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

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