slirp updates

-----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEmjc9NmSo3GLaCjT9nlEeAcc38HUFAlnH9HcACgkQnlEeAcc3
 8HV2whAAhNux6khw4jh+4lJru2Nj0WsoSvEJm27/pyT5L0H10JcggOF/pgC5ZaEe
 qmAk/SU2Qg5FgRII+WzX9AWDO0lEE8Taycvhcd/XVn1+JQIa9eNrLQm4aWIMZS1p
 OekqjPID2cpe99yxtSYi2kVxK5lqW31lOiaWPRRlIlDblPum6v7mbTsHQUQ4D8QG
 MCpL39TYgtE3MbywZX9H4Du3Ld6ROPGcqT7ERNsx4KSxi/RyA3j18cPyWspK0wGe
 Tl7ArH6ND6t9n7Ysk4/SpeczTu2M0CvYSoig6VtozwB8RBB0pJgi7kd0g/r9POCV
 OCZY0+LDmPVc2GTSA9BDR37nYsDqMSKRJ6jjs6Alr11r8PjW7XOwI85XBhng83Ol
 upFQR5P1SpFYZApVm+YIMCkHVg089Y+Vapizwv9ZO70Z7JB7pil31Pv6PjCIXBp/
 nBivt58EJS1wqdhit2+yTqEBfuqBwIMhvQaBtN/BiqwTEzg1anhIuXTbSh2a+uCE
 TEVzjs0hOg+qtl+KWDTdaq5dCeGnsypQfompmJaTGgx65zX/kY3uTx75TP77vTGC
 bAsJnjC5F1pIQ5sm2mrI7Popui1s6/lMyhFNB7pxSOtKJCmuqe2SFQZMCeW86h5+
 5F3MIq8QAE7JqNeZXP3I6EB8LZXHjxfaw0dql1iRlkLIZA2uejM=
 =pV42
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/thibault/tags/samuel-thibault' into staging

slirp updates

# gpg: Signature made Sun 24 Sep 2017 19:07:51 BST
# gpg:                using RSA key 0x9E511E01C737F075
# gpg: Good signature from "Samuel Thibault <samuel.thibault@aquilenet.fr>"
# gpg:                 aka "Samuel Thibault <sthibault@debian.org>"
# gpg:                 aka "Samuel Thibault <samuel.thibault@gnu.org>"
# gpg:                 aka "Samuel Thibault <samuel.thibault@inria.fr>"
# gpg:                 aka "Samuel Thibault <samuel.thibault@labri.fr>"
# gpg:                 aka "Samuel Thibault <samuel.thibault@ens-lyon.org>"
# gpg:                 aka "Samuel Thibault <samuel.thibault@u-bordeaux.fr>"
# gpg: WARNING: This key is not certified with sufficiently trusted signatures!
# gpg:          It is not certain that the signature belongs to the owner.
# Primary key fingerprint: 900C B024 B679 31D4 0F82  304B D017 8C76 7D06 9EE6
#      Subkey fingerprint: 9A37 3D36 64A8 DC62 DA0A  34FD 9E51 1E01 C737 F075

* remotes/thibault/tags/samuel-thibault:
  slirp: Add a special case for the NULL socket
  slirp: Fix intermittent send queue hangs on a socket
  slirp: Add explanation for hostfwd parsing failure

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2017-09-25 20:31:24 +01:00
commit 1e3ee83408
3 changed files with 39 additions and 44 deletions

View File

@ -496,9 +496,11 @@ static int slirp_hostfwd(SlirpState *s, const char *redir_str,
char buf[256];
int is_udp;
char *end;
const char *fail_reason = "Unknown reason";
p = redir_str;
if (!p || get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
fail_reason = "No : separators";
goto fail_syntax;
}
if (!strcmp(buf, "tcp") || buf[0] == '\0') {
@ -506,35 +508,43 @@ static int slirp_hostfwd(SlirpState *s, const char *redir_str,
} else if (!strcmp(buf, "udp")) {
is_udp = 1;
} else {
fail_reason = "Bad protocol name";
goto fail_syntax;
}
if (!legacy_format) {
if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
fail_reason = "Missing : separator";
goto fail_syntax;
}
if (buf[0] != '\0' && !inet_aton(buf, &host_addr)) {
fail_reason = "Bad host address";
goto fail_syntax;
}
}
if (get_str_sep(buf, sizeof(buf), &p, legacy_format ? ':' : '-') < 0) {
fail_reason = "Bad host port separator";
goto fail_syntax;
}
host_port = strtol(buf, &end, 0);
if (*end != '\0' || host_port < 0 || host_port > 65535) {
fail_reason = "Bad host port";
goto fail_syntax;
}
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)) {
fail_reason = "Bad guest address";
goto fail_syntax;
}
guest_port = strtol(p, &end, 0);
if (*end != '\0' || guest_port < 1 || guest_port > 65535) {
fail_reason = "Bad guest port";
goto fail_syntax;
}
@ -547,7 +557,8 @@ static int slirp_hostfwd(SlirpState *s, const char *redir_str,
return 0;
fail_syntax:
error_setg(errp, "Invalid host forwarding rule '%s'", redir_str);
error_setg(errp, "Invalid host forwarding rule '%s' (%s)", redir_str,
fail_reason);
return -1;
}

