Skip to content

Commit fa76c16

Browse files
q2venPaolo Abeni
authored and
Paolo Abeni
committed
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 <[email protected]> Acked-by: Paolo Abeni <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent bd11ff4 commit fa76c16

File tree

1 file changed

+42
-37
lines changed

1 file changed

+42
-37
lines changed

net/ipv6/route.c

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3740,38 +3740,6 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
37403740
int err = -EINVAL;
37413741
int addr_type;
37423742

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
37753743
if (cfg->fc_nh_id) {
37763744
nh = nexthop_find_by_id(net, cfg->fc_nh_id);
37773745
if (!nh) {
@@ -3836,11 +3804,6 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
38363804
rt->fib6_src.plen = cfg->fc_src_len;
38373805
#endif
38383806
if (nh) {
3839-
if (rt->fib6_src.plen) {
3840-
NL_SET_ERR_MSG(extack, "Nexthops can not be used with source routing");
3841-
err = -EINVAL;
3842-
goto out_free;
3843-
}
38443807
if (!nexthop_get(nh)) {
38453808
NL_SET_ERR_MSG(extack, "Nexthop has been deleted");
38463809
err = -ENOENT;
@@ -5240,6 +5203,48 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
52405203
}
52415204
}
52425205

5206+
if (newroute) {
5207+
/* RTF_PCPU is an internal flag; can not be set by userspace */
5208+
if (cfg->fc_flags & RTF_PCPU) {
5209+
NL_SET_ERR_MSG(extack, "Userspace can not set RTF_PCPU");
5210+
goto errout;
5211+
}
5212+
5213+
/* RTF_CACHE is an internal flag; can not be set by userspace */
5214+
if (cfg->fc_flags & RTF_CACHE) {
5215+
NL_SET_ERR_MSG(extack, "Userspace can not set RTF_CACHE");
5216+
goto errout;
5217+
}
5218+
5219+
if (cfg->fc_type > RTN_MAX) {
5220+
NL_SET_ERR_MSG(extack, "Invalid route type");
5221+
goto errout;
5222+
}
5223+
5224+
if (cfg->fc_dst_len > 128) {
5225+
NL_SET_ERR_MSG(extack, "Invalid prefix length");
5226+
goto errout;
5227+
}
5228+
5229+
#ifdef CONFIG_IPV6_SUBTREES
5230+
if (cfg->fc_src_len > 128) {
5231+
NL_SET_ERR_MSG(extack, "Invalid source address length");
5232+
goto errout;
5233+
}
5234+
5235+
if (cfg->fc_nh_id && cfg->fc_src_len) {
5236+
NL_SET_ERR_MSG(extack, "Nexthops can not be used with source routing");
5237+
goto errout;
5238+
}
5239+
#else
5240+
if (cfg->fc_src_len) {
5241+
NL_SET_ERR_MSG(extack,
5242+
"Specifying source address requires IPV6_SUBTREES to be enabled");
5243+
goto errout;
5244+
}
5245+
#endif
5246+
}
5247+
52435248
err = 0;
52445249
errout:
52455250
return err;

0 commit comments

Comments
 (0)