diff options
author | Hannes Frederic Sowa <hannes@stressinduktion.org> | 2014-10-06 13:58:34 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-10-07 00:02:30 -0400 |
commit | 94b2cfe02bfe3f1918d91bd6f498e308c5605cbc (patch) | |
tree | 597dc0faf3ccd86acc74851f92e37bef3988973f /net | |
parent | 1ff0dc9499b25d016777f9b8d3ee486fd588ba59 (diff) |
ipv6: minor fib6 cleanups like type safety, bool conversion, inline removal
Also renamed struct fib6_walker_t to fib6_walker and enum fib_walk_state_t
to fib6_walk_state as recommended by Cong Wang.
Cc: Cong Wang <cwang@twopensource.com>
Cc: YOSHIFUJI Hideaki <hideaki@yoshifuji.org>
Cc: Martin Lau <kafai@fb.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv6/ip6_fib.c | 71 |
1 files changed, 31 insertions, 40 deletions
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index 97b9fa8de377..e8d7465b1597 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c | |||
@@ -46,18 +46,8 @@ | |||
46 | 46 | ||
47 | static struct kmem_cache *fib6_node_kmem __read_mostly; | 47 | static struct kmem_cache *fib6_node_kmem __read_mostly; |
48 | 48 | ||
49 | enum fib_walk_state_t { | 49 | struct fib6_cleaner { |
50 | #ifdef CONFIG_IPV6_SUBTREES | 50 | struct fib6_walker w; |
51 | FWS_S, | ||
52 | #endif | ||
53 | FWS_L, | ||
54 | FWS_R, | ||
55 | FWS_C, | ||
56 | FWS_U | ||
57 | }; | ||
58 | |||
59 | struct fib6_cleaner_t { | ||
60 | struct fib6_walker_t w; | ||
61 | struct net *net; | 51 | struct net *net; |
62 | int (*func)(struct rt6_info *, void *arg); | 52 | int (*func)(struct rt6_info *, void *arg); |
63 | void *arg; | 53 | void *arg; |
@@ -74,8 +64,8 @@ static DEFINE_RWLOCK(fib6_walker_lock); | |||
74 | static void fib6_prune_clones(struct net *net, struct fib6_node *fn); | 64 | static void fib6_prune_clones(struct net *net, struct fib6_node *fn); |
75 | static struct rt6_info *fib6_find_prefix(struct net *net, struct fib6_node *fn); | 65 | static struct rt6_info *fib6_find_prefix(struct net *net, struct fib6_node *fn); |
76 | static struct fib6_node *fib6_repair_tree(struct net *net, struct fib6_node *fn); | 66 | static struct fib6_node *fib6_repair_tree(struct net *net, struct fib6_node *fn); |
77 | static int fib6_walk(struct fib6_walker_t *w); | 67 | static int fib6_walk(struct fib6_walker *w); |
78 | static int fib6_walk_continue(struct fib6_walker_t *w); | 68 | static int fib6_walk_continue(struct fib6_walker *w); |
79 | 69 | ||
80 | /* | 70 | /* |
81 | * A routing update causes an increase of the serial number on the | 71 | * A routing update causes an increase of the serial number on the |
@@ -91,20 +81,21 @@ static void fib6_gc_timer_cb(unsigned long arg); | |||
91 | static LIST_HEAD(fib6_walkers); | 81 | static LIST_HEAD(fib6_walkers); |
92 | #define FOR_WALKERS(w) list_for_each_entry(w, &fib6_walkers, lh) | 82 | #define FOR_WALKERS(w) list_for_each_entry(w, &fib6_walkers, lh) |
93 | 83 | ||
94 | static inline void fib6_walker_link(struct fib6_walker_t *w) | 84 | static void fib6_walker_link(struct fib6_walker *w) |
95 | { | 85 | { |
96 | write_lock_bh(&fib6_walker_lock); | 86 | write_lock_bh(&fib6_walker_lock); |
97 | list_add(&w->lh, &fib6_walkers); | 87 | list_add(&w->lh, &fib6_walkers); |
98 | write_unlock_bh(&fib6_walker_lock); | 88 | write_unlock_bh(&fib6_walker_lock); |
99 | } | 89 | } |
100 | 90 | ||
101 | static inline void fib6_walker_unlink(struct fib6_walker_t *w) | 91 | static void fib6_walker_unlink(struct fib6_walker *w) |
102 | { | 92 | { |
103 | write_lock_bh(&fib6_walker_lock); | 93 | write_lock_bh(&fib6_walker_lock); |
104 | list_del(&w->lh); | 94 | list_del(&w->lh); |
105 | write_unlock_bh(&fib6_walker_lock); | 95 | write_unlock_bh(&fib6_walker_lock); |
106 | } | 96 | } |
107 | static __inline__ u32 fib6_new_sernum(void) | 97 | |
98 | static u32 fib6_new_sernum(void) | ||
108 | { | 99 | { |
109 | u32 n = ++rt_sernum; | 100 | u32 n = ++rt_sernum; |
110 | if ((__s32)n <= 0) | 101 | if ((__s32)n <= 0) |
@@ -128,7 +119,7 @@ static __inline__ u32 fib6_new_sernum(void) | |||
128 | # define BITOP_BE32_SWIZZLE 0 | 119 | # define BITOP_BE32_SWIZZLE 0 |
129 | #endif | 120 | #endif |
130 | 121 | ||
131 | static __inline__ __be32 addr_bit_set(const void *token, int fn_bit) | 122 | static __be32 addr_bit_set(const void *token, int fn_bit) |
132 | { | 123 | { |
133 | const __be32 *addr = token; | 124 | const __be32 *addr = token; |
134 | /* | 125 | /* |
@@ -142,7 +133,7 @@ static __inline__ __be32 addr_bit_set(const void *token, int fn_bit) | |||
142 | addr[fn_bit >> 5]; | 133 | addr[fn_bit >> 5]; |
143 | } | 134 | } |
144 | 135 | ||
145 | static __inline__ struct fib6_node *node_alloc(void) | 136 | static struct fib6_node *node_alloc(void) |
146 | { | 137 | { |
147 | struct fib6_node *fn; | 138 | struct fib6_node *fn; |
148 | 139 | ||
@@ -151,12 +142,12 @@ static __inline__ struct fib6_node *node_alloc(void) | |||
151 | return fn; | 142 | return fn; |
152 | } | 143 | } |
153 | 144 | ||
154 | static __inline__ void node_free(struct fib6_node *fn) | 145 | static void node_free(struct fib6_node *fn) |
155 | { | 146 | { |
156 | kmem_cache_free(fib6_node_kmem, fn); | 147 | kmem_cache_free(fib6_node_kmem, fn); |
157 | } | 148 | } |
158 | 149 | ||
159 | static __inline__ void rt6_release(struct rt6_info *rt) | 150 | static void rt6_release(struct rt6_info *rt) |
160 | { | 151 | { |
161 | if (atomic_dec_and_test(&rt->rt6i_ref)) | 152 | if (atomic_dec_and_test(&rt->rt6i_ref)) |
162 | dst_free(&rt->dst); | 153 | dst_free(&rt->dst); |
@@ -267,7 +258,7 @@ static void __net_init fib6_tables_init(struct net *net) | |||
267 | 258 | ||
268 | #endif | 259 | #endif |
269 | 260 | ||
270 | static int fib6_dump_node(struct fib6_walker_t *w) | 261 | static int fib6_dump_node(struct fib6_walker *w) |
271 | { | 262 | { |
272 | int res; | 263 | int res; |
273 | struct rt6_info *rt; | 264 | struct rt6_info *rt; |
@@ -287,7 +278,7 @@ static int fib6_dump_node(struct fib6_walker_t *w) | |||
287 | 278 | ||
288 | static void fib6_dump_end(struct netlink_callback *cb) | 279 | static void fib6_dump_end(struct netlink_callback *cb) |
289 | { | 280 | { |
290 | struct fib6_walker_t *w = (void *)cb->args[2]; | 281 | struct fib6_walker *w = (void *)cb->args[2]; |
291 | 282 | ||
292 | if (w) { | 283 | if (w) { |
293 | if (cb->args[4]) { | 284 | if (cb->args[4]) { |
@@ -310,7 +301,7 @@ static int fib6_dump_done(struct netlink_callback *cb) | |||
310 | static int fib6_dump_table(struct fib6_table *table, struct sk_buff *skb, | 301 | static int fib6_dump_table(struct fib6_table *table, struct sk_buff *skb, |
311 | struct netlink_callback *cb) | 302 | struct netlink_callback *cb) |
312 | { | 303 | { |
313 | struct fib6_walker_t *w; | 304 | struct fib6_walker *w; |
314 | int res; | 305 | int res; |
315 | 306 | ||
316 | w = (void *)cb->args[2]; | 307 | w = (void *)cb->args[2]; |
@@ -355,7 +346,7 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) | |||
355 | unsigned int h, s_h; | 346 | unsigned int h, s_h; |
356 | unsigned int e = 0, s_e; | 347 | unsigned int e = 0, s_e; |
357 | struct rt6_rtnl_dump_arg arg; | 348 | struct rt6_rtnl_dump_arg arg; |
358 | struct fib6_walker_t *w; | 349 | struct fib6_walker *w; |
359 | struct fib6_table *tb; | 350 | struct fib6_table *tb; |
360 | struct hlist_head *head; | 351 | struct hlist_head *head; |
361 | int res = 0; | 352 | int res = 0; |
@@ -627,7 +618,7 @@ insert_above: | |||
627 | return ln; | 618 | return ln; |
628 | } | 619 | } |
629 | 620 | ||
630 | static inline bool rt6_qualify_for_ecmp(struct rt6_info *rt) | 621 | static bool rt6_qualify_for_ecmp(struct rt6_info *rt) |
631 | { | 622 | { |
632 | return (rt->rt6i_flags & (RTF_GATEWAY|RTF_ADDRCONF|RTF_DYNAMIC)) == | 623 | return (rt->rt6i_flags & (RTF_GATEWAY|RTF_ADDRCONF|RTF_DYNAMIC)) == |
633 | RTF_GATEWAY; | 624 | RTF_GATEWAY; |
@@ -820,7 +811,7 @@ add: | |||
820 | return 0; | 811 | return 0; |
821 | } | 812 | } |
822 | 813 | ||
823 | static __inline__ void fib6_start_gc(struct net *net, struct rt6_info *rt) | 814 | static void fib6_start_gc(struct net *net, struct rt6_info *rt) |
824 | { | 815 | { |
825 | if (!timer_pending(&net->ipv6.ip6_fib_timer) && | 816 | if (!timer_pending(&net->ipv6.ip6_fib_timer) && |
826 | (rt->rt6i_flags & (RTF_EXPIRES | RTF_CACHE))) | 817 | (rt->rt6i_flags & (RTF_EXPIRES | RTF_CACHE))) |
@@ -1174,7 +1165,7 @@ static struct fib6_node *fib6_repair_tree(struct net *net, | |||
1174 | int children; | 1165 | int children; |
1175 | int nstate; | 1166 | int nstate; |
1176 | struct fib6_node *child, *pn; | 1167 | struct fib6_node *child, *pn; |
1177 | struct fib6_walker_t *w; | 1168 | struct fib6_walker *w; |
1178 | int iter = 0; | 1169 | int iter = 0; |
1179 | 1170 | ||
1180 | for (;;) { | 1171 | for (;;) { |
@@ -1276,7 +1267,7 @@ static struct fib6_node *fib6_repair_tree(struct net *net, | |||
1276 | static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp, | 1267 | static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp, |
1277 | struct nl_info *info) | 1268 | struct nl_info *info) |
1278 | { | 1269 | { |
1279 | struct fib6_walker_t *w; | 1270 | struct fib6_walker *w; |
1280 | struct rt6_info *rt = *rtp; | 1271 | struct rt6_info *rt = *rtp; |
1281 | struct net *net = info->nl_net; | 1272 | struct net *net = info->nl_net; |
1282 | 1273 | ||
@@ -1414,7 +1405,7 @@ int fib6_del(struct rt6_info *rt, struct nl_info *info) | |||
1414 | * <0 -> walk is terminated by an error. | 1405 | * <0 -> walk is terminated by an error. |
1415 | */ | 1406 | */ |
1416 | 1407 | ||
1417 | static int fib6_walk_continue(struct fib6_walker_t *w) | 1408 | static int fib6_walk_continue(struct fib6_walker *w) |
1418 | { | 1409 | { |
1419 | struct fib6_node *fn, *pn; | 1410 | struct fib6_node *fn, *pn; |
1420 | 1411 | ||
@@ -1498,7 +1489,7 @@ skip: | |||
1498 | } | 1489 | } |
1499 | } | 1490 | } |
1500 | 1491 | ||
1501 | static int fib6_walk(struct fib6_walker_t *w) | 1492 | static int fib6_walk(struct fib6_walker *w) |
1502 | { | 1493 | { |
1503 | int res; | 1494 | int res; |
1504 | 1495 | ||
@@ -1512,11 +1503,11 @@ static int fib6_walk(struct fib6_walker_t *w) | |||
1512 | return res; | 1503 | return res; |
1513 | } | 1504 | } |
1514 | 1505 | ||
1515 | static int fib6_clean_node(struct fib6_walker_t *w) | 1506 | static int fib6_clean_node(struct fib6_walker *w) |
1516 | { | 1507 | { |
1517 | int res; | 1508 | int res; |
1518 | struct rt6_info *rt; | 1509 | struct rt6_info *rt; |
1519 | struct fib6_cleaner_t *c = container_of(w, struct fib6_cleaner_t, w); | 1510 | struct fib6_cleaner *c = container_of(w, struct fib6_cleaner, w); |
1520 | struct nl_info info = { | 1511 | struct nl_info info = { |
1521 | .nl_net = c->net, | 1512 | .nl_net = c->net, |
1522 | }; | 1513 | }; |
@@ -1554,9 +1545,9 @@ static int fib6_clean_node(struct fib6_walker_t *w) | |||
1554 | 1545 | ||
1555 | static void fib6_clean_tree(struct net *net, struct fib6_node *root, | 1546 | static void fib6_clean_tree(struct net *net, struct fib6_node *root, |
1556 | int (*func)(struct rt6_info *, void *arg), | 1547 | int (*func)(struct rt6_info *, void *arg), |
1557 | int prune, void *arg) | 1548 | bool prune, void *arg) |
1558 | { | 1549 | { |
1559 | struct fib6_cleaner_t c; | 1550 | struct fib6_cleaner c; |
1560 | 1551 | ||
1561 | c.w.root = root; | 1552 | c.w.root = root; |
1562 | c.w.func = fib6_clean_node; | 1553 | c.w.func = fib6_clean_node; |
@@ -1583,7 +1574,7 @@ void fib6_clean_all(struct net *net, int (*func)(struct rt6_info *, void *arg), | |||
1583 | hlist_for_each_entry_rcu(table, head, tb6_hlist) { | 1574 | hlist_for_each_entry_rcu(table, head, tb6_hlist) { |
1584 | write_lock_bh(&table->tb6_lock); | 1575 | write_lock_bh(&table->tb6_lock); |
1585 | fib6_clean_tree(net, &table->tb6_root, | 1576 | fib6_clean_tree(net, &table->tb6_root, |
1586 | func, 0, arg); | 1577 | func, false, arg); |
1587 | write_unlock_bh(&table->tb6_lock); | 1578 | write_unlock_bh(&table->tb6_lock); |
1588 | } | 1579 | } |
1589 | } | 1580 | } |
@@ -1602,7 +1593,7 @@ static int fib6_prune_clone(struct rt6_info *rt, void *arg) | |||
1602 | 1593 | ||
1603 | static void fib6_prune_clones(struct net *net, struct fib6_node *fn) | 1594 | static void fib6_prune_clones(struct net *net, struct fib6_node *fn) |
1604 | { | 1595 | { |
1605 | fib6_clean_tree(net, fn, fib6_prune_clone, 1, NULL); | 1596 | fib6_clean_tree(net, fn, fib6_prune_clone, true, NULL); |
1606 | } | 1597 | } |
1607 | 1598 | ||
1608 | static int fib6_update_sernum(struct rt6_info *rt, void *arg) | 1599 | static int fib6_update_sernum(struct rt6_info *rt, void *arg) |
@@ -1828,7 +1819,7 @@ void fib6_gc_cleanup(void) | |||
1828 | 1819 | ||
1829 | struct ipv6_route_iter { | 1820 | struct ipv6_route_iter { |
1830 | struct seq_net_private p; | 1821 | struct seq_net_private p; |
1831 | struct fib6_walker_t w; | 1822 | struct fib6_walker w; |
1832 | loff_t skip; | 1823 | loff_t skip; |
1833 | struct fib6_table *tbl; | 1824 | struct fib6_table *tbl; |
1834 | __u32 sernum; | 1825 | __u32 sernum; |
@@ -1859,7 +1850,7 @@ static int ipv6_route_seq_show(struct seq_file *seq, void *v) | |||
1859 | return 0; | 1850 | return 0; |
1860 | } | 1851 | } |
1861 | 1852 | ||
1862 | static int ipv6_route_yield(struct fib6_walker_t *w) | 1853 | static int ipv6_route_yield(struct fib6_walker *w) |
1863 | { | 1854 | { |
1864 | struct ipv6_route_iter *iter = w->args; | 1855 | struct ipv6_route_iter *iter = w->args; |
1865 | 1856 | ||
@@ -1980,7 +1971,7 @@ static void *ipv6_route_seq_start(struct seq_file *seq, loff_t *pos) | |||
1980 | 1971 | ||
1981 | static bool ipv6_route_iter_active(struct ipv6_route_iter *iter) | 1972 | static bool ipv6_route_iter_active(struct ipv6_route_iter *iter) |
1982 | { | 1973 | { |
1983 | struct fib6_walker_t *w = &iter->w; | 1974 | struct fib6_walker *w = &iter->w; |
1984 | return w->node && !(w->state == FWS_U && w->node == w->root); | 1975 | return w->node && !(w->state == FWS_U && w->node == w->root); |
1985 | } | 1976 | } |
1986 | 1977 | ||