packet.h 3.6 KB

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