blob: f2b75dea7336938070f3329396165d30f06e3a51 [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
paul00d252c2005-05-23 14:19:54 +000021#ifndef _QUAGGA_BGPD_H
22#define _QUAGGA_BGPD_H
23
paul718e3742002-12-13 20:15:29 +000024/* For union sockunion. */
25#include "sockunion.h"
26
27/* Typedef BGP specific types. */
28typedef u_int16_t as_t;
29typedef u_int16_t bgp_size_t;
30
31/* BGP master for system wide configurations and variables. */
32struct bgp_master
33{
34 /* BGP instance list. */
35 struct list *bgp;
36
37 /* BGP thread master. */
38 struct thread_master *master;
39
40 /* BGP port number. */
41 u_int16_t port;
42
43 /* BGP start time. */
44 time_t start_time;
45
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)
51};
52
53/* BGP instance structure. */
54struct bgp
55{
56 /* AS number of this BGP instance. */
57 as_t as;
58
59 /* Name of this BGP instance. */
60 char *name;
61
62 /* Self peer. */
63 struct peer *peer_self;
64
65 /* BGP peer. */
66 struct list *peer;
67
68 /* BGP peer group. */
69 struct list *group;
70
paulfee0f4c2004-09-13 05:12:46 +000071 /* BGP route-server-clients. */
72 struct list *rsclient;
73
paul718e3742002-12-13 20:15:29 +000074 /* BGP configuration. */
75 u_int16_t config;
76#define BGP_CONFIG_ROUTER_ID (1 << 0)
77#define BGP_CONFIG_CLUSTER_ID (1 << 1)
78#define BGP_CONFIG_CONFEDERATION (1 << 2)
paul718e3742002-12-13 20:15:29 +000079
80 /* BGP router identifier. */
81 struct in_addr router_id;
hasso18a6dce2004-10-03 18:18:34 +000082 struct in_addr router_id_static;
paul718e3742002-12-13 20:15:29 +000083
84 /* BGP route reflector cluster ID. */
85 struct in_addr cluster_id;
86
87 /* BGP confederation information. */
88 as_t confed_id;
89 as_t *confed_peers;
90 int confed_peers_cnt;
91
92 /* BGP flags. */
93 u_int16_t flags;
94#define BGP_FLAG_ALWAYS_COMPARE_MED (1 << 0)
95#define BGP_FLAG_DETERMINISTIC_MED (1 << 1)
96#define BGP_FLAG_MED_MISSING_AS_WORST (1 << 2)
97#define BGP_FLAG_MED_CONFED (1 << 3)
98#define BGP_FLAG_NO_DEFAULT_IPV4 (1 << 4)
99#define BGP_FLAG_NO_CLIENT_TO_CLIENT (1 << 5)
100#define BGP_FLAG_ENFORCE_FIRST_AS (1 << 6)
101#define BGP_FLAG_COMPARE_ROUTER_ID (1 << 7)
102#define BGP_FLAG_ASPATH_IGNORE (1 << 8)
103#define BGP_FLAG_IMPORT_CHECK (1 << 9)
104#define BGP_FLAG_NO_FAST_EXT_FAILOVER (1 << 10)
paul848973c2003-08-13 00:32:49 +0000105#define BGP_FLAG_LOG_NEIGHBOR_CHANGES (1 << 11)
hasso538621f2004-05-21 09:31:30 +0000106#define BGP_FLAG_GRACEFUL_RESTART (1 << 12)
hasso68118452005-04-08 15:40:36 +0000107#define BGP_FLAG_ASPATH_CONFED (1 << 13)
paul718e3742002-12-13 20:15:29 +0000108
109 /* BGP Per AF flags */
110 u_int16_t af_flags[AFI_MAX][SAFI_MAX];
111#define BGP_CONFIG_DAMPENING (1 << 0)
112
113 /* Static route configuration. */
114 struct bgp_table *route[AFI_MAX][SAFI_MAX];
115
116 /* Aggregate address configuration. */
117 struct bgp_table *aggregate[AFI_MAX][SAFI_MAX];
118
119 /* BGP routing information base. */
120 struct bgp_table *rib[AFI_MAX][SAFI_MAX];
121
122 /* BGP redistribute configuration. */
123 u_char redist[AFI_MAX][ZEBRA_ROUTE_MAX];
124
125 /* BGP redistribute metric configuration. */
126 u_char redist_metric_flag[AFI_MAX][ZEBRA_ROUTE_MAX];
127 u_int32_t redist_metric[AFI_MAX][ZEBRA_ROUTE_MAX];
128
129 /* BGP redistribute route-map. */
130 struct
131 {
132 char *name;
133 struct route_map *map;
134 } rmap[AFI_MAX][ZEBRA_ROUTE_MAX];
135
136 /* BGP distance configuration. */
137 u_char distance_ebgp;
138 u_char distance_ibgp;
139 u_char distance_local;
140
141 /* BGP default local-preference. */
142 u_int32_t default_local_pref;
143
144 /* BGP default timer. */
145 u_int32_t default_holdtime;
146 u_int32_t default_keepalive;
hasso538621f2004-05-21 09:31:30 +0000147
148 /* BGP graceful restart */
hasso93406d82005-02-02 14:40:33 +0000149 u_int32_t restart_time;
150 u_int32_t stalepath_time;
paul718e3742002-12-13 20:15:29 +0000151};
152
153/* BGP peer-group support. */
154struct peer_group
155{
156 /* Name of the peer-group. */
157 char *name;
158
159 /* Pointer to BGP. */
160 struct bgp *bgp;
161
162 /* Peer-group client list. */
163 struct list *peer;
164
165 /* Peer-group config */
166 struct peer *conf;
167};
168
169/* BGP Notify message format. */
170struct bgp_notify
171{
172 u_char code;
173 u_char subcode;
174 char *data;
175 bgp_size_t length;
176};
177
178/* Next hop self address. */
179struct bgp_nexthop
180{
181 struct interface *ifp;
182 struct in_addr v4;
183#ifdef HAVE_IPV6
184 struct in6_addr v6_global;
185 struct in6_addr v6_local;
186#endif /* HAVE_IPV6 */
187};
188
189/* BGP router distinguisher value. */
190#define BGP_RD_SIZE 8
191
192struct bgp_rd
193{
194 u_char val[BGP_RD_SIZE];
195};
196
paulfee0f4c2004-09-13 05:12:46 +0000197#define RMAP_IN 0
198#define RMAP_OUT 1
199#define RMAP_IMPORT 2
200#define RMAP_EXPORT 3
201#define RMAP_MAX 4
202
paul718e3742002-12-13 20:15:29 +0000203/* BGP filter structure. */
204struct bgp_filter
205{
206 /* Distribute-list. */
207 struct
208 {
209 char *name;
210 struct access_list *alist;
211 } dlist[FILTER_MAX];
212
213 /* Prefix-list. */
214 struct
215 {
216 char *name;
217 struct prefix_list *plist;
218 } plist[FILTER_MAX];
219
220 /* Filter-list. */
221 struct
222 {
223 char *name;
224 struct as_list *aslist;
225 } aslist[FILTER_MAX];
226
227 /* Route-map. */
228 struct
229 {
230 char *name;
231 struct route_map *map;
paulfee0f4c2004-09-13 05:12:46 +0000232 } map[RMAP_MAX];
paul718e3742002-12-13 20:15:29 +0000233
234 /* Unsuppress-map. */
235 struct
236 {
237 char *name;
238 struct route_map *map;
239 } usmap;
240};
241
242/* BGP neighbor structure. */
243struct peer
244{
245 /* BGP structure. */
246 struct bgp *bgp;
247
248 /* BGP peer group. */
249 struct peer_group *group;
250 u_char af_group[AFI_MAX][SAFI_MAX];
251
252 /* Peer's remote AS number. */
253 as_t as;
254
255 /* Peer's local AS number. */
256 as_t local_as;
257
258 /* Peer's Change local AS number. */
259 as_t change_local_as;
260
261 /* Remote router ID. */
262 struct in_addr remote_id;
263
264 /* Local router ID. */
265 struct in_addr local_id;
266
paulfee0f4c2004-09-13 05:12:46 +0000267 /* Peer specific RIB when configured as route-server-client. */
268 struct bgp_table *rib[AFI_MAX][SAFI_MAX];
269
paul718e3742002-12-13 20:15:29 +0000270 /* Packet receive and send buffer. */
271 struct stream *ibuf;
272 struct stream_fifo *obuf;
273 struct stream *work;
274
275 /* Status of the peer. */
276 int status;
277 int ostatus;
278
279 /* Peer information */
pauleb821182004-05-01 08:44:08 +0000280 int fd; /* File descriptor */
281 int ttl; /* TTL of TCP connection to the peer. */
282 char *desc; /* Description of the peer. */
283 unsigned short port; /* Destination port for peer */
284 char *host; /* Printable address of the peer. */
285 union sockunion su; /* Sockunion address of the peer. */
286 time_t uptime; /* Last Up/Down time */
287 time_t readtime; /* Last read time */
288 time_t resettime; /* Last reset time */
paul718e3742002-12-13 20:15:29 +0000289
pauleb821182004-05-01 08:44:08 +0000290 unsigned int ifindex; /* ifindex of the BGP connection. */
291 char *ifname; /* bind interface name. */
292 char *update_if;
293 union sockunion *update_source;
294 struct zlog *log;
paul718e3742002-12-13 20:15:29 +0000295
pauleb821182004-05-01 08:44:08 +0000296 union sockunion *su_local; /* Sockunion of local address. */
297 union sockunion *su_remote; /* Sockunion of remote address. */
298 int shared_network; /* Is this peer shared same network. */
299 struct bgp_nexthop nexthop; /* Nexthop */
paul718e3742002-12-13 20:15:29 +0000300
301 /* Peer address family configuration. */
302 u_char afc[AFI_MAX][SAFI_MAX];
303 u_char afc_nego[AFI_MAX][SAFI_MAX];
304 u_char afc_adv[AFI_MAX][SAFI_MAX];
305 u_char afc_recv[AFI_MAX][SAFI_MAX];
306
hasso0a486e52005-02-01 20:57:17 +0000307 /* Capability flags (reset in bgp_stop) */
paul718e3742002-12-13 20:15:29 +0000308 u_char cap;
309#define PEER_CAP_REFRESH_ADV (1 << 0) /* refresh advertised */
310#define PEER_CAP_REFRESH_OLD_RCV (1 << 1) /* refresh old received */
311#define PEER_CAP_REFRESH_NEW_RCV (1 << 2) /* refresh rfc received */
312#define PEER_CAP_DYNAMIC_ADV (1 << 3) /* dynamic advertised */
313#define PEER_CAP_DYNAMIC_RCV (1 << 4) /* dynamic received */
hasso538621f2004-05-21 09:31:30 +0000314#define PEER_CAP_RESTART_ADV (1 << 5) /* restart advertised */
315#define PEER_CAP_RESTART_RCV (1 << 6) /* restart received */
paul718e3742002-12-13 20:15:29 +0000316
hasso0a486e52005-02-01 20:57:17 +0000317 /* Capability flags (reset in bgp_stop) */
paul718e3742002-12-13 20:15:29 +0000318 u_int16_t af_cap[AFI_MAX][SAFI_MAX];
319#define PEER_CAP_ORF_PREFIX_SM_ADV (1 << 0) /* send-mode advertised */
320#define PEER_CAP_ORF_PREFIX_RM_ADV (1 << 1) /* receive-mode advertised */
321#define PEER_CAP_ORF_PREFIX_SM_RCV (1 << 2) /* send-mode received */
322#define PEER_CAP_ORF_PREFIX_RM_RCV (1 << 3) /* receive-mode received */
323#define PEER_CAP_ORF_PREFIX_SM_OLD_RCV (1 << 4) /* send-mode received */
324#define PEER_CAP_ORF_PREFIX_RM_OLD_RCV (1 << 5) /* receive-mode received */
hasso93406d82005-02-02 14:40:33 +0000325#define PEER_CAP_RESTART_AF_RCV (1 << 6) /* graceful restart afi/safi received */
326#define PEER_CAP_RESTART_AF_PRESERVE_RCV (1 << 7) /* graceful restart afi/safi F-bit received */
paul718e3742002-12-13 20:15:29 +0000327
328 /* Global configuration flags. */
329 u_int32_t flags;
330#define PEER_FLAG_PASSIVE (1 << 0) /* passive mode */
331#define PEER_FLAG_SHUTDOWN (1 << 1) /* shutdown */
332#define PEER_FLAG_DONT_CAPABILITY (1 << 2) /* dont-capability */
333#define PEER_FLAG_OVERRIDE_CAPABILITY (1 << 3) /* override-capability */
334#define PEER_FLAG_STRICT_CAP_MATCH (1 << 4) /* strict-match */
hassoc9502432005-02-01 22:01:48 +0000335#define PEER_FLAG_DYNAMIC_CAPABILITY (1 << 5) /* dynamic capability */
hasso6ffd2072005-02-02 14:50:11 +0000336#define PEER_FLAG_DISABLE_CONNECTED_CHECK (1 << 6) /* disable-connected-check */
hassoc9502432005-02-01 22:01:48 +0000337#define PEER_FLAG_LOCAL_AS_NO_PREPEND (1 << 7) /* local-as no-prepend */
paul718e3742002-12-13 20:15:29 +0000338
hasso93406d82005-02-02 14:40:33 +0000339 /* NSF mode (graceful restart) */
340 u_char nsf[AFI_MAX][SAFI_MAX];
341
paul718e3742002-12-13 20:15:29 +0000342 /* Per AF configuration flags. */
343 u_int32_t af_flags[AFI_MAX][SAFI_MAX];
344#define PEER_FLAG_SEND_COMMUNITY (1 << 0) /* send-community */
345#define PEER_FLAG_SEND_EXT_COMMUNITY (1 << 1) /* send-community ext. */
346#define PEER_FLAG_NEXTHOP_SELF (1 << 2) /* next-hop-self */
347#define PEER_FLAG_REFLECTOR_CLIENT (1 << 3) /* reflector-client */
348#define PEER_FLAG_RSERVER_CLIENT (1 << 4) /* route-server-client */
349#define PEER_FLAG_SOFT_RECONFIG (1 << 5) /* soft-reconfiguration */
350#define PEER_FLAG_AS_PATH_UNCHANGED (1 << 6) /* transparent-as */
351#define PEER_FLAG_NEXTHOP_UNCHANGED (1 << 7) /* transparent-next-hop */
352#define PEER_FLAG_MED_UNCHANGED (1 << 8) /* transparent-next-hop */
353#define PEER_FLAG_DEFAULT_ORIGINATE (1 << 9) /* default-originate */
354#define PEER_FLAG_REMOVE_PRIVATE_AS (1 << 10) /* remove-private-as */
355#define PEER_FLAG_ALLOWAS_IN (1 << 11) /* set allowas-in */
356#define PEER_FLAG_ORF_PREFIX_SM (1 << 12) /* orf capability send-mode */
357#define PEER_FLAG_ORF_PREFIX_RM (1 << 13) /* orf capability receive-mode */
358#define PEER_FLAG_MAX_PREFIX (1 << 14) /* maximum prefix */
359#define PEER_FLAG_MAX_PREFIX_WARNING (1 << 15) /* maximum prefix warning-only */
paulfee0f4c2004-09-13 05:12:46 +0000360#define PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED (1 << 16) /* leave link-local nexthop unchanged */
paul718e3742002-12-13 20:15:29 +0000361
362 /* default-originate route-map. */
363 struct
364 {
365 char *name;
366 struct route_map *map;
367 } default_rmap[AFI_MAX][SAFI_MAX];
368
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 */
hasso93406d82005-02-02 14:40:33 +0000376#define PEER_STATUS_NSF_MODE (1 << 5) /* NSF aware peer */
377#define PEER_STATUS_NSF_WAIT (1 << 6) /* wait comeback peer */
paul718e3742002-12-13 20:15:29 +0000378
hasso0a486e52005-02-01 20:57:17 +0000379 /* Peer status af flags (reset in bgp_stop) */
paul718e3742002-12-13 20:15:29 +0000380 u_int16_t af_sflags[AFI_MAX][SAFI_MAX];
381#define PEER_STATUS_ORF_PREFIX_SEND (1 << 0) /* prefix-list send peer */
382#define PEER_STATUS_ORF_WAIT_REFRESH (1 << 1) /* wait refresh received peer */
383#define PEER_STATUS_DEFAULT_ORIGINATE (1 << 2) /* default-originate peer */
hassoe0701b72004-05-20 09:19:34 +0000384#define PEER_STATUS_PREFIX_THRESHOLD (1 << 3) /* exceed prefix-threshold */
385#define PEER_STATUS_PREFIX_LIMIT (1 << 4) /* exceed prefix-limit */
hasso93406d82005-02-02 14:40:33 +0000386#define PEER_STATUS_EOR_SEND (1 << 5) /* end-of-rib send to peer */
387#define PEER_STATUS_EOR_RECEIVED (1 << 6) /* end-of-rib received from peer */
hassoe0701b72004-05-20 09:19:34 +0000388
paul718e3742002-12-13 20:15:29 +0000389
390 /* Default attribute value for the peer. */
391 u_int32_t config;
392#define PEER_CONFIG_WEIGHT (1 << 0) /* Default weight. */
393#define PEER_CONFIG_TIMER (1 << 1) /* keepalive & holdtime */
394#define PEER_CONFIG_CONNECT (1 << 2) /* connect */
395#define PEER_CONFIG_ROUTEADV (1 << 3) /* route advertise */
396 u_int32_t weight;
397 u_int32_t holdtime;
398 u_int32_t keepalive;
399 u_int32_t connect;
400 u_int32_t routeadv;
401
402 /* Timer values. */
403 u_int32_t v_start;
404 u_int32_t v_connect;
405 u_int32_t v_holdtime;
406 u_int32_t v_keepalive;
407 u_int32_t v_asorig;
408 u_int32_t v_routeadv;
hasso0a486e52005-02-01 20:57:17 +0000409 u_int32_t v_pmax_restart;
hasso93406d82005-02-02 14:40:33 +0000410 u_int32_t v_gr_restart;
paul718e3742002-12-13 20:15:29 +0000411
412 /* Threads. */
413 struct thread *t_read;
414 struct thread *t_write;
415 struct thread *t_start;
416 struct thread *t_connect;
417 struct thread *t_holdtime;
418 struct thread *t_keepalive;
419 struct thread *t_asorig;
420 struct thread *t_routeadv;
hasso0a486e52005-02-01 20:57:17 +0000421 struct thread *t_pmax_restart;
hasso93406d82005-02-02 14:40:33 +0000422 struct thread *t_gr_restart;
423 struct thread *t_gr_stale;
paul718e3742002-12-13 20:15:29 +0000424
425 /* Statistics field */
426 u_int32_t open_in; /* Open message input count */
427 u_int32_t open_out; /* Open message output count */
428 u_int32_t update_in; /* Update message input count */
429 u_int32_t update_out; /* Update message ouput count */
430 time_t update_time; /* Update message received time. */
431 u_int32_t keepalive_in; /* Keepalive input count */
432 u_int32_t keepalive_out; /* Keepalive output count */
433 u_int32_t notify_in; /* Notify input count */
434 u_int32_t notify_out; /* Notify output count */
435 u_int32_t refresh_in; /* Route Refresh input count */
436 u_int32_t refresh_out; /* Route Refresh output count */
437 u_int32_t dynamic_cap_in; /* Dynamic Capability input count. */
438 u_int32_t dynamic_cap_out; /* Dynamic Capability output count. */
439
440 /* BGP state count */
441 u_int32_t established; /* Established */
442 u_int32_t dropped; /* Dropped */
443
444 /* Syncronization list and time. */
445 struct bgp_synchronize *sync[AFI_MAX][SAFI_MAX];
446 time_t synctime;
447
448 /* Send prefix count. */
449 unsigned long scount[AFI_MAX][SAFI_MAX];
450
451 /* Announcement attribute hash. */
452 struct hash *hash[AFI_MAX][SAFI_MAX];
453
454 /* Notify data. */
455 struct bgp_notify notify;
456
457 /* Whole packet size to be read. */
458 unsigned long packet_size;
459
460 /* Filter structure. */
461 struct bgp_filter filter[AFI_MAX][SAFI_MAX];
462
463 /* ORF Prefix-list */
464 struct prefix_list *orf_plist[AFI_MAX][SAFI_MAX];
465
466 /* Prefix count. */
467 unsigned long pcount[AFI_MAX][SAFI_MAX];
468
469 /* Max prefix count. */
470 unsigned long pmax[AFI_MAX][SAFI_MAX];
hassoe0701b72004-05-20 09:19:34 +0000471 u_char pmax_threshold[AFI_MAX][SAFI_MAX];
hasso0a486e52005-02-01 20:57:17 +0000472 u_int16_t pmax_restart[AFI_MAX][SAFI_MAX];
hassoe0701b72004-05-20 09:19:34 +0000473#define MAXIMUM_PREFIX_THRESHOLD_DEFAULT 75
paul718e3742002-12-13 20:15:29 +0000474
475 /* allowas-in. */
476 char allowas_in[AFI_MAX][SAFI_MAX];
paulac41b2a2003-08-12 05:32:27 +0000477
hassoe0701b72004-05-20 09:19:34 +0000478 /* peer reset cause */
479 char last_reset;
480#define PEER_DOWN_RID_CHANGE 1 /* bgp router-id command */
481#define PEER_DOWN_REMOTE_AS_CHANGE 2 /* neighbor remote-as command */
482#define PEER_DOWN_LOCAL_AS_CHANGE 3 /* neighbor local-as command */
483#define PEER_DOWN_CLID_CHANGE 4 /* bgp cluster-id command */
484#define PEER_DOWN_CONFED_ID_CHANGE 5 /* bgp confederation identifier command */
485#define PEER_DOWN_CONFED_PEER_CHANGE 6 /* bgp confederation peer command */
486#define PEER_DOWN_RR_CLIENT_CHANGE 7 /* neighbor route-reflector-client command */
487#define PEER_DOWN_RS_CLIENT_CHANGE 8 /* neighbor route-server-client command */
488#define PEER_DOWN_UPDATE_SOURCE_CHANGE 9 /* neighbor update-source command */
489#define PEER_DOWN_AF_ACTIVATE 10 /* neighbor activate command */
490#define PEER_DOWN_USER_SHUTDOWN 11 /* neighbor shutdown command */
491#define PEER_DOWN_USER_RESET 12 /* clear ip bgp command */
492#define PEER_DOWN_NOTIFY_RECEIVED 13 /* notification received */
493#define PEER_DOWN_NOTIFY_SEND 14 /* notification send */
494#define PEER_DOWN_CLOSE_SESSION 15 /* tcp session close */
495#define PEER_DOWN_NEIGHBOR_DELETE 16 /* neghbor delete */
496#define PEER_DOWN_RMAP_BIND 17 /* neghbor peer-group command */
497#define PEER_DOWN_RMAP_UNBIND 18 /* no neighbor peer-group command */
498#define PEER_DOWN_CAPABILITY_CHANGE 19 /* neighbor capability command */
499#define PEER_DOWN_PASSIVE_CHANGE 20 /* neighbor passive command */
500#define PEER_DOWN_MULTIHOP_CHANGE 21 /* neighbor multihop command */
hasso93406d82005-02-02 14:40:33 +0000501#define PEER_DOWN_NSF_CLOSE_SESSION 22 /* NSF tcp session close */
hassoe0701b72004-05-20 09:19:34 +0000502
paulac41b2a2003-08-12 05:32:27 +0000503 /* The kind of route-map Flags.*/
504 u_char rmap_type;
505#define PEER_RMAP_TYPE_IN (1 << 0) /* neighbor route-map in */
506#define PEER_RMAP_TYPE_OUT (1 << 1) /* neighbor route-map out */
507#define PEER_RMAP_TYPE_NETWORK (1 << 2) /* network route-map */
508#define PEER_RMAP_TYPE_REDISTRIBUTE (1 << 3) /* redistribute route-map */
509#define PEER_RMAP_TYPE_DEFAULT (1 << 4) /* default-originate route-map */
510#define PEER_RMAP_TYPE_NOSET (1 << 5) /* not allow to set commands */
paulfee0f4c2004-09-13 05:12:46 +0000511#define PEER_RMAP_TYPE_IMPORT (1 << 6) /* neighbor route-map import */
512#define PEER_RMAP_TYPE_EXPORT (1 << 7) /* neighbor route-map export */
paul718e3742002-12-13 20:15:29 +0000513};
514
515/* This structure's member directly points incoming packet data
516 stream. */
517struct bgp_nlri
518{
519 /* AFI. */
520 afi_t afi;
521
522 /* SAFI. */
523 safi_t safi;
524
525 /* Pointer to NLRI byte stream. */
526 u_char *nlri;
527
528 /* Length of whole NLRI. */
529 bgp_size_t length;
530};
531
532/* BGP versions. */
533#define BGP_VERSION_4 4
paul718e3742002-12-13 20:15:29 +0000534
535/* Default BGP port number. */
536#define BGP_PORT_DEFAULT 179
537
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
542
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)
550
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
559
560/* BGP open optional parameter. */
561#define BGP_OPEN_OPT_AUTH 1
562#define BGP_OPEN_OPT_CAP 2
563
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
582/* BGP update origin. */
583#define BGP_ORIGIN_IGP 0
584#define BGP_ORIGIN_EGP 1
585#define BGP_ORIGIN_INCOMPLETE 2
586
587/* BGP notify message codes. */
588#define BGP_NOTIFY_HEADER_ERR 1
589#define BGP_NOTIFY_OPEN_ERR 2
590#define BGP_NOTIFY_UPDATE_ERR 3
591#define BGP_NOTIFY_HOLD_ERR 4
592#define BGP_NOTIFY_FSM_ERR 5
593#define BGP_NOTIFY_CEASE 6
594#define BGP_NOTIFY_CAPABILITY_ERR 7
595#define BGP_NOTIFY_MAX 8
596
597/* BGP_NOTIFY_HEADER_ERR sub codes. */
598#define BGP_NOTIFY_HEADER_NOT_SYNC 1
599#define BGP_NOTIFY_HEADER_BAD_MESLEN 2
600#define BGP_NOTIFY_HEADER_BAD_MESTYPE 3
601#define BGP_NOTIFY_HEADER_MAX 4
602
603/* BGP_NOTIFY_OPEN_ERR sub codes. */
604#define BGP_NOTIFY_OPEN_UNSUP_VERSION 1
605#define BGP_NOTIFY_OPEN_BAD_PEER_AS 2
606#define BGP_NOTIFY_OPEN_BAD_BGP_IDENT 3
607#define BGP_NOTIFY_OPEN_UNSUP_PARAM 4
608#define BGP_NOTIFY_OPEN_AUTH_FAILURE 5
609#define BGP_NOTIFY_OPEN_UNACEP_HOLDTIME 6
610#define BGP_NOTIFY_OPEN_UNSUP_CAPBL 7
611#define BGP_NOTIFY_OPEN_MAX 8
612
613/* BGP_NOTIFY_UPDATE_ERR sub codes. */
614#define BGP_NOTIFY_UPDATE_MAL_ATTR 1
615#define BGP_NOTIFY_UPDATE_UNREC_ATTR 2
616#define BGP_NOTIFY_UPDATE_MISS_ATTR 3
617#define BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR 4
618#define BGP_NOTIFY_UPDATE_ATTR_LENG_ERR 5
619#define BGP_NOTIFY_UPDATE_INVAL_ORIGIN 6
620#define BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP 7
621#define BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP 8
622#define BGP_NOTIFY_UPDATE_OPT_ATTR_ERR 9
623#define BGP_NOTIFY_UPDATE_INVAL_NETWORK 10
624#define BGP_NOTIFY_UPDATE_MAL_AS_PATH 11
625#define BGP_NOTIFY_UPDATE_MAX 12
626
paul545acaf2004-04-20 15:13:15 +0000627/* BGP_NOTIFY_CEASE sub codes (draft-ietf-idr-cease-subcode-05). */
paul718e3742002-12-13 20:15:29 +0000628#define BGP_NOTIFY_CEASE_MAX_PREFIX 1
629#define BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN 2
630#define BGP_NOTIFY_CEASE_PEER_UNCONFIG 3
631#define BGP_NOTIFY_CEASE_ADMIN_RESET 4
632#define BGP_NOTIFY_CEASE_CONNECT_REJECT 5
633#define BGP_NOTIFY_CEASE_CONFIG_CHANGE 6
paul545acaf2004-04-20 15:13:15 +0000634#define BGP_NOTIFY_CEASE_COLLISION_RESOLUTION 7
635#define BGP_NOTIFY_CEASE_OUT_OF_RESOURCE 8
636#define BGP_NOTIFY_CEASE_MAX 9
paul718e3742002-12-13 20:15:29 +0000637
638/* BGP_NOTIFY_CAPABILITY_ERR sub codes (draft-ietf-idr-dynamic-cap-02). */
639#define BGP_NOTIFY_CAPABILITY_INVALID_ACTION 1
640#define BGP_NOTIFY_CAPABILITY_INVALID_LENGTH 2
641#define BGP_NOTIFY_CAPABILITY_MALFORMED_CODE 3
642#define BGP_NOTIFY_CAPABILITY_MAX 4
643
644/* BGP finite state machine status. */
645#define Idle 1
646#define Connect 2
647#define Active 3
648#define OpenSent 4
649#define OpenConfirm 5
650#define Established 6
651#define BGP_STATUS_MAX 7
652
653/* BGP finite state machine events. */
654#define BGP_Start 1
655#define BGP_Stop 2
656#define TCP_connection_open 3
657#define TCP_connection_closed 4
658#define TCP_connection_open_failed 5
659#define TCP_fatal_error 6
660#define ConnectRetry_timer_expired 7
661#define Hold_Timer_expired 8
662#define KeepAlive_timer_expired 9
663#define Receive_OPEN_message 10
664#define Receive_KEEPALIVE_message 11
665#define Receive_UPDATE_message 12
666#define Receive_NOTIFICATION_message 13
667#define BGP_EVENTS_MAX 14
668
669/* BGP timers default value. */
670#define BGP_INIT_START_TIMER 5
671#define BGP_ERROR_START_TIMER 30
672#define BGP_DEFAULT_HOLDTIME 180
673#define BGP_DEFAULT_KEEPALIVE 60
674#define BGP_DEFAULT_ASORIGINATE 15
675#define BGP_DEFAULT_EBGP_ROUTEADV 30
676#define BGP_DEFAULT_IBGP_ROUTEADV 5
677#define BGP_CLEAR_CONNECT_RETRY 20
678#define BGP_DEFAULT_CONNECT_RETRY 120
679
680/* BGP default local preference. */
681#define BGP_DEFAULT_LOCAL_PREF 100
682
hasso538621f2004-05-21 09:31:30 +0000683/* BGP graceful restart */
684#define BGP_DEFAULT_RESTART_TIME 120
685#define BGP_DEFAULT_STALEPATH_TIME 360
686
paul718e3742002-12-13 20:15:29 +0000687/* SAFI which used in open capability negotiation. */
688#define BGP_SAFI_VPNV4 128
689#define BGP_SAFI_VPNV6 129
690
691/* Max TTL value. */
692#define TTL_MAX 255
693
694/* BGP uptime string length. */
695#define BGP_UPTIME_LEN 25
696
697/* Default configuration settings for bgpd. */
698#define BGP_VTY_PORT 2605
paul718e3742002-12-13 20:15:29 +0000699#define BGP_DEFAULT_CONFIG "bgpd.conf"
700
701/* Check AS path loop when we send NLRI. */
702/* #define BGP_SEND_ASPATH_CHECK */
703
704/* IBGP/EBGP identifier. We also have a CONFED peer, which is to say,
705 a peer who's AS is part of our Confederation. */
706enum
707{
708 BGP_PEER_IBGP,
709 BGP_PEER_EBGP,
710 BGP_PEER_INTERNAL,
711 BGP_PEER_CONFED
712};
713
714/* Flag for peer_clear_soft(). */
715enum bgp_clear_type
716{
717 BGP_CLEAR_SOFT_NONE,
718 BGP_CLEAR_SOFT_OUT,
719 BGP_CLEAR_SOFT_IN,
720 BGP_CLEAR_SOFT_BOTH,
paulfee0f4c2004-09-13 05:12:46 +0000721 BGP_CLEAR_SOFT_IN_ORF_PREFIX,
722 BGP_CLEAR_SOFT_RSCLIENT
paul718e3742002-12-13 20:15:29 +0000723};
724
725/* Macros. */
726#define BGP_INPUT(P) ((P)->ibuf)
727#define BGP_INPUT_PNT(P) (STREAM_PNT(BGP_INPUT(P)))
728
729/* Macro to check BGP information is alive or not. */
730#define BGP_INFO_HOLDDOWN(BI) \
731 (! CHECK_FLAG ((BI)->flags, BGP_INFO_VALID) \
732 || CHECK_FLAG ((BI)->flags, BGP_INFO_HISTORY) \
733 || CHECK_FLAG ((BI)->flags, BGP_INFO_DAMPED))
734
735/* Count prefix size from mask length */
736#define PSIZE(a) (((a) + 7) / (8))
737
738/* BGP error codes. */
739#define BGP_SUCCESS 0
740#define BGP_ERR_INVALID_VALUE -1
741#define BGP_ERR_INVALID_FLAG -2
742#define BGP_ERR_INVALID_AS -3
743#define BGP_ERR_INVALID_BGP -4
744#define BGP_ERR_PEER_GROUP_MEMBER -5
745#define BGP_ERR_MULTIPLE_INSTANCE_USED -6
746#define BGP_ERR_PEER_GROUP_MEMBER_EXISTS -7
747#define BGP_ERR_PEER_BELONGS_TO_GROUP -8
748#define BGP_ERR_PEER_GROUP_AF_UNCONFIGURED -9
749#define BGP_ERR_PEER_GROUP_NO_REMOTE_AS -10
750#define BGP_ERR_PEER_GROUP_CANT_CHANGE -11
751#define BGP_ERR_PEER_GROUP_MISMATCH -12
752#define BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT -13
753#define BGP_ERR_MULTIPLE_INSTANCE_NOT_SET -14
754#define BGP_ERR_AS_MISMATCH -15
755#define BGP_ERR_PEER_INACTIVE -16
756#define BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER -17
757#define BGP_ERR_PEER_GROUP_HAS_THE_FLAG -18
758#define BGP_ERR_PEER_FLAG_CONFLICT -19
759#define BGP_ERR_PEER_GROUP_SHUTDOWN -20
760#define BGP_ERR_PEER_FILTER_CONFLICT -21
761#define BGP_ERR_NOT_INTERNAL_PEER -22
762#define BGP_ERR_REMOVE_PRIVATE_AS -23
763#define BGP_ERR_AF_UNCONFIGURED -24
764#define BGP_ERR_SOFT_RECONFIG_UNCONFIGURED -25
765#define BGP_ERR_INSTANCE_MISMATCH -26
766#define BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP -27
767#define BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS -28
768#define BGP_ERR_MAX -29
769
770extern struct bgp_master *bm;
771
772extern struct thread_master *master;
773
774/* Prototypes. */
775void bgp_terminate (void);
776void bgp_reset (void);
777void bgp_zclient_reset ();
778int bgp_nexthop_set (union sockunion *, union sockunion *,
779 struct bgp_nexthop *, struct peer *);
paul718e3742002-12-13 20:15:29 +0000780struct bgp *bgp_get_default ();
paulfd79ac92004-10-13 05:06:08 +0000781struct bgp *bgp_lookup (as_t, const char *);
782struct bgp *bgp_lookup_by_name (const char *);
paul718e3742002-12-13 20:15:29 +0000783struct peer *peer_lookup (struct bgp *, union sockunion *);
paulfd79ac92004-10-13 05:06:08 +0000784struct peer_group *peer_group_lookup (struct bgp *, const char *);
785struct peer_group *peer_group_get (struct bgp *, const char *);
paul718e3742002-12-13 20:15:29 +0000786struct peer *peer_lookup_with_open (union sockunion *, as_t, struct in_addr *,
787 int *);
788int peer_sort (struct peer *peer);
789int peer_active (struct peer *);
790int peer_active_nego (struct peer *);
791struct peer *peer_create_accept (struct bgp *);
792char *peer_uptime (time_t, char *, size_t);
793void bgp_config_write_family_header (struct vty *, afi_t, safi_t, int *);
794
795void bgp_master_init ();
796
797void bgp_init ();
798
799int bgp_option_set (int);
800int bgp_option_unset (int);
801int bgp_option_check (int);
802
paulfd79ac92004-10-13 05:06:08 +0000803int bgp_get (struct bgp **, as_t *, const char *);
paul718e3742002-12-13 20:15:29 +0000804int bgp_delete (struct bgp *);
805
806int bgp_flag_set (struct bgp *, int);
807int bgp_flag_unset (struct bgp *, int);
808int bgp_flag_check (struct bgp *, int);
809
810int bgp_router_id_set (struct bgp *, struct in_addr *);
811int bgp_router_id_unset (struct bgp *);
812
813int bgp_cluster_id_set (struct bgp *, struct in_addr *);
814int bgp_cluster_id_unset (struct bgp *);
815
816int bgp_confederation_id_set (struct bgp *, as_t);
817int bgp_confederation_id_unset (struct bgp *);
818int bgp_confederation_peers_check (struct bgp *, as_t);
819
820int bgp_confederation_peers_add (struct bgp *, as_t);
821int bgp_confederation_peers_remove (struct bgp *, as_t);
822
823int bgp_timers_set (struct bgp *, u_int32_t, u_int32_t);
824int bgp_timers_unset (struct bgp *);
825
826int bgp_default_local_preference_set (struct bgp *, u_int32_t);
827int bgp_default_local_preference_unset (struct bgp *);
828
paulfee0f4c2004-09-13 05:12:46 +0000829int peer_rsclient_active (struct peer *);
830
paul718e3742002-12-13 20:15:29 +0000831int peer_remote_as (struct bgp *, union sockunion *, as_t *, afi_t, safi_t);
paulfd79ac92004-10-13 05:06:08 +0000832int peer_group_remote_as (struct bgp *, const char *, as_t *);
paul718e3742002-12-13 20:15:29 +0000833int peer_delete (struct peer *peer);
834int peer_group_delete (struct peer_group *);
835int peer_group_remote_as_delete (struct peer_group *);
836
837int peer_activate (struct peer *, afi_t, safi_t);
838int peer_deactivate (struct peer *, afi_t, safi_t);
839
840int peer_group_bind (struct bgp *, union sockunion *, struct peer_group *,
841 afi_t, safi_t, as_t *);
842int peer_group_unbind (struct bgp *, struct peer *, struct peer_group *,
843 afi_t, safi_t);
844
845int peer_flag_set (struct peer *, u_int32_t);
846int peer_flag_unset (struct peer *, u_int32_t);
847
848int peer_af_flag_set (struct peer *, afi_t, safi_t, u_int32_t);
849int peer_af_flag_unset (struct peer *, afi_t, safi_t, u_int32_t);
850int peer_af_flag_check (struct peer *, afi_t, safi_t, u_int32_t);
851
852int peer_ebgp_multihop_set (struct peer *, int);
853int peer_ebgp_multihop_unset (struct peer *);
854
855int peer_description_set (struct peer *, char *);
856int peer_description_unset (struct peer *);
857
paulfd79ac92004-10-13 05:06:08 +0000858int peer_update_source_if_set (struct peer *, const char *);
paul718e3742002-12-13 20:15:29 +0000859int peer_update_source_addr_set (struct peer *, union sockunion *);
860int peer_update_source_unset (struct peer *);
861
paulfd79ac92004-10-13 05:06:08 +0000862int peer_default_originate_set (struct peer *, afi_t, safi_t, const char *);
paul718e3742002-12-13 20:15:29 +0000863int peer_default_originate_unset (struct peer *, afi_t, safi_t);
864
865int peer_port_set (struct peer *, u_int16_t);
866int peer_port_unset (struct peer *);
867
868int peer_weight_set (struct peer *, u_int16_t);
869int peer_weight_unset (struct peer *);
870
871int peer_timers_set (struct peer *, u_int32_t, u_int32_t);
872int peer_timers_unset (struct peer *);
873
874int peer_timers_connect_set (struct peer *, u_int32_t);
875int peer_timers_connect_unset (struct peer *);
876
877int peer_advertise_interval_set (struct peer *, u_int32_t);
878int peer_advertise_interval_unset (struct peer *);
879
paulfd79ac92004-10-13 05:06:08 +0000880int peer_interface_set (struct peer *, const char *);
paul718e3742002-12-13 20:15:29 +0000881int peer_interface_unset (struct peer *);
882
paulfd79ac92004-10-13 05:06:08 +0000883int peer_distribute_set (struct peer *, afi_t, safi_t, int, const char *);
paul718e3742002-12-13 20:15:29 +0000884int peer_distribute_unset (struct peer *, afi_t, safi_t, int);
885
886int peer_allowas_in_set (struct peer *, afi_t, safi_t, int);
887int peer_allowas_in_unset (struct peer *, afi_t, safi_t);
888
889int peer_local_as_set (struct peer *, as_t, int);
890int peer_local_as_unset (struct peer *);
891
paulfd79ac92004-10-13 05:06:08 +0000892int peer_prefix_list_set (struct peer *, afi_t, safi_t, int, const char *);
paul718e3742002-12-13 20:15:29 +0000893int peer_prefix_list_unset (struct peer *, afi_t, safi_t, int);
894
paulfd79ac92004-10-13 05:06:08 +0000895int peer_aslist_set (struct peer *, afi_t, safi_t, int, const char *);
paul718e3742002-12-13 20:15:29 +0000896int peer_aslist_unset (struct peer *,afi_t, safi_t, int);
897
paulfd79ac92004-10-13 05:06:08 +0000898int peer_route_map_set (struct peer *, afi_t, safi_t, int, const char *);
paul718e3742002-12-13 20:15:29 +0000899int peer_route_map_unset (struct peer *, afi_t, safi_t, int);
900
paulfd79ac92004-10-13 05:06:08 +0000901int peer_unsuppress_map_set (struct peer *, afi_t, safi_t, const char *);
paul718e3742002-12-13 20:15:29 +0000902int peer_unsuppress_map_unset (struct peer *, afi_t, safi_t);
903
hasso0a486e52005-02-01 20:57:17 +0000904int peer_maximum_prefix_set (struct peer *, afi_t, safi_t, u_int32_t, u_char, int, u_int16_t);
paul718e3742002-12-13 20:15:29 +0000905int peer_maximum_prefix_unset (struct peer *, afi_t, safi_t);
906
907int peer_clear (struct peer *);
908int peer_clear_soft (struct peer *, afi_t, safi_t, enum bgp_clear_type);
hasso93406d82005-02-02 14:40:33 +0000909
910void peer_nsf_stop (struct peer *);
paul00d252c2005-05-23 14:19:54 +0000911
912#endif /* _QUAGGA_BGPD_H */