1 /* Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
3 * Marek Lindner, Simon Wunderlich
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.
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.
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
20 #ifndef _NET_BATMAN_ADV_TYPES_H_
21 #define _NET_BATMAN_ADV_TYPES_H_
25 #include <linux/kernel.h>
27 #define BATADV_HEADER_LEN \
28 (ETH_HLEN + max(sizeof(struct batadv_unicast_packet), \
29 sizeof(struct batadv_bcast_packet)))
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.
34 * *Please be careful: batadv_dat_addr_t must be UNSIGNED*
36 #define batadv_dat_addr_t uint16_t
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
44 struct batadv_hard_iface_bat_iv {
45 unsigned char *ogm_buff;
50 struct batadv_hard_iface {
51 struct list_head list;
54 struct net_device *net_dev;
56 struct kobject *hardif_obj;
58 struct packet_type batman_adv_ptype;
59 struct net_device *soft_iface;
61 struct batadv_hard_iface_bat_iv bat_iv;
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
76 * @candidates: how many candidates are available
77 * @selected: next bonding candidate
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;
91 atomic_t last_ttvn; /* last seen translation table version number */
93 unsigned char *tt_buff;
95 spinlock_t tt_buff_lock; /* protects tt_buff */
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
105 uint32_t last_real_seqno;
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 */
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
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;
128 struct batadv_gw_node {
129 struct hlist_node list;
130 struct batadv_orig_node *orig_node;
131 unsigned long deleted;
137 * @last_seen: when last packet via this neighbor was received
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];
147 struct list_head bonding_list;
148 unsigned long last_seen;
149 DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
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 */
157 #ifdef CONFIG_BATMAN_ADV_BLA
158 struct batadv_bcast_duplist_entry {
159 uint8_t orig[ETH_ALEN];
161 unsigned long entrytime;
165 enum batadv_counters {
168 BATADV_CNT_TX_DROPPED,
172 BATADV_CNT_FORWARD_BYTES,
174 BATADV_CNT_MGMT_TX_BYTES,
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,
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
198 struct batadv_priv_tt {
200 atomic_t ogm_append_cnt;
201 atomic_t local_changes;
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;
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;
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;
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 */
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;
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
255 struct batadv_priv_dat {
256 batadv_dat_addr_t addr;
257 struct batadv_hashtable *hash;
258 struct delayed_work work;
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;
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;
295 struct batadv_priv_gw gw;
296 struct batadv_priv_tt tt;
297 struct batadv_priv_vis vis;
298 struct batadv_priv_dat dat;
301 struct batadv_socket_client {
302 struct list_head queue_list;
303 unsigned int queue_len;
305 spinlock_t lock; /* protects queue_list, queue_len, index */
306 wait_queue_head_t queue_wait;
307 struct batadv_priv *bat_priv;
310 struct batadv_socket_packet {
311 struct list_head list;
313 struct batadv_icmp_packet_rr icmp_packet;
316 struct batadv_tt_common_entry {
317 uint8_t addr[ETH_ALEN];
318 struct hlist_node hash_entry;
320 unsigned long added_at;
325 struct batadv_tt_local_entry {
326 struct batadv_tt_common_entry common;
327 unsigned long last_seen;
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 */
337 struct batadv_tt_orig_list_entry {
338 struct batadv_orig_node *orig_node;
342 struct hlist_node list;
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;
355 uint16_t crc; /* crc checksum over all claims */
358 struct batadv_claim {
359 uint8_t addr[ETH_ALEN];
361 struct batadv_backbone_gw *backbone_gw;
362 unsigned long lasttime; /* last time we heard of claim (locals only) */
365 struct hlist_node hash_entry;
369 struct batadv_tt_change_node {
370 struct list_head list;
371 struct batadv_tt_change change;
374 struct batadv_tt_req_node {
375 uint8_t addr[ETH_ALEN];
376 unsigned long issued_at;
377 struct list_head list;
380 struct batadv_tt_roam_node {
381 uint8_t addr[ETH_ALEN];
383 unsigned long first_time;
384 struct list_head list;
387 /* forw_packet - structure for forw_list maintaining packets to be
390 struct batadv_forw_packet {
391 struct hlist_node list;
392 unsigned long send_time;
396 uint32_t direct_link_flags;
398 struct delayed_work delayed_work;
399 struct batadv_hard_iface *if_incoming;
402 /* While scanning for vis-entries of a particular vis-originator
403 * this list collects its interfaces to create a subgraph/cluster
406 struct batadv_if_list_entry {
407 uint8_t addr[ETH_ALEN];
409 struct hlist_node list;
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;
420 struct batadv_frag_packet_list_entry {
421 struct list_head list;
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.
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 */
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 */
447 struct batadv_recvlist_node {
448 struct list_head list;
449 uint8_t mac[ETH_ALEN];
452 struct batadv_algo_ops {
453 struct hlist_node list;
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
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);
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
481 struct batadv_dat_entry {
483 uint8_t mac_addr[ETH_ALEN];
484 unsigned long last_update;
485 struct hlist_node hash_entry;
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
498 struct batadv_dat_candidate {
500 struct batadv_orig_node *orig_node;
503 #endif /* _NET_BATMAN_ADV_TYPES_H_ */