From 576df71e8b6785d3e5d7439e6112d72c474424cc Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 3 Aug 2023 17:19:44 +1000 Subject: netlink: Explicitly pass netlink sockets to operations All the netlink operations currently implicitly use one of the two global netlink sockets, sometimes depending on an 'ns' parameter. Change them all to explicitly take the socket to use (or two sockets to use in the case of the *_dup() functions). As well as making these functions strictly more general, it makes the callers easier to follow because we're passing a socket variable with a name rather than an unexplained '0' or '1' for the ns parameter. Signed-off-by: David Gibson [sbrivio: Minor formatting changes in pasta_ns_conf()] Signed-off-by: Stefano Brivio --- pasta.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'pasta.c') diff --git a/pasta.c b/pasta.c index 52cfad7..36c63de 100644 --- a/pasta.c +++ b/pasta.c @@ -272,45 +272,53 @@ void pasta_start_ns(struct ctx *c, uid_t uid, gid_t gid, */ void pasta_ns_conf(struct ctx *c) { - nl_link_up(1, 1 /* lo */, 0); + nl_link_up(nl_sock_ns, 1 /* lo */, 0); /* Get or set MAC in target namespace */ if (MAC_IS_ZERO(c->mac_guest)) - nl_link_get_mac(1, c->pasta_ifi, c->mac_guest); + nl_link_get_mac(nl_sock_ns, c->pasta_ifi, c->mac_guest); else - nl_link_set_mac(1, c->pasta_ifi, c->mac_guest); + nl_link_set_mac(nl_sock_ns, c->pasta_ifi, c->mac_guest); if (c->pasta_conf_ns) { - nl_link_up(1, c->pasta_ifi, c->mtu); + nl_link_up(nl_sock_ns, c->pasta_ifi, c->mtu); if (c->ifi4) { if (c->no_copy_addrs) { - nl_addr_set(c->pasta_ifi, AF_INET, + nl_addr_set(nl_sock_ns, c->pasta_ifi, AF_INET, &c->ip4.addr, c->ip4.prefix_len); } else { - nl_addr_dup(c->ifi4, c->pasta_ifi, AF_INET); + nl_addr_dup(nl_sock, c->ifi4, + nl_sock_ns, c->pasta_ifi, AF_INET); } - if (c->no_copy_routes) - nl_route_set_def(c->pasta_ifi, AF_INET, - &c->ip4.gw); - else - nl_route_dup(c->ifi4, c->pasta_ifi, AF_INET); + if (c->no_copy_routes) { + nl_route_set_def(nl_sock_ns, c->pasta_ifi, + AF_INET, &c->ip4.gw); + } else { + nl_route_dup(nl_sock, c->ifi4, nl_sock_ns, + c->pasta_ifi, AF_INET); + } } if (c->ifi6) { if (c->no_copy_addrs) { - nl_addr_set(c->pasta_ifi, AF_INET6, - &c->ip6.addr, 64); + nl_addr_set(nl_sock_ns, c->pasta_ifi, + AF_INET6, &c->ip6.addr, 64); } else { - nl_addr_dup(c->ifi6, c->pasta_ifi, AF_INET6); + nl_addr_dup(nl_sock, c->ifi6, + nl_sock_ns, c->pasta_ifi, + AF_INET6); } - if (c->no_copy_routes) - nl_route_set_def(c->pasta_ifi, AF_INET6, - &c->ip6.gw); - else - nl_route_dup(c->ifi6, c->pasta_ifi, AF_INET6); + if (c->no_copy_routes) { + nl_route_set_def(nl_sock_ns, c->pasta_ifi, + AF_INET6, &c->ip6.gw); + } else { + nl_route_dup(nl_sock, c->ifi6, + nl_sock_ns, c->pasta_ifi, + AF_INET6); + } } } -- cgit v1.2.3