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_and_null(&rfg
->nves
);
2335 if (rfg
->rfapi_import_table
)
2336 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2337 if (rfg
->rt_import_list
)
2338 ecommunity_free(&rfg
->rt_import_list
);
2339 if (rfg
->rt_export_list
)
2340 ecommunity_free(&rfg
->rt_export_list
);
2343 rfg
->vn_node
->info
= NULL
;
2344 route_unlock_node(rfg
->vn_node
); /* frees */
2347 rfg
->un_node
->info
= NULL
;
2348 route_unlock_node(rfg
->un_node
); /* frees */
2351 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, rfg
->rfp_cfg
);
2352 listnode_delete(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
);
2355 XFREE(MTYPE_RFAPI_GROUP_CFG
, rfg
);
2358 * Attempt to reassign the orphaned nves to a new group. If
2359 * a NVE can not be reassigned, its rfd->rfg will remain NULL
2360 * and it will become a zombie until released by rfapi_close().
2362 if (orphaned_nves
) {
2363 struct rfapi_descriptor
*rfd
;
2365 for (ALL_LIST_ELEMENTS(orphaned_nves
, node
, nnode
, rfd
)) {
2367 * 1. rfapi_close() equivalent except:
2368 * a. don't free original descriptor
2369 * b. remember query list
2370 * c. remember advertised route list
2371 * 2. rfapi_open() equivalent except:
2372 * a. reuse original descriptor
2373 * 3. rfapi_register() on remembered advertised route
2375 * 4. rfapi_query on rememebred query list
2380 rc
= rfapi_reopen(rfd
, bgp
);
2383 list_delete_node(orphaned_nves
, node
);
2386 "WARNING: reassigned NVE vn=");
2387 rfapiPrintRfapiIpAddr(vty
, &rfd
->vn_addr
);
2389 vty_out(vty
, " un=");
2390 rfapiPrintRfapiIpAddr(vty
, &rfd
->un_addr
);
2392 vty_out(vty
, " to new group \"%s\"\n",
2397 for (ALL_LIST_ELEMENTS_RO(orphaned_nves
, node
, rfd
)) {
2399 vty_out(vty
, "WARNING: orphaned NVE vn=");
2400 rfapiPrintRfapiIpAddr(vty
, &rfd
->vn_addr
);
2402 vty_out(vty
, " un=");
2403 rfapiPrintRfapiIpAddr(vty
, &rfd
->un_addr
);
2407 list_delete_and_null(&orphaned_nves
);
2412 bgp_rfapi_delete_named_nve_group(struct vty
*vty
, /* NULL = no output */
2414 const char *rfg_name
, /* NULL = any */
2415 rfapi_group_cfg_type_t type
) /* _MAX = any */
2417 struct rfapi_nve_group_cfg
*rfg
= NULL
;
2418 struct listnode
*node
, *nnode
;
2419 struct rfapi_rfg_name
*rfgn
;
2421 /* Search for name */
2423 rfg
= bgp_rfapi_cfg_match_byname(bgp
, rfg_name
, type
);
2426 vty_out(vty
, "No NVE group named \"%s\"\n",
2428 return CMD_WARNING_CONFIG_FAILED
;
2433 * If this group is the redist nve group, unlink it
2435 if (rfg_name
== NULL
|| bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2436 vnc_redistribute_prechange(bgp
);
2437 bgp
->rfapi_cfg
->rfg_redist
= NULL
;
2438 vnc_redistribute_postchange(bgp
);
2443 * remove reference from bgp direct export list
2445 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2447 if (rfg_name
== NULL
|| (type
== RFAPI_GROUP_CFG_NVE
2448 && !strcmp(rfgn
->name
, rfg_name
))) {
2450 /* remove exported routes from this group */
2451 vnc_direct_bgp_del_group(bgp
, rfg
);
2457 * remove reference from zebra export list
2459 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2462 if (rfg_name
== NULL
|| (type
== RFAPI_GROUP_CFG_NVE
2463 && !strcmp(rfgn
->name
, rfg_name
))) {
2465 /* remove exported routes from this group */
2466 vnc_zebra_del_group(bgp
, rfg
);
2471 bgp_rfapi_delete_nve_group(vty
, bgp
, rfg
);
2472 else /* must be delete all */
2473 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->nve_groups_sequential
,
2475 bgp_rfapi_delete_nve_group(vty
, bgp
, rfg
);
2479 DEFUN (vnc_no_nve_group
,
2480 vnc_no_nve_group_cmd
,
2481 "no vnc nve-group NAME",
2484 "Configure a NVE group\n"
2487 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2489 return bgp_rfapi_delete_named_nve_group(vty
, bgp
, argv
[3]->arg
,
2490 RFAPI_GROUP_CFG_NVE
);
2493 DEFUN (vnc_nve_group_prefix
,
2494 vnc_nve_group_prefix_cmd
,
2495 "prefix <vn|un> <A.B.C.D/M|X:X::X:X/M>",
2496 "Specify prefixes matching NVE VN or UN interfaces\n"
2502 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2503 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2506 struct route_table
*rt
;
2507 struct route_node
*rn
;
2508 int is_un_prefix
= 0;
2510 /* make sure it's still in list */
2511 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2512 /* Not in list anymore */
2513 vty_out(vty
, "Current NVE group no longer exists\n");
2514 return CMD_WARNING_CONFIG_FAILED
;
2517 if (!str2prefix(argv
[2]->arg
, &p
)) {
2518 vty_out(vty
, "Malformed prefix \"%s\"\n", argv
[2]->arg
);
2519 return CMD_WARNING_CONFIG_FAILED
;
2522 afi
= family2afi(p
.family
);
2524 vty_out(vty
, "Unsupported address family\n");
2525 return CMD_WARNING_CONFIG_FAILED
;
2528 if (argv
[1]->arg
[0] == 'u') {
2529 rt
= bgp
->rfapi_cfg
->nve_groups_un
[afi
];
2532 rt
= bgp
->rfapi_cfg
->nve_groups_vn
[afi
];
2535 rn
= route_node_get(rt
, &p
); /* NB locks node */
2538 * There is already a group with this prefix
2540 route_unlock_node(rn
);
2541 if (rn
->info
!= rfg
) {
2543 * different group name: fail
2546 "nve group \"%s\" already has \"%s\" prefix %s\n",
2547 ((struct rfapi_nve_group_cfg
*)(rn
->info
))
2549 argv
[1]->arg
, argv
[2]->arg
);
2550 return CMD_WARNING_CONFIG_FAILED
;
2553 * same group name: it's already in the correct place
2554 * in the table, so we're done.
2556 * Implies rfg->(vn|un)_prefix is already correct.
2562 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2563 vnc_redistribute_prechange(bgp
);
2566 /* New prefix, new node */
2570 /* detach rfg from previous route table location */
2572 rfg
->un_node
->info
= NULL
;
2573 route_unlock_node(rfg
->un_node
); /* frees */
2575 rfg
->un_node
= rn
; /* back ref */
2580 /* detach rfg from previous route table location */
2582 rfg
->vn_node
->info
= NULL
;
2583 route_unlock_node(rfg
->vn_node
); /* frees */
2585 rfg
->vn_node
= rn
; /* back ref */
2592 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2593 vnc_redistribute_postchange(bgp
);
2599 DEFUN (vnc_nve_group_rt_import
,
2600 vnc_nve_group_rt_import_cmd
,
2601 "rt import RTLIST...",
2602 "Specify route targets\n"
2604 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2606 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2607 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2609 struct listnode
*node
;
2610 struct rfapi_rfg_name
*rfgn
;
2611 int is_export_bgp
= 0;
2612 int is_export_zebra
= 0;
2614 /* make sure it's still in list */
2615 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2616 /* Not in list anymore */
2617 vty_out(vty
, "Current NVE group no longer exists\n");
2618 return CMD_WARNING_CONFIG_FAILED
;
2621 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
2622 if (rc
!= CMD_SUCCESS
)
2625 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2628 if (rfgn
->rfg
== rfg
) {
2635 vnc_direct_bgp_del_group(bgp
, rfg
);
2637 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2640 if (rfgn
->rfg
== rfg
) {
2641 is_export_zebra
= 1;
2646 if (is_export_zebra
)
2647 vnc_zebra_del_group(bgp
, rfg
);
2650 * stop referencing old import table, now reference new one
2652 if (rfg
->rfapi_import_table
)
2653 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2654 rfg
->rfapi_import_table
=
2655 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
2658 vnc_direct_bgp_add_group(bgp
, rfg
);
2660 if (is_export_zebra
)
2661 vnc_zebra_add_group(bgp
, rfg
);
2666 DEFUN (vnc_nve_group_rt_export
,
2667 vnc_nve_group_rt_export_cmd
,
2668 "rt export RTLIST...",
2669 "Specify route targets\n"
2671 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2673 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2674 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2677 /* make sure it's still in list */
2678 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2679 /* Not in list anymore */
2680 vty_out(vty
, "Current NVE group no longer exists\n");
2681 return CMD_WARNING_CONFIG_FAILED
;
2684 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2685 vnc_redistribute_prechange(bgp
);
2688 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
2690 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2691 vnc_redistribute_postchange(bgp
);
2697 DEFUN (vnc_nve_group_rt_both
,
2698 vnc_nve_group_rt_both_cmd
,
2699 "rt both RTLIST...",
2700 "Specify route targets\n"
2701 "Export+import filters\n"
2702 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
2704 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2705 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2707 int is_export_bgp
= 0;
2708 int is_export_zebra
= 0;
2709 struct listnode
*node
;
2710 struct rfapi_rfg_name
*rfgn
;
2712 /* make sure it's still in list */
2713 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2714 /* Not in list anymore */
2715 vty_out(vty
, "Current NVE group no longer exists\n");
2716 return CMD_WARNING_CONFIG_FAILED
;
2719 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
2720 if (rc
!= CMD_SUCCESS
)
2723 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
2726 if (rfgn
->rfg
== rfg
) {
2733 vnc_direct_bgp_del_group(bgp
, rfg
);
2735 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
2738 if (rfgn
->rfg
== rfg
) {
2739 is_export_zebra
= 1;
2744 if (is_export_zebra
) {
2745 vnc_zlog_debug_verbose("%s: is_export_zebra", __func__
);
2746 vnc_zebra_del_group(bgp
, rfg
);
2750 * stop referencing old import table, now reference new one
2752 if (rfg
->rfapi_import_table
)
2753 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
2754 rfg
->rfapi_import_table
=
2755 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
2758 vnc_direct_bgp_add_group(bgp
, rfg
);
2760 if (is_export_zebra
)
2761 vnc_zebra_add_group(bgp
, rfg
);
2763 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2764 vnc_redistribute_prechange(bgp
);
2767 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
2769 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2770 vnc_redistribute_postchange(bgp
);
2776 DEFUN (vnc_nve_group_l2rd
,
2777 vnc_nve_group_l2rd_cmd
,
2778 "l2rd <(1-255)|auto-vn>",
2779 "Specify default Local Nve ID value to use in RD for L2 routes\n"
2780 "Fixed value 1-255\n"
2781 "use the low-order octet of the NVE's VN address\n")
2783 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2784 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2786 /* make sure it's still in list */
2787 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2788 /* Not in list anymore */
2789 vty_out(vty
, "Current NVE group no longer exists\n");
2790 return CMD_WARNING_CONFIG_FAILED
;
2793 if (strmatch(argv
[1]->text
, "auto:vn")) {
2797 unsigned long value_l
= strtoul(argv
[1]->arg
, &end
, 10);
2798 uint8_t value
= value_l
& 0xff;
2800 if (!argv
[1]->arg
[0] || *end
) {
2801 vty_out(vty
, "%% Malformed l2 nve ID \"%s\"\n",
2803 return CMD_WARNING_CONFIG_FAILED
;
2805 if ((value_l
< 1) || (value_l
> 0xff)) {
2807 "%% Malformed l2 nve id (must be greater than 0 and less than %u\n",
2809 return CMD_WARNING_CONFIG_FAILED
;
2814 rfg
->flags
|= RFAPI_RFG_L2RD
;
2819 DEFUN (vnc_nve_group_no_l2rd
,
2820 vnc_nve_group_no_l2rd_cmd
,
2823 "Specify default Local Nve ID value to use in RD for L2 routes\n")
2825 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2826 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2828 /* make sure it's still in list */
2829 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2830 /* Not in list anymore */
2831 vty_out(vty
, "Current NVE group no longer exists\n");
2832 return CMD_WARNING_CONFIG_FAILED
;
2836 rfg
->flags
&= ~RFAPI_RFG_L2RD
;
2841 DEFUN (vnc_nve_group_rd
,
2842 vnc_nve_group_rd_cmd
,
2843 "rd ASN:NN_OR_IP-ADDRESS:NN",
2844 "Specify route distinguisher\n"
2845 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:vn:<number> )\n")
2847 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2849 struct prefix_rd prd
;
2850 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2852 /* make sure it's still in list */
2853 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2854 /* Not in list anymore */
2855 vty_out(vty
, "Current NVE group no longer exists\n");
2856 return CMD_WARNING_CONFIG_FAILED
;
2859 if (!strncmp(argv
[1]->arg
, "auto:vn:", 8)) {
2861 * use AF_UNIX to designate automatically-assigned RD
2862 * auto:vn:nn where nn is a 2-octet quantity
2865 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
2866 uint16_t value
= value32
& 0xffff;
2868 if (!argv
[1]->arg
[8] || *end
) {
2869 vty_out(vty
, "%% Malformed rd\n");
2870 return CMD_WARNING_CONFIG_FAILED
;
2872 if (value32
> 0xffff) {
2873 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
2875 return CMD_WARNING_CONFIG_FAILED
;
2878 memset(&prd
, 0, sizeof(prd
));
2879 prd
.family
= AF_UNIX
;
2881 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
2882 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
2883 prd
.val
[6] = (value
>> 8) & 0x0ff;
2884 prd
.val
[7] = value
& 0x0ff;
2888 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
2890 vty_out(vty
, "%% Malformed rd\n");
2891 return CMD_WARNING_CONFIG_FAILED
;
2895 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2896 vnc_redistribute_prechange(bgp
);
2901 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
2902 vnc_redistribute_postchange(bgp
);
2907 DEFUN (vnc_nve_group_responselifetime
,
2908 vnc_nve_group_responselifetime_cmd
,
2909 "response-lifetime <LIFETIME|infinite>",
2910 "Specify response lifetime\n"
2911 "Response lifetime in seconds\n" "Infinite response lifetime\n")
2913 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2914 unsigned int rspint
;
2915 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
2916 struct rfapi_descriptor
*rfd
;
2917 struct listnode
*hdnode
;
2919 /* make sure it's still in list */
2920 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
2921 /* Not in list anymore */
2922 vty_out(vty
, "Current NVE group no longer exists\n");
2923 return CMD_WARNING_CONFIG_FAILED
;
2926 if (strmatch(argv
[1]->text
, "infinite")) {
2927 rspint
= RFAPI_INFINITE_LIFETIME
;
2929 rspint
= strtoul(argv
[1]->arg
, NULL
, 10);
2932 rfg
->response_lifetime
= rspint
;
2933 rfg
->flags
|= RFAPI_RFG_RESPONSE_LIFETIME
;
2935 for (ALL_LIST_ELEMENTS_RO(rfg
->nves
, hdnode
, rfd
))
2936 rfd
->response_lifetime
= rspint
;
2941 * Sigh. This command, like exit-address-family, is a hack to deal
2942 * with the lack of rigorous level control in the command handler.
2943 * TBD fix command handler.
2945 DEFUN_NOSH (exit_vnc
,
2948 "Exit VNC configuration mode\n")
2950 if (vty
->node
== BGP_VNC_DEFAULTS_NODE
2951 || vty
->node
== BGP_VNC_NVE_GROUP_NODE
2952 || vty
->node
== BGP_VNC_L2_GROUP_NODE
) {
2954 vty
->node
= BGP_NODE
;
2959 static struct cmd_node bgp_vnc_defaults_node
= {
2960 BGP_VNC_DEFAULTS_NODE
, "%s(config-router-vnc-defaults)# ", 1};
2962 static struct cmd_node bgp_vnc_nve_group_node
= {
2963 BGP_VNC_NVE_GROUP_NODE
, "%s(config-router-vnc-nve-group)# ", 1};
2965 /*-------------------------------------------------------------------------
2967 * Note there are two types of NVEs, one for VPNs one for RFP NVEs
2968 *-----------------------------------------------------------------------*/
2970 DEFUN_NOSH (vnc_vrf_policy
,
2973 "Configure a VRF policy group\n"
2976 struct rfapi_nve_group_cfg
*rfg
;
2977 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
2979 /* Search for name */
2980 rfg
= bgp_rfapi_cfg_match_byname(bgp
, argv
[1]->arg
,
2981 RFAPI_GROUP_CFG_VRF
);
2984 rfg
= rfapi_group_new(bgp
, RFAPI_GROUP_CFG_VRF
, argv
[1]->arg
);
2986 /* Error out of memory */
2987 vty_out(vty
, "Can't allocate memory for NVE group\n");
2988 return CMD_WARNING_CONFIG_FAILED
;
2992 * XXX subsequent calls will need to make sure this item is still
2993 * in the linked list and has the same name
2995 VTY_PUSH_CONTEXT_SUB(BGP_VRF_POLICY_NODE
, rfg
);
3000 DEFUN (vnc_no_vrf_policy
,
3001 vnc_no_vrf_policy_cmd
,
3002 "no vrf-policy NAME",
3004 "Remove a VRF policy group\n"
3007 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3009 return bgp_rfapi_delete_named_nve_group(vty
, bgp
, argv
[2]->arg
,
3010 RFAPI_GROUP_CFG_VRF
);
3013 DEFUN (vnc_vrf_policy_label
,
3014 vnc_vrf_policy_label_cmd
,
3015 "label (0-1048575)",
3016 "Default label value for VRF\n"
3017 "Label Value <0-1048575>\n")
3019 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3022 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3024 /* make sure it's still in list */
3025 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3026 /* Not in list anymore */
3027 vty_out(vty
, "Current NVE group no longer exists\n");
3028 return CMD_WARNING_CONFIG_FAILED
;
3031 label
= strtoul(argv
[1]->arg
, NULL
, 10);
3033 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3034 vnc_redistribute_prechange(bgp
);
3039 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3040 vnc_redistribute_postchange(bgp
);
3045 DEFUN (vnc_vrf_policy_no_label
,
3046 vnc_vrf_policy_no_label_cmd
,
3049 "Remove VRF default label\n")
3051 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3052 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3054 /* make sure it's still in list */
3055 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3056 /* Not in list anymore */
3057 vty_out(vty
, "Current VRF group no longer exists\n");
3058 return CMD_WARNING_CONFIG_FAILED
;
3061 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3062 vnc_redistribute_prechange(bgp
);
3065 rfg
->label
= MPLS_LABEL_ILLEGAL
;
3067 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3068 vnc_redistribute_postchange(bgp
);
3073 DEFUN (vnc_vrf_policy_nexthop
,
3074 vnc_vrf_policy_nexthop_cmd
,
3075 "nexthop <A.B.C.D|X:X::X:X|self>",
3076 "Specify next hop to use for VRF advertised prefixes\n"
3079 "Use configured router-id (default)\n")
3081 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3084 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3086 /* make sure it's still in list */
3087 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3088 /* Not in list anymore */
3089 vty_out(vty
, "Current VRF no longer exists\n");
3090 return CMD_WARNING_CONFIG_FAILED
;
3093 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3094 vnc_redistribute_prechange(bgp
);
3097 if (!str2prefix(argv
[1]->arg
, &p
) && p
.family
) {
3098 // vty_out (vty, "Nexthop set to self\n");
3099 SET_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
);
3100 memset(&rfg
->vn_prefix
, 0, sizeof(struct prefix
));
3102 UNSET_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
);
3107 /* TBD handle router-id/ nexthop changes when have advertised prefixes
3110 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3111 vnc_redistribute_postchange(bgp
);
3117 /* The RT code should be refactored/simplified with above... */
3118 DEFUN (vnc_vrf_policy_rt_import
,
3119 vnc_vrf_policy_rt_import_cmd
,
3120 "rt import RTLIST...",
3121 "Specify route targets\n"
3123 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3125 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3126 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3128 struct listnode
*node
;
3129 struct rfapi_rfg_name
*rfgn
;
3130 int is_export_bgp
= 0;
3131 int is_export_zebra
= 0;
3133 /* make sure it's still in list */
3134 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3135 /* Not in list anymore */
3136 vty_out(vty
, "Current NVE group no longer exists\n");
3137 return CMD_WARNING_CONFIG_FAILED
;
3140 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
3141 if (rc
!= CMD_SUCCESS
)
3144 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
3147 if (rfgn
->rfg
== rfg
) {
3154 vnc_direct_bgp_del_group(bgp
, rfg
);
3156 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
3159 if (rfgn
->rfg
== rfg
) {
3160 is_export_zebra
= 1;
3165 if (is_export_zebra
)
3166 vnc_zebra_del_group(bgp
, rfg
);
3169 * stop referencing old import table, now reference new one
3171 if (rfg
->rfapi_import_table
)
3172 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
3173 rfg
->rfapi_import_table
=
3174 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
3177 vnc_direct_bgp_add_group(bgp
, rfg
);
3179 if (is_export_zebra
)
3180 vnc_zebra_add_group(bgp
, rfg
);
3185 DEFUN (vnc_vrf_policy_rt_export
,
3186 vnc_vrf_policy_rt_export_cmd
,
3187 "rt export RTLIST...",
3188 "Specify route targets\n"
3190 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3192 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3193 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3196 /* make sure it's still in list */
3197 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3198 /* Not in list anymore */
3199 vty_out(vty
, "Current NVE group no longer exists\n");
3200 return CMD_WARNING_CONFIG_FAILED
;
3203 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3204 vnc_redistribute_prechange(bgp
);
3207 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
3209 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3210 vnc_redistribute_postchange(bgp
);
3216 DEFUN (vnc_vrf_policy_rt_both
,
3217 vnc_vrf_policy_rt_both_cmd
,
3218 "rt both RTLIST...",
3219 "Specify route targets\n"
3220 "Export+import filters\n"
3221 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
3223 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3224 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3226 int is_export_bgp
= 0;
3227 int is_export_zebra
= 0;
3228 struct listnode
*node
;
3229 struct rfapi_rfg_name
*rfgn
;
3231 /* make sure it's still in list */
3232 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3233 /* Not in list anymore */
3234 vty_out(vty
, "Current NVE group no longer exists\n");
3235 return CMD_WARNING_CONFIG_FAILED
;
3238 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_import_list
);
3239 if (rc
!= CMD_SUCCESS
)
3242 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_direct_bgp_l
, node
,
3245 if (rfgn
->rfg
== rfg
) {
3252 vnc_direct_bgp_del_group(bgp
, rfg
);
3254 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->rfg_export_zebra_l
, node
,
3257 if (rfgn
->rfg
== rfg
) {
3258 is_export_zebra
= 1;
3263 if (is_export_zebra
) {
3264 vnc_zlog_debug_verbose("%s: is_export_zebra", __func__
);
3265 vnc_zebra_del_group(bgp
, rfg
);
3269 * stop referencing old import table, now reference new one
3271 if (rfg
->rfapi_import_table
)
3272 rfapiImportTableRefDelByIt(bgp
, rfg
->rfapi_import_table
);
3273 rfg
->rfapi_import_table
=
3274 rfapiImportTableRefAdd(bgp
, rfg
->rt_import_list
, rfg
);
3277 vnc_direct_bgp_add_group(bgp
, rfg
);
3279 if (is_export_zebra
)
3280 vnc_zebra_add_group(bgp
, rfg
);
3282 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3283 vnc_redistribute_prechange(bgp
);
3286 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2, &rfg
->rt_export_list
);
3288 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3289 vnc_redistribute_postchange(bgp
);
3295 DEFUN (vnc_vrf_policy_rd
,
3296 vnc_vrf_policy_rd_cmd
,
3297 "rd ASN:NN_OR_IP-ADDRESS:NN",
3298 "Specify default VRF route distinguisher\n"
3299 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number> | auto:nh:<number> )\n")
3302 struct prefix_rd prd
;
3303 VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg
, rfg
);
3304 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3306 /* make sure it's still in list */
3307 if (!listnode_lookup(bgp
->rfapi_cfg
->nve_groups_sequential
, rfg
)) {
3308 /* Not in list anymore */
3309 vty_out(vty
, "Current NVE group no longer exists\n");
3310 return CMD_WARNING_CONFIG_FAILED
;
3313 if (!strncmp(argv
[1]->arg
, "auto:nh:", 8)) {
3315 * use AF_UNIX to designate automatically-assigned RD
3316 * auto:vn:nn where nn is a 2-octet quantity
3319 uint32_t value32
= strtoul(argv
[1]->arg
+ 8, &end
, 10);
3320 uint16_t value
= value32
& 0xffff;
3322 if (!*(argv
[1]->arg
+ 5) || *end
) {
3323 vty_out(vty
, "%% Malformed rd\n");
3324 return CMD_WARNING_CONFIG_FAILED
;
3326 if (value32
> 0xffff) {
3327 vty_out(vty
, "%% Malformed rd (must be less than %u\n",
3329 return CMD_WARNING_CONFIG_FAILED
;
3332 memset(&prd
, 0, sizeof(prd
));
3333 prd
.family
= AF_UNIX
;
3335 prd
.val
[0] = (RD_TYPE_IP
>> 8) & 0x0ff;
3336 prd
.val
[1] = RD_TYPE_IP
& 0x0ff;
3337 prd
.val
[6] = (value
>> 8) & 0x0ff;
3338 prd
.val
[7] = value
& 0x0ff;
3342 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
3344 vty_out(vty
, "%% Malformed rd\n");
3345 return CMD_WARNING_CONFIG_FAILED
;
3349 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3350 vnc_redistribute_prechange(bgp
);
3355 if (bgp
->rfapi_cfg
->rfg_redist
== rfg
) {
3356 vnc_redistribute_postchange(bgp
);
3361 DEFUN_NOSH (exit_vrf_policy
,
3362 exit_vrf_policy_cmd
,
3364 "Exit VRF policy configuration mode\n")
3366 if (vty
->node
== BGP_VRF_POLICY_NODE
) {
3367 vty
->node
= BGP_NODE
;
3372 static struct cmd_node bgp_vrf_policy_node
= {
3373 BGP_VRF_POLICY_NODE
, "%s(config-router-vrf-policy)# ", 1};
3375 /*-------------------------------------------------------------------------
3377 *-----------------------------------------------------------------------*/
3380 DEFUN_NOSH (vnc_l2_group
,
3382 "vnc l2-group NAME",
3383 VNC_CONFIG_STR
"Configure a L2 group\n" "Group name\n")
3385 struct rfapi_l2_group_cfg
*rfg
;
3386 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3388 /* Search for name */
3389 rfg
= rfapi_l2_group_lookup_byname(bgp
, argv
[2]->arg
);
3392 rfg
= rfapi_l2_group_new();
3394 /* Error out of memory */
3395 vty_out(vty
, "Can't allocate memory for L2 group\n");
3396 return CMD_WARNING_CONFIG_FAILED
;
3398 rfg
->name
= strdup(argv
[2]->arg
);
3399 /* add to tail of list */
3400 listnode_add(bgp
->rfapi_cfg
->l2_groups
, rfg
);
3404 * XXX subsequent calls will need to make sure this item is still
3405 * in the linked list and has the same name
3407 VTY_PUSH_CONTEXT_SUB(BGP_VNC_L2_GROUP_NODE
, rfg
);
3411 static void bgp_rfapi_delete_l2_group(struct vty
*vty
, /* NULL = no output */
3413 struct rfapi_l2_group_cfg
*rfg
)
3417 if (rfg
->rt_import_list
)
3418 ecommunity_free(&rfg
->rt_import_list
);
3419 if (rfg
->rt_export_list
)
3420 ecommunity_free(&rfg
->rt_export_list
);
3422 list_delete_and_null(&rfg
->labels
);
3424 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, rfg
->rfp_cfg
);
3425 listnode_delete(bgp
->rfapi_cfg
->l2_groups
, rfg
);
3427 rfapi_l2_group_del(rfg
);
3431 bgp_rfapi_delete_named_l2_group(struct vty
*vty
, /* NULL = no output */
3433 const char *rfg_name
) /* NULL = any */
3435 struct rfapi_l2_group_cfg
*rfg
= NULL
;
3436 struct listnode
*node
, *nnode
;
3438 /* Search for name */
3440 rfg
= rfapi_l2_group_lookup_byname(bgp
, rfg_name
);
3443 vty_out(vty
, "No L2 group named \"%s\"\n",
3445 return CMD_WARNING_CONFIG_FAILED
;
3450 bgp_rfapi_delete_l2_group(vty
, bgp
, rfg
);
3451 else /* must be delete all */
3452 for (ALL_LIST_ELEMENTS(bgp
->rfapi_cfg
->l2_groups
, node
, nnode
,
3454 bgp_rfapi_delete_l2_group(vty
, bgp
, rfg
);
3458 DEFUN (vnc_no_l2_group
,
3459 vnc_no_l2_group_cmd
,
3460 "no vnc l2-group NAME",
3463 "Configure a L2 group\n"
3466 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3468 return bgp_rfapi_delete_named_l2_group(vty
, bgp
, argv
[3]->arg
);
3472 DEFUN (vnc_l2_group_lni
,
3473 vnc_l2_group_lni_cmd
,
3474 "logical-network-id (0-4294967295)",
3475 "Specify Logical Network ID associated with group\n"
3478 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3479 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3481 /* make sure it's still in list */
3482 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3483 /* Not in list anymore */
3484 vty_out(vty
, "Current L2 group no longer exists\n");
3485 return CMD_WARNING_CONFIG_FAILED
;
3488 rfg
->logical_net_id
= strtoul(argv
[1]->arg
, NULL
, 10);
3493 DEFUN (vnc_l2_group_labels
,
3494 vnc_l2_group_labels_cmd
,
3495 "labels LABELLIST...",
3496 "Specify label values associated with group\n"
3497 "Space separated list of label values <0-1048575>\n")
3499 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3500 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3503 /* make sure it's still in list */
3504 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3505 /* Not in list anymore */
3506 vty_out(vty
, "Current L2 group no longer exists\n");
3507 return CMD_WARNING_CONFIG_FAILED
;
3517 for (; argc
; --argc
, ++argv
) {
3519 label
= strtoul(argv
[0]->arg
, NULL
, 10);
3520 if (!listnode_lookup(ll
, (void *)(uintptr_t)label
))
3521 listnode_add(ll
, (void *)(uintptr_t)label
);
3527 DEFUN (vnc_l2_group_no_labels
,
3528 vnc_l2_group_no_labels_cmd
,
3529 "no labels LABELLIST...",
3531 "Specify label values associated with L2 group\n"
3532 "Space separated list of label values <0-1048575>\n")
3534 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3535 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3538 /* make sure it's still in list */
3539 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3540 /* Not in list anymore */
3541 vty_out(vty
, "Current L2 group no longer exists\n");
3542 return CMD_WARNING_CONFIG_FAILED
;
3547 vty_out(vty
, "Label no longer associated with group\n");
3548 return CMD_WARNING_CONFIG_FAILED
;
3553 for (; argc
; --argc
, ++argv
) {
3555 label
= strtoul(argv
[0]->arg
, NULL
, 10);
3556 listnode_delete(ll
, (void *)(uintptr_t)label
);
3562 DEFUN (vnc_l2_group_rt
,
3563 vnc_l2_group_rt_cmd
,
3564 "rt <both|export|import> ASN:NN_OR_IP-ADDRESS:NN",
3565 "Specify route targets\n"
3566 "Export+import filters\n"
3571 VTY_DECLVAR_CONTEXT_SUB(rfapi_l2_group_cfg
, rfg
);
3572 VTY_DECLVAR_CONTEXT(bgp
, bgp
);
3573 int rc
= CMD_SUCCESS
;
3577 switch (argv
[1]->arg
[0]) {
3579 do_export
= 1; /* fall through */
3587 vty_out(vty
, "Unknown option, %s\n", argv
[1]->arg
);
3588 return CMD_ERR_NO_MATCH
;
3591 /* make sure it's still in list */
3592 if (!listnode_lookup(bgp
->rfapi_cfg
->l2_groups
, rfg
)) {
3593 /* Not in list anymore */
3594 vty_out(vty
, "Current L2 group no longer exists\n");
3595 return CMD_WARNING_CONFIG_FAILED
;
3599 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
3600 &rfg
->rt_import_list
);
3601 if (rc
== CMD_SUCCESS
&& do_export
)
3602 rc
= set_ecom_list(vty
, argc
- 2, argv
+ 2,
3603 &rfg
->rt_export_list
);
3608 static struct cmd_node bgp_vnc_l2_group_node
= {
3609 BGP_VNC_L2_GROUP_NODE
, "%s(config-router-vnc-l2-group)# ", 1};
3611 struct rfapi_l2_group_cfg
*
3612 bgp_rfapi_get_group_by_lni_label(struct bgp
*bgp
, uint32_t logical_net_id
,
3615 struct rfapi_l2_group_cfg
*rfg
;
3616 struct listnode
*node
;
3618 if (bgp
->rfapi_cfg
->l2_groups
== NULL
) /* not the best place for this */
3621 label
= label
& 0xfffff; /* label is 20 bits! */
3623 for (ALL_LIST_ELEMENTS_RO(bgp
->rfapi_cfg
->l2_groups
, node
, rfg
)) {
3624 if (rfg
->logical_net_id
== logical_net_id
) {
3625 struct listnode
*lnode
;
3627 for (ALL_LIST_ELEMENTS_RO(rfg
->labels
, lnode
, data
))
3628 if (((uint32_t)((uintptr_t)data
))
3629 == label
) { /* match! */
3637 struct list
*bgp_rfapi_get_labellist_by_lni_label(struct bgp
*bgp
,
3638 uint32_t logical_net_id
,
3641 struct rfapi_l2_group_cfg
*rfg
;
3642 rfg
= bgp_rfapi_get_group_by_lni_label(bgp
, logical_net_id
, label
);
3650 bgp_rfapi_get_ecommunity_by_lni_label(struct bgp
*bgp
, uint32_t is_import
,
3651 uint32_t logical_net_id
, uint32_t label
)
3653 struct rfapi_l2_group_cfg
*rfg
;
3654 rfg
= bgp_rfapi_get_group_by_lni_label(bgp
, logical_net_id
, label
);
3657 return rfg
->rt_import_list
;
3659 return rfg
->rt_export_list
;
3664 void bgp_rfapi_cfg_init(void)
3666 /* main bgpd code does not use this hook, but vnc does */
3667 route_map_event_hook(vnc_routemap_event
);
3669 install_node(&bgp_vnc_defaults_node
, NULL
);
3670 install_node(&bgp_vnc_nve_group_node
, NULL
);
3671 install_node(&bgp_vrf_policy_node
, NULL
);
3672 install_node(&bgp_vnc_l2_group_node
, NULL
);
3673 install_default(BGP_VRF_POLICY_NODE
);
3674 install_default(BGP_VNC_DEFAULTS_NODE
);
3675 install_default(BGP_VNC_NVE_GROUP_NODE
);
3676 install_default(BGP_VNC_L2_GROUP_NODE
);
3681 install_element(BGP_NODE
, &vnc_defaults_cmd
);
3682 install_element(BGP_NODE
, &vnc_nve_group_cmd
);
3683 install_element(BGP_NODE
, &vnc_no_nve_group_cmd
);
3684 install_element(BGP_NODE
, &vnc_vrf_policy_cmd
);
3685 install_element(BGP_NODE
, &vnc_no_vrf_policy_cmd
);
3686 install_element(BGP_NODE
, &vnc_l2_group_cmd
);
3687 install_element(BGP_NODE
, &vnc_no_l2_group_cmd
);
3688 install_element(BGP_NODE
, &vnc_advertise_un_method_cmd
);
3689 install_element(BGP_NODE
, &vnc_export_mode_cmd
);
3691 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_import_cmd
);
3692 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_export_cmd
);
3693 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rt_both_cmd
);
3694 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_rd_cmd
);
3695 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_l2rd_cmd
);
3696 install_element(BGP_VNC_DEFAULTS_NODE
, &vnc_defaults_no_l2rd_cmd
);
3697 install_element(BGP_VNC_DEFAULTS_NODE
,
3698 &vnc_defaults_responselifetime_cmd
);
3699 install_element(BGP_VNC_DEFAULTS_NODE
, &exit_vnc_cmd
);
3701 install_element(BGP_NODE
, &vnc_redistribute_protocol_cmd
);
3702 install_element(BGP_NODE
, &vnc_no_redistribute_protocol_cmd
);
3703 install_element(BGP_NODE
, &vnc_redistribute_nvegroup_cmd
);
3704 install_element(BGP_NODE
, &vnc_redistribute_no_nvegroup_cmd
);
3705 install_element(BGP_NODE
, &vnc_redistribute_lifetime_cmd
);
3706 install_element(BGP_NODE
, &vnc_redistribute_rh_roo_localadmin_cmd
);
3707 install_element(BGP_NODE
, &vnc_redistribute_mode_cmd
);
3708 install_element(BGP_NODE
, &vnc_redistribute_bgp_exterior_cmd
);
3710 install_element(BGP_NODE
, &vnc_redist_bgpdirect_no_prefixlist_cmd
);
3711 install_element(BGP_NODE
, &vnc_redist_bgpdirect_prefixlist_cmd
);
3712 install_element(BGP_NODE
, &vnc_redist_bgpdirect_no_routemap_cmd
);
3713 install_element(BGP_NODE
, &vnc_redist_bgpdirect_routemap_cmd
);
3715 install_element(BGP_VNC_NVE_GROUP_NODE
,
3716 &vnc_nve_group_redist_bgpdirect_no_prefixlist_cmd
);
3717 install_element(BGP_VNC_NVE_GROUP_NODE
,
3718 &vnc_nve_group_redist_bgpdirect_prefixlist_cmd
);
3719 install_element(BGP_VNC_NVE_GROUP_NODE
,
3720 &vnc_nve_group_redist_bgpdirect_no_routemap_cmd
);
3721 install_element(BGP_VNC_NVE_GROUP_NODE
,
3722 &vnc_nve_group_redist_bgpdirect_routemap_cmd
);
3724 install_element(BGP_NODE
, &vnc_export_nvegroup_cmd
);
3725 install_element(BGP_NODE
, &vnc_no_export_nvegroup_cmd
);
3726 install_element(BGP_NODE
, &vnc_nve_export_prefixlist_cmd
);
3727 install_element(BGP_NODE
, &vnc_nve_export_routemap_cmd
);
3728 install_element(BGP_NODE
, &vnc_nve_export_no_prefixlist_cmd
);
3729 install_element(BGP_NODE
, &vnc_nve_export_no_routemap_cmd
);
3731 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_l2rd_cmd
);
3732 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_no_l2rd_cmd
);
3733 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_prefix_cmd
);
3734 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_import_cmd
);
3735 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_export_cmd
);
3736 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rt_both_cmd
);
3737 install_element(BGP_VNC_NVE_GROUP_NODE
, &vnc_nve_group_rd_cmd
);
3738 install_element(BGP_VNC_NVE_GROUP_NODE
,
3739 &vnc_nve_group_responselifetime_cmd
);
3740 install_element(BGP_VNC_NVE_GROUP_NODE
,
3741 &vnc_nve_group_export_prefixlist_cmd
);
3742 install_element(BGP_VNC_NVE_GROUP_NODE
,
3743 &vnc_nve_group_export_routemap_cmd
);
3744 install_element(BGP_VNC_NVE_GROUP_NODE
,
3745 &vnc_nve_group_export_no_prefixlist_cmd
);
3746 install_element(BGP_VNC_NVE_GROUP_NODE
,
3747 &vnc_nve_group_export_no_routemap_cmd
);
3748 install_element(BGP_VNC_NVE_GROUP_NODE
, &exit_vnc_cmd
);
3750 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_label_cmd
);
3751 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_no_label_cmd
);
3752 // Reenable to support VRF controller use case and testing
3753 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_nexthop_cmd
);
3754 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_import_cmd
);
3755 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_export_cmd
);
3756 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rt_both_cmd
);
3757 install_element(BGP_VRF_POLICY_NODE
, &vnc_vrf_policy_rd_cmd
);
3758 install_element(BGP_VRF_POLICY_NODE
, &exit_vrf_policy_cmd
);
3760 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_lni_cmd
);
3761 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_labels_cmd
);
3762 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_no_labels_cmd
);
3763 install_element(BGP_VNC_L2_GROUP_NODE
, &vnc_l2_group_rt_cmd
);
3764 install_element(BGP_VNC_L2_GROUP_NODE
, &exit_vnc_cmd
);
3767 struct rfapi_cfg
*bgp_rfapi_cfg_new(struct rfapi_rfp_cfg
*cfg
)
3769 struct rfapi_cfg
*h
;
3772 h
= (struct rfapi_cfg
*)XCALLOC(MTYPE_RFAPI_CFG
,
3773 sizeof(struct rfapi_cfg
));
3776 h
->nve_groups_sequential
= list_new();
3777 assert(h
->nve_groups_sequential
);
3778 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
3779 h
->nve_groups_vn
[afi
] = route_table_init();
3780 h
->nve_groups_un
[afi
] = route_table_init();
3782 h
->default_response_lifetime
=
3783 BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT
;
3784 h
->rfg_export_direct_bgp_l
= list_new();
3785 h
->rfg_export_zebra_l
= list_new();
3786 h
->resolve_nve_roo_local_admin
=
3787 BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT
;
3789 SET_FLAG(h
->flags
, BGP_VNC_CONFIG_FLAGS_DEFAULT
);
3792 h
->rfp_cfg
.download_type
= RFAPI_RFP_DOWNLOAD_PARTIAL
;
3793 h
->rfp_cfg
.ftd_advertisement_interval
=
3794 RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL
;
3795 h
->rfp_cfg
.holddown_factor
=
3796 RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR
;
3797 h
->rfp_cfg
.use_updated_response
= 0;
3798 h
->rfp_cfg
.use_removes
= 0;
3800 h
->rfp_cfg
.download_type
= cfg
->download_type
;
3801 h
->rfp_cfg
.ftd_advertisement_interval
=
3802 cfg
->ftd_advertisement_interval
;
3803 h
->rfp_cfg
.holddown_factor
= cfg
->holddown_factor
;
3804 h
->rfp_cfg
.use_updated_response
= cfg
->use_updated_response
;
3805 h
->rfp_cfg
.use_removes
= cfg
->use_removes
;
3806 if (cfg
->use_updated_response
)
3807 h
->flags
&= ~BGP_VNC_CONFIG_CALLBACK_DISABLE
;
3809 h
->flags
|= BGP_VNC_CONFIG_CALLBACK_DISABLE
;
3810 if (cfg
->use_removes
)
3811 h
->flags
&= ~BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE
;
3813 h
->flags
|= BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE
;
3818 void bgp_rfapi_cfg_destroy(struct bgp
*bgp
, struct rfapi_cfg
*h
)
3824 bgp_rfapi_delete_named_nve_group(NULL
, bgp
, NULL
, RFAPI_GROUP_CFG_MAX
);
3825 bgp_rfapi_delete_named_l2_group(NULL
, bgp
, NULL
);
3826 if (h
->l2_groups
!= NULL
)
3827 list_delete_and_null(&h
->l2_groups
);
3828 list_delete_and_null(&h
->nve_groups_sequential
);
3829 list_delete_and_null(&h
->rfg_export_direct_bgp_l
);
3830 list_delete_and_null(&h
->rfg_export_zebra_l
);
3831 if (h
->default_rt_export_list
)
3832 ecommunity_free(&h
->default_rt_export_list
);
3833 if (h
->default_rt_import_list
)
3834 ecommunity_free(&h
->default_rt_import_list
);
3835 if (h
->default_rfp_cfg
)
3836 XFREE(MTYPE_RFAPI_RFP_GROUP_CFG
, h
->default_rfp_cfg
);
3837 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
3838 route_table_finish(h
->nve_groups_vn
[afi
]);
3839 route_table_finish(h
->nve_groups_un
[afi
]);
3841 XFREE(MTYPE_RFAPI_CFG
, h
);
3844 int bgp_rfapi_cfg_write(struct vty
*vty
, struct bgp
*bgp
)
3846 struct listnode
*node
, *nnode
;
3847 struct rfapi_nve_group_cfg
*rfg
;
3848 struct rfapi_cfg
*hc
= bgp
->rfapi_cfg
;
3849 struct rfapi_rfg_name
*rfgn
;
3853 if (bgp
->rfapi
== NULL
|| hc
== NULL
)
3856 vty_out(vty
, "!\n");
3857 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
, rfg
))
3858 if (rfg
->type
== RFAPI_GROUP_CFG_VRF
) {
3860 vty_out(vty
, " vrf-policy %s\n", rfg
->name
);
3861 if (rfg
->label
<= MPLS_LABEL_MAX
) {
3862 vty_out(vty
, " label %u\n", rfg
->label
);
3864 if (CHECK_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
)) {
3865 vty_out(vty
, " nexthop self\n");
3868 if (rfg
->vn_prefix
.family
) {
3870 buf
[0] = buf
[BUFSIZ
- 1] = 0;
3871 inet_ntop(rfg
->vn_prefix
.family
,
3872 &rfg
->vn_prefix
.u
.prefix
, buf
,
3874 if (!buf
[0] || buf
[BUFSIZ
- 1]) {
3875 // vty_out (vty, "nexthop
3878 vty_out(vty
, " nexthop %s\n",
3884 if (rfg
->rd
.prefixlen
) {
3886 buf
[0] = buf
[BUFSIZ
- 1] = 0;
3888 if (AF_UNIX
== rfg
->rd
.family
) {
3892 value
= ((rfg
->rd
.val
[6] << 8)
3894 | (rfg
->rd
.val
[7] & 0x0ff);
3896 vty_out(vty
, " rd auto:nh:%d\n",
3901 if (!prefix_rd2str(&rfg
->rd
, buf
,
3903 || !buf
[0] || buf
[BUFSIZ
- 1]) {
3906 "!Error: Can't convert rd\n");
3908 vty_out(vty
, " rd %s\n", buf
);
3913 if (rfg
->rt_import_list
&& rfg
->rt_export_list
3914 && ecommunity_cmp(rfg
->rt_import_list
,
3915 rfg
->rt_export_list
)) {
3916 char *b
= ecommunity_ecom2str(
3917 rfg
->rt_import_list
,
3918 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3919 ECOMMUNITY_ROUTE_TARGET
);
3920 vty_out(vty
, " rt both %s\n", b
);
3921 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3923 if (rfg
->rt_import_list
) {
3924 char *b
= ecommunity_ecom2str(
3925 rfg
->rt_import_list
,
3926 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3927 ECOMMUNITY_ROUTE_TARGET
);
3928 vty_out(vty
, " rt import %s\n", b
);
3929 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3931 if (rfg
->rt_export_list
) {
3932 char *b
= ecommunity_ecom2str(
3933 rfg
->rt_export_list
,
3934 ECOMMUNITY_FORMAT_ROUTE_MAP
,
3935 ECOMMUNITY_ROUTE_TARGET
);
3936 vty_out(vty
, " rt export %s\n", b
);
3937 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
3942 * route filtering: prefix-lists and route-maps
3944 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
3946 const char *afistr
=
3947 (afi
== AFI_IP
) ? "ipv4" : "ipv6";
3949 if (rfg
->plist_export_bgp_name
[afi
]) {
3951 " export bgp %s prefix-list %s\n",
3953 rfg
->plist_export_bgp_name
3956 if (rfg
->plist_export_zebra_name
[afi
]) {
3958 " export zebra %s prefix-list %s\n",
3960 rfg
->plist_export_zebra_name
3964 * currently we only support redist plists for
3966 * If we later add plist support for
3967 * redistributing other
3968 * protocols, we'll need to loop over protocols
3971 if (rfg
->plist_redist_name
3972 [ZEBRA_ROUTE_BGP_DIRECT
][afi
]) {
3974 " redistribute bgp-direct %s prefix-list %s\n",
3976 rfg
->plist_redist_name
3977 [ZEBRA_ROUTE_BGP_DIRECT
]
3980 if (rfg
->plist_redist_name
3981 [ZEBRA_ROUTE_BGP_DIRECT_EXT
][afi
]) {
3983 " redistribute bgp-direct-to-nve-groups %s prefix-list %s\n",
3985 rfg
->plist_redist_name
3986 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
3991 if (rfg
->routemap_export_bgp_name
) {
3992 vty_out(vty
, " export bgp route-map %s\n",
3993 rfg
->routemap_export_bgp_name
);
3995 if (rfg
->routemap_export_zebra_name
) {
3996 vty_out(vty
, " export zebra route-map %s\n",
3997 rfg
->routemap_export_zebra_name
);
3999 if (rfg
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]) {
4001 " redistribute bgp-direct route-map %s\n",
4002 rfg
->routemap_redist_name
4003 [ZEBRA_ROUTE_BGP_DIRECT
]);
4005 if (rfg
->routemap_redist_name
4006 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]) {
4008 " redistribute bgp-direct-to-nve-groups route-map %s\n",
4009 rfg
->routemap_redist_name
4010 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]);
4012 vty_out(vty
, " exit-vrf-policy\n");
4013 vty_out(vty
, "!\n");
4015 if (hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
) {
4016 vty_out(vty
, " vnc advertise-un-method encap-safi\n");
4020 { /* was based on listen ports */
4021 /* for now allow both old and new */
4022 if (bgp
->rfapi
->rfp_methods
.cfg_cb
)
4023 write
+= (bgp
->rfapi
->rfp_methods
.cfg_cb
)(
4024 vty
, bgp
->rfapi
->rfp
);
4027 vty_out(vty
, "!\n");
4029 if (hc
->l2_groups
) {
4030 struct rfapi_l2_group_cfg
*rfg
= NULL
;
4031 struct listnode
*gnode
;
4032 for (ALL_LIST_ELEMENTS_RO(hc
->l2_groups
, gnode
, rfg
)) {
4033 struct listnode
*lnode
;
4036 vty_out(vty
, " vnc l2-group %s\n", rfg
->name
);
4037 if (rfg
->logical_net_id
!= 0)
4039 " logical-network-id %u\n",
4040 rfg
->logical_net_id
);
4041 if (rfg
->labels
!= NULL
4042 && listhead(rfg
->labels
) != NULL
) {
4043 vty_out(vty
, " labels ");
4044 for (ALL_LIST_ELEMENTS_RO(rfg
->labels
,
4047 vty_out(vty
, "%hu ",
4055 if (rfg
->rt_import_list
&& rfg
->rt_export_list
4056 && ecommunity_cmp(rfg
->rt_import_list
,
4057 rfg
->rt_export_list
)) {
4058 char *b
= ecommunity_ecom2str(
4059 rfg
->rt_import_list
,
4060 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4061 ECOMMUNITY_ROUTE_TARGET
);
4062 vty_out(vty
, " rt both %s\n", b
);
4063 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4065 if (rfg
->rt_import_list
) {
4066 char *b
= ecommunity_ecom2str(
4067 rfg
->rt_import_list
,
4068 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4069 ECOMMUNITY_ROUTE_TARGET
);
4070 vty_out(vty
, " rt import %s\n",
4072 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4074 if (rfg
->rt_export_list
) {
4075 char *b
= ecommunity_ecom2str(
4076 rfg
->rt_export_list
,
4077 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4078 ECOMMUNITY_ROUTE_TARGET
);
4079 vty_out(vty
, " rt export %s\n",
4081 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4084 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4085 write
+= (bgp
->rfapi
->rfp_methods
4087 vty
, bgp
->rfapi
->rfp
,
4088 RFAPI_RFP_CFG_GROUP_L2
,
4089 rfg
->name
, rfg
->rfp_cfg
);
4090 vty_out(vty
, " exit-vnc\n");
4091 vty_out(vty
, "!\n");
4095 if (hc
->default_rd
.prefixlen
|| hc
->default_response_lifetime
4096 || hc
->default_rt_import_list
|| hc
->default_rt_export_list
4097 || hc
->nve_groups_sequential
->count
) {
4101 vty_out(vty
, " vnc defaults\n");
4103 if (hc
->default_rd
.prefixlen
) {
4105 buf
[0] = buf
[BUFSIZ
- 1] = 0;
4107 if (AF_UNIX
== hc
->default_rd
.family
) {
4110 value
= ((hc
->default_rd
.val
[6] << 8)
4112 | (hc
->default_rd
.val
[7]
4115 vty_out(vty
, " rd auto:vn:%d\n",
4120 if (!prefix_rd2str(&hc
->default_rd
, buf
,
4122 || !buf
[0] || buf
[BUFSIZ
- 1]) {
4125 "!Error: Can't convert rd\n");
4127 vty_out(vty
, " rd %s\n", buf
);
4131 if (hc
->default_response_lifetime
) {
4132 vty_out(vty
, " response-lifetime ");
4133 if (hc
->default_response_lifetime
!= UINT32_MAX
)
4135 hc
->default_response_lifetime
);
4137 vty_out(vty
, "infinite");
4140 if (hc
->default_rt_import_list
4141 && hc
->default_rt_export_list
4142 && ecommunity_cmp(hc
->default_rt_import_list
,
4143 hc
->default_rt_export_list
)) {
4144 char *b
= ecommunity_ecom2str(
4145 hc
->default_rt_import_list
,
4146 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4147 ECOMMUNITY_ROUTE_TARGET
);
4148 vty_out(vty
, " rt both %s\n", b
);
4149 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4151 if (hc
->default_rt_import_list
) {
4152 char *b
= ecommunity_ecom2str(
4153 hc
->default_rt_import_list
,
4154 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4155 ECOMMUNITY_ROUTE_TARGET
);
4156 vty_out(vty
, " rt import %s\n", b
);
4157 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4159 if (hc
->default_rt_export_list
) {
4160 char *b
= ecommunity_ecom2str(
4161 hc
->default_rt_export_list
,
4162 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4163 ECOMMUNITY_ROUTE_TARGET
);
4164 vty_out(vty
, " rt export %s\n", b
);
4165 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4168 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4169 write
+= (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)(
4170 vty
, bgp
->rfapi
->rfp
,
4171 RFAPI_RFP_CFG_GROUP_DEFAULT
, NULL
,
4172 bgp
->rfapi_cfg
->default_rfp_cfg
);
4173 vty_out(vty
, " exit-vnc\n");
4174 vty_out(vty
, "!\n");
4177 for (ALL_LIST_ELEMENTS(hc
->nve_groups_sequential
, node
, nnode
,
4179 if (rfg
->type
== RFAPI_GROUP_CFG_NVE
) {
4181 vty_out(vty
, " vnc nve-group %s\n", rfg
->name
);
4183 if (rfg
->vn_prefix
.family
&& rfg
->vn_node
) {
4185 buf
[0] = buf
[BUFSIZ
- 1] = 0;
4187 prefix2str(&rfg
->vn_prefix
, buf
,
4189 if (!buf
[0] || buf
[BUFSIZ
- 1]) {
4191 "!Error: Can't convert prefix\n");
4193 vty_out(vty
, " prefix %s %s\n",
4198 if (rfg
->un_prefix
.family
&& rfg
->un_node
) {
4200 buf
[0] = buf
[BUFSIZ
- 1] = 0;
4201 prefix2str(&rfg
->un_prefix
, buf
,
4203 if (!buf
[0] || buf
[BUFSIZ
- 1]) {
4205 "!Error: Can't convert prefix\n");
4207 vty_out(vty
, " prefix %s %s\n",
4213 if (rfg
->rd
.prefixlen
) {
4215 buf
[0] = buf
[BUFSIZ
- 1] = 0;
4217 if (AF_UNIX
== rfg
->rd
.family
) {
4221 value
= ((rfg
->rd
.val
[6] << 8)
4232 if (!prefix_rd2str(&rfg
->rd
,
4235 || buf
[BUFSIZ
- 1]) {
4238 "!Error: Can't convert rd\n");
4246 if (rfg
->flags
& RFAPI_RFG_RESPONSE_LIFETIME
) {
4247 vty_out(vty
, " response-lifetime ");
4248 if (rfg
->response_lifetime
4251 rfg
->response_lifetime
);
4253 vty_out(vty
, "infinite");
4257 if (rfg
->rt_import_list
&& rfg
->rt_export_list
4258 && ecommunity_cmp(rfg
->rt_import_list
,
4259 rfg
->rt_export_list
)) {
4260 char *b
= ecommunity_ecom2str(
4261 rfg
->rt_import_list
,
4262 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4263 ECOMMUNITY_ROUTE_TARGET
);
4264 vty_out(vty
, " rt both %s\n", b
);
4265 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4267 if (rfg
->rt_import_list
) {
4268 char *b
= ecommunity_ecom2str(
4269 rfg
->rt_import_list
,
4270 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4271 ECOMMUNITY_ROUTE_TARGET
);
4272 vty_out(vty
, " rt import %s\n",
4274 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4276 if (rfg
->rt_export_list
) {
4277 char *b
= ecommunity_ecom2str(
4278 rfg
->rt_export_list
,
4279 ECOMMUNITY_FORMAT_ROUTE_MAP
,
4280 ECOMMUNITY_ROUTE_TARGET
);
4281 vty_out(vty
, " rt export %s\n",
4283 XFREE(MTYPE_ECOMMUNITY_STR
, b
);
4288 * route filtering: prefix-lists and route-maps
4290 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4292 const char *afistr
= (afi
== AFI_IP
)
4296 if (rfg
->plist_export_bgp_name
[afi
]) {
4298 " export bgp %s prefix-list %s\n",
4300 rfg
->plist_export_bgp_name
4303 if (rfg
->plist_export_zebra_name
[afi
]) {
4305 " export zebra %s prefix-list %s\n",
4307 rfg
->plist_export_zebra_name
4311 * currently we only support redist
4312 * plists for bgp-direct.
4313 * If we later add plist support for
4314 * redistributing other
4315 * protocols, we'll need to loop over
4318 if (rfg
->plist_redist_name
4319 [ZEBRA_ROUTE_BGP_DIRECT
]
4322 " redistribute bgp-direct %s prefix-list %s\n",
4324 rfg
->plist_redist_name
4325 [ZEBRA_ROUTE_BGP_DIRECT
]
4328 if (rfg
->plist_redist_name
4329 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4332 " redistribute bgp-direct-to-nve-groups %s prefix-list %s\n",
4334 rfg
->plist_redist_name
4335 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]
4340 if (rfg
->routemap_export_bgp_name
) {
4342 " export bgp route-map %s\n",
4343 rfg
->routemap_export_bgp_name
);
4345 if (rfg
->routemap_export_zebra_name
) {
4347 " export zebra route-map %s\n",
4348 rfg
->routemap_export_zebra_name
);
4350 if (rfg
->routemap_redist_name
4351 [ZEBRA_ROUTE_BGP_DIRECT
]) {
4353 " redistribute bgp-direct route-map %s\n",
4354 rfg
->routemap_redist_name
4355 [ZEBRA_ROUTE_BGP_DIRECT
]);
4357 if (rfg
->routemap_redist_name
4358 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]) {
4360 " redistribute bgp-direct-to-nve-groups route-map %s\n",
4361 rfg
->routemap_redist_name
4362 [ZEBRA_ROUTE_BGP_DIRECT_EXT
]);
4364 if (bgp
->rfapi
->rfp_methods
.cfg_group_cb
)
4365 write
+= (bgp
->rfapi
->rfp_methods
4367 vty
, bgp
->rfapi
->rfp
,
4368 RFAPI_RFP_CFG_GROUP_NVE
,
4369 rfg
->name
, rfg
->rfp_cfg
);
4370 vty_out(vty
, " exit-vnc\n");
4371 vty_out(vty
, "!\n");
4373 } /* have listen ports */
4376 * route export to other protocols
4378 if (VNC_EXPORT_BGP_GRP_ENABLED(hc
)) {
4379 vty_out(vty
, " vnc export bgp mode group-nve\n");
4380 } else if (VNC_EXPORT_BGP_RH_ENABLED(hc
)) {
4381 vty_out(vty
, " vnc export bgp mode registering-nve\n");
4382 } else if (VNC_EXPORT_BGP_CE_ENABLED(hc
)) {
4383 vty_out(vty
, " vnc export bgp mode ce\n");
4386 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(hc
)) {
4387 vty_out(vty
, " vnc export zebra mode group-nve\n");
4388 } else if (VNC_EXPORT_ZEBRA_RH_ENABLED(hc
)) {
4389 vty_out(vty
, " vnc export zebra mode registering-nve\n");
4392 if (hc
->rfg_export_direct_bgp_l
) {
4393 for (ALL_LIST_ELEMENTS(hc
->rfg_export_direct_bgp_l
, node
, nnode
,
4396 vty_out(vty
, " vnc export bgp group-nve group %s\n",
4401 if (hc
->rfg_export_zebra_l
) {
4402 for (ALL_LIST_ELEMENTS(hc
->rfg_export_zebra_l
, node
, nnode
,
4405 vty_out(vty
, " vnc export zebra group-nve group %s\n",
4411 if (hc
->rfg_redist_name
) {
4412 vty_out(vty
, " vnc redistribute nve-group %s\n",
4413 hc
->rfg_redist_name
);
4415 if (hc
->redist_lifetime
) {
4416 vty_out(vty
, " vnc redistribute lifetime %d\n",
4417 hc
->redist_lifetime
);
4419 if (hc
->resolve_nve_roo_local_admin
4420 != BGP_VNC_CONFIG_RESOLVE_NVE_ROO_LOCAL_ADMIN_DEFAULT
) {
4423 " vnc redistribute resolve-nve roo-ec-local-admin %d\n",
4424 hc
->resolve_nve_roo_local_admin
);
4427 if (hc
->redist_mode
) /* ! default */
4431 switch (hc
->redist_mode
) {
4432 case VNC_REDIST_MODE_PLAIN
:
4435 case VNC_REDIST_MODE_RFG
:
4438 case VNC_REDIST_MODE_RESOLVE_NVE
:
4443 vty_out(vty
, " vnc redistribute mode %s\n", s
);
4448 * route filtering: prefix-lists and route-maps
4450 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4452 const char *afistr
= (afi
== AFI_IP
) ? "ipv4" : "ipv6";
4454 if (hc
->plist_export_bgp_name
[afi
]) {
4455 vty_out(vty
, " vnc export bgp %s prefix-list %s\n",
4456 afistr
, hc
->plist_export_bgp_name
[afi
]);
4458 if (hc
->plist_export_zebra_name
[afi
]) {
4459 vty_out(vty
, " vnc export zebra %s prefix-list %s\n",
4460 afistr
, hc
->plist_export_zebra_name
[afi
]);
4462 if (hc
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
][afi
]) {
4464 " vnc redistribute bgp-direct %s prefix-list %s\n",
4466 hc
->plist_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]
4471 if (hc
->routemap_export_bgp_name
) {
4472 vty_out(vty
, " vnc export bgp route-map %s\n",
4473 hc
->routemap_export_bgp_name
);
4475 if (hc
->routemap_export_zebra_name
) {
4476 vty_out(vty
, " vnc export zebra route-map %s\n",
4477 hc
->routemap_export_zebra_name
);
4479 if (hc
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]) {
4480 vty_out(vty
, " vnc redistribute bgp-direct route-map %s\n",
4481 hc
->routemap_redist_name
[ZEBRA_ROUTE_BGP_DIRECT
]);
4484 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4485 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
4486 if (hc
->redist
[afi
][type
]) {
4487 if (type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
4488 && hc
->redist_bgp_exterior_view_name
) {
4490 " vnc redistribute %s %s view %s\n",
4491 ((afi
== AFI_IP
) ? "ipv4"
4493 zebra_route_string(type
),
4494 hc
->redist_bgp_exterior_view_name
);
4497 " vnc redistribute %s %s\n",
4498 ((afi
== AFI_IP
) ? "ipv4"
4500 zebra_route_string(type
));
4508 void bgp_rfapi_show_summary(struct bgp
*bgp
, struct vty
*vty
)
4510 struct rfapi_cfg
*hc
= bgp
->rfapi_cfg
;
4512 int type
, redist
= 0;
4517 vty_out(vty
, "%-39s %-19s %s\n", "VNC Advertise method:",
4518 (hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
4519 ? "Encapsulation SAFI"
4520 : "Tunnel Encap attribute"),
4521 ((hc
->flags
& BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
)
4522 == (BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP
4523 & BGP_VNC_CONFIG_FLAGS_DEFAULT
)
4527 vty_out(vty
, "%-39s ", "Export from VNC:");
4529 * route export to other protocols
4531 if (VNC_EXPORT_BGP_GRP_ENABLED(hc
)) {
4533 vty_out(vty
, "ToBGP Groups={");
4534 if (hc
->rfg_export_direct_bgp_l
) {
4536 struct listnode
*node
, *nnode
;
4537 struct rfapi_rfg_name
*rfgn
;
4538 for (ALL_LIST_ELEMENTS(hc
->rfg_export_direct_bgp_l
,
4539 node
, nnode
, rfgn
)) {
4543 vty_out(vty
, "%s", rfgn
->name
);
4547 } else if (VNC_EXPORT_BGP_RH_ENABLED(hc
)) {
4549 vty_out(vty
, "ToBGP {Registering NVE}");
4550 /* note filters, route-maps not shown */
4551 } else if (VNC_EXPORT_BGP_CE_ENABLED(hc
)) {
4553 vty_out(vty
, "ToBGP {NVE connected router:%d}",
4554 hc
->resolve_nve_roo_local_admin
);
4555 /* note filters, route-maps not shown */
4558 if (VNC_EXPORT_ZEBRA_GRP_ENABLED(hc
)) {
4560 vty_out(vty
, "%sToZebra Groups={", (redist
== 1 ? "" : " "));
4561 if (hc
->rfg_export_direct_bgp_l
) {
4563 struct listnode
*node
, *nnode
;
4564 struct rfapi_rfg_name
*rfgn
;
4565 for (ALL_LIST_ELEMENTS(hc
->rfg_export_zebra_l
, node
,
4569 vty_out(vty
, "%s", rfgn
->name
);
4573 } else if (VNC_EXPORT_ZEBRA_RH_ENABLED(hc
)) {
4575 vty_out(vty
, "%sToZebra {Registering NVE}",
4576 (redist
== 1 ? "" : " "));
4577 /* note filters, route-maps not shown */
4579 vty_out(vty
, "%-19s %s\n", (redist
? "" : "Off"),
4580 (redist
? "" : "(default)"));
4582 /* Redistribution */
4584 vty_out(vty
, "%-39s ", "Redistribution into VNC:");
4585 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
) {
4586 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; ++type
) {
4587 if (hc
->redist
[afi
][type
]) {
4588 vty_out(vty
, "{%s,%s} ",
4589 ((afi
== AFI_IP
) ? "ipv4" : "ipv6"),
4590 zebra_route_string(type
));
4595 vty_out(vty
, "%-19s %s\n", (redist
? "" : "Off"),
4596 (redist
? "" : "(default)"));
4598 vty_out(vty
, "%-39s %3u%-16s %s\n",
4599 "RFP Registration Hold-Down Factor:",
4600 hc
->rfp_cfg
.holddown_factor
, "%",
4601 (hc
->rfp_cfg
.holddown_factor
4602 == RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR
4605 vty_out(vty
, "%-39s %-19s %s\n", "RFP Updated responses:",
4606 (hc
->rfp_cfg
.use_updated_response
== 0 ? "Off" : "On"),
4607 (hc
->rfp_cfg
.use_updated_response
== 0 ? "(default)" : ""));
4608 vty_out(vty
, "%-39s %-19s %s\n", "RFP Removal responses:",
4609 (hc
->rfp_cfg
.use_removes
== 0 ? "Off" : "On"),
4610 (hc
->rfp_cfg
.use_removes
== 0 ? "(default)" : ""));
4611 vty_out(vty
, "%-39s %-19s %s\n", "RFP Full table download:",
4612 (hc
->rfp_cfg
.download_type
== RFAPI_RFP_DOWNLOAD_FULL
? "On"
4614 (hc
->rfp_cfg
.download_type
== RFAPI_RFP_DOWNLOAD_PARTIAL
4617 sprintf(tmp
, "%u seconds", hc
->rfp_cfg
.ftd_advertisement_interval
);
4618 vty_out(vty
, "%-39s %-19s %s\n", " Advertisement Interval:", tmp
,
4619 (hc
->rfp_cfg
.ftd_advertisement_interval
4620 == RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL
4623 vty_out(vty
, "%-39s %d seconds\n", "Default RFP response lifetime:",
4624 hc
->default_response_lifetime
);
4629 struct rfapi_cfg
*bgp_rfapi_get_config(struct bgp
*bgp
)
4631 struct rfapi_cfg
*hc
= NULL
;
4633 bgp
= bgp_get_default();
4635 hc
= bgp
->rfapi_cfg
;
4639 #endif /* ENABLE_BGP_VNC */