Skip to content

Commit de30a2e

Browse files
committed
vde: support PTP (switchless) socket
See https://github.com/lima-vm/vde_vmnet/tree/v0.4.0#ptp-mode-switchless-mode Signed-off-by: Akihiro Suda <[email protected]>
1 parent 89ec95b commit de30a2e

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

pkg/limayaml/default.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ network:
127127
vde:
128128
# url points to the vde_switch socket directory, optionally with vde:// prefix
129129
# - url: "vde:///var/run/vde.ctl"
130+
# # VDE Switch port number (not TCP/UDP port number). Set to 65535 for PTP mode.
131+
# # Default: 0
132+
# switchPort: 0
130133
# # MAC address of the instance; lima will pick one based on the instance name,
131134
# # so DHCP assigned ip addresses should remain constant over instance restarts.
132135
# macAddress: ""

pkg/limayaml/limayaml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ type Network struct {
112112
}
113113
type VDE struct {
114114
URL string `yaml:"url,omitempty"`
115+
SwitchPort uint16 `yaml:"switchPort,omitempty"` // VDE Switch port, not TCP/UDP port
115116
MACAddress string `yaml:"macAddress,omitempty"`
116117
Name string `yaml:"name,omitempty"`
117118
}

pkg/limayaml/validate.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,28 @@ func validateNetwork(yNetwork Network) error {
186186
if err != nil {
187187
return errors.Wrapf(err, "field `%s.url` %q failed stat", field, vdeSwitch)
188188
}
189-
if !fi.IsDir() {
190-
return errors.Wrapf(err, "field `%s.url` %q is not a directory", field, vdeSwitch)
191-
}
192-
ctlSocket := filepath.Join(vdeSwitch, "ctl")
193-
fi, err = os.Stat(ctlSocket)
194-
if err != nil {
195-
return errors.Wrapf(err, "field `%s.url` control socket %q failed stat", field, ctlSocket)
196-
}
197-
if fi.Mode()&os.ModeSocket == 0 {
198-
return errors.Errorf("field `%s.url` file %q is not a UNIX socket", field, ctlSocket)
189+
if fi.IsDir() {
190+
/* Switch mode (vdeSwitch is dir, port != 65535) */
191+
ctlSocket := filepath.Join(vdeSwitch, "ctl")
192+
fi, err = os.Stat(ctlSocket)
193+
if err != nil {
194+
return errors.Wrapf(err, "field `%s.url` control socket %q failed stat", field, ctlSocket)
195+
}
196+
if fi.Mode()&os.ModeSocket == 0 {
197+
return errors.Errorf("field `%s.url` file %q is not a UNIX socket", field, ctlSocket)
198+
}
199+
if vde.SwitchPort == 65535 {
200+
return errors.Errorf("field `%s.url` points to a non-PTP switch, so the port number must not be 65535", field)
201+
}
202+
} else {
203+
/* PTP mode (vdeSwitch is socket, port == 65535) */
204+
if fi.Mode()&os.ModeSocket == 0 {
205+
return errors.Errorf("field `%s.url` %q is not a directory nor a UNIX socket", field, vdeSwitch)
206+
}
207+
if vde.SwitchPort != 65535 {
208+
return errors.Errorf("field `%s.url` points to a PTP (switchless) socket %q, so the port number has to be 65535 (got %d)",
209+
field, vdeSwitch, vde.SwitchPort)
210+
}
199211
}
200212
} else if runtime.GOOS != "linux" {
201213
logrus.Warnf("field `%s.url` is unlikely to work for %s (unless libvdeplug4 has been ported to %s and is installed)",

0 commit comments

Comments
 (0)