From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 0694F5A0322 for ; Wed, 14 Aug 2024 06:31:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1723609853; bh=GKEnPc+8kFbh0j1/hdXnBqD2Vyc5oj6igpnujS1UvPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RmSHFgdEugOw9u4Pp8XjBYd0CjCe0E48niFeUyQ0IaC3MBmJrHNqFYa0ALBIrjxgx 4nQsWCqSpzakvx0z+oqJc0ZQqEaZ+ezy8hjkatW2F0c1aMigzrW/o5F2X5UhxU4hDA 365zts4FyJp9Nqc3DUFgYSBybAxGNpB5sqHwXkMXxw7xHfLhHoCZIFURziMDYQitp6 9k7Dx+iNgvU0+62mHW9w+vYrH6y/MeT0tiE9a3axyRuxR8PPNsPr1gG47tuGvgJaTN uqHgMS8sydQ+Pszu+k9wxZg8macVuoRh1quWCHvzuss1foJo1sIjbuR8jjgX8XKPTr 0cNY0Ra39E41A== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WkFgK2PjXz4xDN; Wed, 14 Aug 2024 14:30:53 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 13/16] util: Correct sock_l4() binding for link local addresses Date: Wed, 14 Aug 2024 14:30:47 +1000 Message-ID: <20240814043050.4177037-14-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240814043050.4177037-1-david@gibson.dropbear.id.au> References: <20240814043050.4177037-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: RL3NP3E47Y4QZY33CC4XGNLIO7KGZ5G6 X-Message-ID-Hash: RL3NP3E47Y4QZY33CC4XGNLIO7KGZ5G6 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: When binding an IPv6 socket in sock_l4() we need to supply a scope id if the address is link-local. We check for this by comparing the given address to c->ip6.addr_ll. This is correct only by accident: while c->ip6.addr_ll is typically set to the hsot interface's link local address, the actually purpose of it is to provide a link local address for passt's private use on the tap interface. Instead set the scope id for any link-local address we're binding to. We're going to need something and this is what makes sense for sockets on the host. It doesn't make sense for PIF_SPLICE sockets, but those should always have loopback, not link-local addresses. Signed-off-by: David Gibson --- util.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util.c b/util.c index 892358b1..9682e3ce 100644 --- a/util.c +++ b/util.c @@ -199,8 +199,7 @@ int sock_l4(const struct ctx *c, sa_family_t af, enum epoll_type type, if (bind_addr) { addr6.sin6_addr = *(struct in6_addr *)bind_addr; - if (!memcmp(bind_addr, &c->ip6.addr_ll, - sizeof(c->ip6.addr_ll))) + if (IN6_IS_ADDR_LINKLOCAL(bind_addr)) addr6.sin6_scope_id = c->ifi6; } return sock_l4_sa(c, type, &addr6, sizeof(addr6), ifname, -- 2.46.0