From 88d532a3a1c29e40368e5d074e3fd8dbebc8b998 Mon Sep 17 00:00:00 2001 From: Conrad Lara - KG6JEI Date: Tue, 8 Jul 2014 00:02:47 -0700 Subject: [PATCH] bugfix: get_default_gw needs to follow the route the node will use to internet. because of previous bugfix the function needs to check table 31 and 254 (with 254 taking priority) --- files/www/cgi-bin/perlfunc.pm | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/files/www/cgi-bin/perlfunc.pm b/files/www/cgi-bin/perlfunc.pm index 8a2e4d5a..4fac7946 100644 --- a/files/www/cgi-bin/perlfunc.pm +++ b/files/www/cgi-bin/perlfunc.pm @@ -417,12 +417,22 @@ sub get_ip6_addr sub get_default_gw { my $gw = "none"; - foreach(`route -n`) - { - next unless /^0\.0\.0\.0\s+([\d\.]+)/; - $gw = $1; - last; - } + + # Table 31 is populated by OLSR + foreach(`/usr/sbin/ip route list table 31`) + { + next unless /^default\svia\s([\d\.]+)/; + $gw = $1; + last; + } + + # However a node with a wired default gw will route via that instead + foreach(`/usr/sbin/ip route list table 254`) + { + next unless /^default\svia\s([\d\.]+)/; + $gw = $1; + last; + } return $gw; }