Skip to content

Commit 2159e90

Browse files
committed
Fix dns lookup
1 parent 23f4bc6 commit 2159e90

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

util/wg_pool.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ func (w *WGPool) AddPoolPeerByPubKey(publicKey wgtypes.Key) {
4747
}
4848
}
4949

50+
func (w *WGPool) HasSubdomain(subdomain string) bool {
51+
_, ok := w.subdomains[subdomain]
52+
return ok
53+
}
54+
5055
func (w *WGPool) GetPeerAddressBySubdomain(subdomain string) net.IP {
5156
return w.subdomains[subdomain].address
5257
}

wgapi/myhttpserver/server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ func (h *HTTPServer) StartServer() chan error {
4343
}
4444

4545
var rr dns.RR
46+
var subdomain = strings.Split(question.Name, ".")[0]
4647
switch question.Qtype {
4748
case dns.TypeA:
48-
if val := h.server.GetPeerAddressFor(strings.ToLower(question.Name)); val != nil {
49+
if val := h.server.GetPeerAddressFor(strings.ToLower(subdomain)); val != nil {
4950
rr = &dns.A{
5051
Hdr: dns.RR_Header{
5152
Name: question.Name,

wgapi/mywgserver/server.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ func (s *WGServer) StopServer() {
217217
}
218218

219219
func (s *WGServer) GetPeerAddressFor(subdomain string) net.IP {
220-
return s.wgPool.GetPeerAddressBySubdomain(subdomain)
220+
s.logger.Verbosef("GetPeerAddressFor %s", subdomain)
221+
if s.wgPool.HasSubdomain(subdomain) {
222+
return s.wgPool.GetPeerAddressBySubdomain(subdomain)
223+
} else {
224+
return nil
225+
}
221226
}
222227

223228
func checkIsRoot(logger *device.Logger) (bool, error) {

0 commit comments

Comments
 (0)