From patchwork Wed Feb 22 08:36:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Wei X-Patchwork-Id: 60357 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp437337wrd; Tue, 21 Feb 2023 23:36:41 -0800 (PST) X-Google-Smtp-Source: AK7set/5AjuxInixcl+8bWrqkn4h+JnhviLWuou0RmLQB6BLSWxelrKDbqvAShbpsv/DaZuOpLG5 X-Received: by 2002:a05:6402:12ca:b0:4ab:4411:2f71 with SMTP id k10-20020a05640212ca00b004ab44112f71mr5811341edx.37.1677051401284; Tue, 21 Feb 2023 23:36:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677051401; cv=none; d=google.com; s=arc-20160816; b=JJtyugf5mgCoie97mrlXyi7hRZEenAukQKmZMlpA68G79Shb/0L5KLXf5ggXLpSa3j +7U9V4yDPyOoMlscNPuiTVlFVGXV0SRPPINnfKIzyp99WEMP9ejrBG6MD6NmPeY0lbG2 Y8gW56k2UX1WB7r/J4yipCZktgb/VFeomq5Y7sjXQyNVsv/uWTVqw/aq2EHZSn0KKyVx jY2UMXIEKJdVK4WFsgnHaKJluh54XFtYfebIYKkKK1sGcO+O/vUicx7SCC6ESIHmb5hO F5bF5wHfwp83YBDjB7JOZoIVz0Q3bmqX9J0HSth/D89WTiJxFET3Oho0ozXg2kFd2+F+ SztQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from; bh=RSVT8MuTqeAnvoP0Fq0XLkR8h/F5gH14QD2SSSDiVFs=; b=SuOWqc+YuJEsmSKXtwXB03At/SU3+SPiCgTh4CJqD+jp+CMg4do3XzRLtAyKaMvMre w9v2JHs4f7Y9iIDe5gBYvYkfJk661HKUGhJhVWDLwxx2pAYoqB5VdKStkOW6Rr2R2TCi GI5cAbXQR1/BPeRhUZ8bO+U8DfFIxtetSY3LFqNbdXoJaFS5FiLHxqj8MtbsYSFZ98Gm AgluSiL6ssJQbh2yRNH1zak4cBilEMPp9K407S3QOcWhhj9wAhwVRpIia1yAHokGPFSh E7FLGqyddX76RXcfDMfN0m6QJR/UulT20yyhBBPu096F4eXxtj9mI7Wusi0fM9Ibyr0R 7Nyg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a16-20020aa7cf10000000b004ad062c0da2si649553edy.55.2023.02.21.23.36.18; Tue, 21 Feb 2023 23:36:41 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231193AbjBVH1J (ORCPT + 99 others); Wed, 22 Feb 2023 02:27:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231168AbjBVH1H (ORCPT ); Wed, 22 Feb 2023 02:27:07 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AAB536686; Tue, 21 Feb 2023 23:27:06 -0800 (PST) Received: from kwepemi500015.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4PM72T6nWxz16PCh; Wed, 22 Feb 2023 15:24:33 +0800 (CST) Received: from huawei.com (10.175.101.6) by kwepemi500015.china.huawei.com (7.221.188.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Wed, 22 Feb 2023 15:27:02 +0800 From: Lu Wei To: , , , , , , Subject: [PATCH net,v4,1/2] ipv6: Add lwtunnel encap size of all siblings in nexthop calculation Date: Wed, 22 Feb 2023 16:36:28 +0800 Message-ID: <20230222083629.335683-2-luwei32@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230222083629.335683-1-luwei32@huawei.com> References: <20230222083629.335683-1-luwei32@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemi500015.china.huawei.com (7.221.188.92) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,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?1758515850141921755?= X-GMAIL-MSGID: =?utf-8?q?1758515850141921755?= In function rt6_nlmsg_size(), the length of nexthop is calculated by multipling the nexthop length of fib6_info and the number of siblings. However if the fib6_info has no lwtunnel but the siblings have lwtunnels, the nexthop length is less than it should be, and it will trigger a warning in inet6_rt_notify() as follows: WARNING: CPU: 0 PID: 6082 at net/ipv6/route.c:6180 inet6_rt_notify+0x120/0x130 ...... Call Trace: fib6_add_rt2node+0x685/0xa30 fib6_add+0x96/0x1b0 ip6_route_add+0x50/0xd0 inet6_rtm_newroute+0x97/0xa0 rtnetlink_rcv_msg+0x156/0x3d0 netlink_rcv_skb+0x5a/0x110 netlink_unicast+0x246/0x350 netlink_sendmsg+0x250/0x4c0 sock_sendmsg+0x66/0x70 ___sys_sendmsg+0x7c/0xd0 __sys_sendmsg+0x5d/0xb0 do_syscall_64+0x3f/0x90 entry_SYSCALL_64_after_hwframe+0x72/0xdc This bug can be reproduced by script: ip -6 addr add 2002::2/64 dev ens2 ip -6 route add 100::/64 via 2002::1 dev ens2 metric 100 for i in 10 20 30 40 50 60 70; do ip link add link ens2 name ipv_$i type ipvlan ip -6 addr add 2002::$i/64 dev ipv_$i ifconfig ipv_$i up done for i in 10 20 30 40 50 60; do ip -6 route append 100::/64 encap ip6 dst 2002::$i via 2002::1 dev ipv_$i metric 100 done ip -6 route append 100::/64 via 2002::1 dev ipv_70 metric 100 This patch fixes it by adding nexthop_len of every siblings using rt6_nh_nlmsg_size(). Fixes: beb1afac518d ("net: ipv6: Add support to dump multipath routes via RTA_MULTIPATH attribute") Signed-off-by: Lu Wei Reviewed-by: David Ahern --- net/ipv6/route.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index c180c2ef17c5..0fdb03df2287 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -5533,16 +5533,17 @@ static size_t rt6_nlmsg_size(struct fib6_info *f6i) nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_nlmsg_size, &nexthop_len); } else { + struct fib6_info *sibling, *next_sibling; struct fib6_nh *nh = f6i->fib6_nh; nexthop_len = 0; if (f6i->fib6_nsiblings) { - nexthop_len = nla_total_size(0) /* RTA_MULTIPATH */ - + NLA_ALIGN(sizeof(struct rtnexthop)) - + nla_total_size(16) /* RTA_GATEWAY */ - + lwtunnel_get_encap_size(nh->fib_nh_lws); + rt6_nh_nlmsg_size(nh, &nexthop_len); - nexthop_len *= f6i->fib6_nsiblings; + list_for_each_entry_safe(sibling, next_sibling, + &f6i->fib6_siblings, fib6_siblings) { + rt6_nh_nlmsg_size(sibling->fib6_nh, &nexthop_len); + } } nexthop_len += lwtunnel_get_encap_size(nh->fib_nh_lws); } From patchwork Wed Feb 22 08:36:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Wei X-Patchwork-Id: 60358 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp437802wrd; Tue, 21 Feb 2023 23:38:25 -0800 (PST) X-Google-Smtp-Source: AK7set/VWA1OtbDjk0IGX7itfB/yRXNCVjQvmNa/TxWr3PLqyo/jRrkGYyoE8t+jwPuL1vxkhxWo X-Received: by 2002:aa7:8ecc:0:b0:5a8:bcf2:125 with SMTP id b12-20020aa78ecc000000b005a8bcf20125mr5617979pfr.21.1677051504689; Tue, 21 Feb 2023 23:38:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677051504; cv=none; d=google.com; s=arc-20160816; b=RltunrXywIGyYkpYtRGeYjpePwT43qeFwu64MZeXiThcAMKu5XWfkf2u3yCOG5aJQl X7XfIUVfOftIOhWpZ9WY3GnIgxAJ3oufY6KlzhCYOi449usya95upLfXg2NBmGbh7Wtp nji3M/m1hWVjQdBiOOYrYXPcVxaXEgQSFYJW9OomVV1l3y7HNQ9n0Vx3tswPA4VXRzjS o+LUDHJinyHIuuFyXB578kYzvr5BAs/NiXRGhEmxyWSWeL4rK6fvvQXrwg7fXs0T6JHu wXxdMWEfi2kEkbcpmBi+bYU/ZgHK8l2UOwdt6uPfJ4QZkUS6rpE5wvITNh8MhX14NbvU E9GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from; bh=PeLbL20GFGPb2z8bXjOljVpC7GlmuK4Zx9FcJjrQSkc=; b=EZBo4FjauQKU2z94ptk0soibnP8yEghMRDV/kyRNHEMsil0cPxeejr7W0/1dU+PgVc N5U13Dio0rzWFWXSQw/3Ubjne/qD2ubaMjPvzv7iMQoY9u2+5qJHT2oq3i0Z0bZbzeXm xx95p/fUAEcBOTbU9W70vSD38GxvW3rM5G9pPFiy0kFd1gfaGlIiUQrRLEOwTzhVhcux 710UZZubYBb8IByI8vfNro+bVHlzk5bHr2al0vwYH570nlXz4oXPWvgIYwghOvyQ2L8k wmfTbvuWQtqzXAfFqRab+MuzQDL7YybOZwcnBOcui9092X1MkVFcWjI4/nu14HNBncal 4UQA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020aa7948b000000b005a81586634esi19616402pfk.151.2023.02.21.23.38.11; Tue, 21 Feb 2023 23:38:24 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229836AbjBVH1L (ORCPT + 99 others); Wed, 22 Feb 2023 02:27:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231175AbjBVH1I (ORCPT ); Wed, 22 Feb 2023 02:27:08 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47D0D3668F; Tue, 21 Feb 2023 23:27:06 -0800 (PST) Received: from kwepemi500015.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4PM6zm5rnczKmS2; Wed, 22 Feb 2023 15:22:12 +0800 (CST) Received: from huawei.com (10.175.101.6) by kwepemi500015.china.huawei.com (7.221.188.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Wed, 22 Feb 2023 15:27:03 +0800 From: Lu Wei To: , , , , , , Subject: [PATCH net,v4,2/2] selftests: fib_tests: Add test cases for IPv4/IPv6 in route notify Date: Wed, 22 Feb 2023 16:36:29 +0800 Message-ID: <20230222083629.335683-3-luwei32@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230222083629.335683-1-luwei32@huawei.com> References: <20230222083629.335683-1-luwei32@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemi500015.china.huawei.com (7.221.188.92) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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?1758515958750337814?= X-GMAIL-MSGID: =?utf-8?q?1758515958750337814?= Add tests to check whether the total fib info length is calculated corretly in route notify process. Signed-off-by: Lu Wei Reviewed-by: David Ahern --- tools/testing/selftests/net/fib_tests.sh | 96 +++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh index 70ea8798b1f6..7da8ec838c63 100755 --- a/tools/testing/selftests/net/fib_tests.sh +++ b/tools/testing/selftests/net/fib_tests.sh @@ -9,7 +9,7 @@ ret=0 ksft_skip=4 # all tests in this script. Can be overridden with -t option -TESTS="unregister down carrier nexthop suppress ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh" +TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh" VERBOSE=0 PAUSE_ON_FAIL=no @@ -655,6 +655,98 @@ fib_nexthop_test() cleanup } +fib6_notify_test() +{ + setup + + echo + echo "Fib6 info length calculation in route notify test" + set -e + + for i in 10 20 30 40 50 60 70; + do + $IP link add dummy_$i type dummy + $IP link set dev dummy_$i up + $IP -6 address add 2001:$i::1/64 dev dummy_$i + done + + $NS_EXEC ip monitor route &> errors.txt & + sleep 2 + + $IP -6 route add 2001::/64 \ + nexthop via 2001:10::2 dev dummy_10 \ + nexthop encap ip6 dst 2002::20 via 2001:20::2 dev dummy_20 \ + nexthop encap ip6 dst 2002::30 via 2001:30::2 dev dummy_30 \ + nexthop encap ip6 dst 2002::40 via 2001:40::2 dev dummy_40 \ + nexthop encap ip6 dst 2002::50 via 2001:50::2 dev dummy_50 \ + nexthop encap ip6 dst 2002::60 via 2001:60::2 dev dummy_60 \ + nexthop encap ip6 dst 2002::70 via 2001:70::2 dev dummy_70 + + set +e + + err=`cat errors.txt |grep "Message too long"` + if [ -z "$err" ];then + ret=0 + else + ret=1 + fi + + log_test $ret 0 "ipv6 route add notify" + + { kill %% && wait %%; } 2>/dev/null + + #rm errors.txt + + cleanup &> /dev/null +} + + +fib_notify_test() +{ + setup + + echo + echo "Fib4 info length calculation in route notify test" + + set -e + + for i in 10 20 30 40 50 60 70; + do + $IP link add dummy_$i type dummy + $IP link set dev dummy_$i up + $IP address add 20.20.$i.2/24 dev dummy_$i + done + + $NS_EXEC ip monitor route &> errors.txt & + sleep 2 + + $IP route add 10.0.0.0/24 \ + nexthop via 20.20.10.1 dev dummy_10 \ + nexthop encap ip dst 192.168.10.20 via 20.20.20.1 dev dummy_20 \ + nexthop encap ip dst 192.168.10.30 via 20.20.30.1 dev dummy_30 \ + nexthop encap ip dst 192.168.10.40 via 20.20.40.1 dev dummy_40 \ + nexthop encap ip dst 192.168.10.50 via 20.20.50.1 dev dummy_50 \ + nexthop encap ip dst 192.168.10.60 via 20.20.60.1 dev dummy_60 \ + nexthop encap ip dst 192.168.10.70 via 20.20.70.1 dev dummy_70 + + set +e + + err=`cat errors.txt |grep "Message too long"` + if [ -z "$err" ];then + ret=0 + else + ret=1 + fi + + log_test $ret 0 "ipv4 route add notify" + + { kill %% && wait %%; } 2>/dev/null + + rm errors.txt + + cleanup &> /dev/null +} + fib_suppress_test() { echo @@ -2111,6 +2203,8 @@ do fib_carrier_test|carrier) fib_carrier_test;; fib_rp_filter_test|rp_filter) fib_rp_filter_test;; fib_nexthop_test|nexthop) fib_nexthop_test;; + fib_notify_test|ipv4_notify) fib_notify_test;; + fib6_notify_test|ipv6_notify) fib6_notify_test;; fib_suppress_test|suppress) fib_suppress_test;; ipv6_route_test|ipv6_rt) ipv6_route_test;; ipv4_route_test|ipv4_rt) ipv4_route_test;;