1 /* Ethernet-VPN Packet and vty Processing File
2 * Copyright (C) 2017 6WIND
4 * This file is part of FRRouting
6 * FRRouting is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * FRRouting is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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
25 #include "lib/printfrr.h"
26 #include "lib/vxlan.h"
29 #include "bgpd/bgpd.h"
30 #include "bgpd/bgp_table.h"
31 #include "bgpd/bgp_attr.h"
32 #include "bgpd/bgp_route.h"
33 #include "bgpd/bgp_mplsvpn.h"
34 #include "bgpd/bgp_vpn.h"
35 #include "bgpd/bgp_evpn_vty.h"
36 #include "bgpd/bgp_evpn.h"
37 #include "bgpd/bgp_evpn_private.h"
38 #include "bgpd/bgp_evpn_mh.h"
39 #include "bgpd/bgp_zebra.h"
40 #include "bgpd/bgp_vty.h"
41 #include "bgpd/bgp_errors.h"
42 #include "bgpd/bgp_ecommunity.h"
43 #include "bgpd/bgp_lcommunity.h"
44 #include "bgpd/bgp_community.h"
46 #define SHOW_DISPLAY_STANDARD 0
47 #define SHOW_DISPLAY_TAGS 1
48 #define SHOW_DISPLAY_OVERLAY 2
49 #define VNI_STR_LEN 32
52 * Context for VNI hash walk - used by callbacks.
57 struct in_addr vtep_ip
;
64 int argv_find_and_parse_oly_idx(struct cmd_token
**argv
, int argc
, int *oly_idx
,
65 enum overlay_index_type
*oly
)
67 *oly
= OVERLAY_INDEX_TYPE_NONE
;
68 if (argv_find(argv
, argc
, "gateway-ip", oly_idx
))
69 *oly
= OVERLAY_INDEX_GATEWAY_IP
;
73 static void display_vrf_import_rt(struct vty
*vty
, struct vrf_irt_node
*irt
,
77 uint8_t type
, sub_type
;
78 struct ecommunity_as eas
;
79 struct ecommunity_ip eip
;
80 struct listnode
*node
, *nnode
;
81 struct bgp
*tmp_bgp_vrf
= NULL
;
82 json_object
*json_rt
= NULL
;
83 json_object
*json_vrfs
= NULL
;
84 char rt_buf
[RT_ADDRSTRLEN
];
87 json_rt
= json_object_new_object();
88 json_vrfs
= json_object_new_array();
91 pnt
= (uint8_t *)&irt
->rt
.val
;
94 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
97 memset(&eas
, 0, sizeof(eas
));
99 case ECOMMUNITY_ENCODE_AS
:
100 eas
.as
= (*pnt
++ << 8);
102 ptr_get_be32(pnt
, &eas
.val
);
104 snprintf(rt_buf
, sizeof(rt_buf
), "%u:%u", eas
.as
, eas
.val
);
107 json_object_string_add(json_rt
, "rt", rt_buf
);
109 vty_out(vty
, "Route-target: %s", rt_buf
);
113 case ECOMMUNITY_ENCODE_IP
:
114 memcpy(&eip
.ip
, pnt
, 4);
116 eip
.val
= (*pnt
++ << 8);
119 snprintfrr(rt_buf
, sizeof(rt_buf
), "%pI4:%u", &eip
.ip
, eip
.val
);
122 json_object_string_add(json_rt
, "rt", rt_buf
);
124 vty_out(vty
, "Route-target: %s", rt_buf
);
128 case ECOMMUNITY_ENCODE_AS4
:
129 pnt
= ptr_get_be32(pnt
, &eas
.val
);
130 eas
.val
= (*pnt
++ << 8);
133 snprintf(rt_buf
, sizeof(rt_buf
), "%u:%u", eas
.as
, eas
.val
);
136 json_object_string_add(json_rt
, "rt", rt_buf
);
138 vty_out(vty
, "Route-target: %s", rt_buf
);
148 "\nList of VRFs importing routes with this route-target:\n");
151 for (ALL_LIST_ELEMENTS(irt
->vrfs
, node
, nnode
, tmp_bgp_vrf
)) {
153 json_object_array_add(
155 json_object_new_string(
156 vrf_id_to_name(tmp_bgp_vrf
->vrf_id
)));
158 vty_out(vty
, " %s\n",
159 vrf_id_to_name(tmp_bgp_vrf
->vrf_id
));
163 json_object_object_add(json_rt
, "vrfs", json_vrfs
);
164 json_object_object_add(json
, rt_buf
, json_rt
);
168 static void show_vrf_import_rt_entry(struct hash_bucket
*bucket
, void *args
[])
170 json_object
*json
= NULL
;
171 struct vty
*vty
= NULL
;
172 struct vrf_irt_node
*irt
= (struct vrf_irt_node
*)bucket
->data
;
174 vty
= (struct vty
*)args
[0];
175 json
= (struct json_object
*)args
[1];
177 display_vrf_import_rt(vty
, irt
, json
);
180 static void display_import_rt(struct vty
*vty
, struct irt_node
*irt
,
184 uint8_t type
, sub_type
;
185 struct ecommunity_as eas
;
186 struct ecommunity_ip eip
;
187 struct listnode
*node
, *nnode
;
188 struct bgpevpn
*tmp_vpn
;
189 json_object
*json_rt
= NULL
;
190 json_object
*json_vnis
= NULL
;
191 char rt_buf
[RT_ADDRSTRLEN
];
194 json_rt
= json_object_new_object();
195 json_vnis
= json_object_new_array();
198 /* TODO: This needs to go into a function */
200 pnt
= (uint8_t *)&irt
->rt
.val
;
203 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
206 memset(&eas
, 0, sizeof(eas
));
208 case ECOMMUNITY_ENCODE_AS
:
209 eas
.as
= (*pnt
++ << 8);
211 ptr_get_be32(pnt
, &eas
.val
);
213 snprintf(rt_buf
, sizeof(rt_buf
), "%u:%u", eas
.as
, eas
.val
);
216 json_object_string_add(json_rt
, "rt", rt_buf
);
218 vty_out(vty
, "Route-target: %s", rt_buf
);
222 case ECOMMUNITY_ENCODE_IP
:
223 memcpy(&eip
.ip
, pnt
, 4);
225 eip
.val
= (*pnt
++ << 8);
228 snprintfrr(rt_buf
, sizeof(rt_buf
), "%pI4:%u", &eip
.ip
, eip
.val
);
231 json_object_string_add(json_rt
, "rt", rt_buf
);
233 vty_out(vty
, "Route-target: %s", rt_buf
);
237 case ECOMMUNITY_ENCODE_AS4
:
238 pnt
= ptr_get_be32(pnt
, &eas
.val
);
239 eas
.val
= (*pnt
++ << 8);
242 snprintf(rt_buf
, sizeof(rt_buf
), "%u:%u", eas
.as
, eas
.val
);
245 json_object_string_add(json_rt
, "rt", rt_buf
);
247 vty_out(vty
, "Route-target: %s", rt_buf
);
257 "\nList of VNIs importing routes with this route-target:\n");
260 for (ALL_LIST_ELEMENTS(irt
->vnis
, node
, nnode
, tmp_vpn
)) {
262 json_object_array_add(
263 json_vnis
, json_object_new_int(tmp_vpn
->vni
));
265 vty_out(vty
, " %u\n", tmp_vpn
->vni
);
269 json_object_object_add(json_rt
, "vnis", json_vnis
);
270 json_object_object_add(json
, rt_buf
, json_rt
);
274 static void show_import_rt_entry(struct hash_bucket
*bucket
, void *args
[])
276 json_object
*json
= NULL
;
277 struct vty
*vty
= NULL
;
278 struct irt_node
*irt
= (struct irt_node
*)bucket
->data
;
283 display_import_rt(vty
, irt
, json
);
288 static void bgp_evpn_show_route_rd_header(struct vty
*vty
,
289 struct bgp_dest
*rd_dest
,
290 json_object
*json
, char *rd_str
,
297 const struct prefix
*p
= bgp_dest_get_prefix(rd_dest
);
301 /* Decode RD type. */
302 type
= decode_rd_type(pnt
);
305 vty_out(vty
, "Route Distinguisher: ");
309 decode_rd_as(pnt
+ 2, &rd_as
);
310 snprintf(rd_str
, len
, "%u:%d", rd_as
.as
, rd_as
.val
);
312 json_object_string_add(json
, "rd", rd_str
);
314 vty_out(vty
, "%s\n", rd_str
);
318 decode_rd_as4(pnt
+ 2, &rd_as
);
319 snprintf(rd_str
, len
, "%u:%d", rd_as
.as
, rd_as
.val
);
321 json_object_string_add(json
, "rd", rd_str
);
323 vty_out(vty
, "%s\n", rd_str
);
327 decode_rd_ip(pnt
+ 2, &rd_ip
);
328 snprintfrr(rd_str
, len
, "%pI4:%d", &rd_ip
.ip
, rd_ip
.val
);
330 json_object_string_add(json
, "rd", rd_str
);
332 vty_out(vty
, "%s\n", rd_str
);
337 snprintf(rd_str
, len
, "Unknown");
338 json_object_string_add(json
, "rd", rd_str
);
340 snprintf(rd_str
, len
, "Unknown RD type");
341 vty_out(vty
, "%s\n", rd_str
);
347 static void bgp_evpn_show_route_header(struct vty
*vty
, struct bgp
*bgp
,
348 uint64_t tbl_ver
, json_object
*json
)
351 " Network Next Hop Metric LocPrf Weight Path\n";
357 "BGP table version is %" PRIu64
", local router ID is %pI4\n",
358 tbl_ver
, &bgp
->router_id
);
360 "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal\n");
361 vty_out(vty
, "Origin codes: i - IGP, e - EGP, ? - incomplete\n");
363 "EVPN type-1 prefix: [1]:[EthTag]:[ESI]:[IPlen]:[VTEP-IP]:[Frag-id]\n");
365 "EVPN type-2 prefix: [2]:[EthTag]:[MAClen]:[MAC]:[IPlen]:[IP]\n");
366 vty_out(vty
, "EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP]\n");
367 vty_out(vty
, "EVPN type-4 prefix: [4]:[ESI]:[IPlen]:[OrigIP]\n");
368 vty_out(vty
, "EVPN type-5 prefix: [5]:[EthTag]:[IPlen]:[IP]\n\n");
369 vty_out(vty
, "%s", ri_header
);
372 static void display_l3vni(struct vty
*vty
, struct bgp
*bgp_vrf
,
376 struct listnode
*node
, *nnode
;
377 struct vrf_route_target
*l3rt
;
378 json_object
*json_import_rtl
= NULL
;
379 json_object
*json_export_rtl
= NULL
;
380 char buf2
[ETHER_ADDR_STRLEN
];
382 json_import_rtl
= json_export_rtl
= 0;
385 json_import_rtl
= json_object_new_array();
386 json_export_rtl
= json_object_new_array();
387 json_object_int_add(json
, "vni", bgp_vrf
->l3vni
);
388 json_object_string_add(json
, "type", "L3");
389 json_object_string_add(json
, "inKernel", "True");
390 json_object_string_addf(json
, "rd", "%pRD", &bgp_vrf
->vrf_prd
);
391 json_object_string_addf(json
, "originatorIp", "%pI4",
392 &bgp_vrf
->originator_ip
);
393 json_object_string_add(json
, "advertiseGatewayMacip", "n/a");
394 json_object_string_add(json
, "advertiseSviMacIp", "n/a");
395 json_object_string_add(json
, "advertisePip",
396 bgp_vrf
->evpn_info
->advertise_pip
?
397 "Enabled" : "Disabled");
398 json_object_string_addf(json
, "sysIP", "%pI4",
399 &bgp_vrf
->evpn_info
->pip_ip
);
400 json_object_string_add(json
, "sysMac",
401 prefix_mac2str(&bgp_vrf
->evpn_info
->pip_rmac
,
402 buf2
, sizeof(buf2
)));
403 json_object_string_add(json
, "rmac",
404 prefix_mac2str(&bgp_vrf
->rmac
,
405 buf2
, sizeof(buf2
)));
407 vty_out(vty
, "VNI: %d", bgp_vrf
->l3vni
);
408 vty_out(vty
, " (known to the kernel)");
411 vty_out(vty
, " Type: %s\n", "L3");
412 vty_out(vty
, " Tenant VRF: %s\n",
413 vrf_id_to_name(bgp_vrf
->vrf_id
));
414 vty_out(vty
, " RD: %pRD\n", &bgp_vrf
->vrf_prd
);
415 vty_out(vty
, " Originator IP: %pI4\n",
416 &bgp_vrf
->originator_ip
);
417 vty_out(vty
, " Advertise-gw-macip : %s\n", "n/a");
418 vty_out(vty
, " Advertise-svi-macip : %s\n", "n/a");
419 vty_out(vty
, " Advertise-pip: %s\n",
420 bgp_vrf
->evpn_info
->advertise_pip
? "Yes" : "No");
421 vty_out(vty
, " System-IP: %pI4\n",
422 &bgp_vrf
->evpn_info
->pip_ip
);
423 vty_out(vty
, " System-MAC: %s\n",
424 prefix_mac2str(&bgp_vrf
->evpn_info
->pip_rmac
,
425 buf2
, sizeof(buf2
)));
426 vty_out(vty
, " Router-MAC: %s\n",
427 prefix_mac2str(&bgp_vrf
->rmac
,
428 buf2
, sizeof(buf2
)));
432 vty_out(vty
, " Import Route Target:\n");
434 for (ALL_LIST_ELEMENTS(bgp_vrf
->vrf_import_rtl
, node
, nnode
, l3rt
)) {
435 ecom_str
= ecommunity_ecom2str(l3rt
->ecom
,
436 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
439 json_object_array_add(json_import_rtl
,
440 json_object_new_string(ecom_str
));
442 vty_out(vty
, " %s\n", ecom_str
);
444 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
448 json_object_object_add(json
, "importRts", json_import_rtl
);
450 vty_out(vty
, " Export Route Target:\n");
452 for (ALL_LIST_ELEMENTS(bgp_vrf
->vrf_export_rtl
, node
, nnode
, l3rt
)) {
453 ecom_str
= ecommunity_ecom2str(l3rt
->ecom
,
454 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
457 json_object_array_add(json_export_rtl
,
458 json_object_new_string(ecom_str
));
460 vty_out(vty
, " %s\n", ecom_str
);
462 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
466 json_object_object_add(json
, "exportRts", json_export_rtl
);
469 static void display_vni(struct vty
*vty
, struct bgpevpn
*vpn
, json_object
*json
)
472 struct listnode
*node
, *nnode
;
473 struct ecommunity
*ecom
;
474 json_object
*json_import_rtl
= NULL
;
475 json_object
*json_export_rtl
= NULL
;
476 struct bgp
*bgp_evpn
;
478 bgp_evpn
= bgp_get_evpn();
481 json_import_rtl
= json_object_new_array();
482 json_export_rtl
= json_object_new_array();
483 json_object_int_add(json
, "vni", vpn
->vni
);
484 json_object_string_add(json
, "type", "L2");
485 json_object_string_add(json
, "inKernel",
486 is_vni_live(vpn
) ? "True" : "False");
487 json_object_string_addf(json
, "rd", "%pRD", &vpn
->prd
);
488 json_object_string_addf(json
, "originatorIp", "%pI4",
489 &vpn
->originator_ip
);
490 json_object_string_addf(json
, "mcastGroup", "%pI4",
492 /* per vni knob is enabled -- Enabled
493 * Global knob is enabled -- Active
494 * default -- Disabled
496 if (!vpn
->advertise_gw_macip
&&
497 bgp_evpn
&& bgp_evpn
->advertise_gw_macip
)
498 json_object_string_add(json
, "advertiseGatewayMacip",
500 else if (vpn
->advertise_gw_macip
)
501 json_object_string_add(json
, "advertiseGatewayMacip",
504 json_object_string_add(json
, "advertiseGatewayMacip",
506 if (!vpn
->advertise_svi_macip
&& bgp_evpn
&&
507 bgp_evpn
->evpn_info
->advertise_svi_macip
)
508 json_object_string_add(json
, "advertiseSviMacIp",
510 else if (vpn
->advertise_svi_macip
)
511 json_object_string_add(json
, "advertiseSviMacIp",
514 json_object_string_add(json
, "advertiseSviMacIp",
516 json_object_string_add(
517 json
, "sviInterface",
518 ifindex2ifname(vpn
->svi_ifindex
, vpn
->tenant_vrf_id
));
520 vty_out(vty
, "VNI: %u", vpn
->vni
);
521 if (is_vni_live(vpn
))
522 vty_out(vty
, " (known to the kernel)");
525 vty_out(vty
, " Type: %s\n", "L2");
526 vty_out(vty
, " Tenant-Vrf: %s\n",
527 vrf_id_to_name(vpn
->tenant_vrf_id
));
528 vty_out(vty
, " RD: %pRD\n", &vpn
->prd
);
529 vty_out(vty
, " Originator IP: %pI4\n", &vpn
->originator_ip
);
530 vty_out(vty
, " Mcast group: %pI4\n", &vpn
->mcast_grp
);
531 if (!vpn
->advertise_gw_macip
&&
532 bgp_evpn
&& bgp_evpn
->advertise_gw_macip
)
533 vty_out(vty
, " Advertise-gw-macip : %s\n",
535 else if (vpn
->advertise_gw_macip
)
536 vty_out(vty
, " Advertise-gw-macip : %s\n",
539 vty_out(vty
, " Advertise-gw-macip : %s\n",
541 if (!vpn
->advertise_svi_macip
&& bgp_evpn
&&
542 bgp_evpn
->evpn_info
->advertise_svi_macip
)
543 vty_out(vty
, " Advertise-svi-macip : %s\n",
545 else if (vpn
->advertise_svi_macip
)
546 vty_out(vty
, " Advertise-svi-macip : %s\n",
549 vty_out(vty
, " Advertise-svi-macip : %s\n",
551 vty_out(vty
, " SVI interface : %s\n",
552 ifindex2ifname(vpn
->svi_ifindex
, vpn
->tenant_vrf_id
));
556 vty_out(vty
, " Import Route Target:\n");
558 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
559 ecom_str
= ecommunity_ecom2str(ecom
,
560 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
563 json_object_array_add(json_import_rtl
,
564 json_object_new_string(ecom_str
));
566 vty_out(vty
, " %s\n", ecom_str
);
568 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
572 json_object_object_add(json
, "importRts", json_import_rtl
);
574 vty_out(vty
, " Export Route Target:\n");
576 for (ALL_LIST_ELEMENTS(vpn
->export_rtl
, node
, nnode
, ecom
)) {
577 ecom_str
= ecommunity_ecom2str(ecom
,
578 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
581 json_object_array_add(json_export_rtl
,
582 json_object_new_string(ecom_str
));
584 vty_out(vty
, " %s\n", ecom_str
);
586 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
590 json_object_object_add(json
, "exportRts", json_export_rtl
);
593 static void show_esi_routes(struct bgp
*bgp
,
594 struct bgp_evpn_es
*es
,
599 struct bgp_dest
*dest
;
600 struct bgp_path_info
*pi
;
601 uint32_t prefix_cnt
, path_cnt
;
604 prefix_cnt
= path_cnt
= 0;
606 tbl_ver
= es
->route_table
->version
;
607 for (dest
= bgp_table_top(es
->route_table
); dest
;
608 dest
= bgp_route_next(dest
)) {
609 int add_prefix_to_json
= 0;
610 json_object
*json_paths
= NULL
;
611 json_object
*json_prefix
= NULL
;
612 const struct prefix
*p
= bgp_dest_get_prefix(dest
);
615 json_prefix
= json_object_new_object();
617 pi
= bgp_dest_get_bgp_path_info(dest
);
619 /* Overall header/legend displayed once. */
621 bgp_evpn_show_route_header(vty
, bgp
,
630 json_paths
= json_object_new_array();
632 /* For EVPN, the prefix is displayed for each path (to fit in
633 * with code that already exists).
635 for (; pi
; pi
= pi
->next
) {
636 json_object
*json_path
= NULL
;
639 json_path
= json_object_new_array();
641 route_vty_out(vty
, p
, pi
, 0, SAFI_EVPN
, json_path
,
645 json_object_array_add(json_paths
, json_path
);
648 add_prefix_to_json
= 1;
652 if (add_prefix_to_json
) {
653 json_object_string_addf(json_prefix
, "prefix",
655 json_object_int_add(json_prefix
, "prefixLen",
657 json_object_object_add(json_prefix
, "paths",
659 json_object_object_addf(json
, json_prefix
,
662 json_object_free(json_paths
);
663 json_object_free(json_prefix
);
671 json_object_int_add(json
, "numPrefix", prefix_cnt
);
672 json_object_int_add(json
, "numPaths", path_cnt
);
675 vty_out(vty
, "No EVPN prefixes exist for this ESI\n");
677 vty_out(vty
, "\nDisplayed %u prefixes (%u paths)\n",
678 prefix_cnt
, path_cnt
);
682 /* Display all MAC-IP VNI routes linked to an ES */
683 static void bgp_evpn_show_routes_mac_ip_es(struct vty
*vty
, esi_t
*esi
,
684 json_object
*json
, int detail
,
688 struct bgp_path_info
*pi
;
689 int header
= detail
? 0 : 1;
691 struct listnode
*node
;
692 struct bgp_evpn_es
*es
;
693 struct bgp_path_es_info
*es_info
;
694 struct bgp
*bgp
= bgp_get_evpn();
695 json_object
*json_paths
= NULL
;
703 json_paths
= json_object_new_array();
705 RB_FOREACH (es
, bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
) {
706 struct list
*es_list
;
708 if (esi
&& memcmp(esi
, &es
->esi
, sizeof(*esi
)))
712 es_list
= es
->macip_global_path_list
;
714 es_list
= es
->macip_evi_path_list
;
716 for (ALL_LIST_ELEMENTS_RO(es_list
, node
, es_info
)) {
717 json_object
*json_path
= NULL
;
722 if (!CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
))
725 /* Overall header/legend displayed once. */
727 bgp_evpn_show_route_header(vty
, bgp
, 0, json
);
734 json_path
= json_object_new_array();
737 route_vty_out_detail(
738 vty
, bgp
, rn
, bgp_dest_get_prefix(rn
),
739 pi
, AFI_L2VPN
, SAFI_EVPN
,
740 RPKI_NOT_BEING_USED
, json_path
);
742 route_vty_out(vty
, &rn
->p
, pi
, 0, SAFI_EVPN
,
746 json_object_array_add(json_paths
, json_path
);
751 json_object_object_add(json
, "paths", json_paths
);
752 json_object_int_add(json
, "numPaths", path_cnt
);
755 vty_out(vty
, "There are no MAC-IP ES paths");
757 vty_out(vty
, "\nDisplayed %u paths\n", path_cnt
);
762 static void bgp_evpn_show_routes_mac_ip_evi_es(struct vty
*vty
, esi_t
*esi
,
763 json_object
*json
, int detail
)
765 bgp_evpn_show_routes_mac_ip_es(vty
, esi
, json
, detail
, false);
768 static void bgp_evpn_show_routes_mac_ip_global_es(struct vty
*vty
, esi_t
*esi
,
769 json_object
*json
, int detail
)
771 bgp_evpn_show_routes_mac_ip_es(vty
, esi
, json
, detail
, true);
774 static void show_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
,
775 struct vty
*vty
, int type
, bool mac_table
,
776 struct in_addr vtep_ip
, json_object
*json
,
779 struct bgp_dest
*dest
;
780 struct bgp_path_info
*pi
;
781 struct bgp_table
*table
;
782 int header
= detail
? 0 : 1;
784 uint32_t prefix_cnt
, path_cnt
;
786 prefix_cnt
= path_cnt
= 0;
789 table
= vpn
->mac_table
;
791 table
= vpn
->ip_table
;
793 tbl_ver
= table
->version
;
794 for (dest
= bgp_table_top(table
); dest
; dest
= bgp_route_next(dest
)) {
795 const struct prefix_evpn
*evp
=
796 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
797 int add_prefix_to_json
= 0;
798 json_object
*json_paths
= NULL
;
799 json_object
*json_prefix
= NULL
;
800 const struct prefix
*p
= bgp_dest_get_prefix(dest
);
802 if (type
&& evp
->prefix
.route_type
!= type
)
806 json_prefix
= json_object_new_object();
808 pi
= bgp_dest_get_bgp_path_info(dest
);
810 /* Overall header/legend displayed once. */
812 bgp_evpn_show_route_header(vty
, bgp
,
821 json_paths
= json_object_new_array();
823 /* For EVPN, the prefix is displayed for each path (to fit in
824 * with code that already exists).
826 for (; pi
; pi
= pi
->next
) {
828 json_object
*json_path
= NULL
;
830 if (vtep_ip
.s_addr
!= INADDR_ANY
831 && !IPV4_ADDR_SAME(&(vtep_ip
),
832 &(pi
->attr
->nexthop
)))
835 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
837 * VNI IP/MAC table prefixes don't have MAC/IP
838 * respectively so make sure it's set from path
841 if (is_evpn_prefix_ipaddr_none(evp
)) {
842 /* VNI MAC -> Global */
843 evpn_type2_prefix_global_copy(
844 (struct prefix_evpn
*)&tmp_p
,
846 evpn_type2_path_info_get_ip(
849 /* VNI IP -> Global */
850 evpn_type2_prefix_global_copy(
851 (struct prefix_evpn
*)&tmp_p
,
853 evpn_type2_path_info_get_mac(
858 memcpy(&tmp_p
, p
, sizeof(tmp_p
));
862 json_path
= json_object_new_array();
865 route_vty_out_detail(vty
, bgp
, dest
, &tmp_p
, pi
,
866 AFI_L2VPN
, SAFI_EVPN
,
871 route_vty_out(vty
, &tmp_p
, pi
, 0, SAFI_EVPN
,
875 json_object_array_add(json_paths
, json_path
);
878 add_prefix_to_json
= 1;
882 if (add_prefix_to_json
) {
883 json_object_string_addf(json_prefix
, "prefix",
885 json_object_int_add(json_prefix
, "prefixLen",
887 json_object_object_add(json_prefix
, "paths",
889 json_object_object_addf(json
, json_prefix
,
892 json_object_free(json_paths
);
893 json_object_free(json_prefix
);
901 json_object_int_add(json
, "numPrefix", prefix_cnt
);
902 json_object_int_add(json
, "numPaths", path_cnt
);
905 vty_out(vty
, "No EVPN prefixes %sexist for this VNI",
906 type
? "(of requested type) " : "");
908 vty_out(vty
, "\nDisplayed %u prefixes (%u paths)%s\n",
909 prefix_cnt
, path_cnt
,
910 type
? " (of requested type)" : "");
915 static void show_vni_routes_hash(struct hash_bucket
*bucket
, void *arg
)
917 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
918 struct vni_walk_ctx
*wctx
= arg
;
919 struct vty
*vty
= wctx
->vty
;
920 json_object
*json
= wctx
->json
;
921 json_object
*json_vni
= NULL
;
922 char vni_str
[VNI_STR_LEN
];
924 snprintf(vni_str
, sizeof(vni_str
), "%u", vpn
->vni
);
926 json_vni
= json_object_new_object();
927 json_object_int_add(json_vni
, "vni", vpn
->vni
);
929 vty_out(vty
, "\nVNI: %u\n\n", vpn
->vni
);
932 show_vni_routes(wctx
->bgp
, vpn
, wctx
->vty
, wctx
->type
, wctx
->mac_table
,
933 wctx
->vtep_ip
, json_vni
, wctx
->detail
);
936 json_object_object_add(json
, vni_str
, json_vni
);
939 static void show_vni_routes_all_hash(struct hash_bucket
*bucket
, void *arg
)
941 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
942 struct vni_walk_ctx
*wctx
= arg
;
943 struct vty
*vty
= wctx
->vty
;
944 json_object
*json
= wctx
->json
;
945 json_object
*json_vni
= NULL
;
946 json_object
*json_vni_mac
= NULL
;
947 char vni_str
[VNI_STR_LEN
];
949 snprintf(vni_str
, sizeof(vni_str
), "%u", vpn
->vni
);
951 json_vni
= json_object_new_object();
952 json_object_int_add(json_vni
, "vni", vpn
->vni
);
954 vty_out(vty
, "\nVNI: %u\n\n", vpn
->vni
);
957 show_vni_routes(wctx
->bgp
, vpn
, wctx
->vty
, 0, false, wctx
->vtep_ip
,
958 json_vni
, wctx
->detail
);
961 json_object_object_add(json
, vni_str
, json_vni
);
964 json_vni_mac
= json_object_new_object();
966 vty_out(vty
, "\nVNI: %u MAC Table\n\n", vpn
->vni
);
968 show_vni_routes(wctx
->bgp
, vpn
, wctx
->vty
, 0, true, wctx
->vtep_ip
,
969 json_vni_mac
, wctx
->detail
);
972 json_object_object_add(json_vni
, "macTable", json_vni_mac
);
975 static void show_l3vni_entry(struct vty
*vty
, struct bgp
*bgp
,
978 json_object
*json_vni
= NULL
;
979 json_object
*json_import_rtl
= NULL
;
980 json_object
*json_export_rtl
= NULL
;
982 char buf2
[INET6_ADDRSTRLEN
];
985 struct listnode
*node
, *nnode
;
986 struct vrf_route_target
*l3rt
;
992 json_vni
= json_object_new_object();
993 json_import_rtl
= json_object_new_array();
994 json_export_rtl
= json_object_new_array();
997 /* if an l3vni is present in bgp it is live */
999 snprintf(buf1
, sizeof(buf1
), "*");
1002 json_object_int_add(json_vni
, "vni", bgp
->l3vni
);
1003 json_object_string_add(json_vni
, "type", "L3");
1004 json_object_string_add(json_vni
, "inKernel", "True");
1005 json_object_string_addf(json_vni
, "originatorIp", "%pI4",
1006 &bgp
->originator_ip
);
1007 json_object_string_addf(json_vni
, "rd", "%pRD", &bgp
->vrf_prd
);
1008 json_object_string_add(json_vni
, "advertiseGatewayMacip",
1010 json_object_string_add(json_vni
, "advertiseSviMacIp", "n/a");
1011 json_object_string_add(
1012 json_vni
, "advertisePip",
1013 bgp
->evpn_info
->advertise_pip
? "Enabled" : "Disabled");
1014 json_object_string_addf(json_vni
, "sysIP", "%pI4",
1015 &bgp
->evpn_info
->pip_ip
);
1016 json_object_string_add(json_vni
, "sysMAC",
1017 prefix_mac2str(&bgp
->evpn_info
->pip_rmac
,
1018 buf2
, sizeof(buf2
)));
1019 json_object_string_add(
1021 prefix_mac2str(&bgp
->rmac
, buf2
, sizeof(buf2
)));
1023 vty_out(vty
, "%-1s %-10u %-4s %-21pRD", buf1
, bgp
->l3vni
, "L3",
1027 for (ALL_LIST_ELEMENTS(bgp
->vrf_import_rtl
, node
, nnode
, l3rt
)) {
1028 ecom_str
= ecommunity_ecom2str(l3rt
->ecom
,
1029 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
1032 json_object_array_add(json_import_rtl
,
1033 json_object_new_string(ecom_str
));
1035 if (listcount(bgp
->vrf_import_rtl
) > 1)
1036 snprintf(rt_buf
, sizeof(rt_buf
), "%s, ...",
1039 snprintf(rt_buf
, sizeof(rt_buf
), "%s",
1041 vty_out(vty
, " %-25s", rt_buf
);
1044 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
1046 /* If there are multiple import RTs we break here and show only
1053 json_object_object_add(json_vni
, "importRTs", json_import_rtl
);
1055 for (ALL_LIST_ELEMENTS(bgp
->vrf_export_rtl
, node
, nnode
, l3rt
)) {
1056 ecom_str
= ecommunity_ecom2str(l3rt
->ecom
,
1057 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
1060 json_object_array_add(json_export_rtl
,
1061 json_object_new_string(ecom_str
));
1063 if (listcount(bgp
->vrf_export_rtl
) > 1)
1064 snprintf(rt_buf
, sizeof(rt_buf
), "%s, ...",
1067 snprintf(rt_buf
, sizeof(rt_buf
), "%s",
1069 vty_out(vty
, " %-25s", rt_buf
);
1072 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
1074 /* If there are multiple export RTs we break here and show only
1077 vty_out(vty
, "%-37s", vrf_id_to_name(bgp
->vrf_id
));
1083 char vni_str
[VNI_STR_LEN
];
1085 json_object_object_add(json_vni
, "exportRTs", json_export_rtl
);
1086 snprintf(vni_str
, sizeof(vni_str
), "%u", bgp
->l3vni
);
1087 json_object_object_add(json
, vni_str
, json_vni
);
1093 static void show_vni_entry(struct hash_bucket
*bucket
, void *args
[])
1097 json_object
*json_vni
= NULL
;
1098 json_object
*json_import_rtl
= NULL
;
1099 json_object
*json_export_rtl
= NULL
;
1100 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
1104 struct listnode
*node
, *nnode
;
1105 struct ecommunity
*ecom
;
1106 struct bgp
*bgp_evpn
;
1111 bgp_evpn
= bgp_get_evpn();
1114 json_vni
= json_object_new_object();
1115 json_import_rtl
= json_object_new_array();
1116 json_export_rtl
= json_object_new_array();
1120 if (is_vni_live(vpn
))
1121 snprintf(buf1
, sizeof(buf1
), "*");
1124 json_object_int_add(json_vni
, "vni", vpn
->vni
);
1125 json_object_string_add(json_vni
, "type", "L2");
1126 json_object_string_add(json_vni
, "inKernel",
1127 is_vni_live(vpn
) ? "True" : "False");
1128 json_object_string_addf(json_vni
, "rd", "%pRD", &vpn
->prd
);
1129 json_object_string_addf(json_vni
, "originatorIp", "%pI4",
1130 &vpn
->originator_ip
);
1131 json_object_string_addf(json_vni
, "mcastGroup", "%pI4",
1133 /* per vni knob is enabled -- Enabled
1134 * Global knob is enabled -- Active
1135 * default -- Disabled
1137 if (!vpn
->advertise_gw_macip
&& bgp_evpn
1138 && bgp_evpn
->advertise_gw_macip
)
1139 json_object_string_add(
1140 json_vni
, "advertiseGatewayMacip", "Active");
1141 else if (vpn
->advertise_gw_macip
)
1142 json_object_string_add(
1143 json_vni
, "advertiseGatewayMacip", "Enabled");
1145 json_object_string_add(
1146 json_vni
, "advertiseGatewayMacip", "Disabled");
1147 if (!vpn
->advertise_svi_macip
&& bgp_evpn
1148 && bgp_evpn
->evpn_info
->advertise_svi_macip
)
1149 json_object_string_add(json_vni
, "advertiseSviMacIp",
1151 else if (vpn
->advertise_svi_macip
)
1152 json_object_string_add(json_vni
, "advertiseSviMacIp",
1155 json_object_string_add(json_vni
, "advertiseSviMacIp",
1158 vty_out(vty
, "%-1s %-10u %-4s %-21pRD", buf1
, vpn
->vni
, "L2",
1162 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
1163 ecom_str
= ecommunity_ecom2str(ecom
,
1164 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
1167 json_object_array_add(json_import_rtl
,
1168 json_object_new_string(ecom_str
));
1170 if (listcount(vpn
->import_rtl
) > 1)
1171 snprintf(rt_buf
, sizeof(rt_buf
), "%s, ...",
1174 snprintf(rt_buf
, sizeof(rt_buf
), "%s",
1176 vty_out(vty
, " %-25s", rt_buf
);
1179 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
1181 /* If there are multiple import RTs we break here and show only
1188 json_object_object_add(json_vni
, "importRTs", json_import_rtl
);
1190 for (ALL_LIST_ELEMENTS(vpn
->export_rtl
, node
, nnode
, ecom
)) {
1191 ecom_str
= ecommunity_ecom2str(ecom
,
1192 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
1195 json_object_array_add(json_export_rtl
,
1196 json_object_new_string(ecom_str
));
1198 if (listcount(vpn
->export_rtl
) > 1)
1199 snprintf(rt_buf
, sizeof(rt_buf
), "%s, ...",
1202 snprintf(rt_buf
, sizeof(rt_buf
), "%s",
1204 vty_out(vty
, " %-25s", rt_buf
);
1207 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
1209 /* If there are multiple export RTs we break here and show only
1212 vty_out(vty
, "%-37s",
1213 vrf_id_to_name(vpn
->tenant_vrf_id
));
1219 char vni_str
[VNI_STR_LEN
];
1221 json_object_object_add(json_vni
, "exportRTs", json_export_rtl
);
1222 snprintf(vni_str
, sizeof(vni_str
), "%u", vpn
->vni
);
1223 json_object_object_add(json
, vni_str
, json_vni
);
1229 static int bgp_show_ethernet_vpn(struct vty
*vty
, struct prefix_rd
*prd
,
1230 enum bgp_show_type type
, void *output_arg
,
1231 int option
, bool use_json
)
1233 afi_t afi
= AFI_L2VPN
;
1235 struct bgp_table
*table
;
1236 struct bgp_dest
*dest
;
1237 struct bgp_dest
*rm
;
1238 struct bgp_path_info
*pi
;
1241 char rd_str
[RD_ADDRSTRLEN
];
1244 unsigned long output_count
= 0;
1245 unsigned long total_count
= 0;
1246 json_object
*json
= NULL
;
1247 json_object
*json_array
= NULL
;
1248 json_object
*json_prefix_info
= NULL
;
1250 memset(rd_str
, 0, RD_ADDRSTRLEN
);
1252 bgp
= bgp_get_evpn();
1255 vty_out(vty
, "No BGP process is configured\n");
1257 vty_out(vty
, "{}\n");
1262 json
= json_object_new_object();
1264 for (dest
= bgp_table_top(bgp
->rib
[afi
][SAFI_EVPN
]); dest
;
1265 dest
= bgp_route_next(dest
)) {
1267 json_object
*json_nroute
= NULL
;
1268 const struct prefix
*p
= bgp_dest_get_prefix(dest
);
1270 if (prd
&& memcmp(p
->u
.val
, prd
->val
, 8) != 0)
1273 table
= bgp_dest_get_bgp_table_info(dest
);
1278 tbl_ver
= table
->version
;
1280 for (rm
= bgp_table_top(table
); rm
; rm
= bgp_route_next(rm
)) {
1281 pi
= bgp_dest_get_bgp_path_info(rm
);
1286 for (; pi
; pi
= pi
->next
) {
1287 struct community
*picomm
= NULL
;
1289 picomm
= bgp_attr_get_community(pi
->attr
);
1292 if (type
== bgp_show_type_neighbor
) {
1293 struct peer
*peer
= output_arg
;
1295 if (peer_cmp(peer
, pi
->peer
) != 0)
1298 if (type
== bgp_show_type_lcommunity_exact
) {
1299 struct lcommunity
*lcom
= output_arg
;
1301 if (!bgp_attr_get_lcommunity(
1304 bgp_attr_get_lcommunity(
1309 if (type
== bgp_show_type_lcommunity
) {
1310 struct lcommunity
*lcom
= output_arg
;
1312 if (!bgp_attr_get_lcommunity(
1315 bgp_attr_get_lcommunity(
1320 if (type
== bgp_show_type_community
) {
1321 struct community
*com
= output_arg
;
1324 !community_match(picomm
, com
))
1327 if (type
== bgp_show_type_community_exact
) {
1328 struct community
*com
= output_arg
;
1331 !community_cmp(picomm
, com
))
1336 json_object_int_add(
1337 json
, "bgpTableVersion",
1339 json_object_string_addf(
1344 json_object_int_add(
1347 bgp
->default_local_pref
);
1348 json_object_int_add(
1352 if (option
== SHOW_DISPLAY_TAGS
)
1357 == SHOW_DISPLAY_OVERLAY
)
1361 bgp_evpn_show_route_header(vty
, bgp
, tbl_ver
, NULL
);
1369 json_object_new_object();
1370 bgp_evpn_show_route_rd_header(
1371 vty
, dest
, json_nroute
, rd_str
,
1375 if (use_json
&& !json_array
)
1376 json_array
= json_object_new_array();
1378 if (option
== SHOW_DISPLAY_TAGS
)
1380 vty
, bgp_dest_get_prefix(rm
),
1381 pi
, no_display
, SAFI_EVPN
,
1383 else if (option
== SHOW_DISPLAY_OVERLAY
)
1384 route_vty_out_overlay(
1385 vty
, bgp_dest_get_prefix(rm
),
1386 pi
, no_display
, json_array
);
1389 bgp_dest_get_prefix(rm
),
1390 pi
, no_display
, SAFI_EVPN
,
1398 if (use_json
&& json_array
) {
1399 const struct prefix
*p
=
1400 bgp_dest_get_prefix(rm
);
1402 json_prefix_info
= json_object_new_object();
1404 json_object_string_addf(json_prefix_info
,
1405 "prefix", "%pFX", p
);
1407 json_object_int_add(json_prefix_info
,
1408 "prefixLen", p
->prefixlen
);
1410 json_object_object_add(json_prefix_info
,
1411 "paths", json_array
);
1412 json_object_object_addf(json_nroute
,
1419 if (use_json
&& json_nroute
)
1420 json_object_object_add(json
, rd_str
, json_nroute
);
1424 json_object_int_add(json
, "numPrefix", output_count
);
1425 json_object_int_add(json
, "totalPrefix", total_count
);
1426 vty_json(vty
, json
);
1428 if (output_count
== 0)
1429 vty_out(vty
, "No prefixes displayed, %ld exist\n",
1433 "\nDisplayed %ld out of %ld total prefixes\n",
1434 output_count
, total_count
);
1439 DEFUN(show_ip_bgp_l2vpn_evpn
,
1440 show_ip_bgp_l2vpn_evpn_cmd
,
1441 "show [ip] bgp l2vpn evpn [json]",
1442 SHOW_STR IP_STR BGP_STR L2VPN_HELP_STR EVPN_HELP_STR JSON_STR
)
1444 return bgp_show_ethernet_vpn(vty
, NULL
, bgp_show_type_normal
, NULL
,
1445 SHOW_DISPLAY_STANDARD
,
1446 use_json(argc
, argv
));
1449 DEFUN(show_ip_bgp_l2vpn_evpn_rd
,
1450 show_ip_bgp_l2vpn_evpn_rd_cmd
,
1451 "show [ip] bgp l2vpn evpn rd <ASN:NN_OR_IP-ADDRESS:NN|all> [json]",
1457 "Display information for a route distinguisher\n"
1458 "VPN Route Distinguisher\n"
1459 "All VPN Route Distinguishers\n"
1462 int idx_ext_community
= 0;
1464 struct prefix_rd prd
;
1467 if (argv_find(argv
, argc
, "all", &rd_all
))
1468 return bgp_show_ethernet_vpn(vty
, NULL
, bgp_show_type_normal
,
1469 NULL
, SHOW_DISPLAY_STANDARD
,
1470 use_json(argc
, argv
));
1472 argv_find(argv
, argc
, "ASN:NN_OR_IP-ADDRESS:NN", &idx_ext_community
);
1473 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
1475 vty_out(vty
, "%% Malformed Route Distinguisher\n");
1478 return bgp_show_ethernet_vpn(vty
, &prd
, bgp_show_type_normal
, NULL
,
1479 SHOW_DISPLAY_STANDARD
,
1480 use_json(argc
, argv
));
1483 DEFUN(show_ip_bgp_l2vpn_evpn_all_tags
,
1484 show_ip_bgp_l2vpn_evpn_all_tags_cmd
,
1485 "show [ip] bgp l2vpn evpn all tags",
1491 "Display information about all EVPN NLRIs\n"
1492 "Display BGP tags for prefixes\n")
1494 return bgp_show_ethernet_vpn(vty
, NULL
, bgp_show_type_normal
, NULL
,
1495 SHOW_DISPLAY_TAGS
, 0);
1498 DEFUN(show_ip_bgp_l2vpn_evpn_rd_tags
,
1499 show_ip_bgp_l2vpn_evpn_rd_tags_cmd
,
1500 "show [ip] bgp l2vpn evpn rd <ASN:NN_OR_IP-ADDRESS:NN|all> tags",
1506 "Display information for a route distinguisher\n"
1507 "VPN Route Distinguisher\n"
1508 "All VPN Route Distinguishers\n"
1509 "Display BGP tags for prefixes\n")
1511 int idx_ext_community
= 0;
1513 struct prefix_rd prd
;
1516 if (argv_find(argv
, argc
, "all", &rd_all
))
1517 return bgp_show_ethernet_vpn(vty
, NULL
, bgp_show_type_normal
,
1518 NULL
, SHOW_DISPLAY_TAGS
, 0);
1520 argv_find(argv
, argc
, "ASN:NN_OR_IP-ADDRESS:NN", &idx_ext_community
);
1521 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
1523 vty_out(vty
, "%% Malformed Route Distinguisher\n");
1526 return bgp_show_ethernet_vpn(vty
, &prd
, bgp_show_type_normal
, NULL
,
1527 SHOW_DISPLAY_TAGS
, 0);
1530 DEFUN(show_ip_bgp_l2vpn_evpn_neighbor_routes
,
1531 show_ip_bgp_l2vpn_evpn_neighbor_routes_cmd
,
1532 "show [ip] bgp l2vpn evpn neighbors <A.B.C.D|X:X::X:X|WORD> routes [json]",
1538 "Detailed information on TCP and BGP neighbor connections\n"
1539 "IPv4 Neighbor to display information about\n"
1540 "IPv6 Neighbor to display information about\n"
1541 "Neighbor on BGP configured interface\n"
1542 "Display routes learned from neighbor\n" JSON_STR
)
1546 char *peerstr
= NULL
;
1547 bool uj
= use_json(argc
, argv
);
1548 afi_t afi
= AFI_L2VPN
;
1549 safi_t safi
= SAFI_EVPN
;
1550 struct bgp
*bgp
= NULL
;
1552 bgp_vty_find_and_parse_afi_safi_bgp(vty
, argv
, argc
, &idx
, &afi
, &safi
,
1555 vty_out(vty
, "No index\n");
1559 /* neighbors <A.B.C.D|X:X::X:X|WORD> */
1560 argv_find(argv
, argc
, "neighbors", &idx
);
1561 peerstr
= argv
[++idx
]->arg
;
1563 peer
= peer_lookup_in_view(vty
, bgp
, peerstr
, uj
);
1566 json_object
*json_no
= NULL
;
1567 json_no
= json_object_new_object();
1568 json_object_string_add(json_no
, "warning",
1569 "Malformed address");
1570 vty_out(vty
, "%s\n",
1571 json_object_to_json_string(json_no
));
1572 json_object_free(json_no
);
1574 vty_out(vty
, "Malformed address: %s\n",
1578 if (!peer
|| !peer
->afc
[AFI_L2VPN
][SAFI_EVPN
]) {
1580 json_object
*json_no
= NULL
;
1581 json_no
= json_object_new_object();
1582 json_object_string_add(
1584 "No such neighbor or address family");
1585 vty_out(vty
, "%s\n",
1586 json_object_to_json_string(json_no
));
1587 json_object_free(json_no
);
1589 vty_out(vty
, "%% No such neighbor or address family\n");
1593 return bgp_show_ethernet_vpn(vty
, NULL
, bgp_show_type_neighbor
, peer
,
1594 SHOW_DISPLAY_STANDARD
, uj
);
1597 DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_routes
,
1598 show_ip_bgp_l2vpn_evpn_rd_neighbor_routes_cmd
,
1599 "show [ip] bgp l2vpn evpn rd <ASN:NN_OR_IP-ADDRESS:NN|all> neighbors <A.B.C.D|X:X::X:X|WORD> routes [json]",
1605 "Display information for a route distinguisher\n"
1606 "VPN Route Distinguisher\n"
1607 "All VPN Route Distinguishers\n"
1608 "Detailed information on TCP and BGP neighbor connections\n"
1609 "IPv4 Neighbor to display information about\n"
1610 "IPv6 Neighbor to display information about\n"
1611 "Neighbor on BGP configured interface\n"
1612 "Display routes learned from neighbor\n" JSON_STR
)
1614 int idx_ext_community
= 0;
1618 char *peerstr
= NULL
;
1619 struct prefix_rd prd
= {};
1620 bool uj
= use_json(argc
, argv
);
1621 afi_t afi
= AFI_L2VPN
;
1622 safi_t safi
= SAFI_EVPN
;
1623 struct bgp
*bgp
= NULL
;
1626 bgp_vty_find_and_parse_afi_safi_bgp(vty
, argv
, argc
, &idx
, &afi
, &safi
,
1629 vty_out(vty
, "No index\n");
1633 if (argv_find(argv
, argc
, "all", &rd_all
)) {
1634 argv_find(argv
, argc
, "ASN:NN_OR_IP-ADDRESS:NN",
1635 &idx_ext_community
);
1636 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
1639 json_object
*json_no
= NULL
;
1640 json_no
= json_object_new_object();
1641 json_object_string_add(
1643 "Malformed Route Distinguisher");
1644 vty_out(vty
, "%s\n",
1645 json_object_to_json_string(json_no
));
1646 json_object_free(json_no
);
1649 "%% Malformed Route Distinguisher\n");
1654 /* neighbors <A.B.C.D|X:X::X:X|WORD> */
1655 argv_find(argv
, argc
, "neighbors", &idx
);
1656 peerstr
= argv
[++idx
]->arg
;
1658 peer
= peer_lookup_in_view(vty
, bgp
, peerstr
, uj
);
1661 json_object
*json_no
= NULL
;
1662 json_no
= json_object_new_object();
1663 json_object_string_add(json_no
, "warning",
1664 "Malformed address");
1665 vty_out(vty
, "%s\n",
1666 json_object_to_json_string(json_no
));
1667 json_object_free(json_no
);
1669 vty_out(vty
, "Malformed address: %s\n",
1673 if (!peer
|| !peer
->afc
[AFI_L2VPN
][SAFI_EVPN
]) {
1675 json_object
*json_no
= NULL
;
1676 json_no
= json_object_new_object();
1677 json_object_string_add(
1679 "No such neighbor or address family");
1680 vty_out(vty
, "%s\n",
1681 json_object_to_json_string(json_no
));
1682 json_object_free(json_no
);
1684 vty_out(vty
, "%% No such neighbor or address family\n");
1690 return bgp_show_ethernet_vpn(vty
, NULL
, bgp_show_type_neighbor
,
1691 peer
, SHOW_DISPLAY_STANDARD
, uj
);
1693 return bgp_show_ethernet_vpn(vty
, &prd
, bgp_show_type_neighbor
,
1694 peer
, SHOW_DISPLAY_STANDARD
, uj
);
1697 DEFUN(show_ip_bgp_l2vpn_evpn_neighbor_advertised_routes
,
1698 show_ip_bgp_l2vpn_evpn_neighbor_advertised_routes_cmd
,
1699 "show [ip] bgp l2vpn evpn neighbors <A.B.C.D|X:X::X:X|WORD> advertised-routes [json]",
1705 "Detailed information on TCP and BGP neighbor connections\n"
1706 "IPv4 Neighbor to display information about\n"
1707 "IPv6 Neighbor to display information about\n"
1708 "Neighbor on BGP configured interface\n"
1709 "Display the routes advertised to a BGP neighbor\n" JSON_STR
)
1713 bool uj
= use_json(argc
, argv
);
1714 struct bgp
*bgp
= NULL
;
1715 afi_t afi
= AFI_L2VPN
;
1716 safi_t safi
= SAFI_EVPN
;
1717 char *peerstr
= NULL
;
1722 bgp_vty_find_and_parse_afi_safi_bgp(vty
, argv
, argc
, &idx
, &afi
, &safi
,
1725 vty_out(vty
, "No index\n");
1729 /* neighbors <A.B.C.D|X:X::X:X|WORD> */
1730 argv_find(argv
, argc
, "neighbors", &idx
);
1731 peerstr
= argv
[++idx
]->arg
;
1733 peer
= peer_lookup_in_view(vty
, bgp
, peerstr
, uj
);
1736 json_object
*json_no
= NULL
;
1737 json_no
= json_object_new_object();
1738 json_object_string_add(json_no
, "warning",
1739 "Malformed address");
1740 vty_out(vty
, "%s\n",
1741 json_object_to_json_string(json_no
));
1742 json_object_free(json_no
);
1744 vty_out(vty
, "Malformed address: %s\n",
1748 if (!peer
|| !peer
->afc
[AFI_L2VPN
][SAFI_EVPN
]) {
1750 json_object
*json_no
= NULL
;
1751 json_no
= json_object_new_object();
1752 json_object_string_add(
1754 "No such neighbor or address family");
1755 vty_out(vty
, "%s\n",
1756 json_object_to_json_string(json_no
));
1757 json_object_free(json_no
);
1759 vty_out(vty
, "%% No such neighbor or address family\n");
1763 return show_adj_route_vpn(vty
, peer
, NULL
, AFI_L2VPN
, SAFI_EVPN
, uj
);
1766 DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes
,
1767 show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes_cmd
,
1768 "show [ip] bgp l2vpn evpn rd <ASN:NN_OR_IP-ADDRESS:NN|all> neighbors <A.B.C.D|X:X::X:X|WORD> advertised-routes [json]",
1774 "Display information for a route distinguisher\n"
1775 "VPN Route Distinguisher\n"
1776 "All VPN Route Distinguishers\n"
1777 "Detailed information on TCP and BGP neighbor connections\n"
1778 "IPv4 Neighbor to display information about\n"
1779 "IPv6 Neighbor to display information about\n"
1780 "Neighbor on BGP configured interface\n"
1781 "Display the routes advertised to a BGP neighbor\n" JSON_STR
)
1783 int idx_ext_community
= 0;
1787 struct prefix_rd prd
;
1788 struct bgp
*bgp
= NULL
;
1789 bool uj
= use_json(argc
, argv
);
1790 char *peerstr
= NULL
;
1791 afi_t afi
= AFI_L2VPN
;
1792 safi_t safi
= SAFI_EVPN
;
1801 bgp_vty_find_and_parse_afi_safi_bgp(vty
, argv
, argc
, &idx
, &afi
, &safi
,
1804 vty_out(vty
, "No index\n");
1808 /* neighbors <A.B.C.D|X:X::X:X|WORD> */
1809 argv_find(argv
, argc
, "neighbors", &idx
);
1810 peerstr
= argv
[++idx
]->arg
;
1812 peer
= peer_lookup_in_view(vty
, bgp
, peerstr
, uj
);
1815 json_object
*json_no
= NULL
;
1816 json_no
= json_object_new_object();
1817 json_object_string_add(json_no
, "warning",
1818 "Malformed address");
1819 vty_out(vty
, "%s\n",
1820 json_object_to_json_string(json_no
));
1821 json_object_free(json_no
);
1823 vty_out(vty
, "Malformed address: %s\n",
1827 if (!peer
|| !peer
->afc
[AFI_L2VPN
][SAFI_EVPN
]) {
1829 json_object
*json_no
= NULL
;
1830 json_no
= json_object_new_object();
1831 json_object_string_add(
1833 "No such neighbor or address family");
1834 vty_out(vty
, "%s\n",
1835 json_object_to_json_string(json_no
));
1836 json_object_free(json_no
);
1838 vty_out(vty
, "%% No such neighbor or address family\n");
1842 if (argv_find(argv
, argc
, "all", &rd_all
))
1843 return show_adj_route_vpn(vty
, peer
, NULL
, AFI_L2VPN
, SAFI_EVPN
,
1846 argv_find(argv
, argc
, "ASN:NN_OR_IP-ADDRESS:NN",
1847 &idx_ext_community
);
1848 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
1851 json_object
*json_no
= NULL
;
1852 json_no
= json_object_new_object();
1853 json_object_string_add(
1855 "Malformed Route Distinguisher");
1856 vty_out(vty
, "%s\n",
1857 json_object_to_json_string(json_no
));
1858 json_object_free(json_no
);
1861 "%% Malformed Route Distinguisher\n");
1866 return show_adj_route_vpn(vty
, peer
, &prd
, AFI_L2VPN
, SAFI_EVPN
, uj
);
1869 DEFUN(show_ip_bgp_l2vpn_evpn_all_overlay
,
1870 show_ip_bgp_l2vpn_evpn_all_overlay_cmd
,
1871 "show [ip] bgp l2vpn evpn all overlay [json]",
1877 "Display information about all EVPN NLRIs\n"
1878 "Display BGP Overlay Information for prefixes\n"
1881 return bgp_show_ethernet_vpn(vty
, NULL
, bgp_show_type_normal
, NULL
,
1882 SHOW_DISPLAY_OVERLAY
,
1883 use_json(argc
, argv
));
1886 DEFUN(show_ip_bgp_evpn_rd_overlay
,
1887 show_ip_bgp_evpn_rd_overlay_cmd
,
1888 "show [ip] bgp l2vpn evpn rd <ASN:NN_OR_IP-ADDRESS:NN|all> overlay",
1894 "Display information for a route distinguisher\n"
1895 "VPN Route Distinguisher\n"
1896 "All VPN Route Distinguishers\n"
1897 "Display BGP Overlay Information for prefixes\n")
1899 int idx_ext_community
= 0;
1901 struct prefix_rd prd
;
1904 if (argv_find(argv
, argc
, "all", &rd_all
))
1905 return bgp_show_ethernet_vpn(vty
, NULL
, bgp_show_type_normal
,
1906 NULL
, SHOW_DISPLAY_OVERLAY
,
1907 use_json(argc
, argv
));
1909 argv_find(argv
, argc
, "ASN:NN_OR_IP-ADDRESS:NN", &idx_ext_community
);
1910 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
1912 vty_out(vty
, "%% Malformed Route Distinguisher\n");
1915 return bgp_show_ethernet_vpn(vty
, &prd
, bgp_show_type_normal
, NULL
,
1916 SHOW_DISPLAY_OVERLAY
,
1917 use_json(argc
, argv
));
1920 DEFUN(show_bgp_l2vpn_evpn_com
,
1921 show_bgp_l2vpn_evpn_com_cmd
,
1922 "show bgp l2vpn evpn \
1923 <community AA:NN|large-community AA:BB:CC> \
1924 [exact-match] [json]",
1929 "Display routes matching the community\n"
1930 "Community number where AA and NN are (0-65535)\n"
1931 "Display routes matching the large-community\n"
1932 "List of large-community numbers\n"
1933 "Exact match of the communities\n"
1938 const char *clist_number_or_name
;
1939 int show_type
= bgp_show_type_normal
;
1940 struct community
*com
;
1941 struct lcommunity
*lcom
;
1943 if (argv_find(argv
, argc
, "large-community", &idx
)) {
1944 clist_number_or_name
= argv
[++idx
]->arg
;
1945 show_type
= bgp_show_type_lcommunity
;
1947 if (++idx
< argc
&& strmatch(argv
[idx
]->text
, "exact-match"))
1948 show_type
= bgp_show_type_lcommunity_exact
;
1950 lcom
= lcommunity_str2com(clist_number_or_name
);
1952 vty_out(vty
, "%% Large-community malformed\n");
1956 ret
= bgp_show_ethernet_vpn(vty
, NULL
, show_type
, lcom
,
1957 SHOW_DISPLAY_STANDARD
,
1958 use_json(argc
, argv
));
1960 lcommunity_free(&lcom
);
1961 } else if (argv_find(argv
, argc
, "community", &idx
)) {
1962 clist_number_or_name
= argv
[++idx
]->arg
;
1963 show_type
= bgp_show_type_community
;
1965 if (++idx
< argc
&& strmatch(argv
[idx
]->text
, "exact-match"))
1966 show_type
= bgp_show_type_community_exact
;
1968 com
= community_str2com(clist_number_or_name
);
1971 vty_out(vty
, "%% Community malformed: %s\n",
1972 clist_number_or_name
);
1976 ret
= bgp_show_ethernet_vpn(vty
, NULL
, show_type
, com
,
1977 SHOW_DISPLAY_STANDARD
,
1978 use_json(argc
, argv
));
1979 community_free(&com
);
1985 /* For testing purpose, static route of EVPN RT-5. */
1986 DEFUN(evpnrt5_network
,
1987 evpnrt5_network_cmd
,
1988 "network <A.B.C.D/M|X:X::X:X/M> rd ASN:NN_OR_IP-ADDRESS:NN ethtag WORD label WORD esi WORD gwip <A.B.C.D|X:X::X:X> routermac WORD [route-map RMAP_NAME]",
1989 "Specify a network to announce via BGP\n"
1992 "Specify Route Distinguisher\n"
1993 "VPN Route Distinguisher\n"
1995 "Ethernet Tag Value\n"
1998 "Ethernet Segment Identifier\n"
1999 "ESI value ( 00:11:22:33:44:55:66:77:88:99 format) \n"
2001 "Gateway IP ( A.B.C.D )\n"
2002 "Gateway IPv6 ( X:X::X:X )\n"
2003 "Router Mac Ext Comm\n"
2004 "Router Mac address Value ( aa:bb:cc:dd:ee:ff format)\n"
2005 "Route-map to modify the attributes\n"
2006 "Name of the route map\n")
2008 int idx_ipv4_prefixlen
= 1;
2009 int idx_route_distinguisher
= 3;
2014 int idx_routermac
= 13;
2016 return bgp_static_set_safi(
2017 AFI_L2VPN
, SAFI_EVPN
, vty
, argv
[idx_ipv4_prefixlen
]->arg
,
2018 argv
[idx_route_distinguisher
]->arg
, argv
[idx_label
]->arg
, NULL
,
2019 BGP_EVPN_IP_PREFIX_ROUTE
, argv
[idx_esi
]->arg
,
2020 argv
[idx_gwip
]->arg
, argv
[idx_ethtag
]->arg
,
2021 argv
[idx_routermac
]->arg
);
2024 /* For testing purpose, static route of EVPN RT-5. */
2025 DEFUN(no_evpnrt5_network
,
2026 no_evpnrt5_network_cmd
,
2027 "no network <A.B.C.D/M|X:X::X:X/M> rd ASN:NN_OR_IP-ADDRESS:NN ethtag WORD label WORD esi WORD gwip <A.B.C.D|X:X::X:X>",
2029 "Specify a network to announce via BGP\n"
2032 "Specify Route Distinguisher\n"
2033 "VPN Route Distinguisher\n"
2035 "Ethernet Tag Value\n"
2038 "Ethernet Segment Identifier\n"
2039 "ESI value ( 00:11:22:33:44:55:66:77:88:99 format) \n"
2040 "Gateway IP\n" "Gateway IP ( A.B.C.D )\n" "Gateway IPv6 ( X:X::X:X )\n")
2042 int idx_ipv4_prefixlen
= 2;
2043 int idx_ext_community
= 4;
2048 return bgp_static_unset_safi(
2049 AFI_L2VPN
, SAFI_EVPN
, vty
, argv
[idx_ipv4_prefixlen
]->arg
,
2050 argv
[idx_ext_community
]->arg
, argv
[idx_label
]->arg
,
2051 BGP_EVPN_IP_PREFIX_ROUTE
, argv
[idx_esi
]->arg
,
2052 argv
[idx_gwip
]->arg
, argv
[idx_ethtag
]->arg
);
2055 static void evpn_import_rt_delete_auto(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2057 evpn_rt_delete_auto(bgp
, vpn
->vni
, vpn
->import_rtl
, false);
2060 static void evpn_export_rt_delete_auto(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2062 evpn_rt_delete_auto(bgp
, vpn
->vni
, vpn
->export_rtl
, false);
2066 * Configure the Import RTs for a VNI (vty handler). Caller expected to
2067 * check that this is a change.
2069 static void evpn_configure_import_rt(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2070 struct ecommunity
*ecomadd
)
2072 /* If the VNI is "live", we need to uninstall routes using the current
2073 * import RT(s) first before we update the import RT, and subsequently
2076 if (is_vni_live(vpn
))
2077 bgp_evpn_uninstall_routes(bgp
, vpn
);
2079 /* Cleanup the RT to VNI mapping and get rid of existing import RT. */
2080 bgp_evpn_unmap_vni_from_its_rts(bgp
, vpn
);
2082 /* If the auto route-target is in use we must remove it */
2083 evpn_import_rt_delete_auto(bgp
, vpn
);
2085 /* Add new RT and rebuild the RT to VNI mapping */
2086 listnode_add_sort(vpn
->import_rtl
, ecomadd
);
2088 SET_FLAG(vpn
->flags
, VNI_FLAG_IMPRT_CFGD
);
2089 bgp_evpn_map_vni_to_its_rts(bgp
, vpn
);
2091 /* Install routes that match new import RT */
2092 if (is_vni_live(vpn
))
2093 bgp_evpn_install_routes(bgp
, vpn
);
2097 * Unconfigure Import RT(s) for a VNI (vty handler).
2099 static void evpn_unconfigure_import_rt(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2100 struct ecommunity
*ecomdel
)
2102 struct listnode
*node
, *nnode
, *node_to_del
;
2103 struct ecommunity
*ecom
;
2105 /* Along the lines of "configure" except we have to reset to the
2108 if (is_vni_live(vpn
))
2109 bgp_evpn_uninstall_routes(bgp
, vpn
);
2111 /* Cleanup the RT to VNI mapping and get rid of existing import RT. */
2112 bgp_evpn_unmap_vni_from_its_rts(bgp
, vpn
);
2114 /* Delete all import RTs */
2115 if (ecomdel
== NULL
) {
2116 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
2117 ecommunity_free(&ecom
);
2118 list_delete_node(vpn
->import_rtl
, node
);
2122 /* Delete a specific import RT */
2126 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
2127 if (ecommunity_match(ecom
, ecomdel
)) {
2128 ecommunity_free(&ecom
);
2135 list_delete_node(vpn
->import_rtl
, node_to_del
);
2138 assert(vpn
->import_rtl
);
2139 /* Reset to auto RT - this also rebuilds the RT to VNI mapping */
2140 if (list_isempty(vpn
->import_rtl
)) {
2141 UNSET_FLAG(vpn
->flags
, VNI_FLAG_IMPRT_CFGD
);
2142 bgp_evpn_derive_auto_rt_import(bgp
, vpn
);
2144 /* Rebuild the RT to VNI mapping */
2146 bgp_evpn_map_vni_to_its_rts(bgp
, vpn
);
2148 /* Install routes that match new import RT */
2149 if (is_vni_live(vpn
))
2150 bgp_evpn_install_routes(bgp
, vpn
);
2154 * Configure the Export RT for a VNI (vty handler). Caller expected to
2155 * check that this is a change. Note that only a single export RT is
2156 * allowed for a VNI and any change to configuration is implemented as
2157 * a "replace" (similar to other configuration).
2159 static void evpn_configure_export_rt(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2160 struct ecommunity
*ecomadd
)
2162 /* If the auto route-target is in use we must remove it */
2163 evpn_export_rt_delete_auto(bgp
, vpn
);
2165 listnode_add_sort(vpn
->export_rtl
, ecomadd
);
2166 SET_FLAG(vpn
->flags
, VNI_FLAG_EXPRT_CFGD
);
2168 if (is_vni_live(vpn
))
2169 bgp_evpn_handle_export_rt_change(bgp
, vpn
);
2173 * Unconfigure the Export RT for a VNI (vty handler)
2175 static void evpn_unconfigure_export_rt(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2176 struct ecommunity
*ecomdel
)
2178 struct listnode
*node
, *nnode
, *node_to_del
;
2179 struct ecommunity
*ecom
;
2181 /* Delete all export RTs */
2182 if (ecomdel
== NULL
) {
2183 /* Reset to default and process all routes. */
2184 for (ALL_LIST_ELEMENTS(vpn
->export_rtl
, node
, nnode
, ecom
)) {
2185 ecommunity_free(&ecom
);
2186 list_delete_node(vpn
->export_rtl
, node
);
2190 /* Delete a specific export RT */
2194 for (ALL_LIST_ELEMENTS(vpn
->export_rtl
, node
, nnode
, ecom
)) {
2195 if (ecommunity_match(ecom
, ecomdel
)) {
2196 ecommunity_free(&ecom
);
2203 list_delete_node(vpn
->export_rtl
, node_to_del
);
2206 assert(vpn
->export_rtl
);
2207 if (list_isempty(vpn
->export_rtl
)) {
2208 UNSET_FLAG(vpn
->flags
, VNI_FLAG_EXPRT_CFGD
);
2209 bgp_evpn_derive_auto_rt_export(bgp
, vpn
);
2212 if (is_vni_live(vpn
))
2213 bgp_evpn_handle_export_rt_change(bgp
, vpn
);
2217 * Configure RD for VRF
2219 static void evpn_configure_vrf_rd(struct bgp
*bgp_vrf
, struct prefix_rd
*rd
)
2221 /* If we have already advertise type-5 routes with a diffrent RD, we
2222 * have to delete and withdraw them firs
2224 bgp_evpn_handle_vrf_rd_change(bgp_vrf
, 1);
2227 memcpy(&bgp_vrf
->vrf_prd
, rd
, sizeof(struct prefix_rd
));
2228 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_RD_CFGD
);
2230 /* We have a new RD for VRF.
2231 * Advertise all type-5 routes again with the new RD
2233 bgp_evpn_handle_vrf_rd_change(bgp_vrf
, 0);
2237 * Unconfigure RD for VRF
2239 static void evpn_unconfigure_vrf_rd(struct bgp
*bgp_vrf
)
2241 /* If we have already advertise type-5 routes with a diffrent RD, we
2242 * have to delete and withdraw them firs
2244 bgp_evpn_handle_vrf_rd_change(bgp_vrf
, 1);
2246 /* fall back to default RD */
2247 bgp_evpn_derive_auto_rd_for_vrf(bgp_vrf
);
2248 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_RD_CFGD
);
2250 /* We have a new RD for VRF.
2251 * Advertise all type-5 routes again with the new RD
2253 bgp_evpn_handle_vrf_rd_change(bgp_vrf
, 0);
2257 * Configure RD for a VNI (vty handler)
2259 static void evpn_configure_rd(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2260 struct prefix_rd
*rd
)
2262 /* If the VNI is "live", we need to delete and withdraw this VNI's
2263 * local routes with the prior RD first. Then, after updating RD,
2264 * need to re-advertise.
2266 if (is_vni_live(vpn
))
2267 bgp_evpn_handle_rd_change(bgp
, vpn
, 1);
2270 memcpy(&vpn
->prd
, rd
, sizeof(struct prefix_rd
));
2271 SET_FLAG(vpn
->flags
, VNI_FLAG_RD_CFGD
);
2273 if (is_vni_live(vpn
))
2274 bgp_evpn_handle_rd_change(bgp
, vpn
, 0);
2278 * Unconfigure RD for a VNI (vty handler)
2280 static void evpn_unconfigure_rd(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2282 /* If the VNI is "live", we need to delete and withdraw this VNI's
2283 * local routes with the prior RD first. Then, after resetting RD
2284 * to automatic value, need to re-advertise.
2286 if (is_vni_live(vpn
))
2287 bgp_evpn_handle_rd_change(bgp
, vpn
, 1);
2289 /* reset RD to default */
2290 bgp_evpn_derive_auto_rd(bgp
, vpn
);
2292 if (is_vni_live(vpn
))
2293 bgp_evpn_handle_rd_change(bgp
, vpn
, 0);
2297 * Create VNI, if not already present (VTY handler). Mark as configured.
2299 static struct bgpevpn
*evpn_create_update_vni(struct bgp
*bgp
, vni_t vni
)
2301 struct bgpevpn
*vpn
;
2302 struct in_addr mcast_grp
= {INADDR_ANY
};
2304 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
2306 /* Check if this L2VNI is already configured as L3VNI */
2307 if (bgp_evpn_lookup_l3vni_l2vni_table(vni
)) {
2310 "%u: Failed to create L2VNI %u, it is configured as L3VNI",
2315 /* tenant vrf will be updated when we get local_vni_add from
2318 vpn
= bgp_evpn_new(bgp
, vni
, bgp
->router_id
, 0, mcast_grp
, 0);
2321 /* Mark as configured. */
2322 SET_FLAG(vpn
->flags
, VNI_FLAG_CFGD
);
2327 * Delete VNI. If VNI does not exist in the system (i.e., just
2328 * configuration), all that is needed is to free it. Otherwise,
2329 * any parameters configured for the VNI need to be reset (with
2330 * appropriate action) and the VNI marked as unconfigured; the
2331 * VNI will continue to exist, purely as a "learnt" entity.
2333 static void evpn_delete_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2335 if (!is_vni_live(vpn
)) {
2336 bgp_evpn_free(bgp
, vpn
);
2340 /* We need to take the unconfigure action for each parameter of this VNI
2341 * that is configured. Some optimization is possible, but not worth the
2342 * additional code for an operation that should be pretty rare.
2344 UNSET_FLAG(vpn
->flags
, VNI_FLAG_CFGD
);
2346 /* First, deal with the export side - RD and export RT changes. */
2347 if (is_rd_configured(vpn
))
2348 evpn_unconfigure_rd(bgp
, vpn
);
2349 if (is_export_rt_configured(vpn
))
2350 evpn_unconfigure_export_rt(bgp
, vpn
, NULL
);
2352 /* Next, deal with the import side. */
2353 if (is_import_rt_configured(vpn
))
2354 evpn_unconfigure_import_rt(bgp
, vpn
, NULL
);
2358 * Display import RT mapping to VRFs (vty handler)
2359 * bgp_evpn: evpn bgp instance
2361 static void evpn_show_vrf_import_rts(struct vty
*vty
, struct bgp
*bgp_evpn
,
2369 hash_iterate(bgp_evpn
->vrf_import_rt_hash
,
2370 (void (*)(struct hash_bucket
*,
2371 void *))show_vrf_import_rt_entry
,
2376 * Display import RT mapping to VNIs (vty handler)
2378 static void evpn_show_import_rts(struct vty
*vty
, struct bgp
*bgp
,
2387 bgp
->import_rt_hash
,
2388 (void (*)(struct hash_bucket
*, void *))show_import_rt_entry
,
2393 * Display EVPN routes for all VNIs - vty handler.
2395 static void evpn_show_routes_vni_all(struct vty
*vty
, struct bgp
*bgp
, int type
,
2396 bool mac_table
, struct in_addr vtep_ip
,
2397 json_object
*json
, int detail
)
2400 struct vni_walk_ctx wctx
;
2402 num_vnis
= hashcount(bgp
->vnihash
);
2405 memset(&wctx
, 0, sizeof(wctx
));
2409 wctx
.mac_table
= mac_table
;
2410 wctx
.vtep_ip
= vtep_ip
;
2412 wctx
.detail
= detail
;
2413 hash_iterate(bgp
->vnihash
, (void (*)(struct hash_bucket
*,
2414 void *))show_vni_routes_hash
,
2419 * Display EVPN routes for all VNIs & all types - vty handler.
2421 static void evpn_show_routes_vni_all_type_all(struct vty
*vty
, struct bgp
*bgp
,
2422 struct in_addr vtep_ip
,
2423 json_object
*json
, int detail
)
2426 struct vni_walk_ctx wctx
;
2428 num_vnis
= hashcount(bgp
->vnihash
);
2432 memset(&wctx
, 0, sizeof(struct vni_walk_ctx
));
2435 wctx
.vtep_ip
= vtep_ip
;
2437 wctx
.detail
= detail
;
2438 hash_iterate(bgp
->vnihash
,
2439 (void (*)(struct hash_bucket
*,
2440 void *))show_vni_routes_all_hash
,
2445 * Display EVPN routes for a VNI -- for specific type-3 route (vty handler).
2447 static void evpn_show_route_vni_multicast(struct vty
*vty
, struct bgp
*bgp
,
2448 vni_t vni
, struct in_addr orig_ip
,
2451 struct bgpevpn
*vpn
;
2452 struct prefix_evpn p
;
2453 struct bgp_dest
*dest
;
2454 struct bgp_path_info
*pi
;
2455 uint32_t path_cnt
= 0;
2458 json_object
*json_paths
= NULL
;
2464 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
2466 vty_out(vty
, "VNI not found\n");
2470 /* See if route exists. */
2471 build_evpn_type3_prefix(&p
, orig_ip
);
2472 dest
= bgp_evpn_vni_node_lookup(vpn
, &p
, NULL
);
2473 if (!dest
|| !bgp_dest_has_bgp_path_info_data(dest
)) {
2475 vty_out(vty
, "%% Network not in table\n");
2478 bgp_dest_unlock_node(dest
);
2484 json_paths
= json_object_new_array();
2486 /* Prefix and num paths displayed once per prefix. */
2487 route_vty_out_detail_header(vty
, bgp
, dest
, bgp_dest_get_prefix(dest
),
2488 NULL
, afi
, safi
, json
);
2490 /* Display each path for this prefix. */
2491 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
) {
2492 json_object
*json_path
= NULL
;
2495 json_path
= json_object_new_array();
2497 route_vty_out_detail(vty
, bgp
, dest
, bgp_dest_get_prefix(dest
),
2498 pi
, afi
, safi
, RPKI_NOT_BEING_USED
,
2502 json_object_array_add(json_paths
, json_path
);
2509 json_object_object_add(json
, "paths", json_paths
);
2511 json_object_int_add(json
, "numPaths", path_cnt
);
2513 vty_out(vty
, "\nDisplayed %u paths for requested prefix\n",
2517 bgp_dest_unlock_node(dest
);
2521 * Display EVPN routes for a VNI -- for specific MAC and/or IP (vty handler).
2522 * By definition, only matching type-2 route will be displayed.
2524 static void evpn_show_route_vni_macip(struct vty
*vty
, struct bgp
*bgp
,
2525 vni_t vni
, struct ethaddr
*mac
,
2526 struct ipaddr
*ip
, json_object
*json
)
2528 struct bgpevpn
*vpn
;
2529 struct prefix_evpn p
;
2530 struct prefix_evpn tmp_p
;
2531 struct bgp_dest
*dest
;
2532 struct bgp_path_info
*pi
;
2533 uint32_t path_cnt
= 0;
2536 json_object
*json_paths
= NULL
;
2537 struct ethaddr empty_mac
= {};
2538 const struct prefix_evpn
*evp
;
2544 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
2547 vty_out(vty
, "VNI not found\n");
2551 build_evpn_type2_prefix(&p
, mac
? mac
: &empty_mac
, ip
);
2553 /* See if route exists. Look for both non-sticky and sticky. */
2554 dest
= bgp_evpn_vni_node_lookup(vpn
, &p
, NULL
);
2555 if (!dest
|| !bgp_dest_has_bgp_path_info_data(dest
)) {
2557 vty_out(vty
, "%% Network not in table\n");
2560 bgp_dest_unlock_node(dest
);
2566 * MAC is per-path, we have to walk the path_info's and look for it
2570 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
) {
2571 if (memcmp(mac
, evpn_type2_path_info_get_mac(pi
),
2578 vty_out(vty
, "%% Network not in table\n");
2584 json_paths
= json_object_new_array();
2586 /* Prefix and num paths displayed once per prefix. */
2587 route_vty_out_detail_header(vty
, bgp
, dest
, (struct prefix
*)&p
, NULL
,
2590 evp
= (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
2592 /* Display each path for this prefix. */
2593 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
) {
2594 json_object
*json_path
= NULL
;
2596 /* skip non-matching MACs */
2598 memcmp(mac
, evpn_type2_path_info_get_mac(pi
),
2603 json_path
= json_object_new_array();
2606 * VNI table MAC-IP prefixes don't have MAC so
2607 * make sure it's set from path info
2610 if (is_evpn_prefix_ipaddr_none(evp
)) {
2611 /* VNI MAC -> Global */
2612 evpn_type2_prefix_global_copy(
2613 (struct prefix_evpn
*)&tmp_p
, evp
,
2615 evpn_type2_path_info_get_ip(pi
));
2617 /* VNI IP -> Global */
2618 evpn_type2_prefix_global_copy(
2619 (struct prefix_evpn
*)&tmp_p
, evp
,
2620 evpn_type2_path_info_get_mac(pi
),
2624 route_vty_out_detail(vty
, bgp
, dest
, (struct prefix
*)&tmp_p
,
2625 pi
, afi
, safi
, RPKI_NOT_BEING_USED
,
2629 json_object_array_add(json_paths
, json_path
);
2636 json_object_object_add(json
, "paths", json_paths
);
2638 json_object_int_add(json
, "numPaths", path_cnt
);
2640 vty_out(vty
, "\nDisplayed %u paths for requested prefix\n",
2644 bgp_dest_unlock_node(dest
);
2647 /* Disaplay EVPN routes for a ESI - VTY handler */
2648 static void evpn_show_routes_esi(struct vty
*vty
, struct bgp
*bgp
,
2649 esi_t
*esi
, json_object
*json
)
2651 struct bgp_evpn_es
*es
= NULL
;
2654 es
= bgp_evpn_es_find(esi
);
2657 vty_out(vty
, "ESI not found\n");
2661 show_esi_routes(bgp
, es
, vty
, json
);
2665 * Display EVPN routes for a VNI - vty handler.
2666 * If 'type' is non-zero, only routes matching that type are shown.
2667 * If the vtep_ip is non zero, only routes behind that vtep are shown
2669 static void evpn_show_routes_vni(struct vty
*vty
, struct bgp
*bgp
, vni_t vni
,
2670 int type
, bool mac_table
,
2671 struct in_addr vtep_ip
, json_object
*json
)
2673 struct bgpevpn
*vpn
;
2676 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
2679 vty_out(vty
, "VNI not found\n");
2683 /* Walk this VNI's route table and display appropriate routes. */
2684 show_vni_routes(bgp
, vpn
, vty
, type
, mac_table
, vtep_ip
, json
, 0);
2688 * Display BGP EVPN routing table -- for specific RD and MAC and/or
2689 * IP (vty handler). By definition, only matching type-2 route will be
2692 static void evpn_show_route_rd_macip(struct vty
*vty
, struct bgp
*bgp
,
2693 struct prefix_rd
*prd
, struct ethaddr
*mac
,
2694 struct ipaddr
*ip
, json_object
*json
)
2696 struct prefix_evpn p
;
2697 struct bgp_dest
*dest
;
2698 struct bgp_path_info
*pi
;
2701 uint32_t path_cnt
= 0;
2702 json_object
*json_paths
= NULL
;
2707 /* See if route exists. Look for both non-sticky and sticky. */
2708 build_evpn_type2_prefix(&p
, mac
, ip
);
2709 dest
= bgp_afi_node_lookup(bgp
->rib
[afi
][safi
], afi
, safi
,
2710 (struct prefix
*)&p
, prd
);
2711 if (!dest
|| !bgp_dest_has_bgp_path_info_data(dest
)) {
2713 vty_out(vty
, "%% Network not in table\n");
2716 bgp_dest_unlock_node(dest
);
2721 /* Prefix and num paths displayed once per prefix. */
2722 route_vty_out_detail_header(vty
, bgp
, dest
, bgp_dest_get_prefix(dest
),
2723 prd
, afi
, safi
, json
);
2726 json_paths
= json_object_new_array();
2728 /* Display each path for this prefix. */
2729 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
) {
2730 json_object
*json_path
= NULL
;
2733 json_path
= json_object_new_array();
2735 route_vty_out_detail(vty
, bgp
, dest
, bgp_dest_get_prefix(dest
),
2736 pi
, afi
, safi
, RPKI_NOT_BEING_USED
,
2740 json_object_array_add(json_paths
, json_path
);
2745 if (json
&& path_cnt
) {
2747 json_object_object_addf(json
, json_paths
, "%pFX", &p
);
2748 json_object_int_add(json
, "numPaths", path_cnt
);
2750 vty_out(vty
, "\nDisplayed %u paths for requested prefix\n",
2754 bgp_dest_unlock_node(dest
);
2758 * Display BGP EVPN routing table -- for specific RD (vty handler)
2759 * If 'type' is non-zero, only routes matching that type are shown.
2761 static void evpn_show_route_rd(struct vty
*vty
, struct bgp
*bgp
,
2762 struct prefix_rd
*prd
, int type
,
2765 struct bgp_dest
*rd_dest
;
2766 struct bgp_table
*table
;
2767 struct bgp_dest
*dest
;
2768 struct bgp_path_info
*pi
;
2772 uint32_t prefix_cnt
, path_cnt
;
2773 json_object
*json_rd
= NULL
;
2774 int add_rd_to_json
= 0;
2778 prefix_cnt
= path_cnt
= 0;
2780 rd_dest
= bgp_node_lookup(bgp
->rib
[afi
][safi
], (struct prefix
*)prd
);
2784 table
= bgp_dest_get_bgp_table_info(rd_dest
);
2785 if (table
== NULL
) {
2786 bgp_dest_unlock_node(rd_dest
);
2791 json_rd
= json_object_new_object();
2792 json_object_string_addf(json_rd
, "rd", "%pRD", prd
);
2795 bgp_dest_unlock_node(rd_dest
);
2797 /* Display all prefixes with this RD. */
2798 for (dest
= bgp_table_top(table
); dest
; dest
= bgp_route_next(dest
)) {
2799 const struct prefix_evpn
*evp
=
2800 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
2801 json_object
*json_prefix
= NULL
;
2802 json_object
*json_paths
= NULL
;
2803 int add_prefix_to_json
= 0;
2805 if (type
&& evp
->prefix
.route_type
!= type
)
2809 json_prefix
= json_object_new_object();
2811 pi
= bgp_dest_get_bgp_path_info(dest
);
2813 /* RD header and legend - once overall. */
2814 if (rd_header
&& !json
) {
2816 "EVPN type-1 prefix: [1]:[EthTag]:[ESI]:[IPlen]:[VTEP-IP]:[Frag-id]\n");
2818 "EVPN type-2 prefix: [2]:[EthTag]:[MAClen]:[MAC]\n");
2820 "EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP]\n");
2822 "EVPN type-4 prefix: [4]:[ESI]:[IPlen]:[OrigIP]\n");
2824 "EVPN type-5 prefix: [5]:[EthTag]:[IPlen]:[IP]\n\n");
2828 /* Prefix and num paths displayed once per prefix. */
2829 route_vty_out_detail_header(
2830 vty
, bgp
, dest
, bgp_dest_get_prefix(dest
), prd
,
2831 afi
, safi
, json_prefix
);
2837 json_paths
= json_object_new_array();
2839 /* Display each path for this prefix. */
2840 for (; pi
; pi
= pi
->next
) {
2841 json_object
*json_path
= NULL
;
2844 json_path
= json_object_new_array();
2846 route_vty_out_detail(
2847 vty
, bgp
, dest
, bgp_dest_get_prefix(dest
), pi
,
2848 afi
, safi
, RPKI_NOT_BEING_USED
, json_path
);
2851 json_object_array_add(json_paths
, json_path
);
2854 add_prefix_to_json
= 1;
2859 if (add_prefix_to_json
) {
2860 json_object_object_add(json_prefix
, "paths",
2862 json_object_object_addf(json_rd
, json_prefix
,
2865 json_object_free(json_paths
);
2866 json_object_free(json_prefix
);
2875 json_object_object_addf(json
, json_rd
, "%pRD", prd
);
2877 json_object_free(json_rd
);
2881 json_object_int_add(json
, "numPrefix", prefix_cnt
);
2882 json_object_int_add(json
, "numPaths", path_cnt
);
2884 if (prefix_cnt
== 0)
2885 vty_out(vty
, "No prefixes exist with this RD%s\n",
2886 type
? " (of requested type)" : "");
2889 "\nDisplayed %u prefixes (%u paths) with this RD%s\n",
2890 prefix_cnt
, path_cnt
,
2891 type
? " (of requested type)" : "");
2896 * Display BGP EVPN routing table -- all RDs and MAC and/or IP
2897 * (vty handler). Only matching type-2 routes will be displayed.
2899 static void evpn_show_route_rd_all_macip(struct vty
*vty
, struct bgp
*bgp
,
2900 struct ethaddr
*mac
, struct ipaddr
*ip
,
2903 struct bgp_dest
*rd_dest
;
2904 struct bgp_table
*table
;
2905 struct bgp_dest
*dest
;
2906 struct bgp_path_info
*pi
;
2907 afi_t afi
= AFI_L2VPN
;
2908 safi_t safi
= SAFI_EVPN
;
2909 uint32_t prefix_cnt
, path_cnt
;
2910 prefix_cnt
= path_cnt
= 0;
2912 /* EVPN routing table is a 2-level table with the first level being
2913 * the RD. We need to look in every RD we know about.
2915 for (rd_dest
= bgp_table_top(bgp
->rib
[afi
][safi
]); rd_dest
;
2916 rd_dest
= bgp_route_next(rd_dest
)) {
2917 json_object
*json_paths
= NULL
; /* paths array for prefix */
2918 json_object
*json_prefix
= NULL
; /* prefix within an RD */
2919 json_object
*json_rd
= NULL
; /* holds all prefixes for RD */
2920 char rd_str
[RD_ADDRSTRLEN
];
2921 int add_rd_to_json
= 0;
2922 struct prefix_evpn ep
;
2923 const struct prefix
*rd_destp
= bgp_dest_get_prefix(rd_dest
);
2925 table
= bgp_dest_get_bgp_table_info(rd_dest
);
2929 prefix_rd2str((struct prefix_rd
*)rd_destp
, rd_str
,
2932 /* Construct an RT-2 from the user-supplied mac(ip),
2933 * then search the l2vpn evpn table for it.
2935 build_evpn_type2_prefix(&ep
, mac
, ip
);
2936 dest
= bgp_afi_node_lookup(bgp
->rib
[afi
][safi
], afi
, safi
,
2937 (struct prefix
*)&ep
,
2938 (struct prefix_rd
*)rd_destp
);
2943 json_rd
= json_object_new_object();
2945 const struct prefix
*p
= bgp_dest_get_prefix(dest
);
2947 pi
= bgp_dest_get_bgp_path_info(dest
);
2949 /* RD header - per RD. */
2950 bgp_evpn_show_route_rd_header(vty
, rd_dest
, json_rd
,
2951 rd_str
, RD_ADDRSTRLEN
);
2956 json_prefix
= json_object_new_object();
2957 json_paths
= json_object_new_array();
2958 json_object_string_addf(json_prefix
, "prefix", "%pFX",
2960 json_object_int_add(json_prefix
, "prefixLen",
2963 /* Prefix and num paths displayed once per prefix. */
2964 route_vty_out_detail_header(
2965 vty
, bgp
, dest
, p
, (struct prefix_rd
*)rd_destp
,
2966 AFI_L2VPN
, SAFI_EVPN
, json_prefix
);
2968 /* For EVPN, the prefix is displayed for each path (to
2969 * fit in with code that already exists).
2971 for (; pi
; pi
= pi
->next
) {
2972 json_object
*json_path
= NULL
;
2978 json_path
= json_object_new_array();
2980 route_vty_out_detail(vty
, bgp
, dest
, p
, pi
, AFI_L2VPN
,
2981 SAFI_EVPN
, RPKI_NOT_BEING_USED
,
2985 json_object_array_add(json_paths
, json_path
);
2991 json_object_object_add(json_prefix
, "paths",
2993 json_object_object_addf(json_rd
, json_prefix
, "%pFX",
2996 json_object_object_add(json
, rd_str
, json_rd
);
2998 json_object_free(json_rd
);
3003 bgp_dest_unlock_node(dest
);
3007 json_object_int_add(json
, "numPrefix", prefix_cnt
);
3008 json_object_int_add(json
, "numPaths", path_cnt
);
3010 if (prefix_cnt
== 0) {
3011 vty_out(vty
, "No Matching EVPN prefixes exist\n");
3013 vty_out(vty
, "Displayed %u prefixes (%u paths)\n",
3014 prefix_cnt
, path_cnt
);
3020 * Display BGP EVPN routing table - all routes (vty handler).
3021 * If 'type' is non-zero, only routes matching that type are shown.
3023 static void evpn_show_all_routes(struct vty
*vty
, struct bgp
*bgp
, int type
,
3024 json_object
*json
, int detail
)
3026 struct bgp_dest
*rd_dest
;
3027 struct bgp_table
*table
;
3028 struct bgp_dest
*dest
;
3029 struct bgp_path_info
*pi
;
3030 int header
= detail
? 0 : 1;
3034 uint32_t prefix_cnt
, path_cnt
;
3038 prefix_cnt
= path_cnt
= 0;
3040 /* EVPN routing table is a 2-level table with the first level being
3043 for (rd_dest
= bgp_table_top(bgp
->rib
[afi
][safi
]); rd_dest
;
3044 rd_dest
= bgp_route_next(rd_dest
)) {
3045 char rd_str
[RD_ADDRSTRLEN
];
3046 json_object
*json_rd
= NULL
; /* contains routes for an RD */
3047 int add_rd_to_json
= 0;
3049 const struct prefix
*rd_destp
= bgp_dest_get_prefix(rd_dest
);
3051 table
= bgp_dest_get_bgp_table_info(rd_dest
);
3055 tbl_ver
= table
->version
;
3056 prefix_rd2str((struct prefix_rd
*)rd_destp
, rd_str
,
3060 json_rd
= json_object_new_object();
3064 /* Display all prefixes for an RD */
3065 for (dest
= bgp_table_top(table
); dest
;
3066 dest
= bgp_route_next(dest
)) {
3067 json_object
*json_prefix
=
3068 NULL
; /* contains prefix under a RD */
3069 json_object
*json_paths
=
3070 NULL
; /* array of paths under a prefix*/
3071 const struct prefix_evpn
*evp
=
3072 (const struct prefix_evpn
*)bgp_dest_get_prefix(
3074 int add_prefix_to_json
= 0;
3075 const struct prefix
*p
= bgp_dest_get_prefix(dest
);
3077 if (type
&& evp
->prefix
.route_type
!= type
)
3080 pi
= bgp_dest_get_bgp_path_info(dest
);
3082 /* Overall header/legend displayed once. */
3084 bgp_evpn_show_route_header(vty
, bgp
,
3089 "%19s Extended Community\n"
3094 /* RD header - per RD. */
3096 bgp_evpn_show_route_rd_header(
3097 vty
, rd_dest
, json_rd
, rd_str
,
3106 json_prefix
= json_object_new_object();
3107 json_paths
= json_object_new_array();
3108 json_object_string_addf(json_prefix
, "prefix",
3110 json_object_int_add(json_prefix
, "prefixLen",
3114 /* Prefix and num paths displayed once per prefix. */
3116 route_vty_out_detail_header(
3118 bgp_dest_get_prefix(dest
),
3119 (struct prefix_rd
*)rd_destp
, AFI_L2VPN
,
3120 SAFI_EVPN
, json_prefix
);
3122 /* For EVPN, the prefix is displayed for each path (to
3124 * with code that already exists).
3126 for (; pi
; pi
= pi
->next
) {
3127 json_object
*json_path
= NULL
;
3130 add_prefix_to_json
= 1;
3134 json_path
= json_object_new_array();
3137 route_vty_out_detail(
3139 bgp_dest_get_prefix(dest
), pi
,
3140 AFI_L2VPN
, SAFI_EVPN
,
3141 RPKI_NOT_BEING_USED
, json_path
);
3143 route_vty_out(vty
, p
, pi
, 0, SAFI_EVPN
,
3147 json_object_array_add(json_paths
,
3152 if (add_prefix_to_json
) {
3153 json_object_object_add(json_prefix
,
3156 json_object_object_addf(json_rd
,
3160 json_object_free(json_prefix
);
3161 json_object_free(json_paths
);
3170 json_object_object_add(json
, rd_str
, json_rd
);
3172 json_object_free(json_rd
);
3179 json_object_int_add(json
, "numPrefix", prefix_cnt
);
3180 json_object_int_add(json
, "numPaths", path_cnt
);
3182 if (prefix_cnt
== 0) {
3183 vty_out(vty
, "No EVPN prefixes %sexist\n",
3184 type
? "(of requested type) " : "");
3186 vty_out(vty
, "\nDisplayed %u prefixes (%u paths)%s\n",
3187 prefix_cnt
, path_cnt
,
3188 type
? " (of requested type)" : "");
3194 * Display specified VNI (vty handler)
3196 static void evpn_show_vni(struct vty
*vty
, struct bgp
*bgp
, vni_t vni
,
3200 struct bgpevpn
*vpn
;
3202 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
3205 display_vni(vty
, vpn
, json
);
3207 struct bgp
*bgp_temp
;
3208 struct listnode
*node
= NULL
;
3210 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, node
, bgp_temp
)) {
3211 if (bgp_temp
->l3vni
== vni
) {
3213 display_l3vni(vty
, bgp_temp
, json
);
3220 vty_out(vty
, "{}\n");
3222 vty_out(vty
, "VNI not found\n");
3229 * Display a VNI (upon user query).
3231 static void evpn_show_all_vnis(struct vty
*vty
, struct bgp
*bgp
,
3235 struct bgp
*bgp_temp
= NULL
;
3236 struct listnode
*node
;
3240 vty_out(vty
, "Flags: * - Kernel\n");
3241 vty_out(vty
, " %-10s %-4s %-21s %-25s %-25s %-37s\n", "VNI",
3242 "Type", "RD", "Import RT", "Export RT", "Tenant VRF");
3245 /* print all L2 VNIS */
3248 hash_iterate(bgp
->vnihash
,
3249 (void (*)(struct hash_bucket
*, void *))show_vni_entry
,
3252 /* print all L3 VNIs */
3253 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, node
, bgp_temp
))
3254 show_l3vni_entry(vty
, bgp_temp
, json
);
3258 * evpn - enable advertisement of svi MAC-IP
3260 static void evpn_set_advertise_svi_macip(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3264 if (set
&& bgp
->evpn_info
->advertise_svi_macip
)
3266 else if (!set
&& !bgp
->evpn_info
->advertise_svi_macip
)
3269 bgp
->evpn_info
->advertise_svi_macip
= set
;
3270 bgp_zebra_advertise_svi_macip(bgp
,
3271 bgp
->evpn_info
->advertise_svi_macip
, 0);
3273 if (set
&& vpn
->advertise_svi_macip
)
3275 else if (!set
&& !vpn
->advertise_svi_macip
)
3278 vpn
->advertise_svi_macip
= set
;
3279 bgp_zebra_advertise_svi_macip(bgp
, vpn
->advertise_svi_macip
,
3285 * evpn - enable advertisement of default g/w
3287 static void evpn_set_advertise_default_gw(struct bgp
*bgp
, struct bgpevpn
*vpn
)
3290 if (bgp
->advertise_gw_macip
)
3293 bgp
->advertise_gw_macip
= 1;
3294 bgp_zebra_advertise_gw_macip(bgp
, bgp
->advertise_gw_macip
, 0);
3296 if (vpn
->advertise_gw_macip
)
3299 vpn
->advertise_gw_macip
= 1;
3300 bgp_zebra_advertise_gw_macip(bgp
, vpn
->advertise_gw_macip
,
3307 * evpn - disable advertisement of default g/w
3309 static void evpn_unset_advertise_default_gw(struct bgp
*bgp
,
3310 struct bgpevpn
*vpn
)
3313 if (!bgp
->advertise_gw_macip
)
3316 bgp
->advertise_gw_macip
= 0;
3317 bgp_zebra_advertise_gw_macip(bgp
, bgp
->advertise_gw_macip
, 0);
3319 if (!vpn
->advertise_gw_macip
)
3322 vpn
->advertise_gw_macip
= 0;
3323 bgp_zebra_advertise_gw_macip(bgp
, vpn
->advertise_gw_macip
,
3330 * evpn - enable advertisement of default g/w
3332 static void evpn_process_default_originate_cmd(struct bgp
*bgp_vrf
,
3333 afi_t afi
, bool add
)
3335 safi_t safi
= SAFI_UNICAST
; /* ipv4/ipv6 unicast */
3338 /* bail if we are already advertising default route */
3339 if (evpn_default_originate_set(bgp_vrf
, afi
, safi
))
3343 SET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3344 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV4
);
3345 else if (afi
== AFI_IP6
)
3346 SET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3347 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV6
);
3349 /* bail out if we havent advertised the default route */
3350 if (!evpn_default_originate_set(bgp_vrf
, afi
, safi
))
3353 UNSET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3354 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV4
);
3355 else if (afi
== AFI_IP6
)
3356 UNSET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3357 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV6
);
3360 bgp_evpn_install_uninstall_default_route(bgp_vrf
, afi
, safi
, add
);
3364 * evpn - enable advertisement of default g/w
3366 static void evpn_set_advertise_subnet(struct bgp
*bgp
,
3367 struct bgpevpn
*vpn
)
3369 if (vpn
->advertise_subnet
)
3372 vpn
->advertise_subnet
= 1;
3373 bgp_zebra_advertise_subnet(bgp
, vpn
->advertise_subnet
, vpn
->vni
);
3377 * evpn - disable advertisement of default g/w
3379 static void evpn_unset_advertise_subnet(struct bgp
*bgp
, struct bgpevpn
*vpn
)
3381 if (!vpn
->advertise_subnet
)
3384 vpn
->advertise_subnet
= 0;
3385 bgp_zebra_advertise_subnet(bgp
, vpn
->advertise_subnet
, vpn
->vni
);
3389 * EVPN (VNI advertisement) enabled. Register with zebra.
3391 static void evpn_set_advertise_all_vni(struct bgp
*bgp
)
3393 bgp
->advertise_all_vni
= 1;
3395 bgp_zebra_advertise_all_vni(bgp
, bgp
->advertise_all_vni
);
3399 * EVPN (VNI advertisement) disabled. De-register with zebra. Cleanup VNI
3400 * cache, EVPN routes (delete and withdraw from peers).
3402 static void evpn_unset_advertise_all_vni(struct bgp
*bgp
)
3404 bgp
->advertise_all_vni
= 0;
3405 bgp_set_evpn(bgp_get_default());
3406 bgp_zebra_advertise_all_vni(bgp
, bgp
->advertise_all_vni
);
3407 bgp_evpn_cleanup_on_disable(bgp
);
3410 /* Set resolve overlay index flag */
3411 static void bgp_evpn_set_unset_resolve_overlay_index(struct bgp
*bgp
, bool set
)
3413 if (set
== bgp
->resolve_overlay_index
)
3417 bgp
->resolve_overlay_index
= true;
3418 hash_iterate(bgp
->vnihash
,
3419 (void (*)(struct hash_bucket
*, void *))
3420 bgp_evpn_handle_resolve_overlay_index_set
,
3425 (void (*)(struct hash_bucket
*, void *))
3426 bgp_evpn_handle_resolve_overlay_index_unset
,
3428 bgp
->resolve_overlay_index
= false;
3433 * EVPN - use RFC8365 to auto-derive RT
3435 static void evpn_set_advertise_autort_rfc8365(struct bgp
*bgp
)
3437 bgp
->advertise_autort_rfc8365
= 1;
3438 bgp_evpn_handle_autort_change(bgp
);
3442 * EVPN - don't use RFC8365 to auto-derive RT
3444 static void evpn_unset_advertise_autort_rfc8365(struct bgp
*bgp
)
3446 bgp
->advertise_autort_rfc8365
= 0;
3447 bgp_evpn_handle_autort_change(bgp
);
3450 static void write_vni_config(struct vty
*vty
, struct bgpevpn
*vpn
)
3453 struct listnode
*node
, *nnode
;
3454 struct ecommunity
*ecom
;
3456 if (is_vni_configured(vpn
)) {
3457 vty_out(vty
, " vni %u\n", vpn
->vni
);
3458 if (is_rd_configured(vpn
))
3459 vty_out(vty
, " rd %pRD\n", &vpn
->prd
);
3461 if (is_import_rt_configured(vpn
)) {
3462 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
,
3464 ecom_str
= ecommunity_ecom2str(
3465 ecom
, ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
3466 vty_out(vty
, " route-target import %s\n",
3468 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
3472 if (is_export_rt_configured(vpn
)) {
3473 for (ALL_LIST_ELEMENTS(vpn
->export_rtl
, node
, nnode
,
3475 ecom_str
= ecommunity_ecom2str(
3476 ecom
, ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
3477 vty_out(vty
, " route-target export %s\n",
3479 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
3483 if (vpn
->advertise_gw_macip
)
3484 vty_out(vty
, " advertise-default-gw\n");
3486 if (vpn
->advertise_svi_macip
)
3487 vty_out(vty
, " advertise-svi-ip\n");
3489 if (vpn
->advertise_subnet
)
3490 vty_out(vty
, " advertise-subnet\n");
3492 vty_out(vty
, " exit-vni\n");
3496 #include "bgpd/bgp_evpn_vty_clippy.c"
3498 DEFPY(bgp_evpn_flood_control
,
3499 bgp_evpn_flood_control_cmd
,
3500 "[no$no] flooding <disable$disable|head-end-replication$her>",
3502 "Specify handling for BUM packets\n"
3503 "Do not flood any BUM packets\n"
3504 "Flood BUM packets using head-end replication\n")
3506 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3507 enum vxlan_flood_control flood_ctrl
;
3513 flood_ctrl
= VXLAN_FLOOD_DISABLED
;
3515 flood_ctrl
= VXLAN_FLOOD_HEAD_END_REPL
;
3519 if (bgp
->vxlan_flood_ctrl
== flood_ctrl
)
3522 bgp
->vxlan_flood_ctrl
= flood_ctrl
;
3523 bgp_evpn_flood_control_change(bgp
);
3528 DEFUN (bgp_evpn_advertise_default_gw_vni
,
3529 bgp_evpn_advertise_default_gw_vni_cmd
,
3530 "advertise-default-gw",
3531 "Advertise default g/w mac-ip routes in EVPN for a VNI\n")
3533 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3534 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
3539 evpn_set_advertise_default_gw(bgp
, vpn
);
3544 DEFUN (no_bgp_evpn_advertise_default_vni_gw
,
3545 no_bgp_evpn_advertise_default_gw_vni_cmd
,
3546 "no advertise-default-gw",
3548 "Withdraw default g/w mac-ip routes from EVPN for a VNI\n")
3550 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3551 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
3556 evpn_unset_advertise_default_gw(bgp
, vpn
);
3562 DEFUN (bgp_evpn_advertise_default_gw
,
3563 bgp_evpn_advertise_default_gw_cmd
,
3564 "advertise-default-gw",
3565 "Advertise All default g/w mac-ip routes in EVPN\n")
3567 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3572 if (!EVPN_ENABLED(bgp
)) {
3574 "This command is only supported under the EVPN VRF\n");
3578 evpn_set_advertise_default_gw(bgp
, NULL
);
3583 DEFUN (no_bgp_evpn_advertise_default_gw
,
3584 no_bgp_evpn_advertise_default_gw_cmd
,
3585 "no advertise-default-gw",
3587 "Withdraw All default g/w mac-ip routes from EVPN\n")
3589 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3594 evpn_unset_advertise_default_gw(bgp
, NULL
);
3599 DEFUN (bgp_evpn_advertise_all_vni
,
3600 bgp_evpn_advertise_all_vni_cmd
,
3601 "advertise-all-vni",
3602 "Advertise All local VNIs\n")
3604 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3605 struct bgp
*bgp_evpn
= NULL
;
3610 bgp_evpn
= bgp_get_evpn();
3611 if (bgp_evpn
&& bgp_evpn
!= bgp
) {
3612 vty_out(vty
, "%% Please unconfigure EVPN in %s\n",
3613 bgp_evpn
->name_pretty
);
3614 return CMD_WARNING_CONFIG_FAILED
;
3617 evpn_set_advertise_all_vni(bgp
);
3621 DEFUN (no_bgp_evpn_advertise_all_vni
,
3622 no_bgp_evpn_advertise_all_vni_cmd
,
3623 "no advertise-all-vni",
3625 "Advertise All local VNIs\n")
3627 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3631 evpn_unset_advertise_all_vni(bgp
);
3635 DEFUN (bgp_evpn_advertise_autort_rfc8365
,
3636 bgp_evpn_advertise_autort_rfc8365_cmd
,
3637 "autort rfc8365-compatible",
3638 "Auto-derivation of RT\n"
3639 "Auto-derivation of RT using RFC8365\n")
3641 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3645 evpn_set_advertise_autort_rfc8365(bgp
);
3649 DEFUN (no_bgp_evpn_advertise_autort_rfc8365
,
3650 no_bgp_evpn_advertise_autort_rfc8365_cmd
,
3651 "no autort rfc8365-compatible",
3653 "Auto-derivation of RT\n"
3654 "Auto-derivation of RT using RFC8365\n")
3656 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3660 evpn_unset_advertise_autort_rfc8365(bgp
);
3664 DEFUN (bgp_evpn_default_originate
,
3665 bgp_evpn_default_originate_cmd
,
3666 "default-originate <ipv4 | ipv6>",
3667 "originate a default route\n"
3668 "ipv4 address family\n"
3669 "ipv6 address family\n")
3673 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
);
3677 argv_find_and_parse_afi(argv
, argc
, &idx_afi
, &afi
);
3678 evpn_process_default_originate_cmd(bgp_vrf
, afi
, true);
3682 DEFUN (no_bgp_evpn_default_originate
,
3683 no_bgp_evpn_default_originate_cmd
,
3684 "no default-originate <ipv4 | ipv6>",
3686 "withdraw a default route\n"
3687 "ipv4 address family\n"
3688 "ipv6 address family\n")
3692 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
);
3696 argv_find_and_parse_afi(argv
, argc
, &idx_afi
, &afi
);
3697 evpn_process_default_originate_cmd(bgp_vrf
, afi
, false);
3701 DEFPY (dup_addr_detection
,
3702 dup_addr_detection_cmd
,
3703 "dup-addr-detection [max-moves (2-1000)$max_moves_val time (2-1800)$time_val]",
3704 "Duplicate address detection\n"
3705 "Max allowed moves before address detected as duplicate\n"
3706 "Num of max allowed moves (2-1000) default 5\n"
3707 "Duplicate address detection time\n"
3708 "Time in seconds (2-1800) default 180\n")
3710 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
);
3715 if (!EVPN_ENABLED(bgp_vrf
)) {
3717 "This command is only supported under the EVPN VRF\n");
3721 bgp_vrf
->evpn_info
->dup_addr_detect
= true;
3724 bgp_vrf
->evpn_info
->dad_time
= time_val
;
3726 bgp_vrf
->evpn_info
->dad_max_moves
= max_moves_val
;
3728 bgp_zebra_dup_addr_detection(bgp_vrf
);
3733 DEFPY (dup_addr_detection_auto_recovery
,
3734 dup_addr_detection_auto_recovery_cmd
,
3735 "dup-addr-detection freeze <permanent |(30-3600)$freeze_time_val>",
3736 "Duplicate address detection\n"
3737 "Duplicate address detection freeze\n"
3738 "Duplicate address detection permanent freeze\n"
3739 "Duplicate address detection freeze time (30-3600)\n")
3741 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
);
3742 uint32_t freeze_time
= freeze_time_val
;
3747 if (!EVPN_ENABLED(bgp_vrf
)) {
3749 "This command is only supported under the EVPN VRF\n");
3753 bgp_vrf
->evpn_info
->dup_addr_detect
= true;
3754 bgp_vrf
->evpn_info
->dad_freeze
= true;
3755 bgp_vrf
->evpn_info
->dad_freeze_time
= freeze_time
;
3757 bgp_zebra_dup_addr_detection(bgp_vrf
);
3762 DEFPY (no_dup_addr_detection
,
3763 no_dup_addr_detection_cmd
,
3764 "no dup-addr-detection [max-moves (2-1000)$max_moves_val time (2-1800)$time_val | freeze <permanent$permanent_val | (30-3600)$freeze_time_val>]",
3766 "Duplicate address detection\n"
3767 "Max allowed moves before address detected as duplicate\n"
3768 "Num of max allowed moves (2-1000) default 5\n"
3769 "Duplicate address detection time\n"
3770 "Time in seconds (2-1800) default 180\n"
3771 "Duplicate address detection freeze\n"
3772 "Duplicate address detection permanent freeze\n"
3773 "Duplicate address detection freeze time (30-3600)\n")
3775 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
);
3776 uint32_t max_moves
= (uint32_t)max_moves_val
;
3777 uint32_t freeze_time
= (uint32_t)freeze_time_val
;
3782 if (!EVPN_ENABLED(bgp_vrf
)) {
3784 "This command is only supported under the EVPN VRF\n");
3789 if (!bgp_vrf
->evpn_info
->dup_addr_detect
)
3791 /* Reset all parameters to default. */
3792 bgp_vrf
->evpn_info
->dup_addr_detect
= false;
3793 bgp_vrf
->evpn_info
->dad_time
= EVPN_DAD_DEFAULT_TIME
;
3794 bgp_vrf
->evpn_info
->dad_max_moves
= EVPN_DAD_DEFAULT_MAX_MOVES
;
3795 bgp_vrf
->evpn_info
->dad_freeze
= false;
3796 bgp_vrf
->evpn_info
->dad_freeze_time
= 0;
3799 if (bgp_vrf
->evpn_info
->dad_max_moves
!= max_moves
) {
3801 "%% Value does not match with config\n");
3804 bgp_vrf
->evpn_info
->dad_max_moves
=
3805 EVPN_DAD_DEFAULT_MAX_MOVES
;
3809 if (bgp_vrf
->evpn_info
->dad_time
!= time_val
) {
3811 "%% Value does not match with config\n");
3814 bgp_vrf
->evpn_info
->dad_time
= EVPN_DAD_DEFAULT_TIME
;
3818 if (bgp_vrf
->evpn_info
->dad_freeze_time
3821 "%% Value does not match with config\n");
3824 bgp_vrf
->evpn_info
->dad_freeze_time
= 0;
3825 bgp_vrf
->evpn_info
->dad_freeze
= false;
3828 if (permanent_val
) {
3829 if (bgp_vrf
->evpn_info
->dad_freeze_time
) {
3831 "%% Value does not match with config\n");
3834 bgp_vrf
->evpn_info
->dad_freeze
= false;
3838 bgp_zebra_dup_addr_detection(bgp_vrf
);
3843 DEFPY(bgp_evpn_advertise_svi_ip
,
3844 bgp_evpn_advertise_svi_ip_cmd
,
3845 "[no$no] advertise-svi-ip",
3847 "Advertise svi mac-ip routes in EVPN\n")
3849 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3855 evpn_set_advertise_svi_macip(bgp
, NULL
, 0);
3857 if (!EVPN_ENABLED(bgp
)) {
3859 "This command is only supported under EVPN VRF\n");
3862 evpn_set_advertise_svi_macip(bgp
, NULL
, 1);
3868 DEFPY(bgp_evpn_advertise_svi_ip_vni
,
3869 bgp_evpn_advertise_svi_ip_vni_cmd
,
3870 "[no$no] advertise-svi-ip",
3872 "Advertise svi mac-ip routes in EVPN for a VNI\n")
3874 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3875 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
3881 evpn_set_advertise_svi_macip(bgp
, vpn
, 0);
3883 evpn_set_advertise_svi_macip(bgp
, vpn
, 1);
3888 DEFUN_HIDDEN (bgp_evpn_advertise_vni_subnet
,
3889 bgp_evpn_advertise_vni_subnet_cmd
,
3891 "Advertise the subnet corresponding to VNI\n")
3893 struct bgp
*bgp_vrf
= NULL
;
3894 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3895 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
3900 bgp_vrf
= bgp_lookup_by_vrf_id(vpn
->tenant_vrf_id
);
3904 evpn_set_advertise_subnet(bgp
, vpn
);
3908 DEFUN_HIDDEN (no_bgp_evpn_advertise_vni_subnet
,
3909 no_bgp_evpn_advertise_vni_subnet_cmd
,
3910 "no advertise-subnet",
3912 "Advertise All local VNIs\n")
3914 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3915 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
3920 evpn_unset_advertise_subnet(bgp
, vpn
);
3924 DEFUN (bgp_evpn_advertise_type5
,
3925 bgp_evpn_advertise_type5_cmd
,
3926 "advertise " BGP_AFI_CMD_STR
"" BGP_SAFI_CMD_STR
" [gateway-ip] [route-map RMAP_NAME]",
3927 "Advertise prefix routes\n"
3930 "advertise gateway IP overlay index\n"
3931 "route-map for filtering specific routes\n"
3932 "Name of the route map\n")
3934 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
); /* bgp vrf instance */
3941 int rmap_changed
= 0;
3942 enum overlay_index_type oly
= OVERLAY_INDEX_TYPE_NONE
;
3944 bool adv_flag_changed
= false;
3946 argv_find_and_parse_afi(argv
, argc
, &idx_afi
, &afi
);
3947 argv_find_and_parse_safi(argv
, argc
, &idx_safi
, &safi
);
3948 argv_find_and_parse_oly_idx(argv
, argc
, &idx_oly
, &oly
);
3950 ret
= argv_find(argv
, argc
, "route-map", &idx_rmap
);
3952 if (!bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
)
3954 else if (strcmp(argv
[idx_rmap
+ 1]->arg
,
3955 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
)
3958 } else if (bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
) {
3962 if (!(afi
== AFI_IP
|| afi
== AFI_IP6
)) {
3964 "%% Only ipv4 or ipv6 address families are supported\n");
3968 if (safi
!= SAFI_UNICAST
) {
3970 "%% Only ipv4 unicast or ipv6 unicast are supported\n");
3974 if ((oly
!= OVERLAY_INDEX_TYPE_NONE
)
3975 && (oly
!= OVERLAY_INDEX_GATEWAY_IP
)) {
3976 vty_out(vty
, "%% Unknown overlay-index type specified\n");
3980 if (afi
== AFI_IP
) {
3981 if ((!CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3982 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST
))
3983 && (!CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3984 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP
))) {
3987 * this is the case for first time ever configuration
3988 * adv ipv4 unicast is enabled for the first time.
3989 * So no need to reset any flag
3991 if (oly
== OVERLAY_INDEX_TYPE_NONE
)
3993 bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3994 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST
);
3995 else if (oly
== OVERLAY_INDEX_GATEWAY_IP
)
3997 bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3998 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP
);
3999 } else if ((oly
== OVERLAY_INDEX_TYPE_NONE
)
4001 bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4002 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST
))) {
4005 * This is modify case from gateway-ip
4006 * to no overlay index
4008 adv_flag_changed
= true;
4009 UNSET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4010 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP
);
4011 SET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4012 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST
);
4013 } else if ((oly
== OVERLAY_INDEX_GATEWAY_IP
)
4015 bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4016 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP
))) {
4019 * This is modify case from no overlay index
4022 adv_flag_changed
= true;
4023 UNSET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4024 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST
);
4025 SET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4026 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP
);
4030 * Command is issued with the same option
4031 * (no overlay index or gateway-ip) which was
4032 * already configured. So nothing to do.
4033 * However, route-map may have been modified.
4034 * check if route-map has been modified.
4035 * If not, return an error
4041 if ((!CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4042 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST
))
4043 && (!CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4044 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP
))) {
4047 * this is the case for first time ever configuration
4048 * adv ipv6 unicast is enabled for the first time.
4049 * So no need to reset any flag
4051 if (oly
== OVERLAY_INDEX_TYPE_NONE
)
4053 bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4054 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST
);
4055 else if (oly
== OVERLAY_INDEX_GATEWAY_IP
)
4057 bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4058 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP
);
4059 } else if ((oly
== OVERLAY_INDEX_TYPE_NONE
)
4061 bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4062 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST
))) {
4065 * This is modify case from gateway-ip
4066 * to no overlay index
4068 adv_flag_changed
= true;
4069 UNSET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4070 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP
);
4071 SET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4072 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST
);
4073 } else if ((oly
== OVERLAY_INDEX_GATEWAY_IP
)
4075 bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4076 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP
))) {
4079 * This is modify case from no overlay index
4082 adv_flag_changed
= true;
4083 UNSET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4084 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST
);
4085 SET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4086 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP
);
4090 * Command is issued with the same option
4091 * (no overlay index or gateway-ip) which was
4092 * already configured. So nothing to do.
4093 * However, route-map may have been modified.
4094 * check if route-map has been modified.
4095 * If not, return an error
4102 if ((rmap_changed
) || (adv_flag_changed
)) {
4104 /* If either of these are changed, then FRR needs to
4105 * withdraw already advertised type5 routes.
4107 bgp_evpn_withdraw_type5_routes(bgp_vrf
, afi
, safi
);
4109 if (bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
) {
4110 XFREE(MTYPE_ROUTE_MAP_NAME
,
4111 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
);
4112 route_map_counter_decrement(
4113 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].map
);
4114 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
= NULL
;
4115 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].map
= NULL
;
4120 /* set the route-map for advertise command */
4121 if (ret
&& argv
[idx_rmap
+ 1]->arg
) {
4122 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
=
4123 XSTRDUP(MTYPE_ROUTE_MAP_NAME
, argv
[idx_rmap
+ 1]->arg
);
4124 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].map
=
4125 route_map_lookup_by_name(argv
[idx_rmap
+ 1]->arg
);
4126 route_map_counter_increment(
4127 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].map
);
4130 /* advertise type-5 routes */
4131 if (advertise_type5_routes(bgp_vrf
, afi
))
4132 bgp_evpn_advertise_type5_routes(bgp_vrf
, afi
, safi
);
4136 DEFUN (no_bgp_evpn_advertise_type5
,
4137 no_bgp_evpn_advertise_type5_cmd
,
4138 "no advertise " BGP_AFI_CMD_STR
"" BGP_SAFI_CMD_STR
" [route-map WORD]",
4140 "Advertise prefix routes\n"
4143 "route-map for filtering specific routes\n"
4144 "Name of the route map\n")
4146 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
); /* bgp vrf instance */
4155 argv_find_and_parse_afi(argv
, argc
, &idx_afi
, &afi
);
4156 argv_find_and_parse_safi(argv
, argc
, &idx_safi
, &safi
);
4158 if (!(afi
== AFI_IP
|| afi
== AFI_IP6
)) {
4160 "%% Only ipv4 or ipv6 address families are supported\n");
4164 if (safi
!= SAFI_UNICAST
) {
4166 "%% Only ipv4 unicast or ipv6 unicast are supported\n");
4170 if (afi
== AFI_IP
) {
4172 /* if we are not advertising ipv4 prefix as type-5
4175 if ((CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4176 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST
)) ||
4177 (CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4178 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP
))) {
4179 bgp_evpn_withdraw_type5_routes(bgp_vrf
, afi
, safi
);
4180 UNSET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4181 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST
);
4182 UNSET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4183 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP
);
4187 /* if we are not advertising ipv6 prefix as type-5
4190 if ((CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4191 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST
)) ||
4192 (CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4193 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP
))){
4194 bgp_evpn_withdraw_type5_routes(bgp_vrf
, afi
, safi
);
4195 UNSET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4196 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST
);
4197 UNSET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4198 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP
);
4202 /* clear the route-map information for advertise ipv4/ipv6 unicast */
4203 if (bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
) {
4204 XFREE(MTYPE_ROUTE_MAP_NAME
,
4205 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
);
4206 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
= NULL
;
4207 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].map
= NULL
;
4213 DEFPY (bgp_evpn_use_es_l3nhg
,
4214 bgp_evpn_use_es_l3nhg_cmd
,
4215 "[no$no] use-es-l3nhg",
4217 "use L3 nexthop group for host routes with ES destination\n")
4219 bgp_mh_info
->host_routes_use_l3nhg
= no
? false :true;
4223 DEFPY (bgp_evpn_ead_evi_rx_disable
,
4224 bgp_evpn_ead_evi_rx_disable_cmd
,
4225 "[no$no] disable-ead-evi-rx",
4227 "Activate PE on EAD-ES even if EAD-EVI is not received\n")
4229 bool ead_evi_rx
= no
? true :false;
4231 if (ead_evi_rx
!= bgp_mh_info
->ead_evi_rx
) {
4232 bgp_mh_info
->ead_evi_rx
= ead_evi_rx
;
4233 bgp_evpn_switch_ead_evi_rx();
4238 DEFPY (bgp_evpn_ead_evi_tx_disable
,
4239 bgp_evpn_ead_evi_tx_disable_cmd
,
4240 "[no$no] disable-ead-evi-tx",
4242 "Don't advertise EAD-EVI for local ESs\n")
4244 bgp_mh_info
->ead_evi_tx
= no
? true :false;
4248 DEFPY (bgp_evpn_enable_resolve_overlay_index
,
4249 bgp_evpn_enable_resolve_overlay_index_cmd
,
4250 "[no$no] enable-resolve-overlay-index",
4252 "Enable Recursive Resolution of type-5 route overlay index\n")
4254 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
4256 if (bgp
!= bgp_get_evpn()) {
4257 vty_out(vty
, "This command is only supported under EVPN VRF\n");
4261 bgp_evpn_set_unset_resolve_overlay_index(bgp
, no
? false : true);
4265 DEFPY (bgp_evpn_advertise_pip_ip_mac
,
4266 bgp_evpn_advertise_pip_ip_mac_cmd
,
4267 "[no$no] advertise-pip [ip <A.B.C.D> [mac <X:X:X:X:X:X|X:X:X:X:X:X/M>]]",
4269 "evpn system primary IP\n"
4272 MAC_STR MAC_STR MAC_STR
)
4274 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
); /* bgp vrf instance */
4275 struct bgp
*bgp_evpn
= NULL
;
4277 if (EVPN_ENABLED(bgp_vrf
)) {
4279 "This command is supported under L3VNI BGP EVPN VRF\n");
4280 return CMD_WARNING_CONFIG_FAILED
;
4282 bgp_evpn
= bgp_get_evpn();
4285 /* pip is already enabled */
4286 if (argc
== 1 && bgp_vrf
->evpn_info
->advertise_pip
)
4289 bgp_vrf
->evpn_info
->advertise_pip
= true;
4290 if (ip
.s_addr
!= INADDR_ANY
) {
4291 /* Already configured with same IP */
4292 if (IPV4_ADDR_SAME(&ip
,
4293 &bgp_vrf
->evpn_info
->pip_ip_static
))
4296 bgp_vrf
->evpn_info
->pip_ip_static
= ip
;
4297 bgp_vrf
->evpn_info
->pip_ip
= ip
;
4299 bgp_vrf
->evpn_info
->pip_ip_static
.s_addr
4301 /* default instance router-id assignemt */
4303 bgp_vrf
->evpn_info
->pip_ip
=
4304 bgp_evpn
->router_id
;
4307 if (!is_zero_mac(&mac
->eth_addr
)) {
4308 /* Already configured with same MAC */
4309 if (memcmp(&bgp_vrf
->evpn_info
->pip_rmac_static
,
4310 &mac
->eth_addr
, ETH_ALEN
) == 0)
4313 memcpy(&bgp_vrf
->evpn_info
->pip_rmac_static
,
4314 &mac
->eth_addr
, ETH_ALEN
);
4315 memcpy(&bgp_vrf
->evpn_info
->pip_rmac
,
4316 &bgp_vrf
->evpn_info
->pip_rmac_static
,
4319 /* Copy zebra sys mac */
4320 if (!is_zero_mac(&bgp_vrf
->evpn_info
->pip_rmac_zebra
))
4321 memcpy(&bgp_vrf
->evpn_info
->pip_rmac
,
4322 &bgp_vrf
->evpn_info
->pip_rmac_zebra
,
4327 if (!bgp_vrf
->evpn_info
->advertise_pip
)
4329 /* Disable PIP feature */
4330 bgp_vrf
->evpn_info
->advertise_pip
= false;
4331 /* copy anycast mac */
4332 memcpy(&bgp_vrf
->evpn_info
->pip_rmac
,
4333 &bgp_vrf
->rmac
, ETH_ALEN
);
4335 /* remove MAC-IP option retain PIP knob. */
4336 if ((ip
.s_addr
!= INADDR_ANY
) &&
4337 !IPV4_ADDR_SAME(&ip
,
4338 &bgp_vrf
->evpn_info
->pip_ip_static
)) {
4340 "%% BGP EVPN PIP IP does not match\n");
4341 return CMD_WARNING_CONFIG_FAILED
;
4344 if (!is_zero_mac(&mac
->eth_addr
) &&
4345 memcmp(&bgp_vrf
->evpn_info
->pip_rmac_static
,
4346 &mac
->eth_addr
, ETH_ALEN
) != 0) {
4348 "%% BGP EVPN PIP MAC does not match\n");
4349 return CMD_WARNING_CONFIG_FAILED
;
4351 /* pip_rmac can carry vrr_rmac reset only if it matches
4352 * with static value.
4354 if (memcmp(&bgp_vrf
->evpn_info
->pip_rmac
,
4355 &bgp_vrf
->evpn_info
->pip_rmac_static
,
4357 /* Copy zebra sys mac */
4359 &bgp_vrf
->evpn_info
->pip_rmac_zebra
))
4360 memcpy(&bgp_vrf
->evpn_info
->pip_rmac
,
4361 &bgp_vrf
->evpn_info
->pip_rmac_zebra
,
4364 /* copy anycast mac */
4365 memcpy(&bgp_vrf
->evpn_info
->pip_rmac
,
4366 &bgp_vrf
->rmac
, ETH_ALEN
);
4370 /* reset user configured sys MAC */
4371 memset(&bgp_vrf
->evpn_info
->pip_rmac_static
, 0, ETH_ALEN
);
4372 /* reset user configured sys IP */
4373 bgp_vrf
->evpn_info
->pip_ip_static
.s_addr
= INADDR_ANY
;
4374 /* Assign default PIP IP (bgp instance router-id) */
4376 bgp_vrf
->evpn_info
->pip_ip
= bgp_evpn
->router_id
;
4378 bgp_vrf
->evpn_info
->pip_ip
.s_addr
= INADDR_ANY
;
4381 if (is_evpn_enabled()) {
4382 struct listnode
*node
= NULL
;
4383 struct bgpevpn
*vpn
= NULL
;
4386 * At this point if bgp_evpn is NULL and evpn is enabled
4387 * something stupid has gone wrong
4391 update_advertise_vrf_routes(bgp_vrf
);
4393 /* Update (svi) type-2 routes */
4394 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
)) {
4395 if (!bgp_evpn_is_svi_macip_enabled(vpn
))
4397 update_routes_for_vni(bgp_evpn
, vpn
);
4405 * Display VNI information - for all or a specific VNI
4407 DEFUN(show_bgp_l2vpn_evpn_vni
,
4408 show_bgp_l2vpn_evpn_vni_cmd
,
4409 "show bgp l2vpn evpn vni [" CMD_VNI_RANGE
"] [json]",
4418 struct bgp
*bgp_evpn
;
4422 json_object
*json
= NULL
;
4423 uint32_t num_l2vnis
= 0;
4424 uint32_t num_l3vnis
= 0;
4425 uint32_t num_vnis
= 0;
4426 struct listnode
*node
= NULL
;
4427 struct bgp
*bgp_temp
= NULL
;
4429 uj
= use_json(argc
, argv
);
4431 bgp_evpn
= bgp_get_evpn();
4435 if (!argv_find(argv
, argc
, "evpn", &idx
))
4439 json
= json_object_new_object();
4441 if ((uj
&& argc
== ((idx
+ 1) + 2)) || (!uj
&& argc
== (idx
+ 1) + 1)) {
4443 num_l2vnis
= hashcount(bgp_evpn
->vnihash
);
4445 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, node
, bgp_temp
)) {
4446 if (bgp_temp
->l3vni
)
4449 num_vnis
= num_l2vnis
+ num_l3vnis
;
4451 json_object_string_add(json
, "advertiseGatewayMacip",
4452 bgp_evpn
->advertise_gw_macip
4455 json_object_string_add(json
, "advertiseSviMacIp",
4456 bgp_evpn
->evpn_info
->advertise_svi_macip
4457 ? "Enabled" : "Disabled");
4458 json_object_string_add(json
, "advertiseAllVnis",
4459 is_evpn_enabled() ? "Enabled"
4461 json_object_string_add(
4463 bgp_evpn
->vxlan_flood_ctrl
==
4464 VXLAN_FLOOD_HEAD_END_REPL
4465 ? "Head-end replication"
4467 json_object_string_add(
4468 json
, "vxlanFlooding",
4469 bgp_evpn
->vxlan_flood_ctrl
==
4470 VXLAN_FLOOD_HEAD_END_REPL
4473 json_object_int_add(json
, "numVnis", num_vnis
);
4474 json_object_int_add(json
, "numL2Vnis", num_l2vnis
);
4475 json_object_int_add(json
, "numL3Vnis", num_l3vnis
);
4477 vty_out(vty
, "Advertise Gateway Macip: %s\n",
4478 bgp_evpn
->advertise_gw_macip
? "Enabled"
4480 vty_out(vty
, "Advertise SVI Macip: %s\n",
4481 bgp_evpn
->evpn_info
->advertise_svi_macip
? "Enabled"
4483 vty_out(vty
, "Advertise All VNI flag: %s\n",
4484 is_evpn_enabled() ? "Enabled" : "Disabled");
4485 vty_out(vty
, "BUM flooding: %s\n",
4486 bgp_evpn
->vxlan_flood_ctrl
==
4487 VXLAN_FLOOD_HEAD_END_REPL
4488 ? "Head-end replication"
4490 vty_out(vty
, "VXLAN flooding: %s\n",
4491 bgp_evpn
->vxlan_flood_ctrl
==
4492 VXLAN_FLOOD_HEAD_END_REPL
4495 vty_out(vty
, "Number of L2 VNIs: %u\n", num_l2vnis
);
4496 vty_out(vty
, "Number of L3 VNIs: %u\n", num_l3vnis
);
4498 evpn_show_all_vnis(vty
, bgp_evpn
, json
);
4502 if (!argv_find(argv
, argc
, "vni", &vni_idx
))
4505 /* Display specific VNI */
4506 vni
= strtoul(argv
[vni_idx
+ 1]->arg
, NULL
, 10);
4507 evpn_show_vni(vty
, bgp_evpn
, vni
, json
);
4511 vty_json(vty
, json
);
4516 DEFUN_HIDDEN(show_bgp_l2vpn_evpn_vni_remote_ip_hash
,
4517 show_bgp_l2vpn_evpn_vni_remote_ip_hash_cmd
,
4518 "show bgp l2vpn evpn vni remote-ip-hash",
4526 struct bgp
*bgp_evpn
;
4529 bgp_evpn
= bgp_get_evpn();
4533 if (!argv_find(argv
, argc
, "evpn", &idx
))
4536 hash_iterate(bgp_evpn
->vnihash
,
4537 (void (*)(struct hash_bucket
*,
4538 void *))bgp_evpn_show_remote_ip_hash
,
4544 DEFUN_HIDDEN(show_bgp_l2vpn_evpn_vni_svi_hash
,
4545 show_bgp_l2vpn_evpn_vni_svi_hash_cmd
,
4546 "show bgp l2vpn evpn vni-svi-hash",
4551 "Show vni-svi-hash\n")
4553 struct bgp
*bgp_evpn
;
4556 bgp_evpn
= bgp_get_evpn();
4560 if (!argv_find(argv
, argc
, "evpn", &idx
))
4563 hash_iterate(bgp_evpn
->vni_svi_hash
,
4564 (void (*)(struct hash_bucket
*,
4565 void *))bgp_evpn_show_vni_svi_hash
,
4571 DEFPY(show_bgp_l2vpn_evpn_es_evi
,
4572 show_bgp_l2vpn_evpn_es_evi_cmd
,
4573 "show bgp l2vpn evpn es-evi [vni (1-16777215)$vni] [json$uj] [detail$detail]",
4579 "VxLAN Network Identifier\n"
4582 "Detailed information\n")
4585 bgp_evpn_es_evi_show_vni(vty
, vni
, !!uj
, !!detail
);
4587 bgp_evpn_es_evi_show(vty
, !!uj
, !!detail
);
4592 DEFPY(show_bgp_l2vpn_evpn_es
,
4593 show_bgp_l2vpn_evpn_es_cmd
,
4594 "show bgp l2vpn evpn es [NAME$esi_str|detail$detail] [json$uj]",
4599 "Ethernet Segment\n"
4601 "Detailed information\n"
4607 if (!str_to_esi(esi_str
, &esi
)) {
4608 vty_out(vty
, "%% Malformed ESI\n");
4611 bgp_evpn_es_show_esi(vty
, &esi
, uj
);
4614 bgp_evpn_es_show(vty
, uj
, !!detail
);
4620 DEFPY(show_bgp_l2vpn_evpn_es_vrf
, show_bgp_l2vpn_evpn_es_vrf_cmd
,
4621 "show bgp l2vpn evpn es-vrf [NAME$esi_str] [json$uj]",
4622 SHOW_STR BGP_STR L2VPN_HELP_STR EVPN_HELP_STR
4623 "Ethernet Segment\n"
4629 if (!str_to_esi(esi_str
, &esi
)) {
4630 vty_out(vty
, "%% Malformed ESI\n");
4633 bgp_evpn_es_vrf_show_esi(vty
, &esi
, uj
);
4636 bgp_evpn_es_vrf_show(vty
, uj
, NULL
);
4642 DEFPY(show_bgp_l2vpn_evpn_nh
,
4643 show_bgp_l2vpn_evpn_nh_cmd
,
4644 "show bgp l2vpn evpn next-hops [json$uj]",
4652 bgp_evpn_nh_show(vty
, uj
);
4658 * Display EVPN neighbor summary.
4660 DEFUN(show_bgp_l2vpn_evpn_summary
, show_bgp_l2vpn_evpn_summary_cmd
,
4661 "show bgp [vrf VRFNAME] l2vpn evpn summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <(1-4294967295)|internal|external>>] [terse] [wide] [json]",
4664 "vrf name\n" L2VPN_HELP_STR EVPN_HELP_STR
4665 "Summary of BGP neighbor status\n"
4666 "Show only sessions in Established state\n"
4667 "Show only sessions not in Established state\n"
4668 "Show only the specified neighbor session\n"
4669 "Neighbor to display information about\n"
4670 "Neighbor to display information about\n"
4671 "Neighbor on BGP configured interface\n"
4672 "Show only the specified remote AS sessions\n"
4674 "Internal (iBGP) AS sessions\n"
4675 "External (eBGP) AS sessions\n"
4676 "Shorten the information on BGP instances\n"
4677 "Increase table width for longer output\n" JSON_STR
)
4682 char *neighbor
= NULL
;
4683 as_t as
= 0; /* 0 means AS filter not set */
4684 int as_type
= AS_UNSPECIFIED
;
4685 uint16_t show_flags
= 0;
4687 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
4688 vrf
= argv
[++idx_vrf
]->arg
;
4690 if (argv_find(argv
, argc
, "failed", &idx
))
4691 SET_FLAG(show_flags
, BGP_SHOW_OPT_FAILED
);
4693 if (argv_find(argv
, argc
, "established", &idx
))
4694 SET_FLAG(show_flags
, BGP_SHOW_OPT_ESTABLISHED
);
4697 if (argv_find(argv
, argc
, "neighbor", &idx
))
4698 neighbor
= argv
[idx
+ 1]->arg
;
4700 if (argv_find(argv
, argc
, "remote-as", &idx
)) {
4701 if (argv
[idx
+ 1]->arg
[0] == 'i')
4702 as_type
= AS_INTERNAL
;
4703 else if (argv
[idx
+ 1]->arg
[0] == 'e')
4704 as_type
= AS_EXTERNAL
;
4706 as
= (as_t
)atoi(argv
[idx
+ 1]->arg
);
4709 if (argv_find(argv
, argc
, "terse", &idx
))
4710 SET_FLAG(show_flags
, BGP_SHOW_OPT_TERSE
);
4712 if (argv_find(argv
, argc
, "wide", &idx
))
4713 SET_FLAG(show_flags
, BGP_SHOW_OPT_WIDE
);
4715 if (use_json(argc
, argv
))
4716 SET_FLAG(show_flags
, BGP_SHOW_OPT_JSON
);
4718 return bgp_show_summary_vty(vty
, vrf
, AFI_L2VPN
, SAFI_EVPN
, neighbor
,
4719 as_type
, as
, show_flags
);
4722 static int bgp_evpn_cli_parse_type_cmp(int *type
, const char *type_str
)
4724 if ((strncmp(type_str
, "ma", 2) == 0) || (strmatch(type_str
, "2")))
4725 *type
= BGP_EVPN_MAC_IP_ROUTE
;
4726 else if ((strncmp(type_str
, "mu", 2) == 0) || (strmatch(type_str
, "3")))
4727 *type
= BGP_EVPN_IMET_ROUTE
;
4728 else if ((strncmp(type_str
, "es", 2) == 0) || (strmatch(type_str
, "4")))
4729 *type
= BGP_EVPN_ES_ROUTE
;
4730 else if ((strncmp(type_str
, "ea", 2) == 0) || (strmatch(type_str
, "1")))
4731 *type
= BGP_EVPN_AD_ROUTE
;
4732 else if ((strncmp(type_str
, "p", 1) == 0) || (strmatch(type_str
, "5")))
4733 *type
= BGP_EVPN_IP_PREFIX_ROUTE
;
4740 int bgp_evpn_cli_parse_type(int *type
, struct cmd_token
**argv
, int argc
)
4744 if (argv_find(argv
, argc
, "type", &type_idx
)) {
4745 /* Specific type is requested */
4746 if (bgp_evpn_cli_parse_type_cmp(type
,
4747 argv
[type_idx
+ 1]->arg
) != 0)
4755 * Display global EVPN routing table.
4757 DEFUN(show_bgp_l2vpn_evpn_route
,
4758 show_bgp_l2vpn_evpn_route_cmd
,
4759 "show bgp l2vpn evpn route [detail] [type "EVPN_TYPE_ALL_LIST
"] [json]",
4765 "Display Detailed Information\n"
4767 EVPN_TYPE_ALL_LIST_HELP_STR
4774 json_object
*json
= NULL
;
4776 uj
= use_json(argc
, argv
);
4778 bgp
= bgp_get_evpn();
4783 json
= json_object_new_object();
4785 if (bgp_evpn_cli_parse_type(&type
, argv
, argc
) < 0)
4788 if (argv_find(argv
, argc
, "detail", &detail
))
4791 evpn_show_all_routes(vty
, bgp
, type
, json
, detail
);
4794 vty_json(vty
, json
);
4799 * Display global EVPN routing table for specific RD.
4801 DEFUN(show_bgp_l2vpn_evpn_route_rd
,
4802 show_bgp_l2vpn_evpn_route_rd_cmd
,
4803 "show bgp l2vpn evpn route rd <ASN:NN_OR_IP-ADDRESS:NN|all> [type "EVPN_TYPE_ALL_LIST
"] [json]",
4809 EVPN_RT_DIST_HELP_STR
4810 EVPN_ASN_IP_HELP_STR
4811 "All VPN Route Distinguishers\n"
4813 EVPN_TYPE_ALL_LIST_HELP_STR
4818 struct prefix_rd prd
;
4821 json_object
*json
= NULL
;
4822 int idx_ext_community
= 0;
4825 bgp
= bgp_get_evpn();
4829 /* check if we need json output */
4830 uj
= use_json(argc
, argv
);
4832 json
= json_object_new_object();
4834 if (!argv_find(argv
, argc
, "all", &rd_all
)) {
4836 if (argv_find(argv
, argc
, "ASN:NN_OR_IP-ADDRESS:NN",
4837 &idx_ext_community
)) {
4838 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
4841 "%% Malformed Route Distinguisher\n");
4847 if (bgp_evpn_cli_parse_type(&type
, argv
, argc
) < 0)
4851 evpn_show_all_routes(vty
, bgp
, type
, json
, 1);
4853 evpn_show_route_rd(vty
, bgp
, &prd
, type
, json
);
4856 vty_json(vty
, json
);
4862 * Display global EVPN routing table for specific RD and MACIP.
4864 DEFUN(show_bgp_l2vpn_evpn_route_rd_macip
,
4865 show_bgp_l2vpn_evpn_route_rd_macip_cmd
,
4866 "show bgp l2vpn evpn route rd <ASN:NN_OR_IP-ADDRESS:NN|all> mac WORD [ip WORD] [json]",
4872 EVPN_RT_DIST_HELP_STR
4873 EVPN_ASN_IP_HELP_STR
4874 "All VPN Route Distinguishers\n"
4876 "MAC address (e.g., 00:e0:ec:20:12:62)\n"
4878 "IP address (IPv4 or IPv6)\n"
4883 struct prefix_rd prd
;
4886 int idx_ext_community
= 0;
4890 json_object
*json
= NULL
;
4893 memset(&mac
, 0, sizeof(struct ethaddr
));
4894 memset(&ip
, 0, sizeof(struct ipaddr
));
4896 bgp
= bgp_get_evpn();
4900 /* check if we need json output */
4901 uj
= use_json(argc
, argv
);
4903 json
= json_object_new_object();
4906 if (!argv_find(argv
, argc
, "all", &rd_all
)) {
4907 if (argv_find(argv
, argc
, "ASN:NN_OR_IP-ADDRESS:NN",
4908 &idx_ext_community
)) {
4909 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
4912 "%% Malformed Route Distinguisher\n");
4919 if (argv_find(argv
, argc
, "mac", &mac_idx
)) {
4920 if (!prefix_str2mac(argv
[mac_idx
+ 1]->arg
, &mac
)) {
4921 vty_out(vty
, "%% Malformed MAC address\n");
4926 /* get the ip if specified */
4927 if (argv_find(argv
, argc
, "ip", &ip_idx
)) {
4928 if (str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
) != 0) {
4929 vty_out(vty
, "%% Malformed IP address\n");
4935 evpn_show_route_rd_all_macip(vty
, bgp
, &mac
, &ip
, json
);
4937 evpn_show_route_rd_macip(vty
, bgp
, &prd
, &mac
, &ip
, json
);
4940 vty_json(vty
, json
);
4945 /* Display per ESI routing table */
4946 DEFUN(show_bgp_l2vpn_evpn_route_esi
,
4947 show_bgp_l2vpn_evpn_route_esi_cmd
,
4948 "show bgp l2vpn evpn route esi ESI [json]",
4954 "Ethernet Segment Identifier\n"
4960 struct bgp
*bgp
= NULL
;
4961 json_object
*json
= NULL
;
4963 memset(&esi
, 0, sizeof(esi
));
4964 bgp
= bgp_get_evpn();
4968 uj
= use_json(argc
, argv
);
4970 json
= json_object_new_object();
4972 /* get the ESI - ESI-ID is at argv[6] */
4973 if (!str_to_esi(argv
[6]->arg
, &esi
)) {
4974 vty_out(vty
, "%% Malformed ESI\n");
4978 evpn_show_routes_esi(vty
, bgp
, &esi
, json
);
4981 vty_json(vty
, json
);
4988 * Display per-VNI EVPN routing table.
4990 DEFUN(show_bgp_l2vpn_evpn_route_vni
, show_bgp_l2vpn_evpn_route_vni_cmd
,
4991 "show bgp l2vpn evpn route vni " CMD_VNI_RANGE
" [<type <ead|1|macip|2|multicast|3> | vtep A.B.C.D>] [json]",
4997 "VXLAN Network Identifier\n"
5000 EVPN_TYPE_1_HELP_STR
5001 EVPN_TYPE_1_HELP_STR
5002 EVPN_TYPE_2_HELP_STR
5003 EVPN_TYPE_2_HELP_STR
5004 EVPN_TYPE_3_HELP_STR
5005 EVPN_TYPE_3_HELP_STR
5007 "Remote VTEP IP address\n"
5012 struct in_addr vtep_ip
;
5017 json_object
*json
= NULL
;
5019 bgp
= bgp_get_evpn();
5023 /* check if we need json output */
5024 uj
= use_json(argc
, argv
);
5026 json
= json_object_new_object();
5028 if (!argv_find(argv
, argc
, "evpn", &idx
))
5033 vni
= strtoul(argv
[idx
+ 3]->arg
, NULL
, 10);
5035 if (bgp_evpn_cli_parse_type(&type
, argv
, argc
) < 0)
5038 if (argv_find(argv
, argc
, "vtep", &vtep_idx
)) {
5039 if (!inet_aton(argv
[vtep_idx
+ 1]->arg
, &vtep_ip
)) {
5040 vty_out(vty
, "%% Malformed VTEP IP address\n");
5045 evpn_show_routes_vni(vty
, bgp
, vni
, type
, false, vtep_ip
, json
);
5048 vty_json(vty
, json
);
5054 * Display per-VNI EVPN routing table for specific MACIP.
5056 DEFUN(show_bgp_l2vpn_evpn_route_vni_macip
,
5057 show_bgp_l2vpn_evpn_route_vni_macip_cmd
,
5058 "show bgp l2vpn evpn route vni " CMD_VNI_RANGE
" mac WORD [ip WORD] [json]",
5064 "VXLAN Network Identifier\n"
5067 "MAC address (e.g., 00:e0:ec:20:12:62)\n"
5069 "IP address (IPv4 or IPv6)\n"
5078 json_object
*json
= NULL
;
5080 bgp
= bgp_get_evpn();
5084 /* check if we need json output */
5085 uj
= use_json(argc
, argv
);
5087 json
= json_object_new_object();
5089 if (!argv_find(argv
, argc
, "evpn", &idx
))
5093 vni
= strtoul(argv
[idx
+ 3]->arg
, NULL
, 10);
5096 if (!prefix_str2mac(argv
[idx
+ 5]->arg
, &mac
)) {
5097 vty_out(vty
, "%% Malformed MAC address\n");
5102 memset(&ip
, 0, sizeof(ip
));
5103 if ((!uj
&& ((argc
== (idx
+ 1 + 7)) && argv
[idx
+ 7]->arg
!= NULL
))
5105 && ((argc
== (idx
+ 1 + 8)) && argv
[idx
+ 7]->arg
!= NULL
))) {
5106 if (str2ipaddr(argv
[idx
+ 7]->arg
, &ip
) != 0) {
5107 vty_out(vty
, "%% Malformed IP address\n");
5112 evpn_show_route_vni_macip(vty
, bgp
, vni
, &mac
, &ip
, json
);
5115 vty_json(vty
, json
);
5121 * Display per-VNI EVPN routing table for specific multicast IP (remote VTEP).
5123 DEFUN(show_bgp_l2vpn_evpn_route_vni_multicast
,
5124 show_bgp_l2vpn_evpn_route_vni_multicast_cmd
,
5125 "show bgp l2vpn evpn route vni " CMD_VNI_RANGE
" multicast A.B.C.D [json]",
5131 "VXLAN Network Identifier\n"
5133 EVPN_TYPE_3_HELP_STR
5134 "Originating Router IP address\n"
5140 struct in_addr orig_ip
;
5143 json_object
*json
= NULL
;
5145 bgp
= bgp_get_evpn();
5149 /* check if we need json output */
5150 uj
= use_json(argc
, argv
);
5152 json
= json_object_new_object();
5154 if (!argv_find(argv
, argc
, "evpn", &idx
))
5158 vni
= strtoul(argv
[idx
+ 3]->arg
, NULL
, 10);
5161 ret
= inet_aton(argv
[idx
+ 5]->arg
, &orig_ip
);
5163 vty_out(vty
, "%% Malformed Originating Router IP address\n");
5167 evpn_show_route_vni_multicast(vty
, bgp
, vni
, orig_ip
, json
);
5170 vty_json(vty
, json
);
5176 * Display per-VNI EVPN routing table - for all VNIs.
5178 DEFUN(show_bgp_l2vpn_evpn_route_vni_all
,
5179 show_bgp_l2vpn_evpn_route_vni_all_cmd
,
5180 "show bgp l2vpn evpn route vni all [detail] [vtep A.B.C.D] [json]",
5186 "VXLAN Network Identifier\n"
5188 "Print Detailed Output\n"
5190 "Remote VTEP IP address\n"
5194 struct in_addr vtep_ip
;
5197 json_object
*json
= NULL
;
5198 /* Detail Adjust. Adjust indexes according to detail option */
5201 bgp
= bgp_get_evpn();
5205 /* check if we need json output */
5206 uj
= use_json(argc
, argv
);
5208 json
= json_object_new_object();
5210 if (!argv_find(argv
, argc
, "evpn", &idx
))
5213 if (argv_find(argv
, argc
, "detail", &da
))
5216 /* vtep-ip position depends on detail option */
5218 if ((!uj
&& (argc
== (idx
+ 1 + 5 + da
) && argv
[idx
+ 5 + da
]->arg
))
5220 && (argc
== (idx
+ 1 + 6 + da
) && argv
[idx
+ 5 + da
]->arg
))) {
5221 if (!inet_aton(argv
[idx
+ 5 + da
]->arg
, &vtep_ip
)) {
5222 vty_out(vty
, "%% Malformed VTEP IP address\n");
5227 evpn_show_routes_vni_all(vty
, bgp
, 0, false, vtep_ip
, json
, da
);
5230 vty_json(vty
, json
);
5231 json_object_free(json
);
5238 * Display per-VNI EVPN ALL routing tables - for all VNIs.
5240 DEFPY(show_bgp_vni_all
,
5241 show_bgp_vni_all_cmd
,
5242 "show bgp vni all [vtep A.B.C.D$addr] [detail$detail] [json$uj]",
5253 json_object
*json
= NULL
;
5255 bgp
= bgp_get_evpn();
5259 /* check if we need json output */
5261 json
= json_object_new_object();
5263 evpn_show_routes_vni_all_type_all(vty
, bgp
, addr
, json
, !!detail
);
5266 vty_json(vty
, json
);
5272 * Display per-VNI EVPN EAD routing table - for all VNIs.
5274 DEFPY(show_bgp_vni_all_ead
,
5275 show_bgp_vni_all_ead_cmd
,
5276 "show bgp vni all type <1|ead> [vtep A.B.C.D$addr] [<detail$detail|json$uj>]",
5282 EVPN_TYPE_1_HELP_STR
5283 EVPN_TYPE_1_HELP_STR
5290 json_object
*json
= NULL
;
5292 bgp
= bgp_get_evpn();
5296 /* check if we need json output */
5298 json
= json_object_new_object();
5300 evpn_show_routes_vni_all(vty
, bgp
, BGP_EVPN_AD_ROUTE
, false, addr
, json
,
5304 vty_json(vty
, json
);
5310 * Display per-VNI EVPN MAC routing table - for all VNIs.
5312 DEFPY(show_bgp_vni_all_macip_mac
,
5313 show_bgp_vni_all_macip_mac_cmd
,
5314 "show bgp vni all type <2|macip> mac [vtep A.B.C.D$addr] [<detail$detail|json$uj>]",
5320 EVPN_TYPE_2_HELP_STR
5321 EVPN_TYPE_2_HELP_STR
5329 json_object
*json
= NULL
;
5331 bgp
= bgp_get_evpn();
5335 /* check if we need json output */
5337 json
= json_object_new_object();
5339 evpn_show_routes_vni_all(vty
, bgp
, BGP_EVPN_MAC_IP_ROUTE
, true, addr
,
5343 vty_json(vty
, json
);
5349 * Display per-VNI EVPN IP routing table - for all VNIs.
5351 DEFPY(show_bgp_vni_all_macip_ip
,
5352 show_bgp_vni_all_macip_ip_cmd
,
5353 "show bgp vni all type <2|macip> ip [vtep A.B.C.D$addr] [<detail$detail|json$uj>]",
5359 EVPN_TYPE_2_HELP_STR
5360 EVPN_TYPE_2_HELP_STR
5368 json_object
*json
= NULL
;
5370 bgp
= bgp_get_evpn();
5374 /* check if we need json output */
5376 json
= json_object_new_object();
5378 evpn_show_routes_vni_all(vty
, bgp
, BGP_EVPN_MAC_IP_ROUTE
, false, addr
,
5382 vty_json(vty
, json
);
5388 * Display per-VNI EVPN Multicast routing table - for all VNIs.
5390 DEFPY(show_bgp_vni_all_imet
,
5391 show_bgp_vni_all_imet_cmd
,
5392 "show bgp vni all type <3|multicast> [vtep A.B.C.D$addr] [<detail$detail|json$uj>]",
5398 EVPN_TYPE_3_HELP_STR
5399 EVPN_TYPE_3_HELP_STR
5406 json_object
*json
= NULL
;
5408 bgp
= bgp_get_evpn();
5412 /* check if we need json output */
5414 json
= json_object_new_object();
5416 evpn_show_routes_vni_all(vty
, bgp
, BGP_EVPN_IMET_ROUTE
, false, addr
,
5420 vty_json(vty
, json
);
5426 * Display per-VNI EVPN ALL routing tables - for select VNI
5430 "show bgp vni "CMD_VNI_RANGE
"$vni [vtep A.B.C.D$addr] [json$uj]",
5440 json_object
*json
= NULL
;
5441 json_object
*json_mac
= NULL
;
5443 bgp
= bgp_get_evpn();
5447 /* check if we need json output */
5449 json
= json_object_new_object();
5450 json_mac
= json_object_new_object();
5453 evpn_show_routes_vni(vty
, bgp
, vni
, 0, false, addr
, json
);
5456 vty_out(vty
, "\n\nMAC Table:\n\n");
5458 evpn_show_routes_vni(vty
, bgp
, vni
, 0, true, addr
, json_mac
);
5461 json_object_object_add(json
, "macTable", json_mac
);
5462 vty_json(vty
, json
);
5469 * Display per-VNI EVPN EAD routing table - for select VNI
5471 DEFPY(show_bgp_vni_ead
,
5472 show_bgp_vni_ead_cmd
,
5473 "show bgp vni "CMD_VNI_RANGE
"$vni type <1|ead> [vtep A.B.C.D$addr] [json$uj]",
5479 EVPN_TYPE_1_HELP_STR
5480 EVPN_TYPE_1_HELP_STR
5486 json_object
*json
= NULL
;
5488 bgp
= bgp_get_evpn();
5492 /* check if we need json output */
5494 json
= json_object_new_object();
5496 evpn_show_routes_vni(vty
, bgp
, vni
, BGP_EVPN_AD_ROUTE
, false, addr
,
5500 vty_json(vty
, json
);
5506 * Display per-VNI EVPN MAC-IP MAC routing table - for select VNI
5508 DEFPY(show_bgp_vni_macip_mac
,
5509 show_bgp_vni_macip_mac_cmd
,
5510 "show bgp vni "CMD_VNI_RANGE
"$vni type <2|macip> mac [vtep A.B.C.D$addr] [json$uj]",
5516 EVPN_TYPE_2_HELP_STR
5517 EVPN_TYPE_2_HELP_STR
5524 json_object
*json
= NULL
;
5526 bgp
= bgp_get_evpn();
5530 /* check if we need json output */
5532 json
= json_object_new_object();
5534 evpn_show_routes_vni(vty
, bgp
, vni
, BGP_EVPN_MAC_IP_ROUTE
, true, addr
,
5538 vty_json(vty
, json
);
5544 * Display per-VNI EVPN MAC-IP IP routing table - for select VNI
5546 DEFPY(show_bgp_vni_macip_ip
,
5547 show_bgp_vni_macip_ip_cmd
,
5548 "show bgp vni "CMD_VNI_RANGE
"$vni type <2|macip> ip [vtep A.B.C.D$addr] [json$uj]",
5554 EVPN_TYPE_2_HELP_STR
5555 EVPN_TYPE_2_HELP_STR
5562 json_object
*json
= NULL
;
5564 bgp
= bgp_get_evpn();
5568 /* check if we need json output */
5570 json
= json_object_new_object();
5572 evpn_show_routes_vni(vty
, bgp
, vni
, BGP_EVPN_MAC_IP_ROUTE
, false, addr
,
5576 vty_json(vty
, json
);
5582 * Display per-VNI EVPN Multicast routing table - for select VNI
5584 DEFPY(show_bgp_vni_imet
,
5585 show_bgp_vni_imet_cmd
,
5586 "show bgp vni "CMD_VNI_RANGE
"$vni type <3|multicast> [vtep A.B.C.D$addr] [json$uj]",
5592 EVPN_TYPE_3_HELP_STR
5593 EVPN_TYPE_3_HELP_STR
5599 json_object
*json
= NULL
;
5601 bgp
= bgp_get_evpn();
5605 /* check if we need json output */
5607 json
= json_object_new_object();
5609 evpn_show_routes_vni(vty
, bgp
, vni
, BGP_EVPN_IMET_ROUTE
, false, addr
,
5613 vty_json(vty
, json
);
5619 * Display per-VNI EVPN MACIP MAC routing table - for select VNI & MAC
5621 DEFPY(show_bgp_vni_macip_mac_addr
,
5622 show_bgp_vni_macip_mac_addr_cmd
,
5623 "show bgp vni "CMD_VNI_RANGE
"$vni type <2|macip> mac X:X:X:X:X:X [json$uj]",
5629 EVPN_TYPE_2_HELP_STR
5630 EVPN_TYPE_2_HELP_STR
5636 json_object
*json
= NULL
;
5638 bgp
= bgp_get_evpn();
5642 /* check if we need json output */
5644 json
= json_object_new_object();
5646 evpn_show_route_vni_macip(vty
, bgp
, vni
, &mac
->eth_addr
, NULL
, json
);
5649 vty_json(vty
, json
);
5655 * Display per-VNI EVPN MACIP IP routing table - for select VNI & IP
5657 DEFPY(show_bgp_vni_macip_ip_addr
, show_bgp_vni_macip_ip_addr_cmd
,
5658 "show bgp vni " CMD_VNI_RANGE
5659 "$vni type <2|macip> ip <A.B.C.D|X:X::X:X> [json$uj]",
5660 SHOW_STR BGP_STR VNI_HELP_STR VNI_NUM_HELP_STR EVPN_TYPE_HELP_STR
5661 EVPN_TYPE_2_HELP_STR EVPN_TYPE_2_HELP_STR
5662 "IP Table\n" IP_ADDR_STR IP6_ADDR_STR JSON_STR
)
5665 json_object
*json
= NULL
;
5666 struct ipaddr ip_addr
= {.ipa_type
= IPADDR_NONE
};
5668 bgp
= bgp_get_evpn();
5672 /* check if we need json output */
5674 json
= json_object_new_object();
5676 if (sockunion_family(ip
) == AF_INET
) {
5677 ip_addr
.ipa_type
= IPADDR_V4
;
5678 ip_addr
.ipaddr_v4
.s_addr
= sockunion2ip(ip
);
5680 ip_addr
.ipa_type
= IPADDR_V6
;
5681 memcpy(&ip_addr
.ipaddr_v6
, &ip
->sin6
.sin6_addr
,
5682 sizeof(struct in6_addr
));
5684 evpn_show_route_vni_macip(vty
, bgp
, vni
, NULL
, &ip_addr
, json
);
5687 vty_json(vty
, json
);
5693 show_bgp_l2vpn_evpn_route_mac_ip_evi_es
,
5694 show_bgp_l2vpn_evpn_route_mac_ip_evi_es_cmd
,
5695 "show bgp l2vpn evpn route mac-ip-evi-es [NAME$esi_str|detail$detail] [json$uj]",
5696 SHOW_STR BGP_STR L2VPN_HELP_STR EVPN_HELP_STR
5697 "EVPN route information\n"
5698 "MAC IP routes in the EVI tables linked to the ES\n"
5700 "Detailed information\n" JSON_STR
)
5704 json_object
*json
= NULL
;
5707 if (!str_to_esi(esi_str
, &esi
)) {
5708 vty_out(vty
, "%% Malformed ESI\n");
5717 json
= json_object_new_object();
5718 bgp_evpn_show_routes_mac_ip_evi_es(vty
, esi_p
, json
, !!detail
);
5720 vty_json(vty
, json
);
5726 show_bgp_l2vpn_evpn_route_mac_ip_global_es
,
5727 show_bgp_l2vpn_evpn_route_mac_ip_global_es_cmd
,
5728 "show bgp l2vpn evpn route mac-ip-global-es [NAME$esi_str|detail$detail] [json$uj]",
5729 SHOW_STR BGP_STR L2VPN_HELP_STR EVPN_HELP_STR
5730 "EVPN route information\n"
5731 "MAC IP routes in the global table linked to the ES\n"
5733 "Detailed information\n" JSON_STR
)
5737 json_object
*json
= NULL
;
5740 if (!str_to_esi(esi_str
, &esi
)) {
5741 vty_out(vty
, "%% Malformed ESI\n");
5750 json
= json_object_new_object();
5751 bgp_evpn_show_routes_mac_ip_global_es(vty
, esi_p
, json
, !!detail
);
5753 vty_json(vty
, json
);
5759 * Display EVPN import route-target hash table
5761 DEFUN(show_bgp_l2vpn_evpn_vrf_import_rt
,
5762 show_bgp_l2vpn_evpn_vrf_import_rt_cmd
,
5763 "show bgp l2vpn evpn vrf-import-rt [json]",
5768 "Show vrf import route target\n"
5772 struct bgp
*bgp_evpn
= NULL
;
5773 json_object
*json
= NULL
;
5775 bgp_evpn
= bgp_get_evpn();
5779 uj
= use_json(argc
, argv
);
5781 json
= json_object_new_object();
5783 evpn_show_vrf_import_rts(vty
, bgp_evpn
, json
);
5786 vty_json(vty
, json
);
5792 * Display EVPN import route-target hash table
5794 DEFUN(show_bgp_l2vpn_evpn_import_rt
,
5795 show_bgp_l2vpn_evpn_import_rt_cmd
,
5796 "show bgp l2vpn evpn import-rt [json]",
5801 "Show import route target\n"
5806 json_object
*json
= NULL
;
5808 bgp
= bgp_get_evpn();
5812 uj
= use_json(argc
, argv
);
5814 json
= json_object_new_object();
5816 evpn_show_import_rts(vty
, bgp
, json
);
5819 vty_json(vty
, json
);
5824 DEFPY_HIDDEN(test_es_add
,
5826 "[no$no] test es NAME$esi_str [state NAME$state_str]",
5829 "Ethernet-segment\n"
5830 "Ethernet-Segment Identifier\n"
5838 struct in_addr vtep_ip
;
5841 bgp
= bgp_get_evpn();
5843 vty_out(vty
, "%% EVPN BGP instance not yet created\n");
5847 if (!str_to_esi(esi_str
, &esi
)) {
5848 vty_out(vty
, "%% Malformed ESI\n");
5853 ret
= bgp_evpn_local_es_del(bgp
, &esi
);
5855 vty_out(vty
, "%% Failed to delete ES\n");
5859 if (state_str
&& !strcmp(state_str
, "up"))
5863 vtep_ip
= bgp
->router_id
;
5865 ret
= bgp_evpn_local_es_add(bgp
, &esi
, vtep_ip
, oper_up
,
5866 EVPN_MH_DF_PREF_MIN
, false);
5868 vty_out(vty
, "%% Failed to add ES\n");
5875 DEFPY_HIDDEN(test_es_vni_add
,
5876 test_es_vni_add_cmd
,
5877 "[no$no] test es NAME$esi_str vni (1-16777215)$vni",
5880 "Ethernet-segment\n"
5881 "Ethernet-Segment Identifier\n"
5890 bgp
= bgp_get_evpn();
5892 vty_out(vty
, "%% EVPN BGP instance not yet created\n");
5896 if (!str_to_esi(esi_str
, &esi
)) {
5897 vty_out(vty
, "%% Malformed ESI\n");
5902 ret
= bgp_evpn_local_es_evi_del(bgp
, &esi
, vni
);
5904 vty_out(vty
, "%% Failed to deref ES VNI\n");
5908 ret
= bgp_evpn_local_es_evi_add(bgp
, &esi
, vni
);
5910 vty_out(vty
, "%% Failed to ref ES VNI\n");
5917 ALIAS_HIDDEN(show_bgp_l2vpn_evpn_vni
, show_bgp_evpn_vni_cmd
,
5918 "show bgp evpn vni [" CMD_VNI_RANGE
"]", SHOW_STR BGP_STR EVPN_HELP_STR
5922 ALIAS_HIDDEN(show_bgp_l2vpn_evpn_summary
, show_bgp_evpn_summary_cmd
,
5923 "show bgp evpn summary [json]", SHOW_STR BGP_STR EVPN_HELP_STR
5924 "Summary of BGP neighbor status\n" JSON_STR
)
5926 ALIAS_HIDDEN(show_bgp_l2vpn_evpn_route
, show_bgp_evpn_route_cmd
,
5927 "show bgp evpn route [detail] [type <macip|2|multicast|3>]",
5928 SHOW_STR BGP_STR EVPN_HELP_STR
5930 "Display Detailed Information\n"
5932 EVPN_TYPE_2_HELP_STR
5933 EVPN_TYPE_2_HELP_STR
5934 EVPN_TYPE_3_HELP_STR
5935 EVPN_TYPE_3_HELP_STR
)
5938 show_bgp_l2vpn_evpn_route_rd
, show_bgp_evpn_route_rd_cmd
,
5939 "show bgp evpn route rd ASN:NN_OR_IP-ADDRESS:NN [type <macip|2|multicast|3>]",
5940 SHOW_STR BGP_STR EVPN_HELP_STR
5942 EVPN_RT_DIST_HELP_STR
5943 EVPN_ASN_IP_HELP_STR
5945 EVPN_TYPE_2_HELP_STR
5946 EVPN_TYPE_2_HELP_STR
5947 EVPN_TYPE_3_HELP_STR
5948 EVPN_TYPE_3_HELP_STR
)
5951 show_bgp_l2vpn_evpn_route_rd_macip
, show_bgp_evpn_route_rd_macip_cmd
,
5952 "show bgp evpn route rd ASN:NN_OR_IP-ADDRESS:NN mac WORD [ip WORD]",
5953 SHOW_STR BGP_STR EVPN_HELP_STR
5955 EVPN_RT_DIST_HELP_STR
5956 EVPN_ASN_IP_HELP_STR
5958 "MAC address (e.g., 00:e0:ec:20:12:62)\n"
5960 "IP address (IPv4 or IPv6)\n")
5963 show_bgp_l2vpn_evpn_route_vni
, show_bgp_evpn_route_vni_cmd
,
5964 "show bgp evpn route vni " CMD_VNI_RANGE
" [<type <macip|2|multicast|3> | vtep A.B.C.D>]",
5965 SHOW_STR BGP_STR EVPN_HELP_STR
5967 "VXLAN Network Identifier\n"
5970 EVPN_TYPE_2_HELP_STR
5971 EVPN_TYPE_2_HELP_STR
5972 EVPN_TYPE_3_HELP_STR
5973 EVPN_TYPE_3_HELP_STR
5975 "Remote VTEP IP address\n")
5977 ALIAS_HIDDEN(show_bgp_l2vpn_evpn_route_vni_macip
,
5978 show_bgp_evpn_route_vni_macip_cmd
,
5979 "show bgp evpn route vni " CMD_VNI_RANGE
" mac WORD [ip WORD]",
5980 SHOW_STR BGP_STR EVPN_HELP_STR
5982 "VXLAN Network Identifier\n"
5985 "MAC address (e.g., 00:e0:ec:20:12:62)\n"
5987 "IP address (IPv4 or IPv6)\n")
5989 ALIAS_HIDDEN(show_bgp_l2vpn_evpn_route_vni_multicast
,
5990 show_bgp_evpn_route_vni_multicast_cmd
,
5991 "show bgp evpn route vni " CMD_VNI_RANGE
" multicast A.B.C.D",
5992 SHOW_STR BGP_STR EVPN_HELP_STR
5994 "VXLAN Network Identifier\n"
5996 EVPN_TYPE_3_HELP_STR
5997 "Originating Router IP address\n")
5999 ALIAS_HIDDEN(show_bgp_l2vpn_evpn_route_vni_all
, show_bgp_evpn_route_vni_all_cmd
,
6000 "show bgp evpn route vni all [detail] [vtep A.B.C.D]",
6001 SHOW_STR BGP_STR EVPN_HELP_STR
6003 "VXLAN Network Identifier\n"
6005 "Print Detailed Output\n"
6007 "Remote VTEP IP address\n")
6009 ALIAS_HIDDEN(show_bgp_l2vpn_evpn_import_rt
, show_bgp_evpn_import_rt_cmd
,
6010 "show bgp evpn import-rt",
6011 SHOW_STR BGP_STR EVPN_HELP_STR
"Show import route target\n")
6013 DEFUN_NOSH (bgp_evpn_vni
,
6015 "vni " CMD_VNI_RANGE
,
6016 "VXLAN Network Identifier\n"
6020 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
6021 struct bgpevpn
*vpn
;
6026 vni
= strtoul(argv
[1]->arg
, NULL
, 10);
6028 /* Create VNI, or mark as configured. */
6029 vpn
= evpn_create_update_vni(bgp
, vni
);
6031 vty_out(vty
, "%% Failed to create VNI \n");
6035 VTY_PUSH_CONTEXT_SUB(BGP_EVPN_VNI_NODE
, vpn
);
6039 DEFUN (no_bgp_evpn_vni
,
6040 no_bgp_evpn_vni_cmd
,
6041 "no vni " CMD_VNI_RANGE
,
6043 "VXLAN Network Identifier\n"
6047 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
6048 struct bgpevpn
*vpn
;
6053 vni
= strtoul(argv
[2]->arg
, NULL
, 10);
6055 /* Check if we should disallow. */
6056 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
6058 vty_out(vty
, "%% Specified VNI does not exist\n");
6061 if (!is_vni_configured(vpn
)) {
6062 vty_out(vty
, "%% Specified VNI is not configured\n");
6066 evpn_delete_vni(bgp
, vpn
);
6070 DEFUN_NOSH (exit_vni
,
6073 "Exit from VNI mode\n")
6075 if (vty
->node
== BGP_EVPN_VNI_NODE
)
6076 vty
->node
= BGP_EVPN_NODE
;
6080 DEFUN (bgp_evpn_vrf_rd
,
6081 bgp_evpn_vrf_rd_cmd
,
6082 "rd ASN:NN_OR_IP-ADDRESS:NN",
6083 EVPN_RT_DIST_HELP_STR
6084 EVPN_ASN_IP_HELP_STR
)
6087 struct prefix_rd prd
;
6088 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
);
6093 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
6095 vty_out(vty
, "%% Malformed Route Distinguisher\n");
6099 /* If same as existing value, there is nothing more to do. */
6100 if (bgp_evpn_vrf_rd_matches_existing(bgp_vrf
, &prd
))
6103 /* Configure or update the RD. */
6104 evpn_configure_vrf_rd(bgp_vrf
, &prd
);
6108 DEFUN (no_bgp_evpn_vrf_rd
,
6109 no_bgp_evpn_vrf_rd_cmd
,
6110 "no rd ASN:NN_OR_IP-ADDRESS:NN",
6112 EVPN_RT_DIST_HELP_STR
6113 EVPN_ASN_IP_HELP_STR
)
6116 struct prefix_rd prd
;
6117 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
);
6122 ret
= str2prefix_rd(argv
[2]->arg
, &prd
);
6124 vty_out(vty
, "%% Malformed Route Distinguisher\n");
6128 /* Check if we should disallow. */
6129 if (!is_vrf_rd_configured(bgp_vrf
)) {
6130 vty_out(vty
, "%% RD is not configured for this VRF\n");
6134 if (!bgp_evpn_vrf_rd_matches_existing(bgp_vrf
, &prd
)) {
6136 "%% RD specified does not match configuration for this VRF\n");
6140 evpn_unconfigure_vrf_rd(bgp_vrf
);
6144 DEFUN (no_bgp_evpn_vrf_rd_without_val
,
6145 no_bgp_evpn_vrf_rd_without_val_cmd
,
6148 EVPN_RT_DIST_HELP_STR
)
6150 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
);
6155 /* Check if we should disallow. */
6156 if (!is_vrf_rd_configured(bgp_vrf
)) {
6157 vty_out(vty
, "%% RD is not configured for this VRF\n");
6161 evpn_unconfigure_vrf_rd(bgp_vrf
);
6165 DEFUN (bgp_evpn_vni_rd
,
6166 bgp_evpn_vni_rd_cmd
,
6167 "rd ASN:NN_OR_IP-ADDRESS:NN",
6168 EVPN_RT_DIST_HELP_STR
6169 EVPN_ASN_IP_HELP_STR
)
6171 struct prefix_rd prd
;
6172 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
6173 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
6179 if (!EVPN_ENABLED(bgp
)) {
6181 "This command is only supported under EVPN VRF\n");
6185 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
6187 vty_out(vty
, "%% Malformed Route Distinguisher\n");
6191 /* If same as existing value, there is nothing more to do. */
6192 if (bgp_evpn_rd_matches_existing(vpn
, &prd
))
6195 /* Configure or update the RD. */
6196 evpn_configure_rd(bgp
, vpn
, &prd
);
6200 DEFUN (no_bgp_evpn_vni_rd
,
6201 no_bgp_evpn_vni_rd_cmd
,
6202 "no rd ASN:NN_OR_IP-ADDRESS:NN",
6204 EVPN_RT_DIST_HELP_STR
6205 EVPN_ASN_IP_HELP_STR
)
6207 struct prefix_rd prd
;
6208 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
6209 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
6215 if (!EVPN_ENABLED(bgp
)) {
6217 "This command is only supported under EVPN VRF\n");
6221 ret
= str2prefix_rd(argv
[2]->arg
, &prd
);
6223 vty_out(vty
, "%% Malformed Route Distinguisher\n");
6227 /* Check if we should disallow. */
6228 if (!is_rd_configured(vpn
)) {
6229 vty_out(vty
, "%% RD is not configured for this VNI\n");
6233 if (!bgp_evpn_rd_matches_existing(vpn
, &prd
)) {
6235 "%% RD specified does not match configuration for this VNI\n");
6239 evpn_unconfigure_rd(bgp
, vpn
);
6243 DEFUN (no_bgp_evpn_vni_rd_without_val
,
6244 no_bgp_evpn_vni_rd_without_val_cmd
,
6247 EVPN_RT_DIST_HELP_STR
)
6249 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
6250 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
6255 if (!EVPN_ENABLED(bgp
)) {
6257 "This command is only supported under EVPN VRF\n");
6261 /* Check if we should disallow. */
6262 if (!is_rd_configured(vpn
)) {
6263 vty_out(vty
, "%% RD is not configured for this VNI\n");
6267 evpn_unconfigure_rd(bgp
, vpn
);
6272 * Loop over all extended-communities in the route-target list rtl and
6273 * return 1 if we find ecomtarget
6275 static bool bgp_evpn_rt_matches_existing(struct list
*rtl
,
6276 struct ecommunity
*ecomtarget
)
6278 struct listnode
*node
;
6279 struct ecommunity
*ecom
;
6281 for (ALL_LIST_ELEMENTS_RO(rtl
, node
, ecom
)) {
6282 if (ecommunity_match(ecom
, ecomtarget
))
6290 * L3 RT version of above.
6292 static bool bgp_evpn_vrf_rt_matches_existing(struct list
*rtl
,
6293 struct ecommunity
*ecomtarget
)
6295 struct listnode
*node
;
6296 struct vrf_route_target
*l3rt
;
6298 for (ALL_LIST_ELEMENTS_RO(rtl
, node
, l3rt
)) {
6299 if (ecommunity_match(l3rt
->ecom
, ecomtarget
))
6306 /* display L3VNI related info for a VRF instance */
6307 DEFUN (show_bgp_vrf_l3vni_info
,
6308 show_bgp_vrf_l3vni_info_cmd
,
6309 "show bgp vrf VRFNAME vni [json]",
6317 char buf
[ETHER_ADDR_STRLEN
];
6319 const char *name
= NULL
;
6320 struct bgp
*bgp
= NULL
;
6321 struct listnode
*node
= NULL
;
6322 struct bgpevpn
*vpn
= NULL
;
6323 struct vrf_route_target
*l3rt
;
6324 json_object
*json
= NULL
;
6325 json_object
*json_vnis
= NULL
;
6326 json_object
*json_export_rts
= NULL
;
6327 json_object
*json_import_rts
= NULL
;
6328 bool uj
= use_json(argc
, argv
);
6331 json
= json_object_new_object();
6332 json_vnis
= json_object_new_array();
6333 json_export_rts
= json_object_new_array();
6334 json_import_rts
= json_object_new_array();
6337 name
= argv
[idx_vrf
]->arg
;
6338 bgp
= bgp_lookup_by_name(name
);
6339 if (strmatch(name
, VRF_DEFAULT_NAME
))
6340 bgp
= bgp_get_default();
6344 vty_out(vty
, "BGP instance for VRF %s not found\n",
6347 json_object_string_add(json
, "warning",
6348 "BGP instance not found");
6349 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
6350 json_object_free(json
);
6356 vty_out(vty
, "BGP VRF: %s\n", name
);
6357 vty_out(vty
, " Local-Ip: %pI4\n", &bgp
->originator_ip
);
6358 vty_out(vty
, " L3-VNI: %u\n", bgp
->l3vni
);
6359 vty_out(vty
, " Rmac: %s\n",
6360 prefix_mac2str(&bgp
->rmac
, buf
, sizeof(buf
)));
6361 vty_out(vty
, " VNI Filter: %s\n",
6362 CHECK_FLAG(bgp
->vrf_flags
,
6363 BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
)
6364 ? "prefix-routes-only"
6366 vty_out(vty
, " L2-VNI List:\n");
6368 for (ALL_LIST_ELEMENTS_RO(bgp
->l2vnis
, node
, vpn
))
6369 vty_out(vty
, "%u ", vpn
->vni
);
6371 vty_out(vty
, " Export-RTs:\n");
6373 for (ALL_LIST_ELEMENTS_RO(bgp
->vrf_export_rtl
, node
, l3rt
))
6374 vty_out(vty
, "%s ", ecommunity_str(l3rt
->ecom
));
6376 vty_out(vty
, " Import-RTs:\n");
6378 for (ALL_LIST_ELEMENTS_RO(bgp
->vrf_import_rtl
, node
, l3rt
))
6379 vty_out(vty
, "%s ", ecommunity_str(l3rt
->ecom
));
6381 vty_out(vty
, " RD: %pRD\n", &bgp
->vrf_prd
);
6383 json_object_string_add(json
, "vrf", name
);
6384 json_object_string_addf(json
, "local-ip", "%pI4",
6385 &bgp
->originator_ip
);
6386 json_object_int_add(json
, "l3vni", bgp
->l3vni
);
6387 json_object_string_add(
6389 prefix_mac2str(&bgp
->rmac
, buf
, sizeof(buf
)));
6390 json_object_string_add(
6392 CHECK_FLAG(bgp
->vrf_flags
,
6393 BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
)
6394 ? "prefix-routes-only"
6396 /* list of l2vnis */
6397 for (ALL_LIST_ELEMENTS_RO(bgp
->l2vnis
, node
, vpn
))
6398 json_object_array_add(json_vnis
,
6399 json_object_new_int(vpn
->vni
));
6400 json_object_object_add(json
, "l2vnis", json_vnis
);
6403 for (ALL_LIST_ELEMENTS_RO(bgp
->vrf_export_rtl
, node
, l3rt
))
6404 json_object_array_add(
6406 json_object_new_string(
6407 ecommunity_str(l3rt
->ecom
)));
6408 json_object_object_add(json
, "export-rts", json_export_rts
);
6411 for (ALL_LIST_ELEMENTS_RO(bgp
->vrf_import_rtl
, node
, l3rt
))
6412 json_object_array_add(
6414 json_object_new_string(
6415 ecommunity_str(l3rt
->ecom
)));
6416 json_object_object_add(json
, "import-rts", json_import_rts
);
6417 json_object_string_addf(json
, "rd", "%pRD", &bgp
->vrf_prd
);
6421 vty_json(vty
, json
);
6425 static int add_rt(struct bgp
*bgp
, struct ecommunity
*ecom
, bool is_import
,
6428 /* Do nothing if we already have this route-target */
6430 if (!bgp_evpn_vrf_rt_matches_existing(bgp
->vrf_import_rtl
,
6432 bgp_evpn_configure_import_rt_for_vrf(bgp
, ecom
,
6437 if (!bgp_evpn_vrf_rt_matches_existing(bgp
->vrf_export_rtl
,
6439 bgp_evpn_configure_export_rt_for_vrf(bgp
, ecom
);
6447 static int del_rt(struct bgp
*bgp
, struct ecommunity
*ecom
, bool is_import
)
6449 /* Verify we already have this route-target */
6451 if (!bgp_evpn_vrf_rt_matches_existing(bgp
->vrf_import_rtl
,
6455 bgp_evpn_unconfigure_import_rt_for_vrf(bgp
, ecom
);
6457 if (!bgp_evpn_vrf_rt_matches_existing(bgp
->vrf_export_rtl
,
6461 bgp_evpn_unconfigure_export_rt_for_vrf(bgp
, ecom
);
6467 static int parse_rtlist(struct bgp
*bgp
, struct vty
*vty
, int argc
,
6468 struct cmd_token
**argv
, int rt_idx
, bool is_add
,
6471 int ret
= CMD_SUCCESS
;
6472 bool is_wildcard
= false;
6473 struct ecommunity
*ecom
= NULL
;
6475 for (int i
= rt_idx
; i
< argc
; i
++) {
6476 is_wildcard
= false;
6479 * Special handling for wildcard '*' here.
6481 * Let's just convert it to 0 here so we dont have to modify
6482 * the ecommunity parser.
6484 if ((argv
[i
]->arg
)[0] == '*') {
6485 (argv
[i
]->arg
)[0] = '0';
6489 ecom
= ecommunity_str2com(argv
[i
]->arg
, ECOMMUNITY_ROUTE_TARGET
,
6492 /* Put it back as was */
6494 (argv
[i
]->arg
)[0] = '*';
6497 vty_out(vty
, "%% Malformed Route Target list\n");
6502 ecommunity_str(ecom
);
6505 if (add_rt(bgp
, ecom
, is_import
, is_wildcard
) != 0) {
6507 "%% RT specified already configured for this VRF: %s\n",
6509 ecommunity_free(&ecom
);
6514 if (del_rt(bgp
, ecom
, is_import
) != 0) {
6516 "%% RT specified does not match configuration for this VRF: %s\n",
6521 ecommunity_free(&ecom
);
6528 /* import/export rt for l3vni-vrf */
6529 DEFUN (bgp_evpn_vrf_rt
,
6530 bgp_evpn_vrf_rt_cmd
,
6531 "route-target <both|import|export> RTLIST...",
6533 "import and export\n"
6536 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|*:OPQR|*:MN)\n")
6538 int ret
= CMD_SUCCESS
;
6539 int tmp_ret
= CMD_SUCCESS
;
6541 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
6544 return CMD_WARNING_CONFIG_FAILED
;
6546 if (!strcmp(argv
[1]->arg
, "import"))
6547 rt_type
= RT_TYPE_IMPORT
;
6548 else if (!strcmp(argv
[1]->arg
, "export"))
6549 rt_type
= RT_TYPE_EXPORT
;
6550 else if (!strcmp(argv
[1]->arg
, "both"))
6551 rt_type
= RT_TYPE_BOTH
;
6553 vty_out(vty
, "%% Invalid Route Target type\n");
6554 return CMD_WARNING_CONFIG_FAILED
;
6557 if (strmatch(argv
[2]->arg
, "auto")) {
6558 vty_out(vty
, "%% `auto` cannot be configured via list\n");
6559 return CMD_WARNING_CONFIG_FAILED
;
6562 if (rt_type
!= RT_TYPE_IMPORT
) {
6563 for (int i
= 2; i
< argc
; i
++) {
6564 if ((argv
[i
]->arg
)[0] == '*') {
6566 "%% Wildcard '*' only applicable for import\n");
6567 return CMD_WARNING_CONFIG_FAILED
;
6572 /* Add/update the import route-target */
6573 if (rt_type
== RT_TYPE_BOTH
|| rt_type
== RT_TYPE_IMPORT
)
6574 tmp_ret
= parse_rtlist(bgp
, vty
, argc
, argv
, 2, true, true);
6576 if (ret
== CMD_SUCCESS
&& tmp_ret
!= CMD_SUCCESS
)
6579 if (rt_type
== RT_TYPE_BOTH
|| rt_type
== RT_TYPE_EXPORT
)
6580 tmp_ret
= parse_rtlist(bgp
, vty
, argc
, argv
, 2, true, false);
6582 if (ret
== CMD_SUCCESS
&& tmp_ret
!= CMD_SUCCESS
)
6588 DEFPY (bgp_evpn_vrf_rt_auto
,
6589 bgp_evpn_vrf_rt_auto_cmd
,
6590 "route-target <both|import|export>$type auto",
6592 "import and export\n"
6595 "Automatically derive route target\n")
6597 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
6601 return CMD_WARNING_CONFIG_FAILED
;
6603 if (strmatch(type
, "import"))
6604 rt_type
= RT_TYPE_IMPORT
;
6605 else if (strmatch(type
, "export"))
6606 rt_type
= RT_TYPE_EXPORT
;
6607 else if (strmatch(type
, "both"))
6608 rt_type
= RT_TYPE_BOTH
;
6610 vty_out(vty
, "%% Invalid Route Target type\n");
6611 return CMD_WARNING_CONFIG_FAILED
;
6614 if (rt_type
== RT_TYPE_BOTH
|| rt_type
== RT_TYPE_IMPORT
)
6615 bgp_evpn_configure_import_auto_rt_for_vrf(bgp
);
6617 if (rt_type
== RT_TYPE_BOTH
|| rt_type
== RT_TYPE_EXPORT
)
6618 bgp_evpn_configure_export_auto_rt_for_vrf(bgp
);
6623 DEFUN (no_bgp_evpn_vrf_rt
,
6624 no_bgp_evpn_vrf_rt_cmd
,
6625 "no route-target <both|import|export> RTLIST...",
6628 "import and export\n"
6631 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6633 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
6634 int ret
= CMD_SUCCESS
;
6635 int tmp_ret
= CMD_SUCCESS
;
6639 return CMD_WARNING_CONFIG_FAILED
;
6641 if (!strcmp(argv
[2]->arg
, "import"))
6642 rt_type
= RT_TYPE_IMPORT
;
6643 else if (!strcmp(argv
[2]->arg
, "export"))
6644 rt_type
= RT_TYPE_EXPORT
;
6645 else if (!strcmp(argv
[2]->arg
, "both"))
6646 rt_type
= RT_TYPE_BOTH
;
6648 vty_out(vty
, "%% Invalid Route Target type\n");
6649 return CMD_WARNING_CONFIG_FAILED
;
6652 if (!strcmp(argv
[3]->arg
, "auto")) {
6653 vty_out(vty
, "%% `auto` cannot be unconfigured via list\n");
6654 return CMD_WARNING_CONFIG_FAILED
;
6657 if (rt_type
== RT_TYPE_IMPORT
) {
6658 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
)) {
6660 "%% Import RT is not configured for this VRF\n");
6661 return CMD_WARNING_CONFIG_FAILED
;
6663 } else if (rt_type
== RT_TYPE_EXPORT
) {
6664 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)) {
6666 "%% Export RT is not configured for this VRF\n");
6667 return CMD_WARNING_CONFIG_FAILED
;
6669 } else if (rt_type
== RT_TYPE_BOTH
) {
6670 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
)
6671 && !CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)) {
6673 "%% Import/Export RT is not configured for this VRF\n");
6674 return CMD_WARNING_CONFIG_FAILED
;
6678 if (rt_type
!= RT_TYPE_IMPORT
) {
6679 for (int i
= 3; i
< argc
; i
++) {
6680 if ((argv
[i
]->arg
)[0] == '*') {
6682 "%% Wildcard '*' only applicable for import\n");
6683 return CMD_WARNING_CONFIG_FAILED
;
6688 if (rt_type
== RT_TYPE_BOTH
|| rt_type
== RT_TYPE_IMPORT
)
6689 tmp_ret
= parse_rtlist(bgp
, vty
, argc
, argv
, 3, false, true);
6691 if (ret
== CMD_SUCCESS
&& tmp_ret
!= CMD_SUCCESS
)
6694 if (rt_type
== RT_TYPE_BOTH
|| rt_type
== RT_TYPE_EXPORT
)
6695 tmp_ret
= parse_rtlist(bgp
, vty
, argc
, argv
, 3, false, false);
6697 if (ret
== CMD_SUCCESS
&& tmp_ret
!= CMD_SUCCESS
)
6703 DEFPY (no_bgp_evpn_vrf_rt_auto
,
6704 no_bgp_evpn_vrf_rt_auto_cmd
,
6705 "no route-target <both|import|export>$type auto",
6708 "import and export\n"
6711 "Automatically derive route target\n")
6713 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
6717 return CMD_WARNING_CONFIG_FAILED
;
6719 if (strmatch(type
, "import"))
6720 rt_type
= RT_TYPE_IMPORT
;
6721 else if (strmatch(type
, "export"))
6722 rt_type
= RT_TYPE_EXPORT
;
6723 else if (strmatch(type
, "both"))
6724 rt_type
= RT_TYPE_BOTH
;
6726 vty_out(vty
, "%% Invalid Route Target type\n");
6727 return CMD_WARNING_CONFIG_FAILED
;
6730 if (rt_type
== RT_TYPE_IMPORT
) {
6731 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
)) {
6733 "%% Import AUTO RT is not configured for this VRF\n");
6734 return CMD_WARNING_CONFIG_FAILED
;
6736 } else if (rt_type
== RT_TYPE_EXPORT
) {
6737 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
)) {
6739 "%% Export AUTO RT is not configured for this VRF\n");
6740 return CMD_WARNING_CONFIG_FAILED
;
6742 } else if (rt_type
== RT_TYPE_BOTH
) {
6743 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
) &&
6744 !CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
)) {
6746 "%% Import/Export AUTO RT is not configured for this VRF\n");
6747 return CMD_WARNING_CONFIG_FAILED
;
6751 if (rt_type
== RT_TYPE_BOTH
|| rt_type
== RT_TYPE_IMPORT
)
6752 bgp_evpn_unconfigure_import_auto_rt_for_vrf(bgp
);
6754 if (rt_type
== RT_TYPE_BOTH
|| rt_type
== RT_TYPE_EXPORT
)
6755 bgp_evpn_unconfigure_export_auto_rt_for_vrf(bgp
);
6760 DEFPY(bgp_evpn_ead_ess_frag_evi_limit
, bgp_evpn_ead_es_frag_evi_limit_cmd
,
6761 "[no$no] ead-es-frag evi-limit (1-1000)$limit",
6763 "EAD ES fragment config\n"
6764 "EVIs per-fragment\n"
6767 bgp_mh_info
->evi_per_es_frag
=
6768 no
? BGP_EVPN_MAX_EVI_PER_ES_FRAG
: limit
;
6773 DEFUN(bgp_evpn_ead_es_rt
, bgp_evpn_ead_es_rt_cmd
,
6774 "ead-es-route-target export RT",
6775 "EAD ES Route Target\n"
6777 "Route target (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6779 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
6780 struct ecommunity
*ecomadd
= NULL
;
6785 if (!EVPN_ENABLED(bgp
)) {
6786 vty_out(vty
, "This command is only supported under EVPN VRF\n");
6790 /* Add/update the export route-target */
6791 ecomadd
= ecommunity_str2com(argv
[2]->arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
6793 vty_out(vty
, "%% Malformed Route Target list\n");
6796 ecommunity_str(ecomadd
);
6798 /* Do nothing if we already have this export route-target */
6799 if (!bgp_evpn_rt_matches_existing(bgp_mh_info
->ead_es_export_rtl
,
6801 bgp_evpn_mh_config_ead_export_rt(bgp
, ecomadd
, false);
6806 DEFUN(no_bgp_evpn_ead_es_rt
, no_bgp_evpn_ead_es_rt_cmd
,
6807 "no ead-es-route-target export RT",
6809 "EAD ES Route Target\n"
6810 "export\n" EVPN_ASN_IP_HELP_STR
)
6812 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
6813 struct ecommunity
*ecomdel
= NULL
;
6818 if (!EVPN_ENABLED(bgp
)) {
6819 vty_out(vty
, "This command is only supported under EVPN VRF\n");
6823 ecomdel
= ecommunity_str2com(argv
[3]->arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
6825 vty_out(vty
, "%% Malformed Route Target list\n");
6828 ecommunity_str(ecomdel
);
6830 if (!bgp_evpn_rt_matches_existing(bgp_mh_info
->ead_es_export_rtl
,
6832 ecommunity_free(&ecomdel
);
6834 "%% RT specified does not match EAD-ES RT configuration\n");
6837 bgp_evpn_mh_config_ead_export_rt(bgp
, ecomdel
, true);
6842 DEFUN (bgp_evpn_vni_rt
,
6843 bgp_evpn_vni_rt_cmd
,
6844 "route-target <both|import|export> RT",
6846 "import and export\n"
6849 "Route target (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6851 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
6852 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
6854 struct ecommunity
*ecomadd
= NULL
;
6859 if (!EVPN_ENABLED(bgp
)) {
6861 "This command is only supported under EVPN VRF\n");
6865 if (!strcmp(argv
[1]->text
, "import"))
6866 rt_type
= RT_TYPE_IMPORT
;
6867 else if (!strcmp(argv
[1]->text
, "export"))
6868 rt_type
= RT_TYPE_EXPORT
;
6869 else if (!strcmp(argv
[1]->text
, "both"))
6870 rt_type
= RT_TYPE_BOTH
;
6872 vty_out(vty
, "%% Invalid Route Target type\n");
6876 ecomadd
= ecommunity_str2com(argv
[2]->arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
6878 vty_out(vty
, "%% Malformed Route Target list\n");
6881 ecommunity_str(ecomadd
);
6883 /* Add/update the import route-target */
6884 if (rt_type
== RT_TYPE_BOTH
|| rt_type
== RT_TYPE_IMPORT
) {
6885 /* Do nothing if we already have this import route-target */
6886 if (!bgp_evpn_rt_matches_existing(vpn
->import_rtl
, ecomadd
))
6887 evpn_configure_import_rt(bgp
, vpn
, ecomadd
);
6890 /* Add/update the export route-target */
6891 if (rt_type
== RT_TYPE_BOTH
|| rt_type
== RT_TYPE_EXPORT
) {
6892 /* Do nothing if we already have this export route-target */
6893 if (!bgp_evpn_rt_matches_existing(vpn
->export_rtl
, ecomadd
))
6894 evpn_configure_export_rt(bgp
, vpn
, ecomadd
);
6900 DEFUN (no_bgp_evpn_vni_rt
,
6901 no_bgp_evpn_vni_rt_cmd
,
6902 "no route-target <both|import|export> RT",
6905 "import and export\n"
6908 EVPN_ASN_IP_HELP_STR
)
6910 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
6911 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
6912 int rt_type
, found_ecomdel
;
6913 struct ecommunity
*ecomdel
= NULL
;
6918 if (!EVPN_ENABLED(bgp
)) {
6920 "This command is only supported under EVPN VRF\n");
6924 if (!strcmp(argv
[2]->text
, "import"))
6925 rt_type
= RT_TYPE_IMPORT
;
6926 else if (!strcmp(argv
[2]->text
, "export"))
6927 rt_type
= RT_TYPE_EXPORT
;
6928 else if (!strcmp(argv
[2]->text
, "both"))
6929 rt_type
= RT_TYPE_BOTH
;
6931 vty_out(vty
, "%% Invalid Route Target type\n");
6935 /* The user did "no route-target import", check to see if there are any
6936 * import route-targets configured. */
6937 if (rt_type
== RT_TYPE_IMPORT
) {
6938 if (!is_import_rt_configured(vpn
)) {
6940 "%% Import RT is not configured for this VNI\n");
6943 } else if (rt_type
== RT_TYPE_EXPORT
) {
6944 if (!is_export_rt_configured(vpn
)) {
6946 "%% Export RT is not configured for this VNI\n");
6949 } else if (rt_type
== RT_TYPE_BOTH
) {
6950 if (!is_import_rt_configured(vpn
)
6951 && !is_export_rt_configured(vpn
)) {
6953 "%% Import/Export RT is not configured for this VNI\n");
6958 ecomdel
= ecommunity_str2com(argv
[3]->arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
6960 vty_out(vty
, "%% Malformed Route Target list\n");
6963 ecommunity_str(ecomdel
);
6965 if (rt_type
== RT_TYPE_IMPORT
) {
6966 if (!bgp_evpn_rt_matches_existing(vpn
->import_rtl
, ecomdel
)) {
6967 ecommunity_free(&ecomdel
);
6969 "%% RT specified does not match configuration for this VNI\n");
6972 evpn_unconfigure_import_rt(bgp
, vpn
, ecomdel
);
6973 } else if (rt_type
== RT_TYPE_EXPORT
) {
6974 if (!bgp_evpn_rt_matches_existing(vpn
->export_rtl
, ecomdel
)) {
6975 ecommunity_free(&ecomdel
);
6977 "%% RT specified does not match configuration for this VNI\n");
6980 evpn_unconfigure_export_rt(bgp
, vpn
, ecomdel
);
6981 } else if (rt_type
== RT_TYPE_BOTH
) {
6984 if (bgp_evpn_rt_matches_existing(vpn
->import_rtl
, ecomdel
)) {
6985 evpn_unconfigure_import_rt(bgp
, vpn
, ecomdel
);
6989 if (bgp_evpn_rt_matches_existing(vpn
->export_rtl
, ecomdel
)) {
6990 evpn_unconfigure_export_rt(bgp
, vpn
, ecomdel
);
6994 if (!found_ecomdel
) {
6995 ecommunity_free(&ecomdel
);
6997 "%% RT specified does not match configuration for this VNI\n");
7005 DEFUN (no_bgp_evpn_vni_rt_without_val
,
7006 no_bgp_evpn_vni_rt_without_val_cmd
,
7007 "no route-target <import|export>",
7013 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
7014 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
7020 if (!EVPN_ENABLED(bgp
)) {
7022 "This command is only supported under EVPN VRF\n");
7026 if (!strcmp(argv
[2]->text
, "import")) {
7027 rt_type
= RT_TYPE_IMPORT
;
7028 } else if (!strcmp(argv
[2]->text
, "export")) {
7029 rt_type
= RT_TYPE_EXPORT
;
7031 vty_out(vty
, "%% Invalid Route Target type\n");
7035 /* Check if we should disallow. */
7036 if (rt_type
== RT_TYPE_IMPORT
) {
7037 if (!is_import_rt_configured(vpn
)) {
7039 "%% Import RT is not configured for this VNI\n");
7043 if (!is_export_rt_configured(vpn
)) {
7045 "%% Export RT is not configured for this VNI\n");
7050 /* Unconfigure the RT. */
7051 if (rt_type
== RT_TYPE_IMPORT
)
7052 evpn_unconfigure_import_rt(bgp
, vpn
, NULL
);
7054 evpn_unconfigure_export_rt(bgp
, vpn
, NULL
);
7058 static int vni_cmp(const void **a
, const void **b
)
7060 const struct bgpevpn
*first
= *a
;
7061 const struct bgpevpn
*secnd
= *b
;
7063 return secnd
->vni
- first
->vni
;
7067 * Output EVPN configuration information.
7069 void bgp_config_write_evpn_info(struct vty
*vty
, struct bgp
*bgp
, afi_t afi
,
7072 if (bgp
->advertise_all_vni
)
7073 vty_out(vty
, " advertise-all-vni\n");
7075 if (hashcount(bgp
->vnihash
)) {
7076 struct list
*vnilist
= hash_to_list(bgp
->vnihash
);
7077 struct listnode
*ln
;
7078 struct bgpevpn
*data
;
7080 list_sort(vnilist
, vni_cmp
);
7081 for (ALL_LIST_ELEMENTS_RO(vnilist
, ln
, data
))
7082 write_vni_config(vty
, data
);
7084 list_delete(&vnilist
);
7087 if (bgp
->advertise_autort_rfc8365
)
7088 vty_out(vty
, " autort rfc8365-compatible\n");
7090 if (bgp
->advertise_gw_macip
)
7091 vty_out(vty
, " advertise-default-gw\n");
7093 if (bgp
->evpn_info
->advertise_svi_macip
)
7094 vty_out(vty
, " advertise-svi-ip\n");
7096 if (bgp
->resolve_overlay_index
)
7097 vty_out(vty
, " enable-resolve-overlay-index\n");
7099 if (bgp_mh_info
->evi_per_es_frag
!= BGP_EVPN_MAX_EVI_PER_ES_FRAG
)
7100 vty_out(vty
, " ead-es-frag evi-limit %u\n",
7101 bgp_mh_info
->evi_per_es_frag
);
7103 if (bgp_mh_info
->host_routes_use_l3nhg
!=
7104 BGP_EVPN_MH_USE_ES_L3NHG_DEF
) {
7105 if (bgp_mh_info
->host_routes_use_l3nhg
)
7106 vty_out(vty
, " use-es-l3nhg\n");
7108 vty_out(vty
, " no use-es-l3nhg\n");
7111 if (bgp_mh_info
->ead_evi_rx
!= BGP_EVPN_MH_EAD_EVI_RX_DEF
) {
7112 if (bgp_mh_info
->ead_evi_rx
)
7113 vty_out(vty
, " no disable-ead-evi-rx\n");
7115 vty_out(vty
, " disable-ead-evi-rx\n");
7118 if (bgp_mh_info
->ead_evi_tx
!= BGP_EVPN_MH_EAD_EVI_TX_DEF
) {
7119 if (bgp_mh_info
->ead_evi_tx
)
7120 vty_out(vty
, " no disable-ead-evi-tx\n");
7122 vty_out(vty
, " disable-ead-evi-tx\n");
7125 if (!bgp
->evpn_info
->dup_addr_detect
)
7126 vty_out(vty
, " no dup-addr-detection\n");
7128 if (bgp
->evpn_info
->dad_max_moves
!=
7129 EVPN_DAD_DEFAULT_MAX_MOVES
||
7130 bgp
->evpn_info
->dad_time
!= EVPN_DAD_DEFAULT_TIME
)
7131 vty_out(vty
, " dup-addr-detection max-moves %u time %u\n",
7132 bgp
->evpn_info
->dad_max_moves
,
7133 bgp
->evpn_info
->dad_time
);
7135 if (bgp
->evpn_info
->dad_freeze
) {
7136 if (bgp
->evpn_info
->dad_freeze_time
)
7138 " dup-addr-detection freeze %u\n",
7139 bgp
->evpn_info
->dad_freeze_time
);
7142 " dup-addr-detection freeze permanent\n");
7145 if (bgp
->vxlan_flood_ctrl
== VXLAN_FLOOD_DISABLED
)
7146 vty_out(vty
, " flooding disable\n");
7148 if (CHECK_FLAG(bgp
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
7149 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST
)) {
7150 if (bgp
->adv_cmd_rmap
[AFI_IP
][SAFI_UNICAST
].name
)
7151 vty_out(vty
, " advertise ipv4 unicast route-map %s\n",
7152 bgp
->adv_cmd_rmap
[AFI_IP
][SAFI_UNICAST
].name
);
7155 " advertise ipv4 unicast\n");
7156 } else if (CHECK_FLAG(bgp
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
7157 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP
)) {
7158 if (bgp
->adv_cmd_rmap
[AFI_IP
][SAFI_UNICAST
].name
)
7160 " advertise ipv4 unicast gateway-ip route-map %s\n",
7161 bgp
->adv_cmd_rmap
[AFI_IP
][SAFI_UNICAST
].name
);
7163 vty_out(vty
, " advertise ipv4 unicast gateway-ip\n");
7166 /* EAD ES export route-target */
7167 if (listcount(bgp_mh_info
->ead_es_export_rtl
)) {
7168 struct ecommunity
*ecom
;
7170 struct listnode
*node
;
7172 for (ALL_LIST_ELEMENTS_RO(bgp_mh_info
->ead_es_export_rtl
, node
,
7175 ecom_str
= ecommunity_ecom2str(
7176 ecom
, ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
7177 vty_out(vty
, " ead-es-route-target export %s\n",
7179 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
7183 if (CHECK_FLAG(bgp
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
7184 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST
)) {
7185 if (bgp
->adv_cmd_rmap
[AFI_IP6
][SAFI_UNICAST
].name
)
7187 " advertise ipv6 unicast route-map %s\n",
7188 bgp
->adv_cmd_rmap
[AFI_IP6
][SAFI_UNICAST
].name
);
7191 " advertise ipv6 unicast\n");
7192 } else if (CHECK_FLAG(bgp
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
7193 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP
)) {
7194 if (bgp
->adv_cmd_rmap
[AFI_IP6
][SAFI_UNICAST
].name
)
7196 " advertise ipv6 unicast gateway-ip route-map %s\n",
7197 bgp
->adv_cmd_rmap
[AFI_IP6
][SAFI_UNICAST
].name
);
7199 vty_out(vty
, " advertise ipv6 unicast gateway-ip\n");
7202 if (CHECK_FLAG(bgp
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
7203 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV4
))
7204 vty_out(vty
, " default-originate ipv4\n");
7206 if (CHECK_FLAG(bgp
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
7207 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV6
))
7208 vty_out(vty
, " default-originate ipv6\n");
7210 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_VRF
) {
7211 if (!bgp
->evpn_info
->advertise_pip
)
7212 vty_out(vty
, " no advertise-pip\n");
7213 if (bgp
->evpn_info
->advertise_pip
) {
7214 if (bgp
->evpn_info
->pip_ip_static
.s_addr
7216 vty_out(vty
, " advertise-pip ip %pI4",
7217 &bgp
->evpn_info
->pip_ip_static
);
7219 bgp
->evpn_info
->pip_rmac_static
))) {
7220 char buf
[ETHER_ADDR_STRLEN
];
7222 vty_out(vty
, " mac %s",
7232 if (CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_RD_CFGD
))
7233 vty_out(vty
, " rd %pRD\n", &bgp
->vrf_prd
);
7235 /* import route-target */
7236 if (CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
)) {
7238 struct listnode
*node
, *nnode
;
7239 struct vrf_route_target
*l3rt
;
7241 for (ALL_LIST_ELEMENTS(bgp
->vrf_import_rtl
, node
, nnode
,
7244 if (CHECK_FLAG(l3rt
->flags
, BGP_VRF_RT_AUTO
))
7247 ecom_str
= ecommunity_ecom2str(
7248 l3rt
->ecom
, ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
7250 if (CHECK_FLAG(l3rt
->flags
, BGP_VRF_RT_WILD
)) {
7251 char *vni_str
= NULL
;
7253 vni_str
= strchr(ecom_str
, ':');
7255 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
7259 /* Move pointer to vni */
7262 vty_out(vty
, " route-target import *:%s\n",
7266 vty_out(vty
, " route-target import %s\n",
7269 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
7273 /* import route-target auto */
7274 if (CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
))
7275 vty_out(vty
, " route-target import auto\n");
7277 /* export route-target */
7278 if (CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)) {
7280 struct listnode
*node
, *nnode
;
7281 struct vrf_route_target
*l3rt
;
7283 for (ALL_LIST_ELEMENTS(bgp
->vrf_export_rtl
, node
, nnode
,
7286 if (CHECK_FLAG(l3rt
->flags
, BGP_VRF_RT_AUTO
))
7289 ecom_str
= ecommunity_ecom2str(
7290 l3rt
->ecom
, ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
7291 vty_out(vty
, " route-target export %s\n", ecom_str
);
7292 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
7296 /* export route-target auto */
7297 if (CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
))
7298 vty_out(vty
, " route-target export auto\n");
7301 void bgp_ethernetvpn_init(void)
7303 install_element(VIEW_NODE
, &show_ip_bgp_l2vpn_evpn_cmd
);
7304 install_element(VIEW_NODE
, &show_ip_bgp_l2vpn_evpn_rd_cmd
);
7305 install_element(VIEW_NODE
, &show_ip_bgp_l2vpn_evpn_all_tags_cmd
);
7306 install_element(VIEW_NODE
, &show_ip_bgp_l2vpn_evpn_rd_tags_cmd
);
7307 install_element(VIEW_NODE
,
7308 &show_ip_bgp_l2vpn_evpn_neighbor_routes_cmd
);
7309 install_element(VIEW_NODE
,
7310 &show_ip_bgp_l2vpn_evpn_rd_neighbor_routes_cmd
);
7313 &show_ip_bgp_l2vpn_evpn_neighbor_advertised_routes_cmd
);
7316 &show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes_cmd
);
7317 install_element(VIEW_NODE
, &show_ip_bgp_evpn_rd_overlay_cmd
);
7318 install_element(VIEW_NODE
, &show_ip_bgp_l2vpn_evpn_all_overlay_cmd
);
7319 install_element(BGP_EVPN_NODE
, &no_evpnrt5_network_cmd
);
7320 install_element(BGP_EVPN_NODE
, &evpnrt5_network_cmd
);
7321 install_element(BGP_EVPN_NODE
, &bgp_evpn_advertise_all_vni_cmd
);
7322 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_advertise_all_vni_cmd
);
7323 install_element(BGP_EVPN_NODE
, &bgp_evpn_advertise_autort_rfc8365_cmd
);
7324 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_advertise_autort_rfc8365_cmd
);
7325 install_element(BGP_EVPN_NODE
, &bgp_evpn_advertise_default_gw_cmd
);
7326 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_advertise_default_gw_cmd
);
7327 install_element(BGP_EVPN_NODE
, &bgp_evpn_advertise_svi_ip_cmd
);
7328 install_element(BGP_EVPN_NODE
, &bgp_evpn_advertise_type5_cmd
);
7329 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_advertise_type5_cmd
);
7330 install_element(BGP_EVPN_NODE
, &bgp_evpn_default_originate_cmd
);
7331 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_default_originate_cmd
);
7332 install_element(BGP_EVPN_NODE
, &dup_addr_detection_cmd
);
7333 install_element(BGP_EVPN_NODE
, &dup_addr_detection_auto_recovery_cmd
);
7334 install_element(BGP_EVPN_NODE
, &no_dup_addr_detection_cmd
);
7335 install_element(BGP_EVPN_NODE
, &bgp_evpn_flood_control_cmd
);
7336 install_element(BGP_EVPN_NODE
, &bgp_evpn_advertise_pip_ip_mac_cmd
);
7337 install_element(BGP_EVPN_NODE
, &bgp_evpn_use_es_l3nhg_cmd
);
7338 install_element(BGP_EVPN_NODE
, &bgp_evpn_ead_evi_rx_disable_cmd
);
7339 install_element(BGP_EVPN_NODE
, &bgp_evpn_ead_evi_tx_disable_cmd
);
7340 install_element(BGP_EVPN_NODE
,
7341 &bgp_evpn_enable_resolve_overlay_index_cmd
);
7344 install_element(BGP_EVPN_NODE
, &test_es_add_cmd
);
7345 install_element(BGP_EVPN_NODE
, &test_es_vni_add_cmd
);
7347 /* "show bgp l2vpn evpn" commands. */
7348 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_es_cmd
);
7349 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_es_evi_cmd
);
7350 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_es_vrf_cmd
);
7351 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_nh_cmd
);
7352 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_vni_cmd
);
7353 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_vni_remote_ip_hash_cmd
);
7354 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_vni_svi_hash_cmd
);
7355 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_summary_cmd
);
7356 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_route_cmd
);
7357 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_route_rd_cmd
);
7358 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_route_rd_macip_cmd
);
7359 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_route_esi_cmd
);
7360 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_route_vni_cmd
);
7361 install_element(VIEW_NODE
,
7362 &show_bgp_l2vpn_evpn_route_vni_multicast_cmd
);
7363 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_route_vni_macip_cmd
);
7364 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_route_vni_all_cmd
);
7365 install_element(VIEW_NODE
,
7366 &show_bgp_l2vpn_evpn_route_mac_ip_evi_es_cmd
);
7367 install_element(VIEW_NODE
,
7368 &show_bgp_l2vpn_evpn_route_mac_ip_global_es_cmd
);
7369 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_import_rt_cmd
);
7370 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_vrf_import_rt_cmd
);
7372 /* "show bgp vni" commands. */
7373 install_element(VIEW_NODE
, &show_bgp_vni_all_cmd
);
7374 install_element(VIEW_NODE
, &show_bgp_vni_all_ead_cmd
);
7375 install_element(VIEW_NODE
, &show_bgp_vni_all_macip_mac_cmd
);
7376 install_element(VIEW_NODE
, &show_bgp_vni_all_macip_ip_cmd
);
7377 install_element(VIEW_NODE
, &show_bgp_vni_all_imet_cmd
);
7378 install_element(VIEW_NODE
, &show_bgp_vni_cmd
);
7379 install_element(VIEW_NODE
, &show_bgp_vni_ead_cmd
);
7380 install_element(VIEW_NODE
, &show_bgp_vni_macip_mac_cmd
);
7381 install_element(VIEW_NODE
, &show_bgp_vni_macip_ip_cmd
);
7382 install_element(VIEW_NODE
, &show_bgp_vni_imet_cmd
);
7383 install_element(VIEW_NODE
, &show_bgp_vni_macip_mac_addr_cmd
);
7384 install_element(VIEW_NODE
, &show_bgp_vni_macip_ip_addr_cmd
);
7386 /* "show bgp evpn" commands. */
7387 install_element(VIEW_NODE
, &show_bgp_evpn_vni_cmd
);
7388 install_element(VIEW_NODE
, &show_bgp_evpn_summary_cmd
);
7389 install_element(VIEW_NODE
, &show_bgp_evpn_route_cmd
);
7390 install_element(VIEW_NODE
, &show_bgp_evpn_route_rd_cmd
);
7391 install_element(VIEW_NODE
, &show_bgp_evpn_route_rd_macip_cmd
);
7392 install_element(VIEW_NODE
, &show_bgp_evpn_route_vni_cmd
);
7393 install_element(VIEW_NODE
, &show_bgp_evpn_route_vni_multicast_cmd
);
7394 install_element(VIEW_NODE
, &show_bgp_evpn_route_vni_macip_cmd
);
7395 install_element(VIEW_NODE
, &show_bgp_evpn_route_vni_all_cmd
);
7396 install_element(VIEW_NODE
, &show_bgp_evpn_import_rt_cmd
);
7397 install_element(VIEW_NODE
, &show_bgp_vrf_l3vni_info_cmd
);
7398 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_com_cmd
);
7400 install_element(BGP_EVPN_NODE
, &bgp_evpn_vni_cmd
);
7401 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_vni_cmd
);
7402 install_element(BGP_EVPN_VNI_NODE
, &exit_vni_cmd
);
7403 install_element(BGP_EVPN_VNI_NODE
, &bgp_evpn_vni_rd_cmd
);
7404 install_element(BGP_EVPN_VNI_NODE
, &no_bgp_evpn_vni_rd_cmd
);
7405 install_element(BGP_EVPN_VNI_NODE
, &no_bgp_evpn_vni_rd_without_val_cmd
);
7406 install_element(BGP_EVPN_VNI_NODE
, &bgp_evpn_vni_rt_cmd
);
7407 install_element(BGP_EVPN_VNI_NODE
, &no_bgp_evpn_vni_rt_cmd
);
7408 install_element(BGP_EVPN_VNI_NODE
, &no_bgp_evpn_vni_rt_without_val_cmd
);
7409 install_element(BGP_EVPN_NODE
, &bgp_evpn_vrf_rd_cmd
);
7410 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_vrf_rd_cmd
);
7411 install_element(BGP_NODE
, &no_bgp_evpn_vrf_rd_without_val_cmd
);
7412 install_element(BGP_EVPN_NODE
, &bgp_evpn_vrf_rt_cmd
);
7413 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_vrf_rt_cmd
);
7414 install_element(BGP_EVPN_NODE
, &bgp_evpn_vrf_rt_auto_cmd
);
7415 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_vrf_rt_auto_cmd
);
7416 install_element(BGP_EVPN_NODE
, &bgp_evpn_ead_es_rt_cmd
);
7417 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_ead_es_rt_cmd
);
7418 install_element(BGP_EVPN_NODE
, &bgp_evpn_ead_es_frag_evi_limit_cmd
);
7419 install_element(BGP_EVPN_VNI_NODE
, &bgp_evpn_advertise_svi_ip_vni_cmd
);
7420 install_element(BGP_EVPN_VNI_NODE
,
7421 &bgp_evpn_advertise_default_gw_vni_cmd
);
7422 install_element(BGP_EVPN_VNI_NODE
,
7423 &no_bgp_evpn_advertise_default_gw_vni_cmd
);
7424 install_element(BGP_EVPN_VNI_NODE
, &bgp_evpn_advertise_vni_subnet_cmd
);
7425 install_element(BGP_EVPN_VNI_NODE
,
7426 &no_bgp_evpn_advertise_vni_subnet_cmd
);