types.h 15 KB

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