Skip to content

Add timestamp to the output of dhcpcd -U #714

Description

@zacknewman

In #558 I requested that DHCP RENEWals be logged like they are for DHCPv6. This inconsistency was found to be due to how DHCP code uses logdebugx instead of logmessage like DHCPv6 code does. While I do think the behavior should be made to be consistent, what I actually would like to have is for a way to see information about a DHCP or DHCPv6 lease without enabling "debug" mode.

I try to plan network maintenance around my DHCP and DHCPv6 leases in an effort to keep whatever IPs were assigned. Unfortunately, dhcpcd -U only provides information related to RENEWals and expirations at the time the exchange occurred. Without also knowing when the exchange occurred, this information is not of much use. Since DHCPv6 lease information is logged to syslog(3) (at least on OpenBSD), I am able to get the necessary information since it includes the timestamp. Without the same for DHCP though, I still open myself up to the chance that network maintenance causes my DHCP lease to not be RENEWed (likely) causing a new IP to be assigned.

Would it be possible to include timestamp information in dhcpcd -U? For example instead of something like this:

router$ dhcpcd -U ixl2
reason=CARRIER
interface=ixl2
protocol=link
if_configured=true
ifcarrier=up
ifmetric=0
ifwireless=0
ifflags=34883
ifmtu=1500

reason=RENEW
interface=ixl2
protocol=dhcp
ip_address=76.131.95.65
subnet_cidr=23
network_number=76.131.94.0
subnet_mask=255.255.254.0
routers=76.131.94.1
broadcast_address=255.255.255.255
dhcp_lease_time=7200
dhcp_message_type=5
dhcp_server_identifier=96.113.84.152
dhcp_renewal_time=4159

reason=ROUTERADVERT
interface=ixl2
protocol=ra
nd1_from=fe80::21c:73ff:fe00:99
nd1_acquired=284941
nd1_now=284944
nd1_hoplimit=64
nd1_flags=MO
nd1_lifetime=1800
nd1_source_address=001c73000099
nd1_prefix_information1_length=64
nd1_prefix_information1_flags=L
nd1_prefix_information1_vltime=2592000
nd1_prefix_information1_pltime=604800
nd1_prefix_information1_prefix=fd00:0:101:41::
nd1_prefix_information2_length=64
nd1_prefix_information2_flags=L
nd1_prefix_information2_vltime=2592000
nd1_prefix_information2_pltime=604800
nd1_prefix_information2_prefix=2001:558:1028:3e9f::
nd1_prefix_information3_length=64
nd1_prefix_information3_flags=L
nd1_prefix_information3_vltime=2592000
nd1_prefix_information3_pltime=604800
nd1_prefix_information3_prefix=fd00:0:d:4::

reason=RENEW6
interface=ixl2
protocol=dhcp6
dhcp6_client_id=000445c0fc0ae1b211f09c79f0b2b93691a4
dhcp6_server_id=000100011caae03b40a8f02e8ef4
dhcp6_ia_na1_iaid=00000000
dhcp6_ia_na1_t1=43200
dhcp6_ia_na1_t2=69120
dhcp6_ia_na1_ia_addr1=2001:558:6040:b9:7ce5:5b1a:d32c:1bf0
dhcp6_ia_na1_ia_addr1_pltime=86400
dhcp6_ia_na1_ia_addr1_vltime=86400
dhcp6_ia_pd1_iaid=00000000
dhcp6_ia_pd1_t1=43200
dhcp6_ia_pd1_t2=69120
dhcp6_ia_pd1_prefix1_pltime=86400
dhcp6_ia_pd1_prefix1_vltime=86400
dhcp6_ia_pd1_prefix1_length=60
dhcp6_ia_pd1_prefix1=2601:283:4e00:fdd0::

it'd output something like this:

router$ dhcpcd -U ixl2
reason=CARRIER
interface=ixl2
protocol=link
if_configured=true
ifcarrier=up
ifmetric=0
ifwireless=0
ifflags=34883
ifmtu=1500
timestamp: Aug 25 06:39:01

reason=RENEW
interface=ixl2
protocol=dhcp
ip_address=76.131.95.65
subnet_cidr=23
network_number=76.131.94.0
subnet_mask=255.255.254.0
routers=76.131.94.1
broadcast_address=255.255.255.255
dhcp_lease_time=7200
dhcp_message_type=5
dhcp_server_identifier=96.113.84.152
dhcp_renewal_time=4159
timestamp: Aug 25 06:39:01

reason=ROUTERADVERT
interface=ixl2
protocol=ra
nd1_from=fe80::21c:73ff:fe00:99
nd1_acquired=284941
nd1_now=284944
nd1_hoplimit=64
nd1_flags=MO
nd1_lifetime=1800
nd1_source_address=001c73000099
nd1_prefix_information1_length=64
nd1_prefix_information1_flags=L
nd1_prefix_information1_vltime=2592000
nd1_prefix_information1_pltime=604800
nd1_prefix_information1_prefix=fd00:0:101:41::
nd1_prefix_information2_length=64
nd1_prefix_information2_flags=L
nd1_prefix_information2_vltime=2592000
nd1_prefix_information2_pltime=604800
nd1_prefix_information2_prefix=2001:558:1028:3e9f::
nd1_prefix_information3_length=64
nd1_prefix_information3_flags=L
nd1_prefix_information3_vltime=2592000
nd1_prefix_information3_pltime=604800
nd1_prefix_information3_prefix=fd00:0:d:4::
timestamp: Aug 25 06:39:01

reason=RENEW6
interface=ixl2
protocol=dhcp6
dhcp6_client_id=000445c0fc0ae1b211f09c79f0b2b93691a4
dhcp6_server_id=000100011caae03b40a8f02e8ef4
dhcp6_ia_na1_iaid=00000000
dhcp6_ia_na1_t1=43200
dhcp6_ia_na1_t2=69120
dhcp6_ia_na1_ia_addr1=2001:558:6040:b9:7ce5:5b1a:d32c:1bf0
dhcp6_ia_na1_ia_addr1_pltime=86400
dhcp6_ia_na1_ia_addr1_vltime=86400
dhcp6_ia_pd1_iaid=00000000
dhcp6_ia_pd1_t1=43200
dhcp6_ia_pd1_t2=69120
dhcp6_ia_pd1_prefix1_pltime=86400
dhcp6_ia_pd1_prefix1_vltime=86400
dhcp6_ia_pd1_prefix1_length=60
dhcp6_ia_pd1_prefix1=2601:283:4e00:fdd0::
timestamp: Aug 25 06:39:01

Note in my case I only care about DHCPv6 and DHCP, so not adding timestamp info to link-level messages or router advertisements is fine. For DHCPv6 and DHCP, I would like timestamp information not just for RENEWals but also BOUND, REBIND, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions