types.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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 batadv_unicast_packet), \
  26. sizeof(struct batadv_bcast_packet)))
  27. struct batadv_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. /**
  43. * struct batadv_orig_node - structure for orig_list maintaining nodes of mesh
  44. * @primary_addr: hosts primary interface address
  45. * @last_seen: when last packet from this node was received
  46. * @bcast_seqno_reset: time when the broadcast seqno window was reset
  47. * @batman_seqno_reset: time when the batman seqno window was reset
  48. * @gw_flags: flags related to gateway class
  49. * @flags: for now only VIS_SERVER flag
  50. * @last_real_seqno: last and best known sequence number
  51. * @last_ttl: ttl of last received packet
  52. * @last_bcast_seqno: last broadcast sequence number received by this host
  53. *
  54. * @candidates: how many candidates are available
  55. * @selected: next bonding candidate
  56. */
  57. struct batadv_orig_node {
  58. uint8_t orig[ETH_ALEN];
  59. uint8_t primary_addr[ETH_ALEN];
  60. struct batadv_neigh_node __rcu *router; /* rcu protected pointer */
  61. unsigned long *bcast_own;
  62. uint8_t *bcast_own_sum;
  63. unsigned long last_seen;
  64. unsigned long bcast_seqno_reset;
  65. unsigned long batman_seqno_reset;
  66. uint8_t gw_flags;
  67. uint8_t flags;
  68. atomic_t last_ttvn; /* last seen translation table version number */
  69. uint16_t tt_crc;
  70. unsigned char *tt_buff;
  71. int16_t tt_buff_len;
  72. spinlock_t tt_buff_lock; /* protects tt_buff */
  73. atomic_t tt_size;
  74. bool tt_initialised;
  75. /* The tt_poss_change flag is used to detect an ongoing roaming phase.
  76. * If true, then I sent a Roaming_adv to this orig_node and I have to
  77. * inspect every packet directed to it to check whether it is still
  78. * the true destination or not. This flag will be reset to false as
  79. * soon as I receive a new TTVN from this orig_node
  80. */
  81. bool tt_poss_change;
  82. uint32_t last_real_seqno;
  83. uint8_t last_ttl;
  84. DECLARE_BITMAP(bcast_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
  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 batadv_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. */
  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 batadv_gw_node {
  105. struct hlist_node list;
  106. struct batadv_orig_node *orig_node;
  107. unsigned long deleted;
  108. atomic_t refcount;
  109. struct rcu_head rcu;
  110. };
  111. /* batadv_neigh_node
  112. * @last_seen: when last packet via this neighbor was received
  113. */
  114. struct batadv_neigh_node {
  115. struct hlist_node list;
  116. uint8_t addr[ETH_ALEN];
  117. uint8_t real_packet_count;
  118. uint8_t tq_recv[BATADV_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_seen;
  124. DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
  125. atomic_t refcount;
  126. struct rcu_head rcu;
  127. struct batadv_orig_node *orig_node;
  128. struct batadv_hard_iface *if_incoming;
  129. spinlock_t lq_update_lock; /* protects: tq_recv, tq_index */
  130. };
  131. #ifdef CONFIG_BATMAN_ADV_BLA
  132. struct batadv_bcast_duplist_entry {
  133. uint8_t orig[ETH_ALEN];
  134. uint16_t crc;
  135. unsigned long entrytime;
  136. };
  137. #endif
  138. enum batadv_counters {
  139. BATADV_CNT_TX,
  140. BATADV_CNT_TX_BYTES,
  141. BATADV_CNT_TX_DROPPED,
  142. BATADV_CNT_RX,
  143. BATADV_CNT_RX_BYTES,
  144. BATADV_CNT_FORWARD,
  145. BATADV_CNT_FORWARD_BYTES,
  146. BATADV_CNT_MGMT_TX,
  147. BATADV_CNT_MGMT_TX_BYTES,
  148. BATADV_CNT_MGMT_RX,
  149. BATADV_CNT_MGMT_RX_BYTES,
  150. BATADV_CNT_TT_REQUEST_TX,
  151. BATADV_CNT_TT_REQUEST_RX,
  152. BATADV_CNT_TT_RESPONSE_TX,
  153. BATADV_CNT_TT_RESPONSE_RX,
  154. BATADV_CNT_TT_ROAM_ADV_TX,
  155. BATADV_CNT_TT_ROAM_ADV_RX,
  156. BATADV_CNT_NUM,
  157. };
  158. /**
  159. * struct batadv_priv_tt - per mesh interface translation table data
  160. * @vn: translation table version number
  161. * @local_changes: changes registered in an originator interval
  162. * @poss_change: Detect an ongoing roaming phase. If true, then this node
  163. * received a roaming_adv and has to inspect every packet directed to it to
  164. * check whether it still is the true destination or not. This flag will be
  165. * reset to false as soon as the this node's ttvn is increased
  166. * @changes_list: tracks tt local changes within an originator interval
  167. * @req_list: list of pending tt_requests
  168. * @local_crc: Checksum of the local table, recomputed before sending a new OGM
  169. */
  170. struct batadv_priv_tt {
  171. atomic_t vn;
  172. atomic_t ogm_append_cnt;
  173. atomic_t local_changes;
  174. bool poss_change;
  175. struct list_head changes_list;
  176. struct batadv_hashtable *local_hash;
  177. struct batadv_hashtable *global_hash;
  178. struct list_head req_list;
  179. struct list_head roam_list;
  180. spinlock_t changes_list_lock; /* protects changes */
  181. spinlock_t req_list_lock; /* protects req_list */
  182. spinlock_t roam_list_lock; /* protects roam_list */
  183. atomic_t local_entry_num;
  184. uint16_t local_crc;
  185. unsigned char *last_changeset;
  186. int16_t last_changeset_len;
  187. spinlock_t last_changeset_lock; /* protects last_changeset */
  188. struct delayed_work work;
  189. };
  190. #ifdef CONFIG_BATMAN_ADV_BLA
  191. struct batadv_priv_bla {
  192. atomic_t num_requests; /* number of bla requests in flight */
  193. struct batadv_hashtable *claim_hash;
  194. struct batadv_hashtable *backbone_hash;
  195. struct batadv_bcast_duplist_entry bcast_duplist[BATADV_DUPLIST_SIZE];
  196. int bcast_duplist_curr;
  197. /* protects bcast_duplist and bcast_duplist_curr */
  198. spinlock_t bcast_duplist_lock;
  199. struct batadv_bla_claim_dst claim_dest;
  200. struct delayed_work work;
  201. };
  202. #endif
  203. struct batadv_priv_gw {
  204. struct hlist_head list;
  205. spinlock_t list_lock; /* protects gw_list and curr_gw */
  206. struct batadv_gw_node __rcu *curr_gw; /* rcu protected pointer */
  207. atomic_t reselect;
  208. };
  209. struct batadv_priv_vis {
  210. struct list_head send_list;
  211. struct batadv_hashtable *hash;
  212. spinlock_t hash_lock; /* protects hash */
  213. spinlock_t list_lock; /* protects info::recv_list */
  214. struct delayed_work work;
  215. struct batadv_vis_info *my_info;
  216. };
  217. struct batadv_priv {
  218. atomic_t mesh_state;
  219. struct net_device_stats stats;
  220. uint64_t __percpu *bat_counters; /* Per cpu counters */
  221. atomic_t aggregated_ogms; /* boolean */
  222. atomic_t bonding; /* boolean */
  223. atomic_t fragmentation; /* boolean */
  224. atomic_t ap_isolation; /* boolean */
  225. atomic_t bridge_loop_avoidance; /* boolean */
  226. atomic_t vis_mode; /* VIS_TYPE_* */
  227. atomic_t gw_mode; /* GW_MODE_* */
  228. atomic_t gw_sel_class; /* uint */
  229. atomic_t gw_bandwidth; /* gw bandwidth */
  230. atomic_t orig_interval; /* uint */
  231. atomic_t hop_penalty; /* uint */
  232. atomic_t log_level; /* uint */
  233. atomic_t bcast_seqno;
  234. atomic_t bcast_queue_left;
  235. atomic_t batman_queue_left;
  236. char num_ifaces;
  237. struct batadv_debug_log *debug_log;
  238. struct kobject *mesh_obj;
  239. struct dentry *debug_dir;
  240. struct hlist_head forw_bat_list;
  241. struct hlist_head forw_bcast_list;
  242. struct batadv_hashtable *orig_hash;
  243. spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
  244. spinlock_t forw_bcast_list_lock; /* protects */
  245. struct delayed_work orig_work;
  246. struct batadv_hard_iface __rcu *primary_if; /* rcu protected pointer */
  247. struct batadv_algo_ops *bat_algo_ops;
  248. #ifdef CONFIG_BATMAN_ADV_BLA
  249. struct batadv_priv_bla bla;
  250. #endif
  251. struct batadv_priv_gw gw;
  252. struct batadv_priv_tt tt;
  253. struct batadv_priv_vis vis;
  254. };
  255. struct batadv_socket_client {
  256. struct list_head queue_list;
  257. unsigned int queue_len;
  258. unsigned char index;
  259. spinlock_t lock; /* protects queue_list, queue_len, index */
  260. wait_queue_head_t queue_wait;
  261. struct batadv_priv *bat_priv;
  262. };
  263. struct batadv_socket_packet {
  264. struct list_head list;
  265. size_t icmp_len;
  266. struct batadv_icmp_packet_rr icmp_packet;
  267. };
  268. struct batadv_tt_common_entry {
  269. uint8_t addr[ETH_ALEN];
  270. struct hlist_node hash_entry;
  271. uint16_t flags;
  272. unsigned long added_at;
  273. atomic_t refcount;
  274. struct rcu_head rcu;
  275. };
  276. struct batadv_tt_local_entry {
  277. struct batadv_tt_common_entry common;
  278. unsigned long last_seen;
  279. };
  280. struct batadv_tt_global_entry {
  281. struct batadv_tt_common_entry common;
  282. struct hlist_head orig_list;
  283. spinlock_t list_lock; /* protects the list */
  284. unsigned long roam_at; /* time at which TT_GLOBAL_ROAM was set */
  285. };
  286. struct batadv_tt_orig_list_entry {
  287. struct batadv_orig_node *orig_node;
  288. uint8_t ttvn;
  289. atomic_t refcount;
  290. struct rcu_head rcu;
  291. struct hlist_node list;
  292. };
  293. #ifdef CONFIG_BATMAN_ADV_BLA
  294. struct batadv_backbone_gw {
  295. uint8_t orig[ETH_ALEN];
  296. short vid; /* used VLAN ID */
  297. struct hlist_node hash_entry;
  298. struct batadv_priv *bat_priv;
  299. unsigned long lasttime; /* last time we heard of this backbone gw */
  300. atomic_t request_sent;
  301. atomic_t refcount;
  302. struct rcu_head rcu;
  303. uint16_t crc; /* crc checksum over all claims */
  304. };
  305. struct batadv_claim {
  306. uint8_t addr[ETH_ALEN];
  307. short vid;
  308. struct batadv_backbone_gw *backbone_gw;
  309. unsigned long lasttime; /* last time we heard of claim (locals only) */
  310. struct rcu_head rcu;
  311. atomic_t refcount;
  312. struct hlist_node hash_entry;
  313. };
  314. #endif
  315. struct batadv_tt_change_node {
  316. struct list_head list;
  317. struct batadv_tt_change change;
  318. };
  319. struct batadv_tt_req_node {
  320. uint8_t addr[ETH_ALEN];
  321. unsigned long issued_at;
  322. struct list_head list;
  323. };
  324. struct batadv_tt_roam_node {
  325. uint8_t addr[ETH_ALEN];
  326. atomic_t counter;
  327. unsigned long first_time;
  328. struct list_head list;
  329. };
  330. /* forw_packet - structure for forw_list maintaining packets to be
  331. * send/forwarded
  332. */
  333. struct batadv_forw_packet {
  334. struct hlist_node list;
  335. unsigned long send_time;
  336. uint8_t own;
  337. struct sk_buff *skb;
  338. uint16_t packet_len;
  339. uint32_t direct_link_flags;
  340. uint8_t num_packets;
  341. struct delayed_work delayed_work;
  342. struct batadv_hard_iface *if_incoming;
  343. };
  344. /* While scanning for vis-entries of a particular vis-originator
  345. * this list collects its interfaces to create a subgraph/cluster
  346. * out of them later
  347. */
  348. struct batadv_if_list_entry {
  349. uint8_t addr[ETH_ALEN];
  350. bool primary;
  351. struct hlist_node list;
  352. };
  353. struct batadv_debug_log {
  354. char log_buff[BATADV_LOG_BUF_LEN];
  355. unsigned long log_start;
  356. unsigned long log_end;
  357. spinlock_t lock; /* protects log_buff, log_start and log_end */
  358. wait_queue_head_t queue_wait;
  359. };
  360. struct batadv_frag_packet_list_entry {
  361. struct list_head list;
  362. uint16_t seqno;
  363. struct sk_buff *skb;
  364. };
  365. struct batadv_vis_info {
  366. unsigned long first_seen;
  367. /* list of server-neighbors we received a vis-packet
  368. * from. we should not reply to them.
  369. */
  370. struct list_head recv_list;
  371. struct list_head send_list;
  372. struct kref refcount;
  373. struct hlist_node hash_entry;
  374. struct batadv_priv *bat_priv;
  375. /* this packet might be part of the vis send queue. */
  376. struct sk_buff *skb_packet;
  377. /* vis_info may follow here */
  378. } __packed;
  379. struct batadv_vis_info_entry {
  380. uint8_t src[ETH_ALEN];
  381. uint8_t dest[ETH_ALEN];
  382. uint8_t quality; /* quality = 0 client */
  383. } __packed;
  384. struct batadv_recvlist_node {
  385. struct list_head list;
  386. uint8_t mac[ETH_ALEN];
  387. };
  388. struct batadv_algo_ops {
  389. struct hlist_node list;
  390. char *name;
  391. /* init routing info when hard-interface is enabled */
  392. int (*bat_iface_enable)(struct batadv_hard_iface *hard_iface);
  393. /* de-init routing info when hard-interface is disabled */
  394. void (*bat_iface_disable)(struct batadv_hard_iface *hard_iface);
  395. /* (re-)init mac addresses of the protocol information
  396. * belonging to this hard-interface
  397. */
  398. void (*bat_iface_update_mac)(struct batadv_hard_iface *hard_iface);
  399. /* called when primary interface is selected / changed */
  400. void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);
  401. /* prepare a new outgoing OGM for the send queue */
  402. void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);
  403. /* send scheduled OGM */
  404. void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
  405. };
  406. #endif /* _NET_BATMAN_ADV_TYPES_H_ */