]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_route.h
Merge branch 'stable/3.0' into tmp-3.0-master-merge
[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
fb018d25 24#include "queue.h"
200df115 25#include "bgp_table.h"
26
fb018d25 27struct bgp_nexthop_cache;
7ef5a232 28struct bgp_route_evpn;
fb018d25 29
d62a17ae 30enum bgp_show_type {
31 bgp_show_type_normal,
32 bgp_show_type_regexp,
33 bgp_show_type_prefix_list,
34 bgp_show_type_filter_list,
35 bgp_show_type_route_map,
36 bgp_show_type_neighbor,
37 bgp_show_type_cidr_only,
38 bgp_show_type_prefix_longer,
39 bgp_show_type_community_all,
40 bgp_show_type_community,
41 bgp_show_type_community_exact,
42 bgp_show_type_community_list,
43 bgp_show_type_community_list_exact,
44 bgp_show_type_lcommunity_all,
45 bgp_show_type_lcommunity,
46 bgp_show_type_lcommunity_list,
47 bgp_show_type_flap_statistics,
48 bgp_show_type_flap_neighbor,
49 bgp_show_type_dampend_paths,
50 bgp_show_type_damp_neighbor
b2f0fa55
PG
51};
52
53
d62a17ae 54#define BGP_SHOW_SCODE_HEADER \
55 "Status codes: s suppressed, d damped, " \
56 "h history, * valid, > best, = multipath,\n" \
57 " i internal, r RIB-failure, S Stale, R Removed\n"
181039f3
DL
58#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete\n\n"
59#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path\n"
3f9c7369 60
d62a17ae 61/* Ancillary information to struct bgp_info,
fb982c25
PJ
62 * used for uncommonly used data (aggregation, MPLS, etc.)
63 * and lazily allocated to save memory.
64 */
d62a17ae 65struct bgp_info_extra {
66 /* Pointer to dampening structure. */
67 struct bgp_damp_info *damp_info;
fb982c25 68
d62a17ae 69 /* This route is suppressed with aggregation. */
70 int suppress;
fb982c25 71
d62a17ae 72 /* Nexthop reachability check. */
73 u_int32_t igpmetric;
fb982c25 74
d62a17ae 75 /* MPLS label. */
76 mpls_label_t label;
65efcfce
LB
77
78#if ENABLE_BGP_VNC
d62a17ae 79 union {
80
81 struct {
82 void *rfapi_handle; /* export: NVE advertising this
83 route */
84 struct list *local_nexthops; /* optional, for static
85 routes */
86 } export;
87
88 struct {
89 struct thread *timer;
90 void *hme; /* encap monitor, if this is a VPN route */
91 struct prefix_rd
92 rd; /* import: route's route-distinguisher */
93 u_char un_family; /* family of cached un address, 0 if
94 unset */
95 union {
96 struct in_addr addr4;
97 struct in6_addr addr6;
98 } un; /* cached un address */
99 time_t create_time;
9d303b37
DL
100 struct
101 prefix
102 aux_prefix; /* AFI_L2VPN: the IP addr,
103 if family set */
d62a17ae 104 } import;
105
106 } vnc;
65efcfce 107#endif
128ea8ab 108
d62a17ae 109 /* For imported routes into a VNI (or VRF), this points to the parent.
110 */
111 void *parent;
fb982c25
PJ
112};
113
d62a17ae 114struct bgp_info {
115 /* For linked list. */
116 struct bgp_info *next;
117 struct bgp_info *prev;
118
119 /* For nexthop linked list */
120 LIST_ENTRY(bgp_info) nh_thread;
121
122 /* Back pointer to the prefix node */
123 struct bgp_node *net;
124
125 /* Back pointer to the nexthop structure */
126 struct bgp_nexthop_cache *nexthop;
fb018d25 127
d62a17ae 128 /* Peer structure. */
129 struct peer *peer;
fb018d25 130
d62a17ae 131 /* Attribute structure. */
132 struct attr *attr;
fb018d25 133
d62a17ae 134 /* Extra information */
135 struct bgp_info_extra *extra;
fb018d25 136
cbdfbaa5 137
d62a17ae 138 /* Multipath information */
139 struct bgp_info_mpath *mpath;
de8d5dff 140
d62a17ae 141 /* Uptime. */
142 time_t uptime;
de8d5dff 143
d62a17ae 144 /* reference count */
145 int lock;
cbdfbaa5 146
d62a17ae 147 /* BGP information status. */
148 u_int16_t flags;
718e3744 149#define BGP_INFO_IGP_CHANGED (1 << 0)
150#define BGP_INFO_DAMPED (1 << 1)
151#define BGP_INFO_HISTORY (1 << 2)
152#define BGP_INFO_SELECTED (1 << 3)
153#define BGP_INFO_VALID (1 << 4)
154#define BGP_INFO_ATTR_CHANGED (1 << 5)
155#define BGP_INFO_DMED_CHECK (1 << 6)
156#define BGP_INFO_DMED_SELECTED (1 << 7)
93406d87 157#define BGP_INFO_STALE (1 << 8)
b40d939b 158#define BGP_INFO_REMOVED (1 << 9)
902212c3 159#define BGP_INFO_COUNTED (1 << 10)
de8d5dff
JB
160#define BGP_INFO_MULTIPATH (1 << 11)
161#define BGP_INFO_MULTIPATH_CHG (1 << 12)
cd1964ff 162#define BGP_INFO_RIB_ATTR_CHG (1 << 13)
718e3744 163
d62a17ae 164 /* BGP route type. This can be static, RIP, OSPF, BGP etc. */
165 u_char type;
cbdfbaa5 166
d62a17ae 167 /* When above type is BGP. This sub type specify BGP sub type
168 information. */
169 u_char sub_type;
cbdfbaa5
PJ
170#define BGP_ROUTE_NORMAL 0
171#define BGP_ROUTE_STATIC 1
172#define BGP_ROUTE_AGGREGATE 2
173#define BGP_ROUTE_REDISTRIBUTE 3
65efcfce
LB
174#ifdef ENABLE_BGP_VNC
175# define BGP_ROUTE_RFP 4
176#endif
7c8ff89e 177
d62a17ae 178 u_short instance;
a82478b9 179
d62a17ae 180 /* Addpath identifiers */
181 u_int32_t addpath_rx_id;
182 u_int32_t addpath_tx_id;
718e3744 183};
184
128ea8ab 185/* Structure used in BGP path selection */
d62a17ae 186struct bgp_info_pair {
187 struct bgp_info *old;
188 struct bgp_info *new;
128ea8ab 189};
190
718e3744 191/* BGP static route configuration. */
d62a17ae 192struct bgp_static {
193 /* Backdoor configuration. */
194 int backdoor;
718e3744 195
d62a17ae 196 /* Label index configuration; applies to LU prefixes. */
197 u_int32_t label_index;
1b6d5c7e
VV
198#define BGP_INVALID_LABEL_INDEX 0xFFFFFFFF
199
d62a17ae 200 /* Import check status. */
201 u_char valid;
718e3744 202
d62a17ae 203 /* IGP metric. */
204 u_int32_t igpmetric;
718e3744 205
d62a17ae 206 /* IGP nexthop. */
207 struct in_addr igpnexthop;
718e3744 208
d62a17ae 209 /* Atomic set reference count (ie cause of pathlimit) */
210 u_int32_t atomic;
718e3744 211
d62a17ae 212 /* BGP redistribute route-map. */
213 struct {
214 char *name;
215 struct route_map *map;
216 } rmap;
137446f9 217
d62a17ae 218 /* Route Distinguisher */
219 struct prefix_rd prd;
684a7227 220
d62a17ae 221 /* MPLS label. */
222 mpls_label_t label;
223
224 /* EVPN */
225 struct eth_segment_id *eth_s_id;
226 struct ethaddr *router_mac;
227 uint16_t encap_tunneltype;
228 struct prefix gatewayIp;
718e3744 229};
230
d62a17ae 231#define BGP_NEXTHOP_AFI_FROM_NHLEN(nhlen) \
232 ((nhlen) < IPV4_MAX_BYTELEN \
233 ? 0 \
234 : ((nhlen) < IPV6_MAX_BYTELEN ? AFI_IP : AFI_IP6))
fe3ca08f 235
d62a17ae 236#define BGP_ATTR_NEXTHOP_AFI_IP6(attr) \
237 (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) \
238 && ((attr)->mp_nexthop_len == 16 || (attr)->mp_nexthop_len == 32))
239#define BGP_INFO_COUNTABLE(BI) \
240 (!CHECK_FLAG((BI)->flags, BGP_INFO_HISTORY) \
241 && !CHECK_FLAG((BI)->flags, BGP_INFO_REMOVED))
80e0ad24 242
1a392d46 243/* Flags which indicate a route is unuseable in some form */
d62a17ae 244#define BGP_INFO_UNUSEABLE \
245 (BGP_INFO_HISTORY | BGP_INFO_DAMPED | BGP_INFO_REMOVED)
1a392d46
PJ
246/* Macro to check BGP information is alive or not. Sadly,
247 * not equivalent to just checking previous, because of the
248 * sense of the additional VALID flag.
249 */
d62a17ae 250#define BGP_INFO_HOLDDOWN(BI) \
251 (!CHECK_FLAG((BI)->flags, BGP_INFO_VALID) \
252 || CHECK_FLAG((BI)->flags, BGP_INFO_UNUSEABLE))
1a392d46 253
718e3744 254#define DISTRIBUTE_IN_NAME(F) ((F)->dlist[FILTER_IN].name)
255#define DISTRIBUTE_IN(F) ((F)->dlist[FILTER_IN].alist)
256#define DISTRIBUTE_OUT_NAME(F) ((F)->dlist[FILTER_OUT].name)
257#define DISTRIBUTE_OUT(F) ((F)->dlist[FILTER_OUT].alist)
258
259#define PREFIX_LIST_IN_NAME(F) ((F)->plist[FILTER_IN].name)
260#define PREFIX_LIST_IN(F) ((F)->plist[FILTER_IN].plist)
261#define PREFIX_LIST_OUT_NAME(F) ((F)->plist[FILTER_OUT].name)
262#define PREFIX_LIST_OUT(F) ((F)->plist[FILTER_OUT].plist)
263
264#define FILTER_LIST_IN_NAME(F) ((F)->aslist[FILTER_IN].name)
265#define FILTER_LIST_IN(F) ((F)->aslist[FILTER_IN].aslist)
266#define FILTER_LIST_OUT_NAME(F) ((F)->aslist[FILTER_OUT].name)
267#define FILTER_LIST_OUT(F) ((F)->aslist[FILTER_OUT].aslist)
268
fee0f4c6 269#define ROUTE_MAP_IN_NAME(F) ((F)->map[RMAP_IN].name)
270#define ROUTE_MAP_IN(F) ((F)->map[RMAP_IN].map)
271#define ROUTE_MAP_OUT_NAME(F) ((F)->map[RMAP_OUT].name)
272#define ROUTE_MAP_OUT(F) ((F)->map[RMAP_OUT].map)
273
718e3744 274#define UNSUPPRESS_MAP_NAME(F) ((F)->usmap.name)
275#define UNSUPPRESS_MAP(F) ((F)->usmap.map)
276
2ec1e66f
DW
277/* path PREFIX (addpath rxid NUMBER) */
278#define PATH_ADDPATH_STR_BUFFER PREFIX2STR_BUFFER + 32
279
d62a17ae 280enum bgp_path_type { BGP_PATH_ALL, BGP_PATH_BESTPATH, BGP_PATH_MULTIPATH };
4092b06c 281
d62a17ae 282static inline void bgp_bump_version(struct bgp_node *node)
3f9c7369 283{
d62a17ae 284 node->version = bgp_table_next_version(bgp_node_table(node));
3f9c7369
DS
285}
286
d62a17ae 287static inline int bgp_fibupd_safi(safi_t safi)
cd1964ff 288{
d62a17ae 289 if (safi == SAFI_UNICAST || safi == SAFI_MULTICAST
290 || safi == SAFI_LABELED_UNICAST)
291 return 1;
292 return 0;
cd1964ff
DS
293}
294
718e3744 295/* Prototypes. */
d62a17ae 296extern void bgp_process_queue_init(void);
297extern void bgp_route_init(void);
298extern void bgp_route_finish(void);
299extern void bgp_cleanup_routes(struct bgp *);
300extern void bgp_announce_route(struct peer *, afi_t, safi_t);
3f9c7369 301extern void bgp_stop_announce_route_timer(struct peer_af *paf);
d62a17ae 302extern void bgp_announce_route_all(struct peer *);
303extern void bgp_default_originate(struct peer *, afi_t, safi_t, int);
304extern void bgp_soft_reconfig_in(struct peer *, afi_t, safi_t);
305extern void bgp_clear_route(struct peer *, afi_t, safi_t);
306extern void bgp_clear_route_all(struct peer *);
307extern void bgp_clear_adj_in(struct peer *, afi_t, safi_t);
308extern void bgp_clear_stale_route(struct peer *, afi_t, safi_t);
309
310extern struct bgp_node *bgp_afi_node_get(struct bgp_table *table, afi_t afi,
311 safi_t safi, struct prefix *p,
312 struct prefix_rd *prd);
313extern struct bgp_info *bgp_info_lock(struct bgp_info *);
314extern struct bgp_info *bgp_info_unlock(struct bgp_info *);
315extern void bgp_info_add(struct bgp_node *rn, struct bgp_info *ri);
316extern void bgp_info_reap(struct bgp_node *rn, struct bgp_info *ri);
317extern void bgp_info_delete(struct bgp_node *rn, struct bgp_info *ri);
318extern struct bgp_info_extra *bgp_info_extra_get(struct bgp_info *);
319extern void bgp_info_set_flag(struct bgp_node *, struct bgp_info *, u_int32_t);
320extern void bgp_info_unset_flag(struct bgp_node *, struct bgp_info *,
321 u_int32_t);
322extern void bgp_info_path_with_addpath_rx_str(struct bgp_info *ri, char *buf);
323
324extern int bgp_nlri_parse_ip(struct peer *, struct attr *, struct bgp_nlri *);
325
326extern int bgp_maximum_prefix_overflow(struct peer *, afi_t, safi_t, int);
327
328extern void bgp_redistribute_add(struct bgp *, struct prefix *,
329 const struct in_addr *,
330 const struct in6_addr *, unsigned int ifindex,
331 u_int32_t, u_char, u_short, route_tag_t);
332extern void bgp_redistribute_delete(struct bgp *, struct prefix *, u_char,
333 u_short);
334extern void bgp_redistribute_withdraw(struct bgp *, afi_t, int, u_short);
335
336extern void bgp_static_add(struct bgp *);
337extern void bgp_static_delete(struct bgp *);
338extern void bgp_static_redo_import_check(struct bgp *);
339extern void bgp_purge_static_redist_routes(struct bgp *bgp);
340extern void bgp_static_update(struct bgp *, struct prefix *,
341 struct bgp_static *, afi_t, safi_t);
342extern void bgp_static_withdraw(struct bgp *, struct prefix *, afi_t, safi_t);
343
344extern int bgp_static_set_safi(afi_t afi, safi_t safi, struct vty *vty,
345 const char *, const char *, const char *,
346 const char *, int, const char *, const char *,
347 const char *, const char *);
348
349extern int bgp_static_unset_safi(afi_t afi, safi_t safi, struct vty *,
350 const char *, const char *, const char *, int,
351 const char *, const char *, const char *);
718e3744 352
94f2b392 353/* this is primarily for MPLS-VPN */
d62a17ae 354extern int bgp_update(struct peer *, struct prefix *, u_int32_t, struct attr *,
355 afi_t, safi_t, int, int, struct prefix_rd *,
356 mpls_label_t *, int, struct bgp_route_evpn *);
357extern int bgp_withdraw(struct peer *, struct prefix *, u_int32_t,
358 struct attr *, afi_t, safi_t, int, int,
359 struct prefix_rd *, mpls_label_t *,
360 struct bgp_route_evpn *);
718e3744 361
94f2b392 362/* for bgp_nexthop and bgp_damp */
d62a17ae 363extern void bgp_process(struct bgp *, struct bgp_node *, afi_t, safi_t);
cb1faec9
DS
364
365/*
366 * Add an end-of-initial-update marker to the process queue. This is just a
367 * queue element with NULL bgp node.
368 */
d62a17ae 369extern void bgp_add_eoiu_mark(struct bgp *);
370extern int bgp_config_write_table_map(struct vty *, struct bgp *, afi_t, safi_t,
371 int *);
372extern int bgp_config_write_network(struct vty *, struct bgp *, afi_t, safi_t,
373 int *);
374extern int bgp_config_write_distance(struct vty *, struct bgp *, afi_t, safi_t,
375 int *);
376
377extern void bgp_aggregate_increment(struct bgp *, struct prefix *,
378 struct bgp_info *, afi_t, safi_t);
379extern void bgp_aggregate_decrement(struct bgp *, struct prefix *,
380 struct bgp_info *, afi_t, safi_t);
381
382extern u_char bgp_distance_apply(struct prefix *, struct bgp_info *, afi_t,
383 safi_t, struct bgp *);
384
385extern afi_t bgp_node_afi(struct vty *);
386extern safi_t bgp_node_safi(struct vty *);
387
388extern struct bgp_info *info_make(int type, int sub_type, u_short instance,
389 struct peer *peer, struct attr *attr,
390 struct bgp_node *rn);
391
392extern void route_vty_out(struct vty *, struct prefix *, struct bgp_info *, int,
393 safi_t, json_object *);
394extern void route_vty_out_tag(struct vty *, struct prefix *, struct bgp_info *,
395 int, safi_t, json_object *);
396extern void route_vty_out_tmp(struct vty *, struct prefix *, struct attr *,
397 safi_t, u_char, json_object *);
398extern void route_vty_out_overlay(struct vty *vty, struct prefix *p,
399 struct bgp_info *binfo, int display,
400 json_object *json);
401
402extern int subgroup_process_announce_selected(struct update_subgroup *subgrp,
403 struct bgp_info *selected,
404 struct bgp_node *rn,
405 u_int32_t addpath_tx_id);
3f9c7369 406
cd1964ff 407extern int subgroup_announce_check(struct bgp_node *rn, struct bgp_info *ri,
3f9c7369
DS
408 struct update_subgroup *subgrp,
409 struct prefix *p, struct attr *attr);
410
d62a17ae 411extern void bgp_peer_clear_node_queue_drain_immediate(struct peer *peer);
412extern void bgp_process_queues_drain_immediate(void);
bb86c601 413
65efcfce 414/* for encap/vpn */
d62a17ae 415extern struct bgp_node *bgp_afi_node_get(struct bgp_table *, afi_t, safi_t,
416 struct prefix *, struct prefix_rd *);
417extern struct bgp_node *bgp_afi_node_lookup(struct bgp_table *table, afi_t afi,
418 safi_t safi, struct prefix *p,
419 struct prefix_rd *prd);
420extern struct bgp_info *bgp_info_new(void);
421extern void bgp_info_restore(struct bgp_node *, struct bgp_info *);
422
423extern int bgp_info_cmp_compatible(struct bgp *, struct bgp_info *,
424 struct bgp_info *, char *pfx_buf, afi_t afi,
425 safi_t safi);
426
427extern void bgp_best_selection(struct bgp *bgp, struct bgp_node *rn,
428 struct bgp_maxpaths_cfg *mpath_cfg,
429 struct bgp_info_pair *result, afi_t afi,
430 safi_t safi);
431extern void bgp_zebra_clear_route_change_flags(struct bgp_node *rn);
432extern int bgp_zebra_has_route_changed(struct bgp_node *rn,
433 struct bgp_info *selected);
434
435extern void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp,
436 struct bgp_node *rn,
437 struct prefix_rd *prd, afi_t afi,
438 safi_t safi, json_object *json);
439extern void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
440 struct prefix *p, struct bgp_info *binfo,
441 afi_t afi, safi_t safi,
442 json_object *json_paths);
00d252cb 443#endif /* _QUAGGA_BGP_ROUTE_H */