Skip to content

Commit 8b16e51

Browse files
committed
The initial commit of socket_vmnet (Forked from [email protected])
Signed-off-by: Akihiro Suda <[email protected]>
1 parent a4b489e commit 8b16e51

19 files changed

+441
-348
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,23 @@ jobs:
2424
uname -a
2525
sw_vers
2626
ifconfig
27-
- name: Install build dependencies of VDE
28-
run: brew install autoconf automake
2927
- name: Make Install (x86_64)
3028
run: |
3129
# compile for x86_64
32-
sudo make PREFIX=/opt/vde install
33-
if file /opt/vde/bin/* | grep -q arm64 ; then false ; fi
30+
sudo make PREFIX=/opt/socket_vmnet install
31+
if file /opt/socket_vmnet/bin/* | grep -q arm64 ; then false ; fi
3432
- name: Cleanup
3533
run: |
3634
sudo make clean
3735
- name: Make Install (arm64)
3836
run: |
3937
# cross-compile for arm64
40-
sudo make PREFIX=/opt/vde.arm64 ARCH=arm64 install
41-
if file /opt/vde.arm64/bin/* | grep -q x86_64 ; then false ; fi
38+
sudo make PREFIX=/opt/socket_vmnet.arm64 ARCH=arm64 install
39+
if file /opt/socket_vmnet.arm64/bin/* | grep -q x86_64 ; then false ; fi
4240
- name: Print launchd status (shared mode)
43-
run: launchctl print system/io.github.lima-vm.vde_vmnet.plist
41+
run: launchctl print system/io.github.lima-vm.socket_vmnet.plist
4442
- name: Install test dependencies
4543
run: brew install qemu bash coreutils
4644
- name: Test (shared mode)
47-
run: ./test/test.sh /var/run/vde.ctl
45+
run: ./test/test.sh /var/run/socket_vmnet
4846
# Bridged mode cannot be tested on GHA

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
/vde_vmnet
1+
/socket_vmnet
2+
/socket_vmnet_client
23
*.o

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

Makefile

Lines changed: 31 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,80 @@
11
# PREFIX should be only writable by the root to avoid privilege escalation with launchd or sudo
2-
PREFIX ?= /opt/vde
2+
PREFIX ?= /opt/socket_vmnet
33

4-
# VDEPREFIX should be only writable by the root to avoid privilege escalation with launchd or sudo
5-
VDEPREFIX ?= $(PREFIX)
6-
7-
VMNET_CFLAGS ?= -O3
4+
CFLAGS ?= -O3
85

96
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
107

11-
VMNET_CFLAGS += -I"$(VDEPREFIX)/include" -DVERSION=\"$(VERSION)\"
8+
CFLAGS += -DVERSION=\"$(VERSION)\"
129

13-
VMNET_LDFLAGS += -L"$(VDEPREFIX)/lib" -lvdeplug -framework vmnet
10+
LDFLAGS ?=
11+
VMNET_LDFLAGS = -framework vmnet
1412

1513
# ARCH support arm64 and x86_64
1614
ARCH ?=
1715

1816
ifneq (,$(findstring arm64,$(ARCH)))
1917
HOST ?= --host arm-apple-darwin
20-
VMNET_CFLAGS += -arch arm64
21-
VDE2_CFLAGS += -arch arm64 -Wno-error=implicit-function-declaration
18+
CFLAGS += -arch arm64
2219
else ifneq (,$(findstring x86_64,$(ARCH)))
2320
HOST ?= --host x86_64-apple-darwin
24-
VMNET_CFLAGS += -arch x86_64
25-
VDE2_CFLAGS += -arch x86_64 -Wno-error=implicit-function-declaration
21+
CFLAGS += -arch x86_64
2622
endif
2723

2824
# Interface name for bridged mode. Empty value (default) disables bridged mode.
2925
BRIDGED ?=
3026

31-
all: vde_vmnet
32-
33-
OBJS = $(patsubst %.c, %.o, $(wildcard *.c))
27+
all: socket_vmnet socket_vmnet_client
3428

3529
%.o: %.c *.h
36-
$(CC) $(VMNET_CFLAGS) -c $< -o $@
30+
$(CC) $(CFLAGS) -c $< -o $@
3731

38-
vde_vmnet: $(OBJS)
39-
$(CC) $(VMNET_CFLAGS) -o $@ $(VMNET_LDFLAGS) $(OBJS)
32+
socket_vmnet: $(patsubst %.c, %.o, $(wildcard *.c))
33+
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(VMNET_LDFLAGS) $^
4034

41-
install.bin: vde_vmnet
42-
install vde_vmnet "$(DESTDIR)/$(PREFIX)/bin/vde_vmnet"
35+
socket_vmnet_client: $(patsubst %.c, %.o, $(wildcard client/*.c))
36+
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $^
4337

44-
install.vde-2:
45-
git submodule update --init
46-
cd vde-2 && autoreconf -fis && CFLAGS="$(VDE2_CFLAGS)" ./configure --prefix=$(VDEPREFIX) $(HOST) && make && make install
38+
install.bin: socket_vmnet socket_vmnet_client
39+
mkdir -p "$(DESTDIR)/$(PREFIX)/bin"
40+
install socket_vmnet "$(DESTDIR)/$(PREFIX)/bin/socket_vmnet"
41+
install socket_vmnet_client "$(DESTDIR)/$(PREFIX)/bin/socket_vmnet_client"
4742

4843
install.launchd.plist: launchd/*.plist
49-
sed -e "s@/opt/vde@$(PREFIX)@g" launchd/io.github.virtualsquare.vde-2.vde_switch.plist > "$(DESTDIR)/Library/LaunchDaemons/io.github.virtualsquare.vde-2.vde_switch.plist"
50-
sed -e "s@/opt/vde@$(PREFIX)@g" launchd/io.github.lima-vm.vde_vmnet.plist > "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.vde_vmnet.plist"
44+
sed -e "s@/opt/socket_vmnet@$(PREFIX)@g" launchd/io.github.lima-vm.socket_vmnet.plist > "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.socket_vmnet.plist"
5145

5246
ifneq ($(BRIDGED),)
53-
sed -e "s@/opt/vde@$(PREFIX)@g" -e "s/en0/$(BRIDGED)/g" launchd/io.github.virtualsquare.vde-2.vde_switch.bridged.en0.plist > "$(DESTDIR)/Library/LaunchDaemons/io.github.virtualsquare.vde-2.vde_switch.bridged.$(BRIDGED).plist"
54-
sed -e "s@/opt/vde@$(PREFIX)@g" -e "s/en0/$(BRIDGED)/g" launchd/io.github.lima-vm.vde_vmnet.bridged.en0.plist > "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.vde_vmnet.bridged.$(BRIDGED).plist"
47+
sed -e "s@/opt/socket_vmnet@$(PREFIX)@g" -e "s/en0/$(BRIDGED)/g" launchd/io.github.lima-vm.socket_vmnet.bridged.en0.plist > "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.socket_vmnet.bridged.$(BRIDGED).plist"
5548
endif
5649

5750
install.launchd: install.launchd.plist
58-
launchctl load -w "$(DESTDIR)/Library/LaunchDaemons/io.github.virtualsquare.vde-2.vde_switch.plist"
59-
launchctl load -w "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.vde_vmnet.plist"
51+
launchctl load -w "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.socket_vmnet.plist"
6052
ifneq ($(BRIDGED),)
61-
launchctl load -w "$(DESTDIR)/Library/LaunchDaemons/io.github.virtualsquare.vde-2.vde_switch.bridged.$(BRIDGED).plist"
62-
launchctl load -w "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.vde_vmnet.bridged.$(BRIDGED).plist"
53+
launchctl load -w "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.socket_vmnet.bridged.$(BRIDGED).plist"
6354
endif
6455

65-
install: install.vde-2 install.bin install.launchd
56+
install: install.bin install.launchd
6657

6758
.PHONY: uninstall.bin
6859
uninstall.bin:
69-
rm -f "$(DESTDIR)/$(PREFIX)/bin/vde_vmnet"
70-
71-
.PHONY: uninstall.vde-2
72-
uninstall.vde-2:
73-
cd vde-2 && make uninstall
60+
rm -f "$(DESTDIR)/$(PREFIX)/bin/socket_vmnet"
61+
rm -f "$(DESTDIR)/$(PREFIX)/bin/socket_vmnet_client"
7462

7563
.PHONY: uninstall.launchd
7664
uninstall.launchd:
77-
launchctl unload -w "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.vde_vmnet.plist"
78-
launchctl unload -w "$(DESTDIR)/Library/LaunchDaemons/io.github.virtualsquare.vde-2.vde_switch.plist"
65+
launchctl unload -w "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.socket_vmnet.plist"
7966
ifneq ($(BRIDGED),)
80-
launchctl unload -w "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.vde_vmnet.bridged.$(BRIDGED).plist"
81-
launchctl unload -w "$(DESTDIR)/Library/LaunchDaemons/io.github.virtualsquare.vde-2.vde_switch.bridged.$(BRIDGED).plist"
67+
launchctl unload -w "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.socket_vmnet.bridged.$(BRIDGED).plist"
8268
endif
8369

8470
uninstall.launchd.plist: uninstall.launchd
85-
rm -f "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.vde_vmnet.plist"
86-
rm -f "$(DESTDIR)/Library/LaunchDaemons/io.github.virtualsquare.vde-2.vde_switch.plist"
71+
rm -f "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.socket_vmnet.plist"
8772
ifneq ($(BRIDGED),)
88-
rm -f "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.vde_vmnet.bridged.$(BRIDGED).plist"
89-
rm -f "$(DESTDIR)/Library/LaunchDaemons/io.github.virtualsquare.vde-2.vde_switch.bridged.$(BRIDGED).plist"
73+
rm -f "$(DESTDIR)/Library/LaunchDaemons/io.github.lima-vm.socket_vmnet.bridged.$(BRIDGED).plist"
9074
endif
9175

92-
uninstall: uninstall.launchd.plist uninstall.bin uninstall.vde-2
93-
94-
.PHONY: clean.vde-2
95-
clean.vde-2:
96-
cd vde-2 && make distclean
76+
uninstall: uninstall.launchd.plist uninstall.bin
9777

9878
.PHONY: clean
99-
clean: clean.vde-2
100-
rm -f vde_vmnet *.o
79+
clean:
80+
rm -f socket_vmnet socket_vmnet_client *.o client/*.o

README.md

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
1-
# vde_vmnet: vmnet.framework support for rootless QEMU
1+
# socket_vmnet: vmnet.framework support for rootless and VDE-less QEMU
22

3-
`vde_vmnet` provides [vmnet.framework](https://developer.apple.com/documentation/vmnet) support for VDE applications such as QEMU.
3+
`socket_vmnet` provides [vmnet.framework](https://developer.apple.com/documentation/vmnet) support for QEMU.
44

5-
`vde_vmnet` does not require QEMU to run as the root user.
5+
`socket_vmnet` does not require QEMU to run as the root user.
66

7-
(But `vde_vmnet` itself has to run as the root, in most cases.)
7+
(But `socket_vmnet` itself has to run as the root, in most cases.)
8+
9+
`socket_vmnet` was forked from [`vde_vmnet`](https://github.com/lima-vm/vde_vmnet) v0.6.0.
10+
Unlike `vde_vmnet`, `socket_vmnet` does not depend on VDE.
811

912
## Install
1013

1114
Requires macOS 10.15 or later.
1215

13-
Install [vde-2](https://github.com/virtualsquare/vde-2) and vde_vmnet from source.
16+
Install from source:
1417
```bash
15-
sudo make PREFIX=/opt/vde install
18+
sudo make PREFIX=/opt/socket_vmnet install
1619
```
1720

18-
The `PREFIX` dir below does not necessarily need to be `/opt/vde`, however, it is highly recommended
21+
The `PREFIX` dir below does not necessarily need to be `/opt/socket_vmnet`, however, it is highly recommended
1922
to set the prefix to a directory that can be only written by the root.
2023

2124
Note that `/usr/local` is typically chowned for a non-root user on Homebrew environments, so
2225
`/usr/local` is *not* an appropriate prefix.
2326

2427
The following files will be installed:
25-
- `/opt/vde/bin/vde_switch` (from vde-2)
26-
- `/opt/vde/bin/vde_vmnet`
27-
- `/Library/LaunchDaemons/io.github.virtualsquare.vde-2.vde_switch.plist`
28-
- `/Library/LaunchDaemons/io.github.lima-vm.vde_vmnet.plist`
28+
- `/opt/socket_vmnet/bin/socket_vmnet`
29+
- `/opt/socket_vmnet/bin/socket_vmnet_client`
30+
- `/Library/LaunchDaemons/io.github.lima-vm.socket_vmnet.plist`
2931
- Configured to use `192.168.105.0/24`. Modifiy the file if it conflicts with your local network.
3032

3133
See ["Testing without launchd"](#testing-without-launchd) if you don't prefer to use launchd.
3234

3335
## Usage
3436

3537
```console
36-
qemu-system-x86_64 \
37-
-device virtio-net-pci,netdev=net0 -netdev vde,id=net0,sock=/var/run/vde.ctl \
38-
-m 4096 -accel hvf -cdrom ubuntu-21.04-desktop-amd64.iso
38+
/opt/socket_vmnet/bin/socket_vmnet_client /var/run/socket_vmnet qemu-system-x86_64 \
39+
-device virtio-net-pci,netdev=net0 -netdev socket,id=net0,fd=3 \
40+
-m 4096 -accel hvf -cdrom ubuntu-22.04-desktop-amd64.iso
3941
```
4042

4143
The guest IP is assigned by the DHCP server provided by macOS.
@@ -46,70 +48,44 @@ To confirm, run `sudo apt-get update && sudo apt-get install -y apache2` in the
4648

4749
### Lima integration
4850

49-
See https://github.com/lima-vm/lima/blob/master/docs/network.md to learn how to use `vde_vmnet` with [Lima](https://github.com/lima-vm/lima).
51+
(WIP)
5052

5153
### Multi VM
52-
Multiple VMs can be connected to a single `vde_vmnet` instance.
54+
Multiple VMs can be connected to a single `socket_vmnet` instance.
5355

5456
Make sure to specify unique MAC addresses to VMs: `-device virtio-net-pci,netdev=net0,mac=de:ad:be:ef:00:01` .
5557

56-
NOTE: don't confuse MAC addresses of VMs with the MAC address of `vde_vmnet` itself that is printed as `vmnet_mac_address` in the debug log.
57-
You do not need to configure (and you can't, currently) the MAC address of `vde_vmnet` itself.
58+
NOTE: don't confuse MAC addresses of VMs with the MAC address of `socket_vmnet` itself that is printed as `vmnet_mac_address` in the debug log.
59+
You do not need to configure (and you can't, currently) the MAC address of `socket_vmnet` itself.
5860

5961
### Bridged mode
6062

6163
Run `sudo make install BRIDGED=en0`.
6264

63-
The following additional files will be installed:
64-
- `/Library/LaunchDaemons/io.github.virtualsquare.vde-2.vde_switch.bridged.en0.plist`
65-
- `/Library/LaunchDaemons/io.github.lima-vm.vde_vmnet.bridged.en0.plist`
65+
The following additional file will be installed:
66+
- `/Library/LaunchDaemons/io.github.lima-vm.socket_vmnet.bridged.en0.plist`
6667

67-
Use `/var/run/vde.bridged.en0.ctl` as the VDE socket path.
68+
Use `/var/run/socket_vmnet.bridged.en0` as the socket.
6869

6970
## Advanced usage
7071

7172
### Testing without launchd
7273

7374
```console
74-
sudo make install.vde-2
75-
7675
sudo make install.bin
7776
```
7877

7978
```console
80-
vde_switch --unix /tmp/vde.ctl
81-
```
82-
83-
```console
84-
sudo vde_vmnet --vmnet-gateway=192.168.105.1 /tmp/vde.ctl
79+
sudo socket_vmnet --vmnet-gateway=192.168.105.1 /tmp/socket_vmnet
8580
```
8681

87-
Note: make sure to run `vde_vmnet` with root (`sudo`). See [FAQs](#FAQs) for the reason.
88-
`vde_switch` does not need to be executed as root.
89-
90-
### PTP mode (Switchless mode)
91-
92-
- Pros: doesn't require the `vde_switch` process to be running
93-
- Cons: Only single QEMU process can connect to the socket. Multiple `vde_vmnet` processes need to be launched for multiple QEMU processes.
94-
95-
To enable PTP mode, append `[]` to the socket path argument of `vde_vmnet`.
96-
97-
```console
98-
sudo vde_vmnet /tmp/vde.ptp[]
99-
```
100-
101-
QEMU has to be launched with `port=65535` without `[]`.
102-
103-
```console
104-
qemu-system-x86_64 -netdev vde,id=net0,sock=/tmp/vde.ptp,port=65535 ...
105-
```
106-
107-
The "port" number here has nothing to do with TCP/UDP ports.
82+
Note: make sure to run `socket_vmnet` with root (`sudo`). See [FAQs](#FAQs) for the reason.
10883

10984
## FAQs
110-
### Why does `vde_vmnet` require root?
11185

112-
Running `vde_vmnet` without root could be possible by signing the `vde_vmnet` binary with `com.apple.vm.networking` entitlement.
86+
### Why does `socket_vmnet` require root?
87+
88+
Running `socket_vmnet` without root could be possible by signing the `socket_vmnet` binary with `com.apple.vm.networking` entitlement.
11389

11490
However, signing a binary with `com.apple.vm.networking` entitlement seems to require some contract with Apple.
11591
:disappointed:
@@ -118,22 +94,25 @@ However, signing a binary with `com.apple.vm.networking` entitlement seems to re
11894
11995
https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_vm_networking
12096

121-
### Is it possible to run `vde_vmnet` with SETUID?
97+
### Is it possible to run `socket_vmnet` with SETUID?
12298

12399
Yes, but discouraged, as it allows non-root users to write arbitrary files, by specifying certain CLI args and environment variables.
124100

125101
Instead, consider using launchd or sudo.
126102

127-
See [`./etc_sudoers.d/vde_vmnet`](./etc_sudoers.d/vde_vmnet) to allow running `sudo vde_vmnet` with reduced set of args and environment variables.
103+
See [`./etc_sudoers.d/socket_vmnet`](./etc_sudoers.d/socket_vmnet) to allow running `sudo socket_vmnet` with reduced set of args and environment variables.
104+
105+
### How is socket_vmnet related to vde_vmnet?
106+
107+
`socket_vmnet` was forked from [`vde_vmnet`](https://github.com/lima-vm/vde_vmnet) v0.6.0.
108+
Unlike `vde_vmnet`, `socket_vmnet` does not depend on VDE.
128109

129-
### How is vde_vmnet related to QEMU-builtin vmnet support?
130-
There are proposal to add builtin vmnet support for QEMU:
131-
- https://lore.kernel.org/qemu-devel/[email protected]/
132-
- https://lore.kernel.org/qemu-devel/[email protected]/
110+
### How is socket_vmnet related to QEMU-builtin vmnet support?
111+
There is a proposal to add builtin vmnet support for QEMU: [`[v22] Add vmnet.framework based network backend`](https://patchwork.kernel.org/project/qemu-devel/cover/[email protected]/).
133112

134-
However, QEMU-builtin vmnet is highly likely to require running the entire QEMU process as root.
113+
However, QEMU-builtin vmnet requires running the entire QEMU process as root.
135114

136-
On the other hand, `vde_vmnet` does not require the entire QEMU process to run as root, though `vde_vmnet` has to run as root.
115+
On the other hand, `socket_vmnet` does not require the entire QEMU process to run as root, though `socket_vmnet` has to run as root.
137116

138117
### How to use static IP addresses?
139118
When `--vmnet-gateway=IP` is set to "192.168.105.1", the whole subnet (192.168.105.2-192.168.105.254) is used as the DHCP range.
@@ -164,8 +143,8 @@ sudo /bin/launchctl load -w /System/Library/LaunchDaemons/bootps.plist
164143

165144
- Run QEMU with the MAC address: `-device virtio-net-pci,netdev=net0,mac=de:ad:be:ef:00:01` .
166145

167-
NOTE: don't confuse MAC addresses of VMs with the MAC address of `vde_vmnet` itself that is printed as `vmnet_mac_address` in the debug log.
168-
You do not need to configure (and you can't, currently) the MAC address of `vde_vmnet` itself.
146+
NOTE: don't confuse MAC addresses of VMs with the MAC address of `socket_vmnet` itself that is printed as `vmnet_mac_address` in the debug log.
147+
You do not need to configure (and you can't, currently) the MAC address of `socket_vmnet` itself.
169148

170149
## Links
171150
- https://developer.apple.com/documentation/vmnet
@@ -174,4 +153,4 @@ You do not need to configure (and you can't, currently) the MAC address of `vde_
174153

175154
## Troubleshooting
176155
- Set environment variable `DEBUG=1`
177-
- See `/var/run/vde_vmnet.{stdout,stderr}` (when using launchd)
156+
- See `/var/run/socket_vmnet.{stdout,stderr}` (when using launchd)

0 commit comments

Comments
 (0)