aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2012-04-18 13:21:59 -0400
committerDavid S. Miller <davem@davemloft.net>2012-04-18 13:21:59 -0400
commit91fbe33034c184c6a60e31c2207a2f7ec2f180dc (patch)
tree9b921989b33854d15ad1610a795d28b20810b21d /net
parent798ec84d45754403571d6387396236e877965c5a (diff)
parent1e5cc266dbc401d11aefb966ad35e651c2f67414 (diff)
Merge tag 'batman-adv-for-davem' of git://git.open-mesh.org/linux-merge
Included changes: * remove duplicated line in comment * add htons() invocation for tt_crc as suggested by Al Viro * OriGinator Message seqno initial value is now random * some cleanups and fixes
Diffstat (limited to 'net')
-rw-r--r--net/batman-adv/bat_iv_ogm.c63
-rw-r--r--net/batman-adv/bridge_loop_avoidance.c11
-rw-r--r--net/batman-adv/hard-interface.c33
-rw-r--r--net/batman-adv/icmp_socket.c4
-rw-r--r--net/batman-adv/main.c5
-rw-r--r--net/batman-adv/packet.h6
-rw-r--r--net/batman-adv/routing.c10
-rw-r--r--net/batman-adv/send.c14
-rw-r--r--net/batman-adv/soft-interface.c2
-rw-r--r--net/batman-adv/translation-table.c2
-rw-r--r--net/batman-adv/types.h12
-rw-r--r--net/batman-adv/vis.c8
12 files changed, 96 insertions, 74 deletions
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index fab1071f601e..8b2db2e76c7e 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -30,24 +30,44 @@
30#include "send.h" 30#include "send.h"
31#include "bat_algo.h" 31#include "bat_algo.h"
32 32
33static void bat_iv_ogm_init(struct hard_iface *hard_iface) 33static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
34{ 34{
35 struct batman_ogm_packet *batman_ogm_packet; 35 struct batman_ogm_packet *batman_ogm_packet;
36 uint32_t random_seqno;
37 int res = -1;
36 38
37 hard_iface->packet_len = BATMAN_OGM_LEN; 39 /* randomize initial seqno to avoid collision */
40 get_random_bytes(&random_seqno, sizeof(random_seqno));
41 atomic_set(&hard_iface->seqno, random_seqno);
42
43 hard_iface->packet_len = BATMAN_OGM_HLEN;
38 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC); 44 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
39 45
46 if (!hard_iface->packet_buff)
47 goto out;
48
40 batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff; 49 batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
41 batman_ogm_packet->header.packet_type = BAT_OGM; 50 batman_ogm_packet->header.packet_type = BAT_IV_OGM;
42 batman_ogm_packet->header.version = COMPAT_VERSION; 51 batman_ogm_packet->header.version = COMPAT_VERSION;
43 batman_ogm_packet->header.ttl = 2; 52 batman_ogm_packet->header.ttl = 2;
44 batman_ogm_packet->flags = NO_FLAGS; 53 batman_ogm_packet->flags = NO_FLAGS;
45 batman_ogm_packet->tq = TQ_MAX_VALUE; 54 batman_ogm_packet->tq = TQ_MAX_VALUE;
46 batman_ogm_packet->tt_num_changes = 0; 55 batman_ogm_packet->tt_num_changes = 0;
47 batman_ogm_packet->ttvn = 0; 56 batman_ogm_packet->ttvn = 0;
57
58 res = 0;
59
60out:
61 return res;
62}
63
64static void bat_iv_ogm_iface_disable(struct hard_iface *hard_iface)
65{
66 kfree(hard_iface->packet_buff);
67 hard_iface->packet_buff = NULL;
48} 68}
49 69
50static void bat_iv_ogm_init_primary(struct hard_iface *hard_iface) 70static void bat_iv_ogm_primary_iface_set(struct hard_iface *hard_iface)
51{ 71{
52 struct batman_ogm_packet *batman_ogm_packet; 72 struct batman_ogm_packet *batman_ogm_packet;
53 73
@@ -92,7 +112,7 @@ static uint8_t hop_penalty(uint8_t tq, const struct bat_priv *bat_priv)
92static int bat_iv_ogm_aggr_packet(int buff_pos, int packet_len, 112static int bat_iv_ogm_aggr_packet(int buff_pos, int packet_len,
93 int tt_num_changes) 113 int tt_num_changes)
94{ 114{
95 int next_buff_pos = buff_pos + BATMAN_OGM_LEN + tt_len(tt_num_changes); 115 int next_buff_pos = buff_pos + BATMAN_OGM_HLEN + tt_len(tt_num_changes);
96 116
97 return (next_buff_pos <= packet_len) && 117 return (next_buff_pos <= packet_len) &&
98 (next_buff_pos <= MAX_AGGREGATION_BYTES); 118 (next_buff_pos <= MAX_AGGREGATION_BYTES);
@@ -132,7 +152,7 @@ static void bat_iv_ogm_send_to_if(struct forw_packet *forw_packet,
132 "Sending own" : 152 "Sending own" :
133 "Forwarding")); 153 "Forwarding"));
134 bat_dbg(DBG_BATMAN, bat_priv, 154 bat_dbg(DBG_BATMAN, bat_priv,
135 "%s %spacket (originator %pM, seqno %d, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n", 155 "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
136 fwd_str, (packet_num > 0 ? "aggregated " : ""), 156 fwd_str, (packet_num > 0 ? "aggregated " : ""),
137 batman_ogm_packet->orig, 157 batman_ogm_packet->orig,
138 ntohl(batman_ogm_packet->seqno), 158 ntohl(batman_ogm_packet->seqno),
@@ -142,7 +162,7 @@ static void bat_iv_ogm_send_to_if(struct forw_packet *forw_packet,
142 batman_ogm_packet->ttvn, hard_iface->net_dev->name, 162 batman_ogm_packet->ttvn, hard_iface->net_dev->name,
143 hard_iface->net_dev->dev_addr); 163 hard_iface->net_dev->dev_addr);
144 164
145 buff_pos += BATMAN_OGM_LEN + 165 buff_pos += BATMAN_OGM_HLEN +
146 tt_len(batman_ogm_packet->tt_num_changes); 166 tt_len(batman_ogm_packet->tt_num_changes);
147 packet_num++; 167 packet_num++;
148 batman_ogm_packet = (struct batman_ogm_packet *) 168 batman_ogm_packet = (struct batman_ogm_packet *)
@@ -191,7 +211,7 @@ static void bat_iv_ogm_emit(struct forw_packet *forw_packet)
191 211
192 /* FIXME: what about aggregated packets ? */ 212 /* FIXME: what about aggregated packets ? */
193 bat_dbg(DBG_BATMAN, bat_priv, 213 bat_dbg(DBG_BATMAN, bat_priv,
194 "%s packet (originator %pM, seqno %d, TTL %d) on interface %s [%pM]\n", 214 "%s packet (originator %pM, seqno %u, TTL %d) on interface %s [%pM]\n",
195 (forw_packet->own ? "Sending own" : "Forwarding"), 215 (forw_packet->own ? "Sending own" : "Forwarding"),
196 batman_ogm_packet->orig, 216 batman_ogm_packet->orig,
197 ntohl(batman_ogm_packet->seqno), 217 ntohl(batman_ogm_packet->seqno),
@@ -335,10 +355,9 @@ static void bat_iv_ogm_aggregate_new(const unsigned char *packet_buff,
335 if ((atomic_read(&bat_priv->aggregated_ogms)) && 355 if ((atomic_read(&bat_priv->aggregated_ogms)) &&
336 (packet_len < MAX_AGGREGATION_BYTES)) 356 (packet_len < MAX_AGGREGATION_BYTES))
337 forw_packet_aggr->skb = dev_alloc_skb(MAX_AGGREGATION_BYTES + 357 forw_packet_aggr->skb = dev_alloc_skb(MAX_AGGREGATION_BYTES +
338 sizeof(struct ethhdr)); 358 ETH_HLEN);
339 else 359 else
340 forw_packet_aggr->skb = dev_alloc_skb(packet_len + 360 forw_packet_aggr->skb = dev_alloc_skb(packet_len + ETH_HLEN);
341 sizeof(struct ethhdr));
342 361
343 if (!forw_packet_aggr->skb) { 362 if (!forw_packet_aggr->skb) {
344 if (!own_packet) 363 if (!own_packet)
@@ -346,7 +365,7 @@ static void bat_iv_ogm_aggregate_new(const unsigned char *packet_buff,
346 kfree(forw_packet_aggr); 365 kfree(forw_packet_aggr);
347 goto out; 366 goto out;
348 } 367 }
349 skb_reserve(forw_packet_aggr->skb, sizeof(struct ethhdr)); 368 skb_reserve(forw_packet_aggr->skb, ETH_HLEN);
350 369
351 INIT_HLIST_NODE(&forw_packet_aggr->list); 370 INIT_HLIST_NODE(&forw_packet_aggr->list);
352 371
@@ -520,7 +539,7 @@ static void bat_iv_ogm_forward(struct orig_node *orig_node,
520 batman_ogm_packet->flags &= ~DIRECTLINK; 539 batman_ogm_packet->flags &= ~DIRECTLINK;
521 540
522 bat_iv_ogm_queue_add(bat_priv, (unsigned char *)batman_ogm_packet, 541 bat_iv_ogm_queue_add(bat_priv, (unsigned char *)batman_ogm_packet,
523 BATMAN_OGM_LEN + tt_len(tt_num_changes), 542 BATMAN_OGM_HLEN + tt_len(tt_num_changes),
524 if_incoming, 0, bat_iv_ogm_fwd_send_time()); 543 if_incoming, 0, bat_iv_ogm_fwd_send_time());
525} 544}
526 545
@@ -842,7 +861,8 @@ static int bat_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
842 seq_diff = batman_ogm_packet->seqno - orig_node->last_real_seqno; 861 seq_diff = batman_ogm_packet->seqno - orig_node->last_real_seqno;
843 862
844 /* signalize caller that the packet is to be dropped. */ 863 /* signalize caller that the packet is to be dropped. */
845 if (window_protected(bat_priv, seq_diff, 864 if (!hlist_empty(&orig_node->neigh_list) &&
865 window_protected(bat_priv, seq_diff,
846 &orig_node->batman_seqno_reset)) 866 &orig_node->batman_seqno_reset))
847 goto out; 867 goto out;
848 868
@@ -873,7 +893,7 @@ static int bat_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
873 893
874 if (need_update) { 894 if (need_update) {
875 bat_dbg(DBG_BATMAN, bat_priv, 895 bat_dbg(DBG_BATMAN, bat_priv,
876 "updating last_seqno: old %d, new %d\n", 896 "updating last_seqno: old %u, new %u\n",
877 orig_node->last_real_seqno, batman_ogm_packet->seqno); 897 orig_node->last_real_seqno, batman_ogm_packet->seqno);
878 orig_node->last_real_seqno = batman_ogm_packet->seqno; 898 orig_node->last_real_seqno = batman_ogm_packet->seqno;
879 } 899 }
@@ -914,7 +934,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
914 * packet in an aggregation. Here we expect that the padding 934 * packet in an aggregation. Here we expect that the padding
915 * is always zero (or not 0x01) 935 * is always zero (or not 0x01)
916 */ 936 */
917 if (batman_ogm_packet->header.packet_type != BAT_OGM) 937 if (batman_ogm_packet->header.packet_type != BAT_IV_OGM)
918 return; 938 return;
919 939
920 /* could be changed by schedule_own_packet() */ 940 /* could be changed by schedule_own_packet() */
@@ -926,7 +946,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
926 batman_ogm_packet->orig) ? 1 : 0); 946 batman_ogm_packet->orig) ? 1 : 0);
927 947
928 bat_dbg(DBG_BATMAN, bat_priv, 948 bat_dbg(DBG_BATMAN, bat_priv,
929 "Received BATMAN packet via NB: %pM, IF: %s [%pM] (from OG: %pM, via prev OG: %pM, seqno %d, ttvn %u, crc %u, changes %u, td %d, TTL %d, V %d, IDF %d)\n", 949 "Received BATMAN packet via NB: %pM, IF: %s [%pM] (from OG: %pM, via prev OG: %pM, seqno %u, ttvn %u, crc %u, changes %u, td %d, TTL %d, V %d, IDF %d)\n",
930 ethhdr->h_source, if_incoming->net_dev->name, 950 ethhdr->h_source, if_incoming->net_dev->name,
931 if_incoming->net_dev->dev_addr, batman_ogm_packet->orig, 951 if_incoming->net_dev->dev_addr, batman_ogm_packet->orig,
932 batman_ogm_packet->prev_sender, batman_ogm_packet->seqno, 952 batman_ogm_packet->prev_sender, batman_ogm_packet->seqno,
@@ -1153,12 +1173,12 @@ static void bat_iv_ogm_receive(struct hard_iface *if_incoming,
1153 batman_ogm_packet->seqno = ntohl(batman_ogm_packet->seqno); 1173 batman_ogm_packet->seqno = ntohl(batman_ogm_packet->seqno);
1154 batman_ogm_packet->tt_crc = ntohs(batman_ogm_packet->tt_crc); 1174 batman_ogm_packet->tt_crc = ntohs(batman_ogm_packet->tt_crc);
1155 1175
1156 tt_buff = packet_buff + buff_pos + BATMAN_OGM_LEN; 1176 tt_buff = packet_buff + buff_pos + BATMAN_OGM_HLEN;
1157 1177
1158 bat_iv_ogm_process(ethhdr, batman_ogm_packet, 1178 bat_iv_ogm_process(ethhdr, batman_ogm_packet,
1159 tt_buff, if_incoming); 1179 tt_buff, if_incoming);
1160 1180
1161 buff_pos += BATMAN_OGM_LEN + 1181 buff_pos += BATMAN_OGM_HLEN +
1162 tt_len(batman_ogm_packet->tt_num_changes); 1182 tt_len(batman_ogm_packet->tt_num_changes);
1163 1183
1164 batman_ogm_packet = (struct batman_ogm_packet *) 1184 batman_ogm_packet = (struct batman_ogm_packet *)
@@ -1169,8 +1189,9 @@ static void bat_iv_ogm_receive(struct hard_iface *if_incoming,
1169 1189
1170static struct bat_algo_ops batman_iv __read_mostly = { 1190static struct bat_algo_ops batman_iv __read_mostly = {
1171 .name = "BATMAN IV", 1191 .name = "BATMAN IV",
1172 .bat_ogm_init = bat_iv_ogm_init, 1192 .bat_iface_enable = bat_iv_ogm_iface_enable,
1173 .bat_ogm_init_primary = bat_iv_ogm_init_primary, 1193 .bat_iface_disable = bat_iv_ogm_iface_disable,
1194 .bat_primary_iface_set = bat_iv_ogm_primary_iface_set,
1174 .bat_ogm_update_mac = bat_iv_ogm_update_mac, 1195 .bat_ogm_update_mac = bat_iv_ogm_update_mac,
1175 .bat_ogm_schedule = bat_iv_ogm_schedule, 1196 .bat_ogm_schedule = bat_iv_ogm_schedule,
1176 .bat_ogm_emit = bat_iv_ogm_emit, 1197 .bat_ogm_emit = bat_iv_ogm_emit,
diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index 1cf18ac44ba9..ad394c6496cc 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -290,9 +290,7 @@ static void bla_send_claim(struct bat_priv *bat_priv, uint8_t *mac,
290 goto out; 290 goto out;
291 291
292 ethhdr = (struct ethhdr *)skb->data; 292 ethhdr = (struct ethhdr *)skb->data;
293 hw_src = (uint8_t *)ethhdr + 293 hw_src = (uint8_t *)ethhdr + ETH_HLEN + sizeof(struct arphdr);
294 sizeof(struct ethhdr) +
295 sizeof(struct arphdr);
296 294
297 /* now we pretend that the client would have sent this ... */ 295 /* now we pretend that the client would have sent this ... */
298 switch (claimtype) { 296 switch (claimtype) {
@@ -340,7 +338,7 @@ static void bla_send_claim(struct bat_priv *bat_priv, uint8_t *mac,
340 skb_reset_mac_header(skb); 338 skb_reset_mac_header(skb);
341 skb->protocol = eth_type_trans(skb, soft_iface); 339 skb->protocol = eth_type_trans(skb, soft_iface);
342 bat_priv->stats.rx_packets++; 340 bat_priv->stats.rx_packets++;
343 bat_priv->stats.rx_bytes += skb->len + sizeof(struct ethhdr); 341 bat_priv->stats.rx_bytes += skb->len + ETH_HLEN;
344 soft_iface->last_rx = jiffies; 342 soft_iface->last_rx = jiffies;
345 343
346 netif_rx(skb); 344 netif_rx(skb);
@@ -735,7 +733,6 @@ static int handle_claim(struct bat_priv *bat_priv,
735 733
736/** 734/**
737 * @bat_priv: the bat priv with all the soft interface information 735 * @bat_priv: the bat priv with all the soft interface information
738 * @bat_priv: the bat priv with all the soft interface information
739 * @hw_src: the Hardware source in the ARP Header 736 * @hw_src: the Hardware source in the ARP Header
740 * @hw_dst: the Hardware destination in the ARP Header 737 * @hw_dst: the Hardware destination in the ARP Header
741 * @ethhdr: pointer to the Ethernet header of the claim frame 738 * @ethhdr: pointer to the Ethernet header of the claim frame
@@ -845,7 +842,7 @@ static int bla_process_claim(struct bat_priv *bat_priv,
845 headlen = sizeof(*vhdr); 842 headlen = sizeof(*vhdr);
846 } else { 843 } else {
847 proto = ntohs(ethhdr->h_proto); 844 proto = ntohs(ethhdr->h_proto);
848 headlen = sizeof(*ethhdr); 845 headlen = ETH_HLEN;
849 } 846 }
850 847
851 if (proto != ETH_P_ARP) 848 if (proto != ETH_P_ARP)
@@ -1303,7 +1300,7 @@ int bla_is_backbone_gw(struct sk_buff *skb,
1303 return 0; 1300 return 0;
1304 1301
1305 /* first, find out the vid. */ 1302 /* first, find out the vid. */
1306 if (!pskb_may_pull(skb, hdr_size + sizeof(struct ethhdr))) 1303 if (!pskb_may_pull(skb, hdr_size + ETH_HLEN))
1307 return 0; 1304 return 0;
1308 1305
1309 ethhdr = (struct ethhdr *)(((uint8_t *)skb->data) + hdr_size); 1306 ethhdr = (struct ethhdr *)(((uint8_t *)skb->data) + hdr_size);
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 8c4b790b98be..47c79d724ba3 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -146,7 +146,7 @@ static void primary_if_select(struct bat_priv *bat_priv,
146 if (!new_hard_iface) 146 if (!new_hard_iface)
147 goto out; 147 goto out;
148 148
149 bat_priv->bat_algo_ops->bat_ogm_init_primary(new_hard_iface); 149 bat_priv->bat_algo_ops->bat_primary_iface_set(new_hard_iface);
150 primary_if_update_addr(bat_priv, curr_hard_iface); 150 primary_if_update_addr(bat_priv, curr_hard_iface);
151 151
152out: 152out:
@@ -304,22 +304,17 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
304 if (!softif_is_valid(soft_iface)) { 304 if (!softif_is_valid(soft_iface)) {
305 pr_err("Can't create batman mesh interface %s: already exists as regular interface\n", 305 pr_err("Can't create batman mesh interface %s: already exists as regular interface\n",
306 soft_iface->name); 306 soft_iface->name);
307 dev_put(soft_iface);
308 ret = -EINVAL; 307 ret = -EINVAL;
309 goto err; 308 goto err_dev;
310 } 309 }
311 310
312 hard_iface->soft_iface = soft_iface; 311 hard_iface->soft_iface = soft_iface;
313 bat_priv = netdev_priv(hard_iface->soft_iface); 312 bat_priv = netdev_priv(hard_iface->soft_iface);
314 313
315 bat_priv->bat_algo_ops->bat_ogm_init(hard_iface); 314 ret = bat_priv->bat_algo_ops->bat_iface_enable(hard_iface);
316 315 if (ret < 0) {
317 if (!hard_iface->packet_buff) {
318 bat_err(hard_iface->soft_iface,
319 "Can't add interface packet (%s): out of memory\n",
320 hard_iface->net_dev->name);
321 ret = -ENOMEM; 316 ret = -ENOMEM;
322 goto err; 317 goto err_dev;
323 } 318 }
324 319
325 hard_iface->if_num = bat_priv->num_ifaces; 320 hard_iface->if_num = bat_priv->num_ifaces;
@@ -332,7 +327,6 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
332 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev; 327 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
333 dev_add_pack(&hard_iface->batman_adv_ptype); 328 dev_add_pack(&hard_iface->batman_adv_ptype);
334 329
335 atomic_set(&hard_iface->seqno, 1);
336 atomic_set(&hard_iface->frag_seqno, 1); 330 atomic_set(&hard_iface->frag_seqno, 1);
337 bat_info(hard_iface->soft_iface, "Adding interface: %s\n", 331 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
338 hard_iface->net_dev->name); 332 hard_iface->net_dev->name);
@@ -364,6 +358,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
364out: 358out:
365 return 0; 359 return 0;
366 360
361err_dev:
362 dev_put(soft_iface);
367err: 363err:
368 hardif_free_ref(hard_iface); 364 hardif_free_ref(hard_iface);
369 return ret; 365 return ret;
@@ -398,8 +394,7 @@ void hardif_disable_interface(struct hard_iface *hard_iface)
398 hardif_free_ref(new_if); 394 hardif_free_ref(new_if);
399 } 395 }
400 396
401 kfree(hard_iface->packet_buff); 397 bat_priv->bat_algo_ops->bat_iface_disable(hard_iface);
402 hard_iface->packet_buff = NULL;
403 hard_iface->if_status = IF_NOT_IN_USE; 398 hard_iface->if_status = IF_NOT_IN_USE;
404 399
405 /* delete all references to this hard_iface */ 400 /* delete all references to this hard_iface */
@@ -451,6 +446,13 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
451 check_known_mac_addr(hard_iface->net_dev); 446 check_known_mac_addr(hard_iface->net_dev);
452 list_add_tail_rcu(&hard_iface->list, &hardif_list); 447 list_add_tail_rcu(&hard_iface->list, &hardif_list);
453 448
449 /**
450 * This can't be called via a bat_priv callback because
451 * we have no bat_priv yet.
452 */
453 atomic_set(&hard_iface->seqno, 1);
454 hard_iface->packet_buff = NULL;
455
454 return hard_iface; 456 return hard_iface;
455 457
456free_if: 458free_if:
@@ -572,8 +574,7 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
572 goto err_free; 574 goto err_free;
573 575
574 /* expect a valid ethernet header here. */ 576 /* expect a valid ethernet header here. */
575 if (unlikely(skb->mac_len != sizeof(struct ethhdr) || 577 if (unlikely(skb->mac_len != ETH_HLEN || !skb_mac_header(skb)))
576 !skb_mac_header(skb)))
577 goto err_free; 578 goto err_free;
578 579
579 if (!hard_iface->soft_iface) 580 if (!hard_iface->soft_iface)
@@ -602,7 +603,7 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
602 603
603 switch (batman_ogm_packet->header.packet_type) { 604 switch (batman_ogm_packet->header.packet_type) {
604 /* batman originator packet */ 605 /* batman originator packet */
605 case BAT_OGM: 606 case BAT_IV_OGM:
606 ret = recv_bat_ogm_packet(skb, hard_iface); 607 ret = recv_bat_ogm_packet(skb, hard_iface);
607 break; 608 break;
608 609
diff --git a/net/batman-adv/icmp_socket.c b/net/batman-adv/icmp_socket.c
index b87518edcef9..2e98a57f3407 100644
--- a/net/batman-adv/icmp_socket.c
+++ b/net/batman-adv/icmp_socket.c
@@ -175,13 +175,13 @@ static ssize_t bat_socket_write(struct file *file, const char __user *buff,
175 if (len >= sizeof(struct icmp_packet_rr)) 175 if (len >= sizeof(struct icmp_packet_rr))
176 packet_len = sizeof(struct icmp_packet_rr); 176 packet_len = sizeof(struct icmp_packet_rr);
177 177
178 skb = dev_alloc_skb(packet_len + sizeof(struct ethhdr)); 178 skb = dev_alloc_skb(packet_len + ETH_HLEN);
179 if (!skb) { 179 if (!skb) {
180 len = -ENOMEM; 180 len = -ENOMEM;
181 goto out; 181 goto out;
182 } 182 }
183 183
184 skb_reserve(skb, sizeof(struct ethhdr)); 184 skb_reserve(skb, ETH_HLEN);
185 icmp_packet = (struct icmp_packet_rr *)skb_put(skb, packet_len); 185 icmp_packet = (struct icmp_packet_rr *)skb_put(skb, packet_len);
186 186
187 if (copy_from_user(icmp_packet, buff, packet_len)) { 187 if (copy_from_user(icmp_packet, buff, packet_len)) {
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index e67ca96285b3..791327219531 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -208,8 +208,9 @@ int bat_algo_register(struct bat_algo_ops *bat_algo_ops)
208 } 208 }
209 209
210 /* all algorithms must implement all ops (for now) */ 210 /* all algorithms must implement all ops (for now) */
211 if (!bat_algo_ops->bat_ogm_init || 211 if (!bat_algo_ops->bat_iface_enable ||
212 !bat_algo_ops->bat_ogm_init_primary || 212 !bat_algo_ops->bat_iface_disable ||
213 !bat_algo_ops->bat_primary_iface_set ||
213 !bat_algo_ops->bat_ogm_update_mac || 214 !bat_algo_ops->bat_ogm_update_mac ||
214 !bat_algo_ops->bat_ogm_schedule || 215 !bat_algo_ops->bat_ogm_schedule ||
215 !bat_algo_ops->bat_ogm_emit || 216 !bat_algo_ops->bat_ogm_emit ||
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h
index 59800e82371a..f54969c61a1e 100644
--- a/net/batman-adv/packet.h
+++ b/net/batman-adv/packet.h
@@ -25,7 +25,7 @@
25#define ETH_P_BATMAN 0x4305 /* unofficial/not registered Ethertype */ 25#define ETH_P_BATMAN 0x4305 /* unofficial/not registered Ethertype */
26 26
27enum bat_packettype { 27enum bat_packettype {
28 BAT_OGM = 0x01, 28 BAT_IV_OGM = 0x01,
29 BAT_ICMP = 0x02, 29 BAT_ICMP = 0x02,
30 BAT_UNICAST = 0x03, 30 BAT_UNICAST = 0x03,
31 BAT_BCAST = 0x04, 31 BAT_BCAST = 0x04,
@@ -38,7 +38,7 @@ enum bat_packettype {
38/* this file is included by batctl which needs these defines */ 38/* this file is included by batctl which needs these defines */
39#define COMPAT_VERSION 14 39#define COMPAT_VERSION 14
40 40
41enum batman_flags { 41enum batman_iv_flags {
42 PRIMARIES_FIRST_HOP = 1 << 4, 42 PRIMARIES_FIRST_HOP = 1 << 4,
43 VIS_SERVER = 1 << 5, 43 VIS_SERVER = 1 << 5,
44 DIRECTLINK = 1 << 6 44 DIRECTLINK = 1 << 6
@@ -126,7 +126,7 @@ struct batman_ogm_packet {
126 uint16_t tt_crc; 126 uint16_t tt_crc;
127} __packed; 127} __packed;
128 128
129#define BATMAN_OGM_LEN sizeof(struct batman_ogm_packet) 129#define BATMAN_OGM_HLEN sizeof(struct batman_ogm_packet)
130 130
131struct icmp_packet { 131struct icmp_packet {
132 struct batman_header header; 132 struct batman_header header;
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 78eddc9067e6..ff560863bc74 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -254,7 +254,7 @@ int recv_bat_ogm_packet(struct sk_buff *skb, struct hard_iface *hard_iface)
254 struct ethhdr *ethhdr; 254 struct ethhdr *ethhdr;
255 255
256 /* drop packet if it has not necessary minimum size */ 256 /* drop packet if it has not necessary minimum size */
257 if (unlikely(!pskb_may_pull(skb, BATMAN_OGM_LEN))) 257 if (unlikely(!pskb_may_pull(skb, BATMAN_OGM_HLEN)))
258 return NET_RX_DROP; 258 return NET_RX_DROP;
259 259
260 ethhdr = (struct ethhdr *)skb_mac_header(skb); 260 ethhdr = (struct ethhdr *)skb_mac_header(skb);
@@ -313,7 +313,7 @@ static int recv_my_icmp_packet(struct bat_priv *bat_priv,
313 goto out; 313 goto out;
314 314
315 /* create a copy of the skb, if needed, to modify it. */ 315 /* create a copy of the skb, if needed, to modify it. */
316 if (skb_cow(skb, sizeof(struct ethhdr)) < 0) 316 if (skb_cow(skb, ETH_HLEN) < 0)
317 goto out; 317 goto out;
318 318
319 icmp_packet = (struct icmp_packet_rr *)skb->data; 319 icmp_packet = (struct icmp_packet_rr *)skb->data;
@@ -368,7 +368,7 @@ static int recv_icmp_ttl_exceeded(struct bat_priv *bat_priv,
368 goto out; 368 goto out;
369 369
370 /* create a copy of the skb, if needed, to modify it. */ 370 /* create a copy of the skb, if needed, to modify it. */
371 if (skb_cow(skb, sizeof(struct ethhdr)) < 0) 371 if (skb_cow(skb, ETH_HLEN) < 0)
372 goto out; 372 goto out;
373 373
374 icmp_packet = (struct icmp_packet *)skb->data; 374 icmp_packet = (struct icmp_packet *)skb->data;
@@ -454,7 +454,7 @@ int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if)
454 goto out; 454 goto out;
455 455
456 /* create a copy of the skb, if needed, to modify it. */ 456 /* create a copy of the skb, if needed, to modify it. */
457 if (skb_cow(skb, sizeof(struct ethhdr)) < 0) 457 if (skb_cow(skb, ETH_HLEN) < 0)
458 goto out; 458 goto out;
459 459
460 icmp_packet = (struct icmp_packet_rr *)skb->data; 460 icmp_packet = (struct icmp_packet_rr *)skb->data;
@@ -841,7 +841,7 @@ static int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if)
841 goto out; 841 goto out;
842 842
843 /* create a copy of the skb, if needed, to modify it. */ 843 /* create a copy of the skb, if needed, to modify it. */
844 if (skb_cow(skb, sizeof(struct ethhdr)) < 0) 844 if (skb_cow(skb, ETH_HLEN) < 0)
845 goto out; 845 goto out;
846 846
847 unicast_packet = (struct unicast_packet *)skb->data; 847 unicast_packet = (struct unicast_packet *)skb->data;
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index af7a6741a685..7c66b6121fa6 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -51,7 +51,7 @@ int send_skb_packet(struct sk_buff *skb, struct hard_iface *hard_iface,
51 } 51 }
52 52
53 /* push to the ethernet header. */ 53 /* push to the ethernet header. */
54 if (my_skb_head_push(skb, sizeof(*ethhdr)) < 0) 54 if (my_skb_head_push(skb, ETH_HLEN) < 0)
55 goto send_skb_err; 55 goto send_skb_err;
56 56
57 skb_reset_mac_header(skb); 57 skb_reset_mac_header(skb);
@@ -87,7 +87,7 @@ static void realloc_packet_buffer(struct hard_iface *hard_iface,
87 /* keep old buffer if kmalloc should fail */ 87 /* keep old buffer if kmalloc should fail */
88 if (new_buff) { 88 if (new_buff) {
89 memcpy(new_buff, hard_iface->packet_buff, 89 memcpy(new_buff, hard_iface->packet_buff,
90 BATMAN_OGM_LEN); 90 BATMAN_OGM_HLEN);
91 91
92 kfree(hard_iface->packet_buff); 92 kfree(hard_iface->packet_buff);
93 hard_iface->packet_buff = new_buff; 93 hard_iface->packet_buff = new_buff;
@@ -101,13 +101,13 @@ static int prepare_packet_buffer(struct bat_priv *bat_priv,
101{ 101{
102 int new_len; 102 int new_len;
103 103
104 new_len = BATMAN_OGM_LEN + 104 new_len = BATMAN_OGM_HLEN +
105 tt_len((uint8_t)atomic_read(&bat_priv->tt_local_changes)); 105 tt_len((uint8_t)atomic_read(&bat_priv->tt_local_changes));
106 106
107 /* if we have too many changes for one packet don't send any 107 /* if we have too many changes for one packet don't send any
108 * and wait for the tt table request which will be fragmented */ 108 * and wait for the tt table request which will be fragmented */
109 if (new_len > hard_iface->soft_iface->mtu) 109 if (new_len > hard_iface->soft_iface->mtu)
110 new_len = BATMAN_OGM_LEN; 110 new_len = BATMAN_OGM_HLEN;
111 111
112 realloc_packet_buffer(hard_iface, new_len); 112 realloc_packet_buffer(hard_iface, new_len);
113 113
@@ -117,14 +117,14 @@ static int prepare_packet_buffer(struct bat_priv *bat_priv,
117 atomic_set(&bat_priv->tt_ogm_append_cnt, TT_OGM_APPEND_MAX); 117 atomic_set(&bat_priv->tt_ogm_append_cnt, TT_OGM_APPEND_MAX);
118 118
119 return tt_changes_fill_buffer(bat_priv, 119 return tt_changes_fill_buffer(bat_priv,
120 hard_iface->packet_buff + BATMAN_OGM_LEN, 120 hard_iface->packet_buff + BATMAN_OGM_HLEN,
121 hard_iface->packet_len - BATMAN_OGM_LEN); 121 hard_iface->packet_len - BATMAN_OGM_HLEN);
122} 122}
123 123
124static int reset_packet_buffer(struct bat_priv *bat_priv, 124static int reset_packet_buffer(struct bat_priv *bat_priv,
125 struct hard_iface *hard_iface) 125 struct hard_iface *hard_iface)
126{ 126{
127 realloc_packet_buffer(hard_iface, BATMAN_OGM_LEN); 127 realloc_packet_buffer(hard_iface, BATMAN_OGM_HLEN);
128 return 0; 128 return 0;
129} 129}
130 130
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index efe0fbaadcd6..6e2530b02043 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -292,7 +292,7 @@ void interface_rx(struct net_device *soft_iface,
292/* skb->ip_summed = CHECKSUM_UNNECESSARY;*/ 292/* skb->ip_summed = CHECKSUM_UNNECESSARY;*/
293 293
294 bat_priv->stats.rx_packets++; 294 bat_priv->stats.rx_packets++;
295 bat_priv->stats.rx_bytes += skb->len + sizeof(struct ethhdr); 295 bat_priv->stats.rx_bytes += skb->len + ETH_HLEN;
296 296
297 soft_iface->last_rx = jiffies; 297 soft_iface->last_rx = jiffies;
298 298
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index e16a3690bdb2..a38d315d3cd6 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1339,7 +1339,7 @@ static int send_tt_request(struct bat_priv *bat_priv,
1339 memcpy(tt_request->dst, dst_orig_node->orig, ETH_ALEN); 1339 memcpy(tt_request->dst, dst_orig_node->orig, ETH_ALEN);
1340 tt_request->header.ttl = TTL; 1340 tt_request->header.ttl = TTL;
1341 tt_request->ttvn = ttvn; 1341 tt_request->ttvn = ttvn;
1342 tt_request->tt_data = tt_crc; 1342 tt_request->tt_data = htons(tt_crc);
1343 tt_request->flags = TT_REQUEST; 1343 tt_request->flags = TT_REQUEST;
1344 1344
1345 if (full_table) 1345 if (full_table)
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index a5b1a6333def..2f4848b776a7 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -27,7 +27,7 @@
27#include "packet.h" 27#include "packet.h"
28#include "bitarray.h" 28#include "bitarray.h"
29 29
30#define BAT_HEADER_LEN (sizeof(struct ethhdr) + \ 30#define BAT_HEADER_LEN (ETH_HLEN + \
31 ((sizeof(struct unicast_packet) > sizeof(struct bcast_packet) ? \ 31 ((sizeof(struct unicast_packet) > sizeof(struct bcast_packet) ? \
32 sizeof(struct unicast_packet) : \ 32 sizeof(struct unicast_packet) : \
33 sizeof(struct bcast_packet)))) 33 sizeof(struct bcast_packet))))
@@ -377,10 +377,12 @@ struct recvlist_node {
377struct bat_algo_ops { 377struct bat_algo_ops {
378 struct hlist_node list; 378 struct hlist_node list;
379 char *name; 379 char *name;
380 /* init OGM when hard-interface is enabled */ 380 /* init routing info when hard-interface is enabled */
381 void (*bat_ogm_init)(struct hard_iface *hard_iface); 381 int (*bat_iface_enable)(struct hard_iface *hard_iface);
382 /* init primary OGM when primary interface is selected */ 382 /* de-init routing info when hard-interface is disabled */
383 void (*bat_ogm_init_primary)(struct hard_iface *hard_iface); 383 void (*bat_iface_disable)(struct hard_iface *hard_iface);
384 /* called when primary interface is selected / changed */
385 void (*bat_primary_iface_set)(struct hard_iface *hard_iface);
384 /* init mac addresses of the OGM belonging to this hard-interface */ 386 /* init mac addresses of the OGM belonging to this hard-interface */
385 void (*bat_ogm_update_mac)(struct hard_iface *hard_iface); 387 void (*bat_ogm_update_mac)(struct hard_iface *hard_iface);
386 /* prepare a new outgoing OGM for the send queue */ 388 /* prepare a new outgoing OGM for the send queue */
diff --git a/net/batman-adv/vis.c b/net/batman-adv/vis.c
index c4a5b8cafada..cec216fb77c7 100644
--- a/net/batman-adv/vis.c
+++ b/net/batman-adv/vis.c
@@ -434,12 +434,12 @@ static struct vis_info *add_packet(struct bat_priv *bat_priv,
434 return NULL; 434 return NULL;
435 435
436 info->skb_packet = dev_alloc_skb(sizeof(*packet) + vis_info_len + 436 info->skb_packet = dev_alloc_skb(sizeof(*packet) + vis_info_len +
437 sizeof(struct ethhdr)); 437 ETH_HLEN);
438 if (!info->skb_packet) { 438 if (!info->skb_packet) {
439 kfree(info); 439 kfree(info);
440 return NULL; 440 return NULL;
441 } 441 }
442 skb_reserve(info->skb_packet, sizeof(struct ethhdr)); 442 skb_reserve(info->skb_packet, ETH_HLEN);
443 packet = (struct vis_packet *)skb_put(info->skb_packet, sizeof(*packet) 443 packet = (struct vis_packet *)skb_put(info->skb_packet, sizeof(*packet)
444 + vis_info_len); 444 + vis_info_len);
445 445
@@ -894,11 +894,11 @@ int vis_init(struct bat_priv *bat_priv)
894 894
895 bat_priv->my_vis_info->skb_packet = dev_alloc_skb(sizeof(*packet) + 895 bat_priv->my_vis_info->skb_packet = dev_alloc_skb(sizeof(*packet) +
896 MAX_VIS_PACKET_SIZE + 896 MAX_VIS_PACKET_SIZE +
897 sizeof(struct ethhdr)); 897 ETH_HLEN);
898 if (!bat_priv->my_vis_info->skb_packet) 898 if (!bat_priv->my_vis_info->skb_packet)
899 goto free_info; 899 goto free_info;
900 900
901 skb_reserve(bat_priv->my_vis_info->skb_packet, sizeof(struct ethhdr)); 901 skb_reserve(bat_priv->my_vis_info->skb_packet, ETH_HLEN);
902 packet = (struct vis_packet *)skb_put(bat_priv->my_vis_info->skb_packet, 902 packet = (struct vis_packet *)skb_put(bat_priv->my_vis_info->skb_packet,
903 sizeof(*packet)); 903 sizeof(*packet));
904 904