dhcpv6.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #define ALL_DHCPV6_RELAYS {{{0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  16. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02}}}
  17. #define ALL_DHCPV6_SERVERS {{{0xff, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  18. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03}}}
  19. #define DHCPV6_CLIENT_PORT 546
  20. #define DHCPV6_SERVER_PORT 547
  21. #define DHCPV6_MSG_SOLICIT 1
  22. #define DHCPV6_MSG_ADVERTISE 2
  23. #define DHCPV6_MSG_REQUEST 3
  24. #define DHCPV6_MSG_CONFIRM 4
  25. #define DHCPV6_MSG_RENEW 5
  26. #define DHCPV6_MSG_REBIND 6
  27. #define DHCPV6_MSG_REPLY 7
  28. #define DHCPV6_MSG_RELEASE 8
  29. #define DHCPV6_MSG_DECLINE 9
  30. #define DHCPV6_MSG_RECONFIGURE 10
  31. #define DHCPV6_MSG_INFORMATION_REQUEST 11
  32. #define DHCPV6_MSG_RELAY_FORW 12
  33. #define DHCPV6_MSG_RELAY_REPL 13
  34. #define DHCPV6_OPT_CLIENTID 1
  35. #define DHCPV6_OPT_SERVERID 2
  36. #define DHCPV6_OPT_IA_NA 3
  37. #define DHCPV6_OPT_IA_ADDR 5
  38. #define DHCPV6_OPT_STATUS 13
  39. #define DHCPV6_OPT_RELAY_MSG 9
  40. #define DHCPV6_OPT_AUTH 11
  41. #define DHCPV6_OPT_INTERFACE_ID 18
  42. #define DHCPV6_OPT_RECONF_MSG 19
  43. #define DHCPV6_OPT_RECONF_ACCEPT 20
  44. #define DHCPV6_OPT_DNS_SERVERS 23
  45. #define DHCPV6_OPT_DNS_DOMAIN 24
  46. #define DHCPV6_OPT_IA_PD 25
  47. #define DHCPV6_OPT_IA_PREFIX 26
  48. #define DHCPV6_OPT_INFO_REFRESH 32
  49. #define DHCPV6_OPT_FQDN 39
  50. #define DHCPV6_DUID_VENDOR 2
  51. #define DHCPV6_STATUS_OK 0
  52. #define DHCPV6_STATUS_NOADDRSAVAIL 2
  53. #define DHCPV6_STATUS_NOBINDING 3
  54. #define DHCPV6_STATUS_NOTONLINK 4
  55. #define DHCPV6_STATUS_NOPREFIXAVAIL 6
  56. // I just remembered I have an old one lying around...
  57. #define DHCPV6_ENT_NO 30462
  58. #define DHCPV6_ENT_TYPE 1
  59. #define DHCPV6_HOP_COUNT_LIMIT 32
  60. struct dhcpv6_client_header {
  61. uint8_t msg_type;
  62. uint8_t transaction_id[3];
  63. } __attribute__((packed));
  64. struct dhcpv6_relay_header {
  65. uint8_t msg_type;
  66. uint8_t hop_count;
  67. struct in6_addr link_address;
  68. struct in6_addr peer_address;
  69. uint8_t options[];
  70. } __attribute__((packed));
  71. struct dhcpv6_relay_forward_envelope {
  72. uint8_t msg_type;
  73. uint8_t hop_count;
  74. struct in6_addr link_address;
  75. struct in6_addr peer_address;
  76. uint16_t interface_id_type;
  77. uint16_t interface_id_len;
  78. uint32_t interface_id_data;
  79. uint16_t relay_message_type;
  80. uint16_t relay_message_len;
  81. } __attribute__((packed));
  82. struct dhcpv6_auth_reconfigure {
  83. uint16_t type;
  84. uint16_t len;
  85. uint8_t protocol;
  86. uint8_t algorithm;
  87. uint8_t rdm;
  88. uint32_t replay[2];
  89. uint8_t reconf_type;
  90. uint8_t key[16];
  91. } _packed;
  92. struct dhcpv6_ia_hdr {
  93. uint16_t type;
  94. uint16_t len;
  95. uint32_t iaid;
  96. uint32_t t1;
  97. uint32_t t2;
  98. } _packed;
  99. struct dhcpv6_ia_prefix {
  100. uint16_t type;
  101. uint16_t len;
  102. uint32_t preferred;
  103. uint32_t valid;
  104. uint8_t prefix;
  105. struct in6_addr addr;
  106. } _packed;
  107. struct dhcpv6_ia_addr {
  108. uint16_t type;
  109. uint16_t len;
  110. struct in6_addr addr;
  111. uint32_t preferred;
  112. uint32_t valid;
  113. } _packed;
  114. struct dhcpv6_assignment {
  115. struct list_head head;
  116. struct sockaddr_in6 peer;
  117. time_t valid_until;
  118. time_t reconf_sent;
  119. int reconf_cnt;
  120. char *hostname;
  121. uint8_t key[16];
  122. uint32_t assigned;
  123. uint32_t iaid;
  124. uint8_t mac[6];
  125. uint8_t length; // length == 128 -> IA_NA, length <= 64 -> IA_PD
  126. bool accept_reconf;
  127. uint8_t clid_len;
  128. uint8_t clid_data[];
  129. };
  130. #define dhcpv6_for_each_option(start, end, otype, olen, odata)\
  131. for (uint8_t *_o = (uint8_t*)(start); _o + 4 <= (end) &&\
  132. ((otype) = _o[0] << 8 | _o[1]) && ((odata) = (void*)&_o[4]) &&\
  133. ((olen) = _o[2] << 8 | _o[3]) + (odata) <= (end); \
  134. _o += 4 + (_o[2] << 8 | _o[3]))
  135. int dhcpv6_init_ia(struct interface *iface, int socket);
  136. size_t dhcpv6_handle_ia(uint8_t *buf, size_t buflen, struct interface *iface,
  137. const struct sockaddr_in6 *addr, const void *data, const uint8_t *end);
  138. int dhcpv6_ia_init(int dhcpv6_socket);
  139. int setup_dhcpv6_ia_interface(struct interface *iface, bool enable);
  140. void dhcpv6_write_statefile(void);