]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgpd.h
During connection setup, there may be two connections in progress for a BGP
[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. */
3f9c7369 25#include "queue.h"
718e3744 26#include "sockunion.h"
518f0eb1 27#include "routemap.h"
718e3744 28
3f9c7369
DS
29struct update_subgroup;
30struct bpacket;
31
718e3744 32/* Typedef BGP specific types. */
0b2aa3a0
PJ
33typedef u_int32_t as_t;
34typedef u_int16_t as16_t; /* we may still encounter 16 Bit asnums */
718e3744 35typedef u_int16_t bgp_size_t;
36
3f9c7369
DS
37#define max(a,b) \
38 ({ __typeof__ (a) _a = (a); \
39 __typeof__ (b) _b = (b); \
40 _a > _b ? _a : _b; })
41
42enum bgp_af_index
43{
44 BGP_AF_START,
45 BGP_AF_IPV4_UNICAST = BGP_AF_START,
46 BGP_AF_IPV4_MULTICAST,
47 BGP_AF_IPV4_VPN,
48 BGP_AF_IPV6_UNICAST,
49 BGP_AF_IPV6_MULTICAST,
50 BGP_AF_MAX
51};
52
53#define AF_FOREACH(af) \
54 for ((af) = BGP_AF_START; (af) < BGP_AF_MAX; (af)++)
55
56#define FOREACH_AFI_SAFI(afi, safi) \
57 for (afi = AFI_IP; afi < AFI_MAX; afi++) \
58 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
59
60
718e3744 61/* BGP master for system wide configurations and variables. */
62struct bgp_master
63{
64 /* BGP instance list. */
65 struct list *bgp;
66
67 /* BGP thread master. */
68 struct thread_master *master;
69
200df115 70 /* work queues */
71 struct work_queue *process_main_queue;
72 struct work_queue *process_rsclient_queue;
200df115 73
0df7c91f
PJ
74 /* Listening sockets */
75 struct list *listen_sockets;
76
718e3744 77 /* BGP port number. */
78 u_int16_t port;
79
3a02d1f7
PJ
80 /* Listener address */
81 char *address;
82
718e3744 83 /* BGP start time. */
84 time_t start_time;
85
86 /* Various BGP global configuration. */
87 u_char options;
88#define BGP_OPT_NO_FIB (1 << 0)
89#define BGP_OPT_MULTIPLE_INSTANCE (1 << 1)
90#define BGP_OPT_CONFIG_CISCO (1 << 2)
cccbc015 91#define BGP_OPT_NO_LISTEN (1 << 3)
3f9c7369
DS
92
93 u_int64_t updgrp_idspace;
94 u_int64_t subgrp_idspace;
718e3744 95};
96
73ac8160
DS
97/* BGP route-map structure. */
98struct bgp_rmap
99{
100 char *name;
101 struct route_map *map;
102};
103
7c8ff89e
DS
104struct bgp_redist
105{
106 u_short instance;
107
108 /* BGP redistribute metric configuration. */
109 u_char redist_metric_flag;
110 u_int32_t redist_metric;
111
112 /* BGP redistribute route-map. */
113 struct bgp_rmap rmap;
114};
115
718e3744 116/* BGP instance structure. */
117struct bgp
118{
119 /* AS number of this BGP instance. */
120 as_t as;
121
122 /* Name of this BGP instance. */
123 char *name;
200df115 124
0088b5dc
SH
125 /* Reference count to allow peer_delete to finish after bgp_delete */
126 int lock;
127
718e3744 128 /* Self peer. */
129 struct peer *peer_self;
130
131 /* BGP peer. */
132 struct list *peer;
133
134 /* BGP peer group. */
135 struct list *group;
136
f14e6fdb
DS
137 /* The maximum number of BGP dynamic neighbors that can be created */
138 int dynamic_neighbors_limit;
139
140 /* The current number of BGP dynamic neighbors */
141 int dynamic_neighbors_count;
142
fee0f4c6 143 /* BGP route-server-clients. */
144 struct list *rsclient;
145
3f9c7369
DS
146 struct hash *update_groups[BGP_AF_MAX];
147
148 /*
149 * Global statistics for update groups.
150 */
151 struct {
152 u_int32_t join_events;
153 u_int32_t prune_events;
154 u_int32_t merge_events;
155 u_int32_t split_events;
156 u_int32_t updgrp_switch_events;
157 u_int32_t peer_refreshes_combined;
158 u_int32_t adj_count;
159 u_int32_t merge_checks_triggered;
160
161 u_int32_t updgrps_created;
162 u_int32_t updgrps_deleted;
163 u_int32_t subgrps_created;
164 u_int32_t subgrps_deleted;
165 } update_group_stats;
166
718e3744 167 /* BGP configuration. */
168 u_int16_t config;
169#define BGP_CONFIG_ROUTER_ID (1 << 0)
170#define BGP_CONFIG_CLUSTER_ID (1 << 1)
171#define BGP_CONFIG_CONFEDERATION (1 << 2)
718e3744 172
173 /* BGP router identifier. */
174 struct in_addr router_id;
18a6dce6 175 struct in_addr router_id_static;
718e3744 176
177 /* BGP route reflector cluster ID. */
178 struct in_addr cluster_id;
179
180 /* BGP confederation information. */
181 as_t confed_id;
182 as_t *confed_peers;
183 int confed_peers_cnt;
184
abc920f8
DS
185 struct thread *t_startup; /* start-up timer on only once at the beginning */
186
187 u_int32_t v_maxmed_onstartup; /* Duration of max-med on start-up */
188#define BGP_MAXMED_ONSTARTUP_UNCONFIGURED 0 /* 0 means off, its the default */
189 u_int32_t maxmed_onstartup_value; /* Max-med value when active on start-up */
190 struct thread *t_maxmed_onstartup; /* non-null when max-med onstartup is on */
191 u_char maxmed_onstartup_over; /* Flag to make it effective only once */
192
193 u_char v_maxmed_admin; /* 1/0 if max-med administrative is on/off */
194#define BGP_MAXMED_ADMIN_UNCONFIGURED 0 /* Off by default */
195 u_int32_t maxmed_admin_value; /* Max-med value when administrative in on */
196#define BGP_MAXMED_VALUE_DEFAULT 4294967294 /* Maximum by default */
197
198 u_char maxmed_active; /* 1/0 if max-med is active or not */
199 u_int32_t maxmed_value; /* Max-med value when its active */
fe7d2a48 200
f188f2c4
DS
201 /* BGP update delay on startup */
202 struct thread *t_update_delay;
203 struct thread *t_establish_wait;
204 u_char update_delay_over;
4a16ae86
DS
205 u_char main_zebra_update_hold;
206 u_char main_peers_update_hold;
207 u_char rsclient_peers_update_hold;
f188f2c4
DS
208 u_int16_t v_update_delay;
209 u_int16_t v_establish_wait;
210 char update_delay_begin_time[64];
211 char update_delay_end_time[64];
4a16ae86
DS
212 char update_delay_zebra_resume_time[64];
213 char update_delay_peers_resume_time[64];
f188f2c4
DS
214 u_int32_t established;
215 u_int32_t restarted_peers;
216 u_int32_t implicit_eors;
217 u_int32_t explicit_eors;
218#define BGP_UPDATE_DELAY_DEF 0
219#define BGP_UPDATE_DELAY_MIN 0
220#define BGP_UPDATE_DELAY_MAX 3600
221
718e3744 222 /* BGP flags. */
8bd9d948 223 u_int32_t flags;
718e3744 224#define BGP_FLAG_ALWAYS_COMPARE_MED (1 << 0)
225#define BGP_FLAG_DETERMINISTIC_MED (1 << 1)
226#define BGP_FLAG_MED_MISSING_AS_WORST (1 << 2)
227#define BGP_FLAG_MED_CONFED (1 << 3)
228#define BGP_FLAG_NO_DEFAULT_IPV4 (1 << 4)
229#define BGP_FLAG_NO_CLIENT_TO_CLIENT (1 << 5)
230#define BGP_FLAG_ENFORCE_FIRST_AS (1 << 6)
231#define BGP_FLAG_COMPARE_ROUTER_ID (1 << 7)
232#define BGP_FLAG_ASPATH_IGNORE (1 << 8)
233#define BGP_FLAG_IMPORT_CHECK (1 << 9)
234#define BGP_FLAG_NO_FAST_EXT_FAILOVER (1 << 10)
848973c7 235#define BGP_FLAG_LOG_NEIGHBOR_CHANGES (1 << 11)
538621f2 236#define BGP_FLAG_GRACEFUL_RESTART (1 << 12)
6811845b 237#define BGP_FLAG_ASPATH_CONFED (1 << 13)
2fdd455c 238#define BGP_FLAG_ASPATH_MULTIPATH_RELAX (1 << 14)
8bd9d948 239#define BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY (1 << 15)
907f92c8 240#define BGP_FLAG_DISABLE_NH_CONNECTED_CHK (1 << 16)
16fc1eec 241#define BGP_FLAG_MULTIPATH_RELAX_NO_AS_SET (1 << 17)
718e3744 242
243 /* BGP Per AF flags */
244 u_int16_t af_flags[AFI_MAX][SAFI_MAX];
245#define BGP_CONFIG_DAMPENING (1 << 0)
246
247 /* Static route configuration. */
248 struct bgp_table *route[AFI_MAX][SAFI_MAX];
249
250 /* Aggregate address configuration. */
251 struct bgp_table *aggregate[AFI_MAX][SAFI_MAX];
252
253 /* BGP routing information base. */
254 struct bgp_table *rib[AFI_MAX][SAFI_MAX];
255
73ac8160
DS
256 /* BGP table route-map. */
257 struct bgp_rmap table_map[AFI_MAX][SAFI_MAX];
258
718e3744 259 /* BGP redistribute configuration. */
7c8ff89e 260 struct list *redist[AFI_MAX][ZEBRA_ROUTE_MAX];
718e3744 261
518f0eb1
DS
262 /* timer to dampen route map changes */
263 struct thread *t_rmap_update; /* Handle route map updates */
264 u_int32_t rmap_update_timer; /* Route map update timer */
265#define RMAP_DEFAULT_UPDATE_TIMER 5 /* disabled by default */
266
718e3744 267 /* BGP distance configuration. */
268 u_char distance_ebgp;
269 u_char distance_ibgp;
270 u_char distance_local;
271
272 /* BGP default local-preference. */
273 u_int32_t default_local_pref;
274
3f9c7369
DS
275 /* BGP default subgroup pkt queue max */
276 u_int32_t default_subgroup_pkt_queue_max;
277
718e3744 278 /* BGP default timer. */
279 u_int32_t default_holdtime;
280 u_int32_t default_keepalive;
538621f2 281
282 /* BGP graceful restart */
93406d87 283 u_int32_t restart_time;
284 u_int32_t stalepath_time;
165b5fff
JB
285
286 /* Maximum-paths configuration */
287 struct bgp_maxpaths_cfg {
288 u_int16_t maxpaths_ebgp;
289 u_int16_t maxpaths_ibgp;
5e242b0d
DS
290 u_int16_t ibgp_flags;
291#define BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN (1 << 0)
165b5fff 292 } maxpaths[AFI_MAX][SAFI_MAX];
cb1faec9
DS
293
294 u_int32_t wpkt_quanta; /* per peer packet quanta to write */
3f9c7369 295 u_int32_t coalesce_time;
718e3744 296};
297
d889623f
DS
298#define BGP_ROUTE_ADV_HOLD(bgp) \
299 (bgp->main_peers_update_hold || bgp->rsclient_peers_update_hold)
300
718e3744 301/* BGP peer-group support. */
302struct peer_group
303{
304 /* Name of the peer-group. */
305 char *name;
306
307 /* Pointer to BGP. */
308 struct bgp *bgp;
309
310 /* Peer-group client list. */
311 struct list *peer;
312
f14e6fdb
DS
313 /** Dynamic neighbor listening ranges */
314 struct list *listen_range[AFI_MAX];
315
718e3744 316 /* Peer-group config */
317 struct peer *conf;
318};
319
320/* BGP Notify message format. */
321struct bgp_notify
322{
323 u_char code;
324 u_char subcode;
325 char *data;
326 bgp_size_t length;
327};
328
329/* Next hop self address. */
330struct bgp_nexthop
331{
332 struct interface *ifp;
333 struct in_addr v4;
334#ifdef HAVE_IPV6
335 struct in6_addr v6_global;
336 struct in6_addr v6_local;
337#endif /* HAVE_IPV6 */
338};
339
a82478b9
DS
340/* BGP addpath values */
341#define BGP_ADDPATH_RX 1
342#define BGP_ADDPATH_TX 2
343#define BGP_ADDPATH_ID_LEN 4
344
718e3744 345/* BGP router distinguisher value. */
346#define BGP_RD_SIZE 8
347
348struct bgp_rd
349{
350 u_char val[BGP_RD_SIZE];
351};
352
fee0f4c6 353#define RMAP_IN 0
354#define RMAP_OUT 1
355#define RMAP_IMPORT 2
356#define RMAP_EXPORT 3
357#define RMAP_MAX 4
358
718e3744 359/* BGP filter structure. */
360struct bgp_filter
361{
362 /* Distribute-list. */
363 struct
364 {
365 char *name;
366 struct access_list *alist;
367 } dlist[FILTER_MAX];
368
369 /* Prefix-list. */
370 struct
371 {
372 char *name;
373 struct prefix_list *plist;
374 } plist[FILTER_MAX];
375
376 /* Filter-list. */
377 struct
378 {
379 char *name;
380 struct as_list *aslist;
381 } aslist[FILTER_MAX];
382
383 /* Route-map. */
384 struct
385 {
386 char *name;
387 struct route_map *map;
fee0f4c6 388 } map[RMAP_MAX];
718e3744 389
390 /* Unsuppress-map. */
391 struct
392 {
393 char *name;
394 struct route_map *map;
395 } usmap;
396};
397
6d85b15b
JBD
398/* IBGP/EBGP identifier. We also have a CONFED peer, which is to say,
399 a peer who's AS is part of our Confederation. */
400typedef enum
401{
402 BGP_PEER_IBGP = 1,
403 BGP_PEER_EBGP,
404 BGP_PEER_INTERNAL,
405 BGP_PEER_CONFED,
406} bgp_peer_sort_t;
407
d6661008
DS
408/* BGP message header and packet size. */
409#define BGP_MARKER_SIZE 16
410#define BGP_HEADER_SIZE 19
411#define BGP_MAX_PACKET_SIZE 4096
0a91ff55 412#define BGP_MAX_PACKET_SIZE_OVERFLOW 1024
d6661008 413
3f9c7369
DS
414/*
415 * Trigger delay for bgp_announce_route().
416 */
417#define BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS 100
418#define BGP_ANNOUNCE_ROUTE_DELAY_MS 500
419
420struct peer_af
421{
422 /* back pointer to the peer */
423 struct peer *peer;
424
425 /* which subgroup the peer_af belongs to */
426 struct update_subgroup *subgroup;
427
428 /* for being part of an update subgroup's peer list */
429 LIST_ENTRY(peer_af) subgrp_train;
430
431 /* for being part of a packet's peer list */
432 LIST_ENTRY(peer_af) pkt_train;
433
434 struct bpacket *next_pkt_to_send;
435
436 /*
437 * Trigger timer for bgp_announce_route().
438 */
439 struct thread *t_announce_route;
440
441 afi_t afi;
442 safi_t safi;
443 int afid;
444};
445
718e3744 446/* BGP neighbor structure. */
447struct peer
448{
449 /* BGP structure. */
450 struct bgp *bgp;
451
200df115 452 /* reference count, primarily to allow bgp_process'ing of route_node's
453 * to be done after a struct peer is deleted.
454 *
455 * named 'lock' for hysterical reasons within Quagga.
456 */
457 int lock;
458
718e3744 459 /* BGP peer group. */
460 struct peer_group *group;
461 u_char af_group[AFI_MAX][SAFI_MAX];
3f9c7369
DS
462 u_int64_t version[AFI_MAX][SAFI_MAX];
463
464 /* BGP peer_af structures, per configured AF on this peer */
465 struct peer_af *peer_af_array[BGP_AF_MAX];
718e3744 466
467 /* Peer's remote AS number. */
468 as_t as;
469
470 /* Peer's local AS number. */
471 as_t local_as;
472
6d85b15b
JBD
473 bgp_peer_sort_t sort;
474
718e3744 475 /* Peer's Change local AS number. */
476 as_t change_local_as;
477
478 /* Remote router ID. */
479 struct in_addr remote_id;
480
481 /* Local router ID. */
482 struct in_addr local_id;
483
fee0f4c6 484 /* Peer specific RIB when configured as route-server-client. */
485 struct bgp_table *rib[AFI_MAX][SAFI_MAX];
486
718e3744 487 /* Packet receive and send buffer. */
488 struct stream *ibuf;
489 struct stream_fifo *obuf;
490 struct stream *work;
491
8c71e481
PM
492 /* We use a separate stream to encode MP_REACH_NLRI for efficient
493 * NLRI packing. peer->work stores all the other attributes. The
494 * actual packet is then constructed by concatenating the two.
495 */
496 struct stream *scratch;
497
1ff9a340
DS
498 /* the doppelganger peer structure, due to dual TCP conn setup */
499 struct peer *doppelganger;
500
718e3744 501 /* Status of the peer. */
502 int status;
503 int ostatus;
504
6403814c
DS
505 /* FSM events, stored for debug purposes.
506 * Note: uchar used for reduced memory usage.
507 */
508 unsigned char cur_event;
509 unsigned char last_event;
510 unsigned char last_major_event;
511
0b2aa3a0
PJ
512 /* Peer index, used for dumping TABLE_DUMP_V2 format */
513 uint16_t table_dump_index;
514
718e3744 515 /* Peer information */
eb821189 516 int fd; /* File descriptor */
517 int ttl; /* TTL of TCP connection to the peer. */
fa411a21 518 int gtsm_hops; /* minimum hopcount to peer */
eb821189 519 char *desc; /* Description of the peer. */
520 unsigned short port; /* Destination port for peer */
521 char *host; /* Printable address of the peer. */
522 union sockunion su; /* Sockunion address of the peer. */
a80beece 523#define BGP_PEER_SU_UNSPEC(peer) (peer->su.sa.sa_family == AF_UNSPEC)
eb821189 524 time_t uptime; /* Last Up/Down time */
525 time_t readtime; /* Last read time */
526 time_t resettime; /* Last reset time */
718e3744 527
eb821189 528 unsigned int ifindex; /* ifindex of the BGP connection. */
a80beece 529 char *conf_if; /* neighbor interface config name. */
eb821189 530 char *ifname; /* bind interface name. */
531 char *update_if;
532 union sockunion *update_source;
eb821189 533
534 union sockunion *su_local; /* Sockunion of local address. */
535 union sockunion *su_remote; /* Sockunion of remote address. */
536 int shared_network; /* Is this peer shared same network. */
537 struct bgp_nexthop nexthop; /* Nexthop */
718e3744 538
539 /* Peer address family configuration. */
540 u_char afc[AFI_MAX][SAFI_MAX];
541 u_char afc_nego[AFI_MAX][SAFI_MAX];
542 u_char afc_adv[AFI_MAX][SAFI_MAX];
543 u_char afc_recv[AFI_MAX][SAFI_MAX];
544
0a486e5f 545 /* Capability flags (reset in bgp_stop) */
0b2aa3a0 546 u_int16_t cap;
718e3744 547#define PEER_CAP_REFRESH_ADV (1 << 0) /* refresh advertised */
548#define PEER_CAP_REFRESH_OLD_RCV (1 << 1) /* refresh old received */
549#define PEER_CAP_REFRESH_NEW_RCV (1 << 2) /* refresh rfc received */
550#define PEER_CAP_DYNAMIC_ADV (1 << 3) /* dynamic advertised */
551#define PEER_CAP_DYNAMIC_RCV (1 << 4) /* dynamic received */
538621f2 552#define PEER_CAP_RESTART_ADV (1 << 5) /* restart advertised */
553#define PEER_CAP_RESTART_RCV (1 << 6) /* restart received */
0b2aa3a0
PJ
554#define PEER_CAP_AS4_ADV (1 << 7) /* as4 advertised */
555#define PEER_CAP_AS4_RCV (1 << 8) /* as4 received */
fe7d2a48
DS
556#define PEER_CAP_RESTART_BIT_ADV (1 << 9) /* sent restart state */
557#define PEER_CAP_RESTART_BIT_RCV (1 << 10) /* peer restart state */
a82478b9
DS
558#define PEER_CAP_ADDPATH_ADV (1 << 11) /* addpath advertised */
559#define PEER_CAP_ADDPATH_RCV (1 << 12) /* addpath received */
718e3744 560
0a486e5f 561 /* Capability flags (reset in bgp_stop) */
718e3744 562 u_int16_t af_cap[AFI_MAX][SAFI_MAX];
563#define PEER_CAP_ORF_PREFIX_SM_ADV (1 << 0) /* send-mode advertised */
564#define PEER_CAP_ORF_PREFIX_RM_ADV (1 << 1) /* receive-mode advertised */
565#define PEER_CAP_ORF_PREFIX_SM_RCV (1 << 2) /* send-mode received */
566#define PEER_CAP_ORF_PREFIX_RM_RCV (1 << 3) /* receive-mode received */
567#define PEER_CAP_ORF_PREFIX_SM_OLD_RCV (1 << 4) /* send-mode received */
568#define PEER_CAP_ORF_PREFIX_RM_OLD_RCV (1 << 5) /* receive-mode received */
93406d87 569#define PEER_CAP_RESTART_AF_RCV (1 << 6) /* graceful restart afi/safi received */
570#define PEER_CAP_RESTART_AF_PRESERVE_RCV (1 << 7) /* graceful restart afi/safi F-bit received */
a82478b9
DS
571#define PEER_CAP_ADDPATH_AF_TX_ADV (1 << 8) /* addpath tx advertised */
572#define PEER_CAP_ADDPATH_AF_TX_RCV (1 << 9) /* addpath tx received */
573#define PEER_CAP_ADDPATH_AF_RX_ADV (1 << 10) /* addpath rx advertised */
574#define PEER_CAP_ADDPATH_AF_RX_RCV (1 << 11) /* addpath rx received */
718e3744 575
576 /* Global configuration flags. */
577 u_int32_t flags;
578#define PEER_FLAG_PASSIVE (1 << 0) /* passive mode */
579#define PEER_FLAG_SHUTDOWN (1 << 1) /* shutdown */
580#define PEER_FLAG_DONT_CAPABILITY (1 << 2) /* dont-capability */
581#define PEER_FLAG_OVERRIDE_CAPABILITY (1 << 3) /* override-capability */
582#define PEER_FLAG_STRICT_CAP_MATCH (1 << 4) /* strict-match */
c9502438 583#define PEER_FLAG_DYNAMIC_CAPABILITY (1 << 5) /* dynamic capability */
6ffd2079 584#define PEER_FLAG_DISABLE_CONNECTED_CHECK (1 << 6) /* disable-connected-check */
c9502438 585#define PEER_FLAG_LOCAL_AS_NO_PREPEND (1 << 7) /* local-as no-prepend */
9d3f9705 586#define PEER_FLAG_LOCAL_AS_REPLACE_AS (1 << 8) /* local-as no-prepend replace-as */
1ff9a340
DS
587#define PEER_FLAG_DELETE (1 << 9) /* mark the peer for deleting */
588#define PEER_FLAG_CONFIG_NODE (1 << 10) /* the node to update configs on */
d5a5c8f0 589#define PEER_FLAG_BFD (1 << 11) /* bfd */
3f9c7369 590#define PEER_FLAG_LONESOUL (1 << 12)
f14e6fdb 591#define PEER_FLAG_DYNAMIC_NEIGHBOR (1 << 13) /* dynamic neighbor */
718e3744 592
93406d87 593 /* NSF mode (graceful restart) */
594 u_char nsf[AFI_MAX][SAFI_MAX];
595
718e3744 596 /* Per AF configuration flags. */
597 u_int32_t af_flags[AFI_MAX][SAFI_MAX];
598#define PEER_FLAG_SEND_COMMUNITY (1 << 0) /* send-community */
599#define PEER_FLAG_SEND_EXT_COMMUNITY (1 << 1) /* send-community ext. */
600#define PEER_FLAG_NEXTHOP_SELF (1 << 2) /* next-hop-self */
601#define PEER_FLAG_REFLECTOR_CLIENT (1 << 3) /* reflector-client */
602#define PEER_FLAG_RSERVER_CLIENT (1 << 4) /* route-server-client */
603#define PEER_FLAG_SOFT_RECONFIG (1 << 5) /* soft-reconfiguration */
604#define PEER_FLAG_AS_PATH_UNCHANGED (1 << 6) /* transparent-as */
605#define PEER_FLAG_NEXTHOP_UNCHANGED (1 << 7) /* transparent-next-hop */
606#define PEER_FLAG_MED_UNCHANGED (1 << 8) /* transparent-next-hop */
607#define PEER_FLAG_DEFAULT_ORIGINATE (1 << 9) /* default-originate */
608#define PEER_FLAG_REMOVE_PRIVATE_AS (1 << 10) /* remove-private-as */
609#define PEER_FLAG_ALLOWAS_IN (1 << 11) /* set allowas-in */
610#define PEER_FLAG_ORF_PREFIX_SM (1 << 12) /* orf capability send-mode */
611#define PEER_FLAG_ORF_PREFIX_RM (1 << 13) /* orf capability receive-mode */
612#define PEER_FLAG_MAX_PREFIX (1 << 14) /* maximum prefix */
613#define PEER_FLAG_MAX_PREFIX_WARNING (1 << 15) /* maximum prefix warning-only */
0df7c91f 614#define PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED (1 << 16) /* leave link-local nexthop unchanged */
9e7a53c1 615#define PEER_FLAG_NEXTHOP_SELF_ALL (1 << 17) /* next-hop-self all */
5000f21c
DS
616#define PEER_FLAG_REMOVE_PRIVATE_AS_ALL (1 << 18) /* remove-private-as all */
617#define PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE (1 << 19) /* remove-private-as replace-as */
c7122e14 618#define PEER_FLAG_AS_OVERRIDE (1 << 20) /* as-override */
0df7c91f
PJ
619
620 /* MD5 password */
621 char *password;
718e3744 622
623 /* default-originate route-map. */
624 struct
625 {
626 char *name;
627 struct route_map *map;
628 } default_rmap[AFI_MAX][SAFI_MAX];
629
630 /* Peer status flags. */
631 u_int16_t sflags;
632#define PEER_STATUS_ACCEPT_PEER (1 << 0) /* accept peer */
633#define PEER_STATUS_PREFIX_OVERFLOW (1 << 1) /* prefix-overflow */
634#define PEER_STATUS_CAPABILITY_OPEN (1 << 2) /* capability open send */
635#define PEER_STATUS_HAVE_ACCEPT (1 << 3) /* accept peer's parent */
636#define PEER_STATUS_GROUP (1 << 4) /* peer-group conf */
93406d87 637#define PEER_STATUS_NSF_MODE (1 << 5) /* NSF aware peer */
638#define PEER_STATUS_NSF_WAIT (1 << 6) /* wait comeback peer */
718e3744 639
0a486e5f 640 /* Peer status af flags (reset in bgp_stop) */
718e3744 641 u_int16_t af_sflags[AFI_MAX][SAFI_MAX];
642#define PEER_STATUS_ORF_PREFIX_SEND (1 << 0) /* prefix-list send peer */
643#define PEER_STATUS_ORF_WAIT_REFRESH (1 << 1) /* wait refresh received peer */
644#define PEER_STATUS_DEFAULT_ORIGINATE (1 << 2) /* default-originate peer */
e0701b79 645#define PEER_STATUS_PREFIX_THRESHOLD (1 << 3) /* exceed prefix-threshold */
646#define PEER_STATUS_PREFIX_LIMIT (1 << 4) /* exceed prefix-limit */
93406d87 647#define PEER_STATUS_EOR_SEND (1 << 5) /* end-of-rib send to peer */
648#define PEER_STATUS_EOR_RECEIVED (1 << 6) /* end-of-rib received from peer */
e0701b79 649
718e3744 650 /* Default attribute value for the peer. */
651 u_int32_t config;
652#define PEER_CONFIG_WEIGHT (1 << 0) /* Default weight. */
653#define PEER_CONFIG_TIMER (1 << 1) /* keepalive & holdtime */
654#define PEER_CONFIG_CONNECT (1 << 2) /* connect */
655#define PEER_CONFIG_ROUTEADV (1 << 3) /* route advertise */
656 u_int32_t weight;
657 u_int32_t holdtime;
658 u_int32_t keepalive;
659 u_int32_t connect;
660 u_int32_t routeadv;
661
662 /* Timer values. */
663 u_int32_t v_start;
664 u_int32_t v_connect;
665 u_int32_t v_holdtime;
666 u_int32_t v_keepalive;
667 u_int32_t v_asorig;
668 u_int32_t v_routeadv;
0a486e5f 669 u_int32_t v_pmax_restart;
93406d87 670 u_int32_t v_gr_restart;
718e3744 671
672 /* Threads. */
673 struct thread *t_read;
674 struct thread *t_write;
675 struct thread *t_start;
676 struct thread *t_connect;
677 struct thread *t_holdtime;
678 struct thread *t_keepalive;
679 struct thread *t_asorig;
680 struct thread *t_routeadv;
0a486e5f 681 struct thread *t_pmax_restart;
93406d87 682 struct thread *t_gr_restart;
683 struct thread *t_gr_stale;
64e580a7
PJ
684
685 /* workqueues */
686 struct work_queue *clear_node_queue;
687
718e3744 688 /* Statistics field */
689 u_int32_t open_in; /* Open message input count */
690 u_int32_t open_out; /* Open message output count */
691 u_int32_t update_in; /* Update message input count */
692 u_int32_t update_out; /* Update message ouput count */
693 time_t update_time; /* Update message received time. */
694 u_int32_t keepalive_in; /* Keepalive input count */
695 u_int32_t keepalive_out; /* Keepalive output count */
696 u_int32_t notify_in; /* Notify input count */
697 u_int32_t notify_out; /* Notify output count */
698 u_int32_t refresh_in; /* Route Refresh input count */
699 u_int32_t refresh_out; /* Route Refresh output count */
700 u_int32_t dynamic_cap_in; /* Dynamic Capability input count. */
701 u_int32_t dynamic_cap_out; /* Dynamic Capability output count. */
702
703 /* BGP state count */
704 u_int32_t established; /* Established */
705 u_int32_t dropped; /* Dropped */
706
f188f2c4
DS
707 /* Update delay related fields */
708 u_char update_delay_over; /* When this is set, BGP is no more waiting for EOR */
709
718e3744 710 /* Syncronization list and time. */
711 struct bgp_synchronize *sync[AFI_MAX][SAFI_MAX];
712 time_t synctime;
cb1faec9 713 time_t last_write; /* timestamp when the last UPDATE msg was written */
718e3744 714
715 /* Send prefix count. */
716 unsigned long scount[AFI_MAX][SAFI_MAX];
717
718 /* Announcement attribute hash. */
719 struct hash *hash[AFI_MAX][SAFI_MAX];
720
721 /* Notify data. */
722 struct bgp_notify notify;
723
724 /* Whole packet size to be read. */
725 unsigned long packet_size;
726
727 /* Filter structure. */
728 struct bgp_filter filter[AFI_MAX][SAFI_MAX];
729
730 /* ORF Prefix-list */
731 struct prefix_list *orf_plist[AFI_MAX][SAFI_MAX];
732
16286195
DS
733 /* Text description of last attribute rcvd */
734 char rcvd_attr_str[BUFSIZ];
735
736 /* Track if we printed the attribute in debugs */
737 int rcvd_attr_printed;
738
718e3744 739 /* Prefix count. */
740 unsigned long pcount[AFI_MAX][SAFI_MAX];
741
742 /* Max prefix count. */
743 unsigned long pmax[AFI_MAX][SAFI_MAX];
e0701b79 744 u_char pmax_threshold[AFI_MAX][SAFI_MAX];
0a486e5f 745 u_int16_t pmax_restart[AFI_MAX][SAFI_MAX];
e0701b79 746#define MAXIMUM_PREFIX_THRESHOLD_DEFAULT 75
718e3744 747
748 /* allowas-in. */
749 char allowas_in[AFI_MAX][SAFI_MAX];
ac41b2a2 750
e0701b79 751 /* peer reset cause */
752 char last_reset;
753#define PEER_DOWN_RID_CHANGE 1 /* bgp router-id command */
754#define PEER_DOWN_REMOTE_AS_CHANGE 2 /* neighbor remote-as command */
755#define PEER_DOWN_LOCAL_AS_CHANGE 3 /* neighbor local-as command */
756#define PEER_DOWN_CLID_CHANGE 4 /* bgp cluster-id command */
757#define PEER_DOWN_CONFED_ID_CHANGE 5 /* bgp confederation identifier command */
758#define PEER_DOWN_CONFED_PEER_CHANGE 6 /* bgp confederation peer command */
759#define PEER_DOWN_RR_CLIENT_CHANGE 7 /* neighbor route-reflector-client command */
760#define PEER_DOWN_RS_CLIENT_CHANGE 8 /* neighbor route-server-client command */
761#define PEER_DOWN_UPDATE_SOURCE_CHANGE 9 /* neighbor update-source command */
762#define PEER_DOWN_AF_ACTIVATE 10 /* neighbor activate command */
763#define PEER_DOWN_USER_SHUTDOWN 11 /* neighbor shutdown command */
764#define PEER_DOWN_USER_RESET 12 /* clear ip bgp command */
765#define PEER_DOWN_NOTIFY_RECEIVED 13 /* notification received */
766#define PEER_DOWN_NOTIFY_SEND 14 /* notification send */
767#define PEER_DOWN_CLOSE_SESSION 15 /* tcp session close */
768#define PEER_DOWN_NEIGHBOR_DELETE 16 /* neghbor delete */
769#define PEER_DOWN_RMAP_BIND 17 /* neghbor peer-group command */
770#define PEER_DOWN_RMAP_UNBIND 18 /* no neighbor peer-group command */
771#define PEER_DOWN_CAPABILITY_CHANGE 19 /* neighbor capability command */
772#define PEER_DOWN_PASSIVE_CHANGE 20 /* neighbor passive command */
773#define PEER_DOWN_MULTIHOP_CHANGE 21 /* neighbor multihop command */
93406d87 774#define PEER_DOWN_NSF_CLOSE_SESSION 22 /* NSF tcp session close */
d6661008
DS
775unsigned long last_reset_cause_size;
776u_char last_reset_cause[BGP_MAX_PACKET_SIZE];
e0701b79 777
ac41b2a2 778 /* The kind of route-map Flags.*/
779 u_char rmap_type;
780#define PEER_RMAP_TYPE_IN (1 << 0) /* neighbor route-map in */
781#define PEER_RMAP_TYPE_OUT (1 << 1) /* neighbor route-map out */
782#define PEER_RMAP_TYPE_NETWORK (1 << 2) /* network route-map */
783#define PEER_RMAP_TYPE_REDISTRIBUTE (1 << 3) /* redistribute route-map */
784#define PEER_RMAP_TYPE_DEFAULT (1 << 4) /* default-originate route-map */
785#define PEER_RMAP_TYPE_NOSET (1 << 5) /* not allow to set commands */
fee0f4c6 786#define PEER_RMAP_TYPE_IMPORT (1 << 6) /* neighbor route-map import */
787#define PEER_RMAP_TYPE_EXPORT (1 << 7) /* neighbor route-map export */
718e3744 788};
789
0df7c91f
PJ
790#define PEER_PASSWORD_MINLEN (1)
791#define PEER_PASSWORD_MAXLEN (80)
792
718e3744 793/* This structure's member directly points incoming packet data
794 stream. */
795struct bgp_nlri
796{
797 /* AFI. */
798 afi_t afi;
799
800 /* SAFI. */
801 safi_t safi;
802
803 /* Pointer to NLRI byte stream. */
804 u_char *nlri;
805
806 /* Length of whole NLRI. */
807 bgp_size_t length;
808};
809
3f9c7369
DS
810#define PEERAF_FOREACH(peer, paf, afi) \
811 for ((afi) = BGP_AF_START, (paf) = (peer)->peer_af_array[(afi)]; \
812 (afi) < BGP_AF_MAX; \
813 (afi)++, (paf) = (peer)->peer_af_array[(afi)]) \
814 if ((paf) != NULL) \
815
718e3744 816/* BGP versions. */
817#define BGP_VERSION_4 4
718e3744 818
819/* Default BGP port number. */
820#define BGP_PORT_DEFAULT 179
821
718e3744 822/* BGP minimum message size. */
823#define BGP_MSG_OPEN_MIN_SIZE (BGP_HEADER_SIZE + 10)
824#define BGP_MSG_UPDATE_MIN_SIZE (BGP_HEADER_SIZE + 4)
825#define BGP_MSG_NOTIFY_MIN_SIZE (BGP_HEADER_SIZE + 2)
826#define BGP_MSG_KEEPALIVE_MIN_SIZE (BGP_HEADER_SIZE + 0)
827#define BGP_MSG_ROUTE_REFRESH_MIN_SIZE (BGP_HEADER_SIZE + 4)
828#define BGP_MSG_CAPABILITY_MIN_SIZE (BGP_HEADER_SIZE + 3)
829
830/* BGP message types. */
831#define BGP_MSG_OPEN 1
832#define BGP_MSG_UPDATE 2
833#define BGP_MSG_NOTIFY 3
834#define BGP_MSG_KEEPALIVE 4
835#define BGP_MSG_ROUTE_REFRESH_NEW 5
836#define BGP_MSG_CAPABILITY 6
837#define BGP_MSG_ROUTE_REFRESH_OLD 128
838
839/* BGP open optional parameter. */
840#define BGP_OPEN_OPT_AUTH 1
841#define BGP_OPEN_OPT_CAP 2
842
843/* BGP4 attribute type codes. */
844#define BGP_ATTR_ORIGIN 1
845#define BGP_ATTR_AS_PATH 2
846#define BGP_ATTR_NEXT_HOP 3
847#define BGP_ATTR_MULTI_EXIT_DISC 4
848#define BGP_ATTR_LOCAL_PREF 5
849#define BGP_ATTR_ATOMIC_AGGREGATE 6
850#define BGP_ATTR_AGGREGATOR 7
851#define BGP_ATTR_COMMUNITIES 8
852#define BGP_ATTR_ORIGINATOR_ID 9
853#define BGP_ATTR_CLUSTER_LIST 10
854#define BGP_ATTR_DPA 11
855#define BGP_ATTR_ADVERTISER 12
856#define BGP_ATTR_RCID_PATH 13
857#define BGP_ATTR_MP_REACH_NLRI 14
858#define BGP_ATTR_MP_UNREACH_NLRI 15
859#define BGP_ATTR_EXT_COMMUNITIES 16
0b2aa3a0
PJ
860#define BGP_ATTR_AS4_PATH 17
861#define BGP_ATTR_AS4_AGGREGATOR 18
41367172 862#define BGP_ATTR_AS_PATHLIMIT 21
718e3744 863
864/* BGP update origin. */
865#define BGP_ORIGIN_IGP 0
866#define BGP_ORIGIN_EGP 1
867#define BGP_ORIGIN_INCOMPLETE 2
868
869/* BGP notify message codes. */
870#define BGP_NOTIFY_HEADER_ERR 1
871#define BGP_NOTIFY_OPEN_ERR 2
872#define BGP_NOTIFY_UPDATE_ERR 3
873#define BGP_NOTIFY_HOLD_ERR 4
874#define BGP_NOTIFY_FSM_ERR 5
875#define BGP_NOTIFY_CEASE 6
876#define BGP_NOTIFY_CAPABILITY_ERR 7
877#define BGP_NOTIFY_MAX 8
878
4b4e07d2
DT
879#define BGP_NOTIFY_SUBCODE_UNSPECIFIC 0
880
718e3744 881/* BGP_NOTIFY_HEADER_ERR sub codes. */
882#define BGP_NOTIFY_HEADER_NOT_SYNC 1
883#define BGP_NOTIFY_HEADER_BAD_MESLEN 2
884#define BGP_NOTIFY_HEADER_BAD_MESTYPE 3
885#define BGP_NOTIFY_HEADER_MAX 4
886
887/* BGP_NOTIFY_OPEN_ERR sub codes. */
888#define BGP_NOTIFY_OPEN_UNSUP_VERSION 1
889#define BGP_NOTIFY_OPEN_BAD_PEER_AS 2
890#define BGP_NOTIFY_OPEN_BAD_BGP_IDENT 3
891#define BGP_NOTIFY_OPEN_UNSUP_PARAM 4
892#define BGP_NOTIFY_OPEN_AUTH_FAILURE 5
893#define BGP_NOTIFY_OPEN_UNACEP_HOLDTIME 6
894#define BGP_NOTIFY_OPEN_UNSUP_CAPBL 7
895#define BGP_NOTIFY_OPEN_MAX 8
896
897/* BGP_NOTIFY_UPDATE_ERR sub codes. */
898#define BGP_NOTIFY_UPDATE_MAL_ATTR 1
899#define BGP_NOTIFY_UPDATE_UNREC_ATTR 2
900#define BGP_NOTIFY_UPDATE_MISS_ATTR 3
901#define BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR 4
902#define BGP_NOTIFY_UPDATE_ATTR_LENG_ERR 5
903#define BGP_NOTIFY_UPDATE_INVAL_ORIGIN 6
904#define BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP 7
905#define BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP 8
906#define BGP_NOTIFY_UPDATE_OPT_ATTR_ERR 9
907#define BGP_NOTIFY_UPDATE_INVAL_NETWORK 10
908#define BGP_NOTIFY_UPDATE_MAL_AS_PATH 11
909#define BGP_NOTIFY_UPDATE_MAX 12
910
4b4e07d2 911/* BGP_NOTIFY_CEASE sub codes (RFC 4486). */
718e3744 912#define BGP_NOTIFY_CEASE_MAX_PREFIX 1
913#define BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN 2
914#define BGP_NOTIFY_CEASE_PEER_UNCONFIG 3
915#define BGP_NOTIFY_CEASE_ADMIN_RESET 4
916#define BGP_NOTIFY_CEASE_CONNECT_REJECT 5
917#define BGP_NOTIFY_CEASE_CONFIG_CHANGE 6
545acafb 918#define BGP_NOTIFY_CEASE_COLLISION_RESOLUTION 7
919#define BGP_NOTIFY_CEASE_OUT_OF_RESOURCE 8
920#define BGP_NOTIFY_CEASE_MAX 9
718e3744 921
922/* BGP_NOTIFY_CAPABILITY_ERR sub codes (draft-ietf-idr-dynamic-cap-02). */
923#define BGP_NOTIFY_CAPABILITY_INVALID_ACTION 1
924#define BGP_NOTIFY_CAPABILITY_INVALID_LENGTH 2
925#define BGP_NOTIFY_CAPABILITY_MALFORMED_CODE 3
926#define BGP_NOTIFY_CAPABILITY_MAX 4
927
928/* BGP finite state machine status. */
929#define Idle 1
930#define Connect 2
931#define Active 3
932#define OpenSent 4
933#define OpenConfirm 5
934#define Established 6
ca058a30
PJ
935#define Clearing 7
936#define Deleted 8
937#define BGP_STATUS_MAX 9
718e3744 938
939/* BGP finite state machine events. */
940#define BGP_Start 1
941#define BGP_Stop 2
942#define TCP_connection_open 3
943#define TCP_connection_closed 4
944#define TCP_connection_open_failed 5
945#define TCP_fatal_error 6
946#define ConnectRetry_timer_expired 7
947#define Hold_Timer_expired 8
948#define KeepAlive_timer_expired 9
949#define Receive_OPEN_message 10
950#define Receive_KEEPALIVE_message 11
951#define Receive_UPDATE_message 12
952#define Receive_NOTIFICATION_message 13
ca058a30
PJ
953#define Clearing_Completed 14
954#define BGP_EVENTS_MAX 15
718e3744 955
956/* BGP timers default value. */
5ca5f1c8 957#define BGP_INIT_START_TIMER 1
718e3744 958#define BGP_ERROR_START_TIMER 30
959#define BGP_DEFAULT_HOLDTIME 180
960#define BGP_DEFAULT_KEEPALIVE 60
961#define BGP_DEFAULT_ASORIGINATE 15
962#define BGP_DEFAULT_EBGP_ROUTEADV 30
963#define BGP_DEFAULT_IBGP_ROUTEADV 5
718e3744 964#define BGP_DEFAULT_CONNECT_RETRY 120
965
966/* BGP default local preference. */
967#define BGP_DEFAULT_LOCAL_PREF 100
968
3f9c7369
DS
969/* BGP default subgroup packet queue max . */
970#define BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX 40
971
538621f2 972/* BGP graceful restart */
973#define BGP_DEFAULT_RESTART_TIME 120
974#define BGP_DEFAULT_STALEPATH_TIME 360
975
42e6d745
DO
976/* RFC4364 */
977#define SAFI_MPLS_LABELED_VPN 128
718e3744 978
979/* Max TTL value. */
980#define TTL_MAX 255
981
982/* BGP uptime string length. */
983#define BGP_UPTIME_LEN 25
984
985/* Default configuration settings for bgpd. */
986#define BGP_VTY_PORT 2605
718e3744 987#define BGP_DEFAULT_CONFIG "bgpd.conf"
988
989/* Check AS path loop when we send NLRI. */
990/* #define BGP_SEND_ASPATH_CHECK */
991
f14e6fdb
DS
992/* BGP Dynamic Neighbors feature */
993#define BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT 100
994#define BGP_DYNAMIC_NEIGHBORS_LIMIT_MIN 1
995#define BGP_DYNAMIC_NEIGHBORS_LIMIT_MAX 5000
996
718e3744 997/* Flag for peer_clear_soft(). */
998enum bgp_clear_type
999{
1000 BGP_CLEAR_SOFT_NONE,
1001 BGP_CLEAR_SOFT_OUT,
1002 BGP_CLEAR_SOFT_IN,
1003 BGP_CLEAR_SOFT_BOTH,
fee0f4c6 1004 BGP_CLEAR_SOFT_IN_ORF_PREFIX,
1005 BGP_CLEAR_SOFT_RSCLIENT
718e3744 1006};
1007
1008/* Macros. */
1009#define BGP_INPUT(P) ((P)->ibuf)
1010#define BGP_INPUT_PNT(P) (STREAM_PNT(BGP_INPUT(P)))
6aa136f1
VS
1011#define BGP_IS_VALID_STATE_FOR_NOTIF(S)\
1012 (((S) == OpenSent) || ((S) == OpenConfirm) || ((S) == Established))
718e3744 1013
718e3744 1014/* Count prefix size from mask length */
1015#define PSIZE(a) (((a) + 7) / (8))
1016
1017/* BGP error codes. */
1018#define BGP_SUCCESS 0
1019#define BGP_ERR_INVALID_VALUE -1
1020#define BGP_ERR_INVALID_FLAG -2
1021#define BGP_ERR_INVALID_AS -3
1022#define BGP_ERR_INVALID_BGP -4
1023#define BGP_ERR_PEER_GROUP_MEMBER -5
1024#define BGP_ERR_MULTIPLE_INSTANCE_USED -6
1025#define BGP_ERR_PEER_GROUP_MEMBER_EXISTS -7
1026#define BGP_ERR_PEER_BELONGS_TO_GROUP -8
1027#define BGP_ERR_PEER_GROUP_AF_UNCONFIGURED -9
1028#define BGP_ERR_PEER_GROUP_NO_REMOTE_AS -10
1029#define BGP_ERR_PEER_GROUP_CANT_CHANGE -11
1030#define BGP_ERR_PEER_GROUP_MISMATCH -12
1031#define BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT -13
1032#define BGP_ERR_MULTIPLE_INSTANCE_NOT_SET -14
1033#define BGP_ERR_AS_MISMATCH -15
1034#define BGP_ERR_PEER_INACTIVE -16
1035#define BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER -17
1036#define BGP_ERR_PEER_GROUP_HAS_THE_FLAG -18
1037#define BGP_ERR_PEER_FLAG_CONFLICT -19
1038#define BGP_ERR_PEER_GROUP_SHUTDOWN -20
1039#define BGP_ERR_PEER_FILTER_CONFLICT -21
1040#define BGP_ERR_NOT_INTERNAL_PEER -22
1041#define BGP_ERR_REMOVE_PRIVATE_AS -23
1042#define BGP_ERR_AF_UNCONFIGURED -24
1043#define BGP_ERR_SOFT_RECONFIG_UNCONFIGURED -25
1044#define BGP_ERR_INSTANCE_MISMATCH -26
1045#define BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP -27
1046#define BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS -28
0df7c91f 1047#define BGP_ERR_TCPSIG_FAILED -29
fa411a21 1048#define BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK -30
f5a4827d 1049#define BGP_ERR_NO_IBGP_WITH_TTLHACK -31
a80beece 1050#define BGP_ERR_NO_INTERFACE_CONFIG -32
9d3f9705 1051#define BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS_REMOTE_AS -33
c7122e14 1052#define BGP_ERR_AS_OVERRIDE -34
f14e6fdb
DS
1053#define BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT -35
1054#define BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS -36
1055#define BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND -37
1056#define BGP_ERR_INVALID_FOR_DYNAMIC_PEER -38
1057#define BGP_ERR_MAX -39
718e3744 1058
3f9c7369
DS
1059/*
1060 * Enumeration of different policy kinds a peer can be configured with.
1061 */
1062typedef enum
1063{
1064 BGP_POLICY_ROUTE_MAP,
1065 BGP_POLICY_FILTER_LIST,
1066 BGP_POLICY_PREFIX_LIST,
1067 BGP_POLICY_DISTRIBUTE_LIST,
1068} bgp_policy_type_e;
1069
718e3744 1070extern struct bgp_master *bm;
1071
1072extern struct thread_master *master;
1073
1074/* Prototypes. */
94f2b392 1075extern void bgp_terminate (void);
1076extern void bgp_reset (void);
65957886 1077extern time_t bgp_clock (void);
94f2b392 1078extern void bgp_zclient_reset (void);
1079extern int bgp_nexthop_set (union sockunion *, union sockunion *,
718e3744 1080 struct bgp_nexthop *, struct peer *);
94f2b392 1081extern struct bgp *bgp_get_default (void);
1082extern struct bgp *bgp_lookup (as_t, const char *);
1083extern struct bgp *bgp_lookup_by_name (const char *);
1084extern struct peer *peer_lookup (struct bgp *, union sockunion *);
a80beece
DS
1085extern struct peer *peer_lookup_by_conf_if (struct bgp *, const char *);
1086extern struct peer *peer_conf_interface_get(struct bgp *, const char *, afi_t,
1087 safi_t);
1088extern void bgp_peer_conf_if_to_su_update (struct peer *);
94f2b392 1089extern struct peer_group *peer_group_lookup (struct bgp *, const char *);
1090extern struct peer_group *peer_group_get (struct bgp *, const char *);
f14e6fdb
DS
1091extern struct peer *peer_create_bind_dynamic_neighbor (struct bgp *,
1092 union sockunion *, struct peer_group *);
1093extern struct prefix *peer_group_lookup_dynamic_neighbor_range (
1094 struct peer_group *, struct prefix *);
1095extern struct peer_group *peer_group_lookup_dynamic_neighbor (struct bgp *,
1096 struct prefix *, struct prefix **);
1097extern struct peer *peer_lookup_dynamic_neighbor (struct bgp *,
1098 union sockunion *);
1099extern void peer_drop_dynamic_neighbor (struct peer *);
200df115 1100extern struct peer *peer_lock (struct peer *);
1101extern struct peer *peer_unlock (struct peer *);
6d85b15b 1102extern bgp_peer_sort_t peer_sort (struct peer *peer);
94f2b392 1103extern int peer_active (struct peer *);
1104extern int peer_active_nego (struct peer *);
a80beece
DS
1105extern struct peer *peer_create(union sockunion *, const char *, struct bgp *,
1106 as_t, as_t, afi_t, safi_t);
94f2b392 1107extern struct peer *peer_create_accept (struct bgp *);
1ff9a340 1108extern void peer_xfer_config (struct peer *dst, struct peer *src);
94f2b392 1109extern char *peer_uptime (time_t, char *, size_t);
1110extern int bgp_config_write (struct vty *);
1111extern void bgp_config_write_family_header (struct vty *, afi_t, safi_t, int *);
6b0655a2 1112
94f2b392 1113extern void bgp_master_init (void);
718e3744 1114
94f2b392 1115extern void bgp_init (void);
1116extern void bgp_route_map_init (void);
718e3744 1117
94f2b392 1118extern int bgp_option_set (int);
1119extern int bgp_option_unset (int);
1120extern int bgp_option_check (int);
718e3744 1121
94f2b392 1122extern int bgp_get (struct bgp **, as_t *, const char *);
1123extern int bgp_delete (struct bgp *);
718e3744 1124
94f2b392 1125extern int bgp_flag_set (struct bgp *, int);
1126extern int bgp_flag_unset (struct bgp *, int);
1127extern int bgp_flag_check (struct bgp *, int);
718e3744 1128
0088b5dc
SH
1129extern void bgp_lock (struct bgp *);
1130extern void bgp_unlock (struct bgp *);
1131
94f2b392 1132extern int bgp_router_id_set (struct bgp *, struct in_addr *);
718e3744 1133
94f2b392 1134extern int bgp_cluster_id_set (struct bgp *, struct in_addr *);
1135extern int bgp_cluster_id_unset (struct bgp *);
718e3744 1136
94f2b392 1137extern int bgp_confederation_id_set (struct bgp *, as_t);
1138extern int bgp_confederation_id_unset (struct bgp *);
1139extern int bgp_confederation_peers_check (struct bgp *, as_t);
718e3744 1140
94f2b392 1141extern int bgp_confederation_peers_add (struct bgp *, as_t);
1142extern int bgp_confederation_peers_remove (struct bgp *, as_t);
718e3744 1143
94f2b392 1144extern int bgp_timers_set (struct bgp *, u_int32_t, u_int32_t);
1145extern int bgp_timers_unset (struct bgp *);
718e3744 1146
94f2b392 1147extern int bgp_default_local_preference_set (struct bgp *, u_int32_t);
1148extern int bgp_default_local_preference_unset (struct bgp *);
718e3744 1149
3f9c7369
DS
1150extern int bgp_default_subgroup_pkt_queue_max_set (struct bgp *bgp, u_int32_t);
1151extern int bgp_default_subgroup_pkt_queue_max_unset (struct bgp *bgp);
1152
f14e6fdb
DS
1153extern int bgp_listen_limit_set (struct bgp *, int);
1154extern int bgp_listen_limit_unset (struct bgp *);
1155
f188f2c4
DS
1156extern int bgp_update_delay_active (struct bgp *);
1157extern int bgp_update_delay_configured (struct bgp *);
94f2b392 1158extern int peer_rsclient_active (struct peer *);
a80beece
DS
1159extern void peer_as_change (struct peer *, as_t);
1160extern int peer_remote_as (struct bgp *, union sockunion *,const char *, as_t *,
1161 afi_t, safi_t);
94f2b392 1162extern int peer_group_remote_as (struct bgp *, const char *, as_t *);
1163extern int peer_delete (struct peer *peer);
1164extern int peer_group_delete (struct peer_group *);
1165extern int peer_group_remote_as_delete (struct peer_group *);
f14e6fdb 1166extern int peer_group_listen_range_add(struct peer_group *, struct prefix *);
718e3744 1167
94f2b392 1168extern int peer_activate (struct peer *, afi_t, safi_t);
1169extern int peer_deactivate (struct peer *, afi_t, safi_t);
718e3744 1170
a80beece
DS
1171extern int peer_group_bind (struct bgp *, union sockunion *, struct peer *,
1172 struct peer_group *, afi_t, safi_t, as_t *);
94f2b392 1173extern int peer_group_unbind (struct bgp *, struct peer *, struct peer_group *,
718e3744 1174 afi_t, safi_t);
1175
94f2b392 1176extern int peer_flag_set (struct peer *, u_int32_t);
1177extern int peer_flag_unset (struct peer *, u_int32_t);
718e3744 1178
94f2b392 1179extern int peer_af_flag_set (struct peer *, afi_t, safi_t, u_int32_t);
1180extern int peer_af_flag_unset (struct peer *, afi_t, safi_t, u_int32_t);
1181extern int peer_af_flag_check (struct peer *, afi_t, safi_t, u_int32_t);
718e3744 1182
94f2b392 1183extern int peer_ebgp_multihop_set (struct peer *, int);
1184extern int peer_ebgp_multihop_unset (struct peer *);
718e3744 1185
94f2b392 1186extern int peer_description_set (struct peer *, char *);
1187extern int peer_description_unset (struct peer *);
718e3744 1188
94f2b392 1189extern int peer_update_source_if_set (struct peer *, const char *);
1190extern int peer_update_source_addr_set (struct peer *, union sockunion *);
1191extern int peer_update_source_unset (struct peer *);
718e3744 1192
94f2b392 1193extern int peer_default_originate_set (struct peer *, afi_t, safi_t, const char *);
1194extern int peer_default_originate_unset (struct peer *, afi_t, safi_t);
718e3744 1195
94f2b392 1196extern int peer_port_set (struct peer *, u_int16_t);
1197extern int peer_port_unset (struct peer *);
718e3744 1198
94f2b392 1199extern int peer_weight_set (struct peer *, u_int16_t);
1200extern int peer_weight_unset (struct peer *);
718e3744 1201
94f2b392 1202extern int peer_timers_set (struct peer *, u_int32_t, u_int32_t);
1203extern int peer_timers_unset (struct peer *);
718e3744 1204
94f2b392 1205extern int peer_timers_connect_set (struct peer *, u_int32_t);
1206extern int peer_timers_connect_unset (struct peer *);
718e3744 1207
94f2b392 1208extern int peer_advertise_interval_set (struct peer *, u_int32_t);
1209extern int peer_advertise_interval_unset (struct peer *);
718e3744 1210
94f2b392 1211extern int peer_interface_set (struct peer *, const char *);
1212extern int peer_interface_unset (struct peer *);
718e3744 1213
94f2b392 1214extern int peer_distribute_set (struct peer *, afi_t, safi_t, int, const char *);
1215extern int peer_distribute_unset (struct peer *, afi_t, safi_t, int);
718e3744 1216
94f2b392 1217extern int peer_allowas_in_set (struct peer *, afi_t, safi_t, int);
1218extern int peer_allowas_in_unset (struct peer *, afi_t, safi_t);
718e3744 1219
9d3f9705 1220extern int peer_local_as_set (struct peer *, as_t, int, int);
94f2b392 1221extern int peer_local_as_unset (struct peer *);
718e3744 1222
94f2b392 1223extern int peer_prefix_list_set (struct peer *, afi_t, safi_t, int, const char *);
1224extern int peer_prefix_list_unset (struct peer *, afi_t, safi_t, int);
718e3744 1225
94f2b392 1226extern int peer_aslist_set (struct peer *, afi_t, safi_t, int, const char *);
1227extern int peer_aslist_unset (struct peer *,afi_t, safi_t, int);
718e3744 1228
94f2b392 1229extern int peer_route_map_set (struct peer *, afi_t, safi_t, int, const char *);
1230extern int peer_route_map_unset (struct peer *, afi_t, safi_t, int);
718e3744 1231
94f2b392 1232extern int peer_unsuppress_map_set (struct peer *, afi_t, safi_t, const char *);
0df7c91f
PJ
1233
1234extern int peer_password_set (struct peer *, const char *);
1235extern int peer_password_unset (struct peer *);
1236
94f2b392 1237extern int peer_unsuppress_map_unset (struct peer *, afi_t, safi_t);
718e3744 1238
94f2b392 1239extern int peer_maximum_prefix_set (struct peer *, afi_t, safi_t, u_int32_t, u_char, int, u_int16_t);
1240extern int peer_maximum_prefix_unset (struct peer *, afi_t, safi_t);
718e3744 1241
1ff9a340 1242extern int peer_clear (struct peer *, struct listnode **);
94f2b392 1243extern int peer_clear_soft (struct peer *, afi_t, safi_t, enum bgp_clear_type);
93406d87 1244
fa411a21
NH
1245extern int peer_ttl_security_hops_set (struct peer *, int);
1246extern int peer_ttl_security_hops_unset (struct peer *);
1247
518f0eb1
DS
1248extern int bgp_route_map_update_timer (struct thread *thread);
1249extern void bgp_route_map_terminate(void);
16286195
DS
1250
1251extern int peer_cmp (struct peer *p1, struct peer *p2);
3f9c7369
DS
1252
1253extern struct peer_af * peer_af_create (struct peer *, afi_t, safi_t);
1254extern struct peer_af * peer_af_find (struct peer *, afi_t, safi_t);
1255extern int peer_af_delete (struct peer *, afi_t, safi_t);
1256
1257static inline int
1258afindex (afi_t afi, safi_t safi)
1259{
1260 switch (afi)
1261 {
1262 case AFI_IP:
1263 switch (safi)
1264 {
1265 case SAFI_UNICAST:
1266 return BGP_AF_IPV4_UNICAST;
1267 break;
1268 case SAFI_MULTICAST:
1269 return BGP_AF_IPV4_MULTICAST;
1270 break;
1271 case SAFI_MPLS_VPN:
1272 return BGP_AF_IPV4_VPN;
1273 break;
1274 default:
1275 return BGP_AF_MAX;
1276 break;
1277 }
1278 break;
1279 case AFI_IP6:
1280 switch (safi)
1281 {
1282 case SAFI_UNICAST:
1283 return BGP_AF_IPV6_UNICAST;
1284 break;
1285 case SAFI_MULTICAST:
1286 return BGP_AF_IPV6_MULTICAST;
1287 break;
1288 default:
1289 return BGP_AF_MAX;
1290 break;
1291 }
1292 break;
1293 default:
1294 return BGP_AF_MAX;
1295 break;
1296 }
1297}
1298
1299/* If peer is configured at least one address family return 1. */
1300static inline int
1301peer_group_active (struct peer *peer)
1302{
1303 if (peer->af_group[AFI_IP][SAFI_UNICAST]
1304 || peer->af_group[AFI_IP][SAFI_MULTICAST]
1305 || peer->af_group[AFI_IP][SAFI_MPLS_VPN]
1306 || peer->af_group[AFI_IP6][SAFI_UNICAST]
1307 || peer->af_group[AFI_IP6][SAFI_MULTICAST])
1308 return 1;
1309 return 0;
1310}
1311
1312/* If peer is negotiated at least one address family return 1. */
1313static inline int
1314peer_afi_active_nego (const struct peer *peer, afi_t afi)
1315{
1316 if (peer->afc_nego[afi][SAFI_UNICAST]
1317 || peer->afc_nego[afi][SAFI_MULTICAST]
1318 || peer->afc_nego[afi][SAFI_MPLS_VPN])
1319 return 1;
1320 return 0;
1321}
1322
f14e6fdb
DS
1323/* If at least one address family activated for group, return 1. */
1324static inline int
1325peer_group_af_configured (struct peer_group *group)
1326{
1327 struct peer *peer = group->conf;
1328
1329 if (peer->afc[AFI_IP][SAFI_UNICAST]
1330 || peer->afc[AFI_IP][SAFI_MULTICAST]
1331 || peer->afc[AFI_IP][SAFI_MPLS_VPN]
1332 || peer->afc[AFI_IP6][SAFI_UNICAST]
1333 || peer->afc[AFI_IP6][SAFI_MULTICAST])
1334 return 1;
1335 return 0;
1336}
1337
3f9c7369
DS
1338static inline char *
1339timestamp_string (time_t ts)
1340{
1341#ifdef HAVE_CLOCK_MONOTONIC
1342 time_t tbuf;
1343 tbuf = time(NULL) - (bgp_clock() - ts);
1344 return ctime(&tbuf);
1345#else
1346 return ctime(&ts);
1347#endif /* HAVE_CLOCK_MONOTONIC */
1348}
1349
1350static inline int
1351peer_established (struct peer *peer)
1352{
1353 if (peer->status == Established)
1354 return 1;
1355 return 0;
1356}
1357
f14e6fdb
DS
1358static inline int
1359peer_dynamic_neighbor (struct peer *peer)
1360{
1361 return (CHECK_FLAG(peer->flags, PEER_FLAG_DYNAMIC_NEIGHBOR)) ? 1 : 0;
1362}
1363
00d252cb 1364#endif /* _QUAGGA_BGPD_H */