pmattes / x3270

Family of IBM 3270 emulators
47 stars 19 forks source link

IPv6 / IPv4 failover #27

Closed swhobbit closed 2 years ago

swhobbit commented 2 years ago

PROBLEM: If a hostname has both an IPv6 and IPv4 address in DNS, x3270 will try the IPv6 protocol and then give up. This is problem (for example) when an IPv6 enabled host has an an application (such Hercules SpinHawk) with IPv4 only ports. his especially a problem when connecting to common standard hostnames such as localhost.

This behavior differs from programs such as telnet, ssh, and web browsers, which automatically try both protocols.

EXPECTED BEHAVIOR: x3270 and other programs in the suite should automatically try both IPv4 and IPv6 ports after common errors such as connection refused or host unreachable.

OPTIONAL BEHAVIOR: The programs can be directed by configuration or comment line to only use IPv4 or IPv6 protocol via configuration or command line switch (other than the host parameter)

Rhialto commented 2 years ago

My guess is (and I admit I totally didn't check the code due to lack of time) that the older function gethostbyname(3) is used to find the address of the given host. There is now getaddrinfo(3) which is easier to use in case of a host name with multiple addresses and/or multiple protocols. The manual page has a nice example of how to use it both as a client and a server. The former tries connecting to all possible addresses in turn and the latter binds a listening socket to all of them.

pmattes commented 2 years ago

The code does use getaddrinfo().

pmattes commented 2 years ago

x3270 does accept and try up to 4 entries returned by getaddrinfo, and I just verified that it tries each of them. @swhobbit, can you give me more details about how this is not working as you expect? And what version of the code are you using?

swhobbit commented 2 years ago

[16,/tmp,56] uname -a
Linux pepe-le-pew 5.10.63-v7l+ #1496 SMP Wed Dec 1 15:58:56 GMT 2021 armv7l GNU/Linux

[16,/tmp,62] 'x3270' -v
x3270 v4.2pre1 Thu Nov 25 06:26:04 UTC 2021 ahd Build options: --enable-local-process (code & copyright pages omitted)

host hercules
hercules.hh.kew.com has address 192.168.203.5 hercules.hh.kew.com has IPv6 address 2001:470:B:625:5:5:5:5 host hercules-4
hercules-4.hh.kew.com has address 192.168.203.5 host hercules-6
hercules-6.hh.kew.com has IPv6 address 2001:470:B:625:5:5:5:5

Runs with traces [16,/tmp,53] 'x3270' -trace hercules 32705 # fails (uses IPv4) x3trc.31869-hercules.txt

[16,/tmp,54] 'x3270' -trace hercules-4 32705 # Works x3trc.31881-hercules-4.txt

[16,/tmp,55] 'x3270' -trace hercules-6 32705 # fails x3trc.31909-hercules-6.txt

pmattes commented 2 years ago

Just what I needed -- thank you.

The logic to try multiple host entries works as expected on s3270 and b3270. It is broken on x3270 and c3270. It's the same code -- the same object file, in fact -- with a different front end on it, so clearly the two interactive versions are doing something in response to the first connection failure that the back-end versions are not.

I will get on this tomorrow, and hopefully have a fix available soon.

swhobbit commented 2 years ago

Just what I needed -- thank you.

I wasn't sure, but I thought it was a good start.

BTW, if you didn't decode the hidden message in uname -a, that's on a Raspberry Pi 4 running Raspberry Pi OS.

I will get a fix for this into 4.2. A back-port to 4.1 is possible but might take a bit longer.

That's fine. I've had IPv6 locally for years (note the custom IPv4 and IPv6 flavors for the hostnames), and I only reported it now.

pmattes commented 2 years ago

The fix for this has been committed to 4.1 and master (4.2). I plan to add -4 and -6 options to master shortly.

swhobbit commented 2 years ago

Tested on Linux system that bug was reported on. It now works, trying ::1 (IPv6) and then 127.0.0.1