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