types.h 37.0 KB
Newer Older
1
/* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * Marek Lindner, Simon Wunderlich
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA
 */

#ifndef _NET_BATMAN_ADV_TYPES_H_
#define _NET_BATMAN_ADV_TYPES_H_

#include "packet.h"
#include "bitarray.h"
25
#include <linux/kernel.h>
26

27 28 29
/**
 * Maximum overhead for the encapsulation for a payload packet
 */
30
#define BATADV_HEADER_LEN \
31 32
	(ETH_HLEN + max(sizeof(struct batadv_unicast_packet), \
			sizeof(struct batadv_bcast_packet)))
33

34 35
#ifdef CONFIG_BATMAN_ADV_DAT

36 37 38 39 40 41 42
/* batadv_dat_addr_t is the type used for all DHT addresses. If it is changed,
 * BATADV_DAT_ADDR_MAX is changed as well.
 *
 * *Please be careful: batadv_dat_addr_t must be UNSIGNED*
 */
#define batadv_dat_addr_t uint16_t

43 44
#endif /* CONFIG_BATMAN_ADV_DAT */

45 46 47 48 49 50 51 52 53 54 55 56
/**
 * struct batadv_hard_iface_bat_iv - per hard interface B.A.T.M.A.N. IV data
 * @ogm_buff: buffer holding the OGM packet
 * @ogm_buff_len: length of the OGM packet buffer
 * @ogm_seqno: OGM sequence number - used to identify each OGM
 */
struct batadv_hard_iface_bat_iv {
	unsigned char *ogm_buff;
	int ogm_buff_len;
	atomic_t ogm_seqno;
};

57 58 59 60 61 62
/**
 * struct batadv_hard_iface - network device known to batman-adv
 * @list: list node for batadv_hardif_list
 * @if_num: identificator of the interface
 * @if_status: status of the interface for batman-adv
 * @net_dev: pointer to the net_device
63
 * @num_bcasts: number of payload re-broadcasts on this interface (ARQ)
64 65 66 67 68 69 70
 * @hardif_obj: kobject of the per interface sysfs "mesh" directory
 * @refcount: number of contexts the object is used
 * @batman_adv_ptype: packet type describing packets that should be processed by
 *  batman-adv for this interface
 * @soft_iface: the batman-adv interface which uses this network interface
 * @rcu: struct used for freeing in an RCU-safe manner
 * @bat_iv: BATMAN IV specific per hard interface data
71
 * @cleanup_work: work queue callback item for hard interface deinit
72
 */
73
struct batadv_hard_iface {
74 75 76 77
	struct list_head list;
	int16_t if_num;
	char if_status;
	struct net_device *net_dev;
78
	uint8_t num_bcasts;
79
	struct kobject *hardif_obj;
80
	atomic_t refcount;
81 82 83
	struct packet_type batman_adv_ptype;
	struct net_device *soft_iface;
	struct rcu_head rcu;
84
	struct batadv_hard_iface_bat_iv bat_iv;
85
	struct work_struct cleanup_work;
86 87
};

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
/**
 * struct batadv_frag_table_entry - head in the fragment buffer table
 * @head: head of list with fragments
 * @lock: lock to protect the list of fragments
 * @timestamp: time (jiffie) of last received fragment
 * @seqno: sequence number of the fragments in the list
 * @size: accumulated size of packets in list
 */
struct batadv_frag_table_entry {
	struct hlist_head head;
	spinlock_t lock; /* protects head */
	unsigned long timestamp;
	uint16_t seqno;
	uint16_t size;
};

/**
 * struct batadv_frag_list_entry - entry in a list of fragments
 * @list: list node information
 * @skb: fragment
 * @no: fragment number in the set
 */
struct batadv_frag_list_entry {
	struct hlist_node list;
	struct sk_buff *skb;
	uint8_t no;
};

116
/**
117
 * struct batadv_orig_node - structure for orig_list maintaining nodes of mesh
118
 * @orig: originator ethernet address
119
 * @primary_addr: hosts primary interface address
120 121 122 123 124 125
 * @router: router that should be used to reach this originator
 * @batadv_dat_addr_t:  address of the orig node in the distributed hash
 * @bcast_own: bitfield containing the number of our OGMs this orig_node
 *  rebroadcasted "back" to us (relative to last_real_seqno)
 * @bcast_own_sum: counted result of bcast_own
 * @last_seen: time when last packet from this node was received
126 127
 * @bcast_seqno_reset: time when the broadcast seqno window was reset
 * @batman_seqno_reset: time when the batman seqno window was reset
128
 * @capabilities: announced capabilities of this originator
129 130 131 132 133 134 135 136 137
 * @last_ttvn: last seen translation table version number
 * @tt_crc: CRC of the translation table
 * @tt_buff: last tt changeset this node received from the orig node
 * @tt_buff_len: length of the last tt changeset this node received from the
 *  orig node
 * @tt_buff_lock: lock that protects tt_buff and tt_buff_len
 * @tt_size: number of global TT entries announced by the orig node
 * @tt_initialised: bool keeping track of whether or not this node have received
 *  any translation table information from the orig node yet
138 139
 * @last_real_seqno: last and best known sequence number
 * @last_ttl: ttl of last received packet
140 141 142
 * @bcast_bits: bitfield containing the info which payload broadcast originated
 *  from this orig node this host already has seen (relative to
 *  last_bcast_seqno)
143
 * @last_bcast_seqno: last broadcast sequence number received by this host
144 145 146 147 148 149 150 151 152 153 154
 * @neigh_list: list of potential next hop neighbor towards this orig node
 * @neigh_list_lock: lock protecting neigh_list, router and bonding_list
 * @hash_entry: hlist node for batadv_priv::orig_hash
 * @bat_priv: pointer to soft_iface this orig node belongs to
 * @ogm_cnt_lock: lock protecting bcast_own, bcast_own_sum,
 *  neigh_node->real_bits & neigh_node->real_packet_count
 * @bcast_seqno_lock: lock protecting bcast_bits & last_bcast_seqno
 * @bond_candidates: how many candidates are available
 * @bond_list: list of bonding candidates
 * @refcount: number of contexts the object is used
 * @rcu: struct used for freeing in an RCU-safe manner
155 156 157 158
 * @in_coding_list: list of nodes this orig can hear
 * @out_coding_list: list of nodes that can hear this orig
 * @in_coding_list_lock: protects in_coding_list
 * @out_coding_list_lock: protects out_coding_list
159
 * @fragments: array with heads for fragment chains
160
 */
