Pull request: 2692 time format
Merge in DNS/adguard-home from 2692-time-format to master
Closes #2692.
Squashed commit of the following:
commit a77e3ffc1e2ca7ad1eb4b56641eee787595268e9
Merge: 5262c0b9 1122e71c
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Thu Feb 18 13:58:29 2021 +0300
Merge branch 'master' into 2692-time-format
commit 5262c0b95979a6c7a01bdd56e9476c4cdf217119
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Thu Feb 18 13:50:38 2021 +0300
dhcpd: imp docs
commit 3744338d51dd003a0052672ceffa260c70f5738d
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Wed Feb 17 21:10:37 2021 +0300
dhcpd: fix lease time format
This commit is contained in:
parent
1122e71cf3
commit
a0abad6644
|
@ -19,11 +19,13 @@ and this project adheres to
|
|||
|
||||
### Fixed
|
||||
|
||||
- DHCP lease's `expired` field incorrect time format ([#2692]).
|
||||
- Incomplete DNS upstreams validation ([#2674]).
|
||||
- Wrong parsing of DHCP options of the `ip` type ([#2688]).
|
||||
|
||||
[#2674]: https://github.com/AdguardTeam/AdGuardHome/issues/2674
|
||||
[#2688]: https://github.com/AdguardTeam/AdGuardHome/issues/2688
|
||||
[#2692]: https://github.com/AdguardTeam/AdGuardHome/issues/2692
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,11 @@ import (
|
|||
|
||||
const (
|
||||
defaultDiscoverTime = time.Second * 3
|
||||
// leaseExpireStatic is used to define the Expiry field for static
|
||||
// leases.
|
||||
//
|
||||
// TODO(e.burkov): Remove it when static leases determining mechanism
|
||||
// will be improved.
|
||||
leaseExpireStatic = 1
|
||||
)
|
||||
|
||||
|
@ -37,12 +42,24 @@ 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 {
|
||||
// The front-end is waiting for RFC 3999 format of the time
|
||||
// value. It also shouldn't got an Expiry field for static
|
||||
// leases.
|
||||
//
|
||||
// See https://github.com/AdguardTeam/AdGuardHome/issues/2692.
|
||||
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),
|
||||
})
|
||||
}
|
||||
|
@ -248,14 +265,10 @@ const (
|
|||
LeasesAll = LeasesDynamic | LeasesStatic
|
||||
)
|
||||
|
||||
// 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
|
||||
// Leases returns the list of active IPv4 and IPv6 DHCP leases. It's safe for
|
||||
// concurrent use.
|
||||
func (s *Server) Leases(flags int) (leases []Lease) {
|
||||
return append(s.srv4.GetLeases(flags), s.srv6.GetLeases(flags)...)
|
||||
}
|
||||
|
||||
// FindMACbyIP - find a MAC address by IP address in the currently active DHCP leases
|
||||
|
|
Loading…
Reference in New Issue