3 * Copyright 2009-2016, LabN Consulting, L.L.C.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "lib/zebra.h"
22 #include "lib/command.h"
23 #include "lib/prefix.h"
24 #include "lib/memory.h"
25 #include "lib/linklist.h"
26 #include "lib/table.h"
27 #include "lib/plist.h"
28 #include "lib/routemap.h"
30 #include "bgpd/bgpd.h"
31 #include "bgpd/bgp_attr.h"
32 #include "bgpd/bgp_route.h"
33 #include "bgpd/bgp_mplsvpn.h"
35 #include "bgpd/bgp_ecommunity.h"
36 #include "bgpd/rfapi/rfapi.h"
37 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
38 #include "bgpd/rfapi/rfapi_backend.h"
39 #include "bgpd/rfapi/rfapi_import.h"
40 #include "bgpd/rfapi/rfapi_private.h"
41 #include "bgpd/rfapi/rfapi_monitor.h"
42 #include "bgpd/rfapi/vnc_zebra.h"
43 #include "bgpd/rfapi/vnc_export_bgp.h"
44 #include "bgpd/rfapi/vnc_export_bgp_p.h"
45 #include "bgpd/rfapi/rfapi_vty.h"
46 #include "bgpd/rfapi/vnc_import_bgp.h"
47 #include "bgpd/rfapi/vnc_debug.h"
51 #undef BGP_VNC_DEBUG_MATCH_GROUP
54 DEFINE_MGROUP(RFAPI
, "rfapi")
55 DEFINE_MTYPE(RFAPI
, RFAPI_CFG
, "NVE Configuration")
56 DEFINE_MTYPE(RFAPI
, RFAPI_GROUP_CFG
, "NVE Group Configuration")
57 DEFINE_MTYPE(RFAPI
, RFAPI_L2_CFG
, "RFAPI L2 Group Configuration")
58 DEFINE_MTYPE(RFAPI
, RFAPI_RFP_GROUP_CFG
, "RFAPI RFP Group Configuration")
59 DEFINE_MTYPE(RFAPI
, RFAPI
, "RFAPI Generic")
60 DEFINE_MTYPE(RFAPI
, RFAPI_DESC
, "RFAPI Descriptor")
61 DEFINE_MTYPE(RFAPI
, RFAPI_IMPORTTABLE
, "RFAPI Import Table")
62 DEFINE_MTYPE(RFAPI
, RFAPI_MONITOR
, "RFAPI Monitor VPN")
63 DEFINE_MTYPE(RFAPI
, RFAPI_MONITOR_ENCAP
, "RFAPI Monitor Encap")
64 DEFINE_MTYPE(RFAPI
, RFAPI_NEXTHOP
, "RFAPI Next Hop")
65 DEFINE_MTYPE(RFAPI
, RFAPI_VN_OPTION
, "RFAPI VN Option")
66 DEFINE_MTYPE(RFAPI
, RFAPI_UN_OPTION
, "RFAPI UN Option")
67 DEFINE_MTYPE(RFAPI
, RFAPI_WITHDRAW
, "RFAPI Withdraw")
68 DEFINE_MTYPE(RFAPI
, RFAPI_RFG_NAME
, "RFAPI RFGName")
69 DEFINE_MTYPE(RFAPI
, RFAPI_ADB
, "RFAPI Advertisement Data")
70 DEFINE_MTYPE(RFAPI
, RFAPI_ETI
, "RFAPI Export Table Info")
71 DEFINE_MTYPE(RFAPI
, RFAPI_NVE_ADDR
, "RFAPI NVE Address")
72 DEFINE_MTYPE(RFAPI
, RFAPI_PREFIX_BAG
, "RFAPI Prefix Bag")
73 DEFINE_MTYPE(RFAPI
, RFAPI_IT_EXTRA
, "RFAPI IT Extra")
74 DEFINE_MTYPE(RFAPI
, RFAPI_INFO
, "RFAPI Info")
75 DEFINE_MTYPE(RFAPI
, RFAPI_ADDR
, "RFAPI Addr")
76 DEFINE_MTYPE(RFAPI
, RFAPI_UPDATED_RESPONSE_QUEUE
, "RFAPI Updated Rsp Queue")
77 DEFINE_MTYPE(RFAPI
, RFAPI_RECENT_DELETE
, "RFAPI Recently Deleted Route")
78 DEFINE_MTYPE(RFAPI
, RFAPI_L2ADDR_OPT
, "RFAPI L2 Address Option")
79 DEFINE_MTYPE(RFAPI
, RFAPI_AP
, "RFAPI Advertised Prefix")
80 DEFINE_MTYPE(RFAPI
, RFAPI_MONITOR_ETH
, "RFAPI Monitor Ethernet")
82 DEFINE_QOBJ_TYPE(rfapi_nve_group_cfg
)
83 DEFINE_QOBJ_TYPE(rfapi_l2_group_cfg
)
84 /***********************************************************************
86 ***********************************************************************/
90 * compaitibility to old quagga_time call
91 * time_t value in terms of stabilised absolute time.
92 * replacement for POSIX time()
94 time_t rfapi_time(time_t *t
)
96 time_t clock
= bgp_clock();
102 void nve_group_to_nve_list(struct rfapi_nve_group_cfg
*rfg
, struct list
**nves
,
103 uint8_t family
) /* AF_INET, AF_INET6 */
105 struct listnode
*hln
;
106 struct rfapi_descriptor
*rfd
;
109 * loop over nves in this grp, add to list
111 for (ALL_LIST_ELEMENTS_RO(rfg
->nves
, hln
, rfd
)) {
112 if (rfd
->vn_addr
.addr_family
== family
) {
115 listnode_add(*nves
, rfd
);
121 struct rfapi_nve_group_cfg
*bgp_rfapi_cfg_match_group(struct rfapi_cfg
*hc
,
125 struct rfapi_nve_group_cfg
*rfg_vn
= NULL
;
126 struct rfapi_nve_group_cfg
*rfg_un
= NULL
;
128 struct route_table
*rt_vn
;
129 struct route_table
*rt_un
;
130 struct route_node
*rn_vn
;
131 struct route_node
*rn_un
;
133 struct rfapi_nve_group_cfg
*rfg
;
134 struct listnode
*node
, *nnode
;
136 switch (vn
->family
) {
138 rt_vn
= hc
->nve_groups_vn
[AFI_IP
];
141 rt_vn
= hc
->nve_groups_vn
[AFI_IP6
];
147 switch (un
->family
) {
149 rt_un
= hc
->nve_groups_un
[AFI_IP
];
152 rt_un
= hc
->nve_groups_un
[AFI_IP6
];
158 rn_vn
= route_node_match(rt_vn
, vn
); /* NB locks node */
160 rfg_vn
= rn_vn
->info
;
161 route_unlock_node(rn_vn
);
164 rn_un
= route_node_match(rt_un
, un
); /* NB locks node */
166 rfg_un
= rn_un
->info
;
167 route_unlock_node(rn_un
);
170 #if BGP_VNC_DEBUG_MATCH_GROUP
174 prefix2str(vn
, buf
, BUFSIZ
);
175 vnc_zlog_debug_verbose("%s: vn prefix: %s", __func__
, buf
);
177 prefix2str(un
, buf
, BUFSIZ
);
178 vnc_zlog_debug_verbose("%s: un prefix: %s", __func__
, buf
);
180 vnc_zlog_debug_verbose(
181 "%s: rn_vn=%p, rn_un=%p, rfg_vn=%p, rfg_un=%p",
182 __func__
, rn_vn
, rn_un
, rfg_vn
, rfg_un
);
187 if (rfg_un
== rfg_vn
) /* same group */
189 if (!rfg_un
) /* un doesn't match, return vn-matched grp */
191 if (!rfg_vn
) /* vn doesn't match, return un-matched grp */
195 * Two different nve groups match: the group configured earlier wins.
196 * For now, just walk the sequential list and pick the first one.
197 * If this approach is too slow, then store serial numbers in the
198 * nve group structures as they are defined and just compare
201 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
, rfg
)) {
202 if ((rfg
== rfg_un
) || (rfg
== rfg_vn
)) {
206 vnc_zlog_debug_verbose(
207 "%s: shouldn't happen, returning NULL when un and vn match",
209 return NULL
; /* shouldn't happen */
212 /*------------------------------------------
213 * rfapi_get_rfp_start_val
215 * Returns value passed to rfapi on rfp_start
218 * void * bgp structure
222 *------------------------------------------*/
223 void *rfapi_get_rfp_start_val(void *bgpv
)
225 struct bgp
*bgp
= bgpv
;
226 if (bgp
== NULL
|| bgp
->rfapi
== NULL
)
228 return bgp
->rfapi
->rfp
;
231 /*------------------------------------------
232 * bgp_rfapi_is_vnc_configured
234 * Returns if VNC (BGP VPN messaging /VPN & encap SAFIs) are configured
237 * bgp NULL (=use default instance)
241 * return value: If VNC is configured for the bgpd instance
243 * ENXIO VNC not configured
244 --------------------------------------------*/
245 int bgp_rfapi_is_vnc_configured(struct bgp
*bgp
)
248 bgp
= bgp_get_default();
250 if (bgp
&& bgp
->rfapi_cfg
) {
252 struct peer_group
*group
;
253 struct listnode
*node
, *nnode
;
254 /* if have configured VPN neighbors, assume running VNC */
255 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
256 if (group
->conf
->afc
[AFI_IP
][SAFI_MPLS_VPN
]
257 || group
->conf
->afc
[AFI_IP6
][SAFI_MPLS_VPN
])
260 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
261 if (peer
->afc
[AFI_IP
][SAFI_MPLS_VPN
]
262 || peer
->afc
[AFI_IP6
][SAFI_MPLS_VPN
])
269 /***********************************************************************
270 * VNC Configuration/CLI
271 ***********************************************************************/
274 DEFUN (vnc_advertise_un_method
,
275 vnc_advertise_un_method_cmd
,
276 "vnc advertise-un-method encap-attr",
278 "Method of advertising UN addresses\n"
279 "Via Tunnel Encap attribute (in VPN SAFI)\n")
281 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
283 if (!bgp
->rfapi_cfg
) {
284 vty_out(vty
, "VNC not configured\n");
285 return CMD_WARNING_CONFIG_FAILED
;
289 if (!strncmp(argv
[2]->arg
, "encap-safi", 7)) {
290 bgp
->rfapi_cfg
->flags
|= BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
;
292 bgp
->rfapi_cfg
->flags
&= ~BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
;
298 /*-------------------------------------------------------------------------
300 *-----------------------------------------------------------------------*/
303 DEFUN_NOSH (vnc_defaults
,
305 "vnc defaults", VNC_CONFIG_STR
"Configure default NVE group\n")
307 vty
->node
= BGP_VNC_DEFAULTS_NODE
;
311 static int set_ecom_list(struct vty
*vty
, int argc
, struct cmd_token
**argv
,
312 struct ecommunity
**list
)
314 struct ecommunity
*ecom
= NULL
;
315 struct ecommunity
*ecomadd
;
317 for (; argc
; --argc
, ++argv
) {
319 ecomadd
= ecommunity_str2com(argv
[0]->arg
,
320 ECOMMUNITY_ROUTE_TARGET
, 0);
322 vty_out(vty
, "Malformed community-list value\n");
324 ecommunity_free(&ecom
);
325 return CMD_WARNING_CONFIG_FAILED
;
329 ecommunity_merge(ecom
, ecomadd
);
330 ecommunity_free(&ecomadd
);
337 ecommunity_free(&*list
);
344 DEFUN (vnc_defaults_rt_import
,
345 vnc_defaults_rt_import_cmd
,
346 "rt import RTLIST...",
347 "Specify 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_import_list
);
356 DEFUN (vnc_defaults_rt_export
,
357 vnc_defaults_rt_export_cmd
,
358 "rt export RTLIST...",
359 "Configure default route targets\n"
361 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
363 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
364 return set_ecom_list(vty
, argc
- 2, argv
+ 2,
365 &bgp
->rfapi_cfg
->default_rt_export_list
);
368 DEFUN (vnc_defaults_rt_both
,
369 vnc_defaults_rt_both_cmd
,
371 "Configure default route targets\n"
372 "Export+import filters\n"
373 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
375 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
378 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
379 &bgp
->rfapi_cfg
->default_rt_import_list
);
380 if (rc
!= CMD_SUCCESS
)
382 return set_ecom_list(vty
, argc
- 2, argv
+ 2,
383 &bgp
->rfapi_cfg
->default_rt_export_list
);
386 DEFUN (vnc_defaults_rd
,
388 "rd ASN:nn_or_IP-address:nn",
389 "Specify default route distinguisher\n"
390 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:vn:<number> )\n")
392 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
394 struct prefix_rd prd
;
396 if (!strncmp(argv
[1]->arg
, "auto:vn:", 8)) {
398 * use AF_UNIX to designate automatically-assigned RD
399 * auto:vn:nn where nn is a 2-octet quantity
402 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
403 uint16_t value
= value32
& 0xffff;
405 if (!argv
[1]->arg
[8] || *end
) {
406 vty_out(vty
, "%% Malformed rd\n");
407 return CMD_WARNING_CONFIG_FAILED
;
409 if (value32
> 0xffff) {
410 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
412 return CMD_WARNING_CONFIG_FAILED
;
415 memset(&prd
, 0, sizeof(prd
));
416 prd
.family
= AF_UNIX
;
418 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
419 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
420 prd
.val
[6] = (value
>> 8) & 0x0ff;
421 prd
.val
[7] = value
& 0x0ff;
425 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
427 vty_out(vty
, "%% Malformed rd\n");
428 return CMD_WARNING_CONFIG_FAILED
;
432 bgp
->rfapi_cfg
->default_rd
= prd
;
436 DEFUN (vnc_defaults_l2rd
,
437 vnc_defaults_l2rd_cmd
,
438 "l2rd <(1-255)|auto-vn>",
439 "Specify default Local Nve ID value to use in RD for L2 routes\n"
440 "Fixed value 1-255\n"
441 "use the low-order octet of the NVE's VN address\n")
443 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
446 if (strmatch(argv
[1]->text
, "auto-vn")) {
450 unsigned long value_l
= strtoul(argv
[1]->arg
, &end
, 10);
452 value
= value_l
& 0xff;
453 if (!argv
[1]->arg
[0] || *end
) {
454 vty_out(vty
, "%% Malformed l2 nve ID \"%s\"\n",
456 return CMD_WARNING_CONFIG_FAILED
;
458 if ((value_l
< 1) || (value_l
> 0xff)) {
460 "%% Malformed l2 nve id (must be greater than 0 and less than %u\n",
462 return CMD_WARNING_CONFIG_FAILED
;
465 bgp
->rfapi_cfg
->flags
|= BGP_VNC_CONFIG_L2RD
;
466 bgp
->rfapi_cfg
->default_l2rd
= value
;
471 DEFUN (vnc_defaults_no_l2rd
,
472 vnc_defaults_no_l2rd_cmd
,
475 "Specify default Local Nve ID value to use in RD for L2 routes\n")
477 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
479 bgp
->rfapi_cfg
->default_l2rd
= 0;
480 bgp
->rfapi_cfg
->flags
&= ~BGP_VNC_CONFIG_L2RD
;
485 DEFUN (vnc_defaults_responselifetime
,
486 vnc_defaults_responselifetime_cmd
,
487 "response-lifetime <LIFETIME|infinite>",
488 "Specify default response lifetime\n"
489 "Response lifetime in seconds\n" "Infinite response lifetime\n")
491 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
493 struct rfapi
*h
= NULL
;
494 struct listnode
*hdnode
;
495 struct rfapi_descriptor
*rfd
;
499 return CMD_WARNING_CONFIG_FAILED
;
501 if (strmatch(argv
[1]->text
, "infinite")) {
502 rspint
= RFAPI_INFINITE_LIFETIME
;
504 rspint
= strtoul(argv
[1]->arg
, NULL
, 10);
505 if (rspint
> INT32_MAX
)
507 INT32_MAX
; /* is really an int, not an unsigned
511 bgp
->rfapi_cfg
->default_response_lifetime
= rspint
;
513 for (ALL_LIST_ELEMENTS_RO(&h
->descriptors
, hdnode
, rfd
))
515 && !(rfd
->rfg
->flags
& RFAPI_RFG_RESPONSE_LIFETIME
))
516 rfd
->response_lifetime
= rfd
->rfg
->response_lifetime
=
522 struct rfapi_nve_group_cfg
*
523 bgp_rfapi_cfg_match_byname(struct bgp
*bgp
, const char *name
,
524 rfapi_group_cfg_type_t type
) /* _MAX = any */
526 struct rfapi_nve_group_cfg
*rfg
;
527 struct listnode
*node
, *nnode
;
529 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->nve_groups_sequential
, node
,
531 if ((type
== RFAPI_GROUP_CFG_MAX
|| type
== rfg
->type
)
532 && !strcmp(rfg
->name
, name
))
538 static struct rfapi_nve_group_cfg
*
539 rfapi_group_new(struct bgp
*bgp
, rfapi_group_cfg_type_t type
, const char *name
)
541 struct rfapi_nve_group_cfg
*rfg
;
543 rfg
= XCALLOC(MTYPE_RFAPI_GROUP_CFG
,
544 sizeof(struct rfapi_nve_group_cfg
));
547 rfg
->name
= strdup(name
);
548 /* add to tail of list */
549 listnode_add(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
);
551 rfg
->label
= MPLS_LABEL_ILLEGAL
;
552 QOBJ_REG(rfg
, rfapi_nve_group_cfg
);
557 static struct rfapi_l2_group_cfg
*rfapi_l2_group_lookup_byname(struct bgp
*bgp
,
560 struct rfapi_l2_group_cfg
*rfg
;
561 struct listnode
*node
, *nnode
;
563 if (bgp
->rfapi_cfg
->l2_groups
== NULL
) /* not the best place for this */
564 bgp
->rfapi_cfg
->l2_groups
= list_new();
566 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->l2_groups
, node
, nnode
, rfg
)) {
567 if (!strcmp(rfg
->name
, name
))
573 static struct rfapi_l2_group_cfg
*rfapi_l2_group_new()
575 struct rfapi_l2_group_cfg
*rfg
;
577 rfg
= XCALLOC(MTYPE_RFAPI_L2_CFG
, sizeof(struct rfapi_l2_group_cfg
));
578 QOBJ_REG(rfg
, rfapi_l2_group_cfg
);
583 static void rfapi_l2_group_del(struct rfapi_l2_group_cfg
*rfg
)
586 XFREE(MTYPE_RFAPI_L2_CFG
, rfg
);
589 static int rfapi_str2route_type(const char *l3str
, const char *pstr
, afi_t
*afi
,
595 if (!strcmp(l3str
, "ipv4")) {
598 if (!strcmp(l3str
, "ipv6"))
604 if (!strcmp(pstr
, "connected"))
605 *type
= ZEBRA_ROUTE_CONNECT
;
606 if (!strcmp(pstr
, "kernel"))
607 *type
= ZEBRA_ROUTE_KERNEL
;
608 if (!strcmp(pstr
, "static"))
609 *type
= ZEBRA_ROUTE_STATIC
;
610 if (!strcmp(pstr
, "bgp"))
611 *type
= ZEBRA_ROUTE_BGP
;
612 if (!strcmp(pstr
, "bgp-direct"))
613 *type
= ZEBRA_ROUTE_BGP_DIRECT
;
614 if (!strcmp(pstr
, "bgp-direct-to-nve-groups"))
615 *type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
617 if (!strcmp(pstr
, "rip")) {
619 *type
= ZEBRA_ROUTE_RIP
;
621 *type
= ZEBRA_ROUTE_RIPNG
;
624 if (!strcmp(pstr
, "ripng")) {
627 *type
= ZEBRA_ROUTE_RIPNG
;
630 if (!strcmp(pstr
, "ospf")) {
632 *type
= ZEBRA_ROUTE_OSPF
;
634 *type
= ZEBRA_ROUTE_OSPF6
;
637 if (!strcmp(pstr
, "ospf6")) {
640 *type
= ZEBRA_ROUTE_OSPF6
;
646 /*-------------------------------------------------------------------------
648 *-----------------------------------------------------------------------*/
650 #define VNC_REDIST_ENABLE(bgp, afi, type) \
653 case ZEBRA_ROUTE_BGP_DIRECT: \
654 vnc_import_bgp_redist_enable((bgp), (afi)); \
656 case ZEBRA_ROUTE_BGP_DIRECT_EXT: \
657 vnc_import_bgp_exterior_redist_enable((bgp), (afi)); \
660 vnc_redistribute_set((bgp), (afi), (type)); \
665 #define VNC_REDIST_DISABLE(bgp, afi, type) \
668 case ZEBRA_ROUTE_BGP_DIRECT: \
669 vnc_import_bgp_redist_disable((bgp), (afi)); \
671 case ZEBRA_ROUTE_BGP_DIRECT_EXT: \
672 vnc_import_bgp_exterior_redist_disable((bgp), (afi)); \
675 vnc_redistribute_unset((bgp), (afi), (type)); \
680 static uint8_t redist_was_enabled
[AFI_MAX
][ZEBRA_ROUTE_MAX
];
682 static void vnc_redistribute_prechange(struct bgp
*bgp
)
687 vnc_zlog_debug_verbose("%s: entry", __func__
);
688 memset(redist_was_enabled
, 0, sizeof(redist_was_enabled
));
691 * Look to see if we have any redistribution enabled. If so, flush
692 * the corresponding routes and turn off redistribution temporarily.
693 * We need to do it because the RD's used for the redistributed
694 * routes depend on the nve group.
696 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
697 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
698 if (bgp
->rfapi_cfg
->redist
[afi
][type
]) {
699 redist_was_enabled
[afi
][type
] = 1;
700 VNC_REDIST_DISABLE(bgp
, afi
, type
);
704 vnc_zlog_debug_verbose("%s: return", __func__
);
707 static void vnc_redistribute_postchange(struct bgp
*bgp
)
712 vnc_zlog_debug_verbose("%s: entry", __func__
);
714 * If we turned off redistribution above, turn it back on. Doing so
715 * will tell zebra to resend the routes to us
717 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
718 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
719 if (redist_was_enabled
[afi
][type
]) {
720 VNC_REDIST_ENABLE(bgp
, afi
, type
);
724 vnc_zlog_debug_verbose("%s: return", __func__
);
727 DEFUN (vnc_redistribute_rh_roo_localadmin
,
728 vnc_redistribute_rh_roo_localadmin_cmd
,
729 "vnc redistribute resolve-nve roo-ec-local-admin (0-65535)",
731 "Redistribute routes into VNC\n"
733 "Route Origin Extended Community Local Admin Field\n" "Field value\n")
735 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
739 if (!bgp
->rfapi_cfg
) {
740 vty_out(vty
, "RFAPI not configured\n");
741 return CMD_WARNING_CONFIG_FAILED
;
744 localadmin
= strtoul(argv
[4]->arg
, &endptr
, 0);
745 if (!argv
[4]->arg
[0] || *endptr
) {
746 vty_out(vty
, "%% Malformed value\n");
747 return CMD_WARNING_CONFIG_FAILED
;
750 if (localadmin
> 0xffff) {
751 vty_out(vty
, "%% Value out of range (0-%d)\n", 0xffff);
752 return CMD_WARNING_CONFIG_FAILED
;
755 if (bgp
->rfapi_cfg
->resolve_nve_roo_local_admin
== localadmin
)
758 if ((bgp
->rfapi_cfg
->flags
& BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
)
759 == BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE
) {
761 vnc_export_bgp_prechange(bgp
);
763 vnc_redistribute_prechange(bgp
);
765 bgp
->rfapi_cfg
->resolve_nve_roo_local_admin
= localadmin
;
767 if ((bgp
->rfapi_cfg
->flags
& BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
)
768 == BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE
) {
770 vnc_export_bgp_postchange(bgp
);
772 vnc_redistribute_postchange(bgp
);
778 DEFUN (vnc_redistribute_mode
,
779 vnc_redistribute_mode_cmd
,
780 "vnc redistribute mode <nve-group|plain|resolve-nve>",
782 "Redistribute routes into VNC\n"
783 "Redistribution mode\n"
784 "Based on redistribute nve-group\n"
785 "Unmodified\n" "Resolve each nexthop to connected NVEs\n")
787 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
788 vnc_redist_mode_t newmode
;
790 if (!bgp
->rfapi_cfg
) {
791 vty_out(vty
, "RFAPI not configured\n");
792 return CMD_WARNING_CONFIG_FAILED
;
796 switch (argv
[3]->arg
[0]) {
798 newmode
= VNC_REDIST_MODE_RFG
;
802 newmode
= VNC_REDIST_MODE_PLAIN
;
806 newmode
= VNC_REDIST_MODE_RESOLVE_NVE
;
810 vty_out(vty
, "unknown redistribute mode\n");
811 return CMD_WARNING_CONFIG_FAILED
;
814 if (newmode
!= bgp
->rfapi_cfg
->redist_mode
) {
815 vnc_redistribute_prechange(bgp
);
816 bgp
->rfapi_cfg
->redist_mode
= newmode
;
817 vnc_redistribute_postchange(bgp
);
823 DEFUN (vnc_redistribute_protocol
,
824 vnc_redistribute_protocol_cmd
,
825 "vnc redistribute <ipv4|ipv6> <bgp|bgp-direct|bgp-direct-to-nve-groups|connected|kernel|ospf|rip|static>",
827 "Redistribute routes into VNC\n"
831 "From BGP without Zebra\n"
832 "From BGP without Zebra, only to configured NVE groups\n"
833 "Connected interfaces\n"
834 "From kernel routes\n"
835 "From Open Shortest Path First (OSPF)\n"
836 "From Routing Information Protocol (RIP)\n" "From Static routes\n")
838 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
839 int type
= ZEBRA_ROUTE_MAX
; /* init to bogus value */
842 if (!bgp
->rfapi_cfg
) {
843 vty_out(vty
, "RFAPI not configured\n");
844 return CMD_WARNING_CONFIG_FAILED
;
847 if (rfapi_str2route_type(argv
[2]->arg
, argv
[3]->arg
, &afi
, &type
)) {
848 vty_out(vty
, "%% Invalid route type\n");
849 return CMD_WARNING_CONFIG_FAILED
;
852 if (type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
) {
853 if (bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
) {
854 VNC_REDIST_DISABLE(bgp
, afi
,
855 type
); /* disabled view implicitly */
856 free(bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
);
857 bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
= NULL
;
859 bgp
->rfapi_cfg
->redist_bgp_exterior_view
= bgp
;
862 VNC_REDIST_ENABLE(bgp
, afi
, type
);
867 DEFUN (vnc_no_redistribute_protocol
,
868 vnc_no_redistribute_protocol_cmd
,
869 "no vnc redistribute <ipv4|ipv6> <bgp|bgp-direct|bgp-direct-to-nve-groups|connected|kernel|ospf|rip|static>",
872 "Redistribute from other protocol\n"
876 "From BGP without Zebra\n"
877 "From BGP without Zebra, only to configured NVE groups\n"
878 "Connected interfaces\n"
879 "From kernel routes\n"
880 "From Open Shortest Path First (OSPF)\n"
881 "From Routing Information Protocol (RIP)\n" "From Static routes\n")
883 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
887 if (!bgp
->rfapi_cfg
) {
888 vty_out(vty
, "RFAPI not configured\n");
889 return CMD_WARNING_CONFIG_FAILED
;
892 if (rfapi_str2route_type(argv
[3]->arg
, argv
[4]->arg
, &afi
, &type
)) {
893 vty_out(vty
, "%% Invalid route type\n");
894 return CMD_WARNING_CONFIG_FAILED
;
897 VNC_REDIST_DISABLE(bgp
, afi
, type
);
899 if (type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
) {
900 if (bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
) {
901 free(bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
);
902 bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
= NULL
;
904 bgp
->rfapi_cfg
->redist_bgp_exterior_view
= NULL
;
910 DEFUN (vnc_redistribute_bgp_exterior
,
911 vnc_redistribute_bgp_exterior_cmd
,
912 "vnc redistribute <ipv4|ipv6> bgp-direct-to-nve-groups view NAME",
914 "Redistribute routes into VNC\n"
917 "From BGP without Zebra, only to configured NVE groups\n"
918 "From BGP view\n" "BGP view name\n")
920 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
924 if (!bgp
->rfapi_cfg
) {
925 vty_out(vty
, "RFAPI not configured\n");
926 return CMD_WARNING_CONFIG_FAILED
;
929 if (rfapi_str2route_type(argv
[2]->arg
, "bgp-direct-to-nve-groups", &afi
,
931 vty_out(vty
, "%% Invalid route type\n");
932 return CMD_WARNING_CONFIG_FAILED
;
935 if (bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
)
936 free(bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
);
937 bgp
->rfapi_cfg
->redist_bgp_exterior_view_name
= strdup(argv
[5]->arg
);
938 /* could be NULL if name is not defined yet */
939 bgp
->rfapi_cfg
->redist_bgp_exterior_view
=
940 bgp_lookup_by_name(argv
[5]->arg
);
942 VNC_REDIST_ENABLE(bgp
, afi
, type
);
947 DEFUN (vnc_redistribute_nvegroup
,
948 vnc_redistribute_nvegroup_cmd
,
949 "vnc redistribute nve-group NAME",
951 "Assign a NVE group to routes redistributed from another routing protocol\n"
952 "NVE group\n" "Group name\n")
954 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
956 if (!bgp
->rfapi_cfg
) {
957 vty_out(vty
, "rfapi not configured\n");
958 return CMD_WARNING_CONFIG_FAILED
;
961 vnc_redistribute_prechange(bgp
);
964 * OK if nve group doesn't exist yet; we'll set the pointer
965 * when the group is defined later
967 bgp
->rfapi_cfg
->rfg_redist
= bgp_rfapi_cfg_match_byname(
968 bgp
, argv
[3]->arg
, RFAPI_GROUP_CFG_NVE
);
969 if (bgp
->rfapi_cfg
->rfg_redist_name
)
970 free(bgp
->rfapi_cfg
->rfg_redist_name
);
971 bgp
->rfapi_cfg
->rfg_redist_name
= strdup(argv
[3]->arg
);
973 vnc_redistribute_postchange(bgp
);
978 DEFUN (vnc_redistribute_no_nvegroup
,
979 vnc_redistribute_no_nvegroup_cmd
,
980 "no vnc redistribute nve-group",
983 "Redistribute from other protocol\n"
984 "Assign a NVE group to routes redistributed from another routing protocol\n")
986 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
988 if (!bgp
->rfapi_cfg
) {
989 vty_out(vty
, "rfapi not configured\n");
990 return CMD_WARNING_CONFIG_FAILED
;
993 vnc_redistribute_prechange(bgp
);
995 bgp
->rfapi_cfg
->rfg_redist
= NULL
;
996 if (bgp
->rfapi_cfg
->rfg_redist_name
)
997 free(bgp
->rfapi_cfg
->rfg_redist_name
);
998 bgp
->rfapi_cfg
->rfg_redist_name
= NULL
;
1000 vnc_redistribute_postchange(bgp
);
1006 DEFUN (vnc_redistribute_lifetime
,
1007 vnc_redistribute_lifetime_cmd
,
1008 "vnc redistribute lifetime <LIFETIME|infinite>",
1011 "Assign a lifetime to routes redistributed from another routing protocol\n"
1012 "lifetime value (32 bit)\n"
1013 "Allow lifetime to never expire\n")
1015 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1017 if (!bgp
->rfapi_cfg
) {
1018 vty_out(vty
, "rfapi not configured\n");
1019 return CMD_WARNING_CONFIG_FAILED
;
1022 vnc_redistribute_prechange(bgp
);
1024 if (strmatch(argv
[3]->text
, "infinite")) {
1025 bgp
->rfapi_cfg
->redist_lifetime
= RFAPI_INFINITE_LIFETIME
;
1027 bgp
->rfapi_cfg
->redist_lifetime
=
1028 strtoul(argv
[3]->arg
, NULL
, 10);
1031 vnc_redistribute_postchange(bgp
);
1036 /*-- redist policy, non-nvegroup start --*/
1038 DEFUN (vnc_redist_bgpdirect_no_prefixlist
,
1039 vnc_redist_bgpdirect_no_prefixlist_cmd
,
1040 "no vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> <ipv4|ipv6> prefix-list",
1043 "Redistribute from other protocol\n"
1044 "Redistribute from BGP directly\n"
1045 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1047 "IPv6 routes\n" "Prefix-list for filtering redistributed routes\n")
1049 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1051 struct rfapi_cfg
*hc
;
1052 uint8_t route_type
= 0;
1054 if (!(hc
= bgp
->rfapi_cfg
)) {
1055 vty_out(vty
, "rfapi not configured\n");
1056 return CMD_WARNING_CONFIG_FAILED
;
1059 if (strmatch(argv
[3]->text
, "bgp-direct")) {
1060 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1062 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1065 if (strmatch(argv
[4]->text
, "ipv4")) {
1071 vnc_redistribute_prechange(bgp
);
1073 if (hc
->plist_redist_name
[route_type
][afi
])
1074 free(hc
->plist_redist_name
[route_type
][afi
]);
1075 hc
->plist_redist_name
[route_type
][afi
] = NULL
;
1076 hc
->plist_redist
[route_type
][afi
] = NULL
;
1078 vnc_redistribute_postchange(bgp
);
1083 DEFUN (vnc_redist_bgpdirect_prefixlist
,
1084 vnc_redist_bgpdirect_prefixlist_cmd
,
1085 "vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> <ipv4|ipv6> prefix-list NAME",
1087 "Redistribute from other protocol\n"
1088 "Redistribute from BGP directly\n"
1089 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1092 "Prefix-list for filtering redistributed routes\n"
1093 "prefix list name\n")
1095 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1096 struct rfapi_cfg
*hc
;
1098 uint8_t route_type
= 0;
1100 if (!(hc
= bgp
->rfapi_cfg
)) {
1101 vty_out(vty
, "rfapi not configured\n");
1102 return CMD_WARNING_CONFIG_FAILED
;
1105 if (strmatch(argv
[2]->text
, "bgp-direct")) {
1106 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1108 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1111 if (strmatch(argv
[3]->text
, "ipv4")) {
1117 vnc_redistribute_prechange(bgp
);
1119 if (hc
->plist_redist_name
[route_type
][afi
])
1120 free(hc
->plist_redist_name
[route_type
][afi
]);
1121 hc
->plist_redist_name
[route_type
][afi
] = strdup(argv
[5]->arg
);
1122 hc
->plist_redist
[route_type
][afi
] =
1123 prefix_list_lookup(afi
, argv
[5]->arg
);
1125 vnc_redistribute_postchange(bgp
);
1130 DEFUN (vnc_redist_bgpdirect_no_routemap
,
1131 vnc_redist_bgpdirect_no_routemap_cmd
,
1132 "no vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> route-map",
1135 "Redistribute from other protocols\n"
1136 "Redistribute from BGP directly\n"
1137 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1138 "Route-map for filtering redistributed routes\n")
1140 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1141 struct rfapi_cfg
*hc
;
1142 uint8_t route_type
= 0;
1144 if (!(hc
= bgp
->rfapi_cfg
)) {
1145 vty_out(vty
, "rfapi not configured\n");
1146 return CMD_WARNING_CONFIG_FAILED
;
1149 if (strmatch(argv
[3]->text
, "bgp-direct")) {
1150 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1152 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1155 vnc_redistribute_prechange(bgp
);
1157 if (hc
->routemap_redist_name
[route_type
])
1158 free(hc
->routemap_redist_name
[route_type
]);
1159 hc
->routemap_redist_name
[route_type
] = NULL
;
1160 hc
->routemap_redist
[route_type
] = NULL
;
1162 vnc_redistribute_postchange(bgp
);
1167 DEFUN (vnc_redist_bgpdirect_routemap
,
1168 vnc_redist_bgpdirect_routemap_cmd
,
1169 "vnc redistribute <bgp-direct|bgp-direct-to-nve-groups> route-map NAME",
1171 "Redistribute from other protocols\n"
1172 "Redistribute from BGP directly\n"
1173 "Redistribute from BGP without Zebra, only to configured NVE groups\n"
1174 "Route-map for filtering exported routes\n" "route map name\n")
1176 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1177 struct rfapi_cfg
*hc
;
1178 uint8_t route_type
= 0;
1180 if (!(hc
= bgp
->rfapi_cfg
)) {
1181 vty_out(vty
, "rfapi not configured\n");
1182 return CMD_WARNING_CONFIG_FAILED
;
1185 if (strmatch(argv
[2]->text
, "bgp-direct")) {
1186 route_type
= ZEBRA_ROUTE_BGP_DIRECT
;
1188 route_type
= ZEBRA_ROUTE_BGP_DIRECT_EXT
;
1191 vnc_redistribute_prechange(bgp
);
1193 if (hc
->routemap_redist_name
[route_type
])
1194 free(hc
->routemap_redist_name
[route_type
]);
1195 hc
->routemap_redist_name
[route_type
] = strdup(argv
[4]->arg
);
1196 hc
->routemap_redist
[route_type
] =
1197 route_map_lookup_by_name(argv
[4]->arg
);
1199 vnc_redistribute_postchange(bgp
);
1204 /*-- redist policy, non-nvegroup end --*/
1206 /*-- redist policy, nvegroup start --*/
1208 DEFUN (vnc_nve_group_redist_bgpdirect_no_prefixlist
,
1209 vnc_nve_group_redist_bgpdirect_no_prefixlist_cmd
,
1210 "no redistribute bgp-direct <ipv4|ipv6> prefix-list",
1212 "Redistribute from other protocol\n"
1213 "Redistribute from BGP directly\n"
1216 "Prefix-list for filtering redistributed routes\n")
1218 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1219 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
)
1222 if (!bgp
->rfapi_cfg
) {
1223 vty_out(vty
, "rfapi not configured\n");
1224 return CMD_WARNING_CONFIG_FAILED
;
1227 /* make sure it's still in list */
1228 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1229 /* Not in list anymore */
1230 vty_out(vty
, "Current NVE group no longer exists\n");
1231 return CMD_WARNING_CONFIG_FAILED
;
1234 if (strmatch(argv
[3]->text
, "ipv4")) {
1240 vnc_redistribute_prechange(bgp
);
1242 if (rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
])
1243 free(rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
]);
1244 rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] = NULL
;
1245 rfg
->plist_redist
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] = NULL
;
1247 vnc_redistribute_postchange(bgp
);
1252 DEFUN (vnc_nve_group_redist_bgpdirect_prefixlist
,
1253 vnc_nve_group_redist_bgpdirect_prefixlist_cmd
,
1254 "redistribute bgp-direct <ipv4|ipv6> prefix-list NAME",
1255 "Redistribute from other protocol\n"
1256 "Redistribute from BGP directly\n"
1259 "Prefix-list for filtering redistributed routes\n"
1260 "prefix list name\n")
1262 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1263 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1266 if (!bgp
->rfapi_cfg
) {
1267 vty_out(vty
, "rfapi not configured\n");
1268 return CMD_WARNING_CONFIG_FAILED
;
1271 /* make sure it's still in list */
1272 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1273 /* Not in list anymore */
1274 vty_out(vty
, "Current NVE group no longer exists\n");
1275 return CMD_WARNING_CONFIG_FAILED
;
1278 if (strmatch(argv
[2]->text
, "ipv4")) {
1284 vnc_redistribute_prechange(bgp
);
1286 if (rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
])
1287 free(rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
]);
1288 rfg
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] =
1289 strdup(argv
[4]->arg
);
1290 rfg
->plist_redist
[ZEBRA_ROUTE_BGP_DIRECT
][afi
] =
1291 prefix_list_lookup(afi
, argv
[4]->arg
);
1293 vnc_redistribute_postchange(bgp
);
1298 DEFUN (vnc_nve_group_redist_bgpdirect_no_routemap
,
1299 vnc_nve_group_redist_bgpdirect_no_routemap_cmd
,
1300 "no redistribute bgp-direct route-map",
1302 "Redistribute from other protocols\n"
1303 "Redistribute from BGP directly\n"
1304 "Route-map for filtering redistributed routes\n")
1306 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1307 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1309 if (!bgp
->rfapi_cfg
) {
1310 vty_out(vty
, "rfapi not configured\n");
1311 return CMD_WARNING_CONFIG_FAILED
;
1314 /* make sure it's still in list */
1315 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1316 /* Not in list anymore */
1317 vty_out(vty
, "Current NVE group no longer exists\n");
1318 return CMD_WARNING_CONFIG_FAILED
;
1321 vnc_redistribute_prechange(bgp
);
1323 if (rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
])
1324 free(rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]);
1325 rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
] = NULL
;
1326 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
] = NULL
;
1328 vnc_redistribute_postchange(bgp
);
1333 DEFUN (vnc_nve_group_redist_bgpdirect_routemap
,
1334 vnc_nve_group_redist_bgpdirect_routemap_cmd
,
1335 "redistribute bgp-direct route-map NAME",
1336 "Redistribute from other protocols\n"
1337 "Redistribute from BGP directly\n"
1338 "Route-map for filtering exported routes\n" "route map name\n")
1340 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1341 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1343 if (!bgp
->rfapi_cfg
) {
1344 vty_out(vty
, "rfapi not configured\n");
1345 return CMD_WARNING_CONFIG_FAILED
;
1348 /* make sure it's still in list */
1349 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1350 /* Not in list anymore */
1351 vty_out(vty
, "Current NVE group no longer exists\n");
1352 return CMD_WARNING_CONFIG_FAILED
;
1355 vnc_redistribute_prechange(bgp
);
1357 if (rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
])
1358 free(rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]);
1359 rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
] =
1360 strdup(argv
[3]->arg
);
1361 rfg
->routemap_redist
[ZEBRA_ROUTE_BGP_DIRECT
] =
1362 route_map_lookup_by_name(argv
[3]->arg
);
1364 vnc_redistribute_postchange(bgp
);
1369 /*-- redist policy, nvegroup end --*/
1371 /*-------------------------------------------------------------------------
1373 *-----------------------------------------------------------------------*/
1375 DEFUN (vnc_export_mode
,
1376 vnc_export_mode_cmd
,
1377 "vnc export <bgp|zebra> mode <group-nve|ce|none|registering-nve>",
1379 "Export to other protocols\n"
1381 "Export to Zebra (experimental)\n"
1382 "Select export mode\n"
1383 "Export routes with nve-group next-hops\n"
1384 "Export routes with NVE connected router next-hops\n"
1385 "Disable export\n" "Export routes with registering NVE as next-hop\n")
1387 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1388 uint32_t oldmode
= 0;
1389 uint32_t newmode
= 0;
1391 if (!bgp
->rfapi_cfg
) {
1392 vty_out(vty
, "VNC not configured\n");
1393 return CMD_WARNING_CONFIG_FAILED
;
1396 if (argv
[2]->arg
[0] == 'b') {
1397 oldmode
= bgp
->rfapi_cfg
->flags
1398 & BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
;
1399 switch (argv
[4]->arg
[0]) {
1401 newmode
= BGP_VNC_CONFIG_EXPORT_BGP_MODE_GRP
;
1404 newmode
= BGP_VNC_CONFIG_EXPORT_BGP_MODE_CE
;
1410 newmode
= BGP_VNC_CONFIG_EXPORT_BGP_MODE_RH
;
1413 vty_out(vty
, "Invalid mode specified\n");
1414 return CMD_WARNING_CONFIG_FAILED
;
1417 if (newmode
== oldmode
) {
1418 vty_out(vty
, "Mode unchanged\n");
1422 vnc_export_bgp_prechange(bgp
);
1424 bgp
->rfapi_cfg
->flags
&= ~BGP_VNC_CONFIG_EXPORT_BGP_MODE_BITS
;
1425 bgp
->rfapi_cfg
->flags
|= newmode
;
1427 vnc_export_bgp_postchange(bgp
);
1432 * export to zebra with RH mode is not yet implemented
1435 "Changing modes for zebra export not implemented yet\n");
1436 return CMD_WARNING_CONFIG_FAILED
;
1438 oldmode
= bgp
->rfapi_cfg
->flags
1439 & BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_BITS
;
1440 bgp
->rfapi_cfg
->flags
&= ~BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_BITS
;
1441 switch (argv
[4]->arg
[0]) {
1443 if (oldmode
== BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_RH
) {
1446 bgp
->rfapi_cfg
->flags
|=
1447 BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_GRP
;
1448 if (oldmode
!= BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_GRP
) {
1453 if (oldmode
== BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_RH
) {
1456 if (oldmode
== BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_GRP
) {
1461 if (oldmode
== BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_GRP
) {
1464 bgp
->rfapi_cfg
->flags
|=
1465 BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_RH
;
1466 if (oldmode
!= BGP_VNC_CONFIG_EXPORT_ZEBRA_MODE_RH
) {
1471 vty_out(vty
, "Invalid mode\n");
1472 return CMD_WARNING_CONFIG_FAILED
;
1479 static struct rfapi_rfg_name
*rfgn_new()
1481 return XCALLOC(MTYPE_RFAPI_RFG_NAME
, sizeof(struct rfapi_rfg_name
));
1484 static void rfgn_free(struct rfapi_rfg_name
*rfgn
)
1486 XFREE(MTYPE_RFAPI_RFG_NAME
, rfgn
);
1489 DEFUN (vnc_export_nvegroup
,
1490 vnc_export_nvegroup_cmd
,
1491 "vnc export <bgp|zebra> group-nve group NAME",
1493 "Export to other protocols\n"
1495 "Export to Zebra (experimental)\n"
1496 "NVE group, used in 'group-nve' export mode\n"
1497 "NVE group\n" "Group name\n")
1499 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1500 struct rfapi_nve_group_cfg
*rfg_new
;
1502 if (!bgp
->rfapi_cfg
) {
1503 vty_out(vty
, "rfapi not configured\n");
1504 return CMD_WARNING_CONFIG_FAILED
;
1507 rfg_new
= bgp_rfapi_cfg_match_byname(bgp
, argv
[5]->arg
,
1508 RFAPI_GROUP_CFG_NVE
);
1510 if (argv
[2]->arg
[0] == 'b') {
1512 struct listnode
*node
;
1513 struct rfapi_rfg_name
*rfgn
;
1516 * Set group for export to BGP Direct
1519 /* see if group is already included in export list */
1520 for (ALL_LIST_ELEMENTS_RO(
1521 bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
1524 if (!strcmp(rfgn
->name
, argv
[5]->arg
)) {
1525 /* already in the list: we're done */
1531 rfgn
->name
= strdup(argv
[5]->arg
);
1532 rfgn
->rfg
= rfg_new
; /* OK if not set yet */
1534 listnode_add(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, rfgn
);
1536 vnc_zlog_debug_verbose("%s: testing rfg_new", __func__
);
1538 vnc_zlog_debug_verbose(
1539 "%s: testing bgp grp mode enabled", __func__
);
1540 if (VNC_EXPORT_BGP_GRP_ENABLED(bgp
->rfapi_cfg
))
1541 vnc_zlog_debug_verbose(
1542 "%s: calling vnc_direct_bgp_add_group",
1544 vnc_direct_bgp_add_group(bgp
, rfg_new
);
1549 struct listnode
*node
;
1550 struct rfapi_rfg_name
*rfgn
;
1553 * Set group for export to Zebra
1556 /* see if group is already included in export list */
1557 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
,
1560 if (!strcmp(rfgn
->name
, argv
[5]->arg
)) {
1561 /* already in the list: we're done */
1567 rfgn
->name
= strdup(argv
[5]->arg
);
1568 rfgn
->rfg
= rfg_new
; /* OK if not set yet */
1570 listnode_add(bgp
->rfapi_cfg
->rfg_export_zebra_l
, rfgn
);
1573 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(bgp
->rfapi_cfg
))
1574 vnc_zebra_add_group(bgp
, rfg_new
);
1582 * This command applies to routes exported from VNC to BGP directly
1583 * without going though zebra
1585 DEFUN (vnc_no_export_nvegroup
,
1586 vnc_no_export_nvegroup_cmd
,
1587 "vnc export <bgp|zebra> group-nve no group NAME",
1589 "Export to other protocols\n"
1591 "Export to Zebra (experimental)\n"
1592 "NVE group, used in 'group-nve' export mode\n"
1593 "Disable export of VNC routes\n" "NVE group\n" "Group name\n")
1595 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1596 struct listnode
*node
, *nnode
;
1597 struct rfapi_rfg_name
*rfgn
;
1599 if (!bgp
->rfapi_cfg
) {
1600 vty_out(vty
, "rfapi not configured\n");
1601 return CMD_WARNING_CONFIG_FAILED
;
1604 if (argv
[2]->arg
[0] == 'b') {
1605 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
,
1606 node
, nnode
, rfgn
)) {
1608 if (rfgn
->name
&& !strcmp(rfgn
->name
, argv
[6]->arg
)) {
1609 vnc_zlog_debug_verbose("%s: matched \"%s\"",
1610 __func__
, rfgn
->name
);
1612 vnc_direct_bgp_del_group(bgp
,
1616 bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
,
1623 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
1626 vnc_zlog_debug_verbose("does rfg \"%s\" match?",
1628 if (rfgn
->name
&& !strcmp(rfgn
->name
, argv
[6]->arg
)) {
1630 vnc_zebra_del_group(bgp
, rfgn
->rfg
);
1633 bgp
->rfapi_cfg
->rfg_export_zebra_l
,
1643 DEFUN (vnc_nve_group_export_no_prefixlist
,
1644 vnc_nve_group_export_no_prefixlist_cmd
,
1645 "no export <bgp|zebra> <ipv4|ipv6> prefix-list [NAME]",
1647 "Export to other protocols\n"
1649 "Export to Zebra (experimental)\n"
1652 "Prefix-list for filtering exported routes\n" "prefix list name\n")
1654 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1655 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1658 if (!bgp
->rfapi_cfg
) {
1659 vty_out(vty
, "rfapi not configured\n");
1660 return CMD_WARNING_CONFIG_FAILED
;
1663 /* make sure it's still in list */
1664 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1665 /* Not in list anymore */
1666 vty_out(vty
, "Current NVE group no longer exists\n");
1667 return CMD_WARNING_CONFIG_FAILED
;
1670 if (strmatch(argv
[3]->text
, "ipv4")) {
1676 if (argv
[2]->arg
[0] == 'b') {
1677 if (((argc
> 5) && strmatch(argv
[5]->text
,
1678 rfg
->plist_export_bgp_name
[afi
]))
1681 if (rfg
->plist_export_bgp_name
[afi
])
1682 free(rfg
->plist_export_bgp_name
[afi
]);
1683 rfg
->plist_export_bgp_name
[afi
] = NULL
;
1684 rfg
->plist_export_bgp
[afi
] = NULL
;
1686 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, afi
);
1689 if (((argc
> 5) && strmatch(argv
[5]->text
,
1690 rfg
->plist_export_zebra_name
[afi
]))
1692 if (rfg
->plist_export_zebra_name
[afi
])
1693 free(rfg
->plist_export_zebra_name
[afi
]);
1694 rfg
->plist_export_zebra_name
[afi
] = NULL
;
1695 rfg
->plist_export_zebra
[afi
] = NULL
;
1697 vnc_zebra_reexport_group_afi(bgp
, rfg
, afi
);
1703 DEFUN (vnc_nve_group_export_prefixlist
,
1704 vnc_nve_group_export_prefixlist_cmd
,
1705 "export <bgp|zebra> <ipv4|ipv6> prefix-list NAME",
1706 "Export to other protocols\n"
1708 "Export to Zebra (experimental)\n"
1711 "Prefix-list for filtering exported routes\n" "prefix list name\n")
1713 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1714 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1717 if (!bgp
->rfapi_cfg
) {
1718 vty_out(vty
, "rfapi not configured\n");
1719 return CMD_WARNING_CONFIG_FAILED
;
1722 /* make sure it's still in list */
1723 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1724 /* Not in list anymore */
1725 vty_out(vty
, "Current NVE group no longer exists\n");
1726 return CMD_WARNING_CONFIG_FAILED
;
1729 if (strmatch(argv
[2]->text
, "ipv4")) {
1735 if (argv
[1]->arg
[0] == 'b') {
1736 if (rfg
->plist_export_bgp_name
[afi
])
1737 free(rfg
->plist_export_bgp_name
[afi
]);
1738 rfg
->plist_export_bgp_name
[afi
] = strdup(argv
[4]->arg
);
1739 rfg
->plist_export_bgp
[afi
] =
1740 prefix_list_lookup(afi
, argv
[4]->arg
);
1742 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, afi
);
1745 if (rfg
->plist_export_zebra_name
[afi
])
1746 free(rfg
->plist_export_zebra_name
[afi
]);
1747 rfg
->plist_export_zebra_name
[afi
] = strdup(argv
[4]->arg
);
1748 rfg
->plist_export_zebra
[afi
] =
1749 prefix_list_lookup(afi
, argv
[4]->arg
);
1751 vnc_zebra_reexport_group_afi(bgp
, rfg
, afi
);
1756 DEFUN (vnc_nve_group_export_no_routemap
,
1757 vnc_nve_group_export_no_routemap_cmd
,
1758 "no export <bgp|zebra> route-map [NAME]",
1760 "Export to other protocols\n"
1762 "Export to Zebra (experimental)\n"
1763 "Route-map for filtering exported routes\n" "route map name\n")
1765 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1766 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1768 if (!bgp
->rfapi_cfg
) {
1769 vty_out(vty
, "rfapi not configured\n");
1770 return CMD_WARNING_CONFIG_FAILED
;
1773 /* make sure it's still in list */
1774 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1775 /* Not in list anymore */
1776 vty_out(vty
, "Current NVE group no longer exists\n");
1777 return CMD_WARNING_CONFIG_FAILED
;
1780 if (argv
[2]->arg
[0] == 'b') {
1782 && strmatch(argv
[4]->text
, rfg
->routemap_export_bgp_name
))
1785 if (rfg
->routemap_export_bgp_name
)
1786 free(rfg
->routemap_export_bgp_name
);
1787 rfg
->routemap_export_bgp_name
= NULL
;
1788 rfg
->routemap_export_bgp
= NULL
;
1790 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1791 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1794 if (((argc
> 4) && strmatch(argv
[4]->text
,
1795 rfg
->routemap_export_zebra_name
))
1797 if (rfg
->routemap_export_zebra_name
)
1798 free(rfg
->routemap_export_zebra_name
);
1799 rfg
->routemap_export_zebra_name
= NULL
;
1800 rfg
->routemap_export_zebra
= NULL
;
1802 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1803 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1809 DEFUN (vnc_nve_group_export_routemap
,
1810 vnc_nve_group_export_routemap_cmd
,
1811 "export <bgp|zebra> route-map NAME",
1812 "Export to other protocols\n"
1814 "Export to Zebra (experimental)\n"
1815 "Route-map for filtering exported routes\n" "route map name\n")
1817 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1818 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
1820 if (!bgp
->rfapi_cfg
) {
1821 vty_out(vty
, "rfapi not configured\n");
1822 return CMD_WARNING_CONFIG_FAILED
;
1825 /* make sure it's still in list */
1826 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
1827 /* Not in list anymore */
1828 vty_out(vty
, "Current NVE group no longer exists\n");
1829 return CMD_WARNING_CONFIG_FAILED
;
1832 if (argv
[1]->arg
[0] == 'b') {
1833 if (rfg
->routemap_export_bgp_name
)
1834 free(rfg
->routemap_export_bgp_name
);
1835 rfg
->routemap_export_bgp_name
= strdup(argv
[3]->arg
);
1836 rfg
->routemap_export_bgp
=
1837 route_map_lookup_by_name(argv
[3]->arg
);
1838 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1839 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1841 if (rfg
->routemap_export_zebra_name
)
1842 free(rfg
->routemap_export_zebra_name
);
1843 rfg
->routemap_export_zebra_name
= strdup(argv
[3]->arg
);
1844 rfg
->routemap_export_zebra
=
1845 route_map_lookup_by_name(argv
[3]->arg
);
1846 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP
);
1847 vnc_zebra_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
1852 DEFUN (vnc_nve_export_no_prefixlist
,
1853 vnc_nve_export_no_prefixlist_cmd
,
1854 "no vnc export <bgp|zebra> <ipv4|ipv6> prefix-list [NAME]",
1857 "Export to other protocols\n"
1859 "Export to Zebra (experimental)\n"
1862 "Prefix-list for filtering exported routes\n" "Prefix list name\n")
1864 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1865 struct rfapi_cfg
*hc
;
1868 if (!(hc
= bgp
->rfapi_cfg
)) {
1869 vty_out(vty
, "rfapi not configured\n");
1870 return CMD_WARNING_CONFIG_FAILED
;
1873 if (strmatch(argv
[4]->text
, "ipv4")) {
1879 if (argv
[3]->arg
[0] == 'b') {
1880 if (((argc
> 6) && hc
->plist_export_bgp_name
[afi
]
1881 && strmatch(argv
[6]->text
, hc
->plist_export_bgp_name
[afi
]))
1884 free(hc
->plist_export_bgp_name
[afi
]);
1885 hc
->plist_export_bgp_name
[afi
] = NULL
;
1886 hc
->plist_export_bgp
[afi
] = NULL
;
1887 vnc_direct_bgp_reexport(bgp
, afi
);
1890 if (((argc
> 6) && hc
->plist_export_zebra_name
[afi
]
1891 && strmatch(argv
[6]->text
,
1892 hc
->plist_export_zebra_name
[afi
]))
1895 free(hc
->plist_export_zebra_name
[afi
]);
1896 hc
->plist_export_zebra_name
[afi
] = NULL
;
1897 hc
->plist_export_zebra
[afi
] = NULL
;
1898 /* TBD vnc_zebra_rh_reexport(bgp, afi); */
1904 DEFUN (vnc_nve_export_prefixlist
,
1905 vnc_nve_export_prefixlist_cmd
,
1906 "vnc export <bgp|zebra> <ipv4|ipv6> prefix-list NAME",
1908 "Export to other protocols\n"
1910 "Export to Zebra (experimental)\n"
1913 "Prefix-list for filtering exported routes\n" "Prefix list name\n")
1915 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1916 struct rfapi_cfg
*hc
;
1919 if (!(hc
= bgp
->rfapi_cfg
)) {
1920 vty_out(vty
, "rfapi not configured\n");
1921 return CMD_WARNING_CONFIG_FAILED
;
1924 if (strmatch(argv
[3]->text
, "ipv4")) {
1930 if (argv
[2]->arg
[0] == 'b') {
1931 if (hc
->plist_export_bgp_name
[afi
])
1932 free(hc
->plist_export_bgp_name
[afi
]);
1933 hc
->plist_export_bgp_name
[afi
] = strdup(argv
[5]->arg
);
1934 hc
->plist_export_bgp
[afi
] =
1935 prefix_list_lookup(afi
, argv
[5]->arg
);
1936 vnc_direct_bgp_reexport(bgp
, afi
);
1938 if (hc
->plist_export_zebra_name
[afi
])
1939 free(hc
->plist_export_zebra_name
[afi
]);
1940 hc
->plist_export_zebra_name
[afi
] = strdup(argv
[5]->arg
);
1941 hc
->plist_export_zebra
[afi
] =
1942 prefix_list_lookup(afi
, argv
[5]->arg
);
1943 /* TBD vnc_zebra_rh_reexport(bgp, afi); */
1948 DEFUN (vnc_nve_export_no_routemap
,
1949 vnc_nve_export_no_routemap_cmd
,
1950 "no vnc export <bgp|zebra> route-map [NAME]",
1953 "Export to other protocols\n"
1955 "Export to Zebra (experimental)\n"
1956 "Route-map for filtering exported routes\n" "Route map name\n")
1958 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
1959 struct rfapi_cfg
*hc
;
1961 if (!(hc
= bgp
->rfapi_cfg
)) {
1962 vty_out(vty
, "rfapi not configured\n");
1963 return CMD_WARNING_CONFIG_FAILED
;
1966 if (argv
[3]->arg
[0] == 'b') {
1967 if (((argc
> 5) && hc
->routemap_export_bgp_name
1968 && strmatch(argv
[5]->text
, hc
->routemap_export_bgp_name
))
1971 free(hc
->routemap_export_bgp_name
);
1972 hc
->routemap_export_bgp_name
= NULL
;
1973 hc
->routemap_export_bgp
= NULL
;
1974 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
1975 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
1978 if (((argc
> 5) && hc
->routemap_export_zebra_name
1979 && strmatch(argv
[5]->text
, hc
->routemap_export_zebra_name
))
1982 free(hc
->routemap_export_zebra_name
);
1983 hc
->routemap_export_zebra_name
= NULL
;
1984 hc
->routemap_export_zebra
= NULL
;
1985 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
1986 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
1992 DEFUN (vnc_nve_export_routemap
,
1993 vnc_nve_export_routemap_cmd
,
1994 "vnc export <bgp|zebra> route-map NAME",
1996 "Export to other protocols\n"
1998 "Export to Zebra (experimental)\n"
1999 "Route-map for filtering exported routes\n" "Route map name\n")
2001 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2002 struct rfapi_cfg
*hc
;
2004 if (!(hc
= bgp
->rfapi_cfg
)) {
2005 vty_out(vty
, "rfapi not configured\n");
2006 return CMD_WARNING_CONFIG_FAILED
;
2009 if (argv
[2]->arg
[0] == 'b') {
2010 if (hc
->routemap_export_bgp_name
)
2011 free(hc
->routemap_export_bgp_name
);
2012 hc
->routemap_export_bgp_name
= strdup(argv
[4]->arg
);
2013 hc
->routemap_export_bgp
=
2014 route_map_lookup_by_name(argv
[4]->arg
);
2015 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
2016 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
2018 if (hc
->routemap_export_zebra_name
)
2019 free(hc
->routemap_export_zebra_name
);
2020 hc
->routemap_export_zebra_name
= strdup(argv
[4]->arg
);
2021 hc
->routemap_export_zebra
=
2022 route_map_lookup_by_name(argv
[4]->arg
);
2023 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
2024 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
2031 * respond to changes in the global prefix list configuration
2033 void vnc_prefix_list_update(struct bgp
*bgp
)
2037 struct rfapi_nve_group_cfg
*rfg
;
2038 struct rfapi_cfg
*hc
;
2042 vnc_zlog_debug_verbose("%s: No BGP process is configured",
2047 if (!(hc
= bgp
->rfapi_cfg
)) {
2048 vnc_zlog_debug_verbose("%s: rfapi not configured", __func__
);
2052 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
2054 * Loop over nve groups
2056 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->nve_groups_sequential
,
2059 if (rfg
->plist_export_bgp_name
[afi
]) {
2060 rfg
->plist_export_bgp
[afi
] = prefix_list_lookup(
2061 afi
, rfg
->plist_export_bgp_name
[afi
]);
2063 if (rfg
->plist_export_zebra_name
[afi
]) {
2064 rfg
->plist_export_zebra
2065 [afi
] = prefix_list_lookup(
2066 afi
, rfg
->plist_export_zebra_name
[afi
]);
2068 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2069 if (rfg
->plist_redist_name
[i
][afi
]) {
2071 [i
][afi
] = prefix_list_lookup(
2073 rfg
->plist_redist_name
[i
][afi
]);
2077 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, afi
);
2078 /* TBD vnc_zebra_reexport_group_afi(bgp, rfg, afi); */
2084 if (hc
->plist_export_bgp_name
[afi
]) {
2085 hc
->plist_export_bgp
[afi
] = prefix_list_lookup(
2086 afi
, hc
->plist_export_bgp_name
[afi
]);
2088 if (hc
->plist_export_zebra_name
[afi
]) {
2089 hc
->plist_export_zebra
[afi
] = prefix_list_lookup(
2090 afi
, hc
->plist_export_zebra_name
[afi
]);
2093 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2094 if (hc
->plist_redist_name
[i
][afi
]) {
2095 hc
->plist_redist
[i
][afi
] = prefix_list_lookup(
2096 afi
, hc
->plist_redist_name
[i
][afi
]);
2101 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
2102 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
2104 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
2105 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
2107 vnc_redistribute_prechange(bgp
);
2108 vnc_redistribute_postchange(bgp
);
2112 * respond to changes in the global route map configuration
2114 void vnc_routemap_update(struct bgp
*bgp
, const char *unused
)
2117 struct rfapi_nve_group_cfg
*rfg
;
2118 struct rfapi_cfg
*hc
;
2121 vnc_zlog_debug_verbose("%s(arg=%s)", __func__
, unused
);
2124 vnc_zlog_debug_verbose("%s: No BGP process is configured",
2129 if (!(hc
= bgp
->rfapi_cfg
)) {
2130 vnc_zlog_debug_verbose("%s: rfapi not configured", __func__
);
2135 * Loop over nve groups
2137 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->nve_groups_sequential
, n
,
2140 if (rfg
->routemap_export_bgp_name
) {
2141 rfg
->routemap_export_bgp
= route_map_lookup_by_name(
2142 rfg
->routemap_export_bgp_name
);
2144 if (rfg
->routemap_export_zebra_name
) {
2145 rfg
->routemap_export_bgp
= route_map_lookup_by_name(
2146 rfg
->routemap_export_zebra_name
);
2148 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2149 if (rfg
->routemap_redist_name
[i
]) {
2150 rfg
->routemap_redist
[i
] =
2151 route_map_lookup_by_name(
2152 rfg
->routemap_redist_name
[i
]);
2156 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP
);
2157 vnc_direct_bgp_reexport_group_afi(bgp
, rfg
, AFI_IP6
);
2158 /* TBD vnc_zebra_reexport_group_afi(bgp, rfg, afi); */
2164 if (hc
->routemap_export_bgp_name
) {
2165 hc
->routemap_export_bgp
=
2166 route_map_lookup_by_name(hc
->routemap_export_bgp_name
);
2168 if (hc
->routemap_export_zebra_name
) {
2169 hc
->routemap_export_bgp
= route_map_lookup_by_name(
2170 hc
->routemap_export_zebra_name
);
2172 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; ++i
) {
2173 if (hc
->routemap_redist_name
[i
]) {
2174 hc
->routemap_redist
[i
] = route_map_lookup_by_name(
2175 hc
->routemap_redist_name
[i
]);
2179 vnc_direct_bgp_reexport(bgp
, AFI_IP
);
2180 vnc_direct_bgp_reexport(bgp
, AFI_IP6
);
2182 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP); */
2183 /* TBD vnc_zebra_rh_reexport(bgp, AFI_IP6); */
2185 vnc_redistribute_prechange(bgp
);
2186 vnc_redistribute_postchange(bgp
);
2188 vnc_zlog_debug_verbose("%s done", __func__
);
2191 static void vnc_routemap_event(route_map_event_t type
, /* ignored */
2192 const char *rmap_name
) /* ignored */
2194 struct listnode
*mnode
, *mnnode
;
2197 vnc_zlog_debug_verbose("%s(event type=%d)", __func__
, type
);
2198 if (bm
->bgp
== NULL
) /* may be called during cleanup */
2201 for (ALL_LIST_ELEMENTS(bm
->bgp
, mnode
, mnnode
, bgp
))
2202 vnc_routemap_update(bgp
, rmap_name
);
2204 vnc_zlog_debug_verbose("%s: done", __func__
);
2207 /*-------------------------------------------------------------------------
2209 *-----------------------------------------------------------------------*/
2212 DEFUN_NOSH (vnc_nve_group
,
2214 "vnc nve-group NAME",
2215 VNC_CONFIG_STR
"Configure a NVE group\n" "Group name\n")
2217 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2218 struct rfapi_nve_group_cfg
*rfg
;
2219 struct listnode
*node
, *nnode
;
2220 struct rfapi_rfg_name
*rfgn
;
2222 /* Search for name */
2223 rfg
= bgp_rfapi_cfg_match_byname(bgp
, argv
[2]->arg
,
2224 RFAPI_GROUP_CFG_NVE
);
2227 rfg
= rfapi_group_new(bgp
, RFAPI_GROUP_CFG_NVE
, argv
[2]->arg
);
2229 /* Error out of memory */
2230 vty_out(vty
, "Can't allocate memory for NVE group\n");
2231 return CMD_WARNING_CONFIG_FAILED
;
2234 /* Copy defaults from struct rfapi_cfg */
2235 rfg
->rd
= bgp
->rfapi_cfg
->default_rd
;
2236 if (bgp
->rfapi_cfg
->flags
& BGP_VNC_CONFIG_L2RD
) {
2237 rfg
->l2rd
= bgp
->rfapi_cfg
->default_l2rd
;
2238 rfg
->flags
|= RFAPI_RFG_L2RD
;
2240 rfg
->rd
= bgp
->rfapi_cfg
->default_rd
;
2241 rfg
->response_lifetime
=
2242 bgp
->rfapi_cfg
->default_response_lifetime
;
2244 if (bgp
->rfapi_cfg
->default_rt_export_list
) {
2245 rfg
->rt_export_list
= ecommunity_dup(
2246 bgp
->rfapi_cfg
->default_rt_export_list
);
2249 if (bgp
->rfapi_cfg
->default_rt_import_list
) {
2250 rfg
->rt_import_list
= ecommunity_dup(
2251 bgp
->rfapi_cfg
->default_rt_import_list
);
2252 rfg
->rfapi_import_table
= rfapiImportTableRefAdd(
2253 bgp
, rfg
->rt_import_list
, rfg
);
2257 * If a redist nve group was named but the group was not
2259 * make the linkage now
2261 if (!bgp
->rfapi_cfg
->rfg_redist
) {
2262 if (bgp
->rfapi_cfg
->rfg_redist_name
2263 && !strcmp(bgp
->rfapi_cfg
->rfg_redist_name
,
2266 vnc_redistribute_prechange(bgp
);
2267 bgp
->rfapi_cfg
->rfg_redist
= rfg
;
2268 vnc_redistribute_postchange(bgp
);
2273 * Same treatment for bgp-direct export group
2275 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
,
2276 node
, nnode
, rfgn
)) {
2278 if (!strcmp(rfgn
->name
, rfg
->name
)) {
2280 vnc_direct_bgp_add_group(bgp
, rfg
);
2286 * Same treatment for zebra export group
2288 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2291 vnc_zlog_debug_verbose(
2292 "%s: ezport zebra: checking if \"%s\" == \"%s\"",
2293 __func__
, rfgn
->name
, rfg
->name
);
2294 if (!strcmp(rfgn
->name
, rfg
->name
)) {
2296 vnc_zebra_add_group(bgp
, rfg
);
2303 * XXX subsequent calls will need to make sure this item is still
2304 * in the linked list and has the same name
2306 VTY_PUSH_CONTEXT_SUB(BGP_VNC_NVE_GROUP_NODE
, rfg
);
2311 static void bgp_rfapi_delete_nve_group(struct vty
*vty
, /* NULL = no output */
2313 struct rfapi_nve_group_cfg
*rfg
)
2315 struct list
*orphaned_nves
= NULL
;
2316 struct listnode
*node
, *nnode
;
2319 * If there are currently-open NVEs that belong to this group,
2320 * zero out their references to this group structure.
2323 struct rfapi_descriptor
*rfd
;
2324 orphaned_nves
= list_new();
2325 while ((rfd
= listnode_head(rfg
->nves
))) {
2327 listnode_delete(rfg
->nves
, rfd
);
2328 listnode_add(orphaned_nves
, rfd
);
2330 list_delete(rfg
->nves
);
2336 if (rfg
->rfapi_import_table
)
2337 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2338 if (rfg
->rt_import_list
)
2339 ecommunity_free(&rfg
->rt_import_list
);
2340 if (rfg
->rt_export_list
)
2341 ecommunity_free(&rfg
->rt_export_list
);
2344 rfg
->vn_node
->info
= NULL
;
2345 route_unlock_node(rfg
->vn_node
); /* frees */
2348 rfg
->un_node
->info
= NULL
;
2349 route_unlock_node(rfg
->un_node
); /* frees */
2352 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, rfg
->rfp_cfg
);
2353 listnode_delete(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
);
2356 XFREE(MTYPE_RFAPI_GROUP_CFG
, rfg
);
2359 * Attempt to reassign the orphaned nves to a new group. If
2360 * a NVE can not be reassigned, its rfd->rfg will remain NULL
2361 * and it will become a zombie until released by rfapi_close().
2363 if (orphaned_nves
) {
2364 struct rfapi_descriptor
*rfd
;
2366 for (ALL_LIST_ELEMENTS(orphaned_nves
, node
, nnode
, rfd
)) {
2368 * 1. rfapi_close() equivalent except:
2369 * a. don't free original descriptor
2370 * b. remember query list
2371 * c. remember advertised route list
2372 * 2. rfapi_open() equivalent except:
2373 * a. reuse original descriptor
2374 * 3. rfapi_register() on remembered advertised route
2376 * 4. rfapi_query on rememebred query list
2381 rc
= rfapi_reopen(rfd
, bgp
);
2384 list_delete_node(orphaned_nves
, node
);
2387 "WARNING: reassigned NVE vn=");
2388 rfapiPrintRfapiIpAddr(vty
, &rfd
->vn_addr
);
2390 vty_out(vty
, " un=");
2391 rfapiPrintRfapiIpAddr(vty
, &rfd
->un_addr
);
2393 vty_out(vty
, " to new group \"%s\"\n",
2398 for (ALL_LIST_ELEMENTS_RO(orphaned_nves
, node
, rfd
)) {
2400 vty_out(vty
, "WARNING: orphaned NVE vn=");
2401 rfapiPrintRfapiIpAddr(vty
, &rfd
->vn_addr
);
2403 vty_out(vty
, " un=");
2404 rfapiPrintRfapiIpAddr(vty
, &rfd
->un_addr
);
2408 list_delete(orphaned_nves
);
2413 bgp_rfapi_delete_named_nve_group(struct vty
*vty
, /* NULL = no output */
2415 const char *rfg_name
, /* NULL = any */
2416 rfapi_group_cfg_type_t type
) /* _MAX = any */
2418 struct rfapi_nve_group_cfg
*rfg
= NULL
;
2419 struct listnode
*node
, *nnode
;
2420 struct rfapi_rfg_name
*rfgn
;
2422 /* Search for name */
2424 rfg
= bgp_rfapi_cfg_match_byname(bgp
, rfg_name
, type
);
2427 vty_out(vty
, "No NVE group named \"%s\"\n",
2429 return CMD_WARNING_CONFIG_FAILED
;
2434 * If this group is the redist nve group, unlink it
2436 if (rfg_name
== NULL
|| bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2437 vnc_redistribute_prechange(bgp
);
2438 bgp
->rfapi_cfg
->rfg_redist
= NULL
;
2439 vnc_redistribute_postchange(bgp
);
2444 * remove reference from bgp direct export list
2446 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2448 if (rfg_name
== NULL
|| (type
== RFAPI_GROUP_CFG_NVE
2449 && !strcmp(rfgn
->name
, rfg_name
))) {
2451 /* remove exported routes from this group */
2452 vnc_direct_bgp_del_group(bgp
, rfg
);
2458 * remove reference from zebra export list
2460 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2463 if (rfg_name
== NULL
|| (type
== RFAPI_GROUP_CFG_NVE
2464 && !strcmp(rfgn
->name
, rfg_name
))) {
2466 /* remove exported routes from this group */
2467 vnc_zebra_del_group(bgp
, rfg
);
2472 bgp_rfapi_delete_nve_group(vty
, bgp
, rfg
);
2473 else /* must be delete all */
2474 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->nve_groups_sequential
,
2476 bgp_rfapi_delete_nve_group(vty
, bgp
, rfg
);
2480 DEFUN (vnc_no_nve_group
,
2481 vnc_no_nve_group_cmd
,
2482 "no vnc nve-group NAME",
2485 "Configure a NVE group\n"
2488 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2490 return bgp_rfapi_delete_named_nve_group(vty
, bgp
, argv
[3]->arg
,
2491 RFAPI_GROUP_CFG_NVE
);
2494 DEFUN (vnc_nve_group_prefix
,
2495 vnc_nve_group_prefix_cmd
,
2496 "prefix <vn|un> <A.B.C.D/M|X:X::X:X/M>",
2497 "Specify prefixes matching NVE VN or UN interfaces\n"
2503 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2504 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2507 struct route_table
*rt
;
2508 struct route_node
*rn
;
2509 int is_un_prefix
= 0;
2511 /* make sure it's still in list */
2512 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2513 /* Not in list anymore */
2514 vty_out(vty
, "Current NVE group no longer exists\n");
2515 return CMD_WARNING_CONFIG_FAILED
;
2518 if (!str2prefix(argv
[2]->arg
, &p
)) {
2519 vty_out(vty
, "Malformed prefix \"%s\"\n", argv
[2]->arg
);
2520 return CMD_WARNING_CONFIG_FAILED
;
2523 afi
= family2afi(p
.family
);
2525 vty_out(vty
, "Unsupported address family\n");
2526 return CMD_WARNING_CONFIG_FAILED
;
2529 if (argv
[1]->arg
[0] == 'u') {
2530 rt
= bgp
->rfapi_cfg
->nve_groups_un
[afi
];
2533 rt
= bgp
->rfapi_cfg
->nve_groups_vn
[afi
];
2536 rn
= route_node_get(rt
, &p
); /* NB locks node */
2539 * There is already a group with this prefix
2541 route_unlock_node(rn
);
2542 if (rn
->info
!= rfg
) {
2544 * different group name: fail
2547 "nve group \"%s\" already has \"%s\" prefix %s\n",
2548 ((struct rfapi_nve_group_cfg
*)(rn
->info
))
2550 argv
[1]->arg
, argv
[2]->arg
);
2551 return CMD_WARNING_CONFIG_FAILED
;
2554 * same group name: it's already in the correct place
2555 * in the table, so we're done.
2557 * Implies rfg->(vn|un)_prefix is already correct.
2563 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2564 vnc_redistribute_prechange(bgp
);
2567 /* New prefix, new node */
2571 /* detach rfg from previous route table location */
2573 rfg
->un_node
->info
= NULL
;
2574 route_unlock_node(rfg
->un_node
); /* frees */
2576 rfg
->un_node
= rn
; /* back ref */
2581 /* detach rfg from previous route table location */
2583 rfg
->vn_node
->info
= NULL
;
2584 route_unlock_node(rfg
->vn_node
); /* frees */
2586 rfg
->vn_node
= rn
; /* back ref */
2593 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2594 vnc_redistribute_postchange(bgp
);
2600 DEFUN (vnc_nve_group_rt_import
,
2601 vnc_nve_group_rt_import_cmd
,
2602 "rt import RTLIST...",
2603 "Specify route targets\n"
2605 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2607 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2608 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2610 struct listnode
*node
;
2611 struct rfapi_rfg_name
*rfgn
;
2612 int is_export_bgp
= 0;
2613 int is_export_zebra
= 0;
2615 /* make sure it's still in list */
2616 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2617 /* Not in list anymore */
2618 vty_out(vty
, "Current NVE group no longer exists\n");
2619 return CMD_WARNING_CONFIG_FAILED
;
2622 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
2623 if (rc
!= CMD_SUCCESS
)
2626 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2629 if (rfgn
->rfg
== rfg
) {
2636 vnc_direct_bgp_del_group(bgp
, rfg
);
2638 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2641 if (rfgn
->rfg
== rfg
) {
2642 is_export_zebra
= 1;
2647 if (is_export_zebra
)
2648 vnc_zebra_del_group(bgp
, rfg
);
2651 * stop referencing old import table, now reference new one
2653 if (rfg
->rfapi_import_table
)
2654 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2655 rfg
->rfapi_import_table
=
2656 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
2659 vnc_direct_bgp_add_group(bgp
, rfg
);
2661 if (is_export_zebra
)
2662 vnc_zebra_add_group(bgp
, rfg
);
2667 DEFUN (vnc_nve_group_rt_export
,
2668 vnc_nve_group_rt_export_cmd
,
2669 "rt export RTLIST...",
2670 "Specify route targets\n"
2672 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2674 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2675 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2678 /* make sure it's still in list */
2679 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2680 /* Not in list anymore */
2681 vty_out(vty
, "Current NVE group no longer exists\n");
2682 return CMD_WARNING_CONFIG_FAILED
;
2685 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2686 vnc_redistribute_prechange(bgp
);
2689 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
2691 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2692 vnc_redistribute_postchange(bgp
);
2698 DEFUN (vnc_nve_group_rt_both
,
2699 vnc_nve_group_rt_both_cmd
,
2700 "rt both RTLIST...",
2701 "Specify route targets\n"
2702 "Export+import filters\n"
2703 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2705 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2706 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2708 int is_export_bgp
= 0;
2709 int is_export_zebra
= 0;
2710 struct listnode
*node
;
2711 struct rfapi_rfg_name
*rfgn
;
2713 /* make sure it's still in list */
2714 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2715 /* Not in list anymore */
2716 vty_out(vty
, "Current NVE group no longer exists\n");
2717 return CMD_WARNING_CONFIG_FAILED
;
2720 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
2721 if (rc
!= CMD_SUCCESS
)
2724 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2727 if (rfgn
->rfg
== rfg
) {
2734 vnc_direct_bgp_del_group(bgp
, rfg
);
2736 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2739 if (rfgn
->rfg
== rfg
) {
2740 is_export_zebra
= 1;
2745 if (is_export_zebra
) {
2746 vnc_zlog_debug_verbose("%s: is_export_zebra", __func__
);
2747 vnc_zebra_del_group(bgp
, rfg
);
2751 * stop referencing old import table, now reference new one
2753 if (rfg
->rfapi_import_table
)
2754 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2755 rfg
->rfapi_import_table
=
2756 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
2759 vnc_direct_bgp_add_group(bgp
, rfg
);
2761 if (is_export_zebra
)
2762 vnc_zebra_add_group(bgp
, rfg
);
2764 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2765 vnc_redistribute_prechange(bgp
);
2768 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
2770 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2771 vnc_redistribute_postchange(bgp
);
2777 DEFUN (vnc_nve_group_l2rd
,
2778 vnc_nve_group_l2rd_cmd
,
2779 "l2rd <(1-255)|auto-vn>",
2780 "Specify default Local Nve ID value to use in RD for L2 routes\n"
2781 "Fixed value 1-255\n"
2782 "use the low-order octet of the NVE's VN address\n")
2784 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2785 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2787 /* make sure it's still in list */
2788 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2789 /* Not in list anymore */
2790 vty_out(vty
, "Current NVE group no longer exists\n");
2791 return CMD_WARNING_CONFIG_FAILED
;
2794 if (strmatch(argv
[1]->text
, "auto:vn")) {
2798 unsigned long value_l
= strtoul(argv
[1]->arg
, &end
, 10);
2799 uint8_t value
= value_l
& 0xff;
2801 if (!argv
[1]->arg
[0] || *end
) {
2802 vty_out(vty
, "%% Malformed l2 nve ID \"%s\"\n",
2804 return CMD_WARNING_CONFIG_FAILED
;
2806 if ((value_l
< 1) || (value_l
> 0xff)) {
2808 "%% Malformed l2 nve id (must be greater than 0 and less than %u\n",
2810 return CMD_WARNING_CONFIG_FAILED
;
2815 rfg
->flags
|= RFAPI_RFG_L2RD
;
2820 DEFUN (vnc_nve_group_no_l2rd
,
2821 vnc_nve_group_no_l2rd_cmd
,
2824 "Specify default Local Nve ID value to use in RD for L2 routes\n")
2826 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2827 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2829 /* make sure it's still in list */
2830 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2831 /* Not in list anymore */
2832 vty_out(vty
, "Current NVE group no longer exists\n");
2833 return CMD_WARNING_CONFIG_FAILED
;
2837 rfg
->flags
&= ~RFAPI_RFG_L2RD
;
2842 DEFUN (vnc_nve_group_rd
,
2843 vnc_nve_group_rd_cmd
,
2844 "rd ASN:nn_or_IP-address:nn",
2845 "Specify route distinguisher\n"
2846 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:vn:<number> )\n")
2848 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2850 struct prefix_rd prd
;
2851 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2853 /* make sure it's still in list */
2854 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2855 /* Not in list anymore */
2856 vty_out(vty
, "Current NVE group no longer exists\n");
2857 return CMD_WARNING_CONFIG_FAILED
;
2860 if (!strncmp(argv
[1]->arg
, "auto:vn:", 8)) {
2862 * use AF_UNIX to designate automatically-assigned RD
2863 * auto:vn:nn where nn is a 2-octet quantity
2866 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
2867 uint16_t value
= value32
& 0xffff;
2869 if (!argv
[1]->arg
[8] || *end
) {
2870 vty_out(vty
, "%% Malformed rd\n");
2871 return CMD_WARNING_CONFIG_FAILED
;
2873 if (value32
> 0xffff) {
2874 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
2876 return CMD_WARNING_CONFIG_FAILED
;
2879 memset(&prd
, 0, sizeof(prd
));
2880 prd
.family
= AF_UNIX
;
2882 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
2883 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
2884 prd
.val
[6] = (value
>> 8) & 0x0ff;
2885 prd
.val
[7] = value
& 0x0ff;
2889 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
2891 vty_out(vty
, "%% Malformed rd\n");
2892 return CMD_WARNING_CONFIG_FAILED
;
2896 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2897 vnc_redistribute_prechange(bgp
);
2902 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2903 vnc_redistribute_postchange(bgp
);
2908 DEFUN (vnc_nve_group_responselifetime
,
2909 vnc_nve_group_responselifetime_cmd
,
2910 "response-lifetime <LIFETIME|infinite>",
2911 "Specify response lifetime\n"
2912 "Response lifetime in seconds\n" "Infinite response lifetime\n")
2914 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2915 unsigned int rspint
;
2916 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2917 struct rfapi_descriptor
*rfd
;
2918 struct listnode
*hdnode
;
2920 /* make sure it's still in list */
2921 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2922 /* Not in list anymore */
2923 vty_out(vty
, "Current NVE group no longer exists\n");
2924 return CMD_WARNING_CONFIG_FAILED
;
2927 if (strmatch(argv
[1]->text
, "infinite")) {
2928 rspint
= RFAPI_INFINITE_LIFETIME
;
2930 rspint
= strtoul(argv
[1]->arg
, NULL
, 10);
2933 rfg
->response_lifetime
= rspint
;
2934 rfg
->flags
|= RFAPI_RFG_RESPONSE_LIFETIME
;
2936 for (ALL_LIST_ELEMENTS_RO(rfg
->nves
, hdnode
, rfd
))
2937 rfd
->response_lifetime
= rspint
;
2942 * Sigh. This command, like exit-address-family, is a hack to deal
2943 * with the lack of rigorous level control in the command handler.
2944 * TBD fix command handler.
2946 DEFUN_NOSH (exit_vnc
,
2949 "Exit VNC configuration mode\n")
2951 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
2952 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
2953 || vty
->node
== BGP_VNC_L2_GROUP_NODE
) {
2955 vty
->node
= BGP_NODE
;
2960 static struct cmd_node bgp_vnc_defaults_node
= {
2961 BGP_VNC_DEFAULTS_NODE
, "%s(config-router-vnc-defaults)# ", 1};
2963 static struct cmd_node bgp_vnc_nve_group_node
= {
2964 BGP_VNC_NVE_GROUP_NODE
, "%s(config-router-vnc-nve-group)# ", 1};
2966 /*-------------------------------------------------------------------------
2968 * Note there are two types of NVEs, one for VPNs one for RFP NVEs
2969 *-----------------------------------------------------------------------*/
2971 DEFUN_NOSH (vnc_vrf_policy
,
2974 "Configure a VRF policy group\n"
2977 struct rfapi_nve_group_cfg
*rfg
;
2978 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2981 vty_out(vty
, "No BGP process is configured\n");
2982 return CMD_WARNING_CONFIG_FAILED
;
2985 /* Search for name */
2986 rfg
= bgp_rfapi_cfg_match_byname(bgp
, argv
[1]->arg
,
2987 RFAPI_GROUP_CFG_VRF
);
2990 rfg
= rfapi_group_new(bgp
, RFAPI_GROUP_CFG_VRF
, argv
[1]->arg
);
2992 /* Error out of memory */
2993 vty_out(vty
, "Can't allocate memory for NVE group\n");
2994 return CMD_WARNING_CONFIG_FAILED
;
2998 * XXX subsequent calls will need to make sure this item is still
2999 * in the linked list and has the same name
3001 VTY_PUSH_CONTEXT_SUB(BGP_VRF_POLICY_NODE
, rfg
);
3006 DEFUN (vnc_no_vrf_policy
,
3007 vnc_no_vrf_policy_cmd
,
3008 "no vrf-policy NAME",
3010 "Remove a VRF policy group\n"
3013 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3016 vty_out(vty
, "No BGP process is configured\n");
3017 return CMD_WARNING_CONFIG_FAILED
;
3019 return bgp_rfapi_delete_named_nve_group(vty
, bgp
, argv
[2]->arg
,
3020 RFAPI_GROUP_CFG_VRF
);
3023 DEFUN (vnc_vrf_policy_label
,
3024 vnc_vrf_policy_label_cmd
,
3025 "label (0-1048575)",
3026 "Default label value for VRF\n"
3027 "Label Value <0-1048575>\n")
3029 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3032 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3035 vty_out(vty
, "No BGP process is configured\n");
3036 return CMD_WARNING_CONFIG_FAILED
;
3039 /* make sure it's still in list */
3040 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3041 /* Not in list anymore */
3042 vty_out(vty
, "Current NVE group no longer exists\n");
3043 return CMD_WARNING_CONFIG_FAILED
;
3046 label
= strtoul(argv
[1]->arg
, NULL
, 10);
3048 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3049 vnc_redistribute_prechange(bgp
);
3054 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3055 vnc_redistribute_postchange(bgp
);
3060 DEFUN (vnc_vrf_policy_no_label
,
3061 vnc_vrf_policy_no_label_cmd
,
3064 "Remove VRF default label\n")
3066 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3067 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3069 /* make sure it's still in list */
3070 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3071 /* Not in list anymore */
3072 vty_out(vty
, "Current VRF group no longer exists\n");
3073 return CMD_WARNING_CONFIG_FAILED
;
3076 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3077 vnc_redistribute_prechange(bgp
);
3080 rfg
->label
= MPLS_LABEL_ILLEGAL
;
3082 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3083 vnc_redistribute_postchange(bgp
);
3088 DEFUN (vnc_vrf_policy_nexthop
,
3089 vnc_vrf_policy_nexthop_cmd
,
3090 "nexthop <A.B.C.D|X:X::X:X|self>",
3091 "Specify next hop to use for VRF advertised prefixes\n"
3094 "Use configured router-id (default)\n")
3096 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3099 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3101 /* make sure it's still in list */
3102 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3103 /* Not in list anymore */
3104 vty_out(vty
, "Current VRF no longer exists\n");
3105 return CMD_WARNING_CONFIG_FAILED
;
3108 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3109 vnc_redistribute_prechange(bgp
);
3112 if (!str2prefix(argv
[1]->arg
, &p
) && p
.family
) {
3113 // vty_out (vty, "Nexthop set to self\n");
3114 SET_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
);
3115 memset(&rfg
->vn_prefix
, 0, sizeof(struct prefix
));
3117 UNSET_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
);
3122 /* TBD handle router-id/ nexthop changes when have advertised prefixes
3125 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3126 vnc_redistribute_postchange(bgp
);
3132 /* The RT code should be refactored/simplified with above... */
3133 DEFUN (vnc_vrf_policy_rt_import
,
3134 vnc_vrf_policy_rt_import_cmd
,
3135 "rt import RTLIST...",
3136 "Specify route targets\n"
3138 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3140 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3141 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3143 struct listnode
*node
;
3144 struct rfapi_rfg_name
*rfgn
;
3145 int is_export_bgp
= 0;
3146 int is_export_zebra
= 0;
3149 vty_out(vty
, "No BGP process is configured\n");
3150 return CMD_WARNING_CONFIG_FAILED
;
3153 /* make sure it's still in list */
3154 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3155 /* Not in list anymore */
3156 vty_out(vty
, "Current NVE group no longer exists\n");
3157 return CMD_WARNING_CONFIG_FAILED
;
3160 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
3161 if (rc
!= CMD_SUCCESS
)
3164 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
3167 if (rfgn
->rfg
== rfg
) {
3174 vnc_direct_bgp_del_group(bgp
, rfg
);
3176 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
3179 if (rfgn
->rfg
== rfg
) {
3180 is_export_zebra
= 1;
3185 if (is_export_zebra
)
3186 vnc_zebra_del_group(bgp
, rfg
);
3189 * stop referencing old import table, now reference new one
3191 if (rfg
->rfapi_import_table
)
3192 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
3193 rfg
->rfapi_import_table
=
3194 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
3197 vnc_direct_bgp_add_group(bgp
, rfg
);
3199 if (is_export_zebra
)
3200 vnc_zebra_add_group(bgp
, rfg
);
3205 DEFUN (vnc_vrf_policy_rt_export
,
3206 vnc_vrf_policy_rt_export_cmd
,
3207 "rt export RTLIST...",
3208 "Specify route targets\n"
3210 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3212 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3213 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3217 vty_out(vty
, "No BGP process is configured\n");
3218 return CMD_WARNING_CONFIG_FAILED
;
3221 /* make sure it's still in list */
3222 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3223 /* Not in list anymore */
3224 vty_out(vty
, "Current NVE group no longer exists\n");
3225 return CMD_WARNING_CONFIG_FAILED
;
3228 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3229 vnc_redistribute_prechange(bgp
);
3232 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
3234 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3235 vnc_redistribute_postchange(bgp
);
3241 DEFUN (vnc_vrf_policy_rt_both
,
3242 vnc_vrf_policy_rt_both_cmd
,
3243 "rt both RTLIST...",
3244 "Specify route targets\n"
3245 "Export+import filters\n"
3246 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3248 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3249 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3251 int is_export_bgp
= 0;
3252 int is_export_zebra
= 0;
3253 struct listnode
*node
;
3254 struct rfapi_rfg_name
*rfgn
;
3257 vty_out(vty
, "No BGP process is configured\n");
3258 return CMD_WARNING_CONFIG_FAILED
;
3261 /* make sure it's still in list */
3262 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3263 /* Not in list anymore */
3264 vty_out(vty
, "Current NVE group no longer exists\n");
3265 return CMD_WARNING_CONFIG_FAILED
;
3268 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
3269 if (rc
!= CMD_SUCCESS
)
3272 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
3275 if (rfgn
->rfg
== rfg
) {
3282 vnc_direct_bgp_del_group(bgp
, rfg
);
3284 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
3287 if (rfgn
->rfg
== rfg
) {
3288 is_export_zebra
= 1;
3293 if (is_export_zebra
) {
3294 vnc_zlog_debug_verbose("%s: is_export_zebra", __func__
);
3295 vnc_zebra_del_group(bgp
, rfg
);
3299 * stop referencing old import table, now reference new one
3301 if (rfg
->rfapi_import_table
)
3302 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
3303 rfg
->rfapi_import_table
=
3304 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
3307 vnc_direct_bgp_add_group(bgp
, rfg
);
3309 if (is_export_zebra
)
3310 vnc_zebra_add_group(bgp
, rfg
);
3312 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3313 vnc_redistribute_prechange(bgp
);
3316 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
3318 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3319 vnc_redistribute_postchange(bgp
);
3325 DEFUN (vnc_vrf_policy_rd
,
3326 vnc_vrf_policy_rd_cmd
,
3327 "rd ASN:nn_or_IP-address:nn",
3328 "Specify default VRF route distinguisher\n"
3329 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:nh:<number> )\n")
3332 struct prefix_rd prd
;
3333 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3334 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3337 vty_out(vty
, "No BGP process is configured\n");
3338 return CMD_WARNING_CONFIG_FAILED
;
3341 /* make sure it's still in list */
3342 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3343 /* Not in list anymore */
3344 vty_out(vty
, "Current NVE group no longer exists\n");
3345 return CMD_WARNING_CONFIG_FAILED
;
3348 if (!strncmp(argv
[1]->arg
, "auto:nh:", 8)) {
3350 * use AF_UNIX to designate automatically-assigned RD
3351 * auto:vn:nn where nn is a 2-octet quantity
3354 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
3355 uint16_t value
= value32
& 0xffff;
3357 if (!*(argv
[1]->arg
+ 5) || *end
) {
3358 vty_out(vty
, "%% Malformed rd\n");
3359 return CMD_WARNING_CONFIG_FAILED
;
3361 if (value32
> 0xffff) {
3362 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
3364 return CMD_WARNING_CONFIG_FAILED
;
3367 memset(&prd
, 0, sizeof(prd
));
3368 prd
.family
= AF_UNIX
;
3370 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
3371 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
3372 prd
.val
[6] = (value
>> 8) & 0x0ff;
3373 prd
.val
[7] = value
& 0x0ff;
3377 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
3379 vty_out(vty
, "%% Malformed rd\n");
3380 return CMD_WARNING_CONFIG_FAILED
;
3384 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3385 vnc_redistribute_prechange(bgp
);
3390 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3391 vnc_redistribute_postchange(bgp
);
3396 DEFUN_NOSH (exit_vrf_policy
,
3397 exit_vrf_policy_cmd
,
3399 "Exit VRF policy configuration mode\n")
3401 if (vty
->node
== BGP_VRF_POLICY_NODE
) {
3402 vty
->node
= BGP_NODE
;
3407 static struct cmd_node bgp_vrf_policy_node
= {
3408 BGP_VRF_POLICY_NODE
, "%s(config-router-vrf-policy)# ", 1};
3410 /*-------------------------------------------------------------------------
3412 *-----------------------------------------------------------------------*/
3415 DEFUN_NOSH (vnc_l2_group
,
3417 "vnc l2-group NAME",
3418 VNC_CONFIG_STR
"Configure a L2 group\n" "Group name\n")
3420 struct rfapi_l2_group_cfg
*rfg
;
3421 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3424 vty_out(vty
, "No BGP process is configured\n");
3425 return CMD_WARNING_CONFIG_FAILED
;
3428 /* Search for name */
3429 rfg
= rfapi_l2_group_lookup_byname(bgp
, argv
[1]->arg
);
3432 rfg
= rfapi_l2_group_new();
3434 /* Error out of memory */
3435 vty_out(vty
, "Can't allocate memory for L2 group\n");
3436 return CMD_WARNING_CONFIG_FAILED
;
3438 rfg
->name
= strdup(argv
[1]->arg
);
3439 /* add to tail of list */
3440 listnode_add(bgp
->rfapi_cfg
->l2_groups
, rfg
);
3444 * XXX subsequent calls will need to make sure this item is still
3445 * in the linked list and has the same name
3447 VTY_PUSH_CONTEXT_SUB(BGP_VNC_L2_GROUP_NODE
, rfg
);
3451 static void bgp_rfapi_delete_l2_group(struct vty
*vty
, /* NULL = no output */
3453 struct rfapi_l2_group_cfg
*rfg
)
3457 if (rfg
->rt_import_list
)
3458 ecommunity_free(&rfg
->rt_import_list
);
3459 if (rfg
->rt_export_list
)
3460 ecommunity_free(&rfg
->rt_export_list
);
3462 list_delete(rfg
->labels
);
3464 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, rfg
->rfp_cfg
);
3465 listnode_delete(bgp
->rfapi_cfg
->l2_groups
, rfg
);
3467 rfapi_l2_group_del(rfg
);
3471 bgp_rfapi_delete_named_l2_group(struct vty
*vty
, /* NULL = no output */
3473 const char *rfg_name
) /* NULL = any */
3475 struct rfapi_l2_group_cfg
*rfg
= NULL
;
3476 struct listnode
*node
, *nnode
;
3478 /* Search for name */
3480 rfg
= rfapi_l2_group_lookup_byname(bgp
, rfg_name
);
3483 vty_out(vty
, "No L2 group named \"%s\"\n",
3485 return CMD_WARNING_CONFIG_FAILED
;
3490 bgp_rfapi_delete_l2_group(vty
, bgp
, rfg
);
3491 else /* must be delete all */
3492 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->l2_groups
, node
, nnode
,
3494 bgp_rfapi_delete_l2_group(vty
, bgp
, rfg
);
3498 DEFUN (vnc_no_l2_group
,
3499 vnc_no_l2_group_cmd
,
3500 "no vnc l2-group NAME",
3503 "Configure a L2 group\n"
3506 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3509 vty_out(vty
, "No BGP process is configured\n");
3510 return CMD_WARNING_CONFIG_FAILED
;
3512 return bgp_rfapi_delete_named_l2_group(vty
, bgp
, argv
[3]->arg
);
3516 DEFUN (vnc_l2_group_lni
,
3517 vnc_l2_group_lni_cmd
,
3518 "logical-network-id <0-4294967295>",
3519 "Specify Logical Network ID associated with group\n"
3522 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3523 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3526 vty_out(vty
, "No BGP process is configured\n");
3527 return CMD_WARNING_CONFIG_FAILED
;
3530 /* make sure it's still in list */
3531 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3532 /* Not in list anymore */
3533 vty_out(vty
, "Current L2 group no longer exists\n");
3534 return CMD_WARNING_CONFIG_FAILED
;
3537 rfg
->logical_net_id
= strtoul(argv
[1]->arg
, NULL
, 10);
3542 DEFUN (vnc_l2_group_labels
,
3543 vnc_l2_group_labels_cmd
,
3544 "labels LABELLIST...",
3545 "Specify label values associated with 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
);
3553 vty_out(vty
, "No BGP process is configured\n");
3554 return CMD_WARNING_CONFIG_FAILED
;
3557 /* make sure it's still in list */
3558 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3559 /* Not in list anymore */
3560 vty_out(vty
, "Current L2 group no longer exists\n");
3561 return CMD_WARNING_CONFIG_FAILED
;
3571 for (; argc
; --argc
, ++argv
) {
3573 label
= strtoul(argv
[0]->arg
, NULL
, 10);
3574 if (!listnode_lookup(ll
, (void *)(uintptr_t)label
))
3575 listnode_add(ll
, (void *)(uintptr_t)label
);
3581 DEFUN (vnc_l2_group_no_labels
,
3582 vnc_l2_group_no_labels_cmd
,
3583 "no labels LABELLIST...",
3585 "Specify label values associated with L2 group\n"
3586 "Space separated list of label values <0-1048575>\n")
3588 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3589 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3593 vty_out(vty
, "No BGP process is configured\n");
3594 return CMD_WARNING_CONFIG_FAILED
;
3597 /* make sure it's still in list */
3598 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3599 /* Not in list anymore */
3600 vty_out(vty
, "Current L2 group no longer exists\n");
3601 return CMD_WARNING_CONFIG_FAILED
;
3606 vty_out(vty
, "Label no longer associated with group\n");
3607 return CMD_WARNING_CONFIG_FAILED
;
3612 for (; argc
; --argc
, ++argv
) {
3614 label
= strtoul(argv
[0]->arg
, NULL
, 10);
3615 listnode_delete(ll
, (void *)(uintptr_t)label
);
3621 DEFUN (vnc_l2_group_rt
,
3622 vnc_l2_group_rt_cmd
,
3623 "rt <both|export|import> ASN:nn_or_IP-address:nn",
3624 "Specify route targets\n"
3625 "Export+import filters\n"
3630 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3631 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3632 int rc
= CMD_SUCCESS
;
3636 switch (argv
[1]->arg
[0]) {
3638 do_export
= 1; /* fall through */
3646 vty_out(vty
, "Unknown option, %s\n", argv
[1]->arg
);
3647 return CMD_ERR_NO_MATCH
;
3650 vty_out(vty
, "No BGP process is configured\n");
3651 return CMD_WARNING_CONFIG_FAILED
;
3654 /* make sure it's still in list */
3655 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3656 /* Not in list anymore */
3657 vty_out(vty
, "Current L2 group no longer exists\n");
3658 return CMD_WARNING_CONFIG_FAILED
;
3662 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
3663 &rfg
->rt_import_list
);
3664 if (rc
== CMD_SUCCESS
&& do_export
)
3665 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
3666 &rfg
->rt_export_list
);
3671 static struct cmd_node bgp_vnc_l2_group_node
= {
3672 BGP_VNC_L2_GROUP_NODE
, "%s(config-router-vnc-l2-group)# ", 1};
3674 struct rfapi_l2_group_cfg
*
3675 bgp_rfapi_get_group_by_lni_label(struct bgp
*bgp
, uint32_t logical_net_id
,
3678 struct rfapi_l2_group_cfg
*rfg
;
3679 struct listnode
*node
;
3681 if (bgp
->rfapi_cfg
->l2_groups
== NULL
) /* not the best place for this */
3684 label
= label
& 0xfffff; /* label is 20 bits! */
3686 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->l2_groups
, node
, rfg
)) {
3687 if (rfg
->logical_net_id
== logical_net_id
) {
3688 struct listnode
*lnode
;
3690 for (ALL_LIST_ELEMENTS_RO(rfg
->labels
, lnode
, data
))
3691 if (((uint32_t)((uintptr_t)data
))
3692 == label
) { /* match! */
3700 struct list
*bgp_rfapi_get_labellist_by_lni_label(struct bgp
*bgp
,
3701 uint32_t logical_net_id
,
3704 struct rfapi_l2_group_cfg
*rfg
;
3705 rfg
= bgp_rfapi_get_group_by_lni_label(bgp
, logical_net_id
, label
);
3713 bgp_rfapi_get_ecommunity_by_lni_label(struct bgp
*bgp
, uint32_t is_import
,
3714 uint32_t logical_net_id
, uint32_t label
)
3716 struct rfapi_l2_group_cfg
*rfg
;
3717 rfg
= bgp_rfapi_get_group_by_lni_label(bgp
, logical_net_id
, label
);
3720 return rfg
->rt_import_list
;
3722 return rfg
->rt_export_list
;
3727 void bgp_rfapi_cfg_init(void)
3729 /* main bgpd code does not use this hook, but vnc does */
3730 route_map_event_hook(vnc_routemap_event
);
3732 install_node(&bgp_vnc_defaults_node
, NULL
);
3733 install_node(&bgp_vnc_nve_group_node
, NULL
);
3734 install_node(&bgp_vrf_policy_node
, NULL
);
3735 install_node(&bgp_vnc_l2_group_node
, NULL
);
3736 install_default(BGP_VRF_POLICY_NODE
);
3737 install_default(BGP_VNC_DEFAULTS_NODE
);
3738 install_default(BGP_VNC_NVE_GROUP_NODE
);
3739 install_default(BGP_VNC_L2_GROUP_NODE
);
3744 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3745 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3746 install_element(BGP_NODE
, &vnc_no_nve_group_cmd
);
3747 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3748 install_element(BGP_NODE
, &vnc_no_vrf_policy_cmd
);
3749 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3750 install_element(BGP_NODE
, &vnc_no_l2_group_cmd
);
3751 install_element(BGP_NODE
, &vnc_advertise_un_method_cmd
);
3752 install_element(BGP_NODE
, &vnc_export_mode_cmd
);
3754 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_import_cmd
);
3755 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_export_cmd
);
3756 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_both_cmd
);
3757 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rd_cmd
);
3758 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_l2rd_cmd
);
3759 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_no_l2rd_cmd
);
3760 install_element(BGP_VNC_DEFAULTS_NODE
,
3761 &vnc_defaults_responselifetime_cmd
);
3762 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_cmd
);
3764 install_element(BGP_NODE
, &vnc_redistribute_protocol_cmd
);
3765 install_element(BGP_NODE
, &vnc_no_redistribute_protocol_cmd
);
3766 install_element(BGP_NODE
, &vnc_redistribute_nvegroup_cmd
);
3767 install_element(BGP_NODE
, &vnc_redistribute_no_nvegroup_cmd
);
3768 install_element(BGP_NODE
, &vnc_redistribute_lifetime_cmd
);
3769 install_element(BGP_NODE
, &vnc_redistribute_rh_roo_localadmin_cmd
);
3770 install_element(BGP_NODE
, &vnc_redistribute_mode_cmd
);
3771 install_element(BGP_NODE
, &vnc_redistribute_bgp_exterior_cmd
);
3773 install_element(BGP_NODE
, &vnc_redist_bgpdirect_no_prefixlist_cmd
);
3774 install_element(BGP_NODE
, &vnc_redist_bgpdirect_prefixlist_cmd
);
3775 install_element(BGP_NODE
, &vnc_redist_bgpdirect_no_routemap_cmd
);
3776 install_element(BGP_NODE
, &vnc_redist_bgpdirect_routemap_cmd
);
3778 install_element(BGP_VNC_NVE_GROUP_NODE
,
3779 &vnc_nve_group_redist_bgpdirect_no_prefixlist_cmd
);
3780 install_element(BGP_VNC_NVE_GROUP_NODE
,
3781 &vnc_nve_group_redist_bgpdirect_prefixlist_cmd
);
3782 install_element(BGP_VNC_NVE_GROUP_NODE
,
3783 &vnc_nve_group_redist_bgpdirect_no_routemap_cmd
);
3784 install_element(BGP_VNC_NVE_GROUP_NODE
,
3785 &vnc_nve_group_redist_bgpdirect_routemap_cmd
);
3787 install_element(BGP_NODE
, &vnc_export_nvegroup_cmd
);
3788 install_element(BGP_NODE
, &vnc_no_export_nvegroup_cmd
);
3789 install_element(BGP_NODE
, &vnc_nve_export_prefixlist_cmd
);
3790 install_element(BGP_NODE
, &vnc_nve_export_routemap_cmd
);
3791 install_element(BGP_NODE
, &vnc_nve_export_no_prefixlist_cmd
);
3792 install_element(BGP_NODE
, &vnc_nve_export_no_routemap_cmd
);
3794 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_l2rd_cmd
);
3795 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_no_l2rd_cmd
);
3796 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_prefix_cmd
);
3797 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_import_cmd
);
3798 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_export_cmd
);
3799 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_both_cmd
);
3800 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rd_cmd
);
3801 install_element(BGP_VNC_NVE_GROUP_NODE
,
3802 &vnc_nve_group_responselifetime_cmd
);
3803 install_element(BGP_VNC_NVE_GROUP_NODE
,
3804 &vnc_nve_group_export_prefixlist_cmd
);
3805 install_element(BGP_VNC_NVE_GROUP_NODE
,
3806 &vnc_nve_group_export_routemap_cmd
);
3807 install_element(BGP_VNC_NVE_GROUP_NODE
,
3808 &vnc_nve_group_export_no_prefixlist_cmd
);
3809 install_element(BGP_VNC_NVE_GROUP_NODE
,
3810 &vnc_nve_group_export_no_routemap_cmd
);
3811 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_cmd
);
3813 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_label_cmd
);
3814 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_no_label_cmd
);
3815 // Reenable to support VRF controller use case and testing
3816 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_nexthop_cmd
);
3817 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_import_cmd
);
3818 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_export_cmd
);
3819 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_both_cmd
);
3820 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rd_cmd
);
3821 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
3823 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_lni_cmd
);
3824 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_labels_cmd
);
3825 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_no_labels_cmd
);
3826 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_rt_cmd
);
3827 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_cmd
);
3830 struct rfapi_cfg
*bgp_rfapi_cfg_new(struct rfapi_rfp_cfg
*cfg
)
3832 struct rfapi_cfg
*h
;
3835 h
= (struct rfapi_cfg
*)XCALLOC(MTYPE_RFAPI_CFG
,
3836 sizeof(struct rfapi_cfg
));
3839 h
->nve_groups_sequential
= list_new();
3840 assert(h
->nve_groups_sequential
);
3841 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
3842 h
->nve_groups_vn
[afi
] = route_table_init();
3843 h
->nve_groups_un
[afi
] = route_table_init();
3845 h
->default_response_lifetime
=
3846 BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT
;
3847 h
->rfg_export_direct_bgp_l
= list_new();
3848 h
->rfg_export_zebra_l
= list_new();
3849 h
->resolve_nve_roo_local_admin
=
3850 BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT
;
3852 SET_FLAG(h
->flags
, BGP_VNC_CONFIG_FLAGS_DEFAULT
);
3855 h
->rfp_cfg
.download_type
= RFAPI_RFP_DOWNLOAD_PARTIAL
;
3856 h
->rfp_cfg
.ftd_advertisement_interval
=
3857 RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL
;
3858 h
->rfp_cfg
.holddown_factor
=
3859 RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR
;
3860 h
->rfp_cfg
.use_updated_response
= 0;
3861 h
->rfp_cfg
.use_removes
= 0;
3863 h
->rfp_cfg
.download_type
= cfg
->download_type
;
3864 h
->rfp_cfg
.ftd_advertisement_interval
=
3865 cfg
->ftd_advertisement_interval
;
3866 h
->rfp_cfg
.holddown_factor
= cfg
->holddown_factor
;
3867 h
->rfp_cfg
.use_updated_response
= cfg
->use_updated_response
;
3868 h
->rfp_cfg
.use_removes
= cfg
->use_removes
;
3869 if (cfg
->use_updated_response
)
3870 h
->flags
&= ~BGP_VNC_CONFIG_CALLBACK_DISABLE
;
3872 h
->flags
|= BGP_VNC_CONFIG_CALLBACK_DISABLE
;
3873 if (cfg
->use_removes
)
3874 h
->flags
&= ~BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE
;
3876 h
->flags
|= BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE
;
3881 void bgp_rfapi_cfg_destroy(struct bgp
*bgp
, struct rfapi_cfg
*h
)
3887 bgp_rfapi_delete_named_nve_group(NULL
, bgp
, NULL
, RFAPI_GROUP_CFG_MAX
);
3888 bgp_rfapi_delete_named_l2_group(NULL
, bgp
, NULL
);
3889 if (h
->l2_groups
!= NULL
)
3890 list_delete(h
->l2_groups
);
3891 list_delete(h
->nve_groups_sequential
);
3892 list_delete(h
->rfg_export_direct_bgp_l
);
3893 list_delete(h
->rfg_export_zebra_l
);
3894 if (h
->default_rt_export_list
)
3895 ecommunity_free(&h
->default_rt_export_list
);
3896 if (h
->default_rt_import_list
)
3897 ecommunity_free(&h
->default_rt_import_list
);
3898 if (h
->default_rfp_cfg
)
3899 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, h
->default_rfp_cfg
);
3900 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
3901 route_table_finish(h
->nve_groups_vn
[afi
]);
3902 route_table_finish(h
->nve_groups_un
[afi
]);
3904 XFREE(MTYPE_RFAPI_CFG
, h
);
3907 int bgp_rfapi_cfg_write(struct vty
*vty
, struct bgp
*bgp
)
3909 struct listnode
*node
, *nnode
;
3910 struct rfapi_nve_group_cfg
*rfg
;
3911 struct rfapi_cfg
*hc
= bgp
->rfapi_cfg
;
3912 struct rfapi_rfg_name
*rfgn
;
3916 if (bgp
->rfapi
== NULL
|| hc
== NULL
)
3919 vty_out(vty
, "!\n");
3920 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
, rfg
))
3921 if (rfg
->type
== RFAPI_GROUP_CFG_VRF
) {
3923 vty_out(vty
, " vrf-policy %s\n", rfg
->name
);
3924 if (rfg
->label
<= MPLS_LABEL_MAX
) {
3925 vty_out(vty
, " label %u\n", rfg
->label
);
3927 if (CHECK_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
)) {
3928 vty_out(vty
, " nexthop self\n");
3931 if (rfg
->vn_prefix
.family
) {
3933 buf
[0] = buf
[BUFSIZ
- 1] = 0;
3934 inet_ntop(rfg
->vn_prefix
.family
,
3935 &rfg
->vn_prefix
.u
.prefix
, buf
,
3937 if (!buf
[0] || buf
[BUFSIZ
- 1]) {
3938 // vty_out (vty, "nexthop
3941 vty_out(vty
, " nexthop %s\n",
3947 if (rfg
->rd
.prefixlen
) {
3949 buf
[0] = buf
[BUFSIZ
- 1] = 0;
3951 if (AF_UNIX
== rfg
->rd
.family
) {
3955 value
= ((rfg
->rd
.val
[6] << 8)
3957 | (rfg
->rd
.val
[7] & 0x0ff);
3959 vty_out(vty
, " rd auto:nh:%d\n",
3964 if (!prefix_rd2str(&rfg
->rd
, buf
,
3966 || !buf
[0] || buf
[BUFSIZ
- 1]) {
3969 "!Error: Can't convert rd\n");
3971 vty_out(vty
, " rd %s\n", buf
);
3976 if (rfg
->rt_import_list
&& rfg
->rt_export_list
3977 && ecommunity_cmp(rfg
->rt_import_list
,
3978 rfg
->rt_export_list
)) {
3979 char *b
= ecommunity_ecom2str(
3980 rfg
->rt_import_list
,
3981 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3982 ECOMMUNITY_ROUTE_TARGET
);
3983 vty_out(vty
, " rt both %s\n", b
);
3984 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3986 if (rfg
->rt_import_list
) {
3987 char *b
= ecommunity_ecom2str(
3988 rfg
->rt_import_list
,
3989 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3990 ECOMMUNITY_ROUTE_TARGET
);
3991 vty_out(vty
, " rt import %s\n", b
);
3992 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3994 if (rfg
->rt_export_list
) {
3995 char *b
= ecommunity_ecom2str(
3996 rfg
->rt_export_list
,
3997 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3998 ECOMMUNITY_ROUTE_TARGET
);
3999 vty_out(vty
, " rt export %s\n", b
);
4000 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4005 * route filtering: prefix-lists and route-maps
4007 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4009 const char *afistr
=
4010 (afi
== AFI_IP
) ? "ipv4" : "ipv6";
4012 if (rfg
->plist_export_bgp_name
[afi
]) {
4014 " export bgp %s prefix-list %s\n",
4016 rfg
->plist_export_bgp_name
4019 if (rfg
->plist_export_zebra_name
[afi
]) {
4021 " export zebra %s prefix-list %s\n",
4023 rfg
->plist_export_zebra_name
4027 * currently we only support redist plists for
4029 * If we later add plist support for
4030 * redistributing other
4031 * protocols, we'll need to loop over protocols
4034 if (rfg
->plist_redist_name
4035 [ZEBRA_ROUTE_BGP_DIRECT
][afi
]) {
4037 " redistribute bgp-direct %s prefix-list %s\n",
4039 rfg
->plist_redist_name
4040 [ZEBRA_ROUTE_BGP_DIRECT
]
4043 if (rfg
->plist_redist_name
4044 [ZEBRA_ROUTE_BGP_DIRECT_EXT
][afi
]) {
4046 " redistribute bgp-direct-to-nve-groups %s prefix-list %s\n",
4048 rfg
->plist_redist_name
4049 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4054 if (rfg
->routemap_export_bgp_name
) {
4055 vty_out(vty
, " export bgp route-map %s\n",
4056 rfg
->routemap_export_bgp_name
);
4058 if (rfg
->routemap_export_zebra_name
) {
4059 vty_out(vty
, " export zebra route-map %s\n",
4060 rfg
->routemap_export_zebra_name
);
4062 if (rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]) {
4064 " redistribute bgp-direct route-map %s\n",
4065 rfg
->routemap_redist_name
4066 [ZEBRA_ROUTE_BGP_DIRECT
]);
4068 if (rfg
->routemap_redist_name
4069 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]) {
4071 " redistribute bgp-direct-to-nve-groups route-map %s\n",
4072 rfg
->routemap_redist_name
4073 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]);
4075 vty_out(vty
, " exit-vrf-policy\n");
4076 vty_out(vty
, "!\n");
4078 if (hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
) {
4079 vty_out(vty
, " vnc advertise-un-method encap-safi\n");
4083 { /* was based on listen ports */
4084 /* for now allow both old and new */
4085 if (bgp
->rfapi
->rfp_methods
.cfg_cb
)
4086 write
+= (bgp
->rfapi
->rfp_methods
.cfg_cb
)(
4087 vty
, bgp
->rfapi
->rfp
);
4090 vty_out(vty
, "!\n");
4092 if (hc
->l2_groups
) {
4093 struct rfapi_l2_group_cfg
*rfg
= NULL
;
4094 struct listnode
*gnode
;
4095 for (ALL_LIST_ELEMENTS_RO(hc
->l2_groups
, gnode
, rfg
)) {
4096 struct listnode
*lnode
;
4099 vty_out(vty
, " vnc l2-group %s\n", rfg
->name
);
4100 if (rfg
->logical_net_id
!= 0)
4102 " logical-network-id %u\n",
4103 rfg
->logical_net_id
);
4104 if (rfg
->labels
!= NULL
4105 && listhead(rfg
->labels
) != NULL
) {
4106 vty_out(vty
, " labels ");
4107 for (ALL_LIST_ELEMENTS_RO(rfg
->labels
,
4110 vty_out(vty
, "%hu ",
4118 if (rfg
->rt_import_list
&& rfg
->rt_export_list
4119 && ecommunity_cmp(rfg
->rt_import_list
,
4120 rfg
->rt_export_list
)) {
4121 char *b
= ecommunity_ecom2str(
4122 rfg
->rt_import_list
,
4123 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4124 ECOMMUNITY_ROUTE_TARGET
);
4125 vty_out(vty
, " rt both %s\n", b
);
4126 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4128 if (rfg
->rt_import_list
) {
4129 char *b
= ecommunity_ecom2str(
4130 rfg
->rt_import_list
,
4131 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4132 ECOMMUNITY_ROUTE_TARGET
);
4133 vty_out(vty
, " rt import %s\n",
4135 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4137 if (rfg
->rt_export_list
) {
4138 char *b
= ecommunity_ecom2str(
4139 rfg
->rt_export_list
,
4140 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4141 ECOMMUNITY_ROUTE_TARGET
);
4142 vty_out(vty
, " rt export %s\n",
4144 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4147 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4148 write
+= (bgp
->rfapi
->rfp_methods
4150 vty
, bgp
->rfapi
->rfp
,
4151 RFAPI_RFP_CFG_GROUP_L2
,
4152 rfg
->name
, rfg
->rfp_cfg
);
4153 vty_out(vty
, " exit-vnc\n");
4154 vty_out(vty
, "!\n");
4158 if (hc
->default_rd
.family
|| hc
->default_response_lifetime
4159 || hc
->default_rt_import_list
|| hc
->default_rt_export_list
4160 || hc
->nve_groups_sequential
->count
) {
4164 vty_out(vty
, " vnc defaults\n");
4166 if (hc
->default_rd
.prefixlen
) {
4168 buf
[0] = buf
[BUFSIZ
- 1] = 0;
4170 if (AF_UNIX
== hc
->default_rd
.family
) {
4173 value
= ((hc
->default_rd
.val
[6] << 8)
4175 | (hc
->default_rd
.val
[7]
4178 vty_out(vty
, " rd auto:vn:%d\n",
4183 if (!prefix_rd2str(&hc
->default_rd
, buf
,
4185 || !buf
[0] || buf
[BUFSIZ
- 1]) {
4188 "!Error: Can't convert rd\n");
4190 vty_out(vty
, " rd %s\n", buf
);
4194 if (hc
->default_response_lifetime
) {
4195 vty_out(vty
, " response-lifetime ");
4196 if (hc
->default_response_lifetime
!= UINT32_MAX
)
4198 hc
->default_response_lifetime
);
4200 vty_out(vty
, "infinite");
4203 if (hc
->default_rt_import_list
4204 && hc
->default_rt_export_list
4205 && ecommunity_cmp(hc
->default_rt_import_list
,
4206 hc
->default_rt_export_list
)) {
4207 char *b
= ecommunity_ecom2str(
4208 hc
->default_rt_import_list
,
4209 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4210 ECOMMUNITY_ROUTE_TARGET
);
4211 vty_out(vty
, " rt both %s\n", b
);
4212 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4214 if (hc
->default_rt_import_list
) {
4215 char *b
= ecommunity_ecom2str(
4216 hc
->default_rt_import_list
,
4217 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4218 ECOMMUNITY_ROUTE_TARGET
);
4219 vty_out(vty
, " rt import %s\n", b
);
4220 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4222 if (hc
->default_rt_export_list
) {
4223 char *b
= ecommunity_ecom2str(
4224 hc
->default_rt_export_list
,
4225 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4226 ECOMMUNITY_ROUTE_TARGET
);
4227 vty_out(vty
, " rt export %s\n", b
);
4228 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4231 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4232 write
+= (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)(
4233 vty
, bgp
->rfapi
->rfp
,
4234 RFAPI_RFP_CFG_GROUP_DEFAULT
, NULL
,
4235 bgp
->rfapi_cfg
->default_rfp_cfg
);
4236 vty_out(vty
, " exit-vnc\n");
4237 vty_out(vty
, "!\n");
4240 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
,
4242 if (rfg
->type
== RFAPI_GROUP_CFG_NVE
) {
4244 vty_out(vty
, " vnc nve-group %s\n", rfg
->name
);
4246 if (rfg
->vn_prefix
.family
&& rfg
->vn_node
) {
4248 buf
[0] = buf
[BUFSIZ
- 1] = 0;
4250 prefix2str(&rfg
->vn_prefix
, buf
,
4252 if (!buf
[0] || buf
[BUFSIZ
- 1]) {
4254 "!Error: Can't convert prefix\n");
4256 vty_out(vty
, " prefix %s %s\n",
4261 if (rfg
->un_prefix
.family
&& rfg
->un_node
) {
4263 buf
[0] = buf
[BUFSIZ
- 1] = 0;
4264 prefix2str(&rfg
->un_prefix
, buf
,
4266 if (!buf
[0] || buf
[BUFSIZ
- 1]) {
4268 "!Error: Can't convert prefix\n");
4270 vty_out(vty
, " prefix %s %s\n",
4276 if (rfg
->rd
.prefixlen
) {
4278 buf
[0] = buf
[BUFSIZ
- 1] = 0;
4280 if (AF_UNIX
== rfg
->rd
.family
) {
4284 value
= ((rfg
->rd
.val
[6] << 8)
4295 if (!prefix_rd2str(&rfg
->rd
,
4298 || buf
[BUFSIZ
- 1]) {
4301 "!Error: Can't convert rd\n");
4309 if (rfg
->flags
& RFAPI_RFG_RESPONSE_LIFETIME
) {
4310 vty_out(vty
, " response-lifetime ");
4311 if (rfg
->response_lifetime
4314 rfg
->response_lifetime
);
4316 vty_out(vty
, "infinite");
4320 if (rfg
->rt_import_list
&& rfg
->rt_export_list
4321 && ecommunity_cmp(rfg
->rt_import_list
,
4322 rfg
->rt_export_list
)) {
4323 char *b
= ecommunity_ecom2str(
4324 rfg
->rt_import_list
,
4325 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4326 ECOMMUNITY_ROUTE_TARGET
);
4327 vty_out(vty
, " rt both %s\n", b
);
4328 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4330 if (rfg
->rt_import_list
) {
4331 char *b
= ecommunity_ecom2str(
4332 rfg
->rt_import_list
,
4333 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4334 ECOMMUNITY_ROUTE_TARGET
);
4335 vty_out(vty
, " rt import %s\n",
4337 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4339 if (rfg
->rt_export_list
) {
4340 char *b
= ecommunity_ecom2str(
4341 rfg
->rt_export_list
,
4342 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4343 ECOMMUNITY_ROUTE_TARGET
);
4344 vty_out(vty
, " rt export %s\n",
4346 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4351 * route filtering: prefix-lists and route-maps
4353 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4355 const char *afistr
= (afi
== AFI_IP
)
4359 if (rfg
->plist_export_bgp_name
[afi
]) {
4361 " export bgp %s prefix-list %s\n",
4363 rfg
->plist_export_bgp_name
4366 if (rfg
->plist_export_zebra_name
[afi
]) {
4368 " export zebra %s prefix-list %s\n",
4370 rfg
->plist_export_zebra_name
4374 * currently we only support redist
4375 * plists for bgp-direct.
4376 * If we later add plist support for
4377 * redistributing other
4378 * protocols, we'll need to loop over
4381 if (rfg
->plist_redist_name
4382 [ZEBRA_ROUTE_BGP_DIRECT
]
4385 " redistribute bgp-direct %s prefix-list %s\n",
4387 rfg
->plist_redist_name
4388 [ZEBRA_ROUTE_BGP_DIRECT
]
4391 if (rfg
->plist_redist_name
4392 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4395 " redistribute bgp-direct-to-nve-groups %s prefix-list %s\n",
4397 rfg
->plist_redist_name
4398 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4403 if (rfg
->routemap_export_bgp_name
) {
4405 " export bgp route-map %s\n",
4406 rfg
->routemap_export_bgp_name
);
4408 if (rfg
->routemap_export_zebra_name
) {
4410 " export zebra route-map %s\n",
4411 rfg
->routemap_export_zebra_name
);
4413 if (rfg
->routemap_redist_name
4414 [ZEBRA_ROUTE_BGP_DIRECT
]) {
4416 " redistribute bgp-direct route-map %s\n",
4417 rfg
->routemap_redist_name
4418 [ZEBRA_ROUTE_BGP_DIRECT
]);
4420 if (rfg
->routemap_redist_name
4421 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]) {
4423 " redistribute bgp-direct-to-nve-groups route-map %s\n",
4424 rfg
->routemap_redist_name
4425 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]);
4427 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4428 write
+= (bgp
->rfapi
->rfp_methods
4430 vty
, bgp
->rfapi
->rfp
,
4431 RFAPI_RFP_CFG_GROUP_NVE
,
4432 rfg
->name
, rfg
->rfp_cfg
);
4433 vty_out(vty
, " exit-vnc\n");
4434 vty_out(vty
, "!\n");
4436 } /* have listen ports */
4439 * route export to other protocols
4441 if (VNC_EXPORT_BGP_GRP_ENABLED(hc
)) {
4442 vty_out(vty
, " vnc export bgp mode group-nve\n");
4443 } else if (VNC_EXPORT_BGP_RH_ENABLED(hc
)) {
4444 vty_out(vty
, " vnc export bgp mode registering-nve\n");
4445 } else if (VNC_EXPORT_BGP_CE_ENABLED(hc
)) {
4446 vty_out(vty
, " vnc export bgp mode ce\n");
4449 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(hc
)) {
4450 vty_out(vty
, " vnc export zebra mode group-nve\n");
4451 } else if (VNC_EXPORT_ZEBRA_RH_ENABLED(hc
)) {
4452 vty_out(vty
, " vnc export zebra mode registering-nve\n");
4455 if (hc
->rfg_export_direct_bgp_l
) {
4456 for (ALL_LIST_ELEMENTS(hc
->rfg_export_direct_bgp_l
, node
, nnode
,
4459 vty_out(vty
, " vnc export bgp group-nve group %s\n",
4464 if (hc
->rfg_export_zebra_l
) {
4465 for (ALL_LIST_ELEMENTS(hc
->rfg_export_zebra_l
, node
, nnode
,
4468 vty_out(vty
, " vnc export zebra group-nve group %s\n",
4474 if (hc
->rfg_redist_name
) {
4475 vty_out(vty
, " vnc redistribute nve-group %s\n",
4476 hc
->rfg_redist_name
);
4478 if (hc
->redist_lifetime
) {
4479 vty_out(vty
, " vnc redistribute lifetime %d\n",
4480 hc
->redist_lifetime
);
4482 if (hc
->resolve_nve_roo_local_admin
4483 != BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT
) {
4486 " vnc redistribute resolve-nve roo-ec-local-admin %d\n",
4487 hc
->resolve_nve_roo_local_admin
);
4490 if (hc
->redist_mode
) /* ! default */
4494 switch (hc
->redist_mode
) {
4495 case VNC_REDIST_MODE_PLAIN
:
4498 case VNC_REDIST_MODE_RFG
:
4501 case VNC_REDIST_MODE_RESOLVE_NVE
:
4506 vty_out(vty
, " vnc redistribute mode %s\n", s
);
4511 * route filtering: prefix-lists and route-maps
4513 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4515 const char *afistr
= (afi
== AFI_IP
) ? "ipv4" : "ipv6";
4517 if (hc
->plist_export_bgp_name
[afi
]) {
4518 vty_out(vty
, " vnc export bgp %s prefix-list %s\n",
4519 afistr
, hc
->plist_export_bgp_name
[afi
]);
4521 if (hc
->plist_export_zebra_name
[afi
]) {
4522 vty_out(vty
, " vnc export zebra %s prefix-list %s\n",
4523 afistr
, hc
->plist_export_zebra_name
[afi
]);
4525 if (hc
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
]) {
4527 " vnc redistribute bgp-direct %s prefix-list %s\n",
4529 hc
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]
4534 if (hc
->routemap_export_bgp_name
) {
4535 vty_out(vty
, " vnc export bgp route-map %s\n",
4536 hc
->routemap_export_bgp_name
);
4538 if (hc
->routemap_export_zebra_name
) {
4539 vty_out(vty
, " vnc export zebra route-map %s\n",
4540 hc
->routemap_export_zebra_name
);
4542 if (hc
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]) {
4543 vty_out(vty
, " vnc redistribute bgp-direct route-map %s\n",
4544 hc
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]);
4547 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4548 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
4549 if (hc
->redist
[afi
][type
]) {
4550 if (type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
4551 && hc
->redist_bgp_exterior_view_name
) {
4553 " vnc redistribute %s %s view %s\n",
4554 ((afi
== AFI_IP
) ? "ipv4"
4556 zebra_route_string(type
),
4557 hc
->redist_bgp_exterior_view_name
);
4560 " vnc redistribute %s %s\n",
4561 ((afi
== AFI_IP
) ? "ipv4"
4563 zebra_route_string(type
));
4571 void bgp_rfapi_show_summary(struct bgp
*bgp
, struct vty
*vty
)
4573 struct rfapi_cfg
*hc
= bgp
->rfapi_cfg
;
4575 int type
, redist
= 0;
4580 vty_out(vty
, "%-39s %-19s %s\n", "VNC Advertise method:",
4581 (hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
4582 ? "Encapsulation SAFI"
4583 : "Tunnel Encap attribute"),
4584 ((hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
)
4585 == (BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
4586 & BGP_VNC_CONFIG_FLAGS_DEFAULT
)
4590 vty_out(vty
, "%-39s ", "Export from VNC:");
4592 * route export to other protocols
4594 if (VNC_EXPORT_BGP_GRP_ENABLED(hc
)) {
4596 vty_out(vty
, "ToBGP Groups={");
4597 if (hc
->rfg_export_direct_bgp_l
) {
4599 struct listnode
*node
, *nnode
;
4600 struct rfapi_rfg_name
*rfgn
;
4601 for (ALL_LIST_ELEMENTS(hc
->rfg_export_direct_bgp_l
,
4602 node
, nnode
, rfgn
)) {
4606 vty_out(vty
, "%s", rfgn
->name
);
4610 } else if (VNC_EXPORT_BGP_RH_ENABLED(hc
)) {
4612 vty_out(vty
, "ToBGP {Registering NVE}");
4613 /* note filters, route-maps not shown */
4614 } else if (VNC_EXPORT_BGP_CE_ENABLED(hc
)) {
4616 vty_out(vty
, "ToBGP {NVE connected router:%d}",
4617 hc
->resolve_nve_roo_local_admin
);
4618 /* note filters, route-maps not shown */
4621 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(hc
)) {
4623 vty_out(vty
, "%sToZebra Groups={", (redist
== 1 ? "" : " "));
4624 if (hc
->rfg_export_direct_bgp_l
) {
4626 struct listnode
*node
, *nnode
;
4627 struct rfapi_rfg_name
*rfgn
;
4628 for (ALL_LIST_ELEMENTS(hc
->rfg_export_zebra_l
, node
,
4632 vty_out(vty
, "%s", rfgn
->name
);
4636 } else if (VNC_EXPORT_ZEBRA_RH_ENABLED(hc
)) {
4638 vty_out(vty
, "%sToZebra {Registering NVE}",
4639 (redist
== 1 ? "" : " "));
4640 /* note filters, route-maps not shown */
4642 vty_out(vty
, "%-19s %s\n", (redist
? "" : "Off"),
4643 (redist
? "" : "(default)"));
4645 /* Redistribution */
4647 vty_out(vty
, "%-39s ", "Redistribution into VNC:");
4648 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4649 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
4650 if (hc
->redist
[afi
][type
]) {
4651 vty_out(vty
, "{%s,%s} ",
4652 ((afi
== AFI_IP
) ? "ipv4" : "ipv6"),
4653 zebra_route_string(type
));
4658 vty_out(vty
, "%-19s %s\n", (redist
? "" : "Off"),
4659 (redist
? "" : "(default)"));
4661 vty_out(vty
, "%-39s %3u%-16s %s\n",
4662 "RFP Registration Hold-Down Factor:",
4663 hc
->rfp_cfg
.holddown_factor
, "%",
4664 (hc
->rfp_cfg
.holddown_factor
4665 == RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR
4668 vty_out(vty
, "%-39s %-19s %s\n", "RFP Updated responses:",
4669 (hc
->rfp_cfg
.use_updated_response
== 0 ? "Off" : "On"),
4670 (hc
->rfp_cfg
.use_updated_response
== 0 ? "(default)" : ""));
4671 vty_out(vty
, "%-39s %-19s %s\n", "RFP Removal responses:",
4672 (hc
->rfp_cfg
.use_removes
== 0 ? "Off" : "On"),
4673 (hc
->rfp_cfg
.use_removes
== 0 ? "(default)" : ""));
4674 vty_out(vty
, "%-39s %-19s %s\n", "RFP Full table download:",
4675 (hc
->rfp_cfg
.download_type
== RFAPI_RFP_DOWNLOAD_FULL
? "On"
4677 (hc
->rfp_cfg
.download_type
== RFAPI_RFP_DOWNLOAD_PARTIAL
4680 sprintf(tmp
, "%u seconds", hc
->rfp_cfg
.ftd_advertisement_interval
);
4681 vty_out(vty
, "%-39s %-19s %s\n", " Advertisement Interval:", tmp
,
4682 (hc
->rfp_cfg
.ftd_advertisement_interval
4683 == RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL
4686 vty_out(vty
, "%-39s %d seconds\n", "Default RFP response lifetime:",
4687 hc
->default_response_lifetime
);
4692 struct rfapi_cfg
*bgp_rfapi_get_config(struct bgp
*bgp
)
4694 struct rfapi_cfg
*hc
= NULL
;
4696 bgp
= bgp_get_default();
4698 hc
= bgp
->rfapi_cfg
;
4702 #endif /* ENABLE_BGP_VNC */