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