Blame view

net/batman-adv/bat_v_elp.c 16.7 KB
ac79cbb96   Sven Eckelmann   batman-adv: updat...
1
  /* Copyright (C) 2011-2017  B.A.T.M.A.N. contributors:
d6f94d91f   Linus Luessing   batman-adv: ELP -...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
   *
   * Linus Lüssing, Marek Lindner
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of version 2 of the GNU General Public
   * License as published by the Free Software Foundation.
   *
   * This program is distributed in the hope that it will be useful, but
   * WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, see <http://www.gnu.org/licenses/>.
   */
  
  #include "bat_v_elp.h"
  #include "main.h"
  
  #include <linux/atomic.h>
d62890885   Sven Eckelmann   batman-adv: Accep...
22
  #include <linux/bitops.h>
d6f94d91f   Linus Luessing   batman-adv: ELP -...
23
24
25
  #include <linux/byteorder/generic.h>
  #include <linux/errno.h>
  #include <linux/etherdevice.h>
c833484e5   Antonio Quartulli   batman-adv: ELP -...
26
  #include <linux/ethtool.h>
d6f94d91f   Linus Luessing   batman-adv: ELP -...
27
28
29
30
  #include <linux/fs.h>
  #include <linux/if_ether.h>
  #include <linux/jiffies.h>
  #include <linux/kernel.h>
c833484e5   Antonio Quartulli   batman-adv: ELP -...
31
  #include <linux/kref.h>
d6f94d91f   Linus Luessing   batman-adv: ELP -...
32
  #include <linux/netdevice.h>
d62890885   Sven Eckelmann   batman-adv: Accep...
33
  #include <linux/nl80211.h>
d6f94d91f   Linus Luessing   batman-adv: ELP -...
34
35
36
  #include <linux/random.h>
  #include <linux/rculist.h>
  #include <linux/rcupdate.h>
c833484e5   Antonio Quartulli   batman-adv: ELP -...
37
  #include <linux/rtnetlink.h>
d6f94d91f   Linus Luessing   batman-adv: ELP -...
38
39
40
41
42
  #include <linux/skbuff.h>
  #include <linux/stddef.h>
  #include <linux/string.h>
  #include <linux/types.h>
  #include <linux/workqueue.h>
c833484e5   Antonio Quartulli   batman-adv: ELP -...
43
  #include <net/cfg80211.h>
d6f94d91f   Linus Luessing   batman-adv: ELP -...
44
45
  
  #include "bat_algo.h"
9323158ef   Antonio Quartulli   batman-adv: OGMv2...
46
  #include "bat_v_ogm.h"
d6f94d91f   Linus Luessing   batman-adv: ELP -...
47
  #include "hard-interface.h"
ba412080f   Sven Eckelmann   batman-adv: Conso...
48
  #include "log.h"
162bd64c2   Linus Luessing   batman-adv: ELP -...
49
  #include "originator.h"
d6f94d91f   Linus Luessing   batman-adv: ELP -...
50
  #include "packet.h"
162bd64c2   Linus Luessing   batman-adv: ELP -...
51
  #include "routing.h"