161
struct batadv_orig_node {
162 163
	uint8_t orig[ETH_ALEN];
	uint8_t primary_addr[ETH_ALEN];
164
	struct batadv_neigh_node __rcu *router; /* rcu protected pointer */
165
#ifdef CONFIG_BATMAN_ADV_DAT
166
	batadv_dat_addr_t dat_addr;
167
#endif
168 169
	unsigned long *bcast_own;
	uint8_t *bcast_own_sum;
170
	unsigned long last_seen;
171 172
	unsigned long bcast_seqno_reset;
	unsigned long batman_seqno_reset;
173
	uint8_t capabilities;
174
	atomic_t last_ttvn;
175
	uint32_t tt_crc;
176 177
	unsigned char *tt_buff;
	int16_t tt_buff_len;
178
	spinlock_t tt_buff_lock; /* protects tt_buff & tt_buff_len */
179
	atomic_t tt_size;
180
	bool tt_initialised;
181 182
	uint32_t last_real_seqno;
	uint8_t last_ttl;
183
	DECLARE_BITMAP(bcast_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
184
	uint32_t last_bcast_seqno;
185
	struct hlist_head neigh_list;
186 187
	/* neigh_list_lock protects: neigh_list, router & bonding_list */
	spinlock_t neigh_list_lock;
188
	struct hlist_node hash_entry;
189
	struct batadv_priv *bat_priv;
190
	/* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
191
	 * neigh_node->real_bits & neigh_node->real_packet_count
192
	 */
193
	spinlock_t ogm_cnt_lock;
194
	/* bcast_seqno_lock protects: bcast_bits & last_bcast_seqno */
195
	spinlock_t bcast_seqno_lock;
196 197
	atomic_t bond_candidates;
	struct list_head bond_list;
198 199
	atomic_t refcount;
	struct rcu_head rcu;
200 201 202 203 204 205
#ifdef CONFIG_BATMAN_ADV_NC
	struct list_head in_coding_list;
	struct list_head out_coding_list;
	spinlock_t in_coding_list_lock; /* Protects in_coding_list */
	spinlock_t out_coding_list_lock; /* Protects out_coding_list */
#endif
206
	struct batadv_frag_table_entry fragments[BATADV_FRAG_BUFFER_COUNT];
207 208
};

209 210 211
/**
 * enum batadv_orig_capabilities - orig node capabilities
 * @BATADV_ORIG_CAPA_HAS_DAT: orig node has distributed arp table enabled
212
 * @BATADV_ORIG_CAPA_HAS_NC: orig node has network coding enabled
213 214 215
 */
enum batadv_orig_capabilities {
	BATADV_ORIG_CAPA_HAS_DAT = BIT(0),
216
	BATADV_ORIG_CAPA_HAS_NC = BIT(1),
217 218
};

219 220 221 222
/**
 * struct batadv_gw_node - structure for orig nodes announcing gw capabilities
 * @list: list node for batadv_priv_gw::list
 * @orig_node: pointer to corresponding orig node
223 224
 * @bandwidth_down: advertised uplink download bandwidth
 * @bandwidth_up: advertised uplink upload bandwidth
225 226 227 228
 * @deleted: this struct is scheduled for deletion
 * @refcount: number of contexts the object is used
 * @rcu: struct used for freeing in an RCU-safe manner
 */
229
struct batadv_gw_node {
230
	struct hlist_node list;
231
	struct batadv_orig_node *orig_node;
232 233
	uint32_t bandwidth_down;
	uint32_t bandwidth_up;
234
	unsigned long deleted;
235
	atomic_t refcount;
236 237 238
	struct rcu_head rcu;
};

239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
/**
 * struct batadv_neigh_node - structure for single hop neighbors
 * @list: list node for batadv_orig_node::neigh_list
 * @addr: mac address of neigh node
 * @tq_recv: ring buffer of received TQ values from this neigh node
 * @tq_index: ring buffer index
 * @tq_avg: averaged tq of all tq values in the ring buffer (tq_recv)
 * @last_ttl: last received ttl from this neigh node
 * @bonding_list: list node for batadv_orig_node::bond_list
 * @last_seen: when last packet via this neighbor was received
 * @real_bits: bitfield containing the number of OGMs received from this neigh
 *  node (relative to orig_node->last_real_seqno)
 * @real_packet_count: counted result of real_bits
 * @orig_node: pointer to corresponding orig_node
 * @if_incoming: pointer to incoming hard interface
 * @lq_update_lock: lock protecting tq_recv & tq_index
 * @refcount: number of contexts the object is used
 * @rcu: struct used for freeing in an RCU-safe manner
257
 */
258
struct batadv_neigh_node {
259
	struct hlist_node list;
260
	uint8_t addr[ETH_ALEN];
261
	uint8_t tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE];
262 263 264
	uint8_t tq_index;
	uint8_t tq_avg;
	uint8_t last_ttl;
265
	struct list_head bonding_list;
266
	unsigned long last_seen;
267
	DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
268
	uint8_t real_packet_count;
269 270
	struct batadv_orig_node *orig_node;
	struct batadv_hard_iface *if_incoming;
271 272 273
	spinlock_t lq_update_lock; /* protects tq_recv & tq_index */
	atomic_t refcount;
	struct rcu_head rcu;
274 275
};

