From: anlan_cs Date: Sat, 26 Mar 2022 04:09:27 +0000 (+0800) Subject: bgpd: small simplification for evpn RT commands X-Git-Tag: pim6-testing-20220430~134^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=3b7e8d0f49b995161c6ff1e4d0ada2e04acd831b;p=mirror%2Ffrr.git bgpd: small simplification for evpn RT commands Small simplification for evpn RT commands, i.e. both per-VRF and per-VNI - `bgp_evpn_vrf_rt_cmd` and `bgp_evpn_vni_rt_cmd`. Just extract the duplicated code as a common code, there are no functional changes. Additionally correct one comment for `ecommunity_free()`. Signed-off-by: anlan_cs --- diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c index 5a053a7f34..08caa24a1b 100644 --- a/bgpd/bgp_ecommunity.c +++ b/bgpd/bgp_ecommunity.c @@ -63,7 +63,7 @@ void ecommunity_strfree(char **s) XFREE(MTYPE_ECOMMUNITY_STR, *s); } -/* Allocate ecommunities. */ +/* Free ecommunities. */ void ecommunity_free(struct ecommunity **ecom) { if (!(*ecom)) diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 4da3fa8f3b..5f519e84ed 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -5858,16 +5858,15 @@ DEFUN (bgp_evpn_vrf_rt, return CMD_WARNING; } + ecomadd = ecommunity_str2com(argv[2]->arg, ECOMMUNITY_ROUTE_TARGET, 0); + if (!ecomadd) { + vty_out(vty, "%% Malformed Route Target list\n"); + return CMD_WARNING; + } + ecommunity_str(ecomadd); + /* Add/update the import route-target */ if (rt_type == RT_TYPE_BOTH || rt_type == RT_TYPE_IMPORT) { - ecomadd = ecommunity_str2com(argv[2]->arg, - ECOMMUNITY_ROUTE_TARGET, 0); - if (!ecomadd) { - vty_out(vty, "%% Malformed Route Target list\n"); - return CMD_WARNING; - } - ecommunity_str(ecomadd); - /* Do nothing if we already have this import route-target */ if (!bgp_evpn_rt_matches_existing(bgp->vrf_import_rtl, ecomadd)) bgp_evpn_configure_import_rt_for_vrf(bgp, ecomadd); @@ -5875,14 +5874,6 @@ DEFUN (bgp_evpn_vrf_rt, /* Add/update the export route-target */ if (rt_type == RT_TYPE_BOTH || rt_type == RT_TYPE_EXPORT) { - ecomadd = ecommunity_str2com(argv[2]->arg, - ECOMMUNITY_ROUTE_TARGET, 0); - if (!ecomadd) { - vty_out(vty, "%% Malformed Route Target list\n"); - return CMD_WARNING; - } - ecommunity_str(ecomadd); - /* Do nothing if we already have this export route-target */ if (!bgp_evpn_rt_matches_existing(bgp->vrf_export_rtl, ecomadd)) bgp_evpn_configure_export_rt_for_vrf(bgp, ecomadd); @@ -6107,16 +6098,15 @@ DEFUN (bgp_evpn_vni_rt, return CMD_WARNING; } + ecomadd = ecommunity_str2com(argv[2]->arg, ECOMMUNITY_ROUTE_TARGET, 0); + if (!ecomadd) { + vty_out(vty, "%% Malformed Route Target list\n"); + return CMD_WARNING; + } + ecommunity_str(ecomadd); + /* Add/update the import route-target */ if (rt_type == RT_TYPE_BOTH || rt_type == RT_TYPE_IMPORT) { - ecomadd = ecommunity_str2com(argv[2]->arg, - ECOMMUNITY_ROUTE_TARGET, 0); - if (!ecomadd) { - vty_out(vty, "%% Malformed Route Target list\n"); - return CMD_WARNING; - } - ecommunity_str(ecomadd); - /* Do nothing if we already have this import route-target */ if (!bgp_evpn_rt_matches_existing(vpn->import_rtl, ecomadd)) evpn_configure_import_rt(bgp, vpn, ecomadd); @@ -6124,14 +6114,6 @@ DEFUN (bgp_evpn_vni_rt, /* Add/update the export route-target */ if (rt_type == RT_TYPE_BOTH || rt_type == RT_TYPE_EXPORT) { - ecomadd = ecommunity_str2com(argv[2]->arg, - ECOMMUNITY_ROUTE_TARGET, 0); - if (!ecomadd) { - vty_out(vty, "%% Malformed Route Target list\n"); - return CMD_WARNING; - } - ecommunity_str(ecomadd); - /* Do nothing if we already have this export route-target */ if (!bgp_evpn_rt_matches_existing(vpn->export_rtl, ecomadd)) evpn_configure_export_rt(bgp, vpn, ecomadd);