Skip to content

Commit

Permalink
Remove the support for vde_vmnet (Deprecated since Sep 2022)
Browse files Browse the repository at this point in the history
`vde_vmnet` has been deprecated since Lima v0.12.0 (Sep 2022),
in favor of `socket_vmnet`:
- PR 851

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed May 1, 2024
1 parent 6bbd9a7 commit 7b52030
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 318 deletions.
14 changes: 0 additions & 14 deletions examples/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ networks:
# Lima can manage daemons for networks defined in $LIMA_HOME/_config/networks.yaml
# automatically. The socket_vmnet binary must be installed into
# secure locations only alterable by the "root" user.
# The same applies to vde_switch and vde_vmnet for the deprecated VDE mode.
# - lima: shared
# # MAC address of the instance; lima will pick one based on the instance name,
# # so DHCP assigned ip addresses should remain constant over instance restarts.
Expand All @@ -338,19 +337,6 @@ networks:
# Needs `vmType: vz` (EXPERIMENTAL).
# - vzNAT: true

# vnl (virtual network locator) points to the vde_switch socket directory,
# optionally with vde:// prefix
# ⚠️ vnl is deprecated, use socket.
# - vnl: "vde:///var/run/vde.ctl"
# # VDE Switch port number (not TCP/UDP port number). Set to 65535 for PTP mode.
# # Builtin default: 0
# switchPort: 0
# # MAC address of the instance; lima will pick one based on the instance name,
# # so DHCP assigned ip addresses should remain constant over instance restarts.
# macAddress: ""
# # Interface name, defaults to "lima0", "lima1", etc.
# interface: ""

