From 720acc9e1d2c7f89b353dd1fb190e52a73c0804d Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Sat, 13 Aug 2016 20:41:56 +0200 Subject: [PATCH] util: make dmesg probing optional #1135 While there, turn the probing upside down for general sanity: o Only pull dmesg output once o Pattern-match one pattern only o Anchor the match to the line start --- src/etc/inc/config.console.inc | 2 +- src/etc/inc/util.inc | 36 ++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/etc/inc/config.console.inc b/src/etc/inc/config.console.inc index 859b2c4b5..1e75079e4 100644 --- a/src/etc/inc/config.console.inc +++ b/src/etc/inc/config.console.inc @@ -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: '); diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc index 26a8ee0dd..3da7d0fd1 100644 --- a/src/etc/inc/util.inc +++ b/src/etc/inc/util.inc @@ -876,12 +876,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', @@ -935,25 +944,22 @@ 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(); - $toput['dmesg'] = null; - exec("/sbin/dmesg |grep $ifname", $dmesg_arr); - if (count($dmesg_arr) > 0) { - preg_match_all("/<(.*?)>/i", $dmesg_arr[0], $dmesg); - if (isset($dmesg[1][0])) { - $toput['dmesg'] = $dmesg[1][0]; + foreach ($dmesg_arr as $dmesg_line) { + $dmesg = array(); + if (preg_match("/^{$ifname}: <(.*?)>/i", $dmesg_line, $dmesg) == 1) { + $toput['dmesg'] = $dmesg[1]; + break; } }