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