types.h 15 KB

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