On Mon, 06 Dec 2010 15:00:13 +0100, Enrico Tassi wrote: > The code to detect the network interface does not check if the > guessed interface has an ip address associated to it. > > This in turns makes the ipcalc utility go crazy. Try to run it without > arguments > but with the -b flag. It will output 192.168.1.1 anyway, plus errors/warning > that iodine-client-start does not, but probably should, try to detect, like > "INVALID ADDRESS". And of course returns 0, so you really have to grep here > :-(
Oh, that's nasty.
> So, if you are in the unfortunate case of having a wifi on, but being
> connected
> on cable, the interface detection code fails, and iodine-client-start tries to
> tunnel your traffic trough the wifi assuming is has address 192.168.1.1.
... because of checking /proc/net/wireless. Right.
> I've attached a little patch to use ip to detect interfaces with a global ip
> associated to them.
> diff --git a/iodine-client-start b/iodine-client-start
> index 2f5ad94..6895af9 100755
> --- a/iodine-client-start
> +++ b/iodine-client-start
> @@ -217,18 +217,15 @@ echo ==== Creating IP-over-DNS tunnel over local
> network connection...
> ## Find a network interface
>
> if [ -z ${interface} ]; then
> - interface=$(tail --lines=+3 /proc/net/wireless \
> - | head -1 | tr -d : | awk '{print $1}')
> -fi
> -
> -if [ -z ${interface} ]; then
> - interface=$(ifconfig -a | egrep '^[^ ].*encap:Ethernet' \
> - | head -1 | awk '{print $1}')
> -fi
> -
> -if [ -z ${interface} ]; then
> - echo ERROR: No network interface found.
> - exit 1
> + nifs=$(ip -4 -o addr show scope global | wc -l)
> + if [ $nifs -eq 0 ]; then
> + echo ERROR: No network interface found.
> + exit 1
> + fi
> + interface=$(ip -4 -o addr show scope global | awk '{print $2}')
> + if [ $nifs -gt 1 ]; then
> + echo WARNING: $nifs interfaces with an ip address, chosing the first
> one
> + fi
> fi
>
> echo ==== Local network interface: ${interface}
I seems that this patch avoids the problem of the IP-less interface
but it also changes the semantics of the detection slighty; in the
original version wireless interfaces are preferred (first look into
/proc/net/wireless, only then check with ifconfig), while in your
patch the first one (or all of them?!) is (are) used in the random
order returned by ip addr show.
Let's try with your patch:
$ ip -4 -o addr show scope global
2: eth0 inet 192.168.0.3/24 brd 192.168.0.255 scope global eth0
5: n900 inet 192.168.0.205/30 brd 192.168.0.207 scope global n900
$ interface=$(ip -4 -o addr show scope global | awk '{print $2}') ; echo
$interface
eth0 n900
# ./iodine-client-start
==== Creating IP-over-DNS tunnel over local network connection...
WARNING: 2 interfaces with an ip address, chosing the first one
==== Local network interface: eth0 n900
==== Killing existing DNS tunnels...
Error: either "dev" is duplicate, or "n900" is a garbage.
Use of uninitialized value $ARGV[0] in concatenation (.) or string at
/usr/bin/ipcalc line 136.
==== Local address:
==== Local network: 192.168.1.0/24
Error: an inet prefix is expected rather than "n900".
WARNING: no default route, guessing local router IP address.
Use of uninitialized value $ARGV[0] in concatenation (.) or string at
/usr/bin/ipcalc line 136.
==== Local network router: 192.168.1.1
==== DNS servers: 192.168.0.252 192.168.0.254
==== Ping test of local network router and DNS servers...
192.168.0.252 : [0], 84 bytes, 0.48 ms (0.48 avg, 0% loss)
192.168.0.254 : [0], 84 bytes, 1.44 ms (1.44 avg, 0% loss)
192.168.1.1 : -
192.168.0.252 : 0.48
192.168.0.254 : 1.44
WARNING: Ping test failed.
==== Adding point-to-point route for DNS server 192.168.0.252
RTNETLINK answers: No such process
RTNETLINK answers: No such process
Hm, doesn't look so good :)
If I change the relevant line to
interface=$(ip -4 -o addr show scope global | awk '{print $2}' | head -1)
it works, but then we are again back to arbitralily taking the first
interface ...
Cheers,
gregor
--
.''`. http://info.comodo.priv.at/ -- GPG key IDs: 0x8649AA06, 0x00F3CFE4
: :' : Debian GNU/Linux user, admin, & developer - http://www.debian.org/
`. `' Member of VIBE!AT & SPI, fellow of Free Software Foundation Europe
`- NP: Cássia Eller
signature.asc
Description: Digital signature

