Commit 08524d5e authored by Franco Fichtner's avatar Franco Fichtner

config: make sure that we're not iterating over empty interfaces

parent 39689a70
...@@ -62,7 +62,7 @@ function is_bogonsv6_used() { ...@@ -62,7 +62,7 @@ function is_bogonsv6_used() {
global $config, $g; global $config, $g;
# Only use bogonsv6 table if IPv6 Allow is on, and at least 1 enabled interface also has "blockbogons" enabled. # Only use bogonsv6 table if IPv6 Allow is on, and at least 1 enabled interface also has "blockbogons" enabled.
$usebogonsv6 = false; $usebogonsv6 = false;
if (isset($config['system']['ipv6allow'])) { if (isset($config['system']['ipv6allow']) && isset($config['interfaces'])) {
foreach ($config['interfaces'] as $ifacedata) { foreach ($config['interfaces'] as $ifacedata) {
if(isset($ifacedata['enable']) && isset($ifacedata['blockbogons'])) { if(isset($ifacedata['enable']) && isset($ifacedata['blockbogons'])) {
$usebogonsv6 = true; $usebogonsv6 = true;
......
...@@ -723,12 +723,16 @@ function get_configured_interface_list($only_opt = false, $withdisabled = false) ...@@ -723,12 +723,16 @@ function get_configured_interface_list($only_opt = false, $withdisabled = false)
$iflist = array(); $iflist = array();
/* if list */ /* if list */
if (isset($config['interfaces'])) {
foreach($config['interfaces'] as $if => $ifdetail) { foreach($config['interfaces'] as $if => $ifdetail) {
if ($only_opt && ($if == "wan" || $if == "lan")) if ($only_opt && ($if == "wan" || $if == "lan")) {
continue; continue;
if (isset($ifdetail['enable']) || $withdisabled == true) }
if (isset($ifdetail['enable']) || $withdisabled == true) {
$iflist[$if] = $if; $iflist[$if] = $if;
} }
}
}
return $iflist; return $iflist;
} }
...@@ -740,6 +744,7 @@ function get_configured_interface_list_by_realif($only_opt = false, $withdisable ...@@ -740,6 +744,7 @@ function get_configured_interface_list_by_realif($only_opt = false, $withdisable
$iflist = array(); $iflist = array();
/* if list */ /* if list */
if (isset($config['interfaces'])) {
foreach($config['interfaces'] as $if => $ifdetail) { foreach($config['interfaces'] as $if => $ifdetail) {
if ($only_opt && ($if == "wan" || $if == "lan")) if ($only_opt && ($if == "wan" || $if == "lan"))
continue; continue;
...@@ -749,6 +754,7 @@ function get_configured_interface_list_by_realif($only_opt = false, $withdisable ...@@ -749,6 +754,7 @@ function get_configured_interface_list_by_realif($only_opt = false, $withdisable
$iflist[$tmpif] = $if; $iflist[$tmpif] = $if;
} }
} }
}
return $iflist; return $iflist;
} }
...@@ -760,6 +766,7 @@ function get_configured_interface_with_descr($only_opt = false, $withdisabled = ...@@ -760,6 +766,7 @@ function get_configured_interface_with_descr($only_opt = false, $withdisabled =
$iflist = array(); $iflist = array();
/* if list */ /* if list */
if (isset($config['interfaces'])) {
foreach($config['interfaces'] as $if => $ifdetail) { foreach($config['interfaces'] as $if => $ifdetail) {
if ($only_opt && ($if == "wan" || $if == "lan")) if ($only_opt && ($if == "wan" || $if == "lan"))
continue; continue;
...@@ -770,6 +777,7 @@ function get_configured_interface_with_descr($only_opt = false, $withdisabled = ...@@ -770,6 +777,7 @@ function get_configured_interface_with_descr($only_opt = false, $withdisabled =
$iflist[$if] = strtoupper($ifdetail['descr']); $iflist[$if] = strtoupper($ifdetail['descr']);
} }
} }
}
return $iflist; return $iflist;
} }
...@@ -921,10 +929,11 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "") ...@@ -921,10 +929,11 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "")
$toput['ipaddr'] = $aip[1]; $toput['ipaddr'] = $aip[1];
} }
} }
if (is_array($config['interfaces'])) { if (isset($config['interfaces'])) {
foreach($config['interfaces'] as $name => $int) foreach($config['interfaces'] as $name => $int) {
if($int['if'] == $ifname) $friendly = $name; if($int['if'] == $ifname) $friendly = $name;
} }
}
switch($keyby) { switch($keyby) {
case "physical": case "physical":
if($friendly != "") { if($friendly != "") {
...@@ -1410,7 +1419,7 @@ function is_interface_mismatch() ...@@ -1410,7 +1419,7 @@ function is_interface_mismatch()
$do_assign = false; $do_assign = false;
$i = 0; $i = 0;
if (is_array($config['interfaces'])) { if (isset($config['interfaces'])) {
foreach ($config['interfaces'] as $ifname => $ifcfg) { foreach ($config['interfaces'] as $ifname => $ifcfg) {
if (preg_match("/^enc|^cua|^tun|^tap|^l2tp|^pptp|^ppp|^ovpn|^gif|^gre|^lagg|^bridge|vlan|_wlan/i", $ifcfg['if'])) { if (preg_match("/^enc|^cua|^tun|^tap|^l2tp|^pptp|^ppp|^ovpn|^gif|^gre|^lagg|^bridge|vlan|_wlan/i", $ifcfg['if'])) {
/* Do not check these interfaces */ /* Do not check these interfaces */
......
...@@ -41,6 +41,12 @@ $machine = trim(`uname -m`); ...@@ -41,6 +41,12 @@ $machine = trim(`uname -m`);
print "\n*** Welcome to {$product} {$version} ({$machine}) on {$hostname} ***\n"; print "\n*** Welcome to {$product} {$version} ({$machine}) on {$hostname} ***\n";
$iflist = get_configured_interface_with_descr(false, true); $iflist = get_configured_interface_with_descr(false, true);
if (empty($iflist)) {
printf("\n\tNo network interfaces are assigned.\n");
return;
}
foreach($iflist as $ifname => $friendly) { foreach($iflist as $ifname => $friendly) {
/* point to this interface's config */ /* point to this interface's config */
$ifconf = $config['interfaces'][$ifname]; $ifconf = $config['interfaces'][$ifname];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment