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