bgpd: configure explicit-null for local paths per address family

Until now, the bgp local paths were using the default null label
defined. It was not possible to select the null label for the ipv4
or the ipv6 address families.

This commit addresses this issues by adding two extra-parameters
to the BGP labeled-unicast command.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
This commit is contained in:
Philippe Guibert 2023-04-19 16:40:50 +02:00
parent 34a8441fe8
commit cf1c7e309e
4 changed files with 37 additions and 13 deletions

View File

@ -3087,10 +3087,13 @@ static bool bgp_lu_need_null_label(struct bgp *bgp,
need_null_label:
if (label == NULL)
return true;
if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_EXPLICIT_NULL))
/* Disable PHP : explicit-null */
*label = afi == AFI_IP ? MPLS_LABEL_IPV4_EXPLICIT_NULL
: MPLS_LABEL_IPV6_EXPLICIT_NULL;
/* Disable PHP : explicit-null */
if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_IPV4_EXPLICIT_NULL) &&
afi == AFI_IP)
*label = MPLS_LABEL_IPV4_EXPLICIT_NULL;
else if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_IPV6_EXPLICIT_NULL) &&
afi == AFI_IP6)
*label = MPLS_LABEL_IPV6_EXPLICIT_NULL;
else
/* Enforced PHP popping: implicit-null */
*label = MPLS_LABEL_IMPLICIT_NULL;

View File

@ -2821,17 +2821,27 @@ DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
}
DEFPY(bgp_lu_uses_explicit_null, bgp_lu_uses_explicit_null_cmd,
"[no] bgp labeled-unicast explicit-null",
"[no] bgp labeled-unicast <explicit-null|ipv4-explicit-null|ipv6-explicit-null>$value",
NO_STR BGP_STR
"BGP Labeled-unicast options\n"
"Use explicit-null label values for local prefixes\n")
"Use explicit-null label values for all local prefixes\n"
"Use the IPv4 explicit-null label value for IPv4 local prefixes\n"
"Use the IPv6 explicit-null label value for IPv6 local prefixes\n")
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
uint64_t label_mode;
if (no)
UNSET_FLAG(bgp->flags, BGP_FLAG_LU_EXPLICIT_NULL);
if (strmatch(value, "ipv4-explicit-null"))
label_mode = BGP_FLAG_LU_IPV4_EXPLICIT_NULL;
else if (strmatch(value, "ipv6-explicit-null"))
label_mode = BGP_FLAG_LU_IPV6_EXPLICIT_NULL;
else
SET_FLAG(bgp->flags, BGP_FLAG_LU_EXPLICIT_NULL);
label_mode = BGP_FLAG_LU_IPV4_EXPLICIT_NULL |
BGP_FLAG_LU_IPV6_EXPLICIT_NULL;
if (no)
UNSET_FLAG(bgp->flags, label_mode);
else
SET_FLAG(bgp->flags, label_mode);
return CMD_SUCCESS;
}
@ -18250,8 +18260,17 @@ int bgp_config_write(struct vty *vty)
? ""
: "no ");
if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_EXPLICIT_NULL))
if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_IPV4_EXPLICIT_NULL) &&
!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_IPV6_EXPLICIT_NULL))
vty_out(vty, " bgp labeled-unicast explicit-null\n");
else if (!!CHECK_FLAG(bgp->flags,
BGP_FLAG_LU_IPV4_EXPLICIT_NULL))
vty_out(vty,
" bgp labeled-unicast ipv4-explicit-null\n");
else if (!!CHECK_FLAG(bgp->flags,
BGP_FLAG_LU_IPV6_EXPLICIT_NULL))
vty_out(vty,
" bgp labeled-unicast ipv6-explicit-null\n");
/* draft-ietf-idr-deprecate-as-set-confed-set */
if (bgp->reject_as_sets)

View File

@ -500,8 +500,10 @@ struct bgp {
#define BGP_FLAG_HARD_ADMIN_RESET (1ULL << 31)
/* Evaluate the AIGP attribute during the best path selection process */
#define BGP_FLAG_COMPARE_AIGP (1ULL << 32)
/* For BGP-LU, force local prefixes to use explicit-null label */
#define BGP_FLAG_LU_EXPLICIT_NULL (1ULL << 33)
/* For BGP-LU, force IPv4 local prefixes to use ipv4-explicit-null label */
#define BGP_FLAG_LU_IPV4_EXPLICIT_NULL (1ULL << 33)
/* For BGP-LU, force IPv6 local prefixes to use ipv6-explicit-null label */
#define BGP_FLAG_LU_IPV6_EXPLICIT_NULL (1ULL << 34)
/* BGP default address-families.
* New peers inherit enabled afi/safis from bgp instance.

View File

@ -2780,7 +2780,7 @@ Labeled unicast
*bgpd* supports labeled information, as per :rfc:`3107`.
.. clicmd:: bgp labeled-unicast explicit-null
.. clicmd:: bgp labeled-unicast <explicit-null|ipv4-explicit-null|ipv6-explicit-null>
By default, locally advertised prefixes use the `implicit-null` label to
encode in the outgoing NLRI. The following command uses the `explicit-null`