Revision 7955bcce
Added by kang tastic over 7 years ago
src/etc/inc/util.inc | ||
---|---|---|
2667 | 2667 |
* 2) Replace any remaining "-" with ":". |
2668 | 2668 |
* 3) If any components are input with just a single char (hex digit hopefully), put a "0" in front. |
2669 | 2669 |
* 4) The first two components should be a 16-bit integer (little- or big-endian, depending on the current machine type) that |
2670 |
* is equal to the number of other components. If not, prepend this as "nn:00" (little-endian) or "00:nn" (big-endian).
|
|
2670 |
* is equal to the number of other components. If not, prepend this as "nn:00" (all pfSense builds are little-endian).
|
|
2671 | 2671 |
* This is convenience, because the DUID reported by dhcp6c in logs does not include this count, which corresponds to the |
2672 | 2672 |
* option-len field of DHCPv6's OPTION_CLIENTID option. |
2673 | 2673 |
* |
2674 | 2674 |
* The final result should be closer to: |
2675 | 2675 |
* |
2676 |
* "nn:00:00:0n:nn:nn:nn:..." (little-endian) or "00:nn:00:0n:nn:nn:nn:..." (big-endian)
|
|
2676 |
* "nn:00:00:0n:nn:nn:nn:..." |
|
2677 | 2677 |
* |
2678 | 2678 |
* This function does not validate the input. is_duid() will do validation. |
2679 | 2679 |
*/ |
... | ... | |
2700 | 2700 |
|
2701 | 2701 |
$values = explode(':', strtolower(str_replace('-', ':', $duidpt1))); |
2702 | 2702 |
|
2703 |
if (unpack('S', "\x01\x00")[1] === 1 && hexdec($values[0]) != count($values) - 2) {
|
|
2703 |
if (hexdec($values[0]) != count($values) - 2)
|
|
2704 | 2704 |
array_unshift($values, dechex(count($values)), '00'); |
2705 |
} else if (unpack('S', "\x00\x01")[1] === 1 && hexdec($values[1]) != count($values) - 2) { |
|
2706 |
array_unshift($values, '00', dechex(count($values))); |
|
2707 |
} |
|
2708 | 2705 |
|
2709 | 2706 |
array_walk($values, function(&$value) { |
2710 | 2707 |
$value = str_pad($value, 2, '0', STR_PAD_LEFT); |
... | ... | |
2714 | 2711 |
} |
2715 | 2712 |
|
2716 | 2713 |
/* Returns true if $dhcp6duid is a valid DUID entry. |
2717 |
* Parse the entry to check for valid length according to endianness and known DUID types.
|
|
2714 |
* Parse the entry to check for valid length according to known DUID types. |
|
2718 | 2715 |
*/ |
2719 | 2716 |
function is_duid($dhcp6duid) { |
2720 | 2717 |
$values = explode(":", $dhcp6duid); |
2721 |
if (hexdec($values[unpack('S', "\x01\x00")[1] === 1 ? 0 : 1]) == count($values) - 2) {
|
|
2718 |
if (hexdec($values[0]) == count($values) - 2) {
|
|
2722 | 2719 |
switch (hexdec($values[2] . $values[3])) { |
2723 | 2720 |
case 0: |
2724 | 2721 |
return false; |
... | ... | |
2773 | 2770 |
return false; |
2774 | 2771 |
} |
2775 | 2772 |
|
2776 |
/* returns duid string from {['vardb_path']}/dhcp6c_duid' */
|
|
2773 |
/* returns duid string from 'vardb_path']}/dhcp6c_duid' */ |
|
2777 | 2774 |
function get_duid_from_file() { |
2778 | 2775 |
global $g; |
2779 | 2776 |
|
Also available in: Unified diff
Remove endianness checking
all pfSense builds are little-endian