types.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  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. * @in_coding_list: list of nodes this orig can hear
  123. * @out_coding_list: list of nodes that can hear this orig
  124. * @in_coding_list_lock: protects in_coding_list
  125. * @out_coding_list_lock: protects out_coding_list
  126. */
  127. struct batadv_orig_node {
  128. uint8_t orig[ETH_ALEN];
  129. uint8_t primary_addr[ETH_ALEN];
  130. struct batadv_neigh_node __rcu *router; /* rcu protected pointer */
  131. #ifdef CONFIG_BATMAN_ADV_DAT
  132. batadv_dat_addr_t dat_addr;
  133. #endif
  134. unsigned long *bcast_own;
  135. uint8_t *bcast_own_sum;
  136. unsigned long last_seen;
  137. unsigned long bcast_seqno_reset;
  138. unsigned long batman_seqno_reset;
  139. uint8_t gw_flags;
  140. uint8_t flags;
  141. atomic_t last_ttvn;
  142. uint16_t tt_crc;
  143. unsigned char *tt_buff;
  144. int16_t tt_buff_len;
  145. spinlock_t tt_buff_lock; /* protects tt_buff & tt_buff_len */
  146. atomic_t tt_size;
  147. bool tt_initialised;
  148. uint32_t last_real_seqno;
  149. uint8_t last_ttl;
  150. DECLARE_BITMAP(bcast_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
  151. uint32_t last_bcast_seqno;
  152. struct hlist_head neigh_list;
  153. struct list_head frag_list;
  154. unsigned long last_frag_packet;
  155. /* neigh_list_lock protects: neigh_list, router & bonding_list */
  156. spinlock_t neigh_list_lock;
  157. struct hlist_node hash_entry;
  158. struct batadv_priv *bat_priv;
  159. /* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
  160. * neigh_node->real_bits & neigh_node->real_packet_count
  161. */
  162. spinlock_t ogm_cnt_lock;
  163. /* bcast_seqno_lock protects: bcast_bits & last_bcast_seqno */
  164. spinlock_t bcast_seqno_lock;
  165. atomic_t bond_candidates;
  166. struct list_head bond_list;
  167. atomic_t refcount;
  168. struct rcu_head rcu;
  169. #ifdef CONFIG_BATMAN_ADV_NC
  170. struct list_head in_coding_list;
  171. struct list_head out_coding_list;
  172. spinlock_t in_coding_list_lock; /* Protects in_coding_list */
  173. spinlock_t out_coding_list_lock; /* Protects out_coding_list */
  174. #endif
  175. };
  176. /**
  177. * struct batadv_gw_node - structure for orig nodes announcing gw capabilities
  178. * @list: list node for batadv_priv_gw::list
  179. * @orig_node: pointer to corresponding orig node
  180. * @deleted: this struct is scheduled for deletion
  181. * @refcount: number of contexts the object is used
  182. * @rcu: struct used for freeing in an RCU-safe manner
  183. */
  184. struct batadv_gw_node {
  185. struct hlist_node list;
  186. struct batadv_orig_node *orig_node;
  187. unsigned long deleted;
  188. atomic_t refcount;
  189. struct rcu_head rcu;
  190. };
  191. /**
  192. * struct batadv_neigh_node - structure for single hop neighbors
  193. * @list: list node for batadv_orig_node::neigh_list
  194. * @addr: mac address of neigh node
  195. * @tq_recv: ring buffer of received TQ values from this neigh node
  196. * @tq_index: ring buffer index
  197. * @tq_avg: averaged tq of all tq values in the ring buffer (tq_recv)
  198. * @last_ttl: last received ttl from this neigh node
  199. * @bonding_list: list node for batadv_orig_node::bond_list
  200. * @last_seen: when last packet via this neighbor was received
  201. * @real_bits: bitfield containing the number of OGMs received from this neigh
  202. * node (relative to orig_node->last_real_seqno)
  203. * @real_packet_count: counted result of real_bits
  204. * @orig_node: pointer to corresponding orig_node
  205. * @if_incoming: pointer to incoming hard interface
  206. * @lq_update_lock: lock protecting tq_recv & tq_index
  207. * @refcount: number of contexts the object is used
  208. * @rcu: struct used for freeing in an RCU-safe manner
  209. */
  210. struct batadv_neigh_node {
  211. struct hlist_node list;
  212. uint8_t addr[ETH_ALEN];
  213. uint8_t tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE];
  214. uint8_t tq_index;
  215. uint8_t tq_avg;
  216. uint8_t last_ttl;
  217. struct list_head bonding_list;
  218. unsigned long last_seen;
  219. DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
  220. uint8_t real_packet_count;
  221. struct batadv_orig_node *orig_node;
  222. struct batadv_hard_iface *if_incoming;
  223. spinlock_t lq_update_lock; /* protects tq_recv & tq_index */
  224. atomic_t refcount;
  225. struct rcu_head rcu;
  226. };
  227. /**
  228. * struct batadv_bcast_duplist_entry - structure for LAN broadcast suppression
  229. * @orig[ETH_ALEN]: mac address of orig node orginating the broadcast
  230. * @crc: crc32 checksum of broadcast payload
  231. * @entrytime: time when the broadcast packet was received
  232. */
  233. #ifdef CONFIG_BATMAN_ADV_BLA
  234. struct batadv_bcast_duplist_entry {
  235. uint8_t orig[ETH_ALEN];
  236. __be32 crc;
  237. unsigned long entrytime;
  238. };
  239. #endif
  240. /**
  241. * enum batadv_counters - indices for traffic counters
  242. * @BATADV_CNT_TX: transmitted payload traffic packet counter
  243. * @BATADV_CNT_TX_BYTES: transmitted payload traffic bytes counter
  244. * @BATADV_CNT_TX_DROPPED: dropped transmission payload traffic packet counter
  245. * @BATADV_CNT_RX: received payload traffic packet counter
  246. * @BATADV_CNT_RX_BYTES: received payload traffic bytes counter
  247. * @BATADV_CNT_FORWARD: forwarded payload traffic packet counter
  248. * @BATADV_CNT_FORWARD_BYTES: forwarded payload traffic bytes counter
  249. * @BATADV_CNT_MGMT_TX: transmitted routing protocol traffic packet counter
  250. * @BATADV_CNT_MGMT_TX_BYTES: transmitted routing protocol traffic bytes counter
  251. * @BATADV_CNT_MGMT_RX: received routing protocol traffic packet counter
  252. * @BATADV_CNT_MGMT_RX_BYTES: received routing protocol traffic bytes counter
  253. * @BATADV_CNT_TT_REQUEST_TX: transmitted tt req traffic packet counter
  254. * @BATADV_CNT_TT_REQUEST_RX: received tt req traffic packet counter
  255. * @BATADV_CNT_TT_RESPONSE_TX: transmitted tt resp traffic packet counter
  256. * @BATADV_CNT_TT_RESPONSE_RX: received tt resp traffic packet counter
  257. * @BATADV_CNT_TT_ROAM_ADV_TX: transmitted tt roam traffic packet counter
  258. * @BATADV_CNT_TT_ROAM_ADV_RX: received tt roam traffic packet counter
  259. * @BATADV_CNT_DAT_GET_TX: transmitted dht GET traffic packet counter
  260. * @BATADV_CNT_DAT_GET_RX: received dht GET traffic packet counter
  261. * @BATADV_CNT_DAT_PUT_TX: transmitted dht PUT traffic packet counter
  262. * @BATADV_CNT_DAT_PUT_RX: received dht PUT traffic packet counter
  263. * @BATADV_CNT_DAT_CACHED_REPLY_TX: transmitted dat cache reply traffic packet
  264. * counter
  265. * @BATADV_CNT_NC_CODE: transmitted nc-combined traffic packet counter
  266. * @BATADV_CNT_NC_CODE_BYTES: transmitted nc-combined traffic bytes counter
  267. * @BATADV_CNT_NC_RECODE: transmitted nc-recombined traffic packet counter
  268. * @BATADV_CNT_NC_RECODE_BYTES: transmitted nc-recombined traffic bytes counter
  269. * @BATADV_CNT_NC_BUFFER: counter for packets buffered for later nc decoding
  270. * @BATADV_CNT_NC_DECODE: received and nc-decoded traffic packet counter
  271. * @BATADV_CNT_NC_DECODE_BYTES: received and nc-decoded traffic bytes counter
  272. * @BATADV_CNT_NC_DECODE_FAILED: received and decode-failed traffic packet
  273. * counter
  274. * @BATADV_CNT_NC_SNIFFED: counter for nc-decoded packets received in promisc
  275. * mode.
  276. * @BATADV_CNT_NUM: number of traffic counters
  277. */
  278. enum batadv_counters {
  279. BATADV_CNT_TX,
  280. BATADV_CNT_TX_BYTES,
  281. BATADV_CNT_TX_DROPPED,
  282. BATADV_CNT_RX,
  283. BATADV_CNT_RX_BYTES,
  284. BATADV_CNT_FORWARD,
  285. BATADV_CNT_FORWARD_BYTES,
  286. BATADV_CNT_MGMT_TX,
  287. BATADV_CNT_MGMT_TX_BYTES,
  288. BATADV_CNT_MGMT_RX,
  289. BATADV_CNT_MGMT_RX_BYTES,
  290. BATADV_CNT_TT_REQUEST_TX,
  291. BATADV_CNT_TT_REQUEST_RX,
  292. BATADV_CNT_TT_RESPONSE_TX,
  293. BATADV_CNT_TT_RESPONSE_RX,
  294. BATADV_CNT_TT_ROAM_ADV_TX,
  295. BATADV_CNT_TT_ROAM_ADV_RX,
  296. #ifdef CONFIG_BATMAN_ADV_DAT
  297. BATADV_CNT_DAT_GET_TX,
  298. BATADV_CNT_DAT_GET_RX,
  299. BATADV_CNT_DAT_PUT_TX,
  300. BATADV_CNT_DAT_PUT_RX,
  301. BATADV_CNT_DAT_CACHED_REPLY_TX,
  302. #endif
  303. #ifdef CONFIG_BATMAN_ADV_NC
  304. BATADV_CNT_NC_CODE,
  305. BATADV_CNT_NC_CODE_BYTES,
  306. BATADV_CNT_NC_RECODE,
  307. BATADV_CNT_NC_RECODE_BYTES,
  308. BATADV_CNT_NC_BUFFER,
  309. BATADV_CNT_NC_DECODE,
  310. BATADV_CNT_NC_DECODE_BYTES,
  311. BATADV_CNT_NC_DECODE_FAILED,
  312. BATADV_CNT_NC_SNIFFED,
  313. #endif
  314. BATADV_CNT_NUM,
  315. };
  316. /**
  317. * struct batadv_priv_tt - per mesh interface translation table data
  318. * @vn: translation table version number
  319. * @ogm_append_cnt: counter of number of OGMs containing the local tt diff
  320. * @local_changes: changes registered in an originator interval
  321. * @changes_list: tracks tt local changes within an originator interval
  322. * @local_hash: local translation table hash table
  323. * @global_hash: global translation table hash table
  324. * @req_list: list of pending & unanswered tt_requests
  325. * @roam_list: list of the last roaming events of each client limiting the
  326. * number of roaming events to avoid route flapping
  327. * @changes_list_lock: lock protecting changes_list
  328. * @req_list_lock: lock protecting req_list
  329. * @roam_list_lock: lock protecting roam_list
  330. * @local_entry_num: number of entries in the local hash table
  331. * @local_crc: Checksum of the local table, recomputed before sending a new OGM
  332. * @last_changeset: last tt changeset this host has generated
  333. * @last_changeset_len: length of last tt changeset this host has generated
  334. * @last_changeset_lock: lock protecting last_changeset & last_changeset_len
  335. * @work: work queue callback item for translation table purging
  336. */
  337. struct batadv_priv_tt {
  338. atomic_t vn;
  339. atomic_t ogm_append_cnt;
  340. atomic_t local_changes;
  341. struct list_head changes_list;
  342. struct batadv_hashtable *local_hash;
  343. struct batadv_hashtable *global_hash;
  344. struct list_head req_list;
  345. struct list_head roam_list;
  346. spinlock_t changes_list_lock; /* protects changes */
  347. spinlock_t req_list_lock; /* protects req_list */
  348. spinlock_t roam_list_lock; /* protects roam_list */
  349. atomic_t local_entry_num;
  350. uint16_t local_crc;
  351. unsigned char *last_changeset;
  352. int16_t last_changeset_len;
  353. /* protects last_changeset & last_changeset_len */
  354. spinlock_t last_changeset_lock;
  355. struct delayed_work work;
  356. };
  357. /**
  358. * struct batadv_priv_bla - per mesh interface bridge loope avoidance data
  359. * @num_requests; number of bla requests in flight
  360. * @claim_hash: hash table containing mesh nodes this host has claimed
  361. * @backbone_hash: hash table containing all detected backbone gateways
  362. * @bcast_duplist: recently received broadcast packets array (for broadcast
  363. * duplicate suppression)
  364. * @bcast_duplist_curr: index of last broadcast packet added to bcast_duplist
  365. * @bcast_duplist_lock: lock protecting bcast_duplist & bcast_duplist_curr
  366. * @claim_dest: local claim data (e.g. claim group)
  367. * @work: work queue callback item for cleanups & bla announcements
  368. */
  369. #ifdef CONFIG_BATMAN_ADV_BLA
  370. struct batadv_priv_bla {
  371. atomic_t num_requests;
  372. struct batadv_hashtable *claim_hash;
  373. struct batadv_hashtable *backbone_hash;
  374. struct batadv_bcast_duplist_entry bcast_duplist[BATADV_DUPLIST_SIZE];
  375. int bcast_duplist_curr;
  376. /* protects bcast_duplist & bcast_duplist_curr */
  377. spinlock_t bcast_duplist_lock;
  378. struct batadv_bla_claim_dst claim_dest;
  379. struct delayed_work work;
  380. };
  381. #endif
  382. /**
  383. * struct batadv_debug_log - debug logging data
  384. * @log_buff: buffer holding the logs (ring bufer)
  385. * @log_start: index of next character to read
  386. * @log_end: index of next character to write
  387. * @lock: lock protecting log_buff, log_start & log_end
  388. * @queue_wait: log reader's wait queue
  389. */
  390. #ifdef CONFIG_BATMAN_ADV_DEBUG
  391. struct batadv_priv_debug_log {
  392. char log_buff[BATADV_LOG_BUF_LEN];
  393. unsigned long log_start;
  394. unsigned long log_end;
  395. spinlock_t lock; /* protects log_buff, log_start and log_end */
  396. wait_queue_head_t queue_wait;
  397. };
  398. #endif
  399. /**
  400. * struct batadv_priv_gw - per mesh interface gateway data
  401. * @list: list of available gateway nodes
  402. * @list_lock: lock protecting gw_list & curr_gw
  403. * @curr_gw: pointer to currently selected gateway node
  404. * @reselect: bool indicating a gateway re-selection is in progress
  405. */
  406. struct batadv_priv_gw {
  407. struct hlist_head list;
  408. spinlock_t list_lock; /* protects gw_list & curr_gw */
  409. struct batadv_gw_node __rcu *curr_gw; /* rcu protected pointer */
  410. atomic_t reselect;
  411. };
  412. /**
  413. * struct batadv_priv_vis - per mesh interface vis data
  414. * @send_list: list of batadv_vis_info packets to sent
  415. * @hash: hash table containing vis data from other nodes in the network
  416. * @hash_lock: lock protecting the hash table
  417. * @list_lock: lock protecting my_info::recv_list
  418. * @work: work queue callback item for vis packet sending
  419. * @my_info: holds this node's vis data sent on a regular basis
  420. */
  421. struct batadv_priv_vis {
  422. struct list_head send_list;
  423. struct batadv_hashtable *hash;
  424. spinlock_t hash_lock; /* protects hash */
  425. spinlock_t list_lock; /* protects my_info::recv_list */
  426. struct delayed_work work;
  427. struct batadv_vis_info *my_info;
  428. };
  429. /**
  430. * struct batadv_priv_dat - per mesh interface DAT private data
  431. * @addr: node DAT address
  432. * @hash: hashtable representing the local ARP cache
  433. * @work: work queue callback item for cache purging
  434. */
  435. #ifdef CONFIG_BATMAN_ADV_DAT
  436. struct batadv_priv_dat {
  437. batadv_dat_addr_t addr;
  438. struct batadv_hashtable *hash;
  439. struct delayed_work work;
  440. };
  441. #endif
  442. /**
  443. * struct batadv_priv_nc - per mesh interface network coding private data
  444. * @work: work queue callback item for cleanup
  445. * @debug_dir: dentry for nc subdir in batman-adv directory in debugfs
  446. * @min_tq: only consider neighbors for encoding if neigh_tq > min_tq
  447. * @max_fwd_delay: maximum packet forward delay to allow coding of packets
  448. * @max_buffer_time: buffer time for sniffed packets used to decoding
  449. * @timestamp_fwd_flush: timestamp of last forward packet queue flush
  450. * @timestamp_sniffed_purge: timestamp of last sniffed packet queue purge
  451. * @coding_hash: Hash table used to buffer skbs while waiting for another
  452. * incoming skb to code it with. Skbs are added to the buffer just before being
  453. * forwarded in routing.c
  454. * @decoding_hash: Hash table used to buffer skbs that might be needed to decode
  455. * a received coded skb. The buffer is used for 1) skbs arriving on the
  456. * soft-interface; 2) skbs overheard on the hard-interface; and 3) skbs
  457. * forwarded by batman-adv.
  458. */
  459. struct batadv_priv_nc {
  460. struct delayed_work work;
  461. struct dentry *debug_dir;
  462. u8 min_tq;
  463. u32 max_fwd_delay;
  464. u32 max_buffer_time;
  465. unsigned long timestamp_fwd_flush;
  466. unsigned long timestamp_sniffed_purge;
  467. struct batadv_hashtable *coding_hash;
  468. struct batadv_hashtable *decoding_hash;
  469. };
  470. /**
  471. * struct batadv_priv - per mesh interface data
  472. * @mesh_state: current status of the mesh (inactive/active/deactivating)
  473. * @soft_iface: net device which holds this struct as private data
  474. * @stats: structure holding the data for the ndo_get_stats() call
  475. * @bat_counters: mesh internal traffic statistic counters (see batadv_counters)
  476. * @aggregated_ogms: bool indicating whether OGM aggregation is enabled
  477. * @bonding: bool indicating whether traffic bonding is enabled
  478. * @fragmentation: bool indicating whether traffic fragmentation is enabled
  479. * @ap_isolation: bool indicating whether ap isolation is enabled
  480. * @bridge_loop_avoidance: bool indicating whether bridge loop avoidance is
  481. * enabled
  482. * @distributed_arp_table: bool indicating whether distributed ARP table is
  483. * enabled
  484. * @vis_mode: vis operation: client or server (see batadv_vis_packettype)
  485. * @gw_mode: gateway operation: off, client or server (see batadv_gw_modes)
  486. * @gw_sel_class: gateway selection class (applies if gw_mode client)
  487. * @gw_bandwidth: gateway announced bandwidth (applies if gw_mode server)
  488. * @orig_interval: OGM broadcast interval in milliseconds
  489. * @hop_penalty: penalty which will be applied to an OGM's tq-field on every hop
  490. * @log_level: configured log level (see batadv_dbg_level)
  491. * @bcast_seqno: last sent broadcast packet sequence number
  492. * @bcast_queue_left: number of remaining buffered broadcast packet slots
  493. * @batman_queue_left: number of remaining OGM packet slots
  494. * @num_ifaces: number of interfaces assigned to this mesh interface
  495. * @mesh_obj: kobject for sysfs mesh subdirectory
  496. * @debug_dir: dentry for debugfs batman-adv subdirectory
  497. * @forw_bat_list: list of aggregated OGMs that will be forwarded
  498. * @forw_bcast_list: list of broadcast packets that will be rebroadcasted
  499. * @orig_hash: hash table containing mesh participants (orig nodes)
  500. * @forw_bat_list_lock: lock protecting forw_bat_list
  501. * @forw_bcast_list_lock: lock protecting forw_bcast_list
  502. * @orig_work: work queue callback item for orig node purging
  503. * @cleanup_work: work queue callback item for soft interface deinit
  504. * @primary_if: one of the hard interfaces assigned to this mesh interface
  505. * becomes the primary interface
  506. * @bat_algo_ops: routing algorithm used by this mesh interface
  507. * @bla: bridge loope avoidance data
  508. * @debug_log: holding debug logging relevant data
  509. * @gw: gateway data
  510. * @tt: translation table data
  511. * @vis: vis data
  512. * @dat: distributed arp table data
  513. * @network_coding: bool indicating whether network coding is enabled
  514. * @batadv_priv_nc: network coding data
  515. */
  516. struct batadv_priv {
  517. atomic_t mesh_state;
  518. struct net_device *soft_iface;
  519. struct net_device_stats stats;
  520. uint64_t __percpu *bat_counters; /* Per cpu counters */
  521. atomic_t aggregated_ogms;
  522. atomic_t bonding;
  523. atomic_t fragmentation;
  524. atomic_t ap_isolation;
  525. #ifdef CONFIG_BATMAN_ADV_BLA
  526. atomic_t bridge_loop_avoidance;
  527. #endif
  528. #ifdef CONFIG_BATMAN_ADV_DAT
  529. atomic_t distributed_arp_table;
  530. #endif
  531. atomic_t vis_mode;
  532. atomic_t gw_mode;
  533. atomic_t gw_sel_class;
  534. atomic_t gw_bandwidth;
  535. atomic_t orig_interval;
  536. atomic_t hop_penalty;
  537. #ifdef CONFIG_BATMAN_ADV_DEBUG
  538. atomic_t log_level;
  539. #endif
  540. atomic_t bcast_seqno;
  541. atomic_t bcast_queue_left;
  542. atomic_t batman_queue_left;
  543. char num_ifaces;
  544. struct kobject *mesh_obj;
  545. struct dentry *debug_dir;
  546. struct hlist_head forw_bat_list;
  547. struct hlist_head forw_bcast_list;
  548. struct batadv_hashtable *orig_hash;
  549. spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
  550. spinlock_t forw_bcast_list_lock; /* protects forw_bcast_list */
  551. struct delayed_work orig_work;
  552. struct work_struct cleanup_work;
  553. struct batadv_hard_iface __rcu *primary_if; /* rcu protected pointer */
  554. struct batadv_algo_ops *bat_algo_ops;
  555. #ifdef CONFIG_BATMAN_ADV_BLA
  556. struct batadv_priv_bla bla;
  557. #endif
  558. #ifdef CONFIG_BATMAN_ADV_DEBUG
  559. struct batadv_priv_debug_log *debug_log;
  560. #endif
  561. struct batadv_priv_gw gw;
  562. struct batadv_priv_tt tt;
  563. struct batadv_priv_vis vis;
  564. #ifdef CONFIG_BATMAN_ADV_DAT
  565. struct batadv_priv_dat dat;
  566. #endif
  567. #ifdef CONFIG_BATMAN_ADV_NC
  568. atomic_t network_coding;
  569. struct batadv_priv_nc nc;
  570. #endif /* CONFIG_BATMAN_ADV_NC */
  571. };
  572. /**
  573. * struct batadv_socket_client - layer2 icmp socket client data
  574. * @queue_list: packet queue for packets destined for this socket client
  575. * @queue_len: number of packets in the packet queue (queue_list)
  576. * @index: socket client's index in the batadv_socket_client_hash
  577. * @lock: lock protecting queue_list, queue_len & index
  578. * @queue_wait: socket client's wait queue
  579. * @bat_priv: pointer to soft_iface this client belongs to
  580. */
  581. struct batadv_socket_client {
  582. struct list_head queue_list;
  583. unsigned int queue_len;
  584. unsigned char index;
  585. spinlock_t lock; /* protects queue_list, queue_len & index */
  586. wait_queue_head_t queue_wait;
  587. struct batadv_priv *bat_priv;
  588. };
  589. /**
  590. * struct batadv_socket_packet - layer2 icmp packet for socket client
  591. * @list: list node for batadv_socket_client::queue_list
  592. * @icmp_len: size of the layer2 icmp packet
  593. * @icmp_packet: layer2 icmp packet
  594. */
  595. struct batadv_socket_packet {
  596. struct list_head list;
  597. size_t icmp_len;
  598. struct batadv_icmp_packet_rr icmp_packet;
  599. };
  600. /**
  601. * struct batadv_bla_backbone_gw - batman-adv gateway bridged into the LAN
  602. * @orig: originator address of backbone node (mac address of primary iface)
  603. * @vid: vlan id this gateway was detected on
  604. * @hash_entry: hlist node for batadv_priv_bla::backbone_hash
  605. * @bat_priv: pointer to soft_iface this backbone gateway belongs to
  606. * @lasttime: last time we heard of this backbone gw
  607. * @wait_periods: grace time for bridge forward delays and bla group forming at
  608. * bootup phase - no bcast traffic is formwared until it has elapsed
  609. * @request_sent: if this bool is set to true we are out of sync with this
  610. * backbone gateway - no bcast traffic is formwared until the situation was
  611. * resolved
  612. * @crc: crc16 checksum over all claims
  613. * @refcount: number of contexts the object is used
  614. * @rcu: struct used for freeing in an RCU-safe manner
  615. */
  616. #ifdef CONFIG_BATMAN_ADV_BLA
  617. struct batadv_bla_backbone_gw {
  618. uint8_t orig[ETH_ALEN];
  619. short vid;
  620. struct hlist_node hash_entry;
  621. struct batadv_priv *bat_priv;
  622. unsigned long lasttime;
  623. atomic_t wait_periods;
  624. atomic_t request_sent;
  625. uint16_t crc;
  626. atomic_t refcount;
  627. struct rcu_head rcu;
  628. };
  629. /**
  630. * struct batadv_bla_claim - claimed non-mesh client structure
  631. * @addr: mac address of claimed non-mesh client
  632. * @vid: vlan id this client was detected on
  633. * @batadv_bla_backbone_gw: pointer to backbone gw claiming this client
  634. * @lasttime: last time we heard of claim (locals only)
  635. * @hash_entry: hlist node for batadv_priv_bla::claim_hash
  636. * @refcount: number of contexts the object is used
  637. * @rcu: struct used for freeing in an RCU-safe manner
  638. */
  639. struct batadv_bla_claim {
  640. uint8_t addr[ETH_ALEN];
  641. short vid;
  642. struct batadv_bla_backbone_gw *backbone_gw;
  643. unsigned long lasttime;
  644. struct hlist_node hash_entry;
  645. struct rcu_head rcu;
  646. atomic_t refcount;
  647. };
  648. #endif
  649. /**
  650. * struct batadv_tt_common_entry - tt local & tt global common data
  651. * @addr: mac address of non-mesh client
  652. * @hash_entry: hlist node for batadv_priv_tt::local_hash or for
  653. * batadv_priv_tt::global_hash
  654. * @flags: various state handling flags (see batadv_tt_client_flags)
  655. * @added_at: timestamp used for purging stale tt common entries
  656. * @refcount: number of contexts the object is used
  657. * @rcu: struct used for freeing in an RCU-safe manner
  658. */
  659. struct batadv_tt_common_entry {
  660. uint8_t addr[ETH_ALEN];
  661. struct hlist_node hash_entry;
  662. uint16_t flags;
  663. unsigned long added_at;
  664. atomic_t refcount;
  665. struct rcu_head rcu;
  666. };
  667. /**
  668. * struct batadv_tt_local_entry - translation table local entry data
  669. * @common: general translation table data
  670. * @last_seen: timestamp used for purging stale tt local entries
  671. */
  672. struct batadv_tt_local_entry {
  673. struct batadv_tt_common_entry common;
  674. unsigned long last_seen;
  675. };
  676. /**
  677. * struct batadv_tt_global_entry - translation table global entry data
  678. * @common: general translation table data
  679. * @orig_list: list of orig nodes announcing this non-mesh client
  680. * @list_lock: lock protecting orig_list
  681. * @roam_at: time at which TT_GLOBAL_ROAM was set
  682. */
  683. struct batadv_tt_global_entry {
  684. struct batadv_tt_common_entry common;
  685. struct hlist_head orig_list;
  686. spinlock_t list_lock; /* protects orig_list */
  687. unsigned long roam_at;
  688. };
  689. /**
  690. * struct batadv_tt_orig_list_entry - orig node announcing a non-mesh client
  691. * @orig_node: pointer to orig node announcing this non-mesh client
  692. * @ttvn: translation table version number which added the non-mesh client
  693. * @list: list node for batadv_tt_global_entry::orig_list
  694. * @refcount: number of contexts the object is used
  695. * @rcu: struct used for freeing in an RCU-safe manner
  696. */
  697. struct batadv_tt_orig_list_entry {
  698. struct batadv_orig_node *orig_node;
  699. uint8_t ttvn;
  700. struct hlist_node list;
  701. atomic_t refcount;
  702. struct rcu_head rcu;
  703. };
  704. /**
  705. * struct batadv_tt_change_node - structure for tt changes occured
  706. * @list: list node for batadv_priv_tt::changes_list
  707. * @change: holds the actual translation table diff data
  708. */
  709. struct batadv_tt_change_node {
  710. struct list_head list;
  711. struct batadv_tt_change change;
  712. };
  713. /**
  714. * struct batadv_tt_req_node - data to keep track of the tt requests in flight
  715. * @addr: mac address address of the originator this request was sent to
  716. * @issued_at: timestamp used for purging stale tt requests
  717. * @list: list node for batadv_priv_tt::req_list
  718. */
  719. struct batadv_tt_req_node {
  720. uint8_t addr[ETH_ALEN];
  721. unsigned long issued_at;
  722. struct list_head list;
  723. };
  724. /**
  725. * struct batadv_tt_roam_node - roaming client data
  726. * @addr: mac address of the client in the roaming phase
  727. * @counter: number of allowed roaming events per client within a single
  728. * OGM interval (changes are committed with each OGM)
  729. * @first_time: timestamp used for purging stale roaming node entries
  730. * @list: list node for batadv_priv_tt::roam_list
  731. */
  732. struct batadv_tt_roam_node {
  733. uint8_t addr[ETH_ALEN];
  734. atomic_t counter;
  735. unsigned long first_time;
  736. struct list_head list;
  737. };
  738. /**
  739. * struct batadv_nc_node - network coding node
  740. * @list: next and prev pointer for the list handling
  741. * @addr: the node's mac address
  742. * @refcount: number of contexts the object is used by
  743. * @rcu: struct used for freeing in an RCU-safe manner
  744. * @orig_node: pointer to corresponding orig node struct
  745. * @last_seen: timestamp of last ogm received from this node
  746. */
  747. struct batadv_nc_node {
  748. struct list_head list;
  749. uint8_t addr[ETH_ALEN];
  750. atomic_t refcount;
  751. struct rcu_head rcu;
  752. struct batadv_orig_node *orig_node;
  753. unsigned long last_seen;
  754. };
  755. /**
  756. * struct batadv_nc_path - network coding path
  757. * @hash_entry: next and prev pointer for the list handling
  758. * @rcu: struct used for freeing in an RCU-safe manner
  759. * @refcount: number of contexts the object is used by
  760. * @packet_list: list of buffered packets for this path
  761. * @packet_list_lock: access lock for packet list
  762. * @next_hop: next hop (destination) of path
  763. * @prev_hop: previous hop (source) of path
  764. * @last_valid: timestamp for last validation of path
  765. */
  766. struct batadv_nc_path {
  767. struct hlist_node hash_entry;
  768. struct rcu_head rcu;
  769. atomic_t refcount;
  770. struct list_head packet_list;
  771. spinlock_t packet_list_lock; /* Protects packet_list */
  772. uint8_t next_hop[ETH_ALEN];
  773. uint8_t prev_hop[ETH_ALEN];
  774. unsigned long last_valid;
  775. };
  776. /**
  777. * struct batadv_nc_packet - network coding packet used when coding and
  778. * decoding packets
  779. * @list: next and prev pointer for the list handling
  780. * @packet_id: crc32 checksum of skb data
  781. * @timestamp: field containing the info when the packet was added to path
  782. * @neigh_node: pointer to original next hop neighbor of skb
  783. * @skb: skb which can be encoded or used for decoding
  784. * @nc_path: pointer to path this nc packet is attached to
  785. */
  786. struct batadv_nc_packet {
  787. struct list_head list;
  788. __be32 packet_id;
  789. unsigned long timestamp;
  790. struct batadv_neigh_node *neigh_node;
  791. struct sk_buff *skb;
  792. struct batadv_nc_path *nc_path;
  793. };
  794. /**
  795. * batadv_skb_cb - control buffer structure used to store private data relevant
  796. * to batman-adv in the skb->cb buffer in skbs.
  797. * @decoded: Marks a skb as decoded, which is checked when searching for coding
  798. * opportunities in network-coding.c
  799. */
  800. struct batadv_skb_cb {
  801. bool decoded;
  802. };
  803. /**
  804. * struct batadv_forw_packet - structure for bcast packets to be sent/forwarded
  805. * @list: list node for batadv_socket_client::queue_list
  806. * @send_time: execution time for delayed_work (packet sending)
  807. * @own: bool for locally generated packets (local OGMs are re-scheduled after
  808. * sending)
  809. * @skb: bcast packet's skb buffer
  810. * @packet_len: size of aggregated OGM packet inside the skb buffer
  811. * @direct_link_flags: direct link flags for aggregated OGM packets
  812. * @num_packets: counter for bcast packet retransmission
  813. * @delayed_work: work queue callback item for packet sending
  814. * @if_incoming: pointer incoming hard-iface or primary iface if locally
  815. * generated packet
  816. */
  817. struct batadv_forw_packet {
  818. struct hlist_node list;
  819. unsigned long send_time;
  820. uint8_t own;
  821. struct sk_buff *skb;
  822. uint16_t packet_len;
  823. uint32_t direct_link_flags;
  824. uint8_t num_packets;
  825. struct delayed_work delayed_work;
  826. struct batadv_hard_iface *if_incoming;
  827. };
  828. /**
  829. * struct batadv_frag_packet_list_entry - storage for fragment packet
  830. * @list: list node for orig_node::frag_list
  831. * @seqno: sequence number of the fragment
  832. * @skb: fragment's skb buffer
  833. */
  834. struct batadv_frag_packet_list_entry {
  835. struct list_head list;
  836. uint16_t seqno;
  837. struct sk_buff *skb;
  838. };
  839. /**
  840. * struct batadv_vis_info - local data for vis information
  841. * @first_seen: timestamp used for purging stale vis info entries
  842. * @recv_list: List of server-neighbors we have received this packet from. This
  843. * packet should not be re-forward to them again. List elements are struct
  844. * batadv_vis_recvlist_node
  845. * @send_list: list of packets to be forwarded
  846. * @refcount: number of contexts the object is used
  847. * @hash_entry: hlist node for batadv_priv_vis::hash
  848. * @bat_priv: pointer to soft_iface this orig node belongs to
  849. * @skb_packet: contains the vis packet
  850. */
  851. struct batadv_vis_info {
  852. unsigned long first_seen;
  853. struct list_head recv_list;
  854. struct list_head send_list;
  855. struct kref refcount;
  856. struct hlist_node hash_entry;
  857. struct batadv_priv *bat_priv;
  858. struct sk_buff *skb_packet;
  859. } __packed;
  860. /**
  861. * struct batadv_vis_info_entry - contains link information for vis
  862. * @src: source MAC of the link, all zero for local TT entry
  863. * @dst: destination MAC of the link, client mac address for local TT entry
  864. * @quality: transmission quality of the link, or 0 for local TT entry
  865. */
  866. struct batadv_vis_info_entry {
  867. uint8_t src[ETH_ALEN];
  868. uint8_t dest[ETH_ALEN];
  869. uint8_t quality;
  870. } __packed;
  871. /**
  872. * struct batadv_vis_recvlist_node - list entry for batadv_vis_info::recv_list
  873. * @list: list node for batadv_vis_info::recv_list
  874. * @mac: MAC address of the originator from where the vis_info was received
  875. */
  876. struct batadv_vis_recvlist_node {
  877. struct list_head list;
  878. uint8_t mac[ETH_ALEN];
  879. };
  880. /**
  881. * struct batadv_vis_if_list_entry - auxiliary data for vis data generation
  882. * @addr: MAC address of the interface
  883. * @primary: true if this interface is the primary interface
  884. * @list: list node the interface list
  885. *
  886. * While scanning for vis-entries of a particular vis-originator
  887. * this list collects its interfaces to create a subgraph/cluster
  888. * out of them later
  889. */
  890. struct batadv_vis_if_list_entry {
  891. uint8_t addr[ETH_ALEN];
  892. bool primary;
  893. struct hlist_node list;
  894. };
  895. /**
  896. * struct batadv_algo_ops - mesh algorithm callbacks
  897. * @list: list node for the batadv_algo_list
  898. * @name: name of the algorithm
  899. * @bat_iface_enable: init routing info when hard-interface is enabled
  900. * @bat_iface_disable: de-init routing info when hard-interface is disabled
  901. * @bat_iface_update_mac: (re-)init mac addresses of the protocol information
  902. * belonging to this hard-interface
  903. * @bat_primary_iface_set: called when primary interface is selected / changed
  904. * @bat_ogm_schedule: prepare a new outgoing OGM for the send queue
  905. * @bat_ogm_emit: send scheduled OGM
  906. */
  907. struct batadv_algo_ops {
  908. struct hlist_node list;
  909. char *name;
  910. int (*bat_iface_enable)(struct batadv_hard_iface *hard_iface);
  911. void (*bat_iface_disable)(struct batadv_hard_iface *hard_iface);
  912. void (*bat_iface_update_mac)(struct batadv_hard_iface *hard_iface);
  913. void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);
  914. void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);
  915. void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
  916. };
  917. /**
  918. * struct batadv_dat_entry - it is a single entry of batman-adv ARP backend. It
  919. * is used to stored ARP entries needed for the global DAT cache
  920. * @ip: the IPv4 corresponding to this DAT/ARP entry
  921. * @mac_addr: the MAC address associated to the stored IPv4
  922. * @last_update: time in jiffies when this entry was refreshed last time
  923. * @hash_entry: hlist node for batadv_priv_dat::hash
  924. * @refcount: number of contexts the object is used
  925. * @rcu: struct used for freeing in an RCU-safe manner
  926. */
  927. struct batadv_dat_entry {
  928. __be32 ip;
  929. uint8_t mac_addr[ETH_ALEN];
  930. unsigned long last_update;
  931. struct hlist_node hash_entry;
  932. atomic_t refcount;
  933. struct rcu_head rcu;
  934. };
  935. /**
  936. * struct batadv_dat_candidate - candidate destination for DAT operations
  937. * @type: the type of the selected candidate. It can one of the following:
  938. * - BATADV_DAT_CANDIDATE_NOT_FOUND
  939. * - BATADV_DAT_CANDIDATE_ORIG
  940. * @orig_node: if type is BATADV_DAT_CANDIDATE_ORIG this field points to the
  941. * corresponding originator node structure
  942. */
  943. struct batadv_dat_candidate {
  944. int type;
  945. struct batadv_orig_node *orig_node;
  946. };
  947. #endif /* _NET_BATMAN_ADV_TYPES_H_ */