Hi Axel, sorry for the late reply.

On Sat, 22 Jun 2013 13:32:05 +0200 Axel Beckert <[email protected]> wrote:
> Adding TWOPINGD_OPTS="-6" causes the listener to only listen on IPv6:
> 
> # lsof -p 7012 | fgrep IP
> 2ping   7012 nobody    4u  IPv6 4019791      0t0     UDP *:15998

Binding to :: will allow for both IPv4 and IPv6 (I believe this is
sysctl-tunable, but IIRC the default has been dual stack on IPv6 binds
for awhile):

$ 2ping -6 --listen
Use of uninitialized value $opt_intaddr in pattern match (m//) at
/usr/bin/2ping line 356.
2PING listener (::): 128 to 512 bytes of data.
128 bytes from ::ffff:10.9.8.1: ping_seq=1 time=2.555 ms peertime=3.476 ms
128 bytes from ::ffff:10.9.8.1: ping_seq=2 time=3.284 ms peertime=3.067 ms
128 bytes from ::ffff:10.9.8.1: ping_seq=3 time=3.140 ms peertime=2.969 ms

> The only possibility to run a 2ping listener on both, IPv4 and
> IPv6, at the same time seems to be to explicitly list IP addresses and
> to put the -6 option just between all IPv4 and all IPv6 addresses:
> 
> TWOPINGD_OPTS="-I 192.168.1.129 -6 -I 2001:1620:f51:1:225:90ff:fe09:9c98"
> 
> At least with Teredo tunnels, the option -I doesn't help much as the
> tunnel tends to get a new IP address on restart and the option
> explicitly needs an IP address and not a device name.
> 
> The option -I is also less suitable if you want to enable IPv6 listeners
> on arbitrary machines by default.
> 
> So it would be nice, if there would be a possibility to listen on all
> IPv4 and IPv6 interfaces and addresses without the need to list all IP
> addresses. Maybe add a "-4" option to listen on IPv4, so that one can
> set TWOPINGD_OPTS="-4 -6" in /etc/default/2ping.

The problem I've encountered is if you have multiple IP addresses on an
interface and you bind a UDP socket on 0.0.0.0 and/or ::, any sendto()
replies will set the source address of the first IP on the interface.
So effectively, in any non-trivial setup, you need to bind to each IP.
It's why e.g. the named process shows binds for every IP address on the
system.  Problem is there is not a portable way to do that within perl
(or python), so I've got this in my /etc/default/2ping:

TWOPINGD_OPTS="-6"
addrs="$(ip addr | perl -ne '/inet6? (.*?)[\/ ]/ && !($1 =~ /^fe80::/)
&& print "$1\n"' | sort | uniq)"
if [ -n "$addrs" ]; then
  for addr in $addrs; do
    TWOPINGD_OPTS="$TWOPINGD_OPTS -I $addr"
  done
fi

FYI, I've rewritten 2ping in python and will be doing a new upload soon
which makes things a little more logical.  -4 and -6 are now true v4/v6
restrictors, and specifying neither and letting 2ping "just work" is
preferable in most cases.  For example, your "-I 192.168.1.129 -I
2001:1620:f51:1:225:90ff:fe09:9c98" would work as expected.  It now
explicitly binds to both 0.0.0.0 and :: with --listen:

$ 2ping --listen
2PING listener (0.0.0.0): 128 to 512 bytes of data.
2PING listener (::): 128 to 512 bytes of data.
128 bytes from 10.9.8.1: ping_seq=1 time=2.836 ms peertime=3.180 ms
128 bytes from 10.9.8.1: ping_seq=2 time=6.155 ms peertime=4.987 ms
128 bytes from 10.9.8.1: ping_seq=3 time=3.108 ms peertime=2.768 ms
128 bytes from 2001:470:1f05:22e::1: ping_seq=1 time=2.870 ms
peertime=2.869 ms
128 bytes from 2001:470:1f05:22e::1: ping_seq=2 time=2.757 ms
peertime=2.877 ms
128 bytes from 2001:470:1f05:22e::1: ping_seq=3 time=4.474 ms
peertime=3.260 ms

Giving it a hostname in listener mode with both A and AAAA records will
let it bind to both, or can be restricted with -4 or -6:

$ 2ping --listen -I linda.snowman.lan
2PING listener (2001:470:1f05:22e::5): 128 to 512 bytes of data.
2PING listener (10.9.8.4): 128 to 512 bytes of data.

$ 2ping --listen -4 -I linda.snowman.lan
2PING listener (10.9.8.4): 128 to 512 bytes of data.

Unfortunately you'll probably still need defaults hackery to listen on
dynamic addresses, though if your Teredo interface only has a single IP,
"2ping --listen" should probably just work.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to