|
Right so we have for instance code which looks like this and we have many network ranges defined like this. and later in If we change the first block to then CFengine complains about Which makes sense as we are using a non multiple of 8 block. However, we strongly feel this is a bug? Most modern languages have moved away from mask tables only being built in 8-bit chunks. How do we get around this? EDIT: Seems the error originates from this Line 237 in ff09a71 Could a solution be to change this Lines 246 to 254 in ff09a71 if (mask % 8 != 0)
{
Log(LOG_LEVEL_ERR, "Cannot handle ipv6 masks which are not 8 bit multiples (fix me)");
return -1;
}
addr1.sin6_family = AF_INET6;
inet_pton(AF_INET6, address, &addr1.sin6_addr);
addr2.sin6_family = AF_INET6;
inet_pton(AF_INET6, s2, &addr2.sin6_addr);
for (i = 0; i < blocks; i++) /* blocks < 16 */
{
if (addr1.sin6_addr.s6_addr[i] != addr2.sin6_addr.s6_addr[i])
{
return -1;
}
}
return 0;
}to this instead? /* 1. Calculate the split: full bytes vs leftover bits */
int blocks = mask / 8;
int remaining_bits = mask % 8;
/* 2. Parse the addresses (Existing code) */
addr1.sin6_family = AF_INET6;
inet_pton(AF_INET6, address, &addr1.sin6_addr);
addr2.sin6_family = AF_INET6;
inet_pton(AF_INET6, s2, &addr2.sin6_addr);
if (mask > 128)
{
return -1;
}
/* 3. Compare the full 8-bit blocks*/
for (i = 0; i < blocks; i++)
{
if (addr1.sin6_addr.s6_addr[i] != addr2.sin6_addr.s6_addr[i])
{
return -1;
}
}
/* 4. Compare the remaining bits*/
if (remaining_bits > 0)
{
/* Calculate mask for the partial byte (e.g., /41 -> 1 extra bit) */
/* 1 bit remaining -> shift 0xFF left by 7 -> 10000000 */
uint8_t bitmask = (uint8_t)(0xFF << (8 - remaining_bits));
if ((addr1.sin6_addr.s6_addr[blocks] & bitmask) !=
(addr2.sin6_addr.s6_addr[blocks] & bitmask))
{
return -1;
}
}
return 0;
} |
Replies: 2 comments 5 replies
|
The limitation exists in |
|
Hi @Oisov, this issue was fixed by @victormlg in #6207 |
Hi @Oisov, this issue was fixed by @victormlg in #6207