]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_route.h
bgpd: add L3/L2VPN Virtual Network Control feature
[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
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
20
21 #ifndef _QUAGGA_BGP_ROUTE_H
22 #define _QUAGGA_BGP_ROUTE_H
23
24 #include "queue.h"
25 #include "bgp_table.h"
26
27 struct bgp_nexthop_cache;
28
29 #define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
30 "h history, * valid, > best, = multipath,%s"\
31 " i internal, r RIB-failure, S Stale, R Removed%s"
32 #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
33 #define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
34
35 /* Ancillary information to struct bgp_info,
36 * used for uncommonly used data (aggregation, MPLS, etc.)
37 * and lazily allocated to save memory.
38 */
39 struct bgp_info_extra
40 {
41 /* Pointer to dampening structure. */
42 struct bgp_damp_info *damp_info;
43
44 /* This route is suppressed with aggregation. */
45 int suppress;
46
47 /* Nexthop reachability check. */
48 u_int32_t igpmetric;
49
50 /* MPLS label. */
51 u_char tag[3];
52
53 #if ENABLE_BGP_VNC
54 union {
55
56 struct {
57 void *rfapi_handle; /* export: NVE advertising this route */
58 struct list *local_nexthops; /* optional, for static routes */
59 } export;
60
61 struct {
62 void *timer;
63 void *hme; /* encap monitor, if this is a VPN route */
64 struct prefix_rd rd; /* import: route's route-distinguisher */
65 u_char un_family; /* family of cached un address, 0 if unset */
66 union {
67 struct in_addr addr4;
68 struct in6_addr addr6;
69 } un; /* cached un address */
70 time_t create_time;
71 struct prefix aux_prefix; /* AFI_ETHER: the IP addr, if family set */
72 } import;
73
74 } vnc;
75 #endif
76 };
77
78 struct bgp_info
79 {
80 /* For linked list. */
81 struct bgp_info *next;
82 struct bgp_info *prev;
83
84 /* For nexthop linked list */
85 LIST_ENTRY(bgp_info) nh_thread;
86
87 /* Back pointer to the prefix node */
88 struct bgp_node *net;
89
90 /* Back pointer to the nexthop structure */
91 struct bgp_nexthop_cache *nexthop;
92
93 /* Peer structure. */
94 struct peer *peer;
95
96 /* Attribute structure. */
97 struct attr *attr;
98
99 /* Extra information */
100 struct bgp_info_extra *extra;
101
102
103 /* Multipath information */
104 struct bgp_info_mpath *mpath;
105
106 /* Uptime. */
107 time_t uptime;
108
109 /* reference count */
110 int lock;
111
112 /* BGP information status. */
113 u_int16_t flags;
114 #define BGP_INFO_IGP_CHANGED (1 << 0)
115 #define BGP_INFO_DAMPED (1 << 1)
116 #define BGP_INFO_HISTORY (1 << 2)
117 #define BGP_INFO_SELECTED (1 << 3)
118 #define BGP_INFO_VALID (1 << 4)
119 #define BGP_INFO_ATTR_CHANGED (1 << 5)
120 #define BGP_INFO_DMED_CHECK (1 << 6)
121 #define BGP_INFO_DMED_SELECTED (1 << 7)
122 #define BGP_INFO_STALE (1 << 8)
123 #define BGP_INFO_REMOVED (1 << 9)
124 #define BGP_INFO_COUNTED (1 << 10)
125 #define BGP_INFO_MULTIPATH (1 << 11)
126 #define BGP_INFO_MULTIPATH_CHG (1 << 12)
127
128 /* BGP route type. This can be static, RIP, OSPF, BGP etc. */
129 u_char type;
130
131 /* When above type is BGP. This sub type specify BGP sub type
132 information. */
133 u_char sub_type;
134 #define BGP_ROUTE_NORMAL 0
135 #define BGP_ROUTE_STATIC 1
136 #define BGP_ROUTE_AGGREGATE 2
137 #define BGP_ROUTE_REDISTRIBUTE 3
138 #ifdef ENABLE_BGP_VNC
139 # define BGP_ROUTE_RFP 4
140 #endif
141
142 u_short instance;
143
144 /* Addpath identifiers */
145 u_int32_t addpath_rx_id;
146 u_int32_t addpath_tx_id;
147
148 };
149
150 /* BGP static route configuration. */
151 struct bgp_static
152 {
153 /* Backdoor configuration. */
154 int backdoor;
155
156 /* Import check status. */
157 u_char valid;
158
159 /* IGP metric. */
160 u_int32_t igpmetric;
161
162 /* IGP nexthop. */
163 struct in_addr igpnexthop;
164
165 /* Atomic set reference count (ie cause of pathlimit) */
166 u_int32_t atomic;
167
168 /* BGP redistribute route-map. */
169 struct
170 {
171 char *name;
172 struct route_map *map;
173 } rmap;
174
175 /* Route Distinguisher */
176 struct prefix_rd prd;
177
178 /* MPLS label. */
179 u_char tag[3];
180 };
181
182 #define BGP_ATTR_NEXTHOP_AFI_IP6(attr) \
183 (! CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP)) && \
184 (attr)->extra && ((attr)->extra->mp_nexthop_len == 16 || \
185 (attr)->extra->mp_nexthop_len == 32))
186 #define BGP_INFO_COUNTABLE(BI) \
187 (! CHECK_FLAG ((BI)->flags, BGP_INFO_HISTORY) \
188 && ! CHECK_FLAG ((BI)->flags, BGP_INFO_REMOVED))
189
190 /* Flags which indicate a route is unuseable in some form */
191 #define BGP_INFO_UNUSEABLE \
192 (BGP_INFO_HISTORY|BGP_INFO_DAMPED|BGP_INFO_REMOVED)
193 /* Macro to check BGP information is alive or not. Sadly,
194 * not equivalent to just checking previous, because of the
195 * sense of the additional VALID flag.
196 */
197 #define BGP_INFO_HOLDDOWN(BI) \
198 (! CHECK_FLAG ((BI)->flags, BGP_INFO_VALID) \
199 || CHECK_FLAG ((BI)->flags, BGP_INFO_UNUSEABLE))
200
201 #define DISTRIBUTE_IN_NAME(F) ((F)->dlist[FILTER_IN].name)
202 #define DISTRIBUTE_IN(F) ((F)->dlist[FILTER_IN].alist)
203 #define DISTRIBUTE_OUT_NAME(F) ((F)->dlist[FILTER_OUT].name)
204 #define DISTRIBUTE_OUT(F) ((F)->dlist[FILTER_OUT].alist)
205
206 #define PREFIX_LIST_IN_NAME(F) ((F)->plist[FILTER_IN].name)
207 #define PREFIX_LIST_IN(F) ((F)->plist[FILTER_IN].plist)
208 #define PREFIX_LIST_OUT_NAME(F) ((F)->plist[FILTER_OUT].name)
209 #define PREFIX_LIST_OUT(F) ((F)->plist[FILTER_OUT].plist)
210
211 #define FILTER_LIST_IN_NAME(F) ((F)->aslist[FILTER_IN].name)
212 #define FILTER_LIST_IN(F) ((F)->aslist[FILTER_IN].aslist)
213 #define FILTER_LIST_OUT_NAME(F) ((F)->aslist[FILTER_OUT].name)
214 #define FILTER_LIST_OUT(F) ((F)->aslist[FILTER_OUT].aslist)
215
216 #define ROUTE_MAP_IN_NAME(F) ((F)->map[RMAP_IN].name)
217 #define ROUTE_MAP_IN(F) ((F)->map[RMAP_IN].map)
218 #define ROUTE_MAP_OUT_NAME(F) ((F)->map[RMAP_OUT].name)
219 #define ROUTE_MAP_OUT(F) ((F)->map[RMAP_OUT].map)
220
221 #define UNSUPPRESS_MAP_NAME(F) ((F)->usmap.name)
222 #define UNSUPPRESS_MAP(F) ((F)->usmap.map)
223
224 /* path PREFIX (addpath rxid NUMBER) */
225 #define PATH_ADDPATH_STR_BUFFER PREFIX2STR_BUFFER + 32
226
227 enum bgp_path_type
228 {
229 BGP_PATH_ALL,
230 BGP_PATH_BESTPATH,
231 BGP_PATH_MULTIPATH
232 };
233
234 static inline void
235 bgp_bump_version (struct bgp_node *node)
236 {
237 node->version = bgp_table_next_version(bgp_node_table(node));
238 }
239
240 /* Prototypes. */
241 extern void bgp_process_queue_init (void);
242 extern void bgp_route_init (void);
243 extern void bgp_route_finish (void);
244 extern void bgp_cleanup_routes (void);
245 extern void bgp_announce_route (struct peer *, afi_t, safi_t);
246 extern void bgp_stop_announce_route_timer(struct peer_af *paf);
247 extern void bgp_announce_route_all (struct peer *);
248 extern void bgp_default_originate (struct peer *, afi_t, safi_t, int);
249 extern void bgp_soft_reconfig_in (struct peer *, afi_t, safi_t);
250 extern void bgp_clear_route (struct peer *, afi_t, safi_t);
251 extern void bgp_clear_route_all (struct peer *);
252 extern void bgp_clear_adj_in (struct peer *, afi_t, safi_t);
253 extern void bgp_clear_stale_route (struct peer *, afi_t, safi_t);
254
255 extern struct bgp_node *bgp_afi_node_get (struct bgp_table *table, afi_t afi,
256 safi_t safi, struct prefix *p,
257 struct prefix_rd *prd);
258 extern struct bgp_info *bgp_info_lock (struct bgp_info *);
259 extern struct bgp_info *bgp_info_unlock (struct bgp_info *);
260 extern void bgp_info_add (struct bgp_node *rn, struct bgp_info *ri);
261 extern void bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri);
262 extern struct bgp_info_extra *bgp_info_extra_get (struct bgp_info *);
263 extern void bgp_info_set_flag (struct bgp_node *, struct bgp_info *, u_int32_t);
264 extern void bgp_info_unset_flag (struct bgp_node *, struct bgp_info *, u_int32_t);
265 extern void bgp_info_path_with_addpath_rx_str (struct bgp_info *ri, char *buf);
266
267 extern int bgp_nlri_sanity_check (struct peer *, int, safi_t, u_char *, bgp_size_t, int *);
268 extern int bgp_nlri_parse (struct peer *, struct attr *, struct bgp_nlri *);
269
270 extern int bgp_maximum_prefix_overflow (struct peer *, afi_t, safi_t, int);
271
272 extern void bgp_redistribute_add (struct bgp *, struct prefix *, const struct in_addr *,
273 const struct in6_addr *, unsigned int ifindex,
274 u_int32_t, u_char, u_short, u_short);
275 extern void bgp_redistribute_delete (struct bgp *, struct prefix *, u_char, u_short);
276 extern void bgp_redistribute_withdraw (struct bgp *, afi_t, int, u_short);
277
278 extern void bgp_static_add (struct bgp *);
279 extern void bgp_static_delete (struct bgp *);
280 extern void bgp_static_redo_import_check (struct bgp *);
281 extern void bgp_purge_static_redist_routes (struct bgp *bgp);
282 extern void bgp_static_update (struct bgp *, struct prefix *, struct bgp_static *,
283 afi_t, safi_t);
284 extern void bgp_static_withdraw (struct bgp *, struct prefix *, afi_t, safi_t);
285
286 extern int bgp_static_set_safi (safi_t safi, struct vty *vty, const char *,
287 const char *, const char *, const char *);
288
289 extern int bgp_static_unset_safi (safi_t safi, struct vty *, const char *,
290 const char *, const char *);
291
292 /* this is primarily for MPLS-VPN */
293 extern int bgp_update (struct peer *, struct prefix *, u_int32_t, struct attr *,
294 afi_t, safi_t, int, int, struct prefix_rd *,
295 u_char *, int);
296 extern int bgp_withdraw (struct peer *, struct prefix *, u_int32_t, struct attr *,
297 afi_t, safi_t, int, int, struct prefix_rd *, u_char *);
298
299 /* for bgp_nexthop and bgp_damp */
300 extern void bgp_process (struct bgp *, struct bgp_node *, afi_t, safi_t);
301
302 /*
303 * Add an end-of-initial-update marker to the process queue. This is just a
304 * queue element with NULL bgp node.
305 */
306 extern void bgp_add_eoiu_mark (struct bgp *);
307 extern int bgp_config_write_table_map (struct vty *, struct bgp *, afi_t, safi_t,
308 int *);
309 extern int bgp_config_write_network (struct vty *, struct bgp *, afi_t, safi_t, int *);
310 extern int bgp_config_write_distance (struct vty *, struct bgp *);
311
312 extern void bgp_aggregate_increment (struct bgp *, struct prefix *, struct bgp_info *,
313 afi_t, safi_t);
314 extern void bgp_aggregate_decrement (struct bgp *, struct prefix *, struct bgp_info *,
315 afi_t, safi_t);
316
317 extern u_char bgp_distance_apply (struct prefix *, struct bgp_info *, struct bgp *);
318
319 extern afi_t bgp_node_afi (struct vty *);
320 extern safi_t bgp_node_safi (struct vty *);
321
322 extern void route_vty_out (struct vty *, struct prefix *, struct bgp_info *, int, safi_t, json_object *);
323 extern void route_vty_out_tag (struct vty *, struct prefix *, struct bgp_info *, int, safi_t, json_object *);
324 extern void route_vty_out_tmp (struct vty *, struct prefix *, struct attr *, safi_t, u_char, json_object *);
325
326 extern int
327 subgroup_process_announce_selected (struct update_subgroup *subgrp,
328 struct bgp_info *selected,
329 struct bgp_node *rn,
330 u_int32_t addpath_tx_id);
331
332 extern int subgroup_announce_check(struct bgp_info *ri,
333 struct update_subgroup *subgrp,
334 struct prefix *p, struct attr *attr);
335
336 extern void bgp_peer_clear_node_queue_drain_immediate (struct peer *peer);
337 extern void bgp_process_queues_drain_immediate (void);
338
339 /* for encap/vpn */
340 extern struct bgp_node *
341 bgp_afi_node_get (struct bgp_table *, afi_t , safi_t , struct prefix *,
342 struct prefix_rd *);
343 extern struct bgp_info *bgp_info_new (void);
344 extern void bgp_info_restore (struct bgp_node *, struct bgp_info *);
345
346 extern int bgp_info_cmp_compatible (struct bgp *, struct bgp_info *,
347 struct bgp_info *, afi_t, safi_t );
348
349 #endif /* _QUAGGA_BGP_ROUTE_H */