packet.h 11 KB

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