public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] netlink: Use correct interface index in NL_SET mode
@ 2023-06-27 10:22 David Gibson
  2023-06-27 17:18 ` Stefano Brivio
  0 siblings, 1 reply; 2+ messages in thread
From: David Gibson @ 2023-06-27 10:22 UTC (permalink / raw)
  To: passt-dev, Stefano Brivio; +Cc: David Gibson

nl_addr() and nl_route() take an 'op' selector which affects a number of
parameters to the netlink call.  Unfortunately when we introduced this
option a bug was introduced so that we always use the interface index for
the host side, rather than the one for the pasta namespace.

Really, the entire interface to nl_addr() and nl_route() is pretty bad:
it's tightly coupled with the use cases of its callers.  This is a minimal
fix which doesn't address that, but also doesn't make it significantly
worse.

Bugzilla: https://bugs.passt.top/show_bug.cgi?id=59
Fixes: 2fe046185634 ("netlink: Add functionality to copy routes from outer namespace")
Fixes: e89da3cf03b2 ("netlink: Add functionality to copy addresses from outer namespace")

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 netlink.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/netlink.c b/netlink.c
index bc5b2bf9..e15e23f9 100644
--- a/netlink.c
+++ b/netlink.c
@@ -226,7 +226,7 @@ void nl_route(enum nl_op op, unsigned int ifi, unsigned int ifi_ns,
 
 		.rta.rta_type	  = RTA_OIF,
 		.rta.rta_len	  = RTA_LENGTH(sizeof(unsigned int)),
-		.ifi		  = ifi,
+		.ifi		  = op == NL_SET ? ifi_ns : ifi,
 	};
 	unsigned dup_routes = 0;
 	ssize_t n, nlmsgs_size;
@@ -370,7 +370,7 @@ void nl_addr(enum nl_op op, unsigned int ifi, unsigned int ifi_ns,
 		.nlh.nlmsg_seq     = nl_seq++,
 
 		.ifa.ifa_family    = af,
-		.ifa.ifa_index     = ifi,
+		.ifa.ifa_index     = op == NL_SET ? ifi_ns : ifi,
 		.ifa.ifa_prefixlen = op == NL_SET ? *prefix_len : 0,
 	};
 	ssize_t n, nlmsgs_size;
-- 
@@ -226,7 +226,7 @@ void nl_route(enum nl_op op, unsigned int ifi, unsigned int ifi_ns,
 
 		.rta.rta_type	  = RTA_OIF,
 		.rta.rta_len	  = RTA_LENGTH(sizeof(unsigned int)),
-		.ifi		  = ifi,
+		.ifi		  = op == NL_SET ? ifi_ns : ifi,
 	};
 	unsigned dup_routes = 0;
 	ssize_t n, nlmsgs_size;
@@ -370,7 +370,7 @@ void nl_addr(enum nl_op op, unsigned int ifi, unsigned int ifi_ns,
 		.nlh.nlmsg_seq     = nl_seq++,
 
 		.ifa.ifa_family    = af,
-		.ifa.ifa_index     = ifi,
+		.ifa.ifa_index     = op == NL_SET ? ifi_ns : ifi,
 		.ifa.ifa_prefixlen = op == NL_SET ? *prefix_len : 0,
 	};
 	ssize_t n, nlmsgs_size;
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-27 17:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-27 10:22 [PATCH] netlink: Use correct interface index in NL_SET mode David Gibson
2023-06-27 17:18 ` Stefano Brivio

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).