packet.h 11 KB

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