Skip to content

Commit 32db394

Browse files
authored
Merge pull request #851 from AkihiroSuda/socket_vmnet
vmnet: Support socket_vmnet; deprecate vde_vmnet
2 parents 80e2f86 + b5e0d5a commit 32db394

File tree

21 files changed

+567
-154
lines changed

21 files changed

+567
-154
lines changed

.github/workflows/test.yml

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,6 @@ jobs:
105105
time brew update
106106
time brew install qemu bash coreutils curl jq
107107
time brew upgrade
108-
- name: Install vde_switch and vde_vmnet
109-
env:
110-
VDE_VMNET_VERSION: v0.6.0
111-
run: |
112-
(
113-
brew install autoconf automake
114-
cd ~
115-
git clone https://github.com/lima-vm/vde_vmnet
116-
cd vde_vmnet
117-
git checkout $VDE_VMNET_VERSION
118-
sudo git config --global --add safe.directory /Users/runner/vde_vmnet
119-
sudo make PREFIX=/opt/vde install
120-
)
121-
(
122-
limactl sudoers | sudo tee /etc/sudoers.d/lima
123-
)
124108
- name: Cache ~/Library/Caches/lima/download
125109
uses: actions/cache@v3
126110
with:
@@ -147,15 +131,78 @@ jobs:
147131
retry_on: error
148132
max_attempts: 3
149133
command: ./hack/test-example.sh examples/experimental/9p.yaml
150-
- name: "Test vmnet.yaml"
134+
# GHA macOS is slow and flaky, so we only test a few YAMLS here.
135+
# Other yamls are tested on Linux instances of Cirrus.
136+
137+
vmnet:
138+
name: "VMNet test"
139+
runs-on: macos-11
140+
timeout-minutes: 120
141+
steps:
142+
- uses: actions/setup-go@v3
143+
with:
144+
go-version: 1.19.x
145+
- uses: actions/checkout@v3
146+
with:
147+
fetch-depth: 1
148+
- name: Make
149+
run: make
150+
- name: Install
151+
run: make install
152+
- name: Install test dependencies
153+
run: brew install qemu bash coreutils iperf3
154+
- name: Cache ~/Library/Caches/lima/download
155+
uses: actions/cache@v3
156+
with:
157+
path: ~/Library/Caches/lima/download
158+
key: ${{ runner.os }}-vmnet
159+
- name: Install vde_switch and vde_vmnet (Deprecated)
160+
env:
161+
VDE_VMNET_VERSION: v0.6.0
162+
run: |
163+
(
164+
brew install autoconf automake
165+
cd ~
166+
git clone https://github.com/lima-vm/vde_vmnet
167+
cd vde_vmnet
168+
git checkout $VDE_VMNET_VERSION
169+
sudo git config --global --add safe.directory /Users/runner/vde_vmnet
170+
sudo make PREFIX=/opt/vde install
171+
)
172+
limactl sudoers | sudo tee /etc/sudoers.d/lima
173+
- name: Unit test (pkg/networks) with vde_vmnet (Deprecated)
174+
# Set -count=1 to disable cache
175+
run: go test -v -count=1 ./pkg/networks/...
176+
- name: Test vde_vmnet (Deprecated)
177+
uses: nick-invision/retry@v2
178+
with:
179+
timeout_minutes: 30
180+
retry_on: error
181+
max_attempts: 3
182+
command: ./hack/test-example.sh examples/vmnet.yaml
183+
- name: Install socket_vmnet
184+
env:
185+
SOCKET_VMNET_VERSION: v1.0.0-alpha.0
186+
run: |
187+
(
188+
cd ~
189+
git clone https://github.com/lima-vm/socket_vmnet
190+
cd socket_vmnet
191+
git checkout $SOCKET_VMNET_VERSION
192+
sudo git config --global --add safe.directory /Users/runner/socket_vmnet
193+
sudo make PREFIX=/opt/socket_vmnet install
194+
)
195+
limactl sudoers | sudo tee /etc/sudoers.d/lima
196+
- name: Unit test (pkg/networks) with socket_vmnet
197+
# Set -count=1 to disable cache
198+
run: go test -v -count=1 ./pkg/networks/...
199+
- name: Test socket_vmnet
151200
uses: nick-invision/retry@v2
152201
with:
153202
timeout_minutes: 30
154203
retry_on: error
155204
max_attempts: 3
156205
command: ./hack/test-example.sh examples/vmnet.yaml
157-
# GHA macOS is slow and flaky, so we only test a few YAMLS here.
158-
# Other yamls are tested on Linux instances of Cirrus.
159206

