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