packet.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /* Copyright (C) 2007-2013 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_PACKET_H_
  20. #define _NET_BATMAN_ADV_PACKET_H_
  21. /**
  22. * enum batadv_packettype - types for batman-adv encapsulated packets
  23. * @BATADV_UNICAST_TVLV: unicast packet carrying TVLV containers
  24. */
  25. enum batadv_packettype {
  26. BATADV_IV_OGM = 0x01,
  27. BATADV_ICMP = 0x02,
  28. BATADV_UNICAST = 0x03,
  29. BATADV_BCAST = 0x04,
  30. BATADV_VIS = 0x05,
  31. BATADV_UNICAST_FRAG = 0x06,
  32. BATADV_TT_QUERY = 0x07,
  33. BATADV_ROAM_ADV = 0x08,
  34. BATADV_UNICAST_4ADDR = 0x09,
  35. BATADV_CODED = 0x0a,
  36. BATADV_UNICAST_TVLV = 0x0b,
  37. };
  38. /**
  39. * enum batadv_subtype - packet subtype for unicast4addr
  40. * @BATADV_P_DATA: user payload
  41. * @BATADV_P_DAT_DHT_GET: DHT request message
  42. * @BATADV_P_DAT_DHT_PUT: DHT store message
  43. * @BATADV_P_DAT_CACHE_REPLY: ARP reply generated by DAT
  44. */
  45. enum batadv_subtype {
  46. BATADV_P_DATA = 0x01,
  47. BATADV_P_DAT_DHT_GET = 0x02,
  48. BATADV_P_DAT_DHT_PUT = 0x03,
  49. BATADV_P_DAT_CACHE_REPLY = 0x04,
  50. };
  51. /* this file is included by batctl which needs these defines */
  52. #define BATADV_COMPAT_VERSION 15
  53. enum batadv_iv_flags {
  54. BATADV_NOT_BEST_NEXT_HOP = BIT(3),
  55. BATADV_PRIMARIES_FIRST_HOP = BIT(4),
  56. BATADV_VIS_SERVER = BIT(5),
  57. BATADV_DIRECTLINK = BIT(6),
  58. };
  59. /* ICMP message types */
  60. enum batadv_icmp_packettype {
  61. BATADV_ECHO_REPLY = 0,
  62. BATADV_DESTINATION_UNREACHABLE = 3,
  63. BATADV_ECHO_REQUEST = 8,
  64. BATADV_TTL_EXCEEDED = 11,
  65. BATADV_PARAMETER_PROBLEM = 12,
  66. };
  67. /* vis defines */
  68. enum batadv_vis_packettype {
  69. BATADV_VIS_TYPE_SERVER_SYNC = 0,
  70. BATADV_VIS_TYPE_CLIENT_UPDATE = 1,
  71. };
  72. /* fragmentation defines */
  73. enum batadv_unicast_frag_flags {
  74. BATADV_UNI_FRAG_HEAD = BIT(0),
  75. BATADV_UNI_FRAG_LARGETAIL = BIT(1),
  76. };
  77. /* TT_QUERY subtypes */
  78. #define BATADV_TT_QUERY_TYPE_MASK 0x3
  79. enum batadv_tt_query_packettype {
  80. BATADV_TT_REQUEST = 0,
  81. BATADV_TT_RESPONSE = 1,
  82. };
  83. /* TT_QUERY flags */
  84. enum batadv_tt_query_flags {
  85. BATADV_TT_FULL_TABLE = BIT(2),
  86. };
  87. /* BATADV_TT_CLIENT flags.
  88. * Flags from BIT(0) to BIT(7) are sent on the wire, while flags from BIT(8) to
  89. * BIT(15) are used for local computation only
  90. */
  91. enum batadv_tt_client_flags {
  92. BATADV_TT_CLIENT_DEL = BIT(0),
  93. BATADV_TT_CLIENT_ROAM = BIT(1),
  94. BATADV_TT_CLIENT_WIFI = BIT(2),
  95. BATADV_TT_CLIENT_TEMP = BIT(3),
  96. BATADV_TT_CLIENT_NOPURGE = BIT(8),
  97. BATADV_TT_CLIENT_NEW = BIT(9),
  98. BATADV_TT_CLIENT_PENDING = BIT(10),
  99. };
  100. /* claim frame types for the bridge loop avoidance */
  101. enum batadv_bla_claimframe {
  102. BATADV_CLAIM_TYPE_CLAIM = 0x00,
  103. BATADV_CLAIM_TYPE_UNCLAIM = 0x01,
  104. BATADV_CLAIM_TYPE_ANNOUNCE = 0x02,
  105. BATADV_CLAIM_TYPE_REQUEST = 0x03,
  106. };
  107. /**
  108. * enum batadv_tvlv_type - tvlv type definitions
  109. * @BATADV_TVLV_GW: gateway tvlv
  110. * @BATADV_TVLV_DAT: distributed arp table tvlv
  111. */
  112. enum batadv_tvlv_type {
  113. BATADV_TVLV_GW = 0x01,
  114. BATADV_TVLV_DAT = 0x02,
  115. };
  116. /* the destination hardware field in the ARP frame is used to
  117. * transport the claim type and the group id
  118. */
  119. struct batadv_bla_claim_dst {
  120. uint8_t magic[3]; /* FF:43:05 */
  121. uint8_t type; /* bla_claimframe */
  122. __be16 group; /* group id */
  123. };
  124. struct batadv_header {
  125. uint8_t packet_type;
  126. uint8_t version; /* batman version field */
  127. uint8_t ttl;
  128. /* the parent struct has to add a byte after the header to make
  129. * everything 4 bytes aligned again
  130. */
  131. };
  132. /**
  133. * struct batadv_ogm_packet - ogm (routing protocol) packet
  134. * @header: common batman packet header
  135. * @tvlv_len: length of tvlv data following the ogm header
  136. */
  137. struct batadv_ogm_packet {
  138. struct batadv_header header;
  139. uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
  140. __be32 seqno;
  141. uint8_t orig[ETH_ALEN];
  142. uint8_t prev_sender[ETH_ALEN];
  143. uint8_t reserved;
  144. uint8_t tq;
  145. uint8_t tt_num_changes;
  146. uint8_t ttvn; /* translation table version number */
  147. __be16 tt_crc;
  148. __be16 tvlv_len;
  149. } __packed;
  150. #define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
  151. struct batadv_icmp_packet {
  152. struct batadv_header header;
  153. uint8_t msg_type; /* see ICMP message types above */
  154. uint8_t dst[ETH_ALEN];
  155. uint8_t orig[ETH_ALEN];
  156. __be16 seqno;
  157. uint8_t uid;
  158. uint8_t reserved;
  159. };
  160. #define BATADV_RR_LEN 16
  161. /* icmp_packet_rr must start with all fields from imcp_packet
  162. * as this is assumed by code that handles ICMP packets
  163. */
  164. struct batadv_icmp_packet_rr {
  165. struct batadv_header header;
  166. uint8_t msg_type; /* see ICMP message types above */
  167. uint8_t dst[ETH_ALEN];
  168. uint8_t orig[ETH_ALEN];
  169. __be16 seqno;
  170. uint8_t uid;
  171. uint8_t rr_cur;
  172. uint8_t rr[BATADV_RR_LEN][ETH_ALEN];
  173. };
  174. /* All packet headers in front of an ethernet header have to be completely
  175. * divisible by 2 but not by 4 to make the payload after the ethernet
  176. * header again 4 bytes boundary aligned.
  177. *
  178. * A packing of 2 is necessary to avoid extra padding at the end of the struct
  179. * caused by a structure member which is larger than two bytes. Otherwise
  180. * the structure would not fulfill the previously mentioned rule to avoid the
  181. * misalignment of the payload after the ethernet header. It may also lead to
  182. * leakage of information when the padding it not initialized before sending.
  183. */
  184. #pragma pack(2)
  185. struct batadv_unicast_packet {
  186. struct batadv_header header;
  187. uint8_t ttvn; /* destination translation table version number */
  188. uint8_t dest[ETH_ALEN];
  189. /* "4 bytes boundary + 2 bytes" long to make the payload after the
  190. * following ethernet header again 4 bytes boundary aligned
  191. */
  192. };
  193. /**
  194. * struct batadv_unicast_4addr_packet - extended unicast packet
  195. * @u: common unicast packet header
  196. * @src: address of the source
  197. * @subtype: packet subtype
  198. */
  199. struct batadv_unicast_4addr_packet {
  200. struct batadv_unicast_packet u;
  201. uint8_t src[ETH_ALEN];
  202. uint8_t subtype;
  203. uint8_t reserved;
  204. /* "4 bytes boundary + 2 bytes" long to make the payload after the
  205. * following ethernet header again 4 bytes boundary aligned
  206. */
  207. };
  208. struct batadv_unicast_frag_packet {
  209. struct batadv_header header;
  210. uint8_t ttvn; /* destination translation table version number */
  211. uint8_t dest[ETH_ALEN];
  212. uint8_t flags;
  213. uint8_t align;
  214. uint8_t orig[ETH_ALEN];
  215. __be16 seqno;
  216. } __packed;
  217. struct batadv_bcast_packet {
  218. struct batadv_header header;
  219. uint8_t reserved;
  220. __be32 seqno;
  221. uint8_t orig[ETH_ALEN];
  222. /* "4 bytes boundary + 2 bytes" long to make the payload after the
  223. * following ethernet header again 4 bytes boundary aligned
  224. */
  225. };
  226. #pragma pack()
  227. struct batadv_vis_packet {
  228. struct batadv_header header;
  229. uint8_t vis_type; /* which type of vis-participant sent this? */
  230. __be32 seqno; /* sequence number */
  231. uint8_t entries; /* number of entries behind this struct */
  232. uint8_t reserved;
  233. uint8_t vis_orig[ETH_ALEN]; /* originator reporting its neighbors */
  234. uint8_t target_orig[ETH_ALEN]; /* who should receive this packet */
  235. uint8_t sender_orig[ETH_ALEN]; /* who sent or forwarded this packet */
  236. };
  237. struct batadv_tt_query_packet {
  238. struct batadv_header header;
  239. /* the flag field is a combination of:
  240. * - TT_REQUEST or TT_RESPONSE
  241. * - TT_FULL_TABLE
  242. */
  243. uint8_t flags;
  244. uint8_t dst[ETH_ALEN];
  245. uint8_t src[ETH_ALEN];
  246. /* the ttvn field is:
  247. * if TT_REQUEST: ttvn that triggered the
  248. * request
  249. * if TT_RESPONSE: new ttvn for the src
  250. * orig_node
  251. */
  252. uint8_t ttvn;
  253. /* tt_data field is:
  254. * if TT_REQUEST: crc associated with the
  255. * ttvn
  256. * if TT_RESPONSE: table_size
  257. */
  258. __be16 tt_data;
  259. } __packed;
  260. struct batadv_roam_adv_packet {
  261. struct batadv_header header;
  262. uint8_t reserved;
  263. uint8_t dst[ETH_ALEN];
  264. uint8_t src[ETH_ALEN];
  265. uint8_t client[ETH_ALEN];
  266. } __packed;
  267. struct batadv_tt_change {
  268. uint8_t flags;
  269. uint8_t addr[ETH_ALEN];
  270. } __packed;
  271. /**
  272. * struct batadv_coded_packet - network coded packet
  273. * @header: common batman packet header and ttl of first included packet
  274. * @reserved: Align following fields to 2-byte boundaries
  275. * @first_source: original source of first included packet
  276. * @first_orig_dest: original destinal of first included packet
  277. * @first_crc: checksum of first included packet
  278. * @first_ttvn: tt-version number of first included packet
  279. * @second_ttl: ttl of second packet
  280. * @second_dest: second receiver of this coded packet
  281. * @second_source: original source of second included packet
  282. * @second_orig_dest: original destination of second included packet
  283. * @second_crc: checksum of second included packet
  284. * @second_ttvn: tt version number of second included packet
  285. * @coded_len: length of network coded part of the payload
  286. */
  287. struct batadv_coded_packet {
  288. struct batadv_header header;
  289. uint8_t first_ttvn;
  290. /* uint8_t first_dest[ETH_ALEN]; - saved in mac header destination */
  291. uint8_t first_source[ETH_ALEN];
  292. uint8_t first_orig_dest[ETH_ALEN];
  293. __be32 first_crc;
  294. uint8_t second_ttl;
  295. uint8_t second_ttvn;
  296. uint8_t second_dest[ETH_ALEN];
  297. uint8_t second_source[ETH_ALEN];
  298. uint8_t second_orig_dest[ETH_ALEN];
  299. __be32 second_crc;
  300. __be16 coded_len;
  301. };
  302. /**
  303. * struct batadv_unicast_tvlv - generic unicast packet with tvlv payload
  304. * @header: common batman packet header
  305. * @reserved: reserved field (for packet alignment)
  306. * @src: address of the source
  307. * @dst: address of the destination
  308. * @tvlv_len: length of tvlv data following the unicast tvlv header
  309. * @align: 2 bytes to align the header to a 4 byte boundry
  310. */
  311. struct batadv_unicast_tvlv_packet {
  312. struct batadv_header header;
  313. uint8_t reserved;
  314. uint8_t dst[ETH_ALEN];
  315. uint8_t src[ETH_ALEN];
  316. __be16 tvlv_len;
  317. uint16_t align;
  318. };
  319. /**
  320. * struct batadv_tvlv_hdr - base tvlv header struct
  321. * @type: tvlv container type (see batadv_tvlv_type)
  322. * @version: tvlv container version
  323. * @len: tvlv container length
  324. */
  325. struct batadv_tvlv_hdr {
  326. uint8_t type;
  327. uint8_t version;
  328. __be16 len;
  329. };
  330. /**
  331. * struct batadv_tvlv_gateway_data - gateway data propagated through gw tvlv
  332. * container
  333. * @bandwidth_down: advertised uplink download bandwidth
  334. * @bandwidth_up: advertised uplink upload bandwidth
  335. */
  336. struct batadv_tvlv_gateway_data {
  337. __be32 bandwidth_down;
  338. __be32 bandwidth_up;
  339. };
  340. #endif /* _NET_BATMAN_ADV_PACKET_H_ */