>From 30feda7b5ce8803b10e4bca8e86e1caaadc71596 Mon Sep 17 00:00:00 2001 In-Reply-To: References: From: =?UTF-8?q?Andr=C3=A9=20Batista?= Date: Thu, 30 Jun 2022 15:36:03 -0300 Subject: [PATCH] services: openssh: Check if IPv6 is supported and start service accordingly. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To: 56327@debbugs.gnu.org Fixes . Reported by André Batista . * gnu/services/ssh.scm (openssh-shepherd-service)[ipv6-support?]: New variable. : Use it. When using 'make-inetd-constructor', only pass a ipv6 endpoint if the system supports it. --- gnu/services/ssh.scm | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/gnu/services/ssh.scm b/gnu/services/ssh.scm index 57d3ad218c..050c3aa7c3 100644 --- a/gnu/services/ssh.scm +++ b/gnu/services/ssh.scm @@ -8,6 +8,7 @@ ;;; Copyright © 2020 Oleg Pykhalov ;;; Copyright © 2020 Brice Waegeneire ;;; Copyright © 2021 Tobias Geerinckx-Rice +;;; Copyright © 2022 André Batista ;;; ;;; This file is part of GNU Guix. ;;; @@ -536,23 +537,36 @@ (define inetd-style? #~(and (defined? 'make-inetd-constructor) (not (string=? (@ (shepherd config) Version) "0.9.0")))) + (define ipv6-support? + ;; Helper function to start/stop ssh service on systems with no IPv6. + ;; See https://issues.guix.gnu.org/56327. + #~(false-if-exception (socket AF_INET6 SOCK_STREAM 0))) + (list (shepherd-service (documentation "OpenSSH server.") (requirement '(syslogd loopback)) (provision '(ssh-daemon ssh sshd)) - (start #~(if #$inetd-style? - (make-inetd-constructor - (append #$openssh-command '("-i")) - (list (endpoint - (make-socket-address AF_INET INADDR_ANY - #$port-number)) - (endpoint - (make-socket-address AF_INET6 IN6ADDR_ANY - #$port-number))) - #:max-connections #$max-connections) - (make-forkexec-constructor #$openssh-command - #:pid-file #$pid-file))) + (start #~(cond ((and #$inetd-style? #$ipv6-support?) + (make-inetd-constructor + (append #$openssh-command '("-i")) + (list (endpoint + (make-socket-address AF_INET INADDR_ANY + #$port-number)) + (endpoint + (make-socket-address AF_INET6 IN6ADDR_ANY + #$port-number))) + #:max-connections #$max-connections)) + ((and #$inetd-style? (not #$ipv6-support?)) + (make-inetd-constructor + (append #$openssh-command '("-i")) + (list (endpoint + (make-socket-address AF_INET INADDR_ANY + #$port-number))) + #:max-connections #$max-connections)) + (else + (make-forkexec-constructor #$openssh-command + #:pid-file #$pid-file)))) (stop #~(if #$inetd-style? (make-inetd-destructor) (make-kill-destructor))) -- 2.36.0