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