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