summaryrefslogtreecommitdiffstats
path: root/src/etc/inc/util.inc
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/etc/inc/util.inc
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/etc/inc/util.inc')
-rw-r--r--src/etc/inc/util.inc36
1 files changed, 36 insertions, 0 deletions
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;
+}
?>
OpenPOWER on IntegriCloud