aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/hard-interface.c
diff options
context:
space:
mode:
authorMarek Lindner <lindner_marek@yahoo.de>2011-02-18 07:33:20 -0500
committerMarek Lindner <lindner_marek@yahoo.de>2011-03-05 06:52:06 -0500
commite6c10f433af9c98994c94a10ae862c152fcfb2a9 (patch)
tree56b4a82b83da44f7c3657a283c92c5cc8e248b9f /net/batman-adv/hard-interface.c
parent4389e47af856635eb17d03b2572a50576c12db24 (diff)
batman-adv: rename batman_if struct to hard_iface
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Diffstat (limited to 'net/batman-adv/hard-interface.c')
-rw-r--r--net/batman-adv/hard-interface.c353
1 files changed, 177 insertions, 176 deletions
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 4a2e6e33ebc0..95a35b695700 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -42,29 +42,29 @@ static int batman_skb_recv(struct sk_buff *skb,
42 42
43void hardif_free_rcu(struct rcu_head *rcu) 43void hardif_free_rcu(struct rcu_head *rcu)
44{ 44{
45 struct batman_if *batman_if; 45 struct hard_iface *hard_iface;
46 46
47 batman_if = container_of(rcu, struct batman_if, rcu); 47 hard_iface = container_of(rcu, struct hard_iface, rcu);
48 dev_put(batman_if->net_dev); 48 dev_put(hard_iface->net_dev);
49 kfree(batman_if); 49 kfree(hard_iface);
50} 50}
51 51
52struct batman_if *get_batman_if_by_netdev(struct net_device *net_dev) 52struct hard_iface *hardif_get_by_netdev(struct net_device *net_dev)
53{ 53{
54 struct batman_if *batman_if; 54 struct hard_iface *hard_iface;
55 55
56 rcu_read_lock(); 56 rcu_read_lock();
57 list_for_each_entry_rcu(batman_if, &hardif_list, list) { 57 list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
58 if (batman_if->net_dev == net_dev && 58 if (hard_iface->net_dev == net_dev &&
59 atomic_inc_not_zero(&batman_if->refcount)) 59 atomic_inc_not_zero(&hard_iface->refcount))
60 goto out; 60 goto out;
61 } 61 }
62 62
63 batman_if = NULL; 63 hard_iface = NULL;
64 64
65out: 65out:
66 rcu_read_unlock(); 66 rcu_read_unlock();
67 return batman_if; 67 return hard_iface;
68} 68}
69 69
70static int is_valid_iface(struct net_device *net_dev) 70static int is_valid_iface(struct net_device *net_dev)
@@ -94,25 +94,25 @@ static int is_valid_iface(struct net_device *net_dev)
94 return 1; 94 return 1;
95} 95}
96 96
97static struct batman_if *get_active_batman_if(struct net_device *soft_iface) 97static struct hard_iface *hardif_get_active(struct net_device *soft_iface)
98{ 98{
99 struct batman_if *batman_if; 99 struct hard_iface *hard_iface;
100 100
101 rcu_read_lock(); 101 rcu_read_lock();
102 list_for_each_entry_rcu(batman_if, &hardif_list, list) { 102 list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
103 if (batman_if->soft_iface != soft_iface) 103 if (hard_iface->soft_iface != soft_iface)
104 continue; 104 continue;
105 105
106 if (batman_if->if_status == IF_ACTIVE && 106 if (hard_iface->if_status == IF_ACTIVE &&
107 atomic_inc_not_zero(&batman_if->refcount)) 107 atomic_inc_not_zero(&hard_iface->refcount))
108 goto out; 108 goto out;
109 } 109 }
110 110
111 batman_if = NULL; 111 hard_iface = NULL;
112 112
113out: 113out:
114 rcu_read_unlock(); 114 rcu_read_unlock();
115 return batman_if; 115 return hard_iface;
116} 116}
117 117
118static void update_primary_addr(struct bat_priv *bat_priv) 118static void update_primary_addr(struct bat_priv *bat_priv)
@@ -128,16 +128,16 @@ static void update_primary_addr(struct bat_priv *bat_priv)
128} 128}
129 129
130static void set_primary_if(struct bat_priv *bat_priv, 130static void set_primary_if(struct bat_priv *bat_priv,
131 struct batman_if *batman_if) 131 struct hard_iface *hard_iface)
132{ 132{
133 struct batman_packet *batman_packet; 133 struct batman_packet *batman_packet;
134 struct batman_if *old_if; 134 struct hard_iface *old_if;
135 135
136 if (batman_if && !atomic_inc_not_zero(&batman_if->refcount)) 136 if (hard_iface && !atomic_inc_not_zero(&hard_iface->refcount))
137 batman_if = NULL; 137 hard_iface = NULL;
138 138
139 old_if = bat_priv->primary_if; 139 old_if = bat_priv->primary_if;
140 bat_priv->primary_if = batman_if; 140 bat_priv->primary_if = hard_iface;
141 141
142 if (old_if) 142 if (old_if)
143 hardif_free_ref(old_if); 143 hardif_free_ref(old_if);
@@ -145,7 +145,7 @@ static void set_primary_if(struct bat_priv *bat_priv,
145 if (!bat_priv->primary_if) 145 if (!bat_priv->primary_if)
146 return; 146 return;
147 147
148 batman_packet = (struct batman_packet *)(batman_if->packet_buff); 148 batman_packet = (struct batman_packet *)(hard_iface->packet_buff);
149 batman_packet->flags = PRIMARIES_FIRST_HOP; 149 batman_packet->flags = PRIMARIES_FIRST_HOP;
150 batman_packet->ttl = TTL; 150 batman_packet->ttl = TTL;
151 151
@@ -158,42 +158,42 @@ static void set_primary_if(struct bat_priv *bat_priv,
158 atomic_set(&bat_priv->hna_local_changed, 1); 158 atomic_set(&bat_priv->hna_local_changed, 1);
159} 159}
160 160
161static bool hardif_is_iface_up(struct batman_if *batman_if) 161static bool hardif_is_iface_up(struct hard_iface *hard_iface)
162{ 162{
163 if (batman_if->net_dev->flags & IFF_UP) 163 if (hard_iface->net_dev->flags & IFF_UP)
164 return true; 164 return true;
165 165
166 return false; 166 return false;
167} 167}
168 168
169static void update_mac_addresses(struct batman_if *batman_if) 169static void update_mac_addresses(struct hard_iface *hard_iface)
170{ 170{
171 memcpy(((struct batman_packet *)(batman_if->packet_buff))->orig, 171 memcpy(((struct batman_packet *)(hard_iface->packet_buff))->orig,
172 batman_if->net_dev->dev_addr, ETH_ALEN); 172 hard_iface->net_dev->dev_addr, ETH_ALEN);
173 memcpy(((struct batman_packet *)(batman_if->packet_buff))->prev_sender, 173 memcpy(((struct batman_packet *)(hard_iface->packet_buff))->prev_sender,
174 batman_if->net_dev->dev_addr, ETH_ALEN); 174 hard_iface->net_dev->dev_addr, ETH_ALEN);
175} 175}
176 176
177static void check_known_mac_addr(struct net_device *net_dev) 177static void check_known_mac_addr(struct net_device *net_dev)
178{ 178{
179 struct batman_if *batman_if; 179 struct hard_iface *hard_iface;
180 180
181 rcu_read_lock(); 181 rcu_read_lock();
182 list_for_each_entry_rcu(batman_if, &hardif_list, list) { 182 list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
183 if ((batman_if->if_status != IF_ACTIVE) && 183 if ((hard_iface->if_status != IF_ACTIVE) &&
184 (batman_if->if_status != IF_TO_BE_ACTIVATED)) 184 (hard_iface->if_status != IF_TO_BE_ACTIVATED))
185 continue; 185 continue;
186 186
187 if (batman_if->net_dev == net_dev) 187 if (hard_iface->net_dev == net_dev)
188 continue; 188 continue;
189 189
190 if (!compare_eth(batman_if->net_dev->dev_addr, 190 if (!compare_eth(hard_iface->net_dev->dev_addr,
191 net_dev->dev_addr)) 191 net_dev->dev_addr))
192 continue; 192 continue;
193 193
194 pr_warning("The newly added mac address (%pM) already exists " 194 pr_warning("The newly added mac address (%pM) already exists "
195 "on: %s\n", net_dev->dev_addr, 195 "on: %s\n", net_dev->dev_addr,
196 batman_if->net_dev->name); 196 hard_iface->net_dev->name);
197 pr_warning("It is strongly recommended to keep mac addresses " 197 pr_warning("It is strongly recommended to keep mac addresses "
198 "unique to avoid problems!\n"); 198 "unique to avoid problems!\n");
199 } 199 }
@@ -203,7 +203,7 @@ static void check_known_mac_addr(struct net_device *net_dev)
203int hardif_min_mtu(struct net_device *soft_iface) 203int hardif_min_mtu(struct net_device *soft_iface)
204{ 204{
205 struct bat_priv *bat_priv = netdev_priv(soft_iface); 205 struct bat_priv *bat_priv = netdev_priv(soft_iface);
206 struct batman_if *batman_if; 206 struct hard_iface *hard_iface;
207 /* allow big frames if all devices are capable to do so 207 /* allow big frames if all devices are capable to do so
208 * (have MTU > 1500 + BAT_HEADER_LEN) */ 208 * (have MTU > 1500 + BAT_HEADER_LEN) */
209 int min_mtu = ETH_DATA_LEN; 209 int min_mtu = ETH_DATA_LEN;
@@ -212,15 +212,15 @@ int hardif_min_mtu(struct net_device *soft_iface)
212 goto out; 212 goto out;
213 213
214 rcu_read_lock(); 214 rcu_read_lock();
215 list_for_each_entry_rcu(batman_if, &hardif_list, list) { 215 list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
216 if ((batman_if->if_status != IF_ACTIVE) && 216 if ((hard_iface->if_status != IF_ACTIVE) &&
217 (batman_if->if_status != IF_TO_BE_ACTIVATED)) 217 (hard_iface->if_status != IF_TO_BE_ACTIVATED))
218 continue; 218 continue;
219 219
220 if (batman_if->soft_iface != soft_iface) 220 if (hard_iface->soft_iface != soft_iface)
221 continue; 221 continue;
222 222
223 min_mtu = min_t(int, batman_if->net_dev->mtu - BAT_HEADER_LEN, 223 min_mtu = min_t(int, hard_iface->net_dev->mtu - BAT_HEADER_LEN,
224 min_mtu); 224 min_mtu);
225 } 225 }
226 rcu_read_unlock(); 226 rcu_read_unlock();
@@ -238,80 +238,80 @@ void update_min_mtu(struct net_device *soft_iface)
238 soft_iface->mtu = min_mtu; 238 soft_iface->mtu = min_mtu;
239} 239}
240 240
241static void hardif_activate_interface(struct batman_if *batman_if) 241static void hardif_activate_interface(struct hard_iface *hard_iface)
242{ 242{
243 struct bat_priv *bat_priv; 243 struct bat_priv *bat_priv;
244 244
245 if (batman_if->if_status != IF_INACTIVE) 245 if (hard_iface->if_status != IF_INACTIVE)
246 return; 246 return;
247 247
248 bat_priv = netdev_priv(batman_if->soft_iface); 248 bat_priv = netdev_priv(hard_iface->soft_iface);
249 249
250 update_mac_addresses(batman_if); 250 update_mac_addresses(hard_iface);
251 batman_if->if_status = IF_TO_BE_ACTIVATED; 251 hard_iface->if_status = IF_TO_BE_ACTIVATED;
252 252
253 /** 253 /**
254 * the first active interface becomes our primary interface or 254 * the first active interface becomes our primary interface or
255 * the next active interface after the old primay interface was removed 255 * the next active interface after the old primay interface was removed
256 */ 256 */
257 if (!bat_priv->primary_if) 257 if (!bat_priv->primary_if)
258 set_primary_if(bat_priv, batman_if); 258 set_primary_if(bat_priv, hard_iface);
259 259
260 bat_info(batman_if->soft_iface, "Interface activated: %s\n", 260 bat_info(hard_iface->soft_iface, "Interface activated: %s\n",
261 batman_if->net_dev->name); 261 hard_iface->net_dev->name);
262 262
263 update_min_mtu(batman_if->soft_iface); 263 update_min_mtu(hard_iface->soft_iface);
264 return; 264 return;
265} 265}
266 266
267static void hardif_deactivate_interface(struct batman_if *batman_if) 267static void hardif_deactivate_interface(struct hard_iface *hard_iface)
268{ 268{
269 if ((batman_if->if_status != IF_ACTIVE) && 269 if ((hard_iface->if_status != IF_ACTIVE) &&
270 (batman_if->if_status != IF_TO_BE_ACTIVATED)) 270 (hard_iface->if_status != IF_TO_BE_ACTIVATED))
271 return; 271 return;
272 272
273 batman_if->if_status = IF_INACTIVE; 273 hard_iface->if_status = IF_INACTIVE;
274 274
275 bat_info(batman_if->soft_iface, "Interface deactivated: %s\n", 275 bat_info(hard_iface->soft_iface, "Interface deactivated: %s\n",
276 batman_if->net_dev->name); 276 hard_iface->net_dev->name);
277 277
278 update_min_mtu(batman_if->soft_iface); 278 update_min_mtu(hard_iface->soft_iface);
279} 279}
280 280
281int hardif_enable_interface(struct batman_if *batman_if, char *iface_name) 281int hardif_enable_interface(struct hard_iface *hard_iface, char *iface_name)
282{ 282{
283 struct bat_priv *bat_priv; 283 struct bat_priv *bat_priv;
284 struct batman_packet *batman_packet; 284 struct batman_packet *batman_packet;
285 285
286 if (batman_if->if_status != IF_NOT_IN_USE) 286 if (hard_iface->if_status != IF_NOT_IN_USE)
287 goto out; 287 goto out;
288 288
289 if (!atomic_inc_not_zero(&batman_if->refcount)) 289 if (!atomic_inc_not_zero(&hard_iface->refcount))
290 goto out; 290 goto out;
291 291
292 batman_if->soft_iface = dev_get_by_name(&init_net, iface_name); 292 hard_iface->soft_iface = dev_get_by_name(&init_net, iface_name);
293 293
294 if (!batman_if->soft_iface) { 294 if (!hard_iface->soft_iface) {
295 batman_if->soft_iface = softif_create(iface_name); 295 hard_iface->soft_iface = softif_create(iface_name);
296 296
297 if (!batman_if->soft_iface) 297 if (!hard_iface->soft_iface)
298 goto err; 298 goto err;
299 299
300 /* dev_get_by_name() increases the reference counter for us */ 300 /* dev_get_by_name() increases the reference counter for us */
301 dev_hold(batman_if->soft_iface); 301 dev_hold(hard_iface->soft_iface);
302 } 302 }
303 303
304 bat_priv = netdev_priv(batman_if->soft_iface); 304 bat_priv = netdev_priv(hard_iface->soft_iface);
305 batman_if->packet_len = BAT_PACKET_LEN; 305 hard_iface->packet_len = BAT_PACKET_LEN;
306 batman_if->packet_buff = kmalloc(batman_if->packet_len, GFP_ATOMIC); 306 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
307 307
308 if (!batman_if->packet_buff) { 308 if (!hard_iface->packet_buff) {
309 bat_err(batman_if->soft_iface, "Can't add interface packet " 309 bat_err(hard_iface->soft_iface, "Can't add interface packet "
310 "(%s): out of memory\n", batman_if->net_dev->name); 310 "(%s): out of memory\n", hard_iface->net_dev->name);
311 goto err; 311 goto err;
312 } 312 }
313 313
314 batman_packet = (struct batman_packet *)(batman_if->packet_buff); 314 batman_packet = (struct batman_packet *)(hard_iface->packet_buff);
315 batman_packet->packet_type = BAT_PACKET; 315 batman_packet->packet_type = BAT_PACKET;
316 batman_packet->version = COMPAT_VERSION; 316 batman_packet->version = COMPAT_VERSION;
317 batman_packet->flags = 0; 317 batman_packet->flags = 0;
@@ -319,107 +319,107 @@ int hardif_enable_interface(struct batman_if *batman_if, char *iface_name)
319 batman_packet->tq = TQ_MAX_VALUE; 319 batman_packet->tq = TQ_MAX_VALUE;
320 batman_packet->num_hna = 0; 320 batman_packet->num_hna = 0;
321 321
322 batman_if->if_num = bat_priv->num_ifaces; 322 hard_iface->if_num = bat_priv->num_ifaces;
323 bat_priv->num_ifaces++; 323 bat_priv->num_ifaces++;
324 batman_if->if_status = IF_INACTIVE; 324 hard_iface->if_status = IF_INACTIVE;
325 orig_hash_add_if(batman_if, bat_priv->num_ifaces); 325 orig_hash_add_if(hard_iface, bat_priv->num_ifaces);
326 326
327 batman_if->batman_adv_ptype.type = __constant_htons(ETH_P_BATMAN); 327 hard_iface->batman_adv_ptype.type = __constant_htons(ETH_P_BATMAN);
328 batman_if->batman_adv_ptype.func = batman_skb_recv; 328 hard_iface->batman_adv_ptype.func = batman_skb_recv;
329 batman_if->batman_adv_ptype.dev = batman_if->net_dev; 329 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
330 dev_add_pack(&batman_if->batman_adv_ptype); 330 dev_add_pack(&hard_iface->batman_adv_ptype);
331 331
332 atomic_set(&batman_if->seqno, 1); 332 atomic_set(&hard_iface->seqno, 1);
333 atomic_set(&batman_if->frag_seqno, 1); 333 atomic_set(&hard_iface->frag_seqno, 1);
334 bat_info(batman_if->soft_iface, "Adding interface: %s\n", 334 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
335 batman_if->net_dev->name); 335 hard_iface->net_dev->name);
336 336
337 if (atomic_read(&bat_priv->fragmentation) && batman_if->net_dev->mtu < 337 if (atomic_read(&bat_priv->fragmentation) && hard_iface->net_dev->mtu <
338 ETH_DATA_LEN + BAT_HEADER_LEN) 338 ETH_DATA_LEN + BAT_HEADER_LEN)
339 bat_info(batman_if->soft_iface, 339 bat_info(hard_iface->soft_iface,
340 "The MTU of interface %s is too small (%i) to handle " 340 "The MTU of interface %s is too small (%i) to handle "
341 "the transport of batman-adv packets. Packets going " 341 "the transport of batman-adv packets. Packets going "
342 "over this interface will be fragmented on layer2 " 342 "over this interface will be fragmented on layer2 "
343 "which could impact the performance. Setting the MTU " 343 "which could impact the performance. Setting the MTU "
344 "to %zi would solve the problem.\n", 344 "to %zi would solve the problem.\n",
345 batman_if->net_dev->name, batman_if->net_dev->mtu, 345 hard_iface->net_dev->name, hard_iface->net_dev->mtu,
346 ETH_DATA_LEN + BAT_HEADER_LEN); 346 ETH_DATA_LEN + BAT_HEADER_LEN);
347 347
348 if (!atomic_read(&bat_priv->fragmentation) && batman_if->net_dev->mtu < 348 if (!atomic_read(&bat_priv->fragmentation) && hard_iface->net_dev->mtu <
349 ETH_DATA_LEN + BAT_HEADER_LEN) 349 ETH_DATA_LEN + BAT_HEADER_LEN)
350 bat_info(batman_if->soft_iface, 350 bat_info(hard_iface->soft_iface,
351 "The MTU of interface %s is too small (%i) to handle " 351 "The MTU of interface %s is too small (%i) to handle "
352 "the transport of batman-adv packets. If you experience" 352 "the transport of batman-adv packets. If you experience"
353 " problems getting traffic through try increasing the " 353 " problems getting traffic through try increasing the "
354 "MTU to %zi.\n", 354 "MTU to %zi.\n",
355 batman_if->net_dev->name, batman_if->net_dev->mtu, 355 hard_iface->net_dev->name, hard_iface->net_dev->mtu,
356 ETH_DATA_LEN + BAT_HEADER_LEN); 356 ETH_DATA_LEN + BAT_HEADER_LEN);
357 357
358 if (hardif_is_iface_up(batman_if)) 358 if (hardif_is_iface_up(hard_iface))
359 hardif_activate_interface(batman_if); 359 hardif_activate_interface(hard_iface);
360 else 360 else
361 bat_err(batman_if->soft_iface, "Not using interface %s " 361 bat_err(hard_iface->soft_iface, "Not using interface %s "
362 "(retrying later): interface not active\n", 362 "(retrying later): interface not active\n",
363 batman_if->net_dev->name); 363 hard_iface->net_dev->name);
364 364
365 /* begin scheduling originator messages on that interface */ 365 /* begin scheduling originator messages on that interface */
366 schedule_own_packet(batman_if); 366 schedule_own_packet(hard_iface);
367 367
368out: 368out:
369 return 0; 369 return 0;
370 370
371err: 371err:
372 hardif_free_ref(batman_if); 372 hardif_free_ref(hard_iface);
373 return -ENOMEM; 373 return -ENOMEM;
374} 374}
375 375
376void hardif_disable_interface(struct batman_if *batman_if) 376void hardif_disable_interface(struct hard_iface *hard_iface)
377{ 377{
378 struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface); 378 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
379 379
380 if (batman_if->if_status == IF_ACTIVE) 380 if (hard_iface->if_status == IF_ACTIVE)
381 hardif_deactivate_interface(batman_if); 381 hardif_deactivate_interface(hard_iface);
382 382
383 if (batman_if->if_status != IF_INACTIVE) 383 if (hard_iface->if_status != IF_INACTIVE)
384 return; 384 return;
385 385
386 bat_info(batman_if->soft_iface, "Removing interface: %s\n", 386 bat_info(hard_iface->soft_iface, "Removing interface: %s\n",
387 batman_if->net_dev->name); 387 hard_iface->net_dev->name);
388 dev_remove_pack(&batman_if->batman_adv_ptype); 388 dev_remove_pack(&hard_iface->batman_adv_ptype);
389 389
390 bat_priv->num_ifaces--; 390 bat_priv->num_ifaces--;
391 orig_hash_del_if(batman_if, bat_priv->num_ifaces); 391 orig_hash_del_if(hard_iface, bat_priv->num_ifaces);
392 392
393 if (batman_if == bat_priv->primary_if) { 393 if (hard_iface == bat_priv->primary_if) {
394 struct batman_if *new_if; 394 struct hard_iface *new_if;
395 395
396 new_if = get_active_batman_if(batman_if->soft_iface); 396 new_if = hardif_get_active(hard_iface->soft_iface);
397 set_primary_if(bat_priv, new_if); 397 set_primary_if(bat_priv, new_if);
398 398
399 if (new_if) 399 if (new_if)
400 hardif_free_ref(new_if); 400 hardif_free_ref(new_if);
401 } 401 }
402 402
403 kfree(batman_if->packet_buff); 403 kfree(hard_iface->packet_buff);
404 batman_if->packet_buff = NULL; 404 hard_iface->packet_buff = NULL;
405 batman_if->if_status = IF_NOT_IN_USE; 405 hard_iface->if_status = IF_NOT_IN_USE;
406 406
407 /* delete all references to this batman_if */ 407 /* delete all references to this hard_iface */
408 purge_orig_ref(bat_priv); 408 purge_orig_ref(bat_priv);
409 purge_outstanding_packets(bat_priv, batman_if); 409 purge_outstanding_packets(bat_priv, hard_iface);
410 dev_put(batman_if->soft_iface); 410 dev_put(hard_iface->soft_iface);
411 411
412 /* nobody uses this interface anymore */ 412 /* nobody uses this interface anymore */
413 if (!bat_priv->num_ifaces) 413 if (!bat_priv->num_ifaces)
414 softif_destroy(batman_if->soft_iface); 414 softif_destroy(hard_iface->soft_iface);
415 415
416 batman_if->soft_iface = NULL; 416 hard_iface->soft_iface = NULL;
417 hardif_free_ref(batman_if); 417 hardif_free_ref(hard_iface);
418} 418}
419 419
420static struct batman_if *hardif_add_interface(struct net_device *net_dev) 420static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
421{ 421{
422 struct batman_if *batman_if; 422 struct hard_iface *hard_iface;
423 int ret; 423 int ret;
424 424
425 ret = is_valid_iface(net_dev); 425 ret = is_valid_iface(net_dev);
@@ -428,72 +428,73 @@ static struct batman_if *hardif_add_interface(struct net_device *net_dev)
428 428
429 dev_hold(net_dev); 429 dev_hold(net_dev);
430 430
431 batman_if = kmalloc(sizeof(struct batman_if), GFP_ATOMIC); 431 hard_iface = kmalloc(sizeof(struct hard_iface), GFP_ATOMIC);
432 if (!batman_if) { 432 if (!hard_iface) {
433 pr_err("Can't add interface (%s): out of memory\n", 433 pr_err("Can't add interface (%s): out of memory\n",
434 net_dev->name); 434 net_dev->name);
435 goto release_dev; 435 goto release_dev;
436 } 436 }
437 437
438 ret = sysfs_add_hardif(&batman_if->hardif_obj, net_dev); 438 ret = sysfs_add_hardif(&hard_iface->hardif_obj, net_dev);
439 if (ret) 439 if (ret)
440 goto free_if; 440 goto free_if;
441 441
442 batman_if->if_num = -1; 442 hard_iface->if_num = -1;
443 batman_if->net_dev = net_dev; 443 hard_iface->net_dev = net_dev;
444 batman_if->soft_iface = NULL; 444 hard_iface->soft_iface = NULL;
445 batman_if->if_status = IF_NOT_IN_USE; 445 hard_iface->if_status = IF_NOT_IN_USE;
446 INIT_LIST_HEAD(&batman_if->list); 446 INIT_LIST_HEAD(&hard_iface->list);
447 /* extra reference for return */ 447 /* extra reference for return */
448 atomic_set(&batman_if->refcount, 2); 448 atomic_set(&hard_iface->refcount, 2);
449 449
450 check_known_mac_addr(batman_if->net_dev); 450 check_known_mac_addr(hard_iface->net_dev);
451 451
452 spin_lock(&hardif_list_lock); 452 spin_lock(&hardif_list_lock);
453 list_add_tail_rcu(&batman_if->list, &hardif_list); 453 list_add_tail_rcu(&hard_iface->list, &hardif_list);
454 spin_unlock(&hardif_list_lock); 454 spin_unlock(&hardif_list_lock);
455 455
456 return batman_if; 456 return hard_iface;
457 457
458free_if: 458free_if:
459 kfree(batman_if); 459 kfree(hard_iface);
460release_dev: 460release_dev:
461 dev_put(net_dev); 461 dev_put(net_dev);
462out: 462out:
463 return NULL; 463 return NULL;
464} 464}
465 465
466static void hardif_remove_interface(struct batman_if *batman_if) 466static void hardif_remove_interface(struct hard_iface *hard_iface)
467{ 467{
468 /* first deactivate interface */ 468 /* first deactivate interface */
469 if (batman_if->if_status != IF_NOT_IN_USE) 469 if (hard_iface->if_status != IF_NOT_IN_USE)
470 hardif_disable_interface(batman_if); 470 hardif_disable_interface(hard_iface);
471 471
472 if (batman_if->if_status != IF_NOT_IN_USE) 472 if (hard_iface->if_status != IF_NOT_IN_USE)
473 return; 473 return;
474 474
475 batman_if->if_status = IF_TO_BE_REMOVED; 475 hard_iface->if_status = IF_TO_BE_REMOVED;
476 sysfs_del_hardif(&batman_if->hardif_obj); 476 sysfs_del_hardif(&hard_iface->hardif_obj);
477 hardif_free_ref(batman_if); 477 hardif_free_ref(hard_iface);
478} 478}
479 479
480void hardif_remove_interfaces(void) 480void hardif_remove_interfaces(void)
481{ 481{
482 struct batman_if *batman_if, *batman_if_tmp; 482 struct hard_iface *hard_iface, *hard_iface_tmp;
483 struct list_head if_queue; 483 struct list_head if_queue;
484 484
485 INIT_LIST_HEAD(&if_queue); 485 INIT_LIST_HEAD(&if_queue);
486 486
487 spin_lock(&hardif_list_lock); 487 spin_lock(&hardif_list_lock);
488 list_for_each_entry_safe(batman_if, batman_if_tmp, &hardif_list, list) { 488 list_for_each_entry_safe(hard_iface, hard_iface_tmp,
489 list_del_rcu(&batman_if->list); 489 &hardif_list, list) {
490 list_add_tail(&batman_if->list, &if_queue); 490 list_del_rcu(&hard_iface->list);
491 list_add_tail(&hard_iface->list, &if_queue);
491 } 492 }
492 spin_unlock(&hardif_list_lock); 493 spin_unlock(&hardif_list_lock);
493 494
494 rtnl_lock(); 495 rtnl_lock();
495 list_for_each_entry_safe(batman_if, batman_if_tmp, &if_queue, list) { 496 list_for_each_entry_safe(hard_iface, hard_iface_tmp, &if_queue, list) {
496 hardif_remove_interface(batman_if); 497 hardif_remove_interface(hard_iface);
497 } 498 }
498 rtnl_unlock(); 499 rtnl_unlock();
499} 500}
@@ -502,43 +503,43 @@ static int hard_if_event(struct notifier_block *this,
502 unsigned long event, void *ptr) 503 unsigned long event, void *ptr)
503{ 504{
504 struct net_device *net_dev = (struct net_device *)ptr; 505 struct net_device *net_dev = (struct net_device *)ptr;
505 struct batman_if *batman_if = get_batman_if_by_netdev(net_dev); 506 struct hard_iface *hard_iface = hardif_get_by_netdev(net_dev);
506 struct bat_priv *bat_priv; 507 struct bat_priv *bat_priv;
507 508
508 if (!batman_if && event == NETDEV_REGISTER) 509 if (!hard_iface && event == NETDEV_REGISTER)
509 batman_if = hardif_add_interface(net_dev); 510 hard_iface = hardif_add_interface(net_dev);
510 511
511 if (!batman_if) 512 if (!hard_iface)
512 goto out; 513 goto out;
513 514
514 switch (event) { 515 switch (event) {
515 case NETDEV_UP: 516 case NETDEV_UP:
516 hardif_activate_interface(batman_if); 517 hardif_activate_interface(hard_iface);
517 break; 518 break;
518 case NETDEV_GOING_DOWN: 519 case NETDEV_GOING_DOWN:
519 case NETDEV_DOWN: 520 case NETDEV_DOWN:
520 hardif_deactivate_interface(batman_if); 521 hardif_deactivate_interface(hard_iface);
521 break; 522 break;
522 case NETDEV_UNREGISTER: 523 case NETDEV_UNREGISTER:
523 spin_lock(&hardif_list_lock); 524 spin_lock(&hardif_list_lock);
524 list_del_rcu(&batman_if->list); 525 list_del_rcu(&hard_iface->list);
525 spin_unlock(&hardif_list_lock); 526 spin_unlock(&hardif_list_lock);
526 527
527 hardif_remove_interface(batman_if); 528 hardif_remove_interface(hard_iface);
528 break; 529 break;
529 case NETDEV_CHANGEMTU: 530 case NETDEV_CHANGEMTU:
530 if (batman_if->soft_iface) 531 if (hard_iface->soft_iface)
531 update_min_mtu(batman_if->soft_iface); 532 update_min_mtu(hard_iface->soft_iface);
532 break; 533 break;
533 case NETDEV_CHANGEADDR: 534 case NETDEV_CHANGEADDR:
534 if (batman_if->if_status == IF_NOT_IN_USE) 535 if (hard_iface->if_status == IF_NOT_IN_USE)
535 goto hardif_put; 536 goto hardif_put;
536 537
537 check_known_mac_addr(batman_if->net_dev); 538 check_known_mac_addr(hard_iface->net_dev);
538 update_mac_addresses(batman_if); 539 update_mac_addresses(hard_iface);
539 540
540 bat_priv = netdev_priv(batman_if->soft_iface); 541 bat_priv = netdev_priv(hard_iface->soft_iface);
541 if (batman_if == bat_priv->primary_if) 542 if (hard_iface == bat_priv->primary_if)
542 update_primary_addr(bat_priv); 543 update_primary_addr(bat_priv);
543 break; 544 break;
544 default: 545 default:
@@ -546,7 +547,7 @@ static int hard_if_event(struct notifier_block *this,
546 }; 547 };
547 548
548hardif_put: 549hardif_put:
549 hardif_free_ref(batman_if); 550 hardif_free_ref(hard_iface);
550out: 551out:
551 return NOTIFY_DONE; 552 return NOTIFY_DONE;
552} 553}
@@ -559,10 +560,10 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
559{ 560{
560 struct bat_priv *bat_priv; 561 struct bat_priv *bat_priv;
561 struct batman_packet *batman_packet; 562 struct batman_packet *batman_packet;
562 struct batman_if *batman_if; 563 struct hard_iface *hard_iface;
563 int ret; 564 int ret;
564 565
565 batman_if = container_of(ptype, struct batman_if, batman_adv_ptype); 566 hard_iface = container_of(ptype, struct hard_iface, batman_adv_ptype);
566 skb = skb_share_check(skb, GFP_ATOMIC); 567 skb = skb_share_check(skb, GFP_ATOMIC);
567 568
568 /* skb was released by skb_share_check() */ 569 /* skb was released by skb_share_check() */
@@ -578,16 +579,16 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
578 || !skb_mac_header(skb))) 579 || !skb_mac_header(skb)))
579 goto err_free; 580 goto err_free;
580 581
581 if (!batman_if->soft_iface) 582 if (!hard_iface->soft_iface)
582 goto err_free; 583 goto err_free;
583 584
584 bat_priv = netdev_priv(batman_if->soft_iface); 585 bat_priv = netdev_priv(hard_iface->soft_iface);
585 586
586 if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE) 587 if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE)
587 goto err_free; 588 goto err_free;
588 589
589 /* discard frames on not active interfaces */ 590 /* discard frames on not active interfaces */
590 if (batman_if->if_status != IF_ACTIVE) 591 if (hard_iface->if_status != IF_ACTIVE)
591 goto err_free; 592 goto err_free;
592 593
593 batman_packet = (struct batman_packet *)skb->data; 594 batman_packet = (struct batman_packet *)skb->data;
@@ -605,32 +606,32 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
605 switch (batman_packet->packet_type) { 606 switch (batman_packet->packet_type) {
606 /* batman originator packet */ 607 /* batman originator packet */
607 case BAT_PACKET: 608 case BAT_PACKET:
608 ret = recv_bat_packet(skb, batman_if); 609 ret = recv_bat_packet(skb, hard_iface);
609 break; 610 break;
610 611
611 /* batman icmp packet */ 612 /* batman icmp packet */
612 case BAT_ICMP: 613 case BAT_ICMP:
613 ret = recv_icmp_packet(skb, batman_if); 614 ret = recv_icmp_packet(skb, hard_iface);
614 break; 615 break;
615 616
616 /* unicast packet */ 617 /* unicast packet */
617 case BAT_UNICAST: 618 case BAT_UNICAST:
618 ret = recv_unicast_packet(skb, batman_if); 619 ret = recv_unicast_packet(skb, hard_iface);
619 break; 620 break;
620 621
621 /* fragmented unicast packet */ 622 /* fragmented unicast packet */
622 case BAT_UNICAST_FRAG: 623 case BAT_UNICAST_FRAG:
623 ret = recv_ucast_frag_packet(skb, batman_if); 624 ret = recv_ucast_frag_packet(skb, hard_iface);
624 break; 625 break;
625 626
626 /* broadcast packet */ 627 /* broadcast packet */
627 case BAT_BCAST: 628 case BAT_BCAST:
628 ret = recv_bcast_packet(skb, batman_if); 629 ret = recv_bcast_packet(skb, hard_iface);
629 break; 630 break;
630 631
631 /* vis packet */ 632 /* vis packet */
632 case BAT_VIS: 633 case BAT_VIS:
633 ret = recv_vis_packet(skb, batman_if); 634 ret = recv_vis_packet(skb, hard_iface);
634 break; 635 break;
635 default: 636 default:
636 ret = NET_RX_DROP; 637 ret = NET_RX_DROP;