mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-05-08 16:50:12 +03:00
Pull request 1817: AG-20352-imp-leases-db
Merge in DNS/adguard-home from AG-20352-imp-leases-db to master Squashed commit of the following: commit 2235fb4671bb3f80c933847362cd35b5704dd18d Merge: 0c4d76d4f76a74b271
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Apr 18 15:09:34 2023 +0300 Merge branch 'master' into AG-20352-imp-leases-db commit 0c4d76d4f6222ae06c568864d366df866dc55a54 Merge: e586b82c74afd39b22
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Apr 18 11:07:27 2023 +0300 Merge branch 'master' into AG-20352-imp-leases-db commit e586b82c700c4d432e34f36400519eb08b2653ad Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Apr 18 11:06:40 2023 +0300 dhcpd: imp docs commit 411d4e6f6e36051bf6a66c709380ed268c161c41 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Apr 17 16:56:56 2023 +0300 dhcpd: imp code commit e457dc2c385ab62b36df7f96c949e6b90ed2034a Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Apr 17 14:29:29 2023 +0300 all: imp code more commit c2df20d0125d368d0155af0808af979921763e1f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Apr 14 15:07:53 2023 +0300 all: imp code commit a4e9ffb9ae769c828c22d62ddf231f7bcfea14db Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Apr 12 19:19:35 2023 +0300 dhcpd: fix test more commit 138d89414f1a89558b23962acb7174dce28346d9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Apr 12 18:08:29 2023 +0300 dhcpd: fix test commit e07e7a23e7c913951c8ecb38c12a3345ebe473be Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Apr 12 17:22:27 2023 +0300 all: upd chlog commit 1b6a76e79cf4beed9ca980766ce97930b375bfde Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Apr 12 13:24:11 2023 +0300 all: migrate leases db
This commit is contained in:
parent
76a74b271b
commit
a91a257b15
16 changed files with 283 additions and 199 deletions
internal/dhcpd
|
@ -66,8 +66,7 @@ func (s *v6Server) ResetLeases(leases []*Lease) (err error) {
|
|||
s.leases = nil
|
||||
for _, l := range leases {
|
||||
ip := net.IP(l.IP.AsSlice())
|
||||
if l.Expiry.Unix() != leaseExpireStatic &&
|
||||
!ip6InRange(s.conf.ipStart, ip) {
|
||||
if !l.IsStatic && !ip6InRange(s.conf.ipStart, ip) {
|
||||
|
||||
log.Debug("dhcpv6: skipping a lease with IP %v: not within current IP range", l.IP)
|
||||
|
||||
|
@ -89,7 +88,7 @@ func (s *v6Server) GetLeases(flags GetLeasesFlags) (leases []*Lease) {
|
|||
leases = []*Lease{}
|
||||
s.leasesLock.Lock()
|
||||
for _, l := range s.leases {
|
||||
if l.Expiry.Unix() == leaseExpireStatic {
|
||||
if l.IsStatic {
|
||||
if (flags & LeasesStatic) != 0 {
|
||||
leases = append(leases, l.Clone())
|
||||
}
|
||||
|
@ -150,7 +149,7 @@ func (s *v6Server) rmDynamicLease(lease *Lease) (err error) {
|
|||
l := s.leases[i]
|
||||
|
||||
if bytes.Equal(l.HWAddr, lease.HWAddr) {
|
||||
if l.Expiry.Unix() == leaseExpireStatic {
|
||||
if l.IsStatic {
|
||||
return fmt.Errorf("static lease already exists")
|
||||
}
|
||||
|
||||
|
@ -163,7 +162,7 @@ func (s *v6Server) rmDynamicLease(lease *Lease) (err error) {
|
|||
}
|
||||
|
||||
if l.IP == lease.IP {
|
||||
if l.Expiry.Unix() == leaseExpireStatic {
|
||||
if l.IsStatic {
|
||||
return fmt.Errorf("static lease already exists")
|
||||
}
|
||||
|
||||
|
@ -187,7 +186,7 @@ func (s *v6Server) AddStaticLease(l *Lease) (err error) {
|
|||
return fmt.Errorf("validating lease: %w", err)
|
||||
}
|
||||
|
||||
l.Expiry = time.Unix(leaseExpireStatic, 0)
|
||||
l.IsStatic = true
|
||||
|
||||
s.leasesLock.Lock()
|
||||
err = s.rmDynamicLease(l)
|
||||
|
@ -274,8 +273,7 @@ func (s *v6Server) findLease(mac net.HardwareAddr) *Lease {
|
|||
func (s *v6Server) findExpiredLease() int {
|
||||
now := time.Now().Unix()
|
||||
for i, lease := range s.leases {
|
||||
if lease.Expiry.Unix() != leaseExpireStatic &&
|
||||
lease.Expiry.Unix() <= now {
|
||||
if !lease.IsStatic && lease.Expiry.Unix() <= now {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
@ -421,7 +419,7 @@ func (s *v6Server) commitLease(msg *dhcpv6.Message, lease *Lease) time.Duration
|
|||
dhcpv6.MessageTypeRenew,
|
||||
dhcpv6.MessageTypeRebind:
|
||||
|
||||
if lease.Expiry.Unix() != leaseExpireStatic {
|
||||
if !lease.IsStatic {
|
||||
s.commitDynamicLease(lease)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue