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