Skip to content

Commit 3775769

Browse files
committed
pkg/hostagent: split DNS pkg
Signed-off-by: Akihiro Suda <[email protected]>
1 parent 0f9483b commit 3775769

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pkg/hostagent/dns.go renamed to pkg/hostagent/dns/dns.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file has been adapted from https://github.com/norouter/norouter/blob/v0.6.4/pkg/agent/dns/dns.go
22

3-
package hostagent
3+
package dns
44

55
import (
66
"fmt"
@@ -205,14 +205,14 @@ func (h *Handler) ServeDNS(w dns.ResponseWriter, req *dns.Msg) {
205205
}
206206
}
207207

208-
func (a *HostAgent) StartDNS() (*Server, error) {
208+
func Start(udpLocalPort, tcpLocalPort int) (*Server, error) {
209209
h, err := newHandler()
210210
if err != nil {
211-
panic(err)
211+
return nil, err
212212
}
213213
server := &Server{}
214-
if a.udpDNSLocalPort > 0 {
215-
addr := fmt.Sprintf("127.0.0.1:%d", a.udpDNSLocalPort)
214+
if udpLocalPort > 0 {
215+
addr := fmt.Sprintf("127.0.0.1:%d", udpLocalPort)
216216
s := &dns.Server{Net: "udp", Addr: addr, Handler: h}
217217
server.udp = s
218218
go func() {
@@ -221,8 +221,8 @@ func (a *HostAgent) StartDNS() (*Server, error) {
221221
}
222222
}()
223223
}
224-
if a.tcpDNSLocalPort > 0 {
225-
addr := fmt.Sprintf("127.0.0.1:%d", a.tcpDNSLocalPort)
224+
if tcpLocalPort > 0 {
225+
addr := fmt.Sprintf("127.0.0.1:%d", tcpLocalPort)
226226
s := &dns.Server{Net: "tcp", Addr: addr, Handler: h}
227227
server.tcp = s
228228
go func() {

pkg/hostagent/hostagent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
guestagentapi "github.com/lima-vm/lima/pkg/guestagent/api"
2424
guestagentclient "github.com/lima-vm/lima/pkg/guestagent/api/client"
2525
hostagentapi "github.com/lima-vm/lima/pkg/hostagent/api"
26+
"github.com/lima-vm/lima/pkg/hostagent/dns"
2627
"github.com/lima-vm/lima/pkg/hostagent/events"
2728
"github.com/lima-vm/lima/pkg/limayaml"
2829
"github.com/lima-vm/lima/pkg/qemu"
@@ -248,7 +249,7 @@ func (a *HostAgent) Run(ctx context.Context) error {
248249
}()
249250

250251
if *a.y.UseHostResolver {
251-
dnsServer, err := a.StartDNS()
252+
dnsServer, err := dns.Start(a.udpDNSLocalPort, a.tcpDNSLocalPort)
252253
if err != nil {
253254
return fmt.Errorf("cannot start DNS server: %w", err)
254255
}

0 commit comments

Comments
 (0)