]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
privsep: Only open raw sockets for the needed protocols.
authorRoy Marples <roy@marples.name>
Mon, 1 Jun 2020 17:59:08 +0000 (18:59 +0100)
committerRoy Marples <roy@marples.name>
Mon, 1 Jun 2020 17:59:08 +0000 (18:59 +0100)
Just warn about any errors rather than forcing an early exit as well.
While here, fix startup if DHCPv6 disabled globally but enabled per if.

src/privsep-inet.c
src/privsep-root.c

index 8bf0474ca87f4c38a2a00d2bafa1ffc46c555359..48fb19a20e5d52b40e33b406fa455de30a9e8963 100644 (file)
@@ -170,8 +170,8 @@ ps_inet_startcb(void *arg)
        }
 #endif
 #ifdef DHCP6
-       if ((ctx->options & (DHCPCD_DHCP6 | DHCPCD_MASTER)) ==
-           (DHCPCD_DHCP6 | DHCPCD_MASTER))
+       if ((ctx->options & (DHCPCD_IPV6 | DHCPCD_MASTER)) ==
+           (DHCPCD_IPV6 | DHCPCD_MASTER))
        {
                ctx->dhcp6_rfd = dhcp6_openudp(0, NULL);
                if (ctx->dhcp6_rfd == -1)
index 942fdd8474290d45c2262f9aa80230ee66aaf3d5..04e197423856e869bc08fd68eb02c77340925712 100644 (file)
@@ -607,19 +607,26 @@ ps_root_startcb(void *arg)
         * but makes life very easy for unicasting DHCPv6 in non master
         * mode as we no longer care about address selection. */
 #ifdef INET
-       ctx->udp_wfd = xsocket(PF_INET, SOCK_RAW | SOCK_CXNB, IPPROTO_UDP);
-       if (ctx->udp_wfd == -1)
-               return -1;
+       if (ctx->options & DHCPCD_IPV4) {
+               ctx->udp_wfd = xsocket(PF_INET,
+                   SOCK_RAW | SOCK_CXNB, IPPROTO_UDP);
+               if (ctx->udp_wfd == -1)
+                       logerr("%s: dhcp_openraw", __func__);
+       }
 #endif
 #ifdef INET6
-       ctx->nd_fd = ipv6nd_open(false);
-       if (ctx->nd_fd == -1)
-               return -1;
+       if (ctx->options & DHCPCD_IPV6) {
+               ctx->nd_fd = ipv6nd_open(false);
+               if (ctx->udp_wfd == -1)
+                       logerr("%s: ipv6nd_open", __func__);
+       }
 #endif
 #ifdef DHCP6
-       ctx->dhcp6_wfd = dhcp6_openraw();
-       if (ctx->dhcp6_wfd == -1)
-               return -1;
+       if (ctx->options & DHCPCD_IPV6) {
+               ctx->dhcp6_wfd = dhcp6_openraw();
+               if (ctx->udp_wfd == -1)
+                       logerr("%s: dhcp6_openraw", __func__);
+       }
 #endif
 
 #ifdef PLUGIN_DEV