X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fodhcpd.git;a=blobdiff_plain;f=src%2Fodhcpd.c;h=3c384e831cd5b76267e0981fb7b9b766ec9466d8;hp=794bbfc00648b6b08ad0bffe1944e03fd862ad38;hb=ee243b09f3c81f824cc463c1c757e905f882350e;hpb=1bbf34a1df3e16865b3b9330b338952076bc26f9 diff --git a/src/odhcpd.c b/src/odhcpd.c index 794bbfc..3c384e8 100644 --- a/src/odhcpd.c +++ b/src/odhcpd.c @@ -49,6 +49,12 @@ static int rtnl_seq = 0; static int urandom_fd = -1; +static void sighandler(_unused int signal) +{ + uloop_end(); +} + + int main() { openlog("odhcpd", LOG_PERROR | LOG_PID, LOG_DAEMON); @@ -71,6 +77,8 @@ int main() return 4; signal(SIGUSR1, SIG_IGN); + signal(SIGINT, sighandler); + signal(SIGTERM, sighandler); if (init_router()) return 4; @@ -172,7 +180,7 @@ ssize_t odhcpd_send(int socket, struct sockaddr_in6 *dest, ssize_t sent = sendmsg(socket, &msg, MSG_DONTWAIT); if (sent < 0) - syslog(LOG_WARNING, "Failed to send to %s%%%s (%s)", + syslog(LOG_NOTICE, "Failed to send to %s%%%s (%s)", ipbuf, iface->ifname, strerror(errno)); else syslog(LOG_DEBUG, "Sent %li bytes to %s%%%s", @@ -255,6 +263,25 @@ ssize_t odhcpd_get_interface_addresses(int ifindex, return ret; } +int odhcpd_get_preferred_interface_address(int ifindex, struct in6_addr *addr) +{ + struct odhcpd_ipaddr ipaddrs[8]; + ssize_t ip_cnt = odhcpd_get_interface_addresses(ifindex, ipaddrs, ARRAY_SIZE(ipaddrs)); + uint32_t preferred = 0; + int ret = 0; + + for (ssize_t i = 0; i < ip_cnt; i++) { + struct odhcpd_ipaddr *ipaddr = &ipaddrs[i]; + + if (ipaddr->preferred > preferred || !preferred) { + preferred = ipaddr->preferred; + *addr = ipaddr->addr; + ret = 1; + } + } + + return ret; +} struct interface* odhcpd_get_interface_by_index(int ifindex) { @@ -377,6 +404,11 @@ int odhcpd_register(struct odhcpd_event *event) return uloop_fd_add(&event->uloop, ULOOP_READ); } +void odhcpd_process(struct odhcpd_event *event) +{ + odhcpd_receive_packets(&event->uloop, 0); +} + void odhcpd_urandom(void *data, size_t len) { read(urandom_fd, data, len);