Skip to content

Commit

Permalink
dhcpd: fix lease time format
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Feb 17, 2021
1 parent e32c18f commit 3744338
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/dhcpd/dhcpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (

const (
defaultDiscoverTime = time.Second * 3
leaseExpireStatic = 1
// TODO(e.burkov): Get rid of this useless stuff.
leaseExpireStatic = 1
)

var webHandlersRegistered = false
Expand All @@ -37,12 +38,19 @@ type Lease struct {

// MarshalJSON implements the json.Marshaler interface for *Lease.
func (l *Lease) MarshalJSON() ([]byte, error) {
var expiryStr string
if expiry := l.Expiry; expiry.Unix() != leaseExpireStatic {
expiryStr = expiry.Format(time.RFC3339)
}

type lease Lease
return json.Marshal(&struct {
HWAddr string `json:"mac"`
Expiry string `json:"expires,omitempty"`
*lease
}{
HWAddr: l.HWAddr.String(),
Expiry: expiryStr,
lease: (*lease)(l),
})
}
Expand Down Expand Up @@ -251,11 +259,9 @@ const (
// Leases returns the list of current DHCP leases (thread-safe)
func (s *Server) Leases(flags int) []Lease {
result := s.srv4.GetLeases(flags)

v6leases := s.srv6.GetLeases(flags)
result = append(result, v6leases...)

return result
return append(result, v6leases...)
}

// FindMACbyIP - find a MAC address by IP address in the currently active DHCP leases
Expand Down

0 comments on commit 3744338

Please sign in to comment.