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