Add multi wan dhclient support.

This commit is contained in:
Scott Ullrich 2005-07-06 20:37:12 +00:00
parent b8c835d225
commit 0311dbd536
2 changed files with 150 additions and 20 deletions

View File

@ -216,7 +216,6 @@ function interfaces_optional_configure_if($opti) {
/* bridged? */
if ($optcfg['bridge']) {
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) . " delete up");
/* use open/netBSD style bridge */
mwexec("/sbin/ifconfig bridge{$bridges_total} create");
mwexec("/sbin/brconfig bridge{$bridges_total} add {$optcfg['if']} add {$config['interfaces'][$optcfg['bridge']]['if']} up");
@ -224,8 +223,13 @@ function interfaces_optional_configure_if($opti) {
/* lets keep track of the amount of bridges initialized */
$bridges_total++;
} else {
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) . " " .
escapeshellarg($optcfg['ipaddr'] . "/" . $optcfg['subnet']));
/* if user has selected DHCP type then act accordingly */
if($optcfg['type'] == 'DHCP') {
interfaces_opt_dhcp_configure($opti);
} else {
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) . " " .
escapeshellarg($optcfg['ipaddr'] . "/" . $optcfg['subnet']));
}
}
} else {
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) . " delete down");
@ -382,6 +386,11 @@ function interfaces_wireless_configure($if, $wlcfg) {
}
function find_dhclient_process($interface) {
$pid = `ps ax | grep dhclient | grep {$interface} | cut -f" " -d2`;
return $pid;
}
function interfaces_wan_configure() {
global $config, $g;
@ -389,16 +398,17 @@ function interfaces_wan_configure() {
if(!$g['booting']) {
mute_kernel_msgs();
/* kill dhclient */
killbypid("{$g['varrun_path']}/dhclient.pid");
/* find dhclient process for wan and kill it */
killbypid(find_dhclient_process("wan"));
/* kill PPPoE client (mpd) */
killbypid("{$g['varrun_path']}/mpd.pid");
/* wait for processes to die */
sleep(2);
sleep(1);
unlink_if_exists("{$g['varetc_path']}/dhclient.conf");
unlink_if_exists("{$g['varetc_path']}/dhclient_wan.conf");
unlink_if_exists("{$g['varetc_path']}/mpd.conf");
unlink_if_exists("{$g['varetc_path']}/mpd.links");
unlink_if_exists("{$g['vardb_path']}/wanip");
@ -488,15 +498,54 @@ function interfaces_wan_configure() {
return 0;
}
function interfaces_opt_dhcp_configure($interface) {
global $config, $g;
$optcfg = $config['interfaces'][$interface];
/* generate dhclient_wan.conf */
$fd = fopen("{$g['varetc_path']}/dhclient_{$interface}.conf", "w");
if (!$fd) {
printf("Error: cannot open dhclient_{$interface}.conf in interfaces_opt_dhcp_configure({$interface}) for writing.\n");
return 1;
}
$dhclientconf = "";
if ($optcfg['dhcphostname']) {
$dhclientconf .= <<<EOD
send dhcp-client-identifier "{$optcfg['dhcphostname']}";
interface "{$optcfg['if']}" {
send host-name "{$optcfg['dhcphostname']}";
}
EOD;
}
fwrite($fd, $dhclientconf);
fclose($fd);
$optif = $optcfg['if'];
/* bring wan interface up before starting dhclient */
mwexec("/sbin/ifconfig {$optif} up");
/* fire up dhclient */
mwexec_bg("/sbin/dhclient -c {$g['varetc_path']}/dhclient_{$interface}.conf {$optif}");
return 0;
}
function interfaces_wan_dhcp_configure() {
global $config, $g;
$wancfg = $config['interfaces']['wan'];
/* generate dhclient.conf */
$fd = fopen("{$g['varetc_path']}/dhclient.conf", "w");
/* generate dhclient_wan.conf */
$fd = fopen("{$g['varetc_path']}/dhclient_wan.conf", "w");
if (!$fd) {
printf("Error: cannot open dhclient.conf in interfaces_wan_dhcp_configure().\n");
printf("Error: cannot open dhclient_wan.conf in interfaces_wan_dhcp_configure() for writing.\n");
return 1;
}
@ -522,7 +571,7 @@ EOD;
mwexec("/sbin/ifconfig {$wanif} up");
/* fire up dhclient */
mwexec_bg("/sbin/dhclient -c {$g['varetc_path']}/dhclient.conf {$wanif}");
mwexec_bg("/sbin/dhclient -c {$g['varetc_path']}/dhclient_wan.conf {$wanif}");
return 0;
}

View File

@ -44,21 +44,33 @@ if (!$index)
$optcfg = &$config['interfaces']['opt' . $index];
$pconfig['descr'] = $optcfg['descr'];
$pconfig['bridge'] = $optcfg['bridge'];
$pconfig['ipaddr'] = $optcfg['ipaddr'];
$pconfig['subnet'] = $optcfg['subnet'];
$pconfig['gateway'] = $optcfg['gateway'];
$pconfig['bandwidth'] = $optcfg['bandwidth'];
$pconfig['bandwidthtype'] = $optcfg['bandwidthtype'];
$pconfig['enable'] = isset($optcfg['enable']);
$pconfig['blockpriv'] = isset($optcfg['blockpriv']);
$pconfig['blockbogons'] = isset($optcfg['blockbogons']);
$pconfig['spoofmac'] = $optcfg['spoofmac'];
$pconfig['mtu'] = $optcfg['mtu'];
/* Wireless interface? */
if (isset($optcfg['wireless'])) {
require("interfaces_wlan.inc");
wireless_config_init();
}
if ($optcfg['ipaddr'] == "dhcp") {
$pconfig['type'] = "DHCP";
} else {
$pconfig['type'] = "Static";
$pconfig['ipaddr'] = $optcfg['ipaddr'];
$pconfig['subnet'] = $optcfg['subnet'];
$pconfig['gateway'] = $optcfg['gateway'];
$pconfig['pointtopoint'] = $optcfg['pointtopoint'];
}
if ($_POST) {
unset($input_errors);
@ -123,11 +135,11 @@ if ($_POST) {
}
if (!$input_errors) {
$optcfg['descr'] = $_POST['descr'];
$optcfg['ipaddr'] = $_POST['ipaddr'];
$optcfg['subnet'] = $_POST['subnet'];
$optcfg['bridge'] = $_POST['bridge'];
$optcfg['enable'] = $_POST['enable'] ? true : false;
if($_POST['bandwidth'] <> "" and $_POST['bandwidthtype'] <> "") {
$optcfg['bandwidth'] = $_POST['bandwidth'];
$optcfg['bandwidthtype'] = $_POST['bandwidthtype'];
@ -135,7 +147,17 @@ if ($_POST) {
unset($optcfg['bandwidth']);
unset($optcfg['bandwidthtype']);
}
$optcfg['gateway'] = $_POST['gateway'];
if ($_POST['type'] == "Static") {
$optcfg['ipaddr'] = $_POST['ipaddr'];
$optcfg['subnet'] = $_POST['subnet'];
$optcfg['gateway'] = $_POST['gateway'];
if (isset($optcfg['ispointtopoint']))
$optcfg['pointtopoint'] = $_POST['pointtopoint'];
} else if ($_POST['type'] == "DHCP") {
$optcfg['ipaddr'] = "dhcp";
$optcfg['dhcphostname'] = $_POST['dhcphostname'];
}
write_config();
@ -181,6 +203,20 @@ function enable_change(enable_over) {
function ipaddr_change() {
document.iform.subnet.selectedIndex = gen_bits_opt(document.iform.ipaddr.value);
}
function type_change(enable_change,enable_change_pptp) {
switch (document.iform.type.selectedIndex) {
case 0:
document.iform.ipaddr.disabled = 0;
document.iform.subnet.disabled = 0;
document.iform.gateway.disabled = 0;
break;
case 1:
document.iform.ipaddr.disabled = 1;
document.iform.subnet.disabled = 1;
document.iform.gateway.disabled = 1;
break;
}
}
//-->
</script>
@ -197,14 +233,59 @@ function ipaddr_change() {
<td width="78%" class="vtable">
<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
<strong>Enable Optional <?=$index;?> interface</strong></td>
</tr>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Description</td>
<td width="78%" class="vtable">
<input name="descr" type="text" class="formfld" id="descr" size="30" value="<?=htmlspecialchars($pconfig['descr']);?>">
<br> <span class="vexpl">Enter a description (name) for the interface here.</span>
</td>
</tr>
</td>
</tr>
<tr>
<td colspan="2" valign="top" height="16"></td>
</tr>
<tr>
<td colspan="2" valign="top" class="listtopic">General configuration</td>
</tr>
<tr>
<td valign="middle" class="vncell"><strong>Type</strong></td>
<td class="vtable"> <select name="type" class="formfld" id="type" onchange="type_change()">
<?php $opts = split(" ", "Static DHCP");
foreach ($opts as $opt): ?>
<option <?php if ($opt == $pconfig['type']) echo "selected";?>>
<?=htmlspecialchars($opt);?>
</option>
<?php endforeach; ?>
</select></td>
</tr>
<tr>
<td valign="top" class="vncell">MAC address</td>
<td class="vtable"> <input name="spoofmac" type="text" class="formfld" id="spoofmac" size="30" value="<?=htmlspecialchars($pconfig['spoofmac']);?>">
<?php
$ip = getenv('REMOTE_ADDR');
$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
$mac = str_replace("\n","",$mac);
?>
<a OnClick="document.forms[0].spoofmac.value='<?=$mac?>';" href="#">Copy my MAC address</a>
<br>
This field can be used to modify (&quot;spoof&quot;) the MAC
address of the WAN interface<br>
(may be required with some cable connections)<br>
Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx
or leave blank</td>
</tr>
<tr>
<td valign="top" class="vncell">MTU</td>
<td class="vtable"> <input name="mtu" type="text" class="formfld" id="mtu" size="8" value="<?=htmlspecialchars($pconfig['mtu']);?>">
<br>
If you enter a value in this field, then MSS clamping for
TCP connections to the value entered above minus 40 (TCP/IP
header size) will be in effect. If you leave this field blank,
an MTU of 1492 bytes for PPPoE and 1500 bytes for all other
connection types will be assumed.</td>
</tr>
<tr>
<td colspan="2" valign="top" height="16"></td>
</tr>