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. /* The tt_poss_change flag is used to detect an ongoing roaming phase.
  96. * If true, then I sent a Roaming_adv to this orig_node and I have to
  97. * inspect every packet directed to it to check whether it is still
  98. * the true destination or not. This flag will be reset to false as
  99. * soon as I receive a new TTVN from this orig_node
  100. */
  101. bool tt_poss_change;
  102. uint32_t last_real_seqno;
  103. uint8_t last_ttl;
  104. DECLARE_BITMAP(bcast_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
  105. uint32_t last_bcast_seqno;
  106. struct hlist_head neigh_list;
  107. struct list_head frag_list;
  108. spinlock_t neigh_list_lock; /* protects neigh_list and router */
  109. atomic_t refcount;
  110. struct rcu_head rcu;
  111. struct hlist_node hash_entry;
  112. struct batadv_priv *bat_priv;
  113. unsigned long last_frag_packet;
  114. /* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
  115. * neigh_node->real_bits, neigh_node->real_packet_count
  116. */
  117. spinlock_t ogm_cnt_lock;
  118. /* bcast_seqno_lock protects bcast_bits, last_bcast_seqno */
  119. spinlock_t bcast_seqno_lock;
  120. spinlock_t tt_list_lock; /* protects tt_list */
  121. atomic_t bond_candidates;
  122. struct list_head bond_list;
  123. };
  124. struct batadv_gw_node {
  125. struct hlist_node list;
  126. struct batadv_orig_node *orig_node;
  127. unsigned long deleted;
  128. atomic_t refcount;
  129. struct rcu_head rcu;
  130. };
  131. /* batadv_neigh_node
  132. * @last_seen: when last packet via this neighbor was received
  133. */
  134. struct batadv_neigh_node {
  135. struct hlist_node list;
  136. uint8_t addr[ETH_ALEN];
  137. uint8_t real_packet_count;
  138. uint8_t tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE];
  139. uint8_t tq_index;
  140. uint8_t tq_avg;
  141. uint8_t last_ttl;
  142. struct list_head bonding_list;
  143. unsigned long last_seen;
  144. DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
  145. atomic_t refcount;
  146. struct rcu_head rcu;
  147. struct batadv_orig_node *orig_node;
  148. struct batadv_hard_iface *if_incoming;
  149. spinlock_t lq_update_lock; /* protects: tq_recv, tq_index */
  150. };
  151. #ifdef CONFIG_BATMAN_ADV_BLA
  152. struct batadv_bcast_duplist_entry {
  153. uint8_t orig[ETH_ALEN];
  154. uint16_t crc;
  155. unsigned long entrytime;
  156. };
  157. #endif
  158. enum batadv_counters {
  159. BATADV_CNT_TX,
  160. BATADV_CNT_TX_BYTES,
  161. BATADV_CNT_TX_DROPPED,
  162. BATADV_CNT_RX,
  163. BATADV_CNT_RX_BYTES,
  164. BATADV_CNT_FORWARD,
  165. BATADV_CNT_FORWARD_BYTES,
  166. BATADV_CNT_MGMT_TX,
  167. BATADV_CNT_MGMT_TX_BYTES,
  168. BATADV_CNT_MGMT_RX,
  169. BATADV_CNT_MGMT_RX_BYTES,
  170. BATADV_CNT_TT_REQUEST_TX,
  171. BATADV_CNT_TT_REQUEST_RX,
  172. BATADV_CNT_TT_RESPONSE_TX,
  173. BATADV_CNT_TT_RESPONSE_RX,
  174. BATADV_CNT_TT_ROAM_ADV_TX,
  175. BATADV_CNT_TT_ROAM_ADV_RX,
  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. bool poss_change;
  195. struct list_head changes_list;
  196. struct batadv_hashtable *local_hash;
  197. struct batadv_hashtable *global_hash;
  198. struct list_head req_list;
  199. struct list_head roam_list;
  200. spinlock_t changes_list_lock; /* protects changes */
  201. spinlock_t req_list_lock; /* protects req_list */
  202. spinlock_t roam_list_lock; /* protects roam_list */
  203. atomic_t local_entry_num;
  204. uint16_t local_crc;
  205. unsigned char *last_changeset;
  206. int16_t last_changeset_len;
  207. spinlock_t last_changeset_lock; /* protects last_changeset */
  208. struct delayed_work work;
  209. };
  210. #ifdef CONFIG_BATMAN_ADV_BLA
  211. struct batadv_priv_bla {
  212. atomic_t num_requests; /* number of bla requests in flight */
  213. struct batadv_hashtable *claim_hash;
  214. struct batadv_hashtable *backbone_hash;
  215. struct batadv_bcast_duplist_entry bcast_duplist[BATADV_DUPLIST_SIZE];
  216. int bcast_duplist_curr;
  217. /* protects bcast_duplist and bcast_duplist_curr */
  218. spinlock_t bcast_duplist_lock;
  219. struct batadv_bla_claim_dst claim_dest;
  220. struct delayed_work work;
  221. };
  222. #endif
  223. struct batadv_priv_gw {
  224. struct hlist_head list;
  225. spinlock_t list_lock; /* protects gw_list and curr_gw */
  226. struct batadv_gw_node __rcu *curr_gw; /* rcu protected pointer */
  227. atomic_t reselect;
  228. };
  229. struct batadv_priv_vis {
  230. struct list_head send_list;
  231. struct batadv_hashtable *hash;
  232. spinlock_t hash_lock; /* protects hash */
  233. spinlock_t list_lock; /* protects info::recv_list */
  234. struct delayed_work work;
  235. struct batadv_vis_info *my_info;
  236. };
  237. /**
  238. * struct batadv_priv_dat - per mesh interface DAT private data
  239. * @addr: node DAT address
  240. * @hash: hashtable representing the local ARP cache
  241. * @work: work queue callback item for cache purging
  242. */
  243. #ifdef CONFIG_BATMAN_ADV_DAT
  244. struct batadv_priv_dat {
  245. batadv_dat_addr_t addr;
  246. struct batadv_hashtable *hash;
  247. struct delayed_work work;
  248. };
  249. #endif
  250. struct batadv_priv {
  251. atomic_t mesh_state;
  252. struct net_device_stats stats;
  253. uint64_t __percpu *bat_counters; /* Per cpu counters */
  254. atomic_t aggregated_ogms; /* boolean */
  255. atomic_t bonding; /* boolean */
  256. atomic_t fragmentation; /* boolean */
  257. atomic_t ap_isolation; /* boolean */
  258. atomic_t bridge_loop_avoidance; /* boolean */
  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 */
  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 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_ */