Created attachment 1695 [details] Fix following the current openssh style. $ /usr/bin/ssh -g -L 5000:localhost:22 localhost cat bind: Address already in use [... running] # netstat -apn|grep 5000 tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 23526/ssh $ telnet localhost6 5000 Trying ::1... telnet: connect to address ::1: Connection refused patched: $ ./ssh -g -L 5000:localhost:22 localhost cat [... running] # netstat -apn|grep 5000 tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 23139/ssh tcp 0 0 :::5000 :::* LISTEN 23139/ssh $ telnet localhost6 5000 Trying ::1... Connected to localhost6. Escape character is '^]'. SSH-2.0-OpenSSH_5.2 Using Fedora 11 kernel with its (+AFAIK upstream) defaults: # cat /proc/version Linux version 2.6.30.5-43.fc11.x86_64 (mockbuild@xenbuilder4.fedora.phx.redhat.com) (gcc version 4.4.1 20090725 (Red Hat 4.4.1-2) (GCC) ) #1 SMP Thu Aug 27 21:39:52 EDT 2009 # cat /proc/sys/net/ipv6/bindv6only 0 In the current case one cannot access IPv6 because the IPv4 socket was created first. If IPv6 would be created first it would work. The copy-pasted code could be probably moved to some unified function. This is out of scope of this patch. Similiar problem+resolution was in Bug 164, Bug 1309 and Bug 1392.
Created attachment 1720 [details] unify setsockopt(...,IPV6_V6ONLY,...) calls Good idea about unifying the calls to setsockopt. Here is a diff that does that (includes your change too).
patch applied. this will be in openssh-5.4, thanks for the report+patch.
With the release of 5.4p1, this bug is now considered closed.