From 8276467dbb8f003ccda7ebceb89561b4fa0ac06c Mon Sep 17 00:00:00 2001 From: anti Date: Sat, 4 Apr 2026 05:02:50 -0300 Subject: [PATCH] Fix ips_to_range using XOR instead of subtraction for prefix length MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subtraction underestimates the required prefix when IPs span a CIDR boundary (e.g. .110–.119 gave /28 covering only .96–.111, leaving deckies at .112+ unreachable from the host macvlan route). XOR correctly finds the highest differing bit, yielding /27 (.96–.127). Co-Authored-By: Claude Sonnet 4.6 --- decnet/network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decnet/network.py b/decnet/network.py index 486129c..cbdaac2 100644 --- a/decnet/network.py +++ b/decnet/network.py @@ -208,7 +208,7 @@ def ips_to_range(ips: list[str]) -> str: """ addrs = [IPv4Address(ip) for ip in ips] network = IPv4Network( - (int(min(addrs)), 32 - (int(max(addrs)) - int(min(addrs))).bit_length()), + (int(min(addrs)), 32 - (int(max(addrs)) ^ int(min(addrs))).bit_length()), strict=False, ) return str(network)