mirror of
https://passt.top/passt
synced 2025-06-15 11:55:34 +02:00
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>
This commit is contained in:
parent
cfe7509e5c
commit
576df71e8b
4 changed files with 105 additions and 76 deletions
46
pasta.c
46
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue