Project

General

Profile

« Previous | Next » 

Revision b49e6c01

Added by Phil Davis over 9 years ago

Automatically choose some interface combinations

on factory default boot.
This allows the system to switch interfaces from the newer ones in the
default config (e.g. em0 em1) back to the interfaces used by:
Alix - vr1 vr0
APU - re1 re2
that match the WAN and LAN labels printed on many existing devices.
It means these devices can boot the default config and this will
automatically detect that there is no em0/em1 and will instead select
whatever exists out of vr1/vr0 or re1/re2. This avoids the user having
to use the serial cable to do interface assignment when starting a brand
new image, or when resetting to factory defaults. It could easily be
extended to other common interface combinations.
For me, this (or similar) would be very beneficial. At remote sites it
is really good if it is possible to do reset to factory defaults, or put
a fresh CF/SD card in, and the system boots without needing to connect a
serial cable and do interface assignment.

View differences:

src/etc/inc/config.console.inc
563 563
	}
564 564
}
565 565

  
566
function check_for_alternate_interfaces() {
567
	global $config;
568

  
569
	// If the WAN and/or LAN devices in the factory default config do not exist,
570
	// then look for alternate devices.
571
	// This lets many systems boot a factory default config without being
572
	// forced to do interface assignment on the console.
573

  
574
	$specplatform = system_identify_specific_platform();
575
	$default_device = array();
576

  
577
	// If we recognise the platform, then specify the devices directly.
578
	switch ($specplatform['name']) {
579
		case 'alix':
580
			$default_device['wan'] = "vr1";
581
			$default_device['lan'] = "vr0";
582
			break;
583
		case 'APU':
584
			$default_device['wan'] = "re1";
585
			$default_device['lan'] = "re2";
586
			break;
587
		case 'RCC-VE':
588
			$default_device['wan'] = "igb0";
589
			$default_device['lan'] = "igb1";
590
			break;
591
		default:
592
			$default_device['wan'] = "";
593
			$default_device['lan'] = "";
594
			break;
595
	}
596

  
597
	// Other common device names can be put here and will be looked for
598
	// if the system was not one of the known platforms.
599
	$other_devices_arr['wan'] = array("vr1", "re1", "igb0", "em0");
600
	$other_devices_arr['lan'] = array("vr0", "re2", "igb1", "em1");
601
	$interface_assignment_changed = false;
602

  
603
	foreach ($other_devices_arr as $ifname => $other_devices) {
604
		if (!does_interface_exist($config['interfaces'][$ifname]['if'])) {
605
			if (does_interface_exist($default_device[$ifname])) {
606
				$config['interfaces'][$ifname]['if'] = $default_device[$ifname];
607
				$interface_assignment_changed = true;
608
			} else {
609
				foreach ($other_devices as $other_device) {
610
					if (does_interface_exist($other_device)) {
611
						$config['interfaces'][$ifname]['if'] = $other_device;
612
						$interface_assignment_changed = true;
613
						break;
614
					}
615
				}
616
			}
617
		}
618
	}
619

  
620
	if ($interface_assignment_changed) {
621
		write_config("Factory default boot detected WAN " . $config['interfaces']['wan']['if'] . " and LAN " . $config['interfaces']['lan']['if']);
622
	}
623
}
624

  
566 625
?>
src/etc/rc.bootup
158 158
/* run any early shell commands specified in config.xml */
159 159
system_do_shell_commands(1);
160 160

  
161
if (file_exists("/conf/trigger_initial_wizard")) {
162
	check_for_alternate_interfaces();
163
}
164

  
161 165
/*
162 166
 *	Determine if we need to throw a interface exception
163 167
 *	and ask the user to reassign interfaces.  This will

Also available in: Unified diff