@@ -3737,6 +3737,53 @@ void fib6_nh_release_dsts(struct fib6_nh *fib6_nh)
3737
3737
}
3738
3738
}
3739
3739
3740
+ static int fib6_config_validate (struct fib6_config * cfg ,
3741
+ struct netlink_ext_ack * extack )
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 errout ;
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 errout ;
3753
+ }
3754
+
3755
+ if (cfg -> fc_type > RTN_MAX ) {
3756
+ NL_SET_ERR_MSG (extack , "Invalid route type" );
3757
+ goto errout ;
3758
+ }
3759
+
3760
+ if (cfg -> fc_dst_len > 128 ) {
3761
+ NL_SET_ERR_MSG (extack , "Invalid prefix length" );
3762
+ goto errout ;
3763
+ }
3764
+
3765
+ #ifdef CONFIG_IPV6_SUBTREES
3766
+ if (cfg -> fc_src_len > 128 ) {
3767
+ NL_SET_ERR_MSG (extack , "Invalid source address length" );
3768
+ goto errout ;
3769
+ }
3770
+
3771
+ if (cfg -> fc_nh_id && cfg -> fc_src_len ) {
3772
+ NL_SET_ERR_MSG (extack , "Nexthops can not be used with source routing" );
3773
+ goto errout ;
3774
+ }
3775
+ #else
3776
+ if (cfg -> fc_src_len ) {
3777
+ NL_SET_ERR_MSG (extack ,
3778
+ "Specifying source address requires IPV6_SUBTREES to be enabled" );
3779
+ goto errout ;
3780
+ }
3781
+ #endif
3782
+ return 0 ;
3783
+ errout :
3784
+ return - EINVAL ;
3785
+ }
3786
+
3740
3787
static struct fib6_info * ip6_route_info_create (struct fib6_config * cfg ,
3741
3788
gfp_t gfp_flags ,
3742
3789
struct netlink_ext_ack * extack )
@@ -3886,6 +3933,10 @@ int ip6_route_add(struct fib6_config *cfg, gfp_t gfp_flags,
3886
3933
struct fib6_info * rt ;
3887
3934
int err ;
3888
3935
3936
+ err = fib6_config_validate (cfg , extack );
3937
+ if (err )
3938
+ return err ;
3939
+
3889
3940
rt = ip6_route_info_create (cfg , gfp_flags , extack );
3890
3941
if (IS_ERR (rt ))
3891
3942
return PTR_ERR (rt );
@@ -4479,53 +4530,6 @@ void rt6_purge_dflt_routers(struct net *net)
4479
4530
rcu_read_unlock ();
4480
4531
}
4481
4532
4482
- static int fib6_config_validate (struct fib6_config * cfg ,
4483
- struct netlink_ext_ack * extack )
4484
- {
4485
- /* RTF_PCPU is an internal flag; can not be set by userspace */
4486
- if (cfg -> fc_flags & RTF_PCPU ) {
4487
- NL_SET_ERR_MSG (extack , "Userspace can not set RTF_PCPU" );
4488
- goto errout ;
4489
- }
4490
-
4491
- /* RTF_CACHE is an internal flag; can not be set by userspace */
4492
- if (cfg -> fc_flags & RTF_CACHE ) {
4493
- NL_SET_ERR_MSG (extack , "Userspace can not set RTF_CACHE" );
4494
- goto errout ;
4495
- }
4496
-
4497
- if (cfg -> fc_type > RTN_MAX ) {
4498
- NL_SET_ERR_MSG (extack , "Invalid route type" );
4499
- goto errout ;
4500
- }
4501
-
4502
- if (cfg -> fc_dst_len > 128 ) {
4503
- NL_SET_ERR_MSG (extack , "Invalid prefix length" );
4504
- goto errout ;
4505
- }
4506
-
4507
- #ifdef CONFIG_IPV6_SUBTREES
4508
- if (cfg -> fc_src_len > 128 ) {
4509
- NL_SET_ERR_MSG (extack , "Invalid source address length" );
4510
- goto errout ;
4511
- }
4512
-
4513
- if (cfg -> fc_nh_id && cfg -> fc_src_len ) {
4514
- NL_SET_ERR_MSG (extack , "Nexthops can not be used with source routing" );
4515
- goto errout ;
4516
- }
4517
- #else
4518
- if (cfg -> fc_src_len ) {
4519
- NL_SET_ERR_MSG (extack ,
4520
- "Specifying source address requires IPV6_SUBTREES to be enabled" );
4521
- goto errout ;
4522
- }
4523
- #endif
4524
- return 0 ;
4525
- errout :
4526
- return - EINVAL ;
4527
- }
4528
-
4529
4533
static void rtmsg_to_fib6_config (struct net * net ,
4530
4534
struct in6_rtmsg * rtmsg ,
4531
4535
struct fib6_config * cfg )
@@ -4563,10 +4567,6 @@ int ipv6_route_ioctl(struct net *net, unsigned int cmd, struct in6_rtmsg *rtmsg)
4563
4567
4564
4568
switch (cmd ) {
4565
4569
case SIOCADDRT :
4566
- err = fib6_config_validate (& cfg , NULL );
4567
- if (err )
4568
- break ;
4569
-
4570
4570
/* Only do the default setting of fc_metric in route adding */
4571
4571
if (cfg .fc_metric == 0 )
4572
4572
cfg .fc_metric = IP6_RT_PRIO_USER ;
@@ -5402,6 +5402,10 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
5402
5402
int nhn = 0 ;
5403
5403
int err ;
5404
5404
5405
+ err = fib6_config_validate (cfg , extack );
5406
+ if (err )
5407
+ return err ;
5408
+
5405
5409
replace = (cfg -> fc_nlinfo .nlh &&
5406
5410
(cfg -> fc_nlinfo .nlh -> nlmsg_flags & NLM_F_REPLACE ));
5407
5411
@@ -5636,10 +5640,6 @@ static int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
5636
5640
if (err < 0 )
5637
5641
return err ;
5638
5642
5639
- err = fib6_config_validate (& cfg , extack );
5640
- if (err )
5641
- return err ;
5642
-
5643
5643
if (cfg .fc_metric == 0 )
5644
5644
cfg .fc_metric = IP6_RT_PRIO_USER ;
5645
5645
0 commit comments