]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
inet6: Add 'temporary' directive to the slaac option
authorRoy Marples <roy@marples.name>
Sun, 19 Apr 2020 06:52:47 +0000 (07:52 +0100)
committerRoy Marples <roy@marples.name>
Sun, 19 Apr 2020 06:52:47 +0000 (07:52 +0100)
This instructs dhcpcd to create a temporary address for each
address generated from a RA.
As such, dhcpcd no longer looks at the kernel option for it
as the functionality is being removed from some or never existed
in the first place.

src/dhcpcd.conf.5.in
src/if-bsd.c
src/if-linux.c
src/if-options.c
src/if-options.h
src/if.h
src/ipv6.c
src/ipv6nd.c

index 71c704994727c53aacd2376abcf4e301cc9405dd..974e95180ff17d3b3976ab433b3e8d7721e719ea 100644 (file)
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd February 19, 2020
+.Dd April 19, 2020
 .Dt DHCPCD.CONF 5
 .Os
 .Sh NAME
@@ -442,7 +442,7 @@ will only fork to the background if the RA contains at least one unexpired
 RDNSS option and a valid prefix or no DHCPv6 instruction.
 Set this option so to make
 .Nm dhcpcd
-always fork on an RA.
+always fork on a RA.
 .It Ic ipv6rs
 Enables IPv6 Router Advertisement solicitation.
 This is on by default, but is documented here in the case where it is disabled
@@ -626,11 +626,14 @@ instead of the default
 .It Ic ssid Ar ssid
 Subsequent options are only parsed for this wireless
 .Ar ssid .
-.It Ic slaac Op Ar hwaddr | Ar private
+.It Ic slaac Ar hwaddr | Ar private Op Ar temp | Ar temporary
 Selects the interface identifier used for SLAAC generated IPv6 addresses.
 If
 .Ar private
-is used, an RFC 7217 address is generated.
+is used, a RFC 7217 address is generated.
+The
+.Ar temporary
+directive will create a temporary address for the prefix as well.
 .It Ic static Ar value
 Configures a static
 .Ar value .
index 7361669a63fc014c3bd29cc4f8c5656b59056371..973fca1ac121c5a0de6433f75cc9584761d97c4b 100644 (file)
@@ -1626,7 +1626,6 @@ if_machinearch(char *str, size_t len)
 
 #ifdef INET6
 #if (defined(IPV6CTL_ACCEPT_RTADV) && !defined(ND6_IFF_ACCEPT_RTADV)) || \
-    defined(IPV6CTL_USETEMPADDR) || defined(IPV6CTL_TEMPVLTIME) || \
     defined(IPV6CTL_FORWARDING)
 #define get_inet6_sysctl(code) inet6_sysctl(code, 0, 0)
 #define set_inet6_sysctl(code, val) inet6_sysctl(code, val, 1)
@@ -1687,8 +1686,7 @@ if_applyra(const struct ra *rap)
 #endif
 }
 
-#ifdef IPV6_MANAGETEMPADDR
-#if !defined(IPV6CTL_TEMPVLTIME) && !defined(__OpenBSD__)
+#ifndef IPV6CTL_FORWARDING
 #define get_inet6_sysctlbyname(code) inet6_sysctlbyname(code, 0, 0)
 #define set_inet6_sysctlbyname(code, val) inet6_sysctlbyname(code, val, 1)
 static int
@@ -1708,81 +1706,6 @@ inet6_sysctlbyname(const char *name, int val, int action)
 }
 #endif
 
-#ifdef __OpenBSD__
-int
-ip6_use_tempaddr(const char *ifname)
-{
-       int s, r;
-       struct ifreq ifr;
-
-       s = socket(PF_INET6, SOCK_DGRAM, 0); /* XXX Not efficient */
-       if (s == -1)
-               return -1;
-       strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-       r = ioctl(s, SIOCGIFXFLAGS, &ifr);
-       close(s);
-       if (r == -1)
-               return -1;
-       return ifr.ifr_flags & IFXF_INET6_NOPRIVACY ? 0 : 1;
-}
-
-int
-ip6_temp_preferred_lifetime(__unused const char *ifname)
-{
-
-       return TEMP_PREFERRED_LIFETIME;
-}
-
-int
-ip6_temp_valid_lifetime(__unused const char *ifname)
-{
-
-       return TEMP_VALID_LIFETIME;
-}
-
-#else /* __OpenBSD__ */
-
-int
-ip6_use_tempaddr(__unused const char *ifname)
-{
-       int val;
-
-#ifdef IPV6CTL_USETEMPADDR
-       val = get_inet6_sysctl(IPV6CTL_USETEMPADDR);
-#else
-       val = get_inet6_sysctlbyname("net.inet6.ip6.use_tempaddr");
-#endif
-       return val == -1 ? 0 : val;
-}
-
-int
-ip6_temp_preferred_lifetime(__unused const char *ifname)
-{
-       int val;
-
-#ifdef IPV6CTL_TEMPPLTIME
-       val = get_inet6_sysctl(IPV6CTL_TEMPPLTIME);
-#else
-       val = get_inet6_sysctlbyname("net.inet6.ip6.temppltime");
-#endif
-       return val < 0 ? TEMP_PREFERRED_LIFETIME : val;
-}
-
-int
-ip6_temp_valid_lifetime(__unused const char *ifname)
-{
-       int val;
-
-#ifdef IPV6CTL_TEMPVLTIME
-       val = get_inet6_sysctl(IPV6CTL_TEMPVLTIME);
-#else
-       val = get_inet6_sysctlbyname("net.inet6.ip6.tempvltime");
-#endif
-       return val < 0 ? TEMP_VALID_LIFETIME : val;
-}
-#endif /* !__OpenBSD__ */
-#endif
-
 int
 ip6_forwarding(__unused const char *ifname)
 {
index 9cc6c52758dd7ed0be411df1f6858c1d6887a9fc..5f069c1fb7b99f8cd0132bbc45acbd4b57d9ce10 100644 (file)
@@ -2019,48 +2019,6 @@ if_applyra(const struct ra *rap)
        return error;
 }
 
