]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP: Rework closing BPF and seeing if we need to open UDP
authorRoy Marples <roy@marples.name>
Fri, 25 Oct 2019 14:04:12 +0000 (15:04 +0100)
committerRoy Marples <roy@marples.name>
Fri, 25 Oct 2019 14:04:12 +0000 (15:04 +0100)
Just easier to read.

src/dhcp.c

index f14863bbc7ee139feaeb39c399472ceae305bef0..7e590df9d60938436ba3fa94a5df9bcc63e0d3bf 100644 (file)
@@ -2261,26 +2261,25 @@ dhcp_bind(struct interface *ifp)
 
        /* Close the BPF filter as we can now receive DHCP messages
         * on a UDP socket. */
-       if (state->udp_fd == -1 ||
-           (state->old != NULL && state->old->yiaddr != state->new->yiaddr))
-       {
-               dhcp_close(ifp);
-               /* If not in master mode, open an address specific socket. */
-               if (ctx->udp_fd == -1) {
-                       state->udp_fd = dhcp_openudp(ifp);
-                       if (state->udp_fd == -1) {
-                               logerr(__func__);
-                               /* Address sharing without master mode is
-                                * not supported. It's also possible another
-                                * DHCP client could be running which is
-                                * even worse.
-                                * We still need to work, so re-open BPF. */
-                               dhcp_openbpf(ifp);
-                       } else
-                               eloop_event_add(ctx->eloop,
-                                   state->udp_fd, dhcp_handleifudp, ifp);
-               }
+       if (!(state->udp_fd == -1 ||
+           (state->old != NULL && state->old->yiaddr != state->new->yiaddr)))
+               return;
+       dhcp_close(ifp);
+
+       /* If not in master mode, open an address specific socket. */
+       if (ctx->udp_fd != -1)
+               return;
+       state->udp_fd = dhcp_openudp(ifp);
+       if (state->udp_fd == -1) {
+               logerr(__func__);
+               /* Address sharing without master mode is not supported.
+                * It's also possible another DHCP client could be running,
+                * which is even worse.
+                * We still need to work, so re-open BPF. */
+               dhcp_openbpf(ifp);
+               return;
        }
+       eloop_event_add(ctx->eloop, state->udp_fd, dhcp_handleifudp, ifp);
 }
 
 static void