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