16 static struct blob_buf b;
17 static int reload_pipe[2];
18 struct list_head leases = LIST_HEAD_INIT(leases);
19 struct list_head interfaces = LIST_HEAD_INIT(interfaces);
20 struct config config = {.legacy = false, .dhcp_cb = NULL,
21 .dhcp_statefile = NULL, .log_level = LOG_INFO};
27 IFACE_ATTR_DYNAMICDHCP,
41 IFACE_ATTR_FILTER_CLASS,
42 IFACE_ATTR_DHCPV6_RAW,
43 IFACE_ATTR_RA_DEFAULT,
44 IFACE_ATTR_RA_MANAGEMENT,
45 IFACE_ATTR_RA_OFFLINK,
46 IFACE_ATTR_RA_PREFERENCE,
47 IFACE_ATTR_RA_ADVROUTER,
48 IFACE_ATTR_RA_MAXINTERVAL,
49 IFACE_ATTR_PD_MANAGER,
51 IFACE_ATTR_NDPROXY_ROUTING,
52 IFACE_ATTR_NDPROXY_SLAVE,
56 static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
57 [IFACE_ATTR_INTERFACE] = { .name = "interface", .type = BLOBMSG_TYPE_STRING },
58 [IFACE_ATTR_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING },
59 [IFACE_ATTR_NETWORKID] = { .name = "networkid", .type = BLOBMSG_TYPE_STRING },
60 [IFACE_ATTR_DYNAMICDHCP] = { .name = "dynamicdhcp", .type = BLOBMSG_TYPE_BOOL },
61 [IFACE_ATTR_IGNORE] = { .name = "ignore", .type = BLOBMSG_TYPE_BOOL },
62 [IFACE_ATTR_LEASETIME] = { .name = "leasetime", .type = BLOBMSG_TYPE_STRING },
63 [IFACE_ATTR_START] = { .name = "start", .type = BLOBMSG_TYPE_INT32 },
64 [IFACE_ATTR_LIMIT] = { .name = "limit", .type = BLOBMSG_TYPE_INT32 },
65 [IFACE_ATTR_MASTER] = { .name = "master", .type = BLOBMSG_TYPE_BOOL },
66 [IFACE_ATTR_UPSTREAM] = { .name = "upstream", .type = BLOBMSG_TYPE_ARRAY },
67 [IFACE_ATTR_RA] = { .name = "ra", .type = BLOBMSG_TYPE_STRING },
68 [IFACE_ATTR_DHCPV4] = { .name = "dhcpv4", .type = BLOBMSG_TYPE_STRING },
69 [IFACE_ATTR_DHCPV6] = { .name = "dhcpv6", .type = BLOBMSG_TYPE_STRING },
70 [IFACE_ATTR_NDP] = { .name = "ndp", .type = BLOBMSG_TYPE_STRING },
71 [IFACE_ATTR_ROUTER] = { .name = "router", .type = BLOBMSG_TYPE_ARRAY },
72 [IFACE_ATTR_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY },
73 [IFACE_ATTR_DOMAIN] = { .name = "domain", .type = BLOBMSG_TYPE_ARRAY },
74 [IFACE_ATTR_FILTER_CLASS] = { .name = "filter_class", .type = BLOBMSG_TYPE_STRING },
75 [IFACE_ATTR_DHCPV6_RAW] = { .name = "dhcpv6_raw", .type = BLOBMSG_TYPE_STRING },
76 [IFACE_ATTR_PD_MANAGER] = { .name = "pd_manager", .type = BLOBMSG_TYPE_STRING },
77 [IFACE_ATTR_PD_CER] = { .name = "pd_cer", .type = BLOBMSG_TYPE_STRING },
78 [IFACE_ATTR_RA_DEFAULT] = { .name = "ra_default", .type = BLOBMSG_TYPE_INT32 },
79 [IFACE_ATTR_RA_MANAGEMENT] = { .name = "ra_management", .type = BLOBMSG_TYPE_INT32 },
80 [IFACE_ATTR_RA_OFFLINK] = { .name = "ra_offlink", .type = BLOBMSG_TYPE_BOOL },
81 [IFACE_ATTR_RA_PREFERENCE] = { .name = "ra_preference", .type = BLOBMSG_TYPE_STRING },
82 [IFACE_ATTR_RA_ADVROUTER] = { .name = "ra_advrouter", .type = BLOBMSG_TYPE_BOOL },
83 [IFACE_ATTR_RA_MAXINTERVAL] = { .name = "ra_maxinterval", .type = BLOBMSG_TYPE_INT32 },
84 [IFACE_ATTR_NDPROXY_ROUTING] = { .name = "ndproxy_routing", .type = BLOBMSG_TYPE_BOOL },
85 [IFACE_ATTR_NDPROXY_SLAVE] = { .name = "ndproxy_slave", .type = BLOBMSG_TYPE_BOOL },
88 static const struct uci_blob_param_info iface_attr_info[IFACE_ATTR_MAX] = {
89 [IFACE_ATTR_UPSTREAM] = { .type = BLOBMSG_TYPE_STRING },
90 [IFACE_ATTR_DNS] = { .type = BLOBMSG_TYPE_STRING },
91 [IFACE_ATTR_DOMAIN] = { .type = BLOBMSG_TYPE_STRING },
94 const struct uci_blob_param_list interface_attr_list = {
95 .n_params = IFACE_ATTR_MAX,
96 .params = iface_attrs,
97 .info = iface_attr_info,
105 LEASE_ATTR_LEASETIME,
110 static const struct blobmsg_policy lease_attrs[LEASE_ATTR_MAX] = {
111 [LEASE_ATTR_IP] = { .name = "ip", .type = BLOBMSG_TYPE_STRING },
112 [LEASE_ATTR_MAC] = { .name = "mac", .type = BLOBMSG_TYPE_STRING },
113 [LEASE_ATTR_DUID] = { .name = "duid", .type = BLOBMSG_TYPE_STRING },
114 [LEASE_ATTR_HOSTID] = { .name = "hostid", .type = BLOBMSG_TYPE_STRING },
115 [LEASE_ATTR_LEASETIME] = { .name = "leasetime", .type = BLOBMSG_TYPE_STRING },
116 [LEASE_ATTR_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING },
119 const struct uci_blob_param_list lease_attr_list = {
120 .n_params = LEASE_ATTR_MAX,
121 .params = lease_attrs,
125 ODHCPD_ATTR_MAINDHCP,
126 ODHCPD_ATTR_LEASEFILE,
127 ODHCPD_ATTR_LEASETRIGGER,
128 ODHCPD_ATTR_LOGLEVEL,
132 static const struct blobmsg_policy odhcpd_attrs[LEASE_ATTR_MAX] = {
133 [ODHCPD_ATTR_MAINDHCP] = { .name = "maindhcp", .type = BLOBMSG_TYPE_BOOL },
134 [ODHCPD_ATTR_LEASEFILE] = { .name = "leasefile", .type = BLOBMSG_TYPE_STRING },
135 [ODHCPD_ATTR_LEASETRIGGER] = { .name = "leasetrigger", .type = BLOBMSG_TYPE_STRING },
136 [ODHCPD_ATTR_LOGLEVEL] = { .name = "loglevel", .type = BLOBMSG_TYPE_INT32 },
139 const struct uci_blob_param_list odhcpd_attr_list = {
140 .n_params = ODHCPD_ATTR_MAX,
141 .params = odhcpd_attrs,
144 static int mkdir_p(char *dir, mode_t mask)
146 char *l = strrchr(dir, '/');
154 if (mkdir_p(dir, mask))
159 ret = mkdir(dir, mask);
160 if (ret && errno == EEXIST)
164 syslog(LOG_ERR, "mkdir(%s, %d) failed: %s\n", dir, mask, strerror(errno));
169 static void free_lease(struct lease *l)
178 static struct interface* get_interface(const char *name)
181 list_for_each_entry(c, &interfaces, head)
182 if (!strcmp(c->name, name))
187 static void set_interface_defaults(struct interface *iface)
190 iface->learn_routes = 1;
193 static void clean_interface(struct interface *iface)
197 free(iface->upstream);
198 free(iface->dhcpv4_router);
199 free(iface->dhcpv4_dns);
200 free(iface->dhcpv6_raw);
201 free(iface->filter_class);
202 memset(&iface->ra, 0, sizeof(*iface) - offsetof(struct interface, ra));
203 set_interface_defaults(iface);
206 static void close_interface(struct interface *iface)
208 if (iface->head.next)
209 list_del(&iface->head);
211 setup_router_interface(iface, false);
212 setup_dhcpv6_interface(iface, false);
213 setup_ndp_interface(iface, false);
214 setup_dhcpv4_interface(iface, false);
216 clean_interface(iface);
220 static int parse_mode(const char *mode)
222 if (!strcmp(mode, "disabled"))
223 return RELAYD_DISABLED;
224 else if (!strcmp(mode, "server"))
225 return RELAYD_SERVER;
226 else if (!strcmp(mode, "relay"))
228 else if (!strcmp(mode, "hybrid"))
229 return RELAYD_HYBRID;
234 static void set_config(struct uci_section *s)
236 struct blob_attr *tb[ODHCPD_ATTR_MAX], *c;
238 blob_buf_init(&b, 0);
239 uci_to_blob(&b, s, &odhcpd_attr_list);
240 blobmsg_parse(odhcpd_attrs, ODHCPD_ATTR_MAX, tb, blob_data(b.head), blob_len(b.head));
242 if ((c = tb[ODHCPD_ATTR_MAINDHCP]))
243 config.legacy = blobmsg_get_bool(c);
245 if ((c = tb[ODHCPD_ATTR_LEASEFILE])) {
246 free(config.dhcp_statefile);
247 config.dhcp_statefile = strdup(blobmsg_get_string(c));
250 if ((c = tb[ODHCPD_ATTR_LEASETRIGGER])) {
251 free(config.dhcp_cb);
252 config.dhcp_cb = strdup(blobmsg_get_string(c));
255 if ((c = tb[ODHCPD_ATTR_LOGLEVEL])) {
256 int log_level = (blobmsg_get_u32(c) & LOG_PRIMASK);
258 if (config.log_level != log_level) {
259 config.log_level = log_level;
260 setlogmask(LOG_UPTO(config.log_level));
265 static double parse_leasetime(struct blob_attr *c) {
266 char *val = blobmsg_get_string(c), *endptr = NULL;
267 double time = strcmp(val, "infinite") ? strtod(val, &endptr) : UINT32_MAX;
269 if (time && endptr && endptr[0]) {
270 if (endptr[0] == 's')
272 else if (endptr[0] == 'm')
274 else if (endptr[0] == 'h')
276 else if (endptr[0] == 'd')
278 else if (endptr[0] == 'w')
279 time *= 7 * 24 * 3600;
293 static int set_lease(struct uci_section *s)
295 struct blob_attr *tb[LEASE_ATTR_MAX], *c;
297 blob_buf_init(&b, 0);
298 uci_to_blob(&b, s, &lease_attr_list);
299 blobmsg_parse(lease_attrs, LEASE_ATTR_MAX, tb, blob_data(b.head), blob_len(b.head));
302 if ((c = tb[LEASE_ATTR_NAME]))
303 hostlen = blobmsg_data_len(c);
305 struct lease *lease = calloc(1, sizeof(*lease) + hostlen);
310 memcpy(lease->hostname, blobmsg_get_string(c), hostlen);
312 if ((c = tb[LEASE_ATTR_IP]))
313 if (inet_pton(AF_INET, blobmsg_get_string(c), &lease->ipaddr) < 0)
316 if ((c = tb[LEASE_ATTR_MAC]))
317 if (!ether_aton_r(blobmsg_get_string(c), &lease->mac))
320 if ((c = tb[LEASE_ATTR_DUID])) {
321 size_t duidlen = (blobmsg_data_len(c) - 1) / 2;
322 lease->duid = malloc(duidlen);
326 ssize_t len = odhcpd_unhexlify(lease->duid,
327 duidlen, blobmsg_get_string(c));
332 lease->duid_len = len;
335 if ((c = tb[LEASE_ATTR_HOSTID])) {
337 lease->hostid = strtoul(blobmsg_get_string(c), NULL, 16);
342 if ((c = tb[LEASE_ATTR_LEASETIME])) {
343 double time = parse_leasetime(c);
348 lease->dhcpv4_leasetime = time;
351 list_add(&lease->head, &leases);
361 int config_parse_interface(void *data, size_t len, const char *name, bool overwrite)
363 struct blob_attr *tb[IFACE_ATTR_MAX], *c;
364 blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb, data, len);
366 if (tb[IFACE_ATTR_INTERFACE])
367 name = blobmsg_get_string(tb[IFACE_ATTR_INTERFACE]);
372 struct interface *iface = get_interface(name);
374 iface = calloc(1, sizeof(*iface));
378 strncpy(iface->name, name, sizeof(iface->name) - 1);
380 set_interface_defaults(iface);
382 list_add(&iface->head, &interfaces);
386 const char *ifname = NULL;
388 if ((c = tb[IFACE_ATTR_IFNAME]))
389 ifname = blobmsg_get_string(c);
390 else if ((c = tb[IFACE_ATTR_NETWORKID]))
391 ifname = blobmsg_get_string(c);
395 if (overwrite || !iface->ifname[0])
396 ifname = ubus_get_ifname(name);
399 if (!iface->ifname[0] && !ifname)
403 strncpy(iface->ifname, ifname, sizeof(iface->ifname) - 1);
405 if ((iface->ifindex = if_nametoindex(iface->ifname)) <= 0)
410 if ((c = tb[IFACE_ATTR_DYNAMICDHCP]))
411 iface->no_dynamic_dhcp = !blobmsg_get_bool(c);
413 if (overwrite && (c = tb[IFACE_ATTR_IGNORE]))
414 iface->ignore = blobmsg_get_bool(c);
416 if ((c = tb[IFACE_ATTR_LEASETIME])) {
417 double time = parse_leasetime(c);
422 iface->dhcpv4_leasetime = time;
425 if ((c = tb[IFACE_ATTR_START])) {
426 iface->dhcpv4_start.s_addr = htonl(blobmsg_get_u32(c));
429 iface->dhcpv4 = RELAYD_SERVER;
432 if ((c = tb[IFACE_ATTR_LIMIT]))
433 iface->dhcpv4_end.s_addr = htonl(
434 ntohl(iface->dhcpv4_start.s_addr) + blobmsg_get_u32(c));
436 if ((c = tb[IFACE_ATTR_MASTER]))
437 iface->master = blobmsg_get_bool(c);
439 if (overwrite && (c = tb[IFACE_ATTR_UPSTREAM])) {
440 struct blob_attr *cur;
443 blobmsg_for_each_attr(cur, c, rem) {
444 if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING || !blobmsg_check_attr(cur, false))
447 iface->upstream = realloc(iface->upstream,
448 iface->upstream_len + blobmsg_data_len(cur));
449 if (!iface->upstream)
452 memcpy(iface->upstream + iface->upstream_len, blobmsg_get_string(cur), blobmsg_data_len(cur));
453 iface->upstream_len += blobmsg_data_len(cur);
458 if ((c = tb[IFACE_ATTR_RA])) {
459 if ((mode = parse_mode(blobmsg_get_string(c))) >= 0)
465 if ((c = tb[IFACE_ATTR_DHCPV4])) {
466 if ((mode = parse_mode(blobmsg_get_string(c))) >= 0)
467 iface->dhcpv4 = mode;
472 if ((c = tb[IFACE_ATTR_DHCPV6])) {
473 if ((mode = parse_mode(blobmsg_get_string(c))) >= 0)
474 iface->dhcpv6 = mode;
479 if ((c = tb[IFACE_ATTR_NDP])) {
480 if ((mode = parse_mode(blobmsg_get_string(c))) >= 0)
486 if ((c = tb[IFACE_ATTR_ROUTER])) {
487 struct blob_attr *cur;
490 blobmsg_for_each_attr(cur, c, rem) {
491 if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING || !blobmsg_check_attr(cur, false))
494 struct in_addr addr4;
495 if (inet_pton(AF_INET, blobmsg_get_string(cur), &addr4) == 1) {
496 iface->dhcpv4_router = realloc(iface->dhcpv4_router,
497 (++iface->dhcpv4_router_cnt) * sizeof(*iface->dhcpv4_router));
498 if (!iface->dhcpv4_router)
501 iface->dhcpv4_router[iface->dhcpv4_router_cnt - 1] = addr4;
507 if ((c = tb[IFACE_ATTR_DNS])) {
508 struct blob_attr *cur;
511 iface->always_rewrite_dns = true;
512 blobmsg_for_each_attr(cur, c, rem) {
513 if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING || !blobmsg_check_attr(cur, false))
516 struct in_addr addr4;
517 struct in6_addr addr6;
518 if (inet_pton(AF_INET, blobmsg_get_string(cur), &addr4) == 1) {
519 iface->dhcpv4_dns = realloc(iface->dhcpv4_dns,
520 (++iface->dhcpv4_dns_cnt) * sizeof(*iface->dhcpv4_dns));
521 if (!iface->dhcpv4_dns)
524 iface->dhcpv4_dns[iface->dhcpv4_dns_cnt - 1] = addr4;
525 } else if (inet_pton(AF_INET6, blobmsg_get_string(cur), &addr6) == 1) {
526 iface->dns = realloc(iface->dns,
527 (++iface->dns_cnt) * sizeof(*iface->dns));
531 iface->dns[iface->dns_cnt - 1] = addr6;
537 if ((c = tb[IFACE_ATTR_DOMAIN])) {
538 struct blob_attr *cur;
541 blobmsg_for_each_attr(cur, c, rem) {
542 if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING || !blobmsg_check_attr(cur, false))
546 char *domain = blobmsg_get_string(cur);
547 size_t domainlen = strlen(domain);
548 if (domainlen > 0 && domain[domainlen - 1] == '.')
549 domain[domainlen - 1] = 0;
551 int len = dn_comp(domain, buf, sizeof(buf), NULL, NULL);
555 iface->search = realloc(iface->search, iface->search_len + len);
559 memcpy(&iface->search[iface->search_len], buf, len);
560 iface->search_len += len;
564 if ((c = tb[IFACE_ATTR_FILTER_CLASS])) {
565 iface->filter_class = realloc(iface->filter_class, blobmsg_data_len(c) + 1);
566 memcpy(iface->filter_class, blobmsg_get_string(c), blobmsg_data_len(c) + 1);
569 if ((c = tb[IFACE_ATTR_DHCPV6_RAW])) {
570 iface->dhcpv6_raw_len = blobmsg_data_len(c) / 2;
571 iface->dhcpv6_raw = realloc(iface->dhcpv6_raw, iface->dhcpv6_raw_len);
572 odhcpd_unhexlify(iface->dhcpv6_raw, iface->dhcpv6_raw_len, blobmsg_get_string(c));
575 if ((c = tb[IFACE_ATTR_RA_DEFAULT]))
576 iface->default_router = blobmsg_get_u32(c);
578 if ((c = tb[IFACE_ATTR_RA_MANAGEMENT]))
579 iface->managed = blobmsg_get_u32(c);
581 if ((c = tb[IFACE_ATTR_RA_OFFLINK]))
582 iface->ra_not_onlink = blobmsg_get_bool(c);
584 if ((c = tb[IFACE_ATTR_RA_ADVROUTER]))
585 iface->ra_advrouter = blobmsg_get_bool(c);
587 if ((c = tb[IFACE_ATTR_RA_MAXINTERVAL]))
588 iface->ra_maxinterval = blobmsg_get_u32(c);
590 if ((c = tb[IFACE_ATTR_RA_PREFERENCE])) {
591 const char *prio = blobmsg_get_string(c);
593 if (!strcmp(prio, "high"))
594 iface->route_preference = 1;
595 else if (!strcmp(prio, "low"))
596 iface->route_preference = -1;
597 else if (!strcmp(prio, "medium") || !strcmp(prio, "default"))
598 iface->route_preference = 0;
603 if ((c = tb[IFACE_ATTR_PD_MANAGER]))
604 strncpy(iface->dhcpv6_pd_manager, blobmsg_get_string(c),
605 sizeof(iface->dhcpv6_pd_manager) - 1);
607 if ((c = tb[IFACE_ATTR_PD_CER]) &&
608 inet_pton(AF_INET6, blobmsg_get_string(c), &iface->dhcpv6_pd_cer) < 1)
611 if ((c = tb[IFACE_ATTR_NDPROXY_ROUTING]))
612 iface->learn_routes = blobmsg_get_bool(c);
614 if ((c = tb[IFACE_ATTR_NDPROXY_SLAVE]))
615 iface->external = blobmsg_get_bool(c);
620 close_interface(iface);
624 static int set_interface(struct uci_section *s)
626 blob_buf_init(&b, 0);
627 uci_to_blob(&b, s, &interface_attr_list);
629 return config_parse_interface(blob_data(b.head), blob_len(b.head), s->e.name, true);
632 void odhcpd_reload(void)
634 struct uci_context *uci = uci_alloc_context();
636 while (!list_empty(&leases))
637 free_lease(list_first_entry(&leases, struct lease, head));
639 struct interface *master = NULL, *i, *n;
644 list_for_each_entry(i, &interfaces, head)
647 struct uci_package *dhcp = NULL;
648 if (!uci_load(uci, "dhcp", &dhcp)) {
649 struct uci_element *e;
650 uci_foreach_element(&dhcp->sections, e) {
651 struct uci_section *s = uci_to_section(e);
652 if (!strcmp(s->type, "host"))
654 else if (!strcmp(s->type, "odhcpd"))
658 uci_foreach_element(&dhcp->sections, e) {
659 struct uci_section *s = uci_to_section(e);
660 if (!strcmp(s->type, "dhcp"))
665 if (config.dhcp_statefile) {
666 char *path = strdup(config.dhcp_statefile);
668 mkdir_p(dirname(path), 0755);
673 ubus_apply_network();
676 bool any_dhcpv6_slave = false, any_ra_slave = false, any_ndp_slave = false;
679 list_for_each_entry(i, &interfaces, head) {
683 if (i->dhcpv6 == RELAYD_HYBRID || i->dhcpv6 == RELAYD_RELAY)
684 any_dhcpv6_slave = true;
686 if (i->ra == RELAYD_HYBRID || i->ra == RELAYD_RELAY)
689 if (i->ndp == RELAYD_HYBRID || i->ndp == RELAYD_RELAY)
690 any_ndp_slave = true;
693 /* Evaluate hybrid mode for master */
694 list_for_each_entry(i, &interfaces, head) {
698 enum odhcpd_mode hybrid_mode = RELAYD_DISABLED;
700 if (!ubus_has_prefix(i->name, i->ifname))
701 hybrid_mode = RELAYD_RELAY;
704 if (i->dhcpv6 == RELAYD_HYBRID)
705 i->dhcpv6 = hybrid_mode;
707 if (i->dhcpv6 == RELAYD_RELAY && !any_dhcpv6_slave)
708 i->dhcpv6 = RELAYD_DISABLED;
710 if (i->ra == RELAYD_HYBRID)
713 if (i->ra == RELAYD_RELAY && !any_ra_slave)
714 i->ra = RELAYD_DISABLED;
716 if (i->ndp == RELAYD_HYBRID)
717 i->ndp = hybrid_mode;
719 if (i->ndp == RELAYD_RELAY && !any_ndp_slave)
720 i->ndp = RELAYD_DISABLED;
722 if (i->dhcpv6 == RELAYD_RELAY || i->ra == RELAYD_RELAY || i->ndp == RELAYD_RELAY)
727 list_for_each_entry_safe(i, n, &interfaces, head) {
729 /* Resolve hybrid mode */
730 if (i->dhcpv6 == RELAYD_HYBRID)
731 i->dhcpv6 = (master && master->dhcpv6 == RELAYD_RELAY) ?
732 RELAYD_RELAY : RELAYD_SERVER;
734 if (i->ra == RELAYD_HYBRID)
735 i->ra = (master && master->ra == RELAYD_RELAY) ?
736 RELAYD_RELAY : RELAYD_SERVER;
738 if (i->ndp == RELAYD_HYBRID)
739 i->ndp = (master && master->ndp == RELAYD_RELAY) ?
740 RELAYD_RELAY : RELAYD_DISABLED;
742 setup_router_interface(i, !i->ignore || i->ra != RELAYD_DISABLED);
743 setup_dhcpv6_interface(i, !i->ignore || i->dhcpv6 != RELAYD_DISABLED);
744 setup_ndp_interface(i, !i->ignore || i->ndp != RELAYD_DISABLED);
745 setup_dhcpv4_interface(i, !i->ignore || i->dhcpv4 != RELAYD_DISABLED);
751 uci_unload(uci, dhcp);
752 uci_free_context(uci);
755 static void handle_signal(int signal)
759 if (signal == SIGHUP) {
760 if (write(reload_pipe[1], b, sizeof(b)) < 0) {}
765 static void reload_cb(struct uloop_fd *u, _unused unsigned int events)
768 if (read(u->fd, b, sizeof(b)) < 0) {}
773 static struct uloop_fd reload_fd = { .cb = reload_cb };
775 void odhcpd_run(void)
777 if (pipe2(reload_pipe, O_NONBLOCK | O_CLOEXEC) < 0) {}
779 reload_fd.fd = reload_pipe[0];
780 uloop_fd_add(&reload_fd, ULOOP_READ);
782 signal(SIGTERM, handle_signal);
783 signal(SIGINT, handle_signal);
784 signal(SIGHUP, handle_signal);
794 while (!list_empty(&interfaces))
795 close_interface(list_first_entry(&interfaces, struct interface, head));