batman-adv: split neigh_new function into generic and batman iv specific parts
authorMarek Lindner <lindner_marek@yahoo.de>
Thu, 1 Mar 2012 07:35:21 +0000 (15:35 +0800)
committerAntonio Quartulli <ordex@autistici.org>
Fri, 11 May 2012 11:55:57 +0000 (13:55 +0200)
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Acked-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
net/batman-adv/bat_iv_ogm.c
net/batman-adv/originator.c
net/batman-adv/originator.h

index 8652a7536b1507eb13c968520c8e69aebb922b99..ae0a08c391ea4b951528687a3472d6641a2f806d 100644 (file)
 #include "send.h"
 #include "bat_algo.h"
 
+static struct neigh_node *bat_iv_ogm_neigh_new(struct hard_iface *hard_iface,
+                                              const uint8_t *neigh_addr,
+                                              struct orig_node *orig_node,
+                                              struct orig_node *orig_neigh,
+                                              uint32_t seqno)
+{
+       struct neigh_node *neigh_node;
+
+       neigh_node = batadv_neigh_node_new(hard_iface, neigh_addr, seqno);
+       if (!neigh_node)
+               goto out;
+
+       INIT_LIST_HEAD(&neigh_node->bonding_list);
+       spin_lock_init(&neigh_node->tq_lock);
+
+       neigh_node->orig_node = orig_neigh;
+       neigh_node->if_incoming = hard_iface;
+
+       spin_lock_bh(&orig_node->neigh_list_lock);
+       hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list);
+       spin_unlock_bh(&orig_node->neigh_list_lock);
+
+out:
+       return neigh_node;
+}
+
 static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
 {
        struct batman_ogm_packet *batman_ogm_packet;
@@ -638,8 +664,9 @@ static void bat_iv_ogm_orig_update(struct bat_priv *bat_priv,
                if (!orig_tmp)
                        goto unlock;
 
-               neigh_node = create_neighbor(orig_node, orig_tmp,
-                                            ethhdr->h_source, if_incoming);
+               neigh_node = bat_iv_ogm_neigh_new(if_incoming, ethhdr->h_source,
+                                                 orig_node, orig_tmp,
+                                                 batman_ogm_packet->seqno);
 
                orig_node_free_ref(orig_tmp);
                if (!neigh_node)
@@ -764,10 +791,11 @@ static int bat_iv_ogm_calc_tq(struct orig_node *orig_node,
        rcu_read_unlock();
 
        if (!neigh_node)
-               neigh_node = create_neighbor(orig_neigh_node,
-                                            orig_neigh_node,
-                                            orig_neigh_node->orig,
-                                            if_incoming);
+               neigh_node = bat_iv_ogm_neigh_new(if_incoming,
+                                                 orig_neigh_node->orig,
+                                                 orig_neigh_node,
+                                                 orig_neigh_node,
+                                                 batman_ogm_packet->seqno);
 
        if (!neigh_node)
                goto out;
index 962636b039b23061c1ef8e3ef6696d1529b34130..f4b62011ca3f45b252aafe789b4142d66e61a8ed 100644 (file)
@@ -85,35 +85,29 @@ struct neigh_node *orig_node_get_router(struct orig_node *orig_node)
        return router;
 }
 
-struct neigh_node *create_neighbor(struct orig_node *orig_node,
-                                  struct orig_node *orig_neigh_node,
-                                  const uint8_t *neigh,
-                                  struct hard_iface *if_incoming)
+struct neigh_node *batadv_neigh_node_new(struct hard_iface *hard_iface,
+                                        const uint8_t *neigh_addr,
+                                        uint32_t seqno)
 {
-       struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
+       struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
        struct neigh_node *neigh_node;
 
-       bat_dbg(DBG_BATMAN, bat_priv,
-               "Creating new last-hop neighbor of originator\n");
-
        neigh_node = kzalloc(sizeof(*neigh_node), GFP_ATOMIC);
        if (!neigh_node)
-               return NULL;
+               goto out;
 
        INIT_HLIST_NODE(&neigh_node->list);
-       INIT_LIST_HEAD(&neigh_node->bonding_list);
-       spin_lock_init(&neigh_node->tq_lock);
 
-       memcpy(neigh_node->addr, neigh, ETH_ALEN);
-       neigh_node->orig_node = orig_neigh_node;
-       neigh_node->if_incoming = if_incoming;
+       memcpy(neigh_node->addr, neigh_addr, ETH_ALEN);
 
        /* extra reference for return */
        atomic_set(&neigh_node->refcount, 2);
 
-       spin_lock_bh(&orig_node->neigh_list_lock);
-       hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list);
-       spin_unlock_bh(&orig_node->neigh_list_lock);
+       bat_dbg(DBG_BATMAN, bat_priv,
+               "Creating new neighbor %pM, initial seqno %d\n",
+               neigh_addr, seqno);
+
+out:
        return neigh_node;
 }
 
index 3fe2eda85652d288ba152791734c9b8322f57d2e..f74d0d693359716a4de591c4b0c4535bd4a58c27 100644 (file)
@@ -29,10 +29,9 @@ void originator_free(struct bat_priv *bat_priv);
 void purge_orig_ref(struct bat_priv *bat_priv);
 void orig_node_free_ref(struct orig_node *orig_node);
 struct orig_node *get_orig_node(struct bat_priv *bat_priv, const uint8_t *addr);
-struct neigh_node *create_neighbor(struct orig_node *orig_node,
-                                  struct orig_node *orig_neigh_node,
-                                  const uint8_t *neigh,
-                                  struct hard_iface *if_incoming);
+struct neigh_node *batadv_neigh_node_new(struct hard_iface *hard_iface,
+                                        const uint8_t *neigh_addr,
+                                        uint32_t seqno);
 void neigh_node_free_ref(struct neigh_node *neigh_node);
 struct neigh_node *orig_node_get_router(struct orig_node *orig_node);
 int orig_seq_print_text(struct seq_file *seq, void *offset);