batman-adv: Distributed ARP Table - create DHT helper functions
[linux-2.6-block.git] / net / batman-adv / types.h
CommitLineData
9cfc7bd6 1/* Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
c6c8fea2
SE
2 *
3 * Marek Lindner, Simon Wunderlich
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA
c6c8fea2
SE
18 */
19
c6c8fea2
SE
20#ifndef _NET_BATMAN_ADV_TYPES_H_
21#define _NET_BATMAN_ADV_TYPES_H_
22
23#include "packet.h"
24#include "bitarray.h"
c11fdfae 25#include <linux/kernel.h>
c6c8fea2 26
c11fdfae 27#define BATADV_HEADER_LEN \
96412690
SE
28 (ETH_HLEN + max(sizeof(struct batadv_unicast_packet), \
29 sizeof(struct batadv_bcast_packet)))
c6c8fea2 30
785ea114
AQ
31/* batadv_dat_addr_t is the type used for all DHT addresses. If it is changed,
32 * BATADV_DAT_ADDR_MAX is changed as well.
33 *
34 * *Please be careful: batadv_dat_addr_t must be UNSIGNED*
35 */
36#define batadv_dat_addr_t uint16_t
37
14511519
ML
38/**
39 * struct batadv_hard_iface_bat_iv - per hard interface B.A.T.M.A.N. IV data
40 * @ogm_buff: buffer holding the OGM packet
41 * @ogm_buff_len: length of the OGM packet buffer
42 * @ogm_seqno: OGM sequence number - used to identify each OGM
43 */
44struct batadv_hard_iface_bat_iv {
45 unsigned char *ogm_buff;
46 int ogm_buff_len;
47 atomic_t ogm_seqno;
48};
49
56303d34 50struct batadv_hard_iface {
c6c8fea2
SE
51 struct list_head list;
52 int16_t if_num;
53 char if_status;
54 struct net_device *net_dev;
c6c8fea2 55 atomic_t frag_seqno;
c6c8fea2 56 struct kobject *hardif_obj;
ed75ccbe 57 atomic_t refcount;
c6c8fea2
SE
58 struct packet_type batman_adv_ptype;
59 struct net_device *soft_iface;
60 struct rcu_head rcu;
14511519 61 struct batadv_hard_iface_bat_iv bat_iv;
c6c8fea2
SE
62};
63
2c53040f
BH
64/**
65 * struct batadv_orig_node - structure for orig_list maintaining nodes of mesh
c6c8fea2 66 * @primary_addr: hosts primary interface address
d7b2a97e 67 * @last_seen: when last packet from this node was received
c6c8fea2
SE
68 * @bcast_seqno_reset: time when the broadcast seqno window was reset
69 * @batman_seqno_reset: time when the batman seqno window was reset
70 * @gw_flags: flags related to gateway class
71 * @flags: for now only VIS_SERVER flag
015758d0 72 * @last_real_seqno: last and best known sequence number
c6c8fea2
SE
73 * @last_ttl: ttl of last received packet
74 * @last_bcast_seqno: last broadcast sequence number received by this host
75 *
76 * @candidates: how many candidates are available
77 * @selected: next bonding candidate
78 */
56303d34 79struct batadv_orig_node {
c6c8fea2
SE
80 uint8_t orig[ETH_ALEN];
81 uint8_t primary_addr[ETH_ALEN];
56303d34 82 struct batadv_neigh_node __rcu *router; /* rcu protected pointer */
785ea114 83 batadv_dat_addr_t dat_addr;
c6c8fea2
SE
84 unsigned long *bcast_own;
85 uint8_t *bcast_own_sum;
d7b2a97e 86 unsigned long last_seen;
c6c8fea2
SE
87 unsigned long bcast_seqno_reset;
88 unsigned long batman_seqno_reset;
89 uint8_t gw_flags;
90 uint8_t flags;
a73105b8
AQ
91 atomic_t last_ttvn; /* last seen translation table version number */
92 uint16_t tt_crc;
2dafb49d
AQ
93 unsigned char *tt_buff;
94 int16_t tt_buff_len;
a73105b8
AQ
95 spinlock_t tt_buff_lock; /* protects tt_buff */
96 atomic_t tt_size;
17071578 97 bool tt_initialised;
cc47f66e
AQ
98 /* The tt_poss_change flag is used to detect an ongoing roaming phase.
99 * If true, then I sent a Roaming_adv to this orig_node and I have to
100 * inspect every packet directed to it to check whether it is still
101 * the true destination or not. This flag will be reset to false as
9cfc7bd6
SE
102 * soon as I receive a new TTVN from this orig_node
103 */
cc47f66e 104 bool tt_poss_change;
c6c8fea2
SE
105 uint32_t last_real_seqno;
106 uint8_t last_ttl;
42d0b044 107 DECLARE_BITMAP(bcast_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
c6c8fea2 108 uint32_t last_bcast_seqno;
9591a79f 109 struct hlist_head neigh_list;
c6c8fea2 110 struct list_head frag_list;
e1a5382f 111 spinlock_t neigh_list_lock; /* protects neigh_list and router */
7b36e8ee
ML
112 atomic_t refcount;
113 struct rcu_head rcu;
7aadf889 114 struct hlist_node hash_entry;
56303d34 115 struct batadv_priv *bat_priv;
c6c8fea2 116 unsigned long last_frag_packet;
6e215fd8 117 /* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
9cfc7bd6
SE
118 * neigh_node->real_bits, neigh_node->real_packet_count
119 */
6e215fd8
SE
120 spinlock_t ogm_cnt_lock;
121 /* bcast_seqno_lock protects bcast_bits, last_bcast_seqno */
122 spinlock_t bcast_seqno_lock;
a73105b8 123 spinlock_t tt_list_lock; /* protects tt_list */
a4c135c5
SW
124 atomic_t bond_candidates;
125 struct list_head bond_list;
c6c8fea2
SE
126};
127
56303d34 128struct batadv_gw_node {
c6c8fea2 129 struct hlist_node list;
56303d34 130 struct batadv_orig_node *orig_node;
c6c8fea2 131 unsigned long deleted;
25b6d3c1 132 atomic_t refcount;
c6c8fea2
SE
133 struct rcu_head rcu;
134};
135
56303d34 136/* batadv_neigh_node
d7b2a97e 137 * @last_seen: when last packet via this neighbor was received
c6c8fea2 138 */
56303d34 139struct batadv_neigh_node {
9591a79f 140 struct hlist_node list;
c6c8fea2
SE
141 uint8_t addr[ETH_ALEN];
142 uint8_t real_packet_count;
42d0b044 143 uint8_t tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE];
c6c8fea2
SE
144 uint8_t tq_index;
145 uint8_t tq_avg;
146 uint8_t last_ttl;
a4c135c5 147 struct list_head bonding_list;
d7b2a97e 148 unsigned long last_seen;
42d0b044 149 DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
44524fcd 150 atomic_t refcount;
f987ed6e 151 struct rcu_head rcu;
56303d34
SE
152 struct batadv_orig_node *orig_node;
153 struct batadv_hard_iface *if_incoming;
e3b0d0de 154 spinlock_t lq_update_lock; /* protects: tq_recv, tq_index */
c6c8fea2
SE
155};
156
7a5cc242 157#ifdef CONFIG_BATMAN_ADV_BLA
56303d34 158struct batadv_bcast_duplist_entry {
fe2da6ff
SW
159 uint8_t orig[ETH_ALEN];
160 uint16_t crc;
161 unsigned long entrytime;
162};
7a5cc242 163#endif
c6c8fea2 164
d69909d2 165enum batadv_counters {
1c9b0550
ML
166 BATADV_CNT_TX,
167 BATADV_CNT_TX_BYTES,
168 BATADV_CNT_TX_DROPPED,
169 BATADV_CNT_RX,
170 BATADV_CNT_RX_BYTES,
d69909d2
SE
171 BATADV_CNT_FORWARD,
172 BATADV_CNT_FORWARD_BYTES,
173 BATADV_CNT_MGMT_TX,
174 BATADV_CNT_MGMT_TX_BYTES,
175 BATADV_CNT_MGMT_RX,
176 BATADV_CNT_MGMT_RX_BYTES,
177 BATADV_CNT_TT_REQUEST_TX,
178 BATADV_CNT_TT_REQUEST_RX,
179 BATADV_CNT_TT_RESPONSE_TX,
180 BATADV_CNT_TT_RESPONSE_RX,
181 BATADV_CNT_TT_ROAM_ADV_TX,
182 BATADV_CNT_TT_ROAM_ADV_RX,
183 BATADV_CNT_NUM,
f8214865
MH
184};
185
807736f6
SE
186/**
187 * struct batadv_priv_tt - per mesh interface translation table data
188 * @vn: translation table version number
189 * @local_changes: changes registered in an originator interval
190 * @poss_change: Detect an ongoing roaming phase. If true, then this node
191 * received a roaming_adv and has to inspect every packet directed to it to
192 * check whether it still is the true destination or not. This flag will be
193 * reset to false as soon as the this node's ttvn is increased
194 * @changes_list: tracks tt local changes within an originator interval
195 * @req_list: list of pending tt_requests
196 * @local_crc: Checksum of the local table, recomputed before sending a new OGM
197 */
198struct batadv_priv_tt {
199 atomic_t vn;
200 atomic_t ogm_append_cnt;
201 atomic_t local_changes;
202 bool poss_change;
203 struct list_head changes_list;
204 struct batadv_hashtable *local_hash;
205 struct batadv_hashtable *global_hash;
206 struct list_head req_list;
207 struct list_head roam_list;
208 spinlock_t changes_list_lock; /* protects changes */
209 spinlock_t req_list_lock; /* protects req_list */
210 spinlock_t roam_list_lock; /* protects roam_list */
211 atomic_t local_entry_num;
212 uint16_t local_crc;
213 unsigned char *last_changeset;
214 int16_t last_changeset_len;
215 spinlock_t last_changeset_lock; /* protects last_changeset */
216 struct delayed_work work;
217};
218
219#ifdef CONFIG_BATMAN_ADV_BLA
220struct batadv_priv_bla {
221 atomic_t num_requests; /* number of bla requests in flight */
222 struct batadv_hashtable *claim_hash;
223 struct batadv_hashtable *backbone_hash;
224 struct batadv_bcast_duplist_entry bcast_duplist[BATADV_DUPLIST_SIZE];
225 int bcast_duplist_curr;
7dac7b76
LL
226 /* protects bcast_duplist and bcast_duplist_curr */
227 spinlock_t bcast_duplist_lock;
807736f6
SE
228 struct batadv_bla_claim_dst claim_dest;
229 struct delayed_work work;
230};
231#endif
232
233struct batadv_priv_gw {
234 struct hlist_head list;
235 spinlock_t list_lock; /* protects gw_list and curr_gw */
236 struct batadv_gw_node __rcu *curr_gw; /* rcu protected pointer */
237 atomic_t reselect;
238};
239
240struct batadv_priv_vis {
241 struct list_head send_list;
242 struct batadv_hashtable *hash;
243 spinlock_t hash_lock; /* protects hash */
244 spinlock_t list_lock; /* protects info::recv_list */
245 struct delayed_work work;
246 struct batadv_vis_info *my_info;
247};
248
785ea114
AQ
249/**
250 * struct batadv_priv_dat - per mesh interface DAT private data
251 * @addr: node DAT address
252 */
253struct batadv_priv_dat {
254 batadv_dat_addr_t addr;
255};
256
56303d34 257struct batadv_priv {
c6c8fea2
SE
258 atomic_t mesh_state;
259 struct net_device_stats stats;
f8214865 260 uint64_t __percpu *bat_counters; /* Per cpu counters */
c6c8fea2
SE
261 atomic_t aggregated_ogms; /* boolean */
262 atomic_t bonding; /* boolean */
263 atomic_t fragmentation; /* boolean */
59b699cd 264 atomic_t ap_isolation; /* boolean */
23721387 265 atomic_t bridge_loop_avoidance; /* boolean */
c6c8fea2
SE
266 atomic_t vis_mode; /* VIS_TYPE_* */
267 atomic_t gw_mode; /* GW_MODE_* */
268 atomic_t gw_sel_class; /* uint */
269 atomic_t gw_bandwidth; /* gw bandwidth */
270 atomic_t orig_interval; /* uint */
271 atomic_t hop_penalty; /* uint */
272 atomic_t log_level; /* uint */
273 atomic_t bcast_seqno;
274 atomic_t bcast_queue_left;
275 atomic_t batman_queue_left;
276 char num_ifaces;
56303d34 277 struct batadv_debug_log *debug_log;
c6c8fea2
SE
278 struct kobject *mesh_obj;
279 struct dentry *debug_dir;
280 struct hlist_head forw_bat_list;
281 struct hlist_head forw_bcast_list;
5bf74e9c 282 struct batadv_hashtable *orig_hash;
c6c8fea2
SE
283 spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
284 spinlock_t forw_bcast_list_lock; /* protects */
c6c8fea2 285 struct delayed_work orig_work;
56303d34 286 struct batadv_hard_iface __rcu *primary_if; /* rcu protected pointer */
56303d34 287 struct batadv_algo_ops *bat_algo_ops;
807736f6
SE
288#ifdef CONFIG_BATMAN_ADV_BLA
289 struct batadv_priv_bla bla;
290#endif
291 struct batadv_priv_gw gw;
292 struct batadv_priv_tt tt;
293 struct batadv_priv_vis vis;
785ea114 294 struct batadv_priv_dat dat;
c6c8fea2
SE
295};
296
56303d34 297struct batadv_socket_client {
c6c8fea2
SE
298 struct list_head queue_list;
299 unsigned int queue_len;
300 unsigned char index;
301 spinlock_t lock; /* protects queue_list, queue_len, index */
302 wait_queue_head_t queue_wait;
56303d34 303 struct batadv_priv *bat_priv;
c6c8fea2
SE
304};
305
56303d34 306struct batadv_socket_packet {
c6c8fea2
SE
307 struct list_head list;
308 size_t icmp_len;
96412690 309 struct batadv_icmp_packet_rr icmp_packet;
c6c8fea2
SE
310};
311
56303d34 312struct batadv_tt_common_entry {
c6c8fea2 313 uint8_t addr[ETH_ALEN];
93840ac4 314 struct hlist_node hash_entry;
5fbc1598 315 uint16_t flags;
30cfd02b 316 unsigned long added_at;
7683fdc1
AQ
317 atomic_t refcount;
318 struct rcu_head rcu;
c6c8fea2
SE
319};
320
56303d34
SE
321struct batadv_tt_local_entry {
322 struct batadv_tt_common_entry common;
48100bac
AQ
323 unsigned long last_seen;
324};
325
56303d34
SE
326struct batadv_tt_global_entry {
327 struct batadv_tt_common_entry common;
db08e6e5
SW
328 struct hlist_head orig_list;
329 spinlock_t list_lock; /* protects the list */
330 unsigned long roam_at; /* time at which TT_GLOBAL_ROAM was set */
331};
332
56303d34
SE
333struct batadv_tt_orig_list_entry {
334 struct batadv_orig_node *orig_node;
a73105b8 335 uint8_t ttvn;
d657e621 336 atomic_t refcount;
db08e6e5
SW
337 struct rcu_head rcu;
338 struct hlist_node list;
c6c8fea2
SE
339};
340
7a5cc242 341#ifdef CONFIG_BATMAN_ADV_BLA
56303d34 342struct batadv_backbone_gw {
23721387
SW
343 uint8_t orig[ETH_ALEN];
344 short vid; /* used VLAN ID */
345 struct hlist_node hash_entry;
56303d34 346 struct batadv_priv *bat_priv;
23721387
SW
347 unsigned long lasttime; /* last time we heard of this backbone gw */
348 atomic_t request_sent;
349 atomic_t refcount;
350 struct rcu_head rcu;
351 uint16_t crc; /* crc checksum over all claims */
352};
353
56303d34 354struct batadv_claim {
23721387
SW
355 uint8_t addr[ETH_ALEN];
356 short vid;
56303d34 357 struct batadv_backbone_gw *backbone_gw;
23721387
SW
358 unsigned long lasttime; /* last time we heard of claim (locals only) */
359 struct rcu_head rcu;
360 atomic_t refcount;
361 struct hlist_node hash_entry;
362};
7a5cc242 363#endif
23721387 364
56303d34 365struct batadv_tt_change_node {
a73105b8 366 struct list_head list;
96412690 367 struct batadv_tt_change change;
a73105b8
AQ
368};
369
56303d34 370struct batadv_tt_req_node {
a73105b8
AQ
371 uint8_t addr[ETH_ALEN];
372 unsigned long issued_at;
373 struct list_head list;
374};
375
56303d34 376struct batadv_tt_roam_node {
cc47f66e
AQ
377 uint8_t addr[ETH_ALEN];
378 atomic_t counter;
379 unsigned long first_time;
380 struct list_head list;
381};
382
9cfc7bd6 383/* forw_packet - structure for forw_list maintaining packets to be
c6c8fea2
SE
384 * send/forwarded
385 */
56303d34 386struct batadv_forw_packet {
c6c8fea2
SE
387 struct hlist_node list;
388 unsigned long send_time;
389 uint8_t own;
390 struct sk_buff *skb;
391 uint16_t packet_len;
392 uint32_t direct_link_flags;
393 uint8_t num_packets;
394 struct delayed_work delayed_work;
56303d34 395 struct batadv_hard_iface *if_incoming;
c6c8fea2
SE
396};
397
398/* While scanning for vis-entries of a particular vis-originator
399 * this list collects its interfaces to create a subgraph/cluster
400 * out of them later
401 */
56303d34 402struct batadv_if_list_entry {
c6c8fea2
SE
403 uint8_t addr[ETH_ALEN];
404 bool primary;
405 struct hlist_node list;
406};
407
56303d34 408struct batadv_debug_log {
42d0b044 409 char log_buff[BATADV_LOG_BUF_LEN];
c6c8fea2
SE
410 unsigned long log_start;
411 unsigned long log_end;
412 spinlock_t lock; /* protects log_buff, log_start and log_end */
413 wait_queue_head_t queue_wait;
414};
415
56303d34 416struct batadv_frag_packet_list_entry {
c6c8fea2
SE
417 struct list_head list;
418 uint16_t seqno;
419 struct sk_buff *skb;
420};
421
56303d34 422struct batadv_vis_info {
40219672
AQ
423 unsigned long first_seen;
424 /* list of server-neighbors we received a vis-packet
9cfc7bd6
SE
425 * from. we should not reply to them.
426 */
40219672 427 struct list_head recv_list;
c6c8fea2
SE
428 struct list_head send_list;
429 struct kref refcount;
7aadf889 430 struct hlist_node hash_entry;
56303d34 431 struct batadv_priv *bat_priv;
c6c8fea2
SE
432 /* this packet might be part of the vis send queue. */
433 struct sk_buff *skb_packet;
9cfc7bd6 434 /* vis_info may follow here */
aa0adb1a 435} __packed;
c6c8fea2 436
56303d34 437struct batadv_vis_info_entry {
c6c8fea2
SE
438 uint8_t src[ETH_ALEN];
439 uint8_t dest[ETH_ALEN];
2dafb49d 440 uint8_t quality; /* quality = 0 client */
aa0adb1a 441} __packed;
c6c8fea2 442
56303d34 443struct batadv_recvlist_node {
c6c8fea2
SE
444 struct list_head list;
445 uint8_t mac[ETH_ALEN];
446};
447
56303d34 448struct batadv_algo_ops {
1c280471
ML
449 struct hlist_node list;
450 char *name;
c2aca022 451 /* init routing info when hard-interface is enabled */
56303d34 452 int (*bat_iface_enable)(struct batadv_hard_iface *hard_iface);
00a50076 453 /* de-init routing info when hard-interface is disabled */
56303d34 454 void (*bat_iface_disable)(struct batadv_hard_iface *hard_iface);
c3229398
ML
455 /* (re-)init mac addresses of the protocol information
456 * belonging to this hard-interface
457 */
56303d34 458 void (*bat_iface_update_mac)(struct batadv_hard_iface *hard_iface);
cd8b78e7 459 /* called when primary interface is selected / changed */
56303d34 460 void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);
01c4224b 461 /* prepare a new outgoing OGM for the send queue */
56303d34 462 void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);
01c4224b 463 /* send scheduled OGM */
56303d34 464 void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
1c280471
ML
465};
466
785ea114
AQ
467/**
468 * struct batadv_dat_candidate - candidate destination for DAT operations
469 * @type: the type of the selected candidate. It can one of the following:
470 * - BATADV_DAT_CANDIDATE_NOT_FOUND
471 * - BATADV_DAT_CANDIDATE_ORIG
472 * @orig_node: if type is BATADV_DAT_CANDIDATE_ORIG this field points to the
473 * corresponding originator node structure
474 */
475struct batadv_dat_candidate {
476 int type;
477 struct batadv_orig_node *orig_node;
478};
479
c6c8fea2 480#endif /* _NET_BATMAN_ADV_TYPES_H_ */