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