Page MenuHomePhabricator

"show dhcpv6 server leases" shows leases from wrong file
Closed, ResolvedPublicBUG

Description

"show dhcpv6 server leases" shows outdated (very old) leases from "/opt/vyatta/etc/config/dhcpdv6.leases".
Instead it should use "/config/dhcpd6.leases" which is used by dhcpd.

ps shows dhcpd using /config/dhcpd6.leases:

/usr/sbin/dhcpd -q -6 -lf /config/dhcpd6.leases -cf /etc/dhcp/dhcpd6.conf -pf /var/run/dhcpd6.pid

(edit): fixed typo in filename

Details

Difficulty level
Easy (less than an hour)
Version
1.2.0-rolling+201905261657
Why the issue appeared?
Implementation mistake

Event Timeline

jjakob created this task.Jun 12 2019, 12:12 PM
c-po claimed this task.Jun 12 2019, 12:28 PM
jjakob updated the task description. (Show Details)Jun 12 2019, 1:15 PM

After some more investigation, dhcpd6.leases in /config/ and /opt/vyatta/etc/config/ are the same.
In the same config folder there's also dhcpdv6.leases (with the letter "v" before 6) that's a leftover from an older image.

-rw-r--r-- 1 root root       3262 Jun 12 14:55 dhcpd6.leases
-rw-r--r-- 1 root root       2615 Jun 12 14:23 dhcpd6.leases~
-rw-r--r-- 1 root root      27726 Jun 12 14:30 dhcpd.leases
-rw-r--r-- 1 root root      28072 Jun 12 14:22 dhcpd.leases~
-rwxrwxr-x 1 root vyattacfg  8141 Oct 27  2018 dhcpdv6.leases
-rwxrwxr-x 1 root vyattacfg 17618 Oct 27  2018 dhcpdv6.leases~

If I delete these two, I get a nice traceback when running show dhcpv6 server leases:

vyos@vyos:~$ show dhcpv6 server leases 
Traceback (most recent call last):
  File "/usr/libexec/vyos/op_mode/show_dhcpv6.py", line 81, in <module>
    leases = get_leases(lease_file, state='active')
  File "/usr/libexec/vyos/op_mode/show_dhcpv6.py", line 44, in get_leases
    leases = IscDhcpLeases(lease_file).get()
  File "/usr/lib/python3/dist-packages/isc_dhcp_leases/iscdhcpleases.py", line 110, in get
    with open(self.filename) as lease_file:
FileNotFoundError: [Errno 2] No such file or directory: '/config/dhcpdv6.leases'

So it seems that at some point the dhcpd leases filename was changed without updating the name everywhere else (and leaving the old files dangling).

pasik added a subscriber: pasik.Jun 13 2019, 7:42 PM
c-po changed the task status from Open to Backport pending.Jun 16 2019, 12:05 AM
c-po triaged this task as Normal priority.

Please verify the fix with latest rolling release

jjakob added a comment.EditedJun 16 2019, 6:55 PM

@c-po The commits only fix the generated config filename, not the one used by dhcpd (set in /etc/default/isc-dhcpdv6-server) so it would probably break the dhcpv6-server. Even if both were updated, that would cause the server to forget all the cached leases on upgrade that are stored in the old leases file as there is no migration script to copy the old filename to new.

I'd revert both commits and change just src/op_mode/show_dhcpv6.py line 27 to show the current filename.

jjakob claimed this task.Jun 16 2019, 6:56 PM
jjakob added a subscriber: c-po.
c-po added a comment.Jun 16 2019, 7:15 PM

I‘d keep it as it is as it was previously a bug accessibg the wrong file. As DHCP clients usually request their last assigned address not to many systems will break.

jjakob added a comment.EditedJun 16 2019, 7:50 PM

@c-po Line 115 and 116 of src/conf_mode/dhcpv6_server.py (that generate /etc/default/isc-dhcpdv6-server) still reference the dhcpd6 name and would need to be changed also.
Are you sure we should change all these filenames and the leases filename without migrating it? I guess if you wanted the naming with "dhcpv6" consistent, but IMO it's unnecessary.
The alternative would be to just fix src/op_mode/show_dhcpv6.py and keep the old lease file naming, thus not breaking the cache on upgrade for all users.
I'll create a PR with the version you decide...

c-po added a comment.Jun 22 2019, 4:48 PM

backported into 1.2.2

c-po closed this task as Resolved.Jun 22 2019, 4:48 PM
c-po moved this task from In Progress to Finished on the VyOS 1.2 Crux (VyOS 1.2.2) board.
dmbaturin changed Difficulty level from Unknown (require assessment) to Easy (less than an hour).Jul 1 2019, 8:57 AM
dmbaturin changed Why the issue appeared? from Will be filled on close to Implementation mistake.