Blame SOURCES/0001-Automatically-disable-inet6-transport-if-ipv6-is-dis.patch

26ea39
From 8302f576f8b41f9aa95b091a9ef001ab5ddc2ef5 Mon Sep 17 00:00:00 2001
26ea39
From: Ray Strode <rstrode@redhat.com>
26ea39
Date: Fri, 6 May 2022 14:23:59 -0400
26ea39
Subject: [PATCH] Automatically disable inet6 transport if ipv6 is disabled on
26ea39
 machine
26ea39
26ea39
If a machine is booted with ipv6.disable=1, trying to bind to an
26ea39
AF_INET6 socket will fail with AFNOSUPPORT.
26ea39
26ea39
The tcp transport automatically falls back to ipv4 in this case, but
26ea39
the more specific inet6 transport just fails.
26ea39
26ea39
This failure leads to MakeAllCOTSServerListeners returning a partial
26ea39
success.
26ea39
26ea39
Unfortunately, the X server can't really contiue with partial successes
26ea39
from this function if -displayfd is in use, since that would, in other
26ea39
cases, potentially lead to the -displayfd electing a display number that
26ea39
is potentially partially in use by a rogue program.
26ea39
26ea39
This commit addresses the issue by automatically disabling transports
26ea39
when they fail with AFNOSUPPORT, leading them to get ignored, rather than
26ea39
proceeding and ultimately returning from MakeAllCOTSServerListerns with
26ea39
partial=TRUE.
26ea39
---
26ea39
 Xtranssock.c | 15 +++++++++++----
26ea39
 1 file changed, 11 insertions(+), 4 deletions(-)
26ea39
26ea39
diff --git a/Xtranssock.c b/Xtranssock.c
26ea39
index 632c1b5..2c80a5c 100644
26ea39
--- a/Xtranssock.c
26ea39
+++ b/Xtranssock.c
26ea39
@@ -584,66 +584,73 @@ TRANS(SocketOpenCOTSClient) (Xtransport *thistrans, const char *protocol,
26ea39
 			     const char *host, const char *port)
26ea39
 {
26ea39
     return TRANS(SocketOpenCOTSClientBase)(
26ea39
 			thistrans->TransName, protocol, host, port, -1);
26ea39
 }
26ea39
 
26ea39
 
26ea39
 #endif /* TRANS_CLIENT */
26ea39
 
26ea39
 
26ea39
 #ifdef TRANS_SERVER
26ea39
 
26ea39
 static XtransConnInfo
26ea39
 TRANS(SocketOpenCOTSServer) (Xtransport *thistrans, const char *protocol,
26ea39
 			     const char *host, const char *port)
26ea39
 
26ea39
 {
26ea39
     XtransConnInfo	ciptr;
26ea39
     int	i = -1;
26ea39
 
26ea39
     prmsg (2,"SocketOpenCOTSServer(%s,%s,%s)\n", protocol, host, port);
26ea39
 
26ea39
     SocketInitOnce();
26ea39
 
26ea39
     while ((i = TRANS(SocketSelectFamily) (i, thistrans->TransName)) >= 0) {
26ea39
 	if ((ciptr = TRANS(SocketOpen) (
26ea39
 		 i, Sockettrans2devtab[i].devcotsname)) != NULL)
26ea39
 	    break;
26ea39
     }
26ea39
     if (i < 0) {
26ea39
-	if (i == -1)
26ea39
-	    prmsg (1,"SocketOpenCOTSServer: Unable to open socket for %s\n",
26ea39
-		   thistrans->TransName);
26ea39
-	else
26ea39
+	if (i == -1) {
26ea39
+		if (errno == EAFNOSUPPORT) {
26ea39
+			thistrans->flags |= TRANS_NOLISTEN;
26ea39
+			prmsg (1,"SocketOpenCOTSServer: Socket for %s unsupported on this system.\n",
26ea39
+			       thistrans->TransName);
26ea39
+		} else {
26ea39
+			prmsg (1,"SocketOpenCOTSServer: Unable to open socket for %s\n",
26ea39
+			       thistrans->TransName);
26ea39
+		}
26ea39
+	} else {
26ea39
 	    prmsg (1,"SocketOpenCOTSServer: Unable to determine socket type for %s\n",
26ea39
 		   thistrans->TransName);
26ea39
+	}
26ea39
 	return NULL;
26ea39
     }
26ea39
 
26ea39
     /*
26ea39
      * Using this prevents the bind() check for an existing server listening
26ea39
      * on the same port, but it is required for other reasons.
26ea39
      */
26ea39
 #ifdef SO_REUSEADDR
26ea39
 
26ea39
     /*
26ea39
      * SO_REUSEADDR only applied to AF_INET && AF_INET6
26ea39
      */
26ea39
 
26ea39
     if (Sockettrans2devtab[i].family == AF_INET
26ea39
 #if defined(IPv6) && defined(AF_INET6)
26ea39
       || Sockettrans2devtab[i].family == AF_INET6
26ea39
 #endif
26ea39
     )
26ea39
     {
26ea39
 	int one = 1;
26ea39
 	setsockopt (ciptr->fd, SOL_SOCKET, SO_REUSEADDR,
26ea39
 		    (char *) &one, sizeof (int));
26ea39
     }
26ea39
 #endif
26ea39
 #ifdef IPV6_V6ONLY
26ea39
     if (Sockettrans2devtab[i].family == AF_INET6)
26ea39
     {
26ea39
 	int one = 1;
26ea39
 	setsockopt(ciptr->fd, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(int));
26ea39
     }
26ea39
-- 
26ea39
2.35.1
26ea39