1 | /* |
---|
2 | * dhcpcd - DHCP client daemon |
---|
3 | * Copyright (c) 2006-2014 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 | |
---|
56 | #define D6_OPTION_CLIENTID 1 |
---|
57 | #define D6_OPTION_SERVERID 2 |
---|
58 | #define D6_OPTION_IA_NA 3 |
---|
59 | #define D6_OPTION_IA_TA 4 |
---|
60 | #define D6_OPTION_ORO 6 |
---|
61 | #define D6_OPTION_IA_ADDR 5 |
---|
62 | #define D6_OPTION_PREFERENCE 7 |
---|
63 | #define D6_OPTION_ELAPSED 8 |
---|
64 | #define D6_OPTION_AUTH 11 |
---|
65 | #define D6_OPTION_UNICAST 12 |
---|
66 | #define D6_OPTION_STATUS_CODE 13 |
---|
67 | #define D6_OPTION_RAPID_COMMIT 14 |
---|
68 | #define D6_OPTION_VENDOR_CLASS 16 |
---|
69 | #define D6_OPTION_VENDOR_OPTS 17 |
---|
70 | #define D6_OPTION_SIP_SERVERS_NAME 21 |
---|
71 | #define D6_OPTION_SIP_SERVERS_ADDRESS 22 |
---|
72 | #define D6_OPTION_DNS_SERVERS 23 |
---|
73 | #define D6_OPTION_DOMAIN_LIST 24 |
---|
74 | #define D6_OPTION_IA_PD 25 |
---|
75 | #define D6_OPTION_IAPREFIX 26 |
---|
76 | #define D6_OPTION_NIS_SERVERS 27 |
---|
77 | #define D6_OPTION_NISP_SERVERS 28 |
---|
78 | #define D6_OPTION_NIS_DOMAIN_NAME 29 |
---|
79 | #define D6_OPTION_NISP_DOMAIN_NAME 30 |
---|
80 | #define D6_OPTION_SNTP_SERVERS 31 |
---|
81 | #define D6_OPTION_INFO_REFRESH_TIME 32 |
---|
82 | #define D6_OPTION_BCMS_SERVER_D 33 |
---|
83 | #define D6_OPTION_BCMS_SERVER_A 34 |
---|
84 | #define D6_OPTION_FQDN 39 |
---|
85 | #define D6_OPTION_POSIX_TIMEZONE 41 |
---|
86 | #define D6_OPTION_TZDB_TIMEZONE 42 |
---|
87 | |
---|
88 | #define D6_FQDN_PTR 0x00 |
---|
89 | #define D6_FQDN_BOTH 0x01 |
---|
90 | #define D6_FQDN_NONE 0x04 |
---|
91 | |
---|
92 | #include "dhcp.h" |
---|
93 | #include "ipv6.h" |
---|
94 | |
---|
95 | struct dhcp6_message { |
---|
96 | uint8_t type; |
---|
97 | uint8_t xid[3]; |
---|
98 | /* followed by options */ |
---|
99 | } __packed; |
---|
100 | |
---|
101 | struct dhcp6_option { |
---|
102 | uint16_t code; |
---|
103 | uint16_t len; |
---|
104 | /* followed by data */ |
---|
105 | } __packed; |
---|
106 | |
---|
107 | #define D6_STATUS_OK 0 |
---|
108 | #define D6_STATUS_FAIL 1 |
---|
109 | #define D6_STATUS_NOADDR 2 |
---|
110 | #define D6_STATUS_NOBINDING 3 |
---|
111 | #define D6_STATUS_NOTONLINK 4 |
---|
112 | #define D6_STATUS_USEMULTICAST 5 |
---|
113 | |
---|
114 | #define SOL_MAX_DELAY 1 |
---|
115 | #define SOL_TIMEOUT 1 |
---|
116 | #define SOL_MAX_RT 120 |
---|
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_RD 10 |
---|
124 | #define REN_TIMEOUT 10 |
---|
125 | #define REN_MAX_RT 600 |
---|
126 | #define REB_TIMEOUT 10 |
---|
127 | #define REB_MAX_RT 600 |
---|
128 | #define INF_MAX_DELAY 1 |
---|
129 | #define INF_TIMEOUT 1 |
---|
130 | #define INF_MAX_RT 120 |
---|
131 | #define REL_TIMEOUT 1 |
---|
132 | #define REL_MAX_RC 5 |
---|
133 | #define DEC_TIMEOUT 1 |
---|
134 | #define DEC_MAX_RC 5 |
---|
135 | #define REC_TIMEOUT 2 |
---|
136 | #define REC_MAX_RC 8 |
---|
137 | #define HOP_COUNT_LIMIT 32 |
---|
138 | |
---|
139 | /* RFC4242 3.1 */ |
---|
140 | #define IRT_DEFAULT 86400 |
---|
141 | #define IRT_MINIMUM 600 |
---|
142 | |
---|
143 | #define DHCP6_RAND_MIN -100 |
---|
144 | #define DHCP6_RAND_MAX 100 |
---|
145 | |
---|
146 | enum DH6S { |
---|
147 | DH6S_INIT, |
---|
148 | DH6S_DISCOVER, |
---|
149 | DH6S_REQUEST, |
---|
150 | DH6S_BOUND, |
---|
151 | DH6S_RENEW, |
---|
152 | DH6S_REBIND, |
---|
153 | DH6S_CONFIRM, |
---|
154 | DH6S_INFORM, |
---|
155 | DH6S_INFORMED, |
---|
156 | DH6S_RENEW_REQUESTED, |
---|
157 | DH6S_PROBE, |
---|
158 | DH6S_DELEGATED, |
---|
159 | DH6S_RELEASE |
---|
160 | }; |
---|
161 | |
---|
162 | struct dhcp6_state { |
---|
163 | enum DH6S state; |
---|
164 | time_t start_uptime; |
---|
165 | |
---|
166 | /* Message retransmission timings */ |
---|
167 | struct timeval RT; |
---|
168 | int IMD; |
---|
169 | int RTC; |
---|
170 | int IRT; |
---|
171 | int MRC; |
---|
172 | int MRT; |
---|
173 | void (*MRCcallback)(void *); |
---|
174 | |
---|
175 | struct dhcp6_message *send; |
---|
176 | size_t send_len; |
---|
177 | struct dhcp6_message *recv; |
---|
178 | size_t recv_len; |
---|
179 | struct dhcp6_message *new; |
---|
180 | size_t new_len; |
---|
181 | struct dhcp6_message *old; |
---|
182 | size_t old_len; |
---|
183 | |
---|
184 | uint32_t renew; |
---|
185 | uint32_t rebind; |
---|
186 | uint32_t expire; |
---|
187 | struct in6_addr unicast; |
---|
188 | struct ipv6_addrhead addrs; |
---|
189 | uint32_t lowpl; |
---|
190 | uint32_t sla; |
---|
191 | uint8_t sla_set; |
---|
192 | char leasefile[PATH_MAX]; |
---|
193 | const char *reason; |
---|
194 | |
---|
195 | struct authstate auth; |
---|
196 | }; |
---|
197 | |
---|
198 | #define D6_STATE(ifp) \ |
---|
199 | ((struct dhcp6_state *)(ifp)->if_data[IF_DATA_DHCP6]) |
---|
200 | #define D6_CSTATE(ifp) \ |
---|
201 | ((const struct dhcp6_state *)(ifp)->if_data[IF_DATA_DHCP6]) |
---|
202 | #define D6_STATE_RUNNING(ifp) (D6_STATE((ifp)) && D6_STATE((ifp))->new) |
---|
203 | #define D6_FIRST_OPTION(m) \ |
---|
204 | ((struct dhcp6_option *) \ |
---|
205 | ((uint8_t *)(m) + sizeof(struct dhcp6_message))) |
---|
206 | #define D6_NEXT_OPTION(o) \ |
---|
207 | ((struct dhcp6_option *) \ |
---|
208 | (((uint8_t *)o) + sizeof(struct dhcp6_option) + ntohs((o)->len))) |
---|
209 | #define D6_OPTION_DATA(o) \ |
---|
210 | ((uint8_t *)(o) + sizeof(struct dhcp6_option)) |
---|
211 | #define D6_CFIRST_OPTION(m) \ |
---|
212 | ((const struct dhcp6_option *) \ |
---|
213 | ((const uint8_t *)(m) + sizeof(struct dhcp6_message))) |
---|
214 | #define D6_CNEXT_OPTION(o) \ |
---|
215 | ((const struct dhcp6_option *) \ |
---|
216 | (((const uint8_t *)o) + sizeof(struct dhcp6_option) + ntohs((o)->len))) |
---|
217 | #define D6_COPTION_DATA(o) \ |
---|
218 | ((const uint8_t *)(o) + sizeof(struct dhcp6_option)) |
---|
219 | |
---|
220 | #ifdef INET6 |
---|
221 | extern struct dhcp_opt *dhcp6_opts; |
---|
222 | extern size_t dhcp6_opts_len; |
---|
223 | |
---|
224 | void dhcp6_printoptions(void); |
---|
225 | int dhcp6_addrexists(const struct ipv6_addr *); |
---|
226 | int dhcp6_find_delegates(struct interface *); |
---|
227 | int dhcp6_start(struct interface *, enum DH6S); |
---|
228 | void dhcp6_reboot(struct interface *); |
---|
229 | ssize_t dhcp6_env(char **, const char *, const struct interface *, |
---|
230 | const struct dhcp6_message *, ssize_t); |
---|
231 | void dhcp6_free(struct interface *); |
---|
232 | void dhcp6_handleifa(int, const char *, const struct in6_addr *addr, int); |
---|
233 | void dhcp6_drop(struct interface *, const char *); |
---|
234 | #else |
---|
235 | #define dhcp6_printoptions() |
---|
236 | #define dhcp6_addrexists(a) 0 |
---|
237 | #define dhcp6_find_delegates(a) 0 |
---|
238 | #define dhcp6_start(a, b) 0 |
---|
239 | #define dhcp6_reboot(a) |
---|
240 | #define dhcp6_env(a, b, c, d, e) |
---|
241 | #define dhcp6_free(a) |
---|
242 | #define dhcp6_drop(a, b) |
---|
243 | #endif |
---|
244 | |
---|
245 | #endif |
---|