phonet: no longer hold RTNL in route_dumpit()
BugLink: https://bugs.launchpad.net/bugs/2097393 [ Upstream commit 58a4ff5d77b187086eb12d41d613749420947f19 ] route_dumpit() already relies on RCU, RTNL is not needed. Also change return value at the end of a dump. This allows NLMSG_DONE to be appended to the current skb at the end of a dump, saving a couple of recvmsg() system calls. Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Remi Denis-Courmont <courmisch@gmail.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://lore.kernel.org/r/20240507121748.416287-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Stable-dep-of: b5e837c86041 ("phonet: Handle error of rtnl_register_module().") Signed-off-by: Sasha Levin <sashal@kernel.org> [diewald: adjusted because we already applied follow-up commit b5e837c86041b phonet: Handle error of rtnl_register_module().] Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com> Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
This commit is contained in:
committed by
Mehmet Basaran
parent
e9dd6b5c8c
commit
c7b39dd160
@@ -178,7 +178,7 @@ static int fill_route(struct sk_buff *skb, struct net_device *dev, u8 dst,
|
||||
rtm->rtm_type = RTN_UNICAST;
|
||||
rtm->rtm_flags = 0;
|
||||
if (nla_put_u8(skb, RTA_DST, dst) ||
|
||||
nla_put_u32(skb, RTA_OIF, dev->ifindex))
|
||||
nla_put_u32(skb, RTA_OIF, READ_ONCE(dev->ifindex)))
|
||||
goto nla_put_failure;
|
||||
nlmsg_end(skb, nlh);
|
||||
return 0;
|
||||
@@ -263,6 +263,7 @@ static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
|
||||
static int route_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
|
||||
{
|
||||
struct net *net = sock_net(skb->sk);
|
||||
int err = 0;
|
||||
u8 addr;
|
||||
|
||||
rcu_read_lock();
|
||||
@@ -272,16 +273,16 @@ static int route_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
|
||||
if (!dev)
|
||||
continue;
|
||||
|
||||
if (fill_route(skb, dev, addr << 2, NETLINK_CB(cb->skb).portid,
|
||||
cb->nlh->nlmsg_seq, RTM_NEWROUTE) < 0)
|
||||
goto out;
|
||||
err = fill_route(skb, dev, addr << 2,
|
||||
NETLINK_CB(cb->skb).portid,
|
||||
cb->nlh->nlmsg_seq, RTM_NEWROUTE);
|
||||
if (err < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
out:
|
||||
rcu_read_unlock();
|
||||
cb->args[0] = addr;
|
||||
|
||||
return skb->len;
|
||||
return err;
|
||||
}
|
||||
|
||||
static const struct rtnl_msg_handler phonet_rtnl_msg_handlers[] __initdata_or_module = {
|
||||
@@ -291,7 +292,7 @@ static const struct rtnl_msg_handler phonet_rtnl_msg_handlers[] __initdata_or_mo
|
||||
{THIS_MODULE, PF_PHONET, RTM_NEWROUTE, route_doit, NULL, 0},
|
||||
{THIS_MODULE, PF_PHONET, RTM_DELROUTE, route_doit, NULL, 0},
|
||||
{THIS_MODULE, PF_PHONET, RTM_GETROUTE, NULL, route_dumpit,
|
||||
0},
|
||||
RTNL_FLAG_DUMP_UNLOCKED},
|
||||
};
|
||||
|
||||
int __init phonet_netlink_register(void)
|
||||
|
||||
Reference in New Issue
Block a user