]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgpd.h
2005-05-23 Paul Jakma <paul@dishone.st>
[mirror_frr.git] / bgpd / bgpd.h
CommitLineData
718e3744 1/* 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
fee0f4c6 68 /* BGP route-server-clients. */
69 struct list *rsclient;
70
718e3744 71 /* BGP configuration. */
72 u_int16_t config;
73#define BGP_CONFIG_ROUTER_ID (1 << 0)
74#define BGP_CONFIG_CLUSTER_ID (1 << 1)
75#define BGP_CONFIG_CONFEDERATION (1 << 2)
718e3744 76
77 /* BGP router identifier. */
78 struct in_addr router_id;
18a6dce6 79 struct in_addr router_id_static;
718e3744 80
81 /* BGP route reflector cluster ID. */
82 struct in_addr cluster_id;
83
84 /* BGP confederation information. */
85 as_t confed_id;
86 as_t *confed_peers;
87 int confed_peers_cnt;
88
89 /* BGP flags. */
90 u_int16_t flags;
91#define BGP_FLAG_ALWAYS_COMPARE_MED (1 << 0)
92#define BGP_FLAG_DETERMINISTIC_MED (1 << 1)
93#define BGP_FLAG_MED_MISSING_AS_WORST (1 << 2)
94#define BGP_FLAG_MED_CONFED (1 << 3)
95#define BGP_FLAG_NO_DEFAULT_IPV4 (1 << 4)
96#define BGP_FLAG_NO_CLIENT_TO_CLIENT (1 << 5)
97#define BGP_FLAG_ENFORCE_FIRST_AS (1 << 6)
98#define BGP_FLAG_COMPARE_ROUTER_ID (1 << 7)
99#define BGP_FLAG_ASPATH_IGNORE (1 << 8)
100#define BGP_FLAG_IMPORT_CHECK (1 << 9)
101#define BGP_FLAG_NO_FAST_EXT_FAILOVER (1 << 10)
848973c7 102#define BGP_FLAG_LOG_NEIGHBOR_CHANGES (1 << 11)
538621f2 103#define BGP_FLAG_GRACEFUL_RESTART (1 << 12)
6811845b 104#define BGP_FLAG_ASPATH_CONFED (1 << 13)
718e3744 105
106 /* BGP Per AF flags */
107 u_int16_t af_flags[AFI_MAX][SAFI_MAX];
108#define BGP_CONFIG_DAMPENING (1 << 0)
109
110 /* Static route configuration. */
111 struct bgp_table *route[AFI_MAX][SAFI_MAX];
112
113 /* Aggregate address configuration. */
114 struct bgp_table *aggregate[AFI_MAX][SAFI_MAX];
115
116 /* BGP routing information base. */
117 struct bgp_table *rib[AFI_MAX][SAFI_MAX];
118
119 /* BGP redistribute configuration. */
120 u_char redist[AFI_MAX][ZEBRA_ROUTE_MAX];
121
122 /* BGP redistribute metric configuration. */
123 u_char redist_metric_flag[AFI_MAX][ZEBRA_ROUTE_MAX];
124 u_int32_t redist_metric[AFI_MAX][ZEBRA_ROUTE_MAX];
125
126 /* BGP redistribute route-map. */
127 struct
128 {
129 char *name;
130 struct route_map *map;
131 } rmap[AFI_MAX][ZEBRA_ROUTE_MAX];
132
133 /* BGP distance configuration. */
134 u_char distance_ebgp;
135 u_char distance_ibgp;
136 u_char distance_local;
137
138 /* BGP default local-preference. */
139 u_int32_t default_local_pref;
140
141 /* BGP default timer. */
142 u_int32_t default_holdtime;
143 u_int32_t default_keepalive;
538621f2 144
145 /* BGP graceful restart */
93406d87 146 u_int32_t restart_time;
147 u_int32_t stalepath_time;
718e3744 148};
149
150/* BGP peer-group support. */
151struct peer_group
152{
153 /* Name of the peer-group. */
154 char *name;
155
156 /* Pointer to BGP. */
157 struct bgp *bgp;
158
159 /* Peer-group client list. */
160 struct list *peer;
161
162 /* Peer-group config */
163 struct peer *conf;
164};
165
166/* BGP Notify message format. */
167struct bgp_notify
168{
169 u_char code;
170 u_char subcode;
171 char *data;
172 bgp_size_t length;
173};
174
175/* Next hop self address. */
176struct bgp_nexthop
177{
178 struct interface *ifp;
179 struct in_addr v4;
180#ifdef HAVE_IPV6
181 struct in6_addr v6_global;
182 struct in6_addr v6_local;
183#endif /* HAVE_IPV6 */
184};
185
186/* BGP router distinguisher value. */
187#define BGP_RD_SIZE 8
188
189struct bgp_rd
190{
191 u_char val[BGP_RD_SIZE];
192};
193
fee0f4c6 194#define RMAP_IN 0
195#define RMAP_OUT 1
196#define RMAP_IMPORT 2
197#define RMAP_EXPORT 3
198#define RMAP_MAX 4
199
718e3744 200/* BGP filter structure. */
201struct bgp_filter
202{
203 /* Distribute-list. */
204 struct
205 {
206 char *name;
207 struct access_list *alist;
208 } dlist[FILTER_MAX];
209
210 /* Prefix-list. */
211 struct
212 {
213 char *name;
214 struct prefix_list *plist;
215 } plist[FILTER_MAX];
216
217 /* Filter-list. */
218 struct
219 {
220 char *name;
221 struct as_list *aslist;
222 } aslist[FILTER_MAX];
223
224 /* Route-map. */
225 struct
226 {
227 char *name;
228 struct route_map *map;
fee0f4c6 229 } map[RMAP_MAX];
718e3744 230
231 /* Unsuppress-map. */
232 struct
233 {
234 char *name;
235 struct route_map *map;
236 } usmap;
237};
238
239/* BGP neighbor structure. */
240struct peer
241{
242 /* BGP structure. */
243 struct bgp *bgp;
244
245 /* BGP peer group. */
246 struct peer_group *group;
247 u_char af_group[AFI_MAX][SAFI_MAX];
248
249 /* Peer's remote AS number. */
250 as_t as;
251
252 /* Peer's local AS number. */
253 as_t local_as;
254
255 /* Peer's Change local AS number. */
256 as_t change_local_as;
257
258 /* Remote router ID. */
259 struct in_addr remote_id;
260
261 /* Local router ID. */
262 struct in_addr local_id;
263
fee0f4c6 264 /* Peer specific RIB when configured as route-server-client. */
265 struct bgp_table *rib[AFI_MAX][SAFI_MAX];
266
718e3744 267 /* Packet receive and send buffer. */
268 struct stream *ibuf;
269 struct stream_fifo *obuf;
270 struct stream *work;
271
272 /* Status of the peer. */
273 int status;
274 int ostatus;
275
276 /* Peer information */
eb821189 277 int fd; /* File descriptor */
278 int ttl; /* TTL of TCP connection to the peer. */
279 char *desc; /* Description of the peer. */
280 unsigned short port; /* Destination port for peer */
281 char *host; /* Printable address of the peer. */
282 union sockunion su; /* Sockunion address of the peer. */
283 time_t uptime; /* Last Up/Down time */
284 time_t readtime; /* Last read time */
285 time_t resettime; /* Last reset time */
718e3744 286
eb821189 287 unsigned int ifindex; /* ifindex of the BGP connection. */
288 char *ifname; /* bind interface name. */
289 char *update_if;
290 union sockunion *update_source;
291 struct zlog *log;
eb821189 292
293 union sockunion *su_local; /* Sockunion of local address. */
294 union sockunion *su_remote; /* Sockunion of remote address. */
295 int shared_network; /* Is this peer shared same network. */
296 struct bgp_nexthop nexthop; /* Nexthop */
718e3744 297
298 /* Peer address family configuration. */
299 u_char afc[AFI_MAX][SAFI_MAX];
300 u_char afc_nego[AFI_MAX][SAFI_MAX];
301 u_char afc_adv[AFI_MAX][SAFI_MAX];
302 u_char afc_recv[AFI_MAX][SAFI_MAX];
303
0a486e5f 304 /* Capability flags (reset in bgp_stop) */
718e3744 305 u_char cap;
306#define PEER_CAP_REFRESH_ADV (1 << 0) /* refresh advertised */
307#define PEER_CAP_REFRESH_OLD_RCV (1 << 1) /* refresh old received */
308#define PEER_CAP_REFRESH_NEW_RCV (1 << 2) /* refresh rfc received */
309#define PEER_CAP_DYNAMIC_ADV (1 << 3) /* dynamic advertised */
310#define PEER_CAP_DYNAMIC_RCV (1 << 4) /* dynamic received */
538621f2 311#define PEER_CAP_RESTART_ADV (1 << 5) /* restart advertised */
312#define PEER_CAP_RESTART_RCV (1 << 6) /* restart received */
718e3744 313
0a486e5f 314 /* Capability flags (reset in bgp_stop) */
718e3744 315 u_int16_t af_cap[AFI_MAX][SAFI_MAX];
316#define PEER_CAP_ORF_PREFIX_SM_ADV (1 << 0) /* send-mode advertised */
317#define PEER_CAP_ORF_PREFIX_RM_ADV (1 << 1) /* receive-mode advertised */
318#define PEER_CAP_ORF_PREFIX_SM_RCV (1 << 2) /* send-mode received */
319#define PEER_CAP_ORF_PREFIX_RM_RCV (1 << 3) /* receive-mode received */
320#define PEER_CAP_ORF_PREFIX_SM_OLD_RCV (1 << 4) /* send-mode received */
321#define PEER_CAP_ORF_PREFIX_RM_OLD_RCV (1 << 5) /* receive-mode received */
93406d87 322#define PEER_CAP_RESTART_AF_RCV (1 << 6) /* graceful restart afi/safi received */
323#define PEER_CAP_RESTART_AF_PRESERVE_RCV (1 << 7) /* graceful restart afi/safi F-bit received */
718e3744 324
325 /* Global configuration flags. */
326 u_int32_t flags;
327#define PEER_FLAG_PASSIVE (1 << 0) /* passive mode */
328#define PEER_FLAG_SHUTDOWN (1 << 1) /* shutdown */
329#define PEER_FLAG_DONT_CAPABILITY (1 << 2) /* dont-capability */
330#define PEER_FLAG_OVERRIDE_CAPABILITY (1 << 3) /* override-capability */
331#define PEER_FLAG_STRICT_CAP_MATCH (1 << 4) /* strict-match */
c9502438 332#define PEER_FLAG_DYNAMIC_CAPABILITY (1 << 5) /* dynamic capability */
6ffd2079 333#define PEER_FLAG_DISABLE_CONNECTED_CHECK (1 << 6) /* disable-connected-check */
c9502438 334#define PEER_FLAG_LOCAL_AS_NO_PREPEND (1 << 7) /* local-as no-prepend */
718e3744 335
93406d87 336 /* NSF mode (graceful restart) */
337 u_char nsf[AFI_MAX][SAFI_MAX];
338
718e3744 339 /* Per AF configuration flags. */
340 u_int32_t af_flags[AFI_MAX][SAFI_MAX];
341#define PEER_FLAG_SEND_COMMUNITY (1 << 0) /* send-community */
342#define PEER_FLAG_SEND_EXT_COMMUNITY (1 << 1) /* send-community ext. */
343#define PEER_FLAG_NEXTHOP_SELF (1 << 2) /* next-hop-self */
344#define PEER_FLAG_REFLECTOR_CLIENT (1 << 3) /* reflector-client */
345#define PEER_FLAG_RSERVER_CLIENT (1 << 4) /* route-server-client */
346#define PEER_FLAG_SOFT_RECONFIG (1 << 5) /* soft-reconfiguration */
347#define PEER_FLAG_AS_PATH_UNCHANGED (1 << 6) /* transparent-as */
348#define PEER_FLAG_NEXTHOP_UNCHANGED (1 << 7) /* transparent-next-hop */
349#define PEER_FLAG_MED_UNCHANGED (1 << 8) /* transparent-next-hop */
350#define PEER_FLAG_DEFAULT_ORIGINATE (1 << 9) /* default-originate */
351#define PEER_FLAG_REMOVE_PRIVATE_AS (1 << 10) /* remove-private-as */
352#define PEER_FLAG_ALLOWAS_IN (1 << 11) /* set allowas-in */
353#define PEER_FLAG_ORF_PREFIX_SM (1 << 12) /* orf capability send-mode */
354#define PEER_FLAG_ORF_PREFIX_RM (1 << 13) /* orf capability receive-mode */
355#define PEER_FLAG_MAX_PREFIX (1 << 14) /* maximum prefix */
356#define PEER_FLAG_MAX_PREFIX_WARNING (1 << 15) /* maximum prefix warning-only */
fee0f4c6 357#define PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED (1 << 16) /* leave link-local nexthop unchanged */
718e3744 358
359 /* default-originate route-map. */
360 struct
361 {
362 char *name;
363 struct route_map *map;
364 } default_rmap[AFI_MAX][SAFI_MAX];
365
366 /* Peer status flags. */
367 u_int16_t sflags;
368#define PEER_STATUS_ACCEPT_PEER (1 << 0) /* accept peer */
369#define PEER_STATUS_PREFIX_OVERFLOW (1 << 1) /* prefix-overflow */
370#define PEER_STATUS_CAPABILITY_OPEN (1 << 2) /* capability open send */
371#define PEER_STATUS_HAVE_ACCEPT (1 << 3) /* accept peer's parent */
372#define PEER_STATUS_GROUP (1 << 4) /* peer-group conf */
93406d87 373#define PEER_STATUS_NSF_MODE (1 << 5) /* NSF aware peer */
374#define PEER_STATUS_NSF_WAIT (1 << 6) /* wait comeback peer */
718e3744 375
0a486e5f 376 /* Peer status af flags (reset in bgp_stop) */
718e3744 377 u_int16_t af_sflags[AFI_MAX][SAFI_MAX];
378#define PEER_STATUS_ORF_PREFIX_SEND (1 << 0) /* prefix-list send peer */
379#define PEER_STATUS_ORF_WAIT_REFRESH (1 << 1) /* wait refresh received peer */
380#define PEER_STATUS_DEFAULT_ORIGINATE (1 << 2) /* default-originate peer */
e0701b79 381#define PEER_STATUS_PREFIX_THRESHOLD (1 << 3) /* exceed prefix-threshold */
382#define PEER_STATUS_PREFIX_LIMIT (1 << 4) /* exceed prefix-limit */
93406d87 383#define PEER_STATUS_EOR_SEND (1 << 5) /* end-of-rib send to peer */
384#define PEER_STATUS_EOR_RECEIVED (1 << 6) /* end-of-rib received from peer */
e0701b79 385
718e3744 386
387 /* Default attribute value for the peer. */
388 u_int32_t config;
389#define PEER_CONFIG_WEIGHT (1 << 0) /* Default weight. */
390#define PEER_CONFIG_TIMER (1 << 1) /* keepalive & holdtime */
391#define PEER_CONFIG_CONNECT (1 << 2) /* connect */
392#define PEER_CONFIG_ROUTEADV (1 << 3) /* route advertise */
393 u_int32_t weight;
394 u_int32_t holdtime;
395 u_int32_t keepalive;
396 u_int32_t connect;
397 u_int32_t routeadv;
398
399 /* Timer values. */
400 u_int32_t v_start;
401 u_int32_t v_connect;
402 u_int32_t v_holdtime;
403 u_int32_t v_keepalive;
404 u_int32_t v_asorig;
405 u_int32_t v_routeadv;
0a486e5f 406 u_int32_t v_pmax_restart;
93406d87 407 u_int32_t v_gr_restart;
718e3744 408
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;
0a486e5f 418 struct thread *t_pmax_restart;
93406d87 419 struct thread *t_gr_restart;
420 struct thread *t_gr_stale;
718e3744 421
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. */
436
437 /* BGP state count */
438 u_int32_t established; /* Established */
439 u_int32_t dropped; /* Dropped */
440
441 /* Syncronization list and time. */
442 struct bgp_synchronize *sync[AFI_MAX][SAFI_MAX];
443 time_t synctime;
444
445 /* Send prefix count. */
446 unsigned long scount[AFI_MAX][SAFI_MAX];
447
448 /* Announcement attribute hash. */
449 struct hash *hash[AFI_MAX][SAFI_MAX];
450
451 /* Notify data. */
452 struct bgp_notify notify;
453
454 /* Whole packet size to be read. */
455 unsigned long packet_size;
456
457 /* Filter structure. */
458 struct bgp_filter filter[AFI_MAX][SAFI_MAX];
459
460 /* ORF Prefix-list */
461 struct prefix_list *orf_plist[AFI_MAX][SAFI_MAX];
462
463 /* Prefix count. */
464 unsigned long pcount[AFI_MAX][SAFI_MAX];
465
466 /* Max prefix count. */
467 unsigned long pmax[AFI_MAX][SAFI_MAX];
e0701b79 468 u_char pmax_threshold[AFI_MAX][SAFI_MAX];
0a486e5f 469 u_int16_t pmax_restart[AFI_MAX][SAFI_MAX];
e0701b79 470#define MAXIMUM_PREFIX_THRESHOLD_DEFAULT 75
718e3744 471
472 /* allowas-in. */
473 char allowas_in[AFI_MAX][SAFI_MAX];
ac41b2a2 474
e0701b79 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_PASSIVE_CHANGE 20 /* neighbor passive command */
497#define PEER_DOWN_MULTIHOP_CHANGE 21 /* neighbor multihop command */
93406d87 498#define PEER_DOWN_NSF_CLOSE_SESSION 22 /* NSF tcp session close */
e0701b79 499
ac41b2a2 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 */
fee0f4c6 508#define PEER_RMAP_TYPE_IMPORT (1 << 6) /* neighbor route-map import */
509#define PEER_RMAP_TYPE_EXPORT (1 << 7) /* neighbor route-map export */
718e3744 510};
511
512/* This structure's member directly points incoming packet data
513 stream. */
514struct bgp_nlri
515{
516 /* AFI. */
517 afi_t afi;
518
519 /* SAFI. */
520 safi_t safi;
521
522 /* Pointer to NLRI byte stream. */
523 u_char *nlri;
524
525 /* Length of whole NLRI. */
526 bgp_size_t length;
527};
528
529/* BGP versions. */
530#define BGP_VERSION_4 4
718e3744 531
532/* Default BGP port number. */
533#define BGP_PORT_DEFAULT 179
534
535/* BGP message header and packet size. */
536#define BGP_MARKER_SIZE 16
537#define BGP_HEADER_SIZE 19
538#define BGP_MAX_PACKET_SIZE 4096
539
540/* BGP minimum message size. */
541#define BGP_MSG_OPEN_MIN_SIZE (BGP_HEADER_SIZE + 10)
542#define BGP_MSG_UPDATE_MIN_SIZE (BGP_HEADER_SIZE + 4)
543#define BGP_MSG_NOTIFY_MIN_SIZE (BGP_HEADER_SIZE + 2)
544#define BGP_MSG_KEEPALIVE_MIN_SIZE (BGP_HEADER_SIZE + 0)
545#define BGP_MSG_ROUTE_REFRESH_MIN_SIZE (BGP_HEADER_SIZE + 4)
546#define BGP_MSG_CAPABILITY_MIN_SIZE (BGP_HEADER_SIZE + 3)
547
548/* BGP message types. */
549#define BGP_MSG_OPEN 1
550#define BGP_MSG_UPDATE 2
551#define BGP_MSG_NOTIFY 3
552#define BGP_MSG_KEEPALIVE 4
553#define BGP_MSG_ROUTE_REFRESH_NEW 5
554#define BGP_MSG_CAPABILITY 6
555#define BGP_MSG_ROUTE_REFRESH_OLD 128
556
557/* BGP open optional parameter. */
558#define BGP_OPEN_OPT_AUTH 1
559#define BGP_OPEN_OPT_CAP 2
560
561/* BGP4 attribute type codes. */
562#define BGP_ATTR_ORIGIN 1
563#define BGP_ATTR_AS_PATH 2
564#define BGP_ATTR_NEXT_HOP 3
565#define BGP_ATTR_MULTI_EXIT_DISC 4
566#define BGP_ATTR_LOCAL_PREF 5
567#define BGP_ATTR_ATOMIC_AGGREGATE 6
568#define BGP_ATTR_AGGREGATOR 7
569#define BGP_ATTR_COMMUNITIES 8
570#define BGP_ATTR_ORIGINATOR_ID 9
571#define BGP_ATTR_CLUSTER_LIST 10
572#define BGP_ATTR_DPA 11
573#define BGP_ATTR_ADVERTISER 12
574#define BGP_ATTR_RCID_PATH 13
575#define BGP_ATTR_MP_REACH_NLRI 14
576#define BGP_ATTR_MP_UNREACH_NLRI 15
577#define BGP_ATTR_EXT_COMMUNITIES 16
578
579/* BGP update origin. */
580#define BGP_ORIGIN_IGP 0
581#define BGP_ORIGIN_EGP 1
582#define BGP_ORIGIN_INCOMPLETE 2
583
584/* BGP notify message codes. */
585#define BGP_NOTIFY_HEADER_ERR 1
586#define BGP_NOTIFY_OPEN_ERR 2
587#define BGP_NOTIFY_UPDATE_ERR 3
588#define BGP_NOTIFY_HOLD_ERR 4
589#define BGP_NOTIFY_FSM_ERR 5
590#define BGP_NOTIFY_CEASE 6
591#define BGP_NOTIFY_CAPABILITY_ERR 7
592#define BGP_NOTIFY_MAX 8
593
594/* BGP_NOTIFY_HEADER_ERR sub codes. */
595#define BGP_NOTIFY_HEADER_NOT_SYNC 1
596#define BGP_NOTIFY_HEADER_BAD_MESLEN 2
597#define BGP_NOTIFY_HEADER_BAD_MESTYPE 3
598#define BGP_NOTIFY_HEADER_MAX 4
599
600/* BGP_NOTIFY_OPEN_ERR sub codes. */
601#define BGP_NOTIFY_OPEN_UNSUP_VERSION 1
602#define BGP_NOTIFY_OPEN_BAD_PEER_AS 2
603#define BGP_NOTIFY_OPEN_BAD_BGP_IDENT 3
604#define BGP_NOTIFY_OPEN_UNSUP_PARAM 4
605#define BGP_NOTIFY_OPEN_AUTH_FAILURE 5
606#define BGP_NOTIFY_OPEN_UNACEP_HOLDTIME 6
607#define BGP_NOTIFY_OPEN_UNSUP_CAPBL 7
608#define BGP_NOTIFY_OPEN_MAX 8
609
610/* BGP_NOTIFY_UPDATE_ERR sub codes. */
611#define BGP_NOTIFY_UPDATE_MAL_ATTR 1
612#define BGP_NOTIFY_UPDATE_UNREC_ATTR 2
613#define BGP_NOTIFY_UPDATE_MISS_ATTR 3
614#define BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR 4
615#define BGP_NOTIFY_UPDATE_ATTR_LENG_ERR 5
616#define BGP_NOTIFY_UPDATE_INVAL_ORIGIN 6
617#define BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP 7
618#define BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP 8
619#define BGP_NOTIFY_UPDATE_OPT_ATTR_ERR 9
620#define BGP_NOTIFY_UPDATE_INVAL_NETWORK 10
621#define BGP_NOTIFY_UPDATE_MAL_AS_PATH 11
622#define BGP_NOTIFY_UPDATE_MAX 12
623
545acafb 624/* BGP_NOTIFY_CEASE sub codes (draft-ietf-idr-cease-subcode-05). */
718e3744 625#define BGP_NOTIFY_CEASE_MAX_PREFIX 1
626#define BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN 2
627#define BGP_NOTIFY_CEASE_PEER_UNCONFIG 3
628#define BGP_NOTIFY_CEASE_ADMIN_RESET 4
629#define BGP_NOTIFY_CEASE_CONNECT_REJECT 5
630#define BGP_NOTIFY_CEASE_CONFIG_CHANGE 6
545acafb 631#define BGP_NOTIFY_CEASE_COLLISION_RESOLUTION 7
632#define BGP_NOTIFY_CEASE_OUT_OF_RESOURCE 8
633#define BGP_NOTIFY_CEASE_MAX 9
718e3744 634
635/* BGP_NOTIFY_CAPABILITY_ERR sub codes (draft-ietf-idr-dynamic-cap-02). */
636#define BGP_NOTIFY_CAPABILITY_INVALID_ACTION 1
637#define BGP_NOTIFY_CAPABILITY_INVALID_LENGTH 2
638#define BGP_NOTIFY_CAPABILITY_MALFORMED_CODE 3
639#define BGP_NOTIFY_CAPABILITY_MAX 4
640
641/* BGP finite state machine status. */
642#define Idle 1
643#define Connect 2
644#define Active 3
645#define OpenSent 4
646#define OpenConfirm 5
647#define Established 6
648#define BGP_STATUS_MAX 7
649
650/* BGP finite state machine events. */
651#define BGP_Start 1
652#define BGP_Stop 2
653#define TCP_connection_open 3
654#define TCP_connection_closed 4
655#define TCP_connection_open_failed 5
656#define TCP_fatal_error 6
657#define ConnectRetry_timer_expired 7
658#define Hold_Timer_expired 8
659#define KeepAlive_timer_expired 9
660#define Receive_OPEN_message 10
661#define Receive_KEEPALIVE_message 11
662#define Receive_UPDATE_message 12
663#define Receive_NOTIFICATION_message 13
664#define BGP_EVENTS_MAX 14
665
666/* BGP timers default value. */
667#define BGP_INIT_START_TIMER 5
668#define BGP_ERROR_START_TIMER 30
669#define BGP_DEFAULT_HOLDTIME 180
670#define BGP_DEFAULT_KEEPALIVE 60
671#define BGP_DEFAULT_ASORIGINATE 15
672#define BGP_DEFAULT_EBGP_ROUTEADV 30
673#define BGP_DEFAULT_IBGP_ROUTEADV 5
674#define BGP_CLEAR_CONNECT_RETRY 20
675#define BGP_DEFAULT_CONNECT_RETRY 120
676
677/* BGP default local preference. */
678#define BGP_DEFAULT_LOCAL_PREF 100
679
538621f2 680/* BGP graceful restart */
681#define BGP_DEFAULT_RESTART_TIME 120
682#define BGP_DEFAULT_STALEPATH_TIME 360
683
718e3744 684/* SAFI which used in open capability negotiation. */
685#define BGP_SAFI_VPNV4 128
686#define BGP_SAFI_VPNV6 129
687
688/* Max TTL value. */
689#define TTL_MAX 255
690
691/* BGP uptime string length. */
692#define BGP_UPTIME_LEN 25
693
694/* Default configuration settings for bgpd. */
695#define BGP_VTY_PORT 2605
718e3744 696#define BGP_DEFAULT_CONFIG "bgpd.conf"
697
698/* Check AS path loop when we send NLRI. */
699/* #define BGP_SEND_ASPATH_CHECK */
700
701/* IBGP/EBGP identifier. We also have a CONFED peer, which is to say,
702 a peer who's AS is part of our Confederation. */
703enum
704{
705 BGP_PEER_IBGP,
706 BGP_PEER_EBGP,
707 BGP_PEER_INTERNAL,
708 BGP_PEER_CONFED
709};
710
711/* Flag for peer_clear_soft(). */
712enum bgp_clear_type
713{
714 BGP_CLEAR_SOFT_NONE,
715 BGP_CLEAR_SOFT_OUT,
716 BGP_CLEAR_SOFT_IN,
717 BGP_CLEAR_SOFT_BOTH,
fee0f4c6 718 BGP_CLEAR_SOFT_IN_ORF_PREFIX,
719 BGP_CLEAR_SOFT_RSCLIENT
718e3744 720};
721
722/* Macros. */
723#define BGP_INPUT(P) ((P)->ibuf)
724#define BGP_INPUT_PNT(P) (STREAM_PNT(BGP_INPUT(P)))
725
726/* Macro to check BGP information is alive or not. */
727#define BGP_INFO_HOLDDOWN(BI) \
728 (! CHECK_FLAG ((BI)->flags, BGP_INFO_VALID) \
729 || CHECK_FLAG ((BI)->flags, BGP_INFO_HISTORY) \
730 || CHECK_FLAG ((BI)->flags, BGP_INFO_DAMPED))
731
732/* Count prefix size from mask length */
733#define PSIZE(a) (((a) + 7) / (8))
734
735/* BGP error codes. */
736#define BGP_SUCCESS 0
737#define BGP_ERR_INVALID_VALUE -1
738#define BGP_ERR_INVALID_FLAG -2
739#define BGP_ERR_INVALID_AS -3
740#define BGP_ERR_INVALID_BGP -4
741#define BGP_ERR_PEER_GROUP_MEMBER -5
742#define BGP_ERR_MULTIPLE_INSTANCE_USED -6
743#define BGP_ERR_PEER_GROUP_MEMBER_EXISTS -7
744#define BGP_ERR_PEER_BELONGS_TO_GROUP -8
745#define BGP_ERR_PEER_GROUP_AF_UNCONFIGURED -9
746#define BGP_ERR_PEER_GROUP_NO_REMOTE_AS -10
747#define BGP_ERR_PEER_GROUP_CANT_CHANGE -11
748#define BGP_ERR_PEER_GROUP_MISMATCH -12
749#define BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT -13
750#define BGP_ERR_MULTIPLE_INSTANCE_NOT_SET -14
751#define BGP_ERR_AS_MISMATCH -15
752#define BGP_ERR_PEER_INACTIVE -16
753#define BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER -17
754#define BGP_ERR_PEER_GROUP_HAS_THE_FLAG -18
755#define BGP_ERR_PEER_FLAG_CONFLICT -19
756#define BGP_ERR_PEER_GROUP_SHUTDOWN -20
757#define BGP_ERR_PEER_FILTER_CONFLICT -21
758#define BGP_ERR_NOT_INTERNAL_PEER -22
759#define BGP_ERR_REMOVE_PRIVATE_AS -23
760#define BGP_ERR_AF_UNCONFIGURED -24
761#define BGP_ERR_SOFT_RECONFIG_UNCONFIGURED -25
762#define BGP_ERR_INSTANCE_MISMATCH -26
763#define BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP -27
764#define BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS -28
765#define BGP_ERR_MAX -29
766
767extern struct bgp_master *bm;
768
769extern struct thread_master *master;
770
771/* Prototypes. */
772void bgp_terminate (void);
773void bgp_reset (void);
774void bgp_zclient_reset ();
775int bgp_nexthop_set (union sockunion *, union sockunion *,
776 struct bgp_nexthop *, struct peer *);
777struct bgp *bgp_get_default ();
fd79ac91 778struct bgp *bgp_lookup (as_t, const char *);
779struct bgp *bgp_lookup_by_name (const char *);
718e3744 780struct peer *peer_lookup (struct bgp *, union sockunion *);
fd79ac91 781struct peer_group *peer_group_lookup (struct bgp *, const char *);
782struct peer_group *peer_group_get (struct bgp *, const char *);
718e3744 783struct peer *peer_lookup_with_open (union sockunion *, as_t, struct in_addr *,
784 int *);
785int peer_sort (struct peer *peer);
786int peer_active (struct peer *);
787int peer_active_nego (struct peer *);
788struct peer *peer_create_accept (struct bgp *);
789char *peer_uptime (time_t, char *, size_t);
790void bgp_config_write_family_header (struct vty *, afi_t, safi_t, int *);
791\f
792void bgp_master_init ();
793
794void bgp_init ();
795
796int bgp_option_set (int);
797int bgp_option_unset (int);
798int bgp_option_check (int);
799
fd79ac91 800int bgp_get (struct bgp **, as_t *, const char *);
718e3744 801int bgp_delete (struct bgp *);
802
803int bgp_flag_set (struct bgp *, int);
804int bgp_flag_unset (struct bgp *, int);
805int bgp_flag_check (struct bgp *, int);
806
807int bgp_router_id_set (struct bgp *, struct in_addr *);
808int bgp_router_id_unset (struct bgp *);
809
810int bgp_cluster_id_set (struct bgp *, struct in_addr *);
811int bgp_cluster_id_unset (struct bgp *);
812
813int bgp_confederation_id_set (struct bgp *, as_t);
814int bgp_confederation_id_unset (struct bgp *);
815int bgp_confederation_peers_check (struct bgp *, as_t);
816
817int bgp_confederation_peers_add (struct bgp *, as_t);
818int bgp_confederation_peers_remove (struct bgp *, as_t);
819
820int bgp_timers_set (struct bgp *, u_int32_t, u_int32_t);
821int bgp_timers_unset (struct bgp *);
822
823int bgp_default_local_preference_set (struct bgp *, u_int32_t);
824int bgp_default_local_preference_unset (struct bgp *);
825
fee0f4c6 826int peer_rsclient_active (struct peer *);
827
718e3744 828int peer_remote_as (struct bgp *, union sockunion *, as_t *, afi_t, safi_t);
fd79ac91 829int peer_group_remote_as (struct bgp *, const char *, as_t *);
718e3744 830int peer_delete (struct peer *peer);
831int peer_group_delete (struct peer_group *);
832int peer_group_remote_as_delete (struct peer_group *);
833
834int peer_activate (struct peer *, afi_t, safi_t);
835int peer_deactivate (struct peer *, afi_t, safi_t);
836
837int peer_group_bind (struct bgp *, union sockunion *, struct peer_group *,
838 afi_t, safi_t, as_t *);
839int peer_group_unbind (struct bgp *, struct peer *, struct peer_group *,
840 afi_t, safi_t);
841
842int peer_flag_set (struct peer *, u_int32_t);
843int peer_flag_unset (struct peer *, u_int32_t);
844
845int peer_af_flag_set (struct peer *, afi_t, safi_t, u_int32_t);
846int peer_af_flag_unset (struct peer *, afi_t, safi_t, u_int32_t);
847int peer_af_flag_check (struct peer *, afi_t, safi_t, u_int32_t);
848
849int peer_ebgp_multihop_set (struct peer *, int);
850int peer_ebgp_multihop_unset (struct peer *);
851
852int peer_description_set (struct peer *, char *);
853int peer_description_unset (struct peer *);
854
fd79ac91 855int peer_update_source_if_set (struct peer *, const char *);
718e3744 856int peer_update_source_addr_set (struct peer *, union sockunion *);
857int peer_update_source_unset (struct peer *);
858
fd79ac91 859int peer_default_originate_set (struct peer *, afi_t, safi_t, const char *);
718e3744 860int peer_default_originate_unset (struct peer *, afi_t, safi_t);
861
862int peer_port_set (struct peer *, u_int16_t);
863int peer_port_unset (struct peer *);
864
865int peer_weight_set (struct peer *, u_int16_t);
866int peer_weight_unset (struct peer *);
867
868int peer_timers_set (struct peer *, u_int32_t, u_int32_t);
869int peer_timers_unset (struct peer *);
870
871int peer_timers_connect_set (struct peer *, u_int32_t);
872int peer_timers_connect_unset (struct peer *);
873
874int peer_advertise_interval_set (struct peer *, u_int32_t);
875int peer_advertise_interval_unset (struct peer *);
876
fd79ac91 877int peer_interface_set (struct peer *, const char *);
718e3744 878int peer_interface_unset (struct peer *);
879
fd79ac91 880int peer_distribute_set (struct peer *, afi_t, safi_t, int, const char *);
718e3744 881int peer_distribute_unset (struct peer *, afi_t, safi_t, int);
882
883int peer_allowas_in_set (struct peer *, afi_t, safi_t, int);
884int peer_allowas_in_unset (struct peer *, afi_t, safi_t);
885
886int peer_local_as_set (struct peer *, as_t, int);
887int peer_local_as_unset (struct peer *);
888
fd79ac91 889int peer_prefix_list_set (struct peer *, afi_t, safi_t, int, const char *);
718e3744 890int peer_prefix_list_unset (struct peer *, afi_t, safi_t, int);
891
fd79ac91 892int peer_aslist_set (struct peer *, afi_t, safi_t, int, const char *);
718e3744 893int peer_aslist_unset (struct peer *,afi_t, safi_t, int);
894
fd79ac91 895int peer_route_map_set (struct peer *, afi_t, safi_t, int, const char *);
718e3744 896int peer_route_map_unset (struct peer *, afi_t, safi_t, int);
897
fd79ac91 898int peer_unsuppress_map_set (struct peer *, afi_t, safi_t, const char *);
718e3744 899int peer_unsuppress_map_unset (struct peer *, afi_t, safi_t);
900
0a486e5f 901int peer_maximum_prefix_set (struct peer *, afi_t, safi_t, u_int32_t, u_char, int, u_int16_t);
718e3744 902int peer_maximum_prefix_unset (struct peer *, afi_t, safi_t);
903
904int peer_clear (struct peer *);
905int peer_clear_soft (struct peer *, afi_t, safi_t, enum bgp_clear_type);
93406d87 906
907void peer_nsf_stop (struct peer *);