batman-adv: separate ethernet comparing calls from hash functions
authorMarek Lindner <lindner_marek@yahoo.de>
Fri, 18 Feb 2011 12:28:08 +0000 (12:28 +0000)
committerMarek Lindner <lindner_marek@yahoo.de>
Sat, 5 Mar 2011 11:50:14 +0000 (12:50 +0100)
Note: The function compare_ether_addr() provided by the Linux kernel
requires aligned memory.

Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
net/batman-adv/hard-interface.c
net/batman-adv/main.c
net/batman-adv/main.h
net/batman-adv/routing.c
net/batman-adv/send.c
net/batman-adv/soft-interface.c
net/batman-adv/translation-table.c
net/batman-adv/vis.c

index 89824853d6e3ce023cdc5fb0e8d328134eef3e30..de9bd36e00dcb1a92933876c3c50bda9da0c6d84 100644 (file)
@@ -187,7 +187,7 @@ static void check_known_mac_addr(struct net_device *net_dev)
                if (batman_if->net_dev == net_dev)
                        continue;
 
-               if (!compare_orig(batman_if->net_dev->dev_addr,
+               if (!compare_eth(batman_if->net_dev->dev_addr,
                                  net_dev->dev_addr))
                        continue;
 
index 06d956c91c274e1755c6c9d097c2c628035d0c29..3f977eab298752958d3d32aafd0dd1913ad22823 100644 (file)
@@ -161,7 +161,7 @@ int is_my_mac(uint8_t *addr)
                if (batman_if->if_status != IF_ACTIVE)
                        continue;
 
-               if (compare_orig(batman_if->net_dev->dev_addr, addr)) {
+               if (compare_eth(batman_if->net_dev->dev_addr, addr)) {
                        rcu_read_unlock();
                        return 1;
                }
index e235d7bbe0453f9c5fad9d576129a4b7bdc56cfc..06b5b994cc20a310877df54309413f72b757eeb9 100644 (file)
@@ -165,4 +165,14 @@ static inline void bat_dbg(char type __always_unused,
                pr_err("%s: " fmt, _netdev->name, ## arg);              \
        } while (0)
 
+/**
+ * returns 1 if they are the same ethernet addr
+ *
+ * note: can't use compare_ether_addr() as it requires aligned memory
+ */
+static inline int compare_eth(void *data1, void *data2)
+{
+       return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
+}
+
 #endif /* _NET_BATMAN_ADV_MAIN_H_ */
index ce68815f3eb334d225564ba185909a47ab2afa2e..b54bf6ec637e1afb0c85812baf3fe750e85190cf 100644 (file)
@@ -163,8 +163,8 @@ static int is_bidirectional_neigh(struct orig_node *orig_node,
                hlist_for_each_entry_rcu(tmp_neigh_node, node,
                                         &orig_node->neigh_list, list) {
 
-                       if (compare_orig(tmp_neigh_node->addr,
-                                        orig_neigh_node->orig) &&
+                       if (compare_eth(tmp_neigh_node->addr,
+                                       orig_neigh_node->orig) &&
                            (tmp_neigh_node->if_incoming == if_incoming))
                                neigh_node = tmp_neigh_node;
                }
@@ -192,8 +192,8 @@ static int is_bidirectional_neigh(struct orig_node *orig_node,
                hlist_for_each_entry_rcu(tmp_neigh_node, node,
                                         &orig_neigh_node->neigh_list, list) {
 
-                       if (compare_orig(tmp_neigh_node->addr,
-                                        orig_neigh_node->orig) &&
+                       if (compare_eth(tmp_neigh_node->addr,
+                                       orig_neigh_node->orig) &&
                            (tmp_neigh_node->if_incoming == if_incoming))
                                neigh_node = tmp_neigh_node;
                }
@@ -304,8 +304,8 @@ static void bonding_candidate_add(struct orig_node *orig_node,
        spin_lock_bh(&orig_node->neigh_list_lock);
 
        /* only consider if it has the same primary address ...  */
-       if (!compare_orig(orig_node->orig,
-                         neigh_node->orig_node->primary_addr))
+       if (!compare_eth(orig_node->orig,
+                        neigh_node->orig_node->primary_addr))
                goto candidate_del;
 
        if (!orig_node->router)
@@ -334,7 +334,7 @@ static void bonding_candidate_add(struct orig_node *orig_node,
                        continue;
 
                if ((neigh_node->if_incoming == tmp_neigh_node->if_incoming) ||
-                   (compare_orig(neigh_node->addr, tmp_neigh_node->addr))) {
+                   (compare_eth(neigh_node->addr, tmp_neigh_node->addr))) {
                        interference_candidate = 1;
                        break;
                }
@@ -394,7 +394,7 @@ static void update_orig(struct bat_priv *bat_priv,
        rcu_read_lock();
        hlist_for_each_entry_rcu(tmp_neigh_node, node,
                                 &orig_node->neigh_list, list) {
-               if (compare_orig(tmp_neigh_node->addr, ethhdr->h_source) &&
+               if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) &&
                    (tmp_neigh_node->if_incoming == if_incoming) &&
                     atomic_inc_not_zero(&tmp_neigh_node->refcount)) {
                        if (neigh_node)
@@ -579,7 +579,7 @@ static char count_real_packets(struct ethhdr *ethhdr,
                                               orig_node->last_real_seqno,
                                               batman_packet->seqno);
 
-               if (compare_orig(tmp_neigh_node->addr, ethhdr->h_source) &&
+               if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) &&
                    (tmp_neigh_node->if_incoming == if_incoming))
                        set_mark = 1;
                else
@@ -644,8 +644,8 @@ void receive_bat_packet(struct ethhdr *ethhdr,
 
        has_directlink_flag = (batman_packet->flags & DIRECTLINK ? 1 : 0);
 
-       is_single_hop_neigh = (compare_orig(ethhdr->h_source,
-                                           batman_packet->orig) ? 1 : 0);
+       is_single_hop_neigh = (compare_eth(ethhdr->h_source,
+                                          batman_packet->orig) ? 1 : 0);
 
        bat_dbg(DBG_BATMAN, bat_priv,
                "Received BATMAN packet via NB: %pM, IF: %s [%pM] "
@@ -665,19 +665,19 @@ void receive_bat_packet(struct ethhdr *ethhdr,
                if (batman_if->soft_iface != if_incoming->soft_iface)
                        continue;
 
-               if (compare_orig(ethhdr->h_source,
-                                batman_if->net_dev->dev_addr))
+               if (compare_eth(ethhdr->h_source,
+                               batman_if->net_dev->dev_addr))
                        is_my_addr = 1;
 
-               if (compare_orig(batman_packet->orig,
-                                batman_if->net_dev->dev_addr))
+               if (compare_eth(batman_packet->orig,
+                               batman_if->net_dev->dev_addr))
                        is_my_orig = 1;
 
-               if (compare_orig(batman_packet->prev_sender,
-                                batman_if->net_dev->dev_addr))
+               if (compare_eth(batman_packet->prev_sender,
+                               batman_if->net_dev->dev_addr))
                        is_my_oldorig = 1;
 
-               if (compare_orig(ethhdr->h_source, broadcast_addr))
+               if (compare_eth(ethhdr->h_source, broadcast_addr))
                        is_broadcast = 1;
        }
        rcu_read_unlock();
@@ -717,8 +717,8 @@ void receive_bat_packet(struct ethhdr *ethhdr,
                /* if received seqno equals last send seqno save new
                 * seqno for bidirectional check */
                if (has_directlink_flag &&
-                   compare_orig(if_incoming->net_dev->dev_addr,
-                                batman_packet->orig) &&
+                   compare_eth(if_incoming->net_dev->dev_addr,
+                               batman_packet->orig) &&
                    (batman_packet->seqno - if_incoming_seqno + 2 == 0)) {
                        offset = if_incoming->if_num * NUM_WORDS;
 
@@ -765,11 +765,11 @@ void receive_bat_packet(struct ethhdr *ethhdr,
        /* avoid temporary routing loops */
        if ((orig_node->router) &&
            (orig_node->router->orig_node->router) &&
-           (compare_orig(orig_node->router->addr,
-                         batman_packet->prev_sender)) &&
-           !(compare_orig(batman_packet->orig, batman_packet->prev_sender)) &&
-           (compare_orig(orig_node->router->addr,
-                         orig_node->router->orig_node->router->addr))) {
+           (compare_eth(orig_node->router->addr,
+                        batman_packet->prev_sender)) &&
+           !(compare_eth(batman_packet->orig, batman_packet->prev_sender)) &&
+           (compare_eth(orig_node->router->addr,
+                        orig_node->router->orig_node->router->addr))) {
                bat_dbg(DBG_BATMAN, bat_priv,
                        "Drop packet: ignoring all rebroadcast packets that "
                        "may make me loop (sender: %pM)\n", ethhdr->h_source);
@@ -1185,14 +1185,13 @@ struct neigh_node *find_router(struct bat_priv *bat_priv,
 
        /* if we have something in the primary_addr, we can search
         * for a potential bonding candidate. */
-       if (memcmp(router_orig->primary_addr, zero_mac, ETH_ALEN) == 0)
+       if (compare_eth(router_orig->primary_addr, zero_mac))
                goto return_router;
 
        /* find the orig_node which has the primary interface. might
         * even be the same as our router_orig in many cases */
 
-       if (memcmp(router_orig->primary_addr,
-                               router_orig->orig, ETH_ALEN) == 0) {
+       if (compare_eth(router_orig->primary_addr, router_orig->orig)) {
                primary_orig_node = router_orig;
        } else {
                primary_orig_node = hash_find(bat_priv->orig_hash, compare_orig,
index 831427694fc21ea20f168dee6f5b33d6b372554b..f0232ad77222dc97a6e416547b01d2fa712a8499 100644 (file)
@@ -326,7 +326,7 @@ void schedule_forward_packet(struct orig_node *orig_node,
        if ((orig_node->router) && (orig_node->router->tq_avg != 0)) {
 
                /* rebroadcast ogm of best ranking neighbor as is */
-               if (!compare_orig(orig_node->router->addr, ethhdr->h_source)) {
+               if (!compare_eth(orig_node->router->addr, ethhdr->h_source)) {
                        batman_packet->tq = orig_node->router->tq_avg;
 
                        if (orig_node->router->last_ttl)
index c30ccd66786ade49585e880a660b062e8e7ea300..bea2dcf6bef58c270d87b60a5da72f309659116e 100644 (file)
@@ -132,7 +132,7 @@ static struct softif_neigh *softif_neigh_get(struct bat_priv *bat_priv,
        rcu_read_lock();
        hlist_for_each_entry_rcu(softif_neigh, node,
                                 &bat_priv->softif_neigh_list, list) {
-               if (memcmp(softif_neigh->addr, addr, ETH_ALEN) != 0)
+               if (!compare_eth(softif_neigh->addr, addr))
                        continue;
 
                if (softif_neigh->vid != vid)
index b25e4b328dcb75ce932327c5bf140fae842c6a9d..77d0ee0d125779de959372f33be887b892f360c2 100644 (file)
@@ -101,7 +101,7 @@ void hna_local_add(struct net_device *soft_iface, uint8_t *addr)
        hna_local_entry->last_seen = jiffies;
 
        /* the batman interface mac address should never be purged */
-       if (compare_orig(addr, soft_iface->dev_addr))
+       if (compare_eth(addr, soft_iface->dev_addr))
                hna_local_entry->never_purge = 1;
        else
                hna_local_entry->never_purge = 0;
index 9832d8f9ed440ae85b1d0a67aa34e4bbc7b6c18d..fc9732967dbde480d111541298a64a45d70ec146 100644 (file)
@@ -75,7 +75,7 @@ static int vis_info_cmp(void *data1, void *data2)
        d2 = data2;
        p1 = (struct vis_packet *)d1->skb_packet->data;
        p2 = (struct vis_packet *)d2->skb_packet->data;
-       return compare_orig(p1->vis_orig, p2->vis_orig);
+       return compare_eth(p1->vis_orig, p2->vis_orig);
 }
 
 /* hash function to choose an entry in a hash table of given size */
@@ -113,7 +113,7 @@ static void vis_data_insert_interface(const uint8_t *interface,
        struct hlist_node *pos;
 
        hlist_for_each_entry(entry, pos, if_list, list) {
-               if (compare_orig(entry->addr, (void *)interface))
+               if (compare_eth(entry->addr, (void *)interface))
                        return;
        }
 
@@ -165,7 +165,7 @@ static ssize_t vis_data_read_entry(char *buff, struct vis_info_entry *entry,
        /* maximal length: max(4+17+2, 3+17+1+3+2) == 26 */
        if (primary && entry->quality == 0)
                return sprintf(buff, "HNA %pM, ", entry->dest);
-       else if (compare_orig(entry->src, src))
+       else if (compare_eth(entry->src, src))
                return sprintf(buff, "TQ %pM %d, ", entry->dest,
                               entry->quality);
 
@@ -212,7 +212,7 @@ int vis_seq_print_text(struct seq_file *seq, void *offset)
                                if (entries[j].quality == 0)
                                        continue;
                                compare =
-                                compare_orig(entries[j].src, packet->vis_orig);
+                                compare_eth(entries[j].src, packet->vis_orig);
                                vis_data_insert_interface(entries[j].src,
                                                          &vis_if_list,
                                                          compare);
@@ -222,7 +222,7 @@ int vis_seq_print_text(struct seq_file *seq, void *offset)
                                buf_size += 18 + 26 * packet->entries;
 
                                /* add primary/secondary records */
-                               if (compare_orig(entry->addr, packet->vis_orig))
+                               if (compare_eth(entry->addr, packet->vis_orig))
                                        buf_size +=
                                          vis_data_count_prim_sec(&vis_if_list);
 
@@ -258,7 +258,7 @@ int vis_seq_print_text(struct seq_file *seq, void *offset)
                                if (entries[j].quality == 0)
                                        continue;
                                compare =
-                                compare_orig(entries[j].src, packet->vis_orig);
+                                compare_eth(entries[j].src, packet->vis_orig);
                                vis_data_insert_interface(entries[j].src,
                                                          &vis_if_list,
                                                          compare);
@@ -276,7 +276,7 @@ int vis_seq_print_text(struct seq_file *seq, void *offset)
                                                        entry->primary);
 
                                /* add primary/secondary records */
-                               if (compare_orig(entry->addr, packet->vis_orig))
+                               if (compare_eth(entry->addr, packet->vis_orig))
                                        buff_pos +=
                                         vis_data_read_prim_sec(buff + buff_pos,
                                                                &vis_if_list);
@@ -344,7 +344,7 @@ static int recv_list_is_in(struct bat_priv *bat_priv,
 
        spin_lock_bh(&bat_priv->vis_list_lock);
        list_for_each_entry(entry, recv_list, list) {
-               if (memcmp(entry->mac, mac, ETH_ALEN) == 0) {
+               if (compare_eth(entry->mac, mac)) {
                        spin_unlock_bh(&bat_priv->vis_list_lock);
                        return 1;
                }
@@ -617,7 +617,7 @@ static int generate_vis_packet(struct bat_priv *bat_priv)
                        if (!neigh_node)
                                continue;
 
-                       if (!compare_orig(neigh_node->addr, orig_node->orig))
+                       if (!compare_eth(neigh_node->addr, orig_node->orig))
                                continue;
 
                        if (neigh_node->if_incoming->if_status != IF_ACTIVE)