types.h 46 KB

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