aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv
diff options
context:
space:
mode:
authorMarek Lindner <lindner_marek@yahoo.de>2010-12-12 16:57:10 -0500
committerMarek Lindner <lindner_marek@yahoo.de>2011-03-05 06:49:52 -0500
commita8e7f4bc38c4a90ee308cd7f1f8604f71db59d05 (patch)
treeeaad8069534691aaa06b316ce42fbeb81f380b20 /net/batman-adv
parent8d689218568174955129d0f0e9e4370a391b3609 (diff)
batman-adv: protect neighbor nodes with reference counters
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Diffstat (limited to 'net/batman-adv')
-rw-r--r--net/batman-adv/originator.c20
-rw-r--r--net/batman-adv/originator.h8
-rw-r--r--net/batman-adv/routing.c7
-rw-r--r--net/batman-adv/types.h1
4 files changed, 28 insertions, 8 deletions
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 54863c9385de..b1b1773afa0b 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -59,9 +59,18 @@ err:
59 return 0; 59 return 0;
60} 60}
61 61
62struct neigh_node * 62void neigh_node_free_ref(struct kref *refcount)
63create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node, 63{
64 uint8_t *neigh, struct batman_if *if_incoming) 64 struct neigh_node *neigh_node;
65
66 neigh_node = container_of(refcount, struct neigh_node, refcount);
67 kfree(neigh_node);
68}
69
70struct neigh_node *create_neighbor(struct orig_node *orig_node,
71 struct orig_node *orig_neigh_node,
72 uint8_t *neigh,
73 struct batman_if *if_incoming)
65{ 74{
66 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); 75 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
67 struct neigh_node *neigh_node; 76 struct neigh_node *neigh_node;
@@ -78,6 +87,7 @@ create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node,
78 memcpy(neigh_node->addr, neigh, ETH_ALEN); 87 memcpy(neigh_node->addr, neigh, ETH_ALEN);
79 neigh_node->orig_node = orig_neigh_node; 88 neigh_node->orig_node = orig_neigh_node;
80 neigh_node->if_incoming = if_incoming; 89 neigh_node->if_incoming = if_incoming;
90 kref_init(&neigh_node->refcount);
81 91
82 list_add_tail(&neigh_node->list, &orig_node->neigh_list); 92 list_add_tail(&neigh_node->list, &orig_node->neigh_list);
83 return neigh_node; 93 return neigh_node;
@@ -95,7 +105,7 @@ static void free_orig_node(void *data, void *arg)
95 neigh_node = list_entry(list_pos, struct neigh_node, list); 105 neigh_node = list_entry(list_pos, struct neigh_node, list);
96 106
97 list_del(list_pos); 107 list_del(list_pos);
98 kfree(neigh_node); 108 kref_put(&neigh_node->refcount, neigh_node_free_ref);
99 } 109 }
100 110
101 frag_list_free(&orig_node->frag_list); 111 frag_list_free(&orig_node->frag_list);
@@ -216,7 +226,7 @@ static bool purge_orig_neighbors(struct bat_priv *bat_priv,
216 226
217 neigh_purged = true; 227 neigh_purged = true;
218 list_del(list_pos); 228 list_del(list_pos);
219 kfree(neigh_node); 229 kref_put(&neigh_node->refcount, neigh_node_free_ref);
220 } else { 230 } else {
221 if ((!*best_neigh_node) || 231 if ((!*best_neigh_node) ||
222 (neigh_node->tq_avg > (*best_neigh_node)->tq_avg)) 232 (neigh_node->tq_avg > (*best_neigh_node)->tq_avg))
diff --git a/net/batman-adv/originator.h b/net/batman-adv/originator.h
index 8019fbddffd0..88e5c6049243 100644
--- a/net/batman-adv/originator.h
+++ b/net/batman-adv/originator.h
@@ -26,9 +26,11 @@ int originator_init(struct bat_priv *bat_priv);
26void originator_free(struct bat_priv *bat_priv); 26void originator_free(struct bat_priv *bat_priv);
27void purge_orig_ref(struct bat_priv *bat_priv); 27void purge_orig_ref(struct bat_priv *bat_priv);
28struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr); 28struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr);
29struct neigh_node * 29struct neigh_node *create_neighbor(struct orig_node *orig_node,
30create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node, 30 struct orig_node *orig_neigh_node,
31 uint8_t *neigh, struct batman_if *if_incoming); 31 uint8_t *neigh,
32 struct batman_if *if_incoming);
33void neigh_node_free_ref(struct kref *refcount);
32int orig_seq_print_text(struct seq_file *seq, void *offset); 34int orig_seq_print_text(struct seq_file *seq, void *offset);
33int orig_hash_add_if(struct batman_if *batman_if, int max_if_num); 35int orig_hash_add_if(struct batman_if *batman_if, int max_if_num);
34int orig_hash_del_if(struct batman_if *batman_if, int max_if_num); 36int orig_hash_del_if(struct batman_if *batman_if, int max_if_num);
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 827414067e46..36351d374f28 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -89,6 +89,8 @@ static void update_route(struct bat_priv *bat_priv,
89 struct neigh_node *neigh_node, 89 struct neigh_node *neigh_node,
90 unsigned char *hna_buff, int hna_buff_len) 90 unsigned char *hna_buff, int hna_buff_len)
91{ 91{
92 struct neigh_node *neigh_node_tmp;
93
92 /* route deleted */ 94 /* route deleted */
93 if ((orig_node->router) && (!neigh_node)) { 95 if ((orig_node->router) && (!neigh_node)) {
94 96
@@ -115,7 +117,12 @@ static void update_route(struct bat_priv *bat_priv,
115 orig_node->router->addr); 117 orig_node->router->addr);
116 } 118 }
117 119
120 if (neigh_node)
121 kref_get(&neigh_node->refcount);
122 neigh_node_tmp = orig_node->router;
118 orig_node->router = neigh_node; 123 orig_node->router = neigh_node;
124 if (neigh_node_tmp)
125 kref_put(&neigh_node_tmp->refcount, neigh_node_free_ref);
119} 126}
120 127
121 128
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 7270405046e9..f9217d5dad8e 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -115,6 +115,7 @@ struct neigh_node {
115 struct neigh_node *next_bond_candidate; 115 struct neigh_node *next_bond_candidate;
116 unsigned long last_valid; 116 unsigned long last_valid;
117 unsigned long real_bits[NUM_WORDS]; 117 unsigned long real_bits[NUM_WORDS];
118 struct kref refcount;
118 struct orig_node *orig_node; 119 struct orig_node *orig_node;
119 struct batman_if *if_incoming; 120 struct batman_if *if_incoming;
120}; 121};