blob: 818f7dc836b2efd00d0ed3bfd07f480b0d624033 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP message definition header.
2 Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21/* For union sockunion. */
22#include "sockunion.h"
23
24/* Typedef BGP specific types. */
25typedef u_int16_t as_t;
26typedef u_int16_t bgp_size_t;
27
28/* BGP master for system wide configurations and variables. */
29struct bgp_master
30{
31 /* BGP instance list. */
32 struct list *bgp;
33
34 /* BGP thread master. */
35 struct thread_master *master;
36
37 /* BGP port number. */
38 u_int16_t port;
39
40 /* BGP start time. */
41 time_t start_time;
42
43 /* Various BGP global configuration. */
44 u_char options;
45#define BGP_OPT_NO_FIB (1 << 0)
46#define BGP_OPT_MULTIPLE_INSTANCE (1 << 1)
47#define BGP_OPT_CONFIG_CISCO (1 << 2)
48};
49
50/* BGP instance structure. */
51struct bgp
52{
53 /* AS number of this BGP instance. */
54 as_t as;
55
56 /* Name of this BGP instance. */
57 char *name;
58
59 /* Self peer. */
60 struct peer *peer_self;
61
62 /* BGP peer. */
63 struct list *peer;
64
65 /* BGP peer group. */
66 struct list *group;
67
68 /* BGP configuration. */
69 u_int16_t config;
70#define BGP_CONFIG_ROUTER_ID (1 << 0)
71#define BGP_CONFIG_CLUSTER_ID (1 << 1)
72#define BGP_CONFIG_CONFEDERATION (1 << 2)
paul718e3742002-12-13 20:15:29 +000073
74 /* BGP router identifier. */
75 struct in_addr router_id;
76
77 /* BGP route reflector cluster ID. */
78 struct in_addr cluster_id;
79
80 /* BGP confederation information. */
81 as_t confed_id;
82 as_t *confed_peers;
83 int confed_peers_cnt;
84
85 /* BGP flags. */
86 u_int16_t flags;
87#define BGP_FLAG_ALWAYS_COMPARE_MED (1 << 0)
88#define BGP_FLAG_DETERMINISTIC_MED (1 << 1)
89#define BGP_FLAG_MED_MISSING_AS_WORST (1 << 2)
90#define BGP_FLAG_MED_CONFED (1 << 3)
91#define BGP_FLAG_NO_DEFAULT_IPV4 (1 << 4)
92#define BGP_FLAG_NO_CLIENT_TO_CLIENT (1 << 5)
93#define BGP_FLAG_ENFORCE_FIRST_AS (1 << 6)
94#define BGP_FLAG_COMPARE_ROUTER_ID (1 << 7)
95#define BGP_FLAG_ASPATH_IGNORE (1 << 8)
96#define BGP_FLAG_IMPORT_CHECK (1 << 9)
97#define BGP_FLAG_NO_FAST_EXT_FAILOVER (1 << 10)
paul848973c2003-08-13 00:32:49 +000098#define BGP_FLAG_LOG_NEIGHBOR_CHANGES (1 << 11)
hasso538621f2004-05-21 09:31:30 +000099#define BGP_FLAG_GRACEFUL_RESTART (1 << 12)
paul718e3742002-12-13 20:15:29 +0000100
101 /* BGP Per AF flags */
102 u_int16_t af_flags[AFI_MAX][SAFI_MAX];
103#define BGP_CONFIG_DAMPENING (1 << 0)
104
105 /* Static route configuration. */
106 struct bgp_table *route[AFI_MAX][SAFI_MAX];
107
108 /* Aggregate address configuration. */
109 struct bgp_table *aggregate[AFI_MAX][SAFI_MAX];
110
111 /* BGP routing information base. */
112 struct bgp_table *rib[AFI_MAX][SAFI_MAX];
113
114 /* BGP redistribute configuration. */
115 u_char redist[AFI_MAX][ZEBRA_ROUTE_MAX];
116
117 /* BGP redistribute metric configuration. */
118 u_char redist_metric_flag[AFI_MAX][ZEBRA_ROUTE_MAX];
119 u_int32_t redist_metric[AFI_MAX][ZEBRA_ROUTE_MAX];
120
121 /* BGP redistribute route-map. */
122 struct
123 {
124 char *name;
125 struct route_map *map;
126 } rmap[AFI_MAX][ZEBRA_ROUTE_MAX];
127
128 /* BGP distance configuration. */
129 u_char distance_ebgp;
130 u_char distance_ibgp;
131 u_char distance_local;
132
133 /* BGP default local-preference. */
134 u_int32_t default_local_pref;
135
136 /* BGP default timer. */
137 u_int32_t default_holdtime;
138 u_int32_t default_keepalive;
hasso538621f2004-05-21 09:31:30 +0000139
140 /* BGP graceful restart */
141 u_int16_t restart_time;
142 u_int16_t stalepath_time;
paul718e3742002-12-13 20:15:29 +0000143};
144
145/* BGP peer-group support. */
146struct peer_group
147{
148 /* Name of the peer-group. */
149 char *name;
150
151 /* Pointer to BGP. */
152 struct bgp *bgp;
153
154 /* Peer-group client list. */
155 struct list *peer;
156
157 /* Peer-group config */
158 struct peer *conf;
159};
160
161/* BGP Notify message format. */
162struct bgp_notify
163{
164 u_char code;
165 u_char subcode;
166 char *data;
167 bgp_size_t length;
168};
169
170/* Next hop self address. */
171struct bgp_nexthop
172{
173 struct interface *ifp;
174 struct in_addr v4;
175#ifdef HAVE_IPV6
176 struct in6_addr v6_global;
177 struct in6_addr v6_local;
178#endif /* HAVE_IPV6 */
179};
180
181/* BGP router distinguisher value. */
182#define BGP_RD_SIZE 8
183
184struct bgp_rd
185{
186 u_char val[BGP_RD_SIZE];
187};
188
189/* BGP filter structure. */
190struct bgp_filter
191{
192 /* Distribute-list. */
193 struct
194 {
195 char *name;
196 struct access_list *alist;
197 } dlist[FILTER_MAX];
198
199 /* Prefix-list. */
200 struct
201 {
202 char *name;
203 struct prefix_list *plist;
204 } plist[FILTER_MAX];
205
206 /* Filter-list. */
207 struct
208 {
209 char *name;
210 struct as_list *aslist;
211 } aslist[FILTER_MAX];
212
213 /* Route-map. */
214 struct
215 {
216 char *name;
217 struct route_map *map;
218 } map[FILTER_MAX];
219
220 /* Unsuppress-map. */
221 struct
222 {
223 char *name;
224 struct route_map *map;
225 } usmap;
226};
227
228/* BGP neighbor structure. */
229struct peer
230{
231 /* BGP structure. */
232 struct bgp *bgp;
233
234 /* BGP peer group. */
235 struct peer_group *group;
236 u_char af_group[AFI_MAX][SAFI_MAX];
237
238 /* Peer's remote AS number. */
239 as_t as;
240
241 /* Peer's local AS number. */
242 as_t local_as;
243
244 /* Peer's Change local AS number. */
245 as_t change_local_as;
246
247 /* Remote router ID. */
248 struct in_addr remote_id;
249
250 /* Local router ID. */
251 struct in_addr local_id;
252
253 /* Packet receive and send buffer. */
254 struct stream *ibuf;
255 struct stream_fifo *obuf;
256 struct stream *work;
257
258 /* Status of the peer. */
259 int status;
260 int ostatus;
261
262 /* Peer information */
pauleb821182004-05-01 08:44:08 +0000263 int fd; /* File descriptor */
264 int ttl; /* TTL of TCP connection to the peer. */
265 char *desc; /* Description of the peer. */
266 unsigned short port; /* Destination port for peer */
267 char *host; /* Printable address of the peer. */
268 union sockunion su; /* Sockunion address of the peer. */
269 time_t uptime; /* Last Up/Down time */
270 time_t readtime; /* Last read time */
271 time_t resettime; /* Last reset time */
paul718e3742002-12-13 20:15:29 +0000272
pauleb821182004-05-01 08:44:08 +0000273 unsigned int ifindex; /* ifindex of the BGP connection. */
274 char *ifname; /* bind interface name. */
275 char *update_if;
276 union sockunion *update_source;
277 struct zlog *log;
278 u_char version; /* Peer BGP version. */
paul718e3742002-12-13 20:15:29 +0000279
pauleb821182004-05-01 08:44:08 +0000280 union sockunion *su_local; /* Sockunion of local address. */
281 union sockunion *su_remote; /* Sockunion of remote address. */
282 int shared_network; /* Is this peer shared same network. */
283 struct bgp_nexthop nexthop; /* Nexthop */
paul718e3742002-12-13 20:15:29 +0000284
285 /* Peer address family configuration. */
286 u_char afc[AFI_MAX][SAFI_MAX];
287 u_char afc_nego[AFI_MAX][SAFI_MAX];
288 u_char afc_adv[AFI_MAX][SAFI_MAX];
289 u_char afc_recv[AFI_MAX][SAFI_MAX];
290
291 /* Capability Flags.*/
292 u_char cap;
293#define PEER_CAP_REFRESH_ADV (1 << 0) /* refresh advertised */
294#define PEER_CAP_REFRESH_OLD_RCV (1 << 1) /* refresh old received */
295#define PEER_CAP_REFRESH_NEW_RCV (1 << 2) /* refresh rfc received */
296#define PEER_CAP_DYNAMIC_ADV (1 << 3) /* dynamic advertised */
297#define PEER_CAP_DYNAMIC_RCV (1 << 4) /* dynamic received */
hasso538621f2004-05-21 09:31:30 +0000298#define PEER_CAP_RESTART_ADV (1 << 5) /* restart advertised */
299#define PEER_CAP_RESTART_RCV (1 << 6) /* restart received */
paul718e3742002-12-13 20:15:29 +0000300
301 /* Capability Flags.*/
302 u_int16_t af_cap[AFI_MAX][SAFI_MAX];
303#define PEER_CAP_ORF_PREFIX_SM_ADV (1 << 0) /* send-mode advertised */
304#define PEER_CAP_ORF_PREFIX_RM_ADV (1 << 1) /* receive-mode advertised */
305#define PEER_CAP_ORF_PREFIX_SM_RCV (1 << 2) /* send-mode received */
306#define PEER_CAP_ORF_PREFIX_RM_RCV (1 << 3) /* receive-mode received */
307#define PEER_CAP_ORF_PREFIX_SM_OLD_RCV (1 << 4) /* send-mode received */
308#define PEER_CAP_ORF_PREFIX_RM_OLD_RCV (1 << 5) /* receive-mode received */
hasso538621f2004-05-21 09:31:30 +0000309#define PEER_CAP_RESTART_AF_RCV (1 << 6) /* graceful restart received */
310
311 /* Gracefull Restart */
312 u_int16_t restart_time_rcv;
paul718e3742002-12-13 20:15:29 +0000313
314 /* Global configuration flags. */
315 u_int32_t flags;
316#define PEER_FLAG_PASSIVE (1 << 0) /* passive mode */
317#define PEER_FLAG_SHUTDOWN (1 << 1) /* shutdown */
318#define PEER_FLAG_DONT_CAPABILITY (1 << 2) /* dont-capability */
319#define PEER_FLAG_OVERRIDE_CAPABILITY (1 << 3) /* override-capability */
320#define PEER_FLAG_STRICT_CAP_MATCH (1 << 4) /* strict-match */
321#define PEER_FLAG_NO_ROUTE_REFRESH_CAP (1 << 5) /* route-refresh */
322#define PEER_FLAG_DYNAMIC_CAPABILITY (1 << 6) /* dynamic capability */
323#define PEER_FLAG_ENFORCE_MULTIHOP (1 << 7) /* enforce-multihop */
324#define PEER_FLAG_LOCAL_AS_NO_PREPEND (1 << 8) /* local-as no-prepend */
325
326 /* Per AF configuration flags. */
327 u_int32_t af_flags[AFI_MAX][SAFI_MAX];
328#define PEER_FLAG_SEND_COMMUNITY (1 << 0) /* send-community */
329#define PEER_FLAG_SEND_EXT_COMMUNITY (1 << 1) /* send-community ext. */
330#define PEER_FLAG_NEXTHOP_SELF (1 << 2) /* next-hop-self */
331#define PEER_FLAG_REFLECTOR_CLIENT (1 << 3) /* reflector-client */
332#define PEER_FLAG_RSERVER_CLIENT (1 << 4) /* route-server-client */
333#define PEER_FLAG_SOFT_RECONFIG (1 << 5) /* soft-reconfiguration */
334#define PEER_FLAG_AS_PATH_UNCHANGED (1 << 6) /* transparent-as */
335#define PEER_FLAG_NEXTHOP_UNCHANGED (1 << 7) /* transparent-next-hop */
336#define PEER_FLAG_MED_UNCHANGED (1 << 8) /* transparent-next-hop */
337#define PEER_FLAG_DEFAULT_ORIGINATE (1 << 9) /* default-originate */
338#define PEER_FLAG_REMOVE_PRIVATE_AS (1 << 10) /* remove-private-as */
339#define PEER_FLAG_ALLOWAS_IN (1 << 11) /* set allowas-in */
340#define PEER_FLAG_ORF_PREFIX_SM (1 << 12) /* orf capability send-mode */
341#define PEER_FLAG_ORF_PREFIX_RM (1 << 13) /* orf capability receive-mode */
342#define PEER_FLAG_MAX_PREFIX (1 << 14) /* maximum prefix */
343#define PEER_FLAG_MAX_PREFIX_WARNING (1 << 15) /* maximum prefix warning-only */
344
345 /* default-originate route-map. */
346 struct
347 {
348 char *name;
349 struct route_map *map;
350 } default_rmap[AFI_MAX][SAFI_MAX];
351
352 /* Peer status flags. */
353 u_int16_t sflags;
354#define PEER_STATUS_ACCEPT_PEER (1 << 0) /* accept peer */
355#define PEER_STATUS_PREFIX_OVERFLOW (1 << 1) /* prefix-overflow */
356#define PEER_STATUS_CAPABILITY_OPEN (1 << 2) /* capability open send */
357#define PEER_STATUS_HAVE_ACCEPT (1 << 3) /* accept peer's parent */
358#define PEER_STATUS_GROUP (1 << 4) /* peer-group conf */
359
360 /* Peer status af flags. */
361 u_int16_t af_sflags[AFI_MAX][SAFI_MAX];
362#define PEER_STATUS_ORF_PREFIX_SEND (1 << 0) /* prefix-list send peer */
363#define PEER_STATUS_ORF_WAIT_REFRESH (1 << 1) /* wait refresh received peer */
364#define PEER_STATUS_DEFAULT_ORIGINATE (1 << 2) /* default-originate peer */
hassoe0701b72004-05-20 09:19:34 +0000365#define PEER_STATUS_PREFIX_THRESHOLD (1 << 3) /* exceed prefix-threshold */
366#define PEER_STATUS_PREFIX_LIMIT (1 << 4) /* exceed prefix-limit */
367
paul718e3742002-12-13 20:15:29 +0000368
369 /* Default attribute value for the peer. */
370 u_int32_t config;
371#define PEER_CONFIG_WEIGHT (1 << 0) /* Default weight. */
372#define PEER_CONFIG_TIMER (1 << 1) /* keepalive & holdtime */
373#define PEER_CONFIG_CONNECT (1 << 2) /* connect */
374#define PEER_CONFIG_ROUTEADV (1 << 3) /* route advertise */
375 u_int32_t weight;
376 u_int32_t holdtime;
377 u_int32_t keepalive;
378 u_int32_t connect;
379 u_int32_t routeadv;
380
381 /* Timer values. */
382 u_int32_t v_start;
383 u_int32_t v_connect;
384 u_int32_t v_holdtime;
385 u_int32_t v_keepalive;
386 u_int32_t v_asorig;
387 u_int32_t v_routeadv;
388
389 /* Threads. */
390 struct thread *t_read;
391 struct thread *t_write;
392 struct thread *t_start;
393 struct thread *t_connect;
394 struct thread *t_holdtime;
395 struct thread *t_keepalive;
396 struct thread *t_asorig;
397 struct thread *t_routeadv;
398
399 /* Statistics field */
400 u_int32_t open_in; /* Open message input count */
401 u_int32_t open_out; /* Open message output count */
402 u_int32_t update_in; /* Update message input count */
403 u_int32_t update_out; /* Update message ouput count */
404 time_t update_time; /* Update message received time. */
405 u_int32_t keepalive_in; /* Keepalive input count */
406 u_int32_t keepalive_out; /* Keepalive output count */
407 u_int32_t notify_in; /* Notify input count */
408 u_int32_t notify_out; /* Notify output count */
409 u_int32_t refresh_in; /* Route Refresh input count */
410 u_int32_t refresh_out; /* Route Refresh output count */
411 u_int32_t dynamic_cap_in; /* Dynamic Capability input count. */
412 u_int32_t dynamic_cap_out; /* Dynamic Capability output count. */
413
414 /* BGP state count */
415 u_int32_t established; /* Established */
416 u_int32_t dropped; /* Dropped */
417
418 /* Syncronization list and time. */
419 struct bgp_synchronize *sync[AFI_MAX][SAFI_MAX];
420 time_t synctime;
421
422 /* Send prefix count. */
423 unsigned long scount[AFI_MAX][SAFI_MAX];
424
425 /* Announcement attribute hash. */
426 struct hash *hash[AFI_MAX][SAFI_MAX];
427
428 /* Notify data. */
429 struct bgp_notify notify;
430
431 /* Whole packet size to be read. */
432 unsigned long packet_size;
433
434 /* Filter structure. */
435 struct bgp_filter filter[AFI_MAX][SAFI_MAX];
436
437 /* ORF Prefix-list */
438 struct prefix_list *orf_plist[AFI_MAX][SAFI_MAX];
439
440 /* Prefix count. */
441 unsigned long pcount[AFI_MAX][SAFI_MAX];
442
443 /* Max prefix count. */
444 unsigned long pmax[AFI_MAX][SAFI_MAX];
hassoe0701b72004-05-20 09:19:34 +0000445 u_char pmax_threshold[AFI_MAX][SAFI_MAX];
446#define MAXIMUM_PREFIX_THRESHOLD_DEFAULT 75
paul718e3742002-12-13 20:15:29 +0000447
448 /* allowas-in. */
449 char allowas_in[AFI_MAX][SAFI_MAX];
paulac41b2a2003-08-12 05:32:27 +0000450
hassoe0701b72004-05-20 09:19:34 +0000451 /* peer reset cause */
452 char last_reset;
453#define PEER_DOWN_RID_CHANGE 1 /* bgp router-id command */
454#define PEER_DOWN_REMOTE_AS_CHANGE 2 /* neighbor remote-as command */
455#define PEER_DOWN_LOCAL_AS_CHANGE 3 /* neighbor local-as command */
456#define PEER_DOWN_CLID_CHANGE 4 /* bgp cluster-id command */
457#define PEER_DOWN_CONFED_ID_CHANGE 5 /* bgp confederation identifier command */
458#define PEER_DOWN_CONFED_PEER_CHANGE 6 /* bgp confederation peer command */
459#define PEER_DOWN_RR_CLIENT_CHANGE 7 /* neighbor route-reflector-client command */
460#define PEER_DOWN_RS_CLIENT_CHANGE 8 /* neighbor route-server-client command */
461#define PEER_DOWN_UPDATE_SOURCE_CHANGE 9 /* neighbor update-source command */
462#define PEER_DOWN_AF_ACTIVATE 10 /* neighbor activate command */
463#define PEER_DOWN_USER_SHUTDOWN 11 /* neighbor shutdown command */
464#define PEER_DOWN_USER_RESET 12 /* clear ip bgp command */
465#define PEER_DOWN_NOTIFY_RECEIVED 13 /* notification received */
466#define PEER_DOWN_NOTIFY_SEND 14 /* notification send */
467#define PEER_DOWN_CLOSE_SESSION 15 /* tcp session close */
468#define PEER_DOWN_NEIGHBOR_DELETE 16 /* neghbor delete */
469#define PEER_DOWN_RMAP_BIND 17 /* neghbor peer-group command */
470#define PEER_DOWN_RMAP_UNBIND 18 /* no neighbor peer-group command */
471#define PEER_DOWN_CAPABILITY_CHANGE 19 /* neighbor capability command */
472#define PEER_DOWN_PASSIVE_CHANGE 20 /* neighbor passive command */
473#define PEER_DOWN_MULTIHOP_CHANGE 21 /* neighbor multihop command */
474
paulac41b2a2003-08-12 05:32:27 +0000475 /* The kind of route-map Flags.*/
476 u_char rmap_type;
477#define PEER_RMAP_TYPE_IN (1 << 0) /* neighbor route-map in */
478#define PEER_RMAP_TYPE_OUT (1 << 1) /* neighbor route-map out */
479#define PEER_RMAP_TYPE_NETWORK (1 << 2) /* network route-map */
480#define PEER_RMAP_TYPE_REDISTRIBUTE (1 << 3) /* redistribute route-map */
481#define PEER_RMAP_TYPE_DEFAULT (1 << 4) /* default-originate route-map */
482#define PEER_RMAP_TYPE_NOSET (1 << 5) /* not allow to set commands */
paul718e3742002-12-13 20:15:29 +0000483};
484
485/* This structure's member directly points incoming packet data
486 stream. */
487struct bgp_nlri
488{
489 /* AFI. */
490 afi_t afi;
491
492 /* SAFI. */
493 safi_t safi;
494
495 /* Pointer to NLRI byte stream. */
496 u_char *nlri;
497
498 /* Length of whole NLRI. */
499 bgp_size_t length;
500};
501
502/* BGP versions. */
503#define BGP_VERSION_4 4
504#define BGP_VERSION_MP_4_DRAFT_00 40
505
506/* Default BGP port number. */
507#define BGP_PORT_DEFAULT 179
508
509/* BGP message header and packet size. */
510#define BGP_MARKER_SIZE 16
511#define BGP_HEADER_SIZE 19
512#define BGP_MAX_PACKET_SIZE 4096
513
514/* BGP minimum message size. */
515#define BGP_MSG_OPEN_MIN_SIZE (BGP_HEADER_SIZE + 10)
516#define BGP_MSG_UPDATE_MIN_SIZE (BGP_HEADER_SIZE + 4)
517#define BGP_MSG_NOTIFY_MIN_SIZE (BGP_HEADER_SIZE + 2)
518#define BGP_MSG_KEEPALIVE_MIN_SIZE (BGP_HEADER_SIZE + 0)
519#define BGP_MSG_ROUTE_REFRESH_MIN_SIZE (BGP_HEADER_SIZE + 4)
520#define BGP_MSG_CAPABILITY_MIN_SIZE (BGP_HEADER_SIZE + 3)
521
522/* BGP message types. */
523#define BGP_MSG_OPEN 1
524#define BGP_MSG_UPDATE 2
525#define BGP_MSG_NOTIFY 3
526#define BGP_MSG_KEEPALIVE 4
527#define BGP_MSG_ROUTE_REFRESH_NEW 5
528#define BGP_MSG_CAPABILITY 6
529#define BGP_MSG_ROUTE_REFRESH_OLD 128
530
531/* BGP open optional parameter. */
532#define BGP_OPEN_OPT_AUTH 1
533#define BGP_OPEN_OPT_CAP 2
534
535/* BGP4 attribute type codes. */
536#define BGP_ATTR_ORIGIN 1
537#define BGP_ATTR_AS_PATH 2
538#define BGP_ATTR_NEXT_HOP 3
539#define BGP_ATTR_MULTI_EXIT_DISC 4
540#define BGP_ATTR_LOCAL_PREF 5
541#define BGP_ATTR_ATOMIC_AGGREGATE 6
542#define BGP_ATTR_AGGREGATOR 7
543#define BGP_ATTR_COMMUNITIES 8
544#define BGP_ATTR_ORIGINATOR_ID 9
545#define BGP_ATTR_CLUSTER_LIST 10
546#define BGP_ATTR_DPA 11
547#define BGP_ATTR_ADVERTISER 12
548#define BGP_ATTR_RCID_PATH 13
549#define BGP_ATTR_MP_REACH_NLRI 14
550#define BGP_ATTR_MP_UNREACH_NLRI 15
551#define BGP_ATTR_EXT_COMMUNITIES 16
552
553/* BGP update origin. */
554#define BGP_ORIGIN_IGP 0
555#define BGP_ORIGIN_EGP 1
556#define BGP_ORIGIN_INCOMPLETE 2
557
558/* BGP notify message codes. */
559#define BGP_NOTIFY_HEADER_ERR 1
560#define BGP_NOTIFY_OPEN_ERR 2
561#define BGP_NOTIFY_UPDATE_ERR 3
562#define BGP_NOTIFY_HOLD_ERR 4
563#define BGP_NOTIFY_FSM_ERR 5
564#define BGP_NOTIFY_CEASE 6
565#define BGP_NOTIFY_CAPABILITY_ERR 7
566#define BGP_NOTIFY_MAX 8
567
568/* BGP_NOTIFY_HEADER_ERR sub codes. */
569#define BGP_NOTIFY_HEADER_NOT_SYNC 1
570#define BGP_NOTIFY_HEADER_BAD_MESLEN 2
571#define BGP_NOTIFY_HEADER_BAD_MESTYPE 3
572#define BGP_NOTIFY_HEADER_MAX 4
573
574/* BGP_NOTIFY_OPEN_ERR sub codes. */
575#define BGP_NOTIFY_OPEN_UNSUP_VERSION 1
576#define BGP_NOTIFY_OPEN_BAD_PEER_AS 2
577#define BGP_NOTIFY_OPEN_BAD_BGP_IDENT 3
578#define BGP_NOTIFY_OPEN_UNSUP_PARAM 4
579#define BGP_NOTIFY_OPEN_AUTH_FAILURE 5
580#define BGP_NOTIFY_OPEN_UNACEP_HOLDTIME 6
581#define BGP_NOTIFY_OPEN_UNSUP_CAPBL 7
582#define BGP_NOTIFY_OPEN_MAX 8
583
584/* BGP_NOTIFY_UPDATE_ERR sub codes. */
585#define BGP_NOTIFY_UPDATE_MAL_ATTR 1
586#define BGP_NOTIFY_UPDATE_UNREC_ATTR 2
587#define BGP_NOTIFY_UPDATE_MISS_ATTR 3
588#define BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR 4
589#define BGP_NOTIFY_UPDATE_ATTR_LENG_ERR 5
590#define BGP_NOTIFY_UPDATE_INVAL_ORIGIN 6
591#define BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP 7
592#define BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP 8
593#define BGP_NOTIFY_UPDATE_OPT_ATTR_ERR 9
594#define BGP_NOTIFY_UPDATE_INVAL_NETWORK 10
595#define BGP_NOTIFY_UPDATE_MAL_AS_PATH 11
596#define BGP_NOTIFY_UPDATE_MAX 12
597
paul545acaf2004-04-20 15:13:15 +0000598/* BGP_NOTIFY_CEASE sub codes (draft-ietf-idr-cease-subcode-05). */
paul718e3742002-12-13 20:15:29 +0000599#define BGP_NOTIFY_CEASE_MAX_PREFIX 1
600#define BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN 2
601#define BGP_NOTIFY_CEASE_PEER_UNCONFIG 3
602#define BGP_NOTIFY_CEASE_ADMIN_RESET 4
603#define BGP_NOTIFY_CEASE_CONNECT_REJECT 5
604#define BGP_NOTIFY_CEASE_CONFIG_CHANGE 6
paul545acaf2004-04-20 15:13:15 +0000605#define BGP_NOTIFY_CEASE_COLLISION_RESOLUTION 7
606#define BGP_NOTIFY_CEASE_OUT_OF_RESOURCE 8
607#define BGP_NOTIFY_CEASE_MAX 9
paul718e3742002-12-13 20:15:29 +0000608
609/* BGP_NOTIFY_CAPABILITY_ERR sub codes (draft-ietf-idr-dynamic-cap-02). */
610#define BGP_NOTIFY_CAPABILITY_INVALID_ACTION 1
611#define BGP_NOTIFY_CAPABILITY_INVALID_LENGTH 2
612#define BGP_NOTIFY_CAPABILITY_MALFORMED_CODE 3
613#define BGP_NOTIFY_CAPABILITY_MAX 4
614
615/* BGP finite state machine status. */
616#define Idle 1
617#define Connect 2
618#define Active 3
619#define OpenSent 4
620#define OpenConfirm 5
621#define Established 6
622#define BGP_STATUS_MAX 7
623
624/* BGP finite state machine events. */
625#define BGP_Start 1
626#define BGP_Stop 2
627#define TCP_connection_open 3
628#define TCP_connection_closed 4
629#define TCP_connection_open_failed 5
630#define TCP_fatal_error 6
631#define ConnectRetry_timer_expired 7
632#define Hold_Timer_expired 8
633#define KeepAlive_timer_expired 9
634#define Receive_OPEN_message 10
635#define Receive_KEEPALIVE_message 11
636#define Receive_UPDATE_message 12
637#define Receive_NOTIFICATION_message 13
638#define BGP_EVENTS_MAX 14
639
640/* BGP timers default value. */
641#define BGP_INIT_START_TIMER 5
642#define BGP_ERROR_START_TIMER 30
643#define BGP_DEFAULT_HOLDTIME 180
644#define BGP_DEFAULT_KEEPALIVE 60
645#define BGP_DEFAULT_ASORIGINATE 15
646#define BGP_DEFAULT_EBGP_ROUTEADV 30
647#define BGP_DEFAULT_IBGP_ROUTEADV 5
648#define BGP_CLEAR_CONNECT_RETRY 20
649#define BGP_DEFAULT_CONNECT_RETRY 120
650
651/* BGP default local preference. */
652#define BGP_DEFAULT_LOCAL_PREF 100
653
hasso538621f2004-05-21 09:31:30 +0000654/* BGP graceful restart */
655#define BGP_DEFAULT_RESTART_TIME 120
656#define BGP_DEFAULT_STALEPATH_TIME 360
657
paul718e3742002-12-13 20:15:29 +0000658/* SAFI which used in open capability negotiation. */
659#define BGP_SAFI_VPNV4 128
660#define BGP_SAFI_VPNV6 129
661
662/* Max TTL value. */
663#define TTL_MAX 255
664
665/* BGP uptime string length. */
666#define BGP_UPTIME_LEN 25
667
668/* Default configuration settings for bgpd. */
669#define BGP_VTY_PORT 2605
paul718e3742002-12-13 20:15:29 +0000670#define BGP_DEFAULT_CONFIG "bgpd.conf"
671
672/* Check AS path loop when we send NLRI. */
673/* #define BGP_SEND_ASPATH_CHECK */
674
675/* IBGP/EBGP identifier. We also have a CONFED peer, which is to say,
676 a peer who's AS is part of our Confederation. */
677enum
678{
679 BGP_PEER_IBGP,
680 BGP_PEER_EBGP,
681 BGP_PEER_INTERNAL,
682 BGP_PEER_CONFED
683};
684
685/* Flag for peer_clear_soft(). */
686enum bgp_clear_type
687{
688 BGP_CLEAR_SOFT_NONE,
689 BGP_CLEAR_SOFT_OUT,
690 BGP_CLEAR_SOFT_IN,
691 BGP_CLEAR_SOFT_BOTH,
692 BGP_CLEAR_SOFT_IN_ORF_PREFIX
693};
694
695/* Macros. */
696#define BGP_INPUT(P) ((P)->ibuf)
697#define BGP_INPUT_PNT(P) (STREAM_PNT(BGP_INPUT(P)))
698
699/* Macro to check BGP information is alive or not. */
700#define BGP_INFO_HOLDDOWN(BI) \
701 (! CHECK_FLAG ((BI)->flags, BGP_INFO_VALID) \
702 || CHECK_FLAG ((BI)->flags, BGP_INFO_HISTORY) \
703 || CHECK_FLAG ((BI)->flags, BGP_INFO_DAMPED))
704
705/* Count prefix size from mask length */
706#define PSIZE(a) (((a) + 7) / (8))
707
708/* BGP error codes. */
709#define BGP_SUCCESS 0
710#define BGP_ERR_INVALID_VALUE -1
711#define BGP_ERR_INVALID_FLAG -2
712#define BGP_ERR_INVALID_AS -3
713#define BGP_ERR_INVALID_BGP -4
714#define BGP_ERR_PEER_GROUP_MEMBER -5
715#define BGP_ERR_MULTIPLE_INSTANCE_USED -6
716#define BGP_ERR_PEER_GROUP_MEMBER_EXISTS -7
717#define BGP_ERR_PEER_BELONGS_TO_GROUP -8
718#define BGP_ERR_PEER_GROUP_AF_UNCONFIGURED -9
719#define BGP_ERR_PEER_GROUP_NO_REMOTE_AS -10
720#define BGP_ERR_PEER_GROUP_CANT_CHANGE -11
721#define BGP_ERR_PEER_GROUP_MISMATCH -12
722#define BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT -13
723#define BGP_ERR_MULTIPLE_INSTANCE_NOT_SET -14
724#define BGP_ERR_AS_MISMATCH -15
725#define BGP_ERR_PEER_INACTIVE -16
726#define BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER -17
727#define BGP_ERR_PEER_GROUP_HAS_THE_FLAG -18
728#define BGP_ERR_PEER_FLAG_CONFLICT -19
729#define BGP_ERR_PEER_GROUP_SHUTDOWN -20
730#define BGP_ERR_PEER_FILTER_CONFLICT -21
731#define BGP_ERR_NOT_INTERNAL_PEER -22
732#define BGP_ERR_REMOVE_PRIVATE_AS -23
733#define BGP_ERR_AF_UNCONFIGURED -24
734#define BGP_ERR_SOFT_RECONFIG_UNCONFIGURED -25
735#define BGP_ERR_INSTANCE_MISMATCH -26
736#define BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP -27
737#define BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS -28
738#define BGP_ERR_MAX -29
739
740extern struct bgp_master *bm;
741
742extern struct thread_master *master;
743
744/* Prototypes. */
745void bgp_terminate (void);
746void bgp_reset (void);
747void bgp_zclient_reset ();
748int bgp_nexthop_set (union sockunion *, union sockunion *,
749 struct bgp_nexthop *, struct peer *);
paul6cbbc3c2003-04-28 17:11:02 +0000750struct bgp_master *bgp_get_master ();
paul718e3742002-12-13 20:15:29 +0000751struct bgp *bgp_get_default ();
752struct bgp *bgp_lookup (as_t, char *);
753struct bgp *bgp_lookup_by_name (char *);
754struct peer *peer_lookup (struct bgp *, union sockunion *);
755struct peer_group *peer_group_lookup (struct bgp *, char *);
756struct peer_group *peer_group_get (struct bgp *, char *);
757struct peer *peer_lookup_with_open (union sockunion *, as_t, struct in_addr *,
758 int *);
759int peer_sort (struct peer *peer);
760int peer_active (struct peer *);
761int peer_active_nego (struct peer *);
762struct peer *peer_create_accept (struct bgp *);
763char *peer_uptime (time_t, char *, size_t);
764void bgp_config_write_family_header (struct vty *, afi_t, safi_t, int *);
765
766void bgp_master_init ();
767
768void bgp_init ();
769
770int bgp_option_set (int);
771int bgp_option_unset (int);
772int bgp_option_check (int);
773
774int bgp_get (struct bgp **, as_t *, char *);
775int bgp_delete (struct bgp *);
776
777int bgp_flag_set (struct bgp *, int);
778int bgp_flag_unset (struct bgp *, int);
779int bgp_flag_check (struct bgp *, int);
780
781int bgp_router_id_set (struct bgp *, struct in_addr *);
782int bgp_router_id_unset (struct bgp *);
783
784int bgp_cluster_id_set (struct bgp *, struct in_addr *);
785int bgp_cluster_id_unset (struct bgp *);
786
787int bgp_confederation_id_set (struct bgp *, as_t);
788int bgp_confederation_id_unset (struct bgp *);
789int bgp_confederation_peers_check (struct bgp *, as_t);
790
791int bgp_confederation_peers_add (struct bgp *, as_t);
792int bgp_confederation_peers_remove (struct bgp *, as_t);
793
794int bgp_timers_set (struct bgp *, u_int32_t, u_int32_t);
795int bgp_timers_unset (struct bgp *);
796
797int bgp_default_local_preference_set (struct bgp *, u_int32_t);
798int bgp_default_local_preference_unset (struct bgp *);
799
800int peer_remote_as (struct bgp *, union sockunion *, as_t *, afi_t, safi_t);
801int peer_group_remote_as (struct bgp *, char *, as_t *);
802int peer_delete (struct peer *peer);
803int peer_group_delete (struct peer_group *);
804int peer_group_remote_as_delete (struct peer_group *);
805
806int peer_activate (struct peer *, afi_t, safi_t);
807int peer_deactivate (struct peer *, afi_t, safi_t);
808
809int peer_group_bind (struct bgp *, union sockunion *, struct peer_group *,
810 afi_t, safi_t, as_t *);
811int peer_group_unbind (struct bgp *, struct peer *, struct peer_group *,
812 afi_t, safi_t);
813
814int peer_flag_set (struct peer *, u_int32_t);
815int peer_flag_unset (struct peer *, u_int32_t);
816
817int peer_af_flag_set (struct peer *, afi_t, safi_t, u_int32_t);
818int peer_af_flag_unset (struct peer *, afi_t, safi_t, u_int32_t);
819int peer_af_flag_check (struct peer *, afi_t, safi_t, u_int32_t);
820
821int peer_ebgp_multihop_set (struct peer *, int);
822int peer_ebgp_multihop_unset (struct peer *);
823
824int peer_description_set (struct peer *, char *);
825int peer_description_unset (struct peer *);
826
827int peer_update_source_if_set (struct peer *, char *);
828int peer_update_source_addr_set (struct peer *, union sockunion *);
829int peer_update_source_unset (struct peer *);
830
831int peer_default_originate_set (struct peer *, afi_t, safi_t, char *);
832int peer_default_originate_unset (struct peer *, afi_t, safi_t);
833
834int peer_port_set (struct peer *, u_int16_t);
835int peer_port_unset (struct peer *);
836
837int peer_weight_set (struct peer *, u_int16_t);
838int peer_weight_unset (struct peer *);
839
840int peer_timers_set (struct peer *, u_int32_t, u_int32_t);
841int peer_timers_unset (struct peer *);
842
843int peer_timers_connect_set (struct peer *, u_int32_t);
844int peer_timers_connect_unset (struct peer *);
845
846int peer_advertise_interval_set (struct peer *, u_int32_t);
847int peer_advertise_interval_unset (struct peer *);
848
849int peer_version_set (struct peer *, int);
850int peer_version_unset (struct peer *);
851
852int peer_interface_set (struct peer *, char *);
853int peer_interface_unset (struct peer *);
854
855int peer_distribute_set (struct peer *, afi_t, safi_t, int, char *);
856int peer_distribute_unset (struct peer *, afi_t, safi_t, int);
857
858int peer_allowas_in_set (struct peer *, afi_t, safi_t, int);
859int peer_allowas_in_unset (struct peer *, afi_t, safi_t);
860
861int peer_local_as_set (struct peer *, as_t, int);
862int peer_local_as_unset (struct peer *);
863
864int peer_prefix_list_set (struct peer *, afi_t, safi_t, int, char *);
865int peer_prefix_list_unset (struct peer *, afi_t, safi_t, int);
866
867int peer_aslist_set (struct peer *, afi_t, safi_t, int, char *);
868int peer_aslist_unset (struct peer *,afi_t, safi_t, int);
869
870int peer_route_map_set (struct peer *, afi_t, safi_t, int, char *);
871int peer_route_map_unset (struct peer *, afi_t, safi_t, int);
872
873int peer_unsuppress_map_set (struct peer *, afi_t, safi_t, char *);
874int peer_unsuppress_map_unset (struct peer *, afi_t, safi_t);
875
hassoe0701b72004-05-20 09:19:34 +0000876int peer_maximum_prefix_set (struct peer *, afi_t, safi_t, u_int32_t, u_char, int);
paul718e3742002-12-13 20:15:29 +0000877int peer_maximum_prefix_unset (struct peer *, afi_t, safi_t);
878
879int peer_clear (struct peer *);
880int peer_clear_soft (struct peer *, afi_t, safi_t, enum bgp_clear_type);