Merge pull request #6231 from dslicenc/v6-ra-hoplimit

zebra: add ability to set hoplimit for IPv6 RAs
This commit is contained in:
Donatas Abraitis 2020-04-18 22:48:20 +03:00 committed by GitHub
commit b34b48cb3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 2 deletions

View File

@ -90,6 +90,17 @@ Router Advertisement
and neighbor establishment.
Default: enabled
.. index::
single: ipv6 nd ra-hop-limit (0-255)
single: no ipv6 nd ra-hop-limit [(0-255)]
.. clicmd:: [no] ipv6 nd ra-hop-limit [(0-255)]
The value to be placed in the hop count field of router advertisements sent
from the interface, in hops. Indicates the maximum diameter of the network.
Setting the value to zero indicates that the value is unspecified by this
router. Must be between zero or 255 hops.
Default: ``64``
.. index::
single: ipv6 nd ra-lifetime (0-9000)
single: no ipv6 nd ra-lifetime [(0-9000)]

View File

@ -153,7 +153,7 @@ static int if_zebra_new_hook(struct interface *ifp)
rtadv->AdvLinkMTU = 0;
rtadv->AdvReachableTime = 0;
rtadv->AdvRetransTimer = 0;
rtadv->AdvCurHopLimit = 0;
rtadv->AdvCurHopLimit = RTADV_DEFAULT_HOPLIMIT;
rtadv->AdvDefaultLifetime =
-1; /* derive from MaxRtrAdvInterval */
rtadv->HomeAgentPreference = 0;

View File

@ -117,6 +117,7 @@ struct rtadvconf {
Default: The value specified in the "Assigned Numbers" RFC
[ASSIGNED] that was in effect at the time of implementation. */
int AdvCurHopLimit;
#define RTADV_DEFAULT_HOPLIMIT 64 /* 64 hops */
/* The value to be placed in the Router Lifetime field of Router
Advertisements sent from the interface, in seconds. MUST be

View File

@ -46,6 +46,10 @@
#include "zebra/zebra_errors.h"
#include "zebra/zebra_router.h"
#ifndef VTYSH_EXTRACT_PL
#include "zebra/rtadv_clippy.c"
#endif
extern struct zebra_privs_t zserv_privs;
#if defined(HAVE_RTADV)
@ -230,7 +234,7 @@ static void rtadv_send_packet(int sock, struct interface *ifp,
rtadv->nd_ra_code = 0;
rtadv->nd_ra_cksum = 0;
rtadv->nd_ra_curhoplimit = 64;
rtadv->nd_ra_curhoplimit = zif->rtadv.AdvCurHopLimit;
/* RFC4191: Default Router Preference is 0 if Router Lifetime is 0. */
rtadv->nd_ra_flags_reserved = zif->rtadv.AdvDefaultLifetime == 0
@ -1231,6 +1235,53 @@ DEFUN (no_ipv6_nd_ra_fast_retrans,
return CMD_SUCCESS;
}
DEFPY (ipv6_nd_ra_hop_limit,
ipv6_nd_ra_hop_limit_cmd,
"ipv6 nd ra-hop-limit (0-255)$hopcount",
"Interface IPv6 config commands\n"
"Neighbor discovery\n"
"Advertisement Hop Limit\n"
"Advertisement Hop Limit in hops (default:64)\n")
{
VTY_DECLVAR_CONTEXT(interface, ifp);
struct zebra_if *zif = ifp->info;
if (if_is_loopback(ifp)
|| CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK)) {
vty_out(vty,
"Cannot configure IPv6 Router Advertisements on this interface\n");
return CMD_WARNING_CONFIG_FAILED;
}
zif->rtadv.AdvCurHopLimit = hopcount;
return CMD_SUCCESS;
}
DEFPY (no_ipv6_nd_ra_hop_limit,
no_ipv6_nd_ra_hop_limit_cmd,
"no ipv6 nd ra-hop-limit [(0-255)]",
NO_STR
"Interface IPv6 config commands\n"
"Neighbor discovery\n"
"Advertisement Hop Limit\n"
"Advertisement Hop Limit in hops\n")
{
VTY_DECLVAR_CONTEXT(interface, ifp);
struct zebra_if *zif = ifp->info;
if (if_is_loopback(ifp)
|| CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK)) {
vty_out(vty,
"Cannot configure IPv6 Router Advertisements on this interface\n");
return CMD_WARNING_CONFIG_FAILED;
}
zif->rtadv.AdvCurHopLimit = RTADV_DEFAULT_HOPLIMIT;
return CMD_SUCCESS;
}
DEFUN (ipv6_nd_suppress_ra,
ipv6_nd_suppress_ra_cmd,
"ipv6 nd suppress-ra",
@ -2178,6 +2229,8 @@ static int nd_dump_vty(struct vty *vty, struct interface *ifp)
vty_out(vty,
" ND advertised retransmit interval is %d milliseconds\n",
rtadv->AdvRetransTimer);
vty_out(vty, " ND advertised hop-count limit is %d hops\n",
rtadv->AdvCurHopLimit);
vty_out(vty, " ND router advertisements sent: %d rcvd: %d\n",
zif->ra_sent, zif->ra_rcvd);
interval = rtadv->MaxRtrAdvInterval;
@ -2269,6 +2322,10 @@ static int rtadv_config_write(struct vty *vty, struct interface *ifp)
if (!zif->rtadv.UseFastRexmit)
vty_out(vty, " no ipv6 nd ra-fast-retrans\n");
if (zif->rtadv.AdvCurHopLimit != RTADV_DEFAULT_HOPLIMIT)
vty_out(vty, " ipv6 nd ra-hop-limit %d\n",
zif->rtadv.AdvCurHopLimit);
if (zif->rtadv.AdvDefaultLifetime != -1)
vty_out(vty, " ipv6 nd ra-lifetime %d\n",
zif->rtadv.AdvDefaultLifetime);
@ -2437,6 +2494,8 @@ void rtadv_cmd_init(void)
install_element(INTERFACE_NODE, &ipv6_nd_ra_fast_retrans_cmd);
install_element(INTERFACE_NODE, &no_ipv6_nd_ra_fast_retrans_cmd);
install_element(INTERFACE_NODE, &ipv6_nd_ra_hop_limit_cmd);
install_element(INTERFACE_NODE, &no_ipv6_nd_ra_hop_limit_cmd);
install_element(INTERFACE_NODE, &ipv6_nd_suppress_ra_cmd);
install_element(INTERFACE_NODE, &no_ipv6_nd_suppress_ra_cmd);
install_element(INTERFACE_NODE, &ipv6_nd_ra_interval_cmd);

View File

@ -123,6 +123,9 @@ zebra/zebra_vty.$(OBJEXT): zebra/zebra_vty_clippy.c
zebra/zebra_routemap_clippy.c: $(CLIPPY_DEPS)
zebra/zebra_routemap.$(OBJEXT): zebra/zebra_routemap_clippy.c
zebra/rtadv_clippy.c: $(CLIPPY_DEPS)
zebra/rtadv.$(OBJEXT): zebra/rtadv_clippy.c
noinst_HEADERS += \
zebra/connected.h \
zebra/debug.h \