xorg-x11-xtrans-devel/SOURCES/0001-Automatically-disable-...

114 lines
3.3 KiB
Diff

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