]>
Commit | Line | Data |
---|---|---|
65efcfce LB |
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 | */ | |
f8b6f499 | 21 | #include "lib/zebra.h" |
65efcfce | 22 | |
f8b6f499 LB |
23 | #include "lib/command.h" |
24 | #include "lib/prefix.h" | |
25 | #include "lib/memory.h" | |
26 | #include "lib/linklist.h" | |
27 | #include "lib/table.h" | |
28 | #include "lib/plist.h" | |
29 | #include "lib/routemap.h" | |
65efcfce LB |
30 | |
31 | #include "bgpd/bgpd.h" | |
32 | #include "bgpd/bgp_attr.h" | |
33 | #include "bgpd/bgp_mplsvpn.h" | |
34 | #include "bgpd/bgp_route.h" | |
35 | ||
36 | #include "bgpd/bgp_ecommunity.h" | |
f8b6f499 LB |
37 | #include "bgpd/rfapi/rfapi.h" |
38 | #include "bgpd/rfapi/bgp_rfapi_cfg.h" | |
39 | #include "bgpd/rfapi/rfapi_backend.h" | |
40 | #include "bgpd/rfapi/rfapi_import.h" | |
41 | #include "bgpd/rfapi/rfapi_private.h" | |
42 | #include "bgpd/rfapi/rfapi_monitor.h" | |
43 | #include "bgpd/rfapi/vnc_zebra.h" | |
44 | #include "bgpd/rfapi/vnc_export_bgp.h" | |
45 | #include "bgpd/rfapi/vnc_export_bgp_p.h" | |
46 | #include "bgpd/rfapi/rfapi_vty.h" | |
47 | #include "bgpd/rfapi/vnc_import_bgp.h" | |
a3b55c25 | 48 | #include "bgpd/rfapi/vnc_debug.h" |
65efcfce LB |
49 | |
50 | #if ENABLE_BGP_VNC | |
51 | ||
52 | #undef BGP_VNC_DEBUG_MATCH_GROUP | |
53 | ||
54 | ||
55 | DEFINE_MGROUP(RFAPI, "rfapi") | |
56 | DEFINE_MTYPE(RFAPI, RFAPI_CFG, "NVE Configuration") | |
57 | DEFINE_MTYPE(RFAPI, RFAPI_GROUP_CFG, "NVE Group Configuration") | |
58 | DEFINE_MTYPE(RFAPI, RFAPI_L2_CFG, "RFAPI L2 Group Configuration") | |
59 | DEFINE_MTYPE(RFAPI, RFAPI_RFP_GROUP_CFG, "RFAPI RFP Group Configuration") | |
60 | DEFINE_MTYPE(RFAPI, RFAPI, "RFAPI Generic") | |
61 | DEFINE_MTYPE(RFAPI, RFAPI_DESC, "RFAPI Descriptor") | |
62 | DEFINE_MTYPE(RFAPI, RFAPI_IMPORTTABLE, "RFAPI Import Table") | |
63 | DEFINE_MTYPE(RFAPI, RFAPI_MONITOR, "RFAPI Monitor VPN") | |
64 | DEFINE_MTYPE(RFAPI, RFAPI_MONITOR_ENCAP, "RFAPI Monitor Encap") | |
65 | DEFINE_MTYPE(RFAPI, RFAPI_NEXTHOP, "RFAPI Next Hop") | |
66 | DEFINE_MTYPE(RFAPI, RFAPI_VN_OPTION, "RFAPI VN Option") | |
67 | DEFINE_MTYPE(RFAPI, RFAPI_UN_OPTION, "RFAPI UN Option") | |
68 | DEFINE_MTYPE(RFAPI, RFAPI_WITHDRAW, "RFAPI Withdraw") | |
69 | DEFINE_MTYPE(RFAPI, RFAPI_RFG_NAME, "RFAPI RFGName") | |
70 | DEFINE_MTYPE(RFAPI, RFAPI_ADB, "RFAPI Advertisement Data") | |
71 | DEFINE_MTYPE(RFAPI, RFAPI_ETI, "RFAPI Export Table Info") | |
72 | DEFINE_MTYPE(RFAPI, RFAPI_NVE_ADDR, "RFAPI NVE Address") | |
73 | DEFINE_MTYPE(RFAPI, RFAPI_PREFIX_BAG, "RFAPI Prefix Bag") | |
74 | DEFINE_MTYPE(RFAPI, RFAPI_IT_EXTRA, "RFAPI IT Extra") | |
75 | DEFINE_MTYPE(RFAPI, RFAPI_INFO, "RFAPI Info") | |
76 | DEFINE_MTYPE(RFAPI, RFAPI_ADDR, "RFAPI Addr") | |
77 | DEFINE_MTYPE(RFAPI, RFAPI_UPDATED_RESPONSE_QUEUE, "RFAPI Updated Rsp Queue") | |
78 | DEFINE_MTYPE(RFAPI, RFAPI_RECENT_DELETE, "RFAPI Recently Deleted Route") | |
79 | DEFINE_MTYPE(RFAPI, RFAPI_L2ADDR_OPT, "RFAPI L2 Address Option") | |
80 | DEFINE_MTYPE(RFAPI, RFAPI_AP, "RFAPI Advertised Prefix") | |
81 | DEFINE_MTYPE(RFAPI, RFAPI_MONITOR_ETH, "RFAPI Monitor Ethernet") | |
82 | ||
c77272a1 DS |
83 | DEFINE_QOBJ_TYPE(rfapi_nve_group_cfg) |
84 | DEFINE_QOBJ_TYPE(rfapi_l2_group_cfg) | |
65efcfce LB |
85 | /*********************************************************************** |
86 | * RFAPI Support | |
87 | ***********************************************************************/ | |
88 | ||
89 | ||
90 | /* | |
91 | * compaitibility to old quagga_time call | |
92 | * time_t value in terms of stabilised absolute time. | |
93 | * replacement for POSIX time() | |
94 | */ | |
95 | time_t | |
96 | rfapi_time (time_t *t) | |
97 | { | |
98 | time_t clock = bgp_clock(); | |
99 | if (t) | |
100 | *t = clock; | |
101 | return clock; | |
102 | } | |
103 | ||
104 | void | |
105 | nve_group_to_nve_list ( | |
106 | struct rfapi_nve_group_cfg *rfg, | |
107 | struct list **nves, | |
108 | uint8_t family) /* AF_INET, AF_INET6 */ | |
109 | { | |
110 | struct listnode *hln; | |
111 | struct rfapi_descriptor *rfd; | |
112 | ||
113 | /* | |
114 | * loop over nves in this grp, add to list | |
115 | */ | |
116 | for (ALL_LIST_ELEMENTS_RO (rfg->nves, hln, rfd)) | |
117 | { | |
118 | if (rfd->vn_addr.addr_family == family) | |
119 | { | |
120 | if (!*nves) | |
121 | *nves = list_new (); | |
122 | listnode_add (*nves, rfd); | |
123 | } | |
124 | } | |
125 | } | |
126 | ||
127 | ||
128 | struct rfapi_nve_group_cfg * | |
129 | bgp_rfapi_cfg_match_group ( | |
130 | struct rfapi_cfg *hc, | |
131 | struct prefix *vn, | |
132 | struct prefix *un) | |
133 | { | |
134 | struct rfapi_nve_group_cfg *rfg_vn = NULL; | |
135 | struct rfapi_nve_group_cfg *rfg_un = NULL; | |
136 | ||
137 | struct route_table *rt_vn; | |
138 | struct route_table *rt_un; | |
139 | struct route_node *rn_vn; | |
140 | struct route_node *rn_un; | |
141 | ||
142 | struct rfapi_nve_group_cfg *rfg; | |
143 | struct listnode *node, *nnode; | |
144 | ||
145 | switch (vn->family) | |
146 | { | |
147 | case AF_INET: | |
148 | rt_vn = &(hc->nve_groups_vn[AFI_IP]); | |
149 | break; | |
150 | case AF_INET6: | |
151 | rt_vn = &(hc->nve_groups_vn[AFI_IP6]); | |
152 | break; | |
153 | default: | |
154 | return NULL; | |
155 | } | |
156 | ||
157 | switch (un->family) | |
158 | { | |
159 | case AF_INET: | |
160 | rt_un = &(hc->nve_groups_un[AFI_IP]); | |
161 | break; | |
162 | case AF_INET6: | |
163 | rt_un = &(hc->nve_groups_un[AFI_IP6]); | |
164 | break; | |
165 | default: | |
166 | return NULL; | |
167 | } | |
168 | ||
169 | rn_vn = route_node_match (rt_vn, vn); /* NB locks node */ | |
170 | if (rn_vn) | |
171 | { | |
172 | rfg_vn = rn_vn->info; | |
173 | route_unlock_node (rn_vn); | |
174 | } | |
175 | ||
176 | rn_un = route_node_match (rt_un, un); /* NB locks node */ | |
177 | if (rn_un) | |
178 | { | |
179 | rfg_un = rn_un->info; | |
180 | route_unlock_node (rn_un); | |
181 | } | |
182 | ||
183 | #if BGP_VNC_DEBUG_MATCH_GROUP | |
184 | { | |
185 | char buf[BUFSIZ]; | |
186 | ||
187 | prefix2str (vn, buf, BUFSIZ); | |
a3b55c25 | 188 | vnc_zlog_debug_verbose ("%s: vn prefix: %s", __func__, buf); |
65efcfce LB |
189 | |
190 | prefix2str (un, buf, BUFSIZ); | |
a3b55c25 | 191 | vnc_zlog_debug_verbose ("%s: un prefix: %s", __func__, buf); |
65efcfce | 192 | |
a3b55c25 | 193 | vnc_zlog_debug_verbose ("%s: rn_vn=%p, rn_un=%p, rfg_vn=%p, rfg_un=%p", |
65efcfce LB |
194 | __func__, rn_vn, rn_un, rfg_vn, rfg_un); |
195 | } | |
196 | #endif | |
197 | ||
198 | ||
199 | if (rfg_un == rfg_vn) /* same group */ | |
200 | return rfg_un; | |
201 | if (!rfg_un) /* un doesn't match, return vn-matched grp */ | |
202 | return rfg_vn; | |
203 | if (!rfg_vn) /* vn doesn't match, return un-matched grp */ | |
204 | return rfg_un; | |
205 | ||
206 | /* | |
207 | * Two different nve groups match: the group configured earlier wins. | |
208 | * For now, just walk the sequential list and pick the first one. | |
209 | * If this approach is too slow, then store serial numbers in the | |
210 | * nve group structures as they are defined and just compare | |
211 | * serial numbers. | |
212 | */ | |
213 | for (ALL_LIST_ELEMENTS (hc->nve_groups_sequential, node, nnode, rfg)) | |
214 | { | |
215 | if ((rfg == rfg_un) || (rfg == rfg_vn)) | |
216 | { | |
217 | return rfg; | |
218 | } | |
219 | } | |
a3b55c25 | 220 | vnc_zlog_debug_verbose ("%s: shouldn't happen, returning NULL when un and vn match", |
65efcfce LB |
221 | __func__); |
222 | return NULL; /* shouldn't happen */ | |
223 | } | |
224 | ||
225 | /*------------------------------------------ | |
226 | * rfapi_get_rfp_start_val | |
227 | * | |
228 | * Returns value passed to rfapi on rfp_start | |
229 | * | |
230 | * input: | |
231 | * void * bgp structure | |
232 | * | |
233 | * returns: | |
234 | * void * | |
235 | *------------------------------------------*/ | |
236 | void * | |
237 | rfapi_get_rfp_start_val (void *bgpv) | |
238 | { | |
239 | struct bgp *bgp = bgpv; | |
240 | if (bgp == NULL || bgp->rfapi == NULL) | |
241 | return NULL; | |
242 | return bgp->rfapi->rfp; | |
243 | } | |
244 | ||
245 | /*------------------------------------------ | |
246 | * bgp_rfapi_is_vnc_configured | |
247 | * | |
248 | * Returns if VNC (BGP VPN messaging /VPN & encap SAFIs) are configured | |
249 | * | |
250 | * input: | |
251 | * bgp NULL (=use default instance) | |
252 | * | |
253 | * output: | |
254 | * | |
255 | * return value: If VNC is configured for the bgpd instance | |
256 | * 0 Success | |
257 | * ENXIO VNC not configured | |
258 | --------------------------------------------*/ | |
259 | int | |
260 | bgp_rfapi_is_vnc_configured (struct bgp *bgp) | |
261 | { | |
262 | if (bgp == NULL) | |
263 | bgp = bgp_get_default (); | |
264 | ||
265 | if (bgp && bgp->rfapi_cfg) | |
266 | { | |
267 | struct peer *peer; | |
268 | struct peer_group *group; | |
269 | struct listnode *node, *nnode; | |
270 | /* if have configured VPN neighbors, assume running VNC */ | |
271 | for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group)) | |
272 | { | |
273 | if (group->conf->afc[AFI_IP][SAFI_MPLS_VPN] || | |
274 | group->conf->afc[AFI_IP6][SAFI_MPLS_VPN]) | |
275 | return 0; | |
276 | } | |
277 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) | |
278 | { | |
279 | if (peer->afc[AFI_IP][SAFI_MPLS_VPN] || | |
280 | peer->afc[AFI_IP6][SAFI_MPLS_VPN]) | |
281 | return 0; | |
282 | } | |
283 | } | |
284 | return ENXIO; | |
285 | } | |
286 | ||
287 | /*********************************************************************** | |
288 | * VNC Configuration/CLI | |
289 | ***********************************************************************/ | |
290 | ||
291 | ||
292 | DEFUN (vnc_advertise_un_method, | |
293 | vnc_advertise_un_method_cmd, | |
034d2de2 | 294 | "vnc advertise-un-method <encap-safi|encap-attr>", |
65efcfce LB |
295 | VNC_CONFIG_STR |
296 | "Method of advertising UN addresses\n" | |
297 | "Via Encapsulation SAFI\n" | |
298 | "Via Tunnel Encap attribute (in VPN SAFI)\n") | |
299 | { | |
cdc2d765 | 300 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 301 | |
65efcfce LB |
302 | if (!bgp->rfapi_cfg) |
303 | { | |
304 | vty_out (vty, "VNC not configured%s", VTY_NEWLINE); | |
305 | return CMD_WARNING; | |
306 | } | |
307 | ||
308 | ||
aed3273f | 309 | if (!strncmp (argv[2]->arg, "encap-safi", 7)) |
65efcfce LB |
310 | { |
311 | bgp->rfapi_cfg->flags |= BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP; | |
312 | } | |
313 | else | |
314 | { | |
315 | bgp->rfapi_cfg->flags &= ~BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP; | |
316 | } | |
317 | ||
318 | return CMD_SUCCESS; | |
319 | } | |
320 | ||
321 | /*------------------------------------------------------------------------- | |
322 | * RFG defaults | |
323 | *-----------------------------------------------------------------------*/ | |
324 | ||
325 | ||
326 | DEFUN (vnc_defaults, | |
327 | vnc_defaults_cmd, | |
328 | "vnc defaults", VNC_CONFIG_STR "Configure default NVE group\n") | |
329 | { | |
330 | vty->node = BGP_VNC_DEFAULTS_NODE; | |
331 | return CMD_SUCCESS; | |
332 | } | |
333 | ||
334 | static int | |
335 | set_ecom_list ( | |
336 | struct vty *vty, | |
337 | int argc, | |
aed3273f | 338 | struct cmd_token **argv, |
65efcfce LB |
339 | struct ecommunity **list) |
340 | { | |
341 | struct ecommunity *ecom = NULL; | |
342 | struct ecommunity *ecomadd; | |
343 | ||
344 | for (; argc; --argc, ++argv) | |
345 | { | |
346 | ||
aed3273f | 347 | ecomadd = ecommunity_str2com (argv[0]->arg, ECOMMUNITY_ROUTE_TARGET, 0); |
65efcfce LB |
348 | if (!ecomadd) |
349 | { | |
350 | vty_out (vty, "Malformed community-list value%s", VTY_NEWLINE); | |
351 | if (ecom) | |
352 | ecommunity_free (&ecom); | |
353 | return CMD_WARNING; | |
354 | } | |
355 | ||
356 | if (ecom) | |
357 | { | |
358 | ecommunity_merge (ecom, ecomadd); | |
359 | ecommunity_free (&ecomadd); | |
360 | } | |
361 | else | |
362 | { | |
363 | ecom = ecomadd; | |
364 | } | |
365 | } | |
366 | ||
367 | if (*list) | |
368 | { | |
369 | ecommunity_free (&*list); | |
370 | } | |
371 | *list = ecom; | |
372 | ||
373 | return CMD_SUCCESS; | |
374 | } | |
375 | ||
376 | DEFUN (vnc_defaults_rt_import, | |
377 | vnc_defaults_rt_import_cmd, | |
bdffbcef | 378 | "rt import RTLIST", |
65efcfce LB |
379 | "Specify default route targets\n" |
380 | "Import filter\n" | |
381 | "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n") | |
382 | { | |
cdc2d765 | 383 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
aed3273f | 384 | return set_ecom_list (vty, argc - 2, argv + 2, |
65efcfce LB |
385 | &bgp->rfapi_cfg->default_rt_import_list); |
386 | } | |
387 | ||
388 | DEFUN (vnc_defaults_rt_export, | |
389 | vnc_defaults_rt_export_cmd, | |
bdffbcef | 390 | "rt export RTLIST", |
65efcfce LB |
391 | "Configure default route targets\n" |
392 | "Export filter\n" | |
393 | "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n") | |
394 | { | |
cdc2d765 | 395 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
aed3273f | 396 | return set_ecom_list (vty, argc - 2, argv + 2, |
65efcfce LB |
397 | &bgp->rfapi_cfg->default_rt_export_list); |
398 | } | |
399 | ||
400 | DEFUN (vnc_defaults_rt_both, | |
401 | vnc_defaults_rt_both_cmd, | |
bdffbcef | 402 | "rt both RTLIST", |
65efcfce LB |
403 | "Configure default route targets\n" |
404 | "Export+import filters\n" | |
405 | "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n") | |
406 | { | |
cdc2d765 | 407 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 408 | int rc; |
65efcfce | 409 | |
aed3273f DL |
410 | rc = set_ecom_list (vty, argc - 2, argv + 2, |
411 | &bgp->rfapi_cfg->default_rt_import_list); | |
65efcfce LB |
412 | if (rc != CMD_SUCCESS) |
413 | return rc; | |
aed3273f | 414 | return set_ecom_list (vty, argc - 2, argv + 2, |
65efcfce LB |
415 | &bgp->rfapi_cfg->default_rt_export_list); |
416 | } | |
417 | ||
418 | DEFUN (vnc_defaults_rd, | |
419 | vnc_defaults_rd_cmd, | |
420 | "rd ASN:nn_or_IP-address:nn", | |
421 | "Specify default route distinguisher\n" | |
422 | "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:vn:<number> )\n") | |
423 | { | |
cdc2d765 | 424 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
425 | int ret; |
426 | struct prefix_rd prd; | |
65efcfce | 427 | |
aed3273f | 428 | if (!strncmp (argv[1]->arg, "auto:vn:", 8)) |
65efcfce LB |
429 | { |
430 | /* | |
431 | * use AF_UNIX to designate automatically-assigned RD | |
432 | * auto:vn:nn where nn is a 2-octet quantity | |
433 | */ | |
434 | char *end = NULL; | |
aed3273f | 435 | uint32_t value32 = strtoul (argv[1]->arg + 8, &end, 10); |
65efcfce LB |
436 | uint16_t value = value32 & 0xffff; |
437 | ||
aed3273f | 438 | if (!argv[1]->arg[8] || *end) |
65efcfce LB |
439 | { |
440 | vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE); | |
441 | return CMD_WARNING; | |
442 | } | |
443 | if (value32 > 0xffff) | |
444 | { | |
445 | vty_out (vty, "%% Malformed rd (must be less than %u%s", | |
446 | 0x0ffff, VTY_NEWLINE); | |
447 | return CMD_WARNING; | |
448 | } | |
449 | ||
450 | memset (&prd, 0, sizeof (prd)); | |
451 | prd.family = AF_UNIX; | |
452 | prd.prefixlen = 64; | |
453 | prd.val[0] = (RD_TYPE_IP >> 8) & 0x0ff; | |
454 | prd.val[1] = RD_TYPE_IP & 0x0ff; | |
455 | prd.val[6] = (value >> 8) & 0x0ff; | |
456 | prd.val[7] = value & 0x0ff; | |
457 | ||
458 | } | |
459 | else | |
460 | { | |
461 | ||
aed3273f | 462 | ret = str2prefix_rd (argv[1]->arg, &prd); |
65efcfce LB |
463 | if (!ret) |
464 | { | |
465 | vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE); | |
466 | return CMD_WARNING; | |
467 | } | |
468 | } | |
469 | ||
470 | bgp->rfapi_cfg->default_rd = prd; | |
471 | return CMD_SUCCESS; | |
472 | } | |
473 | ||
474 | DEFUN (vnc_defaults_l2rd, | |
475 | vnc_defaults_l2rd_cmd, | |
bdffbcef | 476 | "l2rd <(1-255)|auto-vn>", |
65efcfce LB |
477 | "Specify default Local Nve ID value to use in RD for L2 routes\n" |
478 | "Fixed value 1-255\n" | |
479 | "use the low-order octet of the NVE's VN address\n") | |
480 | { | |
cdc2d765 | 481 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
482 | uint8_t value = 0; |
483 | ||
bdffbcef | 484 | if (!strcmp (argv[1]->arg, "auto-vn")) |
65efcfce LB |
485 | { |
486 | value = 0; | |
487 | } | |
488 | else | |
489 | { | |
490 | char *end = NULL; | |
aed3273f | 491 | unsigned long value_l = strtoul (argv[1]->arg, &end, 10); |
65efcfce LB |
492 | |
493 | value = value_l & 0xff; | |
aed3273f | 494 | if (!argv[1]->arg[0] || *end) |
65efcfce | 495 | { |
aed3273f | 496 | vty_out (vty, "%% Malformed l2 nve ID \"%s\"%s", argv[1]->arg, |
65efcfce LB |
497 | VTY_NEWLINE); |
498 | return CMD_WARNING; | |
499 | } | |
500 | if ((value_l < 1) || (value_l > 0xff)) | |
501 | { | |
502 | vty_out (vty, | |
503 | "%% Malformed l2 nve id (must be greater than 0 and less than %u%s", | |
504 | 0x100, VTY_NEWLINE); | |
505 | return CMD_WARNING; | |
506 | } | |
507 | } | |
508 | bgp->rfapi_cfg->flags |= BGP_VNC_CONFIG_L2RD; | |
509 | bgp->rfapi_cfg->default_l2rd = value; | |
510 | ||
511 | return CMD_SUCCESS; | |
512 | } | |
513 | ||
514 | DEFUN (vnc_defaults_no_l2rd, | |
515 | vnc_defaults_no_l2rd_cmd, | |
516 | "no l2rd", | |
517 | NO_STR | |
518 | "Specify default Local Nve ID value to use in RD for L2 routes\n") | |
519 | { | |
cdc2d765 | 520 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 521 | |
65efcfce LB |
522 | bgp->rfapi_cfg->default_l2rd = 0; |
523 | bgp->rfapi_cfg->flags &= ~BGP_VNC_CONFIG_L2RD; | |
524 | ||
525 | return CMD_SUCCESS; | |
526 | } | |
527 | ||
528 | DEFUN (vnc_defaults_responselifetime, | |
529 | vnc_defaults_responselifetime_cmd, | |
034d2de2 | 530 | "response-lifetime <LIFETIME|infinite>", |
65efcfce LB |
531 | "Specify default response lifetime\n" |
532 | "Response lifetime in seconds\n" "Infinite response lifetime\n") | |
533 | { | |
cdc2d765 | 534 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 535 | uint32_t rspint; |
65efcfce LB |
536 | struct rfapi *h = NULL; |
537 | struct listnode *hdnode; | |
538 | struct rfapi_descriptor *rfd; | |
539 | ||
65efcfce LB |
540 | h = bgp->rfapi; |
541 | if (!h) | |
542 | return CMD_WARNING; | |
543 | ||
aed3273f | 544 | if (!strcmp (argv[1]->arg, "infinite")) |
65efcfce LB |
545 | { |
546 | rspint = RFAPI_INFINITE_LIFETIME; | |
547 | } | |
548 | else | |
549 | { | |
aed3273f | 550 | VTY_GET_INTEGER ("Response Lifetime", rspint, argv[1]->arg); |
65efcfce LB |
551 | if (rspint > INT32_MAX) |
552 | rspint = INT32_MAX; /* is really an int, not an unsigned int */ | |
553 | } | |
554 | ||
555 | bgp->rfapi_cfg->default_response_lifetime = rspint; | |
556 | ||
557 | for (ALL_LIST_ELEMENTS_RO (&h->descriptors, hdnode, rfd)) | |
558 | if (rfd->rfg && !(rfd->rfg->flags & RFAPI_RFG_RESPONSE_LIFETIME)) | |
559 | rfd->response_lifetime = rfd->rfg->response_lifetime = rspint; | |
560 | ||
561 | return CMD_SUCCESS; | |
562 | } | |
563 | ||
564 | static struct rfapi_nve_group_cfg * | |
565 | rfapi_group_lookup_byname (struct bgp *bgp, const char *name) | |
566 | { | |
567 | struct rfapi_nve_group_cfg *rfg; | |
568 | struct listnode *node, *nnode; | |
569 | ||
570 | for (ALL_LIST_ELEMENTS | |
571 | (bgp->rfapi_cfg->nve_groups_sequential, node, nnode, rfg)) | |
572 | { | |
573 | if (!strcmp (rfg->name, name)) | |
574 | return rfg; | |
575 | } | |
576 | return NULL; | |
577 | } | |
578 | ||
579 | static struct rfapi_nve_group_cfg * | |
580 | rfapi_group_new () | |
581 | { | |
ea8a9825 DS |
582 | struct rfapi_nve_group_cfg *rfg; |
583 | ||
584 | rfg = XCALLOC (MTYPE_RFAPI_GROUP_CFG, sizeof (struct rfapi_nve_group_cfg)); | |
585 | QOBJ_REG (rfg, rfapi_nve_group_cfg); | |
586 | ||
587 | return rfg; | |
65efcfce LB |
588 | } |
589 | ||
590 | static struct rfapi_l2_group_cfg * | |
591 | rfapi_l2_group_lookup_byname (struct bgp *bgp, const char *name) | |
592 | { | |
593 | struct rfapi_l2_group_cfg *rfg; | |
594 | struct listnode *node, *nnode; | |
595 | ||
596 | if (bgp->rfapi_cfg->l2_groups == NULL) /* not the best place for this */ | |
597 | bgp->rfapi_cfg->l2_groups = list_new (); | |
598 | ||
599 | for (ALL_LIST_ELEMENTS (bgp->rfapi_cfg->l2_groups, node, nnode, rfg)) | |
600 | { | |
601 | if (!strcmp (rfg->name, name)) | |
602 | return rfg; | |
603 | } | |
604 | return NULL; | |
605 | } | |
606 | ||
607 | static struct rfapi_l2_group_cfg * | |
608 | rfapi_l2_group_new () | |
609 | { | |
ea8a9825 DS |
610 | struct rfapi_l2_group_cfg *rfg; |
611 | ||
612 | rfg = XCALLOC (MTYPE_RFAPI_L2_CFG, sizeof (struct rfapi_l2_group_cfg)); | |
613 | QOBJ_REG (rfg, rfapi_l2_group_cfg); | |
614 | ||
615 | return rfg; | |
65efcfce LB |
616 | } |
617 | ||
618 | static void | |
619 | rfapi_l2_group_del (struct rfapi_l2_group_cfg *rfg) | |
620 | { | |
ea8a9825 | 621 | QOBJ_UNREG (rfg); |
65efcfce LB |
622 | XFREE (MTYPE_RFAPI_L2_CFG, rfg); |
623 | } | |
624 | ||
625 | static int | |
626 | rfapi_str2route_type ( | |
627 | const char *l3str, | |
628 | const char *pstr, | |
629 | afi_t *afi, | |
630 | int *type) | |
631 | { | |
632 | if (!l3str || !pstr) | |
633 | return EINVAL; | |
634 | ||
635 | if (!strcmp (l3str, "ipv4")) | |
636 | { | |
637 | *afi = AFI_IP; | |
638 | } | |
639 | else | |
640 | { | |
641 | if (!strcmp (l3str, "ipv6")) | |
642 | *afi = AFI_IP6; | |
643 | else | |
644 | return ENOENT; | |
645 | } | |
646 | ||
647 | if (!strcmp (pstr, "connected")) | |
648 | *type = ZEBRA_ROUTE_CONNECT; | |
649 | if (!strcmp (pstr, "kernel")) | |
650 | *type = ZEBRA_ROUTE_KERNEL; | |
651 | if (!strcmp (pstr, "static")) | |
652 | *type = ZEBRA_ROUTE_STATIC; | |
653 | if (!strcmp (pstr, "bgp")) | |
654 | *type = ZEBRA_ROUTE_BGP; | |
655 | if (!strcmp (pstr, "bgp-direct")) | |
656 | *type = ZEBRA_ROUTE_BGP_DIRECT; | |
657 | if (!strcmp (pstr, "bgp-direct-to-nve-groups")) | |
658 | *type = ZEBRA_ROUTE_BGP_DIRECT_EXT; | |
659 | ||
660 | if (!strcmp (pstr, "rip")) | |
661 | { | |
662 | if (*afi == AFI_IP) | |
663 | *type = ZEBRA_ROUTE_RIP; | |
664 | else | |
665 | *type = ZEBRA_ROUTE_RIPNG; | |
666 | } | |
667 | ||
668 | if (!strcmp (pstr, "ripng")) | |
669 | { | |
670 | if (*afi == AFI_IP) | |
671 | return EAFNOSUPPORT; | |
672 | *type = ZEBRA_ROUTE_RIPNG; | |
673 | } | |
674 | ||
675 | if (!strcmp (pstr, "ospf")) | |
676 | { | |
677 | if (*afi == AFI_IP) | |
678 | *type = ZEBRA_ROUTE_OSPF; | |
679 | else | |
680 | *type = ZEBRA_ROUTE_OSPF6; | |
681 | } | |
682 | ||
683 | if (!strcmp (pstr, "ospf6")) | |
684 | { | |
685 | if (*afi == AFI_IP) | |
686 | return EAFNOSUPPORT; | |
687 | *type = ZEBRA_ROUTE_OSPF6; | |
688 | } | |
689 | ||
690 | return 0; | |
691 | } | |
692 | ||
693 | /*------------------------------------------------------------------------- | |
694 | * redistribute | |
695 | *-----------------------------------------------------------------------*/ | |
696 | ||
697 | #define VNC_REDIST_ENABLE(bgp, afi, type) do { \ | |
698 | switch (type) { \ | |
699 | case ZEBRA_ROUTE_BGP_DIRECT: \ | |
700 | vnc_import_bgp_redist_enable((bgp), (afi)); \ | |
701 | break; \ | |
702 | case ZEBRA_ROUTE_BGP_DIRECT_EXT: \ | |
703 | vnc_import_bgp_exterior_redist_enable((bgp), (afi));\ | |
704 | break; \ | |
705 | default: \ | |
706 | vnc_redistribute_set((bgp), (afi), (type)); \ | |
707 | break; \ | |
708 | } \ | |
709 | } while (0) | |
710 | ||
711 | #define VNC_REDIST_DISABLE(bgp, afi, type) do { \ | |
712 | switch (type) { \ | |
713 | case ZEBRA_ROUTE_BGP_DIRECT: \ | |
714 | vnc_import_bgp_redist_disable((bgp), (afi)); \ | |
715 | break; \ | |
716 | case ZEBRA_ROUTE_BGP_DIRECT_EXT: \ | |
717 | vnc_import_bgp_exterior_redist_disable((bgp), (afi));\ | |
718 | break; \ | |
719 | default: \ | |
720 | vnc_redistribute_unset((bgp), (afi), (type)); \ | |
721 | break; \ | |
722 | } \ | |
723 | } while (0) | |
724 | ||
725 | static uint8_t redist_was_enabled[AFI_MAX][ZEBRA_ROUTE_MAX]; | |
726 | ||
727 | static void | |
728 | vnc_redistribute_prechange (struct bgp *bgp) | |
729 | { | |
730 | afi_t afi; | |
731 | int type; | |
732 | ||
a3b55c25 | 733 | vnc_zlog_debug_verbose ("%s: entry", __func__); |
65efcfce LB |
734 | memset (redist_was_enabled, 0, sizeof (redist_was_enabled)); |
735 | ||
736 | /* | |
737 | * Look to see if we have any redistribution enabled. If so, flush | |
738 | * the corresponding routes and turn off redistribution temporarily. | |
739 | * We need to do it because the RD's used for the redistributed | |
740 | * routes depend on the nve group. | |
741 | */ | |
742 | for (afi = AFI_IP; afi < AFI_MAX; ++afi) | |
743 | { | |
744 | for (type = 0; type < ZEBRA_ROUTE_MAX; ++type) | |
745 | { | |
746 | if (bgp->rfapi_cfg->redist[afi][type]) | |
747 | { | |
748 | redist_was_enabled[afi][type] = 1; | |
749 | VNC_REDIST_DISABLE (bgp, afi, type); | |
750 | } | |
751 | } | |
752 | } | |
a3b55c25 | 753 | vnc_zlog_debug_verbose ("%s: return", __func__); |
65efcfce LB |
754 | } |
755 | ||
756 | static void | |
757 | vnc_redistribute_postchange (struct bgp *bgp) | |
758 | { | |
759 | afi_t afi; | |
760 | int type; | |
761 | ||
a3b55c25 | 762 | vnc_zlog_debug_verbose ("%s: entry", __func__); |
65efcfce LB |
763 | /* |
764 | * If we turned off redistribution above, turn it back on. Doing so | |
765 | * will tell zebra to resend the routes to us | |
766 | */ | |
767 | for (afi = AFI_IP; afi < AFI_MAX; ++afi) | |
768 | { | |
769 | for (type = 0; type < ZEBRA_ROUTE_MAX; ++type) | |
770 | { | |
771 | if (redist_was_enabled[afi][type]) | |
772 | { | |
773 | VNC_REDIST_ENABLE (bgp, afi, type); | |
774 | } | |
775 | } | |
776 | } | |
a3b55c25 | 777 | vnc_zlog_debug_verbose ("%s: return", __func__); |
65efcfce LB |
778 | } |
779 | ||
780 | DEFUN (vnc_redistribute_rh_roo_localadmin, | |
781 | vnc_redistribute_rh_roo_localadmin_cmd, | |
034d2de2 | 782 | "vnc redistribute resolve-nve roo-ec-local-admin (0-65535)", |
65efcfce LB |
783 | VNC_CONFIG_STR |
784 | "Redistribute routes into VNC\n" | |
785 | "Resolve-NVE mode\n" | |
786 | "Route Origin Extended Community Local Admin Field\n" "Field value\n") | |
787 | { | |
cdc2d765 | 788 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
789 | uint32_t localadmin; |
790 | char *endptr; | |
791 | ||
65efcfce LB |
792 | if (!bgp->rfapi_cfg) |
793 | { | |
794 | vty_out (vty, "RFAPI not configured%s", VTY_NEWLINE); | |
795 | return CMD_WARNING; | |
796 | } | |
797 | ||
aed3273f DL |
798 | localadmin = strtoul (argv[4]->arg, &endptr, 0); |
799 | if (!argv[4]->arg[0] || *endptr) | |
65efcfce LB |
800 | { |
801 | vty_out (vty, "%% Malformed value%s", VTY_NEWLINE); | |
802 | return CMD_WARNING; | |
803 | } | |
804 | ||
805 | if (localadmin > 0xffff) | |
806 | { | |
807 | vty_out (vty, "%% Value out of range (0-%d)%s", 0xffff, VTY_NEWLINE); | |
808 | return CMD_WARNING; | |
809 | } | |
810 | ||
811 | if (bgp->rfapi_cfg->resolve_nve_roo_local_admin == localadmin) | |
812 | return CMD_SUCCESS; | |
813 | ||
814 | if ((bgp->rfapi_cfg->flags & BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS) == | |
815 | BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE) | |
816 | { | |
817 | ||
818 | vnc_export_bgp_prechange (bgp); | |
819 | } | |
820 | vnc_redistribute_prechange (bgp); | |
821 | ||
822 | bgp->rfapi_cfg->resolve_nve_roo_local_admin = localadmin; | |
823 | ||
824 | if ((bgp->rfapi_cfg->flags & BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS) == | |
825 | BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE) | |
826 | { | |
827 | ||
828 | vnc_export_bgp_postchange (bgp); | |
829 | } | |
830 | vnc_redistribute_postchange (bgp); | |
831 | ||
832 | return CMD_SUCCESS; | |
833 | } | |
834 | ||
835 | ||
836 | DEFUN (vnc_redistribute_mode, | |
837 | vnc_redistribute_mode_cmd, | |
034d2de2 | 838 | "vnc redistribute mode <nve-group|plain|resolve-nve>", |
65efcfce LB |
839 | VNC_CONFIG_STR |
840 | "Redistribute routes into VNC\n" | |
841 | "Redistribution mode\n" | |
842 | "Based on redistribute nve-group\n" | |
843 | "Unmodified\n" "Resolve each nexthop to connected NVEs\n") | |
844 | { | |
cdc2d765 | 845 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
846 | vnc_redist_mode_t newmode; |
847 | ||
65efcfce LB |
848 | if (!bgp->rfapi_cfg) |
849 | { | |
850 | vty_out (vty, "RFAPI not configured%s", VTY_NEWLINE); | |
851 | return CMD_WARNING; | |
852 | } | |
853 | ||
854 | ||
aed3273f | 855 | switch (argv[3]->arg[0]) |
65efcfce LB |
856 | { |
857 | case 'n': | |
858 | newmode = VNC_REDIST_MODE_RFG; | |
859 | break; | |
860 | ||
861 | case 'p': | |
862 | newmode = VNC_REDIST_MODE_PLAIN; | |
863 | break; | |
864 | ||
865 | case 'r': | |
866 | newmode = VNC_REDIST_MODE_RESOLVE_NVE; | |
867 | break; | |
868 | ||
869 | default: | |
870 | vty_out (vty, "unknown redistribute mode%s", VTY_NEWLINE); | |
871 | return CMD_WARNING; | |
872 | } | |
873 | ||
874 | if (newmode != bgp->rfapi_cfg->redist_mode) | |
875 | { | |
876 | vnc_redistribute_prechange (bgp); | |
877 | bgp->rfapi_cfg->redist_mode = newmode; | |
878 | vnc_redistribute_postchange (bgp); | |
879 | } | |
880 | ||
881 | return CMD_SUCCESS; | |
882 | } | |
883 | ||
884 | DEFUN (vnc_redistribute_protocol, | |
885 | vnc_redistribute_protocol_cmd, | |
034d2de2 | 886 | "vnc redistribute <ipv4|ipv6> <bgp|bgp-direct|bgp-direct-to-nve-groups|connected|kernel|ospf|rip|static>", |
65efcfce LB |
887 | VNC_CONFIG_STR |
888 | "Redistribute routes into VNC\n" | |
889 | "IPv4 routes\n" | |
890 | "IPv6 routes\n" | |
891 | "From BGP\n" | |
892 | "From BGP without Zebra\n" | |
893 | "From BGP without Zebra, only to configured NVE groups\n" | |
894 | "Connected interfaces\n" | |
895 | "From kernel routes\n" | |
896 | "From Open Shortest Path First (OSPF)\n" | |
897 | "From Routing Information Protocol (RIP)\n" "From Static routes\n") | |
898 | { | |
cdc2d765 | 899 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 900 | int type = ZEBRA_ROUTE_MAX; /* init to bogus value */ |
65efcfce LB |
901 | afi_t afi; |
902 | ||
65efcfce LB |
903 | if (!bgp->rfapi_cfg) |
904 | { | |
905 | vty_out (vty, "RFAPI not configured%s", VTY_NEWLINE); | |
906 | return CMD_WARNING; | |
907 | } | |
908 | ||
aed3273f | 909 | if (rfapi_str2route_type (argv[2]->arg, argv[3]->arg, &afi, &type)) |
65efcfce LB |
910 | { |
911 | vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE); | |
912 | return CMD_WARNING; | |
913 | } | |
914 | ||
915 | if (type == ZEBRA_ROUTE_BGP_DIRECT_EXT) | |
916 | { | |
917 | if (bgp->rfapi_cfg->redist_bgp_exterior_view_name) | |
918 | { | |
919 | VNC_REDIST_DISABLE (bgp, afi, type); /* disabled view implicitly */ | |
920 | free (bgp->rfapi_cfg->redist_bgp_exterior_view_name); | |
921 | bgp->rfapi_cfg->redist_bgp_exterior_view_name = NULL; | |
922 | } | |
923 | bgp->rfapi_cfg->redist_bgp_exterior_view = bgp; | |
924 | } | |
925 | ||
926 | VNC_REDIST_ENABLE (bgp, afi, type); | |
927 | ||
928 | return CMD_SUCCESS; | |
929 | } | |
930 | ||
931 | DEFUN (vnc_no_redistribute_protocol, | |
932 | vnc_no_redistribute_protocol_cmd, | |
034d2de2 | 933 | "no vnc redistribute <ipv4|ipv6> <bgp|bgp-direct|bgp-direct-to-nve-groups|connected|kernel|ospf|rip|static>", |
65efcfce LB |
934 | NO_STR |
935 | VNC_CONFIG_STR | |
936 | "Redistribute from other protocol\n" | |
937 | "IPv4 routes\n" | |
938 | "IPv6 routes\n" | |
939 | "From BGP\n" | |
940 | "From BGP without Zebra\n" | |
941 | "From BGP without Zebra, only to configured NVE groups\n" | |
942 | "Connected interfaces\n" | |
943 | "From kernel routes\n" | |
944 | "From Open Shortest Path First (OSPF)\n" | |
945 | "From Routing Information Protocol (RIP)\n" "From Static routes\n") | |
946 | { | |
cdc2d765 | 947 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 948 | int type; |
65efcfce LB |
949 | afi_t afi; |
950 | ||
65efcfce LB |
951 | if (!bgp->rfapi_cfg) |
952 | { | |
953 | vty_out (vty, "RFAPI not configured%s", VTY_NEWLINE); | |
954 | return CMD_WARNING; | |
955 | } | |
956 | ||
aed3273f | 957 | if (rfapi_str2route_type (argv[3]->arg, argv[4]->arg, &afi, &type)) |
65efcfce LB |
958 | { |
959 | vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE); | |
960 | return CMD_WARNING; | |
961 | } | |
962 | ||
963 | VNC_REDIST_DISABLE (bgp, afi, type); | |
964 | ||
965 | if (type == ZEBRA_ROUTE_BGP_DIRECT_EXT) | |
966 | { | |
967 | if (bgp->rfapi_cfg->redist_bgp_exterior_view_name) | |
968 | { | |
969 | free (bgp->rfapi_cfg->redist_bgp_exterior_view_name); | |
970 | bgp->rfapi_cfg->redist_bgp_exterior_view_name = NULL; | |
971 | } | |
972 | bgp->rfapi_cfg->redist_bgp_exterior_view = NULL; | |
973 | } | |
974 | ||
975 | return CMD_SUCCESS; | |
976 | } | |
977 | ||
978 | DEFUN (vnc_redistribute_bgp_exterior, | |
979 | vnc_redistribute_bgp_exterior_cmd, | |
034d2de2 | 980 | "vnc redistribute <ipv4|ipv6> bgp-direct-to-nve-groups view NAME", |
65efcfce LB |
981 | VNC_CONFIG_STR |
982 | "Redistribute routes into VNC\n" | |
983 | "IPv4 routes\n" | |
984 | "IPv6 routes\n" | |
985 | "From BGP without Zebra, only to configured NVE groups\n" | |
986 | "From BGP view\n" "BGP view name\n") | |
987 | { | |
cdc2d765 | 988 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 989 | int type; |
65efcfce LB |
990 | afi_t afi; |
991 | ||
65efcfce LB |
992 | if (!bgp->rfapi_cfg) |
993 | { | |
994 | vty_out (vty, "RFAPI not configured%s", VTY_NEWLINE); | |
995 | return CMD_WARNING; | |
996 | } | |
997 | ||
aed3273f | 998 | if (rfapi_str2route_type (argv[2]->arg, "bgp-direct-to-nve-groups", &afi, &type)) |
65efcfce LB |
999 | { |
1000 | vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE); | |
1001 | return CMD_WARNING; | |
1002 | } | |
1003 | ||
1004 | if (bgp->rfapi_cfg->redist_bgp_exterior_view_name) | |
1005 | free (bgp->rfapi_cfg->redist_bgp_exterior_view_name); | |
aed3273f | 1006 | bgp->rfapi_cfg->redist_bgp_exterior_view_name = strdup (argv[5]->arg); |
65efcfce | 1007 | /* could be NULL if name is not defined yet */ |
aed3273f | 1008 | bgp->rfapi_cfg->redist_bgp_exterior_view = bgp_lookup_by_name (argv[5]->arg); |
65efcfce LB |
1009 | |
1010 | VNC_REDIST_ENABLE (bgp, afi, type); | |
1011 | ||
1012 | return CMD_SUCCESS; | |
1013 | } | |
1014 | ||
1015 | DEFUN (vnc_redistribute_nvegroup, | |
1016 | vnc_redistribute_nvegroup_cmd, | |
1017 | "vnc redistribute nve-group NAME", | |
1018 | VNC_CONFIG_STR | |
1019 | "Assign a NVE group to routes redistributed from another routing protocol\n" | |
1020 | "NVE group\n" "Group name\n") | |
1021 | { | |
cdc2d765 | 1022 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 1023 | |
65efcfce LB |
1024 | if (!bgp->rfapi_cfg) |
1025 | { | |
1026 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1027 | return CMD_WARNING; | |
1028 | } | |
1029 | ||
1030 | vnc_redistribute_prechange (bgp); | |
1031 | ||
1032 | /* | |
1033 | * OK if nve group doesn't exist yet; we'll set the pointer | |
1034 | * when the group is defined later | |
1035 | */ | |
aed3273f | 1036 | bgp->rfapi_cfg->rfg_redist = rfapi_group_lookup_byname (bgp, argv[3]->arg); |
65efcfce LB |
1037 | if (bgp->rfapi_cfg->rfg_redist_name) |
1038 | free (bgp->rfapi_cfg->rfg_redist_name); | |
aed3273f | 1039 | bgp->rfapi_cfg->rfg_redist_name = strdup (argv[3]->arg); |
65efcfce LB |
1040 | |
1041 | vnc_redistribute_postchange (bgp); | |
1042 | ||
1043 | return CMD_SUCCESS; | |
1044 | } | |
1045 | ||
1046 | DEFUN (vnc_redistribute_no_nvegroup, | |
1047 | vnc_redistribute_no_nvegroup_cmd, | |
1048 | "no vnc redistribute nve-group", | |
1049 | NO_STR | |
1050 | VNC_CONFIG_STR | |
1051 | "Redistribute from other protocol\n" | |
1052 | "Assign a NVE group to routes redistributed from another routing protocol\n") | |
1053 | { | |
cdc2d765 | 1054 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 1055 | |
65efcfce LB |
1056 | if (!bgp->rfapi_cfg) |
1057 | { | |
1058 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1059 | return CMD_WARNING; | |
1060 | } | |
1061 | ||
1062 | vnc_redistribute_prechange (bgp); | |
1063 | ||
1064 | bgp->rfapi_cfg->rfg_redist = NULL; | |
1065 | if (bgp->rfapi_cfg->rfg_redist_name) | |
1066 | free (bgp->rfapi_cfg->rfg_redist_name); | |
1067 | bgp->rfapi_cfg->rfg_redist_name = NULL; | |
1068 | ||
1069 | vnc_redistribute_postchange (bgp); | |
1070 | ||
1071 | return CMD_SUCCESS; | |
1072 | } | |
1073 | ||
1074 | ||
1075 | DEFUN (vnc_redistribute_lifetime, | |
1076 | vnc_redistribute_lifetime_cmd, | |
034d2de2 | 1077 | "vnc redistribute lifetime <LIFETIME|infinite>", |
65efcfce | 1078 | VNC_CONFIG_STR |
bdffbcef | 1079 | "Redistribute\n" |
65efcfce | 1080 | "Assign a lifetime to routes redistributed from another routing protocol\n" |
034d2de2 DS |
1081 | "lifetime value (32 bit)\n" |
1082 | "Allow lifetime to never expire\n") | |
65efcfce | 1083 | { |
cdc2d765 | 1084 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 1085 | |
65efcfce LB |
1086 | if (!bgp->rfapi_cfg) |
1087 | { | |
1088 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1089 | return CMD_WARNING; | |
1090 | } | |
1091 | ||
1092 | vnc_redistribute_prechange (bgp); | |
1093 | ||
aed3273f | 1094 | if (!strcmp (argv[3]->arg, "infinite")) |
65efcfce LB |
1095 | { |
1096 | bgp->rfapi_cfg->redist_lifetime = RFAPI_INFINITE_LIFETIME; | |
1097 | } | |
1098 | else | |
1099 | { | |
1100 | VTY_GET_INTEGER ("Response Lifetime", bgp->rfapi_cfg->redist_lifetime, | |
aed3273f | 1101 | argv[3]->arg); |
65efcfce LB |
1102 | } |
1103 | ||
1104 | vnc_redistribute_postchange (bgp); | |
1105 | ||
1106 | return CMD_SUCCESS; | |
1107 | } | |
1108 | ||
1109 | /*-- redist policy, non-nvegroup start --*/ | |
1110 | ||
1111 | DEFUN (vnc_redist_bgpdirect_no_prefixlist, | |
1112 | vnc_redist_bgpdirect_no_prefixlist_cmd, | |
034d2de2 | 1113 | "no vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> <ipv4|ipv6> prefix-list", |
65efcfce LB |
1114 | NO_STR |
1115 | VNC_CONFIG_STR | |
1116 | "Redistribute from other protocol\n" | |
1117 | "Redistribute from BGP directly\n" | |
1118 | "Redistribute from BGP without Zebra, only to configured NVE groups\n" | |
1119 | "IPv4 routes\n" | |
1120 | "IPv6 routes\n" "Prefix-list for filtering redistributed routes\n") | |
1121 | { | |
cdc2d765 | 1122 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
1123 | afi_t afi; |
1124 | struct rfapi_cfg *hc; | |
1125 | uint8_t route_type = 0; | |
1126 | ||
65efcfce LB |
1127 | if (!(hc = bgp->rfapi_cfg)) |
1128 | { | |
1129 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1130 | return CMD_WARNING; | |
1131 | } | |
1132 | ||
aed3273f | 1133 | if (!strcmp (argv[3]->arg, "bgp-direct")) |
65efcfce LB |
1134 | { |
1135 | route_type = ZEBRA_ROUTE_BGP_DIRECT; | |
1136 | } | |
1137 | else | |
1138 | { | |
1139 | route_type = ZEBRA_ROUTE_BGP_DIRECT_EXT; | |
1140 | } | |
1141 | ||
aed3273f | 1142 | if (!strcmp (argv[4]->arg, "ipv4")) |
65efcfce LB |
1143 | { |
1144 | afi = AFI_IP; | |
1145 | } | |
1146 | else | |
1147 | { | |
1148 | afi = AFI_IP6; | |
1149 | } | |
1150 | ||
1151 | vnc_redistribute_prechange (bgp); | |
1152 | ||
1153 | if (hc->plist_redist_name[route_type][afi]) | |
1154 | free (hc->plist_redist_name[route_type][afi]); | |
1155 | hc->plist_redist_name[route_type][afi] = NULL; | |
1156 | hc->plist_redist[route_type][afi] = NULL; | |
1157 | ||
1158 | vnc_redistribute_postchange (bgp); | |
1159 | ||
1160 | return CMD_SUCCESS; | |
1161 | } | |
1162 | ||
1163 | DEFUN (vnc_redist_bgpdirect_prefixlist, | |
1164 | vnc_redist_bgpdirect_prefixlist_cmd, | |
034d2de2 | 1165 | "vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> <ipv4|ipv6> prefix-list NAME", |
65efcfce LB |
1166 | VNC_CONFIG_STR |
1167 | "Redistribute from other protocol\n" | |
1168 | "Redistribute from BGP directly\n" | |
1169 | "Redistribute from BGP without Zebra, only to configured NVE groups\n" | |
1170 | "IPv4 routes\n" | |
1171 | "IPv6 routes\n" | |
1172 | "Prefix-list for filtering redistributed routes\n" | |
1173 | "prefix list name\n") | |
1174 | { | |
cdc2d765 | 1175 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
1176 | struct rfapi_cfg *hc; |
1177 | afi_t afi; | |
1178 | uint8_t route_type = 0; | |
1179 | ||
65efcfce LB |
1180 | if (!(hc = bgp->rfapi_cfg)) |
1181 | { | |
1182 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1183 | return CMD_WARNING; | |
1184 | } | |
1185 | ||
aed3273f | 1186 | if (!strcmp (argv[2]->arg, "bgp-direct")) |
65efcfce LB |
1187 | { |
1188 | route_type = ZEBRA_ROUTE_BGP_DIRECT; | |
1189 | } | |
1190 | else | |
1191 | { | |
1192 | route_type = ZEBRA_ROUTE_BGP_DIRECT_EXT; | |
1193 | } | |
1194 | ||
aed3273f | 1195 | if (!strcmp (argv[3]->arg, "ipv4")) |
65efcfce LB |
1196 | { |
1197 | afi = AFI_IP; | |
1198 | } | |
1199 | else | |
1200 | { | |
1201 | afi = AFI_IP6; | |
1202 | } | |
1203 | ||
1204 | vnc_redistribute_prechange (bgp); | |
1205 | ||
1206 | if (hc->plist_redist_name[route_type][afi]) | |
1207 | free (hc->plist_redist_name[route_type][afi]); | |
aed3273f DL |
1208 | hc->plist_redist_name[route_type][afi] = strdup (argv[5]->arg); |
1209 | hc->plist_redist[route_type][afi] = prefix_list_lookup (afi, argv[5]->arg); | |
65efcfce LB |
1210 | |
1211 | vnc_redistribute_postchange (bgp); | |
1212 | ||
1213 | return CMD_SUCCESS; | |
1214 | } | |
1215 | ||
1216 | DEFUN (vnc_redist_bgpdirect_no_routemap, | |
1217 | vnc_redist_bgpdirect_no_routemap_cmd, | |
034d2de2 | 1218 | "no vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> route-map", |
65efcfce LB |
1219 | NO_STR |
1220 | VNC_CONFIG_STR | |
1221 | "Redistribute from other protocols\n" | |
1222 | "Redistribute from BGP directly\n" | |
1223 | "Redistribute from BGP without Zebra, only to configured NVE groups\n" | |
1224 | "Route-map for filtering redistributed routes\n") | |
1225 | { | |
cdc2d765 | 1226 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
1227 | struct rfapi_cfg *hc; |
1228 | uint8_t route_type = 0; | |
1229 | ||
65efcfce LB |
1230 | if (!(hc = bgp->rfapi_cfg)) |
1231 | { | |
1232 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1233 | return CMD_WARNING; | |
1234 | } | |
1235 | ||
aed3273f | 1236 | if (!strcmp (argv[3]->arg, "bgp-direct")) |
65efcfce LB |
1237 | { |
1238 | route_type = ZEBRA_ROUTE_BGP_DIRECT; | |
1239 | } | |
1240 | else | |
1241 | { | |
1242 | route_type = ZEBRA_ROUTE_BGP_DIRECT_EXT; | |
1243 | } | |
1244 | ||
1245 | vnc_redistribute_prechange (bgp); | |
1246 | ||
1247 | if (hc->routemap_redist_name[route_type]) | |
1248 | free (hc->routemap_redist_name[route_type]); | |
1249 | hc->routemap_redist_name[route_type] = NULL; | |
1250 | hc->routemap_redist[route_type] = NULL; | |
1251 | ||
1252 | vnc_redistribute_postchange (bgp); | |
1253 | ||
1254 | return CMD_SUCCESS; | |
1255 | } | |
1256 | ||
1257 | DEFUN (vnc_redist_bgpdirect_routemap, | |
1258 | vnc_redist_bgpdirect_routemap_cmd, | |
034d2de2 | 1259 | "vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> route-map NAME", |
65efcfce LB |
1260 | VNC_CONFIG_STR |
1261 | "Redistribute from other protocols\n" | |
1262 | "Redistribute from BGP directly\n" | |
1263 | "Redistribute from BGP without Zebra, only to configured NVE groups\n" | |
1264 | "Route-map for filtering exported routes\n" "route map name\n") | |
1265 | { | |
cdc2d765 | 1266 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
1267 | struct rfapi_cfg *hc; |
1268 | uint8_t route_type = 0; | |
1269 | ||
65efcfce LB |
1270 | if (!(hc = bgp->rfapi_cfg)) |
1271 | { | |
1272 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1273 | return CMD_WARNING; | |
1274 | } | |
1275 | ||
aed3273f | 1276 | if (!strcmp (argv[2]->arg, "bgp-direct")) |
65efcfce LB |
1277 | { |
1278 | route_type = ZEBRA_ROUTE_BGP_DIRECT; | |
1279 | } | |
1280 | else | |
1281 | { | |
1282 | route_type = ZEBRA_ROUTE_BGP_DIRECT_EXT; | |
1283 | } | |
1284 | ||
1285 | vnc_redistribute_prechange (bgp); | |
1286 | ||
1287 | if (hc->routemap_redist_name[route_type]) | |
1288 | free (hc->routemap_redist_name[route_type]); | |
aed3273f DL |
1289 | hc->routemap_redist_name[route_type] = strdup (argv[4]->arg); |
1290 | hc->routemap_redist[route_type] = route_map_lookup_by_name (argv[4]->arg); | |
65efcfce LB |
1291 | |
1292 | vnc_redistribute_postchange (bgp); | |
1293 | ||
1294 | return CMD_SUCCESS; | |
1295 | } | |
1296 | ||
1297 | /*-- redist policy, non-nvegroup end --*/ | |
1298 | ||
1299 | /*-- redist policy, nvegroup start --*/ | |
1300 | ||
1301 | DEFUN (vnc_nve_group_redist_bgpdirect_no_prefixlist, | |
1302 | vnc_nve_group_redist_bgpdirect_no_prefixlist_cmd, | |
034d2de2 | 1303 | "no redistribute bgp-direct <ipv4|ipv6> prefix-list", |
65efcfce LB |
1304 | NO_STR |
1305 | "Redistribute from other protocol\n" | |
1306 | "Redistribute from BGP directly\n" | |
1307 | "Disable redistribute filter\n" | |
1308 | "IPv4 routes\n" | |
1309 | "IPv6 routes\n" "Prefix-list for filtering redistributed routes\n") | |
1310 | { | |
cdc2d765 | 1311 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 1312 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg) |
65efcfce LB |
1313 | afi_t afi; |
1314 | ||
65efcfce LB |
1315 | if (!bgp->rfapi_cfg) |
1316 | { | |
1317 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1318 | return CMD_WARNING; | |
1319 | } | |
1320 | ||
65efcfce LB |
1321 | /* make sure it's still in list */ |
1322 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
1323 | { | |
1324 | /* Not in list anymore */ | |
1325 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
1326 | return CMD_WARNING; | |
1327 | } | |
1328 | ||
aed3273f | 1329 | if (!strcmp (argv[3]->arg, "ipv4")) |
65efcfce LB |
1330 | { |
1331 | afi = AFI_IP; | |
1332 | } | |
1333 | else | |
1334 | { | |
1335 | afi = AFI_IP6; | |
1336 | } | |
1337 | ||
1338 | vnc_redistribute_prechange (bgp); | |
1339 | ||
1340 | if (rfg->plist_redist_name[ZEBRA_ROUTE_BGP_DIRECT][afi]) | |
1341 | free (rfg->plist_redist_name[ZEBRA_ROUTE_BGP_DIRECT][afi]); | |
1342 | rfg->plist_redist_name[ZEBRA_ROUTE_BGP_DIRECT][afi] = NULL; | |
1343 | rfg->plist_redist[ZEBRA_ROUTE_BGP_DIRECT][afi] = NULL; | |
1344 | ||
1345 | vnc_redistribute_postchange (bgp); | |
1346 | ||
1347 | return CMD_SUCCESS; | |
1348 | } | |
1349 | ||
1350 | DEFUN (vnc_nve_group_redist_bgpdirect_prefixlist, | |
1351 | vnc_nve_group_redist_bgpdirect_prefixlist_cmd, | |
034d2de2 | 1352 | "redistribute bgp-direct <ipv4|ipv6> prefix-list NAME", |
65efcfce LB |
1353 | "Redistribute from other protocol\n" |
1354 | "Redistribute from BGP directly\n" | |
1355 | "IPv4 routes\n" | |
1356 | "IPv6 routes\n" | |
1357 | "Prefix-list for filtering redistributed routes\n" | |
1358 | "prefix list name\n") | |
1359 | { | |
cdc2d765 | 1360 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 1361 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce LB |
1362 | afi_t afi; |
1363 | ||
65efcfce LB |
1364 | if (!bgp->rfapi_cfg) |
1365 | { | |
1366 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1367 | return CMD_WARNING; | |
1368 | } | |
1369 | ||
65efcfce LB |
1370 | /* make sure it's still in list */ |
1371 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
1372 | { | |
1373 | /* Not in list anymore */ | |
1374 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
1375 | return CMD_WARNING; | |
1376 | } | |
1377 | ||
aed3273f | 1378 | if (!strcmp (argv[2]->arg, "ipv4")) |
65efcfce LB |
1379 | { |
1380 | afi = AFI_IP; | |
1381 | } | |
1382 | else | |
1383 | { | |
1384 | afi = AFI_IP6; | |
1385 | } | |
1386 | ||
1387 | vnc_redistribute_prechange (bgp); | |
1388 | ||
1389 | if (rfg->plist_redist_name[ZEBRA_ROUTE_BGP_DIRECT][afi]) | |
1390 | free (rfg->plist_redist_name[ZEBRA_ROUTE_BGP_DIRECT][afi]); | |
aed3273f | 1391 | rfg->plist_redist_name[ZEBRA_ROUTE_BGP_DIRECT][afi] = strdup (argv[4]->arg); |
65efcfce | 1392 | rfg->plist_redist[ZEBRA_ROUTE_BGP_DIRECT][afi] = |
aed3273f | 1393 | prefix_list_lookup (afi, argv[4]->arg); |
65efcfce LB |
1394 | |
1395 | vnc_redistribute_postchange (bgp); | |
1396 | ||
1397 | return CMD_SUCCESS; | |
1398 | } | |
1399 | ||
1400 | DEFUN (vnc_nve_group_redist_bgpdirect_no_routemap, | |
1401 | vnc_nve_group_redist_bgpdirect_no_routemap_cmd, | |
1402 | "no redistribute bgp-direct route-map", | |
1403 | NO_STR | |
1404 | "Redistribute from other protocols\n" | |
1405 | "Redistribute from BGP directly\n" | |
1406 | "Disable redistribute filter\n" | |
1407 | "Route-map for filtering redistributed routes\n") | |
1408 | { | |
cdc2d765 | 1409 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 1410 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce | 1411 | |
65efcfce LB |
1412 | if (!bgp->rfapi_cfg) |
1413 | { | |
1414 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1415 | return CMD_WARNING; | |
1416 | } | |
1417 | ||
65efcfce LB |
1418 | /* make sure it's still in list */ |
1419 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
1420 | { | |
1421 | /* Not in list anymore */ | |
1422 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
1423 | return CMD_WARNING; | |
1424 | } | |
1425 | ||
1426 | vnc_redistribute_prechange (bgp); | |
1427 | ||
1428 | if (rfg->routemap_redist_name[ZEBRA_ROUTE_BGP_DIRECT]) | |
1429 | free (rfg->routemap_redist_name[ZEBRA_ROUTE_BGP_DIRECT]); | |
1430 | rfg->routemap_redist_name[ZEBRA_ROUTE_BGP_DIRECT] = NULL; | |
1431 | rfg->routemap_redist[ZEBRA_ROUTE_BGP_DIRECT] = NULL; | |
1432 | ||
1433 | vnc_redistribute_postchange (bgp); | |
1434 | ||
1435 | return CMD_SUCCESS; | |
1436 | } | |
1437 | ||
1438 | DEFUN (vnc_nve_group_redist_bgpdirect_routemap, | |
1439 | vnc_nve_group_redist_bgpdirect_routemap_cmd, | |
1440 | "redistribute bgp-direct route-map NAME", | |
1441 | "Redistribute from other protocols\n" | |
1442 | "Redistribute from BGP directly\n" | |
1443 | "Route-map for filtering exported routes\n" "route map name\n") | |
1444 | { | |
cdc2d765 | 1445 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 1446 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce | 1447 | |
65efcfce LB |
1448 | if (!bgp->rfapi_cfg) |
1449 | { | |
1450 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1451 | return CMD_WARNING; | |
1452 | } | |
1453 | ||
65efcfce LB |
1454 | /* make sure it's still in list */ |
1455 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
1456 | { | |
1457 | /* Not in list anymore */ | |
1458 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
1459 | return CMD_WARNING; | |
1460 | } | |
1461 | ||
1462 | vnc_redistribute_prechange (bgp); | |
1463 | ||
1464 | if (rfg->routemap_redist_name[ZEBRA_ROUTE_BGP_DIRECT]) | |
1465 | free (rfg->routemap_redist_name[ZEBRA_ROUTE_BGP_DIRECT]); | |
aed3273f | 1466 | rfg->routemap_redist_name[ZEBRA_ROUTE_BGP_DIRECT] = strdup (argv[3]->arg); |
65efcfce | 1467 | rfg->routemap_redist[ZEBRA_ROUTE_BGP_DIRECT] = |
aed3273f | 1468 | route_map_lookup_by_name (argv[3]->arg); |
65efcfce LB |
1469 | |
1470 | vnc_redistribute_postchange (bgp); | |
1471 | ||
1472 | return CMD_SUCCESS; | |
1473 | } | |
1474 | ||
1475 | /*-- redist policy, nvegroup end --*/ | |
1476 | ||
1477 | /*------------------------------------------------------------------------- | |
1478 | * export | |
1479 | *-----------------------------------------------------------------------*/ | |
1480 | ||
1481 | DEFUN (vnc_export_mode, | |
1482 | vnc_export_mode_cmd, | |
034d2de2 | 1483 | "vnc export <bgp|zebra> mode <group-nve|ce|none|registering-nve>", |
65efcfce LB |
1484 | VNC_CONFIG_STR |
1485 | "Export to other protocols\n" | |
1486 | "Export to BGP\n" | |
1487 | "Export to Zebra (experimental)\n" | |
1488 | "Select export mode\n" | |
1489 | "Export routes with nve-group next-hops\n" | |
1490 | "Export routes with NVE connected router next-hops\n" | |
1491 | "Disable export\n" "Export routes with registering NVE as next-hop\n") | |
1492 | { | |
cdc2d765 | 1493 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
1494 | uint32_t oldmode = 0; |
1495 | uint32_t newmode = 0; | |
1496 | ||
65efcfce LB |
1497 | if (!bgp->rfapi_cfg) |
1498 | { | |
1499 | vty_out (vty, "VNC not configured%s", VTY_NEWLINE); | |
1500 | return CMD_WARNING; | |
1501 | } | |
1502 | ||
aed3273f | 1503 | if (argv[2]->arg[0] == 'b') |
65efcfce LB |
1504 | { |
1505 | oldmode = bgp->rfapi_cfg->flags & BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS; | |
aed3273f | 1506 | switch (argv[4]->arg[0]) |
65efcfce LB |
1507 | { |
1508 | case 'g': | |
1509 | newmode = BGP_VNC_CONFIG_EXPORT_BGP_MODE_GRP; | |
1510 | break; | |
1511 | case 'c': | |
1512 | newmode = BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE; | |
1513 | break; | |
1514 | case 'n': | |
1515 | newmode = 0; | |
1516 | break; | |
1517 | case 'r': | |
1518 | newmode = BGP_VNC_CONFIG_EXPORT_BGP_MODE_RH; | |
1519 | break; | |
1520 | default: | |
1521 | vty_out (vty, "Invalid mode specified%s", VTY_NEWLINE); | |
1522 | return CMD_WARNING; | |
1523 | } | |
1524 | ||
1525 | if (newmode == oldmode) | |
1526 | { | |
1527 | vty_out (vty, "Mode unchanged%s", VTY_NEWLINE); | |
1528 | return CMD_SUCCESS; | |
1529 | } | |
1530 | ||
1531 | vnc_export_bgp_prechange (bgp); | |
1532 | ||
1533 | bgp->rfapi_cfg->flags &= ~BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS; | |
1534 | bgp->rfapi_cfg->flags |= newmode; | |
1535 | ||
1536 | vnc_export_bgp_postchange (bgp); | |
1537 | ||
1538 | ||
1539 | } | |
1540 | else | |
1541 | { | |
1542 | /* | |
1543 | * export to zebra with RH mode is not yet implemented | |
1544 | */ | |
1545 | vty_out (vty, "Changing modes for zebra export not implemented yet%s", | |
1546 | VTY_NEWLINE); | |
1547 | return CMD_WARNING; | |
1548 | ||
1549 | oldmode = bgp->rfapi_cfg->flags & BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_BITS; | |
1550 | bgp->rfapi_cfg->flags &= ~BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_BITS; | |
aed3273f | 1551 | switch (argv[4]->arg[0]) |
65efcfce LB |
1552 | { |
1553 | case 'g': | |
1554 | if (oldmode == BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_RH) | |
1555 | { | |
1556 | /* TBD */ | |
1557 | } | |
1558 | bgp->rfapi_cfg->flags |= BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_GRP; | |
1559 | if (oldmode != BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_GRP) | |
1560 | { | |
1561 | /* TBD */ | |
1562 | } | |
1563 | break; | |
1564 | case 'n': | |
1565 | if (oldmode == BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_RH) | |
1566 | { | |
1567 | /* TBD */ | |
1568 | } | |
1569 | if (oldmode == BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_GRP) | |
1570 | { | |
1571 | /* TBD */ | |
1572 | } | |
1573 | break; | |
1574 | case 'r': | |
1575 | if (oldmode == BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_GRP) | |
1576 | { | |
1577 | /* TBD */ | |
1578 | } | |
1579 | bgp->rfapi_cfg->flags |= BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_RH; | |
1580 | if (oldmode != BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_RH) | |
1581 | { | |
1582 | /* TBD */ | |
1583 | } | |
1584 | break; | |
1585 | default: | |
1586 | vty_out (vty, "Invalid mode%s", VTY_NEWLINE); | |
1587 | return CMD_WARNING; | |
1588 | } | |
1589 | } | |
1590 | ||
1591 | return CMD_SUCCESS; | |
1592 | } | |
1593 | ||
1594 | static struct rfapi_rfg_name * | |
1595 | rfgn_new () | |
1596 | { | |
1597 | return XCALLOC (MTYPE_RFAPI_RFG_NAME, sizeof (struct rfapi_rfg_name)); | |
1598 | } | |
1599 | ||
1600 | static void | |
1601 | rfgn_free (struct rfapi_rfg_name *rfgn) | |
1602 | { | |
1603 | XFREE (MTYPE_RFAPI_RFG_NAME, rfgn); | |
1604 | } | |
1605 | ||
1606 | DEFUN (vnc_export_nvegroup, | |
1607 | vnc_export_nvegroup_cmd, | |
034d2de2 | 1608 | "vnc export <bgp|zebra> group-nve group NAME", |
65efcfce LB |
1609 | VNC_CONFIG_STR |
1610 | "Export to other protocols\n" | |
1611 | "Export to BGP\n" | |
1612 | "Export to Zebra (experimental)\n" | |
1613 | "NVE group, used in 'group-nve' export mode\n" | |
1614 | "NVE group\n" "Group name\n") | |
1615 | { | |
cdc2d765 | 1616 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
1617 | struct rfapi_nve_group_cfg *rfg_new; |
1618 | ||
65efcfce LB |
1619 | if (!bgp->rfapi_cfg) |
1620 | { | |
1621 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1622 | return CMD_WARNING; | |
1623 | } | |
1624 | ||
aed3273f | 1625 | rfg_new = rfapi_group_lookup_byname (bgp, argv[5]->arg); |
65efcfce | 1626 | |
aed3273f | 1627 | if (argv[2]->arg[0] == 'b') |
65efcfce LB |
1628 | { |
1629 | ||
1630 | struct listnode *node; | |
1631 | struct rfapi_rfg_name *rfgn; | |
1632 | ||
1633 | /* | |
1634 | * Set group for export to BGP Direct | |
1635 | */ | |
1636 | ||
1637 | /* see if group is already included in export list */ | |
1638 | for (ALL_LIST_ELEMENTS_RO (bgp->rfapi_cfg->rfg_export_direct_bgp_l, | |
1639 | node, rfgn)) | |
1640 | { | |
1641 | ||
aed3273f | 1642 | if (!strcmp (rfgn->name, argv[5]->arg)) |
65efcfce LB |
1643 | { |
1644 | /* already in the list: we're done */ | |
1645 | return CMD_SUCCESS; | |
1646 | } | |
1647 | } | |
1648 | ||
1649 | rfgn = rfgn_new (); | |
aed3273f | 1650 | rfgn->name = strdup (argv[5]->arg); |
65efcfce LB |
1651 | rfgn->rfg = rfg_new; /* OK if not set yet */ |
1652 | ||
1653 | listnode_add (bgp->rfapi_cfg->rfg_export_direct_bgp_l, rfgn); | |
1654 | ||
a3b55c25 | 1655 | vnc_zlog_debug_verbose ("%s: testing rfg_new", __func__); |
65efcfce LB |
1656 | if (rfg_new) |
1657 | { | |
a3b55c25 | 1658 | vnc_zlog_debug_verbose ("%s: testing bgp grp mode enabled", __func__); |
65efcfce | 1659 | if (VNC_EXPORT_BGP_GRP_ENABLED (bgp->rfapi_cfg)) |
a3b55c25 | 1660 | vnc_zlog_debug_verbose ("%s: calling vnc_direct_bgp_add_group", __func__); |
65efcfce LB |
1661 | vnc_direct_bgp_add_group (bgp, rfg_new); |
1662 | } | |
1663 | ||
1664 | } | |
1665 | else | |
1666 | { | |
1667 | ||
1668 | struct listnode *node; | |
1669 | struct rfapi_rfg_name *rfgn; | |
1670 | ||
1671 | /* | |
1672 | * Set group for export to Zebra | |
1673 | */ | |
1674 | ||
1675 | /* see if group is already included in export list */ | |
1676 | for (ALL_LIST_ELEMENTS_RO (bgp->rfapi_cfg->rfg_export_zebra_l, | |
1677 | node, rfgn)) | |
1678 | { | |
1679 | ||
aed3273f | 1680 | if (!strcmp (rfgn->name, argv[5]->arg)) |
65efcfce LB |
1681 | { |
1682 | /* already in the list: we're done */ | |
1683 | return CMD_SUCCESS; | |
1684 | } | |
1685 | } | |
1686 | ||
1687 | rfgn = rfgn_new (); | |
aed3273f | 1688 | rfgn->name = strdup (argv[5]->arg); |
65efcfce LB |
1689 | rfgn->rfg = rfg_new; /* OK if not set yet */ |
1690 | ||
1691 | listnode_add (bgp->rfapi_cfg->rfg_export_zebra_l, rfgn); | |
1692 | ||
1693 | if (rfg_new) | |
1694 | { | |
1695 | if (VNC_EXPORT_ZEBRA_GRP_ENABLED (bgp->rfapi_cfg)) | |
1696 | vnc_zebra_add_group (bgp, rfg_new); | |
1697 | } | |
1698 | } | |
1699 | ||
1700 | return CMD_SUCCESS; | |
1701 | } | |
1702 | ||
1703 | /* | |
1704 | * This command applies to routes exported from VNC to BGP directly | |
1705 | * without going though zebra | |
1706 | */ | |
1707 | DEFUN (vnc_no_export_nvegroup, | |
1708 | vnc_no_export_nvegroup_cmd, | |
034d2de2 | 1709 | "vnc export <bgp|zebra> group-nve no group NAME", |
65efcfce LB |
1710 | VNC_CONFIG_STR |
1711 | "Export to other protocols\n" | |
1712 | "Export to BGP\n" | |
1713 | "Export to Zebra (experimental)\n" | |
1714 | "NVE group, used in 'group-nve' export mode\n" | |
1715 | "Disable export of VNC routes\n" "NVE group\n" "Group name\n") | |
1716 | { | |
cdc2d765 | 1717 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
1718 | struct listnode *node, *nnode; |
1719 | struct rfapi_rfg_name *rfgn; | |
1720 | ||
65efcfce LB |
1721 | if (!bgp->rfapi_cfg) |
1722 | { | |
1723 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1724 | return CMD_WARNING; | |
1725 | } | |
1726 | ||
aed3273f | 1727 | if (argv[2]->arg[0] == 'b') |
65efcfce LB |
1728 | { |
1729 | for (ALL_LIST_ELEMENTS (bgp->rfapi_cfg->rfg_export_direct_bgp_l, | |
1730 | node, nnode, rfgn)) | |
1731 | { | |
1732 | ||
aed3273f | 1733 | if (rfgn->name && !strcmp (rfgn->name, argv[6]->arg)) |
65efcfce | 1734 | { |
a3b55c25 | 1735 | vnc_zlog_debug_verbose ("%s: matched \"%s\"", __func__, rfgn->name); |
65efcfce LB |
1736 | if (rfgn->rfg) |
1737 | vnc_direct_bgp_del_group (bgp, rfgn->rfg); | |
1738 | free (rfgn->name); | |
1739 | list_delete_node (bgp->rfapi_cfg->rfg_export_direct_bgp_l, | |
1740 | node); | |
1741 | rfgn_free (rfgn); | |
1742 | break; | |
1743 | } | |
1744 | } | |
1745 | } | |
1746 | else | |
1747 | { | |
1748 | for (ALL_LIST_ELEMENTS (bgp->rfapi_cfg->rfg_export_zebra_l, | |
1749 | node, nnode, rfgn)) | |
1750 | { | |
1751 | ||
a3b55c25 | 1752 | vnc_zlog_debug_verbose ("does rfg \"%s\" match?", rfgn->name); |
aed3273f | 1753 | if (rfgn->name && !strcmp (rfgn->name, argv[6]->arg)) |
65efcfce LB |
1754 | { |
1755 | if (rfgn->rfg) | |
1756 | vnc_zebra_del_group (bgp, rfgn->rfg); | |
1757 | free (rfgn->name); | |
1758 | list_delete_node (bgp->rfapi_cfg->rfg_export_zebra_l, node); | |
1759 | rfgn_free (rfgn); | |
1760 | break; | |
1761 | } | |
1762 | } | |
1763 | } | |
1764 | return CMD_SUCCESS; | |
1765 | } | |
1766 | ||
1767 | DEFUN (vnc_nve_group_export_no_prefixlist, | |
1768 | vnc_nve_group_export_no_prefixlist_cmd, | |
034d2de2 | 1769 | "no export <bgp|zebra> <ipv4|ipv6> prefix-list [NAME]", |
65efcfce LB |
1770 | NO_STR |
1771 | "Export to other protocols\n" | |
1772 | "Export to BGP\n" | |
1773 | "Export to Zebra (experimental)\n" | |
1774 | "IPv4 routes\n" | |
1775 | "IPv6 routes\n" | |
1776 | "Prefix-list for filtering exported routes\n" "prefix list name\n") | |
1777 | { | |
cdc2d765 | 1778 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 1779 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce LB |
1780 | afi_t afi; |
1781 | ||
65efcfce LB |
1782 | if (!bgp->rfapi_cfg) |
1783 | { | |
1784 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1785 | return CMD_WARNING; | |
1786 | } | |
1787 | ||
65efcfce LB |
1788 | /* make sure it's still in list */ |
1789 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
1790 | { | |
1791 | /* Not in list anymore */ | |
1792 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
1793 | return CMD_WARNING; | |
1794 | } | |
1795 | ||
aed3273f | 1796 | if (!strcmp (argv[3]->arg, "ipv4")) |
65efcfce LB |
1797 | { |
1798 | afi = AFI_IP; | |
1799 | } | |
1800 | else | |
1801 | { | |
1802 | afi = AFI_IP6; | |
1803 | } | |
1804 | ||
aed3273f | 1805 | if (argv[2]->arg[0] == 'b') |
65efcfce | 1806 | { |
aed3273f DL |
1807 | if (((argc > 5) |
1808 | && !strcmp (argv[5]->arg, rfg->plist_export_bgp_name[afi])) | |
1809 | || (argc <= 5)) | |
65efcfce LB |
1810 | { |
1811 | ||
1812 | if (rfg->plist_export_bgp_name[afi]) | |
1813 | free (rfg->plist_export_bgp_name[afi]); | |
1814 | rfg->plist_export_bgp_name[afi] = NULL; | |
1815 | rfg->plist_export_bgp[afi] = NULL; | |
1816 | ||
1817 | vnc_direct_bgp_reexport_group_afi (bgp, rfg, afi); | |
1818 | } | |
1819 | } | |
1820 | else | |
1821 | { | |
aed3273f DL |
1822 | if (((argc > 5) |
1823 | && !strcmp (argv[5]->arg, rfg->plist_export_zebra_name[afi])) | |
1824 | || (argc <= 5)) | |
65efcfce LB |
1825 | { |
1826 | if (rfg->plist_export_zebra_name[afi]) | |
1827 | free (rfg->plist_export_zebra_name[afi]); | |
1828 | rfg->plist_export_zebra_name[afi] = NULL; | |
1829 | rfg->plist_export_zebra[afi] = NULL; | |
1830 | ||
1831 | vnc_zebra_reexport_group_afi (bgp, rfg, afi); | |
1832 | } | |
1833 | } | |
1834 | return CMD_SUCCESS; | |
1835 | } | |
1836 | ||
1837 | DEFUN (vnc_nve_group_export_prefixlist, | |
1838 | vnc_nve_group_export_prefixlist_cmd, | |
034d2de2 | 1839 | "export <bgp|zebra> <ipv4|ipv6> prefix-list NAME", |
65efcfce LB |
1840 | "Export to other protocols\n" |
1841 | "Export to BGP\n" | |
1842 | "Export to Zebra (experimental)\n" | |
1843 | "IPv4 routes\n" | |
1844 | "IPv6 routes\n" | |
1845 | "Prefix-list for filtering exported routes\n" "prefix list name\n") | |
1846 | { | |
cdc2d765 | 1847 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 1848 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce LB |
1849 | afi_t afi; |
1850 | ||
65efcfce LB |
1851 | if (!bgp->rfapi_cfg) |
1852 | { | |
1853 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1854 | return CMD_WARNING; | |
1855 | } | |
1856 | ||
65efcfce LB |
1857 | /* make sure it's still in list */ |
1858 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
1859 | { | |
1860 | /* Not in list anymore */ | |
1861 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
1862 | return CMD_WARNING; | |
1863 | } | |
1864 | ||
aed3273f | 1865 | if (!strcmp (argv[2]->arg, "ipv4")) |
65efcfce LB |
1866 | { |
1867 | afi = AFI_IP; | |
1868 | } | |
1869 | else | |
1870 | { | |
1871 | afi = AFI_IP6; | |
1872 | } | |
1873 | ||
aed3273f | 1874 | if (argv[1]->arg[0] == 'b') |
65efcfce LB |
1875 | { |
1876 | if (rfg->plist_export_bgp_name[afi]) | |
1877 | free (rfg->plist_export_bgp_name[afi]); | |
aed3273f DL |
1878 | rfg->plist_export_bgp_name[afi] = strdup (argv[4]->arg); |
1879 | rfg->plist_export_bgp[afi] = prefix_list_lookup (afi, argv[4]->arg); | |
65efcfce LB |
1880 | |
1881 | vnc_direct_bgp_reexport_group_afi (bgp, rfg, afi); | |
1882 | ||
1883 | } | |
1884 | else | |
1885 | { | |
1886 | if (rfg->plist_export_zebra_name[afi]) | |
1887 | free (rfg->plist_export_zebra_name[afi]); | |
aed3273f DL |
1888 | rfg->plist_export_zebra_name[afi] = strdup (argv[4]->arg); |
1889 | rfg->plist_export_zebra[afi] = prefix_list_lookup (afi, argv[4]->arg); | |
65efcfce LB |
1890 | |
1891 | vnc_zebra_reexport_group_afi (bgp, rfg, afi); | |
1892 | } | |
1893 | return CMD_SUCCESS; | |
1894 | } | |
1895 | ||
1896 | DEFUN (vnc_nve_group_export_no_routemap, | |
1897 | vnc_nve_group_export_no_routemap_cmd, | |
034d2de2 | 1898 | "no export <bgp|zebra> route-map [NAME]", |
65efcfce LB |
1899 | NO_STR |
1900 | "Export to other protocols\n" | |
1901 | "Export to BGP\n" | |
1902 | "Export to Zebra (experimental)\n" | |
1903 | "Route-map for filtering exported routes\n" "route map name\n") | |
1904 | { | |
cdc2d765 | 1905 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 1906 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce | 1907 | |
65efcfce LB |
1908 | if (!bgp->rfapi_cfg) |
1909 | { | |
1910 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1911 | return CMD_WARNING; | |
1912 | } | |
1913 | ||
65efcfce LB |
1914 | /* make sure it's still in list */ |
1915 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
1916 | { | |
1917 | /* Not in list anymore */ | |
1918 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
1919 | return CMD_WARNING; | |
1920 | } | |
1921 | ||
aed3273f | 1922 | if (argv[2]->arg[0] == 'b') |
65efcfce | 1923 | { |
aed3273f DL |
1924 | if (((argc > 4) |
1925 | && !strcmp (argv[4]->arg, rfg->routemap_export_bgp_name)) | |
1926 | || (argc <= 4)) | |
65efcfce LB |
1927 | { |
1928 | ||
1929 | if (rfg->routemap_export_bgp_name) | |
1930 | free (rfg->routemap_export_bgp_name); | |
1931 | rfg->routemap_export_bgp_name = NULL; | |
1932 | rfg->routemap_export_bgp = NULL; | |
1933 | ||
1934 | vnc_direct_bgp_reexport_group_afi (bgp, rfg, AFI_IP); | |
1935 | vnc_direct_bgp_reexport_group_afi (bgp, rfg, AFI_IP6); | |
1936 | } | |
1937 | } | |
1938 | else | |
1939 | { | |
aed3273f DL |
1940 | if (((argc > 4) |
1941 | && !strcmp (argv[4]->arg, rfg->routemap_export_zebra_name)) | |
1942 | || (argc <= 4)) | |
65efcfce LB |
1943 | { |
1944 | if (rfg->routemap_export_zebra_name) | |
1945 | free (rfg->routemap_export_zebra_name); | |
1946 | rfg->routemap_export_zebra_name = NULL; | |
1947 | rfg->routemap_export_zebra = NULL; | |
1948 | ||
1949 | vnc_zebra_reexport_group_afi (bgp, rfg, AFI_IP); | |
1950 | vnc_zebra_reexport_group_afi (bgp, rfg, AFI_IP6); | |
1951 | } | |
1952 | } | |
1953 | return CMD_SUCCESS; | |
1954 | } | |
1955 | ||
1956 | DEFUN (vnc_nve_group_export_routemap, | |
1957 | vnc_nve_group_export_routemap_cmd, | |
034d2de2 | 1958 | "export <bgp|zebra> route-map NAME", |
65efcfce LB |
1959 | "Export to other protocols\n" |
1960 | "Export to BGP\n" | |
1961 | "Export to Zebra (experimental)\n" | |
1962 | "Route-map for filtering exported routes\n" "route map name\n") | |
1963 | { | |
cdc2d765 | 1964 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 1965 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce | 1966 | |
65efcfce LB |
1967 | if (!bgp->rfapi_cfg) |
1968 | { | |
1969 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
1970 | return CMD_WARNING; | |
1971 | } | |
1972 | ||
65efcfce LB |
1973 | /* make sure it's still in list */ |
1974 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
1975 | { | |
1976 | /* Not in list anymore */ | |
1977 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
1978 | return CMD_WARNING; | |
1979 | } | |
1980 | ||
aed3273f | 1981 | if (argv[1]->arg[0] == 'b') |
65efcfce LB |
1982 | { |
1983 | if (rfg->routemap_export_bgp_name) | |
1984 | free (rfg->routemap_export_bgp_name); | |
aed3273f DL |
1985 | rfg->routemap_export_bgp_name = strdup (argv[3]->arg); |
1986 | rfg->routemap_export_bgp = route_map_lookup_by_name (argv[3]->arg); | |
65efcfce LB |
1987 | vnc_direct_bgp_reexport_group_afi (bgp, rfg, AFI_IP); |
1988 | vnc_direct_bgp_reexport_group_afi (bgp, rfg, AFI_IP6); | |
1989 | } | |
1990 | else | |
1991 | { | |
1992 | if (rfg->routemap_export_zebra_name) | |
1993 | free (rfg->routemap_export_zebra_name); | |
aed3273f DL |
1994 | rfg->routemap_export_zebra_name = strdup (argv[3]->arg); |
1995 | rfg->routemap_export_zebra = route_map_lookup_by_name (argv[3]->arg); | |
65efcfce LB |
1996 | vnc_zebra_reexport_group_afi (bgp, rfg, AFI_IP); |
1997 | vnc_zebra_reexport_group_afi (bgp, rfg, AFI_IP6); | |
1998 | } | |
1999 | return CMD_SUCCESS; | |
2000 | } | |
2001 | ||
2002 | DEFUN (vnc_nve_export_no_prefixlist, | |
2003 | vnc_nve_export_no_prefixlist_cmd, | |
034d2de2 | 2004 | "no vnc export <bgp|zebra> <ipv4|ipv6> prefix-list [NAME]", |
65efcfce LB |
2005 | NO_STR |
2006 | VNC_CONFIG_STR | |
2007 | "Export to other protocols\n" | |
2008 | "Export to BGP\n" | |
2009 | "Export to Zebra (experimental)\n" | |
2010 | "IPv4 prefixes\n" | |
2011 | "IPv6 prefixes\n" | |
2012 | "Prefix-list for filtering exported routes\n" "Prefix list name\n") | |
2013 | { | |
cdc2d765 | 2014 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
2015 | struct rfapi_cfg *hc; |
2016 | afi_t afi; | |
2017 | ||
65efcfce LB |
2018 | if (!(hc = bgp->rfapi_cfg)) |
2019 | { | |
2020 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
2021 | return CMD_WARNING; | |
2022 | } | |
2023 | ||
aed3273f | 2024 | if (!strcmp (argv[4]->arg, "ipv4")) |
65efcfce LB |
2025 | { |
2026 | afi = AFI_IP; | |
2027 | } | |
2028 | else | |
2029 | { | |
2030 | afi = AFI_IP6; | |
2031 | } | |
2032 | ||
aed3273f | 2033 | if (argv[3]->arg[0] == 'b') |
65efcfce | 2034 | { |
aed3273f DL |
2035 | if (((argc > 6) |
2036 | && !strcmp (argv[6]->arg, hc->plist_export_bgp_name[afi])) | |
2037 | || (argc <= 6)) | |
65efcfce LB |
2038 | { |
2039 | ||
2040 | if (hc->plist_export_bgp_name[afi]) | |
2041 | free (hc->plist_export_bgp_name[afi]); | |
2042 | hc->plist_export_bgp_name[afi] = NULL; | |
2043 | hc->plist_export_bgp[afi] = NULL; | |
2044 | vnc_direct_bgp_reexport (bgp, afi); | |
2045 | } | |
2046 | } | |
2047 | else | |
2048 | { | |
aed3273f DL |
2049 | if (((argc > 6) |
2050 | && !strcmp (argv[6]->arg, hc->plist_export_zebra_name[afi])) | |
2051 | || (argc <= 6)) | |
65efcfce LB |
2052 | { |
2053 | ||
2054 | if (hc->plist_export_zebra_name[afi]) | |
2055 | free (hc->plist_export_zebra_name[afi]); | |
2056 | hc->plist_export_zebra_name[afi] = NULL; | |
2057 | hc->plist_export_zebra[afi] = NULL; | |
2058 | /* TBD vnc_zebra_rh_reexport(bgp, afi); */ | |
2059 | } | |
2060 | } | |
2061 | return CMD_SUCCESS; | |
2062 | } | |
2063 | ||
2064 | DEFUN (vnc_nve_export_prefixlist, | |
2065 | vnc_nve_export_prefixlist_cmd, | |
034d2de2 | 2066 | "vnc export <bgp|zebra> <ipv4|ipv6> prefix-list NAME", |
65efcfce LB |
2067 | VNC_CONFIG_STR |
2068 | "Export to other protocols\n" | |
2069 | "Export to BGP\n" | |
2070 | "Export to Zebra (experimental)\n" | |
2071 | "Filters, used in 'registering-nve' export mode\n" | |
2072 | "IPv4 prefixes\n" | |
2073 | "IPv6 prefixes\n" | |
2074 | "Prefix-list for filtering exported routes\n" "Prefix list name\n") | |
2075 | { | |
cdc2d765 | 2076 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
2077 | struct rfapi_cfg *hc; |
2078 | afi_t afi; | |
2079 | ||
65efcfce LB |
2080 | if (!(hc = bgp->rfapi_cfg)) |
2081 | { | |
2082 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
2083 | return CMD_WARNING; | |
2084 | } | |
2085 | ||
aed3273f | 2086 | if (!strcmp (argv[3]->arg, "ipv4")) |
65efcfce LB |
2087 | { |
2088 | afi = AFI_IP; | |
2089 | } | |
2090 | else | |
2091 | { | |
2092 | afi = AFI_IP6; | |
2093 | } | |
2094 | ||
aed3273f | 2095 | if (argv[2]->arg[0] == 'b') |
65efcfce LB |
2096 | { |
2097 | if (hc->plist_export_bgp_name[afi]) | |
2098 | free (hc->plist_export_bgp_name[afi]); | |
aed3273f DL |
2099 | hc->plist_export_bgp_name[afi] = strdup (argv[5]->arg); |
2100 | hc->plist_export_bgp[afi] = prefix_list_lookup (afi, argv[5]->arg); | |
65efcfce LB |
2101 | vnc_direct_bgp_reexport (bgp, afi); |
2102 | } | |
2103 | else | |
2104 | { | |
2105 | if (hc->plist_export_zebra_name[afi]) | |
2106 | free (hc->plist_export_zebra_name[afi]); | |
aed3273f DL |
2107 | hc->plist_export_zebra_name[afi] = strdup (argv[5]->arg); |
2108 | hc->plist_export_zebra[afi] = prefix_list_lookup (afi, argv[5]->arg); | |
65efcfce LB |
2109 | /* TBD vnc_zebra_rh_reexport(bgp, afi); */ |
2110 | } | |
2111 | return CMD_SUCCESS; | |
2112 | } | |
2113 | ||
2114 | DEFUN (vnc_nve_export_no_routemap, | |
2115 | vnc_nve_export_no_routemap_cmd, | |
034d2de2 | 2116 | "no vnc export <bgp|zebra> route-map [NAME]", |
65efcfce LB |
2117 | NO_STR |
2118 | VNC_CONFIG_STR | |
2119 | "Export to other protocols\n" | |
2120 | "Export to BGP\n" | |
2121 | "Export to Zebra (experimental)\n" | |
2122 | "Route-map for filtering exported routes\n" "Route map name\n") | |
2123 | { | |
cdc2d765 | 2124 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
2125 | struct rfapi_cfg *hc; |
2126 | ||
65efcfce LB |
2127 | if (!(hc = bgp->rfapi_cfg)) |
2128 | { | |
2129 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
2130 | return CMD_WARNING; | |
2131 | } | |
2132 | ||
aed3273f | 2133 | if (argv[3]->arg[0] == 'b') |
65efcfce | 2134 | { |
aed3273f DL |
2135 | if (((argc > 5) |
2136 | && !strcmp (argv[5]->arg, hc->routemap_export_bgp_name)) | |
2137 | || (argc <= 5)) | |
65efcfce LB |
2138 | { |
2139 | ||
2140 | if (hc->routemap_export_bgp_name) | |
2141 | free (hc->routemap_export_bgp_name); | |
2142 | hc->routemap_export_bgp_name = NULL; | |
2143 | hc->routemap_export_bgp = NULL; | |
2144 | vnc_direct_bgp_reexport (bgp, AFI_IP); | |
2145 | vnc_direct_bgp_reexport (bgp, AFI_IP6); | |
2146 | } | |
2147 | } | |
2148 | else | |
2149 | { | |
aed3273f DL |
2150 | if (((argc > 5) |
2151 | && !strcmp (argv[5]->arg, hc->routemap_export_zebra_name)) | |
2152 | || (argc <= 5)) | |
65efcfce LB |
2153 | { |
2154 | ||
2155 | if (hc->routemap_export_zebra_name) | |
2156 | free (hc->routemap_export_zebra_name); | |
2157 | hc->routemap_export_zebra_name = NULL; | |
2158 | hc->routemap_export_zebra = NULL; | |
2159 | /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */ | |
2160 | /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */ | |
2161 | } | |
2162 | } | |
2163 | return CMD_SUCCESS; | |
2164 | } | |
2165 | ||
2166 | DEFUN (vnc_nve_export_routemap, | |
2167 | vnc_nve_export_routemap_cmd, | |
034d2de2 | 2168 | "vnc export <bgp|zebra> route-map NAME", |
65efcfce LB |
2169 | VNC_CONFIG_STR |
2170 | "Export to other protocols\n" | |
2171 | "Export to BGP\n" | |
2172 | "Export to Zebra (experimental)\n" | |
2173 | "Filters, used in 'registering-nve' export mode\n" | |
2174 | "Route-map for filtering exported routes\n" "Route map name\n") | |
2175 | { | |
cdc2d765 | 2176 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
2177 | struct rfapi_cfg *hc; |
2178 | ||
65efcfce LB |
2179 | if (!(hc = bgp->rfapi_cfg)) |
2180 | { | |
2181 | vty_out (vty, "rfapi not configured%s", VTY_NEWLINE); | |
2182 | return CMD_WARNING; | |
2183 | } | |
2184 | ||
aed3273f | 2185 | if (argv[2]->arg[0] == 'b') |
65efcfce LB |
2186 | { |
2187 | if (hc->routemap_export_bgp_name) | |
2188 | free (hc->routemap_export_bgp_name); | |
aed3273f DL |
2189 | hc->routemap_export_bgp_name = strdup (argv[4]->arg); |
2190 | hc->routemap_export_bgp = route_map_lookup_by_name (argv[4]->arg); | |
65efcfce LB |
2191 | vnc_direct_bgp_reexport (bgp, AFI_IP); |
2192 | vnc_direct_bgp_reexport (bgp, AFI_IP6); | |
2193 | } | |
2194 | else | |
2195 | { | |
2196 | if (hc->routemap_export_zebra_name) | |
2197 | free (hc->routemap_export_zebra_name); | |
aed3273f DL |
2198 | hc->routemap_export_zebra_name = strdup (argv[4]->arg); |
2199 | hc->routemap_export_zebra = route_map_lookup_by_name (argv[4]->arg); | |
65efcfce LB |
2200 | /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */ |
2201 | /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */ | |
2202 | } | |
2203 | return CMD_SUCCESS; | |
2204 | } | |
2205 | ||
2206 | ||
2207 | /* | |
2208 | * respond to changes in the global prefix list configuration | |
2209 | */ | |
2210 | void | |
2211 | vnc_prefix_list_update (struct bgp *bgp) | |
2212 | { | |
2213 | afi_t afi; | |
2214 | struct listnode *n; | |
2215 | struct rfapi_nve_group_cfg *rfg; | |
2216 | struct rfapi_cfg *hc; | |
2217 | int i; | |
2218 | ||
2219 | if (!bgp) | |
2220 | { | |
a3b55c25 | 2221 | vnc_zlog_debug_verbose ("%s: No BGP process is configured", __func__); |
65efcfce LB |
2222 | return; |
2223 | } | |
2224 | ||
2225 | if (!(hc = bgp->rfapi_cfg)) | |
2226 | { | |
a3b55c25 | 2227 | vnc_zlog_debug_verbose ("%s: rfapi not configured", __func__); |
65efcfce LB |
2228 | return; |
2229 | } | |
2230 | ||
2231 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
2232 | { | |
2233 | /* | |
2234 | * Loop over nve groups | |
2235 | */ | |
2236 | for (ALL_LIST_ELEMENTS_RO (bgp->rfapi_cfg->nve_groups_sequential, | |
2237 | n, rfg)) | |
2238 | { | |
2239 | ||
2240 | if (rfg->plist_export_bgp_name[afi]) | |
2241 | { | |
2242 | rfg->plist_export_bgp[afi] = | |
2243 | prefix_list_lookup (afi, rfg->plist_export_bgp_name[afi]); | |
2244 | } | |
2245 | if (rfg->plist_export_zebra_name[afi]) | |
2246 | { | |
2247 | rfg->plist_export_zebra[afi] = | |
2248 | prefix_list_lookup (afi, rfg->plist_export_zebra_name[afi]); | |
2249 | } | |
2250 | for (i = 0; i < ZEBRA_ROUTE_MAX; ++i) | |
2251 | { | |
2252 | if (rfg->plist_redist_name[i][afi]) | |
2253 | { | |
2254 | rfg->plist_redist[i][afi] = | |
2255 | prefix_list_lookup (afi, rfg->plist_redist_name[i][afi]); | |
2256 | } | |
2257 | } | |
2258 | ||
2259 | vnc_direct_bgp_reexport_group_afi (bgp, rfg, afi); | |
2260 | /* TBD vnc_zebra_reexport_group_afi(bgp, rfg, afi); */ | |
2261 | } | |
2262 | ||
2263 | /* | |
2264 | * RH config, too | |
2265 | */ | |
2266 | if (hc->plist_export_bgp_name[afi]) | |
2267 | { | |
2268 | hc->plist_export_bgp[afi] = | |
2269 | prefix_list_lookup (afi, hc->plist_export_bgp_name[afi]); | |
2270 | } | |
2271 | if (hc->plist_export_zebra_name[afi]) | |
2272 | { | |
2273 | hc->plist_export_zebra[afi] = | |
2274 | prefix_list_lookup (afi, hc->plist_export_zebra_name[afi]); | |
2275 | } | |
2276 | ||
2277 | for (i = 0; i < ZEBRA_ROUTE_MAX; ++i) | |
2278 | { | |
2279 | if (hc->plist_redist_name[i][afi]) | |
2280 | { | |
2281 | hc->plist_redist[i][afi] = | |
2282 | prefix_list_lookup (afi, hc->plist_redist_name[i][afi]); | |
2283 | } | |
2284 | } | |
2285 | ||
2286 | } | |
2287 | ||
2288 | vnc_direct_bgp_reexport (bgp, AFI_IP); | |
2289 | vnc_direct_bgp_reexport (bgp, AFI_IP6); | |
2290 | ||
2291 | /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */ | |
2292 | /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */ | |
2293 | ||
2294 | vnc_redistribute_prechange (bgp); | |
2295 | vnc_redistribute_postchange (bgp); | |
2296 | } | |
2297 | ||
2298 | /* | |
2299 | * respond to changes in the global route map configuration | |
2300 | */ | |
2301 | void | |
2302 | vnc_routemap_update (struct bgp *bgp, const char *unused) | |
2303 | { | |
2304 | struct listnode *n; | |
2305 | struct rfapi_nve_group_cfg *rfg; | |
2306 | struct rfapi_cfg *hc; | |
2307 | int i; | |
2308 | ||
a3b55c25 | 2309 | vnc_zlog_debug_verbose ("%s(arg=%s)", __func__, unused); |
65efcfce LB |
2310 | |
2311 | if (!bgp) | |
2312 | { | |
a3b55c25 | 2313 | vnc_zlog_debug_verbose ("%s: No BGP process is configured", __func__); |
65efcfce LB |
2314 | return; |
2315 | } | |
2316 | ||
2317 | if (!(hc = bgp->rfapi_cfg)) | |
2318 | { | |
a3b55c25 | 2319 | vnc_zlog_debug_verbose ("%s: rfapi not configured", __func__); |
65efcfce LB |
2320 | return; |
2321 | } | |
2322 | ||
2323 | /* | |
2324 | * Loop over nve groups | |
2325 | */ | |
2326 | for (ALL_LIST_ELEMENTS_RO (bgp->rfapi_cfg->nve_groups_sequential, n, rfg)) | |
2327 | { | |
2328 | ||
2329 | if (rfg->routemap_export_bgp_name) | |
2330 | { | |
2331 | rfg->routemap_export_bgp = | |
2332 | route_map_lookup_by_name (rfg->routemap_export_bgp_name); | |
2333 | } | |
2334 | if (rfg->routemap_export_zebra_name) | |
2335 | { | |
2336 | rfg->routemap_export_bgp = | |
2337 | route_map_lookup_by_name (rfg->routemap_export_zebra_name); | |
2338 | } | |
2339 | for (i = 0; i < ZEBRA_ROUTE_MAX; ++i) | |
2340 | { | |
2341 | if (rfg->routemap_redist_name[i]) | |
2342 | { | |
2343 | rfg->routemap_redist[i] = | |
2344 | route_map_lookup_by_name (rfg->routemap_redist_name[i]); | |
2345 | } | |
2346 | } | |
2347 | ||
2348 | vnc_direct_bgp_reexport_group_afi (bgp, rfg, AFI_IP); | |
2349 | vnc_direct_bgp_reexport_group_afi (bgp, rfg, AFI_IP6); | |
2350 | /* TBD vnc_zebra_reexport_group_afi(bgp, rfg, afi); */ | |
2351 | } | |
2352 | ||
2353 | /* | |
2354 | * RH config, too | |
2355 | */ | |
2356 | if (hc->routemap_export_bgp_name) | |
2357 | { | |
2358 | hc->routemap_export_bgp = | |
2359 | route_map_lookup_by_name (hc->routemap_export_bgp_name); | |
2360 | } | |
2361 | if (hc->routemap_export_zebra_name) | |
2362 | { | |
2363 | hc->routemap_export_bgp = | |
2364 | route_map_lookup_by_name (hc->routemap_export_zebra_name); | |
2365 | } | |
2366 | for (i = 0; i < ZEBRA_ROUTE_MAX; ++i) | |
2367 | { | |
2368 | if (hc->routemap_redist_name[i]) | |
2369 | { | |
2370 | hc->routemap_redist[i] = | |
2371 | route_map_lookup_by_name (hc->routemap_redist_name[i]); | |
2372 | } | |
2373 | } | |
2374 | ||
2375 | vnc_direct_bgp_reexport (bgp, AFI_IP); | |
2376 | vnc_direct_bgp_reexport (bgp, AFI_IP6); | |
2377 | ||
2378 | /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */ | |
2379 | /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */ | |
2380 | ||
2381 | vnc_redistribute_prechange (bgp); | |
2382 | vnc_redistribute_postchange (bgp); | |
2383 | ||
a3b55c25 | 2384 | vnc_zlog_debug_verbose ("%s done", __func__); |
65efcfce LB |
2385 | } |
2386 | ||
2387 | static void | |
2388 | vnc_routemap_event (route_map_event_t type, /* ignored */ | |
2389 | const char *rmap_name) /* ignored */ | |
2390 | { | |
2391 | struct listnode *mnode, *mnnode; | |
2392 | struct bgp *bgp; | |
2393 | ||
a3b55c25 | 2394 | vnc_zlog_debug_verbose ("%s(event type=%d)", __func__, type); |
65efcfce LB |
2395 | if (bm->bgp == NULL) /* may be called during cleanup */ |
2396 | return; | |
2397 | ||
2398 | for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp)) | |
2399 | vnc_routemap_update (bgp, rmap_name); | |
2400 | ||
a3b55c25 | 2401 | vnc_zlog_debug_verbose ("%s: done", __func__); |
65efcfce LB |
2402 | } |
2403 | ||
2404 | /*------------------------------------------------------------------------- | |
2405 | * nve-group | |
2406 | *-----------------------------------------------------------------------*/ | |
2407 | ||
2408 | ||
2409 | DEFUN (vnc_nve_group, | |
2410 | vnc_nve_group_cmd, | |
2411 | "vnc nve-group NAME", | |
2412 | VNC_CONFIG_STR "Configure a NVE group\n" "Group name\n") | |
2413 | { | |
cdc2d765 | 2414 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 2415 | struct rfapi_nve_group_cfg *rfg; |
65efcfce LB |
2416 | struct listnode *node, *nnode; |
2417 | struct rfapi_rfg_name *rfgn; | |
2418 | ||
65efcfce | 2419 | /* Search for name */ |
aed3273f | 2420 | rfg = rfapi_group_lookup_byname (bgp, argv[2]->arg); |
65efcfce LB |
2421 | |
2422 | if (!rfg) | |
2423 | { | |
2424 | rfg = rfapi_group_new (); | |
2425 | if (!rfg) | |
2426 | { | |
2427 | /* Error out of memory */ | |
2428 | vty_out (vty, "Can't allocate memory for NVE group%s", VTY_NEWLINE); | |
2429 | return CMD_WARNING; | |
2430 | } | |
aed3273f | 2431 | rfg->name = strdup (argv[2]->arg); |
65efcfce LB |
2432 | /* add to tail of list */ |
2433 | listnode_add (bgp->rfapi_cfg->nve_groups_sequential, rfg); | |
2434 | ||
2435 | /* Copy defaults from struct rfapi_cfg */ | |
2436 | rfg->rd = bgp->rfapi_cfg->default_rd; | |
2437 | if (bgp->rfapi_cfg->flags & BGP_VNC_CONFIG_L2RD) | |
2438 | { | |
2439 | rfg->l2rd = bgp->rfapi_cfg->default_l2rd; | |
2440 | rfg->flags |= RFAPI_RFG_L2RD; | |
2441 | } | |
2442 | rfg->rd = bgp->rfapi_cfg->default_rd; | |
2443 | rfg->response_lifetime = bgp->rfapi_cfg->default_response_lifetime; | |
2444 | ||
2445 | if (bgp->rfapi_cfg->default_rt_export_list) | |
2446 | { | |
2447 | rfg->rt_export_list = | |
2448 | ecommunity_dup (bgp->rfapi_cfg->default_rt_export_list); | |
2449 | } | |
2450 | ||
2451 | if (bgp->rfapi_cfg->default_rt_import_list) | |
2452 | { | |
2453 | rfg->rt_import_list = | |
2454 | ecommunity_dup (bgp->rfapi_cfg->default_rt_import_list); | |
2455 | rfg->rfapi_import_table = | |
2456 | rfapiImportTableRefAdd (bgp, rfg->rt_import_list); | |
2457 | } | |
2458 | ||
2459 | /* | |
2460 | * If a redist nve group was named but the group was not defined, | |
2461 | * make the linkage now | |
2462 | */ | |
2463 | if (!bgp->rfapi_cfg->rfg_redist) | |
2464 | { | |
2465 | if (bgp->rfapi_cfg->rfg_redist_name && | |
2466 | !strcmp (bgp->rfapi_cfg->rfg_redist_name, rfg->name)) | |
2467 | { | |
2468 | ||
2469 | vnc_redistribute_prechange (bgp); | |
2470 | bgp->rfapi_cfg->rfg_redist = rfg; | |
2471 | vnc_redistribute_postchange (bgp); | |
2472 | ||
2473 | } | |
2474 | } | |
2475 | ||
2476 | /* | |
2477 | * Same treatment for bgp-direct export group | |
2478 | */ | |
2479 | for (ALL_LIST_ELEMENTS (bgp->rfapi_cfg->rfg_export_direct_bgp_l, | |
2480 | node, nnode, rfgn)) | |
2481 | { | |
2482 | ||
2483 | if (!strcmp (rfgn->name, rfg->name)) | |
2484 | { | |
2485 | rfgn->rfg = rfg; | |
2486 | vnc_direct_bgp_add_group (bgp, rfg); | |
2487 | break; | |
2488 | } | |
2489 | } | |
2490 | ||
2491 | /* | |
2492 | * Same treatment for zebra export group | |
2493 | */ | |
2494 | for (ALL_LIST_ELEMENTS (bgp->rfapi_cfg->rfg_export_zebra_l, | |
2495 | node, nnode, rfgn)) | |
2496 | { | |
2497 | ||
a3b55c25 | 2498 | vnc_zlog_debug_verbose ("%s: ezport zebra: checking if \"%s\" == \"%s\"", |
65efcfce LB |
2499 | __func__, rfgn->name, rfg->name); |
2500 | if (!strcmp (rfgn->name, rfg->name)) | |
2501 | { | |
2502 | rfgn->rfg = rfg; | |
2503 | vnc_zebra_add_group (bgp, rfg); | |
2504 | break; | |
2505 | } | |
2506 | } | |
2507 | } | |
2508 | ||
2509 | /* | |
2510 | * XXX subsequent calls will need to make sure this item is still | |
2511 | * in the linked list and has the same name | |
2512 | */ | |
c77272a1 | 2513 | VTY_PUSH_CONTEXT_SUB (BGP_VNC_NVE_GROUP_NODE, rfg); |
65efcfce | 2514 | |
65efcfce LB |
2515 | return CMD_SUCCESS; |
2516 | } | |
2517 | ||
2518 | static void | |
2519 | bgp_rfapi_delete_nve_group ( | |
2520 | struct vty *vty, /* NULL = no output */ | |
2521 | struct bgp *bgp, | |
2522 | struct rfapi_nve_group_cfg *rfg) | |
2523 | { | |
2524 | struct list *orphaned_nves = NULL; | |
2525 | struct listnode *node, *nnode; | |
2526 | ||
2527 | /* | |
2528 | * If there are currently-open NVEs that belong to this group, | |
2529 | * zero out their references to this group structure. | |
2530 | */ | |
2531 | if (rfg->nves) | |
2532 | { | |
2533 | struct rfapi_descriptor *rfd; | |
2534 | orphaned_nves = list_new (); | |
2535 | while ((rfd = listnode_head (rfg->nves))) | |
2536 | { | |
2537 | rfd->rfg = NULL; | |
2538 | listnode_delete (rfg->nves, rfd); | |
2539 | listnode_add (orphaned_nves, rfd); | |
2540 | } | |
2541 | list_delete (rfg->nves); | |
2542 | rfg->nves = NULL; | |
2543 | } | |
2544 | ||
2545 | /* delete it */ | |
2546 | free (rfg->name); | |
2547 | if (rfg->rfapi_import_table) | |
2548 | rfapiImportTableRefDelByIt (bgp, rfg->rfapi_import_table); | |
2549 | if (rfg->rt_import_list) | |
2550 | ecommunity_free (&rfg->rt_import_list); | |
2551 | if (rfg->rt_export_list) | |
2552 | ecommunity_free (&rfg->rt_export_list); | |
2553 | ||
2554 | if (rfg->vn_node) | |
2555 | { | |
2556 | rfg->vn_node->info = NULL; | |
2557 | route_unlock_node (rfg->vn_node); /* frees */ | |
2558 | } | |
2559 | if (rfg->un_node) | |
2560 | { | |
2561 | rfg->un_node->info = NULL; | |
2562 | route_unlock_node (rfg->un_node); /* frees */ | |
2563 | } | |
2564 | if (rfg->rfp_cfg) | |
2565 | XFREE (MTYPE_RFAPI_RFP_GROUP_CFG, rfg->rfp_cfg); | |
2566 | listnode_delete (bgp->rfapi_cfg->nve_groups_sequential, rfg); | |
2567 | ||
ea8a9825 | 2568 | QOBJ_UNREG (rfg); |
65efcfce LB |
2569 | XFREE (MTYPE_RFAPI_GROUP_CFG, rfg); |
2570 | ||
2571 | /* | |
2572 | * Attempt to reassign the orphaned nves to a new group. If | |
2573 | * a NVE can not be reassigned, its rfd->rfg will remain NULL | |
2574 | * and it will become a zombie until released by rfapi_close(). | |
2575 | */ | |
2576 | if (orphaned_nves) | |
2577 | { | |
2578 | struct rfapi_descriptor *rfd; | |
2579 | ||
2580 | for (ALL_LIST_ELEMENTS (orphaned_nves, node, nnode, rfd)) | |
2581 | { | |
2582 | /* | |
2583 | * 1. rfapi_close() equivalent except: | |
2584 | * a. don't free original descriptor | |
2585 | * b. remember query list | |
2586 | * c. remember advertised route list | |
2587 | * 2. rfapi_open() equivalent except: | |
2588 | * a. reuse original descriptor | |
2589 | * 3. rfapi_register() on remembered advertised route list | |
2590 | * 4. rfapi_query on rememebred query list | |
2591 | */ | |
2592 | ||
2593 | int rc; | |
2594 | ||
2595 | rc = rfapi_reopen (rfd, bgp); | |
2596 | ||
2597 | if (!rc) | |
2598 | { | |
2599 | list_delete_node (orphaned_nves, node); | |
2600 | if (vty) | |
2601 | vty_out (vty, "WARNING: reassigned NVE vn="); | |
2602 | rfapiPrintRfapiIpAddr (vty, &rfd->vn_addr); | |
2603 | if (vty) | |
2604 | vty_out (vty, " un="); | |
2605 | rfapiPrintRfapiIpAddr (vty, &rfd->un_addr); | |
2606 | if (vty) | |
2607 | vty_out (vty, " to new group \"%s\"%s", rfd->rfg->name, | |
2608 | VTY_NEWLINE); | |
2609 | ||
2610 | } | |
2611 | } | |
2612 | ||
2613 | for (ALL_LIST_ELEMENTS_RO (orphaned_nves, node, rfd)) | |
2614 | { | |
2615 | if (vty) | |
2616 | vty_out (vty, "WARNING: orphaned NVE vn="); | |
2617 | rfapiPrintRfapiIpAddr (vty, &rfd->vn_addr); | |
2618 | if (vty) | |
2619 | vty_out (vty, " un="); | |
2620 | rfapiPrintRfapiIpAddr (vty, &rfd->un_addr); | |
2621 | if (vty) | |
2622 | vty_out (vty, "%s", VTY_NEWLINE); | |
2623 | } | |
2624 | list_delete (orphaned_nves); | |
2625 | } | |
2626 | } | |
2627 | ||
2628 | static int | |
2629 | bgp_rfapi_delete_named_nve_group ( | |
2630 | struct vty *vty, /* NULL = no output */ | |
2631 | struct bgp *bgp, | |
2632 | const char *rfg_name) /* NULL = any */ | |
2633 | { | |
2634 | struct rfapi_nve_group_cfg *rfg = NULL; | |
2635 | struct listnode *node, *nnode; | |
2636 | struct rfapi_rfg_name *rfgn; | |
2637 | ||
2638 | /* Search for name */ | |
2639 | if (rfg_name) | |
2640 | { | |
2641 | rfg = rfapi_group_lookup_byname (bgp, rfg_name); | |
2642 | if (!rfg) | |
2643 | { | |
2644 | if (vty) | |
2645 | vty_out (vty, "No NVE group named \"%s\"%s", rfg_name, | |
2646 | VTY_NEWLINE); | |
2647 | return CMD_WARNING; | |
2648 | } | |
2649 | } | |
2650 | ||
2651 | /* | |
2652 | * If this group is the redist nve group, unlink it | |
2653 | */ | |
2654 | if (rfg_name == NULL || bgp->rfapi_cfg->rfg_redist == rfg) | |
2655 | { | |
2656 | vnc_redistribute_prechange (bgp); | |
2657 | bgp->rfapi_cfg->rfg_redist = NULL; | |
2658 | vnc_redistribute_postchange (bgp); | |
2659 | } | |
2660 | ||
2661 | ||
2662 | /* | |
2663 | * remove reference from bgp direct export list | |
2664 | */ | |
2665 | for (ALL_LIST_ELEMENTS_RO (bgp->rfapi_cfg->rfg_export_direct_bgp_l, | |
2666 | node, rfgn)) | |
2667 | { | |
2668 | if (rfg_name == NULL || !strcmp (rfgn->name, rfg_name)) | |
2669 | { | |
2670 | rfgn->rfg = NULL; | |
2671 | /* remove exported routes from this group */ | |
2672 | vnc_direct_bgp_del_group (bgp, rfg); | |
2673 | break; | |
2674 | } | |
2675 | } | |
2676 | ||
2677 | /* | |
2678 | * remove reference from zebra export list | |
2679 | */ | |
2680 | for (ALL_LIST_ELEMENTS_RO (bgp->rfapi_cfg->rfg_export_zebra_l, node, rfgn)) | |
2681 | { | |
2682 | ||
2683 | if (rfg_name == NULL || !strcmp (rfgn->name, rfg_name)) | |
2684 | { | |
2685 | rfgn->rfg = NULL; | |
2686 | /* remove exported routes from this group */ | |
2687 | vnc_zebra_del_group (bgp, rfg); | |
2688 | break; | |
2689 | } | |
2690 | } | |
2691 | if (rfg) | |
2692 | bgp_rfapi_delete_nve_group (vty, bgp, rfg); | |
2693 | else /* must be delete all */ | |
2694 | for (ALL_LIST_ELEMENTS | |
2695 | (bgp->rfapi_cfg->nve_groups_sequential, node, nnode, rfg)) | |
2696 | bgp_rfapi_delete_nve_group (vty, bgp, rfg); | |
2697 | return CMD_SUCCESS; | |
2698 | } | |
2699 | ||
2700 | DEFUN (vnc_no_nve_group, | |
2701 | vnc_no_nve_group_cmd, | |
2702 | "no vnc nve-group NAME", | |
2703 | NO_STR | |
2704 | VNC_CONFIG_STR | |
2705 | "Configure a NVE group\n" | |
2706 | "Group name\n") | |
2707 | { | |
cdc2d765 | 2708 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 2709 | |
aed3273f | 2710 | return bgp_rfapi_delete_named_nve_group (vty, bgp, argv[3]->arg); |
65efcfce LB |
2711 | } |
2712 | ||
2713 | DEFUN (vnc_nve_group_prefix, | |
2714 | vnc_nve_group_prefix_cmd, | |
034d2de2 | 2715 | "prefix <vn|un> <A.B.C.D/M|X:X::X:X/M>", |
65efcfce LB |
2716 | "Specify prefixes matching NVE VN or UN interfaces\n" |
2717 | "VN prefix\n" | |
2718 | "UN prefix\n" | |
2719 | "IPv4 prefix\n" | |
2720 | "IPv6 prefix\n") | |
2721 | { | |
cdc2d765 | 2722 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 2723 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce LB |
2724 | struct prefix p; |
2725 | int afi; | |
2726 | struct route_table *rt; | |
2727 | struct route_node *rn; | |
2728 | int is_un_prefix = 0; | |
2729 | ||
65efcfce LB |
2730 | /* make sure it's still in list */ |
2731 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
2732 | { | |
2733 | /* Not in list anymore */ | |
2734 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
2735 | return CMD_WARNING; | |
2736 | } | |
2737 | ||
aed3273f | 2738 | if (!str2prefix (argv[2]->arg, &p)) |
65efcfce | 2739 | { |
aed3273f | 2740 | vty_out (vty, "Malformed prefix \"%s\"%s", argv[2]->arg, VTY_NEWLINE); |
65efcfce LB |
2741 | return CMD_WARNING; |
2742 | } | |
2743 | ||
2744 | afi = family2afi (p.family); | |
2745 | if (!afi) | |
2746 | { | |
2747 | vty_out (vty, "Unsupported address family%s", VTY_NEWLINE); | |
2748 | return CMD_WARNING; | |
2749 | } | |
2750 | ||
aed3273f | 2751 | if (argv[1]->arg[0] == 'u') |
65efcfce LB |
2752 | { |
2753 | rt = &(bgp->rfapi_cfg->nve_groups_un[afi]); | |
2754 | is_un_prefix = 1; | |
2755 | } | |
2756 | else | |
2757 | { | |
2758 | rt = &(bgp->rfapi_cfg->nve_groups_vn[afi]); | |
2759 | } | |
2760 | ||
2761 | rn = route_node_get (rt, &p); /* NB locks node */ | |
2762 | if (rn->info) | |
2763 | { | |
2764 | /* | |
2765 | * There is already a group with this prefix | |
2766 | */ | |
2767 | route_unlock_node (rn); | |
2768 | if (rn->info != rfg) | |
2769 | { | |
2770 | /* | |
2771 | * different group name: fail | |
2772 | */ | |
2773 | vty_out (vty, "nve group \"%s\" already has \"%s\" prefix %s%s", | |
2774 | ((struct rfapi_nve_group_cfg *) (rn->info))->name, | |
aed3273f | 2775 | argv[1]->arg, argv[2]->arg, VTY_NEWLINE); |
65efcfce LB |
2776 | return CMD_WARNING; |
2777 | } | |
2778 | else | |
2779 | { | |
2780 | /* | |
2781 | * same group name: it's already in the correct place | |
2782 | * in the table, so we're done. | |
2783 | * | |
2784 | * Implies rfg->(vn|un)_prefix is already correct. | |
2785 | */ | |
2786 | return CMD_SUCCESS; | |
2787 | } | |
2788 | } | |
2789 | ||
2790 | if (bgp->rfapi_cfg->rfg_redist == rfg) | |
2791 | { | |
2792 | vnc_redistribute_prechange (bgp); | |
2793 | } | |
2794 | ||
2795 | /* New prefix, new node */ | |
2796 | ||
2797 | if (is_un_prefix) | |
2798 | { | |
2799 | ||
2800 | /* detach rfg from previous route table location */ | |
2801 | if (rfg->un_node) | |
2802 | { | |
2803 | rfg->un_node->info = NULL; | |
2804 | route_unlock_node (rfg->un_node); /* frees */ | |
2805 | } | |
2806 | rfg->un_node = rn; /* back ref */ | |
2807 | rfg->un_prefix = p; | |
2808 | ||
2809 | } | |
2810 | else | |
2811 | { | |
2812 | ||
2813 | /* detach rfg from previous route table location */ | |
2814 | if (rfg->vn_node) | |
2815 | { | |
2816 | rfg->vn_node->info = NULL; | |
2817 | route_unlock_node (rfg->vn_node); /* frees */ | |
2818 | } | |
2819 | rfg->vn_node = rn; /* back ref */ | |
2820 | rfg->vn_prefix = p; | |
2821 | } | |
2822 | ||
2823 | /* attach */ | |
2824 | rn->info = rfg; | |
2825 | ||
2826 | if (bgp->rfapi_cfg->rfg_redist == rfg) | |
2827 | { | |
2828 | vnc_redistribute_postchange (bgp); | |
2829 | } | |
2830 | ||
2831 | return CMD_SUCCESS; | |
2832 | } | |
2833 | ||
2834 | DEFUN (vnc_nve_group_rt_import, | |
2835 | vnc_nve_group_rt_import_cmd, | |
bdffbcef | 2836 | "rt import RTLIST", |
65efcfce LB |
2837 | "Specify route targets\n" |
2838 | "Import filter\n" | |
2839 | "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n") | |
2840 | { | |
cdc2d765 | 2841 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 2842 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce LB |
2843 | int rc; |
2844 | struct listnode *node; | |
2845 | struct rfapi_rfg_name *rfgn; | |
2846 | int is_export_bgp = 0; | |
2847 | int is_export_zebra = 0; | |
2848 | ||
65efcfce LB |
2849 | /* make sure it's still in list */ |
2850 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
2851 | { | |
2852 | /* Not in list anymore */ | |
2853 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
2854 | return CMD_WARNING; | |
2855 | } | |
2856 | ||
aed3273f | 2857 | rc = set_ecom_list (vty, argc - 2, argv + 2, &rfg->rt_import_list); |
65efcfce LB |
2858 | if (rc != CMD_SUCCESS) |
2859 | return rc; | |
2860 | ||
2861 | for (ALL_LIST_ELEMENTS_RO (bgp->rfapi_cfg->rfg_export_direct_bgp_l, | |
2862 | node, rfgn)) | |
2863 | { | |
2864 | ||
2865 | if (rfgn->rfg == rfg) | |
2866 | { | |
2867 | is_export_bgp = 1; | |
2868 | break; | |
2869 | } | |
2870 | } | |
2871 | ||
2872 | if (is_export_bgp) | |
2873 | vnc_direct_bgp_del_group (bgp, rfg); | |
2874 | ||
2875 | for (ALL_LIST_ELEMENTS_RO (bgp->rfapi_cfg->rfg_export_zebra_l, node, rfgn)) | |
2876 | { | |
2877 | ||
2878 | if (rfgn->rfg == rfg) | |
2879 | { | |
2880 | is_export_zebra = 1; | |
2881 | break; | |
2882 | } | |
2883 | } | |
2884 | ||
2885 | if (is_export_zebra) | |
2886 | vnc_zebra_del_group (bgp, rfg); | |
2887 | ||
2888 | /* | |
2889 | * stop referencing old import table, now reference new one | |
2890 | */ | |
2891 | if (rfg->rfapi_import_table) | |
2892 | rfapiImportTableRefDelByIt (bgp, rfg->rfapi_import_table); | |
2893 | rfg->rfapi_import_table = rfapiImportTableRefAdd (bgp, rfg->rt_import_list); | |
2894 | ||
2895 | if (is_export_bgp) | |
2896 | vnc_direct_bgp_add_group (bgp, rfg); | |
2897 | ||
2898 | if (is_export_zebra) | |
2899 | vnc_zebra_add_group (bgp, rfg); | |
2900 | ||
2901 | return CMD_SUCCESS; | |
2902 | } | |
2903 | ||
2904 | DEFUN (vnc_nve_group_rt_export, | |
2905 | vnc_nve_group_rt_export_cmd, | |
bdffbcef | 2906 | "rt export RTLIST", |
65efcfce LB |
2907 | "Specify route targets\n" |
2908 | "Export filter\n" | |
2909 | "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n") | |
2910 | { | |
cdc2d765 | 2911 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 2912 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce LB |
2913 | int rc; |
2914 | ||
65efcfce LB |
2915 | /* make sure it's still in list */ |
2916 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
2917 | { | |
2918 | /* Not in list anymore */ | |
2919 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
2920 | return CMD_WARNING; | |
2921 | } | |
2922 | ||
2923 | if (bgp->rfapi_cfg->rfg_redist == rfg) | |
2924 | { | |
2925 | vnc_redistribute_prechange (bgp); | |
2926 | } | |
2927 | ||
aed3273f | 2928 | rc = set_ecom_list (vty, argc - 2, argv + 2, &rfg->rt_export_list); |
65efcfce LB |
2929 | |
2930 | if (bgp->rfapi_cfg->rfg_redist == rfg) | |
2931 | { | |
2932 | vnc_redistribute_postchange (bgp); | |
2933 | } | |
2934 | ||
2935 | return rc; | |
2936 | } | |
2937 | ||
2938 | DEFUN (vnc_nve_group_rt_both, | |
2939 | vnc_nve_group_rt_both_cmd, | |
bdffbcef | 2940 | "rt both RTLIST", |
65efcfce LB |
2941 | "Specify route targets\n" |
2942 | "Export+import filters\n" | |
2943 | "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n") | |
2944 | { | |
cdc2d765 | 2945 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 2946 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce LB |
2947 | int rc; |
2948 | int is_export_bgp = 0; | |
2949 | int is_export_zebra = 0; | |
2950 | struct listnode *node; | |
2951 | struct rfapi_rfg_name *rfgn; | |
2952 | ||
65efcfce LB |
2953 | /* make sure it's still in list */ |
2954 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
2955 | { | |
2956 | /* Not in list anymore */ | |
2957 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
2958 | return CMD_WARNING; | |
2959 | } | |
2960 | ||
aed3273f | 2961 | rc = set_ecom_list (vty, argc - 2, argv + 2, &rfg->rt_import_list); |
65efcfce LB |
2962 | if (rc != CMD_SUCCESS) |
2963 | return rc; | |
2964 | ||
2965 | for (ALL_LIST_ELEMENTS_RO (bgp->rfapi_cfg->rfg_export_direct_bgp_l, | |
2966 | node, rfgn)) | |
2967 | { | |
2968 | ||
2969 | if (rfgn->rfg == rfg) | |
2970 | { | |
2971 | is_export_bgp = 1; | |
2972 | break; | |
2973 | } | |
2974 | } | |
2975 | ||
2976 | if (is_export_bgp) | |
2977 | vnc_direct_bgp_del_group (bgp, rfg); | |
2978 | ||
2979 | for (ALL_LIST_ELEMENTS_RO (bgp->rfapi_cfg->rfg_export_zebra_l, node, rfgn)) | |
2980 | { | |
2981 | ||
2982 | if (rfgn->rfg == rfg) | |
2983 | { | |
2984 | is_export_zebra = 1; | |
2985 | break; | |
2986 | } | |
2987 | } | |
2988 | ||
2989 | if (is_export_zebra) | |
2990 | { | |
a3b55c25 | 2991 | vnc_zlog_debug_verbose ("%s: is_export_zebra", __func__); |
65efcfce LB |
2992 | vnc_zebra_del_group (bgp, rfg); |
2993 | } | |
2994 | ||
2995 | /* | |
2996 | * stop referencing old import table, now reference new one | |
2997 | */ | |
2998 | if (rfg->rfapi_import_table) | |
2999 | rfapiImportTableRefDelByIt (bgp, rfg->rfapi_import_table); | |
3000 | rfg->rfapi_import_table = rfapiImportTableRefAdd (bgp, rfg->rt_import_list); | |
3001 | ||
3002 | if (is_export_bgp) | |
3003 | vnc_direct_bgp_add_group (bgp, rfg); | |
3004 | ||
3005 | if (is_export_zebra) | |
3006 | vnc_zebra_add_group (bgp, rfg); | |
3007 | ||
3008 | if (bgp->rfapi_cfg->rfg_redist == rfg) | |
3009 | { | |
3010 | vnc_redistribute_prechange (bgp); | |
3011 | } | |
3012 | ||
aed3273f | 3013 | rc = set_ecom_list (vty, argc - 2, argv + 2, &rfg->rt_export_list); |
65efcfce LB |
3014 | |
3015 | if (bgp->rfapi_cfg->rfg_redist == rfg) | |
3016 | { | |
3017 | vnc_redistribute_postchange (bgp); | |
3018 | } | |
3019 | ||
3020 | return rc; | |
3021 | ||
3022 | } | |
3023 | ||
3024 | DEFUN (vnc_nve_group_l2rd, | |
3025 | vnc_nve_group_l2rd_cmd, | |
bdffbcef | 3026 | "l2rd <(1-255)|auto-vn>", |
65efcfce LB |
3027 | "Specify default Local Nve ID value to use in RD for L2 routes\n" |
3028 | "Fixed value 1-255\n" | |
3029 | "use the low-order octet of the NVE's VN address\n") | |
3030 | { | |
cdc2d765 | 3031 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 3032 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce | 3033 | |
65efcfce LB |
3034 | /* make sure it's still in list */ |
3035 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
3036 | { | |
3037 | /* Not in list anymore */ | |
3038 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
3039 | return CMD_WARNING; | |
3040 | } | |
3041 | ||
aed3273f | 3042 | if (!strcmp (argv[1]->arg, "auto:vn")) |
65efcfce LB |
3043 | { |
3044 | rfg->l2rd = 0; | |
3045 | } | |
3046 | else | |
3047 | { | |
3048 | char *end = NULL; | |
aed3273f | 3049 | unsigned long value_l = strtoul (argv[1]->arg, &end, 10); |
65efcfce LB |
3050 | uint8_t value = value_l & 0xff; |
3051 | ||
aed3273f | 3052 | if (!argv[1]->arg[0] || *end) |
65efcfce | 3053 | { |
aed3273f | 3054 | vty_out (vty, "%% Malformed l2 nve ID \"%s\"%s", argv[1]->arg, |
65efcfce LB |
3055 | VTY_NEWLINE); |
3056 | return CMD_WARNING; | |
3057 | } | |
3058 | if ((value_l < 1) || (value_l > 0xff)) | |
3059 | { | |
3060 | vty_out (vty, | |
3061 | "%% Malformed l2 nve id (must be greater than 0 and less than %u%s", | |
3062 | 0x100, VTY_NEWLINE); | |
3063 | return CMD_WARNING; | |
3064 | } | |
3065 | ||
3066 | rfg->l2rd = value; | |
3067 | } | |
3068 | rfg->flags |= RFAPI_RFG_L2RD; | |
3069 | ||
3070 | return CMD_SUCCESS; | |
3071 | } | |
3072 | ||
3073 | DEFUN (vnc_nve_group_no_l2rd, | |
3074 | vnc_nve_group_no_l2rd_cmd, | |
3075 | "no l2rd", | |
3076 | NO_STR | |
3077 | "Specify default Local Nve ID value to use in RD for L2 routes\n") | |
3078 | { | |
cdc2d765 | 3079 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 3080 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce | 3081 | |
65efcfce LB |
3082 | /* make sure it's still in list */ |
3083 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
3084 | { | |
3085 | /* Not in list anymore */ | |
3086 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
3087 | return CMD_WARNING; | |
3088 | } | |
3089 | ||
3090 | rfg->l2rd = 0; | |
3091 | rfg->flags &= ~RFAPI_RFG_L2RD; | |
3092 | ||
3093 | return CMD_SUCCESS; | |
3094 | } | |
3095 | ||
3096 | DEFUN (vnc_nve_group_rd, | |
3097 | vnc_nve_group_rd_cmd, | |
3098 | "rd ASN:nn_or_IP-address:nn", | |
3099 | "Specify route distinguisher\n" | |
3100 | "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:vn:<number> )\n") | |
3101 | { | |
cdc2d765 | 3102 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce LB |
3103 | int ret; |
3104 | struct prefix_rd prd; | |
c77272a1 | 3105 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce | 3106 | |
65efcfce LB |
3107 | /* make sure it's still in list */ |
3108 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
3109 | { | |
3110 | /* Not in list anymore */ | |
3111 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
3112 | return CMD_WARNING; | |
3113 | } | |
3114 | ||
aed3273f | 3115 | if (!strncmp (argv[1]->arg, "auto:vn:", 8)) |
65efcfce LB |
3116 | { |
3117 | /* | |
3118 | * use AF_UNIX to designate automatically-assigned RD | |
3119 | * auto:vn:nn where nn is a 2-octet quantity | |
3120 | */ | |
3121 | char *end = NULL; | |
aed3273f | 3122 | uint32_t value32 = strtoul (argv[1]->arg + 8, &end, 10); |
65efcfce LB |
3123 | uint16_t value = value32 & 0xffff; |
3124 | ||
aed3273f | 3125 | if (!argv[1]->arg[8] || *end) |
65efcfce LB |
3126 | { |
3127 | vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE); | |
3128 | return CMD_WARNING; | |
3129 | } | |
3130 | if (value32 > 0xffff) | |
3131 | { | |
3132 | vty_out (vty, "%% Malformed rd (must be less than %u%s", | |
3133 | 0x0ffff, VTY_NEWLINE); | |
3134 | return CMD_WARNING; | |
3135 | } | |
3136 | ||
3137 | memset (&prd, 0, sizeof (prd)); | |
3138 | prd.family = AF_UNIX; | |
3139 | prd.prefixlen = 64; | |
3140 | prd.val[0] = (RD_TYPE_IP >> 8) & 0x0ff; | |
3141 | prd.val[1] = RD_TYPE_IP & 0x0ff; | |
3142 | prd.val[6] = (value >> 8) & 0x0ff; | |
3143 | prd.val[7] = value & 0x0ff; | |
3144 | ||
3145 | } | |
3146 | else | |
3147 | { | |
3148 | ||
aed3273f | 3149 | ret = str2prefix_rd (argv[1]->arg, &prd); |
65efcfce LB |
3150 | if (!ret) |
3151 | { | |
3152 | vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE); | |
3153 | return CMD_WARNING; | |
3154 | } | |
3155 | } | |
3156 | ||
3157 | if (bgp->rfapi_cfg->rfg_redist == rfg) | |
3158 | { | |
3159 | vnc_redistribute_prechange (bgp); | |
3160 | } | |
3161 | ||
3162 | rfg->rd = prd; | |
3163 | ||
3164 | if (bgp->rfapi_cfg->rfg_redist == rfg) | |
3165 | { | |
3166 | vnc_redistribute_postchange (bgp); | |
3167 | } | |
3168 | return CMD_SUCCESS; | |
3169 | } | |
3170 | ||
3171 | DEFUN (vnc_nve_group_responselifetime, | |
3172 | vnc_nve_group_responselifetime_cmd, | |
034d2de2 | 3173 | "response-lifetime <LIFETIME|infinite>", |
65efcfce LB |
3174 | "Specify response lifetime\n" |
3175 | "Response lifetime in seconds\n" "Infinite response lifetime\n") | |
3176 | { | |
cdc2d765 | 3177 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 3178 | unsigned int rspint; |
c77272a1 | 3179 | VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); |
65efcfce LB |
3180 | struct rfapi_descriptor *rfd; |
3181 | struct listnode *hdnode; | |
3182 | ||
65efcfce LB |
3183 | /* make sure it's still in list */ |
3184 | if (!listnode_lookup (bgp->rfapi_cfg->nve_groups_sequential, rfg)) | |
3185 | { | |
3186 | /* Not in list anymore */ | |
3187 | vty_out (vty, "Current NVE group no longer exists%s", VTY_NEWLINE); | |
3188 | return CMD_WARNING; | |
3189 | } | |
3190 | ||
aed3273f | 3191 | if (!strcmp (argv[1]->arg, "infinite")) |
65efcfce LB |
3192 | { |
3193 | rspint = RFAPI_INFINITE_LIFETIME; | |
3194 | } | |
3195 | else | |
3196 | { | |
aed3273f | 3197 | VTY_GET_INTEGER ("Response Lifetime", rspint, argv[1]->arg); |
65efcfce LB |
3198 | } |
3199 | ||
3200 | rfg->response_lifetime = rspint; | |
3201 | rfg->flags |= RFAPI_RFG_RESPONSE_LIFETIME; | |
3202 | if (rfg->nves) | |
3203 | for (ALL_LIST_ELEMENTS_RO (rfg->nves, hdnode, rfd)) | |
3204 | rfd->response_lifetime = rspint; | |
3205 | return CMD_SUCCESS; | |
3206 | } | |
3207 | ||
3208 | /* | |
3209 | * Sigh. This command, like exit-address-family, is a hack to deal | |
3210 | * with the lack of rigorous level control in the command handler. | |
3211 | * TBD fix command handler. | |
3212 | */ | |
3213 | DEFUN (exit_vnc, | |
3214 | exit_vnc_cmd, | |
3215 | "exit-vnc", | |
3216 | "Exit VNC configuration mode\n") | |
3217 | { | |
3218 | if (vty->node == BGP_VNC_DEFAULTS_NODE || | |
3219 | vty->node == BGP_VNC_NVE_GROUP_NODE || | |
3220 | vty->node == BGP_VNC_L2_GROUP_NODE) | |
3221 | { | |
3222 | ||
3223 | vty->node = BGP_NODE; | |
3224 | } | |
3225 | return CMD_SUCCESS; | |
3226 | } | |
3227 | ||
3228 | static struct cmd_node bgp_vnc_defaults_node = { | |
3229 | BGP_VNC_DEFAULTS_NODE, | |
3230 | "%s(config-router-vnc-defaults)# ", | |
3231 | 1 | |
3232 | }; | |
3233 | ||
3234 | static struct cmd_node bgp_vnc_nve_group_node = { | |
3235 | BGP_VNC_NVE_GROUP_NODE, | |
3236 | "%s(config-router-vnc-nve-group)# ", | |
3237 | 1 | |
3238 | }; | |
3239 | ||
3240 | /*------------------------------------------------------------------------- | |
3241 | * vnc-l2-group | |
3242 | *-----------------------------------------------------------------------*/ | |
3243 | ||
3244 | ||
3245 | DEFUN (vnc_l2_group, | |
3246 | vnc_l2_group_cmd, | |
3247 | "vnc l2-group NAME", | |
3248 | VNC_CONFIG_STR "Configure a L2 group\n" "Group name\n") | |
3249 | { | |
cdc2d765 | 3250 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 3251 | struct rfapi_l2_group_cfg *rfg; |
65efcfce | 3252 | |
65efcfce | 3253 | /* Search for name */ |
aed3273f | 3254 | rfg = rfapi_l2_group_lookup_byname (bgp, argv[2]->arg); |
65efcfce LB |
3255 | |
3256 | if (!rfg) | |
3257 | { | |
3258 | rfg = rfapi_l2_group_new (); | |
3259 | if (!rfg) | |
3260 | { | |
3261 | /* Error out of memory */ | |
3262 | vty_out (vty, "Can't allocate memory for L2 group%s", VTY_NEWLINE); | |
3263 | return CMD_WARNING; | |
3264 | } | |
aed3273f | 3265 | rfg->name = strdup (argv[2]->arg); |
65efcfce LB |
3266 | /* add to tail of list */ |
3267 | listnode_add (bgp->rfapi_cfg->l2_groups, rfg); | |
3268 | } | |
3269 | ||
3270 | /* | |
3271 | * XXX subsequent calls will need to make sure this item is still | |
3272 | * in the linked list and has the same name | |
3273 | */ | |
c77272a1 | 3274 | VTY_PUSH_CONTEXT_SUB (BGP_VNC_L2_GROUP_NODE, rfg); |
65efcfce LB |
3275 | return CMD_SUCCESS; |
3276 | } | |
3277 | ||
3278 | static void | |
3279 | bgp_rfapi_delete_l2_group ( | |
3280 | struct vty *vty, /* NULL = no output */ | |
3281 | struct bgp *bgp, | |
3282 | struct rfapi_l2_group_cfg *rfg) | |
3283 | { | |
3284 | /* delete it */ | |
3285 | free (rfg->name); | |
3286 | if (rfg->rt_import_list) | |
3287 | ecommunity_free (&rfg->rt_import_list); | |
3288 | if (rfg->rt_export_list) | |
3289 | ecommunity_free (&rfg->rt_export_list); | |
3290 | if (rfg->labels) | |
3291 | list_delete (rfg->labels); | |
3292 | if (rfg->rfp_cfg) | |
3293 | XFREE (MTYPE_RFAPI_RFP_GROUP_CFG, rfg->rfp_cfg); | |
3294 | listnode_delete (bgp->rfapi_cfg->l2_groups, rfg); | |
3295 | ||
3296 | rfapi_l2_group_del (rfg); | |
3297 | } | |
3298 | ||
3299 | static int | |
3300 | bgp_rfapi_delete_named_l2_group ( | |
3301 | struct vty *vty, /* NULL = no output */ | |
3302 | struct bgp *bgp, | |
3303 | const char *rfg_name) /* NULL = any */ | |
3304 | { | |
3305 | struct rfapi_l2_group_cfg *rfg = NULL; | |
3306 | struct listnode *node, *nnode; | |
3307 | ||
3308 | /* Search for name */ | |
3309 | if (rfg_name) | |
3310 | { | |
3311 | rfg = rfapi_l2_group_lookup_byname (bgp, rfg_name); | |
3312 | if (!rfg) | |
3313 | { | |
3314 | if (vty) | |
3315 | vty_out (vty, "No L2 group named \"%s\"%s", rfg_name, | |
3316 | VTY_NEWLINE); | |
3317 | return CMD_WARNING; | |
3318 | } | |
3319 | } | |
3320 | ||
3321 | if (rfg) | |
3322 | bgp_rfapi_delete_l2_group (vty, bgp, rfg); | |
3323 | else /* must be delete all */ | |
3324 | for (ALL_LIST_ELEMENTS (bgp->rfapi_cfg->l2_groups, node, nnode, rfg)) | |
3325 | bgp_rfapi_delete_l2_group (vty, bgp, rfg); | |
3326 | return CMD_SUCCESS; | |
3327 | } | |
3328 | ||
3329 | DEFUN (vnc_no_l2_group, | |
3330 | vnc_no_l2_group_cmd, | |
3331 | "no vnc l2-group NAME", | |
3332 | NO_STR | |
3333 | VNC_CONFIG_STR | |
3334 | "Configure a L2 group\n" | |
3335 | "Group name\n") | |
3336 | { | |
cdc2d765 | 3337 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
65efcfce | 3338 | |
aed3273f | 3339 | return bgp_rfapi_delete_named_l2_group (vty, bgp, argv[3]->arg); |
65efcfce LB |
3340 | } |
3341 | ||
3342 | ||
3343 | DEFUN (vnc_l2_group_lni, | |
3344 | vnc_l2_group_lni_cmd, | |
034d2de2 | 3345 | "logical-network-id (0-4294967295)", |
65efcfce LB |
3346 | "Specify Logical Network ID associated with group\n" |
3347 | "value\n") | |
3348 | { | |
cdc2d765 | 3349 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 3350 | VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg, rfg); |
65efcfce | 3351 | |
65efcfce LB |
3352 | /* make sure it's still in list */ |
3353 | if (!listnode_lookup (bgp->rfapi_cfg->l2_groups, rfg)) | |
3354 | { | |
3355 | /* Not in list anymore */ | |
3356 | vty_out (vty, "Current L2 group no longer exists%s", VTY_NEWLINE); | |
3357 | return CMD_WARNING; | |
3358 | } | |
3359 | ||
aed3273f | 3360 | VTY_GET_INTEGER ("logical-network-id", rfg->logical_net_id, argv[1]->arg); |
65efcfce LB |
3361 | |
3362 | return CMD_SUCCESS; | |
3363 | } | |
3364 | ||
3365 | DEFUN (vnc_l2_group_labels, | |
3366 | vnc_l2_group_labels_cmd, | |
bdffbcef | 3367 | "labels LABELLIST", |
65efcfce LB |
3368 | "Specify label values associated with group\n" |
3369 | "Space separated list of label values <0-1048575>\n") | |
3370 | { | |
cdc2d765 | 3371 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 3372 | VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg, rfg); |
65efcfce LB |
3373 | struct list *ll; |
3374 | ||
65efcfce LB |
3375 | /* make sure it's still in list */ |
3376 | if (!listnode_lookup (bgp->rfapi_cfg->l2_groups, rfg)) | |
3377 | { | |
3378 | /* Not in list anymore */ | |
3379 | vty_out (vty, "Current L2 group no longer exists%s", VTY_NEWLINE); | |
3380 | return CMD_WARNING; | |
3381 | } | |
3382 | ||
3383 | ll = rfg->labels; | |
3384 | if (ll == NULL) | |
3385 | { | |
3386 | ll = list_new (); | |
3387 | rfg->labels = ll; | |
3388 | } | |
aed3273f DL |
3389 | |
3390 | argc -= 1; | |
3391 | argv += 1; | |
65efcfce LB |
3392 | for (; argc; --argc, ++argv) |
3393 | { | |
3394 | uint32_t label; | |
aed3273f | 3395 | VTY_GET_INTEGER_RANGE ("Label value", label, argv[0]->arg, 0, 1048575); |
65efcfce LB |
3396 | if (!listnode_lookup (ll, (void *) (uintptr_t) label)) |
3397 | listnode_add (ll, (void *) (uintptr_t) label); | |
3398 | } | |
3399 | ||
3400 | return CMD_SUCCESS; | |
3401 | } | |
3402 | ||
3403 | DEFUN (vnc_l2_group_no_labels, | |
3404 | vnc_l2_group_no_labels_cmd, | |
bdffbcef | 3405 | "no labels LABELLIST", |
65efcfce LB |
3406 | NO_STR |
3407 | "Remove label values associated with L2 group\n" | |
3408 | "Specify label values associated with L2 group\n" | |
3409 | "Space separated list of label values <0-1048575>\n") | |
3410 | { | |
cdc2d765 | 3411 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 3412 | VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg, rfg); |
65efcfce LB |
3413 | struct list *ll; |
3414 | ||
65efcfce LB |
3415 | /* make sure it's still in list */ |
3416 | if (!listnode_lookup (bgp->rfapi_cfg->l2_groups, rfg)) | |
3417 | { | |
3418 | /* Not in list anymore */ | |
3419 | vty_out (vty, "Current L2 group no longer exists%s", VTY_NEWLINE); | |
3420 | return CMD_WARNING; | |
3421 | } | |
3422 | ||
3423 | ll = rfg->labels; | |
3424 | if (ll == NULL) | |
3425 | { | |
3426 | vty_out (vty, "Label no longer associated with group%s", VTY_NEWLINE); | |
3427 | return CMD_WARNING; | |
3428 | } | |
3429 | ||
aed3273f DL |
3430 | argc -= 2; |
3431 | argv += 2; | |
65efcfce LB |
3432 | for (; argc; --argc, ++argv) |
3433 | { | |
3434 | uint32_t label; | |
aed3273f | 3435 | VTY_GET_INTEGER_RANGE ("Label value", label, argv[0]->arg, 0, 1048575); |
65efcfce LB |
3436 | listnode_delete (ll, (void *) (uintptr_t) label); |
3437 | } | |
3438 | ||
3439 | return CMD_SUCCESS; | |
3440 | } | |
3441 | ||
3442 | DEFUN (vnc_l2_group_rt, | |
3443 | vnc_l2_group_rt_cmd, | |
034d2de2 | 3444 | "rt <both|export|import> ASN:nn_or_IP-address:nn", |
65efcfce LB |
3445 | "Specify route targets\n" |
3446 | "Export+import filters\n" | |
3447 | "Export filters\n" | |
3448 | "Import filters\n" | |
3449 | "A route target\n") | |
3450 | { | |
cdc2d765 | 3451 | VTY_DECLVAR_CONTEXT(bgp, bgp); |
c77272a1 | 3452 | VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg, rfg); |
65efcfce LB |
3453 | int rc = CMD_SUCCESS; |
3454 | int do_import = 0; | |
3455 | int do_export = 0; | |
3456 | ||
aed3273f | 3457 | switch (argv[1]->arg[0]) |
65efcfce LB |
3458 | { |
3459 | case 'b': | |
3460 | do_export = 1; /* fall through */ | |
3461 | case 'i': | |
3462 | do_import = 1; | |
3463 | break; | |
3464 | case 'e': | |
3465 | do_export = 1; | |
3466 | break; | |
3467 | default: | |
aed3273f | 3468 | vty_out (vty, "Unknown option, %s%s", argv[1]->arg, VTY_NEWLINE); |
65efcfce LB |
3469 | return CMD_ERR_NO_MATCH; |
3470 | } | |
aed3273f | 3471 | if (argc < 3) |
65efcfce LB |
3472 | return CMD_ERR_INCOMPLETE; |
3473 | ||
3474 | if (!bgp) | |
3475 | { | |
3476 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); | |
3477 | return CMD_WARNING; | |
3478 | } | |
3479 | ||
65efcfce LB |
3480 | /* make sure it's still in list */ |
3481 | if (!listnode_lookup (bgp->rfapi_cfg->l2_groups, rfg)) | |
3482 | { | |
3483 | /* Not in list anymore */ | |
3484 | vty_out (vty, "Current L2 group no longer exists%s", VTY_NEWLINE); | |
3485 | return CMD_WARNING; | |
3486 | } | |
3487 | ||
3488 | if (do_import) | |
aed3273f | 3489 | rc = set_ecom_list (vty, argc - 2, argv + 2, &rfg->rt_import_list); |
65efcfce | 3490 | if (rc == CMD_SUCCESS && do_export) |
aed3273f | 3491 | rc = set_ecom_list (vty, argc - 2, argv + 2, &rfg->rt_export_list); |
65efcfce LB |
3492 | return rc; |
3493 | } | |
3494 | ||
3495 | ||
3496 | static struct cmd_node bgp_vnc_l2_group_node = { | |
3497 | BGP_VNC_L2_GROUP_NODE, | |
3498 | "%s(config-router-vnc-l2-group)# ", | |
3499 | 1 | |
3500 | }; | |
3501 | ||
79799987 | 3502 | struct rfapi_l2_group_cfg * |
65efcfce LB |
3503 | bgp_rfapi_get_group_by_lni_label ( |
3504 | struct bgp *bgp, | |
3505 | uint32_t logical_net_id, | |
3506 | uint32_t label) | |
3507 | { | |
3508 | struct rfapi_l2_group_cfg *rfg; | |
3509 | struct listnode *node; | |
3510 | ||
3511 | if (bgp->rfapi_cfg->l2_groups == NULL) /* not the best place for this */ | |
3512 | return NULL; | |
3513 | ||
3514 | label = label & 0xfffff; /* label is 20 bits! */ | |
3515 | ||
3516 | for (ALL_LIST_ELEMENTS_RO (bgp->rfapi_cfg->l2_groups, node, rfg)) | |
3517 | { | |
3518 | if (rfg->logical_net_id == logical_net_id) | |
3519 | { | |
3520 | struct listnode *lnode; | |
3521 | void *data; | |
3522 | for (ALL_LIST_ELEMENTS_RO (rfg->labels, lnode, data)) | |
3523 | if (((uint32_t) ((uintptr_t) data)) == label) | |
3524 | { /* match! */ | |
3525 | return rfg; | |
3526 | } | |
3527 | } | |
3528 | } | |
3529 | return NULL; | |
3530 | } | |
3531 | ||
3532 | struct list * | |
3533 | bgp_rfapi_get_labellist_by_lni_label ( | |
3534 | struct bgp *bgp, | |
3535 | uint32_t logical_net_id, | |
3536 | uint32_t label) | |
3537 | { | |
3538 | struct rfapi_l2_group_cfg *rfg; | |
3539 | rfg = bgp_rfapi_get_group_by_lni_label (bgp, logical_net_id, label); | |
3540 | if (rfg) | |
3541 | { | |
3542 | return rfg->labels; | |
3543 | } | |
3544 | return NULL; | |
3545 | } | |
3546 | ||
3547 | struct ecommunity * | |
3548 | bgp_rfapi_get_ecommunity_by_lni_label ( | |
3549 | struct bgp *bgp, | |
3550 | uint32_t is_import, | |
3551 | uint32_t logical_net_id, | |
3552 | uint32_t label) | |
3553 | { | |
3554 | struct rfapi_l2_group_cfg *rfg; | |
3555 | rfg = bgp_rfapi_get_group_by_lni_label (bgp, logical_net_id, label); | |
3556 | if (rfg) | |
3557 | { | |
3558 | if (is_import) | |
3559 | return rfg->rt_import_list; | |
3560 | else | |
3561 | return rfg->rt_export_list; | |
3562 | } | |
3563 | return NULL; | |
3564 | } | |
3565 | ||
3566 | void | |
3567 | bgp_rfapi_cfg_init (void) | |
3568 | { | |
3569 | /* main bgpd code does not use this hook, but vnc does */ | |
3570 | route_map_event_hook (vnc_routemap_event); | |
3571 | ||
3572 | install_node (&bgp_vnc_defaults_node, NULL); | |
3573 | install_node (&bgp_vnc_nve_group_node, NULL); | |
3574 | install_node (&bgp_vnc_l2_group_node, NULL); | |
3575 | install_default (BGP_VNC_DEFAULTS_NODE); | |
3576 | install_default (BGP_VNC_NVE_GROUP_NODE); | |
3577 | install_default (BGP_VNC_L2_GROUP_NODE); | |
3578 | ||
3579 | /* | |
3580 | * Add commands | |
3581 | */ | |
3582 | install_element (BGP_NODE, &vnc_defaults_cmd); | |
3583 | install_element (BGP_NODE, &vnc_nve_group_cmd); | |
3584 | install_element (BGP_NODE, &vnc_no_nve_group_cmd); | |
3585 | install_element (BGP_NODE, &vnc_l2_group_cmd); | |
3586 | install_element (BGP_NODE, &vnc_no_l2_group_cmd); | |
3587 | install_element (BGP_NODE, &vnc_advertise_un_method_cmd); | |
3588 | install_element (BGP_NODE, &vnc_export_mode_cmd); | |
3589 | ||
3590 | install_element (BGP_VNC_DEFAULTS_NODE, &vnc_defaults_rt_import_cmd); | |
3591 | install_element (BGP_VNC_DEFAULTS_NODE, &vnc_defaults_rt_export_cmd); | |
3592 | install_element (BGP_VNC_DEFAULTS_NODE, &vnc_defaults_rt_both_cmd); | |
3593 | install_element (BGP_VNC_DEFAULTS_NODE, &vnc_defaults_rd_cmd); | |
3594 | install_element (BGP_VNC_DEFAULTS_NODE, &vnc_defaults_l2rd_cmd); | |
3595 | install_element (BGP_VNC_DEFAULTS_NODE, &vnc_defaults_no_l2rd_cmd); | |
3596 | install_element (BGP_VNC_DEFAULTS_NODE, &vnc_defaults_responselifetime_cmd); | |
3597 | install_element (BGP_VNC_DEFAULTS_NODE, &exit_vnc_cmd); | |
3598 | ||
3599 | install_element (BGP_NODE, &vnc_redistribute_protocol_cmd); | |
3600 | install_element (BGP_NODE, &vnc_no_redistribute_protocol_cmd); | |
3601 | install_element (BGP_NODE, &vnc_redistribute_nvegroup_cmd); | |
3602 | install_element (BGP_NODE, &vnc_redistribute_no_nvegroup_cmd); | |
3603 | install_element (BGP_NODE, &vnc_redistribute_lifetime_cmd); | |
3604 | install_element (BGP_NODE, &vnc_redistribute_rh_roo_localadmin_cmd); | |
3605 | install_element (BGP_NODE, &vnc_redistribute_mode_cmd); | |
3606 | install_element (BGP_NODE, &vnc_redistribute_bgp_exterior_cmd); | |
3607 | ||
3608 | install_element (BGP_NODE, &vnc_redist_bgpdirect_no_prefixlist_cmd); | |
3609 | install_element (BGP_NODE, &vnc_redist_bgpdirect_prefixlist_cmd); | |
3610 | install_element (BGP_NODE, &vnc_redist_bgpdirect_no_routemap_cmd); | |
3611 | install_element (BGP_NODE, &vnc_redist_bgpdirect_routemap_cmd); | |
3612 | ||
3613 | install_element (BGP_VNC_NVE_GROUP_NODE, | |
3614 | &vnc_nve_group_redist_bgpdirect_no_prefixlist_cmd); | |
3615 | install_element (BGP_VNC_NVE_GROUP_NODE, | |
3616 | &vnc_nve_group_redist_bgpdirect_prefixlist_cmd); | |
3617 | install_element (BGP_VNC_NVE_GROUP_NODE, | |
3618 | &vnc_nve_group_redist_bgpdirect_no_routemap_cmd); | |
3619 | install_element (BGP_VNC_NVE_GROUP_NODE, | |
3620 | &vnc_nve_group_redist_bgpdirect_routemap_cmd); | |
3621 | ||
3622 | install_element (BGP_NODE, &vnc_export_nvegroup_cmd); | |
3623 | install_element (BGP_NODE, &vnc_no_export_nvegroup_cmd); | |
3624 | install_element (BGP_NODE, &vnc_nve_export_prefixlist_cmd); | |
3625 | install_element (BGP_NODE, &vnc_nve_export_routemap_cmd); | |
3626 | install_element (BGP_NODE, &vnc_nve_export_no_prefixlist_cmd); | |
3627 | install_element (BGP_NODE, &vnc_nve_export_no_routemap_cmd); | |
3628 | ||
3629 | install_element (BGP_VNC_NVE_GROUP_NODE, &vnc_nve_group_l2rd_cmd); | |
3630 | install_element (BGP_VNC_NVE_GROUP_NODE, &vnc_nve_group_no_l2rd_cmd); | |
3631 | install_element (BGP_VNC_NVE_GROUP_NODE, &vnc_nve_group_prefix_cmd); | |
3632 | install_element (BGP_VNC_NVE_GROUP_NODE, &vnc_nve_group_rt_import_cmd); | |
3633 | install_element (BGP_VNC_NVE_GROUP_NODE, &vnc_nve_group_rt_export_cmd); | |
3634 | install_element (BGP_VNC_NVE_GROUP_NODE, &vnc_nve_group_rt_both_cmd); | |
3635 | install_element (BGP_VNC_NVE_GROUP_NODE, &vnc_nve_group_rd_cmd); | |
3636 | install_element (BGP_VNC_NVE_GROUP_NODE, | |
3637 | &vnc_nve_group_responselifetime_cmd); | |
3638 | install_element (BGP_VNC_NVE_GROUP_NODE, | |
3639 | &vnc_nve_group_export_prefixlist_cmd); | |
3640 | install_element (BGP_VNC_NVE_GROUP_NODE, | |
3641 | &vnc_nve_group_export_routemap_cmd); | |
3642 | install_element (BGP_VNC_NVE_GROUP_NODE, | |
3643 | &vnc_nve_group_export_no_prefixlist_cmd); | |
3644 | install_element (BGP_VNC_NVE_GROUP_NODE, | |
3645 | &vnc_nve_group_export_no_routemap_cmd); | |
3646 | install_element (BGP_VNC_NVE_GROUP_NODE, &exit_vnc_cmd); | |
3647 | ||
3648 | install_element (BGP_VNC_L2_GROUP_NODE, &vnc_l2_group_lni_cmd); | |
3649 | install_element (BGP_VNC_L2_GROUP_NODE, &vnc_l2_group_labels_cmd); | |
3650 | install_element (BGP_VNC_L2_GROUP_NODE, &vnc_l2_group_no_labels_cmd); | |
3651 | install_element (BGP_VNC_L2_GROUP_NODE, &vnc_l2_group_rt_cmd); | |
3652 | install_element (BGP_VNC_L2_GROUP_NODE, &exit_vnc_cmd); | |
3653 | } | |
3654 | ||
3655 | struct rfapi_cfg * | |
3656 | bgp_rfapi_cfg_new (struct rfapi_rfp_cfg *cfg) | |
3657 | { | |
3658 | struct rfapi_cfg *h; | |
3659 | int afi; | |
3660 | ||
3661 | h = | |
3662 | (struct rfapi_cfg *) XCALLOC (MTYPE_RFAPI_CFG, sizeof (struct rfapi_cfg)); | |
3663 | assert (h); | |
3664 | ||
3665 | h->nve_groups_sequential = list_new (); | |
3666 | assert (h->nve_groups_sequential); | |
3667 | ||
3668 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
3669 | { | |
3670 | /* ugly, to deal with addition of delegates, part of 0.99.24.1 merge */ | |
3671 | h->nve_groups_vn[afi].delegate = route_table_get_default_delegate (); | |
3672 | h->nve_groups_un[afi].delegate = route_table_get_default_delegate (); | |
3673 | } | |
3674 | h->default_response_lifetime = BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT; | |
3675 | h->rfg_export_direct_bgp_l = list_new (); | |
3676 | h->rfg_export_zebra_l = list_new (); | |
3677 | h->resolve_nve_roo_local_admin = | |
3678 | BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT; | |
3679 | ||
3680 | SET_FLAG (h->flags, BGP_VNC_CONFIG_FLAGS_DEFAULT); | |
3681 | ||
3682 | if (cfg == NULL) | |
3683 | { | |
3684 | h->rfp_cfg.download_type = RFAPI_RFP_DOWNLOAD_PARTIAL; | |
3685 | h->rfp_cfg.ftd_advertisement_interval = | |
3686 | RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL; | |
3687 | h->rfp_cfg.holddown_factor = RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR; | |
3688 | h->rfp_cfg.use_updated_response = 0; | |
3689 | h->rfp_cfg.use_removes = 0; | |
3690 | } | |
3691 | else | |
3692 | { | |
3693 | h->rfp_cfg.download_type = cfg->download_type; | |
3694 | h->rfp_cfg.ftd_advertisement_interval = cfg->ftd_advertisement_interval; | |
3695 | h->rfp_cfg.holddown_factor = cfg->holddown_factor; | |
3696 | h->rfp_cfg.use_updated_response = cfg->use_updated_response; | |
3697 | h->rfp_cfg.use_removes = cfg->use_removes; | |
3698 | if (cfg->use_updated_response) | |
3699 | h->flags &= ~BGP_VNC_CONFIG_CALLBACK_DISABLE; | |
3700 | else | |
3701 | h->flags |= BGP_VNC_CONFIG_CALLBACK_DISABLE; | |
3702 | if (cfg->use_removes) | |
3703 | h->flags &= ~BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE; | |
3704 | else | |
3705 | h->flags |= BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE; | |
3706 | } | |
3707 | return h; | |
3708 | } | |
3709 | ||
3710 | void | |
3711 | bgp_rfapi_cfg_destroy (struct bgp *bgp, struct rfapi_cfg *h) | |
3712 | { | |
3713 | if (h == NULL) | |
3714 | return; | |
3715 | ||
3716 | bgp_rfapi_delete_named_nve_group (NULL, bgp, NULL); | |
3717 | bgp_rfapi_delete_named_l2_group (NULL, bgp, NULL); | |
3718 | if (h->l2_groups != NULL) | |
3719 | list_delete (h->l2_groups); | |
3720 | list_delete (h->nve_groups_sequential); | |
3721 | list_delete (h->rfg_export_direct_bgp_l); | |
3722 | list_delete (h->rfg_export_zebra_l); | |
3723 | if (h->default_rt_export_list) | |
3724 | ecommunity_free (&h->default_rt_export_list); | |
3725 | if (h->default_rt_import_list) | |
3726 | ecommunity_free (&h->default_rt_import_list); | |
3727 | if (h->default_rfp_cfg) | |
3728 | XFREE (MTYPE_RFAPI_RFP_GROUP_CFG, h->default_rfp_cfg); | |
3729 | XFREE (MTYPE_RFAPI_CFG, h); | |
3730 | ||
3731 | } | |
3732 | ||
3733 | int | |
3734 | bgp_rfapi_cfg_write (struct vty *vty, struct bgp *bgp) | |
3735 | { | |
3736 | struct listnode *node, *nnode; | |
3737 | struct rfapi_nve_group_cfg *rfg; | |
3738 | struct rfapi_cfg *hc = bgp->rfapi_cfg; | |
3739 | struct rfapi_rfg_name *rfgn; | |
3740 | int write = 0; | |
3741 | afi_t afi; | |
3742 | int type; | |
3743 | ||
3744 | if (hc->flags & BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP) | |
3745 | { | |
3746 | vty_out (vty, " vnc advertise-un-method encap-safi%s", VTY_NEWLINE); | |
3747 | write++; | |
3748 | } | |
3749 | ||
3750 | { /* was based on listen ports */ | |
3751 | /* for now allow both old and new */ | |
3752 | if (bgp->rfapi->rfp_methods.cfg_cb) | |
3753 | write += (bgp->rfapi->rfp_methods.cfg_cb) (vty, bgp->rfapi->rfp); | |
3754 | ||
3755 | if (write) | |
3756 | vty_out (vty, "!%s", VTY_NEWLINE); | |
3757 | ||
3758 | if (hc->l2_groups) | |
3759 | { | |
3760 | struct rfapi_l2_group_cfg *rfg = NULL; | |
3761 | struct listnode *gnode; | |
3762 | for (ALL_LIST_ELEMENTS_RO (hc->l2_groups, gnode, rfg)) | |
3763 | { | |
3764 | struct listnode *lnode; | |
3765 | void *data; | |
3766 | ++write; | |
3767 | vty_out (vty, " vnc l2-group %s%s", rfg->name, VTY_NEWLINE); | |
3768 | if (rfg->logical_net_id != 0) | |
3769 | vty_out (vty, " logical-network-id %u%s", rfg->logical_net_id, | |
3770 | VTY_NEWLINE); | |
3771 | if (rfg->labels != NULL && listhead (rfg->labels) != NULL) | |
3772 | { | |
3773 | vty_out (vty, " labels "); | |
3774 | for (ALL_LIST_ELEMENTS_RO (rfg->labels, lnode, data)) | |
3775 | { | |
3776 | vty_out (vty, "%hu ", (uint16_t) ((uintptr_t) data)); | |
3777 | } | |
3778 | vty_out (vty, "%s", VTY_NEWLINE); | |
3779 | } | |
3780 | ||
3781 | if (rfg->rt_import_list && rfg->rt_export_list && | |
3782 | ecommunity_cmp (rfg->rt_import_list, rfg->rt_export_list)) | |
3783 | { | |
3784 | char *b = ecommunity_ecom2str (rfg->rt_import_list, | |
3785 | ECOMMUNITY_FORMAT_ROUTE_MAP); | |
3786 | vty_out (vty, " rt both %s%s", b, VTY_NEWLINE); | |
3787 | XFREE (MTYPE_ECOMMUNITY_STR, b); | |
3788 | } | |
3789 | else | |
3790 | { | |
3791 | if (rfg->rt_import_list) | |
3792 | { | |
3793 | char *b = ecommunity_ecom2str (rfg->rt_import_list, | |
3794 | ECOMMUNITY_FORMAT_ROUTE_MAP); | |
3795 | vty_out (vty, " rt import %s%s", b, VTY_NEWLINE); | |
3796 | XFREE (MTYPE_ECOMMUNITY_STR, b); | |
3797 | } | |
3798 | if (rfg->rt_export_list) | |
3799 | { | |
3800 | char *b = ecommunity_ecom2str (rfg->rt_export_list, | |
3801 | ECOMMUNITY_FORMAT_ROUTE_MAP); | |
3802 | vty_out (vty, " rt export %s%s", b, VTY_NEWLINE); | |
3803 | XFREE (MTYPE_ECOMMUNITY_STR, b); | |
3804 | } | |
3805 | } | |
3806 | if (bgp->rfapi->rfp_methods.cfg_group_cb) | |
3807 | write += | |
3808 | (bgp->rfapi->rfp_methods.cfg_group_cb) (vty, | |
3809 | bgp->rfapi->rfp, | |
3810 | RFAPI_RFP_CFG_GROUP_L2, | |
3811 | rfg->name, | |
3812 | rfg->rfp_cfg); | |
3813 | vty_out (vty, " exit-vnc%s", VTY_NEWLINE); | |
3814 | vty_out (vty, "!%s", VTY_NEWLINE); | |
3815 | } | |
3816 | } | |
3817 | ||
3818 | if (hc->default_rd.family || | |
3819 | hc->default_response_lifetime || | |
3820 | hc->default_rt_import_list || | |
3821 | hc->default_rt_export_list || hc->nve_groups_sequential->count) | |
3822 | { | |
3823 | ||
3824 | ||
3825 | ++write; | |
3826 | vty_out (vty, " vnc defaults%s", VTY_NEWLINE); | |
3827 | ||
3828 | if (hc->default_rd.prefixlen) | |
3829 | { | |
3830 | char buf[BUFSIZ]; | |
3831 | buf[0] = buf[BUFSIZ - 1] = 0; | |
3832 | ||
3833 | if (AF_UNIX == hc->default_rd.family) | |
3834 | { | |
3835 | uint16_t value = 0; | |
3836 | ||
3837 | value = ((hc->default_rd.val[6] << 8) & 0x0ff00) | | |
3838 | (hc->default_rd.val[7] & 0x0ff); | |
3839 | ||
3840 | vty_out (vty, " rd auto:vn:%d%s", value, VTY_NEWLINE); | |
3841 | ||
3842 | } | |
3843 | else | |
3844 | { | |
3845 | ||
3846 | if (!prefix_rd2str (&hc->default_rd, buf, BUFSIZ) || | |
3847 | !buf[0] || buf[BUFSIZ - 1]) | |
3848 | { | |
3849 | ||
3850 | vty_out (vty, "!Error: Can't convert rd%s", VTY_NEWLINE); | |
3851 | } | |
3852 | else | |
3853 | { | |
3854 | vty_out (vty, " rd %s%s", buf, VTY_NEWLINE); | |
3855 | } | |
3856 | } | |
3857 | } | |
3858 | if (hc->default_response_lifetime) | |
3859 | { | |
3860 | vty_out (vty, " response-lifetime "); | |
3861 | if (hc->default_response_lifetime != UINT32_MAX) | |
3862 | vty_out (vty, "%d", hc->default_response_lifetime); | |
3863 | else | |
3864 | vty_out (vty, "infinite"); | |
3865 | vty_out (vty, "%s", VTY_NEWLINE); | |
3866 | } | |
3867 | if (hc->default_rt_import_list && hc->default_rt_export_list && | |
3868 | ecommunity_cmp (hc->default_rt_import_list, | |
3869 | hc->default_rt_export_list)) | |
3870 | { | |
3871 | char *b = ecommunity_ecom2str (hc->default_rt_import_list, | |
3872 | ECOMMUNITY_FORMAT_ROUTE_MAP); | |
3873 | vty_out (vty, " rt both %s%s", b, VTY_NEWLINE); | |
3874 | XFREE (MTYPE_ECOMMUNITY_STR, b); | |
3875 | } | |
3876 | else | |
3877 | { | |
3878 | if (hc->default_rt_import_list) | |
3879 | { | |
3880 | char *b = ecommunity_ecom2str (hc->default_rt_import_list, | |
3881 | ECOMMUNITY_FORMAT_ROUTE_MAP); | |
3882 | vty_out (vty, " rt import %s%s", b, VTY_NEWLINE); | |
3883 | XFREE (MTYPE_ECOMMUNITY_STR, b); | |
3884 | } | |
3885 | if (hc->default_rt_export_list) | |
3886 | { | |
3887 | char *b = ecommunity_ecom2str (hc->default_rt_export_list, | |
3888 | ECOMMUNITY_FORMAT_ROUTE_MAP); | |
3889 | vty_out (vty, " rt export %s%s", b, VTY_NEWLINE); | |
3890 | XFREE (MTYPE_ECOMMUNITY_STR, b); | |
3891 | } | |
3892 | } | |
3893 | if (bgp->rfapi->rfp_methods.cfg_group_cb) | |
3894 | write += | |
3895 | (bgp->rfapi->rfp_methods.cfg_group_cb) (vty, | |
3896 | bgp->rfapi->rfp, | |
3897 | RFAPI_RFP_CFG_GROUP_DEFAULT, | |
3898 | NULL, | |
3899 | bgp->rfapi_cfg->default_rfp_cfg); | |
3900 | vty_out (vty, " exit-vnc%s", VTY_NEWLINE); | |
3901 | vty_out (vty, "!%s", VTY_NEWLINE); | |
3902 | } | |
3903 | ||
3904 | for (ALL_LIST_ELEMENTS (hc->nve_groups_sequential, node, nnode, rfg)) | |
3905 | { | |
3906 | ++write; | |
3907 | vty_out (vty, " vnc nve-group %s%s", rfg->name, VTY_NEWLINE); | |
3908 | ||
3909 | if (rfg->vn_prefix.family && rfg->vn_node) | |
3910 | { | |
3911 | char buf[BUFSIZ]; | |
3912 | buf[0] = buf[BUFSIZ - 1] = 0; | |
3913 | ||
3914 | prefix2str (&rfg->vn_prefix, buf, BUFSIZ); | |
3915 | if (!buf[0] || buf[BUFSIZ - 1]) | |
3916 | { | |
3917 | vty_out (vty, "!Error: Can't convert prefix%s", VTY_NEWLINE); | |
3918 | } | |
3919 | else | |
3920 | { | |
3921 | vty_out (vty, " prefix %s %s%s", "vn", buf, VTY_NEWLINE); | |
3922 | } | |
3923 | } | |
3924 | ||
3925 | if (rfg->un_prefix.family && rfg->un_node) | |
3926 | { | |
3927 | char buf[BUFSIZ]; | |
3928 | buf[0] = buf[BUFSIZ - 1] = 0; | |
3929 | prefix2str (&rfg->un_prefix, buf, BUFSIZ); | |
3930 | if (!buf[0] || buf[BUFSIZ - 1]) | |
3931 | { | |
3932 | vty_out (vty, "!Error: Can't convert prefix%s", VTY_NEWLINE); | |
3933 | } | |
3934 | else | |
3935 | { | |
3936 | vty_out (vty, " prefix %s %s%s", "un", buf, VTY_NEWLINE); | |
3937 | } | |
3938 | } | |
3939 | ||
3940 | ||
3941 | if (rfg->rd.prefixlen) | |
3942 | { | |
3943 | char buf[BUFSIZ]; | |
3944 | buf[0] = buf[BUFSIZ - 1] = 0; | |
3945 | ||
3946 | if (AF_UNIX == rfg->rd.family) | |
3947 | { | |
3948 | ||
3949 | uint16_t value = 0; | |
3950 | ||
3951 | value = ((rfg->rd.val[6] << 8) & 0x0ff00) | | |
3952 | (rfg->rd.val[7] & 0x0ff); | |
3953 | ||
3954 | vty_out (vty, " rd auto:vn:%d%s", value, VTY_NEWLINE); | |
3955 | ||
3956 | } | |
3957 | else | |
3958 | { | |
3959 | ||
3960 | if (!prefix_rd2str (&rfg->rd, buf, BUFSIZ) || | |
3961 | !buf[0] || buf[BUFSIZ - 1]) | |
3962 | { | |
3963 | ||
3964 | vty_out (vty, "!Error: Can't convert rd%s", VTY_NEWLINE); | |
3965 | } | |
3966 | else | |
3967 | { | |
3968 | vty_out (vty, " rd %s%s", buf, VTY_NEWLINE); | |
3969 | } | |
3970 | } | |
3971 | } | |
3972 | if (rfg->flags & RFAPI_RFG_RESPONSE_LIFETIME) | |
3973 | { | |
3974 | vty_out (vty, " response-lifetime "); | |
3975 | if (rfg->response_lifetime != UINT32_MAX) | |
3976 | vty_out (vty, "%d", rfg->response_lifetime); | |
3977 | else | |
3978 | vty_out (vty, "infinite"); | |
3979 | vty_out (vty, "%s", VTY_NEWLINE); | |
3980 | } | |
3981 | ||
3982 | if (rfg->rt_import_list && rfg->rt_export_list && | |
3983 | ecommunity_cmp (rfg->rt_import_list, rfg->rt_export_list)) | |
3984 | { | |
3985 | char *b = ecommunity_ecom2str (rfg->rt_import_list, | |
3986 | ECOMMUNITY_FORMAT_ROUTE_MAP); | |
3987 | vty_out (vty, " rt both %s%s", b, VTY_NEWLINE); | |
3988 | XFREE (MTYPE_ECOMMUNITY_STR, b); | |
3989 | } | |
3990 | else | |
3991 | { | |
3992 | if (rfg->rt_import_list) | |
3993 | { | |
3994 | char *b = ecommunity_ecom2str (rfg->rt_import_list, | |
3995 | ECOMMUNITY_FORMAT_ROUTE_MAP); | |
3996 | vty_out (vty, " rt import %s%s", b, VTY_NEWLINE); | |
3997 | XFREE (MTYPE_ECOMMUNITY_STR, b); | |
3998 | } | |
3999 | if (rfg->rt_export_list) | |
4000 | { | |
4001 | char *b = ecommunity_ecom2str (rfg->rt_export_list, | |
4002 | ECOMMUNITY_FORMAT_ROUTE_MAP); | |
4003 | vty_out (vty, " rt export %s%s", b, VTY_NEWLINE); | |
4004 | XFREE (MTYPE_ECOMMUNITY_STR, b); | |
4005 | } | |
4006 | } | |
4007 | ||
4008 | /* | |
4009 | * route filtering: prefix-lists and route-maps | |
4010 | */ | |
4011 | for (afi = AFI_IP; afi < AFI_MAX; ++afi) | |
4012 | { | |
4013 | ||
4014 | const char *afistr = (afi == AFI_IP) ? "ipv4" : "ipv6"; | |
4015 | ||
4016 | if (rfg->plist_export_bgp_name[afi]) | |
4017 | { | |
4018 | vty_out (vty, " export bgp %s prefix-list %s%s", | |
4019 | afistr, rfg->plist_export_bgp_name[afi], | |
4020 | VTY_NEWLINE); | |
4021 | } | |
4022 | if (rfg->plist_export_zebra_name[afi]) | |
4023 | { | |
4024 | vty_out (vty, " export zebra %s prefix-list %s%s", | |
4025 | afistr, rfg->plist_export_zebra_name[afi], | |
4026 | VTY_NEWLINE); | |
4027 | } | |
4028 | /* | |
4029 | * currently we only support redist plists for bgp-direct. | |
4030 | * If we later add plist support for redistributing other | |
4031 | * protocols, we'll need to loop over protocols here | |
4032 | */ | |
4033 | if (rfg->plist_redist_name[ZEBRA_ROUTE_BGP_DIRECT][afi]) | |
4034 | { | |
4035 | vty_out (vty, " redistribute bgp-direct %s prefix-list %s%s", | |
4036 | afistr, | |
4037 | rfg->plist_redist_name[ZEBRA_ROUTE_BGP_DIRECT][afi], | |
4038 | VTY_NEWLINE); | |
4039 | } | |
4040 | if (rfg->plist_redist_name[ZEBRA_ROUTE_BGP_DIRECT_EXT][afi]) | |
4041 | { | |
4042 | vty_out (vty, | |
4043 | " redistribute bgp-direct-to-nve-groups %s prefix-list %s%s", | |
4044 | afistr, | |
4045 | rfg->plist_redist_name[ZEBRA_ROUTE_BGP_DIRECT_EXT] | |
4046 | [afi], VTY_NEWLINE); | |
4047 | } | |
4048 | } | |
4049 | ||
4050 | if (rfg->routemap_export_bgp_name) | |
4051 | { | |
4052 | vty_out (vty, " export bgp route-map %s%s", | |
4053 | rfg->routemap_export_bgp_name, VTY_NEWLINE); | |
4054 | } | |
4055 | if (rfg->routemap_export_zebra_name) | |
4056 | { | |
4057 | vty_out (vty, " export zebra route-map %s%s", | |
4058 | rfg->routemap_export_zebra_name, VTY_NEWLINE); | |
4059 | } | |
4060 | if (rfg->routemap_redist_name[ZEBRA_ROUTE_BGP_DIRECT]) | |
4061 | { | |
4062 | vty_out (vty, " redistribute bgp-direct route-map %s%s", | |
4063 | rfg->routemap_redist_name[ZEBRA_ROUTE_BGP_DIRECT], | |
4064 | VTY_NEWLINE); | |
4065 | } | |
4066 | if (rfg->routemap_redist_name[ZEBRA_ROUTE_BGP_DIRECT_EXT]) | |
4067 | { | |
4068 | vty_out (vty, | |
4069 | " redistribute bgp-direct-to-nve-groups route-map %s%s", | |
4070 | rfg->routemap_redist_name[ZEBRA_ROUTE_BGP_DIRECT_EXT], | |
4071 | VTY_NEWLINE); | |
4072 | } | |
4073 | if (bgp->rfapi->rfp_methods.cfg_group_cb) | |
4074 | write += | |
4075 | (bgp->rfapi->rfp_methods.cfg_group_cb) (vty, | |
4076 | bgp->rfapi->rfp, | |
4077 | RFAPI_RFP_CFG_GROUP_NVE, | |
4078 | rfg->name, rfg->rfp_cfg); | |
4079 | vty_out (vty, " exit-vnc%s", VTY_NEWLINE); | |
4080 | vty_out (vty, "!%s", VTY_NEWLINE); | |
4081 | } | |
4082 | } /* have listen ports */ | |
4083 | ||
4084 | /* | |
4085 | * route export to other protocols | |
4086 | */ | |
4087 | if (VNC_EXPORT_BGP_GRP_ENABLED (hc)) | |
4088 | { | |
4089 | vty_out (vty, " vnc export bgp mode group-nve%s", VTY_NEWLINE); | |
4090 | } | |
4091 | else if (VNC_EXPORT_BGP_RH_ENABLED (hc)) | |
4092 | { | |
4093 | vty_out (vty, " vnc export bgp mode registering-nve%s", VTY_NEWLINE); | |
4094 | } | |
4095 | else if (VNC_EXPORT_BGP_CE_ENABLED (hc)) | |
4096 | { | |
4097 | vty_out (vty, " vnc export bgp mode ce%s", VTY_NEWLINE); | |
4098 | } | |
4099 | ||
4100 | if (VNC_EXPORT_ZEBRA_GRP_ENABLED (hc)) | |
4101 | { | |
4102 | vty_out (vty, " vnc export zebra mode group-nve%s", VTY_NEWLINE); | |
4103 | } | |
4104 | else if (VNC_EXPORT_ZEBRA_RH_ENABLED (hc)) | |
4105 | { | |
4106 | vty_out (vty, " vnc export zebra mode registering-nve%s", VTY_NEWLINE); | |
4107 | } | |
4108 | ||
4109 | if (hc->rfg_export_direct_bgp_l) | |
4110 | { | |
4111 | for (ALL_LIST_ELEMENTS (hc->rfg_export_direct_bgp_l, node, nnode, rfgn)) | |
4112 | { | |
4113 | ||
4114 | vty_out (vty, " vnc export bgp group-nve group %s%s", | |
4115 | rfgn->name, VTY_NEWLINE); | |
4116 | } | |
4117 | } | |
4118 | ||
4119 | if (hc->rfg_export_zebra_l) | |
4120 | { | |
4121 | for (ALL_LIST_ELEMENTS (hc->rfg_export_zebra_l, node, nnode, rfgn)) | |
4122 | { | |
4123 | ||
4124 | vty_out (vty, " vnc export zebra group-nve group %s%s", | |
4125 | rfgn->name, VTY_NEWLINE); | |
4126 | } | |
4127 | } | |
4128 | ||
4129 | ||
4130 | if (hc->rfg_redist_name) | |
4131 | { | |
4132 | vty_out (vty, " vnc redistribute nve-group %s%s", | |
4133 | hc->rfg_redist_name, VTY_NEWLINE); | |
4134 | } | |
4135 | if (hc->redist_lifetime) | |
4136 | { | |
4137 | vty_out (vty, " vnc redistribute lifetime %d%s", | |
4138 | hc->redist_lifetime, VTY_NEWLINE); | |
4139 | } | |
4140 | if (hc->resolve_nve_roo_local_admin != | |
4141 | BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT) | |
4142 | { | |
4143 | ||
4144 | vty_out (vty, " vnc redistribute resolve-nve roo-ec-local-admin %d%s", | |
4145 | hc->resolve_nve_roo_local_admin, VTY_NEWLINE); | |
4146 | } | |
4147 | ||
4148 | if (hc->redist_mode) /* ! default */ | |
4149 | { | |
4150 | const char *s = ""; | |
4151 | ||
4152 | switch (hc->redist_mode) | |
4153 | { | |
4154 | case VNC_REDIST_MODE_PLAIN: | |
4155 | s = "plain"; | |
4156 | break; | |
4157 | case VNC_REDIST_MODE_RFG: | |
4158 | s = "nve-group"; | |
4159 | break; | |
4160 | case VNC_REDIST_MODE_RESOLVE_NVE: | |
4161 | s = "resolve-nve"; | |
4162 | break; | |
4163 | } | |
4164 | if (s) | |
4165 | { | |
4166 | vty_out (vty, " vnc redistribute mode %s%s", s, VTY_NEWLINE); | |
4167 | } | |
4168 | } | |
4169 | ||
4170 | /* | |
4171 | * route filtering: prefix-lists and route-maps | |
4172 | */ | |
4173 | for (afi = AFI_IP; afi < AFI_MAX; ++afi) | |
4174 | { | |
4175 | ||
4176 | const char *afistr = (afi == AFI_IP) ? "ipv4" : "ipv6"; | |
4177 | ||
4178 | if (hc->plist_export_bgp_name[afi]) | |
4179 | { | |
4180 | vty_out (vty, " vnc export bgp %s prefix-list %s%s", | |
4181 | afistr, hc->plist_export_bgp_name[afi], VTY_NEWLINE); | |
4182 | } | |
4183 | if (hc->plist_export_zebra_name[afi]) | |
4184 | { | |
4185 | vty_out (vty, " vnc export zebra %s prefix-list %s%s", | |
4186 | afistr, hc->plist_export_zebra_name[afi], VTY_NEWLINE); | |
4187 | } | |
4188 | if (hc->plist_redist_name[ZEBRA_ROUTE_BGP_DIRECT][afi]) | |
4189 | { | |
4190 | vty_out (vty, " vnc redistribute bgp-direct %s prefix-list %s%s", | |
4191 | afistr, hc->plist_redist_name[ZEBRA_ROUTE_BGP_DIRECT][afi], | |
4192 | VTY_NEWLINE); | |
4193 | } | |
4194 | } | |
4195 | ||
4196 | if (hc->routemap_export_bgp_name) | |
4197 | { | |
4198 | vty_out (vty, " vnc export bgp route-map %s%s", | |
4199 | hc->routemap_export_bgp_name, VTY_NEWLINE); | |
4200 | } | |
4201 | if (hc->routemap_export_zebra_name) | |
4202 | { | |
4203 | vty_out (vty, " vnc export zebra route-map %s%s", | |
4204 | hc->routemap_export_zebra_name, VTY_NEWLINE); | |
4205 | } | |
4206 | if (hc->routemap_redist_name[ZEBRA_ROUTE_BGP_DIRECT]) | |
4207 | { | |
4208 | vty_out (vty, " vnc redistribute bgp-direct route-map %s%s", | |
4209 | hc->routemap_redist_name[ZEBRA_ROUTE_BGP_DIRECT], VTY_NEWLINE); | |
4210 | } | |
4211 | ||
4212 | for (afi = AFI_IP; afi < AFI_MAX; ++afi) | |
4213 | { | |
4214 | for (type = 0; type < ZEBRA_ROUTE_MAX; ++type) | |
4215 | { | |
4216 | if (hc->redist[afi][type]) | |
4217 | { | |
4218 | if (type == ZEBRA_ROUTE_BGP_DIRECT_EXT && | |
4219 | hc->redist_bgp_exterior_view_name) | |
4220 | { | |
4221 | vty_out (vty, " vnc redistribute %s %s view %s%s", | |
4222 | ((afi == AFI_IP) ? "ipv4" : "ipv6"), | |
4223 | zebra_route_string (type), | |
4224 | hc->redist_bgp_exterior_view_name, VTY_NEWLINE); | |
4225 | } | |
4226 | else | |
4227 | { | |
4228 | vty_out (vty, " vnc redistribute %s %s%s", | |
4229 | ((afi == AFI_IP) ? "ipv4" : "ipv6"), | |
4230 | zebra_route_string (type), VTY_NEWLINE); | |
4231 | } | |
4232 | } | |
4233 | } | |
4234 | } | |
4235 | return write; | |
4236 | } | |
4237 | ||
4238 | void | |
4239 | bgp_rfapi_show_summary (struct bgp *bgp, struct vty *vty) | |
4240 | { | |
4241 | struct rfapi_cfg *hc = bgp->rfapi_cfg; | |
4242 | int afi, type, redist = 0; | |
4243 | char tmp[40]; | |
4244 | if (hc == NULL) | |
4245 | return; | |
4246 | ||
4247 | vty_out (vty, "%-39s %-19s %s%s", "VNC Advertise method:", | |
4248 | (hc->flags & BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP | |
4249 | ? "Encapsulation SAFI" : "Tunnel Encap attribute"), | |
4250 | ((hc->flags & BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP) == | |
4251 | (BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP & | |
4252 | BGP_VNC_CONFIG_FLAGS_DEFAULT) ? "(default)" : ""), VTY_NEWLINE); | |
4253 | /* export */ | |
4254 | vty_out (vty, "%-39s ", "Export from VNC:"); | |
4255 | /* | |
4256 | * route export to other protocols | |
4257 | */ | |
4258 | if (VNC_EXPORT_BGP_GRP_ENABLED (hc)) | |
4259 | { | |
4260 | redist++; | |
4261 | vty_out (vty, "ToBGP Groups={"); | |
4262 | if (hc->rfg_export_direct_bgp_l) | |
4263 | { | |
4264 | int cnt = 0; | |
4265 | struct listnode *node, *nnode; | |
4266 | struct rfapi_rfg_name *rfgn; | |
4267 | for (ALL_LIST_ELEMENTS (hc->rfg_export_direct_bgp_l, | |
4268 | node, nnode, rfgn)) | |
4269 | { | |
4270 | if (cnt++ != 0) | |
4271 | vty_out (vty, ","); | |
4272 | ||
4273 | vty_out (vty, "%s", rfgn->name); | |
4274 | } | |
4275 | } | |
4276 | vty_out (vty, "}"); | |
4277 | } | |
4278 | else if (VNC_EXPORT_BGP_RH_ENABLED (hc)) | |
4279 | { | |
4280 | redist++; | |
4281 | vty_out (vty, "ToBGP {Registering NVE}"); | |
4282 | /* note filters, route-maps not shown */ | |
4283 | } | |
4284 | else if (VNC_EXPORT_BGP_CE_ENABLED (hc)) | |
4285 | { | |
4286 | redist++; | |
4287 | vty_out (vty, "ToBGP {NVE connected router:%d}", | |
4288 | hc->resolve_nve_roo_local_admin); | |
4289 | /* note filters, route-maps not shown */ | |
4290 | } | |
4291 | ||
4292 | if (VNC_EXPORT_ZEBRA_GRP_ENABLED (hc)) | |
4293 | { | |
4294 | redist++; | |
4295 | vty_out (vty, "%sToZebra Groups={", (redist == 1 ? "" : " ")); | |
4296 | if (hc->rfg_export_direct_bgp_l) | |
4297 | { | |
4298 | int cnt = 0; | |
4299 | struct listnode *node, *nnode; | |
4300 | struct rfapi_rfg_name *rfgn; | |
4301 | for (ALL_LIST_ELEMENTS (hc->rfg_export_zebra_l, node, nnode, rfgn)) | |
4302 | { | |
4303 | if (cnt++ != 0) | |
4304 | vty_out (vty, ","); | |
4305 | vty_out (vty, "%s", rfgn->name); | |
4306 | } | |
4307 | } | |
4308 | vty_out (vty, "}"); | |
4309 | } | |
4310 | else if (VNC_EXPORT_ZEBRA_RH_ENABLED (hc)) | |
4311 | { | |
4312 | redist++; | |
4313 | vty_out (vty, "%sToZebra {Registering NVE}", (redist == 1 ? "" : " ")); | |
4314 | /* note filters, route-maps not shown */ | |
4315 | } | |
4316 | vty_out (vty, "%-19s %s%s", (redist ? "" : "Off"), | |
4317 | (redist ? "" : "(default)"), VTY_NEWLINE); | |
4318 | ||
4319 | /* Redistribution */ | |
4320 | redist = 0; | |
4321 | vty_out (vty, "%-39s ", "Redistribution into VNC:"); | |
4322 | for (afi = AFI_IP; afi < AFI_MAX; ++afi) | |
4323 | { | |
4324 | for (type = 0; type < ZEBRA_ROUTE_MAX; ++type) | |
4325 | { | |
4326 | if (hc->redist[afi][type]) | |
4327 | { | |
4328 | vty_out (vty, "{%s,%s} ", | |
4329 | ((afi == AFI_IP) ? "ipv4" : "ipv6"), | |
4330 | zebra_route_string (type)); | |
4331 | redist++; | |
4332 | } | |
4333 | } | |
4334 | } | |
4335 | vty_out (vty, "%-19s %s%s", (redist ? "" : "Off"), | |
4336 | (redist ? "" : "(default)"), VTY_NEWLINE); | |
4337 | ||
4338 | vty_out (vty, "%-39s %3u%-16s %s%s", "RFP Registration Hold-Down Factor:", | |
4339 | hc->rfp_cfg.holddown_factor, "%", | |
4340 | (hc->rfp_cfg.holddown_factor == | |
4341 | RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR ? "(default)" : ""), | |
4342 | VTY_NEWLINE); | |
4343 | vty_out (vty, "%-39s %-19s %s%s", "RFP Updated responses:", | |
4344 | (hc->rfp_cfg.use_updated_response == 0 ? "Off" : "On"), | |
4345 | (hc->rfp_cfg.use_updated_response == 0 ? "(default)" : ""), | |
4346 | VTY_NEWLINE); | |
4347 | vty_out (vty, "%-39s %-19s %s%s", "RFP Removal responses:", | |
4348 | (hc->rfp_cfg.use_removes == 0 ? "Off" : "On"), | |
4349 | (hc->rfp_cfg.use_removes == 0 ? "(default)" : ""), VTY_NEWLINE); | |
4350 | vty_out (vty, "%-39s %-19s %s%s", "RFP Full table download:", | |
4351 | (hc->rfp_cfg.download_type == | |
4352 | RFAPI_RFP_DOWNLOAD_FULL ? "On" : "Off"), | |
4353 | (hc->rfp_cfg.download_type == | |
4354 | RFAPI_RFP_DOWNLOAD_PARTIAL ? "(default)" : ""), VTY_NEWLINE); | |
4355 | sprintf (tmp, "%u seconds", hc->rfp_cfg.ftd_advertisement_interval); | |
4356 | vty_out (vty, "%-39s %-19s %s%s", " Advertisement Interval:", tmp, | |
4357 | (hc->rfp_cfg.ftd_advertisement_interval == | |
4358 | RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL | |
4359 | ? "(default)" : ""), VTY_NEWLINE); | |
4360 | vty_out (vty, "%-39s %d seconds%s", "Default RFP response lifetime:", | |
4361 | hc->default_response_lifetime, VTY_NEWLINE); | |
4362 | vty_out (vty, "%s", VTY_NEWLINE); | |
4363 | return; | |
4364 | } | |
4365 | ||
4366 | struct rfapi_cfg * | |
4367 | bgp_rfapi_get_config (struct bgp *bgp) | |
4368 | { | |
4369 | struct rfapi_cfg *hc = NULL; | |
4370 | if (bgp == NULL) | |
4371 | bgp = bgp_get_default (); | |
4372 | if (bgp != NULL) | |
4373 | hc = bgp->rfapi_cfg; | |
4374 | return hc; | |
4375 | } | |
4376 | ||
4377 | #endif /* ENABLE_BGP_VNC */ |