Commit bdb3289f739e94bcae8b51972ae844ec66c2f4df

Authored by Daniel Lezcano
Committed by David S. Miller
1 parent 5578689a4e

[NETNS][IPV6] rt6_info - make rt6_info accessed as a pointer

This patch make mindless changes and prepares the code to use dynamic
allocation for rt6_info structure. The code accesses the rt6_info
structure as a pointer instead of a global static variable.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: Benjamin Thery <benjamin.thery@bull.net>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 5 changed files with 78 additions and 40 deletions Side-by-side Diff

include/net/ip6_route.h
... ... @@ -34,11 +34,11 @@
34 34 #define RT6_LOOKUP_F_REACHABLE 0x2
35 35 #define RT6_LOOKUP_F_HAS_SADDR 0x4
36 36  
37   -extern struct rt6_info ip6_null_entry;
  37 +extern struct rt6_info *ip6_null_entry;
38 38  
39 39 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
40   -extern struct rt6_info ip6_prohibit_entry;
41   -extern struct rt6_info ip6_blk_hole_entry;
  40 +extern struct rt6_info *ip6_prohibit_entry;
  41 +extern struct rt6_info *ip6_blk_hole_entry;
42 42 #endif
43 43  
44 44 extern void ip6_route_input(struct sk_buff *skb);
... ... @@ -4301,13 +4301,13 @@
4301 4301 if (err)
4302 4302 goto errlo;
4303 4303  
4304   - ip6_null_entry.u.dst.dev = init_net.loopback_dev;
4305   - ip6_null_entry.rt6i_idev = in6_dev_get(init_net.loopback_dev);
  4304 + ip6_null_entry->u.dst.dev = init_net.loopback_dev;
  4305 + ip6_null_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev);
4306 4306 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
4307   - ip6_prohibit_entry.u.dst.dev = init_net.loopback_dev;
4308   - ip6_prohibit_entry.rt6i_idev = in6_dev_get(init_net.loopback_dev);
4309   - ip6_blk_hole_entry.u.dst.dev = init_net.loopback_dev;
4310   - ip6_blk_hole_entry.rt6i_idev = in6_dev_get(init_net.loopback_dev);
  4307 + ip6_prohibit_entry->u.dst.dev = init_net.loopback_dev;
  4308 + ip6_prohibit_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev);
  4309 + ip6_blk_hole_entry->u.dst.dev = init_net.loopback_dev;
  4310 + ip6_blk_hole_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev);
4311 4311 #endif
4312 4312  
4313 4313 register_netdevice_notifier(&ipv6_dev_notf);
net/ipv6/fib6_rules.c
... ... @@ -43,8 +43,8 @@
43 43 if (arg.result)
44 44 return arg.result;
45 45  
46   - dst_hold(&ip6_null_entry.u.dst);
47   - return &ip6_null_entry.u.dst;
  46 + dst_hold(&ip6_null_entry->u.dst);
  47 + return &ip6_null_entry->u.dst;
48 48 }
49 49  
50 50 static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
51 51  
52 52  
... ... @@ -58,14 +58,14 @@
58 58 case FR_ACT_TO_TBL:
59 59 break;
60 60 case FR_ACT_UNREACHABLE:
61   - rt = &ip6_null_entry;
  61 + rt = ip6_null_entry;
62 62 goto discard_pkt;
63 63 default:
64 64 case FR_ACT_BLACKHOLE:
65   - rt = &ip6_blk_hole_entry;
  65 + rt = ip6_blk_hole_entry;
66 66 goto discard_pkt;
67 67 case FR_ACT_PROHIBIT:
68   - rt = &ip6_prohibit_entry;
  68 + rt = ip6_prohibit_entry;