276 277 278 279 280 281
/**
 * struct batadv_bcast_duplist_entry - structure for LAN broadcast suppression
 * @orig[ETH_ALEN]: mac address of orig node orginating the broadcast
 * @crc: crc32 checksum of broadcast payload
 * @entrytime: time when the broadcast packet was received
 */
282
#ifdef CONFIG_BATMAN_ADV_BLA
283
struct batadv_bcast_duplist_entry {
284
	uint8_t orig[ETH_ALEN];
285
	__be32 crc;
286 287
	unsigned long entrytime;
};
288
#endif
289

290 291 292 293 294 295 296 297 298 299 300 301 302
/**
 * enum batadv_counters - indices for traffic counters
 * @BATADV_CNT_TX: transmitted payload traffic packet counter
 * @BATADV_CNT_TX_BYTES: transmitted payload traffic bytes counter
 * @BATADV_CNT_TX_DROPPED: dropped transmission payload traffic packet counter
 * @BATADV_CNT_RX: received payload traffic packet counter
 * @BATADV_CNT_RX_BYTES: received payload traffic bytes counter
 * @BATADV_CNT_FORWARD: forwarded payload traffic packet counter
 * @BATADV_CNT_FORWARD_BYTES: forwarded payload traffic bytes counter
 * @BATADV_CNT_MGMT_TX: transmitted routing protocol traffic packet counter
 * @BATADV_CNT_MGMT_TX_BYTES: transmitted routing protocol traffic bytes counter
 * @BATADV_CNT_MGMT_RX: received routing protocol traffic packet counter
 * @BATADV_CNT_MGMT_RX_BYTES: received routing protocol traffic bytes counter
303 304 305 306
 * @BATADV_CNT_FRAG_RX: received fragment traffic packet counter
 * @BATADV_CNT_FRAG_RX_BYTES: received fragment traffic bytes counter
 * @BATADV_CNT_FRAG_FWD: forwarded fragment traffic packet counter
 * @BATADV_CNT_FRAG_FWD_BYTES: forwarded fragment traffic bytes counter
307 308 309 310 311 312 313 314 315 316 317 318
 * @BATADV_CNT_TT_REQUEST_TX: transmitted tt req traffic packet counter
 * @BATADV_CNT_TT_REQUEST_RX: received tt req traffic packet counter
 * @BATADV_CNT_TT_RESPONSE_TX: transmitted tt resp traffic packet counter
 * @BATADV_CNT_TT_RESPONSE_RX: received tt resp traffic packet counter
 * @BATADV_CNT_TT_ROAM_ADV_TX: transmitted tt roam traffic packet counter
 * @BATADV_CNT_TT_ROAM_ADV_RX: received tt roam traffic packet counter
 * @BATADV_CNT_DAT_GET_TX: transmitted dht GET traffic packet counter
 * @BATADV_CNT_DAT_GET_RX: received dht GET traffic packet counter
 * @BATADV_CNT_DAT_PUT_TX: transmitted dht PUT traffic packet counter
 * @BATADV_CNT_DAT_PUT_RX: received dht PUT traffic packet counter
 * @BATADV_CNT_DAT_CACHED_REPLY_TX: transmitted dat cache reply traffic packet
 *  counter
319 320 321 322
 * @BATADV_CNT_NC_CODE: transmitted nc-combined traffic packet counter
 * @BATADV_CNT_NC_CODE_BYTES: transmitted nc-combined traffic bytes counter
 * @BATADV_CNT_NC_RECODE: transmitted nc-recombined traffic packet counter
 * @BATADV_CNT_NC_RECODE_BYTES: transmitted nc-recombined traffic bytes counter
323
 * @BATADV_CNT_NC_BUFFER: counter for packets buffered for later nc decoding
324 325 326 327 328 329
 * @BATADV_CNT_NC_DECODE: received and nc-decoded traffic packet counter
 * @BATADV_CNT_NC_DECODE_BYTES: received and nc-decoded traffic bytes counter
 * @BATADV_CNT_NC_DECODE_FAILED: received and decode-failed traffic packet
 *  counter
 * @BATADV_CNT_NC_SNIFFED: counter for nc-decoded packets received in promisc
 *  mode.
330 331
 * @BATADV_CNT_NUM: number of traffic counters
 */
332
enum batadv_counters {
333 334 335 336 337
	BATADV_CNT_TX,
	BATADV_CNT_TX_BYTES,
	BATADV_CNT_TX_DROPPED,
	BATADV_CNT_RX,
	BATADV_CNT_RX_BYTES,
338 339 340 341 342 343
	BATADV_CNT_FORWARD,
	BATADV_CNT_FORWARD_BYTES,
	BATADV_CNT_MGMT_TX,
	BATADV_CNT_MGMT_TX_BYTES,
	BATADV_CNT_MGMT_RX,
	BATADV_CNT_MGMT_RX_BYTES,
344 345 346 347
	BATADV_CNT_FRAG_RX,
	BATADV_CNT_FRAG_RX_BYTES,
	BATADV_CNT_FRAG_FWD,
	BATADV_CNT_FRAG_FWD_BYTES,
348 349 350 351 352 353
	BATADV_CNT_TT_REQUEST_TX,
	BATADV_CNT_TT_REQUEST_RX,
	BATADV_CNT_TT_RESPONSE_TX,
	BATADV_CNT_TT_RESPONSE_RX,
	BATADV_CNT_TT_ROAM_ADV_TX,
	BATADV_CNT_TT_ROAM_ADV_RX,
354 355 356 357 358 359
#ifdef CONFIG_BATMAN_ADV_DAT
	BATADV_CNT_DAT_GET_TX,
	BATADV_CNT_DAT_GET_RX,
	BATADV_CNT_DAT_PUT_TX,
	BATADV_CNT_DAT_PUT_RX,
	BATADV_CNT_DAT_CACHED_REPLY_TX,
360 361 362 363 364 365
#endif
#ifdef CONFIG_BATMAN_ADV_NC
	BATADV_CNT_NC_CODE,
	BATADV_CNT_NC_CODE_BYTES,
	BATADV_CNT_NC_RECODE,
	BATADV_CNT_NC_RECODE_BYTES,
366
	BATADV_CNT_NC_BUFFER,
367 368 369 370
	BATADV_CNT_NC_DECODE,
	BATADV_CNT_NC_DECODE_BYTES,
	BATADV_CNT_NC_DECODE_FAILED,
	BATADV_CNT_NC_SNIFFED,
371
#endif
372
	BATADV_CNT_NUM,
373 374
};

