3 * Copyright 2009-2016, LabN Consulting, L.L.C.
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.
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.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "lib/zebra.h"
22 #include "lib/command.h"
23 #include "lib/prefix.h"
24 #include "lib/memory.h"
25 #include "lib/linklist.h"
26 #include "lib/agg_table.h"
27 #include "lib/plist.h"
28 #include "lib/routemap.h"
30 #include "bgpd/bgpd.h"
31 #include "bgpd/bgp_attr.h"
32 #include "bgpd/bgp_route.h"
33 #include "bgpd/bgp_mplsvpn.h"
35 #include "bgpd/bgp_vty.h"
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"
52 #undef BGP_VNC_DEBUG_MATCH_GROUP
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");
83 DEFINE_QOBJ_TYPE(rfapi_nve_group_cfg
);
84 DEFINE_QOBJ_TYPE(rfapi_l2_group_cfg
);
85 /***********************************************************************
87 ***********************************************************************/
91 * compaitibility to old quagga_time call
92 * time_t value in terms of stabilised absolute time.
93 * replacement for POSIX time()
95 time_t rfapi_time(time_t *t
)
97 time_t clock
= monotime(NULL
);
103 void nve_group_to_nve_list(struct rfapi_nve_group_cfg
*rfg
, struct list
**nves
,
104 uint8_t family
) /* AF_INET, AF_INET6 */
106 struct listnode
*hln
;
107 struct rfapi_descriptor
*rfd
;
110 * loop over nves in this grp, add to list
112 for (ALL_LIST_ELEMENTS_RO(rfg
->nves
, hln
, rfd
)) {
113 if (rfd
->vn_addr
.addr_family
== family
) {
116 listnode_add(*nves
, rfd
);
122 struct rfapi_nve_group_cfg
*bgp_rfapi_cfg_match_group(struct rfapi_cfg
*hc
,
126 struct rfapi_nve_group_cfg
*rfg_vn
= NULL
;
127 struct rfapi_nve_group_cfg
*rfg_un
= NULL
;
129 struct agg_table
*rt_vn
;
130 struct agg_table
*rt_un
;
131 struct agg_node
*rn_vn
;
132 struct agg_node
*rn_un
;
134 struct rfapi_nve_group_cfg
*rfg
;
135 struct listnode
*node
, *nnode
;
137 switch (vn
->family
) {
139 rt_vn
= hc
->nve_groups_vn
[AFI_IP
];
142 rt_vn
= hc
->nve_groups_vn
[AFI_IP6
];
148 switch (un
->family
) {
150 rt_un
= hc
->nve_groups_un
[AFI_IP
];
153 rt_un
= hc
->nve_groups_un
[AFI_IP6
];
159 rn_vn
= agg_node_match(rt_vn
, vn
); /* NB locks node */
161 rfg_vn
= rn_vn
->info
;
162 agg_unlock_node(rn_vn
);
165 rn_un
= agg_node_match(rt_un
, un
); /* NB locks node */
167 rfg_un
= rn_un
->info
;
168 agg_unlock_node(rn_un
);
171 #ifdef BGP_VNC_DEBUG_MATCH_GROUP
173 vnc_zlog_debug_verbose("%s: vn prefix: %pFX", __func__
, vn
);
174 vnc_zlog_debug_verbose("%s: un prefix: %pFX", __func__
, un
);
175 vnc_zlog_debug_verbose(
176 "%s: rn_vn=%p, rn_un=%p, rfg_vn=%p, rfg_un=%p",
177 __func__
, rn_vn
, rn_un
, rfg_vn
, rfg_un
);
182 if (rfg_un
== rfg_vn
) /* same group */
184 if (!rfg_un
) /* un doesn't match, return vn-matched grp */
186 if (!rfg_vn
) /* vn doesn't match, return un-matched grp */
190 * Two different nve groups match: the group configured earlier wins.
191 * For now, just walk the sequential list and pick the first one.
192 * If this approach is too slow, then store serial numbers in the
193 * nve group structures as they are defined and just compare
196 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
, rfg
)) {
197 if ((rfg
== rfg_un
) || (rfg
== rfg_vn
)) {
201 vnc_zlog_debug_verbose(
202 "%s: shouldn't happen, returning NULL when un and vn match",
204 return NULL
; /* shouldn't happen */
207 /*------------------------------------------
208 * rfapi_get_rfp_start_val
210 * Returns value passed to rfapi on rfp_start
213 * void * bgp structure
217 *------------------------------------------*/
218 void *rfapi_get_rfp_start_val(void *bgpv
)
220 struct bgp
*bgp
= bgpv
;
221 if (bgp
== NULL
|| bgp
->rfapi
== NULL
)
223 return bgp
->rfapi
->rfp
;
226 /*------------------------------------------
227 * bgp_rfapi_is_vnc_configured
229 * Returns if VNC is configured
232 * bgp NULL (=use default instance)
236 * return value: If VNC is configured for the bgpd instance
238 * EPERM Not Default instance (VNC operations not allowed)
239 * ENXIO VNC not configured
240 --------------------------------------------*/
241 int bgp_rfapi_is_vnc_configured(struct bgp
*bgp
)
244 bgp
= bgp_get_default();
246 if (bgp
&& bgp
->inst_type
!= BGP_INSTANCE_TYPE_DEFAULT
)
249 if (bgp
&& bgp
->rfapi_cfg
)
254 /***********************************************************************
255 * VNC Configuration/CLI
256 ***********************************************************************/
257 #define VNC_VTY_CONFIG_CHECK(bgp) \
259 switch (bgp_rfapi_is_vnc_configured(bgp)) { \
262 "VNC operations only permitted on default BGP instance.\n"); \
263 return CMD_WARNING_CONFIG_FAILED; \
266 vty_out(vty, "VNC not configured.\n"); \
267 return CMD_WARNING_CONFIG_FAILED; \
274 DEFUN (vnc_advertise_un_method
,
275 vnc_advertise_un_method_cmd
,
276 "vnc advertise-un-method encap-attr",
278 "Method of advertising UN addresses\n"
279 "Via Tunnel Encap attribute (in VPN SAFI)\n")
281 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
282 VNC_VTY_CONFIG_CHECK(bgp
);
284 if (!strncmp(argv
[2]->arg
, "encap-safi", 7)) {
285 bgp
->rfapi_cfg
->flags
|= BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
;
287 bgp
->rfapi_cfg
->flags
&= ~BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
;
293 /*-------------------------------------------------------------------------
295 *-----------------------------------------------------------------------*/
298 DEFUN_NOSH (vnc_defaults
,
300 "vnc defaults", VNC_CONFIG_STR
"Configure default NVE group\n")
302 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
303 VNC_VTY_CONFIG_CHECK(bgp
);
304 if (bgp
->inst_type
!= BGP_INSTANCE_TYPE_DEFAULT
) {
305 vty_out(vty
, "Malformed community-list value\n");
306 return CMD_WARNING_CONFIG_FAILED
;
308 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
312 static int set_ecom_list(struct vty
*vty
, int argc
, struct cmd_token
**argv
,
313 struct ecommunity
**list
)
315 struct ecommunity
*ecom
= NULL
;
316 struct ecommunity
*ecomadd
;
318 for (; argc
; --argc
, ++argv
) {
320 ecomadd
= ecommunity_str2com(argv
[0]->arg
,
321 ECOMMUNITY_ROUTE_TARGET
, 0);
323 vty_out(vty
, "Malformed community-list value\n");
325 ecommunity_free(&ecom
);
326 return CMD_WARNING_CONFIG_FAILED
;
330 ecommunity_merge(ecom
, ecomadd
);
331 ecommunity_free(&ecomadd
);
338 ecommunity_free(&*list
);
345 DEFUN (vnc_defaults_rt_import
,
346 vnc_defaults_rt_import_cmd
,
347 "rt import RTLIST...",
348 "Specify default route targets\n"
350 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
352 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
353 return set_ecom_list(vty
, argc
- 2, argv
+ 2,
354 &bgp
->rfapi_cfg
->default_rt_import_list
);
357 DEFUN (vnc_defaults_rt_export
,
358 vnc_defaults_rt_export_cmd
,
359 "rt export RTLIST...",
360 "Configure default route targets\n"
362 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
364 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
365 return set_ecom_list(vty
, argc
- 2, argv
+ 2,
366 &bgp
->rfapi_cfg
->default_rt_export_list
);
369 DEFUN (vnc_defaults_rt_both
,
370 vnc_defaults_rt_both_cmd
,
372 "Configure default route targets\n"
373 "Export+import filters\n"
374 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
376 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
379 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
380 &bgp
->rfapi_cfg
->default_rt_import_list
);
381 if (rc
!= CMD_SUCCESS
)
383 return set_ecom_list(vty
, argc
- 2, argv
+ 2,
384 &bgp
->rfapi_cfg
->default_rt_export_list
);
387 DEFUN (vnc_defaults_rd
,
389 "rd ASN:NN_OR_IP-ADDRESS:NN",
390 "Specify default route distinguisher\n"
391 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:vn:<number> )\n")
393 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
395 struct prefix_rd prd
;
397 if (!strncmp(argv
[1]->arg
, "auto:vn:", 8)) {
399 * use AF_UNIX to designate automatically-assigned RD
400 * auto:vn:nn where nn is a 2-octet quantity
403 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
404 uint16_t value
= value32
& 0xffff;
406 if (!argv
[1]->arg
[8] || *end
) {
407 vty_out(vty
, "%% Malformed rd\n");
408 return CMD_WARNING_CONFIG_FAILED
;
410 if (value32
> 0xffff) {
411 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
413 return CMD_WARNING_CONFIG_FAILED
;
416 memset(&prd
, 0, sizeof(prd
));
417 prd
.family
= AF_UNIX
;
419 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
420 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
421 prd
.val
[6] = (value
>> 8) & 0x0ff;
422 prd
.val
[7] = value
& 0x0ff;
426 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
428 vty_out(vty
, "%% Malformed rd\n");
429 return CMD_WARNING_CONFIG_FAILED
;
433 bgp
->rfapi_cfg
->default_rd
= prd
;
437 DEFUN (vnc_defaults_l2rd
,
438 vnc_defaults_l2rd_cmd
,
439 "l2rd <(1-255)|auto-vn>",
440 "Specify default Local Nve ID value to use in RD for L2 routes\n"
441 "Fixed value 1-255\n"
442 "use the low-order octet of the NVE's VN address\n")
444 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
447 if (strmatch(argv
[1]->text
, "auto-vn")) {
451 unsigned long value_l
= strtoul(argv
[1]->arg
, &end
, 10);
453 value
= value_l
& 0xff;
454 if (!argv
[1]->arg
[0] || *end
) {
455 vty_out(vty
, "%% Malformed l2 nve ID \"%s\"\n",
457 return CMD_WARNING_CONFIG_FAILED
;
459 if ((value_l
< 1) || (value_l
> 0xff)) {
461 "%% Malformed l2 nve id (must be greater than 0 and less than %u\n",
463 return CMD_WARNING_CONFIG_FAILED
;
466 bgp
->rfapi_cfg
->flags
|= BGP_VNC_CONFIG_L2RD
;
467 bgp
->rfapi_cfg
->default_l2rd
= value
;
472 DEFUN (vnc_defaults_no_l2rd
,
473 vnc_defaults_no_l2rd_cmd
,
476 "Specify default Local Nve ID value to use in RD for L2 routes\n")
478 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
480 bgp
->rfapi_cfg
->default_l2rd
= 0;
481 bgp
->rfapi_cfg
->flags
&= ~BGP_VNC_CONFIG_L2RD
;
486 DEFUN (vnc_defaults_responselifetime
,
487 vnc_defaults_responselifetime_cmd
,
488 "response-lifetime <LIFETIME|infinite>",
489 "Specify default response lifetime\n"
490 "Response lifetime in seconds\n" "Infinite response lifetime\n")
492 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
494 struct rfapi
*h
= NULL
;
495 struct listnode
*hdnode
;
496 struct rfapi_descriptor
*rfd
;
500 return CMD_WARNING_CONFIG_FAILED
;
502 if (strmatch(argv
[1]->text
, "infinite")) {
503 rspint
= RFAPI_INFINITE_LIFETIME
;
505 rspint
= strtoul(argv
[1]->arg
, NULL
, 10);
506 if (rspint
> INT32_MAX
)
507 rspint
= INT32_MAX
; /* is really an int, not an unsigned
511 bgp
->rfapi_cfg
->default_response_lifetime
= rspint
;
513 for (ALL_LIST_ELEMENTS_RO(&h
->descriptors
, hdnode
, rfd
))
515 && !(rfd
->rfg
->flags
& RFAPI_RFG_RESPONSE_LIFETIME
))
516 rfd
->response_lifetime
= rfd
->rfg
->response_lifetime
=
522 struct rfapi_nve_group_cfg
*
523 bgp_rfapi_cfg_match_byname(struct bgp
*bgp
, const char *name
,
524 rfapi_group_cfg_type_t type
) /* _MAX = any */
526 struct rfapi_nve_group_cfg
*rfg
;
527 struct listnode
*node
, *nnode
;
529 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->nve_groups_sequential
, node
,
531 if ((type
== RFAPI_GROUP_CFG_MAX
|| type
== rfg
->type
)
532 && !strcmp(rfg
->name
, name
))
538 static struct rfapi_nve_group_cfg
*
539 rfapi_group_new(struct bgp
*bgp
, rfapi_group_cfg_type_t type
, const char *name
)
541 struct rfapi_nve_group_cfg
*rfg
;
543 rfg
= XCALLOC(MTYPE_RFAPI_GROUP_CFG
,
544 sizeof(struct rfapi_nve_group_cfg
));
546 rfg
->name
= strdup(name
);
547 /* add to tail of list */
548 listnode_add(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
);
549 rfg
->label
= MPLS_LABEL_NONE
;
551 QOBJ_REG(rfg
, rfapi_nve_group_cfg
);
556 static struct rfapi_l2_group_cfg
*rfapi_l2_group_lookup_byname(struct bgp
*bgp
,
559 struct rfapi_l2_group_cfg
*rfg
;
560 struct listnode
*node
, *nnode
;
562 if (bgp
->rfapi_cfg
->l2_groups
== NULL
) /* not the best place for this */
563 bgp
->rfapi_cfg
->l2_groups
= list_new();
565 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->l2_groups
, node
, nnode
, rfg
)) {
566 if (!strcmp(rfg
->name
, name
))
572 static struct rfapi_l2_group_cfg
*rfapi_l2_group_new(void)
574 struct rfapi_l2_group_cfg
*rfg
;
576 rfg
= XCALLOC(MTYPE_RFAPI_L2_CFG
, sizeof(struct rfapi_l2_group_cfg
));
577 QOBJ_REG(rfg
, rfapi_l2_group_cfg
);
582 static void rfapi_l2_group_del(struct rfapi_l2_group_cfg
*rfg
)
585 XFREE(MTYPE_RFAPI_L2_CFG
, rfg
);
588 static int rfapi_str2route_type(const char *l3str
, const char *pstr
, afi_t
*afi
,
594 if (!strcmp(l3str
, "ipv4")) {
597 if (!strcmp(l3str
, "ipv6"))
603 if (!strcmp(pstr
, "connected"))
604 *type
= ZEBRA_ROUTE_CONNECT
;
605 if (!strcmp(pstr
, "kernel"))
606 *type
= ZEBRA_ROUTE_KERNEL
;
607 if (!strcmp(pstr
, "static"))
608 *type
= ZEBRA_ROUTE_STATIC
;
609 if (!strcmp(pstr
, "bgp"))
610 *type
= ZEBRA_ROUTE_BGP
;
611 if (!strcmp(pstr
, "bgp-direct"))
612 *type
= ZEBRA_ROUTE_BGP_DIRECT
;
613 if (!strcmp(pstr
, "bgp-direct-to-nve-groups"))
614 *type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
616 if (!strcmp(pstr
, "rip")) {
618 *type
= ZEBRA_ROUTE_RIP
;
620 *type
= ZEBRA_ROUTE_RIPNG
;
623 if (!strcmp(pstr
, "ripng")) {
626 *type
= ZEBRA_ROUTE_RIPNG
;
629 if (!strcmp(pstr
, "ospf")) {
631 *type
= ZEBRA_ROUTE_OSPF
;
633 *type
= ZEBRA_ROUTE_OSPF6
;
636 if (!strcmp(pstr
, "ospf6")) {
639 *type
= ZEBRA_ROUTE_OSPF6
;
645 /*-------------------------------------------------------------------------
647 *-----------------------------------------------------------------------*/
649 #define VNC_REDIST_ENABLE(bgp, afi, type) \
652 case ZEBRA_ROUTE_BGP_DIRECT: \
653 vnc_import_bgp_redist_enable((bgp), (afi)); \
655 case ZEBRA_ROUTE_BGP_DIRECT_EXT: \
656 vnc_import_bgp_exterior_redist_enable((bgp), (afi)); \
659 if ((type) < ZEBRA_ROUTE_MAX) \
660 vnc_redistribute_set((bgp), (afi), (type)); \
665 #define VNC_REDIST_DISABLE(bgp, afi, type) \
668 case ZEBRA_ROUTE_BGP_DIRECT: \
669 vnc_import_bgp_redist_disable((bgp), (afi)); \
671 case ZEBRA_ROUTE_BGP_DIRECT_EXT: \
672 vnc_import_bgp_exterior_redist_disable((bgp), (afi)); \
675 if ((type) < ZEBRA_ROUTE_MAX) \
676 vnc_redistribute_unset((bgp), (afi), (type)); \
681 static uint8_t redist_was_enabled
[AFI_MAX
][ZEBRA_ROUTE_MAX
];
683 static void vnc_redistribute_prechange(struct bgp
*bgp
)
688 vnc_zlog_debug_verbose("%s: entry", __func__
);
689 memset(redist_was_enabled
, 0, sizeof(redist_was_enabled
));
692 * Look to see if we have any redistribution enabled. If so, flush
693 * the corresponding routes and turn off redistribution temporarily.
694 * We need to do it because the RD's used for the redistributed
695 * routes depend on the nve group.
697 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
698 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
699 if (bgp
->rfapi_cfg
->redist
[afi
][type
]) {
700 redist_was_enabled
[afi
][type
] = 1;
701 VNC_REDIST_DISABLE(bgp
, afi
, type
);
705 vnc_zlog_debug_verbose("%s: return", __func__
);
708 static void vnc_redistribute_postchange(struct bgp
*bgp
)
713 vnc_zlog_debug_verbose("%s: entry", __func__
);
715 * If we turned off redistribution above, turn it back on. Doing so
716 * will tell zebra to resend the routes to us
718 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
719 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
720 if (redist_was_enabled
[afi
][type
]) {
721 VNC_REDIST_ENABLE(bgp
, afi
, type
);
725 vnc_zlog_debug_verbose("%s: return", __func__
);
728 DEFUN (vnc_redistribute_rh_roo_localadmin
,
729 vnc_redistribute_rh_roo_localadmin_cmd
,
730 "vnc redistribute resolve-nve roo-ec-local-admin (0-65535)",
732 "Redistribute routes into VNC\n"
734 "Route Origin Extended Community Local Admin Field\n" "Field value\n")
736 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
740 VNC_VTY_CONFIG_CHECK(bgp
);
742 localadmin
= strtoul(argv
[4]->arg
, &endptr
, 0);
743 if (!argv
[4]->arg
[0] || *endptr
) {
744 vty_out(vty
, "%% Malformed value\n");
745 return CMD_WARNING_CONFIG_FAILED
;
748 if (localadmin
> 0xffff) {
749 vty_out(vty
, "%% Value out of range (0-%d)\n", 0xffff);
750 return CMD_WARNING_CONFIG_FAILED
;
753 if (bgp
->rfapi_cfg
->resolve_nve_roo_local_admin
== localadmin
)
756 if ((bgp
->rfapi_cfg
->flags
& BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
)
757 == BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE
) {
759 vnc_export_bgp_prechange(bgp
);
761 vnc_redistribute_prechange(bgp
);
763 bgp
->rfapi_cfg
->resolve_nve_roo_local_admin
= localadmin
;
765 if ((bgp
->rfapi_cfg
->flags
& BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
)
766 == BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE
) {
768 vnc_export_bgp_postchange(bgp
);
770 vnc_redistribute_postchange(bgp
);
776 DEFUN (vnc_redistribute_mode
,
777 vnc_redistribute_mode_cmd
,
778 "vnc redistribute mode <nve-group|plain|resolve-nve>",
780 "Redistribute routes into VNC\n"
781 "Redistribution mode\n"
782 "Based on redistribute nve-group\n"
783 "Unmodified\n" "Resolve each nexthop to connected NVEs\n")
785 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
786 vnc_redist_mode_t newmode
;
788 VNC_VTY_CONFIG_CHECK(bgp
);
790 switch (argv
[3]->arg
[0]) {
792 newmode
= VNC_REDIST_MODE_RFG
;
796 newmode
= VNC_REDIST_MODE_PLAIN
;
800 newmode
= VNC_REDIST_MODE_RESOLVE_NVE
;
804 vty_out(vty
, "unknown redistribute mode\n");
805 return CMD_WARNING_CONFIG_FAILED
;
808 if (newmode
!= bgp
->rfapi_cfg
->redist_mode
) {
809 vnc_redistribute_prechange(bgp
);
810 bgp
->rfapi_cfg
->redist_mode
= newmode
;
811 vnc_redistribute_postchange(bgp
);
817 DEFUN (vnc_redistribute_protocol
,
818 vnc_redistribute_protocol_cmd
,
819 "vnc redistribute <ipv4|ipv6> <bgp|bgp-direct|bgp-direct-to-nve-groups|connected|kernel|ospf|rip|static>",
821 "Redistribute routes into VNC\n"
825 "From BGP without Zebra\n"
826 "From BGP without Zebra, only to configured NVE groups\n"
827 "Connected interfaces\n"
828 "From kernel routes\n"
829 "From Open Shortest Path First (OSPF)\n"
830 "From Routing Information Protocol (RIP)\n" "From Static routes\n")
832 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
833 int type
= ZEBRA_ROUTE_MAX
; /* init to bogus value */
836 VNC_VTY_CONFIG_CHECK(bgp
);
838 if (rfapi_str2route_type(argv
[2]->arg
, argv
[3]->arg
, &afi
, &type
)) {
839 vty_out(vty
, "%% Invalid route type\n");
840 return CMD_WARNING_CONFIG_FAILED
;
843 if (type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
) {
844 if (bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
) {
845 VNC_REDIST_DISABLE(bgp
, afi
,
846 type
); /* disabled view implicitly */
847 free(bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
);
848 bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
= NULL
;
850 bgp
->rfapi_cfg
->redist_bgp_exterior_view
= bgp
;
853 VNC_REDIST_ENABLE(bgp
, afi
, type
);
858 DEFUN (vnc_no_redistribute_protocol
,
859 vnc_no_redistribute_protocol_cmd
,
860 "no vnc redistribute <ipv4|ipv6> <bgp|bgp-direct|bgp-direct-to-nve-groups|connected|kernel|ospf|rip|static>",
863 "Redistribute from other protocol\n"
867 "From BGP without Zebra\n"
868 "From BGP without Zebra, only to configured NVE groups\n"
869 "Connected interfaces\n"
870 "From kernel routes\n"
871 "From Open Shortest Path First (OSPF)\n"
872 "From Routing Information Protocol (RIP)\n" "From Static routes\n")
874 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
878 VNC_VTY_CONFIG_CHECK(bgp
);
880 if (rfapi_str2route_type(argv
[3]->arg
, argv
[4]->arg
, &afi
, &type
)) {
881 vty_out(vty
, "%% Invalid route type\n");
882 return CMD_WARNING_CONFIG_FAILED
;
885 VNC_REDIST_DISABLE(bgp
, afi
, type
);
887 if (type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
) {
888 if (bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
) {
889 free(bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
);
890 bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
= NULL
;
892 bgp
->rfapi_cfg
->redist_bgp_exterior_view
= NULL
;
898 DEFUN (vnc_redistribute_bgp_exterior
,
899 vnc_redistribute_bgp_exterior_cmd
,
900 "vnc redistribute <ipv4|ipv6> bgp-direct-to-nve-groups view NAME",
902 "Redistribute routes into VNC\n"
905 "From BGP without Zebra, only to configured NVE groups\n"
906 "From BGP view\n" "BGP view name\n")
908 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
912 VNC_VTY_CONFIG_CHECK(bgp
);
914 if (rfapi_str2route_type(argv
[2]->arg
, "bgp-direct-to-nve-groups", &afi
,
916 vty_out(vty
, "%% Invalid route type\n");
917 return CMD_WARNING_CONFIG_FAILED
;
920 if (bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
)
921 free(bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
);
922 bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
= strdup(argv
[5]->arg
);
923 /* could be NULL if name is not defined yet */
924 bgp
->rfapi_cfg
->redist_bgp_exterior_view
=
925 bgp_lookup_by_name(argv
[5]->arg
);
927 VNC_REDIST_ENABLE(bgp
, afi
, type
);
932 DEFUN (vnc_redistribute_nvegroup
,
933 vnc_redistribute_nvegroup_cmd
,
934 "vnc redistribute nve-group NAME",
936 "Assign a NVE group to routes redistributed from another routing protocol\n"
937 "NVE group\n" "Group name\n")
939 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
940 VNC_VTY_CONFIG_CHECK(bgp
);
942 vnc_redistribute_prechange(bgp
);
945 * OK if nve group doesn't exist yet; we'll set the pointer
946 * when the group is defined later
948 bgp
->rfapi_cfg
->rfg_redist
= bgp_rfapi_cfg_match_byname(
949 bgp
, argv
[3]->arg
, RFAPI_GROUP_CFG_NVE
);
950 if (bgp
->rfapi_cfg
->rfg_redist_name
)
951 free(bgp
->rfapi_cfg
->rfg_redist_name
);
952 bgp
->rfapi_cfg
->rfg_redist_name
= strdup(argv
[3]->arg
);
954 vnc_redistribute_postchange(bgp
);
959 DEFUN (vnc_redistribute_no_nvegroup
,
960 vnc_redistribute_no_nvegroup_cmd
,
961 "no vnc redistribute nve-group",
964 "Redistribute from other protocol\n"
965 "Assign a NVE group to routes redistributed from another routing protocol\n")
967 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
969 VNC_VTY_CONFIG_CHECK(bgp
);
971 vnc_redistribute_prechange(bgp
);
973 bgp
->rfapi_cfg
->rfg_redist
= NULL
;
974 if (bgp
->rfapi_cfg
->rfg_redist_name
)
975 free(bgp
->rfapi_cfg
->rfg_redist_name
);
976 bgp
->rfapi_cfg
->rfg_redist_name
= NULL
;
978 vnc_redistribute_postchange(bgp
);
984 DEFUN (vnc_redistribute_lifetime
,
985 vnc_redistribute_lifetime_cmd
,
986 "vnc redistribute lifetime <LIFETIME|infinite>",
989 "Assign a lifetime to routes redistributed from another routing protocol\n"
990 "lifetime value (32 bit)\n"
991 "Allow lifetime to never expire\n")
993 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
994 VNC_VTY_CONFIG_CHECK(bgp
);
996 vnc_redistribute_prechange(bgp
);
998 if (strmatch(argv
[3]->text
, "infinite")) {
999 bgp
->rfapi_cfg
->redist_lifetime
= RFAPI_INFINITE_LIFETIME
;
1001 bgp
->rfapi_cfg
->redist_lifetime
=
1002 strtoul(argv
[3]->arg
, NULL
, 10);
1005 vnc_redistribute_postchange(bgp
);
1010 /*-- redist policy, non-nvegroup start --*/
1012 DEFUN (vnc_redist_bgpdirect_no_prefixlist
,
1013 vnc_redist_bgpdirect_no_prefixlist_cmd
,
1014 "no vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> <ipv4|ipv6> prefix-list",
1017 "Redistribute from other protocol\n"
1018 "Redistribute from BGP directly\n"
1019 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1021 "IPv6 routes\n" "Prefix-list for filtering redistributed routes\n")
1023 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1025 struct rfapi_cfg
*hc
;
1026 uint8_t route_type
= 0;
1028 VNC_VTY_CONFIG_CHECK(bgp
);
1029 hc
= bgp
->rfapi_cfg
;
1031 if (strmatch(argv
[3]->text
, "bgp-direct")) {
1032 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1034 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1037 if (strmatch(argv
[4]->text
, "ipv4")) {
1043 vnc_redistribute_prechange(bgp
);
1045 if (hc
->plist_redist_name
[route_type
][afi
])
1046 free(hc
->plist_redist_name
[route_type
][afi
]);
1047 hc
->plist_redist_name
[route_type
][afi
] = NULL
;
1048 hc
->plist_redist
[route_type
][afi
] = NULL
;
1050 vnc_redistribute_postchange(bgp
);
1055 DEFUN (vnc_redist_bgpdirect_prefixlist
,
1056 vnc_redist_bgpdirect_prefixlist_cmd
,
1057 "vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> <ipv4|ipv6> prefix-list NAME",
1059 "Redistribute from other protocol\n"
1060 "Redistribute from BGP directly\n"
1061 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1064 "Prefix-list for filtering redistributed routes\n"
1065 "prefix list name\n")
1067 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1068 struct rfapi_cfg
*hc
;
1070 uint8_t route_type
= 0;
1072 VNC_VTY_CONFIG_CHECK(bgp
);
1073 hc
= bgp
->rfapi_cfg
;
1075 if (strmatch(argv
[2]->text
, "bgp-direct")) {
1076 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1078 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1081 if (strmatch(argv
[3]->text
, "ipv4")) {
1087 vnc_redistribute_prechange(bgp
);
1089 if (hc
->plist_redist_name
[route_type
][afi
])
1090 free(hc
->plist_redist_name
[route_type
][afi
]);
1091 hc
->plist_redist_name
[route_type
][afi
] = strdup(argv
[5]->arg
);
1092 hc
->plist_redist
[route_type
][afi
] =
1093 prefix_list_lookup(afi
, argv
[5]->arg
);
1095 vnc_redistribute_postchange(bgp
);
1100 DEFUN (vnc_redist_bgpdirect_no_routemap
,
1101 vnc_redist_bgpdirect_no_routemap_cmd
,
1102 "no vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> route-map",
1105 "Redistribute from other protocols\n"
1106 "Redistribute from BGP directly\n"
1107 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1108 "Route-map for filtering redistributed routes\n")
1110 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1111 struct rfapi_cfg
*hc
;
1112 uint8_t route_type
= 0;
1114 VNC_VTY_CONFIG_CHECK(bgp
);
1115 hc
= bgp
->rfapi_cfg
;
1117 if (strmatch(argv
[3]->text
, "bgp-direct")) {
1118 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1120 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1123 vnc_redistribute_prechange(bgp
);
1125 if (hc
->routemap_redist_name
[route_type
])
1126 free(hc
->routemap_redist_name
[route_type
]);
1127 hc
->routemap_redist_name
[route_type
] = NULL
;
1128 hc
->routemap_redist
[route_type
] = NULL
;
1130 vnc_redistribute_postchange(bgp
);
1135 DEFUN (vnc_redist_bgpdirect_routemap
,
1136 vnc_redist_bgpdirect_routemap_cmd
,
1137 "vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> route-map NAME",
1139 "Redistribute from other protocols\n"
1140 "Redistribute from BGP directly\n"
1141 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1142 "Route-map for filtering exported routes\n" "route map name\n")
1144 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1145 struct rfapi_cfg
*hc
;
1146 uint8_t route_type
= 0;
1148 VNC_VTY_CONFIG_CHECK(bgp
);
1149 hc
= bgp
->rfapi_cfg
;
1151 if (strmatch(argv
[2]->text
, "bgp-direct")) {
1152 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1154 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1157 vnc_redistribute_prechange(bgp
);
1159 if (hc
->routemap_redist_name
[route_type
])
1160 free(hc
->routemap_redist_name
[route_type
]);
1162 /* If the old route map config overwrite with new
1163 * route map config , old routemap counter have to be
1166 route_map_counter_decrement(hc
->routemap_redist
[route_type
]);
1167 hc
->routemap_redist_name
[route_type
] = strdup(argv
[4]->arg
);
1168 hc
->routemap_redist
[route_type
] =
1169 route_map_lookup_by_name(argv
[4]->arg
);
1170 route_map_counter_increment(hc
->routemap_redist
[route_type
]);
1172 vnc_redistribute_postchange(bgp
);
1177 /*-- redist policy, non-nvegroup end --*/
1179 /*-- redist policy, nvegroup start --*/
1181 DEFUN (vnc_nve_group_redist_bgpdirect_no_prefixlist
,
1182 vnc_nve_group_redist_bgpdirect_no_prefixlist_cmd
,
1183 "no redistribute bgp-direct <ipv4|ipv6> prefix-list",
1185 "Redistribute from other protocol\n"
1186 "Redistribute from BGP directly\n"
1189 "Prefix-list for filtering redistributed routes\n")
1191 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1192 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
)
1195 VNC_VTY_CONFIG_CHECK(bgp
);
1197 /* make sure it's still in list */
1198 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1199 /* Not in list anymore */
1200 vty_out(vty
, "Current NVE group no longer exists\n");
1201 return CMD_WARNING_CONFIG_FAILED
;
1204 if (strmatch(argv
[3]->text
, "ipv4")) {
1210 vnc_redistribute_prechange(bgp
);
1212 if (rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
])
1213 free(rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
]);
1214 rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] = NULL
;
1215 rfg
->plist_redist
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] = NULL
;
1217 vnc_redistribute_postchange(bgp
);
1222 DEFUN (vnc_nve_group_redist_bgpdirect_prefixlist
,
1223 vnc_nve_group_redist_bgpdirect_prefixlist_cmd
,
1224 "redistribute bgp-direct <ipv4|ipv6> prefix-list NAME",
1225 "Redistribute from other protocol\n"
1226 "Redistribute from BGP directly\n"
1229 "Prefix-list for filtering redistributed routes\n"
1230 "prefix list name\n")
1232 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1233 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1236 VNC_VTY_CONFIG_CHECK(bgp
);
1238 /* make sure it's still in list */
1239 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1240 /* Not in list anymore */
1241 vty_out(vty
, "Current NVE group no longer exists\n");
1242 return CMD_WARNING_CONFIG_FAILED
;
1245 if (strmatch(argv
[2]->text
, "ipv4")) {
1251 vnc_redistribute_prechange(bgp
);
1253 if (rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
])
1254 free(rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
]);
1255 rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] =
1256 strdup(argv
[4]->arg
);
1257 rfg
->plist_redist
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] =
1258 prefix_list_lookup(afi
, argv
[4]->arg
);
1260 vnc_redistribute_postchange(bgp
);
1265 DEFUN (vnc_nve_group_redist_bgpdirect_no_routemap
,
1266 vnc_nve_group_redist_bgpdirect_no_routemap_cmd
,
1267 "no redistribute bgp-direct route-map",
1269 "Redistribute from other protocols\n"
1270 "Redistribute from BGP directly\n"
1271 "Route-map for filtering redistributed routes\n")
1273 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1274 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1276 VNC_VTY_CONFIG_CHECK(bgp
);
1278 /* make sure it's still in list */
1279 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1280 /* Not in list anymore */
1281 vty_out(vty
, "Current NVE group no longer exists\n");
1282 return CMD_WARNING_CONFIG_FAILED
;
1285 vnc_redistribute_prechange(bgp
);
1287 if (rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
])
1288 free(rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]);
1289 route_map_counter_decrement(
1290 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
]);
1291 rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
] = NULL
;
1292 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
] = NULL
;
1294 vnc_redistribute_postchange(bgp
);
1299 DEFUN (vnc_nve_group_redist_bgpdirect_routemap
,
1300 vnc_nve_group_redist_bgpdirect_routemap_cmd
,
1301 "redistribute bgp-direct route-map NAME",
1302 "Redistribute from other protocols\n"
1303 "Redistribute from BGP directly\n"
1304 "Route-map for filtering exported routes\n" "route map name\n")
1306 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1307 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1309 VNC_VTY_CONFIG_CHECK(bgp
);
1311 /* make sure it's still in list */
1312 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1313 /* Not in list anymore */
1314 vty_out(vty
, "Current NVE group no longer exists\n");
1315 return CMD_WARNING_CONFIG_FAILED
;
1318 vnc_redistribute_prechange(bgp
);
1320 if (rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
])
1321 free(rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]);
1322 route_map_counter_decrement(
1323 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
]);
1324 rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
] =
1325 strdup(argv
[3]->arg
);
1326 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
] =
1327 route_map_lookup_by_name(argv
[3]->arg
);
1328 route_map_counter_increment(
1329 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
]);
1331 vnc_redistribute_postchange(bgp
);
1336 /*-- redist policy, nvegroup end --*/
1338 /*-------------------------------------------------------------------------
1340 *-----------------------------------------------------------------------*/
1342 DEFUN (vnc_export_mode
,
1343 vnc_export_mode_cmd
,
1344 "vnc export <bgp|zebra> mode <group-nve|ce|none|registering-nve>",
1346 "Export to other protocols\n"
1348 "Export to Zebra (experimental)\n"
1349 "Select export mode\n"
1350 "Export routes with nve-group next-hops\n"
1351 "Export routes with NVE connected router next-hops\n"
1352 "Disable export\n" "Export routes with registering NVE as next-hop\n")
1354 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1355 uint32_t oldmode
= 0;
1356 uint32_t newmode
= 0;
1358 VNC_VTY_CONFIG_CHECK(bgp
);
1360 if (argv
[2]->arg
[0] == 'b') {
1361 oldmode
= bgp
->rfapi_cfg
->flags
1362 & BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
;
1363 switch (argv
[4]->arg
[0]) {
1365 newmode
= BGP_VNC_CONFIG_EXPORT_BGP_MODE_GRP
;
1368 newmode
= BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE
;
1374 newmode
= BGP_VNC_CONFIG_EXPORT_BGP_MODE_RH
;
1377 vty_out(vty
, "Invalid mode specified\n");
1378 return CMD_WARNING_CONFIG_FAILED
;
1381 if (newmode
== oldmode
) {
1382 vty_out(vty
, "Mode unchanged\n");
1386 vnc_export_bgp_prechange(bgp
);
1388 bgp
->rfapi_cfg
->flags
&= ~BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
;
1389 bgp
->rfapi_cfg
->flags
|= newmode
;
1391 vnc_export_bgp_postchange(bgp
);
1396 * export to zebra with RH mode is not yet implemented
1399 "Changing modes for zebra export not implemented yet\n");
1400 return CMD_WARNING_CONFIG_FAILED
;
1406 static struct rfapi_rfg_name
*rfgn_new(void)
1408 return XCALLOC(MTYPE_RFAPI_RFG_NAME
, sizeof(struct rfapi_rfg_name
));
1411 static void rfgn_free(struct rfapi_rfg_name
*rfgn
)
1413 XFREE(MTYPE_RFAPI_RFG_NAME
, rfgn
);
1416 DEFUN (vnc_export_nvegroup
,
1417 vnc_export_nvegroup_cmd
,
1418 "vnc export <bgp|zebra> group-nve group NAME",
1420 "Export to other protocols\n"
1422 "Export to Zebra (experimental)\n"
1423 "NVE group, used in 'group-nve' export mode\n"
1424 "NVE group\n" "Group name\n")
1426 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1427 struct rfapi_nve_group_cfg
*rfg_new
;
1429 VNC_VTY_CONFIG_CHECK(bgp
);
1431 rfg_new
= bgp_rfapi_cfg_match_byname(bgp
, argv
[5]->arg
,
1432 RFAPI_GROUP_CFG_NVE
);
1433 if (rfg_new
== NULL
) {
1434 rfg_new
= bgp_rfapi_cfg_match_byname(bgp
, argv
[5]->arg
,
1435 RFAPI_GROUP_CFG_VRF
);
1437 vnc_add_vrf_opener(bgp
, rfg_new
);
1440 if (rfg_new
== NULL
) {
1441 vty_out(vty
, "Can't find group named \"%s\".\n", argv
[5]->arg
);
1442 return CMD_WARNING_CONFIG_FAILED
;
1445 if (argv
[2]->arg
[0] == 'b') {
1447 struct listnode
*node
;
1448 struct rfapi_rfg_name
*rfgn
;
1451 * Set group for export to BGP Direct
1454 /* see if group is already included in export list */
1455 for (ALL_LIST_ELEMENTS_RO(
1456 bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
1459 if (!strcmp(rfgn
->name
, argv
[5]->arg
)) {
1460 /* already in the list: we're done */
1466 rfgn
->name
= strdup(argv
[5]->arg
);
1467 rfgn
->rfg
= rfg_new
; /* OK if not set yet */
1469 listnode_add(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, rfgn
);
1471 vnc_zlog_debug_verbose("%s: testing rfg_new", __func__
);
1473 vnc_zlog_debug_verbose(
1474 "%s: testing bgp grp mode enabled", __func__
);
1475 if (VNC_EXPORT_BGP_GRP_ENABLED(bgp
->rfapi_cfg
))
1476 vnc_zlog_debug_verbose(
1477 "%s: calling vnc_direct_bgp_add_group",
1479 vnc_direct_bgp_add_group(bgp
, rfg_new
);
1484 struct listnode
*node
;
1485 struct rfapi_rfg_name
*rfgn
;
1488 * Set group for export to Zebra
1491 /* see if group is already included in export list */
1492 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
,
1495 if (!strcmp(rfgn
->name
, argv
[5]->arg
)) {
1496 /* already in the list: we're done */
1502 rfgn
->name
= strdup(argv
[5]->arg
);
1503 rfgn
->rfg
= rfg_new
; /* OK if not set yet */
1505 listnode_add(bgp
->rfapi_cfg
->rfg_export_zebra_l
, rfgn
);
1508 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(bgp
->rfapi_cfg
))
1509 vnc_zebra_add_group(bgp
, rfg_new
);
1517 * This command applies to routes exported from VNC to BGP directly
1518 * without going though zebra
1520 DEFUN (vnc_no_export_nvegroup
,
1521 vnc_no_export_nvegroup_cmd
,
1522 "vnc export <bgp|zebra> group-nve no group NAME",
1524 "Export to other protocols\n"
1526 "Export to Zebra (experimental)\n"
1527 "NVE group, used in 'group-nve' export mode\n"
1528 "Disable export of VNC routes\n" "NVE group\n" "Group name\n")
1530 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1531 struct listnode
*node
, *nnode
;
1532 struct rfapi_rfg_name
*rfgn
;
1534 VNC_VTY_CONFIG_CHECK(bgp
);
1536 if (argv
[2]->arg
[0] == 'b') {
1537 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
,
1538 node
, nnode
, rfgn
)) {
1540 if (rfgn
->name
&& !strcmp(rfgn
->name
, argv
[6]->arg
)) {
1541 vnc_zlog_debug_verbose("%s: matched \"%s\"",
1542 __func__
, rfgn
->name
);
1544 vnc_direct_bgp_del_group(bgp
,
1548 bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
,
1555 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
1558 vnc_zlog_debug_verbose("does rfg \"%s\" match?",
1560 if (rfgn
->name
&& !strcmp(rfgn
->name
, argv
[6]->arg
)) {
1562 vnc_zebra_del_group(bgp
, rfgn
->rfg
);
1565 bgp
->rfapi_cfg
->rfg_export_zebra_l
,
1575 DEFUN (vnc_nve_group_export_no_prefixlist
,
1576 vnc_nve_group_export_no_prefixlist_cmd
,
1577 "no export <bgp|zebra> <ipv4|ipv6> prefix-list [NAME]",
1579 "Export to other protocols\n"
1581 "Export to Zebra (experimental)\n"
1584 "Prefix-list for filtering exported routes\n" "prefix list name\n")
1586 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1587 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1592 VNC_VTY_CONFIG_CHECK(bgp
);
1594 /* make sure it's still in list */
1595 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1596 /* Not in list anymore */
1597 vty_out(vty
, "Current NVE group no longer exists\n");
1598 return CMD_WARNING_CONFIG_FAILED
;
1601 if (!argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
1602 vty_out(vty
, "%% Malformed Address Family\n");
1603 return CMD_WARNING_CONFIG_FAILED
;
1606 if (argv
[idx
- 1]->text
[0] == 'z')
1608 idx
+= 2; /* skip afi and keyword */
1612 || (rfg
->plist_export_bgp_name
[afi
]
1613 && strmatch(argv
[idx
]->arg
,
1614 rfg
->plist_export_bgp_name
[afi
]))) {
1615 if (rfg
->plist_export_bgp_name
[afi
])
1616 free(rfg
->plist_export_bgp_name
[afi
]);
1617 rfg
->plist_export_bgp_name
[afi
] = NULL
;
1618 rfg
->plist_export_bgp
[afi
] = NULL
;
1620 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, afi
);
1624 || (rfg
->plist_export_zebra_name
[afi
]
1625 && strmatch(argv
[idx
]->arg
,
1626 rfg
->plist_export_zebra_name
[afi
]))) {
1627 if (rfg
->plist_export_zebra_name
[afi
])
1628 free(rfg
->plist_export_zebra_name
[afi
]);
1629 rfg
->plist_export_zebra_name
[afi
] = NULL
;
1630 rfg
->plist_export_zebra
[afi
] = NULL
;
1632 vnc_zebra_reexport_group_afi(bgp
, rfg
, afi
);
1638 ALIAS (vnc_nve_group_export_no_prefixlist
,
1639 vnc_vrf_policy_export_no_prefixlist_cmd
,
1640 "no export <ipv4|ipv6> prefix-list [NAME]",
1645 "Prefix-list for filtering exported routes\n" "prefix list name\n")
1647 DEFUN (vnc_nve_group_export_prefixlist
,
1648 vnc_nve_group_export_prefixlist_cmd
,
1649 "export <bgp|zebra> <ipv4|ipv6> prefix-list NAME",
1650 "Export to other protocols\n"
1652 "Export to Zebra (experimental)\n"
1655 "Prefix-list for filtering exported routes\n" "prefix list name\n")
1657 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1658 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1663 VNC_VTY_CONFIG_CHECK(bgp
);
1665 /* make sure it's still in list */
1666 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1667 /* Not in list anymore */
1668 vty_out(vty
, "Current NVE group no longer exists\n");
1669 return CMD_WARNING_CONFIG_FAILED
;
1672 if (!argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
1673 vty_out(vty
, "%% Malformed Address Family\n");
1674 return CMD_WARNING_CONFIG_FAILED
;
1677 if (argv
[idx
- 1]->text
[0] == 'z')
1682 if (rfg
->plist_export_bgp_name
[afi
])
1683 free(rfg
->plist_export_bgp_name
[afi
]);
1684 rfg
->plist_export_bgp_name
[afi
] = strdup(argv
[idx
]->arg
);
1685 rfg
->plist_export_bgp
[afi
] =
1686 prefix_list_lookup(afi
, argv
[idx
]->arg
);
1688 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, afi
);
1691 if (rfg
->plist_export_zebra_name
[afi
])
1692 free(rfg
->plist_export_zebra_name
[afi
]);
1693 rfg
->plist_export_zebra_name
[afi
] = strdup(argv
[idx
]->arg
);
1694 rfg
->plist_export_zebra
[afi
] =
1695 prefix_list_lookup(afi
, argv
[idx
]->arg
);
1697 vnc_zebra_reexport_group_afi(bgp
, rfg
, afi
);
1702 ALIAS (vnc_nve_group_export_prefixlist
,
1703 vnc_vrf_policy_export_prefixlist_cmd
,
1704 "export <ipv4|ipv6> prefix-list NAME",
1708 "Prefix-list for filtering exported routes\n" "prefix list name\n")
1710 DEFUN (vnc_nve_group_export_no_routemap
,
1711 vnc_nve_group_export_no_routemap_cmd
,
1712 "no export <bgp|zebra> route-map [NAME]",
1714 "Export to other protocols\n"
1716 "Export to Zebra (experimental)\n"
1717 "Route-map for filtering exported routes\n" "route map name\n")
1719 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1720 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1724 VNC_VTY_CONFIG_CHECK(bgp
);
1726 /* make sure it's still in list */
1727 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1728 /* Not in list anymore */
1729 vty_out(vty
, "Current NVE group no longer exists\n");
1730 return CMD_WARNING_CONFIG_FAILED
;
1732 switch (argv
[idx
]->text
[0]) {
1739 default: /* route-map */
1746 || (rfg
->routemap_export_bgp_name
1747 && strmatch(argv
[idx
]->arg
,
1748 rfg
->routemap_export_bgp_name
))) {
1749 if (rfg
->routemap_export_bgp_name
)
1750 free(rfg
->routemap_export_bgp_name
);
1751 route_map_counter_decrement(rfg
->routemap_export_bgp
);
1752 rfg
->routemap_export_bgp_name
= NULL
;
1753 rfg
->routemap_export_bgp
= NULL
;
1755 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1756 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1760 || (rfg
->routemap_export_zebra_name
1761 && strmatch(argv
[idx
]->arg
,
1762 rfg
->routemap_export_zebra_name
))) {
1763 if (rfg
->routemap_export_zebra_name
)
1764 free(rfg
->routemap_export_zebra_name
);
1765 route_map_counter_decrement(rfg
->routemap_export_zebra
);
1766 rfg
->routemap_export_zebra_name
= NULL
;
1767 rfg
->routemap_export_zebra
= NULL
;
1769 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1770 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1776 ALIAS (vnc_nve_group_export_no_routemap
,
1777 vnc_vrf_policy_export_no_routemap_cmd
,
1778 "no export route-map [NAME]",
1781 "Route-map for filtering exported routes\n" "route map name\n")
1783 DEFUN (vnc_nve_group_export_routemap
,
1784 vnc_nve_group_export_routemap_cmd
,
1785 "export <bgp|zebra> route-map NAME",
1786 "Export to other protocols\n"
1788 "Export to Zebra (experimental)\n"
1789 "Route-map for filtering exported routes\n" "route map name\n")
1791 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1792 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1796 VNC_VTY_CONFIG_CHECK(bgp
);
1798 /* make sure it's still in list */
1799 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1800 /* Not in list anymore */
1801 vty_out(vty
, "Current NVE group no longer exists\n");
1802 return CMD_WARNING_CONFIG_FAILED
;
1805 if (argv
[1]->text
[0] == 'z')
1810 if (rfg
->routemap_export_bgp_name
)
1811 free(rfg
->routemap_export_bgp_name
);
1812 route_map_counter_decrement(rfg
->routemap_export_bgp
);
1813 rfg
->routemap_export_bgp_name
= strdup(argv
[idx
]->arg
);
1814 rfg
->routemap_export_bgp
=
1815 route_map_lookup_by_name(argv
[idx
]->arg
);
1816 route_map_counter_increment(rfg
->routemap_export_bgp
);
1817 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1818 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1820 if (rfg
->routemap_export_zebra_name
)
1821 free(rfg
->routemap_export_zebra_name
);
1822 route_map_counter_decrement(rfg
->routemap_export_zebra
);
1823 rfg
->routemap_export_zebra_name
= strdup(argv
[idx
]->arg
);
1824 rfg
->routemap_export_zebra
=
1825 route_map_lookup_by_name(argv
[idx
]->arg
);
1826 route_map_counter_increment(rfg
->routemap_export_zebra
);
1827 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1828 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1833 ALIAS (vnc_nve_group_export_routemap
,
1834 vnc_vrf_policy_export_routemap_cmd
,
1835 "export route-map NAME",
1837 "Route-map for filtering exported routes\n" "route map name\n")
1839 DEFUN (vnc_nve_export_no_prefixlist
,
1840 vnc_nve_export_no_prefixlist_cmd
,
1841 "no vnc export <bgp|zebra> <ipv4|ipv6> prefix-list [NAME]",
1844 "Export to other protocols\n"
1846 "Export to Zebra (experimental)\n"
1849 "Prefix-list for filtering exported routes\n" "Prefix list name\n")
1851 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1852 struct rfapi_cfg
*hc
;
1855 VNC_VTY_CONFIG_CHECK(bgp
);
1856 hc
= bgp
->rfapi_cfg
;
1858 if (strmatch(argv
[4]->text
, "ipv4")) {
1864 if (argv
[3]->arg
[0] == 'b') {
1865 if (((argc
> 6) && hc
->plist_export_bgp_name
[afi
]
1866 && strmatch(argv
[6]->text
, hc
->plist_export_bgp_name
[afi
]))
1869 free(hc
->plist_export_bgp_name
[afi
]);
1870 hc
->plist_export_bgp_name
[afi
] = NULL
;
1871 hc
->plist_export_bgp
[afi
] = NULL
;
1872 vnc_direct_bgp_reexport(bgp
, afi
);
1875 if (((argc
> 6) && hc
->plist_export_zebra_name
[afi
]
1876 && strmatch(argv
[6]->text
,
1877 hc
->plist_export_zebra_name
[afi
]))
1880 free(hc
->plist_export_zebra_name
[afi
]);
1881 hc
->plist_export_zebra_name
[afi
] = NULL
;
1882 hc
->plist_export_zebra
[afi
] = NULL
;
1883 /* TBD vnc_zebra_rh_reexport(bgp, afi); */
1889 DEFUN (vnc_nve_export_prefixlist
,
1890 vnc_nve_export_prefixlist_cmd
,
1891 "vnc export <bgp|zebra> <ipv4|ipv6> prefix-list NAME",
1893 "Export to other protocols\n"
1895 "Export to Zebra (experimental)\n"
1898 "Prefix-list for filtering exported routes\n" "Prefix list name\n")
1900 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1901 struct rfapi_cfg
*hc
;
1904 VNC_VTY_CONFIG_CHECK(bgp
);
1905 hc
= bgp
->rfapi_cfg
;
1907 if (strmatch(argv
[3]->text
, "ipv4")) {
1913 if (argv
[2]->arg
[0] == 'b') {
1914 if (hc
->plist_export_bgp_name
[afi
])
1915 free(hc
->plist_export_bgp_name
[afi
]);
1916 hc
->plist_export_bgp_name
[afi
] = strdup(argv
[5]->arg
);
1917 hc
->plist_export_bgp
[afi
] =
1918 prefix_list_lookup(afi
, argv
[5]->arg
);
1919 vnc_direct_bgp_reexport(bgp
, afi
);
1921 if (hc
->plist_export_zebra_name
[afi
])
1922 free(hc
->plist_export_zebra_name
[afi
]);
1923 hc
->plist_export_zebra_name
[afi
] = strdup(argv
[5]->arg
);
1924 hc
->plist_export_zebra
[afi
] =
1925 prefix_list_lookup(afi
, argv
[5]->arg
);
1926 /* TBD vnc_zebra_rh_reexport(bgp, afi); */
1931 DEFUN (vnc_nve_export_no_routemap
,
1932 vnc_nve_export_no_routemap_cmd
,
1933 "no vnc export <bgp|zebra> route-map [NAME]",
1936 "Export to other protocols\n"
1938 "Export to Zebra (experimental)\n"
1939 "Route-map for filtering exported routes\n" "Route map name\n")
1941 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1942 struct rfapi_cfg
*hc
;
1944 VNC_VTY_CONFIG_CHECK(bgp
);
1945 hc
= bgp
->rfapi_cfg
;
1947 if (argv
[3]->arg
[0] == 'b') {
1948 if (((argc
> 5) && hc
->routemap_export_bgp_name
1949 && strmatch(argv
[5]->text
, hc
->routemap_export_bgp_name
))
1952 free(hc
->routemap_export_bgp_name
);
1953 route_map_counter_decrement(hc
->routemap_export_bgp
);
1954 hc
->routemap_export_bgp_name
= NULL
;
1955 hc
->routemap_export_bgp
= NULL
;
1956 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
1957 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
1960 if (((argc
> 5) && hc
->routemap_export_zebra_name
1961 && strmatch(argv
[5]->text
, hc
->routemap_export_zebra_name
))
1964 free(hc
->routemap_export_zebra_name
);
1965 route_map_counter_decrement(hc
->routemap_export_zebra
);
1966 hc
->routemap_export_zebra_name
= NULL
;
1967 hc
->routemap_export_zebra
= NULL
;
1968 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
1969 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
1975 DEFUN (vnc_nve_export_routemap
,
1976 vnc_nve_export_routemap_cmd
,
1977 "vnc export <bgp|zebra> route-map NAME",
1979 "Export to other protocols\n"
1981 "Export to Zebra (experimental)\n"
1982 "Route-map for filtering exported routes\n" "Route map name\n")
1984 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1985 struct rfapi_cfg
*hc
;
1987 VNC_VTY_CONFIG_CHECK(bgp
);
1988 hc
= bgp
->rfapi_cfg
;
1990 if (argv
[2]->arg
[0] == 'b') {
1991 if (hc
->routemap_export_bgp_name
)
1992 free(hc
->routemap_export_bgp_name
);
1993 route_map_counter_decrement(hc
->routemap_export_bgp
);
1994 hc
->routemap_export_bgp_name
= strdup(argv
[4]->arg
);
1995 hc
->routemap_export_bgp
=
1996 route_map_lookup_by_name(argv
[4]->arg
);
1997 route_map_counter_increment(hc
->routemap_export_bgp
);
1998 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
1999 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
2001 if (hc
->routemap_export_zebra_name
)
2002 free(hc
->routemap_export_zebra_name
);
2003 route_map_counter_decrement(hc
->routemap_export_zebra
);
2004 hc
->routemap_export_zebra_name
= strdup(argv
[4]->arg
);
2005 hc
->routemap_export_zebra
=
2006 route_map_lookup_by_name(argv
[4]->arg
);
2007 route_map_counter_increment(hc
->routemap_export_zebra
);
2008 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
2009 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
2016 * respond to changes in the global prefix list configuration
2018 void vnc_prefix_list_update(struct bgp
*bgp
)
2022 struct rfapi_nve_group_cfg
*rfg
;
2023 struct rfapi_cfg
*hc
;
2027 vnc_zlog_debug_verbose("%s: No BGP process is configured",
2032 if (!(hc
= bgp
->rfapi_cfg
)) {
2033 vnc_zlog_debug_verbose("%s: rfapi not configured", __func__
);
2037 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
2039 * Loop over nve groups
2041 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->nve_groups_sequential
,
2044 if (rfg
->plist_export_bgp_name
[afi
]) {
2045 rfg
->plist_export_bgp
[afi
] = prefix_list_lookup(
2046 afi
, rfg
->plist_export_bgp_name
[afi
]);
2048 if (rfg
->plist_export_zebra_name
[afi
]) {
2049 rfg
->plist_export_zebra
2050 [afi
] = prefix_list_lookup(
2051 afi
, rfg
->plist_export_zebra_name
[afi
]);
2053 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2054 if (rfg
->plist_redist_name
[i
][afi
]) {
2056 [i
][afi
] = prefix_list_lookup(
2058 rfg
->plist_redist_name
[i
][afi
]);
2062 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, afi
);
2063 /* TBD vnc_zebra_reexport_group_afi(bgp, rfg, afi); */
2069 if (hc
->plist_export_bgp_name
[afi
]) {
2070 hc
->plist_export_bgp
[afi
] = prefix_list_lookup(
2071 afi
, hc
->plist_export_bgp_name
[afi
]);
2073 if (hc
->plist_export_zebra_name
[afi
]) {
2074 hc
->plist_export_zebra
[afi
] = prefix_list_lookup(
2075 afi
, hc
->plist_export_zebra_name
[afi
]);
2078 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2079 if (hc
->plist_redist_name
[i
][afi
]) {
2080 hc
->plist_redist
[i
][afi
] = prefix_list_lookup(
2081 afi
, hc
->plist_redist_name
[i
][afi
]);
2086 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
2087 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
2089 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
2090 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
2092 vnc_redistribute_prechange(bgp
);
2093 vnc_redistribute_postchange(bgp
);
2097 * respond to changes in the global route map configuration
2099 void vnc_routemap_update(struct bgp
*bgp
, const char *unused
)
2102 struct rfapi_nve_group_cfg
*rfg
;
2103 struct rfapi_cfg
*hc
;
2105 struct route_map
*old
= NULL
;
2107 vnc_zlog_debug_verbose("%s(arg=%s)", __func__
, unused
);
2110 vnc_zlog_debug_verbose("%s: No BGP process is configured",
2115 if (!(hc
= bgp
->rfapi_cfg
)) {
2116 vnc_zlog_debug_verbose("%s: rfapi not configured", __func__
);
2121 * Loop over nve groups
2123 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->nve_groups_sequential
, n
,
2126 if (rfg
->routemap_export_bgp_name
) {
2127 old
= rfg
->routemap_export_bgp
;
2128 rfg
->routemap_export_bgp
= route_map_lookup_by_name(
2129 rfg
->routemap_export_bgp_name
);
2130 /* old is NULL. i.e Route map creation event.
2131 * So update applied_counter.
2132 * If Old is not NULL, i.e It may be routemap
2133 * updation or deletion.
2134 * So no need to update the counter.
2137 route_map_counter_increment(
2138 rfg
->routemap_export_bgp
);
2140 if (rfg
->routemap_export_zebra_name
) {
2141 old
= rfg
->routemap_export_bgp
;
2142 rfg
->routemap_export_bgp
= route_map_lookup_by_name(
2143 rfg
->routemap_export_zebra_name
);
2145 route_map_counter_increment(
2146 rfg
->routemap_export_bgp
);
2148 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2149 if (rfg
->routemap_redist_name
[i
]) {
2150 old
= rfg
->routemap_redist
[i
];
2151 rfg
->routemap_redist
[i
] =
2152 route_map_lookup_by_name(
2153 rfg
->routemap_redist_name
[i
]);
2155 route_map_counter_increment(
2156 rfg
->routemap_redist
[i
]);
2160 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP
);
2161 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
2162 /* TBD vnc_zebra_reexport_group_afi(bgp, rfg, afi); */
2168 if (hc
->routemap_export_bgp_name
) {
2169 old
= hc
->routemap_export_bgp
;
2170 hc
->routemap_export_bgp
=
2171 route_map_lookup_by_name(hc
->routemap_export_bgp_name
);
2173 route_map_counter_increment(hc
->routemap_export_bgp
);
2175 if (hc
->routemap_export_zebra_name
) {
2176 old
= hc
->routemap_export_bgp
;
2177 hc
->routemap_export_bgp
= route_map_lookup_by_name(
2178 hc
->routemap_export_zebra_name
);
2180 route_map_counter_increment(hc
->routemap_export_bgp
);
2182 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2183 if (hc
->routemap_redist_name
[i
]) {
2184 old
= hc
->routemap_redist
[i
];
2185 hc
->routemap_redist
[i
] = route_map_lookup_by_name(
2186 hc
->routemap_redist_name
[i
]);
2188 route_map_counter_increment(
2189 hc
->routemap_redist
[i
]);
2193 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
2194 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
2196 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
2197 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
2199 vnc_redistribute_prechange(bgp
);
2200 vnc_redistribute_postchange(bgp
);
2202 vnc_zlog_debug_verbose("%s done", __func__
);
2205 /*-------------------------------------------------------------------------
2207 *-----------------------------------------------------------------------*/
2210 DEFUN_NOSH (vnc_nve_group
,
2212 "vnc nve-group NAME",
2213 VNC_CONFIG_STR
"Configure a NVE group\n" "Group name\n")
2215 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2216 struct rfapi_nve_group_cfg
*rfg
;
2217 struct listnode
*node
, *nnode
;
2218 struct rfapi_rfg_name
*rfgn
;
2220 VNC_VTY_CONFIG_CHECK(bgp
);
2222 /* Search for name */
2223 rfg
= bgp_rfapi_cfg_match_byname(bgp
, argv
[2]->arg
,
2224 RFAPI_GROUP_CFG_NVE
);
2227 rfg
= rfapi_group_new(bgp
, RFAPI_GROUP_CFG_NVE
, argv
[2]->arg
);
2229 /* Error out of memory */
2230 vty_out(vty
, "Can't allocate memory for NVE group\n");
2231 return CMD_WARNING_CONFIG_FAILED
;
2234 /* Copy defaults from struct rfapi_cfg */
2235 rfg
->rd
= bgp
->rfapi_cfg
->default_rd
;
2236 if (bgp
->rfapi_cfg
->flags
& BGP_VNC_CONFIG_L2RD
) {
2237 rfg
->l2rd
= bgp
->rfapi_cfg
->default_l2rd
;
2238 rfg
->flags
|= RFAPI_RFG_L2RD
;
2240 rfg
->rd
= bgp
->rfapi_cfg
->default_rd
;
2241 rfg
->response_lifetime
=
2242 bgp
->rfapi_cfg
->default_response_lifetime
;
2244 if (bgp
->rfapi_cfg
->default_rt_export_list
) {
2245 rfg
->rt_export_list
= ecommunity_dup(
2246 bgp
->rfapi_cfg
->default_rt_export_list
);
2249 if (bgp
->rfapi_cfg
->default_rt_import_list
) {
2250 rfg
->rt_import_list
= ecommunity_dup(
2251 bgp
->rfapi_cfg
->default_rt_import_list
);
2252 rfg
->rfapi_import_table
= rfapiImportTableRefAdd(
2253 bgp
, rfg
->rt_import_list
, rfg
);
2257 * If a redist nve group was named but the group was not
2259 * make the linkage now
2261 if (!bgp
->rfapi_cfg
->rfg_redist
) {
2262 if (bgp
->rfapi_cfg
->rfg_redist_name
2263 && !strcmp(bgp
->rfapi_cfg
->rfg_redist_name
,
2266 vnc_redistribute_prechange(bgp
);
2267 bgp
->rfapi_cfg
->rfg_redist
= rfg
;
2268 vnc_redistribute_postchange(bgp
);
2273 * Same treatment for bgp-direct export group
2275 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
,
2276 node
, nnode
, rfgn
)) {
2278 if (!strcmp(rfgn
->name
, rfg
->name
)) {
2280 vnc_direct_bgp_add_group(bgp
, rfg
);
2286 * Same treatment for zebra export group
2288 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2291 vnc_zlog_debug_verbose(
2292 "%s: ezport zebra: checking if \"%s\" == \"%s\"",
2293 __func__
, rfgn
->name
, rfg
->name
);
2294 if (!strcmp(rfgn
->name
, rfg
->name
)) {
2296 vnc_zebra_add_group(bgp
, rfg
);
2303 * XXX subsequent calls will need to make sure this item is still
2304 * in the linked list and has the same name
2306 VTY_PUSH_CONTEXT_SUB(BGP_VNC_NVE_GROUP_NODE
, rfg
);
2311 static void bgp_rfapi_delete_nve_group(struct vty
*vty
, /* NULL = no output */
2313 struct rfapi_nve_group_cfg
*rfg
)
2315 struct list
*orphaned_nves
= NULL
;
2316 struct listnode
*node
, *nnode
;
2319 * If there are currently-open NVEs that belong to this group,
2320 * zero out their references to this group structure.
2323 struct rfapi_descriptor
*rfd
;
2324 orphaned_nves
= list_new();
2325 while ((rfd
= listnode_head(rfg
->nves
))) {
2327 listnode_delete(rfg
->nves
, rfd
);
2328 listnode_add(orphaned_nves
, rfd
);
2330 list_delete(&rfg
->nves
);
2335 if (rfg
->rfapi_import_table
)
2336 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2337 if (rfg
->rt_import_list
)
2338 ecommunity_free(&rfg
->rt_import_list
);
2339 if (rfg
->rt_export_list
)
2340 ecommunity_free(&rfg
->rt_export_list
);
2343 rfg
->vn_node
->info
= NULL
;
2344 agg_unlock_node(rfg
->vn_node
); /* frees */
2347 rfg
->un_node
->info
= NULL
;
2348 agg_unlock_node(rfg
->un_node
); /* frees */
2351 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, rfg
->rfp_cfg
);
2352 listnode_delete(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
);
2355 XFREE(MTYPE_RFAPI_GROUP_CFG
, rfg
);
2358 * Attempt to reassign the orphaned nves to a new group. If
2359 * a NVE can not be reassigned, its rfd->rfg will remain NULL
2360 * and it will become a zombie until released by rfapi_close().
2362 if (orphaned_nves
) {
2363 struct rfapi_descriptor
*rfd
;
2365 for (ALL_LIST_ELEMENTS(orphaned_nves
, node
, nnode
, rfd
)) {
2367 * 1. rfapi_close() equivalent except:
2368 * a. don't free original descriptor
2369 * b. remember query list
2370 * c. remember advertised route list
2371 * 2. rfapi_open() equivalent except:
2372 * a. reuse original descriptor
2373 * 3. rfapi_register() on remembered advertised route
2375 * 4. rfapi_query on rememebred query list
2380 rc
= rfapi_reopen(rfd
, bgp
);
2383 list_delete_node(orphaned_nves
, node
);
2386 "WARNING: reassigned NVE vn=");
2387 rfapiPrintRfapiIpAddr(vty
, &rfd
->vn_addr
);
2389 vty_out(vty
, " un=");
2390 rfapiPrintRfapiIpAddr(vty
, &rfd
->un_addr
);
2392 vty_out(vty
, " to new group \"%s\"\n",
2397 for (ALL_LIST_ELEMENTS_RO(orphaned_nves
, node
, rfd
)) {
2399 vty_out(vty
, "WARNING: orphaned NVE vn=");
2400 rfapiPrintRfapiIpAddr(vty
, &rfd
->vn_addr
);
2402 vty_out(vty
, " un=");
2403 rfapiPrintRfapiIpAddr(vty
, &rfd
->un_addr
);
2407 list_delete(&orphaned_nves
);
2412 bgp_rfapi_delete_named_nve_group(struct vty
*vty
, /* NULL = no output */
2414 const char *rfg_name
, /* NULL = any */
2415 rfapi_group_cfg_type_t type
) /* _MAX = any */
2417 struct rfapi_nve_group_cfg
*rfg
= NULL
;
2418 struct listnode
*node
, *nnode
;
2419 struct rfapi_rfg_name
*rfgn
;
2421 /* Search for name */
2423 rfg
= bgp_rfapi_cfg_match_byname(bgp
, rfg_name
, type
);
2426 vty_out(vty
, "No NVE group named \"%s\"\n",
2428 return CMD_WARNING_CONFIG_FAILED
;
2433 * If this group is the redist nve group, unlink it
2435 if (rfg_name
== NULL
|| bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2436 vnc_redistribute_prechange(bgp
);
2437 bgp
->rfapi_cfg
->rfg_redist
= NULL
;
2438 vnc_redistribute_postchange(bgp
);
2443 * remove reference from bgp direct export list
2445 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2447 if (rfgn
->rfg
== rfg
) {
2449 /* remove exported routes from this group */
2450 vnc_direct_bgp_del_group(bgp
, rfg
);
2456 * remove reference from zebra export list
2458 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2460 if (rfgn
->rfg
== rfg
) {
2462 /* remove exported routes from this group */
2463 vnc_zebra_del_group(bgp
, rfg
);
2469 clear_vnc_vrf_closer(rfg
);
2470 bgp_rfapi_delete_nve_group(vty
, bgp
, rfg
);
2471 } else /* must be delete all */
2472 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->nve_groups_sequential
,
2473 node
, nnode
, rfg
)) {
2475 clear_vnc_vrf_closer(rfg
);
2476 bgp_rfapi_delete_nve_group(vty
, bgp
, rfg
);
2481 DEFUN (vnc_no_nve_group
,
2482 vnc_no_nve_group_cmd
,
2483 "no vnc nve-group NAME",
2486 "Configure a NVE group\n"
2489 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2491 return bgp_rfapi_delete_named_nve_group(vty
, bgp
, argv
[3]->arg
,
2492 RFAPI_GROUP_CFG_NVE
);
2495 DEFUN (vnc_nve_group_prefix
,
2496 vnc_nve_group_prefix_cmd
,
2497 "prefix <vn|un> <A.B.C.D/M|X:X::X:X/M>",
2498 "Specify prefixes matching NVE VN or UN interfaces\n"
2504 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2505 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2508 struct agg_table
*rt
;
2509 struct agg_node
*rn
;
2510 int is_un_prefix
= 0;
2512 /* make sure it's still in list */
2513 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2514 /* Not in list anymore */
2515 vty_out(vty
, "Current NVE group no longer exists\n");
2516 return CMD_WARNING_CONFIG_FAILED
;
2519 if (!str2prefix(argv
[2]->arg
, &p
)) {
2520 vty_out(vty
, "Malformed prefix \"%s\"\n", argv
[2]->arg
);
2521 return CMD_WARNING_CONFIG_FAILED
;
2524 afi
= family2afi(p
.family
);
2526 vty_out(vty
, "Unsupported address family\n");
2527 return CMD_WARNING_CONFIG_FAILED
;
2530 if (argv
[1]->arg
[0] == 'u') {
2531 rt
= bgp
->rfapi_cfg
->nve_groups_un
[afi
];
2534 rt
= bgp
->rfapi_cfg
->nve_groups_vn
[afi
];
2537 rn
= agg_node_get(rt
, &p
); /* NB locks node */
2540 * There is already a group with this prefix
2542 agg_unlock_node(rn
);
2543 if (rn
->info
!= rfg
) {
2545 * different group name: fail
2548 "nve group \"%s\" already has \"%s\" prefix %s\n",
2549 ((struct rfapi_nve_group_cfg
*)(rn
->info
))
2551 argv
[1]->arg
, argv
[2]->arg
);
2552 return CMD_WARNING_CONFIG_FAILED
;
2555 * same group name: it's already in the correct place
2556 * in the table, so we're done.
2558 * Implies rfg->(vn|un)_prefix is already correct.
2564 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2565 vnc_redistribute_prechange(bgp
);
2568 /* New prefix, new node */
2572 /* detach rfg from previous route table location */
2574 rfg
->un_node
->info
= NULL
;
2575 agg_unlock_node(rfg
->un_node
); /* frees */
2577 rfg
->un_node
= rn
; /* back ref */
2582 /* detach rfg from previous route table location */
2584 rfg
->vn_node
->info
= NULL
;
2585 agg_unlock_node(rfg
->vn_node
); /* frees */
2587 rfg
->vn_node
= rn
; /* back ref */
2594 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2595 vnc_redistribute_postchange(bgp
);
2601 DEFUN (vnc_nve_group_rt_import
,
2602 vnc_nve_group_rt_import_cmd
,
2603 "rt import RTLIST...",
2604 "Specify route targets\n"
2606 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2608 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2609 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2611 struct listnode
*node
;
2612 struct rfapi_rfg_name
*rfgn
;
2613 int is_export_bgp
= 0;
2614 int is_export_zebra
= 0;
2616 /* make sure it's still in list */
2617 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2618 /* Not in list anymore */
2619 vty_out(vty
, "Current NVE group no longer exists\n");
2620 return CMD_WARNING_CONFIG_FAILED
;
2623 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
2624 if (rc
!= CMD_SUCCESS
)
2627 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2630 if (rfgn
->rfg
== rfg
) {
2637 vnc_direct_bgp_del_group(bgp
, rfg
);
2639 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2642 if (rfgn
->rfg
== rfg
) {
2643 is_export_zebra
= 1;
2648 if (is_export_zebra
)
2649 vnc_zebra_del_group(bgp
, rfg
);
2652 * stop referencing old import table, now reference new one
2654 if (rfg
->rfapi_import_table
)
2655 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2656 rfg
->rfapi_import_table
=
2657 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
2660 vnc_direct_bgp_add_group(bgp
, rfg
);
2662 if (is_export_zebra
)
2663 vnc_zebra_add_group(bgp
, rfg
);
2668 DEFUN (vnc_nve_group_rt_export
,
2669 vnc_nve_group_rt_export_cmd
,
2670 "rt export RTLIST...",
2671 "Specify route targets\n"
2673 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2675 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2676 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2679 /* make sure it's still in list */
2680 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2681 /* Not in list anymore */
2682 vty_out(vty
, "Current NVE group no longer exists\n");
2683 return CMD_WARNING_CONFIG_FAILED
;
2686 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2687 vnc_redistribute_prechange(bgp
);
2690 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
2692 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2693 vnc_redistribute_postchange(bgp
);
2699 DEFUN (vnc_nve_group_rt_both
,
2700 vnc_nve_group_rt_both_cmd
,
2701 "rt both RTLIST...",
2702 "Specify route targets\n"
2703 "Export+import filters\n"
2704 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2706 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2707 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2709 int is_export_bgp
= 0;
2710 int is_export_zebra
= 0;
2711 struct listnode
*node
;
2712 struct rfapi_rfg_name
*rfgn
;
2714 /* make sure it's still in list */
2715 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2716 /* Not in list anymore */
2717 vty_out(vty
, "Current NVE group no longer exists\n");
2718 return CMD_WARNING_CONFIG_FAILED
;
2721 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
2722 if (rc
!= CMD_SUCCESS
)
2725 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2728 if (rfgn
->rfg
== rfg
) {
2735 vnc_direct_bgp_del_group(bgp
, rfg
);
2737 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2740 if (rfgn
->rfg
== rfg
) {
2741 is_export_zebra
= 1;
2746 if (is_export_zebra
) {
2747 vnc_zlog_debug_verbose("%s: is_export_zebra", __func__
);
2748 vnc_zebra_del_group(bgp
, rfg
);
2752 * stop referencing old import table, now reference new one
2754 if (rfg
->rfapi_import_table
)
2755 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2756 rfg
->rfapi_import_table
=
2757 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
2760 vnc_direct_bgp_add_group(bgp
, rfg
);
2762 if (is_export_zebra
)
2763 vnc_zebra_add_group(bgp
, rfg
);
2765 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2766 vnc_redistribute_prechange(bgp
);
2769 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
2771 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2772 vnc_redistribute_postchange(bgp
);
2778 DEFUN (vnc_nve_group_l2rd
,
2779 vnc_nve_group_l2rd_cmd
,
2780 "l2rd <(1-255)|auto-vn>",
2781 "Specify default Local Nve ID value to use in RD for L2 routes\n"
2782 "Fixed value 1-255\n"
2783 "use the low-order octet of the NVE's VN address\n")
2785 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2786 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2788 /* make sure it's still in list */
2789 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2790 /* Not in list anymore */
2791 vty_out(vty
, "Current NVE group no longer exists\n");
2792 return CMD_WARNING_CONFIG_FAILED
;
2795 if (strmatch(argv
[1]->text
, "auto:vn")) {
2799 unsigned long value_l
= strtoul(argv
[1]->arg
, &end
, 10);
2800 uint8_t value
= value_l
& 0xff;
2802 if (!argv
[1]->arg
[0] || *end
) {
2803 vty_out(vty
, "%% Malformed l2 nve ID \"%s\"\n",
2805 return CMD_WARNING_CONFIG_FAILED
;
2807 if ((value_l
< 1) || (value_l
> 0xff)) {
2809 "%% Malformed l2 nve id (must be greater than 0 and less than %u\n",
2811 return CMD_WARNING_CONFIG_FAILED
;
2816 rfg
->flags
|= RFAPI_RFG_L2RD
;
2821 DEFUN (vnc_nve_group_no_l2rd
,
2822 vnc_nve_group_no_l2rd_cmd
,
2825 "Specify default Local Nve ID value to use in RD for L2 routes\n")
2827 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2828 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2830 /* make sure it's still in list */
2831 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2832 /* Not in list anymore */
2833 vty_out(vty
, "Current NVE group no longer exists\n");
2834 return CMD_WARNING_CONFIG_FAILED
;
2838 rfg
->flags
&= ~RFAPI_RFG_L2RD
;
2843 DEFUN (vnc_nve_group_rd
,
2844 vnc_nve_group_rd_cmd
,
2845 "rd ASN:NN_OR_IP-ADDRESS:NN",
2846 "Specify route distinguisher\n"
2847 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:vn:<number> )\n")
2849 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2851 struct prefix_rd prd
;
2852 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2854 /* make sure it's still in list */
2855 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2856 /* Not in list anymore */
2857 vty_out(vty
, "Current NVE group no longer exists\n");
2858 return CMD_WARNING_CONFIG_FAILED
;
2861 if (!strncmp(argv
[1]->arg
, "auto:vn:", 8)) {
2863 * use AF_UNIX to designate automatically-assigned RD
2864 * auto:vn:nn where nn is a 2-octet quantity
2867 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
2868 uint16_t value
= value32
& 0xffff;
2870 if (!argv
[1]->arg
[8] || *end
) {
2871 vty_out(vty
, "%% Malformed rd\n");
2872 return CMD_WARNING_CONFIG_FAILED
;
2874 if (value32
> 0xffff) {
2875 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
2877 return CMD_WARNING_CONFIG_FAILED
;
2880 memset(&prd
, 0, sizeof(prd
));
2881 prd
.family
= AF_UNIX
;
2883 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
2884 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
2885 prd
.val
[6] = (value
>> 8) & 0x0ff;
2886 prd
.val
[7] = value
& 0x0ff;
2890 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
2892 vty_out(vty
, "%% Malformed rd\n");
2893 return CMD_WARNING_CONFIG_FAILED
;
2897 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2898 vnc_redistribute_prechange(bgp
);
2903 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2904 vnc_redistribute_postchange(bgp
);
2909 DEFUN (vnc_nve_group_responselifetime
,
2910 vnc_nve_group_responselifetime_cmd
,
2911 "response-lifetime <LIFETIME|infinite>",
2912 "Specify response lifetime\n"
2913 "Response lifetime in seconds\n" "Infinite response lifetime\n")
2915 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2916 unsigned int rspint
;
2917 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2918 struct rfapi_descriptor
*rfd
;
2919 struct listnode
*hdnode
;
2921 /* make sure it's still in list */
2922 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2923 /* Not in list anymore */
2924 vty_out(vty
, "Current NVE group no longer exists\n");
2925 return CMD_WARNING_CONFIG_FAILED
;
2928 if (strmatch(argv
[1]->text
, "infinite")) {
2929 rspint
= RFAPI_INFINITE_LIFETIME
;
2931 rspint
= strtoul(argv
[1]->arg
, NULL
, 10);
2934 rfg
->response_lifetime
= rspint
;
2935 rfg
->flags
|= RFAPI_RFG_RESPONSE_LIFETIME
;
2937 for (ALL_LIST_ELEMENTS_RO(rfg
->nves
, hdnode
, rfd
))
2938 rfd
->response_lifetime
= rspint
;
2943 * Sigh. This command, like exit-address-family, is a hack to deal
2944 * with the lack of rigorous level control in the command handler.
2945 * TBD fix command handler.
2947 DEFUN_NOSH (exit_vnc
,
2950 "Exit VNC configuration mode\n")
2952 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
2953 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
2954 || vty
->node
== BGP_VNC_L2_GROUP_NODE
) {
2956 vty
->node
= BGP_NODE
;
2961 static struct cmd_node bgp_vnc_defaults_node
= {
2962 .name
= "bgp vnc defaults",
2963 .node
= BGP_VNC_DEFAULTS_NODE
,
2964 .parent_node
= BGP_NODE
,
2965 .prompt
= "%s(config-router-vnc-defaults)# ",
2968 static struct cmd_node bgp_vnc_nve_group_node
= {
2969 .name
= "bgp vnc nve",
2970 .node
= BGP_VNC_NVE_GROUP_NODE
,
2971 .parent_node
= BGP_NODE
,
2972 .prompt
= "%s(config-router-vnc-nve-group)# ",
2975 /*-------------------------------------------------------------------------
2977 * Note there are two types of NVEs, one for VPNs one for RFP NVEs
2978 *-----------------------------------------------------------------------*/
2980 DEFUN_NOSH (vnc_vrf_policy
,
2983 "Configure a VRF policy group\n"
2986 struct rfapi_nve_group_cfg
*rfg
;
2987 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2989 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_VRF
) {
2991 "Can't configure vrf-policy within a BGP VRF instance\n");
2992 return CMD_WARNING_CONFIG_FAILED
;
2995 /* Search for name */
2996 rfg
= bgp_rfapi_cfg_match_byname(bgp
, argv
[1]->arg
,
2997 RFAPI_GROUP_CFG_VRF
);
3000 rfg
= rfapi_group_new(bgp
, RFAPI_GROUP_CFG_VRF
, argv
[1]->arg
);
3002 /* Error out of memory */
3003 vty_out(vty
, "Can't allocate memory for NVE group\n");
3004 return CMD_WARNING_CONFIG_FAILED
;
3008 * XXX subsequent calls will need to make sure this item is still
3009 * in the linked list and has the same name
3011 VTY_PUSH_CONTEXT_SUB(BGP_VRF_POLICY_NODE
, rfg
);
3016 DEFUN (vnc_no_vrf_policy
,
3017 vnc_no_vrf_policy_cmd
,
3018 "no vrf-policy NAME",
3020 "Remove a VRF policy group\n"
3023 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3025 /* silently return */
3026 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_VRF
)
3029 return bgp_rfapi_delete_named_nve_group(vty
, bgp
, argv
[2]->arg
,
3030 RFAPI_GROUP_CFG_VRF
);
3033 DEFUN (vnc_vrf_policy_label
,
3034 vnc_vrf_policy_label_cmd
,
3035 "label (0-1048575)",
3036 "Default label value for VRF\n"
3037 "Label Value <0-1048575>\n")
3039 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3042 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3044 /* make sure it's still in list */
3045 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3046 /* Not in list anymore */
3047 vty_out(vty
, "Current NVE group no longer exists\n");
3048 return CMD_WARNING_CONFIG_FAILED
;
3051 label
= strtoul(argv
[1]->arg
, NULL
, 10);
3053 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3054 vnc_redistribute_prechange(bgp
);
3059 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3060 vnc_redistribute_postchange(bgp
);
3065 DEFUN (vnc_vrf_policy_no_label
,
3066 vnc_vrf_policy_no_label_cmd
,
3069 "Remove VRF default label\n")
3071 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3072 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3074 /* make sure it's still in list */
3075 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3076 /* Not in list anymore */
3077 vty_out(vty
, "Current VRF group no longer exists\n");
3078 return CMD_WARNING_CONFIG_FAILED
;
3081 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3082 vnc_redistribute_prechange(bgp
);
3085 rfg
->label
= MPLS_LABEL_NONE
;
3087 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3088 vnc_redistribute_postchange(bgp
);
3093 DEFUN (vnc_vrf_policy_nexthop
,
3094 vnc_vrf_policy_nexthop_cmd
,
3095 "nexthop <A.B.C.D|X:X::X:X|self>",
3096 "Specify next hop to use for VRF advertised prefixes\n"
3099 "Use configured router-id (default)\n")
3101 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3104 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3106 /* make sure it's still in list */
3107 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3108 /* Not in list anymore */
3109 vty_out(vty
, "Current VRF no longer exists\n");
3110 return CMD_WARNING_CONFIG_FAILED
;
3113 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3114 vnc_redistribute_prechange(bgp
);
3117 if (!str2prefix(argv
[1]->arg
, &p
) && p
.family
) {
3118 // vty_out (vty, "Nexthop set to self\n");
3119 SET_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
);
3120 memset(&rfg
->vn_prefix
, 0, sizeof(struct prefix
));
3122 UNSET_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
);
3127 /* TBD handle router-id/ nexthop changes when have advertised prefixes
3130 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3131 vnc_redistribute_postchange(bgp
);
3137 /* The RT code should be refactored/simplified with above... */
3138 DEFUN (vnc_vrf_policy_rt_import
,
3139 vnc_vrf_policy_rt_import_cmd
,
3140 "rt import RTLIST...",
3141 "Specify route targets\n"
3143 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3145 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3146 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3148 struct listnode
*node
;
3149 struct rfapi_rfg_name
*rfgn
;
3150 int is_export_bgp
= 0;
3151 int is_export_zebra
= 0;
3153 /* make sure it's still in list */
3154 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3155 /* Not in list anymore */
3156 vty_out(vty
, "Current NVE group no longer exists\n");
3157 return CMD_WARNING_CONFIG_FAILED
;
3160 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
3161 if (rc
!= CMD_SUCCESS
)
3164 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
3167 if (rfgn
->rfg
== rfg
) {
3174 vnc_direct_bgp_del_group(bgp
, rfg
);
3176 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
3179 if (rfgn
->rfg
== rfg
) {
3180 is_export_zebra
= 1;
3185 if (is_export_zebra
)
3186 vnc_zebra_del_group(bgp
, rfg
);
3189 * stop referencing old import table, now reference new one
3191 if (rfg
->rfapi_import_table
)
3192 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
3193 rfg
->rfapi_import_table
=
3194 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
3197 vnc_direct_bgp_add_group(bgp
, rfg
);
3199 if (is_export_zebra
)
3200 vnc_zebra_add_group(bgp
, rfg
);
3205 DEFUN (vnc_vrf_policy_rt_export
,
3206 vnc_vrf_policy_rt_export_cmd
,
3207 "rt export RTLIST...",
3208 "Specify route targets\n"
3210 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3212 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3213 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3216 /* make sure it's still in list */
3217 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3218 /* Not in list anymore */
3219 vty_out(vty
, "Current NVE group no longer exists\n");
3220 return CMD_WARNING_CONFIG_FAILED
;
3223 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3224 vnc_redistribute_prechange(bgp
);
3227 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
3229 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3230 vnc_redistribute_postchange(bgp
);
3236 DEFUN (vnc_vrf_policy_rt_both
,
3237 vnc_vrf_policy_rt_both_cmd
,
3238 "rt both RTLIST...",
3239 "Specify route targets\n"
3240 "Export+import filters\n"
3241 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3243 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3244 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3246 int is_export_bgp
= 0;
3247 int is_export_zebra
= 0;
3248 struct listnode
*node
;
3249 struct rfapi_rfg_name
*rfgn
;
3251 /* make sure it's still in list */
3252 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3253 /* Not in list anymore */
3254 vty_out(vty
, "Current NVE group no longer exists\n");
3255 return CMD_WARNING_CONFIG_FAILED
;
3258 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
3259 if (rc
!= CMD_SUCCESS
)
3262 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
3265 if (rfgn
->rfg
== rfg
) {
3272 vnc_direct_bgp_del_group(bgp
, rfg
);
3274 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
3277 if (rfgn
->rfg
== rfg
) {
3278 is_export_zebra
= 1;
3283 if (is_export_zebra
) {
3284 vnc_zlog_debug_verbose("%s: is_export_zebra", __func__
);
3285 vnc_zebra_del_group(bgp
, rfg
);
3289 * stop referencing old import table, now reference new one
3291 if (rfg
->rfapi_import_table
)
3292 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
3293 rfg
->rfapi_import_table
=
3294 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
3297 vnc_direct_bgp_add_group(bgp
, rfg
);
3299 if (is_export_zebra
)
3300 vnc_zebra_add_group(bgp
, rfg
);
3302 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3303 vnc_redistribute_prechange(bgp
);
3306 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
3308 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3309 vnc_redistribute_postchange(bgp
);
3315 DEFUN (vnc_vrf_policy_rd
,
3316 vnc_vrf_policy_rd_cmd
,
3317 "rd ASN:NN_OR_IP-ADDRESS:NN",
3318 "Specify default VRF route distinguisher\n"
3319 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:nh:<number> )\n")
3322 struct prefix_rd prd
;
3323 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3324 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3326 /* make sure it's still in list */
3327 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3328 /* Not in list anymore */
3329 vty_out(vty
, "Current NVE group no longer exists\n");
3330 return CMD_WARNING_CONFIG_FAILED
;
3333 if (!strncmp(argv
[1]->arg
, "auto:nh:", 8)) {
3335 * use AF_UNIX to designate automatically-assigned RD
3336 * auto:vn:nn where nn is a 2-octet quantity
3339 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
3340 uint16_t value
= value32
& 0xffff;
3342 if (!*(argv
[1]->arg
+ 5) || *end
) {
3343 vty_out(vty
, "%% Malformed rd\n");
3344 return CMD_WARNING_CONFIG_FAILED
;
3346 if (value32
> 0xffff) {
3347 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
3349 return CMD_WARNING_CONFIG_FAILED
;
3352 memset(&prd
, 0, sizeof(prd
));
3353 prd
.family
= AF_UNIX
;
3355 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
3356 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
3357 prd
.val
[6] = (value
>> 8) & 0x0ff;
3358 prd
.val
[7] = value
& 0x0ff;
3362 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
3364 vty_out(vty
, "%% Malformed rd\n");
3365 return CMD_WARNING_CONFIG_FAILED
;
3369 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3370 vnc_redistribute_prechange(bgp
);
3375 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3376 vnc_redistribute_postchange(bgp
);
3381 DEFUN_NOSH (exit_vrf_policy
,
3382 exit_vrf_policy_cmd
,
3384 "Exit VRF policy configuration mode\n")
3386 if (vty
->node
== BGP_VRF_POLICY_NODE
) {
3387 vty
->node
= BGP_NODE
;
3392 static struct cmd_node bgp_vrf_policy_node
= {
3393 .name
= "bgp vrf policy",
3394 .node
= BGP_VRF_POLICY_NODE
,
3395 .parent_node
= BGP_NODE
,
3396 .prompt
= "%s(config-router-vrf-policy)# ",
3399 /*-------------------------------------------------------------------------
3401 *-----------------------------------------------------------------------*/
3404 DEFUN_NOSH (vnc_l2_group
,
3406 "vnc l2-group NAME",
3407 VNC_CONFIG_STR
"Configure a L2 group\n" "Group name\n")
3409 struct rfapi_l2_group_cfg
*rfg
;
3410 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3411 VNC_VTY_CONFIG_CHECK(bgp
);
3413 /* Search for name */
3414 rfg
= rfapi_l2_group_lookup_byname(bgp
, argv
[2]->arg
);
3417 rfg
= rfapi_l2_group_new();
3419 /* Error out of memory */
3420 vty_out(vty
, "Can't allocate memory for L2 group\n");
3421 return CMD_WARNING_CONFIG_FAILED
;
3423 rfg
->name
= strdup(argv
[2]->arg
);
3424 /* add to tail of list */
3425 listnode_add(bgp
->rfapi_cfg
->l2_groups
, rfg
);
3429 * XXX subsequent calls will need to make sure this item is still
3430 * in the linked list and has the same name
3432 VTY_PUSH_CONTEXT_SUB(BGP_VNC_L2_GROUP_NODE
, rfg
);
3436 static void bgp_rfapi_delete_l2_group(struct vty
*vty
, /* NULL = no output */
3438 struct rfapi_l2_group_cfg
*rfg
)
3442 if (rfg
->rt_import_list
)
3443 ecommunity_free(&rfg
->rt_import_list
);
3444 if (rfg
->rt_export_list
)
3445 ecommunity_free(&rfg
->rt_export_list
);
3447 list_delete(&rfg
->labels
);
3448 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, rfg
->rfp_cfg
);
3449 listnode_delete(bgp
->rfapi_cfg
->l2_groups
, rfg
);
3451 rfapi_l2_group_del(rfg
);
3455 bgp_rfapi_delete_named_l2_group(struct vty
*vty
, /* NULL = no output */
3457 const char *rfg_name
) /* NULL = any */
3459 struct rfapi_l2_group_cfg
*rfg
= NULL
;
3460 struct listnode
*node
, *nnode
;
3462 /* Search for name */
3464 rfg
= rfapi_l2_group_lookup_byname(bgp
, rfg_name
);
3467 vty_out(vty
, "No L2 group named \"%s\"\n",
3469 return CMD_WARNING_CONFIG_FAILED
;
3474 bgp_rfapi_delete_l2_group(vty
, bgp
, rfg
);
3475 else /* must be delete all */
3476 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->l2_groups
, node
, nnode
,
3478 bgp_rfapi_delete_l2_group(vty
, bgp
, rfg
);
3482 DEFUN (vnc_no_l2_group
,
3483 vnc_no_l2_group_cmd
,
3484 "no vnc l2-group NAME",
3487 "Configure a L2 group\n"
3490 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3492 return bgp_rfapi_delete_named_l2_group(vty
, bgp
, argv
[3]->arg
);
3496 DEFUN (vnc_l2_group_lni
,
3497 vnc_l2_group_lni_cmd
,
3498 "logical-network-id (0-4294967295)",
3499 "Specify Logical Network ID associated with group\n"
3502 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3503 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3505 /* make sure it's still in list */
3506 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3507 /* Not in list anymore */
3508 vty_out(vty
, "Current L2 group no longer exists\n");
3509 return CMD_WARNING_CONFIG_FAILED
;
3512 rfg
->logical_net_id
= strtoul(argv
[1]->arg
, NULL
, 10);
3517 DEFUN (vnc_l2_group_labels
,
3518 vnc_l2_group_labels_cmd
,
3519 "labels (0-1048575)...",
3520 "Specify label values associated with group\n"
3521 "Space separated list of label values <0-1048575>\n")
3523 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3524 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3527 /* make sure it's still in list */
3528 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3529 /* Not in list anymore */
3530 vty_out(vty
, "Current L2 group no longer exists\n");
3531 return CMD_WARNING_CONFIG_FAILED
;
3541 for (; argc
; --argc
, ++argv
) {
3543 label
= strtoul(argv
[0]->arg
, NULL
, 10);
3544 if (!listnode_lookup(ll
, (void *)(uintptr_t)label
))
3545 listnode_add(ll
, (void *)(uintptr_t)label
);
3551 DEFUN (vnc_l2_group_no_labels
,
3552 vnc_l2_group_no_labels_cmd
,
3553 "no labels (0-1048575)...",
3555 "Specify label values associated with L2 group\n"
3556 "Space separated list of label values <0-1048575>\n")
3558 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3559 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3562 /* make sure it's still in list */
3563 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3564 /* Not in list anymore */
3565 vty_out(vty
, "Current L2 group no longer exists\n");
3566 return CMD_WARNING_CONFIG_FAILED
;
3571 vty_out(vty
, "Label no longer associated with group\n");
3572 return CMD_WARNING_CONFIG_FAILED
;
3577 for (; argc
; --argc
, ++argv
) {
3579 label
= strtoul(argv
[0]->arg
, NULL
, 10);
3580 listnode_delete(ll
, (void *)(uintptr_t)label
);
3586 DEFUN (vnc_l2_group_rt
,
3587 vnc_l2_group_rt_cmd
,
3588 "rt <both|export|import> ASN:NN_OR_IP-ADDRESS:NN",
3589 "Specify route targets\n"
3590 "Export+import filters\n"
3595 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3596 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3597 int rc
= CMD_SUCCESS
;
3601 switch (argv
[1]->arg
[0]) {
3603 do_export
= 1; /* fall through */
3611 vty_out(vty
, "Unknown option, %s\n", argv
[1]->arg
);
3612 return CMD_ERR_NO_MATCH
;
3615 /* make sure it's still in list */
3616 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3617 /* Not in list anymore */
3618 vty_out(vty
, "Current L2 group no longer exists\n");
3619 return CMD_WARNING_CONFIG_FAILED
;
3623 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
3624 &rfg
->rt_import_list
);
3625 if (rc
== CMD_SUCCESS
&& do_export
)
3626 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
3627 &rfg
->rt_export_list
);
3632 static struct cmd_node bgp_vnc_l2_group_node
= {
3633 .name
= "bgp vnc l2",
3634 .node
= BGP_VNC_L2_GROUP_NODE
,
3635 .parent_node
= BGP_NODE
,
3636 .prompt
= "%s(config-router-vnc-l2-group)# ",
3639 struct rfapi_l2_group_cfg
*
3640 bgp_rfapi_get_group_by_lni_label(struct bgp
*bgp
, uint32_t logical_net_id
,
3643 struct rfapi_l2_group_cfg
*rfg
;
3644 struct listnode
*node
;
3646 if (bgp
->rfapi_cfg
->l2_groups
== NULL
) /* not the best place for this */
3649 label
= label
& 0xfffff; /* label is 20 bits! */
3651 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->l2_groups
, node
, rfg
)) {
3652 if (rfg
->logical_net_id
== logical_net_id
) {
3653 struct listnode
*lnode
;
3655 for (ALL_LIST_ELEMENTS_RO(rfg
->labels
, lnode
, data
))
3656 if (((uint32_t)((uintptr_t)data
))
3657 == label
) { /* match! */
3665 struct list
*bgp_rfapi_get_labellist_by_lni_label(struct bgp
*bgp
,
3666 uint32_t logical_net_id
,
3669 struct rfapi_l2_group_cfg
*rfg
;
3670 rfg
= bgp_rfapi_get_group_by_lni_label(bgp
, logical_net_id
, label
);
3678 bgp_rfapi_get_ecommunity_by_lni_label(struct bgp
*bgp
, uint32_t is_import
,
3679 uint32_t logical_net_id
, uint32_t label
)
3681 struct rfapi_l2_group_cfg
*rfg
;
3682 rfg
= bgp_rfapi_get_group_by_lni_label(bgp
, logical_net_id
, label
);
3685 return rfg
->rt_import_list
;
3687 return rfg
->rt_export_list
;
3692 void bgp_rfapi_cfg_init(void)
3694 install_node(&bgp_vnc_defaults_node
);
3695 install_node(&bgp_vnc_nve_group_node
);
3696 install_node(&bgp_vrf_policy_node
);
3697 install_node(&bgp_vnc_l2_group_node
);
3698 install_default(BGP_VRF_POLICY_NODE
);
3699 install_default(BGP_VNC_DEFAULTS_NODE
);
3700 install_default(BGP_VNC_NVE_GROUP_NODE
);
3701 install_default(BGP_VNC_L2_GROUP_NODE
);
3706 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3707 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3708 install_element(BGP_NODE
, &vnc_no_nve_group_cmd
);
3709 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3710 install_element(BGP_NODE
, &vnc_no_vrf_policy_cmd
);
3711 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3712 install_element(BGP_NODE
, &vnc_no_l2_group_cmd
);
3713 install_element(BGP_NODE
, &vnc_advertise_un_method_cmd
);
3714 install_element(BGP_NODE
, &vnc_export_mode_cmd
);
3716 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_import_cmd
);
3717 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_export_cmd
);
3718 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_both_cmd
);
3719 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rd_cmd
);
3720 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_l2rd_cmd
);
3721 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_no_l2rd_cmd
);
3722 install_element(BGP_VNC_DEFAULTS_NODE
,
3723 &vnc_defaults_responselifetime_cmd
);
3724 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_cmd
);
3726 install_element(BGP_NODE
, &vnc_redistribute_protocol_cmd
);
3727 install_element(BGP_NODE
, &vnc_no_redistribute_protocol_cmd
);
3728 install_element(BGP_NODE
, &vnc_redistribute_nvegroup_cmd
);
3729 install_element(BGP_NODE
, &vnc_redistribute_no_nvegroup_cmd
);
3730 install_element(BGP_NODE
, &vnc_redistribute_lifetime_cmd
);
3731 install_element(BGP_NODE
, &vnc_redistribute_rh_roo_localadmin_cmd
);
3732 install_element(BGP_NODE
, &vnc_redistribute_mode_cmd
);
3733 install_element(BGP_NODE
, &vnc_redistribute_bgp_exterior_cmd
);
3735 install_element(BGP_NODE
, &vnc_redist_bgpdirect_no_prefixlist_cmd
);
3736 install_element(BGP_NODE
, &vnc_redist_bgpdirect_prefixlist_cmd
);
3737 install_element(BGP_NODE
, &vnc_redist_bgpdirect_no_routemap_cmd
);
3738 install_element(BGP_NODE
, &vnc_redist_bgpdirect_routemap_cmd
);
3740 install_element(BGP_VNC_NVE_GROUP_NODE
,
3741 &vnc_nve_group_redist_bgpdirect_no_prefixlist_cmd
);
3742 install_element(BGP_VNC_NVE_GROUP_NODE
,
3743 &vnc_nve_group_redist_bgpdirect_prefixlist_cmd
);
3744 install_element(BGP_VNC_NVE_GROUP_NODE
,
3745 &vnc_nve_group_redist_bgpdirect_no_routemap_cmd
);
3746 install_element(BGP_VNC_NVE_GROUP_NODE
,
3747 &vnc_nve_group_redist_bgpdirect_routemap_cmd
);
3749 install_element(BGP_NODE
, &vnc_export_nvegroup_cmd
);
3750 install_element(BGP_NODE
, &vnc_no_export_nvegroup_cmd
);
3751 install_element(BGP_NODE
, &vnc_nve_export_prefixlist_cmd
);
3752 install_element(BGP_NODE
, &vnc_nve_export_routemap_cmd
);
3753 install_element(BGP_NODE
, &vnc_nve_export_no_prefixlist_cmd
);
3754 install_element(BGP_NODE
, &vnc_nve_export_no_routemap_cmd
);
3756 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_l2rd_cmd
);
3757 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_no_l2rd_cmd
);
3758 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_prefix_cmd
);
3759 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_import_cmd
);
3760 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_export_cmd
);
3761 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_both_cmd
);
3762 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rd_cmd
);
3763 install_element(BGP_VNC_NVE_GROUP_NODE
,
3764 &vnc_nve_group_responselifetime_cmd
);
3765 install_element(BGP_VNC_NVE_GROUP_NODE
,
3766 &vnc_nve_group_export_prefixlist_cmd
);
3767 install_element(BGP_VNC_NVE_GROUP_NODE
,
3768 &vnc_nve_group_export_routemap_cmd
);
3769 install_element(BGP_VNC_NVE_GROUP_NODE
,
3770 &vnc_nve_group_export_no_prefixlist_cmd
);
3771 install_element(BGP_VNC_NVE_GROUP_NODE
,
3772 &vnc_nve_group_export_no_routemap_cmd
);
3773 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_cmd
);
3775 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_label_cmd
);
3776 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_no_label_cmd
);
3777 // Reenable to support VRF controller use case and testing
3778 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_nexthop_cmd
);
3779 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_import_cmd
);
3780 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_export_cmd
);
3781 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_both_cmd
);
3782 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rd_cmd
);
3783 install_element(BGP_VRF_POLICY_NODE
,
3784 &vnc_vrf_policy_export_prefixlist_cmd
);
3785 install_element(BGP_VRF_POLICY_NODE
,
3786 &vnc_vrf_policy_export_routemap_cmd
);
3787 install_element(BGP_VRF_POLICY_NODE
,
3788 &vnc_vrf_policy_export_no_prefixlist_cmd
);
3789 install_element(BGP_VRF_POLICY_NODE
,
3790 &vnc_vrf_policy_export_no_routemap_cmd
);
3791 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
3793 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_lni_cmd
);
3794 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_labels_cmd
);
3795 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_no_labels_cmd
);
3796 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_rt_cmd
);
3797 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_cmd
);
3800 struct rfapi_cfg
*bgp_rfapi_cfg_new(struct rfapi_rfp_cfg
*cfg
)
3802 struct rfapi_cfg
*h
;
3805 h
= XCALLOC(MTYPE_RFAPI_CFG
, sizeof(struct rfapi_cfg
));
3808 h
->nve_groups_sequential
= list_new();
3809 assert(h
->nve_groups_sequential
);
3810 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
3811 h
->nve_groups_vn
[afi
] = agg_table_init();
3812 h
->nve_groups_un
[afi
] = agg_table_init();
3814 h
->default_response_lifetime
=
3815 BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT
;
3816 h
->rfg_export_direct_bgp_l
= list_new();
3817 h
->rfg_export_zebra_l
= list_new();
3818 h
->resolve_nve_roo_local_admin
=
3819 BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT
;
3821 SET_FLAG(h
->flags
, BGP_VNC_CONFIG_FLAGS_DEFAULT
);
3824 h
->rfp_cfg
.download_type
= RFAPI_RFP_DOWNLOAD_PARTIAL
;
3825 h
->rfp_cfg
.ftd_advertisement_interval
=
3826 RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL
;
3827 h
->rfp_cfg
.holddown_factor
=
3828 RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR
;
3829 h
->rfp_cfg
.use_updated_response
= 0;
3830 h
->rfp_cfg
.use_removes
= 0;
3832 h
->rfp_cfg
.download_type
= cfg
->download_type
;
3833 h
->rfp_cfg
.ftd_advertisement_interval
=
3834 cfg
->ftd_advertisement_interval
;
3835 h
->rfp_cfg
.holddown_factor
= cfg
->holddown_factor
;
3836 h
->rfp_cfg
.use_updated_response
= cfg
->use_updated_response
;
3837 h
->rfp_cfg
.use_removes
= cfg
->use_removes
;
3838 if (cfg
->use_updated_response
)
3839 h
->flags
&= ~BGP_VNC_CONFIG_CALLBACK_DISABLE
;
3841 h
->flags
|= BGP_VNC_CONFIG_CALLBACK_DISABLE
;
3842 if (cfg
->use_removes
)
3843 h
->flags
&= ~BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE
;
3845 h
->flags
|= BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE
;
3850 void bgp_rfapi_cfg_destroy(struct bgp
*bgp
, struct rfapi_cfg
*h
)
3856 bgp_rfapi_delete_named_nve_group(NULL
, bgp
, NULL
, RFAPI_GROUP_CFG_MAX
);
3857 bgp_rfapi_delete_named_l2_group(NULL
, bgp
, NULL
);
3858 if (h
->l2_groups
!= NULL
)
3859 list_delete(&h
->l2_groups
);
3860 list_delete(&h
->nve_groups_sequential
);
3861 list_delete(&h
->rfg_export_direct_bgp_l
);
3862 list_delete(&h
->rfg_export_zebra_l
);
3863 if (h
->default_rt_export_list
)
3864 ecommunity_free(&h
->default_rt_export_list
);
3865 if (h
->default_rt_import_list
)
3866 ecommunity_free(&h
->default_rt_import_list
);
3867 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, h
->default_rfp_cfg
);
3868 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
3869 agg_table_finish(h
->nve_groups_vn
[afi
]);
3870 agg_table_finish(h
->nve_groups_un
[afi
]);
3872 XFREE(MTYPE_RFAPI_CFG
, h
);
3875 int bgp_rfapi_cfg_write(struct vty
*vty
, struct bgp
*bgp
)
3877 struct listnode
*node
, *nnode
;
3878 struct rfapi_nve_group_cfg
*rfg
;
3879 struct rfapi_cfg
*hc
= bgp
->rfapi_cfg
;
3880 struct rfapi_rfg_name
*rfgn
;
3884 if (bgp
->rfapi
== NULL
|| hc
== NULL
)
3887 vty_out(vty
, "!\n");
3888 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
, rfg
))
3889 if (rfg
->type
== RFAPI_GROUP_CFG_VRF
) {
3891 vty_out(vty
, " vrf-policy %s\n", rfg
->name
);
3892 if (rfg
->label
<= MPLS_LABEL_MAX
) {
3893 vty_out(vty
, " label %u\n", rfg
->label
);
3895 if (CHECK_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
)) {
3896 vty_out(vty
, " nexthop self\n");
3899 if (rfg
->vn_prefix
.family
) {
3901 buf
[0] = buf
[BUFSIZ
- 1] = 0;
3902 inet_ntop(rfg
->vn_prefix
.family
,
3903 &rfg
->vn_prefix
.u
.prefix
, buf
,
3905 if (!buf
[0] || buf
[BUFSIZ
- 1]) {
3906 // vty_out (vty, "nexthop
3909 vty_out(vty
, " nexthop %s\n",
3915 if (rfg
->rd
.prefixlen
) {
3916 char buf
[RD_ADDRSTRLEN
];
3918 if (AF_UNIX
== rfg
->rd
.family
) {
3922 value
= ((rfg
->rd
.val
[6] << 8)
3924 | (rfg
->rd
.val
[7] & 0x0ff);
3926 vty_out(vty
, " rd auto:nh:%d\n",
3930 vty_out(vty
, " rd %s\n",
3931 prefix_rd2str(&rfg
->rd
, buf
,
3935 if (rfg
->rt_import_list
&& rfg
->rt_export_list
3936 && ecommunity_cmp(rfg
->rt_import_list
,
3937 rfg
->rt_export_list
)) {
3938 char *b
= ecommunity_ecom2str(
3939 rfg
->rt_import_list
,
3940 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3941 ECOMMUNITY_ROUTE_TARGET
);
3942 vty_out(vty
, " rt both %s\n", b
);
3943 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3945 if (rfg
->rt_import_list
) {
3946 char *b
= ecommunity_ecom2str(
3947 rfg
->rt_import_list
,
3948 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3949 ECOMMUNITY_ROUTE_TARGET
);
3950 vty_out(vty
, " rt import %s\n", b
);
3951 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3953 if (rfg
->rt_export_list
) {
3954 char *b
= ecommunity_ecom2str(
3955 rfg
->rt_export_list
,
3956 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3957 ECOMMUNITY_ROUTE_TARGET
);
3958 vty_out(vty
, " rt export %s\n", b
);
3959 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3964 * route filtering: prefix-lists and route-maps
3966 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
3968 const char *afistr
=
3969 (afi
== AFI_IP
) ? "ipv4" : "ipv6";
3971 if (rfg
->plist_export_bgp_name
[afi
]) {
3973 " export %s%s prefix-list %s\n",
3974 (rfg
->type
== RFAPI_GROUP_CFG_VRF
3978 rfg
->plist_export_bgp_name
3981 if (rfg
->plist_export_zebra_name
[afi
]) {
3983 " export %s%s prefix-list %s\n",
3984 (rfg
->type
== RFAPI_GROUP_CFG_VRF
3988 rfg
->plist_export_zebra_name
3992 * currently we only support redist plists for
3994 * If we later add plist support for
3995 * redistributing other
3996 * protocols, we'll need to loop over protocols
3999 if (rfg
->plist_redist_name
4000 [ZEBRA_ROUTE_BGP_DIRECT
][afi
]) {
4002 " redistribute bgp-direct %s prefix-list %s\n",
4004 rfg
->plist_redist_name
4005 [ZEBRA_ROUTE_BGP_DIRECT
]
4008 if (rfg
->plist_redist_name
4009 [ZEBRA_ROUTE_BGP_DIRECT_EXT
][afi
]) {
4011 " redistribute bgp-direct-to-nve-groups %s prefix-list %s\n",
4013 rfg
->plist_redist_name
4014 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4019 if (rfg
->routemap_export_bgp_name
) {
4020 vty_out(vty
, " export %sroute-map %s\n",
4021 (rfg
->type
== RFAPI_GROUP_CFG_VRF
4024 rfg
->routemap_export_bgp_name
);
4026 if (rfg
->routemap_export_zebra_name
) {
4027 vty_out(vty
, " export %sroute-map %s\n",
4028 (rfg
->type
== RFAPI_GROUP_CFG_VRF
4031 rfg
->routemap_export_zebra_name
);
4033 if (rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]) {
4035 " redistribute bgp-direct route-map %s\n",
4036 rfg
->routemap_redist_name
4037 [ZEBRA_ROUTE_BGP_DIRECT
]);
4039 if (rfg
->routemap_redist_name
4040 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]) {
4042 " redistribute bgp-direct-to-nve-groups route-map %s\n",
4043 rfg
->routemap_redist_name
4044 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]);
4046 vty_out(vty
, " exit-vrf-policy\n");
4047 vty_out(vty
, "!\n");
4049 if (hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
) {
4050 vty_out(vty
, " vnc advertise-un-method encap-safi\n");
4054 { /* was based on listen ports */
4055 /* for now allow both old and new */
4056 if (bgp
->rfapi
->rfp_methods
.cfg_cb
)
4057 write
+= (bgp
->rfapi
->rfp_methods
.cfg_cb
)(
4058 vty
, bgp
->rfapi
->rfp
);
4061 vty_out(vty
, "!\n");
4063 if (hc
->l2_groups
) {
4064 struct rfapi_l2_group_cfg
*rfgc
= NULL
;
4065 struct listnode
*gnode
;
4066 for (ALL_LIST_ELEMENTS_RO(hc
->l2_groups
, gnode
, rfgc
)) {
4067 struct listnode
*lnode
;
4070 vty_out(vty
, " vnc l2-group %s\n", rfgc
->name
);
4071 if (rfgc
->logical_net_id
!= 0)
4073 " logical-network-id %u\n",
4074 rfgc
->logical_net_id
);
4075 if (rfgc
->labels
!= NULL
4076 && listhead(rfgc
->labels
) != NULL
) {
4077 vty_out(vty
, " labels ");
4078 for (ALL_LIST_ELEMENTS_RO(rfgc
->labels
,
4081 vty_out(vty
, "%hu ",
4089 if (rfgc
->rt_import_list
&& rfgc
->rt_export_list
4090 && ecommunity_cmp(rfgc
->rt_import_list
,
4091 rfgc
->rt_export_list
)) {
4092 char *b
= ecommunity_ecom2str(
4093 rfgc
->rt_import_list
,
4094 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4095 ECOMMUNITY_ROUTE_TARGET
);
4096 vty_out(vty
, " rt both %s\n", b
);
4097 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4099 if (rfgc
->rt_import_list
) {
4100 char *b
= ecommunity_ecom2str(
4101 rfgc
->rt_import_list
,
4102 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4103 ECOMMUNITY_ROUTE_TARGET
);
4104 vty_out(vty
, " rt import %s\n",
4106 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4108 if (rfgc
->rt_export_list
) {
4109 char *b
= ecommunity_ecom2str(
4110 rfgc
->rt_export_list
,
4111 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4112 ECOMMUNITY_ROUTE_TARGET
);
4113 vty_out(vty
, " rt export %s\n",
4115 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4118 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4119 write
+= (bgp
->rfapi
->rfp_methods
4121 vty
, bgp
->rfapi
->rfp
,
4122 RFAPI_RFP_CFG_GROUP_L2
,
4123 rfgc
->name
, rfgc
->rfp_cfg
);
4124 vty_out(vty
, " exit-vnc\n");
4125 vty_out(vty
, "!\n");
4129 if (hc
->default_rd
.prefixlen
4130 || hc
->default_response_lifetime
4131 != BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT
4132 || hc
->default_rt_import_list
|| hc
->default_rt_export_list
4133 || hc
->nve_groups_sequential
->count
) {
4137 vty_out(vty
, " vnc defaults\n");
4139 if (hc
->default_rd
.prefixlen
) {
4140 char buf
[RD_ADDRSTRLEN
];
4142 if (AF_UNIX
== hc
->default_rd
.family
) {
4145 value
= ((hc
->default_rd
.val
[6] << 8)
4147 | (hc
->default_rd
.val
[7]
4150 vty_out(vty
, " rd auto:vn:%d\n",
4154 vty_out(vty
, " rd %s\n",
4155 prefix_rd2str(&hc
->default_rd
,
4159 if (hc
->default_response_lifetime
4160 != BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT
) {
4161 vty_out(vty
, " response-lifetime ");
4162 if (hc
->default_response_lifetime
!= UINT32_MAX
)
4164 hc
->default_response_lifetime
);
4166 vty_out(vty
, "infinite");
4169 if (hc
->default_rt_import_list
4170 && hc
->default_rt_export_list
4171 && ecommunity_cmp(hc
->default_rt_import_list
,
4172 hc
->default_rt_export_list
)) {
4173 char *b
= ecommunity_ecom2str(
4174 hc
->default_rt_import_list
,
4175 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4176 ECOMMUNITY_ROUTE_TARGET
);
4177 vty_out(vty
, " rt both %s\n", b
);
4178 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4180 if (hc
->default_rt_import_list
) {
4181 char *b
= ecommunity_ecom2str(
4182 hc
->default_rt_import_list
,
4183 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4184 ECOMMUNITY_ROUTE_TARGET
);
4185 vty_out(vty
, " rt import %s\n", b
);
4186 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4188 if (hc
->default_rt_export_list
) {
4189 char *b
= ecommunity_ecom2str(
4190 hc
->default_rt_export_list
,
4191 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4192 ECOMMUNITY_ROUTE_TARGET
);
4193 vty_out(vty
, " rt export %s\n", b
);
4194 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4197 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4198 write
+= (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)(
4199 vty
, bgp
->rfapi
->rfp
,
4200 RFAPI_RFP_CFG_GROUP_DEFAULT
, NULL
,
4201 bgp
->rfapi_cfg
->default_rfp_cfg
);
4202 vty_out(vty
, " exit-vnc\n");
4203 vty_out(vty
, "!\n");
4206 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
,
4208 if (rfg
->type
== RFAPI_GROUP_CFG_NVE
) {
4210 vty_out(vty
, " vnc nve-group %s\n", rfg
->name
);
4212 if (rfg
->vn_prefix
.family
&& rfg
->vn_node
)
4213 vty_out(vty
, " prefix %s %pFX\n", "vn",
4216 if (rfg
->un_prefix
.family
&& rfg
->un_node
)
4217 vty_out(vty
, " prefix %s %pFX\n", "un",
4221 if (rfg
->rd
.prefixlen
) {
4222 char buf
[RD_ADDRSTRLEN
];
4224 if (AF_UNIX
== rfg
->rd
.family
) {
4228 value
= ((rfg
->rd
.val
[6] << 8)
4238 vty_out(vty
, " rd %s\n",
4243 if (rfg
->flags
& RFAPI_RFG_RESPONSE_LIFETIME
) {
4244 vty_out(vty
, " response-lifetime ");
4245 if (rfg
->response_lifetime
4248 rfg
->response_lifetime
);
4250 vty_out(vty
, "infinite");
4254 if (rfg
->rt_import_list
&& rfg
->rt_export_list
4255 && ecommunity_cmp(rfg
->rt_import_list
,
4256 rfg
->rt_export_list
)) {
4257 char *b
= ecommunity_ecom2str(
4258 rfg
->rt_import_list
,
4259 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4260 ECOMMUNITY_ROUTE_TARGET
);
4261 vty_out(vty
, " rt both %s\n", b
);
4262 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4264 if (rfg
->rt_import_list
) {
4265 char *b
= ecommunity_ecom2str(
4266 rfg
->rt_import_list
,
4267 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4268 ECOMMUNITY_ROUTE_TARGET
);
4269 vty_out(vty
, " rt import %s\n",
4271 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4273 if (rfg
->rt_export_list
) {
4274 char *b
= ecommunity_ecom2str(
4275 rfg
->rt_export_list
,
4276 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4277 ECOMMUNITY_ROUTE_TARGET
);
4278 vty_out(vty
, " rt export %s\n",
4280 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4285 * route filtering: prefix-lists and route-maps
4287 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4289 const char *afistr
= (afi
== AFI_IP
)
4293 if (rfg
->plist_export_bgp_name
[afi
]) {
4295 " export bgp %s prefix-list %s\n",
4297 rfg
->plist_export_bgp_name
4300 if (rfg
->plist_export_zebra_name
[afi
]) {
4302 " export zebra %s prefix-list %s\n",
4304 rfg
->plist_export_zebra_name
4308 * currently we only support redist
4309 * plists for bgp-direct.
4310 * If we later add plist support for
4311 * redistributing other
4312 * protocols, we'll need to loop over
4315 if (rfg
->plist_redist_name
4316 [ZEBRA_ROUTE_BGP_DIRECT
]
4319 " redistribute bgp-direct %s prefix-list %s\n",
4321 rfg
->plist_redist_name
4322 [ZEBRA_ROUTE_BGP_DIRECT
]
4325 if (rfg
->plist_redist_name
4326 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4329 " redistribute bgp-direct-to-nve-groups %s prefix-list %s\n",
4331 rfg
->plist_redist_name
4332 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4337 if (rfg
->routemap_export_bgp_name
) {
4339 " export bgp route-map %s\n",
4340 rfg
->routemap_export_bgp_name
);
4342 if (rfg
->routemap_export_zebra_name
) {
4344 " export zebra route-map %s\n",
4345 rfg
->routemap_export_zebra_name
);
4347 if (rfg
->routemap_redist_name
4348 [ZEBRA_ROUTE_BGP_DIRECT
]) {
4350 " redistribute bgp-direct route-map %s\n",
4351 rfg
->routemap_redist_name
4352 [ZEBRA_ROUTE_BGP_DIRECT
]);
4354 if (rfg
->routemap_redist_name
4355 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]) {
4357 " redistribute bgp-direct-to-nve-groups route-map %s\n",
4358 rfg
->routemap_redist_name
4359 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]);
4361 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4362 write
+= (bgp
->rfapi
->rfp_methods
4364 vty
, bgp
->rfapi
->rfp
,
4365 RFAPI_RFP_CFG_GROUP_NVE
,
4366 rfg
->name
, rfg
->rfp_cfg
);
4367 vty_out(vty
, " exit-vnc\n");
4368 vty_out(vty
, "!\n");
4370 } /* have listen ports */
4373 * route export to other protocols
4375 if (VNC_EXPORT_BGP_GRP_ENABLED(hc
)) {
4376 vty_out(vty
, " vnc export bgp mode group-nve\n");
4377 } else if (VNC_EXPORT_BGP_RH_ENABLED(hc
)) {
4378 vty_out(vty
, " vnc export bgp mode registering-nve\n");
4379 } else if (VNC_EXPORT_BGP_CE_ENABLED(hc
)) {
4380 vty_out(vty
, " vnc export bgp mode ce\n");
4383 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(hc
)) {
4384 vty_out(vty
, " vnc export zebra mode group-nve\n");
4385 } else if (VNC_EXPORT_ZEBRA_RH_ENABLED(hc
)) {
4386 vty_out(vty
, " vnc export zebra mode registering-nve\n");
4389 if (hc
->rfg_export_direct_bgp_l
) {
4390 for (ALL_LIST_ELEMENTS(hc
->rfg_export_direct_bgp_l
, node
, nnode
,
4393 vty_out(vty
, " vnc export bgp group-nve group %s\n",
4398 if (hc
->rfg_export_zebra_l
) {
4399 for (ALL_LIST_ELEMENTS(hc
->rfg_export_zebra_l
, node
, nnode
,
4402 vty_out(vty
, " vnc export zebra group-nve group %s\n",
4408 if (hc
->rfg_redist_name
) {
4409 vty_out(vty
, " vnc redistribute nve-group %s\n",
4410 hc
->rfg_redist_name
);
4412 if (hc
->redist_lifetime
) {
4413 vty_out(vty
, " vnc redistribute lifetime %d\n",
4414 hc
->redist_lifetime
);
4416 if (hc
->resolve_nve_roo_local_admin
4417 != BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT
) {
4420 " vnc redistribute resolve-nve roo-ec-local-admin %d\n",
4421 hc
->resolve_nve_roo_local_admin
);
4424 if (hc
->redist_mode
) /* ! default */
4428 switch (hc
->redist_mode
) {
4429 case VNC_REDIST_MODE_PLAIN
:
4432 case VNC_REDIST_MODE_RFG
:
4435 case VNC_REDIST_MODE_RESOLVE_NVE
:
4440 vty_out(vty
, " vnc redistribute mode %s\n", s
);
4445 * route filtering: prefix-lists and route-maps
4447 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4449 const char *afistr
= (afi
== AFI_IP
) ? "ipv4" : "ipv6";
4451 if (hc
->plist_export_bgp_name
[afi
]) {
4452 vty_out(vty
, " vnc export bgp %s prefix-list %s\n",
4453 afistr
, hc
->plist_export_bgp_name
[afi
]);
4455 if (hc
->plist_export_zebra_name
[afi
]) {
4456 vty_out(vty
, " vnc export zebra %s prefix-list %s\n",
4457 afistr
, hc
->plist_export_zebra_name
[afi
]);
4459 if (hc
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
]) {
4461 " vnc redistribute bgp-direct %s prefix-list %s\n",
4463 hc
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]
4468 if (hc
->routemap_export_bgp_name
) {
4469 vty_out(vty
, " vnc export bgp route-map %s\n",
4470 hc
->routemap_export_bgp_name
);
4472 if (hc
->routemap_export_zebra_name
) {
4473 vty_out(vty
, " vnc export zebra route-map %s\n",
4474 hc
->routemap_export_zebra_name
);
4476 if (hc
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]) {
4477 vty_out(vty
, " vnc redistribute bgp-direct route-map %s\n",
4478 hc
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]);
4481 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4482 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
4483 if (hc
->redist
[afi
][type
]) {
4484 if (type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
4485 && hc
->redist_bgp_exterior_view_name
) {
4487 " vnc redistribute %s %s view %s\n",
4488 ((afi
== AFI_IP
) ? "ipv4"
4490 zebra_route_string(type
),
4491 hc
->redist_bgp_exterior_view_name
);
4494 " vnc redistribute %s %s\n",
4495 ((afi
== AFI_IP
) ? "ipv4"
4497 zebra_route_string(type
));
4505 void bgp_rfapi_show_summary(struct bgp
*bgp
, struct vty
*vty
)
4507 struct rfapi_cfg
*hc
= bgp
->rfapi_cfg
;
4509 int type
, redist
= 0;
4514 vty_out(vty
, "%-39s %-19s %s\n", "VNC Advertise method:",
4515 (hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
4516 ? "Encapsulation SAFI"
4517 : "Tunnel Encap attribute"),
4518 ((hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
)
4519 == (BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
4520 & BGP_VNC_CONFIG_FLAGS_DEFAULT
)
4524 vty_out(vty
, "%-39s ", "Export from VNC:");
4526 * route export to other protocols
4528 if (VNC_EXPORT_BGP_GRP_ENABLED(hc
)) {
4530 vty_out(vty
, "ToBGP Groups={");
4531 if (hc
->rfg_export_direct_bgp_l
) {
4533 struct listnode
*node
, *nnode
;
4534 struct rfapi_rfg_name
*rfgn
;
4535 for (ALL_LIST_ELEMENTS(hc
->rfg_export_direct_bgp_l
,
4536 node
, nnode
, rfgn
)) {
4540 vty_out(vty
, "%s", rfgn
->name
);
4544 } else if (VNC_EXPORT_BGP_RH_ENABLED(hc
)) {
4546 vty_out(vty
, "ToBGP {Registering NVE}");
4547 /* note filters, route-maps not shown */
4548 } else if (VNC_EXPORT_BGP_CE_ENABLED(hc
)) {
4550 vty_out(vty
, "ToBGP {NVE connected router:%d}",
4551 hc
->resolve_nve_roo_local_admin
);
4552 /* note filters, route-maps not shown */
4555 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(hc
)) {
4557 vty_out(vty
, "%sToZebra Groups={", (redist
== 1 ? "" : " "));
4558 if (hc
->rfg_export_zebra_l
) {
4560 struct listnode
*node
, *nnode
;
4561 struct rfapi_rfg_name
*rfgn
;
4562 for (ALL_LIST_ELEMENTS(hc
->rfg_export_zebra_l
, node
,
4566 vty_out(vty
, "%s", rfgn
->name
);
4570 } else if (VNC_EXPORT_ZEBRA_RH_ENABLED(hc
)) {
4572 vty_out(vty
, "%sToZebra {Registering NVE}",
4573 (redist
== 1 ? "" : " "));
4574 /* note filters, route-maps not shown */
4576 vty_out(vty
, "%-19s %s\n", (redist
? "" : "Off"),
4577 (redist
? "" : "(default)"));
4579 /* Redistribution */
4581 vty_out(vty
, "%-39s ", "Redistribution into VNC:");
4582 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4583 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
4584 if (hc
->redist
[afi
][type
]) {
4585 vty_out(vty
, "{%s,%s} ",
4586 ((afi
== AFI_IP
) ? "ipv4" : "ipv6"),
4587 zebra_route_string(type
));
4592 vty_out(vty
, "%-19s %s\n", (redist
? "" : "Off"),
4593 (redist
? "" : "(default)"));
4595 vty_out(vty
, "%-39s %3u%-16s %s\n",
4596 "RFP Registration Hold-Down Factor:",
4597 hc
->rfp_cfg
.holddown_factor
, "%",
4598 (hc
->rfp_cfg
.holddown_factor
4599 == RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR
4602 vty_out(vty
, "%-39s %-19s %s\n", "RFP Updated responses:",
4603 (hc
->rfp_cfg
.use_updated_response
== 0 ? "Off" : "On"),
4604 (hc
->rfp_cfg
.use_updated_response
== 0 ? "(default)" : ""));
4605 vty_out(vty
, "%-39s %-19s %s\n", "RFP Removal responses:",
4606 (hc
->rfp_cfg
.use_removes
== 0 ? "Off" : "On"),
4607 (hc
->rfp_cfg
.use_removes
== 0 ? "(default)" : ""));
4608 vty_out(vty
, "%-39s %-19s %s\n", "RFP Full table download:",
4609 (hc
->rfp_cfg
.download_type
== RFAPI_RFP_DOWNLOAD_FULL
? "On"
4611 (hc
->rfp_cfg
.download_type
== RFAPI_RFP_DOWNLOAD_PARTIAL
4614 snprintf(tmp
, sizeof(tmp
), "%u seconds",
4615 hc
->rfp_cfg
.ftd_advertisement_interval
);
4616 vty_out(vty
, "%-39s %-19s %s\n", " Advertisement Interval:", tmp
,
4617 (hc
->rfp_cfg
.ftd_advertisement_interval
4618 == RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL
4621 vty_out(vty
, "%-39s %d seconds\n", "Default RFP response lifetime:",
4622 hc
->default_response_lifetime
);
4627 struct rfapi_cfg
*bgp_rfapi_get_config(struct bgp
*bgp
)
4629 struct rfapi_cfg
*hc
= NULL
;
4631 bgp
= bgp_get_default();
4633 hc
= bgp
->rfapi_cfg
;
4637 #endif /* ENABLE_BGP_VNC */