d6f94d91f   Linus Luessing   batman-adv: ELP -...
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  #include "send.h"
  
  /**
   * batadv_v_elp_start_timer - restart timer for ELP periodic work
   * @hard_iface: the interface for which the timer has to be reset
   */
  static void batadv_v_elp_start_timer(struct batadv_hard_iface *hard_iface)
  {
  	unsigned int msecs;
  
  	msecs = atomic_read(&hard_iface->bat_v.elp_interval) - BATADV_JITTER;
  	msecs += prandom_u32() % (2 * BATADV_JITTER);
  
  	queue_delayed_work(batadv_event_workqueue, &hard_iface->bat_v.elp_wq,
  			   msecs_to_jiffies(msecs));
  }
  
  /**
c833484e5   Antonio Quartulli   batman-adv: ELP -...
70
71
72
73
74
75
76
77
78
79
   * batadv_v_elp_get_throughput - get the throughput towards a neighbour
   * @neigh: the neighbour for which the throughput has to be obtained
   *
   * Return: The throughput towards the given neighbour in multiples of 100kpbs
   *         (a value of '1' equals to 0.1Mbps, '10' equals 1Mbps, etc).
   */
  static u32 batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh)
  {
  	struct batadv_hard_iface *hard_iface = neigh->if_incoming;
  	struct ethtool_link_ksettings link_settings;
1942de1bb   Marek Lindner   batman-adv: retri...
80
  	struct net_device *real_netdev;
c833484e5   Antonio Quartulli   batman-adv: ELP -...
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  	struct station_info sinfo;
  	u32 throughput;
  	int ret;
  
  	/* if the user specified a customised value for this interface, then
  	 * return it directly
  	 */
  	throughput =  atomic_read(&hard_iface->bat_v.throughput_override);
  	if (throughput != 0)
  		return throughput;
  
  	/* if this is a wireless device, then ask its throughput through
  	 * cfg80211 API
  	 */
10b1bbb46   Sven Eckelmann   batman-adv: Cache...
95
96
  	if (batadv_is_wifi_hardif(hard_iface)) {
  		if (!batadv_is_cfg80211_hardif(hard_iface))
f44a3ae9a   Marek Lindner   batman-adv: refac...
97
98
  			/* unsupported WiFi driver version */
  			goto default_throughput;
c833484e5   Antonio Quartulli   batman-adv: ELP -...
99

1942de1bb   Marek Lindner   batman-adv: retri...
100
101
102
103
104
105
106
  		real_netdev = batadv_get_real_netdev(hard_iface->net_dev);
  		if (!real_netdev)
  			goto default_throughput;
  
  		ret = cfg80211_get_station(real_netdev, neigh->addr, &sinfo);
  
  		dev_put(real_netdev);
f44a3ae9a   Marek Lindner   batman-adv: refac...
107
108
109
110
111
112
113
  		if (ret == -ENOENT) {
  			/* Node is not associated anymore! It would be
  			 * possible to delete this neighbor. For now set
  			 * the throughput metric to 0.
  			 */
  			return 0;
  		}
3f3f87325   Sven Eckelmann   batman-adv: Use d...
114
115
  		if (ret)
  			goto default_throughput;
d62890885   Sven Eckelmann   batman-adv: Accep...
116
117
  		if (!(sinfo.filled & BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT)))
  			goto default_throughput;
3f3f87325   Sven Eckelmann   batman-adv: Use d...
118
119
  
  		return sinfo.expected_throughput / 100;
c833484e5   Antonio Quartulli   batman-adv: ELP -...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
  	}
  
  	/* if not a wifi interface, check if this device provides data via
  	 * ethtool (e.g. an Ethernet adapter)
  	 */
  	memset(&link_settings, 0, sizeof(link_settings));
  	rtnl_lock();
  	ret = __ethtool_get_link_ksettings(hard_iface->net_dev, &link_settings);
  	rtnl_unlock();
  	if (ret == 0) {
  		/* link characteristics might change over time */
  		if (link_settings.base.duplex == DUPLEX_FULL)
  			hard_iface->bat_v.flags |= BATADV_FULL_DUPLEX;
  		else
  			hard_iface->bat_v.flags &= ~BATADV_FULL_DUPLEX;
  
  		throughput = link_settings.base.speed;
  		if (throughput && (throughput != SPEED_UNKNOWN))
  			return throughput * 10;
  	}
  
  default_throughput:
  	if (!(hard_iface->bat_v.flags & BATADV_WARNING_DEFAULT)) {
  		batadv_info(hard_iface->soft_iface,
  			    "WiFi driver or ethtool info does not provide information about link speeds on interface %s, therefore defaulting to hardcoded throughput values of %u.%1u Mbps. Consider overriding the throughput manually or checking your driver.
  ",
  			    hard_iface->net_dev->name,
  			    BATADV_THROUGHPUT_DEFAULT_VALUE / 10,
  			    BATADV_THROUGHPUT_DEFAULT_VALUE % 10);
  		hard_iface->bat_v.flags |= BATADV_WARNING_DEFAULT;
  	}
  
  	/* if none of the above cases apply, return the base_throughput */
  	return BATADV_THROUGHPUT_DEFAULT_VALUE;
  }
  
  /**
   * batadv_v_elp_throughput_metric_update - worker updating the throughput metric
   *  of a single hop neighbour
   * @work: the work queue item
   */
  void batadv_v_elp_throughput_metric_update(struct work_struct *work)
  {
  	struct batadv_hardif_neigh_node_bat_v *neigh_bat_v;
  	struct batadv_hardif_neigh_node *neigh;
  
  	neigh_bat_v = container_of(work, struct batadv_hardif_neigh_node_bat_v,
  				   metric_work);
  	neigh = container_of(neigh_bat_v, struct batadv_hardif_neigh_node,
  			     bat_v);
  
  	ewma_throughput_add(&neigh->bat_v.throughput,
  			    batadv_v_elp_get_throughput(neigh));
  
  	/* decrement refcounter to balance increment performed before scheduling
  	 * this task
  	 */
  	batadv_hardif_neigh_put(neigh);
  }
  
  /**
8d2d499e0   Antonio Quartulli   batman-adv: ELP -...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
   * batadv_v_elp_wifi_neigh_probe - send link probing packets to a neighbour
   * @neigh: the neighbour to probe
   *
   * Sends a predefined number of unicast wifi packets to a given neighbour in
   * order to trigger the throughput estimation on this link by the RC algorithm.
   * Packets are sent only if there there is not enough payload unicast traffic
   * towards this neighbour..
   *
   * Return: True on success and false in case of error during skb preparation.
   */
  static bool
  batadv_v_elp_wifi_neigh_probe(struct batadv_hardif_neigh_node *neigh)
  {
  	struct batadv_hard_iface *hard_iface = neigh->if_incoming;
  	struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  	unsigned long last_tx_diff;
  	struct sk_buff *skb;
  	int probe_len, i;
  	int elp_skb_len;
  
  	/* this probing routine is for Wifi neighbours only */
10b1bbb46   Sven Eckelmann   batman-adv: Cache...
202
  	if (!batadv_is_wifi_hardif(hard_iface))
8d2d499e0   Antonio Quartulli   batman-adv: ELP -...
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
  		return true;
  
  	/* probe the neighbor only if no unicast packets have been sent
  	 * to it in the last 100 milliseconds: this is the rate control
  	 * algorithm sampling interval (minstrel). In this way, if not
  	 * enough traffic has been sent to the neighbor, batman-adv can
  	 * generate 2 probe packets and push the RC algorithm to perform
  	 * the sampling
  	 */
  	last_tx_diff = jiffies_to_msecs(jiffies - neigh->bat_v.last_unicast_tx);
  	if (last_tx_diff <= BATADV_ELP_PROBE_MAX_TX_DIFF)
  		return true;
  
  	probe_len = max_t(int, sizeof(struct batadv_elp_packet),
  			  BATADV_ELP_MIN_PROBE_SIZE);
  
  	for (i = 0; i < BATADV_ELP_PROBES_PER_NODE; i++) {
  		elp_skb_len = hard_iface->bat_v.elp_skb->len;
  		skb = skb_copy_expand(hard_iface->bat_v.elp_skb, 0,
  				      probe_len - elp_skb_len,
  				      GFP_ATOMIC);
  		if (!skb)
  			return false;
  
  		/* Tell the skb to get as big as the allocated space (we want
  		 * the packet to be exactly of that size to make the link
  		 * throughput estimation effective.
  		 */
fa04cc5e7   Sven Eckelmann   batman-adv: Avoid...
231
  		skb_put_zero(skb, probe_len - hard_iface->bat_v.elp_skb->len);
8d2d499e0   Antonio Quartulli   batman-adv: ELP -...
232
233
234
235
236
237
238
239
240
241
242
243
244
  
  		batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  			   "Sending unicast (probe) ELP packet on interface %s to %pM
  ",
  			   hard_iface->net_dev->name, neigh->addr);
  
  		batadv_send_skb_packet(skb, hard_iface, neigh->addr);
  	}
  
  	return true;
  }
  
  /**
d6f94d91f   Linus Luessing   batman-adv: ELP -...
245
246
247
248
249
250
251
   * batadv_v_elp_periodic_work - ELP periodic task per interface
   * @work: work queue item
   *
   * Emits broadcast ELP message in regular intervals.
   */
  static void batadv_v_elp_periodic_work(struct work_struct *work)
  {
c833484e5   Antonio Quartulli   batman-adv: ELP -...
252
  	struct batadv_hardif_neigh_node *hardif_neigh;
d6f94d91f   Linus Luessing   batman-adv: ELP -...
253
254
255
256
257
258
  	struct batadv_hard_iface *hard_iface;
  	struct batadv_hard_iface_bat_v *bat_v;
  	struct batadv_elp_packet *elp_packet;
  	struct batadv_priv *bat_priv;
  	struct sk_buff *skb;
  	u32 elp_interval;
498c536f5   Marek Lindner   batman-adv: fix h...
259
  	bool ret;
d6f94d91f   Linus Luessing   batman-adv: ELP -...
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
  
  	bat_v = container_of(work, struct batadv_hard_iface_bat_v, elp_wq.work);
  	hard_iface = container_of(bat_v, struct batadv_hard_iface, bat_v);
  	bat_priv = netdev_priv(hard_iface->soft_iface);
  
  	if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING)
  		goto out;
  
  	/* we are in the process of shutting this interface down */
  	if ((hard_iface->if_status == BATADV_IF_NOT_IN_USE) ||
  	    (hard_iface->if_status == BATADV_IF_TO_BE_REMOVED))
  		goto out;
  
  	/* the interface was enabled but may not be ready yet */
  	if (hard_iface->if_status != BATADV_IF_ACTIVE)
  		goto restart_timer;
  
  	skb = skb_copy(hard_iface->bat_v.elp_skb, GFP_ATOMIC);
  	if (!skb)
  		goto restart_timer;
  
  	elp_packet = (struct batadv_elp_packet *)skb->data;
  	elp_packet->seqno = htonl(atomic_read(&hard_iface->bat_v.elp_seqno));
  	elp_interval = atomic_read(&hard_iface->bat_v.elp_interval);
  	elp_packet->elp_interval = htonl(elp_interval);
  
  	batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  		   "Sending broadcast ELP packet on interface %s, seqno %u
  ",
  		   hard_iface->net_dev->name,
  		   atomic_read(&hard_iface->bat_v.elp_seqno));