375 376 377
/**
 * struct batadv_priv_tt - per mesh interface translation table data
 * @vn: translation table version number
378
 * @ogm_append_cnt: counter of number of OGMs containing the local tt diff
379 380
 * @local_changes: changes registered in an originator interval
 * @changes_list: tracks tt local changes within an originator interval
381 382 383 384 385 386 387 388 389
 * @local_hash: local translation table hash table
 * @global_hash: global translation table hash table
 * @req_list: list of pending & unanswered tt_requests
 * @roam_list: list of the last roaming events of each client limiting the
 *  number of roaming events to avoid route flapping
 * @changes_list_lock: lock protecting changes_list
 * @req_list_lock: lock protecting req_list
 * @roam_list_lock: lock protecting roam_list
 * @local_entry_num: number of entries in the local hash table
390
 * @local_crc: Checksum of the local table, recomputed before sending a new OGM
391 392 393 394
 * @last_changeset: last tt changeset this host has generated
 * @last_changeset_len: length of last tt changeset this host has generated
 * @last_changeset_lock: lock protecting last_changeset & last_changeset_len
 * @work: work queue callback item for translation table purging
395 396 397 398 399 400 401 402 403 404 405 406 407 408
 */
struct batadv_priv_tt {
	atomic_t vn;
	atomic_t ogm_append_cnt;
	atomic_t local_changes;
	struct list_head changes_list;
	struct batadv_hashtable *local_hash;
	struct batadv_hashtable *global_hash;
	struct list_head req_list;
	struct list_head roam_list;
	spinlock_t changes_list_lock; /* protects changes */
	spinlock_t req_list_lock; /* protects req_list */
	spinlock_t roam_list_lock; /* protects roam_list */
	atomic_t local_entry_num;
409
	uint32_t local_crc;
410 411
	unsigned char *last_changeset;
	int16_t last_changeset_len;
412 413
	/* protects last_changeset & last_changeset_len */
	spinlock_t last_changeset_lock;
414 415 416
	struct delayed_work work;
};

417 418 419 420 421 422 423 424 425 426 427 428
/**
 * struct batadv_priv_bla - per mesh interface bridge loope avoidance data
 * @num_requests; number of bla requests in flight
 * @claim_hash: hash table containing mesh nodes this host has claimed
 * @backbone_hash: hash table containing all detected backbone gateways
 * @bcast_duplist: recently received broadcast packets array (for broadcast
 *  duplicate suppression)
 * @bcast_duplist_curr: index of last broadcast packet added to bcast_duplist
 * @bcast_duplist_lock: lock protecting bcast_duplist & bcast_duplist_curr
 * @claim_dest: local claim data (e.g. claim group)
 * @work: work queue callback item for cleanups & bla announcements
 */
429 430
#ifdef CONFIG_BATMAN_ADV_BLA
struct batadv_priv_bla {
431
	atomic_t num_requests;
432 433 434 435
	struct batadv_hashtable *claim_hash;
	struct batadv_hashtable *backbone_hash;
	struct batadv_bcast_duplist_entry bcast_duplist[BATADV_DUPLIST_SIZE];
	int bcast_duplist_curr;
436
	/* protects bcast_duplist & bcast_duplist_curr */
437
	spinlock_t bcast_duplist_lock;
438 439 440 441 442
	struct batadv_bla_claim_dst claim_dest;
	struct delayed_work work;
};
#endif

443 444 445 446 447 448 449 450
/**
 * struct batadv_debug_log - debug logging data
 * @log_buff: buffer holding the logs (ring bufer)
 * @log_start: index of next character to read
 * @log_end: index of next character to write
 * @lock: lock protecting log_buff, log_start & log_end
 * @queue_wait: log reader's wait queue
 */
451 452 453 454 455 456 457 458 459 460
#ifdef CONFIG_BATMAN_ADV_DEBUG
struct batadv_priv_debug_log {
	char log_buff[BATADV_LOG_BUF_LEN];
	unsigned long log_start;
	unsigned long log_end;
	spinlock_t lock; /* protects log_buff, log_start and log_end */
	wait_queue_head_t queue_wait;
};
#endif

461 462 463 464 465
/**
 * struct batadv_priv_gw - per mesh interface gateway data
 * @list: list of available gateway nodes
 * @list_lock: lock protecting gw_list & curr_gw
 * @curr_gw: pointer to currently selected gateway node
466 467
 * @bandwidth_down: advertised uplink download bandwidth (if gw_mode server)
 * @bandwidth_up: advertised uplink upload bandwidth (if gw_mode server)
468 469
 * @reselect: bool indicating a gateway re-selection is in progress
 */
470 471
struct batadv_priv_gw {
	struct hlist_head list;
472
	spinlock_t list_lock; /* protects gw_list & curr_gw */
473
	struct batadv_gw_node __rcu *curr_gw;  /* rcu protected pointer */
474 475
	atomic_t bandwidth_down;
	atomic_t bandwidth_up;
476 477 478
	atomic_t reselect;
};

