Skip to content

Commit 433d49c

Browse files
Daniel Lezcanodavem330
authored andcommitted
[IPV6]: Make ip6_route_init to return an error code.
The route initialization function does not return any value to notify if the initialization is successful or not. This patch checks all calls made for the initilization in order to return a value for the caller. Unfortunately, proc_net_fops_create will return a NULL pointer if CONFIG_PROC_FS is off, so we can not check the return code without an ifdef CONFIG_PROC_FS block in the ip6_route_init function. Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Benjamin Thery <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9eb87f3 commit 433d49c

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed

include/net/ip6_route.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extern void ip6_route_input(struct sk_buff *skb);
5050
extern struct dst_entry * ip6_route_output(struct sock *sk,
5151
struct flowi *fl);
5252

53-
extern void ip6_route_init(void);
53+
extern int ip6_route_init(void);
5454
extern void ip6_route_cleanup(void);
5555

5656
extern int ipv6_route_ioctl(unsigned int cmd, void __user *arg);

net/ipv6/route.c

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,37 +2468,79 @@ ctl_table ipv6_route_table[] = {
24682468

24692469
#endif
24702470

2471-
void __init ip6_route_init(void)
2471+
int __init ip6_route_init(void)
24722472
{
2473+
int ret;
2474+
24732475
ip6_dst_ops.kmem_cachep =
24742476
kmem_cache_create("ip6_dst_cache", sizeof(struct rt6_info), 0,
24752477
SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
24762478
ip6_dst_blackhole_ops.kmem_cachep = ip6_dst_ops.kmem_cachep;
24772479

2478-
fib6_init();
2479-
proc_net_fops_create(&init_net, "ipv6_route", 0, &ipv6_route_proc_fops);
2480-
proc_net_fops_create(&init_net, "rt6_stats", S_IRUGO, &rt6_stats_seq_fops);
2480+
ret = fib6_init();
2481+
if (ret)
2482+
goto out_kmem_cache;
2483+
2484+
#ifdef CONFIG_PROC_FS
2485+
ret = -ENOMEM;
2486+
if (!proc_net_fops_create(&init_net, "ipv6_route",
2487+
0, &ipv6_route_proc_fops))
2488+
goto out_fib6_init;
2489+
2490+
if (!proc_net_fops_create(&init_net, "rt6_stats",
2491+
S_IRUGO, &rt6_stats_seq_fops))
2492+
goto out_proc_ipv6_route;
2493+
#endif
2494+
24812495
#ifdef CONFIG_XFRM
2482-
xfrm6_init();
2496+
ret = xfrm6_init();
2497+
if (ret)
2498+
goto out_proc_rt6_stats;
24832499
#endif
24842500
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
2485-
fib6_rules_init();
2501+
ret = fib6_rules_init();
2502+
if (ret)
2503+
goto xfrm6_init;
24862504
#endif
2505+
ret = -ENOBUFS;
2506+
if (__rtnl_register(PF_INET6, RTM_NEWROUTE, inet6_rtm_newroute, NULL) ||
2507+
__rtnl_register(PF_INET6, RTM_DELROUTE, inet6_rtm_delroute, NULL) ||
2508+
__rtnl_register(PF_INET6, RTM_GETROUTE, inet6_rtm_getroute, NULL))
2509+
goto fib6_rules_init;
24872510

2488-
__rtnl_register(PF_INET6, RTM_NEWROUTE, inet6_rtm_newroute, NULL);
2489-
__rtnl_register(PF_INET6, RTM_DELROUTE, inet6_rtm_delroute, NULL);
2490-
__rtnl_register(PF_INET6, RTM_GETROUTE, inet6_rtm_getroute, NULL);
2511+
ret = 0;
2512+
out:
2513+
return ret;
2514+
2515+
fib6_rules_init:
2516+
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
2517+
fib6_rules_cleanup();
2518+
xfrm6_init:
2519+
#endif
2520+
#ifdef CONFIG_XFRM
2521+
xfrm6_fini();
2522+
out_proc_rt6_stats:
2523+
#endif
2524+
#ifdef CONFIG_PROC_FS
2525+
proc_net_remove(&init_net, "rt6_stats");
2526+
out_proc_ipv6_route:
2527+
proc_net_remove(&init_net, "ipv6_route");
2528+
out_fib6_init:
2529+
#endif
2530+
rt6_ifdown(NULL);
2531+
fib6_gc_cleanup();
2532+
out_kmem_cache:
2533+
kmem_cache_destroy(ip6_dst_ops.kmem_cachep);
2534+
goto out;
24912535
}
24922536

24932537
void ip6_route_cleanup(void)
24942538
{
24952539
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
24962540
fib6_rules_cleanup();
24972541
#endif
2498-
#ifdef CONFIG_PROC_FS
24992542
proc_net_remove(&init_net, "ipv6_route");
25002543
proc_net_remove(&init_net, "rt6_stats");
2501-
#endif
25022544
#ifdef CONFIG_XFRM
25032545
xfrm6_fini();
25042546
#endif

0 commit comments

Comments
 (0)