mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	fib: rules: no longer hold RTNL in fib_nl_dumprule()
- fib rules are already RCU protected, RTNL is not needed to get them. - Fix return value at the end of a dump, so that NLMSG_DONE can be appended to current skb, saving one recvmsg() system call. Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: David Ahern <dsahern@kernel.org> Link: https://lore.kernel.org/r/20240411133340.1332796-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
		
							parent
							
								
									195b7fc53c
								
							
						
					
					
						commit
						32affa5578
					
				
					 1 changed files with 9 additions and 8 deletions
				
			
		| 
						 | 
					@ -1142,10 +1142,10 @@ static int fib_nl_dumprule(struct sk_buff *skb, struct netlink_callback *cb)
 | 
				
			||||||
	const struct nlmsghdr *nlh = cb->nlh;
 | 
						const struct nlmsghdr *nlh = cb->nlh;
 | 
				
			||||||
	struct net *net = sock_net(skb->sk);
 | 
						struct net *net = sock_net(skb->sk);
 | 
				
			||||||
	struct fib_rules_ops *ops;
 | 
						struct fib_rules_ops *ops;
 | 
				
			||||||
	int idx = 0, family;
 | 
						int err, idx = 0, family;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (cb->strict_check) {
 | 
						if (cb->strict_check) {
 | 
				
			||||||
		int err = fib_valid_dumprule_req(nlh, cb->extack);
 | 
							err = fib_valid_dumprule_req(nlh, cb->extack);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (err < 0)
 | 
							if (err < 0)
 | 
				
			||||||
			return err;
 | 
								return err;
 | 
				
			||||||
| 
						 | 
					@ -1158,17 +1158,17 @@ static int fib_nl_dumprule(struct sk_buff *skb, struct netlink_callback *cb)
 | 
				
			||||||
		if (ops == NULL)
 | 
							if (ops == NULL)
 | 
				
			||||||
			return -EAFNOSUPPORT;
 | 
								return -EAFNOSUPPORT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		dump_rules(skb, cb, ops);
 | 
							return dump_rules(skb, cb, ops);
 | 
				
			||||||
 | 
					 | 
				
			||||||
		return skb->len;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = 0;
 | 
				
			||||||
	rcu_read_lock();
 | 
						rcu_read_lock();
 | 
				
			||||||
	list_for_each_entry_rcu(ops, &net->rules_ops, list) {
 | 
						list_for_each_entry_rcu(ops, &net->rules_ops, list) {
 | 
				
			||||||
		if (idx < cb->args[0] || !try_module_get(ops->owner))
 | 
							if (idx < cb->args[0] || !try_module_get(ops->owner))
 | 
				
			||||||
			goto skip;
 | 
								goto skip;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (dump_rules(skb, cb, ops) < 0)
 | 
							err = dump_rules(skb, cb, ops);
 | 
				
			||||||
 | 
							if (err < 0)
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		cb->args[1] = 0;
 | 
							cb->args[1] = 0;
 | 
				
			||||||
| 
						 | 
					@ -1178,7 +1178,7 @@ static int fib_nl_dumprule(struct sk_buff *skb, struct netlink_callback *cb)
 | 
				
			||||||
	rcu_read_unlock();
 | 
						rcu_read_unlock();
 | 
				
			||||||
	cb->args[0] = idx;
 | 
						cb->args[0] = idx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return skb->len;
 | 
						return err;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void notify_rule_change(int event, struct fib_rule *rule,
 | 
					static void notify_rule_change(int event, struct fib_rule *rule,
 | 
				
			||||||
| 
						 | 
					@ -1293,7 +1293,8 @@ static int __init fib_rules_init(void)
 | 
				
			||||||
	int err;
 | 
						int err;
 | 
				
			||||||
	rtnl_register(PF_UNSPEC, RTM_NEWRULE, fib_nl_newrule, NULL, 0);
 | 
						rtnl_register(PF_UNSPEC, RTM_NEWRULE, fib_nl_newrule, NULL, 0);
 | 
				
			||||||
	rtnl_register(PF_UNSPEC, RTM_DELRULE, fib_nl_delrule, NULL, 0);
 | 
						rtnl_register(PF_UNSPEC, RTM_DELRULE, fib_nl_delrule, NULL, 0);
 | 
				
			||||||
	rtnl_register(PF_UNSPEC, RTM_GETRULE, NULL, fib_nl_dumprule, 0);
 | 
						rtnl_register(PF_UNSPEC, RTM_GETRULE, NULL, fib_nl_dumprule,
 | 
				
			||||||
 | 
							      RTNL_FLAG_DUMP_UNLOCKED);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = register_pernet_subsys(&fib_rules_net_ops);
 | 
						err = register_pernet_subsys(&fib_rules_net_ops);
 | 
				
			||||||
	if (err < 0)
 | 
						if (err < 0)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue