dhcpv4: fix lease ordering by ip address
[oweals/odhcpd.git] / src / odhcpd.c
index 8a6114892d5e38018ef3c90c6d736a86a440c291..4b8e5898d450bc661e0f4d29b48dfff1f35a101c 100644 (file)
@@ -45,7 +45,7 @@
 
 
 
-static int ioctl_sock;
+static int ioctl_sock = -1;
 static int urandom_fd = -1;
 
 static void sighandler(_unused int signal)
@@ -209,7 +209,7 @@ ssize_t odhcpd_send(int socket, struct sockaddr_in6 *dest,
 
        ssize_t sent = sendmsg(socket, &msg, MSG_DONTWAIT);
        if (sent < 0)
-               syslog(LOG_NOTICE, "Failed to send to %s%%%s@%s (%m)",
+               syslog(LOG_ERR, "Failed to send to %s%%%s@%s (%m)",
                                ipbuf, iface->name, iface->ifname);
        else
                syslog(LOG_DEBUG, "Sent %zd bytes to %s%%%s@%s",
@@ -291,36 +291,15 @@ int odhcpd_get_interface_dns_addr(const struct interface *iface, struct in6_addr
 struct interface* odhcpd_get_interface_by_index(int ifindex)
 {
        struct interface *iface;
-       list_for_each_entry(iface, &interfaces, head)
-               if (iface->ifindex == ifindex)
-                       return iface;
-
-       return NULL;
-}
-
-
-struct interface* odhcpd_get_interface_by_name(const char *name)
-{
-       struct interface *iface;
-       list_for_each_entry(iface, &interfaces, head)
-               if (!strcmp(iface->ifname, name))
-                       return iface;
 
-       return NULL;
-}
-
-
-struct interface* odhcpd_get_master_interface(void)
-{
-       struct interface *iface;
-       list_for_each_entry(iface, &interfaces, head)
-               if (iface->master)
+       avl_for_each_element(&interfaces, iface, avl) {
+               if (iface->ifindex == ifindex)
                        return iface;
+       }
 
        return NULL;
 }
 
-
 /* Convenience function to receive and do basic validation of packets */
 static void odhcpd_receive_packets(struct uloop_fd *u, _unused unsigned int events)
 {
@@ -417,7 +396,8 @@ static void odhcpd_receive_packets(struct uloop_fd *u, _unused unsigned int even
                        return;
                } else if (destiface != 0) {
                        struct interface *iface;
-                       list_for_each_entry(iface, &interfaces, head) {
+
+                       avl_for_each_element(&interfaces, iface, avl) {
                                if (iface->ifindex != destiface)
                                        continue;