Skip to content

Commit 609854d

Browse files
committed
server/sockets.c: Don't fail to start if ipv6.disable=1
If ipv6.disable=1 is used on the Linux kernel command line, getaddrinfo still returns AF_INET6 sockets but the subsequent socket(2) call fails with EAFNOSUPPORT: $ cat /proc/cmdline BOOT_IMAGE=(hd0,gpt2)/vmlinuz-5.17.13-300.fc36.x86_64 root=UUID=0c643cb4-703c-4625-9ba8-93e208b9b827 ro console=tty0 rd_NO_PLYMOUTH console=ttyS0,115200 ipv6.disable=1 pcie_aspm=off net.ifnames=0 $ nbdkit -p 10000 null bind_tcpip_socket: socket: Address family not supported by protocol I believe it's safe to ignore this case, as long as we manage to open at least one socket (eg. AF_INET). Reported-by: Bogac Tekman Fixes: https://aur.archlinux.org/packages/nbdkit#comment-877225
1 parent 5892e14 commit 609854d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

server/sockets.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,20 @@ bind_tcpip_socket (sockets *socks)
209209
sock = set_cloexec (socket (a->ai_family, a->ai_socktype, a->ai_protocol));
210210
#endif
211211
if (sock == -1) {
212-
perror ("bind_tcpip_socket: socket");
213-
exit (EXIT_FAILURE);
212+
if (errno == EAFNOSUPPORT) {
213+
/* If ipv6.disable=1 was specified to the Linux kernel then
214+
* getaddrinfo may still return AF_INET6 sockets but socket(2)
215+
* will return this error. I think it's safe to basically
216+
* ignore this error.
217+
*/
218+
saved_errno = errno;
219+
debug ("bind_tcpip_socket: socket: %m (ignored)");
220+
continue;
221+
}
222+
else {
223+
perror ("bind_tcpip_socket: socket");
224+
exit (EXIT_FAILURE);
225+
}
214226
}
215227

216228
opt = 1;

0 commit comments

Comments
 (0)