types.h 12 KB

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