95d392784   Antonio Quartulli   batman-adv: keep ...
291
  	batadv_send_broadcast_skb(skb, hard_iface);
d6f94d91f   Linus Luessing   batman-adv: ELP -...
292
293
  
  	atomic_inc(&hard_iface->bat_v.elp_seqno);
c833484e5   Antonio Quartulli   batman-adv: ELP -...
294
295
296
297
298
299
300
301
302
303
304
305
306
  	/* The throughput metric is updated on each sent packet. This way, if a
  	 * node is dead and no longer sends packets, batman-adv is still able to
  	 * react timely to its death.
  	 *
  	 * The throughput metric is updated by following these steps:
  	 * 1) if the hard_iface is wifi => send a number of unicast ELPs for
  	 *    probing/sampling to each neighbor
  	 * 2) update the throughput metric value of each neighbor (note that the
  	 *    value retrieved in this step might be 100ms old because the
  	 *    probing packets at point 1) could still be in the HW queue)
  	 */
  	rcu_read_lock();
  	hlist_for_each_entry_rcu(hardif_neigh, &hard_iface->neigh_list, list) {
8d2d499e0   Antonio Quartulli   batman-adv: ELP -...
307
308
309
310
311
  		if (!batadv_v_elp_wifi_neigh_probe(hardif_neigh))
  			/* if something goes wrong while probing, better to stop
  			 * sending packets immediately and reschedule the task
  			 */
  			break;
c833484e5   Antonio Quartulli   batman-adv: ELP -...
312
313
314
315
316
317
318
  		if (!kref_get_unless_zero(&hardif_neigh->refcount))
  			continue;
  
  		/* Reading the estimated throughput from cfg80211 is a task that
  		 * may sleep and that is not allowed in an rcu protected
  		 * context. Therefore schedule a task for that.
  		 */
498c536f5   Marek Lindner   batman-adv: fix h...
319
320
321
322
323
  		ret = queue_work(batadv_event_workqueue,
  				 &hardif_neigh->bat_v.metric_work);
  
  		if (!ret)
  			batadv_hardif_neigh_put(hardif_neigh);
c833484e5   Antonio Quartulli   batman-adv: ELP -...
324
325
  	}
  	rcu_read_unlock();