69 69 goto discard_pkt;
70 70 }
71 71  
... ... @@ -73,7 +73,7 @@
73 73 if (table)
74 74 rt = lookup(table, flp, flags);
75 75  
76   - if (rt != &ip6_null_entry) {
  76 + if (rt != ip6_null_entry) {
77 77 struct fib6_rule *r = (struct fib6_rule *)rule;
78 78  
79 79 /*
... ... @@ -200,7 +200,7 @@
200 200 table = kzalloc(sizeof(*table), GFP_ATOMIC);
201 201 if (table != NULL) {
202 202 table->tb6_id = id;
203   - table->tb6_root.leaf = &ip6_null_entry;
  203 + table->tb6_root.leaf = ip6_null_entry;
204 204 table->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
205 205 }
206 206  
... ... @@ -717,8 +717,8 @@
717 717 if (sfn == NULL)
718 718 goto st_failure;
719 719  
720   - sfn->leaf = &ip6_null_entry;
721   - atomic_inc(&ip6_null_entry.rt6i_ref);
  720 + sfn->leaf = ip6_null_entry;
  721 + atomic_inc(&ip6_null_entry->rt6i_ref);
722 722 sfn->fn_flags = RTN_ROOT;
723 723 sfn->fn_sernum = fib6_new_sernum();
724 724  
... ... @@ -777,7 +777,7 @@
777 777 #if RT6_DEBUG >= 2
778 778 if (!pn->leaf) {
779 779 BUG_TRAP(pn->leaf != NULL);
780   - pn->leaf = &ip6_null_entry;
  780 + pn->leaf = ip6_null_entry;
781 781 }
782 782 #endif
783 783 atomic_inc(&pn->leaf->rt6i_ref);
... ... @@ -962,7 +962,7 @@
962 962 static struct rt6_info * fib6_find_prefix(struct fib6_node *fn)
963 963 {
964 964 if (fn->fn_flags&RTN_ROOT)
965   - return &ip6_null_entry;
  965 + return ip6_null_entry;
966 966  
967 967 while(fn) {
968 968 if(fn->left)
... ... @@ -1012,7 +1012,7 @@
1012 1012 #if RT6_DEBUG >= 2
1013 1013 if (fn->leaf==NULL) {
1014 1014 BUG_TRAP(fn->leaf);
1015   - fn->leaf = &ip6_null_entry;
  1015 + fn->leaf = ip6_null_entry;
1016 1016 }
1017 1017 #endif
1018 1018 atomic_inc(&fn->leaf->rt6i_ref);
... ... @@ -1154,7 +1154,7 @@
1154 1154 return -ENOENT;
1155 1155 }
1156 1156 #endif
1157   - if (fn == NULL || rt == &ip6_null_entry)
  1157 + if (fn == NULL || rt == ip6_null_entry)
1158 1158 return -ENOENT;
1159 1159  
1160 1160 BUG_TRAP(fn->fn_flags&RTN_RTINFO);
... ... @@ -1501,7 +1501,7 @@
1501 1501 goto out_fib_table_hash;
1502 1502  
1503 1503 net->ipv6.fib6_main_tbl->tb6_id = RT6_TABLE_MAIN;
1504   - net->ipv6.fib6_main_tbl->tb6_root.leaf = &ip6_null_entry;
  1504 + net->ipv6.fib6_main_tbl->tb6_root.leaf = ip6_null_entry;
1505 1505 net->ipv6.fib6_main_tbl->tb6_root.fn_flags =
1506 1506 RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
1507 1507  
... ... @@ -1511,7 +1511,7 @@
1511 1511 if (!net->ipv6.fib6_local_tbl)
1512 1512 goto out_fib6_main_tbl;
1513 1513 net->ipv6.fib6_local_tbl->tb6_id = RT6_TABLE_LOCAL;
1514   - net->ipv6.fib6_local_tbl->tb6_root.leaf = &ip6_null_entry;
  1514 + net->ipv6.fib6_local_tbl->tb6_root.leaf = ip6_null_entry;
1515 1515 net->ipv6.fib6_local_tbl->tb6_root.fn_flags =
1516 1516 RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
1517 1517 #endif
... ... @@ -127,7 +127,7 @@
127 127 .entries = ATOMIC_INIT(0),
128 128 };
129 129  
130   -struct rt6_info ip6_null_entry = {
  130 +static struct rt6_info ip6_null_entry_template = {
131 131 .u = {
132 132 .dst = {
133 133 .__refcnt = ATOMIC_INIT(1),
... ... @@ -138,7 +138,6 @@
138 138 .input = ip6_pkt_discard,
139 139 .output = ip6_pkt_discard_out,
140 140 .ops = &ip6_dst_ops,
141   - .path = (struct dst_entry*)&ip6_null_entry,
142 141 }
143 142 },
144 143 .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP),
145 144  
... ... @@ -146,12 +145,14 @@
146 145 .rt6i_ref = ATOMIC_INIT(1),
147 146 };
148 147  
  148 +struct rt6_info *ip6_null_entry;
  149 +
149 150 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
150 151  
151 152 static int ip6_pkt_prohibit(struct sk_buff *skb);
152 153 static int ip6_pkt_prohibit_out(struct sk_buff *skb);
153 154  
154   -struct rt6_info ip6_prohibit_entry = {
  155 +struct rt6_info ip6_prohibit_entry_template = {
155 156 .u = {
156 157 .dst = {
157 158 .__refcnt = ATOMIC_INIT(1),
... ... @@ -162,7 +163,6 @@
162 163 .input = ip6_pkt_prohibit,
163 164 .output = ip6_pkt_prohibit_out,
164 165 .ops = &ip6_dst_ops,
165   - .path = (struct dst_entry*)&ip6_prohibit_entry,
166 166 }
167 167 },
168 168 .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP),
... ... @@ -170,7 +170,9 @@
170 170 .rt6i_ref = ATOMIC_INIT(1),
171 171 };
172 172  
173   -struct rt6_info ip6_blk_hole_entry = {
  173 +struct rt6_info *ip6_prohibit_entry;
  174 +
  175 +static struct rt6_info ip6_blk_hole_entry_template = {
174 176 .u = {
175 177 .dst = {
176 178 .__refcnt = ATOMIC_INIT(1),
... ... @@ -181,7 +183,6 @@
181 183 .input = dst_discard,
182 184 .output = dst_discard,
183 185 .ops = &ip6_dst_ops,
184   - .path = (struct dst_entry*)&ip6_blk_hole_entry,
185 186 }
186 187 },
187 188 .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP),
... ... @@ -189,6 +190,8 @@
189 190 .rt6i_ref = ATOMIC_INIT(1),
190 191 };
191 192  
  193 +struct rt6_info *ip6_blk_hole_entry;
  194 +
192 195 #endif
193 196  
194 197 /* allocate dst with ip6_dst_ops */
... ... @@ -271,7 +274,7 @@
271 274 return local;
272 275  
273 276 if (strict)
274   - return &ip6_null_entry;
  277 + return ip6_null_entry;
275 278 }
276 279 return rt;
277 280 }
... ... @@ -437,7 +440,7 @@
437 440 RT6_TRACE("%s() => %p\n",
438 441 __FUNCTION__, match);
439 442  
440   - return (match ? match : &ip6_null_entry);
  443 + return (match ? match : ip6_null_entry);
