From patchwork Thu Jan 28 12:49:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 373123 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B4E7C433E0 for ; Thu, 28 Jan 2021 12:51:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB56564DE1 for ; Thu, 28 Jan 2021 12:51:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231708AbhA1Mv3 (ORCPT ); Thu, 28 Jan 2021 07:51:29 -0500 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:10199 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231670AbhA1MvC (ORCPT ); Thu, 28 Jan 2021 07:51:02 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Thu, 28 Jan 2021 04:50:21 -0800 Received: from localhost.localdomain (172.20.145.6) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 28 Jan 2021 12:50:19 +0000 From: Petr Machata To: CC: David Ahern , "David S. Miller" , Jakub Kicinski , Ido Schimmel , "Petr Machata" Subject: [PATCH net-next 03/12] nexthop: Introduce to struct nh_grp_entry a per-type union Date: Thu, 28 Jan 2021 13:49:15 +0100 Message-ID: <96736e8f9767633e73dacd59c0836547824d0ff8.1611836479.git.petrm@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL111.nvidia.com (172.20.187.18) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1611838221; bh=Hlr7VD83c12xPjed7e0j4HsacUYtv+gCCon+r9CBSlE=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=DP8gfjDgT0wGMHn21hgpOPK3ja/gQbMYgil4NhLgvpiiZeN6Sl73Wh9pQ6CQDSXM4 B8xx1bgsUTGOy4Kttam5kWoIU9Wqt2eA7zYUoddDJA/yWCKkZMlX5hBz+FBKv/TBHV dLhXBOp7zjSvgiCbJ2d25WudRfdEJw9VuNjvOmfUGdI3w3tTdurX9sObg4Y29g8T9I qcv5jnwEnDGZT4buZn4yoO+2vO4yKnmPVMTHT2Kx6so0NGuqAszxtauWnZ0oZJrl81 ZF5RdR+3NJ5ROr2VdHKnFkyhjKQSDwvNFADneqWxrcDdZu4nGCex/4SL3hKw6lkCAf 0PBSNCvUH6v/Q== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The values that a next-hop group needs to keep track of depend on the group type. Introduce a union to separate fields specific to the mpath groups from fields specific to other group types. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Reviewed-by: David Ahern --- include/net/nexthop.h | 7 ++++++- net/ipv4/nexthop.c | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/net/nexthop.h b/include/net/nexthop.h index 226930d66b63..d0e245b0635d 100644 --- a/include/net/nexthop.h +++ b/include/net/nexthop.h @@ -66,7 +66,12 @@ struct nh_info { struct nh_grp_entry { struct nexthop *nh; u8 weight; - atomic_t upper_bound; + + union { + struct { + atomic_t upper_bound; + } mpath; + }; struct list_head nh_list; struct nexthop *nh_parent; /* nexthop of group with this entry */ diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 43bb5f451343..7a30df5aea75 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -689,7 +689,7 @@ static struct nexthop *nexthop_select_path_mp(struct nh_group *nhg, int hash) struct nh_grp_entry *nhge = &nhg->nh_entries[i]; struct nh_info *nhi; - if (hash > atomic_read(&nhge->upper_bound)) + if (hash > atomic_read(&nhge->mpath.upper_bound)) continue; nhi = rcu_dereference(nhge->nh->nh_info); @@ -924,7 +924,7 @@ static void nh_group_rebalance(struct nh_group *nhg) w += nhge->weight; upper_bound = DIV_ROUND_CLOSEST_ULL((u64)w << 31, total) - 1; - atomic_set(&nhge->upper_bound, upper_bound); + atomic_set(&nhge->mpath.upper_bound, upper_bound); } } From patchwork Thu Jan 28 12:49:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 373122 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03628C433DB for ; Thu, 28 Jan 2021 12:52:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C8E0564DE3 for ; Thu, 28 Jan 2021 12:51:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231800AbhA1Mvk (ORCPT ); Thu, 28 Jan 2021 07:51:40 -0500 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:10203 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231687AbhA1MvF (ORCPT ); Thu, 28 Jan 2021 07:51:05 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Thu, 28 Jan 2021 04:50:24 -0800 Received: from localhost.localdomain (172.20.145.6) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 28 Jan 2021 12:50:21 +0000 From: Petr Machata To: CC: David Ahern , "David S. Miller" , Jakub Kicinski , Ido Schimmel , "Petr Machata" Subject: [PATCH net-next 04/12] nexthop: Assert the invariant that a NH group is of only one type Date: Thu, 28 Jan 2021 13:49:16 +0100 Message-ID: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL111.nvidia.com (172.20.187.18) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1611838224; bh=ytMwLuN+U91Wdu6V6nXe44wN0pUwWSX2bNh0iJNBcvA=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=bLYWB8BJTFuJLeWjTmlq7QcZY3O+muiEM0uy+MmZcKm+6UI4ayHLYpHXf90SDOW8z 31qSQsqOWNrD9073BwD7W2mGp74G7koW4HM2sEiSlZOsicqrHxXcEmXXdSitqkRBXK tW+7Loympv3il6F/a0lNv1mUGjilwR67XeTaqm+b5d37yrrmP44JBQpbXiuj3ajZLp CGPYRcKT7sTw809EgpNgn3xygK8VSuXy4MyPka7ckmxUuyTdlX3oi6Yt8W9/k1E2eF isKYussohrdR1aKB+n+AXhauwR9XhjPjeIhzLO9ubKrZ4RcfilDjj3I8sv+pgkmV5l CfQjuNpIqy2gQ== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Most of the code that deals with nexthop groups relies on the fact that the group is of exactly one well-known type. Currently there is only one type, "mpath", but as more next-hop group types come, it becomes desirable to have a central place where the setting is validated. Introduce such place into nexthop_create_group(), such that the check is done before the code that relies on that invariant is invoked. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Reviewed-by: David Ahern --- net/ipv4/nexthop.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 7a30df5aea75..c09b8231f56a 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -1466,10 +1466,13 @@ static struct nexthop *nexthop_create_group(struct net *net, nhg->nh_entries[i].nh_parent = nh; } - if (cfg->nh_grp_type == NEXTHOP_GRP_TYPE_MPATH) { + if (cfg->nh_grp_type == NEXTHOP_GRP_TYPE_MPATH) nhg->mpath = 1; + + WARN_ON_ONCE(nhg->mpath != 1); + + if (nhg->mpath) nh_group_rebalance(nhg); - } if (cfg->nh_fdb) nhg->fdb_nh = 1; From patchwork Thu Jan 28 12:49:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 373121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FDF7C433E0 for ; Thu, 28 Jan 2021 12:52:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 644FD64DE3 for ; Thu, 28 Jan 2021 12:52:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231286AbhA1MwV (ORCPT ); Thu, 28 Jan 2021 07:52:21 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:15899 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231715AbhA1MvK (ORCPT ); Thu, 28 Jan 2021 07:51:10 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Thu, 28 Jan 2021 04:50:30 -0800 Received: from localhost.localdomain (172.20.145.6) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 28 Jan 2021 12:50:27 +0000 From: Petr Machata To: CC: David Ahern , "David S. Miller" , Jakub Kicinski , Ido Schimmel , "Petr Machata" Subject: [PATCH net-next 06/12] nexthop: Dispatch notifier init()/fini() by group type Date: Thu, 28 Jan 2021 13:49:18 +0100 Message-ID: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL111.nvidia.com (172.20.187.18) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1611838230; bh=9jGJ9NJrYCmCHdZzdQPqjwMACE7wN7WyvLYG/A7Vfx0=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=Y06z0jXq+TIrRvJIGxqp5c2k05DvinigHy7rnmcK68xNC4dOk/LbBlYF8l112uUQX 3my6UXDMmTJG9g2AYpOo/r8eiApNgGV8bCK2nKsOa+Zc9fOWHjYwlFQZa5HfX2mhuv OrJRAs7bJdlZRw0otUceLoFuM+dLHNjimNL8Tmm5g+NvIp9hI6yQKzUd3trVnI5SwU EgDtJJqe1ChKagCiwQDU86voawE9k+58snCTa48eM64t27EzEu0SfKs+qhlZYrpCrM +1SuXKzPa6Tr1inVOR1+z1ye3BiMumXyrnCqz3oHTnCm/b95i59iIOJElXs4ODMduf vbrRJyGhJndlA== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org After there are several next-hop group types, initialization and finalization of notifier type needs to reflect the actual type. Transform nh_notifier_grp_info_init() and _fini() to make extending them easier. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Reviewed-by: David Ahern --- net/ipv4/nexthop.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 12f812b9538d..7149b12c4703 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -86,10 +86,9 @@ static void nh_notifier_single_info_fini(struct nh_notifier_info *info) kfree(info->nh); } -static int nh_notifier_grp_info_init(struct nh_notifier_info *info, - const struct nexthop *nh) +static int nh_notifier_mp_info_init(struct nh_notifier_info *info, + struct nh_group *nhg) { - struct nh_group *nhg = rtnl_dereference(nh->nh_grp); u16 num_nh = nhg->num_nh; int i; @@ -114,9 +113,23 @@ static int nh_notifier_grp_info_init(struct nh_notifier_info *info, return 0; } -static void nh_notifier_grp_info_fini(struct nh_notifier_info *info) +static int nh_notifier_grp_info_init(struct nh_notifier_info *info, + const struct nexthop *nh) { - kfree(info->nh_grp); + struct nh_group *nhg = rtnl_dereference(nh->nh_grp); + + if (nhg->mpath) + return nh_notifier_mp_info_init(info, nhg); + return -EINVAL; +} + +static void nh_notifier_grp_info_fini(struct nh_notifier_info *info, + const struct nexthop *nh) +{ + struct nh_group *nhg = rtnl_dereference(nh->nh_grp); + + if (nhg->mpath) + kfree(info->nh_grp); } static int nh_notifier_info_init(struct nh_notifier_info *info, @@ -134,7 +147,7 @@ static void nh_notifier_info_fini(struct nh_notifier_info *info, const struct nexthop *nh) { if (nh->is_group) - nh_notifier_grp_info_fini(info); + nh_notifier_grp_info_fini(info, nh); else nh_notifier_single_info_fini(info); } From patchwork Thu Jan 28 12:49:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 373119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5985C433DB for ; Thu, 28 Jan 2021 12:53:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C7B064DE4 for ; Thu, 28 Jan 2021 12:53:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231171AbhA1MxI (ORCPT ); Thu, 28 Jan 2021 07:53:08 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:15988 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231809AbhA1Mvp (ORCPT ); Thu, 28 Jan 2021 07:51:45 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Thu, 28 Jan 2021 04:50:39 -0800 Received: from localhost.localdomain (172.20.145.6) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 28 Jan 2021 12:50:36 +0000 From: Petr Machata To: CC: David Ahern , "David S. Miller" , Jakub Kicinski , Ido Schimmel , "Petr Machata" Subject: [PATCH net-next 09/12] nexthop: Strongly-type context of rtm_dump_nexthop() Date: Thu, 28 Jan 2021 13:49:21 +0100 Message-ID: <540e18781f82a0f0b0482b10e7180a57369e8388.1611836479.git.petrm@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL111.nvidia.com (172.20.187.18) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1611838239; bh=8EH3BUufPpqWJ26HPs+KEmOTX5a+ROBs6kNxVSRTSpI=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=ir9r7F5m4lGdn7d4LpUlxsIvF1XGITErEGz/zl7qFOuuBZK8PQ69MgTKc8E+le82e HAlclJjriArMs+hiNkTbXFNR2qDb8XPDP68KFj1MtkOBMVPSMxq3s5lqTvdXpWZNFj G0meejFnEZ59LRv0Ae0Zul0EWFES7e+cNIRbBwgIFHwZa0mu6VmccE21X18F04af+w TvusiJ3bIEE61t4wskZ5fdpf2IfvfDD6SLyENa7SpLpyWDu+RLQ+cnFs0rK8zUxAzr 3ZLpO8M5DkA5YVD2PkcrYtK0j1Ex0orrzc5bJcJDzQ1KqGGVpOGP7LYTBkPKC7Sp78 ZR6ivR2k4CoCQ== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The dump operations need to keep state from one invocation to another. A scratch area is dedicated for this purpose in the passed-in argument, cb, namely via two aliased arrays, struct netlink_callback.args and .ctx. Dumping of buckets will end up having to iterate over next hops as well, and it would be nice to be able to reuse the iteration logic with the NH dumper. The fact that the logic currently relies on fixed index to the .args array, and the indices would have to be coordinated between the two dumpers, makes this somewhat awkward. To make the access patters clearer, introduce a helper struct with a NH index, and instead of using the .args array directly, use it through this structure. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Reviewed-by: David Ahern --- net/ipv4/nexthop.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 1c4f10fe3b4e..7ae197efa5a9 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -2066,9 +2066,23 @@ static int nh_valid_dump_req(const struct nlmsghdr *nlh, return __nh_valid_dump_req(nlh, tb, filter, cb->extack); } +struct rtm_dump_nh_ctx { + u32 idx; +}; + +static struct rtm_dump_nh_ctx * +rtm_dump_nh_ctx(struct netlink_callback *cb) +{ + struct rtm_dump_nh_ctx *ctx = (void *)cb->ctx; + + BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx)); + return ctx; +} + /* rtnl */ static int rtm_dump_nexthop(struct sk_buff *skb, struct netlink_callback *cb) { + struct rtm_dump_nh_ctx *ctx = rtm_dump_nh_ctx(cb); struct nhmsg *nhm = nlmsg_data(cb->nlh); struct net *net = sock_net(skb->sk); struct rb_root *root = &net->nexthop.rb_root; @@ -2081,7 +2095,7 @@ static int rtm_dump_nexthop(struct sk_buff *skb, struct netlink_callback *cb) if (err < 0) return err; - s_idx = cb->args[0]; + s_idx = ctx->idx; for (node = rb_first(root); node; node = rb_next(node)) { struct nexthop *nh; @@ -2108,7 +2122,7 @@ static int rtm_dump_nexthop(struct sk_buff *skb, struct netlink_callback *cb) out: err = skb->len; out_err: - cb->args[0] = idx; + ctx->idx = idx; cb->seq = net->nexthop.seq; nl_dump_check_consistent(cb, nlmsg_hdr(skb)); From patchwork Thu Jan 28 12:49:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 373120 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7314BC433DB for ; Thu, 28 Jan 2021 12:52:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F81C64DE4 for ; Thu, 28 Jan 2021 12:52:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231858AbhA1Mwt (ORCPT ); Thu, 28 Jan 2021 07:52:49 -0500 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:4126 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231779AbhA1MvW (ORCPT ); Thu, 28 Jan 2021 07:51:22 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Thu, 28 Jan 2021 04:50:41 -0800 Received: from localhost.localdomain (172.20.145.6) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 28 Jan 2021 12:50:39 +0000 From: Petr Machata To: CC: David Ahern , "David S. Miller" , Jakub Kicinski , Ido Schimmel , "Petr Machata" Subject: [PATCH net-next 10/12] nexthop: Extract a helper for walking the next-hop tree Date: Thu, 28 Jan 2021 13:49:22 +0100 Message-ID: <2537ad1b469601766024e2eb66c135ee2e82e8d0.1611836479.git.petrm@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL111.nvidia.com (172.20.187.18) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1611838242; bh=hVBSeUUH/0E70ID0YkRhLTSPOsjMsO3zoElGixA3Coo=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=sNh3FSSPrvIihl3ZuPP/BIAt2FGqrEWHdhmzjkSSzTJZs1Vr/Ehdk25KLe5TmaG4q 9+euKh1eQvZAyX0cUqnzhfOHoqV+0JFxhcSYA1+takOKRatVRS1FEnfRTPXhQLXumy gaX2RAZ/ButBsVcxTzzDNQySqQExcZQcCg3jWHZYDqAw/F1o5vYpkUgXD8//SRxQx8 NDhStHJFfAV3zfkHPVmbUcToszkRZG2EOLV52hQJv+s16/QbPwb8NP56jSTb4YfUkA d6QPWv1bjLOVYmIfvDq6HZ7Ptmw+9Slz6hiqINV6Byb44yRXfEWC0l+GXFOrziMvHs tG+fpPjWGVtOQ== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Extract from rtm_dump_nexthop() a helper to walk the next hop tree. A separate function for this will be reusable from the bucket dumper. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Reviewed-by: David Ahern --- net/ipv4/nexthop.c | 52 +++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 7ae197efa5a9..e5175f531ffb 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -2079,22 +2079,17 @@ rtm_dump_nh_ctx(struct netlink_callback *cb) return ctx; } -/* rtnl */ -static int rtm_dump_nexthop(struct sk_buff *skb, struct netlink_callback *cb) +static int rtm_dump_walk_nexthops(struct sk_buff *skb, + struct netlink_callback *cb, + struct rb_root *root, + struct rtm_dump_nh_ctx *ctx, + struct nh_dump_filter *filter) { - struct rtm_dump_nh_ctx *ctx = rtm_dump_nh_ctx(cb); struct nhmsg *nhm = nlmsg_data(cb->nlh); - struct net *net = sock_net(skb->sk); - struct rb_root *root = &net->nexthop.rb_root; - struct nh_dump_filter filter = {}; struct rb_node *node; int idx = 0, s_idx; int err; - err = nh_valid_dump_req(cb->nlh, &filter, cb); - if (err < 0) - return err; - s_idx = ctx->idx; for (node = rb_first(root); node; node = rb_next(node)) { struct nexthop *nh; @@ -2103,29 +2098,48 @@ static int rtm_dump_nexthop(struct sk_buff *skb, struct netlink_callback *cb) goto cont; nh = rb_entry(node, struct nexthop, rb_node); - if (nh_dump_filtered(nh, &filter, nhm->nh_family)) + if (nh_dump_filtered(nh, filter, nhm->nh_family)) goto cont; + ctx->idx = idx; err = nh_fill_node(skb, nh, RTM_NEWNEXTHOP, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, NLM_F_MULTI); - if (err < 0) { - if (likely(skb->len)) - goto out; - - goto out_err; - } + if (err < 0) + return err; cont: idx++; } + ctx->idx = idx; + return 0; +} + +/* rtnl */ +static int rtm_dump_nexthop(struct sk_buff *skb, struct netlink_callback *cb) +{ + struct rtm_dump_nh_ctx *ctx = rtm_dump_nh_ctx(cb); + struct net *net = sock_net(skb->sk); + struct rb_root *root = &net->nexthop.rb_root; + struct nh_dump_filter filter = {}; + int err; + + err = nh_valid_dump_req(cb->nlh, &filter, cb); + if (err < 0) + return err; + + err = rtm_dump_walk_nexthops(skb, cb, root, ctx, &filter); + if (err < 0) { + if (likely(skb->len)) + goto out; + goto out_err; + } + out: err = skb->len; out_err: - ctx->idx = idx; cb->seq = net->nexthop.seq; nl_dump_check_consistent(cb, nlmsg_hdr(skb)); - return err; } From patchwork Thu Jan 28 12:49:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 373118 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B589C433E0 for ; Thu, 28 Jan 2021 12:53:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E5D3664DE4 for ; Thu, 28 Jan 2021 12:53:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231783AbhA1Mxx (ORCPT ); Thu, 28 Jan 2021 07:53:53 -0500 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:10229 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231834AbhA1Mv5 (ORCPT ); Thu, 28 Jan 2021 07:51:57 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Thu, 28 Jan 2021 04:50:47 -0800 Received: from localhost.localdomain (172.20.145.6) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 28 Jan 2021 12:50:45 +0000 From: Petr Machata To: CC: David Ahern , "David S. Miller" , Jakub Kicinski , Ido Schimmel , "Petr Machata" Subject: [PATCH net-next 12/12] nexthop: Extract a helper for validation of get/del RTNL requests Date: Thu, 28 Jan 2021 13:49:24 +0100 Message-ID: <69b7beb0f8ae239762f08b8385fe74640f3b3f64.1611836479.git.petrm@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL111.nvidia.com (172.20.187.18) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1611838247; bh=xrdRKAldmEvAszH3e90YvRse9CsRUM5RiftNqnvflQw=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=fuQtOjbLKBuOSCyy5VKNdQ/xjeGnKmNY+RZCBZVCtSdsJqcjHnk3jx44szlsO8Yws XmBD74xLu9XTmBe1ZvoCLyVhpIsGosQz5Q+/0hC+LeTlT808JrRbrqr2mhdRZ2kdbv VFReyKVIzs+ivUCYWtNLLkWwkZaHKVShAcbX/rUc9KlucEXe9FYLWZ/jUyejCcEopI SGs6mdgkuol44qlwk22A2271/0Wk1svd0fege+vD5F26HUFRyHoBTcCx6Qym2ZcpJH hKULQXZVQ/PQWn3tQLBU5y7ieBM6JPfUHbfylvwoG412l6ucxXhUg2M4s5kSDhGpx5 Jl+yX0fgQ1xTA== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Validation of messages for get / del of a next hop is the same as will be validation of messages for get of a resilient next hop group bucket. The difference is that policy for resilient next hop group buckets is a superset of that used for next-hop get. It is therefore possible to reuse the code that validates the nhmsg fields, extracts the next-hop ID, and validates that. To that end, extract from nh_valid_get_del_req() a helper __nh_valid_get_del_req() that does just that. Make the nlh argument const so that the function can be called from the dump context, which only has a const nlh. Propagate the constness to nh_valid_get_del_req(). Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Reviewed-by: David Ahern --- net/ipv4/nexthop.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 9536cf2f6aca..f1c6cbdb9e43 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -1872,37 +1872,44 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, return err; } -static int nh_valid_get_del_req(struct nlmsghdr *nlh, u32 *id, - struct netlink_ext_ack *extack) +static int __nh_valid_get_del_req(const struct nlmsghdr *nlh, + struct nlattr **tb, u32 *id, + struct netlink_ext_ack *extack) { struct nhmsg *nhm = nlmsg_data(nlh); - struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_get)]; - int err; - - err = nlmsg_parse(nlh, sizeof(*nhm), tb, - ARRAY_SIZE(rtm_nh_policy_get) - 1, - rtm_nh_policy_get, extack); - if (err < 0) - return err; - err = -EINVAL; if (nhm->nh_protocol || nhm->resvd || nhm->nh_scope || nhm->nh_flags) { NL_SET_ERR_MSG(extack, "Invalid values in header"); - goto out; + return -EINVAL; } if (!tb[NHA_ID]) { NL_SET_ERR_MSG(extack, "Nexthop id is missing"); - goto out; + return -EINVAL; } *id = nla_get_u32(tb[NHA_ID]); - if (!(*id)) + if (!(*id)) { NL_SET_ERR_MSG(extack, "Invalid nexthop id"); - else - err = 0; -out: - return err; + return -EINVAL; + } + + return 0; +} + +static int nh_valid_get_del_req(const struct nlmsghdr *nlh, u32 *id, + struct netlink_ext_ack *extack) +{ + struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_get)]; + int err; + + err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, + ARRAY_SIZE(rtm_nh_policy_get) - 1, + rtm_nh_policy_get, extack); + if (err < 0) + return err; + + return __nh_valid_get_del_req(nlh, tb, id, extack); } /* rtnl */