types.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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. struct batadv_priv_gw {
  221. struct hlist_head list;
  222. spinlock_t list_lock; /* protects gw_list and curr_gw */
  223. struct batadv_gw_node __rcu *curr_gw; /* rcu protected pointer */
  224. atomic_t reselect;
  225. };
  226. struct batadv_priv_vis {
  227. struct list_head send_list;
  228. struct batadv_hashtable *hash;
  229. spinlock_t hash_lock; /* protects hash */
  230. spinlock_t list_lock; /* protects info::recv_list */
  231. struct delayed_work work;
  232. struct batadv_vis_info *my_info;
  233. };
  234. /**
  235. * struct batadv_priv_dat - per mesh interface DAT private data
  236. * @addr: node DAT address
  237. * @hash: hashtable representing the local ARP cache
  238. * @work: work queue callback item for cache purging
  239. */
  240. #ifdef CONFIG_BATMAN_ADV_DAT
  241. struct batadv_priv_dat {
  242. batadv_dat_addr_t addr;
  243. struct batadv_hashtable *hash;
  244. struct delayed_work work;
  245. };
  246. #endif
  247. struct batadv_priv {
  248. atomic_t mesh_state;
  249. struct net_device_stats stats;
  250. uint64_t __percpu *bat_counters; /* Per cpu counters */
  251. atomic_t aggregated_ogms; /* boolean */
  252. atomic_t bonding; /* boolean */
  253. atomic_t fragmentation; /* boolean */
  254. atomic_t ap_isolation; /* boolean */
  255. #ifdef CONFIG_BATMAN_ADV_BLA
  256. atomic_t bridge_loop_avoidance; /* boolean */
  257. #endif
  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. #ifdef CONFIG_BATMAN_ADV_DEBUG
  268. atomic_t log_level; /* uint */
  269. #endif
  270. atomic_t bcast_seqno;
  271. atomic_t bcast_queue_left;
  272. atomic_t batman_queue_left;
  273. char num_ifaces;
  274. #ifdef CONFIG_BATMAN_ADV_DEBUG
  275. struct batadv_debug_log *debug_log;
  276. #endif
  277. struct kobject *mesh_obj;
  278. struct dentry *debug_dir;
  279. struct hlist_head forw_bat_list;
  280. struct hlist_head forw_bcast_list;
  281. struct batadv_hashtable *orig_hash;
  282. spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
  283. spinlock_t forw_bcast_list_lock; /* protects forw_bcast_list */
  284. struct delayed_work orig_work;
  285. struct batadv_hard_iface __rcu *primary_if; /* rcu protected pointer */
  286. struct batadv_algo_ops *bat_algo_ops;
  287. #ifdef CONFIG_BATMAN_ADV_BLA
  288. struct batadv_priv_bla bla;
  289. #endif
  290. struct batadv_priv_gw gw;
  291. struct batadv_priv_tt tt;
  292. struct batadv_priv_vis vis;
  293. #ifdef CONFIG_BATMAN_ADV_DAT
  294. struct batadv_priv_dat dat;
  295. #endif
  296. };
  297. struct batadv_socket_client {
  298. struct list_head queue_list;
  299. unsigned int queue_len;
  300. unsigned char index;
  301. spinlock_t lock; /* protects queue_list, queue_len, index */
  302. wait_queue_head_t queue_wait;
  303. struct batadv_priv *bat_priv;
  304. };
  305. struct batadv_socket_packet {
  306. struct list_head list;
  307. size_t icmp_len;
  308. struct batadv_icmp_packet_rr icmp_packet;
  309. };
  310. struct batadv_tt_common_entry {
  311. uint8_t addr[ETH_ALEN];
  312. struct hlist_node hash_entry;
  313. uint16_t flags;
  314. unsigned long added_at;
  315. atomic_t refcount;
  316. struct rcu_head rcu;
  317. };
  318. struct batadv_tt_local_entry {
  319. struct batadv_tt_common_entry common;
  320. unsigned long last_seen;
  321. };
  322. struct batadv_tt_global_entry {
  323. struct batadv_tt_common_entry common;
  324. struct hlist_head orig_list;
  325. spinlock_t list_lock; /* protects the list */
  326. unsigned long roam_at; /* time at which TT_GLOBAL_ROAM was set */
  327. };
  328. struct batadv_tt_orig_list_entry {
  329. struct batadv_orig_node *orig_node;
  330. uint8_t ttvn;
  331. atomic_t refcount;
  332. struct rcu_head rcu;
  333. struct hlist_node list;
  334. };
  335. #ifdef CONFIG_BATMAN_ADV_BLA
  336. struct batadv_backbone_gw {
  337. uint8_t orig[ETH_ALEN];
  338. short vid; /* used VLAN ID */
  339. struct hlist_node hash_entry;
  340. struct batadv_priv *bat_priv;
  341. unsigned long lasttime; /* last time we heard of this backbone gw */
  342. atomic_t wait_periods;
  343. atomic_t request_sent;
  344. atomic_t refcount;
  345. struct rcu_head rcu;
  346. uint16_t crc; /* crc checksum over all claims */
  347. };
  348. struct batadv_claim {
  349. uint8_t addr[ETH_ALEN];
  350. short vid;
  351. struct batadv_backbone_gw *backbone_gw;
  352. unsigned long lasttime; /* last time we heard of claim (locals only) */
  353. struct rcu_head rcu;
  354. atomic_t refcount;
  355. struct hlist_node hash_entry;
  356. };
  357. #endif
  358. struct batadv_tt_change_node {
  359. struct list_head list;
  360. struct batadv_tt_change change;
  361. };
  362. struct batadv_tt_req_node {
  363. uint8_t addr[ETH_ALEN];
  364. unsigned long issued_at;
  365. struct list_head list;
  366. };
  367. struct batadv_tt_roam_node {
  368. uint8_t addr[ETH_ALEN];
  369. atomic_t counter;
  370. unsigned long first_time;
  371. struct list_head list;
  372. };
  373. /* forw_packet - structure for forw_list maintaining packets to be
  374. * send/forwarded
  375. */
  376. struct batadv_forw_packet {
  377. struct hlist_node list;
  378. unsigned long send_time;
  379. uint8_t own;
  380. struct sk_buff *skb;
  381. uint16_t packet_len;
  382. uint32_t direct_link_flags;
  383. uint8_t num_packets;
  384. struct delayed_work delayed_work;
  385. struct batadv_hard_iface *if_incoming;
  386. };
  387. /* While scanning for vis-entries of a particular vis-originator
  388. * this list collects its interfaces to create a subgraph/cluster
  389. * out of them later
  390. */
  391. struct batadv_if_list_entry {
  392. uint8_t addr[ETH_ALEN];
  393. bool primary;
  394. struct hlist_node list;
  395. };
  396. struct batadv_debug_log {
  397. char log_buff[BATADV_LOG_BUF_LEN];
  398. unsigned long log_start;
  399. unsigned long log_end;
  400. spinlock_t lock; /* protects log_buff, log_start and log_end */
  401. wait_queue_head_t queue_wait;
  402. };
  403. struct batadv_frag_packet_list_entry {
  404. struct list_head list;
  405. uint16_t seqno;
  406. struct sk_buff *skb;
  407. };
  408. struct batadv_vis_info {
  409. unsigned long first_seen;
  410. /* list of server-neighbors we received a vis-packet
  411. * from. we should not reply to them.
  412. */
  413. struct list_head recv_list;
  414. struct list_head send_list;
  415. struct kref refcount;
  416. struct hlist_node hash_entry;
  417. struct batadv_priv *bat_priv;
  418. /* this packet might be part of the vis send queue. */
  419. struct sk_buff *skb_packet;
  420. /* vis_info may follow here */
  421. } __packed;
  422. struct batadv_vis_info_entry {
  423. uint8_t src[ETH_ALEN];
  424. uint8_t dest[ETH_ALEN];
  425. uint8_t quality; /* quality = 0 client */
  426. } __packed;
  427. struct batadv_recvlist_node {
  428. struct list_head list;
  429. uint8_t mac[ETH_ALEN];
  430. };
  431. struct batadv_algo_ops {
  432. struct hlist_node list;
  433. char *name;
  434. /* init routing info when hard-interface is enabled */
  435. int (*bat_iface_enable)(struct batadv_hard_iface *hard_iface);
  436. /* de-init routing info when hard-interface is disabled */
  437. void (*bat_iface_disable)(struct batadv_hard_iface *hard_iface);
  438. /* (re-)init mac addresses of the protocol information
  439. * belonging to this hard-interface
  440. */
  441. void (*bat_iface_update_mac)(struct batadv_hard_iface *hard_iface);
  442. /* called when primary interface is selected / changed */
  443. void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);
  444. /* prepare a new outgoing OGM for the send queue */
  445. void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);
  446. /* send scheduled OGM */
  447. void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
  448. };
  449. /**
  450. * struct batadv_dat_entry - it is a single entry of batman-adv ARP backend. It
  451. * is used to stored ARP entries needed for the global DAT cache
  452. * @ip: the IPv4 corresponding to this DAT/ARP entry
  453. * @mac_addr: the MAC address associated to the stored IPv4
  454. * @last_update: time in jiffies when this entry was refreshed last time
  455. * @hash_entry: hlist node for batadv_priv_dat::hash
  456. * @refcount: number of contexts the object is used
  457. * @rcu: struct used for freeing in an RCU-safe manner
  458. */
  459. struct batadv_dat_entry {
  460. __be32 ip;
  461. uint8_t mac_addr[ETH_ALEN];
  462. unsigned long last_update;
  463. struct hlist_node hash_entry;
  464. atomic_t refcount;
  465. struct rcu_head rcu;
  466. };
  467. /**
  468. * struct batadv_dat_candidate - candidate destination for DAT operations
  469. * @type: the type of the selected candidate. It can one of the following:
  470. * - BATADV_DAT_CANDIDATE_NOT_FOUND
  471. * - BATADV_DAT_CANDIDATE_ORIG
  472. * @orig_node: if type is BATADV_DAT_CANDIDATE_ORIG this field points to the
  473. * corresponding originator node structure
  474. */
  475. struct batadv_dat_candidate {
  476. int type;
  477. struct batadv_orig_node *orig_node;
  478. };
  479. #endif /* _NET_BATMAN_ADV_TYPES_H_ */