types.h 41 KB

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