types.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. atomic_t last_ttvn; /* last seen translation table version number */
  71. uint16_t tt_crc;
  72. unsigned char *tt_buff;
  73. int16_t tt_buff_len;
  74. spinlock_t tt_buff_lock; /* protects tt_buff */
  75. atomic_t tt_size;
  76. /* The tt_poss_change flag is used to detect an ongoing roaming phase.
  77. * If true, then I sent a Roaming_adv to this orig_node and I have to
  78. * inspect every packet directed to it to check whether it is still
  79. * the true destination or not. This flag will be reset to false as
  80. * soon as I receive a new TTVN from this orig_node */
  81. bool tt_poss_change;
  82. uint32_t last_real_seqno;
  83. uint8_t last_ttl;
  84. unsigned long bcast_bits[NUM_WORDS];
  85. uint32_t last_bcast_seqno;
  86. struct hlist_head neigh_list;
  87. struct list_head frag_list;
  88. spinlock_t neigh_list_lock; /* protects neigh_list and router */
  89. atomic_t refcount;
  90. struct rcu_head rcu;
  91. struct hlist_node hash_entry;
  92. struct bat_priv *bat_priv;
  93. unsigned long last_frag_packet;
  94. /* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
  95. * neigh_node->real_bits, neigh_node->real_packet_count */
  96. spinlock_t ogm_cnt_lock;
  97. /* bcast_seqno_lock protects bcast_bits, last_bcast_seqno */
  98. spinlock_t bcast_seqno_lock;
  99. spinlock_t tt_list_lock; /* protects tt_list */
  100. atomic_t bond_candidates;
  101. struct list_head bond_list;
  102. };
  103. struct gw_node {
  104. struct hlist_node list;
  105. struct orig_node *orig_node;
  106. unsigned long deleted;
  107. atomic_t refcount;
  108. struct rcu_head rcu;
  109. };
  110. /**
  111. * neigh_node
  112. * @last_valid: when last packet via this neighbor was received
  113. */
  114. struct neigh_node {
  115. struct hlist_node list;
  116. uint8_t addr[ETH_ALEN];
  117. uint8_t real_packet_count;
  118. uint8_t tq_recv[TQ_GLOBAL_WINDOW_SIZE];
  119. uint8_t tq_index;
  120. uint8_t tq_avg;
  121. uint8_t last_ttl;
  122. struct list_head bonding_list;
  123. unsigned long last_valid;
  124. unsigned long real_bits[NUM_WORDS];
  125. atomic_t refcount;
  126. struct rcu_head rcu;
  127. struct orig_node *orig_node;
  128. struct hard_iface *if_incoming;
  129. spinlock_t tq_lock; /* protects: tq_recv, tq_index */
  130. };
  131. struct bat_priv {
  132. atomic_t mesh_state;
  133. struct net_device_stats stats;
  134. atomic_t aggregated_ogms; /* boolean */
  135. atomic_t bonding; /* boolean */
  136. atomic_t fragmentation; /* boolean */
  137. atomic_t vis_mode; /* VIS_TYPE_* */
  138. atomic_t gw_mode; /* GW_MODE_* */
  139. atomic_t gw_sel_class; /* uint */
  140. atomic_t gw_bandwidth; /* gw bandwidth */
  141. atomic_t orig_interval; /* uint */
  142. atomic_t hop_penalty; /* uint */
  143. atomic_t log_level; /* uint */
  144. atomic_t bcast_seqno;
  145. atomic_t bcast_queue_left;
  146. atomic_t batman_queue_left;
  147. atomic_t ttvn; /* tranlation table version number */
  148. atomic_t tt_ogm_append_cnt;
  149. atomic_t tt_local_changes; /* changes registered in a OGM interval */
  150. /* The tt_poss_change flag is used to detect an ongoing roaming phase.
  151. * If true, then I received a Roaming_adv and I have to inspect every
  152. * packet directed to me to check whether I am still the true
  153. * destination or not. This flag will be reset to false as soon as I
  154. * increase my TTVN */
  155. bool tt_poss_change;
  156. char num_ifaces;
  157. struct debug_log *debug_log;
  158. struct kobject *mesh_obj;
  159. struct dentry *debug_dir;
  160. struct hlist_head forw_bat_list;
  161. struct hlist_head forw_bcast_list;
  162. struct hlist_head gw_list;
  163. struct hlist_head softif_neigh_vids;
  164. struct list_head tt_changes_list; /* tracks changes in a OGM int */
  165. struct list_head vis_send_list;
  166. struct hashtable_t *orig_hash;
  167. struct hashtable_t *tt_local_hash;
  168. struct hashtable_t *tt_global_hash;
  169. struct list_head tt_req_list; /* list of pending tt_requests */
  170. struct list_head tt_roam_list;
  171. struct hashtable_t *vis_hash;
  172. spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
  173. spinlock_t forw_bcast_list_lock; /* protects */
  174. spinlock_t tt_changes_list_lock; /* protects tt_changes */
  175. spinlock_t tt_req_list_lock; /* protects tt_req_list */
  176. spinlock_t tt_roam_list_lock; /* protects tt_roam_list */
  177. spinlock_t gw_list_lock; /* protects gw_list and curr_gw */
  178. spinlock_t vis_hash_lock; /* protects vis_hash */
  179. spinlock_t vis_list_lock; /* protects vis_info::recv_list */
  180. spinlock_t softif_neigh_lock; /* protects soft-interface neigh list */
  181. spinlock_t softif_neigh_vid_lock; /* protects soft-interface vid list */
  182. atomic_t num_local_tt;
  183. /* Checksum of the local table, recomputed before sending a new OGM */
  184. atomic_t tt_crc;
  185. unsigned char *tt_buff;
  186. int16_t tt_buff_len;
  187. spinlock_t tt_buff_lock; /* protects tt_buff */
  188. struct delayed_work tt_work;
  189. struct delayed_work orig_work;
  190. struct delayed_work vis_work;
  191. struct gw_node __rcu *curr_gw; /* rcu protected pointer */
  192. struct hard_iface __rcu *primary_if; /* rcu protected pointer */
  193. struct vis_info *my_vis_info;
  194. };
  195. struct socket_client {
  196. struct list_head queue_list;
  197. unsigned int queue_len;
  198. unsigned char index;
  199. spinlock_t lock; /* protects queue_list, queue_len, index */
  200. wait_queue_head_t queue_wait;
  201. struct bat_priv *bat_priv;
  202. };
  203. struct socket_packet {
  204. struct list_head list;
  205. size_t icmp_len;
  206. struct icmp_packet_rr icmp_packet;
  207. };
  208. struct tt_local_entry {
  209. uint8_t addr[ETH_ALEN];
  210. unsigned long last_seen;
  211. char never_purge;
  212. atomic_t refcount;
  213. struct rcu_head rcu;
  214. struct hlist_node hash_entry;
  215. };
  216. struct tt_global_entry {
  217. uint8_t addr[ETH_ALEN];
  218. struct orig_node *orig_node;
  219. uint8_t ttvn;
  220. uint8_t flags; /* only TT_GLOBAL_ROAM is used */
  221. unsigned long roam_at; /* time at which TT_GLOBAL_ROAM was set */
  222. atomic_t refcount;
  223. struct rcu_head rcu;
  224. struct hlist_node hash_entry; /* entry in the global table */
  225. };
  226. struct tt_change_node {
  227. struct list_head list;
  228. struct tt_change change;
  229. };
  230. struct tt_req_node {
  231. uint8_t addr[ETH_ALEN];
  232. unsigned long issued_at;
  233. struct list_head list;
  234. };
  235. struct tt_roam_node {
  236. uint8_t addr[ETH_ALEN];
  237. atomic_t counter;
  238. unsigned long first_time;
  239. struct list_head list;
  240. };
  241. /**
  242. * forw_packet - structure for forw_list maintaining packets to be
  243. * send/forwarded
  244. */
  245. struct forw_packet {
  246. struct hlist_node list;
  247. unsigned long send_time;
  248. uint8_t own;
  249. struct sk_buff *skb;
  250. uint16_t packet_len;
  251. uint32_t direct_link_flags;
  252. uint8_t num_packets;
  253. struct delayed_work delayed_work;
  254. struct hard_iface *if_incoming;
  255. };
  256. /* While scanning for vis-entries of a particular vis-originator
  257. * this list collects its interfaces to create a subgraph/cluster
  258. * out of them later
  259. */
  260. struct if_list_entry {
  261. uint8_t addr[ETH_ALEN];
  262. bool primary;
  263. struct hlist_node list;
  264. };
  265. struct debug_log {
  266. char log_buff[LOG_BUF_LEN];
  267. unsigned long log_start;
  268. unsigned long log_end;
  269. spinlock_t lock; /* protects log_buff, log_start and log_end */
  270. wait_queue_head_t queue_wait;
  271. };
  272. struct frag_packet_list_entry {
  273. struct list_head list;
  274. uint16_t seqno;
  275. struct sk_buff *skb;
  276. };
  277. struct vis_info {
  278. unsigned long first_seen;
  279. /* list of server-neighbors we received a vis-packet
  280. * from. we should not reply to them. */
  281. struct list_head recv_list;
  282. struct list_head send_list;
  283. struct kref refcount;
  284. struct hlist_node hash_entry;
  285. struct bat_priv *bat_priv;
  286. /* this packet might be part of the vis send queue. */
  287. struct sk_buff *skb_packet;
  288. /* vis_info may follow here*/
  289. } __packed;
  290. struct vis_info_entry {
  291. uint8_t src[ETH_ALEN];
  292. uint8_t dest[ETH_ALEN];
  293. uint8_t quality; /* quality = 0 client */
  294. } __packed;
  295. struct recvlist_node {
  296. struct list_head list;
  297. uint8_t mac[ETH_ALEN];
  298. };
  299. struct softif_neigh_vid {
  300. struct hlist_node list;
  301. struct bat_priv *bat_priv;
  302. short vid;
  303. atomic_t refcount;
  304. struct softif_neigh __rcu *softif_neigh;
  305. struct rcu_head rcu;
  306. struct hlist_head softif_neigh_list;
  307. };
  308. struct softif_neigh {
  309. struct hlist_node list;
  310. uint8_t addr[ETH_ALEN];
  311. unsigned long last_seen;
  312. atomic_t refcount;
  313. struct rcu_head rcu;
  314. };
  315. #endif /* _NET_BATMAN_ADV_TYPES_H_ */