Use fls64 instead of ffs64 because we're interested in how many bits

a number is so it fits.
This commit is contained in:
Roy Marples 2016-02-02 22:52:40 +00:00
parent b158268270
commit 96695efe83
2 changed files with 14 additions and 15 deletions

20
configure vendored
View File

@ -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

View File

@ -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);