From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 3A9095A026D for ; Tue, 27 Jun 2023 12:22:53 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Qr14T1sBMz4wqV; Tue, 27 Jun 2023 20:22:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1687861369; bh=rjw7xBeD7mQZUnj/sMdRjT03503V8Locmgw/lrrfAKU=; h=From:To:Cc:Subject:Date:From; b=Jm7f2ce3kpiN2FvQQ/kpBD9hayhrVgcVWJ/dyKN40Zvl7Yp1QkTsSL8ly5BZ4oyeW k5/jaHabvTiy9Jl3dMqI2akisr0osrNrpZe8PzO1od0MuHgLzhRoaJCLx0NQikqpFR s5v9znuy19j7L9+GpEu+bj32D98R9Z9016vDJ6kE= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH] netlink: Use correct interface index in NL_SET mode Date: Tue, 27 Jun 2023 20:22:33 +1000 Message-ID: <20230627102233.3114542-1-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 5U7EMZQ3UVSCWGKKTI73UEN2T2SLLBMA X-Message-ID-Hash: 5U7EMZQ3UVSCWGKKTI73UEN2T2SLLBMA X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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; -- 2.41.0