diff --git a/op-mode-definitions/dhcp.xml.in b/op-mode-definitions/dhcp.xml.in index e753558aa82..7d7b57ee668 100644 --- a/op-mode-definitions/dhcp.xml.in +++ b/op-mode-definitions/dhcp.xml.in @@ -117,7 +117,7 @@ Show DHCP server leases sorted by the specified key - end hostname ip mac pool remaining start state + client_id end hostname ip mac pool remaining start state ${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf '' --origin $6 --sort $8 @@ -137,7 +137,7 @@ Show DHCP server leases sorted by the specified key - end hostname ip mac remaining start state + client_id end hostname ip mac remaining start state ${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf '' --pool $6 --sort $8 @@ -148,7 +148,7 @@ Show DHCP server leases sorted by the specified key - end hostname ip mac pool remaining start state + client_id end hostname ip mac pool remaining start state ${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf '' --sort $6 @@ -166,7 +166,7 @@ Show DHCP server leases sorted by the specified key - end hostname ip mac pool remaining start + client_id end hostname ip mac pool remaining start ${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf '' --state $6 --sort $8 @@ -256,7 +256,7 @@ Show DHCP server leases sorted by the specified key - end hostname ip mac pool remaining start state + client_id end hostname ip mac pool remaining start state ${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf $5 --origin $8 --sort $10 @@ -276,7 +276,7 @@ Show DHCP server leases sorted by the specified key - end hostname ip mac remaining start state + client_id end hostname ip mac remaining start state ${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf $5 --pool $8 --sort $10 @@ -287,7 +287,7 @@ Show DHCP server leases sorted by the specified key - end hostname ip mac pool remaining start state + client_id end hostname ip mac pool remaining start state ${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf $5 --sort $8 @@ -305,7 +305,7 @@ Show DHCP server leases sorted by the specified key - end hostname ip mac pool remaining start + client_id end hostname ip mac pool remaining start ${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf $5 --state $8 --sort $10 diff --git a/python/vyos/kea.py b/python/vyos/kea.py index 436c134c81c..5ba3bd48332 100644 --- a/python/vyos/kea.py +++ b/python/vyos/kea.py @@ -683,6 +683,15 @@ def kea_get_server_leases( if inet == '4': data_lease['start'] = lease['start_time'].timestamp() + # DHCPv4 option 61. Kea returns it already colon separated, so + # unlike the DHCPv6 DUID below it must not go through + # _format_hex_string() -- that would insert a second colon after + # every existing one. + # + # `or` rather than a get() default: Lease4::toElement() omits the + # key for a client that sent no option 61, but this way an empty + # string reads as '-' too, matching 'hostname' two lines above. + data_lease['client_id'] = lease.get('client-id') or '-' if inet == '6': data_lease['last_communication'] = lease['start_time'].timestamp() diff --git a/src/op_mode/dhcp.py b/src/op_mode/dhcp.py index 7a4c61fee6a..b0eac77d891 100755 --- a/src/op_mode/dhcp.py +++ b/src/op_mode/dhcp.py @@ -51,6 +51,7 @@ 'backup', ] sort_valid_inet = [ + 'client_id', 'end', 'mac', 'hostname', @@ -111,8 +112,20 @@ def _get_formatted_server_leases(raw_data, family='inet'): pool = lease.get('pool') hostname = lease.get('hostname') origin = lease.get('origin') + client_id = lease.get('client_id') data_entries.append( - [ipaddr, hw_addr, state, start, end, remain, pool, hostname, origin] + [ + ipaddr, + hw_addr, + state, + start, + end, + remain, + pool, + hostname, + origin, + client_id, + ] ) headers = [ @@ -125,6 +138,7 @@ def _get_formatted_server_leases(raw_data, family='inet'): 'Pool', 'Hostname', 'Origin', + 'Client ID', ] if family == 'inet6':