aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv
diff options
context:
space:
mode:
authorMarek Lindner <lindner_marek@yahoo.de>2012-03-01 02:35:21 -0500
committerAntonio Quartulli <ordex@autistici.org>2012-05-11 07:55:57 -0400
commit7ae8b2852f946c71fdbd910156baa605a4ae3cee (patch)
treed5d436a84baa564adaddc498e94d5e4b5a40816b /net/batman-adv
parent0b0094e000840115b5baece2293c5fb1aab4fded (diff)
batman-adv: split neigh_new function into generic and batman iv specific parts
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>
Diffstat (limited to 'net/batman-adv')
-rw-r--r--net/batman-adv/bat_iv_ogm.c40
-rw-r--r--net/batman-adv/originator.c28
-rw-r--r--net/batman-adv/originator.h7
3 files changed, 48 insertions, 27 deletions
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 8652a7536b15..ae0a08c391ea 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -30,6 +30,32 @@
30#include "send.h" 30#include "send.h"
31#include "bat_algo.h" 31#include "bat_algo.h"
32 32
33static struct neigh_node *bat_iv_ogm_neigh_new(struct hard_iface *hard_iface,
34 const uint8_t *neigh_addr,
35 struct orig_node *orig_node,
36 struct orig_node *orig_neigh,
37 uint32_t seqno)
38{
39 struct neigh_node *neigh_node;
40
41 neigh_node = batadv_neigh_node_new(hard_iface, neigh_addr, seqno);
42 if (!neigh_node)
43 goto out;
44
45 INIT_LIST_HEAD(&neigh_node->bonding_list);
46 spin_lock_init(&neigh_node->tq_lock);
47
48 neigh_node->orig_node = orig_neigh;
49 neigh_node->if_incoming = hard_iface;
50
51 spin_lock_bh(&orig_node->neigh_list_lock);
52 hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list);
53 spin_unlock_bh(&orig_node->neigh_list_lock);
54
55out:
56 return neigh_node;
57}
58
33static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface) 59static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
34{ 60{
35 struct batman_ogm_packet *batman_ogm_packet; 61 struct batman_ogm_packet *batman_ogm_packet;
@@ -638,8 +664,9 @@ static void bat_iv_ogm_orig_update(struct bat_priv *bat_priv,
638 if (!orig_tmp) 664 if (!orig_tmp)
639 goto unlock; 665 goto unlock;
640 666
641 neigh_node = create_neighbor(orig_node, orig_tmp, 667 neigh_node = bat_iv_ogm_neigh_new(if_incoming, ethhdr->h_source,
642 ethhdr->h_source, if_incoming); 668 orig_node, orig_tmp,
669 batman_ogm_packet->seqno);
643 670
644 orig_node_free_ref(orig_tmp); 671 orig_node_free_ref(orig_tmp);
645 if (!neigh_node) 672 if (!neigh_node)
@@ -764,10 +791,11 @@ static int bat_iv_ogm_calc_tq(struct orig_node *orig_node,
764 rcu_read_unlock(); 791 rcu_read_unlock();
765 792
766 if (!neigh_node) 793 if (!neigh_node)
767 neigh_node = create_neighbor(orig_neigh_node, 794 neigh_node = bat_iv_ogm_neigh_new(if_incoming,
768 orig_neigh_node, 795 orig_neigh_node->orig,
769 orig_neigh_node->orig, 796 orig_neigh_node,
770 if_incoming); 797 orig_neigh_node,
798 batman_ogm_packet->seqno);
771 799
772 if (!neigh_node) 800 if (!neigh_node)
773 goto out; 801 goto out;
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 962636b039b2..f4b62011ca3f 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -85,35 +85,29 @@ struct neigh_node *orig_node_get_router(struct orig_node *orig_node)
85 return router; 85 return router;
86} 86}
87 87
88struct neigh_node *create_neighbor(struct orig_node *orig_node, 88struct neigh_node *batadv_neigh_node_new(struct hard_iface *hard_iface,
89 struct orig_node *orig_neigh_node, 89 const uint8_t *neigh_addr,
90 const uint8_t *neigh, 90 uint32_t seqno)
91 struct hard_iface *if_incoming)
92{ 91{
93 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); 92 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
94 struct neigh_node *neigh_node; 93 struct neigh_node *neigh_node;
95 94
96 bat_dbg(DBG_BATMAN, bat_priv,
97 "Creating new last-hop neighbor of originator\n");
98
99 neigh_node = kzalloc(sizeof(*neigh_node), GFP_ATOMIC); 95 neigh_node = kzalloc(sizeof(*neigh_node), GFP_ATOMIC);
100 if (!neigh_node) 96 if (!neigh_node)
101 return NULL; 97 goto out;
102 98
103 INIT_HLIST_NODE(&neigh_node->list); 99 INIT_HLIST_NODE(&neigh_node->list);
104 INIT_LIST_HEAD(&neigh_node->bonding_list);
105 spin_lock_init(&neigh_node->tq_lock);
106 100
107 memcpy(neigh_node->addr, neigh, ETH_ALEN); 101 memcpy(neigh_node->addr, neigh_addr, ETH_ALEN);
108 neigh_node->orig_node = orig_neigh_node;
109 neigh_node->if_incoming = if_incoming;
110 102
111 /* extra reference for return */ 103 /* extra reference for return */
112 atomic_set(&neigh_node->refcount, 2); 104 atomic_set(&neigh_node->refcount, 2);
113 105
114 spin_lock_bh(&orig_node->neigh_list_lock); 106 bat_dbg(DBG_BATMAN, bat_priv,
115 hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list); 107 "Creating new neighbor %pM, initial seqno %d\n",
116 spin_unlock_bh(&orig_node->neigh_list_lock); 108 neigh_addr, seqno);
109
110out:
117 return neigh_node; 111 return neigh_node;
118} 112}
119 113
diff --git a/net/batman-adv/originator.h b/net/batman-adv/originator.h
index 3fe2eda85652..f74d0d693359 100644
--- a/net/batman-adv/originator.h
+++ b/net/batman-adv/originator.h
@@ -29,10 +29,9 @@ void originator_free(struct bat_priv *bat_priv);
29void purge_orig_ref(struct bat_priv *bat_priv); 29void purge_orig_ref(struct bat_priv *bat_priv);
30void orig_node_free_ref(struct orig_node *orig_node); 30void orig_node_free_ref(struct orig_node *orig_node);
31struct orig_node *get_orig_node(struct bat_priv *bat_priv, const uint8_t *addr); 31struct orig_node *get_orig_node(struct bat_priv *bat_priv, const uint8_t *addr);
32struct neigh_node *create_neighbor(struct orig_node *orig_node, 32struct neigh_node *batadv_neigh_node_new(struct hard_iface *hard_iface,
33 struct orig_node *orig_neigh_node, 33 const uint8_t *neigh_addr,
34 const uint8_t *neigh, 34 uint32_t seqno);
35 struct hard_iface *if_incoming);
36void neigh_node_free_ref(struct neigh_node *neigh_node); 35void neigh_node_free_ref(struct neigh_node *neigh_node);
37struct neigh_node *orig_node_get_router(struct orig_node *orig_node); 36struct neigh_node *orig_node_get_router(struct orig_node *orig_node);
38int orig_seq_print_text(struct seq_file *seq, void *offset); 37int orig_seq_print_text(struct seq_file *seq, void *offset);