From 9444716fbd923731e453456410b5d54b7be04370 Mon Sep 17 00:00:00 2001 From: Conrad Lara - KG6JEI Date: Tue, 24 Mar 2015 23:25:18 -0700 Subject: [PATCH] feature: Add function and code to UI code to prepare for changing interface names in the core OS. Create get_interface which will lookup in the current uci network config the realname for the logical interface name. When the interface is not found it will fall back to a hard coded list. Configure the UI to use the new get_interface function. --- files/www/cgi-bin/channelmaps.pm | 6 ++- files/www/cgi-bin/mesh | 2 +- files/www/cgi-bin/perlfunc.pm | 44 +++++++++++++----- files/www/cgi-bin/ports | 9 +--- files/www/cgi-bin/setup | 8 ++-- files/www/cgi-bin/signal | 2 +- files/www/cgi-bin/status | 78 ++++++++++++-------------------- 7 files changed, 75 insertions(+), 74 deletions(-) diff --git a/files/www/cgi-bin/channelmaps.pm b/files/www/cgi-bin/channelmaps.pm index c2048d6b..ac22e554 100644 --- a/files/www/cgi-bin/channelmaps.pm +++ b/files/www/cgi-bin/channelmaps.pm @@ -139,7 +139,8 @@ sub is_channel_valid # We don't have the device band in the data file so lets fall back to checking manually else { my $channelok=0; - foreach (`iwinfo wlan0 freqlist`) + my $wifiintf = get_interface("wifi"); + foreach (`iwinfo $wifiintf freqlist`) { next unless /Channel $channel/; next if /\[restricted\]/; @@ -166,7 +167,8 @@ sub rf_channels_list else { my %channels = (); - foreach (`iwinfo wlan0 freqlist` ) + my $wifiintf = get_interface("wifi"); + foreach (`iwinfo $wifiintf freqlist` ) { next unless /([0-9]+.[0-9]+) GHz \(Channel ([0-9]+)\)/; next if /\[restricted\]/; diff --git a/files/www/cgi-bin/mesh b/files/www/cgi-bin/mesh index 77bf6baa..4d3a1093 100755 --- a/files/www/cgi-bin/mesh +++ b/files/www/cgi-bin/mesh @@ -47,7 +47,7 @@ $node = "NOCALL" if $node eq ""; $tactical = nvram_get("tactical"); $config = nvram_get("config"); $config = "not set" if $config eq "" or not -d "/etc/config.$config"; -($my_ip) = get_ip4_network("wlan0"); +($my_ip) = get_ip4_network(get_interface("wifi")); read_postdata(); diff --git a/files/www/cgi-bin/perlfunc.pm b/files/www/cgi-bin/perlfunc.pm index 78ab68c8..4d4ffd5a 100644 --- a/files/www/cgi-bin/perlfunc.pm +++ b/files/www/cgi-bin/perlfunc.pm @@ -286,14 +286,7 @@ sub reboot_page $link = "/cgi-bin/status" unless $link; # is the browser coming from the lan? - if(system "ifconfig br-lan >/dev/null 2>&1") - { - ($lanip, $lanmask, $junk, $lannet) = &get_ip4_network("eth0"); - } - else - { - ($lanip, $lanmask, $junk, $lannet) = &get_ip4_network("br-lan"); - } + ($lanip, $lanmask, $junk, $lannet) = &get_ip4_network(get_interface("lan")); my($browser) = $ENV{REMOTE_ADDR} =~ /::ffff:([\d\.]+)/; my $fromlan = validate_same_subnet($browser, $lanip, $lanmask); $junk = ""; # dummy to avoid warning @@ -538,8 +531,8 @@ sub load_cfg { #my $mac2 = nvram_get("mac2"); my $node = nvram_get("node"); - my $mac2 = mac2ip(get_mac("wlan0"), 0); - my $dtdmac = mac2ip(get_mac("eth0"), 0); + my $mac2 = mac2ip(get_mac(get_interface("wifi")), 0); + my $dtdmac = mac2ip(get_mac(get_interface("lan")), 0); open(FILE, $_[0]) or return 0; while(defined ($line = )) { @@ -1280,7 +1273,8 @@ sub wifi_useschains #has increased it to a higher level. sub wifi_txpoweroffset { - my $doesiwoffset=`iwinfo wlan0 info 2>/dev/null` =~ /TX power offset: (\d+)/; + my $wlanintf = get_interface("wifi"); + my $doesiwoffset=`iwinfo $wlanintf info 2>/dev/null` =~ /TX power offset: (\d+)/; if ( $doesiwoffset ) { return $1; } else @@ -1339,5 +1333,33 @@ sub page_footer print "" } + +sub get_interface +{ + my ($intfname) = @_; + my $intfname = `uci -q get network.$intfname.ifname`; + chomp $intfname; + + if ($intfname) { + return $intfname; + } else { + # Capture rules incase uci file is not in sync. + if ( $intfname eq "lan" ) + { + return "eth0"; + } elsif ( $intfname eq "wan" ){ + return "eth0.1"; + } elsif ( $intfname eq "wifi" ){ + return "wlan0"; + } elsif ( $intfname eq "dtdlink" ){ + return "eth0.1"; + } else { + # we have a problem + die("Unknown interface in call to get_interface"); + } + } +} + + #weird uhttpd/busybox error requires a 1 at the end of this file 1 diff --git a/files/www/cgi-bin/ports b/files/www/cgi-bin/ports index 046abc99..1072b6aa 100755 --- a/files/www/cgi-bin/ports +++ b/files/www/cgi-bin/ports @@ -75,14 +75,7 @@ else { $dmz_mode = 0 } # get the network details of the lan interface for dhcp calculations -if(system "ifconfig br-lan >/dev/null 2>&1") -{ - ($lanip, $lanmask, $junk, $lannet, $lancidr) = get_ip4_network("eth0"); -} -else -{ - ($lanip, $lanmask, $junk, $lannet, $lancidr) = get_ip4_network("br-lan"); -} +($lanip, $lanmask, $junk, $lannet, $lancidr) = get_ip4_network(get_interface("lan")); $lannet_d = ip2decimal($lannet); diff --git a/files/www/cgi-bin/setup b/files/www/cgi-bin/setup index d8696bec..2fecadb1 100755 --- a/files/www/cgi-bin/setup +++ b/files/www/cgi-bin/setup @@ -130,8 +130,9 @@ $parms{dmz_dhcp_limit} = $dmz_dhcp_limit = $dmz_dhcp_end - $dmz_dhcp_start + 1; unless($parms{reload}) { - ($wifi_txpower) = `iwinfo wlan0 info 2>/dev/null` =~ /Tx-Power: (\d+)/; - (my $doesiwoffset) = `iwinfo wlan0 info 2>/dev/null` =~ /TX power offset: (\d+)/; + my $wifiintf = get_interface("wifi"); + ($wifi_txpower) = `iwinfo $wifiintf info 2>/dev/null` =~ /Tx-Power: (\d+)/; + (my $doesiwoffset) = `iwinfo $wifiintf info 2>/dev/null` =~ /TX power offset: (\d+)/; if ( $doesiwoffset ) { $wifi_txpower -= $1; } @@ -173,6 +174,7 @@ $parms{wifi_rxant} = $wifi_rxant; if($parms{button_apply} or $parms{button_save}) { + my $wifiintf = get_interface("wifi"); $cmd = ""; if(wifi_useschains()){ $cmd .= "echo $wifi_rxant > /sys/kernel/debug/ieee80211/phy0/ath9k/rx_chainmask;"; @@ -185,7 +187,7 @@ if($parms{button_apply} or $parms{button_save}) $cmd .= "ifup wifi_mon >/dev/null 2>&1;"; } $cmd .= "iw phy phy0 set distance $wifi_distance >/dev/null 2>&1;"; - $cmd .= "iw dev wlan0 set txpower fixed ${wifi_txpower}00 >/dev/null 2>&1;"; + $cmd .= "iw dev $wifiintf set txpower fixed ${wifi_txpower}00 >/dev/null 2>&1;"; system $cmd; } diff --git a/files/www/cgi-bin/signal b/files/www/cgi-bin/signal index 6a3e230c..1cdb41d9 100755 --- a/files/www/cgi-bin/signal +++ b/files/www/cgi-bin/signal @@ -52,7 +52,7 @@ system "rm -f /tmp/web/siglevel" if $parms{start}; # get the current levels -($s, $n) = get_wifi_signal("wlan0"); +($s, $n) = get_wifi_signal(get_interface("wifi")); if($s eq "N/A") { $s = $n = "---" } # load the previous levels diff --git a/files/www/cgi-bin/status b/files/www/cgi-bin/status index 2d63adac..86b344e4 100755 --- a/files/www/cgi-bin/status +++ b/files/www/cgi-bin/status @@ -136,61 +136,43 @@ $browser_ip = ""; # left column - network interface info -if(system "ifconfig br-lan >/dev/null 2>&1") # lan not bridged +# show the wifi address +($ip, $mask, $bcast, $net, $cidr) = get_ip4_network(get_interface("wifi")); +$cidr = "/ $cidr" if $cidr; +$str = "WiFi address$ip $cidr
"; +$str .= "" . get_ip6_addr(get_interface("wifi")) . ""; +push @col1, $str; + +# find out if the browser is on this node's lan +# if not, hide the local network details +($ip, $mask, $bcast, $net, $cidr) = get_ip4_network(get_interface("lan")); +if($ENV{REMOTE_ADDR} =~ /::ffff:([\d\.]+)/) { - # show the wifi address - ($ip, $mask, $bcast, $net, $cidr) = get_ip4_network("wlan0"); - $cidr = "/ $cidr" if $cidr; - $str = "WiFi address$ip $cidr
"; - $str .= "" . get_ip6_addr("wlan0") . ""; - push @col1, $str; - - # find out if the browser is on this node's lan - # if not, hide the local network details - ($ip, $mask, $bcast, $net, $cidr) = get_ip4_network("eth0"); - if($ENV{REMOTE_ADDR} =~ /::ffff:([\d\.]+)/) - { - $browser_ip = $1; - $hide_local = 1 unless validate_same_subnet($browser_ip, $ip, $mask); - } - - if($ip =~ /^10\./ or not $hide_local) - { - $cidr = "/ $cidr" if $cidr; - $str = "LAN address$ip $cidr
"; - $str .= "" . get_ip6_addr("eth0") . ""; - push @col1, $str; - } -} -else # lan is bridged -{ - # show the wifi/lan bridge address unless the browser is on a different network - ($ip, $mask, $bcast, $net, $cidr) = get_ip4_network("br-lan"); - if($ENV{REMOTE_ADDR} =~ /::ffff:([\d\.]+)/) - { - $browser_ip = $1; - $hide_local = 1 unless validate_same_subnet($browser_ip, $ip, $mask); - } - - unless($hide_local) - { - $cidr = "/ $cidr" if $cidr; - $str = "WiFi/LAN address$ip $cidr
"; - $str .= "" . get_ip6_addr("br-lan") . ""; - push @col1, $str; - } + $browser_ip = $1; + $hide_local = 1 unless validate_same_subnet($browser_ip, $ip, $mask); } -if(not $hide_local and not system "ifconfig eth0.1 >/dev/null 2>&1") +if($ip =~ /^10\./ or not $hide_local) { - ($ip, $mask, $bcast, $net, $cidr) = get_ip4_network("eth0.1"); $cidr = "/ $cidr" if $cidr; - $cidr = "" unless $cidr; - $str = "WAN address$ip $cidr
"; - $str .= "" . get_ip6_addr("eth0.1") . ""; + $str = "LAN address$ip $cidr
"; + $str .= "" . get_ip6_addr(get_interface("lan")) . ""; push @col1, $str; } +{ + my $wanintf = get_interface("wan"); + if(not $hide_local and not system "ifconfig $wanintf >/dev/null 2>&1") + { + ($ip, $mask, $bcast, $net, $cidr) = get_ip4_network("$wanintf"); + $cidr = "/ $cidr" if $cidr; + $cidr = "" unless $cidr; + $str = "WAN address$ip $cidr
"; + $str .= "" . get_ip6_addr("$wanintf") . ""; + push @col1, $str; + } +} + $ip = get_default_gw(); if($ip =~ /^10\./ or not $hide_local) @@ -232,7 +214,7 @@ if(-f "/tmp/olsrd.log") if($config eq "mesh" or $config eq "client") { $str = "Signal/Noise/Ratio"; - ($s, $n) = get_wifi_signal("wlan0"); + ($s, $n) = get_wifi_signal(get_interface("wifi")); if($s eq "N/A") { $str .= "N/A" } else { $str .= sprintf "%d / %d / %d dB", $s, $n, $s - $n } $str .= "   ";