types.h 15 KB

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