]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_route.h
Merge pull request #12780 from opensourcerouting/spdx-license-id
[mirror_frr.git] / bgpd / bgp_route.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
718e3744 2/* BGP routing information base
896014f4 3 * Copyright (C) 1996, 97, 98, 2000 Kunihiro Ishiguro
896014f4 4 */
718e3744 5
00d252cb 6#ifndef _QUAGGA_BGP_ROUTE_H
7#define _QUAGGA_BGP_ROUTE_H
8
4a11bf2c
DL
9#include <stdbool.h>
10
11#include "hook.h"
fb018d25 12#include "queue.h"
74489921 13#include "nexthop.h"
200df115 14#include "bgp_table.h"
dcc68b5e 15#include "bgp_addpath_types.h"
4933eaaf 16#include "bgp_rpki.h"
200df115 17
fb018d25 18struct bgp_nexthop_cache;
7ef5a232 19struct bgp_route_evpn;
fb018d25 20
d62a17ae 21enum bgp_show_type {
22 bgp_show_type_normal,
23 bgp_show_type_regexp,
24 bgp_show_type_prefix_list,
ed126382 25 bgp_show_type_access_list,
d62a17ae 26 bgp_show_type_filter_list,
27 bgp_show_type_route_map,
28 bgp_show_type_neighbor,
29 bgp_show_type_cidr_only,
30 bgp_show_type_prefix_longer,
a70a28a5 31 bgp_show_type_community_alias,
d62a17ae 32 bgp_show_type_community_all,
33 bgp_show_type_community,
34 bgp_show_type_community_exact,
35 bgp_show_type_community_list,
36 bgp_show_type_community_list_exact,
37 bgp_show_type_lcommunity_all,
38 bgp_show_type_lcommunity,
36a206db 39 bgp_show_type_lcommunity_exact,
d62a17ae 40 bgp_show_type_lcommunity_list,
36a206db 41 bgp_show_type_lcommunity_list_exact,
d62a17ae 42 bgp_show_type_flap_statistics,
43 bgp_show_type_flap_neighbor,
44 bgp_show_type_dampend_paths,
dba3c1d3
PG
45 bgp_show_type_damp_neighbor,
46 bgp_show_type_detail,
1e2ce4f1 47 bgp_show_type_rpki,
7d3cae70 48 bgp_show_type_prefix_version,
b2f0fa55
PG
49};
50
6392aaa6
PM
51enum bgp_show_adj_route_type {
52 bgp_show_adj_route_advertised,
53 bgp_show_adj_route_received,
54 bgp_show_adj_route_filtered,
f20ce998 55 bgp_show_adj_route_bestpath,
6392aaa6
PM
56};
57
b2f0fa55 58
d62a17ae 59#define BGP_SHOW_SCODE_HEADER \
9df8b37c 60 "Status codes: s suppressed, d damped, " \
d62a17ae 61 "h history, * valid, > best, = multipath,\n" \
9df8b37c 62 " i internal, r RIB-failure, S Stale, R Removed\n"
82c298be
DA
63#define BGP_SHOW_OCODE_HEADER \
64 "Origin codes: i - IGP, e - EGP, ? - incomplete\n"
9df8b37c 65#define BGP_SHOW_NCODE_HEADER "Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self\n"
82c298be
DA
66#define BGP_SHOW_RPKI_HEADER \
67 "RPKI validation codes: V valid, I invalid, N Not found\n\n"
eaeba5e8 68#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path\n"
ae248832 69#define BGP_SHOW_HEADER_WIDE " Network Next Hop Metric LocPrf Weight Path\n"
3f9c7369 70
b57ba6d2
MK
71/* Maximum number of labels we can process or send with a prefix. We
72 * really do only 1 for MPLS (BGP-LU) but we can do 2 for EVPN-VxLAN.
73 */
74#define BGP_MAX_LABELS 2
75
e496b420
HS
76/* Maximum number of sids we can process or send with a prefix. */
77#define BGP_MAX_SIDS 6
78
1d7260a1
DA
79/* Maximum buffer length for storing BGP best path selection reason */
80#define BGP_MAX_SELECTION_REASON_STR_BUF 32
81
513386b5
DA
82/* Error codes for handling NLRI */
83#define BGP_NLRI_PARSE_OK 0
84#define BGP_NLRI_PARSE_ERROR_PREFIX_OVERFLOW -1
85#define BGP_NLRI_PARSE_ERROR_PACKET_OVERFLOW -2
86#define BGP_NLRI_PARSE_ERROR_PREFIX_LENGTH -3
87#define BGP_NLRI_PARSE_ERROR_PACKET_LENGTH -4
88#define BGP_NLRI_PARSE_ERROR_LABEL_LENGTH -5
89#define BGP_NLRI_PARSE_ERROR_EVPN_MISSING_TYPE -6
90#define BGP_NLRI_PARSE_ERROR_EVPN_TYPE2_SIZE -7
91#define BGP_NLRI_PARSE_ERROR_EVPN_TYPE3_SIZE -8
92#define BGP_NLRI_PARSE_ERROR_EVPN_TYPE4_SIZE -9
93#define BGP_NLRI_PARSE_ERROR_EVPN_TYPE5_SIZE -10
94#define BGP_NLRI_PARSE_ERROR_FLOWSPEC_IPV6_NOT_SUPPORTED -11
95#define BGP_NLRI_PARSE_ERROR_FLOWSPEC_NLRI_SIZELIMIT -12
96#define BGP_NLRI_PARSE_ERROR_FLOWSPEC_BAD_FORMAT -13
97#define BGP_NLRI_PARSE_ERROR_ADDRESS_FAMILY -14
c44ab6f1 98#define BGP_NLRI_PARSE_ERROR_EVPN_TYPE1_SIZE -15
513386b5
DA
99#define BGP_NLRI_PARSE_ERROR -32
100
60605cbc
AK
101/* 1. local MAC-IP/type-2 paths in the VNI routing table are linked to the
102 * destination ES
103 * 2. remote MAC-IP paths in the global routing table are linked to the
26c03e43
AK
104 * destination ES
105 */
106struct bgp_path_es_info {
107 /* back pointer to the route */
108 struct bgp_path_info *pi;
109 vni_t vni;
110 /* destination ES */
111 struct bgp_evpn_es *es;
112 /* memory used for linking the path to the destination ES */
113 struct listnode es_listnode;
74efb822
AK
114 uint8_t flags;
115/* Path is linked to the VNI list */
116#define BGP_EVPN_PATH_ES_INFO_VNI_LIST (1 << 0)
117/* Path is linked to the global list */
118#define BGP_EVPN_PATH_ES_INFO_GLOBAL_LIST (1 << 1)
26c03e43
AK
119};
120
60605cbc
AK
121/* IP paths imported into the VRF from an EVPN route source
122 * are linked to the nexthop/VTEP IP
123 */
090efa2f 124struct bgp_path_evpn_nh_info {
60605cbc
AK
125 /* back pointer to the route */
126 struct bgp_path_info *pi;
090efa2f 127 struct bgp_evpn_nh *nh;
60605cbc
AK
128 /* memory used for linking the path to the nexthop */
129 struct listnode nh_listnode;
130};
131
132struct bgp_path_mh_info {
133 struct bgp_path_es_info *es_info;
090efa2f 134 struct bgp_path_evpn_nh_info *nh_info;
60605cbc
AK
135};
136
16f3db2d
RS
137struct bgp_sid_info {
138 struct in6_addr sid;
139 uint8_t loc_block_len;
140 uint8_t loc_node_len;
141 uint8_t func_len;
142 uint8_t arg_len;
ea7cd161
RS
143 uint8_t transposition_len;
144 uint8_t transposition_offset;
16f3db2d
RS
145};
146
4b7e6066 147/* Ancillary information to struct bgp_path_info,
fb982c25
PJ
148 * used for uncommonly used data (aggregation, MPLS, etc.)
149 * and lazily allocated to save memory.
150 */
4b7e6066 151struct bgp_path_info_extra {
d62a17ae 152 /* Pointer to dampening structure. */
153 struct bgp_damp_info *damp_info;
fb982c25 154
4056a5f6
RZ
155 /** List of aggregations that suppress this path. */
156 struct list *aggr_suppressors;
fb982c25 157
d62a17ae 158 /* Nexthop reachability check. */
d7c0a89a 159 uint32_t igpmetric;
fb982c25 160
b57ba6d2
MK
161 /* MPLS label(s) - VNI(s) for EVPN-VxLAN */
162 mpls_label_t label[BGP_MAX_LABELS];
d7c0a89a 163 uint32_t num_labels;
342dd0c6 164
0ca10580
CS
165 /* af specific flags */
166 uint16_t af_flags;
167#define BGP_EVPN_MACIP_TYPE_SVI_IP (1 << 0)
168
e496b420 169 /* SRv6 SID(s) for SRv6-VPN */
16f3db2d 170 struct bgp_sid_info sid[BGP_MAX_SIDS];
e496b420
HS
171 uint32_t num_sids;
172
49e5a4a0 173#ifdef ENABLE_BGP_VNC
d62a17ae 174 union {
175
176 struct {
177 void *rfapi_handle; /* export: NVE advertising this
178 route */
179 struct list *local_nexthops; /* optional, for static
180 routes */
181 } export;
182
183 struct {
184 struct thread *timer;
185 void *hme; /* encap monitor, if this is a VPN route */
186 struct prefix_rd
187 rd; /* import: route's route-distinguisher */
d7c0a89a 188 uint8_t un_family; /* family of cached un address, 0 if
d62a17ae 189 unset */
190 union {
191 struct in_addr addr4;
192 struct in6_addr addr6;
193 } un; /* cached un address */
194 time_t create_time;
996c9314
LB
195 struct prefix aux_prefix; /* AFI_L2VPN: the IP addr,
196 if family set */
d62a17ae 197 } import;
198
199 } vnc;
65efcfce 200#endif
128ea8ab 201
34c7f35f
SW
202 /*
203 * For imported routes into a VNI (or VRF)
d62a17ae 204 */
34c7f35f 205 void *parent; /* parent from global table */
852d9f97
SW
206 union {
207 struct ethaddr mac; /* MAC set here for VNI IP table */
208 struct ipaddr ip; /* IP set here for VNI MAC table */
209 } vni_info;
ddb5b488
PZ
210
211 /*
212 * Some tunnelish parameters follow. Maybe consolidate into an
213 * internal tunnel structure?
214 */
215
216 /*
217 * Original bgp instance for imported routes. Needed for:
218 * 1. Find all routes from a specific vrf for deletion
219 * 2. vrf context of original nexthop
220 *
221 * Store pointer to bgp instance rather than bgp->vrf_id because
222 * bgp->vrf_id is not always valid (or may change?).
223 *
224 * Set to NULL if route is not imported from another bgp instance.
225 */
226 struct bgp *bgp_orig;
227
4cd690ae
PG
228 /*
229 * Original bgp session to know if the session is a
230 * connected EBGP session or not
231 */
232 struct peer *peer_orig;
233
ddb5b488
PZ
234 /*
235 * Nexthop in context of original bgp instance. Needed
236 * for label resolution of core mpls routes exported to a vrf.
237 * Set nexthop_orig.family to 0 if not valid.
238 */
239 struct prefix nexthop_orig;
ce3c0614 240 /* presence of FS pbr firewall based entry */
c26edcda 241 struct list *bgp_fs_pbr;
ce3c0614
PG
242 /* presence of FS pbr iprule based entry */
243 struct list *bgp_fs_iprule;
26c03e43 244 /* Destination Ethernet Segment links for EVPN MH */
60605cbc 245 struct bgp_path_mh_info *mh_info;
fb982c25
PJ
246};
247
4b7e6066 248struct bgp_path_info {
d62a17ae 249 /* For linked list. */
4b7e6066
DS
250 struct bgp_path_info *next;
251 struct bgp_path_info *prev;
d62a17ae 252
253 /* For nexthop linked list */
4b7e6066 254 LIST_ENTRY(bgp_path_info) nh_thread;
d62a17ae 255
256 /* Back pointer to the prefix node */
9bcb3eef 257 struct bgp_dest *net;
d62a17ae 258
259 /* Back pointer to the nexthop structure */
260 struct bgp_nexthop_cache *nexthop;
fb018d25 261
d62a17ae 262 /* Peer structure. */
263 struct peer *peer;
fb018d25 264
d62a17ae 265 /* Attribute structure. */
266 struct attr *attr;
fb018d25 267
d62a17ae 268 /* Extra information */
4b7e6066 269 struct bgp_path_info_extra *extra;
fb018d25 270
cbdfbaa5 271
d62a17ae 272 /* Multipath information */
4b7e6066 273 struct bgp_path_info_mpath *mpath;
de8d5dff 274
d62a17ae 275 /* Uptime. */
276 time_t uptime;
de8d5dff 277
d62a17ae 278 /* reference count */
279 int lock;
cbdfbaa5 280
d62a17ae 281 /* BGP information status. */
46dbf9d0 282 uint32_t flags;
1defdda8
DS
283#define BGP_PATH_IGP_CHANGED (1 << 0)
284#define BGP_PATH_DAMPED (1 << 1)
285#define BGP_PATH_HISTORY (1 << 2)
286#define BGP_PATH_SELECTED (1 << 3)
287#define BGP_PATH_VALID (1 << 4)
288#define BGP_PATH_ATTR_CHANGED (1 << 5)
289#define BGP_PATH_DMED_CHECK (1 << 6)
290#define BGP_PATH_DMED_SELECTED (1 << 7)
291#define BGP_PATH_STALE (1 << 8)
292#define BGP_PATH_REMOVED (1 << 9)
293#define BGP_PATH_COUNTED (1 << 10)
294#define BGP_PATH_MULTIPATH (1 << 11)
295#define BGP_PATH_MULTIPATH_CHG (1 << 12)
296#define BGP_PATH_RIB_ATTR_CHG (1 << 13)
297#define BGP_PATH_ANNC_NH_SELF (1 << 14)
b1875e65 298#define BGP_PATH_LINK_BW_CHG (1 << 15)
46dbf9d0 299#define BGP_PATH_ACCEPT_OWN (1 << 16)
718e3744 300
d62a17ae 301 /* BGP route type. This can be static, RIP, OSPF, BGP etc. */
d7c0a89a 302 uint8_t type;
cbdfbaa5 303
d62a17ae 304 /* When above type is BGP. This sub type specify BGP sub type
305 information. */
d7c0a89a 306 uint8_t sub_type;
cbdfbaa5
PJ
307#define BGP_ROUTE_NORMAL 0
308#define BGP_ROUTE_STATIC 1
309#define BGP_ROUTE_AGGREGATE 2
9ea364a2 310#define BGP_ROUTE_REDISTRIBUTE 3
65efcfce 311#ifdef ENABLE_BGP_VNC
9ea364a2 312# define BGP_ROUTE_RFP 4
65efcfce 313#endif
ddb5b488 314#define BGP_ROUTE_IMPORTED 5 /* from another bgp instance/safi */
7c8ff89e 315
d7c0a89a 316 unsigned short instance;
a82478b9 317
d62a17ae 318 /* Addpath identifiers */
d7c0a89a 319 uint32_t addpath_rx_id;
dcc68b5e 320 struct bgp_addpath_info_data tx_addpath;
718e3744 321};
322
128ea8ab 323/* Structure used in BGP path selection */
4b7e6066
DS
324struct bgp_path_info_pair {
325 struct bgp_path_info *old;
326 struct bgp_path_info *new;
128ea8ab 327};
328
718e3744 329/* BGP static route configuration. */
d62a17ae 330struct bgp_static {
331 /* Backdoor configuration. */
332 int backdoor;
718e3744 333
d62a17ae 334 /* Label index configuration; applies to LU prefixes. */
d7c0a89a 335 uint32_t label_index;
1b6d5c7e
VV
336#define BGP_INVALID_LABEL_INDEX 0xFFFFFFFF
337
d62a17ae 338 /* Import check status. */
d7c0a89a 339 uint8_t valid;
718e3744 340
d62a17ae 341 /* IGP metric. */
d7c0a89a 342 uint32_t igpmetric;
718e3744 343
d62a17ae 344 /* IGP nexthop. */
345 struct in_addr igpnexthop;
718e3744 346
d62a17ae 347 /* Atomic set reference count (ie cause of pathlimit) */
d7c0a89a 348 uint32_t atomic;
718e3744 349
d62a17ae 350 /* BGP redistribute route-map. */
351 struct {
352 char *name;
353 struct route_map *map;
354 } rmap;
137446f9 355
d62a17ae 356 /* Route Distinguisher */
357 struct prefix_rd prd;
684a7227 358
d62a17ae 359 /* MPLS label. */
360 mpls_label_t label;
361
362 /* EVPN */
0a50c248 363 esi_t *eth_s_id;
d62a17ae 364 struct ethaddr *router_mac;
365 uint16_t encap_tunneltype;
366 struct prefix gatewayIp;
718e3744 367};
368
e00d8008
NT
369/* Aggreagete address:
370 *
371 * advertise-map Set condition to advertise attribute
372 * as-set Generate AS set path information
373 * attribute-map Set attributes of aggregate
374 * route-map Set parameters of aggregate
375 * summary-only Filter more specific routes from updates
376 * suppress-map Conditionally filter more specific routes from updates
377 * <cr>
378 */
379struct bgp_aggregate {
380 /* Summary-only flag. */
381 uint8_t summary_only;
382
383 /* AS set generation. */
384 uint8_t as_set;
385
386 /* Route-map for aggregated route. */
20894f50
DA
387 struct {
388 char *name;
389 struct route_map *map;
390 } rmap;
e00d8008
NT
391
392 /* Suppress-count. */
393 unsigned long count;
394
395 /* Count of routes of origin type incomplete under this aggregate. */
396 unsigned long incomplete_origin_count;
397
398 /* Count of routes of origin type egp under this aggregate. */
399 unsigned long egp_origin_count;
400
229757f1
DA
401 /* Optional modify flag to override ORIGIN */
402 uint8_t origin;
403
e00d8008
NT
404 /* Hash containing the communities of all the
405 * routes under this aggregate.
406 */
407 struct hash *community_hash;
408
409 /* Hash containing the extended communities of all the
410 * routes under this aggregate.
411 */
412 struct hash *ecommunity_hash;
413
414 /* Hash containing the large communities of all the
415 * routes under this aggregate.
416 */
417 struct hash *lcommunity_hash;
418
419 /* Hash containing the AS-Path of all the
420 * routes under this aggregate.
421 */
422 struct hash *aspath_hash;
423
424 /* Aggregate route's community. */
425 struct community *community;
426
427 /* Aggregate route's extended community. */
428 struct ecommunity *ecommunity;
429
430 /* Aggregate route's large community. */
431 struct lcommunity *lcommunity;
432
433 /* Aggregate route's as-path. */
434 struct aspath *aspath;
435
436 /* SAFI configuration. */
437 safi_t safi;
6aabb15d
RZ
438
439 /** Match only equal MED. */
440 bool match_med;
441 /* MED matching state. */
442 /** Did we get the first MED value? */
443 bool med_initialized;
444 /** Are there MED mismatches? */
445 bool med_mismatched;
446 /** MED value found in current group. */
447 uint32_t med_matched_value;
448
449 /**
450 * Test if aggregated address MED of all route match, otherwise
451 * returns `false`. This macro will also return `true` if MED
452 * matching is disabled.
453 */
454#define AGGREGATE_MED_VALID(aggregate) \
455 (((aggregate)->match_med && !(aggregate)->med_mismatched) \
456 || !(aggregate)->match_med)
365ab2e7
RZ
457
458 /** Suppress map route map name (`NULL` when disabled). */
459 char *suppress_map_name;
460 /** Suppress map route map pointer. */
461 struct route_map *suppress_map;
e00d8008
NT
462};
463
d62a17ae 464#define BGP_NEXTHOP_AFI_FROM_NHLEN(nhlen) \
465 ((nhlen) < IPV4_MAX_BYTELEN \
466 ? 0 \
467 : ((nhlen) < IPV6_MAX_BYTELEN ? AFI_IP : AFI_IP6))
fe3ca08f 468
109153dd
TA
469#define BGP_ATTR_MP_NEXTHOP_LEN_IP6(attr) \
470 ((attr)->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL || \
471 (attr)->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL || \
472 (attr)->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL || \
473 (attr)->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL)
474
d62a17ae 475#define BGP_ATTR_NEXTHOP_AFI_IP6(attr) \
109153dd
TA
476 (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) && \
477 BGP_ATTR_MP_NEXTHOP_LEN_IP6(attr))
478
1defdda8
DS
479#define BGP_PATH_COUNTABLE(BI) \
480 (!CHECK_FLAG((BI)->flags, BGP_PATH_HISTORY) \
481 && !CHECK_FLAG((BI)->flags, BGP_PATH_REMOVED))
80e0ad24 482
1a392d46 483/* Flags which indicate a route is unuseable in some form */
1defdda8
DS
484#define BGP_PATH_UNUSEABLE \
485 (BGP_PATH_HISTORY | BGP_PATH_DAMPED | BGP_PATH_REMOVED)
1a392d46
PJ
486/* Macro to check BGP information is alive or not. Sadly,
487 * not equivalent to just checking previous, because of the
488 * sense of the additional VALID flag.
489 */
1defdda8
DS
490#define BGP_PATH_HOLDDOWN(BI) \
491 (!CHECK_FLAG((BI)->flags, BGP_PATH_VALID) \
492 || CHECK_FLAG((BI)->flags, BGP_PATH_UNUSEABLE))
1a392d46 493
718e3744 494#define DISTRIBUTE_IN_NAME(F) ((F)->dlist[FILTER_IN].name)
495#define DISTRIBUTE_IN(F) ((F)->dlist[FILTER_IN].alist)
496#define DISTRIBUTE_OUT_NAME(F) ((F)->dlist[FILTER_OUT].name)
497#define DISTRIBUTE_OUT(F) ((F)->dlist[FILTER_OUT].alist)
498
499#define PREFIX_LIST_IN_NAME(F) ((F)->plist[FILTER_IN].name)
500#define PREFIX_LIST_IN(F) ((F)->plist[FILTER_IN].plist)
501#define PREFIX_LIST_OUT_NAME(F) ((F)->plist[FILTER_OUT].name)
502#define PREFIX_LIST_OUT(F) ((F)->plist[FILTER_OUT].plist)
503
504#define FILTER_LIST_IN_NAME(F) ((F)->aslist[FILTER_IN].name)
505#define FILTER_LIST_IN(F) ((F)->aslist[FILTER_IN].aslist)
506#define FILTER_LIST_OUT_NAME(F) ((F)->aslist[FILTER_OUT].name)
507#define FILTER_LIST_OUT(F) ((F)->aslist[FILTER_OUT].aslist)
508
fee0f4c6 509#define ROUTE_MAP_IN_NAME(F) ((F)->map[RMAP_IN].name)
510#define ROUTE_MAP_IN(F) ((F)->map[RMAP_IN].map)
511#define ROUTE_MAP_OUT_NAME(F) ((F)->map[RMAP_OUT].name)
512#define ROUTE_MAP_OUT(F) ((F)->map[RMAP_OUT].map)
513
718e3744 514#define UNSUPPRESS_MAP_NAME(F) ((F)->usmap.name)
515#define UNSUPPRESS_MAP(F) ((F)->usmap.map)
516
7f7940e6
MK
517#define ADVERTISE_MAP_NAME(F) ((F)->advmap.aname)
518#define ADVERTISE_MAP(F) ((F)->advmap.amap)
519
520#define ADVERTISE_CONDITION(F) ((F)->advmap.condition)
521
522#define CONDITION_MAP_NAME(F) ((F)->advmap.cname)
523#define CONDITION_MAP(F) ((F)->advmap.cmap)
524
2ec1e66f
DW
525/* path PREFIX (addpath rxid NUMBER) */
526#define PATH_ADDPATH_STR_BUFFER PREFIX2STR_BUFFER + 32
527
360660c6
DS
528enum bgp_path_type {
529 BGP_PATH_SHOW_ALL,
530 BGP_PATH_SHOW_BESTPATH,
531 BGP_PATH_SHOW_MULTIPATH
532};
4092b06c 533
9bcb3eef 534static inline void bgp_bump_version(struct bgp_dest *dest)
3f9c7369 535{
9bcb3eef 536 dest->version = bgp_table_next_version(bgp_dest_table(dest));
3f9c7369
DS
537}
538
d62a17ae 539static inline int bgp_fibupd_safi(safi_t safi)
cd1964ff 540{
d62a17ae 541 if (safi == SAFI_UNICAST || safi == SAFI_MULTICAST
529efa23
PG
542 || safi == SAFI_LABELED_UNICAST
543 || safi == SAFI_FLOWSPEC)
d62a17ae 544 return 1;
545 return 0;
cd1964ff
DS
546}
547
0a2f9ac1 548/* Flag if the route path's family matches params. */
549static inline bool is_pi_family_matching(struct bgp_path_info *pi,
550 afi_t afi, safi_t safi)
551{
552 struct bgp_table *table;
9bcb3eef 553 struct bgp_dest *dest;
0a2f9ac1 554
9bcb3eef
DS
555 dest = pi->net;
556 if (!dest)
0a2f9ac1 557 return false;
9bcb3eef 558 table = bgp_dest_table(dest);
0a2f9ac1 559 if (table &&
560 table->afi == afi &&
561 table->safi == safi)
562 return true;
563 return false;
564}
565
e34291b8 566static inline void prep_for_rmap_apply(struct bgp_path_info *dst_pi,
567 struct bgp_path_info_extra *dst_pie,
9bcb3eef 568 struct bgp_dest *dest,
e34291b8 569 struct bgp_path_info *src_pi,
570 struct peer *peer, struct attr *attr)
571{
572 memset(dst_pi, 0, sizeof(struct bgp_path_info));
573 dst_pi->peer = peer;
574 dst_pi->attr = attr;
9bcb3eef 575 dst_pi->net = dest;
b1875e65 576 dst_pi->flags = src_pi->flags;
577 dst_pi->type = src_pi->type;
578 dst_pi->sub_type = src_pi->sub_type;
579 dst_pi->mpath = src_pi->mpath;
e34291b8 580 if (src_pi->extra) {
581 memcpy(dst_pie, src_pi->extra,
582 sizeof(struct bgp_path_info_extra));
583 dst_pi->extra = dst_pie;
584 }
585}
586
a77e2f4b
S
587static inline bool bgp_check_advertise(struct bgp *bgp, struct bgp_dest *dest)
588{
589 return (!(BGP_SUPPRESS_FIB_ENABLED(bgp) &&
590 CHECK_FLAG(dest->flags, BGP_NODE_FIB_INSTALL_PENDING) &&
591 (!bgp_option_check(BGP_OPT_NO_FIB))));
592}
593
be785e35
DS
594/*
595 * If we have a fib result and it failed to install( or was withdrawn due
596 * to better admin distance we need to send down the wire a withdrawal.
597 * This function assumes that bgp_check_advertise was already returned
598 * as good to go.
599 */
600static inline bool bgp_check_withdrawal(struct bgp *bgp, struct bgp_dest *dest)
601{
4801fc46 602 struct bgp_path_info *pi, *selected = NULL;
be785e35
DS
603
604 if (!BGP_SUPPRESS_FIB_ENABLED(bgp))
605 return false;
606
607 for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
4801fc46
DS
608 if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) {
609 selected = pi;
be785e35 610 continue;
4801fc46 611 }
be785e35
DS
612
613 if (pi->sub_type != BGP_ROUTE_NORMAL)
614 return true;
615 }
616
4801fc46
DS
617 /*
618 * pi is selected and bgp is dealing with a static route
619 * ( ie a network statement of some sort ). FIB installed
620 * is irrelevant
621 *
622 * I am not sure what the above for loop is wanted in this
623 * manner at this point. But I do know that if I have
624 * a static route that is selected and it's the one
625 * being checked for should I withdrawal we do not
626 * want to withdraw the route on installation :)
627 */
628 if (selected && selected->sub_type == BGP_ROUTE_STATIC)
629 return false;
630
be785e35
DS
631 if (CHECK_FLAG(dest->flags, BGP_NODE_FIB_INSTALLED))
632 return false;
633
634 return true;
635}
636
4a11bf2c
DL
637/* called before bgp_process() */
638DECLARE_HOOK(bgp_process,
9bcb3eef
DS
639 (struct bgp * bgp, afi_t afi, safi_t safi, struct bgp_dest *bn,
640 struct peer *peer, bool withdraw),
8451921b 641 (bgp, afi, safi, bn, peer, withdraw));
4a11bf2c 642
96f3485c
MK
643/* BGP show options */
644#define BGP_SHOW_OPT_JSON (1 << 0)
645#define BGP_SHOW_OPT_WIDE (1 << 1)
646#define BGP_SHOW_OPT_AFI_ALL (1 << 2)
647#define BGP_SHOW_OPT_AFI_IP (1 << 3)
648#define BGP_SHOW_OPT_AFI_IP6 (1 << 4)
85eeb029
DA
649#define BGP_SHOW_OPT_ESTABLISHED (1 << 5)
650#define BGP_SHOW_OPT_FAILED (1 << 6)
67799a48 651#define BGP_SHOW_OPT_JSON_DETAIL (1 << 7)
96c81f66 652#define BGP_SHOW_OPT_TERSE (1 << 8)
509d82bd 653#define BGP_SHOW_OPT_ROUTES_DETAIL (1 << 9)
96f3485c 654
718e3744 655/* Prototypes. */
9bcb3eef 656extern void bgp_rib_remove(struct bgp_dest *dest, struct bgp_path_info *pi,
db0e1937 657 struct peer *peer, afi_t afi, safi_t safi);
b6c386bb 658extern void bgp_process_queue_init(struct bgp *bgp);
d62a17ae 659extern void bgp_route_init(void);
660extern void bgp_route_finish(void);
661extern void bgp_cleanup_routes(struct bgp *);
e1a32ec1
DS
662extern void bgp_announce_route(struct peer *peer, afi_t afi, safi_t safi,
663 bool force);
3f9c7369 664extern void bgp_stop_announce_route_timer(struct peer_af *paf);
d62a17ae 665extern void bgp_announce_route_all(struct peer *);
666extern void bgp_default_originate(struct peer *, afi_t, safi_t, int);
46aeabed
LS
667extern void bgp_soft_reconfig_table_task_cancel(const struct bgp *bgp,
668 const struct bgp_table *table,
669 const struct peer *peer);
89c73443
DS
670
671/*
672 * If this peer is configured for soft reconfig in then do the work
673 * and return true. If it is not return false; and do nothing
674 */
675extern bool bgp_soft_reconfig_in(struct peer *peer, afi_t afi, safi_t safi);
d62a17ae 676extern void bgp_clear_route(struct peer *, afi_t, safi_t);
677extern void bgp_clear_route_all(struct peer *);
678extern void bgp_clear_adj_in(struct peer *, afi_t, safi_t);
679extern void bgp_clear_stale_route(struct peer *, afi_t, safi_t);
9af52ccf 680extern void bgp_set_stale_route(struct peer *peer, afi_t afi, safi_t safi);
3dc339cd
DA
681extern bool bgp_outbound_policy_exists(struct peer *, struct bgp_filter *);
682extern bool bgp_inbound_policy_exists(struct peer *, struct bgp_filter *);
d62a17ae 683
9bcb3eef 684extern struct bgp_dest *bgp_afi_node_get(struct bgp_table *table, afi_t afi,
5a1ae2c2 685 safi_t safi, const struct prefix *p,
d62a17ae 686 struct prefix_rd *prd);
18ee8310
DS
687extern struct bgp_path_info *bgp_path_info_lock(struct bgp_path_info *path);
688extern struct bgp_path_info *bgp_path_info_unlock(struct bgp_path_info *path);
da0c0ef7
KM
689extern struct bgp_path_info *
690bgp_get_imported_bpi_ultimate(struct bgp_path_info *info);
9bcb3eef 691extern void bgp_path_info_add(struct bgp_dest *dest, struct bgp_path_info *pi);
a2e219fe 692extern void bgp_path_info_extra_free(struct bgp_path_info_extra **extra);
9bcb3eef
DS
693extern void bgp_path_info_reap(struct bgp_dest *dest, struct bgp_path_info *pi);
694extern void bgp_path_info_delete(struct bgp_dest *dest,
695 struct bgp_path_info *pi);
4b7e6066 696extern struct bgp_path_info_extra *
18ee8310 697bgp_path_info_extra_get(struct bgp_path_info *path);
9bcb3eef 698extern void bgp_path_info_set_flag(struct bgp_dest *dest,
18ee8310 699 struct bgp_path_info *path, uint32_t flag);
9bcb3eef 700extern void bgp_path_info_unset_flag(struct bgp_dest *dest,
18ee8310 701 struct bgp_path_info *path, uint32_t flag);
40381db7 702extern void bgp_path_info_path_with_addpath_rx_str(struct bgp_path_info *pi,
7533cad7 703 char *buf, size_t buf_len);
d62a17ae 704
705extern int bgp_nlri_parse_ip(struct peer *, struct attr *, struct bgp_nlri *);
706
3dc339cd 707extern bool bgp_maximum_prefix_overflow(struct peer *, afi_t, safi_t, int);
d62a17ae 708
9de1f7ff
DS
709extern void bgp_redistribute_add(struct bgp *bgp, struct prefix *p,
710 const union g_addr *nexthop, ifindex_t ifindex,
957f74c3 711 enum nexthop_types_t nhtype, uint8_t distance,
0789eb69
KM
712 enum blackhole_type bhtype, uint32_t metric,
713 uint8_t type, unsigned short instance,
714 route_tag_t tag);
d7c0a89a
QY
715extern void bgp_redistribute_delete(struct bgp *, struct prefix *, uint8_t,
716 unsigned short);
717extern void bgp_redistribute_withdraw(struct bgp *, afi_t, int, unsigned short);
d62a17ae 718
719extern void bgp_static_add(struct bgp *);
720extern void bgp_static_delete(struct bgp *);
721extern void bgp_static_redo_import_check(struct bgp *);
722extern void bgp_purge_static_redist_routes(struct bgp *bgp);
5f040085
DS
723extern void bgp_static_update(struct bgp *bgp, const struct prefix *p,
724 struct bgp_static *s, afi_t afi, safi_t safi);
725extern void bgp_static_withdraw(struct bgp *bgp, const struct prefix *p,
726 afi_t afi, safi_t safi);
d62a17ae 727
728extern int bgp_static_set_safi(afi_t afi, safi_t safi, struct vty *vty,
729 const char *, const char *, const char *,
730 const char *, int, const char *, const char *,
731 const char *, const char *);
732
733extern int bgp_static_unset_safi(afi_t afi, safi_t safi, struct vty *,
734 const char *, const char *, const char *, int,
735 const char *, const char *, const char *);
718e3744 736
94f2b392 737/* this is primarily for MPLS-VPN */
367b458c
DS
738extern void bgp_update(struct peer *peer, const struct prefix *p,
739 uint32_t addpath_id, struct attr *attr, afi_t afi,
740 safi_t safi, int type, int sub_type,
741 struct prefix_rd *prd, mpls_label_t *label,
742 uint32_t num_labels, int soft_reconfig,
743 struct bgp_route_evpn *evpn);
744extern void bgp_withdraw(struct peer *peer, const struct prefix *p,
745 uint32_t addpath_id, struct attr *attr, afi_t afi,
746 safi_t safi, int type, int sub_type,
747 struct prefix_rd *prd, mpls_label_t *label,
748 uint32_t num_labels, struct bgp_route_evpn *evpn);
718e3744 749
94f2b392 750/* for bgp_nexthop and bgp_damp */
9bcb3eef 751extern void bgp_process(struct bgp *, struct bgp_dest *, afi_t, safi_t);
cb1faec9
DS
752
753/*
754 * Add an end-of-initial-update marker to the process queue. This is just a
755 * queue element with NULL bgp node.
756 */
d62a17ae 757extern void bgp_add_eoiu_mark(struct bgp *);
60466a63
QY
758extern void bgp_config_write_table_map(struct vty *, struct bgp *, afi_t,
759 safi_t);
2b791107 760extern void bgp_config_write_network(struct vty *, struct bgp *, afi_t, safi_t);
60466a63
QY
761extern void bgp_config_write_distance(struct vty *, struct bgp *, afi_t,
762 safi_t);
d62a17ae 763
5f040085
DS
764extern void bgp_aggregate_delete(struct bgp *bgp, const struct prefix *p,
765 afi_t afi, safi_t safi,
766 struct bgp_aggregate *aggregate);
767extern void bgp_aggregate_route(struct bgp *bgp, const struct prefix *p,
768 afi_t afi, safi_t safi,
769 struct bgp_aggregate *aggregate);
5a1ae2c2 770extern void bgp_aggregate_increment(struct bgp *bgp, const struct prefix *p,
4b7e6066
DS
771 struct bgp_path_info *path, afi_t afi,
772 safi_t safi);
5a1ae2c2 773extern void bgp_aggregate_decrement(struct bgp *bgp, const struct prefix *p,
4b7e6066
DS
774 struct bgp_path_info *path, afi_t afi,
775 safi_t safi);
d62a17ae 776
b8685f9b
DS
777extern uint8_t bgp_distance_apply(const struct prefix *p,
778 struct bgp_path_info *path, afi_t afi,
779 safi_t safi, struct bgp *bgp);
d62a17ae 780
781extern afi_t bgp_node_afi(struct vty *);
782extern safi_t bgp_node_safi(struct vty *);
783
4b7e6066
DS
784extern struct bgp_path_info *info_make(int type, int sub_type,
785 unsigned short instance,
786 struct peer *peer, struct attr *attr,
9bcb3eef 787 struct bgp_dest *dest);
4b7e6066 788
bd494ec5 789extern void route_vty_out(struct vty *vty, const struct prefix *p,
4b7e6066 790 struct bgp_path_info *path, int display, safi_t safi,
ae248832 791 json_object *json_paths, bool wide);
bd494ec5 792extern void route_vty_out_tag(struct vty *vty, const struct prefix *p,
4b7e6066
DS
793 struct bgp_path_info *path, int display,
794 safi_t safi, json_object *json);
7d3cae70
DA
795extern void route_vty_out_tmp(struct vty *vty, struct bgp_dest *dest,
796 const struct prefix *p, struct attr *attr,
797 safi_t safi, bool use_json, json_object *json_ar,
798 bool wide);
bd494ec5 799extern void route_vty_out_overlay(struct vty *vty, const struct prefix *p,
9b6d8fcf 800 struct bgp_path_info *path, int display,
d62a17ae 801 json_object *json);
802
e73c112e
MK
803extern void bgp_notify_conditional_adv_scanner(struct update_subgroup *subgrp);
804
3dc339cd
DA
805extern void subgroup_process_announce_selected(struct update_subgroup *subgrp,
806 struct bgp_path_info *selected,
9bcb3eef 807 struct bgp_dest *dest,
3dc339cd 808 uint32_t addpath_tx_id);
3f9c7369 809
9bcb3eef 810extern bool subgroup_announce_check(struct bgp_dest *dest,
3dc339cd
DA
811 struct bgp_path_info *pi,
812 struct update_subgroup *subgrp,
7f7940e6 813 const struct prefix *p, struct attr *attr,
51c3a7de 814 struct attr *post_attr);
3f9c7369 815
d62a17ae 816extern void bgp_peer_clear_node_queue_drain_immediate(struct peer *peer);
817extern void bgp_process_queues_drain_immediate(void);
bb86c601 818
65efcfce 819/* for encap/vpn */
9bcb3eef 820extern struct bgp_dest *bgp_afi_node_lookup(struct bgp_table *table, afi_t afi,
bd494ec5 821 safi_t safi, const struct prefix *p,
d62a17ae 822 struct prefix_rd *prd);
9bcb3eef 823extern void bgp_path_info_restore(struct bgp_dest *dest,
18ee8310
DS
824 struct bgp_path_info *path);
825
826extern int bgp_path_info_cmp_compatible(struct bgp *bgp,
827 struct bgp_path_info *new,
828 struct bgp_path_info *exist,
fdf81fa0
DS
829 char *pfx_buf, afi_t afi, safi_t safi,
830 enum bgp_path_selection_reason *reason);
1479ed2f 831extern void bgp_attr_add_llgr_community(struct attr *attr);
7f323236 832extern void bgp_attr_add_gshut_community(struct attr *attr);
d62a17ae 833
9bcb3eef 834extern void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
d62a17ae 835 struct bgp_maxpaths_cfg *mpath_cfg,
4b7e6066 836 struct bgp_path_info_pair *result, afi_t afi,
d62a17ae 837 safi_t safi);
9bcb3eef
DS
838extern void bgp_zebra_clear_route_change_flags(struct bgp_dest *dest);
839extern bool bgp_zebra_has_route_changed(struct bgp_path_info *selected);
d62a17ae 840
841extern void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp,
9bcb3eef 842 struct bgp_dest *dest,
34c7f35f 843 const struct prefix *p,
edfee30d 844 const struct prefix_rd *prd, afi_t afi,
d62a17ae 845 safi_t safi, json_object *json);
846extern void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
34c7f35f 847 struct bgp_dest *bn, const struct prefix *p,
9bcb3eef 848 struct bgp_path_info *path, afi_t afi,
4933eaaf
DS
849 safi_t safi, enum rpki_states,
850 json_object *json_paths);
1ae44dfc
LB
851extern int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi,
852 struct bgp_table *table, struct prefix_rd *prd,
853 enum bgp_show_type type, void *output_arg,
27bb782a 854 uint16_t show_flags);
42c93837 855extern void bgp_best_path_select_defer(struct bgp *bgp, afi_t afi, safi_t safi);
e7cbe5e5
NT
856extern bool bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi,
857 uint8_t type, uint8_t stype,
9bcb3eef 858 struct attr *attr, struct bgp_dest *dest);
d071f237
AK
859extern int bgp_evpn_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
860 struct bgp_path_info *exist, int *paths_eq);
4056a5f6
RZ
861extern void bgp_aggregate_toggle_suppressed(struct bgp_aggregate *aggregate,
862 struct bgp *bgp,
863 const struct prefix *p, afi_t afi,
864 safi_t safi, bool suppress);
f2ee6d5c 865extern void subgroup_announce_reset_nhop(uint8_t family, struct attr *attr);
1d7260a1
DA
866const char *
867bgp_path_selection_reason2str(enum bgp_path_selection_reason reason);
be92fc9f 868extern bool bgp_addpath_encode_rx(struct peer *peer, afi_t afi, safi_t safi);
46dbf9d0
DA
869extern const struct prefix_rd *bgp_rd_from_dest(const struct bgp_dest *dest,
870 safi_t safi);
eb473185
DA
871extern void bgp_path_info_free_with_caller(const char *caller,
872 struct bgp_path_info *path);
873extern void bgp_path_info_add_with_caller(const char *caller,
874 struct bgp_dest *dest,
875 struct bgp_path_info *pi);
876#define bgp_path_info_add(A, B) \
877 bgp_path_info_add_with_caller(__func__, (A), (B))
878#define bgp_path_info_free(B) bgp_path_info_free_with_caller(__func__, (B))
00d252cb 879#endif /* _QUAGGA_BGP_ROUTE_H */