# Port forwarding rules. Forwarding between ports 22 and ssh.localPort cannot be overridden.
# Rules are checked sequentially until the first one matches.
# portForwards:
Expand Down
3 changes: 1 addition & 2 deletions examples/vmnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ mounts:
writable: true
networks:
# The instance can get routable IP addresses from the vmnet framework using
# https://github.com/lima-vm/socket_vmnet (since Lima v0.12) or
# https://github.com/lima-vm/vde_vmnet (deprecated) .
# https://github.com/lima-vm/socket_vmnet (since Lima v0.12).
#
# Available networks are defined in
# $LIMA_HOME/_config/networks.yaml. Supported network types are "host",
Expand Down
20 changes: 0 additions & 20 deletions pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,38 +508,18 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
iface := make(map[string]int)
for _, nw := range append(append(d.Networks, y.Networks...), o.Networks...) {
if i, ok := iface[nw.Interface]; ok {
if nw.VNLDeprecated != "" {
networks[i].VNLDeprecated = nw.VNLDeprecated
networks[i].SwitchPortDeprecated = nw.SwitchPortDeprecated
networks[i].Socket = ""
networks[i].Lima = ""
}
if nw.Socket != "" {
if nw.VNLDeprecated != "" {
// We can't return an error, so just log it, and prefer `socket` over `vnl`
logrus.Errorf("Network %q has both vnl=%q and socket=%q fields; ignoring vnl",
nw.Interface, nw.VNLDeprecated, nw.Socket)
}
networks[i].Socket = nw.Socket
networks[i].VNLDeprecated = ""
networks[i].SwitchPortDeprecated = 0
networks[i].Lima = ""
}
if nw.Lima != "" {
if nw.VNLDeprecated != "" {
// We can't return an error, so just log it, and prefer `lima` over `vnl`
logrus.Errorf("Network %q has both vnl=%q and lima=%q fields; ignoring vnl",
nw.Interface, nw.VNLDeprecated, nw.Lima)
}
if nw.Socket != "" {
// We can't return an error, so just log it, and prefer `lima` over `socket`
logrus.Errorf("Network %q has both socket=%q and lima=%q fields; ignoring socket",
nw.Interface, nw.Socket, nw.Lima)
}
networks[i].Lima = nw.Lima
networks[i].Socket = ""
networks[i].VNLDeprecated = ""
networks[i].SwitchPortDeprecated = 0
}
if nw.MACAddress != "" {
networks[i].MACAddress = nw.MACAddress
Expand Down
8 changes: 2 additions & 6 deletions pkg/limayaml/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,8 @@ func TestFillDefault(t *testing.T) {
},
Networks: []Network{
{
VNLDeprecated: "/tmp/vde.ctl",
SwitchPortDeprecated: 65535,
MACAddress: "11:22:33:44:55:66",
Interface: "def0",
MACAddress: "11:22:33:44:55:66",
Interface: "def0",
},
},
DNS: []net.IP{
Expand Down Expand Up @@ -645,8 +643,6 @@ func TestFillDefault(t *testing.T) {
// o.Networks[1] is overriding the d.Networks[0].Lima entry for the "def0" interface
expect.Networks = append(append(d.Networks, y.Networks...), o.Networks[0])
expect.Networks[0].Lima = o.Networks[1].Lima
expect.Networks[0].VNLDeprecated = ""
expect.Networks[0].SwitchPortDeprecated = 0

// Only highest prio DNS are retained
expect.DNS = o.DNS
Expand Down
23 changes: 3 additions & 20 deletions pkg/limayaml/limayaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,15 @@ type CopyToHost struct {
}

type Network struct {
// `Lima`, `Socket`, and `VNL` are mutually exclusive; exactly one is required
// `Lima` and `Socket` are mutually exclusive; exactly one is required
Lima string `yaml:"lima,omitempty" json:"lima,omitempty"`
// Socket is a QEMU-compatible socket
Socket string `yaml:"socket,omitempty" json:"socket,omitempty"`
// VZNAT uses VZNATNetworkDeviceAttachment. Needs VZ. No root privilege is required.
VZNAT *bool `yaml:"vzNAT,omitempty" json:"vzNAT,omitempty"`

// VNLDeprecated is a Virtual Network Locator (https://github.com/rd235/vdeplug4/commit/089984200f447abb0e825eb45548b781ba1ebccd).
// On macOS, only VDE2-compatible form (optionally with vde:// prefix) is supported.
// VNLDeprecated is deprecated. Use Socket.
VNLDeprecated string `yaml:"vnl,omitempty" json:"vnl,omitempty"`
SwitchPortDeprecated uint16 `yaml:"switchPort,omitempty" json:"switchPort,omitempty"` // VDE Switch port, not TCP/UDP port (only used by VDE networking)
MACAddress string `yaml:"macAddress,omitempty" json:"macAddress,omitempty"`
Interface string `yaml:"interface,omitempty" json:"interface,omitempty"`
MACAddress string `yaml:"macAddress,omitempty" json:"macAddress,omitempty"`
Interface string `yaml:"interface,omitempty" json:"interface,omitempty"`
}

type HostResolver struct {
Expand All @@ -260,15 +255,3 @@ type CACertificates struct {
Files []string `yaml:"files,omitempty" json:"files,omitempty"`
Certs []string `yaml:"certs,omitempty" json:"certs,omitempty"`
}

// DEPRECATED types below

// Types have been renamed to turn all references to the old names into compiler errors,
// and to avoid accidental usage in new code.

type VDEDeprecated struct {
VNL string `yaml:"vnl,omitempty" json:"vnl,omitempty"`
SwitchPort uint16 `yaml:"switchPort,omitempty" json:"switchPort,omitempty"` // VDE Switch port, not TCP/UDP port
MACAddress string `yaml:"macAddress,omitempty" json:"macAddress,omitempty"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
}
64 changes: 3 additions & 61 deletions pkg/limayaml/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func Validate(y LimaYAML, warn bool) error {
return fmt.Errorf("field `dns` must be empty when field `HostResolver.Enabled` is true")
}

if err := validateNetwork(y, warn); err != nil {
if err := validateNetwork(y); err != nil {
return err
}
if warn {
Expand All @@ -309,7 +309,7 @@ func Validate(y LimaYAML, warn bool) error {
return nil
}

func validateNetwork(y LimaYAML, warn bool) error {
func validateNetwork(y LimaYAML) error {
interfaceName := make(map[string]int)
for i, nw := range y.Networks {
field := fmt.Sprintf("networks[%d]", i)
Expand All @@ -334,22 +334,10 @@ func validateNetwork(y LimaYAML, warn bool) error {
if nw.VZNAT != nil && *nw.VZNAT {
return fmt.Errorf("field `%s.lima` and field `%s.vzNAT` are mutually exclusive", field, field)
}
if nw.VNLDeprecated != "" {
return fmt.Errorf("field `%s.lima` and field `%s.vnl` are mutually exclusive", field, field)
}
if nw.SwitchPortDeprecated != 0 {
return fmt.Errorf("field `%s.switchPort` cannot be used with field `%s.lima`", field, field)
}
} else if nw.Socket != "" {
if nw.VZNAT != nil && *nw.VZNAT {
return fmt.Errorf("field `%s.socket` and field `%s.vzNAT` are mutually exclusive", field, field)
}
if nw.VNLDeprecated != "" {
return fmt.Errorf("field `%s.socket` and field `%s.vnl` are mutually exclusive", field, field)
}
if nw.SwitchPortDeprecated != 0 {
return fmt.Errorf("field `%s.switchPort` cannot be used with field `%s.socket`", field, field)
}
if fi, err := os.Stat(nw.Socket); err != nil && !errors.Is(err, os.ErrNotExist) {
return err
} else if err == nil && fi.Mode()&os.ModeSocket == 0 {
Expand All @@ -365,54 +353,8 @@ func validateNetwork(y LimaYAML, warn bool) error {
if nw.Socket != "" {
return fmt.Errorf("field `%s.vzNAT` and field `%s.socket` are mutually exclusive", field, field)
}
if nw.VNLDeprecated != "" {
return fmt.Errorf("field `%s.vzNAT` and field `%s.vnl` are mutually exclusive", field, field)
}
if nw.SwitchPortDeprecated != 0 {
return fmt.Errorf("field `%s.switchPort` cannot be used with field `%s.vzNAT`", field, field)
}
} else {
if nw.VNLDeprecated == "" {
return fmt.Errorf("field `%s.lima`, field `%s.socket`, or field `%s.vnl` must be set", field, field, field)
}
// The field is called VDE.VNL in anticipation of QEMU upgrading VDE2 to VDEplug4,
// but right now the only valid value on macOS is a path to the vde_switch socket directory,
// optionally with vde:// prefix.
if !strings.Contains(nw.VNLDeprecated, "://") || strings.HasPrefix(nw.VNLDeprecated, "vde://") {
vdeSwitch := strings.TrimPrefix(nw.VNLDeprecated, "vde://")
if fi, err := os.Stat(vdeSwitch); err != nil {
// negligible when the instance is stopped
logrus.WithError(err).Debugf("field `%s.vnl` %q failed stat", field, vdeSwitch)
} else {
if fi.IsDir() {
/* Switch mode (vdeSwitch is dir, port != 65535) */
ctlSocket := filepath.Join(vdeSwitch, "ctl")
// ErrNotExist during os.Stat(ctlSocket) can be ignored. ctlSocket does not need to exist until actually starting the VM
if fi, err = os.Stat(ctlSocket); err == nil {
if fi.Mode()&os.ModeSocket == 0 {
return fmt.Errorf("field `%s.vnl` file %q is not a UNIX socket", field, ctlSocket)
}
}
if nw.SwitchPortDeprecated == 65535 {
return fmt.Errorf("field `%s.vnl` points to a non-PTP switch, so the port number must not be 65535", field)
}
} else {
/* PTP mode (vdeSwitch is socket, port == 65535) */
if fi.Mode()&os.ModeSocket == 0 {
return fmt.Errorf("field `%s.vnl` %q is not a directory nor a UNIX socket", field, vdeSwitch)
}
if nw.SwitchPortDeprecated != 65535 {
return fmt.Errorf("field `%s.vnl` points to a PTP (switchless) socket %q, so the port number has to be 65535 (got %d)",
field, vdeSwitch, nw.SwitchPortDeprecated)
}
}
}
} else if runtime.GOOS != "linux" {
if warn {
logrus.Warnf("field `%s.vnl` is unlikely to work for %s (unless libvdeplug4 has been ported to %s and is installed)",
field, runtime.GOOS, runtime.GOOS)
}
}
return fmt.Errorf("field `%s.lima` or field `%s.socket must be set", field, field)
}
if nw.MACAddress != "" {
hw, err := net.ParseMAC(nw.MACAddress)
Expand Down
56 changes: 7 additions & 49 deletions pkg/networks/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import (
"io/fs"
"os/exec"
"path/filepath"
"strings"

"github.com/lima-vm/lima/pkg/osutil"
"github.com/lima-vm/lima/pkg/store/dirnames"
)

const (
VDESwitch = "vde_switch" // Deprecated
VDEVMNet = "vde_vmnet" // Deprecated
SocketVMNet = "socket_vmnet"
)

Expand All @@ -39,10 +36,6 @@ func (config *YAML) Usernet(name string) (bool, error) {
// DaemonPath returns the daemon path.
func (config *YAML) DaemonPath(daemon string) (string, error) {
switch daemon {
case VDESwitch:
return config.Paths.VDESwitch, nil
case VDEVMNet:
return config.Paths.VDEVMNet, nil
case SocketVMNet:
return config.Paths.SocketVMNet, nil
default:
Expand Down Expand Up @@ -73,40 +66,23 @@ func (config *YAML) Sock(name string) string {
return filepath.Join(config.Paths.VarRun, fmt.Sprintf("socket_vmnet.%s", name))
}

// VDESock returns a vde socket.
//
// Deprecated: Use Sock.
func (config *YAML) VDESock(name string) string {
return filepath.Join(config.Paths.VarRun, fmt.Sprintf("%s.ctl", name))
}

func (config *YAML) PIDFile(name, daemon string) string {
daemonTrimmed := strings.TrimPrefix(daemon, "vde_") // for compatibility
return filepath.Join(config.Paths.VarRun, fmt.Sprintf("%s_%s.pid", name, daemonTrimmed))
return filepath.Join(config.Paths.VarRun, fmt.Sprintf("%s_%s.pid", name, daemon))
}

func (config *YAML) LogFile(name, daemon, stream string) string {
networksDir, _ := dirnames.LimaNetworksDir()
daemonTrimmed := strings.TrimPrefix(daemon, "vde_") // for compatibility
return filepath.Join(networksDir, fmt.Sprintf("%s_%s.%s.log", name, daemonTrimmed, stream))
return filepath.Join(networksDir, fmt.Sprintf("%s_%s.%s.log", name, daemon, stream))
}

func (config *YAML) User(daemon string) (osutil.User, error) {
if ok, _ := config.IsDaemonInstalled(daemon); !ok {
daemonPath, _ := config.DaemonPath(daemon)
return osutil.User{}, fmt.Errorf("daemon %q (path=%q) is not available", daemon, daemonPath)
}
//nolint:gocritic // singleCaseSwitch: should rewrite switch statement to if statement
switch daemon {
case VDESwitch:
user, err := osutil.LookupUser("daemon")
if err != nil {
return user, err
}
group, err := osutil.LookupGroup(config.Group)
user.Group = group.Name
user.Gid = group.Gid
return user, err
case VDEVMNet, SocketVMNet:
case SocketVMNet:
return osutil.LookupUser("root")
}
return osutil.User{}, fmt.Errorf("daemon %q not defined", daemon)
Expand All @@ -121,28 +97,8 @@ func (config *YAML) StartCmd(name, daemon string) string {
panic(fmt.Errorf("daemon %q is not available", daemon))
}
var cmd string
//nolint:gocritic // singleCaseSwitch: should rewrite switch statement to if statement

Check failure on line 100 in pkg/networks/commands.go

View workflow job for this annotation

GitHub Actions / Lints

directive `//nolint:gocritic // singleCaseSwitch: should rewrite switch statement to if statement` is unused for linter "gocritic" (nolintlint)
switch daemon {
case VDESwitch:
if config.Paths.VDESwitch == "" {
panic("config.Paths.VDESwitch is empty")
}
cmd = fmt.Sprintf("%s --pidfile=%s --sock=%s --group=%s --dirmode=0770 --nostdin",
config.Paths.VDESwitch, config.PIDFile(name, VDESwitch), config.VDESock(name), config.Group)
case VDEVMNet:
nw := config.Networks[name]
if config.Paths.VDEVMNet == "" {
panic("config.Paths.VDEVMNet is empty")
}
cmd = fmt.Sprintf("%s --pidfile=%s --vde-group=%s --vmnet-mode=%s",
config.Paths.VDEVMNet, config.PIDFile(name, VDEVMNet), config.Group, nw.Mode)
switch nw.Mode {
case ModeBridged:
cmd += fmt.Sprintf(" --vmnet-interface=%s", nw.Interface)
case ModeHost, ModeShared:
cmd += fmt.Sprintf(" --vmnet-gateway=%s --vmnet-dhcp-end=%s --vmnet-mask=%s",
nw.Gateway, nw.DHCPEnd, nw.NetMask)
}
cmd += " " + config.VDESock(name)
case SocketVMNet:
nw := config.Networks[name]
if config.Paths.SocketVMNet == "" {
Expand All @@ -158,6 +114,8 @@ func (config *YAML) StartCmd(name, daemon string) string {
nw.Gateway, nw.DHCPEnd, nw.NetMask)
}
cmd += " " + config.Sock(name)
default:
panic(fmt.Errorf("unexpected daemon %q", daemon))
}
return cmd
}
Expand Down
8 changes: 0 additions & 8 deletions pkg/networks/commands_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ func TestSock(t *testing.T) {
assert.Equal(t, sock, "/private/var/run/lima/socket_vmnet.foo")
}

func TestVDESock(t *testing.T) {
config, err := DefaultConfig()
assert.NilError(t, err)

vdeSock := config.VDESock("foo")
assert.Equal(t, vdeSock, "/private/var/run/lima/foo.ctl")
}

func TestPIDFile(t *testing.T) {
config, err := DefaultConfig()
assert.NilError(t, err)
Expand Down
Loading

0 comments on commit 7b52030

Please sign in to comment.