]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/rfapi/rfapi_private.h
Merge pull request #12248 from pguibert6WIND/bgpasdot
[mirror_frr.git] / bgpd / rfapi / rfapi_private.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 *
4 * Copyright 2009-2016, LabN Consulting, L.L.C.
5 *
6 */
7
8 /*
9 * Internal definitions for RFAPI. Not for use by other code
10 */
11
12 #ifndef _QUAGGA_BGP_RFAPI_PRIVATE_H
13 #define _QUAGGA_BGP_RFAPI_PRIVATE_H
14
15 #include "lib/linklist.h"
16 #include "lib/skiplist.h"
17 #include "lib/workqueue.h"
18
19 #include "bgpd/bgp_attr.h"
20 #include "bgpd/bgp_route.h"
21
22 #include "rfapi.h"
23
24 /*
25 * Lists of rfapi_adb. Each rfapi_adb is referenced twice:
26 *
27 * 1. each is referenced in by_lifetime
28 * 2. each is referenced by exactly one of: ipN_by_prefix, ip0_by_ether
29 */
30 struct rfapi_advertised_prefixes {
31 struct skiplist *ipN_by_prefix; /* all except 0/32, 0/128 */
32 struct skiplist *ip0_by_ether; /* ip prefix 0/32, 0/128 */
33 struct skiplist *by_lifetime; /* all */
34 };
35
36 struct rfapi_descriptor {
37 struct agg_node *un_node; /* backref to un table */
38
39 struct rfapi_descriptor *next; /* next vn_addr */
40
41 /* supplied by client */
42 struct bgp *bgp; /* from rfp_start_val */
43 struct rfapi_ip_addr vn_addr;
44 struct rfapi_ip_addr un_addr;
45 rfapi_response_cb_t *response_cb; /* override per-bgp response_cb */
46 void *cookie; /* for callbacks */
47 struct rfapi_tunneltype_option default_tunneltype_option;
48
49 /* supplied by matched configuration */
50 struct prefix_rd rd;
51 struct ecommunity *rt_export_list;
52 uint32_t response_lifetime;
53
54 /* list of prefixes currently being advertised by this nve */
55 struct rfapi_advertised_prefixes advertised;
56
57 time_t open_time;
58
59 uint32_t max_prefix_lifetime;
60 uint32_t min_prefix_lifetime;
61
62 /* reference to this nve's import table */
63 struct rfapi_import_table *import_table;
64
65 uint32_t monitor_count;
66 struct agg_table *mon; /* rfapi_monitors */
67 struct skiplist *mon_eth; /* ethernet monitors */
68
69 /*
70 * rib RIB as seen by NVE
71 * rib_pending RIB containing nodes with updated info chains
72 * rsp_times last time we sent response containing pfx
73 */
74 uint32_t rib_prefix_count; /* pfxes with routes */
75 struct agg_table *rib[AFI_MAX];
76 struct agg_table *rib_pending[AFI_MAX];
77 struct work_queue *updated_responses_queue;
78 struct agg_table *rsp_times[AFI_MAX];
79
80 uint32_t rsp_counter; /* dedup initial rsp */
81 time_t rsp_time; /* dedup initial rsp */
82 time_t ftd_last_allowed_time; /* FTD filter */
83
84 unsigned int stat_count_nh_reachable;
85 unsigned int stat_count_nh_removal;
86
87 /*
88 * points to the original nve group structure that matched
89 * when this nve_descriptor was created. We use this pointer
90 * in rfapi_close() to find the nve group structure and
91 * delete its reference back to us.
92 *
93 * If the nve group structure is deleted (via configuration
94 * change) while this nve_descriptor exists, this rfg pointer
95 * will be set to NULL.
96 */
97 struct rfapi_nve_group_cfg *rfg;
98
99 /*
100 * This ~7kB structure is here to permit multiple routes for
101 * a prefix to be injected to BGP. There are at least two
102 * situations where such conditions obtain:
103 *
104 * When an VNC route is exported to BGP on behalf of the set of
105 * NVEs that belong to the export NVE group, it is replicated
106 * so that there is one route per NVE (and the route's nexthop
107 * is the NVE's VN address).
108 *
109 * Each of these routes being injected to BGP must have a distinct
110 * peer pointer (otherwise, if they have the same peer pointer, each
111 * route will be considered an implicit waithdraw of the previous
112 * route injected from that peer, and the new route will replace
113 * rather than augment the old one(s)).
114 */
115 struct peer *peer;
116
117 uint32_t flags;
118 #define RFAPI_HD_FLAG_CALLBACK_SCHEDULED_AFI_IP 0x00000001
119 #define RFAPI_HD_FLAG_CALLBACK_SCHEDULED_AFI_IP6 0x00000002
120 #define RFAPI_HD_FLAG_CALLBACK_SCHEDULED_AFI_L2VPN 0x00000004
121 #define RFAPI_HD_FLAG_PROVISIONAL 0x00000008
122 #define RFAPI_HD_FLAG_CLOSING_ADMINISTRATIVELY 0x00000010
123 #define RFAPI_HD_FLAG_IS_VRF 0x00000012
124 };
125
126 #define RFAPI_QUEUED_FLAG(afi) \
127 (((afi) == AFI_IP) \
128 ? RFAPI_HD_FLAG_CALLBACK_SCHEDULED_AFI_IP \
129 : (((afi) == AFI_IP6) \
130 ? RFAPI_HD_FLAG_CALLBACK_SCHEDULED_AFI_IP6 \
131 : (((afi) == AFI_L2VPN) \
132 ? RFAPI_HD_FLAG_CALLBACK_SCHEDULED_AFI_L2VPN \
133 : (assert(0), 0))))
134
135
136 struct rfapi_global_stats {
137 time_t last_reset;
138 unsigned int max_descriptors;
139
140 unsigned int count_unknown_nves;
141
142 unsigned int count_queries;
143 unsigned int count_queries_failed;
144
145 unsigned int max_responses; /* semantics? */
146
147 unsigned int count_registrations;
148 unsigned int count_registrations_failed;
149
150 unsigned int count_updated_response_updates;
151 unsigned int count_updated_response_deletes;
152 };
153
154 /*
155 * There is one of these per BGP instance.
156 *
157 * Radix tree is indexed by un address; follow chain and
158 * check vn address to get exact match.
159 */
160 struct rfapi {
161 struct agg_table *un[AFI_MAX];
162 struct rfapi_import_table *imports; /* IPv4, IPv6 */
163 struct list descriptors; /* debug & resolve-nve imports */
164
165 struct rfapi_global_stats stat;
166
167 /*
168 * callbacks into RFP, set at startup time (bgp_rfapi_new() gets
169 * values from rfp_start()) or via rfapi_rfp_set_cb_methods()
170 * (otherwise NULL). Note that the response_cb method can also
171 * be overridden per-rfd (currently used only for debug/test scenarios)
172 */
173 struct rfapi_rfp_cb_methods rfp_methods;
174
175 /*
176 * Import tables for Ethernet over IPSEC
177 *
178 * The skiplist keys are LNIs. Values are pointers
179 * to struct rfapi_import_table.
180 */
181 struct skiplist *import_mac; /* L2 */
182
183 /*
184 * when exporting plain routes ("registered-nve" mode) to
185 * bgp unicast or zebra, we need to keep track of information
186 * related to expiring the routes according to the VNC lifetime
187 */
188 struct agg_table *rt_export_bgp[AFI_MAX];
189 struct agg_table *rt_export_zebra[AFI_MAX];
190
191 /*
192 * For VNC->BGP unicast exports in CE mode, we need a
193 * routing table that collects all of the VPN routes
194 * in a single tree. The VPN rib is split up according
195 * to RD first, so we can't use that. This is an import
196 * table that matches all RTs.
197 */
198 struct rfapi_import_table *it_ce;
199
200 /*
201 * when importing bgp-direct routes in resolve-nve mode,
202 * this list maps unicast route nexthops to their bgp_path_infos
203 * in the unicast table
204 */
205 struct skiplist *resolve_nve_nexthop;
206
207 /*
208 * Descriptors for which rfapi_close() was called during a callback.
209 * They will be closed after the callback finishes.
210 */
211 struct work_queue *deferred_close_q;
212
213 /*
214 * For "show vnc responses"
215 */
216 uint32_t response_immediate_count;
217 uint32_t response_updated_count;
218 uint32_t monitor_count;
219
220 uint32_t rib_prefix_count_total;
221 uint32_t rib_prefix_count_total_max;
222
223 uint32_t flags;
224 #define RFAPI_INCALLBACK 0x00000001
225 void *rfp; /* from rfp_start */
226 };
227
228 #define RFAPI_RIB_PREFIX_COUNT_INCR(rfd, rfapi) \
229 do { \
230 ++(rfd)->rib_prefix_count; \
231 ++(rfapi)->rib_prefix_count_total; \
232 if ((rfapi)->rib_prefix_count_total \
233 > (rfapi)->rib_prefix_count_total_max) \
234 ++(rfapi)->rib_prefix_count_total_max; \
235 } while (0)
236
237 #define RFAPI_RIB_PREFIX_COUNT_DECR(rfd, rfapi) \
238 do { \
239 --(rfd)->rib_prefix_count; \
240 --(rfapi)->rib_prefix_count_total; \
241 } while (0)
242
243 #define RFAPI_0_PREFIX(prefix) \
244 ((((prefix)->family == AF_INET) \
245 ? (prefix)->u.prefix4.s_addr == INADDR_ANY \
246 : (((prefix)->family == AF_INET6) \
247 ? (IN6_IS_ADDR_UNSPECIFIED(&(prefix)->u.prefix6)) \
248 : 0)))
249
250 #define RFAPI_0_ETHERADDR(ea) \
251 (((ea)->octet[0] | (ea)->octet[1] | (ea)->octet[2] | (ea)->octet[3] \
252 | (ea)->octet[4] | (ea)->octet[5]) \
253 == 0)
254
255 #define RFAPI_HOST_PREFIX(prefix) \
256 (((prefix)->family == AF_INET) \
257 ? ((prefix)->prefixlen == IPV4_MAX_BITLEN) \
258 : (((prefix)->family == AF_INET6) \
259 ? ((prefix)->prefixlen == IPV6_MAX_BITLEN) \
260 : 0))
261
262 extern int rfapi_find_rfd(struct bgp *bgp, struct rfapi_ip_addr *vn_addr,
263 struct rfapi_ip_addr *un_addr,
264 struct rfapi_descriptor **rfd);
265
266 extern void
267 add_vnc_route(struct rfapi_descriptor *rfd, /* cookie + UN addr for VPN */
268 struct bgp *bgp, int safi, const struct prefix *p,
269 struct prefix_rd *prd, struct rfapi_ip_addr *nexthop,
270 uint32_t *local_pref, /* host byte order */
271 uint32_t *lifetime, /* host byte order */
272 struct bgp_tea_options *rfp_options,
273 struct rfapi_un_option *options_un,
274 struct rfapi_vn_option *options_vn,
275 struct ecommunity *rt_export_list, uint32_t *med, uint32_t *label,
276 uint8_t type, uint8_t sub_type, int flags);
277 #define RFAPI_AHR_NO_TUNNEL_SUBTLV 0x00000001
278 #define RFAPI_AHR_RFPOPT_IS_VNCTLV 0x00000002 /* hack! */
279
280 extern void del_vnc_route(struct rfapi_descriptor *rfd, struct peer *peer,
281 struct bgp *bgp, safi_t safi, const struct prefix *p,
282 struct prefix_rd *prd, uint8_t type, uint8_t sub_type,
283 struct rfapi_nexthop *lnh, int kill);
284
285 extern int rfapiCliGetPrefixAddr(struct vty *vty, const char *str,
286 struct prefix *p);
287
288 extern int rfapiGetVncLifetime(struct attr *attr, uint32_t *lifetime);
289
290 extern int rfapiGetVncTunnelUnAddr(struct attr *attr, struct prefix *p);
291
292 extern int rfapi_reopen(struct rfapi_descriptor *rfd, struct bgp *bgp);
293
294 extern void vnc_import_bgp_add_rfp_host_route_mode_resolve_nve(
295 struct bgp *bgp, struct rfapi_descriptor *rfd, struct prefix *prefix);
296
297 extern void vnc_import_bgp_del_rfp_host_route_mode_resolve_nve(
298 struct bgp *bgp, struct rfapi_descriptor *rfd, struct prefix *prefix);
299
300 extern void rfapiFreeBgpTeaOptionChain(struct bgp_tea_options *p);
301
302 extern struct rfapi_vn_option *rfapiVnOptionsDup(struct rfapi_vn_option *orig);
303
304 extern struct rfapi_un_option *rfapiUnOptionsDup(struct rfapi_un_option *orig);
305
306 extern struct bgp_tea_options *rfapiOptionsDup(struct bgp_tea_options *orig);
307
308 extern int rfapi_ip_addr_cmp(struct rfapi_ip_addr *a1,
309 struct rfapi_ip_addr *a2);
310
311 extern uint32_t rfp_cost_to_localpref(uint8_t cost);
312
313 extern int rfapi_set_autord_from_vn(struct prefix_rd *rd,
314 struct rfapi_ip_addr *vn);
315
316 extern struct rfapi_nexthop *rfapi_nexthop_new(struct rfapi_nexthop *copyme);
317
318 extern void rfapi_nexthop_free(void *goner);
319
320 extern struct rfapi_vn_option *
321 rfapi_vn_options_dup(struct rfapi_vn_option *existing);
322
323 extern void rfapi_un_options_free(struct rfapi_un_option *goner);
324
325 extern void rfapi_vn_options_free(struct rfapi_vn_option *goner);
326
327 extern void vnc_add_vrf_opener(struct bgp *bgp,
328 struct rfapi_nve_group_cfg *rfg);
329 extern void clear_vnc_vrf_closer(struct rfapi_nve_group_cfg *rfg);
330 /*------------------------------------------
331 * rfapi_extract_l2o
332 *
333 * Find Layer 2 options in an option chain
334 *
335 * input:
336 * pHop option chain
337 *
338 * output:
339 * l2o layer 2 options extracted
340 *
341 * return value:
342 * 0 OK
343 * 1 no options found
344 *
345 --------------------------------------------*/
346 extern int rfapi_extract_l2o(
347 struct bgp_tea_options *pHop, /* chain of options */
348 struct rfapi_l2address_option *l2o); /* return extracted value */
349
350 /*
351 * compaitibility to old quagga_time call
352 * time_t value in terms of stabilised absolute time.
353 * replacement for POSIX time()
354 *
355 * Please do not use this. This is kept only for
356 * Lou's CI in that that CI compiles against some
357 * private bgp code and it will just fail to compile
358 * without this. Use monotime()
359 */
360 extern time_t rfapi_time(time_t *t);
361
362 DECLARE_MGROUP(RFAPI);
363 DECLARE_MTYPE(RFAPI_CFG);
364 DECLARE_MTYPE(RFAPI_GROUP_CFG);
365 DECLARE_MTYPE(RFAPI_L2_CFG);
366 DECLARE_MTYPE(RFAPI_RFP_GROUP_CFG);
367 DECLARE_MTYPE(RFAPI);
368 DECLARE_MTYPE(RFAPI_DESC);
369 DECLARE_MTYPE(RFAPI_IMPORTTABLE);
370 DECLARE_MTYPE(RFAPI_MONITOR);
371 DECLARE_MTYPE(RFAPI_MONITOR_ENCAP);
372 DECLARE_MTYPE(RFAPI_NEXTHOP);
373 DECLARE_MTYPE(RFAPI_VN_OPTION);
374 DECLARE_MTYPE(RFAPI_UN_OPTION);
375 DECLARE_MTYPE(RFAPI_WITHDRAW);
376 DECLARE_MTYPE(RFAPI_RFG_NAME);
377 DECLARE_MTYPE(RFAPI_ADB);
378 DECLARE_MTYPE(RFAPI_ETI);
379 DECLARE_MTYPE(RFAPI_NVE_ADDR);
380 DECLARE_MTYPE(RFAPI_PREFIX_BAG);
381 DECLARE_MTYPE(RFAPI_IT_EXTRA);
382 DECLARE_MTYPE(RFAPI_INFO);
383 DECLARE_MTYPE(RFAPI_ADDR);
384 DECLARE_MTYPE(RFAPI_UPDATED_RESPONSE_QUEUE);
385 DECLARE_MTYPE(RFAPI_RECENT_DELETE);
386 DECLARE_MTYPE(RFAPI_L2ADDR_OPT);
387 DECLARE_MTYPE(RFAPI_AP);
388 DECLARE_MTYPE(RFAPI_MONITOR_ETH);
389
390
391 /*
392 * Caller must supply an already-allocated rfd with the "caller"
393 * fields already set (vn_addr, un_addr, callback, cookie)
394 * The advertised_prefixes[] array elements should be NULL to
395 * have this function set them to newly-allocated radix trees.
396 */
397 extern int rfapi_init_and_open(struct bgp *bgp, struct rfapi_descriptor *rfd,
398 struct rfapi_nve_group_cfg *rfg);
399
400 #endif /* _QUAGGA_BGP_RFAPI_PRIVATE_H */