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
= bgp_clock();
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 char buf
[PREFIX_STRLEN
];
175 prefix2str(vn
, buf
, sizeof(buf
));
176 vnc_zlog_debug_verbose("%s: vn prefix: %s", __func__
, buf
);
178 prefix2str(un
, buf
, sizeof(buf
));
179 vnc_zlog_debug_verbose("%s: un prefix: %s", __func__
, buf
);
181 vnc_zlog_debug_verbose(
182 "%s: rn_vn=%p, rn_un=%p, rfg_vn=%p, rfg_un=%p",
183 __func__
, rn_vn
, rn_un
, rfg_vn
, rfg_un
);
188 if (rfg_un
== rfg_vn
) /* same group */
190 if (!rfg_un
) /* un doesn't match, return vn-matched grp */
192 if (!rfg_vn
) /* vn doesn't match, return un-matched grp */
196 * Two different nve groups match: the group configured earlier wins.
197 * For now, just walk the sequential list and pick the first one.
198 * If this approach is too slow, then store serial numbers in the
199 * nve group structures as they are defined and just compare
202 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
, rfg
)) {
203 if ((rfg
== rfg_un
) || (rfg
== rfg_vn
)) {
207 vnc_zlog_debug_verbose(
208 "%s: shouldn't happen, returning NULL when un and vn match",
210 return NULL
; /* shouldn't happen */
213 /*------------------------------------------
214 * rfapi_get_rfp_start_val
216 * Returns value passed to rfapi on rfp_start
219 * void * bgp structure
223 *------------------------------------------*/
224 void *rfapi_get_rfp_start_val(void *bgpv
)
226 struct bgp
*bgp
= bgpv
;
227 if (bgp
== NULL
|| bgp
->rfapi
== NULL
)
229 return bgp
->rfapi
->rfp
;
232 /*------------------------------------------
233 * bgp_rfapi_is_vnc_configured
235 * Returns if VNC is configured
238 * bgp NULL (=use default instance)
242 * return value: If VNC is configured for the bgpd instance
244 * EPERM Not Default instance (VNC operations not allowed)
245 * ENXIO VNC not configured
246 --------------------------------------------*/
247 int bgp_rfapi_is_vnc_configured(struct bgp
*bgp
)
250 bgp
= bgp_get_default();
252 if (bgp
&& bgp
->inst_type
!= BGP_INSTANCE_TYPE_DEFAULT
)
255 if (bgp
&& bgp
->rfapi_cfg
)
260 /***********************************************************************
261 * VNC Configuration/CLI
262 ***********************************************************************/
263 #define VNC_VTY_CONFIG_CHECK(bgp) \
265 switch (bgp_rfapi_is_vnc_configured(bgp)) { \
268 "VNC operations only permitted on default BGP instance.\n"); \
269 return CMD_WARNING_CONFIG_FAILED; \
272 vty_out(vty, "VNC not configured.\n"); \
273 return CMD_WARNING_CONFIG_FAILED; \
280 DEFUN (vnc_advertise_un_method
,
281 vnc_advertise_un_method_cmd
,
282 "vnc advertise-un-method encap-attr",
284 "Method of advertising UN addresses\n"
285 "Via Tunnel Encap attribute (in VPN SAFI)\n")
287 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
288 VNC_VTY_CONFIG_CHECK(bgp
);
290 if (!strncmp(argv
[2]->arg
, "encap-safi", 7)) {
291 bgp
->rfapi_cfg
->flags
|= BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
;
293 bgp
->rfapi_cfg
->flags
&= ~BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
;
299 /*-------------------------------------------------------------------------
301 *-----------------------------------------------------------------------*/
304 DEFUN_NOSH (vnc_defaults
,
306 "vnc defaults", VNC_CONFIG_STR
"Configure default NVE group\n")
308 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
309 VNC_VTY_CONFIG_CHECK(bgp
);
310 if (bgp
->inst_type
!= BGP_INSTANCE_TYPE_DEFAULT
) {
311 vty_out(vty
, "Malformed community-list value\n");
312 return CMD_WARNING_CONFIG_FAILED
;
314 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
318 static int set_ecom_list(struct vty
*vty
, int argc
, struct cmd_token
**argv
,
319 struct ecommunity
**list
)
321 struct ecommunity
*ecom
= NULL
;
322 struct ecommunity
*ecomadd
;
324 for (; argc
; --argc
, ++argv
) {
326 ecomadd
= ecommunity_str2com(argv
[0]->arg
,
327 ECOMMUNITY_ROUTE_TARGET
, 0);
329 vty_out(vty
, "Malformed community-list value\n");
331 ecommunity_free(&ecom
);
332 return CMD_WARNING_CONFIG_FAILED
;
336 ecommunity_merge(ecom
, ecomadd
);
337 ecommunity_free(&ecomadd
);
344 ecommunity_free(&*list
);
351 DEFUN (vnc_defaults_rt_import
,
352 vnc_defaults_rt_import_cmd
,
353 "rt import RTLIST...",
354 "Specify default route targets\n"
356 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
358 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
359 return set_ecom_list(vty
, argc
- 2, argv
+ 2,
360 &bgp
->rfapi_cfg
->default_rt_import_list
);
363 DEFUN (vnc_defaults_rt_export
,
364 vnc_defaults_rt_export_cmd
,
365 "rt export RTLIST...",
366 "Configure default route targets\n"
368 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
370 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
371 return set_ecom_list(vty
, argc
- 2, argv
+ 2,
372 &bgp
->rfapi_cfg
->default_rt_export_list
);
375 DEFUN (vnc_defaults_rt_both
,
376 vnc_defaults_rt_both_cmd
,
378 "Configure default route targets\n"
379 "Export+import filters\n"
380 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
382 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
385 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
386 &bgp
->rfapi_cfg
->default_rt_import_list
);
387 if (rc
!= CMD_SUCCESS
)
389 return set_ecom_list(vty
, argc
- 2, argv
+ 2,
390 &bgp
->rfapi_cfg
->default_rt_export_list
);
393 DEFUN (vnc_defaults_rd
,
395 "rd ASN:NN_OR_IP-ADDRESS:NN",
396 "Specify default route distinguisher\n"
397 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:vn:<number> )\n")
399 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
401 struct prefix_rd prd
;
403 if (!strncmp(argv
[1]->arg
, "auto:vn:", 8)) {
405 * use AF_UNIX to designate automatically-assigned RD
406 * auto:vn:nn where nn is a 2-octet quantity
409 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
410 uint16_t value
= value32
& 0xffff;
412 if (!argv
[1]->arg
[8] || *end
) {
413 vty_out(vty
, "%% Malformed rd\n");
414 return CMD_WARNING_CONFIG_FAILED
;
416 if (value32
> 0xffff) {
417 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
419 return CMD_WARNING_CONFIG_FAILED
;
422 memset(&prd
, 0, sizeof(prd
));
423 prd
.family
= AF_UNIX
;
425 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
426 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
427 prd
.val
[6] = (value
>> 8) & 0x0ff;
428 prd
.val
[7] = value
& 0x0ff;
432 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
434 vty_out(vty
, "%% Malformed rd\n");
435 return CMD_WARNING_CONFIG_FAILED
;
439 bgp
->rfapi_cfg
->default_rd
= prd
;
443 DEFUN (vnc_defaults_l2rd
,
444 vnc_defaults_l2rd_cmd
,
445 "l2rd <(1-255)|auto-vn>",
446 "Specify default Local Nve ID value to use in RD for L2 routes\n"
447 "Fixed value 1-255\n"
448 "use the low-order octet of the NVE's VN address\n")
450 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
453 if (strmatch(argv
[1]->text
, "auto-vn")) {
457 unsigned long value_l
= strtoul(argv
[1]->arg
, &end
, 10);
459 value
= value_l
& 0xff;
460 if (!argv
[1]->arg
[0] || *end
) {
461 vty_out(vty
, "%% Malformed l2 nve ID \"%s\"\n",
463 return CMD_WARNING_CONFIG_FAILED
;
465 if ((value_l
< 1) || (value_l
> 0xff)) {
467 "%% Malformed l2 nve id (must be greater than 0 and less than %u\n",
469 return CMD_WARNING_CONFIG_FAILED
;
472 bgp
->rfapi_cfg
->flags
|= BGP_VNC_CONFIG_L2RD
;
473 bgp
->rfapi_cfg
->default_l2rd
= value
;
478 DEFUN (vnc_defaults_no_l2rd
,
479 vnc_defaults_no_l2rd_cmd
,
482 "Specify default Local Nve ID value to use in RD for L2 routes\n")
484 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
486 bgp
->rfapi_cfg
->default_l2rd
= 0;
487 bgp
->rfapi_cfg
->flags
&= ~BGP_VNC_CONFIG_L2RD
;
492 DEFUN (vnc_defaults_responselifetime
,
493 vnc_defaults_responselifetime_cmd
,
494 "response-lifetime <LIFETIME|infinite>",
495 "Specify default response lifetime\n"
496 "Response lifetime in seconds\n" "Infinite response lifetime\n")
498 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
500 struct rfapi
*h
= NULL
;
501 struct listnode
*hdnode
;
502 struct rfapi_descriptor
*rfd
;
506 return CMD_WARNING_CONFIG_FAILED
;
508 if (strmatch(argv
[1]->text
, "infinite")) {
509 rspint
= RFAPI_INFINITE_LIFETIME
;
511 rspint
= strtoul(argv
[1]->arg
, NULL
, 10);
512 if (rspint
> INT32_MAX
)
513 rspint
= INT32_MAX
; /* is really an int, not an unsigned
517 bgp
->rfapi_cfg
->default_response_lifetime
= rspint
;
519 for (ALL_LIST_ELEMENTS_RO(&h
->descriptors
, hdnode
, rfd
))
521 && !(rfd
->rfg
->flags
& RFAPI_RFG_RESPONSE_LIFETIME
))
522 rfd
->response_lifetime
= rfd
->rfg
->response_lifetime
=
528 struct rfapi_nve_group_cfg
*
529 bgp_rfapi_cfg_match_byname(struct bgp
*bgp
, const char *name
,
530 rfapi_group_cfg_type_t type
) /* _MAX = any */
532 struct rfapi_nve_group_cfg
*rfg
;
533 struct listnode
*node
, *nnode
;
535 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->nve_groups_sequential
, node
,
537 if ((type
== RFAPI_GROUP_CFG_MAX
|| type
== rfg
->type
)
538 && !strcmp(rfg
->name
, name
))
544 static struct rfapi_nve_group_cfg
*
545 rfapi_group_new(struct bgp
*bgp
, rfapi_group_cfg_type_t type
, const char *name
)
547 struct rfapi_nve_group_cfg
*rfg
;
549 rfg
= XCALLOC(MTYPE_RFAPI_GROUP_CFG
,
550 sizeof(struct rfapi_nve_group_cfg
));
552 rfg
->name
= strdup(name
);
553 /* add to tail of list */
554 listnode_add(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
);
555 rfg
->label
= MPLS_LABEL_NONE
;
557 QOBJ_REG(rfg
, rfapi_nve_group_cfg
);
562 static struct rfapi_l2_group_cfg
*rfapi_l2_group_lookup_byname(struct bgp
*bgp
,
565 struct rfapi_l2_group_cfg
*rfg
;
566 struct listnode
*node
, *nnode
;
568 if (bgp
->rfapi_cfg
->l2_groups
== NULL
) /* not the best place for this */
569 bgp
->rfapi_cfg
->l2_groups
= list_new();
571 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->l2_groups
, node
, nnode
, rfg
)) {
572 if (!strcmp(rfg
->name
, name
))
578 static struct rfapi_l2_group_cfg
*rfapi_l2_group_new(void)
580 struct rfapi_l2_group_cfg
*rfg
;
582 rfg
= XCALLOC(MTYPE_RFAPI_L2_CFG
, sizeof(struct rfapi_l2_group_cfg
));
583 QOBJ_REG(rfg
, rfapi_l2_group_cfg
);
588 static void rfapi_l2_group_del(struct rfapi_l2_group_cfg
*rfg
)
591 XFREE(MTYPE_RFAPI_L2_CFG
, rfg
);
594 static int rfapi_str2route_type(const char *l3str
, const char *pstr
, afi_t
*afi
,
600 if (!strcmp(l3str
, "ipv4")) {
603 if (!strcmp(l3str
, "ipv6"))
609 if (!strcmp(pstr
, "connected"))
610 *type
= ZEBRA_ROUTE_CONNECT
;
611 if (!strcmp(pstr
, "kernel"))
612 *type
= ZEBRA_ROUTE_KERNEL
;
613 if (!strcmp(pstr
, "static"))
614 *type
= ZEBRA_ROUTE_STATIC
;
615 if (!strcmp(pstr
, "bgp"))
616 *type
= ZEBRA_ROUTE_BGP
;
617 if (!strcmp(pstr
, "bgp-direct"))
618 *type
= ZEBRA_ROUTE_BGP_DIRECT
;
619 if (!strcmp(pstr
, "bgp-direct-to-nve-groups"))
620 *type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
622 if (!strcmp(pstr
, "rip")) {
624 *type
= ZEBRA_ROUTE_RIP
;
626 *type
= ZEBRA_ROUTE_RIPNG
;
629 if (!strcmp(pstr
, "ripng")) {
632 *type
= ZEBRA_ROUTE_RIPNG
;
635 if (!strcmp(pstr
, "ospf")) {
637 *type
= ZEBRA_ROUTE_OSPF
;
639 *type
= ZEBRA_ROUTE_OSPF6
;
642 if (!strcmp(pstr
, "ospf6")) {
645 *type
= ZEBRA_ROUTE_OSPF6
;
651 /*-------------------------------------------------------------------------
653 *-----------------------------------------------------------------------*/
655 #define VNC_REDIST_ENABLE(bgp, afi, type) \
658 case ZEBRA_ROUTE_BGP_DIRECT: \
659 vnc_import_bgp_redist_enable((bgp), (afi)); \
661 case ZEBRA_ROUTE_BGP_DIRECT_EXT: \
662 vnc_import_bgp_exterior_redist_enable((bgp), (afi)); \
665 if ((type) < ZEBRA_ROUTE_MAX) \
666 vnc_redistribute_set((bgp), (afi), (type)); \
671 #define VNC_REDIST_DISABLE(bgp, afi, type) \
674 case ZEBRA_ROUTE_BGP_DIRECT: \
675 vnc_import_bgp_redist_disable((bgp), (afi)); \
677 case ZEBRA_ROUTE_BGP_DIRECT_EXT: \
678 vnc_import_bgp_exterior_redist_disable((bgp), (afi)); \
681 if ((type) < ZEBRA_ROUTE_MAX) \
682 vnc_redistribute_unset((bgp), (afi), (type)); \
687 static uint8_t redist_was_enabled
[AFI_MAX
][ZEBRA_ROUTE_MAX
];
689 static void vnc_redistribute_prechange(struct bgp
*bgp
)
694 vnc_zlog_debug_verbose("%s: entry", __func__
);
695 memset(redist_was_enabled
, 0, sizeof(redist_was_enabled
));
698 * Look to see if we have any redistribution enabled. If so, flush
699 * the corresponding routes and turn off redistribution temporarily.
700 * We need to do it because the RD's used for the redistributed
701 * routes depend on the nve group.
703 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
704 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
705 if (bgp
->rfapi_cfg
->redist
[afi
][type
]) {
706 redist_was_enabled
[afi
][type
] = 1;
707 VNC_REDIST_DISABLE(bgp
, afi
, type
);
711 vnc_zlog_debug_verbose("%s: return", __func__
);
714 static void vnc_redistribute_postchange(struct bgp
*bgp
)
719 vnc_zlog_debug_verbose("%s: entry", __func__
);
721 * If we turned off redistribution above, turn it back on. Doing so
722 * will tell zebra to resend the routes to us
724 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
725 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
726 if (redist_was_enabled
[afi
][type
]) {
727 VNC_REDIST_ENABLE(bgp
, afi
, type
);
731 vnc_zlog_debug_verbose("%s: return", __func__
);
734 DEFUN (vnc_redistribute_rh_roo_localadmin
,
735 vnc_redistribute_rh_roo_localadmin_cmd
,
736 "vnc redistribute resolve-nve roo-ec-local-admin (0-65535)",
738 "Redistribute routes into VNC\n"
740 "Route Origin Extended Community Local Admin Field\n" "Field value\n")
742 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
746 VNC_VTY_CONFIG_CHECK(bgp
);
748 localadmin
= strtoul(argv
[4]->arg
, &endptr
, 0);
749 if (!argv
[4]->arg
[0] || *endptr
) {
750 vty_out(vty
, "%% Malformed value\n");
751 return CMD_WARNING_CONFIG_FAILED
;
754 if (localadmin
> 0xffff) {
755 vty_out(vty
, "%% Value out of range (0-%d)\n", 0xffff);
756 return CMD_WARNING_CONFIG_FAILED
;
759 if (bgp
->rfapi_cfg
->resolve_nve_roo_local_admin
== localadmin
)
762 if ((bgp
->rfapi_cfg
->flags
& BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
)
763 == BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE
) {
765 vnc_export_bgp_prechange(bgp
);
767 vnc_redistribute_prechange(bgp
);
769 bgp
->rfapi_cfg
->resolve_nve_roo_local_admin
= localadmin
;
771 if ((bgp
->rfapi_cfg
->flags
& BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
)
772 == BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE
) {
774 vnc_export_bgp_postchange(bgp
);
776 vnc_redistribute_postchange(bgp
);
782 DEFUN (vnc_redistribute_mode
,
783 vnc_redistribute_mode_cmd
,
784 "vnc redistribute mode <nve-group|plain|resolve-nve>",
786 "Redistribute routes into VNC\n"
787 "Redistribution mode\n"
788 "Based on redistribute nve-group\n"
789 "Unmodified\n" "Resolve each nexthop to connected NVEs\n")
791 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
792 vnc_redist_mode_t newmode
;
794 VNC_VTY_CONFIG_CHECK(bgp
);
796 switch (argv
[3]->arg
[0]) {
798 newmode
= VNC_REDIST_MODE_RFG
;
802 newmode
= VNC_REDIST_MODE_PLAIN
;
806 newmode
= VNC_REDIST_MODE_RESOLVE_NVE
;
810 vty_out(vty
, "unknown redistribute mode\n");
811 return CMD_WARNING_CONFIG_FAILED
;
814 if (newmode
!= bgp
->rfapi_cfg
->redist_mode
) {
815 vnc_redistribute_prechange(bgp
);
816 bgp
->rfapi_cfg
->redist_mode
= newmode
;
817 vnc_redistribute_postchange(bgp
);
823 DEFUN (vnc_redistribute_protocol
,
824 vnc_redistribute_protocol_cmd
,
825 "vnc redistribute <ipv4|ipv6> <bgp|bgp-direct|bgp-direct-to-nve-groups|connected|kernel|ospf|rip|static>",
827 "Redistribute routes into VNC\n"
831 "From BGP without Zebra\n"
832 "From BGP without Zebra, only to configured NVE groups\n"
833 "Connected interfaces\n"
834 "From kernel routes\n"
835 "From Open Shortest Path First (OSPF)\n"
836 "From Routing Information Protocol (RIP)\n" "From Static routes\n")
838 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
839 int type
= ZEBRA_ROUTE_MAX
; /* init to bogus value */
842 VNC_VTY_CONFIG_CHECK(bgp
);
844 if (rfapi_str2route_type(argv
[2]->arg
, argv
[3]->arg
, &afi
, &type
)) {
845 vty_out(vty
, "%% Invalid route type\n");
846 return CMD_WARNING_CONFIG_FAILED
;
849 if (type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
) {
850 if (bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
) {
851 VNC_REDIST_DISABLE(bgp
, afi
,
852 type
); /* disabled view implicitly */
853 free(bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
);
854 bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
= NULL
;
856 bgp
->rfapi_cfg
->redist_bgp_exterior_view
= bgp
;
859 VNC_REDIST_ENABLE(bgp
, afi
, type
);
864 DEFUN (vnc_no_redistribute_protocol
,
865 vnc_no_redistribute_protocol_cmd
,
866 "no vnc redistribute <ipv4|ipv6> <bgp|bgp-direct|bgp-direct-to-nve-groups|connected|kernel|ospf|rip|static>",
869 "Redistribute from other protocol\n"
873 "From BGP without Zebra\n"
874 "From BGP without Zebra, only to configured NVE groups\n"
875 "Connected interfaces\n"
876 "From kernel routes\n"
877 "From Open Shortest Path First (OSPF)\n"
878 "From Routing Information Protocol (RIP)\n" "From Static routes\n")
880 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
884 VNC_VTY_CONFIG_CHECK(bgp
);
886 if (rfapi_str2route_type(argv
[3]->arg
, argv
[4]->arg
, &afi
, &type
)) {
887 vty_out(vty
, "%% Invalid route type\n");
888 return CMD_WARNING_CONFIG_FAILED
;
891 VNC_REDIST_DISABLE(bgp
, afi
, type
);
893 if (type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
) {
894 if (bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
) {
895 free(bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
);
896 bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
= NULL
;
898 bgp
->rfapi_cfg
->redist_bgp_exterior_view
= NULL
;
904 DEFUN (vnc_redistribute_bgp_exterior
,
905 vnc_redistribute_bgp_exterior_cmd
,
906 "vnc redistribute <ipv4|ipv6> bgp-direct-to-nve-groups view NAME",
908 "Redistribute routes into VNC\n"
911 "From BGP without Zebra, only to configured NVE groups\n"
912 "From BGP view\n" "BGP view name\n")
914 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
918 VNC_VTY_CONFIG_CHECK(bgp
);
920 if (rfapi_str2route_type(argv
[2]->arg
, "bgp-direct-to-nve-groups", &afi
,
922 vty_out(vty
, "%% Invalid route type\n");
923 return CMD_WARNING_CONFIG_FAILED
;
926 if (bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
)
927 free(bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
);
928 bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
= strdup(argv
[5]->arg
);
929 /* could be NULL if name is not defined yet */
930 bgp
->rfapi_cfg
->redist_bgp_exterior_view
=
931 bgp_lookup_by_name(argv
[5]->arg
);
933 VNC_REDIST_ENABLE(bgp
, afi
, type
);
938 DEFUN (vnc_redistribute_nvegroup
,
939 vnc_redistribute_nvegroup_cmd
,
940 "vnc redistribute nve-group NAME",
942 "Assign a NVE group to routes redistributed from another routing protocol\n"
943 "NVE group\n" "Group name\n")
945 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
946 VNC_VTY_CONFIG_CHECK(bgp
);
948 vnc_redistribute_prechange(bgp
);
951 * OK if nve group doesn't exist yet; we'll set the pointer
952 * when the group is defined later
954 bgp
->rfapi_cfg
->rfg_redist
= bgp_rfapi_cfg_match_byname(
955 bgp
, argv
[3]->arg
, RFAPI_GROUP_CFG_NVE
);
956 if (bgp
->rfapi_cfg
->rfg_redist_name
)
957 free(bgp
->rfapi_cfg
->rfg_redist_name
);
958 bgp
->rfapi_cfg
->rfg_redist_name
= strdup(argv
[3]->arg
);
960 vnc_redistribute_postchange(bgp
);
965 DEFUN (vnc_redistribute_no_nvegroup
,
966 vnc_redistribute_no_nvegroup_cmd
,
967 "no vnc redistribute nve-group",
970 "Redistribute from other protocol\n"
971 "Assign a NVE group to routes redistributed from another routing protocol\n")
973 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
975 VNC_VTY_CONFIG_CHECK(bgp
);
977 vnc_redistribute_prechange(bgp
);
979 bgp
->rfapi_cfg
->rfg_redist
= NULL
;
980 if (bgp
->rfapi_cfg
->rfg_redist_name
)
981 free(bgp
->rfapi_cfg
->rfg_redist_name
);
982 bgp
->rfapi_cfg
->rfg_redist_name
= NULL
;
984 vnc_redistribute_postchange(bgp
);
990 DEFUN (vnc_redistribute_lifetime
,
991 vnc_redistribute_lifetime_cmd
,
992 "vnc redistribute lifetime <LIFETIME|infinite>",
995 "Assign a lifetime to routes redistributed from another routing protocol\n"
996 "lifetime value (32 bit)\n"
997 "Allow lifetime to never expire\n")
999 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1000 VNC_VTY_CONFIG_CHECK(bgp
);
1002 vnc_redistribute_prechange(bgp
);
1004 if (strmatch(argv
[3]->text
, "infinite")) {
1005 bgp
->rfapi_cfg
->redist_lifetime
= RFAPI_INFINITE_LIFETIME
;
1007 bgp
->rfapi_cfg
->redist_lifetime
=
1008 strtoul(argv
[3]->arg
, NULL
, 10);
1011 vnc_redistribute_postchange(bgp
);
1016 /*-- redist policy, non-nvegroup start --*/
1018 DEFUN (vnc_redist_bgpdirect_no_prefixlist
,
1019 vnc_redist_bgpdirect_no_prefixlist_cmd
,
1020 "no vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> <ipv4|ipv6> prefix-list",
1023 "Redistribute from other protocol\n"
1024 "Redistribute from BGP directly\n"
1025 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1027 "IPv6 routes\n" "Prefix-list for filtering redistributed routes\n")
1029 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1031 struct rfapi_cfg
*hc
;
1032 uint8_t route_type
= 0;
1034 VNC_VTY_CONFIG_CHECK(bgp
);
1035 hc
= bgp
->rfapi_cfg
;
1037 if (strmatch(argv
[3]->text
, "bgp-direct")) {
1038 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1040 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1043 if (strmatch(argv
[4]->text
, "ipv4")) {
1049 vnc_redistribute_prechange(bgp
);
1051 if (hc
->plist_redist_name
[route_type
][afi
])
1052 free(hc
->plist_redist_name
[route_type
][afi
]);
1053 hc
->plist_redist_name
[route_type
][afi
] = NULL
;
1054 hc
->plist_redist
[route_type
][afi
] = NULL
;
1056 vnc_redistribute_postchange(bgp
);
1061 DEFUN (vnc_redist_bgpdirect_prefixlist
,
1062 vnc_redist_bgpdirect_prefixlist_cmd
,
1063 "vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> <ipv4|ipv6> prefix-list NAME",
1065 "Redistribute from other protocol\n"
1066 "Redistribute from BGP directly\n"
1067 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1070 "Prefix-list for filtering redistributed routes\n"
1071 "prefix list name\n")
1073 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1074 struct rfapi_cfg
*hc
;
1076 uint8_t route_type
= 0;
1078 VNC_VTY_CONFIG_CHECK(bgp
);
1079 hc
= bgp
->rfapi_cfg
;
1081 if (strmatch(argv
[2]->text
, "bgp-direct")) {
1082 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1084 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1087 if (strmatch(argv
[3]->text
, "ipv4")) {
1093 vnc_redistribute_prechange(bgp
);
1095 if (hc
->plist_redist_name
[route_type
][afi
])
1096 free(hc
->plist_redist_name
[route_type
][afi
]);
1097 hc
->plist_redist_name
[route_type
][afi
] = strdup(argv
[5]->arg
);
1098 hc
->plist_redist
[route_type
][afi
] =
1099 prefix_list_lookup(afi
, argv
[5]->arg
);
1101 vnc_redistribute_postchange(bgp
);
1106 DEFUN (vnc_redist_bgpdirect_no_routemap
,
1107 vnc_redist_bgpdirect_no_routemap_cmd
,
1108 "no vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> route-map",
1111 "Redistribute from other protocols\n"
1112 "Redistribute from BGP directly\n"
1113 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1114 "Route-map for filtering redistributed routes\n")
1116 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1117 struct rfapi_cfg
*hc
;
1118 uint8_t route_type
= 0;
1120 VNC_VTY_CONFIG_CHECK(bgp
);
1121 hc
= bgp
->rfapi_cfg
;
1123 if (strmatch(argv
[3]->text
, "bgp-direct")) {
1124 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1126 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1129 vnc_redistribute_prechange(bgp
);
1131 if (hc
->routemap_redist_name
[route_type
])
1132 free(hc
->routemap_redist_name
[route_type
]);
1133 hc
->routemap_redist_name
[route_type
] = NULL
;
1134 hc
->routemap_redist
[route_type
] = NULL
;
1136 vnc_redistribute_postchange(bgp
);
1141 DEFUN (vnc_redist_bgpdirect_routemap
,
1142 vnc_redist_bgpdirect_routemap_cmd
,
1143 "vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> route-map NAME",
1145 "Redistribute from other protocols\n"
1146 "Redistribute from BGP directly\n"
1147 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1148 "Route-map for filtering exported routes\n" "route map name\n")
1150 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1151 struct rfapi_cfg
*hc
;
1152 uint8_t route_type
= 0;
1154 VNC_VTY_CONFIG_CHECK(bgp
);
1155 hc
= bgp
->rfapi_cfg
;
1157 if (strmatch(argv
[2]->text
, "bgp-direct")) {
1158 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1160 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1163 vnc_redistribute_prechange(bgp
);
1165 if (hc
->routemap_redist_name
[route_type
])
1166 free(hc
->routemap_redist_name
[route_type
]);
1168 /* If the old route map config overwrite with new
1169 * route map config , old routemap counter have to be
1172 route_map_counter_decrement(hc
->routemap_redist
[route_type
]);
1173 hc
->routemap_redist_name
[route_type
] = strdup(argv
[4]->arg
);
1174 hc
->routemap_redist
[route_type
] =
1175 route_map_lookup_by_name(argv
[4]->arg
);
1176 route_map_counter_increment(hc
->routemap_redist
[route_type
]);
1178 vnc_redistribute_postchange(bgp
);
1183 /*-- redist policy, non-nvegroup end --*/
1185 /*-- redist policy, nvegroup start --*/
1187 DEFUN (vnc_nve_group_redist_bgpdirect_no_prefixlist
,
1188 vnc_nve_group_redist_bgpdirect_no_prefixlist_cmd
,
1189 "no redistribute bgp-direct <ipv4|ipv6> prefix-list",
1191 "Redistribute from other protocol\n"
1192 "Redistribute from BGP directly\n"
1195 "Prefix-list for filtering redistributed routes\n")
1197 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1198 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
)
1201 VNC_VTY_CONFIG_CHECK(bgp
);
1203 /* make sure it's still in list */
1204 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1205 /* Not in list anymore */
1206 vty_out(vty
, "Current NVE group no longer exists\n");
1207 return CMD_WARNING_CONFIG_FAILED
;
1210 if (strmatch(argv
[3]->text
, "ipv4")) {
1216 vnc_redistribute_prechange(bgp
);
1218 if (rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
])
1219 free(rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
]);
1220 rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] = NULL
;
1221 rfg
->plist_redist
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] = NULL
;
1223 vnc_redistribute_postchange(bgp
);
1228 DEFUN (vnc_nve_group_redist_bgpdirect_prefixlist
,
1229 vnc_nve_group_redist_bgpdirect_prefixlist_cmd
,
1230 "redistribute bgp-direct <ipv4|ipv6> prefix-list NAME",
1231 "Redistribute from other protocol\n"
1232 "Redistribute from BGP directly\n"
1235 "Prefix-list for filtering redistributed routes\n"
1236 "prefix list name\n")
1238 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1239 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1242 VNC_VTY_CONFIG_CHECK(bgp
);
1244 /* make sure it's still in list */
1245 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1246 /* Not in list anymore */
1247 vty_out(vty
, "Current NVE group no longer exists\n");
1248 return CMD_WARNING_CONFIG_FAILED
;
1251 if (strmatch(argv
[2]->text
, "ipv4")) {
1257 vnc_redistribute_prechange(bgp
);
1259 if (rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
])
1260 free(rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
]);
1261 rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] =
1262 strdup(argv
[4]->arg
);
1263 rfg
->plist_redist
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] =
1264 prefix_list_lookup(afi
, argv
[4]->arg
);
1266 vnc_redistribute_postchange(bgp
);
1271 DEFUN (vnc_nve_group_redist_bgpdirect_no_routemap
,
1272 vnc_nve_group_redist_bgpdirect_no_routemap_cmd
,
1273 "no redistribute bgp-direct route-map",
1275 "Redistribute from other protocols\n"
1276 "Redistribute from BGP directly\n"
1277 "Route-map for filtering redistributed routes\n")
1279 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1280 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1282 VNC_VTY_CONFIG_CHECK(bgp
);
1284 /* make sure it's still in list */
1285 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1286 /* Not in list anymore */
1287 vty_out(vty
, "Current NVE group no longer exists\n");
1288 return CMD_WARNING_CONFIG_FAILED
;
1291 vnc_redistribute_prechange(bgp
);
1293 if (rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
])
1294 free(rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]);
1295 route_map_counter_decrement(
1296 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
]);
1297 rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
] = NULL
;
1298 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
] = NULL
;
1300 vnc_redistribute_postchange(bgp
);
1305 DEFUN (vnc_nve_group_redist_bgpdirect_routemap
,
1306 vnc_nve_group_redist_bgpdirect_routemap_cmd
,
1307 "redistribute bgp-direct route-map NAME",
1308 "Redistribute from other protocols\n"
1309 "Redistribute from BGP directly\n"
1310 "Route-map for filtering exported routes\n" "route map name\n")
1312 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1313 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1315 VNC_VTY_CONFIG_CHECK(bgp
);
1317 /* make sure it's still in list */
1318 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1319 /* Not in list anymore */
1320 vty_out(vty
, "Current NVE group no longer exists\n");
1321 return CMD_WARNING_CONFIG_FAILED
;
1324 vnc_redistribute_prechange(bgp
);
1326 if (rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
])
1327 free(rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]);
1328 route_map_counter_decrement(
1329 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
]);
1330 rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
] =
1331 strdup(argv
[3]->arg
);
1332 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
] =
1333 route_map_lookup_by_name(argv
[3]->arg
);
1334 route_map_counter_increment(
1335 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
]);
1337 vnc_redistribute_postchange(bgp
);
1342 /*-- redist policy, nvegroup end --*/
1344 /*-------------------------------------------------------------------------
1346 *-----------------------------------------------------------------------*/
1348 DEFUN (vnc_export_mode
,
1349 vnc_export_mode_cmd
,
1350 "vnc export <bgp|zebra> mode <group-nve|ce|none|registering-nve>",
1352 "Export to other protocols\n"
1354 "Export to Zebra (experimental)\n"
1355 "Select export mode\n"
1356 "Export routes with nve-group next-hops\n"
1357 "Export routes with NVE connected router next-hops\n"
1358 "Disable export\n" "Export routes with registering NVE as next-hop\n")
1360 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1361 uint32_t oldmode
= 0;
1362 uint32_t newmode
= 0;
1364 VNC_VTY_CONFIG_CHECK(bgp
);
1366 if (argv
[2]->arg
[0] == 'b') {
1367 oldmode
= bgp
->rfapi_cfg
->flags
1368 & BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
;
1369 switch (argv
[4]->arg
[0]) {
1371 newmode
= BGP_VNC_CONFIG_EXPORT_BGP_MODE_GRP
;
1374 newmode
= BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE
;
1380 newmode
= BGP_VNC_CONFIG_EXPORT_BGP_MODE_RH
;
1383 vty_out(vty
, "Invalid mode specified\n");
1384 return CMD_WARNING_CONFIG_FAILED
;
1387 if (newmode
== oldmode
) {
1388 vty_out(vty
, "Mode unchanged\n");
1392 vnc_export_bgp_prechange(bgp
);
1394 bgp
->rfapi_cfg
->flags
&= ~BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
;
1395 bgp
->rfapi_cfg
->flags
|= newmode
;
1397 vnc_export_bgp_postchange(bgp
);
1402 * export to zebra with RH mode is not yet implemented
1405 "Changing modes for zebra export not implemented yet\n");
1406 return CMD_WARNING_CONFIG_FAILED
;
1412 static struct rfapi_rfg_name
*rfgn_new(void)
1414 return XCALLOC(MTYPE_RFAPI_RFG_NAME
, sizeof(struct rfapi_rfg_name
));
1417 static void rfgn_free(struct rfapi_rfg_name
*rfgn
)
1419 XFREE(MTYPE_RFAPI_RFG_NAME
, rfgn
);
1422 DEFUN (vnc_export_nvegroup
,
1423 vnc_export_nvegroup_cmd
,
1424 "vnc export <bgp|zebra> group-nve group NAME",
1426 "Export to other protocols\n"
1428 "Export to Zebra (experimental)\n"
1429 "NVE group, used in 'group-nve' export mode\n"
1430 "NVE group\n" "Group name\n")
1432 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1433 struct rfapi_nve_group_cfg
*rfg_new
;
1435 VNC_VTY_CONFIG_CHECK(bgp
);
1437 rfg_new
= bgp_rfapi_cfg_match_byname(bgp
, argv
[5]->arg
,
1438 RFAPI_GROUP_CFG_NVE
);
1439 if (rfg_new
== NULL
) {
1440 rfg_new
= bgp_rfapi_cfg_match_byname(bgp
, argv
[5]->arg
,
1441 RFAPI_GROUP_CFG_VRF
);
1443 vnc_add_vrf_opener(bgp
, rfg_new
);
1446 if (rfg_new
== NULL
) {
1447 vty_out(vty
, "Can't find group named \"%s\".\n", argv
[5]->arg
);
1448 return CMD_WARNING_CONFIG_FAILED
;
1451 if (argv
[2]->arg
[0] == 'b') {
1453 struct listnode
*node
;
1454 struct rfapi_rfg_name
*rfgn
;
1457 * Set group for export to BGP Direct
1460 /* see if group is already included in export list */
1461 for (ALL_LIST_ELEMENTS_RO(
1462 bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
1465 if (!strcmp(rfgn
->name
, argv
[5]->arg
)) {
1466 /* already in the list: we're done */
1472 rfgn
->name
= strdup(argv
[5]->arg
);
1473 rfgn
->rfg
= rfg_new
; /* OK if not set yet */
1475 listnode_add(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, rfgn
);
1477 vnc_zlog_debug_verbose("%s: testing rfg_new", __func__
);
1479 vnc_zlog_debug_verbose(
1480 "%s: testing bgp grp mode enabled", __func__
);
1481 if (VNC_EXPORT_BGP_GRP_ENABLED(bgp
->rfapi_cfg
))
1482 vnc_zlog_debug_verbose(
1483 "%s: calling vnc_direct_bgp_add_group",
1485 vnc_direct_bgp_add_group(bgp
, rfg_new
);
1490 struct listnode
*node
;
1491 struct rfapi_rfg_name
*rfgn
;
1494 * Set group for export to Zebra
1497 /* see if group is already included in export list */
1498 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
,
1501 if (!strcmp(rfgn
->name
, argv
[5]->arg
)) {
1502 /* already in the list: we're done */
1508 rfgn
->name
= strdup(argv
[5]->arg
);
1509 rfgn
->rfg
= rfg_new
; /* OK if not set yet */
1511 listnode_add(bgp
->rfapi_cfg
->rfg_export_zebra_l
, rfgn
);
1514 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(bgp
->rfapi_cfg
))
1515 vnc_zebra_add_group(bgp
, rfg_new
);
1523 * This command applies to routes exported from VNC to BGP directly
1524 * without going though zebra
1526 DEFUN (vnc_no_export_nvegroup
,
1527 vnc_no_export_nvegroup_cmd
,
1528 "vnc export <bgp|zebra> group-nve no group NAME",
1530 "Export to other protocols\n"
1532 "Export to Zebra (experimental)\n"
1533 "NVE group, used in 'group-nve' export mode\n"
1534 "Disable export of VNC routes\n" "NVE group\n" "Group name\n")
1536 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1537 struct listnode
*node
, *nnode
;
1538 struct rfapi_rfg_name
*rfgn
;
1540 VNC_VTY_CONFIG_CHECK(bgp
);
1542 if (argv
[2]->arg
[0] == 'b') {
1543 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
,
1544 node
, nnode
, rfgn
)) {
1546 if (rfgn
->name
&& !strcmp(rfgn
->name
, argv
[6]->arg
)) {
1547 vnc_zlog_debug_verbose("%s: matched \"%s\"",
1548 __func__
, rfgn
->name
);
1550 vnc_direct_bgp_del_group(bgp
,
1554 bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
,
1561 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
1564 vnc_zlog_debug_verbose("does rfg \"%s\" match?",
1566 if (rfgn
->name
&& !strcmp(rfgn
->name
, argv
[6]->arg
)) {
1568 vnc_zebra_del_group(bgp
, rfgn
->rfg
);
1571 bgp
->rfapi_cfg
->rfg_export_zebra_l
,
1581 DEFUN (vnc_nve_group_export_no_prefixlist
,
1582 vnc_nve_group_export_no_prefixlist_cmd
,
1583 "no export <bgp|zebra> <ipv4|ipv6> prefix-list [NAME]",
1585 "Export to other protocols\n"
1587 "Export to Zebra (experimental)\n"
1590 "Prefix-list for filtering exported routes\n" "prefix list name\n")
1592 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1593 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1598 VNC_VTY_CONFIG_CHECK(bgp
);
1600 /* make sure it's still in list */
1601 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1602 /* Not in list anymore */
1603 vty_out(vty
, "Current NVE group no longer exists\n");
1604 return CMD_WARNING_CONFIG_FAILED
;
1607 if (!argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
1608 vty_out(vty
, "%% Malformed Address Family\n");
1609 return CMD_WARNING_CONFIG_FAILED
;
1612 if (argv
[idx
- 1]->text
[0] == 'z')
1614 idx
+= 2; /* skip afi and keyword */
1618 || (rfg
->plist_export_bgp_name
[afi
]
1619 && strmatch(argv
[idx
]->arg
,
1620 rfg
->plist_export_bgp_name
[afi
]))) {
1621 if (rfg
->plist_export_bgp_name
[afi
])
1622 free(rfg
->plist_export_bgp_name
[afi
]);
1623 rfg
->plist_export_bgp_name
[afi
] = NULL
;
1624 rfg
->plist_export_bgp
[afi
] = NULL
;
1626 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, afi
);
1630 || (rfg
->plist_export_zebra_name
[afi
]
1631 && strmatch(argv
[idx
]->arg
,
1632 rfg
->plist_export_zebra_name
[afi
]))) {
1633 if (rfg
->plist_export_zebra_name
[afi
])
1634 free(rfg
->plist_export_zebra_name
[afi
]);
1635 rfg
->plist_export_zebra_name
[afi
] = NULL
;
1636 rfg
->plist_export_zebra
[afi
] = NULL
;
1638 vnc_zebra_reexport_group_afi(bgp
, rfg
, afi
);
1644 ALIAS (vnc_nve_group_export_no_prefixlist
,
1645 vnc_vrf_policy_export_no_prefixlist_cmd
,
1646 "no export <ipv4|ipv6> prefix-list [NAME]",
1651 "Prefix-list for filtering exported routes\n" "prefix list name\n")
1653 DEFUN (vnc_nve_group_export_prefixlist
,
1654 vnc_nve_group_export_prefixlist_cmd
,
1655 "export <bgp|zebra> <ipv4|ipv6> prefix-list NAME",
1656 "Export to other protocols\n"
1658 "Export to Zebra (experimental)\n"
1661 "Prefix-list for filtering exported routes\n" "prefix list name\n")
1663 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1664 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1669 VNC_VTY_CONFIG_CHECK(bgp
);
1671 /* make sure it's still in list */
1672 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1673 /* Not in list anymore */
1674 vty_out(vty
, "Current NVE group no longer exists\n");
1675 return CMD_WARNING_CONFIG_FAILED
;
1678 if (!argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
1679 vty_out(vty
, "%% Malformed Address Family\n");
1680 return CMD_WARNING_CONFIG_FAILED
;
1683 if (argv
[idx
- 1]->text
[0] == 'z')
1688 if (rfg
->plist_export_bgp_name
[afi
])
1689 free(rfg
->plist_export_bgp_name
[afi
]);
1690 rfg
->plist_export_bgp_name
[afi
] = strdup(argv
[idx
]->arg
);
1691 rfg
->plist_export_bgp
[afi
] =
1692 prefix_list_lookup(afi
, argv
[idx
]->arg
);
1694 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, afi
);
1697 if (rfg
->plist_export_zebra_name
[afi
])
1698 free(rfg
->plist_export_zebra_name
[afi
]);
1699 rfg
->plist_export_zebra_name
[afi
] = strdup(argv
[idx
]->arg
);
1700 rfg
->plist_export_zebra
[afi
] =
1701 prefix_list_lookup(afi
, argv
[idx
]->arg
);
1703 vnc_zebra_reexport_group_afi(bgp
, rfg
, afi
);
1708 ALIAS (vnc_nve_group_export_prefixlist
,
1709 vnc_vrf_policy_export_prefixlist_cmd
,
1710 "export <ipv4|ipv6> prefix-list NAME",
1714 "Prefix-list for filtering exported routes\n" "prefix list name\n")
1716 DEFUN (vnc_nve_group_export_no_routemap
,
1717 vnc_nve_group_export_no_routemap_cmd
,
1718 "no export <bgp|zebra> route-map [NAME]",
1720 "Export to other protocols\n"
1722 "Export to Zebra (experimental)\n"
1723 "Route-map for filtering exported routes\n" "route map name\n")
1725 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1726 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1730 VNC_VTY_CONFIG_CHECK(bgp
);
1732 /* make sure it's still in list */
1733 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1734 /* Not in list anymore */
1735 vty_out(vty
, "Current NVE group no longer exists\n");
1736 return CMD_WARNING_CONFIG_FAILED
;
1738 switch (argv
[idx
]->text
[0]) {
1745 default: /* route-map */
1752 || (rfg
->routemap_export_bgp_name
1753 && strmatch(argv
[idx
]->arg
,
1754 rfg
->routemap_export_bgp_name
))) {
1755 if (rfg
->routemap_export_bgp_name
)
1756 free(rfg
->routemap_export_bgp_name
);
1757 route_map_counter_decrement(rfg
->routemap_export_bgp
);
1758 rfg
->routemap_export_bgp_name
= NULL
;
1759 rfg
->routemap_export_bgp
= NULL
;
1761 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1762 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1766 || (rfg
->routemap_export_zebra_name
1767 && strmatch(argv
[idx
]->arg
,
1768 rfg
->routemap_export_zebra_name
))) {
1769 if (rfg
->routemap_export_zebra_name
)
1770 free(rfg
->routemap_export_zebra_name
);
1771 route_map_counter_decrement(rfg
->routemap_export_zebra
);
1772 rfg
->routemap_export_zebra_name
= NULL
;
1773 rfg
->routemap_export_zebra
= NULL
;
1775 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1776 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1782 ALIAS (vnc_nve_group_export_no_routemap
,
1783 vnc_vrf_policy_export_no_routemap_cmd
,
1784 "no export route-map [NAME]",
1787 "Route-map for filtering exported routes\n" "route map name\n")
1789 DEFUN (vnc_nve_group_export_routemap
,
1790 vnc_nve_group_export_routemap_cmd
,
1791 "export <bgp|zebra> route-map NAME",
1792 "Export to other protocols\n"
1794 "Export to Zebra (experimental)\n"
1795 "Route-map for filtering exported routes\n" "route map name\n")
1797 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1798 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1802 VNC_VTY_CONFIG_CHECK(bgp
);
1804 /* make sure it's still in list */
1805 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1806 /* Not in list anymore */
1807 vty_out(vty
, "Current NVE group no longer exists\n");
1808 return CMD_WARNING_CONFIG_FAILED
;
1811 if (argv
[1]->text
[0] == 'z')
1816 if (rfg
->routemap_export_bgp_name
)
1817 free(rfg
->routemap_export_bgp_name
);
1818 route_map_counter_decrement(rfg
->routemap_export_bgp
);
1819 rfg
->routemap_export_bgp_name
= strdup(argv
[idx
]->arg
);
1820 rfg
->routemap_export_bgp
=
1821 route_map_lookup_by_name(argv
[idx
]->arg
);
1822 route_map_counter_increment(rfg
->routemap_export_bgp
);
1823 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1824 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1826 if (rfg
->routemap_export_zebra_name
)
1827 free(rfg
->routemap_export_zebra_name
);
1828 route_map_counter_decrement(rfg
->routemap_export_zebra
);
1829 rfg
->routemap_export_zebra_name
= strdup(argv
[idx
]->arg
);
1830 rfg
->routemap_export_zebra
=
1831 route_map_lookup_by_name(argv
[idx
]->arg
);
1832 route_map_counter_increment(rfg
->routemap_export_zebra
);
1833 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1834 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1839 ALIAS (vnc_nve_group_export_routemap
,
1840 vnc_vrf_policy_export_routemap_cmd
,
1841 "export route-map NAME",
1843 "Route-map for filtering exported routes\n" "route map name\n")
1845 DEFUN (vnc_nve_export_no_prefixlist
,
1846 vnc_nve_export_no_prefixlist_cmd
,
1847 "no vnc export <bgp|zebra> <ipv4|ipv6> prefix-list [NAME]",
1850 "Export to other protocols\n"
1852 "Export to Zebra (experimental)\n"
1855 "Prefix-list for filtering exported routes\n" "Prefix list name\n")
1857 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1858 struct rfapi_cfg
*hc
;
1861 VNC_VTY_CONFIG_CHECK(bgp
);
1862 hc
= bgp
->rfapi_cfg
;
1864 if (strmatch(argv
[4]->text
, "ipv4")) {
1870 if (argv
[3]->arg
[0] == 'b') {
1871 if (((argc
> 6) && hc
->plist_export_bgp_name
[afi
]
1872 && strmatch(argv
[6]->text
, hc
->plist_export_bgp_name
[afi
]))
1875 free(hc
->plist_export_bgp_name
[afi
]);
1876 hc
->plist_export_bgp_name
[afi
] = NULL
;
1877 hc
->plist_export_bgp
[afi
] = NULL
;
1878 vnc_direct_bgp_reexport(bgp
, afi
);
1881 if (((argc
> 6) && hc
->plist_export_zebra_name
[afi
]
1882 && strmatch(argv
[6]->text
,
1883 hc
->plist_export_zebra_name
[afi
]))
1886 free(hc
->plist_export_zebra_name
[afi
]);
1887 hc
->plist_export_zebra_name
[afi
] = NULL
;
1888 hc
->plist_export_zebra
[afi
] = NULL
;
1889 /* TBD vnc_zebra_rh_reexport(bgp, afi); */
1895 DEFUN (vnc_nve_export_prefixlist
,
1896 vnc_nve_export_prefixlist_cmd
,
1897 "vnc export <bgp|zebra> <ipv4|ipv6> prefix-list NAME",
1899 "Export to other protocols\n"
1901 "Export to Zebra (experimental)\n"
1904 "Prefix-list for filtering exported routes\n" "Prefix list name\n")
1906 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1907 struct rfapi_cfg
*hc
;
1910 VNC_VTY_CONFIG_CHECK(bgp
);
1911 hc
= bgp
->rfapi_cfg
;
1913 if (strmatch(argv
[3]->text
, "ipv4")) {
1919 if (argv
[2]->arg
[0] == 'b') {
1920 if (hc
->plist_export_bgp_name
[afi
])
1921 free(hc
->plist_export_bgp_name
[afi
]);
1922 hc
->plist_export_bgp_name
[afi
] = strdup(argv
[5]->arg
);
1923 hc
->plist_export_bgp
[afi
] =
1924 prefix_list_lookup(afi
, argv
[5]->arg
);
1925 vnc_direct_bgp_reexport(bgp
, afi
);
1927 if (hc
->plist_export_zebra_name
[afi
])
1928 free(hc
->plist_export_zebra_name
[afi
]);
1929 hc
->plist_export_zebra_name
[afi
] = strdup(argv
[5]->arg
);
1930 hc
->plist_export_zebra
[afi
] =
1931 prefix_list_lookup(afi
, argv
[5]->arg
);
1932 /* TBD vnc_zebra_rh_reexport(bgp, afi); */
1937 DEFUN (vnc_nve_export_no_routemap
,
1938 vnc_nve_export_no_routemap_cmd
,
1939 "no vnc export <bgp|zebra> route-map [NAME]",
1942 "Export to other protocols\n"
1944 "Export to Zebra (experimental)\n"
1945 "Route-map for filtering exported routes\n" "Route map name\n")
1947 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1948 struct rfapi_cfg
*hc
;
1950 VNC_VTY_CONFIG_CHECK(bgp
);
1951 hc
= bgp
->rfapi_cfg
;
1953 if (argv
[3]->arg
[0] == 'b') {
1954 if (((argc
> 5) && hc
->routemap_export_bgp_name
1955 && strmatch(argv
[5]->text
, hc
->routemap_export_bgp_name
))
1958 free(hc
->routemap_export_bgp_name
);
1959 route_map_counter_decrement(hc
->routemap_export_bgp
);
1960 hc
->routemap_export_bgp_name
= NULL
;
1961 hc
->routemap_export_bgp
= NULL
;
1962 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
1963 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
1966 if (((argc
> 5) && hc
->routemap_export_zebra_name
1967 && strmatch(argv
[5]->text
, hc
->routemap_export_zebra_name
))
1970 free(hc
->routemap_export_zebra_name
);
1971 route_map_counter_decrement(hc
->routemap_export_zebra
);
1972 hc
->routemap_export_zebra_name
= NULL
;
1973 hc
->routemap_export_zebra
= NULL
;
1974 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
1975 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
1981 DEFUN (vnc_nve_export_routemap
,
1982 vnc_nve_export_routemap_cmd
,
1983 "vnc export <bgp|zebra> route-map NAME",
1985 "Export to other protocols\n"
1987 "Export to Zebra (experimental)\n"
1988 "Route-map for filtering exported routes\n" "Route map name\n")
1990 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1991 struct rfapi_cfg
*hc
;
1993 VNC_VTY_CONFIG_CHECK(bgp
);
1994 hc
= bgp
->rfapi_cfg
;
1996 if (argv
[2]->arg
[0] == 'b') {
1997 if (hc
->routemap_export_bgp_name
)
1998 free(hc
->routemap_export_bgp_name
);
1999 route_map_counter_decrement(hc
->routemap_export_bgp
);
2000 hc
->routemap_export_bgp_name
= strdup(argv
[4]->arg
);
2001 hc
->routemap_export_bgp
=
2002 route_map_lookup_by_name(argv
[4]->arg
);
2003 route_map_counter_increment(hc
->routemap_export_bgp
);
2004 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
2005 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
2007 if (hc
->routemap_export_zebra_name
)
2008 free(hc
->routemap_export_zebra_name
);
2009 route_map_counter_decrement(hc
->routemap_export_zebra
);
2010 hc
->routemap_export_zebra_name
= strdup(argv
[4]->arg
);
2011 hc
->routemap_export_zebra
=
2012 route_map_lookup_by_name(argv
[4]->arg
);
2013 route_map_counter_increment(hc
->routemap_export_zebra
);
2014 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
2015 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
2022 * respond to changes in the global prefix list configuration
2024 void vnc_prefix_list_update(struct bgp
*bgp
)
2028 struct rfapi_nve_group_cfg
*rfg
;
2029 struct rfapi_cfg
*hc
;
2033 vnc_zlog_debug_verbose("%s: No BGP process is configured",
2038 if (!(hc
= bgp
->rfapi_cfg
)) {
2039 vnc_zlog_debug_verbose("%s: rfapi not configured", __func__
);
2043 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
2045 * Loop over nve groups
2047 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->nve_groups_sequential
,
2050 if (rfg
->plist_export_bgp_name
[afi
]) {
2051 rfg
->plist_export_bgp
[afi
] = prefix_list_lookup(
2052 afi
, rfg
->plist_export_bgp_name
[afi
]);
2054 if (rfg
->plist_export_zebra_name
[afi
]) {
2055 rfg
->plist_export_zebra
2056 [afi
] = prefix_list_lookup(
2057 afi
, rfg
->plist_export_zebra_name
[afi
]);
2059 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2060 if (rfg
->plist_redist_name
[i
][afi
]) {
2062 [i
][afi
] = prefix_list_lookup(
2064 rfg
->plist_redist_name
[i
][afi
]);
2068 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, afi
);
2069 /* TBD vnc_zebra_reexport_group_afi(bgp, rfg, afi); */
2075 if (hc
->plist_export_bgp_name
[afi
]) {
2076 hc
->plist_export_bgp
[afi
] = prefix_list_lookup(
2077 afi
, hc
->plist_export_bgp_name
[afi
]);
2079 if (hc
->plist_export_zebra_name
[afi
]) {
2080 hc
->plist_export_zebra
[afi
] = prefix_list_lookup(
2081 afi
, hc
->plist_export_zebra_name
[afi
]);
2084 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2085 if (hc
->plist_redist_name
[i
][afi
]) {
2086 hc
->plist_redist
[i
][afi
] = prefix_list_lookup(
2087 afi
, hc
->plist_redist_name
[i
][afi
]);
2092 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
2093 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
2095 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
2096 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
2098 vnc_redistribute_prechange(bgp
);
2099 vnc_redistribute_postchange(bgp
);
2103 * respond to changes in the global route map configuration
2105 void vnc_routemap_update(struct bgp
*bgp
, const char *unused
)
2108 struct rfapi_nve_group_cfg
*rfg
;
2109 struct rfapi_cfg
*hc
;
2111 struct route_map
*old
= NULL
;
2113 vnc_zlog_debug_verbose("%s(arg=%s)", __func__
, unused
);
2116 vnc_zlog_debug_verbose("%s: No BGP process is configured",
2121 if (!(hc
= bgp
->rfapi_cfg
)) {
2122 vnc_zlog_debug_verbose("%s: rfapi not configured", __func__
);
2127 * Loop over nve groups
2129 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->nve_groups_sequential
, n
,
2132 if (rfg
->routemap_export_bgp_name
) {
2133 old
= rfg
->routemap_export_bgp
;
2134 rfg
->routemap_export_bgp
= route_map_lookup_by_name(
2135 rfg
->routemap_export_bgp_name
);
2136 /* old is NULL. i.e Route map creation event.
2137 * So update applied_counter.
2138 * If Old is not NULL, i.e It may be routemap
2139 * updation or deletion.
2140 * So no need to update the counter.
2143 route_map_counter_increment(
2144 rfg
->routemap_export_bgp
);
2146 if (rfg
->routemap_export_zebra_name
) {
2147 old
= rfg
->routemap_export_bgp
;
2148 rfg
->routemap_export_bgp
= route_map_lookup_by_name(
2149 rfg
->routemap_export_zebra_name
);
2151 route_map_counter_increment(
2152 rfg
->routemap_export_bgp
);
2154 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2155 if (rfg
->routemap_redist_name
[i
]) {
2156 old
= rfg
->routemap_redist
[i
];
2157 rfg
->routemap_redist
[i
] =
2158 route_map_lookup_by_name(
2159 rfg
->routemap_redist_name
[i
]);
2161 route_map_counter_increment(
2162 rfg
->routemap_redist
[i
]);
2166 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP
);
2167 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
2168 /* TBD vnc_zebra_reexport_group_afi(bgp, rfg, afi); */
2174 if (hc
->routemap_export_bgp_name
) {
2175 old
= hc
->routemap_export_bgp
;
2176 hc
->routemap_export_bgp
=
2177 route_map_lookup_by_name(hc
->routemap_export_bgp_name
);
2179 route_map_counter_increment(hc
->routemap_export_bgp
);
2181 if (hc
->routemap_export_zebra_name
) {
2182 old
= hc
->routemap_export_bgp
;
2183 hc
->routemap_export_bgp
= route_map_lookup_by_name(
2184 hc
->routemap_export_zebra_name
);
2186 route_map_counter_increment(hc
->routemap_export_bgp
);
2188 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2189 if (hc
->routemap_redist_name
[i
]) {
2190 old
= hc
->routemap_redist
[i
];
2191 hc
->routemap_redist
[i
] = route_map_lookup_by_name(
2192 hc
->routemap_redist_name
[i
]);
2194 route_map_counter_increment(
2195 hc
->routemap_redist
[i
]);
2199 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
2200 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
2202 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
2203 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
2205 vnc_redistribute_prechange(bgp
);
2206 vnc_redistribute_postchange(bgp
);
2208 vnc_zlog_debug_verbose("%s done", __func__
);
2211 /*-------------------------------------------------------------------------
2213 *-----------------------------------------------------------------------*/
2216 DEFUN_NOSH (vnc_nve_group
,
2218 "vnc nve-group NAME",
2219 VNC_CONFIG_STR
"Configure a NVE group\n" "Group name\n")
2221 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2222 struct rfapi_nve_group_cfg
*rfg
;
2223 struct listnode
*node
, *nnode
;
2224 struct rfapi_rfg_name
*rfgn
;
2226 VNC_VTY_CONFIG_CHECK(bgp
);
2228 /* Search for name */
2229 rfg
= bgp_rfapi_cfg_match_byname(bgp
, argv
[2]->arg
,
2230 RFAPI_GROUP_CFG_NVE
);
2233 rfg
= rfapi_group_new(bgp
, RFAPI_GROUP_CFG_NVE
, argv
[2]->arg
);
2235 /* Error out of memory */
2236 vty_out(vty
, "Can't allocate memory for NVE group\n");
2237 return CMD_WARNING_CONFIG_FAILED
;
2240 /* Copy defaults from struct rfapi_cfg */
2241 rfg
->rd
= bgp
->rfapi_cfg
->default_rd
;
2242 if (bgp
->rfapi_cfg
->flags
& BGP_VNC_CONFIG_L2RD
) {
2243 rfg
->l2rd
= bgp
->rfapi_cfg
->default_l2rd
;
2244 rfg
->flags
|= RFAPI_RFG_L2RD
;
2246 rfg
->rd
= bgp
->rfapi_cfg
->default_rd
;
2247 rfg
->response_lifetime
=
2248 bgp
->rfapi_cfg
->default_response_lifetime
;
2250 if (bgp
->rfapi_cfg
->default_rt_export_list
) {
2251 rfg
->rt_export_list
= ecommunity_dup(
2252 bgp
->rfapi_cfg
->default_rt_export_list
);
2255 if (bgp
->rfapi_cfg
->default_rt_import_list
) {
2256 rfg
->rt_import_list
= ecommunity_dup(
2257 bgp
->rfapi_cfg
->default_rt_import_list
);
2258 rfg
->rfapi_import_table
= rfapiImportTableRefAdd(
2259 bgp
, rfg
->rt_import_list
, rfg
);
2263 * If a redist nve group was named but the group was not
2265 * make the linkage now
2267 if (!bgp
->rfapi_cfg
->rfg_redist
) {
2268 if (bgp
->rfapi_cfg
->rfg_redist_name
2269 && !strcmp(bgp
->rfapi_cfg
->rfg_redist_name
,
2272 vnc_redistribute_prechange(bgp
);
2273 bgp
->rfapi_cfg
->rfg_redist
= rfg
;
2274 vnc_redistribute_postchange(bgp
);
2279 * Same treatment for bgp-direct export group
2281 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
,
2282 node
, nnode
, rfgn
)) {
2284 if (!strcmp(rfgn
->name
, rfg
->name
)) {
2286 vnc_direct_bgp_add_group(bgp
, rfg
);
2292 * Same treatment for zebra export group
2294 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2297 vnc_zlog_debug_verbose(
2298 "%s: ezport zebra: checking if \"%s\" == \"%s\"",
2299 __func__
, rfgn
->name
, rfg
->name
);
2300 if (!strcmp(rfgn
->name
, rfg
->name
)) {
2302 vnc_zebra_add_group(bgp
, rfg
);
2309 * XXX subsequent calls will need to make sure this item is still
2310 * in the linked list and has the same name
2312 VTY_PUSH_CONTEXT_SUB(BGP_VNC_NVE_GROUP_NODE
, rfg
);
2317 static void bgp_rfapi_delete_nve_group(struct vty
*vty
, /* NULL = no output */
2319 struct rfapi_nve_group_cfg
*rfg
)
2321 struct list
*orphaned_nves
= NULL
;
2322 struct listnode
*node
, *nnode
;
2325 * If there are currently-open NVEs that belong to this group,
2326 * zero out their references to this group structure.
2329 struct rfapi_descriptor
*rfd
;
2330 orphaned_nves
= list_new();
2331 while ((rfd
= listnode_head(rfg
->nves
))) {
2333 listnode_delete(rfg
->nves
, rfd
);
2334 listnode_add(orphaned_nves
, rfd
);
2336 list_delete(&rfg
->nves
);
2341 if (rfg
->rfapi_import_table
)
2342 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2343 if (rfg
->rt_import_list
)
2344 ecommunity_free(&rfg
->rt_import_list
);
2345 if (rfg
->rt_export_list
)
2346 ecommunity_free(&rfg
->rt_export_list
);
2349 rfg
->vn_node
->info
= NULL
;
2350 agg_unlock_node(rfg
->vn_node
); /* frees */
2353 rfg
->un_node
->info
= NULL
;
2354 agg_unlock_node(rfg
->un_node
); /* frees */
2357 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, rfg
->rfp_cfg
);
2358 listnode_delete(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
);
2361 XFREE(MTYPE_RFAPI_GROUP_CFG
, rfg
);
2364 * Attempt to reassign the orphaned nves to a new group. If
2365 * a NVE can not be reassigned, its rfd->rfg will remain NULL
2366 * and it will become a zombie until released by rfapi_close().
2368 if (orphaned_nves
) {
2369 struct rfapi_descriptor
*rfd
;
2371 for (ALL_LIST_ELEMENTS(orphaned_nves
, node
, nnode
, rfd
)) {
2373 * 1. rfapi_close() equivalent except:
2374 * a. don't free original descriptor
2375 * b. remember query list
2376 * c. remember advertised route list
2377 * 2. rfapi_open() equivalent except:
2378 * a. reuse original descriptor
2379 * 3. rfapi_register() on remembered advertised route
2381 * 4. rfapi_query on rememebred query list
2386 rc
= rfapi_reopen(rfd
, bgp
);
2389 list_delete_node(orphaned_nves
, node
);
2392 "WARNING: reassigned NVE vn=");
2393 rfapiPrintRfapiIpAddr(vty
, &rfd
->vn_addr
);
2395 vty_out(vty
, " un=");
2396 rfapiPrintRfapiIpAddr(vty
, &rfd
->un_addr
);
2398 vty_out(vty
, " to new group \"%s\"\n",
2403 for (ALL_LIST_ELEMENTS_RO(orphaned_nves
, node
, rfd
)) {
2405 vty_out(vty
, "WARNING: orphaned NVE vn=");
2406 rfapiPrintRfapiIpAddr(vty
, &rfd
->vn_addr
);
2408 vty_out(vty
, " un=");
2409 rfapiPrintRfapiIpAddr(vty
, &rfd
->un_addr
);
2413 list_delete(&orphaned_nves
);
2418 bgp_rfapi_delete_named_nve_group(struct vty
*vty
, /* NULL = no output */
2420 const char *rfg_name
, /* NULL = any */
2421 rfapi_group_cfg_type_t type
) /* _MAX = any */
2423 struct rfapi_nve_group_cfg
*rfg
= NULL
;
2424 struct listnode
*node
, *nnode
;
2425 struct rfapi_rfg_name
*rfgn
;
2427 /* Search for name */
2429 rfg
= bgp_rfapi_cfg_match_byname(bgp
, rfg_name
, type
);
2432 vty_out(vty
, "No NVE group named \"%s\"\n",
2434 return CMD_WARNING_CONFIG_FAILED
;
2439 * If this group is the redist nve group, unlink it
2441 if (rfg_name
== NULL
|| bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2442 vnc_redistribute_prechange(bgp
);
2443 bgp
->rfapi_cfg
->rfg_redist
= NULL
;
2444 vnc_redistribute_postchange(bgp
);
2449 * remove reference from bgp direct export list
2451 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2453 if (rfgn
->rfg
== rfg
) {
2455 /* remove exported routes from this group */
2456 vnc_direct_bgp_del_group(bgp
, rfg
);
2462 * remove reference from zebra export list
2464 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2466 if (rfgn
->rfg
== rfg
) {
2468 /* remove exported routes from this group */
2469 vnc_zebra_del_group(bgp
, rfg
);
2475 clear_vnc_vrf_closer(rfg
);
2476 bgp_rfapi_delete_nve_group(vty
, bgp
, rfg
);
2477 } else /* must be delete all */
2478 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->nve_groups_sequential
,
2479 node
, nnode
, rfg
)) {
2481 clear_vnc_vrf_closer(rfg
);
2482 bgp_rfapi_delete_nve_group(vty
, bgp
, rfg
);
2487 DEFUN (vnc_no_nve_group
,
2488 vnc_no_nve_group_cmd
,
2489 "no vnc nve-group NAME",
2492 "Configure a NVE group\n"
2495 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2497 return bgp_rfapi_delete_named_nve_group(vty
, bgp
, argv
[3]->arg
,
2498 RFAPI_GROUP_CFG_NVE
);
2501 DEFUN (vnc_nve_group_prefix
,
2502 vnc_nve_group_prefix_cmd
,
2503 "prefix <vn|un> <A.B.C.D/M|X:X::X:X/M>",
2504 "Specify prefixes matching NVE VN or UN interfaces\n"
2510 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2511 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2514 struct agg_table
*rt
;
2515 struct agg_node
*rn
;
2516 int is_un_prefix
= 0;
2518 /* make sure it's still in list */
2519 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2520 /* Not in list anymore */
2521 vty_out(vty
, "Current NVE group no longer exists\n");
2522 return CMD_WARNING_CONFIG_FAILED
;
2525 if (!str2prefix(argv
[2]->arg
, &p
)) {
2526 vty_out(vty
, "Malformed prefix \"%s\"\n", argv
[2]->arg
);
2527 return CMD_WARNING_CONFIG_FAILED
;
2530 afi
= family2afi(p
.family
);
2532 vty_out(vty
, "Unsupported address family\n");
2533 return CMD_WARNING_CONFIG_FAILED
;
2536 if (argv
[1]->arg
[0] == 'u') {
2537 rt
= bgp
->rfapi_cfg
->nve_groups_un
[afi
];
2540 rt
= bgp
->rfapi_cfg
->nve_groups_vn
[afi
];
2543 rn
= agg_node_get(rt
, &p
); /* NB locks node */
2546 * There is already a group with this prefix
2548 agg_unlock_node(rn
);
2549 if (rn
->info
!= rfg
) {
2551 * different group name: fail
2554 "nve group \"%s\" already has \"%s\" prefix %s\n",
2555 ((struct rfapi_nve_group_cfg
*)(rn
->info
))
2557 argv
[1]->arg
, argv
[2]->arg
);
2558 return CMD_WARNING_CONFIG_FAILED
;
2561 * same group name: it's already in the correct place
2562 * in the table, so we're done.
2564 * Implies rfg->(vn|un)_prefix is already correct.
2570 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2571 vnc_redistribute_prechange(bgp
);
2574 /* New prefix, new node */
2578 /* detach rfg from previous route table location */
2580 rfg
->un_node
->info
= NULL
;
2581 agg_unlock_node(rfg
->un_node
); /* frees */
2583 rfg
->un_node
= rn
; /* back ref */
2588 /* detach rfg from previous route table location */
2590 rfg
->vn_node
->info
= NULL
;
2591 agg_unlock_node(rfg
->vn_node
); /* frees */
2593 rfg
->vn_node
= rn
; /* back ref */
2600 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2601 vnc_redistribute_postchange(bgp
);
2607 DEFUN (vnc_nve_group_rt_import
,
2608 vnc_nve_group_rt_import_cmd
,
2609 "rt import RTLIST...",
2610 "Specify route targets\n"
2612 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2614 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2615 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2617 struct listnode
*node
;
2618 struct rfapi_rfg_name
*rfgn
;
2619 int is_export_bgp
= 0;
2620 int is_export_zebra
= 0;
2622 /* make sure it's still in list */
2623 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2624 /* Not in list anymore */
2625 vty_out(vty
, "Current NVE group no longer exists\n");
2626 return CMD_WARNING_CONFIG_FAILED
;
2629 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
2630 if (rc
!= CMD_SUCCESS
)
2633 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2636 if (rfgn
->rfg
== rfg
) {
2643 vnc_direct_bgp_del_group(bgp
, rfg
);
2645 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2648 if (rfgn
->rfg
== rfg
) {
2649 is_export_zebra
= 1;
2654 if (is_export_zebra
)
2655 vnc_zebra_del_group(bgp
, rfg
);
2658 * stop referencing old import table, now reference new one
2660 if (rfg
->rfapi_import_table
)
2661 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2662 rfg
->rfapi_import_table
=
2663 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
2666 vnc_direct_bgp_add_group(bgp
, rfg
);
2668 if (is_export_zebra
)
2669 vnc_zebra_add_group(bgp
, rfg
);
2674 DEFUN (vnc_nve_group_rt_export
,
2675 vnc_nve_group_rt_export_cmd
,
2676 "rt export RTLIST...",
2677 "Specify route targets\n"
2679 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2681 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2682 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2685 /* make sure it's still in list */
2686 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2687 /* Not in list anymore */
2688 vty_out(vty
, "Current NVE group no longer exists\n");
2689 return CMD_WARNING_CONFIG_FAILED
;
2692 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2693 vnc_redistribute_prechange(bgp
);
2696 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
2698 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2699 vnc_redistribute_postchange(bgp
);
2705 DEFUN (vnc_nve_group_rt_both
,
2706 vnc_nve_group_rt_both_cmd
,
2707 "rt both RTLIST...",
2708 "Specify route targets\n"
2709 "Export+import filters\n"
2710 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2712 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2713 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2715 int is_export_bgp
= 0;
2716 int is_export_zebra
= 0;
2717 struct listnode
*node
;
2718 struct rfapi_rfg_name
*rfgn
;
2720 /* make sure it's still in list */
2721 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2722 /* Not in list anymore */
2723 vty_out(vty
, "Current NVE group no longer exists\n");
2724 return CMD_WARNING_CONFIG_FAILED
;
2727 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
2728 if (rc
!= CMD_SUCCESS
)
2731 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2734 if (rfgn
->rfg
== rfg
) {
2741 vnc_direct_bgp_del_group(bgp
, rfg
);
2743 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2746 if (rfgn
->rfg
== rfg
) {
2747 is_export_zebra
= 1;
2752 if (is_export_zebra
) {
2753 vnc_zlog_debug_verbose("%s: is_export_zebra", __func__
);
2754 vnc_zebra_del_group(bgp
, rfg
);
2758 * stop referencing old import table, now reference new one
2760 if (rfg
->rfapi_import_table
)
2761 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2762 rfg
->rfapi_import_table
=
2763 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
2766 vnc_direct_bgp_add_group(bgp
, rfg
);
2768 if (is_export_zebra
)
2769 vnc_zebra_add_group(bgp
, rfg
);
2771 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2772 vnc_redistribute_prechange(bgp
);
2775 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
2777 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2778 vnc_redistribute_postchange(bgp
);
2784 DEFUN (vnc_nve_group_l2rd
,
2785 vnc_nve_group_l2rd_cmd
,
2786 "l2rd <(1-255)|auto-vn>",
2787 "Specify default Local Nve ID value to use in RD for L2 routes\n"
2788 "Fixed value 1-255\n"
2789 "use the low-order octet of the NVE's VN address\n")
2791 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2792 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2794 /* make sure it's still in list */
2795 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2796 /* Not in list anymore */
2797 vty_out(vty
, "Current NVE group no longer exists\n");
2798 return CMD_WARNING_CONFIG_FAILED
;
2801 if (strmatch(argv
[1]->text
, "auto:vn")) {
2805 unsigned long value_l
= strtoul(argv
[1]->arg
, &end
, 10);
2806 uint8_t value
= value_l
& 0xff;
2808 if (!argv
[1]->arg
[0] || *end
) {
2809 vty_out(vty
, "%% Malformed l2 nve ID \"%s\"\n",
2811 return CMD_WARNING_CONFIG_FAILED
;
2813 if ((value_l
< 1) || (value_l
> 0xff)) {
2815 "%% Malformed l2 nve id (must be greater than 0 and less than %u\n",
2817 return CMD_WARNING_CONFIG_FAILED
;
2822 rfg
->flags
|= RFAPI_RFG_L2RD
;
2827 DEFUN (vnc_nve_group_no_l2rd
,
2828 vnc_nve_group_no_l2rd_cmd
,
2831 "Specify default Local Nve ID value to use in RD for L2 routes\n")
2833 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2834 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2836 /* make sure it's still in list */
2837 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2838 /* Not in list anymore */
2839 vty_out(vty
, "Current NVE group no longer exists\n");
2840 return CMD_WARNING_CONFIG_FAILED
;
2844 rfg
->flags
&= ~RFAPI_RFG_L2RD
;
2849 DEFUN (vnc_nve_group_rd
,
2850 vnc_nve_group_rd_cmd
,
2851 "rd ASN:NN_OR_IP-ADDRESS:NN",
2852 "Specify route distinguisher\n"
2853 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:vn:<number> )\n")
2855 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2857 struct prefix_rd prd
;
2858 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2860 /* make sure it's still in list */
2861 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2862 /* Not in list anymore */
2863 vty_out(vty
, "Current NVE group no longer exists\n");
2864 return CMD_WARNING_CONFIG_FAILED
;
2867 if (!strncmp(argv
[1]->arg
, "auto:vn:", 8)) {
2869 * use AF_UNIX to designate automatically-assigned RD
2870 * auto:vn:nn where nn is a 2-octet quantity
2873 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
2874 uint16_t value
= value32
& 0xffff;
2876 if (!argv
[1]->arg
[8] || *end
) {
2877 vty_out(vty
, "%% Malformed rd\n");
2878 return CMD_WARNING_CONFIG_FAILED
;
2880 if (value32
> 0xffff) {
2881 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
2883 return CMD_WARNING_CONFIG_FAILED
;
2886 memset(&prd
, 0, sizeof(prd
));
2887 prd
.family
= AF_UNIX
;
2889 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
2890 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
2891 prd
.val
[6] = (value
>> 8) & 0x0ff;
2892 prd
.val
[7] = value
& 0x0ff;
2896 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
2898 vty_out(vty
, "%% Malformed rd\n");
2899 return CMD_WARNING_CONFIG_FAILED
;
2903 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2904 vnc_redistribute_prechange(bgp
);
2909 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2910 vnc_redistribute_postchange(bgp
);
2915 DEFUN (vnc_nve_group_responselifetime
,
2916 vnc_nve_group_responselifetime_cmd
,
2917 "response-lifetime <LIFETIME|infinite>",
2918 "Specify response lifetime\n"
2919 "Response lifetime in seconds\n" "Infinite response lifetime\n")
2921 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2922 unsigned int rspint
;
2923 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2924 struct rfapi_descriptor
*rfd
;
2925 struct listnode
*hdnode
;
2927 /* make sure it's still in list */
2928 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2929 /* Not in list anymore */
2930 vty_out(vty
, "Current NVE group no longer exists\n");
2931 return CMD_WARNING_CONFIG_FAILED
;
2934 if (strmatch(argv
[1]->text
, "infinite")) {
2935 rspint
= RFAPI_INFINITE_LIFETIME
;
2937 rspint
= strtoul(argv
[1]->arg
, NULL
, 10);
2940 rfg
->response_lifetime
= rspint
;
2941 rfg
->flags
|= RFAPI_RFG_RESPONSE_LIFETIME
;
2943 for (ALL_LIST_ELEMENTS_RO(rfg
->nves
, hdnode
, rfd
))
2944 rfd
->response_lifetime
= rspint
;
2949 * Sigh. This command, like exit-address-family, is a hack to deal
2950 * with the lack of rigorous level control in the command handler.
2951 * TBD fix command handler.
2953 DEFUN_NOSH (exit_vnc
,
2956 "Exit VNC configuration mode\n")
2958 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
2959 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
2960 || vty
->node
== BGP_VNC_L2_GROUP_NODE
) {
2962 vty
->node
= BGP_NODE
;
2967 static struct cmd_node bgp_vnc_defaults_node
= {
2968 .name
= "bgp vnc defaults",
2969 .node
= BGP_VNC_DEFAULTS_NODE
,
2970 .parent_node
= BGP_NODE
,
2971 .prompt
= "%s(config-router-vnc-defaults)# ",
2974 static struct cmd_node bgp_vnc_nve_group_node
= {
2975 .name
= "bgp vnc nve",
2976 .node
= BGP_VNC_NVE_GROUP_NODE
,
2977 .parent_node
= BGP_NODE
,
2978 .prompt
= "%s(config-router-vnc-nve-group)# ",
2981 /*-------------------------------------------------------------------------
2983 * Note there are two types of NVEs, one for VPNs one for RFP NVEs
2984 *-----------------------------------------------------------------------*/
2986 DEFUN_NOSH (vnc_vrf_policy
,
2989 "Configure a VRF policy group\n"
2992 struct rfapi_nve_group_cfg
*rfg
;
2993 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2995 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_VRF
) {
2997 "Can't configure vrf-policy within a BGP VRF instance\n");
2998 return CMD_WARNING_CONFIG_FAILED
;
3001 /* Search for name */
3002 rfg
= bgp_rfapi_cfg_match_byname(bgp
, argv
[1]->arg
,
3003 RFAPI_GROUP_CFG_VRF
);
3006 rfg
= rfapi_group_new(bgp
, RFAPI_GROUP_CFG_VRF
, argv
[1]->arg
);
3008 /* Error out of memory */
3009 vty_out(vty
, "Can't allocate memory for NVE group\n");
3010 return CMD_WARNING_CONFIG_FAILED
;
3014 * XXX subsequent calls will need to make sure this item is still
3015 * in the linked list and has the same name
3017 VTY_PUSH_CONTEXT_SUB(BGP_VRF_POLICY_NODE
, rfg
);
3022 DEFUN (vnc_no_vrf_policy
,
3023 vnc_no_vrf_policy_cmd
,
3024 "no vrf-policy NAME",
3026 "Remove a VRF policy group\n"
3029 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3031 /* silently return */
3032 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_VRF
)
3035 return bgp_rfapi_delete_named_nve_group(vty
, bgp
, argv
[2]->arg
,
3036 RFAPI_GROUP_CFG_VRF
);
3039 DEFUN (vnc_vrf_policy_label
,
3040 vnc_vrf_policy_label_cmd
,
3041 "label (0-1048575)",
3042 "Default label value for VRF\n"
3043 "Label Value <0-1048575>\n")
3045 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3048 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3050 /* make sure it's still in list */
3051 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3052 /* Not in list anymore */
3053 vty_out(vty
, "Current NVE group no longer exists\n");
3054 return CMD_WARNING_CONFIG_FAILED
;
3057 label
= strtoul(argv
[1]->arg
, NULL
, 10);
3059 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3060 vnc_redistribute_prechange(bgp
);
3065 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3066 vnc_redistribute_postchange(bgp
);
3071 DEFUN (vnc_vrf_policy_no_label
,
3072 vnc_vrf_policy_no_label_cmd
,
3075 "Remove VRF default label\n")
3077 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3078 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3080 /* make sure it's still in list */
3081 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3082 /* Not in list anymore */
3083 vty_out(vty
, "Current VRF group no longer exists\n");
3084 return CMD_WARNING_CONFIG_FAILED
;
3087 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3088 vnc_redistribute_prechange(bgp
);
3091 rfg
->label
= MPLS_LABEL_NONE
;
3093 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3094 vnc_redistribute_postchange(bgp
);
3099 DEFUN (vnc_vrf_policy_nexthop
,
3100 vnc_vrf_policy_nexthop_cmd
,
3101 "nexthop <A.B.C.D|X:X::X:X|self>",
3102 "Specify next hop to use for VRF advertised prefixes\n"
3105 "Use configured router-id (default)\n")
3107 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3110 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3112 /* make sure it's still in list */
3113 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3114 /* Not in list anymore */
3115 vty_out(vty
, "Current VRF no longer exists\n");
3116 return CMD_WARNING_CONFIG_FAILED
;
3119 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3120 vnc_redistribute_prechange(bgp
);
3123 if (!str2prefix(argv
[1]->arg
, &p
) && p
.family
) {
3124 // vty_out (vty, "Nexthop set to self\n");
3125 SET_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
);
3126 memset(&rfg
->vn_prefix
, 0, sizeof(struct prefix
));
3128 UNSET_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
);
3133 /* TBD handle router-id/ nexthop changes when have advertised prefixes
3136 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3137 vnc_redistribute_postchange(bgp
);
3143 /* The RT code should be refactored/simplified with above... */
3144 DEFUN (vnc_vrf_policy_rt_import
,
3145 vnc_vrf_policy_rt_import_cmd
,
3146 "rt import RTLIST...",
3147 "Specify route targets\n"
3149 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3151 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3152 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3154 struct listnode
*node
;
3155 struct rfapi_rfg_name
*rfgn
;
3156 int is_export_bgp
= 0;
3157 int is_export_zebra
= 0;
3159 /* make sure it's still in list */
3160 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3161 /* Not in list anymore */
3162 vty_out(vty
, "Current NVE group no longer exists\n");
3163 return CMD_WARNING_CONFIG_FAILED
;
3166 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
3167 if (rc
!= CMD_SUCCESS
)
3170 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
3173 if (rfgn
->rfg
== rfg
) {
3180 vnc_direct_bgp_del_group(bgp
, rfg
);
3182 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
3185 if (rfgn
->rfg
== rfg
) {
3186 is_export_zebra
= 1;
3191 if (is_export_zebra
)
3192 vnc_zebra_del_group(bgp
, rfg
);
3195 * stop referencing old import table, now reference new one
3197 if (rfg
->rfapi_import_table
)
3198 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
3199 rfg
->rfapi_import_table
=
3200 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
3203 vnc_direct_bgp_add_group(bgp
, rfg
);
3205 if (is_export_zebra
)
3206 vnc_zebra_add_group(bgp
, rfg
);
3211 DEFUN (vnc_vrf_policy_rt_export
,
3212 vnc_vrf_policy_rt_export_cmd
,
3213 "rt export RTLIST...",
3214 "Specify route targets\n"
3216 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3218 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3219 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3222 /* make sure it's still in list */
3223 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3224 /* Not in list anymore */
3225 vty_out(vty
, "Current NVE group no longer exists\n");
3226 return CMD_WARNING_CONFIG_FAILED
;
3229 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3230 vnc_redistribute_prechange(bgp
);
3233 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
3235 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3236 vnc_redistribute_postchange(bgp
);
3242 DEFUN (vnc_vrf_policy_rt_both
,
3243 vnc_vrf_policy_rt_both_cmd
,
3244 "rt both RTLIST...",
3245 "Specify route targets\n"
3246 "Export+import filters\n"
3247 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3249 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3250 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3252 int is_export_bgp
= 0;
3253 int is_export_zebra
= 0;
3254 struct listnode
*node
;
3255 struct rfapi_rfg_name
*rfgn
;
3257 /* make sure it's still in list */
3258 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3259 /* Not in list anymore */
3260 vty_out(vty
, "Current NVE group no longer exists\n");
3261 return CMD_WARNING_CONFIG_FAILED
;
3264 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
3265 if (rc
!= CMD_SUCCESS
)
3268 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
3271 if (rfgn
->rfg
== rfg
) {
3278 vnc_direct_bgp_del_group(bgp
, rfg
);
3280 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
3283 if (rfgn
->rfg
== rfg
) {
3284 is_export_zebra
= 1;
3289 if (is_export_zebra
) {
3290 vnc_zlog_debug_verbose("%s: is_export_zebra", __func__
);
3291 vnc_zebra_del_group(bgp
, rfg
);
3295 * stop referencing old import table, now reference new one
3297 if (rfg
->rfapi_import_table
)
3298 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
3299 rfg
->rfapi_import_table
=
3300 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
3303 vnc_direct_bgp_add_group(bgp
, rfg
);
3305 if (is_export_zebra
)
3306 vnc_zebra_add_group(bgp
, rfg
);
3308 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3309 vnc_redistribute_prechange(bgp
);
3312 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
3314 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3315 vnc_redistribute_postchange(bgp
);
3321 DEFUN (vnc_vrf_policy_rd
,
3322 vnc_vrf_policy_rd_cmd
,
3323 "rd ASN:NN_OR_IP-ADDRESS:NN",
3324 "Specify default VRF route distinguisher\n"
3325 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:nh:<number> )\n")
3328 struct prefix_rd prd
;
3329 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3330 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3332 /* make sure it's still in list */
3333 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3334 /* Not in list anymore */
3335 vty_out(vty
, "Current NVE group no longer exists\n");
3336 return CMD_WARNING_CONFIG_FAILED
;
3339 if (!strncmp(argv
[1]->arg
, "auto:nh:", 8)) {
3341 * use AF_UNIX to designate automatically-assigned RD
3342 * auto:vn:nn where nn is a 2-octet quantity
3345 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
3346 uint16_t value
= value32
& 0xffff;
3348 if (!*(argv
[1]->arg
+ 5) || *end
) {
3349 vty_out(vty
, "%% Malformed rd\n");
3350 return CMD_WARNING_CONFIG_FAILED
;
3352 if (value32
> 0xffff) {
3353 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
3355 return CMD_WARNING_CONFIG_FAILED
;
3358 memset(&prd
, 0, sizeof(prd
));
3359 prd
.family
= AF_UNIX
;
3361 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
3362 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
3363 prd
.val
[6] = (value
>> 8) & 0x0ff;
3364 prd
.val
[7] = value
& 0x0ff;
3368 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
3370 vty_out(vty
, "%% Malformed rd\n");
3371 return CMD_WARNING_CONFIG_FAILED
;
3375 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3376 vnc_redistribute_prechange(bgp
);
3381 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3382 vnc_redistribute_postchange(bgp
);
3387 DEFUN_NOSH (exit_vrf_policy
,
3388 exit_vrf_policy_cmd
,
3390 "Exit VRF policy configuration mode\n")
3392 if (vty
->node
== BGP_VRF_POLICY_NODE
) {
3393 vty
->node
= BGP_NODE
;
3398 static struct cmd_node bgp_vrf_policy_node
= {
3399 .name
= "bgp vrf policy",
3400 .node
= BGP_VRF_POLICY_NODE
,
3401 .parent_node
= BGP_NODE
,
3402 .prompt
= "%s(config-router-vrf-policy)# ",
3405 /*-------------------------------------------------------------------------
3407 *-----------------------------------------------------------------------*/
3410 DEFUN_NOSH (vnc_l2_group
,
3412 "vnc l2-group NAME",
3413 VNC_CONFIG_STR
"Configure a L2 group\n" "Group name\n")
3415 struct rfapi_l2_group_cfg
*rfg
;
3416 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3417 VNC_VTY_CONFIG_CHECK(bgp
);
3419 /* Search for name */
3420 rfg
= rfapi_l2_group_lookup_byname(bgp
, argv
[2]->arg
);
3423 rfg
= rfapi_l2_group_new();
3425 /* Error out of memory */
3426 vty_out(vty
, "Can't allocate memory for L2 group\n");
3427 return CMD_WARNING_CONFIG_FAILED
;
3429 rfg
->name
= strdup(argv
[2]->arg
);
3430 /* add to tail of list */
3431 listnode_add(bgp
->rfapi_cfg
->l2_groups
, rfg
);
3435 * XXX subsequent calls will need to make sure this item is still
3436 * in the linked list and has the same name
3438 VTY_PUSH_CONTEXT_SUB(BGP_VNC_L2_GROUP_NODE
, rfg
);
3442 static void bgp_rfapi_delete_l2_group(struct vty
*vty
, /* NULL = no output */
3444 struct rfapi_l2_group_cfg
*rfg
)
3448 if (rfg
->rt_import_list
)
3449 ecommunity_free(&rfg
->rt_import_list
);
3450 if (rfg
->rt_export_list
)
3451 ecommunity_free(&rfg
->rt_export_list
);
3453 list_delete(&rfg
->labels
);
3454 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, rfg
->rfp_cfg
);
3455 listnode_delete(bgp
->rfapi_cfg
->l2_groups
, rfg
);
3457 rfapi_l2_group_del(rfg
);
3461 bgp_rfapi_delete_named_l2_group(struct vty
*vty
, /* NULL = no output */
3463 const char *rfg_name
) /* NULL = any */
3465 struct rfapi_l2_group_cfg
*rfg
= NULL
;
3466 struct listnode
*node
, *nnode
;
3468 /* Search for name */
3470 rfg
= rfapi_l2_group_lookup_byname(bgp
, rfg_name
);
3473 vty_out(vty
, "No L2 group named \"%s\"\n",
3475 return CMD_WARNING_CONFIG_FAILED
;
3480 bgp_rfapi_delete_l2_group(vty
, bgp
, rfg
);
3481 else /* must be delete all */
3482 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->l2_groups
, node
, nnode
,
3484 bgp_rfapi_delete_l2_group(vty
, bgp
, rfg
);
3488 DEFUN (vnc_no_l2_group
,
3489 vnc_no_l2_group_cmd
,
3490 "no vnc l2-group NAME",
3493 "Configure a L2 group\n"
3496 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3498 return bgp_rfapi_delete_named_l2_group(vty
, bgp
, argv
[3]->arg
);
3502 DEFUN (vnc_l2_group_lni
,
3503 vnc_l2_group_lni_cmd
,
3504 "logical-network-id (0-4294967295)",
3505 "Specify Logical Network ID associated with group\n"
3508 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3509 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3511 /* make sure it's still in list */
3512 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3513 /* Not in list anymore */
3514 vty_out(vty
, "Current L2 group no longer exists\n");
3515 return CMD_WARNING_CONFIG_FAILED
;
3518 rfg
->logical_net_id
= strtoul(argv
[1]->arg
, NULL
, 10);
3523 DEFUN (vnc_l2_group_labels
,
3524 vnc_l2_group_labels_cmd
,
3525 "labels (0-1048575)...",
3526 "Specify label values associated with group\n"
3527 "Space separated list of label values <0-1048575>\n")
3529 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3530 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3533 /* make sure it's still in list */
3534 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3535 /* Not in list anymore */
3536 vty_out(vty
, "Current L2 group no longer exists\n");
3537 return CMD_WARNING_CONFIG_FAILED
;
3547 for (; argc
; --argc
, ++argv
) {
3549 label
= strtoul(argv
[0]->arg
, NULL
, 10);
3550 if (!listnode_lookup(ll
, (void *)(uintptr_t)label
))
3551 listnode_add(ll
, (void *)(uintptr_t)label
);
3557 DEFUN (vnc_l2_group_no_labels
,
3558 vnc_l2_group_no_labels_cmd
,
3559 "no labels (0-1048575)...",
3561 "Specify label values associated with L2 group\n"
3562 "Space separated list of label values <0-1048575>\n")
3564 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3565 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3568 /* make sure it's still in list */
3569 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3570 /* Not in list anymore */
3571 vty_out(vty
, "Current L2 group no longer exists\n");
3572 return CMD_WARNING_CONFIG_FAILED
;
3577 vty_out(vty
, "Label no longer associated with group\n");
3578 return CMD_WARNING_CONFIG_FAILED
;
3583 for (; argc
; --argc
, ++argv
) {
3585 label
= strtoul(argv
[0]->arg
, NULL
, 10);
3586 listnode_delete(ll
, (void *)(uintptr_t)label
);
3592 DEFUN (vnc_l2_group_rt
,
3593 vnc_l2_group_rt_cmd
,
3594 "rt <both|export|import> ASN:NN_OR_IP-ADDRESS:NN",
3595 "Specify route targets\n"
3596 "Export+import filters\n"
3601 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3602 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3603 int rc
= CMD_SUCCESS
;
3607 switch (argv
[1]->arg
[0]) {
3609 do_export
= 1; /* fall through */
3617 vty_out(vty
, "Unknown option, %s\n", argv
[1]->arg
);
3618 return CMD_ERR_NO_MATCH
;
3621 /* make sure it's still in list */
3622 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3623 /* Not in list anymore */
3624 vty_out(vty
, "Current L2 group no longer exists\n");
3625 return CMD_WARNING_CONFIG_FAILED
;
3629 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
3630 &rfg
->rt_import_list
);
3631 if (rc
== CMD_SUCCESS
&& do_export
)
3632 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
3633 &rfg
->rt_export_list
);
3638 static struct cmd_node bgp_vnc_l2_group_node
= {
3639 .name
= "bgp vnc l2",
3640 .node
= BGP_VNC_L2_GROUP_NODE
,
3641 .parent_node
= BGP_NODE
,
3642 .prompt
= "%s(config-router-vnc-l2-group)# ",
3645 struct rfapi_l2_group_cfg
*
3646 bgp_rfapi_get_group_by_lni_label(struct bgp
*bgp
, uint32_t logical_net_id
,
3649 struct rfapi_l2_group_cfg
*rfg
;
3650 struct listnode
*node
;
3652 if (bgp
->rfapi_cfg
->l2_groups
== NULL
) /* not the best place for this */
3655 label
= label
& 0xfffff; /* label is 20 bits! */
3657 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->l2_groups
, node
, rfg
)) {
3658 if (rfg
->logical_net_id
== logical_net_id
) {
3659 struct listnode
*lnode
;
3661 for (ALL_LIST_ELEMENTS_RO(rfg
->labels
, lnode
, data
))
3662 if (((uint32_t)((uintptr_t)data
))
3663 == label
) { /* match! */
3671 struct list
*bgp_rfapi_get_labellist_by_lni_label(struct bgp
*bgp
,
3672 uint32_t logical_net_id
,
3675 struct rfapi_l2_group_cfg
*rfg
;
3676 rfg
= bgp_rfapi_get_group_by_lni_label(bgp
, logical_net_id
, label
);
3684 bgp_rfapi_get_ecommunity_by_lni_label(struct bgp
*bgp
, uint32_t is_import
,
3685 uint32_t logical_net_id
, uint32_t label
)
3687 struct rfapi_l2_group_cfg
*rfg
;
3688 rfg
= bgp_rfapi_get_group_by_lni_label(bgp
, logical_net_id
, label
);
3691 return rfg
->rt_import_list
;
3693 return rfg
->rt_export_list
;
3698 void bgp_rfapi_cfg_init(void)
3700 install_node(&bgp_vnc_defaults_node
);
3701 install_node(&bgp_vnc_nve_group_node
);
3702 install_node(&bgp_vrf_policy_node
);
3703 install_node(&bgp_vnc_l2_group_node
);
3704 install_default(BGP_VRF_POLICY_NODE
);
3705 install_default(BGP_VNC_DEFAULTS_NODE
);
3706 install_default(BGP_VNC_NVE_GROUP_NODE
);
3707 install_default(BGP_VNC_L2_GROUP_NODE
);
3712 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3713 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3714 install_element(BGP_NODE
, &vnc_no_nve_group_cmd
);
3715 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3716 install_element(BGP_NODE
, &vnc_no_vrf_policy_cmd
);
3717 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3718 install_element(BGP_NODE
, &vnc_no_l2_group_cmd
);
3719 install_element(BGP_NODE
, &vnc_advertise_un_method_cmd
);
3720 install_element(BGP_NODE
, &vnc_export_mode_cmd
);
3722 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_import_cmd
);
3723 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_export_cmd
);
3724 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_both_cmd
);
3725 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rd_cmd
);
3726 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_l2rd_cmd
);
3727 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_no_l2rd_cmd
);
3728 install_element(BGP_VNC_DEFAULTS_NODE
,
3729 &vnc_defaults_responselifetime_cmd
);
3730 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_cmd
);
3732 install_element(BGP_NODE
, &vnc_redistribute_protocol_cmd
);
3733 install_element(BGP_NODE
, &vnc_no_redistribute_protocol_cmd
);
3734 install_element(BGP_NODE
, &vnc_redistribute_nvegroup_cmd
);
3735 install_element(BGP_NODE
, &vnc_redistribute_no_nvegroup_cmd
);
3736 install_element(BGP_NODE
, &vnc_redistribute_lifetime_cmd
);
3737 install_element(BGP_NODE
, &vnc_redistribute_rh_roo_localadmin_cmd
);
3738 install_element(BGP_NODE
, &vnc_redistribute_mode_cmd
);
3739 install_element(BGP_NODE
, &vnc_redistribute_bgp_exterior_cmd
);
3741 install_element(BGP_NODE
, &vnc_redist_bgpdirect_no_prefixlist_cmd
);
3742 install_element(BGP_NODE
, &vnc_redist_bgpdirect_prefixlist_cmd
);
3743 install_element(BGP_NODE
, &vnc_redist_bgpdirect_no_routemap_cmd
);
3744 install_element(BGP_NODE
, &vnc_redist_bgpdirect_routemap_cmd
);
3746 install_element(BGP_VNC_NVE_GROUP_NODE
,
3747 &vnc_nve_group_redist_bgpdirect_no_prefixlist_cmd
);
3748 install_element(BGP_VNC_NVE_GROUP_NODE
,
3749 &vnc_nve_group_redist_bgpdirect_prefixlist_cmd
);
3750 install_element(BGP_VNC_NVE_GROUP_NODE
,
3751 &vnc_nve_group_redist_bgpdirect_no_routemap_cmd
);
3752 install_element(BGP_VNC_NVE_GROUP_NODE
,
3753 &vnc_nve_group_redist_bgpdirect_routemap_cmd
);
3755 install_element(BGP_NODE
, &vnc_export_nvegroup_cmd
);
3756 install_element(BGP_NODE
, &vnc_no_export_nvegroup_cmd
);
3757 install_element(BGP_NODE
, &vnc_nve_export_prefixlist_cmd
);
3758 install_element(BGP_NODE
, &vnc_nve_export_routemap_cmd
);
3759 install_element(BGP_NODE
, &vnc_nve_export_no_prefixlist_cmd
);
3760 install_element(BGP_NODE
, &vnc_nve_export_no_routemap_cmd
);
3762 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_l2rd_cmd
);
3763 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_no_l2rd_cmd
);
3764 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_prefix_cmd
);
3765 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_import_cmd
);
3766 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_export_cmd
);
3767 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_both_cmd
);
3768 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rd_cmd
);
3769 install_element(BGP_VNC_NVE_GROUP_NODE
,
3770 &vnc_nve_group_responselifetime_cmd
);
3771 install_element(BGP_VNC_NVE_GROUP_NODE
,
3772 &vnc_nve_group_export_prefixlist_cmd
);
3773 install_element(BGP_VNC_NVE_GROUP_NODE
,
3774 &vnc_nve_group_export_routemap_cmd
);
3775 install_element(BGP_VNC_NVE_GROUP_NODE
,
3776 &vnc_nve_group_export_no_prefixlist_cmd
);
3777 install_element(BGP_VNC_NVE_GROUP_NODE
,
3778 &vnc_nve_group_export_no_routemap_cmd
);
3779 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_cmd
);
3781 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_label_cmd
);
3782 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_no_label_cmd
);
3783 // Reenable to support VRF controller use case and testing
3784 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_nexthop_cmd
);
3785 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_import_cmd
);
3786 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_export_cmd
);
3787 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_both_cmd
);
3788 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rd_cmd
);
3789 install_element(BGP_VRF_POLICY_NODE
,
3790 &vnc_vrf_policy_export_prefixlist_cmd
);
3791 install_element(BGP_VRF_POLICY_NODE
,
3792 &vnc_vrf_policy_export_routemap_cmd
);
3793 install_element(BGP_VRF_POLICY_NODE
,
3794 &vnc_vrf_policy_export_no_prefixlist_cmd
);
3795 install_element(BGP_VRF_POLICY_NODE
,
3796 &vnc_vrf_policy_export_no_routemap_cmd
);
3797 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
3799 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_lni_cmd
);
3800 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_labels_cmd
);
3801 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_no_labels_cmd
);
3802 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_rt_cmd
);
3803 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_cmd
);
3806 struct rfapi_cfg
*bgp_rfapi_cfg_new(struct rfapi_rfp_cfg
*cfg
)
3808 struct rfapi_cfg
*h
;
3811 h
= XCALLOC(MTYPE_RFAPI_CFG
, sizeof(struct rfapi_cfg
));
3814 h
->nve_groups_sequential
= list_new();
3815 assert(h
->nve_groups_sequential
);
3816 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
3817 h
->nve_groups_vn
[afi
] = agg_table_init();
3818 h
->nve_groups_un
[afi
] = agg_table_init();
3820 h
->default_response_lifetime
=
3821 BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT
;
3822 h
->rfg_export_direct_bgp_l
= list_new();
3823 h
->rfg_export_zebra_l
= list_new();
3824 h
->resolve_nve_roo_local_admin
=
3825 BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT
;
3827 SET_FLAG(h
->flags
, BGP_VNC_CONFIG_FLAGS_DEFAULT
);
3830 h
->rfp_cfg
.download_type
= RFAPI_RFP_DOWNLOAD_PARTIAL
;
3831 h
->rfp_cfg
.ftd_advertisement_interval
=
3832 RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL
;
3833 h
->rfp_cfg
.holddown_factor
=
3834 RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR
;
3835 h
->rfp_cfg
.use_updated_response
= 0;
3836 h
->rfp_cfg
.use_removes
= 0;
3838 h
->rfp_cfg
.download_type
= cfg
->download_type
;
3839 h
->rfp_cfg
.ftd_advertisement_interval
=
3840 cfg
->ftd_advertisement_interval
;
3841 h
->rfp_cfg
.holddown_factor
= cfg
->holddown_factor
;
3842 h
->rfp_cfg
.use_updated_response
= cfg
->use_updated_response
;
3843 h
->rfp_cfg
.use_removes
= cfg
->use_removes
;
3844 if (cfg
->use_updated_response
)
3845 h
->flags
&= ~BGP_VNC_CONFIG_CALLBACK_DISABLE
;
3847 h
->flags
|= BGP_VNC_CONFIG_CALLBACK_DISABLE
;
3848 if (cfg
->use_removes
)
3849 h
->flags
&= ~BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE
;
3851 h
->flags
|= BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE
;
3856 void bgp_rfapi_cfg_destroy(struct bgp
*bgp
, struct rfapi_cfg
*h
)
3862 bgp_rfapi_delete_named_nve_group(NULL
, bgp
, NULL
, RFAPI_GROUP_CFG_MAX
);
3863 bgp_rfapi_delete_named_l2_group(NULL
, bgp
, NULL
);
3864 if (h
->l2_groups
!= NULL
)
3865 list_delete(&h
->l2_groups
);
3866 list_delete(&h
->nve_groups_sequential
);
3867 list_delete(&h
->rfg_export_direct_bgp_l
);
3868 list_delete(&h
->rfg_export_zebra_l
);
3869 if (h
->default_rt_export_list
)
3870 ecommunity_free(&h
->default_rt_export_list
);
3871 if (h
->default_rt_import_list
)
3872 ecommunity_free(&h
->default_rt_import_list
);
3873 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, h
->default_rfp_cfg
);
3874 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
3875 agg_table_finish(h
->nve_groups_vn
[afi
]);
3876 agg_table_finish(h
->nve_groups_un
[afi
]);
3878 XFREE(MTYPE_RFAPI_CFG
, h
);
3881 int bgp_rfapi_cfg_write(struct vty
*vty
, struct bgp
*bgp
)
3883 struct listnode
*node
, *nnode
;
3884 struct rfapi_nve_group_cfg
*rfg
;
3885 struct rfapi_cfg
*hc
= bgp
->rfapi_cfg
;
3886 struct rfapi_rfg_name
*rfgn
;
3890 if (bgp
->rfapi
== NULL
|| hc
== NULL
)
3893 vty_out(vty
, "!\n");
3894 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
, rfg
))
3895 if (rfg
->type
== RFAPI_GROUP_CFG_VRF
) {
3897 vty_out(vty
, " vrf-policy %s\n", rfg
->name
);
3898 if (rfg
->label
<= MPLS_LABEL_MAX
) {
3899 vty_out(vty
, " label %u\n", rfg
->label
);
3901 if (CHECK_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
)) {
3902 vty_out(vty
, " nexthop self\n");
3905 if (rfg
->vn_prefix
.family
) {
3907 buf
[0] = buf
[BUFSIZ
- 1] = 0;
3908 inet_ntop(rfg
->vn_prefix
.family
,
3909 &rfg
->vn_prefix
.u
.prefix
, buf
,
3911 if (!buf
[0] || buf
[BUFSIZ
- 1]) {
3912 // vty_out (vty, "nexthop
3915 vty_out(vty
, " nexthop %s\n",
3921 if (rfg
->rd
.prefixlen
) {
3922 char buf
[RD_ADDRSTRLEN
];
3924 if (AF_UNIX
== rfg
->rd
.family
) {
3928 value
= ((rfg
->rd
.val
[6] << 8)
3930 | (rfg
->rd
.val
[7] & 0x0ff);
3932 vty_out(vty
, " rd auto:nh:%d\n",
3936 vty_out(vty
, " rd %s\n",
3937 prefix_rd2str(&rfg
->rd
, buf
,
3941 if (rfg
->rt_import_list
&& rfg
->rt_export_list
3942 && ecommunity_cmp(rfg
->rt_import_list
,
3943 rfg
->rt_export_list
)) {
3944 char *b
= ecommunity_ecom2str(
3945 rfg
->rt_import_list
,
3946 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3947 ECOMMUNITY_ROUTE_TARGET
);
3948 vty_out(vty
, " rt both %s\n", b
);
3949 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3951 if (rfg
->rt_import_list
) {
3952 char *b
= ecommunity_ecom2str(
3953 rfg
->rt_import_list
,
3954 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3955 ECOMMUNITY_ROUTE_TARGET
);
3956 vty_out(vty
, " rt import %s\n", b
);
3957 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3959 if (rfg
->rt_export_list
) {
3960 char *b
= ecommunity_ecom2str(
3961 rfg
->rt_export_list
,
3962 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3963 ECOMMUNITY_ROUTE_TARGET
);
3964 vty_out(vty
, " rt export %s\n", b
);
3965 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3970 * route filtering: prefix-lists and route-maps
3972 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
3974 const char *afistr
=
3975 (afi
== AFI_IP
) ? "ipv4" : "ipv6";
3977 if (rfg
->plist_export_bgp_name
[afi
]) {
3979 " export %s%s prefix-list %s\n",
3980 (rfg
->type
== RFAPI_GROUP_CFG_VRF
3984 rfg
->plist_export_bgp_name
3987 if (rfg
->plist_export_zebra_name
[afi
]) {
3989 " export %s%s prefix-list %s\n",
3990 (rfg
->type
== RFAPI_GROUP_CFG_VRF
3994 rfg
->plist_export_zebra_name
3998 * currently we only support redist plists for
4000 * If we later add plist support for
4001 * redistributing other
4002 * protocols, we'll need to loop over protocols
4005 if (rfg
->plist_redist_name
4006 [ZEBRA_ROUTE_BGP_DIRECT
][afi
]) {
4008 " redistribute bgp-direct %s prefix-list %s\n",
4010 rfg
->plist_redist_name
4011 [ZEBRA_ROUTE_BGP_DIRECT
]
4014 if (rfg
->plist_redist_name
4015 [ZEBRA_ROUTE_BGP_DIRECT_EXT
][afi
]) {
4017 " redistribute bgp-direct-to-nve-groups %s prefix-list %s\n",
4019 rfg
->plist_redist_name
4020 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4025 if (rfg
->routemap_export_bgp_name
) {
4026 vty_out(vty
, " export %sroute-map %s\n",
4027 (rfg
->type
== RFAPI_GROUP_CFG_VRF
4030 rfg
->routemap_export_bgp_name
);
4032 if (rfg
->routemap_export_zebra_name
) {
4033 vty_out(vty
, " export %sroute-map %s\n",
4034 (rfg
->type
== RFAPI_GROUP_CFG_VRF
4037 rfg
->routemap_export_zebra_name
);
4039 if (rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]) {
4041 " redistribute bgp-direct route-map %s\n",
4042 rfg
->routemap_redist_name
4043 [ZEBRA_ROUTE_BGP_DIRECT
]);
4045 if (rfg
->routemap_redist_name
4046 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]) {
4048 " redistribute bgp-direct-to-nve-groups route-map %s\n",
4049 rfg
->routemap_redist_name
4050 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]);
4052 vty_out(vty
, " exit-vrf-policy\n");
4053 vty_out(vty
, "!\n");
4055 if (hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
) {
4056 vty_out(vty
, " vnc advertise-un-method encap-safi\n");
4060 { /* was based on listen ports */
4061 /* for now allow both old and new */
4062 if (bgp
->rfapi
->rfp_methods
.cfg_cb
)
4063 write
+= (bgp
->rfapi
->rfp_methods
.cfg_cb
)(
4064 vty
, bgp
->rfapi
->rfp
);
4067 vty_out(vty
, "!\n");
4069 if (hc
->l2_groups
) {
4070 struct rfapi_l2_group_cfg
*rfgc
= NULL
;
4071 struct listnode
*gnode
;
4072 for (ALL_LIST_ELEMENTS_RO(hc
->l2_groups
, gnode
, rfgc
)) {
4073 struct listnode
*lnode
;
4076 vty_out(vty
, " vnc l2-group %s\n", rfgc
->name
);
4077 if (rfgc
->logical_net_id
!= 0)
4079 " logical-network-id %u\n",
4080 rfgc
->logical_net_id
);
4081 if (rfgc
->labels
!= NULL
4082 && listhead(rfgc
->labels
) != NULL
) {
4083 vty_out(vty
, " labels ");
4084 for (ALL_LIST_ELEMENTS_RO(rfgc
->labels
,
4087 vty_out(vty
, "%hu ",
4095 if (rfgc
->rt_import_list
&& rfgc
->rt_export_list
4096 && ecommunity_cmp(rfgc
->rt_import_list
,
4097 rfgc
->rt_export_list
)) {
4098 char *b
= ecommunity_ecom2str(
4099 rfgc
->rt_import_list
,
4100 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4101 ECOMMUNITY_ROUTE_TARGET
);
4102 vty_out(vty
, " rt both %s\n", b
);
4103 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4105 if (rfgc
->rt_import_list
) {
4106 char *b
= ecommunity_ecom2str(
4107 rfgc
->rt_import_list
,
4108 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4109 ECOMMUNITY_ROUTE_TARGET
);
4110 vty_out(vty
, " rt import %s\n",
4112 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4114 if (rfgc
->rt_export_list
) {
4115 char *b
= ecommunity_ecom2str(
4116 rfgc
->rt_export_list
,
4117 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4118 ECOMMUNITY_ROUTE_TARGET
);
4119 vty_out(vty
, " rt export %s\n",
4121 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4124 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4125 write
+= (bgp
->rfapi
->rfp_methods
4127 vty
, bgp
->rfapi
->rfp
,
4128 RFAPI_RFP_CFG_GROUP_L2
,
4129 rfgc
->name
, rfgc
->rfp_cfg
);
4130 vty_out(vty
, " exit-vnc\n");
4131 vty_out(vty
, "!\n");
4135 if (hc
->default_rd
.prefixlen
4136 || hc
->default_response_lifetime
4137 != BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT
4138 || hc
->default_rt_import_list
|| hc
->default_rt_export_list
4139 || hc
->nve_groups_sequential
->count
) {
4143 vty_out(vty
, " vnc defaults\n");
4145 if (hc
->default_rd
.prefixlen
) {
4146 char buf
[RD_ADDRSTRLEN
];
4148 if (AF_UNIX
== hc
->default_rd
.family
) {
4151 value
= ((hc
->default_rd
.val
[6] << 8)
4153 | (hc
->default_rd
.val
[7]
4156 vty_out(vty
, " rd auto:vn:%d\n",
4160 vty_out(vty
, " rd %s\n",
4161 prefix_rd2str(&hc
->default_rd
,
4165 if (hc
->default_response_lifetime
4166 != BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT
) {
4167 vty_out(vty
, " response-lifetime ");
4168 if (hc
->default_response_lifetime
!= UINT32_MAX
)
4170 hc
->default_response_lifetime
);
4172 vty_out(vty
, "infinite");
4175 if (hc
->default_rt_import_list
4176 && hc
->default_rt_export_list
4177 && ecommunity_cmp(hc
->default_rt_import_list
,
4178 hc
->default_rt_export_list
)) {
4179 char *b
= ecommunity_ecom2str(
4180 hc
->default_rt_import_list
,
4181 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4182 ECOMMUNITY_ROUTE_TARGET
);
4183 vty_out(vty
, " rt both %s\n", b
);
4184 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4186 if (hc
->default_rt_import_list
) {
4187 char *b
= ecommunity_ecom2str(
4188 hc
->default_rt_import_list
,
4189 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4190 ECOMMUNITY_ROUTE_TARGET
);
4191 vty_out(vty
, " rt import %s\n", b
);
4192 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4194 if (hc
->default_rt_export_list
) {
4195 char *b
= ecommunity_ecom2str(
4196 hc
->default_rt_export_list
,
4197 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4198 ECOMMUNITY_ROUTE_TARGET
);
4199 vty_out(vty
, " rt export %s\n", b
);
4200 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4203 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4204 write
+= (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)(
4205 vty
, bgp
->rfapi
->rfp
,
4206 RFAPI_RFP_CFG_GROUP_DEFAULT
, NULL
,
4207 bgp
->rfapi_cfg
->default_rfp_cfg
);
4208 vty_out(vty
, " exit-vnc\n");
4209 vty_out(vty
, "!\n");
4212 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
,
4214 if (rfg
->type
== RFAPI_GROUP_CFG_NVE
) {
4216 vty_out(vty
, " vnc nve-group %s\n", rfg
->name
);
4218 if (rfg
->vn_prefix
.family
&& rfg
->vn_node
) {
4219 char buf
[PREFIX_STRLEN
];
4221 prefix2str(&rfg
->vn_prefix
, buf
,
4223 vty_out(vty
, " prefix %s %s\n", "vn",
4227 if (rfg
->un_prefix
.family
&& rfg
->un_node
) {
4228 char buf
[PREFIX_STRLEN
];
4230 prefix2str(&rfg
->un_prefix
, buf
,
4232 vty_out(vty
, " prefix %s %s\n", "un",
4237 if (rfg
->rd
.prefixlen
) {
4238 char buf
[RD_ADDRSTRLEN
];
4240 if (AF_UNIX
== rfg
->rd
.family
) {
4244 value
= ((rfg
->rd
.val
[6] << 8)
4254 vty_out(vty
, " rd %s\n",
4259 if (rfg
->flags
& RFAPI_RFG_RESPONSE_LIFETIME
) {
4260 vty_out(vty
, " response-lifetime ");
4261 if (rfg
->response_lifetime
4264 rfg
->response_lifetime
);
4266 vty_out(vty
, "infinite");
4270 if (rfg
->rt_import_list
&& rfg
->rt_export_list
4271 && ecommunity_cmp(rfg
->rt_import_list
,
4272 rfg
->rt_export_list
)) {
4273 char *b
= ecommunity_ecom2str(
4274 rfg
->rt_import_list
,
4275 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4276 ECOMMUNITY_ROUTE_TARGET
);
4277 vty_out(vty
, " rt both %s\n", b
);
4278 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4280 if (rfg
->rt_import_list
) {
4281 char *b
= ecommunity_ecom2str(
4282 rfg
->rt_import_list
,
4283 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4284 ECOMMUNITY_ROUTE_TARGET
);
4285 vty_out(vty
, " rt import %s\n",
4287 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4289 if (rfg
->rt_export_list
) {
4290 char *b
= ecommunity_ecom2str(
4291 rfg
->rt_export_list
,
4292 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4293 ECOMMUNITY_ROUTE_TARGET
);
4294 vty_out(vty
, " rt export %s\n",
4296 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4301 * route filtering: prefix-lists and route-maps
4303 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4305 const char *afistr
= (afi
== AFI_IP
)
4309 if (rfg
->plist_export_bgp_name
[afi
]) {
4311 " export bgp %s prefix-list %s\n",
4313 rfg
->plist_export_bgp_name
4316 if (rfg
->plist_export_zebra_name
[afi
]) {
4318 " export zebra %s prefix-list %s\n",
4320 rfg
->plist_export_zebra_name
4324 * currently we only support redist
4325 * plists for bgp-direct.
4326 * If we later add plist support for
4327 * redistributing other
4328 * protocols, we'll need to loop over
4331 if (rfg
->plist_redist_name
4332 [ZEBRA_ROUTE_BGP_DIRECT
]
4335 " redistribute bgp-direct %s prefix-list %s\n",
4337 rfg
->plist_redist_name
4338 [ZEBRA_ROUTE_BGP_DIRECT
]
4341 if (rfg
->plist_redist_name
4342 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4345 " redistribute bgp-direct-to-nve-groups %s prefix-list %s\n",
4347 rfg
->plist_redist_name
4348 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4353 if (rfg
->routemap_export_bgp_name
) {
4355 " export bgp route-map %s\n",
4356 rfg
->routemap_export_bgp_name
);
4358 if (rfg
->routemap_export_zebra_name
) {
4360 " export zebra route-map %s\n",
4361 rfg
->routemap_export_zebra_name
);
4363 if (rfg
->routemap_redist_name
4364 [ZEBRA_ROUTE_BGP_DIRECT
]) {
4366 " redistribute bgp-direct route-map %s\n",
4367 rfg
->routemap_redist_name
4368 [ZEBRA_ROUTE_BGP_DIRECT
]);
4370 if (rfg
->routemap_redist_name
4371 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]) {
4373 " redistribute bgp-direct-to-nve-groups route-map %s\n",
4374 rfg
->routemap_redist_name
4375 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]);
4377 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4378 write
+= (bgp
->rfapi
->rfp_methods
4380 vty
, bgp
->rfapi
->rfp
,
4381 RFAPI_RFP_CFG_GROUP_NVE
,
4382 rfg
->name
, rfg
->rfp_cfg
);
4383 vty_out(vty
, " exit-vnc\n");
4384 vty_out(vty
, "!\n");
4386 } /* have listen ports */
4389 * route export to other protocols
4391 if (VNC_EXPORT_BGP_GRP_ENABLED(hc
)) {
4392 vty_out(vty
, " vnc export bgp mode group-nve\n");
4393 } else if (VNC_EXPORT_BGP_RH_ENABLED(hc
)) {
4394 vty_out(vty
, " vnc export bgp mode registering-nve\n");
4395 } else if (VNC_EXPORT_BGP_CE_ENABLED(hc
)) {
4396 vty_out(vty
, " vnc export bgp mode ce\n");
4399 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(hc
)) {
4400 vty_out(vty
, " vnc export zebra mode group-nve\n");
4401 } else if (VNC_EXPORT_ZEBRA_RH_ENABLED(hc
)) {
4402 vty_out(vty
, " vnc export zebra mode registering-nve\n");
4405 if (hc
->rfg_export_direct_bgp_l
) {
4406 for (ALL_LIST_ELEMENTS(hc
->rfg_export_direct_bgp_l
, node
, nnode
,
4409 vty_out(vty
, " vnc export bgp group-nve group %s\n",
4414 if (hc
->rfg_export_zebra_l
) {
4415 for (ALL_LIST_ELEMENTS(hc
->rfg_export_zebra_l
, node
, nnode
,
4418 vty_out(vty
, " vnc export zebra group-nve group %s\n",
4424 if (hc
->rfg_redist_name
) {
4425 vty_out(vty
, " vnc redistribute nve-group %s\n",
4426 hc
->rfg_redist_name
);
4428 if (hc
->redist_lifetime
) {
4429 vty_out(vty
, " vnc redistribute lifetime %d\n",
4430 hc
->redist_lifetime
);
4432 if (hc
->resolve_nve_roo_local_admin
4433 != BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT
) {
4436 " vnc redistribute resolve-nve roo-ec-local-admin %d\n",
4437 hc
->resolve_nve_roo_local_admin
);
4440 if (hc
->redist_mode
) /* ! default */
4444 switch (hc
->redist_mode
) {
4445 case VNC_REDIST_MODE_PLAIN
:
4448 case VNC_REDIST_MODE_RFG
:
4451 case VNC_REDIST_MODE_RESOLVE_NVE
:
4456 vty_out(vty
, " vnc redistribute mode %s\n", s
);
4461 * route filtering: prefix-lists and route-maps
4463 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4465 const char *afistr
= (afi
== AFI_IP
) ? "ipv4" : "ipv6";
4467 if (hc
->plist_export_bgp_name
[afi
]) {
4468 vty_out(vty
, " vnc export bgp %s prefix-list %s\n",
4469 afistr
, hc
->plist_export_bgp_name
[afi
]);
4471 if (hc
->plist_export_zebra_name
[afi
]) {
4472 vty_out(vty
, " vnc export zebra %s prefix-list %s\n",
4473 afistr
, hc
->plist_export_zebra_name
[afi
]);
4475 if (hc
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
]) {
4477 " vnc redistribute bgp-direct %s prefix-list %s\n",
4479 hc
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]
4484 if (hc
->routemap_export_bgp_name
) {
4485 vty_out(vty
, " vnc export bgp route-map %s\n",
4486 hc
->routemap_export_bgp_name
);
4488 if (hc
->routemap_export_zebra_name
) {
4489 vty_out(vty
, " vnc export zebra route-map %s\n",
4490 hc
->routemap_export_zebra_name
);
4492 if (hc
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]) {
4493 vty_out(vty
, " vnc redistribute bgp-direct route-map %s\n",
4494 hc
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]);
4497 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4498 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
4499 if (hc
->redist
[afi
][type
]) {
4500 if (type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
4501 && hc
->redist_bgp_exterior_view_name
) {
4503 " vnc redistribute %s %s view %s\n",
4504 ((afi
== AFI_IP
) ? "ipv4"
4506 zebra_route_string(type
),
4507 hc
->redist_bgp_exterior_view_name
);
4510 " vnc redistribute %s %s\n",
4511 ((afi
== AFI_IP
) ? "ipv4"
4513 zebra_route_string(type
));
4521 void bgp_rfapi_show_summary(struct bgp
*bgp
, struct vty
*vty
)
4523 struct rfapi_cfg
*hc
= bgp
->rfapi_cfg
;
4525 int type
, redist
= 0;
4530 vty_out(vty
, "%-39s %-19s %s\n", "VNC Advertise method:",
4531 (hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
4532 ? "Encapsulation SAFI"
4533 : "Tunnel Encap attribute"),
4534 ((hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
)
4535 == (BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
4536 & BGP_VNC_CONFIG_FLAGS_DEFAULT
)
4540 vty_out(vty
, "%-39s ", "Export from VNC:");
4542 * route export to other protocols
4544 if (VNC_EXPORT_BGP_GRP_ENABLED(hc
)) {
4546 vty_out(vty
, "ToBGP Groups={");
4547 if (hc
->rfg_export_direct_bgp_l
) {
4549 struct listnode
*node
, *nnode
;
4550 struct rfapi_rfg_name
*rfgn
;
4551 for (ALL_LIST_ELEMENTS(hc
->rfg_export_direct_bgp_l
,
4552 node
, nnode
, rfgn
)) {
4556 vty_out(vty
, "%s", rfgn
->name
);
4560 } else if (VNC_EXPORT_BGP_RH_ENABLED(hc
)) {
4562 vty_out(vty
, "ToBGP {Registering NVE}");
4563 /* note filters, route-maps not shown */
4564 } else if (VNC_EXPORT_BGP_CE_ENABLED(hc
)) {
4566 vty_out(vty
, "ToBGP {NVE connected router:%d}",
4567 hc
->resolve_nve_roo_local_admin
);
4568 /* note filters, route-maps not shown */
4571 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(hc
)) {
4573 vty_out(vty
, "%sToZebra Groups={", (redist
== 1 ? "" : " "));
4574 if (hc
->rfg_export_zebra_l
) {
4576 struct listnode
*node
, *nnode
;
4577 struct rfapi_rfg_name
*rfgn
;
4578 for (ALL_LIST_ELEMENTS(hc
->rfg_export_zebra_l
, node
,
4582 vty_out(vty
, "%s", rfgn
->name
);
4586 } else if (VNC_EXPORT_ZEBRA_RH_ENABLED(hc
)) {
4588 vty_out(vty
, "%sToZebra {Registering NVE}",
4589 (redist
== 1 ? "" : " "));
4590 /* note filters, route-maps not shown */
4592 vty_out(vty
, "%-19s %s\n", (redist
? "" : "Off"),
4593 (redist
? "" : "(default)"));
4595 /* Redistribution */
4597 vty_out(vty
, "%-39s ", "Redistribution into VNC:");
4598 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4599 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
4600 if (hc
->redist
[afi
][type
]) {
4601 vty_out(vty
, "{%s,%s} ",
4602 ((afi
== AFI_IP
) ? "ipv4" : "ipv6"),
4603 zebra_route_string(type
));
4608 vty_out(vty
, "%-19s %s\n", (redist
? "" : "Off"),
4609 (redist
? "" : "(default)"));
4611 vty_out(vty
, "%-39s %3u%-16s %s\n",
4612 "RFP Registration Hold-Down Factor:",
4613 hc
->rfp_cfg
.holddown_factor
, "%",
4614 (hc
->rfp_cfg
.holddown_factor
4615 == RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR
4618 vty_out(vty
, "%-39s %-19s %s\n", "RFP Updated responses:",
4619 (hc
->rfp_cfg
.use_updated_response
== 0 ? "Off" : "On"),
4620 (hc
->rfp_cfg
.use_updated_response
== 0 ? "(default)" : ""));
4621 vty_out(vty
, "%-39s %-19s %s\n", "RFP Removal responses:",
4622 (hc
->rfp_cfg
.use_removes
== 0 ? "Off" : "On"),
4623 (hc
->rfp_cfg
.use_removes
== 0 ? "(default)" : ""));
4624 vty_out(vty
, "%-39s %-19s %s\n", "RFP Full table download:",
4625 (hc
->rfp_cfg
.download_type
== RFAPI_RFP_DOWNLOAD_FULL
? "On"
4627 (hc
->rfp_cfg
.download_type
== RFAPI_RFP_DOWNLOAD_PARTIAL
4630 snprintf(tmp
, sizeof(tmp
), "%u seconds",
4631 hc
->rfp_cfg
.ftd_advertisement_interval
);
4632 vty_out(vty
, "%-39s %-19s %s\n", " Advertisement Interval:", tmp
,
4633 (hc
->rfp_cfg
.ftd_advertisement_interval
4634 == RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL
4637 vty_out(vty
, "%-39s %d seconds\n", "Default RFP response lifetime:",
4638 hc
->default_response_lifetime
);
4643 struct rfapi_cfg
*bgp_rfapi_get_config(struct bgp
*bgp
)
4645 struct rfapi_cfg
*hc
= NULL
;
4647 bgp
= bgp_get_default();
4649 hc
= bgp
->rfapi_cfg
;
4653 #endif /* ENABLE_BGP_VNC */