aboutgitcodebugslistschat
path: root/pasta.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-11-04 14:10:33 +1100
committerStefano Brivio <sbrivio@redhat.com>2022-11-04 12:04:19 +0100
commitdd09cceaee216afc90101ee5c3a2d57b1ca1a042 (patch)
tree357910fd41e5ab0a1a0038debd0b5c24739d14aa /pasta.c
parent2b793d94ca353ac3071b5d9a75e73b64cc0c76ca (diff)
downloadpasst-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 'pasta.c')
-rw-r--r--pasta.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/pasta.c b/pasta.c
index ae695e2..db86317 100644
--- a/pasta.c
+++ b/pasta.c
@@ -249,19 +249,16 @@ void pasta_ns_conf(struct ctx *c)
nl_link(1, 1 /* lo */, MAC_ZERO, 1, 0);
if (c->pasta_conf_ns) {
- int prefix_len;
-
nl_link(1, c->pasta_ifi, c->mac_guest, 1, c->mtu);
if (c->ifi4) {
- prefix_len = __builtin_popcount(c->ip4.mask);
nl_addr(1, c->pasta_ifi, AF_INET, &c->ip4.addr,
- &prefix_len, NULL);
+ &c->ip4.prefix_len, NULL);
nl_route(1, c->pasta_ifi, AF_INET, &c->ip4.gw);
}
if (c->ifi6) {
- prefix_len = 64;
+ int prefix_len = 64;
nl_addr(1, c->pasta_ifi, AF_INET6, &c->ip6.addr,
&prefix_len, NULL);
nl_route(1, c->pasta_ifi, AF_INET6, &c->ip6.gw);