mirror of https://github.com/xemu-project/xemu.git
slirp: Use newer slirp_*_hostxfwd API
Nicholas Ngai (1): net/slirp: Use newer slirp_*_hostxfwd API -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEqpLrvfAUiqYaQ7iu5IlMrEVBS7AFAmYu5OgACgkQ5IlMrEVB S7DGOQ//cnW2fiXnj+ijmQ4+h8Yj2vCtGZ9+7D74Q6KSbY0AkYVhRm+qWJA1XJrR Y7JvetqKGCxhol24x0aopDvcybIDU/EqFrxhmZY+dJhZWxfsvYpLGJ5TfulRA1gy PSDYQi6LlwDJyQT08po2TLA0zSOmxycdrA8mTJuf8UHDiXnwcy9WjDFF1tCrGoN4 LgvsUUpQ6y9fZQxbFyPFwtHkUeREvfhRPT0c5lNsF0Cot8uXt5YOyCc0XKjX1d0F ucuCwv65gsIdcaDHcHIYhyKZX3lfAXAAaDe9njvISYcyOlyXOZS9df3tuMTeEW8S wuN10WuQHI7mpLS/IomnmYxb16lyhhwLC9kmNVZt6jGfTYB/xHUeXb9gIsdkc05s Cxy+VdxgnzGji6dOwufI8/ufWSti1PRB1yhZsmJtLC7MDOv5EJkxrmRXhWkr6LYZ CU52uT7CsOTKdmmwdjTUqkfswB70Js68J33Rbm3VWJlnSBAQ/ioGt50r7tqFBwT8 HQc4CqYBT58BPb7rKrUa6dCy1uAprYl2juU3vl/nHcp2zIxIar1yzQK3OG+3h6fZ Mrg/C5l4WiEKFgdl5sMj1xJK15aC42/UyzxUFM12usKaOtKjQAIkjx6U7HCjwfdR BZmxTx2u7jGm9a0R3qhVhZjmIIbfLoeEHepLMOAHN+TGAl0bcxc= =22cZ -----END PGP SIGNATURE----- Merge tag 'samuel-thibault' of https://people.debian.org/~sthibault/qemu into staging slirp: Use newer slirp_*_hostxfwd API Nicholas Ngai (1): net/slirp: Use newer slirp_*_hostxfwd API # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCgAdFiEEqpLrvfAUiqYaQ7iu5IlMrEVBS7AFAmYu5OgACgkQ5IlMrEVB # S7DGOQ//cnW2fiXnj+ijmQ4+h8Yj2vCtGZ9+7D74Q6KSbY0AkYVhRm+qWJA1XJrR # Y7JvetqKGCxhol24x0aopDvcybIDU/EqFrxhmZY+dJhZWxfsvYpLGJ5TfulRA1gy # PSDYQi6LlwDJyQT08po2TLA0zSOmxycdrA8mTJuf8UHDiXnwcy9WjDFF1tCrGoN4 # LgvsUUpQ6y9fZQxbFyPFwtHkUeREvfhRPT0c5lNsF0Cot8uXt5YOyCc0XKjX1d0F # ucuCwv65gsIdcaDHcHIYhyKZX3lfAXAAaDe9njvISYcyOlyXOZS9df3tuMTeEW8S # wuN10WuQHI7mpLS/IomnmYxb16lyhhwLC9kmNVZt6jGfTYB/xHUeXb9gIsdkc05s # Cxy+VdxgnzGji6dOwufI8/ufWSti1PRB1yhZsmJtLC7MDOv5EJkxrmRXhWkr6LYZ # CU52uT7CsOTKdmmwdjTUqkfswB70Js68J33Rbm3VWJlnSBAQ/ioGt50r7tqFBwT8 # HQc4CqYBT58BPb7rKrUa6dCy1uAprYl2juU3vl/nHcp2zIxIar1yzQK3OG+3h6fZ # Mrg/C5l4WiEKFgdl5sMj1xJK15aC42/UyzxUFM12usKaOtKjQAIkjx6U7HCjwfdR # BZmxTx2u7jGm9a0R3qhVhZjmIIbfLoeEHepLMOAHN+TGAl0bcxc= # =22cZ # -----END PGP SIGNATURE----- # gpg: Signature made Sun 28 Apr 2024 05:08:08 PM PDT # gpg: using RSA key AA92EBBDF0148AA61A43B8AEE4894CAC45414BB0 # gpg: Good signature from "Samuel Thibault <samuel.thibault@ens-lyon.org>" [undefined] # gpg: aka "Samuel Thibault <sthibault@debian.org>" [undefined] # gpg: aka "Samuel Thibault <samuel.thibault@gnu.org>" [unknown] # gpg: aka "Samuel Thibault <samuel.thibault@inria.fr>" [undefined] # gpg: aka "Samuel Thibault <samuel.thibault@labri.fr>" [undefined] # gpg: aka "Samuel Thibault <samuel.thibault@aquilenet.fr>" [unknown] # gpg: aka "Samuel Thibault <samuel.thibault@u-bordeaux.fr>" [unknown] # gpg: aka "Samuel Thibault <sthibault@hypra.fr>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 900C B024 B679 31D4 0F82 304B D017 8C76 7D06 9EE6 # Subkey fingerprint: AA92 EBBD F014 8AA6 1A43 B8AE E489 4CAC 4541 4BB0 * tag 'samuel-thibault' of https://people.debian.org/~sthibault/qemu: net/slirp: Use newer slirp_*_hostxfwd API Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
commit
5fee33d97a
62
net/slirp.c
62
net/slirp.c
|
@ -718,7 +718,12 @@ static SlirpState *slirp_lookup(Monitor *mon, const char *id)
|
|||
|
||||
void hmp_hostfwd_remove(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
struct in_addr host_addr = { .s_addr = INADDR_ANY };
|
||||
struct sockaddr_in host_addr = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_addr = {
|
||||
.s_addr = INADDR_ANY,
|
||||
},
|
||||
};
|
||||
int host_port;
|
||||
char buf[256];
|
||||
const char *src_str, *p;
|
||||
|
@ -755,15 +760,21 @@ void hmp_hostfwd_remove(Monitor *mon, const QDict *qdict)
|
|||
if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
|
||||
goto fail_syntax;
|
||||
}
|
||||
if (buf[0] != '\0' && !inet_aton(buf, &host_addr)) {
|
||||
if (buf[0] != '\0' && !inet_aton(buf, &host_addr.sin_addr)) {
|
||||
goto fail_syntax;
|
||||
}
|
||||
|
||||
if (qemu_strtoi(p, NULL, 10, &host_port)) {
|
||||
goto fail_syntax;
|
||||
}
|
||||
host_addr.sin_port = htons(host_port);
|
||||
|
||||
err = slirp_remove_hostfwd(s->slirp, is_udp, host_addr, host_port);
|
||||
#if SLIRP_CHECK_VERSION(4, 5, 0)
|
||||
err = slirp_remove_hostxfwd(s->slirp, (struct sockaddr *) &host_addr,
|
||||
sizeof(host_addr), is_udp ? SLIRP_HOSTFWD_UDP : 0);
|
||||
#else
|
||||
err = slirp_remove_hostfwd(s->slirp, is_udp, host_addr.sin_addr, host_port);
|
||||
#endif
|
||||
|
||||
monitor_printf(mon, "host forwarding rule for %s %s\n", src_str,
|
||||
err ? "not found" : "removed");
|
||||
|
@ -775,13 +786,24 @@ void hmp_hostfwd_remove(Monitor *mon, const QDict *qdict)
|
|||
|
||||
static int slirp_hostfwd(SlirpState *s, const char *redir_str, Error **errp)
|
||||
{
|
||||
struct in_addr host_addr = { .s_addr = INADDR_ANY };
|
||||
struct in_addr guest_addr = { .s_addr = 0 };
|
||||
struct sockaddr_in host_addr = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_addr = {
|
||||
.s_addr = INADDR_ANY,
|
||||
},
|
||||
};
|
||||
struct sockaddr_in guest_addr = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_addr = {
|
||||
.s_addr = 0,
|
||||
},
|
||||
};
|
||||
int err;
|
||||
int host_port, guest_port;
|
||||
const char *p;
|
||||
char buf[256];
|
||||
int is_udp;
|
||||
char *end;
|
||||
const char *end;
|
||||
const char *fail_reason = "Unknown reason";
|
||||
|
||||
p = redir_str;
|
||||
|
@ -802,7 +824,7 @@ static int slirp_hostfwd(SlirpState *s, const char *redir_str, Error **errp)
|
|||
fail_reason = "Missing : separator";
|
||||
goto fail_syntax;
|
||||
}
|
||||
if (buf[0] != '\0' && !inet_aton(buf, &host_addr)) {
|
||||
if (buf[0] != '\0' && !inet_aton(buf, &host_addr.sin_addr)) {
|
||||
fail_reason = "Bad host address";
|
||||
goto fail_syntax;
|
||||
}
|
||||
|
@ -811,29 +833,41 @@ static int slirp_hostfwd(SlirpState *s, const char *redir_str, Error **errp)
|
|||
fail_reason = "Bad host port separator";
|
||||
goto fail_syntax;
|
||||
}
|
||||
host_port = strtol(buf, &end, 0);
|
||||
if (*end != '\0' || host_port < 0 || host_port > 65535) {
|
||||
err = qemu_strtoi(buf, &end, 0, &host_port);
|
||||
if (err || host_port < 0 || host_port > 65535) {
|
||||
fail_reason = "Bad host port";
|
||||
goto fail_syntax;
|
||||
}
|
||||
host_addr.sin_port = htons(host_port);
|
||||
|
||||
if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
|
||||
fail_reason = "Missing guest address";
|
||||
goto fail_syntax;
|
||||
}
|
||||
if (buf[0] != '\0' && !inet_aton(buf, &guest_addr)) {
|
||||
if (buf[0] != '\0' && !inet_aton(buf, &guest_addr.sin_addr)) {
|
||||
fail_reason = "Bad guest address";
|
||||
goto fail_syntax;
|
||||
}
|
||||
|
||||
guest_port = strtol(p, &end, 0);
|
||||
if (*end != '\0' || guest_port < 1 || guest_port > 65535) {
|
||||
err = qemu_strtoi(p, &end, 0, &guest_port);
|
||||
if (err || guest_port < 1 || guest_port > 65535) {
|
||||
fail_reason = "Bad guest port";
|
||||
goto fail_syntax;
|
||||
}
|
||||
guest_addr.sin_port = htons(guest_port);
|
||||
|
||||
if (slirp_add_hostfwd(s->slirp, is_udp, host_addr, host_port, guest_addr,
|
||||
guest_port) < 0) {
|
||||
#if SLIRP_CHECK_VERSION(4, 5, 0)
|
||||
err = slirp_add_hostxfwd(s->slirp,
|
||||
(struct sockaddr *) &host_addr, sizeof(host_addr),
|
||||
(struct sockaddr *) &guest_addr, sizeof(guest_addr),
|
||||
is_udp ? SLIRP_HOSTFWD_UDP : 0);
|
||||
#else
|
||||
err = slirp_add_hostfwd(s->slirp, is_udp,
|
||||
host_addr.sin_addr, host_port,
|
||||
guest_addr.sin_addr, guest_port);
|
||||
#endif
|
||||
|
||||
if (err < 0) {
|
||||
error_setg(errp, "Could not set up host forwarding rule '%s'",
|
||||
redir_str);
|
||||
return -1;
|
||||
|
|
Loading…
Reference in New Issue