packet.h 8.9 KB

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