diff options
author | David S. Miller <davem@davemloft.net> | 2011-05-08 18:39:11 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-05-08 18:39:11 -0400 |
commit | 02e73c1edc3746e308d1768a27fdc8121f641ab1 (patch) | |
tree | a3db8009e4549e3d85905e11ac2bf8e64df1763f /net/batman-adv/soft-interface.c | |
parent | c5216cc70fa769e5a51837f2cf07c4a0aa734fcf (diff) | |
parent | 27aea2128ec09924dfe08e97739b2bf8b15c8619 (diff) |
Merge branch 'batman-adv/next' of git://git.open-mesh.org/ecsv/linux-merge
Diffstat (limited to 'net/batman-adv/soft-interface.c')
-rw-r--r-- | net/batman-adv/soft-interface.c | 409 |
1 files changed, 292 insertions, 117 deletions
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c index 9e5fcd1596cf..c76a33eeb3f1 100644 --- a/net/batman-adv/soft-interface.c +++ b/net/batman-adv/soft-interface.c | |||
@@ -86,135 +86,251 @@ static void softif_neigh_free_ref(struct softif_neigh *softif_neigh) | |||
86 | call_rcu(&softif_neigh->rcu, softif_neigh_free_rcu); | 86 | call_rcu(&softif_neigh->rcu, softif_neigh_free_rcu); |
87 | } | 87 | } |
88 | 88 | ||
89 | static struct softif_neigh *softif_neigh_get_selected(struct bat_priv *bat_priv) | 89 | static void softif_neigh_vid_free_rcu(struct rcu_head *rcu) |
90 | { | 90 | { |
91 | struct softif_neigh *neigh; | 91 | struct softif_neigh_vid *softif_neigh_vid; |
92 | 92 | struct softif_neigh *softif_neigh; | |
93 | rcu_read_lock(); | 93 | struct hlist_node *node, *node_tmp; |
94 | neigh = rcu_dereference(bat_priv->softif_neigh); | 94 | struct bat_priv *bat_priv; |
95 | |||
96 | if (neigh && !atomic_inc_not_zero(&neigh->refcount)) | ||
97 | neigh = NULL; | ||
98 | |||
99 | rcu_read_unlock(); | ||
100 | return neigh; | ||
101 | } | ||
102 | 95 | ||
103 | static void softif_neigh_select(struct bat_priv *bat_priv, | 96 | softif_neigh_vid = container_of(rcu, struct softif_neigh_vid, rcu); |
104 | struct softif_neigh *new_neigh) | 97 | bat_priv = softif_neigh_vid->bat_priv; |
105 | { | ||
106 | struct softif_neigh *curr_neigh; | ||
107 | 98 | ||
108 | spin_lock_bh(&bat_priv->softif_neigh_lock); | 99 | spin_lock_bh(&bat_priv->softif_neigh_lock); |
109 | 100 | hlist_for_each_entry_safe(softif_neigh, node, node_tmp, | |
110 | if (new_neigh && !atomic_inc_not_zero(&new_neigh->refcount)) | 101 | &softif_neigh_vid->softif_neigh_list, list) { |
111 | new_neigh = NULL; | 102 | hlist_del_rcu(&softif_neigh->list); |
112 | 103 | softif_neigh_free_ref(softif_neigh); | |
113 | curr_neigh = bat_priv->softif_neigh; | 104 | } |
114 | rcu_assign_pointer(bat_priv->softif_neigh, new_neigh); | ||
115 | |||
116 | if (curr_neigh) | ||
117 | softif_neigh_free_ref(curr_neigh); | ||
118 | |||
119 | spin_unlock_bh(&bat_priv->softif_neigh_lock); | 105 | spin_unlock_bh(&bat_priv->softif_neigh_lock); |
106 | |||
107 | kfree(softif_neigh_vid); | ||
120 | } | 108 | } |
121 | 109 | ||
122 | static void softif_neigh_deselect(struct bat_priv *bat_priv) | 110 | static void softif_neigh_vid_free_ref(struct softif_neigh_vid *softif_neigh_vid) |
123 | { | 111 | { |
124 | softif_neigh_select(bat_priv, NULL); | 112 | if (atomic_dec_and_test(&softif_neigh_vid->refcount)) |
113 | call_rcu(&softif_neigh_vid->rcu, softif_neigh_vid_free_rcu); | ||
125 | } | 114 | } |
126 | 115 | ||
127 | void softif_neigh_purge(struct bat_priv *bat_priv) | 116 | static struct softif_neigh_vid *softif_neigh_vid_get(struct bat_priv *bat_priv, |
117 | short vid) | ||
128 | { | 118 | { |
129 | struct softif_neigh *softif_neigh, *curr_softif_neigh; | 119 | struct softif_neigh_vid *softif_neigh_vid; |
130 | struct hlist_node *node, *node_tmp; | 120 | struct hlist_node *node; |
131 | char do_deselect = 0; | ||
132 | |||
133 | curr_softif_neigh = softif_neigh_get_selected(bat_priv); | ||
134 | |||
135 | spin_lock_bh(&bat_priv->softif_neigh_lock); | ||
136 | |||
137 | hlist_for_each_entry_safe(softif_neigh, node, node_tmp, | ||
138 | &bat_priv->softif_neigh_list, list) { | ||
139 | 121 | ||
140 | if ((!time_after(jiffies, softif_neigh->last_seen + | 122 | rcu_read_lock(); |
141 | msecs_to_jiffies(SOFTIF_NEIGH_TIMEOUT))) && | 123 | hlist_for_each_entry_rcu(softif_neigh_vid, node, |
142 | (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE)) | 124 | &bat_priv->softif_neigh_vids, list) { |
125 | if (softif_neigh_vid->vid != vid) | ||
143 | continue; | 126 | continue; |
144 | 127 | ||
145 | if (curr_softif_neigh == softif_neigh) { | 128 | if (!atomic_inc_not_zero(&softif_neigh_vid->refcount)) |
146 | bat_dbg(DBG_ROUTES, bat_priv, | 129 | continue; |
147 | "Current mesh exit point '%pM' vanished " | ||
148 | "(vid: %d).\n", | ||
149 | softif_neigh->addr, softif_neigh->vid); | ||
150 | do_deselect = 1; | ||
151 | } | ||
152 | 130 | ||
153 | hlist_del_rcu(&softif_neigh->list); | 131 | goto out; |
154 | softif_neigh_free_ref(softif_neigh); | ||
155 | } | 132 | } |
156 | 133 | ||
157 | spin_unlock_bh(&bat_priv->softif_neigh_lock); | 134 | softif_neigh_vid = kzalloc(sizeof(struct softif_neigh_vid), |
135 | GFP_ATOMIC); | ||
136 | if (!softif_neigh_vid) | ||
137 | goto out; | ||
158 | 138 | ||
159 | /* soft_neigh_deselect() needs to acquire the softif_neigh_lock */ | 139 | softif_neigh_vid->vid = vid; |
160 | if (do_deselect) | 140 | softif_neigh_vid->bat_priv = bat_priv; |
161 | softif_neigh_deselect(bat_priv); | ||
162 | 141 | ||
163 | if (curr_softif_neigh) | 142 | /* initialize with 2 - caller decrements counter by one */ |
164 | softif_neigh_free_ref(curr_softif_neigh); | 143 | atomic_set(&softif_neigh_vid->refcount, 2); |
144 | INIT_HLIST_HEAD(&softif_neigh_vid->softif_neigh_list); | ||
145 | INIT_HLIST_NODE(&softif_neigh_vid->list); | ||
146 | spin_lock_bh(&bat_priv->softif_neigh_vid_lock); | ||
147 | hlist_add_head_rcu(&softif_neigh_vid->list, | ||
148 | &bat_priv->softif_neigh_vids); | ||
149 | spin_unlock_bh(&bat_priv->softif_neigh_vid_lock); | ||
150 | |||
151 | out: | ||
152 | rcu_read_unlock(); | ||
153 | return softif_neigh_vid; | ||
165 | } | 154 | } |
166 | 155 | ||
167 | static struct softif_neigh *softif_neigh_get(struct bat_priv *bat_priv, | 156 | static struct softif_neigh *softif_neigh_get(struct bat_priv *bat_priv, |
168 | uint8_t *addr, short vid) | 157 | uint8_t *addr, short vid) |
169 | { | 158 | { |
170 | struct softif_neigh *softif_neigh; | 159 | struct softif_neigh_vid *softif_neigh_vid; |
160 | struct softif_neigh *softif_neigh = NULL; | ||
171 | struct hlist_node *node; | 161 | struct hlist_node *node; |
172 | 162 | ||
163 | softif_neigh_vid = softif_neigh_vid_get(bat_priv, vid); | ||
164 | if (!softif_neigh_vid) | ||
165 | goto out; | ||
166 | |||
173 | rcu_read_lock(); | 167 | rcu_read_lock(); |
174 | hlist_for_each_entry_rcu(softif_neigh, node, | 168 | hlist_for_each_entry_rcu(softif_neigh, node, |
175 | &bat_priv->softif_neigh_list, list) { | 169 | &softif_neigh_vid->softif_neigh_list, |
170 | list) { | ||
176 | if (!compare_eth(softif_neigh->addr, addr)) | 171 | if (!compare_eth(softif_neigh->addr, addr)) |
177 | continue; | 172 | continue; |
178 | 173 | ||
179 | if (softif_neigh->vid != vid) | ||
180 | continue; | ||
181 | |||
182 | if (!atomic_inc_not_zero(&softif_neigh->refcount)) | 174 | if (!atomic_inc_not_zero(&softif_neigh->refcount)) |
183 | continue; | 175 | continue; |
184 | 176 | ||
185 | softif_neigh->last_seen = jiffies; | 177 | softif_neigh->last_seen = jiffies; |
186 | goto out; | 178 | goto unlock; |
187 | } | 179 | } |
188 | 180 | ||
189 | softif_neigh = kzalloc(sizeof(struct softif_neigh), GFP_ATOMIC); | 181 | softif_neigh = kzalloc(sizeof(struct softif_neigh), GFP_ATOMIC); |
190 | if (!softif_neigh) | 182 | if (!softif_neigh) |
191 | goto out; | 183 | goto unlock; |
192 | 184 | ||
193 | memcpy(softif_neigh->addr, addr, ETH_ALEN); | 185 | memcpy(softif_neigh->addr, addr, ETH_ALEN); |
194 | softif_neigh->vid = vid; | ||
195 | softif_neigh->last_seen = jiffies; | 186 | softif_neigh->last_seen = jiffies; |
196 | /* initialize with 2 - caller decrements counter by one */ | 187 | /* initialize with 2 - caller decrements counter by one */ |
197 | atomic_set(&softif_neigh->refcount, 2); | 188 | atomic_set(&softif_neigh->refcount, 2); |
198 | 189 | ||
199 | INIT_HLIST_NODE(&softif_neigh->list); | 190 | INIT_HLIST_NODE(&softif_neigh->list); |
200 | spin_lock_bh(&bat_priv->softif_neigh_lock); | 191 | spin_lock_bh(&bat_priv->softif_neigh_lock); |
201 | hlist_add_head_rcu(&softif_neigh->list, &bat_priv->softif_neigh_list); | 192 | hlist_add_head_rcu(&softif_neigh->list, |
193 | &softif_neigh_vid->softif_neigh_list); | ||
202 | spin_unlock_bh(&bat_priv->softif_neigh_lock); | 194 | spin_unlock_bh(&bat_priv->softif_neigh_lock); |
203 | 195 | ||
196 | unlock: | ||
197 | rcu_read_unlock(); | ||
204 | out: | 198 | out: |
199 | if (softif_neigh_vid) | ||
200 | softif_neigh_vid_free_ref(softif_neigh_vid); | ||
201 | return softif_neigh; | ||
202 | } | ||
203 | |||
204 | static struct softif_neigh *softif_neigh_get_selected( | ||
205 | struct softif_neigh_vid *softif_neigh_vid) | ||
206 | { | ||
207 | struct softif_neigh *softif_neigh; | ||
208 | |||
209 | rcu_read_lock(); | ||
210 | softif_neigh = rcu_dereference(softif_neigh_vid->softif_neigh); | ||
211 | |||
212 | if (softif_neigh && !atomic_inc_not_zero(&softif_neigh->refcount)) | ||
213 | softif_neigh = NULL; | ||
214 | |||
205 | rcu_read_unlock(); | 215 | rcu_read_unlock(); |
206 | return softif_neigh; | 216 | return softif_neigh; |
207 | } | 217 | } |
208 | 218 | ||
219 | static struct softif_neigh *softif_neigh_vid_get_selected( | ||
220 | struct bat_priv *bat_priv, | ||
221 | short vid) | ||
222 | { | ||
223 | struct softif_neigh_vid *softif_neigh_vid; | ||
224 | struct softif_neigh *softif_neigh = NULL; | ||
225 | |||
226 | softif_neigh_vid = softif_neigh_vid_get(bat_priv, vid); | ||
227 | if (!softif_neigh_vid) | ||
228 | goto out; | ||
229 | |||
230 | softif_neigh = softif_neigh_get_selected(softif_neigh_vid); | ||
231 | out: | ||
232 | if (softif_neigh_vid) | ||
233 | softif_neigh_vid_free_ref(softif_neigh_vid); | ||
234 | return softif_neigh; | ||
235 | } | ||
236 | |||
237 | static void softif_neigh_vid_select(struct bat_priv *bat_priv, | ||
238 | struct softif_neigh *new_neigh, | ||
239 | short vid) | ||
240 | { | ||
241 | struct softif_neigh_vid *softif_neigh_vid; | ||
242 | struct softif_neigh *curr_neigh; | ||
243 | |||
244 | softif_neigh_vid = softif_neigh_vid_get(bat_priv, vid); | ||
245 | if (!softif_neigh_vid) | ||
246 | goto out; | ||
247 | |||
248 | spin_lock_bh(&bat_priv->softif_neigh_lock); | ||
249 | |||
250 | if (new_neigh && !atomic_inc_not_zero(&new_neigh->refcount)) | ||
251 | new_neigh = NULL; | ||
252 | |||
253 | curr_neigh = softif_neigh_vid->softif_neigh; | ||
254 | rcu_assign_pointer(softif_neigh_vid->softif_neigh, new_neigh); | ||
255 | |||
256 | if ((curr_neigh) && (!new_neigh)) | ||
257 | bat_dbg(DBG_ROUTES, bat_priv, | ||
258 | "Removing mesh exit point on vid: %d (prev: %pM).\n", | ||
259 | vid, curr_neigh->addr); | ||
260 | else if ((curr_neigh) && (new_neigh)) | ||
261 | bat_dbg(DBG_ROUTES, bat_priv, | ||
262 | "Changing mesh exit point on vid: %d from %pM " | ||
263 | "to %pM.\n", vid, curr_neigh->addr, new_neigh->addr); | ||
264 | else if ((!curr_neigh) && (new_neigh)) | ||
265 | bat_dbg(DBG_ROUTES, bat_priv, | ||
266 | "Setting mesh exit point on vid: %d to %pM.\n", | ||
267 | vid, new_neigh->addr); | ||
268 | |||
269 | if (curr_neigh) | ||
270 | softif_neigh_free_ref(curr_neigh); | ||
271 | |||
272 | spin_unlock_bh(&bat_priv->softif_neigh_lock); | ||
273 | |||
274 | out: | ||
275 | if (softif_neigh_vid) | ||
276 | softif_neigh_vid_free_ref(softif_neigh_vid); | ||
277 | } | ||
278 | |||
279 | static void softif_neigh_vid_deselect(struct bat_priv *bat_priv, | ||
280 | struct softif_neigh_vid *softif_neigh_vid) | ||
281 | { | ||
282 | struct softif_neigh *curr_neigh; | ||
283 | struct softif_neigh *softif_neigh = NULL, *softif_neigh_tmp; | ||
284 | struct hard_iface *primary_if = NULL; | ||
285 | struct hlist_node *node; | ||
286 | |||
287 | primary_if = primary_if_get_selected(bat_priv); | ||
288 | if (!primary_if) | ||
289 | goto out; | ||
290 | |||
291 | /* find new softif_neigh immediately to avoid temporary loops */ | ||
292 | rcu_read_lock(); | ||
293 | curr_neigh = rcu_dereference(softif_neigh_vid->softif_neigh); | ||
294 | |||
295 | hlist_for_each_entry_rcu(softif_neigh_tmp, node, | ||
296 | &softif_neigh_vid->softif_neigh_list, | ||
297 | list) { | ||
298 | if (softif_neigh_tmp == curr_neigh) | ||
299 | continue; | ||
300 | |||
301 | /* we got a neighbor but its mac is 'bigger' than ours */ | ||
302 | if (memcmp(primary_if->net_dev->dev_addr, | ||
303 | softif_neigh_tmp->addr, ETH_ALEN) < 0) | ||
304 | continue; | ||
305 | |||
306 | if (!atomic_inc_not_zero(&softif_neigh_tmp->refcount)) | ||
307 | continue; | ||
308 | |||
309 | softif_neigh = softif_neigh_tmp; | ||
310 | goto unlock; | ||
311 | } | ||
312 | |||
313 | unlock: | ||
314 | rcu_read_unlock(); | ||
315 | out: | ||
316 | softif_neigh_vid_select(bat_priv, softif_neigh, softif_neigh_vid->vid); | ||
317 | |||
318 | if (primary_if) | ||
319 | hardif_free_ref(primary_if); | ||
320 | if (softif_neigh) | ||
321 | softif_neigh_free_ref(softif_neigh); | ||
322 | } | ||
323 | |||
209 | int softif_neigh_seq_print_text(struct seq_file *seq, void *offset) | 324 | int softif_neigh_seq_print_text(struct seq_file *seq, void *offset) |
210 | { | 325 | { |
211 | struct net_device *net_dev = (struct net_device *)seq->private; | 326 | struct net_device *net_dev = (struct net_device *)seq->private; |
212 | struct bat_priv *bat_priv = netdev_priv(net_dev); | 327 | struct bat_priv *bat_priv = netdev_priv(net_dev); |
328 | struct softif_neigh_vid *softif_neigh_vid; | ||
213 | struct softif_neigh *softif_neigh; | 329 | struct softif_neigh *softif_neigh; |
214 | struct hard_iface *primary_if; | 330 | struct hard_iface *primary_if; |
215 | struct hlist_node *node; | 331 | struct hlist_node *node, *node_tmp; |
216 | struct softif_neigh *curr_softif_neigh; | 332 | struct softif_neigh *curr_softif_neigh; |
217 | int ret = 0; | 333 | int ret = 0, last_seen_secs, last_seen_msecs; |
218 | 334 | ||
219 | primary_if = primary_if_get_selected(bat_priv); | 335 | primary_if = primary_if_get_selected(bat_priv); |
220 | if (!primary_if) { | 336 | if (!primary_if) { |
@@ -233,17 +349,33 @@ int softif_neigh_seq_print_text(struct seq_file *seq, void *offset) | |||
233 | 349 | ||
234 | seq_printf(seq, "Softif neighbor list (%s)\n", net_dev->name); | 350 | seq_printf(seq, "Softif neighbor list (%s)\n", net_dev->name); |
235 | 351 | ||
236 | curr_softif_neigh = softif_neigh_get_selected(bat_priv); | ||
237 | rcu_read_lock(); | 352 | rcu_read_lock(); |
238 | hlist_for_each_entry_rcu(softif_neigh, node, | 353 | hlist_for_each_entry_rcu(softif_neigh_vid, node, |
239 | &bat_priv->softif_neigh_list, list) | 354 | &bat_priv->softif_neigh_vids, list) { |
240 | seq_printf(seq, "%s %pM (vid: %d)\n", | 355 | seq_printf(seq, " %-15s %s on vid: %d\n", |
241 | curr_softif_neigh == softif_neigh | 356 | "Originator", "last-seen", softif_neigh_vid->vid); |
242 | ? "=>" : " ", softif_neigh->addr, | 357 | |
243 | softif_neigh->vid); | 358 | curr_softif_neigh = softif_neigh_get_selected(softif_neigh_vid); |
359 | |||
360 | hlist_for_each_entry_rcu(softif_neigh, node_tmp, | ||
361 | &softif_neigh_vid->softif_neigh_list, | ||
362 | list) { | ||
363 | last_seen_secs = jiffies_to_msecs(jiffies - | ||
364 | softif_neigh->last_seen) / 1000; | ||
365 | last_seen_msecs = jiffies_to_msecs(jiffies - | ||
366 | softif_neigh->last_seen) % 1000; | ||
367 | seq_printf(seq, "%s %pM %3i.%03is\n", | ||
368 | curr_softif_neigh == softif_neigh | ||
369 | ? "=>" : " ", softif_neigh->addr, | ||
370 | last_seen_secs, last_seen_msecs); | ||
371 | } | ||
372 | |||
373 | if (curr_softif_neigh) | ||
374 | softif_neigh_free_ref(curr_softif_neigh); | ||
375 | |||
376 | seq_printf(seq, "\n"); | ||
377 | } | ||
244 | rcu_read_unlock(); | 378 | rcu_read_unlock(); |
245 | if (curr_softif_neigh) | ||
246 | softif_neigh_free_ref(curr_softif_neigh); | ||
247 | 379 | ||
248 | out: | 380 | out: |
249 | if (primary_if) | 381 | if (primary_if) |
@@ -251,6 +383,70 @@ out: | |||
251 | return ret; | 383 | return ret; |
252 | } | 384 | } |
253 | 385 | ||
386 | void softif_neigh_purge(struct bat_priv *bat_priv) | ||
387 | { | ||
388 | struct softif_neigh *softif_neigh, *curr_softif_neigh; | ||
389 | struct softif_neigh_vid *softif_neigh_vid; | ||
390 | struct hlist_node *node, *node_tmp, *node_tmp2; | ||
391 | char do_deselect; | ||
392 | |||
393 | rcu_read_lock(); | ||
394 | hlist_for_each_entry_rcu(softif_neigh_vid, node, | ||
395 | &bat_priv->softif_neigh_vids, list) { | ||
396 | if (!atomic_inc_not_zero(&softif_neigh_vid->refcount)) | ||
397 | continue; | ||
398 | |||
399 | curr_softif_neigh = softif_neigh_get_selected(softif_neigh_vid); | ||
400 | do_deselect = 0; | ||
401 | |||
402 | spin_lock_bh(&bat_priv->softif_neigh_lock); | ||
403 | hlist_for_each_entry_safe(softif_neigh, node_tmp, node_tmp2, | ||
404 | &softif_neigh_vid->softif_neigh_list, | ||
405 | list) { | ||
406 | if ((!time_after(jiffies, softif_neigh->last_seen + | ||
407 | msecs_to_jiffies(SOFTIF_NEIGH_TIMEOUT))) && | ||
408 | (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE)) | ||
409 | continue; | ||
410 | |||
411 | if (curr_softif_neigh == softif_neigh) { | ||
412 | bat_dbg(DBG_ROUTES, bat_priv, | ||
413 | "Current mesh exit point on vid: %d " | ||
414 | "'%pM' vanished.\n", | ||
415 | softif_neigh_vid->vid, | ||
416 | softif_neigh->addr); | ||
417 | do_deselect = 1; | ||
418 | } | ||
419 | |||
420 | hlist_del_rcu(&softif_neigh->list); | ||
421 | softif_neigh_free_ref(softif_neigh); | ||
422 | } | ||
423 | spin_unlock_bh(&bat_priv->softif_neigh_lock); | ||
424 | |||
425 | /* soft_neigh_vid_deselect() needs to acquire the | ||
426 | * softif_neigh_lock */ | ||
427 | if (do_deselect) | ||
428 | softif_neigh_vid_deselect(bat_priv, softif_neigh_vid); | ||
429 | |||
430 | if (curr_softif_neigh) | ||
431 | softif_neigh_free_ref(curr_softif_neigh); | ||
432 | |||
433 | softif_neigh_vid_free_ref(softif_neigh_vid); | ||
434 | } | ||
435 | rcu_read_unlock(); | ||
436 | |||
437 | spin_lock_bh(&bat_priv->softif_neigh_vid_lock); | ||
438 | hlist_for_each_entry_safe(softif_neigh_vid, node, node_tmp, | ||
439 | &bat_priv->softif_neigh_vids, list) { | ||
440 | if (!hlist_empty(&softif_neigh_vid->softif_neigh_list)) | ||
441 | continue; | ||
442 | |||
443 | hlist_del_rcu(&softif_neigh_vid->list); | ||
444 | softif_neigh_vid_free_ref(softif_neigh_vid); | ||
445 | } | ||
446 | spin_unlock_bh(&bat_priv->softif_neigh_vid_lock); | ||
447 | |||
448 | } | ||
449 | |||
254 | static void softif_batman_recv(struct sk_buff *skb, struct net_device *dev, | 450 | static void softif_batman_recv(struct sk_buff *skb, struct net_device *dev, |
255 | short vid) | 451 | short vid) |
256 | { | 452 | { |
@@ -283,10 +479,7 @@ static void softif_batman_recv(struct sk_buff *skb, struct net_device *dev, | |||
283 | if (!softif_neigh) | 479 | if (!softif_neigh) |
284 | goto out; | 480 | goto out; |
285 | 481 | ||
286 | curr_softif_neigh = softif_neigh_get_selected(bat_priv); | 482 | curr_softif_neigh = softif_neigh_vid_get_selected(bat_priv, vid); |
287 | if (!curr_softif_neigh) | ||
288 | goto out; | ||
289 | |||
290 | if (curr_softif_neigh == softif_neigh) | 483 | if (curr_softif_neigh == softif_neigh) |
291 | goto out; | 484 | goto out; |
292 | 485 | ||
@@ -299,33 +492,16 @@ static void softif_batman_recv(struct sk_buff *skb, struct net_device *dev, | |||
299 | softif_neigh->addr, ETH_ALEN) < 0) | 492 | softif_neigh->addr, ETH_ALEN) < 0) |
300 | goto out; | 493 | goto out; |
301 | 494 | ||
302 | /* switch to new 'smallest neighbor' */ | ||
303 | if ((curr_softif_neigh) && | ||
304 | (memcmp(softif_neigh->addr, curr_softif_neigh->addr, | ||
305 | ETH_ALEN) < 0)) { | ||
306 | bat_dbg(DBG_ROUTES, bat_priv, | ||
307 | "Changing mesh exit point from %pM (vid: %d) " | ||
308 | "to %pM (vid: %d).\n", | ||
309 | curr_softif_neigh->addr, | ||
310 | curr_softif_neigh->vid, | ||
311 | softif_neigh->addr, softif_neigh->vid); | ||
312 | |||
313 | softif_neigh_select(bat_priv, softif_neigh); | ||
314 | goto out; | ||
315 | } | ||
316 | |||
317 | /* close own batX device and use softif_neigh as exit node */ | 495 | /* close own batX device and use softif_neigh as exit node */ |
318 | if ((!curr_softif_neigh) && | 496 | if (!curr_softif_neigh) { |
319 | (memcmp(softif_neigh->addr, | 497 | softif_neigh_vid_select(bat_priv, softif_neigh, vid); |
320 | primary_if->net_dev->dev_addr, ETH_ALEN) < 0)) { | ||
321 | bat_dbg(DBG_ROUTES, bat_priv, | ||
322 | "Setting mesh exit point to %pM (vid: %d).\n", | ||
323 | softif_neigh->addr, softif_neigh->vid); | ||
324 | |||
325 | softif_neigh_select(bat_priv, softif_neigh); | ||
326 | goto out; | 498 | goto out; |
327 | } | 499 | } |
328 | 500 | ||
501 | /* switch to new 'smallest neighbor' */ | ||
502 | if (memcmp(softif_neigh->addr, curr_softif_neigh->addr, ETH_ALEN) < 0) | ||
503 | softif_neigh_vid_select(bat_priv, softif_neigh, vid); | ||
504 | |||
329 | out: | 505 | out: |
330 | kfree_skb(skb); | 506 | kfree_skb(skb); |
331 | if (softif_neigh) | 507 | if (softif_neigh) |
@@ -363,11 +539,11 @@ static int interface_set_mac_addr(struct net_device *dev, void *p) | |||
363 | if (!is_valid_ether_addr(addr->sa_data)) | 539 | if (!is_valid_ether_addr(addr->sa_data)) |
364 | return -EADDRNOTAVAIL; | 540 | return -EADDRNOTAVAIL; |
365 | 541 | ||
366 | /* only modify hna-table if it has been initialised before */ | 542 | /* only modify transtable if it has been initialised before */ |
367 | if (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) { | 543 | if (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) { |
368 | hna_local_remove(bat_priv, dev->dev_addr, | 544 | tt_local_remove(bat_priv, dev->dev_addr, |
369 | "mac address changed"); | 545 | "mac address changed"); |
370 | hna_local_add(dev, addr->sa_data); | 546 | tt_local_add(dev, addr->sa_data); |
371 | } | 547 | } |
372 | 548 | ||
373 | memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); | 549 | memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); |
@@ -420,12 +596,12 @@ int interface_tx(struct sk_buff *skb, struct net_device *soft_iface) | |||
420 | * if we have a another chosen mesh exit node in range | 596 | * if we have a another chosen mesh exit node in range |
421 | * it will transport the packets to the mesh | 597 | * it will transport the packets to the mesh |
422 | */ | 598 | */ |
423 | curr_softif_neigh = softif_neigh_get_selected(bat_priv); | 599 | curr_softif_neigh = softif_neigh_vid_get_selected(bat_priv, vid); |
424 | if ((curr_softif_neigh) && (curr_softif_neigh->vid == vid)) | 600 | if (curr_softif_neigh) |
425 | goto dropped; | 601 | goto dropped; |
426 | 602 | ||
427 | /* TODO: check this for locks */ | 603 | /* TODO: check this for locks */ |
428 | hna_local_add(soft_iface, ethhdr->h_source); | 604 | tt_local_add(soft_iface, ethhdr->h_source); |
429 | 605 | ||
430 | if (is_multicast_ether_addr(ethhdr->h_dest)) { | 606 | if (is_multicast_ether_addr(ethhdr->h_dest)) { |
431 | ret = gw_is_target(bat_priv, skb); | 607 | ret = gw_is_target(bat_priv, skb); |
@@ -529,8 +705,8 @@ void interface_rx(struct net_device *soft_iface, | |||
529 | * if we have a another chosen mesh exit node in range | 705 | * if we have a another chosen mesh exit node in range |
530 | * it will transport the packets to the non-mesh network | 706 | * it will transport the packets to the non-mesh network |
531 | */ | 707 | */ |
532 | curr_softif_neigh = softif_neigh_get_selected(bat_priv); | 708 | curr_softif_neigh = softif_neigh_vid_get_selected(bat_priv, vid); |
533 | if (curr_softif_neigh && (curr_softif_neigh->vid == vid)) { | 709 | if (curr_softif_neigh) { |
534 | skb_push(skb, hdr_size); | 710 | skb_push(skb, hdr_size); |
535 | unicast_packet = (struct unicast_packet *)skb->data; | 711 | unicast_packet = (struct unicast_packet *)skb->data; |
536 | 712 | ||
@@ -613,8 +789,8 @@ static void interface_setup(struct net_device *dev) | |||
613 | * have not been initialized yet | 789 | * have not been initialized yet |
614 | */ | 790 | */ |
615 | dev->mtu = ETH_DATA_LEN; | 791 | dev->mtu = ETH_DATA_LEN; |
616 | dev->hard_header_len = BAT_HEADER_LEN; /* reserve more space in the | 792 | /* reserve more space in the skbuff for our header */ |
617 | * skbuff for our header */ | 793 | dev->hard_header_len = BAT_HEADER_LEN; |
618 | 794 | ||
619 | /* generate random address */ | 795 | /* generate random address */ |
620 | random_ether_addr(dev_addr); | 796 | random_ether_addr(dev_addr); |
@@ -639,7 +815,7 @@ struct net_device *softif_create(char *name) | |||
639 | goto out; | 815 | goto out; |
640 | } | 816 | } |
641 | 817 | ||
642 | ret = register_netdev(soft_iface); | 818 | ret = register_netdevice(soft_iface); |
643 | if (ret < 0) { | 819 | if (ret < 0) { |
644 | pr_err("Unable to register the batman interface '%s': %i\n", | 820 | pr_err("Unable to register the batman interface '%s': %i\n", |
645 | name, ret); | 821 | name, ret); |
@@ -663,11 +839,10 @@ struct net_device *softif_create(char *name) | |||
663 | 839 | ||
664 | atomic_set(&bat_priv->mesh_state, MESH_INACTIVE); | 840 | atomic_set(&bat_priv->mesh_state, MESH_INACTIVE); |
665 | atomic_set(&bat_priv->bcast_seqno, 1); | 841 | atomic_set(&bat_priv->bcast_seqno, 1); |
666 | atomic_set(&bat_priv->hna_local_changed, 0); | 842 | atomic_set(&bat_priv->tt_local_changed, 0); |
667 | 843 | ||
668 | bat_priv->primary_if = NULL; | 844 | bat_priv->primary_if = NULL; |
669 | bat_priv->num_ifaces = 0; | 845 | bat_priv->num_ifaces = 0; |
670 | bat_priv->softif_neigh = NULL; | ||
671 | 846 | ||
672 | ret = sysfs_add_meshif(soft_iface); | 847 | ret = sysfs_add_meshif(soft_iface); |
673 | if (ret < 0) | 848 | if (ret < 0) |