xref: /dragonfly/contrib/dhcpcd/src/dhcp6.h (revision 6e316fcd)
1 /*
2  * dhcpcd - DHCP client daemon
3  * Copyright (c) 2006-2018 Roy Marples <roy@marples.name>
4  * All rights reserved
5 
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #ifndef DHCP6_H
29 #define DHCP6_H
30 
31 #include "dhcpcd.h"
32 
33 #define IN6ADDR_LINKLOCAL_ALLDHCP_INIT \
34 	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
35 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02 }}}
36 
37 /* UDP port numbers for DHCP */
38 #define DHCP6_CLIENT_PORT	546
39 #define DHCP6_SERVER_PORT	547
40 
41 /* DHCP message type */
42 #define DHCP6_SOLICIT		1
43 #define DHCP6_ADVERTISE		2
44 #define DHCP6_REQUEST		3
45 #define DHCP6_CONFIRM		4
46 #define DHCP6_RENEW		5
47 #define DHCP6_REBIND		6
48 #define DHCP6_REPLY		7
49 #define DHCP6_RELEASE		8
50 #define DHCP6_DECLINE		9
51 #define DHCP6_RECONFIGURE	10
52 #define DHCP6_INFORMATION_REQ	11
53 #define DHCP6_RELAY_FLOW	12
54 #define DHCP6_RELAY_REPL	13
55 #define DHCP6_RECONFIGURE_REQ	18
56 #define DHCP6_RECONFIGURE_REPLY	19
57 
58 #define D6_OPTION_CLIENTID		1
59 #define D6_OPTION_SERVERID		2
60 #define D6_OPTION_IA_NA			3
61 #define D6_OPTION_IA_TA			4
62 #define D6_OPTION_ORO			6
63 #define D6_OPTION_IA_ADDR		5
64 #define D6_OPTION_PREFERENCE		7
65 #define D6_OPTION_ELAPSED		8
66 #define D6_OPTION_AUTH			11
67 #define D6_OPTION_UNICAST		12
68 #define D6_OPTION_STATUS_CODE		13
69 #define D6_OPTION_RAPID_COMMIT		14
70 #define D6_OPTION_USER_CLASS		15
71 #define D6_OPTION_VENDOR_CLASS		16
72 #define D6_OPTION_VENDOR_OPTS		17
73 #define D6_OPTION_INTERFACE_ID		18
74 #define D6_OPTION_RECONF_MSG		19
75 #define D6_OPTION_RECONF_ACCEPT		20
76 #define D6_OPTION_SIP_SERVERS_NAME	21
77 #define D6_OPTION_SIP_SERVERS_ADDRESS	22
78 #define D6_OPTION_DNS_SERVERS		23
79 #define D6_OPTION_DOMAIN_LIST		24
80 #define D6_OPTION_IA_PD			25
81 #define D6_OPTION_IAPREFIX		26
82 #define D6_OPTION_NIS_SERVERS		27
83 #define D6_OPTION_NISP_SERVERS		28
84 #define D6_OPTION_NIS_DOMAIN_NAME	29
85 #define D6_OPTION_NISP_DOMAIN_NAME	30
86 #define D6_OPTION_SNTP_SERVERS		31
87 #define D6_OPTION_INFO_REFRESH_TIME	32
88 #define D6_OPTION_BCMS_SERVER_D		33
89 #define D6_OPTION_BCMS_SERVER_A		34
90 #define D6_OPTION_FQDN			39
91 #define D6_OPTION_POSIX_TIMEZONE	41
92 #define D6_OPTION_TZDB_TIMEZONE		42
93 #define D6_OPTION_PD_EXCLUDE		67
94 #define D6_OPTION_SOL_MAX_RT		82
95 #define D6_OPTION_INF_MAX_RT		83
96 #define	D6_OPTION_MUDURL		112
97 
98 #define D6_FQDN_PTR	0x00
99 #define D6_FQDN_BOTH	0x01
100 #define D6_FQDN_NONE	0x04
101 
102 #include "dhcp.h"
103 #include "ipv6.h"
104 
105 #define D6_STATUS_OK		0
106 #define D6_STATUS_FAIL		1
107 #define D6_STATUS_NOADDR	2
108 #define D6_STATUS_NOBINDING	3
109 #define D6_STATUS_NOTONLINK	4
110 #define D6_STATUS_USEMULTICAST	5
111 
112 #define	SOL_MAX_DELAY		1
113 #define	SOL_TIMEOUT		1
114 #define	SOL_MAX_RT		3600 /* RFC7083 */
115 #define	SOL_MAX_RC		0
116 #define	REQ_MAX_DELAY		0
117 #define	REQ_TIMEOUT		1
118 #define	REQ_MAX_RT		30
119 #define	REQ_MAX_RC		10
120 #define	CNF_MAX_DELAY		1
121 #define	CNF_TIMEOUT		1
122 #define	CNF_MAX_RT		4
123 #define	CNF_MAX_RC		0
124 #define	CNF_MAX_RD		10
125 #define	REN_MAX_DELAY		0
126 #define	REN_TIMEOUT		10
127 #define	REN_MAX_RT		600
128 #define	REB_MAX_DELAY		0
129 #define	REB_TIMEOUT		10
130 #define	REB_MAX_RT		600
131 #define	INF_MAX_DELAY		1
132 #define	INF_TIMEOUT		1
133 #define	INF_MAX_RD		CNF_MAX_RD /* NOT RFC defined */
134 #define	INF_MAX_RT		3600 /* RFC7083 */
135 #define	REL_MAX_DELAY		0
136 #define	REL_TIMEOUT		1
137 #define	REL_MAX_RT		0
138 #define	REL_MAX_RC		5
139 #define	DEC_MAX_DELAY		0
140 #define	DEC_TIMEOUT		1
141 #define	DEC_MAX_RC		5
142 #define	REC_MAX_DELAY		0
143 #define	REC_TIMEOUT		2
144 #define	REC_MAX_RC		8
145 #define	HOP_COUNT_LIMIT		32
146 
147 /* RFC4242 3.1 */
148 #define IRT_DEFAULT		86400
149 #define IRT_MINIMUM		600
150 
151 #define DHCP6_RAND_MIN		-100
152 #define DHCP6_RAND_MAX		100
153 
154 enum DH6S {
155 	DH6S_INIT,
156 	DH6S_DISCOVER,
157 	DH6S_REQUEST,
158 	DH6S_BOUND,
159 	DH6S_RENEW,
160 	DH6S_REBIND,
161 	DH6S_CONFIRM,
162 	DH6S_INFORM,
163 	DH6S_INFORMED,
164 	DH6S_RENEW_REQUESTED,
165 	DH6S_PROBE,
166 	DH6S_DELEGATED,
167 	DH6S_TIMEDOUT,
168 	DH6S_ITIMEDOUT,
169 	DH6S_RELEASE,
170 	DH6S_RELEASED
171 };
172 
173 struct dhcp6_state {
174 	enum DH6S state;
175 	struct timespec started;
176 
177 	/* Message retransmission timings */
178 	struct timespec RT;
179 	unsigned int IMD;
180 	unsigned int RTC;
181 	time_t IRT;
182 	unsigned int MRC;
183 	time_t MRT;
184 	void (*MRCcallback)(void *);
185 	time_t sol_max_rt;
186 	time_t inf_max_rt;
187 
188 	struct dhcp6_message *send;
189 	size_t send_len;
190 	struct dhcp6_message *recv;
191 	size_t recv_len;
192 	struct dhcp6_message *new;
193 	size_t new_len;
194 	struct dhcp6_message *old;
195 	size_t old_len;
196 
197 	struct timespec acquired;
198 	uint32_t renew;
199 	uint32_t rebind;
200 	uint32_t expire;
201 	struct in6_addr unicast;
202 	struct ipv6_addrhead addrs;
203 	uint32_t lowpl;
204 	/* The +3 is for the possible .pd extension for prefix delegation */
205 	char leasefile[sizeof(LEASEFILE6) + IF_NAMESIZE + (IF_SSIDLEN * 4) +3];
206 	const char *reason;
207 
208 	struct authstate auth;
209 };
210 
211 #define D6_STATE(ifp)							       \
212 	((struct dhcp6_state *)(ifp)->if_data[IF_DATA_DHCP6])
213 #define D6_CSTATE(ifp)							       \
214 	((const struct dhcp6_state *)(ifp)->if_data[IF_DATA_DHCP6])
215 #define D6_STATE_RUNNING(ifp)						       \
216 	(D6_CSTATE((ifp)) &&						       \
217 	D6_CSTATE((ifp))->reason && dhcp6_dadcompleted((ifp)))
218 
219 #ifdef DHCP6
220 void dhcp6_printoptions(const struct dhcpcd_ctx *,
221     const struct dhcp_opt *, size_t);
222 const struct ipv6_addr *dhcp6_iffindaddr(const struct interface *ifp,
223     const struct in6_addr *addr, unsigned int flags);
224 struct ipv6_addr *dhcp6_findaddr(struct dhcpcd_ctx *, const struct in6_addr *,
225     unsigned int);
226 size_t dhcp6_find_delegates(struct interface *);
227 int dhcp6_start(struct interface *, enum DH6S);
228 void dhcp6_reboot(struct interface *);
229 void dhcp6_renew(struct interface *);
230 ssize_t dhcp6_env(char **, const char *, const struct interface *,
231     const struct dhcp6_message *, size_t);
232 void dhcp6_free(struct interface *);
233 void dhcp6_handleifa(int, struct ipv6_addr *, pid_t);
234 int dhcp6_dadcompleted(const struct interface *);
235 void dhcp6_drop(struct interface *, const char *);
236 void dhcp6_dropnondelegates(struct interface *ifp);
237 int dhcp6_dump(struct interface *);
238 #else
239 #define dhcp6_printoptions(a, b, c) {}
240 #define dhcp6_iffindaddr(a, b, c) (NULL)
241 #define dhcp6_findaddr(a, b, c) (NULL)
242 #define dhcp6_find_delegates(a) {}
243 #define dhcp6_start(a, b) (0)
244 #define dhcp6_reboot(a) {}
245 #define dhcp6_renew(a) {}
246 #define dhcp6_env(a, b, c, d, e) (0)
247 #define dhcp6_free(a) {}
248 #define dhcp6_dadcompleted(a) (0)
249 #define dhcp6_drop(a, b) {}
250 #define dhcp6_dropnondelegates(a) {}
251 #define dhcp6_dump(a) (-1)
252 #endif
253 
254 #endif
255