Bug 275653 - net/socat does not open a listener port on FreeBSD 14
Summary: net/socat does not open a listener port on FreeBSD 14
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Some People
Assignee: Emanuel Haupt
URL:
Keywords:
: 277343 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-12-09 08:53 UTC by freebsd
Modified: 2024-02-27 08:45 UTC (History)
1 user (show)

See Also:
bugzilla: maintainer-feedback? (ehaupt)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description freebsd 2023-12-09 08:53:46 UTC
Have been running socat in previous FreeBSD versions as:

/usr/local/bin/socat TCP-LISTEN:12345,reuseaddr,fork -

On FreeBSD 14 (currently 14.0-p2), this process still starts (it's in the process list), but the defined port no longer has an open listener, confirmed by sockstat and by telnet.
Comment 1 Emanuel Haupt freebsd_committer freebsd_triage 2023-12-09 11:31:11 UTC
I've noticed the following entry in the socat 1.8.0.0 release notes (http://www.dest-unreach.org/socat/CHANGES):

	configure option --enable-default-ipv allows to specify at build time if
	IPv4, IPv6, or none of these is the preferred default; this is related
	to environment variables SOCAT_PREFERRED_RESOLVE_IP and
	SOCAT_DEFAULT_LISTEN_IP, and to Socat option -4, -6.
	Furthermore, mechanism of IPv4 vs.IPv6 selection has been reworked.
	When no IP version is preferred by these mechanism, passive Socat
	addresses (LISTEN, RECV, RECVFROM) default to IPv6 because it might
	support both versions (but checkout option ipv6-v6only).
	For client addresses, when one of these mechanisms applies and name
	resolution gives addresses of both IP versions, the addresses of the
	preferred versions are tried first.


Sure enough by default socat now binds to IPv6:

Running
$ /usr/local/bin/socat TCP-LISTEN:12345,reuseaddr,fork -

Different terminal shows:
$ sockstat -46l | grep 12345
root     socat      15152 5   tcp6   *:12345               *:*

Sending data:
$ echo foo | nc -6 -v -w2 ::1 12345
Connection to ::1 12345 port [tcp/*] succeeded!

You can specify -4 to explicitly listen to IPv4:

$ /usr/local/bin/socat -4 TCP-LISTEN:12345,reuseaddr,fork -
...

$ sockstat -46l | grep 12345
root   socat      17447 5   tcp4   *:12345               *:*

$ echo foo | nc -4 -v -w2 0 12345
Connection to 0 12345 port [tcp/*] succeeded!

This seems like a POLA violation to me. I am going patch the port.
Comment 2 freebsd 2023-12-09 11:36:48 UTC
Ah yes, good one. Both machines are indeed dual stack, but I specifically use socat on the IPv4 address, and would have expected socat to simply bind to both stacks, which it either did by default on FreeBSD 13, or it stopped doing because of the version upgrade in socat itself.
Comment 3 commit-hook freebsd_committer freebsd_triage 2023-12-09 11:49:09 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=4c6bb66915d405ad49d3d843c6fdd2857e9371c8

commit 4c6bb66915d405ad49d3d843c6fdd2857e9371c8
Author:     Emanuel Haupt <ehaupt@FreeBSD.org>
AuthorDate: 2023-12-09 11:48:40 +0000
Commit:     Emanuel Haupt <ehaupt@FreeBSD.org>
CommitDate: 2023-12-09 11:48:44 +0000

    net/socat: Add configurable IPv4/IPv6 preference option

    In socat version 1.8.0.0, a new feature was introduced allowing users to
    configure the default IP version preference at build time using the
    `--enable-default-ipv` option. This change resulted in a default
    preference for IPv6, which led to unexpected behavior for some users.

    To address this, a new option has been added to the FreeBSD port of
    socat. By default, the port restores the previous behavior where IPv4
    is preferred. However, users now have the option to explicitly specify a
    preference for IPv6 if desired.

    This change aims to align with the Principle of Least Astonishment
    (POLA) and provide users with flexibility in choosing their preferred IP
    version.

    PR:             275653 (based on)

 net/socat/Makefile | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Comment 4 freebsd 2023-12-09 11:55:24 UTC
Thanks, Emanuel!
Comment 5 Emanuel Haupt freebsd_committer freebsd_triage 2023-12-09 11:57:48 UTC
Thanks for the PR!
Comment 6 Emanuel Haupt freebsd_committer freebsd_triage 2024-02-27 08:45:30 UTC
*** Bug 277343 has been marked as a duplicate of this bug. ***