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 #if 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 #if 0 /* superseded */
2212 static void vnc_routemap_event(route_map_event_t type
, /* ignored */
2213 const char *rmap_name
) /* ignored */
2215 struct listnode
*mnode
, *mnnode
;
2218 vnc_zlog_debug_verbose("%s(event type=%d)", __func__
, type
);
2219 if (bm
->bgp
== NULL
) /* may be called during cleanup */
2222 for (ALL_LIST_ELEMENTS(bm
->bgp
, mnode
, mnnode
, bgp
))
2223 vnc_routemap_update(bgp
, rmap_name
);
2225 vnc_zlog_debug_verbose("%s: done", __func__
);
2229 /*-------------------------------------------------------------------------
2231 *-----------------------------------------------------------------------*/
2234 DEFUN_NOSH (vnc_nve_group
,
2236 "vnc nve-group NAME",
2237 VNC_CONFIG_STR
"Configure a NVE group\n" "Group name\n")
2239 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2240 struct rfapi_nve_group_cfg
*rfg
;
2241 struct listnode
*node
, *nnode
;
2242 struct rfapi_rfg_name
*rfgn
;
2244 VNC_VTY_CONFIG_CHECK(bgp
);
2246 /* Search for name */
2247 rfg
= bgp_rfapi_cfg_match_byname(bgp
, argv
[2]->arg
,
2248 RFAPI_GROUP_CFG_NVE
);
2251 rfg
= rfapi_group_new(bgp
, RFAPI_GROUP_CFG_NVE
, argv
[2]->arg
);
2253 /* Error out of memory */
2254 vty_out(vty
, "Can't allocate memory for NVE group\n");
2255 return CMD_WARNING_CONFIG_FAILED
;
2258 /* Copy defaults from struct rfapi_cfg */
2259 rfg
->rd
= bgp
->rfapi_cfg
->default_rd
;
2260 if (bgp
->rfapi_cfg
->flags
& BGP_VNC_CONFIG_L2RD
) {
2261 rfg
->l2rd
= bgp
->rfapi_cfg
->default_l2rd
;
2262 rfg
->flags
|= RFAPI_RFG_L2RD
;
2264 rfg
->rd
= bgp
->rfapi_cfg
->default_rd
;
2265 rfg
->response_lifetime
=
2266 bgp
->rfapi_cfg
->default_response_lifetime
;
2268 if (bgp
->rfapi_cfg
->default_rt_export_list
) {
2269 rfg
->rt_export_list
= ecommunity_dup(
2270 bgp
->rfapi_cfg
->default_rt_export_list
);
2273 if (bgp
->rfapi_cfg
->default_rt_import_list
) {
2274 rfg
->rt_import_list
= ecommunity_dup(
2275 bgp
->rfapi_cfg
->default_rt_import_list
);
2276 rfg
->rfapi_import_table
= rfapiImportTableRefAdd(
2277 bgp
, rfg
->rt_import_list
, rfg
);
2281 * If a redist nve group was named but the group was not
2283 * make the linkage now
2285 if (!bgp
->rfapi_cfg
->rfg_redist
) {
2286 if (bgp
->rfapi_cfg
->rfg_redist_name
2287 && !strcmp(bgp
->rfapi_cfg
->rfg_redist_name
,
2290 vnc_redistribute_prechange(bgp
);
2291 bgp
->rfapi_cfg
->rfg_redist
= rfg
;
2292 vnc_redistribute_postchange(bgp
);
2297 * Same treatment for bgp-direct export group
2299 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
,
2300 node
, nnode
, rfgn
)) {
2302 if (!strcmp(rfgn
->name
, rfg
->name
)) {
2304 vnc_direct_bgp_add_group(bgp
, rfg
);
2310 * Same treatment for zebra export group
2312 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2315 vnc_zlog_debug_verbose(
2316 "%s: ezport zebra: checking if \"%s\" == \"%s\"",
2317 __func__
, rfgn
->name
, rfg
->name
);
2318 if (!strcmp(rfgn
->name
, rfg
->name
)) {
2320 vnc_zebra_add_group(bgp
, rfg
);
2327 * XXX subsequent calls will need to make sure this item is still
2328 * in the linked list and has the same name
2330 VTY_PUSH_CONTEXT_SUB(BGP_VNC_NVE_GROUP_NODE
, rfg
);
2335 static void bgp_rfapi_delete_nve_group(struct vty
*vty
, /* NULL = no output */
2337 struct rfapi_nve_group_cfg
*rfg
)
2339 struct list
*orphaned_nves
= NULL
;
2340 struct listnode
*node
, *nnode
;
2343 * If there are currently-open NVEs that belong to this group,
2344 * zero out their references to this group structure.
2347 struct rfapi_descriptor
*rfd
;
2348 orphaned_nves
= list_new();
2349 while ((rfd
= listnode_head(rfg
->nves
))) {
2351 listnode_delete(rfg
->nves
, rfd
);
2352 listnode_add(orphaned_nves
, rfd
);
2354 list_delete(&rfg
->nves
);
2359 if (rfg
->rfapi_import_table
)
2360 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2361 if (rfg
->rt_import_list
)
2362 ecommunity_free(&rfg
->rt_import_list
);
2363 if (rfg
->rt_export_list
)
2364 ecommunity_free(&rfg
->rt_export_list
);
2367 rfg
->vn_node
->info
= NULL
;
2368 agg_unlock_node(rfg
->vn_node
); /* frees */
2371 rfg
->un_node
->info
= NULL
;
2372 agg_unlock_node(rfg
->un_node
); /* frees */
2375 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, rfg
->rfp_cfg
);
2376 listnode_delete(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
);
2379 XFREE(MTYPE_RFAPI_GROUP_CFG
, rfg
);
2382 * Attempt to reassign the orphaned nves to a new group. If
2383 * a NVE can not be reassigned, its rfd->rfg will remain NULL
2384 * and it will become a zombie until released by rfapi_close().
2386 if (orphaned_nves
) {
2387 struct rfapi_descriptor
*rfd
;
2389 for (ALL_LIST_ELEMENTS(orphaned_nves
, node
, nnode
, rfd
)) {
2391 * 1. rfapi_close() equivalent except:
2392 * a. don't free original descriptor
2393 * b. remember query list
2394 * c. remember advertised route list
2395 * 2. rfapi_open() equivalent except:
2396 * a. reuse original descriptor
2397 * 3. rfapi_register() on remembered advertised route
2399 * 4. rfapi_query on rememebred query list
2404 rc
= rfapi_reopen(rfd
, bgp
);
2407 list_delete_node(orphaned_nves
, node
);
2410 "WARNING: reassigned NVE vn=");
2411 rfapiPrintRfapiIpAddr(vty
, &rfd
->vn_addr
);
2413 vty_out(vty
, " un=");
2414 rfapiPrintRfapiIpAddr(vty
, &rfd
->un_addr
);
2416 vty_out(vty
, " to new group \"%s\"\n",
2421 for (ALL_LIST_ELEMENTS_RO(orphaned_nves
, node
, rfd
)) {
2423 vty_out(vty
, "WARNING: orphaned NVE vn=");
2424 rfapiPrintRfapiIpAddr(vty
, &rfd
->vn_addr
);
2426 vty_out(vty
, " un=");
2427 rfapiPrintRfapiIpAddr(vty
, &rfd
->un_addr
);
2431 list_delete(&orphaned_nves
);
2436 bgp_rfapi_delete_named_nve_group(struct vty
*vty
, /* NULL = no output */
2438 const char *rfg_name
, /* NULL = any */
2439 rfapi_group_cfg_type_t type
) /* _MAX = any */
2441 struct rfapi_nve_group_cfg
*rfg
= NULL
;
2442 struct listnode
*node
, *nnode
;
2443 struct rfapi_rfg_name
*rfgn
;
2445 /* Search for name */
2447 rfg
= bgp_rfapi_cfg_match_byname(bgp
, rfg_name
, type
);
2450 vty_out(vty
, "No NVE group named \"%s\"\n",
2452 return CMD_WARNING_CONFIG_FAILED
;
2457 * If this group is the redist nve group, unlink it
2459 if (rfg_name
== NULL
|| bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2460 vnc_redistribute_prechange(bgp
);
2461 bgp
->rfapi_cfg
->rfg_redist
= NULL
;
2462 vnc_redistribute_postchange(bgp
);
2467 * remove reference from bgp direct export list
2469 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2471 if (rfgn
->rfg
== rfg
) {
2473 /* remove exported routes from this group */
2474 vnc_direct_bgp_del_group(bgp
, rfg
);
2480 * remove reference from zebra export list
2482 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2484 if (rfgn
->rfg
== rfg
) {
2486 /* remove exported routes from this group */
2487 vnc_zebra_del_group(bgp
, rfg
);
2493 clear_vnc_vrf_closer(rfg
);
2494 bgp_rfapi_delete_nve_group(vty
, bgp
, rfg
);
2495 } else /* must be delete all */
2496 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->nve_groups_sequential
,
2497 node
, nnode
, rfg
)) {
2499 clear_vnc_vrf_closer(rfg
);
2500 bgp_rfapi_delete_nve_group(vty
, bgp
, rfg
);
2505 DEFUN (vnc_no_nve_group
,
2506 vnc_no_nve_group_cmd
,
2507 "no vnc nve-group NAME",
2510 "Configure a NVE group\n"
2513 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2515 return bgp_rfapi_delete_named_nve_group(vty
, bgp
, argv
[3]->arg
,
2516 RFAPI_GROUP_CFG_NVE
);
2519 DEFUN (vnc_nve_group_prefix
,
2520 vnc_nve_group_prefix_cmd
,
2521 "prefix <vn|un> <A.B.C.D/M|X:X::X:X/M>",
2522 "Specify prefixes matching NVE VN or UN interfaces\n"
2528 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2529 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2532 struct agg_table
*rt
;
2533 struct agg_node
*rn
;
2534 int is_un_prefix
= 0;
2536 /* make sure it's still in list */
2537 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2538 /* Not in list anymore */
2539 vty_out(vty
, "Current NVE group no longer exists\n");
2540 return CMD_WARNING_CONFIG_FAILED
;
2543 if (!str2prefix(argv
[2]->arg
, &p
)) {
2544 vty_out(vty
, "Malformed prefix \"%s\"\n", argv
[2]->arg
);
2545 return CMD_WARNING_CONFIG_FAILED
;
2548 afi
= family2afi(p
.family
);
2550 vty_out(vty
, "Unsupported address family\n");
2551 return CMD_WARNING_CONFIG_FAILED
;
2554 if (argv
[1]->arg
[0] == 'u') {
2555 rt
= bgp
->rfapi_cfg
->nve_groups_un
[afi
];
2558 rt
= bgp
->rfapi_cfg
->nve_groups_vn
[afi
];
2561 rn
= agg_node_get(rt
, &p
); /* NB locks node */
2564 * There is already a group with this prefix
2566 agg_unlock_node(rn
);
2567 if (rn
->info
!= rfg
) {
2569 * different group name: fail
2572 "nve group \"%s\" already has \"%s\" prefix %s\n",
2573 ((struct rfapi_nve_group_cfg
*)(rn
->info
))
2575 argv
[1]->arg
, argv
[2]->arg
);
2576 return CMD_WARNING_CONFIG_FAILED
;
2579 * same group name: it's already in the correct place
2580 * in the table, so we're done.
2582 * Implies rfg->(vn|un)_prefix is already correct.
2588 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2589 vnc_redistribute_prechange(bgp
);
2592 /* New prefix, new node */
2596 /* detach rfg from previous route table location */
2598 rfg
->un_node
->info
= NULL
;
2599 agg_unlock_node(rfg
->un_node
); /* frees */
2601 rfg
->un_node
= rn
; /* back ref */
2606 /* detach rfg from previous route table location */
2608 rfg
->vn_node
->info
= NULL
;
2609 agg_unlock_node(rfg
->vn_node
); /* frees */
2611 rfg
->vn_node
= rn
; /* back ref */
2618 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2619 vnc_redistribute_postchange(bgp
);
2625 DEFUN (vnc_nve_group_rt_import
,
2626 vnc_nve_group_rt_import_cmd
,
2627 "rt import RTLIST...",
2628 "Specify route targets\n"
2630 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2632 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2633 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2635 struct listnode
*node
;
2636 struct rfapi_rfg_name
*rfgn
;
2637 int is_export_bgp
= 0;
2638 int is_export_zebra
= 0;
2640 /* make sure it's still in list */
2641 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2642 /* Not in list anymore */
2643 vty_out(vty
, "Current NVE group no longer exists\n");
2644 return CMD_WARNING_CONFIG_FAILED
;
2647 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
2648 if (rc
!= CMD_SUCCESS
)
2651 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2654 if (rfgn
->rfg
== rfg
) {
2661 vnc_direct_bgp_del_group(bgp
, rfg
);
2663 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2666 if (rfgn
->rfg
== rfg
) {
2667 is_export_zebra
= 1;
2672 if (is_export_zebra
)
2673 vnc_zebra_del_group(bgp
, rfg
);
2676 * stop referencing old import table, now reference new one
2678 if (rfg
->rfapi_import_table
)
2679 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2680 rfg
->rfapi_import_table
=
2681 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
2684 vnc_direct_bgp_add_group(bgp
, rfg
);
2686 if (is_export_zebra
)
2687 vnc_zebra_add_group(bgp
, rfg
);
2692 DEFUN (vnc_nve_group_rt_export
,
2693 vnc_nve_group_rt_export_cmd
,
2694 "rt export RTLIST...",
2695 "Specify route targets\n"
2697 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2699 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2700 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2703 /* make sure it's still in list */
2704 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2705 /* Not in list anymore */
2706 vty_out(vty
, "Current NVE group no longer exists\n");
2707 return CMD_WARNING_CONFIG_FAILED
;
2710 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2711 vnc_redistribute_prechange(bgp
);
2714 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
2716 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2717 vnc_redistribute_postchange(bgp
);
2723 DEFUN (vnc_nve_group_rt_both
,
2724 vnc_nve_group_rt_both_cmd
,
2725 "rt both RTLIST...",
2726 "Specify route targets\n"
2727 "Export+import filters\n"
2728 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2730 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2731 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2733 int is_export_bgp
= 0;
2734 int is_export_zebra
= 0;
2735 struct listnode
*node
;
2736 struct rfapi_rfg_name
*rfgn
;
2738 /* make sure it's still in list */
2739 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2740 /* Not in list anymore */
2741 vty_out(vty
, "Current NVE group no longer exists\n");
2742 return CMD_WARNING_CONFIG_FAILED
;
2745 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
2746 if (rc
!= CMD_SUCCESS
)
2749 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2752 if (rfgn
->rfg
== rfg
) {
2759 vnc_direct_bgp_del_group(bgp
, rfg
);
2761 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2764 if (rfgn
->rfg
== rfg
) {
2765 is_export_zebra
= 1;
2770 if (is_export_zebra
) {
2771 vnc_zlog_debug_verbose("%s: is_export_zebra", __func__
);
2772 vnc_zebra_del_group(bgp
, rfg
);
2776 * stop referencing old import table, now reference new one
2778 if (rfg
->rfapi_import_table
)
2779 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2780 rfg
->rfapi_import_table
=
2781 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
2784 vnc_direct_bgp_add_group(bgp
, rfg
);
2786 if (is_export_zebra
)
2787 vnc_zebra_add_group(bgp
, rfg
);
2789 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2790 vnc_redistribute_prechange(bgp
);
2793 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
2795 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2796 vnc_redistribute_postchange(bgp
);
2802 DEFUN (vnc_nve_group_l2rd
,
2803 vnc_nve_group_l2rd_cmd
,
2804 "l2rd <(1-255)|auto-vn>",
2805 "Specify default Local Nve ID value to use in RD for L2 routes\n"
2806 "Fixed value 1-255\n"
2807 "use the low-order octet of the NVE's VN address\n")
2809 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2810 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2812 /* make sure it's still in list */
2813 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2814 /* Not in list anymore */
2815 vty_out(vty
, "Current NVE group no longer exists\n");
2816 return CMD_WARNING_CONFIG_FAILED
;
2819 if (strmatch(argv
[1]->text
, "auto:vn")) {
2823 unsigned long value_l
= strtoul(argv
[1]->arg
, &end
, 10);
2824 uint8_t value
= value_l
& 0xff;
2826 if (!argv
[1]->arg
[0] || *end
) {
2827 vty_out(vty
, "%% Malformed l2 nve ID \"%s\"\n",
2829 return CMD_WARNING_CONFIG_FAILED
;
2831 if ((value_l
< 1) || (value_l
> 0xff)) {
2833 "%% Malformed l2 nve id (must be greater than 0 and less than %u\n",
2835 return CMD_WARNING_CONFIG_FAILED
;
2840 rfg
->flags
|= RFAPI_RFG_L2RD
;
2845 DEFUN (vnc_nve_group_no_l2rd
,
2846 vnc_nve_group_no_l2rd_cmd
,
2849 "Specify default Local Nve ID value to use in RD for L2 routes\n")
2851 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2852 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2854 /* make sure it's still in list */
2855 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2856 /* Not in list anymore */
2857 vty_out(vty
, "Current NVE group no longer exists\n");
2858 return CMD_WARNING_CONFIG_FAILED
;
2862 rfg
->flags
&= ~RFAPI_RFG_L2RD
;
2867 DEFUN (vnc_nve_group_rd
,
2868 vnc_nve_group_rd_cmd
,
2869 "rd ASN:NN_OR_IP-ADDRESS:NN",
2870 "Specify route distinguisher\n"
2871 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:vn:<number> )\n")
2873 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2875 struct prefix_rd prd
;
2876 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2878 /* make sure it's still in list */
2879 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2880 /* Not in list anymore */
2881 vty_out(vty
, "Current NVE group no longer exists\n");
2882 return CMD_WARNING_CONFIG_FAILED
;
2885 if (!strncmp(argv
[1]->arg
, "auto:vn:", 8)) {
2887 * use AF_UNIX to designate automatically-assigned RD
2888 * auto:vn:nn where nn is a 2-octet quantity
2891 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
2892 uint16_t value
= value32
& 0xffff;
2894 if (!argv
[1]->arg
[8] || *end
) {
2895 vty_out(vty
, "%% Malformed rd\n");
2896 return CMD_WARNING_CONFIG_FAILED
;
2898 if (value32
> 0xffff) {
2899 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
2901 return CMD_WARNING_CONFIG_FAILED
;
2904 memset(&prd
, 0, sizeof(prd
));
2905 prd
.family
= AF_UNIX
;
2907 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
2908 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
2909 prd
.val
[6] = (value
>> 8) & 0x0ff;
2910 prd
.val
[7] = value
& 0x0ff;
2914 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
2916 vty_out(vty
, "%% Malformed rd\n");
2917 return CMD_WARNING_CONFIG_FAILED
;
2921 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2922 vnc_redistribute_prechange(bgp
);
2927 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2928 vnc_redistribute_postchange(bgp
);
2933 DEFUN (vnc_nve_group_responselifetime
,
2934 vnc_nve_group_responselifetime_cmd
,
2935 "response-lifetime <LIFETIME|infinite>",
2936 "Specify response lifetime\n"
2937 "Response lifetime in seconds\n" "Infinite response lifetime\n")
2939 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2940 unsigned int rspint
;
2941 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2942 struct rfapi_descriptor
*rfd
;
2943 struct listnode
*hdnode
;
2945 /* make sure it's still in list */
2946 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2947 /* Not in list anymore */
2948 vty_out(vty
, "Current NVE group no longer exists\n");
2949 return CMD_WARNING_CONFIG_FAILED
;
2952 if (strmatch(argv
[1]->text
, "infinite")) {
2953 rspint
= RFAPI_INFINITE_LIFETIME
;
2955 rspint
= strtoul(argv
[1]->arg
, NULL
, 10);
2958 rfg
->response_lifetime
= rspint
;
2959 rfg
->flags
|= RFAPI_RFG_RESPONSE_LIFETIME
;
2961 for (ALL_LIST_ELEMENTS_RO(rfg
->nves
, hdnode
, rfd
))
2962 rfd
->response_lifetime
= rspint
;
2967 * Sigh. This command, like exit-address-family, is a hack to deal
2968 * with the lack of rigorous level control in the command handler.
2969 * TBD fix command handler.
2971 DEFUN_NOSH (exit_vnc
,
2974 "Exit VNC configuration mode\n")
2976 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
2977 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
2978 || vty
->node
== BGP_VNC_L2_GROUP_NODE
) {
2980 vty
->node
= BGP_NODE
;
2985 static struct cmd_node bgp_vnc_defaults_node
= {
2986 BGP_VNC_DEFAULTS_NODE
, "%s(config-router-vnc-defaults)# ", 1};
2988 static struct cmd_node bgp_vnc_nve_group_node
= {
2989 BGP_VNC_NVE_GROUP_NODE
, "%s(config-router-vnc-nve-group)# ", 1};
2991 /*-------------------------------------------------------------------------
2993 * Note there are two types of NVEs, one for VPNs one for RFP NVEs
2994 *-----------------------------------------------------------------------*/
2996 DEFUN_NOSH (vnc_vrf_policy
,
2999 "Configure a VRF policy group\n"
3002 struct rfapi_nve_group_cfg
*rfg
;
3003 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3005 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_VRF
) {
3007 "Can't configure vrf-policy within a BGP VRF instance\n");
3008 return CMD_WARNING_CONFIG_FAILED
;
3011 /* Search for name */
3012 rfg
= bgp_rfapi_cfg_match_byname(bgp
, argv
[1]->arg
,
3013 RFAPI_GROUP_CFG_VRF
);
3016 rfg
= rfapi_group_new(bgp
, RFAPI_GROUP_CFG_VRF
, argv
[1]->arg
);
3018 /* Error out of memory */
3019 vty_out(vty
, "Can't allocate memory for NVE group\n");
3020 return CMD_WARNING_CONFIG_FAILED
;
3024 * XXX subsequent calls will need to make sure this item is still
3025 * in the linked list and has the same name
3027 VTY_PUSH_CONTEXT_SUB(BGP_VRF_POLICY_NODE
, rfg
);
3032 DEFUN (vnc_no_vrf_policy
,
3033 vnc_no_vrf_policy_cmd
,
3034 "no vrf-policy NAME",
3036 "Remove a VRF policy group\n"
3039 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3041 /* silently return */
3042 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_VRF
)
3045 return bgp_rfapi_delete_named_nve_group(vty
, bgp
, argv
[2]->arg
,
3046 RFAPI_GROUP_CFG_VRF
);
3049 DEFUN (vnc_vrf_policy_label
,
3050 vnc_vrf_policy_label_cmd
,
3051 "label (0-1048575)",
3052 "Default label value for VRF\n"
3053 "Label Value <0-1048575>\n")
3055 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3058 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3060 /* make sure it's still in list */
3061 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3062 /* Not in list anymore */
3063 vty_out(vty
, "Current NVE group no longer exists\n");
3064 return CMD_WARNING_CONFIG_FAILED
;
3067 label
= strtoul(argv
[1]->arg
, NULL
, 10);
3069 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3070 vnc_redistribute_prechange(bgp
);
3075 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3076 vnc_redistribute_postchange(bgp
);
3081 DEFUN (vnc_vrf_policy_no_label
,
3082 vnc_vrf_policy_no_label_cmd
,
3085 "Remove VRF default label\n")
3087 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3088 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3090 /* make sure it's still in list */
3091 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3092 /* Not in list anymore */
3093 vty_out(vty
, "Current VRF group no longer exists\n");
3094 return CMD_WARNING_CONFIG_FAILED
;
3097 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3098 vnc_redistribute_prechange(bgp
);
3101 rfg
->label
= MPLS_LABEL_NONE
;
3103 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3104 vnc_redistribute_postchange(bgp
);
3109 DEFUN (vnc_vrf_policy_nexthop
,
3110 vnc_vrf_policy_nexthop_cmd
,
3111 "nexthop <A.B.C.D|X:X::X:X|self>",
3112 "Specify next hop to use for VRF advertised prefixes\n"
3115 "Use configured router-id (default)\n")
3117 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3120 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3122 /* make sure it's still in list */
3123 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3124 /* Not in list anymore */
3125 vty_out(vty
, "Current VRF no longer exists\n");
3126 return CMD_WARNING_CONFIG_FAILED
;
3129 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3130 vnc_redistribute_prechange(bgp
);
3133 if (!str2prefix(argv
[1]->arg
, &p
) && p
.family
) {
3134 // vty_out (vty, "Nexthop set to self\n");
3135 SET_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
);
3136 memset(&rfg
->vn_prefix
, 0, sizeof(struct prefix
));
3138 UNSET_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
);
3143 /* TBD handle router-id/ nexthop changes when have advertised prefixes
3146 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3147 vnc_redistribute_postchange(bgp
);
3153 /* The RT code should be refactored/simplified with above... */
3154 DEFUN (vnc_vrf_policy_rt_import
,
3155 vnc_vrf_policy_rt_import_cmd
,
3156 "rt import RTLIST...",
3157 "Specify route targets\n"
3159 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3161 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3162 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3164 struct listnode
*node
;
3165 struct rfapi_rfg_name
*rfgn
;
3166 int is_export_bgp
= 0;
3167 int is_export_zebra
= 0;
3169 /* make sure it's still in list */
3170 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3171 /* Not in list anymore */
3172 vty_out(vty
, "Current NVE group no longer exists\n");
3173 return CMD_WARNING_CONFIG_FAILED
;
3176 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
3177 if (rc
!= CMD_SUCCESS
)
3180 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
3183 if (rfgn
->rfg
== rfg
) {
3190 vnc_direct_bgp_del_group(bgp
, rfg
);
3192 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
3195 if (rfgn
->rfg
== rfg
) {
3196 is_export_zebra
= 1;
3201 if (is_export_zebra
)
3202 vnc_zebra_del_group(bgp
, rfg
);
3205 * stop referencing old import table, now reference new one
3207 if (rfg
->rfapi_import_table
)
3208 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
3209 rfg
->rfapi_import_table
=
3210 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
3213 vnc_direct_bgp_add_group(bgp
, rfg
);
3215 if (is_export_zebra
)
3216 vnc_zebra_add_group(bgp
, rfg
);
3221 DEFUN (vnc_vrf_policy_rt_export
,
3222 vnc_vrf_policy_rt_export_cmd
,
3223 "rt export RTLIST...",
3224 "Specify route targets\n"
3226 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3228 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3229 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3232 /* make sure it's still in list */
3233 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3234 /* Not in list anymore */
3235 vty_out(vty
, "Current NVE group no longer exists\n");
3236 return CMD_WARNING_CONFIG_FAILED
;
3239 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3240 vnc_redistribute_prechange(bgp
);
3243 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
3245 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3246 vnc_redistribute_postchange(bgp
);
3252 DEFUN (vnc_vrf_policy_rt_both
,
3253 vnc_vrf_policy_rt_both_cmd
,
3254 "rt both RTLIST...",
3255 "Specify route targets\n"
3256 "Export+import filters\n"
3257 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3259 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3260 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3262 int is_export_bgp
= 0;
3263 int is_export_zebra
= 0;
3264 struct listnode
*node
;
3265 struct rfapi_rfg_name
*rfgn
;
3267 /* make sure it's still in list */
3268 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3269 /* Not in list anymore */
3270 vty_out(vty
, "Current NVE group no longer exists\n");
3271 return CMD_WARNING_CONFIG_FAILED
;
3274 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
3275 if (rc
!= CMD_SUCCESS
)
3278 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
3281 if (rfgn
->rfg
== rfg
) {
3288 vnc_direct_bgp_del_group(bgp
, rfg
);
3290 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
3293 if (rfgn
->rfg
== rfg
) {
3294 is_export_zebra
= 1;
3299 if (is_export_zebra
) {
3300 vnc_zlog_debug_verbose("%s: is_export_zebra", __func__
);
3301 vnc_zebra_del_group(bgp
, rfg
);
3305 * stop referencing old import table, now reference new one
3307 if (rfg
->rfapi_import_table
)
3308 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
3309 rfg
->rfapi_import_table
=
3310 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
3313 vnc_direct_bgp_add_group(bgp
, rfg
);
3315 if (is_export_zebra
)
3316 vnc_zebra_add_group(bgp
, rfg
);
3318 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3319 vnc_redistribute_prechange(bgp
);
3322 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
3324 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3325 vnc_redistribute_postchange(bgp
);
3331 DEFUN (vnc_vrf_policy_rd
,
3332 vnc_vrf_policy_rd_cmd
,
3333 "rd ASN:NN_OR_IP-ADDRESS:NN",
3334 "Specify default VRF route distinguisher\n"
3335 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:nh:<number> )\n")
3338 struct prefix_rd prd
;
3339 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3340 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3342 /* make sure it's still in list */
3343 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3344 /* Not in list anymore */
3345 vty_out(vty
, "Current NVE group no longer exists\n");
3346 return CMD_WARNING_CONFIG_FAILED
;
3349 if (!strncmp(argv
[1]->arg
, "auto:nh:", 8)) {
3351 * use AF_UNIX to designate automatically-assigned RD
3352 * auto:vn:nn where nn is a 2-octet quantity
3355 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
3356 uint16_t value
= value32
& 0xffff;
3358 if (!*(argv
[1]->arg
+ 5) || *end
) {
3359 vty_out(vty
, "%% Malformed rd\n");
3360 return CMD_WARNING_CONFIG_FAILED
;
3362 if (value32
> 0xffff) {
3363 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
3365 return CMD_WARNING_CONFIG_FAILED
;
3368 memset(&prd
, 0, sizeof(prd
));
3369 prd
.family
= AF_UNIX
;
3371 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
3372 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
3373 prd
.val
[6] = (value
>> 8) & 0x0ff;
3374 prd
.val
[7] = value
& 0x0ff;
3378 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
3380 vty_out(vty
, "%% Malformed rd\n");
3381 return CMD_WARNING_CONFIG_FAILED
;
3385 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3386 vnc_redistribute_prechange(bgp
);
3391 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3392 vnc_redistribute_postchange(bgp
);
3397 DEFUN_NOSH (exit_vrf_policy
,
3398 exit_vrf_policy_cmd
,
3400 "Exit VRF policy configuration mode\n")
3402 if (vty
->node
== BGP_VRF_POLICY_NODE
) {
3403 vty
->node
= BGP_NODE
;
3408 static struct cmd_node bgp_vrf_policy_node
= {
3409 BGP_VRF_POLICY_NODE
, "%s(config-router-vrf-policy)# ", 1};
3411 /*-------------------------------------------------------------------------
3413 *-----------------------------------------------------------------------*/
3416 DEFUN_NOSH (vnc_l2_group
,
3418 "vnc l2-group NAME",
3419 VNC_CONFIG_STR
"Configure a L2 group\n" "Group name\n")
3421 struct rfapi_l2_group_cfg
*rfg
;
3422 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3423 VNC_VTY_CONFIG_CHECK(bgp
);
3425 /* Search for name */
3426 rfg
= rfapi_l2_group_lookup_byname(bgp
, argv
[2]->arg
);
3429 rfg
= rfapi_l2_group_new();
3431 /* Error out of memory */
3432 vty_out(vty
, "Can't allocate memory for L2 group\n");
3433 return CMD_WARNING_CONFIG_FAILED
;
3435 rfg
->name
= strdup(argv
[2]->arg
);
3436 /* add to tail of list */
3437 listnode_add(bgp
->rfapi_cfg
->l2_groups
, rfg
);
3441 * XXX subsequent calls will need to make sure this item is still
3442 * in the linked list and has the same name
3444 VTY_PUSH_CONTEXT_SUB(BGP_VNC_L2_GROUP_NODE
, rfg
);
3448 static void bgp_rfapi_delete_l2_group(struct vty
*vty
, /* NULL = no output */
3450 struct rfapi_l2_group_cfg
*rfg
)
3454 if (rfg
->rt_import_list
)
3455 ecommunity_free(&rfg
->rt_import_list
);
3456 if (rfg
->rt_export_list
)
3457 ecommunity_free(&rfg
->rt_export_list
);
3459 list_delete(&rfg
->labels
);
3460 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, rfg
->rfp_cfg
);
3461 listnode_delete(bgp
->rfapi_cfg
->l2_groups
, rfg
);
3463 rfapi_l2_group_del(rfg
);
3467 bgp_rfapi_delete_named_l2_group(struct vty
*vty
, /* NULL = no output */
3469 const char *rfg_name
) /* NULL = any */
3471 struct rfapi_l2_group_cfg
*rfg
= NULL
;
3472 struct listnode
*node
, *nnode
;
3474 /* Search for name */
3476 rfg
= rfapi_l2_group_lookup_byname(bgp
, rfg_name
);
3479 vty_out(vty
, "No L2 group named \"%s\"\n",
3481 return CMD_WARNING_CONFIG_FAILED
;
3486 bgp_rfapi_delete_l2_group(vty
, bgp
, rfg
);
3487 else /* must be delete all */
3488 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->l2_groups
, node
, nnode
,
3490 bgp_rfapi_delete_l2_group(vty
, bgp
, rfg
);
3494 DEFUN (vnc_no_l2_group
,
3495 vnc_no_l2_group_cmd
,
3496 "no vnc l2-group NAME",
3499 "Configure a L2 group\n"
3502 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3504 return bgp_rfapi_delete_named_l2_group(vty
, bgp
, argv
[3]->arg
);
3508 DEFUN (vnc_l2_group_lni
,
3509 vnc_l2_group_lni_cmd
,
3510 "logical-network-id (0-4294967295)",
3511 "Specify Logical Network ID associated with group\n"
3514 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3515 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3517 /* make sure it's still in list */
3518 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3519 /* Not in list anymore */
3520 vty_out(vty
, "Current L2 group no longer exists\n");
3521 return CMD_WARNING_CONFIG_FAILED
;
3524 rfg
->logical_net_id
= strtoul(argv
[1]->arg
, NULL
, 10);
3529 DEFUN (vnc_l2_group_labels
,
3530 vnc_l2_group_labels_cmd
,
3531 "labels (0-1048575)...",
3532 "Specify label values associated with group\n"
3533 "Space separated list of label values <0-1048575>\n")
3535 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3536 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3539 /* make sure it's still in list */
3540 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3541 /* Not in list anymore */
3542 vty_out(vty
, "Current L2 group no longer exists\n");
3543 return CMD_WARNING_CONFIG_FAILED
;
3553 for (; argc
; --argc
, ++argv
) {
3555 label
= strtoul(argv
[0]->arg
, NULL
, 10);
3556 if (!listnode_lookup(ll
, (void *)(uintptr_t)label
))
3557 listnode_add(ll
, (void *)(uintptr_t)label
);
3563 DEFUN (vnc_l2_group_no_labels
,
3564 vnc_l2_group_no_labels_cmd
,
3565 "no labels (0-1048575)...",
3567 "Specify label values associated with L2 group\n"
3568 "Space separated list of label values <0-1048575>\n")
3570 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3571 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3574 /* make sure it's still in list */
3575 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3576 /* Not in list anymore */
3577 vty_out(vty
, "Current L2 group no longer exists\n");
3578 return CMD_WARNING_CONFIG_FAILED
;
3583 vty_out(vty
, "Label no longer associated with group\n");
3584 return CMD_WARNING_CONFIG_FAILED
;
3589 for (; argc
; --argc
, ++argv
) {
3591 label
= strtoul(argv
[0]->arg
, NULL
, 10);
3592 listnode_delete(ll
, (void *)(uintptr_t)label
);
3598 DEFUN (vnc_l2_group_rt
,
3599 vnc_l2_group_rt_cmd
,
3600 "rt <both|export|import> ASN:NN_OR_IP-ADDRESS:NN",
3601 "Specify route targets\n"
3602 "Export+import filters\n"
3607 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3608 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3609 int rc
= CMD_SUCCESS
;
3613 switch (argv
[1]->arg
[0]) {
3615 do_export
= 1; /* fall through */
3623 vty_out(vty
, "Unknown option, %s\n", argv
[1]->arg
);
3624 return CMD_ERR_NO_MATCH
;
3627 /* make sure it's still in list */
3628 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3629 /* Not in list anymore */
3630 vty_out(vty
, "Current L2 group no longer exists\n");
3631 return CMD_WARNING_CONFIG_FAILED
;
3635 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
3636 &rfg
->rt_import_list
);
3637 if (rc
== CMD_SUCCESS
&& do_export
)
3638 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
3639 &rfg
->rt_export_list
);
3644 static struct cmd_node bgp_vnc_l2_group_node
= {
3645 BGP_VNC_L2_GROUP_NODE
, "%s(config-router-vnc-l2-group)# ", 1};
3647 struct rfapi_l2_group_cfg
*
3648 bgp_rfapi_get_group_by_lni_label(struct bgp
*bgp
, uint32_t logical_net_id
,
3651 struct rfapi_l2_group_cfg
*rfg
;
3652 struct listnode
*node
;
3654 if (bgp
->rfapi_cfg
->l2_groups
== NULL
) /* not the best place for this */
3657 label
= label
& 0xfffff; /* label is 20 bits! */
3659 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->l2_groups
, node
, rfg
)) {
3660 if (rfg
->logical_net_id
== logical_net_id
) {
3661 struct listnode
*lnode
;
3663 for (ALL_LIST_ELEMENTS_RO(rfg
->labels
, lnode
, data
))
3664 if (((uint32_t)((uintptr_t)data
))
3665 == label
) { /* match! */
3673 struct list
*bgp_rfapi_get_labellist_by_lni_label(struct bgp
*bgp
,
3674 uint32_t logical_net_id
,
3677 struct rfapi_l2_group_cfg
*rfg
;
3678 rfg
= bgp_rfapi_get_group_by_lni_label(bgp
, logical_net_id
, label
);
3686 bgp_rfapi_get_ecommunity_by_lni_label(struct bgp
*bgp
, uint32_t is_import
,
3687 uint32_t logical_net_id
, uint32_t label
)
3689 struct rfapi_l2_group_cfg
*rfg
;
3690 rfg
= bgp_rfapi_get_group_by_lni_label(bgp
, logical_net_id
, label
);
3693 return rfg
->rt_import_list
;
3695 return rfg
->rt_export_list
;
3700 void bgp_rfapi_cfg_init(void)
3702 /* main bgpd code does not use this hook, but vnc does */
3703 /* superseded by bgp_route_map_process_update_cb() */
3704 /* bgp_route_map_event_hook_add(vnc_routemap_event); */
3706 install_node(&bgp_vnc_defaults_node
, NULL
);
3707 install_node(&bgp_vnc_nve_group_node
, NULL
);
3708 install_node(&bgp_vrf_policy_node
, NULL
);
3709 install_node(&bgp_vnc_l2_group_node
, NULL
);
3710 install_default(BGP_VRF_POLICY_NODE
);
3711 install_default(BGP_VNC_DEFAULTS_NODE
);
3712 install_default(BGP_VNC_NVE_GROUP_NODE
);
3713 install_default(BGP_VNC_L2_GROUP_NODE
);
3718 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3719 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3720 install_element(BGP_NODE
, &vnc_no_nve_group_cmd
);
3721 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3722 install_element(BGP_NODE
, &vnc_no_vrf_policy_cmd
);
3723 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3724 install_element(BGP_NODE
, &vnc_no_l2_group_cmd
);
3725 install_element(BGP_NODE
, &vnc_advertise_un_method_cmd
);
3726 install_element(BGP_NODE
, &vnc_export_mode_cmd
);
3728 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_import_cmd
);
3729 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_export_cmd
);
3730 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_both_cmd
);
3731 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rd_cmd
);
3732 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_l2rd_cmd
);
3733 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_no_l2rd_cmd
);
3734 install_element(BGP_VNC_DEFAULTS_NODE
,
3735 &vnc_defaults_responselifetime_cmd
);
3736 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_cmd
);
3738 install_element(BGP_NODE
, &vnc_redistribute_protocol_cmd
);
3739 install_element(BGP_NODE
, &vnc_no_redistribute_protocol_cmd
);
3740 install_element(BGP_NODE
, &vnc_redistribute_nvegroup_cmd
);
3741 install_element(BGP_NODE
, &vnc_redistribute_no_nvegroup_cmd
);
3742 install_element(BGP_NODE
, &vnc_redistribute_lifetime_cmd
);
3743 install_element(BGP_NODE
, &vnc_redistribute_rh_roo_localadmin_cmd
);
3744 install_element(BGP_NODE
, &vnc_redistribute_mode_cmd
);
3745 install_element(BGP_NODE
, &vnc_redistribute_bgp_exterior_cmd
);
3747 install_element(BGP_NODE
, &vnc_redist_bgpdirect_no_prefixlist_cmd
);
3748 install_element(BGP_NODE
, &vnc_redist_bgpdirect_prefixlist_cmd
);
3749 install_element(BGP_NODE
, &vnc_redist_bgpdirect_no_routemap_cmd
);
3750 install_element(BGP_NODE
, &vnc_redist_bgpdirect_routemap_cmd
);
3752 install_element(BGP_VNC_NVE_GROUP_NODE
,
3753 &vnc_nve_group_redist_bgpdirect_no_prefixlist_cmd
);
3754 install_element(BGP_VNC_NVE_GROUP_NODE
,
3755 &vnc_nve_group_redist_bgpdirect_prefixlist_cmd
);
3756 install_element(BGP_VNC_NVE_GROUP_NODE
,
3757 &vnc_nve_group_redist_bgpdirect_no_routemap_cmd
);
3758 install_element(BGP_VNC_NVE_GROUP_NODE
,
3759 &vnc_nve_group_redist_bgpdirect_routemap_cmd
);
3761 install_element(BGP_NODE
, &vnc_export_nvegroup_cmd
);
3762 install_element(BGP_NODE
, &vnc_no_export_nvegroup_cmd
);
3763 install_element(BGP_NODE
, &vnc_nve_export_prefixlist_cmd
);
3764 install_element(BGP_NODE
, &vnc_nve_export_routemap_cmd
);
3765 install_element(BGP_NODE
, &vnc_nve_export_no_prefixlist_cmd
);
3766 install_element(BGP_NODE
, &vnc_nve_export_no_routemap_cmd
);
3768 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_l2rd_cmd
);
3769 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_no_l2rd_cmd
);
3770 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_prefix_cmd
);
3771 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_import_cmd
);
3772 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_export_cmd
);
3773 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_both_cmd
);
3774 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rd_cmd
);
3775 install_element(BGP_VNC_NVE_GROUP_NODE
,
3776 &vnc_nve_group_responselifetime_cmd
);
3777 install_element(BGP_VNC_NVE_GROUP_NODE
,
3778 &vnc_nve_group_export_prefixlist_cmd
);
3779 install_element(BGP_VNC_NVE_GROUP_NODE
,
3780 &vnc_nve_group_export_routemap_cmd
);
3781 install_element(BGP_VNC_NVE_GROUP_NODE
,
3782 &vnc_nve_group_export_no_prefixlist_cmd
);
3783 install_element(BGP_VNC_NVE_GROUP_NODE
,
3784 &vnc_nve_group_export_no_routemap_cmd
);
3785 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_cmd
);
3787 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_label_cmd
);
3788 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_no_label_cmd
);
3789 // Reenable to support VRF controller use case and testing
3790 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_nexthop_cmd
);
3791 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_import_cmd
);
3792 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_export_cmd
);
3793 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_both_cmd
);
3794 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rd_cmd
);
3795 install_element(BGP_VRF_POLICY_NODE
,
3796 &vnc_vrf_policy_export_prefixlist_cmd
);
3797 install_element(BGP_VRF_POLICY_NODE
,
3798 &vnc_vrf_policy_export_routemap_cmd
);
3799 install_element(BGP_VRF_POLICY_NODE
,
3800 &vnc_vrf_policy_export_no_prefixlist_cmd
);
3801 install_element(BGP_VRF_POLICY_NODE
,
3802 &vnc_vrf_policy_export_no_routemap_cmd
);
3803 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
3805 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_lni_cmd
);
3806 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_labels_cmd
);
3807 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_no_labels_cmd
);
3808 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_rt_cmd
);
3809 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_cmd
);
3812 struct rfapi_cfg
*bgp_rfapi_cfg_new(struct rfapi_rfp_cfg
*cfg
)
3814 struct rfapi_cfg
*h
;
3817 h
= XCALLOC(MTYPE_RFAPI_CFG
, sizeof(struct rfapi_cfg
));
3820 h
->nve_groups_sequential
= list_new();
3821 assert(h
->nve_groups_sequential
);
3822 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
3823 h
->nve_groups_vn
[afi
] = agg_table_init();
3824 h
->nve_groups_un
[afi
] = agg_table_init();
3826 h
->default_response_lifetime
=
3827 BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT
;
3828 h
->rfg_export_direct_bgp_l
= list_new();
3829 h
->rfg_export_zebra_l
= list_new();
3830 h
->resolve_nve_roo_local_admin
=
3831 BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT
;
3833 SET_FLAG(h
->flags
, BGP_VNC_CONFIG_FLAGS_DEFAULT
);
3836 h
->rfp_cfg
.download_type
= RFAPI_RFP_DOWNLOAD_PARTIAL
;
3837 h
->rfp_cfg
.ftd_advertisement_interval
=
3838 RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL
;
3839 h
->rfp_cfg
.holddown_factor
=
3840 RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR
;
3841 h
->rfp_cfg
.use_updated_response
= 0;
3842 h
->rfp_cfg
.use_removes
= 0;
3844 h
->rfp_cfg
.download_type
= cfg
->download_type
;
3845 h
->rfp_cfg
.ftd_advertisement_interval
=
3846 cfg
->ftd_advertisement_interval
;
3847 h
->rfp_cfg
.holddown_factor
= cfg
->holddown_factor
;
3848 h
->rfp_cfg
.use_updated_response
= cfg
->use_updated_response
;
3849 h
->rfp_cfg
.use_removes
= cfg
->use_removes
;
3850 if (cfg
->use_updated_response
)
3851 h
->flags
&= ~BGP_VNC_CONFIG_CALLBACK_DISABLE
;
3853 h
->flags
|= BGP_VNC_CONFIG_CALLBACK_DISABLE
;
3854 if (cfg
->use_removes
)
3855 h
->flags
&= ~BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE
;
3857 h
->flags
|= BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE
;
3862 void bgp_rfapi_cfg_destroy(struct bgp
*bgp
, struct rfapi_cfg
*h
)
3868 bgp_rfapi_delete_named_nve_group(NULL
, bgp
, NULL
, RFAPI_GROUP_CFG_MAX
);
3869 bgp_rfapi_delete_named_l2_group(NULL
, bgp
, NULL
);
3870 if (h
->l2_groups
!= NULL
)
3871 list_delete(&h
->l2_groups
);
3872 list_delete(&h
->nve_groups_sequential
);
3873 list_delete(&h
->rfg_export_direct_bgp_l
);
3874 list_delete(&h
->rfg_export_zebra_l
);
3875 if (h
->default_rt_export_list
)
3876 ecommunity_free(&h
->default_rt_export_list
);
3877 if (h
->default_rt_import_list
)
3878 ecommunity_free(&h
->default_rt_import_list
);
3879 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, h
->default_rfp_cfg
);
3880 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
3881 agg_table_finish(h
->nve_groups_vn
[afi
]);
3882 agg_table_finish(h
->nve_groups_un
[afi
]);
3884 XFREE(MTYPE_RFAPI_CFG
, h
);
3887 int bgp_rfapi_cfg_write(struct vty
*vty
, struct bgp
*bgp
)
3889 struct listnode
*node
, *nnode
;
3890 struct rfapi_nve_group_cfg
*rfg
;
3891 struct rfapi_cfg
*hc
= bgp
->rfapi_cfg
;
3892 struct rfapi_rfg_name
*rfgn
;
3896 if (bgp
->rfapi
== NULL
|| hc
== NULL
)
3899 vty_out(vty
, "!\n");
3900 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
, rfg
))
3901 if (rfg
->type
== RFAPI_GROUP_CFG_VRF
) {
3903 vty_out(vty
, " vrf-policy %s\n", rfg
->name
);
3904 if (rfg
->label
<= MPLS_LABEL_MAX
) {
3905 vty_out(vty
, " label %u\n", rfg
->label
);
3907 if (CHECK_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
)) {
3908 vty_out(vty
, " nexthop self\n");
3911 if (rfg
->vn_prefix
.family
) {
3913 buf
[0] = buf
[BUFSIZ
- 1] = 0;
3914 inet_ntop(rfg
->vn_prefix
.family
,
3915 &rfg
->vn_prefix
.u
.prefix
, buf
,
3917 if (!buf
[0] || buf
[BUFSIZ
- 1]) {
3918 // vty_out (vty, "nexthop
3921 vty_out(vty
, " nexthop %s\n",
3927 if (rfg
->rd
.prefixlen
) {
3928 char buf
[RD_ADDRSTRLEN
];
3930 if (AF_UNIX
== rfg
->rd
.family
) {
3934 value
= ((rfg
->rd
.val
[6] << 8)
3936 | (rfg
->rd
.val
[7] & 0x0ff);
3938 vty_out(vty
, " rd auto:nh:%d\n",
3942 vty_out(vty
, " rd %s\n",
3943 prefix_rd2str(&rfg
->rd
, buf
,
3947 if (rfg
->rt_import_list
&& rfg
->rt_export_list
3948 && ecommunity_cmp(rfg
->rt_import_list
,
3949 rfg
->rt_export_list
)) {
3950 char *b
= ecommunity_ecom2str(
3951 rfg
->rt_import_list
,
3952 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3953 ECOMMUNITY_ROUTE_TARGET
);
3954 vty_out(vty
, " rt both %s\n", b
);
3955 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3957 if (rfg
->rt_import_list
) {
3958 char *b
= ecommunity_ecom2str(
3959 rfg
->rt_import_list
,
3960 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3961 ECOMMUNITY_ROUTE_TARGET
);
3962 vty_out(vty
, " rt import %s\n", b
);
3963 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3965 if (rfg
->rt_export_list
) {
3966 char *b
= ecommunity_ecom2str(
3967 rfg
->rt_export_list
,
3968 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3969 ECOMMUNITY_ROUTE_TARGET
);
3970 vty_out(vty
, " rt export %s\n", b
);
3971 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3976 * route filtering: prefix-lists and route-maps
3978 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
3980 const char *afistr
=
3981 (afi
== AFI_IP
) ? "ipv4" : "ipv6";
3983 if (rfg
->plist_export_bgp_name
[afi
]) {
3985 " export %s%s prefix-list %s\n",
3986 (rfg
->type
== RFAPI_GROUP_CFG_VRF
3990 rfg
->plist_export_bgp_name
3993 if (rfg
->plist_export_zebra_name
[afi
]) {
3995 " export %s%s prefix-list %s\n",
3996 (rfg
->type
== RFAPI_GROUP_CFG_VRF
4000 rfg
->plist_export_zebra_name
4004 * currently we only support redist plists for
4006 * If we later add plist support for
4007 * redistributing other
4008 * protocols, we'll need to loop over protocols
4011 if (rfg
->plist_redist_name
4012 [ZEBRA_ROUTE_BGP_DIRECT
][afi
]) {
4014 " redistribute bgp-direct %s prefix-list %s\n",
4016 rfg
->plist_redist_name
4017 [ZEBRA_ROUTE_BGP_DIRECT
]
4020 if (rfg
->plist_redist_name
4021 [ZEBRA_ROUTE_BGP_DIRECT_EXT
][afi
]) {
4023 " redistribute bgp-direct-to-nve-groups %s prefix-list %s\n",
4025 rfg
->plist_redist_name
4026 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4031 if (rfg
->routemap_export_bgp_name
) {
4032 vty_out(vty
, " export %sroute-map %s\n",
4033 (rfg
->type
== RFAPI_GROUP_CFG_VRF
4036 rfg
->routemap_export_bgp_name
);
4038 if (rfg
->routemap_export_zebra_name
) {
4039 vty_out(vty
, " export %sroute-map %s\n",
4040 (rfg
->type
== RFAPI_GROUP_CFG_VRF
4043 rfg
->routemap_export_zebra_name
);
4045 if (rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]) {
4047 " redistribute bgp-direct route-map %s\n",
4048 rfg
->routemap_redist_name
4049 [ZEBRA_ROUTE_BGP_DIRECT
]);
4051 if (rfg
->routemap_redist_name
4052 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]) {
4054 " redistribute bgp-direct-to-nve-groups route-map %s\n",
4055 rfg
->routemap_redist_name
4056 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]);
4058 vty_out(vty
, " exit-vrf-policy\n");
4059 vty_out(vty
, "!\n");
4061 if (hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
) {
4062 vty_out(vty
, " vnc advertise-un-method encap-safi\n");
4066 { /* was based on listen ports */
4067 /* for now allow both old and new */
4068 if (bgp
->rfapi
->rfp_methods
.cfg_cb
)
4069 write
+= (bgp
->rfapi
->rfp_methods
.cfg_cb
)(
4070 vty
, bgp
->rfapi
->rfp
);
4073 vty_out(vty
, "!\n");
4075 if (hc
->l2_groups
) {
4076 struct rfapi_l2_group_cfg
*rfgc
= NULL
;
4077 struct listnode
*gnode
;
4078 for (ALL_LIST_ELEMENTS_RO(hc
->l2_groups
, gnode
, rfgc
)) {
4079 struct listnode
*lnode
;
4082 vty_out(vty
, " vnc l2-group %s\n", rfgc
->name
);
4083 if (rfgc
->logical_net_id
!= 0)
4085 " logical-network-id %u\n",
4086 rfgc
->logical_net_id
);
4087 if (rfgc
->labels
!= NULL
4088 && listhead(rfgc
->labels
) != NULL
) {
4089 vty_out(vty
, " labels ");
4090 for (ALL_LIST_ELEMENTS_RO(rfgc
->labels
,
4093 vty_out(vty
, "%hu ",
4101 if (rfgc
->rt_import_list
&& rfgc
->rt_export_list
4102 && ecommunity_cmp(rfgc
->rt_import_list
,
4103 rfgc
->rt_export_list
)) {
4104 char *b
= ecommunity_ecom2str(
4105 rfgc
->rt_import_list
,
4106 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4107 ECOMMUNITY_ROUTE_TARGET
);
4108 vty_out(vty
, " rt both %s\n", b
);
4109 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4111 if (rfgc
->rt_import_list
) {
4112 char *b
= ecommunity_ecom2str(
4113 rfgc
->rt_import_list
,
4114 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4115 ECOMMUNITY_ROUTE_TARGET
);
4116 vty_out(vty
, " rt import %s\n",
4118 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4120 if (rfgc
->rt_export_list
) {
4121 char *b
= ecommunity_ecom2str(
4122 rfgc
->rt_export_list
,
4123 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4124 ECOMMUNITY_ROUTE_TARGET
);
4125 vty_out(vty
, " rt export %s\n",
4127 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4130 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4131 write
+= (bgp
->rfapi
->rfp_methods
4133 vty
, bgp
->rfapi
->rfp
,
4134 RFAPI_RFP_CFG_GROUP_L2
,
4135 rfgc
->name
, rfgc
->rfp_cfg
);
4136 vty_out(vty
, " exit-vnc\n");
4137 vty_out(vty
, "!\n");
4141 if (hc
->default_rd
.prefixlen
4142 || hc
->default_response_lifetime
4143 != BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT
4144 || hc
->default_rt_import_list
|| hc
->default_rt_export_list
4145 || hc
->nve_groups_sequential
->count
) {
4149 vty_out(vty
, " vnc defaults\n");
4151 if (hc
->default_rd
.prefixlen
) {
4152 char buf
[RD_ADDRSTRLEN
];
4154 if (AF_UNIX
== hc
->default_rd
.family
) {
4157 value
= ((hc
->default_rd
.val
[6] << 8)
4159 | (hc
->default_rd
.val
[7]
4162 vty_out(vty
, " rd auto:vn:%d\n",
4166 vty_out(vty
, " rd %s\n",
4167 prefix_rd2str(&hc
->default_rd
,
4171 if (hc
->default_response_lifetime
4172 != BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT
) {
4173 vty_out(vty
, " response-lifetime ");
4174 if (hc
->default_response_lifetime
!= UINT32_MAX
)
4176 hc
->default_response_lifetime
);
4178 vty_out(vty
, "infinite");
4181 if (hc
->default_rt_import_list
4182 && hc
->default_rt_export_list
4183 && ecommunity_cmp(hc
->default_rt_import_list
,
4184 hc
->default_rt_export_list
)) {
4185 char *b
= ecommunity_ecom2str(
4186 hc
->default_rt_import_list
,
4187 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4188 ECOMMUNITY_ROUTE_TARGET
);
4189 vty_out(vty
, " rt both %s\n", b
);
4190 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4192 if (hc
->default_rt_import_list
) {
4193 char *b
= ecommunity_ecom2str(
4194 hc
->default_rt_import_list
,
4195 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4196 ECOMMUNITY_ROUTE_TARGET
);
4197 vty_out(vty
, " rt import %s\n", b
);
4198 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4200 if (hc
->default_rt_export_list
) {
4201 char *b
= ecommunity_ecom2str(
4202 hc
->default_rt_export_list
,
4203 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4204 ECOMMUNITY_ROUTE_TARGET
);
4205 vty_out(vty
, " rt export %s\n", b
);
4206 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4209 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4210 write
+= (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)(
4211 vty
, bgp
->rfapi
->rfp
,
4212 RFAPI_RFP_CFG_GROUP_DEFAULT
, NULL
,
4213 bgp
->rfapi_cfg
->default_rfp_cfg
);
4214 vty_out(vty
, " exit-vnc\n");
4215 vty_out(vty
, "!\n");
4218 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
,
4220 if (rfg
->type
== RFAPI_GROUP_CFG_NVE
) {
4222 vty_out(vty
, " vnc nve-group %s\n", rfg
->name
);
4224 if (rfg
->vn_prefix
.family
&& rfg
->vn_node
) {
4225 char buf
[PREFIX_STRLEN
];
4227 prefix2str(&rfg
->vn_prefix
, buf
,
4229 vty_out(vty
, " prefix %s %s\n", "vn",
4233 if (rfg
->un_prefix
.family
&& rfg
->un_node
) {
4234 char buf
[PREFIX_STRLEN
];
4236 prefix2str(&rfg
->un_prefix
, buf
,
4238 vty_out(vty
, " prefix %s %s\n", "un",
4243 if (rfg
->rd
.prefixlen
) {
4244 char buf
[RD_ADDRSTRLEN
];
4246 if (AF_UNIX
== rfg
->rd
.family
) {
4250 value
= ((rfg
->rd
.val
[6] << 8)
4260 vty_out(vty
, " rd %s\n",
4265 if (rfg
->flags
& RFAPI_RFG_RESPONSE_LIFETIME
) {
4266 vty_out(vty
, " response-lifetime ");
4267 if (rfg
->response_lifetime
4270 rfg
->response_lifetime
);
4272 vty_out(vty
, "infinite");
4276 if (rfg
->rt_import_list
&& rfg
->rt_export_list
4277 && ecommunity_cmp(rfg
->rt_import_list
,
4278 rfg
->rt_export_list
)) {
4279 char *b
= ecommunity_ecom2str(
4280 rfg
->rt_import_list
,
4281 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4282 ECOMMUNITY_ROUTE_TARGET
);
4283 vty_out(vty
, " rt both %s\n", b
);
4284 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4286 if (rfg
->rt_import_list
) {
4287 char *b
= ecommunity_ecom2str(
4288 rfg
->rt_import_list
,
4289 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4290 ECOMMUNITY_ROUTE_TARGET
);
4291 vty_out(vty
, " rt import %s\n",
4293 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4295 if (rfg
->rt_export_list
) {
4296 char *b
= ecommunity_ecom2str(
4297 rfg
->rt_export_list
,
4298 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4299 ECOMMUNITY_ROUTE_TARGET
);
4300 vty_out(vty
, " rt export %s\n",
4302 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4307 * route filtering: prefix-lists and route-maps
4309 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4311 const char *afistr
= (afi
== AFI_IP
)
4315 if (rfg
->plist_export_bgp_name
[afi
]) {
4317 " export bgp %s prefix-list %s\n",
4319 rfg
->plist_export_bgp_name
4322 if (rfg
->plist_export_zebra_name
[afi
]) {
4324 " export zebra %s prefix-list %s\n",
4326 rfg
->plist_export_zebra_name
4330 * currently we only support redist
4331 * plists for bgp-direct.
4332 * If we later add plist support for
4333 * redistributing other
4334 * protocols, we'll need to loop over
4337 if (rfg
->plist_redist_name
4338 [ZEBRA_ROUTE_BGP_DIRECT
]
4341 " redistribute bgp-direct %s prefix-list %s\n",
4343 rfg
->plist_redist_name
4344 [ZEBRA_ROUTE_BGP_DIRECT
]
4347 if (rfg
->plist_redist_name
4348 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4351 " redistribute bgp-direct-to-nve-groups %s prefix-list %s\n",
4353 rfg
->plist_redist_name
4354 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4359 if (rfg
->routemap_export_bgp_name
) {
4361 " export bgp route-map %s\n",
4362 rfg
->routemap_export_bgp_name
);
4364 if (rfg
->routemap_export_zebra_name
) {
4366 " export zebra route-map %s\n",
4367 rfg
->routemap_export_zebra_name
);
4369 if (rfg
->routemap_redist_name
4370 [ZEBRA_ROUTE_BGP_DIRECT
]) {
4372 " redistribute bgp-direct route-map %s\n",
4373 rfg
->routemap_redist_name
4374 [ZEBRA_ROUTE_BGP_DIRECT
]);
4376 if (rfg
->routemap_redist_name
4377 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]) {
4379 " redistribute bgp-direct-to-nve-groups route-map %s\n",
4380 rfg
->routemap_redist_name
4381 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]);
4383 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4384 write
+= (bgp
->rfapi
->rfp_methods
4386 vty
, bgp
->rfapi
->rfp
,
4387 RFAPI_RFP_CFG_GROUP_NVE
,
4388 rfg
->name
, rfg
->rfp_cfg
);
4389 vty_out(vty
, " exit-vnc\n");
4390 vty_out(vty
, "!\n");
4392 } /* have listen ports */
4395 * route export to other protocols
4397 if (VNC_EXPORT_BGP_GRP_ENABLED(hc
)) {
4398 vty_out(vty
, " vnc export bgp mode group-nve\n");
4399 } else if (VNC_EXPORT_BGP_RH_ENABLED(hc
)) {
4400 vty_out(vty
, " vnc export bgp mode registering-nve\n");
4401 } else if (VNC_EXPORT_BGP_CE_ENABLED(hc
)) {
4402 vty_out(vty
, " vnc export bgp mode ce\n");
4405 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(hc
)) {
4406 vty_out(vty
, " vnc export zebra mode group-nve\n");
4407 } else if (VNC_EXPORT_ZEBRA_RH_ENABLED(hc
)) {
4408 vty_out(vty
, " vnc export zebra mode registering-nve\n");
4411 if (hc
->rfg_export_direct_bgp_l
) {
4412 for (ALL_LIST_ELEMENTS(hc
->rfg_export_direct_bgp_l
, node
, nnode
,
4415 vty_out(vty
, " vnc export bgp group-nve group %s\n",
4420 if (hc
->rfg_export_zebra_l
) {
4421 for (ALL_LIST_ELEMENTS(hc
->rfg_export_zebra_l
, node
, nnode
,
4424 vty_out(vty
, " vnc export zebra group-nve group %s\n",
4430 if (hc
->rfg_redist_name
) {
4431 vty_out(vty
, " vnc redistribute nve-group %s\n",
4432 hc
->rfg_redist_name
);
4434 if (hc
->redist_lifetime
) {
4435 vty_out(vty
, " vnc redistribute lifetime %d\n",
4436 hc
->redist_lifetime
);
4438 if (hc
->resolve_nve_roo_local_admin
4439 != BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT
) {
4442 " vnc redistribute resolve-nve roo-ec-local-admin %d\n",
4443 hc
->resolve_nve_roo_local_admin
);
4446 if (hc
->redist_mode
) /* ! default */
4450 switch (hc
->redist_mode
) {
4451 case VNC_REDIST_MODE_PLAIN
:
4454 case VNC_REDIST_MODE_RFG
:
4457 case VNC_REDIST_MODE_RESOLVE_NVE
:
4462 vty_out(vty
, " vnc redistribute mode %s\n", s
);
4467 * route filtering: prefix-lists and route-maps
4469 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4471 const char *afistr
= (afi
== AFI_IP
) ? "ipv4" : "ipv6";
4473 if (hc
->plist_export_bgp_name
[afi
]) {
4474 vty_out(vty
, " vnc export bgp %s prefix-list %s\n",
4475 afistr
, hc
->plist_export_bgp_name
[afi
]);
4477 if (hc
->plist_export_zebra_name
[afi
]) {
4478 vty_out(vty
, " vnc export zebra %s prefix-list %s\n",
4479 afistr
, hc
->plist_export_zebra_name
[afi
]);
4481 if (hc
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
]) {
4483 " vnc redistribute bgp-direct %s prefix-list %s\n",
4485 hc
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]
4490 if (hc
->routemap_export_bgp_name
) {
4491 vty_out(vty
, " vnc export bgp route-map %s\n",
4492 hc
->routemap_export_bgp_name
);
4494 if (hc
->routemap_export_zebra_name
) {
4495 vty_out(vty
, " vnc export zebra route-map %s\n",
4496 hc
->routemap_export_zebra_name
);
4498 if (hc
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]) {
4499 vty_out(vty
, " vnc redistribute bgp-direct route-map %s\n",
4500 hc
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]);
4503 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4504 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
4505 if (hc
->redist
[afi
][type
]) {
4506 if (type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
4507 && hc
->redist_bgp_exterior_view_name
) {
4509 " vnc redistribute %s %s view %s\n",
4510 ((afi
== AFI_IP
) ? "ipv4"
4512 zebra_route_string(type
),
4513 hc
->redist_bgp_exterior_view_name
);
4516 " vnc redistribute %s %s\n",
4517 ((afi
== AFI_IP
) ? "ipv4"
4519 zebra_route_string(type
));
4527 void bgp_rfapi_show_summary(struct bgp
*bgp
, struct vty
*vty
)
4529 struct rfapi_cfg
*hc
= bgp
->rfapi_cfg
;
4531 int type
, redist
= 0;
4536 vty_out(vty
, "%-39s %-19s %s\n", "VNC Advertise method:",
4537 (hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
4538 ? "Encapsulation SAFI"
4539 : "Tunnel Encap attribute"),
4540 ((hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
)
4541 == (BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
4542 & BGP_VNC_CONFIG_FLAGS_DEFAULT
)
4546 vty_out(vty
, "%-39s ", "Export from VNC:");
4548 * route export to other protocols
4550 if (VNC_EXPORT_BGP_GRP_ENABLED(hc
)) {
4552 vty_out(vty
, "ToBGP Groups={");
4553 if (hc
->rfg_export_direct_bgp_l
) {
4555 struct listnode
*node
, *nnode
;
4556 struct rfapi_rfg_name
*rfgn
;
4557 for (ALL_LIST_ELEMENTS(hc
->rfg_export_direct_bgp_l
,
4558 node
, nnode
, rfgn
)) {
4562 vty_out(vty
, "%s", rfgn
->name
);
4566 } else if (VNC_EXPORT_BGP_RH_ENABLED(hc
)) {
4568 vty_out(vty
, "ToBGP {Registering NVE}");
4569 /* note filters, route-maps not shown */
4570 } else if (VNC_EXPORT_BGP_CE_ENABLED(hc
)) {
4572 vty_out(vty
, "ToBGP {NVE connected router:%d}",
4573 hc
->resolve_nve_roo_local_admin
);
4574 /* note filters, route-maps not shown */
4577 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(hc
)) {
4579 vty_out(vty
, "%sToZebra Groups={", (redist
== 1 ? "" : " "));
4580 if (hc
->rfg_export_zebra_l
) {
4582 struct listnode
*node
, *nnode
;
4583 struct rfapi_rfg_name
*rfgn
;
4584 for (ALL_LIST_ELEMENTS(hc
->rfg_export_zebra_l
, node
,
4588 vty_out(vty
, "%s", rfgn
->name
);
4592 } else if (VNC_EXPORT_ZEBRA_RH_ENABLED(hc
)) {
4594 vty_out(vty
, "%sToZebra {Registering NVE}",
4595 (redist
== 1 ? "" : " "));
4596 /* note filters, route-maps not shown */
4598 vty_out(vty
, "%-19s %s\n", (redist
? "" : "Off"),
4599 (redist
? "" : "(default)"));
4601 /* Redistribution */
4603 vty_out(vty
, "%-39s ", "Redistribution into VNC:");
4604 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4605 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
4606 if (hc
->redist
[afi
][type
]) {
4607 vty_out(vty
, "{%s,%s} ",
4608 ((afi
== AFI_IP
) ? "ipv4" : "ipv6"),
4609 zebra_route_string(type
));
4614 vty_out(vty
, "%-19s %s\n", (redist
? "" : "Off"),
4615 (redist
? "" : "(default)"));
4617 vty_out(vty
, "%-39s %3u%-16s %s\n",
4618 "RFP Registration Hold-Down Factor:",
4619 hc
->rfp_cfg
.holddown_factor
, "%",
4620 (hc
->rfp_cfg
.holddown_factor
4621 == RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR
4624 vty_out(vty
, "%-39s %-19s %s\n", "RFP Updated responses:",
4625 (hc
->rfp_cfg
.use_updated_response
== 0 ? "Off" : "On"),
4626 (hc
->rfp_cfg
.use_updated_response
== 0 ? "(default)" : ""));
4627 vty_out(vty
, "%-39s %-19s %s\n", "RFP Removal responses:",
4628 (hc
->rfp_cfg
.use_removes
== 0 ? "Off" : "On"),
4629 (hc
->rfp_cfg
.use_removes
== 0 ? "(default)" : ""));
4630 vty_out(vty
, "%-39s %-19s %s\n", "RFP Full table download:",
4631 (hc
->rfp_cfg
.download_type
== RFAPI_RFP_DOWNLOAD_FULL
? "On"
4633 (hc
->rfp_cfg
.download_type
== RFAPI_RFP_DOWNLOAD_PARTIAL
4636 sprintf(tmp
, "%u seconds", hc
->rfp_cfg
.ftd_advertisement_interval
);
4637 vty_out(vty
, "%-39s %-19s %s\n", " Advertisement Interval:", tmp
,
4638 (hc
->rfp_cfg
.ftd_advertisement_interval
4639 == RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL
4642 vty_out(vty
, "%-39s %d seconds\n", "Default RFP response lifetime:",
4643 hc
->default_response_lifetime
);
4648 struct rfapi_cfg
*bgp_rfapi_get_config(struct bgp
*bgp
)
4650 struct rfapi_cfg
*hc
= NULL
;
4652 bgp
= bgp_get_default();
4654 hc
= bgp
->rfapi_cfg
;
4658 #endif /* ENABLE_BGP_VNC */