packet.h 11 KB

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