From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>, <netdev@vger.kernel.org>
Subject: [PATCH v1 net-next 6/6] fib: rules: Convert RTM_DELRULE to per-netns RTNL.
Date: Thu, 6 Feb 2025 17:46:29 +0900 [thread overview]
Message-ID: <20250206084629.16602-7-kuniyu@amazon.com> (raw)
In-Reply-To: <20250206084629.16602-1-kuniyu@amazon.com>
fib_nl_delrule() is the doit() handler for RTM_DELRULE but also called
1;95;0cfrom vrf_newlink() in case something fails in vrf_add_fib_rules().
In the latter case, RTNL is already held and the 3rd arg extack is NULL.
Let's hold per-netns RTNL in fib_nl_delrule() if extack is NULL.
Now we can place ASSERT_RTNL_NET() in call_fib_rule_notifiers().
While at it, fib_rule r is moved to the suitable scope.
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
net/core/fib_rules.c | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index cc26c762fa9e..3430d026134d 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -371,7 +371,8 @@ static int call_fib_rule_notifiers(struct net *net,
.rule = rule,
};
- ASSERT_RTNL();
+ ASSERT_RTNL_NET(net);
+
/* Paired with READ_ONCE() in fib_rules_seq() */
WRITE_ONCE(ops->fib_rules_seq, ops->fib_rules_seq + 1);
return call_fib_notifiers(net, event_type, &info.info);
@@ -909,13 +910,13 @@ EXPORT_SYMBOL_GPL(fib_nl_newrule);
int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,
struct netlink_ext_ack *extack)
{
- struct net *net = sock_net(skb->sk);
+ bool user_priority = false, hold_rtnl = !!extack;
+ struct fib_rule *rule = NULL, *nlrule = NULL;
struct fib_rule_hdr *frh = nlmsg_data(nlh);
+ struct net *net = sock_net(skb->sk);
struct fib_rules_ops *ops = NULL;
- struct fib_rule *rule = NULL, *r, *nlrule = NULL;
struct nlattr *tb[FRA_MAX+1];
int err = -EINVAL;
- bool user_priority = false;
if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*frh))) {
NL_SET_ERR_MSG(extack, "Invalid msg length");
@@ -940,6 +941,9 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,
if (err)
goto errout;
+ if (hold_rtnl)
+ rtnl_net_lock(net);
+
err = fib_nl2rule_rtnl(nlrule, ops, tb, extack);
if (err)
goto errout_free;
@@ -980,7 +984,7 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,
* current if it is goto rule, have actually been added.
*/
if (ops->nr_goto_rules > 0) {
- struct fib_rule *n;
+ struct fib_rule *n, *r;
n = list_next_entry(rule, list);
if (&n->list == &ops->rules_list || n->pref != rule->pref)
@@ -994,10 +998,12 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,
}
}
- call_fib_rule_notifiers(net, FIB_EVENT_RULE_DEL, rule, ops,
- NULL);
- notify_rule_change(RTM_DELRULE, rule, ops, nlh,
- NETLINK_CB(skb).portid);
+ call_fib_rule_notifiers(net, FIB_EVENT_RULE_DEL, rule, ops, NULL);
+
+ if (hold_rtnl)
+ rtnl_net_unlock(net);
+
+ notify_rule_change(RTM_DELRULE, rule, ops, nlh, NETLINK_CB(skb).portid);
fib_rule_put(rule);
flush_route_cache(ops);
rules_ops_put(ops);
@@ -1005,6 +1011,8 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,
return 0;
errout_free:
+ if (hold_rtnl)
+ rtnl_net_unlock(net);
kfree(nlrule);
errout:
rules_ops_put(ops);
@@ -1324,7 +1332,8 @@ static struct pernet_operations fib_rules_net_ops = {
static const struct rtnl_msg_handler fib_rules_rtnl_msg_handlers[] __initconst = {
{.msgtype = RTM_NEWRULE, .doit = fib_nl_newrule,
.flags = RTNL_FLAG_DOIT_PERNET},
- {.msgtype = RTM_DELRULE, .doit = fib_nl_delrule},
+ {.msgtype = RTM_DELRULE, .doit = fib_nl_delrule,
+ .flags = RTNL_FLAG_DOIT_PERNET},
{.msgtype = RTM_GETRULE, .dumpit = fib_nl_dumprule,
.flags = RTNL_FLAG_DUMP_UNLOCKED},
};
--
2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2025-02-06 8:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 8:46 [PATCH v1 net-next 0/6] fib: rules: Convert RTM_NEWRULE and RTM_DELRULE to per-netns RTNL Kuniyuki Iwashima
2025-02-06 8:46 ` [PATCH v1 net-next 1/6] fib: rules: Don't check net in rule_exists() and rule_find() Kuniyuki Iwashima
2025-02-06 8:46 ` [PATCH v1 net-next 2/6] fib: rules: Pass net to fib_nl2rule() instead of skb Kuniyuki Iwashima
2025-02-06 8:46 ` [PATCH v1 net-next 3/6] fib: rules: Split fib_nl2rule() Kuniyuki Iwashima
2025-02-06 8:46 ` [PATCH v1 net-next 4/6] fib: rules: Convert RTM_NEWRULE to per-netns RTNL Kuniyuki Iwashima
2025-02-06 8:46 ` [PATCH v1 net-next 5/6] fib: rules: Add error_free label in fib_nl_delrule() Kuniyuki Iwashima
2025-02-06 8:46 ` Kuniyuki Iwashima [this message]
2025-02-06 9:41 ` [PATCH v1 net-next 6/6] fib: rules: Convert RTM_DELRULE to per-netns RTNL Eric Dumazet
2025-02-06 9:52 ` Kuniyuki Iwashima
2025-02-06 11:22 ` Ido Schimmel
2025-02-07 4:12 ` Kuniyuki Iwashima
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250206084629.16602-7-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.