aboutgitcodebugslistschat
path: root/pasta.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-08-03 17:19:41 +1000
committerStefano Brivio <sbrivio@redhat.com>2023-08-04 01:24:52 +0200
commiteff3bcb24547e671e63df9b70157c3ff9bb9f95a (patch)
treea5525772899f39b4fe48644b567a5bca937231fa /pasta.c
parente96182e9c28197a8f868df5d2a9975bc51a090e9 (diff)
downloadpasst-eff3bcb24547e671e63df9b70157c3ff9bb9f95a.tar
passt-eff3bcb24547e671e63df9b70157c3ff9bb9f95a.tar.gz
passt-eff3bcb24547e671e63df9b70157c3ff9bb9f95a.tar.bz2
passt-eff3bcb24547e671e63df9b70157c3ff9bb9f95a.tar.lz
passt-eff3bcb24547e671e63df9b70157c3ff9bb9f95a.tar.xz
passt-eff3bcb24547e671e63df9b70157c3ff9bb9f95a.tar.zst
passt-eff3bcb24547e671e63df9b70157c3ff9bb9f95a.zip
netlink: Split nl_addr() into separate operation functions
nl_addr() can perform three quite different operations based on the 'op' parameter, each of which uses a different subset of the parameters. Split them up into a function for each operation. This does use more lines of code, but the overlap wasn't that great, and the separated logic is much easier to follow. It's also clearer in the callers what we expect the netlink operations to do, and what information it uses. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> [sbrivio: Minor formatting fixes in pasta_ns_conf()] Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'pasta.c')
-rw-r--r--pasta.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/pasta.c b/pasta.c
index cb509dd..b55a1a2 100644
--- a/pasta.c
+++ b/pasta.c
@@ -282,21 +282,29 @@ void pasta_ns_conf(struct ctx *c)
if (c->pasta_conf_ns) {
enum nl_op op_routes = c->no_copy_routes ? NL_SET : NL_DUP;
- enum nl_op op_addrs = c->no_copy_addrs ? NL_SET : NL_DUP;
nl_link_up(1, c->pasta_ifi, c->mtu);
if (c->ifi4) {
- nl_addr(op_addrs, c->ifi4, c->pasta_ifi, AF_INET,
- &c->ip4.addr, &c->ip4.prefix_len, NULL);
+ if (c->no_copy_addrs) {
+ nl_addr_set(c->pasta_ifi, AF_INET,
+ &c->ip4.addr, c->ip4.prefix_len);
+ } else {
+ nl_addr_dup(c->ifi4, c->pasta_ifi, AF_INET);
+ }
+
nl_route(op_routes, c->ifi4, c->pasta_ifi, AF_INET,
&c->ip4.gw);
}
if (c->ifi6) {
- int prefix_len = 64;
- nl_addr(op_addrs, c->ifi6, c->pasta_ifi, AF_INET6,
- &c->ip6.addr, &prefix_len, NULL);
+ if (c->no_copy_addrs) {
+ nl_addr_set(c->pasta_ifi, AF_INET6,
+ &c->ip6.addr, 64);
+ } else {
+ nl_addr_dup(c->ifi6, c->pasta_ifi, AF_INET6);
+ }
+
nl_route(op_routes, c->ifi6, c->pasta_ifi, AF_INET6,
&c->ip6.gw);
}