diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2023-08-03 17:19:44 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2023-08-04 01:27:42 +0200 |
commit | 576df71e8b6785d3e5d7439e6112d72c474424cc (patch) | |
tree | 3fa85e6c8e04fad986f8adcfd0adeb807f14c20f /pasta.c | |
parent | cfe7509e5c1650256f3eebe68aaf3b19611ac9b8 (diff) | |
download | passt-576df71e8b6785d3e5d7439e6112d72c474424cc.tar passt-576df71e8b6785d3e5d7439e6112d72c474424cc.tar.gz passt-576df71e8b6785d3e5d7439e6112d72c474424cc.tar.bz2 passt-576df71e8b6785d3e5d7439e6112d72c474424cc.tar.lz passt-576df71e8b6785d3e5d7439e6112d72c474424cc.tar.xz passt-576df71e8b6785d3e5d7439e6112d72c474424cc.tar.zst passt-576df71e8b6785d3e5d7439e6112d72c474424cc.zip |
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 <david@gibson.dropbear.id.au>
[sbrivio: Minor formatting changes in pasta_ns_conf()]
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'pasta.c')
-rw-r--r-- | pasta.c | 46 |
1 files changed, 27 insertions, 19 deletions
@@ -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); + } } } |