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=CU/4nt6G; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id C1DF75A027B for ; Fri, 16 Aug 2024 07:40:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1723786807; bh=GKEnPc+8kFbh0j1/hdXnBqD2Vyc5oj6igpnujS1UvPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CU/4nt6GdS0CT4sDGmpOzWNpg8PKOtv+xNJWMBjCuxiXUlQ+/b1N2I2GvJe6BwY1X 9env4lrE4/PXRbCEHLtt/3Yxa2pjdeKrkPcEk1lRJSUXbTJkAPcBUhqnvirbqHxl4H g2CK4q4nG6xj/pmA1tritAVhZybh0jjtrnebeK15vXwjFqqhxMZO1duk34Nt9yQn5r ZRxChoFvgvYSffC3SRN+RmWrU+viuJfl7DAPqP4LQrH79AX1+RZFuD37zyYFrRP35Q TiytpNb9MmWoMWsF8/mQB9GCt51Z7PNLlHJ+Fa/a/a38YQ4OpetXk8iyfi7FUuXY/K g+Nio7azsweyw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WlW6H0kCdz4x5G; Fri, 16 Aug 2024 15:40:07 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 12/22] util: Correct sock_l4() binding for link local addresses Date: Fri, 16 Aug 2024 15:39:53 +1000 Message-ID: <20240816054004.1335006-13-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240816054004.1335006-1-david@gibson.dropbear.id.au> References: <20240816054004.1335006-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 3QNMTM6N3XWLHLYF4VV7CYH6HUYT27WR X-Message-ID-Hash: 3QNMTM6N3XWLHLYF4VV7CYH6HUYT27WR 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 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