]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.h
*: Add camelCase JSON keys in addition to PascalCase
[mirror_frr.git] / bgpd / bgp_route.h
1 /* BGP routing information base
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 */
20
21 #ifndef _QUAGGA_BGP_ROUTE_H
22 #define _QUAGGA_BGP_ROUTE_H
23
24 #include <stdbool.h>
25
26 #include "hook.h"
27 #include "queue.h"
28 #include "nexthop.h"
29 #include "bgp_table.h"
30 #include "bgp_addpath_types.h"
31 #include "bgp_rpki.h"
32
33 struct bgp_nexthop_cache;
34 struct bgp_route_evpn;
35
36 enum 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,
45 bgp_show_type_community_alias,
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,
53 bgp_show_type_lcommunity_exact,
54 bgp_show_type_lcommunity_list,
55 bgp_show_type_lcommunity_list_exact,
56 bgp_show_type_flap_statistics,
57 bgp_show_type_flap_neighbor,
58 bgp_show_type_dampend_paths,
59 bgp_show_type_damp_neighbor,
60 bgp_show_type_detail,
61 bgp_show_type_rpki,
62 bgp_show_type_prefix_version,
63 };
64
65 enum bgp_show_adj_route_type {
66 bgp_show_adj_route_advertised,
67 bgp_show_adj_route_received,
68 bgp_show_adj_route_filtered,
69 bgp_show_adj_route_bestpath,
70 };
71
72
73 #define BGP_SHOW_SCODE_HEADER \
74 "Status codes: s suppressed, d damped, " \
75 "h history, * valid, > best, = multipath,\n" \
76 " i internal, r RIB-failure, S Stale, R Removed\n"
77 #define BGP_SHOW_OCODE_HEADER \
78 "Origin codes: i - IGP, e - EGP, ? - incomplete\n"
79 #define BGP_SHOW_NCODE_HEADER "Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self\n"
80 #define BGP_SHOW_RPKI_HEADER \
81 "RPKI validation codes: V valid, I invalid, N Not found\n\n"
82 #define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path\n"
83 #define BGP_SHOW_HEADER_WIDE " Network Next Hop Metric LocPrf Weight Path\n"
84
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
90 /* Maximum number of sids we can process or send with a prefix. */
91 #define BGP_MAX_SIDS 6
92
93 /* Maximum buffer length for storing BGP best path selection reason */
94 #define BGP_MAX_SELECTION_REASON_STR_BUF 32
95
96 /* Error codes for handling NLRI */
97 #define BGP_NLRI_PARSE_OK 0
98 #define BGP_NLRI_PARSE_ERROR_PREFIX_OVERFLOW -1
99 #define BGP_NLRI_PARSE_ERROR_PACKET_OVERFLOW -2
100 #define BGP_NLRI_PARSE_ERROR_PREFIX_LENGTH -3
101 #define BGP_NLRI_PARSE_ERROR_PACKET_LENGTH -4
102 #define BGP_NLRI_PARSE_ERROR_LABEL_LENGTH -5
103 #define BGP_NLRI_PARSE_ERROR_EVPN_MISSING_TYPE -6
104 #define BGP_NLRI_PARSE_ERROR_EVPN_TYPE2_SIZE -7
105 #define BGP_NLRI_PARSE_ERROR_EVPN_TYPE3_SIZE -8
106 #define BGP_NLRI_PARSE_ERROR_EVPN_TYPE4_SIZE -9
107 #define BGP_NLRI_PARSE_ERROR_EVPN_TYPE5_SIZE -10
108 #define BGP_NLRI_PARSE_ERROR_FLOWSPEC_IPV6_NOT_SUPPORTED -11
109 #define BGP_NLRI_PARSE_ERROR_FLOWSPEC_NLRI_SIZELIMIT -12
110 #define BGP_NLRI_PARSE_ERROR_FLOWSPEC_BAD_FORMAT -13
111 #define BGP_NLRI_PARSE_ERROR_ADDRESS_FAMILY -14
112 #define BGP_NLRI_PARSE_ERROR_EVPN_TYPE1_SIZE -15
113 #define BGP_NLRI_PARSE_ERROR -32
114
115 /* 1. local MAC-IP/type-2 paths in the VNI routing table are linked to the
116 * destination ES
117 * 2. remote MAC-IP paths in the global routing table are linked to the
118 * destination ES
119 */
120 struct bgp_path_es_info {
121 /* back pointer to the route */
122 struct bgp_path_info *pi;
123 vni_t vni;
124 /* destination ES */
125 struct bgp_evpn_es *es;
126 /* memory used for linking the path to the destination ES */
127 struct listnode es_listnode;
128 uint8_t flags;
129 /* Path is linked to the VNI list */
130 #define BGP_EVPN_PATH_ES_INFO_VNI_LIST (1 << 0)
131 /* Path is linked to the global list */
132 #define BGP_EVPN_PATH_ES_INFO_GLOBAL_LIST (1 << 1)
133 };
134
135 /* IP paths imported into the VRF from an EVPN route source
136 * are linked to the nexthop/VTEP IP
137 */
138 struct bgp_path_evpn_nh_info {
139 /* back pointer to the route */
140 struct bgp_path_info *pi;
141 struct bgp_evpn_nh *nh;
142 /* memory used for linking the path to the nexthop */
143 struct listnode nh_listnode;
144 };
145
146 struct bgp_path_mh_info {
147 struct bgp_path_es_info *es_info;
148 struct bgp_path_evpn_nh_info *nh_info;
149 };
150
151 struct bgp_sid_info {
152 struct in6_addr sid;
153 uint8_t loc_block_len;
154 uint8_t loc_node_len;
155 uint8_t func_len;
156 uint8_t arg_len;
157 };
158
159 /* Ancillary information to struct bgp_path_info,
160 * used for uncommonly used data (aggregation, MPLS, etc.)
161 * and lazily allocated to save memory.
162 */
163 struct bgp_path_info_extra {
164 /* Pointer to dampening structure. */
165 struct bgp_damp_info *damp_info;
166
167 /** List of aggregations that suppress this path. */
168 struct list *aggr_suppressors;
169
170 /* Nexthop reachability check. */
171 uint32_t igpmetric;
172
173 /* MPLS label(s) - VNI(s) for EVPN-VxLAN */
174 mpls_label_t label[BGP_MAX_LABELS];
175 uint32_t num_labels;
176
177 /* af specific flags */
178 uint16_t af_flags;
179 #define BGP_EVPN_MACIP_TYPE_SVI_IP (1 << 0)
180
181 /* SRv6 SID(s) for SRv6-VPN */
182 struct bgp_sid_info sid[BGP_MAX_SIDS];
183 uint32_t num_sids;
184
185 #ifdef ENABLE_BGP_VNC
186 union {
187
188 struct {
189 void *rfapi_handle; /* export: NVE advertising this
190 route */
191 struct list *local_nexthops; /* optional, for static
192 routes */
193 } export;
194
195 struct {
196 struct thread *timer;
197 void *hme; /* encap monitor, if this is a VPN route */
198 struct prefix_rd
199 rd; /* import: route's route-distinguisher */
200 uint8_t un_family; /* family of cached un address, 0 if
201 unset */
202 union {
203 struct in_addr addr4;
204 struct in6_addr addr6;
205 } un; /* cached un address */
206 time_t create_time;
207 struct prefix aux_prefix; /* AFI_L2VPN: the IP addr,
208 if family set */
209 } import;
210
211 } vnc;
212 #endif
213
214 /* For imported routes into a VNI (or VRF), this points to the parent.
215 */
216 void *parent;
217
218 /*
219 * Some tunnelish parameters follow. Maybe consolidate into an
220 * internal tunnel structure?
221 */
222
223 /*
224 * Original bgp instance for imported routes. Needed for:
225 * 1. Find all routes from a specific vrf for deletion
226 * 2. vrf context of original nexthop
227 *
228 * Store pointer to bgp instance rather than bgp->vrf_id because
229 * bgp->vrf_id is not always valid (or may change?).
230 *
231 * Set to NULL if route is not imported from another bgp instance.
232 */
233 struct bgp *bgp_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 uint16_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
301 /* BGP route type. This can be static, RIP, OSPF, BGP etc. */
302 uint8_t type;
303
304 /* When above type is BGP. This sub type specify BGP sub type
305 information. */
306 uint8_t sub_type;
307 #define BGP_ROUTE_NORMAL 0
308 #define BGP_ROUTE_STATIC 1
309 #define BGP_ROUTE_AGGREGATE 2
310 #define BGP_ROUTE_REDISTRIBUTE 3
311 #ifdef ENABLE_BGP_VNC
312 # define BGP_ROUTE_RFP 4
313 #endif
314 #define BGP_ROUTE_IMPORTED 5 /* from another bgp instance/safi */
315
316 unsigned short instance;
317
318 /* Addpath identifiers */
319 uint32_t addpath_rx_id;
320 struct bgp_addpath_info_data tx_addpath;
321 };
322
323 /* Structure used in BGP path selection */
324 struct bgp_path_info_pair {
325 struct bgp_path_info *old;
326 struct bgp_path_info *new;
327 };
328
329 /* BGP static route configuration. */
330 struct bgp_static {
331 /* Backdoor configuration. */
332 int backdoor;
333
334 /* Label index configuration; applies to LU prefixes. */
335 uint32_t label_index;
336 #define BGP_INVALID_LABEL_INDEX 0xFFFFFFFF
337
338 /* Import check status. */
339 uint8_t valid;
340
341 /* IGP metric. */
342 uint32_t igpmetric;
343
344 /* IGP nexthop. */
345 struct in_addr igpnexthop;
346
347 /* Atomic set reference count (ie cause of pathlimit) */
348 uint32_t atomic;
349
350 /* BGP redistribute route-map. */
351 struct {
352 char *name;
353 struct route_map *map;
354 } rmap;
355
356 /* Route Distinguisher */
357 struct prefix_rd prd;
358
359 /* MPLS label. */
360 mpls_label_t label;
361
362 /* EVPN */
363 esi_t *eth_s_id;
364 struct ethaddr *router_mac;
365 uint16_t encap_tunneltype;
366 struct prefix gatewayIp;
367 };
368
369 /* Aggreagete address:
370 *
371 * advertise-map Set condition to advertise attribute
372 * as-set Generate AS set path information
373 * attribute-map Set attributes of aggregate
374 * route-map Set parameters of aggregate
375 * summary-only Filter more specific routes from updates
376 * suppress-map Conditionally filter more specific routes from updates
377 * <cr>
378 */
379 struct bgp_aggregate {
380 /* Summary-only flag. */
381 uint8_t summary_only;
382
383 /* AS set generation. */
384 uint8_t as_set;
385
386 /* Route-map for aggregated route. */
387 struct {
388 char *name;
389 struct route_map *map;
390 } rmap;
391
392 /* Suppress-count. */
393 unsigned long count;
394
395 /* Count of routes of origin type incomplete under this aggregate. */
396 unsigned long incomplete_origin_count;
397
398 /* Count of routes of origin type egp under this aggregate. */
399 unsigned long egp_origin_count;
400
401 /* Optional modify flag to override ORIGIN */
402 uint8_t origin;
403
404 /* Hash containing the communities of all the
405 * routes under this aggregate.
406 */
407 struct hash *community_hash;
408
409 /* Hash containing the extended communities of all the
410 * routes under this aggregate.
411 */
412 struct hash *ecommunity_hash;
413
414 /* Hash containing the large communities of all the
415 * routes under this aggregate.
416 */
417 struct hash *lcommunity_hash;
418
419 /* Hash containing the AS-Path of all the
420 * routes under this aggregate.
421 */
422 struct hash *aspath_hash;
423
424 /* Aggregate route's community. */
425 struct community *community;
426
427 /* Aggregate route's extended community. */
428 struct ecommunity *ecommunity;
429
430 /* Aggregate route's large community. */
431 struct lcommunity *lcommunity;
432
433 /* Aggregate route's as-path. */
434 struct aspath *aspath;
435
436 /* SAFI configuration. */
437 safi_t safi;
438
439 /** Match only equal MED. */
440 bool match_med;
441 /* MED matching state. */
442 /** Did we get the first MED value? */
443 bool med_initialized;
444 /** Are there MED mismatches? */
445 bool med_mismatched;
446 /** MED value found in current group. */
447 uint32_t med_matched_value;
448
449 /**
450 * Test if aggregated address MED of all route match, otherwise
451 * returns `false`. This macro will also return `true` if MED
452 * matching is disabled.
453 */
454 #define AGGREGATE_MED_VALID(aggregate) \
455 (((aggregate)->match_med && !(aggregate)->med_mismatched) \
456 || !(aggregate)->match_med)
457
458 /** Suppress map route map name (`NULL` when disabled). */
459 char *suppress_map_name;
460 /** Suppress map route map pointer. */
461 struct route_map *suppress_map;
462 };
463
464 #define BGP_NEXTHOP_AFI_FROM_NHLEN(nhlen) \
465 ((nhlen) < IPV4_MAX_BYTELEN \
466 ? 0 \
467 : ((nhlen) < IPV6_MAX_BYTELEN ? AFI_IP : AFI_IP6))
468
469 #define BGP_ATTR_NEXTHOP_AFI_IP6(attr) \
470 (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) \
471 && ((attr)->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL \
472 || (attr)->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL \
473 || (attr)->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL \
474 || (attr)->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL))
475 #define BGP_PATH_COUNTABLE(BI) \
476 (!CHECK_FLAG((BI)->flags, BGP_PATH_HISTORY) \
477 && !CHECK_FLAG((BI)->flags, BGP_PATH_REMOVED))
478
479 /* Flags which indicate a route is unuseable in some form */
480 #define BGP_PATH_UNUSEABLE \
481 (BGP_PATH_HISTORY | BGP_PATH_DAMPED | BGP_PATH_REMOVED)
482 /* Macro to check BGP information is alive or not. Sadly,
483 * not equivalent to just checking previous, because of the
484 * sense of the additional VALID flag.
485 */
486 #define BGP_PATH_HOLDDOWN(BI) \
487 (!CHECK_FLAG((BI)->flags, BGP_PATH_VALID) \
488 || CHECK_FLAG((BI)->flags, BGP_PATH_UNUSEABLE))
489
490 #define DISTRIBUTE_IN_NAME(F) ((F)->dlist[FILTER_IN].name)
491 #define DISTRIBUTE_IN(F) ((F)->dlist[FILTER_IN].alist)
492 #define DISTRIBUTE_OUT_NAME(F) ((F)->dlist[FILTER_OUT].name)
493 #define DISTRIBUTE_OUT(F) ((F)->dlist[FILTER_OUT].alist)
494
495 #define PREFIX_LIST_IN_NAME(F) ((F)->plist[FILTER_IN].name)
496 #define PREFIX_LIST_IN(F) ((F)->plist[FILTER_IN].plist)
497 #define PREFIX_LIST_OUT_NAME(F) ((F)->plist[FILTER_OUT].name)
498 #define PREFIX_LIST_OUT(F) ((F)->plist[FILTER_OUT].plist)
499
500 #define FILTER_LIST_IN_NAME(F) ((F)->aslist[FILTER_IN].name)
501 #define FILTER_LIST_IN(F) ((F)->aslist[FILTER_IN].aslist)
502 #define FILTER_LIST_OUT_NAME(F) ((F)->aslist[FILTER_OUT].name)
503 #define FILTER_LIST_OUT(F) ((F)->aslist[FILTER_OUT].aslist)
504
505 #define ROUTE_MAP_IN_NAME(F) ((F)->map[RMAP_IN].name)
506 #define ROUTE_MAP_IN(F) ((F)->map[RMAP_IN].map)
507 #define ROUTE_MAP_OUT_NAME(F) ((F)->map[RMAP_OUT].name)
508 #define ROUTE_MAP_OUT(F) ((F)->map[RMAP_OUT].map)
509
510 #define UNSUPPRESS_MAP_NAME(F) ((F)->usmap.name)
511 #define UNSUPPRESS_MAP(F) ((F)->usmap.map)
512
513 #define ADVERTISE_MAP_NAME(F) ((F)->advmap.aname)
514 #define ADVERTISE_MAP(F) ((F)->advmap.amap)
515
516 #define ADVERTISE_CONDITION(F) ((F)->advmap.condition)
517
518 #define CONDITION_MAP_NAME(F) ((F)->advmap.cname)
519 #define CONDITION_MAP(F) ((F)->advmap.cmap)
520
521 /* path PREFIX (addpath rxid NUMBER) */
522 #define PATH_ADDPATH_STR_BUFFER PREFIX2STR_BUFFER + 32
523
524 enum bgp_path_type {
525 BGP_PATH_SHOW_ALL,
526 BGP_PATH_SHOW_BESTPATH,
527 BGP_PATH_SHOW_MULTIPATH
528 };
529
530 static inline void bgp_bump_version(struct bgp_dest *dest)
531 {
532 dest->version = bgp_table_next_version(bgp_dest_table(dest));
533 }
534
535 static inline int bgp_fibupd_safi(safi_t safi)
536 {
537 if (safi == SAFI_UNICAST || safi == SAFI_MULTICAST
538 || safi == SAFI_LABELED_UNICAST
539 || safi == SAFI_FLOWSPEC)
540 return 1;
541 return 0;
542 }
543
544 /* Flag if the route path's family matches params. */
545 static inline bool is_pi_family_matching(struct bgp_path_info *pi,
546 afi_t afi, safi_t safi)
547 {
548 struct bgp_table *table;
549 struct bgp_dest *dest;
550
551 dest = pi->net;
552 if (!dest)
553 return false;
554 table = bgp_dest_table(dest);
555 if (table &&
556 table->afi == afi &&
557 table->safi == safi)
558 return true;
559 return false;
560 }
561
562 static inline void prep_for_rmap_apply(struct bgp_path_info *dst_pi,
563 struct bgp_path_info_extra *dst_pie,
564 struct bgp_dest *dest,
565 struct bgp_path_info *src_pi,
566 struct peer *peer, struct attr *attr)
567 {
568 memset(dst_pi, 0, sizeof(struct bgp_path_info));
569 dst_pi->peer = peer;
570 dst_pi->attr = attr;
571 dst_pi->net = dest;
572 dst_pi->flags = src_pi->flags;
573 dst_pi->type = src_pi->type;
574 dst_pi->sub_type = src_pi->sub_type;
575 dst_pi->mpath = src_pi->mpath;
576 if (src_pi->extra) {
577 memcpy(dst_pie, src_pi->extra,
578 sizeof(struct bgp_path_info_extra));
579 dst_pi->extra = dst_pie;
580 }
581 }
582
583 static inline bool bgp_check_advertise(struct bgp *bgp, struct bgp_dest *dest)
584 {
585 return (!(BGP_SUPPRESS_FIB_ENABLED(bgp) &&
586 CHECK_FLAG(dest->flags, BGP_NODE_FIB_INSTALL_PENDING) &&
587 (!bgp_option_check(BGP_OPT_NO_FIB))));
588 }
589
590 /*
591 * If we have a fib result and it failed to install( or was withdrawn due
592 * to better admin distance we need to send down the wire a withdrawal.
593 * This function assumes that bgp_check_advertise was already returned
594 * as good to go.
595 */
596 static inline bool bgp_check_withdrawal(struct bgp *bgp, struct bgp_dest *dest)
597 {
598 struct bgp_path_info *pi;
599
600 if (!BGP_SUPPRESS_FIB_ENABLED(bgp))
601 return false;
602
603 for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
604 if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))
605 continue;
606
607 if (pi->sub_type != BGP_ROUTE_NORMAL)
608 return true;
609 }
610
611 if (CHECK_FLAG(dest->flags, BGP_NODE_FIB_INSTALLED))
612 return false;
613
614 return true;
615 }
616
617 /* called before bgp_process() */
618 DECLARE_HOOK(bgp_process,
619 (struct bgp * bgp, afi_t afi, safi_t safi, struct bgp_dest *bn,
620 struct peer *peer, bool withdraw),
621 (bgp, afi, safi, bn, peer, withdraw));
622
623 /* BGP show options */
624 #define BGP_SHOW_OPT_JSON (1 << 0)
625 #define BGP_SHOW_OPT_WIDE (1 << 1)
626 #define BGP_SHOW_OPT_AFI_ALL (1 << 2)
627 #define BGP_SHOW_OPT_AFI_IP (1 << 3)
628 #define BGP_SHOW_OPT_AFI_IP6 (1 << 4)
629 #define BGP_SHOW_OPT_ESTABLISHED (1 << 5)
630 #define BGP_SHOW_OPT_FAILED (1 << 6)
631 #define BGP_SHOW_OPT_DETAIL (1 << 7)
632 #define BGP_SHOW_OPT_TERSE (1 << 8)
633
634 /* Prototypes. */
635 extern void bgp_rib_remove(struct bgp_dest *dest, struct bgp_path_info *pi,
636 struct peer *peer, afi_t afi, safi_t safi);
637 extern void bgp_process_queue_init(struct bgp *bgp);
638 extern void bgp_route_init(void);
639 extern void bgp_route_finish(void);
640 extern void bgp_cleanup_routes(struct bgp *);
641 extern void bgp_announce_route(struct peer *peer, afi_t afi, safi_t safi,
642 bool force);
643 extern void bgp_stop_announce_route_timer(struct peer_af *paf);
644 extern void bgp_announce_route_all(struct peer *);
645 extern void bgp_default_originate(struct peer *, afi_t, safi_t, int);
646 extern void bgp_soft_reconfig_table_task_cancel(const struct bgp *bgp,
647 const struct bgp_table *table,
648 const struct peer *peer);
649 extern void bgp_soft_reconfig_in(struct peer *, afi_t, safi_t);
650 extern void bgp_clear_route(struct peer *, afi_t, safi_t);
651 extern void bgp_clear_route_all(struct peer *);
652 extern void bgp_clear_adj_in(struct peer *, afi_t, safi_t);
653 extern void bgp_clear_stale_route(struct peer *, afi_t, safi_t);
654 extern void bgp_set_stale_route(struct peer *peer, afi_t afi, safi_t safi);
655 extern bool bgp_outbound_policy_exists(struct peer *, struct bgp_filter *);
656 extern bool bgp_inbound_policy_exists(struct peer *, struct bgp_filter *);
657
658 extern struct bgp_dest *bgp_afi_node_get(struct bgp_table *table, afi_t afi,
659 safi_t safi, const struct prefix *p,
660 struct prefix_rd *prd);
661 extern struct bgp_path_info *bgp_path_info_lock(struct bgp_path_info *path);
662 extern struct bgp_path_info *bgp_path_info_unlock(struct bgp_path_info *path);
663 extern struct bgp_path_info *
664 bgp_get_imported_bpi_ultimate(struct bgp_path_info *info);
665 extern void bgp_path_info_add(struct bgp_dest *dest, struct bgp_path_info *pi);
666 extern void bgp_path_info_extra_free(struct bgp_path_info_extra **extra);
667 extern void bgp_path_info_reap(struct bgp_dest *dest, struct bgp_path_info *pi);
668 extern void bgp_path_info_delete(struct bgp_dest *dest,
669 struct bgp_path_info *pi);
670 extern struct bgp_path_info_extra *
671 bgp_path_info_extra_get(struct bgp_path_info *path);
672 extern void bgp_path_info_set_flag(struct bgp_dest *dest,
673 struct bgp_path_info *path, uint32_t flag);
674 extern void bgp_path_info_unset_flag(struct bgp_dest *dest,
675 struct bgp_path_info *path, uint32_t flag);
676 extern void bgp_path_info_path_with_addpath_rx_str(struct bgp_path_info *pi,
677 char *buf, size_t buf_len);
678
679 extern int bgp_nlri_parse_ip(struct peer *, struct attr *, struct bgp_nlri *);
680
681 extern bool bgp_maximum_prefix_overflow(struct peer *, afi_t, safi_t, int);
682
683 extern void bgp_redistribute_add(struct bgp *bgp, struct prefix *p,
684 const union g_addr *nexthop, ifindex_t ifindex,
685 enum nexthop_types_t nhtype, uint8_t distance,
686 enum blackhole_type bhtype, uint32_t metric,
687 uint8_t type, unsigned short instance,
688 route_tag_t tag);
689 extern void bgp_redistribute_delete(struct bgp *, struct prefix *, uint8_t,
690 unsigned short);
691 extern void bgp_redistribute_withdraw(struct bgp *, afi_t, int, unsigned short);
692
693 extern void bgp_static_add(struct bgp *);
694 extern void bgp_static_delete(struct bgp *);
695 extern void bgp_static_redo_import_check(struct bgp *);
696 extern void bgp_purge_static_redist_routes(struct bgp *bgp);
697 extern void bgp_static_update(struct bgp *bgp, const struct prefix *p,
698 struct bgp_static *s, afi_t afi, safi_t safi);
699 extern void bgp_static_withdraw(struct bgp *bgp, const struct prefix *p,
700 afi_t afi, safi_t safi);
701
702 extern int bgp_static_set_safi(afi_t afi, safi_t safi, struct vty *vty,
703 const char *, const char *, const char *,
704 const char *, int, const char *, const char *,
705 const char *, const char *);
706
707 extern int bgp_static_unset_safi(afi_t afi, safi_t safi, struct vty *,
708 const char *, const char *, const char *, int,
709 const char *, const char *, const char *);
710
711 /* this is primarily for MPLS-VPN */
712 extern int bgp_update(struct peer *peer, const struct prefix *p,
713 uint32_t addpath_id, struct attr *attr,
714 afi_t afi, safi_t safi, int type, int sub_type,
715 struct prefix_rd *prd, mpls_label_t *label,
716 uint32_t num_labels, int soft_reconfig,
717 struct bgp_route_evpn *evpn);
718 extern int bgp_withdraw(struct peer *peer, const struct prefix *p,
719 uint32_t addpath_id, struct attr *attr, afi_t afi,
720 safi_t safi, int type, int sub_type,
721 struct prefix_rd *prd, mpls_label_t *label,
722 uint32_t num_labels, struct bgp_route_evpn *evpn);
723
724 /* for bgp_nexthop and bgp_damp */
725 extern void bgp_process(struct bgp *, struct bgp_dest *, afi_t, safi_t);
726
727 /*
728 * Add an end-of-initial-update marker to the process queue. This is just a
729 * queue element with NULL bgp node.
730 */
731 extern void bgp_add_eoiu_mark(struct bgp *);
732 extern void bgp_config_write_table_map(struct vty *, struct bgp *, afi_t,
733 safi_t);
734 extern void bgp_config_write_network(struct vty *, struct bgp *, afi_t, safi_t);
735 extern void bgp_config_write_distance(struct vty *, struct bgp *, afi_t,
736 safi_t);
737
738 extern void bgp_aggregate_delete(struct bgp *bgp, const struct prefix *p,
739 afi_t afi, safi_t safi,
740 struct bgp_aggregate *aggregate);
741 extern void bgp_aggregate_route(struct bgp *bgp, const struct prefix *p,
742 afi_t afi, safi_t safi,
743 struct bgp_aggregate *aggregate);
744 extern void bgp_aggregate_increment(struct bgp *bgp, const struct prefix *p,
745 struct bgp_path_info *path, afi_t afi,
746 safi_t safi);
747 extern void bgp_aggregate_decrement(struct bgp *bgp, const struct prefix *p,
748 struct bgp_path_info *path, afi_t afi,
749 safi_t safi);
750
751 extern uint8_t bgp_distance_apply(const struct prefix *p,
752 struct bgp_path_info *path, afi_t afi,
753 safi_t safi, struct bgp *bgp);
754
755 extern afi_t bgp_node_afi(struct vty *);
756 extern safi_t bgp_node_safi(struct vty *);
757
758 extern struct bgp_path_info *info_make(int type, int sub_type,
759 unsigned short instance,
760 struct peer *peer, struct attr *attr,
761 struct bgp_dest *dest);
762
763 extern void route_vty_out(struct vty *vty, const struct prefix *p,
764 struct bgp_path_info *path, int display, safi_t safi,
765 json_object *json_paths, bool wide);
766 extern void route_vty_out_tag(struct vty *vty, const struct prefix *p,
767 struct bgp_path_info *path, int display,
768 safi_t safi, json_object *json);
769 extern void route_vty_out_tmp(struct vty *vty, struct bgp_dest *dest,
770 const struct prefix *p, struct attr *attr,
771 safi_t safi, bool use_json, json_object *json_ar,
772 bool wide);
773 extern void route_vty_out_overlay(struct vty *vty, const struct prefix *p,
774 struct bgp_path_info *path, int display,
775 json_object *json);
776
777 extern void bgp_notify_conditional_adv_scanner(struct update_subgroup *subgrp);
778
779 extern void subgroup_process_announce_selected(struct update_subgroup *subgrp,
780 struct bgp_path_info *selected,
781 struct bgp_dest *dest,
782 uint32_t addpath_tx_id);
783
784 extern bool subgroup_announce_check(struct bgp_dest *dest,
785 struct bgp_path_info *pi,
786 struct update_subgroup *subgrp,
787 const struct prefix *p, struct attr *attr,
788 bool skip_rmap_check);
789
790 extern void bgp_peer_clear_node_queue_drain_immediate(struct peer *peer);
791 extern void bgp_process_queues_drain_immediate(void);
792
793 /* for encap/vpn */
794 extern struct bgp_dest *bgp_afi_node_lookup(struct bgp_table *table, afi_t afi,
795 safi_t safi, const struct prefix *p,
796 struct prefix_rd *prd);
797 extern void bgp_path_info_restore(struct bgp_dest *dest,
798 struct bgp_path_info *path);
799
800 extern int bgp_path_info_cmp_compatible(struct bgp *bgp,
801 struct bgp_path_info *new,
802 struct bgp_path_info *exist,
803 char *pfx_buf, afi_t afi, safi_t safi,
804 enum bgp_path_selection_reason *reason);
805 extern void bgp_attr_add_llgr_community(struct attr *attr);
806 extern void bgp_attr_add_gshut_community(struct attr *attr);
807
808 extern void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
809 struct bgp_maxpaths_cfg *mpath_cfg,
810 struct bgp_path_info_pair *result, afi_t afi,
811 safi_t safi);
812 extern void bgp_zebra_clear_route_change_flags(struct bgp_dest *dest);
813 extern bool bgp_zebra_has_route_changed(struct bgp_path_info *selected);
814
815 extern void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp,
816 struct bgp_dest *dest,
817 const struct prefix_rd *prd, afi_t afi,
818 safi_t safi, json_object *json);
819 extern void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
820 struct bgp_dest *bn,
821 struct bgp_path_info *path, afi_t afi,
822 safi_t safi, enum rpki_states,
823 json_object *json_paths);
824 extern int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi,
825 struct bgp_table *table, struct prefix_rd *prd,
826 enum bgp_show_type type, void *output_arg,
827 bool use_json);
828 extern int bgp_best_path_select_defer(struct bgp *bgp, afi_t afi, safi_t safi);
829 extern bool bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi,
830 uint8_t type, uint8_t stype,
831 struct attr *attr, struct bgp_dest *dest);
832 extern int bgp_evpn_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
833 struct bgp_path_info *exist, int *paths_eq);
834 extern void bgp_aggregate_toggle_suppressed(struct bgp_aggregate *aggregate,
835 struct bgp *bgp,
836 const struct prefix *p, afi_t afi,
837 safi_t safi, bool suppress);
838 extern void subgroup_announce_reset_nhop(uint8_t family, struct attr *attr);
839 const char *
840 bgp_path_selection_reason2str(enum bgp_path_selection_reason reason);
841 extern bool bgp_addpath_encode_rx(struct peer *peer, afi_t afi, safi_t safi);
842 #endif /* _QUAGGA_BGP_ROUTE_H */