479 480 481 482 483 484 485 486 487 488 489 490 491 492
/**
 * struct batadv_priv_tvlv - per mesh interface tvlv data
 * @container_list: list of registered tvlv containers to be sent with each OGM
 * @handler_list: list of the various tvlv content handlers
 * @container_list_lock: protects tvlv container list access
 * @handler_list_lock: protects handler list access
 */
struct batadv_priv_tvlv {
	struct hlist_head container_list;
	struct hlist_head handler_list;
	spinlock_t container_list_lock; /* protects container_list */
	spinlock_t handler_list_lock; /* protects handler_list */
};

493 494 495
/**
 * struct batadv_priv_dat - per mesh interface DAT private data
 * @addr: node DAT address
496 497
 * @hash: hashtable representing the local ARP cache
 * @work: work queue callback item for cache purging
498
 */
499
#ifdef CONFIG_BATMAN_ADV_DAT
500 501
struct batadv_priv_dat {
	batadv_dat_addr_t addr;
502 503
	struct batadv_hashtable *hash;
	struct delayed_work work;
504
};
505
#endif
506

507 508 509
/**
 * struct batadv_priv_nc - per mesh interface network coding private data
 * @work: work queue callback item for cleanup
510 511
 * @debug_dir: dentry for nc subdir in batman-adv directory in debugfs
 * @min_tq: only consider neighbors for encoding if neigh_tq > min_tq
512
 * @max_fwd_delay: maximum packet forward delay to allow coding of packets
513
 * @max_buffer_time: buffer time for sniffed packets used to decoding
514
 * @timestamp_fwd_flush: timestamp of last forward packet queue flush
515
 * @timestamp_sniffed_purge: timestamp of last sniffed packet queue purge
516 517 518
 * @coding_hash: Hash table used to buffer skbs while waiting for another
 *  incoming skb to code it with. Skbs are added to the buffer just before being
 *  forwarded in routing.c
519 520 521 522
 * @decoding_hash: Hash table used to buffer skbs that might be needed to decode
 *  a received coded skb. The buffer is used for 1) skbs arriving on the
 *  soft-interface; 2) skbs overheard on the hard-interface; and 3) skbs
 *  forwarded by batman-adv.
523 524 525
 */
struct batadv_priv_nc {
	struct delayed_work work;
526 527
	struct dentry *debug_dir;
	u8 min_tq;
528
	u32 max_fwd_delay;
529
	u32 max_buffer_time;
530
	unsigned long timestamp_fwd_flush;
531
	unsigned long timestamp_sniffed_purge;
532
	struct batadv_hashtable *coding_hash;
533
	struct batadv_hashtable *decoding_hash;
534 535
};

536 537 538
/**
 * struct batadv_priv - per mesh interface data
 * @mesh_state: current status of the mesh (inactive/active/deactivating)
539
 * @soft_iface: net device which holds this struct as private data
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
 * @stats: structure holding the data for the ndo_get_stats() call
 * @bat_counters: mesh internal traffic statistic counters (see batadv_counters)
 * @aggregated_ogms: bool indicating whether OGM aggregation is enabled
 * @bonding: bool indicating whether traffic bonding is enabled
 * @fragmentation: bool indicating whether traffic fragmentation is enabled
 * @ap_isolation: bool indicating whether ap isolation is enabled
 * @bridge_loop_avoidance: bool indicating whether bridge loop avoidance is
 *  enabled
 * @distributed_arp_table: bool indicating whether distributed ARP table is
 *  enabled
 * @gw_mode: gateway operation: off, client or server (see batadv_gw_modes)
 * @gw_sel_class: gateway selection class (applies if gw_mode client)
 * @orig_interval: OGM broadcast interval in milliseconds
 * @hop_penalty: penalty which will be applied to an OGM's tq-field on every hop
 * @log_level: configured log level (see batadv_dbg_level)
 * @bcast_seqno: last sent broadcast packet sequence number
 * @bcast_queue_left: number of remaining buffered broadcast packet slots
 * @batman_queue_left: number of remaining OGM packet slots
 * @num_ifaces: number of interfaces assigned to this mesh interface
 * @mesh_obj: kobject for sysfs mesh subdirectory
 * @debug_dir: dentry for debugfs batman-adv subdirectory
 * @forw_bat_list: list of aggregated OGMs that will be forwarded
 * @forw_bcast_list: list of broadcast packets that will be rebroadcasted
 * @orig_hash: hash table containing mesh participants (orig nodes)
 * @forw_bat_list_lock: lock protecting forw_bat_list
 * @forw_bcast_list_lock: lock protecting forw_bcast_list
 * @orig_work: work queue callback item for orig node purging
567
 * @cleanup_work: work queue callback item for soft interface deinit
568 569 570 571 572 573 574
 * @primary_if: one of the hard interfaces assigned to this mesh interface
 *  becomes the primary interface
 * @bat_algo_ops: routing algorithm used by this mesh interface
 * @bla: bridge loope avoidance data
 * @debug_log: holding debug logging relevant data
 * @gw: gateway data
 * @tt: translation table data
575
 * @tvlv: type-version-length-value data
576
 * @dat: distributed arp table data
577 578
 * @network_coding: bool indicating whether network coding is enabled
 * @batadv_priv_nc: network coding data
579
 */
