]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP: Simplify opening the UDP port for all interfaces.
authorRoy Marples <roy@marples.name>
Fri, 25 Oct 2019 13:44:23 +0000 (14:44 +0100)
committerRoy Marples <roy@marples.name>
Fri, 25 Oct 2019 13:44:23 +0000 (14:44 +0100)
src/dhcp.c

index 2dd0bbda2f89e2c163794ccf237606676b303ba3..f14863bbc7ee139feaeb39c399472ceae305bef0 100644 (file)
@@ -3532,7 +3532,17 @@ dhcp_handleifudp(void *arg)
        struct interface *ifp = arg;
 
        dhcp_readudp(ifp->ctx, ifp);
+}
+
+static int
+dhcp_open(struct dhcpcd_ctx *ctx)
+{
 
+       if (ctx->udp_fd != -1 || (ctx->udp_fd = dhcp_openudp(NULL)) == -1)
+               return ctx->udp_fd;
+
+       eloop_event_add(ctx->eloop, ctx->udp_fd, dhcp_handleudp, ctx);
+       return ctx->udp_fd;
 }
 
 static int
@@ -3743,16 +3753,13 @@ dhcp_start1(void *arg)
         * ICMP port unreachable message back to the DHCP server.
         * Only do this in master mode so we don't swallow messages
         * for dhcpcd running on another interface. */
-       if (ctx->udp_fd == -1 && ctx->options & DHCPCD_MASTER) {
-               ctx->udp_fd = dhcp_openudp(NULL);
-               if (ctx->udp_fd == -1) {
+       if (ctx->options & DHCPCD_MASTER) {
+               if (dhcp_open(ctx) == -1) {
                        /* Don't log an error if some other process
                         * is handling this. */
                        if (errno != EADDRINUSE)
-                               logerr("%s: dhcp_openudp", __func__);
-               } else
-                       eloop_event_add(ctx->eloop,
-                           ctx->udp_fd, dhcp_handleudp, ctx);
+                               logerr("%s: dhcp_open", __func__);
+               }
        }
 
        if (dhcp_init(ifp) == -1) {