types.h 58 KB

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