summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormarjohn56 <martin@queens-park.com>2016-12-21 15:26:17 +0000
committermarjohn56 <martin@queens-park.com>2016-12-21 15:26:17 +0000
commit7be23d53705ccbcee64d3236bf74b34c513da686 (patch)
treefd0af042ad225b942c1ca42972d7b3e689b42e72 /src
parentd6df09d0f2da7ed36dc9c68816ddc914f46d6522 (diff)
downloadpfsense-7be23d53705ccbcee64d3236bf74b34c513da686.zip
pfsense-7be23d53705ccbcee64d3236bf74b34c513da686.tar.gz
User Defined DUID
User may define a DUID to use in System->Advanced->Networking. The entered DUID is validated for composition and length, if valid it is stored in the config.xml. On call of wan_dhcp6_configure() the DUID is written to file to be read by dhcp6c on launch.
Diffstat (limited to 'src')
-rw-r--r--src/etc/inc/interfaces.inc7
-rw-r--r--src/etc/inc/util.inc36
-rw-r--r--src/usr/local/www/system_advanced_network.php22
3 files changed, 65 insertions, 0 deletions
diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc
index be68bdd..eaac41c 100644
--- a/src/etc/inc/interfaces.inc
+++ b/src/etc/inc/interfaces.inc
@@ -3868,6 +3868,13 @@ function interface_dhcpv6_configure($interface = "wan", $wancfg) {
$wanif = get_real_interface($interface, "inet6");
$dhcp6cconf = "";
+ if (!empty($config['system']['global-v6duid'])) {
+ // Write the DUID file
+ if(!write_dhcp6_duid($config['system']['global-v6duid'])) {
+ log_error(gettext("Failed to write user DUID file!"));
+ }
+ }
+
if ($wancfg['adv_dhcp6_config_file_override']) {
// DHCP6 Config File Override
$dhcp6cconf = DHCP6_Config_File_Override($wancfg, $wanif);
diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc
index 528fe0e..f8fceea 100644
--- a/src/etc/inc/util.inc
+++ b/src/etc/inc/util.inc
@@ -2542,4 +2542,40 @@ function validateipaddr(&$addr, $type, $label, &$err_msg, $alias=false) {
return false;
}
+
+
+/* returns true if $dhcp6duid is a valid duid entrry */
+function is_duid($dhcp6duid) {
+ $values = explode(":", $dhcp6duid);
+ if (count($values) != 16 || strlen($dhcp6duid) != 47) {
+ return false;
+ }
+ for ($i = 0; $i < 16; $i++) {
+ if (ctype_xdigit($values[$i]) == false)
+ return false;
+ if (hexdec($values[$i]) < 0 || hexdec($values[$i]) > 255)
+ return false;
+ }
+ return true;
+}
+
+/* Write the DHCP6 DUID file */
+function write_dhcp6_duid($duidstring) {
+ // Create the hex array from the dhcp6duid config entry and write to file
+ global $g;
+
+ if(!is_duid($duidstring)) {
+ log_error(gettext("Error: attempting to write DUID file - Invalid DUID detected"));
+ return false;
+ }
+ $temp = str_replace(":","",$duidstring);
+ $duid_binstring = pack("H*",$temp);
+ if ($fd = fopen("{$g['vardb_path']}/dhcp6c_duid", "wb")) {
+ fwrite($fd, $duid_binstring);
+ fclose($fd);
+ return true;
+ }
+ log_error(gettext("Error: attempting to write DUID file - File write error"));
+ return false;
+}
?>
diff --git a/src/usr/local/www/system_advanced_network.php b/src/usr/local/www/system_advanced_network.php
index 06a4e2d..b453045 100644
--- a/src/usr/local/www/system_advanced_network.php
+++ b/src/usr/local/www/system_advanced_network.php
@@ -40,6 +40,7 @@ require_once("shaper.inc");
$pconfig['ipv6nat_enable'] = isset($config['diag']['ipv6nat']['enable']);
$pconfig['ipv6nat_ipaddr'] = $config['diag']['ipv6nat']['ipaddr'];
$pconfig['ipv6allow'] = isset($config['system']['ipv6allow']);
+$pconfig['global-v6duid'] = $config['system']['global-v6duid'];
$pconfig['prefer_ipv4'] = isset($config['system']['prefer_ipv4']);
$pconfig['sharednet'] = $config['system']['sharednet'];
$pconfig['disablechecksumoffloading'] = isset($config['system']['disablechecksumoffloading']);
@@ -83,6 +84,18 @@ if ($_POST) {
unset($config['system']['prefer_ipv4']);
}
+ if (!empty($_POST['global-v6duid'])) {
+ $_POST['global-v6duid'] = strtolower(str_replace("-", ":", $_POST['global-v6duid']));
+ if (!is_duid($_POST['global-v6duid'])) {
+ $input_errors[] = gettext("A valid DUID must be specified");
+ } else {
+ $config['system']['global-v6duid'] = $_POST['global-v6duid'];
+ }
+ }
+ else {
+ unset($config['system']['global-v6duid']);
+ }
+
if ($_POST['sharednet'] == "yes") {
$config['system']['sharednet'] = true;
system_disable_arp_wrong_if();
@@ -186,6 +199,15 @@ $section->addInput(new Form_Checkbox(
))->setHelp('By default, if IPv6 is configured and a hostname resolves IPv6 and IPv4 addresses, '.
'IPv6 will be used. If this option is selected, IPv4 will be preferred over IPv6.');
+$section->addInput(new Form_Input(
+ 'global-v6duid',
+ 'DHCP6 DUID',
+ 'text',
+ $pconfig['global-v6duid'],
+ ['placeholder' => 'xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx']
+ ))->setWidth(9)->sethelp('Enter the DUID to use here. Use this option if using RAM Disk, as the DUID will be lost on reboot. The existing DUID may be found in var/db/dhcp6_duid.' .'<br />' .
+ 'NOTE: Do not use this option with multiple DHCP6 interfaces.');
+
$form->add($section);
$section = new Form_Section('Network Interfaces');
OpenPOWER on IntegriCloud