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