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