diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2022-11-04 14:10:33 +1100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2022-11-04 12:04:19 +0100 |
commit | dd09cceaee216afc90101ee5c3a2d57b1ca1a042 (patch) | |
tree | 357910fd41e5ab0a1a0038debd0b5c24739d14aa /passt.h | |
parent | 2b793d94ca353ac3071b5d9a75e73b64cc0c76ca (diff) | |
download | passt-dd09cceaee216afc90101ee5c3a2d57b1ca1a042.tar passt-dd09cceaee216afc90101ee5c3a2d57b1ca1a042.tar.gz passt-dd09cceaee216afc90101ee5c3a2d57b1ca1a042.tar.bz2 passt-dd09cceaee216afc90101ee5c3a2d57b1ca1a042.tar.lz passt-dd09cceaee216afc90101ee5c3a2d57b1ca1a042.tar.xz passt-dd09cceaee216afc90101ee5c3a2d57b1ca1a042.tar.zst passt-dd09cceaee216afc90101ee5c3a2d57b1ca1a042.zip |
Minor improvements to IPv4 netmask handling
There are several minor problems with our parsing of IPv4 netmasks (-n).
First, we don't reject nonsensical netmasks like 0.255.0.255. Address this
structurally by using prefix length instead of netmask as the primary
variable, only converting (and validating) when we need to. This has the
added benefit of making some things more uniform with the IPv6 path.
Second, when the user specifies a prefix length, we truncate the output
from strtol() to an integer, which means we would treat -n 4294967320 as
valid (equivalent to 24). Fix types to check for this.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'passt.h')
-rw-r--r-- | passt.h | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -99,7 +99,7 @@ enum passt_modes { * struct ip4_ctx - IPv4 execution context * @addr: IPv4 address for external, routable interface * @addr_seen: Latest IPv4 address seen as source from tap - * @mask: IPv4 netmask, network order + * @prefixlen: IPv4 prefix length (netmask) * @gw: Default IPv4 gateway, network order * @dns: IPv4 DNS addresses, zero-terminated, network order * @dns_fwd: Address forwarded (UDP) to first IPv4 DNS, network order @@ -107,7 +107,7 @@ enum passt_modes { struct ip4_ctx { uint32_t addr; uint32_t addr_seen; - uint32_t mask; + int prefix_len; uint32_t gw; uint32_t dns[MAXNS + 1]; uint32_t dns_fwd; |