packet.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* Copyright (C) 2007-2012 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. #define BATADV_ETH_P_BATMAN 0x4305 /* unofficial/not registered Ethertype */
  22. enum batadv_packettype {
  23. BATADV_IV_OGM = 0x01,
  24. BATADV_ICMP = 0x02,
  25. BATADV_UNICAST = 0x03,
  26. BATADV_BCAST = 0x04,
  27. BATADV_VIS = 0x05,
  28. BATADV_UNICAST_FRAG = 0x06,
  29. BATADV_TT_QUERY = 0x07,
  30. BATADV_ROAM_ADV = 0x08,
  31. };
  32. /* this file is included by batctl which needs these defines */
  33. #define BATADV_COMPAT_VERSION 14
  34. enum batadv_iv_flags {
  35. BATADV_NOT_BEST_NEXT_HOP = 1 << 3,
  36. BATADV_PRIMARIES_FIRST_HOP = 1 << 4,
  37. BATADV_VIS_SERVER = 1 << 5,
  38. BATADV_DIRECTLINK = 1 << 6,
  39. };
  40. /* ICMP message types */
  41. enum batadv_icmp_packettype {
  42. BATADV_ECHO_REPLY = 0,
  43. BATADV_DESTINATION_UNREACHABLE = 3,
  44. BATADV_ECHO_REQUEST = 8,
  45. BATADV_TTL_EXCEEDED = 11,
  46. BATADV_PARAMETER_PROBLEM = 12,
  47. };
  48. /* vis defines */
  49. enum batadv_vis_packettype {
  50. BATADV_VIS_TYPE_SERVER_SYNC = 0,
  51. BATADV_VIS_TYPE_CLIENT_UPDATE = 1,
  52. };
  53. /* fragmentation defines */
  54. enum batadv_unicast_frag_flags {
  55. BATADV_UNI_FRAG_HEAD = 1 << 0,
  56. BATADV_UNI_FRAG_LARGETAIL = 1 << 1,
  57. };
  58. /* TT_QUERY subtypes */
  59. #define BATADV_TT_QUERY_TYPE_MASK 0x3
  60. enum batadv_tt_query_packettype {
  61. BATADV_TT_REQUEST = 0,
  62. BATADV_TT_RESPONSE = 1,
  63. };
  64. /* TT_QUERY flags */
  65. enum batadv_tt_query_flags {
  66. BATADV_TT_FULL_TABLE = 1 << 2,
  67. };
  68. /* BATADV_TT_CLIENT flags.
  69. * Flags from 1 to 1 << 7 are sent on the wire, while flags from 1 << 8 to
  70. * 1 << 15 are used for local computation only
  71. */
  72. enum batadv_tt_client_flags {
  73. BATADV_TT_CLIENT_DEL = 1 << 0,
  74. BATADV_TT_CLIENT_ROAM = 1 << 1,
  75. BATADV_TT_CLIENT_WIFI = 1 << 2,
  76. BATADV_TT_CLIENT_NOPURGE = 1 << 8,
  77. BATADV_TT_CLIENT_NEW = 1 << 9,
  78. BATADV_TT_CLIENT_PENDING = 1 << 10,
  79. };
  80. /* claim frame types for the bridge loop avoidance */
  81. enum batadv_bla_claimframe {
  82. BATADV_CLAIM_TYPE_ADD = 0x00,
  83. BATADV_CLAIM_TYPE_DEL = 0x01,
  84. BATADV_CLAIM_TYPE_ANNOUNCE = 0x02,
  85. BATADV_CLAIM_TYPE_REQUEST = 0x03,
  86. };
  87. /* the destination hardware field in the ARP frame is used to
  88. * transport the claim type and the group id
  89. */
  90. struct batadv_bla_claim_dst {
  91. uint8_t magic[3]; /* FF:43:05 */
  92. uint8_t type; /* bla_claimframe */
  93. __be16 group; /* group id */
  94. } __packed;
  95. struct batadv_header {
  96. uint8_t packet_type;
  97. uint8_t version; /* batman version field */
  98. uint8_t ttl;
  99. } __packed;
  100. struct batadv_ogm_packet {
  101. struct batadv_header header;
  102. uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
  103. __be32 seqno;
  104. uint8_t orig[ETH_ALEN];
  105. uint8_t prev_sender[ETH_ALEN];
  106. uint8_t gw_flags; /* flags related to gateway class */
  107. uint8_t tq;
  108. uint8_t tt_num_changes;
  109. uint8_t ttvn; /* translation table version number */
  110. __be16 tt_crc;
  111. } __packed;
  112. #define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
  113. struct batadv_icmp_packet {
  114. struct batadv_header header;
  115. uint8_t msg_type; /* see ICMP message types above */
  116. uint8_t dst[ETH_ALEN];
  117. uint8_t orig[ETH_ALEN];
  118. __be16 seqno;
  119. uint8_t uid;
  120. uint8_t reserved;
  121. } __packed;
  122. #define BATADV_RR_LEN 16
  123. /* icmp_packet_rr must start with all fields from imcp_packet
  124. * as this is assumed by code that handles ICMP packets
  125. */
  126. struct batadv_icmp_packet_rr {
  127. struct batadv_header header;
  128. uint8_t msg_type; /* see ICMP message types above */
  129. uint8_t dst[ETH_ALEN];
  130. uint8_t orig[ETH_ALEN];
  131. __be16 seqno;
  132. uint8_t uid;
  133. uint8_t rr_cur;
  134. uint8_t rr[BATADV_RR_LEN][ETH_ALEN];
  135. } __packed;
  136. struct batadv_unicast_packet {
  137. struct batadv_header header;
  138. uint8_t ttvn; /* destination translation table version number */
  139. uint8_t dest[ETH_ALEN];
  140. } __packed;
  141. struct batadv_unicast_frag_packet {
  142. struct batadv_header header;
  143. uint8_t ttvn; /* destination translation table version number */
  144. uint8_t dest[ETH_ALEN];
  145. uint8_t flags;
  146. uint8_t align;
  147. uint8_t orig[ETH_ALEN];
  148. __be16 seqno;
  149. } __packed;
  150. struct batadv_bcast_packet {
  151. struct batadv_header header;
  152. uint8_t reserved;
  153. __be32 seqno;
  154. uint8_t orig[ETH_ALEN];
  155. } __packed;
  156. struct batadv_vis_packet {
  157. struct batadv_header header;
  158. uint8_t vis_type; /* which type of vis-participant sent this? */
  159. __be32 seqno; /* sequence number */
  160. uint8_t entries; /* number of entries behind this struct */
  161. uint8_t reserved;
  162. uint8_t vis_orig[ETH_ALEN]; /* originator reporting its neighbors */
  163. uint8_t target_orig[ETH_ALEN]; /* who should receive this packet */
  164. uint8_t sender_orig[ETH_ALEN]; /* who sent or forwarded this packet */
  165. } __packed;
  166. struct batadv_tt_query_packet {
  167. struct batadv_header header;
  168. /* the flag field is a combination of:
  169. * - TT_REQUEST or TT_RESPONSE
  170. * - TT_FULL_TABLE
  171. */
  172. uint8_t flags;
  173. uint8_t dst[ETH_ALEN];
  174. uint8_t src[ETH_ALEN];
  175. /* the ttvn field is:
  176. * if TT_REQUEST: ttvn that triggered the
  177. * request
  178. * if TT_RESPONSE: new ttvn for the src
  179. * orig_node
  180. */
  181. uint8_t ttvn;
  182. /* tt_data field is:
  183. * if TT_REQUEST: crc associated with the
  184. * ttvn
  185. * if TT_RESPONSE: table_size
  186. */
  187. __be16 tt_data;
  188. } __packed;
  189. struct batadv_roam_adv_packet {
  190. struct batadv_header header;
  191. uint8_t reserved;
  192. uint8_t dst[ETH_ALEN];
  193. uint8_t src[ETH_ALEN];
  194. uint8_t client[ETH_ALEN];
  195. } __packed;
  196. struct batadv_tt_change {
  197. uint8_t flags;
  198. uint8_t addr[ETH_ALEN];
  199. } __packed;
  200. #endif /* _NET_BATMAN_ADV_PACKET_H_ */