types.h 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2007-2018 B.A.T.M.A.N. contributors:
  3. *
  4. * Marek Lindner, Simon Wunderlich
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of version 2 of the GNU General Public
  8. * License as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef _NET_BATMAN_ADV_TYPES_H_
  19. #define _NET_BATMAN_ADV_TYPES_H_
  20. #ifndef _NET_BATMAN_ADV_MAIN_H_
  21. #error only "main.h" can be included directly
  22. #endif
  23. #include <linux/average.h>
  24. #include <linux/bitops.h>
  25. #include <linux/compiler.h>
  26. #include <linux/if_ether.h>
  27. #include <linux/kref.h>
  28. #include <linux/mutex.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/netlink.h>
  31. #include <linux/sched.h> /* for linux/wait.h */
  32. #include <linux/spinlock.h>
  33. #include <linux/types.h>
  34. #include <linux/wait.h>
  35. #include <linux/workqueue.h>
  36. #include <uapi/linux/batadv_packet.h>
  37. #include <uapi/linux/batman_adv.h>
  38. struct seq_file;
  39. #ifdef CONFIG_BATMAN_ADV_DAT
  40. /**
  41. * typedef batadv_dat_addr_t - type used for all DHT addresses
  42. *
  43. * If it is changed, BATADV_DAT_ADDR_MAX is changed as well.
  44. *
  45. * *Please be careful: batadv_dat_addr_t must be UNSIGNED*
  46. */
  47. typedef u16 batadv_dat_addr_t;
  48. #endif /* CONFIG_BATMAN_ADV_DAT */
  49. /**
  50. * enum batadv_dhcp_recipient - dhcp destination
  51. */
  52. enum batadv_dhcp_recipient {
  53. /** @BATADV_DHCP_NO: packet is not a dhcp message */
  54. BATADV_DHCP_NO = 0,
  55. /** @BATADV_DHCP_TO_SERVER: dhcp message is directed to a server */
  56. BATADV_DHCP_TO_SERVER,
  57. /** @BATADV_DHCP_TO_CLIENT: dhcp message is directed to a client */
  58. BATADV_DHCP_TO_CLIENT,
  59. };
  60. /**
  61. * BATADV_TT_REMOTE_MASK - bitmask selecting the flags that are sent over the
  62. * wire only
  63. */
  64. #define BATADV_TT_REMOTE_MASK 0x00FF
  65. /**
  66. * BATADV_TT_SYNC_MASK - bitmask of the flags that need to be kept in sync
  67. * among the nodes. These flags are used to compute the global/local CRC
  68. */
  69. #define BATADV_TT_SYNC_MASK 0x00F0
  70. /**
  71. * struct batadv_hard_iface_bat_iv - per hard-interface B.A.T.M.A.N. IV data
  72. */
  73. struct batadv_hard_iface_bat_iv {
  74. /** @ogm_buff: buffer holding the OGM packet */
  75. unsigned char *ogm_buff;
  76. /** @ogm_buff_len: length of the OGM packet buffer */
  77. int ogm_buff_len;
  78. /** @ogm_seqno: OGM sequence number - used to identify each OGM */
  79. atomic_t ogm_seqno;
  80. /** @ogm_buff_mutex: lock protecting ogm_buff and ogm_buff_len */
  81. struct mutex ogm_buff_mutex;
  82. };
  83. /**
  84. * enum batadv_v_hard_iface_flags - interface flags useful to B.A.T.M.A.N. V
  85. */
  86. enum batadv_v_hard_iface_flags {
  87. /**
  88. * @BATADV_FULL_DUPLEX: tells if the connection over this link is
  89. * full-duplex
  90. */
  91. BATADV_FULL_DUPLEX = BIT(0),
  92. /**
  93. * @BATADV_WARNING_DEFAULT: tells whether we have warned the user that
  94. * no throughput data is available for this interface and that default
  95. * values are assumed.
  96. */
  97. BATADV_WARNING_DEFAULT = BIT(1),
  98. };
  99. /**
  100. * struct batadv_hard_iface_bat_v - per hard-interface B.A.T.M.A.N. V data
  101. */
  102. struct batadv_hard_iface_bat_v {
  103. /** @elp_interval: time interval between two ELP transmissions */
  104. atomic_t elp_interval;
  105. /** @elp_seqno: current ELP sequence number */
  106. atomic_t elp_seqno;
  107. /** @elp_skb: base skb containing the ELP message to send */
  108. struct sk_buff *elp_skb;
  109. /** @elp_wq: workqueue used to schedule ELP transmissions */
  110. struct delayed_work elp_wq;
  111. /**
  112. * @throughput_override: throughput override to disable link
  113. * auto-detection
  114. */
  115. atomic_t throughput_override;
  116. /** @flags: interface specific flags */
  117. u8 flags;
  118. };
  119. /**
  120. * enum batadv_hard_iface_wifi_flags - Flags describing the wifi configuration
  121. * of a batadv_hard_iface
  122. */
  123. enum batadv_hard_iface_wifi_flags {
  124. /** @BATADV_HARDIF_WIFI_WEXT_DIRECT: it is a wext wifi device */
  125. BATADV_HARDIF_WIFI_WEXT_DIRECT = BIT(0),
  126. /** @BATADV_HARDIF_WIFI_CFG80211_DIRECT: it is a cfg80211 wifi device */
  127. BATADV_HARDIF_WIFI_CFG80211_DIRECT = BIT(1),
  128. /**
  129. * @BATADV_HARDIF_WIFI_WEXT_INDIRECT: link device is a wext wifi device
  130. */
  131. BATADV_HARDIF_WIFI_WEXT_INDIRECT = BIT(2),
  132. /**
  133. * @BATADV_HARDIF_WIFI_CFG80211_INDIRECT: link device is a cfg80211 wifi
  134. * device
  135. */
  136. BATADV_HARDIF_WIFI_CFG80211_INDIRECT = BIT(3),
  137. };
  138. /**
  139. * struct batadv_hard_iface - network device known to batman-adv
  140. */
  141. struct batadv_hard_iface {
  142. /** @list: list node for batadv_hardif_list */
  143. struct list_head list;
  144. /** @if_num: identificator of the interface */
  145. unsigned int if_num;
  146. /** @if_status: status of the interface for batman-adv */
  147. char if_status;
  148. /**
  149. * @num_bcasts: number of payload re-broadcasts on this interface (ARQ)
  150. */
  151. u8 num_bcasts;
  152. /**
  153. * @wifi_flags: flags whether this is (directly or indirectly) a wifi
  154. * interface
  155. */
  156. u32 wifi_flags;
  157. /** @net_dev: pointer to the net_device */
  158. struct net_device *net_dev;
  159. /** @hardif_obj: kobject of the per interface sysfs "mesh" directory */
  160. struct kobject *hardif_obj;
  161. /** @refcount: number of contexts the object is used */
  162. struct kref refcount;
  163. /**
  164. * @batman_adv_ptype: packet type describing packets that should be
  165. * processed by batman-adv for this interface
  166. */
  167. struct packet_type batman_adv_ptype;
  168. /**
  169. * @soft_iface: the batman-adv interface which uses this network
  170. * interface
  171. */
  172. struct net_device *soft_iface;
  173. /** @rcu: struct used for freeing in an RCU-safe manner */
  174. struct rcu_head rcu;
  175. /** @bat_iv: per hard-interface B.A.T.M.A.N. IV data */
  176. struct batadv_hard_iface_bat_iv bat_iv;
  177. #ifdef CONFIG_BATMAN_ADV_BATMAN_V
  178. /** @bat_v: per hard-interface B.A.T.M.A.N. V data */
  179. struct batadv_hard_iface_bat_v bat_v;
  180. #endif
  181. #ifdef CONFIG_BATMAN_ADV_DEBUGFS
  182. /**
  183. * @debug_dir: dentry for nc subdir in batman-adv directory in debugfs
  184. */
  185. struct dentry *debug_dir;
  186. #endif
  187. /**
  188. * @neigh_list: list of unique single hop neighbors via this interface
  189. */
  190. struct hlist_head neigh_list;
  191. /** @neigh_list_lock: lock protecting neigh_list */
  192. spinlock_t neigh_list_lock;
  193. };
  194. /**
  195. * struct batadv_orig_ifinfo - originator info per outgoing interface
  196. */
  197. struct batadv_orig_ifinfo {
  198. /** @list: list node for &batadv_orig_node.ifinfo_list */
  199. struct hlist_node list;
  200. /** @if_outgoing: pointer to outgoing hard-interface */
  201. struct batadv_hard_iface *if_outgoing;
  202. /** @router: router that should be used to reach this originator */
  203. struct batadv_neigh_node __rcu *router;
  204. /** @last_real_seqno: last and best known sequence number */
  205. u32 last_real_seqno;
  206. /** @last_ttl: ttl of last received packet */
  207. u8 last_ttl;
  208. /** @last_seqno_forwarded: seqno of the OGM which was forwarded last */
  209. u32 last_seqno_forwarded;
  210. /** @batman_seqno_reset: time when the batman seqno window was reset */
  211. unsigned long batman_seqno_reset;
  212. /** @refcount: number of contexts the object is used */
  213. struct kref refcount;
  214. /** @rcu: struct used for freeing in an RCU-safe manner */
  215. struct rcu_head rcu;
  216. };
  217. /**
  218. * struct batadv_frag_table_entry - head in the fragment buffer table
  219. */
  220. struct batadv_frag_table_entry {
  221. /** @fragment_list: head of list with fragments */
  222. struct hlist_head fragment_list;
  223. /** @lock: lock to protect the list of fragments */
  224. spinlock_t lock;
  225. /** @timestamp: time (jiffie) of last received fragment */
  226. unsigned long timestamp;
  227. /** @seqno: sequence number of the fragments in the list */
  228. u16 seqno;
  229. /** @size: accumulated size of packets in list */
  230. u16 size;
  231. /** @total_size: expected size of the assembled packet */
  232. u16 total_size;
  233. };
  234. /**
  235. * struct batadv_frag_list_entry - entry in a list of fragments
  236. */
  237. struct batadv_frag_list_entry {
  238. /** @list: list node information */
  239. struct hlist_node list;
  240. /** @skb: fragment */
  241. struct sk_buff *skb;
  242. /** @no: fragment number in the set */
  243. u8 no;
  244. };
  245. /**
  246. * struct batadv_vlan_tt - VLAN specific TT attributes
  247. */
  248. struct batadv_vlan_tt {
  249. /** @crc: CRC32 checksum of the entries belonging to this vlan */
  250. u32 crc;
  251. /** @num_entries: number of TT entries for this VLAN */
  252. atomic_t num_entries;
  253. };
  254. /**
  255. * struct batadv_orig_node_vlan - VLAN specific data per orig_node
  256. */
  257. struct batadv_orig_node_vlan {
  258. /** @vid: the VLAN identifier */
  259. unsigned short vid;
  260. /** @tt: VLAN specific TT attributes */
  261. struct batadv_vlan_tt tt;
  262. /** @list: list node for &batadv_orig_node.vlan_list */
  263. struct hlist_node list;
  264. /**
  265. * @refcount: number of context where this object is currently in use
  266. */
  267. struct kref refcount;
  268. /** @rcu: struct used for freeing in a RCU-safe manner */
  269. struct rcu_head rcu;
  270. };
  271. /**
  272. * struct batadv_orig_bat_iv - B.A.T.M.A.N. IV private orig_node members
  273. */
  274. struct batadv_orig_bat_iv {
  275. /**
  276. * @bcast_own: set of bitfields (one per hard-interface) where each one
  277. * counts the number of our OGMs this orig_node rebroadcasted "back" to
  278. * us (relative to last_real_seqno). Every bitfield is
  279. * BATADV_TQ_LOCAL_WINDOW_SIZE bits long.
  280. */
  281. unsigned long *bcast_own;
  282. /** @bcast_own_sum: sum of bcast_own */
  283. u8 *bcast_own_sum;
  284. /**
  285. * @ogm_cnt_lock: lock protecting bcast_own, bcast_own_sum,
  286. * neigh_node->bat_iv.real_bits & neigh_node->bat_iv.real_packet_count
  287. */
  288. spinlock_t ogm_cnt_lock;
  289. };
  290. /**
  291. * struct batadv_orig_node - structure for orig_list maintaining nodes of mesh
  292. */
  293. struct batadv_orig_node {
  294. /** @orig: originator ethernet address */
  295. u8 orig[ETH_ALEN];
  296. /** @ifinfo_list: list for routers per outgoing interface */
  297. struct hlist_head ifinfo_list;
  298. /**
  299. * @last_bonding_candidate: pointer to last ifinfo of last used router
  300. */
  301. struct batadv_orig_ifinfo *last_bonding_candidate;
  302. #ifdef CONFIG_BATMAN_ADV_DAT
  303. /** @dat_addr: address of the orig node in the distributed hash */
  304. batadv_dat_addr_t dat_addr;
  305. #endif
  306. /** @last_seen: time when last packet from this node was received */
  307. unsigned long last_seen;
  308. /**
  309. * @bcast_seqno_reset: time when the broadcast seqno window was reset
  310. */
  311. unsigned long bcast_seqno_reset;
  312. #ifdef CONFIG_BATMAN_ADV_MCAST
  313. /**
  314. * @mcast_handler_lock: synchronizes mcast-capability and -flag changes
  315. */
  316. spinlock_t mcast_handler_lock;
  317. /** @mcast_flags: multicast flags announced by the orig node */
  318. u8 mcast_flags;
  319. /**
  320. * @mcast_want_all_unsnoopables_node: a list node for the
  321. * mcast.want_all_unsnoopables list
  322. */
  323. struct hlist_node mcast_want_all_unsnoopables_node;
  324. /**
  325. * @mcast_want_all_ipv4_node: a list node for the mcast.want_all_ipv4
  326. * list
  327. */
  328. struct hlist_node mcast_want_all_ipv4_node;
  329. /**
  330. * @mcast_want_all_ipv6_node: a list node for the mcast.want_all_ipv6
  331. * list
  332. */
  333. struct hlist_node mcast_want_all_ipv6_node;
  334. #endif
  335. /** @capabilities: announced capabilities of this originator */
  336. unsigned long capabilities;
  337. /**
  338. * @capa_initialized: bitfield to remember whether a capability was
  339. * initialized
  340. */
  341. unsigned long capa_initialized;
  342. /** @last_ttvn: last seen translation table version number */
  343. atomic_t last_ttvn;
  344. /** @tt_buff: last tt changeset this node received from the orig node */
  345. unsigned char *tt_buff;
  346. /**
  347. * @tt_buff_len: length of the last tt changeset this node received
  348. * from the orig node
  349. */
  350. s16 tt_buff_len;
  351. /** @tt_buff_lock: lock that protects tt_buff and tt_buff_len */
  352. spinlock_t tt_buff_lock;
  353. /**
  354. * @tt_lock: prevents from updating the table while reading it. Table
  355. * update is made up by two operations (data structure update and
  356. * metdata -CRC/TTVN-recalculation) and they have to be executed
  357. * atomically in order to avoid another thread to read the
  358. * table/metadata between those.
  359. */
  360. spinlock_t tt_lock;
  361. /**
  362. * @bcast_bits: bitfield containing the info which payload broadcast
  363. * originated from this orig node this host already has seen (relative
  364. * to last_bcast_seqno)
  365. */
  366. DECLARE_BITMAP(bcast_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
  367. /**
  368. * @last_bcast_seqno: last broadcast sequence number received by this
  369. * host
  370. */
  371. u32 last_bcast_seqno;
  372. /**
  373. * @neigh_list: list of potential next hop neighbor towards this orig
  374. * node
  375. */
  376. struct hlist_head neigh_list;
  377. /**
  378. * @neigh_list_lock: lock protecting neigh_list, ifinfo_list,
  379. * last_bonding_candidate and router
  380. */
  381. spinlock_t neigh_list_lock;
  382. /** @hash_entry: hlist node for &batadv_priv.orig_hash */
  383. struct hlist_node hash_entry;
  384. /** @bat_priv: pointer to soft_iface this orig node belongs to */
  385. struct batadv_priv *bat_priv;
  386. /** @bcast_seqno_lock: lock protecting bcast_bits & last_bcast_seqno */
  387. spinlock_t bcast_seqno_lock;
  388. /** @refcount: number of contexts the object is used */
  389. struct kref refcount;
  390. /** @rcu: struct used for freeing in an RCU-safe manner */
  391. struct rcu_head rcu;
  392. #ifdef CONFIG_BATMAN_ADV_NC
  393. /** @in_coding_list: list of nodes this orig can hear */
  394. struct list_head in_coding_list;
  395. /** @out_coding_list: list of nodes that can hear this orig */
  396. struct list_head out_coding_list;
  397. /** @in_coding_list_lock: protects in_coding_list */
  398. spinlock_t in_coding_list_lock;
  399. /** @out_coding_list_lock: protects out_coding_list */
  400. spinlock_t out_coding_list_lock;
  401. #endif
  402. /** @fragments: array with heads for fragment chains */
  403. struct batadv_frag_table_entry fragments[BATADV_FRAG_BUFFER_COUNT];
  404. /**
  405. * @vlan_list: a list of orig_node_vlan structs, one per VLAN served by
  406. * the originator represented by this object
  407. */
  408. struct hlist_head vlan_list;
  409. /** @vlan_list_lock: lock protecting vlan_list */
  410. spinlock_t vlan_list_lock;
  411. /** @bat_iv: B.A.T.M.A.N. IV private structure */
  412. struct batadv_orig_bat_iv bat_iv;
  413. };
  414. /**
  415. * enum batadv_orig_capabilities - orig node capabilities
  416. */
  417. enum batadv_orig_capabilities {
  418. /**
  419. * @BATADV_ORIG_CAPA_HAS_DAT: orig node has distributed arp table
  420. * enabled
  421. */
  422. BATADV_ORIG_CAPA_HAS_DAT,
  423. /** @BATADV_ORIG_CAPA_HAS_NC: orig node has network coding enabled */
  424. BATADV_ORIG_CAPA_HAS_NC,
  425. /** @BATADV_ORIG_CAPA_HAS_TT: orig node has tt capability */
  426. BATADV_ORIG_CAPA_HAS_TT,
  427. /**
  428. * @BATADV_ORIG_CAPA_HAS_MCAST: orig node has some multicast capability
  429. * (= orig node announces a tvlv of type BATADV_TVLV_MCAST)
  430. */
  431. BATADV_ORIG_CAPA_HAS_MCAST,
  432. };
  433. /**
  434. * struct batadv_gw_node - structure for orig nodes announcing gw capabilities
  435. */
  436. struct batadv_gw_node {
  437. /** @list: list node for &batadv_priv_gw.list */
  438. struct hlist_node list;
  439. /** @orig_node: pointer to corresponding orig node */
  440. struct batadv_orig_node *orig_node;
  441. /** @bandwidth_down: advertised uplink download bandwidth */
  442. u32 bandwidth_down;
  443. /** @bandwidth_up: advertised uplink upload bandwidth */
  444. u32 bandwidth_up;
  445. /** @refcount: number of contexts the object is used */
  446. struct kref refcount;
  447. /** @rcu: struct used for freeing in an RCU-safe manner */
  448. struct rcu_head rcu;
  449. };
  450. DECLARE_EWMA(throughput, 10, 8)
  451. /**
  452. * struct batadv_hardif_neigh_node_bat_v - B.A.T.M.A.N. V private neighbor
  453. * information
  454. */
  455. struct batadv_hardif_neigh_node_bat_v {
  456. /** @throughput: ewma link throughput towards this neighbor */
  457. struct ewma_throughput throughput;
  458. /** @elp_interval: time interval between two ELP transmissions */
  459. u32 elp_interval;
  460. /** @elp_latest_seqno: latest and best known ELP sequence number */
  461. u32 elp_latest_seqno;
  462. /**
  463. * @last_unicast_tx: when the last unicast packet has been sent to this
  464. * neighbor
  465. */
  466. unsigned long last_unicast_tx;
  467. /** @metric_work: work queue callback item for metric update */
  468. struct work_struct metric_work;
  469. };
  470. /**
  471. * struct batadv_hardif_neigh_node - unique neighbor per hard-interface
  472. */
  473. struct batadv_hardif_neigh_node {
  474. /** @list: list node for &batadv_hard_iface.neigh_list */
  475. struct hlist_node list;
  476. /** @addr: the MAC address of the neighboring interface */
  477. u8 addr[ETH_ALEN];
  478. /**
  479. * @orig: the address of the originator this neighbor node belongs to
  480. */
  481. u8 orig[ETH_ALEN];
  482. /** @if_incoming: pointer to incoming hard-interface */
  483. struct batadv_hard_iface *if_incoming;
  484. /** @last_seen: when last packet via this neighbor was received */
  485. unsigned long last_seen;
  486. #ifdef CONFIG_BATMAN_ADV_BATMAN_V
  487. /** @bat_v: B.A.T.M.A.N. V private data */
  488. struct batadv_hardif_neigh_node_bat_v bat_v;
  489. #endif
  490. /** @refcount: number of contexts the object is used */
  491. struct kref refcount;
  492. /** @rcu: struct used for freeing in a RCU-safe manner */
  493. struct rcu_head rcu;
  494. };
  495. /**
  496. * struct batadv_neigh_node - structure for single hops neighbors
  497. */
  498. struct batadv_neigh_node {
  499. /** @list: list node for &batadv_orig_node.neigh_list */
  500. struct hlist_node list;
  501. /** @orig_node: pointer to corresponding orig_node */
  502. struct batadv_orig_node *orig_node;
  503. /** @addr: the MAC address of the neighboring interface */
  504. u8 addr[ETH_ALEN];
  505. /** @ifinfo_list: list for routing metrics per outgoing interface */
  506. struct hlist_head ifinfo_list;
  507. /** @ifinfo_lock: lock protecting ifinfo_list and its members */
  508. spinlock_t ifinfo_lock;
  509. /** @if_incoming: pointer to incoming hard-interface */
  510. struct batadv_hard_iface *if_incoming;
  511. /** @last_seen: when last packet via this neighbor was received */
  512. unsigned long last_seen;
  513. /** @hardif_neigh: hardif_neigh of this neighbor */
  514. struct batadv_hardif_neigh_node *hardif_neigh;
  515. /** @refcount: number of contexts the object is used */
  516. struct kref refcount;
  517. /** @rcu: struct used for freeing in an RCU-safe manner */
  518. struct rcu_head rcu;
  519. };
  520. /**
  521. * struct batadv_neigh_ifinfo_bat_iv - neighbor information per outgoing
  522. * interface for B.A.T.M.A.N. IV
  523. */
  524. struct batadv_neigh_ifinfo_bat_iv {
  525. /** @tq_recv: ring buffer of received TQ values from this neigh node */
  526. u8 tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE];
  527. /** @tq_index: ring buffer index */
  528. u8 tq_index;
  529. /**
  530. * @tq_avg: averaged tq of all tq values in the ring buffer (tq_recv)
  531. */
  532. u8 tq_avg;
  533. /**
  534. * @real_bits: bitfield containing the number of OGMs received from this
  535. * neigh node (relative to orig_node->last_real_seqno)
  536. */
  537. DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
  538. /** @real_packet_count: counted result of real_bits */
  539. u8 real_packet_count;
  540. };
  541. /**
  542. * struct batadv_neigh_ifinfo_bat_v - neighbor information per outgoing
  543. * interface for B.A.T.M.A.N. V
  544. */
  545. struct batadv_neigh_ifinfo_bat_v {
  546. /**
  547. * @throughput: last throughput metric received from originator via this
  548. * neigh
  549. */
  550. u32 throughput;
  551. /** @last_seqno: last sequence number known for this neighbor */
  552. u32 last_seqno;
  553. };
  554. /**
  555. * struct batadv_neigh_ifinfo - neighbor information per outgoing interface
  556. */
  557. struct batadv_neigh_ifinfo {
  558. /** @list: list node for &batadv_neigh_node.ifinfo_list */
  559. struct hlist_node list;
  560. /** @if_outgoing: pointer to outgoing hard-interface */
  561. struct batadv_hard_iface *if_outgoing;
  562. /** @bat_iv: B.A.T.M.A.N. IV private structure */
  563. struct batadv_neigh_ifinfo_bat_iv bat_iv;
  564. #ifdef CONFIG_BATMAN_ADV_BATMAN_V
  565. /** @bat_v: B.A.T.M.A.N. V private data */
  566. struct batadv_neigh_ifinfo_bat_v bat_v;
  567. #endif
  568. /** @last_ttl: last received ttl from this neigh node */
  569. u8 last_ttl;
  570. /** @refcount: number of contexts the object is used */
  571. struct kref refcount;
  572. /** @rcu: struct used for freeing in a RCU-safe manner */
  573. struct rcu_head rcu;
  574. };
  575. #ifdef CONFIG_BATMAN_ADV_BLA
  576. /**
  577. * struct batadv_bcast_duplist_entry - structure for LAN broadcast suppression
  578. */
  579. struct batadv_bcast_duplist_entry {
  580. /** @orig: mac address of orig node orginating the broadcast */
  581. u8 orig[ETH_ALEN];
  582. /** @crc: crc32 checksum of broadcast payload */
  583. __be32 crc;
  584. /** @entrytime: time when the broadcast packet was received */
  585. unsigned long entrytime;
  586. };
  587. #endif
  588. /**
  589. * enum batadv_counters - indices for traffic counters
  590. */
  591. enum batadv_counters {
  592. /** @BATADV_CNT_TX: transmitted payload traffic packet counter */
  593. BATADV_CNT_TX,
  594. /** @BATADV_CNT_TX_BYTES: transmitted payload traffic bytes counter */
  595. BATADV_CNT_TX_BYTES,
  596. /**
  597. * @BATADV_CNT_TX_DROPPED: dropped transmission payload traffic packet
  598. * counter
  599. */
  600. BATADV_CNT_TX_DROPPED,
  601. /** @BATADV_CNT_RX: received payload traffic packet counter */
  602. BATADV_CNT_RX,
  603. /** @BATADV_CNT_RX_BYTES: received payload traffic bytes counter */
  604. BATADV_CNT_RX_BYTES,
  605. /** @BATADV_CNT_FORWARD: forwarded payload traffic packet counter */
  606. BATADV_CNT_FORWARD,
  607. /**
  608. * @BATADV_CNT_FORWARD_BYTES: forwarded payload traffic bytes counter
  609. */
  610. BATADV_CNT_FORWARD_BYTES,
  611. /**
  612. * @BATADV_CNT_MGMT_TX: transmitted routing protocol traffic packet
  613. * counter
  614. */
  615. BATADV_CNT_MGMT_TX,
  616. /**
  617. * @BATADV_CNT_MGMT_TX_BYTES: transmitted routing protocol traffic bytes
  618. * counter
  619. */
  620. BATADV_CNT_MGMT_TX_BYTES,
  621. /**
  622. * @BATADV_CNT_MGMT_RX: received routing protocol traffic packet counter
  623. */
  624. BATADV_CNT_MGMT_RX,
  625. /**
  626. * @BATADV_CNT_MGMT_RX_BYTES: received routing protocol traffic bytes
  627. * counter
  628. */
  629. BATADV_CNT_MGMT_RX_BYTES,
  630. /** @BATADV_CNT_FRAG_TX: transmitted fragment traffic packet counter */
  631. BATADV_CNT_FRAG_TX,
  632. /**
  633. * @BATADV_CNT_FRAG_TX_BYTES: transmitted fragment traffic bytes counter
  634. */
  635. BATADV_CNT_FRAG_TX_BYTES,
  636. /** @BATADV_CNT_FRAG_RX: received fragment traffic packet counter */
  637. BATADV_CNT_FRAG_RX,
  638. /**
  639. * @BATADV_CNT_FRAG_RX_BYTES: received fragment traffic bytes counter
  640. */
  641. BATADV_CNT_FRAG_RX_BYTES,
  642. /** @BATADV_CNT_FRAG_FWD: forwarded fragment traffic packet counter */
  643. BATADV_CNT_FRAG_FWD,
  644. /**
  645. * @BATADV_CNT_FRAG_FWD_BYTES: forwarded fragment traffic bytes counter
  646. */
  647. BATADV_CNT_FRAG_FWD_BYTES,
  648. /**
  649. * @BATADV_CNT_TT_REQUEST_TX: transmitted tt req traffic packet counter
  650. */
  651. BATADV_CNT_TT_REQUEST_TX,
  652. /** @BATADV_CNT_TT_REQUEST_RX: received tt req traffic packet counter */
  653. BATADV_CNT_TT_REQUEST_RX,
  654. /**
  655. * @BATADV_CNT_TT_RESPONSE_TX: transmitted tt resp traffic packet
  656. * counter
  657. */
  658. BATADV_CNT_TT_RESPONSE_TX,
  659. /**
  660. * @BATADV_CNT_TT_RESPONSE_RX: received tt resp traffic packet counter
  661. */
  662. BATADV_CNT_TT_RESPONSE_RX,
  663. /**
  664. * @BATADV_CNT_TT_ROAM_ADV_TX: transmitted tt roam traffic packet
  665. * counter
  666. */
  667. BATADV_CNT_TT_ROAM_ADV_TX,
  668. /**
  669. * @BATADV_CNT_TT_ROAM_ADV_RX: received tt roam traffic packet counter
  670. */
  671. BATADV_CNT_TT_ROAM_ADV_RX,
  672. #ifdef CONFIG_BATMAN_ADV_DAT
  673. /**
  674. * @BATADV_CNT_DAT_GET_TX: transmitted dht GET traffic packet counter
  675. */
  676. BATADV_CNT_DAT_GET_TX,
  677. /** @BATADV_CNT_DAT_GET_RX: received dht GET traffic packet counter */
  678. BATADV_CNT_DAT_GET_RX,
  679. /**
  680. * @BATADV_CNT_DAT_PUT_TX: transmitted dht PUT traffic packet counter
  681. */
  682. BATADV_CNT_DAT_PUT_TX,
  683. /** @BATADV_CNT_DAT_PUT_RX: received dht PUT traffic packet counter */
  684. BATADV_CNT_DAT_PUT_RX,
  685. /**
  686. * @BATADV_CNT_DAT_CACHED_REPLY_TX: transmitted dat cache reply traffic
  687. * packet counter
  688. */
  689. BATADV_CNT_DAT_CACHED_REPLY_TX,
  690. #endif
  691. #ifdef CONFIG_BATMAN_ADV_NC
  692. /**
  693. * @BATADV_CNT_NC_CODE: transmitted nc-combined traffic packet counter
  694. */
  695. BATADV_CNT_NC_CODE,
  696. /**
  697. * @BATADV_CNT_NC_CODE_BYTES: transmitted nc-combined traffic bytes
  698. * counter
  699. */
  700. BATADV_CNT_NC_CODE_BYTES,
  701. /**
  702. * @BATADV_CNT_NC_RECODE: transmitted nc-recombined traffic packet
  703. * counter
  704. */
  705. BATADV_CNT_NC_RECODE,
  706. /**
  707. * @BATADV_CNT_NC_RECODE_BYTES: transmitted nc-recombined traffic bytes
  708. * counter
  709. */
  710. BATADV_CNT_NC_RECODE_BYTES,
  711. /**
  712. * @BATADV_CNT_NC_BUFFER: counter for packets buffered for later nc
  713. * decoding
  714. */
  715. BATADV_CNT_NC_BUFFER,
  716. /**
  717. * @BATADV_CNT_NC_DECODE: received and nc-decoded traffic packet counter
  718. */
  719. BATADV_CNT_NC_DECODE,
  720. /**
  721. * @BATADV_CNT_NC_DECODE_BYTES: received and nc-decoded traffic bytes
  722. * counter
  723. */
  724. BATADV_CNT_NC_DECODE_BYTES,
  725. /**
  726. * @BATADV_CNT_NC_DECODE_FAILED: received and decode-failed traffic
  727. * packet counter
  728. */
  729. BATADV_CNT_NC_DECODE_FAILED,
  730. /**
  731. * @BATADV_CNT_NC_SNIFFED: counter for nc-decoded packets received in
  732. * promisc mode.
  733. */
  734. BATADV_CNT_NC_SNIFFED,
  735. #endif
  736. /** @BATADV_CNT_NUM: number of traffic counters */
  737. BATADV_CNT_NUM,
  738. };
  739. /**
  740. * struct batadv_priv_tt - per mesh interface translation table data
  741. */
  742. struct batadv_priv_tt {
  743. /** @vn: translation table version number */
  744. atomic_t vn;
  745. /**
  746. * @ogm_append_cnt: counter of number of OGMs containing the local tt
  747. * diff
  748. */
  749. atomic_t ogm_append_cnt;
  750. /** @local_changes: changes registered in an originator interval */
  751. atomic_t local_changes;
  752. /**
  753. * @changes_list: tracks tt local changes within an originator interval
  754. */
  755. struct list_head changes_list;
  756. /** @local_hash: local translation table hash table */
  757. struct batadv_hashtable *local_hash;
  758. /** @global_hash: global translation table hash table */
  759. struct batadv_hashtable *global_hash;
  760. /** @req_list: list of pending & unanswered tt_requests */
  761. struct hlist_head req_list;
  762. /**
  763. * @roam_list: list of the last roaming events of each client limiting
  764. * the number of roaming events to avoid route flapping
  765. */
  766. struct list_head roam_list;
  767. /** @changes_list_lock: lock protecting changes_list */
  768. spinlock_t changes_list_lock;
  769. /** @req_list_lock: lock protecting req_list */
  770. spinlock_t req_list_lock;
  771. /** @roam_list_lock: lock protecting roam_list */
  772. spinlock_t roam_list_lock;
  773. /** @last_changeset: last tt changeset this host has generated */
  774. unsigned char *last_changeset;
  775. /**
  776. * @last_changeset_len: length of last tt changeset this host has
  777. * generated
  778. */
  779. s16 last_changeset_len;
  780. /**
  781. * @last_changeset_lock: lock protecting last_changeset &
  782. * last_changeset_len
  783. */
  784. spinlock_t last_changeset_lock;
  785. /**
  786. * @commit_lock: prevents from executing a local TT commit while reading
  787. * the local table. The local TT commit is made up by two operations
  788. * (data structure update and metdata -CRC/TTVN- recalculation) and
  789. * they have to be executed atomically in order to avoid another thread
  790. * to read the table/metadata between those.
  791. */
  792. spinlock_t commit_lock;
  793. /** @work: work queue callback item for translation table purging */
  794. struct delayed_work work;
  795. };
  796. #ifdef CONFIG_BATMAN_ADV_BLA
  797. /**
  798. * struct batadv_priv_bla - per mesh interface bridge loope avoidance data
  799. */
  800. struct batadv_priv_bla {
  801. /** @num_requests: number of bla requests in flight */
  802. atomic_t num_requests;
  803. /**
  804. * @claim_hash: hash table containing mesh nodes this host has claimed
  805. */
  806. struct batadv_hashtable *claim_hash;
  807. /**
  808. * @backbone_hash: hash table containing all detected backbone gateways
  809. */
  810. struct batadv_hashtable *backbone_hash;
  811. /** @loopdetect_addr: MAC address used for own loopdetection frames */
  812. u8 loopdetect_addr[ETH_ALEN];
  813. /**
  814. * @loopdetect_lasttime: time when the loopdetection frames were sent
  815. */
  816. unsigned long loopdetect_lasttime;
  817. /**
  818. * @loopdetect_next: how many periods to wait for the next loopdetect
  819. * process
  820. */
  821. atomic_t loopdetect_next;
  822. /**
  823. * @bcast_duplist: recently received broadcast packets array (for
  824. * broadcast duplicate suppression)
  825. */
  826. struct batadv_bcast_duplist_entry bcast_duplist[BATADV_DUPLIST_SIZE];
  827. /**
  828. * @bcast_duplist_curr: index of last broadcast packet added to
  829. * bcast_duplist
  830. */
  831. int bcast_duplist_curr;
  832. /**
  833. * @bcast_duplist_lock: lock protecting bcast_duplist &
  834. * bcast_duplist_curr
  835. */
  836. spinlock_t bcast_duplist_lock;
  837. /** @claim_dest: local claim data (e.g. claim group) */
  838. struct batadv_bla_claim_dst claim_dest;
  839. /** @work: work queue callback item for cleanups & bla announcements */
  840. struct delayed_work work;
  841. };
  842. #endif
  843. #ifdef CONFIG_BATMAN_ADV_DEBUG
  844. /**
  845. * struct batadv_priv_debug_log - debug logging data
  846. */
  847. struct batadv_priv_debug_log {
  848. /** @log_buff: buffer holding the logs (ring bufer) */
  849. char log_buff[BATADV_LOG_BUF_LEN];
  850. /** @log_start: index of next character to read */
  851. unsigned long log_start;
  852. /** @log_end: index of next character to write */
  853. unsigned long log_end;
  854. /** @lock: lock protecting log_buff, log_start & log_end */
  855. spinlock_t lock;
  856. /** @queue_wait: log reader's wait queue */
  857. wait_queue_head_t queue_wait;
  858. };
  859. #endif
  860. /**
  861. * struct batadv_priv_gw - per mesh interface gateway data
  862. */
  863. struct batadv_priv_gw {
  864. /** @gateway_list: list of available gateway nodes */
  865. struct hlist_head gateway_list;
  866. /** @list_lock: lock protecting gateway_list & curr_gw */
  867. spinlock_t list_lock;
  868. /** @curr_gw: pointer to currently selected gateway node */
  869. struct batadv_gw_node __rcu *curr_gw;
  870. /**
  871. * @mode: gateway operation: off, client or server (see batadv_gw_modes)
  872. */
  873. atomic_t mode;
  874. /** @sel_class: gateway selection class (applies if gw_mode client) */
  875. atomic_t sel_class;
  876. /**
  877. * @bandwidth_down: advertised uplink download bandwidth (if gw_mode
  878. * server)
  879. */
  880. atomic_t bandwidth_down;
  881. /**
  882. * @bandwidth_up: advertised uplink upload bandwidth (if gw_mode server)
  883. */
  884. atomic_t bandwidth_up;
  885. /** @reselect: bool indicating a gateway re-selection is in progress */
  886. atomic_t reselect;
  887. };
  888. /**
  889. * struct batadv_priv_tvlv - per mesh interface tvlv data
  890. */
  891. struct batadv_priv_tvlv {
  892. /**
  893. * @container_list: list of registered tvlv containers to be sent with
  894. * each OGM
  895. */
  896. struct hlist_head container_list;
  897. /** @handler_list: list of the various tvlv content handlers */
  898. struct hlist_head handler_list;
  899. /** @container_list_lock: protects tvlv container list access */
  900. spinlock_t container_list_lock;
  901. /** @handler_list_lock: protects handler list access */
  902. spinlock_t handler_list_lock;
  903. };
  904. #ifdef CONFIG_BATMAN_ADV_DAT
  905. /**
  906. * struct batadv_priv_dat - per mesh interface DAT private data
  907. */
  908. struct batadv_priv_dat {
  909. /** @addr: node DAT address */
  910. batadv_dat_addr_t addr;
  911. /** @hash: hashtable representing the local ARP cache */
  912. struct batadv_hashtable *hash;
  913. /** @work: work queue callback item for cache purging */
  914. struct delayed_work work;
  915. };
  916. #endif
  917. #ifdef CONFIG_BATMAN_ADV_MCAST
  918. /**
  919. * struct batadv_mcast_querier_state - IGMP/MLD querier state when bridged
  920. */
  921. struct batadv_mcast_querier_state {
  922. /** @exists: whether a querier exists in the mesh */
  923. unsigned char exists:1;
  924. /**
  925. * @shadowing: if a querier exists, whether it is potentially shadowing
  926. * multicast listeners (i.e. querier is behind our own bridge segment)
  927. */
  928. unsigned char shadowing:1;
  929. };
  930. /**
  931. * struct batadv_priv_mcast - per mesh interface mcast data
  932. */
  933. struct batadv_priv_mcast {
  934. /**
  935. * @mla_list: list of multicast addresses we are currently announcing
  936. * via TT
  937. */
  938. struct hlist_head mla_list; /* see __batadv_mcast_mla_update() */
  939. /**
  940. * @want_all_unsnoopables_list: a list of orig_nodes wanting all
  941. * unsnoopable multicast traffic
  942. */
  943. struct hlist_head want_all_unsnoopables_list;
  944. /**
  945. * @want_all_ipv4_list: a list of orig_nodes wanting all IPv4 multicast
  946. * traffic
  947. */
  948. struct hlist_head want_all_ipv4_list;
  949. /**
  950. * @want_all_ipv6_list: a list of orig_nodes wanting all IPv6 multicast
  951. * traffic
  952. */
  953. struct hlist_head want_all_ipv6_list;
  954. /** @querier_ipv4: the current state of an IGMP querier in the mesh */
  955. struct batadv_mcast_querier_state querier_ipv4;
  956. /** @querier_ipv6: the current state of an MLD querier in the mesh */
  957. struct batadv_mcast_querier_state querier_ipv6;
  958. /** @flags: the flags we have last sent in our mcast tvlv */
  959. u8 flags;
  960. /** @enabled: whether the multicast tvlv is currently enabled */
  961. unsigned char enabled:1;
  962. /** @bridged: whether the soft interface has a bridge on top */
  963. unsigned char bridged:1;
  964. /**
  965. * @mla_lock: a lock protecting mla_list and mla_flags
  966. */
  967. spinlock_t mla_lock;
  968. /**
  969. * @num_want_all_unsnoopables: number of nodes wanting unsnoopable IP
  970. * traffic
  971. */
  972. atomic_t num_want_all_unsnoopables;
  973. /** @num_want_all_ipv4: counter for items in want_all_ipv4_list */
  974. atomic_t num_want_all_ipv4;
  975. /** @num_want_all_ipv6: counter for items in want_all_ipv6_list */
  976. atomic_t num_want_all_ipv6;
  977. /**
  978. * @want_lists_lock: lock for protecting modifications to mcasts
  979. * want_all_{unsnoopables,ipv4,ipv6}_list (traversals are rcu-locked)
  980. */
  981. spinlock_t want_lists_lock;
  982. /** @work: work queue callback item for multicast TT and TVLV updates */
  983. struct delayed_work work;
  984. };
  985. #endif
  986. /**
  987. * struct batadv_priv_nc - per mesh interface network coding private data
  988. */
  989. struct batadv_priv_nc {
  990. /** @work: work queue callback item for cleanup */
  991. struct delayed_work work;
  992. #ifdef CONFIG_BATMAN_ADV_DEBUGFS
  993. /**
  994. * @debug_dir: dentry for nc subdir in batman-adv directory in debugfs
  995. */
  996. struct dentry *debug_dir;
  997. #endif
  998. /**
  999. * @min_tq: only consider neighbors for encoding if neigh_tq > min_tq
  1000. */
  1001. u8 min_tq;
  1002. /**
  1003. * @max_fwd_delay: maximum packet forward delay to allow coding of
  1004. * packets
  1005. */
  1006. u32 max_fwd_delay;
  1007. /**
  1008. * @max_buffer_time: buffer time for sniffed packets used to decoding
  1009. */
  1010. u32 max_buffer_time;
  1011. /**
  1012. * @timestamp_fwd_flush: timestamp of last forward packet queue flush
  1013. */
  1014. unsigned long timestamp_fwd_flush;
  1015. /**
  1016. * @timestamp_sniffed_purge: timestamp of last sniffed packet queue
  1017. * purge
  1018. */
  1019. unsigned long timestamp_sniffed_purge;
  1020. /**
  1021. * @coding_hash: Hash table used to buffer skbs while waiting for
  1022. * another incoming skb to code it with. Skbs are added to the buffer
  1023. * just before being forwarded in routing.c
  1024. */
  1025. struct batadv_hashtable *coding_hash;
  1026. /**
  1027. * @decoding_hash: Hash table used to buffer skbs that might be needed
  1028. * to decode a received coded skb. The buffer is used for 1) skbs
  1029. * arriving on the soft-interface; 2) skbs overheard on the
  1030. * hard-interface; and 3) skbs forwarded by batman-adv.
  1031. */
  1032. struct batadv_hashtable *decoding_hash;
  1033. };
  1034. /**
  1035. * struct batadv_tp_unacked - unacked packet meta-information
  1036. *
  1037. * This struct is supposed to represent a buffer unacked packet. However, since
  1038. * the purpose of the TP meter is to count the traffic only, there is no need to
  1039. * store the entire sk_buff, the starting offset and the length are enough
  1040. */
  1041. struct batadv_tp_unacked {
  1042. /** @seqno: seqno of the unacked packet */
  1043. u32 seqno;
  1044. /** @len: length of the packet */
  1045. u16 len;
  1046. /** @list: list node for &batadv_tp_vars.unacked_list */
  1047. struct list_head list;
  1048. };
  1049. /**
  1050. * enum batadv_tp_meter_role - Modus in tp meter session
  1051. */
  1052. enum batadv_tp_meter_role {
  1053. /** @BATADV_TP_RECEIVER: Initialized as receiver */
  1054. BATADV_TP_RECEIVER,
  1055. /** @BATADV_TP_SENDER: Initialized as sender */
  1056. BATADV_TP_SENDER
  1057. };
  1058. /**
  1059. * struct batadv_tp_vars - tp meter private variables per session
  1060. */
  1061. struct batadv_tp_vars {
  1062. /** @list: list node for &bat_priv.tp_list */
  1063. struct hlist_node list;
  1064. /** @timer: timer for ack (receiver) and retry (sender) */
  1065. struct timer_list timer;
  1066. /** @bat_priv: pointer to the mesh object */
  1067. struct batadv_priv *bat_priv;
  1068. /** @start_time: start time in jiffies */
  1069. unsigned long start_time;
  1070. /** @other_end: mac address of remote */
  1071. u8 other_end[ETH_ALEN];
  1072. /** @role: receiver/sender modi */
  1073. enum batadv_tp_meter_role role;
  1074. /** @sending: sending binary semaphore: 1 if sending, 0 is not */
  1075. atomic_t sending;
  1076. /** @reason: reason for a stopped session */
  1077. enum batadv_tp_meter_reason reason;
  1078. /** @finish_work: work item for the finishing procedure */
  1079. struct delayed_work finish_work;
  1080. /** @test_length: test length in milliseconds */
  1081. u32 test_length;
  1082. /** @session: TP session identifier */
  1083. u8 session[2];
  1084. /** @icmp_uid: local ICMP "socket" index */
  1085. u8 icmp_uid;
  1086. /* sender variables */
  1087. /** @dec_cwnd: decimal part of the cwnd used during linear growth */
  1088. u16 dec_cwnd;
  1089. /** @cwnd: current size of the congestion window */
  1090. u32 cwnd;
  1091. /** @cwnd_lock: lock do protect @cwnd & @dec_cwnd */
  1092. spinlock_t cwnd_lock;
  1093. /**
  1094. * @ss_threshold: Slow Start threshold. Once cwnd exceeds this value the
  1095. * connection switches to the Congestion Avoidance state
  1096. */
  1097. u32 ss_threshold;
  1098. /** @last_acked: last acked byte */
  1099. atomic_t last_acked;
  1100. /** @last_sent: last sent byte, not yet acked */
  1101. u32 last_sent;
  1102. /** @tot_sent: amount of data sent/ACKed so far */
  1103. atomic64_t tot_sent;
  1104. /** @dup_acks: duplicate ACKs counter */
  1105. atomic_t dup_acks;
  1106. /** @fast_recovery: true if in Fast Recovery mode */
  1107. unsigned char fast_recovery:1;
  1108. /** @recover: last sent seqno when entering Fast Recovery */
  1109. u32 recover;
  1110. /** @rto: sender timeout */
  1111. u32 rto;
  1112. /** @srtt: smoothed RTT scaled by 2^3 */
  1113. u32 srtt;
  1114. /** @rttvar: RTT variation scaled by 2^2 */
  1115. u32 rttvar;
  1116. /**
  1117. * @more_bytes: waiting queue anchor when waiting for more ack/retry
  1118. * timeout
  1119. */
  1120. wait_queue_head_t more_bytes;
  1121. /** @prerandom_offset: offset inside the prerandom buffer */
  1122. u32 prerandom_offset;
  1123. /** @prerandom_lock: spinlock protecting access to prerandom_offset */
  1124. spinlock_t prerandom_lock;
  1125. /* receiver variables */
  1126. /** @last_recv: last in-order received packet */
  1127. u32 last_recv;
  1128. /** @unacked_list: list of unacked packets (meta-info only) */
  1129. struct list_head unacked_list;
  1130. /** @unacked_lock: protect unacked_list */
  1131. spinlock_t unacked_lock;
  1132. /** @last_recv_time: time time (jiffies) a msg was received */
  1133. unsigned long last_recv_time;
  1134. /** @refcount: number of context where the object is used */
  1135. struct kref refcount;
  1136. /** @rcu: struct used for freeing in an RCU-safe manner */
  1137. struct rcu_head rcu;
  1138. };
  1139. /**
  1140. * struct batadv_softif_vlan - per VLAN attributes set
  1141. */
  1142. struct batadv_softif_vlan {
  1143. /** @bat_priv: pointer to the mesh object */
  1144. struct batadv_priv *bat_priv;
  1145. /** @vid: VLAN identifier */
  1146. unsigned short vid;
  1147. /** @kobj: kobject for sysfs vlan subdirectory */
  1148. struct kobject *kobj;
  1149. /** @ap_isolation: AP isolation state */
  1150. atomic_t ap_isolation; /* boolean */
  1151. /** @tt: TT private attributes (VLAN specific) */
  1152. struct batadv_vlan_tt tt;
  1153. /** @list: list node for &bat_priv.softif_vlan_list */
  1154. struct hlist_node list;
  1155. /**
  1156. * @refcount: number of context where this object is currently in use
  1157. */
  1158. struct kref refcount;
  1159. /** @rcu: struct used for freeing in a RCU-safe manner */
  1160. struct rcu_head rcu;
  1161. };
  1162. /**
  1163. * struct batadv_priv_bat_v - B.A.T.M.A.N. V per soft-interface private data
  1164. */
  1165. struct batadv_priv_bat_v {
  1166. /** @ogm_buff: buffer holding the OGM packet */
  1167. unsigned char *ogm_buff;
  1168. /** @ogm_buff_len: length of the OGM packet buffer */
  1169. int ogm_buff_len;
  1170. /** @ogm_seqno: OGM sequence number - used to identify each OGM */
  1171. atomic_t ogm_seqno;
  1172. /** @ogm_buff_mutex: lock protecting ogm_buff and ogm_buff_len */
  1173. struct mutex ogm_buff_mutex;
  1174. /** @ogm_wq: workqueue used to schedule OGM transmissions */
  1175. struct delayed_work ogm_wq;
  1176. };
  1177. /**
  1178. * struct batadv_priv - per mesh interface data
  1179. */
  1180. struct batadv_priv {
  1181. /**
  1182. * @mesh_state: current status of the mesh
  1183. * (inactive/active/deactivating)
  1184. */
  1185. atomic_t mesh_state;
  1186. /** @soft_iface: net device which holds this struct as private data */
  1187. struct net_device *soft_iface;
  1188. /**
  1189. * @bat_counters: mesh internal traffic statistic counters (see
  1190. * batadv_counters)
  1191. */
  1192. u64 __percpu *bat_counters; /* Per cpu counters */
  1193. /**
  1194. * @aggregated_ogms: bool indicating whether OGM aggregation is enabled
  1195. */
  1196. atomic_t aggregated_ogms;
  1197. /** @bonding: bool indicating whether traffic bonding is enabled */
  1198. atomic_t bonding;
  1199. /**
  1200. * @fragmentation: bool indicating whether traffic fragmentation is
  1201. * enabled
  1202. */
  1203. atomic_t fragmentation;
  1204. /**
  1205. * @packet_size_max: max packet size that can be transmitted via
  1206. * multiple fragmented skbs or a single frame if fragmentation is
  1207. * disabled
  1208. */
  1209. atomic_t packet_size_max;
  1210. /**
  1211. * @frag_seqno: incremental counter to identify chains of egress
  1212. * fragments
  1213. */
  1214. atomic_t frag_seqno;
  1215. #ifdef CONFIG_BATMAN_ADV_BLA
  1216. /**
  1217. * @bridge_loop_avoidance: bool indicating whether bridge loop
  1218. * avoidance is enabled
  1219. */
  1220. atomic_t bridge_loop_avoidance;
  1221. #endif
  1222. #ifdef CONFIG_BATMAN_ADV_DAT
  1223. /**
  1224. * @distributed_arp_table: bool indicating whether distributed ARP table
  1225. * is enabled
  1226. */
  1227. atomic_t distributed_arp_table;
  1228. #endif
  1229. #ifdef CONFIG_BATMAN_ADV_MCAST
  1230. /**
  1231. * @multicast_mode: Enable or disable multicast optimizations on this
  1232. * node's sender/originating side
  1233. */
  1234. atomic_t multicast_mode;
  1235. #endif
  1236. /** @orig_interval: OGM broadcast interval in milliseconds */
  1237. atomic_t orig_interval;
  1238. /**
  1239. * @hop_penalty: penalty which will be applied to an OGM's tq-field on
  1240. * every hop
  1241. */
  1242. atomic_t hop_penalty;
  1243. #ifdef CONFIG_BATMAN_ADV_DEBUG
  1244. /** @log_level: configured log level (see batadv_dbg_level) */
  1245. atomic_t log_level;
  1246. #endif
  1247. /**
  1248. * @isolation_mark: the skb->mark value used to match packets for AP
  1249. * isolation
  1250. */
  1251. u32 isolation_mark;
  1252. /**
  1253. * @isolation_mark_mask: bitmask identifying the bits in skb->mark to be
  1254. * used for the isolation mark
  1255. */
  1256. u32 isolation_mark_mask;
  1257. /** @bcast_seqno: last sent broadcast packet sequence number */
  1258. atomic_t bcast_seqno;
  1259. /**
  1260. * @bcast_queue_left: number of remaining buffered broadcast packet
  1261. * slots
  1262. */
  1263. atomic_t bcast_queue_left;
  1264. /** @batman_queue_left: number of remaining OGM packet slots */
  1265. atomic_t batman_queue_left;
  1266. /** @num_ifaces: number of interfaces assigned to this mesh interface */
  1267. unsigned int num_ifaces;
  1268. /** @mesh_obj: kobject for sysfs mesh subdirectory */
  1269. struct kobject *mesh_obj;
  1270. #ifdef CONFIG_BATMAN_ADV_DEBUGFS
  1271. /** @debug_dir: dentry for debugfs batman-adv subdirectory */
  1272. struct dentry *debug_dir;
  1273. #endif
  1274. /** @forw_bat_list: list of aggregated OGMs that will be forwarded */
  1275. struct hlist_head forw_bat_list;
  1276. /**
  1277. * @forw_bcast_list: list of broadcast packets that will be
  1278. * rebroadcasted
  1279. */
  1280. struct hlist_head forw_bcast_list;
  1281. /** @tp_list: list of tp sessions */
  1282. struct hlist_head tp_list;
  1283. /** @tp_num: number of currently active tp sessions */
  1284. struct batadv_hashtable *orig_hash;
  1285. /** @orig_hash: hash table containing mesh participants (orig nodes) */
  1286. spinlock_t forw_bat_list_lock;
  1287. /** @forw_bat_list_lock: lock protecting forw_bat_list */
  1288. spinlock_t forw_bcast_list_lock;
  1289. /** @forw_bcast_list_lock: lock protecting forw_bcast_list */
  1290. spinlock_t tp_list_lock;
  1291. /** @tp_list_lock: spinlock protecting @tp_list */
  1292. atomic_t tp_num;
  1293. /** @orig_work: work queue callback item for orig node purging */
  1294. struct delayed_work orig_work;
  1295. /**
  1296. * @primary_if: one of the hard-interfaces assigned to this mesh
  1297. * interface becomes the primary interface
  1298. */
  1299. struct batadv_hard_iface __rcu *primary_if; /* rcu protected pointer */
  1300. /** @algo_ops: routing algorithm used by this mesh interface */
  1301. struct batadv_algo_ops *algo_ops;
  1302. /**
  1303. * @softif_vlan_list: a list of softif_vlan structs, one per VLAN
  1304. * created on top of the mesh interface represented by this object
  1305. */
  1306. struct hlist_head softif_vlan_list;
  1307. /** @softif_vlan_list_lock: lock protecting softif_vlan_list */
  1308. spinlock_t softif_vlan_list_lock;
  1309. #ifdef CONFIG_BATMAN_ADV_BLA
  1310. /** @bla: bridge loope avoidance data */
  1311. struct batadv_priv_bla bla;
  1312. #endif
  1313. #ifdef CONFIG_BATMAN_ADV_DEBUG
  1314. /** @debug_log: holding debug logging relevant data */
  1315. struct batadv_priv_debug_log *debug_log;
  1316. #endif
  1317. /** @gw: gateway data */
  1318. struct batadv_priv_gw gw;
  1319. /** @tt: translation table data */
  1320. struct batadv_priv_tt tt;
  1321. /** @tvlv: type-version-length-value data */
  1322. struct batadv_priv_tvlv tvlv;
  1323. #ifdef CONFIG_BATMAN_ADV_DAT
  1324. /** @dat: distributed arp table data */
  1325. struct batadv_priv_dat dat;
  1326. #endif
  1327. #ifdef CONFIG_BATMAN_ADV_MCAST
  1328. /** @mcast: multicast data */
  1329. struct batadv_priv_mcast mcast;
  1330. #endif
  1331. #ifdef CONFIG_BATMAN_ADV_NC
  1332. /**
  1333. * @network_coding: bool indicating whether network coding is enabled
  1334. */
  1335. atomic_t network_coding;
  1336. /** @nc: network coding data */
  1337. struct batadv_priv_nc nc;
  1338. #endif /* CONFIG_BATMAN_ADV_NC */
  1339. #ifdef CONFIG_BATMAN_ADV_BATMAN_V
  1340. /** @bat_v: B.A.T.M.A.N. V per soft-interface private data */
  1341. struct batadv_priv_bat_v bat_v;
  1342. #endif
  1343. };
  1344. /**
  1345. * struct batadv_socket_client - layer2 icmp socket client data
  1346. */
  1347. struct batadv_socket_client {
  1348. /**
  1349. * @queue_list: packet queue for packets destined for this socket client
  1350. */
  1351. struct list_head queue_list;
  1352. /** @queue_len: number of packets in the packet queue (queue_list) */
  1353. unsigned int queue_len;
  1354. /** @index: socket client's index in the batadv_socket_client_hash */
  1355. unsigned char index;
  1356. /** @lock: lock protecting queue_list, queue_len & index */
  1357. spinlock_t lock;
  1358. /** @queue_wait: socket client's wait queue */
  1359. wait_queue_head_t queue_wait;
  1360. /** @bat_priv: pointer to soft_iface this client belongs to */
  1361. struct batadv_priv *bat_priv;
  1362. };
  1363. /**
  1364. * struct batadv_socket_packet - layer2 icmp packet for socket client
  1365. */
  1366. struct batadv_socket_packet {
  1367. /** @list: list node for &batadv_socket_client.queue_list */
  1368. struct list_head list;
  1369. /** @icmp_len: size of the layer2 icmp packet */
  1370. size_t icmp_len;
  1371. /** @icmp_packet: layer2 icmp packet */
  1372. u8 icmp_packet[BATADV_ICMP_MAX_PACKET_SIZE];
  1373. };
  1374. #ifdef CONFIG_BATMAN_ADV_BLA
  1375. /**
  1376. * struct batadv_bla_backbone_gw - batman-adv gateway bridged into the LAN
  1377. */
  1378. struct batadv_bla_backbone_gw {
  1379. /**
  1380. * @orig: originator address of backbone node (mac address of primary
  1381. * iface)
  1382. */
  1383. u8 orig[ETH_ALEN];
  1384. /** @vid: vlan id this gateway was detected on */
  1385. unsigned short vid;
  1386. /** @hash_entry: hlist node for &batadv_priv_bla.backbone_hash */
  1387. struct hlist_node hash_entry;
  1388. /** @bat_priv: pointer to soft_iface this backbone gateway belongs to */
  1389. struct batadv_priv *bat_priv;
  1390. /** @lasttime: last time we heard of this backbone gw */
  1391. unsigned long lasttime;
  1392. /**
  1393. * @wait_periods: grace time for bridge forward delays and bla group
  1394. * forming at bootup phase - no bcast traffic is formwared until it has
  1395. * elapsed
  1396. */
  1397. atomic_t wait_periods;
  1398. /**
  1399. * @request_sent: if this bool is set to true we are out of sync with
  1400. * this backbone gateway - no bcast traffic is formwared until the
  1401. * situation was resolved
  1402. */
  1403. atomic_t request_sent;
  1404. /** @crc: crc16 checksum over all claims */
  1405. u16 crc;
  1406. /** @crc_lock: lock protecting crc */
  1407. spinlock_t crc_lock;
  1408. /** @report_work: work struct for reporting detected loops */
  1409. struct work_struct report_work;
  1410. /** @refcount: number of contexts the object is used */
  1411. struct kref refcount;
  1412. /** @rcu: struct used for freeing in an RCU-safe manner */
  1413. struct rcu_head rcu;
  1414. };
  1415. /**
  1416. * struct batadv_bla_claim - claimed non-mesh client structure
  1417. */
  1418. struct batadv_bla_claim {
  1419. /** @addr: mac address of claimed non-mesh client */
  1420. u8 addr[ETH_ALEN];
  1421. /** @vid: vlan id this client was detected on */
  1422. unsigned short vid;
  1423. /** @backbone_gw: pointer to backbone gw claiming this client */
  1424. struct batadv_bla_backbone_gw *backbone_gw;
  1425. /** @backbone_lock: lock protecting backbone_gw pointer */
  1426. spinlock_t backbone_lock;
  1427. /** @lasttime: last time we heard of claim (locals only) */
  1428. unsigned long lasttime;
  1429. /** @hash_entry: hlist node for &batadv_priv_bla.claim_hash */
  1430. struct hlist_node hash_entry;
  1431. /** @refcount: number of contexts the object is used */
  1432. struct rcu_head rcu;
  1433. /** @rcu: struct used for freeing in an RCU-safe manner */
  1434. struct kref refcount;
  1435. };
  1436. #endif
  1437. /**
  1438. * struct batadv_tt_common_entry - tt local & tt global common data
  1439. */
  1440. struct batadv_tt_common_entry {
  1441. /** @addr: mac address of non-mesh client */
  1442. u8 addr[ETH_ALEN];
  1443. /** @vid: VLAN identifier */
  1444. unsigned short vid;
  1445. /**
  1446. * @hash_entry: hlist node for &batadv_priv_tt.local_hash or for
  1447. * &batadv_priv_tt.global_hash
  1448. */
  1449. struct hlist_node hash_entry;
  1450. /** @flags: various state handling flags (see batadv_tt_client_flags) */
  1451. u16 flags;
  1452. /** @added_at: timestamp used for purging stale tt common entries */
  1453. unsigned long added_at;
  1454. /** @refcount: number of contexts the object is used */
  1455. struct kref refcount;
  1456. /** @rcu: struct used for freeing in an RCU-safe manner */
  1457. struct rcu_head rcu;
  1458. };
  1459. /**
  1460. * struct batadv_tt_local_entry - translation table local entry data
  1461. */
  1462. struct batadv_tt_local_entry {
  1463. /** @common: general translation table data */
  1464. struct batadv_tt_common_entry common;
  1465. /** @last_seen: timestamp used for purging stale tt local entries */
  1466. unsigned long last_seen;
  1467. /** @vlan: soft-interface vlan of the entry */
  1468. struct batadv_softif_vlan *vlan;
  1469. };
  1470. /**
  1471. * struct batadv_tt_global_entry - translation table global entry data
  1472. */
  1473. struct batadv_tt_global_entry {
  1474. /** @common: general translation table data */
  1475. struct batadv_tt_common_entry common;
  1476. /** @orig_list: list of orig nodes announcing this non-mesh client */
  1477. struct hlist_head orig_list;
  1478. /** @orig_list_count: number of items in the orig_list */
  1479. atomic_t orig_list_count;
  1480. /** @list_lock: lock protecting orig_list */
  1481. spinlock_t list_lock;
  1482. /** @roam_at: time at which TT_GLOBAL_ROAM was set */
  1483. unsigned long roam_at;
  1484. };
  1485. /**
  1486. * struct batadv_tt_orig_list_entry - orig node announcing a non-mesh client
  1487. */
  1488. struct batadv_tt_orig_list_entry {
  1489. /** @orig_node: pointer to orig node announcing this non-mesh client */
  1490. struct batadv_orig_node *orig_node;
  1491. /**
  1492. * @ttvn: translation table version number which added the non-mesh
  1493. * client
  1494. */
  1495. u8 ttvn;
  1496. /** @flags: per orig entry TT sync flags */
  1497. u8 flags;
  1498. /** @list: list node for &batadv_tt_global_entry.orig_list */
  1499. struct hlist_node list;
  1500. /** @refcount: number of contexts the object is used */
  1501. struct kref refcount;
  1502. /** @rcu: struct used for freeing in an RCU-safe manner */
  1503. struct rcu_head rcu;
  1504. };
  1505. /**
  1506. * struct batadv_tt_change_node - structure for tt changes occurred
  1507. */
  1508. struct batadv_tt_change_node {
  1509. /** @list: list node for &batadv_priv_tt.changes_list */
  1510. struct list_head list;
  1511. /** @change: holds the actual translation table diff data */
  1512. struct batadv_tvlv_tt_change change;
  1513. };
  1514. /**
  1515. * struct batadv_tt_req_node - data to keep track of the tt requests in flight
  1516. */
  1517. struct batadv_tt_req_node {
  1518. /**
  1519. * @addr: mac address address of the originator this request was sent to
  1520. */
  1521. u8 addr[ETH_ALEN];
  1522. /** @issued_at: timestamp used for purging stale tt requests */
  1523. unsigned long issued_at;
  1524. /** @refcount: number of contexts the object is used by */
  1525. struct kref refcount;
  1526. /** @list: list node for &batadv_priv_tt.req_list */
  1527. struct hlist_node list;
  1528. };
  1529. /**
  1530. * struct batadv_tt_roam_node - roaming client data
  1531. */
  1532. struct batadv_tt_roam_node {
  1533. /** @addr: mac address of the client in the roaming phase */
  1534. u8 addr[ETH_ALEN];
  1535. /**
  1536. * @counter: number of allowed roaming events per client within a single
  1537. * OGM interval (changes are committed with each OGM)
  1538. */
  1539. atomic_t counter;
  1540. /**
  1541. * @first_time: timestamp used for purging stale roaming node entries
  1542. */
  1543. unsigned long first_time;
  1544. /** @list: list node for &batadv_priv_tt.roam_list */
  1545. struct list_head list;
  1546. };
  1547. /**
  1548. * struct batadv_nc_node - network coding node
  1549. */
  1550. struct batadv_nc_node {
  1551. /** @list: next and prev pointer for the list handling */
  1552. struct list_head list;
  1553. /** @addr: the node's mac address */
  1554. u8 addr[ETH_ALEN];
  1555. /** @refcount: number of contexts the object is used by */
  1556. struct kref refcount;
  1557. /** @rcu: struct used for freeing in an RCU-safe manner */
  1558. struct rcu_head rcu;
  1559. /** @orig_node: pointer to corresponding orig node struct */
  1560. struct batadv_orig_node *orig_node;
  1561. /** @last_seen: timestamp of last ogm received from this node */
  1562. unsigned long last_seen;
  1563. };
  1564. /**
  1565. * struct batadv_nc_path - network coding path
  1566. */
  1567. struct batadv_nc_path {
  1568. /** @hash_entry: next and prev pointer for the list handling */
  1569. struct hlist_node hash_entry;
  1570. /** @rcu: struct used for freeing in an RCU-safe manner */
  1571. struct rcu_head rcu;
  1572. /** @refcount: number of contexts the object is used by */
  1573. struct kref refcount;
  1574. /** @packet_list: list of buffered packets for this path */
  1575. struct list_head packet_list;
  1576. /** @packet_list_lock: access lock for packet list */
  1577. spinlock_t packet_list_lock;
  1578. /** @next_hop: next hop (destination) of path */
  1579. u8 next_hop[ETH_ALEN];
  1580. /** @prev_hop: previous hop (source) of path */
  1581. u8 prev_hop[ETH_ALEN];
  1582. /** @last_valid: timestamp for last validation of path */
  1583. unsigned long last_valid;
  1584. };
  1585. /**
  1586. * struct batadv_nc_packet - network coding packet used when coding and
  1587. * decoding packets
  1588. */
  1589. struct batadv_nc_packet {
  1590. /** @list: next and prev pointer for the list handling */
  1591. struct list_head list;
  1592. /** @packet_id: crc32 checksum of skb data */
  1593. __be32 packet_id;
  1594. /**
  1595. * @timestamp: field containing the info when the packet was added to
  1596. * path
  1597. */
  1598. unsigned long timestamp;
  1599. /** @neigh_node: pointer to original next hop neighbor of skb */
  1600. struct batadv_neigh_node *neigh_node;
  1601. /** @skb: skb which can be encoded or used for decoding */
  1602. struct sk_buff *skb;
  1603. /** @nc_path: pointer to path this nc packet is attached to */
  1604. struct batadv_nc_path *nc_path;
  1605. };
  1606. /**
  1607. * struct batadv_skb_cb - control buffer structure used to store private data
  1608. * relevant to batman-adv in the skb->cb buffer in skbs.
  1609. */
  1610. struct batadv_skb_cb {
  1611. /**
  1612. * @decoded: Marks a skb as decoded, which is checked when searching for
  1613. * coding opportunities in network-coding.c
  1614. */
  1615. unsigned char decoded:1;
  1616. /** @num_bcasts: Counter for broadcast packet retransmissions */
  1617. unsigned char num_bcasts;
  1618. };
  1619. /**
  1620. * struct batadv_forw_packet - structure for bcast packets to be sent/forwarded
  1621. */
  1622. struct batadv_forw_packet {
  1623. /**
  1624. * @list: list node for &batadv_priv.forw.bcast_list and
  1625. * &batadv_priv.forw.bat_list
  1626. */
  1627. struct hlist_node list;
  1628. /** @cleanup_list: list node for purging functions */
  1629. struct hlist_node cleanup_list;
  1630. /** @send_time: execution time for delayed_work (packet sending) */
  1631. unsigned long send_time;
  1632. /**
  1633. * @own: bool for locally generated packets (local OGMs are re-scheduled
  1634. * after sending)
  1635. */
  1636. u8 own;
  1637. /** @skb: bcast packet's skb buffer */
  1638. struct sk_buff *skb;
  1639. /** @packet_len: size of aggregated OGM packet inside the skb buffer */
  1640. u16 packet_len;
  1641. /** @direct_link_flags: direct link flags for aggregated OGM packets */
  1642. u32 direct_link_flags;
  1643. /** @num_packets: counter for aggregated OGMv1 packets */
  1644. u8 num_packets;
  1645. /** @delayed_work: work queue callback item for packet sending */
  1646. struct delayed_work delayed_work;
  1647. /**
  1648. * @if_incoming: pointer to incoming hard-iface or primary iface if
  1649. * locally generated packet
  1650. */
  1651. struct batadv_hard_iface *if_incoming;
  1652. /**
  1653. * @if_outgoing: packet where the packet should be sent to, or NULL if
  1654. * unspecified
  1655. */
  1656. struct batadv_hard_iface *if_outgoing;
  1657. /** @queue_left: The queue (counter) this packet was applied to */
  1658. atomic_t *queue_left;
  1659. };
  1660. /**
  1661. * struct batadv_algo_iface_ops - mesh algorithm callbacks (interface specific)
  1662. */
  1663. struct batadv_algo_iface_ops {
  1664. /**
  1665. * @activate: start routing mechanisms when hard-interface is brought up
  1666. * (optional)
  1667. */
  1668. void (*activate)(struct batadv_hard_iface *hard_iface);
  1669. /** @enable: init routing info when hard-interface is enabled */
  1670. int (*enable)(struct batadv_hard_iface *hard_iface);
  1671. /** @enabled: notification when hard-interface was enabled (optional) */
  1672. void (*enabled)(struct batadv_hard_iface *hard_iface);
  1673. /** @disable: de-init routing info when hard-interface is disabled */
  1674. void (*disable)(struct batadv_hard_iface *hard_iface);
  1675. /**
  1676. * @update_mac: (re-)init mac addresses of the protocol information
  1677. * belonging to this hard-interface
  1678. */
  1679. void (*update_mac)(struct batadv_hard_iface *hard_iface);
  1680. /** @primary_set: called when primary interface is selected / changed */
  1681. void (*primary_set)(struct batadv_hard_iface *hard_iface);
  1682. };
  1683. /**
  1684. * struct batadv_algo_neigh_ops - mesh algorithm callbacks (neighbour specific)
  1685. */
  1686. struct batadv_algo_neigh_ops {
  1687. /** @hardif_init: called on creation of single hop entry (optional) */
  1688. void (*hardif_init)(struct batadv_hardif_neigh_node *neigh);
  1689. /**
  1690. * @cmp: compare the metrics of two neighbors for their respective
  1691. * outgoing interfaces
  1692. */
  1693. int (*cmp)(struct batadv_neigh_node *neigh1,
  1694. struct batadv_hard_iface *if_outgoing1,
  1695. struct batadv_neigh_node *neigh2,
  1696. struct batadv_hard_iface *if_outgoing2);
  1697. /**
  1698. * @is_similar_or_better: check if neigh1 is equally similar or better
  1699. * than neigh2 for their respective outgoing interface from the metric
  1700. * prospective
  1701. */
  1702. bool (*is_similar_or_better)(struct batadv_neigh_node *neigh1,
  1703. struct batadv_hard_iface *if_outgoing1,
  1704. struct batadv_neigh_node *neigh2,
  1705. struct batadv_hard_iface *if_outgoing2);
  1706. #ifdef CONFIG_BATMAN_ADV_DEBUGFS
  1707. /** @print: print the single hop neighbor list (optional) */
  1708. void (*print)(struct batadv_priv *priv, struct seq_file *seq);
  1709. #endif
  1710. /** @dump: dump neighbors to a netlink socket (optional) */
  1711. void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
  1712. struct batadv_priv *priv,
  1713. struct batadv_hard_iface *hard_iface);
  1714. };
  1715. /**
  1716. * struct batadv_algo_orig_ops - mesh algorithm callbacks (originator specific)
  1717. */
  1718. struct batadv_algo_orig_ops {
  1719. /**
  1720. * @free: free the resources allocated by the routing algorithm for an
  1721. * orig_node object (optional)
  1722. */
  1723. void (*free)(struct batadv_orig_node *orig_node);
  1724. /**
  1725. * @add_if: ask the routing algorithm to apply the needed changes to the
  1726. * orig_node due to a new hard-interface being added into the mesh
  1727. * (optional)
  1728. */
  1729. int (*add_if)(struct batadv_orig_node *orig_node,
  1730. unsigned int max_if_num);
  1731. /**
  1732. * @del_if: ask the routing algorithm to apply the needed changes to the
  1733. * orig_node due to an hard-interface being removed from the mesh
  1734. * (optional)
  1735. */
  1736. int (*del_if)(struct batadv_orig_node *orig_node,
  1737. unsigned int max_if_num, unsigned int del_if_num);
  1738. #ifdef CONFIG_BATMAN_ADV_DEBUGFS
  1739. /** @print: print the originator table (optional) */
  1740. void (*print)(struct batadv_priv *priv, struct seq_file *seq,
  1741. struct batadv_hard_iface *hard_iface);
  1742. #endif
  1743. /** @dump: dump originators to a netlink socket (optional) */
  1744. void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
  1745. struct batadv_priv *priv,
  1746. struct batadv_hard_iface *hard_iface);
  1747. };
  1748. /**
  1749. * struct batadv_algo_gw_ops - mesh algorithm callbacks (GW specific)
  1750. */
  1751. struct batadv_algo_gw_ops {
  1752. /** @init_sel_class: initialize GW selection class (optional) */
  1753. void (*init_sel_class)(struct batadv_priv *bat_priv);
  1754. /**
  1755. * @store_sel_class: parse and stores a new GW selection class
  1756. * (optional)
  1757. */
  1758. ssize_t (*store_sel_class)(struct batadv_priv *bat_priv, char *buff,
  1759. size_t count);
  1760. /** @show_sel_class: prints the current GW selection class (optional) */
  1761. ssize_t (*show_sel_class)(struct batadv_priv *bat_priv, char *buff);
  1762. /**
  1763. * @get_best_gw_node: select the best GW from the list of available
  1764. * nodes (optional)
  1765. */
  1766. struct batadv_gw_node *(*get_best_gw_node)
  1767. (struct batadv_priv *bat_priv);
  1768. /**
  1769. * @is_eligible: check if a newly discovered GW is a potential candidate
  1770. * for the election as best GW (optional)
  1771. */
  1772. bool (*is_eligible)(struct batadv_priv *bat_priv,
  1773. struct batadv_orig_node *curr_gw_orig,
  1774. struct batadv_orig_node *orig_node);
  1775. #ifdef CONFIG_BATMAN_ADV_DEBUGFS
  1776. /** @print: print the gateway table (optional) */
  1777. void (*print)(struct batadv_priv *bat_priv, struct seq_file *seq);
  1778. #endif
  1779. /** @dump: dump gateways to a netlink socket (optional) */
  1780. void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
  1781. struct batadv_priv *priv);
  1782. };
  1783. /**
  1784. * struct batadv_algo_ops - mesh algorithm callbacks
  1785. */
  1786. struct batadv_algo_ops {
  1787. /** @list: list node for the batadv_algo_list */
  1788. struct hlist_node list;
  1789. /** @name: name of the algorithm */
  1790. char *name;
  1791. /** @iface: callbacks related to interface handling */
  1792. struct batadv_algo_iface_ops iface;
  1793. /** @neigh: callbacks related to neighbors handling */
  1794. struct batadv_algo_neigh_ops neigh;
  1795. /** @orig: callbacks related to originators handling */
  1796. struct batadv_algo_orig_ops orig;
  1797. /** @gw: callbacks related to GW mode */
  1798. struct batadv_algo_gw_ops gw;
  1799. };
  1800. /**
  1801. * struct batadv_dat_entry - it is a single entry of batman-adv ARP backend. It
  1802. * is used to stored ARP entries needed for the global DAT cache
  1803. */
  1804. struct batadv_dat_entry {
  1805. /** @ip: the IPv4 corresponding to this DAT/ARP entry */
  1806. __be32 ip;
  1807. /** @mac_addr: the MAC address associated to the stored IPv4 */
  1808. u8 mac_addr[ETH_ALEN];
  1809. /** @vid: the vlan ID associated to this entry */
  1810. unsigned short vid;
  1811. /**
  1812. * @last_update: time in jiffies when this entry was refreshed last time
  1813. */
  1814. unsigned long last_update;
  1815. /** @hash_entry: hlist node for &batadv_priv_dat.hash */
  1816. struct hlist_node hash_entry;
  1817. /** @refcount: number of contexts the object is used */
  1818. struct kref refcount;
  1819. /** @rcu: struct used for freeing in an RCU-safe manner */
  1820. struct rcu_head rcu;
  1821. };
  1822. /**
  1823. * struct batadv_hw_addr - a list entry for a MAC address
  1824. */
  1825. struct batadv_hw_addr {
  1826. /** @list: list node for the linking of entries */
  1827. struct hlist_node list;
  1828. /** @addr: the MAC address of this list entry */
  1829. unsigned char addr[ETH_ALEN];
  1830. };
  1831. /**
  1832. * struct batadv_dat_candidate - candidate destination for DAT operations
  1833. */
  1834. struct batadv_dat_candidate {
  1835. /**
  1836. * @type: the type of the selected candidate. It can one of the
  1837. * following:
  1838. * - BATADV_DAT_CANDIDATE_NOT_FOUND
  1839. * - BATADV_DAT_CANDIDATE_ORIG
  1840. */
  1841. int type;
  1842. /**
  1843. * @orig_node: if type is BATADV_DAT_CANDIDATE_ORIG this field points to
  1844. * the corresponding originator node structure
  1845. */
  1846. struct batadv_orig_node *orig_node;
  1847. };
  1848. /**
  1849. * struct batadv_tvlv_container - container for tvlv appended to OGMs
  1850. */
  1851. struct batadv_tvlv_container {
  1852. /** @list: hlist node for &batadv_priv_tvlv.container_list */
  1853. struct hlist_node list;
  1854. /** @tvlv_hdr: tvlv header information needed to construct the tvlv */
  1855. struct batadv_tvlv_hdr tvlv_hdr;
  1856. /** @refcount: number of contexts the object is used */
  1857. struct kref refcount;
  1858. };
  1859. /**
  1860. * struct batadv_tvlv_handler - handler for specific tvlv type and version
  1861. */
  1862. struct batadv_tvlv_handler {
  1863. /** @list: hlist node for &batadv_priv_tvlv.handler_list */
  1864. struct hlist_node list;
  1865. /**
  1866. * @ogm_handler: handler callback which is given the tvlv payload to
  1867. * process on incoming OGM packets
  1868. */
  1869. void (*ogm_handler)(struct batadv_priv *bat_priv,
  1870. struct batadv_orig_node *orig,
  1871. u8 flags, void *tvlv_value, u16 tvlv_value_len);
  1872. /**
  1873. * @unicast_handler: handler callback which is given the tvlv payload to
  1874. * process on incoming unicast tvlv packets
  1875. */
  1876. int (*unicast_handler)(struct batadv_priv *bat_priv,
  1877. u8 *src, u8 *dst,
  1878. void *tvlv_value, u16 tvlv_value_len);
  1879. /** @type: tvlv type this handler feels responsible for */
  1880. u8 type;
  1881. /** @version: tvlv version this handler feels responsible for */
  1882. u8 version;
  1883. /** @flags: tvlv handler flags */
  1884. u8 flags;
  1885. /** @refcount: number of contexts the object is used */
  1886. struct kref refcount;
  1887. /** @rcu: struct used for freeing in an RCU-safe manner */
  1888. struct rcu_head rcu;
  1889. };
  1890. /**
  1891. * enum batadv_tvlv_handler_flags - tvlv handler flags definitions
  1892. */
  1893. enum batadv_tvlv_handler_flags {
  1894. /**
  1895. * @BATADV_TVLV_HANDLER_OGM_CIFNOTFND: tvlv ogm processing function
  1896. * will call this handler even if its type was not found (with no data)
  1897. */
  1898. BATADV_TVLV_HANDLER_OGM_CIFNOTFND = BIT(1),
  1899. /**
  1900. * @BATADV_TVLV_HANDLER_OGM_CALLED: interval tvlv handling flag - the
  1901. * API marks a handler as being called, so it won't be called if the
  1902. * BATADV_TVLV_HANDLER_OGM_CIFNOTFND flag was set
  1903. */
  1904. BATADV_TVLV_HANDLER_OGM_CALLED = BIT(2),
  1905. };
  1906. /**
  1907. * struct batadv_store_mesh_work - Work queue item to detach add/del interface
  1908. * from sysfs locks
  1909. */
  1910. struct batadv_store_mesh_work {
  1911. /**
  1912. * @net_dev: netdevice to add/remove to/from batman-adv soft-interface
  1913. */
  1914. struct net_device *net_dev;
  1915. /** @soft_iface_name: name of soft-interface to modify */
  1916. char soft_iface_name[IFNAMSIZ];
  1917. /** @work: work queue item */
  1918. struct work_struct work;
  1919. };
  1920. #endif /* _NET_BATMAN_ADV_TYPES_H_ */