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