types.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
  3. *
  4. * Marek Lindner, Simon Wunderlich
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of version 2 of the GNU General Public
  8. * License as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA
  19. *
  20. */
  21. #ifndef _NET_BATMAN_ADV_TYPES_H_
  22. #define _NET_BATMAN_ADV_TYPES_H_
  23. #include "packet.h"
  24. #include "bitarray.h"
  25. #define BAT_HEADER_LEN (sizeof(struct ethhdr) + \
  26. ((sizeof(struct unicast_packet) > sizeof(struct bcast_packet) ? \
  27. sizeof(struct unicast_packet) : \
  28. sizeof(struct bcast_packet))))
  29. struct hard_iface {
  30. struct list_head list;
  31. int16_t if_num;
  32. char if_status;
  33. struct net_device *net_dev;
  34. atomic_t seqno;
  35. atomic_t frag_seqno;
  36. unsigned char *packet_buff;
  37. int packet_len;
  38. struct kobject *hardif_obj;
  39. atomic_t refcount;
  40. struct packet_type batman_adv_ptype;
  41. struct net_device *soft_iface;
  42. struct rcu_head rcu;
  43. };
  44. /**
  45. * orig_node - structure for orig_list maintaining nodes of mesh
  46. * @primary_addr: hosts primary interface address
  47. * @last_valid: when last packet from this node was received
  48. * @bcast_seqno_reset: time when the broadcast seqno window was reset
  49. * @batman_seqno_reset: time when the batman seqno window was reset
  50. * @gw_flags: flags related to gateway class
  51. * @flags: for now only VIS_SERVER flag
  52. * @last_real_seqno: last and best known squence number
  53. * @last_ttl: ttl of last received packet
  54. * @last_bcast_seqno: last broadcast sequence number received by this host
  55. *
  56. * @candidates: how many candidates are available
  57. * @selected: next bonding candidate
  58. */
  59. struct orig_node {
  60. uint8_t orig[ETH_ALEN];
  61. uint8_t primary_addr[ETH_ALEN];
  62. struct neigh_node __rcu *router; /* rcu protected pointer */
  63. unsigned long *bcast_own;
  64. uint8_t *bcast_own_sum;
  65. unsigned long last_valid;
  66. unsigned long bcast_seqno_reset;
  67. unsigned long batman_seqno_reset;
  68. uint8_t gw_flags;
  69. uint8_t flags;
  70. unsigned char *tt_buff;
  71. int16_t tt_buff_len;
  72. uint32_t last_real_seqno;
  73. uint8_t last_ttl;
  74. unsigned long bcast_bits[NUM_WORDS];
  75. uint32_t last_bcast_seqno;
  76. struct hlist_head neigh_list;
  77. struct list_head frag_list;
  78. spinlock_t neigh_list_lock; /* protects neigh_list and router */
  79. atomic_t refcount;
  80. struct rcu_head rcu;
  81. struct hlist_node hash_entry;
  82. struct bat_priv *bat_priv;
  83. unsigned long last_frag_packet;
  84. /* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
  85. * neigh_node->real_bits, neigh_node->real_packet_count */
  86. spinlock_t ogm_cnt_lock;
  87. /* bcast_seqno_lock protects bcast_bits, last_bcast_seqno */
  88. spinlock_t bcast_seqno_lock;
  89. atomic_t bond_candidates;
  90. struct list_head bond_list;
  91. };
  92. struct gw_node {
  93. struct hlist_node list;
  94. struct orig_node *orig_node;
  95. unsigned long deleted;
  96. atomic_t refcount;
  97. struct rcu_head rcu;
  98. };
  99. /**
  100. * neigh_node
  101. * @last_valid: when last packet via this neighbor was received
  102. */
  103. struct neigh_node {
  104. struct hlist_node list;
  105. uint8_t addr[ETH_ALEN];
  106. uint8_t real_packet_count;
  107. uint8_t tq_recv[TQ_GLOBAL_WINDOW_SIZE];
  108. uint8_t tq_index;
  109. uint8_t tq_avg;
  110. uint8_t last_ttl;
  111. struct list_head bonding_list;
  112. unsigned long last_valid;
  113. unsigned long real_bits[NUM_WORDS];
  114. atomic_t refcount;
  115. struct rcu_head rcu;
  116. struct orig_node *orig_node;
  117. struct hard_iface *if_incoming;
  118. spinlock_t tq_lock; /* protects: tq_recv, tq_index */
  119. };
  120. struct bat_priv {
  121. atomic_t mesh_state;
  122. struct net_device_stats stats;
  123. atomic_t aggregated_ogms; /* boolean */
  124. atomic_t bonding; /* boolean */
  125. atomic_t fragmentation; /* boolean */
  126. atomic_t vis_mode; /* VIS_TYPE_* */
  127. atomic_t gw_mode; /* GW_MODE_* */
  128. atomic_t gw_sel_class; /* uint */
  129. atomic_t gw_bandwidth; /* gw bandwidth */
  130. atomic_t orig_interval; /* uint */
  131. atomic_t hop_penalty; /* uint */
  132. atomic_t log_level; /* uint */
  133. atomic_t bcast_seqno;
  134. atomic_t bcast_queue_left;
  135. atomic_t batman_queue_left;
  136. char num_ifaces;
  137. struct debug_log *debug_log;
  138. struct kobject *mesh_obj;
  139. struct dentry *debug_dir;
  140. struct hlist_head forw_bat_list;
  141. struct hlist_head forw_bcast_list;
  142. struct hlist_head gw_list;
  143. struct hlist_head softif_neigh_vids;
  144. struct list_head vis_send_list;
  145. struct hashtable_t *orig_hash;
  146. struct hashtable_t *tt_local_hash;
  147. struct hashtable_t *tt_global_hash;
  148. struct hashtable_t *vis_hash;
  149. spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
  150. spinlock_t forw_bcast_list_lock; /* protects */
  151. spinlock_t tt_lhash_lock; /* protects tt_local_hash */
  152. spinlock_t tt_ghash_lock; /* protects tt_global_hash */
  153. spinlock_t gw_list_lock; /* protects gw_list and curr_gw */
  154. spinlock_t vis_hash_lock; /* protects vis_hash */
  155. spinlock_t vis_list_lock; /* protects vis_info::recv_list */
  156. spinlock_t softif_neigh_lock; /* protects soft-interface neigh list */
  157. spinlock_t softif_neigh_vid_lock; /* protects soft-interface vid list */
  158. int16_t num_local_tt;
  159. atomic_t tt_local_changed;
  160. struct delayed_work tt_work;
  161. struct delayed_work orig_work;
  162. struct delayed_work vis_work;
  163. struct gw_node __rcu *curr_gw; /* rcu protected pointer */
  164. struct hard_iface __rcu *primary_if; /* rcu protected pointer */
  165. struct vis_info *my_vis_info;
  166. };
  167. struct socket_client {
  168. struct list_head queue_list;
  169. unsigned int queue_len;
  170. unsigned char index;
  171. spinlock_t lock; /* protects queue_list, queue_len, index */
  172. wait_queue_head_t queue_wait;
  173. struct bat_priv *bat_priv;
  174. };
  175. struct socket_packet {
  176. struct list_head list;
  177. size_t icmp_len;
  178. struct icmp_packet_rr icmp_packet;
  179. };
  180. struct tt_local_entry {
  181. uint8_t addr[ETH_ALEN];
  182. unsigned long last_seen;
  183. char never_purge;
  184. struct hlist_node hash_entry;
  185. };
  186. struct tt_global_entry {
  187. uint8_t addr[ETH_ALEN];
  188. struct orig_node *orig_node;
  189. struct hlist_node hash_entry;
  190. };
  191. /**
  192. * forw_packet - structure for forw_list maintaining packets to be
  193. * send/forwarded
  194. */
  195. struct forw_packet {
  196. struct hlist_node list;
  197. unsigned long send_time;
  198. uint8_t own;
  199. struct sk_buff *skb;
  200. uint16_t packet_len;
  201. uint32_t direct_link_flags;
  202. uint8_t num_packets;
  203. struct delayed_work delayed_work;
  204. struct hard_iface *if_incoming;
  205. };
  206. /* While scanning for vis-entries of a particular vis-originator
  207. * this list collects its interfaces to create a subgraph/cluster
  208. * out of them later
  209. */
  210. struct if_list_entry {
  211. uint8_t addr[ETH_ALEN];
  212. bool primary;
  213. struct hlist_node list;
  214. };
  215. struct debug_log {
  216. char log_buff[LOG_BUF_LEN];
  217. unsigned long log_start;
  218. unsigned long log_end;
  219. spinlock_t lock; /* protects log_buff, log_start and log_end */
  220. wait_queue_head_t queue_wait;
  221. };
  222. struct frag_packet_list_entry {
  223. struct list_head list;
  224. uint16_t seqno;
  225. struct sk_buff *skb;
  226. };
  227. struct vis_info {
  228. unsigned long first_seen;
  229. struct list_head recv_list;
  230. /* list of server-neighbors we received a vis-packet
  231. * from. we should not reply to them. */
  232. struct list_head send_list;
  233. struct kref refcount;
  234. struct hlist_node hash_entry;
  235. struct bat_priv *bat_priv;
  236. /* this packet might be part of the vis send queue. */
  237. struct sk_buff *skb_packet;
  238. /* vis_info may follow here*/
  239. } __packed;
  240. struct vis_info_entry {
  241. uint8_t src[ETH_ALEN];
  242. uint8_t dest[ETH_ALEN];
  243. uint8_t quality; /* quality = 0 client */
  244. } __packed;
  245. struct recvlist_node {
  246. struct list_head list;
  247. uint8_t mac[ETH_ALEN];
  248. };
  249. struct softif_neigh_vid {
  250. struct hlist_node list;
  251. struct bat_priv *bat_priv;
  252. short vid;
  253. atomic_t refcount;
  254. struct softif_neigh __rcu *softif_neigh;
  255. struct rcu_head rcu;
  256. struct hlist_head softif_neigh_list;
  257. };
  258. struct softif_neigh {
  259. struct hlist_node list;
  260. uint8_t addr[ETH_ALEN];
  261. unsigned long last_seen;
  262. atomic_t refcount;
  263. struct rcu_head rcu;
  264. };
  265. #endif /* _NET_BATMAN_ADV_TYPES_H_ */