The following commit has been merged in the merge/master branch: commit a97ec892afc89d1b81cd8934697f47b3ee4efd10 Merge: 669cbd55edae689ce151bc17860f9cd236b72c5e d80561222893dfca2bbf32dc75a697fd24bbf14e Author: Antonio Quartulli antonio@meshcoding.com Date: Sat Feb 15 21:04:59 2014 +0100
Merge commit 'd80561222893dfca2bbf32dc75a697fd24bbf14e' into merge/master
Signed-off-by: Antonio Quartulli antonio@meshcoding.com
Conflicts: net/batman-adv/compat.h
diff --combined net/batman-adv/bat_iv_ogm.c index 512159b,8323bce..8323bce --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@@ -241,19 -241,19 +241,19 @@@ batadv_iv_ogm_orig_get(struct batadv_pr size = bat_priv->num_ifaces * sizeof(uint8_t); orig_node->bat_iv.bcast_own_sum = kzalloc(size, GFP_ATOMIC); if (!orig_node->bat_iv.bcast_own_sum) - goto free_bcast_own; + goto free_orig_node;
hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig, batadv_choose_orig, orig_node, &orig_node->hash_entry); if (hash_added != 0) - goto free_bcast_own; + goto free_orig_node;
return orig_node;
- free_bcast_own: - kfree(orig_node->bat_iv.bcast_own); free_orig_node: + /* free twice, as batadv_orig_node_new sets refcount to 2 */ + batadv_orig_node_free_ref(orig_node); batadv_orig_node_free_ref(orig_node);
return NULL; @@@ -266,7 -266,7 +266,7 @@@ batadv_iv_ogm_neigh_new(struct batadv_h struct batadv_orig_node *orig_neigh) { struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); - struct batadv_neigh_node *neigh_node; + struct batadv_neigh_node *neigh_node, *tmp_neigh_node;
neigh_node = batadv_neigh_node_new(hard_iface, neigh_addr, orig_node); if (!neigh_node) @@@ -281,14 -281,24 +281,24 @@@ neigh_node->orig_node = orig_neigh; neigh_node->if_incoming = hard_iface;
- batadv_dbg(BATADV_DBG_BATMAN, bat_priv, - "Creating new neighbor %pM for orig_node %pM on interface %s\n", - neigh_addr, orig_node->orig, hard_iface->net_dev->name); - spin_lock_bh(&orig_node->neigh_list_lock); - hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list); + tmp_neigh_node = batadv_neigh_node_get(orig_node, hard_iface, + neigh_addr); + if (!tmp_neigh_node) { + hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list); + } else { + kfree(neigh_node); + batadv_hardif_free_ref(hard_iface); + neigh_node = tmp_neigh_node; + } spin_unlock_bh(&orig_node->neigh_list_lock);
+ if (!tmp_neigh_node) + batadv_dbg(BATADV_DBG_BATMAN, bat_priv, + "Creating new neighbor %pM for orig_node %pM on interface %s\n", + neigh_addr, orig_node->orig, + hard_iface->net_dev->name); + out: return neigh_node; } diff --combined net/batman-adv/distributed-arp-table.c index edee504,5bb37a8..5bb37a8 --- a/net/batman-adv/distributed-arp-table.c +++ b/net/batman-adv/distributed-arp-table.c @@@ -1027,6 -1027,11 +1027,11 @@@ bool batadv_dat_snoop_incoming_arp_requ if (!skb_new) goto out;
+ /* the rest of the TX path assumes that the mac_header offset pointing + * to the inner Ethernet header has been set, therefore reset it now. + */ + skb_reset_mac_header(skb_new); + if (vid & BATADV_VLAN_HAS_TAG) skb_new = vlan_insert_tag(skb_new, htons(ETH_P_8021Q), vid & VLAN_VID_MASK); diff --combined net/batman-adv/hard-interface.c index 1b12573,b851cc5..b851cc5 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@@ -87,15 -87,13 +87,13 @@@ static bool batadv_is_on_batman_iface(c return false;
/* recurse over the parent device */ - parent_dev = dev_get_by_index(&init_net, net_dev->iflink); + parent_dev = __dev_get_by_index(&init_net, net_dev->iflink); /* if we got a NULL parent_dev there is something broken.. */ if (WARN(!parent_dev, "Cannot find parent device")) return false;
ret = batadv_is_on_batman_iface(parent_dev);
- if (parent_dev) - dev_put(parent_dev); return ret; }
@@@ -243,7 -241,7 +241,7 @@@ int batadv_hardif_min_mtu(struct net_de { struct batadv_priv *bat_priv = netdev_priv(soft_iface); const struct batadv_hard_iface *hard_iface; - int min_mtu = ETH_DATA_LEN; + int min_mtu = INT_MAX;
rcu_read_lock(); list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { @@@ -258,8 -256,6 +256,6 @@@ } rcu_read_unlock();
- atomic_set(&bat_priv->packet_size_max, min_mtu); - if (atomic_read(&bat_priv->fragmentation) == 0) goto out;
@@@ -270,13 -266,21 +266,21 @@@ min_mtu = min_t(int, min_mtu, BATADV_FRAG_MAX_FRAG_SIZE); min_mtu -= sizeof(struct batadv_frag_packet); min_mtu *= BATADV_FRAG_MAX_FRAGMENTS; - atomic_set(&bat_priv->packet_size_max, min_mtu); - - /* with fragmentation enabled we can fragment external packets easily */ - min_mtu = min_t(int, min_mtu, ETH_DATA_LEN);
out: - return min_mtu - batadv_max_header_len(); + /* report to the other components the maximum amount of bytes that + * batman-adv can send over the wire (without considering the payload + * overhead). For example, this value is used by TT to compute the + * maximum local table table size + */ + atomic_set(&bat_priv->packet_size_max, min_mtu); + + /* the real soft-interface MTU is computed by removing the payload + * overhead from the maximum amount of bytes that was just computed. + * + * However batman-adv does not support MTUs bigger than ETH_DATA_LEN + */ + return min_t(int, min_mtu - batadv_max_header_len(), ETH_DATA_LEN); }
/* adjusts the MTU if a new interface with a smaller MTU appeared. */ diff --combined net/batman-adv/originator.c index 6df12a2,8539416..8539416 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c @@@ -458,6 -458,42 +458,42 @@@ out }
/** + * batadv_neigh_node_get - retrieve a neighbour from the list + * @orig_node: originator which the neighbour belongs to + * @hard_iface: the interface where this neighbour is connected to + * @addr: the address of the neighbour + * + * Looks for and possibly returns a neighbour belonging to this originator list + * which is connected through the provided hard interface. + * Returns NULL if the neighbour is not found. + */ + struct batadv_neigh_node * + batadv_neigh_node_get(const struct batadv_orig_node *orig_node, + const struct batadv_hard_iface *hard_iface, + const uint8_t *addr) + { + struct batadv_neigh_node *tmp_neigh_node, *res = NULL; + + rcu_read_lock(); + hlist_for_each_entry_rcu(tmp_neigh_node, &orig_node->neigh_list, list) { + if (!batadv_compare_eth(tmp_neigh_node->addr, addr)) + continue; + + if (tmp_neigh_node->if_incoming != hard_iface) + continue; + + if (!atomic_inc_not_zero(&tmp_neigh_node->refcount)) + continue; + + res = tmp_neigh_node; + break; + } + rcu_read_unlock(); + + return res; + } + + /** * batadv_orig_ifinfo_free_rcu - free the orig_ifinfo object * @rcu: rcu pointer of the orig_ifinfo object */ diff --combined net/batman-adv/originator.h index 37be290,db3a9ed..db3a9ed --- a/net/batman-adv/originator.h +++ b/net/batman-adv/originator.h @@@ -29,6 -29,10 +29,10 @@@ void batadv_orig_node_free_ref_now(stru struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv, const uint8_t *addr); struct batadv_neigh_node * + batadv_neigh_node_get(const struct batadv_orig_node *orig_node, + const struct batadv_hard_iface *hard_iface, + const uint8_t *addr); + struct batadv_neigh_node * batadv_neigh_node_new(struct batadv_hard_iface *hard_iface, const uint8_t *neigh_addr, struct batadv_orig_node *orig_node); diff --combined net/batman-adv/routing.c index 1ed9f7c,a953d5b..a953d5b --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c @@@ -688,7 -688,7 +688,7 @@@ static int batadv_check_unicast_ttvn(st int is_old_ttvn;
/* check if there is enough data before accessing it */ - if (pskb_may_pull(skb, hdr_len + ETH_HLEN) < 0) + if (!pskb_may_pull(skb, hdr_len + ETH_HLEN)) return 0;
/* create a copy of the skb (in case of for re-routing) to modify it. */ @@@ -918,6 -918,8 +918,8 @@@ int batadv_recv_unicast_tvlv(struct sk_
if (ret != NET_RX_SUCCESS) ret = batadv_route_unicast_packet(skb, recv_if); + else + consume_skb(skb);
return ret; } diff --combined net/batman-adv/send.c index 579f5f0,1703a2e..1703a2e --- a/net/batman-adv/send.c +++ b/net/batman-adv/send.c @@@ -254,7 -254,7 +254,7 @@@ static int batadv_send_skb_unicast(stru struct batadv_orig_node *orig_node, unsigned short vid) { - struct ethhdr *ethhdr = (struct ethhdr *)skb->data; + struct ethhdr *ethhdr; struct batadv_unicast_packet *unicast_packet; int ret = NET_XMIT_DROP;
@@@ -279,6 -279,10 +279,10 @@@ goto out; }
+ /* skb->data might have been reallocated by + * batadv_send_skb_prepare_unicast{,_4addr}() + */ + ethhdr = eth_hdr(skb); unicast_packet = (struct batadv_unicast_packet *)skb->data;
/* inform the destination node that we are still missing a correct route diff --combined net/batman-adv/translation-table.c index b6071f6,959dde7..959dde7 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@@ -1975,6 -1975,7 +1975,7 @@@ static uint32_t batadv_tt_global_crc(st struct hlist_head *head; uint32_t i, crc_tmp, crc = 0; uint8_t flags; + __be16 tmp_vid;
for (i = 0; i < hash->size; i++) { head = &hash->table[i]; @@@ -2011,8 -2012,11 +2012,11 @@@ orig_node)) continue;
- crc_tmp = crc32c(0, &tt_common->vid, - sizeof(tt_common->vid)); + /* use network order to read the VID: this ensures that + * every node reads the bytes in the same order. + */ + tmp_vid = htons(tt_common->vid); + crc_tmp = crc32c(0, &tmp_vid, sizeof(tmp_vid));
/* compute the CRC on flags that have to be kept in sync * among nodes @@@ -2046,6 -2050,7 +2050,7 @@@ static uint32_t batadv_tt_local_crc(str struct hlist_head *head; uint32_t i, crc_tmp, crc = 0; uint8_t flags; + __be16 tmp_vid;
for (i = 0; i < hash->size; i++) { head = &hash->table[i]; @@@ -2064,8 -2069,11 +2069,11 @@@ if (tt_common->flags & BATADV_TT_CLIENT_NEW) continue;
- crc_tmp = crc32c(0, &tt_common->vid, - sizeof(tt_common->vid)); + /* use network order to read the VID: this ensures that + * every node reads the bytes in the same order. + */ + tmp_vid = htons(tt_common->vid); + crc_tmp = crc32c(0, &tmp_vid, sizeof(tmp_vid));
/* compute the CRC on flags that have to be kept in sync * among nodes @@@ -2262,6 -2270,7 +2270,7 @@@ static bool batadv_tt_global_check_crc( { struct batadv_tvlv_tt_vlan_data *tt_vlan_tmp; struct batadv_orig_node_vlan *vlan; + uint32_t crc; int i;
/* check if each received CRC matches the locally stored one */ @@@ -2281,7 -2290,10 +2290,10 @@@ if (!vlan) return false;
- if (vlan->tt.crc != ntohl(tt_vlan_tmp->crc)) + crc = vlan->tt.crc; + batadv_orig_node_vlan_free_ref(vlan); + + if (crc != ntohl(tt_vlan_tmp->crc)) return false; }
@@@ -3218,7 -3230,6 +3230,6 @@@ static void batadv_tt_update_orig(struc
spin_lock_bh(&orig_node->tt_lock);
- tt_change = (struct batadv_tvlv_tt_change *)tt_buff; batadv_tt_update_changes(bat_priv, orig_node, tt_num_changes, ttvn, tt_change);