From patchwork Thu Nov 24 11:48:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Gobert X-Patchwork-Id: 25469 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3350329wrr; Thu, 24 Nov 2022 03:58:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf44SMQLRUzyE2d98oYPEdp3YPC1XzhXWHhrCm9sHFERnDGB5gtm2Nx1wr4FGcc8rzdEoqED X-Received: by 2002:aa7:96e6:0:b0:56d:9eed:61eb with SMTP id i6-20020aa796e6000000b0056d9eed61ebmr34890600pfq.4.1669291124715; Thu, 24 Nov 2022 03:58:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669291124; cv=none; d=google.com; s=arc-20160816; b=Dl0AFyWL47KSoS++7006oxwuD+VKZv9ebyl5FlVyLdV9uVjjLbwEuMEUacBNePxRg6 zftY7U3Mi4mX+NpCwmCIFs3AFRGhH1lBOfhUXlESXHG5T1gKmLmcz9eRzLueAqcTdOki /Bn40Q2/dUxNIkYvtQ+GnhyZY2aszjPSk3iMHog7vWF0hHYfoZJIc2MF8DKxiLzLmto8 NfhyMLaBLCsvwGnjSaYvkysGeSC7+56yTvmqk/ZdoUq4recHU8xV3UOoXKBEYVUFJ3KW NXnQJP4iLeT5e/+fJ5RDt5YYrjqxf+OppTKSACt8IsV4WfweZ6vSohtBTpl2l2xl3DWl JykQ== 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=KWfj56pFXj1HTsSt2vtLzvRq7ahqzIR48ZMo4DRqEeY=; b=AjI9+37iuMFfyQTCyofpm3WXsPH6I5JPOOtxK7K5ohtE9vXPo4UuNALV2XwWhS8p5U IXR1zWggYiVV88h/y6CpGB0NsAGtW+XgvnSfJT06TD4DJMcsIx1aEZhcCf/YJvjFU6bO WWnCBNjFdzaErJgqN1Mm2BE//F31KhIgP0qcLIwB7RSapC3cDhoOupb4n+YgaNaxCejs 9RKGovppmVLgQN3xjBrm7PVHfxefE2SUY0FCsKNtzDPAnpOruSdfZqRr7jEkKjVXEE5V +bA38xC3dynY31uVc2ddXpSMEc0Ztgw96jLsCDwUgy2B1HapSEJbOVxU0dPYNqLv1RnF yQjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=I7f0FQe6; 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 k21-20020a056a00135500b00572f208f7basi587675pfu.149.2022.11.24.03.58.32; Thu, 24 Nov 2022 03:58:44 -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=I7f0FQe6; 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 S230211AbiKXLte (ORCPT + 99 others); Thu, 24 Nov 2022 06:49:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229581AbiKXLta (ORCPT ); Thu, 24 Nov 2022 06:49:30 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61A66193F9; Thu, 24 Nov 2022 03:49:29 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id t25-20020a1c7719000000b003cfa34ea516so4362011wmi.1; Thu, 24 Nov 2022 03:49:29 -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=KWfj56pFXj1HTsSt2vtLzvRq7ahqzIR48ZMo4DRqEeY=; b=I7f0FQe64ZYl5Lvmn1JKId9c+MghKklHNQtOPw1msJG0fE40JL2mXsujNZNlvgiS+6 ljQeF5b1coULk1oz0gI1nDd5GCd8oF0pD9dk6N/QrIPVibX+BsSi3eQ1osAx4hZ0KMj5 RF/w8ay2QDO7hgAfEOh7VJ8g3Q4OQBFBLP42Qba3SWPWb+ay9MqixKjgMalUoxOzofpd o2+XD3vqFZU0xszWit8exEzymNAWdE1x8agJiF2KlrcLPnbbyClKOpG4GeE5AlV79fzv sfGlJnOs08oTfC+/pU/clhI+vMrSQjP+14sdSmXLG7TXkbsZ1X4/G3agoxyjdOu226OE G2ig== 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=KWfj56pFXj1HTsSt2vtLzvRq7ahqzIR48ZMo4DRqEeY=; b=xG81gWnbgAmjV7dquv2oppyjikHRn27+DxOH9uFglg8lsyiHSWmi+9VnSlG+pKDG5F 2ndV85z/ik2TO/TcUNK4YZAkx98AwvpPN3iTlywDbypZKEy9rq1MerMSLVTwly+xDi1l sDrDd123tcR2bnrV7RI3SdTL5owJw3Q0drDSDrh59a0EYqBbNMET0NeiaQxthNlIugXq c/Yz0LzH6Q/4GDJyKqo/mNhl0k0StsvZnUG5Vt8OY2lB0LGFnb/Er89jV0Oj4wt53uPD DM9bizKNH6nh8j2kaq0edYc//QMljdIvqHikbwSV5SkOt9+HhPqV1Pj5AvVzrtGWuLZz T5Cw== X-Gm-Message-State: ANoB5pkdSGztQVTft88wxnAa/Eafi5/1VTdHVZyHDar7Ds7bMwX0qcTP L2dewqQBMaFCddWExzZQZCme60s1Jyk= X-Received: by 2002:a05:600c:3d16:b0:3c6:de4a:d768 with SMTP id bh22-20020a05600c3d1600b003c6de4ad768mr10082720wmb.61.1669290567905; Thu, 24 Nov 2022 03:49:27 -0800 (PST) Received: from debian ([89.238.191.199]) by smtp.gmail.com with ESMTPSA id p11-20020a05600c468b00b003cfd10a33afsm5727643wmo.11.2022.11.24.03.48.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Nov 2022 03:49:26 -0800 (PST) Date: Thu, 24 Nov 2022 12:48:23 +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] net: setsockopt: fix IPV6_UNICAST_IF option for connected sockets Message-ID: <20221124114713.GA73129@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?1750378609879029685?= X-GMAIL-MSGID: =?utf-8?q?1750378609879029685?= 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 Signed-off-by: Richard Gobert Reviewed-by: David Ahern --- net/ipv6/datagram.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c index 7c7155b48f17..c3999f9e3545 100644 --- a/net/ipv6/datagram.c +++ b/net/ipv6/datagram.c @@ -42,24 +42,30 @@ 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; 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; + 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)); }