]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: add ability to set hoplimit for IPv6 RAs
authorDon Slice <dslice@cumulusnetworks.com>
Wed, 15 Apr 2020 12:37:17 +0000 (12:37 +0000)
committerDon Slice <dslice@cumulusnetworks.com>
Wed, 15 Apr 2020 17:56:57 +0000 (17:56 +0000)
Reported by testing agency that rfc 4861 section 6.2.1 states
that all implementations must have a configuration knob to change
the setting of the advertised hop limit.  This fix adds that
capability.

Ticket: CM-29200
Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
zebra/interface.c
zebra/interface.h
zebra/rtadv.c
zebra/subdir.am

index 59cbfc6854559cf6a4b99841ff94fade1339b5f7..7ab7e11f0ee74f6935cedb3398c6c2dfa3bda291 100644 (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;
index b7e90a0c31edcbadbb9afd55f6872698fe606855..2021e301cd01d6f61218a442c6b97821b7e96e65 100644 (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
index a22e39dc4896fd92d7181d36093302abcd88e496..11434edfcf54730a8c6f48f62f2ba9c535127ce9 100644 (file)
 #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);
index 71094cb52c95ef0bfc1c6a26117bb80ce62b6a1c..7a524a1ea97f9248246f0c634a695d140c22714d 100644 (file)
@@ -120,6 +120,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 \