mirror of
https://git.vectorsigma.ru/public/AdGuardHome.git
synced 2026-08-06 10:59:22 +00:00
Pull request #2421: AGNDS-2949 Fix DHCP name resolve
Merge in DNS/adguard-home from AGNDS-2949-fix-dhcp-name-resolve to master Squashed commit of the following: commit f766313f391643cb80c97e6e7333c753614d6d8e Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Jun 3 17:39:19 2025 +0300 dnsforward: fix test commit a181c98df6ad4a2e5690c34288cb87c65c2c3f50 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Jun 2 17:37:38 2025 +0300 dnsforward: add tests, imp docs commit 81cee6f47a78d57b6cbeb6ff55b9601b3f84afd4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Jun 2 17:20:49 2025 +0300 dnsforward: match whole subdomain for dhcp names
This commit is contained in:
@@ -20,6 +20,8 @@ NOTE: Add new changes BELOW THIS COMMENT.
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- The hostnames of DHCP clients with multiple labels not being recognized.
|
||||||
|
|
||||||
- Status reported by the systemd service implementation in cases of auto-restart after a failed start.
|
- Status reported by the systemd service implementation in cases of auto-restart after a failed start.
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|||||||
@@ -563,7 +563,7 @@ func (s *Server) dhcpHostFromRequest(q *dns.Question) (reqHost string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reqHost = strings.ToLower(q.Name[:len(q.Name)-1])
|
reqHost = strings.ToLower(q.Name[:len(q.Name)-1])
|
||||||
if !netutil.IsImmediateSubdomain(reqHost, s.localDomainSuffix) {
|
if !netutil.IsSubdomain(reqHost, s.localDomainSuffix) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -498,14 +498,28 @@ func TestServer_ProcessDHCPHosts_localRestriction(t *testing.T) {
|
|||||||
|
|
||||||
func TestServer_ProcessDHCPHosts(t *testing.T) {
|
func TestServer_ProcessDHCPHosts(t *testing.T) {
|
||||||
const (
|
const (
|
||||||
localTLD = "lan"
|
localTLD = "lan"
|
||||||
|
customTLD = "custom"
|
||||||
|
|
||||||
knownClient = "example"
|
oneLabelClient = "example"
|
||||||
externalHost = knownClient + ".com"
|
twoLabelClient = "sub.example"
|
||||||
clientHost = knownClient + "." + localTLD
|
externalHost = oneLabelClient + ".com"
|
||||||
|
oneLabelClientHost = oneLabelClient + "." + localTLD
|
||||||
|
twoLabelClientHost = twoLabelClient + "." + localTLD
|
||||||
)
|
)
|
||||||
|
|
||||||
knownIP := netip.MustParseAddr("1.2.3.4")
|
knownClients := map[string]netip.Addr{
|
||||||
|
oneLabelClient: netip.MustParseAddr("1.2.3.4"),
|
||||||
|
twoLabelClient: netip.MustParseAddr("1.2.3.5"),
|
||||||
|
}
|
||||||
|
|
||||||
|
testDHCP := &testDHCP{
|
||||||
|
OnEnabled: func() (ok bool) { return true },
|
||||||
|
OnIPByHost: func(host string) (ip netip.Addr) {
|
||||||
|
return knownClients[host]
|
||||||
|
},
|
||||||
|
OnHostByIP: func(ip netip.Addr) (host string) { panic("not implemented") },
|
||||||
|
}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
wantIP netip.Addr
|
wantIP netip.Addr
|
||||||
@@ -529,9 +543,16 @@ func TestServer_ProcessDHCPHosts(t *testing.T) {
|
|||||||
wantRes: resultCodeSuccess,
|
wantRes: resultCodeSuccess,
|
||||||
qtyp: dns.TypeCNAME,
|
qtyp: dns.TypeCNAME,
|
||||||
}, {
|
}, {
|
||||||
wantIP: knownIP,
|
wantIP: knownClients[oneLabelClient],
|
||||||
name: "internal",
|
name: "internal",
|
||||||
host: clientHost,
|
host: oneLabelClientHost,
|
||||||
|
suffix: localTLD,
|
||||||
|
wantRes: resultCodeSuccess,
|
||||||
|
qtyp: dns.TypeA,
|
||||||
|
}, {
|
||||||
|
wantIP: knownClients[twoLabelClient],
|
||||||
|
name: "internal_two_label",
|
||||||
|
host: twoLabelClientHost,
|
||||||
suffix: localTLD,
|
suffix: localTLD,
|
||||||
wantRes: resultCodeSuccess,
|
wantRes: resultCodeSuccess,
|
||||||
qtyp: dns.TypeA,
|
qtyp: dns.TypeA,
|
||||||
@@ -545,32 +566,27 @@ func TestServer_ProcessDHCPHosts(t *testing.T) {
|
|||||||
}, {
|
}, {
|
||||||
wantIP: netip.Addr{},
|
wantIP: netip.Addr{},
|
||||||
name: "internal_aaaa",
|
name: "internal_aaaa",
|
||||||
host: clientHost,
|
host: oneLabelClientHost,
|
||||||
suffix: localTLD,
|
suffix: localTLD,
|
||||||
wantRes: resultCodeSuccess,
|
wantRes: resultCodeSuccess,
|
||||||
qtyp: dns.TypeAAAA,
|
qtyp: dns.TypeAAAA,
|
||||||
}, {
|
}, {
|
||||||
wantIP: knownIP,
|
wantIP: knownClients[oneLabelClient],
|
||||||
name: "custom_suffix",
|
name: "custom_suffix",
|
||||||
host: knownClient + ".custom",
|
host: oneLabelClient + "." + customTLD,
|
||||||
suffix: "custom",
|
suffix: customTLD,
|
||||||
|
wantRes: resultCodeSuccess,
|
||||||
|
qtyp: dns.TypeA,
|
||||||
|
}, {
|
||||||
|
wantIP: knownClients[twoLabelClient],
|
||||||
|
name: "custom_suffix_two_label",
|
||||||
|
host: twoLabelClient + "." + customTLD,
|
||||||
|
suffix: customTLD,
|
||||||
wantRes: resultCodeSuccess,
|
wantRes: resultCodeSuccess,
|
||||||
qtyp: dns.TypeA,
|
qtyp: dns.TypeA,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
testDHCP := &testDHCP{
|
|
||||||
OnEnabled: func() (_ bool) { return true },
|
|
||||||
OnIPByHost: func(host string) (ip netip.Addr) {
|
|
||||||
if host == knownClient {
|
|
||||||
ip = knownIP
|
|
||||||
}
|
|
||||||
|
|
||||||
return ip
|
|
||||||
},
|
|
||||||
OnHostByIP: func(ip netip.Addr) (host string) { panic("not implemented") },
|
|
||||||
}
|
|
||||||
|
|
||||||
s := &Server{
|
s := &Server{
|
||||||
dnsFilter: createTestDNSFilter(t),
|
dnsFilter: createTestDNSFilter(t),
|
||||||
dhcpServer: testDHCP,
|
dhcpServer: testDHCP,
|
||||||
@@ -578,16 +594,7 @@ func TestServer_ProcessDHCPHosts(t *testing.T) {
|
|||||||
baseLogger: slogutil.NewDiscardLogger(),
|
baseLogger: slogutil.NewDiscardLogger(),
|
||||||
}
|
}
|
||||||
|
|
||||||
req := &dns.Msg{
|
req := (&dns.Msg{}).SetQuestion(dns.Fqdn(tc.host), tc.qtyp)
|
||||||
MsgHdr: dns.MsgHdr{
|
|
||||||
Id: 1234,
|
|
||||||
},
|
|
||||||
Question: []dns.Question{{
|
|
||||||
Name: dns.Fqdn(tc.host),
|
|
||||||
Qtype: tc.qtyp,
|
|
||||||
Qclass: dns.ClassINET,
|
|
||||||
}},
|
|
||||||
}
|
|
||||||
|
|
||||||
dctx := &dnsContext{
|
dctx := &dnsContext{
|
||||||
proxyCtx: &proxy.DNSContext{
|
proxyCtx: &proxy.DNSContext{
|
||||||
@@ -603,8 +610,8 @@ func TestServer_ProcessDHCPHosts(t *testing.T) {
|
|||||||
require.NoError(t, dctx.err)
|
require.NoError(t, dctx.err)
|
||||||
|
|
||||||
if tc.qtyp == dns.TypeAAAA {
|
if tc.qtyp == dns.TypeAAAA {
|
||||||
// TODO(a.garipov): Remove this special handling
|
// TODO(a.garipov): Remove this special handling when we fully
|
||||||
// when we fully support AAAA.
|
// support AAAA.
|
||||||
require.NotNil(t, pctx.Res)
|
require.NotNil(t, pctx.Res)
|
||||||
|
|
||||||
ans := pctx.Res.Answer
|
ans := pctx.Res.Answer
|
||||||
|
|||||||
Reference in New Issue
Block a user