]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP6: Use sla setting when calculating delegated prefix length
authorRoy Marples <roy@marples.name>
Mon, 15 Jun 2020 14:51:17 +0000 (15:51 +0100)
committerRoy Marples <roy@marples.name>
Mon, 15 Jun 2020 14:51:17 +0000 (15:51 +0100)
This is fine as we have a limited list of interfaces we're
delegating to so we know all the numbers.
This fixes an issue where an interface index could exceed 8 bits.

While here change sla_set to a boolean.

src/dhcp6.c
src/if-options.c
src/if-options.h

index 70d56a813b8ed729978bdba26809f0e8aa83f332..da472b9db382510a0b96af198f0d56c0e64ad06b 100644 (file)
@@ -541,12 +541,12 @@ dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp,
                state->reason = "DELEGATED6";
        }
 
-       if (sla == NULL || sla->sla_set == 0) {
+       if (sla == NULL || !sla->sla_set) {
                /* No SLA set, so make an assumption of
                 * desired SLA and prefix length. */
                asla.sla = ifp->index;
                asla.prefix_len = 0;
-               asla.sla_set = 0;
+               asla.sla_set = false;
                sla = &asla;
        } else if (sla->prefix_len == 0) {
                /* An SLA was given, but prefix length was not.
@@ -554,7 +554,7 @@ dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp,
                 * potentially more than one interface. */
                asla.sla = sla->sla;
                asla.prefix_len = 0;
-               asla.sla_set = 0;
+               asla.sla_set = sla->sla_set;
                sla = &asla;
        }
 
@@ -562,16 +562,15 @@ dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp,
                uint32_t sla_max;
                int bits;
 
-               if (ia->sla_max == 0) {
+               sla_max = ia->sla_max;
+               if (sla_max == 0 && (sla == NULL || !sla->sla_set)) {
                        const struct interface *ifi;
 
-                       sla_max = 0;
                        TAILQ_FOREACH(ifi, ifp->ctx->ifaces, next) {
                                if (ifi->index > sla_max)
                                        sla_max = ifi->index;
                        }
-               } else
-                       sla_max = ia->sla_max;
+               }
 
                bits = fls32(sla_max);
 
index 3dde04bf33c6c2a45b84bf437bb35dcd8f48cd1c..1b66f7589a887408d4d23442a15e64d52b2b2c86 100644 (file)
@@ -1460,7 +1460,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                                logerrx("%s: interface name too long", arg);
                                goto err_sla;
                        }
-                       sla->sla_set = 0;
+                       sla->sla_set = false;
                        sla->prefix_len = 0;
                        sla->suffix = 1;
                        p = np;
@@ -1471,7 +1471,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                                if (*p != '\0') {
                                        sla->sla = (uint32_t)strtou(p, NULL,
                                            0, 0, UINT32_MAX, &e);
-                                       sla->sla_set = 1;
+                                       sla->sla_set = true;
                                        if (e) {
                                                logerrx("%s: failed to convert "
                                                    "sla",
@@ -1530,7 +1530,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                                            sla->ifname);
                                        goto err_sla;
                                }
-                               if (sla->sla_set == 0 &&
+                               if (!sla->sla_set &&
                                    strcmp(slap->ifname, sla->ifname) == 0)
                                {
                                        logwarnx("%s: cannot specify the "
index 870eabf67064fccec8fd886902df7e1ec2355859..2c974f578521c19a6baccf08f2ceefaa681fd3be 100644 (file)
@@ -188,7 +188,7 @@ struct if_sla {
        uint32_t sla;
        uint8_t prefix_len;
        uint64_t suffix;
-       int8_t sla_set;
+       bool sla_set;
 };
 
 struct if_ia {