Skip to content

Commit

Permalink
bgpd: add bgp ipv6-auto-ra command
Browse files Browse the repository at this point in the history
Introduce a command to stop bgpd from enabling IPv6 router advertisement
messages sending on interfaces.

Signed-off-by: Mikhail Sokolovskiy <sokolmish@gmail.com>
(cherry picked from commit 7b1c0c2)

# Conflicts:
#	bgpd/bgp_vty.c
#	bgpd/bgpd.c
#	bgpd/bgpd.h
  • Loading branch information
Sokolmish authored and mergify[bot] committed Oct 28, 2024
1 parent fbc85e8 commit 53484ab
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 6 deletions.
15 changes: 10 additions & 5 deletions bgpd/bgp_nht.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,11 +635,12 @@ static void bgp_process_nexthop_update(struct bgp_nexthop_cache *bnc,
* we receive from bgp. This is to allow us
* to work with v4 routing over v6 nexthops
*/
if (peer && !peer->ifp
&& CHECK_FLAG(peer->flags,
PEER_FLAG_CAPABILITY_ENHE)
&& nhr->prefix.family == AF_INET6
&& nexthop->type != NEXTHOP_TYPE_BLACKHOLE) {
if (peer && !peer->ifp &&
CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE) &&
!CHECK_FLAG(bnc->bgp->flags,
BGP_FLAG_IPV6_NO_AUTO_RA) &&
nhr->prefix.family == AF_INET6 &&
nexthop->type != NEXTHOP_TYPE_BLACKHOLE) {
struct interface *ifp;

ifp = if_lookup_by_index(nexthop->ifindex,
Expand Down Expand Up @@ -1494,6 +1495,10 @@ void bgp_nht_reg_enhe_cap_intfs(struct peer *peer)
return;

bgp = peer->bgp;

if (CHECK_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA))
return;

if (!sockunion2hostprefix(&peer->connection->su, &p)) {
zlog_warn("%s: Unable to convert sockunion to prefix for %s",
__func__, peer->host);
Expand Down
41 changes: 41 additions & 0 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -4819,6 +4819,27 @@ DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
return CMD_SUCCESS;
}

DEFPY (bgp_ipv6_auto_ra,
bgp_ipv6_auto_ra_cmd,
"[no] bgp ipv6-auto-ra",
NO_STR
BGP_STR
"Allow enabling IPv6 ND RA sending\n")
{
if (vty->node == CONFIG_NODE) {
struct listnode *node, *nnode;
struct bgp *bgp;

COND_FLAG(bm->flags, BM_FLAG_IPV6_NO_AUTO_RA, no);
for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
COND_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA, no);
} else {
VTY_DECLVAR_CONTEXT(bgp, bgp);
COND_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA, no);
}
return CMD_SUCCESS;
}

static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
int v6only,
const char *peer_group_name,
Expand Down Expand Up @@ -18457,9 +18478,18 @@ int bgp_config_write(struct vty *vty)
if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
vty_out(vty, "bgp send-extra-data zebra\n");

<<<<<<< HEAD
/* BGP session DSCP value */
if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
=======
if (CHECK_FLAG(bm->flags, BM_FLAG_IPV6_NO_AUTO_RA))
vty_out(vty, "no bgp ipv6-auto-ra\n");

/* DSCP value for outgoing packets in BGP connections */
if (bm->ip_tos != IPTOS_PREC_INTERNETCONTROL)
vty_out(vty, "bgp session-dscp %u\n", bm->ip_tos >> 2);
>>>>>>> 7b1c0c23fc (bgpd: add `bgp ipv6-auto-ra` command)

/* BGP InQ limit */
if (bm->inq_limit != BM_DEFAULT_Q_LIMIT)
Expand Down Expand Up @@ -18843,6 +18873,11 @@ int bgp_config_write(struct vty *vty)
if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
vty_out(vty, " bgp shutdown\n");

/* Automatic RA enabling by BGP */
if (!CHECK_FLAG(bm->flags, BM_FLAG_IPV6_NO_AUTO_RA))
if (CHECK_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA))
vty_out(vty, " no bgp ipv6-auto-ra\n");

if (bgp->allow_martian)
vty_out(vty, " bgp allow-martian-nexthop\n");

Expand Down Expand Up @@ -19383,6 +19418,12 @@ void bgp_vty_init(void)
install_element(BGP_NODE, &bgp_fast_convergence_cmd);
install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);

/* global bgp ipv6-auto-ra command */
install_element(CONFIG_NODE, &bgp_ipv6_auto_ra_cmd);

/* bgp ipv6-auto-ra command */
install_element(BGP_NODE, &bgp_ipv6_auto_ra_cmd);

/* global bgp update-delay command */
install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
Expand Down
3 changes: 3 additions & 0 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,9 @@ void bgp_zebra_initiate_radv(struct bgp *bgp, struct peer *peer)
{
uint32_t ra_interval = BGP_UNNUM_DEFAULT_RA_INTERVAL;

if (CHECK_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA))
return;

