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 @@ ...@@ -28,14 +28,6 @@
POSSIBILITY OF SUCH DAMAGE. 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) function timeout($timer = 9)
{ {
while (!isset($key)) { while (!isset($key)) {
...@@ -55,9 +47,7 @@ function timeout($timer = 9) ...@@ -55,9 +47,7 @@ function timeout($timer = 9)
return $key; return $key;
} }
function set_networking_interfaces_ports($probe = false)
function set_networking_interfaces_ports()
{ {
global $config; global $config;
...@@ -66,8 +56,12 @@ function set_networking_interfaces_ports() ...@@ -66,8 +56,12 @@ function set_networking_interfaces_ports()
$interactive = true; $interactive = true;
$key = null; $key = null;
/* kernel messages clobber stty probing on ifconfig up */
mute_kernel_msgs();
$iflist = get_interface_list(); $iflist = get_interface_list();
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: ');
$key = timeout(7); $key = timeout(7);
...@@ -78,6 +72,7 @@ function set_networking_interfaces_ports() ...@@ -78,6 +72,7 @@ function set_networking_interfaces_ports()
if ($key != "\n") { if ($key != "\n") {
echo PHP_EOL; echo PHP_EOL;
} }
}
echo <<<EOD echo <<<EOD
...@@ -90,6 +85,7 @@ EOD; ...@@ -90,6 +85,7 @@ EOD;
$iflist = array(); $iflist = array();
} else { } else {
foreach ($iflist as $iface => $ifa) { foreach ($iflist as $iface => $ifa) {
interfaces_bring_up($iface);
echo sprintf("% -7s%s %s %s\n", $iface, $ifa['mac'], echo sprintf("% -7s%s %s %s\n", $iface, $ifa['mac'],
$ifa['up'] ? " (up)" : "(down)", $ifa['dmesg']); $ifa['up'] ? " (up)" : "(down)", $ifa['dmesg']);
} }
...@@ -149,6 +145,9 @@ EOD; ...@@ -149,6 +145,9 @@ EOD;
if ($wanif == 'a') { if ($wanif == 'a') {
$wanif = autodetect_interface('WAN', $fp); $wanif = autodetect_interface('WAN', $fp);
if (!$wanif) {
continue;
}
} }
if (!array_key_exists($wanif, $iflist)) { if (!array_key_exists($wanif, $iflist)) {
...@@ -176,6 +175,9 @@ EOD; ...@@ -176,6 +175,9 @@ EOD;
if ($lanif == 'a') { if ($lanif == 'a') {
$lanif = autodetect_interface('LAN', $fp); $lanif = autodetect_interface('LAN', $fp);
if (!$lanif) {
continue;
}
} }
if (!array_key_exists($lanif, $iflist)) { if (!array_key_exists($lanif, $iflist)) {
...@@ -227,7 +229,7 @@ EOD; ...@@ -227,7 +229,7 @@ EOD;
} }
if ($optif[$i] == 'a') { if ($optif[$i] == 'a') {
$ad = autodetect_interface(gettext("Optional") . " " . $io, $fp); $ad = autodetect_interface('OPT' . $io, $fp);
if (!$ad) { if (!$ad) {
unset($optif[$i]); unset($optif[$i]);
continue; continue;
...@@ -288,6 +290,8 @@ EOD; ...@@ -288,6 +290,8 @@ EOD;
} }
if (!in_array($key, array('y', 'Y'))) { if (!in_array($key, array('y', 'Y'))) {
unmute_kernel_msgs();
fclose($fp);
return false; return false;
} }
...@@ -416,33 +420,36 @@ EOD; ...@@ -416,33 +420,36 @@ EOD;
write_config("Console assignment of interfaces"); write_config("Console assignment of interfaces");
printf(gettext("done.%s"), "\n"); printf(gettext("done.%s"), "\n");
unmute_kernel_msgs();
fclose($fp); fclose($fp);
return true; 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 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. Then press ENTER to continue.
EOD; EOD;
fgets($fp); fgets($fp);
$iflist = get_interface_list('media');
foreach ($iflist_prev as $ifn => $ifa) { $iflist = get_interface_list(true);
if (!$ifa['up'] && $iflist[$ifn]['up']) {
printf(gettext("Detected link-up on interface %s.%s"), $ifn, "\n"); foreach ($iflist as $ifn => $ifa) {
if (!isset($iflist_prev[$ifn])) {
printf(gettext("Detected link-up: %s%s"), $ifn, "\n");
return $ifn; return $ifn;
} }
} }
printf(gettext("No link-up detected.%s"), "\n"); printf(gettext("No link-up detected.%s"), "\n");
return null; return false;
} }
function vlan_setup($iflist, $fp) function vlan_setup($iflist, $fp)
......
...@@ -815,16 +815,13 @@ function get_configured_ipv6_addresses() ...@@ -815,16 +815,13 @@ function get_configured_ipv6_addresses()
* get_interface_list() - Return a list of all physical interfaces * get_interface_list() - Return a list of all physical interfaces
* along with MAC, IPv4 and status. * along with MAC, IPv4 and status.
* *
* $mode = "active" - use ifconfig -lu * $only_active = false -- interfaces that are available in the system
* "media" - use ifconfig to check physical connection * true -- interfaces that are physically connected
* status (much slower)
*/ */
function get_interface_list($mode = 'active') function get_interface_list($only_active = false)
{ {
global $config; global $config;
$upints = array();
/* list of virtual interface types */ /* list of virtual interface types */
$vfaces = array( $vfaces = array(
'_vlan', '_vlan',
...@@ -851,25 +848,22 @@ function get_interface_list($mode = 'active') ...@@ -851,25 +848,22 @@ function get_interface_list($mode = 'active')
'vip' 'vip'
); );
$ifnames_up = legacy_interface_listget('up');
$ifnames = legacy_interface_listget(); $ifnames = legacy_interface_listget();
switch ($mode) { if ($only_active) {
case 'media': $_ifnames = array();
$intlist = $ifnames;
$ifconfig = ''; foreach ($ifnames as $ifname) {
exec("/sbin/ifconfig -a", $ifconfig); $ifinfo = legacy_interface_stats($ifname);
$regexp = '/(' . implode('|', $intlist) . '):\s/'; if (isset($ifinfo['link state'])) {
$ifstatus = preg_grep('/status:/', $ifconfig); if ($ifinfo['link state'] == '2') {
foreach ($ifstatus as $status) { $_ifnames[] = $ifname;
$int = array_shift($intlist);
if (stristr($status, 'active')) {
$upints[] = $int;
} }
} }
break; }
default:
$upints = legacy_interface_listget('up'); $ifnames = $_ifnames;
break;
} }
foreach ($ifnames as $ifname) { foreach ($ifnames as $ifname) {
...@@ -880,7 +874,7 @@ function get_interface_list($mode = 'active') ...@@ -880,7 +874,7 @@ function get_interface_list($mode = 'active')
$ifdata = pfSense_get_interface_addresses($ifname); $ifdata = pfSense_get_interface_addresses($ifname);
$toput = array( $toput = array(
'up' => in_array($ifname, $upints), 'up' => in_array($ifname, $ifnames_up),
'ipaddr' => $ifdata['ipaddr'], 'ipaddr' => $ifdata['ipaddr'],
'mac' => $ifdata['macaddr'] 'mac' => $ifdata['macaddr']
); );
......
...@@ -173,7 +173,7 @@ if (is_interface_mismatch()) { ...@@ -173,7 +173,7 @@ if (is_interface_mismatch()) {
echo PHP_EOL . gettext('Default interfaces not found -- Running interface assignment option.') . PHP_EOL; echo PHP_EOL . gettext('Default interfaces not found -- Running interface assignment option.') . PHP_EOL;
led_assigninterfaces(); led_assigninterfaces();
while (!set_networking_interfaces_ports()); while (!set_networking_interfaces_ports(true));
led_kitt(); 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