packet.h 11 KB

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