xref: /linux/net/batman-adv/types.h (revision 91ec2035134982b98fab0609a9fd8480e8217dc1)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) B.A.T.M.A.N. contributors:
3  *
4  * Marek Lindner, Simon Wunderlich
5  */
6 
7 #ifndef _NET_BATMAN_ADV_TYPES_H_
8 #define _NET_BATMAN_ADV_TYPES_H_
9 
10 #ifndef _NET_BATMAN_ADV_MAIN_H_
11 #error only "main.h" can be included directly
12 #endif
13 
14 #include <linux/average.h>
15 #include <linux/bitops.h>
16 #include <linux/compiler.h>
17 #include <linux/completion.h>
18 #include <linux/if.h>
19 #include <linux/if_ether.h>
20 #include <linux/kref.h>
21 #include <linux/mutex.h>
22 #include <linux/netdevice.h>
23 #include <linux/netlink.h>
24 #include <linux/rhashtable-types.h>
25 #include <linux/sched.h> /* for linux/wait.h */
26 #include <linux/skbuff.h>
27 #include <linux/spinlock.h>
28 #include <linux/timer.h>
29 #include <linux/types.h>
30 #include <linux/wait.h>
31 #include <linux/workqueue.h>
32 #include <uapi/linux/batadv_packet.h>
33 #include <uapi/linux/batman_adv.h>
34 
35 #ifdef CONFIG_BATMAN_ADV_DAT
36 
37 /**
38  * typedef batadv_dat_addr_t - type used for all DHT addresses
39  *
40  * If it is changed, BATADV_DAT_ADDR_MAX is changed as well.
41  *
42  * *Please be careful: batadv_dat_addr_t must be UNSIGNED*
43  */
44 typedef u16 batadv_dat_addr_t;
45 
46 #endif /* CONFIG_BATMAN_ADV_DAT */
47 
48 /**
49  * enum batadv_dhcp_recipient - dhcp destination
50  */
51 enum batadv_dhcp_recipient {
52 	/** @BATADV_DHCP_NO: packet is not a dhcp message */
53 	BATADV_DHCP_NO = 0,
54 
55 	/** @BATADV_DHCP_TO_SERVER: dhcp message is directed to a server */
56 	BATADV_DHCP_TO_SERVER,
57 
58 	/** @BATADV_DHCP_TO_CLIENT: dhcp message is directed to a client */
59 	BATADV_DHCP_TO_CLIENT,
60 };
61 
62 /**
63  * BATADV_TT_REMOTE_MASK - bitmask selecting the flags that are sent over the
64  *  wire only
65  */
66 #define BATADV_TT_REMOTE_MASK	0x00FF
67 
68 /**
69  * BATADV_TT_SYNC_MASK - bitmask of the flags that need to be kept in sync
70  *  among the nodes. These flags are used to compute the global/local CRC
71  */
72 #define BATADV_TT_SYNC_MASK	0x00F0
73 
74 /**
75  * struct batadv_ogm_buf - Buffer to construct an OGM with TVLV
76  */
77 struct batadv_ogm_buf {
78 	/** @buf: buffer holding the OGM packet */
79 	void *buf;
80 
81 	/** @len: length of the OGM packet buffer data */
82 	size_t len;
83 
84 	/** @capacity: size of allocated buf */
85 	size_t capacity;
86 
87 	/** @header_length: fixed size header length (must be <= len) */
88 	size_t header_length;
89 };
90 
91 /**
92  * struct batadv_hard_iface_bat_iv - per hard-interface B.A.T.M.A.N. IV data
93  */
94 struct batadv_hard_iface_bat_iv {
95 	/** @ogm_buff: buffer holding the OGM packet */
96 	struct batadv_ogm_buf ogm_buff;
97 
98 	/** @ogm_seqno: OGM sequence number - used to identify each OGM */
99 	atomic_t ogm_seqno;
100 
101 	/** @reschedule_work: recover OGM schedule after schedule error */
102 	struct delayed_work reschedule_work;
103 
104 	/** @ogm_buff_mutex: lock protecting ogm_buff */
105 	struct mutex ogm_buff_mutex;
106 };
107 
108 /**
109  * enum batadv_v_hard_iface_flags - interface flags useful to B.A.T.M.A.N. V
110  */
111 enum batadv_v_hard_iface_flags {
112 	/**
113 	 * @BATADV_FULL_DUPLEX: tells if the connection over this link is
114 	 *  full-duplex
115 	 */
116 	BATADV_FULL_DUPLEX	= BIT(0),
117 
118 	/**
119 	 * @BATADV_WARNING_DEFAULT: tells whether we have warned the user that
120 	 *  no throughput data is available for this interface and that default
121 	 *  values are assumed.
122 	 */
123 	BATADV_WARNING_DEFAULT	= BIT(1),
124 };
125 
126 /**
127  * struct batadv_hard_iface_bat_v - per hard-interface B.A.T.M.A.N. V data
128  */
129 struct batadv_hard_iface_bat_v {
130 	/** @elp_interval: time interval between two ELP transmissions */
131 	u32 elp_interval;
132 
133 	/** @elp_seqno: current ELP sequence number */
134 	atomic_t elp_seqno;
135 
136 	/** @elp_skb: base skb containing the ELP message to send */
137 	struct sk_buff *elp_skb;
138 
139 	/** @elp_wq: workqueue used to schedule ELP transmissions */
140 	struct delayed_work elp_wq;
141 
142 	/** @aggr_wq: workqueue used to transmit queued OGM packets */
143 	struct delayed_work aggr_wq;
144 
145 	/** @aggr_list: queue for to be aggregated OGM packets */
146 	struct sk_buff_head aggr_list;
147 
148 	/**
149 	 * @aggr_list_enabled: aggr_list is active and new skbs can be
150 	 * enqueued. Protected by aggr_list.lock after initialization
151 	 */
152 	bool aggr_list_enabled:1;
153 
154 	/** @aggr_len: size of the OGM aggregate (excluding ethernet header) */
155 	unsigned int aggr_len;
156 
157 	/**
158 	 * @throughput_override: throughput override to disable link
159 	 *  auto-detection
160 	 */
161 	u32 throughput_override;
162 
163 	/** @flags: interface specific flags */
164 	u8 flags;
165 };
166 
167 /**
168  * enum batadv_hard_iface_wifi_flags - Flags describing the wifi configuration
169  *  of a batadv_hard_iface
170  */
171 enum batadv_hard_iface_wifi_flags {
172 	/** @BATADV_HARDIF_WIFI_WEXT_DIRECT: it is a wext wifi device */
173 	BATADV_HARDIF_WIFI_WEXT_DIRECT = BIT(0),
174 
175 	/** @BATADV_HARDIF_WIFI_CFG80211_DIRECT: it is a cfg80211 wifi device */
176 	BATADV_HARDIF_WIFI_CFG80211_DIRECT = BIT(1),
177 
178 	/**
179 	 * @BATADV_HARDIF_WIFI_WEXT_INDIRECT: link device is a wext wifi device
180 	 */
181 	BATADV_HARDIF_WIFI_WEXT_INDIRECT = BIT(2),
182 
183 	/**
184 	 * @BATADV_HARDIF_WIFI_CFG80211_INDIRECT: link device is a cfg80211 wifi
185 	 * device
186 	 */
187 	BATADV_HARDIF_WIFI_CFG80211_INDIRECT = BIT(3),
188 };
189 
190 /**
191  * struct batadv_wifi_net_device_state - cache of wifi information of net_devices
192  */
193 struct batadv_wifi_net_device_state {
194 	/** @l: anchor in rhashtable */
195 	struct rhash_head l;
196 
197 	/** @netdev: pointer to the net_device */
198 	struct net_device *netdev;
199 
200 	/** @dev_tracker: device tracker for @netdev */
201 	netdevice_tracker dev_tracker;
202 
203 	/**
204 	 * @wifi_flags: flags whether this is (directly or indirectly) a wifi
205 	 *  interface
206 	 */
207 	u32 wifi_flags;
208 
209 	/** @rcu: struct used for freeing in an RCU-safe manner */
210 	struct rcu_head rcu;
211 };
212 
213 /**
214  * struct batadv_hard_iface - network device known to batman-adv
215  */
216 struct batadv_hard_iface {
217 	/** @if_status: status of the interface for batman-adv */
218 	char if_status;
219 
220 	/**
221 	 * @num_bcasts: number of payload re-broadcasts on this interface (ARQ)
222 	 */
223 	u8 num_bcasts;
224 
225 	/** @net_dev: pointer to the net_device */
226 	struct net_device *net_dev;
227 
228 	/** @dev_tracker: device tracker for @net_dev */
229 	netdevice_tracker dev_tracker;
230 
231 	/** @refcount: number of contexts the object is used */
232 	struct kref refcount;
233 
234 	/**
235 	 * @batman_adv_ptype: packet type describing packets that should be
236 	 * processed by batman-adv for this interface
237 	 */
238 	struct packet_type batman_adv_ptype;
239 
240 	/**
241 	 * @mesh_iface: the batman-adv interface which uses this network
242 	 *  interface
243 	 */
244 	struct net_device *mesh_iface;
245 
246 	/** @meshif_dev_tracker: device tracker for @mesh_iface */
247 	netdevice_tracker meshif_dev_tracker;
248 
249 	/** @rcu: struct used for freeing in an RCU-safe manner */
250 	struct rcu_head rcu;
251 
252 	/**
253 	 * @hop_penalty: penalty which will be applied to the tq-field
254 	 * of an OGM received via this interface
255 	 */
256 	u8 hop_penalty;
257 
258 	/** @bat_iv: per hard-interface B.A.T.M.A.N. IV data */
259 	struct batadv_hard_iface_bat_iv bat_iv;
260 
261 #ifdef CONFIG_BATMAN_ADV_BATMAN_V
262 	/** @bat_v: per hard-interface B.A.T.M.A.N. V data */
263 	struct batadv_hard_iface_bat_v bat_v;
264 #endif
265 
266 	/**
267 	 * @neigh_list: list of unique single hop neighbors via this interface
268 	 */
269 	struct hlist_head neigh_list;
270 
271 	/** @neigh_list_lock: lock protecting neigh_list */
272 	spinlock_t neigh_list_lock;
273 };
274 
275 /**
276  * struct batadv_orig_ifinfo_bat_iv - B.A.T.M.A.N. IV private orig_ifinfo
277  *  members
278  */
279 struct batadv_orig_ifinfo_bat_iv {
280 	/**
281 	 * @bcast_own: bitfield which counts the number of our OGMs this
282 	 * orig_node rebroadcasted "back" to us  (relative to last_real_seqno)
283 	 */
284 	DECLARE_BITMAP(bcast_own, BATADV_TQ_LOCAL_WINDOW_SIZE);
285 
286 	/** @bcast_own_sum: sum of bcast_own */
287 	u8 bcast_own_sum;
288 };
289 
290 /**
291  * struct batadv_orig_ifinfo - originator info per outgoing interface
292  */
293 struct batadv_orig_ifinfo {
294 	/** @list: list node for &batadv_orig_node.ifinfo_list */
295 	struct hlist_node list;
296 
297 	/** @if_outgoing: pointer to outgoing hard-interface */
298 	struct batadv_hard_iface *if_outgoing;
299 
300 	/** @router: router that should be used to reach this originator */
301 	struct batadv_neigh_node __rcu *router;
302 
303 	/** @last_real_seqno: last and best known sequence number */
304 	u32 last_real_seqno;
305 
306 	/** @last_ttl: ttl of last received packet */
307 	u8 last_ttl;
308 
309 	/** @last_seqno_forwarded: seqno of the OGM which was forwarded last */
310 	u32 last_seqno_forwarded;
311 
312 	/** @batman_seqno_reset: time when the batman seqno window was reset */
313 	unsigned long batman_seqno_reset;
314 
315 	/** @bat_iv: B.A.T.M.A.N. IV private structure */
316 	struct batadv_orig_ifinfo_bat_iv bat_iv;
317 
318 	/** @refcount: number of contexts the object is used */
319 	struct kref refcount;
320 
321 	/** @rcu: struct used for freeing in an RCU-safe manner */
322 	struct rcu_head rcu;
323 };
324 
325 /**
326  * struct batadv_frag_table_entry - head in the fragment buffer table
327  */
328 struct batadv_frag_table_entry {
329 	/** @fragment_list: head of list with fragments */
330 	struct hlist_head fragment_list;
331 
332 	/** @lock: lock to protect the list of fragments */
333 	spinlock_t lock;
334 
335 	/** @timestamp: time (jiffy) of last received fragment */
336 	unsigned long timestamp;
337 
338 	/** @seqno: sequence number of the fragments in the list */
339 	u16 seqno;
340 
341 	/** @size: accumulated size of packets in list */
342 	size_t size;
343 
344 	/** @total_size: expected size of the assembled packet */
345 	u16 total_size;
346 };
347 
348 /**
349  * struct batadv_frag_list_entry - entry in a list of fragments
350  */
351 struct batadv_frag_list_entry {
352 	/** @list: list node information */
353 	struct hlist_node list;
354 
355 	/** @skb: fragment */
356 	struct sk_buff *skb;
357 
358 	/** @no: fragment number in the set */
359 	u8 no;
360 };
361 
362 /**
363  * struct batadv_vlan_tt - VLAN specific TT attributes
364  */
365 struct batadv_vlan_tt {
366 	/** @crc: CRC32 checksum of the entries belonging to this vlan */
367 	u32 crc;
368 
369 	/** @num_entries: number of TT entries for this VLAN */
370 	atomic_t num_entries;
371 };
372 
373 /**
374  * struct batadv_orig_node_vlan - VLAN specific data per orig_node
375  */
376 struct batadv_orig_node_vlan {
377 	/** @vid: the VLAN identifier */
378 	unsigned short vid;
379 
380 	/** @tt: VLAN specific TT attributes */
381 	struct batadv_vlan_tt tt;
382 
383 	/** @list: list node for &batadv_orig_node.vlan_list */
384 	struct hlist_node list;
385 
386 	/**
387 	 * @refcount: number of context where this object is currently in use
388 	 */
389 	struct kref refcount;
390 
391 	/** @rcu: struct used for freeing in a RCU-safe manner */
392 	struct rcu_head rcu;
393 };
394 
395 /**
396  * struct batadv_orig_bat_iv - B.A.T.M.A.N. IV private orig_node members
397  */
398 struct batadv_orig_bat_iv {
399 	/**
400 	 * @ogm_cnt_lock: lock protecting &batadv_orig_ifinfo_bat_iv.bcast_own,
401 	 * &batadv_orig_ifinfo_bat_iv.bcast_own_sum,
402 	 * &batadv_neigh_ifinfo_bat_iv.bat_iv.real_bits and
403 	 * &batadv_neigh_ifinfo_bat_iv.real_packet_count
404 	 */
405 	spinlock_t ogm_cnt_lock;
406 };
407 
408 /**
409  * struct batadv_orig_node - structure for orig_list maintaining nodes of mesh
410  */
411 struct batadv_orig_node {
412 	/** @orig: originator ethernet address */
413 	u8 orig[ETH_ALEN];
414 
415 	/** @ifinfo_list: list for routers per outgoing interface */
416 	struct hlist_head ifinfo_list;
417 
418 	/**
419 	 * @last_bonding_candidate: pointer to last ifinfo of last used router
420 	 */
421 	struct batadv_orig_ifinfo *last_bonding_candidate;
422 
423 #ifdef CONFIG_BATMAN_ADV_DAT
424 	/** @dat_addr: address of the orig node in the distributed hash */
425 	batadv_dat_addr_t dat_addr;
426 #endif
427 
428 	/** @last_seen: time when last packet from this node was received */
429 	unsigned long last_seen;
430 
431 	/**
432 	 * @bcast_seqno_reset: time when the broadcast seqno window was reset
433 	 */
434 	unsigned long bcast_seqno_reset;
435 
436 #ifdef CONFIG_BATMAN_ADV_MCAST
437 	/**
438 	 * @mcast_handler_lock: synchronizes mcast-capability and -flag changes
439 	 */
440 	spinlock_t mcast_handler_lock;
441 
442 	/** @mcast_flags: multicast flags announced by the orig node */
443 	u8 mcast_flags;
444 
445 	/**
446 	 * @mcast_want_all_unsnoopables_node: a list node for the
447 	 *  mcast.want_all_unsnoopables list
448 	 */
449 	struct hlist_node mcast_want_all_unsnoopables_node;
450 
451 	/**
452 	 * @mcast_want_all_ipv4_node: a list node for the mcast.want_all_ipv4
453 	 *  list
454 	 */
455 	struct hlist_node mcast_want_all_ipv4_node;
456 	/**
457 	 * @mcast_want_all_ipv6_node: a list node for the mcast.want_all_ipv6
458 	 *  list
459 	 */
460 	struct hlist_node mcast_want_all_ipv6_node;
461 
462 	/**
463 	 * @mcast_want_all_rtr4_node: a list node for the mcast.want_all_rtr4
464 	 *  list
465 	 */
466 	struct hlist_node mcast_want_all_rtr4_node;
467 	/**
468 	 * @mcast_want_all_rtr6_node: a list node for the mcast.want_all_rtr6
469 	 *  list
470 	 */
471 	struct hlist_node mcast_want_all_rtr6_node;
472 #endif
473 
474 	/** @capabilities: announced capabilities of this originator */
475 	unsigned long capabilities;
476 
477 	/**
478 	 * @capa_initialized: bitfield to remember whether a capability was
479 	 *  initialized
480 	 */
481 	unsigned long capa_initialized;
482 
483 	/** @last_ttvn: last seen translation table version number */
484 	u8 last_ttvn;
485 
486 	/** @tt_buff: last tt changeset this node received from the orig node */
487 	unsigned char *tt_buff;
488 
489 	/**
490 	 * @tt_buff_len: length of the last tt changeset this node received
491 	 *  from the orig node
492 	 */
493 	u16 tt_buff_len;
494 
495 	/** @tt_buff_lock: lock that protects tt_buff and tt_buff_len */
496 	spinlock_t tt_buff_lock;
497 
498 	/**
499 	 * @tt_lock: avoids concurrent read from and write to the table. Table
500 	 *  update is made up of two operations (data structure update and
501 	 *  metadata -CRC/TTVN-recalculation) and they have to be executed
502 	 *  atomically in order to avoid another thread to read the
503 	 *  table/metadata between those.
504 	 */
505 	spinlock_t tt_lock;
506 
507 	/**
508 	 * @bcast_bits: bitfield containing the info which payload broadcast
509 	 *  originated from this orig node this host already has seen (relative
510 	 *  to last_bcast_seqno)
511 	 */
512 	DECLARE_BITMAP(bcast_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
513 
514 	/**
515 	 * @last_bcast_seqno: last broadcast sequence number received by this
516 	 *  host
517 	 */
518 	u32 last_bcast_seqno;
519 
520 	/**
521 	 * @neigh_list: list of potential next hop neighbor towards this orig
522 	 *  node
523 	 */
524 	struct hlist_head neigh_list;
525 
526 	/**
527 	 * @neigh_list_lock: lock protecting neigh_list, ifinfo_list,
528 	 *  last_bonding_candidate and router
529 	 */
530 	spinlock_t neigh_list_lock;
531 
532 	/** @hash_entry: hlist node for &batadv_priv.orig_hash */
533 	struct hlist_node hash_entry;
534 
535 	/** @bat_priv: pointer to mesh_iface this orig node belongs to */
536 	struct batadv_priv *bat_priv;
537 
538 	/** @bcast_seqno_lock: lock protecting bcast_bits & last_bcast_seqno */
539 	spinlock_t bcast_seqno_lock;
540 
541 	/** @refcount: number of contexts the object is used */
542 	struct kref refcount;
543 
544 	/** @rcu: struct used for freeing in an RCU-safe manner */
545 	struct rcu_head rcu;
546 
547 	/** @fragments: array with heads for fragment chains */
548 	struct batadv_frag_table_entry fragments[BATADV_FRAG_BUFFER_COUNT];
549 
550 	/**
551 	 * @vlan_list: a list of orig_node_vlan structs, one per VLAN served by
552 	 *  the originator represented by this object
553 	 */
554 	struct hlist_head vlan_list;
555 
556 	/** @vlan_list_lock: lock protecting vlan_list */
557 	spinlock_t vlan_list_lock;
558 
559 	/** @bat_iv: B.A.T.M.A.N. IV private structure */
560 	struct batadv_orig_bat_iv bat_iv;
561 };
562 
563 /**
564  * enum batadv_orig_capabilities - orig node capabilities
565  */
566 enum batadv_orig_capabilities {
567 	/**
568 	 * @BATADV_ORIG_CAPA_HAS_DAT: orig node has distributed arp table
569 	 *  enabled
570 	 */
571 	BATADV_ORIG_CAPA_HAS_DAT,
572 
573 	/** @BATADV_ORIG_CAPA_HAS_TT: orig node has tt capability */
574 	BATADV_ORIG_CAPA_HAS_TT,
575 
576 	/**
577 	 * @BATADV_ORIG_CAPA_HAS_MCAST: orig node has some multicast capability
578 	 *  (= orig node announces a tvlv of type BATADV_TVLV_MCAST)
579 	 */
580 	BATADV_ORIG_CAPA_HAS_MCAST,
581 };
582 
583 /**
584  * struct batadv_gw_node - structure for orig nodes announcing gw capabilities
585  */
586 struct batadv_gw_node {
587 	/** @list: list node for &batadv_priv_gw.list */
588 	struct hlist_node list;
589 
590 	/** @orig_node: pointer to corresponding orig node */
591 	struct batadv_orig_node *orig_node;
592 
593 	/** @bandwidth_down: advertised uplink download bandwidth */
594 	u32 bandwidth_down;
595 
596 	/** @bandwidth_up: advertised uplink upload bandwidth */
597 	u32 bandwidth_up;
598 
599 	/** @refcount: number of contexts the object is used */
600 	struct kref refcount;
601 
602 	/** @rcu: struct used for freeing in an RCU-safe manner */
603 	struct rcu_head rcu;
604 };
605 
606 DECLARE_EWMA(throughput, 10, 8)
607 
608 /**
609  * struct batadv_hardif_neigh_node_bat_v - B.A.T.M.A.N. V private neighbor
610  *  information
611  */
612 struct batadv_hardif_neigh_node_bat_v {
613 	/** @throughput: ewma link throughput towards this neighbor */
614 	struct ewma_throughput throughput;
615 
616 	/** @elp_interval: time interval between two ELP transmissions */
617 	u32 elp_interval;
618 
619 	/** @elp_latest_seqno: latest and best known ELP sequence number */
620 	u32 elp_latest_seqno;
621 
622 	/**
623 	 * @last_unicast_tx: when the last unicast packet has been sent to this
624 	 *  neighbor
625 	 */
626 	unsigned long last_unicast_tx;
627 };
628 
629 /**
630  * struct batadv_hardif_neigh_node - unique neighbor per hard-interface
631  */
632 struct batadv_hardif_neigh_node {
633 	/** @list: list node for &batadv_hard_iface.neigh_list */
634 	struct hlist_node list;
635 
636 	/** @addr: the MAC address of the neighboring interface */
637 	u8 addr[ETH_ALEN];
638 
639 	/**
640 	 * @orig: the address of the originator this neighbor node belongs to
641 	 */
642 	u8 orig[ETH_ALEN];
643 
644 	/** @if_incoming: pointer to incoming hard-interface */
645 	struct batadv_hard_iface *if_incoming;
646 
647 	/** @last_seen: when last packet via this neighbor was received */
648 	unsigned long last_seen;
649 
650 #ifdef CONFIG_BATMAN_ADV_BATMAN_V
651 	/** @bat_v: B.A.T.M.A.N. V private data */
652 	struct batadv_hardif_neigh_node_bat_v bat_v;
653 #endif
654 
655 	/** @refcount: number of contexts the object is used */
656 	struct kref refcount;
657 
658 	/** @rcu: struct used for freeing in a RCU-safe manner */
659 	struct rcu_head rcu;
660 };
661 
662 /**
663  * struct batadv_neigh_node - structure for single hops neighbors
664  */
665 struct batadv_neigh_node {
666 	/** @list: list node for &batadv_orig_node.neigh_list */
667 	struct hlist_node list;
668 
669 #ifdef CONFIG_BATMAN_ADV_BATMAN_V
670 	/**
671 	 * @orig_node_id: pointer to corresponding orig_node. It must only be used
672 	 * to identify the node but must NEVER be dereferenced. The reference counter
673 	 * was not increased when this was assigned because it would otherwise create
674 	 * a reference cycle.
675 	 */
676 	struct batadv_orig_node *__private orig_node_id;
677 #endif
678 
679 	/** @addr: the MAC address of the neighboring interface */
680 	u8 addr[ETH_ALEN];
681 
682 	/** @ifinfo_list: list for routing metrics per outgoing interface */
683 	struct hlist_head ifinfo_list;
684 
685 	/** @ifinfo_lock: lock protecting ifinfo_list and its members */
686 	spinlock_t ifinfo_lock;
687 
688 	/** @if_incoming: pointer to incoming hard-interface */
689 	struct batadv_hard_iface *if_incoming;
690 
691 	/** @last_seen: when last packet via this neighbor was received */
692 	unsigned long last_seen;
693 
694 	/** @hardif_neigh: hardif_neigh of this neighbor */
695 	struct batadv_hardif_neigh_node *hardif_neigh;
696 
697 	/** @refcount: number of contexts the object is used */
698 	struct kref refcount;
699 
700 	/** @rcu: struct used for freeing in an RCU-safe manner */
701 	struct rcu_head rcu;
702 };
703 
704 /**
705  * struct batadv_neigh_ifinfo_bat_iv - neighbor information per outgoing
706  *  interface for B.A.T.M.A.N. IV
707  */
708 struct batadv_neigh_ifinfo_bat_iv {
709 	/** @tq_recv: ring buffer of received TQ values from this neigh node */
710 	u8 tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE];
711 
712 	/** @tq_index: ring buffer index */
713 	u8 tq_index;
714 
715 	/**
716 	 * @tq_avg: averaged tq of all tq values in the ring buffer (tq_recv)
717 	 */
718 	u8 tq_avg;
719 
720 	/**
721 	 * @real_bits: bitfield containing the number of OGMs received from this
722 	 *  neigh node (relative to orig_node->last_real_seqno)
723 	 */
724 	DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
725 
726 	/** @real_packet_count: counted result of real_bits */
727 	u8 real_packet_count;
728 };
729 
730 /**
731  * struct batadv_neigh_ifinfo_bat_v - neighbor information per outgoing
732  *  interface for B.A.T.M.A.N. V
733  */
734 struct batadv_neigh_ifinfo_bat_v {
735 	/**
736 	 * @throughput: last throughput metric received from originator via this
737 	 *  neigh
738 	 */
739 	u32 throughput;
740 
741 	/** @last_seqno: last sequence number known for this neighbor */
742 	u32 last_seqno;
743 };
744 
745 /**
746  * struct batadv_neigh_ifinfo - neighbor information per outgoing interface
747  */
748 struct batadv_neigh_ifinfo {
749 	/** @list: list node for &batadv_neigh_node.ifinfo_list */
750 	struct hlist_node list;
751 
752 	/** @if_outgoing: pointer to outgoing hard-interface */
753 	struct batadv_hard_iface *if_outgoing;
754 
755 	/** @bat_iv: B.A.T.M.A.N. IV private structure */
756 	struct batadv_neigh_ifinfo_bat_iv bat_iv;
757 
758 #ifdef CONFIG_BATMAN_ADV_BATMAN_V
759 	/** @bat_v: B.A.T.M.A.N. V private data */
760 	struct batadv_neigh_ifinfo_bat_v bat_v;
761 #endif
762 
763 	/** @last_ttl: last received ttl from this neigh node */
764 	u8 last_ttl;
765 
766 	/** @refcount: number of contexts the object is used */
767 	struct kref refcount;
768 
769 	/** @rcu: struct used for freeing in a RCU-safe manner */
770 	struct rcu_head rcu;
771 };
772 
773 #ifdef CONFIG_BATMAN_ADV_BLA
774 
775 /**
776  * struct batadv_bcast_duplist_entry - structure for LAN broadcast suppression
777  */
778 struct batadv_bcast_duplist_entry {
779 	/** @orig: mac address of orig node originating the broadcast */
780 	u8 orig[ETH_ALEN];
781 
782 	/** @crc: crc32 checksum of broadcast payload */
783 	u32 crc;
784 
785 	/** @entrytime: time when the broadcast packet was received */
786 	unsigned long entrytime;
787 };
788 #endif
789 
790 /**
791  * enum batadv_counters - indices for traffic counters
792  */
793 enum batadv_counters {
794 	/** @BATADV_CNT_TX: transmitted payload traffic packet counter */
795 	BATADV_CNT_TX,
796 
797 	/** @BATADV_CNT_TX_BYTES: transmitted payload traffic bytes counter */
798 	BATADV_CNT_TX_BYTES,
799 
800 	/**
801 	 * @BATADV_CNT_TX_DROPPED: dropped transmission payload traffic packet
802 	 *  counter
803 	 */
804 	BATADV_CNT_TX_DROPPED,
805 
806 	/** @BATADV_CNT_RX: received payload traffic packet counter */
807 	BATADV_CNT_RX,
808 
809 	/** @BATADV_CNT_RX_BYTES: received payload traffic bytes counter */
810 	BATADV_CNT_RX_BYTES,
811 
812 	/** @BATADV_CNT_FORWARD: forwarded payload traffic packet counter */
813 	BATADV_CNT_FORWARD,
814 
815 	/**
816 	 * @BATADV_CNT_FORWARD_BYTES: forwarded payload traffic bytes counter
817 	 */
818 	BATADV_CNT_FORWARD_BYTES,
819 
820 	/**
821 	 * @BATADV_CNT_MGMT_TX: transmitted routing protocol traffic packet
822 	 *  counter
823 	 */
824 	BATADV_CNT_MGMT_TX,
825 
826 	/**
827 	 * @BATADV_CNT_MGMT_TX_BYTES: transmitted routing protocol traffic bytes
828 	 *  counter
829 	 */
830 	BATADV_CNT_MGMT_TX_BYTES,
831 
832 	/**
833 	 * @BATADV_CNT_MGMT_RX: received routing protocol traffic packet counter
834 	 */
835 	BATADV_CNT_MGMT_RX,
836 
837 	/**
838 	 * @BATADV_CNT_MGMT_RX_BYTES: received routing protocol traffic bytes
839 	 *  counter
840 	 */
841 	BATADV_CNT_MGMT_RX_BYTES,
842 
843 	/** @BATADV_CNT_FRAG_TX: transmitted fragment traffic packet counter */
844 	BATADV_CNT_FRAG_TX,
845 
846 	/**
847 	 * @BATADV_CNT_FRAG_TX_BYTES: transmitted fragment traffic bytes counter
848 	 */
849 	BATADV_CNT_FRAG_TX_BYTES,
850 
851 	/** @BATADV_CNT_FRAG_RX: received fragment traffic packet counter */
852 	BATADV_CNT_FRAG_RX,
853 
854 	/**
855 	 * @BATADV_CNT_FRAG_RX_BYTES: received fragment traffic bytes counter
856 	 */
857 	BATADV_CNT_FRAG_RX_BYTES,
858 
859 	/** @BATADV_CNT_FRAG_FWD: forwarded fragment traffic packet counter */
860 	BATADV_CNT_FRAG_FWD,
861 
862 	/**
863 	 * @BATADV_CNT_FRAG_FWD_BYTES: forwarded fragment traffic bytes counter
864 	 */
865 	BATADV_CNT_FRAG_FWD_BYTES,
866 
867 	/**
868 	 * @BATADV_CNT_TT_REQUEST_TX: transmitted tt req traffic packet counter
869 	 */
870 	BATADV_CNT_TT_REQUEST_TX,
871 
872 	/** @BATADV_CNT_TT_REQUEST_RX: received tt req traffic packet counter */
873 	BATADV_CNT_TT_REQUEST_RX,
874 
875 	/**
876 	 * @BATADV_CNT_TT_RESPONSE_TX: transmitted tt resp traffic packet
877 	 *  counter
878 	 */
879 	BATADV_CNT_TT_RESPONSE_TX,
880 
881 	/**
882 	 * @BATADV_CNT_TT_RESPONSE_RX: received tt resp traffic packet counter
883 	 */
884 	BATADV_CNT_TT_RESPONSE_RX,
885 
886 	/**
887 	 * @BATADV_CNT_TT_ROAM_ADV_TX: transmitted tt roam traffic packet
888 	 *  counter
889 	 */
890 	BATADV_CNT_TT_ROAM_ADV_TX,
891 
892 	/**
893 	 * @BATADV_CNT_TT_ROAM_ADV_RX: received tt roam traffic packet counter
894 	 */
895 	BATADV_CNT_TT_ROAM_ADV_RX,
896 
897 #ifdef CONFIG_BATMAN_ADV_MCAST
898 	/**
899 	 * @BATADV_CNT_MCAST_TX: transmitted batman-adv multicast packets
900 	 *  counter
901 	 */
902 	BATADV_CNT_MCAST_TX,
903 
904 	/**
905 	 * @BATADV_CNT_MCAST_TX_BYTES: transmitted batman-adv multicast packets
906 	 *  bytes counter
907 	 */
908 	BATADV_CNT_MCAST_TX_BYTES,
909 
910 	/**
911 	 * @BATADV_CNT_MCAST_TX_LOCAL: counter for multicast packets which
912 	 *  were locally encapsulated and transmitted as batman-adv multicast
913 	 *  packets
914 	 */
915 	BATADV_CNT_MCAST_TX_LOCAL,
916 
917 	/**
918 	 * @BATADV_CNT_MCAST_TX_LOCAL_BYTES: bytes counter for multicast packets
919 	 *  which were locally encapsulated and transmitted as batman-adv
920 	 *  multicast packets
921 	 */
922 	BATADV_CNT_MCAST_TX_LOCAL_BYTES,
923 
924 	/**
925 	 * @BATADV_CNT_MCAST_RX: received batman-adv multicast packet counter
926 	 */
927 	BATADV_CNT_MCAST_RX,
928 
929 	/**
930 	 * @BATADV_CNT_MCAST_RX_BYTES: received batman-adv multicast packet
931 	 *  bytes counter
932 	 */
933 	BATADV_CNT_MCAST_RX_BYTES,
934 
935 	/**
936 	 * @BATADV_CNT_MCAST_RX_LOCAL: counter for received batman-adv multicast
937 	 *  packets which were forwarded to the local mesh interface
938 	 */
939 	BATADV_CNT_MCAST_RX_LOCAL,
940 
941 	/**
942 	 * @BATADV_CNT_MCAST_RX_LOCAL_BYTES: bytes counter for received
943 	 *  batman-adv multicast packets which were forwarded to the local mesh
944 	 *  interface
945 	 */
946 	BATADV_CNT_MCAST_RX_LOCAL_BYTES,
947 
948 	/**
949 	 * @BATADV_CNT_MCAST_FWD: counter for received batman-adv multicast
950 	 *  packets which were forwarded to other, neighboring nodes
951 	 */
952 	BATADV_CNT_MCAST_FWD,
953 
954 	/**
955 	 * @BATADV_CNT_MCAST_FWD_BYTES: bytes counter for received batman-adv
956 	 *  multicast packets which were forwarded to other, neighboring nodes
957 	 */
958 	BATADV_CNT_MCAST_FWD_BYTES,
959 #endif
960 
961 #ifdef CONFIG_BATMAN_ADV_DAT
962 	/**
963 	 * @BATADV_CNT_DAT_GET_TX: transmitted dht GET traffic packet counter
964 	 */
965 	BATADV_CNT_DAT_GET_TX,
966 
967 	/** @BATADV_CNT_DAT_GET_RX: received dht GET traffic packet counter */
968 	BATADV_CNT_DAT_GET_RX,
969 
970 	/**
971 	 * @BATADV_CNT_DAT_PUT_TX: transmitted dht PUT traffic packet counter
972 	 */
973 	BATADV_CNT_DAT_PUT_TX,
974 
975 	/** @BATADV_CNT_DAT_PUT_RX: received dht PUT traffic packet counter */
976 	BATADV_CNT_DAT_PUT_RX,
977 
978 	/**
979 	 * @BATADV_CNT_DAT_CACHED_REPLY_TX: transmitted dat cache reply traffic
980 	 *  packet counter
981 	 */
982 	BATADV_CNT_DAT_CACHED_REPLY_TX,
983 #endif
984 
985 	/** @BATADV_CNT_NUM: number of traffic counters */
986 	BATADV_CNT_NUM,
987 };
988 
989 /**
990  * struct batadv_priv_tt - per mesh interface translation table data
991  */
992 struct batadv_priv_tt {
993 	/** @vn: translation table version number */
994 	atomic_t vn;
995 
996 	/**
997 	 * @ogm_append_cnt: counter of number of OGMs containing the local tt
998 	 *  diff
999 	 */
1000 	atomic_t ogm_append_cnt;
1001 
1002 	/** @local_changes: changes registered in an originator interval */
1003 	size_t local_changes;
1004 
1005 	/**
1006 	 * @changes_list: tracks tt local changes within an originator interval
1007 	 */
1008 	struct list_head changes_list;
1009 
1010 	/** @local_hash: local translation table hash table */
1011 	struct batadv_hashtable *local_hash;
1012 
1013 	/** @global_hash: global translation table hash table */
1014 	struct batadv_hashtable *global_hash;
1015 
1016 	/** @req_list: list of pending & unanswered tt_requests */
1017 	struct hlist_head req_list;
1018 
1019 	/**
1020 	 * @roam_list: list of the last roaming events of each client limiting
1021 	 *  the number of roaming events to avoid route flapping
1022 	 */
1023 	struct list_head roam_list;
1024 
1025 	/** @changes_list_lock: lock protecting changes_list & local_changes */
1026 	spinlock_t changes_list_lock;
1027 
1028 	/** @req_list_lock: lock protecting req_list */
1029 	spinlock_t req_list_lock;
1030 
1031 	/** @roam_list_lock: lock protecting roam_list */
1032 	spinlock_t roam_list_lock;
1033 
1034 	/** @last_changeset: last tt changeset this host has generated */
1035 	unsigned char *last_changeset;
1036 
1037 	/**
1038 	 * @last_changeset_len: length of last tt changeset this host has
1039 	 *  generated
1040 	 */
1041 	u16 last_changeset_len;
1042 
1043 	/**
1044 	 * @last_changeset_lock: lock protecting last_changeset &
1045 	 *  last_changeset_len
1046 	 */
1047 	spinlock_t last_changeset_lock;
1048 
1049 	/**
1050 	 * @commit_lock: prevents from executing a local TT commit while reading
1051 	 *  the local table. The local TT commit is made up of two operations
1052 	 *  (data structure update and metadata -CRC/TTVN- recalculation) and
1053 	 *  they have to be executed atomically in order to avoid another thread
1054 	 *  to read the table/metadata between those.
1055 	 */
1056 	spinlock_t commit_lock;
1057 
1058 	/** @work: work queue callback item for translation table purging */
1059 	struct delayed_work work;
1060 };
1061 
1062 #ifdef CONFIG_BATMAN_ADV_BLA
1063 
1064 /**
1065  * struct batadv_priv_bla - per mesh interface bridge loop avoidance data
1066  */
1067 struct batadv_priv_bla {
1068 	/** @num_requests: number of bla requests in flight */
1069 	atomic_t num_requests;
1070 
1071 	/**
1072 	 * @num_requests_lock: locks update num_requests +
1073 	 * batadv_backbone_gw::state + batadv_backbone_gw::wait_periods update
1074 	 */
1075 	spinlock_t num_requests_lock;
1076 
1077 	/**
1078 	 * @claim_hash: hash table containing mesh nodes this host has claimed
1079 	 */
1080 	struct batadv_hashtable *claim_hash;
1081 
1082 	/**
1083 	 * @backbone_hash: hash table containing all detected backbone gateways
1084 	 */
1085 	struct batadv_hashtable *backbone_hash;
1086 
1087 	/** @loopdetect_addr: MAC address used for own loopdetection frames */
1088 	u8 loopdetect_addr[ETH_ALEN];
1089 
1090 	/**
1091 	 * @loopdetect_lasttime: time when the loopdetection frames were sent
1092 	 */
1093 	unsigned long loopdetect_lasttime;
1094 
1095 	/**
1096 	 * @loopdetect_next: how many periods to wait for the next loopdetect
1097 	 *  process
1098 	 */
1099 	atomic_t loopdetect_next;
1100 
1101 	/**
1102 	 * @bcast_duplist: recently received broadcast packets array (for
1103 	 *  broadcast duplicate suppression)
1104 	 */
1105 	struct batadv_bcast_duplist_entry bcast_duplist[BATADV_DUPLIST_SIZE];
1106 
1107 	/**
1108 	 * @bcast_duplist_curr: index of last broadcast packet added to
1109 	 *  bcast_duplist
1110 	 */
1111 	int bcast_duplist_curr;
1112 
1113 	/**
1114 	 * @bcast_duplist_lock: lock protecting bcast_duplist &
1115 	 *  bcast_duplist_curr
1116 	 */
1117 	spinlock_t bcast_duplist_lock;
1118 
1119 	/** @claim_dest: local claim data (e.g. claim group) */
1120 	struct batadv_bla_claim_dst claim_dest;
1121 
1122 	/** @work: work queue callback item for cleanups & bla announcements */
1123 	struct delayed_work work;
1124 };
1125 #endif
1126 
1127 /**
1128  * struct batadv_priv_gw - per mesh interface gateway data
1129  */
1130 struct batadv_priv_gw {
1131 	/** @gateway_list: list of available gateway nodes */
1132 	struct hlist_head gateway_list;
1133 
1134 	/** @list_lock: lock protecting gateway_list, curr_gw, generation */
1135 	spinlock_t list_lock;
1136 
1137 	/** @curr_gw: pointer to currently selected gateway node */
1138 	struct batadv_gw_node __rcu *curr_gw;
1139 
1140 	/** @generation: current (generation) sequence number */
1141 	unsigned int generation;
1142 
1143 	/**
1144 	 * @mode: gateway operation: off, client or server (see batadv_gw_modes)
1145 	 */
1146 	enum batadv_gw_modes mode;
1147 
1148 	/** @sel_class: gateway selection class (applies if gw_mode client) */
1149 	u32 sel_class;
1150 
1151 	/**
1152 	 * @bandwidth_down: advertised uplink download bandwidth (if gw_mode
1153 	 *  server)
1154 	 */
1155 	u32 bandwidth_down;
1156 
1157 	/**
1158 	 * @bandwidth_up: advertised uplink upload bandwidth (if gw_mode server)
1159 	 */
1160 	u32 bandwidth_up;
1161 
1162 	/** @reselect: bool indicating a gateway re-selection is in progress */
1163 	atomic_t reselect;
1164 };
1165 
1166 /**
1167  * struct batadv_priv_tvlv - per mesh interface tvlv data
1168  */
1169 struct batadv_priv_tvlv {
1170 	/**
1171 	 * @container_list: list of registered tvlv containers to be sent with
1172 	 *  each OGM
1173 	 */
1174 	struct hlist_head container_list;
1175 
1176 	/** @handler_list: list of the various tvlv content handlers */
1177 	struct hlist_head handler_list;
1178 
1179 	/** @container_list_lock: protects tvlv container list access */
1180 	spinlock_t container_list_lock;
1181 
1182 	/** @handler_list_lock: protects handler list access */
1183 	spinlock_t handler_list_lock;
1184 };
1185 
1186 #ifdef CONFIG_BATMAN_ADV_DAT
1187 
1188 /**
1189  * struct batadv_priv_dat - per mesh interface DAT private data
1190  */
1191 struct batadv_priv_dat {
1192 	/** @addr: node DAT address */
1193 	batadv_dat_addr_t addr;
1194 
1195 	/** @hash: hashtable representing the local ARP cache */
1196 	struct batadv_hashtable *hash;
1197 
1198 	/** @work: work queue callback item for cache purging */
1199 	struct delayed_work work;
1200 };
1201 #endif
1202 
1203 #ifdef CONFIG_BATMAN_ADV_MCAST
1204 /**
1205  * struct batadv_mcast_querier_state - IGMP/MLD querier state when bridged
1206  */
1207 struct batadv_mcast_querier_state {
1208 	/** @exists: whether a querier exists in the mesh */
1209 	unsigned char exists:1;
1210 
1211 	/**
1212 	 * @shadowing: if a querier exists, whether it is potentially shadowing
1213 	 *  multicast listeners (i.e. querier is behind our own bridge segment)
1214 	 */
1215 	unsigned char shadowing:1;
1216 };
1217 
1218 /**
1219  * struct batadv_mcast_mla_flags - flags for the querier, bridge and tvlv state
1220  */
1221 struct batadv_mcast_mla_flags {
1222 	/** @querier_ipv4: the current state of an IGMP querier in the mesh */
1223 	struct batadv_mcast_querier_state querier_ipv4;
1224 
1225 	/** @querier_ipv6: the current state of an MLD querier in the mesh */
1226 	struct batadv_mcast_querier_state querier_ipv6;
1227 
1228 	/** @enabled: whether the multicast tvlv is currently enabled */
1229 	unsigned char enabled:1;
1230 
1231 	/** @bridged: whether the mesh interface has a bridge on top */
1232 	unsigned char bridged:1;
1233 
1234 	/** @tvlv_flags: the flags we have last sent in our mcast tvlv */
1235 	u8 tvlv_flags;
1236 };
1237 
1238 /**
1239  * struct batadv_priv_mcast - per mesh interface mcast data
1240  */
1241 struct batadv_priv_mcast {
1242 	/**
1243 	 * @mla_list: list of multicast addresses we are currently announcing
1244 	 *  via TT
1245 	 */
1246 	struct hlist_head mla_list; /* see __batadv_mcast_mla_update() */
1247 
1248 	/**
1249 	 * @want_all_unsnoopables_list: a list of orig_nodes wanting all
1250 	 *  unsnoopable multicast traffic
1251 	 */
1252 	struct hlist_head want_all_unsnoopables_list;
1253 
1254 	/**
1255 	 * @want_all_ipv4_list: a list of orig_nodes wanting all IPv4 multicast
1256 	 *  traffic
1257 	 */
1258 	struct hlist_head want_all_ipv4_list;
1259 
1260 	/**
1261 	 * @want_all_ipv6_list: a list of orig_nodes wanting all IPv6 multicast
1262 	 *  traffic
1263 	 */
1264 	struct hlist_head want_all_ipv6_list;
1265 
1266 	/**
1267 	 * @want_all_rtr4_list: a list of orig_nodes wanting all routable IPv4
1268 	 *  multicast traffic
1269 	 */
1270 	struct hlist_head want_all_rtr4_list;
1271 
1272 	/**
1273 	 * @want_all_rtr6_list: a list of orig_nodes wanting all routable IPv6
1274 	 *  multicast traffic
1275 	 */
1276 	struct hlist_head want_all_rtr6_list;
1277 
1278 	/**
1279 	 * @mla_flags: flags for the querier, bridge and tvlv state
1280 	 */
1281 	struct batadv_mcast_mla_flags mla_flags;
1282 
1283 	/**
1284 	 * @mla_lock: a lock protecting mla_list and mla_flags
1285 	 */
1286 	spinlock_t mla_lock;
1287 
1288 	/**
1289 	 * @num_want_all_unsnoopables: number of nodes wanting unsnoopable IP
1290 	 *  traffic
1291 	 */
1292 	atomic_t num_want_all_unsnoopables;
1293 
1294 	/** @num_want_all_ipv4: counter for items in want_all_ipv4_list */
1295 	atomic_t num_want_all_ipv4;
1296 
1297 	/** @num_want_all_ipv6: counter for items in want_all_ipv6_list */
1298 	atomic_t num_want_all_ipv6;
1299 
1300 	/** @num_want_all_rtr4: counter for items in want_all_rtr4_list */
1301 	atomic_t num_want_all_rtr4;
1302 
1303 	/** @num_want_all_rtr6: counter for items in want_all_rtr6_list */
1304 	atomic_t num_want_all_rtr6;
1305 
1306 	/**
1307 	 * @num_no_mc_ptype_capa: counter for number of nodes without the
1308 	 *  BATADV_MCAST_HAVE_MC_PTYPE_CAPA flag
1309 	 */
1310 	atomic_t num_no_mc_ptype_capa;
1311 
1312 	/**
1313 	 * @want_lists_lock: lock for protecting modifications to mcasts
1314 	 *  want_all_{unsnoopables,ipv4,ipv6}_list (traversals are rcu-locked)
1315 	 */
1316 	spinlock_t want_lists_lock;
1317 
1318 	/** @work: work queue callback item for multicast TT and TVLV updates */
1319 	struct delayed_work work;
1320 };
1321 #endif
1322 
1323 /**
1324  * struct batadv_tp_unacked - unacked packet meta-information
1325  *
1326  * This struct is supposed to represent a buffer unacked packet. However, since
1327  * the purpose of the TP meter is to count the traffic only, there is no need to
1328  * store the entire sk_buff, the starting offset and the length are enough
1329  */
1330 struct batadv_tp_unacked {
1331 	/** @seqno: seqno of the unacked packet */
1332 	u32 seqno;
1333 
1334 	/** @len: length of the packet */
1335 	u32 len;
1336 
1337 	/** @list: list node for &batadv_tp_receiver.unacked_list */
1338 	struct list_head list;
1339 };
1340 
1341 /**
1342  * struct batadv_tp_vars_common - common tp meter private variables per session
1343  */
1344 struct batadv_tp_vars_common {
1345 	/** @list: list node for &bat_priv.tp_sender_list/&bat_priv.tp_receiver_list */
1346 	struct hlist_node list;
1347 
1348 	/** @timer: timer for ack (receiver) and retry (sender) */
1349 	struct timer_list timer;
1350 
1351 	/** @bat_priv: pointer to the mesh object */
1352 	struct batadv_priv *bat_priv;
1353 
1354 	/** @other_end: mac address of remote */
1355 	u8 other_end[ETH_ALEN];
1356 
1357 	/** @session: TP session identifier */
1358 	u8 session[2];
1359 
1360 	/** @refcount: number of context where the object is used */
1361 	struct kref refcount;
1362 
1363 	/** @rcu: struct used for freeing in an RCU-safe manner */
1364 	struct rcu_head rcu;
1365 };
1366 
1367 /**
1368  * struct batadv_tp_sender_cc - congestion control variables
1369  */
1370 struct batadv_tp_sender_cc {
1371 	/** @fast_recovery: true if in Fast Recovery mode */
1372 	bool fast_recovery:1;
1373 
1374 	/** @dup_acks: duplicate ACKs counter */
1375 	u8 dup_acks;
1376 
1377 	/** @dec_cwnd: decimal part of the cwnd used during linear growth */
1378 	u16 dec_cwnd;
1379 
1380 	/** @cwnd: current size of the congestion window */
1381 	u32 cwnd;
1382 
1383 	/**
1384 	 * @ss_threshold: Slow Start threshold. Once cwnd exceeds this value the
1385 	 *  connection switches to the Congestion Avoidance state
1386 	 */
1387 	u32 ss_threshold;
1388 
1389 	/** @last_acked: last acked byte */
1390 	u32 last_acked;
1391 
1392 	/** @last_sent: last sent byte, not yet acked */
1393 	u32 last_sent;
1394 
1395 	/** @recover: last sent seqno when entering Fast Recovery */
1396 	u32 recover;
1397 
1398 	/** @rto: sender timeout */
1399 	u32 rto;
1400 
1401 	/** @srtt: smoothed RTT scaled by 2^3 */
1402 	u32 srtt;
1403 
1404 	/** @rttvar: RTT variation scaled by 2^2 */
1405 	u32 rttvar;
1406 };
1407 
1408 /**
1409  * struct batadv_tp_sender - sender tp meter private variables per session
1410  */
1411 struct batadv_tp_sender {
1412 	/** @common: common batadv_tp_vars_common (must be first member) */
1413 	struct batadv_tp_vars_common common;
1414 
1415 	/** @start_time: start time in jiffies */
1416 	unsigned long start_time;
1417 
1418 	/**
1419 	 * @send_result: 0 when sending is ongoing and otherwise
1420 	 * enum batadv_tp_meter_reason
1421 	 */
1422 	atomic_t send_result;
1423 
1424 	/** @finish_work: work item for the finishing procedure */
1425 	struct delayed_work finish_work;
1426 
1427 	/** @finished: completion signaled when a sender thread exits */
1428 	struct completion finished;
1429 
1430 	/** @test_length: test length in milliseconds */
1431 	u32 test_length;
1432 
1433 	/** @icmp_uid: local ICMP "socket" index */
1434 	u8 icmp_uid;
1435 
1436 	/** @cc: congestion control variables */
1437 	struct batadv_tp_sender_cc cc;
1438 
1439 	/** @cc_lock: lock to protect @cc */
1440 	spinlock_t cc_lock;
1441 
1442 	/** @tot_sent: amount of data sent/ACKed so far */
1443 	atomic64_t tot_sent;
1444 
1445 	/**
1446 	 * @more_bytes: waiting queue anchor when waiting for more ack/retry
1447 	 *  timeout
1448 	 */
1449 	wait_queue_head_t more_bytes;
1450 
1451 	/** @prerandom_offset: offset inside the prerandom buffer */
1452 	u32 prerandom_offset;
1453 
1454 	/** @prerandom_lock: spinlock protecting access to prerandom_offset */
1455 	spinlock_t prerandom_lock;
1456 };
1457 
1458 /**
1459  * struct batadv_tp_receiver - receiver tp meter private variables per session
1460  */
1461 struct batadv_tp_receiver {
1462 	/** @common: common batadv_tp_vars_common (must be first member) */
1463 	struct batadv_tp_vars_common common;
1464 
1465 	/** @receiving: receiving binary semaphore: 1 if receiving, 0 is not */
1466 	atomic_t receiving;
1467 
1468 	/** @last_recv: last in-order received packet */
1469 	u32 last_recv;
1470 
1471 	/** @last_recv_time: time (jiffies) a msg was received */
1472 	unsigned long last_recv_time;
1473 
1474 	/** @unacked_list: list of unacked packets (meta-info only) */
1475 	struct list_head unacked_list;
1476 
1477 	/** @ack_seqno_lock: protect unacked_list + &batadv_tp_receiver.last_recv */
1478 	spinlock_t ack_seqno_lock;
1479 
1480 	/** @unacked_count: number of unacked entries */
1481 	size_t unacked_count;
1482 };
1483 
1484 /**
1485  * struct batadv_meshif_vlan - per VLAN attributes set
1486  */
1487 struct batadv_meshif_vlan {
1488 	/** @bat_priv: pointer to the mesh object */
1489 	struct batadv_priv *bat_priv;
1490 
1491 	/** @vid: VLAN identifier */
1492 	unsigned short vid;
1493 
1494 	/** @ap_isolation: AP isolation state */
1495 	u8 ap_isolation;		/* boolean */
1496 
1497 	/** @tt: TT private attributes (VLAN specific) */
1498 	struct batadv_vlan_tt tt;
1499 
1500 	/** @list: list node for &bat_priv.meshif_vlan_list */
1501 	struct hlist_node list;
1502 
1503 	/**
1504 	 * @refcount: number of context where this object is currently in use
1505 	 */
1506 	struct kref refcount;
1507 
1508 	/** @rcu: struct used for freeing in a RCU-safe manner */
1509 	struct rcu_head rcu;
1510 };
1511 
1512 /**
1513  * struct batadv_priv_bat_v - B.A.T.M.A.N. V per mesh-interface private data
1514  */
1515 struct batadv_priv_bat_v {
1516 	/** @ogm_buff: buffer holding the OGM packet */
1517 	struct batadv_ogm_buf ogm_buff;
1518 
1519 	/** @ogm_seqno: OGM sequence number - used to identify each OGM */
1520 	atomic_t ogm_seqno;
1521 
1522 	/** @ogm_buff_mutex: lock protecting ogm_buff */
1523 	struct mutex ogm_buff_mutex;
1524 
1525 	/** @ogm_wq: workqueue used to schedule OGM transmissions */
1526 	struct delayed_work ogm_wq;
1527 };
1528 
1529 /**
1530  * struct batadv_priv - per mesh interface data
1531  */
1532 struct batadv_priv {
1533 	/**
1534 	 * @mesh_state: current status of the mesh
1535 	 *  (inactive/active/deactivating)
1536 	 */
1537 	enum batadv_mesh_state mesh_state;
1538 
1539 	/** @mesh_iface: net device which holds this struct as private data */
1540 	struct net_device *mesh_iface;
1541 
1542 	/**
1543 	 * @mtu_set_by_user: MTU was set once by user
1544 	 * protected by rtnl_lock
1545 	 */
1546 	int mtu_set_by_user;
1547 
1548 	/**
1549 	 * @bat_counters: mesh internal traffic statistic counters (see
1550 	 *  batadv_counters)
1551 	 */
1552 	u64 __percpu *bat_counters; /* Per cpu counters */
1553 
1554 	/**
1555 	 * @aggregated_ogms: bool indicating whether OGM aggregation is enabled
1556 	 */
1557 	u8 aggregated_ogms;
1558 
1559 	/** @bonding: bool indicating whether traffic bonding is enabled */
1560 	u8 bonding;
1561 
1562 	/**
1563 	 * @fragmentation: bool indicating whether traffic fragmentation is
1564 	 *  enabled
1565 	 */
1566 	u8 fragmentation;
1567 
1568 #ifdef CONFIG_BATMAN_ADV_BLA
1569 	/**
1570 	 * @bridge_loop_avoidance: bool indicating whether bridge loop
1571 	 *  avoidance is enabled
1572 	 */
1573 	u8 bridge_loop_avoidance;
1574 #endif
1575 
1576 #ifdef CONFIG_BATMAN_ADV_DAT
1577 	/**
1578 	 * @distributed_arp_table: bool indicating whether distributed ARP table
1579 	 *  is enabled
1580 	 */
1581 	u8 distributed_arp_table;
1582 #endif
1583 
1584 #ifdef CONFIG_BATMAN_ADV_MCAST
1585 	/**
1586 	 * @multicast_mode: Enable or disable multicast optimizations on this
1587 	 *  node's sender/originating side
1588 	 */
1589 	u8 multicast_mode;
1590 
1591 	/**
1592 	 * @multicast_fanout: Maximum number of packet copies to generate for a
1593 	 *  multicast-to-unicast conversion
1594 	 */
1595 	u32 multicast_fanout;
1596 #endif
1597 
1598 	/**
1599 	 * @packet_size_max: max packet size that can be transmitted via
1600 	 *  multiple fragmented skbs or a single frame if fragmentation is
1601 	 *  disabled
1602 	 */
1603 	int packet_size_max;
1604 
1605 	/**
1606 	 * @frag_seqno: incremental counter to identify chains of egress
1607 	 *  fragments
1608 	 */
1609 	atomic_t frag_seqno;
1610 
1611 	/** @orig_interval: OGM broadcast interval in milliseconds */
1612 	u32 orig_interval;
1613 
1614 	/**
1615 	 * @hop_penalty: penalty which will be applied to an OGM's tq-field on
1616 	 *  every hop
1617 	 */
1618 	u8 hop_penalty;
1619 
1620 #ifdef CONFIG_BATMAN_ADV_DEBUG
1621 	/** @log_level: configured log level (see batadv_dbg_level) */
1622 	u32 log_level;
1623 #endif
1624 
1625 	/**
1626 	 * @isolation_mark: the skb->mark value used to match packets for AP
1627 	 *  isolation
1628 	 */
1629 	u32 isolation_mark;
1630 
1631 	/**
1632 	 * @isolation_mark_mask: bitmask identifying the bits in skb->mark to be
1633 	 *  used for the isolation mark
1634 	 */
1635 	u32 isolation_mark_mask;
1636 
1637 	/** @bcast_seqno: last sent broadcast packet sequence number */
1638 	atomic_t bcast_seqno;
1639 
1640 	/**
1641 	 * @bcast_queue_left: number of remaining buffered broadcast packet
1642 	 *  slots
1643 	 */
1644 	atomic_t bcast_queue_left;
1645 
1646 	/** @batman_queue_left: number of remaining OGM packet slots */
1647 	atomic_t batman_queue_left;
1648 
1649 	/** @forw_bat_list: list of aggregated OGMs that will be forwarded */
1650 	struct hlist_head forw_bat_list;
1651 
1652 	/**
1653 	 * @forw_bcast_list: list of broadcast packets that will be
1654 	 *  rebroadcasted
1655 	 */
1656 	struct hlist_head forw_bcast_list;
1657 
1658 	/** @tp_sender_list: list of tp sender sessions */
1659 	struct hlist_head tp_sender_list;
1660 
1661 	/** @tp_receiver_list: list of tp receiver sessions */
1662 	struct hlist_head tp_receiver_list;
1663 
1664 	/** @orig_hash: hash table containing mesh participants (orig nodes) */
1665 	struct batadv_hashtable *orig_hash;
1666 
1667 	/** @forw_bat_list_lock: lock protecting forw_bat_list */
1668 	spinlock_t forw_bat_list_lock;
1669 
1670 	/** @forw_bcast_list_lock: lock protecting forw_bcast_list */
1671 	spinlock_t forw_bcast_list_lock;
1672 
1673 	/** @tp_list_lock: spinlock protecting @tp_sender_list + @tp_receiver_list */
1674 	spinlock_t tp_list_lock;
1675 
1676 	/** @tp_num: number of currently active tp sessions */
1677 	atomic_t tp_num;
1678 
1679 	/** @hardif_generation: generation counter added to netlink hardif dumps */
1680 	unsigned int hardif_generation;
1681 
1682 	/** @orig_work: work queue callback item for orig node purging */
1683 	struct delayed_work orig_work;
1684 
1685 	/**
1686 	 * @primary_if: one of the hard-interfaces assigned to this mesh
1687 	 *  interface becomes the primary interface
1688 	 */
1689 	struct batadv_hard_iface __rcu *primary_if;  /* rcu protected pointer */
1690 
1691 	/** @algo_ops: routing algorithm used by this mesh interface */
1692 	struct batadv_algo_ops *algo_ops;
1693 
1694 	/**
1695 	 * @meshif_vlan_list: a list of meshif_vlan structs, one per VLAN
1696 	 *  created on top of the mesh interface represented by this object
1697 	 */
1698 	struct hlist_head meshif_vlan_list;
1699 
1700 	/** @meshif_vlan_list_lock: lock protecting meshif_vlan_list */
1701 	spinlock_t meshif_vlan_list_lock;
1702 
1703 #ifdef CONFIG_BATMAN_ADV_BLA
1704 	/** @bla: bridge loop avoidance data */
1705 	struct batadv_priv_bla bla;
1706 #endif
1707 
1708 	/** @gw: gateway data */
1709 	struct batadv_priv_gw gw;
1710 
1711 	/** @tt: translation table data */
1712 	struct batadv_priv_tt tt;
1713 
1714 	/** @tvlv: type-version-length-value data */
1715 	struct batadv_priv_tvlv tvlv;
1716 
1717 #ifdef CONFIG_BATMAN_ADV_DAT
1718 	/** @dat: distributed arp table data */
1719 	struct batadv_priv_dat dat;
1720 #endif
1721 
1722 #ifdef CONFIG_BATMAN_ADV_MCAST
1723 	/** @mcast: multicast data */
1724 	struct batadv_priv_mcast mcast;
1725 #endif
1726 
1727 #ifdef CONFIG_BATMAN_ADV_BATMAN_V
1728 	/** @bat_v: B.A.T.M.A.N. V per mesh-interface private data */
1729 	struct batadv_priv_bat_v bat_v;
1730 #endif
1731 };
1732 
1733 #ifdef CONFIG_BATMAN_ADV_BLA
1734 
1735 /**
1736  * enum batadv_bla_backbone_gw_state - state of a bridge loop avoidance
1737  *  backbone gateway
1738  */
1739 enum batadv_bla_backbone_gw_state {
1740 	/**
1741 	 * @BATADV_BLA_BACKBONE_GW_STOPPED: backbone gw is being removed
1742 	 * and it must no longer work on requests
1743 	 */
1744 	BATADV_BLA_BACKBONE_GW_STOPPED,
1745 
1746 	/**
1747 	 * @BATADV_BLA_BACKBONE_GW_UNSYNCED: backbone was detected out
1748 	 * of sync and a request was sent. No traffic is forwarded until the
1749 	 * situation is resolved
1750 	 */
1751 	BATADV_BLA_BACKBONE_GW_UNSYNCED,
1752 
1753 	/**
1754 	 * @BATADV_BLA_BACKBONE_GW_SYNCED: backbone is considered to be in
1755 	 * sync. traffic can be forwarded
1756 	 */
1757 	BATADV_BLA_BACKBONE_GW_SYNCED,
1758 };
1759 
1760 /**
1761  * struct batadv_bla_backbone_gw - batman-adv gateway bridged into the LAN
1762  */
1763 struct batadv_bla_backbone_gw {
1764 	/**
1765 	 * @orig: originator address of backbone node (mac address of primary
1766 	 *  iface)
1767 	 */
1768 	u8 orig[ETH_ALEN];
1769 
1770 	/** @vid: vlan id this gateway was detected on */
1771 	unsigned short vid;
1772 
1773 	/** @hash_entry: hlist node for &batadv_priv_bla.backbone_hash */
1774 	struct hlist_node hash_entry;
1775 
1776 	/** @bat_priv: pointer to mesh_iface this backbone gateway belongs to */
1777 	struct batadv_priv *bat_priv;
1778 
1779 	/** @lasttime: last time we heard of this backbone gw */
1780 	unsigned long lasttime;
1781 
1782 	/**
1783 	 * @wait_periods: grace time for bridge forward delays and bla group
1784 	 *  forming at bootup phase - no bcast traffic is formwared until it has
1785 	 *  elapsed. Must only be access with num_requests_lock.
1786 	 */
1787 	u8 wait_periods;
1788 
1789 	/** @state: sync state. Must only be access with num_requests_lock. */
1790 	enum batadv_bla_backbone_gw_state state;
1791 
1792 	/** @crc: crc16 checksum over all claims */
1793 	u16 crc;
1794 
1795 	/** @crc_lock: lock protecting crc */
1796 	spinlock_t crc_lock;
1797 
1798 	/** @report_work: work struct for reporting detected loops */
1799 	struct work_struct report_work;
1800 
1801 	/** @refcount: number of contexts the object is used */
1802 	struct kref refcount;
1803 
1804 	/** @rcu: struct used for freeing in an RCU-safe manner */
1805 	struct rcu_head rcu;
1806 };
1807 
1808 /**
1809  * struct batadv_bla_claim - claimed non-mesh client structure
1810  */
1811 struct batadv_bla_claim {
1812 	/** @addr: mac address of claimed non-mesh client */
1813 	u8 addr[ETH_ALEN];
1814 
1815 	/** @vid: vlan id this client was detected on */
1816 	unsigned short vid;
1817 
1818 	/** @backbone_gw: pointer to backbone gw claiming this client */
1819 	struct batadv_bla_backbone_gw *backbone_gw;
1820 
1821 	/** @backbone_lock: lock protecting backbone_gw pointer */
1822 	spinlock_t backbone_lock;
1823 
1824 	/** @lasttime: last time we heard of claim (locals only) */
1825 	unsigned long lasttime;
1826 
1827 	/** @hash_entry: hlist node for &batadv_priv_bla.claim_hash */
1828 	struct hlist_node hash_entry;
1829 
1830 	/** @rcu: struct used for freeing in an RCU-safe manner */
1831 	struct rcu_head rcu;
1832 
1833 	/** @refcount: number of contexts the object is used */
1834 	struct kref refcount;
1835 };
1836 #endif
1837 
1838 /**
1839  * struct batadv_tt_common_entry - tt local & tt global common data
1840  */
1841 struct batadv_tt_common_entry {
1842 	/** @addr: mac address of non-mesh client */
1843 	u8 addr[ETH_ALEN];
1844 
1845 	/** @vid: VLAN identifier */
1846 	unsigned short vid;
1847 
1848 	/**
1849 	 * @hash_entry: hlist node for &batadv_priv_tt.local_hash or for
1850 	 *  &batadv_priv_tt.global_hash
1851 	 */
1852 	struct hlist_node hash_entry;
1853 
1854 	/** @flags: various state handling flags (see batadv_tt_client_flags) */
1855 	u16 flags;
1856 
1857 	/** @added_at: timestamp used for purging stale tt common entries */
1858 	unsigned long added_at;
1859 
1860 	/** @refcount: number of contexts the object is used */
1861 	struct kref refcount;
1862 
1863 	/** @rcu: struct used for freeing in an RCU-safe manner */
1864 	struct rcu_head rcu;
1865 };
1866 
1867 /**
1868  * struct batadv_tt_local_entry - translation table local entry data
1869  */
1870 struct batadv_tt_local_entry {
1871 	/** @common: general translation table data */
1872 	struct batadv_tt_common_entry common;
1873 
1874 	/** @last_seen: timestamp used for purging stale tt local entries */
1875 	unsigned long last_seen;
1876 
1877 	/** @vlan: mesh-interface vlan of the entry */
1878 	struct batadv_meshif_vlan *vlan;
1879 };
1880 
1881 /**
1882  * struct batadv_tt_global_entry - translation table global entry data
1883  */
1884 struct batadv_tt_global_entry {
1885 	/** @common: general translation table data */
1886 	struct batadv_tt_common_entry common;
1887 
1888 	/** @orig_list: list of orig nodes announcing this non-mesh client */
1889 	struct hlist_head orig_list;
1890 
1891 	/** @orig_list_count: number of items in the orig_list */
1892 	atomic_t orig_list_count;
1893 
1894 	/** @list_lock: lock protecting orig_list */
1895 	spinlock_t list_lock;
1896 
1897 	/** @roam_at: time at which TT_GLOBAL_ROAM was set */
1898 	unsigned long roam_at;
1899 };
1900 
1901 /**
1902  * struct batadv_tt_orig_list_entry - orig node announcing a non-mesh client
1903  */
1904 struct batadv_tt_orig_list_entry {
1905 	/** @orig_node: pointer to orig node announcing this non-mesh client */
1906 	struct batadv_orig_node *orig_node;
1907 
1908 	/**
1909 	 * @ttvn: translation table version number which added the non-mesh
1910 	 *  client
1911 	 */
1912 	u8 ttvn;
1913 
1914 	/** @flags: per orig entry TT sync flags */
1915 	u8 flags;
1916 
1917 	/** @list: list node for &batadv_tt_global_entry.orig_list */
1918 	struct hlist_node list;
1919 
1920 	/** @refcount: number of contexts the object is used */
1921 	struct kref refcount;
1922 
1923 	/** @rcu: struct used for freeing in an RCU-safe manner */
1924 	struct rcu_head rcu;
1925 };
1926 
1927 /**
1928  * struct batadv_tt_change_node - structure for tt changes occurred
1929  */
1930 struct batadv_tt_change_node {
1931 	/** @list: list node for &batadv_priv_tt.changes_list */
1932 	struct list_head list;
1933 
1934 	/** @change: holds the actual translation table diff data */
1935 	struct batadv_tvlv_tt_change change;
1936 };
1937 
1938 /**
1939  * struct batadv_tt_req_node - data to keep track of the tt requests in flight
1940  */
1941 struct batadv_tt_req_node {
1942 	/**
1943 	 * @addr: mac address of the originator this request was sent to
1944 	 */
1945 	u8 addr[ETH_ALEN];
1946 
1947 	/** @issued_at: timestamp used for purging stale tt requests */
1948 	unsigned long issued_at;
1949 
1950 	/** @refcount: number of contexts the object is used by */
1951 	struct kref refcount;
1952 
1953 	/** @list: list node for &batadv_priv_tt.req_list */
1954 	struct hlist_node list;
1955 };
1956 
1957 /**
1958  * struct batadv_tt_roam_node - roaming client data
1959  */
1960 struct batadv_tt_roam_node {
1961 	/** @addr: mac address of the client in the roaming phase */
1962 	u8 addr[ETH_ALEN];
1963 
1964 	/** @vid: VLAN identifier */
1965 	u16 vid;
1966 
1967 	/**
1968 	 * @counter: number of allowed roaming events per client within a single
1969 	 * OGM interval (changes are committed with each OGM)
1970 	 */
1971 	atomic_t counter;
1972 
1973 	/**
1974 	 * @first_time: timestamp used for purging stale roaming node entries
1975 	 */
1976 	unsigned long first_time;
1977 
1978 	/** @list: list node for &batadv_priv_tt.roam_list */
1979 	struct list_head list;
1980 };
1981 
1982 /**
1983  * struct batadv_skb_cb - control buffer structure used to store private data
1984  *  relevant to batman-adv in the skb->cb buffer in skbs.
1985  */
1986 struct batadv_skb_cb {
1987 	/** @num_bcasts: Counter for broadcast packet retransmissions */
1988 	unsigned char num_bcasts;
1989 };
1990 
1991 /**
1992  * struct batadv_forw_packet - structure for bcast packets to be sent/forwarded
1993  */
1994 struct batadv_forw_packet {
1995 	/**
1996 	 * @list: list node for &batadv_priv.forw.bcast_list and
1997 	 *  &batadv_priv.forw.bat_list
1998 	 */
1999 	struct hlist_node list;
2000 
2001 	/** @cleanup_list: list node for purging functions */
2002 	struct hlist_node cleanup_list;
2003 
2004 	/** @send_time: execution time for delayed_work (packet sending) */
2005 	unsigned long send_time;
2006 
2007 	/**
2008 	 * @own: bool for locally generated packets (local OGMs are re-scheduled
2009 	 * after sending)
2010 	 */
2011 	u8 own;
2012 
2013 	/** @skb: bcast packet's skb buffer */
2014 	struct sk_buff *skb;
2015 
2016 	/** @packet_len: size of aggregated OGM packet inside the skb buffer */
2017 	u16 packet_len;
2018 
2019 	/** @direct_link_flags: direct link flags for aggregated OGM packets */
2020 	DECLARE_BITMAP(direct_link_flags, BATADV_MAX_AGGREGATION_PACKETS);
2021 
2022 	/** @num_packets: counter for aggregated OGMv1 packets */
2023 	u8 num_packets;
2024 
2025 	/** @delayed_work: work queue callback item for packet sending */
2026 	struct delayed_work delayed_work;
2027 
2028 	/**
2029 	 * @if_incoming: pointer to incoming hard-iface or primary iface if
2030 	 *  locally generated packet
2031 	 */
2032 	struct batadv_hard_iface *if_incoming;
2033 
2034 	/**
2035 	 * @if_outgoing: packet where the packet should be sent to, or NULL if
2036 	 *  unspecified
2037 	 */
2038 	struct batadv_hard_iface *if_outgoing;
2039 
2040 	/** @queue_left: The queue (counter) this packet was applied to */
2041 	atomic_t *queue_left;
2042 };
2043 
2044 /**
2045  * struct batadv_algo_iface_ops - mesh algorithm callbacks (interface specific)
2046  */
2047 struct batadv_algo_iface_ops {
2048 	/**
2049 	 * @activate: start routing mechanisms when hard-interface is brought up
2050 	 *  (optional)
2051 	 */
2052 	void (*activate)(struct batadv_hard_iface *hard_iface);
2053 
2054 	/** @enable: init routing info when hard-interface is enabled */
2055 	int (*enable)(struct batadv_hard_iface *hard_iface);
2056 
2057 	/** @enabled: notification when hard-interface was enabled (optional) */
2058 	void (*enabled)(struct batadv_hard_iface *hard_iface);
2059 
2060 	/** @disable: de-init routing info when hard-interface is disabled */
2061 	void (*disable)(struct batadv_hard_iface *hard_iface);
2062 
2063 	/**
2064 	 * @update_mac: (re-)init mac addresses of the protocol information
2065 	 *  belonging to this hard-interface
2066 	 */
2067 	void (*update_mac)(struct batadv_hard_iface *hard_iface);
2068 
2069 	/** @primary_set: called when primary interface is selected / changed */
2070 	void (*primary_set)(struct batadv_hard_iface *hard_iface);
2071 };
2072 
2073 /**
2074  * struct batadv_algo_neigh_ops - mesh algorithm callbacks (neighbour specific)
2075  */
2076 struct batadv_algo_neigh_ops {
2077 	/** @hardif_init: called on creation of single hop entry (optional) */
2078 	void (*hardif_init)(struct batadv_hardif_neigh_node *neigh);
2079 
2080 	/**
2081 	 * @cmp: compare the metrics of two neighbors for their respective
2082 	 *  outgoing interfaces
2083 	 */
2084 	int (*cmp)(struct batadv_neigh_node *neigh1,
2085 		   struct batadv_hard_iface *if_outgoing1,
2086 		   struct batadv_neigh_node *neigh2,
2087 		   struct batadv_hard_iface *if_outgoing2);
2088 
2089 	/**
2090 	 * @is_similar_or_better: check if neigh1 is equally similar or better
2091 	 *  than neigh2 for their respective outgoing interface from the metric
2092 	 *  prospective
2093 	 */
2094 	bool (*is_similar_or_better)(struct batadv_neigh_node *neigh1,
2095 				     struct batadv_hard_iface *if_outgoing1,
2096 				     struct batadv_neigh_node *neigh2,
2097 				     struct batadv_hard_iface *if_outgoing2);
2098 
2099 	/** @dump: dump neighbors to a netlink socket (optional) */
2100 	void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
2101 		     struct batadv_priv *priv,
2102 		     struct batadv_hard_iface *hard_iface);
2103 };
2104 
2105 /**
2106  * struct batadv_algo_orig_ops - mesh algorithm callbacks (originator specific)
2107  */
2108 struct batadv_algo_orig_ops {
2109 	/** @dump: dump originators to a netlink socket (optional) */
2110 	void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
2111 		     struct batadv_priv *priv,
2112 		     struct batadv_hard_iface *hard_iface);
2113 };
2114 
2115 /**
2116  * struct batadv_algo_gw_ops - mesh algorithm callbacks (GW specific)
2117  */
2118 struct batadv_algo_gw_ops {
2119 	/** @init_sel_class: initialize GW selection class (optional) */
2120 	void (*init_sel_class)(struct batadv_priv *bat_priv);
2121 
2122 	/**
2123 	 * @sel_class_max: maximum allowed GW selection class
2124 	 */
2125 	u32 sel_class_max;
2126 
2127 	/**
2128 	 * @get_best_gw_node: select the best GW from the list of available
2129 	 *  nodes (optional)
2130 	 */
2131 	struct batadv_gw_node *(*get_best_gw_node)
2132 		(struct batadv_priv *bat_priv);
2133 
2134 	/**
2135 	 * @is_eligible: check if a newly discovered GW is a potential candidate
2136 	 *  for the election as best GW (optional)
2137 	 */
2138 	bool (*is_eligible)(struct batadv_priv *bat_priv,
2139 			    struct batadv_orig_node *curr_gw_orig,
2140 			    struct batadv_orig_node *orig_node);
2141 
2142 	/** @dump: dump gateways to a netlink socket (optional) */
2143 	void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
2144 		     struct batadv_priv *priv);
2145 };
2146 
2147 /**
2148  * struct batadv_algo_ops - mesh algorithm callbacks
2149  */
2150 struct batadv_algo_ops {
2151 	/** @list: list node for the batadv_algo_list */
2152 	struct hlist_node list;
2153 
2154 	/** @name: name of the algorithm */
2155 	char *name;
2156 
2157 	/** @iface: callbacks related to interface handling */
2158 	struct batadv_algo_iface_ops iface;
2159 
2160 	/** @neigh: callbacks related to neighbors handling */
2161 	struct batadv_algo_neigh_ops neigh;
2162 
2163 	/** @orig: callbacks related to originators handling */
2164 	struct batadv_algo_orig_ops orig;
2165 
2166 	/** @gw: callbacks related to GW mode */
2167 	struct batadv_algo_gw_ops gw;
2168 };
2169 
2170 /**
2171  * struct batadv_dat_entry - it is a single entry of batman-adv ARP backend. It
2172  * is used to stored ARP entries needed for the global DAT cache
2173  */
2174 struct batadv_dat_entry {
2175 	/** @ip: the IPv4 corresponding to this DAT/ARP entry */
2176 	__be32 ip;
2177 
2178 	/** @mac_addr: the MAC address associated to the stored IPv4 */
2179 	u8 mac_addr[ETH_ALEN];
2180 
2181 	/** @vid: the vlan ID associated to this entry */
2182 	unsigned short vid;
2183 
2184 	/**
2185 	 * @last_update: time in jiffies when this entry was refreshed last time
2186 	 */
2187 	unsigned long last_update;
2188 
2189 	/** @hash_entry: hlist node for &batadv_priv_dat.hash */
2190 	struct hlist_node hash_entry;
2191 
2192 	/** @refcount: number of contexts the object is used */
2193 	struct kref refcount;
2194 
2195 	/** @rcu: struct used for freeing in an RCU-safe manner */
2196 	struct rcu_head rcu;
2197 };
2198 
2199 /**
2200  * struct batadv_hw_addr - a list entry for a MAC address
2201  */
2202 struct batadv_hw_addr {
2203 	/** @list: list node for the linking of entries */
2204 	struct hlist_node list;
2205 
2206 	/** @addr: the MAC address of this list entry */
2207 	unsigned char addr[ETH_ALEN];
2208 };
2209 
2210 /**
2211  * struct batadv_dat_candidate - candidate destination for DAT operations
2212  */
2213 struct batadv_dat_candidate {
2214 	/**
2215 	 * @type: the type of the selected candidate. It can one of the
2216 	 *  following:
2217 	 *	  - BATADV_DAT_CANDIDATE_NOT_FOUND
2218 	 *	  - BATADV_DAT_CANDIDATE_ORIG
2219 	 */
2220 	int type;
2221 
2222 	/**
2223 	 * @orig_node: if type is BATADV_DAT_CANDIDATE_ORIG this field points to
2224 	 * the corresponding originator node structure
2225 	 */
2226 	struct batadv_orig_node *orig_node;
2227 };
2228 
2229 /**
2230  * struct batadv_tvlv_container - container for tvlv appended to OGMs
2231  */
2232 struct batadv_tvlv_container {
2233 	/** @list: hlist node for &batadv_priv_tvlv.container_list */
2234 	struct hlist_node list;
2235 
2236 	/** @tvlv_hdr: tvlv header information needed to construct the tvlv */
2237 	struct batadv_tvlv_hdr tvlv_hdr;
2238 
2239 	/** @refcount: number of contexts the object is used */
2240 	struct kref refcount;
2241 };
2242 
2243 /**
2244  * struct batadv_tvlv_handler - handler for specific tvlv type and version
2245  */
2246 struct batadv_tvlv_handler {
2247 	/** @list: hlist node for &batadv_priv_tvlv.handler_list */
2248 	struct hlist_node list;
2249 
2250 	/**
2251 	 * @ogm_handler: handler callback which is given the tvlv payload to
2252 	 *  process on incoming OGM packets
2253 	 */
2254 	void (*ogm_handler)(struct batadv_priv *bat_priv,
2255 			    struct batadv_orig_node *orig,
2256 			    u8 flags, void *tvlv_value, u16 tvlv_value_len);
2257 
2258 	/**
2259 	 * @unicast_handler: handler callback which is given the tvlv payload to
2260 	 *  process on incoming unicast tvlv packets
2261 	 */
2262 	int (*unicast_handler)(struct batadv_priv *bat_priv,
2263 			       u8 *src, u8 *dst,
2264 			       void *tvlv_value, u16 tvlv_value_len);
2265 
2266 	/**
2267 	 * @mcast_handler: handler callback which is given the tvlv payload to
2268 	 *  process on incoming mcast packet
2269 	 */
2270 	int (*mcast_handler)(struct batadv_priv *bat_priv, struct sk_buff *skb);
2271 
2272 	/** @type: tvlv type this handler feels responsible for */
2273 	u8 type;
2274 
2275 	/** @version: tvlv version this handler feels responsible for */
2276 	u8 version;
2277 
2278 	/** @flags: tvlv handler flags */
2279 	u8 flags;
2280 
2281 	/** @refcount: number of contexts the object is used */
2282 	struct kref refcount;
2283 
2284 	/** @rcu: struct used for freeing in an RCU-safe manner */
2285 	struct rcu_head rcu;
2286 };
2287 
2288 /**
2289  * enum batadv_tvlv_handler_flags - tvlv handler flags definitions
2290  */
2291 enum batadv_tvlv_handler_flags {
2292 	/**
2293 	 * @BATADV_TVLV_HANDLER_OGM_CIFNOTFND: tvlv ogm processing function
2294 	 *  will call this handler even if its type was not found (with no data)
2295 	 */
2296 	BATADV_TVLV_HANDLER_OGM_CIFNOTFND = BIT(1),
2297 };
2298 
2299 #endif /* _NET_BATMAN_ADV_TYPES_H_ */
2300