types.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. /* Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
  2. *
  3. * Marek Lindner, Simon Wunderlich
  4. *
  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.
  8. *
  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.
  13. *
  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
  17. * 02110-1301, USA
  18. */
  19. #ifndef _NET_BATMAN_ADV_TYPES_H_
  20. #define _NET_BATMAN_ADV_TYPES_H_
  21. #include "packet.h"
  22. #include "bitarray.h"
  23. #include <linux/kernel.h>
  24. #define BATADV_HEADER_LEN \
  25. (ETH_HLEN + max(sizeof(struct unicast_packet), \
  26. sizeof(struct bcast_packet)))
  27. struct hard_iface {
  28. struct list_head list;
  29. int16_t if_num;
  30. char if_status;
  31. struct net_device *net_dev;
  32. atomic_t seqno;
  33. atomic_t frag_seqno;
  34. unsigned char *packet_buff;
  35. int packet_len;
  36. struct kobject *hardif_obj;
  37. atomic_t refcount;
  38. struct packet_type batman_adv_ptype;
  39. struct net_device *soft_iface;
  40. struct rcu_head rcu;
  41. };
  42. /* orig_node - structure for orig_list maintaining nodes of mesh
  43. * @primary_addr: hosts primary interface address
  44. * @last_seen: when last packet from this node was received
  45. * @bcast_seqno_reset: time when the broadcast seqno window was reset
  46. * @batman_seqno_reset: time when the batman seqno window was reset
  47. * @gw_flags: flags related to gateway class
  48. * @flags: for now only VIS_SERVER flag
  49. * @last_real_seqno: last and best known sequence number
  50. * @last_ttl: ttl of last received packet
  51. * @last_bcast_seqno: last broadcast sequence number received by this host
  52. *
  53. * @candidates: how many candidates are available
  54. * @selected: next bonding candidate
  55. */
  56. struct orig_node {
  57. uint8_t orig[ETH_ALEN];
  58. uint8_t primary_addr[ETH_ALEN];
  59. struct neigh_node __rcu *router; /* rcu protected pointer */
  60. unsigned long *bcast_own;
  61. uint8_t *bcast_own_sum;
  62. unsigned long last_seen;
  63. unsigned long bcast_seqno_reset;
  64. unsigned long batman_seqno_reset;
  65. uint8_t gw_flags;
  66. uint8_t flags;
  67. atomic_t last_ttvn; /* last seen translation table version number */
  68. uint16_t tt_crc;
  69. unsigned char *tt_buff;
  70. int16_t tt_buff_len;
  71. spinlock_t tt_buff_lock; /* protects tt_buff */
  72. atomic_t tt_size;
  73. bool tt_initialised;
  74. /* The tt_poss_change flag is used to detect an ongoing roaming phase.
  75. * If true, then I sent a Roaming_adv to this orig_node and I have to
  76. * inspect every packet directed to it to check whether it is still
  77. * the true destination or not. This flag will be reset to false as
  78. * soon as I receive a new TTVN from this orig_node
  79. */
  80. bool tt_poss_change;
  81. uint32_t last_real_seqno;
  82. uint8_t last_ttl;
  83. DECLARE_BITMAP(bcast_bits, TQ_LOCAL_WINDOW_SIZE);
  84. uint32_t last_bcast_seqno;
  85. struct hlist_head neigh_list;
  86. struct list_head frag_list;
  87. spinlock_t neigh_list_lock; /* protects neigh_list and router */
  88. atomic_t refcount;
  89. struct rcu_head rcu;
  90. struct hlist_node hash_entry;
  91. struct bat_priv *bat_priv;
  92. unsigned long last_frag_packet;
  93. /* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
  94. * neigh_node->real_bits, neigh_node->real_packet_count
  95. */
  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. /* neigh_node
  111. * @last_seen: when last packet via this neighbor was received
  112. */
  113. struct neigh_node {
  114. struct hlist_node list;
  115. uint8_t addr[ETH_ALEN];
  116. uint8_t real_packet_count;
  117. uint8_t tq_recv[TQ_GLOBAL_WINDOW_SIZE];
  118. uint8_t tq_index;
  119. uint8_t tq_avg;
  120. uint8_t last_ttl;
  121. struct list_head bonding_list;
  122. unsigned long last_seen;
  123. DECLARE_BITMAP(real_bits, TQ_LOCAL_WINDOW_SIZE);
  124. atomic_t refcount;
  125. struct rcu_head rcu;
  126. struct orig_node *orig_node;
  127. struct hard_iface *if_incoming;
  128. spinlock_t lq_update_lock; /* protects: tq_recv, tq_index */
  129. };
  130. #ifdef CONFIG_BATMAN_ADV_BLA
  131. struct bcast_duplist_entry {
  132. uint8_t orig[ETH_ALEN];
  133. uint16_t crc;
  134. unsigned long entrytime;
  135. };
  136. #endif
  137. enum bat_counters {
  138. BAT_CNT_FORWARD,
  139. BAT_CNT_FORWARD_BYTES,
  140. BAT_CNT_MGMT_TX,
  141. BAT_CNT_MGMT_TX_BYTES,
  142. BAT_CNT_MGMT_RX,
  143. BAT_CNT_MGMT_RX_BYTES,
  144. BAT_CNT_TT_REQUEST_TX,
  145. BAT_CNT_TT_REQUEST_RX,
  146. BAT_CNT_TT_RESPONSE_TX,
  147. BAT_CNT_TT_RESPONSE_RX,
  148. BAT_CNT_TT_ROAM_ADV_TX,
  149. BAT_CNT_TT_ROAM_ADV_RX,
  150. BAT_CNT_NUM,
  151. };
  152. struct bat_priv {
  153. atomic_t mesh_state;
  154. struct net_device_stats stats;
  155. uint64_t __percpu *bat_counters; /* Per cpu counters */
  156. atomic_t aggregated_ogms; /* boolean */
  157. atomic_t bonding; /* boolean */
  158. atomic_t fragmentation; /* boolean */
  159. atomic_t ap_isolation; /* boolean */
  160. atomic_t bridge_loop_avoidance; /* boolean */
  161. atomic_t vis_mode; /* VIS_TYPE_* */
  162. atomic_t gw_mode; /* GW_MODE_* */
  163. atomic_t gw_sel_class; /* uint */
  164. atomic_t gw_bandwidth; /* gw bandwidth */
  165. atomic_t orig_interval; /* uint */
  166. atomic_t hop_penalty; /* uint */
  167. atomic_t log_level; /* uint */
  168. atomic_t bcast_seqno;
  169. atomic_t bcast_queue_left;
  170. atomic_t batman_queue_left;
  171. atomic_t ttvn; /* translation table version number */
  172. atomic_t tt_ogm_append_cnt;
  173. atomic_t tt_local_changes; /* changes registered in a OGM interval */
  174. atomic_t bla_num_requests; /* number of bla requests in flight */
  175. /* The tt_poss_change flag is used to detect an ongoing roaming phase.
  176. * If true, then I received a Roaming_adv and I have to inspect every
  177. * packet directed to me to check whether I am still the true
  178. * destination or not. This flag will be reset to false as soon as I
  179. * increase my TTVN
  180. */
  181. bool tt_poss_change;
  182. char num_ifaces;
  183. struct debug_log *debug_log;
  184. struct kobject *mesh_obj;
  185. struct dentry *debug_dir;
  186. struct hlist_head forw_bat_list;
  187. struct hlist_head forw_bcast_list;
  188. struct hlist_head gw_list;
  189. struct list_head tt_changes_list; /* tracks changes in a OGM int */
  190. struct list_head vis_send_list;
  191. struct hashtable_t *orig_hash;
  192. struct hashtable_t *tt_local_hash;
  193. struct hashtable_t *tt_global_hash;
  194. #ifdef CONFIG_BATMAN_ADV_BLA
  195. struct hashtable_t *claim_hash;
  196. struct hashtable_t *backbone_hash;
  197. #endif
  198. struct list_head tt_req_list; /* list of pending tt_requests */
  199. struct list_head tt_roam_list;
  200. struct hashtable_t *vis_hash;
  201. #ifdef CONFIG_BATMAN_ADV_BLA
  202. struct bcast_duplist_entry bcast_duplist[DUPLIST_SIZE];
  203. int bcast_duplist_curr;
  204. struct bla_claim_dst claim_dest;
  205. #endif
  206. spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
  207. spinlock_t forw_bcast_list_lock; /* protects */
  208. spinlock_t tt_changes_list_lock; /* protects tt_changes */
  209. spinlock_t tt_req_list_lock; /* protects tt_req_list */
  210. spinlock_t tt_roam_list_lock; /* protects tt_roam_list */
  211. spinlock_t gw_list_lock; /* protects gw_list and curr_gw */
  212. spinlock_t vis_hash_lock; /* protects vis_hash */
  213. spinlock_t vis_list_lock; /* protects vis_info::recv_list */
  214. atomic_t num_local_tt;
  215. /* Checksum of the local table, recomputed before sending a new OGM */
  216. uint16_t tt_crc;
  217. unsigned char *tt_buff;
  218. int16_t tt_buff_len;
  219. spinlock_t tt_buff_lock; /* protects tt_buff */
  220. struct delayed_work tt_work;
  221. struct delayed_work orig_work;
  222. struct delayed_work vis_work;
  223. struct delayed_work bla_work;
  224. struct gw_node __rcu *curr_gw; /* rcu protected pointer */
  225. atomic_t gw_reselect;
  226. struct hard_iface __rcu *primary_if; /* rcu protected pointer */
  227. struct vis_info *my_vis_info;
  228. struct bat_algo_ops *bat_algo_ops;
  229. };
  230. struct socket_client {
  231. struct list_head queue_list;
  232. unsigned int queue_len;
  233. unsigned char index;
  234. spinlock_t lock; /* protects queue_list, queue_len, index */
  235. wait_queue_head_t queue_wait;
  236. struct bat_priv *bat_priv;
  237. };
  238. struct socket_packet {
  239. struct list_head list;
  240. size_t icmp_len;
  241. struct icmp_packet_rr icmp_packet;
  242. };
  243. struct tt_common_entry {
  244. uint8_t addr[ETH_ALEN];
  245. struct hlist_node hash_entry;
  246. uint16_t flags;
  247. atomic_t refcount;
  248. struct rcu_head rcu;
  249. };
  250. struct tt_local_entry {
  251. struct tt_common_entry common;
  252. unsigned long last_seen;
  253. };
  254. struct tt_global_entry {
  255. struct tt_common_entry common;
  256. struct hlist_head orig_list;
  257. spinlock_t list_lock; /* protects the list */
  258. unsigned long roam_at; /* time at which TT_GLOBAL_ROAM was set */
  259. };
  260. struct tt_orig_list_entry {
  261. struct orig_node *orig_node;
  262. uint8_t ttvn;
  263. struct rcu_head rcu;
  264. struct hlist_node list;
  265. };
  266. #ifdef CONFIG_BATMAN_ADV_BLA
  267. struct backbone_gw {
  268. uint8_t orig[ETH_ALEN];
  269. short vid; /* used VLAN ID */
  270. struct hlist_node hash_entry;
  271. struct bat_priv *bat_priv;
  272. unsigned long lasttime; /* last time we heard of this backbone gw */
  273. atomic_t request_sent;
  274. atomic_t refcount;
  275. struct rcu_head rcu;
  276. uint16_t crc; /* crc checksum over all claims */
  277. };
  278. struct claim {
  279. uint8_t addr[ETH_ALEN];
  280. short vid;
  281. struct backbone_gw *backbone_gw;
  282. unsigned long lasttime; /* last time we heard of claim (locals only) */
  283. struct rcu_head rcu;
  284. atomic_t refcount;
  285. struct hlist_node hash_entry;
  286. };
  287. #endif
  288. struct tt_change_node {
  289. struct list_head list;
  290. struct tt_change change;
  291. };
  292. struct tt_req_node {
  293. uint8_t addr[ETH_ALEN];
  294. unsigned long issued_at;
  295. struct list_head list;
  296. };
  297. struct tt_roam_node {
  298. uint8_t addr[ETH_ALEN];
  299. atomic_t counter;
  300. unsigned long first_time;
  301. struct list_head list;
  302. };
  303. /* forw_packet - structure for forw_list maintaining packets to be
  304. * send/forwarded
  305. */
  306. struct forw_packet {
  307. struct hlist_node list;
  308. unsigned long send_time;
  309. uint8_t own;
  310. struct sk_buff *skb;
  311. uint16_t packet_len;
  312. uint32_t direct_link_flags;
  313. uint8_t num_packets;
  314. struct delayed_work delayed_work;
  315. struct hard_iface *if_incoming;
  316. };
  317. /* While scanning for vis-entries of a particular vis-originator
  318. * this list collects its interfaces to create a subgraph/cluster
  319. * out of them later
  320. */
  321. struct if_list_entry {
  322. uint8_t addr[ETH_ALEN];
  323. bool primary;
  324. struct hlist_node list;
  325. };
  326. struct debug_log {
  327. char log_buff[LOG_BUF_LEN];
  328. unsigned long log_start;
  329. unsigned long log_end;
  330. spinlock_t lock; /* protects log_buff, log_start and log_end */
  331. wait_queue_head_t queue_wait;
  332. };
  333. struct frag_packet_list_entry {
  334. struct list_head list;
  335. uint16_t seqno;
  336. struct sk_buff *skb;
  337. };
  338. struct vis_info {
  339. unsigned long first_seen;
  340. /* list of server-neighbors we received a vis-packet
  341. * from. we should not reply to them.
  342. */
  343. struct list_head recv_list;
  344. struct list_head send_list;
  345. struct kref refcount;
  346. struct hlist_node hash_entry;
  347. struct bat_priv *bat_priv;
  348. /* this packet might be part of the vis send queue. */
  349. struct sk_buff *skb_packet;
  350. /* vis_info may follow here */
  351. } __packed;
  352. struct vis_info_entry {
  353. uint8_t src[ETH_ALEN];
  354. uint8_t dest[ETH_ALEN];
  355. uint8_t quality; /* quality = 0 client */
  356. } __packed;
  357. struct recvlist_node {
  358. struct list_head list;
  359. uint8_t mac[ETH_ALEN];
  360. };
  361. struct bat_algo_ops {
  362. struct hlist_node list;
  363. char *name;
  364. /* init routing info when hard-interface is enabled */
  365. int (*bat_iface_enable)(struct hard_iface *hard_iface);
  366. /* de-init routing info when hard-interface is disabled */
  367. void (*bat_iface_disable)(struct hard_iface *hard_iface);
  368. /* (re-)init mac addresses of the protocol information
  369. * belonging to this hard-interface
  370. */
  371. void (*bat_iface_update_mac)(struct hard_iface *hard_iface);
  372. /* called when primary interface is selected / changed */
  373. void (*bat_primary_iface_set)(struct hard_iface *hard_iface);
  374. /* prepare a new outgoing OGM for the send queue */
  375. void (*bat_ogm_schedule)(struct hard_iface *hard_iface);
  376. /* send scheduled OGM */
  377. void (*bat_ogm_emit)(struct forw_packet *forw_packet);
  378. };
  379. #endif /* _NET_BATMAN_ADV_TYPES_H_ */