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