-
Beniamino Galvani authored
DHCP leases for a given interface are already exported on D-Bus through DHCP4Config and DHCP6Config objects. It is useful to have the same information also available on the filesystem so that it can be easily used by scripts. NM already saves some information about DHCP leases in /var, however that directory can only be accessed by root, for good reasons. Append lease options to the existing state file /run/NetworkManager/devices/$ifindex. Contrary to /var this directory is not persistent, but it seems more correct to expose the lease only when it is active and not after it expired or after a reboot. Since the file is in keyfile format, we add new [dhcp4] and [dhcp6] sections; however, since some options have the same name for DHCPv4 and DHCPv6, we add a "dhcp4." or "dhcp6." prefix to make the parsing by scripts (e.g. via "grep") easier. The option name is the same we use on D-Bus. Since some DHCPv6 options also have a "dhcp6_" prefix, the key name can contain "dhcp6" twice. The new sections look like this: [dhcp4] dhcp4.broadcast_address=172.25.1.255 dhcp4.dhcp_lease_time=120 dhcp4.dhcp_server_identifier=172.25.1.4 dhcp4.domain_name_servers=172.25.1.4 dhcp4.domain_search=example.com dhcp4.expiry=1641214444 dhcp4.ip_address=172.25.1.182 dhcp4.next_server=172.25.1.4 dhcp4.routers=172.25.1.4 dhcp4.subnet_mask=255.255.255.0 [dhcp6] dhcp6.dhcp6_name_servers=fd01::1 dhcp6.dhcp6_ntp_servers=ntp.example.com dhcp6.ip6_address=fd01::1aa
6ab5c4e5
To find the state of this project's repository at the time of any of these versions, check out the tags.