580
struct batadv_priv {
581
	atomic_t mesh_state;
582
	struct net_device *soft_iface;
583
	struct net_device_stats stats;
584
	uint64_t __percpu *bat_counters; /* Per cpu counters */
585 586 587 588
	atomic_t aggregated_ogms;
	atomic_t bonding;
	atomic_t fragmentation;
	atomic_t ap_isolation;
589
#ifdef CONFIG_BATMAN_ADV_BLA
590
	atomic_t bridge_loop_avoidance;
591
#endif
592
#ifdef CONFIG_BATMAN_ADV_DAT
593
	atomic_t distributed_arp_table;
594
#endif
595 596 597 598
	atomic_t gw_mode;
	atomic_t gw_sel_class;
	atomic_t orig_interval;
	atomic_t hop_penalty;
599
#ifdef CONFIG_BATMAN_ADV_DEBUG
600
	atomic_t log_level;
601
#endif
602 603 604 605 606 607 608 609
	atomic_t bcast_seqno;
	atomic_t bcast_queue_left;
	atomic_t batman_queue_left;
	char num_ifaces;
	struct kobject *mesh_obj;
	struct dentry *debug_dir;
	struct hlist_head forw_bat_list;
	struct hlist_head forw_bcast_list;
610
	struct batadv_hashtable *orig_hash;
611
	spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
612
	spinlock_t forw_bcast_list_lock; /* protects forw_bcast_list */
613
	struct delayed_work orig_work;
614
	struct work_struct cleanup_work;
615 616
	struct batadv_hard_iface __rcu *primary_if;  /* rcu protected pointer */
	struct batadv_algo_ops *bat_algo_ops;
617 618
#ifdef CONFIG_BATMAN_ADV_BLA
	struct batadv_priv_bla bla;
619 620 621
#endif
#ifdef CONFIG_BATMAN_ADV_DEBUG
	struct batadv_priv_debug_log *debug_log;
622 623 624
#endif
	struct batadv_priv_gw gw;
	struct batadv_priv_tt tt;
625
	struct batadv_priv_tvlv tvlv;
626
#ifdef CONFIG_BATMAN_ADV_DAT
627
	struct batadv_priv_dat dat;
628
#endif
629 630 631 632
#ifdef CONFIG_BATMAN_ADV_NC
	atomic_t network_coding;
	struct batadv_priv_nc nc;
#endif /* CONFIG_BATMAN_ADV_NC */
633 634
};

635 636 637 638 639 640 641 642 643
/**
 * struct batadv_socket_client - layer2 icmp socket client data
 * @queue_list: packet queue for packets destined for this socket client
 * @queue_len: number of packets in the packet queue (queue_list)
 * @index: socket client's index in the batadv_socket_client_hash
 * @lock: lock protecting queue_list, queue_len & index
 * @queue_wait: socket client's wait queue
 * @bat_priv: pointer to soft_iface this client belongs to
 */
644
struct batadv_socket_client {
645 646 647
	struct list_head queue_list;
	unsigned int queue_len;
	unsigned char index;
648
	spinlock_t lock; /* protects queue_list, queue_len & index */
649
	wait_queue_head_t queue_wait;
650
	struct batadv_priv *bat_priv;
651 652
};

653 654 655 656 657 658
/**
 * struct batadv_socket_packet - layer2 icmp packet for socket client
 * @list: list node for batadv_socket_client::queue_list
 * @icmp_len: size of the layer2 icmp packet
 * @icmp_packet: layer2 icmp packet
 */
659
struct batadv_socket_packet {
660 661
	struct list_head list;
	size_t icmp_len;
662
	struct batadv_icmp_packet_rr icmp_packet;
663 664
};

665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
/**
 * struct batadv_bla_backbone_gw - batman-adv gateway bridged into the LAN
 * @orig: originator address of backbone node (mac address of primary iface)
 * @vid: vlan id this gateway was detected on
 * @hash_entry: hlist node for batadv_priv_bla::backbone_hash
 * @bat_priv: pointer to soft_iface this backbone gateway belongs to
 * @lasttime: last time we heard of this backbone gw
 * @wait_periods: grace time for bridge forward delays and bla group forming at
 *  bootup phase - no bcast traffic is formwared until it has elapsed
 * @request_sent: if this bool is set to true we are out of sync with this
 *  backbone gateway - no bcast traffic is formwared until the situation was
 *  resolved
 * @crc: crc16 checksum over all claims
 * @refcount: number of contexts the object is used
 * @rcu: struct used for freeing in an RCU-safe manner
 */
681
#ifdef CONFIG_BATMAN_ADV_BLA
682
struct batadv_bla_backbone_gw {
683
	uint8_t orig[ETH_ALEN];
684
	unsigned short vid;
685 686
	struct hlist_node hash_entry;
	struct batadv_priv *bat_priv;
687
	unsigned long lasttime;
688 689
	atomic_t wait_periods;
	atomic_t request_sent;
690
	uint16_t crc;
691 692 693 694
	atomic_t refcount;
	struct rcu_head rcu;
};

695 696 697 698 699 700 701 702 703 704
/**
 * struct batadv_bla_claim - claimed non-mesh client structure
 * @addr: mac address of claimed non-mesh client
 * @vid: vlan id this client was detected on
 * @batadv_bla_backbone_gw: pointer to backbone gw claiming this client
 * @lasttime: last time we heard of claim (locals only)
 * @hash_entry: hlist node for batadv_priv_bla::claim_hash
 * @refcount: number of contexts the object is used
 * @rcu: struct used for freeing in an RCU-safe manner
 */
705
struct batadv_bla_claim {
706
	uint8_t addr[ETH_ALEN];
707
	unsigned short vid;
708
	struct batadv_bla_backbone_gw *backbone_gw;
709 710
	unsigned long lasttime;
	struct hlist_node hash_entry;
711 712 713 714 715
	struct rcu_head rcu;
	atomic_t refcount;
};
#endif

716 717 718 719 720 721 722 723 724 725
/**
 * struct batadv_tt_common_entry - tt local & tt global common data
 * @addr: mac address of non-mesh client
 * @hash_entry: hlist node for batadv_priv_tt::local_hash or for
 *  batadv_priv_tt::global_hash
 * @flags: various state handling flags (see batadv_tt_client_flags)
 * @added_at: timestamp used for purging stale tt common entries
 * @refcount: number of contexts the object is used
 * @rcu: struct used for freeing in an RCU-safe manner
 */
