Skip to content

Commit ff22985

Browse files
committed
dhcp-server: T9202: add client identifier to DHCPv4 lease output
kea_get_server_leases() copies the DHCPv6 DUID out of the lease Kea returns but drops the DHCPv4 client identifier, so `show dhcp server leases` cannot show it and neither can anything built on the op-mode API. Kea itself has it: lease4-get-all returns 'client-id' alongside 'hw-address'. This matters wherever a reservation is matched on the client identifier rather than the MAC. Hosts using systemd-networkd send an RFC 4361 identifier -- ff:<IAID>:<DUID> -- instead of the traditional 01:<MAC>, and Kea matches a static-mapping 'duid' against the DUID embedded in it. Without the identifier in the lease output there is no way to read the value a reservation has to be written with, and a static-mapping carrying the wrong one is accepted, rendered into the Kea configuration, and silently never matches: the host keeps taking a dynamic address while every screen reports it as reserved. Kea returns client-id already colon separated, so unlike the DHCPv6 DUID it is not passed through _format_hex_string(). IP Address MAC address Hostname Client ID 192.168.10.60 00:e0:4c:68:4e:0d arya 01:00:e0:4c:68:4e:0d 192.168.10.40 52:54:00:32:6a:fa ppp-server ff:00:32:6a:fa:00:01:00:01:32:0d:2a:4c:52:54:00:32:6a:fa 192.168.10.92 52:54:00:e3:be:41 ember-u26 ff:b5:5e:67:ff:00:02:00:00:ab:11:68:46:79:5a:ab:74:cd:25 The column is appended rather than inserted next to the MAC, matching where DHCPv6 already puts its DUID and leaving the existing column order untouched. 'client_id' is also accepted as a sort key and offered in the completion list for the inet variants of 'show dhcp server leases sort'. Signed-off-by: allanice001 <allanice001@gmail.com>
1 parent ba8924d commit ff22985

3 files changed

Lines changed: 28 additions & 9 deletions

File tree

op-mode-definitions/dhcp.xml.in

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
<properties>
118118
<help>Show DHCP server leases sorted by the specified key</help>
119119
<completionHelp>
120-
<list>end hostname ip mac pool remaining start state</list>
120+
<list>client_id end hostname ip mac pool remaining start state</list>
121121
</completionHelp>
122122
</properties>
123123
<command>${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf '' --origin $6 --sort $8</command>
@@ -137,7 +137,7 @@
137137
<properties>
138138
<help>Show DHCP server leases sorted by the specified key</help>
139139
<completionHelp>
140-
<list>end hostname ip mac remaining start state</list>
140+
<list>client_id end hostname ip mac remaining start state</list>
141141
</completionHelp>
142142
</properties>
143143
<command>${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf '' --pool $6 --sort $8</command>
@@ -148,7 +148,7 @@
148148
<properties>
149149
<help>Show DHCP server leases sorted by the specified key</help>
150150
<completionHelp>
151-
<list>end hostname ip mac pool remaining start state</list>
151+
<list>client_id end hostname ip mac pool remaining start state</list>
152152
</completionHelp>
153153
</properties>
154154
<command>${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf '' --sort $6</command>
@@ -166,7 +166,7 @@
166166
<properties>
167167
<help>Show DHCP server leases sorted by the specified key</help>
168168
<completionHelp>
169-
<list>end hostname ip mac pool remaining start</list>
169+
<list>client_id end hostname ip mac pool remaining start</list>
170170
</completionHelp>
171171
</properties>
172172
<command>${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf '' --state $6 --sort $8</command>
@@ -256,7 +256,7 @@
256256
<properties>
257257
<help>Show DHCP server leases sorted by the specified key</help>
258258
<completionHelp>
259-
<list>end hostname ip mac pool remaining start state</list>
259+
<list>client_id end hostname ip mac pool remaining start state</list>
260260
</completionHelp>
261261
</properties>
262262
<command>${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf $5 --origin $8 --sort $10</command>
@@ -276,7 +276,7 @@
276276
<properties>
277277
<help>Show DHCP server leases sorted by the specified key</help>
278278
<completionHelp>
279-
<list>end hostname ip mac remaining start state</list>
279+
<list>client_id end hostname ip mac remaining start state</list>
280280
</completionHelp>
281281
</properties>
282282
<command>${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf $5 --pool $8 --sort $10</command>
@@ -287,7 +287,7 @@
287287
<properties>
288288
<help>Show DHCP server leases sorted by the specified key</help>
289289
<completionHelp>
290-
<list>end hostname ip mac pool remaining start state</list>
290+
<list>client_id end hostname ip mac pool remaining start state</list>
291291
</completionHelp>
292292
</properties>
293293
<command>${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf $5 --sort $8</command>
@@ -305,7 +305,7 @@
305305
<properties>
306306
<help>Show DHCP server leases sorted by the specified key</help>
307307
<completionHelp>
308-
<list>end hostname ip mac pool remaining start</list>
308+
<list>client_id end hostname ip mac pool remaining start</list>
309309
</completionHelp>
310310
</properties>
311311
<command>${vyos_op_scripts_dir}/dhcp.py show_server_leases --family inet --vrf $5 --state $8 --sort $10</command>

python/vyos/kea.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,11 @@ def kea_get_server_leases(
683683

684684
if inet == '4':
685685
data_lease['start'] = lease['start_time'].timestamp()
686+
# DHCPv4 option 61. Kea returns it already colon separated, so
687+
# unlike the DHCPv6 DUID below it must not go through
688+
# _format_hex_string() -- that would insert a second colon after
689+
# every existing one. Absent for clients that send no option 61.
690+
data_lease['client_id'] = lease.get('client-id', '-')
686691

687692
if inet == '6':
688693
data_lease['last_communication'] = lease['start_time'].timestamp()

src/op_mode/dhcp.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
'backup',
5252
]
5353
sort_valid_inet = [
54+
'client_id',
5455
'end',
5556
'mac',
5657
'hostname',
@@ -111,8 +112,20 @@ def _get_formatted_server_leases(raw_data, family='inet'):
111112
pool = lease.get('pool')
112113
hostname = lease.get('hostname')
113114
origin = lease.get('origin')
115+
client_id = lease.get('client_id')
114116
data_entries.append(
115-
[ipaddr, hw_addr, state, start, end, remain, pool, hostname, origin]
117+
[
118+
ipaddr,
119+
hw_addr,
120+
state,
121+
start,
122+
end,
123+
remain,
124+
pool,
125+
hostname,
126+
origin,
127+
client_id,
128+
]
116129
)
117130

118131
headers = [
@@ -125,6 +138,7 @@ def _get_formatted_server_leases(raw_data, family='inet'):
125138
'Pool',
126139
'Hostname',
127140
'Origin',
141+
'Client ID',
128142
]
129143

130144
if family == 'inet6':

0 commit comments

Comments
 (0)