From 4ec97df4c475223b31df31cb61e78f1bdb71d789 Mon Sep 17 00:00:00 2001 From: Stephan de Wit Date: Tue, 1 Aug 2023 11:50:59 +0200 Subject: [PATCH] dhcpv6: revert previous, use base16 instead --- src/opnsense/scripts/dhcp/get_leases6.py | 42 ++++++++++-------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/opnsense/scripts/dhcp/get_leases6.py b/src/opnsense/scripts/dhcp/get_leases6.py index 40d845cc9..c237a9373 100755 --- a/src/opnsense/scripts/dhcp/get_leases6.py +++ b/src/opnsense/scripts/dhcp/get_leases6.py @@ -33,7 +33,6 @@ import calendar import datetime import time import argparse -import re def parse_date(ymd, hms): dt = '%s %s' % (ymd, hms) @@ -68,8 +67,8 @@ def parse_iaaddr_iaprefix(input): def parse_iaid_duid(input): """ - parse the combined IAID_DUID value. This is provided in octal or hex format. - In case of octal, non-printable characters are provided as octal escapes. + parse the combined IAID_DUID value. This is provided in octal format. + non-printable characters are provided as octal escapes. We return the hex representation of the raw IAID_DUID value, the IAID integer, as well as the separated DUID value in a dict. The IAID_DUID value is used to uniquely identify a lease, so this value should be used to determine the last @@ -77,29 +76,24 @@ def parse_iaid_duid(input): """ input = input[1:-1] # strip double quotes parsed = [] - - hex_pattern = re.compile(r'^([0-9a-fA-F]{2}:){0,}[0-9a-fA-F]{2}$') - if hex_pattern.match(input): - parsed = input.split(':') - else: - i = 0 - while i < len(input): - c = input[i] - if c == '\\': - next_c = input[i + 1] - if next_c == '\\' or next == '"': - parsed.append("%02x" % ord(next_c)) - i += 1 - elif next_c.isnumeric(): - octal_to_decimal = int(input[i+1:i+4], 8) - parsed.append("%02x" % octal_to_decimal) - i += 3 - else: - parsed.append("%02x" % ord(c)) - i += 1 + i = 0 + while i < len(input): + c = input[i] + if c == '\\': + next_c = input[i + 1] + if next_c == '\\' or next == '"': + parsed.append("%02x" % ord(next_c)) + i += 1 + elif next_c.isnumeric(): + octal_to_decimal = int(input[i+1:i+4], 8) + parsed.append("%02x" % octal_to_decimal) + i += 3 + else: + parsed.append("%02x" % ord(c)) + i += 1 return { - 'iaid': int(''.join(reversed(parsed[0:4]))), + 'iaid': int(''.join(reversed(parsed[0:4])), 16), 'duid': ":".join([str(a) for a in parsed[4:]]), 'iaid_duid': ":".join([str(a) for a in parsed]) }