[PATCH] Address already in use (98) when binding to localhost

Christian Kujau <[email protected]>
Newsgroups gmane.network.stunnel.user
Message-ID <[email protected]>
Hi,

I reported the following to the Fedora bugtracker[0], but only then
realized that this happens with the upstream version too. In short:
since stunnel 5.44 I am no longer able to have stunnel bind to
localhost, when "localhost" is literally mentioned in the configuration
file:

$ cat stunnel.test [test]
client          = yes
protocol        = smtp
accept          = localhost:12345
connect         = localhost:2025


$ stunnel-5.44 stunnel.test [...]
[ ] Binding service [test]
[ ] Listening file descriptor created (FD=6)
[ ] Option SO_REUSEADDR set on accept socket
[ ] Service [test] (FD=6) bound to 127.0.0.1:12345
[ ] Listening file descriptor created (FD=7)
[ ] Option SO_REUSEADDR set on accept socket
[!] bind: Address already in use (98)
[!] Error binding service [test] to 127.0.0.1:12345
[ ] Unbinding service [test]
[ ] Service [test] closed (FD=6)
[ ] Service [test] closed


When using "127.0.0.1" or "::1" instead of "localhost" in the
configuration file, stunnel-5.44 works. However, then one can only
connect to either the IPv4 _or_ the IPv6 address, depending on what's
configured. With stunnel-5.43 and "accept=localhost:12345" both IPv4 and
IPv6 was available.

I suspect that this is related to the following change log entry for 5.44:

 > Default accept address restored to INADDR_ANY.
I have attached a patch to revert that (?) change and also included a
test script that fails on my system when the patch is not applied.

I see "Version 5.45" already mention in the changelog on the website,
but now download yet?

Thanks,
Christian.

[0] https://bugzilla.redhat.com/show_bug.cgi?id=1542361
-- 
BOFH excuse #424:

operation failed because: there is no message for this error (#1014)

_______________________________________________
stunnel-users mailing list
[email protected]
https://www.stunnel.org/cgi-bin/mailman/listinfo/stunnel-users
stunnel_test_019.diff.txt (text/plain, 965 B)
--- /dev/null	2018-02-05 14:57:29.436074709 -0800
+++ tests/recipes/019_localhost	2018-02-06 00:45:59.964728931 -0800
@@ -0,0 +1,32 @@
+#!/bin/sh
+. $(dirname $0)/../test_library
+
+start() {
+  ../../src/stunnel -fd 0 <<EOT
+  debug = debug
+  syslog = no
+  pid = ${result_path}/stunnel.pid
+  output = ${result_path}/stunnel.log
+
+  [https client]
+  client = yes
+  accept = localhost:${http1}
+  connect = localhost:${https}
+
+  [https server]
+  accept = localhost:${https}
+  connect = localhost:${http2}
+  cert = ${script_path}/certs/stunnel.pem
+EOT
+}
+
+check_ports "019_localhost"
+if grep -q "IPv6" "results.log" && PATH="${PATH}:/sbin:/usr/sbin" ifconfig | grep -q "inet6" && [ -n "$(command -v ncat)" ] # nc does not support IPv6
+  then
+    start 2> "error.log"
+    test_log_for "019_localhost" "success" "$1" 2>> "stderr.log"
+    exit $?
+  else
+    exit_logs "019_localhost" "skipped"
+    exit 125
+  fi
stunnel_addrlist_clear.diff.txt (text/plain, 419 B)
--- src/options.c.orig	2017-11-14 23:06:12.000000000 -0800
+++ src/options.c	2018-02-06 00:01:58.892498016 -0800
@@ -1151,7 +1151,7 @@ NOEXPORT char *parse_service_option(CMD
     /* accept */
     switch(cmd) {
     case CMD_BEGIN:
-        addrlist_clear(&section->local_addr, 1);
+        addrlist_clear(&section->local_addr, 0);
         break;
     case CMD_EXEC:
         if(strcasecmp(opt, "accept"))
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEdixJnDzFDyW2HUFk7ByGZki0elEFAlp5fLMACgkQ7ByGZki0
elHDIRAAwQMnQLBwobWuvwg/g5YYPkCsKe5M0AQoAH34n0vxUUUYVPGhxZSVm+Jv
PVYBrP6fuTwU/nBA+iBsGGZWq4R+igAJ6eds07eGCZ1Fl29xjY9fZZ0vhkWgrlhZ
vD4lHXgmoU/tqg3LPHg72y6499qCcE1larxT4BaqDaHq+SNzOKPnnSREzmzv6+KH
dEd2KxyDsxGH5R3cnm3DJs5LSRohPv3D0XBFihDm3XXI6U7vu/eNOL5KCBHrYLN8
zBCoPlwOFcIdEv4RcYiLjmuUtsqdSIY/BCYXF75oMD1j9EZt1j7YZ6+mUb+oNsmX
yyIrqQDefBg81xTf/0q6SRnR0Wcqory4yizNqXLQBHtqH7j0Mo+Xvnt+UhxS6CQn
DUPpFATKYXe0elieuFc0nLI/pbhyw8bNOgKToKnbJx7U3K3fOclqm9ZW0RJtjgDN
vu0JEYG6dlXkr5Qc5TlSGn6QX1hy4GCvC6eOjvwLE43wvvcBBOJ5VGBkKlN+daO0
47VEcm/7aQApAl9+mZYaziWSkCK7XefDg7t7KsNGtlsOexfov8etZz09AP2f962n
HpEYyUsSekYxIVBx0uCSVO2747+5xlVvB2euL94UHkMsH+7t6LtngX26az0Iem2/
923y5n/ZqYgbucjm8kD5QU0ycOEzqiGh1osiuZUaeAd89ZrU73Q=
=7GH3
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.