types.h 46 KB

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