From patchwork Tue Mar 18 23:31:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 14021734 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80008.amazon.com (smtp-fw-80008.amazon.com [99.78.197.219]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D08EE1EF39E for ; Tue, 18 Mar 2025 23:33:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742340800; cv=none; b=YCk2W+duGvclHIkDzF1q+1f15+5awc+8QiHohd/P2v49YS63QbJz+cx3kBiYfCvfGTbAKL2hb6Kc1FANwJzcugfkO9oAlLYG7z9LW1mOmHwuuZn2NXDi/sOu/jFLcHR+8ZMKo4JIJlTy41Sw3n679ZBFMzs9Kcn+rZf6UuhE13U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742340800; c=relaxed/simple; bh=4i13R7Ze1ivTLzxG2CFzV2CD2mtQO9xvEdXP237qUUo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OTCRhbPuNOWGIHszFbbMOrsKAj2yK9ZHJolvCYpVnkT170yO2RzL8jzEC6uCB7YW+2/mUewgQbzvKgsygOZDiF8HypISh/NCDPmer8V6asV2V1qOeVWC8/7HMbHs3jLvw38APdbXzuXJK77rqKTwGyKDazK2YU0YXIWxS6romKs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=TQnNsIEW; arc=none smtp.client-ip=99.78.197.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="TQnNsIEW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1742340798; x=1773876798; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+ymCdQhgVdJVYK45xjx4+I3K0h7s+YUkZc2dbRPZ3uQ=; b=TQnNsIEWABZdHE8XUorCJwOrgt1BprZ5KofmTi/r4afbBxFHB7Ohix1N 7Hu0Qhp0lDj61THmRcuAE9+bE9B+xdnx529hhK+uF/lSehlDP5o2mUOKr l2FwNgvry6hu2jX8JdxqJLugM9RU7ywWvkXcISijTTqG+BGk3ZaPOOI6N c=; X-IronPort-AV: E=Sophos;i="6.14,258,1736812800"; d="scan'208";a="179801360" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80008.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 23:33:17 +0000 Received: from EX19MTAUWB002.ant.amazon.com [10.0.7.35:53629] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.40.40:2525] with esmtp (Farcaster) id afcf3cd4-3665-4882-a76d-397a305887df; Tue, 18 Mar 2025 23:33:16 +0000 (UTC) X-Farcaster-Flow-ID: afcf3cd4-3665-4882-a76d-397a305887df Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Tue, 18 Mar 2025 23:33:16 +0000 Received: from 6c7e67bfbae3.amazon.com (10.135.212.115) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Tue, 18 Mar 2025 23:33:14 +0000 From: Kuniyuki Iwashima To: David Ahern , "David S. Miller" , Eric Dumazet , Jakub Kicinski , "Paolo Abeni" CC: Simon Horman , Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 1/7] nexthop: Move nlmsg_parse() in rtm_to_nh_config() to rtm_new_nexthop(). Date: Tue, 18 Mar 2025 16:31:44 -0700 Message-ID: <20250318233240.53946-2-kuniyu@amazon.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318233240.53946-1-kuniyu@amazon.com> References: <20250318233240.53946-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D043UWA002.ant.amazon.com (10.13.139.53) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org We will split rtm_to_nh_config() into non-RTNL and RTNL parts, and then the latter also needs tb. As a prep, let's move nlmsg_parse() to rtm_new_nexthop(). Signed-off-by: Kuniyuki Iwashima --- net/ipv4/nexthop.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 01df7dd795f0..487933ecdb68 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -3016,19 +3016,13 @@ static int rtm_to_nh_config_grp_res(struct nlattr *res, struct nh_config *cfg, } static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, - struct nlmsghdr *nlh, struct nh_config *cfg, + struct nlmsghdr *nlh, struct nlattr **tb, + struct nh_config *cfg, struct netlink_ext_ack *extack) { struct nhmsg *nhm = nlmsg_data(nlh); - struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_new)]; int err; - err = nlmsg_parse(nlh, sizeof(*nhm), tb, - ARRAY_SIZE(rtm_nh_policy_new) - 1, - rtm_nh_policy_new, extack); - if (err < 0) - return err; - err = -EINVAL; if (nhm->resvd || nhm->nh_scope) { NL_SET_ERR_MSG(extack, "Invalid values in ancillary header"); @@ -3093,7 +3087,8 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, NL_SET_ERR_MSG(extack, "Invalid group type"); goto out; } - err = nh_check_attr_group(net, tb, ARRAY_SIZE(tb), + + err = nh_check_attr_group(net, tb, ARRAY_SIZE(rtm_nh_policy_new), cfg->nh_grp_type, extack); if (err) goto out; @@ -3211,18 +3206,26 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { + struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_new)]; struct net *net = sock_net(skb->sk); struct nh_config cfg; struct nexthop *nh; int err; - err = rtm_to_nh_config(net, skb, nlh, &cfg, extack); - if (!err) { - nh = nexthop_add(net, &cfg, extack); - if (IS_ERR(nh)) - err = PTR_ERR(nh); - } + err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, + ARRAY_SIZE(rtm_nh_policy_new) - 1, + rtm_nh_policy_new, extack); + if (err < 0) + goto out; + err = rtm_to_nh_config(net, skb, nlh, tb, &cfg, extack); + if (err) + goto out; + + nh = nexthop_add(net, &cfg, extack); + if (IS_ERR(nh)) + err = PTR_ERR(nh); +out: return err; } From patchwork Tue Mar 18 23:31:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 14021735 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFC6F1EF372 for ; Tue, 18 Mar 2025 23:33:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.220 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742340824; cv=none; b=bcVfX1OUBox3oByvO4oh0RQIYLF/bUIiWgYEjNf7YHF54i5gGS8W6p4kefi+yNLAbazW98DbFldqCQsJwb//AP+hsFS02V5EdzXE6p36R6ocNni/c/Ovg08kdoia6t31rGH6+YuR7Re9W74qru80jUZQ7T+Zzq0apHI7IYAzhak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742340824; c=relaxed/simple; bh=bOMw7GNtJRTvanCsq/dnHnTrT6xQdV5E37PG5konqdM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Zufk9f4Mghqc1ij8onos/hVcIun8sI5ADMvMm4gJwjmIc/r6wD0MHLNZ4NDRiMOxr8a/M+KQiUnkBbqZc/G8jBhZ/DKqUDszMC2ORUJah0kdV1/tJyDRNvakS52fCGz3eI3+mSC4r/KV2ijkXdT2DtDneilspVHulGiV1mUCEjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=sIQdYWaf; arc=none smtp.client-ip=99.78.197.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="sIQdYWaf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1742340822; x=1773876822; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zHdrhA84cT2wMsuUQcJO68Uox7pkf0x7wVsIXQHeaRk=; b=sIQdYWafeQNScPyEIABQwadWNgl+6zIMSg6iE6lOJZ7LbozBIXVlV9ab nXotTySn8qliy3YJ0Aybo9AbjbElVGE41CRYRIuF+NU3S/+b9UhYmE6tZ Nkdu2m1oYVhoMpnG0FGmUA59ODTKZmHNaVgX/P0XqrRuXRx1RM920ZwSb A=; X-IronPort-AV: E=Sophos;i="6.14,258,1736812800"; d="scan'208";a="183070011" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80009.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 23:33:41 +0000 Received: from EX19MTAUWC002.ant.amazon.com [10.0.21.151:55518] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.40.101:2525] with esmtp (Farcaster) id 25be4672-0854-4322-88b4-242c86a10a1b; Tue, 18 Mar 2025 23:33:40 +0000 (UTC) X-Farcaster-Flow-ID: 25be4672-0854-4322-88b4-242c86a10a1b Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Tue, 18 Mar 2025 23:33:40 +0000 Received: from 6c7e67bfbae3.amazon.com (10.135.212.115) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Tue, 18 Mar 2025 23:33:38 +0000 From: Kuniyuki Iwashima To: David Ahern , "David S. Miller" , Eric Dumazet , Jakub Kicinski , "Paolo Abeni" CC: Simon Horman , Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 2/7] nexthop: Split nh_check_attr_group(). Date: Tue, 18 Mar 2025 16:31:45 -0700 Message-ID: <20250318233240.53946-3-kuniyu@amazon.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318233240.53946-1-kuniyu@amazon.com> References: <20250318233240.53946-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D036UWC003.ant.amazon.com (10.13.139.214) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org We will push RTNL down to rtm_new_nexthop(), and then we want to move non-RTNL operations out of the scope. nh_check_attr_group() validates NHA_GROUP attributes, and some validation requires RTNL. Let's factorise such parts as nh_check_attr_group_rtnl() and call it from rtm_to_nh_config_rtnl(). Signed-off-by: Kuniyuki Iwashima --- net/ipv4/nexthop.c | 68 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 487933ecdb68..98d5bf6e40f9 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -1272,10 +1272,8 @@ static int nh_check_attr_group(struct net *net, u16 nh_grp_type, struct netlink_ext_ack *extack) { unsigned int len = nla_len(tb[NHA_GROUP]); - u8 nh_family = AF_UNSPEC; struct nexthop_grp *nhg; unsigned int i, j; - u8 nhg_fdb = 0; if (!len || len & (sizeof(struct nexthop_grp) - 1)) { NL_SET_ERR_MSG(extack, @@ -1307,10 +1305,41 @@ static int nh_check_attr_group(struct net *net, } } - if (tb[NHA_FDB]) - nhg_fdb = 1; nhg = nla_data(tb[NHA_GROUP]); - for (i = 0; i < len; ++i) { + for (i = NHA_GROUP_TYPE + 1; i < tb_size; ++i) { + if (!tb[i]) + continue; + switch (i) { + case NHA_HW_STATS_ENABLE: + case NHA_FDB: + continue; + case NHA_RES_GROUP: + if (nh_grp_type == NEXTHOP_GRP_TYPE_RES) + continue; + break; + } + NL_SET_ERR_MSG(extack, + "No other attributes can be set in nexthop groups"); + return -EINVAL; + } + + return 0; +} + +static int nh_check_attr_group_rtnl(struct net *net, struct nlattr *tb[], + struct netlink_ext_ack *extack) +{ + u8 nh_family = AF_UNSPEC; + struct nexthop_grp *nhg; + unsigned int len; + unsigned int i; + u8 nhg_fdb; + + len = nla_len(tb[NHA_GROUP]) / sizeof(*nhg); + nhg = nla_data(tb[NHA_GROUP]); + nhg_fdb = !!tb[NHA_FDB]; + + for (i = 0; i < len; i++) { struct nexthop *nh; bool is_fdb_nh; @@ -1330,22 +1359,6 @@ static int nh_check_attr_group(struct net *net, return -EINVAL; } } - for (i = NHA_GROUP_TYPE + 1; i < tb_size; ++i) { - if (!tb[i]) - continue; - switch (i) { - case NHA_HW_STATS_ENABLE: - case NHA_FDB: - continue; - case NHA_RES_GROUP: - if (nh_grp_type == NEXTHOP_GRP_TYPE_RES) - continue; - break; - } - NL_SET_ERR_MSG(extack, - "No other attributes can be set in nexthop groups"); - return -EINVAL; - } return 0; } @@ -3202,6 +3215,15 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, return err; } +static int rtm_to_nh_config_rtnl(struct net *net, struct nlattr **tb, + struct netlink_ext_ack *extack) +{ + if (tb[NHA_GROUP]) + return nh_check_attr_group_rtnl(net, tb, extack); + + return 0; +} + /* rtnl */ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) @@ -3222,6 +3244,10 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, if (err) goto out; + err = rtm_to_nh_config_rtnl(net, tb, extack); + if (!err) + goto out; + nh = nexthop_add(net, &cfg, extack); if (IS_ERR(nh)) err = PTR_ERR(nh); From patchwork Tue Mar 18 23:31:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 14021736 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0D201F7076 for ; Tue, 18 Mar 2025 23:34:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=207.171.184.29 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742340860; cv=none; b=uExkWxcAvPzZSri/VSgJJEQaeyWR7e3zcKjpjBQ9f1tBexly7suIfc4ai24ufzOafZ1o6pgvNWPLQVV334swYjyYDxRfGHaHtiEVeF38j6XADCZChFSpnfYTxMd5QuMaTLbz3ptFy53x6lTr236AzI9hhBUB2F1vIrOU6Fd7hEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742340860; c=relaxed/simple; bh=Xw1EDqYTOuFHL3tUea4us5d+i3GgyPq9S/VPmxZpKPs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bWdU0jtQNciy7MwaPugfXfeZScZvKHKWd2HZf+ikt60GRsTqph9ANd5vq5U6ST7HqscnQhe027tbb8N0zQLhB/954qRa7e6vTesuV6Y2xA/YdUifzfWruOm/P6O5ACynoqYACqaWnKwfqJoay672ebo0OWZssc30OHQIzgmeF4w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=qywkkKqZ; arc=none smtp.client-ip=207.171.184.29 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="qywkkKqZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1742340858; x=1773876858; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IkT2t+NOEPW9yk/cgUHnNUV2NbBfVjQj/ws2g04pW3I=; b=qywkkKqZYZaAChmsA5McZsyliEoNPTOK4P2165BUUfMDFteCwI8bPbdC 9q8q7X0/8ig2kVK18eMsW31Jklxms0pP0VPA2eiETzlefj7G7/835pcRT EUpT9N50XsZ3U9R7mkIR8UibQ72AZcY5VzehjOIe0sp9CwDqCiZz7TkX4 E=; X-IronPort-AV: E=Sophos;i="6.14,258,1736812800"; d="scan'208";a="503926994" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-9102.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 23:34:11 +0000 Received: from EX19MTAUWA002.ant.amazon.com [10.0.21.151:21222] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.58.39:2525] with esmtp (Farcaster) id 8fc47406-65aa-4c76-bc9d-b95497fde948; Tue, 18 Mar 2025 23:34:11 +0000 (UTC) X-Farcaster-Flow-ID: 8fc47406-65aa-4c76-bc9d-b95497fde948 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Tue, 18 Mar 2025 23:34:04 +0000 Received: from 6c7e67bfbae3.amazon.com (10.135.212.115) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Tue, 18 Mar 2025 23:34:01 +0000 From: Kuniyuki Iwashima To: David Ahern , "David S. Miller" , Eric Dumazet , Jakub Kicinski , "Paolo Abeni" CC: Simon Horman , Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 3/7] nexthop: Move NHA_OIF validation to rtm_to_nh_config_rtnl(). Date: Tue, 18 Mar 2025 16:31:46 -0700 Message-ID: <20250318233240.53946-4-kuniyu@amazon.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318233240.53946-1-kuniyu@amazon.com> References: <20250318233240.53946-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D035UWB002.ant.amazon.com (10.13.138.97) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org NHA_OIF needs to look up a device by __dev_get_by_index(), which requires RTNL. Let's move NHA_OIF validation to rtm_to_nh_config_rtnl(). Note that the proceeding checks made the original !cfg->nh_fdb check redundant. NHA_FDB is set -> NHA_OIF cannot be set NHA_FDB is set but false -> NHA_OIF must be set NHA_FDB is not set -> NHA_OIF must be set Signed-off-by: Kuniyuki Iwashima --- net/ipv4/nexthop.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 98d5bf6e40f9..f21ea1ddd68f 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -3134,25 +3134,6 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, goto out; } - if (!cfg->nh_fdb && tb[NHA_OIF]) { - cfg->nh_ifindex = nla_get_u32(tb[NHA_OIF]); - if (cfg->nh_ifindex) - cfg->dev = __dev_get_by_index(net, cfg->nh_ifindex); - - if (!cfg->dev) { - NL_SET_ERR_MSG(extack, "Invalid device index"); - goto out; - } else if (!(cfg->dev->flags & IFF_UP)) { - NL_SET_ERR_MSG(extack, "Nexthop device is not up"); - err = -ENETDOWN; - goto out; - } else if (!netif_carrier_ok(cfg->dev)) { - NL_SET_ERR_MSG(extack, "Carrier for nexthop device is down"); - err = -ENETDOWN; - goto out; - } - } - err = -EINVAL; if (tb[NHA_GATEWAY]) { struct nlattr *gwa = tb[NHA_GATEWAY]; @@ -3216,11 +3197,33 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, } static int rtm_to_nh_config_rtnl(struct net *net, struct nlattr **tb, + struct nh_config *cfg, struct netlink_ext_ack *extack) { if (tb[NHA_GROUP]) return nh_check_attr_group_rtnl(net, tb, extack); + if (tb[NHA_OIF]) { + cfg->nh_ifindex = nla_get_u32(tb[NHA_OIF]); + if (cfg->nh_ifindex) + cfg->dev = __dev_get_by_index(net, cfg->nh_ifindex); + + if (!cfg->dev) { + NL_SET_ERR_MSG(extack, "Invalid device index"); + return -EINVAL; + } + + if (!(cfg->dev->flags & IFF_UP)) { + NL_SET_ERR_MSG(extack, "Nexthop device is not up"); + return -ENETDOWN; + } + + if (!netif_carrier_ok(cfg->dev)) { + NL_SET_ERR_MSG(extack, "Carrier for nexthop device is down"); + return -ENETDOWN; + } + } + return 0; } @@ -3244,7 +3247,7 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, if (err) goto out; - err = rtm_to_nh_config_rtnl(net, tb, extack); + err = rtm_to_nh_config_rtnl(net, tb, &cfg, extack); if (!err) goto out; From patchwork Tue Mar 18 23:31:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 14021737 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52002.amazon.com (smtp-fw-52002.amazon.com [52.119.213.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16F951F7076 for ; Tue, 18 Mar 2025 23:34:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742340872; cv=none; b=NXGL5SgPHR361Pp4/URTinRXypqdsANzpCEPE/vOR8XHWUsjgg7MM2JKGefBD/K4oaw+oBhPSd9lY5+ukqAkygZwRqT95yY6ugFL1+wSe5IyhN862IHQL5ENYShdevygEgV/PDcckm5qHieyB+/tWa6kDgPWgLzk+4meJumVBKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742340872; c=relaxed/simple; bh=j/sk7MslS7mFqzEh7zsg5n06Y1dgeBPY3a8mqGL6Ybg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uGYNwojlWfskws9Ivsg4h2JdZ7eJWfwOkYDro9Rr+Uo71i84QEbQYmib8OCrUFg8NTPxQ89bl+oHDt2pXlXLQhkjeRJUO8b1+jFVnSZ7r4tlP2hJkSD+fTwIZNo15kT1XCK8gt26UFac+JQEEjBej60OUtAw7e2TwMLuBAOSdyE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=dB+T7DEi; arc=none smtp.client-ip=52.119.213.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="dB+T7DEi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1742340871; x=1773876871; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p7EqmJziqjK9CoE1bau4jFoNDoLB/P9K//h96cMEfAU=; b=dB+T7DEi4CazBSs9ou8zG0AAfLtB+ZLyUpPPhP5ZkM/jIkEj2uJsRHQH qfG0si/0Sj3KZHOwpqq9tarhJ6qWGetowlorY3LSvwqIhuHmSHWVLXl3f scDoT/lZEmG2TEyhLZWkj+TQ7GmRPhabDJtJEJSrhrcLf0jQTeQJD6Usb c=; X-IronPort-AV: E=Sophos;i="6.14,258,1736812800"; d="scan'208";a="706166550" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-52002.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 23:34:29 +0000 Received: from EX19MTAUWB001.ant.amazon.com [10.0.38.20:25467] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.62.245:2525] with esmtp (Farcaster) id aae482d8-60f8-4e0f-8a61-c1a1d91ea4ff; Tue, 18 Mar 2025 23:34:29 +0000 (UTC) X-Farcaster-Flow-ID: aae482d8-60f8-4e0f-8a61-c1a1d91ea4ff Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB001.ant.amazon.com (10.250.64.248) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Tue, 18 Mar 2025 23:34:28 +0000 Received: from 6c7e67bfbae3.amazon.com (10.135.212.115) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Tue, 18 Mar 2025 23:34:26 +0000 From: Kuniyuki Iwashima To: David Ahern , "David S. Miller" , Eric Dumazet , Jakub Kicinski , "Paolo Abeni" CC: Simon Horman , Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 4/7] nexthop: Check NLM_F_REPLACE and NHA_ID in rtm_new_nexthop(). Date: Tue, 18 Mar 2025 16:31:47 -0700 Message-ID: <20250318233240.53946-5-kuniyu@amazon.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318233240.53946-1-kuniyu@amazon.com> References: <20250318233240.53946-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D035UWB004.ant.amazon.com (10.13.138.104) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org nexthop_add() checks if NLM_F_REPLACE is specified without non-zero NHA_ID, which does not require RTNL. Let's move the check to rtm_new_nexthop(). Signed-off-by: Kuniyuki Iwashima --- net/ipv4/nexthop.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index f21ea1ddd68f..09f5f31f34a0 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -2928,11 +2928,6 @@ static struct nexthop *nexthop_add(struct net *net, struct nh_config *cfg, struct nexthop *nh; int err; - if (cfg->nlflags & NLM_F_REPLACE && !cfg->nh_id) { - NL_SET_ERR_MSG(extack, "Replace requires nexthop id"); - return ERR_PTR(-EINVAL); - } - if (!cfg->nh_id) { cfg->nh_id = nh_find_unused_id(net); if (!cfg->nh_id) { @@ -3247,6 +3242,12 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, if (err) goto out; + if (cfg.nlflags & NLM_F_REPLACE && !cfg.nh_id) { + NL_SET_ERR_MSG(extack, "Replace requires nexthop id"); + err = -EINVAL; + goto out; + } + err = rtm_to_nh_config_rtnl(net, tb, &cfg, extack); if (!err) goto out; From patchwork Tue Mar 18 23:31:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 14021738 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21CF11F7076 for ; Tue, 18 Mar 2025 23:34:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.95.49.90 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742340897; cv=none; b=WsEJSuTp50IhIi45nmCmr7UCmjFkngfRX1nNL2L7gWQwAJ67qZzGR67Xfm6BZ5jvcuLrLts+cpHxASzbch6mcLUCXSFPHcxkzYXLQT6T3HrvfkEVwS4tXW6mdypCqfQZDF7HIchpel63Xc6gHp6RzdYAiBDUs+0o3XtBlOCpI5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742340897; c=relaxed/simple; bh=Rid7cLLB3tLlup+VYdRfGQ+vEUhD98T2Bk9MEslMFh4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SPHmF1HI249alfNXT5aOpE4/5N6gkggBQlIIIoCmgONlY1H7vbEp/8VlvMKzGOGCC+kFTOBi3++WnHqHQEb0drF4V76via6Hh52+dUKkm29QwZW85Rai0xCgp+9GZWT/Yord3lScbOzoMD8Kn29dXEdRQnzAGnPD7ZX4+eVjxY4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=vgv4aFmV; arc=none smtp.client-ip=52.95.49.90 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="vgv4aFmV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1742340896; x=1773876896; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=trSspWxDMxD+GsX7d9lbyC5sGqeOld+2ndIYdMFdr3M=; b=vgv4aFmVQGTM+mXn9LF8knwVnM9cZdvQNjkYxe/7x/L+hNnuF9yRevxA E1/gXvBaW1FPmTB4HT3NTEINsra1bWUQZWYbJvwOBjaoKGsIkw2sU0LSf i5rO5vEoBotPtOZxsG/0sj3H1J4rE55Lw4Ju03r9eAjAEDkUlKCcI96Uu M=; X-IronPort-AV: E=Sophos;i="6.14,258,1736812800"; d="scan'208";a="481547199" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-6002.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 23:34:53 +0000 Received: from EX19MTAUWC001.ant.amazon.com [10.0.38.20:34008] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.22.127:2525] with esmtp (Farcaster) id f2716520-2d20-4867-b36c-ea32e53f8cf4; Tue, 18 Mar 2025 23:34:52 +0000 (UTC) X-Farcaster-Flow-ID: f2716520-2d20-4867-b36c-ea32e53f8cf4 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Tue, 18 Mar 2025 23:34:52 +0000 Received: from 6c7e67bfbae3.amazon.com (10.135.212.115) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Tue, 18 Mar 2025 23:34:49 +0000 From: Kuniyuki Iwashima To: David Ahern , "David S. Miller" , Eric Dumazet , Jakub Kicinski , "Paolo Abeni" CC: Simon Horman , Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 5/7] nexthop: Remove redundant group len check in nexthop_create_group(). Date: Tue, 18 Mar 2025 16:31:48 -0700 Message-ID: <20250318233240.53946-6-kuniyu@amazon.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318233240.53946-1-kuniyu@amazon.com> References: <20250318233240.53946-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D037UWB003.ant.amazon.com (10.13.138.115) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org The number of NHA_GROUP entries is guaranteed to be non-zero in nh_check_attr_group(). Let's remove the redundant check in nexthop_create_group(). Signed-off-by: Kuniyuki Iwashima --- net/ipv4/nexthop.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 09f5f31f34a0..409f13d64ed4 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -2692,9 +2692,6 @@ static struct nexthop *nexthop_create_group(struct net *net, int err; int i; - if (WARN_ON(!num_nh)) - return ERR_PTR(-EINVAL); - nh = nexthop_alloc(); if (!nh) return ERR_PTR(-ENOMEM); From patchwork Tue Mar 18 23:31:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 14021739 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80008.amazon.com (smtp-fw-80008.amazon.com [99.78.197.219]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B86A207649 for ; Tue, 18 Mar 2025 23:35:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742340920; cv=none; b=V/Q7GuWPsw/YZP5h0zhKiIiFfnkdtQhXLMpRG3sQCSjK114LoujjOM60jyc9jOkra/mJbzdHJtKbqzTsBwJh5of5EtAe+h63wYBStRZJcJ3tcaAe/OpNS1CPEYRQmq6FpQsDJi6DwS3pB192d22/Dj9qyFUeaLZ8LaavYh4vCr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742340920; c=relaxed/simple; bh=ddUSUo6k/KwRkL6XKbIbIvMULYgm2LOTl/6DJtFMpC4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oRq7LAiOgU6yLfmYQeuhKrzWj87mXcmAxZagsOkQ/Pj5Kd+VTOsaqZcj1wGMRoSdqxINYb48qtIamx4Xh6zbT2Oc6wYSeDAvGHkoYYboh/ODGzGKpHdHtHUH1C7Vp+S65vbKkSYaG9XdaxpwK0AVIph9mzPoAQD/MqI/DvSg2d0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=lc8aImgz; arc=none smtp.client-ip=99.78.197.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="lc8aImgz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1742340919; x=1773876919; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1QJUdUvB0Zqw8+oT2He2sFBsFvqtkfTr0kewt07t1H8=; b=lc8aImgzfR70Uwlq4CI8vKiEJhINuijkXY0ZpuYdos5zULNl0RzOS7in e1p/GVM9ax4+1Fy7tx3h5A83K+lHZiX7Soxp4ewbNBC7wjQAnLnpWhuHQ uEVd+MGA3M5kocZfOifCM0Lt4YViY+rS8r0XR5td3q6iII6jvE8R0hFUI Q=; X-IronPort-AV: E=Sophos;i="6.14,258,1736812800"; d="scan'208";a="179801682" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80008.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 23:35:16 +0000 Received: from EX19MTAUWB002.ant.amazon.com [10.0.7.35:29127] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.40.40:2525] with esmtp (Farcaster) id 9d6e4900-ed01-4137-ab6e-ccac72378cd4; Tue, 18 Mar 2025 23:35:16 +0000 (UTC) X-Farcaster-Flow-ID: 9d6e4900-ed01-4137-ab6e-ccac72378cd4 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Tue, 18 Mar 2025 23:35:16 +0000 Received: from 6c7e67bfbae3.amazon.com (10.135.212.115) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Tue, 18 Mar 2025 23:35:13 +0000 From: Kuniyuki Iwashima To: David Ahern , "David S. Miller" , Eric Dumazet , Jakub Kicinski , "Paolo Abeni" CC: Simon Horman , Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 6/7] nexthop: Convert RTM_NEWNEXTHOP to per-netns RTNL. Date: Tue, 18 Mar 2025 16:31:49 -0700 Message-ID: <20250318233240.53946-7-kuniyu@amazon.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318233240.53946-1-kuniyu@amazon.com> References: <20250318233240.53946-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D042UWA004.ant.amazon.com (10.13.139.16) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org If we pass false to the rtnl_held param of lwtunnel_valid_encap_type(), we can move RTNL down before rtm_to_nh_config_rtnl(). Let's use rtnl_net_lock() in rtm_new_nexthop(). Signed-off-by: Kuniyuki Iwashima --- net/ipv4/nexthop.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 409f13d64ed4..ea62454e0a0c 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -3169,7 +3169,7 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, cfg->nh_encap_type = nla_get_u16(tb[NHA_ENCAP_TYPE]); err = lwtunnel_valid_encap_type(cfg->nh_encap_type, - extack, true); + extack, false); if (err < 0) goto out; @@ -3245,13 +3245,18 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, goto out; } + rtnl_net_lock(net); + err = rtm_to_nh_config_rtnl(net, tb, &cfg, extack); if (!err) - goto out; + goto unlock; nh = nexthop_add(net, &cfg, extack); if (IS_ERR(nh)) err = PTR_ERR(nh); + +unlock: + rtnl_net_unlock(net); out: return err; } @@ -4067,18 +4072,19 @@ static struct pernet_operations nexthop_net_ops = { }; static const struct rtnl_msg_handler nexthop_rtnl_msg_handlers[] __initconst = { - {.msgtype = RTM_NEWNEXTHOP, .doit = rtm_new_nexthop}, + {.msgtype = RTM_NEWNEXTHOP, .doit = rtm_new_nexthop, + .flags = RTNL_FLAG_DOIT_PERNET}, {.msgtype = RTM_DELNEXTHOP, .doit = rtm_del_nexthop}, {.msgtype = RTM_GETNEXTHOP, .doit = rtm_get_nexthop, .dumpit = rtm_dump_nexthop}, {.msgtype = RTM_GETNEXTHOPBUCKET, .doit = rtm_get_nexthop_bucket, .dumpit = rtm_dump_nexthop_bucket}, {.protocol = PF_INET, .msgtype = RTM_NEWNEXTHOP, - .doit = rtm_new_nexthop}, + .doit = rtm_new_nexthop, .flags = RTNL_FLAG_DOIT_PERNET}, {.protocol = PF_INET, .msgtype = RTM_GETNEXTHOP, .dumpit = rtm_dump_nexthop}, {.protocol = PF_INET6, .msgtype = RTM_NEWNEXTHOP, - .doit = rtm_new_nexthop}, + .doit = rtm_new_nexthop, .flags = RTNL_FLAG_DOIT_PERNET}, {.protocol = PF_INET6, .msgtype = RTM_GETNEXTHOP, .dumpit = rtm_dump_nexthop}, }; From patchwork Tue Mar 18 23:31:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 14021740 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65A402080FB for ; Tue, 18 Mar 2025 23:35:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742340947; cv=none; b=c5C7U9aEkiTPvyN2kcGiPeK339r4mnRdb4rsgMhbMRabtP2vLJKNv+Cm5uD5/M9CJ5mHqq6HnmxUTM5sVWsDQpQVNAHxPxbLfSDW9ngf9C8ufQbOLpQ8YbNQPZXlYU5nngV+wqufbbJxBvMaGI53w0A1ra76PKaHX+cb0yljAZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742340947; c=relaxed/simple; bh=82BAcFJ1uV8GF3R5nNpvUyY1LZ4+B4SpwleyGbJoFGM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j/6rgnoF84J28Z6FTNo6D5dVNS60Tpz1gIi8oWVfAp/DR/rr9UkJg+Z8qlKJH2FwFCMXMXJ0Wm+Dt3R12wlzs/saNWwFDdkVPR4gNIHF9SG5icasiR/jvkpwuVxHsbbM9CamQGpFJ1cOaX8THqCGYy2TzOzT+gZhBVGSWteeZgc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=pnC9gyar; arc=none smtp.client-ip=52.119.213.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="pnC9gyar" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1742340945; x=1773876945; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=swg7IjG+TErjkoFAu6DgewpwfsJgarMsY8qYR9KCcBA=; b=pnC9gyarPL3xCMUu6advkZfKUS7VBLrAf7SnJ/gRfX/jX/9qvLME38vB zXOSSvksOgEIGeLVRTtleqX6hH/k3U6k0udlfGrtSAjUxoAk5Fyb7y5RE PZ0qrgvpVBJuiuJc+RksJ7ff0tb6NSjdv1jBr0yenyWnfhavA83Y3xF+H A=; X-IronPort-AV: E=Sophos;i="6.14,258,1736812800"; d="scan'208";a="280531422" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 23:35:41 +0000 Received: from EX19MTAUWA002.ant.amazon.com [10.0.21.151:54467] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.52.235:2525] with esmtp (Farcaster) id 8f45bd48-2be1-495d-85de-e5bc6a0ac22c; Tue, 18 Mar 2025 23:35:40 +0000 (UTC) X-Farcaster-Flow-ID: 8f45bd48-2be1-495d-85de-e5bc6a0ac22c Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Tue, 18 Mar 2025 23:35:40 +0000 Received: from 6c7e67bfbae3.amazon.com (10.135.212.115) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Tue, 18 Mar 2025 23:35:37 +0000 From: Kuniyuki Iwashima To: David Ahern , "David S. Miller" , Eric Dumazet , Jakub Kicinski , "Paolo Abeni" CC: Simon Horman , Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 7/7] nexthop: Convert RTM_DELNEXTHOP to per-netns RTNL. Date: Tue, 18 Mar 2025 16:31:50 -0700 Message-ID: <20250318233240.53946-8-kuniyu@amazon.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318233240.53946-1-kuniyu@amazon.com> References: <20250318233240.53946-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D036UWB002.ant.amazon.com (10.13.139.139) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org In rtm_del_nexthop(), only nexthop_find_by_id() and remove_nexthop() require RTNL as they touch net->nexthop.rb_root. Let's move RTNL down as rtnl_net_lock() before nexthop_find_by_id(). Signed-off-by: Kuniyuki Iwashima --- net/ipv4/nexthop.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index ea62454e0a0c..66d7796ba174 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -3314,13 +3314,17 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, if (err) return err; + rtnl_net_lock(net); + nh = nexthop_find_by_id(net, id); - if (!nh) - return -ENOENT; + if (nh) + remove_nexthop(net, nh, &nlinfo); + else + err = -ENOENT; - remove_nexthop(net, nh, &nlinfo); + rtnl_net_unlock(net); - return 0; + return err; } /* rtnl */ @@ -4074,7 +4078,8 @@ static struct pernet_operations nexthop_net_ops = { static const struct rtnl_msg_handler nexthop_rtnl_msg_handlers[] __initconst = { {.msgtype = RTM_NEWNEXTHOP, .doit = rtm_new_nexthop, .flags = RTNL_FLAG_DOIT_PERNET}, - {.msgtype = RTM_DELNEXTHOP, .doit = rtm_del_nexthop}, + {.msgtype = RTM_DELNEXTHOP, .doit = rtm_del_nexthop, + .flags = RTNL_FLAG_DOIT_PERNET}, {.msgtype = RTM_GETNEXTHOP, .doit = rtm_get_nexthop, .dumpit = rtm_dump_nexthop}, {.msgtype = RTM_GETNEXTHOPBUCKET, .doit = rtm_get_nexthop_bucket,