diff options
author | Ermal Luçi <eri@pfsense.org> | 2008-06-04 21:28:00 +0000 |
---|---|---|
committer | Ermal Luçi <eri@pfsense.org> | 2008-06-04 21:28:00 +0000 |
commit | 2075fadb5fce5e844d96c500cdc804a1bb7f1da9 (patch) | |
tree | 2515e3c4c9ef0c74db4b9d05f56081f251353499 /etc/inc/interfaces.inc | |
parent | 3ec5e5f9b3b803eabf95f9fd0ddfe588488a5411 (diff) | |
download | pfsense-2075fadb5fce5e844d96c500cdc804a1bb7f1da9.zip pfsense-2075fadb5fce5e844d96c500cdc804a1bb7f1da9.tar.gz |
Fix braindead vlan creation procedures.
Now we do not need to go through all vlans just to delete/create one of them.
Diffstat (limited to 'etc/inc/interfaces.inc')
-rw-r--r-- | etc/inc/interfaces.inc | 97 |
1 files changed, 49 insertions, 48 deletions
diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index 05460ed..b981cfe 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -46,66 +46,67 @@ function interfaces_loopback_configure() { } function interfaces_vlan_configure() { - global $config, $g; - - if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) { + global $config; - /* devices with native VLAN support */ - $vlan_native_supp = $g['vlan_native_supp']; + if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) { - /* devices with long frame support */ - $vlan_long_frame = $g['vlan_long_frame']; + foreach ($config['vlans']['vlan'] as $vlan) + /* XXX: Maybe we should report any errors?! */ + interface_vlan_configure($vlan['if'], $vlan['tag'], $vlan['vlanif']); + } +} - /* sweep through and axe old interfaces */ - $vlan_count = get_number_of_vlan_interfaces(); - for($x=0; $x<$vlan_count; $x++) - exec("/sbin/ifconfig vlan{$x} down destroy"); +function interface_vlan_configure($if, $tag, $vlanif = "") { + global $config, $g; - $i = 0; + /* devices with native VLAN support */ + $vlan_native_supp = $g['vlan_native_supp']; - foreach ($config['vlans']['vlan'] as $vlan) { + /* devices with long frame support */ + $vlan_long_frame = $g['vlan_long_frame']; - $cmd = "/sbin/ifconfig vlan{$i} create vlan " . - escapeshellarg($vlan['tag']) . " vlandev " . - escapeshellarg($vlan['if']); + /* make sure the parent interface is up */ + mwexec("/sbin/ifconfig " . escapeshellarg($if) . " up"); - /* get driver name */ - for ($j = 0; $j < strlen($vlan['if']); $j++) { - if ($vlan['if'][$j] >= '0' && $vlan['if'][$j] <= '9') - break; - } - $drvname = substr($vlan['if'], 0, $j); + if ($g['booting']) + $vif = $vlanif; + else + $vif = "vlan"; + $cmd = "/sbin/ifconfig {$vif} create vlan " . + escapeshellarg($tag) . " vlandev " . + escapeshellarg($if); + + /* get driver name */ + for ($j = 0; $j < strlen($if); $j++) { + if ($if[$j] >= '0' && $if[$j] <= '9') + break; + } + $drvname = substr($if, 0, $j); - if (in_array($drvname, $vlan_native_supp)) - $cmd .= " link0"; - else if (in_array($drvname, $vlan_long_frame)) - $cmd .= " mtu 1500"; + if (in_array($drvname, $vlan_native_supp)) + $cmd .= " link0"; + else if (in_array($drvname, $vlan_long_frame)) + $cmd .= " mtu 1500"; - mwexec($cmd); + $vlanif = exec($cmd); - /* invalidate interface cache */ - get_interface_arr(true); + /* invalidate interface cache */ + get_interface_arr(true); - /* all vlans need to spoof their parent mac address, too. see - * ticket #1514: http://cvstrac.pfsense.com/tktview?tn=1514,33 - */ - foreach($config['interfaces'] as $interfaces) { - if($interfaces['if'] == $vlan['if']) { - if($interfaces['spoofmac']) { - mwexec("/sbin/ifconfig " . escapeshellarg($interfaces['if']) . - " link " . escapeshellarg($interfaces['spoofmac'])); - } - } - } - - /* make sure the parent interface is up */ - mwexec("/sbin/ifconfig " . escapeshellarg($vlan['if']) . " up"); + /* all vlans need to spoof their parent mac address, too. see + * ticket #1514: http://cvstrac.pfsense.com/tktview?tn=1514,33 + */ + foreach($config['interfaces'] as $interfaces) { + if($interfaces['if'] == $if && $interfaces['spoofmac']) { + mwexec("/sbin/ifconfig " . escapeshellarg($if) . + " link " . escapeshellarg($interfaces['spoofmac'])); + } + } - $i++; - } - } + /* XXX: ermal -- for now leave it here at the moment it does not hurt. */ + mwexec("/sbin/ifconfig " . escapeshellarg($if) . " up"); - return 0; + return $vlanif; } function interfaces_lan_configure() { @@ -1863,4 +1864,4 @@ function get_interface_mac($interface) { return $mac; } -?>
\ No newline at end of file +?> |