1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright 2009-2016, LabN Consulting, L.L.C.
9 #include "lib/command.h"
10 #include "lib/prefix.h"
11 #include "lib/memory.h"
12 #include "lib/linklist.h"
13 #include "lib/agg_table.h"
14 #include "lib/plist.h"
15 #include "lib/routemap.h"
17 #include "bgpd/bgpd.h"
18 #include "bgpd/bgp_attr.h"
19 #include "bgpd/bgp_route.h"
20 #include "bgpd/bgp_mplsvpn.h"
22 #include "bgpd/bgp_vty.h"
23 #include "bgpd/bgp_ecommunity.h"
24 #include "bgpd/rfapi/rfapi.h"
25 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
26 #include "bgpd/rfapi/rfapi_backend.h"
27 #include "bgpd/rfapi/rfapi_import.h"
28 #include "bgpd/rfapi/rfapi_private.h"
29 #include "bgpd/rfapi/rfapi_monitor.h"
30 #include "bgpd/rfapi/vnc_zebra.h"
31 #include "bgpd/rfapi/vnc_export_bgp.h"
32 #include "bgpd/rfapi/vnc_export_bgp_p.h"
33 #include "bgpd/rfapi/rfapi_vty.h"
34 #include "bgpd/rfapi/vnc_import_bgp.h"
35 #include "bgpd/rfapi/vnc_debug.h"
39 #undef BGP_VNC_DEBUG_MATCH_GROUP
42 DEFINE_MGROUP(RFAPI
, "rfapi");
43 DEFINE_MTYPE(RFAPI
, RFAPI_CFG
, "NVE Configuration");
44 DEFINE_MTYPE(RFAPI
, RFAPI_GROUP_CFG
, "NVE Group Configuration");
45 DEFINE_MTYPE(RFAPI
, RFAPI_L2_CFG
, "RFAPI L2 Group Configuration");
46 DEFINE_MTYPE(RFAPI
, RFAPI_RFP_GROUP_CFG
, "RFAPI RFP Group Configuration");
47 DEFINE_MTYPE(RFAPI
, RFAPI
, "RFAPI Generic");
48 DEFINE_MTYPE(RFAPI
, RFAPI_DESC
, "RFAPI Descriptor");
49 DEFINE_MTYPE(RFAPI
, RFAPI_IMPORTTABLE
, "RFAPI Import Table");
50 DEFINE_MTYPE(RFAPI
, RFAPI_MONITOR
, "RFAPI Monitor VPN");
51 DEFINE_MTYPE(RFAPI
, RFAPI_MONITOR_ENCAP
, "RFAPI Monitor Encap");
52 DEFINE_MTYPE(RFAPI
, RFAPI_NEXTHOP
, "RFAPI Next Hop");
53 DEFINE_MTYPE(RFAPI
, RFAPI_VN_OPTION
, "RFAPI VN Option");
54 DEFINE_MTYPE(RFAPI
, RFAPI_UN_OPTION
, "RFAPI UN Option");
55 DEFINE_MTYPE(RFAPI
, RFAPI_WITHDRAW
, "RFAPI Withdraw");
56 DEFINE_MTYPE(RFAPI
, RFAPI_RFG_NAME
, "RFAPI RFGName");
57 DEFINE_MTYPE(RFAPI
, RFAPI_ADB
, "RFAPI Advertisement Data");
58 DEFINE_MTYPE(RFAPI
, RFAPI_ETI
, "RFAPI Export Table Info");
59 DEFINE_MTYPE(RFAPI
, RFAPI_NVE_ADDR
, "RFAPI NVE Address");
60 DEFINE_MTYPE(RFAPI
, RFAPI_PREFIX_BAG
, "RFAPI Prefix Bag");
61 DEFINE_MTYPE(RFAPI
, RFAPI_IT_EXTRA
, "RFAPI IT Extra");
62 DEFINE_MTYPE(RFAPI
, RFAPI_INFO
, "RFAPI Info");
63 DEFINE_MTYPE(RFAPI
, RFAPI_ADDR
, "RFAPI Addr");
64 DEFINE_MTYPE(RFAPI
, RFAPI_UPDATED_RESPONSE_QUEUE
, "RFAPI Updated Rsp Queue");
65 DEFINE_MTYPE(RFAPI
, RFAPI_RECENT_DELETE
, "RFAPI Recently Deleted Route");
66 DEFINE_MTYPE(RFAPI
, RFAPI_L2ADDR_OPT
, "RFAPI L2 Address Option");
67 DEFINE_MTYPE(RFAPI
, RFAPI_AP
, "RFAPI Advertised Prefix");
68 DEFINE_MTYPE(RFAPI
, RFAPI_MONITOR_ETH
, "RFAPI Monitor Ethernet");
70 DEFINE_QOBJ_TYPE(rfapi_nve_group_cfg
);
71 DEFINE_QOBJ_TYPE(rfapi_l2_group_cfg
);
72 /***********************************************************************
74 ***********************************************************************/
78 * compaitibility to old quagga_time call
79 * time_t value in terms of stabilised absolute time.
80 * replacement for POSIX time()
82 time_t rfapi_time(time_t *t
)
84 time_t clock
= monotime(NULL
);
90 void nve_group_to_nve_list(struct rfapi_nve_group_cfg
*rfg
, struct list
**nves
,
91 uint8_t family
) /* AF_INET, AF_INET6 */
94 struct rfapi_descriptor
*rfd
;
97 * loop over nves in this grp, add to list
99 for (ALL_LIST_ELEMENTS_RO(rfg
->nves
, hln
, rfd
)) {
100 if (rfd
->vn_addr
.addr_family
== family
) {
103 listnode_add(*nves
, rfd
);
109 struct rfapi_nve_group_cfg
*bgp_rfapi_cfg_match_group(struct rfapi_cfg
*hc
,
113 struct rfapi_nve_group_cfg
*rfg_vn
= NULL
;
114 struct rfapi_nve_group_cfg
*rfg_un
= NULL
;
116 struct agg_table
*rt_vn
;
117 struct agg_table
*rt_un
;
118 struct agg_node
*rn_vn
;
119 struct agg_node
*rn_un
;
121 struct rfapi_nve_group_cfg
*rfg
;
122 struct listnode
*node
, *nnode
;
124 switch (vn
->family
) {
126 rt_vn
= hc
->nve_groups_vn
[AFI_IP
];
129 rt_vn
= hc
->nve_groups_vn
[AFI_IP6
];
135 switch (un
->family
) {
137 rt_un
= hc
->nve_groups_un
[AFI_IP
];
140 rt_un
= hc
->nve_groups_un
[AFI_IP6
];
146 rn_vn
= agg_node_match(rt_vn
, vn
); /* NB locks node */
148 rfg_vn
= rn_vn
->info
;
149 agg_unlock_node(rn_vn
);
152 rn_un
= agg_node_match(rt_un
, un
); /* NB locks node */
154 rfg_un
= rn_un
->info
;
155 agg_unlock_node(rn_un
);
158 #ifdef BGP_VNC_DEBUG_MATCH_GROUP
160 vnc_zlog_debug_verbose("%s: vn prefix: %pFX", __func__
, vn
);
161 vnc_zlog_debug_verbose("%s: un prefix: %pFX", __func__
, un
);
162 vnc_zlog_debug_verbose(
163 "%s: rn_vn=%p, rn_un=%p, rfg_vn=%p, rfg_un=%p",
164 __func__
, rn_vn
, rn_un
, rfg_vn
, rfg_un
);
169 if (rfg_un
== rfg_vn
) /* same group */
171 if (!rfg_un
) /* un doesn't match, return vn-matched grp */
173 if (!rfg_vn
) /* vn doesn't match, return un-matched grp */
177 * Two different nve groups match: the group configured earlier wins.
178 * For now, just walk the sequential list and pick the first one.
179 * If this approach is too slow, then store serial numbers in the
180 * nve group structures as they are defined and just compare
183 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
, rfg
)) {
184 if ((rfg
== rfg_un
) || (rfg
== rfg_vn
)) {
188 vnc_zlog_debug_verbose(
189 "%s: shouldn't happen, returning NULL when un and vn match",
191 return NULL
; /* shouldn't happen */
194 /*------------------------------------------
195 * rfapi_get_rfp_start_val
197 * Returns value passed to rfapi on rfp_start
200 * void * bgp structure
204 *------------------------------------------*/
205 void *rfapi_get_rfp_start_val(void *bgpv
)
207 struct bgp
*bgp
= bgpv
;
208 if (bgp
== NULL
|| bgp
->rfapi
== NULL
)
210 return bgp
->rfapi
->rfp
;
213 /*------------------------------------------
214 * bgp_rfapi_is_vnc_configured
216 * Returns if VNC is configured
219 * bgp NULL (=use default instance)
223 * return value: If VNC is configured for the bgpd instance
225 * EPERM Not Default instance (VNC operations not allowed)
226 * ENXIO VNC not configured
227 --------------------------------------------*/
228 int bgp_rfapi_is_vnc_configured(struct bgp
*bgp
)
231 bgp
= bgp_get_default();
233 if (bgp
&& bgp
->inst_type
!= BGP_INSTANCE_TYPE_DEFAULT
)
236 if (bgp
&& bgp
->rfapi_cfg
)
241 /***********************************************************************
242 * VNC Configuration/CLI
243 ***********************************************************************/
244 #define VNC_VTY_CONFIG_CHECK(bgp) \
246 switch (bgp_rfapi_is_vnc_configured(bgp)) { \
249 "VNC operations only permitted on default BGP instance.\n"); \
250 return CMD_WARNING_CONFIG_FAILED; \
253 vty_out(vty, "VNC not configured.\n"); \
254 return CMD_WARNING_CONFIG_FAILED; \
261 DEFUN (vnc_advertise_un_method
,
262 vnc_advertise_un_method_cmd
,
263 "vnc advertise-un-method encap-attr",
265 "Method of advertising UN addresses\n"
266 "Via Tunnel Encap attribute (in VPN SAFI)\n")
268 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
269 VNC_VTY_CONFIG_CHECK(bgp
);
271 if (!strncmp(argv
[2]->arg
, "encap-safi", 7)) {
272 bgp
->rfapi_cfg
->flags
|= BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
;
274 bgp
->rfapi_cfg
->flags
&= ~BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
;
280 /*-------------------------------------------------------------------------
282 *-----------------------------------------------------------------------*/
285 DEFUN_NOSH (vnc_defaults
,
287 "vnc defaults", VNC_CONFIG_STR
"Configure default NVE group\n")
289 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
290 VNC_VTY_CONFIG_CHECK(bgp
);
291 if (bgp
->inst_type
!= BGP_INSTANCE_TYPE_DEFAULT
) {
292 vty_out(vty
, "Malformed community-list value\n");
293 return CMD_WARNING_CONFIG_FAILED
;
295 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
299 static int set_ecom_list(struct vty
*vty
, int argc
, struct cmd_token
**argv
,
300 struct ecommunity
**list
)
302 struct ecommunity
*ecom
= NULL
;
303 struct ecommunity
*ecomadd
;
305 for (; argc
; --argc
, ++argv
) {
307 ecomadd
= ecommunity_str2com(argv
[0]->arg
,
308 ECOMMUNITY_ROUTE_TARGET
, 0);
310 vty_out(vty
, "Malformed community-list value\n");
312 ecommunity_free(&ecom
);
313 return CMD_WARNING_CONFIG_FAILED
;
317 ecommunity_merge(ecom
, ecomadd
);
318 ecommunity_free(&ecomadd
);
325 ecommunity_free(&*list
);
332 DEFUN (vnc_defaults_rt_import
,
333 vnc_defaults_rt_import_cmd
,
334 "rt import RTLIST...",
335 "Specify default route targets\n"
337 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
339 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
340 return set_ecom_list(vty
, argc
- 2, argv
+ 2,
341 &bgp
->rfapi_cfg
->default_rt_import_list
);
344 DEFUN (vnc_defaults_rt_export
,
345 vnc_defaults_rt_export_cmd
,
346 "rt export RTLIST...",
347 "Configure default route targets\n"
349 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
351 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
352 return set_ecom_list(vty
, argc
- 2, argv
+ 2,
353 &bgp
->rfapi_cfg
->default_rt_export_list
);
356 DEFUN (vnc_defaults_rt_both
,
357 vnc_defaults_rt_both_cmd
,
359 "Configure default route targets\n"
360 "Export+import filters\n"
361 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
363 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
366 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
367 &bgp
->rfapi_cfg
->default_rt_import_list
);
368 if (rc
!= CMD_SUCCESS
)
370 return set_ecom_list(vty
, argc
- 2, argv
+ 2,
371 &bgp
->rfapi_cfg
->default_rt_export_list
);
374 DEFUN (vnc_defaults_rd
,
376 "rd ASN:NN_OR_IP-ADDRESS:NN",
377 "Specify default route distinguisher\n"
378 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:vn:<number> )\n")
380 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
382 struct prefix_rd prd
;
384 if (!strncmp(argv
[1]->arg
, "auto:vn:", 8)) {
386 * use AF_UNIX to designate automatically-assigned RD
387 * auto:vn:nn where nn is a 2-octet quantity
390 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
391 uint16_t value
= value32
& 0xffff;
393 if (!argv
[1]->arg
[8] || *end
) {
394 vty_out(vty
, "%% Malformed rd\n");
395 return CMD_WARNING_CONFIG_FAILED
;
397 if (value32
> 0xffff) {
398 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
400 return CMD_WARNING_CONFIG_FAILED
;
403 memset(&prd
, 0, sizeof(prd
));
404 prd
.family
= AF_UNIX
;
406 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
407 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
408 prd
.val
[6] = (value
>> 8) & 0x0ff;
409 prd
.val
[7] = value
& 0x0ff;
413 /* TODO: save RD format */
414 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
416 vty_out(vty
, "%% Malformed rd\n");
417 return CMD_WARNING_CONFIG_FAILED
;
421 bgp
->rfapi_cfg
->default_rd
= prd
;
425 DEFUN (vnc_defaults_l2rd
,
426 vnc_defaults_l2rd_cmd
,
427 "l2rd <(1-255)|auto-vn>",
428 "Specify default Local Nve ID value to use in RD for L2 routes\n"
429 "Fixed value 1-255\n"
430 "use the low-order octet of the NVE's VN address\n")
432 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
435 if (strmatch(argv
[1]->text
, "auto-vn")) {
439 unsigned long value_l
= strtoul(argv
[1]->arg
, &end
, 10);
441 value
= value_l
& 0xff;
442 if (!argv
[1]->arg
[0] || *end
) {
443 vty_out(vty
, "%% Malformed l2 nve ID \"%s\"\n",
445 return CMD_WARNING_CONFIG_FAILED
;
447 if ((value_l
< 1) || (value_l
> 0xff)) {
449 "%% Malformed l2 nve id (must be greater than 0 and less than %u\n",
451 return CMD_WARNING_CONFIG_FAILED
;
454 bgp
->rfapi_cfg
->flags
|= BGP_VNC_CONFIG_L2RD
;
455 bgp
->rfapi_cfg
->default_l2rd
= value
;
460 DEFUN (vnc_defaults_no_l2rd
,
461 vnc_defaults_no_l2rd_cmd
,
464 "Specify default Local Nve ID value to use in RD for L2 routes\n")
466 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
468 bgp
->rfapi_cfg
->default_l2rd
= 0;
469 bgp
->rfapi_cfg
->flags
&= ~BGP_VNC_CONFIG_L2RD
;
474 DEFUN (vnc_defaults_responselifetime
,
475 vnc_defaults_responselifetime_cmd
,
476 "response-lifetime <LIFETIME|infinite>",
477 "Specify default response lifetime\n"
478 "Response lifetime in seconds\n" "Infinite response lifetime\n")
480 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
482 struct rfapi
*h
= NULL
;
483 struct listnode
*hdnode
;
484 struct rfapi_descriptor
*rfd
;
488 return CMD_WARNING_CONFIG_FAILED
;
490 if (strmatch(argv
[1]->text
, "infinite")) {
491 rspint
= RFAPI_INFINITE_LIFETIME
;
493 rspint
= strtoul(argv
[1]->arg
, NULL
, 10);
494 if (rspint
> INT32_MAX
)
495 rspint
= INT32_MAX
; /* is really an int, not an unsigned
499 bgp
->rfapi_cfg
->default_response_lifetime
= rspint
;
501 for (ALL_LIST_ELEMENTS_RO(&h
->descriptors
, hdnode
, rfd
))
503 && !(rfd
->rfg
->flags
& RFAPI_RFG_RESPONSE_LIFETIME
))
504 rfd
->response_lifetime
= rfd
->rfg
->response_lifetime
=
510 struct rfapi_nve_group_cfg
*
511 bgp_rfapi_cfg_match_byname(struct bgp
*bgp
, const char *name
,
512 rfapi_group_cfg_type_t type
) /* _MAX = any */
514 struct rfapi_nve_group_cfg
*rfg
;
515 struct listnode
*node
, *nnode
;
517 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->nve_groups_sequential
, node
,
519 if ((type
== RFAPI_GROUP_CFG_MAX
|| type
== rfg
->type
)
520 && !strcmp(rfg
->name
, name
))
526 static struct rfapi_nve_group_cfg
*
527 rfapi_group_new(struct bgp
*bgp
, rfapi_group_cfg_type_t type
, const char *name
)
529 struct rfapi_nve_group_cfg
*rfg
;
531 rfg
= XCALLOC(MTYPE_RFAPI_GROUP_CFG
,
532 sizeof(struct rfapi_nve_group_cfg
));
534 rfg
->name
= strdup(name
);
535 /* add to tail of list */
536 listnode_add(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
);
537 rfg
->label
= MPLS_LABEL_NONE
;
539 QOBJ_REG(rfg
, rfapi_nve_group_cfg
);
544 static struct rfapi_l2_group_cfg
*rfapi_l2_group_lookup_byname(struct bgp
*bgp
,
547 struct rfapi_l2_group_cfg
*rfg
;
548 struct listnode
*node
, *nnode
;
550 if (bgp
->rfapi_cfg
->l2_groups
== NULL
) /* not the best place for this */
551 bgp
->rfapi_cfg
->l2_groups
= list_new();
553 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->l2_groups
, node
, nnode
, rfg
)) {
554 if (!strcmp(rfg
->name
, name
))
560 static struct rfapi_l2_group_cfg
*rfapi_l2_group_new(void)
562 struct rfapi_l2_group_cfg
*rfg
;
564 rfg
= XCALLOC(MTYPE_RFAPI_L2_CFG
, sizeof(struct rfapi_l2_group_cfg
));
565 QOBJ_REG(rfg
, rfapi_l2_group_cfg
);
570 static void rfapi_l2_group_del(struct rfapi_l2_group_cfg
*rfg
)
573 XFREE(MTYPE_RFAPI_L2_CFG
, rfg
);
576 static int rfapi_str2route_type(const char *l3str
, const char *pstr
, afi_t
*afi
,
582 if (!strcmp(l3str
, "ipv4")) {
585 if (!strcmp(l3str
, "ipv6"))
591 if (!strcmp(pstr
, "connected"))
592 *type
= ZEBRA_ROUTE_CONNECT
;
593 if (!strcmp(pstr
, "kernel"))
594 *type
= ZEBRA_ROUTE_KERNEL
;
595 if (!strcmp(pstr
, "static"))
596 *type
= ZEBRA_ROUTE_STATIC
;
597 if (!strcmp(pstr
, "bgp"))
598 *type
= ZEBRA_ROUTE_BGP
;
599 if (!strcmp(pstr
, "bgp-direct"))
600 *type
= ZEBRA_ROUTE_BGP_DIRECT
;
601 if (!strcmp(pstr
, "bgp-direct-to-nve-groups"))
602 *type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
604 if (!strcmp(pstr
, "rip")) {
606 *type
= ZEBRA_ROUTE_RIP
;
608 *type
= ZEBRA_ROUTE_RIPNG
;
611 if (!strcmp(pstr
, "ripng")) {
614 *type
= ZEBRA_ROUTE_RIPNG
;
617 if (!strcmp(pstr
, "ospf")) {
619 *type
= ZEBRA_ROUTE_OSPF
;
621 *type
= ZEBRA_ROUTE_OSPF6
;
624 if (!strcmp(pstr
, "ospf6")) {
627 *type
= ZEBRA_ROUTE_OSPF6
;
633 /*-------------------------------------------------------------------------
635 *-----------------------------------------------------------------------*/
637 #define VNC_REDIST_ENABLE(bgp, afi, type) \
640 case ZEBRA_ROUTE_BGP_DIRECT: \
641 vnc_import_bgp_redist_enable((bgp), (afi)); \
643 case ZEBRA_ROUTE_BGP_DIRECT_EXT: \
644 vnc_import_bgp_exterior_redist_enable((bgp), (afi)); \
647 if ((type) < ZEBRA_ROUTE_MAX) \
648 vnc_redistribute_set((bgp), (afi), (type)); \
653 #define VNC_REDIST_DISABLE(bgp, afi, type) \
656 case ZEBRA_ROUTE_BGP_DIRECT: \
657 vnc_import_bgp_redist_disable((bgp), (afi)); \
659 case ZEBRA_ROUTE_BGP_DIRECT_EXT: \
660 vnc_import_bgp_exterior_redist_disable((bgp), (afi)); \
663 if ((type) < ZEBRA_ROUTE_MAX) \
664 vnc_redistribute_unset((bgp), (afi), (type)); \
669 static uint8_t redist_was_enabled
[AFI_MAX
][ZEBRA_ROUTE_MAX
];
671 static void vnc_redistribute_prechange(struct bgp
*bgp
)
676 vnc_zlog_debug_verbose("%s: entry", __func__
);
677 memset(redist_was_enabled
, 0, sizeof(redist_was_enabled
));
680 * Look to see if we have any redistribution enabled. If so, flush
681 * the corresponding routes and turn off redistribution temporarily.
682 * We need to do it because the RD's used for the redistributed
683 * routes depend on the nve group.
685 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
686 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
687 if (bgp
->rfapi_cfg
->redist
[afi
][type
]) {
688 redist_was_enabled
[afi
][type
] = 1;
689 VNC_REDIST_DISABLE(bgp
, afi
, type
);
693 vnc_zlog_debug_verbose("%s: return", __func__
);
696 static void vnc_redistribute_postchange(struct bgp
*bgp
)
701 vnc_zlog_debug_verbose("%s: entry", __func__
);
703 * If we turned off redistribution above, turn it back on. Doing so
704 * will tell zebra to resend the routes to us
706 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
707 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
708 if (redist_was_enabled
[afi
][type
]) {
709 VNC_REDIST_ENABLE(bgp
, afi
, type
);
713 vnc_zlog_debug_verbose("%s: return", __func__
);
716 DEFUN (vnc_redistribute_rh_roo_localadmin
,
717 vnc_redistribute_rh_roo_localadmin_cmd
,
718 "vnc redistribute resolve-nve roo-ec-local-admin (0-65535)",
720 "Redistribute routes into VNC\n"
722 "Route Origin Extended Community Local Admin Field\n" "Field value\n")
724 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
728 VNC_VTY_CONFIG_CHECK(bgp
);
730 localadmin
= strtoul(argv
[4]->arg
, &endptr
, 0);
731 if (!argv
[4]->arg
[0] || *endptr
) {
732 vty_out(vty
, "%% Malformed value\n");
733 return CMD_WARNING_CONFIG_FAILED
;
736 if (localadmin
> 0xffff) {
737 vty_out(vty
, "%% Value out of range (0-%d)\n", 0xffff);
738 return CMD_WARNING_CONFIG_FAILED
;
741 if (bgp
->rfapi_cfg
->resolve_nve_roo_local_admin
== localadmin
)
744 if ((bgp
->rfapi_cfg
->flags
& BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
)
745 == BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE
) {
747 vnc_export_bgp_prechange(bgp
);
749 vnc_redistribute_prechange(bgp
);
751 bgp
->rfapi_cfg
->resolve_nve_roo_local_admin
= localadmin
;
753 if ((bgp
->rfapi_cfg
->flags
& BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
)
754 == BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE
) {
756 vnc_export_bgp_postchange(bgp
);
758 vnc_redistribute_postchange(bgp
);
764 DEFUN (vnc_redistribute_mode
,
765 vnc_redistribute_mode_cmd
,
766 "vnc redistribute mode <nve-group|plain|resolve-nve>",
768 "Redistribute routes into VNC\n"
769 "Redistribution mode\n"
770 "Based on redistribute nve-group\n"
771 "Unmodified\n" "Resolve each nexthop to connected NVEs\n")
773 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
774 vnc_redist_mode_t newmode
;
776 VNC_VTY_CONFIG_CHECK(bgp
);
778 switch (argv
[3]->arg
[0]) {
780 newmode
= VNC_REDIST_MODE_RFG
;
784 newmode
= VNC_REDIST_MODE_PLAIN
;
788 newmode
= VNC_REDIST_MODE_RESOLVE_NVE
;
792 vty_out(vty
, "unknown redistribute mode\n");
793 return CMD_WARNING_CONFIG_FAILED
;
796 if (newmode
!= bgp
->rfapi_cfg
->redist_mode
) {
797 vnc_redistribute_prechange(bgp
);
798 bgp
->rfapi_cfg
->redist_mode
= newmode
;
799 vnc_redistribute_postchange(bgp
);
805 DEFUN (vnc_redistribute_protocol
,
806 vnc_redistribute_protocol_cmd
,
807 "vnc redistribute <ipv4|ipv6> <bgp|bgp-direct|bgp-direct-to-nve-groups|connected|kernel|ospf|rip|static>",
809 "Redistribute routes into VNC\n"
813 "From BGP without Zebra\n"
814 "From BGP without Zebra, only to configured NVE groups\n"
815 "Connected interfaces\n"
816 "From kernel routes\n"
817 "From Open Shortest Path First (OSPF)\n"
818 "From Routing Information Protocol (RIP)\n" "From Static routes\n")
820 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
821 int type
= ZEBRA_ROUTE_MAX
; /* init to bogus value */
824 VNC_VTY_CONFIG_CHECK(bgp
);
826 if (rfapi_str2route_type(argv
[2]->arg
, argv
[3]->arg
, &afi
, &type
)) {
827 vty_out(vty
, "%% Invalid route type\n");
828 return CMD_WARNING_CONFIG_FAILED
;
831 if (type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
) {
832 if (bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
) {
833 VNC_REDIST_DISABLE(bgp
, afi
,
834 type
); /* disabled view implicitly */
835 free(bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
);
836 bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
= NULL
;
838 bgp
->rfapi_cfg
->redist_bgp_exterior_view
= bgp
;
841 VNC_REDIST_ENABLE(bgp
, afi
, type
);
846 DEFUN (vnc_no_redistribute_protocol
,
847 vnc_no_redistribute_protocol_cmd
,
848 "no vnc redistribute <ipv4|ipv6> <bgp|bgp-direct|bgp-direct-to-nve-groups|connected|kernel|ospf|rip|static>",
851 "Redistribute from other protocol\n"
855 "From BGP without Zebra\n"
856 "From BGP without Zebra, only to configured NVE groups\n"
857 "Connected interfaces\n"
858 "From kernel routes\n"
859 "From Open Shortest Path First (OSPF)\n"
860 "From Routing Information Protocol (RIP)\n" "From Static routes\n")
862 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
866 VNC_VTY_CONFIG_CHECK(bgp
);
868 if (rfapi_str2route_type(argv
[3]->arg
, argv
[4]->arg
, &afi
, &type
)) {
869 vty_out(vty
, "%% Invalid route type\n");
870 return CMD_WARNING_CONFIG_FAILED
;
873 VNC_REDIST_DISABLE(bgp
, afi
, type
);
875 if (type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
) {
876 if (bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
) {
877 free(bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
);
878 bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
= NULL
;
880 bgp
->rfapi_cfg
->redist_bgp_exterior_view
= NULL
;
886 DEFUN (vnc_redistribute_bgp_exterior
,
887 vnc_redistribute_bgp_exterior_cmd
,
888 "vnc redistribute <ipv4|ipv6> bgp-direct-to-nve-groups view NAME",
890 "Redistribute routes into VNC\n"
893 "From BGP without Zebra, only to configured NVE groups\n"
894 "From BGP view\n" "BGP view name\n")
896 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
900 VNC_VTY_CONFIG_CHECK(bgp
);
902 if (rfapi_str2route_type(argv
[2]->arg
, "bgp-direct-to-nve-groups", &afi
,
904 vty_out(vty
, "%% Invalid route type\n");
905 return CMD_WARNING_CONFIG_FAILED
;
908 if (bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
)
909 free(bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
);
910 bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
= strdup(argv
[5]->arg
);
911 /* could be NULL if name is not defined yet */
912 bgp
->rfapi_cfg
->redist_bgp_exterior_view
=
913 bgp_lookup_by_name(argv
[5]->arg
);
915 VNC_REDIST_ENABLE(bgp
, afi
, type
);
920 DEFUN (vnc_redistribute_nvegroup
,
921 vnc_redistribute_nvegroup_cmd
,
922 "vnc redistribute nve-group NAME",
924 "Assign a NVE group to routes redistributed from another routing protocol\n"
925 "NVE group\n" "Group name\n")
927 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
928 VNC_VTY_CONFIG_CHECK(bgp
);
930 vnc_redistribute_prechange(bgp
);
933 * OK if nve group doesn't exist yet; we'll set the pointer
934 * when the group is defined later
936 bgp
->rfapi_cfg
->rfg_redist
= bgp_rfapi_cfg_match_byname(
937 bgp
, argv
[3]->arg
, RFAPI_GROUP_CFG_NVE
);
938 if (bgp
->rfapi_cfg
->rfg_redist_name
)
939 free(bgp
->rfapi_cfg
->rfg_redist_name
);
940 bgp
->rfapi_cfg
->rfg_redist_name
= strdup(argv
[3]->arg
);
942 vnc_redistribute_postchange(bgp
);
947 DEFUN (vnc_redistribute_no_nvegroup
,
948 vnc_redistribute_no_nvegroup_cmd
,
949 "no vnc redistribute nve-group",
952 "Redistribute from other protocol\n"
953 "Assign a NVE group to routes redistributed from another routing protocol\n")
955 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
957 VNC_VTY_CONFIG_CHECK(bgp
);
959 vnc_redistribute_prechange(bgp
);
961 bgp
->rfapi_cfg
->rfg_redist
= NULL
;
962 if (bgp
->rfapi_cfg
->rfg_redist_name
)
963 free(bgp
->rfapi_cfg
->rfg_redist_name
);
964 bgp
->rfapi_cfg
->rfg_redist_name
= NULL
;
966 vnc_redistribute_postchange(bgp
);
972 DEFUN (vnc_redistribute_lifetime
,
973 vnc_redistribute_lifetime_cmd
,
974 "vnc redistribute lifetime <LIFETIME|infinite>",
977 "Assign a lifetime to routes redistributed from another routing protocol\n"
978 "lifetime value (32 bit)\n"
979 "Allow lifetime to never expire\n")
981 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
982 VNC_VTY_CONFIG_CHECK(bgp
);
984 vnc_redistribute_prechange(bgp
);
986 if (strmatch(argv
[3]->text
, "infinite")) {
987 bgp
->rfapi_cfg
->redist_lifetime
= RFAPI_INFINITE_LIFETIME
;
989 bgp
->rfapi_cfg
->redist_lifetime
=
990 strtoul(argv
[3]->arg
, NULL
, 10);
993 vnc_redistribute_postchange(bgp
);
998 /*-- redist policy, non-nvegroup start --*/
1000 DEFUN (vnc_redist_bgpdirect_no_prefixlist
,
1001 vnc_redist_bgpdirect_no_prefixlist_cmd
,
1002 "no vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> <ipv4|ipv6> prefix-list",
1005 "Redistribute from other protocol\n"
1006 "Redistribute from BGP directly\n"
1007 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1009 "IPv6 routes\n" "Prefix-list for filtering redistributed routes\n")
1011 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1013 struct rfapi_cfg
*hc
;
1014 uint8_t route_type
= 0;
1016 VNC_VTY_CONFIG_CHECK(bgp
);
1017 hc
= bgp
->rfapi_cfg
;
1019 if (strmatch(argv
[3]->text
, "bgp-direct")) {
1020 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1022 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1025 if (strmatch(argv
[4]->text
, "ipv4")) {
1031 vnc_redistribute_prechange(bgp
);
1033 if (hc
->plist_redist_name
[route_type
][afi
])
1034 free(hc
->plist_redist_name
[route_type
][afi
]);
1035 hc
->plist_redist_name
[route_type
][afi
] = NULL
;
1036 hc
->plist_redist
[route_type
][afi
] = NULL
;
1038 vnc_redistribute_postchange(bgp
);
1043 DEFUN (vnc_redist_bgpdirect_prefixlist
,
1044 vnc_redist_bgpdirect_prefixlist_cmd
,
1045 "vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> <ipv4|ipv6> prefix-list NAME",
1047 "Redistribute from other protocol\n"
1048 "Redistribute from BGP directly\n"
1049 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1052 "Prefix-list for filtering redistributed routes\n"
1053 "prefix list name\n")
1055 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1056 struct rfapi_cfg
*hc
;
1058 uint8_t route_type
= 0;
1060 VNC_VTY_CONFIG_CHECK(bgp
);
1061 hc
= bgp
->rfapi_cfg
;
1063 if (strmatch(argv
[2]->text
, "bgp-direct")) {
1064 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1066 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1069 if (strmatch(argv
[3]->text
, "ipv4")) {
1075 vnc_redistribute_prechange(bgp
);
1077 if (hc
->plist_redist_name
[route_type
][afi
])
1078 free(hc
->plist_redist_name
[route_type
][afi
]);
1079 hc
->plist_redist_name
[route_type
][afi
] = strdup(argv
[5]->arg
);
1080 hc
->plist_redist
[route_type
][afi
] =
1081 prefix_list_lookup(afi
, argv
[5]->arg
);
1083 vnc_redistribute_postchange(bgp
);
1088 DEFUN (vnc_redist_bgpdirect_no_routemap
,
1089 vnc_redist_bgpdirect_no_routemap_cmd
,
1090 "no vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> route-map",
1093 "Redistribute from other protocols\n"
1094 "Redistribute from BGP directly\n"
1095 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1096 "Route-map for filtering redistributed routes\n")
1098 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1099 struct rfapi_cfg
*hc
;
1100 uint8_t route_type
= 0;
1102 VNC_VTY_CONFIG_CHECK(bgp
);
1103 hc
= bgp
->rfapi_cfg
;
1105 if (strmatch(argv
[3]->text
, "bgp-direct")) {
1106 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1108 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1111 vnc_redistribute_prechange(bgp
);
1113 if (hc
->routemap_redist_name
[route_type
])
1114 free(hc
->routemap_redist_name
[route_type
]);
1115 hc
->routemap_redist_name
[route_type
] = NULL
;
1116 hc
->routemap_redist
[route_type
] = NULL
;
1118 vnc_redistribute_postchange(bgp
);
1123 DEFUN (vnc_redist_bgpdirect_routemap
,
1124 vnc_redist_bgpdirect_routemap_cmd
,
1125 "vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> route-map NAME",
1127 "Redistribute from other protocols\n"
1128 "Redistribute from BGP directly\n"
1129 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1130 "Route-map for filtering exported routes\n" "route map name\n")
1132 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1133 struct rfapi_cfg
*hc
;
1134 uint8_t route_type
= 0;
1136 VNC_VTY_CONFIG_CHECK(bgp
);
1137 hc
= bgp
->rfapi_cfg
;
1139 if (strmatch(argv
[2]->text
, "bgp-direct")) {
1140 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1142 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1145 vnc_redistribute_prechange(bgp
);
1147 if (hc
->routemap_redist_name
[route_type
])
1148 free(hc
->routemap_redist_name
[route_type
]);
1150 /* If the old route map config overwrite with new
1151 * route map config , old routemap counter have to be
1154 route_map_counter_decrement(hc
->routemap_redist
[route_type
]);
1155 hc
->routemap_redist_name
[route_type
] = strdup(argv
[4]->arg
);
1156 hc
->routemap_redist
[route_type
] =
1157 route_map_lookup_by_name(argv
[4]->arg
);
1158 route_map_counter_increment(hc
->routemap_redist
[route_type
]);
1160 vnc_redistribute_postchange(bgp
);
1165 /*-- redist policy, non-nvegroup end --*/
1167 /*-- redist policy, nvegroup start --*/
1169 DEFUN (vnc_nve_group_redist_bgpdirect_no_prefixlist
,
1170 vnc_nve_group_redist_bgpdirect_no_prefixlist_cmd
,
1171 "no redistribute bgp-direct <ipv4|ipv6> prefix-list",
1173 "Redistribute from other protocol\n"
1174 "Redistribute from BGP directly\n"
1177 "Prefix-list for filtering redistributed routes\n")
1179 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1180 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
)
1183 VNC_VTY_CONFIG_CHECK(bgp
);
1185 /* make sure it's still in list */
1186 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1187 /* Not in list anymore */
1188 vty_out(vty
, "Current NVE group no longer exists\n");
1189 return CMD_WARNING_CONFIG_FAILED
;
1192 if (strmatch(argv
[3]->text
, "ipv4")) {
1198 vnc_redistribute_prechange(bgp
);
1200 if (rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
])
1201 free(rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
]);
1202 rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] = NULL
;
1203 rfg
->plist_redist
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] = NULL
;
1205 vnc_redistribute_postchange(bgp
);
1210 DEFUN (vnc_nve_group_redist_bgpdirect_prefixlist
,
1211 vnc_nve_group_redist_bgpdirect_prefixlist_cmd
,
1212 "redistribute bgp-direct <ipv4|ipv6> prefix-list NAME",
1213 "Redistribute from other protocol\n"
1214 "Redistribute from BGP directly\n"
1217 "Prefix-list for filtering redistributed routes\n"
1218 "prefix list name\n")
1220 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1221 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1224 VNC_VTY_CONFIG_CHECK(bgp
);
1226 /* make sure it's still in list */
1227 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1228 /* Not in list anymore */
1229 vty_out(vty
, "Current NVE group no longer exists\n");
1230 return CMD_WARNING_CONFIG_FAILED
;
1233 if (strmatch(argv
[2]->text
, "ipv4")) {
1239 vnc_redistribute_prechange(bgp
);
1241 if (rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
])
1242 free(rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
]);
1243 rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] =
1244 strdup(argv
[4]->arg
);
1245 rfg
->plist_redist
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] =
1246 prefix_list_lookup(afi
, argv
[4]->arg
);
1248 vnc_redistribute_postchange(bgp
);
1253 DEFUN (vnc_nve_group_redist_bgpdirect_no_routemap
,
1254 vnc_nve_group_redist_bgpdirect_no_routemap_cmd
,
1255 "no redistribute bgp-direct route-map",
1257 "Redistribute from other protocols\n"
1258 "Redistribute from BGP directly\n"
1259 "Route-map for filtering redistributed routes\n")
1261 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1262 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1264 VNC_VTY_CONFIG_CHECK(bgp
);
1266 /* make sure it's still in list */
1267 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1268 /* Not in list anymore */
1269 vty_out(vty
, "Current NVE group no longer exists\n");
1270 return CMD_WARNING_CONFIG_FAILED
;
1273 vnc_redistribute_prechange(bgp
);
1275 if (rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
])
1276 free(rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]);
1277 route_map_counter_decrement(
1278 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
]);
1279 rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
] = NULL
;
1280 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
] = NULL
;
1282 vnc_redistribute_postchange(bgp
);
1287 DEFUN (vnc_nve_group_redist_bgpdirect_routemap
,
1288 vnc_nve_group_redist_bgpdirect_routemap_cmd
,
1289 "redistribute bgp-direct route-map NAME",
1290 "Redistribute from other protocols\n"
1291 "Redistribute from BGP directly\n"
1292 "Route-map for filtering exported routes\n" "route map name\n")
1294 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1295 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1297 VNC_VTY_CONFIG_CHECK(bgp
);
1299 /* make sure it's still in list */
1300 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1301 /* Not in list anymore */
1302 vty_out(vty
, "Current NVE group no longer exists\n");
1303 return CMD_WARNING_CONFIG_FAILED
;
1306 vnc_redistribute_prechange(bgp
);
1308 if (rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
])
1309 free(rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]);
1310 route_map_counter_decrement(
1311 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
]);
1312 rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
] =
1313 strdup(argv
[3]->arg
);
1314 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
] =
1315 route_map_lookup_by_name(argv
[3]->arg
);
1316 route_map_counter_increment(
1317 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
]);
1319 vnc_redistribute_postchange(bgp
);
1324 /*-- redist policy, nvegroup end --*/
1326 /*-------------------------------------------------------------------------
1328 *-----------------------------------------------------------------------*/
1330 DEFUN (vnc_export_mode
,
1331 vnc_export_mode_cmd
,
1332 "vnc export <bgp|zebra> mode <group-nve|ce|none|registering-nve>",
1334 "Export to other protocols\n"
1336 "Export to Zebra (experimental)\n"
1337 "Select export mode\n"
1338 "Export routes with nve-group next-hops\n"
1339 "Export routes with NVE connected router next-hops\n"
1340 "Disable export\n" "Export routes with registering NVE as next-hop\n")
1342 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1343 uint32_t oldmode
= 0;
1344 uint32_t newmode
= 0;
1346 VNC_VTY_CONFIG_CHECK(bgp
);
1348 if (argv
[2]->arg
[0] == 'b') {
1349 oldmode
= bgp
->rfapi_cfg
->flags
1350 & BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
;
1351 switch (argv
[4]->arg
[0]) {
1353 newmode
= BGP_VNC_CONFIG_EXPORT_BGP_MODE_GRP
;
1356 newmode
= BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE
;
1362 newmode
= BGP_VNC_CONFIG_EXPORT_BGP_MODE_RH
;
1365 vty_out(vty
, "Invalid mode specified\n");
1366 return CMD_WARNING_CONFIG_FAILED
;
1369 if (newmode
== oldmode
) {
1370 vty_out(vty
, "Mode unchanged\n");
1374 vnc_export_bgp_prechange(bgp
);
1376 bgp
->rfapi_cfg
->flags
&= ~BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
;
1377 bgp
->rfapi_cfg
->flags
|= newmode
;
1379 vnc_export_bgp_postchange(bgp
);
1384 * export to zebra with RH mode is not yet implemented
1387 "Changing modes for zebra export not implemented yet\n");
1388 return CMD_WARNING_CONFIG_FAILED
;
1394 static struct rfapi_rfg_name
*rfgn_new(void)
1396 return XCALLOC(MTYPE_RFAPI_RFG_NAME
, sizeof(struct rfapi_rfg_name
));
1399 static void rfgn_free(struct rfapi_rfg_name
*rfgn
)
1401 XFREE(MTYPE_RFAPI_RFG_NAME
, rfgn
);
1404 DEFUN (vnc_export_nvegroup
,
1405 vnc_export_nvegroup_cmd
,
1406 "vnc export <bgp|zebra> group-nve group NAME",
1408 "Export to other protocols\n"
1410 "Export to Zebra (experimental)\n"
1411 "NVE group, used in 'group-nve' export mode\n"
1412 "NVE group\n" "Group name\n")
1414 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1415 struct rfapi_nve_group_cfg
*rfg_new
;
1417 VNC_VTY_CONFIG_CHECK(bgp
);
1419 rfg_new
= bgp_rfapi_cfg_match_byname(bgp
, argv
[5]->arg
,
1420 RFAPI_GROUP_CFG_NVE
);
1421 if (rfg_new
== NULL
) {
1422 rfg_new
= bgp_rfapi_cfg_match_byname(bgp
, argv
[5]->arg
,
1423 RFAPI_GROUP_CFG_VRF
);
1425 vnc_add_vrf_opener(bgp
, rfg_new
);
1428 if (rfg_new
== NULL
) {
1429 vty_out(vty
, "Can't find group named \"%s\".\n", argv
[5]->arg
);
1430 return CMD_WARNING_CONFIG_FAILED
;
1433 if (argv
[2]->arg
[0] == 'b') {
1435 struct listnode
*node
;
1436 struct rfapi_rfg_name
*rfgn
;
1439 * Set group for export to BGP Direct
1442 /* see if group is already included in export list */
1443 for (ALL_LIST_ELEMENTS_RO(
1444 bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
1447 if (!strcmp(rfgn
->name
, argv
[5]->arg
)) {
1448 /* already in the list: we're done */
1454 rfgn
->name
= strdup(argv
[5]->arg
);
1455 rfgn
->rfg
= rfg_new
; /* OK if not set yet */
1457 listnode_add(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, rfgn
);
1459 vnc_zlog_debug_verbose("%s: testing rfg_new", __func__
);
1461 vnc_zlog_debug_verbose(
1462 "%s: testing bgp grp mode enabled", __func__
);
1463 if (VNC_EXPORT_BGP_GRP_ENABLED(bgp
->rfapi_cfg
))
1464 vnc_zlog_debug_verbose(
1465 "%s: calling vnc_direct_bgp_add_group",
1467 vnc_direct_bgp_add_group(bgp
, rfg_new
);
1472 struct listnode
*node
;
1473 struct rfapi_rfg_name
*rfgn
;
1476 * Set group for export to Zebra
1479 /* see if group is already included in export list */
1480 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
,
1483 if (!strcmp(rfgn
->name
, argv
[5]->arg
)) {
1484 /* already in the list: we're done */
1490 rfgn
->name
= strdup(argv
[5]->arg
);
1491 rfgn
->rfg
= rfg_new
; /* OK if not set yet */
1493 listnode_add(bgp
->rfapi_cfg
->rfg_export_zebra_l
, rfgn
);
1496 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(bgp
->rfapi_cfg
))
1497 vnc_zebra_add_group(bgp
, rfg_new
);
1505 * This command applies to routes exported from VNC to BGP directly
1506 * without going though zebra
1508 DEFUN (vnc_no_export_nvegroup
,
1509 vnc_no_export_nvegroup_cmd
,
1510 "vnc export <bgp|zebra> group-nve no group NAME",
1512 "Export to other protocols\n"
1514 "Export to Zebra (experimental)\n"
1515 "NVE group, used in 'group-nve' export mode\n"
1516 "Disable export of VNC routes\n" "NVE group\n" "Group name\n")
1518 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1519 struct listnode
*node
, *nnode
;
1520 struct rfapi_rfg_name
*rfgn
;
1522 VNC_VTY_CONFIG_CHECK(bgp
);
1524 if (argv
[2]->arg
[0] == 'b') {
1525 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
,
1526 node
, nnode
, rfgn
)) {
1528 if (rfgn
->name
&& !strcmp(rfgn
->name
, argv
[6]->arg
)) {
1529 vnc_zlog_debug_verbose("%s: matched \"%s\"",
1530 __func__
, rfgn
->name
);
1532 vnc_direct_bgp_del_group(bgp
,
1536 bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
,
1543 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
1546 vnc_zlog_debug_verbose("does rfg \"%s\" match?",
1548 if (rfgn
->name
&& !strcmp(rfgn
->name
, argv
[6]->arg
)) {
1550 vnc_zebra_del_group(bgp
, rfgn
->rfg
);
1553 bgp
->rfapi_cfg
->rfg_export_zebra_l
,
1563 DEFUN (vnc_nve_group_export_no_prefixlist
,
1564 vnc_nve_group_export_no_prefixlist_cmd
,
1565 "no export <bgp|zebra> <ipv4|ipv6> prefix-list [NAME]",
1567 "Export to other protocols\n"
1569 "Export to Zebra (experimental)\n"
1572 "Prefix-list for filtering exported routes\n" "prefix list name\n")
1574 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1575 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1580 VNC_VTY_CONFIG_CHECK(bgp
);
1582 /* make sure it's still in list */
1583 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1584 /* Not in list anymore */
1585 vty_out(vty
, "Current NVE group no longer exists\n");
1586 return CMD_WARNING_CONFIG_FAILED
;
1589 if (!argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
1590 vty_out(vty
, "%% Malformed Address Family\n");
1591 return CMD_WARNING_CONFIG_FAILED
;
1594 if (argv
[idx
- 1]->text
[0] == 'z')
1596 idx
+= 2; /* skip afi and keyword */
1600 || (rfg
->plist_export_bgp_name
[afi
]
1601 && strmatch(argv
[idx
]->arg
,
1602 rfg
->plist_export_bgp_name
[afi
]))) {
1603 if (rfg
->plist_export_bgp_name
[afi
])
1604 free(rfg
->plist_export_bgp_name
[afi
]);
1605 rfg
->plist_export_bgp_name
[afi
] = NULL
;
1606 rfg
->plist_export_bgp
[afi
] = NULL
;
1608 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, afi
);
1612 || (rfg
->plist_export_zebra_name
[afi
]
1613 && strmatch(argv
[idx
]->arg
,
1614 rfg
->plist_export_zebra_name
[afi
]))) {
1615 if (rfg
->plist_export_zebra_name
[afi
])
1616 free(rfg
->plist_export_zebra_name
[afi
]);
1617 rfg
->plist_export_zebra_name
[afi
] = NULL
;
1618 rfg
->plist_export_zebra
[afi
] = NULL
;
1620 vnc_zebra_reexport_group_afi(bgp
, rfg
, afi
);
1626 ALIAS (vnc_nve_group_export_no_prefixlist
,
1627 vnc_vrf_policy_export_no_prefixlist_cmd
,
1628 "no export <ipv4|ipv6> prefix-list [NAME]",
1633 "Prefix-list for filtering exported routes\n" "prefix list name\n")
1635 DEFUN (vnc_nve_group_export_prefixlist
,
1636 vnc_nve_group_export_prefixlist_cmd
,
1637 "export <bgp|zebra> <ipv4|ipv6> prefix-list NAME",
1638 "Export to other protocols\n"
1640 "Export to Zebra (experimental)\n"
1643 "Prefix-list for filtering exported routes\n" "prefix list name\n")
1645 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1646 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1651 VNC_VTY_CONFIG_CHECK(bgp
);
1653 /* make sure it's still in list */
1654 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1655 /* Not in list anymore */
1656 vty_out(vty
, "Current NVE group no longer exists\n");
1657 return CMD_WARNING_CONFIG_FAILED
;
1660 if (!argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
1661 vty_out(vty
, "%% Malformed Address Family\n");
1662 return CMD_WARNING_CONFIG_FAILED
;
1665 if (argv
[idx
- 1]->text
[0] == 'z')
1670 if (rfg
->plist_export_bgp_name
[afi
])
1671 free(rfg
->plist_export_bgp_name
[afi
]);
1672 rfg
->plist_export_bgp_name
[afi
] = strdup(argv
[idx
]->arg
);
1673 rfg
->plist_export_bgp
[afi
] =
1674 prefix_list_lookup(afi
, argv
[idx
]->arg
);
1676 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, afi
);
1679 if (rfg
->plist_export_zebra_name
[afi
])
1680 free(rfg
->plist_export_zebra_name
[afi
]);
1681 rfg
->plist_export_zebra_name
[afi
] = strdup(argv
[idx
]->arg
);
1682 rfg
->plist_export_zebra
[afi
] =
1683 prefix_list_lookup(afi
, argv
[idx
]->arg
);
1685 vnc_zebra_reexport_group_afi(bgp
, rfg
, afi
);
1690 ALIAS (vnc_nve_group_export_prefixlist
,
1691 vnc_vrf_policy_export_prefixlist_cmd
,
1692 "export <ipv4|ipv6> prefix-list NAME",
1696 "Prefix-list for filtering exported routes\n" "prefix list name\n")
1698 DEFUN (vnc_nve_group_export_no_routemap
,
1699 vnc_nve_group_export_no_routemap_cmd
,
1700 "no export <bgp|zebra> route-map [NAME]",
1702 "Export to other protocols\n"
1704 "Export to Zebra (experimental)\n"
1705 "Route-map for filtering exported routes\n" "route map name\n")
1707 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1708 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1712 VNC_VTY_CONFIG_CHECK(bgp
);
1714 /* make sure it's still in list */
1715 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1716 /* Not in list anymore */
1717 vty_out(vty
, "Current NVE group no longer exists\n");
1718 return CMD_WARNING_CONFIG_FAILED
;
1720 switch (argv
[idx
]->text
[0]) {
1727 default: /* route-map */
1734 || (rfg
->routemap_export_bgp_name
1735 && strmatch(argv
[idx
]->arg
,
1736 rfg
->routemap_export_bgp_name
))) {
1737 if (rfg
->routemap_export_bgp_name
)
1738 free(rfg
->routemap_export_bgp_name
);
1739 route_map_counter_decrement(rfg
->routemap_export_bgp
);
1740 rfg
->routemap_export_bgp_name
= NULL
;
1741 rfg
->routemap_export_bgp
= NULL
;
1743 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1744 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1748 || (rfg
->routemap_export_zebra_name
1749 && strmatch(argv
[idx
]->arg
,
1750 rfg
->routemap_export_zebra_name
))) {
1751 if (rfg
->routemap_export_zebra_name
)
1752 free(rfg
->routemap_export_zebra_name
);
1753 route_map_counter_decrement(rfg
->routemap_export_zebra
);
1754 rfg
->routemap_export_zebra_name
= NULL
;
1755 rfg
->routemap_export_zebra
= NULL
;
1757 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1758 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1764 ALIAS (vnc_nve_group_export_no_routemap
,
1765 vnc_vrf_policy_export_no_routemap_cmd
,
1766 "no export route-map [NAME]",
1769 "Route-map for filtering exported routes\n" "route map name\n")
1771 DEFUN (vnc_nve_group_export_routemap
,
1772 vnc_nve_group_export_routemap_cmd
,
1773 "export <bgp|zebra> route-map NAME",
1774 "Export to other protocols\n"
1776 "Export to Zebra (experimental)\n"
1777 "Route-map for filtering exported routes\n" "route map name\n")
1779 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1780 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1784 VNC_VTY_CONFIG_CHECK(bgp
);
1786 /* make sure it's still in list */
1787 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1788 /* Not in list anymore */
1789 vty_out(vty
, "Current NVE group no longer exists\n");
1790 return CMD_WARNING_CONFIG_FAILED
;
1793 if (argv
[1]->text
[0] == 'z')
1798 if (rfg
->routemap_export_bgp_name
)
1799 free(rfg
->routemap_export_bgp_name
);
1800 route_map_counter_decrement(rfg
->routemap_export_bgp
);
1801 rfg
->routemap_export_bgp_name
= strdup(argv
[idx
]->arg
);
1802 rfg
->routemap_export_bgp
=
1803 route_map_lookup_by_name(argv
[idx
]->arg
);
1804 route_map_counter_increment(rfg
->routemap_export_bgp
);
1805 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1806 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1808 if (rfg
->routemap_export_zebra_name
)
1809 free(rfg
->routemap_export_zebra_name
);
1810 route_map_counter_decrement(rfg
->routemap_export_zebra
);
1811 rfg
->routemap_export_zebra_name
= strdup(argv
[idx
]->arg
);
1812 rfg
->routemap_export_zebra
=
1813 route_map_lookup_by_name(argv
[idx
]->arg
);
1814 route_map_counter_increment(rfg
->routemap_export_zebra
);
1815 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1816 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1821 ALIAS (vnc_nve_group_export_routemap
,
1822 vnc_vrf_policy_export_routemap_cmd
,
1823 "export route-map NAME",
1825 "Route-map for filtering exported routes\n" "route map name\n")
1827 DEFUN (vnc_nve_export_no_prefixlist
,
1828 vnc_nve_export_no_prefixlist_cmd
,
1829 "no vnc export <bgp|zebra> <ipv4|ipv6> prefix-list [NAME]",
1832 "Export to other protocols\n"
1834 "Export to Zebra (experimental)\n"
1837 "Prefix-list for filtering exported routes\n" "Prefix list name\n")
1839 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1840 struct rfapi_cfg
*hc
;
1843 VNC_VTY_CONFIG_CHECK(bgp
);
1844 hc
= bgp
->rfapi_cfg
;
1846 if (strmatch(argv
[4]->text
, "ipv4")) {
1852 if (argv
[3]->arg
[0] == 'b') {
1853 if (((argc
> 6) && hc
->plist_export_bgp_name
[afi
]
1854 && strmatch(argv
[6]->text
, hc
->plist_export_bgp_name
[afi
]))
1857 free(hc
->plist_export_bgp_name
[afi
]);
1858 hc
->plist_export_bgp_name
[afi
] = NULL
;
1859 hc
->plist_export_bgp
[afi
] = NULL
;
1860 vnc_direct_bgp_reexport(bgp
, afi
);
1863 if (((argc
> 6) && hc
->plist_export_zebra_name
[afi
]
1864 && strmatch(argv
[6]->text
,
1865 hc
->plist_export_zebra_name
[afi
]))
1868 free(hc
->plist_export_zebra_name
[afi
]);
1869 hc
->plist_export_zebra_name
[afi
] = NULL
;
1870 hc
->plist_export_zebra
[afi
] = NULL
;
1871 /* TBD vnc_zebra_rh_reexport(bgp, afi); */
1877 DEFUN (vnc_nve_export_prefixlist
,
1878 vnc_nve_export_prefixlist_cmd
,
1879 "vnc export <bgp|zebra> <ipv4|ipv6> prefix-list NAME",
1881 "Export to other protocols\n"
1883 "Export to Zebra (experimental)\n"
1886 "Prefix-list for filtering exported routes\n" "Prefix list name\n")
1888 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1889 struct rfapi_cfg
*hc
;
1892 VNC_VTY_CONFIG_CHECK(bgp
);
1893 hc
= bgp
->rfapi_cfg
;
1895 if (strmatch(argv
[3]->text
, "ipv4")) {
1901 if (argv
[2]->arg
[0] == 'b') {
1902 if (hc
->plist_export_bgp_name
[afi
])
1903 free(hc
->plist_export_bgp_name
[afi
]);
1904 hc
->plist_export_bgp_name
[afi
] = strdup(argv
[5]->arg
);
1905 hc
->plist_export_bgp
[afi
] =
1906 prefix_list_lookup(afi
, argv
[5]->arg
);
1907 vnc_direct_bgp_reexport(bgp
, afi
);
1909 if (hc
->plist_export_zebra_name
[afi
])
1910 free(hc
->plist_export_zebra_name
[afi
]);
1911 hc
->plist_export_zebra_name
[afi
] = strdup(argv
[5]->arg
);
1912 hc
->plist_export_zebra
[afi
] =
1913 prefix_list_lookup(afi
, argv
[5]->arg
);
1914 /* TBD vnc_zebra_rh_reexport(bgp, afi); */
1919 DEFUN (vnc_nve_export_no_routemap
,
1920 vnc_nve_export_no_routemap_cmd
,
1921 "no vnc export <bgp|zebra> route-map [NAME]",
1924 "Export to other protocols\n"
1926 "Export to Zebra (experimental)\n"
1927 "Route-map for filtering exported routes\n" "Route map name\n")
1929 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1930 struct rfapi_cfg
*hc
;
1932 VNC_VTY_CONFIG_CHECK(bgp
);
1933 hc
= bgp
->rfapi_cfg
;
1935 if (argv
[3]->arg
[0] == 'b') {
1936 if (((argc
> 5) && hc
->routemap_export_bgp_name
1937 && strmatch(argv
[5]->text
, hc
->routemap_export_bgp_name
))
1940 free(hc
->routemap_export_bgp_name
);
1941 route_map_counter_decrement(hc
->routemap_export_bgp
);
1942 hc
->routemap_export_bgp_name
= NULL
;
1943 hc
->routemap_export_bgp
= NULL
;
1944 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
1945 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
1948 if (((argc
> 5) && hc
->routemap_export_zebra_name
1949 && strmatch(argv
[5]->text
, hc
->routemap_export_zebra_name
))
1952 free(hc
->routemap_export_zebra_name
);
1953 route_map_counter_decrement(hc
->routemap_export_zebra
);
1954 hc
->routemap_export_zebra_name
= NULL
;
1955 hc
->routemap_export_zebra
= NULL
;
1956 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
1957 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
1963 DEFUN (vnc_nve_export_routemap
,
1964 vnc_nve_export_routemap_cmd
,
1965 "vnc export <bgp|zebra> route-map NAME",
1967 "Export to other protocols\n"
1969 "Export to Zebra (experimental)\n"
1970 "Route-map for filtering exported routes\n" "Route map name\n")
1972 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1973 struct rfapi_cfg
*hc
;
1975 VNC_VTY_CONFIG_CHECK(bgp
);
1976 hc
= bgp
->rfapi_cfg
;
1978 if (argv
[2]->arg
[0] == 'b') {
1979 if (hc
->routemap_export_bgp_name
)
1980 free(hc
->routemap_export_bgp_name
);
1981 route_map_counter_decrement(hc
->routemap_export_bgp
);
1982 hc
->routemap_export_bgp_name
= strdup(argv
[4]->arg
);
1983 hc
->routemap_export_bgp
=
1984 route_map_lookup_by_name(argv
[4]->arg
);
1985 route_map_counter_increment(hc
->routemap_export_bgp
);
1986 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
1987 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
1989 if (hc
->routemap_export_zebra_name
)
1990 free(hc
->routemap_export_zebra_name
);
1991 route_map_counter_decrement(hc
->routemap_export_zebra
);
1992 hc
->routemap_export_zebra_name
= strdup(argv
[4]->arg
);
1993 hc
->routemap_export_zebra
=
1994 route_map_lookup_by_name(argv
[4]->arg
);
1995 route_map_counter_increment(hc
->routemap_export_zebra
);
1996 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
1997 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
2004 * respond to changes in the global prefix list configuration
2006 void vnc_prefix_list_update(struct bgp
*bgp
)
2010 struct rfapi_nve_group_cfg
*rfg
;
2011 struct rfapi_cfg
*hc
;
2015 vnc_zlog_debug_verbose("%s: No BGP process is configured",
2020 if (!(hc
= bgp
->rfapi_cfg
)) {
2021 vnc_zlog_debug_verbose("%s: rfapi not configured", __func__
);
2025 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
2027 * Loop over nve groups
2029 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->nve_groups_sequential
,
2032 if (rfg
->plist_export_bgp_name
[afi
]) {
2033 rfg
->plist_export_bgp
[afi
] = prefix_list_lookup(
2034 afi
, rfg
->plist_export_bgp_name
[afi
]);
2036 if (rfg
->plist_export_zebra_name
[afi
]) {
2037 rfg
->plist_export_zebra
2038 [afi
] = prefix_list_lookup(
2039 afi
, rfg
->plist_export_zebra_name
[afi
]);
2041 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2042 if (rfg
->plist_redist_name
[i
][afi
]) {
2044 [i
][afi
] = prefix_list_lookup(
2046 rfg
->plist_redist_name
[i
][afi
]);
2050 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, afi
);
2051 /* TBD vnc_zebra_reexport_group_afi(bgp, rfg, afi); */
2057 if (hc
->plist_export_bgp_name
[afi
]) {
2058 hc
->plist_export_bgp
[afi
] = prefix_list_lookup(
2059 afi
, hc
->plist_export_bgp_name
[afi
]);
2061 if (hc
->plist_export_zebra_name
[afi
]) {
2062 hc
->plist_export_zebra
[afi
] = prefix_list_lookup(
2063 afi
, hc
->plist_export_zebra_name
[afi
]);
2066 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2067 if (hc
->plist_redist_name
[i
][afi
]) {
2068 hc
->plist_redist
[i
][afi
] = prefix_list_lookup(
2069 afi
, hc
->plist_redist_name
[i
][afi
]);
2074 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
2075 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
2077 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
2078 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
2080 vnc_redistribute_prechange(bgp
);
2081 vnc_redistribute_postchange(bgp
);
2085 * respond to changes in the global route map configuration
2087 void vnc_routemap_update(struct bgp
*bgp
, const char *unused
)
2090 struct rfapi_nve_group_cfg
*rfg
;
2091 struct rfapi_cfg
*hc
;
2093 struct route_map
*old
= NULL
;
2095 vnc_zlog_debug_verbose("%s(arg=%s)", __func__
, unused
);
2098 vnc_zlog_debug_verbose("%s: No BGP process is configured",
2103 if (!(hc
= bgp
->rfapi_cfg
)) {
2104 vnc_zlog_debug_verbose("%s: rfapi not configured", __func__
);
2109 * Loop over nve groups
2111 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->nve_groups_sequential
, n
,
2114 if (rfg
->routemap_export_bgp_name
) {
2115 old
= rfg
->routemap_export_bgp
;
2116 rfg
->routemap_export_bgp
= route_map_lookup_by_name(
2117 rfg
->routemap_export_bgp_name
);
2118 /* old is NULL. i.e Route map creation event.
2119 * So update applied_counter.
2120 * If Old is not NULL, i.e It may be routemap
2121 * updation or deletion.
2122 * So no need to update the counter.
2125 route_map_counter_increment(
2126 rfg
->routemap_export_bgp
);
2128 if (rfg
->routemap_export_zebra_name
) {
2129 old
= rfg
->routemap_export_bgp
;
2130 rfg
->routemap_export_bgp
= route_map_lookup_by_name(
2131 rfg
->routemap_export_zebra_name
);
2133 route_map_counter_increment(
2134 rfg
->routemap_export_bgp
);
2136 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2137 if (rfg
->routemap_redist_name
[i
]) {
2138 old
= rfg
->routemap_redist
[i
];
2139 rfg
->routemap_redist
[i
] =
2140 route_map_lookup_by_name(
2141 rfg
->routemap_redist_name
[i
]);
2143 route_map_counter_increment(
2144 rfg
->routemap_redist
[i
]);
2148 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP
);
2149 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
2150 /* TBD vnc_zebra_reexport_group_afi(bgp, rfg, afi); */
2156 if (hc
->routemap_export_bgp_name
) {
2157 old
= hc
->routemap_export_bgp
;
2158 hc
->routemap_export_bgp
=
2159 route_map_lookup_by_name(hc
->routemap_export_bgp_name
);
2161 route_map_counter_increment(hc
->routemap_export_bgp
);
2163 if (hc
->routemap_export_zebra_name
) {
2164 old
= hc
->routemap_export_bgp
;
2165 hc
->routemap_export_bgp
= route_map_lookup_by_name(
2166 hc
->routemap_export_zebra_name
);
2168 route_map_counter_increment(hc
->routemap_export_bgp
);
2170 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2171 if (hc
->routemap_redist_name
[i
]) {
2172 old
= hc
->routemap_redist
[i
];
2173 hc
->routemap_redist
[i
] = route_map_lookup_by_name(
2174 hc
->routemap_redist_name
[i
]);
2176 route_map_counter_increment(
2177 hc
->routemap_redist
[i
]);
2181 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
2182 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
2184 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
2185 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
2187 vnc_redistribute_prechange(bgp
);
2188 vnc_redistribute_postchange(bgp
);
2190 vnc_zlog_debug_verbose("%s done", __func__
);
2193 /*-------------------------------------------------------------------------
2195 *-----------------------------------------------------------------------*/
2198 DEFUN_NOSH (vnc_nve_group
,
2200 "vnc nve-group NAME",
2201 VNC_CONFIG_STR
"Configure a NVE group\n" "Group name\n")
2203 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2204 struct rfapi_nve_group_cfg
*rfg
;
2205 struct listnode
*node
, *nnode
;
2206 struct rfapi_rfg_name
*rfgn
;
2208 VNC_VTY_CONFIG_CHECK(bgp
);
2210 /* Search for name */
2211 rfg
= bgp_rfapi_cfg_match_byname(bgp
, argv
[2]->arg
,
2212 RFAPI_GROUP_CFG_NVE
);
2215 rfg
= rfapi_group_new(bgp
, RFAPI_GROUP_CFG_NVE
, argv
[2]->arg
);
2217 /* Error out of memory */
2218 vty_out(vty
, "Can't allocate memory for NVE group\n");
2219 return CMD_WARNING_CONFIG_FAILED
;
2222 /* Copy defaults from struct rfapi_cfg */
2223 rfg
->rd
= bgp
->rfapi_cfg
->default_rd
;
2224 if (bgp
->rfapi_cfg
->flags
& BGP_VNC_CONFIG_L2RD
) {
2225 rfg
->l2rd
= bgp
->rfapi_cfg
->default_l2rd
;
2226 rfg
->flags
|= RFAPI_RFG_L2RD
;
2228 rfg
->rd
= bgp
->rfapi_cfg
->default_rd
;
2229 rfg
->response_lifetime
=
2230 bgp
->rfapi_cfg
->default_response_lifetime
;
2232 if (bgp
->rfapi_cfg
->default_rt_export_list
) {
2233 rfg
->rt_export_list
= ecommunity_dup(
2234 bgp
->rfapi_cfg
->default_rt_export_list
);
2237 if (bgp
->rfapi_cfg
->default_rt_import_list
) {
2238 rfg
->rt_import_list
= ecommunity_dup(
2239 bgp
->rfapi_cfg
->default_rt_import_list
);
2240 rfg
->rfapi_import_table
= rfapiImportTableRefAdd(
2241 bgp
, rfg
->rt_import_list
, rfg
);
2245 * If a redist nve group was named but the group was not
2247 * make the linkage now
2249 if (!bgp
->rfapi_cfg
->rfg_redist
) {
2250 if (bgp
->rfapi_cfg
->rfg_redist_name
2251 && !strcmp(bgp
->rfapi_cfg
->rfg_redist_name
,
2254 vnc_redistribute_prechange(bgp
);
2255 bgp
->rfapi_cfg
->rfg_redist
= rfg
;
2256 vnc_redistribute_postchange(bgp
);
2261 * Same treatment for bgp-direct export group
2263 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
,
2264 node
, nnode
, rfgn
)) {
2266 if (!strcmp(rfgn
->name
, rfg
->name
)) {
2268 vnc_direct_bgp_add_group(bgp
, rfg
);
2274 * Same treatment for zebra export group
2276 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2279 vnc_zlog_debug_verbose(
2280 "%s: ezport zebra: checking if \"%s\" == \"%s\"",
2281 __func__
, rfgn
->name
, rfg
->name
);
2282 if (!strcmp(rfgn
->name
, rfg
->name
)) {
2284 vnc_zebra_add_group(bgp
, rfg
);
2291 * XXX subsequent calls will need to make sure this item is still
2292 * in the linked list and has the same name
2294 VTY_PUSH_CONTEXT_SUB(BGP_VNC_NVE_GROUP_NODE
, rfg
);
2299 static void bgp_rfapi_delete_nve_group(struct vty
*vty
, /* NULL = no output */
2301 struct rfapi_nve_group_cfg
*rfg
)
2303 struct list
*orphaned_nves
= NULL
;
2304 struct listnode
*node
, *nnode
;
2307 * If there are currently-open NVEs that belong to this group,
2308 * zero out their references to this group structure.
2311 struct rfapi_descriptor
*rfd
;
2312 orphaned_nves
= list_new();
2313 while ((rfd
= listnode_head(rfg
->nves
))) {
2315 listnode_delete(rfg
->nves
, rfd
);
2316 listnode_add(orphaned_nves
, rfd
);
2318 list_delete(&rfg
->nves
);
2323 if (rfg
->rfapi_import_table
)
2324 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2325 if (rfg
->rt_import_list
)
2326 ecommunity_free(&rfg
->rt_import_list
);
2327 if (rfg
->rt_export_list
)
2328 ecommunity_free(&rfg
->rt_export_list
);
2331 rfg
->vn_node
->info
= NULL
;
2332 agg_unlock_node(rfg
->vn_node
); /* frees */
2335 rfg
->un_node
->info
= NULL
;
2336 agg_unlock_node(rfg
->un_node
); /* frees */
2339 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, rfg
->rfp_cfg
);
2340 listnode_delete(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
);
2343 XFREE(MTYPE_RFAPI_GROUP_CFG
, rfg
);
2346 * Attempt to reassign the orphaned nves to a new group. If
2347 * a NVE can not be reassigned, its rfd->rfg will remain NULL
2348 * and it will become a zombie until released by rfapi_close().
2350 if (orphaned_nves
) {
2351 struct rfapi_descriptor
*rfd
;
2353 for (ALL_LIST_ELEMENTS(orphaned_nves
, node
, nnode
, rfd
)) {
2355 * 1. rfapi_close() equivalent except:
2356 * a. don't free original descriptor
2357 * b. remember query list
2358 * c. remember advertised route list
2359 * 2. rfapi_open() equivalent except:
2360 * a. reuse original descriptor
2361 * 3. rfapi_register() on remembered advertised route
2363 * 4. rfapi_query on rememebred query list
2368 rc
= rfapi_reopen(rfd
, bgp
);
2371 list_delete_node(orphaned_nves
, node
);
2374 "WARNING: reassigned NVE vn=");
2375 rfapiPrintRfapiIpAddr(vty
, &rfd
->vn_addr
);
2377 vty_out(vty
, " un=");
2378 rfapiPrintRfapiIpAddr(vty
, &rfd
->un_addr
);
2380 vty_out(vty
, " to new group \"%s\"\n",
2385 for (ALL_LIST_ELEMENTS_RO(orphaned_nves
, node
, rfd
)) {
2387 vty_out(vty
, "WARNING: orphaned NVE vn=");
2388 rfapiPrintRfapiIpAddr(vty
, &rfd
->vn_addr
);
2390 vty_out(vty
, " un=");
2391 rfapiPrintRfapiIpAddr(vty
, &rfd
->un_addr
);
2395 list_delete(&orphaned_nves
);
2400 bgp_rfapi_delete_named_nve_group(struct vty
*vty
, /* NULL = no output */
2402 const char *rfg_name
, /* NULL = any */
2403 rfapi_group_cfg_type_t type
) /* _MAX = any */
2405 struct rfapi_nve_group_cfg
*rfg
= NULL
;
2406 struct listnode
*node
, *nnode
;
2407 struct rfapi_rfg_name
*rfgn
;
2409 /* Search for name */
2411 rfg
= bgp_rfapi_cfg_match_byname(bgp
, rfg_name
, type
);
2414 vty_out(vty
, "No NVE group named \"%s\"\n",
2416 return CMD_WARNING_CONFIG_FAILED
;
2421 * If this group is the redist nve group, unlink it
2423 if (rfg_name
== NULL
|| bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2424 vnc_redistribute_prechange(bgp
);
2425 bgp
->rfapi_cfg
->rfg_redist
= NULL
;
2426 vnc_redistribute_postchange(bgp
);
2431 * remove reference from bgp direct export list
2433 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2435 if (rfgn
->rfg
== rfg
) {
2437 /* remove exported routes from this group */
2438 vnc_direct_bgp_del_group(bgp
, rfg
);
2444 * remove reference from zebra export list
2446 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2448 if (rfgn
->rfg
== rfg
) {
2450 /* remove exported routes from this group */
2451 vnc_zebra_del_group(bgp
, rfg
);
2457 clear_vnc_vrf_closer(rfg
);
2458 bgp_rfapi_delete_nve_group(vty
, bgp
, rfg
);
2459 } else /* must be delete all */
2460 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->nve_groups_sequential
,
2461 node
, nnode
, rfg
)) {
2463 clear_vnc_vrf_closer(rfg
);
2464 bgp_rfapi_delete_nve_group(vty
, bgp
, rfg
);
2469 DEFUN (vnc_no_nve_group
,
2470 vnc_no_nve_group_cmd
,
2471 "no vnc nve-group NAME",
2474 "Configure a NVE group\n"
2477 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2479 return bgp_rfapi_delete_named_nve_group(vty
, bgp
, argv
[3]->arg
,
2480 RFAPI_GROUP_CFG_NVE
);
2483 DEFUN (vnc_nve_group_prefix
,
2484 vnc_nve_group_prefix_cmd
,
2485 "prefix <vn|un> <A.B.C.D/M|X:X::X:X/M>",
2486 "Specify prefixes matching NVE VN or UN interfaces\n"
2492 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2493 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2496 struct agg_table
*rt
;
2497 struct agg_node
*rn
;
2498 int is_un_prefix
= 0;
2500 /* make sure it's still in list */
2501 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2502 /* Not in list anymore */
2503 vty_out(vty
, "Current NVE group no longer exists\n");
2504 return CMD_WARNING_CONFIG_FAILED
;
2507 if (!str2prefix(argv
[2]->arg
, &p
)) {
2508 vty_out(vty
, "Malformed prefix \"%s\"\n", argv
[2]->arg
);
2509 return CMD_WARNING_CONFIG_FAILED
;
2512 afi
= family2afi(p
.family
);
2514 vty_out(vty
, "Unsupported address family\n");
2515 return CMD_WARNING_CONFIG_FAILED
;
2518 if (argv
[1]->arg
[0] == 'u') {
2519 rt
= bgp
->rfapi_cfg
->nve_groups_un
[afi
];
2522 rt
= bgp
->rfapi_cfg
->nve_groups_vn
[afi
];
2525 rn
= agg_node_get(rt
, &p
); /* NB locks node */
2528 * There is already a group with this prefix
2530 agg_unlock_node(rn
);
2531 if (rn
->info
!= rfg
) {
2533 * different group name: fail
2536 "nve group \"%s\" already has \"%s\" prefix %s\n",
2537 ((struct rfapi_nve_group_cfg
*)(rn
->info
))
2539 argv
[1]->arg
, argv
[2]->arg
);
2540 return CMD_WARNING_CONFIG_FAILED
;
2543 * same group name: it's already in the correct place
2544 * in the table, so we're done.
2546 * Implies rfg->(vn|un)_prefix is already correct.
2552 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2553 vnc_redistribute_prechange(bgp
);
2556 /* New prefix, new node */
2560 /* detach rfg from previous route table location */
2562 rfg
->un_node
->info
= NULL
;
2563 agg_unlock_node(rfg
->un_node
); /* frees */
2565 rfg
->un_node
= rn
; /* back ref */
2570 /* detach rfg from previous route table location */
2572 rfg
->vn_node
->info
= NULL
;
2573 agg_unlock_node(rfg
->vn_node
); /* frees */
2575 rfg
->vn_node
= rn
; /* back ref */
2582 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2583 vnc_redistribute_postchange(bgp
);
2589 DEFUN (vnc_nve_group_rt_import
,
2590 vnc_nve_group_rt_import_cmd
,
2591 "rt import RTLIST...",
2592 "Specify route targets\n"
2594 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2596 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2597 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2599 struct listnode
*node
;
2600 struct rfapi_rfg_name
*rfgn
;
2601 int is_export_bgp
= 0;
2602 int is_export_zebra
= 0;
2604 /* make sure it's still in list */
2605 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2606 /* Not in list anymore */
2607 vty_out(vty
, "Current NVE group no longer exists\n");
2608 return CMD_WARNING_CONFIG_FAILED
;
2611 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
2612 if (rc
!= CMD_SUCCESS
)
2615 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2618 if (rfgn
->rfg
== rfg
) {
2625 vnc_direct_bgp_del_group(bgp
, rfg
);
2627 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2630 if (rfgn
->rfg
== rfg
) {
2631 is_export_zebra
= 1;
2636 if (is_export_zebra
)
2637 vnc_zebra_del_group(bgp
, rfg
);
2640 * stop referencing old import table, now reference new one
2642 if (rfg
->rfapi_import_table
)
2643 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2644 rfg
->rfapi_import_table
=
2645 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
2648 vnc_direct_bgp_add_group(bgp
, rfg
);
2650 if (is_export_zebra
)
2651 vnc_zebra_add_group(bgp
, rfg
);
2656 DEFUN (vnc_nve_group_rt_export
,
2657 vnc_nve_group_rt_export_cmd
,
2658 "rt export RTLIST...",
2659 "Specify route targets\n"
2661 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2663 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2664 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2667 /* make sure it's still in list */
2668 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2669 /* Not in list anymore */
2670 vty_out(vty
, "Current NVE group no longer exists\n");
2671 return CMD_WARNING_CONFIG_FAILED
;
2674 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2675 vnc_redistribute_prechange(bgp
);
2678 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
2680 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2681 vnc_redistribute_postchange(bgp
);
2687 DEFUN (vnc_nve_group_rt_both
,
2688 vnc_nve_group_rt_both_cmd
,
2689 "rt both RTLIST...",
2690 "Specify route targets\n"
2691 "Export+import filters\n"
2692 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2694 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2695 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2697 int is_export_bgp
= 0;
2698 int is_export_zebra
= 0;
2699 struct listnode
*node
;
2700 struct rfapi_rfg_name
*rfgn
;
2702 /* make sure it's still in list */
2703 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2704 /* Not in list anymore */
2705 vty_out(vty
, "Current NVE group no longer exists\n");
2706 return CMD_WARNING_CONFIG_FAILED
;
2709 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
2710 if (rc
!= CMD_SUCCESS
)
2713 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2716 if (rfgn
->rfg
== rfg
) {
2723 vnc_direct_bgp_del_group(bgp
, rfg
);
2725 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2728 if (rfgn
->rfg
== rfg
) {
2729 is_export_zebra
= 1;
2734 if (is_export_zebra
) {
2735 vnc_zlog_debug_verbose("%s: is_export_zebra", __func__
);
2736 vnc_zebra_del_group(bgp
, rfg
);
2740 * stop referencing old import table, now reference new one
2742 if (rfg
->rfapi_import_table
)
2743 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2744 rfg
->rfapi_import_table
=
2745 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
2748 vnc_direct_bgp_add_group(bgp
, rfg
);
2750 if (is_export_zebra
)
2751 vnc_zebra_add_group(bgp
, rfg
);
2753 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2754 vnc_redistribute_prechange(bgp
);
2757 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
2759 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2760 vnc_redistribute_postchange(bgp
);
2766 DEFUN (vnc_nve_group_l2rd
,
2767 vnc_nve_group_l2rd_cmd
,
2768 "l2rd <(1-255)|auto-vn>",
2769 "Specify default Local Nve ID value to use in RD for L2 routes\n"
2770 "Fixed value 1-255\n"
2771 "use the low-order octet of the NVE's VN address\n")
2773 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2774 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2776 /* make sure it's still in list */
2777 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2778 /* Not in list anymore */
2779 vty_out(vty
, "Current NVE group no longer exists\n");
2780 return CMD_WARNING_CONFIG_FAILED
;
2783 if (strmatch(argv
[1]->text
, "auto:vn")) {
2787 unsigned long value_l
= strtoul(argv
[1]->arg
, &end
, 10);
2788 uint8_t value
= value_l
& 0xff;
2790 if (!argv
[1]->arg
[0] || *end
) {
2791 vty_out(vty
, "%% Malformed l2 nve ID \"%s\"\n",
2793 return CMD_WARNING_CONFIG_FAILED
;
2795 if ((value_l
< 1) || (value_l
> 0xff)) {
2797 "%% Malformed l2 nve id (must be greater than 0 and less than %u\n",
2799 return CMD_WARNING_CONFIG_FAILED
;
2804 rfg
->flags
|= RFAPI_RFG_L2RD
;
2809 DEFUN (vnc_nve_group_no_l2rd
,
2810 vnc_nve_group_no_l2rd_cmd
,
2813 "Specify default Local Nve ID value to use in RD for L2 routes\n")
2815 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2816 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2818 /* make sure it's still in list */
2819 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2820 /* Not in list anymore */
2821 vty_out(vty
, "Current NVE group no longer exists\n");
2822 return CMD_WARNING_CONFIG_FAILED
;
2826 rfg
->flags
&= ~RFAPI_RFG_L2RD
;
2831 DEFUN (vnc_nve_group_rd
,
2832 vnc_nve_group_rd_cmd
,
2833 "rd ASN:NN_OR_IP-ADDRESS:NN",
2834 "Specify route distinguisher\n"
2835 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:vn:<number> )\n")
2837 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2839 struct prefix_rd prd
;
2840 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2842 /* make sure it's still in list */
2843 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2844 /* Not in list anymore */
2845 vty_out(vty
, "Current NVE group no longer exists\n");
2846 return CMD_WARNING_CONFIG_FAILED
;
2849 if (!strncmp(argv
[1]->arg
, "auto:vn:", 8)) {
2851 * use AF_UNIX to designate automatically-assigned RD
2852 * auto:vn:nn where nn is a 2-octet quantity
2855 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
2856 uint16_t value
= value32
& 0xffff;
2858 if (!argv
[1]->arg
[8] || *end
) {
2859 vty_out(vty
, "%% Malformed rd\n");
2860 return CMD_WARNING_CONFIG_FAILED
;
2862 if (value32
> 0xffff) {
2863 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
2865 return CMD_WARNING_CONFIG_FAILED
;
2868 memset(&prd
, 0, sizeof(prd
));
2869 prd
.family
= AF_UNIX
;
2871 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
2872 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
2873 prd
.val
[6] = (value
>> 8) & 0x0ff;
2874 prd
.val
[7] = value
& 0x0ff;
2878 /* TODO: save RD format */
2879 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
2881 vty_out(vty
, "%% Malformed rd\n");
2882 return CMD_WARNING_CONFIG_FAILED
;
2886 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2887 vnc_redistribute_prechange(bgp
);
2892 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2893 vnc_redistribute_postchange(bgp
);
2898 DEFUN (vnc_nve_group_responselifetime
,
2899 vnc_nve_group_responselifetime_cmd
,
2900 "response-lifetime <LIFETIME|infinite>",
2901 "Specify response lifetime\n"
2902 "Response lifetime in seconds\n" "Infinite response lifetime\n")
2904 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2905 unsigned int rspint
;
2906 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2907 struct rfapi_descriptor
*rfd
;
2908 struct listnode
*hdnode
;
2910 /* make sure it's still in list */
2911 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2912 /* Not in list anymore */
2913 vty_out(vty
, "Current NVE group no longer exists\n");
2914 return CMD_WARNING_CONFIG_FAILED
;
2917 if (strmatch(argv
[1]->text
, "infinite")) {
2918 rspint
= RFAPI_INFINITE_LIFETIME
;
2920 rspint
= strtoul(argv
[1]->arg
, NULL
, 10);
2923 rfg
->response_lifetime
= rspint
;
2924 rfg
->flags
|= RFAPI_RFG_RESPONSE_LIFETIME
;
2926 for (ALL_LIST_ELEMENTS_RO(rfg
->nves
, hdnode
, rfd
))
2927 rfd
->response_lifetime
= rspint
;
2932 * Sigh. This command, like exit-address-family, is a hack to deal
2933 * with the lack of rigorous level control in the command handler.
2934 * TBD fix command handler.
2936 DEFUN_NOSH (exit_vnc
,
2939 "Exit VNC configuration mode\n")
2941 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
2942 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
2943 || vty
->node
== BGP_VNC_L2_GROUP_NODE
) {
2945 vty
->node
= BGP_NODE
;
2950 static struct cmd_node bgp_vnc_defaults_node
= {
2951 .name
= "bgp vnc defaults",
2952 .node
= BGP_VNC_DEFAULTS_NODE
,
2953 .parent_node
= BGP_NODE
,
2954 .prompt
= "%s(config-router-vnc-defaults)# ",
2957 static struct cmd_node bgp_vnc_nve_group_node
= {
2958 .name
= "bgp vnc nve",
2959 .node
= BGP_VNC_NVE_GROUP_NODE
,
2960 .parent_node
= BGP_NODE
,
2961 .prompt
= "%s(config-router-vnc-nve-group)# ",
2964 /*-------------------------------------------------------------------------
2966 * Note there are two types of NVEs, one for VPNs one for RFP NVEs
2967 *-----------------------------------------------------------------------*/
2969 DEFUN_NOSH (vnc_vrf_policy
,
2972 "Configure a VRF policy group\n"
2975 struct rfapi_nve_group_cfg
*rfg
;
2976 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2978 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_VRF
) {
2980 "Can't configure vrf-policy within a BGP VRF instance\n");
2981 return CMD_WARNING_CONFIG_FAILED
;
2984 /* Search for name */
2985 rfg
= bgp_rfapi_cfg_match_byname(bgp
, argv
[1]->arg
,
2986 RFAPI_GROUP_CFG_VRF
);
2989 rfg
= rfapi_group_new(bgp
, RFAPI_GROUP_CFG_VRF
, argv
[1]->arg
);
2991 /* Error out of memory */
2992 vty_out(vty
, "Can't allocate memory for NVE group\n");
2993 return CMD_WARNING_CONFIG_FAILED
;
2997 * XXX subsequent calls will need to make sure this item is still
2998 * in the linked list and has the same name
3000 VTY_PUSH_CONTEXT_SUB(BGP_VRF_POLICY_NODE
, rfg
);
3005 DEFUN (vnc_no_vrf_policy
,
3006 vnc_no_vrf_policy_cmd
,
3007 "no vrf-policy NAME",
3009 "Remove a VRF policy group\n"
3012 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3014 /* silently return */
3015 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_VRF
)
3018 return bgp_rfapi_delete_named_nve_group(vty
, bgp
, argv
[2]->arg
,
3019 RFAPI_GROUP_CFG_VRF
);
3022 DEFUN (vnc_vrf_policy_label
,
3023 vnc_vrf_policy_label_cmd
,
3024 "label (0-1048575)",
3025 "Default label value for VRF\n"
3026 "Label Value <0-1048575>\n")
3028 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3031 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3033 /* make sure it's still in list */
3034 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3035 /* Not in list anymore */
3036 vty_out(vty
, "Current NVE group no longer exists\n");
3037 return CMD_WARNING_CONFIG_FAILED
;
3040 label
= strtoul(argv
[1]->arg
, NULL
, 10);
3042 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3043 vnc_redistribute_prechange(bgp
);
3048 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3049 vnc_redistribute_postchange(bgp
);
3054 DEFUN (vnc_vrf_policy_no_label
,
3055 vnc_vrf_policy_no_label_cmd
,
3058 "Remove VRF default label\n")
3060 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3061 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3063 /* make sure it's still in list */
3064 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3065 /* Not in list anymore */
3066 vty_out(vty
, "Current VRF group no longer exists\n");
3067 return CMD_WARNING_CONFIG_FAILED
;
3070 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3071 vnc_redistribute_prechange(bgp
);
3074 rfg
->label
= MPLS_LABEL_NONE
;
3076 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3077 vnc_redistribute_postchange(bgp
);
3082 DEFUN (vnc_vrf_policy_nexthop
,
3083 vnc_vrf_policy_nexthop_cmd
,
3084 "nexthop <A.B.C.D|X:X::X:X|self>",
3085 "Specify next hop to use for VRF advertised prefixes\n"
3088 "Use configured router-id (default)\n")
3090 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3093 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3095 /* make sure it's still in list */
3096 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3097 /* Not in list anymore */
3098 vty_out(vty
, "Current VRF no longer exists\n");
3099 return CMD_WARNING_CONFIG_FAILED
;
3102 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3103 vnc_redistribute_prechange(bgp
);
3106 if (!str2prefix(argv
[1]->arg
, &p
) && p
.family
) {
3107 // vty_out (vty, "Nexthop set to self\n");
3108 SET_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
);
3109 memset(&rfg
->vn_prefix
, 0, sizeof(struct prefix
));
3111 UNSET_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
);
3116 /* TBD handle router-id/ nexthop changes when have advertised prefixes
3119 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3120 vnc_redistribute_postchange(bgp
);
3126 /* The RT code should be refactored/simplified with above... */
3127 DEFUN (vnc_vrf_policy_rt_import
,
3128 vnc_vrf_policy_rt_import_cmd
,
3129 "rt import RTLIST...",
3130 "Specify route targets\n"
3132 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3134 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3135 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3137 struct listnode
*node
;
3138 struct rfapi_rfg_name
*rfgn
;
3139 int is_export_bgp
= 0;
3140 int is_export_zebra
= 0;
3142 /* make sure it's still in list */
3143 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3144 /* Not in list anymore */
3145 vty_out(vty
, "Current NVE group no longer exists\n");
3146 return CMD_WARNING_CONFIG_FAILED
;
3149 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
3150 if (rc
!= CMD_SUCCESS
)
3153 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
3156 if (rfgn
->rfg
== rfg
) {
3163 vnc_direct_bgp_del_group(bgp
, rfg
);
3165 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
3168 if (rfgn
->rfg
== rfg
) {
3169 is_export_zebra
= 1;
3174 if (is_export_zebra
)
3175 vnc_zebra_del_group(bgp
, rfg
);
3178 * stop referencing old import table, now reference new one
3180 if (rfg
->rfapi_import_table
)
3181 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
3182 rfg
->rfapi_import_table
=
3183 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
3186 vnc_direct_bgp_add_group(bgp
, rfg
);
3188 if (is_export_zebra
)
3189 vnc_zebra_add_group(bgp
, rfg
);
3194 DEFUN (vnc_vrf_policy_rt_export
,
3195 vnc_vrf_policy_rt_export_cmd
,
3196 "rt export RTLIST...",
3197 "Specify route targets\n"
3199 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3201 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3202 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3205 /* make sure it's still in list */
3206 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3207 /* Not in list anymore */
3208 vty_out(vty
, "Current NVE group no longer exists\n");
3209 return CMD_WARNING_CONFIG_FAILED
;
3212 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3213 vnc_redistribute_prechange(bgp
);
3216 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
3218 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3219 vnc_redistribute_postchange(bgp
);
3225 DEFUN (vnc_vrf_policy_rt_both
,
3226 vnc_vrf_policy_rt_both_cmd
,
3227 "rt both RTLIST...",
3228 "Specify route targets\n"
3229 "Export+import filters\n"
3230 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3232 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3233 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3235 int is_export_bgp
= 0;
3236 int is_export_zebra
= 0;
3237 struct listnode
*node
;
3238 struct rfapi_rfg_name
*rfgn
;
3240 /* make sure it's still in list */
3241 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3242 /* Not in list anymore */
3243 vty_out(vty
, "Current NVE group no longer exists\n");
3244 return CMD_WARNING_CONFIG_FAILED
;
3247 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
3248 if (rc
!= CMD_SUCCESS
)
3251 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
3254 if (rfgn
->rfg
== rfg
) {
3261 vnc_direct_bgp_del_group(bgp
, rfg
);
3263 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
3266 if (rfgn
->rfg
== rfg
) {
3267 is_export_zebra
= 1;
3272 if (is_export_zebra
) {
3273 vnc_zlog_debug_verbose("%s: is_export_zebra", __func__
);
3274 vnc_zebra_del_group(bgp
, rfg
);
3278 * stop referencing old import table, now reference new one
3280 if (rfg
->rfapi_import_table
)
3281 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
3282 rfg
->rfapi_import_table
=
3283 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
3286 vnc_direct_bgp_add_group(bgp
, rfg
);
3288 if (is_export_zebra
)
3289 vnc_zebra_add_group(bgp
, rfg
);
3291 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3292 vnc_redistribute_prechange(bgp
);
3295 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
3297 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3298 vnc_redistribute_postchange(bgp
);
3304 DEFUN (vnc_vrf_policy_rd
,
3305 vnc_vrf_policy_rd_cmd
,
3306 "rd ASN:NN_OR_IP-ADDRESS:NN",
3307 "Specify default VRF route distinguisher\n"
3308 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:nh:<number> )\n")
3311 struct prefix_rd prd
;
3312 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3313 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3315 /* make sure it's still in list */
3316 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3317 /* Not in list anymore */
3318 vty_out(vty
, "Current NVE group no longer exists\n");
3319 return CMD_WARNING_CONFIG_FAILED
;
3322 if (!strncmp(argv
[1]->arg
, "auto:nh:", 8)) {
3324 * use AF_UNIX to designate automatically-assigned RD
3325 * auto:vn:nn where nn is a 2-octet quantity
3328 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
3329 uint16_t value
= value32
& 0xffff;
3331 if (!*(argv
[1]->arg
+ 5) || *end
) {
3332 vty_out(vty
, "%% Malformed rd\n");
3333 return CMD_WARNING_CONFIG_FAILED
;
3335 if (value32
> 0xffff) {
3336 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
3338 return CMD_WARNING_CONFIG_FAILED
;
3341 memset(&prd
, 0, sizeof(prd
));
3342 prd
.family
= AF_UNIX
;
3344 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
3345 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
3346 prd
.val
[6] = (value
>> 8) & 0x0ff;
3347 prd
.val
[7] = value
& 0x0ff;
3351 /* TODO: save RD format */
3352 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
3354 vty_out(vty
, "%% Malformed rd\n");
3355 return CMD_WARNING_CONFIG_FAILED
;
3359 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3360 vnc_redistribute_prechange(bgp
);
3365 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3366 vnc_redistribute_postchange(bgp
);
3371 DEFUN_NOSH (exit_vrf_policy
,
3372 exit_vrf_policy_cmd
,
3374 "Exit VRF policy configuration mode\n")
3376 if (vty
->node
== BGP_VRF_POLICY_NODE
) {
3377 vty
->node
= BGP_NODE
;
3382 static struct cmd_node bgp_vrf_policy_node
= {
3383 .name
= "bgp vrf policy",
3384 .node
= BGP_VRF_POLICY_NODE
,
3385 .parent_node
= BGP_NODE
,
3386 .prompt
= "%s(config-router-vrf-policy)# ",
3389 /*-------------------------------------------------------------------------
3391 *-----------------------------------------------------------------------*/
3394 DEFUN_NOSH (vnc_l2_group
,
3396 "vnc l2-group NAME",
3397 VNC_CONFIG_STR
"Configure a L2 group\n" "Group name\n")
3399 struct rfapi_l2_group_cfg
*rfg
;
3400 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3401 VNC_VTY_CONFIG_CHECK(bgp
);
3403 /* Search for name */
3404 rfg
= rfapi_l2_group_lookup_byname(bgp
, argv
[2]->arg
);
3407 rfg
= rfapi_l2_group_new();
3409 /* Error out of memory */
3410 vty_out(vty
, "Can't allocate memory for L2 group\n");
3411 return CMD_WARNING_CONFIG_FAILED
;
3413 rfg
->name
= strdup(argv
[2]->arg
);
3414 /* add to tail of list */
3415 listnode_add(bgp
->rfapi_cfg
->l2_groups
, rfg
);
3419 * XXX subsequent calls will need to make sure this item is still
3420 * in the linked list and has the same name
3422 VTY_PUSH_CONTEXT_SUB(BGP_VNC_L2_GROUP_NODE
, rfg
);
3426 static void bgp_rfapi_delete_l2_group(struct vty
*vty
, /* NULL = no output */
3428 struct rfapi_l2_group_cfg
*rfg
)
3432 if (rfg
->rt_import_list
)
3433 ecommunity_free(&rfg
->rt_import_list
);
3434 if (rfg
->rt_export_list
)
3435 ecommunity_free(&rfg
->rt_export_list
);
3437 list_delete(&rfg
->labels
);
3438 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, rfg
->rfp_cfg
);
3439 listnode_delete(bgp
->rfapi_cfg
->l2_groups
, rfg
);
3441 rfapi_l2_group_del(rfg
);
3445 bgp_rfapi_delete_named_l2_group(struct vty
*vty
, /* NULL = no output */
3447 const char *rfg_name
) /* NULL = any */
3449 struct rfapi_l2_group_cfg
*rfg
= NULL
;
3450 struct listnode
*node
, *nnode
;
3452 /* Search for name */
3454 rfg
= rfapi_l2_group_lookup_byname(bgp
, rfg_name
);
3457 vty_out(vty
, "No L2 group named \"%s\"\n",
3459 return CMD_WARNING_CONFIG_FAILED
;
3464 bgp_rfapi_delete_l2_group(vty
, bgp
, rfg
);
3465 else /* must be delete all */
3466 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->l2_groups
, node
, nnode
,
3468 bgp_rfapi_delete_l2_group(vty
, bgp
, rfg
);
3472 DEFUN (vnc_no_l2_group
,
3473 vnc_no_l2_group_cmd
,
3474 "no vnc l2-group NAME",
3477 "Configure a L2 group\n"
3480 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3482 return bgp_rfapi_delete_named_l2_group(vty
, bgp
, argv
[3]->arg
);
3486 DEFUN (vnc_l2_group_lni
,
3487 vnc_l2_group_lni_cmd
,
3488 "logical-network-id (0-4294967295)",
3489 "Specify Logical Network ID associated with group\n"
3492 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3493 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3495 /* make sure it's still in list */
3496 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3497 /* Not in list anymore */
3498 vty_out(vty
, "Current L2 group no longer exists\n");
3499 return CMD_WARNING_CONFIG_FAILED
;
3502 rfg
->logical_net_id
= strtoul(argv
[1]->arg
, NULL
, 10);
3507 DEFUN (vnc_l2_group_labels
,
3508 vnc_l2_group_labels_cmd
,
3509 "labels (0-1048575)...",
3510 "Specify label values associated with group\n"
3511 "Space separated list of label values <0-1048575>\n")
3513 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3514 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
;
3531 for (; argc
; --argc
, ++argv
) {
3533 label
= strtoul(argv
[0]->arg
, NULL
, 10);
3534 if (!listnode_lookup(ll
, (void *)(uintptr_t)label
))
3535 listnode_add(ll
, (void *)(uintptr_t)label
);
3541 DEFUN (vnc_l2_group_no_labels
,
3542 vnc_l2_group_no_labels_cmd
,
3543 "no labels (0-1048575)...",
3545 "Specify label values associated with L2 group\n"
3546 "Space separated list of label values <0-1048575>\n")
3548 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3549 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3552 /* make sure it's still in list */
3553 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3554 /* Not in list anymore */
3555 vty_out(vty
, "Current L2 group no longer exists\n");
3556 return CMD_WARNING_CONFIG_FAILED
;
3561 vty_out(vty
, "Label no longer associated with group\n");
3562 return CMD_WARNING_CONFIG_FAILED
;
3567 for (; argc
; --argc
, ++argv
) {
3569 label
= strtoul(argv
[0]->arg
, NULL
, 10);
3570 listnode_delete(ll
, (void *)(uintptr_t)label
);
3576 DEFUN (vnc_l2_group_rt
,
3577 vnc_l2_group_rt_cmd
,
3578 "rt <both|export|import> ASN:NN_OR_IP-ADDRESS:NN",
3579 "Specify route targets\n"
3580 "Export+import filters\n"
3585 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3586 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3587 int rc
= CMD_SUCCESS
;
3591 switch (argv
[1]->arg
[0]) {
3593 do_export
= 1; /* fall through */
3601 vty_out(vty
, "Unknown option, %s\n", argv
[1]->arg
);
3602 return CMD_ERR_NO_MATCH
;
3605 /* make sure it's still in list */
3606 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3607 /* Not in list anymore */
3608 vty_out(vty
, "Current L2 group no longer exists\n");
3609 return CMD_WARNING_CONFIG_FAILED
;
3613 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
3614 &rfg
->rt_import_list
);
3615 if (rc
== CMD_SUCCESS
&& do_export
)
3616 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
3617 &rfg
->rt_export_list
);
3622 static struct cmd_node bgp_vnc_l2_group_node
= {
3623 .name
= "bgp vnc l2",
3624 .node
= BGP_VNC_L2_GROUP_NODE
,
3625 .parent_node
= BGP_NODE
,
3626 .prompt
= "%s(config-router-vnc-l2-group)# ",
3629 struct rfapi_l2_group_cfg
*
3630 bgp_rfapi_get_group_by_lni_label(struct bgp
*bgp
, uint32_t logical_net_id
,
3633 struct rfapi_l2_group_cfg
*rfg
;
3634 struct listnode
*node
;
3636 if (bgp
->rfapi_cfg
->l2_groups
== NULL
) /* not the best place for this */
3639 label
= label
& 0xfffff; /* label is 20 bits! */
3641 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->l2_groups
, node
, rfg
)) {
3642 if (rfg
->logical_net_id
== logical_net_id
) {
3643 struct listnode
*lnode
;
3645 for (ALL_LIST_ELEMENTS_RO(rfg
->labels
, lnode
, data
))
3646 if (((uint32_t)((uintptr_t)data
))
3647 == label
) { /* match! */
3655 struct list
*bgp_rfapi_get_labellist_by_lni_label(struct bgp
*bgp
,
3656 uint32_t logical_net_id
,
3659 struct rfapi_l2_group_cfg
*rfg
;
3660 rfg
= bgp_rfapi_get_group_by_lni_label(bgp
, logical_net_id
, label
);
3668 bgp_rfapi_get_ecommunity_by_lni_label(struct bgp
*bgp
, uint32_t is_import
,
3669 uint32_t logical_net_id
, uint32_t label
)
3671 struct rfapi_l2_group_cfg
*rfg
;
3672 rfg
= bgp_rfapi_get_group_by_lni_label(bgp
, logical_net_id
, label
);
3675 return rfg
->rt_import_list
;
3677 return rfg
->rt_export_list
;
3682 void bgp_rfapi_cfg_init(void)
3684 install_node(&bgp_vnc_defaults_node
);
3685 install_node(&bgp_vnc_nve_group_node
);
3686 install_node(&bgp_vrf_policy_node
);
3687 install_node(&bgp_vnc_l2_group_node
);
3688 install_default(BGP_VRF_POLICY_NODE
);
3689 install_default(BGP_VNC_DEFAULTS_NODE
);
3690 install_default(BGP_VNC_NVE_GROUP_NODE
);
3691 install_default(BGP_VNC_L2_GROUP_NODE
);
3696 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3697 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3698 install_element(BGP_NODE
, &vnc_no_nve_group_cmd
);
3699 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3700 install_element(BGP_NODE
, &vnc_no_vrf_policy_cmd
);
3701 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3702 install_element(BGP_NODE
, &vnc_no_l2_group_cmd
);
3703 install_element(BGP_NODE
, &vnc_advertise_un_method_cmd
);
3704 install_element(BGP_NODE
, &vnc_export_mode_cmd
);
3706 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_import_cmd
);
3707 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_export_cmd
);
3708 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_both_cmd
);
3709 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rd_cmd
);
3710 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_l2rd_cmd
);
3711 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_no_l2rd_cmd
);
3712 install_element(BGP_VNC_DEFAULTS_NODE
,
3713 &vnc_defaults_responselifetime_cmd
);
3714 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_cmd
);
3716 install_element(BGP_NODE
, &vnc_redistribute_protocol_cmd
);
3717 install_element(BGP_NODE
, &vnc_no_redistribute_protocol_cmd
);
3718 install_element(BGP_NODE
, &vnc_redistribute_nvegroup_cmd
);
3719 install_element(BGP_NODE
, &vnc_redistribute_no_nvegroup_cmd
);
3720 install_element(BGP_NODE
, &vnc_redistribute_lifetime_cmd
);
3721 install_element(BGP_NODE
, &vnc_redistribute_rh_roo_localadmin_cmd
);
3722 install_element(BGP_NODE
, &vnc_redistribute_mode_cmd
);
3723 install_element(BGP_NODE
, &vnc_redistribute_bgp_exterior_cmd
);
3725 install_element(BGP_NODE
, &vnc_redist_bgpdirect_no_prefixlist_cmd
);
3726 install_element(BGP_NODE
, &vnc_redist_bgpdirect_prefixlist_cmd
);
3727 install_element(BGP_NODE
, &vnc_redist_bgpdirect_no_routemap_cmd
);
3728 install_element(BGP_NODE
, &vnc_redist_bgpdirect_routemap_cmd
);
3730 install_element(BGP_VNC_NVE_GROUP_NODE
,
3731 &vnc_nve_group_redist_bgpdirect_no_prefixlist_cmd
);
3732 install_element(BGP_VNC_NVE_GROUP_NODE
,
3733 &vnc_nve_group_redist_bgpdirect_prefixlist_cmd
);
3734 install_element(BGP_VNC_NVE_GROUP_NODE
,
3735 &vnc_nve_group_redist_bgpdirect_no_routemap_cmd
);
3736 install_element(BGP_VNC_NVE_GROUP_NODE
,
3737 &vnc_nve_group_redist_bgpdirect_routemap_cmd
);
3739 install_element(BGP_NODE
, &vnc_export_nvegroup_cmd
);
3740 install_element(BGP_NODE
, &vnc_no_export_nvegroup_cmd
);
3741 install_element(BGP_NODE
, &vnc_nve_export_prefixlist_cmd
);
3742 install_element(BGP_NODE
, &vnc_nve_export_routemap_cmd
);
3743 install_element(BGP_NODE
, &vnc_nve_export_no_prefixlist_cmd
);
3744 install_element(BGP_NODE
, &vnc_nve_export_no_routemap_cmd
);
3746 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_l2rd_cmd
);
3747 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_no_l2rd_cmd
);
3748 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_prefix_cmd
);
3749 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_import_cmd
);
3750 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_export_cmd
);
3751 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_both_cmd
);
3752 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rd_cmd
);
3753 install_element(BGP_VNC_NVE_GROUP_NODE
,
3754 &vnc_nve_group_responselifetime_cmd
);
3755 install_element(BGP_VNC_NVE_GROUP_NODE
,
3756 &vnc_nve_group_export_prefixlist_cmd
);
3757 install_element(BGP_VNC_NVE_GROUP_NODE
,
3758 &vnc_nve_group_export_routemap_cmd
);
3759 install_element(BGP_VNC_NVE_GROUP_NODE
,
3760 &vnc_nve_group_export_no_prefixlist_cmd
);
3761 install_element(BGP_VNC_NVE_GROUP_NODE
,
3762 &vnc_nve_group_export_no_routemap_cmd
);
3763 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_cmd
);
3765 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_label_cmd
);
3766 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_no_label_cmd
);
3767 // Reenable to support VRF controller use case and testing
3768 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_nexthop_cmd
);
3769 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_import_cmd
);
3770 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_export_cmd
);
3771 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_both_cmd
);
3772 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rd_cmd
);
3773 install_element(BGP_VRF_POLICY_NODE
,
3774 &vnc_vrf_policy_export_prefixlist_cmd
);
3775 install_element(BGP_VRF_POLICY_NODE
,
3776 &vnc_vrf_policy_export_routemap_cmd
);
3777 install_element(BGP_VRF_POLICY_NODE
,
3778 &vnc_vrf_policy_export_no_prefixlist_cmd
);
3779 install_element(BGP_VRF_POLICY_NODE
,
3780 &vnc_vrf_policy_export_no_routemap_cmd
);
3781 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
3783 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_lni_cmd
);
3784 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_labels_cmd
);
3785 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_no_labels_cmd
);
3786 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_rt_cmd
);
3787 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_cmd
);
3790 struct rfapi_cfg
*bgp_rfapi_cfg_new(struct rfapi_rfp_cfg
*cfg
)
3792 struct rfapi_cfg
*h
;
3795 h
= XCALLOC(MTYPE_RFAPI_CFG
, sizeof(struct rfapi_cfg
));
3798 h
->nve_groups_sequential
= list_new();
3799 assert(h
->nve_groups_sequential
);
3800 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
3801 h
->nve_groups_vn
[afi
] = agg_table_init();
3802 h
->nve_groups_un
[afi
] = agg_table_init();
3804 h
->default_response_lifetime
=
3805 BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT
;
3806 h
->rfg_export_direct_bgp_l
= list_new();
3807 h
->rfg_export_zebra_l
= list_new();
3808 h
->resolve_nve_roo_local_admin
=
3809 BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT
;
3811 SET_FLAG(h
->flags
, BGP_VNC_CONFIG_FLAGS_DEFAULT
);
3814 h
->rfp_cfg
.download_type
= RFAPI_RFP_DOWNLOAD_PARTIAL
;
3815 h
->rfp_cfg
.ftd_advertisement_interval
=
3816 RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL
;
3817 h
->rfp_cfg
.holddown_factor
=
3818 RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR
;
3819 h
->rfp_cfg
.use_updated_response
= 0;
3820 h
->rfp_cfg
.use_removes
= 0;
3822 h
->rfp_cfg
.download_type
= cfg
->download_type
;
3823 h
->rfp_cfg
.ftd_advertisement_interval
=
3824 cfg
->ftd_advertisement_interval
;
3825 h
->rfp_cfg
.holddown_factor
= cfg
->holddown_factor
;
3826 h
->rfp_cfg
.use_updated_response
= cfg
->use_updated_response
;
3827 h
->rfp_cfg
.use_removes
= cfg
->use_removes
;
3828 if (cfg
->use_updated_response
)
3829 h
->flags
&= ~BGP_VNC_CONFIG_CALLBACK_DISABLE
;
3831 h
->flags
|= BGP_VNC_CONFIG_CALLBACK_DISABLE
;
3832 if (cfg
->use_removes
)
3833 h
->flags
&= ~BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE
;
3835 h
->flags
|= BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE
;
3840 static void bgp_rfapi_rfgn_list_delete(void *data
)
3842 struct rfapi_rfg_name
*rfgn
= data
;
3847 void bgp_rfapi_cfg_destroy(struct bgp
*bgp
, struct rfapi_cfg
*h
)
3853 bgp_rfapi_delete_named_nve_group(NULL
, bgp
, NULL
, RFAPI_GROUP_CFG_MAX
);
3854 bgp_rfapi_delete_named_l2_group(NULL
, bgp
, NULL
);
3855 if (h
->l2_groups
!= NULL
)
3856 list_delete(&h
->l2_groups
);
3857 list_delete(&h
->nve_groups_sequential
);
3859 h
->rfg_export_direct_bgp_l
->del
= bgp_rfapi_rfgn_list_delete
;
3860 list_delete(&h
->rfg_export_direct_bgp_l
);
3862 h
->rfg_export_zebra_l
->del
= bgp_rfapi_rfgn_list_delete
;
3863 list_delete(&h
->rfg_export_zebra_l
);
3865 if (h
->default_rt_export_list
)
3866 ecommunity_free(&h
->default_rt_export_list
);
3867 if (h
->default_rt_import_list
)
3868 ecommunity_free(&h
->default_rt_import_list
);
3869 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, h
->default_rfp_cfg
);
3870 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
3871 agg_table_finish(h
->nve_groups_vn
[afi
]);
3872 agg_table_finish(h
->nve_groups_un
[afi
]);
3874 XFREE(MTYPE_RFAPI_CFG
, h
);
3877 int bgp_rfapi_cfg_write(struct vty
*vty
, struct bgp
*bgp
)
3879 struct listnode
*node
, *nnode
;
3880 struct rfapi_nve_group_cfg
*rfg
;
3881 struct rfapi_cfg
*hc
= bgp
->rfapi_cfg
;
3882 struct rfapi_rfg_name
*rfgn
;
3886 if (bgp
->rfapi
== NULL
|| hc
== NULL
)
3889 vty_out(vty
, "!\n");
3890 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
, rfg
))
3891 if (rfg
->type
== RFAPI_GROUP_CFG_VRF
) {
3893 vty_out(vty
, " vrf-policy %s\n", rfg
->name
);
3894 if (rfg
->label
<= MPLS_LABEL_MAX
) {
3895 vty_out(vty
, " label %u\n", rfg
->label
);
3897 if (CHECK_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
)) {
3898 vty_out(vty
, " nexthop self\n");
3901 if (rfg
->vn_prefix
.family
) {
3903 buf
[0] = buf
[BUFSIZ
- 1] = 0;
3904 inet_ntop(rfg
->vn_prefix
.family
,
3905 &rfg
->vn_prefix
.u
.prefix
, buf
,
3907 if (!buf
[0] || buf
[BUFSIZ
- 1]) {
3908 // vty_out (vty, "nexthop
3911 vty_out(vty
, " nexthop %s\n",
3917 if (rfg
->rd
.prefixlen
) {
3918 if (AF_UNIX
== rfg
->rd
.family
) {
3922 value
= ((rfg
->rd
.val
[6] << 8)
3924 | (rfg
->rd
.val
[7] & 0x0ff);
3926 vty_out(vty
, " rd auto:nh:%d\n",
3930 vty_out(vty
, " rd %pRDP\n", &rfg
->rd
);
3933 if (rfg
->rt_import_list
&& rfg
->rt_export_list
3934 && ecommunity_cmp(rfg
->rt_import_list
,
3935 rfg
->rt_export_list
)) {
3936 char *b
= ecommunity_ecom2str(
3937 rfg
->rt_import_list
,
3938 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3939 ECOMMUNITY_ROUTE_TARGET
);
3940 vty_out(vty
, " rt both %s\n", b
);
3941 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3943 if (rfg
->rt_import_list
) {
3944 char *b
= ecommunity_ecom2str(
3945 rfg
->rt_import_list
,
3946 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3947 ECOMMUNITY_ROUTE_TARGET
);
3948 vty_out(vty
, " rt import %s\n", b
);
3949 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3951 if (rfg
->rt_export_list
) {
3952 char *b
= ecommunity_ecom2str(
3953 rfg
->rt_export_list
,
3954 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3955 ECOMMUNITY_ROUTE_TARGET
);
3956 vty_out(vty
, " rt export %s\n", b
);
3957 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3962 * route filtering: prefix-lists and route-maps
3964 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
3966 const char *afistr
=
3967 (afi
== AFI_IP
) ? "ipv4" : "ipv6";
3969 if (rfg
->plist_export_bgp_name
[afi
]) {
3971 " export %s%s prefix-list %s\n",
3972 (rfg
->type
== RFAPI_GROUP_CFG_VRF
3976 rfg
->plist_export_bgp_name
3979 if (rfg
->plist_export_zebra_name
[afi
]) {
3981 " export %s%s prefix-list %s\n",
3982 (rfg
->type
== RFAPI_GROUP_CFG_VRF
3986 rfg
->plist_export_zebra_name
3990 * currently we only support redist plists for
3992 * If we later add plist support for
3993 * redistributing other
3994 * protocols, we'll need to loop over protocols
3997 if (rfg
->plist_redist_name
3998 [ZEBRA_ROUTE_BGP_DIRECT
][afi
]) {
4000 " redistribute bgp-direct %s prefix-list %s\n",
4002 rfg
->plist_redist_name
4003 [ZEBRA_ROUTE_BGP_DIRECT
]
4006 if (rfg
->plist_redist_name
4007 [ZEBRA_ROUTE_BGP_DIRECT_EXT
][afi
]) {
4009 " redistribute bgp-direct-to-nve-groups %s prefix-list %s\n",
4011 rfg
->plist_redist_name
4012 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4017 if (rfg
->routemap_export_bgp_name
) {
4018 vty_out(vty
, " export %sroute-map %s\n",
4019 (rfg
->type
== RFAPI_GROUP_CFG_VRF
4022 rfg
->routemap_export_bgp_name
);
4024 if (rfg
->routemap_export_zebra_name
) {
4025 vty_out(vty
, " export %sroute-map %s\n",
4026 (rfg
->type
== RFAPI_GROUP_CFG_VRF
4029 rfg
->routemap_export_zebra_name
);
4031 if (rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]) {
4033 " redistribute bgp-direct route-map %s\n",
4034 rfg
->routemap_redist_name
4035 [ZEBRA_ROUTE_BGP_DIRECT
]);
4037 if (rfg
->routemap_redist_name
4038 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]) {
4040 " redistribute bgp-direct-to-nve-groups route-map %s\n",
4041 rfg
->routemap_redist_name
4042 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]);
4044 vty_out(vty
, " exit-vrf-policy\n");
4045 vty_out(vty
, "!\n");
4047 if (hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
) {
4048 vty_out(vty
, " vnc advertise-un-method encap-safi\n");
4052 { /* was based on listen ports */
4053 /* for now allow both old and new */
4054 if (bgp
->rfapi
->rfp_methods
.cfg_cb
)
4055 write
+= (bgp
->rfapi
->rfp_methods
.cfg_cb
)(
4056 vty
, bgp
->rfapi
->rfp
);
4059 vty_out(vty
, "!\n");
4061 if (hc
->l2_groups
) {
4062 struct rfapi_l2_group_cfg
*rfgc
= NULL
;
4063 struct listnode
*gnode
;
4064 for (ALL_LIST_ELEMENTS_RO(hc
->l2_groups
, gnode
, rfgc
)) {
4065 struct listnode
*lnode
;
4068 vty_out(vty
, " vnc l2-group %s\n", rfgc
->name
);
4069 if (rfgc
->logical_net_id
!= 0)
4071 " logical-network-id %u\n",
4072 rfgc
->logical_net_id
);
4073 if (rfgc
->labels
!= NULL
4074 && listhead(rfgc
->labels
) != NULL
) {
4075 vty_out(vty
, " labels ");
4076 for (ALL_LIST_ELEMENTS_RO(rfgc
->labels
,
4079 vty_out(vty
, "%hu ",
4087 if (rfgc
->rt_import_list
&& rfgc
->rt_export_list
4088 && ecommunity_cmp(rfgc
->rt_import_list
,
4089 rfgc
->rt_export_list
)) {
4090 char *b
= ecommunity_ecom2str(
4091 rfgc
->rt_import_list
,
4092 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4093 ECOMMUNITY_ROUTE_TARGET
);
4094 vty_out(vty
, " rt both %s\n", b
);
4095 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4097 if (rfgc
->rt_import_list
) {
4098 char *b
= ecommunity_ecom2str(
4099 rfgc
->rt_import_list
,
4100 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4101 ECOMMUNITY_ROUTE_TARGET
);
4102 vty_out(vty
, " rt import %s\n",
4104 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4106 if (rfgc
->rt_export_list
) {
4107 char *b
= ecommunity_ecom2str(
4108 rfgc
->rt_export_list
,
4109 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4110 ECOMMUNITY_ROUTE_TARGET
);
4111 vty_out(vty
, " rt export %s\n",
4113 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4116 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4117 write
+= (bgp
->rfapi
->rfp_methods
4119 vty
, bgp
->rfapi
->rfp
,
4120 RFAPI_RFP_CFG_GROUP_L2
,
4121 rfgc
->name
, rfgc
->rfp_cfg
);
4122 vty_out(vty
, " exit-vnc\n");
4123 vty_out(vty
, "!\n");
4127 if (hc
->default_rd
.prefixlen
4128 || hc
->default_response_lifetime
4129 != BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT
4130 || hc
->default_rt_import_list
|| hc
->default_rt_export_list
4131 || hc
->nve_groups_sequential
->count
) {
4135 vty_out(vty
, " vnc defaults\n");
4137 if (hc
->default_rd
.prefixlen
) {
4138 if (AF_UNIX
== hc
->default_rd
.family
) {
4141 value
= ((hc
->default_rd
.val
[6] << 8)
4143 | (hc
->default_rd
.val
[7]
4146 vty_out(vty
, " rd auto:vn:%d\n",
4150 vty_out(vty
, " rd %pRDP\n",
4153 if (hc
->default_response_lifetime
4154 != BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT
) {
4155 vty_out(vty
, " response-lifetime ");
4156 if (hc
->default_response_lifetime
!= UINT32_MAX
)
4158 hc
->default_response_lifetime
);
4160 vty_out(vty
, "infinite");
4163 if (hc
->default_rt_import_list
4164 && hc
->default_rt_export_list
4165 && ecommunity_cmp(hc
->default_rt_import_list
,
4166 hc
->default_rt_export_list
)) {
4167 char *b
= ecommunity_ecom2str(
4168 hc
->default_rt_import_list
,
4169 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4170 ECOMMUNITY_ROUTE_TARGET
);
4171 vty_out(vty
, " rt both %s\n", b
);
4172 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4174 if (hc
->default_rt_import_list
) {
4175 char *b
= ecommunity_ecom2str(
4176 hc
->default_rt_import_list
,
4177 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4178 ECOMMUNITY_ROUTE_TARGET
);
4179 vty_out(vty
, " rt import %s\n", b
);
4180 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4182 if (hc
->default_rt_export_list
) {
4183 char *b
= ecommunity_ecom2str(
4184 hc
->default_rt_export_list
,
4185 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4186 ECOMMUNITY_ROUTE_TARGET
);
4187 vty_out(vty
, " rt export %s\n", b
);
4188 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4191 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4192 write
+= (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)(
4193 vty
, bgp
->rfapi
->rfp
,
4194 RFAPI_RFP_CFG_GROUP_DEFAULT
, NULL
,
4195 bgp
->rfapi_cfg
->default_rfp_cfg
);
4196 vty_out(vty
, " exit-vnc\n");
4197 vty_out(vty
, "!\n");
4200 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
,
4202 if (rfg
->type
== RFAPI_GROUP_CFG_NVE
) {
4204 vty_out(vty
, " vnc nve-group %s\n", rfg
->name
);
4206 if (rfg
->vn_prefix
.family
&& rfg
->vn_node
)
4207 vty_out(vty
, " prefix %s %pFX\n", "vn",
4210 if (rfg
->un_prefix
.family
&& rfg
->un_node
)
4211 vty_out(vty
, " prefix %s %pFX\n", "un",
4215 if (rfg
->rd
.prefixlen
) {
4216 if (AF_UNIX
== rfg
->rd
.family
) {
4220 value
= ((rfg
->rd
.val
[6] << 8)
4230 vty_out(vty
, " rd %pRDP\n",
4233 if (rfg
->flags
& RFAPI_RFG_RESPONSE_LIFETIME
) {
4234 vty_out(vty
, " response-lifetime ");
4235 if (rfg
->response_lifetime
4238 rfg
->response_lifetime
);
4240 vty_out(vty
, "infinite");
4244 if (rfg
->rt_import_list
&& rfg
->rt_export_list
4245 && ecommunity_cmp(rfg
->rt_import_list
,
4246 rfg
->rt_export_list
)) {
4247 char *b
= ecommunity_ecom2str(
4248 rfg
->rt_import_list
,
4249 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4250 ECOMMUNITY_ROUTE_TARGET
);
4251 vty_out(vty
, " rt both %s\n", b
);
4252 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4254 if (rfg
->rt_import_list
) {
4255 char *b
= ecommunity_ecom2str(
4256 rfg
->rt_import_list
,
4257 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4258 ECOMMUNITY_ROUTE_TARGET
);
4259 vty_out(vty
, " rt import %s\n",
4261 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4263 if (rfg
->rt_export_list
) {
4264 char *b
= ecommunity_ecom2str(
4265 rfg
->rt_export_list
,
4266 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4267 ECOMMUNITY_ROUTE_TARGET
);
4268 vty_out(vty
, " rt export %s\n",
4270 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4275 * route filtering: prefix-lists and route-maps
4277 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4279 const char *afistr
= (afi
== AFI_IP
)
4283 if (rfg
->plist_export_bgp_name
[afi
]) {
4285 " export bgp %s prefix-list %s\n",
4287 rfg
->plist_export_bgp_name
4290 if (rfg
->plist_export_zebra_name
[afi
]) {
4292 " export zebra %s prefix-list %s\n",
4294 rfg
->plist_export_zebra_name
4298 * currently we only support redist
4299 * plists for bgp-direct.
4300 * If we later add plist support for
4301 * redistributing other
4302 * protocols, we'll need to loop over
4305 if (rfg
->plist_redist_name
4306 [ZEBRA_ROUTE_BGP_DIRECT
]
4309 " redistribute bgp-direct %s prefix-list %s\n",
4311 rfg
->plist_redist_name
4312 [ZEBRA_ROUTE_BGP_DIRECT
]
4315 if (rfg
->plist_redist_name
4316 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4319 " redistribute bgp-direct-to-nve-groups %s prefix-list %s\n",
4321 rfg
->plist_redist_name
4322 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4327 if (rfg
->routemap_export_bgp_name
) {
4329 " export bgp route-map %s\n",
4330 rfg
->routemap_export_bgp_name
);
4332 if (rfg
->routemap_export_zebra_name
) {
4334 " export zebra route-map %s\n",
4335 rfg
->routemap_export_zebra_name
);
4337 if (rfg
->routemap_redist_name
4338 [ZEBRA_ROUTE_BGP_DIRECT
]) {
4340 " redistribute bgp-direct route-map %s\n",
4341 rfg
->routemap_redist_name
4342 [ZEBRA_ROUTE_BGP_DIRECT
]);
4344 if (rfg
->routemap_redist_name
4345 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]) {
4347 " redistribute bgp-direct-to-nve-groups route-map %s\n",
4348 rfg
->routemap_redist_name
4349 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]);
4351 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4352 write
+= (bgp
->rfapi
->rfp_methods
4354 vty
, bgp
->rfapi
->rfp
,
4355 RFAPI_RFP_CFG_GROUP_NVE
,
4356 rfg
->name
, rfg
->rfp_cfg
);
4357 vty_out(vty
, " exit-vnc\n");
4358 vty_out(vty
, "!\n");
4360 } /* have listen ports */
4363 * route export to other protocols
4365 if (VNC_EXPORT_BGP_GRP_ENABLED(hc
)) {
4366 vty_out(vty
, " vnc export bgp mode group-nve\n");
4367 } else if (VNC_EXPORT_BGP_RH_ENABLED(hc
)) {
4368 vty_out(vty
, " vnc export bgp mode registering-nve\n");
4369 } else if (VNC_EXPORT_BGP_CE_ENABLED(hc
)) {
4370 vty_out(vty
, " vnc export bgp mode ce\n");
4373 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(hc
)) {
4374 vty_out(vty
, " vnc export zebra mode group-nve\n");
4375 } else if (VNC_EXPORT_ZEBRA_RH_ENABLED(hc
)) {
4376 vty_out(vty
, " vnc export zebra mode registering-nve\n");
4379 if (hc
->rfg_export_direct_bgp_l
) {
4380 for (ALL_LIST_ELEMENTS(hc
->rfg_export_direct_bgp_l
, node
, nnode
,
4383 vty_out(vty
, " vnc export bgp group-nve group %s\n",
4388 if (hc
->rfg_export_zebra_l
) {
4389 for (ALL_LIST_ELEMENTS(hc
->rfg_export_zebra_l
, node
, nnode
,
4392 vty_out(vty
, " vnc export zebra group-nve group %s\n",
4398 if (hc
->rfg_redist_name
) {
4399 vty_out(vty
, " vnc redistribute nve-group %s\n",
4400 hc
->rfg_redist_name
);
4402 if (hc
->redist_lifetime
) {
4403 vty_out(vty
, " vnc redistribute lifetime %d\n",
4404 hc
->redist_lifetime
);
4406 if (hc
->resolve_nve_roo_local_admin
4407 != BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT
) {
4410 " vnc redistribute resolve-nve roo-ec-local-admin %d\n",
4411 hc
->resolve_nve_roo_local_admin
);
4414 if (hc
->redist_mode
) /* ! default */
4418 switch (hc
->redist_mode
) {
4419 case VNC_REDIST_MODE_PLAIN
:
4422 case VNC_REDIST_MODE_RFG
:
4425 case VNC_REDIST_MODE_RESOLVE_NVE
:
4430 vty_out(vty
, " vnc redistribute mode %s\n", s
);
4435 * route filtering: prefix-lists and route-maps
4437 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4439 const char *afistr
= (afi
== AFI_IP
) ? "ipv4" : "ipv6";
4441 if (hc
->plist_export_bgp_name
[afi
]) {
4442 vty_out(vty
, " vnc export bgp %s prefix-list %s\n",
4443 afistr
, hc
->plist_export_bgp_name
[afi
]);
4445 if (hc
->plist_export_zebra_name
[afi
]) {
4446 vty_out(vty
, " vnc export zebra %s prefix-list %s\n",
4447 afistr
, hc
->plist_export_zebra_name
[afi
]);
4449 if (hc
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
]) {
4451 " vnc redistribute bgp-direct %s prefix-list %s\n",
4453 hc
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]
4458 if (hc
->routemap_export_bgp_name
) {
4459 vty_out(vty
, " vnc export bgp route-map %s\n",
4460 hc
->routemap_export_bgp_name
);
4462 if (hc
->routemap_export_zebra_name
) {
4463 vty_out(vty
, " vnc export zebra route-map %s\n",
4464 hc
->routemap_export_zebra_name
);
4466 if (hc
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]) {
4467 vty_out(vty
, " vnc redistribute bgp-direct route-map %s\n",
4468 hc
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]);
4471 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4472 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
4473 if (hc
->redist
[afi
][type
]) {
4474 if (type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
4475 && hc
->redist_bgp_exterior_view_name
) {
4477 " vnc redistribute %s %s view %s\n",
4478 ((afi
== AFI_IP
) ? "ipv4"
4480 zebra_route_string(type
),
4481 hc
->redist_bgp_exterior_view_name
);
4484 " vnc redistribute %s %s\n",
4485 ((afi
== AFI_IP
) ? "ipv4"
4487 zebra_route_string(type
));
4495 void bgp_rfapi_show_summary(struct bgp
*bgp
, struct vty
*vty
)
4497 struct rfapi_cfg
*hc
= bgp
->rfapi_cfg
;
4499 int type
, redist
= 0;
4504 vty_out(vty
, "%-39s %-19s %s\n", "VNC Advertise method:",
4505 (hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
4506 ? "Encapsulation SAFI"
4507 : "Tunnel Encap attribute"),
4508 ((hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
)
4509 == (BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
4510 & BGP_VNC_CONFIG_FLAGS_DEFAULT
)
4514 vty_out(vty
, "%-39s ", "Export from VNC:");
4516 * route export to other protocols
4518 if (VNC_EXPORT_BGP_GRP_ENABLED(hc
)) {
4520 vty_out(vty
, "ToBGP Groups={");
4521 if (hc
->rfg_export_direct_bgp_l
) {
4523 struct listnode
*node
, *nnode
;
4524 struct rfapi_rfg_name
*rfgn
;
4525 for (ALL_LIST_ELEMENTS(hc
->rfg_export_direct_bgp_l
,
4526 node
, nnode
, rfgn
)) {
4530 vty_out(vty
, "%s", rfgn
->name
);
4534 } else if (VNC_EXPORT_BGP_RH_ENABLED(hc
)) {
4536 vty_out(vty
, "ToBGP {Registering NVE}");
4537 /* note filters, route-maps not shown */
4538 } else if (VNC_EXPORT_BGP_CE_ENABLED(hc
)) {
4540 vty_out(vty
, "ToBGP {NVE connected router:%d}",
4541 hc
->resolve_nve_roo_local_admin
);
4542 /* note filters, route-maps not shown */
4545 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(hc
)) {
4547 vty_out(vty
, "%sToZebra Groups={", (redist
== 1 ? "" : " "));
4548 if (hc
->rfg_export_zebra_l
) {
4550 struct listnode
*node
, *nnode
;
4551 struct rfapi_rfg_name
*rfgn
;
4552 for (ALL_LIST_ELEMENTS(hc
->rfg_export_zebra_l
, node
,
4556 vty_out(vty
, "%s", rfgn
->name
);
4560 } else if (VNC_EXPORT_ZEBRA_RH_ENABLED(hc
)) {
4562 vty_out(vty
, "%sToZebra {Registering NVE}",
4563 (redist
== 1 ? "" : " "));
4564 /* note filters, route-maps not shown */
4566 vty_out(vty
, "%-19s %s\n", (redist
? "" : "Off"),
4567 (redist
? "" : "(default)"));
4569 /* Redistribution */
4571 vty_out(vty
, "%-39s ", "Redistribution into VNC:");
4572 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4573 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
4574 if (hc
->redist
[afi
][type
]) {
4575 vty_out(vty
, "{%s,%s} ",
4576 ((afi
== AFI_IP
) ? "ipv4" : "ipv6"),
4577 zebra_route_string(type
));
4582 vty_out(vty
, "%-19s %s\n", (redist
? "" : "Off"),
4583 (redist
? "" : "(default)"));
4585 vty_out(vty
, "%-39s %3u%-16s %s\n",
4586 "RFP Registration Hold-Down Factor:",
4587 hc
->rfp_cfg
.holddown_factor
, "%",
4588 (hc
->rfp_cfg
.holddown_factor
4589 == RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR
4592 vty_out(vty
, "%-39s %-19s %s\n", "RFP Updated responses:",
4593 (hc
->rfp_cfg
.use_updated_response
== 0 ? "Off" : "On"),
4594 (hc
->rfp_cfg
.use_updated_response
== 0 ? "(default)" : ""));
4595 vty_out(vty
, "%-39s %-19s %s\n", "RFP Removal responses:",
4596 (hc
->rfp_cfg
.use_removes
== 0 ? "Off" : "On"),
4597 (hc
->rfp_cfg
.use_removes
== 0 ? "(default)" : ""));
4598 vty_out(vty
, "%-39s %-19s %s\n", "RFP Full table download:",
4599 (hc
->rfp_cfg
.download_type
== RFAPI_RFP_DOWNLOAD_FULL
? "On"
4601 (hc
->rfp_cfg
.download_type
== RFAPI_RFP_DOWNLOAD_PARTIAL
4604 snprintf(tmp
, sizeof(tmp
), "%u seconds",
4605 hc
->rfp_cfg
.ftd_advertisement_interval
);
4606 vty_out(vty
, "%-39s %-19s %s\n", " Advertisement Interval:", tmp
,
4607 (hc
->rfp_cfg
.ftd_advertisement_interval
4608 == RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL
4611 vty_out(vty
, "%-39s %d seconds\n", "Default RFP response lifetime:",
4612 hc
->default_response_lifetime
);
4617 struct rfapi_cfg
*bgp_rfapi_get_config(struct bgp
*bgp
)
4619 struct rfapi_cfg
*hc
= NULL
;
4621 bgp
= bgp_get_default();
4623 hc
= bgp
->rfapi_cfg
;
4627 #endif /* ENABLE_BGP_VNC */