All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
@ 2018-11-14 12:36 Marc-André Lureau
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 01/41] slirp: move socket pair creation in helper function Marc-André Lureau
                   ` (43 more replies)
  0 siblings, 44 replies; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Hi,

Based-on: https://people.debian.org/~sthibault/qemu.git/ slirp branch

This series goal is to allow building libslirp as an independent library.

While looking at making SLIRP a seperate running process, I thought
that having an independent library from QEMU would be a first step.

There has been some attempts to make slirp a seperate project in the past.
(https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg01092.html)
Unfortunately, they forked from QEMU and didn't provide enough
compatibility for QEMU to make use of it (in particular, vmstate
handling was removed, they lost git history etc). Furthermore, they
are not maintained as far as I can see.

I would propose to make slirp a seperate project, that can initially
be used by QEMU as a submodule, keeping Makefile.objs until a proper
shared library with stability guarantees etc is ready..

The subproject could created by preserving git tags, and cleaning up the code style, this way:

git filter-branch --tree-filter "if ls * 1> /dev/null 2>&1; then clang-format -i * /dev/null; fi " -f --subdirectory-filter "slirp" --prune-empty --tag-name-filter cat -- --all
(my clang-format https://gist.github.com/elmarco/cb20c8d92007df0e2fb8a2404678ac73)

What do you think?

Marc-André Lureau (41):
  slirp: move socket pair creation in helper function
  glib-compat: add g_spawn_async_with_fds() fallback
  slirp: simplify fork_exec()
  slirp: remove unused M_TRAILINGSPACE
  slirp: use a callback structure to interface with qemu
  slirp: add a callback for qemu_chr_fe_write_all()
  slirp: add clock_get_ns() callback
  slirp: add callbacks for timer
  slirp: add a set_nonblock() callback
  slirp: remove PROBE_CONN dead-code
  slirp: remove FULL_BOLT
  slirp: remove the disabled readv()/writev() code path
  slirp: remove HAVE_SYS_SIGNAL_H
  slirp: remove unused HAVE_SYS_BITYPES_H
  slirp: remove NO_UNIX_SOCKETS
  slirp: remove unused HAVE_SYS_STROPTS_H
  slirp: remove unused HAVE_ARPA_INET_H
  slirp: remove unused HAVE_SYS_WAIT_H
  slirp: remove unused HAVE_SYS_SELECT_H
  slirp: remove HAVE_SYS_IOCTL_H
  slirp: remove HAVE_SYS_FILIO_H
  slirp: remove unused DECLARE_IOVEC
  slirp: remove unused HAVE_INET_ATON
  slirp: replace HOST_WORDS_BIGENDIAN with glib equivalent
  slirp: replace SIZEOF_CHAR_P with glib equivalent
  slirp: replace compile time DO_KEEPALIVE
  slirp: remove unused global slirp_instance
  slirp: replace error_report() with g_critical()
  slirp: improve a bit the debug macros
  slirp: replace trace functions with DEBUG calls
  slirp: add a callback to log guest errors
  slirp: remove unused sbflush()
  slirp: replace qemu_notify_event() with a callback
  slirp: remove #if notdef dead code
  slirp: NULL is defined by glib (at least)
  slirp: remove dead TCP_ACK_HACK code
  slirp: replace ARRAY_SIZE with G_N_ELEMENTS
  net: do not depend on slirp internals
  slirp: move QEMU state saving to a separate unit
  slirp: replace remaining QEMU dependency
  build-sys: add a basic meson build

 include/glib-compat.h |  56 ++++++
 net/colo.h            |   3 +-
 net/util.h            |  55 +++++
 slirp/debug.h         |  47 ++++-
 slirp/ip.h            |  24 ++-
 slirp/ip6.h           |   8 +-
 slirp/ip6_icmp.h      |  22 +-
 slirp/libslirp.h      |  35 +++-
 slirp/main.h          |   4 -
 slirp/mbuf.h          |   1 -
 slirp/qtailq.h        | 218 ++++++++++++++++++++
 slirp/sbuf.h          |   3 +-
 slirp/slirp.h         |  58 ++----
 slirp/slirp_config.h  |  86 --------
 slirp/socket.h        |   1 +
 slirp/state.h         |   9 +
 slirp/tcp.h           |   4 +-
 slirp/util.h          | 145 +++++++++++++
 net/colo-compare.c    |   1 +
 net/colo.c            |   1 +
 net/filter-rewriter.c |   1 +
 net/slirp.c           |  65 +++++-
 slirp/arp_table.c     |  13 +-
 slirp/bootp.c         |   4 +-
 slirp/cksum.c         |   5 +-
 slirp/dhcpv6.c        |  19 +-
 slirp/dnssearch.c     |   1 -
 slirp/if.c            |   6 +-
 slirp/ip6_icmp.c      |  34 ++--
 slirp/ip6_input.c     |   1 -
 slirp/ip6_output.c    |   2 -
 slirp/ip_icmp.c       |  25 ++-
 slirp/ip_input.c      | 201 ------------------
 slirp/ip_output.c     |   1 -
 slirp/mbuf.c          |   3 +-
 slirp/misc.c          | 188 +++++++++--------
 slirp/ncsi.c          |   5 +-
 slirp/ndp_table.c     |  20 +-
 slirp/sbuf.c          |   8 +-
 slirp/slirp.c         | 458 +++---------------------------------------
 slirp/socket.c        |  72 +++----
 slirp/state.c         | 394 ++++++++++++++++++++++++++++++++++++
 slirp/tcp_input.c     |  86 ++------
 slirp/tcp_output.c    |   3 +-
 slirp/tcp_subr.c      |  21 +-
 slirp/tcp_timer.c     |   3 +-
 slirp/tftp.c          |  18 +-
 slirp/udp.c           |  13 +-
 slirp/udp6.c          |   8 +-
 slirp/util.c          | 176 ++++++++++++++++
 stubs/slirp.c         |   2 +-
 Makefile.objs         |   1 -
 slirp/Makefile.objs   |   4 +-
 slirp/meson.build     |  48 +++++
 slirp/trace-events    |   5 -
 55 files changed, 1547 insertions(+), 1148 deletions(-)
 create mode 100644 slirp/qtailq.h
 delete mode 100644 slirp/slirp_config.h
 create mode 100644 slirp/state.h
 create mode 100644 slirp/util.h
 create mode 100644 slirp/state.c
 create mode 100644 slirp/util.c
 create mode 100644 slirp/meson.build
 delete mode 100644 slirp/trace-events

-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 01/41] slirp: move socket pair creation in helper function
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-19 22:46   ` Samuel Thibault
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 02/41] glib-compat: add g_spawn_async_with_fds() fallback Marc-André Lureau
                   ` (42 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Originally, the patch was fixing a bunch of issues, but Peter beat me
to it with earlier commit "slirp: fork_exec(): create and connect
child socket before fork()".

Factor out socket pair creation, to simplify the fork_exec() code.
Use the name socketpair_with_oob() since the code is actually similar
to what socketpair() would do, except that it uses TCP sockets, for
SLIRP to be able to call send with MSG_OOB (since SO_OOBINLINE is set,
this could probably be faked instead on regular unix sockets though).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/misc.c | 142 +++++++++++++++++++++++++--------------------------
 1 file changed, 71 insertions(+), 71 deletions(-)

diff --git a/slirp/misc.c b/slirp/misc.c
index 4840187750..7362e14339 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -73,85 +73,92 @@ fork_exec(struct socket *so, const char *ex)
 
 #else
 
-/*
- * XXX This is ugly
- * We create and bind a socket, then fork off to another
- * process, which connects to this socket, after which we
- * exec the wanted program.  If something (strange) happens,
- * the accept() call could block us forever.
- */
+static int
+slirp_socketpair_with_oob(int sv[2])
+{
+    struct sockaddr_in addr = {
+        .sin_family = AF_INET,
+        .sin_port = 0,
+        .sin_addr.s_addr = INADDR_ANY,
+    };
+    socklen_t addrlen = sizeof(addr);
+    int ret, s;
+
+    sv[1] = -1;
+    s = qemu_socket(AF_INET, SOCK_STREAM, 0);
+    if (s < 0 || bind(s, (struct sockaddr *)&addr, addrlen) < 0 ||
+        listen(s, 1) < 0 ||
+        getsockname(s, (struct sockaddr *)&addr, &addrlen) < 0) {
+        goto err;
+    }
+
+    sv[1] = qemu_socket(AF_INET, SOCK_STREAM, 0);
+    if (sv[1] < 0) {
+        goto err;
+    }
+    /*
+     * This connect won't block because we've already listen()ed on
+     * the server end (even though we won't accept() the connection
+     * until later on).
+     */
+    do {
+        ret = connect(sv[1], (struct sockaddr *)&addr, addrlen);
+    } while (ret < 0 && errno == EINTR);
+    if (ret < 0) {
+        goto err;
+    }
+
+    do {
+        sv[0] = accept(s, (struct sockaddr *)&addr, &addrlen);
+    } while (sv[0] < 0 && errno == EINTR);
+    if (sv[0] < 0) {
+        goto err;
+    }
+
+    closesocket(s);
+    return 0;
+
+err:
+    error_report("Error: slirp_socketpair(): %s", strerror(errno));
+    if (s >= 0) {
+        closesocket(s);
+    }
+    if (sv[1] >= 0) {
+        closesocket(sv[1]);
+    }
+    return -1;
+}
+
 int
 fork_exec(struct socket *so, const char *ex)
 {
-        int s, cs;
-        struct sockaddr_in addr, csaddr;
-	socklen_t addrlen = sizeof(addr);
-        socklen_t csaddrlen = sizeof(csaddr);
-	int opt;
 	char **argv;
-	int ret;
+	int opt, c, sp[2];
 	pid_t pid;
 
 	DEBUG_CALL("fork_exec");
 	DEBUG_ARG("so = %p", so);
 	DEBUG_ARG("ex = %p", ex);
 
-    addr.sin_family = AF_INET;
-    addr.sin_port = 0;
-    addr.sin_addr.s_addr = INADDR_ANY;
-
-    s = qemu_socket(AF_INET, SOCK_STREAM, 0);
-    if (s < 0 || bind(s, (struct sockaddr *)&addr, addrlen) < 0 ||
-        listen(s, 1) < 0) {
-        error_report("Error: inet socket: %s", strerror(errno));
-        if (s >= 0) {
-            closesocket(s);
-        }
+    if (slirp_socketpair_with_oob(sp) < 0) {
         return 0;
     }
 
-        if (getsockname(s, (struct sockaddr *)&csaddr, &csaddrlen) < 0) {
-            closesocket(s);
-            return 0;
-        }
-        cs = qemu_socket(AF_INET, SOCK_STREAM, 0);
-        if (cs < 0) {
-            closesocket(s);
-            return 0;
-        }
-        csaddr.sin_addr = loopback_addr;
-        /*
-         * This connect won't block because we've already listen()ed on
-         * the server end (even though we won't accept() the connection
-         * until later on).
-         */
-        do {
-            ret = connect(cs, (struct sockaddr *)&csaddr, csaddrlen);
-        } while (ret < 0 && errno == EINTR);
-        if (ret < 0) {
-            closesocket(s);
-            closesocket(cs);
-            return 0;
-        }
-
 	pid = fork();
 	switch(pid) {
 	 case -1:
 		error_report("Error: fork failed: %s", strerror(errno));
-                closesocket(cs);
-		close(s);
+		closesocket(sp[0]);
+		closesocket(sp[1]);
 		return 0;
 
 	 case 0:
-                setsid();
-
-		/* Set the DISPLAY */
-                close(s);
-                dup2(cs, 0);
-                dup2(cs, 1);
-                dup2(cs, 2);
-		for (s = getdtablesize() - 1; s >= 3; s--)
-		   close(s);
+		setsid();
+		dup2(sp[1], 0);
+		dup2(sp[1], 1);
+		dup2(sp[1], 2);
+		for (c = getdtablesize() - 1; c >= 3; c--)
+		   close(c);
 
                 argv = g_strsplit(ex, " ", -1);
 		execvp(argv[0], (char **)argv);
@@ -163,19 +170,12 @@ fork_exec(struct socket *so, const char *ex)
 		exit(1);
 
 	 default:
+		so->s = sp[0];
+		closesocket(sp[1]);
 		qemu_add_child_watch(pid);
-                closesocket(cs);
-                /*
-                 * This should never block, because we already connect()ed
-                 * on the child end before we forked.
-                 */
-                do {
-                    so->s = accept(s, (struct sockaddr *)&addr, &addrlen);
-                } while (so->s < 0 && errno == EINTR);
-                closesocket(s);
-                socket_set_fast_reuse(so->s);
-                opt = 1;
-                qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
+		socket_set_fast_reuse(so->s);
+		opt = 1;
+		qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
 		qemu_set_nonblock(so->s);
 		return 1;
 	}
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 02/41] glib-compat: add g_spawn_async_with_fds() fallback
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 01/41] slirp: move socket pair creation in helper function Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-19 22:50   ` Samuel Thibault
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 03/41] slirp: simplify fork_exec() Marc-André Lureau
                   ` (41 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/glib-compat.h | 56 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/include/glib-compat.h b/include/glib-compat.h
index fdf95a255d..8a078c5288 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -83,6 +83,62 @@ static inline gboolean g_strv_contains_qemu(const gchar *const *strv,
 }
 #define g_strv_contains(a, b) g_strv_contains_qemu(a, b)
 
+#if !GLIB_CHECK_VERSION(2, 58, 0)
+typedef struct QemuGSpawnFds {
+    GSpawnChildSetupFunc child_setup;
+    gpointer user_data;
+    gint stdin_fd;
+    gint stdout_fd;
+    gint stderr_fd;
+} QemuGSpawnFds;
+
+static inline void
+qemu_gspawn_fds_setup(gpointer user_data)
+{
+    QemuGSpawnFds *q = (QemuGSpawnFds *)user_data;
+
+    dup2(q->stdin_fd, 0);
+    dup2(q->stdout_fd, 1);
+    dup2(q->stderr_fd, 2);
+    q->child_setup(q->user_data);
+}
+#endif
+
+static inline gboolean
+g_spawn_async_with_fds_qemu(const gchar *working_directory,
+                            gchar **argv,
+                            gchar **envp,
+                            GSpawnFlags flags,
+                            GSpawnChildSetupFunc child_setup,
+                            gpointer user_data,
+                            GPid *child_pid,
+                            gint stdin_fd,
+                            gint stdout_fd,
+                            gint stderr_fd,
+                            GError **error)
+{
+#if GLIB_CHECK_VERSION(2, 58, 0)
+    return g_spawn_async_with_fds(working_directory, argv, envp, flags,
+                                  child_setup, user_data,
+                                  child_pid, stdin_fd, stdout_fd, stderr_fd,
+                                  error);
+#else
+    QemuGSpawnFds setup = {
+        .child_setup = child_setup,
+        .user_data = user_data,
+        .stdin_fd = stdin_fd,
+        .stdout_fd = stdout_fd,
+        .stderr_fd = stderr_fd,
+    };
+
+    return g_spawn_async(working_directory, argv, envp, flags,
+                         qemu_gspawn_fds_setup, &setup,
+                         child_pid, error);
+#endif
+}
+
+#define g_spawn_async_with_fds(wd, argv, env, f, c, d, p, ifd, ofd, efd, err) \
+    g_spawn_async_with_fds_qemu(wd, argv, env, f, c, d, p, ifd, ofd, efd, err)
 
 #if defined(_WIN32) && !GLIB_CHECK_VERSION(2, 50, 0)
 /*
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 03/41] slirp: simplify fork_exec()
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 01/41] slirp: move socket pair creation in helper function Marc-André Lureau
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 02/41] glib-compat: add g_spawn_async_with_fds() fallback Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 14:22   ` Daniel P. Berrangé
  2018-11-19 22:56   ` Samuel Thibault
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 04/41] slirp: remove unused M_TRAILINGSPACE Marc-André Lureau
                   ` (40 subsequent siblings)
  43 siblings, 2 replies; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Use g_spawn_async_with_fds() to setup the child.

GSpawn handles reaping the child, and closing parent file descriptors.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/misc.c | 75 +++++++++++++++++++++++++---------------------------
 1 file changed, 36 insertions(+), 39 deletions(-)

diff --git a/slirp/misc.c b/slirp/misc.c
index 7362e14339..7972b9b05b 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -129,56 +129,53 @@ err:
     return -1;
 }
 
+static void
+fork_exec_child_setup(gpointer data)
+{
+    setsid();
+}
+
 int
 fork_exec(struct socket *so, const char *ex)
 {
-	char **argv;
-	int opt, c, sp[2];
-	pid_t pid;
+    GError *err = NULL;
+    char **argv;
+    int opt, sp[2];
 
-	DEBUG_CALL("fork_exec");
-	DEBUG_ARG("so = %p", so);
-	DEBUG_ARG("ex = %p", ex);
+    DEBUG_CALL("fork_exec");
+    DEBUG_ARG("so = %p", so);
+    DEBUG_ARG("ex = %p", ex);
 
     if (slirp_socketpair_with_oob(sp) < 0) {
         return 0;
     }
 
-	pid = fork();
-	switch(pid) {
-	 case -1:
-		error_report("Error: fork failed: %s", strerror(errno));
-		closesocket(sp[0]);
-		closesocket(sp[1]);
-		return 0;
-
-	 case 0:
-		setsid();
-		dup2(sp[1], 0);
-		dup2(sp[1], 1);
-		dup2(sp[1], 2);
-		for (c = getdtablesize() - 1; c >= 3; c--)
-		   close(c);
+    argv = g_strsplit(ex, " ", -1);
+    g_spawn_async_with_fds(NULL /* cwd */,
+                           argv,
+                           NULL /* env */,
+                           G_SPAWN_SEARCH_PATH,
+                           fork_exec_child_setup, NULL /* data */,
+                           NULL /* child_pid */,
+                           sp[1], sp[1], sp[1],
+                           &err);
+    g_strfreev(argv);
 
-                argv = g_strsplit(ex, " ", -1);
-		execvp(argv[0], (char **)argv);
-
-		/* Ooops, failed, let's tell the user why */
-        fprintf(stderr, "Error: execvp of %s failed: %s\n",
-                argv[0], strerror(errno));
-		close(0); close(1); close(2); /* XXX */
-		exit(1);
+    if (err) {
+        error_report("%s", err->message);
+        g_error_free(err);
+        closesocket(sp[0]);
+        closesocket(sp[1]);
+        return 0;
+    }
 
-	 default:
-		so->s = sp[0];
-		closesocket(sp[1]);
-		qemu_add_child_watch(pid);
-		socket_set_fast_reuse(so->s);
-		opt = 1;
-		qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
-		qemu_set_nonblock(so->s);
-		return 1;
-	}
+    so->s = sp[0];
+    closesocket(sp[1]);
+    socket_set_fast_reuse(so->s);
+    opt = 1;
+    qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
+    qemu_set_nonblock(so->s);
+    return 1;
 }
 #endif
 
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 04/41] slirp: remove unused M_TRAILINGSPACE
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (2 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 03/41] slirp: simplify fork_exec() Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:32   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 05/41] slirp: use a callback structure to interface with qemu Marc-André Lureau
                   ` (39 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/mbuf.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/slirp/mbuf.h b/slirp/mbuf.h
index bfdf8c4577..cbf17e136b 100644
--- a/slirp/mbuf.h
+++ b/slirp/mbuf.h
@@ -72,7 +72,6 @@
  * How much free room there is
  */
 #define M_FREEROOM(m) (M_ROOM(m) - (m)->m_len)
-#define M_TRAILINGSPACE M_FREEROOM
 
 struct mbuf {
 	/* XXX should union some of these! */
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 05/41] slirp: use a callback structure to interface with qemu
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (3 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 04/41] slirp: remove unused M_TRAILINGSPACE Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:10   ` Philippe Mathieu-Daudé
  2018-11-14 14:30   ` Stefan Hajnoczi
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 06/41] slirp: add a callback for qemu_chr_fe_write_all() Marc-André Lureau
                   ` (38 subsequent siblings)
  43 siblings, 2 replies; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

This will bring slirp a bit forward to the state of an independent
project.

This could be squashed with earlier submitted "slirp: associate
slirp_output".

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/libslirp.h |  7 +++++--
 slirp/slirp.h    |  2 +-
 net/slirp.c      |  6 +++++-
 slirp/ncsi.c     |  2 +-
 slirp/slirp.c    | 10 +++++-----
 5 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 04b6db9f49..36d5fb9163 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -5,7 +5,10 @@
 
 typedef struct Slirp Slirp;
 
-typedef void (*slirp_output)(void *opaque, const uint8_t *pkt, int pkt_len);
+typedef struct SlirpCb {
+    void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
+} SlirpCb;
+
 
 Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
                   struct in_addr vnetmask, struct in_addr vhost,
@@ -17,7 +20,7 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
                   struct in_addr vdhcp_start, struct in_addr vnameserver,
                   struct in6_addr vnameserver6, const char **vdnssearch,
                   const char *vdomainname,
-                  slirp_output output,
+                  const SlirpCb *callbacks,
                   void *opaque);
 void slirp_cleanup(Slirp *slirp);
 
diff --git a/slirp/slirp.h b/slirp/slirp.h
index de299aa36c..f7c087456a 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -220,7 +220,7 @@ struct Slirp {
     GRand *grand;
     QEMUTimer *ra_timer;
 
-    slirp_output output;
+    const SlirpCb *cb;
     void *opaque;
 };
 
diff --git a/net/slirp.c b/net/slirp.c
index dfc72cfc2e..233f66b1ef 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -140,6 +140,10 @@ static NetClientInfo net_slirp_info = {
     .cleanup = net_slirp_cleanup,
 };
 
+static SlirpCb slirp_cb = {
+    .output = net_slirp_output,
+};
+
 static int net_slirp_init(NetClientState *peer, const char *model,
                           const char *name, int restricted,
                           bool ipv4, const char *vnetwork, const char *vhost,
@@ -379,7 +383,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
                           vhostname, tftp_server_name,
                           tftp_export, bootfile, dhcp,
                           dns, ip6_dns, dnssearch, vdomainname,
-                          net_slirp_output, s);
+                          &slirp_cb, s);
     QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry);
 
     for (config = slirp_configs; config; config = config->next) {
diff --git a/slirp/ncsi.c b/slirp/ncsi.c
index d7701f7785..10decfb5ef 100644
--- a/slirp/ncsi.c
+++ b/slirp/ncsi.c
@@ -163,5 +163,5 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
     *pchecksum = htonl(checksum);
     ncsi_rsp_len += 4;
 
-    slirp->output(slirp->opaque, ncsi_reply, ETH_HLEN + ncsi_rsp_len);
+    slirp->cb->output(slirp->opaque, ncsi_reply, ETH_HLEN + ncsi_rsp_len);
 }
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 0e4ade3e4a..7213915bf3 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -288,14 +288,14 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
                   struct in_addr vdhcp_start, struct in_addr vnameserver,
                   struct in6_addr vnameserver6, const char **vdnssearch,
                   const char *vdomainname,
-                  slirp_output output,
+                  const SlirpCb *callbacks,
                   void *opaque)
 {
     Slirp *slirp = g_malloc0(sizeof(Slirp));
 
     slirp_init_once();
 
-    slirp->output = output;
+    slirp->cb = callbacks;
     slirp->grand = g_rand_new();
     slirp->restricted = restricted;
 
@@ -843,7 +843,7 @@ static void arp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
             rah->ar_sip = ah->ar_tip;
             memcpy(rah->ar_tha, ah->ar_sha, ETH_ALEN);
             rah->ar_tip = ah->ar_sip;
-            slirp->output(slirp->opaque, arp_reply, sizeof(arp_reply));
+            slirp->cb->output(slirp->opaque, arp_reply, sizeof(arp_reply));
         }
         break;
     case ARPOP_REPLY:
@@ -943,7 +943,7 @@ static int if_encap4(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh,
             /* target IP */
             rah->ar_tip = iph->ip_dst.s_addr;
             slirp->client_ipaddr = iph->ip_dst;
-            slirp->output(slirp->opaque, arp_req, sizeof(arp_req));
+            slirp->cb->output(slirp->opaque, arp_req, sizeof(arp_req));
             ifm->resolution_requested = true;
 
             /* Expire request and drop outgoing packet after 1 second */
@@ -1029,7 +1029,7 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
                 eh->h_dest[0], eh->h_dest[1], eh->h_dest[2],
                 eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]));
     memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len);
-    slirp->output(slirp->opaque, buf, ifm->m_len + ETH_HLEN);
+    slirp->cb->output(slirp->opaque, buf, ifm->m_len + ETH_HLEN);
     return 1;
 }
 
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 06/41] slirp: add a callback for qemu_chr_fe_write_all()
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (4 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 05/41] slirp: use a callback structure to interface with qemu Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-15 13:12   ` Paolo Bonzini
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 07/41] slirp: add clock_get_ns() callback Marc-André Lureau
                   ` (37 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Replace strong dependency on QEMU.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/libslirp.h | 1 +
 net/slirp.c      | 6 ++++++
 slirp/slirp.c    | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 36d5fb9163..16ced2aa0f 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -7,6 +7,7 @@ typedef struct Slirp Slirp;
 
 typedef struct SlirpCb {
     void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
+    int (*chr_write_all)(void *chr, const void *buf, size_t len);
 } SlirpCb;
 
 
diff --git a/net/slirp.c b/net/slirp.c
index 233f66b1ef..5c1f676487 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -140,8 +140,14 @@ static NetClientInfo net_slirp_info = {
     .cleanup = net_slirp_cleanup,
 };
 
+static int net_slirp_chr_write_all(void *chr, const void *buf, size_t len)
+{
+    return qemu_chr_fe_write_all(chr, buf, len);
+}
+
 static SlirpCb slirp_cb = {
     .output = net_slirp_output,
+    .chr_write_all = net_slirp_chr_write_all,
 };
 
 static int net_slirp_init(NetClientState *peer, const char *model,
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 7213915bf3..4e809e5d7f 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -1099,7 +1099,7 @@ ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags)
     if (so->s == -1 && so->chardev) {
         /* XXX this blocks entire thread. Rewrite to use
          * qemu_chr_fe_write and background I/O callbacks */
-        qemu_chr_fe_write_all(so->chardev, buf, len);
+        so->slirp->cb->chr_write_all(so->chardev, buf, len);
         return len;
     }
 
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 07/41] slirp: add clock_get_ns() callback
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (5 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 06/41] slirp: add a callback for qemu_chr_fe_write_all() Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-15 12:54   ` Paolo Bonzini
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 08/41] slirp: add callbacks for timer Marc-André Lureau
                   ` (36 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/libslirp.h |  6 ++++++
 net/slirp.c      | 19 +++++++++++++++++++
 slirp/if.c       |  2 +-
 slirp/ip6_icmp.c |  6 ++++--
 slirp/slirp.c    | 11 ++++++-----
 5 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 16ced2aa0f..fcebcd1e58 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -5,9 +5,15 @@
 
 typedef struct Slirp Slirp;
 
+typedef enum SlirpClockType {
+    SLIRP_CLOCK_VIRTUAL,
+    SLIRP_CLOCK_REALTIME,
+} SlirpClockType;
+
 typedef struct SlirpCb {
     void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
     int (*chr_write_all)(void *chr, const void *buf, size_t len);
+    int64_t (*clock_get_ns)(SlirpClockType type);
 } SlirpCb;
 
 
diff --git a/net/slirp.c b/net/slirp.c
index 5c1f676487..af6c643b82 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -145,9 +145,28 @@ static int net_slirp_chr_write_all(void *chr, const void *buf, size_t len)
     return qemu_chr_fe_write_all(chr, buf, len);
 }
 
+static QEMUClockType slirp_clock_to_qemu(SlirpClockType type)
+{
+    switch (type) {
+    case SLIRP_CLOCK_VIRTUAL:
+        return QEMU_CLOCK_VIRTUAL;
+    case SLIRP_CLOCK_REALTIME:
+        return QEMU_CLOCK_REALTIME;
+    }
+
+    g_warn_if_reached();
+    return QEMU_CLOCK_REALTIME;
+}
+
+static int64_t net_slirp_clock_get_ns(SlirpClockType type)
+{
+    return qemu_clock_get_ns(slirp_clock_to_qemu(type));
+}
+
 static SlirpCb slirp_cb = {
     .output = net_slirp_output,
     .chr_write_all = net_slirp_chr_write_all,
+    .clock_get_ns = net_slirp_clock_get_ns,
 };
 
 static int net_slirp_init(NetClientState *peer, const char *model,
diff --git a/slirp/if.c b/slirp/if.c
index 590753c658..1c96869831 100644
--- a/slirp/if.c
+++ b/slirp/if.c
@@ -150,7 +150,7 @@ diddit:
  */
 void if_start(Slirp *slirp)
 {
-    uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
+    uint64_t now = slirp->cb->clock_get_ns(SLIRP_CLOCK_REALTIME);
     bool from_batchq = false;
     struct mbuf *ifm, *ifm_next, *ifqt;
 
diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
index cd1e0b9fe1..0f80d49ef9 100644
--- a/slirp/ip6_icmp.c
+++ b/slirp/ip6_icmp.c
@@ -17,7 +17,8 @@ static void ra_timer_handler(void *opaque)
 {
     Slirp *slirp = opaque;
     timer_mod(slirp->ra_timer,
-              qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval);
+              slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
+              NDP_Interval);
     ndp_send_ra(slirp);
 }
 
@@ -31,7 +32,8 @@ void icmp6_init(Slirp *slirp)
                                      SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL,
                                      ra_timer_handler, slirp);
     timer_mod(slirp->ra_timer,
-              qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval);
+              slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
+              NDP_Interval);
 }
 
 void icmp6_cleanup(Slirp *slirp)
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 4e809e5d7f..979495e88b 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -571,15 +571,15 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
 
 void slirp_pollfds_poll(GArray *pollfds, int select_error)
 {
-    Slirp *slirp;
+    Slirp *slirp = QTAILQ_FIRST(&slirp_instances);
     struct socket *so, *so_next;
     int ret;
 
-    if (QTAILQ_EMPTY(&slirp_instances)) {
+    if (!slirp) {
         return;
     }
 
-    curtime = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+    curtime = slirp->cb->clock_get_ns(SLIRP_CLOCK_REALTIME) / SCALE_MS;
 
     QTAILQ_FOREACH(slirp, &slirp_instances, entry) {
         /*
@@ -947,7 +947,8 @@ static int if_encap4(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh,
             ifm->resolution_requested = true;
 
             /* Expire request and drop outgoing packet after 1 second */
-            ifm->expiration_date = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + 1000000000ULL;
+            ifm->expiration_date = slirp->cb->clock_get_ns(SLIRP_CLOCK_REALTIME)
+                + 1000000000ULL;
         }
         return 0;
     } else {
@@ -974,7 +975,7 @@ static int if_encap6(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh,
             ndp_send_ns(slirp, ip6h->ip_dst);
             ifm->resolution_requested = true;
             ifm->expiration_date =
-                qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + 1000000000ULL;
+                slirp->cb->clock_get_ns(SLIRP_CLOCK_REALTIME) + 1000000000ULL;
         }
         return 0;
     } else {
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 08/41] slirp: add callbacks for timer
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (6 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 07/41] slirp: add clock_get_ns() callback Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-15 12:56   ` Paolo Bonzini
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 09/41] slirp: add a set_nonblock() callback Marc-André Lureau
                   ` (35 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/libslirp.h |  6 ++++++
 slirp/slirp.h    |  2 +-
 net/slirp.c      | 23 +++++++++++++++++++++++
 slirp/ip6_icmp.c | 21 ++++++++++-----------
 4 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index fcebcd1e58..88185e6c33 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -10,10 +10,16 @@ typedef enum SlirpClockType {
     SLIRP_CLOCK_REALTIME,
 } SlirpClockType;
 
+typedef void (*SlirpTimerCb)(void *opaque);
+
 typedef struct SlirpCb {
     void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
     int (*chr_write_all)(void *chr, const void *buf, size_t len);
     int64_t (*clock_get_ns)(SlirpClockType type);
+    void *(*timer_new)(SlirpClockType type, int scale,
+                      SlirpTimerCb cb, void *opaque);
+    void (*timer_free)(void *timer);
+    void (*timer_mod)(void *timer, int64_t expire_timer);
 } SlirpCb;
 
 
diff --git a/slirp/slirp.h b/slirp/slirp.h
index f7c087456a..e5abf1c594 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -218,7 +218,7 @@ struct Slirp {
     NdpTable ndp_table;
 
     GRand *grand;
-    QEMUTimer *ra_timer;
+    void *ra_timer;
 
     const SlirpCb *cb;
     void *opaque;
diff --git a/net/slirp.c b/net/slirp.c
index af6c643b82..7b28886802 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -163,10 +163,33 @@ static int64_t net_slirp_clock_get_ns(SlirpClockType type)
     return qemu_clock_get_ns(slirp_clock_to_qemu(type));
 }
 
+static void *net_slirp_timer_new(SlirpClockType type,
+                                 int scale,
+                                 SlirpTimerCb cb, void *opaque)
+{
+    return timer_new_full(NULL, slirp_clock_to_qemu(type),
+                          scale, QEMU_TIMER_ATTR_EXTERNAL,
+                          cb, opaque);
+}
+
+static void net_slirp_timer_free(void *timer)
+{
+    timer_del(timer);
+    timer_free(timer);
+}
+
+static void net_slirp_timer_mod(void *timer, int64_t expire_timer)
+{
+    timer_mod(timer, expire_timer);
+}
+
 static SlirpCb slirp_cb = {
     .output = net_slirp_output,
     .chr_write_all = net_slirp_chr_write_all,
     .clock_get_ns = net_slirp_clock_get_ns,
+    .timer_new = net_slirp_timer_new,
+    .timer_free = net_slirp_timer_free,
+    .timer_mod = net_slirp_timer_mod,
 };
 
 static int net_slirp_init(NetClientState *peer, const char *model,
diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
index 0f80d49ef9..71d95daef0 100644
--- a/slirp/ip6_icmp.c
+++ b/slirp/ip6_icmp.c
@@ -16,9 +16,10 @@
 static void ra_timer_handler(void *opaque)
 {
     Slirp *slirp = opaque;
-    timer_mod(slirp->ra_timer,
-              slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
-              NDP_Interval);
+
+    slirp->cb->timer_mod(slirp->ra_timer,
+        slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
+        NDP_Interval);
     ndp_send_ra(slirp);
 }
 
@@ -28,12 +29,11 @@ void icmp6_init(Slirp *slirp)
         return;
     }
 
-    slirp->ra_timer = timer_new_full(NULL, QEMU_CLOCK_VIRTUAL,
-                                     SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL,
-                                     ra_timer_handler, slirp);
-    timer_mod(slirp->ra_timer,
-              slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
-              NDP_Interval);
+    slirp->ra_timer = slirp->cb->timer_new(SLIRP_CLOCK_VIRTUAL, SCALE_MS,
+                                           ra_timer_handler, slirp);
+    slirp->cb->timer_mod(slirp->ra_timer,
+        slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
+        NDP_Interval);
 }
 
 void icmp6_cleanup(Slirp *slirp)
@@ -42,8 +42,7 @@ void icmp6_cleanup(Slirp *slirp)
         return;
     }
 
-    timer_del(slirp->ra_timer);
-    timer_free(slirp->ra_timer);
+    slirp->cb->timer_free(slirp->ra_timer);
 }
 
 static void icmp6_send_echoreply(struct mbuf *m, Slirp *slirp, struct ip6 *ip,
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 09/41] slirp: add a set_nonblock() callback
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (7 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 08/41] slirp: add callbacks for timer Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-15 13:03   ` Paolo Bonzini
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 10/41] slirp: remove PROBE_CONN dead-code Marc-André Lureau
                   ` (34 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

qemu_set_nonblock() does some event registration with the main loop on
win32, let's have a callback.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/libslirp.h | 1 +
 net/slirp.c      | 1 +
 slirp/misc.c     | 2 +-
 slirp/tcp_subr.c | 4 ++--
 4 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 88185e6c33..f2e7f94ebb 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -20,6 +20,7 @@ typedef struct SlirpCb {
                       SlirpTimerCb cb, void *opaque);
     void (*timer_free)(void *timer);
     void (*timer_mod)(void *timer, int64_t expire_timer);
+    void (*set_nonblock)(int fd);
 } SlirpCb;
 
 
diff --git a/net/slirp.c b/net/slirp.c
index 7b28886802..5ea8c255f6 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -190,6 +190,7 @@ static SlirpCb slirp_cb = {
     .timer_new = net_slirp_timer_new,
     .timer_free = net_slirp_timer_free,
     .timer_mod = net_slirp_timer_mod,
+    .set_nonblock = qemu_set_nonblock,
 };
 
 static int net_slirp_init(NetClientState *peer, const char *model,
diff --git a/slirp/misc.c b/slirp/misc.c
index 7972b9b05b..dd2b3512a8 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -174,7 +174,7 @@ fork_exec(struct socket *so, const char *ex)
     socket_set_fast_reuse(so->s);
     opt = 1;
     qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
-    qemu_set_nonblock(so->s);
+    so->slirp->cb->set_nonblock(so->s);
     return 1;
 }
 #endif
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index 4b40850c7a..8d97f1f54e 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -412,7 +412,7 @@ int tcp_fconnect(struct socket *so, unsigned short af)
     int opt, s=so->s;
     struct sockaddr_storage addr;
 
-    qemu_set_nonblock(s);
+    so->slirp->cb->set_nonblock(s);
     socket_set_fast_reuse(s);
     opt = 1;
     qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
@@ -484,7 +484,7 @@ void tcp_connect(struct socket *inso)
         tcp_close(sototcpcb(so)); /* This will sofree() as well */
         return;
     }
-    qemu_set_nonblock(s);
+    so->slirp->cb->set_nonblock(s);
     socket_set_fast_reuse(s);
     opt = 1;
     qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 10/41] slirp: remove PROBE_CONN dead-code
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (8 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 09/41] slirp: add a set_nonblock() callback Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:12   ` Philippe Mathieu-Daudé
  2018-11-14 13:33   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 11/41] slirp: remove FULL_BOLT Marc-André Lureau
                   ` (33 subsequent siblings)
  43 siblings, 2 replies; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Nobody cares for over 14y. Somebody can revert or rewrite if
interested by that.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp_config.h |  4 ----
 slirp/slirp.c        | 41 -----------------------------------------
 2 files changed, 45 deletions(-)

diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index c59f655207..721667e3ef 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -2,10 +2,6 @@
  * User definable configuration options
  */
 
-/* Define if you want the connection to be probed */
-/* XXX Not working yet, so ignore this for now */
-#undef PROBE_CONN
-
 /* Define to 1 if you want KEEPALIVE timers */
 #define DO_KEEPALIVE 0
 
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 979495e88b..2d32debf2a 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -699,47 +699,6 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error)
                         }
                     }
                 }
-
-                /*
-                 * Probe a still-connecting, non-blocking socket
-                 * to check if it's still alive
-                 */
-#ifdef PROBE_CONN
-                if (so->so_state & SS_ISFCONNECTING) {
-                    ret = qemu_recv(so->s, &ret, 0, 0);
-
-                    if (ret < 0) {
-                        /* XXX */
-                        if (errno == EAGAIN || errno == EWOULDBLOCK ||
-                            errno == EINPROGRESS || errno == ENOTCONN) {
-                            continue; /* Still connecting, continue */
-                        }
-
-                        /* else failed */
-                        so->so_state &= SS_PERSISTENT_MASK;
-                        so->so_state |= SS_NOFDREF;
-
-                        /* tcp_input will take care of it */
-                    } else {
-                        ret = send(so->s, &ret, 0, 0);
-                        if (ret < 0) {
-                            /* XXX */
-                            if (errno == EAGAIN || errno == EWOULDBLOCK ||
-                                errno == EINPROGRESS || errno == ENOTCONN) {
-                                continue;
-                            }
-                            /* else failed */
-                            so->so_state &= SS_PERSISTENT_MASK;
-                            so->so_state |= SS_NOFDREF;
-                        } else {
-                            so->so_state &= ~SS_ISFCONNECTING;
-                        }
-
-                    }
-                    tcp_input((struct mbuf *)NULL, sizeof(struct ip), so,
-                              so->so_ffamily);
-                } /* SS_ISFCONNECTING */
-#endif
             }
 
             /*
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 11/41] slirp: remove FULL_BOLT
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (9 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 10/41] slirp: remove PROBE_CONN dead-code Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:46   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 12/41] slirp: remove the disabled readv()/writev() code path Marc-André Lureau
                   ` (32 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Looking at git history, this looks like something from the past, when
there was a tty layer. Let's remove it.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp_config.h | 7 -------
 slirp/if.c           | 2 --
 2 files changed, 9 deletions(-)

diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index 721667e3ef..f0cc1c781b 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -5,13 +5,6 @@
 /* Define to 1 if you want KEEPALIVE timers */
 #define DO_KEEPALIVE 0
 
-/* Define this if you want slirp to write to the tty as fast as it can */
-/* This should only be set if you are using load-balancing, slirp does a */
-/* pretty good job on single modems already, and seting this will make */
-/* interactive sessions less responsive */
-/* XXXXX Talk about having fast modem as unit 0 */
-#undef FULL_BOLT
-
 /*********************************************************/
 /*
  * Autoconf defined configuration options
diff --git a/slirp/if.c b/slirp/if.c
index 1c96869831..1a9122a732 100644
--- a/slirp/if.c
+++ b/slirp/if.c
@@ -131,12 +131,10 @@ diddit:
 		}
 	}
 
-#ifndef FULL_BOLT
 	/*
 	 * This prevents us from malloc()ing too many mbufs
 	 */
 	if_start(ifm->slirp);
-#endif
 }
 
 /*
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 12/41] slirp: remove the disabled readv()/writev() code path
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (10 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 11/41] slirp: remove FULL_BOLT Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:46   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 13/41] slirp: remove HAVE_SYS_SIGNAL_H Marc-André Lureau
                   ` (31 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

The soread() function may be used on datagram sockets, and would
provide different behaviour if HAVE_READV was set, on empty datagrams.
This looks like a minor optimization, that never has been a strong
goal for slirp.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp_config.h |  3 ---
 slirp/socket.c       | 15 ---------------
 2 files changed, 18 deletions(-)

diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index f0cc1c781b..3ce64e088e 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -29,9 +29,6 @@
 /* Define if the machine is big endian */
 //#undef HOST_WORDS_BIGENDIAN
 
-/* Define if you have readv */
-#undef HAVE_READV
-
 /* Define if iovec needs to be declared */
 #undef DECLARE_IOVEC
 #ifdef _WIN32
diff --git a/slirp/socket.c b/slirp/socket.c
index 041ec5061a..7012c7c07d 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -187,12 +187,7 @@ soread(struct socket *so)
 	 */
 	sopreprbuf(so, iov, &n);
 
-#ifdef HAVE_READV
-	nn = readv(so->s, (struct iovec *)iov, n);
-	DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
-#else
 	nn = qemu_recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
-#endif
 	if (nn <= 0) {
 		if (nn < 0 && (errno == EINTR || errno == EAGAIN))
 			return 0;
@@ -226,7 +221,6 @@ soread(struct socket *so)
 		}
 	}
 
-#ifndef HAVE_READV
 	/*
 	 * If there was no error, try and read the second time round
 	 * We read again if n = 2 (ie, there's another part of the buffer)
@@ -244,7 +238,6 @@ soread(struct socket *so)
         }
 
 	DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
-#endif
 
 	/* Update fields */
 	sb->sb_cc += nn;
@@ -452,13 +445,7 @@ sowrite(struct socket *so)
 	}
 	/* Check if there's urgent data to send, and if so, send it */
 
-#ifdef HAVE_READV
-	nn = writev(so->s, (const struct iovec *)iov, n);
-
-	DEBUG_MISC((dfd, "  ... wrote nn = %d bytes\n", nn));
-#else
 	nn = slirp_send(so, iov[0].iov_base, iov[0].iov_len,0);
-#endif
 	/* This should never happen, but people tell me it does *shrug* */
 	if (nn < 0 && (errno == EAGAIN || errno == EINTR))
 		return 0;
@@ -467,7 +454,6 @@ sowrite(struct socket *so)
 		goto err_disconnected;
 	}
 
-#ifndef HAVE_READV
 	if (n == 2 && nn == iov[0].iov_len) {
             int ret;
             ret = slirp_send(so, iov[1].iov_base, iov[1].iov_len,0);
@@ -475,7 +461,6 @@ sowrite(struct socket *so)
                 nn += ret;
         }
         DEBUG_MISC((dfd, "  ... wrote nn = %d bytes\n", nn));
-#endif
 
 	/* Update sbuf */
 	sb->sb_cc -= nn;
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 13/41] slirp: remove HAVE_SYS_SIGNAL_H
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (11 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 12/41] slirp: remove the disabled readv()/writev() code path Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:47   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 14/41] slirp: remove unused HAVE_SYS_BITYPES_H Marc-André Lureau
                   ` (30 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp.h        | 3 ---
 slirp/slirp_config.h | 3 ---
 2 files changed, 6 deletions(-)

diff --git a/slirp/slirp.h b/slirp/slirp.h
index e5abf1c594..1dbe39bc9a 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -35,9 +35,6 @@ typedef char *caddr_t;
 #ifndef NO_UNIX_SOCKETS
 #include <sys/un.h>
 #endif
-#ifdef HAVE_SYS_SIGNAL_H
-# include <sys/signal.h>
-#endif
 #ifndef _WIN32
 #include <sys/socket.h>
 #endif
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index 3ce64e088e..2605c4222b 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -50,9 +50,6 @@
 #define HAVE_ARPA_INET_H
 #endif
 
-/* Define if you have sys/signal.h */
-#undef HAVE_SYS_SIGNAL_H
-
 /* Define if you have sys/stropts.h */
 #undef HAVE_SYS_STROPTS_H
 
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 14/41] slirp: remove unused HAVE_SYS_BITYPES_H
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (12 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 13/41] slirp: remove HAVE_SYS_SIGNAL_H Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:47   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 15/41] slirp: remove NO_UNIX_SOCKETS Marc-André Lureau
                   ` (29 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp.h        | 4 ----
 slirp/slirp_config.h | 3 ---
 2 files changed, 7 deletions(-)

diff --git a/slirp/slirp.h b/slirp/slirp.h
index 1dbe39bc9a..7c0bcd9e1c 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -19,10 +19,6 @@ typedef char *caddr_t;
 # endif
 #endif
 
-#ifdef HAVE_SYS_BITYPES_H
-# include <sys/bitypes.h>
-#endif
-
 #ifndef _WIN32
 #include <sys/uio.h>
 #endif
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index 2605c4222b..a205dc8c28 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -23,9 +23,6 @@
 #define HAVE_SYS_FILIO_H
 #endif
 
-/* Define if you have sys/bitypes.h */
-#undef HAVE_SYS_BITYPES_H
-
 /* Define if the machine is big endian */
 //#undef HOST_WORDS_BIGENDIAN
 
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 15/41] slirp: remove NO_UNIX_SOCKETS
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (13 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 14/41] slirp: remove unused HAVE_SYS_BITYPES_H Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:48   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 16/41] slirp: remove unused HAVE_SYS_STROPTS_H Marc-André Lureau
                   ` (28 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp.h        | 3 ---
 slirp/slirp_config.h | 6 ------
 2 files changed, 9 deletions(-)

diff --git a/slirp/slirp.h b/slirp/slirp.h
index 7c0bcd9e1c..424151b99b 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -28,9 +28,6 @@ typedef char *caddr_t;
 #include <arpa/inet.h>
 #endif
 
-#ifndef NO_UNIX_SOCKETS
-#include <sys/un.h>
-#endif
 #ifndef _WIN32
 #include <sys/socket.h>
 #endif
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index a205dc8c28..4417b05d1c 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -58,9 +58,3 @@
 #ifndef _WIN32
 #define HAVE_INET_ATON
 #endif
-
-/* Define if you DON'T have unix-domain sockets */
-#undef NO_UNIX_SOCKETS
-#ifdef _WIN32
-#define NO_UNIX_SOCKETS
-#endif
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 16/41] slirp: remove unused HAVE_SYS_STROPTS_H
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (14 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 15/41] slirp: remove NO_UNIX_SOCKETS Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:49   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 17/41] slirp: remove unused HAVE_ARPA_INET_H Marc-André Lureau
                   ` (27 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp.h        | 5 -----
 slirp/slirp_config.h | 3 ---
 2 files changed, 8 deletions(-)

diff --git a/slirp/slirp.h b/slirp/slirp.h
index 424151b99b..92abb2d78d 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -54,11 +54,6 @@ typedef char *caddr_t;
 #define remque slirp_remque
 #define quehead slirp_quehead
 
-#ifdef HAVE_SYS_STROPTS_H
-#include <sys/stropts.h>
-#endif
-
-
 #include "debug.h"
 
 #include "qemu/queue.h"
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index 4417b05d1c..47811e36dc 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -47,9 +47,6 @@
 #define HAVE_ARPA_INET_H
 #endif
 
-/* Define if you have sys/stropts.h */
-#undef HAVE_SYS_STROPTS_H
-
 /* Define to sizeof(char *) */
 #define SIZEOF_CHAR_P (HOST_LONG_BITS / 8)
 
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 17/41] slirp: remove unused HAVE_ARPA_INET_H
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (15 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 16/41] slirp: remove unused HAVE_SYS_STROPTS_H Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:50   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 18/41] slirp: remove unused HAVE_SYS_WAIT_H Marc-André Lureau
                   ` (26 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp_config.h | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index 47811e36dc..e95284071a 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -41,12 +41,6 @@
 #define HAVE_SYS_SELECT_H
 #endif
 
-/* Define if you have arpa/inet.h */
-#undef HAVE_ARPA_INET_H
-#ifndef _WIN32
-#define HAVE_ARPA_INET_H
-#endif
-
 /* Define to sizeof(char *) */
 #define SIZEOF_CHAR_P (HOST_LONG_BITS / 8)
 
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 18/41] slirp: remove unused HAVE_SYS_WAIT_H
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (16 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 17/41] slirp: remove unused HAVE_ARPA_INET_H Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:50   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 19/41] slirp: remove unused HAVE_SYS_SELECT_H Marc-André Lureau
                   ` (25 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp.h        | 4 ----
 slirp/slirp_config.h | 3 ---
 2 files changed, 7 deletions(-)

diff --git a/slirp/slirp.h b/slirp/slirp.h
index 92abb2d78d..7aa14feeb6 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -40,10 +40,6 @@ typedef char *caddr_t;
 # include <sys/select.h>
 #endif
 
-#ifdef HAVE_SYS_WAIT_H
-# include <sys/wait.h>
-#endif
-
 #ifdef HAVE_SYS_FILIO_H
 # include <sys/filio.h>
 #endif
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index e95284071a..9becb98e11 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -32,9 +32,6 @@
 #define DECLARE_IOVEC
 #endif
 
-/* Define if you have a POSIX.1 sys/wait.h */
-#undef HAVE_SYS_WAIT_H
-
 /* Define if you have sys/select.h */
 #undef HAVE_SYS_SELECT_H
 #ifndef _WIN32
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 19/41] slirp: remove unused HAVE_SYS_SELECT_H
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (17 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 18/41] slirp: remove unused HAVE_SYS_WAIT_H Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:51   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 20/41] slirp: remove HAVE_SYS_IOCTL_H Marc-André Lureau
                   ` (24 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/main.h         | 4 ----
 slirp/slirp.h        | 4 ----
 slirp/slirp_config.h | 6 ------
 3 files changed, 14 deletions(-)

diff --git a/slirp/main.h b/slirp/main.h
index e04677944f..4bc05fb904 100644
--- a/slirp/main.h
+++ b/slirp/main.h
@@ -8,10 +8,6 @@
 #ifndef SLIRP_MAIN_H
 #define SLIRP_MAIN_H
 
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif
-
 extern u_int curtime;
 extern struct in_addr loopback_addr;
 extern unsigned long loopback_mask;
diff --git a/slirp/slirp.h b/slirp/slirp.h
index 7aa14feeb6..abe87618af 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -36,10 +36,6 @@ typedef char *caddr_t;
 # include <sys/ioctl.h>
 #endif
 
-#ifdef HAVE_SYS_SELECT_H
-# include <sys/select.h>
-#endif
-
 #ifdef HAVE_SYS_FILIO_H
 # include <sys/filio.h>
 #endif
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index 9becb98e11..68e75f3873 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -32,12 +32,6 @@
 #define DECLARE_IOVEC
 #endif
 
-/* Define if you have sys/select.h */
-#undef HAVE_SYS_SELECT_H
-#ifndef _WIN32
-#define HAVE_SYS_SELECT_H
-#endif
-
 /* Define to sizeof(char *) */
 #define SIZEOF_CHAR_P (HOST_LONG_BITS / 8)
 
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 20/41] slirp: remove HAVE_SYS_IOCTL_H
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (18 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 19/41] slirp: remove unused HAVE_SYS_SELECT_H Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:51   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 21/41] slirp: remove HAVE_SYS_FILIO_H Marc-André Lureau
                   ` (23 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp.h        | 2 +-
 slirp/slirp_config.h | 6 ------
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/slirp/slirp.h b/slirp/slirp.h
index abe87618af..a2e7c50361 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -32,7 +32,7 @@ typedef char *caddr_t;
 #include <sys/socket.h>
 #endif
 
-#if defined(HAVE_SYS_IOCTL_H)
+#ifndef _WIN32
 # include <sys/ioctl.h>
 #endif
 
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index 68e75f3873..0e78e92d94 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -11,12 +11,6 @@
  * You shouldn't need to touch any of these
  */
 
-/* Define if you have sys/ioctl.h */
-#undef HAVE_SYS_IOCTL_H
-#ifndef _WIN32
-#define HAVE_SYS_IOCTL_H
-#endif
-
 /* Define if you have sys/filio.h */
 #undef HAVE_SYS_FILIO_H
 #ifdef __APPLE__
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 21/41] slirp: remove HAVE_SYS_FILIO_H
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (19 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 20/41] slirp: remove HAVE_SYS_IOCTL_H Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:52   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 22/41] slirp: remove unused DECLARE_IOVEC Marc-André Lureau
                   ` (22 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp.h        | 2 +-
 slirp/slirp_config.h | 6 ------
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/slirp/slirp.h b/slirp/slirp.h
index a2e7c50361..1a336b2cf1 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -36,7 +36,7 @@ typedef char *caddr_t;
 # include <sys/ioctl.h>
 #endif
 
-#ifdef HAVE_SYS_FILIO_H
+#ifdef __APPLE__
 # include <sys/filio.h>
 #endif
 
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index 0e78e92d94..f1ee927c15 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -11,12 +11,6 @@
  * You shouldn't need to touch any of these
  */
 
-/* Define if you have sys/filio.h */
-#undef HAVE_SYS_FILIO_H
-#ifdef __APPLE__
-#define HAVE_SYS_FILIO_H
-#endif
-
 /* Define if the machine is big endian */
 //#undef HOST_WORDS_BIGENDIAN
 
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 22/41] slirp: remove unused DECLARE_IOVEC
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (20 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 21/41] slirp: remove HAVE_SYS_FILIO_H Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:53   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 23/41] slirp: remove unused HAVE_INET_ATON Marc-André Lureau
                   ` (21 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

It's actually qemu configure CONFIG_IOVEC that is being used.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp_config.h | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index f1ee927c15..833f25a965 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -14,12 +14,6 @@
 /* Define if the machine is big endian */
 //#undef HOST_WORDS_BIGENDIAN
 
-/* Define if iovec needs to be declared */
-#undef DECLARE_IOVEC
-#ifdef _WIN32
-#define DECLARE_IOVEC
-#endif
-
 /* Define to sizeof(char *) */
 #define SIZEOF_CHAR_P (HOST_LONG_BITS / 8)
 
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 23/41] slirp: remove unused HAVE_INET_ATON
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (21 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 22/41] slirp: remove unused DECLARE_IOVEC Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:54   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 24/41] slirp: replace HOST_WORDS_BIGENDIAN with glib equivalent Marc-André Lureau
                   ` (20 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp_config.h | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index 833f25a965..5126711849 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -16,9 +16,3 @@
 
 /* Define to sizeof(char *) */
 #define SIZEOF_CHAR_P (HOST_LONG_BITS / 8)
-
-/* Define if you have inet_aton */
-#undef HAVE_INET_ATON
-#ifndef _WIN32
-#define HAVE_INET_ATON
-#endif
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 24/41] slirp: replace HOST_WORDS_BIGENDIAN with glib equivalent
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (22 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 23/41] slirp: remove unused HAVE_INET_ATON Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:14   ` Philippe Mathieu-Daudé
  2018-11-14 13:32   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 25/41] slirp: replace SIZEOF_CHAR_P " Marc-André Lureau
                   ` (19 subsequent siblings)
  43 siblings, 2 replies; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

One more step towards making the project independent from QEMU.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/ip.h           | 8 +++++---
 slirp/ip6.h          | 3 ++-
 slirp/ip6_icmp.h     | 6 +++---
 slirp/slirp_config.h | 3 ---
 slirp/tcp.h          | 4 +++-
 5 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/slirp/ip.h b/slirp/ip.h
index 59cf4aa918..83fc9cdfbf 100644
--- a/slirp/ip.h
+++ b/slirp/ip.h
@@ -33,7 +33,9 @@
 #ifndef IP_H
 #define IP_H
 
-#ifdef HOST_WORDS_BIGENDIAN
+#include <glib.h>
+
+#if G_BYTE_ORDER == G_BIG_ENDIAN
 # undef NTOHL
 # undef NTOHS
 # undef HTONL
@@ -69,7 +71,7 @@ typedef uint32_t n_long;                 /* long as received from the net */
  * Structure of an internet header, naked of options.
  */
 struct ip {
-#ifdef HOST_WORDS_BIGENDIAN
+#if G_BYTE_ORDER == G_BIG_ENDIAN
 	uint8_t ip_v:4,			/* version */
 		ip_hl:4;		/* header length */
 #else
@@ -135,7 +137,7 @@ struct	ip_timestamp {
 	uint8_t	ipt_code;		/* IPOPT_TS */
 	uint8_t	ipt_len;		/* size of structure (variable) */
 	uint8_t	ipt_ptr;		/* index of current entry */
-#ifdef HOST_WORDS_BIGENDIAN
+#if G_BYTE_ORDER == G_BIG_ENDIAN
 	uint8_t	ipt_oflw:4,		/* overflow counter */
 		ipt_flg:4;		/* flags, see below */
 #else
diff --git a/slirp/ip6.h b/slirp/ip6.h
index b1bea43b3c..14e9c78735 100644
--- a/slirp/ip6.h
+++ b/slirp/ip6.h
@@ -6,6 +6,7 @@
 #ifndef SLIRP_IP6_H
 #define SLIRP_IP6_H
 
+#include <glib.h>
 #include "net/eth.h"
 
 #define ALLNODES_MULTICAST  { .s6_addr = \
@@ -113,7 +114,7 @@ static inline void in6_compute_ethaddr(struct in6_addr ip,
  * Structure of an internet header, naked of options.
  */
 struct ip6 {
-#ifdef HOST_WORDS_BIGENDIAN
+#if G_BYTE_ORDER == G_BIG_ENDIAN
     uint32_t
         ip_v:4,         /* version */
         ip_tc_hi:4,     /* traffic class */
diff --git a/slirp/ip6_icmp.h b/slirp/ip6_icmp.h
index b3378b17b5..32b0914055 100644
--- a/slirp/ip6_icmp.h
+++ b/slirp/ip6_icmp.h
@@ -34,7 +34,7 @@ struct ndp_rs {     /* Router Solicitation Message */
 
 struct ndp_ra {     /* Router Advertisement Message */
     uint8_t chl;    /* Cur Hop Limit */
-#ifdef HOST_WORDS_BIGENDIAN
+#if G_BYTE_ORDER == G_BIG_ENDIAN
     uint8_t
         M:1,
         O:1,
@@ -56,7 +56,7 @@ struct ndp_ns {     /* Neighbor Solicitation Message */
 } QEMU_PACKED;
 
 struct ndp_na {     /* Neighbor Advertisement Message */
-#ifdef HOST_WORDS_BIGENDIAN
+#if G_BYTE_ORDER == G_BIG_ENDIAN
     uint32_t
         R:1,                /* Router Flag */
         S:1,                /* Solicited Flag */
@@ -125,7 +125,7 @@ struct ndpopt {
 #define ndpopt_linklayer ndpopt_body.linklayer_addr
         struct prefixinfo {                     /* Prefix Information */
             uint8_t     prefix_length;
-#ifdef HOST_WORDS_BIGENDIAN
+#if G_BYTE_ORDER == G_BIG_ENDIAN
             uint8_t     L:1, A:1, reserved1:6;
 #else
             uint8_t     reserved1:6, A:1, L:1;
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index 5126711849..b2def6d20c 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -11,8 +11,5 @@
  * You shouldn't need to touch any of these
  */
 
-/* Define if the machine is big endian */
-//#undef HOST_WORDS_BIGENDIAN
-
 /* Define to sizeof(char *) */
 #define SIZEOF_CHAR_P (HOST_LONG_BITS / 8)
diff --git a/slirp/tcp.h b/slirp/tcp.h
index 174d3d960c..47aaea6c5b 100644
--- a/slirp/tcp.h
+++ b/slirp/tcp.h
@@ -33,6 +33,8 @@
 #ifndef TCP_H
 #define TCP_H
 
+#include <glib.h>
+
 typedef	uint32_t tcp_seq;
 
 #define      PR_SLOWHZ       2               /* 2 slow timeouts per second (approx) */
@@ -51,7 +53,7 @@ struct tcphdr {
 	uint16_t th_dport;              /* destination port */
 	tcp_seq	th_seq;			/* sequence number */
 	tcp_seq	th_ack;			/* acknowledgement number */
-#ifdef HOST_WORDS_BIGENDIAN
+#if G_BYTE_ORDER == G_BIG_ENDIAN
 	uint8_t	th_off:4,		/* data offset */
 		th_x2:4;		/* (unused) */
 #else
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 25/41] slirp: replace SIZEOF_CHAR_P with glib equivalent
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (23 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 24/41] slirp: replace HOST_WORDS_BIGENDIAN with glib equivalent Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:14   ` Philippe Mathieu-Daudé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 26/41] slirp: replace compile time DO_KEEPALIVE Marc-André Lureau
                   ` (18 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/ip.h           | 2 +-
 slirp/slirp_config.h | 3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/slirp/ip.h b/slirp/ip.h
index 83fc9cdfbf..243b6c8b24 100644
--- a/slirp/ip.h
+++ b/slirp/ip.h
@@ -177,7 +177,7 @@ struct	ip_timestamp {
 
 #define	IP_MSS		576		/* default maximum segment size */
 
-#if SIZEOF_CHAR_P == 4
+#if GLIB_SIZEOF_VOID_P == 4
 struct mbuf_ptr {
 	struct mbuf *mptr;
 	uint32_t dummy;
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
index b2def6d20c..7147e0de04 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -10,6 +10,3 @@
  * Autoconf defined configuration options
  * You shouldn't need to touch any of these
  */
-
-/* Define to sizeof(char *) */
-#define SIZEOF_CHAR_P (HOST_LONG_BITS / 8)
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 26/41] slirp: replace compile time DO_KEEPALIVE
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (24 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 25/41] slirp: replace SIZEOF_CHAR_P " Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-20  1:09   ` Samuel Thibault
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 27/41] slirp: remove unused global slirp_instance Marc-André Lureau
                   ` (17 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Use a global variable instead (similar to slirp_debug)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp.h        |  6 +++---
 slirp/slirp_config.h | 12 ------------
 slirp/slirp.c        |  3 +++
 slirp/tcp_input.c    |  2 +-
 slirp/tcp_timer.c    |  2 +-
 5 files changed, 8 insertions(+), 17 deletions(-)
 delete mode 100644 slirp/slirp_config.h

diff --git a/slirp/slirp.h b/slirp/slirp.h
index 1a336b2cf1..c328aac88a 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -1,8 +1,6 @@
 #ifndef SLIRP_H
 #define SLIRP_H
 
-#include "slirp_config.h"
-
 #ifdef _WIN32
 
 typedef char *caddr_t;
@@ -219,7 +217,9 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
 #include <netdb.h>
 #endif
 
-#define SO_OPTIONS DO_KEEPALIVE
+
+extern bool slirp_do_keepalive;
+
 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
 
 /* dnssearch.c */
diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
deleted file mode 100644
index 7147e0de04..0000000000
--- a/slirp/slirp_config.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * User definable configuration options
- */
-
-/* Define to 1 if you want KEEPALIVE timers */
-#define DO_KEEPALIVE 0
-
-/*********************************************************/
-/*
- * Autoconf defined configuration options
- * You shouldn't need to touch any of these
- */
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 2d32debf2a..864a9b5a7a 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -35,6 +35,9 @@
 #include <net/if.h>
 #endif
 
+/* Define to 1 if you want KEEPALIVE timers */
+bool slirp_do_keepalive;
+
 /* host loopback address */
 struct in_addr loopback_addr;
 /* host loopback network mask */
diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c
index d073ef9525..922dbe32eb 100644
--- a/slirp/tcp_input.c
+++ b/slirp/tcp_input.c
@@ -481,7 +481,7 @@ findso:
 	 * Reset idle time and keep-alive timer.
 	 */
 	tp->t_idle = 0;
-	if (SO_OPTIONS)
+	if (slirp_do_keepalive)
 	   tp->t_timer[TCPT_KEEP] = TCPTV_KEEPINTVL;
 	else
 	   tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_IDLE;
diff --git a/slirp/tcp_timer.c b/slirp/tcp_timer.c
index 52ef5f9100..d953a16386 100644
--- a/slirp/tcp_timer.c
+++ b/slirp/tcp_timer.c
@@ -262,7 +262,7 @@ tcp_timers(register struct tcpcb *tp, int timer)
 		if (tp->t_state < TCPS_ESTABLISHED)
 			goto dropit;
 
-		if ((SO_OPTIONS) && tp->t_state <= TCPS_CLOSE_WAIT) {
+		if (slirp_do_keepalive && tp->t_state <= TCPS_CLOSE_WAIT) {
 		    	if (tp->t_idle >= TCPTV_KEEP_IDLE + TCP_MAXIDLE)
 				goto dropit;
 			/*
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 27/41] slirp: remove unused global slirp_instance
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (25 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 26/41] slirp: replace compile time DO_KEEPALIVE Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:55   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 28/41] slirp: replace error_report() with g_critical() Marc-André Lureau
                   ` (16 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/slirp/slirp.h b/slirp/slirp.h
index c328aac88a..4356b2f427 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -199,8 +199,6 @@ struct Slirp {
     void *opaque;
 };
 
-extern Slirp *slirp_instance;
-
 #ifndef NULL
 #define NULL (void *)0
 #endif
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 28/41] slirp: replace error_report() with g_critical()
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (26 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 27/41] slirp: remove unused global slirp_instance Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-20  1:14   ` Samuel Thibault
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 29/41] slirp: improve a bit the debug macros Marc-André Lureau
                   ` (15 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Reduce dependency on QEMU. QEMU could use a custom log handler if it
wants to redirect/filter it.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/ip6_icmp.c | 2 +-
 slirp/misc.c     | 4 ++--
 slirp/slirp.c    | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
index 71d95daef0..e2e23d57bd 100644
--- a/slirp/ip6_icmp.c
+++ b/slirp/ip6_icmp.c
@@ -418,7 +418,7 @@ void icmp6_input(struct mbuf *m)
             icmp6_send_echoreply(m, slirp, ip, icmp);
         } else {
             /* TODO */
-            error_report("external icmpv6 not supported yet");
+            g_critical("external icmpv6 not supported yet");
         }
         break;
 
diff --git a/slirp/misc.c b/slirp/misc.c
index dd2b3512a8..17361b79a4 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -119,7 +119,7 @@ slirp_socketpair_with_oob(int sv[2])
     return 0;
 
 err:
-    error_report("Error: slirp_socketpair(): %s", strerror(errno));
+    g_critical("slirp_socketpair(): %s", strerror(errno));
     if (s >= 0) {
         closesocket(s);
     }
@@ -162,7 +162,7 @@ fork_exec(struct socket *so, const char *ex)
     g_strfreev(argv);
 
     if (err) {
-        error_report("%s", err->message);
+        g_critical("fork_exec: %s", err->message);
         g_error_free(err);
         closesocket(sp[0]);
         closesocket(sp[1]);
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 864a9b5a7a..b1270a0309 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -1215,8 +1215,8 @@ static int sbuf_tmp_post_load(void *opaque, int version)
     }
     if (tmp->woff >= requested_len ||
         tmp->roff >= requested_len) {
-        error_report("invalid sbuf offsets r/w=%u/%u len=%u",
-                     tmp->roff, tmp->woff, requested_len);
+        g_critical("invalid sbuf offsets r/w=%u/%u len=%u",
+                   tmp->roff, tmp->woff, requested_len);
         return -EINVAL;
     }
 
@@ -1324,7 +1324,7 @@ static int ss_family_post_load(void *opaque, int version_id)
         tss->parent->ss.ss_family = AF_INET6;
         break;
     default:
-        error_report("invalid ss_family type %x", tss->portable_family);
+        g_critical("invalid ss_family type %x", tss->portable_family);
         return -EINVAL;
     }
 
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 29/41] slirp: improve a bit the debug macros
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (27 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 28/41] slirp: replace error_report() with g_critical() Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 14:04   ` Daniel P. Berrangé
  2018-11-20  1:19   ` Samuel Thibault
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 30/41] slirp: replace trace functions with DEBUG calls Marc-André Lureau
                   ` (14 subsequent siblings)
  43 siblings, 2 replies; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Let them accept multiple arguments. Simplify the inner argument
handling of DEBUG_ARGS/DEBUG_MISC_DEBUG_ERROR.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/debug.h      | 47 ++++++++++++++++++++++++++++++++++++----------
 slirp/arp_table.c  | 12 ++++++------
 slirp/bootp.c      |  3 +--
 slirp/cksum.c      |  4 ++--
 slirp/dhcpv6.c     | 11 +++++------
 slirp/ip6_icmp.c   |  2 +-
 slirp/ip_icmp.c    | 18 +++++++++---------
 slirp/mbuf.c       |  2 +-
 slirp/ndp_table.c  | 18 +++++++++---------
 slirp/slirp.c      | 12 ++++++------
 slirp/socket.c     | 32 +++++++++++++++----------------
 slirp/tcp_input.c  | 15 +++++++--------
 slirp/tcp_output.c |  2 +-
 slirp/tcp_subr.c   |  4 ++--
 slirp/udp.c        |  6 +++---
 slirp/udp6.c       |  6 +++---
 16 files changed, 109 insertions(+), 85 deletions(-)

diff --git a/slirp/debug.h b/slirp/debug.h
index 6cfa61edb3..ca3a4b04da 100644
--- a/slirp/debug.h
+++ b/slirp/debug.h
@@ -17,18 +17,45 @@
 
 extern int slirp_debug;
 
-#define DEBUG_CALL(x) if (slirp_debug & DBG_CALL) { fprintf(dfd, "%s...\n", x); fflush(dfd); }
-#define DEBUG_ARG(x, y) if (slirp_debug & DBG_CALL) { fputc(' ', dfd); fprintf(dfd, x, y); fputc('\n', dfd); fflush(dfd); }
-#define DEBUG_ARGS(x) if (slirp_debug & DBG_CALL) { fprintf x ; fflush(dfd); }
-#define DEBUG_MISC(x) if (slirp_debug & DBG_MISC) { fprintf x ; fflush(dfd); }
-#define DEBUG_ERROR(x) if (slirp_debug & DBG_ERROR) {fprintf x ; fflush(dfd); }
+#define DEBUG_CALL(fmt, ...) do {               \
+    if (slirp_debug & DBG_CALL) {               \
+        fprintf(dfd, fmt, ##__VA_ARGS__);       \
+        fprintf(dfd, "...\n");                  \
+        fflush(dfd);                            \
+    }                                           \
+} while (0)
+
+#define DEBUG_ARG(fmt, ...) do {                \
+    if (slirp_debug & DBG_CALL) {               \
+        fputc(' ', dfd);                        \
+        fprintf(dfd, fmt, ##__VA_ARGS__);       \
+        fputc('\n', dfd);                       \
+        fflush(dfd);                            \
+    }                                           \
+} while (0)
+
+#define DEBUG_ARGS(fmt, ...) DEBUG_ARG(fmt, ##__VA_ARGS__)
+
+#define DEBUG_MISC(fmt, ...) do {               \
+    if (slirp_debug & DBG_MISC) {               \
+        fprintf(dfd, fmt, ##__VA_ARGS__);       \
+        fflush(dfd);                            \
+    }                                           \
+} while (0)
+
+#define DEBUG_ERROR(fmt, ...) do {              \
+    if (slirp_debug & DBG_ERROR) {              \
+        fprintf(dfd, fmt, ##__VA_ARGS__);       \
+        fflush(dfd);                            \
+    }                                           \
+} while (0)
 
 #else
 
-#define DEBUG_CALL(x)
-#define DEBUG_ARG(x, y)
-#define DEBUG_ARGS(x)
-#define DEBUG_MISC(x)
-#define DEBUG_ERROR(x)
+#define DEBUG_CALL(fmt, ...)
+#define DEBUG_ARG(fmt, ...)
+#define DEBUG_ARGS(fmt, ...)
+#define DEBUG_MISC(fmt, ...)
+#define DEBUG_ERROR(fmt, ...)
 
 #endif
diff --git a/slirp/arp_table.c b/slirp/arp_table.c
index f81963bb88..ce19e6e7c0 100644
--- a/slirp/arp_table.c
+++ b/slirp/arp_table.c
@@ -34,9 +34,9 @@ void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN])
 
     DEBUG_CALL("arp_table_add");
     DEBUG_ARG("ip = %s", inet_ntoa((struct in_addr){.s_addr = ip_addr}));
-    DEBUG_ARGS((dfd, " hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
-                ethaddr[0], ethaddr[1], ethaddr[2],
-                ethaddr[3], ethaddr[4], ethaddr[5]));
+    DEBUG_ARGS(" hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+               ethaddr[0], ethaddr[1], ethaddr[2],
+               ethaddr[3], ethaddr[4], ethaddr[5]);
 
     if (ip_addr == 0 || ip_addr == 0xffffffff || ip_addr == broadcast_addr) {
         /* Do not register broadcast addresses */
@@ -79,9 +79,9 @@ bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
     for (i = 0; i < ARP_TABLE_SIZE; i++) {
         if (arptbl->table[i].ar_sip == ip_addr) {
             memcpy(out_ethaddr, arptbl->table[i].ar_sha,  ETH_ALEN);
-            DEBUG_ARGS((dfd, " found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
-                        out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
-                        out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]));
+            DEBUG_ARGS(" found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+                       out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
+                       out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]);
             return 1;
         }
     }
diff --git a/slirp/bootp.c b/slirp/bootp.c
index 7b1af73c95..5ab6692038 100644
--- a/slirp/bootp.c
+++ b/slirp/bootp.c
@@ -37,8 +37,7 @@
 static const uint8_t rfc1533_cookie[] = { RFC1533_COOKIE };
 
 #ifdef DEBUG
-#define DPRINTF(fmt, ...) \
-do if (slirp_debug & DBG_CALL) { fprintf(dfd, fmt, ##  __VA_ARGS__); fflush(dfd); } while (0)
+#define DPRINTF(fmt, ...) DEBUG_CALL(fmt, ##__VA_ARGS__)
 #else
 #define DPRINTF(fmt, ...) do{}while(0)
 #endif
diff --git a/slirp/cksum.c b/slirp/cksum.c
index 6d73abf4a0..b9466485b5 100644
--- a/slirp/cksum.c
+++ b/slirp/cksum.c
@@ -124,8 +124,8 @@ int cksum(struct mbuf *m, int len)
 cont:
 #ifdef DEBUG
 	if (len) {
-		DEBUG_ERROR((dfd, "cksum: out of data\n"));
-		DEBUG_ERROR((dfd, " len = %d\n", len));
+		DEBUG_ERROR("cksum: out of data\n");
+		DEBUG_ERROR(" len = %d\n", len);
 	}
 #endif
 	if (mlen == -1) {
diff --git a/slirp/dhcpv6.c b/slirp/dhcpv6.c
index d266611e85..943a13bca8 100644
--- a/slirp/dhcpv6.c
+++ b/slirp/dhcpv6.c
@@ -92,14 +92,14 @@ static int dhcpv6_parse_info_request(uint8_t *odata, int olen,
                     ri->want_boot_url = true;
                     break;
                 default:
-                    DEBUG_MISC((dfd, "dhcpv6: Unsupported option request %d\n",
-                                req_opt));
+                    DEBUG_MISC("dhcpv6: Unsupported option request %d\n",
+                               req_opt);
                 }
             }
             break;
         default:
-            DEBUG_MISC((dfd, "dhcpv6 info req: Unsupported option %d, len=%d\n",
-                        option, len));
+            DEBUG_MISC("dhcpv6 info req: Unsupported option %d, len=%d\n",
+                       option, len);
         }
 
         odata += len + 4;
@@ -203,7 +203,6 @@ void dhcpv6_input(struct sockaddr_in6 *srcsas, struct mbuf *m)
         dhcpv6_info_request(m->slirp, srcsas, xid, &data[4], data_len - 4);
         break;
     default:
-        DEBUG_MISC((dfd, "dhcpv6_input: Unsupported message type 0x%x\n",
-                    data[0]));
+        DEBUG_MISC("dhcpv6_input: Unsupported message type 0x%x\n", data[0]);
     }
 }
diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
index e2e23d57bd..6f20190a0a 100644
--- a/slirp/ip6_icmp.c
+++ b/slirp/ip6_icmp.c
@@ -77,7 +77,7 @@ void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code)
     struct ip6 *ip = mtod(m, struct ip6 *);
 
     DEBUG_CALL("icmp6_send_error");
-    DEBUG_ARGS((dfd, " type = %d, code = %d\n", type, code));
+    DEBUG_ARGS(" type = %d, code = %d\n", type, code);
 
     if (IN6_IS_ADDR_MULTICAST(&ip->ip_src) ||
             in6_zero(&ip->ip_src)) {
diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c
index 9210eef3f3..af11cfcefe 100644
--- a/slirp/ip_icmp.c
+++ b/slirp/ip_icmp.c
@@ -99,8 +99,8 @@ static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
 
     if (sendto(so->s, m->m_data + hlen, m->m_len - hlen, 0,
                (struct sockaddr *)&addr, sizeof(addr)) == -1) {
-        DEBUG_MISC((dfd, "icmp_input icmp sendto tx errno = %d-%s\n",
-                    errno, strerror(errno)));
+        DEBUG_MISC("icmp_input icmp sendto tx errno = %d-%s\n",
+                   errno, strerror(errno));
         icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
         icmp_detach(so);
     }
@@ -165,8 +165,8 @@ icmp_input(struct mbuf *m, int hlen)
         return;
       }
       if (udp_attach(so, AF_INET) == -1) {
-	DEBUG_MISC((dfd,"icmp_input udp_attach errno = %d-%s\n",
-		    errno,strerror(errno)));
+	DEBUG_MISC("icmp_input udp_attach errno = %d-%s\n",
+               errno,strerror(errno));
 	sofree(so);
 	m_free(m);
 	goto end_error;
@@ -188,8 +188,8 @@ icmp_input(struct mbuf *m, int hlen)
 
       if(sendto(so->s, icmp_ping_msg, strlen(icmp_ping_msg), 0,
 		(struct sockaddr *)&addr, sockaddr_size(&addr)) == -1) {
-	DEBUG_MISC((dfd,"icmp_input udp sendto tx errno = %d-%s\n",
-		    errno,strerror(errno)));
+	DEBUG_MISC("icmp_input udp sendto tx errno = %d-%s\n",
+               errno,strerror(errno));
 	icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
 	udp_detach(so);
       }
@@ -257,7 +257,7 @@ icmp_send_error(struct mbuf *msrc, u_char type, u_char code, int minsize,
   { char bufa[20], bufb[20];
     strcpy(bufa, inet_ntoa(ip->ip_src));
     strcpy(bufb, inet_ntoa(ip->ip_dst));
-    DEBUG_MISC((dfd, " %.16s to %.16s\n", bufa, bufb));
+    DEBUG_MISC(" %.16s to %.16s\n", bufa, bufb);
   }
 #endif
   if(ip->ip_off & IP_OFFMASK) goto end_error;    /* Only reply to fragment 0 */
@@ -457,8 +457,8 @@ void icmp_receive(struct socket *so)
         } else {
             error_code = ICMP_UNREACH_HOST;
         }
-        DEBUG_MISC((dfd, " udp icmp rx errno = %d-%s\n", errno,
-                    strerror(errno)));
+        DEBUG_MISC(" udp icmp rx errno = %d-%s\n", errno,
+                   strerror(errno));
         icmp_send_error(so->so_m, ICMP_UNREACH, error_code, 0, strerror(errno));
     } else {
         icmp_reflect(so->so_m);
diff --git a/slirp/mbuf.c b/slirp/mbuf.c
index aa1f28afb1..d8d275e0e7 100644
--- a/slirp/mbuf.c
+++ b/slirp/mbuf.c
@@ -232,7 +232,7 @@ dtom(Slirp *slirp, void *dat)
 	  }
 	}
 
-	DEBUG_ERROR((dfd, "dtom failed"));
+	DEBUG_ERROR("dtom failed");
 
 	return (struct mbuf *)0;
 }
diff --git a/slirp/ndp_table.c b/slirp/ndp_table.c
index e1676a0a7b..a4e6421fd3 100644
--- a/slirp/ndp_table.c
+++ b/slirp/ndp_table.c
@@ -19,9 +19,9 @@ void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr,
     inet_ntop(AF_INET6, &(ip_addr), addrstr, INET6_ADDRSTRLEN);
     DEBUG_ARG("ip = %s", addrstr);
 #endif
-    DEBUG_ARGS((dfd, " hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
-                ethaddr[0], ethaddr[1], ethaddr[2],
-                ethaddr[3], ethaddr[4], ethaddr[5]));
+    DEBUG_ARGS(" hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+               ethaddr[0], ethaddr[1], ethaddr[2],
+               ethaddr[3], ethaddr[4], ethaddr[5]);
 
     if (IN6_IS_ADDR_MULTICAST(&ip_addr) || in6_zero(&ip_addr)) {
         /* Do not register multicast or unspecified addresses */
@@ -69,18 +69,18 @@ bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr,
         out_ethaddr[3] = ip_addr.s6_addr[13];
         out_ethaddr[4] = ip_addr.s6_addr[14];
         out_ethaddr[5] = ip_addr.s6_addr[15];
-        DEBUG_ARGS((dfd, " multicast addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
-                    out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
-                    out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]));
+        DEBUG_ARGS(" multicast addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+                   out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
+                   out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]);
         return 1;
     }
 
     for (i = 0; i < NDP_TABLE_SIZE; i++) {
         if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) {
             memcpy(out_ethaddr, ndp_table->table[i].eth_addr,  ETH_ALEN);
-            DEBUG_ARGS((dfd, " found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
-                        out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
-                        out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]));
+            DEBUG_ARGS(" found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+                       out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
+                       out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]);
             return 1;
         }
     }
diff --git a/slirp/slirp.c b/slirp/slirp.c
index b1270a0309..9a87abee27 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -985,12 +985,12 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
     }
 
     memcpy(eh->h_dest, ethaddr, ETH_ALEN);
-    DEBUG_ARGS((dfd, " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
-                eh->h_source[0], eh->h_source[1], eh->h_source[2],
-                eh->h_source[3], eh->h_source[4], eh->h_source[5]));
-    DEBUG_ARGS((dfd, " dst = %02x:%02x:%02x:%02x:%02x:%02x\n",
-                eh->h_dest[0], eh->h_dest[1], eh->h_dest[2],
-                eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]));
+    DEBUG_ARGS(" src = %02x:%02x:%02x:%02x:%02x:%02x\n",
+               eh->h_source[0], eh->h_source[1], eh->h_source[2],
+               eh->h_source[3], eh->h_source[4], eh->h_source[5]);
+    DEBUG_ARGS(" dst = %02x:%02x:%02x:%02x:%02x:%02x\n",
+               eh->h_dest[0], eh->h_dest[1], eh->h_dest[2],
+               eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]);
     memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len);
     slirp->cb->output(slirp->opaque, buf, ifm->m_len + ETH_HLEN);
     return 1;
diff --git a/slirp/socket.c b/slirp/socket.c
index 7012c7c07d..677fd20c9d 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -208,7 +208,7 @@ soread(struct socket *so)
 				}
 			}
 
-			DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno)));
+			DEBUG_MISC(" --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno));
 			sofcantrcvmore(so);
 
 			if (err == ECONNRESET || err == ECONNREFUSED
@@ -237,7 +237,7 @@ soread(struct socket *so)
                 nn += ret;
         }
 
-	DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
+	DEBUG_MISC(" ... read nn = %d bytes\n", nn);
 
 	/* Update fields */
 	sb->sb_cc += nn;
@@ -370,7 +370,7 @@ sosendoob(struct socket *so)
 		n = slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */
 #ifdef DEBUG
 		if (n != len) {
-			DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n"));
+			DEBUG_ERROR("Didn't send all data urgently XXXXX\n");
 		}
 #endif
 	}
@@ -379,7 +379,7 @@ sosendoob(struct socket *so)
 		return n;
 	}
 	so->so_urgc -= n;
-	DEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc));
+	DEBUG_MISC(" ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc);
 
 	sb->sb_cc -= n;
 	sb->sb_rptr += n;
@@ -460,7 +460,7 @@ sowrite(struct socket *so)
             if (ret > 0)
                 nn += ret;
         }
-        DEBUG_MISC((dfd, "  ... wrote nn = %d bytes\n", nn));
+        DEBUG_MISC("  ... wrote nn = %d bytes\n", nn);
 
 	/* Update sbuf */
 	sb->sb_cc -= nn;
@@ -478,8 +478,8 @@ sowrite(struct socket *so)
 	return nn;
 
 err_disconnected:
-	DEBUG_MISC((dfd, " --- sowrite disconnected, so->so_state = %x, errno = %d\n",
-		    so->so_state, errno));
+	DEBUG_MISC(" --- sowrite disconnected, so->so_state = %x, errno = %d\n",
+               so->so_state, errno);
 	sofcantsendmore(so);
 	tcp_sockclosed(sototcpcb(so));
 	return -1;
@@ -512,8 +512,8 @@ sorecvfrom(struct socket *so)
 	    if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
 	    else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET;
 
-	    DEBUG_MISC((dfd," udp icmp rx errno = %d-%s\n",
-			errno,strerror(errno)));
+	    DEBUG_MISC(" udp icmp rx errno = %d-%s\n",
+                   errno,strerror(errno));
 	    icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno));
 	  } else {
 	    icmp_reflect(so->so_m);
@@ -564,8 +564,8 @@ sorecvfrom(struct socket *so)
 
 	  m->m_len = recvfrom(so->s, m->m_data, len, 0,
 			      (struct sockaddr *)&addr, &addrlen);
-	  DEBUG_MISC((dfd, " did recvfrom %d, errno = %d-%s\n",
-		      m->m_len, errno,strerror(errno)));
+	  DEBUG_MISC(" did recvfrom %d, errno = %d-%s\n",
+                 m->m_len, errno,strerror(errno));
 	  if(m->m_len<0) {
 	    /* Report error as ICMP */
 	    switch (so->so_lfamily) {
@@ -579,7 +579,7 @@ sorecvfrom(struct socket *so)
 		code = ICMP_UNREACH_NET;
 	      }
 
-	      DEBUG_MISC((dfd, " rx error, tx icmp ICMP_UNREACH:%i\n", code));
+	      DEBUG_MISC(" rx error, tx icmp ICMP_UNREACH:%i\n", code);
 	      icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno));
 	      break;
 	    case AF_INET6:
@@ -591,7 +591,7 @@ sorecvfrom(struct socket *so)
 		code = ICMP6_UNREACH_NO_ROUTE;
 	      }
 
-	      DEBUG_MISC((dfd, " rx error, tx icmp6 ICMP_UNREACH:%i\n", code));
+	      DEBUG_MISC(" rx error, tx icmp6 ICMP_UNREACH:%i\n", code);
 	      icmp6_send_error(so->so_m, ICMP6_UNREACH, code);
 	      break;
 	    default:
@@ -839,9 +839,9 @@ void sotranslate_out(struct socket *so, struct sockaddr_storage *addr)
             }
         }
 
-        DEBUG_MISC((dfd, " addr.sin_port=%d, "
-            "addr.sin_addr.s_addr=%.16s\n",
-            ntohs(sin->sin_port), inet_ntoa(sin->sin_addr)));
+        DEBUG_MISC(" addr.sin_port=%d, "
+                   "addr.sin_addr.s_addr=%.16s\n",
+                   ntohs(sin->sin_port), inet_ntoa(sin->sin_addr));
         break;
 
     case AF_INET6:
diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c
index 922dbe32eb..e33fb83df5 100644
--- a/slirp/tcp_input.c
+++ b/slirp/tcp_input.c
@@ -236,8 +236,8 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *inso, unsigned short af)
     Slirp *slirp;
 
 	DEBUG_CALL("tcp_input");
-	DEBUG_ARGS((dfd, " m = %p  iphlen = %2d  inso = %p\n",
-		    m, iphlen, inso));
+	DEBUG_ARGS(" m = %p  iphlen = %2d  inso = %p\n",
+               m, iphlen, inso);
 
 	/*
 	 * If called with m == 0, then we're continuing the connect
@@ -662,8 +662,8 @@ findso:
               (errno != EINPROGRESS) && (errno != EWOULDBLOCK)
           ) {
 	    uint8_t code;
-	    DEBUG_MISC((dfd, " tcp fconnect errno = %d-%s\n",
-			errno,strerror(errno)));
+	    DEBUG_MISC(" tcp fconnect errno = %d-%s\n",
+                   errno,strerror(errno));
 	    if(errno == ECONNREFUSED) {
 	      /* ACK the SYN, send RST to refuse the connection */
 	      tcp_respond(tp, ti, m, ti->ti_seq + 1, (tcp_seq) 0,
@@ -1032,8 +1032,7 @@ trimthenstep6:
 
 		if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) {
 			if (ti->ti_len == 0 && tiwin == tp->snd_wnd) {
-			  DEBUG_MISC((dfd, " dup ack  m = %p  so = %p\n",
-				      m, so));
+			  DEBUG_MISC(" dup ack  m = %p  so = %p\n", m, so);
 				/*
 				 * If we have outstanding data (other than
 				 * a window probe), this is a completely
@@ -1411,7 +1410,7 @@ tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti)
 	int opt, optlen;
 
 	DEBUG_CALL("tcp_dooptions");
-	DEBUG_ARGS((dfd, " tp = %p  cnt=%i\n", tp, cnt));
+	DEBUG_ARGS(" tp = %p  cnt=%i\n", tp, cnt);
 
 	for (; cnt > 0; cnt -= optlen, cp += optlen) {
 		opt = cp[0];
@@ -1611,7 +1610,7 @@ tcp_mss(struct tcpcb *tp, u_int offer)
                                                (mss - (TCP_RCVSPACE % mss)) :
                                                0));
 
-	DEBUG_MISC((dfd, " returning mss = %d\n", mss));
+	DEBUG_MISC(" returning mss = %d\n", mss);
 
 	return mss;
 }
diff --git a/slirp/tcp_output.c b/slirp/tcp_output.c
index 90b5c376f7..44da8a4e47 100644
--- a/slirp/tcp_output.c
+++ b/slirp/tcp_output.c
@@ -92,7 +92,7 @@ again:
 
 	flags = tcp_outflags[tp->t_state];
 
-	DEBUG_MISC((dfd, " --- tcp_output flags = 0x%x\n",flags));
+	DEBUG_MISC(" --- tcp_output flags = 0x%x\n", flags);
 
 	/*
 	 * If in persist timeout with window of 0, send 1 byte.
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index 8d97f1f54e..98bceea9f6 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -420,7 +420,7 @@ int tcp_fconnect(struct socket *so, unsigned short af)
     qemu_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
 
     addr = so->fhost.ss;
-    DEBUG_CALL(" connect()ing")
+    DEBUG_CALL(" connect()ing");
     sotranslate_out(so, &addr);
 
     /* We don't care what port we get */
@@ -964,7 +964,7 @@ int tcp_ctl(struct socket *so)
                     so->chardev = ex_ptr->ex_chardev;
                     return 1;
                 }
-                DEBUG_MISC((dfd, " executing %s\n", ex_ptr->ex_exec));
+                DEBUG_MISC(" executing %s\n", ex_ptr->ex_exec);
                 return fork_exec(so, ex_ptr->ex_exec);
             }
         }
diff --git a/slirp/udp.c b/slirp/udp.c
index c47870a61b..a45ad81dda 100644
--- a/slirp/udp.c
+++ b/slirp/udp.c
@@ -172,8 +172,8 @@ udp_input(register struct mbuf *m, int iphlen)
 	   */
 	  so = socreate(slirp);
 	  if (udp_attach(so, AF_INET) == -1) {
-	    DEBUG_MISC((dfd," udp_attach errno = %d-%s\n",
-			errno,strerror(errno)));
+	    DEBUG_MISC(" udp_attach errno = %d-%s\n",
+                   errno, strerror(errno));
 	    sofree(so);
 	    goto bad;
 	  }
@@ -209,7 +209,7 @@ udp_input(register struct mbuf *m, int iphlen)
 	  m->m_len += iphlen;
 	  m->m_data -= iphlen;
 	  *ip=save_ip;
-	  DEBUG_MISC((dfd,"udp tx errno = %d-%s\n",errno,strerror(errno)));
+	  DEBUG_MISC("udp tx errno = %d-%s\n", errno, strerror(errno));
 	  icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0,
 	                  strerror(errno));
 	  goto bad;
diff --git a/slirp/udp6.c b/slirp/udp6.c
index 986010f0d3..473ba1586e 100644
--- a/slirp/udp6.c
+++ b/slirp/udp6.c
@@ -92,8 +92,8 @@ void udp6_input(struct mbuf *m)
         /* If there's no socket for this packet, create one. */
         so = socreate(slirp);
         if (udp_attach(so, AF_INET6) == -1) {
-            DEBUG_MISC((dfd, " udp6_attach errno = %d-%s\n",
-                        errno, strerror(errno)));
+            DEBUG_MISC(" udp6_attach errno = %d-%s\n",
+                       errno, strerror(errno));
             sofree(so);
             goto bad;
         }
@@ -119,7 +119,7 @@ void udp6_input(struct mbuf *m)
         m->m_len += iphlen;
         m->m_data -= iphlen;
         *ip = save_ip;
-        DEBUG_MISC((dfd, "udp tx errno = %d-%s\n", errno, strerror(errno)));
+        DEBUG_MISC("udp tx errno = %d-%s\n", errno, strerror(errno));
         icmp6_send_error(m, ICMP6_UNREACH, ICMP6_UNREACH_NO_ROUTE);
         goto bad;
     }
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 30/41] slirp: replace trace functions with DEBUG calls
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (28 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 29/41] slirp: improve a bit the debug macros Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-20  1:21   ` Samuel Thibault
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 31/41] slirp: add a callback to log guest errors Marc-André Lureau
                   ` (13 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Remove a dependency on QEMU. Use the existing logging facilities.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/tftp.c       | 7 ++++---
 Makefile.objs      | 1 -
 slirp/trace-events | 5 -----
 3 files changed, 4 insertions(+), 9 deletions(-)
 delete mode 100644 slirp/trace-events

diff --git a/slirp/tftp.c b/slirp/tftp.c
index 735b57aa55..dddb614b8a 100644
--- a/slirp/tftp.c
+++ b/slirp/tftp.c
@@ -26,7 +26,6 @@
 #include "slirp.h"
 #include "qemu-common.h"
 #include "qemu/cutils.h"
-#include "trace.h"
 
 static inline int tftp_session_in_use(struct tftp_session *spt)
 {
@@ -205,7 +204,8 @@ static void tftp_send_error(struct tftp_session *spt,
   struct mbuf *m;
   struct tftp_t *tp;
 
-  trace_slirp_tftp_error(msg);
+  DEBUG_ERROR("tftp error msg: %s", msg);
+
   m = m_get(spt->slirp);
 
   if (!m) {
@@ -325,7 +325,8 @@ static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas,
       break;
     }
   }
-  trace_slirp_tftp_rrq(req_fname);
+
+  DEBUG_MISC("tftp rrq file: %s", req_fname);
 
   /* check mode */
   if ((pktlen - k) < 6) {
diff --git a/Makefile.objs b/Makefile.objs
index 31852eaf8f..1e1ff387d7 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -251,7 +251,6 @@ trace-events-subdirs += net
 trace-events-subdirs += qapi
 trace-events-subdirs += qom
 trace-events-subdirs += scsi
-trace-events-subdirs += slirp
 trace-events-subdirs += target/arm
 trace-events-subdirs += target/i386
 trace-events-subdirs += target/mips
diff --git a/slirp/trace-events b/slirp/trace-events
deleted file mode 100644
index ff8f656e8c..0000000000
--- a/slirp/trace-events
+++ /dev/null
@@ -1,5 +0,0 @@
-# See docs/devel/tracing.txt for syntax documentation.
-
-# slirp/tftp.c
-slirp_tftp_rrq(const char *file) "file: %s"
-slirp_tftp_error(const char *file) "msg: %s"
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 31/41] slirp: add a callback to log guest errors
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (29 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 30/41] slirp: replace trace functions with DEBUG calls Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-20  1:27   ` Samuel Thibault
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 32/41] slirp: remove unused sbflush() Marc-André Lureau
                   ` (12 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/libslirp.h | 1 +
 net/slirp.c      | 7 +++++++
 slirp/dhcpv6.c   | 6 +++---
 slirp/ip6_icmp.c | 7 +++----
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index f2e7f94ebb..c7582e6516 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -21,6 +21,7 @@ typedef struct SlirpCb {
     void (*timer_free)(void *timer);
     void (*timer_mod)(void *timer, int64_t expire_timer);
     void (*set_nonblock)(int fd);
+    void (*guest_error)(const char *msg);
 } SlirpCb;
 
 
diff --git a/net/slirp.c b/net/slirp.c
index 5ea8c255f6..b36092c948 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/log.h"
 #include "net/slirp.h"
 
 
@@ -183,6 +184,11 @@ static void net_slirp_timer_mod(void *timer, int64_t expire_timer)
     timer_mod(timer, expire_timer);
 }
 
+static void net_slirp_guest_error(const char *msg)
+{
+    qemu_log_mask(LOG_GUEST_ERROR, "%s", msg);
+}
+
 static SlirpCb slirp_cb = {
     .output = net_slirp_output,
     .chr_write_all = net_slirp_chr_write_all,
@@ -191,6 +197,7 @@ static SlirpCb slirp_cb = {
     .timer_free = net_slirp_timer_free,
     .timer_mod = net_slirp_timer_mod,
     .set_nonblock = qemu_set_nonblock,
+    .guest_error = net_slirp_guest_error,
 };
 
 static int net_slirp_init(NetClientState *peer, const char *model,
diff --git a/slirp/dhcpv6.c b/slirp/dhcpv6.c
index 943a13bca8..5d703e8ae6 100644
--- a/slirp/dhcpv6.c
+++ b/slirp/dhcpv6.c
@@ -50,7 +50,7 @@ struct requested_infos {
  * the odata region, thus the caller must keep odata valid as long as it
  * needs to access the requested_infos struct.
  */
-static int dhcpv6_parse_info_request(uint8_t *odata, int olen,
+static int dhcpv6_parse_info_request(Slirp *slirp, uint8_t *odata, int olen,
                                      struct requested_infos *ri)
 {
     int i, req_opt;
@@ -61,7 +61,7 @@ static int dhcpv6_parse_info_request(uint8_t *odata, int olen,
         int len = odata[2] << 8 | odata[3];
 
         if (len + 4 > olen) {
-            qemu_log_mask(LOG_GUEST_ERROR, "Guest sent bad DHCPv6 packet!\n");
+            slirp->cb->guest_error("Guest sent bad DHCPv6 packet!");
             return -E2BIG;
         }
 
@@ -121,7 +121,7 @@ static void dhcpv6_info_request(Slirp *slirp, struct sockaddr_in6 *srcsas,
     struct mbuf *m;
     uint8_t *resp;
 
-    if (dhcpv6_parse_info_request(odata, olen, &ri) < 0) {
+    if (dhcpv6_parse_info_request(slirp, odata, olen, &ri) < 0) {
         return;
     }
 
diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
index 6f20190a0a..d523852a1f 100644
--- a/slirp/ip6_icmp.c
+++ b/slirp/ip6_icmp.c
@@ -343,8 +343,7 @@ static void ndp_input(struct mbuf *m, Slirp *slirp, struct ip6 *ip,
 
     case ICMP6_NDP_RA:
         DEBUG_CALL(" type = Router Advertisement");
-        qemu_log_mask(LOG_GUEST_ERROR,
-                "Warning: guest sent NDP RA, but shouldn't");
+        slirp->cb->guest_error("Warning: guest sent NDP RA, but shouldn't");
         break;
 
     case ICMP6_NDP_NS:
@@ -377,8 +376,8 @@ static void ndp_input(struct mbuf *m, Slirp *slirp, struct ip6 *ip,
 
     case ICMP6_NDP_REDIRECT:
         DEBUG_CALL(" type = Redirect");
-        qemu_log_mask(LOG_GUEST_ERROR,
-                "Warning: guest sent NDP REDIRECT, but shouldn't");
+        slirp->cb->guest_error(
+            "Warning: guest sent NDP REDIRECT, but shouldn't");
         break;
     }
 }
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 32/41] slirp: remove unused sbflush()
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (30 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 31/41] slirp: add a callback to log guest errors Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 14:05   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 33/41] slirp: replace qemu_notify_event() with a callback Marc-André Lureau
                   ` (11 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/sbuf.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/slirp/sbuf.h b/slirp/sbuf.h
index a722ecb629..644c201341 100644
--- a/slirp/sbuf.h
+++ b/slirp/sbuf.h
@@ -8,7 +8,6 @@
 #ifndef SBUF_H
 #define SBUF_H
 
-#define sbflush(sb) sbdrop((sb),(sb)->sb_cc)
 #define sbspace(sb) ((sb)->sb_datalen - (sb)->sb_cc)
 
 struct sbuf {
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 33/41] slirp: replace qemu_notify_event() with a callback
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (31 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 32/41] slirp: remove unused sbflush() Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-20  1:32   ` Samuel Thibault
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 34/41] slirp: remove #if notdef dead code Marc-André Lureau
                   ` (10 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Use a "slirp socket" helper function to call the callback when
sbdrop() returns true.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/libslirp.h  | 1 +
 slirp/sbuf.h      | 2 +-
 slirp/socket.h    | 1 +
 net/slirp.c       | 1 +
 slirp/sbuf.c      | 6 ++++--
 slirp/socket.c    | 7 +++++++
 slirp/tcp_input.c | 6 +++---
 7 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index c7582e6516..7d04404340 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -22,6 +22,7 @@ typedef struct SlirpCb {
     void (*timer_mod)(void *timer, int64_t expire_timer);
     void (*set_nonblock)(int fd);
     void (*guest_error)(const char *msg);
+    void (*notify)(void);
 } SlirpCb;
 
 
diff --git a/slirp/sbuf.h b/slirp/sbuf.h
index 644c201341..1cb9a42834 100644
--- a/slirp/sbuf.h
+++ b/slirp/sbuf.h
@@ -21,7 +21,7 @@ struct sbuf {
 };
 
 void sbfree(struct sbuf *);
-void sbdrop(struct sbuf *, int);
+bool sbdrop(struct sbuf *, int);
 void sbreserve(struct sbuf *, int);
 void sbappend(struct socket *, struct mbuf *);
 void sbcopy(struct sbuf *, int, int, char *);
diff --git a/slirp/socket.h b/slirp/socket.h
index 930ed95972..79b6fbd4c1 100644
--- a/slirp/socket.h
+++ b/slirp/socket.h
@@ -154,6 +154,7 @@ int soreadbuf(struct socket *so, const char *buf, int size);
 void sotranslate_out(struct socket *, struct sockaddr_storage *);
 void sotranslate_in(struct socket *, struct sockaddr_storage *);
 void sotranslate_accept(struct socket *);
+void sodrop(struct socket *, int num);
 
 
 #endif /* SLIRP_SOCKET_H */
diff --git a/net/slirp.c b/net/slirp.c
index b36092c948..4c39878933 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -198,6 +198,7 @@ static SlirpCb slirp_cb = {
     .timer_mod = net_slirp_timer_mod,
     .set_nonblock = qemu_set_nonblock,
     .guest_error = net_slirp_guest_error,
+    .notify = qemu_notify_event,
 };
 
 static int net_slirp_init(NetClientState *peer, const char *model,
diff --git a/slirp/sbuf.c b/slirp/sbuf.c
index 912f235f65..17f28e97a6 100644
--- a/slirp/sbuf.c
+++ b/slirp/sbuf.c
@@ -17,7 +17,7 @@ sbfree(struct sbuf *sb)
 	free(sb->sb_data);
 }
 
-void
+bool
 sbdrop(struct sbuf *sb, int num)
 {
     int limit = sb->sb_datalen / 2;
@@ -34,8 +34,10 @@ sbdrop(struct sbuf *sb, int num)
 		sb->sb_rptr -= sb->sb_datalen;
 
     if (sb->sb_cc < limit && sb->sb_cc + num >= limit) {
-        qemu_notify_event();
+        return true;
     }
+
+    return false;
 }
 
 void
diff --git a/slirp/socket.c b/slirp/socket.c
index 677fd20c9d..2b1b5052c4 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -928,3 +928,10 @@ void sotranslate_accept(struct socket *so)
         break;
     }
 }
+
+void sodrop(struct socket *s, int num)
+{
+    if (sbdrop(&s->so_snd, num)) {
+        s->slirp->cb->notify();
+    }
+}
diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c
index e33fb83df5..456d5829e7 100644
--- a/slirp/tcp_input.c
+++ b/slirp/tcp_input.c
@@ -527,7 +527,7 @@ findso:
 				    SEQ_GT(ti->ti_ack, tp->t_rtseq))
 					tcp_xmit_timer(tp, tp->t_rtt);
 				acked = ti->ti_ack - tp->snd_una;
-				sbdrop(&so->so_snd, acked);
+				sodrop(so, acked);
 				tp->snd_una = ti->ti_ack;
 				m_free(m);
 
@@ -1140,10 +1140,10 @@ trimthenstep6:
 		}
 		if (acked > so->so_snd.sb_cc) {
 			tp->snd_wnd -= so->so_snd.sb_cc;
-			sbdrop(&so->so_snd, (int )so->so_snd.sb_cc);
+			sodrop(so, (int)so->so_snd.sb_cc);
 			ourfinisacked = 1;
 		} else {
-			sbdrop(&so->so_snd, acked);
+			sodrop(so, acked);
 			tp->snd_wnd -= acked;
 			ourfinisacked = 0;
 		}
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 34/41] slirp: remove #if notdef dead code
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (32 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 33/41] slirp: replace qemu_notify_event() with a callback Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 14:07   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 35/41] slirp: NULL is defined by glib (at least) Marc-André Lureau
                   ` (9 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/ip_input.c  | 200 ----------------------------------------------
 slirp/tcp_input.c |  39 ---------
 2 files changed, 239 deletions(-)

diff --git a/slirp/ip_input.c b/slirp/ip_input.c
index 348e1dca5a..6831526320 100644
--- a/slirp/ip_input.c
+++ b/slirp/ip_input.c
@@ -447,206 +447,6 @@ ip_slowtimo(Slirp *slirp)
     }
 }
 
-/*
- * Do option processing on a datagram,
- * possibly discarding it if bad options are encountered,
- * or forwarding it if source-routed.
- * Returns 1 if packet has been forwarded/freed,
- * 0 if the packet should be processed further.
- */
-
-#ifdef notdef
-
-int
-ip_dooptions(m)
-	struct mbuf *m;
-{
-	register struct ip *ip = mtod(m, struct ip *);
-	register u_char *cp;
-	register struct ip_timestamp *ipt;
-	register struct in_ifaddr *ia;
-	int opt, optlen, cnt, off, code, type, forward = 0;
-	struct in_addr *sin, dst;
-typedef uint32_t n_time;
-	n_time ntime;
-
-	dst = ip->ip_dst;
-	cp = (u_char *)(ip + 1);
-	cnt = (ip->ip_hl << 2) - sizeof (struct ip);
-	for (; cnt > 0; cnt -= optlen, cp += optlen) {
-		opt = cp[IPOPT_OPTVAL];
-		if (opt == IPOPT_EOL)
-			break;
-		if (opt == IPOPT_NOP)
-			optlen = 1;
-		else {
-			optlen = cp[IPOPT_OLEN];
-			if (optlen <= 0 || optlen > cnt) {
-				code = &cp[IPOPT_OLEN] - (u_char *)ip;
-				goto bad;
-			}
-		}
-		switch (opt) {
-
-		default:
-			break;
-
-		/*
-		 * Source routing with record.
-		 * Find interface with current destination address.
-		 * If none on this machine then drop if strictly routed,
-		 * or do nothing if loosely routed.
-		 * Record interface address and bring up next address
-		 * component.  If strictly routed make sure next
-		 * address is on directly accessible net.
-		 */
-		case IPOPT_LSRR:
-		case IPOPT_SSRR:
-			if ((off = cp[IPOPT_OFFSET]) < IPOPT_MINOFF) {
-				code = &cp[IPOPT_OFFSET] - (u_char *)ip;
-				goto bad;
-			}
-			ipaddr.sin_addr = ip->ip_dst;
-			ia = (struct in_ifaddr *)
-				ifa_ifwithaddr((struct sockaddr *)&ipaddr);
-			if (ia == 0) {
-				if (opt == IPOPT_SSRR) {
-					type = ICMP_UNREACH;
-					code = ICMP_UNREACH_SRCFAIL;
-					goto bad;
-				}
-				/*
-				 * Loose routing, and not at next destination
-				 * yet; nothing to do except forward.
-				 */
-				break;
-			}
-                        off--; /* 0 origin */
-			if (off > optlen - sizeof(struct in_addr)) {
-				/*
-				 * End of source route.  Should be for us.
-				 */
-				save_rte(cp, ip->ip_src);
-				break;
-			}
-			/*
-			 * locate outgoing interface
-			 */
-			bcopy((caddr_t)(cp + off), (caddr_t)&ipaddr.sin_addr,
-			    sizeof(ipaddr.sin_addr));
-			if (opt == IPOPT_SSRR) {
-#define	INA	struct in_ifaddr *
-#define	SA	struct sockaddr *
- 			    if ((ia = (INA)ifa_ifwithdstaddr((SA)&ipaddr)) == 0)
-				ia = (INA)ifa_ifwithnet((SA)&ipaddr);
-			} else
-				ia = ip_rtaddr(ipaddr.sin_addr);
-			if (ia == 0) {
-				type = ICMP_UNREACH;
-				code = ICMP_UNREACH_SRCFAIL;
-				goto bad;
-			}
-			ip->ip_dst = ipaddr.sin_addr;
-			bcopy((caddr_t)&(IA_SIN(ia)->sin_addr),
-			    (caddr_t)(cp + off), sizeof(struct in_addr));
-			cp[IPOPT_OFFSET] += sizeof(struct in_addr);
-			/*
-			 * Let ip_intr's mcast routing check handle mcast pkts
-			 */
-			forward = !IN_MULTICAST(ntohl(ip->ip_dst.s_addr));
-			break;
-
-		case IPOPT_RR:
-			if ((off = cp[IPOPT_OFFSET]) < IPOPT_MINOFF) {
-				code = &cp[IPOPT_OFFSET] - (u_char *)ip;
-				goto bad;
-			}
-			/*
-			 * If no space remains, ignore.
-			 */
-                        off--; /* 0 origin */
-			if (off > optlen - sizeof(struct in_addr))
-				break;
-			bcopy((caddr_t)(&ip->ip_dst), (caddr_t)&ipaddr.sin_addr,
-			    sizeof(ipaddr.sin_addr));
-			/*
-			 * locate outgoing interface; if we're the destination,
-			 * use the incoming interface (should be same).
-			 */
-			if ((ia = (INA)ifa_ifwithaddr((SA)&ipaddr)) == 0 &&
-			    (ia = ip_rtaddr(ipaddr.sin_addr)) == 0) {
-				type = ICMP_UNREACH;
-				code = ICMP_UNREACH_HOST;
-				goto bad;
-			}
-			bcopy((caddr_t)&(IA_SIN(ia)->sin_addr),
-			    (caddr_t)(cp + off), sizeof(struct in_addr));
-			cp[IPOPT_OFFSET] += sizeof(struct in_addr);
-			break;
-
-		case IPOPT_TS:
-			code = cp - (u_char *)ip;
-			ipt = (struct ip_timestamp *)cp;
-			if (ipt->ipt_len < 5)
-				goto bad;
-			if (ipt->ipt_ptr > ipt->ipt_len - sizeof (int32_t)) {
-				if (++ipt->ipt_oflw == 0)
-					goto bad;
-				break;
-			}
-			sin = (struct in_addr *)(cp + ipt->ipt_ptr - 1);
-			switch (ipt->ipt_flg) {
-
-			case IPOPT_TS_TSONLY:
-				break;
-
-			case IPOPT_TS_TSANDADDR:
-				if (ipt->ipt_ptr + sizeof(n_time) +
-				    sizeof(struct in_addr) > ipt->ipt_len)
-					goto bad;
-				ipaddr.sin_addr = dst;
-				ia = (INA)ifaof_ i f p foraddr((SA)&ipaddr,
-							    m->m_pkthdr.rcvif);
-				if (ia == 0)
-					continue;
-				bcopy((caddr_t)&IA_SIN(ia)->sin_addr,
-				    (caddr_t)sin, sizeof(struct in_addr));
-				ipt->ipt_ptr += sizeof(struct in_addr);
-				break;
-
-			case IPOPT_TS_PRESPEC:
-				if (ipt->ipt_ptr + sizeof(n_time) +
-				    sizeof(struct in_addr) > ipt->ipt_len)
-					goto bad;
-				bcopy((caddr_t)sin, (caddr_t)&ipaddr.sin_addr,
-				    sizeof(struct in_addr));
-				if (ifa_ifwithaddr((SA)&ipaddr) == 0)
-					continue;
-				ipt->ipt_ptr += sizeof(struct in_addr);
-				break;
-
-			default:
-				goto bad;
-			}
-			ntime = iptime();
-			bcopy((caddr_t)&ntime, (caddr_t)cp + ipt->ipt_ptr - 1,
-			    sizeof(n_time));
-			ipt->ipt_ptr += sizeof(n_time);
-		}
-	}
-	if (forward) {
-		ip_forward(m, 1);
-		return (1);
-	}
-	return (0);
-bad:
-	icmp_send_error(m, type, code, 0, 0);
-
-	return (1);
-}
-
-#endif /* notdef */
-
 /*
  * Strip out IP options, at higher
  * level protocol in the kernel.
diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c
index 456d5829e7..de4ef92aba 100644
--- a/slirp/tcp_input.c
+++ b/slirp/tcp_input.c
@@ -1441,45 +1441,6 @@ tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti)
 	}
 }
 
-
-/*
- * Pull out of band byte out of a segment so
- * it doesn't appear in the user's data queue.
- * It is still reflected in the segment length for
- * sequencing purposes.
- */
-
-#ifdef notdef
-
-void
-tcp_pulloutofband(so, ti, m)
-	struct socket *so;
-	struct tcpiphdr *ti;
-	register struct mbuf *m;
-{
-	int cnt = ti->ti_urp - 1;
-
-	while (cnt >= 0) {
-		if (m->m_len > cnt) {
-			char *cp = mtod(m, caddr_t) + cnt;
-			struct tcpcb *tp = sototcpcb(so);
-
-			tp->t_iobc = *cp;
-			tp->t_oobflags |= TCPOOB_HAVEDATA;
-			memcpy(sp, cp+1, (unsigned)(m->m_len - cnt - 1));
-			m->m_len--;
-			return;
-		}
-		cnt -= m->m_len;
-		m = m->m_next; /* XXX WRONG! Fix it! */
-		if (m == 0)
-			break;
-	}
-	panic("tcp_pulloutofband");
-}
-
-#endif /* notdef */
-
 /*
  * Collect new round-trip time estimate
  * and update averages and current timeout.
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 35/41] slirp: NULL is defined by glib (at least)
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (33 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 34/41] slirp: remove #if notdef dead code Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 14:11   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 36/41] slirp: remove dead TCP_ACK_HACK code Marc-André Lureau
                   ` (8 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp.h | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/slirp/slirp.h b/slirp/slirp.h
index 4356b2f427..2a61a85995 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -199,10 +199,6 @@ struct Slirp {
     void *opaque;
 };
 
-#ifndef NULL
-#define NULL (void *)0
-#endif
-
 void if_start(Slirp *);
 
 int get_dns_addr(struct in_addr *pdns_addr);
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 36/41] slirp: remove dead TCP_ACK_HACK code
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (34 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 35/41] slirp: NULL is defined by glib (at least) Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 14:12   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS Marc-André Lureau
                   ` (7 subsequent siblings)
  43 siblings, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Untouched since original introduction in 2004.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/tcp_input.c | 23 +----------------------
 1 file changed, 1 insertion(+), 22 deletions(-)

diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c
index de4ef92aba..0d34abf8d7 100644
--- a/slirp/tcp_input.c
+++ b/slirp/tcp_input.c
@@ -60,27 +60,6 @@
  * Set DELACK for segments received in order, but ack immediately
  * when segments are out of order (so fast retransmit can work).
  */
-#ifdef TCP_ACK_HACK
-#define TCP_REASS(tp, ti, m, so, flags) {\
-       if ((ti)->ti_seq == (tp)->rcv_nxt && \
-           tcpfrag_list_empty(tp) && \
-           (tp)->t_state == TCPS_ESTABLISHED) {\
-               if (ti->ti_flags & TH_PUSH) \
-                       tp->t_flags |= TF_ACKNOW; \
-               else \
-                       tp->t_flags |= TF_DELACK; \
-               (tp)->rcv_nxt += (ti)->ti_len; \
-               flags = (ti)->ti_flags & TH_FIN; \
-               if (so->so_emu) { \
-		       if (tcp_emu((so),(m))) sbappend((so), (m)); \
-	       } else \
-	       	       sbappend((so), (m)); \
-	} else {\
-               (flags) = tcp_reass((tp), (ti), (m)); \
-               tp->t_flags |= TF_ACKNOW; \
-       } \
-}
-#else
 #define	TCP_REASS(tp, ti, m, so, flags) { \
 	if ((ti)->ti_seq == (tp)->rcv_nxt && \
         tcpfrag_list_empty(tp) && \
@@ -97,7 +76,7 @@
 		tp->t_flags |= TF_ACKNOW; \
 	} \
 }
-#endif
+
 static void tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt,
                           struct tcpiphdr *ti);
 static void tcp_xmit_timer(register struct tcpcb *tp, int rtt);
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (35 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 36/41] slirp: remove dead TCP_ACK_HACK code Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:17   ` Philippe Mathieu-Daudé
  2018-11-14 14:15   ` Daniel P. Berrangé
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 38/41] net: do not depend on slirp internals Marc-André Lureau
                   ` (6 subsequent siblings)
  43 siblings, 2 replies; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Do not require QEMU macro.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/ncsi.c | 2 +-
 slirp/tftp.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/slirp/ncsi.c b/slirp/ncsi.c
index 10decfb5ef..8594382270 100644
--- a/slirp/ncsi.c
+++ b/slirp/ncsi.c
@@ -128,7 +128,7 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
     memset(reh->h_source, 0xff, ETH_ALEN);
     reh->h_proto = htons(ETH_P_NCSI);
 
-    for (i = 0; i < ARRAY_SIZE(ncsi_rsp_handlers); i++) {
+    for (i = 0; i < G_N_ELEMENTS(ncsi_rsp_handlers); i++) {
         if (ncsi_rsp_handlers[i].type == nh->type + 0x80) {
             handler = &ncsi_rsp_handlers[i];
             break;
diff --git a/slirp/tftp.c b/slirp/tftp.c
index dddb614b8a..ef8d0352b4 100644
--- a/slirp/tftp.c
+++ b/slirp/tftp.c
@@ -360,7 +360,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas,
       return;
   }
 
-  while (k < pktlen && nb_options < ARRAY_SIZE(option_name)) {
+  while (k < pktlen && nb_options < G_N_ELEMENTS(option_name)) {
       const char *key, *value;
 
       key = &tp->x.tp_buf[k];
@@ -404,7 +404,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas,
   }
 
   if (nb_options > 0) {
-      assert(nb_options <= ARRAY_SIZE(option_name));
+      assert(nb_options <= G_N_ELEMENTS(option_name));
       tftp_send_oack(spt, option_name, option_value, nb_options, tp);
       return;
   }
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 38/41] net: do not depend on slirp internals
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (36 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 13:21   ` Philippe Mathieu-Daudé
  2018-11-15 13:19   ` Paolo Bonzini
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 39/41] slirp: move QEMU state saving to a separate unit Marc-André Lureau
                   ` (5 subsequent siblings)
  43 siblings, 2 replies; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Only slirp/libslirp.h should be included.

Instead of using some slirp declarations and utility functions directly,
let's copy them in net/util.h.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 net/colo.h            |  3 +--
 net/util.h            | 55 +++++++++++++++++++++++++++++++++++++++++++
 net/colo-compare.c    |  1 +
 net/colo.c            |  1 +
 net/filter-rewriter.c |  1 +
 net/slirp.c           |  2 +-
 stubs/slirp.c         |  2 +-
 7 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/net/colo.h b/net/colo.h
index 11c5226488..420d916af2 100644
--- a/net/colo.h
+++ b/net/colo.h
@@ -15,10 +15,9 @@
 #ifndef QEMU_COLO_PROXY_H
 #define QEMU_COLO_PROXY_H
 
-#include "slirp/slirp.h"
 #include "qemu/jhash.h"
 #include "qemu/timer.h"
-#include "slirp/tcp.h"
+#include "net/eth.h"
 
 #define HASHTABLE_MAX_SIZE 16384
 
diff --git a/net/util.h b/net/util.h
index 60b73d372d..358185fd50 100644
--- a/net/util.h
+++ b/net/util.h
@@ -26,6 +26,61 @@
 #define QEMU_NET_UTIL_H
 
 
+/*
+ * Structure of an internet header, naked of options.
+ */
+struct ip {
+#ifdef HOST_WORDS_BIGENDIAN
+    uint8_t ip_v:4,         /* version */
+            ip_hl:4;        /* header length */
+#else
+    uint8_t ip_hl:4,        /* header length */
+            ip_v:4;         /* version */
+#endif
+    uint8_t ip_tos;         /* type of service */
+    uint16_t ip_len;        /* total length */
+    uint16_t ip_id;         /* identification */
+    uint16_t ip_off;        /* fragment offset field */
+#define IP_DF 0x4000        /* don't fragment flag */
+#define IP_MF 0x2000        /* more fragments flag */
+#define IP_OFFMASK 0x1fff   /* mask for fragmenting bits */
+    uint8_t ip_ttl;         /* time to live */
+    uint8_t ip_p;           /* protocol */
+    uint16_t ip_sum;        /* checksum */
+    struct in_addr ip_src, ip_dst;  /* source and dest address */
+} QEMU_PACKED;
+
+static inline bool in6_equal_net(const struct in6_addr *a,
+                                 const struct in6_addr *b,
+                                 int prefix_len)
+{
+    if (memcmp(a, b, prefix_len / 8) != 0) {
+        return 0;
+    }
+
+    if (prefix_len % 8 == 0) {
+        return 1;
+    }
+
+    return a->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8))
+        == b->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8));
+}
+
+#define TCPS_CLOSED             0       /* closed */
+#define TCPS_LISTEN             1       /* listening for connection */
+#define TCPS_SYN_SENT           2       /* active, have sent syn */
+#define TCPS_SYN_RECEIVED       3       /* have send and received syn */
+/* states < TCPS_ESTABLISHED are those where connections not established */
+#define TCPS_ESTABLISHED        4       /* established */
+#define TCPS_CLOSE_WAIT         5       /* rcvd fin, waiting for close */
+/* states > TCPS_CLOSE_WAIT are those where user has closed */
+#define TCPS_FIN_WAIT_1         6       /* have closed, sent fin */
+#define TCPS_CLOSING            7       /* closed xchd FIN; await FIN ACK */
+#define TCPS_LAST_ACK           8       /* had fin and close; await FIN ACK */
+/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
+#define TCPS_FIN_WAIT_2         9       /* have closed, fin is acked */
+#define TCPS_TIME_WAIT          10      /* in 2*msl quiet wait after close */
+
 int net_parse_macaddr(uint8_t *macaddr, const char *p);
 
 #endif /* QEMU_NET_UTIL_H */
diff --git a/net/colo-compare.c b/net/colo-compare.c
index a39191d522..3b6f596432 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -30,6 +30,7 @@
 #include "net/colo-compare.h"
 #include "migration/colo.h"
 #include "migration/migration.h"
+#include "util.h"
 
 #define TYPE_COLO_COMPARE "colo-compare"
 #define COLO_COMPARE(obj) \
diff --git a/net/colo.c b/net/colo.c
index 49176bf07b..8196b35837 100644
--- a/net/colo.c
+++ b/net/colo.c
@@ -15,6 +15,7 @@
 #include "qemu/osdep.h"
 #include "trace.h"
 #include "colo.h"
+#include "util.h"
 
 uint32_t connection_key_hash(const void *opaque)
 {
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
index bb8f4d93b1..9ccd8947db 100644
--- a/net/filter-rewriter.c
+++ b/net/filter-rewriter.c
@@ -22,6 +22,7 @@
 #include "net/checksum.h"
 #include "net/colo.h"
 #include "migration/colo.h"
+#include "util.h"
 
 #define FILTER_COLO_REWRITER(obj) \
     OBJECT_CHECK(RewriterState, (obj), TYPE_FILTER_REWRITER)
diff --git a/net/slirp.c b/net/slirp.c
index 4c39878933..7524049e49 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -38,12 +38,12 @@
 #include "qemu/error-report.h"
 #include "qemu/sockets.h"
 #include "slirp/libslirp.h"
-#include "slirp/ip6.h"
 #include "chardev/char-fe.h"
 #include "sysemu/sysemu.h"
 #include "qemu/cutils.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
+#include "util.h"
 
 static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
 {
diff --git a/stubs/slirp.c b/stubs/slirp.c
index 42f7e1afd0..70704346fd 100644
--- a/stubs/slirp.c
+++ b/stubs/slirp.c
@@ -1,7 +1,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "qemu/host-utils.h"
-#include "slirp/slirp.h"
+#include "slirp/libslirp.h"
 
 void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
 {
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 39/41] slirp: move QEMU state saving to a separate unit
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (37 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 38/41] net: do not depend on slirp internals Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 40/41] slirp: replace remaining QEMU dependency Marc-André Lureau
                   ` (4 subsequent siblings)
  43 siblings, 0 replies; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Make state saving optional: this will allow to build SLIRP without
QEMU. (eventually, the vmstate helpers will be extracted, so an
external project & process could save its state)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/slirp.h       |   3 +
 slirp/state.h       |   9 +
 slirp/slirp.c       | 371 ++---------------------------------------
 slirp/state.c       | 394 ++++++++++++++++++++++++++++++++++++++++++++
 slirp/Makefile.objs |   4 +-
 5 files changed, 420 insertions(+), 361 deletions(-)
 create mode 100644 slirp/state.h
 create mode 100644 slirp/state.c

diff --git a/slirp/slirp.h b/slirp/slirp.h
index 2a61a85995..e5cd0cd334 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -270,4 +270,7 @@ int tcp_emu(struct socket *, struct mbuf *);
 int tcp_ctl(struct socket *);
 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
 
+struct socket *
+slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr, int guest_port);
+
 #endif
diff --git a/slirp/state.h b/slirp/state.h
new file mode 100644
index 0000000000..154866898f
--- /dev/null
+++ b/slirp/state.h
@@ -0,0 +1,9 @@
+#ifndef SLIRP_STATE_H_
+#define SLIRP_STATE_H_
+
+#include "libslirp.h"
+
+void slirp_state_register(Slirp *slirp);
+void slirp_state_unregister(Slirp *slirp);
+
+#endif /* SLIRP_STATE_H_ */
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 9a87abee27..8b56f28d77 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -31,6 +31,10 @@
 #include "hw/hw.h"
 #include "qemu/cutils.h"
 
+#ifdef WITH_STATE
+#include "state.h"
+#endif
+
 #ifndef _WIN32
 #include <net/if.h>
 #endif
@@ -273,14 +277,6 @@ static void slirp_init_once(void)
     loopback_mask = htonl(IN_CLASSA_NET);
 }
 
-static void slirp_state_save(QEMUFile *f, void *opaque);
-static int slirp_state_load(QEMUFile *f, void *opaque, int version_id);
-
-static SaveVMHandlers savevm_slirp_state = {
-    .save_state = slirp_state_save,
-    .load_state = slirp_state_load,
-};
-
 Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
                   struct in_addr vnetmask, struct in_addr vhost,
                   bool in6_enabled,
@@ -336,8 +332,9 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
 
     slirp->opaque = opaque;
 
-    register_savevm_live(NULL, "slirp", 0, 4, &savevm_slirp_state, slirp);
-
+#ifdef WITH_STATE
+    slirp_state_register(slirp);
+#endif
     QTAILQ_INSERT_TAIL(&slirp_instances, slirp, entry);
 
     return slirp;
@@ -354,9 +351,9 @@ void slirp_cleanup(Slirp *slirp)
     }
 
     QTAILQ_REMOVE(&slirp_instances, slirp, entry);
-
-    unregister_savevm(NULL, "slirp", slirp);
-
+#ifdef WITH_STATE
+    slirp_state_unregister(slirp);
+#endif
     ip_cleanup(slirp);
     ip6_cleanup(slirp);
     m_cleanup(slirp);
@@ -1080,7 +1077,7 @@ ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags)
     return send(so->s, buf, len, flags);
 }
 
-static struct socket *
+struct socket *
 slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr, int guest_port)
 {
     struct socket *so;
@@ -1128,349 +1125,3 @@ void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port,
         tcp_output(sototcpcb(so));
 }
 
-static int slirp_tcp_post_load(void *opaque, int version)
-{
-    tcp_template((struct tcpcb *)opaque);
-
-    return 0;
-}
-
-static const VMStateDescription vmstate_slirp_tcp = {
-    .name = "slirp-tcp",
-    .version_id = 0,
-    .post_load = slirp_tcp_post_load,
-    .fields = (VMStateField[]) {
-        VMSTATE_INT16(t_state, struct tcpcb),
-        VMSTATE_INT16_ARRAY(t_timer, struct tcpcb, TCPT_NTIMERS),
-        VMSTATE_INT16(t_rxtshift, struct tcpcb),
-        VMSTATE_INT16(t_rxtcur, struct tcpcb),
-        VMSTATE_INT16(t_dupacks, struct tcpcb),
-        VMSTATE_UINT16(t_maxseg, struct tcpcb),
-        VMSTATE_UINT8(t_force, struct tcpcb),
-        VMSTATE_UINT16(t_flags, struct tcpcb),
-        VMSTATE_UINT32(snd_una, struct tcpcb),
-        VMSTATE_UINT32(snd_nxt, struct tcpcb),
-        VMSTATE_UINT32(snd_up, struct tcpcb),
-        VMSTATE_UINT32(snd_wl1, struct tcpcb),
-        VMSTATE_UINT32(snd_wl2, struct tcpcb),
-        VMSTATE_UINT32(iss, struct tcpcb),
-        VMSTATE_UINT32(snd_wnd, struct tcpcb),
-        VMSTATE_UINT32(rcv_wnd, struct tcpcb),
-        VMSTATE_UINT32(rcv_nxt, struct tcpcb),
-        VMSTATE_UINT32(rcv_up, struct tcpcb),
-        VMSTATE_UINT32(irs, struct tcpcb),
-        VMSTATE_UINT32(rcv_adv, struct tcpcb),
-        VMSTATE_UINT32(snd_max, struct tcpcb),
-        VMSTATE_UINT32(snd_cwnd, struct tcpcb),
-        VMSTATE_UINT32(snd_ssthresh, struct tcpcb),
-        VMSTATE_INT16(t_idle, struct tcpcb),
-        VMSTATE_INT16(t_rtt, struct tcpcb),
-        VMSTATE_UINT32(t_rtseq, struct tcpcb),
-        VMSTATE_INT16(t_srtt, struct tcpcb),
-        VMSTATE_INT16(t_rttvar, struct tcpcb),
-        VMSTATE_UINT16(t_rttmin, struct tcpcb),
-        VMSTATE_UINT32(max_sndwnd, struct tcpcb),
-        VMSTATE_UINT8(t_oobflags, struct tcpcb),
-        VMSTATE_UINT8(t_iobc, struct tcpcb),
-        VMSTATE_INT16(t_softerror, struct tcpcb),
-        VMSTATE_UINT8(snd_scale, struct tcpcb),
-        VMSTATE_UINT8(rcv_scale, struct tcpcb),
-        VMSTATE_UINT8(request_r_scale, struct tcpcb),
-        VMSTATE_UINT8(requested_s_scale, struct tcpcb),
-        VMSTATE_UINT32(ts_recent, struct tcpcb),
-        VMSTATE_UINT32(ts_recent_age, struct tcpcb),
-        VMSTATE_UINT32(last_ack_sent, struct tcpcb),
-        VMSTATE_END_OF_LIST()
-    }
-};
-
-/* The sbuf has a pair of pointers that are migrated as offsets;
- * we calculate the offsets and restore the pointers using
- * pre_save/post_load on a tmp structure.
- */
-struct sbuf_tmp {
-    struct sbuf *parent;
-    uint32_t roff, woff;
-};
-
-static int sbuf_tmp_pre_save(void *opaque)
-{
-    struct sbuf_tmp *tmp = opaque;
-    tmp->woff = tmp->parent->sb_wptr - tmp->parent->sb_data;
-    tmp->roff = tmp->parent->sb_rptr - tmp->parent->sb_data;
-
-    return 0;
-}
-
-static int sbuf_tmp_post_load(void *opaque, int version)
-{
-    struct sbuf_tmp *tmp = opaque;
-    uint32_t requested_len = tmp->parent->sb_datalen;
-
-    /* Allocate the buffer space used by the field after the tmp */
-    sbreserve(tmp->parent, tmp->parent->sb_datalen);
-
-    if (tmp->parent->sb_datalen != requested_len) {
-        return -ENOMEM;
-    }
-    if (tmp->woff >= requested_len ||
-        tmp->roff >= requested_len) {
-        g_critical("invalid sbuf offsets r/w=%u/%u len=%u",
-                   tmp->roff, tmp->woff, requested_len);
-        return -EINVAL;
-    }
-
-    tmp->parent->sb_wptr = tmp->parent->sb_data + tmp->woff;
-    tmp->parent->sb_rptr = tmp->parent->sb_data + tmp->roff;
-
-    return 0;
-}
-
-
-static const VMStateDescription vmstate_slirp_sbuf_tmp = {
-    .name = "slirp-sbuf-tmp",
-    .post_load = sbuf_tmp_post_load,
-    .pre_save  = sbuf_tmp_pre_save,
-    .version_id = 0,
-    .fields = (VMStateField[]) {
-        VMSTATE_UINT32(woff, struct sbuf_tmp),
-        VMSTATE_UINT32(roff, struct sbuf_tmp),
-        VMSTATE_END_OF_LIST()
-    }
-};
-
-static const VMStateDescription vmstate_slirp_sbuf = {
-    .name = "slirp-sbuf",
-    .version_id = 0,
-    .fields = (VMStateField[]) {
-        VMSTATE_UINT32(sb_cc, struct sbuf),
-        VMSTATE_UINT32(sb_datalen, struct sbuf),
-        VMSTATE_WITH_TMP(struct sbuf, struct sbuf_tmp, vmstate_slirp_sbuf_tmp),
-        VMSTATE_VBUFFER_UINT32(sb_data, struct sbuf, 0, NULL, sb_datalen),
-        VMSTATE_END_OF_LIST()
-    }
-};
-
-static bool slirp_older_than_v4(void *opaque, int version_id)
-{
-    return version_id < 4;
-}
-
-static bool slirp_family_inet(void *opaque, int version_id)
-{
-    union slirp_sockaddr *ssa = (union slirp_sockaddr *)opaque;
-    return ssa->ss.ss_family == AF_INET;
-}
-
-static int slirp_socket_pre_load(void *opaque)
-{
-    struct socket *so = opaque;
-    if (tcp_attach(so) < 0) {
-        return -ENOMEM;
-    }
-    /* Older versions don't load these fields */
-    so->so_ffamily = AF_INET;
-    so->so_lfamily = AF_INET;
-    return 0;
-}
-
-#ifndef _WIN32
-#define VMSTATE_SIN4_ADDR(f, s, t) VMSTATE_UINT32_TEST(f, s, t)
-#else
-/* Win uses u_long rather than uint32_t - but it's still 32bits long */
-#define VMSTATE_SIN4_ADDR(f, s, t) VMSTATE_SINGLE_TEST(f, s, t, 0, \
-                                       vmstate_info_uint32, u_long)
-#endif
-
-/* The OS provided ss_family field isn't that portable; it's size
- * and type varies (16/8 bit, signed, unsigned)
- * and the values it contains aren't fully portable.
- */
-typedef struct SS_FamilyTmpStruct {
-    union slirp_sockaddr    *parent;
-    uint16_t                 portable_family;
-} SS_FamilyTmpStruct;
-
-#define SS_FAMILY_MIG_IPV4   2  /* Linux, BSD, Win... */
-#define SS_FAMILY_MIG_IPV6  10  /* Linux */
-#define SS_FAMILY_MIG_OTHER 0xffff
-
-static int ss_family_pre_save(void *opaque)
-{
-    SS_FamilyTmpStruct *tss = opaque;
-
-    tss->portable_family = SS_FAMILY_MIG_OTHER;
-
-    if (tss->parent->ss.ss_family == AF_INET) {
-        tss->portable_family = SS_FAMILY_MIG_IPV4;
-    } else if (tss->parent->ss.ss_family == AF_INET6) {
-        tss->portable_family = SS_FAMILY_MIG_IPV6;
-    }
-
-    return 0;
-}
-
-static int ss_family_post_load(void *opaque, int version_id)
-{
-    SS_FamilyTmpStruct *tss = opaque;
-
-    switch (tss->portable_family) {
-    case SS_FAMILY_MIG_IPV4:
-        tss->parent->ss.ss_family = AF_INET;
-        break;
-    case SS_FAMILY_MIG_IPV6:
-    case 23: /* compatibility: AF_INET6 from mingw */
-    case 28: /* compatibility: AF_INET6 from FreeBSD sys/socket.h */
-        tss->parent->ss.ss_family = AF_INET6;
-        break;
-    default:
-        g_critical("invalid ss_family type %x", tss->portable_family);
-        return -EINVAL;
-    }
-
-    return 0;
-}
-
-static const VMStateDescription vmstate_slirp_ss_family = {
-    .name = "slirp-socket-addr/ss_family",
-    .pre_save  = ss_family_pre_save,
-    .post_load = ss_family_post_load,
-    .fields = (VMStateField[]) {
-        VMSTATE_UINT16(portable_family, SS_FamilyTmpStruct),
-        VMSTATE_END_OF_LIST()
-    }
-};
-
-static const VMStateDescription vmstate_slirp_socket_addr = {
-    .name = "slirp-socket-addr",
-    .version_id = 4,
-    .fields = (VMStateField[]) {
-        VMSTATE_WITH_TMP(union slirp_sockaddr, SS_FamilyTmpStruct,
-                            vmstate_slirp_ss_family),
-        VMSTATE_SIN4_ADDR(sin.sin_addr.s_addr, union slirp_sockaddr,
-                            slirp_family_inet),
-        VMSTATE_UINT16_TEST(sin.sin_port, union slirp_sockaddr,
-                            slirp_family_inet),
-
-#if 0
-        /* Untested: Needs checking by someone with IPv6 test */
-        VMSTATE_BUFFER_TEST(sin6.sin6_addr, union slirp_sockaddr,
-                            slirp_family_inet6),
-        VMSTATE_UINT16_TEST(sin6.sin6_port, union slirp_sockaddr,
-                            slirp_family_inet6),
-        VMSTATE_UINT32_TEST(sin6.sin6_flowinfo, union slirp_sockaddr,
-                            slirp_family_inet6),
-        VMSTATE_UINT32_TEST(sin6.sin6_scope_id, union slirp_sockaddr,
-                            slirp_family_inet6),
-#endif
-
-        VMSTATE_END_OF_LIST()
-    }
-};
-
-static const VMStateDescription vmstate_slirp_socket = {
-    .name = "slirp-socket",
-    .version_id = 4,
-    .pre_load = slirp_socket_pre_load,
-    .fields = (VMStateField[]) {
-        VMSTATE_UINT32(so_urgc, struct socket),
-        /* Pre-v4 versions */
-        VMSTATE_SIN4_ADDR(so_faddr.s_addr, struct socket,
-                            slirp_older_than_v4),
-        VMSTATE_SIN4_ADDR(so_laddr.s_addr, struct socket,
-                            slirp_older_than_v4),
-        VMSTATE_UINT16_TEST(so_fport, struct socket, slirp_older_than_v4),
-        VMSTATE_UINT16_TEST(so_lport, struct socket, slirp_older_than_v4),
-        /* v4 and newer */
-        VMSTATE_STRUCT(fhost, struct socket, 4, vmstate_slirp_socket_addr,
-                       union slirp_sockaddr),
-        VMSTATE_STRUCT(lhost, struct socket, 4, vmstate_slirp_socket_addr,
-                       union slirp_sockaddr),
-
-        VMSTATE_UINT8(so_iptos, struct socket),
-        VMSTATE_UINT8(so_emu, struct socket),
-        VMSTATE_UINT8(so_type, struct socket),
-        VMSTATE_INT32(so_state, struct socket),
-        VMSTATE_STRUCT(so_rcv, struct socket, 0, vmstate_slirp_sbuf,
-                       struct sbuf),
-        VMSTATE_STRUCT(so_snd, struct socket, 0, vmstate_slirp_sbuf,
-                       struct sbuf),
-        VMSTATE_STRUCT_POINTER(so_tcpcb, struct socket, vmstate_slirp_tcp,
-                       struct tcpcb),
-        VMSTATE_END_OF_LIST()
-    }
-};
-
-static const VMStateDescription vmstate_slirp_bootp_client = {
-    .name = "slirp_bootpclient",
-    .fields = (VMStateField[]) {
-        VMSTATE_UINT16(allocated, BOOTPClient),
-        VMSTATE_BUFFER(macaddr, BOOTPClient),
-        VMSTATE_END_OF_LIST()
-    }
-};
-
-static const VMStateDescription vmstate_slirp = {
-    .name = "slirp",
-    .version_id = 4,
-    .fields = (VMStateField[]) {
-        VMSTATE_UINT16_V(ip_id, Slirp, 2),
-        VMSTATE_STRUCT_ARRAY(bootp_clients, Slirp, NB_BOOTP_CLIENTS, 3,
-                             vmstate_slirp_bootp_client, BOOTPClient),
-        VMSTATE_END_OF_LIST()
-    }
-};
-
-static void slirp_state_save(QEMUFile *f, void *opaque)
-{
-    Slirp *slirp = opaque;
-    struct ex_list *ex_ptr;
-
-    for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next)
-        if (ex_ptr->ex_chardev) {
-            struct socket *so;
-            so = slirp_find_ctl_socket(slirp, ex_ptr->ex_addr,
-                                       ntohs(ex_ptr->ex_fport));
-            if (!so)
-                continue;
-
-            qemu_put_byte(f, 42);
-            vmstate_save_state(f, &vmstate_slirp_socket, so, NULL);
-        }
-    qemu_put_byte(f, 0);
-
-    vmstate_save_state(f, &vmstate_slirp, slirp, NULL);
-}
-
-
-static int slirp_state_load(QEMUFile *f, void *opaque, int version_id)
-{
-    Slirp *slirp = opaque;
-    struct ex_list *ex_ptr;
-
-    while (qemu_get_byte(f)) {
-        int ret;
-        struct socket *so = socreate(slirp);
-
-        ret = vmstate_load_state(f, &vmstate_slirp_socket, so, version_id);
-
-        if (ret < 0)
-            return ret;
-
-        if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) !=
-            slirp->vnetwork_addr.s_addr) {
-            return -EINVAL;
-        }
-        for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {
-            if (ex_ptr->ex_chardev &&
-                so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr &&
-                so->so_fport == ex_ptr->ex_fport) {
-                break;
-            }
-        }
-        if (!ex_ptr)
-            return -EINVAL;
-    }
-
-    return vmstate_load_state(f, &vmstate_slirp, slirp, version_id);
-}
diff --git a/slirp/state.c b/slirp/state.c
new file mode 100644
index 0000000000..1572761aa1
--- /dev/null
+++ b/slirp/state.c
@@ -0,0 +1,394 @@
+/*
+ * libslirp
+ *
+ * Copyright (c) 2004-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "qemu/osdep.h"
+
+#include "slirp.h"
+#include "state.h"
+#include "migration/vmstate.h"
+#include "migration/qemu-file-types.h"
+#include "migration/register.h"
+
+static int slirp_tcp_post_load(void *opaque, int version)
+{
+    tcp_template((struct tcpcb *)opaque);
+
+    return 0;
+}
+
+static const VMStateDescription vmstate_slirp_tcp = {
+    .name = "slirp-tcp",
+    .version_id = 0,
+    .post_load = slirp_tcp_post_load,
+    .fields = (VMStateField[]) {
+        VMSTATE_INT16(t_state, struct tcpcb),
+        VMSTATE_INT16_ARRAY(t_timer, struct tcpcb, TCPT_NTIMERS),
+        VMSTATE_INT16(t_rxtshift, struct tcpcb),
+        VMSTATE_INT16(t_rxtcur, struct tcpcb),
+        VMSTATE_INT16(t_dupacks, struct tcpcb),
+        VMSTATE_UINT16(t_maxseg, struct tcpcb),
+        VMSTATE_UINT8(t_force, struct tcpcb),
+        VMSTATE_UINT16(t_flags, struct tcpcb),
+        VMSTATE_UINT32(snd_una, struct tcpcb),
+        VMSTATE_UINT32(snd_nxt, struct tcpcb),
+        VMSTATE_UINT32(snd_up, struct tcpcb),
+        VMSTATE_UINT32(snd_wl1, struct tcpcb),
+        VMSTATE_UINT32(snd_wl2, struct tcpcb),
+        VMSTATE_UINT32(iss, struct tcpcb),
+        VMSTATE_UINT32(snd_wnd, struct tcpcb),
+        VMSTATE_UINT32(rcv_wnd, struct tcpcb),
+        VMSTATE_UINT32(rcv_nxt, struct tcpcb),
+        VMSTATE_UINT32(rcv_up, struct tcpcb),
+        VMSTATE_UINT32(irs, struct tcpcb),
+        VMSTATE_UINT32(rcv_adv, struct tcpcb),
+        VMSTATE_UINT32(snd_max, struct tcpcb),
+        VMSTATE_UINT32(snd_cwnd, struct tcpcb),
+        VMSTATE_UINT32(snd_ssthresh, struct tcpcb),
+        VMSTATE_INT16(t_idle, struct tcpcb),
+        VMSTATE_INT16(t_rtt, struct tcpcb),
+        VMSTATE_UINT32(t_rtseq, struct tcpcb),
+        VMSTATE_INT16(t_srtt, struct tcpcb),
+        VMSTATE_INT16(t_rttvar, struct tcpcb),
+        VMSTATE_UINT16(t_rttmin, struct tcpcb),
+        VMSTATE_UINT32(max_sndwnd, struct tcpcb),
+        VMSTATE_UINT8(t_oobflags, struct tcpcb),
+        VMSTATE_UINT8(t_iobc, struct tcpcb),
+        VMSTATE_INT16(t_softerror, struct tcpcb),
+        VMSTATE_UINT8(snd_scale, struct tcpcb),
+        VMSTATE_UINT8(rcv_scale, struct tcpcb),
+        VMSTATE_UINT8(request_r_scale, struct tcpcb),
+        VMSTATE_UINT8(requested_s_scale, struct tcpcb),
+        VMSTATE_UINT32(ts_recent, struct tcpcb),
+        VMSTATE_UINT32(ts_recent_age, struct tcpcb),
+        VMSTATE_UINT32(last_ack_sent, struct tcpcb),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+/* The sbuf has a pair of pointers that are migrated as offsets;
+ * we calculate the offsets and restore the pointers using
+ * pre_save/post_load on a tmp structure.
+ */
+struct sbuf_tmp {
+    struct sbuf *parent;
+    uint32_t roff, woff;
+};
+
+static int sbuf_tmp_pre_save(void *opaque)
+{
+    struct sbuf_tmp *tmp = opaque;
+    tmp->woff = tmp->parent->sb_wptr - tmp->parent->sb_data;
+    tmp->roff = tmp->parent->sb_rptr - tmp->parent->sb_data;
+
+    return 0;
+}
+
+static int sbuf_tmp_post_load(void *opaque, int version)
+{
+    struct sbuf_tmp *tmp = opaque;
+    uint32_t requested_len = tmp->parent->sb_datalen;
+
+    /* Allocate the buffer space used by the field after the tmp */
+    sbreserve(tmp->parent, tmp->parent->sb_datalen);
+
+    if (tmp->parent->sb_datalen != requested_len) {
+        return -ENOMEM;
+    }
+    if (tmp->woff >= requested_len ||
+        tmp->roff >= requested_len) {
+        g_critical("invalid sbuf offsets r/w=%u/%u len=%u",
+                   tmp->roff, tmp->woff, requested_len);
+        return -EINVAL;
+    }
+
+    tmp->parent->sb_wptr = tmp->parent->sb_data + tmp->woff;
+    tmp->parent->sb_rptr = tmp->parent->sb_data + tmp->roff;
+
+    return 0;
+}
+
+
+static const VMStateDescription vmstate_slirp_sbuf_tmp = {
+    .name = "slirp-sbuf-tmp",
+    .post_load = sbuf_tmp_post_load,
+    .pre_save  = sbuf_tmp_pre_save,
+    .version_id = 0,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32(woff, struct sbuf_tmp),
+        VMSTATE_UINT32(roff, struct sbuf_tmp),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static const VMStateDescription vmstate_slirp_sbuf = {
+    .name = "slirp-sbuf",
+    .version_id = 0,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32(sb_cc, struct sbuf),
+        VMSTATE_UINT32(sb_datalen, struct sbuf),
+        VMSTATE_WITH_TMP(struct sbuf, struct sbuf_tmp, vmstate_slirp_sbuf_tmp),
+        VMSTATE_VBUFFER_UINT32(sb_data, struct sbuf, 0, NULL, sb_datalen),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static bool slirp_older_than_v4(void *opaque, int version_id)
+{
+    return version_id < 4;
+}
+
+static bool slirp_family_inet(void *opaque, int version_id)
+{
+    union slirp_sockaddr *ssa = (union slirp_sockaddr *)opaque;
+    return ssa->ss.ss_family == AF_INET;
+}
+
+static int slirp_socket_pre_load(void *opaque)
+{
+    struct socket *so = opaque;
+    if (tcp_attach(so) < 0) {
+        return -ENOMEM;
+    }
+    /* Older versions don't load these fields */
+    so->so_ffamily = AF_INET;
+    so->so_lfamily = AF_INET;
+    return 0;
+}
+
+#ifndef _WIN32
+#define VMSTATE_SIN4_ADDR(f, s, t) VMSTATE_UINT32_TEST(f, s, t)
+#else
+/* Win uses u_long rather than uint32_t - but it's still 32bits long */
+#define VMSTATE_SIN4_ADDR(f, s, t) VMSTATE_SINGLE_TEST(f, s, t, 0, \
+                                       vmstate_info_uint32, u_long)
+#endif
+
+/* The OS provided ss_family field isn't that portable; it's size
+ * and type varies (16/8 bit, signed, unsigned)
+ * and the values it contains aren't fully portable.
+ */
+typedef struct SS_FamilyTmpStruct {
+    union slirp_sockaddr    *parent;
+    uint16_t                 portable_family;
+} SS_FamilyTmpStruct;
+
+#define SS_FAMILY_MIG_IPV4   2  /* Linux, BSD, Win... */
+#define SS_FAMILY_MIG_IPV6  10  /* Linux */
+#define SS_FAMILY_MIG_OTHER 0xffff
+
+static int ss_family_pre_save(void *opaque)
+{
+    SS_FamilyTmpStruct *tss = opaque;
+
+    tss->portable_family = SS_FAMILY_MIG_OTHER;
+
+    if (tss->parent->ss.ss_family == AF_INET) {
+        tss->portable_family = SS_FAMILY_MIG_IPV4;
+    } else if (tss->parent->ss.ss_family == AF_INET6) {
+        tss->portable_family = SS_FAMILY_MIG_IPV6;
+    }
+
+    return 0;
+}
+
+static int ss_family_post_load(void *opaque, int version_id)
+{
+    SS_FamilyTmpStruct *tss = opaque;
+
+    switch (tss->portable_family) {
+    case SS_FAMILY_MIG_IPV4:
+        tss->parent->ss.ss_family = AF_INET;
+        break;
+    case SS_FAMILY_MIG_IPV6:
+    case 23: /* compatibility: AF_INET6 from mingw */
+    case 28: /* compatibility: AF_INET6 from FreeBSD sys/socket.h */
+        tss->parent->ss.ss_family = AF_INET6;
+        break;
+    default:
+        g_critical("invalid ss_family type %x", tss->portable_family);
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+static const VMStateDescription vmstate_slirp_ss_family = {
+    .name = "slirp-socket-addr/ss_family",
+    .pre_save  = ss_family_pre_save,
+    .post_load = ss_family_post_load,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT16(portable_family, SS_FamilyTmpStruct),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static const VMStateDescription vmstate_slirp_socket_addr = {
+    .name = "slirp-socket-addr",
+    .version_id = 4,
+    .fields = (VMStateField[]) {
+        VMSTATE_WITH_TMP(union slirp_sockaddr, SS_FamilyTmpStruct,
+                            vmstate_slirp_ss_family),
+        VMSTATE_SIN4_ADDR(sin.sin_addr.s_addr, union slirp_sockaddr,
+                            slirp_family_inet),
+        VMSTATE_UINT16_TEST(sin.sin_port, union slirp_sockaddr,
+                            slirp_family_inet),
+
+#if 0
+        /* Untested: Needs checking by someone with IPv6 test */
+        VMSTATE_BUFFER_TEST(sin6.sin6_addr, union slirp_sockaddr,
+                            slirp_family_inet6),
+        VMSTATE_UINT16_TEST(sin6.sin6_port, union slirp_sockaddr,
+                            slirp_family_inet6),
+        VMSTATE_UINT32_TEST(sin6.sin6_flowinfo, union slirp_sockaddr,
+                            slirp_family_inet6),
+        VMSTATE_UINT32_TEST(sin6.sin6_scope_id, union slirp_sockaddr,
+                            slirp_family_inet6),
+#endif
+
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static const VMStateDescription vmstate_slirp_socket = {
+    .name = "slirp-socket",
+    .version_id = 4,
+    .pre_load = slirp_socket_pre_load,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32(so_urgc, struct socket),
+        /* Pre-v4 versions */
+        VMSTATE_SIN4_ADDR(so_faddr.s_addr, struct socket,
+                            slirp_older_than_v4),
+        VMSTATE_SIN4_ADDR(so_laddr.s_addr, struct socket,
+                            slirp_older_than_v4),
+        VMSTATE_UINT16_TEST(so_fport, struct socket, slirp_older_than_v4),
+        VMSTATE_UINT16_TEST(so_lport, struct socket, slirp_older_than_v4),
+        /* v4 and newer */
+        VMSTATE_STRUCT(fhost, struct socket, 4, vmstate_slirp_socket_addr,
+                       union slirp_sockaddr),
+        VMSTATE_STRUCT(lhost, struct socket, 4, vmstate_slirp_socket_addr,
+                       union slirp_sockaddr),
+
+        VMSTATE_UINT8(so_iptos, struct socket),
+        VMSTATE_UINT8(so_emu, struct socket),
+        VMSTATE_UINT8(so_type, struct socket),
+        VMSTATE_INT32(so_state, struct socket),
+        VMSTATE_STRUCT(so_rcv, struct socket, 0, vmstate_slirp_sbuf,
+                       struct sbuf),
+        VMSTATE_STRUCT(so_snd, struct socket, 0, vmstate_slirp_sbuf,
+                       struct sbuf),
+        VMSTATE_STRUCT_POINTER(so_tcpcb, struct socket, vmstate_slirp_tcp,
+                       struct tcpcb),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static const VMStateDescription vmstate_slirp_bootp_client = {
+    .name = "slirp_bootpclient",
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT16(allocated, BOOTPClient),
+        VMSTATE_BUFFER(macaddr, BOOTPClient),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static const VMStateDescription vmstate_slirp = {
+    .name = "slirp",
+    .version_id = 4,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT16_V(ip_id, Slirp, 2),
+        VMSTATE_STRUCT_ARRAY(bootp_clients, Slirp, NB_BOOTP_CLIENTS, 3,
+                             vmstate_slirp_bootp_client, BOOTPClient),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static void slirp_state_save(QEMUFile *f, void *opaque)
+{
+    Slirp *slirp = opaque;
+    struct ex_list *ex_ptr;
+
+    for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next)
+        if (ex_ptr->ex_chardev) {
+            struct socket *so;
+            so = slirp_find_ctl_socket(slirp, ex_ptr->ex_addr,
+                                       ntohs(ex_ptr->ex_fport));
+            if (!so) {
+                continue;
+            }
+
+            qemu_put_byte(f, 42);
+            vmstate_save_state(f, &vmstate_slirp_socket, so, NULL);
+        }
+    qemu_put_byte(f, 0);
+
+    vmstate_save_state(f, &vmstate_slirp, slirp, NULL);
+}
+
+
+static int slirp_state_load(QEMUFile *f, void *opaque, int version_id)
+{
+    Slirp *slirp = opaque;
+    struct ex_list *ex_ptr;
+
+    while (qemu_get_byte(f)) {
+        int ret;
+        struct socket *so = socreate(slirp);
+
+        ret = vmstate_load_state(f, &vmstate_slirp_socket, so, version_id);
+        if (ret < 0) {
+            return ret;
+        }
+
+        if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) !=
+            slirp->vnetwork_addr.s_addr) {
+            return -EINVAL;
+        }
+        for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {
+            if (ex_ptr->ex_chardev &&
+                so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr &&
+                so->so_fport == ex_ptr->ex_fport) {
+                break;
+            }
+        }
+        if (!ex_ptr) {
+            return -EINVAL;
+        }
+    }
+
+    return vmstate_load_state(f, &vmstate_slirp, slirp, version_id);
+}
+
+void slirp_state_register(Slirp *slirp)
+{
+    static SaveVMHandlers savevm_slirp_state = {
+        .save_state = slirp_state_save,
+        .load_state = slirp_state_load,
+    };
+
+    register_savevm_live(NULL, "slirp", 0, 4, &savevm_slirp_state, slirp);
+}
+
+void slirp_state_unregister(Slirp *slirp)
+{
+    unregister_savevm(NULL, "slirp", slirp);
+}
diff --git a/slirp/Makefile.objs b/slirp/Makefile.objs
index 28049b03cd..98a82d2615 100644
--- a/slirp/Makefile.objs
+++ b/slirp/Makefile.objs
@@ -2,4 +2,6 @@ common-obj-y = cksum.o if.o ip_icmp.o ip6_icmp.o ip6_input.o ip6_output.o \
                ip_input.o ip_output.o dnssearch.o dhcpv6.o
 common-obj-y += slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o
 common-obj-y += tcp_subr.o tcp_timer.o udp.o udp6.o bootp.o tftp.o arp_table.o \
-                ndp_table.o ncsi.o
+                ndp_table.o ncsi.o state.o
+
+slirp.o-cflags := -DWITH_STATE=1
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 40/41] slirp: replace remaining QEMU dependency
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (38 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 39/41] slirp: move QEMU state saving to a separate unit Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 41/41] build-sys: add a basic meson build Marc-André Lureau
                   ` (3 subsequent siblings)
  43 siblings, 0 replies; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

Introduce utility header/object, and replace remaining qemu functions
with SLIRP helpers.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/ip.h          |  14 +--
 slirp/ip6.h         |   5 +-
 slirp/ip6_icmp.h    |  16 ++--
 slirp/libslirp.h    |  12 ++-
 slirp/qtailq.h      | 218 ++++++++++++++++++++++++++++++++++++++++++++
 slirp/slirp.h       |  12 +--
 slirp/util.h        | 145 +++++++++++++++++++++++++++++
 slirp/arp_table.c   |   1 -
 slirp/bootp.c       |   1 -
 slirp/cksum.c       |   1 -
 slirp/dhcpv6.c      |   2 -
 slirp/dnssearch.c   |   1 -
 slirp/if.c          |   2 -
 slirp/ip6_icmp.c    |   4 -
 slirp/ip6_input.c   |   1 -
 slirp/ip6_output.c  |   2 -
 slirp/ip_icmp.c     |   7 +-
 slirp/ip_input.c    |   1 -
 slirp/ip_output.c   |   1 -
 slirp/mbuf.c        |   1 -
 slirp/misc.c        |  21 ++---
 slirp/ncsi.c        |   1 -
 slirp/ndp_table.c   |   2 -
 slirp/sbuf.c        |   2 -
 slirp/slirp.c       |   8 --
 slirp/socket.c      |  18 ++--
 slirp/tcp_input.c   |   1 -
 slirp/tcp_output.c  |   1 -
 slirp/tcp_subr.c    |  13 ++-
 slirp/tcp_timer.c   |   1 -
 slirp/tftp.c        |   7 +-
 slirp/udp.c         |   7 +-
 slirp/udp6.c        |   2 -
 slirp/util.c        | 176 +++++++++++++++++++++++++++++++++++
 slirp/Makefile.objs |   2 +-
 35 files changed, 606 insertions(+), 103 deletions(-)
 create mode 100644 slirp/qtailq.h
 create mode 100644 slirp/util.h
 create mode 100644 slirp/util.c

diff --git a/slirp/ip.h b/slirp/ip.h
index 243b6c8b24..cd6ddf2bb7 100644
--- a/slirp/ip.h
+++ b/slirp/ip.h
@@ -89,7 +89,7 @@ struct ip {
 	uint8_t ip_p;			/* protocol */
 	uint16_t	ip_sum;			/* checksum */
 	struct	in_addr ip_src,ip_dst;	/* source and dest address */
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 #define	IP_MAXPACKET	65535		/* maximum packet size */
 
@@ -151,7 +151,7 @@ struct	ip_timestamp {
 			n_long ipt_time;
 		} ipt_ta[1];
 	} ipt_timestamp;
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 /* flag bits for ipt_flg */
 #define	IPOPT_TS_TSONLY		0		/* timestamps only */
@@ -181,11 +181,11 @@ struct	ip_timestamp {
 struct mbuf_ptr {
 	struct mbuf *mptr;
 	uint32_t dummy;
-} QEMU_PACKED;
+} SLIRP_PACKED;
 #else
 struct mbuf_ptr {
 	struct mbuf *mptr;
-} QEMU_PACKED;
+} SLIRP_PACKED;
 #endif
 struct qlink {
 	void *next, *prev;
@@ -201,7 +201,7 @@ struct ipovly {
 	uint16_t	ih_len;			/* protocol length */
 	struct	in_addr ih_src;		/* source internet address */
 	struct	in_addr ih_dst;		/* destination internet address */
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 /*
  * Ip reassembly queue structure.  Each fragment
@@ -217,7 +217,7 @@ struct ipq {
 	uint8_t	ipq_p;			/* protocol of this fragment */
 	uint16_t	ipq_id;			/* sequence id for reassembly */
 	struct	in_addr ipq_src,ipq_dst;
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 /*
  * Ip header, when holding a fragment.
@@ -227,7 +227,7 @@ struct ipq {
 struct	ipasfrag {
 	struct qlink ipf_link;
 	struct ip ipf_ip;
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 #define ipf_off      ipf_ip.ip_off
 #define ipf_tos      ipf_ip.ip_tos
diff --git a/slirp/ip6.h b/slirp/ip6.h
index 14e9c78735..e0a13dec1c 100644
--- a/slirp/ip6.h
+++ b/slirp/ip6.h
@@ -7,7 +7,6 @@
 #define SLIRP_IP6_H
 
 #include <glib.h>
-#include "net/eth.h"
 
 #define ALLNODES_MULTICAST  { .s6_addr = \
                             { 0xff, 0x02, 0x00, 0x00,\
@@ -133,7 +132,7 @@ struct ip6 {
     uint8_t     ip_nh;               /* next header */
     uint8_t     ip_hl;               /* hop limit */
     struct in6_addr ip_src, ip_dst;  /* source and dest address */
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 /*
  * IPv6 pseudo-header used by upper-layer protocols
@@ -145,7 +144,7 @@ struct ip6_pseudohdr {
     uint16_t    ih_zero_hi;       /* zero */
     uint8_t     ih_zero_lo;       /* zero */
     uint8_t     ih_nh;            /* next header */
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 
 #endif
diff --git a/slirp/ip6_icmp.h b/slirp/ip6_icmp.h
index 32b0914055..1f09b485e3 100644
--- a/slirp/ip6_icmp.h
+++ b/slirp/ip6_icmp.h
@@ -48,12 +48,12 @@ struct ndp_ra {     /* Router Advertisement Message */
     uint16_t lifetime;      /* Router Lifetime */
     uint32_t reach_time;    /* Reachable Time */
     uint32_t retrans_time;  /* Retrans Timer */
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 struct ndp_ns {     /* Neighbor Solicitation Message */
     uint32_t reserved;
     struct in6_addr target; /* Target Address */
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 struct ndp_na {     /* Neighbor Advertisement Message */
 #if G_BYTE_ORDER == G_BIG_ENDIAN
@@ -72,13 +72,13 @@ struct ndp_na {     /* Neighbor Advertisement Message */
         reserved_lo:24;
 #endif
     struct in6_addr target; /* Target Address */
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 struct ndp_redirect {
     uint32_t reserved;
     struct in6_addr target; /* Target Address */
     struct in6_addr dest;   /* Destination Address */
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 /*
  * Structure of an icmpv6 header.
@@ -103,7 +103,7 @@ struct icmp6 {
 #define icmp6_nns icmp6_body.ndp_ns
 #define icmp6_nna icmp6_body.ndp_na
 #define icmp6_redirect icmp6_body.ndp_redirect
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 #define ICMP6_MINLEN    4
 #define ICMP6_ERROR_MINLEN  8
@@ -134,16 +134,16 @@ struct ndpopt {
             uint32_t    pref_lt;                /* Preferred Lifetime */
             uint32_t    reserved2;
             struct in6_addr prefix;
-        } QEMU_PACKED prefixinfo;
+        } SLIRP_PACKED prefixinfo;
 #define ndpopt_prefixinfo ndpopt_body.prefixinfo
         struct rdnss {
             uint16_t reserved;
             uint32_t lifetime;
             struct in6_addr addr;
-        } QEMU_PACKED rdnss;
+        } SLIRP_PACKED rdnss;
 #define ndpopt_rdnss ndpopt_body.rdnss
     } ndpopt_body;
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 /* NDP options type */
 #define NDPOPT_LINKLAYER_SOURCE     1   /* Source Link-Layer Address */
diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 7d04404340..419f7a7712 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -1,7 +1,17 @@
 #ifndef LIBSLIRP_H
 #define LIBSLIRP_H
 
-#include "qemu-common.h"
+#include <glib.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#ifdef _WIN32
+#include <winsock2.h>
+#include <in6addr.h>
+#else
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#endif
 
 typedef struct Slirp Slirp;
 
diff --git a/slirp/qtailq.h b/slirp/qtailq.h
new file mode 100644
index 0000000000..7c1d73a5bd
--- /dev/null
+++ b/slirp/qtailq.h
@@ -0,0 +1,218 @@
+/*      $NetBSD: queue.h,v 1.52 2009/04/20 09:56:08 mschuett Exp $ */
+
+/*
+ * slirp version: Copy from QEMU, removed all but tail queues.
+ */
+
+/*
+ * Copyright (c) 1991, 1993
+ *      The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *      @(#)queue.h     8.5 (Berkeley) 8/20/94
+ */
+
+#ifndef QTAILQ_H
+#define QTAILQ_H
+
+/*
+ * A tail queue is headed by a pair of pointers, one to the head of the
+ * list and the other to the tail of the list. The elements are doubly
+ * linked so that an arbitrary element can be removed without a need to
+ * traverse the list. New elements can be added to the list before or
+ * after an existing element, at the head of the list, or at the end of
+ * the list. A tail queue may be traversed in either direction.
+ */
+
+#define Q_TAILQ_HEAD(name, type, qual)                                         \
+    struct name {                                                              \
+        qual type *tqh_first;      /* first element */                         \
+        qual type *qual *tqh_last; /* addr of last next element */             \
+    }
+#define QTAILQ_HEAD(name, type) Q_TAILQ_HEAD(name, struct type, )
+
+#define QTAILQ_HEAD_INITIALIZER(head)                                          \
+    {                                                                          \
+        NULL, &(head).tqh_first                                                \
+    }
+
+#define Q_TAILQ_ENTRY(type, qual)                                              \
+    struct {                                                                   \
+        qual type *tqe_next;       /* next element */                          \
+        qual type *qual *tqe_prev; /* address of previous next element */      \
+    }
+#define QTAILQ_ENTRY(type) Q_TAILQ_ENTRY(struct type, )
+
+/*
+ * Tail queue functions.
+ */
+#define QTAILQ_INIT(head)                                                      \
+    do {                                                                       \
+        (head)->tqh_first = NULL;                                              \
+        (head)->tqh_last = &(head)->tqh_first;                                 \
+    } while (/*CONSTCOND*/ 0)
+
+#define QTAILQ_INSERT_HEAD(head, elm, field)                                   \
+    do {                                                                       \
+        if (((elm)->field.tqe_next = (head)->tqh_first) != NULL)               \
+            (head)->tqh_first->field.tqe_prev = &(elm)->field.tqe_next;        \
+        else                                                                   \
+            (head)->tqh_last = &(elm)->field.tqe_next;                         \
+        (head)->tqh_first = (elm);                                             \
+        (elm)->field.tqe_prev = &(head)->tqh_first;                            \
+    } while (/*CONSTCOND*/ 0)
+
+#define QTAILQ_INSERT_TAIL(head, elm, field)                                   \
+    do {                                                                       \
+        (elm)->field.tqe_next = NULL;                                          \
+        (elm)->field.tqe_prev = (head)->tqh_last;                              \
+        *(head)->tqh_last = (elm);                                             \
+        (head)->tqh_last = &(elm)->field.tqe_next;                             \
+    } while (/*CONSTCOND*/ 0)
+
+#define QTAILQ_INSERT_AFTER(head, listelm, elm, field)                         \
+    do {                                                                       \
+        if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)       \
+            (elm)->field.tqe_next->field.tqe_prev = &(elm)->field.tqe_next;    \
+        else                                                                   \
+            (head)->tqh_last = &(elm)->field.tqe_next;                         \
+        (listelm)->field.tqe_next = (elm);                                     \
+        (elm)->field.tqe_prev = &(listelm)->field.tqe_next;                    \
+    } while (/*CONSTCOND*/ 0)
+
+#define QTAILQ_INSERT_BEFORE(listelm, elm, field)                              \
+    do {                                                                       \
+        (elm)->field.tqe_prev = (listelm)->field.tqe_prev;                     \
+        (elm)->field.tqe_next = (listelm);                                     \
+        *(listelm)->field.tqe_prev = (elm);                                    \
+        (listelm)->field.tqe_prev = &(elm)->field.tqe_next;                    \
+    } while (/*CONSTCOND*/ 0)
+
+#define QTAILQ_REMOVE(head, elm, field)                                        \
+    do {                                                                       \
+        if (((elm)->field.tqe_next) != NULL)                                   \
+            (elm)->field.tqe_next->field.tqe_prev = (elm)->field.tqe_prev;     \
+        else                                                                   \
+            (head)->tqh_last = (elm)->field.tqe_prev;                          \
+        *(elm)->field.tqe_prev = (elm)->field.tqe_next;                        \
+        (elm)->field.tqe_prev = NULL;                                          \
+    } while (/*CONSTCOND*/ 0)
+
+#define QTAILQ_FOREACH(var, head, field)                                       \
+    for ((var) = ((head)->tqh_first); (var); (var) = ((var)->field.tqe_next))
+
+#define QTAILQ_FOREACH_SAFE(var, head, field, next_var)                        \
+    for ((var) = ((head)->tqh_first);                                          \
+         (var) && ((next_var) = ((var)->field.tqe_next), 1);                   \
+         (var) = (next_var))
+
+#define QTAILQ_FOREACH_REVERSE(var, head, headname, field)                     \
+    for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last));       \
+         (var);                                                                \
+         (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
+
+#define QTAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, prev_var)      \
+    for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last));       \
+         (var) &&                                                              \
+         ((prev_var) =                                                         \
+              (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)),     \
+         1);                                                                   \
+         (var) = (prev_var))
+
+/*
+ * Tail queue access methods.
+ */
+#define QTAILQ_EMPTY(head) ((head)->tqh_first == NULL)
+#define QTAILQ_FIRST(head) ((head)->tqh_first)
+#define QTAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
+#define QTAILQ_IN_USE(elm, field) ((elm)->field.tqe_prev != NULL)
+
+#define QTAILQ_LAST(head, headname)                                            \
+    (*(((struct headname *)((head)->tqh_last))->tqh_last))
+#define QTAILQ_PREV(elm, headname, field)                                      \
+    (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
+
+#define field_at_offset(base, offset, type)                                    \
+    ((type)(((char *)(base)) + (offset)))
+
+typedef struct DUMMY_Q_ENTRY DUMMY_Q_ENTRY;
+typedef struct DUMMY_Q DUMMY_Q;
+
+struct DUMMY_Q_ENTRY {
+    QTAILQ_ENTRY(DUMMY_Q_ENTRY) next;
+};
+
+struct DUMMY_Q {
+    QTAILQ_HEAD(DUMMY_Q_HEAD, DUMMY_Q_ENTRY) head;
+};
+
+#define dummy_q ((DUMMY_Q *)0)
+#define dummy_qe ((DUMMY_Q_ENTRY *)0)
+
+/*
+ * Offsets of layout of a tail queue head.
+ */
+#define QTAILQ_FIRST_OFFSET (offsetof(typeof(dummy_q->head), tqh_first))
+#define QTAILQ_LAST_OFFSET (offsetof(typeof(dummy_q->head), tqh_last))
+/*
+ * Raw access of elements of a tail queue
+ */
+#define QTAILQ_RAW_FIRST(head)                                                 \
+    (*field_at_offset(head, QTAILQ_FIRST_OFFSET, void **))
+#define QTAILQ_RAW_TQH_LAST(head)                                              \
+    (*field_at_offset(head, QTAILQ_LAST_OFFSET, void ***))
+
+/*
+ * Offsets of layout of a tail queue element.
+ */
+#define QTAILQ_NEXT_OFFSET (offsetof(typeof(dummy_qe->next), tqe_next))
+#define QTAILQ_PREV_OFFSET (offsetof(typeof(dummy_qe->next), tqe_prev))
+
+/*
+ * Raw access of elements of a tail entry
+ */
+#define QTAILQ_RAW_NEXT(elm, entry)                                            \
+    (*field_at_offset(elm, entry + QTAILQ_NEXT_OFFSET, void **))
+#define QTAILQ_RAW_TQE_PREV(elm, entry)                                        \
+    (*field_at_offset(elm, entry + QTAILQ_PREV_OFFSET, void ***))
+/*
+ * Tail queue tranversal using pointer arithmetic.
+ */
+#define QTAILQ_RAW_FOREACH(elm, head, entry)                                   \
+    for ((elm) = QTAILQ_RAW_FIRST(head); (elm);                                \
+         (elm) = QTAILQ_RAW_NEXT(elm, entry))
+/*
+ * Tail queue insertion using pointer arithmetic.
+ */
+#define QTAILQ_RAW_INSERT_TAIL(head, elm, entry)                               \
+    do {                                                                       \
+        QTAILQ_RAW_NEXT(elm, entry) = NULL;                                    \
+        QTAILQ_RAW_TQE_PREV(elm, entry) = QTAILQ_RAW_TQH_LAST(head);           \
+        *QTAILQ_RAW_TQH_LAST(head) = (elm);                                    \
+        QTAILQ_RAW_TQH_LAST(head) = &QTAILQ_RAW_NEXT(elm, entry);              \
+    } while (/*CONSTCOND*/ 0)
+
+#endif /* QTAILQ_H */
diff --git a/slirp/slirp.h b/slirp/slirp.h
index e5cd0cd334..f82d295834 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -5,8 +5,8 @@
 
 typedef char *caddr_t;
 
-# include <windows.h>
 # include <winsock2.h>
+# include <windows.h>
 # include <ws2tcpip.h>
 # include <sys/timeb.h>
 # include <iphlpapi.h>
@@ -45,10 +45,8 @@ typedef char *caddr_t;
 #define quehead slirp_quehead
 
 #include "debug.h"
-
-#include "qemu/queue.h"
-#include "qemu/sockets.h"
-#include "net/eth.h"
+#include "util.h"
+#include "qtailq.h"
 
 #include "libslirp.h"
 #include "ip.h"
@@ -93,7 +91,7 @@ struct slirp_arphdr {
     uint32_t      ar_sip;           /* sender IP address       */
     unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
     uint32_t      ar_tip;           /* target IP address       */
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 #define ARP_TABLE_SIZE 16
 
@@ -110,7 +108,7 @@ bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
 struct ndpentry {
     unsigned char   eth_addr[ETH_ALEN];     /* sender hardware address */
     struct in6_addr ip_addr;                /* sender IP address       */
-} QEMU_PACKED;
+} SLIRP_PACKED;
 
 #define NDP_TABLE_SIZE 16
 
diff --git a/slirp/util.h b/slirp/util.h
new file mode 100644
index 0000000000..d8f52c87b0
--- /dev/null
+++ b/slirp/util.h
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010-2016 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef UTIL_H_
+#define UTIL_H_
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#ifdef _WIN32
+#include <winsock2.h>
+#include <windows.h>
+#else
+#include <sys/socket.h>
+#include <netinet/tcp.h>
+#include <netinet/in.h>
+#endif
+
+#if defined(_WIN32)
+# define SLIRP_PACKED __attribute__((gcc_struct, packed))
+#else
+# define SLIRP_PACKED __attribute__((packed))
+#endif
+
+#ifndef DIV_ROUND_UP
+#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+#endif
+
+#define SCALE_MS 1000000
+
+#ifndef container_of
+#define container_of(ptr, type, member) (__extension__({                \
+                const typeof(((type *) 0)->member) *__mptr = (ptr);     \
+                (type *) ((char *) __mptr - offsetof(type, member));}))
+#endif
+
+#ifndef glue
+#define xglue(x, y) x ## y
+#define glue(x, y) xglue(x, y)
+#define stringify(s) tostring(s)
+#define tostring(s) #s
+#endif
+
+#if defined(_WIN32) /* CONFIG_IOVEC */
+struct iovec {
+    void *iov_base;
+    size_t iov_len;
+};
+#else
+#include <sys/uio.h>
+#endif
+
+#define ETH_ALEN    6
+#define ETH_HLEN    6
+#define ETH_P_IP                  (0x0800)      /* Internet Protocol packet  */
+#define ETH_P_ARP                 (0x0806)      /* Address Resolution packet */
+#define ETH_P_IPV6                (0x86dd)
+#define ETH_P_VLAN                (0x8100)
+#define ETH_P_DVLAN               (0x88a8)
+#define ETH_P_NCSI                (0x88f8)
+#define ETH_P_UNKNOWN             (0xffff)
+
+#ifdef _WIN32
+int slirp_closesocket(int fd);
+int slirp_ioctlsocket(int fd, int req, void *val);
+int inet_aton(const char *cp, struct in_addr *ia);
+#define slirp_getsockopt(sockfd, level, optname, optval, optlen) \
+    getsockopt(sockfd, level, optname, (void *)optval, optlen)
+#define slirp_setsockopt(sockfd, level, optname, optval, optlen)        \
+    setsockopt(sockfd, level, optname, (const void *)optval, optlen)
+#define slirp_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags)
+#else
+#define slirp_setsockopt setsockopt
+#define slirp_getsockopt getsockopt
+#define slirp_recv recv
+#define slirp_closesocket close
+#define slirp_ioctlsocket ioctl
+#endif
+
+int slirp_socket(int domain, int type, int protocol);
+
+static inline int socket_set_nodelay(int fd)
+{
+    int v = 1;
+    return slirp_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v));
+}
+
+static inline int socket_set_fast_reuse(int fd)
+{
+#ifndef _WIN32
+    int v = 1;
+    return slirp_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v));
+#else
+    /* Enabling the reuse of an endpoint that was used by a socket still in
+     * TIME_WAIT state is usually performed by setting SO_REUSEADDR. On Windows
+     * fast reuse is the default and SO_REUSEADDR does strange things. So we
+     * don't have to do anything here. More info can be found at:
+     * http://msdn.microsoft.com/en-us/library/windows/desktop/ms740621.aspx */
+    return 0;
+#endif
+}
+
+static inline void pstrcpy(char *buf, int buf_size, const char *str)
+{
+    int c;
+    char *q = buf;
+
+    if (buf_size <= 0)
+        return;
+
+    for(;;) {
+        c = *str++;
+        if (c == 0 || q >= buf + buf_size - 1)
+            break;
+        *q++ = c;
+    }
+    *q = '\0';
+}
+
+#endif
diff --git a/slirp/arp_table.c b/slirp/arp_table.c
index ce19e6e7c0..d657b559d1 100644
--- a/slirp/arp_table.c
+++ b/slirp/arp_table.c
@@ -22,7 +22,6 @@
  * THE SOFTWARE.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 
 void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN])
diff --git a/slirp/bootp.c b/slirp/bootp.c
index 5ab6692038..083dd58984 100644
--- a/slirp/bootp.c
+++ b/slirp/bootp.c
@@ -21,7 +21,6 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include "qemu/osdep.h"
 #include "slirp.h"
 
 #if defined(_WIN32)
diff --git a/slirp/cksum.c b/slirp/cksum.c
index b9466485b5..2cd3589297 100644
--- a/slirp/cksum.c
+++ b/slirp/cksum.c
@@ -30,7 +30,6 @@
  * in_cksum.c,v 1.2 1994/08/02 07:48:16 davidg Exp
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 
 /*
diff --git a/slirp/dhcpv6.c b/slirp/dhcpv6.c
index 5d703e8ae6..01b5916b1e 100644
--- a/slirp/dhcpv6.c
+++ b/slirp/dhcpv6.c
@@ -20,8 +20,6 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "qemu/osdep.h"
-#include "qemu/log.h"
 #include "slirp.h"
 #include "dhcpv6.h"
 
diff --git a/slirp/dnssearch.c b/slirp/dnssearch.c
index 8fb563321b..c459cece8d 100644
--- a/slirp/dnssearch.c
+++ b/slirp/dnssearch.c
@@ -22,7 +22,6 @@
  * THE SOFTWARE.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 
 static const uint8_t RFC3397_OPT_DOMAIN_SEARCH = 119;
diff --git a/slirp/if.c b/slirp/if.c
index 1a9122a732..ec29a926f0 100644
--- a/slirp/if.c
+++ b/slirp/if.c
@@ -5,9 +5,7 @@
  * terms and conditions of the copyright.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
-#include "qemu/timer.h"
 
 static void
 ifs_insque(struct mbuf *ifm, struct mbuf *ifmhead)
diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
index d523852a1f..328926f328 100644
--- a/slirp/ip6_icmp.c
+++ b/slirp/ip6_icmp.c
@@ -3,12 +3,8 @@
  * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 #include "ip6_icmp.h"
-#include "qemu/timer.h"
-#include "qemu/error-report.h"
-#include "qemu/log.h"
 
 #define NDP_Interval g_rand_int_range(slirp->grand, \
         NDP_MinRtrAdvInterval, NDP_MaxRtrAdvInterval)
diff --git a/slirp/ip6_input.c b/slirp/ip6_input.c
index ac2e3ea882..4aa9f2eadc 100644
--- a/slirp/ip6_input.c
+++ b/slirp/ip6_input.c
@@ -3,7 +3,6 @@
  * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 #include "ip6_icmp.h"
 
diff --git a/slirp/ip6_output.c b/slirp/ip6_output.c
index 762cbfe89c..2dd80f4649 100644
--- a/slirp/ip6_output.c
+++ b/slirp/ip6_output.c
@@ -3,8 +3,6 @@
  * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne.
  */
 
-#include "qemu/osdep.h"
-#include "qemu-common.h"
 #include "slirp.h"
 
 /* Number of packets queued before we start sending
diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c
index af11cfcefe..41cdf665ce 100644
--- a/slirp/ip_icmp.c
+++ b/slirp/ip_icmp.c
@@ -30,7 +30,6 @@
  * ip_icmp.c,v 1.7 1995/05/30 08:09:42 rgrimes Exp
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 #include "ip_icmp.h"
 
@@ -79,7 +78,7 @@ static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
     struct ip *ip = mtod(m, struct ip *);
     struct sockaddr_in addr;
 
-    so->s = qemu_socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
+    so->s = slirp_socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
     if (so->s == -1) {
         return -1;
     }
@@ -110,7 +109,7 @@ static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
 
 void icmp_detach(struct socket *so)
 {
-    closesocket(so->s);
+    slirp_closesocket(so->s);
     sofree(so);
 }
 
@@ -420,7 +419,7 @@ void icmp_receive(struct socket *so)
     icp = mtod(m, struct icmp *);
 
     id = icp->icmp_id;
-    len = qemu_recv(so->s, icp, M_ROOM(m), 0);
+    len = slirp_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
diff --git a/slirp/ip_input.c b/slirp/ip_input.c
index 6831526320..cfda30fccd 100644
--- a/slirp/ip_input.c
+++ b/slirp/ip_input.c
@@ -38,7 +38,6 @@
  * terms and conditions of the copyright.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 #include "ip_icmp.h"
 
diff --git a/slirp/ip_output.c b/slirp/ip_output.c
index db403f04c1..f6ec141df5 100644
--- a/slirp/ip_output.c
+++ b/slirp/ip_output.c
@@ -38,7 +38,6 @@
  * terms and conditions of the copyright.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 
 /* Number of packets queued before we start sending
diff --git a/slirp/mbuf.c b/slirp/mbuf.c
index d8d275e0e7..521c02c967 100644
--- a/slirp/mbuf.c
+++ b/slirp/mbuf.c
@@ -15,7 +15,6 @@
  * the flags
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 
 #define MBUF_THRESH 30
diff --git a/slirp/misc.c b/slirp/misc.c
index 17361b79a4..80a94194dd 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -5,11 +5,8 @@
  * terms and conditions of the copyright.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 #include "libslirp.h"
-#include "qemu/error-report.h"
-#include "qemu/main-loop.h"
 
 #ifdef DEBUG
 int slirp_debug = DBG_CALL|DBG_MISC|DBG_ERROR;
@@ -85,14 +82,14 @@ slirp_socketpair_with_oob(int sv[2])
     int ret, s;
 
     sv[1] = -1;
-    s = qemu_socket(AF_INET, SOCK_STREAM, 0);
+    s = slirp_socket(AF_INET, SOCK_STREAM, 0);
     if (s < 0 || bind(s, (struct sockaddr *)&addr, addrlen) < 0 ||
         listen(s, 1) < 0 ||
         getsockname(s, (struct sockaddr *)&addr, &addrlen) < 0) {
         goto err;
     }
 
-    sv[1] = qemu_socket(AF_INET, SOCK_STREAM, 0);
+    sv[1] = slirp_socket(AF_INET, SOCK_STREAM, 0);
     if (sv[1] < 0) {
         goto err;
     }
@@ -115,16 +112,16 @@ slirp_socketpair_with_oob(int sv[2])
         goto err;
     }
 
-    closesocket(s);
+    slirp_closesocket(s);
     return 0;
 
 err:
     g_critical("slirp_socketpair(): %s", strerror(errno));
     if (s >= 0) {
-        closesocket(s);
+        slirp_closesocket(s);
     }
     if (sv[1] >= 0) {
-        closesocket(sv[1]);
+        slirp_closesocket(sv[1]);
     }
     return -1;
 }
@@ -164,16 +161,16 @@ fork_exec(struct socket *so, const char *ex)
     if (err) {
         g_critical("fork_exec: %s", err->message);
         g_error_free(err);
-        closesocket(sp[0]);
-        closesocket(sp[1]);
+        slirp_closesocket(sp[0]);
+        slirp_closesocket(sp[1]);
         return 0;
     }
 
     so->s = sp[0];
-    closesocket(sp[1]);
+    slirp_closesocket(sp[1]);
     socket_set_fast_reuse(so->s);
     opt = 1;
-    qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
+    slirp_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
     so->slirp->cb->set_nonblock(so->s);
     return 1;
 }
diff --git a/slirp/ncsi.c b/slirp/ncsi.c
index 8594382270..327f17543c 100644
--- a/slirp/ncsi.c
+++ b/slirp/ncsi.c
@@ -6,7 +6,6 @@
  * This code is licensed under the GPL version 2 or later. See the
  * COPYING file in the top-level directory.
  */
-#include "qemu/osdep.h"
 #include "slirp.h"
 
 #include "ncsi-pkt.h"
diff --git a/slirp/ndp_table.c b/slirp/ndp_table.c
index a4e6421fd3..2dbc3805a5 100644
--- a/slirp/ndp_table.c
+++ b/slirp/ndp_table.c
@@ -3,8 +3,6 @@
  * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne.
  */
 
-#include "qemu/osdep.h"
-#include "qemu-common.h"
 #include "slirp.h"
 
 void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr,
diff --git a/slirp/sbuf.c b/slirp/sbuf.c
index 17f28e97a6..51a9f0cc7d 100644
--- a/slirp/sbuf.c
+++ b/slirp/sbuf.c
@@ -5,9 +5,7 @@
  * terms and conditions of the copyright.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
-#include "qemu/main-loop.h"
 
 static void sbappendsb(struct sbuf *sb, struct mbuf *m);
 
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 8b56f28d77..15386e5245 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -21,15 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include "qemu/osdep.h"
-#include "qemu-common.h"
-#include "qemu/timer.h"
-#include "qemu/error-report.h"
-#include "chardev/char-fe.h"
-#include "migration/register.h"
 #include "slirp.h"
-#include "hw/hw.h"
-#include "qemu/cutils.h"
 
 #ifdef WITH_STATE
 #include "state.h"
diff --git a/slirp/socket.c b/slirp/socket.c
index 2b1b5052c4..c3860ba067 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -5,8 +5,6 @@
  * terms and conditions of the copyright.
  */
 
-#include "qemu/osdep.h"
-#include "qemu-common.h"
 #include "slirp.h"
 #include "ip_icmp.h"
 #ifdef __sun__
@@ -187,7 +185,7 @@ soread(struct socket *so)
 	 */
 	sopreprbuf(so, iov, &n);
 
-	nn = qemu_recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
+	nn = slirp_recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
 	if (nn <= 0) {
 		if (nn < 0 && (errno == EINTR || errno == EAGAIN))
 			return 0;
@@ -203,7 +201,7 @@ soread(struct socket *so)
 				if (getpeername(so->s, paddr, &alen) < 0) {
 					err = errno;
 				} else {
-					getsockopt(so->s, SOL_SOCKET, SO_ERROR,
+					slirp_getsockopt(so->s, SOL_SOCKET, SO_ERROR,
 						&err, &elen);
 				}
 			}
@@ -232,7 +230,7 @@ soread(struct socket *so)
 	 */
 	if (n == 2 && nn == iov[0].iov_len) {
             int ret;
-            ret = qemu_recv(so->s, iov[1].iov_base, iov[1].iov_len,0);
+            ret = slirp_recv(so->s, iov[1].iov_base, iov[1].iov_len,0);
             if (ret > 0)
                 nn += ret;
         }
@@ -553,7 +551,7 @@ sorecvfrom(struct socket *so)
 	   */
 	  len = M_FREEROOM(m);
 	  /* if (so->so_fport != htons(53)) { */
-	  ioctlsocket(so->s, FIONREAD, &n);
+	  slirp_ioctlsocket(so->s, FIONREAD, &n);
 
 	  if (n > len) {
 	    n = (m->m_data - m->m_dat) + m->m_len + n + 1;
@@ -718,14 +716,14 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
 	addr.sin_addr.s_addr = haddr;
 	addr.sin_port = hport;
 
-	if (((s = qemu_socket(AF_INET,SOCK_STREAM,0)) < 0) ||
+	if (((s = slirp_socket(AF_INET,SOCK_STREAM,0)) < 0) ||
 	    (socket_set_fast_reuse(s) < 0) ||
 	    (bind(s,(struct sockaddr *)&addr, sizeof(addr)) < 0) ||
 	    (listen(s,1) < 0)) {
 		int tmperrno = errno; /* Don't clobber the real reason we failed */
 
                 if (s >= 0) {
-                    closesocket(s);
+                    slirp_closesocket(s);
                 }
 		sofree(so);
 		/* Restore the real errno */
@@ -736,9 +734,9 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
 #endif
 		return NULL;
 	}
-	qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
+	slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
 	opt = 1;
-	qemu_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(int));
+	slirp_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(int));
 
 	getsockname(s,(struct sockaddr *)&addr,&addrlen);
 	so->so_ffamily = AF_INET;
diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c
index 0d34abf8d7..c9cbec205e 100644
--- a/slirp/tcp_input.c
+++ b/slirp/tcp_input.c
@@ -38,7 +38,6 @@
  * terms and conditions of the copyright.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 #include "ip_icmp.h"
 
diff --git a/slirp/tcp_output.c b/slirp/tcp_output.c
index 44da8a4e47..a1547c0b23 100644
--- a/slirp/tcp_output.c
+++ b/slirp/tcp_output.c
@@ -38,7 +38,6 @@
  * terms and conditions of the copyright.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 
 static const u_char  tcp_outflags[TCP_NSTATES] = {
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index 98bceea9f6..d8dd7d57a6 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -38,7 +38,6 @@
  * terms and conditions of the copyright.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 
 /* patchable/settable parameters for tcp */
@@ -337,7 +336,7 @@ tcp_close(struct tcpcb *tp)
 	/* clobber input socket cache if we're closing the cached connection */
 	if (so == slirp->tcp_last_so)
 		slirp->tcp_last_so = &slirp->tcb;
-	closesocket(so->s);
+	slirp_closesocket(so->s);
 	sbfree(&so->so_rcv);
 	sbfree(&so->so_snd);
 	sofree(so);
@@ -407,7 +406,7 @@ int tcp_fconnect(struct socket *so, unsigned short af)
   DEBUG_CALL("tcp_fconnect");
   DEBUG_ARG("so = %p", so);
 
-  ret = so->s = qemu_socket(af, SOCK_STREAM, 0);
+  ret = so->s = slirp_socket(af, SOCK_STREAM, 0);
   if (ret >= 0) {
     int opt, s=so->s;
     struct sockaddr_storage addr;
@@ -415,9 +414,9 @@ int tcp_fconnect(struct socket *so, unsigned short af)
     so->slirp->cb->set_nonblock(s);
     socket_set_fast_reuse(s);
     opt = 1;
-    qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
+    slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
     opt = 1;
-    qemu_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
+    slirp_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
 
     addr = so->fhost.ss;
     DEBUG_CALL(" connect()ing");
@@ -487,7 +486,7 @@ void tcp_connect(struct socket *inso)
     so->slirp->cb->set_nonblock(s);
     socket_set_fast_reuse(s);
     opt = 1;
-    qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
+    slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
     socket_set_nodelay(s);
 
     so->fhost.ss = addr;
@@ -496,7 +495,7 @@ void tcp_connect(struct socket *inso)
     /* Close the accept() socket, set right state */
     if (inso->so_state & SS_FACCEPTONCE) {
         /* If we only accept once, close the accept() socket */
-        closesocket(so->s);
+        slirp_closesocket(so->s);
 
         /* Don't select it yet, even though we have an FD */
         /* if it's not FACCEPTONCE, it's already NOFDREF */
diff --git a/slirp/tcp_timer.c b/slirp/tcp_timer.c
index d953a16386..ebc9d16f06 100644
--- a/slirp/tcp_timer.c
+++ b/slirp/tcp_timer.c
@@ -30,7 +30,6 @@
  * tcp_timer.c,v 1.2 1994/08/02 07:49:10 davidg Exp
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 
 static struct tcpcb *tcp_timers(register struct tcpcb *tp, int timer);
diff --git a/slirp/tftp.c b/slirp/tftp.c
index ef8d0352b4..a78d06d2a4 100644
--- a/slirp/tftp.c
+++ b/slirp/tftp.c
@@ -22,10 +22,11 @@
  * THE SOFTWARE.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
-#include "qemu-common.h"
-#include "qemu/cutils.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 static inline int tftp_session_in_use(struct tftp_session *spt)
 {
diff --git a/slirp/udp.c b/slirp/udp.c
index a45ad81dda..1de3775add 100644
--- a/slirp/udp.c
+++ b/slirp/udp.c
@@ -38,7 +38,6 @@
  * terms and conditions of the copyright.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 #include "ip_icmp.h"
 
@@ -282,7 +281,7 @@ int udp_output(struct socket *so, struct mbuf *m,
 int
 udp_attach(struct socket *so, unsigned short af)
 {
-  so->s = qemu_socket(af, SOCK_DGRAM, 0);
+  so->s = slirp_socket(af, SOCK_DGRAM, 0);
   if (so->s != -1) {
     so->so_expire = curtime + SO_EXPIRE;
     insque(so, &so->slirp->udb);
@@ -293,7 +292,7 @@ udp_attach(struct socket *so, unsigned short af)
 void
 udp_detach(struct socket *so)
 {
-	closesocket(so->s);
+	slirp_closesocket(so->s);
 	sofree(so);
 }
 
@@ -328,7 +327,7 @@ udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
 	socklen_t addrlen = sizeof(struct sockaddr_in);
 
 	so = socreate(slirp);
-	so->s = qemu_socket(AF_INET,SOCK_DGRAM,0);
+	so->s = slirp_socket(AF_INET,SOCK_DGRAM,0);
         if (so->s < 0) {
             sofree(so);
             return NULL;
diff --git a/slirp/udp6.c b/slirp/udp6.c
index 473ba1586e..d14329f05f 100644
--- a/slirp/udp6.c
+++ b/slirp/udp6.c
@@ -3,8 +3,6 @@
  * Guillaume Subiron
  */
 
-#include "qemu/osdep.h"
-#include "qemu-common.h"
 #include "slirp.h"
 #include "udp.h"
 #include "dhcpv6.h"
diff --git a/slirp/util.c b/slirp/util.c
new file mode 100644
index 0000000000..6fc6fea197
--- /dev/null
+++ b/slirp/util.c
@@ -0,0 +1,176 @@
+/*
+ * util.c (mostly based on QEMU os-win32.c)
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010-2016 Red Hat, Inc.
+ *
+ * QEMU library functions for win32 which are shared between QEMU and
+ * the QEMU tools.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "util.h"
+
+#include <glib.h>
+#include <fcntl.h>
+#include <stdint.h>
+
+#ifdef _WIN32
+int inet_aton(const char *cp, struct in_addr *ia)
+{
+    uint32_t addr = inet_addr(cp);
+    if (addr == 0xffffffff) {
+        return 0;
+    }
+    ia->s_addr = addr;
+    return 1;
+}
+#endif
+
+static void slirp_set_cloexec(int fd)
+{
+#ifndef _WIN32
+    int f;
+    f = fcntl(fd, F_GETFD);
+    assert(f != -1);
+    f = fcntl(fd, F_SETFD, f | FD_CLOEXEC);
+    assert(f != -1);
+#endif
+}
+
+/*
+ * Opens a socket with FD_CLOEXEC set
+ */
+int slirp_socket(int domain, int type, int protocol)
+{
+    int ret;
+
+#ifdef SOCK_CLOEXEC
+    ret = socket(domain, type | SOCK_CLOEXEC, protocol);
+    if (ret != -1 || errno != EINVAL) {
+        return ret;
+    }
+#endif
+    ret = socket(domain, type, protocol);
+    if (ret >= 0) {
+        slirp_set_cloexec(ret);
+    }
+
+    return ret;
+}
+
+#ifdef _WIN32
+static int socket_error(void)
+{
+    switch (WSAGetLastError()) {
+    case 0:
+        return 0;
+    case WSAEINTR:
+        return EINTR;
+    case WSAEINVAL:
+        return EINVAL;
+    case WSA_INVALID_HANDLE:
+        return EBADF;
+    case WSA_NOT_ENOUGH_MEMORY:
+        return ENOMEM;
+    case WSA_INVALID_PARAMETER:
+        return EINVAL;
+    case WSAENAMETOOLONG:
+        return ENAMETOOLONG;
+    case WSAENOTEMPTY:
+        return ENOTEMPTY;
+    case WSAEWOULDBLOCK:
+         /* not using EWOULDBLOCK as we don't want code to have
+          * to check both EWOULDBLOCK and EAGAIN */
+        return EAGAIN;
+    case WSAEINPROGRESS:
+        return EINPROGRESS;
+    case WSAEALREADY:
+        return EALREADY;
+    case WSAENOTSOCK:
+        return ENOTSOCK;
+    case WSAEDESTADDRREQ:
+        return EDESTADDRREQ;
+    case WSAEMSGSIZE:
+        return EMSGSIZE;
+    case WSAEPROTOTYPE:
+        return EPROTOTYPE;
+    case WSAENOPROTOOPT:
+        return ENOPROTOOPT;
+    case WSAEPROTONOSUPPORT:
+        return EPROTONOSUPPORT;
+    case WSAEOPNOTSUPP:
+        return EOPNOTSUPP;
+    case WSAEAFNOSUPPORT:
+        return EAFNOSUPPORT;
+    case WSAEADDRINUSE:
+        return EADDRINUSE;
+    case WSAEADDRNOTAVAIL:
+        return EADDRNOTAVAIL;
+    case WSAENETDOWN:
+        return ENETDOWN;
+    case WSAENETUNREACH:
+        return ENETUNREACH;
+    case WSAENETRESET:
+        return ENETRESET;
+    case WSAECONNABORTED:
+        return ECONNABORTED;
+    case WSAECONNRESET:
+        return ECONNRESET;
+    case WSAENOBUFS:
+        return ENOBUFS;
+    case WSAEISCONN:
+        return EISCONN;
+    case WSAENOTCONN:
+        return ENOTCONN;
+    case WSAETIMEDOUT:
+        return ETIMEDOUT;
+    case WSAECONNREFUSED:
+        return ECONNREFUSED;
+    case WSAELOOP:
+        return ELOOP;
+    case WSAEHOSTUNREACH:
+        return EHOSTUNREACH;
+    default:
+        return EIO;
+    }
+}
+
+#undef ioctlsocket
+int slirp_ioctlsocket(int fd, int req, void *val)
+{
+    int ret;
+    ret = ioctlsocket(fd, req, val);
+    if (ret < 0) {
+        errno = socket_error();
+    }
+    return ret;
+}
+
+#undef closesocket
+int slirp_closesocket(int fd)
+{
+    int ret;
+    ret = closesocket(fd);
+    if (ret < 0) {
+        errno = socket_error();
+    }
+    return ret;
+}
+#endif /* WIN32 */
diff --git a/slirp/Makefile.objs b/slirp/Makefile.objs
index 98a82d2615..446a33b879 100644
--- a/slirp/Makefile.objs
+++ b/slirp/Makefile.objs
@@ -2,6 +2,6 @@ common-obj-y = cksum.o if.o ip_icmp.o ip6_icmp.o ip6_input.o ip6_output.o \
                ip_input.o ip_output.o dnssearch.o dhcpv6.o
 common-obj-y += slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o
 common-obj-y += tcp_subr.o tcp_timer.o udp.o udp6.o bootp.o tftp.o arp_table.o \
-                ndp_table.o ncsi.o state.o
+                ndp_table.o ncsi.o state.o util.o
 
 slirp.o-cflags := -DWITH_STATE=1
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* [Qemu-devel] [PATCH for-3.2 41/41] build-sys: add a basic meson build
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (39 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 40/41] slirp: replace remaining QEMU dependency Marc-André Lureau
@ 2018-11-14 12:36 ` Marc-André Lureau
  2018-11-14 12:59 ` [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Markus Armbruster
                   ` (2 subsequent siblings)
  43 siblings, 0 replies; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 12:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo, Marc-André Lureau

This is a minimal file to build a libslirp shared library.

It has been tested to build on Linux and with mingw64 cross-compilation.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/meson.build | 48 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 slirp/meson.build

diff --git a/slirp/meson.build b/slirp/meson.build
new file mode 100644
index 0000000000..aa6f1b39e2
--- /dev/null
+++ b/slirp/meson.build
@@ -0,0 +1,48 @@
+project('slirp', 'c', version : '3.1')
+
+add_global_arguments('-std=gnu99', language : 'c')
+
+host_system = host_machine.system()
+
+glib_dep = dependency('glib-2.0')
+
+cc = meson.get_compiler('c')
+
+platform_deps = []
+
+if host_system == 'windows'
+  platform_deps += [
+    cc.find_library('ws2_32'),
+    cc.find_library('iphlpapi')
+  ]
+endif
+
+shared_library('slirp',
+               'arp_table.c',
+               'bootp.c',
+               'cksum.c',
+               'dhcpv6.c',
+               'dnssearch.c',
+               'if.c',
+               'ip6_icmp.c',
+               'ip6_input.c',
+               'ip6_output.c',
+               'ip_icmp.c',
+               'ip_input.c',
+               'ip_output.c',
+               'mbuf.c',
+               'misc.c',
+               'ncsi.c',
+               'ndp_table.c',
+               'sbuf.c',
+               'slirp.c',
+               'socket.c',
+               'tcp_input.c',
+               'tcp_output.c',
+               'tcp_subr.c',
+               'tcp_timer.c',
+               'tftp.c',
+               'udp.c',
+               'udp6.c',
+               'util.c',
+               dependencies : [glib_dep, platform_deps])
-- 
2.19.1.708.g4ede3d42df

^ permalink raw reply related	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (40 preceding siblings ...)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 41/41] build-sys: add a basic meson build Marc-André Lureau
@ 2018-11-14 12:59 ` Markus Armbruster
  2018-11-14 13:20   ` Richard W.M. Jones
  2018-11-14 13:33   ` Thomas Huth
  2018-11-14 13:45 ` Daniel P. Berrangé
  2018-11-14 14:26 ` Stefan Hajnoczi
  43 siblings, 2 replies; 137+ messages in thread
From: Markus Armbruster @ 2018-11-14 12:59 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> Hi,
>
> Based-on: https://people.debian.org/~sthibault/qemu.git/ slirp branch
>
> This series goal is to allow building libslirp as an independent library.
>
> While looking at making SLIRP a seperate running process, I thought
> that having an independent library from QEMU would be a first step.
>
> There has been some attempts to make slirp a seperate project in the past.
> (https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg01092.html)
> Unfortunately, they forked from QEMU and didn't provide enough
> compatibility for QEMU to make use of it (in particular, vmstate
> handling was removed, they lost git history etc). Furthermore, they
> are not maintained as far as I can see.
>
> I would propose to make slirp a seperate project, that can initially
> be used by QEMU as a submodule, keeping Makefile.objs until a proper
> shared library with stability guarantees etc is ready..
>
> The subproject could created by preserving git tags, and cleaning up the code style, this way:
>
> git filter-branch --tree-filter "if ls * 1> /dev/null 2>&1; then clang-format -i * /dev/null; fi " -f --subdirectory-filter "slirp" --prune-empty --tag-name-filter cat -- --all
> (my clang-format https://gist.github.com/elmarco/cb20c8d92007df0e2fb8a2404678ac73)
>
> What do you think?

Has the slirp code been improved to be generally useful?  I still got it
filed under "friends don't let friends use that, except for testing"...

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 05/41] slirp: use a callback structure to interface with qemu
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 05/41] slirp: use a callback structure to interface with qemu Marc-André Lureau
@ 2018-11-14 13:10   ` Philippe Mathieu-Daudé
  2018-11-19 23:09     ` Samuel Thibault
  2018-11-14 14:30   ` Stefan Hajnoczi
  1 sibling, 1 reply; 137+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-11-14 13:10 UTC (permalink / raw)
  To: Marc-André Lureau, qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo

On 14/11/18 13:36, Marc-André Lureau wrote:
> This will bring slirp a bit forward to the state of an independent
> project.
> 
> This could be squashed with earlier submitted "slirp: associate
> slirp_output".
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   slirp/libslirp.h |  7 +++++--
>   slirp/slirp.h    |  2 +-
>   net/slirp.c      |  6 +++++-
>   slirp/ncsi.c     |  2 +-
>   slirp/slirp.c    | 10 +++++-----
>   5 files changed, 17 insertions(+), 10 deletions(-)
> 
> diff --git a/slirp/libslirp.h b/slirp/libslirp.h
> index 04b6db9f49..36d5fb9163 100644
> --- a/slirp/libslirp.h
> +++ b/slirp/libslirp.h
> @@ -5,7 +5,10 @@
>   
>   typedef struct Slirp Slirp;
>   
> -typedef void (*slirp_output)(void *opaque, const uint8_t *pkt, int pkt_len);
> +typedef struct SlirpCb {
> +    void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
> +} SlirpCb;
> +
>   
>   Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
>                     struct in_addr vnetmask, struct in_addr vhost,
> @@ -17,7 +20,7 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
>                     struct in_addr vdhcp_start, struct in_addr vnameserver,
>                     struct in6_addr vnameserver6, const char **vdnssearch,
>                     const char *vdomainname,
> -                  slirp_output output,
> +                  const SlirpCb *callbacks,
>                     void *opaque);
>   void slirp_cleanup(Slirp *slirp);
>   
> diff --git a/slirp/slirp.h b/slirp/slirp.h
> index de299aa36c..f7c087456a 100644
> --- a/slirp/slirp.h
> +++ b/slirp/slirp.h
> @@ -220,7 +220,7 @@ struct Slirp {
>       GRand *grand;
>       QEMUTimer *ra_timer;
>   
> -    slirp_output output;
> +    const SlirpCb *cb;
>       void *opaque;
>   };
>   
> diff --git a/net/slirp.c b/net/slirp.c
> index dfc72cfc2e..233f66b1ef 100644
> --- a/net/slirp.c
> +++ b/net/slirp.c
> @@ -140,6 +140,10 @@ static NetClientInfo net_slirp_info = {
>       .cleanup = net_slirp_cleanup,
>   };
>   
> +static SlirpCb slirp_cb = {

const     ^

With the const qualifier:
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> +    .output = net_slirp_output,
> +};
> +
>   static int net_slirp_init(NetClientState *peer, const char *model,
>                             const char *name, int restricted,
>                             bool ipv4, const char *vnetwork, const char *vhost,
> @@ -379,7 +383,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
>                             vhostname, tftp_server_name,
>                             tftp_export, bootfile, dhcp,
>                             dns, ip6_dns, dnssearch, vdomainname,
> -                          net_slirp_output, s);
> +                          &slirp_cb, s);
>       QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry);
>   
>       for (config = slirp_configs; config; config = config->next) {
> diff --git a/slirp/ncsi.c b/slirp/ncsi.c
> index d7701f7785..10decfb5ef 100644
> --- a/slirp/ncsi.c
> +++ b/slirp/ncsi.c
> @@ -163,5 +163,5 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
>       *pchecksum = htonl(checksum);
>       ncsi_rsp_len += 4;
>   
> -    slirp->output(slirp->opaque, ncsi_reply, ETH_HLEN + ncsi_rsp_len);
> +    slirp->cb->output(slirp->opaque, ncsi_reply, ETH_HLEN + ncsi_rsp_len);
>   }
> diff --git a/slirp/slirp.c b/slirp/slirp.c
> index 0e4ade3e4a..7213915bf3 100644
> --- a/slirp/slirp.c
> +++ b/slirp/slirp.c
> @@ -288,14 +288,14 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
>                     struct in_addr vdhcp_start, struct in_addr vnameserver,
>                     struct in6_addr vnameserver6, const char **vdnssearch,
>                     const char *vdomainname,
> -                  slirp_output output,
> +                  const SlirpCb *callbacks,
>                     void *opaque)
>   {
>       Slirp *slirp = g_malloc0(sizeof(Slirp));
>   
>       slirp_init_once();
>   
> -    slirp->output = output;
> +    slirp->cb = callbacks;
>       slirp->grand = g_rand_new();
>       slirp->restricted = restricted;
>   
> @@ -843,7 +843,7 @@ static void arp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
>               rah->ar_sip = ah->ar_tip;
>               memcpy(rah->ar_tha, ah->ar_sha, ETH_ALEN);
>               rah->ar_tip = ah->ar_sip;
> -            slirp->output(slirp->opaque, arp_reply, sizeof(arp_reply));
> +            slirp->cb->output(slirp->opaque, arp_reply, sizeof(arp_reply));
>           }
>           break;
>       case ARPOP_REPLY:
> @@ -943,7 +943,7 @@ static int if_encap4(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh,
>               /* target IP */
>               rah->ar_tip = iph->ip_dst.s_addr;
>               slirp->client_ipaddr = iph->ip_dst;
> -            slirp->output(slirp->opaque, arp_req, sizeof(arp_req));
> +            slirp->cb->output(slirp->opaque, arp_req, sizeof(arp_req));
>               ifm->resolution_requested = true;
>   
>               /* Expire request and drop outgoing packet after 1 second */
> @@ -1029,7 +1029,7 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
>                   eh->h_dest[0], eh->h_dest[1], eh->h_dest[2],
>                   eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]));
>       memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len);
> -    slirp->output(slirp->opaque, buf, ifm->m_len + ETH_HLEN);
> +    slirp->cb->output(slirp->opaque, buf, ifm->m_len + ETH_HLEN);
>       return 1;
>   }
>   
> 

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 10/41] slirp: remove PROBE_CONN dead-code
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 10/41] slirp: remove PROBE_CONN dead-code Marc-André Lureau
@ 2018-11-14 13:12   ` Philippe Mathieu-Daudé
  2018-11-19 23:17     ` Samuel Thibault
  2018-11-14 13:33   ` Daniel P. Berrangé
  1 sibling, 1 reply; 137+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-11-14 13:12 UTC (permalink / raw)
  To: Marc-André Lureau, qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo

On 14/11/18 13:36, Marc-André Lureau wrote:
> Nobody cares for over 14y. Somebody can revert or rewrite if
> interested by that.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>   slirp/slirp_config.h |  4 ----
>   slirp/slirp.c        | 41 -----------------------------------------
>   2 files changed, 45 deletions(-)
> 
> diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
> index c59f655207..721667e3ef 100644
> --- a/slirp/slirp_config.h
> +++ b/slirp/slirp_config.h
> @@ -2,10 +2,6 @@
>    * User definable configuration options
>    */
>   
> -/* Define if you want the connection to be probed */
> -/* XXX Not working yet, so ignore this for now */
> -#undef PROBE_CONN
> -
>   /* Define to 1 if you want KEEPALIVE timers */
>   #define DO_KEEPALIVE 0
>   
> diff --git a/slirp/slirp.c b/slirp/slirp.c
> index 979495e88b..2d32debf2a 100644
> --- a/slirp/slirp.c
> +++ b/slirp/slirp.c
> @@ -699,47 +699,6 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error)
>                           }
>                       }
>                   }
> -
> -                /*
> -                 * Probe a still-connecting, non-blocking socket
> -                 * to check if it's still alive
> -                 */
> -#ifdef PROBE_CONN
> -                if (so->so_state & SS_ISFCONNECTING) {
> -                    ret = qemu_recv(so->s, &ret, 0, 0);
> -
> -                    if (ret < 0) {
> -                        /* XXX */
> -                        if (errno == EAGAIN || errno == EWOULDBLOCK ||
> -                            errno == EINPROGRESS || errno == ENOTCONN) {
> -                            continue; /* Still connecting, continue */
> -                        }
> -
> -                        /* else failed */
> -                        so->so_state &= SS_PERSISTENT_MASK;
> -                        so->so_state |= SS_NOFDREF;
> -
> -                        /* tcp_input will take care of it */
> -                    } else {
> -                        ret = send(so->s, &ret, 0, 0);
> -                        if (ret < 0) {
> -                            /* XXX */
> -                            if (errno == EAGAIN || errno == EWOULDBLOCK ||
> -                                errno == EINPROGRESS || errno == ENOTCONN) {
> -                                continue;
> -                            }
> -                            /* else failed */
> -                            so->so_state &= SS_PERSISTENT_MASK;
> -                            so->so_state |= SS_NOFDREF;
> -                        } else {
> -                            so->so_state &= ~SS_ISFCONNECTING;
> -                        }
> -
> -                    }
> -                    tcp_input((struct mbuf *)NULL, sizeof(struct ip), so,
> -                              so->so_ffamily);
> -                } /* SS_ISFCONNECTING */
> -#endif
>               }
>   
>               /*
> 

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 24/41] slirp: replace HOST_WORDS_BIGENDIAN with glib equivalent
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 24/41] slirp: replace HOST_WORDS_BIGENDIAN with glib equivalent Marc-André Lureau
@ 2018-11-14 13:14   ` Philippe Mathieu-Daudé
  2018-11-20  1:07     ` Samuel Thibault
  2018-11-14 13:32   ` Daniel P. Berrangé
  1 sibling, 1 reply; 137+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-11-14 13:14 UTC (permalink / raw)
  To: Marc-André Lureau, qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo

On 14/11/18 13:36, Marc-André Lureau wrote:
> One more step towards making the project independent from QEMU.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>   slirp/ip.h           | 8 +++++---
>   slirp/ip6.h          | 3 ++-
>   slirp/ip6_icmp.h     | 6 +++---
>   slirp/slirp_config.h | 3 ---
>   slirp/tcp.h          | 4 +++-
>   5 files changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/slirp/ip.h b/slirp/ip.h
> index 59cf4aa918..83fc9cdfbf 100644
> --- a/slirp/ip.h
> +++ b/slirp/ip.h
> @@ -33,7 +33,9 @@
>   #ifndef IP_H
>   #define IP_H
>   
> -#ifdef HOST_WORDS_BIGENDIAN
> +#include <glib.h>
> +
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>   # undef NTOHL
>   # undef NTOHS
>   # undef HTONL
> @@ -69,7 +71,7 @@ typedef uint32_t n_long;                 /* long as received from the net */
>    * Structure of an internet header, naked of options.
>    */
>   struct ip {
> -#ifdef HOST_WORDS_BIGENDIAN
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>   	uint8_t ip_v:4,			/* version */
>   		ip_hl:4;		/* header length */
>   #else
> @@ -135,7 +137,7 @@ struct	ip_timestamp {
>   	uint8_t	ipt_code;		/* IPOPT_TS */
>   	uint8_t	ipt_len;		/* size of structure (variable) */
>   	uint8_t	ipt_ptr;		/* index of current entry */
> -#ifdef HOST_WORDS_BIGENDIAN
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>   	uint8_t	ipt_oflw:4,		/* overflow counter */
>   		ipt_flg:4;		/* flags, see below */
>   #else
> diff --git a/slirp/ip6.h b/slirp/ip6.h
> index b1bea43b3c..14e9c78735 100644
> --- a/slirp/ip6.h
> +++ b/slirp/ip6.h
> @@ -6,6 +6,7 @@
>   #ifndef SLIRP_IP6_H
>   #define SLIRP_IP6_H
>   
> +#include <glib.h>
>   #include "net/eth.h"
>   
>   #define ALLNODES_MULTICAST  { .s6_addr = \
> @@ -113,7 +114,7 @@ static inline void in6_compute_ethaddr(struct in6_addr ip,
>    * Structure of an internet header, naked of options.
>    */
>   struct ip6 {
> -#ifdef HOST_WORDS_BIGENDIAN
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>       uint32_t
>           ip_v:4,         /* version */
>           ip_tc_hi:4,     /* traffic class */
> diff --git a/slirp/ip6_icmp.h b/slirp/ip6_icmp.h
> index b3378b17b5..32b0914055 100644
> --- a/slirp/ip6_icmp.h
> +++ b/slirp/ip6_icmp.h
> @@ -34,7 +34,7 @@ struct ndp_rs {     /* Router Solicitation Message */
>   
>   struct ndp_ra {     /* Router Advertisement Message */
>       uint8_t chl;    /* Cur Hop Limit */
> -#ifdef HOST_WORDS_BIGENDIAN
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>       uint8_t
>           M:1,
>           O:1,
> @@ -56,7 +56,7 @@ struct ndp_ns {     /* Neighbor Solicitation Message */
>   } QEMU_PACKED;
>   
>   struct ndp_na {     /* Neighbor Advertisement Message */
> -#ifdef HOST_WORDS_BIGENDIAN
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>       uint32_t
>           R:1,                /* Router Flag */
>           S:1,                /* Solicited Flag */
> @@ -125,7 +125,7 @@ struct ndpopt {
>   #define ndpopt_linklayer ndpopt_body.linklayer_addr
>           struct prefixinfo {                     /* Prefix Information */
>               uint8_t     prefix_length;
> -#ifdef HOST_WORDS_BIGENDIAN
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>               uint8_t     L:1, A:1, reserved1:6;
>   #else
>               uint8_t     reserved1:6, A:1, L:1;
> diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
> index 5126711849..b2def6d20c 100644
> --- a/slirp/slirp_config.h
> +++ b/slirp/slirp_config.h
> @@ -11,8 +11,5 @@
>    * You shouldn't need to touch any of these
>    */
>   
> -/* Define if the machine is big endian */
> -//#undef HOST_WORDS_BIGENDIAN
> -
>   /* Define to sizeof(char *) */
>   #define SIZEOF_CHAR_P (HOST_LONG_BITS / 8)
> diff --git a/slirp/tcp.h b/slirp/tcp.h
> index 174d3d960c..47aaea6c5b 100644
> --- a/slirp/tcp.h
> +++ b/slirp/tcp.h
> @@ -33,6 +33,8 @@
>   #ifndef TCP_H
>   #define TCP_H
>   
> +#include <glib.h>
> +
>   typedef	uint32_t tcp_seq;
>   
>   #define      PR_SLOWHZ       2               /* 2 slow timeouts per second (approx) */
> @@ -51,7 +53,7 @@ struct tcphdr {
>   	uint16_t th_dport;              /* destination port */
>   	tcp_seq	th_seq;			/* sequence number */
>   	tcp_seq	th_ack;			/* acknowledgement number */
> -#ifdef HOST_WORDS_BIGENDIAN
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>   	uint8_t	th_off:4,		/* data offset */
>   		th_x2:4;		/* (unused) */
>   #else
> 

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 25/41] slirp: replace SIZEOF_CHAR_P with glib equivalent
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 25/41] slirp: replace SIZEOF_CHAR_P " Marc-André Lureau
@ 2018-11-14 13:14   ` Philippe Mathieu-Daudé
  2018-11-20  1:08     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-11-14 13:14 UTC (permalink / raw)
  To: Marc-André Lureau, qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo

On 14/11/18 13:36, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>   slirp/ip.h           | 2 +-
>   slirp/slirp_config.h | 3 ---
>   2 files changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/slirp/ip.h b/slirp/ip.h
> index 83fc9cdfbf..243b6c8b24 100644
> --- a/slirp/ip.h
> +++ b/slirp/ip.h
> @@ -177,7 +177,7 @@ struct	ip_timestamp {
>   
>   #define	IP_MSS		576		/* default maximum segment size */
>   
> -#if SIZEOF_CHAR_P == 4
> +#if GLIB_SIZEOF_VOID_P == 4
>   struct mbuf_ptr {
>   	struct mbuf *mptr;
>   	uint32_t dummy;
> diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
> index b2def6d20c..7147e0de04 100644
> --- a/slirp/slirp_config.h
> +++ b/slirp/slirp_config.h
> @@ -10,6 +10,3 @@
>    * Autoconf defined configuration options
>    * You shouldn't need to touch any of these
>    */
> -
> -/* Define to sizeof(char *) */
> -#define SIZEOF_CHAR_P (HOST_LONG_BITS / 8)
> 

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS Marc-André Lureau
@ 2018-11-14 13:17   ` Philippe Mathieu-Daudé
  2018-11-20  1:35     ` Samuel Thibault
  2018-11-14 14:15   ` Daniel P. Berrangé
  1 sibling, 1 reply; 137+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-11-14 13:17 UTC (permalink / raw)
  To: Marc-André Lureau, qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo

On 14/11/18 13:36, Marc-André Lureau wrote:
> Do not require QEMU macro.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>   slirp/ncsi.c | 2 +-
>   slirp/tftp.c | 4 ++--
>   2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/slirp/ncsi.c b/slirp/ncsi.c
> index 10decfb5ef..8594382270 100644
> --- a/slirp/ncsi.c
> +++ b/slirp/ncsi.c
> @@ -128,7 +128,7 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
>       memset(reh->h_source, 0xff, ETH_ALEN);
>       reh->h_proto = htons(ETH_P_NCSI);
>   
> -    for (i = 0; i < ARRAY_SIZE(ncsi_rsp_handlers); i++) {
> +    for (i = 0; i < G_N_ELEMENTS(ncsi_rsp_handlers); i++) {
>           if (ncsi_rsp_handlers[i].type == nh->type + 0x80) {
>               handler = &ncsi_rsp_handlers[i];
>               break;
> diff --git a/slirp/tftp.c b/slirp/tftp.c
> index dddb614b8a..ef8d0352b4 100644
> --- a/slirp/tftp.c
> +++ b/slirp/tftp.c
> @@ -360,7 +360,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas,
>         return;
>     }
>   
> -  while (k < pktlen && nb_options < ARRAY_SIZE(option_name)) {
> +  while (k < pktlen && nb_options < G_N_ELEMENTS(option_name)) {
>         const char *key, *value;
>   
>         key = &tp->x.tp_buf[k];
> @@ -404,7 +404,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas,
>     }
>   
>     if (nb_options > 0) {
> -      assert(nb_options <= ARRAY_SIZE(option_name));
> +      assert(nb_options <= G_N_ELEMENTS(option_name));
>         tftp_send_oack(spt, option_name, option_value, nb_options, tp);
>         return;
>     }
> 

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-14 12:59 ` [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Markus Armbruster
@ 2018-11-14 13:20   ` Richard W.M. Jones
  2018-11-14 13:33   ` Thomas Huth
  1 sibling, 0 replies; 137+ messages in thread
From: Richard W.M. Jones @ 2018-11-14 13:20 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Marc-André Lureau, qemu-devel, samuel.thibault, stefanha, renzo

On Wed, Nov 14, 2018 at 01:59:25PM +0100, Markus Armbruster wrote:
> Marc-André Lureau <marcandre.lureau@redhat.com> writes:
> 
> > Hi,
> >
> > Based-on: https://people.debian.org/~sthibault/qemu.git/ slirp branch
> >
> > This series goal is to allow building libslirp as an independent library.
> >
> > While looking at making SLIRP a seperate running process, I thought
> > that having an independent library from QEMU would be a first step.
> >
> > There has been some attempts to make slirp a seperate project in the past.
> > (https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg01092.html)
> > Unfortunately, they forked from QEMU and didn't provide enough
> > compatibility for QEMU to make use of it (in particular, vmstate
> > handling was removed, they lost git history etc). Furthermore, they
> > are not maintained as far as I can see.
> >
> > I would propose to make slirp a seperate project, that can initially
> > be used by QEMU as a submodule, keeping Makefile.objs until a proper
> > shared library with stability guarantees etc is ready..
> >
> > The subproject could created by preserving git tags, and cleaning up the code style, this way:
> >
> > git filter-branch --tree-filter "if ls * 1> /dev/null 2>&1; then clang-format -i * /dev/null; fi " -f --subdirectory-filter "slirp" --prune-empty --tag-name-filter cat -- --all
> > (my clang-format https://gist.github.com/elmarco/cb20c8d92007df0e2fb8a2404678ac73)
> >
> > What do you think?
> 
> Has the slirp code been improved to be generally useful?  I still got it
> filed under "friends don't let friends use that, except for testing"...

SLIRP may or may not be bad internally -- I don't know -- but it
provides an unbeatable feature that nothing else replaces: no setup,
no root network access.  We use it all over the place.

The idea of these patches is to move SLIRP into a separate project and
have it run as a separate process.  This solves IMHO two problems:
qemu maintainers don't seem to like it, as demonstrated above, and if
there are any security problems them we can nail down the SLIRP
external process so it has literally no access to the host except for
the handful of network socket system calls it needs.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 38/41] net: do not depend on slirp internals
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 38/41] net: do not depend on slirp internals Marc-André Lureau
@ 2018-11-14 13:21   ` Philippe Mathieu-Daudé
  2018-11-20  1:37     ` Samuel Thibault
  2018-11-15 13:19   ` Paolo Bonzini
  1 sibling, 1 reply; 137+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-11-14 13:21 UTC (permalink / raw)
  To: Marc-André Lureau, qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo

On 14/11/18 13:36, Marc-André Lureau wrote:
> Only slirp/libslirp.h should be included.
> 
> Instead of using some slirp declarations and utility functions directly,
> let's copy them in net/util.h.

Nice cleanup! Can this single patch be applied out of this RFC series?

> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>   net/colo.h            |  3 +--
>   net/util.h            | 55 +++++++++++++++++++++++++++++++++++++++++++
>   net/colo-compare.c    |  1 +
>   net/colo.c            |  1 +
>   net/filter-rewriter.c |  1 +
>   net/slirp.c           |  2 +-
>   stubs/slirp.c         |  2 +-
>   7 files changed, 61 insertions(+), 4 deletions(-)
> 
> diff --git a/net/colo.h b/net/colo.h
> index 11c5226488..420d916af2 100644
> --- a/net/colo.h
> +++ b/net/colo.h
> @@ -15,10 +15,9 @@
>   #ifndef QEMU_COLO_PROXY_H
>   #define QEMU_COLO_PROXY_H
>   
> -#include "slirp/slirp.h"
>   #include "qemu/jhash.h"
>   #include "qemu/timer.h"
> -#include "slirp/tcp.h"
> +#include "net/eth.h"
>   
>   #define HASHTABLE_MAX_SIZE 16384
>   
> diff --git a/net/util.h b/net/util.h
> index 60b73d372d..358185fd50 100644
> --- a/net/util.h
> +++ b/net/util.h
> @@ -26,6 +26,61 @@
>   #define QEMU_NET_UTIL_H
>   
>   
> +/*
> + * Structure of an internet header, naked of options.
> + */
> +struct ip {
> +#ifdef HOST_WORDS_BIGENDIAN
> +    uint8_t ip_v:4,         /* version */
> +            ip_hl:4;        /* header length */
> +#else
> +    uint8_t ip_hl:4,        /* header length */
> +            ip_v:4;         /* version */
> +#endif
> +    uint8_t ip_tos;         /* type of service */
> +    uint16_t ip_len;        /* total length */
> +    uint16_t ip_id;         /* identification */
> +    uint16_t ip_off;        /* fragment offset field */
> +#define IP_DF 0x4000        /* don't fragment flag */
> +#define IP_MF 0x2000        /* more fragments flag */
> +#define IP_OFFMASK 0x1fff   /* mask for fragmenting bits */
> +    uint8_t ip_ttl;         /* time to live */
> +    uint8_t ip_p;           /* protocol */
> +    uint16_t ip_sum;        /* checksum */
> +    struct in_addr ip_src, ip_dst;  /* source and dest address */
> +} QEMU_PACKED;
> +
> +static inline bool in6_equal_net(const struct in6_addr *a,
> +                                 const struct in6_addr *b,
> +                                 int prefix_len)
> +{
> +    if (memcmp(a, b, prefix_len / 8) != 0) {
> +        return 0;
> +    }
> +
> +    if (prefix_len % 8 == 0) {
> +        return 1;
> +    }
> +
> +    return a->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8))
> +        == b->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8));
> +}
> +
> +#define TCPS_CLOSED             0       /* closed */
> +#define TCPS_LISTEN             1       /* listening for connection */
> +#define TCPS_SYN_SENT           2       /* active, have sent syn */
> +#define TCPS_SYN_RECEIVED       3       /* have send and received syn */
> +/* states < TCPS_ESTABLISHED are those where connections not established */
> +#define TCPS_ESTABLISHED        4       /* established */
> +#define TCPS_CLOSE_WAIT         5       /* rcvd fin, waiting for close */
> +/* states > TCPS_CLOSE_WAIT are those where user has closed */
> +#define TCPS_FIN_WAIT_1         6       /* have closed, sent fin */
> +#define TCPS_CLOSING            7       /* closed xchd FIN; await FIN ACK */
> +#define TCPS_LAST_ACK           8       /* had fin and close; await FIN ACK */
> +/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
> +#define TCPS_FIN_WAIT_2         9       /* have closed, fin is acked */
> +#define TCPS_TIME_WAIT          10      /* in 2*msl quiet wait after close */
> +
>   int net_parse_macaddr(uint8_t *macaddr, const char *p);
>   
>   #endif /* QEMU_NET_UTIL_H */
> diff --git a/net/colo-compare.c b/net/colo-compare.c
> index a39191d522..3b6f596432 100644
> --- a/net/colo-compare.c
> +++ b/net/colo-compare.c
> @@ -30,6 +30,7 @@
>   #include "net/colo-compare.h"
>   #include "migration/colo.h"
>   #include "migration/migration.h"
> +#include "util.h"
>   
>   #define TYPE_COLO_COMPARE "colo-compare"
>   #define COLO_COMPARE(obj) \
> diff --git a/net/colo.c b/net/colo.c
> index 49176bf07b..8196b35837 100644
> --- a/net/colo.c
> +++ b/net/colo.c
> @@ -15,6 +15,7 @@
>   #include "qemu/osdep.h"
>   #include "trace.h"
>   #include "colo.h"
> +#include "util.h"
>   
>   uint32_t connection_key_hash(const void *opaque)
>   {
> diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
> index bb8f4d93b1..9ccd8947db 100644
> --- a/net/filter-rewriter.c
> +++ b/net/filter-rewriter.c
> @@ -22,6 +22,7 @@
>   #include "net/checksum.h"
>   #include "net/colo.h"
>   #include "migration/colo.h"
> +#include "util.h"
>   
>   #define FILTER_COLO_REWRITER(obj) \
>       OBJECT_CHECK(RewriterState, (obj), TYPE_FILTER_REWRITER)
> diff --git a/net/slirp.c b/net/slirp.c
> index 4c39878933..7524049e49 100644
> --- a/net/slirp.c
> +++ b/net/slirp.c
> @@ -38,12 +38,12 @@
>   #include "qemu/error-report.h"
>   #include "qemu/sockets.h"
>   #include "slirp/libslirp.h"
> -#include "slirp/ip6.h"
>   #include "chardev/char-fe.h"
>   #include "sysemu/sysemu.h"
>   #include "qemu/cutils.h"
>   #include "qapi/error.h"
>   #include "qapi/qmp/qdict.h"
> +#include "util.h"
>   
>   static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
>   {
> diff --git a/stubs/slirp.c b/stubs/slirp.c
> index 42f7e1afd0..70704346fd 100644
> --- a/stubs/slirp.c
> +++ b/stubs/slirp.c
> @@ -1,7 +1,7 @@
>   #include "qemu/osdep.h"
>   #include "qemu-common.h"
>   #include "qemu/host-utils.h"
> -#include "slirp/slirp.h"
> +#include "slirp/libslirp.h"
>   
>   void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
>   {
> 

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 24/41] slirp: replace HOST_WORDS_BIGENDIAN with glib equivalent
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 24/41] slirp: replace HOST_WORDS_BIGENDIAN with glib equivalent Marc-André Lureau
  2018-11-14 13:14   ` Philippe Mathieu-Daudé
@ 2018-11-14 13:32   ` Daniel P. Berrangé
  1 sibling, 0 replies; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:32 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:26PM +0400, Marc-André Lureau wrote:
> One more step towards making the project independent from QEMU.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/ip.h           | 8 +++++---
>  slirp/ip6.h          | 3 ++-
>  slirp/ip6_icmp.h     | 6 +++---
>  slirp/slirp_config.h | 3 ---
>  slirp/tcp.h          | 4 +++-
>  5 files changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/slirp/ip.h b/slirp/ip.h
> index 59cf4aa918..83fc9cdfbf 100644
> --- a/slirp/ip.h
> +++ b/slirp/ip.h
> @@ -33,7 +33,9 @@
>  #ifndef IP_H
>  #define IP_H
>  
> -#ifdef HOST_WORDS_BIGENDIAN
> +#include <glib.h>
> +
> +#if G_BYTE_ORDER == G_BIG_ENDIAN

This is a example of legacy cruft in QEMU that we should just
clean up across the entire codebase. Obviously it made sense
when first added to QEMU, but there's no sense in duplicating
what's provided by glib now it is a mandatory dependency.

I'm fine with you just changing slirp in this patch to avoid
getting bogged down in debate, but I'd strongly encourage a
followup to clean the rest of QEMU too

 Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
 

>  # undef NTOHL
>  # undef NTOHS
>  # undef HTONL
> @@ -69,7 +71,7 @@ typedef uint32_t n_long;                 /* long as received from the net */
>   * Structure of an internet header, naked of options.
>   */
>  struct ip {
> -#ifdef HOST_WORDS_BIGENDIAN
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>  	uint8_t ip_v:4,			/* version */
>  		ip_hl:4;		/* header length */
>  #else
> @@ -135,7 +137,7 @@ struct	ip_timestamp {
>  	uint8_t	ipt_code;		/* IPOPT_TS */
>  	uint8_t	ipt_len;		/* size of structure (variable) */
>  	uint8_t	ipt_ptr;		/* index of current entry */
> -#ifdef HOST_WORDS_BIGENDIAN
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>  	uint8_t	ipt_oflw:4,		/* overflow counter */
>  		ipt_flg:4;		/* flags, see below */
>  #else
> diff --git a/slirp/ip6.h b/slirp/ip6.h
> index b1bea43b3c..14e9c78735 100644
> --- a/slirp/ip6.h
> +++ b/slirp/ip6.h
> @@ -6,6 +6,7 @@
>  #ifndef SLIRP_IP6_H
>  #define SLIRP_IP6_H
>  
> +#include <glib.h>
>  #include "net/eth.h"
>  
>  #define ALLNODES_MULTICAST  { .s6_addr = \
> @@ -113,7 +114,7 @@ static inline void in6_compute_ethaddr(struct in6_addr ip,
>   * Structure of an internet header, naked of options.
>   */
>  struct ip6 {
> -#ifdef HOST_WORDS_BIGENDIAN
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>      uint32_t
>          ip_v:4,         /* version */
>          ip_tc_hi:4,     /* traffic class */
> diff --git a/slirp/ip6_icmp.h b/slirp/ip6_icmp.h
> index b3378b17b5..32b0914055 100644
> --- a/slirp/ip6_icmp.h
> +++ b/slirp/ip6_icmp.h
> @@ -34,7 +34,7 @@ struct ndp_rs {     /* Router Solicitation Message */
>  
>  struct ndp_ra {     /* Router Advertisement Message */
>      uint8_t chl;    /* Cur Hop Limit */
> -#ifdef HOST_WORDS_BIGENDIAN
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>      uint8_t
>          M:1,
>          O:1,
> @@ -56,7 +56,7 @@ struct ndp_ns {     /* Neighbor Solicitation Message */
>  } QEMU_PACKED;
>  
>  struct ndp_na {     /* Neighbor Advertisement Message */
> -#ifdef HOST_WORDS_BIGENDIAN
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>      uint32_t
>          R:1,                /* Router Flag */
>          S:1,                /* Solicited Flag */
> @@ -125,7 +125,7 @@ struct ndpopt {
>  #define ndpopt_linklayer ndpopt_body.linklayer_addr
>          struct prefixinfo {                     /* Prefix Information */
>              uint8_t     prefix_length;
> -#ifdef HOST_WORDS_BIGENDIAN
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>              uint8_t     L:1, A:1, reserved1:6;
>  #else
>              uint8_t     reserved1:6, A:1, L:1;
> diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h
> index 5126711849..b2def6d20c 100644
> --- a/slirp/slirp_config.h
> +++ b/slirp/slirp_config.h
> @@ -11,8 +11,5 @@
>   * You shouldn't need to touch any of these
>   */
>  
> -/* Define if the machine is big endian */
> -//#undef HOST_WORDS_BIGENDIAN
> -
>  /* Define to sizeof(char *) */
>  #define SIZEOF_CHAR_P (HOST_LONG_BITS / 8)
> diff --git a/slirp/tcp.h b/slirp/tcp.h
> index 174d3d960c..47aaea6c5b 100644
> --- a/slirp/tcp.h
> +++ b/slirp/tcp.h
> @@ -33,6 +33,8 @@
>  #ifndef TCP_H
>  #define TCP_H
>  
> +#include <glib.h>
> +
>  typedef	uint32_t tcp_seq;
>  
>  #define      PR_SLOWHZ       2               /* 2 slow timeouts per second (approx) */
> @@ -51,7 +53,7 @@ struct tcphdr {
>  	uint16_t th_dport;              /* destination port */
>  	tcp_seq	th_seq;			/* sequence number */
>  	tcp_seq	th_ack;			/* acknowledgement number */
> -#ifdef HOST_WORDS_BIGENDIAN
> +#if G_BYTE_ORDER == G_BIG_ENDIAN
>  	uint8_t	th_off:4,		/* data offset */
>  		th_x2:4;		/* (unused) */
>  #else
> -- 
> 2.19.1.708.g4ede3d42df
> 
> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 04/41] slirp: remove unused M_TRAILINGSPACE
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 04/41] slirp: remove unused M_TRAILINGSPACE Marc-André Lureau
@ 2018-11-14 13:32   ` Daniel P. Berrangé
  2018-11-19 23:01     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:32 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:06PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/mbuf.h | 1 -
>  1 file changed, 1 deletion(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 10/41] slirp: remove PROBE_CONN dead-code
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 10/41] slirp: remove PROBE_CONN dead-code Marc-André Lureau
  2018-11-14 13:12   ` Philippe Mathieu-Daudé
@ 2018-11-14 13:33   ` Daniel P. Berrangé
  1 sibling, 0 replies; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:33 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:12PM +0400, Marc-André Lureau wrote:
> Nobody cares for over 14y. Somebody can revert or rewrite if
> interested by that.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp_config.h |  4 ----
>  slirp/slirp.c        | 41 -----------------------------------------
>  2 files changed, 45 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-14 12:59 ` [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Markus Armbruster
  2018-11-14 13:20   ` Richard W.M. Jones
@ 2018-11-14 13:33   ` Thomas Huth
  2018-11-14 14:46     ` Markus Armbruster
  1 sibling, 1 reply; 137+ messages in thread
From: Thomas Huth @ 2018-11-14 13:33 UTC (permalink / raw)
  To: Markus Armbruster, Marc-André Lureau
  Cc: samuel.thibault, renzo, qemu-devel, stefanha, rjones, Jan Kiszka

On 2018-11-14 13:59, Markus Armbruster wrote:
> Marc-André Lureau <marcandre.lureau@redhat.com> writes:
> 
>> Hi,
>>
>> Based-on: https://people.debian.org/~sthibault/qemu.git/ slirp branch
>>
>> This series goal is to allow building libslirp as an independent library.
>>
>> While looking at making SLIRP a seperate running process, I thought
>> that having an independent library from QEMU would be a first step.
>>
>> There has been some attempts to make slirp a seperate project in the past.
>> (https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg01092.html)
>> Unfortunately, they forked from QEMU and didn't provide enough
>> compatibility for QEMU to make use of it (in particular, vmstate
>> handling was removed, they lost git history etc). Furthermore, they
>> are not maintained as far as I can see.
>>
>> I would propose to make slirp a seperate project, that can initially
>> be used by QEMU as a submodule, keeping Makefile.objs until a proper
>> shared library with stability guarantees etc is ready..
>>
>> The subproject could created by preserving git tags, and cleaning up the code style, this way:
>>
>> git filter-branch --tree-filter "if ls * 1> /dev/null 2>&1; then clang-format -i * /dev/null; fi " -f --subdirectory-filter "slirp" --prune-empty --tag-name-filter cat -- --all
>> (my clang-format https://gist.github.com/elmarco/cb20c8d92007df0e2fb8a2404678ac73)
>>
>> What do you think?
> 
> Has the slirp code been improved to be generally useful?  I still got it
> filed under "friends don't let friends use that, except for testing"...

The slirp code is already used in a lot of other projects:

- WinUAE
  (https://github.com/tonioni/WinUAE/tree/master/slirp)

- Previous
  (https://sourceforge.net/p/previous/code/HEAD/tree/trunk/src/slirp/)

- BasiliskII
  (https://github.com/cebix/macemu/tree/master/BasiliskII/src/slirp)

- Bochs

(https://sourceforge.net/p/bochs/code/HEAD/tree/trunk/bochs/iodev/network/slirp/)

... and likely many more. AFAIK they all (or at least most) have been
forked from the QEMU code at one point in time and diverged, i.e. they
likely missed the bug fixes and new features that have been added in
QEMU (like IPv6). So yes, IMHO it makes a lot of sense to try to make a
separate library out of the slirp code again, especially if we could
convince the other projects to use it, too, and to collaborate on that
version.

 Thomas

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (41 preceding siblings ...)
  2018-11-14 12:59 ` [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Markus Armbruster
@ 2018-11-14 13:45 ` Daniel P. Berrangé
  2018-11-15 16:49   ` Giuseppe Scrivano
  2018-11-14 14:26 ` Stefan Hajnoczi
  43 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:45 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:02PM +0400, Marc-André Lureau wrote:
> Hi,
> 
> Based-on: https://people.debian.org/~sthibault/qemu.git/ slirp branch
> 
> This series goal is to allow building libslirp as an independent library.

At least half of the patches in this series are deleting unused or
unreachable code. I'd suggest you send all of those as a non-RFC
series, as they are things we could merge straight away regardless
of whether/when slirp becomes a separate library.

> While looking at making SLIRP a seperate running process, I thought
> that having an independent library from QEMU would be a first step.
> 
> There has been some attempts to make slirp a seperate project in the past.
> (https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg01092.html)
> Unfortunately, they forked from QEMU and didn't provide enough
> compatibility for QEMU to make use of it (in particular, vmstate
> handling was removed, they lost git history etc). Furthermore, they
> are not maintained as far as I can see.

More recently there is this fun project which just pulled in the
QEMU code and chopped out everything todo with slirp:

  https://github.com/rootless-containers/slirp4netns

If the libslirp you propose can satisfy their integration needs
it would be a positive validation of the need for & benefit of
a standalone libslirp.

> I would propose to make slirp a seperate project, that can initially
> be used by QEMU as a submodule, keeping Makefile.objs until a proper
> shared library with stability guarantees etc is ready..

A sub-module sounds ok in short term, but from a distro packaging
POV, I think there'd be strong pressure to unbundle it as quickly
as possible, even immediately. A lack of stable ABI would not be
ideal, but it is not a show stopper either - it would just mean
relatively frequent rebuilds for soname changes which is something
that happens quite a bit already for other deps we have in Fedora:

$ grep soname qemu.spec 
- Rebuild for libiscsi changed soname again
- Rebuild for changed Xen sonames
- Rebuild to pick up changed libxen* sonames
- Rebuild for libiscsi soname bump
- Rebuild for changed xen soname

> The subproject could created by preserving git tags, and cleaning up the code style, this way:
> 
> git filter-branch --tree-filter "if ls * 1> /dev/null 2>&1; then clang-format -i * /dev/null; fi " -f --subdirectory-filter "slirp" --prune-empty --tag-name-filter cat -- --all
> (my clang-format https://gist.github.com/elmarco/cb20c8d92007df0e2fb8a2404678ac73)

FWIW, when I split the libvirt python binding out of the main
libvirt repo, I needed a few more commands to fully clean the
git repo, otherwise the git repo size was still enourmous
despite having very few files left. At the time I ran this:

  $ git clone libvirt libvirt-python
  $ cd libvirt-python
  $ git filter-branch --subdirectory-filter python --tag-name-filter cat -- --all 
  $ git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
  $ git reflog expire --expire=now --all
  $ git gc --prune=now

  https://www.redhat.com/archives/libvir-list/2013-September/msg00413.html

> What do you think?

I think it sounds worthwhile given the number of times this has
come up before and the fact that people are forking QEMU already
to get access to slirp code.

A standalone project could potentially draw in more contributors
who are otherwise put off by it being part of the bigger QEMU
project, and/or unable to even use it as part of QEMU. This could
ultimately improve slirp's quality.


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 11/41] slirp: remove FULL_BOLT
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 11/41] slirp: remove FULL_BOLT Marc-André Lureau
@ 2018-11-14 13:46   ` Daniel P. Berrangé
  2018-11-19 23:18     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:46 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:13PM +0400, Marc-André Lureau wrote:
> Looking at git history, this looks like something from the past, when
> there was a tty layer. Let's remove it.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp_config.h | 7 -------
>  slirp/if.c           | 2 --
>  2 files changed, 9 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 12/41] slirp: remove the disabled readv()/writev() code path
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 12/41] slirp: remove the disabled readv()/writev() code path Marc-André Lureau
@ 2018-11-14 13:46   ` Daniel P. Berrangé
  2018-11-19 23:19     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:46 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:14PM +0400, Marc-André Lureau wrote:
> The soread() function may be used on datagram sockets, and would
> provide different behaviour if HAVE_READV was set, on empty datagrams.
> This looks like a minor optimization, that never has been a strong
> goal for slirp.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp_config.h |  3 ---
>  slirp/socket.c       | 15 ---------------
>  2 files changed, 18 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 13/41] slirp: remove HAVE_SYS_SIGNAL_H
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 13/41] slirp: remove HAVE_SYS_SIGNAL_H Marc-André Lureau
@ 2018-11-14 13:47   ` Daniel P. Berrangé
  2018-11-20  0:58     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:47 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:15PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp.h        | 3 ---
>  slirp/slirp_config.h | 3 ---
>  2 files changed, 6 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 14/41] slirp: remove unused HAVE_SYS_BITYPES_H
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 14/41] slirp: remove unused HAVE_SYS_BITYPES_H Marc-André Lureau
@ 2018-11-14 13:47   ` Daniel P. Berrangé
  2018-11-20  0:59     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:47 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:16PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp.h        | 4 ----
>  slirp/slirp_config.h | 3 ---
>  2 files changed, 7 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 15/41] slirp: remove NO_UNIX_SOCKETS
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 15/41] slirp: remove NO_UNIX_SOCKETS Marc-André Lureau
@ 2018-11-14 13:48   ` Daniel P. Berrangé
  2018-11-20  0:59     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:48 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:17PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp.h        | 3 ---
>  slirp/slirp_config.h | 6 ------
>  2 files changed, 9 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 16/41] slirp: remove unused HAVE_SYS_STROPTS_H
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 16/41] slirp: remove unused HAVE_SYS_STROPTS_H Marc-André Lureau
@ 2018-11-14 13:49   ` Daniel P. Berrangé
  2018-11-20  1:00     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:49 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:18PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp.h        | 5 -----
>  slirp/slirp_config.h | 3 ---
>  2 files changed, 8 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 17/41] slirp: remove unused HAVE_ARPA_INET_H
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 17/41] slirp: remove unused HAVE_ARPA_INET_H Marc-André Lureau
@ 2018-11-14 13:50   ` Daniel P. Berrangé
  2018-11-20  1:01     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:50 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:19PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp_config.h | 6 ------
>  1 file changed, 6 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 18/41] slirp: remove unused HAVE_SYS_WAIT_H
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 18/41] slirp: remove unused HAVE_SYS_WAIT_H Marc-André Lureau
@ 2018-11-14 13:50   ` Daniel P. Berrangé
  2018-11-20  1:01     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:50 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:20PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp.h        | 4 ----
>  slirp/slirp_config.h | 3 ---
>  2 files changed, 7 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 19/41] slirp: remove unused HAVE_SYS_SELECT_H
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 19/41] slirp: remove unused HAVE_SYS_SELECT_H Marc-André Lureau
@ 2018-11-14 13:51   ` Daniel P. Berrangé
  2018-11-20  1:02     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:51 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:21PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/main.h         | 4 ----
>  slirp/slirp.h        | 4 ----
>  slirp/slirp_config.h | 6 ------
>  3 files changed, 14 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 20/41] slirp: remove HAVE_SYS_IOCTL_H
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 20/41] slirp: remove HAVE_SYS_IOCTL_H Marc-André Lureau
@ 2018-11-14 13:51   ` Daniel P. Berrangé
  2018-11-20  1:03     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:51 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:22PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp.h        | 2 +-
>  slirp/slirp_config.h | 6 ------
>  2 files changed, 1 insertion(+), 7 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 21/41] slirp: remove HAVE_SYS_FILIO_H
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 21/41] slirp: remove HAVE_SYS_FILIO_H Marc-André Lureau
@ 2018-11-14 13:52   ` Daniel P. Berrangé
  2018-11-20  1:04     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:52 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:23PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp.h        | 2 +-
>  slirp/slirp_config.h | 6 ------
>  2 files changed, 1 insertion(+), 7 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 22/41] slirp: remove unused DECLARE_IOVEC
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 22/41] slirp: remove unused DECLARE_IOVEC Marc-André Lureau
@ 2018-11-14 13:53   ` Daniel P. Berrangé
  2018-11-20  1:05     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:53 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:24PM +0400, Marc-André Lureau wrote:
> It's actually qemu configure CONFIG_IOVEC that is being used.

That makes it sound like slirp is using CONFIG_IOVEC, but AFAICT
that's only used by QEMU's osdep code.

> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp_config.h | 6 ------
>  1 file changed, 6 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 23/41] slirp: remove unused HAVE_INET_ATON
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 23/41] slirp: remove unused HAVE_INET_ATON Marc-André Lureau
@ 2018-11-14 13:54   ` Daniel P. Berrangé
  2018-11-20  1:05     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:54 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:25PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp_config.h | 6 ------
>  1 file changed, 6 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 27/41] slirp: remove unused global slirp_instance
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 27/41] slirp: remove unused global slirp_instance Marc-André Lureau
@ 2018-11-14 13:55   ` Daniel P. Berrangé
  2018-11-20  1:10     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 13:55 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:29PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp.h | 2 --
>  1 file changed, 2 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 29/41] slirp: improve a bit the debug macros
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 29/41] slirp: improve a bit the debug macros Marc-André Lureau
@ 2018-11-14 14:04   ` Daniel P. Berrangé
  2018-11-14 20:51     ` Marc-André Lureau
  2018-11-20  1:19   ` Samuel Thibault
  1 sibling, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 14:04 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:31PM +0400, Marc-André Lureau wrote:
> Let them accept multiple arguments. Simplify the inner argument
> handling of DEBUG_ARGS/DEBUG_MISC_DEBUG_ERROR.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/debug.h      | 47 ++++++++++++++++++++++++++++++++++++----------
>  slirp/arp_table.c  | 12 ++++++------
>  slirp/bootp.c      |  3 +--
>  slirp/cksum.c      |  4 ++--
>  slirp/dhcpv6.c     | 11 +++++------
>  slirp/ip6_icmp.c   |  2 +-
>  slirp/ip_icmp.c    | 18 +++++++++---------
>  slirp/mbuf.c       |  2 +-
>  slirp/ndp_table.c  | 18 +++++++++---------
>  slirp/slirp.c      | 12 ++++++------
>  slirp/socket.c     | 32 +++++++++++++++----------------
>  slirp/tcp_input.c  | 15 +++++++--------
>  slirp/tcp_output.c |  2 +-
>  slirp/tcp_subr.c   |  4 ++--
>  slirp/udp.c        |  6 +++---
>  slirp/udp6.c       |  6 +++---
>  16 files changed, 109 insertions(+), 85 deletions(-)
> 
> diff --git a/slirp/debug.h b/slirp/debug.h
> index 6cfa61edb3..ca3a4b04da 100644
> --- a/slirp/debug.h
> +++ b/slirp/debug.h
> @@ -17,18 +17,45 @@
>  
>  extern int slirp_debug;
>  
> -#define DEBUG_CALL(x) if (slirp_debug & DBG_CALL) { fprintf(dfd, "%s...\n", x); fflush(dfd); }
> -#define DEBUG_ARG(x, y) if (slirp_debug & DBG_CALL) { fputc(' ', dfd); fprintf(dfd, x, y); fputc('\n', dfd); fflush(dfd); }
> -#define DEBUG_ARGS(x) if (slirp_debug & DBG_CALL) { fprintf x ; fflush(dfd); }
> -#define DEBUG_MISC(x) if (slirp_debug & DBG_MISC) { fprintf x ; fflush(dfd); }
> -#define DEBUG_ERROR(x) if (slirp_debug & DBG_ERROR) {fprintf x ; fflush(dfd); }
> +#define DEBUG_CALL(fmt, ...) do {               \
> +    if (slirp_debug & DBG_CALL) {               \
> +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> +        fprintf(dfd, "...\n");                  \
> +        fflush(dfd);                            \
> +    }                                           \
> +} while (0)
> +
> +#define DEBUG_ARG(fmt, ...) do {                \
> +    if (slirp_debug & DBG_CALL) {               \
> +        fputc(' ', dfd);                        \
> +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> +        fputc('\n', dfd);                       \
> +        fflush(dfd);                            \
> +    }                                           \
> +} while (0)
> +
> +#define DEBUG_ARGS(fmt, ...) DEBUG_ARG(fmt, ##__VA_ARGS__)
> +
> +#define DEBUG_MISC(fmt, ...) do {               \
> +    if (slirp_debug & DBG_MISC) {               \
> +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> +        fflush(dfd);                            \
> +    }                                           \
> +} while (0)
> +
> +#define DEBUG_ERROR(fmt, ...) do {              \
> +    if (slirp_debug & DBG_ERROR) {              \
> +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> +        fflush(dfd);                            \
> +    }                                           \
> +} while (0)

I tend to think it would be nicer to change these to
use  g_debug, and #define G_LOG_DOMAIN  "libslirp" in
the .c files.

This would allow apps to intercept the debug messages
via a custom log handler.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 32/41] slirp: remove unused sbflush()
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 32/41] slirp: remove unused sbflush() Marc-André Lureau
@ 2018-11-14 14:05   ` Daniel P. Berrangé
  2018-11-20  1:28     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 14:05 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:34PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/sbuf.h | 1 -
>  1 file changed, 1 deletion(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 34/41] slirp: remove #if notdef dead code
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 34/41] slirp: remove #if notdef dead code Marc-André Lureau
@ 2018-11-14 14:07   ` Daniel P. Berrangé
  2018-11-20  1:28     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 14:07 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:36PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/ip_input.c  | 200 ----------------------------------------------
>  slirp/tcp_input.c |  39 ---------
>  2 files changed, 239 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 35/41] slirp: NULL is defined by glib (at least)
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 35/41] slirp: NULL is defined by glib (at least) Marc-André Lureau
@ 2018-11-14 14:11   ` Daniel P. Berrangé
  2018-11-20  1:33     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 14:11 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

NULL is defined in stddef.h for at least 15 years AFAICT, so
even glib shouldn't bother to define it :-)  So I'd suggest
changing $subject to just defer to stddef.h

On Wed, Nov 14, 2018 at 04:36:37PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/slirp.h | 4 ----
>  1 file changed, 4 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

> 
> diff --git a/slirp/slirp.h b/slirp/slirp.h
> index 4356b2f427..2a61a85995 100644
> --- a/slirp/slirp.h
> +++ b/slirp/slirp.h
> @@ -199,10 +199,6 @@ struct Slirp {
>      void *opaque;
>  };
>  
> -#ifndef NULL
> -#define NULL (void *)0
> -#endif
> -
>  void if_start(Slirp *);
>  
>  int get_dns_addr(struct in_addr *pdns_addr);
> -- 
> 2.19.1.708.g4ede3d42df
> 
> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 36/41] slirp: remove dead TCP_ACK_HACK code
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 36/41] slirp: remove dead TCP_ACK_HACK code Marc-André Lureau
@ 2018-11-14 14:12   ` Daniel P. Berrangé
  2018-11-20  1:34     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 14:12 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:38PM +0400, Marc-André Lureau wrote:
> Untouched since original introduction in 2004.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/tcp_input.c | 23 +----------------------
>  1 file changed, 1 insertion(+), 22 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS Marc-André Lureau
  2018-11-14 13:17   ` Philippe Mathieu-Daudé
@ 2018-11-14 14:15   ` Daniel P. Berrangé
  1 sibling, 0 replies; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 14:15 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:39PM +0400, Marc-André Lureau wrote:
> Do not require QEMU macro.

As with the endian thing, we should really purge ARRAY_SIZE from
the entire QEMU codebase and just defer to glib. ARRAY_SIZE made
sense before glib was a hard dep in QEMU, but there's no reason
beyond bike shed colour choice to preserve it now.

I'm fine with this patch being targetted to slirp to avoid getting
dragged into a broader discussion, but I'd encourage the global
cleanup. I've personally used G_N_ELEMENTS in all QEMU code I've
been writing since its more familiar from glib than a QEMU
specific macro name.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>



Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 03/41] slirp: simplify fork_exec()
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 03/41] slirp: simplify fork_exec() Marc-André Lureau
@ 2018-11-14 14:22   ` Daniel P. Berrangé
  2018-11-19 22:59     ` Samuel Thibault
  2018-11-19 22:56   ` Samuel Thibault
  1 sibling, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 14:22 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, samuel.thibault, rjones, stefanha, renzo

On Wed, Nov 14, 2018 at 04:36:05PM +0400, Marc-André Lureau wrote:
> Use g_spawn_async_with_fds() to setup the child.
> 
> GSpawn handles reaping the child, and closing parent file descriptors.

The g_spawn* family of APIs is portable to Win32, which the current
fork/exec code in slirp is not.

So I'm curious if this conversion is sufficient to make this part
of slirp work on Win32, or if further portability problems remain.
If it does work on Win32, then you can also delete the stub
fork_exec() impl the code currently has.

> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/misc.c | 75 +++++++++++++++++++++++++---------------------------
>  1 file changed, 36 insertions(+), 39 deletions(-)
> 
> diff --git a/slirp/misc.c b/slirp/misc.c
> index 7362e14339..7972b9b05b 100644
> --- a/slirp/misc.c
> +++ b/slirp/misc.c
> @@ -129,56 +129,53 @@ err:
>      return -1;
>  }
>  
> +static void
> +fork_exec_child_setup(gpointer data)
> +{
> +    setsid();
> +}
> +
>  int
>  fork_exec(struct socket *so, const char *ex)
>  {
> -	char **argv;
> -	int opt, c, sp[2];
> -	pid_t pid;
> +    GError *err = NULL;
> +    char **argv;
> +    int opt, sp[2];
>  
> -	DEBUG_CALL("fork_exec");
> -	DEBUG_ARG("so = %p", so);
> -	DEBUG_ARG("ex = %p", ex);
> +    DEBUG_CALL("fork_exec");
> +    DEBUG_ARG("so = %p", so);
> +    DEBUG_ARG("ex = %p", ex);
>  
>      if (slirp_socketpair_with_oob(sp) < 0) {
>          return 0;
>      }
>  
> -	pid = fork();
> -	switch(pid) {
> -	 case -1:
> -		error_report("Error: fork failed: %s", strerror(errno));
> -		closesocket(sp[0]);
> -		closesocket(sp[1]);
> -		return 0;
> -
> -	 case 0:
> -		setsid();
> -		dup2(sp[1], 0);
> -		dup2(sp[1], 1);
> -		dup2(sp[1], 2);
> -		for (c = getdtablesize() - 1; c >= 3; c--)
> -		   close(c);
> +    argv = g_strsplit(ex, " ", -1);
> +    g_spawn_async_with_fds(NULL /* cwd */,
> +                           argv,
> +                           NULL /* env */,
> +                           G_SPAWN_SEARCH_PATH,
> +                           fork_exec_child_setup, NULL /* data */,
> +                           NULL /* child_pid */,
> +                           sp[1], sp[1], sp[1],
> +                           &err);
> +    g_strfreev(argv);
>  
> -                argv = g_strsplit(ex, " ", -1);
> -		execvp(argv[0], (char **)argv);
> -
> -		/* Ooops, failed, let's tell the user why */
> -        fprintf(stderr, "Error: execvp of %s failed: %s\n",
> -                argv[0], strerror(errno));
> -		close(0); close(1); close(2); /* XXX */
> -		exit(1);
> +    if (err) {
> +        error_report("%s", err->message);
> +        g_error_free(err);
> +        closesocket(sp[0]);
> +        closesocket(sp[1]);
> +        return 0;
> +    }
>  
> -	 default:
> -		so->s = sp[0];
> -		closesocket(sp[1]);
> -		qemu_add_child_watch(pid);
> -		socket_set_fast_reuse(so->s);
> -		opt = 1;
> -		qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
> -		qemu_set_nonblock(so->s);
> -		return 1;
> -	}
> +    so->s = sp[0];
> +    closesocket(sp[1]);
> +    socket_set_fast_reuse(so->s);
> +    opt = 1;
> +    qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
> +    qemu_set_nonblock(so->s);
> +    return 1;
>  }
>  #endif
>  
> -- 
> 2.19.1.708.g4ede3d42df
> 
> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
                   ` (42 preceding siblings ...)
  2018-11-14 13:45 ` Daniel P. Berrangé
@ 2018-11-14 14:26 ` Stefan Hajnoczi
  2018-11-14 14:30   ` Daniel P. Berrangé
  43 siblings, 1 reply; 137+ messages in thread
From: Stefan Hajnoczi @ 2018-11-14 14:26 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, samuel.thibault, rjones, renzo

[-- Attachment #1: Type: text/plain, Size: 1625 bytes --]

On Wed, Nov 14, 2018 at 04:36:02PM +0400, Marc-André Lureau wrote:
> Hi,
> 
> Based-on: https://people.debian.org/~sthibault/qemu.git/ slirp branch
> 
> This series goal is to allow building libslirp as an independent library.
> 
> While looking at making SLIRP a seperate running process, I thought
> that having an independent library from QEMU would be a first step.
> 
> There has been some attempts to make slirp a seperate project in the past.
> (https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg01092.html)
> Unfortunately, they forked from QEMU and didn't provide enough
> compatibility for QEMU to make use of it (in particular, vmstate
> handling was removed, they lost git history etc). Furthermore, they
> are not maintained as far as I can see.
> 
> I would propose to make slirp a seperate project, that can initially
> be used by QEMU as a submodule, keeping Makefile.objs until a proper
> shared library with stability guarantees etc is ready..
> 
> The subproject could created by preserving git tags, and cleaning up the code style, this way:
> 
> git filter-branch --tree-filter "if ls * 1> /dev/null 2>&1; then clang-format -i * /dev/null; fi " -f --subdirectory-filter "slirp" --prune-empty --tag-name-filter cat -- --all
> (my clang-format https://gist.github.com/elmarco/cb20c8d92007df0e2fb8a2404678ac73)
> 
> What do you think?

Great idea!

Maybe in the future there will be a tests too.  Right now my impression
is that slirp isn't hardened and suitable for production use cases (i.e.
security).  But with some love (and testing!) I think that could change.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 05/41] slirp: use a callback structure to interface with qemu
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 05/41] slirp: use a callback structure to interface with qemu Marc-André Lureau
  2018-11-14 13:10   ` Philippe Mathieu-Daudé
@ 2018-11-14 14:30   ` Stefan Hajnoczi
  1 sibling, 0 replies; 137+ messages in thread
From: Stefan Hajnoczi @ 2018-11-14 14:30 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, samuel.thibault, rjones, renzo

[-- Attachment #1: Type: text/plain, Size: 420 bytes --]

On Wed, Nov 14, 2018 at 04:36:07PM +0400, Marc-André Lureau wrote:
> -typedef void (*slirp_output)(void *opaque, const uint8_t *pkt, int pkt_len);
> +typedef struct SlirpCb {
> +    void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
> +} SlirpCb;

Please include doc comments for each SlirpCb callback introduced by this
series.  Otherwise it will be hard for other people to use libslirp.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-14 14:26 ` Stefan Hajnoczi
@ 2018-11-14 14:30   ` Daniel P. Berrangé
  2018-11-14 15:26     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 137+ messages in thread
From: Daniel P. Berrangé @ 2018-11-14 14:30 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Marc-André Lureau, samuel.thibault, renzo, qemu-devel, rjones

On Wed, Nov 14, 2018 at 02:26:42PM +0000, Stefan Hajnoczi wrote:
> On Wed, Nov 14, 2018 at 04:36:02PM +0400, Marc-André Lureau wrote:
> > Hi,
> > 
> > Based-on: https://people.debian.org/~sthibault/qemu.git/ slirp branch
> > 
> > This series goal is to allow building libslirp as an independent library.
> > 
> > While looking at making SLIRP a seperate running process, I thought
> > that having an independent library from QEMU would be a first step.
> > 
> > There has been some attempts to make slirp a seperate project in the past.
> > (https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg01092.html)
> > Unfortunately, they forked from QEMU and didn't provide enough
> > compatibility for QEMU to make use of it (in particular, vmstate
> > handling was removed, they lost git history etc). Furthermore, they
> > are not maintained as far as I can see.
> > 
> > I would propose to make slirp a seperate project, that can initially
> > be used by QEMU as a submodule, keeping Makefile.objs until a proper
> > shared library with stability guarantees etc is ready..
> > 
> > The subproject could created by preserving git tags, and cleaning up the code style, this way:
> > 
> > git filter-branch --tree-filter "if ls * 1> /dev/null 2>&1; then clang-format -i * /dev/null; fi " -f --subdirectory-filter "slirp" --prune-empty --tag-name-filter cat -- --all
> > (my clang-format https://gist.github.com/elmarco/cb20c8d92007df0e2fb8a2404678ac73)
> > 
> > What do you think?
> 
> Great idea!
> 
> Maybe in the future there will be a tests too.  Right now my impression
> is that slirp isn't hardened and suitable for production use cases (i.e.
> security).  But with some love (and testing!) I think that could change.

With Marc-André's desire to move it to a separate process, it is the
kind of thing where seccomp could actually do a fairly good job as it
would be a narrow enough piece of functionality that you can put some
meaningful constraints around it.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-14 13:33   ` Thomas Huth
@ 2018-11-14 14:46     ` Markus Armbruster
  2018-11-14 15:10       ` Dr. David Alan Gilbert
                         ` (2 more replies)
  0 siblings, 3 replies; 137+ messages in thread
From: Markus Armbruster @ 2018-11-14 14:46 UTC (permalink / raw)
  To: Thomas Huth
  Cc: Marc-André Lureau, renzo, Jan Kiszka, rjones, qemu-devel,
	stefanha, samuel.thibault

Thomas Huth <thuth@redhat.com> writes:

> On 2018-11-14 13:59, Markus Armbruster wrote:
>> Marc-André Lureau <marcandre.lureau@redhat.com> writes:
>> 
>>> Hi,
>>>
>>> Based-on: https://people.debian.org/~sthibault/qemu.git/ slirp branch
>>>
>>> This series goal is to allow building libslirp as an independent library.
>>>
>>> While looking at making SLIRP a seperate running process, I thought
>>> that having an independent library from QEMU would be a first step.
>>>
>>> There has been some attempts to make slirp a seperate project in the past.
>>> (https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg01092.html)
>>> Unfortunately, they forked from QEMU and didn't provide enough
>>> compatibility for QEMU to make use of it (in particular, vmstate
>>> handling was removed, they lost git history etc). Furthermore, they
>>> are not maintained as far as I can see.
>>>
>>> I would propose to make slirp a seperate project, that can initially
>>> be used by QEMU as a submodule, keeping Makefile.objs until a proper
>>> shared library with stability guarantees etc is ready..
>>>
>>> The subproject could created by preserving git tags, and cleaning up the code style, this way:
>>>
>>> git filter-branch --tree-filter "if ls * 1> /dev/null 2>&1; then clang-format -i * /dev/null; fi " -f --subdirectory-filter "slirp" --prune-empty --tag-name-filter cat -- --all
>>> (my clang-format https://gist.github.com/elmarco/cb20c8d92007df0e2fb8a2404678ac73)
>>>
>>> What do you think?
>> 
>> Has the slirp code been improved to be generally useful?  I still got it
>> filed under "friends don't let friends use that, except for testing"...
>
> The slirp code is already used in a lot of other projects:

The issue I have with SLIRP isn't that it solves a useless problem (au
contraire!), it's that it's a useless solution.  Okay, that's an unfair
exaggeration, it's not useless, I just wouldn't trust it in production,
unless it has improved significantly since I last looked at it.

> - WinUAE
>   (https://github.com/tonioni/WinUAE/tree/master/slirp)
>
> - Previous
>   (https://sourceforge.net/p/previous/code/HEAD/tree/trunk/src/slirp/)
>
> - BasiliskII
>   (https://github.com/cebix/macemu/tree/master/BasiliskII/src/slirp)
>
> - Bochs
>
> (https://sourceforge.net/p/bochs/code/HEAD/tree/trunk/bochs/iodev/network/slirp/)
>
> ... and likely many more. AFAIK they all (or at least most) have been
> forked from the QEMU code at one point in time and diverged, i.e. they
> likely missed the bug fixes and new features that have been added in
> QEMU (like IPv6). So yes, IMHO it makes a lot of sense to try to make a
> separate library out of the slirp code again, especially if we could
> convince the other projects to use it, too, and to collaborate on that
> version.

No objections to spinning it out, as long as it comes with a fair
assessment of its limitations.

Turning it into a proper project might even improve its chances to
get improved towards production quality, compared to its current
existence as a corner of QEMU next to nobody wants to touch.

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-14 14:46     ` Markus Armbruster
@ 2018-11-14 15:10       ` Dr. David Alan Gilbert
  2018-11-14 15:14       ` Richard W.M. Jones
  2018-11-14 16:52       ` Thomas Huth
  2 siblings, 0 replies; 137+ messages in thread
From: Dr. David Alan Gilbert @ 2018-11-14 15:10 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Thomas Huth, renzo, Jan Kiszka, qemu-devel, rjones, stefanha,
	samuel.thibault, Marc-André Lureau

* Markus Armbruster (armbru@redhat.com) wrote:
> Thomas Huth <thuth@redhat.com> writes:
> 
> > On 2018-11-14 13:59, Markus Armbruster wrote:
> >> Marc-André Lureau <marcandre.lureau@redhat.com> writes:
> >> 
> >>> Hi,
> >>>
> >>> Based-on: https://people.debian.org/~sthibault/qemu.git/ slirp branch
> >>>
> >>> This series goal is to allow building libslirp as an independent library.
> >>>
> >>> While looking at making SLIRP a seperate running process, I thought
> >>> that having an independent library from QEMU would be a first step.
> >>>
> >>> There has been some attempts to make slirp a seperate project in the past.
> >>> (https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg01092.html)
> >>> Unfortunately, they forked from QEMU and didn't provide enough
> >>> compatibility for QEMU to make use of it (in particular, vmstate
> >>> handling was removed, they lost git history etc). Furthermore, they
> >>> are not maintained as far as I can see.
> >>>
> >>> I would propose to make slirp a seperate project, that can initially
> >>> be used by QEMU as a submodule, keeping Makefile.objs until a proper
> >>> shared library with stability guarantees etc is ready..
> >>>
> >>> The subproject could created by preserving git tags, and cleaning up the code style, this way:
> >>>
> >>> git filter-branch --tree-filter "if ls * 1> /dev/null 2>&1; then clang-format -i * /dev/null; fi " -f --subdirectory-filter "slirp" --prune-empty --tag-name-filter cat -- --all
> >>> (my clang-format https://gist.github.com/elmarco/cb20c8d92007df0e2fb8a2404678ac73)
> >>>
> >>> What do you think?
> >> 
> >> Has the slirp code been improved to be generally useful?  I still got it
> >> filed under "friends don't let friends use that, except for testing"...
> >
> > The slirp code is already used in a lot of other projects:
> 
> The issue I have with SLIRP isn't that it solves a useless problem (au
> contraire!), it's that it's a useless solution.  Okay, that's an unfair
> exaggeration, it's not useless, I just wouldn't trust it in production,
> unless it has improved significantly since I last looked at it.

It's now used as a critical part of 'rootless-containers' - i.e. running
containers with no priviledges; see:
https://github.com/rootless-containers/slirp4netns/

Dave

> > - WinUAE
> >   (https://github.com/tonioni/WinUAE/tree/master/slirp)
> >
> > - Previous
> >   (https://sourceforge.net/p/previous/code/HEAD/tree/trunk/src/slirp/)
> >
> > - BasiliskII
> >   (https://github.com/cebix/macemu/tree/master/BasiliskII/src/slirp)
> >
> > - Bochs
> >
> > (https://sourceforge.net/p/bochs/code/HEAD/tree/trunk/bochs/iodev/network/slirp/)
> >
> > ... and likely many more. AFAIK they all (or at least most) have been
> > forked from the QEMU code at one point in time and diverged, i.e. they
> > likely missed the bug fixes and new features that have been added in
> > QEMU (like IPv6). So yes, IMHO it makes a lot of sense to try to make a
> > separate library out of the slirp code again, especially if we could
> > convince the other projects to use it, too, and to collaborate on that
> > version.
> 
> No objections to spinning it out, as long as it comes with a fair
> assessment of its limitations.
> 
> Turning it into a proper project might even improve its chances to
> get improved towards production quality, compared to its current
> existence as a corner of QEMU next to nobody wants to touch.
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-14 14:46     ` Markus Armbruster
  2018-11-14 15:10       ` Dr. David Alan Gilbert
@ 2018-11-14 15:14       ` Richard W.M. Jones
  2018-11-14 16:52       ` Thomas Huth
  2 siblings, 0 replies; 137+ messages in thread
From: Richard W.M. Jones @ 2018-11-14 15:14 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Thomas Huth, Marc-André Lureau, renzo, Jan Kiszka,
	qemu-devel, stefanha, samuel.thibault

On Wed, Nov 14, 2018 at 03:46:39PM +0100, Markus Armbruster wrote:
> The issue I have with SLIRP isn't that it solves a useless problem (au
> contraire!), it's that it's a useless solution.  Okay, that's an unfair
> exaggeration, it's not useless, I just wouldn't trust it in production,
> unless it has improved significantly since I last looked at it.

It's used by virt-builder, virt-customize, virt-v2v, etc., in some
cases in production.  Of course those uses are not completely general
purpose (it'll be things like running very specific, known ‘yum install’
commands from the guest), and we test it quite a bit.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-14 14:30   ` Daniel P. Berrangé
@ 2018-11-14 15:26     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 137+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-11-14 15:26 UTC (permalink / raw)
  To: Daniel P. Berrangé, Stefan Hajnoczi
  Cc: Marc-André Lureau, rjones, renzo, qemu-devel, samuel.thibault

On 14/11/18 15:30, Daniel P. Berrangé wrote:
> On Wed, Nov 14, 2018 at 02:26:42PM +0000, Stefan Hajnoczi wrote:
>> On Wed, Nov 14, 2018 at 04:36:02PM +0400, Marc-André Lureau wrote:
[...]
>>
>> Maybe in the future there will be a tests too.  Right now my impression
>> is that slirp isn't hardened and suitable for production use cases (i.e.
>> security).  But with some love (and testing!) I think that could change.
> 
> With Marc-André's desire to move it to a separate process, it is the
> kind of thing where seccomp could actually do a fairly good job as it
> would be a narrow enough piece of functionality that you can put some
> meaningful constraints around it.

It will also become easier to fuzz.

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-14 14:46     ` Markus Armbruster
  2018-11-14 15:10       ` Dr. David Alan Gilbert
  2018-11-14 15:14       ` Richard W.M. Jones
@ 2018-11-14 16:52       ` Thomas Huth
  2018-11-14 17:51         ` Markus Armbruster
  2 siblings, 1 reply; 137+ messages in thread
From: Thomas Huth @ 2018-11-14 16:52 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: renzo, Jan Kiszka, qemu-devel, rjones, stefanha, samuel.thibault,
	Marc-André Lureau

On 2018-11-14 15:46, Markus Armbruster wrote:
> Thomas Huth <thuth@redhat.com> writes:
> 
>> On 2018-11-14 13:59, Markus Armbruster wrote:
>>> Marc-André Lureau <marcandre.lureau@redhat.com> writes:
>>>
>>>> Hi,
>>>>
>>>> Based-on: https://people.debian.org/~sthibault/qemu.git/ slirp branch
>>>>
>>>> This series goal is to allow building libslirp as an independent library.
>>>>
>>>> While looking at making SLIRP a seperate running process, I thought
>>>> that having an independent library from QEMU would be a first step.
>>>>
>>>> There has been some attempts to make slirp a seperate project in the past.
>>>> (https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg01092.html)
>>>> Unfortunately, they forked from QEMU and didn't provide enough
>>>> compatibility for QEMU to make use of it (in particular, vmstate
>>>> handling was removed, they lost git history etc). Furthermore, they
>>>> are not maintained as far as I can see.
>>>>
>>>> I would propose to make slirp a seperate project, that can initially
>>>> be used by QEMU as a submodule, keeping Makefile.objs until a proper
>>>> shared library with stability guarantees etc is ready..
>>>>
>>>> The subproject could created by preserving git tags, and cleaning up the code style, this way:
>>>>
>>>> git filter-branch --tree-filter "if ls * 1> /dev/null 2>&1; then clang-format -i * /dev/null; fi " -f --subdirectory-filter "slirp" --prune-empty --tag-name-filter cat -- --all
>>>> (my clang-format https://gist.github.com/elmarco/cb20c8d92007df0e2fb8a2404678ac73)
>>>>
>>>> What do you think?
>>>
>>> Has the slirp code been improved to be generally useful?  I still got it
>>> filed under "friends don't let friends use that, except for testing"...
>>
>> The slirp code is already used in a lot of other projects:
> 
> The issue I have with SLIRP isn't that it solves a useless problem (au
> contraire!), it's that it's a useless solution.

Ouch, that was completely arrogant and inappropriate. It's far away from
being useless, and Samuel is doing a very good job in picking up all the
patches and fixes that have been posted in the past months. Have you had
a look at the changelog at all before you wrote that sentence?

> Okay, that's an unfair
> exaggeration, it's not useless, I just wouldn't trust it in production,
> unless it has improved significantly since I last looked at it.

Nobody said that the slirp code would suddenly be perfect, but if it's
getting even more traction and attention as a separate library (since
other projects might contribute their fixes back "upstream" in that
case), it could really get a solid building block for a lot of emulators
and similar software.

 Thomas

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-14 16:52       ` Thomas Huth
@ 2018-11-14 17:51         ` Markus Armbruster
  2018-11-14 18:14           ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 137+ messages in thread
From: Markus Armbruster @ 2018-11-14 17:51 UTC (permalink / raw)
  To: Thomas Huth
  Cc: Markus Armbruster, renzo, Jan Kiszka, rjones, qemu-devel,
	stefanha, Marc-André Lureau, samuel.thibault

Thomas Huth <thuth@redhat.com> writes:

> On 2018-11-14 15:46, Markus Armbruster wrote:
>> Thomas Huth <thuth@redhat.com> writes:
>> 
>>> On 2018-11-14 13:59, Markus Armbruster wrote:
>>>> Marc-André Lureau <marcandre.lureau@redhat.com> writes:
>>>>
>>>>> Hi,
>>>>>
>>>>> Based-on: https://people.debian.org/~sthibault/qemu.git/ slirp branch
>>>>>
>>>>> This series goal is to allow building libslirp as an independent library.
>>>>>
>>>>> While looking at making SLIRP a seperate running process, I thought
>>>>> that having an independent library from QEMU would be a first step.
>>>>>
>>>>> There has been some attempts to make slirp a seperate project in the past.
>>>>> (https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg01092.html)
>>>>> Unfortunately, they forked from QEMU and didn't provide enough
>>>>> compatibility for QEMU to make use of it (in particular, vmstate
>>>>> handling was removed, they lost git history etc). Furthermore, they
>>>>> are not maintained as far as I can see.
>>>>>
>>>>> I would propose to make slirp a seperate project, that can initially
>>>>> be used by QEMU as a submodule, keeping Makefile.objs until a proper
>>>>> shared library with stability guarantees etc is ready..
>>>>>
>>>>> The subproject could created by preserving git tags, and cleaning up the code style, this way:
>>>>>
>>>>> git filter-branch --tree-filter "if ls * 1> /dev/null 2>&1; then clang-format -i * /dev/null; fi " -f --subdirectory-filter "slirp" --prune-empty --tag-name-filter cat -- --all
>>>>> (my clang-format https://gist.github.com/elmarco/cb20c8d92007df0e2fb8a2404678ac73)
>>>>>
>>>>> What do you think?
>>>>
>>>> Has the slirp code been improved to be generally useful?  I still got it
>>>> filed under "friends don't let friends use that, except for testing"...
>>>
>>> The slirp code is already used in a lot of other projects:
>> 
>> The issue I have with SLIRP isn't that it solves a useless problem (au
>> contraire!), it's that it's a useless solution.
>
> Ouch, that was completely arrogant and inappropriate. It's far away from
> being useless,

... as I immediately admit ...

>                and Samuel is doing a very good job in picking up all the
> patches and fixes that have been posted in the past months. Have you had
> a look at the changelog at all before you wrote that sentence?

... right in the next sentence:

>> Okay, that's an unfair
>> exaggeration, it's not useless, I just wouldn't trust it in production,
>> unless it has improved significantly since I last looked at it.

If my joke offended Samuel, or anyone, I offer my sincere apologies.

> Nobody said that the slirp code would suddenly be perfect, but if it's
> getting even more traction and attention as a separate library (since
> other projects might contribute their fixes back "upstream" in that
> case), it could really get a solid building block for a lot of emulators
> and similar software.
[...]

I'm afraid we're in violent agreement there.  I wrote:

>> No objections to spinning it out, as long as it comes with a fair
>> assessment of its limitations.
>> 
>> Turning it into a proper project might even improve its chances to
>> get improved towards production quality, compared to its current
>> existence as a corner of QEMU next to nobody wants to touch.

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-14 17:51         ` Markus Armbruster
@ 2018-11-14 18:14           ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 137+ messages in thread
From: Dr. David Alan Gilbert @ 2018-11-14 18:14 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Thomas Huth, renzo, Jan Kiszka, qemu-devel, rjones, stefanha,
	samuel.thibault, Marc-André Lureau

* Markus Armbruster (armbru@redhat.com) wrote:
> Thomas Huth <thuth@redhat.com> writes:
> 
> > On 2018-11-14 15:46, Markus Armbruster wrote:
> >> Thomas Huth <thuth@redhat.com> writes:
> >> 
> >>> On 2018-11-14 13:59, Markus Armbruster wrote:
> >>>> Marc-André Lureau <marcandre.lureau@redhat.com> writes:
> >>>>
> >>>>> Hi,
> >>>>>
> >>>>> Based-on: https://people.debian.org/~sthibault/qemu.git/ slirp branch
> >>>>>
> >>>>> This series goal is to allow building libslirp as an independent library.
> >>>>>
> >>>>> While looking at making SLIRP a seperate running process, I thought
> >>>>> that having an independent library from QEMU would be a first step.
> >>>>>
> >>>>> There has been some attempts to make slirp a seperate project in the past.
> >>>>> (https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg01092.html)
> >>>>> Unfortunately, they forked from QEMU and didn't provide enough
> >>>>> compatibility for QEMU to make use of it (in particular, vmstate
> >>>>> handling was removed, they lost git history etc). Furthermore, they
> >>>>> are not maintained as far as I can see.
> >>>>>
> >>>>> I would propose to make slirp a seperate project, that can initially
> >>>>> be used by QEMU as a submodule, keeping Makefile.objs until a proper
> >>>>> shared library with stability guarantees etc is ready..
> >>>>>
> >>>>> The subproject could created by preserving git tags, and cleaning up the code style, this way:
> >>>>>
> >>>>> git filter-branch --tree-filter "if ls * 1> /dev/null 2>&1; then clang-format -i * /dev/null; fi " -f --subdirectory-filter "slirp" --prune-empty --tag-name-filter cat -- --all
> >>>>> (my clang-format https://gist.github.com/elmarco/cb20c8d92007df0e2fb8a2404678ac73)
> >>>>>
> >>>>> What do you think?
> >>>>
> >>>> Has the slirp code been improved to be generally useful?  I still got it
> >>>> filed under "friends don't let friends use that, except for testing"...
> >>>
> >>> The slirp code is already used in a lot of other projects:
> >> 
> >> The issue I have with SLIRP isn't that it solves a useless problem (au
> >> contraire!), it's that it's a useless solution.
> >
> > Ouch, that was completely arrogant and inappropriate. It's far away from
> > being useless,
> 
> ... as I immediately admit ...
> 
> >                and Samuel is doing a very good job in picking up all the
> > patches and fixes that have been posted in the past months. Have you had
> > a look at the changelog at all before you wrote that sentence?
> 
> ... right in the next sentence:
> 
> >> Okay, that's an unfair
> >> exaggeration, it's not useless, I just wouldn't trust it in production,
> >> unless it has improved significantly since I last looked at it.
> 
> If my joke offended Samuel, or anyone, I offer my sincere apologies.
> 
> > Nobody said that the slirp code would suddenly be perfect, but if it's
> > getting even more traction and attention as a separate library (since
> > other projects might contribute their fixes back "upstream" in that
> > case), it could really get a solid building block for a lot of emulators
> > and similar software.
> [...]
> 
> I'm afraid we're in violent agreement there.  I wrote:
> 
> >> No objections to spinning it out, as long as it comes with a fair
> >> assessment of its limitations.
> >> 
> >> Turning it into a proper project might even improve its chances to
> >> get improved towards production quality, compared to its current
> >> existence as a corner of QEMU next to nobody wants to touch.

One thought is that it might actually be the best standalone stack
around at the moment; I mean while I'm seeing people objecting
to bits of SLIRP, I'm not seeing anyone saying

'Why don't you just use ....'

Dave

--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 29/41] slirp: improve a bit the debug macros
  2018-11-14 14:04   ` Daniel P. Berrangé
@ 2018-11-14 20:51     ` Marc-André Lureau
  0 siblings, 0 replies; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-14 20:51 UTC (permalink / raw)
  To: P. Berrange, Daniel
  Cc: qemu-devel, samuel.thibault, Richard Jones, Stefan Hajnoczi, renzo

Hi

On Wed, Nov 14, 2018 at 6:04 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Wed, Nov 14, 2018 at 04:36:31PM +0400, Marc-André Lureau wrote:
> > Let them accept multiple arguments. Simplify the inner argument
> > handling of DEBUG_ARGS/DEBUG_MISC_DEBUG_ERROR.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/debug.h      | 47 ++++++++++++++++++++++++++++++++++++----------
> >  slirp/arp_table.c  | 12 ++++++------
> >  slirp/bootp.c      |  3 +--
> >  slirp/cksum.c      |  4 ++--
> >  slirp/dhcpv6.c     | 11 +++++------
> >  slirp/ip6_icmp.c   |  2 +-
> >  slirp/ip_icmp.c    | 18 +++++++++---------
> >  slirp/mbuf.c       |  2 +-
> >  slirp/ndp_table.c  | 18 +++++++++---------
> >  slirp/slirp.c      | 12 ++++++------
> >  slirp/socket.c     | 32 +++++++++++++++----------------
> >  slirp/tcp_input.c  | 15 +++++++--------
> >  slirp/tcp_output.c |  2 +-
> >  slirp/tcp_subr.c   |  4 ++--
> >  slirp/udp.c        |  6 +++---
> >  slirp/udp6.c       |  6 +++---
> >  16 files changed, 109 insertions(+), 85 deletions(-)
> >
> > diff --git a/slirp/debug.h b/slirp/debug.h
> > index 6cfa61edb3..ca3a4b04da 100644
> > --- a/slirp/debug.h
> > +++ b/slirp/debug.h
> > @@ -17,18 +17,45 @@
> >
> >  extern int slirp_debug;
> >
> > -#define DEBUG_CALL(x) if (slirp_debug & DBG_CALL) { fprintf(dfd, "%s...\n", x); fflush(dfd); }
> > -#define DEBUG_ARG(x, y) if (slirp_debug & DBG_CALL) { fputc(' ', dfd); fprintf(dfd, x, y); fputc('\n', dfd); fflush(dfd); }
> > -#define DEBUG_ARGS(x) if (slirp_debug & DBG_CALL) { fprintf x ; fflush(dfd); }
> > -#define DEBUG_MISC(x) if (slirp_debug & DBG_MISC) { fprintf x ; fflush(dfd); }
> > -#define DEBUG_ERROR(x) if (slirp_debug & DBG_ERROR) {fprintf x ; fflush(dfd); }
> > +#define DEBUG_CALL(fmt, ...) do {               \
> > +    if (slirp_debug & DBG_CALL) {               \
> > +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> > +        fprintf(dfd, "...\n");                  \
> > +        fflush(dfd);                            \
> > +    }                                           \
> > +} while (0)
> > +
> > +#define DEBUG_ARG(fmt, ...) do {                \
> > +    if (slirp_debug & DBG_CALL) {               \
> > +        fputc(' ', dfd);                        \
> > +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> > +        fputc('\n', dfd);                       \
> > +        fflush(dfd);                            \
> > +    }                                           \
> > +} while (0)
> > +
> > +#define DEBUG_ARGS(fmt, ...) DEBUG_ARG(fmt, ##__VA_ARGS__)
> > +
> > +#define DEBUG_MISC(fmt, ...) do {               \
> > +    if (slirp_debug & DBG_MISC) {               \
> > +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> > +        fflush(dfd);                            \
> > +    }                                           \
> > +} while (0)
> > +
> > +#define DEBUG_ERROR(fmt, ...) do {              \
> > +    if (slirp_debug & DBG_ERROR) {              \
> > +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> > +        fflush(dfd);                            \
> > +    }                                           \
> > +} while (0)
>
> I tend to think it would be nicer to change these to
> use  g_debug, and #define G_LOG_DOMAIN  "libslirp" in
> the .c files.
>
> This would allow apps to intercept the debug messages
> via a custom log handler.

Yes, even better would be structured logging, but it requires glib 2.50

One issue with the replacement is that we may want to keep the
slirp_debug filtering. If not, then we lose the classification.
Second issue is that slirp issues several debug calls and write \n in
the end. This is something you can't do with g_log. So it would need
some debug calls rewrite.

I would like to see this clean up patch applied before we decide how
to replace it with glog.

And yes, we should have a Slirp G_LOG_DOMAIN (I meant to do that, and forgot)

>
> Regards,
> Daniel
> --
> |: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org         -o-            https://fstop138.berrange.com :|
> |: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 07/41] slirp: add clock_get_ns() callback
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 07/41] slirp: add clock_get_ns() callback Marc-André Lureau
@ 2018-11-15 12:54   ` Paolo Bonzini
  2018-11-19 23:15     ` Samuel Thibault
  0 siblings, 1 reply; 137+ messages in thread
From: Paolo Bonzini @ 2018-11-15 12:54 UTC (permalink / raw)
  To: Marc-André Lureau, qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo

On 14/11/2018 13:36, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/libslirp.h |  6 ++++++
>  net/slirp.c      | 19 +++++++++++++++++++
>  slirp/if.c       |  2 +-
>  slirp/ip6_icmp.c |  6 ++++--
>  slirp/slirp.c    | 11 ++++++-----
>  5 files changed, 36 insertions(+), 8 deletions(-)
> 
> diff --git a/slirp/libslirp.h b/slirp/libslirp.h
> index 16ced2aa0f..fcebcd1e58 100644
> --- a/slirp/libslirp.h
> +++ b/slirp/libslirp.h
> @@ -5,9 +5,15 @@
>  
>  typedef struct Slirp Slirp;
>  
> +typedef enum SlirpClockType {
> +    SLIRP_CLOCK_VIRTUAL,
> +    SLIRP_CLOCK_REALTIME,

The more I look at this, the more I think that SLIRP_CLOCK_REALTIME is
wrong and it should also be using SLIRP_CLOCK_VIRTUAL.  It's used to put
a cap on the amount of time the guest has to reply to an ARP request,
and of course the guest cannot process it if it's paused.  So this can
be simpler, because SlirpClockType can disappear completely.

Paolo

> +} SlirpClockType;
> +
>  typedef struct SlirpCb {
>      void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
>      int (*chr_write_all)(void *chr, const void *buf, size_t len);
> +    int64_t (*clock_get_ns)(SlirpClockType type);
>  } SlirpCb;
>  
>  
> diff --git a/net/slirp.c b/net/slirp.c
> index 5c1f676487..af6c643b82 100644
> --- a/net/slirp.c
> +++ b/net/slirp.c
> @@ -145,9 +145,28 @@ static int net_slirp_chr_write_all(void *chr, const void *buf, size_t len)
>      return qemu_chr_fe_write_all(chr, buf, len);
>  }
>  
> +static QEMUClockType slirp_clock_to_qemu(SlirpClockType type)
> +{
> +    switch (type) {
> +    case SLIRP_CLOCK_VIRTUAL:
> +        return QEMU_CLOCK_VIRTUAL;
> +    case SLIRP_CLOCK_REALTIME:
> +        return QEMU_CLOCK_REALTIME;
> +    }
> +
> +    g_warn_if_reached();
> +    return QEMU_CLOCK_REALTIME;
> +}
> +
> +static int64_t net_slirp_clock_get_ns(SlirpClockType type)
> +{
> +    return qemu_clock_get_ns(slirp_clock_to_qemu(type));
> +}
> +
>  static SlirpCb slirp_cb = {
>      .output = net_slirp_output,
>      .chr_write_all = net_slirp_chr_write_all,
> +    .clock_get_ns = net_slirp_clock_get_ns,
>  };
>  
>  static int net_slirp_init(NetClientState *peer, const char *model,
> diff --git a/slirp/if.c b/slirp/if.c
> index 590753c658..1c96869831 100644
> --- a/slirp/if.c
> +++ b/slirp/if.c
> @@ -150,7 +150,7 @@ diddit:
>   */
>  void if_start(Slirp *slirp)
>  {
> -    uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
> +    uint64_t now = slirp->cb->clock_get_ns(SLIRP_CLOCK_REALTIME);
>      bool from_batchq = false;
>      struct mbuf *ifm, *ifm_next, *ifqt;
>  
> diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
> index cd1e0b9fe1..0f80d49ef9 100644
> --- a/slirp/ip6_icmp.c
> +++ b/slirp/ip6_icmp.c
> @@ -17,7 +17,8 @@ static void ra_timer_handler(void *opaque)
>  {
>      Slirp *slirp = opaque;
>      timer_mod(slirp->ra_timer,
> -              qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval);
> +              slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
> +              NDP_Interval);
>      ndp_send_ra(slirp);
>  }
>  
> @@ -31,7 +32,8 @@ void icmp6_init(Slirp *slirp)
>                                       SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL,
>                                       ra_timer_handler, slirp);
>      timer_mod(slirp->ra_timer,
> -              qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval);
> +              slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
> +              NDP_Interval);
>  }
>  
>  void icmp6_cleanup(Slirp *slirp)
> diff --git a/slirp/slirp.c b/slirp/slirp.c
> index 4e809e5d7f..979495e88b 100644
> --- a/slirp/slirp.c
> +++ b/slirp/slirp.c
> @@ -571,15 +571,15 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
>  
>  void slirp_pollfds_poll(GArray *pollfds, int select_error)
>  {
> -    Slirp *slirp;
> +    Slirp *slirp = QTAILQ_FIRST(&slirp_instances);
>      struct socket *so, *so_next;
>      int ret;
>  
> -    if (QTAILQ_EMPTY(&slirp_instances)) {
> +    if (!slirp) {
>          return;
>      }
>  
> -    curtime = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
> +    curtime = slirp->cb->clock_get_ns(SLIRP_CLOCK_REALTIME) / SCALE_MS;
>  
>      QTAILQ_FOREACH(slirp, &slirp_instances, entry) {
>          /*
> @@ -947,7 +947,8 @@ static int if_encap4(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh,
>              ifm->resolution_requested = true;
>  
>              /* Expire request and drop outgoing packet after 1 second */
> -            ifm->expiration_date = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + 1000000000ULL;
> +            ifm->expiration_date = slirp->cb->clock_get_ns(SLIRP_CLOCK_REALTIME)
> +                + 1000000000ULL;
>          }
>          return 0;
>      } else {
> @@ -974,7 +975,7 @@ static int if_encap6(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh,
>              ndp_send_ns(slirp, ip6h->ip_dst);
>              ifm->resolution_requested = true;
>              ifm->expiration_date =
> -                qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + 1000000000ULL;
> +                slirp->cb->clock_get_ns(SLIRP_CLOCK_REALTIME) + 1000000000ULL;
>          }
>          return 0;
>      } else {
> 

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 08/41] slirp: add callbacks for timer
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 08/41] slirp: add callbacks for timer Marc-André Lureau
@ 2018-11-15 12:56   ` Paolo Bonzini
  2019-01-15 19:21     ` Marc-André Lureau
  0 siblings, 1 reply; 137+ messages in thread
From: Paolo Bonzini @ 2018-11-15 12:56 UTC (permalink / raw)
  To: Marc-André Lureau, qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo

On 14/11/2018 13:36, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/libslirp.h |  6 ++++++
>  slirp/slirp.h    |  2 +-
>  net/slirp.c      | 23 +++++++++++++++++++++++
>  slirp/ip6_icmp.c | 21 ++++++++++-----------
>  4 files changed, 40 insertions(+), 12 deletions(-)
> 
> diff --git a/slirp/libslirp.h b/slirp/libslirp.h
> index fcebcd1e58..88185e6c33 100644
> --- a/slirp/libslirp.h
> +++ b/slirp/libslirp.h
> @@ -10,10 +10,16 @@ typedef enum SlirpClockType {
>      SLIRP_CLOCK_REALTIME,
>  } SlirpClockType;
>  
> +typedef void (*SlirpTimerCb)(void *opaque);
> +
>  typedef struct SlirpCb {
>      void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
>      int (*chr_write_all)(void *chr, const void *buf, size_t len);
>      int64_t (*clock_get_ns)(SlirpClockType type);
> +    void *(*timer_new)(SlirpClockType type, int scale,
> +                      SlirpTimerCb cb, void *opaque);

Same here wrt SlirpClockType; and nicely, scale is always nanoseconds so
it can be removed.

Paolo

> +    void (*timer_free)(void *timer);
> +    void (*timer_mod)(void *timer, int64_t expire_timer);
>  } SlirpCb;
>  
>  
> diff --git a/slirp/slirp.h b/slirp/slirp.h
> index f7c087456a..e5abf1c594 100644
> --- a/slirp/slirp.h
> +++ b/slirp/slirp.h
> @@ -218,7 +218,7 @@ struct Slirp {
>      NdpTable ndp_table;
>  
>      GRand *grand;
> -    QEMUTimer *ra_timer;
> +    void *ra_timer;
>  
>      const SlirpCb *cb;
>      void *opaque;
> diff --git a/net/slirp.c b/net/slirp.c
> index af6c643b82..7b28886802 100644
> --- a/net/slirp.c
> +++ b/net/slirp.c
> @@ -163,10 +163,33 @@ static int64_t net_slirp_clock_get_ns(SlirpClockType type)
>      return qemu_clock_get_ns(slirp_clock_to_qemu(type));
>  }
>  
> +static void *net_slirp_timer_new(SlirpClockType type,
> +                                 int scale,
> +                                 SlirpTimerCb cb, void *opaque)
> +{
> +    return timer_new_full(NULL, slirp_clock_to_qemu(type),
> +                          scale, QEMU_TIMER_ATTR_EXTERNAL,
> +                          cb, opaque);
> +}
> +
> +static void net_slirp_timer_free(void *timer)
> +{
> +    timer_del(timer);
> +    timer_free(timer);
> +}
> +
> +static void net_slirp_timer_mod(void *timer, int64_t expire_timer)
> +{
> +    timer_mod(timer, expire_timer);
> +}
> +
>  static SlirpCb slirp_cb = {
>      .output = net_slirp_output,
>      .chr_write_all = net_slirp_chr_write_all,
>      .clock_get_ns = net_slirp_clock_get_ns,
> +    .timer_new = net_slirp_timer_new,
> +    .timer_free = net_slirp_timer_free,
> +    .timer_mod = net_slirp_timer_mod,
>  };
>  
>  static int net_slirp_init(NetClientState *peer, const char *model,
> diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
> index 0f80d49ef9..71d95daef0 100644
> --- a/slirp/ip6_icmp.c
> +++ b/slirp/ip6_icmp.c
> @@ -16,9 +16,10 @@
>  static void ra_timer_handler(void *opaque)
>  {
>      Slirp *slirp = opaque;
> -    timer_mod(slirp->ra_timer,
> -              slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
> -              NDP_Interval);
> +
> +    slirp->cb->timer_mod(slirp->ra_timer,
> +        slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
> +        NDP_Interval);
>      ndp_send_ra(slirp);
>  }
>  
> @@ -28,12 +29,11 @@ void icmp6_init(Slirp *slirp)
>          return;
>      }
>  
> -    slirp->ra_timer = timer_new_full(NULL, QEMU_CLOCK_VIRTUAL,
> -                                     SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL,
> -                                     ra_timer_handler, slirp);
> -    timer_mod(slirp->ra_timer,
> -              slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
> -              NDP_Interval);
> +    slirp->ra_timer = slirp->cb->timer_new(SLIRP_CLOCK_VIRTUAL, SCALE_MS,
> +                                           ra_timer_handler, slirp);
> +    slirp->cb->timer_mod(slirp->ra_timer,
> +        slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
> +        NDP_Interval);
>  }
>  
>  void icmp6_cleanup(Slirp *slirp)
> @@ -42,8 +42,7 @@ void icmp6_cleanup(Slirp *slirp)
>          return;
>      }
>  
> -    timer_del(slirp->ra_timer);
> -    timer_free(slirp->ra_timer);
> +    slirp->cb->timer_free(slirp->ra_timer);
>  }
>  
>  static void icmp6_send_echoreply(struct mbuf *m, Slirp *slirp, struct ip6 *ip,
> 

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 09/41] slirp: add a set_nonblock() callback
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 09/41] slirp: add a set_nonblock() callback Marc-André Lureau
@ 2018-11-15 13:03   ` Paolo Bonzini
  2018-11-21 21:02     ` Marc-André Lureau
  2019-01-15 19:22     ` Marc-André Lureau
  0 siblings, 2 replies; 137+ messages in thread
From: Paolo Bonzini @ 2018-11-15 13:03 UTC (permalink / raw)
  To: Marc-André Lureau, qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo

On 14/11/2018 13:36, Marc-André Lureau wrote:
> qemu_set_nonblock() does some event registration with the main loop on
> win32, let's have a callback.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Perhaps a better interface would be register_poll_fd, which is called
before a file descriptor can be returned to slirp_pollfds_fill?  And
perhaps a dual unregister_poll_fd, which QEMU would leave empty, to be
called before closing the file descriptor.

Paolo

> ---
>  slirp/libslirp.h | 1 +
>  net/slirp.c      | 1 +
>  slirp/misc.c     | 2 +-
>  slirp/tcp_subr.c | 4 ++--
>  4 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/slirp/libslirp.h b/slirp/libslirp.h
> index 88185e6c33..f2e7f94ebb 100644
> --- a/slirp/libslirp.h
> +++ b/slirp/libslirp.h
> @@ -20,6 +20,7 @@ typedef struct SlirpCb {
>                        SlirpTimerCb cb, void *opaque);
>      void (*timer_free)(void *timer);
>      void (*timer_mod)(void *timer, int64_t expire_timer);
> +    void (*set_nonblock)(int fd);
>  } SlirpCb;
>  
>  
> diff --git a/net/slirp.c b/net/slirp.c
> index 7b28886802..5ea8c255f6 100644
> --- a/net/slirp.c
> +++ b/net/slirp.c
> @@ -190,6 +190,7 @@ static SlirpCb slirp_cb = {
>      .timer_new = net_slirp_timer_new,
>      .timer_free = net_slirp_timer_free,
>      .timer_mod = net_slirp_timer_mod,
> +    .set_nonblock = qemu_set_nonblock,
>  };
>  
>  static int net_slirp_init(NetClientState *peer, const char *model,
> diff --git a/slirp/misc.c b/slirp/misc.c
> index 7972b9b05b..dd2b3512a8 100644
> --- a/slirp/misc.c
> +++ b/slirp/misc.c
> @@ -174,7 +174,7 @@ fork_exec(struct socket *so, const char *ex)
>      socket_set_fast_reuse(so->s);
>      opt = 1;
>      qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
> -    qemu_set_nonblock(so->s);
> +    so->slirp->cb->set_nonblock(so->s);
>      return 1;
>  }
>  #endif
> diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
> index 4b40850c7a..8d97f1f54e 100644
> --- a/slirp/tcp_subr.c
> +++ b/slirp/tcp_subr.c
> @@ -412,7 +412,7 @@ int tcp_fconnect(struct socket *so, unsigned short af)
>      int opt, s=so->s;
>      struct sockaddr_storage addr;
>  
> -    qemu_set_nonblock(s);
> +    so->slirp->cb->set_nonblock(s);
>      socket_set_fast_reuse(s);
>      opt = 1;
>      qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
> @@ -484,7 +484,7 @@ void tcp_connect(struct socket *inso)
>          tcp_close(sototcpcb(so)); /* This will sofree() as well */
>          return;
>      }
> -    qemu_set_nonblock(s);
> +    so->slirp->cb->set_nonblock(s);
>      socket_set_fast_reuse(s);
>      opt = 1;
>      qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
> 

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 06/41] slirp: add a callback for qemu_chr_fe_write_all()
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 06/41] slirp: add a callback for qemu_chr_fe_write_all() Marc-André Lureau
@ 2018-11-15 13:12   ` Paolo Bonzini
  2019-01-15 19:22     ` Marc-André Lureau
  0 siblings, 1 reply; 137+ messages in thread
From: Paolo Bonzini @ 2018-11-15 13:12 UTC (permalink / raw)
  To: Marc-André Lureau, qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo

On 14/11/2018 13:36, Marc-André Lureau wrote:
> Replace strong dependency on QEMU.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/libslirp.h | 1 +
>  net/slirp.c      | 6 ++++++
>  slirp/slirp.c    | 2 +-
>  3 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/slirp/libslirp.h b/slirp/libslirp.h
> index 36d5fb9163..16ced2aa0f 100644
> --- a/slirp/libslirp.h
> +++ b/slirp/libslirp.h
> @@ -7,6 +7,7 @@ typedef struct Slirp Slirp;
>  
>  typedef struct SlirpCb {
>      void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
> +    int (*chr_write_all)(void *chr, const void *buf, size_t len);
>  } SlirpCb;
>  
>  
> diff --git a/net/slirp.c b/net/slirp.c
> index 233f66b1ef..5c1f676487 100644
> --- a/net/slirp.c
> +++ b/net/slirp.c
> @@ -140,8 +140,14 @@ static NetClientInfo net_slirp_info = {
>      .cleanup = net_slirp_cleanup,
>  };
>  
> +static int net_slirp_chr_write_all(void *chr, const void *buf, size_t len)
> +{
> +    return qemu_chr_fe_write_all(chr, buf, len);
> +}
> +
>  static SlirpCb slirp_cb = {
>      .output = net_slirp_output,
> +    .chr_write_all = net_slirp_chr_write_all,


>  };
>  
>  static int net_slirp_init(NetClientState *peer, const char *model,
> diff --git a/slirp/slirp.c b/slirp/slirp.c
> index 7213915bf3..4e809e5d7f 100644
> --- a/slirp/slirp.c
> +++ b/slirp/slirp.c
> @@ -1099,7 +1099,7 @@ ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags)
>      if (so->s == -1 && so->chardev) {
>          /* XXX this blocks entire thread. Rewrite to use
>           * qemu_chr_fe_write and background I/O callbacks */
> -        qemu_chr_fe_write_all(so->chardev, buf, len);
> +        so->slirp->cb->chr_write_all(so->chardev, buf, len);
>          return len;
>      }
>  
> 

Rather than this, I would split out add_exec's do_pty==3 case to a new
function add_guestfwd, and pass the function pointer to add_guestfwd.  Then:

1) add_guestfwd can store the function pointer in struct ex_list,

2) tcp_ctl can store the ex_ptr in struct socket directly, instead of
storing ex_ptr->ex_exec (that is the chardev field becomes "struct
ex_list *guestfwd" or something)

3) slirp_send can use so->chardev to retrieve both the function pointer
and the void* (renaming it to so->exec maybe)

Paolo

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 38/41] net: do not depend on slirp internals
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 38/41] net: do not depend on slirp internals Marc-André Lureau
  2018-11-14 13:21   ` Philippe Mathieu-Daudé
@ 2018-11-15 13:19   ` Paolo Bonzini
  1 sibling, 0 replies; 137+ messages in thread
From: Paolo Bonzini @ 2018-11-15 13:19 UTC (permalink / raw)
  To: Marc-André Lureau, qemu-devel
  Cc: samuel.thibault, rjones, stefanha, renzo

On 14/11/2018 13:36, Marc-André Lureau wrote:
> Only slirp/libslirp.h should be included.
> 
> Instead of using some slirp declarations and utility functions directly,
> let's copy them in net/util.h.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  net/colo.h            |  3 +--
>  net/util.h            | 55 +++++++++++++++++++++++++++++++++++++++++++
>  net/colo-compare.c    |  1 +
>  net/colo.c            |  1 +
>  net/filter-rewriter.c |  1 +
>  net/slirp.c           |  2 +-
>  stubs/slirp.c         |  2 +-
>  7 files changed, 61 insertions(+), 4 deletions(-)

Can you merge net/util.h and net/eth.h?

Thanks,

Paolo

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-14 13:45 ` Daniel P. Berrangé
@ 2018-11-15 16:49   ` Giuseppe Scrivano
  2018-11-16  5:09     ` Akihiro Suda
  0 siblings, 1 reply; 137+ messages in thread
From: Giuseppe Scrivano @ 2018-11-15 16:49 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: Daniel P. Berrangé,
	qemu-devel, samuel.thibault, rjones, stefanha, renzo,
	Akihiro Suda

Daniel P. Berrangé <berrange@redhat.com> writes:

> On Wed, Nov 14, 2018 at 04:36:02PM +0400, Marc-André Lureau wrote:
>> Hi,
>> 
>> Based-on: https://people.debian.org/~sthibault/qemu.git/ slirp branch
>> 
>> This series goal is to allow building libslirp as an independent library.

Marc-André, thanks for working on this!


> At least half of the patches in this series are deleting unused or
> unreachable code. I'd suggest you send all of those as a non-RFC
> series, as they are things we could merge straight away regardless
> of whether/when slirp becomes a separate library.
>
>> While looking at making SLIRP a seperate running process, I thought
>> that having an independent library from QEMU would be a first step.
>> 
>> There has been some attempts to make slirp a seperate project in the past.
>> (https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg01092.html)
>> Unfortunately, they forked from QEMU and didn't provide enough
>> compatibility for QEMU to make use of it (in particular, vmstate
>> handling was removed, they lost git history etc). Furthermore, they
>> are not maintained as far as I can see.
>
> More recently there is this fun project which just pulled in the
> QEMU code and chopped out everything todo with slirp:
>
>   https://github.com/rootless-containers/slirp4netns

to give a little bit of background on slirp4netns:

slirp4netns is used for setting up the network in a network namespace
without requiring root privileges.

It is already used by Podman and Buildah to set up the network for
rootless containers, so they won't be limited to run in the host network
namespace or require a suid helper.

Coincidentally just today I was working on a slirp4netns change for
spawning a QEMU process instead of using the forked version.
I'd prefer to not rely on the slirp forked version, but this costs the
access to the underlying knobs.  With a separate libslirp project, this
is not needed anymore.

One change I am aware of in the forked version is the possibility to
tweak the MTU and AFAIK this is the only blocker from adopting libslirp
immediately.
Akihiro, is there anything more that could block slirp4netns from just
using libslirp once it is available?

Regards,
Giuseppe

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project
  2018-11-15 16:49   ` Giuseppe Scrivano
@ 2018-11-16  5:09     ` Akihiro Suda
  0 siblings, 0 replies; 137+ messages in thread
From: Akihiro Suda @ 2018-11-16  5:09 UTC (permalink / raw)
  To: gscrivan
  Cc: marcandre.lureau, berrange, qemu-devel, samuel.thibault, rjones,
	stefanha, renzo

> One change I am aware of in the forked version is the possibility
to tweak the MTU and AFAIK this is the only blocker from adopting
libslirp immediately.
> Akihiro, is there anything more that could block slirp4netns from
just using libslirp once it is available?

No, the only blocker is MTU (which significantly improves the bandwidth
from 1.07 Gbps to 9.21 Gbps :
https://github.com/rootless-containers/slirp4netns/tree/19ec5cf6b8f562ebaed6d4004c8b172907ea6adb#benchmarks
)

In future I think we want to support checksum offloading and
multiqueue/multithread, but these can be experimented and discussed after
we get support for the standalone libslirp.
https://github.com/rootless-containers/slirp4netns/issues/16
https://github.com/rootless-containers/slirp4netns/issues/17


2018年11月16日(金) 0:49 Giuseppe Scrivano <gscrivan@redhat.com>:

> Daniel P. Berrangé <berrange@redhat.com> writes:
>
> > On Wed, Nov 14, 2018 at 04:36:02PM +0400, Marc-André Lureau wrote:
> >> Hi,
> >>
> >> Based-on: https://people.debian.org/~sthibault/qemu.git/ slirp branch
> >>
> >> This series goal is to allow building libslirp as an independent
> library.
>
> Marc-André, thanks for working on this!
>
>
> > At least half of the patches in this series are deleting unused or
> > unreachable code. I'd suggest you send all of those as a non-RFC
> > series, as they are things we could merge straight away regardless
> > of whether/when slirp becomes a separate library.
> >
> >> While looking at making SLIRP a seperate running process, I thought
> >> that having an independent library from QEMU would be a first step.
> >>
> >> There has been some attempts to make slirp a seperate project in the
> past.
> >> (https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg01092.html)
> >> Unfortunately, they forked from QEMU and didn't provide enough
> >> compatibility for QEMU to make use of it (in particular, vmstate
> >> handling was removed, they lost git history etc). Furthermore, they
> >> are not maintained as far as I can see.
> >
> > More recently there is this fun project which just pulled in the
> > QEMU code and chopped out everything todo with slirp:
> >
> >   https://github.com/rootless-containers/slirp4netns
>
> to give a little bit of background on slirp4netns:
>
> slirp4netns is used for setting up the network in a network namespace
> without requiring root privileges.
>
> It is already used by Podman and Buildah to set up the network for
> rootless containers, so they won't be limited to run in the host network
> namespace or require a suid helper.
>
> Coincidentally just today I was working on a slirp4netns change for
> spawning a QEMU process instead of using the forked version.
> I'd prefer to not rely on the slirp forked version, but this costs the
> access to the underlying knobs.  With a separate libslirp project, this
> is not needed anymore.
>
> One change I am aware of in the forked version is the possibility to
> tweak the MTU and AFAIK this is the only blocker from adopting libslirp
> immediately.
> Akihiro, is there anything more that could block slirp4netns from just
> using libslirp once it is available?
>
> Regards,
> Giuseppe
>

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 01/41] slirp: move socket pair creation in helper function
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 01/41] slirp: move socket pair creation in helper function Marc-André Lureau
@ 2018-11-19 22:46   ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-19 22:46 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, rjones, stefanha, renzo

Hello,

Marc-André Lureau, le mer. 14 nov. 2018 16:36:03 +0400, a ecrit:
> Originally, the patch was fixing a bunch of issues, but Peter beat me
> to it with earlier commit "slirp: fork_exec(): create and connect
> child socket before fork()".
> 
> Factor out socket pair creation, to simplify the fork_exec() code.
> Use the name socketpair_with_oob() since the code is actually similar
> to what socketpair() would do, except that it uses TCP sockets, for
> SLIRP to be able to call send with MSG_OOB (since SO_OOBINLINE is set,
> this could probably be faked instead on regular unix sockets though).
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Applied to my tree, thanks!

Samuel

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 02/41] glib-compat: add g_spawn_async_with_fds() fallback
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 02/41] glib-compat: add g_spawn_async_with_fds() fallback Marc-André Lureau
@ 2018-11-19 22:50   ` Samuel Thibault
  2018-11-20  6:11     ` Thomas Huth
  0 siblings, 1 reply; 137+ messages in thread
From: Samuel Thibault @ 2018-11-19 22:50 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, rjones, stefanha, renzo

Marc-André Lureau, le mer. 14 nov. 2018 16:36:04 +0400, a ecrit:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

include/glib-compat.h maintainers, may I keep this in my slirp tree, to
be pushed to master when appropriate?

Samuel

> ---
>  include/glib-compat.h | 56 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 56 insertions(+)
> 
> diff --git a/include/glib-compat.h b/include/glib-compat.h
> index fdf95a255d..8a078c5288 100644
> --- a/include/glib-compat.h
> +++ b/include/glib-compat.h
> @@ -83,6 +83,62 @@ static inline gboolean g_strv_contains_qemu(const gchar *const *strv,
>  }
>  #define g_strv_contains(a, b) g_strv_contains_qemu(a, b)
>  
> +#if !GLIB_CHECK_VERSION(2, 58, 0)
> +typedef struct QemuGSpawnFds {
> +    GSpawnChildSetupFunc child_setup;
> +    gpointer user_data;
> +    gint stdin_fd;
> +    gint stdout_fd;
> +    gint stderr_fd;
> +} QemuGSpawnFds;
> +
> +static inline void
> +qemu_gspawn_fds_setup(gpointer user_data)
> +{
> +    QemuGSpawnFds *q = (QemuGSpawnFds *)user_data;
> +
> +    dup2(q->stdin_fd, 0);
> +    dup2(q->stdout_fd, 1);
> +    dup2(q->stderr_fd, 2);
> +    q->child_setup(q->user_data);
> +}
> +#endif
> +
> +static inline gboolean
> +g_spawn_async_with_fds_qemu(const gchar *working_directory,
> +                            gchar **argv,
> +                            gchar **envp,
> +                            GSpawnFlags flags,
> +                            GSpawnChildSetupFunc child_setup,
> +                            gpointer user_data,
> +                            GPid *child_pid,
> +                            gint stdin_fd,
> +                            gint stdout_fd,
> +                            gint stderr_fd,
> +                            GError **error)
> +{
> +#if GLIB_CHECK_VERSION(2, 58, 0)
> +    return g_spawn_async_with_fds(working_directory, argv, envp, flags,
> +                                  child_setup, user_data,
> +                                  child_pid, stdin_fd, stdout_fd, stderr_fd,
> +                                  error);
> +#else
> +    QemuGSpawnFds setup = {
> +        .child_setup = child_setup,
> +        .user_data = user_data,
> +        .stdin_fd = stdin_fd,
> +        .stdout_fd = stdout_fd,
> +        .stderr_fd = stderr_fd,
> +    };
> +
> +    return g_spawn_async(working_directory, argv, envp, flags,
> +                         qemu_gspawn_fds_setup, &setup,
> +                         child_pid, error);
> +#endif
> +}
> +
> +#define g_spawn_async_with_fds(wd, argv, env, f, c, d, p, ifd, ofd, efd, err) \
> +    g_spawn_async_with_fds_qemu(wd, argv, env, f, c, d, p, ifd, ofd, efd, err)
>  
>  #if defined(_WIN32) && !GLIB_CHECK_VERSION(2, 50, 0)
>  /*
> -- 
> 2.19.1.708.g4ede3d42df
> 

-- 
Samuel
  bien sûr que ça convient mieux à tout le monde
  enfin, dans la mesure où tout le monde c'est comme moi
 -+- le consensus, c'est facile -+-

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 03/41] slirp: simplify fork_exec()
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 03/41] slirp: simplify fork_exec() Marc-André Lureau
  2018-11-14 14:22   ` Daniel P. Berrangé
@ 2018-11-19 22:56   ` Samuel Thibault
  1 sibling, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-19 22:56 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, rjones, stefanha, renzo

Marc-André Lureau, le mer. 14 nov. 2018 16:36:05 +0400, a ecrit:
> Use g_spawn_async_with_fds() to setup the child.
> 
> GSpawn handles reaping the child, and closing parent file descriptors.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Applied to my slirp-2 tree, thanks!

Samuel

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 03/41] slirp: simplify fork_exec()
  2018-11-14 14:22   ` Daniel P. Berrangé
@ 2018-11-19 22:59     ` Samuel Thibault
  2018-11-19 23:20       ` Eric Blake
  0 siblings, 1 reply; 137+ messages in thread
From: Samuel Thibault @ 2018-11-19 22:59 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Hello,

Daniel P. Berrangé, le mer. 14 nov. 2018 14:22:34 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:05PM +0400, Marc-André Lureau wrote:
> > Use g_spawn_async_with_fds() to setup the child.
> > 
> > GSpawn handles reaping the child, and closing parent file descriptors.
> 
> The g_spawn* family of APIs is portable to Win32, which the current
> fork/exec code in slirp is not.
> 
> So I'm curious if this conversion is sufficient to make this part
> of slirp work on Win32, or if further portability problems remain.
> If it does work on Win32, then you can also delete the stub
> fork_exec() impl the code currently has.

Mmm, I don't think any portability issue remains. SO_OOBINLINE is used
in other places, the rest is portable. There is the setsid() call which
may just not make sense on Windows, but we could just disable it there.

I have pushed to 

https://people.debian.org/~sthibault/qemu.git slirp-2-win

what it could look like. I don't have a windows box off hand, could
somebody try it to confirm that it builds?

Samuel

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 04/41] slirp: remove unused M_TRAILINGSPACE
  2018-11-14 13:32   ` Daniel P. Berrangé
@ 2018-11-19 23:01     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-19 23:01 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:32:57 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:06PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/mbuf.h | 1 -
> >  1 file changed, 1 deletion(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 05/41] slirp: use a callback structure to interface with qemu
  2018-11-14 13:10   ` Philippe Mathieu-Daudé
@ 2018-11-19 23:09     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-19 23:09 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Stefan Hajnoczi
  Cc: Marc-André Lureau, qemu-devel, rjones, renzo

Philippe Mathieu-Daudé, le mer. 14 nov. 2018 14:10:15 +0100, a ecrit:
> With the const qualifier:
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Stefan Hajnoczi, le mer. 14 nov. 2018 14:30:14 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:07PM +0400, Marc-André Lureau wrote:
> > -typedef void (*slirp_output)(void *opaque, const uint8_t *pkt, int pkt_len);
> > +typedef struct SlirpCb {
> > +    void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
> > +} SlirpCb;
> 
> Please include doc comments for each SlirpCb callback introduced by this
> series.  Otherwise it will be hard for other people to use libslirp.

I have added both and pushed to my tree, thanks!

Samuel

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 07/41] slirp: add clock_get_ns() callback
  2018-11-15 12:54   ` Paolo Bonzini
@ 2018-11-19 23:15     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-19 23:15 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Paolo Bonzini, le jeu. 15 nov. 2018 13:54:02 +0100, a ecrit:
> On 14/11/2018 13:36, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/libslirp.h |  6 ++++++
> >  net/slirp.c      | 19 +++++++++++++++++++
> >  slirp/if.c       |  2 +-
> >  slirp/ip6_icmp.c |  6 ++++--
> >  slirp/slirp.c    | 11 ++++++-----
> >  5 files changed, 36 insertions(+), 8 deletions(-)
> > 
> > diff --git a/slirp/libslirp.h b/slirp/libslirp.h
> > index 16ced2aa0f..fcebcd1e58 100644
> > --- a/slirp/libslirp.h
> > +++ b/slirp/libslirp.h
> > @@ -5,9 +5,15 @@
> >  
> >  typedef struct Slirp Slirp;
> >  
> > +typedef enum SlirpClockType {
> > +    SLIRP_CLOCK_VIRTUAL,
> > +    SLIRP_CLOCK_REALTIME,
> 
> The more I look at this, the more I think that SLIRP_CLOCK_REALTIME is
> wrong and it should also be using SLIRP_CLOCK_VIRTUAL.  It's used to put
> a cap on the amount of time the guest has to reply to an ARP request,
> and of course the guest cannot process it if it's paused.  So this can
> be simpler, because SlirpClockType can disappear completely.

Mmm, I'd tend to agree indeed.
(it's also used for TCP timers, but the same reasoning applies)

We'd need to check that turning them to VIRTUAL does work fine.

Samuel

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 10/41] slirp: remove PROBE_CONN dead-code
  2018-11-14 13:12   ` Philippe Mathieu-Daudé
@ 2018-11-19 23:17     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-19 23:17 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Philippe Mathieu-Daudé, le mer. 14 nov. 2018 14:12:04 +0100, a ecrit:
> On 14/11/18 13:36, Marc-André Lureau wrote:
> > Nobody cares for over 14y. Somebody can revert or rewrite if
> > interested by that.
> > 
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Daniel P. Berrangé, le mer. 14 nov. 2018 13:33:28 +0000, a ecrit:
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

Samuel

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 11/41] slirp: remove FULL_BOLT
  2018-11-14 13:46   ` Daniel P. Berrangé
@ 2018-11-19 23:18     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-19 23:18 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:46:02 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:13PM +0400, Marc-André Lureau wrote:
> > Looking at git history, this looks like something from the past, when
> > there was a tty layer. Let's remove it.
> > 
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/slirp_config.h | 7 -------
> >  slirp/if.c           | 2 --
> >  2 files changed, 9 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 12/41] slirp: remove the disabled readv()/writev() code path
  2018-11-14 13:46   ` Daniel P. Berrangé
@ 2018-11-19 23:19     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-19 23:19 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:46:46 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:14PM +0400, Marc-André Lureau wrote:
> > The soread() function may be used on datagram sockets, and would
> > provide different behaviour if HAVE_READV was set, on empty datagrams.
> > This looks like a minor optimization, that never has been a strong
> > goal for slirp.
> > 
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/slirp_config.h |  3 ---
> >  slirp/socket.c       | 15 ---------------
> >  2 files changed, 18 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 03/41] slirp: simplify fork_exec()
  2018-11-19 22:59     ` Samuel Thibault
@ 2018-11-19 23:20       ` Eric Blake
  0 siblings, 0 replies; 137+ messages in thread
From: Eric Blake @ 2018-11-19 23:20 UTC (permalink / raw)
  To: Samuel Thibault, Daniel P. Berrangé
  Cc: Marc-André Lureau, renzo, qemu-devel, stefanha, rjones

On 11/19/18 4:59 PM, Samuel Thibault wrote:
> Mmm, I don't think any portability issue remains. SO_OOBINLINE is used
> in other places, the rest is portable. There is the setsid() call which
> may just not make sense on Windows, but we could just disable it there.
> 
> I have pushed to
> 
> https://people.debian.org/~sthibault/qemu.git slirp-2-win
> 
> what it could look like. I don't have a windows box off hand, could
> somebody try it to confirm that it builds?

You could try 'make docker-test-mingw@fedora' to at least try building 
for a Windows environment (but that doesn't say much about testing the 
resulting binary).

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 13/41] slirp: remove HAVE_SYS_SIGNAL_H
  2018-11-14 13:47   ` Daniel P. Berrangé
@ 2018-11-20  0:58     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  0:58 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:47:32 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:15PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/slirp.h        | 3 ---
> >  slirp/slirp_config.h | 3 ---
> >  2 files changed, 6 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 14/41] slirp: remove unused HAVE_SYS_BITYPES_H
  2018-11-14 13:47   ` Daniel P. Berrangé
@ 2018-11-20  0:59     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  0:59 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:47:57 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:16PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/slirp.h        | 4 ----
> >  slirp/slirp_config.h | 3 ---
> >  2 files changed, 7 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 15/41] slirp: remove NO_UNIX_SOCKETS
  2018-11-14 13:48   ` Daniel P. Berrangé
@ 2018-11-20  0:59     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  0:59 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:48:37 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:17PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/slirp.h        | 3 ---
> >  slirp/slirp_config.h | 6 ------
> >  2 files changed, 9 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 16/41] slirp: remove unused HAVE_SYS_STROPTS_H
  2018-11-14 13:49   ` Daniel P. Berrangé
@ 2018-11-20  1:00     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:00 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:49:08 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:18PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/slirp.h        | 5 -----
> >  slirp/slirp_config.h | 3 ---
> >  2 files changed, 8 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 17/41] slirp: remove unused HAVE_ARPA_INET_H
  2018-11-14 13:50   ` Daniel P. Berrangé
@ 2018-11-20  1:01     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:01 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:50:01 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:19PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/slirp_config.h | 6 ------
> >  1 file changed, 6 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 18/41] slirp: remove unused HAVE_SYS_WAIT_H
  2018-11-14 13:50   ` Daniel P. Berrangé
@ 2018-11-20  1:01     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:01 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:50:33 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:20PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/slirp.h        | 4 ----
> >  slirp/slirp_config.h | 3 ---
> >  2 files changed, 7 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 19/41] slirp: remove unused HAVE_SYS_SELECT_H
  2018-11-14 13:51   ` Daniel P. Berrangé
@ 2018-11-20  1:02     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:02 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:51:01 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:21PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/main.h         | 4 ----
> >  slirp/slirp.h        | 4 ----
> >  slirp/slirp_config.h | 6 ------
> >  3 files changed, 14 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 20/41] slirp: remove HAVE_SYS_IOCTL_H
  2018-11-14 13:51   ` Daniel P. Berrangé
@ 2018-11-20  1:03     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:03 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:51:29 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:22PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/slirp.h        | 2 +-
> >  slirp/slirp_config.h | 6 ------
> >  2 files changed, 1 insertion(+), 7 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 21/41] slirp: remove HAVE_SYS_FILIO_H
  2018-11-14 13:52   ` Daniel P. Berrangé
@ 2018-11-20  1:04     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:04 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:52:12 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:23PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/slirp.h        | 2 +-
> >  slirp/slirp_config.h | 6 ------
> >  2 files changed, 1 insertion(+), 7 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 22/41] slirp: remove unused DECLARE_IOVEC
  2018-11-14 13:53   ` Daniel P. Berrangé
@ 2018-11-20  1:05     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:05 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:53:31 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:24PM +0400, Marc-André Lureau wrote:
> > It's actually qemu configure CONFIG_IOVEC that is being used.
> 
> That makes it sound like slirp is using CONFIG_IOVEC, but AFAICT
> that's only used by QEMU's osdep code.
> 
> > 
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/slirp_config.h | 6 ------
> >  1 file changed, 6 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 23/41] slirp: remove unused HAVE_INET_ATON
  2018-11-14 13:54   ` Daniel P. Berrangé
@ 2018-11-20  1:05     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:05 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:54:33 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:25PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/slirp_config.h | 6 ------
> >  1 file changed, 6 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 24/41] slirp: replace HOST_WORDS_BIGENDIAN with glib equivalent
  2018-11-14 13:14   ` Philippe Mathieu-Daudé
@ 2018-11-20  1:07     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:07 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Philippe Mathieu-Daudé, le mer. 14 nov. 2018 14:14:16 +0100, a ecrit:
> On 14/11/18 13:36, Marc-André Lureau wrote:
> > One more step towards making the project independent from QEMU.
> > 
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Daniel P. Berrangé, le mer. 14 nov. 2018 13:32:29 +0000, a ecrit:
>  Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

Samuel

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 25/41] slirp: replace SIZEOF_CHAR_P with glib equivalent
  2018-11-14 13:14   ` Philippe Mathieu-Daudé
@ 2018-11-20  1:08     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:08 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Philippe Mathieu-Daudé, le mer. 14 nov. 2018 14:14:35 +0100, a ecrit:
> On 14/11/18 13:36, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 26/41] slirp: replace compile time DO_KEEPALIVE
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 26/41] slirp: replace compile time DO_KEEPALIVE Marc-André Lureau
@ 2018-11-20  1:09   ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:09 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, rjones, stefanha, renzo

Marc-André Lureau, le mer. 14 nov. 2018 16:36:28 +0400, a ecrit:
> Use a global variable instead (similar to slirp_debug)
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 27/41] slirp: remove unused global slirp_instance
  2018-11-14 13:55   ` Daniel P. Berrangé
@ 2018-11-20  1:10     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:10 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 13:55:18 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:29PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/slirp.h | 2 --
> >  1 file changed, 2 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 28/41] slirp: replace error_report() with g_critical()
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 28/41] slirp: replace error_report() with g_critical() Marc-André Lureau
@ 2018-11-20  1:14   ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:14 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, rjones, stefanha, renzo

Marc-André Lureau, le mer. 14 nov. 2018 16:36:30 +0400, a ecrit:
> Reduce dependency on QEMU. QEMU could use a custom log handler if it
> wants to redirect/filter it.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 29/41] slirp: improve a bit the debug macros
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 29/41] slirp: improve a bit the debug macros Marc-André Lureau
  2018-11-14 14:04   ` Daniel P. Berrangé
@ 2018-11-20  1:19   ` Samuel Thibault
  1 sibling, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:19 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, rjones, stefanha, renzo

Marc-André Lureau, le mer. 14 nov. 2018 16:36:31 +0400, a ecrit:
> Let them accept multiple arguments. Simplify the inner argument
> handling of DEBUG_ARGS/DEBUG_MISC_DEBUG_ERROR.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 30/41] slirp: replace trace functions with DEBUG calls
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 30/41] slirp: replace trace functions with DEBUG calls Marc-André Lureau
@ 2018-11-20  1:21   ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:21 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, rjones, stefanha, renzo

Marc-André Lureau, le mer. 14 nov. 2018 16:36:32 +0400, a ecrit:
> Remove a dependency on QEMU. Use the existing logging facilities.

I'm hesitating on this one: this is not really a debugging print (as in
qemu debugging), but a real user debugging print. We do want to compile
this in without DEBUG defined.

Samuel

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 31/41] slirp: add a callback to log guest errors
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 31/41] slirp: add a callback to log guest errors Marc-André Lureau
@ 2018-11-20  1:27   ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:27 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, rjones, stefanha, renzo

Marc-André Lureau, le mer. 14 nov. 2018 16:36:33 +0400, a ecrit:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 34/41] slirp: remove #if notdef dead code
  2018-11-14 14:07   ` Daniel P. Berrangé
@ 2018-11-20  1:28     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:28 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 14:07:38 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:36PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/ip_input.c  | 200 ----------------------------------------------
> >  slirp/tcp_input.c |  39 ---------
> >  2 files changed, 239 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 32/41] slirp: remove unused sbflush()
  2018-11-14 14:05   ` Daniel P. Berrangé
@ 2018-11-20  1:28     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:28 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 14:05:33 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:34PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/sbuf.h | 1 -
> >  1 file changed, 1 deletion(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 33/41] slirp: replace qemu_notify_event() with a callback
  2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 33/41] slirp: replace qemu_notify_event() with a callback Marc-André Lureau
@ 2018-11-20  1:32   ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:32 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, rjones, stefanha, renzo

Marc-André Lureau, le mer. 14 nov. 2018 16:36:35 +0400, a ecrit:
> Use a "slirp socket" helper function to call the callback when
> sbdrop() returns true.

It's really far from clear what this should be doing :)

I'd say find out how to rephrase 86073017e384 ("slirp: Signal free input
buffer space to io-thread") in a generic way.

Samuel

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 35/41] slirp: NULL is defined by glib (at least)
  2018-11-14 14:11   ` Daniel P. Berrangé
@ 2018-11-20  1:33     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:33 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 14:11:34 +0000, a ecrit:
> NULL is defined in stddef.h for at least 15 years AFAICT, so
> even glib shouldn't bother to define it :-)  So I'd suggest
> changing $subject to just defer to stddef.h
> 
> On Wed, Nov 14, 2018 at 04:36:37PM +0400, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/slirp.h | 4 ----
> >  1 file changed, 4 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 36/41] slirp: remove dead TCP_ACK_HACK code
  2018-11-14 14:12   ` Daniel P. Berrangé
@ 2018-11-20  1:34     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:34 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Daniel P. Berrangé, le mer. 14 nov. 2018 14:12:06 +0000, a ecrit:
> On Wed, Nov 14, 2018 at 04:36:38PM +0400, Marc-André Lureau wrote:
> > Untouched since original introduction in 2004.
> > 
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/tcp_input.c | 23 +----------------------
> >  1 file changed, 1 insertion(+), 22 deletions(-)
> 
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS
  2018-11-14 13:17   ` Philippe Mathieu-Daudé
@ 2018-11-20  1:35     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:35 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Daniel P. Berrangé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Philippe Mathieu-Daudé, le mer. 14 nov. 2018 14:17:56 +0100, a ecrit:
> On 14/11/18 13:36, Marc-André Lureau wrote:
> > Do not require QEMU macro.
> > 
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Daniel P. Berrangé, le mer. 14 nov. 2018 14:15:15 +0000, a ecrit:
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 38/41] net: do not depend on slirp internals
  2018-11-14 13:21   ` Philippe Mathieu-Daudé
@ 2018-11-20  1:37     ` Samuel Thibault
  0 siblings, 0 replies; 137+ messages in thread
From: Samuel Thibault @ 2018-11-20  1:37 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Marc-André Lureau, qemu-devel, rjones, stefanha, renzo

Philippe Mathieu-Daudé, le mer. 14 nov. 2018 14:21:36 +0100, a ecrit:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Applied to my tree, thanks!

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 02/41] glib-compat: add g_spawn_async_with_fds() fallback
  2018-11-19 22:50   ` Samuel Thibault
@ 2018-11-20  6:11     ` Thomas Huth
  0 siblings, 0 replies; 137+ messages in thread
From: Thomas Huth @ 2018-11-20  6:11 UTC (permalink / raw)
  To: Samuel Thibault, Marc-André Lureau
  Cc: renzo, qemu-devel, stefanha, rjones, Daniel P. Berrangé

On 2018-11-19 23:50, Samuel Thibault wrote:
> Marc-André Lureau, le mer. 14 nov. 2018 16:36:04 +0400, a ecrit:
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> 
> include/glib-compat.h maintainers, may I keep this in my slirp tree, to
> be pushed to master when appropriate?

$ scripts/get_maintainer.pl -f include/glib-compat.h
get_maintainer.pl: No maintainers found [...]

... so I'd say yes, please just go ahead and queue this :-)

 Thomas

>> ---
>>  include/glib-compat.h | 56 +++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 56 insertions(+)
>>
>> diff --git a/include/glib-compat.h b/include/glib-compat.h
>> index fdf95a255d..8a078c5288 100644
>> --- a/include/glib-compat.h
>> +++ b/include/glib-compat.h
>> @@ -83,6 +83,62 @@ static inline gboolean g_strv_contains_qemu(const gchar *const *strv,
>>  }
>>  #define g_strv_contains(a, b) g_strv_contains_qemu(a, b)
>>  
>> +#if !GLIB_CHECK_VERSION(2, 58, 0)
>> +typedef struct QemuGSpawnFds {
>> +    GSpawnChildSetupFunc child_setup;
>> +    gpointer user_data;
>> +    gint stdin_fd;
>> +    gint stdout_fd;
>> +    gint stderr_fd;
>> +} QemuGSpawnFds;
>> +
>> +static inline void
>> +qemu_gspawn_fds_setup(gpointer user_data)
>> +{
>> +    QemuGSpawnFds *q = (QemuGSpawnFds *)user_data;
>> +
>> +    dup2(q->stdin_fd, 0);
>> +    dup2(q->stdout_fd, 1);
>> +    dup2(q->stderr_fd, 2);
>> +    q->child_setup(q->user_data);
>> +}
>> +#endif
>> +
>> +static inline gboolean
>> +g_spawn_async_with_fds_qemu(const gchar *working_directory,
>> +                            gchar **argv,
>> +                            gchar **envp,
>> +                            GSpawnFlags flags,
>> +                            GSpawnChildSetupFunc child_setup,
>> +                            gpointer user_data,
>> +                            GPid *child_pid,
>> +                            gint stdin_fd,
>> +                            gint stdout_fd,
>> +                            gint stderr_fd,
>> +                            GError **error)
>> +{
>> +#if GLIB_CHECK_VERSION(2, 58, 0)
>> +    return g_spawn_async_with_fds(working_directory, argv, envp, flags,
>> +                                  child_setup, user_data,
>> +                                  child_pid, stdin_fd, stdout_fd, stderr_fd,
>> +                                  error);
>> +#else
>> +    QemuGSpawnFds setup = {
>> +        .child_setup = child_setup,
>> +        .user_data = user_data,
>> +        .stdin_fd = stdin_fd,
>> +        .stdout_fd = stdout_fd,
>> +        .stderr_fd = stderr_fd,
>> +    };
>> +
>> +    return g_spawn_async(working_directory, argv, envp, flags,
>> +                         qemu_gspawn_fds_setup, &setup,
>> +                         child_pid, error);
>> +#endif
>> +}
>> +
>> +#define g_spawn_async_with_fds(wd, argv, env, f, c, d, p, ifd, ofd, efd, err) \
>> +    g_spawn_async_with_fds_qemu(wd, argv, env, f, c, d, p, ifd, ofd, efd, err)
>>  
>>  #if defined(_WIN32) && !GLIB_CHECK_VERSION(2, 50, 0)
>>  /*
>> -- 
>> 2.19.1.708.g4ede3d42df
>>
> 

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 09/41] slirp: add a set_nonblock() callback
  2018-11-15 13:03   ` Paolo Bonzini
@ 2018-11-21 21:02     ` Marc-André Lureau
  2018-11-22 13:09       ` Paolo Bonzini
  2019-01-15 19:22     ` Marc-André Lureau
  1 sibling, 1 reply; 137+ messages in thread
From: Marc-André Lureau @ 2018-11-21 21:02 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: QEMU, samuel.thibault, Richard W.M. Jones, Stefan Hajnoczi, renzo

Hi
On Thu, Nov 15, 2018 at 5:09 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 14/11/2018 13:36, Marc-André Lureau wrote:
> > qemu_set_nonblock() does some event registration with the main loop on
> > win32, let's have a callback.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> Perhaps a better interface would be register_poll_fd, which is called
> before a file descriptor can be returned to slirp_pollfds_fill?  And
> perhaps a dual unregister_poll_fd, which QEMU would leave empty, to be
> called before closing the file descriptor.

That sounds like a good idea, but I think it will bring more issues as
qemu_fd_register() doing WSAEventSelect will put the socket in
nonblocking mode anyway, and we don't have/need qemu_fd_unregister()
yet:

https://msdn.microsoft.com/de-de/library/windows/desktop/ms738573(v=vs.85).aspx
"The WSAAsyncSelect and WSAEventSelect functions automatically set a
socket to nonblocking mode. If WSAAsyncSelect or WSAEventSelect has
been issued on a socket, then any attempt to use ioctlsocket to set
the socket back to blocking mode will fail with WSAEINVAL.
To set the socket back to blocking mode, an application must first
disable WSAAsyncSelect by calling WSAAsyncSelect with the lEvent
parameter equal to zero, or disable WSAEventSelect by calling
WSAEventSelect with the lNetworkEvents parameter equal to zero."

I will stick to the set_nonblock() callback for now.

thanks



> Paolo
>
> > ---
> >  slirp/libslirp.h | 1 +
> >  net/slirp.c      | 1 +
> >  slirp/misc.c     | 2 +-
> >  slirp/tcp_subr.c | 4 ++--
> >  4 files changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/slirp/libslirp.h b/slirp/libslirp.h
> > index 88185e6c33..f2e7f94ebb 100644
> > --- a/slirp/libslirp.h
> > +++ b/slirp/libslirp.h
> > @@ -20,6 +20,7 @@ typedef struct SlirpCb {
> >                        SlirpTimerCb cb, void *opaque);
> >      void (*timer_free)(void *timer);
> >      void (*timer_mod)(void *timer, int64_t expire_timer);
> > +    void (*set_nonblock)(int fd);
> >  } SlirpCb;
> >
> >
> > diff --git a/net/slirp.c b/net/slirp.c
> > index 7b28886802..5ea8c255f6 100644
> > --- a/net/slirp.c
> > +++ b/net/slirp.c
> > @@ -190,6 +190,7 @@ static SlirpCb slirp_cb = {
> >      .timer_new = net_slirp_timer_new,
> >      .timer_free = net_slirp_timer_free,
> >      .timer_mod = net_slirp_timer_mod,
> > +    .set_nonblock = qemu_set_nonblock,
> >  };
> >
> >  static int net_slirp_init(NetClientState *peer, const char *model,
> > diff --git a/slirp/misc.c b/slirp/misc.c
> > index 7972b9b05b..dd2b3512a8 100644
> > --- a/slirp/misc.c
> > +++ b/slirp/misc.c
> > @@ -174,7 +174,7 @@ fork_exec(struct socket *so, const char *ex)
> >      socket_set_fast_reuse(so->s);
> >      opt = 1;
> >      qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
> > -    qemu_set_nonblock(so->s);
> > +    so->slirp->cb->set_nonblock(so->s);
> >      return 1;
> >  }
> >  #endif
> > diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
> > index 4b40850c7a..8d97f1f54e 100644
> > --- a/slirp/tcp_subr.c
> > +++ b/slirp/tcp_subr.c
> > @@ -412,7 +412,7 @@ int tcp_fconnect(struct socket *so, unsigned short af)
> >      int opt, s=so->s;
> >      struct sockaddr_storage addr;
> >
> > -    qemu_set_nonblock(s);
> > +    so->slirp->cb->set_nonblock(s);
> >      socket_set_fast_reuse(s);
> >      opt = 1;
> >      qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
> > @@ -484,7 +484,7 @@ void tcp_connect(struct socket *inso)
> >          tcp_close(sototcpcb(so)); /* This will sofree() as well */
> >          return;
> >      }
> > -    qemu_set_nonblock(s);
> > +    so->slirp->cb->set_nonblock(s);
> >      socket_set_fast_reuse(s);
> >      opt = 1;
> >      qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
> >
>
>


-- 
Marc-André Lureau

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 09/41] slirp: add a set_nonblock() callback
  2018-11-21 21:02     ` Marc-André Lureau
@ 2018-11-22 13:09       ` Paolo Bonzini
  0 siblings, 0 replies; 137+ messages in thread
From: Paolo Bonzini @ 2018-11-22 13:09 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: QEMU, samuel.thibault, Richard W.M. Jones, Stefan Hajnoczi, renzo

On 21/11/18 22:02, Marc-André Lureau wrote:
> Hi
> On Thu, Nov 15, 2018 at 5:09 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> On 14/11/2018 13:36, Marc-André Lureau wrote:
>>> qemu_set_nonblock() does some event registration with the main loop on
>>> win32, let's have a callback.
>>>
>>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>
>> Perhaps a better interface would be register_poll_fd, which is called
>> before a file descriptor can be returned to slirp_pollfds_fill?  And
>> perhaps a dual unregister_poll_fd, which QEMU would leave empty, to be
>> called before closing the file descriptor.
> 
> That sounds like a good idea, but I think it will bring more issues as
> qemu_fd_register() doing WSAEventSelect will put the socket in
> nonblocking mode anyway, and we don't have/need qemu_fd_unregister()
> yet:

Right, I was more thinking of other possible future clients of SLIRP.
But what you have now surely is fine.

(One possible way to work around the problem could be to put the socket
in non-blocking mode in SLIRP, since that is OS-dependent but not
client-dependent.  Then we can document that the register/unregister_fd
API is called with sockets that are already in non-blocking mode.  That
complicates the code a bit in order to have a nicer API).

Paolo

> https://msdn.microsoft.com/de-de/library/windows/desktop/ms738573(v=vs.85).aspx
> "The WSAAsyncSelect and WSAEventSelect functions automatically set a
> socket to nonblocking mode. If WSAAsyncSelect or WSAEventSelect has
> been issued on a socket, then any attempt to use ioctlsocket to set
> the socket back to blocking mode will fail with WSAEINVAL.
> To set the socket back to blocking mode, an application must first
> disable WSAAsyncSelect by calling WSAAsyncSelect with the lEvent
> parameter equal to zero, or disable WSAEventSelect by calling
> WSAEventSelect with the lNetworkEvents parameter equal to zero."
> 
> I will stick to the set_nonblock() callback for now.
> 
> thanks
> 
> 
> 
>> Paolo
>>
>>> ---
>>>  slirp/libslirp.h | 1 +
>>>  net/slirp.c      | 1 +
>>>  slirp/misc.c     | 2 +-
>>>  slirp/tcp_subr.c | 4 ++--
>>>  4 files changed, 5 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/slirp/libslirp.h b/slirp/libslirp.h
>>> index 88185e6c33..f2e7f94ebb 100644
>>> --- a/slirp/libslirp.h
>>> +++ b/slirp/libslirp.h
>>> @@ -20,6 +20,7 @@ typedef struct SlirpCb {
>>>                        SlirpTimerCb cb, void *opaque);
>>>      void (*timer_free)(void *timer);
>>>      void (*timer_mod)(void *timer, int64_t expire_timer);
>>> +    void (*set_nonblock)(int fd);
>>>  } SlirpCb;
>>>
>>>
>>> diff --git a/net/slirp.c b/net/slirp.c
>>> index 7b28886802..5ea8c255f6 100644
>>> --- a/net/slirp.c
>>> +++ b/net/slirp.c
>>> @@ -190,6 +190,7 @@ static SlirpCb slirp_cb = {
>>>      .timer_new = net_slirp_timer_new,
>>>      .timer_free = net_slirp_timer_free,
>>>      .timer_mod = net_slirp_timer_mod,
>>> +    .set_nonblock = qemu_set_nonblock,
>>>  };
>>>
>>>  static int net_slirp_init(NetClientState *peer, const char *model,
>>> diff --git a/slirp/misc.c b/slirp/misc.c
>>> index 7972b9b05b..dd2b3512a8 100644
>>> --- a/slirp/misc.c
>>> +++ b/slirp/misc.c
>>> @@ -174,7 +174,7 @@ fork_exec(struct socket *so, const char *ex)
>>>      socket_set_fast_reuse(so->s);
>>>      opt = 1;
>>>      qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
>>> -    qemu_set_nonblock(so->s);
>>> +    so->slirp->cb->set_nonblock(so->s);
>>>      return 1;
>>>  }
>>>  #endif
>>> diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
>>> index 4b40850c7a..8d97f1f54e 100644
>>> --- a/slirp/tcp_subr.c
>>> +++ b/slirp/tcp_subr.c
>>> @@ -412,7 +412,7 @@ int tcp_fconnect(struct socket *so, unsigned short af)
>>>      int opt, s=so->s;
>>>      struct sockaddr_storage addr;
>>>
>>> -    qemu_set_nonblock(s);
>>> +    so->slirp->cb->set_nonblock(s);
>>>      socket_set_fast_reuse(s);
>>>      opt = 1;
>>>      qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
>>> @@ -484,7 +484,7 @@ void tcp_connect(struct socket *inso)
>>>          tcp_close(sototcpcb(so)); /* This will sofree() as well */
>>>          return;
>>>      }
>>> -    qemu_set_nonblock(s);
>>> +    so->slirp->cb->set_nonblock(s);
>>>      socket_set_fast_reuse(s);
>>>      opt = 1;
>>>      qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
>>>
>>
>>
> 
> 

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 08/41] slirp: add callbacks for timer
  2018-11-15 12:56   ` Paolo Bonzini
@ 2019-01-15 19:21     ` Marc-André Lureau
  0 siblings, 0 replies; 137+ messages in thread
From: Marc-André Lureau @ 2019-01-15 19:21 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: qemu-devel, Samuel Thibault, Richard Jones, Stefan Hajnoczi, renzo

Hi

On Thu, Nov 15, 2018 at 4:56 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 14/11/2018 13:36, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/libslirp.h |  6 ++++++
> >  slirp/slirp.h    |  2 +-
> >  net/slirp.c      | 23 +++++++++++++++++++++++
> >  slirp/ip6_icmp.c | 21 ++++++++++-----------
> >  4 files changed, 40 insertions(+), 12 deletions(-)
> >
> > diff --git a/slirp/libslirp.h b/slirp/libslirp.h
> > index fcebcd1e58..88185e6c33 100644
> > --- a/slirp/libslirp.h
> > +++ b/slirp/libslirp.h
> > @@ -10,10 +10,16 @@ typedef enum SlirpClockType {
> >      SLIRP_CLOCK_REALTIME,
> >  } SlirpClockType;
> >
> > +typedef void (*SlirpTimerCb)(void *opaque);
> > +
> >  typedef struct SlirpCb {
> >      void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
> >      int (*chr_write_all)(void *chr, const void *buf, size_t len);
> >      int64_t (*clock_get_ns)(SlirpClockType type);
> > +    void *(*timer_new)(SlirpClockType type, int scale,
> > +                      SlirpTimerCb cb, void *opaque);
>
> Same here wrt SlirpClockType; and nicely, scale is always nanoseconds so
> it can be removed.

ack, done


>
> Paolo
>
> > +    void (*timer_free)(void *timer);
> > +    void (*timer_mod)(void *timer, int64_t expire_timer);
> >  } SlirpCb;
> >
> >
> > diff --git a/slirp/slirp.h b/slirp/slirp.h
> > index f7c087456a..e5abf1c594 100644
> > --- a/slirp/slirp.h
> > +++ b/slirp/slirp.h
> > @@ -218,7 +218,7 @@ struct Slirp {
> >      NdpTable ndp_table;
> >
> >      GRand *grand;
> > -    QEMUTimer *ra_timer;
> > +    void *ra_timer;
> >
> >      const SlirpCb *cb;
> >      void *opaque;
> > diff --git a/net/slirp.c b/net/slirp.c
> > index af6c643b82..7b28886802 100644
> > --- a/net/slirp.c
> > +++ b/net/slirp.c
> > @@ -163,10 +163,33 @@ static int64_t net_slirp_clock_get_ns(SlirpClockType type)
> >      return qemu_clock_get_ns(slirp_clock_to_qemu(type));
> >  }
> >
> > +static void *net_slirp_timer_new(SlirpClockType type,
> > +                                 int scale,
> > +                                 SlirpTimerCb cb, void *opaque)
> > +{
> > +    return timer_new_full(NULL, slirp_clock_to_qemu(type),
> > +                          scale, QEMU_TIMER_ATTR_EXTERNAL,
> > +                          cb, opaque);
> > +}
> > +
> > +static void net_slirp_timer_free(void *timer)
> > +{
> > +    timer_del(timer);
> > +    timer_free(timer);
> > +}
> > +
> > +static void net_slirp_timer_mod(void *timer, int64_t expire_timer)
> > +{
> > +    timer_mod(timer, expire_timer);
> > +}
> > +
> >  static SlirpCb slirp_cb = {
> >      .output = net_slirp_output,
> >      .chr_write_all = net_slirp_chr_write_all,
> >      .clock_get_ns = net_slirp_clock_get_ns,
> > +    .timer_new = net_slirp_timer_new,
> > +    .timer_free = net_slirp_timer_free,
> > +    .timer_mod = net_slirp_timer_mod,
> >  };
> >
> >  static int net_slirp_init(NetClientState *peer, const char *model,
> > diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
> > index 0f80d49ef9..71d95daef0 100644
> > --- a/slirp/ip6_icmp.c
> > +++ b/slirp/ip6_icmp.c
> > @@ -16,9 +16,10 @@
> >  static void ra_timer_handler(void *opaque)
> >  {
> >      Slirp *slirp = opaque;
> > -    timer_mod(slirp->ra_timer,
> > -              slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
> > -              NDP_Interval);
> > +
> > +    slirp->cb->timer_mod(slirp->ra_timer,
> > +        slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
> > +        NDP_Interval);
> >      ndp_send_ra(slirp);
> >  }
> >
> > @@ -28,12 +29,11 @@ void icmp6_init(Slirp *slirp)
> >          return;
> >      }
> >
> > -    slirp->ra_timer = timer_new_full(NULL, QEMU_CLOCK_VIRTUAL,
> > -                                     SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL,
> > -                                     ra_timer_handler, slirp);
> > -    timer_mod(slirp->ra_timer,
> > -              slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
> > -              NDP_Interval);
> > +    slirp->ra_timer = slirp->cb->timer_new(SLIRP_CLOCK_VIRTUAL, SCALE_MS,
> > +                                           ra_timer_handler, slirp);
> > +    slirp->cb->timer_mod(slirp->ra_timer,
> > +        slirp->cb->clock_get_ns(SLIRP_CLOCK_VIRTUAL) / SCALE_MS +
> > +        NDP_Interval);
> >  }
> >
> >  void icmp6_cleanup(Slirp *slirp)
> > @@ -42,8 +42,7 @@ void icmp6_cleanup(Slirp *slirp)
> >          return;
> >      }
> >
> > -    timer_del(slirp->ra_timer);
> > -    timer_free(slirp->ra_timer);
> > +    slirp->cb->timer_free(slirp->ra_timer);
> >  }
> >
> >  static void icmp6_send_echoreply(struct mbuf *m, Slirp *slirp, struct ip6 *ip,
> >
>

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 06/41] slirp: add a callback for qemu_chr_fe_write_all()
  2018-11-15 13:12   ` Paolo Bonzini
@ 2019-01-15 19:22     ` Marc-André Lureau
  0 siblings, 0 replies; 137+ messages in thread
From: Marc-André Lureau @ 2019-01-15 19:22 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: qemu-devel, Samuel Thibault, Richard Jones, Stefan Hajnoczi, renzo

Hi

On Thu, Nov 15, 2018 at 5:15 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 14/11/2018 13:36, Marc-André Lureau wrote:
> > Replace strong dependency on QEMU.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/libslirp.h | 1 +
> >  net/slirp.c      | 6 ++++++
> >  slirp/slirp.c    | 2 +-
> >  3 files changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/slirp/libslirp.h b/slirp/libslirp.h
> > index 36d5fb9163..16ced2aa0f 100644
> > --- a/slirp/libslirp.h
> > +++ b/slirp/libslirp.h
> > @@ -7,6 +7,7 @@ typedef struct Slirp Slirp;
> >
> >  typedef struct SlirpCb {
> >      void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
> > +    int (*chr_write_all)(void *chr, const void *buf, size_t len);
> >  } SlirpCb;
> >
> >
> > diff --git a/net/slirp.c b/net/slirp.c
> > index 233f66b1ef..5c1f676487 100644
> > --- a/net/slirp.c
> > +++ b/net/slirp.c
> > @@ -140,8 +140,14 @@ static NetClientInfo net_slirp_info = {
> >      .cleanup = net_slirp_cleanup,
> >  };
> >
> > +static int net_slirp_chr_write_all(void *chr, const void *buf, size_t len)
> > +{
> > +    return qemu_chr_fe_write_all(chr, buf, len);
> > +}
> > +
> >  static SlirpCb slirp_cb = {
> >      .output = net_slirp_output,
> > +    .chr_write_all = net_slirp_chr_write_all,
>
>
> >  };
> >
> >  static int net_slirp_init(NetClientState *peer, const char *model,
> > diff --git a/slirp/slirp.c b/slirp/slirp.c
> > index 7213915bf3..4e809e5d7f 100644
> > --- a/slirp/slirp.c
> > +++ b/slirp/slirp.c
> > @@ -1099,7 +1099,7 @@ ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags)
> >      if (so->s == -1 && so->chardev) {
> >          /* XXX this blocks entire thread. Rewrite to use
> >           * qemu_chr_fe_write and background I/O callbacks */
> > -        qemu_chr_fe_write_all(so->chardev, buf, len);
> > +        so->slirp->cb->chr_write_all(so->chardev, buf, len);
> >          return len;
> >      }
> >
> >
>
> Rather than this, I would split out add_exec's do_pty==3 case to a new
> function add_guestfwd, and pass the function pointer to add_guestfwd.  Then:
>
> 1) add_guestfwd can store the function pointer in struct ex_list,
>
> 2) tcp_ctl can store the ex_ptr in struct socket directly, instead of
> storing ex_ptr->ex_exec (that is the chardev field becomes "struct
> ex_list *guestfwd" or something)
>
> 3) slirp_send can use so->chardev to retrieve both the function pointer
> and the void* (renaming it to so->exec maybe)

Ok, please check the upcoming series, patch "slirp: generalize
guestfwd with a callback based approach". I think it is what you
propose here.

thanks

^ permalink raw reply	[flat|nested] 137+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.2 09/41] slirp: add a set_nonblock() callback
  2018-11-15 13:03   ` Paolo Bonzini
  2018-11-21 21:02     ` Marc-André Lureau
@ 2019-01-15 19:22     ` Marc-André Lureau
  1 sibling, 0 replies; 137+ messages in thread
From: Marc-André Lureau @ 2019-01-15 19:22 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: qemu-devel, Samuel Thibault, Richard Jones, Stefan Hajnoczi, renzo

Hi

On Thu, Nov 15, 2018 at 5:04 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 14/11/2018 13:36, Marc-André Lureau wrote:
> > qemu_set_nonblock() does some event registration with the main loop on
> > win32, let's have a callback.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> Perhaps a better interface would be register_poll_fd, which is called
> before a file descriptor can be returned to slirp_pollfds_fill?  And
> perhaps a dual unregister_poll_fd, which QEMU would leave empty, to be
> called before closing the file descriptor.

done

thanks

>
> Paolo
>
> > ---
> >  slirp/libslirp.h | 1 +
> >  net/slirp.c      | 1 +
> >  slirp/misc.c     | 2 +-
> >  slirp/tcp_subr.c | 4 ++--
> >  4 files changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/slirp/libslirp.h b/slirp/libslirp.h
> > index 88185e6c33..f2e7f94ebb 100644
> > --- a/slirp/libslirp.h
> > +++ b/slirp/libslirp.h
> > @@ -20,6 +20,7 @@ typedef struct SlirpCb {
> >                        SlirpTimerCb cb, void *opaque);
> >      void (*timer_free)(void *timer);
> >      void (*timer_mod)(void *timer, int64_t expire_timer);
> > +    void (*set_nonblock)(int fd);
> >  } SlirpCb;
> >
> >
> > diff --git a/net/slirp.c b/net/slirp.c
> > index 7b28886802..5ea8c255f6 100644
> > --- a/net/slirp.c
> > +++ b/net/slirp.c
> > @@ -190,6 +190,7 @@ static SlirpCb slirp_cb = {
> >      .timer_new = net_slirp_timer_new,
> >      .timer_free = net_slirp_timer_free,
> >      .timer_mod = net_slirp_timer_mod,
> > +    .set_nonblock = qemu_set_nonblock,
> >  };
> >
> >  static int net_slirp_init(NetClientState *peer, const char *model,
> > diff --git a/slirp/misc.c b/slirp/misc.c
> > index 7972b9b05b..dd2b3512a8 100644
> > --- a/slirp/misc.c
> > +++ b/slirp/misc.c
> > @@ -174,7 +174,7 @@ fork_exec(struct socket *so, const char *ex)
> >      socket_set_fast_reuse(so->s);
> >      opt = 1;
> >      qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
> > -    qemu_set_nonblock(so->s);
> > +    so->slirp->cb->set_nonblock(so->s);
> >      return 1;
> >  }
> >  #endif
> > diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
> > index 4b40850c7a..8d97f1f54e 100644
> > --- a/slirp/tcp_subr.c
> > +++ b/slirp/tcp_subr.c
> > @@ -412,7 +412,7 @@ int tcp_fconnect(struct socket *so, unsigned short af)
> >      int opt, s=so->s;
> >      struct sockaddr_storage addr;
> >
> > -    qemu_set_nonblock(s);
> > +    so->slirp->cb->set_nonblock(s);
> >      socket_set_fast_reuse(s);
> >      opt = 1;
> >      qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
> > @@ -484,7 +484,7 @@ void tcp_connect(struct socket *inso)
> >          tcp_close(sototcpcb(so)); /* This will sofree() as well */
> >          return;
> >      }
> > -    qemu_set_nonblock(s);
> > +    so->slirp->cb->set_nonblock(s);
> >      socket_set_fast_reuse(s);
> >      opt = 1;
> >      qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
> >
>

^ permalink raw reply	[flat|nested] 137+ messages in thread

end of thread, other threads:[~2019-01-15 19:34 UTC | newest]

Thread overview: 137+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-14 12:36 [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Marc-André Lureau
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 01/41] slirp: move socket pair creation in helper function Marc-André Lureau
2018-11-19 22:46   ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 02/41] glib-compat: add g_spawn_async_with_fds() fallback Marc-André Lureau
2018-11-19 22:50   ` Samuel Thibault
2018-11-20  6:11     ` Thomas Huth
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 03/41] slirp: simplify fork_exec() Marc-André Lureau
2018-11-14 14:22   ` Daniel P. Berrangé
2018-11-19 22:59     ` Samuel Thibault
2018-11-19 23:20       ` Eric Blake
2018-11-19 22:56   ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 04/41] slirp: remove unused M_TRAILINGSPACE Marc-André Lureau
2018-11-14 13:32   ` Daniel P. Berrangé
2018-11-19 23:01     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 05/41] slirp: use a callback structure to interface with qemu Marc-André Lureau
2018-11-14 13:10   ` Philippe Mathieu-Daudé
2018-11-19 23:09     ` Samuel Thibault
2018-11-14 14:30   ` Stefan Hajnoczi
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 06/41] slirp: add a callback for qemu_chr_fe_write_all() Marc-André Lureau
2018-11-15 13:12   ` Paolo Bonzini
2019-01-15 19:22     ` Marc-André Lureau
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 07/41] slirp: add clock_get_ns() callback Marc-André Lureau
2018-11-15 12:54   ` Paolo Bonzini
2018-11-19 23:15     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 08/41] slirp: add callbacks for timer Marc-André Lureau
2018-11-15 12:56   ` Paolo Bonzini
2019-01-15 19:21     ` Marc-André Lureau
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 09/41] slirp: add a set_nonblock() callback Marc-André Lureau
2018-11-15 13:03   ` Paolo Bonzini
2018-11-21 21:02     ` Marc-André Lureau
2018-11-22 13:09       ` Paolo Bonzini
2019-01-15 19:22     ` Marc-André Lureau
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 10/41] slirp: remove PROBE_CONN dead-code Marc-André Lureau
2018-11-14 13:12   ` Philippe Mathieu-Daudé
2018-11-19 23:17     ` Samuel Thibault
2018-11-14 13:33   ` Daniel P. Berrangé
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 11/41] slirp: remove FULL_BOLT Marc-André Lureau
2018-11-14 13:46   ` Daniel P. Berrangé
2018-11-19 23:18     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 12/41] slirp: remove the disabled readv()/writev() code path Marc-André Lureau
2018-11-14 13:46   ` Daniel P. Berrangé
2018-11-19 23:19     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 13/41] slirp: remove HAVE_SYS_SIGNAL_H Marc-André Lureau
2018-11-14 13:47   ` Daniel P. Berrangé
2018-11-20  0:58     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 14/41] slirp: remove unused HAVE_SYS_BITYPES_H Marc-André Lureau
2018-11-14 13:47   ` Daniel P. Berrangé
2018-11-20  0:59     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 15/41] slirp: remove NO_UNIX_SOCKETS Marc-André Lureau
2018-11-14 13:48   ` Daniel P. Berrangé
2018-11-20  0:59     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 16/41] slirp: remove unused HAVE_SYS_STROPTS_H Marc-André Lureau
2018-11-14 13:49   ` Daniel P. Berrangé
2018-11-20  1:00     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 17/41] slirp: remove unused HAVE_ARPA_INET_H Marc-André Lureau
2018-11-14 13:50   ` Daniel P. Berrangé
2018-11-20  1:01     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 18/41] slirp: remove unused HAVE_SYS_WAIT_H Marc-André Lureau
2018-11-14 13:50   ` Daniel P. Berrangé
2018-11-20  1:01     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 19/41] slirp: remove unused HAVE_SYS_SELECT_H Marc-André Lureau
2018-11-14 13:51   ` Daniel P. Berrangé
2018-11-20  1:02     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 20/41] slirp: remove HAVE_SYS_IOCTL_H Marc-André Lureau
2018-11-14 13:51   ` Daniel P. Berrangé
2018-11-20  1:03     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 21/41] slirp: remove HAVE_SYS_FILIO_H Marc-André Lureau
2018-11-14 13:52   ` Daniel P. Berrangé
2018-11-20  1:04     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 22/41] slirp: remove unused DECLARE_IOVEC Marc-André Lureau
2018-11-14 13:53   ` Daniel P. Berrangé
2018-11-20  1:05     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 23/41] slirp: remove unused HAVE_INET_ATON Marc-André Lureau
2018-11-14 13:54   ` Daniel P. Berrangé
2018-11-20  1:05     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 24/41] slirp: replace HOST_WORDS_BIGENDIAN with glib equivalent Marc-André Lureau
2018-11-14 13:14   ` Philippe Mathieu-Daudé
2018-11-20  1:07     ` Samuel Thibault
2018-11-14 13:32   ` Daniel P. Berrangé
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 25/41] slirp: replace SIZEOF_CHAR_P " Marc-André Lureau
2018-11-14 13:14   ` Philippe Mathieu-Daudé
2018-11-20  1:08     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 26/41] slirp: replace compile time DO_KEEPALIVE Marc-André Lureau
2018-11-20  1:09   ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 27/41] slirp: remove unused global slirp_instance Marc-André Lureau
2018-11-14 13:55   ` Daniel P. Berrangé
2018-11-20  1:10     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 28/41] slirp: replace error_report() with g_critical() Marc-André Lureau
2018-11-20  1:14   ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 29/41] slirp: improve a bit the debug macros Marc-André Lureau
2018-11-14 14:04   ` Daniel P. Berrangé
2018-11-14 20:51     ` Marc-André Lureau
2018-11-20  1:19   ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 30/41] slirp: replace trace functions with DEBUG calls Marc-André Lureau
2018-11-20  1:21   ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 31/41] slirp: add a callback to log guest errors Marc-André Lureau
2018-11-20  1:27   ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 32/41] slirp: remove unused sbflush() Marc-André Lureau
2018-11-14 14:05   ` Daniel P. Berrangé
2018-11-20  1:28     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 33/41] slirp: replace qemu_notify_event() with a callback Marc-André Lureau
2018-11-20  1:32   ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 34/41] slirp: remove #if notdef dead code Marc-André Lureau
2018-11-14 14:07   ` Daniel P. Berrangé
2018-11-20  1:28     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 35/41] slirp: NULL is defined by glib (at least) Marc-André Lureau
2018-11-14 14:11   ` Daniel P. Berrangé
2018-11-20  1:33     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 36/41] slirp: remove dead TCP_ACK_HACK code Marc-André Lureau
2018-11-14 14:12   ` Daniel P. Berrangé
2018-11-20  1:34     ` Samuel Thibault
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS Marc-André Lureau
2018-11-14 13:17   ` Philippe Mathieu-Daudé
2018-11-20  1:35     ` Samuel Thibault
2018-11-14 14:15   ` Daniel P. Berrangé
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 38/41] net: do not depend on slirp internals Marc-André Lureau
2018-11-14 13:21   ` Philippe Mathieu-Daudé
2018-11-20  1:37     ` Samuel Thibault
2018-11-15 13:19   ` Paolo Bonzini
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 39/41] slirp: move QEMU state saving to a separate unit Marc-André Lureau
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 40/41] slirp: replace remaining QEMU dependency Marc-André Lureau
2018-11-14 12:36 ` [Qemu-devel] [PATCH for-3.2 41/41] build-sys: add a basic meson build Marc-André Lureau
2018-11-14 12:59 ` [Qemu-devel] [PATCH for-3.2 00/41] RFC: slirp: make it again a standalone project Markus Armbruster
2018-11-14 13:20   ` Richard W.M. Jones
2018-11-14 13:33   ` Thomas Huth
2018-11-14 14:46     ` Markus Armbruster
2018-11-14 15:10       ` Dr. David Alan Gilbert
2018-11-14 15:14       ` Richard W.M. Jones
2018-11-14 16:52       ` Thomas Huth
2018-11-14 17:51         ` Markus Armbruster
2018-11-14 18:14           ` Dr. David Alan Gilbert
2018-11-14 13:45 ` Daniel P. Berrangé
2018-11-15 16:49   ` Giuseppe Scrivano
2018-11-16  5:09     ` Akihiro Suda
2018-11-14 14:26 ` Stefan Hajnoczi
2018-11-14 14:30   ` Daniel P. Berrangé
2018-11-14 15:26     ` Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.