mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	ipv4: fib: Convert RTM_NEWROUTE and RTM_DELROUTE to per-netns RTNL.
We converted fib_info hash tables to per-netns one and now ready to convert RTM_NEWROUTE and RTM_DELROUTE to per-netns RTNL. Let's hold rtnl_net_lock() in inet_rtm_newroute() and inet_rtm_delroute(). Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Reviewed-by: David Ahern <dsahern@kernel.org> Link: https://patch.msgid.link/20250228042328.96624-13-kuniyu@amazon.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
		
							parent
							
								
									254ba7e603
								
							
						
					
					
						commit
						1dd2af7963
					
				
					 1 changed files with 14 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -884,20 +884,24 @@ static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh,
 | 
			
		|||
	if (err < 0)
 | 
			
		||||
		goto errout;
 | 
			
		||||
 | 
			
		||||
	rtnl_net_lock(net);
 | 
			
		||||
 | 
			
		||||
	if (cfg.fc_nh_id && !nexthop_find_by_id(net, cfg.fc_nh_id)) {
 | 
			
		||||
		NL_SET_ERR_MSG(extack, "Nexthop id does not exist");
 | 
			
		||||
		err = -EINVAL;
 | 
			
		||||
		goto errout;
 | 
			
		||||
		goto unlock;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tb = fib_get_table(net, cfg.fc_table);
 | 
			
		||||
	if (!tb) {
 | 
			
		||||
		NL_SET_ERR_MSG(extack, "FIB table does not exist");
 | 
			
		||||
		err = -ESRCH;
 | 
			
		||||
		goto errout;
 | 
			
		||||
		goto unlock;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = fib_table_delete(net, tb, &cfg, extack);
 | 
			
		||||
unlock:
 | 
			
		||||
	rtnl_net_unlock(net);
 | 
			
		||||
errout:
 | 
			
		||||
	return err;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -914,15 +918,20 @@ static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
 | 
			
		|||
	if (err < 0)
 | 
			
		||||
		goto errout;
 | 
			
		||||
 | 
			
		||||
	rtnl_net_lock(net);
 | 
			
		||||
 | 
			
		||||
	tb = fib_new_table(net, cfg.fc_table);
 | 
			
		||||
	if (!tb) {
 | 
			
		||||
		err = -ENOBUFS;
 | 
			
		||||
		goto errout;
 | 
			
		||||
		goto unlock;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = fib_table_insert(net, tb, &cfg, extack);
 | 
			
		||||
	if (!err && cfg.fc_type == RTN_LOCAL)
 | 
			
		||||
		net->ipv4.fib_has_custom_local_routes = true;
 | 
			
		||||
 | 
			
		||||
unlock:
 | 
			
		||||
	rtnl_net_unlock(net);
 | 
			
		||||
errout:
 | 
			
		||||
	return err;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1683,9 +1692,9 @@ static struct pernet_operations fib_net_ops = {
 | 
			
		|||
 | 
			
		||||
static const struct rtnl_msg_handler fib_rtnl_msg_handlers[] __initconst = {
 | 
			
		||||
	{.protocol = PF_INET, .msgtype = RTM_NEWROUTE,
 | 
			
		||||
	 .doit = inet_rtm_newroute},
 | 
			
		||||
	 .doit = inet_rtm_newroute, .flags = RTNL_FLAG_DOIT_PERNET},
 | 
			
		||||
	{.protocol = PF_INET, .msgtype = RTM_DELROUTE,
 | 
			
		||||
	 .doit = inet_rtm_delroute},
 | 
			
		||||
	 .doit = inet_rtm_delroute, .flags = RTNL_FLAG_DOIT_PERNET},
 | 
			
		||||
	{.protocol = PF_INET, .msgtype = RTM_GETROUTE, .dumpit = inet_dump_fib,
 | 
			
		||||
	 .flags = RTNL_FLAG_DUMP_UNLOCKED | RTNL_FLAG_DUMP_SPLIT_NLM_DONE},
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue