diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index 8ce45558e96f..20a242f16d5a 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -645,6 +645,8 @@ static void bgp_process_nexthop_update(struct bgp_nexthop_cache *bnc, 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; @@ -1515,6 +1517,10 @@ void bgp_nht_reg_enhe_cap_intfs(struct peer *peer) return; bgp = peer->bgp; + + /* Shouldn't enable RA if they are disabled */ + assert(!CHECK_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA)); + if (!sockunion2hostprefix(&peer->connection->su, &p)) { zlog_warn("%s: Unable to convert sockunion to prefix for %s", __func__, peer->host); @@ -1565,6 +1571,11 @@ void bgp_nht_dereg_enhe_cap_intfs(struct peer *peer) bgp = peer->bgp; + /* + * Don't check BGP_FLAG_IPV6_NO_AUTO_RA flag there, + * try to disable it anyway + */ + if (!sockunion2hostprefix(&peer->connection->su, &p)) { zlog_warn("%s: Unable to convert sockunion to prefix for %s", __func__, peer->host); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 0ef135183540..17d76413344e 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -5034,6 +5034,42 @@ DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd, return CMD_SUCCESS; } +static void bgp_set_no_auto_ra_flag(struct vty *vty, bool flag) +{ + if (vty->node == CONFIG_NODE) { + struct listnode *node, *nnode; + struct bgp *bgp; + + COND_FLAG(bm->flags, BM_FLAG_IPV6_NO_AUTO_RA, flag); + for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) + COND_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA, flag); + } else { + VTY_DECLVAR_CONTEXT(bgp, bgp); + COND_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA, flag); + } +} + +DEFUN (bgp_ipv6_auto_ra, + bgp_ipv6_auto_ra_cmd, + "bgp ipv6-auto-ra", + BGP_STR + "Don't allow enabling IPv6 ND RA sending\n") +{ + bgp_set_no_auto_ra_flag(vty, false); + return CMD_SUCCESS; +} + +DEFUN (no_bgp_ipv6_auto_ra, + no_bgp_ipv6_auto_ra_cmd, + "no bgp ipv6-auto-ra", + NO_STR + BGP_STR + "Don't allow enabling IPv6 ND RA sending\n") +{ + bgp_set_no_auto_ra_flag(vty, true); + return CMD_SUCCESS; +} + static int peer_conf_interface_get(struct vty *vty, const char *conf_if, int v6only, const char *peer_group_name, @@ -19360,6 +19396,9 @@ 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"); + + 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) @@ -19777,6 +19816,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"); @@ -20317,6 +20361,14 @@ 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); + install_element(CONFIG_NODE, &no_bgp_ipv6_auto_ra_cmd); + + /* bgp ipv6-auto-ra command */ + install_element(BGP_NODE, &bgp_ipv6_auto_ra_cmd); + install_element(BGP_NODE, &no_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); diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 72620de7d98e..c50e66786d03 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -2338,6 +2338,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; @@ -2358,6 +2361,11 @@ void bgp_zebra_initiate_radv(struct bgp *bgp, struct peer *peer) void bgp_zebra_terminate_radv(struct bgp *bgp, struct peer *peer) { + /* + * Don't check BGP_FLAG_IPV6_NO_AUTO_RA flag there, + * try to disable it anyway + */ + /* Don't try to terminate if we're not connected to Zebra */ if (zclient->sock < 0) return; diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 3810413adcf0..ba0f8401f103 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -1412,6 +1412,8 @@ int bgp_global_gr_init(struct bgp *bgp) 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); bgp->present_zebra_gr_state = ZEBRA_GR_DISABLE; diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 95ddba4cddf0..0abe81792fcd 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -171,6 +171,7 @@ struct bgp_master { #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) @@ -551,6 +552,8 @@ struct bgp { #define BGP_FLAG_ENFORCE_FIRST_AS (1ULL << 36) #define BGP_FLAG_DYNAMIC_CAPABILITY (1ULL << 37) #define BGP_FLAG_VNI_DOWN (1ULL << 38) +/* Prohibit BGP from enabling IPv6 RA on interfaces */ +#define BGP_FLAG_IPV6_NO_AUTO_RA (1ULL << 39) /* BGP default address-families. * New peers inherit enabled afi/safis from bgp instance. diff --git a/doc/user/bgp.rst b/doc/user/bgp.rst index a569a9af2889..91f816d36062 100644 --- a/doc/user/bgp.rst +++ b/doc/user/bgp.rst @@ -1282,6 +1282,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 diff --git a/doc/user/ipv6.rst b/doc/user/ipv6.rst index 4f01061e7b03..18aae00bdb3f 100644 --- a/doc/user/ipv6.rst +++ b/doc/user/ipv6.rst @@ -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]