From patchwork Thu Dec 8 14:54:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Gobert X-Patchwork-Id: 31386 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp249978wrr; Thu, 8 Dec 2022 07:10:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf7p5JvB6Qkzal+qv41G9hz3uf9t9AvzFxnN4OTUU++YYftnsPa1yb0LohwqG2jJN8QtObiC X-Received: by 2002:aa7:db90:0:b0:459:aa70:d4fd with SMTP id u16-20020aa7db90000000b00459aa70d4fdmr81249246edt.162.1670512235571; Thu, 08 Dec 2022 07:10:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670512235; cv=none; d=google.com; s=arc-20160816; b=xNDZeOueq8wKyPcqlqfPbTtlup0DVSV+YW11dw5qCaE6nXr6Sl6Flq/w/UEi7u/+Yu CjSL0mOEaQ07QqQg6nj9Xubz+swewKZjbUMtxVznDKCBP1nK4/PP+bDmXkWAsv5ImybG KG/jGctNLuh95mdztUH+L7GNoVSaAd+hsH9oVYMjevL1vwC7CyHpg8PuwKL3nzm/eXGR 4w4Z03735Ta/vBkSsA22BPWmy7GsO2iJIt3376TxF34uw2Nx3mqWut+HUB2uCZpNQ9wJ vIuYLd/X5d5YygSckhgHXX+uXiMBCWZFlhYt1UZDDjL9erh3SHoCPTxOogpIpeIEzyH1 lKGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-disposition:mime-version :message-id:subject:to:from:date:dkim-signature; bh=RqKvZUHndgJsmYSWYtOw+ggxUD/rVpTNob38zsmbVZU=; b=aviBHCNcAHjC4FfYHcTDFXVcZQ3eRSPNpTaMurN0YjmbknQs8HB+rAE69Tvq3yYOPU bMf3AnII/OY7ylOZNSx+p3WG8kwz+16MypSZLpLK9N+5Emb2m4bk8OFFr2fAafZaiZio oZV2ftlThmfpNt4Zean6k0hwv4KAbqUYv8fAeqgskxG3MVSNSI8GzJbiKS5v2/z6Q23Y 9ENGpndEUunBSNuMXKcBzFPidPw6ThWXpDAnxbdWMGkxoPZAGJKZOqRCYSfvKxOf0B+o hHvjWBW6/BUXy5gvr19MvnduSjCgs1AstjeQ7MXzmK/GDQwp/sQfiJb4K9ggrPp/RReU oO1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MfpArdTI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wz13-20020a170906fe4d00b007813b1924ccsi19106911ejb.934.2022.12.08.07.10.11; Thu, 08 Dec 2022 07:10:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MfpArdTI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230010AbiLHOzL (ORCPT + 99 others); Thu, 8 Dec 2022 09:55:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230014AbiLHOzF (ORCPT ); Thu, 8 Dec 2022 09:55:05 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0D549D2D1; Thu, 8 Dec 2022 06:55:04 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id ja4-20020a05600c556400b003cf6e77f89cso4405024wmb.0; Thu, 08 Dec 2022 06:55:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=user-agent:content-disposition:mime-version:message-id:subject:to :from:date:from:to:cc:subject:date:message-id:reply-to; bh=RqKvZUHndgJsmYSWYtOw+ggxUD/rVpTNob38zsmbVZU=; b=MfpArdTIjl5P7RM6yxK+K3jPBoMjzdFj25G54OM4bTeC9GGq6t2dd9oOyg9mVTplwN h0WLRH/L7RqOlTvTosGi5lhb++ui5We0HehEpipMR8Oy1Qcq2gvVrBiHVzfMNUZw/P1Z 8PMvPde4vN9/cJ9J/ph0lO88SxbmExnGQt2E8JyWgth4tCXVR3i4fHEBPtPk3JQyLuW6 03coqD/kwwGCMd3UuwtMVvu5CqDru9MUcZeokLcL+ePBF4VPX331564D1hsO4Jee8IxE 7DNM/lpumpGaUyh7glFSD7hpQhC7D2ufgvJ93klU+zuKYrENH4aP5o56btx3gEcaFI9N 0bBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:content-disposition:mime-version:message-id:subject:to :from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RqKvZUHndgJsmYSWYtOw+ggxUD/rVpTNob38zsmbVZU=; b=22LWCjzecCZpqcyWwJUWOIbiTXmLmkraBJb7a5TcevWdy5Zv/0kRJv2niiEW816ux7 DdYLu377DrNPuWDHLQCyIteTZgCfJ0XcsSLdt8FqGNcqHBL9MTklGs9KMCoPQMel6QEF BH4DTWedwTmevsBts5p2XP81szY8tMLazyAH4FZGd5RZ7JDooc10eq+Jq/lgUCOnu9uO ES7WEnnEBi38jbyLUqZj2GvFtplbogOlDXIXnXZaPbSPufUA/rG8diGff/ssHMJ0/3s3 UZvW5USTU4inesNaFcAXkB5Llz+bkHP4LOldjtzz3FUN1R4T0ahvqZ1tvthZ2bIQPCTl ChsQ== X-Gm-Message-State: ANoB5pmg4/ZQs/nwxZspB3DBBfRcsljQHLnZg4wpuXE3i0esencB9Hpu WlFzIMGb5wNkbe9OIEVXC+Q= X-Received: by 2002:a05:600c:1685:b0:3d1:f687:1fd0 with SMTP id k5-20020a05600c168500b003d1f6871fd0mr1833043wmn.12.1670511303112; Thu, 08 Dec 2022 06:55:03 -0800 (PST) Received: from debian ([89.238.191.199]) by smtp.gmail.com with ESMTPSA id z13-20020a05600c220d00b003cf71b1f66csm5118588wml.0.2022.12.08.06.54.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 06:55:02 -0800 (PST) Date: Thu, 8 Dec 2022 15:54:46 +0100 From: Richard Gobert To: davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] net: setsockopt: fix IPV6_UNICAST_IF option for connected sockets Message-ID: <20221208145437.GA75680@debian> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751659038242228168?= X-GMAIL-MSGID: =?utf-8?q?1751659038242228168?= Change the behaviour of ip6_datagram_connect to consider the interface set by the IPV6_UNICAST_IF socket option, similarly to udpv6_sendmsg. This change is the IPv6 counterpart of the fix for IP_UNICAST_IF. The tests introduced by that patch showed that the incorrect behavior is present in IPv6 as well. This patch fixes the broken test. Reported-by: kernel test robot Link: https://lore.kernel.org/r/202210062117.c7eef1a3-oliver.sang@intel.com Fixes: 0e4d354762ce ("net-next: Fix IP_UNICAST_IF option behavior for connected sockets") Signed-off-by: Richard Gobert Reviewed-by: David Ahern --- net/ipv6/datagram.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c index 7c7155b48f17..e624497fa992 100644 --- a/net/ipv6/datagram.c +++ b/net/ipv6/datagram.c @@ -42,24 +42,29 @@ static void ip6_datagram_flow_key_init(struct flowi6 *fl6, struct sock *sk) { struct inet_sock *inet = inet_sk(sk); struct ipv6_pinfo *np = inet6_sk(sk); + int oif = sk->sk_bound_dev_if; memset(fl6, 0, sizeof(*fl6)); fl6->flowi6_proto = sk->sk_protocol; fl6->daddr = sk->sk_v6_daddr; fl6->saddr = np->saddr; - fl6->flowi6_oif = sk->sk_bound_dev_if; fl6->flowi6_mark = sk->sk_mark; fl6->fl6_dport = inet->inet_dport; fl6->fl6_sport = inet->inet_sport; fl6->flowlabel = np->flow_label; fl6->flowi6_uid = sk->sk_uid; - if (!fl6->flowi6_oif) - fl6->flowi6_oif = np->sticky_pktinfo.ipi6_ifindex; + if (!oif) + oif = np->sticky_pktinfo.ipi6_ifindex; - if (!fl6->flowi6_oif && ipv6_addr_is_multicast(&fl6->daddr)) - fl6->flowi6_oif = np->mcast_oif; + if (!oif) { + if (ipv6_addr_is_multicast(&fl6->daddr)) + oif = np->mcast_oif; + else + oif = np->ucast_oif; + } + fl6->flowi6_oif = oif; security_sk_classify_flow(sk, flowi6_to_flowi_common(fl6)); }