NDPHeader.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef NDPHeader_H
  16. #define NDPHeader_H
  17. #include "util/Assert.h"
  18. #include "util/Endian.h"
  19. #include <stdint.h>
  20. struct NDPHeader_NeighborSolicitation {
  21. uint8_t oneThirtyFive;
  22. uint8_t zero;
  23. uint16_t checksum;
  24. uint32_t reserved;
  25. uint8_t targetAddr[16];
  26. };
  27. #define NDPHeader_NeighborSolicitation_SIZE 24
  28. Assert_compileTime(
  29. sizeof(struct NDPHeader_NeighborSolicitation) == NDPHeader_NeighborSolicitation_SIZE);
  30. struct NDPHeader_RouterSolicitation {
  31. uint8_t oneThirtyThree;
  32. uint8_t zero;
  33. uint16_t checksum;
  34. uint32_t reserved;
  35. };
  36. #define NDPHeader_RouterSolicitation_SIZE 8
  37. Assert_compileTime(
  38. sizeof(struct NDPHeader_RouterSolicitation) == NDPHeader_RouterSolicitation_SIZE);
  39. struct NDPHeader_NeighborAdvert {
  40. uint8_t oneThirtySix;
  41. uint8_t zero;
  42. uint16_t checksum;
  43. uint8_t bits;
  44. uint8_t reserved[3];
  45. uint8_t targetAddr[16];
  46. };
  47. #define NDPHeader_NeighborAdvert_SIZE 24
  48. Assert_compileTime(sizeof(struct NDPHeader_NeighborAdvert) == NDPHeader_NeighborAdvert_SIZE);
  49. #define NDPHeader_NeighborAdvert_bits_ROUTER (1<<7)
  50. #define NDPHeader_NeighborAdvert_bits_SOLICITED (1<<6)
  51. #define NDPHeader_NeighborAdvert_bits_OVERRIDE (1<<5)
  52. #define NDPHeader_MacOpt_type_SELF 1
  53. #define NDPHeader_MacOpt_type_TARGET 2
  54. struct NDPHeader_MacOpt {
  55. uint8_t type; // two for target addr and one for source addr
  56. uint8_t one; // length in 8 byte increments
  57. uint8_t mac[6];
  58. };
  59. #define NDPHeader_MacOpt_SIZE 8
  60. Assert_compileTime(sizeof(struct NDPHeader_MacOpt) == NDPHeader_MacOpt_SIZE);
  61. struct NDPHeader_RouterAdvert {
  62. uint8_t oneThirtyFour;
  63. uint8_t zero;
  64. uint16_t checksum;
  65. uint8_t currentHopLimit;
  66. uint8_t bits;
  67. uint16_t routerLifetime_be;
  68. uint32_t reachableTime_be;
  69. uint32_t retransTime_be;
  70. };
  71. #define NDPHeader_RouterAdvert_SIZE 16
  72. Assert_compileTime(sizeof(struct NDPHeader_RouterAdvert) == NDPHeader_RouterAdvert_SIZE);
  73. #define NDPHeader_RouterAdvert_bits_ADDRS_AVAILABLE (1<<7)
  74. #define NDPHeader_RouterAdvert_bits_OTHER_INFO_AVAILABLE (1<<6)
  75. struct NDPHeader_RouterAdvert_PrefixOpt {
  76. uint8_t three; // type
  77. uint8_t four; // length
  78. uint8_t prefixLen;
  79. uint8_t bits;
  80. uint32_t validLifetimeSeconds_be;
  81. uint32_t preferredLifetimeSeconds_be;
  82. uint32_t reservedTwo;
  83. uint8_t prefix[16];
  84. };
  85. #define NDPHeader_RouterAdvert_PrefixOpt_bits_ONLINK (1<<7)
  86. #define NDPHeader_RouterAdvert_PrefixOpt_bits_ADDRCONF (1<<6)
  87. #define NDPHeader_RouterAdvert_PrefixOpt_SIZE 32
  88. Assert_compileTime(
  89. sizeof(struct NDPHeader_RouterAdvert_PrefixOpt) == NDPHeader_RouterAdvert_PrefixOpt_SIZE);
  90. #endif