/* Don't try to initiate if we're not connected to Zebra */
if (zclient->sock < 0)
return;
Expand Down
24 changes: 24 additions & 0 deletions bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,31 @@ int bgp_global_gr_init(struct bgp *bgp)
memcpy(bgp->GLOBAL_GR_FSM, local_GLOBAL_GR_FSM,
sizeof(local_GLOBAL_GR_FSM));

<<<<<<< HEAD
bgp->global_gr_present_state = GLOBAL_HELPER;
=======
/* Inherit any BGP-wide configuration. */
if (CHECK_FLAG(bm->flags, BM_FLAG_GR_RESTARTER))
bgp->global_gr_present_state = GLOBAL_GR;
else if (CHECK_FLAG(bm->flags, BM_FLAG_GR_DISABLED))
bgp->global_gr_present_state = GLOBAL_DISABLE;
else
bgp->global_gr_present_state = GLOBAL_HELPER;

if (bm->restart_time != BGP_DEFAULT_RESTART_TIME)
bgp->restart_time = bm->restart_time;
if (bm->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
bgp->stalepath_time = bm->stalepath_time;
if (bm->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
bgp->select_defer_time = bm->select_defer_time;
if (bm->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
bgp->rib_stale_time = bm->rib_stale_time;
if (CHECK_FLAG(bm->flags, BM_FLAG_GR_PRESERVE_FWD))
SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
if (CHECK_FLAG(bm->flags, BM_FLAG_IPV6_NO_AUTO_RA))
SET_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA);

>>>>>>> 7b1c0c23fc (bgpd: add `bgp ipv6-auto-ra` command)
bgp->present_zebra_gr_state = ZEBRA_GR_DISABLE;

return BGP_GR_SUCCESS;
Expand Down
30 changes: 30 additions & 0 deletions bgpd/bgpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,27 @@ struct bgp_master {
uint32_t flags;
#define BM_FLAG_GRACEFUL_SHUTDOWN (1 << 0)
#define BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA (1 << 1)
<<<<<<< HEAD
=======
#define BM_FLAG_MAINTENANCE_MODE (1 << 2)
#define BM_FLAG_GR_RESTARTER (1 << 3)
#define BM_FLAG_GR_DISABLED (1 << 4)
#define BM_FLAG_GR_PRESERVE_FWD (1 << 5)
#define BM_FLAG_GRACEFUL_RESTART (1 << 6)
#define BM_FLAG_GR_COMPLETE (1 << 7)
#define BM_FLAG_IPV6_NO_AUTO_RA (1 << 8)

#define BM_FLAG_GR_CONFIGURED (BM_FLAG_GR_RESTARTER | BM_FLAG_GR_DISABLED)

/* BGP-wide graceful restart config params */
uint32_t restart_time;
uint32_t stalepath_time;
uint32_t select_defer_time;
uint32_t rib_stale_time;

time_t startup_time;
time_t gr_completion_time;
>>>>>>> 7b1c0c23fc (bgpd: add `bgp ipv6-auto-ra` command)

bool terminating; /* global flag that sigint terminate seen */

Expand Down Expand Up @@ -514,6 +535,15 @@ struct bgp {
/* For BGP-LU, force IPv6 local prefixes to use ipv6-explicit-null label */
#define BGP_FLAG_LU_IPV6_EXPLICIT_NULL (1ULL << 34)
#define BGP_FLAG_SOFT_VERSION_CAPABILITY (1ULL << 35)
<<<<<<< HEAD
=======
#define BGP_FLAG_ENFORCE_FIRST_AS (1ULL << 36)
#define BGP_FLAG_DYNAMIC_CAPABILITY (1ULL << 37)
#define BGP_FLAG_VNI_DOWN (1ULL << 38)
#define BGP_FLAG_INSTANCE_HIDDEN (1ULL << 39)
/* Prohibit BGP from enabling IPv6 RA on interfaces */
#define BGP_FLAG_IPV6_NO_AUTO_RA (1ULL << 40)
>>>>>>> 7b1c0c23fc (bgpd: add `bgp ipv6-auto-ra` command)

/* BGP default address-families.
* New peers inherit enabled afi/safis from bgp instance.
Expand Down
7 changes: 7 additions & 0 deletions doc/user/bgp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,13 @@ IPv6 Support
address family is enabled by default for all new neighbors.


.. clicmd:: bgp ipv6-auto-ra

By default, bgpd can ask Zebra to enable sending IPv6 router advertisement
messages on interfaces. For example, this happens for unnumbered peers
support or when extended-nexthop capability is used. The ``no`` form of this
command disables such behaviour.

.. _bgp-route-aggregation:

Route Aggregation
Expand Down
3 changes: 2 additions & 1 deletion doc/user/ipv6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Router Advertisement
.. clicmd:: ipv6 nd suppress-ra

Don't send router advertisement messages. The ``no`` form of this command
enables sending RA messages.
enables sending RA messages. Note that while being suppressed, RA messages
might still be enabled by other daemons, such as bgpd or vrrpd.

.. clicmd:: ipv6 nd prefix ipv6prefix [valid-lifetime] [preferred-lifetime] [off-link] [no-autoconfig] [router-address]

Expand Down

0 comments on commit 53484ab

Please sign in to comment.