types.h 7.1 KB

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