441 444 }
442 445  
443 446 #ifdef CONFIG_IPV6_ROUTE_INFO
... ... @@ -522,7 +525,7 @@
522 525  
523 526 #define BACKTRACK(saddr) \
524 527 do { \
525   - if (rt == &ip6_null_entry) { \
  528 + if (rt == ip6_null_entry) { \
526 529 struct fib6_node *pn; \
527 530 while (1) { \
528 531 if (fn->fn_flags & RTN_TL_ROOT) \
... ... @@ -686,7 +689,7 @@
686 689 restart:
687 690 rt = rt6_select(fn, oif, strict | reachable);
688 691 BACKTRACK(&fl->fl6_src);
689   - if (rt == &ip6_null_entry ||
  692 + if (rt == ip6_null_entry ||
690 693 rt->rt6i_flags & RTF_CACHE)
691 694 goto out;
692 695  
... ... @@ -704,7 +707,7 @@
704 707 }
705 708  
706 709 dst_release(&rt->u.dst);
707   - rt = nrt ? : &ip6_null_entry;
  710 + rt = nrt ? : ip6_null_entry;
708 711  
709 712 dst_hold(&rt->u.dst);
710 713 if (nrt) {
... ... @@ -1257,7 +1260,7 @@
1257 1260 int err;
1258 1261 struct fib6_table *table;
1259 1262  
1260   - if (rt == &ip6_null_entry)
  1263 + if (rt == ip6_null_entry)
1261 1264 return -ENOENT;
1262 1265  
1263 1266 table = rt->rt6i_table;
... ... @@ -1369,7 +1372,7 @@
1369 1372 }
1370 1373  
1371 1374 if (!rt)
1372   - rt = &ip6_null_entry;
  1375 + rt = ip6_null_entry;
1373 1376 BACKTRACK(&fl->fl6_src);
1374 1377 out:
1375 1378 dst_hold(&rt->u.dst);
... ... @@ -1415,7 +1418,7 @@
1415 1418  
1416 1419 rt = ip6_route_redirect(dest, src, saddr, neigh->dev);
1417 1420  
1418   - if (rt == &ip6_null_entry) {
  1421 + if (rt == ip6_null_entry) {
1419 1422 if (net_ratelimit())
1420 1423 printk(KERN_DEBUG "rt6_redirect: source isn't a valid nexthop "
1421 1424 "for redirect target\n");
... ... @@ -1886,7 +1889,7 @@
1886 1889 static int fib6_ifdown(struct rt6_info *rt, void *arg)
1887 1890 {
1888 1891 if (((void*)rt->rt6i_dev == arg || arg == NULL) &&
1889   - rt != &ip6_null_entry) {
  1892 + rt != ip6_null_entry) {
1890 1893 RT6_TRACE("deleted by ifdown %p\n", rt);
1891 1894 return -1;
1892 1895 }
1893 1896  
... ... @@ -2565,9 +2568,30 @@
2565 2568  
2566 2569 ip6_dst_blackhole_ops.kmem_cachep = ip6_dst_ops.kmem_cachep;
2567 2570  
  2571 + ret = -ENOMEM;
  2572 + ip6_null_entry = kmemdup(&ip6_null_entry_template,
  2573 + sizeof(*ip6_null_entry), GFP_KERNEL);
  2574 + if (!ip6_null_entry)
  2575 + goto out_kmem_cache;
  2576 + ip6_null_entry->u.dst.path = (struct dst_entry *)ip6_null_entry;
  2577 +
  2578 +#ifdef CONFIG_IPV6_MULTIPLE_TABLES
  2579 + ip6_prohibit_entry = kmemdup(&ip6_prohibit_entry_template,
  2580 + sizeof(*ip6_prohibit_entry), GFP_KERNEL);
  2581 + if (!ip6_prohibit_entry)
  2582 + goto out_ip6_null_entry;
  2583 + ip6_prohibit_entry->u.dst.path = (struct dst_entry *)ip6_prohibit_entry;
  2584 +
  2585 + ip6_blk_hole_entry = kmemdup(&ip6_blk_hole_entry_template,
  2586 + sizeof(*ip6_blk_hole_entry), GFP_KERNEL);
  2587 + if (!ip6_blk_hole_entry)
  2588 + goto out_ip6_prohibit_entry;
  2589 + ip6_blk_hole_entry->u.dst.path = (struct dst_entry *)ip6_blk_hole_entry;
  2590 +#endif
  2591 +
2568 2592 ret = fib6_init();
2569 2593 if (ret)
2570   - goto out_kmem_cache;
  2594 + goto out_ip6_blk_hole_entry;
2571 2595  
2572 2596 ret = xfrm6_init();
2573 2597 if (ret)
... ... @@ -2595,6 +2619,14 @@
2595 2619 xfrm6_fini();
2596 2620 out_fib6_init:
2597 2621 fib6_gc_cleanup();
  2622 +out_ip6_blk_hole_entry:
  2623 +#ifdef CONFIG_IPV6_MULTIPLE_TABLES
  2624 + kfree(ip6_blk_hole_entry);
  2625 +out_ip6_prohibit_entry:
  2626 + kfree(ip6_prohibit_entry);
  2627 +out_ip6_null_entry:
  2628 +#endif
  2629 + kfree(ip6_null_entry);
2598 2630 out_kmem_cache:
2599 2631 kmem_cache_destroy(ip6_dst_ops.kmem_cachep);
2600 2632 goto out;
... ... @@ -2607,5 +2639,11 @@
2607 2639 xfrm6_fini();
2608 2640 fib6_gc_cleanup();
2609 2641 kmem_cache_destroy(ip6_dst_ops.kmem_cachep);
  2642 +
  2643 + kfree(ip6_null_entry);
  2644 +#ifdef CONFIG_IPV6_MULTIPLE_TABLES
  2645 + kfree(ip6_prohibit_entry);
  2646 + kfree(ip6_blk_hole_entry);
  2647 +#endif
2610 2648 }