]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/rfapi/bgp_rfapi_cfg.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / bgpd / rfapi / bgp_rfapi_cfg.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 #ifndef _QUAGGA_BGP_RFAPI_CFG_H
9 #define _QUAGGA_BGP_RFAPI_CFG_H
10
11 #include "lib/table.h"
12 #include "lib/routemap.h"
13
14 #ifdef ENABLE_BGP_VNC
15 #include "rfapi.h"
16
17 struct rfapi_l2_group_cfg {
18 char *name;
19 uint32_t logical_net_id;
20 struct list *labels; /* list of uint32_t */
21 struct ecommunity *rt_import_list;
22 struct ecommunity *rt_export_list;
23 void *rfp_cfg; /* rfp owned group config */
24
25 QOBJ_FIELDS;
26 };
27 DECLARE_QOBJ_TYPE(rfapi_l2_group_cfg);
28
29 typedef enum {
30 RFAPI_GROUP_CFG_NVE = 1,
31 RFAPI_GROUP_CFG_VRF,
32 RFAPI_GROUP_CFG_L2,
33 RFAPI_GROUP_CFG_MAX
34 } rfapi_group_cfg_type_t;
35
36 struct rfapi_nve_group_cfg {
37 struct agg_node *vn_node; /* backref */
38 struct agg_node *un_node; /* backref */
39
40 rfapi_group_cfg_type_t type; /* NVE|VPN */
41 char *name; /* unique by type! */
42 struct prefix vn_prefix;
43 struct prefix un_prefix;
44
45 struct prefix_rd rd;
46 uint8_t l2rd; /* 0 = VN addr LSB */
47 uint32_t response_lifetime;
48 uint32_t flags;
49 #define RFAPI_RFG_RESPONSE_LIFETIME 0x01 /* bits */
50 #define RFAPI_RFG_L2RD 0x02
51 #define RFAPI_RFG_VPN_NH_SELF 0x04
52 struct ecommunity *rt_import_list;
53 struct ecommunity *rt_export_list;
54 struct rfapi_import_table *rfapi_import_table;
55
56 void *rfp_cfg; /* rfp owned group config */
57 /*
58 * List of NVE descriptors that are assigned to this NVE group
59 *
60 * Currently (Mar 2010) this list is used only by the route
61 * export code to generate per-NVE nexthops for each route.
62 *
63 * The nve descriptors listed here have pointers back to
64 * this nve group config structure to enable them to delete
65 * their own list entries when they are closed. Consequently,
66 * if an instance of this nve group config structure is deleted,
67 * we must first set the nve descriptor references to it to NULL.
68 */
69 struct list *nves;
70
71 /*
72 * Route filtering
73 *
74 * Prefix lists are segregated by afi (part of the base plist code)
75 * Route-maps are not segregated
76 */
77 char *plist_export_bgp_name[AFI_MAX];
78 struct prefix_list *plist_export_bgp[AFI_MAX];
79
80 char *plist_export_zebra_name[AFI_MAX];
81 struct prefix_list *plist_export_zebra[AFI_MAX];
82
83 char *plist_redist_name[ZEBRA_ROUTE_MAX][AFI_MAX];
84 struct prefix_list *plist_redist[ZEBRA_ROUTE_MAX][AFI_MAX];
85
86 char *routemap_export_bgp_name;
87 struct route_map *routemap_export_bgp;
88
89 char *routemap_export_zebra_name;
90 struct route_map *routemap_export_zebra;
91
92 char *routemap_redist_name[ZEBRA_ROUTE_MAX];
93 struct route_map *routemap_redist[ZEBRA_ROUTE_MAX];
94
95 /* for VRF type groups */
96 uint32_t label;
97 struct rfapi_descriptor *rfd;
98 QOBJ_FIELDS;
99 };
100 DECLARE_QOBJ_TYPE(rfapi_nve_group_cfg);
101
102 struct rfapi_rfg_name {
103 struct rfapi_nve_group_cfg *rfg;
104 char *name;
105 };
106
107 typedef enum {
108 VNC_REDIST_MODE_PLAIN = 0, /* 0 = default */
109 VNC_REDIST_MODE_RFG,
110 VNC_REDIST_MODE_RESOLVE_NVE
111 } vnc_redist_mode_t;
112
113 struct rfapi_cfg {
114 struct prefix_rd default_rd;
115 uint8_t default_l2rd;
116 struct ecommunity *default_rt_import_list;
117 struct ecommunity *default_rt_export_list;
118 uint32_t default_response_lifetime;
119 #define BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT 3600
120 void *default_rfp_cfg; /* rfp owned group config */
121
122 struct list *l2_groups; /* rfapi_l2_group_cfg list */
123 /* three views into the same collection of rfapi_nve_group_cfg */
124 struct list *nve_groups_sequential;
125 struct agg_table *nve_groups_vn[AFI_MAX];
126 struct agg_table *nve_groups_un[AFI_MAX];
127
128 /*
129 * For Single VRF export to ordinary routing protocols. This is
130 * the nve-group that the ordinary protocols belong to. We use it
131 * to set the RD when sending unicast Zebra routes to VNC
132 */
133 uint8_t redist[AFI_MAX][ZEBRA_ROUTE_MAX];
134 uint32_t redist_lifetime;
135 vnc_redist_mode_t redist_mode;
136
137 /*
138 * view name of BGP unicast instance that holds
139 * exterior routes
140 */
141 char *redist_bgp_exterior_view_name;
142 struct bgp *redist_bgp_exterior_view;
143
144 /*
145 * nve group for redistribution of routes from zebra to VNC
146 * (which is probably not useful for production networks)
147 */
148 char *rfg_redist_name;
149 struct rfapi_nve_group_cfg *rfg_redist;
150
151 /*
152 * List of NVE groups on whose behalf we will export VNC
153 * routes to zebra. ((NB: it's actually a list of <struct
154 * rfapi_rfg_name>)
155 * This list is used when BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_BITS is
156 * BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_GRP
157 */
158 struct list *rfg_export_zebra_l;
159
160 /*
161 * List of NVE groups on whose behalf we will export VNC
162 * routes directly to the bgp unicast RIB. (NB: it's actually
163 * a list of <struct rfapi_rfg_name>)
164 * This list is used when BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS is
165 * BGP_VNC_CONFIG_EXPORT_BGP_MODE_GRP
166 */
167 struct list *rfg_export_direct_bgp_l;
168
169 /*
170 * Exported Route filtering
171 *
172 * Prefix lists are segregated by afi (part of the base plist code)
173 * Route-maps are not segregated
174 */
175 char *plist_export_bgp_name[AFI_MAX];
176 struct prefix_list *plist_export_bgp[AFI_MAX];
177
178 char *plist_export_zebra_name[AFI_MAX];
179 struct prefix_list *plist_export_zebra[AFI_MAX];
180
181 char *routemap_export_bgp_name;
182 struct route_map *routemap_export_bgp;
183
184 char *routemap_export_zebra_name;
185 struct route_map *routemap_export_zebra;
186
187 /*
188 * Redistributed route filtering (routes from other
189 * protocols into VNC)
190 */
191 char *plist_redist_name[ZEBRA_ROUTE_MAX][AFI_MAX];
192 struct prefix_list *plist_redist[ZEBRA_ROUTE_MAX][AFI_MAX];
193
194 char *routemap_redist_name[ZEBRA_ROUTE_MAX];
195 struct route_map *routemap_redist[ZEBRA_ROUTE_MAX];
196
197 /*
198 * For importing bgp unicast routes to VNC, we encode the CE
199 * (route nexthop) in a Route Origin extended community. The
200 * local part (16-bit) is user-configurable.
201 */
202 uint16_t resolve_nve_roo_local_admin;
203 #define BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT 5226
204
205 uint32_t flags;
206 #define BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP 0x00000001
207 #define BGP_VNC_CONFIG_CALLBACK_DISABLE 0x00000002
208 #define BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE 0x00000004
209
210 #define BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS 0x000000f0
211 #define BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_BITS 0x00000f00
212
213 #define BGP_VNC_CONFIG_EXPORT_BGP_MODE_NONE 0x00000000
214 #define BGP_VNC_CONFIG_EXPORT_BGP_MODE_GRP 0x00000010
215 #define BGP_VNC_CONFIG_EXPORT_BGP_MODE_RH 0x00000020 /* registerd nve */
216 #define BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE 0x00000040
217
218 #define BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_NONE 0x00000000
219 #define BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_GRP 0x00000100
220 #define BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_RH 0x00000200
221
222 #define BGP_VNC_CONFIG_FILTER_SELF_FROM_RSP 0x00001000
223 #define BGP_VNC_CONFIG_L2RD 0x00002000
224
225 /* Use new NVE RIB to filter callback routes */
226 /* Filter querying NVE's registrations from responses */
227 /* Default to updated-responses off */
228 /* Default to removal-responses off */
229 #define BGP_VNC_CONFIG_FLAGS_DEFAULT \
230 (BGP_VNC_CONFIG_FILTER_SELF_FROM_RSP | BGP_VNC_CONFIG_CALLBACK_DISABLE \
231 | BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE)
232
233 struct rfapi_rfp_cfg rfp_cfg; /* rfp related configuration */
234 };
235
236 #define VNC_EXPORT_ZEBRA_GRP_ENABLED(hc) \
237 (((hc)->flags & BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_BITS) \
238 == BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_GRP)
239
240 #define VNC_EXPORT_ZEBRA_RH_ENABLED(hc) \
241 (((hc)->flags & BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_BITS) \
242 == BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_RH)
243
244 #define VNC_EXPORT_BGP_GRP_ENABLED(hc) \
245 (((hc)->flags & BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS) \
246 == BGP_VNC_CONFIG_EXPORT_BGP_MODE_GRP)
247
248 #define VNC_EXPORT_BGP_RH_ENABLED(hc) \
249 (((hc)->flags & BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS) \
250 == BGP_VNC_CONFIG_EXPORT_BGP_MODE_RH)
251
252 #define VNC_EXPORT_BGP_CE_ENABLED(hc) \
253 (((hc)->flags & BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS) \
254 == BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE)
255
256
257 void bgp_rfapi_cfg_init(void);
258
259 struct rfapi_cfg *bgp_rfapi_cfg_new(struct rfapi_rfp_cfg *cfg);
260
261 void bgp_rfapi_cfg_destroy(struct bgp *bgp, struct rfapi_cfg *h);
262
263 int bgp_rfapi_cfg_write(struct vty *vty, struct bgp *bgp);
264
265 extern int bgp_rfapi_is_vnc_configured(struct bgp *bgp);
266
267 extern void nve_group_to_nve_list(struct rfapi_nve_group_cfg *rfg,
268 struct list **nves,
269 uint8_t family); /* AF_INET, AF_INET6 */
270
271 struct rfapi_nve_group_cfg *bgp_rfapi_cfg_match_group(struct rfapi_cfg *hc,
272 struct prefix *vn,
273 struct prefix *un);
274
275 struct rfapi_nve_group_cfg *
276 bgp_rfapi_cfg_match_byname(struct bgp *bgp, const char *name,
277 rfapi_group_cfg_type_t type); /* _MAX = any */
278
279 extern void vnc_prefix_list_update(struct bgp *bgp);
280
281 extern void vnc_routemap_update(struct bgp *bgp, const char *unused);
282
283 extern void bgp_rfapi_show_summary(struct bgp *bgp, struct vty *vty);
284
285 extern struct rfapi_cfg *bgp_rfapi_get_config(struct bgp *bgp);
286
287 extern struct rfapi_l2_group_cfg *
288 bgp_rfapi_get_group_by_lni_label(struct bgp *bgp, uint32_t logical_net_id,
289 uint32_t label);
290
291 extern struct ecommunity *
292 bgp_rfapi_get_ecommunity_by_lni_label(struct bgp *bgp, uint32_t is_import,
293 uint32_t logical_net_id,
294 uint32_t label); /* note, 20bit label! */
295
296 extern struct list *
297 bgp_rfapi_get_labellist_by_lni_label(struct bgp *bgp, uint32_t logical_net_id,
298 uint32_t label); /* note, 20bit label! */
299
300 #endif /* ENABLE_BGP_VNC */
301
302 #endif /* _QUAGGA_BGP_RFAPI_CFG_H */