dhcpv6.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /**
  2. * Copyright (C) 2012 Steven Barth <steven@midlink.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License version 2 for more details.
  12. *
  13. */
  14. #pragma once
  15. #include "odhcpd.h"
  16. #define ALL_DHCPV6_RELAYS "ff02::1:2"
  17. #define ALL_DHCPV6_SERVERS "ff05::1:3"
  18. #define DHCPV6_CLIENT_PORT 546
  19. #define DHCPV6_SERVER_PORT 547
  20. #define DHCPV6_MSG_SOLICIT 1
  21. #define DHCPV6_MSG_ADVERTISE 2
  22. #define DHCPV6_MSG_REQUEST 3
  23. #define DHCPV6_MSG_CONFIRM 4
  24. #define DHCPV6_MSG_RENEW 5
  25. #define DHCPV6_MSG_REBIND 6
  26. #define DHCPV6_MSG_REPLY 7
  27. #define DHCPV6_MSG_RELEASE 8
  28. #define DHCPV6_MSG_DECLINE 9
  29. #define DHCPV6_MSG_RECONFIGURE 10
  30. #define DHCPV6_MSG_INFORMATION_REQUEST 11
  31. #define DHCPV6_MSG_RELAY_FORW 12
  32. #define DHCPV6_MSG_RELAY_REPL 13
  33. #define DHCPV6_MSG_DHCPV4_QUERY 20
  34. #define DHCPV6_MSG_DHCPV4_RESPONSE 21
  35. #define DHCPV6_OPT_CLIENTID 1
  36. #define DHCPV6_OPT_SERVERID 2
  37. #define DHCPV6_OPT_IA_NA 3
  38. #define DHCPV6_OPT_IA_ADDR 5
  39. #define DHCPV6_OPT_ORO 6
  40. #define DHCPV6_OPT_STATUS 13
  41. #define DHCPV6_OPT_RELAY_MSG 9
  42. #define DHCPV6_OPT_AUTH 11
  43. #define DHCPV6_OPT_RAPID_COMMIT 14
  44. #define DHCPV6_OPT_USER_CLASS 15
  45. #define DHCPV6_OPT_INTERFACE_ID 18
  46. #define DHCPV6_OPT_RECONF_MSG 19
  47. #define DHCPV6_OPT_RECONF_ACCEPT 20
  48. #define DHCPV6_OPT_DNS_SERVERS 23
  49. #define DHCPV6_OPT_DNS_DOMAIN 24
  50. #define DHCPV6_OPT_IA_PD 25
  51. #define DHCPV6_OPT_IA_PREFIX 26
  52. #define DHCPV6_OPT_SNTP_SERVERS 31
  53. #define DHCPV6_OPT_INFO_REFRESH 32
  54. #define DHCPV6_OPT_FQDN 39
  55. #define DHCPV6_OPT_NTP_SERVERS 56
  56. #define DHCPV6_OPT_SOL_MAX_RT 82
  57. #define DHCPV6_OPT_INF_MAX_RT 83
  58. #define DHCPV6_OPT_DHCPV4_MSG 87
  59. #define DHCPV6_OPT_4O6_SERVER 88
  60. #define DHCPV6_DUID_VENDOR 2
  61. #define DHCPV6_STATUS_OK 0
  62. #define DHCPV6_STATUS_NOADDRSAVAIL 2
  63. #define DHCPV6_STATUS_NOBINDING 3
  64. #define DHCPV6_STATUS_NOTONLINK 4
  65. #define DHCPV6_STATUS_USEMULTICAST 5
  66. #define DHCPV6_STATUS_NOPREFIXAVAIL 6
  67. // I just remembered I have an old one lying around...
  68. #define DHCPV6_ENT_NO 30462
  69. #define DHCPV6_ENT_TYPE 1
  70. #define DHCPV6_HOP_COUNT_LIMIT 32
  71. #define DHCPV6_REC_TIMEOUT 2000 /* msec */
  72. #define DHCPV6_REC_MAX_RC 8
  73. struct dhcpv6_client_header {
  74. uint8_t msg_type;
  75. uint8_t transaction_id[3];
  76. } __attribute__((packed));
  77. struct dhcpv6_relay_header {
  78. uint8_t msg_type;
  79. uint8_t hop_count;
  80. struct in6_addr link_address;
  81. struct in6_addr peer_address;
  82. uint8_t options[];
  83. } __attribute__((packed));
  84. struct dhcpv6_relay_forward_envelope {
  85. uint8_t msg_type;
  86. uint8_t hop_count;
  87. struct in6_addr link_address;
  88. struct in6_addr peer_address;
  89. uint16_t interface_id_type;
  90. uint16_t interface_id_len;
  91. uint32_t interface_id_data;
  92. uint16_t relay_message_type;
  93. uint16_t relay_message_len;
  94. } __attribute__((packed));
  95. struct dhcpv6_auth_reconfigure {
  96. uint16_t type;
  97. uint16_t len;
  98. uint8_t protocol;
  99. uint8_t algorithm;
  100. uint8_t rdm;
  101. uint32_t replay[2];
  102. uint8_t reconf_type;
  103. uint8_t key[16];
  104. } _packed;
  105. struct dhcpv6_ia_hdr {
  106. uint16_t type;
  107. uint16_t len;
  108. uint32_t iaid;
  109. uint32_t t1;
  110. uint32_t t2;
  111. } _packed;
  112. struct dhcpv6_ia_prefix {
  113. uint16_t type;
  114. uint16_t len;
  115. uint32_t preferred_lt;
  116. uint32_t valid_lt;
  117. uint8_t prefix;
  118. struct in6_addr addr;
  119. } _packed;
  120. struct dhcpv6_ia_addr {
  121. uint16_t type;
  122. uint16_t len;
  123. struct in6_addr addr;
  124. uint32_t preferred_lt;
  125. uint32_t valid_lt;
  126. } _packed;
  127. struct dhcpv6_cer_id {
  128. uint16_t type;
  129. uint16_t len;
  130. uint16_t reserved;
  131. uint16_t auth_type;
  132. uint8_t auth[16];
  133. struct in6_addr addr;
  134. };
  135. #define dhcpv6_for_each_option(start, end, otype, olen, odata)\
  136. for (uint8_t *_o = (uint8_t*)(start); _o + 4 <= (end) &&\
  137. ((otype) = _o[0] << 8 | _o[1]) && ((odata) = (void*)&_o[4]) &&\
  138. ((olen) = _o[2] << 8 | _o[3]) + (odata) <= (end); \
  139. _o += 4 + (_o[2] << 8 | _o[3]))