slirp updates
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEErr90SPq5RTpFUjkOsKUb9YyRecUFAliy6MAACgkQsKUb9YyR ecW3QxAAsY9j91/+DxOMNmLDYkQLBFfMrYV+NO6z1OJwlbuzYL4vbNp2PeVEAYi2 XWka3oriug5xq6EvIgdijQMwkULtMhkGMdFoSlRMvedqk3Pwviu9o90Snp4sxO+K tWcmsDpn1CKmlJyCsTLSiShKgV31/O8VRH5qE/HFEDDX5Fjqf9g2+pB2TnvlM3JA 3tjtqCnyyZjBm9Nov+oPw92TTmC+KMoO1UKKO9Hkc49HR4mPgEb4z5qS894dlOpi XmmCICZHcH8DBQFs5N8k2+CvPvLf80UmM4RhznbuwUqOrrFWRBOLEHO9iMfc6dVi M0V1vnLIYsTJmEQRSTQ9izdhSWKi2YgwcLFgi2CyTSa5rTDIyzEXlhTUbc56pd9g qtBBpmbU21MpO1Cvfe07q0zsKQ9OK/WbPkylzNwilVf0xRKrMxvJgjdKuoXfMYq2 QmKi7xu+cVz6ArfIUQ0UJ9N81sILS3gNte3DeQc+uqIkTNEFEjIAXfnfS1dQbwLW BmxNhZW6LJjfJbw7S4w9gXf14pK+wqYaQ/trohwCmrKY3S7aiZ4y5nkh9lwybT5r 9OM0iPw9hcUcULBfHKz4/z3iMm+HYV/JkfaXc7iYFoFu7r0b80nswvB2wh2gRq6W 19T0nVcaI8YFFRVT2Y1sgUyrPukfLg2mpYA6m2rt5tUMkXrupwE= =lOyX -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/thibault/tags/samuel-thibault' into staging slirp updates # gpg: Signature made Sun 26 Feb 2017 14:40:00 GMT # gpg: using RSA key 0xB0A51BF58C9179C5 # 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: AEBF 7448 FAB9 453A 4552 390E B0A5 1BF5 8C91 79C5 * remotes/thibault/tags/samuel-thibault: slirp: tcp_listen(): Don't try to close() an fd we never opened slirp: Convert mbufs to use g_malloc() and g_free() slirp: Check qemu_socket() return value in udp_listen() Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
685783c5b6
30
slirp/mbuf.c
30
slirp/mbuf.c
|
@ -10,7 +10,7 @@
|
|||
* FreeBSD. They are fixed size, determined by the MTU,
|
||||
* so that one whole packet can fit. Mbuf's cannot be
|
||||
* chained together. If there's more data than the mbuf
|
||||
* could hold, an external malloced buffer is pointed to
|
||||
* could hold, an external g_malloced buffer is pointed to
|
||||
* by m_ext (and the data pointers) and M_EXT is set in
|
||||
* the flags
|
||||
*/
|
||||
|
@ -41,26 +41,26 @@ void m_cleanup(Slirp *slirp)
|
|||
while ((struct quehead *) m != &slirp->m_usedlist) {
|
||||
next = m->m_next;
|
||||
if (m->m_flags & M_EXT) {
|
||||
free(m->m_ext);
|
||||
g_free(m->m_ext);
|
||||
}
|
||||
free(m);
|
||||
g_free(m);
|
||||
m = next;
|
||||
}
|
||||
m = (struct mbuf *) slirp->m_freelist.qh_link;
|
||||
while ((struct quehead *) m != &slirp->m_freelist) {
|
||||
next = m->m_next;
|
||||
free(m);
|
||||
g_free(m);
|
||||
m = next;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get an mbuf from the free list, if there are none
|
||||
* malloc one
|
||||
* allocate one
|
||||
*
|
||||
* Because fragmentation can occur if we alloc new mbufs and
|
||||
* free old mbufs, we mark all mbufs above mbuf_thresh as M_DOFREE,
|
||||
* which tells m_free to actually free() it
|
||||
* which tells m_free to actually g_free() it
|
||||
*/
|
||||
struct mbuf *
|
||||
m_get(Slirp *slirp)
|
||||
|
@ -71,8 +71,7 @@ m_get(Slirp *slirp)
|
|||
DEBUG_CALL("m_get");
|
||||
|
||||
if (slirp->m_freelist.qh_link == &slirp->m_freelist) {
|
||||
m = (struct mbuf *)malloc(SLIRP_MSIZE);
|
||||
if (m == NULL) goto end_error;
|
||||
m = g_malloc(SLIRP_MSIZE);
|
||||
slirp->mbuf_alloced++;
|
||||
if (slirp->mbuf_alloced > MBUF_THRESH)
|
||||
flags = M_DOFREE;
|
||||
|
@ -94,7 +93,6 @@ m_get(Slirp *slirp)
|
|||
m->m_prevpkt = NULL;
|
||||
m->resolution_requested = false;
|
||||
m->expiration_date = (uint64_t)-1;
|
||||
end_error:
|
||||
DEBUG_ARG("m = %p", m);
|
||||
return m;
|
||||
}
|
||||
|
@ -112,15 +110,15 @@ m_free(struct mbuf *m)
|
|||
remque(m);
|
||||
|
||||
/* If it's M_EXT, free() it */
|
||||
if (m->m_flags & M_EXT)
|
||||
free(m->m_ext);
|
||||
|
||||
if (m->m_flags & M_EXT) {
|
||||
g_free(m->m_ext);
|
||||
}
|
||||
/*
|
||||
* Either free() it or put it on the free list
|
||||
*/
|
||||
if (m->m_flags & M_DOFREE) {
|
||||
m->slirp->mbuf_alloced--;
|
||||
free(m);
|
||||
g_free(m);
|
||||
} else if ((m->m_flags & M_FREELIST) == 0) {
|
||||
insque(m,&m->slirp->m_freelist);
|
||||
m->m_flags = M_FREELIST; /* Clobber other flags */
|
||||
|
@ -130,7 +128,7 @@ m_free(struct mbuf *m)
|
|||
|
||||
/*
|
||||
* Copy data from one mbuf to the end of
|
||||
* the other.. if result is too big for one mbuf, malloc()
|
||||
* the other.. if result is too big for one mbuf, allocate
|
||||
* an M_EXT data segment
|
||||
*/
|
||||
void
|
||||
|
@ -160,12 +158,12 @@ m_inc(struct mbuf *m, int size)
|
|||
|
||||
if (m->m_flags & M_EXT) {
|
||||
datasize = m->m_data - m->m_ext;
|
||||
m->m_ext = (char *)realloc(m->m_ext,size);
|
||||
m->m_ext = g_realloc(m->m_ext, size);
|
||||
m->m_data = m->m_ext + datasize;
|
||||
} else {
|
||||
char *dat;
|
||||
datasize = m->m_data - m->m_dat;
|
||||
dat = (char *)malloc(size);
|
||||
dat = g_malloc(size);
|
||||
memcpy(dat, m->m_dat, m->m_size);
|
||||
|
||||
m->m_ext = dat;
|
||||
|
|
|
@ -713,7 +713,9 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
|
|||
(listen(s,1) < 0)) {
|
||||
int tmperrno = errno; /* Don't clobber the real reason we failed */
|
||||
|
||||
close(s);
|
||||
if (s >= 0) {
|
||||
closesocket(s);
|
||||
}
|
||||
sofree(so);
|
||||
/* Restore the real errno */
|
||||
#ifdef _WIN32
|
||||
|
|
|
@ -335,6 +335,10 @@ udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
|
|||
return NULL;
|
||||
}
|
||||
so->s = qemu_socket(AF_INET,SOCK_DGRAM,0);
|
||||
if (so->s < 0) {
|
||||
sofree(so);
|
||||
return NULL;
|
||||
}
|
||||
so->so_expire = curtime + SO_EXPIRE;
|
||||
insque(so, &slirp->udb);
|
||||
|
||||
|
|
Loading…
Reference in a new issue