Commit 13d8899c6b for frr
commit 13d8899c6bfbd8348ca0c909ea630c3363caa76d
Author: Philippe Guibert <philippe.guibert@6wind.com>
Date: Thu Nov 26 16:23:00 2026 +0100
bgpd: add allowas-in for the routes imported into a VRF
Since d4426b62d2 ("bgpd: copy source vrf ASN to leaked route and block
loops"), a route is not imported from VPN into a VRF when its AS path
contains the AS of this VRF. Configurations working with previous
releases break, for instance when the VRF uses the AS of the customer
sites:
ce2 (AS 65100) --- r2 VRF-A (AS 65300) --> r2 (AS 65300)
| eBGP VPNv4
r1 VRF-B (AS 65100) <-- r1 (AS 65200)
ce2 advertises 10.0.0.1/32: r1 receives it in VPN with AS path
"65300 65100", but does not import it into VRF-B anymore.
vpn_leak_to_vrf_update_onevrf() only relaxes this check with the
allowas-in value of the peer from which the route was received: the VPN
peer, or the peer of the source VRF. This also relaxes the AS path check
of all the routes received from this peer, and nothing can be done for
the routes originated in the source VRF.
Add the "allowas-in vpn import [(1-10)]" command in the VRF
address-family. It accepts the VRF AS in the AS path of the routes
imported into this VRF, up to the given number of occurrences, 3 by
default as for "neighbor PEER allowas-in". The "no" form disables it and
resets the number. It is disabled by default. This default is a
BGP_VPN_IMPORT_ALLOWAS_IN configuration default, with the same value in
all the profiles, so that a build can enable it; "no allowas-in vpn
import" is then shown in the configuration.
As for "route-map vpn import" and "import vrf route-map", add the
"import vrf allowas-in [(1-10)]" command for the routes imported
with "import vrf VRFNAME". Both commands set the same option. Each one is
refused in the other leaking mode, and the configuration shows the one
matching the leaking mode of the VRF. As "import vrf route-map", "import
vrf allowas-in" keeps the VRF in the VRF-to-VRF leaking mode when the
last "import vrf VRFNAME" or "import vrf route-map" is removed, as long as
the option differs from the default.
The routes are imported again when the command changes.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c
index 6d4336001b..ba3616b32e 100644
--- a/bgpd/bgp_mplsvpn.c
+++ b/bgpd/bgp_mplsvpn.c
@@ -2517,6 +2517,10 @@ static void vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */
*/
aspath_loop_count = from->allowas_in[afi][SAFI_UNICAST];
+ if (CHECK_FLAG(to_bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_FROMVPN_ALLOWAS_IN) &&
+ to_bgp->vpn_policy[afi].import_allowas_in > aspath_loop_count)
+ aspath_loop_count = to_bgp->vpn_policy[afi].import_allowas_in;
+
if (aspath_loop_check(path_vpn->attr->aspath, to_bgp->as) > aspath_loop_count) {
for (bpi = bgp_dest_get_bgp_path_info(bn); bpi;
bpi = bpi->next) {
@@ -3453,7 +3457,9 @@ void vrf_unimport_from_vrf(struct bgp *to_bgp, struct bgp *from_bgp, const char
vpn_leak_prechange(idir, afi, bgp_get_default(), to_bgp);
if (to_bgp->vpn_policy[afi].import_vrf->count == 0) {
- if (!to_bgp->vpn_policy[afi].rmap[idir] && !to_bgp->vpn_policy[afi].rmap_name[idir])
+ if (!to_bgp->vpn_policy[afi].rmap[idir] &&
+ !to_bgp->vpn_policy[afi].rmap_name[idir] &&
+ !bgp_vpn_policy_import_allowas_in_configured(to_bgp, afi))
UNSET_FLAG(to_bgp->af_flags[afi][safi],
BGP_CONFIG_VRF_TO_VRF_IMPORT);
if (to_bgp->vpn_policy[afi].rtlist[idir])
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 3f43cf5c1b..e19a5b8e34 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -154,6 +154,10 @@ FRR_CFG_DEFAULT_BOOL(BGP_IPV6_NEXTHOP_PREFER_GLOBAL,
{ .val_bool = false },
);
+FRR_CFG_DEFAULT_BOOL(BGP_VPN_IMPORT_ALLOWAS_IN,
+ { .val_bool = false },
+);
+
DEFINE_HOOK(bgp_inst_config_write,
(struct bgp *bgp, struct vty *vty),
(bgp, vty));
@@ -748,6 +752,7 @@ int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
enum asnotation_mode asnotation)
{
int ret = bgp_get(bgp, as, name, inst_type, as_pretty, asnotation);
+ afi_t afi;
if (ret == BGP_CREATED) {
bgp_timers_set(NULL, *bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
@@ -788,6 +793,10 @@ int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
SET_FLAG((*bgp)->flags, BGP_FLAG_COMPARE_AIGP);
if (DFLT_BGP_DEFAULT_ORIGINATE_SETONLY_UNCONDITIONAL)
SET_FLAG((*bgp)->flags, BGP_FLAG_DEFAULT_ORIGINATE_SETONLY_UNCONDITIONAL);
+ if (DFLT_BGP_VPN_IMPORT_ALLOWAS_IN)
+ for (afi = AFI_IP; afi < AFI_MAX; afi++)
+ SET_FLAG((*bgp)->vpn_policy[afi].flags,
+ BGP_VPN_POLICY_FROMVPN_ALLOWAS_IN);
ret = BGP_SUCCESS;
}
@@ -11615,6 +11624,50 @@ ALIAS (af_route_map_vpn_imexport,
"For routes leaked from vpn to current address-family\n"
"For routes leaked from current address-family to vpn\n")
+bool bgp_vpn_policy_import_allowas_in_configured(struct bgp *bgp, afi_t afi)
+{
+ if (!CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_FROMVPN_ALLOWAS_IN))
+ return DFLT_BGP_VPN_IMPORT_ALLOWAS_IN;
+
+ return !DFLT_BGP_VPN_IMPORT_ALLOWAS_IN ||
+ bgp->vpn_policy[afi].import_allowas_in != BGP_ALLOWAS_IN_DEFAULT;
+}
+
+static void bgp_vpn_policy_import_allowas_in_set(struct bgp *bgp, afi_t afi, bool no,
+ const char *count_str, long count)
+{
+ vpn_leak_prechange(BGP_VPN_POLICY_DIR_FROMVPN, afi, bgp_get_default(), bgp);
+ if (no) {
+ UNSET_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_FROMVPN_ALLOWAS_IN);
+ bgp->vpn_policy[afi].import_allowas_in = BGP_ALLOWAS_IN_DEFAULT;
+ } else {
+ SET_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_FROMVPN_ALLOWAS_IN);
+ bgp->vpn_policy[afi].import_allowas_in = count_str ? count : BGP_ALLOWAS_IN_DEFAULT;
+ }
+ vpn_leak_postchange(BGP_VPN_POLICY_DIR_FROMVPN, afi, bgp_get_default(), bgp);
+}
+
+DEFPY (af_allowas_in_vpn_import,
+ af_allowas_in_vpn_import_cmd,
+ "[no] allowas-in vpn import [(1-10)$count]",
+ NO_STR
+ "Accept as-path with my AS present in it\n"
+ "Between current address-family and vpn\n"
+ "For routes leaked from vpn to current address-family\n"
+ "Number of occurrences of AS number\n")
+{
+ VTY_DECLVAR_CONTEXT(bgp, bgp);
+ afi_t afi;
+
+ afi = vpn_policy_getafi(vty, bgp, false);
+ if (afi == AFI_MAX)
+ return CMD_WARNING_CONFIG_FAILED;
+
+ bgp_vpn_policy_import_allowas_in_set(bgp, afi, !!no, count_str, count);
+
+ return CMD_SUCCESS;
+}
+
DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
"import vrf route-map RMAP$rmap_str",
"Import routes from another VRF\n"
@@ -11694,7 +11747,8 @@ DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
bgp->vpn_policy[afi].rmap_name[dir] = NULL;
bgp->vpn_policy[afi].rmap[dir] = NULL;
- if (bgp->vpn_policy[afi].import_vrf->count == 0)
+ if (bgp->vpn_policy[afi].import_vrf->count == 0 &&
+ !bgp_vpn_policy_import_allowas_in_configured(bgp, afi))
UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
BGP_CONFIG_VRF_TO_VRF_IMPORT);
@@ -11703,6 +11757,50 @@ DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
return CMD_SUCCESS;
}
+DEFPY (af_import_vrf_allowas_in,
+ af_import_vrf_allowas_in_cmd,
+ "[no] import vrf allowas-in [(1-10)$count]",
+ NO_STR
+ "Import routes from another VRF\n"
+ "Vrf routes being filtered\n"
+ "Accept as-path with my AS present in it\n"
+ "Number of occurrences of AS number\n")
+{
+ VTY_DECLVAR_CONTEXT(bgp, bgp);
+ afi_t afi;
+ struct bgp *bgp_default;
+
+ afi = vpn_policy_getafi(vty, bgp, true);
+ if (afi == AFI_MAX)
+ return CMD_WARNING_CONFIG_FAILED;
+
+ bgp_default = bgp_get_default();
+ if (!no && !bgp_default) {
+ int32_t ret;
+ as_t as = BGP_AS_ZERO;
+
+ /* Auto-create with an unspecified ASN, to be filled in later. */
+ ret = bgp_get_vty(&bgp_default, &as, NULL, BGP_INSTANCE_TYPE_DEFAULT, NULL,
+ ASNOTATION_UNDEFINED);
+
+ if (ret) {
+ vty_out(vty, "VRF default is not configured as a bgp instance\n");
+ return CMD_WARNING;
+ }
+
+ SET_FLAG(bgp_default->flags, BGP_FLAG_INSTANCE_HIDDEN);
+ }
+
+ bgp_vpn_policy_import_allowas_in_set(bgp, afi, !!no, count_str, count);
+ if (bgp_vpn_policy_import_allowas_in_configured(bgp, afi))
+ SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST], BGP_CONFIG_VRF_TO_VRF_IMPORT);
+ else if (bgp->vpn_policy[afi].import_vrf->count == 0 &&
+ !bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
+ UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST], BGP_CONFIG_VRF_TO_VRF_IMPORT);
+
+ return CMD_SUCCESS;
+}
+
DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
"[no] import vrf VIEWVRFNAME$import_name",
NO_STR
@@ -21484,6 +21582,7 @@ static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
{
int indent = 2;
uint32_t tovpn_sid_index = 0;
+ const char *allowas_in_cmd;
if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
@@ -21496,6 +21595,19 @@ static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
bgp->vpn_policy[afi]
.rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
}
+ if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST], BGP_CONFIG_VRF_TO_VRF_IMPORT))
+ allowas_in_cmd = "import vrf allowas-in";
+ else
+ allowas_in_cmd = "allowas-in vpn import";
+ if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_FROMVPN_ALLOWAS_IN)) {
+ if (bgp->vpn_policy[afi].import_allowas_in != BGP_ALLOWAS_IN_DEFAULT)
+ vty_out(vty, "%*s%s %u\n", indent, "", allowas_in_cmd,
+ bgp->vpn_policy[afi].import_allowas_in);
+ else if (!SAVE_BGP_VPN_IMPORT_ALLOWAS_IN)
+ vty_out(vty, "%*s%s\n", indent, "", allowas_in_cmd);
+ } else if (SAVE_BGP_VPN_IMPORT_ALLOWAS_IN) {
+ vty_out(vty, "%*sno %s\n", indent, "", allowas_in_cmd);
+ }
if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
BGP_CONFIG_VRF_TO_VRF_IMPORT)
|| CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
@@ -25513,8 +25625,12 @@ void bgp_vty_init(void)
install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
+ install_element(BGP_IPV4_NODE, &af_allowas_in_vpn_import_cmd);
+ install_element(BGP_IPV6_NODE, &af_allowas_in_vpn_import_cmd);
install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
+ install_element(BGP_IPV4_NODE, &af_import_vrf_allowas_in_cmd);
+ install_element(BGP_IPV6_NODE, &af_import_vrf_allowas_in_cmd);
install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h
index dbc820d2ba..efa74ac25f 100644
--- a/bgpd/bgp_vty.h
+++ b/bgpd/bgp_vty.h
@@ -170,6 +170,7 @@ extern void bgp_config_write_listen(struct vty *vty, struct bgp *bgp);
extern void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp);
extern int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret);
extern bool bgp_config_inprocess(void);
+extern bool bgp_vpn_policy_import_allowas_in_configured(struct bgp *bgp, afi_t afi);
extern struct peer *peer_and_group_lookup_vty(struct vty *vty,
const char *peer_str);
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index b6ae117744..a58e6c2996 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -4148,6 +4148,7 @@ peer_init:
bgp->vpn_policy[afi].tovpn_label = MPLS_LABEL_NONE;
bgp->vpn_policy[afi].tovpn_zebra_vrf_label_last_sent =
MPLS_LABEL_NONE;
+ bgp->vpn_policy[afi].import_allowas_in = BGP_ALLOWAS_IN_DEFAULT;
if (!bgp->vpn_policy[afi].import_vrf)
bgp->vpn_policy[afi].import_vrf = list_new();
@@ -5056,6 +5057,7 @@ int bgp_delete(struct bgp *bgp)
if (bgp->vpn_policy[afi].import_vrf)
list_delete(&bgp->vpn_policy[afi].import_vrf);
+ UNSET_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_FROMVPN_ALLOWAS_IN);
dir = BGP_VPN_POLICY_DIR_FROMVPN;
if (bgp->vpn_policy[afi].rtlist[dir])
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 045718a1f0..cd7993cc2f 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -313,6 +313,11 @@ struct vpn_policy {
char *rmap_name[BGP_VPN_POLICY_DIR_MAX];
struct route_map *rmap[BGP_VPN_POLICY_DIR_MAX];
+ /* Number of occurrences of the VRF AS accepted when importing, with
+ * BGP_VPN_POLICY_FROMVPN_ALLOWAS_IN
+ */
+ uint8_t import_allowas_in;
+
/* should be mpls_label_t? */
uint32_t tovpn_label; /* may be MPLS_LABEL_NONE */
uint32_t tovpn_zebra_vrf_label_last_sent;
@@ -333,6 +338,8 @@ struct vpn_policy {
#define BGP_VPN_POLICY_TOVPN_SID_FUNC_WIDE (1 << 8)
/* Is this RT value set by the cli? */
#define BGP_VPN_POLICY_TOVPN_RT_CLI_SET (1 << 9)
+/* Accept the VRF AS in the AS path of the routes imported */
+#define BGP_VPN_POLICY_FROMVPN_ALLOWAS_IN (1 << 10)
/*
* If we are importing another vrf into us keep a list of
diff --git a/doc/user/bgp.rst b/doc/user/bgp.rst
index d636c61dfa..6a3df0fe40 100644
--- a/doc/user/bgp.rst
+++ b/doc/user/bgp.rst
@@ -3993,6 +3993,14 @@ address-family:
Specifies an optional route-map to be applied to routes imported or exported
between the current unicast VRF and VPN.
+.. clicmd:: allowas-in vpn import [(1-10)]
+
+ Accept the AS of the current unicast VRF in the AS path of the routes
+ imported from VPN, up to the given number of occurrences, 3 by default. By
+ default, these routes are not imported. Unlike
+ ``neighbor PEER allowas-in``, this does not change the AS path check of the
+ routes received from the peers.
+
.. clicmd:: import|export vpn
Enables import or export of routes between the current unicast VRF and VPN.
@@ -4014,6 +4022,11 @@ address-family:
Specifies an optional route-map to be applied to routes imported using the
``import vrf VRFNAME`` shortcut syntax.
+.. clicmd:: import vrf allowas-in [(1-10)]
+
+ Same as ``allowas-in vpn import``, for the routes imported using the
+ ``import vrf VRFNAME`` shortcut syntax.
+
.. clicmd:: bgp retain route-target all
It is possible to retain or not VPN prefixes that are not imported by local