types.h 46 KB

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