summaryrefslogtreecommitdiffstats
path: root/src/etc/inc/util.inc
diff options
context:
space:
mode:
authorPhil Davis <phil.davis@inf.org>2017-01-08 20:53:15 +0545
committerPhil Davis <phil.davis@inf.org>2017-01-08 20:53:15 +0545
commitf4bbec8bf04aa22601cfdea2b9c7513cf01d9d79 (patch)
tree276ba1a0b08840461d5486f5a53f1b951a4a45ca /src/etc/inc/util.inc
parent7e33d908b155007e06281f07544e9ab26f357d6e (diff)
downloadpfsense-f4bbec8bf04aa22601cfdea2b9c7513cf01d9d79.zip
pfsense-f4bbec8bf04aa22601cfdea2b9c7513cf01d9d79.tar.gz
Helper format_duid() for DUID input
Diffstat (limited to 'src/etc/inc/util.inc')
-rw-r--r--src/etc/inc/util.inc30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc
index 4d157d7..ad94157 100644
--- a/src/etc/inc/util.inc
+++ b/src/etc/inc/util.inc
@@ -2553,7 +2553,35 @@ function validateipaddr(&$addr, $type, $label, &$err_msg, $alias=false) {
return false;
}
-/* returns true if $dhcp6duid is a valid duid entrry */
+/* format a string to look (more) like the expected DUID format:
+ * 1) Replace any "-" with ":"
+ * 2) If the user inputs 14 components, then add the expected "0e:00:" to the front.
+ * This is convenience, because the actual DUID (which is reported in logs) is the last 14 components.
+ * 3) If any components are input with just a single char (hex digit hopefully), put a "0" in front.
+ *
+ * The final result should be closer to:
+ *
+ * "0e:00:00:01:00:01:nn:nn:nn:nn:nn:nn:nn:nn:nn:nn"
+ *
+ * This function does not validate the input. is_duid() will do validation.
+*/
+function format_duid($dhcp6duid) {
+ $formatted_dhcp6duid = strtolower(str_replace("-", ":", $dhcp6duid));
+ $values = explode(":", $formatted_dhcp6duid);
+ if (count($values) == 14) {
+ $formatted_dhcp6duid = '0e:00:' . $formatted_dhcp6duid;
+ $values = explode(":", $formatted_dhcp6duid);
+ }
+ foreach ($values as $idx => $value) {
+ if (strlen($value) == 1) {
+ $values[$idx] = "0" . $value;
+ }
+ }
+ $formatted_dhcp6duid = implode(":", $values);
+ return $formatted_dhcp6duid;
+}
+
+/* returns true if $dhcp6duid is a valid duid entry */
function is_duid($dhcp6duid) {
$values = explode(":", $dhcp6duid);
if (count($values) != 16 || strlen($dhcp6duid) != 47) {
OpenPOWER on IntegriCloud