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