From eff3bcb24547e671e63df9b70157c3ff9bb9f95a Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 3 Aug 2023 17:19:41 +1000 Subject: 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 [sbrivio: Minor formatting fixes in pasta_ns_conf()] Signed-off-by: Stefano Brivio --- pasta.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'pasta.c') 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); } -- cgit v1.2.3