Commit fdbfba8c authored by Marc-André Lureau's avatar Marc-André Lureau Committed by Samuel Thibault
Browse files

slirp: remove slirp_ prefix for socket wrappers



QEMU wraps the socket functions in os-win32.h, but in commit
a9d8b3ec, the header inclusion was dropped,
breaking libslirp on Windows.

There are already a few socket functions that are wrapped in libslirp,
with "slirp_" prefix, but many of them are missing, and we are going
to wrap the missing functions in a second patch.

Using "slirp_" prefix avoids the conflict with socket function #define
wrappers in QEMU os-win32.h, but they are quite intrusive. In the end,
the functions should behave the same as original one, but with errno
being set. To avoid the churn, and potential confusion, remove the
"slirp_" prefix. A series of #undef is necessary until libslirp is
made standalone to prevent the #define conflict with QEMU.

Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20190212160953.29051-2-marcandre.lureau@redhat.com>
Signed-off-by: default avatarSamuel Thibault <samuel.thibault@ens-lyon.org>
parent 0b5e750b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
void icmp_detach(struct socket *so)
{
    so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque);
    slirp_closesocket(so->s);
    closesocket(so->s);
    sofree(so);
}

@@ -421,7 +421,7 @@ void icmp_receive(struct socket *so)
    icp = mtod(m, struct icmp *);

    id = icp->icmp_id;
    len = slirp_recv(so->s, icp, M_ROOM(m), 0);
    len = recv(so->s, icp, M_ROOM(m), 0);
    /*
     * The behavior of reading SOCK_DGRAM+IPPROTO_ICMP sockets is inconsistent
     * between host OSes.  On Linux, only the ICMP header and payload is
+7 −7
Original line number Diff line number Diff line
@@ -98,16 +98,16 @@ slirp_socketpair_with_oob(int sv[2])
        goto err;
    }

    slirp_closesocket(s);
    closesocket(s);
    return 0;

err:
    g_critical("slirp_socketpair(): %s", strerror(errno));
    if (s >= 0) {
        slirp_closesocket(s);
        closesocket(s);
    }
    if (sv[1] >= 0) {
        slirp_closesocket(sv[1]);
        closesocket(sv[1]);
    }
    return -1;
}
@@ -211,16 +211,16 @@ fork_exec(struct socket *so, const char *ex)
    if (err) {
        g_critical("fork_exec: %s", err->message);
        g_error_free(err);
        slirp_closesocket(sp[0]);
        slirp_closesocket(sp[1]);
        closesocket(sp[0]);
        closesocket(sp[1]);
        return 0;
    }

    so->s = sp[0];
    slirp_closesocket(sp[1]);
    closesocket(sp[1]);
    slirp_socket_set_fast_reuse(so->s);
    opt = 1;
    slirp_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
    setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
    slirp_set_nonblock(so->s);
    so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque);
    return 1;
+1 −1
Original line number Diff line number Diff line
@@ -961,7 +961,7 @@ int slirp_remove_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr,
            addr.sin_addr.s_addr == host_addr.s_addr &&
            addr.sin_port == port) {
            so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque);
            slirp_closesocket(so->s);
            closesocket(so->s);
            sofree(so);
            return 0;
        }
+7 −7
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ soread(struct socket *so)
	 */
	sopreprbuf(so, iov, &n);

	nn = slirp_recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
	nn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
	if (nn <= 0) {
		if (nn < 0 && (errno == EINTR || errno == EAGAIN))
			return 0;
@@ -201,7 +201,7 @@ soread(struct socket *so)
				if (getpeername(so->s, paddr, &alen) < 0) {
					err = errno;
				} else {
					slirp_getsockopt(so->s, SOL_SOCKET, SO_ERROR,
					getsockopt(so->s, SOL_SOCKET, SO_ERROR,
						&err, &elen);
				}
			}
@@ -231,7 +231,7 @@ soread(struct socket *so)
	 */
	if (n == 2 && nn == iov[0].iov_len) {
            int ret;
            ret = slirp_recv(so->s, iov[1].iov_base, iov[1].iov_len,0);
            ret = recv(so->s, iov[1].iov_base, iov[1].iov_len,0);
            if (ret > 0)
                nn += ret;
        }
@@ -552,7 +552,7 @@ sorecvfrom(struct socket *so)
	   */
	  len = M_FREEROOM(m);
	  /* if (so->so_fport != htons(53)) { */
	  slirp_ioctlsocket(so->s, FIONREAD, &n);
	  ioctlsocket(so->s, FIONREAD, &n);

	  if (n > len) {
	    n = (m->m_data - m->m_dat) + m->m_len + n + 1;
@@ -724,7 +724,7 @@ tcp_listen(Slirp *slirp, uint32_t haddr, unsigned hport, uint32_t laddr,
		int tmperrno = errno; /* Don't clobber the real reason we failed */

                if (s >= 0) {
                    slirp_closesocket(s);
                    closesocket(s);
                }
		sofree(so);
		/* Restore the real errno */
@@ -735,9 +735,9 @@ tcp_listen(Slirp *slirp, uint32_t haddr, unsigned hport, uint32_t laddr,
#endif
		return NULL;
	}
	slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
	setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
	opt = 1;
	slirp_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(int));
	setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(int));

	getsockname(s,(struct sockaddr *)&addr,&addrlen);
	so->so_ffamily = AF_INET;
+5 −5
Original line number Diff line number Diff line
@@ -337,7 +337,7 @@ tcp_close(struct tcpcb *tp)
	if (so == slirp->tcp_last_so)
		slirp->tcp_last_so = &slirp->tcb;
	so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque);
	slirp_closesocket(so->s);
	closesocket(so->s);
	sbfree(&so->so_rcv);
	sbfree(&so->so_snd);
	sofree(so);
@@ -416,9 +416,9 @@ int tcp_fconnect(struct socket *so, unsigned short af)
    so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque);
    slirp_socket_set_fast_reuse(s);
    opt = 1;
    slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
    setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
    opt = 1;
    slirp_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
    setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));

    addr = so->fhost.ss;
    DEBUG_CALL(" connect()ing");
@@ -489,7 +489,7 @@ void tcp_connect(struct socket *inso)
    so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque);
    slirp_socket_set_fast_reuse(s);
    opt = 1;
    slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
    setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
    slirp_socket_set_nodelay(s);

    so->fhost.ss = addr;
@@ -499,7 +499,7 @@ void tcp_connect(struct socket *inso)
    if (inso->so_state & SS_FACCEPTONCE) {
        /* If we only accept once, close the accept() socket */
        so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque);
        slirp_closesocket(so->s);
        closesocket(so->s);

        /* Don't select it yet, even though we have an FD */
        /* if it's not FACCEPTONCE, it's already NOFDREF */
Loading