Skip to content

Commit ddf909e

Browse files
committed
bgpd: add bgp ipv6-auto-ra command
Introduce a command to stop bgpd from enabling IPv6 router advertisement messages sending on interfaces. Signed-off-by: Mikhail Sokolovskiy <[email protected]>
1 parent 659741f commit ddf909e

File tree

7 files changed

+62
-6
lines changed

7 files changed

+62
-6
lines changed

bgpd/bgp_nht.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,12 @@ static void bgp_process_nexthop_update(struct bgp_nexthop_cache *bnc,
642642
* we receive from bgp. This is to allow us
643643
* to work with v4 routing over v6 nexthops
644644
*/
645-
if (peer && !peer->ifp
646-
&& CHECK_FLAG(peer->flags,
647-
PEER_FLAG_CAPABILITY_ENHE)
648-
&& nhr->prefix.family == AF_INET6
649-
&& nexthop->type != NEXTHOP_TYPE_BLACKHOLE) {
645+
if (peer && !peer->ifp &&
646+
CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE) &&
647+
!CHECK_FLAG(bnc->bgp->flags,
648+
BGP_FLAG_IPV6_NO_AUTO_RA) &&
649+
nhr->prefix.family == AF_INET6 &&
650+
nexthop->type != NEXTHOP_TYPE_BLACKHOLE) {
650651
struct interface *ifp;
651652

652653
ifp = if_lookup_by_index(nexthop->ifindex,
@@ -1515,6 +1516,10 @@ void bgp_nht_reg_enhe_cap_intfs(struct peer *peer)
15151516
return;
15161517

15171518
bgp = peer->bgp;
1519+
1520+
/* Shouldn't enable RA if they are disabled */
1521+
assert(!CHECK_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA));
1522+
15181523
if (!sockunion2hostprefix(&peer->connection->su, &p)) {
15191524
zlog_warn("%s: Unable to convert sockunion to prefix for %s",
15201525
__func__, peer->host);

bgpd/bgp_vty.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5034,6 +5034,27 @@ DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
50345034
return CMD_SUCCESS;
50355035
}
50365036

5037+
DEFPY (bgp_ipv6_auto_ra,
5038+
bgp_ipv6_auto_ra_cmd,
5039+
"[no] bgp ipv6-auto-ra",
5040+
NO_STR
5041+
BGP_STR
5042+
"Allow enabling IPv6 ND RA sending\n")
5043+
{
5044+
if (vty->node == CONFIG_NODE) {
5045+
struct listnode *node, *nnode;
5046+
struct bgp *bgp;
5047+
5048+
COND_FLAG(bm->flags, BM_FLAG_IPV6_NO_AUTO_RA, no);
5049+
for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
5050+
COND_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA, no);
5051+
} else {
5052+
VTY_DECLVAR_CONTEXT(bgp, bgp);
5053+
COND_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA, no);
5054+
}
5055+
return CMD_SUCCESS;
5056+
}
5057+
50375058
static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
50385059
int v6only,
50395060
const char *peer_group_name,
@@ -19361,6 +19382,9 @@ int bgp_config_write(struct vty *vty)
1936119382
if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
1936219383
vty_out(vty, "bgp send-extra-data zebra\n");
1936319384

19385+
if (CHECK_FLAG(bm->flags, BM_FLAG_IPV6_NO_AUTO_RA))
19386+
vty_out(vty, "no bgp ipv6-auto-ra\n");
19387+
1936419388
/* DSCP value for outgoing packets in BGP connections */
1936519389
if (bm->ip_tos != IPTOS_PREC_INTERNETCONTROL)
1936619390
vty_out(vty, "bgp session-dscp %u\n", bm->ip_tos >> 2);
@@ -19777,6 +19801,11 @@ int bgp_config_write(struct vty *vty)
1977719801
if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
1977819802
vty_out(vty, " bgp shutdown\n");
1977919803

