Skip to content

Commit c68049e

Browse files
committed
Fix hostresolver setting for VZ, but disable it by default
Since it was implicitly disabled for VZ, we cannot simply fix the bug, but change the default to match the previous de-facto default. See #4089 for more info. Signed-off-by: Jan Dubois <[email protected]>
1 parent aad73df commit c68049e

File tree

7 files changed

+18
-8
lines changed

7 files changed

+18
-8
lines changed

pkg/cidata/cidata.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,12 @@ func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, i
275275
for _, addr := range instConfig.DNS {
276276
args.DNSAddresses = append(args.DNSAddresses, addr.String())
277277
}
278-
case firstUsernetIndex != -1 || *instConfig.VMType == limatype.VZ:
279-
args.DNSAddresses = append(args.DNSAddresses, args.SlirpDNS)
280278
case *instConfig.HostResolver.Enabled:
281279
args.UDPDNSLocalPort = udpDNSLocalPort
282280
args.TCPDNSLocalPort = tcpDNSLocalPort
283281
args.DNSAddresses = append(args.DNSAddresses, args.SlirpDNS)
282+
case firstUsernetIndex != -1 || *instConfig.VMType == limatype.VZ:
283+
args.DNSAddresses = append(args.DNSAddresses, args.SlirpDNS)
284284
default:
285285
args.DNSAddresses, err = osutil.DNSAddresses()
286286
if err != nil {

pkg/driver/qemu/qemu_driver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ func (l *LimaQemuDriver) FillConfig(ctx context.Context, cfg *limatype.LimaYAML,
166166
cfg.CPUType = nil
167167
}
168168

169+
if cfg.HostResolver.Enabled == nil {
170+
cfg.HostResolver.Enabled = ptr.Of(true)
171+
}
172+
169173
mountTypesUnsupported := make(map[string]struct{})
170174
for _, f := range cfg.MountTypesUnsupported {
171175
mountTypesUnsupported[f] = struct{}{}

pkg/driverutil/vm.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/sirupsen/logrus"
1515

1616
"github.com/lima-vm/lima/v2/pkg/limatype"
17+
"github.com/lima-vm/lima/v2/pkg/ptr"
1718
"github.com/lima-vm/lima/v2/pkg/registry"
1819
)
1920

@@ -47,6 +48,10 @@ func validateConfigAgainstDriver(ctx context.Context, y *limatype.LimaYAML, file
4748
return err
4849
}
4950

51+
if y.HostResolver.Enabled == nil {
52+
y.HostResolver.Enabled = ptr.Of(false)
53+
}
54+
5055
return nil
5156
}
5257

pkg/limayaml/defaults.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,7 @@ func FillDefault(ctx context.Context, y, d, o *limatype.LimaYAML, filePath strin
538538
if o.HostResolver.Enabled != nil {
539539
y.HostResolver.Enabled = o.HostResolver.Enabled
540540
}
541-
if y.HostResolver.Enabled == nil {
542-
y.HostResolver.Enabled = ptr.Of(true)
543-
}
541+
// Default will be filled in by driver (false, except for QEMU)
544542

545543
if y.HostResolver.IPv6 == nil {
546544
y.HostResolver.IPv6 = d.HostResolver.IPv6

pkg/limayaml/defaults_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func TestFillDefault(t *testing.T) {
139139
// their values are retained and defaults for their fields are applied correctly.
140140
y = limatype.LimaYAML{
141141
HostResolver: limatype.HostResolver{
142+
Enabled: ptr.Of(true),
142143
Hosts: map[string]string{
143144
"MY.Host": "host.lima.internal",
144145
},

templates/default.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ propagateProxyEnv: null
565565
# can only work when using a vmnet network interface and the host has working
566566
# IPv6 configured as well.
567567
hostResolver:
568-
# 🟢 Builtin default: true
568+
# 🟢 Builtin default: false (except for vmType: qemu, where it is true)
569569
enabled: null
570570
# 🟢 Builtin default: false
571571
ipv6: null

website/content/en/docs/config/network/user.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The loopback addresses of the host is `192.168.5.2` and is accessible from the g
2323

2424
## DNS (192.168.5.3)
2525

26-
If `hostResolver.enabled` in `lima.yaml` is true, then the hostagent is going to run a DNS server over tcp and udp - each on a separate randomly selected free port. This server does a local lookup using the native host resolver, so it will deal correctly with VPN configurations and split-DNS setups, as well as mDNS, local `/etc/hosts` etc. For this the hostagent has to be compiled with `CGO_ENABLED=1` as default Go resolver is [broken](https://github.com/golang/go/issues/12524).
26+
If `hostResolver.enabled` in `lima.yaml` is true (default for `qemu` driver), then the hostagent is going to run a DNS server over tcp and udp - each on a separate randomly selected free port. This server does a local lookup using the native host resolver, so it will deal correctly with VPN configurations and split-DNS setups, as well as mDNS, local `/etc/hosts` etc. For this the hostagent has to be compiled with `CGO_ENABLED=1` as default Go resolver is [broken](https://github.com/golang/go/issues/12524).
2727

2828
These tcp and udp ports are then forwarded via iptables rules to `192.168.5.3:53`, overriding the DNS provided by QEMU via slirp.
2929

@@ -43,4 +43,6 @@ DNS over tcp is rarely used. It is usually only used either when user explicitly
4343

4444
During initial cloud-init bootstrap, `iptables` may not yet be installed. In that case the repo server is determined using the slirp DNS. After `iptables` has been installed, the forwarding rule is applied, switching over to the hostagent DNS.
4545

46-
If `hostResolver.enabled` is false, then DNS servers can be configured manually in `lima.yaml` via the `dns` setting. If that list is empty, then Lima will either use the slirp DNS (on Linux), or the nameservers from the first host interface in service order that has an assigned IPv4 address (on macOS).
46+
If `hostResolver.enabled` is false (default for all drivers except `qemu`), then DNS servers can be configured manually in `lima.yaml` via the `dns` setting. If that list is empty, then Lima will either use the slirp DNS (on Linux), or the nameservers from the first host interface in service order that has an assigned IPv4 address (on macOS).
47+
48+
The host resolver is not needed with the `vz` driver because the `gvisor-tap-vsock` implementation used by `usernet` has the same functionality built-in.

0 commit comments

Comments
 (0)