packet.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
  3. *
  4. * Marek Lindner, Simon Wunderlich
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of version 2 of the GNU General Public
  8. * License as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA
  19. *
  20. */
  21. #ifndef _NET_BATMAN_ADV_PACKET_H_
  22. #define _NET_BATMAN_ADV_PACKET_H_
  23. #define ETH_P_BATMAN 0x4305 /* unofficial/not registered Ethertype */
  24. enum bat_packettype {
  25. BAT_PACKET = 0x01,
  26. BAT_ICMP = 0x02,
  27. BAT_UNICAST = 0x03,
  28. BAT_BCAST = 0x04,
  29. BAT_VIS = 0x05,
  30. BAT_UNICAST_FRAG = 0x06,
  31. BAT_TT_QUERY = 0x07,
  32. BAT_ROAM_ADV = 0x08
  33. };
  34. /* this file is included by batctl which needs these defines */
  35. #define COMPAT_VERSION 14
  36. enum batman_flags {
  37. PRIMARIES_FIRST_HOP = 1 << 4,
  38. VIS_SERVER = 1 << 5,
  39. DIRECTLINK = 1 << 6
  40. };
  41. /* ICMP message types */
  42. enum icmp_packettype {
  43. ECHO_REPLY = 0,
  44. DESTINATION_UNREACHABLE = 3,
  45. ECHO_REQUEST = 8,
  46. TTL_EXCEEDED = 11,
  47. PARAMETER_PROBLEM = 12
  48. };
  49. /* vis defines */
  50. enum vis_packettype {
  51. VIS_TYPE_SERVER_SYNC = 0,
  52. VIS_TYPE_CLIENT_UPDATE = 1
  53. };
  54. /* fragmentation defines */
  55. enum unicast_frag_flags {
  56. UNI_FRAG_HEAD = 1 << 0,
  57. UNI_FRAG_LARGETAIL = 1 << 1
  58. };
  59. /* TT_QUERY subtypes */
  60. #define TT_QUERY_TYPE_MASK 0x3
  61. enum tt_query_packettype {
  62. TT_REQUEST = 0,
  63. TT_RESPONSE = 1
  64. };
  65. /* TT_QUERY flags */
  66. enum tt_query_flags {
  67. TT_FULL_TABLE = 1 << 2
  68. };
  69. /* TT_CLIENT flags.
  70. * Flags from 1 to 1 << 7 are sent on the wire, while flags from 1 << 8 to
  71. * 1 << 15 are used for local computation only */
  72. enum tt_client_flags {
  73. TT_CLIENT_DEL = 1 << 0,
  74. TT_CLIENT_ROAM = 1 << 1,
  75. TT_CLIENT_NOPURGE = 1 << 8,
  76. TT_CLIENT_NEW = 1 << 9,
  77. TT_CLIENT_PENDING = 1 << 10
  78. };
  79. struct batman_packet {
  80. uint8_t packet_type;
  81. uint8_t version; /* batman version field */
  82. uint8_t ttl;
  83. uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
  84. uint32_t seqno;
  85. uint8_t orig[6];
  86. uint8_t prev_sender[6];
  87. uint8_t gw_flags; /* flags related to gateway class */
  88. uint8_t tq;
  89. uint8_t tt_num_changes;
  90. uint8_t ttvn; /* translation table version number */
  91. uint16_t tt_crc;
  92. } __packed;
  93. #define BAT_PACKET_LEN sizeof(struct batman_packet)
  94. struct icmp_packet {
  95. uint8_t packet_type;
  96. uint8_t version; /* batman version field */
  97. uint8_t ttl;
  98. uint8_t msg_type; /* see ICMP message types above */
  99. uint8_t dst[6];
  100. uint8_t orig[6];
  101. uint16_t seqno;
  102. uint8_t uid;
  103. uint8_t reserved;
  104. } __packed;
  105. #define BAT_RR_LEN 16
  106. /* icmp_packet_rr must start with all fields from imcp_packet
  107. * as this is assumed by code that handles ICMP packets */
  108. struct icmp_packet_rr {
  109. uint8_t packet_type;
  110. uint8_t version; /* batman version field */
  111. uint8_t ttl;
  112. uint8_t msg_type; /* see ICMP message types above */
  113. uint8_t dst[6];
  114. uint8_t orig[6];
  115. uint16_t seqno;
  116. uint8_t uid;
  117. uint8_t rr_cur;
  118. uint8_t rr[BAT_RR_LEN][ETH_ALEN];
  119. } __packed;
  120. struct unicast_packet {
  121. uint8_t packet_type;
  122. uint8_t version; /* batman version field */
  123. uint8_t ttl;
  124. uint8_t ttvn; /* destination translation table version number */
  125. uint8_t dest[6];
  126. } __packed;
  127. struct unicast_frag_packet {
  128. uint8_t packet_type;
  129. uint8_t version; /* batman version field */
  130. uint8_t ttl;
  131. uint8_t ttvn; /* destination translation table version number */
  132. uint8_t dest[6];
  133. uint8_t flags;
  134. uint8_t align;
  135. uint8_t orig[6];
  136. uint16_t seqno;
  137. } __packed;
  138. struct bcast_packet {
  139. uint8_t packet_type;
  140. uint8_t version; /* batman version field */
  141. uint8_t ttl;
  142. uint8_t reserved;
  143. uint32_t seqno;
  144. uint8_t orig[6];
  145. } __packed;
  146. struct vis_packet {
  147. uint8_t packet_type;
  148. uint8_t version; /* batman version field */
  149. uint8_t ttl; /* TTL */
  150. uint8_t vis_type; /* which type of vis-participant sent this? */
  151. uint32_t seqno; /* sequence number */
  152. uint8_t entries; /* number of entries behind this struct */
  153. uint8_t reserved;
  154. uint8_t vis_orig[6]; /* originator that announces its neighbors */
  155. uint8_t target_orig[6]; /* who should receive this packet */
  156. uint8_t sender_orig[6]; /* who sent or rebroadcasted this packet */
  157. } __packed;
  158. struct tt_query_packet {
  159. uint8_t packet_type;
  160. uint8_t version; /* batman version field */
  161. uint8_t ttl;
  162. /* the flag field is a combination of:
  163. * - TT_REQUEST or TT_RESPONSE
  164. * - TT_FULL_TABLE */
  165. uint8_t flags;
  166. uint8_t dst[ETH_ALEN];
  167. uint8_t src[ETH_ALEN];
  168. /* the ttvn field is:
  169. * if TT_REQUEST: ttvn that triggered the
  170. * request
  171. * if TT_RESPONSE: new ttvn for the src
  172. * orig_node */
  173. uint8_t ttvn;
  174. /* tt_data field is:
  175. * if TT_REQUEST: crc associated with the
  176. * ttvn
  177. * if TT_RESPONSE: table_size */
  178. uint16_t tt_data;
  179. } __packed;
  180. struct roam_adv_packet {
  181. uint8_t packet_type;
  182. uint8_t version;
  183. uint8_t ttl;
  184. uint8_t reserved;
  185. uint8_t dst[ETH_ALEN];
  186. uint8_t src[ETH_ALEN];
  187. uint8_t client[ETH_ALEN];
  188. } __packed;
  189. struct tt_change {
  190. uint8_t flags;
  191. uint8_t addr[ETH_ALEN];
  192. } __packed;
  193. #endif /* _NET_BATMAN_ADV_PACKET_H_ */