Repository navigation
addr_matches_if_netmask: mask the address for a dotted IPv6 netmask - #599
Merged
Merged
Conversation
The IPv4 path and the IPv6 prefix-length path AND the netmask into the address before comparing it to the local interfaces, but when an IPv6 netmask is given in address form (host 2001:db8::1/ffff:ffff:ffff:ffff::) the mask is taken from inet_pton() and the address is never masked. The match loop then compares each interface address ANDed with the mask against the unmasked target, so an entry whose address has host bits set does not match, unlike the equivalent /64 prefix form. Mask the address once the netmask is known, as the IPv4 path already does.
millert
approved these changes
Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
addr_matches_if_netmask()masks the target address with the netmask for IPv4 and for an IPv6 prefix length, but when the IPv6 netmask is written as an address (host 2001:db8::1/ffff:ffff:ffff:ffff::) the mask comes frominet_pton()and the address is never masked. The match loop then compares each interface address ANDed with the mask against the unmasked target, so a network/netmask entry whose address has host bits set does not match the local host, while the equivalent/64prefix form does.Mask the address once the netmask is known, the same way the IPv4 path does. A plain
host = ...rule written this way fails closed, but a negated entry used as an exclusion (ALL, !2001:db8:mgmt::1/ffff:ffff:ffff:ffff::) fails open: the missed match drops the exclusion so the host is no longer denied. I checked it by callingaddr_matches()against a fixed interface list containing2001:db8:1:2::5:2001:db8:1:2::abcd/64and the equivalent2001:db8:1:2::abcd/ffff:ffff:ffff:ffff::now both match, the IPv4 prefix and dotted forms are unchanged, and an out-of-network address still does not match.