Commit a034ee3c authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

fib: cleanups

Use rcu_dereference_rtnl() helper

Change hard coded constants in fib_flag_trans()
 7 -> RTN_UNREACHABLE
 8 -> RTN_PROHIBIT
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4642610c
...@@ -186,9 +186,7 @@ static inline struct tnode *node_parent_rcu(struct node *node) ...@@ -186,9 +186,7 @@ static inline struct tnode *node_parent_rcu(struct node *node)
{ {
struct tnode *ret = node_parent(node); struct tnode *ret = node_parent(node);
return rcu_dereference_check(ret, return rcu_dereference_rtnl(ret);
rcu_read_lock_held() ||
lockdep_rtnl_is_held());
} }
/* Same as rcu_assign_pointer /* Same as rcu_assign_pointer
...@@ -211,9 +209,7 @@ static inline struct node *tnode_get_child_rcu(struct tnode *tn, unsigned int i) ...@@ -211,9 +209,7 @@ static inline struct node *tnode_get_child_rcu(struct tnode *tn, unsigned int i)
{ {
struct node *ret = tnode_get_child(tn, i); struct node *ret = tnode_get_child(tn, i);
return rcu_dereference_check(ret, return rcu_dereference_rtnl(ret);
rcu_read_lock_held() ||
lockdep_rtnl_is_held());
} }
static inline int tnode_child_length(const struct tnode *tn) static inline int tnode_child_length(const struct tnode *tn)
...@@ -459,8 +455,8 @@ static struct tnode *tnode_new(t_key key, int pos, int bits) ...@@ -459,8 +455,8 @@ static struct tnode *tnode_new(t_key key, int pos, int bits)
tn->empty_children = 1<<bits; tn->empty_children = 1<<bits;
} }
pr_debug("AT %p s=%u %lu\n", tn, (unsigned int) sizeof(struct tnode), pr_debug("AT %p s=%zu %zu\n", tn, sizeof(struct tnode),
(unsigned long) (sizeof(struct node) << bits)); sizeof(struct node) << bits);
return tn; return tn;
} }
...@@ -609,11 +605,10 @@ static struct node *resize(struct trie *t, struct tnode *tn) ...@@ -609,11 +605,10 @@ static struct node *resize(struct trie *t, struct tnode *tn)
/* Keep root node larger */ /* Keep root node larger */
if (!node_parent((struct node*) tn)) { if (!node_parent((struct node *)tn)) {
inflate_threshold_use = inflate_threshold_root; inflate_threshold_use = inflate_threshold_root;
halve_threshold_use = halve_threshold_root; halve_threshold_use = halve_threshold_root;
} } else {
else {
inflate_threshold_use = inflate_threshold; inflate_threshold_use = inflate_threshold;
halve_threshold_use = halve_threshold; halve_threshold_use = halve_threshold;
} }
...@@ -639,7 +634,7 @@ static struct node *resize(struct trie *t, struct tnode *tn) ...@@ -639,7 +634,7 @@ static struct node *resize(struct trie *t, struct tnode *tn)
check_tnode(tn); check_tnode(tn);
/* Return if at least one inflate is run */ /* Return if at least one inflate is run */
if( max_work != MAX_WORK) if (max_work != MAX_WORK)
return (struct node *) tn; return (struct node *) tn;
/* /*
...@@ -966,9 +961,7 @@ fib_find_node(struct trie *t, u32 key) ...@@ -966,9 +961,7 @@ fib_find_node(struct trie *t, u32 key)
struct node *n; struct node *n;
pos = 0; pos = 0;
n = rcu_dereference_check(t->trie, n = rcu_dereference_rtnl(t->trie);
rcu_read_lock_held() ||
lockdep_rtnl_is_held());
while (n != NULL && NODE_TYPE(n) == T_TNODE) { while (n != NULL && NODE_TYPE(n) == T_TNODE) {
tn = (struct tnode *) n; tn = (struct tnode *) n;
...@@ -1748,16 +1741,14 @@ static struct leaf *leaf_walk_rcu(struct tnode *p, struct node *c) ...@@ -1748,16 +1741,14 @@ static struct leaf *leaf_walk_rcu(struct tnode *p, struct node *c)
/* Node empty, walk back up to parent */ /* Node empty, walk back up to parent */
c = (struct node *) p; c = (struct node *) p;
} while ( (p = node_parent_rcu(c)) != NULL); } while ((p = node_parent_rcu(c)) != NULL);
return NULL; /* Root of trie */ return NULL; /* Root of trie */
} }
static struct leaf *trie_firstleaf(struct trie *t) static struct leaf *trie_firstleaf(struct trie *t)
{ {
struct tnode *n = (struct tnode *) rcu_dereference_check(t->trie, struct tnode *n = (struct tnode *)rcu_dereference_rtnl(t->trie);
rcu_read_lock_held() ||
lockdep_rtnl_is_held());
if (!n) if (!n)
return NULL; return NULL;
...@@ -2043,14 +2034,14 @@ struct fib_trie_iter { ...@@ -2043,14 +2034,14 @@ struct fib_trie_iter {
struct seq_net_private p; struct seq_net_private p;
struct fib_table *tb; struct fib_table *tb;
struct tnode *tnode; struct tnode *tnode;
unsigned index; unsigned int index;
unsigned depth; unsigned int depth;
}; };
static struct node *fib_trie_get_next(struct fib_trie_iter *iter) static struct node *fib_trie_get_next(struct fib_trie_iter *iter)
{ {
struct tnode *tn = iter->tnode; struct tnode *tn = iter->tnode;
unsigned cindex = iter->index; unsigned int cindex = iter->index;
struct tnode *p; struct tnode *p;
/* A single entry routing table */ /* A single entry routing table */
...@@ -2159,7 +2150,7 @@ static void trie_collect_stats(struct trie *t, struct trie_stat *s) ...@@ -2159,7 +2150,7 @@ static void trie_collect_stats(struct trie *t, struct trie_stat *s)
*/ */
static void trie_show_stats(struct seq_file *seq, struct trie_stat *stat) static void trie_show_stats(struct seq_file *seq, struct trie_stat *stat)
{ {
unsigned i, max, pointers, bytes, avdepth; unsigned int i, max, pointers, bytes, avdepth;
if (stat->leaves) if (stat->leaves)
avdepth = stat->totdepth*100 / stat->leaves; avdepth = stat->totdepth*100 / stat->leaves;
...@@ -2356,7 +2347,8 @@ static void fib_trie_seq_stop(struct seq_file *seq, void *v) ...@@ -2356,7 +2347,8 @@ static void fib_trie_seq_stop(struct seq_file *seq, void *v)
static void seq_indent(struct seq_file *seq, int n) static void seq_indent(struct seq_file *seq, int n)
{ {
while (n-- > 0) seq_puts(seq, " "); while (n-- > 0)
seq_puts(seq, " ");
} }
static inline const char *rtn_scope(char *buf, size_t len, enum rt_scope_t s) static inline const char *rtn_scope(char *buf, size_t len, enum rt_scope_t s)
...@@ -2388,7 +2380,7 @@ static const char *const rtn_type_names[__RTN_MAX] = { ...@@ -2388,7 +2380,7 @@ static const char *const rtn_type_names[__RTN_MAX] = {
[RTN_XRESOLVE] = "XRESOLVE", [RTN_XRESOLVE] = "XRESOLVE",
}; };
static inline const char *rtn_type(char *buf, size_t len, unsigned t) static inline const char *rtn_type(char *buf, size_t len, unsigned int t)
{ {
if (t < __RTN_MAX && rtn_type_names[t]) if (t < __RTN_MAX && rtn_type_names[t])
return rtn_type_names[t]; return rtn_type_names[t];
...@@ -2544,13 +2536,12 @@ static void fib_route_seq_stop(struct seq_file *seq, void *v) ...@@ -2544,13 +2536,12 @@ static void fib_route_seq_stop(struct seq_file *seq, void *v)
rcu_read_unlock(); rcu_read_unlock();
} }
static unsigned fib_flag_trans(int type, __be32 mask, const struct fib_info *fi) static unsigned int fib_flag_trans(int type, __be32 mask, const struct fib_info *fi)
{ {
static unsigned type2flags[RTN_MAX + 1] = { unsigned int flags = 0;
[7] = RTF_REJECT, [8] = RTF_REJECT,
};
unsigned flags = type2flags[type];
if (type == RTN_UNREACHABLE || type == RTN_PROHIBIT)
flags = RTF_REJECT;
if (fi && fi->fib_nh->nh_gw) if (fi && fi->fib_nh->nh_gw)
flags |= RTF_GATEWAY; flags |= RTF_GATEWAY;
if (mask == htonl(0xFFFFFFFF)) if (mask == htonl(0xFFFFFFFF))
...@@ -2562,7 +2553,7 @@ static unsigned fib_flag_trans(int type, __be32 mask, const struct fib_info *fi) ...@@ -2562,7 +2553,7 @@ static unsigned fib_flag_trans(int type, __be32 mask, const struct fib_info *fi)
/* /*
* This outputs /proc/net/route. * This outputs /proc/net/route.
* The format of the file is not supposed to be changed * The format of the file is not supposed to be changed
* and needs to be same as fib_hash output to avoid breaking * and needs to be same as fib_hash output to avoid breaking
* legacy utilities * legacy utilities
*/ */
static int fib_route_seq_show(struct seq_file *seq, void *v) static int fib_route_seq_show(struct seq_file *seq, void *v)
...@@ -2587,7 +2578,7 @@ static int fib_route_seq_show(struct seq_file *seq, void *v) ...@@ -2587,7 +2578,7 @@ static int fib_route_seq_show(struct seq_file *seq, void *v)
list_for_each_entry_rcu(fa, &li->falh, fa_list) { list_for_each_entry_rcu(fa, &li->falh, fa_list) {
const struct fib_info *fi = fa->fa_info; const struct fib_info *fi = fa->fa_info;
unsigned flags = fib_flag_trans(fa->fa_type, mask, fi); unsigned int flags = fib_flag_trans(fa->fa_type, mask, fi);
int len; int len;
if (fa->fa_type == RTN_BROADCAST if (fa->fa_type == RTN_BROADCAST
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment