1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* BGP message definition header.
3 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
13 #include "frr_pthread.h"
20 /* For union sockunion. */
22 #include "sockunion.h"
26 #include "bgp_memory.h"
29 #include "bgp_labelpool.h"
30 #include "bgp_addpath_types.h"
31 #include "bgp_nexthop.h"
36 #define BGP_MAX_HOSTNAME 64 /* Linux max, is larger than most other sys */
37 #define BGP_PEER_MAX_HASH_SIZE 16384
39 /* Default interval for IPv6 RAs when triggered by BGP unnumbered neighbor. */
40 #define BGP_UNNUM_DEFAULT_RA_INTERVAL 10
42 struct update_subgroup
;
44 struct bgp_pbr_config
;
47 * Allow the neighbor XXXX remote-as to take internal or external
48 * AS_SPECIFIED is zero to auto-inherit original non-feature/enhancement
52 enum { AS_UNSPECIFIED
= 0,
58 /* Zebra Gracaful Restart states */
64 /* Typedef BGP specific types. */
65 typedef uint32_t as_t
;
66 typedef uint16_t as16_t
; /* we may still encounter 16 Bit asnums */
67 typedef uint16_t bgp_size_t
;
71 BGP_AF_IPV4_UNICAST
= BGP_AF_START
,
72 BGP_AF_IPV4_MULTICAST
,
75 BGP_AF_IPV6_MULTICAST
,
80 BGP_AF_IPV4_LBL_UNICAST
,
81 BGP_AF_IPV6_LBL_UNICAST
,
87 #define AF_FOREACH(af) for ((af) = BGP_AF_START; (af) < BGP_AF_MAX; (af)++)
89 #define FOREACH_SAFI(safi) \
90 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
92 extern struct frr_pthread
*bgp_pth_io
;
93 extern struct frr_pthread
*bgp_pth_ka
;
95 /* BGP master for system wide configurations and variables. */
97 /* BGP instance list. */
100 /* BGP thread master. */
101 struct thread_master
*master
;
103 /* Listening sockets */
104 struct list
*listen_sockets
;
106 /* BGP port number. */
109 /* Listener addresses */
110 struct list
*addresses
;
113 struct hash
*self_mac_hash
;
115 /* BGP start time. */
118 /* Various BGP global configuration. */
121 #define BGP_OPT_NO_FIB (1 << 0)
122 #define BGP_OPT_NO_LISTEN (1 << 1)
123 #define BGP_OPT_NO_ZEBRA (1 << 2)
125 uint64_t updgrp_idspace
;
126 uint64_t subgrp_idspace
;
128 /* timer to dampen route map changes */
129 struct thread
*t_rmap_update
; /* Handle route map updates */
130 uint32_t rmap_update_timer
; /* Route map update timer */
131 #define RMAP_DEFAULT_UPDATE_TIMER 5 /* disabled by default */
133 /* Id space for automatic RD derivation for an EVI/VRF */
134 bitfield_t rd_idspace
;
136 /* dynamic mpls label allocation pool */
137 struct labelpool labelpool
;
139 /* BGP-EVPN VRF ID. Defaults to default VRF (if any) */
140 struct bgp
* bgp_evpn
;
142 /* How big should we set the socket buffer size */
143 uint32_t socket_buffer
;
145 /* Should we do wait for fib install globally? */
148 /* EVPN multihoming */
149 struct bgp_evpn_mh_info
*mh_info
;
151 /* global update-delay timer values */
152 uint16_t v_update_delay
;
153 uint16_t v_establish_wait
;
156 #define BM_FLAG_GRACEFUL_SHUTDOWN (1 << 0)
157 #define BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA (1 << 1)
159 bool terminating
; /* global flag that sigint terminate seen */
161 /* DSCP value for TCP sessions */
164 #define BM_DEFAULT_Q_LIMIT 10000
170 DECLARE_QOBJ_TYPE(bgp_master
);
172 /* BGP route-map structure. */
175 struct route_map
*map
;
179 unsigned short instance
;
181 /* BGP redistribute metric configuration. */
182 uint8_t redist_metric_flag
;
183 uint32_t redist_metric
;
185 /* BGP redistribute route-map. */
186 struct bgp_rmap rmap
;
189 enum vpn_policy_direction
{
190 BGP_VPN_POLICY_DIR_FROMVPN
= 0,
191 BGP_VPN_POLICY_DIR_TOVPN
= 1,
192 BGP_VPN_POLICY_DIR_MAX
= 2
196 struct bgp
*bgp
; /* parent */
198 struct ecommunity
*rtlist
[BGP_VPN_POLICY_DIR_MAX
];
199 struct ecommunity
*import_redirect_rtlist
;
200 char *rmap_name
[BGP_VPN_POLICY_DIR_MAX
];
201 struct route_map
*rmap
[BGP_VPN_POLICY_DIR_MAX
];
203 /* should be mpls_label_t? */
204 uint32_t tovpn_label
; /* may be MPLS_LABEL_NONE */
205 uint32_t tovpn_zebra_vrf_label_last_sent
;
206 struct prefix_rd tovpn_rd
;
207 struct prefix tovpn_nexthop
; /* unset => set to 0 */
209 #define BGP_VPN_POLICY_TOVPN_LABEL_AUTO (1 << 0)
210 #define BGP_VPN_POLICY_TOVPN_RD_SET (1 << 1)
211 #define BGP_VPN_POLICY_TOVPN_NEXTHOP_SET (1 << 2)
212 #define BGP_VPN_POLICY_TOVPN_SID_AUTO (1 << 3)
215 * If we are importing another vrf into us keep a list of
216 * vrf names that are being imported into us.
218 struct list
*import_vrf
;
221 * if we are being exported to another vrf keep a list of
222 * vrf names that we are being exported to.
224 struct list
*export_vrf
;
227 * Segment-Routing SRv6 Mode
229 uint32_t tovpn_sid_index
; /* unset => set to 0 */
230 struct in6_addr
*tovpn_sid
;
231 struct srv6_locator_chunk
*tovpn_sid_locator
;
232 uint32_t tovpn_sid_transpose_label
;
233 struct in6_addr
*tovpn_zebra_vrf_sid_last_sent
;
237 * Type of 'struct bgp'.
238 * - Default: The default instance
239 * - VRF: A specific (non-default) VRF
240 * - View: An instance used for route exchange
241 * The "default" instance is treated separately to simplify the code. Note
242 * that if deployed in a Multi-VRF environment, it may not exist.
244 enum bgp_instance_type
{
245 BGP_INSTANCE_TYPE_DEFAULT
,
246 BGP_INSTANCE_TYPE_VRF
,
247 BGP_INSTANCE_TYPE_VIEW
250 #define BGP_SEND_EOR(bgp, afi, safi) \
251 (!CHECK_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR) \
252 && ((bgp->gr_info[afi][safi].t_select_deferral == NULL) \
253 || (bgp->gr_info[afi][safi].eor_required \
254 == bgp->gr_info[afi][safi].eor_received)))
256 /* BGP GR Global ds */
258 #define BGP_GLOBAL_GR_MODE 4
259 #define BGP_GLOBAL_GR_EVENT_CMD 4
261 /* Graceful restart selection deferral timer info */
262 struct graceful_restart_info
{
263 /* Count of EOR message expected */
264 uint32_t eor_required
;
265 /* Count of EOR received */
266 uint32_t eor_received
;
268 struct thread
*t_select_deferral
;
269 /* Routes Deferred */
270 uint32_t gr_deferred
;
271 /* Best route select */
272 struct thread
*t_route_select
;
273 /* AFI, SAFI enabled */
274 bool af_enabled
[AFI_MAX
][SAFI_MAX
];
275 /* Route update completed */
276 bool route_sync
[AFI_MAX
][SAFI_MAX
];
280 GLOBAL_HELPER
= 0, /* This is the default mode */
286 enum global_gr_command
{
290 NO_GLOBAL_DISABLE_CMD
293 #define BGP_GR_SUCCESS 0
294 #define BGP_GR_FAILURE 1
296 /* Handling of BGP link bandwidth (LB) on receiver - whether and how to
297 * do weighted ECMP. Note: This applies after multipath computation.
299 enum bgp_link_bw_handling
{
300 /* Do ECMP if some paths don't have LB - default */
302 /* Completely ignore LB, just do regular ECMP */
303 BGP_LINK_BW_IGNORE_BW
,
304 /* Skip paths without LB, do wECMP on others */
305 BGP_LINK_BW_SKIP_MISSING
,
306 /* Do wECMP with default weight for paths not having LB */
307 BGP_LINK_BW_DEFWT_4_MISSING
310 RB_HEAD(bgp_es_vrf_rb_head
, bgp_evpn_es_vrf
);
311 RB_PROTOTYPE(bgp_es_vrf_rb_head
, bgp_evpn_es_vrf
, rb_node
, bgp_es_vrf_rb_cmp
);
313 struct bgp_snmp_stats
{
314 /* SNMP variables for mplsL3Vpn*/
315 time_t creation_time
;
318 uint32_t routes_added
;
319 uint32_t routes_deleted
;
322 struct bgp_srv6_function
{
324 char locator_name
[SRV6_LOCNAME_SIZE
];
327 /* BGP instance structure. */
329 /* AS number of this BGP instance. */
332 /* Name of this BGP instance. */
334 char *name_pretty
; /* printable "VRF|VIEW name|default" */
336 /* Type of instance and VRF id. */
337 enum bgp_instance_type inst_type
;
340 /* Reference count to allow peer_delete to finish after bgp_delete */
344 struct peer
*peer_self
;
348 struct hash
*peerhash
;
350 /* BGP peer group. */
353 /* The maximum number of BGP dynamic neighbors that can be created */
354 int dynamic_neighbors_limit
;
356 /* The current number of BGP dynamic neighbors */
357 int dynamic_neighbors_count
;
359 struct hash
*update_groups
[BGP_AF_MAX
];
362 * Global statistics for update groups.
365 uint32_t join_events
;
366 uint32_t prune_events
;
367 uint32_t merge_events
;
368 uint32_t split_events
;
369 uint32_t updgrp_switch_events
;
370 uint32_t peer_refreshes_combined
;
372 uint32_t merge_checks_triggered
;
374 uint32_t updgrps_created
;
375 uint32_t updgrps_deleted
;
376 uint32_t subgrps_created
;
377 uint32_t subgrps_deleted
;
378 } update_group_stats
;
380 struct bgp_snmp_stats
*snmp_stats
;
382 /* BGP configuration. */
384 #define BGP_CONFIG_CLUSTER_ID (1 << 0)
385 #define BGP_CONFIG_CONFEDERATION (1 << 1)
387 /* BGP router identifier. */
388 struct in_addr router_id
;
389 struct in_addr router_id_static
;
390 struct in_addr router_id_zebra
;
392 /* BGP route reflector cluster ID. */
393 struct in_addr cluster_id
;
395 /* BGP confederation information. */
398 int confed_peers_cnt
;
401 *t_startup
; /* start-up timer on only once at the beginning */
403 uint32_t v_maxmed_onstartup
; /* Duration of max-med on start-up */
404 #define BGP_MAXMED_ONSTARTUP_UNCONFIGURED 0 /* 0 means off, its the default */
405 uint32_t maxmed_onstartup_value
; /* Max-med value when active on
408 *t_maxmed_onstartup
; /* non-null when max-med onstartup is on */
409 uint8_t maxmed_onstartup_over
; /* Flag to make it effective only once */
411 bool v_maxmed_admin
; /* true/false if max-med administrative is on/off
413 #define BGP_MAXMED_ADMIN_UNCONFIGURED false /* Off by default */
414 uint32_t maxmed_admin_value
; /* Max-med value when administrative in on
416 #define BGP_MAXMED_VALUE_DEFAULT 4294967294 /* Maximum by default */
418 uint8_t maxmed_active
; /* 1/0 if max-med is active or not */
419 uint32_t maxmed_value
; /* Max-med value when its active */
421 /* BGP update delay on startup */
422 struct thread
*t_update_delay
;
423 struct thread
*t_establish_wait
;
424 struct thread
*t_revalidate
[AFI_MAX
][SAFI_MAX
];
426 uint8_t update_delay_over
;
427 uint8_t main_zebra_update_hold
;
428 uint8_t main_peers_update_hold
;
429 uint16_t v_update_delay
;
430 uint16_t v_establish_wait
;
431 char update_delay_begin_time
[64];
432 char update_delay_end_time
[64];
433 char update_delay_zebra_resume_time
[64];
434 char update_delay_peers_resume_time
[64];
435 uint32_t established
;
436 uint32_t restarted_peers
;
437 uint32_t implicit_eors
;
438 uint32_t explicit_eors
;
439 #define BGP_UPDATE_DELAY_DEF 0
440 #define BGP_UPDATE_DELAY_MIN 0
441 #define BGP_UPDATE_DELAY_MAX 3600
443 /* Reference bandwidth for BGP link-bandwidth. Used when
444 * the LB value has to be computed based on some other
445 * factor (e.g., number of multipaths for the prefix)
449 #define BGP_LINK_BW_REF_BW 1
453 #define BGP_FLAG_ALWAYS_COMPARE_MED (1ULL << 0)
454 #define BGP_FLAG_DETERMINISTIC_MED (1ULL << 1)
455 #define BGP_FLAG_MED_MISSING_AS_WORST (1ULL << 2)
456 #define BGP_FLAG_MED_CONFED (1ULL << 3)
457 #define BGP_FLAG_NO_CLIENT_TO_CLIENT (1ULL << 4)
458 #define BGP_FLAG_COMPARE_ROUTER_ID (1ULL << 5)
459 #define BGP_FLAG_ASPATH_IGNORE (1ULL << 6)
460 #define BGP_FLAG_IMPORT_CHECK (1ULL << 7)
461 #define BGP_FLAG_NO_FAST_EXT_FAILOVER (1ULL << 8)
462 #define BGP_FLAG_LOG_NEIGHBOR_CHANGES (1ULL << 9)
464 /* This flag is set when we have full BGP Graceful-Restart mode enable */
465 #define BGP_FLAG_GRACEFUL_RESTART (1ULL << 10)
467 #define BGP_FLAG_ASPATH_CONFED (1ULL << 11)
468 #define BGP_FLAG_ASPATH_MULTIPATH_RELAX (1ULL << 12)
469 #define BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY (1ULL << 13)
470 #define BGP_FLAG_DISABLE_NH_CONNECTED_CHK (1ULL << 14)
471 #define BGP_FLAG_MULTIPATH_RELAX_AS_SET (1ULL << 15)
472 #define BGP_FLAG_FORCE_STATIC_PROCESS (1ULL << 16)
473 #define BGP_FLAG_SHOW_HOSTNAME (1ULL << 17)
474 #define BGP_FLAG_GR_PRESERVE_FWD (1ULL << 18)
475 #define BGP_FLAG_GRACEFUL_SHUTDOWN (1ULL << 19)
476 #define BGP_FLAG_DELETE_IN_PROGRESS (1ULL << 20)
477 #define BGP_FLAG_SELECT_DEFER_DISABLE (1ULL << 21)
478 #define BGP_FLAG_GR_DISABLE_EOR (1ULL << 22)
479 #define BGP_FLAG_EBGP_REQUIRES_POLICY (1ULL << 23)
480 #define BGP_FLAG_SHOW_NEXTHOP_HOSTNAME (1ULL << 24)
482 /* This flag is set if the instance is in administrative shutdown */
483 #define BGP_FLAG_SHUTDOWN (1ULL << 25)
484 #define BGP_FLAG_SUPPRESS_FIB_PENDING (1ULL << 26)
485 #define BGP_FLAG_SUPPRESS_DUPLICATES (1ULL << 27)
486 #define BGP_FLAG_PEERTYPE_MULTIPATH_RELAX (1ULL << 29)
487 /* Indicate Graceful Restart support for BGP NOTIFICATION messages */
488 #define BGP_FLAG_GRACEFUL_NOTIFICATION (1ULL << 30)
489 /* Send Hard Reset CEASE Notification for 'Administrative Reset' */
490 #define BGP_FLAG_HARD_ADMIN_RESET (1ULL << 31)
491 /* Evaluate the AIGP attribute during the best path selection process */
492 #define BGP_FLAG_COMPARE_AIGP (1ULL << 32)
494 /* BGP default address-families.
495 * New peers inherit enabled afi/safis from bgp instance.
497 uint16_t default_af
[AFI_MAX
][SAFI_MAX
];
499 enum global_mode GLOBAL_GR_FSM
[BGP_GLOBAL_GR_MODE
]
500 [BGP_GLOBAL_GR_EVENT_CMD
];
501 enum global_mode global_gr_present_state
;
503 /* This variable stores the current Graceful Restart state of Zebra
504 * - ZEBRA_GR_ENABLE / ZEBRA_GR_DISABLE
506 enum zebra_gr_mode present_zebra_gr_state
;
508 /* BGP Per AF flags */
509 uint16_t af_flags
[AFI_MAX
][SAFI_MAX
];
510 #define BGP_CONFIG_DAMPENING (1 << 0)
511 /* l2vpn evpn flags - 1 << 0 is used for DAMPENNG */
512 #define BGP_L2VPN_EVPN_ADV_IPV4_UNICAST (1 << 1)
513 #define BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP (1 << 2)
514 #define BGP_L2VPN_EVPN_ADV_IPV6_UNICAST (1 << 3)
515 #define BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP (1 << 4)
516 #define BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV4 (1 << 5)
517 #define BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV6 (1 << 6)
518 /* import/export between address families */
519 #define BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT (1 << 7)
520 #define BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT (1 << 8)
521 /* vrf-route leaking flags */
522 #define BGP_CONFIG_VRF_TO_VRF_IMPORT (1 << 9)
523 #define BGP_CONFIG_VRF_TO_VRF_EXPORT (1 << 10)
524 /* vpnvx retain flag */
525 #define BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL (1 << 11)
527 /* BGP per AF peer count */
528 uint32_t af_peer_count
[AFI_MAX
][SAFI_MAX
];
530 /* Tree for next-hop lookup cache. */
531 struct bgp_nexthop_cache_head nexthop_cache_table
[AFI_MAX
];
533 /* Tree for import-check */
534 struct bgp_nexthop_cache_head import_check_table
[AFI_MAX
];
536 struct bgp_table
*connected_table
[AFI_MAX
];
538 struct hash
*address_hash
;
540 /* DB for all local tunnel-ips - used mainly for martian checks
541 Currently it only has all VxLan tunnel IPs*/
542 struct hash
*tip_hash
;
544 /* Static route configuration. */
545 struct bgp_table
*route
[AFI_MAX
][SAFI_MAX
];
547 /* Aggregate address configuration. */
548 struct bgp_table
*aggregate
[AFI_MAX
][SAFI_MAX
];
550 /* BGP routing information base. */
551 struct bgp_table
*rib
[AFI_MAX
][SAFI_MAX
];
553 /* BGP table route-map. */
554 struct bgp_rmap table_map
[AFI_MAX
][SAFI_MAX
];
556 /* BGP redistribute configuration. */
557 struct list
*redist
[AFI_MAX
][ZEBRA_ROUTE_MAX
];
559 /* Allocate MPLS labels */
560 uint8_t allocate_mpls_labels
[AFI_MAX
][SAFI_MAX
];
562 /* Allocate hash entries to store policy routing information
563 * The hash are used to host pbr rules somewhere.
564 * Actually, pbr will only be used by flowspec
565 * those hash elements will have relationship together as
566 * illustrated in below diagram:
568 * pbr_action a <----- pbr_match i <--- pbr_match_entry 1..n
569 * <----- pbr_match j <--- pbr_match_entry 1..m
572 * - here in BGP structure, the list of match and actions will
573 * stand for the list of ipset sets, and table_ids in the kernel
574 * - the arrow above between pbr_match and pbr_action indicate
575 * that a backpointer permits match to find the action
576 * - the arrow betwen match_entry and match is a hash list
577 * contained in match, that lists the whole set of entries
579 struct hash
*pbr_match_hash
;
580 struct hash
*pbr_rule_hash
;
581 struct hash
*pbr_action_hash
;
583 /* timer to re-evaluate neighbor default-originate route-maps */
584 struct thread
*t_rmap_def_originate_eval
;
585 #define RMAP_DEFAULT_ORIGINATE_EVAL_TIMER 5
587 /* BGP distance configuration. */
588 uint8_t distance_ebgp
[AFI_MAX
][SAFI_MAX
];
589 uint8_t distance_ibgp
[AFI_MAX
][SAFI_MAX
];
590 uint8_t distance_local
[AFI_MAX
][SAFI_MAX
];
592 /* BGP default local-preference. */
593 uint32_t default_local_pref
;
595 /* BGP default subgroup pkt queue max */
596 uint32_t default_subgroup_pkt_queue_max
;
598 /* BGP default timer. */
599 uint32_t default_holdtime
;
600 uint32_t default_keepalive
;
601 uint32_t default_connect_retry
;
602 uint32_t default_delayopen
;
604 /* BGP minimum holdtime. */
605 uint16_t default_min_holdtime
;
607 /* BGP graceful restart */
608 uint32_t restart_time
;
609 uint32_t stalepath_time
;
610 uint32_t select_defer_time
;
611 struct graceful_restart_info gr_info
[AFI_MAX
][SAFI_MAX
];
612 uint32_t rib_stale_time
;
614 /* BGP Long-lived Graceful Restart */
615 uint32_t llgr_stale_time
;
617 #define BGP_ROUTE_SELECT_DELAY 1
618 #define BGP_MAX_BEST_ROUTE_SELECT 10000
619 /* Maximum-paths configuration */
620 struct bgp_maxpaths_cfg
{
621 uint16_t maxpaths_ebgp
;
622 uint16_t maxpaths_ibgp
;
623 bool same_clusterlen
;
624 } maxpaths
[AFI_MAX
][SAFI_MAX
];
626 _Atomic
uint32_t wpkt_quanta
; // max # packets to write per i/o cycle
627 _Atomic
uint32_t rpkt_quanta
; // max # packets to read per i/o cycle
629 /* Automatic coalesce adjust on/off */
630 bool heuristic_coalesce
;
631 /* Actual coalesce time */
632 uint32_t coalesce_time
;
634 /* Auto-shutdown new peers */
637 struct bgp_addpath_bgp_data tx_addpath
;
639 #ifdef ENABLE_BGP_VNC
640 struct rfapi_cfg
*rfapi_cfg
;
644 /* EVPN related information */
647 struct hash
*vnihash
;
650 * VNI hash table based on SVI ifindex as its key.
651 * We use SVI ifindex as key to lookup a VNI table for gateway IP
652 * overlay index recursive lookup.
653 * For this purpose, a hashtable is added which optimizes this lookup.
655 struct hash
*vni_svi_hash
;
657 /* EVPN enable - advertise gateway macip routes */
658 int advertise_gw_macip
;
660 /* EVPN enable - advertise local VNIs and their MACs etc. */
661 int advertise_all_vni
;
663 /* draft-ietf-idr-deprecate-as-set-confed-set
664 * Reject aspaths with AS_SET and/or AS_CONFED_SET.
668 struct bgp_evpn_info
*evpn_info
;
670 /* EVPN - use RFC 8365 to auto-derive RT */
671 int advertise_autort_rfc8365
;
674 * Flooding mechanism for BUM packets for VxLAN-EVPN.
676 enum vxlan_flood_control vxlan_flood_ctrl
;
678 /* Hash table of Import RTs to EVIs */
679 struct hash
*import_rt_hash
;
681 /* Hash table of VRF import RTs to VRFs */
682 struct hash
*vrf_import_rt_hash
;
684 /* L3-VNI corresponding to this vrf */
687 /* router-mac to be used in mac-ip routes for this vrf */
690 /* originator ip - to be used as NH for type-5 routes */
691 struct in_addr originator_ip
;
693 /* SVI associated with the L3-VNI corresponding to this vrf */
694 ifindex_t l3vni_svi_ifindex
;
696 /* RB tree of ES-VRFs */
697 struct bgp_es_vrf_rb_head es_vrf_rb_tree
;
699 /* Hash table of EVPN nexthops maintained per-tenant-VRF */
700 struct hash
*evpn_nh_table
;
703 * Flag resolve_overlay_index is used for recursive resolution
704 * procedures for EVPN type-5 route's gateway IP overlay index.
705 * When this flag is set, we build remote-ip-hash for
706 * all L2VNIs and resolve overlay index nexthops using this hash.
707 * Overlay index nexthops remain unresolved if this flag is not set.
709 bool resolve_overlay_index
;
713 #define BGP_VRF_AUTO (1 << 0)
714 #define BGP_VRF_IMPORT_RT_CFGD (1 << 1)
715 #define BGP_VRF_EXPORT_RT_CFGD (1 << 2)
716 #define BGP_VRF_IMPORT_AUTO_RT_CFGD (1 << 3) /* retain auto when cfgd */
717 #define BGP_VRF_EXPORT_AUTO_RT_CFGD (1 << 4) /* retain auto when cfgd */
718 #define BGP_VRF_RD_CFGD (1 << 5)
719 #define BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY (1 << 6)
720 /* per-VRF toVPN SID */
721 #define BGP_VRF_TOVPN_SID_AUTO (1 << 7)
723 /* unique ID for auto derivation of RD for this vrf */
726 /* Automatically derived RD for this VRF */
727 struct prefix_rd vrf_prd_auto
;
729 /* RD for this VRF */
730 struct prefix_rd vrf_prd
;
732 /* import rt list for the vrf instance */
733 struct list
*vrf_import_rtl
;
735 /* export rt list for the vrf instance */
736 struct list
*vrf_export_rtl
;
738 /* list of corresponding l2vnis (struct bgpevpn) */
741 /* route map for advertise ipv4/ipv6 unicast (type-5 routes) */
742 struct bgp_rmap adv_cmd_rmap
[AFI_MAX
][SAFI_MAX
];
744 struct vpn_policy vpn_policy
[AFI_MAX
];
746 struct bgp_pbr_config
*bgp_pbr_cfg
;
748 /* Count of peers in established state */
749 uint32_t established_peers
;
751 /* Weighted ECMP related config. */
752 enum bgp_link_bw_handling lb_handling
;
754 /* Process Queue for handling routes */
755 struct work_queue
*process_queue
;
757 bool fast_convergence
;
759 /* BGP Conditional advertisement */
760 uint32_t condition_check_period
;
761 uint32_t condition_filter_count
;
762 struct thread
*t_condition_check
;
764 /* BGP VPN SRv6 backend */
766 char srv6_locator_name
[SRV6_LOCNAME_SIZE
];
767 struct list
*srv6_locator_chunks
;
768 struct list
*srv6_functions
;
769 uint32_t tovpn_sid_index
; /* unset => set to 0 */
770 struct in6_addr
*tovpn_sid
;
771 struct srv6_locator_chunk
*tovpn_sid_locator
;
772 uint32_t tovpn_sid_transpose_label
;
773 struct in6_addr
*tovpn_zebra_vrf_sid_last_sent
;
775 /* TCP keepalive parameters for BGP connection */
776 uint16_t tcp_keepalive_idle
;
777 uint16_t tcp_keepalive_intvl
;
778 uint16_t tcp_keepalive_probes
;
780 struct timeval ebgprequirespolicywarning
;
781 #define FIFTEENMINUTE2USEC (int64_t)15 * 60 * 1000000
787 DECLARE_QOBJ_TYPE(bgp
);
789 struct bgp_interface
{
790 #define BGP_INTERFACE_MPLS_BGP_FORWARDING (1 << 0)
794 DECLARE_HOOK(bgp_inst_delete
, (struct bgp
*bgp
), (bgp
));
795 DECLARE_HOOK(bgp_inst_config_write
,
796 (struct bgp
*bgp
, struct vty
*vty
),
798 DECLARE_HOOK(bgp_config_end
, (struct bgp
*bgp
), (bgp
));
800 /* Thread callback information */
801 struct afi_safi_info
{
807 #define BGP_ROUTE_ADV_HOLD(bgp) (bgp->main_peers_update_hold)
809 #define IS_BGP_INST_KNOWN_TO_ZEBRA(bgp) \
810 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT \
811 || (bgp->inst_type == BGP_INSTANCE_TYPE_VRF \
812 && bgp->vrf_id != VRF_UNKNOWN))
814 #define BGP_SELECT_DEFER_DISABLE(bgp) \
815 (CHECK_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE))
817 #define BGP_SUPPRESS_FIB_ENABLED(bgp) \
818 (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING) \
821 /* BGP peer-group support. */
823 /* Name of the peer-group. */
826 /* Pointer to BGP. */
829 /* Peer-group client list. */
832 /** Dynamic neighbor listening ranges */
833 struct list
*listen_range
[AFI_MAX
];
835 /* Peer-group config */
839 /* BGP Notify message format. */
849 /* Next hop self address. */
851 struct interface
*ifp
;
853 struct in6_addr v6_global
;
854 struct in6_addr v6_local
;
857 /* BGP addpath values */
858 #define BGP_ADDPATH_RX 1
859 #define BGP_ADDPATH_TX 2
860 #define BGP_ADDPATH_ID_LEN 4
862 #define BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE 1
864 /* Route map direction */
869 #define BGP_DEFAULT_TTL 1
870 #define BGP_GTSM_HOPS_DISABLED 0
871 #define BGP_GTSM_HOPS_CONNECTED 1
874 #define CONDITION_NON_EXIST false
875 #define CONDITION_EXIST true
877 enum update_type
{ UPDATE_TYPE_WITHDRAW
, UPDATE_TYPE_ADVERTISE
};
881 /* BGP filter structure. */
883 /* Distribute-list. */
886 struct access_list
*alist
;
892 struct prefix_list
*plist
;
898 struct as_list
*aslist
;
899 } aslist
[FILTER_MAX
];
904 struct route_map
*map
;
907 /* Unsuppress-map. */
910 struct route_map
*map
;
916 struct route_map
*amap
;
921 struct route_map
*cmap
;
923 enum update_type update_type
;
927 /* IBGP/EBGP identifier. We also have a CONFED peer, which is to say,
928 a peer who's AS is part of our Confederation. */
930 BGP_PEER_UNSPECIFIED
,
937 /* BGP message header and packet size. */
938 #define BGP_MARKER_SIZE 16
939 #define BGP_HEADER_SIZE 19
940 #define BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE 4096
941 #define BGP_EXTENDED_MESSAGE_MAX_PACKET_SIZE 65535
942 #define BGP_MAX_PACKET_SIZE BGP_EXTENDED_MESSAGE_MAX_PACKET_SIZE
943 #define BGP_MAX_PACKET_SIZE_OVERFLOW 1024
946 * Trigger delay for bgp_announce_route().
948 #define BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS 100
949 #define BGP_ANNOUNCE_ROUTE_DELAY_MS 500
952 /* back pointer to the peer */
955 /* which subgroup the peer_af belongs to */
956 struct update_subgroup
*subgroup
;
958 /* for being part of an update subgroup's peer list */
959 LIST_ENTRY(peer_af
) subgrp_train
;
961 /* for being part of a packet's peer list */
962 LIST_ENTRY(peer_af
) pkt_train
;
964 struct bpacket
*next_pkt_to_send
;
967 * Trigger timer for bgp_announce_route().
969 struct thread
*t_announce_route
;
975 /* BGP GR per peer ds */
977 #define BGP_PEER_GR_MODE 5
978 #define BGP_PEER_GR_EVENT_CMD 6
985 PEER_GLOBAL_INHERIT
/* This is the default mode */
989 enum peer_gr_command
{
998 typedef unsigned int (*bgp_peer_gr_action_ptr
)(struct peer
*, int, int);
1000 struct bgp_peer_gr
{
1001 enum peer_mode next_state
;
1002 bgp_peer_gr_action_ptr action_fun
;
1006 * BGP FSM event codes, per RFC 4271 ss. 8.1
1008 enum bgp_fsm_rfc_codes
{
1009 BGP_FSM_ManualStart
= 1,
1010 BGP_FSM_ManualStop
= 2,
1011 BGP_FSM_AutomaticStart
= 3,
1012 BGP_FSM_ManualStart_with_PassiveTcpEstablishment
= 4,
1013 BGP_FSM_AutomaticStart_with_PassiveTcpEstablishment
= 5,
1014 BGP_FSM_AutomaticStart_with_DampPeerOscillations
= 6,
1015 BGP_FSM_AutomaticStart_with_DampPeerOscillations_and_PassiveTcpEstablishment
=
1017 BGP_FSM_AutomaticStop
= 8,
1018 BGP_FSM_ConnectRetryTimer_Expires
= 9,
1019 BGP_FSM_HoldTimer_Expires
= 10,
1020 BGP_FSM_KeepaliveTimer_Expires
= 11,
1021 BGP_FSM_DelayOpenTimer_Expires
= 12,
1022 BGP_FSM_IdleHoldTimer_Expires
= 13,
1023 BGP_FSM_TcpConnection_Valid
= 14,
1024 BGP_FSM_Tcp_CR_Invalid
= 15,
1025 BGP_FSM_Tcp_CR_Acked
= 16,
1026 BGP_FSM_TcpConnectionConfirmed
= 17,
1027 BGP_FSM_TcpConnectionFails
= 18,
1028 BGP_FSM_BGPOpen
= 19,
1029 BGP_FSM_BGPOpen_with_DelayOpenTimer_running
= 20,
1030 BGP_FSM_BGPHeaderErr
= 21,
1031 BGP_FSM_BGPOpenMsgErr
= 22,
1032 BGP_FSM_OpenCollisionDump
= 23,
1033 BGP_FSM_NotifMsgVerErr
= 24,
1034 BGP_FSM_NotifMsg
= 25,
1035 BGP_FSM_KeepAliveMsg
= 26,
1036 BGP_FSM_UpdateMsg
= 27,
1037 BGP_FSM_UpdateMsgErr
= 28
1041 * BGP finite state machine events
1043 * Note: these do not correspond to RFC-defined event codes. Those are
1044 * defined elsewhere.
1046 enum bgp_fsm_events
{
1049 TCP_connection_open
,
1050 TCP_connection_open_w_delay
,
1051 TCP_connection_closed
,
1052 TCP_connection_open_failed
,
1054 ConnectRetry_timer_expired
,
1056 KeepAlive_timer_expired
,
1057 DelayOpen_timer_expired
,
1058 Receive_OPEN_message
,
1059 Receive_KEEPALIVE_message
,
1060 Receive_UPDATE_message
,
1061 Receive_NOTIFICATION_message
,
1066 /* BGP finite state machine status. */
1067 enum bgp_fsm_status
{
1079 #define PEER_HOSTNAME(peer) ((peer)->host ? (peer)->host : "(unknown peer)")
1082 uint32_t stale_time
;
1086 /* BGP neighbor structure. */
1088 /* BGP structure. */
1091 /* reference count, primarily to allow bgp_process'ing of route_node's
1092 * to be done after a struct peer is deleted.
1094 * named 'lock' for hysterical reasons within Quagga.
1098 /* BGP peer group. */
1099 struct peer_group
*group
;
1100 uint64_t version
[AFI_MAX
][SAFI_MAX
];
1102 /* BGP peer_af structures, per configured AF on this peer */
1103 struct peer_af
*peer_af_array
[BGP_AF_MAX
];
1105 /* Peer's remote AS number. */
1109 /* Peer's local AS number. */
1112 enum bgp_peer_sort sort
;
1114 /* Peer's Change local AS number. */
1115 as_t change_local_as
;
1117 /* Remote router ID. */
1118 struct in_addr remote_id
;
1120 /* Local router ID. */
1121 struct in_addr local_id
;
1123 /* Packet receive and send buffer. */
1124 pthread_mutex_t io_mtx
; // guards ibuf, obuf
1125 struct stream_fifo
*ibuf
; // packets waiting to be processed
1126 struct stream_fifo
*obuf
; // packets waiting to be written
1128 /* used as a block to deposit raw wire data to */
1129 uint8_t ibuf_scratch
[BGP_EXTENDED_MESSAGE_MAX_PACKET_SIZE
1130 * BGP_READ_PACKET_MAX
];
1131 struct ringbuf
*ibuf_work
; // WiP buffer used by bgp_read() only
1132 struct stream
*obuf_work
; // WiP buffer used to construct packets
1134 struct stream
*curr
; // the current packet being parsed
1136 /* We use a separate stream to encode MP_REACH_NLRI for efficient
1137 * NLRI packing. peer->obuf_work stores all the other attributes. The
1138 * actual packet is then constructed by concatenating the two.
1140 struct stream
*scratch
;
1142 /* the doppelganger peer structure, due to dual TCP conn setup */
1143 struct peer
*doppelganger
;
1145 /* Status of the peer. */
1146 enum bgp_fsm_status status
;
1147 enum bgp_fsm_status ostatus
;
1149 /* FSM events, stored for debug purposes.
1150 * Note: uchar used for reduced memory usage.
1152 enum bgp_fsm_events cur_event
;
1153 enum bgp_fsm_events last_event
;
1154 enum bgp_fsm_events last_major_event
;
1156 /* Peer index, used for dumping TABLE_DUMP_V2 format */
1157 uint16_t table_dump_index
;
1159 /* Peer information */
1160 int fd
; /* File descriptor */
1161 int ttl
; /* TTL of TCP connection to the peer. */
1162 int rtt
; /* Estimated round-trip-time from TCP_INFO */
1163 int rtt_expected
; /* Expected round-trip-time for a peer */
1164 uint8_t rtt_keepalive_rcv
; /* Received count for RTT shutdown */
1165 uint8_t rtt_keepalive_conf
; /* Configured count for RTT shutdown */
1166 int gtsm_hops
; /* minimum hopcount to peer */
1167 char *desc
; /* Description of the peer. */
1168 unsigned short port
; /* Destination port for peer */
1169 char *host
; /* Printable address of the peer. */
1170 union sockunion su
; /* Sockunion address of the peer. */
1171 #define BGP_PEER_SU_UNSPEC(peer) (peer->su.sa.sa_family == AF_UNSPEC)
1172 time_t uptime
; /* Last Up/Down time */
1173 time_t readtime
; /* Last read time */
1174 time_t resettime
; /* Last reset time */
1176 char *conf_if
; /* neighbor interface config name. */
1177 struct interface
*ifp
; /* corresponding interface */
1178 char *ifname
; /* bind interface name. */
1180 union sockunion
*update_source
;
1182 union sockunion
*su_local
; /* Sockunion of local address. */
1183 union sockunion
*su_remote
; /* Sockunion of remote address. */
1184 int shared_network
; /* Is this peer shared same network. */
1185 struct bgp_nexthop nexthop
; /* Nexthop */
1187 /* Roles in bgp session */
1189 uint8_t remote_role
;
1190 #define ROLE_PROVIDER 0
1191 #define ROLE_RS_SERVER 1
1192 #define ROLE_RS_CLIENT 2
1193 #define ROLE_CUSTOMER 3
1195 #define ROLE_UNDEFINED 255
1197 #define ROLE_NAME_MAX_LEN 20
1199 /* Peer address family configuration. */
1200 uint8_t afc
[AFI_MAX
][SAFI_MAX
];
1201 uint8_t afc_nego
[AFI_MAX
][SAFI_MAX
];
1202 uint8_t afc_adv
[AFI_MAX
][SAFI_MAX
];
1203 uint8_t afc_recv
[AFI_MAX
][SAFI_MAX
];
1205 /* Capability flags (reset in bgp_stop) */
1207 #define PEER_CAP_REFRESH_ADV (1U << 0) /* refresh advertised */
1208 #define PEER_CAP_REFRESH_OLD_RCV (1U << 1) /* refresh old received */
1209 #define PEER_CAP_REFRESH_NEW_RCV (1U << 2) /* refresh rfc received */
1210 #define PEER_CAP_DYNAMIC_ADV (1U << 3) /* dynamic advertised */
1211 #define PEER_CAP_DYNAMIC_RCV (1U << 4) /* dynamic received */
1212 #define PEER_CAP_RESTART_ADV (1U << 5) /* restart advertised */
1213 #define PEER_CAP_RESTART_RCV (1U << 6) /* restart received */
1214 #define PEER_CAP_AS4_ADV (1U << 7) /* as4 advertised */
1215 #define PEER_CAP_AS4_RCV (1U << 8) /* as4 received */
1216 /* sent graceful-restart restart (R) bit */
1217 #define PEER_CAP_GRACEFUL_RESTART_R_BIT_ADV (1U << 9)
1218 /* received graceful-restart restart (R) bit */
1219 #define PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV (1U << 10)
1220 #define PEER_CAP_ADDPATH_ADV (1U << 11) /* addpath advertised */
1221 #define PEER_CAP_ADDPATH_RCV (1U << 12) /* addpath received */
1222 #define PEER_CAP_ENHE_ADV (1U << 13) /* Extended nexthop advertised */
1223 #define PEER_CAP_ENHE_RCV (1U << 14) /* Extended nexthop received */
1224 #define PEER_CAP_HOSTNAME_ADV (1U << 15) /* hostname advertised */
1225 #define PEER_CAP_HOSTNAME_RCV (1U << 16) /* hostname received */
1226 #define PEER_CAP_ENHANCED_RR_ADV (1U << 17) /* enhanced rr advertised */
1227 #define PEER_CAP_ENHANCED_RR_RCV (1U << 18) /* enhanced rr received */
1228 #define PEER_CAP_EXTENDED_MESSAGE_ADV (1U << 19)
1229 #define PEER_CAP_EXTENDED_MESSAGE_RCV (1U << 20)
1230 #define PEER_CAP_LLGR_ADV (1U << 21)
1231 #define PEER_CAP_LLGR_RCV (1U << 22)
1232 /* sent graceful-restart notification (N) bit */
1233 #define PEER_CAP_GRACEFUL_RESTART_N_BIT_ADV (1U << 23)
1234 /* received graceful-restart notification (N) bit */
1235 #define PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV (1U << 24)
1236 #define PEER_CAP_ROLE_ADV (1U << 25) /* role advertised */
1237 #define PEER_CAP_ROLE_RCV (1U << 26) /* role received */
1238 #define PEER_CAP_SOFT_VERSION_ADV (1U << 27)
1239 #define PEER_CAP_SOFT_VERSION_RCV (1U << 28)
1241 /* Capability flags (reset in bgp_stop) */
1242 uint32_t af_cap
[AFI_MAX
][SAFI_MAX
];
1243 #define PEER_CAP_ORF_PREFIX_SM_ADV (1U << 0) /* send-mode advertised */
1244 #define PEER_CAP_ORF_PREFIX_RM_ADV (1U << 1) /* receive-mode advertised */
1245 #define PEER_CAP_ORF_PREFIX_SM_RCV (1U << 2) /* send-mode received */
1246 #define PEER_CAP_ORF_PREFIX_RM_RCV (1U << 3) /* receive-mode received */
1247 #define PEER_CAP_ORF_PREFIX_SM_OLD_RCV (1U << 4) /* send-mode received */
1248 #define PEER_CAP_ORF_PREFIX_RM_OLD_RCV (1U << 5) /* receive-mode received */
1249 #define PEER_CAP_RESTART_AF_RCV (1U << 6) /* graceful restart afi/safi received */
1250 #define PEER_CAP_RESTART_AF_PRESERVE_RCV (1U << 7) /* graceful restart afi/safi F-bit received */
1251 #define PEER_CAP_ADDPATH_AF_TX_ADV (1U << 8) /* addpath tx advertised */
1252 #define PEER_CAP_ADDPATH_AF_TX_RCV (1U << 9) /* addpath tx received */
1253 #define PEER_CAP_ADDPATH_AF_RX_ADV (1U << 10) /* addpath rx advertised */
1254 #define PEER_CAP_ADDPATH_AF_RX_RCV (1U << 11) /* addpath rx received */
1255 #define PEER_CAP_ENHE_AF_ADV (1U << 12) /* Extended nexthopi afi/safi advertised */
1256 #define PEER_CAP_ENHE_AF_RCV (1U << 13) /* Extended nexthop afi/safi received */
1257 #define PEER_CAP_ENHE_AF_NEGO (1U << 14) /* Extended nexthop afi/safi negotiated */
1258 #define PEER_CAP_LLGR_AF_ADV (1U << 15)
1259 #define PEER_CAP_LLGR_AF_RCV (1U << 16)
1261 /* Global configuration flags. */
1263 * Parallel array to flags that indicates whether each flag originates
1264 * from a peer-group or if it is config that is specific to this
1265 * individual peer. If a flag is set independent of the peer-group, the
1266 * same bit should be set here. If this peer is a peer-group, this
1267 * memory region should be all zeros.
1269 * The assumption is that the default state for all flags is unset,
1270 * so if a flag is unset, the corresponding override flag is unset too.
1271 * However if a flag is set, the corresponding override flag is set.
1273 uint64_t flags_override
;
1275 * Parallel array to flags that indicates whether the default behavior
1276 * of *flags_override* should be inverted. If a flag is unset and the
1277 * corresponding invert flag is set, the corresponding override flag
1278 * would be set. However if a flag is set and the corresponding invert
1279 * flag is unset, the corresponding override flag would be unset.
1281 * This can be used for attributes like *send-community*, which are
1282 * implicitely enabled and have to be disabled explicitely, compared to
1283 * 'normal' attributes like *next-hop-self* which are implicitely set.
1285 * All operations dealing with flags should apply the following boolean
1286 * logic to keep the internal flag system in a sane state:
1288 * value=0 invert=0 Inherit flag if member, otherwise unset flag
1289 * value=0 invert=1 Unset flag unconditionally
1290 * value=1 invert=0 Set flag unconditionally
1291 * value=1 invert=1 Inherit flag if member, otherwise set flag
1293 * Contrary to the implementation of *flags_override*, the flag
1294 * inversion state can be set either on the peer OR the peer *and* the
1295 * peer-group. This was done on purpose, as the inversion state of a
1296 * flag can be determined on either the peer or the peer-group.
1298 * Example: Enabling the cisco configuration mode inverts all flags
1299 * related to *send-community* unconditionally for both peer-groups and
1302 * This behavior is different for interface peers though, which enable
1303 * the *extended-nexthop* flag by default, which regular peers do not.
1304 * As the peer-group can contain both regular and interface peers, the
1305 * flag inversion state must be set on the peer only.
1307 * When a peer inherits the configuration from a peer-group and the
1308 * inversion state of the flag differs between peer and peer-group, the
1309 * newly set value must equal to the inverted state of the peer-group.
1311 uint64_t flags_invert
;
1313 * Effective array for storing the peer/peer-group flags. In case of a
1314 * peer-group, the peer-specific overrides (see flags_override and
1315 * flags_invert) must be respected.
1316 * When changing the structure of flags/af_flags, do not forget to
1317 * change flags_invert/flags_override too.
1320 #define PEER_FLAG_PASSIVE (1ULL << 0) /* passive mode */
1321 #define PEER_FLAG_SHUTDOWN (1ULL << 1) /* shutdown */
1322 #define PEER_FLAG_DONT_CAPABILITY (1ULL << 2) /* dont-capability */
1323 #define PEER_FLAG_OVERRIDE_CAPABILITY (1ULL << 3) /* override-capability */
1324 #define PEER_FLAG_STRICT_CAP_MATCH (1ULL << 4) /* strict-match */
1325 #define PEER_FLAG_DYNAMIC_CAPABILITY (1ULL << 5) /* dynamic capability */
1326 #define PEER_FLAG_DISABLE_CONNECTED_CHECK (1ULL << 6) /* disable-connected-check */
1327 #define PEER_FLAG_LOCAL_AS_NO_PREPEND (1ULL << 7) /* local-as no-prepend */
1328 #define PEER_FLAG_LOCAL_AS_REPLACE_AS (1ULL << 8) /* local-as no-prepend replace-as */
1329 #define PEER_FLAG_DELETE (1ULL << 9) /* mark the peer for deleting */
1330 #define PEER_FLAG_CONFIG_NODE (1ULL << 10) /* the node to update configs on */
1331 #define PEER_FLAG_LONESOUL (1ULL << 11)
1332 #define PEER_FLAG_DYNAMIC_NEIGHBOR (1ULL << 12) /* dynamic neighbor */
1333 #define PEER_FLAG_CAPABILITY_ENHE (1ULL << 13) /* Extended next-hop (rfc 5549)*/
1334 #define PEER_FLAG_IFPEER_V6ONLY (1ULL << 14) /* if-based peer is v6 only */
1335 #define PEER_FLAG_IS_RFAPI_HD (1ULL << 15) /* attached to rfapi HD */
1336 #define PEER_FLAG_ENFORCE_FIRST_AS (1ULL << 16) /* enforce-first-as */
1337 #define PEER_FLAG_ROUTEADV (1ULL << 17) /* route advertise */
1338 #define PEER_FLAG_TIMER (1ULL << 18) /* keepalive & holdtime */
1339 #define PEER_FLAG_TIMER_CONNECT (1ULL << 19) /* connect timer */
1340 #define PEER_FLAG_PASSWORD (1ULL << 20) /* password */
1341 #define PEER_FLAG_LOCAL_AS (1ULL << 21) /* local-as */
1342 #define PEER_FLAG_UPDATE_SOURCE (1ULL << 22) /* update-source */
1344 /* BGP-GR Peer related flags */
1345 #define PEER_FLAG_GRACEFUL_RESTART_HELPER (1ULL << 23) /* Helper */
1346 #define PEER_FLAG_GRACEFUL_RESTART (1ULL << 24) /* Graceful Restart */
1347 #define PEER_FLAG_GRACEFUL_RESTART_GLOBAL_INHERIT (1ULL << 25) /* Global-Inherit */
1348 #define PEER_FLAG_RTT_SHUTDOWN (1ULL << 26) /* shutdown rtt */
1349 #define PEER_FLAG_TIMER_DELAYOPEN (1ULL << 27) /* delayopen timer */
1350 #define PEER_FLAG_TCP_MSS (1ULL << 28) /* tcp-mss */
1351 /* Disable IEEE floating-point link bandwidth encoding in
1352 * extended communities.
1354 #define PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE (1ULL << 29)
1355 /* force the extended format for Optional Parameters in OPEN message */
1356 #define PEER_FLAG_EXTENDED_OPT_PARAMS (1ULL << 30)
1358 /* BGP Open Policy flags.
1359 * Enforce using roles on both sides:
1360 * `local-role ROLE strict-mode` configured.
1362 #define PEER_FLAG_ROLE_STRICT_MODE (1ULL << 31)
1363 /* `local-role` configured */
1364 #define PEER_FLAG_ROLE (1ULL << 32)
1365 #define PEER_FLAG_PORT (1ULL << 33)
1366 #define PEER_FLAG_AIGP (1ULL << 34)
1367 #define PEER_FLAG_GRACEFUL_SHUTDOWN (1ULL << 35)
1368 #define PEER_FLAG_CAPABILITY_SOFT_VERSION (1ULL << 36)
1371 *GR-Disabled mode means unset PEER_FLAG_GRACEFUL_RESTART
1372 *& PEER_FLAG_GRACEFUL_RESTART_HELPER
1373 *and PEER_FLAG_GRACEFUL_RESTART_GLOBAL_INHERIT
1376 struct bgp_peer_gr PEER_GR_FSM
[BGP_PEER_GR_MODE
][BGP_PEER_GR_EVENT_CMD
];
1377 enum peer_mode peer_gr_present_state
;
1378 /* Non stop forwarding afi-safi count for BGP gr feature*/
1379 uint8_t nsf_af_count
;
1381 uint8_t peer_gr_new_status_flag
;
1382 #define PEER_GRACEFUL_RESTART_NEW_STATE_HELPER (1U << 0)
1383 #define PEER_GRACEFUL_RESTART_NEW_STATE_RESTART (1U << 1)
1384 #define PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT (1U << 2)
1386 /* outgoing message sent in CEASE_ADMIN_SHUTDOWN notify */
1387 char *tx_shutdown_message
;
1389 /* NSF mode (graceful restart) */
1390 uint8_t nsf
[AFI_MAX
][SAFI_MAX
];
1392 time_t eor_stime
[AFI_MAX
][SAFI_MAX
];
1393 /* Last update packet sent time */
1394 time_t pkt_stime
[AFI_MAX
][SAFI_MAX
];
1396 /* Peer Per AF flags */
1398 * Please consult the comments for *flags_override*, *flags_invert* and
1399 * *flags* to understand what these three arrays do. The address-family
1400 * specific attributes are being treated the exact same way as global
1403 uint64_t af_flags_override
[AFI_MAX
][SAFI_MAX
];
1404 uint64_t af_flags_invert
[AFI_MAX
][SAFI_MAX
];
1405 uint64_t af_flags
[AFI_MAX
][SAFI_MAX
];
1406 #define PEER_FLAG_SEND_COMMUNITY (1ULL << 0)
1407 #define PEER_FLAG_SEND_EXT_COMMUNITY (1ULL << 1)
1408 #define PEER_FLAG_NEXTHOP_SELF (1ULL << 2)
1409 #define PEER_FLAG_REFLECTOR_CLIENT (1ULL << 3)
1410 #define PEER_FLAG_RSERVER_CLIENT (1ULL << 4)
1411 #define PEER_FLAG_SOFT_RECONFIG (1ULL << 5)
1412 #define PEER_FLAG_AS_PATH_UNCHANGED (1ULL << 6)
1413 #define PEER_FLAG_NEXTHOP_UNCHANGED (1ULL << 7)
1414 #define PEER_FLAG_MED_UNCHANGED (1ULL << 8)
1415 #define PEER_FLAG_DEFAULT_ORIGINATE (1ULL << 9)
1416 #define PEER_FLAG_REMOVE_PRIVATE_AS (1ULL << 10)
1417 #define PEER_FLAG_ALLOWAS_IN (1ULL << 11)
1418 #define PEER_FLAG_ORF_PREFIX_SM (1ULL << 12)
1419 #define PEER_FLAG_ORF_PREFIX_RM (1ULL << 13)
1420 #define PEER_FLAG_MAX_PREFIX (1ULL << 14)
1421 #define PEER_FLAG_MAX_PREFIX_WARNING (1ULL << 15)
1422 #define PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED (1ULL << 16)
1423 #define PEER_FLAG_FORCE_NEXTHOP_SELF (1ULL << 17)
1424 #define PEER_FLAG_REMOVE_PRIVATE_AS_ALL (1ULL << 18)
1425 #define PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE (1ULL << 19)
1426 #define PEER_FLAG_AS_OVERRIDE (1ULL << 20)
1427 #define PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE (1ULL << 21)
1428 #define PEER_FLAG_WEIGHT (1ULL << 24)
1429 #define PEER_FLAG_ALLOWAS_IN_ORIGIN (1ULL << 25)
1430 #define PEER_FLAG_SEND_LARGE_COMMUNITY (1ULL << 26)
1431 #define PEER_FLAG_MAX_PREFIX_OUT (1ULL << 27)
1432 #define PEER_FLAG_MAX_PREFIX_FORCE (1ULL << 28)
1433 #define PEER_FLAG_DISABLE_ADDPATH_RX (1ULL << 29)
1434 #define PEER_FLAG_SOO (1ULL << 30)
1435 #define PEER_FLAG_ACCEPT_OWN (1ULL << 31)
1437 enum bgp_addpath_strat addpath_type
[AFI_MAX
][SAFI_MAX
];
1442 /* default-originate route-map. */
1445 struct route_map
*map
;
1446 } default_rmap
[AFI_MAX
][SAFI_MAX
];
1448 /* Peer status flags. */
1450 #define PEER_STATUS_ACCEPT_PEER (1U << 0) /* accept peer */
1451 #define PEER_STATUS_PREFIX_OVERFLOW (1U << 1) /* prefix-overflow */
1452 #define PEER_STATUS_CAPABILITY_OPEN (1U << 2) /* capability open send */
1453 #define PEER_STATUS_HAVE_ACCEPT (1U << 3) /* accept peer's parent */
1454 #define PEER_STATUS_GROUP (1U << 4) /* peer-group conf */
1455 #define PEER_STATUS_NSF_MODE (1U << 5) /* NSF aware peer */
1456 #define PEER_STATUS_NSF_WAIT (1U << 6) /* wait comeback peer */
1457 /* received extended format encoding for OPEN message */
1458 #define PEER_STATUS_EXT_OPT_PARAMS_LENGTH (1U << 7)
1460 /* Peer status af flags (reset in bgp_stop) */
1461 uint16_t af_sflags
[AFI_MAX
][SAFI_MAX
];
1462 #define PEER_STATUS_ORF_PREFIX_SEND (1U << 0) /* prefix-list send peer */
1463 #define PEER_STATUS_ORF_WAIT_REFRESH (1U << 1) /* wait refresh received peer */
1464 #define PEER_STATUS_PREFIX_THRESHOLD (1U << 2) /* exceed prefix-threshold */
1465 #define PEER_STATUS_PREFIX_LIMIT (1U << 3) /* exceed prefix-limit */
1466 #define PEER_STATUS_EOR_SEND (1U << 4) /* end-of-rib send to peer */
1467 #define PEER_STATUS_EOR_RECEIVED (1U << 5) /* end-of-rib received from peer */
1468 #define PEER_STATUS_ENHANCED_REFRESH (1U << 6) /* Enhanced Route Refresh */
1469 #define PEER_STATUS_BORR_SEND (1U << 7) /* BoRR send to peer */
1470 #define PEER_STATUS_BORR_RECEIVED (1U << 8) /* BoRR received from peer */
1471 #define PEER_STATUS_EORR_SEND (1U << 9) /* EoRR send to peer */
1472 #define PEER_STATUS_EORR_RECEIVED (1U << 10) /* EoRR received from peer */
1473 /* LLGR aware peer */
1474 #define PEER_STATUS_LLGR_WAIT (1U << 11)
1475 #define PEER_STATUS_REFRESH_PENDING (1U << 12) /* refresh request from peer */
1476 #define PEER_STATUS_RTT_SHUTDOWN (1U << 13) /* In shutdown state due to RTT */
1478 /* Configured timer values. */
1479 _Atomic
uint32_t holdtime
;
1480 _Atomic
uint32_t keepalive
;
1481 _Atomic
uint32_t connect
;
1482 _Atomic
uint32_t routeadv
;
1483 _Atomic
uint32_t delayopen
;
1486 _Atomic
uint32_t v_start
;
1487 _Atomic
uint32_t v_connect
;
1488 _Atomic
uint32_t v_holdtime
;
1489 _Atomic
uint32_t v_keepalive
;
1490 _Atomic
uint32_t v_routeadv
;
1491 _Atomic
uint32_t v_delayopen
;
1492 _Atomic
uint32_t v_pmax_restart
;
1493 _Atomic
uint32_t v_gr_restart
;
1496 struct thread
*t_read
;
1497 struct thread
*t_write
;
1498 struct thread
*t_start
;
1499 struct thread
*t_connect_check_r
;
1500 struct thread
*t_connect_check_w
;
1501 struct thread
*t_connect
;
1502 struct thread
*t_holdtime
;
1503 struct thread
*t_routeadv
;
1504 struct thread
*t_delayopen
;
1505 struct thread
*t_pmax_restart
;
1506 struct thread
*t_gr_restart
;
1507 struct thread
*t_gr_stale
;
1508 struct thread
*t_llgr_stale
[AFI_MAX
][SAFI_MAX
];
1509 struct thread
*t_revalidate_all
[AFI_MAX
][SAFI_MAX
];
1510 struct thread
*t_generate_updgrp_packets
;
1511 struct thread
*t_process_packet
;
1512 struct thread
*t_process_packet_error
;
1513 struct thread
*t_refresh_stalepath
;
1516 _Atomic
uint32_t thread_flags
;
1517 #define PEER_THREAD_WRITES_ON (1U << 0)
1518 #define PEER_THREAD_READS_ON (1U << 1)
1519 #define PEER_THREAD_KEEPALIVES_ON (1U << 2)
1520 #define PEER_THREAD_SUBGRP_ADV_DELAY (1U << 3)
1523 struct work_queue
*clear_node_queue
;
1525 #define PEER_TOTAL_RX(peer) \
1526 atomic_load_explicit(&peer->open_in, memory_order_relaxed) \
1527 + atomic_load_explicit(&peer->update_in, memory_order_relaxed) \
1528 + atomic_load_explicit(&peer->notify_in, memory_order_relaxed) \
1529 + atomic_load_explicit(&peer->refresh_in, \
1530 memory_order_relaxed) \
1531 + atomic_load_explicit(&peer->keepalive_in, \
1532 memory_order_relaxed) \
1533 + atomic_load_explicit(&peer->dynamic_cap_in, \
1534 memory_order_relaxed)
1536 #define PEER_TOTAL_TX(peer) \
1537 atomic_load_explicit(&peer->open_out, memory_order_relaxed) \
1538 + atomic_load_explicit(&peer->update_out, \
1539 memory_order_relaxed) \
1540 + atomic_load_explicit(&peer->notify_out, \
1541 memory_order_relaxed) \
1542 + atomic_load_explicit(&peer->refresh_out, \
1543 memory_order_relaxed) \
1544 + atomic_load_explicit(&peer->keepalive_out, \
1545 memory_order_relaxed) \
1546 + atomic_load_explicit(&peer->dynamic_cap_out, \
1547 memory_order_relaxed)
1549 /* Statistics field */
1550 _Atomic
uint32_t open_in
; /* Open message input count */
1551 _Atomic
uint32_t open_out
; /* Open message output count */
1552 _Atomic
uint32_t update_in
; /* Update message input count */
1553 _Atomic
uint32_t update_out
; /* Update message ouput count */
1554 _Atomic
time_t update_time
; /* Update message received time. */
1555 _Atomic
uint32_t keepalive_in
; /* Keepalive input count */
1556 _Atomic
uint32_t keepalive_out
; /* Keepalive output count */
1557 _Atomic
uint32_t notify_in
; /* Notify input count */
1558 _Atomic
uint32_t notify_out
; /* Notify output count */
1559 _Atomic
uint32_t refresh_in
; /* Route Refresh input count */
1560 _Atomic
uint32_t refresh_out
; /* Route Refresh output count */
1561 _Atomic
uint32_t dynamic_cap_in
; /* Dynamic Capability input count. */
1562 _Atomic
uint32_t dynamic_cap_out
; /* Dynamic Capability output count. */
1564 uint32_t stat_pfx_filter
;
1565 uint32_t stat_pfx_aspath_loop
;
1566 uint32_t stat_pfx_originator_loop
;
1567 uint32_t stat_pfx_cluster_loop
;
1568 uint32_t stat_pfx_nh_invalid
;
1569 uint32_t stat_pfx_dup_withdraw
;
1570 uint32_t stat_upd_7606
; /* RFC7606: treat-as-withdraw */
1572 /* BGP state count */
1573 uint32_t established
; /* Established */
1574 uint32_t dropped
; /* Dropped */
1576 /* Update delay related fields */
1577 uint8_t update_delay_over
; /* When this is set, BGP is no more waiting
1580 /* Syncronization list and time. */
1581 struct bgp_synchronize
*sync
[AFI_MAX
][SAFI_MAX
];
1583 /* timestamp when the last UPDATE msg was written */
1584 _Atomic
time_t last_write
;
1585 /* timestamp when the last msg was written */
1586 _Atomic
time_t last_update
;
1588 /* only updated under io_mtx.
1589 * last_sendq_warn is only for ratelimiting log warning messages.
1591 time_t last_sendq_ok
, last_sendq_warn
;
1594 struct bgp_notify notify
;
1596 /* Filter structure. */
1597 struct bgp_filter filter
[AFI_MAX
][SAFI_MAX
];
1600 * Parallel array to filter that indicates whether each filter
1601 * originates from a peer-group or if it is config that is specific to
1602 * this individual peer. If a filter is set independent of the
1603 * peer-group the appropriate bit should be set here. If this peer is a
1604 * peer-group, this memory region should be all zeros. The assumption
1605 * is that the default state for all flags is unset. Due to filters
1606 * having a direction (e.g. in/out/...), this array has a third
1607 * dimension for storing the overrides independently per direction.
1610 * - if a filter for an individual peer is unset, the corresponding
1611 * override flag is unset and the peer is considered to be back in
1612 * sync with the peer-group.
1613 * - This does *not* contain the filter values, rather it contains
1614 * whether the filter in filter (struct bgp_filter) is peer-specific.
1616 uint8_t filter_override
[AFI_MAX
][SAFI_MAX
][FILTER_MAX
];
1617 #define PEER_FT_DISTRIBUTE_LIST (1U << 0) /* distribute-list */
1618 #define PEER_FT_FILTER_LIST (1U << 1) /* filter-list */
1619 #define PEER_FT_PREFIX_LIST (1U << 2) /* prefix-list */
1620 #define PEER_FT_ROUTE_MAP (1U << 3) /* route-map */
1621 #define PEER_FT_UNSUPPRESS_MAP (1U << 4) /* unsuppress-map */
1622 #define PEER_FT_ADVERTISE_MAP (1U << 5) /* advertise-map */
1624 /* ORF Prefix-list */
1625 struct prefix_list
*orf_plist
[AFI_MAX
][SAFI_MAX
];
1627 /* Text description of last attribute rcvd */
1628 char rcvd_attr_str
[BUFSIZ
];
1630 /* Track if we printed the attribute in debugs */
1631 int rcvd_attr_printed
;
1633 /* Accepted prefix count */
1634 uint32_t pcount
[AFI_MAX
][SAFI_MAX
];
1636 /* Max prefix count. */
1637 uint32_t pmax
[AFI_MAX
][SAFI_MAX
];
1638 uint8_t pmax_threshold
[AFI_MAX
][SAFI_MAX
];
1639 uint16_t pmax_restart
[AFI_MAX
][SAFI_MAX
];
1640 #define MAXIMUM_PREFIX_THRESHOLD_DEFAULT 75
1642 /* Send prefix count. */
1643 uint32_t pmax_out
[AFI_MAX
][SAFI_MAX
];
1646 char allowas_in
[AFI_MAX
][SAFI_MAX
];
1649 struct ecommunity
*soo
[AFI_MAX
][SAFI_MAX
];
1652 unsigned long weight
[AFI_MAX
][SAFI_MAX
];
1654 /* peer reset cause */
1656 #define PEER_DOWN_RID_CHANGE 1U /* bgp router-id command */
1657 #define PEER_DOWN_REMOTE_AS_CHANGE 2U /* neighbor remote-as command */
1658 #define PEER_DOWN_LOCAL_AS_CHANGE 3U /* neighbor local-as command */
1659 #define PEER_DOWN_CLID_CHANGE 4U /* bgp cluster-id command */
1660 #define PEER_DOWN_CONFED_ID_CHANGE 5U /* bgp confederation id command */
1661 #define PEER_DOWN_CONFED_PEER_CHANGE 6U /* bgp confederation peer command */
1662 #define PEER_DOWN_RR_CLIENT_CHANGE 7U /* neighbor rr-client command */
1663 #define PEER_DOWN_RS_CLIENT_CHANGE 8U /* neighbor rs-client command */
1664 #define PEER_DOWN_UPDATE_SOURCE_CHANGE 9U /* neighbor update-source command */
1665 #define PEER_DOWN_AF_ACTIVATE 10U /* neighbor activate command */
1666 #define PEER_DOWN_USER_SHUTDOWN 11U /* neighbor shutdown command */
1667 #define PEER_DOWN_USER_RESET 12U /* clear ip bgp command */
1668 #define PEER_DOWN_NOTIFY_RECEIVED 13U /* notification received */
1669 #define PEER_DOWN_NOTIFY_SEND 14U /* notification send */
1670 #define PEER_DOWN_CLOSE_SESSION 15U /* tcp session close */
1671 #define PEER_DOWN_NEIGHBOR_DELETE 16U /* neghbor delete */
1672 #define PEER_DOWN_RMAP_BIND 17U /* neghbor peer-group command */
1673 #define PEER_DOWN_RMAP_UNBIND 18U /* no neighbor peer-group command */
1674 #define PEER_DOWN_CAPABILITY_CHANGE 19U /* neighbor capability command */
1675 #define PEER_DOWN_PASSIVE_CHANGE 20U /* neighbor passive command */
1676 #define PEER_DOWN_MULTIHOP_CHANGE 21U /* neighbor multihop command */
1677 #define PEER_DOWN_NSF_CLOSE_SESSION 22U /* NSF tcp session close */
1678 #define PEER_DOWN_V6ONLY_CHANGE 23U /* if-based peering v6only toggled */
1679 #define PEER_DOWN_BFD_DOWN 24U /* BFD down */
1680 #define PEER_DOWN_IF_DOWN 25U /* Interface down */
1681 #define PEER_DOWN_NBR_ADDR_DEL 26U /* Peer address lost */
1682 #define PEER_DOWN_WAITING_NHT 27U /* Waiting for NHT to resolve */
1683 #define PEER_DOWN_NBR_ADDR 28U /* Waiting for peer IPv6 IP Addr */
1684 #define PEER_DOWN_VRF_UNINIT 29U /* Associated VRF is not init yet */
1685 #define PEER_DOWN_NOAFI_ACTIVATED 30U /* No AFI/SAFI activated for peer */
1686 #define PEER_DOWN_AS_SETS_REJECT 31U /* Reject routes with AS_SET */
1687 #define PEER_DOWN_WAITING_OPEN 32U /* Waiting for open to succeed */
1688 #define PEER_DOWN_PFX_COUNT 33U /* Reached received prefix count */
1689 #define PEER_DOWN_SOCKET_ERROR 34U /* Some socket error happened */
1690 #define PEER_DOWN_RTT_SHUTDOWN 35U /* Automatically shutdown due to RTT */
1692 * Remember to update peer_down_str in bgp_fsm.c when you add
1693 * a new value to the last_reset reason
1696 uint16_t last_reset_cause_size
;
1697 uint8_t last_reset_cause
[BGP_MAX_PACKET_SIZE
];
1699 /* The kind of route-map Flags.*/
1701 #define PEER_RMAP_TYPE_IN (1U << 0) /* neighbor route-map in */
1702 #define PEER_RMAP_TYPE_OUT (1U << 1) /* neighbor route-map out */
1703 #define PEER_RMAP_TYPE_NETWORK (1U << 2) /* network route-map */
1704 #define PEER_RMAP_TYPE_REDISTRIBUTE (1U << 3) /* redistribute route-map */
1705 #define PEER_RMAP_TYPE_DEFAULT (1U << 4) /* default-originate route-map */
1706 #define PEER_RMAP_TYPE_NOSET (1U << 5) /* not allow to set commands */
1707 #define PEER_RMAP_TYPE_IMPORT (1U << 6) /* neighbor route-map import */
1708 #define PEER_RMAP_TYPE_EXPORT (1U << 7) /* neighbor route-map export */
1709 #define PEER_RMAP_TYPE_AGGREGATE (1U << 8) /* aggregate-address route-map */
1711 /** Peer overwrite configuration. */
1712 struct bfd_session_config
{
1714 * Manual configuration bit.
1716 * This flag only makes sense for real peers (and not groups),
1717 * it keeps track if the user explicitly configured BFD for a
1721 /** Control Plane Independent. */
1723 /** Detection multiplier. */
1724 uint8_t detection_multiplier
;
1725 /** Minimum required RX interval. */
1727 /** Minimum required TX interval. */
1729 /** Profile name. */
1730 char profile
[BFD_PROFILE_NAME_LEN
];
1731 /** Peer BFD session */
1732 struct bfd_session_params
*session
;
1735 /* hostname and domainname advertised by host */
1739 /* Sender side AS path loop detection. */
1740 bool as_path_loop_detection
;
1742 /* Extended Message Support */
1743 uint16_t max_packet_size
;
1745 /* Conditional advertisement */
1746 bool advmap_config_change
[AFI_MAX
][SAFI_MAX
];
1747 bool advmap_table_change
;
1749 /* set TCP max segment size */
1752 /* Long-lived Graceful Restart */
1753 struct llgr_info llgr
[AFI_MAX
][SAFI_MAX
];
1755 bool shut_during_cfg
;
1757 #define BGP_ATTR_MAX 255
1758 /* Path attributes discard */
1759 bool discard_attrs
[BGP_ATTR_MAX
];
1761 /* Path attributes treat-as-withdraw */
1762 bool withdraw_attrs
[BGP_ATTR_MAX
];
1764 /* BGP Software Version Capability */
1765 #define BGP_MAX_SOFT_VERSION 64
1770 DECLARE_QOBJ_TYPE(peer
);
1772 /* Inherit peer attribute from peer-group. */
1773 #define PEER_ATTR_INHERIT(peer, group, attr) \
1774 ((peer)->attr = (group)->conf->attr)
1775 #define PEER_STR_ATTR_INHERIT(peer, group, attr, mt) \
1777 XFREE(mt, (peer)->attr); \
1778 if ((group)->conf->attr) \
1779 (peer)->attr = XSTRDUP(mt, (group)->conf->attr); \
1781 (peer)->attr = NULL; \
1783 #define PEER_SU_ATTR_INHERIT(peer, group, attr) \
1786 sockunion_free((peer)->attr); \
1787 if ((group)->conf->attr) \
1788 (peer)->attr = sockunion_dup((group)->conf->attr); \
1790 (peer)->attr = NULL; \
1793 /* Check if suppress start/restart of sessions to peer. */
1794 #define BGP_PEER_START_SUPPRESSED(P) \
1795 (CHECK_FLAG((P)->flags, PEER_FLAG_SHUTDOWN) || \
1796 CHECK_FLAG((P)->sflags, PEER_STATUS_PREFIX_OVERFLOW) || \
1797 CHECK_FLAG((P)->bgp->flags, BGP_FLAG_SHUTDOWN) || \
1798 (P)->shut_during_cfg)
1800 #define PEER_ROUTE_ADV_DELAY(peer) \
1801 (CHECK_FLAG(peer->thread_flags, PEER_THREAD_SUBGRP_ADV_DELAY))
1803 #define PEER_PASSWORD_MINLEN (1)
1804 #define PEER_PASSWORD_MAXLEN (80)
1806 /* This structure's member directly points incoming packet data
1810 uint16_t afi
; /* iana_afi_t */
1813 uint8_t safi
; /* iana_safi_t */
1815 /* Pointer to NLRI byte stream. */
1818 /* Length of whole NLRI. */
1823 #define BGP_VERSION_4 4
1825 /* Default BGP port number. */
1826 #define BGP_PORT_DEFAULT 179
1828 /* Extended BGP Administrative Shutdown Communication */
1829 #define BGP_ADMIN_SHUTDOWN_MSG_LEN 255
1831 /* BGP minimum message size. */
1832 #define BGP_MSG_OPEN_MIN_SIZE (BGP_HEADER_SIZE + 10)
1833 #define BGP_MSG_UPDATE_MIN_SIZE (BGP_HEADER_SIZE + 4)
1834 #define BGP_MSG_NOTIFY_MIN_SIZE (BGP_HEADER_SIZE + 2)
1835 #define BGP_MSG_KEEPALIVE_MIN_SIZE (BGP_HEADER_SIZE + 0)
1836 #define BGP_MSG_ROUTE_REFRESH_MIN_SIZE (BGP_HEADER_SIZE + 4)
1837 #define BGP_MSG_CAPABILITY_MIN_SIZE (BGP_HEADER_SIZE + 3)
1839 /* BGP message types. */
1840 #define BGP_MSG_OPEN 1
1841 #define BGP_MSG_UPDATE 2
1842 #define BGP_MSG_NOTIFY 3
1843 #define BGP_MSG_KEEPALIVE 4
1844 #define BGP_MSG_ROUTE_REFRESH_NEW 5
1845 #define BGP_MSG_CAPABILITY 6
1846 #define BGP_MSG_ROUTE_REFRESH_OLD 128
1848 /* BGP open optional parameter. */
1849 #define BGP_OPEN_OPT_CAP 2
1851 /* BGP4 attribute type codes. */
1852 #define BGP_ATTR_ORIGIN 1
1853 #define BGP_ATTR_AS_PATH 2
1854 #define BGP_ATTR_NEXT_HOP 3
1855 #define BGP_ATTR_MULTI_EXIT_DISC 4
1856 #define BGP_ATTR_LOCAL_PREF 5
1857 #define BGP_ATTR_ATOMIC_AGGREGATE 6
1858 #define BGP_ATTR_AGGREGATOR 7
1859 #define BGP_ATTR_COMMUNITIES 8
1860 #define BGP_ATTR_ORIGINATOR_ID 9
1861 #define BGP_ATTR_CLUSTER_LIST 10
1862 #define BGP_ATTR_MP_REACH_NLRI 14
1863 #define BGP_ATTR_MP_UNREACH_NLRI 15
1864 #define BGP_ATTR_EXT_COMMUNITIES 16
1865 #define BGP_ATTR_AS4_PATH 17
1866 #define BGP_ATTR_AS4_AGGREGATOR 18
1867 #define BGP_ATTR_PMSI_TUNNEL 22
1868 #define BGP_ATTR_ENCAP 23
1869 #define BGP_ATTR_IPV6_EXT_COMMUNITIES 25
1870 #define BGP_ATTR_AIGP 26
1871 #define BGP_ATTR_LARGE_COMMUNITIES 32
1872 #define BGP_ATTR_OTC 35
1873 #define BGP_ATTR_PREFIX_SID 40
1874 #define BGP_ATTR_SRTE_COLOR 51
1875 #ifdef ENABLE_BGP_VNC_ATTR
1876 #define BGP_ATTR_VNC 255
1879 /* BGP update origin. */
1880 #define BGP_ORIGIN_IGP 0
1881 #define BGP_ORIGIN_EGP 1
1882 #define BGP_ORIGIN_INCOMPLETE 2
1883 #define BGP_ORIGIN_UNSPECIFIED 255
1885 /* BGP notify message codes. */
1886 #define BGP_NOTIFY_HEADER_ERR 1
1887 #define BGP_NOTIFY_OPEN_ERR 2
1888 #define BGP_NOTIFY_UPDATE_ERR 3
1889 #define BGP_NOTIFY_HOLD_ERR 4
1890 #define BGP_NOTIFY_FSM_ERR 5
1891 #define BGP_NOTIFY_CEASE 6
1892 #define BGP_NOTIFY_ROUTE_REFRESH_ERR 7
1894 /* Subcodes for BGP Finite State Machine Error */
1895 #define BGP_NOTIFY_FSM_ERR_SUBCODE_UNSPECIFIC 0
1896 #define BGP_NOTIFY_FSM_ERR_SUBCODE_OPENSENT 1
1897 #define BGP_NOTIFY_FSM_ERR_SUBCODE_OPENCONFIRM 2
1898 #define BGP_NOTIFY_FSM_ERR_SUBCODE_ESTABLISHED 3
1900 #define BGP_NOTIFY_SUBCODE_UNSPECIFIC 0
1902 /* BGP_NOTIFY_HEADER_ERR sub codes. */
1903 #define BGP_NOTIFY_HEADER_NOT_SYNC 1
1904 #define BGP_NOTIFY_HEADER_BAD_MESLEN 2
1905 #define BGP_NOTIFY_HEADER_BAD_MESTYPE 3
1907 /* BGP_NOTIFY_OPEN_ERR sub codes. */
1908 #define BGP_NOTIFY_OPEN_MALFORMED_ATTR 0
1909 #define BGP_NOTIFY_OPEN_UNSUP_VERSION 1
1910 #define BGP_NOTIFY_OPEN_BAD_PEER_AS 2
1911 #define BGP_NOTIFY_OPEN_BAD_BGP_IDENT 3
1912 #define BGP_NOTIFY_OPEN_UNSUP_PARAM 4
1913 #define BGP_NOTIFY_OPEN_UNACEP_HOLDTIME 6
1914 #define BGP_NOTIFY_OPEN_UNSUP_CAPBL 7
1915 #define BGP_NOTIFY_OPEN_ROLE_MISMATCH 11
1917 /* BGP_NOTIFY_UPDATE_ERR sub codes. */
1918 #define BGP_NOTIFY_UPDATE_MAL_ATTR 1
1919 #define BGP_NOTIFY_UPDATE_UNREC_ATTR 2
1920 #define BGP_NOTIFY_UPDATE_MISS_ATTR 3
1921 #define BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR 4
1922 #define BGP_NOTIFY_UPDATE_ATTR_LENG_ERR 5
1923 #define BGP_NOTIFY_UPDATE_INVAL_ORIGIN 6
1924 #define BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP 8
1925 #define BGP_NOTIFY_UPDATE_OPT_ATTR_ERR 9
1926 #define BGP_NOTIFY_UPDATE_INVAL_NETWORK 10
1927 #define BGP_NOTIFY_UPDATE_MAL_AS_PATH 11
1929 /* BGP_NOTIFY_CEASE sub codes (RFC 4486). */
1930 #define BGP_NOTIFY_CEASE_MAX_PREFIX 1
1931 #define BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN 2
1932 #define BGP_NOTIFY_CEASE_PEER_UNCONFIG 3
1933 #define BGP_NOTIFY_CEASE_ADMIN_RESET 4
1934 #define BGP_NOTIFY_CEASE_CONNECT_REJECT 5
1935 #define BGP_NOTIFY_CEASE_CONFIG_CHANGE 6
1936 #define BGP_NOTIFY_CEASE_COLLISION_RESOLUTION 7
1937 #define BGP_NOTIFY_CEASE_OUT_OF_RESOURCE 8
1938 #define BGP_NOTIFY_CEASE_HARD_RESET 9
1939 #define BGP_NOTIFY_CEASE_BFD_DOWN 10
1941 /* BGP_NOTIFY_ROUTE_REFRESH_ERR sub codes (RFC 7313). */
1942 #define BGP_NOTIFY_ROUTE_REFRESH_INVALID_MSG_LEN 1
1944 /* BGP route refresh optional subtypes. */
1945 #define BGP_ROUTE_REFRESH_NORMAL 0
1946 #define BGP_ROUTE_REFRESH_BORR 1
1947 #define BGP_ROUTE_REFRESH_EORR 2
1949 /* BGP timers default value. */
1950 #define BGP_INIT_START_TIMER 1
1951 /* The following 3 are RFC defaults that are overridden in bgp_vty.c with
1952 * version-/profile-specific values. The values here do not matter, they only
1953 * exist to provide a clear layering separation between core and CLI.
1955 #define BGP_DEFAULT_HOLDTIME 180
1956 #define BGP_DEFAULT_KEEPALIVE 60
1957 #define BGP_DEFAULT_CONNECT_RETRY 120
1959 #define BGP_DEFAULT_EBGP_ROUTEADV 0
1960 #define BGP_DEFAULT_IBGP_ROUTEADV 0
1962 /* BGP RFC 4271 DelayOpenTime default value */
1963 #define BGP_DEFAULT_DELAYOPEN 120
1965 /* BGP default local preference. */
1966 #define BGP_DEFAULT_LOCAL_PREF 100
1968 /* BGP local-preference to send when 'bgp graceful-shutdown'
1970 #define BGP_GSHUT_LOCAL_PREF 0
1972 /* BGP default subgroup packet queue max . */
1973 #define BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX 40
1975 /* BGP graceful restart */
1976 #define BGP_DEFAULT_RESTART_TIME 120
1977 #define BGP_DEFAULT_STALEPATH_TIME 360
1978 #define BGP_DEFAULT_SELECT_DEFERRAL_TIME 360
1979 #define BGP_DEFAULT_RIB_STALE_TIME 500
1980 #define BGP_DEFAULT_UPDATE_ADVERTISEMENT_TIME 1
1982 /* BGP Long-lived Graceful Restart */
1983 #define BGP_DEFAULT_LLGR_STALE_TIME 0
1985 /* BGP uptime string length. */
1986 #define BGP_UPTIME_LEN 25
1988 /* Default configuration settings for bgpd. */
1989 #define BGP_VTY_PORT 2605
1990 #define BGP_DEFAULT_CONFIG "bgpd.conf"
1992 /* BGP Dynamic Neighbors feature */
1993 #define BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT 100
1994 #define BGP_DYNAMIC_NEIGHBORS_LIMIT_MIN 1
1995 #define BGP_DYNAMIC_NEIGHBORS_LIMIT_MAX 65535
1998 #define BGP_AIGP_TLV_RESERVED 0 /* AIGP Reserved */
1999 #define BGP_AIGP_TLV_METRIC 1 /* AIGP Metric */
2000 #define BGP_AIGP_TLV_METRIC_LEN 11
2001 #define BGP_AIGP_TLV_METRIC_MAX 0xffffffffffffffffULL
2002 #define BGP_AIGP_TLV_METRIC_DESC "Accumulated IGP Metric"
2004 /* Flag for peer_clear_soft(). */
2005 enum bgp_clear_type
{
2006 BGP_CLEAR_SOFT_NONE
,
2009 BGP_CLEAR_SOFT_BOTH
,
2010 BGP_CLEAR_SOFT_IN_ORF_PREFIX
,
2011 BGP_CLEAR_MESSAGE_STATS
2015 #define BGP_INPUT(P) ((P)->curr)
2016 #define BGP_INPUT_PNT(P) (stream_pnt(BGP_INPUT(P)))
2017 #define BGP_IS_VALID_STATE_FOR_NOTIF(S) \
2018 (((S) == OpenSent) || ((S) == OpenConfirm) || ((S) == Established))
2020 /* BGP error codes. */
2021 enum bgp_create_error_code
{
2024 BGP_ERR_INVALID_VALUE
= -1,
2025 BGP_ERR_INVALID_FLAG
= -2,
2026 BGP_ERR_INVALID_AS
= -3,
2027 BGP_ERR_PEER_GROUP_MEMBER
= -4,
2028 BGP_ERR_PEER_GROUP_NO_REMOTE_AS
= -5,
2029 BGP_ERR_PEER_GROUP_CANT_CHANGE
= -6,
2030 BGP_ERR_PEER_GROUP_MISMATCH
= -7,
2031 BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT
= -8,
2032 BGP_ERR_AS_MISMATCH
= -9,
2033 BGP_ERR_PEER_FLAG_CONFLICT
= -10,
2034 BGP_ERR_PEER_GROUP_SHUTDOWN
= -11,
2035 BGP_ERR_PEER_FILTER_CONFLICT
= -12,
2036 BGP_ERR_NOT_INTERNAL_PEER
= -13,
2037 BGP_ERR_REMOVE_PRIVATE_AS
= -14,
2038 BGP_ERR_AF_UNCONFIGURED
= -15,
2039 BGP_ERR_SOFT_RECONFIG_UNCONFIGURED
= -16,
2040 BGP_ERR_INSTANCE_MISMATCH
= -17,
2041 BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS
= -19,
2042 BGP_ERR_TCPSIG_FAILED
= -20,
2043 BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK
= -21,
2044 BGP_ERR_NO_IBGP_WITH_TTLHACK
= -22,
2045 BGP_ERR_NO_INTERFACE_CONFIG
= -23,
2046 BGP_ERR_AS_OVERRIDE
= -25,
2047 BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT
= -26,
2048 BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS
= -27,
2049 BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND
= -28,
2050 BGP_ERR_INVALID_FOR_DYNAMIC_PEER
= -29,
2051 BGP_ERR_INVALID_FOR_DIRECT_PEER
= -30,
2052 BGP_ERR_PEER_SAFI_CONFLICT
= -31,
2055 BGP_ERR_GR_INVALID_CMD
= -32,
2056 BGP_ERR_GR_OPERATION_FAILED
= -33,
2057 BGP_GR_NO_OPERATION
= -34,
2059 /*BGP Open Policy ERRORS */
2060 BGP_ERR_INVALID_ROLE_NAME
= -35,
2061 BGP_ERR_INVALID_INTERNAL_ROLE
= -36
2065 * Enumeration of different policy kinds a peer can be configured with.
2067 enum bgp_policy_type
{
2068 BGP_POLICY_ROUTE_MAP
,
2069 BGP_POLICY_FILTER_LIST
,
2070 BGP_POLICY_PREFIX_LIST
,
2071 BGP_POLICY_DISTRIBUTE_LIST
,
2074 /* peer_flag_change_type. */
2075 enum peer_change_type
{
2078 peer_change_reset_in
,
2079 peer_change_reset_out
,
2082 extern struct bgp_master
*bm
;
2083 extern unsigned int multipath_num
;
2086 extern void bgp_terminate(void);
2087 extern void bgp_reset(void);
2088 extern void bgp_zclient_reset(void);
2089 extern struct bgp
*bgp_get_default(void);
2090 extern struct bgp
*bgp_lookup(as_t
, const char *);
2091 extern struct bgp
*bgp_lookup_by_name(const char *);
2092 extern struct bgp
*bgp_lookup_by_vrf_id(vrf_id_t
);
2093 extern struct bgp
*bgp_get_evpn(void);
2094 extern void bgp_set_evpn(struct bgp
*bgp
);
2095 extern struct peer
*peer_lookup(struct bgp
*, union sockunion
*);
2096 extern struct peer
*peer_lookup_by_conf_if(struct bgp
*, const char *);
2097 extern struct peer
*peer_lookup_by_hostname(struct bgp
*, const char *);
2098 extern void bgp_peer_conf_if_to_su_update(struct peer
*);
2099 extern int peer_group_listen_range_del(struct peer_group
*, struct prefix
*);
2100 extern struct peer_group
*peer_group_lookup(struct bgp
*, const char *);
2101 extern struct peer_group
*peer_group_get(struct bgp
*, const char *);
2102 extern struct peer
*peer_create_bind_dynamic_neighbor(struct bgp
*,
2104 struct peer_group
*);
2105 extern struct prefix
*
2106 peer_group_lookup_dynamic_neighbor_range(struct peer_group
*, struct prefix
*);
2107 extern struct peer_group
*peer_group_lookup_dynamic_neighbor(struct bgp
*,
2110 extern struct peer
*peer_lookup_dynamic_neighbor(struct bgp
*,
2114 * Peers are incredibly easy to memory leak
2115 * due to the various ways that they are actually used
2116 * Provide some functionality to debug locks and unlocks
2118 extern struct peer
*peer_lock_with_caller(const char *, struct peer
*);
2119 extern struct peer
*peer_unlock_with_caller(const char *, struct peer
*);
2120 #define peer_unlock(A) peer_unlock_with_caller(__FUNCTION__, (A))
2121 #define peer_lock(B) peer_lock_with_caller(__FUNCTION__, (B))
2123 extern enum bgp_peer_sort
peer_sort(struct peer
*peer
);
2124 extern enum bgp_peer_sort
peer_sort_lookup(struct peer
*peer
);
2126 extern bool peer_active(struct peer
*);
2127 extern bool peer_active_nego(struct peer
*);
2128 extern bool peer_afc_received(struct peer
*peer
);
2129 extern bool peer_afc_advertised(struct peer
*peer
);
2130 extern void bgp_recalculate_all_bestpaths(struct bgp
*bgp
);
2131 extern struct peer
*peer_create(union sockunion
*su
, const char *conf_if
,
2132 struct bgp
*bgp
, as_t local_as
, as_t remote_as
,
2133 int as_type
, struct peer_group
*group
,
2135 extern struct peer
*peer_create_accept(struct bgp
*);
2136 extern void peer_xfer_config(struct peer
*dst
, struct peer
*src
);
2137 extern char *peer_uptime(time_t uptime2
, char *buf
, size_t len
, bool use_json
,
2140 extern int bgp_config_write(struct vty
*);
2142 extern void bgp_master_init(struct thread_master
*master
, const int buffer_size
,
2143 struct list
*addresses
);
2145 extern void bgp_init(unsigned short instance
);
2146 extern void bgp_pthreads_run(void);
2147 extern void bgp_pthreads_finish(void);
2148 extern void bgp_route_map_init(void);
2149 extern void bgp_session_reset(struct peer
*);
2151 extern int bgp_option_set(int);
2152 extern int bgp_option_unset(int);
2153 extern int bgp_option_check(int);
2155 /* set the bgp no-rib option during runtime and remove installed routes */
2156 extern void bgp_option_norib_set_runtime(void);
2158 /* unset the bgp no-rib option during runtime and reset all peers */
2159 extern void bgp_option_norib_unset_runtime(void);
2161 extern int bgp_get(struct bgp
**, as_t
*, const char *, enum bgp_instance_type
);
2162 extern void bgp_instance_up(struct bgp
*);
2163 extern void bgp_instance_down(struct bgp
*);
2164 extern int bgp_delete(struct bgp
*);
2166 extern int bgp_handle_socket(struct bgp
*bgp
, struct vrf
*vrf
,
2167 vrf_id_t old_vrf_id
, bool create
);
2169 extern void bgp_router_id_zebra_bump(vrf_id_t
, const struct prefix
*);
2170 extern void bgp_router_id_static_set(struct bgp
*, struct in_addr
);
2172 extern void bm_wait_for_fib_set(bool set
);
2173 extern void bgp_suppress_fib_pending_set(struct bgp
*bgp
, bool set
);
2174 extern void bgp_cluster_id_set(struct bgp
*bgp
, struct in_addr
*cluster_id
);
2175 extern void bgp_cluster_id_unset(struct bgp
*bgp
);
2177 extern void bgp_confederation_id_set(struct bgp
*bgp
, as_t as
);
2178 extern void bgp_confederation_id_unset(struct bgp
*bgp
);
2179 extern bool bgp_confederation_peers_check(struct bgp
*, as_t
);
2181 extern void bgp_confederation_peers_add(struct bgp
*bgp
, as_t as
);
2182 extern void bgp_confederation_peers_remove(struct bgp
*bgp
, as_t as
);
2184 extern void bgp_timers_set(struct bgp
*, uint32_t keepalive
, uint32_t holdtime
,
2185 uint32_t connect_retry
, uint32_t delayopen
);
2186 extern void bgp_timers_unset(struct bgp
*);
2188 extern void bgp_default_local_preference_set(struct bgp
*bgp
,
2189 uint32_t local_pref
);
2190 extern void bgp_default_local_preference_unset(struct bgp
*bgp
);
2192 extern void bgp_default_subgroup_pkt_queue_max_set(struct bgp
*bgp
,
2193 uint32_t queue_size
);
2194 extern void bgp_default_subgroup_pkt_queue_max_unset(struct bgp
*bgp
);
2196 extern void bgp_listen_limit_set(struct bgp
*bgp
, int listen_limit
);
2197 extern void bgp_listen_limit_unset(struct bgp
*bgp
);
2199 extern bool bgp_update_delay_active(struct bgp
*);
2200 extern bool bgp_update_delay_configured(struct bgp
*);
2201 extern bool bgp_afi_safi_peer_exists(struct bgp
*bgp
, afi_t afi
, safi_t safi
);
2202 extern void peer_as_change(struct peer
*, as_t
, int);
2203 extern int peer_remote_as(struct bgp
*, union sockunion
*, const char *, as_t
*,
2205 extern int peer_group_remote_as(struct bgp
*, const char *, as_t
*, int);
2206 extern int peer_delete(struct peer
*peer
);
2207 extern void peer_notify_unconfig(struct peer
*peer
);
2208 extern int peer_group_delete(struct peer_group
*);
2209 extern int peer_group_remote_as_delete(struct peer_group
*);
2210 extern int peer_group_listen_range_add(struct peer_group
*, struct prefix
*);
2211 extern void peer_group_notify_unconfig(struct peer_group
*group
);
2213 extern int peer_activate(struct peer
*, afi_t
, safi_t
);
2214 extern int peer_deactivate(struct peer
*, afi_t
, safi_t
);
2216 extern int peer_group_bind(struct bgp
*, union sockunion
*, struct peer
*,
2217 struct peer_group
*, as_t
*);
2219 extern int peer_flag_set(struct peer
*peer
, uint64_t flag
);
2220 extern int peer_flag_unset(struct peer
*peer
, uint64_t flag
);
2221 extern void peer_flag_inherit(struct peer
*peer
, uint64_t flag
);
2223 extern int peer_af_flag_set(struct peer
*peer
, afi_t afi
, safi_t safi
,
2225 extern int peer_af_flag_unset(struct peer
*peer
, afi_t afi
, safi_t safi
,
2227 extern int peer_af_flag_check(struct peer
*, afi_t
, safi_t
, uint32_t);
2228 extern void peer_af_flag_inherit(struct peer
*peer
, afi_t afi
, safi_t safi
,
2230 extern void peer_change_action(struct peer
*peer
, afi_t afi
, safi_t safi
,
2231 enum peer_change_type type
);
2233 extern int peer_ebgp_multihop_set(struct peer
*, int);
2234 extern int peer_ebgp_multihop_unset(struct peer
*);
2235 extern int is_ebgp_multihop_configured(struct peer
*peer
);
2237 extern int peer_role_set(struct peer
*peer
, uint8_t role
, bool strict_mode
);
2238 extern int peer_role_unset(struct peer
*peer
);
2240 extern void peer_description_set(struct peer
*, const char *);
2241 extern void peer_description_unset(struct peer
*);
2243 extern int peer_update_source_if_set(struct peer
*, const char *);
2244 extern void peer_update_source_addr_set(struct peer
*peer
,
2245 const union sockunion
*su
);
2246 extern void peer_update_source_unset(struct peer
*peer
);
2248 extern int peer_default_originate_set(struct peer
*peer
, afi_t afi
, safi_t safi
,
2250 struct route_map
*route_map
);
2251 extern int peer_default_originate_unset(struct peer
*, afi_t
, safi_t
);
2252 extern void bgp_tcp_keepalive_set(struct bgp
*bgp
, uint16_t idle
,
2253 uint16_t interval
, uint16_t probes
);
2254 extern void bgp_tcp_keepalive_unset(struct bgp
*bgp
);
2256 extern void peer_port_set(struct peer
*, uint16_t);
2257 extern void peer_port_unset(struct peer
*);
2259 extern int peer_weight_set(struct peer
*, afi_t
, safi_t
, uint16_t);
2260 extern int peer_weight_unset(struct peer
*, afi_t
, safi_t
);
2262 extern int peer_timers_set(struct peer
*, uint32_t keepalive
,
2264 extern int peer_timers_unset(struct peer
*);
2266 extern int peer_timers_connect_set(struct peer
*, uint32_t);
2267 extern int peer_timers_connect_unset(struct peer
*);
2269 extern int peer_advertise_interval_set(struct peer
*, uint32_t);
2270 extern int peer_advertise_interval_unset(struct peer
*);
2272 extern int peer_timers_delayopen_set(struct peer
*peer
, uint32_t delayopen
);
2273 extern int peer_timers_delayopen_unset(struct peer
*peer
);
2275 extern void peer_interface_set(struct peer
*, const char *);
2276 extern void peer_interface_unset(struct peer
*);
2278 extern int peer_distribute_set(struct peer
*, afi_t
, safi_t
, int, const char *);
2279 extern int peer_distribute_unset(struct peer
*, afi_t
, safi_t
, int);
2281 extern int peer_allowas_in_set(struct peer
*, afi_t
, safi_t
, int, int);
2282 extern int peer_allowas_in_unset(struct peer
*, afi_t
, safi_t
);
2284 extern int peer_local_as_set(struct peer
*, as_t
, bool no_prepend
,
2286 extern int peer_local_as_unset(struct peer
*);
2288 extern int peer_prefix_list_set(struct peer
*, afi_t
, safi_t
, int,
2290 extern int peer_prefix_list_unset(struct peer
*, afi_t
, safi_t
, int);
2292 extern int peer_aslist_set(struct peer
*, afi_t
, safi_t
, int, const char *);
2293 extern int peer_aslist_unset(struct peer
*, afi_t
, safi_t
, int);
2295 extern int peer_route_map_set(struct peer
*peer
, afi_t afi
, safi_t safi
, int,
2296 const char *name
, struct route_map
*route_map
);
2297 extern int peer_route_map_unset(struct peer
*, afi_t
, safi_t
, int);
2299 extern int peer_unsuppress_map_set(struct peer
*peer
, afi_t afi
, safi_t safi
,
2301 struct route_map
*route_map
);
2303 extern int peer_advertise_map_set(struct peer
*peer
, afi_t afi
, safi_t safi
,
2304 const char *advertise_name
,
2305 struct route_map
*advertise_map
,
2306 const char *condition_name
,
2307 struct route_map
*condition_map
,
2310 extern int peer_password_set(struct peer
*, const char *);
2311 extern int peer_password_unset(struct peer
*);
2313 extern int peer_unsuppress_map_unset(struct peer
*, afi_t
, safi_t
);
2315 extern int peer_advertise_map_unset(struct peer
*peer
, afi_t afi
, safi_t safi
,
2316 const char *advertise_name
,
2317 struct route_map
*advertise_map
,
2318 const char *condition_name
,
2319 struct route_map
*condition_map
,
2322 extern int peer_maximum_prefix_set(struct peer
*, afi_t
, safi_t
, uint32_t,
2323 uint8_t, int, uint16_t, bool force
);
2324 extern int peer_maximum_prefix_unset(struct peer
*, afi_t
, safi_t
);
2326 extern void peer_maximum_prefix_out_refresh_routes(struct peer
*peer
, afi_t afi
,
2328 extern int peer_maximum_prefix_out_set(struct peer
*peer
, afi_t afi
,
2329 safi_t safi
, uint32_t max
);
2330 extern int peer_maximum_prefix_out_unset(struct peer
*peer
, afi_t afi
,
2333 extern int peer_clear(struct peer
*, struct listnode
**);
2334 extern int peer_clear_soft(struct peer
*, afi_t
, safi_t
, enum bgp_clear_type
);
2336 extern int peer_ttl_security_hops_set(struct peer
*, int);
2337 extern int peer_ttl_security_hops_unset(struct peer
*);
2339 extern void peer_tx_shutdown_message_set(struct peer
*, const char *msg
);
2340 extern void peer_tx_shutdown_message_unset(struct peer
*);
2342 extern void bgp_route_map_update_timer(struct thread
*thread
);
2343 extern const char *bgp_get_name_by_role(uint8_t role
);
2345 extern void bgp_route_map_terminate(void);
2347 extern int peer_cmp(struct peer
*p1
, struct peer
*p2
);
2349 extern int bgp_map_afi_safi_iana2int(iana_afi_t pkt_afi
, iana_safi_t pkt_safi
,
2350 afi_t
*afi
, safi_t
*safi
);
2351 extern int bgp_map_afi_safi_int2iana(afi_t afi
, safi_t safi
,
2352 iana_afi_t
*pkt_afi
,
2353 iana_safi_t
*pkt_safi
);
2355 extern struct peer_af
*peer_af_create(struct peer
*, afi_t
, safi_t
);
2356 extern struct peer_af
*peer_af_find(struct peer
*, afi_t
, safi_t
);
2357 extern int peer_af_delete(struct peer
*, afi_t
, safi_t
);
2359 extern void bgp_shutdown_enable(struct bgp
*bgp
, const char *msg
);
2360 extern void bgp_shutdown_disable(struct bgp
*bgp
);
2362 extern void bgp_close(void);
2363 extern void bgp_free(struct bgp
*);
2364 void bgp_gr_apply_running_config(void);
2367 int bgp_global_gr_init(struct bgp
*bgp
);
2368 int bgp_peer_gr_init(struct peer
*peer
);
2371 #define BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(_bgp, _peer_list) \
2373 struct peer *peer_loop; \
2374 bool gr_router_detected = false; \
2375 struct listnode *node = {0}; \
2376 for (ALL_LIST_ELEMENTS_RO(_peer_list, node, peer_loop)) { \
2377 if (CHECK_FLAG(peer_loop->flags, \
2378 PEER_FLAG_GRACEFUL_RESTART)) \
2379 gr_router_detected = true; \
2381 if (gr_router_detected \
2382 && _bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) { \
2383 bgp_zebra_send_capabilities(_bgp, false); \
2384 } else if (!gr_router_detected \
2385 && _bgp->present_zebra_gr_state \
2386 == ZEBRA_GR_ENABLE) { \
2387 bgp_zebra_send_capabilities(_bgp, true); \
2391 static inline struct bgp
*bgp_lock(struct bgp
*bgp
)
2397 static inline void bgp_unlock(struct bgp
*bgp
)
2399 assert(bgp
->lock
> 0);
2400 if (--bgp
->lock
== 0)
2404 static inline int afindex(afi_t afi
, safi_t safi
)
2410 return BGP_AF_IPV4_UNICAST
;
2411 case SAFI_MULTICAST
:
2412 return BGP_AF_IPV4_MULTICAST
;
2413 case SAFI_LABELED_UNICAST
:
2414 return BGP_AF_IPV4_LBL_UNICAST
;
2416 return BGP_AF_IPV4_VPN
;
2418 return BGP_AF_IPV4_ENCAP
;
2420 return BGP_AF_IPV4_FLOWSPEC
;
2430 return BGP_AF_IPV6_UNICAST
;
2431 case SAFI_MULTICAST
:
2432 return BGP_AF_IPV6_MULTICAST
;
2433 case SAFI_LABELED_UNICAST
:
2434 return BGP_AF_IPV6_LBL_UNICAST
;
2436 return BGP_AF_IPV6_VPN
;
2438 return BGP_AF_IPV6_ENCAP
;
2440 return BGP_AF_IPV6_FLOWSPEC
;
2450 return BGP_AF_L2VPN_EVPN
;
2452 case SAFI_MULTICAST
:
2453 case SAFI_LABELED_UNICAST
:
2467 assert(!"Reached end of function we should never hit");
2470 /* If the peer is not a peer-group but is bound to a peer-group return 1 */
2471 static inline int peer_group_active(struct peer
*peer
)
2473 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
) && peer
->group
)
2478 /* If peer is negotiated at least one address family return 1. */
2479 static inline int peer_afi_active_nego(const struct peer
*peer
, afi_t afi
)
2481 if (peer
->afc_nego
[afi
][SAFI_UNICAST
]
2482 || peer
->afc_nego
[afi
][SAFI_MULTICAST
]
2483 || peer
->afc_nego
[afi
][SAFI_LABELED_UNICAST
]
2484 || peer
->afc_nego
[afi
][SAFI_MPLS_VPN
]
2485 || peer
->afc_nego
[afi
][SAFI_ENCAP
]
2486 || peer
->afc_nego
[afi
][SAFI_FLOWSPEC
]
2487 || peer
->afc_nego
[afi
][SAFI_EVPN
])
2492 /* If at least one address family activated for group, return 1. */
2493 static inline int peer_group_af_configured(struct peer_group
*group
)
2495 struct peer
*peer
= group
->conf
;
2497 if (peer
->afc
[AFI_IP
][SAFI_UNICAST
] || peer
->afc
[AFI_IP
][SAFI_MULTICAST
]
2498 || peer
->afc
[AFI_IP
][SAFI_LABELED_UNICAST
]
2499 || peer
->afc
[AFI_IP
][SAFI_FLOWSPEC
]
2500 || peer
->afc
[AFI_IP
][SAFI_MPLS_VPN
] || peer
->afc
[AFI_IP
][SAFI_ENCAP
]
2501 || peer
->afc
[AFI_IP6
][SAFI_UNICAST
]
2502 || peer
->afc
[AFI_IP6
][SAFI_MULTICAST
]
2503 || peer
->afc
[AFI_IP6
][SAFI_LABELED_UNICAST
]
2504 || peer
->afc
[AFI_IP6
][SAFI_MPLS_VPN
]
2505 || peer
->afc
[AFI_IP6
][SAFI_ENCAP
]
2506 || peer
->afc
[AFI_IP6
][SAFI_FLOWSPEC
]
2507 || peer
->afc
[AFI_L2VPN
][SAFI_EVPN
])
2512 static inline char *timestamp_string(time_t ts
)
2515 tbuf
= time(NULL
) - (monotime(NULL
) - ts
);
2516 return ctime(&tbuf
);
2519 static inline bool peer_established(struct peer
*peer
)
2521 return peer
->status
== Established
;
2524 static inline bool peer_dynamic_neighbor(struct peer
*peer
)
2526 return CHECK_FLAG(peer
->flags
, PEER_FLAG_DYNAMIC_NEIGHBOR
);
2529 static inline bool peer_dynamic_neighbor_no_nsf(struct peer
*peer
)
2531 return (peer_dynamic_neighbor(peer
) &&
2532 !CHECK_FLAG(peer
->sflags
, PEER_STATUS_NSF_WAIT
));
2535 static inline int peer_cap_enhe(struct peer
*peer
, afi_t afi
, safi_t safi
)
2537 return (CHECK_FLAG(peer
->af_cap
[afi
][safi
], PEER_CAP_ENHE_AF_NEGO
));
2540 /* Lookup VRF for BGP instance based on its type. */
2541 static inline struct vrf
*bgp_vrf_lookup_by_instance_type(struct bgp
*bgp
)
2545 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
)
2546 vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
2547 else if (bgp
->inst_type
== BGP_INSTANCE_TYPE_VRF
)
2548 vrf
= vrf_lookup_by_name(bgp
->name
);
2555 static inline uint32_t bgp_vrf_interfaces(struct bgp
*bgp
, bool active
)
2558 struct interface
*ifp
;
2561 /* if there is one interface in the vrf which is up then it is deemed
2564 vrf
= bgp_vrf_lookup_by_instance_type(bgp
);
2567 RB_FOREACH (ifp
, if_name_head
, &vrf
->ifaces_by_name
) {
2568 if (strcmp(ifp
->name
, bgp
->name
) == 0)
2570 if (!active
|| if_is_up(ifp
))
2576 /* Link BGP instance to VRF. */
2577 static inline void bgp_vrf_link(struct bgp
*bgp
, struct vrf
*vrf
)
2579 bgp
->vrf_id
= vrf
->vrf_id
;
2580 if (vrf
->info
!= (void *)bgp
)
2581 vrf
->info
= (void *)bgp_lock(bgp
);
2584 /* Unlink BGP instance from VRF. */
2585 static inline void bgp_vrf_unlink(struct bgp
*bgp
, struct vrf
*vrf
)
2587 if (vrf
->info
== (void *)bgp
) {
2591 bgp
->vrf_id
= VRF_UNKNOWN
;
2594 static inline bool bgp_in_graceful_shutdown(struct bgp
*bgp
)
2596 /* True if either set for this instance or globally */
2597 return (!!CHECK_FLAG(bgp
->flags
, BGP_FLAG_GRACEFUL_SHUTDOWN
) ||
2598 !!CHECK_FLAG(bm
->flags
, BM_FLAG_GRACEFUL_SHUTDOWN
));
2601 /* For benefit of rfapi */
2602 extern struct peer
*peer_new(struct bgp
*bgp
);
2604 extern struct peer
*peer_lookup_in_view(struct vty
*vty
, struct bgp
*bgp
,
2605 const char *ip_str
, bool use_json
);
2606 extern int bgp_lookup_by_as_name_type(struct bgp
**bgp_val
, as_t
*as
,
2608 enum bgp_instance_type inst_type
);
2611 DECLARE_HOOK(bgp_vrf_status_changed
, (struct bgp
*bgp
, struct interface
*ifp
),
2613 DECLARE_HOOK(peer_status_changed
, (struct peer
*peer
), (peer
));
2614 DECLARE_HOOK(bgp_snmp_init_stats
, (struct bgp
*bgp
), (bgp
));
2615 DECLARE_HOOK(bgp_snmp_update_last_changed
, (struct bgp
*bgp
), (bgp
));
2616 DECLARE_HOOK(bgp_snmp_update_stats
,
2617 (struct bgp_node
*rn
, struct bgp_path_info
*pi
, bool added
),
2619 DECLARE_HOOK(bgp_rpki_prefix_status
,
2620 (struct peer
* peer
, struct attr
*attr
,
2621 const struct prefix
*prefix
),
2622 (peer
, attr
, prefix
));
2624 void peer_nsf_stop(struct peer
*peer
);
2626 void peer_tcp_mss_set(struct peer
*peer
, uint32_t tcp_mss
);
2627 void peer_tcp_mss_unset(struct peer
*peer
);
2629 extern void bgp_recalculate_afi_safi_bestpaths(struct bgp
*bgp
, afi_t afi
,
2631 extern void peer_on_policy_change(struct peer
*peer
, afi_t afi
, safi_t safi
,
2633 extern bool bgp_path_attribute_discard(struct peer
*peer
, char *buf
,
2635 extern bool bgp_path_attribute_treat_as_withdraw(struct peer
*peer
, char *buf
,
2637 #ifdef _FRR_ATTRIBUTE_PRINTFRR
2638 /* clang-format off */
2639 #pragma FRR printfrr_ext "%pBP" (struct peer *)
2640 /* clang-format on */
2643 #endif /* _QUAGGA_BGPD_H */