Problem statement
Standardizing on a /24 check is insufficient for advanced configurations.
Admins may need to define smaller, non-overlapping subnets within the same
class (e.g., 192.168.32.1/255.255.255.240 and
192.168.32.128/255.255.255.240). The broker must validate these correctly
to prevent false positives while still catching genuine overlaps.
Suggested mitigation
The broker should implement a comparison function that accepts in_addr for
both the IP and the netmask. By comparing the host-order bitmask of two
interfaces, the broker can identify which network is "wider" and use that
mask to determine if the smaller network resides within the larger one's
address space.
Example implementation
#include <stdint.h>
#include <arpa/inet.h>
#include <netinet/in.h>
/**
* Validates if two networks overlap using IP and Netmask.
* Addresses and masks should be provided in host byte order.
*/
int check_overlap(uint32_t addr1, uint32_t mask1,
uint32_t addr2, uint32_t mask2) {
// Determine the 'wider' network by choosing the smaller mask value.
// e.g., 255.255.255.0 (0xFFFFFF00) is wider than
// 255.255.255.240 (0xFFFFFFF0).
uint32_t effective_mask = (mask1 < mask2) ? mask1 : mask2;
return (addr1 & effective_mask) == (addr2 & effective_mask);
}
// Integration snippet:
// struct in_addr req_ip, req_mask;
// ... parse from config ...
// uint32_t h_ip = ntohl(req_ip.s_addr);
// uint32_t h_mask = ntohl(req_mask.s_addr);
//
// if (check_overlap(h_ip, h_mask, if_ip, if_mask)) {
// /* Collision detected */
// }
Problem statement
Standardizing on a
/24check is insufficient for advanced configurations.Admins may need to define smaller, non-overlapping subnets within the same
class (e.g.,
192.168.32.1/255.255.255.240and192.168.32.128/255.255.255.240). The broker must validate these correctlyto prevent false positives while still catching genuine overlaps.
Suggested mitigation
The broker should implement a comparison function that accepts
in_addrforboth the IP and the netmask. By comparing the host-order bitmask of two
interfaces, the broker can identify which network is "wider" and use that
mask to determine if the smaller network resides within the larger one's
address space.
Example implementation