From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=fail reason="key not found in DNS" header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202312 header.b=DE7A3us/; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 2F6BD5A0275 for ; Wed, 21 Aug 2024 06:20:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1724214023; bh=Hh9JVUb9V7DeCyo7hE2qNYE0eOJVdzz2xf4DdliWhlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DE7A3us/reulTyQs2arTxctvEhLu9a4MrI5lAEgKyQo0NagYxo/chMEv/o17705uv 0AzrZndcR932DyovnRvRmvLdNAhzRpbWD8ITu0K+poJ8MraKnn8QKn4KC/gcISlTEM ERVVbhwOLo8iLre/Gzm/OtPyyKaZ0+t1rhuzBOgWj9WcKU1sQbJYmFmd44APWdKsBK Vk+XpffRISQmTmvvZtNaHZrs3Z+TDXB3/jp7kwokMwrURHMokjMijIaI5B2H+abyjh OBrgCZmolQH4l1UpNjcPCGAClQ9NjZLUKwc72n7gZpz5pCk98PtVdgUqtO+VwGaEVs OOPtoBxFwBh1Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WpY5z2Nf0z4x8P; Wed, 21 Aug 2024 14:20:23 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 12/23] util: Correct sock_l4() binding for link local addresses Date: Wed, 21 Aug 2024 14:20:08 +1000 Message-ID: <20240821042020.718422-13-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240821042020.718422-1-david@gibson.dropbear.id.au> References: <20240821042020.718422-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: MQETSBJBG4NLVLHYUTT3IVCB4J23EGEM X-Message-ID-Hash: MQETSBJBG4NLVLHYUTT3IVCB4J23EGEM 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: Paul Holzinger , 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 host interface's link local address, the actual 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 7cb2c10f..f9f8113c 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