summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Botelho <garga@pfSense.org>2013-12-09 03:48:45 -0800
committerRenato Botelho <garga@pfSense.org>2013-12-09 03:48:45 -0800
commitbed4017e7f073ed4101cf7728909b13d38e047b7 (patch)
treefbe3a758dfc8aab810105001d8ee20f57ac177a7
parentfb7c06b834fd1b02519039f3b3a206338bdcb3f8 (diff)
parent5a997d96b283ae03b18d801f7ade980f331c9ce2 (diff)
downloadpfsense-bed4017e7f073ed4101cf7728909b13d38e047b7.zip
pfsense-bed4017e7f073ed4101cf7728909b13d38e047b7.tar.gz
Merge pull request #862 from phil-davis/master
Fixes for DHCP range validation when entering from console
-rwxr-xr-xetc/rc.initial.setlanip58
1 files changed, 32 insertions, 26 deletions
diff --git a/etc/rc.initial.setlanip b/etc/rc.initial.setlanip
index f5320fd..13a9bdc 100755
--- a/etc/rc.initial.setlanip
+++ b/etc/rc.initial.setlanip
@@ -349,7 +349,7 @@ $config['interfaces'][$interface]['gatewayv6'] = $gwname6;
$config['interfaces'][$interface]['enable'] = true;
function console_configure_dhcpd($version = 4) {
- global $g, $config, $restart_dhcpd, $fp, $interface, $dry_run, $intip, $intbits;
+ global $g, $config, $restart_dhcpd, $fp, $interface, $dry_run, $intip, $intbits, $intip6, $intbits6;
$label_IPvX = ($version === 6) ? "IPv6" : "IPv4";
$dhcpd = ($version === 6) ? "dhcpdv6" : "dhcpd";
@@ -357,33 +357,39 @@ function console_configure_dhcpd($version = 4) {
if($g['services_dhcp_server_enable'])
$yn = prompt_for_enable_dhcp_server($version);
if ($yn == "y") {
- $subnet_start = ($version === 6) ? gen_subnetv6($intip, $intbits) : gen_subnet($intip, $intbits);
- $subnet_end = ($version === 6) ? gen_subnetv6_max($intip, $intbits) : gen_subnet_max($intip, $intbits);
+ $subnet_start = ($version === 6) ? gen_subnetv6($intip6, $intbits6) : gen_subnet($intip, $intbits);
+ $subnet_end = ($version === 6) ? gen_subnetv6_max($intip6, $intbits6) : gen_subnet_max($intip, $intbits);
do {
- echo sprintf(gettext("Enter the start address of the %s client address range:"), $label_IPvX) . " ";
- $dhcpstartip = chop(fgets($fp));
- if ($dhcpstartip === "") {
- fclose($fp);
- exit(0);
- }
- $is_ipaddr = ($version === 6) ? is_ipaddrv6($dhcpstartip) : is_ipaddrv4($dhcpstartip);
- $is_inrange = is_inrange($dhcpstartip, $subnet_start, $subnet_end);
- if (!$is_inrange)
- echo gettext("This IP address must be in the interface's subnet") . "\n";
- } while (!$is_ipaddr || !$is_inrange);
+ do {
+ echo sprintf(gettext("Enter the start address of the %s client address range:"), $label_IPvX) . " ";
+ $dhcpstartip = chop(fgets($fp));
+ if ($dhcpstartip === "") {
+ fclose($fp);
+ exit(0);
+ }
+ $is_ipaddr = ($version === 6) ? is_ipaddrv6($dhcpstartip) : is_ipaddrv4($dhcpstartip);
+ $is_inrange = is_inrange($dhcpstartip, $subnet_start, $subnet_end);
+ if (!$is_inrange)
+ echo gettext("This IP address must be in the interface's subnet") . "\n";
+ } while (!$is_ipaddr || !$is_inrange);
- do {
- echo sprintf(gettext("Enter the end address of the %s client address range:"), $label_IPvX) . " ";
- $dhcpendip = chop(fgets($fp));
- if ($dhcpendip === "") {
- fclose($fp);
- exit(0);
- }
- $is_ipaddr = ($version === 6) ? is_ipaddrv6($dhcpendip) : is_ipaddrv4($dhcpendip);
- $is_inrange = is_inrange($dhcpendip, $subnet_start, $subnet_end);
- if (!$is_inrange)
- echo gettext("This IP address must be in the interface's subnet") . "\n";
- } while (!$is_ipaddr || !$is_inrange);
+ do {
+ echo sprintf(gettext("Enter the end address of the %s client address range:"), $label_IPvX) . " ";
+ $dhcpendip = chop(fgets($fp));
+ if ($dhcpendip === "") {
+ fclose($fp);
+ exit(0);
+ }
+ $is_ipaddr = ($version === 6) ? is_ipaddrv6($dhcpendip) : is_ipaddrv4($dhcpendip);
+ $is_inrange = is_inrange($dhcpendip, $subnet_start, $subnet_end);
+ if (!$is_inrange)
+ echo gettext("This IP address must be in the interface's subnet") . "\n";
+ $not_inorder = ($version === 6) ? (inet_pton($dhcpendip) < inet_pton($dhcpstartip)) : ip_less_than($dhcpendip, $dhcpstartip);
+ if ($not_inorder) {
+ echo gettext("The end address of the DHCP range must be >= the start address") . "\n";
+ }
+ } while (!$is_ipaddr || !$is_inrange);
+ } while ($not_inorder);
$restart_dhcpd = true;
$config[$dhcpd][$interface]['enable'] = true;
$config[$dhcpd][$interface]['range']['from'] = $dhcpstartip;
OpenPOWER on IntegriCloud