types.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  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. #ifdef CONFIG_BATMAN_ADV_DAT
  25. /* batadv_dat_addr_t is the type used for all DHT addresses. If it is changed,
  26. * BATADV_DAT_ADDR_MAX is changed as well.
  27. *
  28. * *Please be careful: batadv_dat_addr_t must be UNSIGNED*
  29. */
  30. #define batadv_dat_addr_t uint16_t
  31. #endif /* CONFIG_BATMAN_ADV_DAT */
  32. /**
  33. * BATADV_TT_REMOTE_MASK - bitmask selecting the flags that are sent over the
  34. * wire only
  35. */
  36. #define BATADV_TT_REMOTE_MASK 0x00FF
  37. /**
  38. * struct batadv_hard_iface_bat_iv - per hard interface B.A.T.M.A.N. IV data
  39. * @ogm_buff: buffer holding the OGM packet
  40. * @ogm_buff_len: length of the OGM packet buffer
  41. * @ogm_seqno: OGM sequence number - used to identify each OGM
  42. */
  43. struct batadv_hard_iface_bat_iv {
  44. unsigned char *ogm_buff;
  45. int ogm_buff_len;
  46. atomic_t ogm_seqno;
  47. };
  48. /**
  49. * struct batadv_hard_iface - network device known to batman-adv
  50. * @list: list node for batadv_hardif_list
  51. * @if_num: identificator of the interface
  52. * @if_status: status of the interface for batman-adv
  53. * @net_dev: pointer to the net_device
  54. * @num_bcasts: number of payload re-broadcasts on this interface (ARQ)
  55. * @hardif_obj: kobject of the per interface sysfs "mesh" directory
  56. * @refcount: number of contexts the object is used
  57. * @batman_adv_ptype: packet type describing packets that should be processed by
  58. * batman-adv for this interface
  59. * @soft_iface: the batman-adv interface which uses this network interface
  60. * @rcu: struct used for freeing in an RCU-safe manner
  61. * @bat_iv: BATMAN IV specific per hard interface data
  62. * @cleanup_work: work queue callback item for hard interface deinit
  63. */
  64. struct batadv_hard_iface {
  65. struct list_head list;
  66. int16_t if_num;
  67. char if_status;
  68. struct net_device *net_dev;
  69. uint8_t num_bcasts;
  70. struct kobject *hardif_obj;
  71. atomic_t refcount;
  72. struct packet_type batman_adv_ptype;
  73. struct net_device *soft_iface;
  74. struct rcu_head rcu;
  75. struct batadv_hard_iface_bat_iv bat_iv;
  76. struct work_struct cleanup_work;
  77. };
  78. /**
  79. * struct batadv_frag_table_entry - head in the fragment buffer table
  80. * @head: head of list with fragments
  81. * @lock: lock to protect the list of fragments
  82. * @timestamp: time (jiffie) of last received fragment
  83. * @seqno: sequence number of the fragments in the list
  84. * @size: accumulated size of packets in list
  85. */
  86. struct batadv_frag_table_entry {
  87. struct hlist_head head;
  88. spinlock_t lock; /* protects head */
  89. unsigned long timestamp;
  90. uint16_t seqno;
  91. uint16_t size;
  92. };
  93. /**
  94. * struct batadv_frag_list_entry - entry in a list of fragments
  95. * @list: list node information
  96. * @skb: fragment
  97. * @no: fragment number in the set
  98. */
  99. struct batadv_frag_list_entry {
  100. struct hlist_node list;
  101. struct sk_buff *skb;
  102. uint8_t no;
  103. };
  104. /**
  105. * struct batadv_vlan_tt - VLAN specific TT attributes
  106. * @crc: CRC32 checksum of the entries belonging to this vlan
  107. * @num_entries: number of TT entries for this VLAN
  108. */
  109. struct batadv_vlan_tt {
  110. uint32_t crc;
  111. atomic_t num_entries;
  112. };
  113. /**
  114. * batadv_orig_node_vlan - VLAN specific data per orig_node
  115. * @vid: the VLAN identifier
  116. * @tt: VLAN specific TT attributes
  117. * @list: list node for orig_node::vlan_list
  118. * @refcount: number of context where this object is currently in use
  119. * @rcu: struct used for freeing in a RCU-safe manner
  120. */
  121. struct batadv_orig_node_vlan {
  122. unsigned short vid;
  123. struct batadv_vlan_tt tt;
  124. struct list_head list;
  125. atomic_t refcount;
  126. struct rcu_head rcu;
  127. };
  128. /**
  129. * struct batadv_orig_bat_iv - B.A.T.M.A.N. IV private orig_node members
  130. * @bcast_own: bitfield containing the number of our OGMs this orig_node
  131. * rebroadcasted "back" to us (relative to last_real_seqno)
  132. * @bcast_own_sum: counted result of bcast_own
  133. * @ogm_cnt_lock: lock protecting bcast_own, bcast_own_sum,
  134. * neigh_node->bat_iv.real_bits & neigh_node->bat_iv.real_packet_count
  135. */
  136. struct batadv_orig_bat_iv {
  137. unsigned long *bcast_own;
  138. uint8_t *bcast_own_sum;
  139. /* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
  140. * neigh_node->bat_iv.real_bits & neigh_node->bat_iv.real_packet_count
  141. */
  142. spinlock_t ogm_cnt_lock;
  143. };
  144. /**
  145. * struct batadv_orig_node - structure for orig_list maintaining nodes of mesh
  146. * @orig: originator ethernet address
  147. * @primary_addr: hosts primary interface address
  148. * @router: router that should be used to reach this originator
  149. * @batadv_dat_addr_t: address of the orig node in the distributed hash
  150. * @last_seen: time when last packet from this node was received
  151. * @bcast_seqno_reset: time when the broadcast seqno window was reset
  152. * @batman_seqno_reset: time when the batman seqno window was reset
  153. * @capabilities: announced capabilities of this originator
  154. * @last_ttvn: last seen translation table version number
  155. * @tt_buff: last tt changeset this node received from the orig node
  156. * @tt_buff_len: length of the last tt changeset this node received from the
  157. * orig node
  158. * @tt_buff_lock: lock that protects tt_buff and tt_buff_len
  159. * @tt_initialised: bool keeping track of whether or not this node have received
  160. * any translation table information from the orig node yet
  161. * @tt_lock: prevents from updating the table while reading it. Table update is
  162. * made up by two operations (data structure update and metdata -CRC/TTVN-
  163. * recalculation) and they have to be executed atomically in order to avoid
  164. * another thread to read the table/metadata between those.
  165. * @last_real_seqno: last and best known sequence number
  166. * @last_ttl: ttl of last received packet
  167. * @bcast_bits: bitfield containing the info which payload broadcast originated
  168. * from this orig node this host already has seen (relative to
  169. * last_bcast_seqno)
  170. * @last_bcast_seqno: last broadcast sequence number received by this host
  171. * @neigh_list: list of potential next hop neighbor towards this orig node
  172. * @neigh_list_lock: lock protecting neigh_list, router and bonding_list
  173. * @hash_entry: hlist node for batadv_priv::orig_hash
  174. * @bat_priv: pointer to soft_iface this orig node belongs to
  175. * @bcast_seqno_lock: lock protecting bcast_bits & last_bcast_seqno
  176. * @bond_candidates: how many candidates are available
  177. * @bond_list: list of bonding candidates
  178. * @refcount: number of contexts the object is used
  179. * @rcu: struct used for freeing in an RCU-safe manner
  180. * @in_coding_list: list of nodes this orig can hear
  181. * @out_coding_list: list of nodes that can hear this orig
  182. * @in_coding_list_lock: protects in_coding_list
  183. * @out_coding_list_lock: protects out_coding_list
  184. * @fragments: array with heads for fragment chains
  185. * @vlan_list: a list of orig_node_vlan structs, one per VLAN served by the
  186. * originator represented by this object
  187. * @vlan_list_lock: lock protecting vlan_list
  188. * @bat_iv: B.A.T.M.A.N. IV private structure
  189. */
  190. struct batadv_orig_node {
  191. uint8_t orig[ETH_ALEN];
  192. uint8_t primary_addr[ETH_ALEN];
  193. struct batadv_neigh_node __rcu *router; /* rcu protected pointer */
  194. #ifdef CONFIG_BATMAN_ADV_DAT
  195. batadv_dat_addr_t dat_addr;
  196. #endif
  197. unsigned long last_seen;
  198. unsigned long bcast_seqno_reset;
  199. unsigned long batman_seqno_reset;
  200. uint8_t capabilities;
  201. atomic_t last_ttvn;
  202. unsigned char *tt_buff;
  203. int16_t tt_buff_len;
  204. spinlock_t tt_buff_lock; /* protects tt_buff & tt_buff_len */
  205. bool tt_initialised;
  206. /* prevents from changing the table while reading it */
  207. spinlock_t tt_lock;
  208. uint32_t last_real_seqno;
  209. uint8_t last_ttl;
  210. DECLARE_BITMAP(bcast_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
  211. uint32_t last_bcast_seqno;
  212. struct hlist_head neigh_list;
  213. /* neigh_list_lock protects: neigh_list, router & bonding_list */
  214. spinlock_t neigh_list_lock;
  215. struct hlist_node hash_entry;
  216. struct batadv_priv *bat_priv;
  217. /* bcast_seqno_lock protects: bcast_bits & last_bcast_seqno */
  218. spinlock_t bcast_seqno_lock;
  219. atomic_t bond_candidates;
  220. struct list_head bond_list;
  221. atomic_t refcount;
  222. struct rcu_head rcu;
  223. #ifdef CONFIG_BATMAN_ADV_NC
  224. struct list_head in_coding_list;
  225. struct list_head out_coding_list;
  226. spinlock_t in_coding_list_lock; /* Protects in_coding_list */
  227. spinlock_t out_coding_list_lock; /* Protects out_coding_list */
  228. #endif
  229. struct batadv_frag_table_entry fragments[BATADV_FRAG_BUFFER_COUNT];
  230. struct list_head vlan_list;
  231. spinlock_t vlan_list_lock; /* protects vlan_list */
  232. struct batadv_orig_bat_iv bat_iv;
  233. };
  234. /**
  235. * enum batadv_orig_capabilities - orig node capabilities
  236. * @BATADV_ORIG_CAPA_HAS_DAT: orig node has distributed arp table enabled
  237. * @BATADV_ORIG_CAPA_HAS_NC: orig node has network coding enabled
  238. */
  239. enum batadv_orig_capabilities {
  240. BATADV_ORIG_CAPA_HAS_DAT = BIT(0),
  241. BATADV_ORIG_CAPA_HAS_NC = BIT(1),
  242. };
  243. /**
  244. * struct batadv_gw_node - structure for orig nodes announcing gw capabilities
  245. * @list: list node for batadv_priv_gw::list
  246. * @orig_node: pointer to corresponding orig node
  247. * @bandwidth_down: advertised uplink download bandwidth
  248. * @bandwidth_up: advertised uplink upload bandwidth
  249. * @deleted: this struct is scheduled for deletion
  250. * @refcount: number of contexts the object is used
  251. * @rcu: struct used for freeing in an RCU-safe manner
  252. */
  253. struct batadv_gw_node {
  254. struct hlist_node list;
  255. struct batadv_orig_node *orig_node;
  256. uint32_t bandwidth_down;
  257. uint32_t bandwidth_up;
  258. unsigned long deleted;
  259. atomic_t refcount;
  260. struct rcu_head rcu;
  261. };
  262. /**
  263. * struct batadv_neigh_bat_iv - B.A.T.M.A.N. IV specific structure for single
  264. * hop neighbors
  265. * @tq_recv: ring buffer of received TQ values from this neigh node
  266. * @tq_index: ring buffer index
  267. * @tq_avg: averaged tq of all tq values in the ring buffer (tq_recv)
  268. * @real_bits: bitfield containing the number of OGMs received from this neigh
  269. * node (relative to orig_node->last_real_seqno)
  270. * @real_packet_count: counted result of real_bits
  271. * @lq_update_lock: lock protecting tq_recv & tq_index
  272. */
  273. struct batadv_neigh_bat_iv {
  274. uint8_t tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE];
  275. uint8_t tq_index;
  276. uint8_t tq_avg;
  277. DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
  278. uint8_t real_packet_count;
  279. spinlock_t lq_update_lock; /* protects tq_recv & tq_index */
  280. };
  281. /**
  282. * struct batadv_neigh_node - structure for single hops neighbors
  283. * @list: list node for batadv_orig_node::neigh_list
  284. * @orig_node: pointer to corresponding orig_node
  285. * @addr: the MAC address of the neighboring interface
  286. * @if_incoming: pointer to incoming hard interface
  287. * @last_seen: when last packet via this neighbor was received
  288. * @last_ttl: last received ttl from this neigh node
  289. * @bonding_list: list node for batadv_orig_node::bond_list
  290. * @refcount: number of contexts the object is used
  291. * @rcu: struct used for freeing in an RCU-safe manner
  292. * @bat_iv: B.A.T.M.A.N. IV private structure
  293. */
  294. struct batadv_neigh_node {
  295. struct hlist_node list;
  296. struct batadv_orig_node *orig_node;
  297. uint8_t addr[ETH_ALEN];
  298. struct batadv_hard_iface *if_incoming;
  299. unsigned long last_seen;
  300. uint8_t last_ttl;
  301. struct list_head bonding_list;
  302. atomic_t refcount;
  303. struct rcu_head rcu;
  304. struct batadv_neigh_bat_iv bat_iv;
  305. };
  306. /**
  307. * struct batadv_bcast_duplist_entry - structure for LAN broadcast suppression
  308. * @orig[ETH_ALEN]: mac address of orig node orginating the broadcast
  309. * @crc: crc32 checksum of broadcast payload
  310. * @entrytime: time when the broadcast packet was received
  311. */
  312. #ifdef CONFIG_BATMAN_ADV_BLA
  313. struct batadv_bcast_duplist_entry {
  314. uint8_t orig[ETH_ALEN];
  315. __be32 crc;
  316. unsigned long entrytime;
  317. };
  318. #endif
  319. /**
  320. * enum batadv_counters - indices for traffic counters
  321. * @BATADV_CNT_TX: transmitted payload traffic packet counter
  322. * @BATADV_CNT_TX_BYTES: transmitted payload traffic bytes counter
  323. * @BATADV_CNT_TX_DROPPED: dropped transmission payload traffic packet counter
  324. * @BATADV_CNT_RX: received payload traffic packet counter
  325. * @BATADV_CNT_RX_BYTES: received payload traffic bytes counter
  326. * @BATADV_CNT_FORWARD: forwarded payload traffic packet counter
  327. * @BATADV_CNT_FORWARD_BYTES: forwarded payload traffic bytes counter
  328. * @BATADV_CNT_MGMT_TX: transmitted routing protocol traffic packet counter
  329. * @BATADV_CNT_MGMT_TX_BYTES: transmitted routing protocol traffic bytes counter
  330. * @BATADV_CNT_MGMT_RX: received routing protocol traffic packet counter
  331. * @BATADV_CNT_MGMT_RX_BYTES: received routing protocol traffic bytes counter
  332. * @BATADV_CNT_FRAG_TX: transmitted fragment traffic packet counter
  333. * @BATADV_CNT_FRAG_TX_BYTES: transmitted fragment traffic bytes counter
  334. * @BATADV_CNT_FRAG_RX: received fragment traffic packet counter
  335. * @BATADV_CNT_FRAG_RX_BYTES: received fragment traffic bytes counter
  336. * @BATADV_CNT_FRAG_FWD: forwarded fragment traffic packet counter
  337. * @BATADV_CNT_FRAG_FWD_BYTES: forwarded fragment traffic bytes counter
  338. * @BATADV_CNT_TT_REQUEST_TX: transmitted tt req traffic packet counter
  339. * @BATADV_CNT_TT_REQUEST_RX: received tt req traffic packet counter
  340. * @BATADV_CNT_TT_RESPONSE_TX: transmitted tt resp traffic packet counter
  341. * @BATADV_CNT_TT_RESPONSE_RX: received tt resp traffic packet counter
  342. * @BATADV_CNT_TT_ROAM_ADV_TX: transmitted tt roam traffic packet counter
  343. * @BATADV_CNT_TT_ROAM_ADV_RX: received tt roam traffic packet counter
  344. * @BATADV_CNT_DAT_GET_TX: transmitted dht GET traffic packet counter
  345. * @BATADV_CNT_DAT_GET_RX: received dht GET traffic packet counter
  346. * @BATADV_CNT_DAT_PUT_TX: transmitted dht PUT traffic packet counter
  347. * @BATADV_CNT_DAT_PUT_RX: received dht PUT traffic packet counter
  348. * @BATADV_CNT_DAT_CACHED_REPLY_TX: transmitted dat cache reply traffic packet
  349. * counter
  350. * @BATADV_CNT_NC_CODE: transmitted nc-combined traffic packet counter
  351. * @BATADV_CNT_NC_CODE_BYTES: transmitted nc-combined traffic bytes counter
  352. * @BATADV_CNT_NC_RECODE: transmitted nc-recombined traffic packet counter
  353. * @BATADV_CNT_NC_RECODE_BYTES: transmitted nc-recombined traffic bytes counter
  354. * @BATADV_CNT_NC_BUFFER: counter for packets buffered for later nc decoding
  355. * @BATADV_CNT_NC_DECODE: received and nc-decoded traffic packet counter
  356. * @BATADV_CNT_NC_DECODE_BYTES: received and nc-decoded traffic bytes counter
  357. * @BATADV_CNT_NC_DECODE_FAILED: received and decode-failed traffic packet
  358. * counter
  359. * @BATADV_CNT_NC_SNIFFED: counter for nc-decoded packets received in promisc
  360. * mode.
  361. * @BATADV_CNT_NUM: number of traffic counters
  362. */
  363. enum batadv_counters {
  364. BATADV_CNT_TX,
  365. BATADV_CNT_TX_BYTES,
  366. BATADV_CNT_TX_DROPPED,
  367. BATADV_CNT_RX,
  368. BATADV_CNT_RX_BYTES,
  369. BATADV_CNT_FORWARD,
  370. BATADV_CNT_FORWARD_BYTES,
  371. BATADV_CNT_MGMT_TX,
  372. BATADV_CNT_MGMT_TX_BYTES,
  373. BATADV_CNT_MGMT_RX,
  374. BATADV_CNT_MGMT_RX_BYTES,
  375. BATADV_CNT_FRAG_TX,
  376. BATADV_CNT_FRAG_TX_BYTES,
  377. BATADV_CNT_FRAG_RX,
  378. BATADV_CNT_FRAG_RX_BYTES,
  379. BATADV_CNT_FRAG_FWD,
  380. BATADV_CNT_FRAG_FWD_BYTES,
  381. BATADV_CNT_TT_REQUEST_TX,
  382. BATADV_CNT_TT_REQUEST_RX,
  383. BATADV_CNT_TT_RESPONSE_TX,
  384. BATADV_CNT_TT_RESPONSE_RX,
  385. BATADV_CNT_TT_ROAM_ADV_TX,
  386. BATADV_CNT_TT_ROAM_ADV_RX,
  387. #ifdef CONFIG_BATMAN_ADV_DAT
  388. BATADV_CNT_DAT_GET_TX,
  389. BATADV_CNT_DAT_GET_RX,
  390. BATADV_CNT_DAT_PUT_TX,
  391. BATADV_CNT_DAT_PUT_RX,
  392. BATADV_CNT_DAT_CACHED_REPLY_TX,
  393. #endif
  394. #ifdef CONFIG_BATMAN_ADV_NC
  395. BATADV_CNT_NC_CODE,
  396. BATADV_CNT_NC_CODE_BYTES,
  397. BATADV_CNT_NC_RECODE,
  398. BATADV_CNT_NC_RECODE_BYTES,
  399. BATADV_CNT_NC_BUFFER,
  400. BATADV_CNT_NC_DECODE,
  401. BATADV_CNT_NC_DECODE_BYTES,
  402. BATADV_CNT_NC_DECODE_FAILED,
  403. BATADV_CNT_NC_SNIFFED,
  404. #endif
  405. BATADV_CNT_NUM,
  406. };
  407. /**
  408. * struct batadv_priv_tt - per mesh interface translation table data
  409. * @vn: translation table version number
  410. * @ogm_append_cnt: counter of number of OGMs containing the local tt diff
  411. * @local_changes: changes registered in an originator interval
  412. * @changes_list: tracks tt local changes within an originator interval
  413. * @local_hash: local translation table hash table
  414. * @global_hash: global translation table hash table
  415. * @req_list: list of pending & unanswered tt_requests
  416. * @roam_list: list of the last roaming events of each client limiting the
  417. * number of roaming events to avoid route flapping
  418. * @changes_list_lock: lock protecting changes_list
  419. * @req_list_lock: lock protecting req_list
  420. * @roam_list_lock: lock protecting roam_list
  421. * @last_changeset: last tt changeset this host has generated
  422. * @last_changeset_len: length of last tt changeset this host has generated
  423. * @last_changeset_lock: lock protecting last_changeset & last_changeset_len
  424. * @commit_lock: prevents from executing a local TT commit while reading the
  425. * local table. The local TT commit is made up by two operations (data
  426. * structure update and metdata -CRC/TTVN- recalculation) and they have to be
  427. * executed atomically in order to avoid another thread to read the
  428. * table/metadata between those.
  429. * @work: work queue callback item for translation table purging
  430. */
  431. struct batadv_priv_tt {
  432. atomic_t vn;
  433. atomic_t ogm_append_cnt;
  434. atomic_t local_changes;
  435. struct list_head changes_list;
  436. struct batadv_hashtable *local_hash;
  437. struct batadv_hashtable *global_hash;
  438. struct list_head req_list;
  439. struct list_head roam_list;
  440. spinlock_t changes_list_lock; /* protects changes */
  441. spinlock_t req_list_lock; /* protects req_list */
  442. spinlock_t roam_list_lock; /* protects roam_list */
  443. unsigned char *last_changeset;
  444. int16_t last_changeset_len;
  445. /* protects last_changeset & last_changeset_len */
  446. spinlock_t last_changeset_lock;
  447. /* prevents from executing a commit while reading the table */
  448. spinlock_t commit_lock;
  449. struct delayed_work work;
  450. };
  451. /**
  452. * struct batadv_priv_bla - per mesh interface bridge loope avoidance data
  453. * @num_requests; number of bla requests in flight
  454. * @claim_hash: hash table containing mesh nodes this host has claimed
  455. * @backbone_hash: hash table containing all detected backbone gateways
  456. * @bcast_duplist: recently received broadcast packets array (for broadcast
  457. * duplicate suppression)
  458. * @bcast_duplist_curr: index of last broadcast packet added to bcast_duplist
  459. * @bcast_duplist_lock: lock protecting bcast_duplist & bcast_duplist_curr
  460. * @claim_dest: local claim data (e.g. claim group)
  461. * @work: work queue callback item for cleanups & bla announcements
  462. */
  463. #ifdef CONFIG_BATMAN_ADV_BLA
  464. struct batadv_priv_bla {
  465. atomic_t num_requests;
  466. struct batadv_hashtable *claim_hash;
  467. struct batadv_hashtable *backbone_hash;
  468. struct batadv_bcast_duplist_entry bcast_duplist[BATADV_DUPLIST_SIZE];
  469. int bcast_duplist_curr;
  470. /* protects bcast_duplist & bcast_duplist_curr */
  471. spinlock_t bcast_duplist_lock;
  472. struct batadv_bla_claim_dst claim_dest;
  473. struct delayed_work work;
  474. };
  475. #endif
  476. /**
  477. * struct batadv_debug_log - debug logging data
  478. * @log_buff: buffer holding the logs (ring bufer)
  479. * @log_start: index of next character to read
  480. * @log_end: index of next character to write
  481. * @lock: lock protecting log_buff, log_start & log_end
  482. * @queue_wait: log reader's wait queue
  483. */
  484. #ifdef CONFIG_BATMAN_ADV_DEBUG
  485. struct batadv_priv_debug_log {
  486. char log_buff[BATADV_LOG_BUF_LEN];
  487. unsigned long log_start;
  488. unsigned long log_end;
  489. spinlock_t lock; /* protects log_buff, log_start and log_end */
  490. wait_queue_head_t queue_wait;
  491. };
  492. #endif
  493. /**
  494. * struct batadv_priv_gw - per mesh interface gateway data
  495. * @list: list of available gateway nodes
  496. * @list_lock: lock protecting gw_list & curr_gw
  497. * @curr_gw: pointer to currently selected gateway node
  498. * @bandwidth_down: advertised uplink download bandwidth (if gw_mode server)
  499. * @bandwidth_up: advertised uplink upload bandwidth (if gw_mode server)
  500. * @reselect: bool indicating a gateway re-selection is in progress
  501. */
  502. struct batadv_priv_gw {
  503. struct hlist_head list;
  504. spinlock_t list_lock; /* protects gw_list & curr_gw */
  505. struct batadv_gw_node __rcu *curr_gw; /* rcu protected pointer */
  506. atomic_t bandwidth_down;
  507. atomic_t bandwidth_up;
  508. atomic_t reselect;
  509. };
  510. /**
  511. * struct batadv_priv_tvlv - per mesh interface tvlv data
  512. * @container_list: list of registered tvlv containers to be sent with each OGM
  513. * @handler_list: list of the various tvlv content handlers
  514. * @container_list_lock: protects tvlv container list access
  515. * @handler_list_lock: protects handler list access
  516. */
  517. struct batadv_priv_tvlv {
  518. struct hlist_head container_list;
  519. struct hlist_head handler_list;
  520. spinlock_t container_list_lock; /* protects container_list */
  521. spinlock_t handler_list_lock; /* protects handler_list */
  522. };
  523. /**
  524. * struct batadv_priv_dat - per mesh interface DAT private data
  525. * @addr: node DAT address
  526. * @hash: hashtable representing the local ARP cache
  527. * @work: work queue callback item for cache purging
  528. */
  529. #ifdef CONFIG_BATMAN_ADV_DAT
  530. struct batadv_priv_dat {
  531. batadv_dat_addr_t addr;
  532. struct batadv_hashtable *hash;
  533. struct delayed_work work;
  534. };
  535. #endif
  536. /**
  537. * struct batadv_priv_nc - per mesh interface network coding private data
  538. * @work: work queue callback item for cleanup
  539. * @debug_dir: dentry for nc subdir in batman-adv directory in debugfs
  540. * @min_tq: only consider neighbors for encoding if neigh_tq > min_tq
  541. * @max_fwd_delay: maximum packet forward delay to allow coding of packets
  542. * @max_buffer_time: buffer time for sniffed packets used to decoding
  543. * @timestamp_fwd_flush: timestamp of last forward packet queue flush
  544. * @timestamp_sniffed_purge: timestamp of last sniffed packet queue purge
  545. * @coding_hash: Hash table used to buffer skbs while waiting for another
  546. * incoming skb to code it with. Skbs are added to the buffer just before being
  547. * forwarded in routing.c
  548. * @decoding_hash: Hash table used to buffer skbs that might be needed to decode
  549. * a received coded skb. The buffer is used for 1) skbs arriving on the
  550. * soft-interface; 2) skbs overheard on the hard-interface; and 3) skbs
  551. * forwarded by batman-adv.
  552. */
  553. struct batadv_priv_nc {
  554. struct delayed_work work;
  555. struct dentry *debug_dir;
  556. u8 min_tq;
  557. u32 max_fwd_delay;
  558. u32 max_buffer_time;
  559. unsigned long timestamp_fwd_flush;
  560. unsigned long timestamp_sniffed_purge;
  561. struct batadv_hashtable *coding_hash;
  562. struct batadv_hashtable *decoding_hash;
  563. };
  564. /**
  565. * struct batadv_softif_vlan - per VLAN attributes set
  566. * @vid: VLAN identifier
  567. * @kobj: kobject for sysfs vlan subdirectory
  568. * @ap_isolation: AP isolation state
  569. * @tt: TT private attributes (VLAN specific)
  570. * @list: list node for bat_priv::softif_vlan_list
  571. * @refcount: number of context where this object is currently in use
  572. * @rcu: struct used for freeing in a RCU-safe manner
  573. */
  574. struct batadv_softif_vlan {
  575. unsigned short vid;
  576. struct kobject *kobj;
  577. atomic_t ap_isolation; /* boolean */
  578. struct batadv_vlan_tt tt;
  579. struct hlist_node list;
  580. atomic_t refcount;
  581. struct rcu_head rcu;
  582. };
  583. /**
  584. * struct batadv_priv - per mesh interface data
  585. * @mesh_state: current status of the mesh (inactive/active/deactivating)
  586. * @soft_iface: net device which holds this struct as private data
  587. * @stats: structure holding the data for the ndo_get_stats() call
  588. * @bat_counters: mesh internal traffic statistic counters (see batadv_counters)
  589. * @aggregated_ogms: bool indicating whether OGM aggregation is enabled
  590. * @bonding: bool indicating whether traffic bonding is enabled
  591. * @fragmentation: bool indicating whether traffic fragmentation is enabled
  592. * @packet_size_max: max packet size that can be transmitted via
  593. * multiple fragmented skbs or a single frame if fragmentation is disabled
  594. * @frag_seqno: incremental counter to identify chains of egress fragments
  595. * @bridge_loop_avoidance: bool indicating whether bridge loop avoidance is
  596. * enabled
  597. * @distributed_arp_table: bool indicating whether distributed ARP table is
  598. * enabled
  599. * @gw_mode: gateway operation: off, client or server (see batadv_gw_modes)
  600. * @gw_sel_class: gateway selection class (applies if gw_mode client)
  601. * @orig_interval: OGM broadcast interval in milliseconds
  602. * @hop_penalty: penalty which will be applied to an OGM's tq-field on every hop
  603. * @log_level: configured log level (see batadv_dbg_level)
  604. * @bcast_seqno: last sent broadcast packet sequence number
  605. * @bcast_queue_left: number of remaining buffered broadcast packet slots
  606. * @batman_queue_left: number of remaining OGM packet slots
  607. * @num_ifaces: number of interfaces assigned to this mesh interface
  608. * @mesh_obj: kobject for sysfs mesh subdirectory
  609. * @debug_dir: dentry for debugfs batman-adv subdirectory
  610. * @forw_bat_list: list of aggregated OGMs that will be forwarded
  611. * @forw_bcast_list: list of broadcast packets that will be rebroadcasted
  612. * @orig_hash: hash table containing mesh participants (orig nodes)
  613. * @forw_bat_list_lock: lock protecting forw_bat_list
  614. * @forw_bcast_list_lock: lock protecting forw_bcast_list
  615. * @orig_work: work queue callback item for orig node purging
  616. * @cleanup_work: work queue callback item for soft interface deinit
  617. * @primary_if: one of the hard interfaces assigned to this mesh interface
  618. * becomes the primary interface
  619. * @bat_algo_ops: routing algorithm used by this mesh interface
  620. * @softif_vlan_list: a list of softif_vlan structs, one per VLAN created on top
  621. * of the mesh interface represented by this object
  622. * @softif_vlan_list_lock: lock protecting softif_vlan_list
  623. * @bla: bridge loope avoidance data
  624. * @debug_log: holding debug logging relevant data
  625. * @gw: gateway data
  626. * @tt: translation table data
  627. * @tvlv: type-version-length-value data
  628. * @dat: distributed arp table data
  629. * @network_coding: bool indicating whether network coding is enabled
  630. * @batadv_priv_nc: network coding data
  631. */
  632. struct batadv_priv {
  633. atomic_t mesh_state;
  634. struct net_device *soft_iface;
  635. struct net_device_stats stats;
  636. uint64_t __percpu *bat_counters; /* Per cpu counters */
  637. atomic_t aggregated_ogms;
  638. atomic_t bonding;
  639. atomic_t fragmentation;
  640. atomic_t packet_size_max;
  641. atomic_t frag_seqno;
  642. #ifdef CONFIG_BATMAN_ADV_BLA
  643. atomic_t bridge_loop_avoidance;
  644. #endif
  645. #ifdef CONFIG_BATMAN_ADV_DAT
  646. atomic_t distributed_arp_table;
  647. #endif
  648. atomic_t gw_mode;
  649. atomic_t gw_sel_class;
  650. atomic_t orig_interval;
  651. atomic_t hop_penalty;
  652. #ifdef CONFIG_BATMAN_ADV_DEBUG
  653. atomic_t log_level;
  654. #endif
  655. atomic_t bcast_seqno;
  656. atomic_t bcast_queue_left;
  657. atomic_t batman_queue_left;
  658. char num_ifaces;
  659. struct kobject *mesh_obj;
  660. struct dentry *debug_dir;
  661. struct hlist_head forw_bat_list;
  662. struct hlist_head forw_bcast_list;
  663. struct batadv_hashtable *orig_hash;
  664. spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
  665. spinlock_t forw_bcast_list_lock; /* protects forw_bcast_list */
  666. struct delayed_work orig_work;
  667. struct work_struct cleanup_work;
  668. struct batadv_hard_iface __rcu *primary_if; /* rcu protected pointer */
  669. struct batadv_algo_ops *bat_algo_ops;
  670. struct hlist_head softif_vlan_list;
  671. spinlock_t softif_vlan_list_lock; /* protects softif_vlan_list */
  672. #ifdef CONFIG_BATMAN_ADV_BLA
  673. struct batadv_priv_bla bla;
  674. #endif
  675. #ifdef CONFIG_BATMAN_ADV_DEBUG
  676. struct batadv_priv_debug_log *debug_log;
  677. #endif
  678. struct batadv_priv_gw gw;
  679. struct batadv_priv_tt tt;
  680. struct batadv_priv_tvlv tvlv;
  681. #ifdef CONFIG_BATMAN_ADV_DAT
  682. struct batadv_priv_dat dat;
  683. #endif
  684. #ifdef CONFIG_BATMAN_ADV_NC
  685. atomic_t network_coding;
  686. struct batadv_priv_nc nc;
  687. #endif /* CONFIG_BATMAN_ADV_NC */
  688. };
  689. /**
  690. * struct batadv_socket_client - layer2 icmp socket client data
  691. * @queue_list: packet queue for packets destined for this socket client
  692. * @queue_len: number of packets in the packet queue (queue_list)
  693. * @index: socket client's index in the batadv_socket_client_hash
  694. * @lock: lock protecting queue_list, queue_len & index
  695. * @queue_wait: socket client's wait queue
  696. * @bat_priv: pointer to soft_iface this client belongs to
  697. */
  698. struct batadv_socket_client {
  699. struct list_head queue_list;
  700. unsigned int queue_len;
  701. unsigned char index;
  702. spinlock_t lock; /* protects queue_list, queue_len & index */
  703. wait_queue_head_t queue_wait;
  704. struct batadv_priv *bat_priv;
  705. };
  706. /**
  707. * struct batadv_socket_packet - layer2 icmp packet for socket client
  708. * @list: list node for batadv_socket_client::queue_list
  709. * @icmp_len: size of the layer2 icmp packet
  710. * @icmp_packet: layer2 icmp packet
  711. */
  712. struct batadv_socket_packet {
  713. struct list_head list;
  714. size_t icmp_len;
  715. struct batadv_icmp_packet_rr icmp_packet;
  716. };
  717. /**
  718. * struct batadv_bla_backbone_gw - batman-adv gateway bridged into the LAN
  719. * @orig: originator address of backbone node (mac address of primary iface)
  720. * @vid: vlan id this gateway was detected on
  721. * @hash_entry: hlist node for batadv_priv_bla::backbone_hash
  722. * @bat_priv: pointer to soft_iface this backbone gateway belongs to
  723. * @lasttime: last time we heard of this backbone gw
  724. * @wait_periods: grace time for bridge forward delays and bla group forming at
  725. * bootup phase - no bcast traffic is formwared until it has elapsed
  726. * @request_sent: if this bool is set to true we are out of sync with this
  727. * backbone gateway - no bcast traffic is formwared until the situation was
  728. * resolved
  729. * @crc: crc16 checksum over all claims
  730. * @refcount: number of contexts the object is used
  731. * @rcu: struct used for freeing in an RCU-safe manner
  732. */
  733. #ifdef CONFIG_BATMAN_ADV_BLA
  734. struct batadv_bla_backbone_gw {
  735. uint8_t orig[ETH_ALEN];
  736. unsigned short vid;
  737. struct hlist_node hash_entry;
  738. struct batadv_priv *bat_priv;
  739. unsigned long lasttime;
  740. atomic_t wait_periods;
  741. atomic_t request_sent;
  742. uint16_t crc;
  743. atomic_t refcount;
  744. struct rcu_head rcu;
  745. };
  746. /**
  747. * struct batadv_bla_claim - claimed non-mesh client structure
  748. * @addr: mac address of claimed non-mesh client
  749. * @vid: vlan id this client was detected on
  750. * @batadv_bla_backbone_gw: pointer to backbone gw claiming this client
  751. * @lasttime: last time we heard of claim (locals only)
  752. * @hash_entry: hlist node for batadv_priv_bla::claim_hash
  753. * @refcount: number of contexts the object is used
  754. * @rcu: struct used for freeing in an RCU-safe manner
  755. */
  756. struct batadv_bla_claim {
  757. uint8_t addr[ETH_ALEN];
  758. unsigned short vid;
  759. struct batadv_bla_backbone_gw *backbone_gw;
  760. unsigned long lasttime;
  761. struct hlist_node hash_entry;
  762. struct rcu_head rcu;
  763. atomic_t refcount;
  764. };
  765. #endif
  766. /**
  767. * struct batadv_tt_common_entry - tt local & tt global common data
  768. * @addr: mac address of non-mesh client
  769. * @vid: VLAN identifier
  770. * @hash_entry: hlist node for batadv_priv_tt::local_hash or for
  771. * batadv_priv_tt::global_hash
  772. * @flags: various state handling flags (see batadv_tt_client_flags)
  773. * @added_at: timestamp used for purging stale tt common entries
  774. * @refcount: number of contexts the object is used
  775. * @rcu: struct used for freeing in an RCU-safe manner
  776. */
  777. struct batadv_tt_common_entry {
  778. uint8_t addr[ETH_ALEN];
  779. unsigned short vid;
  780. struct hlist_node hash_entry;
  781. uint16_t flags;
  782. unsigned long added_at;
  783. atomic_t refcount;
  784. struct rcu_head rcu;
  785. };
  786. /**
  787. * struct batadv_tt_local_entry - translation table local entry data
  788. * @common: general translation table data
  789. * @last_seen: timestamp used for purging stale tt local entries
  790. */
  791. struct batadv_tt_local_entry {
  792. struct batadv_tt_common_entry common;
  793. unsigned long last_seen;
  794. };
  795. /**
  796. * struct batadv_tt_global_entry - translation table global entry data
  797. * @common: general translation table data
  798. * @orig_list: list of orig nodes announcing this non-mesh client
  799. * @list_lock: lock protecting orig_list
  800. * @roam_at: time at which TT_GLOBAL_ROAM was set
  801. */
  802. struct batadv_tt_global_entry {
  803. struct batadv_tt_common_entry common;
  804. struct hlist_head orig_list;
  805. spinlock_t list_lock; /* protects orig_list */
  806. unsigned long roam_at;
  807. };
  808. /**
  809. * struct batadv_tt_orig_list_entry - orig node announcing a non-mesh client
  810. * @orig_node: pointer to orig node announcing this non-mesh client
  811. * @ttvn: translation table version number which added the non-mesh client
  812. * @list: list node for batadv_tt_global_entry::orig_list
  813. * @refcount: number of contexts the object is used
  814. * @rcu: struct used for freeing in an RCU-safe manner
  815. */
  816. struct batadv_tt_orig_list_entry {
  817. struct batadv_orig_node *orig_node;
  818. uint8_t ttvn;
  819. struct hlist_node list;
  820. atomic_t refcount;
  821. struct rcu_head rcu;
  822. };
  823. /**
  824. * struct batadv_tt_change_node - structure for tt changes occured
  825. * @list: list node for batadv_priv_tt::changes_list
  826. * @change: holds the actual translation table diff data
  827. */
  828. struct batadv_tt_change_node {
  829. struct list_head list;
  830. struct batadv_tvlv_tt_change change;
  831. };
  832. /**
  833. * struct batadv_tt_req_node - data to keep track of the tt requests in flight
  834. * @addr: mac address address of the originator this request was sent to
  835. * @issued_at: timestamp used for purging stale tt requests
  836. * @list: list node for batadv_priv_tt::req_list
  837. */
  838. struct batadv_tt_req_node {
  839. uint8_t addr[ETH_ALEN];
  840. unsigned long issued_at;
  841. struct list_head list;
  842. };
  843. /**
  844. * struct batadv_tt_roam_node - roaming client data
  845. * @addr: mac address of the client in the roaming phase
  846. * @counter: number of allowed roaming events per client within a single
  847. * OGM interval (changes are committed with each OGM)
  848. * @first_time: timestamp used for purging stale roaming node entries
  849. * @list: list node for batadv_priv_tt::roam_list
  850. */
  851. struct batadv_tt_roam_node {
  852. uint8_t addr[ETH_ALEN];
  853. atomic_t counter;
  854. unsigned long first_time;
  855. struct list_head list;
  856. };
  857. /**
  858. * struct batadv_nc_node - network coding node
  859. * @list: next and prev pointer for the list handling
  860. * @addr: the node's mac address
  861. * @refcount: number of contexts the object is used by
  862. * @rcu: struct used for freeing in an RCU-safe manner
  863. * @orig_node: pointer to corresponding orig node struct
  864. * @last_seen: timestamp of last ogm received from this node
  865. */
  866. struct batadv_nc_node {
  867. struct list_head list;
  868. uint8_t addr[ETH_ALEN];
  869. atomic_t refcount;
  870. struct rcu_head rcu;
  871. struct batadv_orig_node *orig_node;
  872. unsigned long last_seen;
  873. };
  874. /**
  875. * struct batadv_nc_path - network coding path
  876. * @hash_entry: next and prev pointer for the list handling
  877. * @rcu: struct used for freeing in an RCU-safe manner
  878. * @refcount: number of contexts the object is used by
  879. * @packet_list: list of buffered packets for this path
  880. * @packet_list_lock: access lock for packet list
  881. * @next_hop: next hop (destination) of path
  882. * @prev_hop: previous hop (source) of path
  883. * @last_valid: timestamp for last validation of path
  884. */
  885. struct batadv_nc_path {
  886. struct hlist_node hash_entry;
  887. struct rcu_head rcu;
  888. atomic_t refcount;
  889. struct list_head packet_list;
  890. spinlock_t packet_list_lock; /* Protects packet_list */
  891. uint8_t next_hop[ETH_ALEN];
  892. uint8_t prev_hop[ETH_ALEN];
  893. unsigned long last_valid;
  894. };
  895. /**
  896. * struct batadv_nc_packet - network coding packet used when coding and
  897. * decoding packets
  898. * @list: next and prev pointer for the list handling
  899. * @packet_id: crc32 checksum of skb data
  900. * @timestamp: field containing the info when the packet was added to path
  901. * @neigh_node: pointer to original next hop neighbor of skb
  902. * @skb: skb which can be encoded or used for decoding
  903. * @nc_path: pointer to path this nc packet is attached to
  904. */
  905. struct batadv_nc_packet {
  906. struct list_head list;
  907. __be32 packet_id;
  908. unsigned long timestamp;
  909. struct batadv_neigh_node *neigh_node;
  910. struct sk_buff *skb;
  911. struct batadv_nc_path *nc_path;
  912. };
  913. /**
  914. * batadv_skb_cb - control buffer structure used to store private data relevant
  915. * to batman-adv in the skb->cb buffer in skbs.
  916. * @decoded: Marks a skb as decoded, which is checked when searching for coding
  917. * opportunities in network-coding.c
  918. */
  919. struct batadv_skb_cb {
  920. bool decoded;
  921. };
  922. /**
  923. * struct batadv_forw_packet - structure for bcast packets to be sent/forwarded
  924. * @list: list node for batadv_socket_client::queue_list
  925. * @send_time: execution time for delayed_work (packet sending)
  926. * @own: bool for locally generated packets (local OGMs are re-scheduled after
  927. * sending)
  928. * @skb: bcast packet's skb buffer
  929. * @packet_len: size of aggregated OGM packet inside the skb buffer
  930. * @direct_link_flags: direct link flags for aggregated OGM packets
  931. * @num_packets: counter for bcast packet retransmission
  932. * @delayed_work: work queue callback item for packet sending
  933. * @if_incoming: pointer incoming hard-iface or primary iface if locally
  934. * generated packet
  935. */
  936. struct batadv_forw_packet {
  937. struct hlist_node list;
  938. unsigned long send_time;
  939. uint8_t own;
  940. struct sk_buff *skb;
  941. uint16_t packet_len;
  942. uint32_t direct_link_flags;
  943. uint8_t num_packets;
  944. struct delayed_work delayed_work;
  945. struct batadv_hard_iface *if_incoming;
  946. };
  947. /**
  948. * struct batadv_algo_ops - mesh algorithm callbacks
  949. * @list: list node for the batadv_algo_list
  950. * @name: name of the algorithm
  951. * @bat_iface_enable: init routing info when hard-interface is enabled
  952. * @bat_iface_disable: de-init routing info when hard-interface is disabled
  953. * @bat_iface_update_mac: (re-)init mac addresses of the protocol information
  954. * belonging to this hard-interface
  955. * @bat_primary_iface_set: called when primary interface is selected / changed
  956. * @bat_ogm_schedule: prepare a new outgoing OGM for the send queue
  957. * @bat_ogm_emit: send scheduled OGM
  958. * @bat_neigh_cmp: compare the metrics of two neighbors
  959. * @bat_neigh_is_equiv_or_better: check if neigh1 is equally good or
  960. * better than neigh2 from the metric prospective
  961. * @bat_orig_print: print the originator table (optional)
  962. * @bat_orig_free: free the resources allocated by the routing algorithm for an
  963. * orig_node object
  964. * @bat_orig_add_if: ask the routing algorithm to apply the needed changes to
  965. * the orig_node due to a new hard-interface being added into the mesh
  966. * @bat_orig_del_if: ask the routing algorithm to apply the needed changes to
  967. * the orig_node due to an hard-interface being removed from the mesh
  968. */
  969. struct batadv_algo_ops {
  970. struct hlist_node list;
  971. char *name;
  972. int (*bat_iface_enable)(struct batadv_hard_iface *hard_iface);
  973. void (*bat_iface_disable)(struct batadv_hard_iface *hard_iface);
  974. void (*bat_iface_update_mac)(struct batadv_hard_iface *hard_iface);
  975. void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);
  976. void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);
  977. void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
  978. int (*bat_neigh_cmp)(struct batadv_neigh_node *neigh1,
  979. struct batadv_neigh_node *neigh2);
  980. bool (*bat_neigh_is_equiv_or_better)(struct batadv_neigh_node *neigh1,
  981. struct batadv_neigh_node *neigh2);
  982. /* orig_node handling API */
  983. void (*bat_orig_print)(struct batadv_priv *priv, struct seq_file *seq);
  984. void (*bat_orig_free)(struct batadv_orig_node *orig_node);
  985. int (*bat_orig_add_if)(struct batadv_orig_node *orig_node,
  986. int max_if_num);
  987. int (*bat_orig_del_if)(struct batadv_orig_node *orig_node,
  988. int max_if_num, int del_if_num);
  989. };
  990. /**
  991. * struct batadv_dat_entry - it is a single entry of batman-adv ARP backend. It
  992. * is used to stored ARP entries needed for the global DAT cache
  993. * @ip: the IPv4 corresponding to this DAT/ARP entry
  994. * @mac_addr: the MAC address associated to the stored IPv4
  995. * @vid: the vlan ID associated to this entry
  996. * @last_update: time in jiffies when this entry was refreshed last time
  997. * @hash_entry: hlist node for batadv_priv_dat::hash
  998. * @refcount: number of contexts the object is used
  999. * @rcu: struct used for freeing in an RCU-safe manner
  1000. */
  1001. struct batadv_dat_entry {
  1002. __be32 ip;
  1003. uint8_t mac_addr[ETH_ALEN];
  1004. unsigned short vid;
  1005. unsigned long last_update;
  1006. struct hlist_node hash_entry;
  1007. atomic_t refcount;
  1008. struct rcu_head rcu;
  1009. };
  1010. /**
  1011. * struct batadv_dat_candidate - candidate destination for DAT operations
  1012. * @type: the type of the selected candidate. It can one of the following:
  1013. * - BATADV_DAT_CANDIDATE_NOT_FOUND
  1014. * - BATADV_DAT_CANDIDATE_ORIG
  1015. * @orig_node: if type is BATADV_DAT_CANDIDATE_ORIG this field points to the
  1016. * corresponding originator node structure
  1017. */
  1018. struct batadv_dat_candidate {
  1019. int type;
  1020. struct batadv_orig_node *orig_node;
  1021. };
  1022. /**
  1023. * struct batadv_tvlv_container - container for tvlv appended to OGMs
  1024. * @list: hlist node for batadv_priv_tvlv::container_list
  1025. * @tvlv_hdr: tvlv header information needed to construct the tvlv
  1026. * @value_len: length of the buffer following this struct which contains
  1027. * the actual tvlv payload
  1028. * @refcount: number of contexts the object is used
  1029. */
  1030. struct batadv_tvlv_container {
  1031. struct hlist_node list;
  1032. struct batadv_tvlv_hdr tvlv_hdr;
  1033. atomic_t refcount;
  1034. };
  1035. /**
  1036. * struct batadv_tvlv_handler - handler for specific tvlv type and version
  1037. * @list: hlist node for batadv_priv_tvlv::handler_list
  1038. * @ogm_handler: handler callback which is given the tvlv payload to process on
  1039. * incoming OGM packets
  1040. * @unicast_handler: handler callback which is given the tvlv payload to process
  1041. * on incoming unicast tvlv packets
  1042. * @type: tvlv type this handler feels responsible for
  1043. * @version: tvlv version this handler feels responsible for
  1044. * @flags: tvlv handler flags
  1045. * @refcount: number of contexts the object is used
  1046. * @rcu: struct used for freeing in an RCU-safe manner
  1047. */
  1048. struct batadv_tvlv_handler {
  1049. struct hlist_node list;
  1050. void (*ogm_handler)(struct batadv_priv *bat_priv,
  1051. struct batadv_orig_node *orig,
  1052. uint8_t flags,
  1053. void *tvlv_value, uint16_t tvlv_value_len);
  1054. int (*unicast_handler)(struct batadv_priv *bat_priv,
  1055. uint8_t *src, uint8_t *dst,
  1056. void *tvlv_value, uint16_t tvlv_value_len);
  1057. uint8_t type;
  1058. uint8_t version;
  1059. uint8_t flags;
  1060. atomic_t refcount;
  1061. struct rcu_head rcu;
  1062. };
  1063. /**
  1064. * enum batadv_tvlv_handler_flags - tvlv handler flags definitions
  1065. * @BATADV_TVLV_HANDLER_OGM_CIFNOTFND: tvlv ogm processing function will call
  1066. * this handler even if its type was not found (with no data)
  1067. * @BATADV_TVLV_HANDLER_OGM_CALLED: interval tvlv handling flag - the API marks
  1068. * a handler as being called, so it won't be called if the
  1069. * BATADV_TVLV_HANDLER_OGM_CIFNOTFND flag was set
  1070. */
  1071. enum batadv_tvlv_handler_flags {
  1072. BATADV_TVLV_HANDLER_OGM_CIFNOTFND = BIT(1),
  1073. BATADV_TVLV_HANDLER_OGM_CALLED = BIT(2),
  1074. };
  1075. #endif /* _NET_BATMAN_ADV_TYPES_H_ */