aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv
diff options
context:
space:
mode:
authorLinus Luessing <linus.luessing@web.de>2016-01-16 03:40:10 -0500
committerAntonio Quartulli <a@unstable.cc>2016-02-29 03:05:30 -0500
commit162bd64c24aba8efe68948e95e61628403106cd7 (patch)
treefba0b614a5be99bcc6c6bce9c041dac1dd9a7193 /net/batman-adv
parentd6f94d91f766b4205e5b0aa4b11f96271c793f6d (diff)
batman-adv: ELP - creating neighbor structures
Initially developed by Linus during a 6 months trainee study period in Ascom (Switzerland) AG. Signed-off-by: Linus Luessing <linus.luessing@web.de> Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch> Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
Diffstat (limited to 'net/batman-adv')
-rw-r--r--net/batman-adv/bat_v.c23
-rw-r--r--net/batman-adv/bat_v_elp.c152
-rw-r--r--net/batman-adv/bat_v_elp.h4
-rw-r--r--net/batman-adv/main.h3
-rw-r--r--net/batman-adv/types.h33
5 files changed, 214 insertions, 1 deletions
diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c
index 01327f627a08..0fea894855ff 100644
--- a/net/batman-adv/bat_v.c
+++ b/net/batman-adv/bat_v.c
@@ -22,6 +22,7 @@
22#include <linux/init.h> 22#include <linux/init.h>
23 23
24#include "bat_v_elp.h" 24#include "bat_v_elp.h"
25#include "packet.h"
25 26
26static int batadv_v_iface_enable(struct batadv_hard_iface *hard_iface) 27static int batadv_v_iface_enable(struct batadv_hard_iface *hard_iface)
27{ 28{
@@ -42,6 +43,12 @@ static void batadv_v_primary_iface_set(struct batadv_hard_iface *hard_iface)
42 batadv_v_elp_primary_iface_set(hard_iface); 43 batadv_v_elp_primary_iface_set(hard_iface);
43} 44}
44 45
46static void
47batadv_v_hardif_neigh_init(struct batadv_hardif_neigh_node *hardif_neigh)
48{
49 ewma_throughput_init(&hardif_neigh->bat_v.throughput);
50}
51
45static void batadv_v_ogm_schedule(struct batadv_hard_iface *hard_iface) 52static void batadv_v_ogm_schedule(struct batadv_hard_iface *hard_iface)
46{ 53{
47} 54}
@@ -56,6 +63,7 @@ static struct batadv_algo_ops batadv_batman_v __read_mostly = {
56 .bat_iface_disable = batadv_v_iface_disable, 63 .bat_iface_disable = batadv_v_iface_disable,
57 .bat_iface_update_mac = batadv_v_iface_update_mac, 64 .bat_iface_update_mac = batadv_v_iface_update_mac,
58 .bat_primary_iface_set = batadv_v_primary_iface_set, 65 .bat_primary_iface_set = batadv_v_primary_iface_set,
66 .bat_hardif_neigh_init = batadv_v_hardif_neigh_init,
59 .bat_ogm_emit = batadv_v_ogm_emit, 67 .bat_ogm_emit = batadv_v_ogm_emit,
60 .bat_ogm_schedule = batadv_v_ogm_schedule, 68 .bat_ogm_schedule = batadv_v_ogm_schedule,
61}; 69};
@@ -70,5 +78,18 @@ static struct batadv_algo_ops batadv_batman_v __read_mostly = {
70 */ 78 */
71int __init batadv_v_init(void) 79int __init batadv_v_init(void)
72{ 80{
73 return batadv_algo_register(&batadv_batman_v); 81 int ret;
82
83 /* B.A.T.M.A.N. V echo location protocol packet */
84 ret = batadv_recv_handler_register(BATADV_ELP,
85 batadv_v_elp_packet_recv);
86 if (ret < 0)
87 return ret;
88
89 ret = batadv_algo_register(&batadv_batman_v);
90
91 if (ret < 0)
92 batadv_recv_handler_unregister(BATADV_ELP);
93
94 return ret;
74} 95}
diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c
index bc6e046c614c..dac88fad2697 100644
--- a/net/batman-adv/bat_v_elp.c
+++ b/net/batman-adv/bat_v_elp.c
@@ -38,7 +38,10 @@
38 38
39#include "bat_algo.h" 39#include "bat_algo.h"
40#include "hard-interface.h" 40#include "hard-interface.h"
41#include "hash.h"
42#include "originator.h"
41#include "packet.h" 43#include "packet.h"
44#include "routing.h"
42#include "send.h" 45#include "send.h"
43 46
44/** 47/**
@@ -191,3 +194,152 @@ void batadv_v_elp_primary_iface_set(struct batadv_hard_iface *primary_iface)
191 } 194 }
192 rcu_read_unlock(); 195 rcu_read_unlock();
193} 196}
197
198/**
199 * batadv_v_ogm_orig_get - retrieve and possibly create an originator node
200 * @bat_priv: the bat priv with all the soft interface information
201 * @addr: the address of the originator
202 *
203 * Return: the orig_node corresponding to the specified address. If such object
204 * does not exist it is allocated here. In case of allocation failure returns
205 * NULL.
206 */
207static struct batadv_orig_node *
208batadv_v_ogm_orig_get(struct batadv_priv *bat_priv,
209 const u8 *addr)
210{
211 struct batadv_orig_node *orig_node;
212 int hash_added;
213
214 orig_node = batadv_orig_hash_find(bat_priv, addr);
215 if (orig_node)
216 return orig_node;
217
218 orig_node = batadv_orig_node_new(bat_priv, addr);
219 if (!orig_node)
220 return NULL;
221
222 hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
223 batadv_choose_orig, orig_node,
224 &orig_node->hash_entry);
225 if (hash_added != 0) {
226 /* orig_node->refcounter is initialised to 2 by
227 * batadv_orig_node_new()
228 */
229 batadv_orig_node_put(orig_node);
230 batadv_orig_node_put(orig_node);
231 orig_node = NULL;
232 }
233
234 return orig_node;
235}
236
237/**
238 * batadv_v_elp_neigh_update - update an ELP neighbour node
239 * @bat_priv: the bat priv with all the soft interface information
240 * @neigh_addr: the neighbour interface address
241 * @if_incoming: the interface the packet was received through
242 * @elp_packet: the received ELP packet
243 *
244 * Updates the ELP neighbour node state with the data received within the new
245 * ELP packet.
246 */
247static void batadv_v_elp_neigh_update(struct batadv_priv *bat_priv,
248 u8 *neigh_addr,
249 struct batadv_hard_iface *if_incoming,
250 struct batadv_elp_packet *elp_packet)
251
252{
253 struct batadv_neigh_node *neigh;
254 struct batadv_orig_node *orig_neigh;
255 struct batadv_hardif_neigh_node *hardif_neigh;
256 s32 seqno_diff;
257 s32 elp_latest_seqno;
258
259 orig_neigh = batadv_v_ogm_orig_get(bat_priv, elp_packet->orig);
260 if (!orig_neigh)
261 return;
262
263 neigh = batadv_neigh_node_new(orig_neigh, if_incoming, neigh_addr);
264 if (!neigh)
265 goto orig_free;
266
267 hardif_neigh = batadv_hardif_neigh_get(if_incoming, neigh_addr);
268 if (!hardif_neigh)
269 goto neigh_free;
270
271 elp_latest_seqno = hardif_neigh->bat_v.elp_latest_seqno;
272 seqno_diff = ntohl(elp_packet->seqno) - elp_latest_seqno;
273
274 /* known or older sequence numbers are ignored. However always adopt
275 * if the router seems to have been restarted.
276 */
277 if (seqno_diff < 1 && seqno_diff > -BATADV_ELP_MAX_AGE)
278 goto hardif_free;
279
280 neigh->last_seen = jiffies;
281 hardif_neigh->last_seen = jiffies;
282 hardif_neigh->bat_v.elp_latest_seqno = ntohl(elp_packet->seqno);
283 hardif_neigh->bat_v.elp_interval = ntohl(elp_packet->elp_interval);
284
285hardif_free:
286 if (hardif_neigh)
287 batadv_hardif_neigh_put(hardif_neigh);
288neigh_free:
289 if (neigh)
290 batadv_neigh_node_put(neigh);
291orig_free:
292 if (orig_neigh)
293 batadv_orig_node_put(orig_neigh);
294}
295
296/**
297 * batadv_v_elp_packet_recv - main ELP packet handler
298 * @skb: the received packet
299 * @if_incoming: the interface this packet was received through
300 *
301 * Return: NET_RX_SUCCESS and consumes the skb if the packet was peoperly
302 * processed or NET_RX_DROP in case of failure.
303 */
304int batadv_v_elp_packet_recv(struct sk_buff *skb,
305 struct batadv_hard_iface *if_incoming)
306{
307 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
308 struct batadv_elp_packet *elp_packet;
309 struct batadv_hard_iface *primary_if;
310 struct ethhdr *ethhdr = (struct ethhdr *)skb_mac_header(skb);
311 bool ret;
312
313 ret = batadv_check_management_packet(skb, if_incoming, BATADV_ELP_HLEN);
314 if (!ret)
315 return NET_RX_DROP;
316
317 if (batadv_is_my_mac(bat_priv, ethhdr->h_source))
318 return NET_RX_DROP;
319
320 /* did we receive a B.A.T.M.A.N. V ELP packet on an interface
321 * that does not have B.A.T.M.A.N. V ELP enabled ?
322 */
323 if (strcmp(bat_priv->bat_algo_ops->name, "BATMAN_V") != 0)
324 return NET_RX_DROP;
325
326 elp_packet = (struct batadv_elp_packet *)skb->data;
327
328 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
329 "Received ELP packet from %pM seqno %u ORIG: %pM\n",
330 ethhdr->h_source, ntohl(elp_packet->seqno),
331 elp_packet->orig);
332
333 primary_if = batadv_primary_if_get_selected(bat_priv);
334 if (!primary_if)
335 goto out;
336
337 batadv_v_elp_neigh_update(bat_priv, ethhdr->h_source, if_incoming,
338 elp_packet);
339
340out:
341 if (primary_if)
342 batadv_hardif_put(primary_if);
343 consume_skb(skb);
344 return NET_RX_SUCCESS;
345}
diff --git a/net/batman-adv/bat_v_elp.h b/net/batman-adv/bat_v_elp.h
index 7a584d1f055b..5a7bc398a9ef 100644
--- a/net/batman-adv/bat_v_elp.h
+++ b/net/batman-adv/bat_v_elp.h
@@ -20,8 +20,12 @@
20#ifndef _NET_BATMAN_ADV_BAT_V_ELP_H_ 20#ifndef _NET_BATMAN_ADV_BAT_V_ELP_H_
21#define _NET_BATMAN_ADV_BAT_V_ELP_H_ 21#define _NET_BATMAN_ADV_BAT_V_ELP_H_
22 22
23struct sk_buff;
24
23int batadv_v_elp_iface_enable(struct batadv_hard_iface *hard_iface); 25int batadv_v_elp_iface_enable(struct batadv_hard_iface *hard_iface);
24void batadv_v_elp_iface_disable(struct batadv_hard_iface *hard_iface); 26void batadv_v_elp_iface_disable(struct batadv_hard_iface *hard_iface);
25void batadv_v_elp_primary_iface_set(struct batadv_hard_iface *primary_iface); 27void batadv_v_elp_primary_iface_set(struct batadv_hard_iface *primary_iface);
28int batadv_v_elp_packet_recv(struct sk_buff *skb,
29 struct batadv_hard_iface *if_incoming);
26 30
27#endif /* _NET_BATMAN_ADV_BAT_V_ELP_H_ */ 31#endif /* _NET_BATMAN_ADV_BAT_V_ELP_H_ */
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 8c01f54c61f3..d91bae270f42 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -60,6 +60,9 @@
60#define BATADV_TQ_LOCAL_BIDRECT_RECV_MINIMUM 1 60#define BATADV_TQ_LOCAL_BIDRECT_RECV_MINIMUM 1
61#define BATADV_TQ_TOTAL_BIDRECT_LIMIT 1 61#define BATADV_TQ_TOTAL_BIDRECT_LIMIT 1
62 62
63/* B.A.T.M.A.N. V */
64#define BATADV_ELP_MAX_AGE 64
65
63/* number of OGMs sent with the last tt diff */ 66/* number of OGMs sent with the last tt diff */
64#define BATADV_TT_OGM_APPEND_MAX 3 67#define BATADV_TT_OGM_APPEND_MAX 3
65 68
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 992d5fd5554e..7fc82a5d4ac4 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -22,6 +22,7 @@
22#error only "main.h" can be included directly 22#error only "main.h" can be included directly
23#endif 23#endif
24 24
25#include <linux/average.h>
25#include <linux/bitops.h> 26#include <linux/bitops.h>
26#include <linux/compiler.h> 27#include <linux/compiler.h>
27#include <linux/if_ether.h> 28#include <linux/if_ether.h>
@@ -364,12 +365,28 @@ struct batadv_gw_node {
364 struct rcu_head rcu; 365 struct rcu_head rcu;
365}; 366};
366 367
368DECLARE_EWMA(throughput, 1024, 8)
369
370/**
371 * struct batadv_hardif_neigh_node_bat_v - B.A.T.M.A.N. V private neighbor
372 * information
373 * @throughput: ewma link throughput towards this neighbor
374 * @elp_interval: time interval between two ELP transmissions
375 * @elp_latest_seqno: latest and best known ELP sequence number
376 */
377struct batadv_hardif_neigh_node_bat_v {
378 struct ewma_throughput throughput;
379 u32 elp_interval;
380 u32 elp_latest_seqno;
381};
382
367/** 383/**
368 * struct batadv_hardif_neigh_node - unique neighbor per hard-interface 384 * struct batadv_hardif_neigh_node - unique neighbor per hard-interface
369 * @list: list node for batadv_hard_iface::neigh_list 385 * @list: list node for batadv_hard_iface::neigh_list
370 * @addr: the MAC address of the neighboring interface 386 * @addr: the MAC address of the neighboring interface
371 * @if_incoming: pointer to incoming hard-interface 387 * @if_incoming: pointer to incoming hard-interface
372 * @last_seen: when last packet via this neighbor was received 388 * @last_seen: when last packet via this neighbor was received
389 * @bat_v: B.A.T.M.A.N. V private data
373 * @refcount: number of contexts the object is used 390 * @refcount: number of contexts the object is used
374 * @rcu: struct used for freeing in a RCU-safe manner 391 * @rcu: struct used for freeing in a RCU-safe manner
375 */ 392 */
@@ -378,6 +395,9 @@ struct batadv_hardif_neigh_node {
378 u8 addr[ETH_ALEN]; 395 u8 addr[ETH_ALEN];
379 struct batadv_hard_iface *if_incoming; 396 struct batadv_hard_iface *if_incoming;
380 unsigned long last_seen; 397 unsigned long last_seen;
398#ifdef CONFIG_BATMAN_ADV_BATMAN_V
399 struct batadv_hardif_neigh_node_bat_v bat_v;
400#endif
381 struct kref refcount; 401 struct kref refcount;
382 struct rcu_head rcu; 402 struct rcu_head rcu;
383}; 403};
@@ -425,10 +445,20 @@ struct batadv_neigh_ifinfo_bat_iv {
425}; 445};
426 446
427/** 447/**
448 * struct batadv_neigh_ifinfo_bat_v - neighbor information per outgoing
449 * interface for B.A.T.M.A.N. V
450 * @throughput: last throughput metric received from originator via this neigh
451 */
452struct batadv_neigh_ifinfo_bat_v {
453 u32 throughput;
454};
455
456/**
428 * struct batadv_neigh_ifinfo - neighbor information per outgoing interface 457 * struct batadv_neigh_ifinfo - neighbor information per outgoing interface
429 * @list: list node for batadv_neigh_node::ifinfo_list 458 * @list: list node for batadv_neigh_node::ifinfo_list
430 * @if_outgoing: pointer to outgoing hard-interface 459 * @if_outgoing: pointer to outgoing hard-interface
431 * @bat_iv: B.A.T.M.A.N. IV private structure 460 * @bat_iv: B.A.T.M.A.N. IV private structure
461 * @bat_v: B.A.T.M.A.N. V private data
432 * @last_ttl: last received ttl from this neigh node 462 * @last_ttl: last received ttl from this neigh node
433 * @refcount: number of contexts the object is used 463 * @refcount: number of contexts the object is used
434 * @rcu: struct used for freeing in a RCU-safe manner 464 * @rcu: struct used for freeing in a RCU-safe manner
@@ -437,6 +467,9 @@ struct batadv_neigh_ifinfo {
437 struct hlist_node list; 467 struct hlist_node list;
438 struct batadv_hard_iface *if_outgoing; 468 struct batadv_hard_iface *if_outgoing;
439 struct batadv_neigh_ifinfo_bat_iv bat_iv; 469 struct batadv_neigh_ifinfo_bat_iv bat_iv;
470#ifdef CONFIG_BATMAN_ADV_BATMAN_V
471 struct batadv_neigh_ifinfo_bat_v bat_v;
472#endif
440 u8 last_ttl; 473 u8 last_ttl;
441 struct kref refcount; 474 struct kref refcount;
442 struct rcu_head rcu; 475 struct rcu_head rcu;