changeset 5293:b161ecf0b891 draft

privsep: Only open raw sockets for the needed protocols. 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.
author Roy Marples <roy@marples.name>
date Mon, 01 Jun 2020 18:59:08 +0100
parents 2f2b53b05dc5
children 942ddb46cd55
files src/privsep-inet.c src/privsep-root.c
diffstat 2 files changed, 18 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/privsep-inet.c	Mon Jun 01 15:38:51 2020 +0100
+++ b/src/privsep-inet.c	Mon Jun 01 18:59:08 2020 +0100
@@ -170,8 +170,8 @@
 	}
 #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)
--- a/src/privsep-root.c	Mon Jun 01 15:38:51 2020 +0100
+++ b/src/privsep-root.c	Mon Jun 01 18:59:08 2020 +0100
@@ -607,19 +607,26 @@
 	 * 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