dhcpv4: DHCP pool size is off-by-one
[project/odhcpd.git] / src / dhcpv4.c
1 /**
2 * Copyright (C) 2012-2013 Steven Barth <steven@midlink.org>
3 * Copyright (C) 2016 Hans Dedecker <dedeckeh@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License v2 as published by
7 * the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 *
15 */
16
17 #include <time.h>
18 #include <errno.h>
19 #include <fcntl.h>
20 #include <unistd.h>
21 #include <stddef.h>
22 #include <stdlib.h>
23 #include <resolv.h>
24 #include <limits.h>
25 #include <net/if.h>
26 #include <net/if_arp.h>
27 #include <netinet/ip.h>
28 #include <sys/ioctl.h>
29 #include <sys/timerfd.h>
30 #include <arpa/inet.h>
31
32 #include <libubox/md5.h>
33
34 #include "odhcpd.h"
35 #include "dhcpv4.h"
36 #include "dhcpv6.h"
37
38 #define PACKET_SIZE(start, end) (((uint8_t *)end - (uint8_t *)start) < DHCPV4_MIN_PACKET_SIZE ? \
39 DHCPV4_MIN_PACKET_SIZE : (uint8_t *)end - (uint8_t *)start)
40
41 static void dhcpv4_netevent_cb(unsigned long event, struct netevent_handler_info *info);
42 static int setup_dhcpv4_addresses(struct interface *iface);
43 static bool addr_is_fr_ip(struct interface *iface, struct in_addr *addr);
44 static void valid_until_cb(struct uloop_timeout *event);
45 static void handle_addrlist_change(struct interface *iface);
46 static void dhcpv4_fr_start(struct dhcp_assignment *a);
47 static void dhcpv4_fr_rand_delay(struct dhcp_assignment *a);
48 static void dhcpv4_fr_stop(struct dhcp_assignment *a);
49 static void handle_dhcpv4(void *addr, void *data, size_t len,
50 struct interface *iface, void *dest_addr);
51 static struct dhcp_assignment* dhcpv4_lease(struct interface *iface,
52 enum dhcpv4_msg msg, const uint8_t *mac, const uint32_t reqaddr,
53 uint32_t *leasetime, const char *hostname, const size_t hostname_len,
54 const bool accept_fr_nonce, bool *incl_fr_opt, uint32_t *fr_serverid,
55 const char *reqopts, const size_t reqopts_len);
56
57 static struct netevent_handler dhcpv4_netevent_handler = { .cb = dhcpv4_netevent_cb, };
58 static struct uloop_timeout valid_until_timeout = {.cb = valid_until_cb};
59 static uint32_t serial = 0;
60
61 struct odhcpd_ref_ip {
62 struct list_head head;
63 int ref_cnt;
64 struct odhcpd_ipaddr addr;
65 };
66
67 /* Create socket and register events */
68 int dhcpv4_init(void)
69 {
70 uloop_timeout_set(&valid_until_timeout, 1000);
71 netlink_add_netevent_handler(&dhcpv4_netevent_handler);
72
73 return 0;
74 }
75
76 int dhcpv4_setup_interface(struct interface *iface, bool enable)
77 {
78 int ret = 0;
79
80 if (iface->dhcpv4_event.uloop.fd >= 0) {
81 uloop_fd_delete(&iface->dhcpv4_event.uloop);
82 close(iface->dhcpv4_event.uloop.fd);
83 iface->dhcpv4_event.uloop.fd = -1;
84 }
85
86 if (iface->dhcpv4 && enable) {
87 struct sockaddr_in bind_addr = {AF_INET, htons(DHCPV4_SERVER_PORT),
88 {INADDR_ANY}, {0}};
89 int val = 1;
90
91 if (!iface->dhcpv4_assignments.next)
92 INIT_LIST_HEAD(&iface->dhcpv4_assignments);
93
94 if (!iface->dhcpv4_fr_ips.next)
95 INIT_LIST_HEAD(&iface->dhcpv4_fr_ips);
96
97 iface->dhcpv4_event.uloop.fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
98 if (iface->dhcpv4_event.uloop.fd < 0) {
99 syslog(LOG_ERR, "socket(AF_INET): %m");
100 ret = -1;
101 goto out;
102 }
103
104 /* Basic IPv4 configuration */
105 if (setsockopt(iface->dhcpv4_event.uloop.fd, SOL_SOCKET, SO_REUSEADDR,
106 &val, sizeof(val)) < 0) {
107 syslog(LOG_ERR, "setsockopt(SO_REUSEADDR): %m");
108 ret = -1;
109 goto out;
110 }
111
112 if (setsockopt(iface->dhcpv4_event.uloop.fd, SOL_SOCKET, SO_BROADCAST,
113 &val, sizeof(val)) < 0) {
114 syslog(LOG_ERR, "setsockopt(SO_BROADCAST): %m");
115 ret = -1;
116 goto out;
117 }
118
119 if (setsockopt(iface->dhcpv4_event.uloop.fd, IPPROTO_IP, IP_PKTINFO,
120 &val, sizeof(val)) < 0) {
121 syslog(LOG_ERR, "setsockopt(IP_PKTINFO): %m");
122 ret = -1;
123 goto out;
124 }
125
126 val = IPTOS_PREC_INTERNETCONTROL;
127 if (setsockopt(iface->dhcpv4_event.uloop.fd, IPPROTO_IP, IP_TOS,
128 &val, sizeof(val)) < 0) {
129 syslog(LOG_ERR, "setsockopt(IP_TOS): %m");
130 ret = -1;
131 goto out;
132 }
133
134 val = IP_PMTUDISC_DONT;
135 if (setsockopt(iface->dhcpv4_event.uloop.fd, IPPROTO_IP, IP_MTU_DISCOVER,
136 &val, sizeof(val)) < 0) {
137 syslog(LOG_ERR, "setsockopt(IP_MTU_DISCOVER): %m");
138 ret = -1;
139 goto out;
140 }
141
142 if (setsockopt(iface->dhcpv4_event.uloop.fd, SOL_SOCKET, SO_BINDTODEVICE,
143 iface->ifname, strlen(iface->ifname)) < 0) {
144 syslog(LOG_ERR, "setsockopt(SO_BINDTODEVICE): %m");
145 ret = -1;
146 goto out;
147 }
148
149 if (bind(iface->dhcpv4_event.uloop.fd, (struct sockaddr*)&bind_addr,
150 sizeof(bind_addr)) < 0) {
151 syslog(LOG_ERR, "bind(): %m");
152 ret = -1;
153 goto out;
154 }
155
156 if (setup_dhcpv4_addresses(iface) < 0) {
157 ret = -1;
158 goto out;
159 }
160
161 iface->dhcpv4_event.handle_dgram = handle_dhcpv4;
162 odhcpd_register(&iface->dhcpv4_event);
163 } else if (iface->dhcpv4_assignments.next) {
164 while (!list_empty(&iface->dhcpv4_assignments))
165 free_assignment(list_first_entry(&iface->dhcpv4_assignments,
166 struct dhcp_assignment, head));
167 }
168
169 out:
170 if (ret < 0 && iface->dhcpv4_event.uloop.fd >= 0) {
171 close(iface->dhcpv4_event.uloop.fd);
172 iface->dhcpv4_event.uloop.fd = -1;
173 }
174
175 return ret;
176 }
177
178
179 static void dhcpv4_netevent_cb(unsigned long event, struct netevent_handler_info *info)
180 {
181 struct interface *iface = info->iface;
182
183 if (!iface || iface->dhcpv4 == MODE_DISABLED)
184 return;
185
186 switch (event) {
187 case NETEV_IFINDEX_CHANGE:
188 dhcpv4_setup_interface(iface, true);
189 break;
190 case NETEV_ADDRLIST_CHANGE:
191 handle_addrlist_change(iface);
192 break;
193 default:
194 break;
195 }
196 }
197
198 static struct dhcp_assignment *find_assignment_by_hwaddr(struct interface *iface, const uint8_t *hwaddr)
199 {
200 struct dhcp_assignment *a;
201
202 list_for_each_entry(a, &iface->dhcpv4_assignments, head)
203 if (!memcmp(a->hwaddr, hwaddr, 6))
204 return a;
205
206 return NULL;
207 }
208
209 static int setup_dhcpv4_addresses(struct interface *iface)
210 {
211 iface->dhcpv4_start_ip.s_addr = INADDR_ANY;
212 iface->dhcpv4_end_ip.s_addr = INADDR_ANY;
213 iface->dhcpv4_local.s_addr = INADDR_ANY;
214 iface->dhcpv4_bcast.s_addr = INADDR_ANY;
215 iface->dhcpv4_mask.s_addr = INADDR_ANY;
216
217 /* Sanity checks */
218 if (iface->dhcpv4_start.s_addr & htonl(0xffff0000) ||
219 iface->dhcpv4_end.s_addr & htonl(0xffff0000) ||
220 ntohl(iface->dhcpv4_start.s_addr) > ntohl(iface->dhcpv4_end.s_addr)) {
221 syslog(LOG_ERR, "Invalid DHCP range for %s", iface->name);
222 return -1;
223 }
224
225 if (!iface->addr4_len) {
226 syslog(LOG_ERR, "No network(s) available on %s", iface->name);
227 return -1;
228 }
229
230 uint32_t start = ntohl(iface->dhcpv4_start.s_addr);
231 uint32_t end = ntohl(iface->dhcpv4_end.s_addr);
232
233 for (size_t i = 0; i < iface->addr4_len && start && end; i++) {
234 struct in_addr *addr = &iface->addr4[i].addr.in;
235 struct in_addr mask;
236
237 if (addr_is_fr_ip(iface, addr))
238 continue;
239
240 odhcpd_bitlen2netmask(false, iface->addr4[i].prefix, &mask);
241 if ((start & ntohl(~mask.s_addr)) == start &&
242 (end & ntohl(~mask.s_addr)) == end) {
243 iface->dhcpv4_start_ip.s_addr = htonl(start) |
244 (addr->s_addr & mask.s_addr);
245 iface->dhcpv4_end_ip.s_addr = htonl(end) |
246 (addr->s_addr & mask.s_addr);
247 iface->dhcpv4_local = *addr;
248 iface->dhcpv4_bcast = iface->addr4[i].broadcast;
249 iface->dhcpv4_mask = mask;
250 return 0;
251 }
252 }
253
254 /* Don't allocate IP range for subnets bigger than 28 */
255 if (iface->addr4[0].prefix > 28) {
256 syslog(LOG_ERR, "Auto allocation of DHCP range fails on %s", iface->name);
257 return -1;
258 }
259
260 iface->dhcpv4_local = iface->addr4[0].addr.in;
261 iface->dhcpv4_bcast = iface->addr4[0].broadcast;
262 odhcpd_bitlen2netmask(false, iface->addr4[0].prefix, &iface->dhcpv4_mask);
263 end = start = iface->dhcpv4_local.s_addr & iface->dhcpv4_mask.s_addr;
264
265 /* Auto allocate ranges */
266 if (ntohl(iface->dhcpv4_mask.s_addr) <= 0xffffff00) { /* /24, 150 of 256, [100..249] */
267 iface->dhcpv4_start_ip.s_addr = start | htonl(100);
268 iface->dhcpv4_end_ip.s_addr = end | htonl(100 + 150 - 1);
269 } else if (ntohl(iface->dhcpv4_mask.s_addr) <= 0xffffff80) { /* /25, 100 of 128, [20..119] */
270 iface->dhcpv4_start_ip.s_addr = start | htonl(20);
271 iface->dhcpv4_end_ip.s_addr = end | htonl(20 + 100 - 1);
272 } else if (ntohl(iface->dhcpv4_mask.s_addr) <= 0xffffffc0) { /* /26, 50 of 64, [10..59] */
273 iface->dhcpv4_start_ip.s_addr = start | htonl(10);
274 iface->dhcpv4_end_ip.s_addr = end | htonl(10 + 50 - 1);
275 } else if (ntohl(iface->dhcpv4_mask.s_addr) <= 0xffffffe0) { /* /27, 20 of 32, [10..29] */
276 iface->dhcpv4_start_ip.s_addr = start | htonl(10);
277 iface->dhcpv4_end_ip.s_addr = end | htonl(10 + 20 - 1);
278 } else { /* /28, 10 of 16, [3..12] */
279 iface->dhcpv4_start_ip.s_addr = start | htonl(3);
280 iface->dhcpv4_end_ip.s_addr = end | htonl(3 + 10 - 1);
281 }
282
283 return 0;
284 }
285
286 static void inc_ref_cnt_ip(struct odhcpd_ref_ip **ptr, struct odhcpd_ref_ip *ip)
287 {
288 *ptr = ip;
289 ip->ref_cnt++;
290 }
291
292 static void decr_ref_cnt_ip(struct odhcpd_ref_ip **ptr, struct interface *iface)
293 {
294 struct odhcpd_ref_ip *ip = *ptr;
295
296 if (--ip->ref_cnt == 0) {
297 netlink_setup_addr(&ip->addr, iface->ifindex, false, false);
298
299 list_del(&ip->head);
300 free(ip);
301 }
302
303 *ptr = NULL;
304 }
305
306 static bool addr_is_fr_ip(struct interface *iface, struct in_addr *addr)
307 {
308 struct odhcpd_ref_ip *p;
309
310 list_for_each_entry(p, &iface->dhcpv4_fr_ips, head) {
311 if (addr->s_addr == p->addr.addr.in.s_addr)
312 return true;
313 }
314
315 return false;
316 }
317
318 static bool leases_require_fr(struct interface *iface, struct odhcpd_ipaddr *addr,
319 uint32_t mask)
320 {
321 struct dhcp_assignment *a = NULL;
322 struct odhcpd_ref_ip *fr_ip = NULL;
323
324 list_for_each_entry(a, &iface->dhcpv4_assignments, head) {
325 if ((a->accept_fr_nonce || iface->dhcpv4_forcereconf) &&
326 !a->fr_ip &&
327 ((a->addr & mask) == (addr->addr.in.s_addr & mask))) {
328 if (!fr_ip) {
329 fr_ip = calloc(1, sizeof(*fr_ip));
330 if (!fr_ip)
331 break;
332
333 list_add(&fr_ip->head, &iface->dhcpv4_fr_ips);
334 fr_ip->addr = *addr;
335 }
336 inc_ref_cnt_ip(&a->fr_ip, fr_ip);
337 }
338 }
339
340 return fr_ip ? true : false;
341 }
342
343 static void valid_until_cb(struct uloop_timeout *event)
344 {
345 struct interface *iface;
346 time_t now = odhcpd_time();
347
348 avl_for_each_element(&interfaces, iface, avl) {
349 if (iface->dhcpv4 != MODE_SERVER || iface->dhcpv4_assignments.next == NULL)
350 continue;
351
352 struct dhcp_assignment *a, *n;
353 list_for_each_entry_safe(a, n, &iface->dhcpv4_assignments, head) {
354 if (!INFINITE_VALID(a->valid_until) && a->valid_until < now)
355 free_assignment(a);
356 }
357 }
358 uloop_timeout_set(event, 1000);
359 }
360
361 static void handle_addrlist_change(struct interface *iface)
362 {
363 struct odhcpd_ipaddr ip;
364 struct odhcpd_ref_ip *a;
365 struct dhcp_assignment *c;
366 uint32_t mask = iface->dhcpv4_mask.s_addr;
367
368 memset(&ip, 0, sizeof(ip));
369 ip.addr.in = iface->dhcpv4_local;
370 ip.prefix = odhcpd_netmask2bitlen(false, &iface->dhcpv4_mask);
371 ip.broadcast = iface->dhcpv4_bcast;
372
373 setup_dhcpv4_addresses(iface);
374
375 if ((ip.addr.in.s_addr & mask) ==
376 (iface->dhcpv4_local.s_addr & iface->dhcpv4_mask.s_addr))
377 return;
378
379 if (ip.addr.in.s_addr && !leases_require_fr(iface, &ip, mask))
380 return;
381
382 if (iface->dhcpv4_local.s_addr == INADDR_ANY || list_empty(&iface->dhcpv4_fr_ips))
383 return;
384
385 a = list_first_entry(&iface->dhcpv4_fr_ips, struct odhcpd_ref_ip, head);
386
387 if (netlink_setup_addr(&a->addr, iface->ifindex, false, true)) {
388 syslog(LOG_ERR, "Failed to add ip address on %s", iface->name);
389 return;
390 }
391
392 list_for_each_entry(c, &iface->dhcpv4_assignments, head) {
393 if ((c->flags & OAF_BOUND) && c->fr_ip && !c->fr_cnt) {
394 if (c->accept_fr_nonce || iface->dhcpv4_forcereconf)
395 dhcpv4_fr_rand_delay(c);
396 else
397 dhcpv4_fr_stop(c);
398 }
399 }
400 }
401
402 static char *dhcpv4_msg_to_string(uint8_t reqmsg)
403 {
404 switch (reqmsg) {
405 case (DHCPV4_MSG_DISCOVER):
406 return "DHCPV4_MSG_DISCOVER";
407 case (DHCPV4_MSG_OFFER):
408 return "DHCPV4_MSG_OFFER";
409 case (DHCPV4_MSG_REQUEST):
410 return "DHCPV4_MSG_REQUEST";
411 case (DHCPV4_MSG_DECLINE):
412 return "DHCPV4_MSG_DECLINE";
413 case (DHCPV4_MSG_ACK):
414 return "DHCPV4_MSG_ACK";
415 case (DHCPV4_MSG_NAK):
416 return "DHCPV4_MSG_NAK";
417 case (DHCPV4_MSG_RELEASE):
418 return "DHCPV4_MSG_RELEASE";
419 case (DHCPV4_MSG_INFORM):
420 return "DHCPV4_MSG_INFORM";
421 case (DHCPV4_MSG_FORCERENEW):
422 return "DHCPV4_MSG_FORCERENEW";
423 default:
424 return "UNKNOWN";
425 }
426 }
427
428 static void dhcpv4_free_assignment(struct dhcp_assignment *a)
429 {
430 if (a->fr_ip)
431 dhcpv4_fr_stop(a);
432 }
433
434 static void dhcpv4_put(struct dhcpv4_message *msg, uint8_t **cookie,
435 uint8_t type, uint8_t len, const void *data)
436 {
437 uint8_t *c = *cookie;
438 uint8_t *end = (uint8_t *)msg + sizeof(*msg);
439 bool tag_only = type == DHCPV4_OPT_PAD || type == DHCPV4_OPT_END;
440 int total_len = tag_only ? 1 : 2 + len;
441
442 if (*cookie + total_len > end)
443 return;
444
445 *cookie += total_len;
446 *c++ = type;
447
448 if (tag_only)
449 return;
450
451 *c++ = len;
452 memcpy(c, data, len);
453 }
454
455 static void dhcpv4_fr_send(struct dhcp_assignment *a)
456 {
457 struct dhcpv4_message fr_msg = {
458 .op = DHCPV4_BOOTREPLY,
459 .htype = 1,
460 .hlen = 6,
461 .hops = 0,
462 .secs = 0,
463 .flags = 0,
464 .ciaddr = {INADDR_ANY},
465 .yiaddr = {INADDR_ANY},
466 .siaddr = {INADDR_ANY},
467 .giaddr = {INADDR_ANY},
468 .chaddr = {0},
469 .sname = {0},
470 .file = {0},
471 };
472 struct dhcpv4_auth_forcerenew *auth_o, auth = {
473 .protocol = 3,
474 .algorithm = 1,
475 .rdm = 0,
476 .replay = {htonl(time(NULL)), htonl(++serial)},
477 .type = 2,
478 .key = {0},
479 };
480 struct interface *iface = a->iface;
481
482 odhcpd_urandom(&fr_msg.xid, sizeof(fr_msg.xid));
483 memcpy(fr_msg.chaddr, a->hwaddr, fr_msg.hlen);
484
485 fr_msg.options[0] = 0x63;
486 fr_msg.options[1] = 0x82;
487 fr_msg.options[2] = 0x53;
488 fr_msg.options[3] = 0x63;
489
490 uint8_t *cookie = &fr_msg.options[4];
491 uint8_t msg = DHCPV4_MSG_FORCERENEW;
492
493 dhcpv4_put(&fr_msg, &cookie, DHCPV4_OPT_MESSAGE, 1, &msg);
494 if (a->accept_fr_nonce) {
495 dhcpv4_put(&fr_msg, &cookie, DHCPV4_OPT_AUTHENTICATION, sizeof(auth), &auth);
496 auth_o = (struct dhcpv4_auth_forcerenew *)(cookie - sizeof(auth));
497 dhcpv4_put(&fr_msg, &cookie, DHCPV4_OPT_END, 0, NULL);
498
499 md5_ctx_t md5;
500 uint8_t secretbytes[64];
501 memset(secretbytes, 0, sizeof(secretbytes));
502 memcpy(secretbytes, a->key, sizeof(a->key));
503
504 for (size_t i = 0; i < sizeof(secretbytes); ++i)
505 secretbytes[i] ^= 0x36;
506
507 md5_begin(&md5);
508 md5_hash(secretbytes, sizeof(secretbytes), &md5);
509 md5_hash(&fr_msg, sizeof(fr_msg), &md5);
510 md5_end(auth_o->key, &md5);
511
512 for (size_t i = 0; i < sizeof(secretbytes); ++i) {
513 secretbytes[i] ^= 0x36;
514 secretbytes[i] ^= 0x5c;
515 }
516
517 md5_begin(&md5);
518 md5_hash(secretbytes, sizeof(secretbytes), &md5);
519 md5_hash(auth_o->key, sizeof(auth_o->key), &md5);
520 md5_end(auth_o->key, &md5);
521 } else {
522 dhcpv4_put(&fr_msg, &cookie, DHCPV4_OPT_SERVERID, 4,
523 &a->fr_ip->addr.addr.in.s_addr);
524 dhcpv4_put(&fr_msg, &cookie, DHCPV4_OPT_END, 0, NULL);
525 }
526
527 struct sockaddr_in dest;
528 memset(&dest, 0, sizeof(dest));
529 dest.sin_family = AF_INET;
530 dest.sin_port = htons(DHCPV4_CLIENT_PORT);
531 dest.sin_addr.s_addr = a->addr;
532
533 if (sendto(iface->dhcpv4_event.uloop.fd, &fr_msg, PACKET_SIZE(&fr_msg, cookie),
534 MSG_DONTWAIT, (struct sockaddr*)&dest, sizeof(dest)) < 0)
535 syslog(LOG_ERR, "Failed to send %s to %s - %s: %m", dhcpv4_msg_to_string(msg),
536 odhcpd_print_mac(a->hwaddr, sizeof(a->hwaddr)), inet_ntoa(dest.sin_addr));
537 else
538 syslog(LOG_NOTICE, "Sent %s to %s - %s", dhcpv4_msg_to_string(msg),
539 odhcpd_print_mac(a->hwaddr, sizeof(a->hwaddr)), inet_ntoa(dest.sin_addr));
540 }
541
542 static void dhcpv4_fr_timer(struct uloop_timeout *event)
543 {
544 struct dhcp_assignment *a = container_of(event, struct dhcp_assignment, fr_timer);
545
546 if (a->fr_cnt > 0 && a->fr_cnt < 8) {
547 dhcpv4_fr_send(a);
548 uloop_timeout_set(&a->fr_timer, 1000 << a->fr_cnt);
549 a->fr_cnt++;
550 } else
551 dhcpv4_fr_stop(a);
552 }
553
554 static void dhcpv4_fr_start(struct dhcp_assignment *a)
555 {
556 uloop_timeout_set(&a->fr_timer, 1000 << a->fr_cnt);
557 a->fr_timer.cb = dhcpv4_fr_timer;
558 a->fr_cnt++;
559
560 dhcpv4_fr_send(a);
561 }
562
563 static void dhcpv4_fr_delay_timer(struct uloop_timeout *event)
564 {
565 struct dhcp_assignment *a = container_of(event, struct dhcp_assignment, fr_timer);
566 struct interface *iface = a->iface;
567
568 (iface->dhcpv4_event.uloop.fd == -1 ? dhcpv4_fr_rand_delay(a) : dhcpv4_fr_start(a));
569 }
570
571 static void dhcpv4_fr_rand_delay(struct dhcp_assignment *a)
572 {
573 #define MIN_DELAY 500
574 #define MAX_FUZZ 500
575 int msecs;
576
577 odhcpd_urandom(&msecs, sizeof(msecs));
578
579 msecs = labs(msecs)%MAX_FUZZ + MIN_DELAY;
580
581 uloop_timeout_set(&a->fr_timer, msecs);
582 a->fr_timer.cb = dhcpv4_fr_delay_timer;
583 }
584
585 static void dhcpv4_fr_stop(struct dhcp_assignment *a)
586 {
587 uloop_timeout_cancel(&a->fr_timer);
588 decr_ref_cnt_ip(&a->fr_ip, a->iface);
589 a->fr_cnt = 0;
590 a->fr_timer.cb = NULL;
591 }
592
593 /* Handler for DHCPv4 messages */
594 static void handle_dhcpv4(void *addr, void *data, size_t len,
595 struct interface *iface, _unused void *dest_addr)
596 {
597 struct dhcpv4_message *req = data;
598
599 if (!iface->dhcpv4)
600 return;
601
602 if (len < offsetof(struct dhcpv4_message, options) + 4 ||
603 req->op != DHCPV4_BOOTREQUEST || req->hlen != 6)
604 return;
605
606 syslog(LOG_NOTICE, "Got DHCPv4 request on %s", iface->name);
607
608 if (!iface->dhcpv4_start_ip.s_addr && !iface->dhcpv4_end_ip.s_addr) {
609 syslog(LOG_ERR, "No DHCP range available on %s", iface->name);
610 return;
611 }
612
613 int sock = iface->dhcpv4_event.uloop.fd;
614
615 struct dhcpv4_message reply = {
616 .op = DHCPV4_BOOTREPLY,
617 .htype = req->htype,
618 .hlen = req->hlen,
619 .hops = 0,
620 .xid = req->xid,
621 .secs = 0,
622 .flags = req->flags,
623 .ciaddr = {INADDR_ANY},
624 .giaddr = req->giaddr,
625 .siaddr = iface->dhcpv4_local,
626 };
627 memcpy(reply.chaddr, req->chaddr, sizeof(reply.chaddr));
628
629 reply.options[0] = 0x63;
630 reply.options[1] = 0x82;
631 reply.options[2] = 0x53;
632 reply.options[3] = 0x63;
633
634 uint8_t *cookie = &reply.options[4];
635 uint8_t reqmsg = DHCPV4_MSG_REQUEST;
636 uint8_t msg = DHCPV4_MSG_ACK;
637
638 uint32_t reqaddr = INADDR_ANY;
639 uint32_t leasetime = 0;
640 size_t hostname_len = 0;
641 size_t reqopts_len = 0;
642 char hostname[256];
643 char reqopts[256];
644 bool accept_fr_nonce = false;
645 bool incl_fr_opt = false;
646
647 uint8_t *start = &req->options[4];
648 uint8_t *end = ((uint8_t*)data) + len;
649 struct dhcpv4_option *opt;
650 dhcpv4_for_each_option(start, end, opt) {
651 if (opt->type == DHCPV4_OPT_MESSAGE && opt->len == 1)
652 reqmsg = opt->data[0];
653 else if (opt->type == DHCPV4_OPT_REQOPTS && opt->len > 0) {
654 reqopts_len = opt->len;
655 memcpy(reqopts, opt->data, reqopts_len);
656 reqopts[reqopts_len] = 0;
657 } else if (opt->type == DHCPV4_OPT_HOSTNAME && opt->len > 0) {
658 hostname_len = opt->len;
659 memcpy(hostname, opt->data, hostname_len);
660 hostname[hostname_len] = 0;
661 } else if (opt->type == DHCPV4_OPT_IPADDRESS && opt->len == 4)
662 memcpy(&reqaddr, opt->data, 4);
663 else if (opt->type == DHCPV4_OPT_SERVERID && opt->len == 4) {
664 if (memcmp(opt->data, &iface->dhcpv4_local, 4))
665 return;
666 } else if (iface->filter_class && opt->type == DHCPV4_OPT_USER_CLASS) {
667 uint8_t *c = opt->data, *cend = &opt->data[opt->len];
668 for (; c < cend && &c[*c] < cend; c = &c[1 + *c]) {
669 size_t elen = strlen(iface->filter_class);
670 if (*c == elen && !memcmp(&c[1], iface->filter_class, elen))
671 return; // Ignore from homenet
672 }
673 } else if (opt->type == DHCPV4_OPT_LEASETIME && opt->len == 4)
674 memcpy(&leasetime, opt->data, 4);
675 else if (opt->type == DHCPV4_OPT_FORCERENEW_NONCE_CAPABLE && opt->len > 0) {
676 for (uint8_t i = 0; i < opt->len; i++) {
677 if (opt->data[i] == 1) {
678 accept_fr_nonce = true;
679 break;
680 }
681 }
682
683 }
684 }
685
686 if (reqmsg != DHCPV4_MSG_DISCOVER && reqmsg != DHCPV4_MSG_REQUEST &&
687 reqmsg != DHCPV4_MSG_INFORM && reqmsg != DHCPV4_MSG_DECLINE &&
688 reqmsg != DHCPV4_MSG_RELEASE)
689 return;
690
691 struct dhcp_assignment *a = NULL;
692 uint32_t serverid = iface->dhcpv4_local.s_addr;
693 uint32_t fr_serverid = INADDR_ANY;
694
695 if (reqmsg != DHCPV4_MSG_INFORM)
696 a = dhcpv4_lease(iface, reqmsg, req->chaddr, reqaddr,
697 &leasetime, hostname, hostname_len,
698 accept_fr_nonce, &incl_fr_opt, &fr_serverid,
699 reqopts, reqopts_len);
700
701 if (!a) {
702 if (reqmsg == DHCPV4_MSG_REQUEST)
703 msg = DHCPV4_MSG_NAK;
704 else if (reqmsg == DHCPV4_MSG_DISCOVER)
705 return;
706 } else if (reqmsg == DHCPV4_MSG_DISCOVER)
707 msg = DHCPV4_MSG_OFFER;
708 else if (reqmsg == DHCPV4_MSG_REQUEST &&
709 ((reqaddr && reqaddr != a->addr) ||
710 (req->ciaddr.s_addr && req->ciaddr.s_addr != a->addr))) {
711 msg = DHCPV4_MSG_NAK;
712 /*
713 * DHCP client requested an IP which we can't offer to him. Probably the
714 * client changed the network or the network has been changed. The reply
715 * type is set to DHCPV4_MSG_NAK, because the client should not use that IP.
716 *
717 * For modern devices we build an answer that includes a valid IP, like
718 * a DHCPV4_MSG_ACK. The client will use that IP and doesn't need to
719 * perform additional DHCP round trips.
720 *
721 */
722
723 /*
724 *
725 * Buggy clients do serverid checking in nack messages; therefore set the
726 * serverid in nack messages triggered by a previous force renew equal to
727 * the server id in use at that time by the server
728 *
729 */
730 if (fr_serverid)
731 serverid = fr_serverid;
732
733 if (req->ciaddr.s_addr &&
734 ((iface->dhcpv4_start_ip.s_addr & iface->dhcpv4_mask.s_addr) !=
735 (req->ciaddr.s_addr & iface->dhcpv4_mask.s_addr)))
736 req->ciaddr.s_addr = INADDR_ANY;
737 }
738
739 syslog(LOG_NOTICE, "Received %s from %s on %s", dhcpv4_msg_to_string(reqmsg),
740 odhcpd_print_mac(req->chaddr, req->hlen), iface->name);
741
742 #ifdef WITH_UBUS
743 if (reqmsg == DHCPV4_MSG_RELEASE)
744 ubus_bcast_dhcp_event("dhcp.release", req->chaddr, req->hlen,
745 &req->ciaddr, hostname, iface->ifname);
746 #endif
747 if (reqmsg == DHCPV4_MSG_DECLINE || reqmsg == DHCPV4_MSG_RELEASE)
748 return;
749
750 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_MESSAGE, 1, &msg);
751 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_SERVERID, 4, &serverid);
752
753 if (a) {
754 uint32_t val;
755
756 reply.yiaddr.s_addr = a->addr;
757
758 val = htonl(leasetime);
759 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_LEASETIME, 4, &val);
760
761 if (leasetime != UINT32_MAX) {
762 val = htonl(500 * leasetime / 1000);
763 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_RENEW, 4, &val);
764
765 val = htonl(875 * leasetime / 1000);
766 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_REBIND, 4, &val);
767 }
768
769 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_NETMASK, 4,
770 &iface->dhcpv4_mask.s_addr);
771
772 if (a->hostname)
773 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_HOSTNAME,
774 strlen(a->hostname), a->hostname);
775
776 if (iface->dhcpv4_bcast.s_addr != INADDR_ANY)
777 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_BROADCAST, 4, &iface->dhcpv4_bcast);
778
779 if (incl_fr_opt) {
780 if (reqmsg == DHCPV4_MSG_REQUEST) {
781 struct dhcpv4_auth_forcerenew auth = {
782 .protocol = 3,
783 .algorithm = 1,
784 .rdm = 0,
785 .replay = {htonl(time(NULL)), htonl(++serial)},
786 .type = 1,
787 .key = {0},
788 };
789
790 memcpy(auth.key, a->key, sizeof(auth.key));
791 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_AUTHENTICATION, sizeof(auth), &auth);
792 } else {
793 uint8_t one = 1;
794 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_FORCERENEW_NONCE_CAPABLE,
795 sizeof(one), &one);
796 }
797 }
798 }
799
800 struct ifreq ifr;
801
802 memset(&ifr, 0, sizeof(ifr));
803 strncpy(ifr.ifr_name, iface->ifname, sizeof(ifr.ifr_name) - 1);
804
805 if (!ioctl(sock, SIOCGIFMTU, &ifr)) {
806 uint16_t mtu = htons(ifr.ifr_mtu);
807 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_MTU, 2, &mtu);
808 }
809
810 if (iface->search && iface->search_len <= 255)
811 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_SEARCH_DOMAIN,
812 iface->search_len, iface->search);
813 else if (!res_init() && _res.dnsrch[0] && _res.dnsrch[0][0]) {
814 uint8_t search_buf[256];
815 int len = dn_comp(_res.dnsrch[0], search_buf,
816 sizeof(search_buf), NULL, NULL);
817 if (len > 0)
818 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_SEARCH_DOMAIN,
819 len, search_buf);
820 }
821
822 if (iface->dhcpv4_router_cnt == 0)
823 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_ROUTER, 4, &iface->dhcpv4_local);
824 else
825 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_ROUTER,
826 4 * iface->dhcpv4_router_cnt, iface->dhcpv4_router);
827
828
829 if (iface->dhcpv4_dns_cnt == 0)
830 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_DNSSERVER, 4, &iface->dhcpv4_local);
831 else
832 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_DNSSERVER,
833 4 * iface->dhcpv4_dns_cnt, iface->dhcpv4_dns);
834
835
836 dhcpv4_put(&reply, &cookie, DHCPV4_OPT_END, 0, NULL);
837
838 struct sockaddr_in dest = *((struct sockaddr_in*)addr);
839 if (req->giaddr.s_addr) {
840 /*
841 * relay agent is configured, send reply to the agent
842 */
843 dest.sin_addr = req->giaddr;
844 dest.sin_port = htons(DHCPV4_SERVER_PORT);
845 } else if (req->ciaddr.s_addr && req->ciaddr.s_addr != dest.sin_addr.s_addr) {
846 /*
847 * client has existing configuration (ciaddr is set) AND this address is
848 * not the address it used for the dhcp message
849 */
850 dest.sin_addr = req->ciaddr;
851 dest.sin_port = htons(DHCPV4_CLIENT_PORT);
852 } else if ((ntohs(req->flags) & DHCPV4_FLAG_BROADCAST) ||
853 req->hlen != reply.hlen || !reply.yiaddr.s_addr) {
854 /*
855 * client requests a broadcast reply OR we can't offer an IP
856 */
857 dest.sin_addr.s_addr = INADDR_BROADCAST;
858 dest.sin_port = htons(DHCPV4_CLIENT_PORT);
859 } else if (!req->ciaddr.s_addr && msg == DHCPV4_MSG_NAK) {
860 /*
861 * client has no previous configuration -> no IP, so we need to reply
862 * with a broadcast packet
863 */
864 dest.sin_addr.s_addr = INADDR_BROADCAST;
865 dest.sin_port = htons(DHCPV4_CLIENT_PORT);
866 } else {
867 struct arpreq arp = {.arp_flags = ATF_COM};
868
869 /*
870 * send reply to the newly (in this proccess) allocated IP
871 */
872 dest.sin_addr = reply.yiaddr;
873 dest.sin_port = htons(DHCPV4_CLIENT_PORT);
874
875 memcpy(arp.arp_ha.sa_data, req->chaddr, 6);
876 memcpy(&arp.arp_pa, &dest, sizeof(arp.arp_pa));
877 memcpy(arp.arp_dev, iface->ifname, sizeof(arp.arp_dev));
878
879 if (ioctl(sock, SIOCSARP, &arp) < 0)
880 syslog(LOG_ERR, "ioctl(SIOCSARP): %m");
881 }
882
883 if (sendto(sock, &reply, PACKET_SIZE(&reply, cookie), MSG_DONTWAIT,
884 (struct sockaddr*)&dest, sizeof(dest)) < 0)
885 syslog(LOG_ERR, "Failed to send %s to %s - %s: %m",
886 dhcpv4_msg_to_string(msg),
887 dest.sin_addr.s_addr == INADDR_BROADCAST ?
888 "ff:ff:ff:ff:ff:ff": odhcpd_print_mac(req->chaddr, req->hlen),
889 inet_ntoa(dest.sin_addr));
890 else
891 syslog(LOG_NOTICE, "Sent %s to %s - %s",
892 dhcpv4_msg_to_string(msg),
893 dest.sin_addr.s_addr == INADDR_BROADCAST ?
894 "ff:ff:ff:ff:ff:ff": odhcpd_print_mac(req->chaddr, req->hlen),
895 inet_ntoa(dest.sin_addr));
896
897
898 #ifdef WITH_UBUS
899 if (msg == DHCPV4_MSG_ACK)
900 ubus_bcast_dhcp_event("dhcp.ack", req->chaddr, req->hlen, &reply.yiaddr,
901 hostname, iface->ifname);
902 #endif
903 }
904
905 static bool dhcpv4_assign(struct interface *iface, struct dhcp_assignment *a,
906 uint32_t raddr)
907 {
908 struct dhcp_assignment *c;
909 uint32_t start = ntohl(iface->dhcpv4_start_ip.s_addr);
910 uint32_t end = ntohl(iface->dhcpv4_end_ip.s_addr);
911 uint32_t count = end - start + 1;
912 uint32_t seed = 0;
913
914 /* Preconfigured IP address by static lease */
915 if (a->addr) {
916 if (list_empty(&iface->dhcpv4_assignments)) {
917 list_add(&a->head, &iface->dhcpv4_assignments);
918 return true;
919 }
920
921 list_for_each_entry(c, &iface->dhcpv4_assignments, head) {
922 if (ntohl(c->addr) > ntohl(a->addr)) {
923 list_add_tail(&a->head, &c->head);
924 return true;
925 } else if (ntohl(a->addr) == ntohl(c->addr))
926 return false;
927 }
928 }
929
930 /* try to assign the IP the client asked for */
931 if (start <= ntohl(raddr) && ntohl(raddr) <= end &&
932 !config_find_lease_by_ipaddr(raddr)) {
933 if (list_empty(&iface->dhcpv4_assignments)) {
934 list_add(&a->head, &iface->dhcpv4_assignments);
935 goto raddr_out;
936 }
937
938 list_for_each_entry(c, &iface->dhcpv4_assignments, head) {
939 if (ntohl(raddr) == ntohl(c->addr))
940 break;
941
942 if (ntohl(c->addr) > ntohl(raddr) || list_is_last(&c->head, &iface->dhcpv4_assignments)) {
943 list_add_tail(&a->head,
944 ntohl(c->addr) > ntohl(raddr) ? &c->head : &iface->dhcpv4_assignments);
945 raddr_out:
946 a->addr = raddr;
947
948 syslog(LOG_INFO, "Assigning the IP the client asked for: %u.%u.%u.%u",
949 ((uint8_t *)&a->addr)[0], ((uint8_t *)&a->addr)[1],
950 ((uint8_t *)&a->addr)[2], ((uint8_t *)&a->addr)[3]);
951
952 return true;
953 }
954 }
955 }
956
957 /* Seed RNG with checksum of hwaddress */
958 for (size_t i = 0; i < sizeof(a->hwaddr); ++i) {
959 /* Knuth's multiplicative method */
960 uint8_t o = a->hwaddr[i];
961 seed += (o*2654435761) % UINT32_MAX;
962 }
963
964 srand(seed);
965
966 for (uint32_t i = 0, try = (((uint32_t)rand()) % count) + start; i < count;
967 ++i, try = (((try - start) + 1) % count) + start) {
968
969 if (config_find_lease_by_ipaddr(htonl(try)))
970 continue;
971
972 if (list_empty(&iface->dhcpv4_assignments)) {
973 list_add(&a->head, &iface->dhcpv4_assignments);
974 a->addr = htonl(try);
975
976 syslog(LOG_INFO, "Assigning mapped IP (empty list): %u.%u.%u.%u",
977 ((uint8_t *)&a->addr)[0], ((uint8_t *)&a->addr)[1],
978 ((uint8_t *)&a->addr)[2], ((uint8_t *)&a->addr)[3]);
979
980 return true;
981 }
982
983 list_for_each_entry(c, &iface->dhcpv4_assignments, head) {
984 if (try == ntohl(c->addr))
985 break;
986
987 if (ntohl(c->addr) > try || list_is_last(&c->head, &iface->dhcpv4_assignments)) {
988 list_add_tail(&a->head,
989 ntohl(c->addr) > try ? &c->head : &iface->dhcpv4_assignments);
990 a->addr = htonl(try);
991
992 syslog(LOG_INFO, "Assigning mapped IP: %u.%u.%u.%u (try %u of %u)",
993 ((uint8_t *)&a->addr)[0], ((uint8_t *)&a->addr)[1],
994 ((uint8_t *)&a->addr)[2], ((uint8_t *)&a->addr)[3],
995 i, count);
996
997 return true;
998 }
999 }
1000 }
1001
1002 syslog(LOG_WARNING, "Can't assign any IP address -> address space is full");
1003 return false;
1004 }
1005
1006
1007 static struct dhcp_assignment*
1008 dhcpv4_lease(struct interface *iface, enum dhcpv4_msg msg, const uint8_t *mac,
1009 const uint32_t reqaddr, uint32_t *leasetime, const char *hostname,
1010 const size_t hostname_len, const bool accept_fr_nonce, bool *incl_fr_opt,
1011 uint32_t *fr_serverid, const char* reqopts, const size_t reqopts_len)
1012 {
1013 struct dhcp_assignment *a = find_assignment_by_hwaddr(iface, mac);
1014 struct lease *l = config_find_lease_by_mac(mac);
1015 time_t now = odhcpd_time();
1016
1017 if (l && a && a->lease != l) {
1018 free_assignment(a);
1019 a = NULL;
1020 }
1021
1022 if (a && (a->flags & OAF_BOUND) && a->fr_ip) {
1023 *fr_serverid = a->fr_ip->addr.addr.in.s_addr;
1024 dhcpv4_fr_stop(a);
1025 }
1026
1027 if (msg == DHCPV4_MSG_DISCOVER || msg == DHCPV4_MSG_REQUEST) {
1028 bool assigned = !!a;
1029
1030 if (!a) {
1031 if (!iface->no_dynamic_dhcp || l) {
1032 /* Create new binding */
1033 a = calloc(1, sizeof(*a));
1034 if (!a) {
1035 syslog(LOG_ERR, "Failed to calloc binding on interface %s",
1036 iface->ifname);
1037 return NULL;
1038 }
1039 memcpy(a->hwaddr, mac, sizeof(a->hwaddr));
1040 /* Set valid time to 0 for static lease indicating */
1041 /* infinite lifetime otherwise current time */
1042 a->valid_until = l ? 0 : now;
1043 a->dhcp_free_cb = dhcpv4_free_assignment;
1044 a->iface = iface;
1045 a->flags = OAF_DHCPV4;
1046 a->addr = l ? l->ipaddr : INADDR_ANY;
1047
1048 assigned = dhcpv4_assign(iface, a, reqaddr);
1049
1050 if (l) {
1051 a->flags |= OAF_STATIC;
1052
1053 if (l->hostname)
1054 a->hostname = strdup(l->hostname);
1055
1056 if (l->leasetime)
1057 a->leasetime = l->leasetime;
1058
1059 list_add(&a->lease_list, &l->assignments);
1060 a->lease = l;
1061 }
1062 }
1063 } else if (((a->addr & iface->dhcpv4_mask.s_addr) !=
1064 (iface->dhcpv4_start_ip.s_addr & iface->dhcpv4_mask.s_addr)) &&
1065 !(a->flags & OAF_STATIC)) {
1066 list_del(&a->head);
1067 a->addr = INADDR_ANY;
1068
1069 assigned = dhcpv4_assign(iface, a, reqaddr);
1070 }
1071
1072 if (assigned) {
1073 uint32_t my_leasetime;
1074
1075 if (a->leasetime)
1076 my_leasetime = a->leasetime;
1077 else
1078 my_leasetime = iface->dhcpv4_leasetime;
1079
1080 if ((*leasetime == 0) || (my_leasetime < *leasetime))
1081 *leasetime = my_leasetime;
1082
1083 if (msg == DHCPV4_MSG_DISCOVER) {
1084 a->flags &= ~OAF_BOUND;
1085
1086 *incl_fr_opt = accept_fr_nonce;
1087 if (!(a->flags & OAF_STATIC))
1088 a->valid_until = now;
1089 } else {
1090 if ((!(a->flags & OAF_STATIC) || !a->hostname) && hostname_len > 0) {
1091 a->hostname = realloc(a->hostname, hostname_len + 1);
1092 if (a->hostname) {
1093 memcpy(a->hostname, hostname, hostname_len);
1094 a->hostname[hostname_len] = 0;
1095
1096 if (odhcpd_valid_hostname(a->hostname))
1097 a->flags &= ~OAF_BROKEN_HOSTNAME;
1098 else
1099 a->flags |= OAF_BROKEN_HOSTNAME;
1100 }
1101 }
1102
1103 if (reqopts_len > 0) {
1104 a->reqopts = realloc(a->reqopts, reqopts_len + 1);
1105 if (a->reqopts) {
1106 memcpy(a->reqopts, reqopts, reqopts_len);
1107 a->reqopts[reqopts_len] = 0;
1108 }
1109 }
1110
1111 if (!(a->flags & OAF_BOUND)) {
1112 a->accept_fr_nonce = accept_fr_nonce;
1113 *incl_fr_opt = accept_fr_nonce;
1114 odhcpd_urandom(a->key, sizeof(a->key));
1115 a->flags |= OAF_BOUND;
1116 } else
1117 *incl_fr_opt = false;
1118
1119 if (!(a->flags & OAF_STATIC))
1120 a->valid_until = ((*leasetime == UINT32_MAX) ? 0 : (time_t)(now + *leasetime));
1121 }
1122 } else if (!assigned && a) {
1123 /* Cleanup failed assignment */
1124 free_assignment(a);
1125 a = NULL;
1126 }
1127
1128 } else if (msg == DHCPV4_MSG_RELEASE && a) {
1129 a->flags &= ~OAF_BOUND;
1130
1131 if (!(a->flags & OAF_STATIC))
1132 a->valid_until = now - 1;
1133
1134 } else if (msg == DHCPV4_MSG_DECLINE && a) {
1135 a->flags &= ~OAF_BOUND;
1136
1137 if (!(a->flags & OAF_STATIC)) {
1138 memset(a->hwaddr, 0, sizeof(a->hwaddr));
1139 a->valid_until = now + 3600; /* Block address for 1h */
1140 }
1141 }
1142
1143 dhcpv6_ia_write_statefile();
1144
1145 return a;
1146 }