types.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. /* Copyright (C) 2007-2012 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, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA
  18. */
  19. #ifndef _NET_BATMAN_ADV_TYPES_H_
  20. #define _NET_BATMAN_ADV_TYPES_H_
  21. #include "packet.h"
  22. #include "bitarray.h"
  23. #include <linux/kernel.h>
  24. #define BATADV_HEADER_LEN \
  25. (ETH_HLEN + max(sizeof(struct batadv_unicast_packet), \
  26. sizeof(struct batadv_bcast_packet)))
  27. #ifdef CONFIG_BATMAN_ADV_DAT
  28. /* batadv_dat_addr_t is the type used for all DHT addresses. If it is changed,
  29. * BATADV_DAT_ADDR_MAX is changed as well.
  30. *
  31. * *Please be careful: batadv_dat_addr_t must be UNSIGNED*
  32. */
  33. #define batadv_dat_addr_t uint16_t
  34. #endif /* CONFIG_BATMAN_ADV_DAT */
  35. /**
  36. * struct batadv_hard_iface_bat_iv - per hard interface B.A.T.M.A.N. IV data
  37. * @ogm_buff: buffer holding the OGM packet
  38. * @ogm_buff_len: length of the OGM packet buffer
  39. * @ogm_seqno: OGM sequence number - used to identify each OGM
  40. */
  41. struct batadv_hard_iface_bat_iv {
  42. unsigned char *ogm_buff;
  43. int ogm_buff_len;
  44. atomic_t ogm_seqno;
  45. };
  46. struct batadv_hard_iface {
  47. struct list_head list;
  48. int16_t if_num;
  49. char if_status;
  50. struct net_device *net_dev;
  51. atomic_t frag_seqno;
  52. struct kobject *hardif_obj;
  53. atomic_t refcount;
  54. struct packet_type batman_adv_ptype;
  55. struct net_device *soft_iface;
  56. struct rcu_head rcu;
  57. struct batadv_hard_iface_bat_iv bat_iv;
  58. };
  59. /**
  60. * struct batadv_orig_node - structure for orig_list maintaining nodes of mesh
  61. * @primary_addr: hosts primary interface address
  62. * @last_seen: when last packet from this node was received
  63. * @bcast_seqno_reset: time when the broadcast seqno window was reset
  64. * @batman_seqno_reset: time when the batman seqno window was reset
  65. * @gw_flags: flags related to gateway class
  66. * @flags: for now only VIS_SERVER flag
  67. * @last_real_seqno: last and best known sequence number
  68. * @last_ttl: ttl of last received packet
  69. * @last_bcast_seqno: last broadcast sequence number received by this host
  70. *
  71. * @candidates: how many candidates are available
  72. * @selected: next bonding candidate
  73. */
  74. struct batadv_orig_node {
  75. uint8_t orig[ETH_ALEN];
  76. uint8_t primary_addr[ETH_ALEN];
  77. struct batadv_neigh_node __rcu *router; /* rcu protected pointer */
  78. #ifdef CONFIG_BATMAN_ADV_DAT
  79. batadv_dat_addr_t dat_addr;
  80. #endif
  81. unsigned long *bcast_own;
  82. uint8_t *bcast_own_sum;
  83. unsigned long last_seen;
  84. unsigned long bcast_seqno_reset;
  85. unsigned long batman_seqno_reset;
  86. uint8_t gw_flags;
  87. uint8_t flags;
  88. atomic_t last_ttvn; /* last seen translation table version number */
  89. uint16_t tt_crc;
  90. unsigned char *tt_buff;
  91. int16_t tt_buff_len;
  92. spinlock_t tt_buff_lock; /* protects tt_buff */
  93. atomic_t tt_size;
  94. bool tt_initialised;
  95. uint32_t last_real_seqno;
  96. uint8_t last_ttl;
  97. DECLARE_BITMAP(bcast_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
  98. uint32_t last_bcast_seqno;
  99. struct hlist_head neigh_list;
  100. struct list_head frag_list;
  101. spinlock_t neigh_list_lock; /* protects neigh_list and router */
  102. atomic_t refcount;
  103. struct rcu_head rcu;
  104. struct hlist_node hash_entry;
  105. struct batadv_priv *bat_priv;
  106. unsigned long last_frag_packet;
  107. /* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
  108. * neigh_node->real_bits, neigh_node->real_packet_count
  109. */
  110. spinlock_t ogm_cnt_lock;
  111. /* bcast_seqno_lock protects bcast_bits, last_bcast_seqno */
  112. spinlock_t bcast_seqno_lock;
  113. spinlock_t tt_list_lock; /* protects tt_list */
  114. atomic_t bond_candidates;
  115. struct list_head bond_list;
  116. };
  117. struct batadv_gw_node {
  118. struct hlist_node list;
  119. struct batadv_orig_node *orig_node;
  120. unsigned long deleted;
  121. atomic_t refcount;
  122. struct rcu_head rcu;
  123. };
  124. /* batadv_neigh_node
  125. * @last_seen: when last packet via this neighbor was received
  126. */
  127. struct batadv_neigh_node {
  128. struct hlist_node list;
  129. uint8_t addr[ETH_ALEN];
  130. uint8_t real_packet_count;
  131. uint8_t tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE];
  132. uint8_t tq_index;
  133. uint8_t tq_avg;
  134. uint8_t last_ttl;
  135. struct list_head bonding_list;
  136. unsigned long last_seen;
  137. DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
  138. atomic_t refcount;
  139. struct rcu_head rcu;
  140. struct batadv_orig_node *orig_node;
  141. struct batadv_hard_iface *if_incoming;
  142. spinlock_t lq_update_lock; /* protects: tq_recv, tq_index */
  143. };
  144. #ifdef CONFIG_BATMAN_ADV_BLA
  145. struct batadv_bcast_duplist_entry {
  146. uint8_t orig[ETH_ALEN];
  147. __be32 crc;
  148. unsigned long entrytime;
  149. };
  150. #endif
  151. enum batadv_counters {
  152. BATADV_CNT_TX,
  153. BATADV_CNT_TX_BYTES,
  154. BATADV_CNT_TX_DROPPED,
  155. BATADV_CNT_RX,
  156. BATADV_CNT_RX_BYTES,
  157. BATADV_CNT_FORWARD,
  158. BATADV_CNT_FORWARD_BYTES,
  159. BATADV_CNT_MGMT_TX,
  160. BATADV_CNT_MGMT_TX_BYTES,
  161. BATADV_CNT_MGMT_RX,
  162. BATADV_CNT_MGMT_RX_BYTES,
  163. BATADV_CNT_TT_REQUEST_TX,
  164. BATADV_CNT_TT_REQUEST_RX,
  165. BATADV_CNT_TT_RESPONSE_TX,
  166. BATADV_CNT_TT_RESPONSE_RX,
  167. BATADV_CNT_TT_ROAM_ADV_TX,
  168. BATADV_CNT_TT_ROAM_ADV_RX,
  169. #ifdef CONFIG_BATMAN_ADV_DAT
  170. BATADV_CNT_DAT_GET_TX,
  171. BATADV_CNT_DAT_GET_RX,
  172. BATADV_CNT_DAT_PUT_TX,
  173. BATADV_CNT_DAT_PUT_RX,
  174. BATADV_CNT_DAT_CACHED_REPLY_TX,
  175. #endif
  176. BATADV_CNT_NUM,
  177. };
  178. /**
  179. * struct batadv_priv_tt - per mesh interface translation table data
  180. * @vn: translation table version number
  181. * @local_changes: changes registered in an originator interval
  182. * @poss_change: Detect an ongoing roaming phase. If true, then this node
  183. * received a roaming_adv and has to inspect every packet directed to it to
  184. * check whether it still is the true destination or not. This flag will be
  185. * reset to false as soon as the this node's ttvn is increased
  186. * @changes_list: tracks tt local changes within an originator interval
  187. * @req_list: list of pending tt_requests
  188. * @local_crc: Checksum of the local table, recomputed before sending a new OGM
  189. */
  190. struct batadv_priv_tt {
  191. atomic_t vn;
  192. atomic_t ogm_append_cnt;
  193. atomic_t local_changes;
  194. struct list_head changes_list;
  195. struct batadv_hashtable *local_hash;
  196. struct batadv_hashtable *global_hash;
  197. struct list_head req_list;
  198. struct list_head roam_list;
  199. spinlock_t changes_list_lock; /* protects changes */
  200. spinlock_t req_list_lock; /* protects req_list */
  201. spinlock_t roam_list_lock; /* protects roam_list */
  202. atomic_t local_entry_num;
  203. uint16_t local_crc;
  204. unsigned char *last_changeset;
  205. int16_t last_changeset_len;
  206. spinlock_t last_changeset_lock; /* protects last_changeset */
  207. struct delayed_work work;
  208. };
  209. #ifdef CONFIG_BATMAN_ADV_BLA
  210. struct batadv_priv_bla {
  211. atomic_t num_requests; /* number of bla requests in flight */
  212. struct batadv_hashtable *claim_hash;
  213. struct batadv_hashtable *backbone_hash;
  214. struct batadv_bcast_duplist_entry bcast_duplist[BATADV_DUPLIST_SIZE];
  215. int bcast_duplist_curr;
  216. /* protects bcast_duplist and bcast_duplist_curr */
  217. spinlock_t bcast_duplist_lock;
  218. struct batadv_bla_claim_dst claim_dest;
  219. struct delayed_work work;
  220. };
  221. #endif
  222. struct batadv_priv_gw {
  223. struct hlist_head list;
  224. spinlock_t list_lock; /* protects gw_list and curr_gw */
  225. struct batadv_gw_node __rcu *curr_gw; /* rcu protected pointer */
  226. atomic_t reselect;
  227. };
  228. struct batadv_priv_vis {
  229. struct list_head send_list;
  230. struct batadv_hashtable *hash;
  231. spinlock_t hash_lock; /* protects hash */
  232. spinlock_t list_lock; /* protects info::recv_list */
  233. struct delayed_work work;
  234. struct batadv_vis_info *my_info;
  235. };
  236. /**
  237. * struct batadv_priv_dat - per mesh interface DAT private data
  238. * @addr: node DAT address
  239. * @hash: hashtable representing the local ARP cache
  240. * @work: work queue callback item for cache purging
  241. */
  242. #ifdef CONFIG_BATMAN_ADV_DAT
  243. struct batadv_priv_dat {
  244. batadv_dat_addr_t addr;
  245. struct batadv_hashtable *hash;
  246. struct delayed_work work;
  247. };
  248. #endif
  249. struct batadv_priv {
  250. atomic_t mesh_state;
  251. struct net_device_stats stats;
  252. uint64_t __percpu *bat_counters; /* Per cpu counters */
  253. atomic_t aggregated_ogms; /* boolean */
  254. atomic_t bonding; /* boolean */
  255. atomic_t fragmentation; /* boolean */
  256. atomic_t ap_isolation; /* boolean */
  257. atomic_t bridge_loop_avoidance; /* boolean */
  258. #ifdef CONFIG_BATMAN_ADV_DAT
  259. atomic_t distributed_arp_table; /* boolean */
  260. #endif
  261. atomic_t vis_mode; /* VIS_TYPE_* */
  262. atomic_t gw_mode; /* GW_MODE_* */
  263. atomic_t gw_sel_class; /* uint */
  264. atomic_t gw_bandwidth; /* gw bandwidth */
  265. atomic_t orig_interval; /* uint */
  266. atomic_t hop_penalty; /* uint */
  267. atomic_t log_level; /* uint */
  268. atomic_t bcast_seqno;
  269. atomic_t bcast_queue_left;
  270. atomic_t batman_queue_left;
  271. char num_ifaces;
  272. struct batadv_debug_log *debug_log;
  273. struct kobject *mesh_obj;
  274. struct dentry *debug_dir;
  275. struct hlist_head forw_bat_list;
  276. struct hlist_head forw_bcast_list;
  277. struct batadv_hashtable *orig_hash;
  278. spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
  279. spinlock_t forw_bcast_list_lock; /* protects forw_bcast_list */
  280. struct delayed_work orig_work;
  281. struct batadv_hard_iface __rcu *primary_if; /* rcu protected pointer */
  282. struct batadv_algo_ops *bat_algo_ops;
  283. #ifdef CONFIG_BATMAN_ADV_BLA
  284. struct batadv_priv_bla bla;
  285. #endif
  286. struct batadv_priv_gw gw;
  287. struct batadv_priv_tt tt;
  288. struct batadv_priv_vis vis;
  289. #ifdef CONFIG_BATMAN_ADV_DAT
  290. struct batadv_priv_dat dat;
  291. #endif
  292. };
  293. struct batadv_socket_client {
  294. struct list_head queue_list;
  295. unsigned int queue_len;
  296. unsigned char index;
  297. spinlock_t lock; /* protects queue_list, queue_len, index */
  298. wait_queue_head_t queue_wait;
  299. struct batadv_priv *bat_priv;
  300. };
  301. struct batadv_socket_packet {
  302. struct list_head list;
  303. size_t icmp_len;
  304. struct batadv_icmp_packet_rr icmp_packet;
  305. };
  306. struct batadv_tt_common_entry {
  307. uint8_t addr[ETH_ALEN];
  308. struct hlist_node hash_entry;
  309. uint16_t flags;
  310. unsigned long added_at;
  311. atomic_t refcount;
  312. struct rcu_head rcu;
  313. };
  314. struct batadv_tt_local_entry {
  315. struct batadv_tt_common_entry common;
  316. unsigned long last_seen;
  317. };
  318. struct batadv_tt_global_entry {
  319. struct batadv_tt_common_entry common;
  320. struct hlist_head orig_list;
  321. spinlock_t list_lock; /* protects the list */
  322. unsigned long roam_at; /* time at which TT_GLOBAL_ROAM was set */
  323. };
  324. struct batadv_tt_orig_list_entry {
  325. struct batadv_orig_node *orig_node;
  326. uint8_t ttvn;
  327. atomic_t refcount;
  328. struct rcu_head rcu;
  329. struct hlist_node list;
  330. };
  331. #ifdef CONFIG_BATMAN_ADV_BLA
  332. struct batadv_backbone_gw {
  333. uint8_t orig[ETH_ALEN];
  334. short vid; /* used VLAN ID */
  335. struct hlist_node hash_entry;
  336. struct batadv_priv *bat_priv;
  337. unsigned long lasttime; /* last time we heard of this backbone gw */
  338. atomic_t wait_periods;
  339. atomic_t request_sent;
  340. atomic_t refcount;
  341. struct rcu_head rcu;
  342. uint16_t crc; /* crc checksum over all claims */
  343. };
  344. struct batadv_claim {
  345. uint8_t addr[ETH_ALEN];
  346. short vid;
  347. struct batadv_backbone_gw *backbone_gw;
  348. unsigned long lasttime; /* last time we heard of claim (locals only) */
  349. struct rcu_head rcu;
  350. atomic_t refcount;
  351. struct hlist_node hash_entry;
  352. };
  353. #endif
  354. struct batadv_tt_change_node {
  355. struct list_head list;
  356. struct batadv_tt_change change;
  357. };
  358. struct batadv_tt_req_node {
  359. uint8_t addr[ETH_ALEN];
  360. unsigned long issued_at;
  361. struct list_head list;
  362. };
  363. struct batadv_tt_roam_node {
  364. uint8_t addr[ETH_ALEN];
  365. atomic_t counter;
  366. unsigned long first_time;
  367. struct list_head list;
  368. };
  369. /* forw_packet - structure for forw_list maintaining packets to be
  370. * send/forwarded
  371. */
  372. struct batadv_forw_packet {
  373. struct hlist_node list;
  374. unsigned long send_time;
  375. uint8_t own;
  376. struct sk_buff *skb;
  377. uint16_t packet_len;
  378. uint32_t direct_link_flags;
  379. uint8_t num_packets;
  380. struct delayed_work delayed_work;
  381. struct batadv_hard_iface *if_incoming;
  382. };
  383. /* While scanning for vis-entries of a particular vis-originator
  384. * this list collects its interfaces to create a subgraph/cluster
  385. * out of them later
  386. */
  387. struct batadv_if_list_entry {
  388. uint8_t addr[ETH_ALEN];
  389. bool primary;
  390. struct hlist_node list;
  391. };
  392. struct batadv_debug_log {
  393. char log_buff[BATADV_LOG_BUF_LEN];
  394. unsigned long log_start;
  395. unsigned long log_end;
  396. spinlock_t lock; /* protects log_buff, log_start and log_end */
  397. wait_queue_head_t queue_wait;
  398. };
  399. struct batadv_frag_packet_list_entry {
  400. struct list_head list;
  401. uint16_t seqno;
  402. struct sk_buff *skb;
  403. };
  404. struct batadv_vis_info {
  405. unsigned long first_seen;
  406. /* list of server-neighbors we received a vis-packet
  407. * from. we should not reply to them.
  408. */
  409. struct list_head recv_list;
  410. struct list_head send_list;
  411. struct kref refcount;
  412. struct hlist_node hash_entry;
  413. struct batadv_priv *bat_priv;
  414. /* this packet might be part of the vis send queue. */
  415. struct sk_buff *skb_packet;
  416. /* vis_info may follow here */
  417. } __packed;
  418. struct batadv_vis_info_entry {
  419. uint8_t src[ETH_ALEN];
  420. uint8_t dest[ETH_ALEN];
  421. uint8_t quality; /* quality = 0 client */
  422. } __packed;
  423. struct batadv_recvlist_node {
  424. struct list_head list;
  425. uint8_t mac[ETH_ALEN];
  426. };
  427. struct batadv_algo_ops {
  428. struct hlist_node list;
  429. char *name;
  430. /* init routing info when hard-interface is enabled */
  431. int (*bat_iface_enable)(struct batadv_hard_iface *hard_iface);
  432. /* de-init routing info when hard-interface is disabled */
  433. void (*bat_iface_disable)(struct batadv_hard_iface *hard_iface);
  434. /* (re-)init mac addresses of the protocol information
  435. * belonging to this hard-interface
  436. */
  437. void (*bat_iface_update_mac)(struct batadv_hard_iface *hard_iface);
  438. /* called when primary interface is selected / changed */
  439. void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);
  440. /* prepare a new outgoing OGM for the send queue */
  441. void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);
  442. /* send scheduled OGM */
  443. void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
  444. };
  445. /**
  446. * struct batadv_dat_entry - it is a single entry of batman-adv ARP backend. It
  447. * is used to stored ARP entries needed for the global DAT cache
  448. * @ip: the IPv4 corresponding to this DAT/ARP entry
  449. * @mac_addr: the MAC address associated to the stored IPv4
  450. * @last_update: time in jiffies when this entry was refreshed last time
  451. * @hash_entry: hlist node for batadv_priv_dat::hash
  452. * @refcount: number of contexts the object is used
  453. * @rcu: struct used for freeing in an RCU-safe manner
  454. */
  455. struct batadv_dat_entry {
  456. __be32 ip;
  457. uint8_t mac_addr[ETH_ALEN];
  458. unsigned long last_update;
  459. struct hlist_node hash_entry;
  460. atomic_t refcount;
  461. struct rcu_head rcu;
  462. };
  463. /**
  464. * struct batadv_dat_candidate - candidate destination for DAT operations
  465. * @type: the type of the selected candidate. It can one of the following:
  466. * - BATADV_DAT_CANDIDATE_NOT_FOUND
  467. * - BATADV_DAT_CANDIDATE_ORIG
  468. * @orig_node: if type is BATADV_DAT_CANDIDATE_ORIG this field points to the
  469. * corresponding originator node structure
  470. */
  471. struct batadv_dat_candidate {
  472. int type;
  473. struct batadv_orig_node *orig_node;
  474. };
  475. #endif /* _NET_BATMAN_ADV_TYPES_H_ */