]> Pileus Git - ~andy/linux/blob - net/batman-adv/types.h
batman-adv: Distributed ARP Table - implement local storage
[~andy/linux] / net / batman-adv / types.h
1 /* Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
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
18  */
19
20 #ifndef _NET_BATMAN_ADV_TYPES_H_
21 #define _NET_BATMAN_ADV_TYPES_H_
22
23 #include "packet.h"
24 #include "bitarray.h"
25 #include <linux/kernel.h>
26
27 #define BATADV_HEADER_LEN \
28         (ETH_HLEN + max(sizeof(struct batadv_unicast_packet), \
29                         sizeof(struct batadv_bcast_packet)))
30
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
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  */
44 struct batadv_hard_iface_bat_iv {
45         unsigned char *ogm_buff;
46         int ogm_buff_len;
47         atomic_t ogm_seqno;
48 };
49
50 struct batadv_hard_iface {
51         struct list_head list;
52         int16_t if_num;
53         char if_status;
54         struct net_device *net_dev;
55         atomic_t frag_seqno;
56         struct kobject *hardif_obj;
57         atomic_t refcount;
58         struct packet_type batman_adv_ptype;
59         struct net_device *soft_iface;
60         struct rcu_head rcu;
61         struct batadv_hard_iface_bat_iv bat_iv;
62 };
63
64 /**
65  *      struct batadv_orig_node - structure for orig_list maintaining nodes of mesh
66  *      @primary_addr: hosts primary interface address
67  *      @last_seen: when last packet from this node was received
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
72  *      @last_real_seqno: last and best known sequence number
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  */
79 struct batadv_orig_node {
80         uint8_t orig[ETH_ALEN];
81         uint8_t primary_addr[ETH_ALEN];
82         struct batadv_neigh_node __rcu *router; /* rcu protected pointer */
83         batadv_dat_addr_t dat_addr;
84         unsigned long *bcast_own;
85         uint8_t *bcast_own_sum;
86         unsigned long last_seen;
87         unsigned long bcast_seqno_reset;
88         unsigned long batman_seqno_reset;
89         uint8_t gw_flags;
90         uint8_t flags;
91         atomic_t last_ttvn; /* last seen translation table version number */
92         uint16_t tt_crc;
93         unsigned char *tt_buff;
94         int16_t tt_buff_len;
95         spinlock_t tt_buff_lock; /* protects tt_buff */
96         atomic_t tt_size;
97         bool tt_initialised;
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
102          * soon as I receive a new TTVN from this orig_node
103          */
104         bool tt_poss_change;
105         uint32_t last_real_seqno;
106         uint8_t last_ttl;
107         DECLARE_BITMAP(bcast_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
108         uint32_t last_bcast_seqno;
109         struct hlist_head neigh_list;
110         struct list_head frag_list;
111         spinlock_t neigh_list_lock; /* protects neigh_list and router */
112         atomic_t refcount;
113         struct rcu_head rcu;
114         struct hlist_node hash_entry;
115         struct batadv_priv *bat_priv;
116         unsigned long last_frag_packet;
117         /* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
118          * neigh_node->real_bits, neigh_node->real_packet_count
119          */
120         spinlock_t ogm_cnt_lock;
121         /* bcast_seqno_lock protects bcast_bits, last_bcast_seqno */
122         spinlock_t bcast_seqno_lock;
123         spinlock_t tt_list_lock; /* protects tt_list */
124         atomic_t bond_candidates;
125         struct list_head bond_list;
126 };
127
128 struct batadv_gw_node {
129         struct hlist_node list;
130         struct batadv_orig_node *orig_node;
131         unsigned long deleted;
132         atomic_t refcount;
133         struct rcu_head rcu;
134 };
135
136 /*      batadv_neigh_node
137  *      @last_seen: when last packet via this neighbor was received
138  */
139 struct batadv_neigh_node {
140         struct hlist_node list;
141         uint8_t addr[ETH_ALEN];
142         uint8_t real_packet_count;
143         uint8_t tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE];
144         uint8_t tq_index;
145         uint8_t tq_avg;
146         uint8_t last_ttl;
147         struct list_head bonding_list;
148         unsigned long last_seen;
149         DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
150         atomic_t refcount;
151         struct rcu_head rcu;
152         struct batadv_orig_node *orig_node;
153         struct batadv_hard_iface *if_incoming;
154         spinlock_t lq_update_lock;      /* protects: tq_recv, tq_index */
155 };
156
157 #ifdef CONFIG_BATMAN_ADV_BLA
158 struct batadv_bcast_duplist_entry {
159         uint8_t orig[ETH_ALEN];
160         uint16_t crc;
161         unsigned long entrytime;
162 };
163 #endif
164
165 enum batadv_counters {
166         BATADV_CNT_TX,
167         BATADV_CNT_TX_BYTES,
168         BATADV_CNT_TX_DROPPED,
169         BATADV_CNT_RX,
170         BATADV_CNT_RX_BYTES,
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,
184 };
185
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  */
198 struct 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
220 struct 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;
226         /* protects bcast_duplist and bcast_duplist_curr */
227         spinlock_t bcast_duplist_lock;
228         struct batadv_bla_claim_dst claim_dest;
229         struct delayed_work work;
230 };
231 #endif
232
233 struct 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
240 struct 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
249 /**
250  * struct batadv_priv_dat - per mesh interface DAT private data
251  * @addr: node DAT address
252  * @hash: hashtable representing the local ARP cache
253  * @work: work queue callback item for cache purging
254  */
255 struct batadv_priv_dat {
256         batadv_dat_addr_t addr;
257         struct batadv_hashtable *hash;
258         struct delayed_work work;
259 };
260
261 struct batadv_priv {
262         atomic_t mesh_state;
263         struct net_device_stats stats;
264         uint64_t __percpu *bat_counters; /* Per cpu counters */
265         atomic_t aggregated_ogms;       /* boolean */
266         atomic_t bonding;               /* boolean */
267         atomic_t fragmentation;         /* boolean */
268         atomic_t ap_isolation;          /* boolean */
269         atomic_t bridge_loop_avoidance; /* boolean */
270         atomic_t vis_mode;              /* VIS_TYPE_* */
271         atomic_t gw_mode;               /* GW_MODE_* */
272         atomic_t gw_sel_class;          /* uint */
273         atomic_t gw_bandwidth;          /* gw bandwidth */
274         atomic_t orig_interval;         /* uint */
275         atomic_t hop_penalty;           /* uint */
276         atomic_t log_level;             /* uint */
277         atomic_t bcast_seqno;
278         atomic_t bcast_queue_left;
279         atomic_t batman_queue_left;
280         char num_ifaces;
281         struct batadv_debug_log *debug_log;
282         struct kobject *mesh_obj;
283         struct dentry *debug_dir;
284         struct hlist_head forw_bat_list;
285         struct hlist_head forw_bcast_list;
286         struct batadv_hashtable *orig_hash;
287         spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
288         spinlock_t forw_bcast_list_lock; /* protects  */
289         struct delayed_work orig_work;
290         struct batadv_hard_iface __rcu *primary_if;  /* rcu protected pointer */
291         struct batadv_algo_ops *bat_algo_ops;
292 #ifdef CONFIG_BATMAN_ADV_BLA
293         struct batadv_priv_bla bla;
294 #endif
295         struct batadv_priv_gw gw;
296         struct batadv_priv_tt tt;
297         struct batadv_priv_vis vis;
298         struct batadv_priv_dat dat;
299 };
300
301 struct batadv_socket_client {
302         struct list_head queue_list;
303         unsigned int queue_len;
304         unsigned char index;
305         spinlock_t lock; /* protects queue_list, queue_len, index */
306         wait_queue_head_t queue_wait;
307         struct batadv_priv *bat_priv;
308 };
309
310 struct batadv_socket_packet {
311         struct list_head list;
312         size_t icmp_len;
313         struct batadv_icmp_packet_rr icmp_packet;
314 };
315
316 struct batadv_tt_common_entry {
317         uint8_t addr[ETH_ALEN];
318         struct hlist_node hash_entry;
319         uint16_t flags;
320         unsigned long added_at;
321         atomic_t refcount;
322         struct rcu_head rcu;
323 };
324
325 struct batadv_tt_local_entry {
326         struct batadv_tt_common_entry common;
327         unsigned long last_seen;
328 };
329
330 struct batadv_tt_global_entry {
331         struct batadv_tt_common_entry common;
332         struct hlist_head orig_list;
333         spinlock_t list_lock;   /* protects the list */
334         unsigned long roam_at; /* time at which TT_GLOBAL_ROAM was set */
335 };
336
337 struct batadv_tt_orig_list_entry {
338         struct batadv_orig_node *orig_node;
339         uint8_t ttvn;
340         atomic_t refcount;
341         struct rcu_head rcu;
342         struct hlist_node list;
343 };
344
345 #ifdef CONFIG_BATMAN_ADV_BLA
346 struct batadv_backbone_gw {
347         uint8_t orig[ETH_ALEN];
348         short vid;              /* used VLAN ID */
349         struct hlist_node hash_entry;
350         struct batadv_priv *bat_priv;
351         unsigned long lasttime; /* last time we heard of this backbone gw */
352         atomic_t request_sent;
353         atomic_t refcount;
354         struct rcu_head rcu;
355         uint16_t crc;           /* crc checksum over all claims */
356 };
357
358 struct batadv_claim {
359         uint8_t addr[ETH_ALEN];
360         short vid;
361         struct batadv_backbone_gw *backbone_gw;
362         unsigned long lasttime; /* last time we heard of claim (locals only) */
363         struct rcu_head rcu;
364         atomic_t refcount;
365         struct hlist_node hash_entry;
366 };
367 #endif
368
369 struct batadv_tt_change_node {
370         struct list_head list;
371         struct batadv_tt_change change;
372 };
373
374 struct batadv_tt_req_node {
375         uint8_t addr[ETH_ALEN];
376         unsigned long issued_at;
377         struct list_head list;
378 };
379
380 struct batadv_tt_roam_node {
381         uint8_t addr[ETH_ALEN];
382         atomic_t counter;
383         unsigned long first_time;
384         struct list_head list;
385 };
386
387 /*      forw_packet - structure for forw_list maintaining packets to be
388  *                    send/forwarded
389  */
390 struct batadv_forw_packet {
391         struct hlist_node list;
392         unsigned long send_time;
393         uint8_t own;
394         struct sk_buff *skb;
395         uint16_t packet_len;
396         uint32_t direct_link_flags;
397         uint8_t num_packets;
398         struct delayed_work delayed_work;
399         struct batadv_hard_iface *if_incoming;
400 };
401
402 /* While scanning for vis-entries of a particular vis-originator
403  * this list collects its interfaces to create a subgraph/cluster
404  * out of them later
405  */
406 struct batadv_if_list_entry {
407         uint8_t addr[ETH_ALEN];
408         bool primary;
409         struct hlist_node list;
410 };
411
412 struct batadv_debug_log {
413         char log_buff[BATADV_LOG_BUF_LEN];
414         unsigned long log_start;
415         unsigned long log_end;
416         spinlock_t lock; /* protects log_buff, log_start and log_end */
417         wait_queue_head_t queue_wait;
418 };
419
420 struct batadv_frag_packet_list_entry {
421         struct list_head list;
422         uint16_t seqno;
423         struct sk_buff *skb;
424 };
425
426 struct batadv_vis_info {
427         unsigned long first_seen;
428         /* list of server-neighbors we received a vis-packet
429          * from.  we should not reply to them.
430          */
431         struct list_head recv_list;
432         struct list_head send_list;
433         struct kref refcount;
434         struct hlist_node hash_entry;
435         struct batadv_priv *bat_priv;
436         /* this packet might be part of the vis send queue. */
437         struct sk_buff *skb_packet;
438         /* vis_info may follow here */
439 } __packed;
440
441 struct batadv_vis_info_entry {
442         uint8_t  src[ETH_ALEN];
443         uint8_t  dest[ETH_ALEN];
444         uint8_t  quality;       /* quality = 0 client */
445 } __packed;
446
447 struct batadv_recvlist_node {
448         struct list_head list;
449         uint8_t mac[ETH_ALEN];
450 };
451
452 struct batadv_algo_ops {
453         struct hlist_node list;
454         char *name;
455         /* init routing info when hard-interface is enabled */
456         int (*bat_iface_enable)(struct batadv_hard_iface *hard_iface);
457         /* de-init routing info when hard-interface is disabled */
458         void (*bat_iface_disable)(struct batadv_hard_iface *hard_iface);
459         /* (re-)init mac addresses of the protocol information
460          * belonging to this hard-interface
461          */
462         void (*bat_iface_update_mac)(struct batadv_hard_iface *hard_iface);
463         /* called when primary interface is selected / changed */
464         void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);
465         /* prepare a new outgoing OGM for the send queue */
466         void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);
467         /* send scheduled OGM */
468         void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
469 };
470
471 /**
472  * struct batadv_dat_entry - it is a single entry of batman-adv ARP backend. It
473  * is used to stored ARP entries needed for the global DAT cache
474  * @ip: the IPv4 corresponding to this DAT/ARP entry
475  * @mac_addr: the MAC address associated to the stored IPv4
476  * @last_update: time in jiffies when this entry was refreshed last time
477  * @hash_entry: hlist node for batadv_priv_dat::hash
478  * @refcount: number of contexts the object is used
479  * @rcu: struct used for freeing in an RCU-safe manner
480  */
481 struct batadv_dat_entry {
482         __be32 ip;
483         uint8_t mac_addr[ETH_ALEN];
484         unsigned long last_update;
485         struct hlist_node hash_entry;
486         atomic_t refcount;
487         struct rcu_head rcu;
488 };
489
490 /**
491  * struct batadv_dat_candidate - candidate destination for DAT operations
492  * @type: the type of the selected candidate. It can one of the following:
493  *        - BATADV_DAT_CANDIDATE_NOT_FOUND
494  *        - BATADV_DAT_CANDIDATE_ORIG
495  * @orig_node: if type is BATADV_DAT_CANDIDATE_ORIG this field points to the
496  *             corresponding originator node structure
497  */
498 struct batadv_dat_candidate {
499         int type;
500         struct batadv_orig_node *orig_node;
501 };
502
503 #endif /* _NET_BATMAN_ADV_TYPES_H_ */