]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
If we fail to open sockets, don't bother sending the request.
authorRoy Marples <roy@marples.name>
Mon, 6 Aug 2012 10:24:13 +0000 (10:24 +0000)
committerRoy Marples <roy@marples.name>
Mon, 6 Aug 2012 10:24:13 +0000 (10:24 +0000)
dhcpcd.c
dhcpcd.h

index 06026c484705eeb75650702961ffe9d73ef96ea8..52d198fbb0d312c9019c25c0494492233191ed70 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -326,7 +326,11 @@ send_message(struct interface *iface, int type,
        }
 
        /* Ensure sockets are open. */
-       open_sockets(iface);
+       if (open_sockets(iface) == -1) {
+               if (!(options & DHCPCD_TEST))
+                       drop_dhcp(iface, "FAIL");
+               return;
+       }
 
        /* If we couldn't open a UDP port for our IP address
         * then we cannot renew.
@@ -1710,11 +1714,13 @@ handle_args(struct fd_list *fd, int argc, char **argv)
        return 0;
 }
 
-void
+int
 open_sockets(struct interface *iface)
 {
+       int r = 0;
+
        if (iface->raw_fd == -1) {
-               if (open_socket(iface, ETHERTYPE_IP) == -1)
+               if ((r = open_socket(iface, ETHERTYPE_IP)) == -1)
                        syslog(LOG_ERR, "%s: open_socket: %m", iface->name);
                else
                        add_event(iface->raw_fd, handle_dhcp_packet, iface);
@@ -1725,9 +1731,12 @@ open_sockets(struct interface *iface)
            (iface->state->new->cookie == htonl(MAGIC_COOKIE) ||
            iface->state->options->options & DHCPCD_INFORM))
        {
-               if (open_udp_socket(iface) == -1 && errno != EADDRINUSE)
+               if (open_udp_socket(iface) == -1 && errno != EADDRINUSE) {
                        syslog(LOG_ERR, "%s: open_udp_socket: %m", iface->name);
+                       r = -1;
+               }
        }
+       return r;
 }
 
 void
index fbee398893c93fc6b972a1e523acd3e3cdab1142..1f229522fe583cdfae4ba4281987bf4a139cb88e 100644 (file)
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -141,7 +141,7 @@ void start_rebind(void *);
 void start_reboot(struct interface *);
 void start_expire(void *);
 void send_decline(struct interface *);
-void open_sockets(struct interface *);
+int open_sockets(struct interface *);
 void close_sockets(struct interface *);
 void drop_dhcp(struct interface *, const char *);
 void drop_interface(struct interface *, const char *);