160207
upgrade:
161208
name: "Upgrade test"

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ The `copy` command only works for instances that have been created by lima 0.5.0
435435

436436
The default guest IP 192.168.5.15 is not accessible from the host and other guests.
437437

438-
To add another IP address that is accessible from the host and other virtual machines, enable [`vde_vmnet`](https://github.com/lima-vm/vde_vmnet).
438+
To add another IP address that is accessible from the host and other virtual machines, enable [`socket_vmnet`](https://github.com/lima-vm/socket_vmnet) (since Lima v0.12)
439+
or [`vde_vmnet`](https://github.com/lima-vm/vde_vmnet) (Deprecated).
439440

440441
See [`./docs/network.md`](./docs/network.md).
441442

docs/network.md

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The guest IP address is set to `192.168.5.15`.
1010

1111
This IP address is not accessible from the host by design.
1212

13-
Use [vde_vmnet](https://github.com/lima-vm/vde_vmnet) to allow accessing the guest IP from the host and other guests.
13+
Use VMNet (see below) to allow accessing the guest IP from the host and other guests.
1414

1515
### Host IP (192.168.5.2)
1616

@@ -42,50 +42,32 @@ During initial cloud-init bootstrap, `iptables` may not yet be installed. In tha
4242

4343
If `useHostResolver` 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).
4444

45-
## `vde_vmnet` (192.168.105.0/24)
45+
## Managed VMNet networks (192.168.105.0/24)
4646

47-
[`vde_vmnet`](https://github.com/lima-vm/vde_vmnet) is required for adding another guest IP that is accessible from
48-
the host and other guests.
49-
50-
To enable `vde_vmnet` (in addition the user-mode network), add the following lines to the YAML after installing `vde_vmnet`.
51-
52-
```yaml
53-
networks:
54-
# vnl (virtual network locator) points to the vde_switch socket directory,
55-
# optionally with vde:// prefix
56-
# - vnl: "vde:///var/run/vde.ctl"
57-
# # VDE Switch port number (not TCP/UDP port number). Set to 65535 for PTP mode.
58-
# # Default: 0
59-
# switchPort: 0
60-
# # MAC address of the instance; lima will pick one based on the instance name,
61-
# # so DHCP assigned ip addresses should remain constant over instance restarts.
62-
# macAddress: ""
63-
# # Interface name, defaults to "lima0", "lima1", etc.
64-
# interface: ""
65-
```
66-
67-
The IP address range is typically `192.168.105.0/24`, but depends on the configuration of `vde_vmnet`.
68-
See [the documentation of `vde_vmnet`](https://github.com/lima-vm/vde_vmnet) for further information.
69-
70-
## Managed VMNet networks (via vde_vmnet)
47+
Either [`socket_vmnet`](https://github.com/lima-vm/socket_vmnet) (since Lima v0.12) or [`vde_vmnet`](https://github.com/lima-vm/vde_vmnet) (Deprecated)
48+
is required for adding another guest IP that is accessible from the host and other guests.
7149

7250
Starting with version v0.7.0 lima can manage the networking daemons automatically. Networks are defined in
7351
`$LIMA_HOME/_config/networks.yaml`. If this file doesn't already exist, it will be created with these default
7452
settings:
7553

7654
```yaml
77-
# Paths to vde executables. Because vde_vmnet is invoked via sudo it should be
55+
# Path to socket_vmnet executable. Because socket_vmnet is invoked via sudo it should be
7856
# installed where only root can modify/replace it. This means also none of the
7957
# parent directories should be writable by the user.
8058
#
8159
# The varRun directory also must not be writable by the user because it will
82-
# include the vde_vmnet pid files. Those will be terminated via sudo, so replacing
83-
# the pid files would allow killing of arbitrary privileged processes. varRun
60+
# include the socket_vmnet pid file. Those will be terminated via sudo, so replacing
61+
# the pid file would allow killing of arbitrary privileged processes. varRun
8462
# however MUST be writable by the daemon user.
8563
#
8664
# None of the paths segments may be symlinks, why it has to be /private/var
8765
# instead of /var etc.
8866
paths:
67+
# socketVMNet requires Lima >= 0.12 .
68+
# socketVMNet has precedence over vdeVMNet.
69+
socketVMNet: /opt/socket_vmnet/bin/socket_vmnet
70+
# vdeSwitch and vdeVMNet are DEPRECATED.
8971
vdeSwitch: /opt/vde/bin/vde_switch
9072
vdeVMNet: /opt/vde/bin/vde_vmnet
9173
varRun: /private/var/run/lima
@@ -115,8 +97,9 @@ Instances can then reference these networks from their `lima.yaml` file:
11597
```yaml
11698
networks:
11799
# Lima can manage daemons for networks defined in $LIMA_HOME/_config/networks.yaml
118-
# automatically. Both vde_switch and vde_vmnet binaries must be installed into
100+
# automatically. The socket_vmnet must be installed into
119101
# secure locations only alterable by the "root" user.
102+
# The same applies to vde_switch and vde_vmnet for the deprecated VDE mode.
120103
# - lima: shared
121104
# # MAC address of the instance; lima will pick one based on the instance name,
122105
# # so DHCP assigned ip addresses should remain constant over instance restarts.
@@ -129,10 +112,38 @@ The network daemons are started automatically when the first instance referencin
129112
and will stop automatically once the last instance has stopped. Daemon logs will be stored in the
130113
`$LIMA_HOME/_networks` directory.
131114

132-
Since the commands to start and stop the `vde_vmnet` daemon requires root, the user either must
115+
Since the commands to start and stop the `socket_vmnet` daemon (or the `vde_vmnet` daemon) requires root, the user either must
133116
have password-less `sudo` enabled, or add the required commands to a `sudoers` file. This can
134117
be done via:
135118

136119
```shell
137120
limactl sudoers | sudo tee /etc/sudoers.d/lima
138121
```
122+
123+
## Unmanaged VMNet networks
124+
For Lima >= 0.12:
125+
```yaml
126+
networks:
127+
# Lima can also connect to "unmanaged" networks addressed by "socket". This
128+
# means that the daemons will not be controlled by Lima, but must be started
129+
# before the instance. The interface type (host, shared, or bridged) is
130+
# configured in socket_vmnet and not in lima.
131+
# - socket: "/var/run/socket_vmnet"
132+
```
133+
134+
For older Lima releases:
135+
```yaml
136+
networks:
137+
# vnl (virtual network locator) points to the vde_switch socket directory,
138+
# optionally with vde:// prefix
139+
# ⚠️ vnl is deprecated, use socket.
140+
# - vnl: "vde:///var/run/vde.ctl"
141+
# # VDE Switch port number (not TCP/UDP port number). Set to 65535 for PTP mode.
142+
# # Builtin default: 0
143+
# switchPort: 0
144+
# # MAC address of the instance; lima will pick one based on the instance name,
145+
# # so DHCP assigned ip addresses should remain constant over instance restarts.
146+
# macAddress: ""
147+
# # Interface name, defaults to "lima0", "lima1", etc.
148+
# interface: ""
149+
```

examples/default.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,25 +217,29 @@ video:
217217
display: null
218218

219219
# The instance can get routable IP addresses from the vmnet framework using
220-
# https://github.com/lima-vm/vde_vmnet.
220+
# https://github.com/lima-vm/socket_vmnet.
221221
# 🟢 Builtin default: null
222222
networks:
223223
# Lima can manage daemons for networks defined in $LIMA_HOME/_config/networks.yaml
224-
# automatically. Both vde_switch and vde_vmnet binaries must be installed into
224+
# automatically. The socket_vmnet binary must be installed into
225225
# secure locations only alterable by the "root" user.
226+
# The same applies to vde_switch and vde_vmnet for the deprecated VDE mode.
226227
# - lima: shared
227228
# # MAC address of the instance; lima will pick one based on the instance name,
228229
# # so DHCP assigned ip addresses should remain constant over instance restarts.
229230
# macAddress: ""
230231
# # Interface name, defaults to "lima0", "lima1", etc.
231232
# interface: ""
232233
#
233-
# Lima can also connect to "unmanaged" vde networks addressed by "vnl". This
234+
# Lima can also connect to "unmanaged" networks addressed by "socket". This
234235
# means that the daemons will not be controlled by Lima, but must be started
235236
# before the instance. The interface type (host, shared, or bridged) is
236-
# configured in vde_vmnet and not in lima.
237+
# configured in socket_vmnet and not in lima.
238+
# - socket: "/var/run/socket_vmnet"
239+
237240
# vnl (virtual network locator) points to the vde_switch socket directory,
238241
# optionally with vde:// prefix
242+
# ⚠️ vnl is deprecated, use socket.
239243
# - vnl: "vde:///var/run/vde.ctl"
240244
# # VDE Switch port number (not TCP/UDP port number). Set to 65535 for PTP mode.
241245
# # Builtin default: 0

examples/vmnet.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ mounts:
2121
writable: true
2222
networks:
2323
# The instance can get routable IP addresses from the vmnet framework using
24-
# https://github.com/lima-vm/vde_vmnet. Available networks are defined in
24+
# https://github.com/lima-vm/socket_vmnet (since Lima v0.12) or
25+
# https://github.com/lima-vm/vde_vmnet (deprecated) .
26+
#
27+
# Available networks are defined in
2528
# $LIMA_HOME/_config/networks.yaml. Supported network types are "host",
2629
# "shared", or "bridged".
30+
#
31+
# Interface "lima0": shared mode (IP is assigned by macOS's bootpd)
2732
- lima: shared
33+
# Interface "lima1": bridged mode (IP is assigned by a DHCP server on the physical network)
34+
# - lima: bridged

hack/test-example.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ declare -A CHECKS=(
2323
["containerd-user"]="1"
2424
["restart"]="1"
2525
["port-forwards"]="1"
26+
["vmnet"]=""
2627
)
2728

2829
case "$NAME" in
@@ -41,6 +42,9 @@ case "$NAME" in
4142
# ● run-r2b459797f5b04262bfa79984077a65c7.service loaded failed failed /usr/bin/systemctl start man-db-cache-update
4243
CHECKS["systemd-strict"]=
4344
;;
45+
"vmnet")
46+
CHECKS["vmnet"]=1
47+
;;
4448
esac
4549

4650
if limactl ls -q | grep -q "$NAME"; then
@@ -217,6 +221,22 @@ if [[ -n ${CHECKS["port-forwards"]} ]]; then
217221
set +x
218222
fi
219223

224+
if [[ -n ${CHECKS["vmnet"]} ]]; then
225+
INFO "Testing vmnet functionality"
226+
guestip="$(limactl shell "$NAME" ip -4 -j addr show dev lima0 | jq -r '.[0].addr_info[0].local')"
227+
INFO "Pinging the guest IP ${guestip}"
228+
set -x
229+
ping -c 3 "$guestip"
230+
set +x
231+
INFO "Benchmarking with iperf3"
232+
set -x
233+
limactl shell "$NAME" sudo apt-get install -y iperf3
234+
limactl shell "$NAME" iperf3 -s -1 -D
235+
iperf3 -c "$guestip"
236+
set +x
237+
# NOTE: we only test the shared interface here, as the bridged interface cannot be used on GHA (and systemd-networkd-wait-online.service will fail)
238+
fi
239+
220240
if [[ -n ${CHECKS["restart"]} ]]; then
221241
INFO "Create file in the guest home directory and verify that it still exists after a restart"
222242
# shellcheck disable=SC2016

0 commit comments

Comments
 (0)