Skip to content

Commit 874786d

Browse files
authored
Merge pull request #139 from AkihiroSuda/dev-machineid
Put machineID to the MAC address hasher + update docs + misc
2 parents fbb94ed + 5e19bb8 commit 874786d

File tree

12 files changed

+370
-82
lines changed

12 files changed

+370
-82
lines changed

.github/workflows/test.yml

+14-4
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ jobs:
7070
run: make
7171
- name: Install
7272
run: sudo make install
73-
- name: Validate examples
74-
run: limactl validate ./examples/*.yaml
73+
- name: Validate examples (except vmnet.yaml)
74+
run: find examples -name '*.yaml' | grep -v 'vmnet.yaml' | xargs limactl validate
7575
- name: Uninstall
7676
run: sudo make uninstall
7777

@@ -81,9 +81,9 @@ jobs:
8181
timeout-minutes: 40
8282
strategy:
8383
matrix:
84-
# GHA macOS is slow and flaky, so we only test "default.yaml" here.
84+
# GHA macOS is slow and flaky, so we only test a few YAMLS here.
8585
# Other yamls are tested on Linux instances of Cirrus.
86-
example: [default.yaml]
86+
example: [default.yaml, vmnet.yaml]
8787
steps:
8888
- uses: actions/setup-go@v2
8989
with:
@@ -100,6 +100,16 @@ jobs:
100100
# bash: required by test-example.sh (OS version of bash is too old)
101101
# coreutils: required by test-example.sh for the "timeout" command
102102
run: brew install qemu bash coreutils
103+
- name: Install vde_vmnet
104+
if: matrix.example == 'vmnet.yaml'
105+
env:
106+
VDE_VMNET_VERSION: v0.4.0
107+
run: |
108+
git clone https://github.com/lima-vm/vde_vmnet
109+
cd vde_vmnet
110+
git checkout $VDE_VMNET_VERSION
111+
make
112+
sudo make install
103113
- name: Prepare ssh
104114
run: |
105115
if [ -e ~/.ssh/id_rsa ]; then

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ The current default spec:
202202
- ["Port forwarding does not work"](#port-forwarding-does-not-work)
203203
- [stuck on "Waiting for the essential requirement 1 of X: "ssh"](#stuck-on-waiting-for-the-essential-requirement-1-of-x-ssh)
204204
- ["permission denied" for `limactl cp` command](#permission-denied-for-limactl-cp-command)
205+
- [Networking](#networking)
206+
- ["Cannot access the guest IP 192.168.5.15 from the host"](#cannot-access-the-guest-ip-192168515-from-the-host)
205207
- ["Hints for debugging other problems?"](#hints-for-debugging-other-problems)
206208

207209
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -304,6 +306,15 @@ The `copy` command only works for instances that have been created by lima 0.5.0
304306
< ~/.lima/_config/user.pub limactl shell INSTANCE sh -c 'tee -a ~/.ssh/authorized_keys'
305307
```
306308

309+
### Networking
310+
#### "Cannot access the guest IP 192.168.5.15 from the host"
311+
312+
The default guest IP 192.168.5.15 is not accessible from the host and other guests.
313+
314+
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).
315+
316+
See [`./docs/network.md`](./docs/network.md).
317+
307318
### "Hints for debugging other problems?"
308319
- Inspect logs:
309320
- `limactl --debug start`

docs/internal.md

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ The directory contains the following files:
8585

8686
- `user-data`: [Cloud-init user-data](https://cloudinit.readthedocs.io/en/latest/topics/format.html)
8787
- `meta-data`: [Cloud-init meta-data](https://cloudinit.readthedocs.io/en/latest/topics/instancedata.html)
88+
- `network-config`: [Cloud-init Networking Config Version 2](https://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v2.html)
8889
- `lima.env`: the environment variables
8990
- `lima-guestagent`: Lima guest agent binary
9091
- `nerdctl-full.tgz`: [`nerdctl-full-<VERSION>-linux-<ARCH>.tar.gz`](https://github.com/containerd/nerdctl/releases)

docs/network.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Network
2+
3+
## user-mode network (192.168.5.0/24)
4+
5+
By default Lima only enables the user-mode networking aka "slirp".
6+
7+
### Guest IP (192.168.5.15)
8+
9+
The guest IP address is typically set to 192.168.5.15.
10+
11+
This IP address is not accessible from the host by design.
12+
13+
Use `vde_vmnet` to allow accessing the guest IP from the host and other guests.
14+
15+
### Host IP (192.168.5.2)
16+
17+
The loopback addresses of the host is accessible from the guest as 192.168.5.2.
18+
19+
### DNS (192.168.5.3)
20+
21+
The DNS.
22+
23+
## `vde_vmnet` (192.168.105.0/24)
24+
25+
[`vde_vmnet`](https://github.com/lima-vm/vde_vmnet) is required for adding another guest IP that is accessible from
26+
the host and other guests.
27+
28+
To enable `vde_vmnet` (in addition the user-mode network), add the following lines to the YAML after installing `vde_vmnet`.
29+
30+
```yaml
31+
network:
32+
# The instance can get routable IP addresses from the vmnet framework using
33+
# https://github.com/lima-vm/vde_vmnet. Both vde_switch and vde_vmnet
34+
# daemons must be running before the instance is started. The interface type
35+
# (host, shared, or bridged) is configured in vde_vmnet and not lima.
36+
vde:
37+
# vnl (virtual network locator) points to the vde_switch socket directory,
38+
# optionally with vde:// prefix
39+
- vnl: "vde:///var/run/vde.ctl"
40+
# MAC address of the instance; lima will pick one based on the instance name,
41+
# so DHCP assigned ip addresses should remain constant over instance restarts.
42+
macAddress: ""
43+
# Interface name, defaults to "vde0", "vde1", etc.
44+
name: ""
45+
```
46+
47+
The IP address range is typically `192.168.105.0/24`, but depends on the configuration of `vde_vmnet`.
48+
See [the documentation of `vde_vmnet`](https://github.com/lima-vm/vde_vmnet) for further information.

examples/vmnet.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
images:
2+
# Hint: run `limactl prune` to invalidate the "current" cache
3+
- location: "https://cloud-images.ubuntu.com/hirsute/current/hirsute-server-cloudimg-amd64.img"
4+
arch: "x86_64"
5+
- location: "https://cloud-images.ubuntu.com/hirsute/current/hirsute-server-cloudimg-arm64.img"
6+
arch: "aarch64"
7+
mounts:
8+
- location: "~"
9+
writable: false
10+
- location: "/tmp/lima"
11+
writable: true
12+
ssh:
13+
# localPort is changed from 60022 to avoid conflicting with the default.
14+
# (TODO: assign localPort automatically)
15+
localPort: 60105
16+
17+
network:
18+
# The instance can get routable IP addresses from the vmnet framework using
19+
# https://github.com/lima-vm/vde_vmnet. Both vde_switch and vde_vmnet
20+
# daemons must be running before the instance is started. The interface type
21+
# (host, shared, or bridged) is configured in vde_vmnet and not lima.
22+
vde:
23+
- vnl: "vde:///var/run/vde.ctl"

pkg/limayaml/default.yaml

+72-51
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# ===================================================================== #
2+
# BASIC CONFIGURATION
3+
# ===================================================================== #
4+
15
# Arch: "default", "x86_64", "aarch64".
26
# "default" corresponds to the host architecture.
37
arch: "default"
@@ -31,20 +35,6 @@ memory: "4GiB"
3135
# Default: "100GiB"
3236
disk: "100GiB"
3337

34-
network:
35-
# The instance can get routable IP addresses from the vmnet framework using
36-
# https://github.com/AkihiroSuda/vde_vmnet. Both vde_switch and vde_vmnet
37-
# daemons must be running before the instance is started. The interface type
38-
# (host, shared, or bridged) is configured in vde_vmnet and not lima.
39-
vde:
40-
# url points to the vde_switch socket directory
41-
# - url: "/var/run/vde.ctl"
42-
# # MAC address of the instance; lima will pick one based on the instance name,
43-
# # so DHCP assigned ip addresses should remain constant over instance restarts.
44-
# macAddress: ""
45-
# # Interface name, defaults to "vde0", "vde1", etc.
46-
# name: ""
47-
4838
# Expose host directories to the guest
4939
# Default: none
5040
mounts:
@@ -67,17 +57,9 @@ ssh:
6757
# Default: true
6858
loadDotSSHPubKeys: true
6959

70-
firmware:
71-
# Use legacy BIOS instead of UEFI.
72-
# Default: false
73-
legacyBIOS: false
74-
75-
video:
76-
# QEMU display, e.g., "none", "cocoa", "sdl".
77-
# As of QEMU v5.2, enabling this is known to have negative impact
78-
# on performance on macOS hosts: https://gitlab.com/qemu-project/qemu/-/issues/334
79-
# Default: "none"
80-
display: "none"
60+
# ===================================================================== #
61+
# ADVANCED CONFIGURATION
62+
# ===================================================================== #
8163

8264
containerd:
8365
# Enable system-wide (aka rootful) containerd and its dependencies (BuildKit, Stargz Snapshotter)
@@ -87,32 +69,6 @@ containerd:
8769
# Default: true
8870
user: true
8971

90-
# Port forwarding rules. Forwarding between ports 22 and ssh.localPort cannot be overridden.
91-
# Rules are checked sequentially until the first one matches.
92-
# portForwards:
93-
# - guestPort: 443
94-
# hostIP: "0.0.0.0" # overrides the default value "127.0.0.1"; allows privileged port forwarding
95-
# # default: hostPort: 443 (same as guestPort)
96-
# # default: guestIP: "127.0.0.1" (also matches bind addresses "0.0.0.0", "::", and "::1")
97-
# # default: proto: "tcp" (only valid value right now)
98-
# - guestPortRange: [4000, 4999]
99-
# hostIP: "0.0.0.0" # overrides the default value "127.0.0.1"
100-
# # default: hostPortRange: [4000, 4999] (must specify same number of ports as guestPortRange)
101-
# - guestPort: 80
102-
# hostPort: 8080 # overrides the default value 80
103-
# - guestIP: "127.0.0.2" # overrides the default value "127.0.0.1"
104-
# hostIP: "127.0.0.2" # overrides the default value "127.0.0.1"
105-
# # default: guestPortRange: [1024, 65535]
106-
# # default: hostPortRange: [1024, 65535]
107-
# - guestPort: 8888
108-
# ignore: true (don't forward this port)
109-
# # Lima internally appends this fallback rule at the end:
110-
# - guestIP: "127.0.0.1"
111-
# guestPortRange: [1024, 65535]
112-
# hostIP: "127.0.0.1"
113-
# hostPortRange: [1024, 65535]
114-
# # Any port still not matched by a rule will not be forwarded (ignored)
115-
11672
# Provisioning scripts need to be idempotent because they might be called
11773
# multiple times, e.g. when the host VM is being restarted.
11874
# provision:
@@ -146,3 +102,68 @@ containerd:
146102
# hint: |
147103
# vim was not installed in the guest. Make sure the package system is working correctly.
148104
# Also see "/var/log/cloud-init-output.log" in the guest.
105+
106+
# ===================================================================== #
107+
# FURTHER ADVANCED CONFIGURATION
108+
# ===================================================================== #
109+
110+
firmware:
111+
# Use legacy BIOS instead of UEFI.
112+
# Default: false
113+
legacyBIOS: false
114+
115+
video:
116+
# QEMU display, e.g., "none", "cocoa", "sdl".
117+
# As of QEMU v5.2, enabling this is known to have negative impact
118+
# on performance on macOS hosts: https://gitlab.com/qemu-project/qemu/-/issues/334
119+
# Default: "none"
120+
display: "none"
121+
122+
network:
123+
# The instance can get routable IP addresses from the vmnet framework using
124+
# https://github.com/lima-vm/vde_vmnet. Both vde_switch and vde_vmnet
125+
# daemons must be running before the instance is started. The interface type
126+
# (host, shared, or bridged) is configured in vde_vmnet and not lima.
127+
vde:
128+
# vnl (virtual network locator) points to the vde_switch socket directory,
129+
# optionally with vde:// prefix
130+
# - vnl: "vde:///var/run/vde.ctl"
131+
# # VDE Switch port number (not TCP/UDP port number). Set to 65535 for PTP mode.
132+
# # Default: 0
133+
# switchPort: 0
134+
# # MAC address of the instance; lima will pick one based on the instance name,
135+
# # so DHCP assigned ip addresses should remain constant over instance restarts.
136+
# macAddress: ""
137+
# # Interface name, defaults to "vde0", "vde1", etc.
138+
# name: ""
139+
140+
# Port forwarding rules. Forwarding between ports 22 and ssh.localPort cannot be overridden.
141+
# Rules are checked sequentially until the first one matches.
142+
# portForwards:
143+
# - guestPort: 443
144+
# hostIP: "0.0.0.0" # overrides the default value "127.0.0.1"; allows privileged port forwarding
145+
# # default: hostPort: 443 (same as guestPort)
146+
# # default: guestIP: "127.0.0.1" (also matches bind addresses "0.0.0.0", "::", and "::1")
147+
# # default: proto: "tcp" (only valid value right now)
148+
# - guestPortRange: [4000, 4999]
149+
# hostIP: "0.0.0.0" # overrides the default value "127.0.0.1"
150+
# # default: hostPortRange: [4000, 4999] (must specify same number of ports as guestPortRange)
151+
# - guestPort: 80
152+
# hostPort: 8080 # overrides the default value 80
153+
# - guestIP: "127.0.0.2" # overrides the default value "127.0.0.1"
154+
# hostIP: "127.0.0.2" # overrides the default value "127.0.0.1"
155+
# # default: guestPortRange: [1024, 65535]
156+
# # default: hostPortRange: [1024, 65535]
157+
# - guestPort: 8888
158+
# ignore: true (don't forward this port)
159+
# # Lima internally appends this fallback rule at the end:
160+
# - guestIP: "127.0.0.1"
161+
# guestPortRange: [1024, 65535]
162+
# hostIP: "127.0.0.1"
163+
# hostPortRange: [1024, 65535]
164+
# # Any port still not matched by a rule will not be forwarded (ignored)
165+
166+
# ===================================================================== #
167+
# END OF TEMPLATE
168+
# ===================================================================== #
169+

pkg/limayaml/defaults.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ import (
88
"strconv"
99

1010
"github.com/AkihiroSuda/lima/pkg/guestagent/api"
11+
"github.com/AkihiroSuda/lima/pkg/osutil"
1112
)
1213

1314
func MACAddress(uniqueID string) string {
14-
// TODO: combine the uniqueID with the host machineID to create a globally unique hash
15-
sha := sha256.Sum256([]byte(uniqueID))
16-
// According to https://gitlab.com/wireshark/wireshark/-/blob/master/manuf
17-
// no well-known MAC addresses start with 0x22.
18-
hw := append(net.HardwareAddr{0x22}, sha[0:5]...)
15+
sha := sha256.Sum256([]byte(osutil.MachineID() + uniqueID))
16+
// "5" is the magic number in the Lima ecosystem.
17+
// (Visit https://en.wiktionary.org/wiki/lima and Command-F "five")
18+
//
19+
// But the second hex number is changed to 2 to satisfy the convention for
20+
// local MAC addresses (https://en.wikipedia.org/wiki/MAC_address#Ranges_of_group_and_locally_administered_addresses)
21+
//
22+
// See also https://gitlab.com/wireshark/wireshark/-/blob/master/manuf to confirm the uniqueness of this prefix.
23+
hw := append(net.HardwareAddr{0x52, 0x55, 0x55}, sha[0:3]...)
1924
return hw.String()
2025
}
2126

pkg/limayaml/limayaml.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ type Network struct {
111111
VDE []VDE `yaml:"vde,omitempty"`
112112
}
113113
type VDE struct {
114-
URL string `yaml:"url,omitempty"`
114+
// VNL is a Virtual Network Locator (https://github.com/rd235/vdeplug4/commit/089984200f447abb0e825eb45548b781ba1ebccd).
115+
// On macOS, only VDE2-compatible form (optionally with vde:// prefix) is supported.
116+
VNL string `yaml:"vnl,omitempty"`
117+
SwitchPort uint16 `yaml:"switchPort,omitempty"` // VDE Switch port, not TCP/UDP port
115118
MACAddress string `yaml:"macAddress,omitempty"`
116119
Name string `yaml:"name,omitempty"`
117120
}

0 commit comments

Comments
 (0)