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