19804+
/* Automatic RA enabling by BGP */
19805+
if (!CHECK_FLAG(bm->flags, BM_FLAG_IPV6_NO_AUTO_RA))
19806+
if (CHECK_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA))
19807+
vty_out(vty, " no bgp ipv6-auto-ra\n");
19808+
1978019809
if (bgp->allow_martian)
1978119810
vty_out(vty, " bgp allow-martian-nexthop\n");
1978219811

@@ -20317,6 +20346,12 @@ void bgp_vty_init(void)
2031720346
install_element(BGP_NODE, &bgp_fast_convergence_cmd);
2031820347
install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
2031920348

20349+
/* global bgp ipv6-auto-ra command */
20350+
install_element(CONFIG_NODE, &bgp_ipv6_auto_ra_cmd);
20351+
20352+
/* bgp ipv6-auto-ra command */
20353+
install_element(BGP_NODE, &bgp_ipv6_auto_ra_cmd);
20354+
2032020355
/* global bgp update-delay command */
2032120356
install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
2032220357
install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);

bgpd/bgp_zebra.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,6 +2338,9 @@ void bgp_zebra_initiate_radv(struct bgp *bgp, struct peer *peer)
23382338
{
23392339
uint32_t ra_interval = BGP_UNNUM_DEFAULT_RA_INTERVAL;
23402340

2341+
if (CHECK_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA))
2342+
return;
2343+
23412344
/* Don't try to initiate if we're not connected to Zebra */
23422345
if (zclient->sock < 0)
23432346
return;

bgpd/bgpd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,8 @@ int bgp_global_gr_init(struct bgp *bgp)
14121412
bgp->rib_stale_time = bm->rib_stale_time;
14131413
if (CHECK_FLAG(bm->flags, BM_FLAG_GR_PRESERVE_FWD))
14141414
SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
1415+
if (CHECK_FLAG(bm->flags, BM_FLAG_IPV6_NO_AUTO_RA))
1416+
SET_FLAG(bgp->flags, BGP_FLAG_IPV6_NO_AUTO_RA);
14151417

14161418
bgp->present_zebra_gr_state = ZEBRA_GR_DISABLE;
14171419

bgpd/bgpd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ struct bgp_master {
171171
#define BM_FLAG_GR_PRESERVE_FWD (1 << 5)
172172
#define BM_FLAG_GRACEFUL_RESTART (1 << 6)
173173
#define BM_FLAG_GR_COMPLETE (1 << 7)
174+
#define BM_FLAG_IPV6_NO_AUTO_RA (1 << 8)
174175

175176
#define BM_FLAG_GR_CONFIGURED (BM_FLAG_GR_RESTARTER | BM_FLAG_GR_DISABLED)
176177

@@ -551,6 +552,8 @@ struct bgp {
551552
#define BGP_FLAG_ENFORCE_FIRST_AS (1ULL << 36)
552553
#define BGP_FLAG_DYNAMIC_CAPABILITY (1ULL << 37)
553554
#define BGP_FLAG_VNI_DOWN (1ULL << 38)
555+
/* Prohibit BGP from enabling IPv6 RA on interfaces */
556+
#define BGP_FLAG_IPV6_NO_AUTO_RA (1ULL << 39)
554557

555558
/* BGP default address-families.
556559
* New peers inherit enabled afi/safis from bgp instance.

doc/user/bgp.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,13 @@ IPv6 Support
12821282
address family is enabled by default for all new neighbors.
12831283

12841284

1285+
.. clicmd:: bgp ipv6-auto-ra
1286+
1287+
By default, bgpd can ask Zebra to enable sending IPv6 router advertisement
1288+
messages on interfaces. For example, this happens for unnumbered peers
1289+
support or when extended-nexthop capability is used. The ``no`` form of this
1290+
command disables such behaviour.
1291+
12851292
.. _bgp-route-aggregation:
12861293

12871294
Route Aggregation

doc/user/ipv6.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ Router Advertisement
2525
.. clicmd:: ipv6 nd suppress-ra
2626

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

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

0 commit comments

Comments
 (0)