726
struct batadv_tt_common_entry {
727
	uint8_t addr[ETH_ALEN];
728
	struct hlist_node hash_entry;
729
	uint16_t flags;
730
	unsigned long added_at;
731 732
	atomic_t refcount;
	struct rcu_head rcu;
733 734
};

735 736 737 738 739
/**
 * struct batadv_tt_local_entry - translation table local entry data
 * @common: general translation table data
 * @last_seen: timestamp used for purging stale tt local entries
 */
740 741
struct batadv_tt_local_entry {
	struct batadv_tt_common_entry common;
742 743 744
	unsigned long last_seen;
};

745 746 747 748 749 750 751
/**
 * struct batadv_tt_global_entry - translation table global entry data
 * @common: general translation table data
 * @orig_list: list of orig nodes announcing this non-mesh client
 * @list_lock: lock protecting orig_list
 * @roam_at: time at which TT_GLOBAL_ROAM was set
 */
752 753
struct batadv_tt_global_entry {
	struct batadv_tt_common_entry common;
754
	struct hlist_head orig_list;
755 756
	spinlock_t list_lock;	/* protects orig_list */
	unsigned long roam_at;
757 758
};

759 760 761 762 763 764 765 766
/**
 * struct batadv_tt_orig_list_entry - orig node announcing a non-mesh client
 * @orig_node: pointer to orig node announcing this non-mesh client
 * @ttvn: translation table version number which added the non-mesh client
 * @list: list node for batadv_tt_global_entry::orig_list
 * @refcount: number of contexts the object is used
 * @rcu: struct used for freeing in an RCU-safe manner
 */
767 768
struct batadv_tt_orig_list_entry {
	struct batadv_orig_node *orig_node;
769
	uint8_t ttvn;
770
	struct hlist_node list;
771
	atomic_t refcount;
772
	struct rcu_head rcu;
773 774
};

775 776 777 778 779
/**
 * struct batadv_tt_change_node - structure for tt changes occured
 * @list: list node for batadv_priv_tt::changes_list
 * @change: holds the actual translation table diff data
 */
780
struct batadv_tt_change_node {
781
	struct list_head list;
782
	struct batadv_tvlv_tt_change change;
783 784
};

785 786 787 788 789 790
/**
 * struct batadv_tt_req_node - data to keep track of the tt requests in flight
 * @addr: mac address address of the originator this request was sent to
 * @issued_at: timestamp used for purging stale tt requests
 * @list: list node for batadv_priv_tt::req_list
 */
791
struct batadv_tt_req_node {
792 793 794 795 796
	uint8_t addr[ETH_ALEN];
	unsigned long issued_at;
	struct list_head list;
};

797 798 799 800 801 802 803 804
/**
 * struct batadv_tt_roam_node - roaming client data
 * @addr: mac address of the client in the roaming phase
 * @counter: number of allowed roaming events per client within a single
 *  OGM interval (changes are committed with each OGM)
 * @first_time: timestamp used for purging stale roaming node entries
 * @list: list node for batadv_priv_tt::roam_list
 */
805
struct batadv_tt_roam_node {
806 807 808 809 810 811
	uint8_t addr[ETH_ALEN];
	atomic_t counter;
	unsigned long first_time;
	struct list_head list;
};

812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829
/**
 * struct batadv_nc_node - network coding node
 * @list: next and prev pointer for the list handling
 * @addr: the node's mac address
 * @refcount: number of contexts the object is used by
 * @rcu: struct used for freeing in an RCU-safe manner
 * @orig_node: pointer to corresponding orig node struct
 * @last_seen: timestamp of last ogm received from this node
 */
struct batadv_nc_node {
	struct list_head list;
	uint8_t addr[ETH_ALEN];
	atomic_t refcount;
	struct rcu_head rcu;
	struct batadv_orig_node *orig_node;
	unsigned long last_seen;
};

830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
/**
 * struct batadv_nc_path - network coding path
 * @hash_entry: next and prev pointer for the list handling
 * @rcu: struct used for freeing in an RCU-safe manner
 * @refcount: number of contexts the object is used by
 * @packet_list: list of buffered packets for this path
 * @packet_list_lock: access lock for packet list
 * @next_hop: next hop (destination) of path
 * @prev_hop: previous hop (source) of path
 * @last_valid: timestamp for last validation of path
 */
struct batadv_nc_path {
	struct hlist_node hash_entry;
	struct rcu_head rcu;
	atomic_t refcount;
	struct list_head packet_list;
	spinlock_t packet_list_lock; /* Protects packet_list */
	uint8_t next_hop[ETH_ALEN];
	uint8_t prev_hop[ETH_ALEN];
	unsigned long last_valid;
};

/**
 * struct batadv_nc_packet - network coding packet used when coding and
 *  decoding packets
 * @list: next and prev pointer for the list handling
 * @packet_id: crc32 checksum of skb data
 * @timestamp: field containing the info when the packet was added to path
 * @neigh_node: pointer to original next hop neighbor of skb
 * @skb: skb which can be encoded or used for decoding
 * @nc_path: pointer to path this nc packet is attached to
 */
struct batadv_nc_packet {
	struct list_head list;
	__be32 packet_id;
	unsigned long timestamp;
	struct batadv_neigh_node *neigh_node;
	struct sk_buff *skb;
	struct batadv_nc_path *nc_path;
};

871 872 873 874 875 876 877 878 879 880
/**
 * batadv_skb_cb - control buffer structure used to store private data relevant
 *  to batman-adv in the skb->cb buffer in skbs.
 * @decoded: Marks a skb as decoded, which is checked when searching for coding
 *  opportunities in network-coding.c
 */
struct batadv_skb_cb {
	bool decoded;
};

