From: Roy Marples Date: Mon, 15 Jun 2020 14:51:17 +0000 (+0100) Subject: DHCP6: Use sla setting when calculating delegated prefix length X-Git-Tag: v9.1.2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1913fa8a17cc495104eaecf3e71c62e21a18cc8;p=thirdparty%2Fdhcpcd.git DHCP6: Use sla setting when calculating delegated prefix length 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. --- diff --git a/src/dhcp6.c b/src/dhcp6.c index 70d56a81..da472b9d 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -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); diff --git a/src/if-options.c b/src/if-options.c index 3dde04bf..1b66f758 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -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 " diff --git a/src/if-options.h b/src/if-options.h index 870eabf6..2c974f57 100644 --- a/src/if-options.h +++ b/src/if-options.h @@ -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 {