1 /* $NetBSD: dhcp6.h,v 1.10 2015/07/09 10:15:34 roy Exp $ */
4 * dhcpcd - DHCP client daemon
5 * Copyright (c) 2006-2015 Roy Marples <roy@marples.name>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #define IN6ADDR_LINKLOCAL_ALLDHCP_INIT \
36 {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
37 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02 }}}
39 /* UDP port numbers for DHCP */
40 #define DHCP6_CLIENT_PORT 546
41 #define DHCP6_SERVER_PORT 547
43 /* DHCP message type */
44 #define DHCP6_SOLICIT 1
45 #define DHCP6_ADVERTISE 2
46 #define DHCP6_REQUEST 3
47 #define DHCP6_CONFIRM 4
49 #define DHCP6_REBIND 6
51 #define DHCP6_RELEASE 8
52 #define DHCP6_DECLINE 9
53 #define DHCP6_RECONFIGURE 10
54 #define DHCP6_INFORMATION_REQ 11
55 #define DHCP6_RELAY_FLOW 12
56 #define DHCP6_RELAY_REPL 13
57 #define DHCP6_RECONFIGURE_REQ 18
58 #define DHCP6_RECONFIGURE_REPLY 19
60 #define D6_OPTION_CLIENTID 1
61 #define D6_OPTION_SERVERID 2
62 #define D6_OPTION_IA_NA 3
63 #define D6_OPTION_IA_TA 4
64 #define D6_OPTION_ORO 6
65 #define D6_OPTION_IA_ADDR 5
66 #define D6_OPTION_PREFERENCE 7
67 #define D6_OPTION_ELAPSED 8
68 #define D6_OPTION_AUTH 11
69 #define D6_OPTION_UNICAST 12
70 #define D6_OPTION_STATUS_CODE 13
71 #define D6_OPTION_RAPID_COMMIT 14
72 #define D6_OPTION_VENDOR_CLASS 16
73 #define D6_OPTION_VENDOR_OPTS 17
74 #define D6_OPTION_INTERFACE_ID 18
75 #define D6_OPTION_RECONF_MSG 19
76 #define D6_OPTION_RECONF_ACCEPT 20
77 #define D6_OPTION_SIP_SERVERS_NAME 21
78 #define D6_OPTION_SIP_SERVERS_ADDRESS 22
79 #define D6_OPTION_DNS_SERVERS 23
80 #define D6_OPTION_DOMAIN_LIST 24
81 #define D6_OPTION_IA_PD 25
82 #define D6_OPTION_IAPREFIX 26
83 #define D6_OPTION_NIS_SERVERS 27
84 #define D6_OPTION_NISP_SERVERS 28
85 #define D6_OPTION_NIS_DOMAIN_NAME 29
86 #define D6_OPTION_NISP_DOMAIN_NAME 30
87 #define D6_OPTION_SNTP_SERVERS 31
88 #define D6_OPTION_INFO_REFRESH_TIME 32
89 #define D6_OPTION_BCMS_SERVER_D 33
90 #define D6_OPTION_BCMS_SERVER_A 34
91 #define D6_OPTION_FQDN 39
92 #define D6_OPTION_POSIX_TIMEZONE 41
93 #define D6_OPTION_TZDB_TIMEZONE 42
94 #define D6_OPTION_PD_EXCLUDE 67
95 #define D6_OPTION_SOL_MAX_RT 82
96 #define D6_OPTION_INF_MAX_RT 83
98 #define D6_FQDN_PTR 0x00
99 #define D6_FQDN_BOTH 0x01
100 #define D6_FQDN_NONE 0x04
105 struct dhcp6_message
{
108 /* followed by options */
111 struct dhcp6_option
{
114 /* followed by data */
117 #define D6_STATUS_OK 0
118 #define D6_STATUS_FAIL 1
119 #define D6_STATUS_NOADDR 2
120 #define D6_STATUS_NOBINDING 3
121 #define D6_STATUS_NOTONLINK 4
122 #define D6_STATUS_USEMULTICAST 5
124 #define SOL_MAX_DELAY 1
125 #define SOL_TIMEOUT 1
126 #define SOL_MAX_RT 3600 /* RFC7083 */
127 #define REQ_TIMEOUT 1
128 #define REQ_MAX_RT 30
129 #define REQ_MAX_RC 10
130 #define CNF_MAX_DELAY 1
131 #define CNF_TIMEOUT 1
133 #define CNF_MAX_RD 10
134 #define REN_TIMEOUT 10
135 #define REN_MAX_RT 600
136 #define REB_TIMEOUT 10
137 #define REB_MAX_RT 600
138 #define INF_MAX_DELAY 1
139 #define INF_TIMEOUT 1
140 #define INF_MAX_RT 3600 /* RFC7083 */
141 #define REL_TIMEOUT 1
143 #define DEC_TIMEOUT 1
145 #define REC_TIMEOUT 2
147 #define HOP_COUNT_LIMIT 32
150 #define IRT_DEFAULT 86400
151 #define IRT_MINIMUM 600
153 #define DHCP6_RAND_MIN -100
154 #define DHCP6_RAND_MAX 100
166 DH6S_RENEW_REQUESTED
,
175 struct timespec started
;
177 /* Message retransmission timings */
184 void (*MRCcallback
)(void *);
188 struct dhcp6_message
*send
;
190 struct dhcp6_message
*recv
;
192 struct dhcp6_message
*new;
194 struct dhcp6_message
*old
;
200 struct in6_addr unicast
;
201 struct ipv6_addrhead addrs
;
203 /* The +3 is for the possible .pd extension for prefix delegation */
204 char leasefile
[sizeof(LEASEFILE6
) + IF_NAMESIZE
+ (IF_SSIDSIZE
* 4) +3];
207 struct authstate auth
;
210 #define D6_STATE(ifp) \
211 ((struct dhcp6_state *)(ifp)->if_data[IF_DATA_DHCP6])
212 #define D6_CSTATE(ifp) \
213 ((const struct dhcp6_state *)(ifp)->if_data[IF_DATA_DHCP6])
214 #define D6_STATE_RUNNING(ifp) \
215 (D6_CSTATE((ifp)) && \
216 D6_CSTATE((ifp))->reason && dhcp6_dadcompleted((ifp)))
218 #define D6_FIRST_OPTION(m) \
219 ((struct dhcp6_option *) \
220 ((uint8_t *)(m) + sizeof(struct dhcp6_message)))
221 #define D6_NEXT_OPTION(o) \
222 ((struct dhcp6_option *) \
223 (((uint8_t *)o) + sizeof(struct dhcp6_option) + ntohs((o)->len)))
224 #define D6_OPTION_DATA(o) \
225 ((uint8_t *)(o) + sizeof(struct dhcp6_option))
226 #define D6_CFIRST_OPTION(m) \
227 ((const struct dhcp6_option *) \
228 ((const uint8_t *)(m) + sizeof(struct dhcp6_message)))
229 #define D6_CNEXT_OPTION(o) \
230 ((const struct dhcp6_option *) \
231 (((const uint8_t *)o) + sizeof(struct dhcp6_option) + ntohs((o)->len)))
232 #define D6_COPTION_DATA(o) \
233 ((const uint8_t *)(o) + sizeof(struct dhcp6_option))
236 void dhcp6_printoptions(const struct dhcpcd_ctx
*,
237 const struct dhcp_opt
*, size_t);
238 const struct ipv6_addr
*dhcp6_iffindaddr(const struct interface
*ifp
,
239 const struct in6_addr
*addr
, short flags
);
240 struct ipv6_addr
*dhcp6_findaddr(struct dhcpcd_ctx
*, const struct in6_addr
*,
242 size_t dhcp6_find_delegates(struct interface
*);
243 int dhcp6_has_public_addr(const struct interface
*);
244 int dhcp6_start(struct interface
*, enum DH6S
);
245 void dhcp6_reboot(struct interface
*);
246 ssize_t
dhcp6_env(char **, const char *, const struct interface
*,
247 const struct dhcp6_message
*, size_t);
248 void dhcp6_free(struct interface
*);
249 void dhcp6_handleifa(struct dhcpcd_ctx
*, int, const char *,
250 const struct in6_addr
*addr
, int);
251 int dhcp6_dadcompleted(const struct interface
*);
252 void dhcp6_drop(struct interface
*, const char *);
253 int dhcp6_dump(struct interface
*);
255 #define dhcp6_find_delegates(a) {}
256 #define dhcp6_start(a, b) (0)
257 #define dhcp6_reboot(a) {}
258 #define dhcp6_env(a, b, c, d, e) {}
259 #define dhcp6_free(a) {}
260 #define dhcp6_dadcompleted(a) (0)
261 #define dhcp6_drop(a, b) {}
262 #define dhcp6_dump(a) (-1)