]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Use fls64 instead of ffs64 because we're interested in how many bits
authorRoy Marples <roy@marples.name>
Tue, 2 Feb 2016 22:52:40 +0000 (22:52 +0000)
committerRoy Marples <roy@marples.name>
Tue, 2 Feb 2016 22:52:40 +0000 (22:52 +0000)
a number is so it fits.

configure
dhcp6.c

index 24cac8f040b5719ed8af3b9627517a3129c681de..541e091f99072d24c4f7e7651fc18535cfd5776e 100755 (executable)
--- a/configure
+++ b/configure
@@ -985,23 +985,23 @@ if [ "$BE64ENC" = no ]; then
        echo "#include          \"compat/endian.h\"" >>$CONFIG_H
 fi
 
-if [ -z "$FFS64" ]; then
-       printf "Testing for ffs64 ... "
-       cat <<EOF >_ffs64.c
+if [ -z "$FLS64" ]; then
+       printf "Testing for fls64 ... "
+       cat <<EOF >_fls64.c
 #include <sys/bitops.h>
 int main(void) {
-       return (int)ffs64(1337);
+       return (int)fls64(1337);
 }
 EOF
-       if $XCC _ffs64.c -o _ffs64 2>&3; then
-               FFS64=yes
+       if $XCC _fls64.c -o _fls64 2>&3; then
+               FLS64=yes
        else
-               FFS64=no
+               FLS64=no
        fi
-       echo "$FFS64"
-       rm -f _ffs64.c _ffs64
+       echo "$FLS64"
+       rm -f _fls64.c _fls64
 fi
-if [ "$FFS64" = yes ]; then
+if [ "$FLS64" = yes ]; then
        echo "#define HAVE_SYS_BITOPS_H" >>$CONFIG_H
 fi
 
diff --git a/dhcp6.c b/dhcp6.c
index 0e6b958b2d4d38abbdc1c2d02b6f83fa405fb578..bd6eb52c0f1d1d6b8160af86324415de03da59ff 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -424,13 +424,13 @@ dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp,
 
                        sla_max = 0;
                        TAILQ_FOREACH(ifi, ifp->ctx->ifaces, next) {
-                               if (ifi != ifp && ifi->index > sla_max)
+                               if (ifi->index > sla_max)
                                        sla_max = ifi->index;
                        }
                } else
                        sla_max = ia->sla_max;
 
-               bits = ffs32(sla_max);
+               bits = fls32(sla_max);
 
                if (prefix->prefix_len + bits > UINT8_MAX)
                        asla.prefix_len = UINT8_MAX;
@@ -443,10 +443,9 @@ dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp,
                                asla.prefix_len = 64;
                        else
                                asla.prefix_len = (uint8_t)ROUNDUP8(asla.prefix_len);
-
                }
 
-#define BIT(n) (1l << (n))
+#define BIT(n) (1UL << (n))
 #define BIT_MASK(len) (BIT(len) - 1)
                if (ia->sla_max == 0)
                        /* Work out the real sla_max from our bits used */
@@ -2355,7 +2354,7 @@ dhcp6_ifdelegateaddr(struct interface *ifp, struct ipv6_addr *prefix,
            sla, ia)) == -1)
                return NULL;
 
-       if (ffs64(sla->suffix) > 128 - pfxlen) {
+       if (fls64(sla->suffix) > 128 - pfxlen) {
                logger(ifp->ctx, LOG_ERR,
                    "%s: suffix %" PRIu64 " + prefix_len %d > 128",
                    ifp->name, sla->suffix, pfxlen);