View File

@ -30,7 +30,6 @@ if_init(Slirp *slirp)
{
slirp->if_fastq.qh_link = slirp->if_fastq.qh_rlink = &slirp->if_fastq;
slirp->if_batchq.qh_link = slirp->if_batchq.qh_rlink = &slirp->if_batchq;
slirp->next_m = (struct mbuf *) &slirp->if_batchq;
}
/*
@ -74,14 +73,16 @@ if_output(struct socket *so, struct mbuf *ifm)
* We mustn't put this packet back on the fastq (or we'll send it out of order)
* XXX add cache here?
*/
for (ifq = (struct mbuf *) slirp->if_batchq.qh_rlink;
(struct quehead *) ifq != &slirp->if_batchq;
ifq = ifq->ifq_prev) {
if (so == ifq->ifq_so) {
/* A match! */
ifm->ifq_so = so;
ifs_insque(ifm, ifq->ifs_prev);
goto diddit;
if (so) {
for (ifq = (struct mbuf *) slirp->if_batchq.qh_rlink;
(struct quehead *) ifq != &slirp->if_batchq;
ifq = ifq->ifq_prev) {
if (so == ifq->ifq_so) {
/* A match! */
ifm->ifq_so = so;
ifs_insque(ifm, ifq->ifs_prev);
goto diddit;
}
}
}
@ -100,10 +101,6 @@ if_output(struct socket *so, struct mbuf *ifm)
}
} else {
ifq = (struct mbuf *) slirp->if_batchq.qh_rlink;
/* Set next_m if the queue was empty so far */
if ((struct quehead *) slirp->next_m == &slirp->if_batchq) {
slirp->next_m = ifm;
}
}
/* Create a new doubly linked list for this session */
@ -143,21 +140,18 @@ diddit:
}
/*
* Send a packet
* We choose a packet based on its position in the output queues;
* Send one packet from each session.
* If there are packets on the fastq, they are sent FIFO, before
* everything else. Otherwise we choose the first packet from the
* batchq and send it. the next packet chosen will be from the session
* after this one, then the session after that one, and so on.. So,
* for example, if there are 3 ftp session's fighting for bandwidth,
* everything else. Then we choose the first packet from each
* batchq session (socket) and send it.
* For example, if there are 3 ftp sessions fighting for bandwidth,
* one packet will be sent from the first session, then one packet
* from the second session, then one packet from the third, then back
* to the first, etc. etc.
* from the second session, then one packet from the third.
*/
void if_start(Slirp *slirp)
{
uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
bool from_batchq, next_from_batchq;
bool from_batchq = false;
struct mbuf *ifm, *ifm_next, *ifqt;
DEBUG_CALL("if_start");
@ -167,26 +161,29 @@ void if_start(Slirp *slirp)
}
slirp->if_start_busy = true;
struct mbuf *batch_head = NULL;
if (slirp->if_batchq.qh_link != &slirp->if_batchq) {
batch_head = (struct mbuf *) slirp->if_batchq.qh_link;
}
if (slirp->if_fastq.qh_link != &slirp->if_fastq) {
ifm_next = (struct mbuf *) slirp->if_fastq.qh_link;
next_from_batchq = false;
} else if ((struct quehead *) slirp->next_m != &slirp->if_batchq) {
/* Nothing on fastq, pick up from batchq via next_m */
ifm_next = slirp->next_m;
next_from_batchq = true;
} else if (batch_head) {
/* Nothing on fastq, pick up from batchq */
ifm_next = batch_head;
from_batchq = true;
} else {
ifm_next = NULL;
}
while (ifm_next) {
ifm = ifm_next;
from_batchq = next_from_batchq;
ifm_next = ifm->ifq_next;
if ((struct quehead *) ifm_next == &slirp->if_fastq) {
/* No more packets in fastq, switch to batchq */
ifm_next = slirp->next_m;
next_from_batchq = true;
ifm_next = batch_head;
from_batchq = true;
}
if ((struct quehead *) ifm_next == &slirp->if_batchq) {
/* end of batchq */
@ -199,11 +196,6 @@ void if_start(Slirp *slirp)
continue;
}
if (ifm == slirp->next_m) {
/* Set which packet to send on next iteration */
slirp->next_m = ifm->ifq_next;
}
/* Remove it from the queue */
ifqt = ifm->ifq_prev;
remque(ifm);
@ -214,15 +206,8 @@ void if_start(Slirp *slirp)
insque(next, ifqt);
ifs_remque(ifm);
if (!from_batchq) {
/* Next packet in fastq is from the same session */
ifm_next = next;
next_from_batchq = false;
} else if ((struct quehead *) slirp->next_m == &slirp->if_batchq) {
/* Set next_m and ifm_next if the session packet is now the
* only one on batchq */
slirp->next_m = ifm_next = next;
}
}

View File

@ -183,7 +183,6 @@ struct Slirp {
/* if states */
struct quehead if_fastq; /* fast queue (for interactive data) */
struct quehead if_batchq; /* queue for non-interactive data */
struct mbuf *next_m; /* pointer to next mbuf to output */
bool if_start_busy; /* avoid if_start recursion */
/* ip states */