For -netdev user,guestfwd=..., add support for unix2: in addition to the currently supported tcp: and cmd:. With unix2:, a new connection is opened to the given unix socket per TCP connection to the target address/port pair. The unix socket need not exist at qemu startup time.
This is an improvement over the current unix: support, which mixes all guest connections onto a single host unix connection, and (by default) requires the unix socket to be present at qemu startup time. Also update the minimum libslirp version to 4.2.0 (released in 2020) as it adds support for the slirp_add_unix() function. Signed-off-by: Gavin Li <[email protected]> --- Changes in v2: - rename unix-per-connection to unix2 - update commit message for references meson.build | 2 +- net/slirp.c | 6 ++++++ qemu-options.hx | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index d7bcb581c1..6567ede5d9 100644 --- a/meson.build +++ b/meson.build @@ -1289,7 +1289,7 @@ endif slirp = not_found if not get_option('slirp').auto() or have_system slirp = dependency('slirp', required: get_option('slirp'), - method: 'pkg-config') + method: 'pkg-config', version: '>=4.2.0') # slirp < 4.7 is incompatible with CFI support in QEMU. This is because # it passes function pointers within libslirp as callbacks for timers. # When using a system-wide shared libslirp, the type information for the diff --git a/net/slirp.c b/net/slirp.c index 451c0fd1ba..2886c0b22f 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -1159,6 +1159,12 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, Error **errp) "forwarding rule '%s'", config_str); return -1; } + } else if (g_str_has_prefix(p, "unix2:")) { + if (slirp_add_unix(s->slirp, &p[6], &server, port) < 0) { + error_setg(errp, "Conflicting/invalid host:port in guest " + "forwarding rule '%s'", config_str); + return -1; + } } else { Error *err = NULL; /* diff --git a/qemu-options.hx b/qemu-options.hx index 5fe9d73eaa..488a4e9828 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3553,6 +3553,15 @@ SRST # and connect the TCP stream to its stdin/stdout |qemu_system| -nic 'user,id=n1,guestfwd=tcp:10.0.2.100:1234-cmd:netcat 10.10.1.1 4321' + ``guestfwd=[tcp]:server:port-unix2:path`` + With ``unix2:``, a new connection is opened to the given unix socket + per TCP connection made by the guest. The unix socket need not exist + at startup time. + + .. parsed-literal:: + + |qemu_system| -nic user,guestfwd=tcp:10.0.2.100:1234-unix2:/tmp/socket + ``-netdev tap,id=id[,fd=h][,ifname=name][,script=file][,downscript=dfile][,br=bridge][,helper=helper]`` Configure a host TAP network backend with ID id. base-commit: 71f25c75417d31c214ba2cd26b273c114fc99987 -- 2.55.0