d6f94d91f   Linus Luessing   batman-adv: ELP -...
326
327
328
329
330
331
332
333
334
335
336
337
338
339
  restart_timer:
  	batadv_v_elp_start_timer(hard_iface);
  out:
  	return;
  }
  
  /**
   * batadv_v_elp_iface_enable - setup the ELP interface private resources
   * @hard_iface: interface for which the data has to be prepared
   *
   * Return: 0 on success or a -ENOMEM in case of failure.
   */
  int batadv_v_elp_iface_enable(struct batadv_hard_iface *hard_iface)
  {
94f748fd4   Sven Eckelmann   batman-adv: Use e...
340
  	static const size_t tvlv_padding = sizeof(__be32);
d6f94d91f   Linus Luessing   batman-adv: ELP -...
341
342
343
344
345
  	struct batadv_elp_packet *elp_packet;
  	unsigned char *elp_buff;
  	u32 random_seqno;
  	size_t size;
  	int res = -ENOMEM;
94f748fd4   Sven Eckelmann   batman-adv: Use e...
346
  	size = ETH_HLEN + NET_IP_ALIGN + BATADV_ELP_HLEN + tvlv_padding;
d6f94d91f   Linus Luessing   batman-adv: ELP -...
347
348
349
350
351
  	hard_iface->bat_v.elp_skb = dev_alloc_skb(size);
  	if (!hard_iface->bat_v.elp_skb)
  		goto out;
  
  	skb_reserve(hard_iface->bat_v.elp_skb, ETH_HLEN + NET_IP_ALIGN);
94f748fd4   Sven Eckelmann   batman-adv: Use e...
352
353
  	elp_buff = skb_put_zero(hard_iface->bat_v.elp_skb,
  				BATADV_ELP_HLEN + tvlv_padding);
d6f94d91f   Linus Luessing   batman-adv: ELP -...
354
  	elp_packet = (struct batadv_elp_packet *)elp_buff;
d6f94d91f   Linus Luessing   batman-adv: ELP -...
355
356
357
358
359
360
361
  
  	elp_packet->packet_type = BATADV_ELP;
  	elp_packet->version = BATADV_COMPAT_VERSION;
  
  	/* randomize initial seqno to avoid collision */
  	get_random_bytes(&random_seqno, sizeof(random_seqno));
  	atomic_set(&hard_iface->bat_v.elp_seqno, random_seqno);
d6f94d91f   Linus Luessing   batman-adv: ELP -...
362

c833484e5   Antonio Quartulli   batman-adv: ELP -...
363
364
365
366
367
  	/* assume full-duplex by default */
  	hard_iface->bat_v.flags |= BATADV_FULL_DUPLEX;
  
  	/* warn the user (again) if there is no throughput data is available */
  	hard_iface->bat_v.flags &= ~BATADV_WARNING_DEFAULT;
10b1bbb46   Sven Eckelmann   batman-adv: Cache...
368
  	if (batadv_is_wifi_hardif(hard_iface))
c833484e5   Antonio Quartulli   batman-adv: ELP -...
369
  		hard_iface->bat_v.flags &= ~BATADV_FULL_DUPLEX;
d6f94d91f   Linus Luessing   batman-adv: ELP -...
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
  	INIT_DELAYED_WORK(&hard_iface->bat_v.elp_wq,
  			  batadv_v_elp_periodic_work);
  	batadv_v_elp_start_timer(hard_iface);
  	res = 0;
  
  out:
  	return res;
  }
  
  /**
   * batadv_v_elp_iface_disable - release ELP interface private resources
   * @hard_iface: interface for which the resources have to be released
   */
  void batadv_v_elp_iface_disable(struct batadv_hard_iface *hard_iface)
  {
  	cancel_delayed_work_sync(&hard_iface->bat_v.elp_wq);
  
  	dev_kfree_skb(hard_iface->bat_v.elp_skb);
  	hard_iface->bat_v.elp_skb = NULL;
  }
  
  /**
ebe24cea9   Marek Lindner   batman-adv: initi...
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
   * batadv_v_elp_iface_activate - update the ELP buffer belonging to the given
   *  hard-interface
   * @primary_iface: the new primary interface
   * @hard_iface: interface holding the to-be-updated buffer
   */
  void batadv_v_elp_iface_activate(struct batadv_hard_iface *primary_iface,
  				 struct batadv_hard_iface *hard_iface)
  {
  	struct batadv_elp_packet *elp_packet;
  	struct sk_buff *skb;
  
  	if (!hard_iface->bat_v.elp_skb)
  		return;
  
  	skb = hard_iface->bat_v.elp_skb;
  	elp_packet = (struct batadv_elp_packet *)skb->data;
  	ether_addr_copy(elp_packet->orig,
  			primary_iface->net_dev->dev_addr);
  }
  
  /**
d6f94d91f   Linus Luessing   batman-adv: ELP -...
413
414
415
416
417
418
419
   * batadv_v_elp_primary_iface_set - change internal data to reflect the new
   *  primary interface
   * @primary_iface: the new primary interface
   */
  void batadv_v_elp_primary_iface_set(struct batadv_hard_iface *primary_iface)
  {
  	struct batadv_hard_iface *hard_iface;
d6f94d91f   Linus Luessing   batman-adv: ELP -...
420
421
422
423
424
425
  
  	/* update orig field of every elp iface belonging to this mesh */
  	rcu_read_lock();
  	list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
  		if (primary_iface->soft_iface != hard_iface->soft_iface)
  			continue;
ebe24cea9   Marek Lindner   batman-adv: initi...
426
  		batadv_v_elp_iface_activate(primary_iface, hard_iface);
d6f94d91f   Linus Luessing   batman-adv: ELP -...
427
428
429
  	}
  	rcu_read_unlock();
  }
