blob: a8bfa52f54187a1bc011367b3c99be5e057e3406 [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)
73#define BGP_CONFIG_DEFAULT_LOCAL_PREF (1 << 3)
74
75 /* BGP router identifier. */
76 struct in_addr router_id;
77
78 /* BGP route reflector cluster ID. */
79 struct in_addr cluster_id;
80
81 /* BGP confederation information. */
82 as_t confed_id;
83 as_t *confed_peers;
84 int confed_peers_cnt;
85
86 /* BGP flags. */
87 u_int16_t flags;
88#define BGP_FLAG_ALWAYS_COMPARE_MED (1 << 0)
89#define BGP_FLAG_DETERMINISTIC_MED (1 << 1)
90#define BGP_FLAG_MED_MISSING_AS_WORST (1 << 2)
91#define BGP_FLAG_MED_CONFED (1 << 3)
92#define BGP_FLAG_NO_DEFAULT_IPV4 (1 << 4)
93#define BGP_FLAG_NO_CLIENT_TO_CLIENT (1 << 5)
94#define BGP_FLAG_ENFORCE_FIRST_AS (1 << 6)
95#define BGP_FLAG_COMPARE_ROUTER_ID (1 << 7)
96#define BGP_FLAG_ASPATH_IGNORE (1 << 8)
97#define BGP_FLAG_IMPORT_CHECK (1 << 9)
98#define BGP_FLAG_NO_FAST_EXT_FAILOVER (1 << 10)
paul848973c2003-08-13 00:32:49 +000099#define BGP_FLAG_LOG_NEIGHBOR_CHANGES (1 << 11)
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;
139};
140
141/* BGP peer-group support. */
142struct peer_group
143{
144 /* Name of the peer-group. */
145 char *name;
146
147 /* Pointer to BGP. */
148 struct bgp *bgp;
149
150 /* Peer-group client list. */
151 struct list *peer;
152
153 /* Peer-group config */
154 struct peer *conf;
155};
156
157/* BGP Notify message format. */
158struct bgp_notify
159{
160 u_char code;
161 u_char subcode;
162 char *data;
163 bgp_size_t length;
164};
165
166/* Next hop self address. */
167struct bgp_nexthop
168{
169 struct interface *ifp;
170 struct in_addr v4;
171#ifdef HAVE_IPV6
172 struct in6_addr v6_global;
173 struct in6_addr v6_local;
174#endif /* HAVE_IPV6 */
175};
176
177/* BGP router distinguisher value. */
178#define BGP_RD_SIZE 8
179
180struct bgp_rd
181{
182 u_char val[BGP_RD_SIZE];
183};
184
185/* BGP filter structure. */
186struct bgp_filter
187{
188 /* Distribute-list. */
189 struct
190 {
191 char *name;
192 struct access_list *alist;
193 } dlist[FILTER_MAX];
194
195 /* Prefix-list. */
196 struct
197 {
198 char *name;
199 struct prefix_list *plist;
200 } plist[FILTER_MAX];
201
202 /* Filter-list. */
203 struct
204 {
205 char *name;
206 struct as_list *aslist;
207 } aslist[FILTER_MAX];
208
209 /* Route-map. */
210 struct
211 {
212 char *name;
213 struct route_map *map;
214 } map[FILTER_MAX];
215
216 /* Unsuppress-map. */
217 struct
218 {
219 char *name;
220 struct route_map *map;
221 } usmap;
222};
223
224/* BGP neighbor structure. */
225struct peer
226{
227 /* BGP structure. */
228 struct bgp *bgp;
229
230 /* BGP peer group. */
231 struct peer_group *group;
232 u_char af_group[AFI_MAX][SAFI_MAX];
233
234 /* Peer's remote AS number. */
235 as_t as;
236
237 /* Peer's local AS number. */
238 as_t local_as;
239
240 /* Peer's Change local AS number. */
241 as_t change_local_as;
242
243 /* Remote router ID. */
244 struct in_addr remote_id;
245
246 /* Local router ID. */
247 struct in_addr local_id;
248
249 /* Packet receive and send buffer. */
250 struct stream *ibuf;
251 struct stream_fifo *obuf;
252 struct stream *work;
253
254 /* Status of the peer. */
255 int status;
256 int ostatus;
257
258 /* Peer information */
paul6ad23f02004-02-17 19:45:10 +0000259 int *fd; /* connection in use: -> local||accept */
260 int ttl; /* TTL of TCP connection to the peer. */
261 int fd_local; /* locally initiated connection */
262 int fd_accept; /* remote initiated/accepted connection */
263 char *desc; /* Description of the peer. */
264 unsigned short port; /* Destination port for peer */
265 char *host; /* Printable address of the peer. */
266 union sockunion su; /* Sockunion address of the peer. */
267 time_t uptime; /* Last Up/Down time */
268 time_t readtime; /* Last read time */
269 time_t resettime; /* Last reset time */
paul718e3742002-12-13 20:15:29 +0000270
paul6ad23f02004-02-17 19:45:10 +0000271 unsigned int ifindex; /* ifindex of the BGP connection. */
272 char *ifname; /* bind interface name. */
273 char *update_if; /* interface to send from */
274 union sockunion *update_source; /* sockunion to send from */
275 struct zlog *log; /* log socket */
276 u_char version; /* Peer BGP version. */
paul718e3742002-12-13 20:15:29 +0000277
paul6ad23f02004-02-17 19:45:10 +0000278 union sockunion *su_local; /* Sockunion of local address. */
279 union sockunion *su_remote; /* Sockunion of remote address. */
280 int shared_network; /* Is this peer shared same network. */
281 struct bgp_nexthop nexthop; /* Nexthop */
paul718e3742002-12-13 20:15:29 +0000282
283 /* Peer address family configuration. */
284 u_char afc[AFI_MAX][SAFI_MAX];
285 u_char afc_nego[AFI_MAX][SAFI_MAX];
286 u_char afc_adv[AFI_MAX][SAFI_MAX];
287 u_char afc_recv[AFI_MAX][SAFI_MAX];
288
289 /* Capability Flags.*/
290 u_char cap;
291#define PEER_CAP_REFRESH_ADV (1 << 0) /* refresh advertised */
292#define PEER_CAP_REFRESH_OLD_RCV (1 << 1) /* refresh old received */
293#define PEER_CAP_REFRESH_NEW_RCV (1 << 2) /* refresh rfc received */
294#define PEER_CAP_DYNAMIC_ADV (1 << 3) /* dynamic advertised */
295#define PEER_CAP_DYNAMIC_RCV (1 << 4) /* dynamic received */
296
297 /* Capability Flags.*/
298 u_int16_t af_cap[AFI_MAX][SAFI_MAX];
299#define PEER_CAP_ORF_PREFIX_SM_ADV (1 << 0) /* send-mode advertised */
300#define PEER_CAP_ORF_PREFIX_RM_ADV (1 << 1) /* receive-mode advertised */
301#define PEER_CAP_ORF_PREFIX_SM_RCV (1 << 2) /* send-mode received */
302#define PEER_CAP_ORF_PREFIX_RM_RCV (1 << 3) /* receive-mode received */
303#define PEER_CAP_ORF_PREFIX_SM_OLD_RCV (1 << 4) /* send-mode received */
304#define PEER_CAP_ORF_PREFIX_RM_OLD_RCV (1 << 5) /* receive-mode received */
305
306 /* Global configuration flags. */
307 u_int32_t flags;
308#define PEER_FLAG_PASSIVE (1 << 0) /* passive mode */
309#define PEER_FLAG_SHUTDOWN (1 << 1) /* shutdown */
310#define PEER_FLAG_DONT_CAPABILITY (1 << 2) /* dont-capability */
311#define PEER_FLAG_OVERRIDE_CAPABILITY (1 << 3) /* override-capability */
312#define PEER_FLAG_STRICT_CAP_MATCH (1 << 4) /* strict-match */
313#define PEER_FLAG_NO_ROUTE_REFRESH_CAP (1 << 5) /* route-refresh */
314#define PEER_FLAG_DYNAMIC_CAPABILITY (1 << 6) /* dynamic capability */
315#define PEER_FLAG_ENFORCE_MULTIHOP (1 << 7) /* enforce-multihop */
316#define PEER_FLAG_LOCAL_AS_NO_PREPEND (1 << 8) /* local-as no-prepend */
317
318 /* Per AF configuration flags. */
319 u_int32_t af_flags[AFI_MAX][SAFI_MAX];
320#define PEER_FLAG_SEND_COMMUNITY (1 << 0) /* send-community */
321#define PEER_FLAG_SEND_EXT_COMMUNITY (1 << 1) /* send-community ext. */
322#define PEER_FLAG_NEXTHOP_SELF (1 << 2) /* next-hop-self */
323#define PEER_FLAG_REFLECTOR_CLIENT (1 << 3) /* reflector-client */
324#define PEER_FLAG_RSERVER_CLIENT (1 << 4) /* route-server-client */
325#define PEER_FLAG_SOFT_RECONFIG (1 << 5) /* soft-reconfiguration */
326#define PEER_FLAG_AS_PATH_UNCHANGED (1 << 6) /* transparent-as */
327#define PEER_FLAG_NEXTHOP_UNCHANGED (1 << 7) /* transparent-next-hop */
328#define PEER_FLAG_MED_UNCHANGED (1 << 8) /* transparent-next-hop */
329#define PEER_FLAG_DEFAULT_ORIGINATE (1 << 9) /* default-originate */
330#define PEER_FLAG_REMOVE_PRIVATE_AS (1 << 10) /* remove-private-as */
331#define PEER_FLAG_ALLOWAS_IN (1 << 11) /* set allowas-in */
332#define PEER_FLAG_ORF_PREFIX_SM (1 << 12) /* orf capability send-mode */
333#define PEER_FLAG_ORF_PREFIX_RM (1 << 13) /* orf capability receive-mode */
334#define PEER_FLAG_MAX_PREFIX (1 << 14) /* maximum prefix */
335#define PEER_FLAG_MAX_PREFIX_WARNING (1 << 15) /* maximum prefix warning-only */
336
337 /* default-originate route-map. */
338 struct
339 {
340 char *name;
341 struct route_map *map;
342 } default_rmap[AFI_MAX][SAFI_MAX];
343
344 /* Peer status flags. */
345 u_int16_t sflags;
346#define PEER_STATUS_ACCEPT_PEER (1 << 0) /* accept peer */
347#define PEER_STATUS_PREFIX_OVERFLOW (1 << 1) /* prefix-overflow */
348#define PEER_STATUS_CAPABILITY_OPEN (1 << 2) /* capability open send */
349#define PEER_STATUS_HAVE_ACCEPT (1 << 3) /* accept peer's parent */
350#define PEER_STATUS_GROUP (1 << 4) /* peer-group conf */
351
352 /* Peer status af flags. */
353 u_int16_t af_sflags[AFI_MAX][SAFI_MAX];
354#define PEER_STATUS_ORF_PREFIX_SEND (1 << 0) /* prefix-list send peer */
355#define PEER_STATUS_ORF_WAIT_REFRESH (1 << 1) /* wait refresh received peer */
356#define PEER_STATUS_DEFAULT_ORIGINATE (1 << 2) /* default-originate peer */
357
358 /* Default attribute value for the peer. */
359 u_int32_t config;
360#define PEER_CONFIG_WEIGHT (1 << 0) /* Default weight. */
361#define PEER_CONFIG_TIMER (1 << 1) /* keepalive & holdtime */
362#define PEER_CONFIG_CONNECT (1 << 2) /* connect */
363#define PEER_CONFIG_ROUTEADV (1 << 3) /* route advertise */
364 u_int32_t weight;
365 u_int32_t holdtime;
366 u_int32_t keepalive;
367 u_int32_t connect;
368 u_int32_t routeadv;
369
370 /* Timer values. */
371 u_int32_t v_start;
372 u_int32_t v_connect;
373 u_int32_t v_holdtime;
374 u_int32_t v_keepalive;
375 u_int32_t v_asorig;
376 u_int32_t v_routeadv;
377
378 /* Threads. */
379 struct thread *t_read;
380 struct thread *t_write;
381 struct thread *t_start;
382 struct thread *t_connect;
383 struct thread *t_holdtime;
384 struct thread *t_keepalive;
385 struct thread *t_asorig;
386 struct thread *t_routeadv;
387
388 /* Statistics field */
389 u_int32_t open_in; /* Open message input count */
390 u_int32_t open_out; /* Open message output count */
391 u_int32_t update_in; /* Update message input count */
392 u_int32_t update_out; /* Update message ouput count */
393 time_t update_time; /* Update message received time. */
394 u_int32_t keepalive_in; /* Keepalive input count */
395 u_int32_t keepalive_out; /* Keepalive output count */
396 u_int32_t notify_in; /* Notify input count */
397 u_int32_t notify_out; /* Notify output count */
398 u_int32_t refresh_in; /* Route Refresh input count */
399 u_int32_t refresh_out; /* Route Refresh output count */
400 u_int32_t dynamic_cap_in; /* Dynamic Capability input count. */
401 u_int32_t dynamic_cap_out; /* Dynamic Capability output count. */
402
403 /* BGP state count */
404 u_int32_t established; /* Established */
405 u_int32_t dropped; /* Dropped */
406
407 /* Syncronization list and time. */
408 struct bgp_synchronize *sync[AFI_MAX][SAFI_MAX];
409 time_t synctime;
410
411 /* Send prefix count. */
412 unsigned long scount[AFI_MAX][SAFI_MAX];
413
414 /* Announcement attribute hash. */
415 struct hash *hash[AFI_MAX][SAFI_MAX];
416
417 /* Notify data. */
418 struct bgp_notify notify;
419
420 /* Whole packet size to be read. */
421 unsigned long packet_size;
422
423 /* Filter structure. */
424 struct bgp_filter filter[AFI_MAX][SAFI_MAX];
425
426 /* ORF Prefix-list */
427 struct prefix_list *orf_plist[AFI_MAX][SAFI_MAX];
428
429 /* Prefix count. */
430 unsigned long pcount[AFI_MAX][SAFI_MAX];
431
432 /* Max prefix count. */
433 unsigned long pmax[AFI_MAX][SAFI_MAX];
434
435 /* allowas-in. */
436 char allowas_in[AFI_MAX][SAFI_MAX];
paulac41b2a2003-08-12 05:32:27 +0000437
438 /* The kind of route-map Flags.*/
439 u_char rmap_type;
440#define PEER_RMAP_TYPE_IN (1 << 0) /* neighbor route-map in */
441#define PEER_RMAP_TYPE_OUT (1 << 1) /* neighbor route-map out */
442#define PEER_RMAP_TYPE_NETWORK (1 << 2) /* network route-map */
443#define PEER_RMAP_TYPE_REDISTRIBUTE (1 << 3) /* redistribute route-map */
444#define PEER_RMAP_TYPE_DEFAULT (1 << 4) /* default-originate route-map */
445#define PEER_RMAP_TYPE_NOSET (1 << 5) /* not allow to set commands */
paul718e3742002-12-13 20:15:29 +0000446};
447
448/* This structure's member directly points incoming packet data
449 stream. */
450struct bgp_nlri
451{
452 /* AFI. */
453 afi_t afi;
454
455 /* SAFI. */
456 safi_t safi;
457
458 /* Pointer to NLRI byte stream. */
459 u_char *nlri;
460
461 /* Length of whole NLRI. */
462 bgp_size_t length;
463};
464
465/* BGP versions. */
466#define BGP_VERSION_4 4
467#define BGP_VERSION_MP_4_DRAFT_00 40
468
469/* Default BGP port number. */
470#define BGP_PORT_DEFAULT 179
471
472/* BGP message header and packet size. */
473#define BGP_MARKER_SIZE 16
474#define BGP_HEADER_SIZE 19
475#define BGP_MAX_PACKET_SIZE 4096
476
477/* BGP minimum message size. */
478#define BGP_MSG_OPEN_MIN_SIZE (BGP_HEADER_SIZE + 10)
479#define BGP_MSG_UPDATE_MIN_SIZE (BGP_HEADER_SIZE + 4)
480#define BGP_MSG_NOTIFY_MIN_SIZE (BGP_HEADER_SIZE + 2)
481#define BGP_MSG_KEEPALIVE_MIN_SIZE (BGP_HEADER_SIZE + 0)
482#define BGP_MSG_ROUTE_REFRESH_MIN_SIZE (BGP_HEADER_SIZE + 4)
483#define BGP_MSG_CAPABILITY_MIN_SIZE (BGP_HEADER_SIZE + 3)
484
485/* BGP message types. */
486#define BGP_MSG_OPEN 1
487#define BGP_MSG_UPDATE 2
488#define BGP_MSG_NOTIFY 3
489#define BGP_MSG_KEEPALIVE 4
490#define BGP_MSG_ROUTE_REFRESH_NEW 5
491#define BGP_MSG_CAPABILITY 6
492#define BGP_MSG_ROUTE_REFRESH_OLD 128
493
494/* BGP open optional parameter. */
495#define BGP_OPEN_OPT_AUTH 1
496#define BGP_OPEN_OPT_CAP 2
497
498/* BGP4 attribute type codes. */
499#define BGP_ATTR_ORIGIN 1
500#define BGP_ATTR_AS_PATH 2
501#define BGP_ATTR_NEXT_HOP 3
502#define BGP_ATTR_MULTI_EXIT_DISC 4
503#define BGP_ATTR_LOCAL_PREF 5
504#define BGP_ATTR_ATOMIC_AGGREGATE 6
505#define BGP_ATTR_AGGREGATOR 7
506#define BGP_ATTR_COMMUNITIES 8
507#define BGP_ATTR_ORIGINATOR_ID 9
508#define BGP_ATTR_CLUSTER_LIST 10
509#define BGP_ATTR_DPA 11
510#define BGP_ATTR_ADVERTISER 12
511#define BGP_ATTR_RCID_PATH 13
512#define BGP_ATTR_MP_REACH_NLRI 14
513#define BGP_ATTR_MP_UNREACH_NLRI 15
514#define BGP_ATTR_EXT_COMMUNITIES 16
515
516/* BGP update origin. */
517#define BGP_ORIGIN_IGP 0
518#define BGP_ORIGIN_EGP 1
519#define BGP_ORIGIN_INCOMPLETE 2
520
521/* BGP notify message codes. */
522#define BGP_NOTIFY_HEADER_ERR 1
523#define BGP_NOTIFY_OPEN_ERR 2
524#define BGP_NOTIFY_UPDATE_ERR 3
525#define BGP_NOTIFY_HOLD_ERR 4
526#define BGP_NOTIFY_FSM_ERR 5
527#define BGP_NOTIFY_CEASE 6
528#define BGP_NOTIFY_CAPABILITY_ERR 7
529#define BGP_NOTIFY_MAX 8
530
531/* BGP_NOTIFY_HEADER_ERR sub codes. */
532#define BGP_NOTIFY_HEADER_NOT_SYNC 1
533#define BGP_NOTIFY_HEADER_BAD_MESLEN 2
534#define BGP_NOTIFY_HEADER_BAD_MESTYPE 3
535#define BGP_NOTIFY_HEADER_MAX 4
536
537/* BGP_NOTIFY_OPEN_ERR sub codes. */
538#define BGP_NOTIFY_OPEN_UNSUP_VERSION 1
539#define BGP_NOTIFY_OPEN_BAD_PEER_AS 2
540#define BGP_NOTIFY_OPEN_BAD_BGP_IDENT 3
541#define BGP_NOTIFY_OPEN_UNSUP_PARAM 4
542#define BGP_NOTIFY_OPEN_AUTH_FAILURE 5
543#define BGP_NOTIFY_OPEN_UNACEP_HOLDTIME 6
544#define BGP_NOTIFY_OPEN_UNSUP_CAPBL 7
545#define BGP_NOTIFY_OPEN_MAX 8
546
547/* BGP_NOTIFY_UPDATE_ERR sub codes. */
548#define BGP_NOTIFY_UPDATE_MAL_ATTR 1
549#define BGP_NOTIFY_UPDATE_UNREC_ATTR 2
550#define BGP_NOTIFY_UPDATE_MISS_ATTR 3
551#define BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR 4
552#define BGP_NOTIFY_UPDATE_ATTR_LENG_ERR 5
553#define BGP_NOTIFY_UPDATE_INVAL_ORIGIN 6
554#define BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP 7
555#define BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP 8
556#define BGP_NOTIFY_UPDATE_OPT_ATTR_ERR 9
557#define BGP_NOTIFY_UPDATE_INVAL_NETWORK 10
558#define BGP_NOTIFY_UPDATE_MAL_AS_PATH 11
559#define BGP_NOTIFY_UPDATE_MAX 12
560
561/* BGP_NOTIFY_CEASE sub codes (draft-ietf-idr-cease-subcode-00). */
562#define BGP_NOTIFY_CEASE_MAX_PREFIX 1
563#define BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN 2
564#define BGP_NOTIFY_CEASE_PEER_UNCONFIG 3
565#define BGP_NOTIFY_CEASE_ADMIN_RESET 4
566#define BGP_NOTIFY_CEASE_CONNECT_REJECT 5
567#define BGP_NOTIFY_CEASE_CONFIG_CHANGE 6
568#define BGP_NOTIFY_CEASE_MAX 7
569
570/* BGP_NOTIFY_CAPABILITY_ERR sub codes (draft-ietf-idr-dynamic-cap-02). */
571#define BGP_NOTIFY_CAPABILITY_INVALID_ACTION 1
572#define BGP_NOTIFY_CAPABILITY_INVALID_LENGTH 2
573#define BGP_NOTIFY_CAPABILITY_MALFORMED_CODE 3
574#define BGP_NOTIFY_CAPABILITY_MAX 4
575
576/* BGP finite state machine status. */
577#define Idle 1
578#define Connect 2
579#define Active 3
580#define OpenSent 4
581#define OpenConfirm 5
582#define Established 6
583#define BGP_STATUS_MAX 7
584
585/* BGP finite state machine events. */
586#define BGP_Start 1
587#define BGP_Stop 2
588#define TCP_connection_open 3
589#define TCP_connection_closed 4
590#define TCP_connection_open_failed 5
591#define TCP_fatal_error 6
592#define ConnectRetry_timer_expired 7
593#define Hold_Timer_expired 8
594#define KeepAlive_timer_expired 9
595#define Receive_OPEN_message 10
596#define Receive_KEEPALIVE_message 11
597#define Receive_UPDATE_message 12
598#define Receive_NOTIFICATION_message 13
599#define BGP_EVENTS_MAX 14
600
601/* BGP timers default value. */
602#define BGP_INIT_START_TIMER 5
603#define BGP_ERROR_START_TIMER 30
604#define BGP_DEFAULT_HOLDTIME 180
605#define BGP_DEFAULT_KEEPALIVE 60
606#define BGP_DEFAULT_ASORIGINATE 15
607#define BGP_DEFAULT_EBGP_ROUTEADV 30
608#define BGP_DEFAULT_IBGP_ROUTEADV 5
609#define BGP_CLEAR_CONNECT_RETRY 20
610#define BGP_DEFAULT_CONNECT_RETRY 120
611
612/* BGP default local preference. */
613#define BGP_DEFAULT_LOCAL_PREF 100
614
615/* SAFI which used in open capability negotiation. */
616#define BGP_SAFI_VPNV4 128
617#define BGP_SAFI_VPNV6 129
618
619/* Max TTL value. */
620#define TTL_MAX 255
621
622/* BGP uptime string length. */
623#define BGP_UPTIME_LEN 25
624
625/* Default configuration settings for bgpd. */
626#define BGP_VTY_PORT 2605
paul718e3742002-12-13 20:15:29 +0000627#define BGP_DEFAULT_CONFIG "bgpd.conf"
628
629/* Check AS path loop when we send NLRI. */
630/* #define BGP_SEND_ASPATH_CHECK */
631
632/* IBGP/EBGP identifier. We also have a CONFED peer, which is to say,
633 a peer who's AS is part of our Confederation. */
634enum
635{
636 BGP_PEER_IBGP,
637 BGP_PEER_EBGP,
638 BGP_PEER_INTERNAL,
639 BGP_PEER_CONFED
640};
641
642/* Flag for peer_clear_soft(). */
643enum bgp_clear_type
644{
645 BGP_CLEAR_SOFT_NONE,
646 BGP_CLEAR_SOFT_OUT,
647 BGP_CLEAR_SOFT_IN,
648 BGP_CLEAR_SOFT_BOTH,
649 BGP_CLEAR_SOFT_IN_ORF_PREFIX
650};
651
652/* Macros. */
653#define BGP_INPUT(P) ((P)->ibuf)
654#define BGP_INPUT_PNT(P) (STREAM_PNT(BGP_INPUT(P)))
655
656/* Macro to check BGP information is alive or not. */
657#define BGP_INFO_HOLDDOWN(BI) \
658 (! CHECK_FLAG ((BI)->flags, BGP_INFO_VALID) \
659 || CHECK_FLAG ((BI)->flags, BGP_INFO_HISTORY) \
660 || CHECK_FLAG ((BI)->flags, BGP_INFO_DAMPED))
661
662/* Count prefix size from mask length */
663#define PSIZE(a) (((a) + 7) / (8))
664
665/* BGP error codes. */
666#define BGP_SUCCESS 0
667#define BGP_ERR_INVALID_VALUE -1
668#define BGP_ERR_INVALID_FLAG -2
669#define BGP_ERR_INVALID_AS -3
670#define BGP_ERR_INVALID_BGP -4
671#define BGP_ERR_PEER_GROUP_MEMBER -5
672#define BGP_ERR_MULTIPLE_INSTANCE_USED -6
673#define BGP_ERR_PEER_GROUP_MEMBER_EXISTS -7
674#define BGP_ERR_PEER_BELONGS_TO_GROUP -8
675#define BGP_ERR_PEER_GROUP_AF_UNCONFIGURED -9
676#define BGP_ERR_PEER_GROUP_NO_REMOTE_AS -10
677#define BGP_ERR_PEER_GROUP_CANT_CHANGE -11
678#define BGP_ERR_PEER_GROUP_MISMATCH -12
679#define BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT -13
680#define BGP_ERR_MULTIPLE_INSTANCE_NOT_SET -14
681#define BGP_ERR_AS_MISMATCH -15
682#define BGP_ERR_PEER_INACTIVE -16
683#define BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER -17
684#define BGP_ERR_PEER_GROUP_HAS_THE_FLAG -18
685#define BGP_ERR_PEER_FLAG_CONFLICT -19
686#define BGP_ERR_PEER_GROUP_SHUTDOWN -20
687#define BGP_ERR_PEER_FILTER_CONFLICT -21
688#define BGP_ERR_NOT_INTERNAL_PEER -22
689#define BGP_ERR_REMOVE_PRIVATE_AS -23
690#define BGP_ERR_AF_UNCONFIGURED -24
691#define BGP_ERR_SOFT_RECONFIG_UNCONFIGURED -25
692#define BGP_ERR_INSTANCE_MISMATCH -26
693#define BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP -27
694#define BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS -28
695#define BGP_ERR_MAX -29
696
697extern struct bgp_master *bm;
698
699extern struct thread_master *master;
700
701/* Prototypes. */
702void bgp_terminate (void);
703void bgp_reset (void);
704void bgp_zclient_reset ();
705int bgp_nexthop_set (union sockunion *, union sockunion *,
706 struct bgp_nexthop *, struct peer *);
paul6cbbc3c2003-04-28 17:11:02 +0000707struct bgp_master *bgp_get_master ();
paul718e3742002-12-13 20:15:29 +0000708struct bgp *bgp_get_default ();
709struct bgp *bgp_lookup (as_t, char *);
710struct bgp *bgp_lookup_by_name (char *);
711struct peer *peer_lookup (struct bgp *, union sockunion *);
712struct peer_group *peer_group_lookup (struct bgp *, char *);
713struct peer_group *peer_group_get (struct bgp *, char *);
714struct peer *peer_lookup_with_open (union sockunion *, as_t, struct in_addr *,
715 int *);
716int peer_sort (struct peer *peer);
717int peer_active (struct peer *);
718int peer_active_nego (struct peer *);
719struct peer *peer_create_accept (struct bgp *);
720char *peer_uptime (time_t, char *, size_t);
721void bgp_config_write_family_header (struct vty *, afi_t, safi_t, int *);
722
723void bgp_master_init ();
724
725void bgp_init ();
726
727int bgp_option_set (int);
728int bgp_option_unset (int);
729int bgp_option_check (int);
730
731int bgp_get (struct bgp **, as_t *, char *);
732int bgp_delete (struct bgp *);
733
734int bgp_flag_set (struct bgp *, int);
735int bgp_flag_unset (struct bgp *, int);
736int bgp_flag_check (struct bgp *, int);
737
738int bgp_router_id_set (struct bgp *, struct in_addr *);
739int bgp_router_id_unset (struct bgp *);
740
741int bgp_cluster_id_set (struct bgp *, struct in_addr *);
742int bgp_cluster_id_unset (struct bgp *);
743
744int bgp_confederation_id_set (struct bgp *, as_t);
745int bgp_confederation_id_unset (struct bgp *);
746int bgp_confederation_peers_check (struct bgp *, as_t);
747
748int bgp_confederation_peers_add (struct bgp *, as_t);
749int bgp_confederation_peers_remove (struct bgp *, as_t);
750
751int bgp_timers_set (struct bgp *, u_int32_t, u_int32_t);
752int bgp_timers_unset (struct bgp *);
753
754int bgp_default_local_preference_set (struct bgp *, u_int32_t);
755int bgp_default_local_preference_unset (struct bgp *);
756
757int peer_remote_as (struct bgp *, union sockunion *, as_t *, afi_t, safi_t);
758int peer_group_remote_as (struct bgp *, char *, as_t *);
759int peer_delete (struct peer *peer);
760int peer_group_delete (struct peer_group *);
761int peer_group_remote_as_delete (struct peer_group *);
762
763int peer_activate (struct peer *, afi_t, safi_t);
764int peer_deactivate (struct peer *, afi_t, safi_t);
765
766int peer_group_bind (struct bgp *, union sockunion *, struct peer_group *,
767 afi_t, safi_t, as_t *);
768int peer_group_unbind (struct bgp *, struct peer *, struct peer_group *,
769 afi_t, safi_t);
770
771int peer_flag_set (struct peer *, u_int32_t);
772int peer_flag_unset (struct peer *, u_int32_t);
773
774int peer_af_flag_set (struct peer *, afi_t, safi_t, u_int32_t);
775int peer_af_flag_unset (struct peer *, afi_t, safi_t, u_int32_t);
776int peer_af_flag_check (struct peer *, afi_t, safi_t, u_int32_t);
777
778int peer_ebgp_multihop_set (struct peer *, int);
779int peer_ebgp_multihop_unset (struct peer *);
780
781int peer_description_set (struct peer *, char *);
782int peer_description_unset (struct peer *);
783
784int peer_update_source_if_set (struct peer *, char *);
785int peer_update_source_addr_set (struct peer *, union sockunion *);
786int peer_update_source_unset (struct peer *);
787
788int peer_default_originate_set (struct peer *, afi_t, safi_t, char *);
789int peer_default_originate_unset (struct peer *, afi_t, safi_t);
790
791int peer_port_set (struct peer *, u_int16_t);
792int peer_port_unset (struct peer *);
793
794int peer_weight_set (struct peer *, u_int16_t);
795int peer_weight_unset (struct peer *);
796
797int peer_timers_set (struct peer *, u_int32_t, u_int32_t);
798int peer_timers_unset (struct peer *);
799
800int peer_timers_connect_set (struct peer *, u_int32_t);
801int peer_timers_connect_unset (struct peer *);
802
803int peer_advertise_interval_set (struct peer *, u_int32_t);
804int peer_advertise_interval_unset (struct peer *);
805
806int peer_version_set (struct peer *, int);
807int peer_version_unset (struct peer *);
808
809int peer_interface_set (struct peer *, char *);
810int peer_interface_unset (struct peer *);
811
812int peer_distribute_set (struct peer *, afi_t, safi_t, int, char *);
813int peer_distribute_unset (struct peer *, afi_t, safi_t, int);
814
815int peer_allowas_in_set (struct peer *, afi_t, safi_t, int);
816int peer_allowas_in_unset (struct peer *, afi_t, safi_t);
817
818int peer_local_as_set (struct peer *, as_t, int);
819int peer_local_as_unset (struct peer *);
820
821int peer_prefix_list_set (struct peer *, afi_t, safi_t, int, char *);
822int peer_prefix_list_unset (struct peer *, afi_t, safi_t, int);
823
824int peer_aslist_set (struct peer *, afi_t, safi_t, int, char *);
825int peer_aslist_unset (struct peer *,afi_t, safi_t, int);
826
827int peer_route_map_set (struct peer *, afi_t, safi_t, int, char *);
828int peer_route_map_unset (struct peer *, afi_t, safi_t, int);
829
830int peer_unsuppress_map_set (struct peer *, afi_t, safi_t, char *);
831int peer_unsuppress_map_unset (struct peer *, afi_t, safi_t);
832
833int peer_maximum_prefix_set (struct peer *, afi_t, safi_t, u_int32_t, int);
834int peer_maximum_prefix_unset (struct peer *, afi_t, safi_t);
835
836int peer_clear (struct peer *);
837int peer_clear_soft (struct peer *, afi_t, safi_t, enum bgp_clear_type);