packet.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. };
  32. /* this file is included by batctl which needs these defines */
  33. #define COMPAT_VERSION 12
  34. enum batman_flags {
  35. PRIMARIES_FIRST_HOP = 1 << 4,
  36. VIS_SERVER = 1 << 5,
  37. DIRECTLINK = 1 << 6
  38. };
  39. /* ICMP message types */
  40. enum icmp_packettype {
  41. ECHO_REPLY = 0,
  42. DESTINATION_UNREACHABLE = 3,
  43. ECHO_REQUEST = 8,
  44. TTL_EXCEEDED = 11,
  45. PARAMETER_PROBLEM = 12
  46. };
  47. /* vis defines */
  48. enum vis_packettype {
  49. VIS_TYPE_SERVER_SYNC = 0,
  50. VIS_TYPE_CLIENT_UPDATE = 1
  51. };
  52. /* fragmentation defines */
  53. enum unicast_frag_flags {
  54. UNI_FRAG_HEAD = 1 << 0,
  55. UNI_FRAG_LARGETAIL = 1 << 1
  56. };
  57. struct batman_packet {
  58. uint8_t packet_type;
  59. uint8_t version; /* batman version field */
  60. uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
  61. uint8_t tq;
  62. uint32_t seqno;
  63. uint8_t orig[6];
  64. uint8_t prev_sender[6];
  65. uint8_t ttl;
  66. uint8_t num_tt;
  67. uint8_t gw_flags; /* flags related to gateway class */
  68. uint8_t align;
  69. } __packed;
  70. #define BAT_PACKET_LEN sizeof(struct batman_packet)
  71. struct icmp_packet {
  72. uint8_t packet_type;
  73. uint8_t version; /* batman version field */
  74. uint8_t msg_type; /* see ICMP message types above */
  75. uint8_t ttl;
  76. uint8_t dst[6];
  77. uint8_t orig[6];
  78. uint16_t seqno;
  79. uint8_t uid;
  80. } __packed;
  81. #define BAT_RR_LEN 16
  82. /* icmp_packet_rr must start with all fields from imcp_packet
  83. * as this is assumed by code that handles ICMP packets */
  84. struct icmp_packet_rr {
  85. uint8_t packet_type;
  86. uint8_t version; /* batman version field */
  87. uint8_t msg_type; /* see ICMP message types above */
  88. uint8_t ttl;
  89. uint8_t dst[6];
  90. uint8_t orig[6];
  91. uint16_t seqno;
  92. uint8_t uid;
  93. uint8_t rr_cur;
  94. uint8_t rr[BAT_RR_LEN][ETH_ALEN];
  95. } __packed;
  96. struct unicast_packet {
  97. uint8_t packet_type;
  98. uint8_t version; /* batman version field */
  99. uint8_t dest[6];
  100. uint8_t ttl;
  101. } __packed;
  102. struct unicast_frag_packet {
  103. uint8_t packet_type;
  104. uint8_t version; /* batman version field */
  105. uint8_t dest[6];
  106. uint8_t ttl;
  107. uint8_t flags;
  108. uint8_t orig[6];
  109. uint16_t seqno;
  110. } __packed;
  111. struct bcast_packet {
  112. uint8_t packet_type;
  113. uint8_t version; /* batman version field */
  114. uint8_t orig[6];
  115. uint8_t ttl;
  116. uint32_t seqno;
  117. } __packed;
  118. struct vis_packet {
  119. uint8_t packet_type;
  120. uint8_t version; /* batman version field */
  121. uint8_t vis_type; /* which type of vis-participant sent this? */
  122. uint8_t entries; /* number of entries behind this struct */
  123. uint32_t seqno; /* sequence number */
  124. uint8_t ttl; /* TTL */
  125. uint8_t vis_orig[6]; /* originator that announces its neighbors */
  126. uint8_t target_orig[6]; /* who should receive this packet */
  127. uint8_t sender_orig[6]; /* who sent or rebroadcasted this packet */
  128. } __packed;
  129. #endif /* _NET_BATMAN_ADV_PACKET_H_ */