types.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. /* Copyright (C) 2007-2013 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. /**
  25. * Maximum overhead for the encapsulation for a payload packet
  26. */
  27. #define BATADV_HEADER_LEN \
  28. (ETH_HLEN + max(sizeof(struct batadv_unicast_packet), \
  29. sizeof(struct batadv_bcast_packet)))
  30. #ifdef CONFIG_BATMAN_ADV_DAT
  31. /* batadv_dat_addr_t is the type used for all DHT addresses. If it is changed,
  32. * BATADV_DAT_ADDR_MAX is changed as well.
  33. *
  34. * *Please be careful: batadv_dat_addr_t must be UNSIGNED*
  35. */
  36. #define batadv_dat_addr_t uint16_t
  37. #endif /* CONFIG_BATMAN_ADV_DAT */
  38. /**
  39. * struct batadv_hard_iface_bat_iv - per hard interface B.A.T.M.A.N. IV data
  40. * @ogm_buff: buffer holding the OGM packet
  41. * @ogm_buff_len: length of the OGM packet buffer
  42. * @ogm_seqno: OGM sequence number - used to identify each OGM
  43. */
  44. struct batadv_hard_iface_bat_iv {
  45. unsigned char *ogm_buff;
  46. int ogm_buff_len;
  47. atomic_t ogm_seqno;
  48. };
  49. /**
  50. * struct batadv_hard_iface - network device known to batman-adv
  51. * @list: list node for batadv_hardif_list
  52. * @if_num: identificator of the interface
  53. * @if_status: status of the interface for batman-adv
  54. * @net_dev: pointer to the net_device
  55. * @frag_seqno: last fragment sequence number sent by this interface
  56. * @hardif_obj: kobject of the per interface sysfs "mesh" directory
  57. * @refcount: number of contexts the object is used
  58. * @batman_adv_ptype: packet type describing packets that should be processed by
  59. * batman-adv for this interface
  60. * @soft_iface: the batman-adv interface which uses this network interface
  61. * @rcu: struct used for freeing in an RCU-safe manner
  62. * @bat_iv: BATMAN IV specific per hard interface data
  63. * @cleanup_work: work queue callback item for hard interface deinit
  64. */
  65. struct batadv_hard_iface {
  66. struct list_head list;
  67. int16_t if_num;
  68. char if_status;
  69. struct net_device *net_dev;
  70. atomic_t frag_seqno;
  71. struct kobject *hardif_obj;
  72. atomic_t refcount;
  73. struct packet_type batman_adv_ptype;
  74. struct net_device *soft_iface;
  75. struct rcu_head rcu;
  76. struct batadv_hard_iface_bat_iv bat_iv;
  77. struct work_struct cleanup_work;
  78. };
  79. /**
  80. * struct batadv_orig_node - structure for orig_list maintaining nodes of mesh
  81. * @orig: originator ethernet address
  82. * @primary_addr: hosts primary interface address
  83. * @router: router that should be used to reach this originator
  84. * @batadv_dat_addr_t: address of the orig node in the distributed hash
  85. * @bcast_own: bitfield containing the number of our OGMs this orig_node
  86. * rebroadcasted "back" to us (relative to last_real_seqno)
  87. * @bcast_own_sum: counted result of bcast_own
  88. * @last_seen: time when last packet from this node was received
  89. * @bcast_seqno_reset: time when the broadcast seqno window was reset
  90. * @batman_seqno_reset: time when the batman seqno window was reset
  91. * @gw_flags: flags related to gateway class
  92. * @flags: for now only VIS_SERVER flag
  93. * @last_ttvn: last seen translation table version number
  94. * @tt_crc: CRC of the translation table
  95. * @tt_buff: last tt changeset this node received from the orig node
  96. * @tt_buff_len: length of the last tt changeset this node received from the
  97. * orig node
  98. * @tt_buff_lock: lock that protects tt_buff and tt_buff_len
  99. * @tt_size: number of global TT entries announced by the orig node
  100. * @tt_initialised: bool keeping track of whether or not this node have received
  101. * any translation table information from the orig node yet
  102. * @last_real_seqno: last and best known sequence number
  103. * @last_ttl: ttl of last received packet
  104. * @bcast_bits: bitfield containing the info which payload broadcast originated
  105. * from this orig node this host already has seen (relative to
  106. * last_bcast_seqno)
  107. * @last_bcast_seqno: last broadcast sequence number received by this host
  108. * @neigh_list: list of potential next hop neighbor towards this orig node
  109. * @frag_list: fragmentation buffer list for fragment re-assembly
  110. * @last_frag_packet: time when last fragmented packet from this node was
  111. * received
  112. * @neigh_list_lock: lock protecting neigh_list, router and bonding_list
  113. * @hash_entry: hlist node for batadv_priv::orig_hash
  114. * @bat_priv: pointer to soft_iface this orig node belongs to
  115. * @ogm_cnt_lock: lock protecting bcast_own, bcast_own_sum,
  116. * neigh_node->real_bits & neigh_node->real_packet_count
  117. * @bcast_seqno_lock: lock protecting bcast_bits & last_bcast_seqno
  118. * @bond_candidates: how many candidates are available
  119. * @bond_list: list of bonding candidates
  120. * @refcount: number of contexts the object is used
  121. * @rcu: struct used for freeing in an RCU-safe manner
  122. */
  123. struct batadv_orig_node {
  124. uint8_t orig[ETH_ALEN];
  125. uint8_t primary_addr[ETH_ALEN];
  126. struct batadv_neigh_node __rcu *router; /* rcu protected pointer */
  127. #ifdef CONFIG_BATMAN_ADV_DAT
  128. batadv_dat_addr_t dat_addr;
  129. #endif
  130. unsigned long *bcast_own;
  131. uint8_t *bcast_own_sum;
  132. unsigned long last_seen;
  133. unsigned long bcast_seqno_reset;
  134. unsigned long batman_seqno_reset;
  135. uint8_t gw_flags;
  136. uint8_t flags;
  137. atomic_t last_ttvn;
  138. uint16_t tt_crc;
  139. unsigned char *tt_buff;
  140. int16_t tt_buff_len;
  141. spinlock_t tt_buff_lock; /* protects tt_buff & tt_buff_len */
  142. atomic_t tt_size;
  143. bool tt_initialised;
  144. uint32_t last_real_seqno;
  145. uint8_t last_ttl;
  146. DECLARE_BITMAP(bcast_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
  147. uint32_t last_bcast_seqno;
  148. struct hlist_head neigh_list;
  149. struct list_head frag_list;
  150. unsigned long last_frag_packet;
  151. /* neigh_list_lock protects: neigh_list, router & bonding_list */
  152. spinlock_t neigh_list_lock;
  153. struct hlist_node hash_entry;
  154. struct batadv_priv *bat_priv;
  155. /* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
  156. * neigh_node->real_bits & neigh_node->real_packet_count
  157. */
  158. spinlock_t ogm_cnt_lock;
  159. /* bcast_seqno_lock protects: bcast_bits & last_bcast_seqno */
  160. spinlock_t bcast_seqno_lock;
  161. atomic_t bond_candidates;
  162. struct list_head bond_list;
  163. atomic_t refcount;
  164. struct rcu_head rcu;
  165. };
  166. /**
  167. * struct batadv_gw_node - structure for orig nodes announcing gw capabilities
  168. * @list: list node for batadv_priv_gw::list
  169. * @orig_node: pointer to corresponding orig node
  170. * @deleted: this struct is scheduled for deletion
  171. * @refcount: number of contexts the object is used
  172. * @rcu: struct used for freeing in an RCU-safe manner
  173. */
  174. struct batadv_gw_node {
  175. struct hlist_node list;
  176. struct batadv_orig_node *orig_node;
  177. unsigned long deleted;
  178. atomic_t refcount;
  179. struct rcu_head rcu;
  180. };
  181. /**
  182. * struct batadv_neigh_node - structure for single hop neighbors
  183. * @list: list node for batadv_orig_node::neigh_list
  184. * @addr: mac address of neigh node
  185. * @tq_recv: ring buffer of received TQ values from this neigh node
  186. * @tq_index: ring buffer index
  187. * @tq_avg: averaged tq of all tq values in the ring buffer (tq_recv)
  188. * @last_ttl: last received ttl from this neigh node
  189. * @bonding_list: list node for batadv_orig_node::bond_list
  190. * @last_seen: when last packet via this neighbor was received
  191. * @real_bits: bitfield containing the number of OGMs received from this neigh
  192. * node (relative to orig_node->last_real_seqno)
  193. * @real_packet_count: counted result of real_bits
  194. * @orig_node: pointer to corresponding orig_node
  195. * @if_incoming: pointer to incoming hard interface
  196. * @lq_update_lock: lock protecting tq_recv & tq_index
  197. * @refcount: number of contexts the object is used
  198. * @rcu: struct used for freeing in an RCU-safe manner
  199. */
  200. struct batadv_neigh_node {
  201. struct hlist_node list;
  202. uint8_t addr[ETH_ALEN];
  203. uint8_t tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE];
  204. uint8_t tq_index;
  205. uint8_t tq_avg;
  206. uint8_t last_ttl;
  207. struct list_head bonding_list;
  208. unsigned long last_seen;
  209. DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
  210. uint8_t real_packet_count;
  211. struct batadv_orig_node *orig_node;
  212. struct batadv_hard_iface *if_incoming;
  213. spinlock_t lq_update_lock; /* protects tq_recv & tq_index */
  214. atomic_t refcount;
  215. struct rcu_head rcu;
  216. };
  217. /**
  218. * struct batadv_bcast_duplist_entry - structure for LAN broadcast suppression
  219. * @orig[ETH_ALEN]: mac address of orig node orginating the broadcast
  220. * @crc: crc32 checksum of broadcast payload
  221. * @entrytime: time when the broadcast packet was received
  222. */
  223. #ifdef CONFIG_BATMAN_ADV_BLA
  224. struct batadv_bcast_duplist_entry {
  225. uint8_t orig[ETH_ALEN];
  226. __be32 crc;
  227. unsigned long entrytime;
  228. };
  229. #endif
  230. /**
  231. * enum batadv_counters - indices for traffic counters
  232. * @BATADV_CNT_TX: transmitted payload traffic packet counter
  233. * @BATADV_CNT_TX_BYTES: transmitted payload traffic bytes counter
  234. * @BATADV_CNT_TX_DROPPED: dropped transmission payload traffic packet counter
  235. * @BATADV_CNT_RX: received payload traffic packet counter
  236. * @BATADV_CNT_RX_BYTES: received payload traffic bytes counter
  237. * @BATADV_CNT_FORWARD: forwarded payload traffic packet counter
  238. * @BATADV_CNT_FORWARD_BYTES: forwarded payload traffic bytes counter
  239. * @BATADV_CNT_MGMT_TX: transmitted routing protocol traffic packet counter
  240. * @BATADV_CNT_MGMT_TX_BYTES: transmitted routing protocol traffic bytes counter
  241. * @BATADV_CNT_MGMT_RX: received routing protocol traffic packet counter
  242. * @BATADV_CNT_MGMT_RX_BYTES: received routing protocol traffic bytes counter
  243. * @BATADV_CNT_TT_REQUEST_TX: transmitted tt req traffic packet counter
  244. * @BATADV_CNT_TT_REQUEST_RX: received tt req traffic packet counter
  245. * @BATADV_CNT_TT_RESPONSE_TX: transmitted tt resp traffic packet counter
  246. * @BATADV_CNT_TT_RESPONSE_RX: received tt resp traffic packet counter
  247. * @BATADV_CNT_TT_ROAM_ADV_TX: transmitted tt roam traffic packet counter
  248. * @BATADV_CNT_TT_ROAM_ADV_RX: received tt roam traffic packet counter
  249. * @BATADV_CNT_DAT_GET_TX: transmitted dht GET traffic packet counter
  250. * @BATADV_CNT_DAT_GET_RX: received dht GET traffic packet counter
  251. * @BATADV_CNT_DAT_PUT_TX: transmitted dht PUT traffic packet counter
  252. * @BATADV_CNT_DAT_PUT_RX: received dht PUT traffic packet counter
  253. * @BATADV_CNT_DAT_CACHED_REPLY_TX: transmitted dat cache reply traffic packet
  254. * counter
  255. * @BATADV_CNT_NUM: number of traffic counters
  256. */
  257. enum batadv_counters {
  258. BATADV_CNT_TX,
  259. BATADV_CNT_TX_BYTES,
  260. BATADV_CNT_TX_DROPPED,
  261. BATADV_CNT_RX,
  262. BATADV_CNT_RX_BYTES,
  263. BATADV_CNT_FORWARD,
  264. BATADV_CNT_FORWARD_BYTES,
  265. BATADV_CNT_MGMT_TX,
  266. BATADV_CNT_MGMT_TX_BYTES,
  267. BATADV_CNT_MGMT_RX,
  268. BATADV_CNT_MGMT_RX_BYTES,
  269. BATADV_CNT_TT_REQUEST_TX,
  270. BATADV_CNT_TT_REQUEST_RX,
  271. BATADV_CNT_TT_RESPONSE_TX,
  272. BATADV_CNT_TT_RESPONSE_RX,
  273. BATADV_CNT_TT_ROAM_ADV_TX,
  274. BATADV_CNT_TT_ROAM_ADV_RX,
  275. #ifdef CONFIG_BATMAN_ADV_DAT
  276. BATADV_CNT_DAT_GET_TX,
  277. BATADV_CNT_DAT_GET_RX,
  278. BATADV_CNT_DAT_PUT_TX,
  279. BATADV_CNT_DAT_PUT_RX,
  280. BATADV_CNT_DAT_CACHED_REPLY_TX,
  281. #endif
  282. BATADV_CNT_NUM,
  283. };
  284. /**
  285. * struct batadv_priv_tt - per mesh interface translation table data
  286. * @vn: translation table version number
  287. * @ogm_append_cnt: counter of number of OGMs containing the local tt diff
  288. * @local_changes: changes registered in an originator interval
  289. * @changes_list: tracks tt local changes within an originator interval
  290. * @local_hash: local translation table hash table
  291. * @global_hash: global translation table hash table
  292. * @req_list: list of pending & unanswered tt_requests
  293. * @roam_list: list of the last roaming events of each client limiting the
  294. * number of roaming events to avoid route flapping
  295. * @changes_list_lock: lock protecting changes_list
  296. * @req_list_lock: lock protecting req_list
  297. * @roam_list_lock: lock protecting roam_list
  298. * @local_entry_num: number of entries in the local hash table
  299. * @local_crc: Checksum of the local table, recomputed before sending a new OGM
  300. * @last_changeset: last tt changeset this host has generated
  301. * @last_changeset_len: length of last tt changeset this host has generated
  302. * @last_changeset_lock: lock protecting last_changeset & last_changeset_len
  303. * @work: work queue callback item for translation table purging
  304. */
  305. struct batadv_priv_tt {
  306. atomic_t vn;
  307. atomic_t ogm_append_cnt;
  308. atomic_t local_changes;
  309. struct list_head changes_list;
  310. struct batadv_hashtable *local_hash;
  311. struct batadv_hashtable *global_hash;
  312. struct list_head req_list;
  313. struct list_head roam_list;
  314. spinlock_t changes_list_lock; /* protects changes */
  315. spinlock_t req_list_lock; /* protects req_list */
  316. spinlock_t roam_list_lock; /* protects roam_list */
  317. atomic_t local_entry_num;
  318. uint16_t local_crc;
  319. unsigned char *last_changeset;
  320. int16_t last_changeset_len;
  321. /* protects last_changeset & last_changeset_len */
  322. spinlock_t last_changeset_lock;
  323. struct delayed_work work;
  324. };
  325. /**
  326. * struct batadv_priv_bla - per mesh interface bridge loope avoidance data
  327. * @num_requests; number of bla requests in flight
  328. * @claim_hash: hash table containing mesh nodes this host has claimed
  329. * @backbone_hash: hash table containing all detected backbone gateways
  330. * @bcast_duplist: recently received broadcast packets array (for broadcast
  331. * duplicate suppression)
  332. * @bcast_duplist_curr: index of last broadcast packet added to bcast_duplist
  333. * @bcast_duplist_lock: lock protecting bcast_duplist & bcast_duplist_curr
  334. * @claim_dest: local claim data (e.g. claim group)
  335. * @work: work queue callback item for cleanups & bla announcements
  336. */
  337. #ifdef CONFIG_BATMAN_ADV_BLA
  338. struct batadv_priv_bla {
  339. atomic_t num_requests;
  340. struct batadv_hashtable *claim_hash;
  341. struct batadv_hashtable *backbone_hash;
  342. struct batadv_bcast_duplist_entry bcast_duplist[BATADV_DUPLIST_SIZE];
  343. int bcast_duplist_curr;
  344. /* protects bcast_duplist & bcast_duplist_curr */
  345. spinlock_t bcast_duplist_lock;
  346. struct batadv_bla_claim_dst claim_dest;
  347. struct delayed_work work;
  348. };
  349. #endif
  350. /**
  351. * struct batadv_debug_log - debug logging data
  352. * @log_buff: buffer holding the logs (ring bufer)
  353. * @log_start: index of next character to read
  354. * @log_end: index of next character to write
  355. * @lock: lock protecting log_buff, log_start & log_end
  356. * @queue_wait: log reader's wait queue
  357. */
  358. #ifdef CONFIG_BATMAN_ADV_DEBUG
  359. struct batadv_priv_debug_log {
  360. char log_buff[BATADV_LOG_BUF_LEN];
  361. unsigned long log_start;
  362. unsigned long log_end;
  363. spinlock_t lock; /* protects log_buff, log_start and log_end */
  364. wait_queue_head_t queue_wait;
  365. };
  366. #endif
  367. /**
  368. * struct batadv_priv_gw - per mesh interface gateway data
  369. * @list: list of available gateway nodes
  370. * @list_lock: lock protecting gw_list & curr_gw
  371. * @curr_gw: pointer to currently selected gateway node
  372. * @reselect: bool indicating a gateway re-selection is in progress
  373. */
  374. struct batadv_priv_gw {
  375. struct hlist_head list;
  376. spinlock_t list_lock; /* protects gw_list & curr_gw */
  377. struct batadv_gw_node __rcu *curr_gw; /* rcu protected pointer */
  378. atomic_t reselect;
  379. };
  380. /**
  381. * struct batadv_priv_vis - per mesh interface vis data
  382. * @send_list: list of batadv_vis_info packets to sent
  383. * @hash: hash table containing vis data from other nodes in the network
  384. * @hash_lock: lock protecting the hash table
  385. * @list_lock: lock protecting my_info::recv_list
  386. * @work: work queue callback item for vis packet sending
  387. * @my_info: holds this node's vis data sent on a regular basis
  388. */
  389. struct batadv_priv_vis {
  390. struct list_head send_list;
  391. struct batadv_hashtable *hash;
  392. spinlock_t hash_lock; /* protects hash */
  393. spinlock_t list_lock; /* protects my_info::recv_list */
  394. struct delayed_work work;
  395. struct batadv_vis_info *my_info;
  396. };
  397. /**
  398. * struct batadv_priv_dat - per mesh interface DAT private data
  399. * @addr: node DAT address
  400. * @hash: hashtable representing the local ARP cache
  401. * @work: work queue callback item for cache purging
  402. */
  403. #ifdef CONFIG_BATMAN_ADV_DAT
  404. struct batadv_priv_dat {
  405. batadv_dat_addr_t addr;
  406. struct batadv_hashtable *hash;
  407. struct delayed_work work;
  408. };
  409. #endif
  410. /**
  411. * struct batadv_priv - per mesh interface data
  412. * @mesh_state: current status of the mesh (inactive/active/deactivating)
  413. * @soft_iface: net device which holds this struct as private data
  414. * @stats: structure holding the data for the ndo_get_stats() call
  415. * @bat_counters: mesh internal traffic statistic counters (see batadv_counters)
  416. * @aggregated_ogms: bool indicating whether OGM aggregation is enabled
  417. * @bonding: bool indicating whether traffic bonding is enabled
  418. * @fragmentation: bool indicating whether traffic fragmentation is enabled
  419. * @ap_isolation: bool indicating whether ap isolation is enabled
  420. * @bridge_loop_avoidance: bool indicating whether bridge loop avoidance is
  421. * enabled
  422. * @distributed_arp_table: bool indicating whether distributed ARP table is
  423. * enabled
  424. * @vis_mode: vis operation: client or server (see batadv_vis_packettype)
  425. * @gw_mode: gateway operation: off, client or server (see batadv_gw_modes)
  426. * @gw_sel_class: gateway selection class (applies if gw_mode client)
  427. * @gw_bandwidth: gateway announced bandwidth (applies if gw_mode server)
  428. * @orig_interval: OGM broadcast interval in milliseconds
  429. * @hop_penalty: penalty which will be applied to an OGM's tq-field on every hop
  430. * @log_level: configured log level (see batadv_dbg_level)
  431. * @bcast_seqno: last sent broadcast packet sequence number
  432. * @bcast_queue_left: number of remaining buffered broadcast packet slots
  433. * @batman_queue_left: number of remaining OGM packet slots
  434. * @num_ifaces: number of interfaces assigned to this mesh interface
  435. * @mesh_obj: kobject for sysfs mesh subdirectory
  436. * @debug_dir: dentry for debugfs batman-adv subdirectory
  437. * @forw_bat_list: list of aggregated OGMs that will be forwarded
  438. * @forw_bcast_list: list of broadcast packets that will be rebroadcasted
  439. * @orig_hash: hash table containing mesh participants (orig nodes)
  440. * @forw_bat_list_lock: lock protecting forw_bat_list
  441. * @forw_bcast_list_lock: lock protecting forw_bcast_list
  442. * @orig_work: work queue callback item for orig node purging
  443. * @cleanup_work: work queue callback item for soft interface deinit
  444. * @primary_if: one of the hard interfaces assigned to this mesh interface
  445. * becomes the primary interface
  446. * @bat_algo_ops: routing algorithm used by this mesh interface
  447. * @bla: bridge loope avoidance data
  448. * @debug_log: holding debug logging relevant data
  449. * @gw: gateway data
  450. * @tt: translation table data
  451. * @vis: vis data
  452. * @dat: distributed arp table data
  453. */
  454. struct batadv_priv {
  455. atomic_t mesh_state;
  456. struct net_device *soft_iface;
  457. struct net_device_stats stats;
  458. uint64_t __percpu *bat_counters; /* Per cpu counters */
  459. atomic_t aggregated_ogms;
  460. atomic_t bonding;
  461. atomic_t fragmentation;
  462. atomic_t ap_isolation;
  463. #ifdef CONFIG_BATMAN_ADV_BLA
  464. atomic_t bridge_loop_avoidance;
  465. #endif
  466. #ifdef CONFIG_BATMAN_ADV_DAT
  467. atomic_t distributed_arp_table;
  468. #endif
  469. atomic_t vis_mode;
  470. atomic_t gw_mode;
  471. atomic_t gw_sel_class;
  472. atomic_t gw_bandwidth;
  473. atomic_t orig_interval;
  474. atomic_t hop_penalty;
  475. #ifdef CONFIG_BATMAN_ADV_DEBUG
  476. atomic_t log_level;
  477. #endif
  478. atomic_t bcast_seqno;
  479. atomic_t bcast_queue_left;
  480. atomic_t batman_queue_left;
  481. char num_ifaces;
  482. struct kobject *mesh_obj;
  483. struct dentry *debug_dir;
  484. struct hlist_head forw_bat_list;
  485. struct hlist_head forw_bcast_list;
  486. struct batadv_hashtable *orig_hash;
  487. spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
  488. spinlock_t forw_bcast_list_lock; /* protects forw_bcast_list */
  489. struct delayed_work orig_work;
  490. struct work_struct cleanup_work;
  491. struct batadv_hard_iface __rcu *primary_if; /* rcu protected pointer */
  492. struct batadv_algo_ops *bat_algo_ops;
  493. #ifdef CONFIG_BATMAN_ADV_BLA
  494. struct batadv_priv_bla bla;
  495. #endif
  496. #ifdef CONFIG_BATMAN_ADV_DEBUG
  497. struct batadv_priv_debug_log *debug_log;
  498. #endif
  499. struct batadv_priv_gw gw;
  500. struct batadv_priv_tt tt;
  501. struct batadv_priv_vis vis;
  502. #ifdef CONFIG_BATMAN_ADV_DAT
  503. struct batadv_priv_dat dat;
  504. #endif
  505. };
  506. /**
  507. * struct batadv_socket_client - layer2 icmp socket client data
  508. * @queue_list: packet queue for packets destined for this socket client
  509. * @queue_len: number of packets in the packet queue (queue_list)
  510. * @index: socket client's index in the batadv_socket_client_hash
  511. * @lock: lock protecting queue_list, queue_len & index
  512. * @queue_wait: socket client's wait queue
  513. * @bat_priv: pointer to soft_iface this client belongs to
  514. */
  515. struct batadv_socket_client {
  516. struct list_head queue_list;
  517. unsigned int queue_len;
  518. unsigned char index;
  519. spinlock_t lock; /* protects queue_list, queue_len & index */
  520. wait_queue_head_t queue_wait;
  521. struct batadv_priv *bat_priv;
  522. };
  523. /**
  524. * struct batadv_socket_packet - layer2 icmp packet for socket client
  525. * @list: list node for batadv_socket_client::queue_list
  526. * @icmp_len: size of the layer2 icmp packet
  527. * @icmp_packet: layer2 icmp packet
  528. */
  529. struct batadv_socket_packet {
  530. struct list_head list;
  531. size_t icmp_len;
  532. struct batadv_icmp_packet_rr icmp_packet;
  533. };
  534. /**
  535. * struct batadv_bla_backbone_gw - batman-adv gateway bridged into the LAN
  536. * @orig: originator address of backbone node (mac address of primary iface)
  537. * @vid: vlan id this gateway was detected on
  538. * @hash_entry: hlist node for batadv_priv_bla::backbone_hash
  539. * @bat_priv: pointer to soft_iface this backbone gateway belongs to
  540. * @lasttime: last time we heard of this backbone gw
  541. * @wait_periods: grace time for bridge forward delays and bla group forming at
  542. * bootup phase - no bcast traffic is formwared until it has elapsed
  543. * @request_sent: if this bool is set to true we are out of sync with this
  544. * backbone gateway - no bcast traffic is formwared until the situation was
  545. * resolved
  546. * @crc: crc16 checksum over all claims
  547. * @refcount: number of contexts the object is used
  548. * @rcu: struct used for freeing in an RCU-safe manner
  549. */
  550. #ifdef CONFIG_BATMAN_ADV_BLA
  551. struct batadv_bla_backbone_gw {
  552. uint8_t orig[ETH_ALEN];
  553. short vid;
  554. struct hlist_node hash_entry;
  555. struct batadv_priv *bat_priv;
  556. unsigned long lasttime;
  557. atomic_t wait_periods;
  558. atomic_t request_sent;
  559. uint16_t crc;
  560. atomic_t refcount;
  561. struct rcu_head rcu;
  562. };
  563. /**
  564. * struct batadv_bla_claim - claimed non-mesh client structure
  565. * @addr: mac address of claimed non-mesh client
  566. * @vid: vlan id this client was detected on
  567. * @batadv_bla_backbone_gw: pointer to backbone gw claiming this client
  568. * @lasttime: last time we heard of claim (locals only)
  569. * @hash_entry: hlist node for batadv_priv_bla::claim_hash
  570. * @refcount: number of contexts the object is used
  571. * @rcu: struct used for freeing in an RCU-safe manner
  572. */
  573. struct batadv_bla_claim {
  574. uint8_t addr[ETH_ALEN];
  575. short vid;
  576. struct batadv_bla_backbone_gw *backbone_gw;
  577. unsigned long lasttime;
  578. struct hlist_node hash_entry;
  579. struct rcu_head rcu;
  580. atomic_t refcount;
  581. };
  582. #endif
  583. /**
  584. * struct batadv_tt_common_entry - tt local & tt global common data
  585. * @addr: mac address of non-mesh client
  586. * @hash_entry: hlist node for batadv_priv_tt::local_hash or for
  587. * batadv_priv_tt::global_hash
  588. * @flags: various state handling flags (see batadv_tt_client_flags)
  589. * @added_at: timestamp used for purging stale tt common entries
  590. * @refcount: number of contexts the object is used
  591. * @rcu: struct used for freeing in an RCU-safe manner
  592. */
  593. struct batadv_tt_common_entry {
  594. uint8_t addr[ETH_ALEN];
  595. struct hlist_node hash_entry;
  596. uint16_t flags;
  597. unsigned long added_at;
  598. atomic_t refcount;
  599. struct rcu_head rcu;
  600. };
  601. /**
  602. * struct batadv_tt_local_entry - translation table local entry data
  603. * @common: general translation table data
  604. * @last_seen: timestamp used for purging stale tt local entries
  605. */
  606. struct batadv_tt_local_entry {
  607. struct batadv_tt_common_entry common;
  608. unsigned long last_seen;
  609. };
  610. /**
  611. * struct batadv_tt_global_entry - translation table global entry data
  612. * @common: general translation table data
  613. * @orig_list: list of orig nodes announcing this non-mesh client
  614. * @list_lock: lock protecting orig_list
  615. * @roam_at: time at which TT_GLOBAL_ROAM was set
  616. */
  617. struct batadv_tt_global_entry {
  618. struct batadv_tt_common_entry common;
  619. struct hlist_head orig_list;
  620. spinlock_t list_lock; /* protects orig_list */
  621. unsigned long roam_at;
  622. };
  623. /**
  624. * struct batadv_tt_orig_list_entry - orig node announcing a non-mesh client
  625. * @orig_node: pointer to orig node announcing this non-mesh client
  626. * @ttvn: translation table version number which added the non-mesh client
  627. * @list: list node for batadv_tt_global_entry::orig_list
  628. * @refcount: number of contexts the object is used
  629. * @rcu: struct used for freeing in an RCU-safe manner
  630. */
  631. struct batadv_tt_orig_list_entry {
  632. struct batadv_orig_node *orig_node;
  633. uint8_t ttvn;
  634. struct hlist_node list;
  635. atomic_t refcount;
  636. struct rcu_head rcu;
  637. };
  638. /**
  639. * struct batadv_tt_change_node - structure for tt changes occured
  640. * @list: list node for batadv_priv_tt::changes_list
  641. * @change: holds the actual translation table diff data
  642. */
  643. struct batadv_tt_change_node {
  644. struct list_head list;
  645. struct batadv_tt_change change;
  646. };
  647. /**
  648. * struct batadv_tt_req_node - data to keep track of the tt requests in flight
  649. * @addr: mac address address of the originator this request was sent to
  650. * @issued_at: timestamp used for purging stale tt requests
  651. * @list: list node for batadv_priv_tt::req_list
  652. */
  653. struct batadv_tt_req_node {
  654. uint8_t addr[ETH_ALEN];
  655. unsigned long issued_at;
  656. struct list_head list;
  657. };
  658. /**
  659. * struct batadv_tt_roam_node - roaming client data
  660. * @addr: mac address of the client in the roaming phase
  661. * @counter: number of allowed roaming events per client within a single
  662. * OGM interval (changes are committed with each OGM)
  663. * @first_time: timestamp used for purging stale roaming node entries
  664. * @list: list node for batadv_priv_tt::roam_list
  665. */
  666. struct batadv_tt_roam_node {
  667. uint8_t addr[ETH_ALEN];
  668. atomic_t counter;
  669. unsigned long first_time;
  670. struct list_head list;
  671. };
  672. /**
  673. * struct batadv_forw_packet - structure for bcast packets to be sent/forwarded
  674. * @list: list node for batadv_socket_client::queue_list
  675. * @send_time: execution time for delayed_work (packet sending)
  676. * @own: bool for locally generated packets (local OGMs are re-scheduled after
  677. * sending)
  678. * @skb: bcast packet's skb buffer
  679. * @packet_len: size of aggregated OGM packet inside the skb buffer
  680. * @direct_link_flags: direct link flags for aggregated OGM packets
  681. * @num_packets: counter for bcast packet retransmission
  682. * @delayed_work: work queue callback item for packet sending
  683. * @if_incoming: pointer incoming hard-iface or primary iface if locally
  684. * generated packet
  685. */
  686. struct batadv_forw_packet {
  687. struct hlist_node list;
  688. unsigned long send_time;
  689. uint8_t own;
  690. struct sk_buff *skb;
  691. uint16_t packet_len;
  692. uint32_t direct_link_flags;
  693. uint8_t num_packets;
  694. struct delayed_work delayed_work;
  695. struct batadv_hard_iface *if_incoming;
  696. };
  697. /**
  698. * struct batadv_frag_packet_list_entry - storage for fragment packet
  699. * @list: list node for orig_node::frag_list
  700. * @seqno: sequence number of the fragment
  701. * @skb: fragment's skb buffer
  702. */
  703. struct batadv_frag_packet_list_entry {
  704. struct list_head list;
  705. uint16_t seqno;
  706. struct sk_buff *skb;
  707. };
  708. /**
  709. * struct batadv_vis_info - local data for vis information
  710. * @first_seen: timestamp used for purging stale vis info entries
  711. * @recv_list: List of server-neighbors we have received this packet from. This
  712. * packet should not be re-forward to them again. List elements are struct
  713. * batadv_vis_recvlist_node
  714. * @send_list: list of packets to be forwarded
  715. * @refcount: number of contexts the object is used
  716. * @hash_entry: hlist node for batadv_priv_vis::hash
  717. * @bat_priv: pointer to soft_iface this orig node belongs to
  718. * @skb_packet: contains the vis packet
  719. */
  720. struct batadv_vis_info {
  721. unsigned long first_seen;
  722. struct list_head recv_list;
  723. struct list_head send_list;
  724. struct kref refcount;
  725. struct hlist_node hash_entry;
  726. struct batadv_priv *bat_priv;
  727. struct sk_buff *skb_packet;
  728. } __packed;
  729. /**
  730. * struct batadv_vis_info_entry - contains link information for vis
  731. * @src: source MAC of the link, all zero for local TT entry
  732. * @dst: destination MAC of the link, client mac address for local TT entry
  733. * @quality: transmission quality of the link, or 0 for local TT entry
  734. */
  735. struct batadv_vis_info_entry {
  736. uint8_t src[ETH_ALEN];
  737. uint8_t dest[ETH_ALEN];
  738. uint8_t quality;
  739. } __packed;
  740. /**
  741. * struct batadv_vis_recvlist_node - list entry for batadv_vis_info::recv_list
  742. * @list: list node for batadv_vis_info::recv_list
  743. * @mac: MAC address of the originator from where the vis_info was received
  744. */
  745. struct batadv_vis_recvlist_node {
  746. struct list_head list;
  747. uint8_t mac[ETH_ALEN];
  748. };
  749. /**
  750. * struct batadv_vis_if_list_entry - auxiliary data for vis data generation
  751. * @addr: MAC address of the interface
  752. * @primary: true if this interface is the primary interface
  753. * @list: list node the interface list
  754. *
  755. * While scanning for vis-entries of a particular vis-originator
  756. * this list collects its interfaces to create a subgraph/cluster
  757. * out of them later
  758. */
  759. struct batadv_vis_if_list_entry {
  760. uint8_t addr[ETH_ALEN];
  761. bool primary;
  762. struct hlist_node list;
  763. };
  764. /**
  765. * struct batadv_algo_ops - mesh algorithm callbacks
  766. * @list: list node for the batadv_algo_list
  767. * @name: name of the algorithm
  768. * @bat_iface_enable: init routing info when hard-interface is enabled
  769. * @bat_iface_disable: de-init routing info when hard-interface is disabled
  770. * @bat_iface_update_mac: (re-)init mac addresses of the protocol information
  771. * belonging to this hard-interface
  772. * @bat_primary_iface_set: called when primary interface is selected / changed
  773. * @bat_ogm_schedule: prepare a new outgoing OGM for the send queue
  774. * @bat_ogm_emit: send scheduled OGM
  775. */
  776. struct batadv_algo_ops {
  777. struct hlist_node list;
  778. char *name;
  779. int (*bat_iface_enable)(struct batadv_hard_iface *hard_iface);
  780. void (*bat_iface_disable)(struct batadv_hard_iface *hard_iface);
  781. void (*bat_iface_update_mac)(struct batadv_hard_iface *hard_iface);
  782. void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);
  783. void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);
  784. void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
  785. };
  786. /**
  787. * struct batadv_dat_entry - it is a single entry of batman-adv ARP backend. It
  788. * is used to stored ARP entries needed for the global DAT cache
  789. * @ip: the IPv4 corresponding to this DAT/ARP entry
  790. * @mac_addr: the MAC address associated to the stored IPv4
  791. * @last_update: time in jiffies when this entry was refreshed last time
  792. * @hash_entry: hlist node for batadv_priv_dat::hash
  793. * @refcount: number of contexts the object is used
  794. * @rcu: struct used for freeing in an RCU-safe manner
  795. */
  796. struct batadv_dat_entry {
  797. __be32 ip;
  798. uint8_t mac_addr[ETH_ALEN];
  799. unsigned long last_update;
  800. struct hlist_node hash_entry;
  801. atomic_t refcount;
  802. struct rcu_head rcu;
  803. };
  804. /**
  805. * struct batadv_dat_candidate - candidate destination for DAT operations
  806. * @type: the type of the selected candidate. It can one of the following:
  807. * - BATADV_DAT_CANDIDATE_NOT_FOUND
  808. * - BATADV_DAT_CANDIDATE_ORIG
  809. * @orig_node: if type is BATADV_DAT_CANDIDATE_ORIG this field points to the
  810. * corresponding originator node structure
  811. */
  812. struct batadv_dat_candidate {
  813. int type;
  814. struct batadv_orig_node *orig_node;
  815. };
  816. #endif /* _NET_BATMAN_ADV_TYPES_H_ */