1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright 2009-2016, LabN Consulting, L.L.C.
9 * Internal definitions for RFAPI. Not for use by other code
12 #ifndef _QUAGGA_BGP_RFAPI_PRIVATE_H
13 #define _QUAGGA_BGP_RFAPI_PRIVATE_H
15 #include "lib/linklist.h"
16 #include "lib/skiplist.h"
17 #include "lib/workqueue.h"
19 #include "bgpd/bgp_attr.h"
20 #include "bgpd/bgp_route.h"
25 * Lists of rfapi_adb. Each rfapi_adb is referenced twice:
27 * 1. each is referenced in by_lifetime
28 * 2. each is referenced by exactly one of: ipN_by_prefix, ip0_by_ether
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 */
36 struct rfapi_descriptor
{
37 struct agg_node
*un_node
; /* backref to un table */
39 struct rfapi_descriptor
*next
; /* next vn_addr */
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
;
49 /* supplied by matched configuration */
51 struct ecommunity
*rt_export_list
;
52 uint32_t response_lifetime
;
54 /* list of prefixes currently being advertised by this nve */
55 struct rfapi_advertised_prefixes advertised
;
59 uint32_t max_prefix_lifetime
;
60 uint32_t min_prefix_lifetime
;
62 /* reference to this nve's import table */
63 struct rfapi_import_table
*import_table
;
65 uint32_t monitor_count
;
66 struct agg_table
*mon
; /* rfapi_monitors */
67 struct skiplist
*mon_eth
; /* ethernet monitors */
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
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
];
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 */
84 unsigned int stat_count_nh_reachable
;
85 unsigned int stat_count_nh_removal
;
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.
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.
97 struct rfapi_nve_group_cfg
*rfg
;
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:
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).
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)).
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
126 #define RFAPI_QUEUED_FLAG(afi) \
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 \
136 struct rfapi_global_stats
{
138 unsigned int max_descriptors
;
140 unsigned int count_unknown_nves
;
142 unsigned int count_queries
;
143 unsigned int count_queries_failed
;
145 unsigned int max_responses
; /* semantics? */
147 unsigned int count_registrations
;
148 unsigned int count_registrations_failed
;
150 unsigned int count_updated_response_updates
;
151 unsigned int count_updated_response_deletes
;
155 * There is one of these per BGP instance.
157 * Radix tree is indexed by un address; follow chain and
158 * check vn address to get exact match.
161 struct agg_table
*un
[AFI_MAX
];
162 struct rfapi_import_table
*imports
; /* IPv4, IPv6 */
163 struct list descriptors
; /* debug & resolve-nve imports */
165 struct rfapi_global_stats stat
;
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)
173 struct rfapi_rfp_cb_methods rfp_methods
;
176 * Import tables for Ethernet over IPSEC
178 * The skiplist keys are LNIs. Values are pointers
179 * to struct rfapi_import_table.
181 struct skiplist
*import_mac
; /* L2 */
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
188 struct agg_table
*rt_export_bgp
[AFI_MAX
];
189 struct agg_table
*rt_export_zebra
[AFI_MAX
];
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.
198 struct rfapi_import_table
*it_ce
;
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
205 struct skiplist
*resolve_nve_nexthop
;
208 * Descriptors for which rfapi_close() was called during a callback.
209 * They will be closed after the callback finishes.
211 struct work_queue
*deferred_close_q
;
214 * For "show vnc responses"
216 uint32_t response_immediate_count
;
217 uint32_t response_updated_count
;
218 uint32_t monitor_count
;
220 uint32_t rib_prefix_count_total
;
221 uint32_t rib_prefix_count_total_max
;
224 #define RFAPI_INCALLBACK 0x00000001
225 void *rfp
; /* from rfp_start */
228 #define RFAPI_RIB_PREFIX_COUNT_INCR(rfd, rfapi) \
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; \
237 #define RFAPI_RIB_PREFIX_COUNT_DECR(rfd, rfapi) \
239 --(rfd)->rib_prefix_count; \
240 --(rfapi)->rib_prefix_count_total; \
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)) \
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]) \
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) \
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
);
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! */
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
);
285 extern int rfapiCliGetPrefixAddr(struct vty
*vty
, const char *str
,
288 extern int rfapiGetVncLifetime(struct attr
*attr
, uint32_t *lifetime
);
290 extern int rfapiGetVncTunnelUnAddr(struct attr
*attr
, struct prefix
*p
);
292 extern int rfapi_reopen(struct rfapi_descriptor
*rfd
, struct bgp
*bgp
);
294 extern void vnc_import_bgp_add_rfp_host_route_mode_resolve_nve(
295 struct bgp
*bgp
, struct rfapi_descriptor
*rfd
, struct prefix
*prefix
);
297 extern void vnc_import_bgp_del_rfp_host_route_mode_resolve_nve(
298 struct bgp
*bgp
, struct rfapi_descriptor
*rfd
, struct prefix
*prefix
);
300 extern void rfapiFreeBgpTeaOptionChain(struct bgp_tea_options
*p
);
302 extern struct rfapi_vn_option
*rfapiVnOptionsDup(struct rfapi_vn_option
*orig
);
304 extern struct rfapi_un_option
*rfapiUnOptionsDup(struct rfapi_un_option
*orig
);
306 extern struct bgp_tea_options
*rfapiOptionsDup(struct bgp_tea_options
*orig
);
308 extern int rfapi_ip_addr_cmp(struct rfapi_ip_addr
*a1
,
309 struct rfapi_ip_addr
*a2
);
311 extern uint32_t rfp_cost_to_localpref(uint8_t cost
);
313 extern int rfapi_set_autord_from_vn(struct prefix_rd
*rd
,
314 struct rfapi_ip_addr
*vn
);
316 extern struct rfapi_nexthop
*rfapi_nexthop_new(struct rfapi_nexthop
*copyme
);
318 extern void rfapi_nexthop_free(void *goner
);
320 extern struct rfapi_vn_option
*
321 rfapi_vn_options_dup(struct rfapi_vn_option
*existing
);
323 extern void rfapi_un_options_free(struct rfapi_un_option
*goner
);
325 extern void rfapi_vn_options_free(struct rfapi_vn_option
*goner
);
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 /*------------------------------------------
333 * Find Layer 2 options in an option chain
339 * l2o layer 2 options extracted
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 */
351 * compaitibility to old quagga_time call
352 * time_t value in terms of stabilised absolute time.
353 * replacement for POSIX time()
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()
360 extern time_t rfapi_time(time_t *t
);
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
);
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.
397 extern int rfapi_init_and_open(struct bgp
*bgp
, struct rfapi_descriptor
*rfd
,
398 struct rfapi_nve_group_cfg
*rfg
);
400 #endif /* _QUAGGA_BGP_RFAPI_PRIVATE_H */