types.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 batman_if {
  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. struct kref 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 *router;
  63. unsigned long *bcast_own;
  64. uint8_t *bcast_own_sum;
  65. uint8_t tq_own;
  66. int tq_asym_penalty;
  67. unsigned long last_valid;
  68. unsigned long bcast_seqno_reset;
  69. unsigned long batman_seqno_reset;
  70. uint8_t gw_flags;
  71. uint8_t flags;
  72. unsigned char *hna_buff;
  73. int16_t hna_buff_len;
  74. uint32_t last_real_seqno;
  75. uint8_t last_ttl;
  76. unsigned long bcast_bits[NUM_WORDS];
  77. uint32_t last_bcast_seqno;
  78. struct hlist_head neigh_list;
  79. struct list_head frag_list;
  80. spinlock_t neigh_list_lock; /* protects neighbor list */
  81. unsigned long last_frag_packet;
  82. struct {
  83. uint8_t candidates;
  84. struct neigh_node *selected;
  85. } bond;
  86. };
  87. struct gw_node {
  88. struct hlist_node list;
  89. struct orig_node *orig_node;
  90. unsigned long deleted;
  91. struct kref refcount;
  92. struct rcu_head rcu;
  93. };
  94. /**
  95. * neigh_node
  96. * @last_valid: when last packet via this neighbor was received
  97. */
  98. struct neigh_node {
  99. struct hlist_node list;
  100. uint8_t addr[ETH_ALEN];
  101. uint8_t real_packet_count;
  102. uint8_t tq_recv[TQ_GLOBAL_WINDOW_SIZE];
  103. uint8_t tq_index;
  104. uint8_t tq_avg;
  105. uint8_t last_ttl;
  106. struct neigh_node *next_bond_candidate;
  107. unsigned long last_valid;
  108. unsigned long real_bits[NUM_WORDS];
  109. struct kref refcount;
  110. struct rcu_head rcu;
  111. struct orig_node *orig_node;
  112. struct batman_if *if_incoming;
  113. };
  114. struct bat_priv {
  115. atomic_t mesh_state;
  116. struct net_device_stats stats;
  117. atomic_t aggregated_ogms; /* boolean */
  118. atomic_t bonding; /* boolean */
  119. atomic_t fragmentation; /* boolean */
  120. atomic_t vis_mode; /* VIS_TYPE_* */
  121. atomic_t gw_mode; /* GW_MODE_* */
  122. atomic_t gw_sel_class; /* uint */
  123. atomic_t gw_bandwidth; /* gw bandwidth */
  124. atomic_t orig_interval; /* uint */
  125. atomic_t hop_penalty; /* uint */
  126. atomic_t log_level; /* uint */
  127. atomic_t bcast_seqno;
  128. atomic_t bcast_queue_left;
  129. atomic_t batman_queue_left;
  130. char num_ifaces;
  131. struct hlist_head softif_neigh_list;
  132. struct softif_neigh *softif_neigh;
  133. struct debug_log *debug_log;
  134. struct batman_if *primary_if;
  135. struct kobject *mesh_obj;
  136. struct dentry *debug_dir;
  137. struct hlist_head forw_bat_list;
  138. struct hlist_head forw_bcast_list;
  139. struct hlist_head gw_list;
  140. struct list_head vis_send_list;
  141. struct hashtable_t *orig_hash;
  142. struct hashtable_t *hna_local_hash;
  143. struct hashtable_t *hna_global_hash;
  144. struct hashtable_t *vis_hash;
  145. spinlock_t orig_hash_lock; /* protects orig_hash */
  146. spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
  147. spinlock_t forw_bcast_list_lock; /* protects */
  148. spinlock_t hna_lhash_lock; /* protects hna_local_hash */
  149. spinlock_t hna_ghash_lock; /* protects hna_global_hash */
  150. spinlock_t gw_list_lock; /* protects gw_list */
  151. spinlock_t vis_hash_lock; /* protects vis_hash */
  152. spinlock_t vis_list_lock; /* protects vis_info::recv_list */
  153. spinlock_t softif_neigh_lock; /* protects soft-interface neigh list */
  154. int16_t num_local_hna;
  155. atomic_t hna_local_changed;
  156. struct delayed_work hna_work;
  157. struct delayed_work orig_work;
  158. struct delayed_work vis_work;
  159. struct gw_node *curr_gw;
  160. struct vis_info *my_vis_info;
  161. };
  162. struct socket_client {
  163. struct list_head queue_list;
  164. unsigned int queue_len;
  165. unsigned char index;
  166. spinlock_t lock; /* protects queue_list, queue_len, index */
  167. wait_queue_head_t queue_wait;
  168. struct bat_priv *bat_priv;
  169. };
  170. struct socket_packet {
  171. struct list_head list;
  172. size_t icmp_len;
  173. struct icmp_packet_rr icmp_packet;
  174. };
  175. struct hna_local_entry {
  176. uint8_t addr[ETH_ALEN];
  177. unsigned long last_seen;
  178. char never_purge;
  179. };
  180. struct hna_global_entry {
  181. uint8_t addr[ETH_ALEN];
  182. struct orig_node *orig_node;
  183. };
  184. /**
  185. * forw_packet - structure for forw_list maintaining packets to be
  186. * send/forwarded
  187. */
  188. struct forw_packet {
  189. struct hlist_node list;
  190. unsigned long send_time;
  191. uint8_t own;
  192. struct sk_buff *skb;
  193. uint16_t packet_len;
  194. uint32_t direct_link_flags;
  195. uint8_t num_packets;
  196. struct delayed_work delayed_work;
  197. struct batman_if *if_incoming;
  198. };
  199. /* While scanning for vis-entries of a particular vis-originator
  200. * this list collects its interfaces to create a subgraph/cluster
  201. * out of them later
  202. */
  203. struct if_list_entry {
  204. uint8_t addr[ETH_ALEN];
  205. bool primary;
  206. struct hlist_node list;
  207. };
  208. struct debug_log {
  209. char log_buff[LOG_BUF_LEN];
  210. unsigned long log_start;
  211. unsigned long log_end;
  212. spinlock_t lock; /* protects log_buff, log_start and log_end */
  213. wait_queue_head_t queue_wait;
  214. };
  215. struct frag_packet_list_entry {
  216. struct list_head list;
  217. uint16_t seqno;
  218. struct sk_buff *skb;
  219. };
  220. struct vis_info {
  221. unsigned long first_seen;
  222. struct list_head recv_list;
  223. /* list of server-neighbors we received a vis-packet
  224. * from. we should not reply to them. */
  225. struct list_head send_list;
  226. struct kref refcount;
  227. struct bat_priv *bat_priv;
  228. /* this packet might be part of the vis send queue. */
  229. struct sk_buff *skb_packet;
  230. /* vis_info may follow here*/
  231. } __packed;
  232. struct vis_info_entry {
  233. uint8_t src[ETH_ALEN];
  234. uint8_t dest[ETH_ALEN];
  235. uint8_t quality; /* quality = 0 means HNA */
  236. } __packed;
  237. struct recvlist_node {
  238. struct list_head list;
  239. uint8_t mac[ETH_ALEN];
  240. };
  241. struct softif_neigh {
  242. struct hlist_node list;
  243. uint8_t addr[ETH_ALEN];
  244. unsigned long last_seen;
  245. short vid;
  246. struct kref refcount;
  247. struct rcu_head rcu;
  248. };
  249. #endif /* _NET_BATMAN_ADV_TYPES_H_ */