Commit 6d01df69 authored by Per von Zweigbergk's avatar Per von Zweigbergk Committed by Franco Fichtner

(get_interface_list) Properly handle an interface not appearing in dmesg

(cherry picked from commit c9e04ae0)
(cherry picked from commit 720acc9e)
parent 9c419b3e
...@@ -59,7 +59,7 @@ function set_networking_interfaces_ports($probe = false) ...@@ -59,7 +59,7 @@ function set_networking_interfaces_ports($probe = false)
/* kernel messages clobber stty probing on ifconfig up */ /* kernel messages clobber stty probing on ifconfig up */
mute_kernel_msgs(); mute_kernel_msgs();
$iflist = get_interface_list(); $iflist = get_interface_list(false, true);
if ($probe) { if ($probe) {
echo PHP_EOL . gettext('Press any key to start the manual interface assignment: '); echo PHP_EOL . gettext('Press any key to start the manual interface assignment: ');
......
...@@ -893,12 +893,21 @@ function get_configured_ipv6_addresses() ...@@ -893,12 +893,21 @@ function get_configured_ipv6_addresses()
* *
* $only_active = false -- interfaces that are available in the system * $only_active = false -- interfaces that are available in the system
* true -- interfaces that are physically connected * true -- interfaces that are physically connected
*
* $include_dmesg = false -- skip probing dmesg for more information
* true -- probe dmesg for more information
*/ */
function get_interface_list($only_active = false) function get_interface_list($only_active = false, $include_dmesg = false)
{ {
global $config; global $config;
$dmesg_arr = array();
$iflist = array(); $iflist = array();
if ($include_dmesg) {
exec('/sbin/dmesg', $dmesg_arr);
}
/* list of virtual interface types */ /* list of virtual interface types */
$vfaces = array( $vfaces = array(
'_vlan', '_vlan',
...@@ -952,25 +961,23 @@ function get_interface_list($only_active = false) ...@@ -952,25 +961,23 @@ function get_interface_list($only_active = false)
$toput = array( $toput = array(
'up' => in_array($ifname, $ifnames_up), 'up' => in_array($ifname, $ifnames_up),
'ipaddr' => !empty($ifdata['ipaddr']) ? $ifdata['ipaddr'] : null, 'ipaddr' => !empty($ifdata['ipaddr']) ? $ifdata['ipaddr'] : null,
'mac' => $ifdata['macaddr'] 'mac' => $ifdata['macaddr'],
'dmesg' => '',
); );
if (isset($config['interfaces'])) { foreach (legacy_config_get_interfaces(array('virtual' => false)) as $name => $int) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $name => $int) { if ($int['if'] == $ifname) {
if ($int['if'] == $ifname) { $toput['friendly'] = $name;
$toput['friendly'] = $name; break;
break;
}
} }
} }
$dmesg_arr = array(); foreach ($dmesg_arr as $dmesg_line) {
exec("/sbin/dmesg |grep $ifname", $dmesg_arr); $dmesg = array();
preg_match_all("/<(.*?)>/i", $dmesg_arr[0], $dmesg); if (preg_match("/^{$ifname}: <(.*?)>/i", $dmesg_line, $dmesg) == 1) {
if (isset($dmesg[1][0])) { $toput['dmesg'] = $dmesg[1];
$toput['dmesg'] = $dmesg[1][0]; break;
} else { }
$toput['dmesg'] = null;
} }
$iflist[$ifname] = $toput; $iflist[$ifname] = $toput;
......
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