On Thu, 14 May 2026 16:30:16 +1000
David Gibson
On Sun, Apr 12, 2026 at 08:53:08PM -0400, Jon Maloy wrote:
[...]
+/** inany_prefix_len() - Convert prefix length to native format + * @addr: IPv4 or IPv6 address + * @prefix_len: prefix length (any format, auto-detected)
If it's pertaining to an inany, it should always be IPv6 format. Auto-detecting just masks bugs elsewhere.
+ * + * Return: prefix length in native format (0-32 for IPv4, 0-128 for IPv6) + */ +static inline int inany_prefix_len(const union inany_addr *addr, + int prefix_len) +{ + if (inany_v4(addr) && prefix_len >= 96)
Yikes. Even ignoring the fact I don't like this function at all
Can you then please suggest / sketch another solution? We went back and forth on this topic quite a bit but we couldn't come up with anything more elegant so far.
this isn't good. If we somehow get a IPv4-mapped inany with a prefix_len that's < 96, something has already gone wrong. This, however, will just fall back to the IPv6 case. So if prefix_len is 33..96 it will return something entirely nonsensical, and if it's 0..32 it will return something that looks ok, but ignores the fact that something is already wrong.
+ return prefix_len - 96; + + return prefix_len; +} + +/** inany_prefix_len6() - Convert prefix length to generic format + * @addr: IPv4 or IPv6 address + * @prefix_len: prefix length (any format, auto-detected) + * + * Return: prefix length in generic format (96-128 for IPv4, 0-128 for IPv6) + */ +static inline int inany_prefix_len6(const union inany_addr *addr, + int prefix_len)
This function should not be necessary. If the prefix_len is attached to an inany, it should already be in IPv6 format.
+{ + if (inany_v4(addr) && prefix_len && prefix_len <= 32) + return prefix_len + 96;
Similar comments here. Also a 0.0.0.0/0 is a valid prefix which should be translated to ::ffff:0:0/96, not to ::ffff:0:0/0 as this function will.
[...]
-- Stefano