packet.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. * Flags from BIT(4) to BIT(7) are kept in sync with the rest of the network.
  106. */
  107. enum batadv_tt_client_flags {
  108. BATADV_TT_CLIENT_DEL = BIT(0),
  109. BATADV_TT_CLIENT_ROAM = BIT(1),
  110. BATADV_TT_CLIENT_WIFI = BIT(4),
  111. BATADV_TT_CLIENT_NOPURGE = BIT(8),
  112. BATADV_TT_CLIENT_NEW = BIT(9),
  113. BATADV_TT_CLIENT_PENDING = BIT(10),
  114. BATADV_TT_CLIENT_TEMP = BIT(11),
  115. };
  116. /**
  117. * batadv_vlan_flags - flags for the four MSB of any vlan ID field
  118. * @BATADV_VLAN_HAS_TAG: whether the field contains a valid vlan tag or not
  119. */
  120. enum batadv_vlan_flags {
  121. BATADV_VLAN_HAS_TAG = BIT(15),
  122. };
  123. /* claim frame types for the bridge loop avoidance */
  124. enum batadv_bla_claimframe {
  125. BATADV_CLAIM_TYPE_CLAIM = 0x00,
  126. BATADV_CLAIM_TYPE_UNCLAIM = 0x01,
  127. BATADV_CLAIM_TYPE_ANNOUNCE = 0x02,
  128. BATADV_CLAIM_TYPE_REQUEST = 0x03,
  129. };
  130. /**
  131. * enum batadv_tvlv_type - tvlv type definitions
  132. * @BATADV_TVLV_GW: gateway tvlv
  133. * @BATADV_TVLV_DAT: distributed arp table tvlv
  134. * @BATADV_TVLV_NC: network coding tvlv
  135. * @BATADV_TVLV_TT: translation table tvlv
  136. * @BATADV_TVLV_ROAM: roaming advertisement tvlv
  137. */
  138. enum batadv_tvlv_type {
  139. BATADV_TVLV_GW = 0x01,
  140. BATADV_TVLV_DAT = 0x02,
  141. BATADV_TVLV_NC = 0x03,
  142. BATADV_TVLV_TT = 0x04,
  143. BATADV_TVLV_ROAM = 0x05,
  144. };
  145. /* the destination hardware field in the ARP frame is used to
  146. * transport the claim type and the group id
  147. */
  148. struct batadv_bla_claim_dst {
  149. uint8_t magic[3]; /* FF:43:05 */
  150. uint8_t type; /* bla_claimframe */
  151. __be16 group; /* group id */
  152. };
  153. struct batadv_header {
  154. uint8_t packet_type;
  155. uint8_t version; /* batman version field */
  156. uint8_t ttl;
  157. /* the parent struct has to add a byte after the header to make
  158. * everything 4 bytes aligned again
  159. */
  160. };
  161. /**
  162. * struct batadv_ogm_packet - ogm (routing protocol) packet
  163. * @header: common batman packet header
  164. * @flags: contains routing relevant flags - see enum batadv_iv_flags
  165. * @tvlv_len: length of tvlv data following the ogm header
  166. */
  167. struct batadv_ogm_packet {
  168. struct batadv_header header;
  169. uint8_t flags;
  170. __be32 seqno;
  171. uint8_t orig[ETH_ALEN];
  172. uint8_t prev_sender[ETH_ALEN];
  173. uint8_t reserved;
  174. uint8_t tq;
  175. __be16 tvlv_len;
  176. /* __packed is not needed as the struct size is divisible by 4,
  177. * and the largest data type in this struct has a size of 4.
  178. */
  179. };
  180. #define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
  181. /**
  182. * batadv_icmp_header - common ICMP header
  183. * @header: common batman header
  184. * @msg_type: ICMP packet type
  185. * @dst: address of the destination node
  186. * @orig: address of the source node
  187. * @uid: local ICMP socket identifier
  188. */
  189. struct batadv_icmp_header {
  190. struct batadv_header header;
  191. uint8_t msg_type; /* see ICMP message types above */
  192. uint8_t dst[ETH_ALEN];
  193. uint8_t orig[ETH_ALEN];
  194. uint8_t uid;
  195. };
  196. /**
  197. * batadv_icmp_packet - ICMP packet
  198. * @icmph: common ICMP header
  199. * @reserved: not used - useful for alignment
  200. * @seqno: ICMP sequence number
  201. */
  202. struct batadv_icmp_packet {
  203. struct batadv_icmp_header icmph;
  204. uint8_t reserved;
  205. __be16 seqno;
  206. };
  207. #define BATADV_RR_LEN 16
  208. /**
  209. * batadv_icmp_packet_rr - ICMP RouteRecord packet
  210. * @icmph: common ICMP header
  211. * @rr_cur: number of entries the rr array
  212. * @seqno: ICMP sequence number
  213. * @rr: route record array
  214. */
  215. struct batadv_icmp_packet_rr {
  216. struct batadv_icmp_header icmph;
  217. uint8_t rr_cur;
  218. __be16 seqno;
  219. uint8_t rr[BATADV_RR_LEN][ETH_ALEN];
  220. };
  221. #define BATADV_ICMP_MAX_PACKET_SIZE sizeof(struct batadv_icmp_packet_rr)
  222. /* All packet headers in front of an ethernet header have to be completely
  223. * divisible by 2 but not by 4 to make the payload after the ethernet
  224. * header again 4 bytes boundary aligned.
  225. *
  226. * A packing of 2 is necessary to avoid extra padding at the end of the struct
  227. * caused by a structure member which is larger than two bytes. Otherwise
  228. * the structure would not fulfill the previously mentioned rule to avoid the
  229. * misalignment of the payload after the ethernet header. It may also lead to
  230. * leakage of information when the padding it not initialized before sending.
  231. */
  232. #pragma pack(2)
  233. struct batadv_unicast_packet {
  234. struct batadv_header header;
  235. uint8_t ttvn; /* destination translation table version number */
  236. uint8_t dest[ETH_ALEN];
  237. /* "4 bytes boundary + 2 bytes" long to make the payload after the
  238. * following ethernet header again 4 bytes boundary aligned
  239. */
  240. };
  241. /**
  242. * struct batadv_unicast_4addr_packet - extended unicast packet
  243. * @u: common unicast packet header
  244. * @src: address of the source
  245. * @subtype: packet subtype
  246. */
  247. struct batadv_unicast_4addr_packet {
  248. struct batadv_unicast_packet u;
  249. uint8_t src[ETH_ALEN];
  250. uint8_t subtype;
  251. uint8_t reserved;
  252. /* "4 bytes boundary + 2 bytes" long to make the payload after the
  253. * following ethernet header again 4 bytes boundary aligned
  254. */
  255. };
  256. /**
  257. * struct batadv_frag_packet - fragmented packet
  258. * @header: common batman packet header with type, compatversion, and ttl
  259. * @dest: final destination used when routing fragments
  260. * @orig: originator of the fragment used when merging the packet
  261. * @no: fragment number within this sequence
  262. * @reserved: reserved byte for alignment
  263. * @seqno: sequence identification
  264. * @total_size: size of the merged packet
  265. */
  266. struct batadv_frag_packet {
  267. struct batadv_header header;
  268. #if defined(__BIG_ENDIAN_BITFIELD)
  269. uint8_t no:4;
  270. uint8_t reserved:4;
  271. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  272. uint8_t reserved:4;
  273. uint8_t no:4;
  274. #else
  275. #error "unknown bitfield endianess"
  276. #endif
  277. uint8_t dest[ETH_ALEN];
  278. uint8_t orig[ETH_ALEN];
  279. __be16 seqno;
  280. __be16 total_size;
  281. };
  282. struct batadv_bcast_packet {
  283. struct batadv_header header;
  284. uint8_t reserved;
  285. __be32 seqno;
  286. uint8_t orig[ETH_ALEN];
  287. /* "4 bytes boundary + 2 bytes" long to make the payload after the
  288. * following ethernet header again 4 bytes boundary aligned
  289. */
  290. };
  291. #pragma pack()
  292. /**
  293. * struct batadv_coded_packet - network coded packet
  294. * @header: common batman packet header and ttl of first included packet
  295. * @reserved: Align following fields to 2-byte boundaries
  296. * @first_source: original source of first included packet
  297. * @first_orig_dest: original destinal of first included packet
  298. * @first_crc: checksum of first included packet
  299. * @first_ttvn: tt-version number of first included packet
  300. * @second_ttl: ttl of second packet
  301. * @second_dest: second receiver of this coded packet
  302. * @second_source: original source of second included packet
  303. * @second_orig_dest: original destination of second included packet
  304. * @second_crc: checksum of second included packet
  305. * @second_ttvn: tt version number of second included packet
  306. * @coded_len: length of network coded part of the payload
  307. */
  308. struct batadv_coded_packet {
  309. struct batadv_header header;
  310. uint8_t first_ttvn;
  311. /* uint8_t first_dest[ETH_ALEN]; - saved in mac header destination */
  312. uint8_t first_source[ETH_ALEN];
  313. uint8_t first_orig_dest[ETH_ALEN];
  314. __be32 first_crc;
  315. uint8_t second_ttl;
  316. uint8_t second_ttvn;
  317. uint8_t second_dest[ETH_ALEN];
  318. uint8_t second_source[ETH_ALEN];
  319. uint8_t second_orig_dest[ETH_ALEN];
  320. __be32 second_crc;
  321. __be16 coded_len;
  322. };
  323. /**
  324. * struct batadv_unicast_tvlv - generic unicast packet with tvlv payload
  325. * @header: common batman packet header
  326. * @reserved: reserved field (for packet alignment)
  327. * @src: address of the source
  328. * @dst: address of the destination
  329. * @tvlv_len: length of tvlv data following the unicast tvlv header
  330. * @align: 2 bytes to align the header to a 4 byte boundry
  331. */
  332. struct batadv_unicast_tvlv_packet {
  333. struct batadv_header header;
  334. uint8_t reserved;
  335. uint8_t dst[ETH_ALEN];
  336. uint8_t src[ETH_ALEN];
  337. __be16 tvlv_len;
  338. uint16_t align;
  339. };
  340. /**
  341. * struct batadv_tvlv_hdr - base tvlv header struct
  342. * @type: tvlv container type (see batadv_tvlv_type)
  343. * @version: tvlv container version
  344. * @len: tvlv container length
  345. */
  346. struct batadv_tvlv_hdr {
  347. uint8_t type;
  348. uint8_t version;
  349. __be16 len;
  350. };
  351. /**
  352. * struct batadv_tvlv_gateway_data - gateway data propagated through gw tvlv
  353. * container
  354. * @bandwidth_down: advertised uplink download bandwidth
  355. * @bandwidth_up: advertised uplink upload bandwidth
  356. */
  357. struct batadv_tvlv_gateway_data {
  358. __be32 bandwidth_down;
  359. __be32 bandwidth_up;
  360. };
  361. /**
  362. * struct batadv_tvlv_tt_data - tt data propagated through the tt tvlv container
  363. * @flags: translation table flags (see batadv_tt_data_flags)
  364. * @ttvn: translation table version number
  365. * @vlan_num: number of announced VLANs. In the TVLV this struct is followed by
  366. * one batadv_tvlv_tt_vlan_data object per announced vlan
  367. */
  368. struct batadv_tvlv_tt_data {
  369. uint8_t flags;
  370. uint8_t ttvn;
  371. __be16 num_vlan;
  372. };
  373. /**
  374. * struct batadv_tvlv_tt_vlan_data - vlan specific tt data propagated through
  375. * the tt tvlv container
  376. * @crc: crc32 checksum of the entries belonging to this vlan
  377. * @vid: vlan identifier
  378. * @reserved: unused, useful for alignment purposes
  379. */
  380. struct batadv_tvlv_tt_vlan_data {
  381. __be32 crc;
  382. __be16 vid;
  383. uint16_t reserved;
  384. };
  385. /**
  386. * struct batadv_tvlv_tt_change - translation table diff data
  387. * @flags: status indicators concerning the non-mesh client (see
  388. * batadv_tt_client_flags)
  389. * @reserved: reserved field
  390. * @addr: mac address of non-mesh client that triggered this tt change
  391. * @vid: VLAN identifier
  392. */
  393. struct batadv_tvlv_tt_change {
  394. uint8_t flags;
  395. uint8_t reserved;
  396. uint8_t addr[ETH_ALEN];
  397. __be16 vid;
  398. };
  399. /**
  400. * struct batadv_tvlv_roam_adv - roaming advertisement
  401. * @client: mac address of roaming client
  402. * @vid: VLAN identifier
  403. */
  404. struct batadv_tvlv_roam_adv {
  405. uint8_t client[ETH_ALEN];
  406. __be16 vid;
  407. };
  408. #endif /* _NET_BATMAN_ADV_PACKET_H_ */