From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Leo =?UTF-8?Q?Nikkil=C3=A4?= via "Bug reports for GUILE, GNU's Ubiquitous Extension Language" Newsgroups: gmane.lisp.guile.bugs Subject: bug#65399: [PATCH] web: Fix non-IPv4 default socket. Date: Sun, 20 Aug 2023 12:15:37 +0300 Message-ID: <20230820091541.22760-1-hello@lnikki.la> Reply-To: Leo =?UTF-8?Q?Nikkil=C3=A4?= Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15476"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Leo =?UTF-8?Q?Nikkil=C3=A4?= To: 65399@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Sun Aug 20 11:17:38 2023 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qXeYy-0003oT-Bn for guile-bugs@m.gmane-mx.org; Sun, 20 Aug 2023 11:17:37 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qXeYS-0000Nd-5N; Sun, 20 Aug 2023 05:17:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qXeYP-0000NM-MY for bug-guile@gnu.org; Sun, 20 Aug 2023 05:17:01 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qXeYP-0003oH-E9 for bug-guile@gnu.org; Sun, 20 Aug 2023 05:17:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qXeYQ-0005Ti-J5 for bug-guile@gnu.org; Sun, 20 Aug 2023 05:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Leo =?UTF-8?Q?Nikkil=C3=A4?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sun, 20 Aug 2023 09:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 65399 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.169252297320989 (code B ref -1); Sun, 20 Aug 2023 09:17:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Aug 2023 09:16:13 +0000 Original-Received: from localhost ([127.0.0.1]:53101 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qXeXd-0005SS-3D for submit@debbugs.gnu.org; Sun, 20 Aug 2023 05:16:13 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:54260) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qXeXY-0005S3-Eu for submit@debbugs.gnu.org; Sun, 20 Aug 2023 05:16:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qXeXR-0000E1-7F for bug-guile@gnu.org; Sun, 20 Aug 2023 05:16:01 -0400 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qXeXO-0003jr-Cv for bug-guile@gnu.org; Sun, 20 Aug 2023 05:16:00 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 8A6995C00C6; Sun, 20 Aug 2023 05:15:55 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 20 Aug 2023 05:15:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lnikki.la; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:sender:subject :subject:to:to; s=fm2; t=1692522955; x=1692609355; bh=teGudweu/I fXVCdEzcDrnz1Ylko6cFZcaPHcJALYOxo=; b=p4qoC/ScalUwZq9cg4/8HxSZfi GYmeabeqAq9E5Rs8eB7rgmNSu44JkR8mKZ1lE4K+TyDGN0ccH6J1xoPYMzNg3Hjr yW+Iu4K6B7sNlyZlXNp2mjvjSe4xpX0yiWlqvQzOGIn0CC19a23iqXz3aqiuao5e qZXH5OMknRrVj9NM6JJGJzfdzh0V3zjGu4sKoaj+Ys+TuWBN/Osd7uOwoFa43oDy 51LWuMdGYj04ccnjXP53caWcop1kcJkjE9O/dNCNRN4MiSJrk8umPj/Vslfp9T6Q AvdLKhXJgj06cRbmgS9mJybjhs6OENwetxUvdmSpnpmn2MGpFc4HMQYcc+6Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1692522955; x=1692609355; bh=teGudweu/IfXV CdEzcDrnz1Ylko6cFZcaPHcJALYOxo=; b=n00kBBY2J4QosGNS1jqeQZc8uCoX7 B0OoNPbAoxlv74eHvZMVqWnzrhGLdSEAWyelvvp4CyBSAfYWlKRE1nt1YkRMcYd3 1w4PXxYHAX2LQlgkNukwf7+DKyh7xhkSKIj/sMOMit5/T2befw4LmsKoPTSaMm9B jSYCnK3SnQ4vx9NxzRI2DKwLHLuHu6+ctxL/h5KKAyntTgMeVDRIlAVEXDHsTlmX r07UF27LGEvCwU/0xXAhajSkwjdvADEEyB5ONVKzGQhMyUfbUL/mh6yZ2TuIghrG GUc/QgU3YqN63R7TklFC2/uahEXHetW/8n3xbjJr/ns5lEMfusr9Dsw9Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedruddujedgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffoggfgsedtkeertd ertdejnecuhfhrohhmpefnvghoucfpihhkkhhilhomuceohhgvlhhloheslhhnihhkkhhi rdhlrgeqnecuggftrfgrthhtvghrnhephfffgfduieeljedtffevgfejjeekhfevhfffhf ffheegffehheeifffgveeiudfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghm pehmrghilhhfrhhomhephhgvlhhloheslhhnihhkkhhirdhlrg X-ME-Proxy: Feedback-ID: i41f146a7:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 20 Aug 2023 05:15:54 -0400 (EDT) X-Mailer: git-send-email 2.41.0 Received-SPF: pass client-ip=66.111.4.28; envelope-from=hello@lnikki.la; helo=out4-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10655 Archived-At: PF_INET sockets were being created by default with #:family AF_INET6 or AF_UNIX, resulting in In procedure bind: Address family not supported by protocol * module/web/server/http.scm (make-default-socket): Use #:family. * doc/ref/web.texi (Web Server): Fix quoting in documentation, bind to suitable address. * test-suite/tests/web-server.test: Test it. --- doc/ref/web.texi | 4 ++- module/web/server/http.scm | 2 +- test-suite/tests/web-server.test | 59 +++++++++++++++++++------------- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/doc/ref/web.texi b/doc/ref/web.texi index 607c855b6..d76529456 100644 --- a/doc/ref/web.texi +++ b/doc/ref/web.texi @@ -1827,7 +1827,9 @@ implementation's open function. ;; On a different port (run-server handler 'http '(#:port 8081)) ;; IPv6 -(run-server handler 'http '(#:family AF_INET6 #:port 8081)) +(run-server handler 'http `(#:family ,AF_INET6 + #:addr ,IN6ADDR_LOOPBACK + #:port 8081)) ;; Custom socket (run-server handler 'http `(#:socket ,(sudo-make-me-a-socket))) @end example diff --git a/module/web/server/http.scm b/module/web/server/http.scm index 05bf46bf0..447282f4c 100644 --- a/module/web/server/http.scm +++ b/module/web/server/http.scm @@ -39,7 +39,7 @@ (define (make-default-socket family addr port) - (let ((sock (socket PF_INET SOCK_STREAM 0))) + (let ((sock (socket family SOCK_STREAM 0))) (setsockopt sock SOL_SOCKET SO_REUSEADDR 1) (bind sock family addr port) sock)) diff --git a/test-suite/tests/web-server.test b/test-suite/tests/web-server.test index d84c47d18..38e23e791 100644 --- a/test-suite/tests/web-server.test +++ b/test-suite/tests/web-server.test @@ -56,14 +56,42 @@ '((content-type . (application/octet-stream)))) (string->utf8 "forbidden"))))) -(define %port-number 8885) +(define %port-number4 8885) +(define %port-number6 8886) (define %server-base-uri "http://localhost:8885") (when (provided? 'threads) - ;; Run a local publishing server in a separate thread. + ;; Run local publishing servers (IPv4, IPv6) in separate threads. (call-with-new-thread (lambda () - (run-server handle-request 'http `(#:port ,%port-number))))) + (run-server handle-request 'http `(#:port ,%port-number4)))) + (call-with-new-thread + (lambda () + (run-server handle-request 'http `(#:family ,AF_INET6 + #:addr ,IN6ADDR_LOOPBACK + #:port ,%port-number6))))) + +(define (connect-to-server family addr port-number) + (let ((socket (socket family SOCK_STREAM 0))) + (let loop ((n 1)) + (define success? + (catch 'system-error + (lambda () + (format (current-error-port) + "connecting to the server, attempt #~a~%" n) + (connect socket family addr port-number) + (close-port socket) + #t) + (lambda args + (if (and (= ECONNREFUSED (system-error-errno args)) + (<= n 15)) + #f + (apply throw args))))) + + (or success? + (begin + (sleep 1) + (loop (+ n 1))))))) (define-syntax-rule (expect method path code args ...) (if (provided? 'threads) @@ -79,26 +107,11 @@ (pass-if "server is listening" ;; First, wait until the server is listening, up to a few seconds. (if (provided? 'threads) - (let ((socket (socket AF_INET SOCK_STREAM 0))) - (let loop ((n 1)) - (define success? - (catch 'system-error - (lambda () - (format (current-error-port) - "connecting to the server, attempt #~a~%" n) - (connect socket AF_INET INADDR_LOOPBACK %port-number) - (close-port socket) - #t) - (lambda args - (if (and (= ECONNREFUSED (system-error-errno args)) - (<= n 15)) - #f - (apply throw args))))) - - (or success? - (begin - (sleep 1) - (loop (+ n 1)))))) + (begin + (format (current-error-port) "connecting using IPv4...~%") + (connect-to-server AF_INET INADDR_LOOPBACK %port-number4) + (format (current-error-port) "connecting using IPv6...~%") + (connect-to-server AF_INET6 IN6ADDR_LOOPBACK %port-number6)) (throw 'unresolved))) (pass-if-equal "GET /" base-commit: c7632b8f974abc3bb654e116d62e4165c39490af -- 2.41.0