-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
incorrect netmask generation on certain architectures with the release 7.80 #1717
Comments
The core problem probably comes down to this (from ISO 9899:2011 6.5.7 Bit-wise shift operators):
|
looks like I found a solution, testing a patch on a few more architectures |
Could you please test the following patch and report back? --- a/nbase/nbase_addrset.c
+++ b/nbase/nbase_addrset.c
@@ -477,30 +477,32 @@
static int sockaddr_to_mask (const struct sockaddr *sa, int bits, u32 *mask)
{
- s8 i;
- int unmasked_bits = 0;
+ int i, k;
if (bits >= 0) {
if (sa->sa_family == AF_INET) {
- unmasked_bits = 32 - bits;
+ bits += 96;
}
#ifdef HAVE_IPV6
else if (sa->sa_family == AF_INET6) {
- unmasked_bits = 128 - bits;
+ ; /* do nothing */
}
#endif
else {
return 0;
}
}
+ else
+ bits = 128;
+ k = bits / 32;
for (i=0; i < 4; i++) {
- if (unmasked_bits <= 32 * (3 - i)) {
+ if (i < k) {
mask[i] = 0xffffffff;
}
- else if (unmasked_bits >= 32 * (4 - i)) {
+ else if (i > k) {
mask[i] = 0;
}
else {
- mask[i] = ~((1 << (unmasked_bits - (32 * (4 - i)))) - 1);
+ mask[i] = 0xfffffffe << (31 - bits % 32);
}
}
return 1;
--- a/ncat/test/test-addrset.sh
+++ b/ncat/test/test-addrset.sh
@@ -208,6 +208,25 @@
1:3::3
EOF
+# IPv6 CIDR netmask.
+test_addrset "1:2::3:4:5/95" "1:2::3:4:5 1:2::2:0:0 1:2::3:ffff:ffff" <<EOF
+1:2::3:4:5
+1:2::1:ffff:ffff
+1:2::2:0:0
+1:2::3:ffff:ffff
+1:2::4:0:0
+1:3::3
+EOF
+
+# IPv6 CIDR netmask.
+test_addrset "11::2/15" "11::2:3:4:5 10::1 11:ffff:ffff:ffff:ffff:ffff:ffff:ffff" <<EOF
+11::2:3:4:5
+9:ffff:ffff:ffff:ffff:ffff:ffff:ffff
+10::1
+11:ffff:ffff:ffff:ffff:ffff:ffff:ffff
+12::0
+EOF
+
# /128 netmask.
test_addrset "1:2::0003/128" "1:2::3" <<EOF
1:2::3 |
Sure, but it will have to wait till Monday. |
Tested the new patch against the same architectures as the PR: x86_64, i586, ppc, ppc64, ppc64le, aarch64 and s390x. Did not see any problems, so the patch looks good from what I can tell. |
I have committed the patch as r37726. Thank you for reporting the issue and pin-pointing the root cause. |
Hi,
I am seeing a bug with the unit tests in the new 7.80 release. The test-addrset.sh fails for some specific tests on certain architectures: ppc64, ppc64le, s390x.
I was able to narrow it down to
nbase_addrset.c:sockaddr_to_mask()
line 503Adding the following debug code:
and running the first failing test manual:
I get for passing architectures:
for failing ones:
The text was updated successfully, but these errors were encountered: