traviscross / mtr

Official repository for mtr, a network diagnostic tool
http://www.bitwizard.nl/mtr/
GNU General Public License v2.0
2.64k stars 337 forks source link

Set SO_BINDTODEVICE for `-I` #440

Closed rovo89 closed 2 years ago

rovo89 commented 2 years ago

This is done by traceroute and other tools as well. It requires CAP_NET_RAW, but without it the -I option doesn't seem to have any effect.

I could only test with IPv4, but it worked fine for ICMP, TCP and UDP. Not sure if additional handling is required for the case where CAP_NET_RAW isn't available it shows "Unexpected mtr-packet error" like it does for -M. Before this change there was no error, but it didn't take the interface into account.

Could be relevant for #379, #250, #232, although it doesn't handle the -a option. This is comparable to traceroute though. traceroute -s <IP> shows the same (wrong?) hops as mtr -a <IP> after this change, while traceroute -i <NAME> shows the same (correct) hops as mtr -I <NAME>. So I'd argue that this is the correct behavior.