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 --- conf.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'conf.c') diff --git a/conf.c b/conf.c index e538b08..7286f92 100644 --- a/conf.c +++ b/conf.c @@ -641,7 +641,7 @@ static unsigned int conf_ip4(unsigned int ifi, struct ip4_ctx *ip4, unsigned char *mac) { if (!ifi) - ifi = nl_get_ext_if(AF_INET); + ifi = nl_get_ext_if(nl_sock, AF_INET); if (!ifi) { warn("No external routable interface for IPv4"); @@ -649,10 +649,11 @@ static unsigned int conf_ip4(unsigned int ifi, } if (IN4_IS_ADDR_UNSPECIFIED(&ip4->gw)) - nl_route_get_def(ifi, AF_INET, &ip4->gw); + nl_route_get_def(nl_sock, ifi, AF_INET, &ip4->gw); if (IN4_IS_ADDR_UNSPECIFIED(&ip4->addr)) - nl_addr_get(ifi, AF_INET, &ip4->addr, &ip4->prefix_len, NULL); + nl_addr_get(nl_sock, ifi, AF_INET, + &ip4->addr, &ip4->prefix_len, NULL); if (!ip4->prefix_len) { in_addr_t addr = ntohl(ip4->addr.s_addr); @@ -669,7 +670,7 @@ static unsigned int conf_ip4(unsigned int ifi, memcpy(&ip4->addr_seen, &ip4->addr, sizeof(ip4->addr_seen)); if (MAC_IS_ZERO(mac)) - nl_link_get_mac(0, ifi, mac); + nl_link_get_mac(nl_sock, ifi, mac); if (IN4_IS_ADDR_UNSPECIFIED(&ip4->addr) || MAC_IS_ZERO(mac)) @@ -692,7 +693,7 @@ static unsigned int conf_ip6(unsigned int ifi, int prefix_len = 0; if (!ifi) - ifi = nl_get_ext_if(AF_INET6); + ifi = nl_get_ext_if(nl_sock, AF_INET6); if (!ifi) { warn("No external routable interface for IPv6"); @@ -700,9 +701,9 @@ static unsigned int conf_ip6(unsigned int ifi, } if (IN6_IS_ADDR_UNSPECIFIED(&ip6->gw)) - nl_route_get_def(ifi, AF_INET6, &ip6->gw); + nl_route_get_def(nl_sock, ifi, AF_INET6, &ip6->gw); - nl_addr_get(ifi, AF_INET6, + nl_addr_get(nl_sock, ifi, AF_INET6, IN6_IS_ADDR_UNSPECIFIED(&ip6->addr) ? &ip6->addr : NULL, &prefix_len, &ip6->addr_ll); -- cgit v1.2.3