AdGuardHome/internal/dhcpd/v4_unix_test.go

1019 lines
25 KiB
Go
Raw Normal View History

Pull request: 4722 dhcp http panic Merge in DNS/adguard-home from 4722-dhcp-http-panic to master Updates #4722. Squashed commit of the following: commit 8a8db48c3bd4f6bb7fabe65b5b7b162f0986fc76 Merge: 39b344f9 b74b92fc Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 20:11:23 2022 +0300 Merge branch 'master' into 4722-dhcp-http-panic commit 39b344f97180af17ab22041e5655a27bcc99c29e Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 18:33:56 2022 +0300 dhcpd: imp code, fmt commit a36d70d2c25791b2e657e21d6f4681b33497f0cd Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 17:38:17 2022 +0300 dhcpd: imp names, docs commit 600d63da7af62de5cb52fc7670ef28c9f4fe95a7 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 17:36:17 2022 +0300 dhcpd: rename files, imp tags commit 44f5507649db8536a07c4c21c8ad6e4a60ba3f43 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 16:40:26 2022 +0300 dhcpd: add mock commit cfc3cfb714705067d3aa71a7cb5df4245e091cfd Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 16:15:27 2022 +0300 all: use ptr instead of value commit ec526c2cf22df3470641296cfc402113c23c3f9b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:57:10 2022 +0300 all: log changes commit 0eca09f4c72bbdc73a2334c839d7781847ba3962 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:50:32 2022 +0300 dhcpd: let v4 be unconfigured commit 59636e9ff48aea989d7bdfd216b37899b57137d2 Merge: 9238ca0a bc1503af Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:50:17 2022 +0300 Merge branch 'master' into 4722-dhcp-http-panic commit 9238ca0a1e190ddc344f01959f474932809f086a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Sep 7 18:28:56 2022 +0300 dhcpd: imp conf commit 5f801c9be96c2fa735a50373495d8c6ca2914f32 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 6 16:31:13 2022 +0300 dhcpd: hide behind iface commit a95c2741a7e3e5bfe8775bf937a3709217b76da0 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 31 16:24:02 2022 +0300 dhcpd: separate os files
2022-09-13 23:45:35 +03:00
//go:build darwin || freebsd || linux || openbsd
package dhcpd
import (
"fmt"
"net"
"net/netip"
"strings"
"testing"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/golibs/netutil"
"github.com/AdguardTeam/golibs/stringutil"
"github.com/AdguardTeam/golibs/testutil"
"github.com/insomniacslk/dhcp/dhcpv4"
"github.com/mdlayher/packet"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var (
DefaultRangeStart = netip.MustParseAddr("192.168.10.100")
DefaultRangeEnd = netip.MustParseAddr("192.168.10.200")
DefaultGatewayIP = netip.MustParseAddr("192.168.10.1")
DefaultSelfIP = netip.MustParseAddr("192.168.10.2")
DefaultSubnetMask = netip.MustParseAddr("255.255.255.0")
)
// defaultV4ServerConf returns the default configuration for *v4Server to use in
// tests.
Pull request: 4722 dhcp http panic Merge in DNS/adguard-home from 4722-dhcp-http-panic to master Updates #4722. Squashed commit of the following: commit 8a8db48c3bd4f6bb7fabe65b5b7b162f0986fc76 Merge: 39b344f9 b74b92fc Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 20:11:23 2022 +0300 Merge branch 'master' into 4722-dhcp-http-panic commit 39b344f97180af17ab22041e5655a27bcc99c29e Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 18:33:56 2022 +0300 dhcpd: imp code, fmt commit a36d70d2c25791b2e657e21d6f4681b33497f0cd Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 17:38:17 2022 +0300 dhcpd: imp names, docs commit 600d63da7af62de5cb52fc7670ef28c9f4fe95a7 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 17:36:17 2022 +0300 dhcpd: rename files, imp tags commit 44f5507649db8536a07c4c21c8ad6e4a60ba3f43 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 16:40:26 2022 +0300 dhcpd: add mock commit cfc3cfb714705067d3aa71a7cb5df4245e091cfd Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 16:15:27 2022 +0300 all: use ptr instead of value commit ec526c2cf22df3470641296cfc402113c23c3f9b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:57:10 2022 +0300 all: log changes commit 0eca09f4c72bbdc73a2334c839d7781847ba3962 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:50:32 2022 +0300 dhcpd: let v4 be unconfigured commit 59636e9ff48aea989d7bdfd216b37899b57137d2 Merge: 9238ca0a bc1503af Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:50:17 2022 +0300 Merge branch 'master' into 4722-dhcp-http-panic commit 9238ca0a1e190ddc344f01959f474932809f086a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Sep 7 18:28:56 2022 +0300 dhcpd: imp conf commit 5f801c9be96c2fa735a50373495d8c6ca2914f32 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 6 16:31:13 2022 +0300 dhcpd: hide behind iface commit a95c2741a7e3e5bfe8775bf937a3709217b76da0 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 31 16:24:02 2022 +0300 dhcpd: separate os files
2022-09-13 23:45:35 +03:00
func defaultV4ServerConf() (conf *V4ServerConf) {
return &V4ServerConf{
Enabled: true,
RangeStart: DefaultRangeStart,
RangeEnd: DefaultRangeEnd,
GatewayIP: DefaultGatewayIP,
SubnetMask: DefaultSubnetMask,
Pull request: 4722 dhcp http panic Merge in DNS/adguard-home from 4722-dhcp-http-panic to master Updates #4722. Squashed commit of the following: commit 8a8db48c3bd4f6bb7fabe65b5b7b162f0986fc76 Merge: 39b344f9 b74b92fc Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 20:11:23 2022 +0300 Merge branch 'master' into 4722-dhcp-http-panic commit 39b344f97180af17ab22041e5655a27bcc99c29e Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 18:33:56 2022 +0300 dhcpd: imp code, fmt commit a36d70d2c25791b2e657e21d6f4681b33497f0cd Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 17:38:17 2022 +0300 dhcpd: imp names, docs commit 600d63da7af62de5cb52fc7670ef28c9f4fe95a7 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 17:36:17 2022 +0300 dhcpd: rename files, imp tags commit 44f5507649db8536a07c4c21c8ad6e4a60ba3f43 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 16:40:26 2022 +0300 dhcpd: add mock commit cfc3cfb714705067d3aa71a7cb5df4245e091cfd Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 16:15:27 2022 +0300 all: use ptr instead of value commit ec526c2cf22df3470641296cfc402113c23c3f9b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:57:10 2022 +0300 all: log changes commit 0eca09f4c72bbdc73a2334c839d7781847ba3962 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:50:32 2022 +0300 dhcpd: let v4 be unconfigured commit 59636e9ff48aea989d7bdfd216b37899b57137d2 Merge: 9238ca0a bc1503af Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:50:17 2022 +0300 Merge branch 'master' into 4722-dhcp-http-panic commit 9238ca0a1e190ddc344f01959f474932809f086a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Sep 7 18:28:56 2022 +0300 dhcpd: imp conf commit 5f801c9be96c2fa735a50373495d8c6ca2914f32 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 6 16:31:13 2022 +0300 dhcpd: hide behind iface commit a95c2741a7e3e5bfe8775bf937a3709217b76da0 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 31 16:24:02 2022 +0300 dhcpd: separate os files
2022-09-13 23:45:35 +03:00
notify: testNotify,
dnsIPAddrs: []netip.Addr{DefaultSelfIP},
}
}
// defaultSrv prepares the default DHCPServer to use in tests. The underlying
// type of s is *v4Server.
func defaultSrv(t *testing.T) (s DHCPServer) {
t.Helper()
var err error
s, err = v4Create(defaultV4ServerConf())
require.NoError(t, err)
return s
}
func TestV4Server_leasing(t *testing.T) {
const (
staticName = "static-client"
anotherName = "another-client"
)
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
staticIP := netip.MustParseAddr("192.168.10.10")
anotherIP := DefaultRangeStart
staticMAC := net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}
anotherMAC := net.HardwareAddr{0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB}
s := defaultSrv(t)
t.Run("add_static", func(t *testing.T) {
err := s.AddStaticLease(&Lease{
Expiry: time.Unix(leaseExpireStatic, 0),
Hostname: staticName,
HWAddr: staticMAC,
IP: staticIP,
IsStatic: true,
})
require.NoError(t, err)
t.Run("same_name", func(t *testing.T) {
err = s.AddStaticLease(&Lease{
Expiry: time.Unix(leaseExpireStatic, 0),
Hostname: staticName,
HWAddr: anotherMAC,
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
IP: anotherIP,
IsStatic: true,
})
assert.ErrorIs(t, err, ErrDupHostname)
})
t.Run("same_mac", func(t *testing.T) {
wantErrMsg := "dhcpv4: adding static lease: removing " +
"dynamic leases for " + anotherIP.String() +
" (" + staticMAC.String() + "): static lease already exists"
err = s.AddStaticLease(&Lease{
Expiry: time.Unix(leaseExpireStatic, 0),
Hostname: anotherName,
HWAddr: staticMAC,
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
IP: anotherIP,
IsStatic: true,
})
testutil.AssertErrorMsg(t, wantErrMsg, err)
})
t.Run("same_ip", func(t *testing.T) {
wantErrMsg := "dhcpv4: adding static lease: removing " +
"dynamic leases for " + staticIP.String() +
" (" + anotherMAC.String() + "): static lease already exists"
err = s.AddStaticLease(&Lease{
Expiry: time.Unix(leaseExpireStatic, 0),
Hostname: anotherName,
HWAddr: anotherMAC,
IP: staticIP,
IsStatic: true,
})
testutil.AssertErrorMsg(t, wantErrMsg, err)
})
})
t.Run("add_dynamic", func(t *testing.T) {
s4, ok := s.(*v4Server)
require.True(t, ok)
discoverAnOffer := func(
t *testing.T,
name string,
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
netIP netip.Addr,
mac net.HardwareAddr,
) (resp *dhcpv4.DHCPv4) {
testutil.CleanupAndRequireSuccess(t, func() (err error) {
return s.ResetLeases(s.GetLeases(LeasesStatic))
})
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
ip := net.IP(netIP.AsSlice())
req, err := dhcpv4.NewDiscovery(
mac,
dhcpv4.WithOption(dhcpv4.OptHostName(name)),
dhcpv4.WithOption(dhcpv4.OptRequestedIPAddress(ip)),
dhcpv4.WithOption(dhcpv4.OptClientIdentifier([]byte{1, 2, 3, 4, 5, 6, 8})),
dhcpv4.WithGatewayIP(DefaultGatewayIP.AsSlice()),
)
require.NoError(t, err)
resp = &dhcpv4.DHCPv4{}
Pull request: 4863 fix dhcp request Merge in DNS/adguard-home from 4863-fix-dhcp-request to master Closes #4863. Squashed commit of the following: commit f8872015e315eab3b2ce0249e552d12cbcf72f63 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:34:35 2022 +0300 dhcpd: imp code commit b63c5d98c2055c3a3b76ff47737551840409f324 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:19:22 2022 +0300 dhcpd: fix deadlock commit 5c03b54a86ab05efde9716faef60b84ecab01d19 Merge: f076cf8f 8733f55c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:12:27 2022 +0300 Merge branch 'master' into 4863-fix-dhcp-request commit f076cf8fc13944613b7127aac86ca78f68009f93 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:08:04 2022 +0300 dhcpd: imp code, names commit a09540b6db6b86b80b8eb84c08187bfd9f960190 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 17:28:39 2022 +0300 dhcpd: imp code, docs commit 38b12235509aaf55fa130f820213410b6b3022bb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:42:32 2022 +0300 dhcpd: imp docs more commit ff07c2f90f097754beb736fd5bd5cafc337ac65c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:41:42 2022 +0300 dhcpd: fix docs commit fafbc2ec2317f2320d8e1db167a1ae6c1c7c3790 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:35:42 2022 +0300 dhcpd: imp code commit 9fe30190a7f125fd640b58e17661a4c33c078eba Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 15:00:56 2022 +0300 all: imp chlog commit 1067fe95df5cb2252d1b9b70d2f3f8463997aea1 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:54:03 2022 +0300 dhcpd: log changes commit 20de395c2bdcfb8e0554bb1c45385c15d617be65 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:49:58 2022 +0300 dhcpd: impl rfc 2131 for req
2022-08-30 20:39:34 +03:00
res := s4.handle(req, resp)
require.Positive(t, res)
require.Equal(t, dhcpv4.MessageTypeOffer, resp.MessageType())
resp.ClientHWAddr = mac
return resp
}
t.Run("same_name", func(t *testing.T) {
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
resp := discoverAnOffer(t, staticName, anotherIP, anotherMAC)
req, err := dhcpv4.NewRequestFromOffer(resp, dhcpv4.WithOption(
dhcpv4.OptHostName(staticName),
))
require.NoError(t, err)
Pull request: 4863 fix dhcp request Merge in DNS/adguard-home from 4863-fix-dhcp-request to master Closes #4863. Squashed commit of the following: commit f8872015e315eab3b2ce0249e552d12cbcf72f63 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:34:35 2022 +0300 dhcpd: imp code commit b63c5d98c2055c3a3b76ff47737551840409f324 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:19:22 2022 +0300 dhcpd: fix deadlock commit 5c03b54a86ab05efde9716faef60b84ecab01d19 Merge: f076cf8f 8733f55c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:12:27 2022 +0300 Merge branch 'master' into 4863-fix-dhcp-request commit f076cf8fc13944613b7127aac86ca78f68009f93 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:08:04 2022 +0300 dhcpd: imp code, names commit a09540b6db6b86b80b8eb84c08187bfd9f960190 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 17:28:39 2022 +0300 dhcpd: imp code, docs commit 38b12235509aaf55fa130f820213410b6b3022bb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:42:32 2022 +0300 dhcpd: imp docs more commit ff07c2f90f097754beb736fd5bd5cafc337ac65c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:41:42 2022 +0300 dhcpd: fix docs commit fafbc2ec2317f2320d8e1db167a1ae6c1c7c3790 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:35:42 2022 +0300 dhcpd: imp code commit 9fe30190a7f125fd640b58e17661a4c33c078eba Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 15:00:56 2022 +0300 all: imp chlog commit 1067fe95df5cb2252d1b9b70d2f3f8463997aea1 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:54:03 2022 +0300 dhcpd: log changes commit 20de395c2bdcfb8e0554bb1c45385c15d617be65 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:49:58 2022 +0300 dhcpd: impl rfc 2131 for req
2022-08-30 20:39:34 +03:00
res := s4.handle(req, resp)
require.Positive(t, res)
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
var netIP netip.Addr
netIP, ok = netip.AddrFromSlice(resp.YourIPAddr)
require.True(t, ok)
assert.Equal(t, aghnet.GenerateHostname(netIP), resp.HostName())
})
t.Run("same_mac", func(t *testing.T) {
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
resp := discoverAnOffer(t, anotherName, anotherIP, staticMAC)
req, err := dhcpv4.NewRequestFromOffer(resp, dhcpv4.WithOption(
dhcpv4.OptHostName(anotherName),
))
require.NoError(t, err)
Pull request: 4863 fix dhcp request Merge in DNS/adguard-home from 4863-fix-dhcp-request to master Closes #4863. Squashed commit of the following: commit f8872015e315eab3b2ce0249e552d12cbcf72f63 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:34:35 2022 +0300 dhcpd: imp code commit b63c5d98c2055c3a3b76ff47737551840409f324 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:19:22 2022 +0300 dhcpd: fix deadlock commit 5c03b54a86ab05efde9716faef60b84ecab01d19 Merge: f076cf8f 8733f55c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:12:27 2022 +0300 Merge branch 'master' into 4863-fix-dhcp-request commit f076cf8fc13944613b7127aac86ca78f68009f93 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:08:04 2022 +0300 dhcpd: imp code, names commit a09540b6db6b86b80b8eb84c08187bfd9f960190 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 17:28:39 2022 +0300 dhcpd: imp code, docs commit 38b12235509aaf55fa130f820213410b6b3022bb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:42:32 2022 +0300 dhcpd: imp docs more commit ff07c2f90f097754beb736fd5bd5cafc337ac65c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:41:42 2022 +0300 dhcpd: fix docs commit fafbc2ec2317f2320d8e1db167a1ae6c1c7c3790 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:35:42 2022 +0300 dhcpd: imp code commit 9fe30190a7f125fd640b58e17661a4c33c078eba Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 15:00:56 2022 +0300 all: imp chlog commit 1067fe95df5cb2252d1b9b70d2f3f8463997aea1 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:54:03 2022 +0300 dhcpd: log changes commit 20de395c2bdcfb8e0554bb1c45385c15d617be65 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:49:58 2022 +0300 dhcpd: impl rfc 2131 for req
2022-08-30 20:39:34 +03:00
res := s4.handle(req, resp)
require.Positive(t, res)
fqdnOptData := resp.Options.Get(dhcpv4.OptionFQDN)
require.Len(t, fqdnOptData, 3+len(staticName))
assert.Equal(t, []uint8(staticName), fqdnOptData[3:])
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
ip := net.IP(staticIP.AsSlice())
assert.Equal(t, ip, resp.YourIPAddr)
})
t.Run("same_ip", func(t *testing.T) {
resp := discoverAnOffer(t, anotherName, staticIP, anotherMAC)
req, err := dhcpv4.NewRequestFromOffer(resp, dhcpv4.WithOption(
dhcpv4.OptHostName(anotherName),
))
require.NoError(t, err)
Pull request: 4863 fix dhcp request Merge in DNS/adguard-home from 4863-fix-dhcp-request to master Closes #4863. Squashed commit of the following: commit f8872015e315eab3b2ce0249e552d12cbcf72f63 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:34:35 2022 +0300 dhcpd: imp code commit b63c5d98c2055c3a3b76ff47737551840409f324 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:19:22 2022 +0300 dhcpd: fix deadlock commit 5c03b54a86ab05efde9716faef60b84ecab01d19 Merge: f076cf8f 8733f55c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:12:27 2022 +0300 Merge branch 'master' into 4863-fix-dhcp-request commit f076cf8fc13944613b7127aac86ca78f68009f93 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:08:04 2022 +0300 dhcpd: imp code, names commit a09540b6db6b86b80b8eb84c08187bfd9f960190 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 17:28:39 2022 +0300 dhcpd: imp code, docs commit 38b12235509aaf55fa130f820213410b6b3022bb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:42:32 2022 +0300 dhcpd: imp docs more commit ff07c2f90f097754beb736fd5bd5cafc337ac65c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:41:42 2022 +0300 dhcpd: fix docs commit fafbc2ec2317f2320d8e1db167a1ae6c1c7c3790 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:35:42 2022 +0300 dhcpd: imp code commit 9fe30190a7f125fd640b58e17661a4c33c078eba Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 15:00:56 2022 +0300 all: imp chlog commit 1067fe95df5cb2252d1b9b70d2f3f8463997aea1 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:54:03 2022 +0300 dhcpd: log changes commit 20de395c2bdcfb8e0554bb1c45385c15d617be65 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:49:58 2022 +0300 dhcpd: impl rfc 2131 for req
2022-08-30 20:39:34 +03:00
res := s4.handle(req, resp)
require.Positive(t, res)
assert.NotEqual(t, staticIP, resp.YourIPAddr)
})
})
}
func TestV4Server_AddRemove_static(t *testing.T) {
s := defaultSrv(t)
ls := s.GetLeases(LeasesStatic)
require.Empty(t, ls)
testCases := []struct {
lease *Lease
name string
wantErrMsg string
}{{
lease: &Lease{
Hostname: "success.local",
HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
IP: netip.MustParseAddr("192.168.10.150"),
},
name: "success",
wantErrMsg: "",
}, {
lease: &Lease{
Hostname: "probably-router.local",
HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
IP: DefaultGatewayIP,
},
name: "with_gateway_ip",
wantErrMsg: "dhcpv4: adding static lease: " +
"can't assign the gateway IP 192.168.10.1 to the lease",
}, {
lease: &Lease{
Hostname: "ip6.local",
HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
IP: netip.MustParseAddr("ffff::1"),
},
name: "ipv6",
wantErrMsg: `dhcpv4: adding static lease: ` +
`invalid ip "ffff::1", only ipv4 is supported`,
}, {
lease: &Lease{
Hostname: "bad-mac.local",
HWAddr: net.HardwareAddr{0xAA, 0xAA},
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
IP: netip.MustParseAddr("192.168.10.150"),
},
name: "bad_mac",
wantErrMsg: `dhcpv4: adding static lease: bad mac address "aa:aa": ` +
`bad mac address length 2, allowed: [6 8 20]`,
}, {
lease: &Lease{
Hostname: "bad-lbl-.local",
HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
IP: netip.MustParseAddr("192.168.10.150"),
},
name: "bad_hostname",
wantErrMsg: `dhcpv4: adding static lease: validating hostname: ` +
`bad hostname "bad-lbl-.local": ` +
`bad hostname label "bad-lbl-": bad hostname label rune '-'`,
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := s.AddStaticLease(tc.lease)
testutil.AssertErrorMsg(t, tc.wantErrMsg, err)
if tc.wantErrMsg != "" {
return
}
err = s.RemoveStaticLease(&Lease{
IP: tc.lease.IP,
HWAddr: tc.lease.HWAddr,
})
diffErrMsg := fmt.Sprintf("dhcpv4: lease for ip %s is different: %+v", tc.lease.IP, tc.lease)
testutil.AssertErrorMsg(t, diffErrMsg, err)
// Remove static lease.
err = s.RemoveStaticLease(tc.lease)
require.NoError(t, err)
})
ls = s.GetLeases(LeasesStatic)
require.Emptyf(t, ls, "after %s", tc.name)
}
}
func TestV4_AddReplace(t *testing.T) {
sIface := defaultSrv(t)
s, ok := sIface.(*v4Server)
require.True(t, ok)
dynLeases := []Lease{{
Hostname: "dynamic-1.local",
HWAddr: net.HardwareAddr{0x11, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
IP: netip.MustParseAddr("192.168.10.150"),
}, {
Hostname: "dynamic-2.local",
HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
IP: netip.MustParseAddr("192.168.10.151"),
}}
for i := range dynLeases {
err := s.addLease(&dynLeases[i])
require.NoError(t, err)
}
stLeases := []*Lease{{
Hostname: "static-1.local",
HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
IP: netip.MustParseAddr("192.168.10.150"),
}, {
Hostname: "static-2.local",
HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
IP: netip.MustParseAddr("192.168.10.152"),
}}
for _, l := range stLeases {
err := s.AddStaticLease(l)
require.NoError(t, err)
}
ls := s.GetLeases(LeasesStatic)
require.Len(t, ls, 2)
for i, l := range ls {
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
assert.Equal(t, stLeases[i].IP, l.IP)
assert.Equal(t, stLeases[i].HWAddr, l.HWAddr)
assert.True(t, l.IsStatic)
}
}
Pull request: 4863 fix dhcp request Merge in DNS/adguard-home from 4863-fix-dhcp-request to master Closes #4863. Squashed commit of the following: commit f8872015e315eab3b2ce0249e552d12cbcf72f63 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:34:35 2022 +0300 dhcpd: imp code commit b63c5d98c2055c3a3b76ff47737551840409f324 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:19:22 2022 +0300 dhcpd: fix deadlock commit 5c03b54a86ab05efde9716faef60b84ecab01d19 Merge: f076cf8f 8733f55c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:12:27 2022 +0300 Merge branch 'master' into 4863-fix-dhcp-request commit f076cf8fc13944613b7127aac86ca78f68009f93 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:08:04 2022 +0300 dhcpd: imp code, names commit a09540b6db6b86b80b8eb84c08187bfd9f960190 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 17:28:39 2022 +0300 dhcpd: imp code, docs commit 38b12235509aaf55fa130f820213410b6b3022bb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:42:32 2022 +0300 dhcpd: imp docs more commit ff07c2f90f097754beb736fd5bd5cafc337ac65c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:41:42 2022 +0300 dhcpd: fix docs commit fafbc2ec2317f2320d8e1db167a1ae6c1c7c3790 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:35:42 2022 +0300 dhcpd: imp code commit 9fe30190a7f125fd640b58e17661a4c33c078eba Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 15:00:56 2022 +0300 all: imp chlog commit 1067fe95df5cb2252d1b9b70d2f3f8463997aea1 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:54:03 2022 +0300 dhcpd: log changes commit 20de395c2bdcfb8e0554bb1c45385c15d617be65 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:49:58 2022 +0300 dhcpd: impl rfc 2131 for req
2022-08-30 20:39:34 +03:00
func TestV4Server_handle_optionsPriority(t *testing.T) {
defaultIP := netip.MustParseAddr("192.168.1.1")
knownIP := net.IP{1, 2, 3, 4}
// prepareSrv creates a *v4Server and sets the opt6IPs in the initial
// configuration of the server as the value for DHCP option 6.
prepareSrv := func(t *testing.T, opt6IPs []net.IP) (s *v4Server) {
t.Helper()
conf := defaultV4ServerConf()
if len(opt6IPs) > 0 {
b := &strings.Builder{}
stringutil.WriteToBuilder(b, "6 ips ", opt6IPs[0].String())
for _, ip := range opt6IPs[1:] {
stringutil.WriteToBuilder(b, ",", ip.String())
}
conf.Options = []string{b.String()}
} else {
defer func() { s.implicitOpts.Update(dhcpv4.OptDNS(defaultIP.AsSlice())) }()
}
Pull request: 4722 dhcp http panic Merge in DNS/adguard-home from 4722-dhcp-http-panic to master Updates #4722. Squashed commit of the following: commit 8a8db48c3bd4f6bb7fabe65b5b7b162f0986fc76 Merge: 39b344f9 b74b92fc Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 20:11:23 2022 +0300 Merge branch 'master' into 4722-dhcp-http-panic commit 39b344f97180af17ab22041e5655a27bcc99c29e Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 18:33:56 2022 +0300 dhcpd: imp code, fmt commit a36d70d2c25791b2e657e21d6f4681b33497f0cd Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 17:38:17 2022 +0300 dhcpd: imp names, docs commit 600d63da7af62de5cb52fc7670ef28c9f4fe95a7 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 17:36:17 2022 +0300 dhcpd: rename files, imp tags commit 44f5507649db8536a07c4c21c8ad6e4a60ba3f43 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 16:40:26 2022 +0300 dhcpd: add mock commit cfc3cfb714705067d3aa71a7cb5df4245e091cfd Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 16:15:27 2022 +0300 all: use ptr instead of value commit ec526c2cf22df3470641296cfc402113c23c3f9b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:57:10 2022 +0300 all: log changes commit 0eca09f4c72bbdc73a2334c839d7781847ba3962 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:50:32 2022 +0300 dhcpd: let v4 be unconfigured commit 59636e9ff48aea989d7bdfd216b37899b57137d2 Merge: 9238ca0a bc1503af Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:50:17 2022 +0300 Merge branch 'master' into 4722-dhcp-http-panic commit 9238ca0a1e190ddc344f01959f474932809f086a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Sep 7 18:28:56 2022 +0300 dhcpd: imp conf commit 5f801c9be96c2fa735a50373495d8c6ca2914f32 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 6 16:31:13 2022 +0300 dhcpd: hide behind iface commit a95c2741a7e3e5bfe8775bf937a3709217b76da0 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 31 16:24:02 2022 +0300 dhcpd: separate os files
2022-09-13 23:45:35 +03:00
var err error
s, err = v4Create(conf)
require.NoError(t, err)
s.conf.dnsIPAddrs = []netip.Addr{defaultIP}
return s
}
// checkResp creates a discovery message with DHCP option 6 requested amd
// asserts the response to contain wantIPs in this option.
checkResp := func(t *testing.T, s *v4Server, wantIPs []net.IP) {
t.Helper()
mac := net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}
req, err := dhcpv4.NewDiscovery(mac, dhcpv4.WithRequestedOptions(
dhcpv4.OptionDomainNameServer,
))
require.NoError(t, err)
var resp *dhcpv4.DHCPv4
resp, err = dhcpv4.NewReplyFromRequest(req)
require.NoError(t, err)
Pull request: 4863 fix dhcp request Merge in DNS/adguard-home from 4863-fix-dhcp-request to master Closes #4863. Squashed commit of the following: commit f8872015e315eab3b2ce0249e552d12cbcf72f63 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:34:35 2022 +0300 dhcpd: imp code commit b63c5d98c2055c3a3b76ff47737551840409f324 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:19:22 2022 +0300 dhcpd: fix deadlock commit 5c03b54a86ab05efde9716faef60b84ecab01d19 Merge: f076cf8f 8733f55c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:12:27 2022 +0300 Merge branch 'master' into 4863-fix-dhcp-request commit f076cf8fc13944613b7127aac86ca78f68009f93 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:08:04 2022 +0300 dhcpd: imp code, names commit a09540b6db6b86b80b8eb84c08187bfd9f960190 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 17:28:39 2022 +0300 dhcpd: imp code, docs commit 38b12235509aaf55fa130f820213410b6b3022bb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:42:32 2022 +0300 dhcpd: imp docs more commit ff07c2f90f097754beb736fd5bd5cafc337ac65c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:41:42 2022 +0300 dhcpd: fix docs commit fafbc2ec2317f2320d8e1db167a1ae6c1c7c3790 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:35:42 2022 +0300 dhcpd: imp code commit 9fe30190a7f125fd640b58e17661a4c33c078eba Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 15:00:56 2022 +0300 all: imp chlog commit 1067fe95df5cb2252d1b9b70d2f3f8463997aea1 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:54:03 2022 +0300 dhcpd: log changes commit 20de395c2bdcfb8e0554bb1c45385c15d617be65 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:49:58 2022 +0300 dhcpd: impl rfc 2131 for req
2022-08-30 20:39:34 +03:00
res := s.handle(req, resp)
require.Equal(t, 1, res)
o := resp.GetOneOption(dhcpv4.OptionDomainNameServer)
require.NotEmpty(t, o)
wantData := []byte{}
for _, ip := range wantIPs {
wantData = append(wantData, ip...)
}
assert.Equal(t, o, wantData)
}
t.Run("default", func(t *testing.T) {
s := prepareSrv(t, nil)
checkResp(t, s, []net.IP{defaultIP.AsSlice()})
})
t.Run("explicitly_configured", func(t *testing.T) {
s := prepareSrv(t, []net.IP{knownIP, knownIP})
checkResp(t, s, []net.IP{knownIP, knownIP})
})
}
func TestV4Server_updateOptions(t *testing.T) {
testIP := net.IP{1, 2, 3, 4}
dontWant := func(c dhcpv4.OptionCode) (opt dhcpv4.Option) {
return dhcpv4.OptGeneric(c, nil)
}
testCases := []struct {
name string
wantOpts dhcpv4.Options
reqMods []dhcpv4.Modifier
confOpts []string
}{{
name: "requested_default",
wantOpts: dhcpv4.OptionsFromList(
dhcpv4.OptBroadcastAddress(netutil.IPv4bcast()),
),
reqMods: []dhcpv4.Modifier{
dhcpv4.WithRequestedOptions(dhcpv4.OptionBroadcastAddress),
},
confOpts: nil,
}, {
name: "requested_non-default",
wantOpts: dhcpv4.OptionsFromList(
dhcpv4.OptBroadcastAddress(testIP),
),
reqMods: []dhcpv4.Modifier{
dhcpv4.WithRequestedOptions(dhcpv4.OptionBroadcastAddress),
},
confOpts: []string{
fmt.Sprintf("%d ip %s", dhcpv4.OptionBroadcastAddress, testIP),
},
}, {
name: "non-requested_default",
wantOpts: dhcpv4.OptionsFromList(
dontWant(dhcpv4.OptionBroadcastAddress),
),
reqMods: nil,
confOpts: nil,
}, {
name: "non-requested_non-default",
wantOpts: dhcpv4.OptionsFromList(
dhcpv4.OptBroadcastAddress(testIP),
),
reqMods: nil,
confOpts: []string{
fmt.Sprintf("%d ip %s", dhcpv4.OptionBroadcastAddress, testIP),
},
}, {
name: "requested_deleted",
wantOpts: dhcpv4.OptionsFromList(
dontWant(dhcpv4.OptionBroadcastAddress),
),
reqMods: []dhcpv4.Modifier{
dhcpv4.WithRequestedOptions(dhcpv4.OptionBroadcastAddress),
},
confOpts: []string{
fmt.Sprintf("%d del", dhcpv4.OptionBroadcastAddress),
},
}, {
name: "requested_non-default_deleted",
wantOpts: dhcpv4.OptionsFromList(
dontWant(dhcpv4.OptionBroadcastAddress),
),
reqMods: []dhcpv4.Modifier{
dhcpv4.WithRequestedOptions(dhcpv4.OptionBroadcastAddress),
},
confOpts: []string{
fmt.Sprintf("%d ip %s", dhcpv4.OptionBroadcastAddress, testIP),
fmt.Sprintf("%d del", dhcpv4.OptionBroadcastAddress),
},
}}
for _, tc := range testCases {
req, err := dhcpv4.New(tc.reqMods...)
require.NoError(t, err)
resp, err := dhcpv4.NewReplyFromRequest(req)
require.NoError(t, err)
conf := defaultV4ServerConf()
conf.Options = tc.confOpts
s, err := v4Create(conf)
require.NoError(t, err)
require.IsType(t, (*v4Server)(nil), s)
t.Run(tc.name, func(t *testing.T) {
Pull request: 4722 dhcp http panic Merge in DNS/adguard-home from 4722-dhcp-http-panic to master Updates #4722. Squashed commit of the following: commit 8a8db48c3bd4f6bb7fabe65b5b7b162f0986fc76 Merge: 39b344f9 b74b92fc Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 20:11:23 2022 +0300 Merge branch 'master' into 4722-dhcp-http-panic commit 39b344f97180af17ab22041e5655a27bcc99c29e Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 18:33:56 2022 +0300 dhcpd: imp code, fmt commit a36d70d2c25791b2e657e21d6f4681b33497f0cd Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 17:38:17 2022 +0300 dhcpd: imp names, docs commit 600d63da7af62de5cb52fc7670ef28c9f4fe95a7 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 17:36:17 2022 +0300 dhcpd: rename files, imp tags commit 44f5507649db8536a07c4c21c8ad6e4a60ba3f43 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 16:40:26 2022 +0300 dhcpd: add mock commit cfc3cfb714705067d3aa71a7cb5df4245e091cfd Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 16:15:27 2022 +0300 all: use ptr instead of value commit ec526c2cf22df3470641296cfc402113c23c3f9b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:57:10 2022 +0300 all: log changes commit 0eca09f4c72bbdc73a2334c839d7781847ba3962 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:50:32 2022 +0300 dhcpd: let v4 be unconfigured commit 59636e9ff48aea989d7bdfd216b37899b57137d2 Merge: 9238ca0a bc1503af Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:50:17 2022 +0300 Merge branch 'master' into 4722-dhcp-http-panic commit 9238ca0a1e190ddc344f01959f474932809f086a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Sep 7 18:28:56 2022 +0300 dhcpd: imp conf commit 5f801c9be96c2fa735a50373495d8c6ca2914f32 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 6 16:31:13 2022 +0300 dhcpd: hide behind iface commit a95c2741a7e3e5bfe8775bf937a3709217b76da0 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 31 16:24:02 2022 +0300 dhcpd: separate os files
2022-09-13 23:45:35 +03:00
s.updateOptions(req, resp)
for c, v := range tc.wantOpts {
if v == nil {
assert.NotContains(t, resp.Options, c)
continue
}
assert.Equal(t, v, resp.Options.Get(dhcpv4.GenericOptionCode(c)))
}
})
}
}
func TestV4StaticLease_Get(t *testing.T) {
sIface := defaultSrv(t)
s, ok := sIface.(*v4Server)
require.True(t, ok)
dnsAddr := netip.MustParseAddr("192.168.10.1")
s.conf.dnsIPAddrs = []netip.Addr{dnsAddr}
s.implicitOpts.Update(dhcpv4.OptDNS(dnsAddr.AsSlice()))
l := &Lease{
Hostname: "static-1.local",
HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
IP: netip.MustParseAddr("192.168.10.150"),
}
err := s.AddStaticLease(l)
require.NoError(t, err)
var req, resp *dhcpv4.DHCPv4
mac := net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}
t.Run("discover", func(t *testing.T) {
req, err = dhcpv4.NewDiscovery(mac, dhcpv4.WithRequestedOptions(
dhcpv4.OptionDomainNameServer,
))
require.NoError(t, err)
resp, err = dhcpv4.NewReplyFromRequest(req)
require.NoError(t, err)
Pull request: 4863 fix dhcp request Merge in DNS/adguard-home from 4863-fix-dhcp-request to master Closes #4863. Squashed commit of the following: commit f8872015e315eab3b2ce0249e552d12cbcf72f63 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:34:35 2022 +0300 dhcpd: imp code commit b63c5d98c2055c3a3b76ff47737551840409f324 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:19:22 2022 +0300 dhcpd: fix deadlock commit 5c03b54a86ab05efde9716faef60b84ecab01d19 Merge: f076cf8f 8733f55c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:12:27 2022 +0300 Merge branch 'master' into 4863-fix-dhcp-request commit f076cf8fc13944613b7127aac86ca78f68009f93 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:08:04 2022 +0300 dhcpd: imp code, names commit a09540b6db6b86b80b8eb84c08187bfd9f960190 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 17:28:39 2022 +0300 dhcpd: imp code, docs commit 38b12235509aaf55fa130f820213410b6b3022bb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:42:32 2022 +0300 dhcpd: imp docs more commit ff07c2f90f097754beb736fd5bd5cafc337ac65c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:41:42 2022 +0300 dhcpd: fix docs commit fafbc2ec2317f2320d8e1db167a1ae6c1c7c3790 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:35:42 2022 +0300 dhcpd: imp code commit 9fe30190a7f125fd640b58e17661a4c33c078eba Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 15:00:56 2022 +0300 all: imp chlog commit 1067fe95df5cb2252d1b9b70d2f3f8463997aea1 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:54:03 2022 +0300 dhcpd: log changes commit 20de395c2bdcfb8e0554bb1c45385c15d617be65 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:49:58 2022 +0300 dhcpd: impl rfc 2131 for req
2022-08-30 20:39:34 +03:00
assert.Equal(t, 1, s.handle(req, resp))
})
// Don't continue if we got any errors in the previous subtest.
require.NoError(t, err)
t.Run("offer", func(t *testing.T) {
assert.Equal(t, dhcpv4.MessageTypeOffer, resp.MessageType())
assert.Equal(t, mac, resp.ClientHWAddr)
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
ip := net.IP(l.IP.AsSlice())
assert.True(t, ip.Equal(resp.YourIPAddr))
assert.True(t, resp.Router()[0].Equal(s.conf.GatewayIP.AsSlice()))
assert.True(t, resp.ServerIdentifier().Equal(s.conf.GatewayIP.AsSlice()))
ones, _ := resp.SubnetMask().Size()
assert.Equal(t, s.conf.subnet.Bits(), ones)
assert.Equal(t, s.conf.leaseTime.Seconds(), resp.IPAddressLeaseTime(-1).Seconds())
})
t.Run("request", func(t *testing.T) {
req, err = dhcpv4.NewRequestFromOffer(resp)
require.NoError(t, err)
resp, err = dhcpv4.NewReplyFromRequest(req)
require.NoError(t, err)
Pull request: 4863 fix dhcp request Merge in DNS/adguard-home from 4863-fix-dhcp-request to master Closes #4863. Squashed commit of the following: commit f8872015e315eab3b2ce0249e552d12cbcf72f63 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:34:35 2022 +0300 dhcpd: imp code commit b63c5d98c2055c3a3b76ff47737551840409f324 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:19:22 2022 +0300 dhcpd: fix deadlock commit 5c03b54a86ab05efde9716faef60b84ecab01d19 Merge: f076cf8f 8733f55c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:12:27 2022 +0300 Merge branch 'master' into 4863-fix-dhcp-request commit f076cf8fc13944613b7127aac86ca78f68009f93 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:08:04 2022 +0300 dhcpd: imp code, names commit a09540b6db6b86b80b8eb84c08187bfd9f960190 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 17:28:39 2022 +0300 dhcpd: imp code, docs commit 38b12235509aaf55fa130f820213410b6b3022bb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:42:32 2022 +0300 dhcpd: imp docs more commit ff07c2f90f097754beb736fd5bd5cafc337ac65c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:41:42 2022 +0300 dhcpd: fix docs commit fafbc2ec2317f2320d8e1db167a1ae6c1c7c3790 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:35:42 2022 +0300 dhcpd: imp code commit 9fe30190a7f125fd640b58e17661a4c33c078eba Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 15:00:56 2022 +0300 all: imp chlog commit 1067fe95df5cb2252d1b9b70d2f3f8463997aea1 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:54:03 2022 +0300 dhcpd: log changes commit 20de395c2bdcfb8e0554bb1c45385c15d617be65 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:49:58 2022 +0300 dhcpd: impl rfc 2131 for req
2022-08-30 20:39:34 +03:00
assert.Equal(t, 1, s.handle(req, resp))
})
require.NoError(t, err)
t.Run("ack", func(t *testing.T) {
assert.Equal(t, dhcpv4.MessageTypeAck, resp.MessageType())
assert.Equal(t, mac, resp.ClientHWAddr)
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
ip := net.IP(l.IP.AsSlice())
assert.True(t, ip.Equal(resp.YourIPAddr))
assert.True(t, resp.Router()[0].Equal(s.conf.GatewayIP.AsSlice()))
assert.True(t, resp.ServerIdentifier().Equal(s.conf.GatewayIP.AsSlice()))
ones, _ := resp.SubnetMask().Size()
assert.Equal(t, s.conf.subnet.Bits(), ones)
assert.Equal(t, s.conf.leaseTime.Seconds(), resp.IPAddressLeaseTime(-1).Seconds())
})
dnsAddrs := resp.DNS()
require.Len(t, dnsAddrs, 1)
assert.True(t, dnsAddrs[0].Equal(s.conf.GatewayIP.AsSlice()))
t.Run("check_lease", func(t *testing.T) {
ls := s.GetLeases(LeasesStatic)
require.Len(t, ls, 1)
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
assert.Equal(t, l.IP, ls[0].IP)
assert.Equal(t, mac, ls[0].HWAddr)
})
}
func TestV4DynamicLease_Get(t *testing.T) {
conf := defaultV4ServerConf()
conf.Options = []string{
"81 hex 303132",
"82 ip 1.2.3.4",
}
Pull request: 4722 dhcp http panic Merge in DNS/adguard-home from 4722-dhcp-http-panic to master Updates #4722. Squashed commit of the following: commit 8a8db48c3bd4f6bb7fabe65b5b7b162f0986fc76 Merge: 39b344f9 b74b92fc Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 20:11:23 2022 +0300 Merge branch 'master' into 4722-dhcp-http-panic commit 39b344f97180af17ab22041e5655a27bcc99c29e Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 18:33:56 2022 +0300 dhcpd: imp code, fmt commit a36d70d2c25791b2e657e21d6f4681b33497f0cd Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 17:38:17 2022 +0300 dhcpd: imp names, docs commit 600d63da7af62de5cb52fc7670ef28c9f4fe95a7 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 17:36:17 2022 +0300 dhcpd: rename files, imp tags commit 44f5507649db8536a07c4c21c8ad6e4a60ba3f43 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 16:40:26 2022 +0300 dhcpd: add mock commit cfc3cfb714705067d3aa71a7cb5df4245e091cfd Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 16:15:27 2022 +0300 all: use ptr instead of value commit ec526c2cf22df3470641296cfc402113c23c3f9b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:57:10 2022 +0300 all: log changes commit 0eca09f4c72bbdc73a2334c839d7781847ba3962 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:50:32 2022 +0300 dhcpd: let v4 be unconfigured commit 59636e9ff48aea989d7bdfd216b37899b57137d2 Merge: 9238ca0a bc1503af Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 14:50:17 2022 +0300 Merge branch 'master' into 4722-dhcp-http-panic commit 9238ca0a1e190ddc344f01959f474932809f086a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Sep 7 18:28:56 2022 +0300 dhcpd: imp conf commit 5f801c9be96c2fa735a50373495d8c6ca2914f32 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 6 16:31:13 2022 +0300 dhcpd: hide behind iface commit a95c2741a7e3e5bfe8775bf937a3709217b76da0 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 31 16:24:02 2022 +0300 dhcpd: separate os files
2022-09-13 23:45:35 +03:00
s, err := v4Create(conf)
require.NoError(t, err)
s.conf.dnsIPAddrs = []netip.Addr{netip.MustParseAddr("192.168.10.1")}
s.implicitOpts.Update(dhcpv4.OptDNS(s.conf.dnsIPAddrs[0].AsSlice()))
var req, resp *dhcpv4.DHCPv4
mac := net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}
t.Run("discover", func(t *testing.T) {
req, err = dhcpv4.NewDiscovery(mac, dhcpv4.WithRequestedOptions(
dhcpv4.OptionFQDN,
dhcpv4.OptionRelayAgentInformation,
))
require.NoError(t, err)
resp, err = dhcpv4.NewReplyFromRequest(req)
require.NoError(t, err)
Pull request: 4863 fix dhcp request Merge in DNS/adguard-home from 4863-fix-dhcp-request to master Closes #4863. Squashed commit of the following: commit f8872015e315eab3b2ce0249e552d12cbcf72f63 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:34:35 2022 +0300 dhcpd: imp code commit b63c5d98c2055c3a3b76ff47737551840409f324 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:19:22 2022 +0300 dhcpd: fix deadlock commit 5c03b54a86ab05efde9716faef60b84ecab01d19 Merge: f076cf8f 8733f55c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:12:27 2022 +0300 Merge branch 'master' into 4863-fix-dhcp-request commit f076cf8fc13944613b7127aac86ca78f68009f93 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:08:04 2022 +0300 dhcpd: imp code, names commit a09540b6db6b86b80b8eb84c08187bfd9f960190 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 17:28:39 2022 +0300 dhcpd: imp code, docs commit 38b12235509aaf55fa130f820213410b6b3022bb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:42:32 2022 +0300 dhcpd: imp docs more commit ff07c2f90f097754beb736fd5bd5cafc337ac65c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:41:42 2022 +0300 dhcpd: fix docs commit fafbc2ec2317f2320d8e1db167a1ae6c1c7c3790 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:35:42 2022 +0300 dhcpd: imp code commit 9fe30190a7f125fd640b58e17661a4c33c078eba Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 15:00:56 2022 +0300 all: imp chlog commit 1067fe95df5cb2252d1b9b70d2f3f8463997aea1 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:54:03 2022 +0300 dhcpd: log changes commit 20de395c2bdcfb8e0554bb1c45385c15d617be65 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:49:58 2022 +0300 dhcpd: impl rfc 2131 for req
2022-08-30 20:39:34 +03:00
assert.Equal(t, 1, s.handle(req, resp))
})
// Don't continue if we got any errors in the previous subtest.
require.NoError(t, err)
t.Run("offer", func(t *testing.T) {
assert.Equal(t, dhcpv4.MessageTypeOffer, resp.MessageType())
assert.Equal(t, mac, resp.ClientHWAddr)
assert.True(t, resp.YourIPAddr.Equal(s.conf.RangeStart.AsSlice()))
assert.True(t, resp.ServerIdentifier().Equal(s.conf.GatewayIP.AsSlice()))
router := resp.Router()
require.Len(t, router, 1)
assert.True(t, router[0].Equal(s.conf.GatewayIP.AsSlice()))
ones, _ := resp.SubnetMask().Size()
assert.Equal(t, s.conf.subnet.Bits(), ones)
assert.Equal(t, s.conf.leaseTime.Seconds(), resp.IPAddressLeaseTime(-1).Seconds())
assert.Equal(t, []byte("012"), resp.Options.Get(dhcpv4.OptionFQDN))
rai := resp.RelayAgentInfo()
require.NotNil(t, rai)
assert.Equal(t, net.IP{1, 2, 3, 4}, net.IP(rai.ToBytes()))
})
t.Run("request", func(t *testing.T) {
req, err = dhcpv4.NewRequestFromOffer(resp)
require.NoError(t, err)
resp, err = dhcpv4.NewReplyFromRequest(req)
require.NoError(t, err)
Pull request: 4863 fix dhcp request Merge in DNS/adguard-home from 4863-fix-dhcp-request to master Closes #4863. Squashed commit of the following: commit f8872015e315eab3b2ce0249e552d12cbcf72f63 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:34:35 2022 +0300 dhcpd: imp code commit b63c5d98c2055c3a3b76ff47737551840409f324 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 20:19:22 2022 +0300 dhcpd: fix deadlock commit 5c03b54a86ab05efde9716faef60b84ecab01d19 Merge: f076cf8f 8733f55c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:12:27 2022 +0300 Merge branch 'master' into 4863-fix-dhcp-request commit f076cf8fc13944613b7127aac86ca78f68009f93 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 19:08:04 2022 +0300 dhcpd: imp code, names commit a09540b6db6b86b80b8eb84c08187bfd9f960190 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 17:28:39 2022 +0300 dhcpd: imp code, docs commit 38b12235509aaf55fa130f820213410b6b3022bb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:42:32 2022 +0300 dhcpd: imp docs more commit ff07c2f90f097754beb736fd5bd5cafc337ac65c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:41:42 2022 +0300 dhcpd: fix docs commit fafbc2ec2317f2320d8e1db167a1ae6c1c7c3790 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 16:35:42 2022 +0300 dhcpd: imp code commit 9fe30190a7f125fd640b58e17661a4c33c078eba Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 15:00:56 2022 +0300 all: imp chlog commit 1067fe95df5cb2252d1b9b70d2f3f8463997aea1 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:54:03 2022 +0300 dhcpd: log changes commit 20de395c2bdcfb8e0554bb1c45385c15d617be65 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 30 14:49:58 2022 +0300 dhcpd: impl rfc 2131 for req
2022-08-30 20:39:34 +03:00
assert.Equal(t, 1, s.handle(req, resp))
})
require.NoError(t, err)
t.Run("ack", func(t *testing.T) {
assert.Equal(t, dhcpv4.MessageTypeAck, resp.MessageType())
assert.Equal(t, mac, resp.ClientHWAddr)
assert.True(t, resp.YourIPAddr.Equal(s.conf.RangeStart.AsSlice()))
router := resp.Router()
require.Len(t, router, 1)
assert.True(t, router[0].Equal(s.conf.GatewayIP.AsSlice()))
assert.True(t, resp.ServerIdentifier().Equal(s.conf.GatewayIP.AsSlice()))
ones, _ := resp.SubnetMask().Size()
assert.Equal(t, s.conf.subnet.Bits(), ones)
assert.Equal(t, s.conf.leaseTime.Seconds(), resp.IPAddressLeaseTime(-1).Seconds())
})
dnsAddrs := resp.DNS()
require.Len(t, dnsAddrs, 1)
Pull request: 2508 ip conversion vol.2 Merge in DNS/adguard-home from 2508-ip-conversion-vol2 to master Closes #2508. Squashed commit of the following: commit 5b9d33f9cd352756831f63e34c4aea48674628c1 Author: Eugene Burkov <e.burkov@adguard.com> Date: Wed Jan 20 17:15:17 2021 +0300 util: replace net.IPNet with pointer commit 680126de7d59464077f9edf1bbaa925dd3fcee19 Merge: d3ba6a6c 5a50efad Author: Eugene Burkov <e.burkov@adguard.com> Date: Wed Jan 20 17:02:41 2021 +0300 Merge branch 'master' into 2508-ip-conversion-vol2 commit d3ba6a6cdd01c0aa736418fdb86ed40120169fe9 Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Jan 19 18:29:54 2021 +0300 all: remove last conversion commit 88b63f11a6c3f8705d7fa0c448c50dd646cc9214 Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Jan 19 14:12:45 2021 +0300 all: improve code quality commit 71af60c70a0dbaf55e2221023d6d2e4993c9e9a7 Merge: 98af3784 9f75725d Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 17:13:27 2021 +0300 Merge branch 'master' into 2508-ip-conversion-vol2 commit 98af3784ce44d0993d171653c13d6e83bb8d1e6a Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 16:32:53 2021 +0300 all: log changes commit e99595a172bae1e844019d344544be84ddd65e4e Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 16:06:49 2021 +0300 all: fix or remove remaining net.IP <-> string conversions commit 7fd0634ce945f7e4c9b856684c5199f8a84a543e Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Jan 15 15:36:17 2021 +0300 all: remove redundant net.IP <-> string converions commit 5df8af030421237d41b67ed659f83526cc258199 Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Jan 14 16:35:25 2021 +0300 stats: remove redundant net.IP <-> string conversion commit fbe4e3fc015e6898063543a90c04401d76dbb18f Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Jan 14 16:20:35 2021 +0300 querylog: remove redundant net.IP <-> string conversion
2021-01-20 17:27:53 +03:00
assert.True(t, net.IP{192, 168, 10, 1}.Equal(dnsAddrs[0]))
// check lease
t.Run("check_lease", func(t *testing.T) {
ls := s.GetLeases(LeasesDynamic)
require.Len(t, ls, 1)
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
ip := netip.MustParseAddr("192.168.10.100")
assert.Equal(t, ip, ls[0].IP)
assert.Equal(t, mac, ls[0].HWAddr)
})
}
func TestNormalizeHostname(t *testing.T) {
testCases := []struct {
name string
hostname string
wantErrMsg string
want string
}{{
name: "success",
hostname: "example.com",
wantErrMsg: "",
want: "example.com",
}, {
name: "success_empty",
hostname: "",
wantErrMsg: "",
want: "",
}, {
name: "success_spaces",
hostname: "my device 01",
wantErrMsg: "",
want: "my-device-01",
}, {
name: "success_underscores",
hostname: "my_device_01",
wantErrMsg: "",
want: "my-device-01",
}, {
name: "error_part",
hostname: "device !!!",
wantErrMsg: "",
want: "device",
}, {
name: "error_part_spaces",
hostname: "device ! ! !",
wantErrMsg: "",
want: "device",
}, {
name: "error",
hostname: "!!!",
wantErrMsg: `normalizing "!!!": no valid parts`,
want: "",
}, {
name: "error_spaces",
hostname: "! ! !",
wantErrMsg: `normalizing "! ! !": no valid parts`,
want: "",
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got, err := normalizeHostname(tc.hostname)
testutil.AssertErrorMsg(t, tc.wantErrMsg, err)
assert.Equal(t, tc.want, got)
})
}
}
// fakePacketConn is a mock implementation of net.PacketConn to simplify
// testing.
type fakePacketConn struct {
// writeTo is used to substitute net.PacketConn's WriteTo method.
writeTo func(p []byte, addr net.Addr) (n int, err error)
// net.PacketConn is embedded here simply to make *fakePacketConn a
// net.PacketConn without actually implementing all methods.
net.PacketConn
}
// WriteTo implements net.PacketConn interface for *fakePacketConn.
func (fc *fakePacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
return fc.writeTo(p, addr)
}
func TestV4Server_Send(t *testing.T) {
s := &v4Server{}
var (
defaultIP = net.IP{99, 99, 99, 99}
knownIP = net.IP{4, 2, 4, 2}
knownMAC = net.HardwareAddr{6, 5, 4, 3, 2, 1}
)
defaultPeer := &net.UDPAddr{
IP: defaultIP,
// Use neither client nor server port to check it actually
// changed.
Port: dhcpv4.ClientPort + dhcpv4.ServerPort,
}
defaultResp := &dhcpv4.DHCPv4{}
testCases := []struct {
want net.Addr
req *dhcpv4.DHCPv4
resp *dhcpv4.DHCPv4
name string
}{{
name: "giaddr",
req: &dhcpv4.DHCPv4{GatewayIPAddr: knownIP},
resp: defaultResp,
want: &net.UDPAddr{
IP: knownIP,
Port: dhcpv4.ServerPort,
},
}, {
name: "nak",
req: &dhcpv4.DHCPv4{},
resp: &dhcpv4.DHCPv4{
Options: dhcpv4.OptionsFromList(
dhcpv4.OptMessageType(dhcpv4.MessageTypeNak),
),
},
want: defaultPeer,
}, {
name: "ciaddr",
req: &dhcpv4.DHCPv4{ClientIPAddr: knownIP},
resp: &dhcpv4.DHCPv4{},
want: &net.UDPAddr{
IP: knownIP,
Port: dhcpv4.ClientPort,
},
}, {
name: "chaddr",
req: &dhcpv4.DHCPv4{ClientHWAddr: knownMAC},
resp: &dhcpv4.DHCPv4{YourIPAddr: knownIP},
want: &dhcpUnicastAddr{
Addr: packet.Addr{HardwareAddr: knownMAC},
yiaddr: knownIP,
},
}, {
name: "who_are_you",
req: &dhcpv4.DHCPv4{},
resp: &dhcpv4.DHCPv4{},
want: defaultPeer,
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
conn := &fakePacketConn{
writeTo: func(_ []byte, addr net.Addr) (_ int, _ error) {
assert.Equal(t, tc.want, addr)
return 0, nil
},
}
s.send(cloneUDPAddr(defaultPeer), conn, tc.req, tc.resp)
})
}
t.Run("giaddr_nak", func(t *testing.T) {
req := &dhcpv4.DHCPv4{
GatewayIPAddr: knownIP,
}
// Ensure the request is for unicast.
req.SetUnicast()
resp := &dhcpv4.DHCPv4{
Options: dhcpv4.OptionsFromList(
dhcpv4.OptMessageType(dhcpv4.MessageTypeNak),
),
}
want := &net.UDPAddr{
IP: req.GatewayIPAddr,
Port: dhcpv4.ServerPort,
}
conn := &fakePacketConn{
writeTo: func(_ []byte, addr net.Addr) (n int, err error) {
assert.Equal(t, want, addr)
return 0, nil
},
}
s.send(cloneUDPAddr(defaultPeer), conn, req, resp)
assert.True(t, resp.IsBroadcast())
})
}
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
func TestV4Server_FindMACbyIP(t *testing.T) {
const (
staticName = "static-client"
anotherName = "another-client"
)
staticIP := netip.MustParseAddr("192.168.10.10")
staticMAC := net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}
anotherIP := netip.MustParseAddr("192.168.100.100")
anotherMAC := net.HardwareAddr{0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB}
s := &v4Server{
leases: []*Lease{{
Expiry: time.Unix(leaseExpireStatic, 0),
Hostname: staticName,
HWAddr: staticMAC,
IP: staticIP,
IsStatic: true,
Pull request 1771: AG-20352-dhcpd-lease-netip-addr Merge in DNS/adguard-home from AG-20352-dhcpd-lease-netip-addr to master Squashed commit of the following: commit 4acd094e2d6ed972bac99cdb671670f6d8e61721 Merge: 51f61c19 df61741f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 23 16:44:17 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 51f61c193fdd31ee675be5598fc361228e407eb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 18:25:30 2023 +0300 dhcpd: fix typo commit 2e64ad55475957925d2a3010c649e0adc5f18c4f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 17:20:31 2023 +0300 dhcpd: add todo commit 668d4f62fd2c5b2e168025bf0b6bb36d7b617c80 Merge: 0020006e 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:09:38 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit 0020006e89f336dc58db1a2ca3ce90d2e7a5ca16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 15:08:58 2023 +0300 all: imp code commit 9a77f79869cdbde6de760734c0d8cf504e0464ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 18:13:35 2023 +0300 dhcpd: add todo commit 638c4ce2af72235bf065a6492d58f3f1b1e7644a Merge: c82b18f1 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:57:19 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c82b18f1408d9e353aec517f4283e2f3eb260890 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 13:56:31 2023 +0300 all: imp code commit 27e518120024103c292ac1cf134c6801fffc967e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 12:14:02 2023 +0300 dhcpd: imp tests commit 8e919b0ceb0b20d1935587e717c7965cd8a33ad9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 11:02:50 2023 +0300 dhcpd: add tests commit 78ddefa73a255509af1c788147d6b1c332bb66ba Merge: c68e85c4 9f7a582d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:15:24 2023 +0300 Merge branch 'master' into AG-20352-dhcpd-lease-netip-addr commit c68e85c40947b6c83516424a2bd7af89b99447b4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 14:14:43 2023 +0300 all: add tests commit f338086309a68c4b71036fa14f757e39358702d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:44:06 2023 +0300 all: dhcpd lease netip addr
2023-03-23 16:52:01 +03:00
}, {
Expiry: time.Unix(10, 0),
Hostname: anotherName,
HWAddr: anotherMAC,
IP: anotherIP,
}},
}
testCases := []struct {
want net.HardwareAddr
ip netip.Addr
name string
}{{
name: "basic",
ip: staticIP,
want: staticMAC,
}, {
name: "not_found",
ip: netip.MustParseAddr("1.2.3.4"),
want: nil,
}, {
name: "expired",
ip: anotherIP,
want: nil,
}, {
name: "v6",
ip: netip.MustParseAddr("ffff::1"),
want: nil,
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
mac := s.FindMACbyIP(tc.ip)
require.Equal(t, tc.want, mac)
})
}
}
func TestV4Server_handleDecline(t *testing.T) {
const (
dynamicName = "dynamic-client"
anotherName = "another-client"
)
dynamicIP := netip.MustParseAddr("192.168.10.200")
dynamicMAC := net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}
s := defaultSrv(t)
s4, ok := s.(*v4Server)
require.True(t, ok)
s4.leases = []*Lease{{
Hostname: dynamicName,
HWAddr: dynamicMAC,
IP: dynamicIP,
}}
req, err := dhcpv4.New(
dhcpv4.WithOption(dhcpv4.OptRequestedIPAddress(net.IP(dynamicIP.AsSlice()))),
)
require.NoError(t, err)
req.ClientIPAddr = net.IP(dynamicIP.AsSlice())
req.ClientHWAddr = dynamicMAC
resp := &dhcpv4.DHCPv4{}
err = s4.handleDecline(req, resp)
require.NoError(t, err)
wantResp := &dhcpv4.DHCPv4{
YourIPAddr: net.IP(s4.conf.RangeStart.AsSlice()),
Options: dhcpv4.OptionsFromList(
dhcpv4.OptMessageType(dhcpv4.MessageTypeAck),
),
}
require.Equal(t, wantResp, resp)
}
func TestV4Server_handleRelease(t *testing.T) {
const (
dynamicName = "dymamic-client"
anotherName = "another-client"
)
dynamicIP := netip.MustParseAddr("192.168.10.200")
dynamicMAC := net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}
s := defaultSrv(t)
s4, ok := s.(*v4Server)
require.True(t, ok)
s4.leases = []*Lease{{
Hostname: dynamicName,
HWAddr: dynamicMAC,
IP: dynamicIP,
}}
req, err := dhcpv4.New(
dhcpv4.WithOption(dhcpv4.OptRequestedIPAddress(net.IP(dynamicIP.AsSlice()))),
)
require.NoError(t, err)
req.ClientIPAddr = net.IP(dynamicIP.AsSlice())
req.ClientHWAddr = dynamicMAC
resp := &dhcpv4.DHCPv4{}
err = s4.handleRelease(req, resp)
require.NoError(t, err)
wantResp := &dhcpv4.DHCPv4{
Options: dhcpv4.OptionsFromList(
dhcpv4.OptMessageType(dhcpv4.MessageTypeAck),
),
}
require.Equal(t, wantResp, resp)
}