162bd64c2   Linus Luessing   batman-adv: ELP -...
430
431
  
  /**
162bd64c2   Linus Luessing   batman-adv: ELP -...
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
   * batadv_v_elp_neigh_update - update an ELP neighbour node
   * @bat_priv: the bat priv with all the soft interface information
   * @neigh_addr: the neighbour interface address
   * @if_incoming: the interface the packet was received through
   * @elp_packet: the received ELP packet
   *
   * Updates the ELP neighbour node state with the data received within the new
   * ELP packet.
   */
  static void batadv_v_elp_neigh_update(struct batadv_priv *bat_priv,
  				      u8 *neigh_addr,
  				      struct batadv_hard_iface *if_incoming,
  				      struct batadv_elp_packet *elp_packet)
  
  {
  	struct batadv_neigh_node *neigh;
  	struct batadv_orig_node *orig_neigh;
  	struct batadv_hardif_neigh_node *hardif_neigh;
  	s32 seqno_diff;
  	s32 elp_latest_seqno;
  
  	orig_neigh = batadv_v_ogm_orig_get(bat_priv, elp_packet->orig);
  	if (!orig_neigh)
  		return;
6f0a6b5ee   Marek Lindner   batman-adv: refac...
456
457
  	neigh = batadv_neigh_node_get_or_create(orig_neigh,
  						if_incoming, neigh_addr);
162bd64c2   Linus Luessing   batman-adv: ELP -...
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
  	if (!neigh)
  		goto orig_free;
  
  	hardif_neigh = batadv_hardif_neigh_get(if_incoming, neigh_addr);
  	if (!hardif_neigh)
  		goto neigh_free;
  
  	elp_latest_seqno = hardif_neigh->bat_v.elp_latest_seqno;
  	seqno_diff = ntohl(elp_packet->seqno) - elp_latest_seqno;
  
  	/* known or older sequence numbers are ignored. However always adopt
  	 * if the router seems to have been restarted.
  	 */
  	if (seqno_diff < 1 && seqno_diff > -BATADV_ELP_MAX_AGE)
  		goto hardif_free;
  
  	neigh->last_seen = jiffies;
  	hardif_neigh->last_seen = jiffies;
  	hardif_neigh->bat_v.elp_latest_seqno = ntohl(elp_packet->seqno);
  	hardif_neigh->bat_v.elp_interval = ntohl(elp_packet->elp_interval);
  
  hardif_free:
  	if (hardif_neigh)
  		batadv_hardif_neigh_put(hardif_neigh);
  neigh_free:
  	if (neigh)
  		batadv_neigh_node_put(neigh);
  orig_free:
  	if (orig_neigh)
  		batadv_orig_node_put(orig_neigh);
  }
  
  /**
   * batadv_v_elp_packet_recv - main ELP packet handler
   * @skb: the received packet
   * @if_incoming: the interface this packet was received through
   *
   * Return: NET_RX_SUCCESS and consumes the skb if the packet was peoperly
   * processed or NET_RX_DROP in case of failure.
   */
  int batadv_v_elp_packet_recv(struct sk_buff *skb,
  			     struct batadv_hard_iface *if_incoming)
  {
  	struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
  	struct batadv_elp_packet *elp_packet;
  	struct batadv_hard_iface *primary_if;
  	struct ethhdr *ethhdr = (struct ethhdr *)skb_mac_header(skb);
b91a2543b   Sven Eckelmann   batman-adv: Consu...
505
506
  	bool res;
  	int ret = NET_RX_DROP;
162bd64c2   Linus Luessing   batman-adv: ELP -...
507

b91a2543b   Sven Eckelmann   batman-adv: Consu...
508
509
510
  	res = batadv_check_management_packet(skb, if_incoming, BATADV_ELP_HLEN);
  	if (!res)
  		goto free_skb;
162bd64c2   Linus Luessing   batman-adv: ELP -...
511
512
  
  	if (batadv_is_my_mac(bat_priv, ethhdr->h_source))
b91a2543b   Sven Eckelmann   batman-adv: Consu...
513
  		goto free_skb;
162bd64c2   Linus Luessing   batman-adv: ELP -...
514
515
516
517
  
  	/* did we receive a B.A.T.M.A.N. V ELP packet on an interface
  	 * that does not have B.A.T.M.A.N. V ELP enabled ?
  	 */
29824a55c   Antonio Quartulli   batman-adv: split...
518
  	if (strcmp(bat_priv->algo_ops->name, "BATMAN_V") != 0)
b91a2543b   Sven Eckelmann   batman-adv: Consu...
519
  		goto free_skb;
162bd64c2   Linus Luessing   batman-adv: ELP -...
520
521
522
523
524
525
526
527
528
529
530
  
  	elp_packet = (struct batadv_elp_packet *)skb->data;
  
  	batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  		   "Received ELP packet from %pM seqno %u ORIG: %pM
  ",
  		   ethhdr->h_source, ntohl(elp_packet->seqno),
  		   elp_packet->orig);
  
  	primary_if = batadv_primary_if_get_selected(bat_priv);
  	if (!primary_if)
b91a2543b   Sven Eckelmann   batman-adv: Consu...
531
  		goto free_skb;
162bd64c2   Linus Luessing   batman-adv: ELP -...
532
533
534
  
  	batadv_v_elp_neigh_update(bat_priv, ethhdr->h_source, if_incoming,
  				  elp_packet);
b91a2543b   Sven Eckelmann   batman-adv: Consu...
535
536
537
538
539
540
541
542
543
544
  	ret = NET_RX_SUCCESS;
  	batadv_hardif_put(primary_if);
  
  free_skb:
  	if (ret == NET_RX_SUCCESS)
  		consume_skb(skb);
  	else
  		kfree_skb(skb);
  
  	return ret;
162bd64c2   Linus Luessing   batman-adv: ELP -...
545
  }