Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ipv6: Move some validation from ip6_route_info_create() to rtm_to_fib6_config().

ip6_route_info_create() is called from 3 functions:

* ip6_route_add()
* ip6_route_multipath_add()
* addrconf_f6i_alloc()

addrconf_f6i_alloc() does not need validation for struct fib6_config in
ip6_route_info_create().

ip6_route_multipath_add() calls ip6_route_info_create() for multiple
routes with slightly different fib6_config instances, which is copied
from the base config passed from userspace. So, we need not validate
the same config repeatedly.

Let's move such validation into rtm_to_fib6_config().

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Acked-by: Paolo Abeni <pabeni@redhat.com>
Link: https://patch.msgid.link/20250418000443.43734-4-kuniyu@amazon.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Kuniyuki Iwashima and committed by
Paolo Abeni
fa76c167 bd11ff42

+42 -37
+42 -37
net/ipv6/route.c
··· 3740 3740 int err = -EINVAL; 3741 3741 int addr_type; 3742 3742 3743 - /* RTF_PCPU is an internal flag; can not be set by userspace */ 3744 - if (cfg->fc_flags & RTF_PCPU) { 3745 - NL_SET_ERR_MSG(extack, "Userspace can not set RTF_PCPU"); 3746 - goto out; 3747 - } 3748 - 3749 - /* RTF_CACHE is an internal flag; can not be set by userspace */ 3750 - if (cfg->fc_flags & RTF_CACHE) { 3751 - NL_SET_ERR_MSG(extack, "Userspace can not set RTF_CACHE"); 3752 - goto out; 3753 - } 3754 - 3755 - if (cfg->fc_type > RTN_MAX) { 3756 - NL_SET_ERR_MSG(extack, "Invalid route type"); 3757 - goto out; 3758 - } 3759 - 3760 - if (cfg->fc_dst_len > 128) { 3761 - NL_SET_ERR_MSG(extack, "Invalid prefix length"); 3762 - goto out; 3763 - } 3764 - if (cfg->fc_src_len > 128) { 3765 - NL_SET_ERR_MSG(extack, "Invalid source address length"); 3766 - goto out; 3767 - } 3768 - #ifndef CONFIG_IPV6_SUBTREES 3769 - if (cfg->fc_src_len) { 3770 - NL_SET_ERR_MSG(extack, 3771 - "Specifying source address requires IPV6_SUBTREES to be enabled"); 3772 - goto out; 3773 - } 3774 - #endif 3775 3743 if (cfg->fc_nh_id) { 3776 3744 nh = nexthop_find_by_id(net, cfg->fc_nh_id); 3777 3745 if (!nh) { ··· 3804 3836 rt->fib6_src.plen = cfg->fc_src_len; 3805 3837 #endif 3806 3838 if (nh) { 3807 - if (rt->fib6_src.plen) { 3808 - NL_SET_ERR_MSG(extack, "Nexthops can not be used with source routing"); 3809 - err = -EINVAL; 3810 - goto out_free; 3811 - } 3812 3839 if (!nexthop_get(nh)) { 3813 3840 NL_SET_ERR_MSG(extack, "Nexthop has been deleted"); 3814 3841 err = -ENOENT; ··· 5201 5238 cfg->fc_expires = jiffies_to_clock_t(timeout * HZ); 5202 5239 cfg->fc_flags |= RTF_EXPIRES; 5203 5240 } 5241 + } 5242 + 5243 + if (newroute) { 5244 + /* RTF_PCPU is an internal flag; can not be set by userspace */ 5245 + if (cfg->fc_flags & RTF_PCPU) { 5246 + NL_SET_ERR_MSG(extack, "Userspace can not set RTF_PCPU"); 5247 + goto errout; 5248 + } 5249 + 5250 + /* RTF_CACHE is an internal flag; can not be set by userspace */ 5251 + if (cfg->fc_flags & RTF_CACHE) { 5252 + NL_SET_ERR_MSG(extack, "Userspace can not set RTF_CACHE"); 5253 + goto errout; 5254 + } 5255 + 5256 + if (cfg->fc_type > RTN_MAX) { 5257 + NL_SET_ERR_MSG(extack, "Invalid route type"); 5258 + goto errout; 5259 + } 5260 + 5261 + if (cfg->fc_dst_len > 128) { 5262 + NL_SET_ERR_MSG(extack, "Invalid prefix length"); 5263 + goto errout; 5264 + } 5265 + 5266 + #ifdef CONFIG_IPV6_SUBTREES 5267 + if (cfg->fc_src_len > 128) { 5268 + NL_SET_ERR_MSG(extack, "Invalid source address length"); 5269 + goto errout; 5270 + } 5271 + 5272 + if (cfg->fc_nh_id && cfg->fc_src_len) { 5273 + NL_SET_ERR_MSG(extack, "Nexthops can not be used with source routing"); 5274 + goto errout; 5275 + } 5276 + #else 5277 + if (cfg->fc_src_len) { 5278 + NL_SET_ERR_MSG(extack, 5279 + "Specifying source address requires IPV6_SUBTREES to be enabled"); 5280 + goto errout; 5281 + } 5282 + #endif 5204 5283 } 5205 5284 5206 5285 err = 0;