xref: /linux/net/batman-adv/types.h (revision 66182ca873a4e87b3496eca79d57f86b76d7f52d)
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 	u16 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 	s16 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 	s16 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 	/** @reason: reason for a stopped session */
1327 	enum batadv_tp_meter_reason reason;
1328 
1329 	/** @finish_work: work item for the finishing procedure */
1330 	struct delayed_work finish_work;
1331 
1332 	/** @finished: completion signaled when a sender thread exits */
1333 	struct completion finished;
1334 
1335 	/** @test_length: test length in milliseconds */
1336 	u32 test_length;
1337 
1338 	/** @session: TP session identifier */
1339 	u8 session[2];
1340 
1341 	/** @icmp_uid: local ICMP "socket" index */
1342 	u8 icmp_uid;
1343 
1344 	/* sender variables */
1345 
1346 	/** @dec_cwnd: decimal part of the cwnd used during linear growth */
1347 	u16 dec_cwnd;
1348 
1349 	/** @cwnd: current size of the congestion window */
1350 	u32 cwnd;
1351 
1352 	/** @cwnd_lock: lock do protect @cwnd & @dec_cwnd */
1353 	spinlock_t cwnd_lock;
1354 
1355 	/**
1356 	 * @ss_threshold: Slow Start threshold. Once cwnd exceeds this value the
1357 	 *  connection switches to the Congestion Avoidance state
1358 	 */
1359 	u32 ss_threshold;
1360 
1361 	/** @last_acked: last acked byte */
1362 	atomic_t last_acked;
1363 
1364 	/** @last_sent: last sent byte, not yet acked */
1365 	u32 last_sent;
1366 
1367 	/** @tot_sent: amount of data sent/ACKed so far */
1368 	atomic64_t tot_sent;
1369 
1370 	/** @dup_acks: duplicate ACKs counter */
1371 	atomic_t dup_acks;
1372 
1373 	/** @fast_recovery: true if in Fast Recovery mode */
1374 	unsigned char fast_recovery:1;
1375 
1376 	/** @recover: last sent seqno when entering Fast Recovery */
1377 	u32 recover;
1378 
1379 	/** @rto: sender timeout */
1380 	u32 rto;
1381 
1382 	/** @srtt: smoothed RTT scaled by 2^3 */
1383 	u32 srtt;
1384 
1385 	/** @rttvar: RTT variation scaled by 2^2 */
1386 	u32 rttvar;
1387 
1388 	/**
1389 	 * @more_bytes: waiting queue anchor when waiting for more ack/retry
1390 	 *  timeout
1391 	 */
1392 	wait_queue_head_t more_bytes;
1393 
1394 	/** @prerandom_offset: offset inside the prerandom buffer */
1395 	u32 prerandom_offset;
1396 
1397 	/** @prerandom_lock: spinlock protecting access to prerandom_offset */
1398 	spinlock_t prerandom_lock;
1399 
1400 	/* receiver variables */
1401 
1402 	/** @last_recv: last in-order received packet */
1403 	u32 last_recv;
1404 
1405 	/** @unacked_list: list of unacked packets (meta-info only) */
1406 	struct list_head unacked_list;
1407 
1408 	/** @unacked_lock: protect unacked_list */
1409 	spinlock_t unacked_lock;
1410 
1411 	/** @last_recv_time: time (jiffies) a msg was received */
1412 	unsigned long last_recv_time;
1413 
1414 	/** @refcount: number of context where the object is used */
1415 	struct kref refcount;
1416 
1417 	/** @rcu: struct used for freeing in an RCU-safe manner */
1418 	struct rcu_head rcu;
1419 };
1420 
1421 /**
1422  * struct batadv_meshif_vlan - per VLAN attributes set
1423  */
1424 struct batadv_meshif_vlan {
1425 	/** @bat_priv: pointer to the mesh object */
1426 	struct batadv_priv *bat_priv;
1427 
1428 	/** @vid: VLAN identifier */
1429 	unsigned short vid;
1430 
1431 	/** @ap_isolation: AP isolation state */
1432 	atomic_t ap_isolation;		/* boolean */
1433 
1434 	/** @tt: TT private attributes (VLAN specific) */
1435 	struct batadv_vlan_tt tt;
1436 
1437 	/** @list: list node for &bat_priv.meshif_vlan_list */
1438 	struct hlist_node list;
1439 
1440 	/**
1441 	 * @refcount: number of context where this object is currently in use
1442 	 */
1443 	struct kref refcount;
1444 
1445 	/** @rcu: struct used for freeing in a RCU-safe manner */
1446 	struct rcu_head rcu;
1447 };
1448 
1449 /**
1450  * struct batadv_priv_bat_v - B.A.T.M.A.N. V per mesh-interface private data
1451  */
1452 struct batadv_priv_bat_v {
1453 	/** @ogm_buff: buffer holding the OGM packet */
1454 	unsigned char *ogm_buff;
1455 
1456 	/** @ogm_buff_len: length of the OGM packet buffer */
1457 	int ogm_buff_len;
1458 
1459 	/** @ogm_seqno: OGM sequence number - used to identify each OGM */
1460 	atomic_t ogm_seqno;
1461 
1462 	/** @ogm_buff_mutex: lock protecting ogm_buff and ogm_buff_len */
1463 	struct mutex ogm_buff_mutex;
1464 
1465 	/** @ogm_wq: workqueue used to schedule OGM transmissions */
1466 	struct delayed_work ogm_wq;
1467 };
1468 
1469 /**
1470  * struct batadv_priv - per mesh interface data
1471  */
1472 struct batadv_priv {
1473 	/**
1474 	 * @mesh_state: current status of the mesh
1475 	 *  (inactive/active/deactivating)
1476 	 */
1477 	atomic_t mesh_state;
1478 
1479 	/** @mesh_iface: net device which holds this struct as private data */
1480 	struct net_device *mesh_iface;
1481 
1482 	/**
1483 	 * @mtu_set_by_user: MTU was set once by user
1484 	 * protected by rtnl_lock
1485 	 */
1486 	int mtu_set_by_user;
1487 
1488 	/**
1489 	 * @bat_counters: mesh internal traffic statistic counters (see
1490 	 *  batadv_counters)
1491 	 */
1492 	u64 __percpu *bat_counters; /* Per cpu counters */
1493 
1494 	/**
1495 	 * @aggregated_ogms: bool indicating whether OGM aggregation is enabled
1496 	 */
1497 	atomic_t aggregated_ogms;
1498 
1499 	/** @bonding: bool indicating whether traffic bonding is enabled */
1500 	atomic_t bonding;
1501 
1502 	/**
1503 	 * @fragmentation: bool indicating whether traffic fragmentation is
1504 	 *  enabled
1505 	 */
1506 	atomic_t fragmentation;
1507 
1508 	/**
1509 	 * @packet_size_max: max packet size that can be transmitted via
1510 	 *  multiple fragmented skbs or a single frame if fragmentation is
1511 	 *  disabled
1512 	 */
1513 	atomic_t packet_size_max;
1514 
1515 	/**
1516 	 * @frag_seqno: incremental counter to identify chains of egress
1517 	 *  fragments
1518 	 */
1519 	atomic_t frag_seqno;
1520 
1521 #ifdef CONFIG_BATMAN_ADV_BLA
1522 	/**
1523 	 * @bridge_loop_avoidance: bool indicating whether bridge loop
1524 	 *  avoidance is enabled
1525 	 */
1526 	atomic_t bridge_loop_avoidance;
1527 #endif
1528 
1529 #ifdef CONFIG_BATMAN_ADV_DAT
1530 	/**
1531 	 * @distributed_arp_table: bool indicating whether distributed ARP table
1532 	 *  is enabled
1533 	 */
1534 	atomic_t distributed_arp_table;
1535 #endif
1536 
1537 #ifdef CONFIG_BATMAN_ADV_MCAST
1538 	/**
1539 	 * @multicast_mode: Enable or disable multicast optimizations on this
1540 	 *  node's sender/originating side
1541 	 */
1542 	atomic_t multicast_mode;
1543 
1544 	/**
1545 	 * @multicast_fanout: Maximum number of packet copies to generate for a
1546 	 *  multicast-to-unicast conversion
1547 	 */
1548 	atomic_t multicast_fanout;
1549 #endif
1550 
1551 	/** @orig_interval: OGM broadcast interval in milliseconds */
1552 	atomic_t orig_interval;
1553 
1554 	/**
1555 	 * @hop_penalty: penalty which will be applied to an OGM's tq-field on
1556 	 *  every hop
1557 	 */
1558 	atomic_t hop_penalty;
1559 
1560 #ifdef CONFIG_BATMAN_ADV_DEBUG
1561 	/** @log_level: configured log level (see batadv_dbg_level) */
1562 	atomic_t log_level;
1563 #endif
1564 
1565 	/**
1566 	 * @isolation_mark: the skb->mark value used to match packets for AP
1567 	 *  isolation
1568 	 */
1569 	u32 isolation_mark;
1570 
1571 	/**
1572 	 * @isolation_mark_mask: bitmask identifying the bits in skb->mark to be
1573 	 *  used for the isolation mark
1574 	 */
1575 	u32 isolation_mark_mask;
1576 
1577 	/** @bcast_seqno: last sent broadcast packet sequence number */
1578 	atomic_t bcast_seqno;
1579 
1580 	/**
1581 	 * @bcast_queue_left: number of remaining buffered broadcast packet
1582 	 *  slots
1583 	 */
1584 	atomic_t bcast_queue_left;
1585 
1586 	/** @batman_queue_left: number of remaining OGM packet slots */
1587 	atomic_t batman_queue_left;
1588 
1589 	/** @forw_bat_list: list of aggregated OGMs that will be forwarded */
1590 	struct hlist_head forw_bat_list;
1591 
1592 	/**
1593 	 * @forw_bcast_list: list of broadcast packets that will be
1594 	 *  rebroadcasted
1595 	 */
1596 	struct hlist_head forw_bcast_list;
1597 
1598 	/** @tp_list: list of tp sessions */
1599 	struct hlist_head tp_list;
1600 
1601 	/** @orig_hash: hash table containing mesh participants (orig nodes) */
1602 	struct batadv_hashtable *orig_hash;
1603 
1604 	/** @forw_bat_list_lock: lock protecting forw_bat_list */
1605 	spinlock_t forw_bat_list_lock;
1606 
1607 	/** @forw_bcast_list_lock: lock protecting forw_bcast_list */
1608 	spinlock_t forw_bcast_list_lock;
1609 
1610 	/** @tp_list_lock: spinlock protecting @tp_list */
1611 	spinlock_t tp_list_lock;
1612 
1613 	/** @tp_num: number of currently active tp sessions */
1614 	atomic_t tp_num;
1615 
1616 	/** @orig_work: work queue callback item for orig node purging */
1617 	struct delayed_work orig_work;
1618 
1619 	/**
1620 	 * @primary_if: one of the hard-interfaces assigned to this mesh
1621 	 *  interface becomes the primary interface
1622 	 */
1623 	struct batadv_hard_iface __rcu *primary_if;  /* rcu protected pointer */
1624 
1625 	/** @algo_ops: routing algorithm used by this mesh interface */
1626 	struct batadv_algo_ops *algo_ops;
1627 
1628 	/**
1629 	 * @meshif_vlan_list: a list of meshif_vlan structs, one per VLAN
1630 	 *  created on top of the mesh interface represented by this object
1631 	 */
1632 	struct hlist_head meshif_vlan_list;
1633 
1634 	/** @meshif_vlan_list_lock: lock protecting meshif_vlan_list */
1635 	spinlock_t meshif_vlan_list_lock;
1636 
1637 #ifdef CONFIG_BATMAN_ADV_BLA
1638 	/** @bla: bridge loop avoidance data */
1639 	struct batadv_priv_bla bla;
1640 #endif
1641 
1642 	/** @gw: gateway data */
1643 	struct batadv_priv_gw gw;
1644 
1645 	/** @tt: translation table data */
1646 	struct batadv_priv_tt tt;
1647 
1648 	/** @tvlv: type-version-length-value data */
1649 	struct batadv_priv_tvlv tvlv;
1650 
1651 #ifdef CONFIG_BATMAN_ADV_DAT
1652 	/** @dat: distributed arp table data */
1653 	struct batadv_priv_dat dat;
1654 #endif
1655 
1656 #ifdef CONFIG_BATMAN_ADV_MCAST
1657 	/** @mcast: multicast data */
1658 	struct batadv_priv_mcast mcast;
1659 #endif
1660 
1661 #ifdef CONFIG_BATMAN_ADV_BATMAN_V
1662 	/** @bat_v: B.A.T.M.A.N. V per mesh-interface private data */
1663 	struct batadv_priv_bat_v bat_v;
1664 #endif
1665 };
1666 
1667 #ifdef CONFIG_BATMAN_ADV_BLA
1668 
1669 /**
1670  * struct batadv_bla_backbone_gw - batman-adv gateway bridged into the LAN
1671  */
1672 struct batadv_bla_backbone_gw {
1673 	/**
1674 	 * @orig: originator address of backbone node (mac address of primary
1675 	 *  iface)
1676 	 */
1677 	u8 orig[ETH_ALEN];
1678 
1679 	/** @vid: vlan id this gateway was detected on */
1680 	unsigned short vid;
1681 
1682 	/** @hash_entry: hlist node for &batadv_priv_bla.backbone_hash */
1683 	struct hlist_node hash_entry;
1684 
1685 	/** @bat_priv: pointer to mesh_iface this backbone gateway belongs to */
1686 	struct batadv_priv *bat_priv;
1687 
1688 	/** @lasttime: last time we heard of this backbone gw */
1689 	unsigned long lasttime;
1690 
1691 	/**
1692 	 * @wait_periods: grace time for bridge forward delays and bla group
1693 	 *  forming at bootup phase - no bcast traffic is formwared until it has
1694 	 *  elapsed
1695 	 */
1696 	atomic_t wait_periods;
1697 
1698 	/**
1699 	 * @request_sent: if this bool is set to true we are out of sync with
1700 	 *  this backbone gateway - no bcast traffic is formwared until the
1701 	 *  situation was resolved
1702 	 */
1703 	atomic_t request_sent;
1704 
1705 	/** @crc: crc16 checksum over all claims */
1706 	u16 crc;
1707 
1708 	/** @crc_lock: lock protecting crc */
1709 	spinlock_t crc_lock;
1710 
1711 	/** @report_work: work struct for reporting detected loops */
1712 	struct work_struct report_work;
1713 
1714 	/** @refcount: number of contexts the object is used */
1715 	struct kref refcount;
1716 
1717 	/** @rcu: struct used for freeing in an RCU-safe manner */
1718 	struct rcu_head rcu;
1719 };
1720 
1721 /**
1722  * struct batadv_bla_claim - claimed non-mesh client structure
1723  */
1724 struct batadv_bla_claim {
1725 	/** @addr: mac address of claimed non-mesh client */
1726 	u8 addr[ETH_ALEN];
1727 
1728 	/** @vid: vlan id this client was detected on */
1729 	unsigned short vid;
1730 
1731 	/** @backbone_gw: pointer to backbone gw claiming this client */
1732 	struct batadv_bla_backbone_gw *backbone_gw;
1733 
1734 	/** @backbone_lock: lock protecting backbone_gw pointer */
1735 	spinlock_t backbone_lock;
1736 
1737 	/** @lasttime: last time we heard of claim (locals only) */
1738 	unsigned long lasttime;
1739 
1740 	/** @hash_entry: hlist node for &batadv_priv_bla.claim_hash */
1741 	struct hlist_node hash_entry;
1742 
1743 	/** @refcount: number of contexts the object is used */
1744 	struct rcu_head rcu;
1745 
1746 	/** @rcu: struct used for freeing in an RCU-safe manner */
1747 	struct kref refcount;
1748 };
1749 #endif
1750 
1751 /**
1752  * struct batadv_tt_common_entry - tt local & tt global common data
1753  */
1754 struct batadv_tt_common_entry {
1755 	/** @addr: mac address of non-mesh client */
1756 	u8 addr[ETH_ALEN];
1757 
1758 	/** @vid: VLAN identifier */
1759 	unsigned short vid;
1760 
1761 	/**
1762 	 * @hash_entry: hlist node for &batadv_priv_tt.local_hash or for
1763 	 *  &batadv_priv_tt.global_hash
1764 	 */
1765 	struct hlist_node hash_entry;
1766 
1767 	/** @flags: various state handling flags (see batadv_tt_client_flags) */
1768 	u16 flags;
1769 
1770 	/** @added_at: timestamp used for purging stale tt common entries */
1771 	unsigned long added_at;
1772 
1773 	/** @refcount: number of contexts the object is used */
1774 	struct kref refcount;
1775 
1776 	/** @rcu: struct used for freeing in an RCU-safe manner */
1777 	struct rcu_head rcu;
1778 };
1779 
1780 /**
1781  * struct batadv_tt_local_entry - translation table local entry data
1782  */
1783 struct batadv_tt_local_entry {
1784 	/** @common: general translation table data */
1785 	struct batadv_tt_common_entry common;
1786 
1787 	/** @last_seen: timestamp used for purging stale tt local entries */
1788 	unsigned long last_seen;
1789 
1790 	/** @vlan: mesh-interface vlan of the entry */
1791 	struct batadv_meshif_vlan *vlan;
1792 };
1793 
1794 /**
1795  * struct batadv_tt_global_entry - translation table global entry data
1796  */
1797 struct batadv_tt_global_entry {
1798 	/** @common: general translation table data */
1799 	struct batadv_tt_common_entry common;
1800 
1801 	/** @orig_list: list of orig nodes announcing this non-mesh client */
1802 	struct hlist_head orig_list;
1803 
1804 	/** @orig_list_count: number of items in the orig_list */
1805 	atomic_t orig_list_count;
1806 
1807 	/** @list_lock: lock protecting orig_list */
1808 	spinlock_t list_lock;
1809 
1810 	/** @roam_at: time at which TT_GLOBAL_ROAM was set */
1811 	unsigned long roam_at;
1812 };
1813 
1814 /**
1815  * struct batadv_tt_orig_list_entry - orig node announcing a non-mesh client
1816  */
1817 struct batadv_tt_orig_list_entry {
1818 	/** @orig_node: pointer to orig node announcing this non-mesh client */
1819 	struct batadv_orig_node *orig_node;
1820 
1821 	/**
1822 	 * @ttvn: translation table version number which added the non-mesh
1823 	 *  client
1824 	 */
1825 	u8 ttvn;
1826 
1827 	/** @flags: per orig entry TT sync flags */
1828 	u8 flags;
1829 
1830 	/** @list: list node for &batadv_tt_global_entry.orig_list */
1831 	struct hlist_node list;
1832 
1833 	/** @refcount: number of contexts the object is used */
1834 	struct kref refcount;
1835 
1836 	/** @rcu: struct used for freeing in an RCU-safe manner */
1837 	struct rcu_head rcu;
1838 };
1839 
1840 /**
1841  * struct batadv_tt_change_node - structure for tt changes occurred
1842  */
1843 struct batadv_tt_change_node {
1844 	/** @list: list node for &batadv_priv_tt.changes_list */
1845 	struct list_head list;
1846 
1847 	/** @change: holds the actual translation table diff data */
1848 	struct batadv_tvlv_tt_change change;
1849 };
1850 
1851 /**
1852  * struct batadv_tt_req_node - data to keep track of the tt requests in flight
1853  */
1854 struct batadv_tt_req_node {
1855 	/**
1856 	 * @addr: mac address of the originator this request was sent to
1857 	 */
1858 	u8 addr[ETH_ALEN];
1859 
1860 	/** @issued_at: timestamp used for purging stale tt requests */
1861 	unsigned long issued_at;
1862 
1863 	/** @refcount: number of contexts the object is used by */
1864 	struct kref refcount;
1865 
1866 	/** @list: list node for &batadv_priv_tt.req_list */
1867 	struct hlist_node list;
1868 };
1869 
1870 /**
1871  * struct batadv_tt_roam_node - roaming client data
1872  */
1873 struct batadv_tt_roam_node {
1874 	/** @addr: mac address of the client in the roaming phase */
1875 	u8 addr[ETH_ALEN];
1876 
1877 	/**
1878 	 * @counter: number of allowed roaming events per client within a single
1879 	 * OGM interval (changes are committed with each OGM)
1880 	 */
1881 	atomic_t counter;
1882 
1883 	/**
1884 	 * @first_time: timestamp used for purging stale roaming node entries
1885 	 */
1886 	unsigned long first_time;
1887 
1888 	/** @list: list node for &batadv_priv_tt.roam_list */
1889 	struct list_head list;
1890 };
1891 
1892 /**
1893  * struct batadv_skb_cb - control buffer structure used to store private data
1894  *  relevant to batman-adv in the skb->cb buffer in skbs.
1895  */
1896 struct batadv_skb_cb {
1897 	/** @num_bcasts: Counter for broadcast packet retransmissions */
1898 	unsigned char num_bcasts;
1899 };
1900 
1901 /**
1902  * struct batadv_forw_packet - structure for bcast packets to be sent/forwarded
1903  */
1904 struct batadv_forw_packet {
1905 	/**
1906 	 * @list: list node for &batadv_priv.forw.bcast_list and
1907 	 *  &batadv_priv.forw.bat_list
1908 	 */
1909 	struct hlist_node list;
1910 
1911 	/** @cleanup_list: list node for purging functions */
1912 	struct hlist_node cleanup_list;
1913 
1914 	/** @send_time: execution time for delayed_work (packet sending) */
1915 	unsigned long send_time;
1916 
1917 	/**
1918 	 * @own: bool for locally generated packets (local OGMs are re-scheduled
1919 	 * after sending)
1920 	 */
1921 	u8 own;
1922 
1923 	/** @skb: bcast packet's skb buffer */
1924 	struct sk_buff *skb;
1925 
1926 	/** @packet_len: size of aggregated OGM packet inside the skb buffer */
1927 	u16 packet_len;
1928 
1929 	/** @direct_link_flags: direct link flags for aggregated OGM packets */
1930 	DECLARE_BITMAP(direct_link_flags, BATADV_MAX_AGGREGATION_PACKETS);
1931 
1932 	/** @num_packets: counter for aggregated OGMv1 packets */
1933 	u8 num_packets;
1934 
1935 	/** @delayed_work: work queue callback item for packet sending */
1936 	struct delayed_work delayed_work;
1937 
1938 	/**
1939 	 * @if_incoming: pointer to incoming hard-iface or primary iface if
1940 	 *  locally generated packet
1941 	 */
1942 	struct batadv_hard_iface *if_incoming;
1943 
1944 	/**
1945 	 * @if_outgoing: packet where the packet should be sent to, or NULL if
1946 	 *  unspecified
1947 	 */
1948 	struct batadv_hard_iface *if_outgoing;
1949 
1950 	/** @queue_left: The queue (counter) this packet was applied to */
1951 	atomic_t *queue_left;
1952 };
1953 
1954 /**
1955  * struct batadv_algo_iface_ops - mesh algorithm callbacks (interface specific)
1956  */
1957 struct batadv_algo_iface_ops {
1958 	/**
1959 	 * @activate: start routing mechanisms when hard-interface is brought up
1960 	 *  (optional)
1961 	 */
1962 	void (*activate)(struct batadv_hard_iface *hard_iface);
1963 
1964 	/** @enable: init routing info when hard-interface is enabled */
1965 	int (*enable)(struct batadv_hard_iface *hard_iface);
1966 
1967 	/** @enabled: notification when hard-interface was enabled (optional) */
1968 	void (*enabled)(struct batadv_hard_iface *hard_iface);
1969 
1970 	/** @disable: de-init routing info when hard-interface is disabled */
1971 	void (*disable)(struct batadv_hard_iface *hard_iface);
1972 
1973 	/**
1974 	 * @update_mac: (re-)init mac addresses of the protocol information
1975 	 *  belonging to this hard-interface
1976 	 */
1977 	void (*update_mac)(struct batadv_hard_iface *hard_iface);
1978 
1979 	/** @primary_set: called when primary interface is selected / changed */
1980 	void (*primary_set)(struct batadv_hard_iface *hard_iface);
1981 };
1982 
1983 /**
1984  * struct batadv_algo_neigh_ops - mesh algorithm callbacks (neighbour specific)
1985  */
1986 struct batadv_algo_neigh_ops {
1987 	/** @hardif_init: called on creation of single hop entry (optional) */
1988 	void (*hardif_init)(struct batadv_hardif_neigh_node *neigh);
1989 
1990 	/**
1991 	 * @cmp: compare the metrics of two neighbors for their respective
1992 	 *  outgoing interfaces
1993 	 */
1994 	int (*cmp)(struct batadv_neigh_node *neigh1,
1995 		   struct batadv_hard_iface *if_outgoing1,
1996 		   struct batadv_neigh_node *neigh2,
1997 		   struct batadv_hard_iface *if_outgoing2);
1998 
1999 	/**
2000 	 * @is_similar_or_better: check if neigh1 is equally similar or better
2001 	 *  than neigh2 for their respective outgoing interface from the metric
2002 	 *  prospective
2003 	 */
2004 	bool (*is_similar_or_better)(struct batadv_neigh_node *neigh1,
2005 				     struct batadv_hard_iface *if_outgoing1,
2006 				     struct batadv_neigh_node *neigh2,
2007 				     struct batadv_hard_iface *if_outgoing2);
2008 
2009 	/** @dump: dump neighbors to a netlink socket (optional) */
2010 	void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
2011 		     struct batadv_priv *priv,
2012 		     struct batadv_hard_iface *hard_iface);
2013 };
2014 
2015 /**
2016  * struct batadv_algo_orig_ops - mesh algorithm callbacks (originator specific)
2017  */
2018 struct batadv_algo_orig_ops {
2019 	/** @dump: dump originators to a netlink socket (optional) */
2020 	void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
2021 		     struct batadv_priv *priv,
2022 		     struct batadv_hard_iface *hard_iface);
2023 };
2024 
2025 /**
2026  * struct batadv_algo_gw_ops - mesh algorithm callbacks (GW specific)
2027  */
2028 struct batadv_algo_gw_ops {
2029 	/** @init_sel_class: initialize GW selection class (optional) */
2030 	void (*init_sel_class)(struct batadv_priv *bat_priv);
2031 
2032 	/**
2033 	 * @sel_class_max: maximum allowed GW selection class
2034 	 */
2035 	u32 sel_class_max;
2036 
2037 	/**
2038 	 * @get_best_gw_node: select the best GW from the list of available
2039 	 *  nodes (optional)
2040 	 */
2041 	struct batadv_gw_node *(*get_best_gw_node)
2042 		(struct batadv_priv *bat_priv);
2043 
2044 	/**
2045 	 * @is_eligible: check if a newly discovered GW is a potential candidate
2046 	 *  for the election as best GW (optional)
2047 	 */
2048 	bool (*is_eligible)(struct batadv_priv *bat_priv,
2049 			    struct batadv_orig_node *curr_gw_orig,
2050 			    struct batadv_orig_node *orig_node);
2051 
2052 	/** @dump: dump gateways to a netlink socket (optional) */
2053 	void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
2054 		     struct batadv_priv *priv);
2055 };
2056 
2057 /**
2058  * struct batadv_algo_ops - mesh algorithm callbacks
2059  */
2060 struct batadv_algo_ops {
2061 	/** @list: list node for the batadv_algo_list */
2062 	struct hlist_node list;
2063 
2064 	/** @name: name of the algorithm */
2065 	char *name;
2066 
2067 	/** @iface: callbacks related to interface handling */
2068 	struct batadv_algo_iface_ops iface;
2069 
2070 	/** @neigh: callbacks related to neighbors handling */
2071 	struct batadv_algo_neigh_ops neigh;
2072 
2073 	/** @orig: callbacks related to originators handling */
2074 	struct batadv_algo_orig_ops orig;
2075 
2076 	/** @gw: callbacks related to GW mode */
2077 	struct batadv_algo_gw_ops gw;
2078 };
2079 
2080 /**
2081  * struct batadv_dat_entry - it is a single entry of batman-adv ARP backend. It
2082  * is used to stored ARP entries needed for the global DAT cache
2083  */
2084 struct batadv_dat_entry {
2085 	/** @ip: the IPv4 corresponding to this DAT/ARP entry */
2086 	__be32 ip;
2087 
2088 	/** @mac_addr: the MAC address associated to the stored IPv4 */
2089 	u8 mac_addr[ETH_ALEN];
2090 
2091 	/** @vid: the vlan ID associated to this entry */
2092 	unsigned short vid;
2093 
2094 	/**
2095 	 * @last_update: time in jiffies when this entry was refreshed last time
2096 	 */
2097 	unsigned long last_update;
2098 
2099 	/** @hash_entry: hlist node for &batadv_priv_dat.hash */
2100 	struct hlist_node hash_entry;
2101 
2102 	/** @refcount: number of contexts the object is used */
2103 	struct kref refcount;
2104 
2105 	/** @rcu: struct used for freeing in an RCU-safe manner */
2106 	struct rcu_head rcu;
2107 };
2108 
2109 /**
2110  * struct batadv_hw_addr - a list entry for a MAC address
2111  */
2112 struct batadv_hw_addr {
2113 	/** @list: list node for the linking of entries */
2114 	struct hlist_node list;
2115 
2116 	/** @addr: the MAC address of this list entry */
2117 	unsigned char addr[ETH_ALEN];
2118 };
2119 
2120 /**
2121  * struct batadv_dat_candidate - candidate destination for DAT operations
2122  */
2123 struct batadv_dat_candidate {
2124 	/**
2125 	 * @type: the type of the selected candidate. It can one of the
2126 	 *  following:
2127 	 *	  - BATADV_DAT_CANDIDATE_NOT_FOUND
2128 	 *	  - BATADV_DAT_CANDIDATE_ORIG
2129 	 */
2130 	int type;
2131 
2132 	/**
2133 	 * @orig_node: if type is BATADV_DAT_CANDIDATE_ORIG this field points to
2134 	 * the corresponding originator node structure
2135 	 */
2136 	struct batadv_orig_node *orig_node;
2137 };
2138 
2139 /**
2140  * struct batadv_tvlv_container - container for tvlv appended to OGMs
2141  */
2142 struct batadv_tvlv_container {
2143 	/** @list: hlist node for &batadv_priv_tvlv.container_list */
2144 	struct hlist_node list;
2145 
2146 	/** @tvlv_hdr: tvlv header information needed to construct the tvlv */
2147 	struct batadv_tvlv_hdr tvlv_hdr;
2148 
2149 	/** @refcount: number of contexts the object is used */
2150 	struct kref refcount;
2151 };
2152 
2153 /**
2154  * struct batadv_tvlv_handler - handler for specific tvlv type and version
2155  */
2156 struct batadv_tvlv_handler {
2157 	/** @list: hlist node for &batadv_priv_tvlv.handler_list */
2158 	struct hlist_node list;
2159 
2160 	/**
2161 	 * @ogm_handler: handler callback which is given the tvlv payload to
2162 	 *  process on incoming OGM packets
2163 	 */
2164 	void (*ogm_handler)(struct batadv_priv *bat_priv,
2165 			    struct batadv_orig_node *orig,
2166 			    u8 flags, void *tvlv_value, u16 tvlv_value_len);
2167 
2168 	/**
2169 	 * @unicast_handler: handler callback which is given the tvlv payload to
2170 	 *  process on incoming unicast tvlv packets
2171 	 */
2172 	int (*unicast_handler)(struct batadv_priv *bat_priv,
2173 			       u8 *src, u8 *dst,
2174 			       void *tvlv_value, u16 tvlv_value_len);
2175 
2176 	/**
2177 	 * @mcast_handler: handler callback which is given the tvlv payload to
2178 	 *  process on incoming mcast packet
2179 	 */
2180 	int (*mcast_handler)(struct batadv_priv *bat_priv, struct sk_buff *skb);
2181 
2182 	/** @type: tvlv type this handler feels responsible for */
2183 	u8 type;
2184 
2185 	/** @version: tvlv version this handler feels responsible for */
2186 	u8 version;
2187 
2188 	/** @flags: tvlv handler flags */
2189 	u8 flags;
2190 
2191 	/** @refcount: number of contexts the object is used */
2192 	struct kref refcount;
2193 
2194 	/** @rcu: struct used for freeing in an RCU-safe manner */
2195 	struct rcu_head rcu;
2196 };
2197 
2198 /**
2199  * enum batadv_tvlv_handler_flags - tvlv handler flags definitions
2200  */
2201 enum batadv_tvlv_handler_flags {
2202 	/**
2203 	 * @BATADV_TVLV_HANDLER_OGM_CIFNOTFND: tvlv ogm processing function
2204 	 *  will call this handler even if its type was not found (with no data)
2205 	 */
2206 	BATADV_TVLV_HANDLER_OGM_CIFNOTFND = BIT(1),
2207 
2208 	/**
2209 	 * @BATADV_TVLV_HANDLER_OGM_CALLED: interval tvlv handling flag - the
2210 	 *  API marks a handler as being called, so it won't be called if the
2211 	 *  BATADV_TVLV_HANDLER_OGM_CIFNOTFND flag was set
2212 	 */
2213 	BATADV_TVLV_HANDLER_OGM_CALLED = BIT(2),
2214 };
2215 
2216 #endif /* _NET_BATMAN_ADV_TYPES_H_ */
2217