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