881 882 883 884 885 886 887 888 889 890 891 892 893
/**
 * struct batadv_forw_packet - structure for bcast packets to be sent/forwarded
 * @list: list node for batadv_socket_client::queue_list
 * @send_time: execution time for delayed_work (packet sending)
 * @own: bool for locally generated packets (local OGMs are re-scheduled after
 *  sending)
 * @skb: bcast packet's skb buffer
 * @packet_len: size of aggregated OGM packet inside the skb buffer
 * @direct_link_flags: direct link flags for aggregated OGM packets
 * @num_packets: counter for bcast packet retransmission
 * @delayed_work: work queue callback item for packet sending
 * @if_incoming: pointer incoming hard-iface or primary iface if locally
 *  generated packet
894
 */
895
struct batadv_forw_packet {
896 897 898 899 900 901 902 903
	struct hlist_node list;
	unsigned long send_time;
	uint8_t own;
	struct sk_buff *skb;
	uint16_t packet_len;
	uint32_t direct_link_flags;
	uint8_t num_packets;
	struct delayed_work delayed_work;
904
	struct batadv_hard_iface *if_incoming;
905 906
};

907 908 909 910 911 912 913 914 915 916 917 918
/**
 * struct batadv_algo_ops - mesh algorithm callbacks
 * @list: list node for the batadv_algo_list
 * @name: name of the algorithm
 * @bat_iface_enable: init routing info when hard-interface is enabled
 * @bat_iface_disable: de-init routing info when hard-interface is disabled
 * @bat_iface_update_mac: (re-)init mac addresses of the protocol information
 *  belonging to this hard-interface
 * @bat_primary_iface_set: called when primary interface is selected / changed
 * @bat_ogm_schedule: prepare a new outgoing OGM for the send queue
 * @bat_ogm_emit: send scheduled OGM
 */
919
struct batadv_algo_ops {
920 921
	struct hlist_node list;
	char *name;
922 923 924 925 926 927
	int (*bat_iface_enable)(struct batadv_hard_iface *hard_iface);
	void (*bat_iface_disable)(struct batadv_hard_iface *hard_iface);
	void (*bat_iface_update_mac)(struct batadv_hard_iface *hard_iface);
	void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);
	void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);
	void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
928 929
};

930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
/**
 * struct batadv_dat_entry - it is a single entry of batman-adv ARP backend. It
 * is used to stored ARP entries needed for the global DAT cache
 * @ip: the IPv4 corresponding to this DAT/ARP entry
 * @mac_addr: the MAC address associated to the stored IPv4
 * @last_update: time in jiffies when this entry was refreshed last time
 * @hash_entry: hlist node for batadv_priv_dat::hash
 * @refcount: number of contexts the object is used
 * @rcu: struct used for freeing in an RCU-safe manner
 */
struct batadv_dat_entry {
	__be32 ip;
	uint8_t mac_addr[ETH_ALEN];
	unsigned long last_update;
	struct hlist_node hash_entry;
	atomic_t refcount;
	struct rcu_head rcu;
};

949 950 951 952 953 954 955 956 957 958 959 960 961
/**
 * struct batadv_dat_candidate - candidate destination for DAT operations
 * @type: the type of the selected candidate. It can one of the following:
 *	  - BATADV_DAT_CANDIDATE_NOT_FOUND
 *	  - BATADV_DAT_CANDIDATE_ORIG
 * @orig_node: if type is BATADV_DAT_CANDIDATE_ORIG this field points to the
 *	       corresponding originator node structure
 */
struct batadv_dat_candidate {
	int type;
	struct batadv_orig_node *orig_node;
};

962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
/**
 * struct batadv_tvlv_container - container for tvlv appended to OGMs
 * @list: hlist node for batadv_priv_tvlv::container_list
 * @tvlv_hdr: tvlv header information needed to construct the tvlv
 * @value_len: length of the buffer following this struct which contains
 *  the actual tvlv payload
 * @refcount: number of contexts the object is used
 */
struct batadv_tvlv_container {
	struct hlist_node list;
	struct batadv_tvlv_hdr tvlv_hdr;
	atomic_t refcount;
};

/**
 * struct batadv_tvlv_handler - handler for specific tvlv type and version
 * @list: hlist node for batadv_priv_tvlv::handler_list
 * @ogm_handler: handler callback which is given the tvlv payload to process on
 *  incoming OGM packets
 * @unicast_handler: handler callback which is given the tvlv payload to process
 *  on incoming unicast tvlv packets
 * @type: tvlv type this handler feels responsible for
 * @version: tvlv version this handler feels responsible for
 * @flags: tvlv handler flags
 * @refcount: number of contexts the object is used
 * @rcu: struct used for freeing in an RCU-safe manner
 */
struct batadv_tvlv_handler {
	struct hlist_node list;
	void (*ogm_handler)(struct batadv_priv *bat_priv,
			    struct batadv_orig_node *orig,
			    uint8_t flags,
			    void *tvlv_value, uint16_t tvlv_value_len);
	int (*unicast_handler)(struct batadv_priv *bat_priv,
			       uint8_t *src, uint8_t *dst,
			       void *tvlv_value, uint16_t tvlv_value_len);
	uint8_t type;
	uint8_t version;
	uint8_t flags;
	atomic_t refcount;
	struct rcu_head rcu;
};

/**
 * enum batadv_tvlv_handler_flags - tvlv handler flags definitions
 * @BATADV_TVLV_HANDLER_OGM_CIFNOTFND: tvlv ogm processing function will call
 *  this handler even if its type was not found (with no data)
 * @BATADV_TVLV_HANDLER_OGM_CALLED: interval tvlv handling flag - the API marks
 *  a handler as being called, so it won't be called if the
 *  BATADV_TVLV_HANDLER_OGM_CIFNOTFND flag was set
 */
enum batadv_tvlv_handler_flags {
	BATADV_TVLV_HANDLER_OGM_CIFNOTFND = BIT(1),
	BATADV_TVLV_HANDLER_OGM_CALLED = BIT(2),
};

1018
#endif /* _NET_BATMAN_ADV_TYPES_H_ */