From 86d79ae232f033312a251c84ce232a8b24e7ee76 Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Sat, 29 Dec 2018 16:44:07 +0300 Subject: [PATCH] dhcpd -- Remember hostname, for UI. --- dhcpd/dhcpd.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dhcpd/dhcpd.go b/dhcpd/dhcpd.go index 74f6c2fb..1503749d 100644 --- a/dhcpd/dhcpd.go +++ b/dhcpd/dhcpd.go @@ -14,9 +14,10 @@ const defaultDiscoverTime = time.Second * 3 // field ordering is important -- yaml fields will mirror ordering from here type Lease struct { - HWAddr net.HardwareAddr `json:"mac" yaml:"hwaddr"` - IP net.IP `json:"ip"` - Expiry time.Time `json:"expires"` + HWAddr net.HardwareAddr `json:"mac" yaml:"hwaddr"` + IP net.IP `json:"ip"` + Hostname string `json:"hostname"` + Expiry time.Time `json:"expires"` } // field ordering is important -- yaml fields will mirror ordering from here @@ -176,7 +177,8 @@ func (s *Server) reserveLease(p dhcp4.Packet) (*Lease, error) { return nil, wrapErrPrint(err, "Couldn't find free IP for the lease %s", hwaddr.String()) } trace("Assigning to %s IP address %s", hwaddr, ip.String()) - lease := &Lease{HWAddr: hwaddr, IP: ip} + hostname := p.ParseOptions()[dhcp4.OptionHostName] + lease := &Lease{HWAddr: hwaddr, IP: ip, Hostname: string(hostname)} s.leases = append(s.leases, lease) return lease, nil }