types.h 13 KB

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