Bug 9346 - ping -I br0 <ip of br0> doesn't work
Summary: ping -I br0 <ip of br0> doesn't work
Status: RESOLVED WONTFIX
Alias: None
Product: Busybox
Classification: Unclassified
Component: Networking (show other bugs)
Version: unspecified
Hardware: PC Linux
: P5 critical
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-11 08:19 UTC by Markus Gothe
Modified: 2016-12-25 18:40 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:


Attachments
strace of ping (71.90 KB, text/plain)
2016-12-12 10:24 UTC, Markus Gothe
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Gothe 2016-10-11 08:19:02 UTC
ping -I br0 <ip of br0> doesn't work.

Setup:

brctl addbr br0
ifconfig br0 192.168.7.1

busybox ping -I br0 192.168.7.1

With ping from iputils this works like a charm.

I've tested this against both 1.25.1 and 1.22.1 on MIPS and x86.
Comment 1 Denys Vlasenko 2016-12-10 19:32:49 UTC
(In reply to Markus Gothe from comment #0)

Can't reproduce: it works for me just fine on current git.

Can you reproduce it with current git? If yes, please post the strace of the failing ping.
Comment 2 Markus Gothe 2016-12-12 10:24:43 UTC
Created attachment 6821 [details]
strace of ping

Output of sudo strace -vvv -ff -o ping.log ./busybox ping -I br0 192.168.7.1
Comment 3 Denys Vlasenko 2016-12-12 18:03:46 UTC
(In reply to Markus Gothe from comment #2)
Ok, I was wrong: I tried it without -I br0. With -I br0, bbox ping fails for me too.

And it's probably not a bug.

Pinging (one of) your own IP does not go over any physical interface, it goes over loopback: kernel definitely doesn't send any packets over the network, it simply feeds TX packet back to RX code.

Tried "ping -I lo" in your case and it works.

Now, why iputils works? bbox code does

setsockopt(0, SOL_SOCKET, SO_BINDTODEVICE, "br\0\0\0", 32)

to instruct kernel to use a specific iface. iputils does:

setsockopt(5, SOL_SOCKET, SO_BINDTODEVICE, [3175010], 4)

See that 4? This is not a correct length for this setsockopt!
(3175010 is a misdecoded string "br0\0"). This setsockop has no effect, kernel still will use whichever iface it wants.

Proof: try "ping -I eth0": it will still "successcully" ping br0's IP!
Comment 4 Markus Gothe 2016-12-13 09:17:35 UTC
(In reply to Denys Vlasenko from comment #3)
I challenge you:

markus@markus:~/development/branches/9.0.x/TINYAC$ ping -I br0 192.168.7.1
PING 192.168.7.1 (192.168.7.1) from 192.168.7.1 br0: 56(84) bytes of data.
64 bytes from 192.168.7.1: icmp_req=1 ttl=64 time=0.020 ms
64 bytes from 192.168.7.1: icmp_req=2 ttl=64 time=0.034 ms
64 bytes from 192.168.7.1: icmp_req=3 ttl=64 time=0.027 ms
64 bytes from 192.168.7.1: icmp_req=4 ttl=64 time=0.032 ms
^C
--- 192.168.7.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2997ms
rtt min/avg/max/mdev = 0.020/0.028/0.034/0.006 ms
markus@markus:~/development/branches/9.0.x/TINYAC$ ping -I eth0 192.168.7.1
PING 192.168.7.1 (192.168.7.1) from 192.168.7.1 eth0: 56(84) bytes of data.
From 10.10.10.3 icmp_seq=1 Destination Host Unreachable
From 10.10.10.3 icmp_seq=2 Destination Host Unreachable
From 10.10.10.3 icmp_seq=3 Destination Host Unreachable
^C
--- 192.168.7.1 ping statistics ---
5 packets transmitted, 0 received, +3 errors, 100% packet loss, time 4024ms

An strace gives me this:
setsockopt(4, SOL_SOCKET, SO_BINDTODEVICE, "eth0\0", 5) = 0
Comment 5 Denys Vlasenko 2016-12-13 09:49:51 UTC
# ifconfig br0 1.1.1.1

# ip a
...
4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
    link/ether ba:2b:a0:03:d0:43 brd ff:ff:ff:ff:ff:ff
    inet 1.1.1.1/8 brd 1.255.255.255 scope global br0
       valid_lft forever preferred_lft forever

# busybox ping -I eth0 1.1.1.1
PING 1.1.1.1 (1.1.1.1): 56 data bytes
^C
--- 1.1.1.1 ping statistics ---
5 packets transmitted, 0 packets received, 100% packet loss

# ping -I eth0 1.1.1.1
PING 1.1.1.1 (1.1.1.1) from 10.34.1.104 eth0: 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=64 time=0.062 ms
64 bytes from 1.1.1.1: icmp_seq=2 ttl=64 time=0.057 ms
64 bytes from 1.1.1.1: icmp_seq=3 ttl=64 time=0.058 ms
^C

# ping -V
ping utility, iputils-s20160308
Comment 6 Denys Vlasenko 2016-12-13 11:41:16 UTC
Also, you can use tcpdump and see that ping packets do, in fact, use loopback interface, not br0 or eth0.