Skip to content

Commit b543d0f

Browse files
committed
QEMU: use a static offset to choose vsock port on the host side
600000 is arbitrarily picked to avoid conflicts with the "standard" networking range of 65535 ports, since vsock supports 32-bit port numbers.
1 parent c34e44e commit b543d0f

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lib/runners/qemu.nix

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,10 @@ lib.warnIf (mem == 2048) ''
163163
# Clean up temporary files.
164164
${pkgs.coreutils}/bin/rm -f ./socat.log ./notify_socket.cred
165165
# Default value: for running without systemd.
166-
NOTIFY_VSOCK_PORT=8888
166+
NOTIFY_VSOCK_PORT=$(( 600000 + ${vsock.cid} ))
167167
# Start socat to forward systemd notify socket over vsock
168168
if [ -n "''${NOTIFY_SOCKET-}" ]; then
169-
${pkgs.socat}/bin/socat -d -d VSOCK-LISTEN:-1,fork UNIX-SENDTO:$NOTIFY_SOCKET 2> ./socat.log &
170-
NOTIFY_VSOCK_PORT=$({ ${pkgs.coreutils}/bin/tail -f ./socat.log || true; } | ${pkgs.gawk}/bin/awk '/listening on/ { if (match($0, /port:[0-9]*/)) { print substr($0, RSTART + 5, RLENGTH - 5); exit; } }')
171-
echo "Picked port for notify vsock: $NOTIFY_VSOCK_PORT"
169+
${pkgs.socat}/bin/socat -d -d VSOCK-LISTEN:$NOTIFY_VSOCK_PORT,fork UNIX-SENDTO:$NOTIFY_SOCKET 2> ./socat.log &
172170
fi
173171
echo -n "vsock-stream:2:$NOTIFY_VSOCK_PORT" > ./notify_socket.cred
174172
@@ -322,7 +320,7 @@ lib.warnIf (mem == 2048) ''
322320
# tried, SMBIOS Type 11 entries simply don't work. It looks like it might
323321
# be broken on QEMU side. Why? I don't know.
324322
"-fw_cfg"
325-
"name=opt/io.systemd.credentials/vmm.notify_socket,file=./notify_socket.cred"
323+
"name=opt/io.systemd.credentials/vmm.notify_socket,string=vsock-stream:2:${toString (600000 + vsock.cid)}"
326324
]
327325
++
328326
extraArgs

0 commit comments

Comments
 (0)