-#ifdef IPV6_MANAGETEMPADDR
-int
-ip6_use_tempaddr(const char *ifname)
-{
-       char path[256];
-       int val;
-
-       if (ifname == NULL)
-               ifname = "all";
-       snprintf(path, sizeof(path), "%s/%s/use_tempaddr", p_conf, ifname);
-       val = check_proc_int(path);
-       return val == -1 ? 0 : val;
-}
-
-int
-ip6_temp_preferred_lifetime(const char *ifname)
-{
-       char path[256];
-       int val;
-
-       if (ifname == NULL)
-               ifname = "all";
-       snprintf(path, sizeof(path), "%s/%s/temp_prefered_lft", p_conf,
-           ifname);
-       val = check_proc_int(path);
-       return val < 0 ? TEMP_PREFERRED_LIFETIME : val;
-}
-
-int
-ip6_temp_valid_lifetime(const char *ifname)
-{
-       char path[256];
-       int val;
-
-       if (ifname == NULL)
-               ifname = "all";
-       snprintf(path, sizeof(path), "%s/%s/temp_valid_lft", p_conf, ifname);
-       val = check_proc_int(path);
-       return val < 0 ? TEMP_VALID_LIFETIME : val;
-}
-#endif /* IPV6_MANAGETEMPADDR */
-
 int
 ip6_forwarding(const char *ifname)
 {
index 1280cfbd99d0f54bdbfd8775b72ef368ebd97456..79b2f6bf7bb21b569dbb8ad337d3a00117a4b642 100644 (file)
@@ -2193,12 +2193,20 @@ invalid_token:
                break;
        case O_SLAAC:
                ARG_REQUIRED;
+               np = strwhite(arg);
+               if (np != NULL) {
+                       *np++ = '\0';
+                       np = strskipwhite(np);
+               }
                if (strcmp(arg, "private") == 0 ||
                    strcmp(arg, "stableprivate") == 0 ||
                    strcmp(arg, "stable") == 0)
                        ifo->options |= DHCPCD_SLAACPRIVATE;
                else
                        ifo->options &= ~DHCPCD_SLAACPRIVATE;
+               if (np != NULL &&
+                   (strcmp(np, "temp") == 0 || strcmp(np, "temporary") == 0))
+                       ifo->options |= DHCPCD_SLAACTEMP;
                break;
        case O_BOOTP:
                ifo->options |= DHCPCD_BOOTP;
index 9c3c0f570ea169b5d832a8296b651899eed79c06..f9d47713fec58386650e261fc724d1f6de610cb2 100644 (file)
 #define DHCPCD_PRINT_PIDFILE           (1ULL << 59)
 #define DHCPCD_ONESHOT                 (1ULL << 60)
 #define DHCPCD_INACTIVE                        (1ULL << 61)
+#define        DHCPCD_SLAACTEMP                (1ULL << 62)
 
 #define DHCPCD_NODROP  (DHCPCD_EXITING | DHCPCD_PERSISTENT)
 
index df1cb92c549f602984366fa76929daa9a1375a47..0a2fc6cb3a26a3af41ea47eeeca16b6a298a14b4 100644 (file)
--- a/src/if.h
+++ b/src/if.h
@@ -220,13 +220,6 @@ int if_addrflags(const struct interface *, const struct in_addr *,
 #ifdef INET6
 void if_disable_rtadv(void);
 void if_setup_inet6(const struct interface *);
-#ifdef IPV6_MANAGETEMPADDR
-int ip6_use_tempaddr(const char *ifname);
-int ip6_temp_preferred_lifetime(const char *ifname);
-int ip6_temp_valid_lifetime(const char *ifname);
-#else
-#define ip6_use_tempaddr(a) (0)
-#endif
 int ip6_forwarding(const char *ifname);
 
 struct ra;
index 3e0dcc0c76aade33dea987b24cac510bc2699de8..954f47f0cc34443ba8da2828cf882be3ebbc7465 100644 (file)
@@ -744,7 +744,7 @@ ipv6_addaddr1(struct ipv6_addr *ia, const struct timespec *now)
        if (ia->flags & IPV6_AF_TEMPORARY &&
            ia->prefix_pltime &&
            ia->prefix_vltime &&
-           ip6_use_tempaddr(ifp->name))
+           ifp->options->options & DHCPCD_SLAACTEMP)
                eloop_timeout_add_sec(ifp->ctx->eloop,
                    ia->prefix_pltime - REGEN_ADVANCE,
                    ipv6_regentempaddr, ia);
@@ -1866,7 +1866,7 @@ static void
 ipv6_regen_desync(struct interface *ifp, bool force)
 {
        struct ipv6_state *state;
-       unsigned int max, pref;
+       unsigned int max;
 
        state = IPV6_STATE(ifp);
 
@@ -1874,14 +1874,13 @@ ipv6_regen_desync(struct interface *ifp, bool force)
         * greater than TEMP_VALID_LIFETIME - REGEN_ADVANCE.
         * I believe this is an error and it should be never be greater than
         * TEMP_PREFERRED_LIFETIME - REGEN_ADVANCE. */
-       pref = (unsigned int)ip6_temp_preferred_lifetime(ifp->name);
-       max = pref - REGEN_ADVANCE;
+       max = TEMP_PREFERRED_LIFETIME - REGEN_ADVANCE;
        if (state->desync_factor && !force && state->desync_factor < max)
                return;
        if (state->desync_factor == 0)
                state->desync_factor =
                    arc4random_uniform(MIN(MAX_DESYNC_FACTOR, max));
-       max = pref - state->desync_factor - REGEN_ADVANCE;
+       max = TEMP_PREFERRED_LIFETIME - state->desync_factor - REGEN_ADVANCE;
        eloop_timeout_add_sec(ifp->ctx->eloop, max, ipv6_regentempaddrs, ifp);
 }
 
@@ -1917,7 +1916,6 @@ ipv6_createtempaddr(struct ipv6_addr *ia0, const struct timespec *now)
        struct ipv6_state *state;
        struct interface *ifp = ia0->iface;
        struct ipv6_addr *ia;
-       uint32_t i;
 
        ia = ipv6_newaddr(ifp, &ia0->prefix, ia0->prefix_len,
            IPV6_AF_AUTOCONF | IPV6_AF_TEMPORARY);
@@ -1932,11 +1930,9 @@ ipv6_createtempaddr(struct ipv6_addr *ia0, const struct timespec *now)
 
        /* RFC4941 Section 3.3.4 */
        state = IPV6_STATE(ia->iface);
-       i = (uint32_t)ip6_temp_preferred_lifetime(ifp->name) -
-           state->desync_factor;
-       ia->prefix_pltime = MIN(ia0->prefix_pltime, i);
-       i = (uint32_t)ip6_temp_valid_lifetime(ifp->name);
-       ia->prefix_vltime = MIN(ia0->prefix_vltime, i);
+       ia->prefix_pltime = MIN(ia0->prefix_pltime,
+           TEMP_PREFERRED_LIFETIME - state->desync_factor);
+       ia->prefix_vltime = MIN(ia0->prefix_vltime, TEMP_VALID_LIFETIME);
        if (ia->prefix_pltime <= REGEN_ADVANCE ||
            ia->prefix_pltime > ia0->prefix_vltime)
        {
@@ -1994,7 +1990,7 @@ ipv6_settemptime(struct ipv6_addr *ia, int flags)
                        ext = (unsigned int)ia->acquired.tv_sec
                            + ia->prefix_pltime;
                        max = (unsigned int)(ap->created.tv_sec +
-                           ip6_temp_preferred_lifetime(ap->iface->name) -
+                           TEMP_PREFERRED_LIFETIME -
                            state->desync_factor);
                        if (ext < max)
                                ap->prefix_pltime = ia->prefix_pltime;
@@ -2006,7 +2002,7 @@ valid:
                        ext = (unsigned int)ia->acquired.tv_sec +
                            ia->prefix_vltime;
                        max = (unsigned int)(ap->created.tv_sec +
-                           ip6_temp_valid_lifetime(ap->iface->name));
+                           TEMP_VALID_LIFETIME);
                        if (ext < max)
                                ap->prefix_vltime = ia->prefix_vltime;
                        else
index 6f5ce35b24196c00e64ba0effd7b8798d8336610..1b048db90115f007f24a749829c70fca96aab3fc 100644 (file)
@@ -1338,7 +1338,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
 #ifdef IPV6_MANAGETEMPADDR
                        /* RFC4941 Section 3.3.3 */
                        if (ia->flags & IPV6_AF_AUTOCONF &&
-                           ip6_use_tempaddr(ia->iface->name) &&
+                           ia->iface->options->options & DHCPCD_SLAACTEMP &&
                            IA6_CANAUTOCONF(ia))
                        {
                                if (!new_ia) {