Skip to content

Commit 42e8a50

Browse files
committed
Update DNS
1 parent 86f0903 commit 42e8a50

3 files changed

Lines changed: 11 additions & 58 deletions

File tree

agent/internal/container/runtime_linux.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"strings"
1313
"time"
1414

15-
"techulus/cloud-agent/internal/dns"
1615
"techulus/cloud-agent/internal/retry"
1716
)
1817

@@ -122,9 +121,6 @@ func Deploy(config *DeployConfig) (*DeployResult, error) {
122121
}
123122
}
124123

125-
if dnsIP := dns.GetContainerDNS(); dnsIP != "" {
126-
args = append(args, "--dns", dnsIP)
127-
}
128124

129125
if config.HealthCheck != nil && config.HealthCheck.Cmd != "" {
130126
args = append(args, "--health-cmd", config.HealthCheck.Cmd)
@@ -516,7 +512,6 @@ func EnsureNetwork(subnetId int) error {
516512
"--driver", "bridge",
517513
"--subnet", subnet,
518514
"--gateway", gateway,
519-
"--disable-dns",
520515
NetworkName,
521516
}
522517

agent/internal/dns/handler.go

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,13 @@
11
package dns
22

33
import (
4-
"time"
5-
64
"github.com/miekg/dns"
75
)
86

97
const defaultTTL = 30
108

11-
var upstreamServers = []string{
12-
"8.8.8.8:53",
13-
"1.1.1.1:53",
14-
}
15-
169
type dnsHandler struct {
17-
store *RecordStore
18-
client *dns.Client
19-
}
20-
21-
func newDNSHandler(store *RecordStore) *dnsHandler {
22-
return &dnsHandler{
23-
store: store,
24-
client: &dns.Client{
25-
Net: "udp",
26-
Timeout: 5 * time.Second,
27-
},
28-
}
10+
store *RecordStore
2911
}
3012

3113
func (h *dnsHandler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
@@ -36,29 +18,23 @@ func (h *dnsHandler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
3618
for _, q := range r.Question {
3719
switch q.Qtype {
3820
case dns.TypeA:
39-
if !h.handleA(m, q) {
40-
h.forwardQuery(w, r)
41-
return
42-
}
21+
h.handleA(m, q)
4322
case dns.TypeAAAA:
44-
if !h.handleAAAA(m, q) {
45-
h.forwardQuery(w, r)
46-
return
47-
}
23+
h.handleAAAA(m, q)
4824
default:
49-
h.forwardQuery(w, r)
50-
return
25+
m.Rcode = dns.RcodeNotImplemented
5126
}
5227
}
5328

5429
w.WriteMsg(m)
5530
}
5631

57-
func (h *dnsHandler) handleA(m *dns.Msg, q dns.Question) bool {
32+
func (h *dnsHandler) handleA(m *dns.Msg, q dns.Question) {
5833
ips := h.store.Lookup(q.Name)
5934

6035
if ips == nil {
61-
return false
36+
m.Rcode = dns.RcodeNameError
37+
return
6238
}
6339

6440
for _, ip := range ips {
@@ -75,14 +51,14 @@ func (h *dnsHandler) handleA(m *dns.Msg, q dns.Question) bool {
7551
m.Answer = append(m.Answer, rr)
7652
}
7753
}
78-
return true
7954
}
8055

81-
func (h *dnsHandler) handleAAAA(m *dns.Msg, q dns.Question) bool {
56+
func (h *dnsHandler) handleAAAA(m *dns.Msg, q dns.Question) {
8257
ips := h.store.Lookup(q.Name)
8358

8459
if ips == nil {
85-
return false
60+
m.Rcode = dns.RcodeNameError
61+
return
8662
}
8763

8864
for _, ip := range ips {
@@ -99,22 +75,4 @@ func (h *dnsHandler) handleAAAA(m *dns.Msg, q dns.Question) bool {
9975
m.Answer = append(m.Answer, rr)
10076
}
10177
}
102-
return true
103-
}
104-
105-
func (h *dnsHandler) forwardQuery(w dns.ResponseWriter, r *dns.Msg) {
106-
for _, server := range upstreamServers {
107-
resp, _, err := h.client.Exchange(r, server)
108-
if err != nil {
109-
continue
110-
}
111-
resp.Id = r.Id
112-
w.WriteMsg(resp)
113-
return
114-
}
115-
116-
m := new(dns.Msg)
117-
m.SetReply(r)
118-
m.Rcode = dns.RcodeServerFailure
119-
w.WriteMsg(m)
12078
}

agent/internal/dns/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (s *Server) Start(ctx context.Context) error {
4242

4343
addr := fmt.Sprintf("%s:%d", s.listenAddr, s.port)
4444

45-
handler := newDNSHandler(s.store)
45+
handler := &dnsHandler{store: s.store}
4646

4747
udpReady := make(chan struct{})
4848
tcpReady := make(chan struct{})

0 commit comments

Comments
 (0)