"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "internal/dhcpd/dhcpd.go" between
AdGuardHome-0.105.1.tar.gz and AdGuardHome-0.105.2.tar.gz

About: AdGuard Home is a network-wide ads & trackers blocking DNS server. It operates as a DNS server that re-routes tracking domains to a "black hole," thus preventing your devices from connecting to those servers.

dhcpd.go  (AdGuardHome-0.105.1):dhcpd.go  (AdGuardHome-0.105.2)
skipping to change at line 22 skipping to change at line 22
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/AdguardTeam/AdGuardHome/internal/util" "github.com/AdguardTeam/AdGuardHome/internal/util"
"github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/log"
) )
const ( const (
defaultDiscoverTime = time.Second * 3 defaultDiscoverTime = time.Second * 3
leaseExpireStatic = 1 // 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
) )
var webHandlersRegistered = false var webHandlersRegistered = false
// Lease contains the necessary information about a DHCP lease // Lease contains the necessary information about a DHCP lease
type Lease struct { type Lease struct {
HWAddr net.HardwareAddr `json:"mac"` HWAddr net.HardwareAddr `json:"mac"`
IP net.IP `json:"ip"` IP net.IP `json:"ip"`
Hostname string `json:"hostname"` Hostname string `json:"hostname"`
// Lease expiration time // Lease expiration time
// 1: static lease // 1: static lease
Expiry time.Time `json:"expires"` Expiry time.Time `json:"expires"`
} }
// MarshalJSON implements the json.Marshaler interface for *Lease. // MarshalJSON implements the json.Marshaler interface for *Lease.
func (l *Lease) MarshalJSON() ([]byte, error) { 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 type lease Lease
return json.Marshal(&struct { return json.Marshal(&struct {
HWAddr string `json:"mac"` HWAddr string `json:"mac"`
Expiry string `json:"expires,omitempty"`
*lease *lease
}{ }{
HWAddr: l.HWAddr.String(), HWAddr: l.HWAddr.String(),
Expiry: expiryStr,
lease: (*lease)(l), lease: (*lease)(l),
}) })
} }
// UnmarshalJSON implements the json.Unmarshaler interface for *Lease. // UnmarshalJSON implements the json.Unmarshaler interface for *Lease.
func (l *Lease) UnmarshalJSON(data []byte) (err error) { func (l *Lease) UnmarshalJSON(data []byte) (err error) {
type lease Lease type lease Lease
aux := struct { aux := struct {
HWAddr string `json:"mac"` HWAddr string `json:"mac"`
*lease *lease
skipping to change at line 251 skipping to change at line 268
s.srv6.Stop() s.srv6.Stop()
} }
// flags for Leases() function // flags for Leases() function
const ( const (
LeasesDynamic = 1 LeasesDynamic = 1
LeasesStatic = 2 LeasesStatic = 2
LeasesAll = LeasesDynamic | LeasesStatic LeasesAll = LeasesDynamic | LeasesStatic
) )
// Leases returns the list of current DHCP leases (thread-safe) // Leases returns the list of active IPv4 and IPv6 DHCP leases. It's safe for
func (s *Server) Leases(flags int) []Lease { // concurrent use.
result := s.srv4.GetLeases(flags) func (s *Server) Leases(flags int) (leases []Lease) {
return append(s.srv4.GetLeases(flags), s.srv6.GetLeases(flags)...)
v6leases := s.srv6.GetLeases(flags)
result = append(result, v6leases...)
return result
} }
// FindMACbyIP - find a MAC address by IP address in the currently active DHCP l eases // FindMACbyIP - find a MAC address by IP address in the currently active DHCP l eases
func (s *Server) FindMACbyIP(ip net.IP) net.HardwareAddr { func (s *Server) FindMACbyIP(ip net.IP) net.HardwareAddr {
if ip.To4() != nil { if ip.To4() != nil {
return s.srv4.FindMACbyIP(ip) return s.srv4.FindMACbyIP(ip)
} }
return s.srv6.FindMACbyIP(ip) return s.srv6.FindMACbyIP(ip)
} }
skipping to change at line 296 skipping to change at line 309
} }
var val []byte var val []byte
switch t { switch t {
case "hex": case "hex":
val, err = hex.DecodeString(sval) val, err = hex.DecodeString(sval)
if err != nil { if err != nil {
return 0, nil return 0, nil
} }
case "ip": case "ip":
ip := net.ParseIP(sval) ip := net.ParseIP(sval)
if ip == nil { if ip == nil {
return 0, nil return 0, nil
} }
val = ip
// Most DHCP options require IPv4, so do not put the 16-byte
// version if we can. Otherwise, the clients will receive weird
// data that looks like four IPv4 addresses.
//
// See https://github.com/AdguardTeam/AdGuardHome/issues/2688.
if ip4 := ip.To4(); ip4 != nil {
val = ip4
} else {
val = ip
}
default: default:
return 0, nil return 0, nil
} }
return uint8(code), val return uint8(code), val
} }
 End of changes. 8 change blocks. 
11 lines changed or deleted 32 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)