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