Commit a17c51f3 authored by Franco Fichtner's avatar Franco Fichtner

interfaces: improve interface assign again

o Only probe for key press on bootup.

o Rebuild autodetect feature: fixup second use case of
  get_interface_list() to filter out devices without a
  good link state, bring back interface up for it to
  work and mute kernel messages that would clobber stty
  behaviour.
parent d5a95a4d
......@@ -28,14 +28,6 @@
POSSIBILITY OF SUCH DAMAGE.
*/
/****f* util/timeout
* NAME
* timeout - console input with timeout countdown. Note: erases 2 char of screen for timer. Leave space.
* INPUTS
* optional, seconds to wait before timeout. Default 9 seconds.
* RESULT
* returns 1 char of user input or null if no input.
******/
function timeout($timer = 9)
{
while (!isset($key)) {
......@@ -55,9 +47,7 @@ function timeout($timer = 9)
return $key;
}
function set_networking_interfaces_ports()
function set_networking_interfaces_ports($probe = false)
{
global $config;
......@@ -66,17 +56,22 @@ function set_networking_interfaces_ports()
$interactive = true;
$key = null;
/* kernel messages clobber stty probing on ifconfig up */
mute_kernel_msgs();
$iflist = get_interface_list();
echo PHP_EOL . gettext('Press any key to start the manual interface assignment: ');
if ($probe) {
echo PHP_EOL . gettext('Press any key to start the manual interface assignment: ');
$key = timeout(7);
if (!isset($key)) {
$interactive = false;
}
$key = timeout(7);
if (!isset($key)) {
$interactive = false;
}
if ($key != "\n") {
echo PHP_EOL;
if ($key != "\n") {
echo PHP_EOL;
}
}
echo <<<EOD
......@@ -90,6 +85,7 @@ EOD;
$iflist = array();
} else {
foreach ($iflist as $iface => $ifa) {
interfaces_bring_up($iface);
echo sprintf("% -7s%s %s %s\n", $iface, $ifa['mac'],
$ifa['up'] ? " (up)" : "(down)", $ifa['dmesg']);
}
......@@ -149,6 +145,9 @@ EOD;
if ($wanif == 'a') {
$wanif = autodetect_interface('WAN', $fp);
if (!$wanif) {
continue;
}
}
if (!array_key_exists($wanif, $iflist)) {
......@@ -176,6 +175,9 @@ EOD;
if ($lanif == 'a') {
$lanif = autodetect_interface('LAN', $fp);
if (!$lanif) {
continue;
}
}
if (!array_key_exists($lanif, $iflist)) {
......@@ -227,7 +229,7 @@ EOD;
}
if ($optif[$i] == 'a') {
$ad = autodetect_interface(gettext("Optional") . " " . $io, $fp);
$ad = autodetect_interface('OPT' . $io, $fp);
if (!$ad) {
unset($optif[$i]);
continue;
......@@ -288,6 +290,8 @@ EOD;
}
if (!in_array($key, array('y', 'Y'))) {
unmute_kernel_msgs();
fclose($fp);
return false;
}
......@@ -416,33 +420,36 @@ EOD;
write_config("Console assignment of interfaces");
printf(gettext("done.%s"), "\n");
unmute_kernel_msgs();
fclose($fp);
return true;
}
function autodetect_interface($ifname, $fp)
function autodetect_interface($name, $fp)
{
$iflist_prev = get_interface_list('media');
$iflist_prev = get_interface_list(true);
echo <<<EOD
Connect the {$ifname} interface now and make sure that the link is up.
Connect the {$name} interface now and make sure that the link is up.
Then press ENTER to continue.
EOD;
fgets($fp);
$iflist = get_interface_list('media');
foreach ($iflist_prev as $ifn => $ifa) {
if (!$ifa['up'] && $iflist[$ifn]['up']) {
printf(gettext("Detected link-up on interface %s.%s"), $ifn, "\n");
$iflist = get_interface_list(true);
foreach ($iflist as $ifn => $ifa) {
if (!isset($iflist_prev[$ifn])) {
printf(gettext("Detected link-up: %s%s"), $ifn, "\n");
return $ifn;
}
}
printf(gettext("No link-up detected.%s"), "\n");
return null;
return false;
}
function vlan_setup($iflist, $fp)
......
......@@ -815,16 +815,13 @@ function get_configured_ipv6_addresses()
* get_interface_list() - Return a list of all physical interfaces
* along with MAC, IPv4 and status.
*
* $mode = "active" - use ifconfig -lu
* "media" - use ifconfig to check physical connection
* status (much slower)
* $only_active = false -- interfaces that are available in the system
* true -- interfaces that are physically connected
*/
function get_interface_list($mode = 'active')
function get_interface_list($only_active = false)
{
global $config;
$upints = array();
/* list of virtual interface types */
$vfaces = array(
'_vlan',
......@@ -851,25 +848,22 @@ function get_interface_list($mode = 'active')
'vip'
);
$ifnames_up = legacy_interface_listget('up');
$ifnames = legacy_interface_listget();
switch ($mode) {
case 'media':
$intlist = $ifnames;
$ifconfig = '';
exec("/sbin/ifconfig -a", $ifconfig);
$regexp = '/(' . implode('|', $intlist) . '):\s/';
$ifstatus = preg_grep('/status:/', $ifconfig);
foreach ($ifstatus as $status) {
$int = array_shift($intlist);
if (stristr($status, 'active')) {
$upints[] = $int;
if ($only_active) {
$_ifnames = array();
foreach ($ifnames as $ifname) {
$ifinfo = legacy_interface_stats($ifname);
if (isset($ifinfo['link state'])) {
if ($ifinfo['link state'] == '2') {
$_ifnames[] = $ifname;
}
}
}
break;
default:
$upints = legacy_interface_listget('up');
break;
$ifnames = $_ifnames;
}
foreach ($ifnames as $ifname) {
......@@ -880,7 +874,7 @@ function get_interface_list($mode = 'active')
$ifdata = pfSense_get_interface_addresses($ifname);
$toput = array(
'up' => in_array($ifname, $upints),
'up' => in_array($ifname, $ifnames_up),
'ipaddr' => $ifdata['ipaddr'],
'mac' => $ifdata['macaddr']
);
......
......@@ -173,7 +173,7 @@ if (is_interface_mismatch()) {
echo PHP_EOL . gettext('Default interfaces not found -- Running interface assignment option.') . PHP_EOL;
led_assigninterfaces();
while (!set_networking_interfaces_ports());
while (!set_networking_interfaces_ports(true));
led_kitt();
}
......
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