Skip to contentSkip to conversation

RFC: slirp: make it again a standalone project

PATCH Applied Marc-André Lureau 14 participants 137 messages Nov 14, 2018 – Jan 15, 2019

Subsystems (3)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover RFC: slirp: make it again a standalone project

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
Signature · 1 line
2.19.1.708.g4ede3d42df
#1 lore raw

PATCH 1/41 slirp: move socket pair creation in helper function

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).

---
 slirp/misc.c | 142 +++++++++++++++++++++++++--------------------------
 1 file changed, 71 insertions(+), 71 deletions(-)
slirp/misc.c +71 -71
index 4840187750..7362e14339 100644
@@ -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;
 	}
Signature · 1 line
2.19.1.708.g4ede3d42df
#2 lore raw

Re: [Qemu-devel] [PATCH for-3.2 01/41] slirp: move socket pair creation in helper function

Hello,

Marc-André Lureau, le mer. 14 nov. 2018 16:36:03 +0400, a ecrit:

Quoted 11 lines

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).

Applied to my tree, thanks!

Samuel

#3 lore raw

PATCH 2/41 glib-compat: add g_spawn_async_with_fds() fallback

In reply to Marc-André Lureau
---
 include/glib-compat.h | 56 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
include/glib-compat.h +56 -0
index fdf95a255d..8a078c5288 100644
@@ -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)
 /*
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 2/41
#4 lore raw

Re: [Qemu-devel] [PATCH for-3.2 02/41] glib-compat: add g_spawn_async_with_fds() fallback

Marc-André Lureau, le mer. 14 nov. 2018 16:36:04 +0400, a ecrit:

Quoted 1 line

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

Samuel

Quoted 74 lines
---
 include/glib-compat.h | 56 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
include/glib-compat.h +56 -0
index fdf95a255d..8a078c5288 100644
@@ -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)
 /*
Signature · 1 line
2.19.1.708.g4ede3d42df
Signature · 4 lines
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 -+-
#5 lore raw

Re: [Qemu-devel] [PATCH for-3.2 02/41] glib-compat: add g_spawn_async_with_fds() fallback

Quoted 7 lines · Samuel Thibault

Marc-André Lureau, le mer. 14 nov. 2018 16:36:04 +0400, a ecrit:

Quoted 1 line

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

Quoted 75 lines
Quoted 74 lines
---
 include/glib-compat.h | 56 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
include/glib-compat.h +56 -0
index fdf95a255d..8a078c5288 100644
@@ -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)
 /*
Signature · 1 line
2.19.1.708.g4ede3d42df
#6 lore raw

PATCH 3/41 slirp: simplify fork_exec()

In reply to Marc-André Lureau

Use g_spawn_async_with_fds() to setup the child.

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

---
 slirp/misc.c | 75 +++++++++++++++++++++++++---------------------------
 1 file changed, 36 insertions(+), 39 deletions(-)
slirp/misc.c +36 -39
index 7362e14339..7972b9b05b 100644
@@ -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
 
Signature · 1 line
2.19.1.708.g4ede3d42df
#7 lore raw

Re: [Qemu-devel] [PATCH for-3.2 03/41] slirp: simplify fork_exec()

Quoted 3 lines · Marc-André Lureau

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.

Quoted 107 lines
---
 slirp/misc.c | 75 +++++++++++++++++++++++++---------------------------
 1 file changed, 36 insertions(+), 39 deletions(-)
slirp/misc.c +36 -39
index 7362e14339..7972b9b05b 100644
@@ -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
 
Signature · 1 line
2.19.1.708.g4ede3d42df

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#8 lore raw

Re: [Qemu-devel] [PATCH for-3.2 03/41] slirp: simplify fork_exec()

Hello,

Daniel P. Berrangé, le mer. 14 nov. 2018 14:22:34 +0000, a ecrit:

Quoted 5 lines · Marc-André Lureau
Quoted 3 lines

Use g_spawn_async_with_fds() to setup the child.

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

Quoted 7 lines

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

#9 lore raw

Re: [Qemu-devel] [PATCH for-3.2 03/41] slirp: simplify fork_exec()

Quoted 10 lines · Samuel Thibault

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).

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#11 lore raw

PATCH 4/41 slirp: remove unused M_TRAILINGSPACE

In reply to Marc-André Lureau
---
 slirp/mbuf.h | 1 -
 1 file changed, 1 deletion(-)
slirp/mbuf.h +0 -1
index bfdf8c4577..cbf17e136b 100644
@@ -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! */
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 4/41
#12 lore raw

Re: [Qemu-devel] [PATCH for-3.2 04/41] slirp: remove unused M_TRAILINGSPACE

Quoted 4 lines · Marc-André Lureau
---
 slirp/mbuf.h | 1 -
 1 file changed, 1 deletion(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#14 lore raw

PATCH 5/41 slirp: use a callback structure to interface with qemu

In reply to 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".

---
 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(-)
slirp/libslirp.h +5 -2
index 04b6db9f49..36d5fb9163 100644
@@ -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);
 
slirp/slirp.h +1 -1
index de299aa36c..f7c087456a 100644
@@ -220,7 +220,7 @@ struct Slirp {
     GRand *grand;
     QEMUTimer *ra_timer;
 
-    slirp_output output;
+    const SlirpCb *cb;
     void *opaque;
 };
 
net/slirp.c +5 -1
index dfc72cfc2e..233f66b1ef 100644
@@ -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) {
slirp/ncsi.c +1 -1
index d7701f7785..10decfb5ef 100644
@@ -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);
 }
slirp/slirp.c +5 -5
index 0e4ade3e4a..7213915bf3 100644
@@ -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;
 }
 
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 5/41
#15 lore raw

Re: [Qemu-devel] [PATCH for-3.2 05/41] slirp: use a callback structure to interface with qemu

Quoted 58 lines · 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".

---
  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(-)
slirp/libslirp.h +5 -2
index 04b6db9f49..36d5fb9163 100644
@@ -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);
 
slirp/slirp.h +1 -1
index de299aa36c..f7c087456a 100644
@@ -220,7 +220,7 @@ struct Slirp {
      GRand *grand;
      QEMUTimer *ra_timer;
 
-    slirp_output output;
+    const SlirpCb *cb;
      void *opaque;
  };
 
net/slirp.c +0 -0
index dfc72cfc2e..233f66b1ef 100644

net/slirp.c static NetClientInfo net_slirp_info = { · line 143

Quoted 4 lines
net/slirp.c +1 -0
@@ -140,6 +140,10 @@ static NetClientInfo net_slirp_info = {
      .cleanup = net_slirp_cleanup,
  };
 
+static SlirpCb slirp_cb = {

const ^

With the const qualifier:

Quoted 75 lines
net/slirp.c +4 -1
+    .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) {
slirp/ncsi.c +1 -1
index d7701f7785..10decfb5ef 100644
@@ -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);
  }
slirp/slirp.c +5 -5
index 0e4ade3e4a..7213915bf3 100644
@@ -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;
  }
 
#16 lore raw

Re: [Qemu-devel] [PATCH for-3.2 05/41] slirp: use a callback structure to interface with qemu

In reply to Marc-André Lureau

slirp/libslirp.h line 10

Quoted 4 lines · Marc-André Lureau
slirp/libslirp.h +3 -1
-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

#17 lore raw

Re: [Qemu-devel] [PATCH for-3.2 05/41] slirp: use a callback structure to interface with qemu

Philippe Mathieu-Daudé, le mer. 14 nov. 2018 14:10:15 +0100, a ecrit:

Quoted 2 lines

With the const qualifier:

Stefan Hajnoczi, le mer. 14 nov. 2018 14:30:14 +0000, a ecrit:

Quoted 8 lines · Marc-André Lureau

slirp/libslirp.h line 10

Quoted 4 lines
slirp/libslirp.h +3 -1
-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

#18 lore raw

PATCH 6/41 slirp: add a callback for qemu_chr_fe_write_all()

In reply to Marc-André Lureau

Replace strong dependency on QEMU.

---
 slirp/libslirp.h | 1 +
 net/slirp.c      | 6 ++++++
 slirp/slirp.c    | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)
slirp/libslirp.h +1 -0
index 36d5fb9163..16ced2aa0f 100644
@@ -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;
 
 
net/slirp.c +6 -0
index 233f66b1ef..5c1f676487 100644
@@ -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,
slirp/slirp.c +1 -1
index 7213915bf3..4e809e5d7f 100644
@@ -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;
     }
 
Signature · 1 line
2.19.1.708.g4ede3d42df
#19 lore raw

Re: [Qemu-devel] [PATCH for-3.2 06/41] slirp: add a callback for qemu_chr_fe_write_all()

Quoted 48 lines · Marc-André Lureau

Replace strong dependency on QEMU.

---
 slirp/libslirp.h | 1 +
 net/slirp.c      | 6 ++++++
 slirp/slirp.c    | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)
slirp/libslirp.h +1 -0
index 36d5fb9163..16ced2aa0f 100644
@@ -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;
 
 
net/slirp.c +6 -0
index 233f66b1ef..5c1f676487 100644
@@ -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,

slirp/slirp.c +0 -0
index 7213915bf3..4e809e5d7f 100644

slirp/slirp.c ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags) · line 1105

Quoted 8 lines
slirp/slirp.c +1 -1
@@ -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

#20 lore raw

Re: [Qemu-devel] [PATCH for-3.2 06/41] slirp: add a callback for qemu_chr_fe_write_all()

Hi

Quoted 62 lines · Paolo Bonzini
Quoted 48 lines · Marc-André Lureau

Replace strong dependency on QEMU.

---
 slirp/libslirp.h | 1 +
 net/slirp.c      | 6 ++++++
 slirp/slirp.c    | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)
slirp/libslirp.h +1 -0
index 36d5fb9163..16ced2aa0f 100644
@@ -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;
 
 
net/slirp.c +6 -0
index 233f66b1ef..5c1f676487 100644
@@ -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,

slirp/slirp.c +0 -0
index 7213915bf3..4e809e5d7f 100644

slirp/slirp.c ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags) · line 1105

Quoted 8 lines
slirp/slirp.c +1 -1
@@ -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:

Quoted 8 lines

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

#21 lore raw

PATCH 7/41 slirp: add clock_get_ns() callback

In reply to Marc-André Lureau
---
 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(-)
slirp/libslirp.h +6 -0
index 16ced2aa0f..fcebcd1e58 100644
@@ -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;
 
 
net/slirp.c +19 -0
index 5c1f676487..af6c643b82 100644
@@ -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,
slirp/if.c +1 -1
index 590753c658..1c96869831 100644
@@ -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;
 
slirp/ip6_icmp.c +4 -2
index cd1e0b9fe1..0f80d49ef9 100644
@@ -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)
slirp/slirp.c +6 -5
index 4e809e5d7f..979495e88b 100644
@@ -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 {
Signature · 1 line
2.19.1.708.g4ede3d42df
#22 lore raw

Re: [Qemu-devel] [PATCH for-3.2 07/41] slirp: add clock_get_ns() callback

Quoted 14 lines · Marc-André Lureau
---
 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(-)
slirp/libslirp.h +0 -0
index 16ced2aa0f..fcebcd1e58 100644

slirp/libslirp.h line 10

Quoted 6 lines
slirp/libslirp.h +3 -0
@@ -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

Quoted 122 lines
slirp/libslirp.h +3 -0
+} 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;
 
 
net/slirp.c +19 -0
index 5c1f676487..af6c643b82 100644
@@ -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,
slirp/if.c +1 -1
index 590753c658..1c96869831 100644
@@ -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;
 
slirp/ip6_icmp.c +4 -2
index cd1e0b9fe1..0f80d49ef9 100644
@@ -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)
slirp/slirp.c +6 -5
index 4e809e5d7f..979495e88b 100644
@@ -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 {
#23 lore raw

Re: [Qemu-devel] [PATCH for-3.2 07/41] slirp: add clock_get_ns() callback

Paolo Bonzini, le jeu. 15 nov. 2018 13:54:02 +0100, a ecrit:

Quoted 18 lines · Marc-André Lureau
Quoted 17 lines
---
 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(-)
slirp/libslirp.h +0 -0
index 16ced2aa0f..fcebcd1e58 100644
@@ -5,9 +5,15 @@
 
 typedef struct Slirp Slirp;
 
Quoted 9 lines

slirp/libslirp.h line 10

Quoted 3 lines
slirp/libslirp.h +3 -0
+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

#24 lore raw

PATCH 8/41 slirp: add callbacks for timer

In reply to Marc-André Lureau
---
 slirp/libslirp.h |  6 ++++++
 slirp/slirp.h    |  2 +-
 net/slirp.c      | 23 +++++++++++++++++++++++
 slirp/ip6_icmp.c | 21 ++++++++++-----------
 4 files changed, 40 insertions(+), 12 deletions(-)
slirp/libslirp.h +6 -0
index fcebcd1e58..88185e6c33 100644
@@ -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;
 
 
slirp/slirp.h +1 -1
index f7c087456a..e5abf1c594 100644
@@ -218,7 +218,7 @@ struct Slirp {
     NdpTable ndp_table;
 
     GRand *grand;
-    QEMUTimer *ra_timer;
+    void *ra_timer;
 
     const SlirpCb *cb;
     void *opaque;
net/slirp.c +23 -0
index af6c643b82..7b28886802 100644
@@ -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,
slirp/ip6_icmp.c +10 -11
index 0f80d49ef9..71d95daef0 100644
@@ -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,
Signature · 1 line
2.19.1.708.g4ede3d42df
#25 lore raw

Re: [Qemu-devel] [PATCH for-3.2 08/41] slirp: add callbacks for timer

Quoted 14 lines · Marc-André Lureau
---
 slirp/libslirp.h |  6 ++++++
 slirp/slirp.h    |  2 +-
 net/slirp.c      | 23 +++++++++++++++++++++++
 slirp/ip6_icmp.c | 21 ++++++++++-----------
 4 files changed, 40 insertions(+), 12 deletions(-)
slirp/libslirp.h +0 -0
index fcebcd1e58..88185e6c33 100644
@@ -10,10 +10,16 @@ typedef enum SlirpClockType {
     SLIRP_CLOCK_REALTIME,

slirp/libslirp.h typedef enum SlirpClockType { · line 20

Quoted 10 lines
slirp/libslirp.h +4 -0
 } 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

Quoted 103 lines
slirp/libslirp.h +2 -0
+    void (*timer_free)(void *timer);
+    void (*timer_mod)(void *timer, int64_t expire_timer);
 } SlirpCb;
 
 
slirp/slirp.h +1 -1
index f7c087456a..e5abf1c594 100644
@@ -218,7 +218,7 @@ struct Slirp {
     NdpTable ndp_table;
 
     GRand *grand;
-    QEMUTimer *ra_timer;
+    void *ra_timer;
 
     const SlirpCb *cb;
     void *opaque;
net/slirp.c +23 -0
index af6c643b82..7b28886802 100644
@@ -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,
slirp/ip6_icmp.c +10 -11
index 0f80d49ef9..71d95daef0 100644
@@ -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,
#26 lore raw

Re: [Qemu-devel] [PATCH for-3.2 08/41] slirp: add callbacks for timer

Hi

Quoted 18 lines · Paolo Bonzini
Quoted 16 lines · Marc-André Lureau
---
 slirp/libslirp.h |  6 ++++++
 slirp/slirp.h    |  2 +-
 net/slirp.c      | 23 +++++++++++++++++++++++
 slirp/ip6_icmp.c | 21 ++++++++++-----------
 4 files changed, 40 insertions(+), 12 deletions(-)
slirp/libslirp.h +0 -0
index fcebcd1e58..88185e6c33 100644
@@ -10,10 +10,16 @@ typedef enum SlirpClockType {
     SLIRP_CLOCK_REALTIME,
 } SlirpClockType;
 
Quoted 11 lines

slirp/libslirp.h typedef enum SlirpClockType { · line 20

Quoted 8 lines
slirp/libslirp.h +4 -0
+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

Quoted 107 lines

Paolo

Quoted 103 lines
slirp/libslirp.h +2 -0
+    void (*timer_free)(void *timer);
+    void (*timer_mod)(void *timer, int64_t expire_timer);
 } SlirpCb;
 
 
slirp/slirp.h +1 -1
index f7c087456a..e5abf1c594 100644
@@ -218,7 +218,7 @@ struct Slirp {
     NdpTable ndp_table;
 
     GRand *grand;
-    QEMUTimer *ra_timer;
+    void *ra_timer;
 
     const SlirpCb *cb;
     void *opaque;
net/slirp.c +23 -0
index af6c643b82..7b28886802 100644
@@ -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,
slirp/ip6_icmp.c +10 -11
index 0f80d49ef9..71d95daef0 100644
@@ -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,
#27 lore raw

PATCH 9/41 slirp: add a set_nonblock() callback

In reply to Marc-André Lureau

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

---
 slirp/libslirp.h | 1 +
 net/slirp.c      | 1 +
 slirp/misc.c     | 2 +-
 slirp/tcp_subr.c | 4 ++--
 4 files changed, 5 insertions(+), 3 deletions(-)
slirp/libslirp.h +1 -0
index 88185e6c33..f2e7f94ebb 100644
@@ -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;
 
 
net/slirp.c +1 -0
index 7b28886802..5ea8c255f6 100644
@@ -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,
slirp/misc.c +1 -1
index 7972b9b05b..dd2b3512a8 100644
@@ -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
slirp/tcp_subr.c +2 -2
index 4b40850c7a..8d97f1f54e 100644
@@ -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));
Signature · 1 line
2.19.1.708.g4ede3d42df
#28 lore raw

Re: [Qemu-devel] [PATCH for-3.2 09/41] slirp: add a set_nonblock() callback

Quoted 4 lines · Marc-André Lureau

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

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

Quoted 67 lines
---
 slirp/libslirp.h | 1 +
 net/slirp.c      | 1 +
 slirp/misc.c     | 2 +-
 slirp/tcp_subr.c | 4 ++--
 4 files changed, 5 insertions(+), 3 deletions(-)
slirp/libslirp.h +1 -0
index 88185e6c33..f2e7f94ebb 100644
@@ -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;
 
 
net/slirp.c +1 -0
index 7b28886802..5ea8c255f6 100644
@@ -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,
slirp/misc.c +1 -1
index 7972b9b05b..dd2b3512a8 100644
@@ -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
slirp/tcp_subr.c +2 -2
index 4b40850c7a..8d97f1f54e 100644
@@ -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));
#29 lore raw

Re: [Qemu-devel] [PATCH for-3.2 09/41] slirp: add a set_nonblock() callback

Hi

Quoted 11 lines · Paolo Bonzini
Quoted 4 lines · Marc-André Lureau

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

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

Quoted 71 lines

Paolo

Quoted 67 lines
---
 slirp/libslirp.h | 1 +
 net/slirp.c      | 1 +
 slirp/misc.c     | 2 +-
 slirp/tcp_subr.c | 4 ++--
 4 files changed, 5 insertions(+), 3 deletions(-)
slirp/libslirp.h +1 -0
index 88185e6c33..f2e7f94ebb 100644
@@ -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;
 
 
net/slirp.c +1 -0
index 7b28886802..5ea8c255f6 100644
@@ -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,
slirp/misc.c +1 -1
index 7972b9b05b..dd2b3512a8 100644
@@ -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
slirp/tcp_subr.c +2 -2
index 4b40850c7a..8d97f1f54e 100644
@@ -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));
Signature · 1 line
Marc-André Lureau
#30 lore raw

Re: [Qemu-devel] [PATCH for-3.2 09/41] slirp: add a set_nonblock() callback

Quoted 14 lines · Marc-André Lureau

Hi

Quoted 11 lines · Paolo Bonzini
Quoted 4 lines · Marc-André Lureau

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

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.

Quoted 4 lines

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

Quoted 89 lines

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

Quoted 71 lines

Paolo

Quoted 67 lines
---
 slirp/libslirp.h | 1 +
 net/slirp.c      | 1 +
 slirp/misc.c     | 2 +-
 slirp/tcp_subr.c | 4 ++--
 4 files changed, 5 insertions(+), 3 deletions(-)
slirp/libslirp.h +1 -0
index 88185e6c33..f2e7f94ebb 100644
@@ -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;
 
 
net/slirp.c +1 -0
index 7b28886802..5ea8c255f6 100644
@@ -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,
slirp/misc.c +1 -1
index 7972b9b05b..dd2b3512a8 100644
@@ -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
slirp/tcp_subr.c +2 -2
index 4b40850c7a..8d97f1f54e 100644
@@ -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));
#31 lore raw

Re: [Qemu-devel] [PATCH for-3.2 09/41] slirp: add a set_nonblock() callback

In reply to Paolo Bonzini

Hi

Quoted 11 lines · Paolo Bonzini
Quoted 4 lines · Marc-André Lureau

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

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

Quoted 71 lines

Paolo

Quoted 67 lines
---
 slirp/libslirp.h | 1 +
 net/slirp.c      | 1 +
 slirp/misc.c     | 2 +-
 slirp/tcp_subr.c | 4 ++--
 4 files changed, 5 insertions(+), 3 deletions(-)
slirp/libslirp.h +1 -0
index 88185e6c33..f2e7f94ebb 100644
@@ -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;
 
 
net/slirp.c +1 -0
index 7b28886802..5ea8c255f6 100644
@@ -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,
slirp/misc.c +1 -1
index 7972b9b05b..dd2b3512a8 100644
@@ -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
slirp/tcp_subr.c +2 -2
index 4b40850c7a..8d97f1f54e 100644
@@ -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));
#32 lore raw

PATCH 10/41 slirp: remove PROBE_CONN dead-code

In reply to Marc-André Lureau

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

---
 slirp/slirp_config.h |  4 ----
 slirp/slirp.c        | 41 -----------------------------------------
 2 files changed, 45 deletions(-)
slirp/slirp_config.h +0 -4
index c59f655207..721667e3ef 100644
@@ -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
 
slirp/slirp.c +0 -41

47 lines not on this page · raw message

Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 10/41
#33 lore raw

Re: [Qemu-devel] [PATCH for-3.2 10/41] slirp: remove PROBE_CONN dead-code

Quoted 4 lines · Marc-André Lureau

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

Quoted 73 lines
---
  slirp/slirp_config.h |  4 ----
  slirp/slirp.c        | 41 -----------------------------------------
  2 files changed, 45 deletions(-)
slirp/slirp_config.h +0 -4
index c59f655207..721667e3ef 100644
@@ -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
 
slirp/slirp.c +0 -41
index 979495e88b..2d32debf2a 100644
@@ -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
              }
 
              /*
Reviewed-by on v1 10/41
#34 lore raw

Re: [Qemu-devel] [PATCH for-3.2 10/41] slirp: remove PROBE_CONN dead-code

In reply to Marc-André Lureau
Quoted 8 lines · Marc-André Lureau

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

---
 slirp/slirp_config.h |  4 ----
 slirp/slirp.c        | 41 -----------------------------------------
 2 files changed, 45 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#35 lore raw

Re: [Qemu-devel] [PATCH for-3.2 10/41] slirp: remove PROBE_CONN dead-code

Philippe Mathieu-Daudé, le mer. 14 nov. 2018 14:12:04 +0100, a ecrit:

Quoted 7 lines · Marc-André Lureau
Quoted 4 lines

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

Daniel P. Berrangé, le mer. 14 nov. 2018 13:33:28 +0000, a ecrit:

Quoted 1 line

Applied to my tree, thanks!

Samuel

#36 lore raw

PATCH 11/41 slirp: remove FULL_BOLT

In reply to Marc-André Lureau

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

---
 slirp/slirp_config.h | 7 -------
 slirp/if.c           | 2 --
 2 files changed, 9 deletions(-)
slirp/slirp_config.h +0 -7
index 721667e3ef..f0cc1c781b 100644
@@ -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
slirp/if.c +0 -2
index 1c96869831..1a9122a732 100644
@@ -131,12 +131,10 @@ diddit:
 		}
 	}
 
-#ifndef FULL_BOLT
 	/*
 	 * This prevents us from malloc()ing too many mbufs
 	 */
 	if_start(ifm->slirp);
-#endif
 }
 
 /*
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 11/41
#37 lore raw

Re: [Qemu-devel] [PATCH for-3.2 11/41] slirp: remove FULL_BOLT

Quoted 8 lines · Marc-André Lureau

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

---
 slirp/slirp_config.h | 7 -------
 slirp/if.c           | 2 --
 2 files changed, 9 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#38 lore raw

Re: [Qemu-devel] [PATCH for-3.2 11/41] slirp: remove FULL_BOLT

Daniel P. Berrangé, le mer. 14 nov. 2018 13:46:02 +0000, a ecrit:

Quoted 11 lines · Marc-André Lureau
Quoted 8 lines

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

---
 slirp/slirp_config.h | 7 -------
 slirp/if.c           | 2 --
 2 files changed, 9 deletions(-)

Applied to my tree, thanks!

#39 lore raw

PATCH 12/41 slirp: remove the disabled readv()/writev() code path

In reply to 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.

---
 slirp/slirp_config.h |  3 ---
 slirp/socket.c       | 15 ---------------
 2 files changed, 18 deletions(-)
slirp/slirp_config.h +0 -3
index f0cc1c781b..3ce64e088e 100644
@@ -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
slirp/socket.c +0 -15
index 041ec5061a..7012c7c07d 100644
@@ -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;
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 12/41
#40 lore raw

Re: [Qemu-devel] [PATCH for-3.2 12/41] slirp: remove the disabled readv()/writev() code path

Quoted 10 lines · 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.

---
 slirp/slirp_config.h |  3 ---
 slirp/socket.c       | 15 ---------------
 2 files changed, 18 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#41 lore raw

Re: [Qemu-devel] [PATCH for-3.2 12/41] slirp: remove the disabled readv()/writev() code path

Daniel P. Berrangé, le mer. 14 nov. 2018 13:46:46 +0000, a ecrit:

Quoted 6 lines · Marc-André Lureau
Quoted 5 lines

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.

Quoted 7 lines
Quoted 5 lines
---
 slirp/slirp_config.h |  3 ---
 slirp/socket.c       | 15 ---------------
 2 files changed, 18 deletions(-)

Applied to my tree, thanks!

#42 lore raw

PATCH 13/41 slirp: remove HAVE_SYS_SIGNAL_H

In reply to Marc-André Lureau
---
 slirp/slirp.h        | 3 ---
 slirp/slirp_config.h | 3 ---
 2 files changed, 6 deletions(-)
slirp/slirp.h +0 -3
index e5abf1c594..1dbe39bc9a 100644
@@ -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
slirp/slirp_config.h +0 -3
index 3ce64e088e..2605c4222b 100644
@@ -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
 
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 13/41
#43 lore raw

Re: [Qemu-devel] [PATCH for-3.2 13/41] slirp: remove HAVE_SYS_SIGNAL_H

Quoted 5 lines · Marc-André Lureau
---
 slirp/slirp.h        | 3 ---
 slirp/slirp_config.h | 3 ---
 2 files changed, 6 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#45 lore raw

PATCH 14/41 slirp: remove unused HAVE_SYS_BITYPES_H

In reply to Marc-André Lureau
---
 slirp/slirp.h        | 4 ----
 slirp/slirp_config.h | 3 ---
 2 files changed, 7 deletions(-)
slirp/slirp.h +0 -4
index 1dbe39bc9a..7c0bcd9e1c 100644
@@ -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
slirp/slirp_config.h +0 -3
index 2605c4222b..a205dc8c28 100644
@@ -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
 
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 14/41
#46 lore raw

Re: [Qemu-devel] [PATCH for-3.2 14/41] slirp: remove unused HAVE_SYS_BITYPES_H

Quoted 5 lines · Marc-André Lureau
---
 slirp/slirp.h        | 4 ----
 slirp/slirp_config.h | 3 ---
 2 files changed, 7 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#48 lore raw

PATCH 15/41 slirp: remove NO_UNIX_SOCKETS

In reply to Marc-André Lureau
---
 slirp/slirp.h        | 3 ---
 slirp/slirp_config.h | 6 ------
 2 files changed, 9 deletions(-)
slirp/slirp.h +0 -3
index 7c0bcd9e1c..424151b99b 100644
@@ -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
slirp/slirp_config.h +0 -6
index a205dc8c28..4417b05d1c 100644
@@ -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
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 15/41
#49 lore raw

Re: [Qemu-devel] [PATCH for-3.2 15/41] slirp: remove NO_UNIX_SOCKETS

Quoted 5 lines · Marc-André Lureau
---
 slirp/slirp.h        | 3 ---
 slirp/slirp_config.h | 6 ------
 2 files changed, 9 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#51 lore raw

PATCH 16/41 slirp: remove unused HAVE_SYS_STROPTS_H

In reply to Marc-André Lureau
---
 slirp/slirp.h        | 5 -----
 slirp/slirp_config.h | 3 ---
 2 files changed, 8 deletions(-)
slirp/slirp.h +0 -5
index 424151b99b..92abb2d78d 100644
@@ -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"
slirp/slirp_config.h +0 -3
index 4417b05d1c..47811e36dc 100644
@@ -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)
 
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 16/41
#52 lore raw

Re: [Qemu-devel] [PATCH for-3.2 16/41] slirp: remove unused HAVE_SYS_STROPTS_H

Quoted 5 lines · Marc-André Lureau
---
 slirp/slirp.h        | 5 -----
 slirp/slirp_config.h | 3 ---
 2 files changed, 8 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#54 lore raw

PATCH 17/41 slirp: remove unused HAVE_ARPA_INET_H

In reply to Marc-André Lureau
---
 slirp/slirp_config.h | 6 ------
 1 file changed, 6 deletions(-)
slirp/slirp_config.h +0 -6
index 47811e36dc..e95284071a 100644
@@ -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)
 
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 17/41
#55 lore raw

Re: [Qemu-devel] [PATCH for-3.2 17/41] slirp: remove unused HAVE_ARPA_INET_H

Quoted 4 lines · Marc-André Lureau
---
 slirp/slirp_config.h | 6 ------
 1 file changed, 6 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#57 lore raw

PATCH 18/41 slirp: remove unused HAVE_SYS_WAIT_H

In reply to Marc-André Lureau
---
 slirp/slirp.h        | 4 ----
 slirp/slirp_config.h | 3 ---
 2 files changed, 7 deletions(-)
slirp/slirp.h +0 -4
index 92abb2d78d..7aa14feeb6 100644
@@ -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
slirp/slirp_config.h +0 -3
index e95284071a..9becb98e11 100644
@@ -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
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 18/41
#58 lore raw

Re: [Qemu-devel] [PATCH for-3.2 18/41] slirp: remove unused HAVE_SYS_WAIT_H

Quoted 5 lines · Marc-André Lureau
---
 slirp/slirp.h        | 4 ----
 slirp/slirp_config.h | 3 ---
 2 files changed, 7 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#60 lore raw

PATCH 19/41 slirp: remove unused HAVE_SYS_SELECT_H

In reply to Marc-André Lureau
---
 slirp/main.h         | 4 ----
 slirp/slirp.h        | 4 ----
 slirp/slirp_config.h | 6 ------
 3 files changed, 14 deletions(-)
slirp/main.h +0 -4
index e04677944f..4bc05fb904 100644
@@ -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;
slirp/slirp.h +0 -4
index 7aa14feeb6..abe87618af 100644
@@ -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
slirp/slirp_config.h +0 -6
index 9becb98e11..68e75f3873 100644
@@ -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)
 
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 19/41
#61 lore raw

Re: [Qemu-devel] [PATCH for-3.2 19/41] slirp: remove unused HAVE_SYS_SELECT_H

Quoted 6 lines · Marc-André Lureau
---
 slirp/main.h         | 4 ----
 slirp/slirp.h        | 4 ----
 slirp/slirp_config.h | 6 ------
 3 files changed, 14 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#63 lore raw

PATCH 20/41 slirp: remove HAVE_SYS_IOCTL_H

In reply to Marc-André Lureau
---
 slirp/slirp.h        | 2 +-
 slirp/slirp_config.h | 6 ------
 2 files changed, 1 insertion(+), 7 deletions(-)
slirp/slirp.h +1 -1
index abe87618af..a2e7c50361 100644
@@ -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
 
slirp/slirp_config.h +0 -6
index 68e75f3873..0e78e92d94 100644
@@ -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__
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 20/41
#64 lore raw

Re: [Qemu-devel] [PATCH for-3.2 20/41] slirp: remove HAVE_SYS_IOCTL_H

Quoted 5 lines · Marc-André Lureau
---
 slirp/slirp.h        | 2 +-
 slirp/slirp_config.h | 6 ------
 2 files changed, 1 insertion(+), 7 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#66 lore raw

PATCH 21/41 slirp: remove HAVE_SYS_FILIO_H

In reply to Marc-André Lureau
---
 slirp/slirp.h        | 2 +-
 slirp/slirp_config.h | 6 ------
 2 files changed, 1 insertion(+), 7 deletions(-)
slirp/slirp.h +1 -1
index a2e7c50361..1a336b2cf1 100644
@@ -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
 
slirp/slirp_config.h +0 -6
index 0e78e92d94..f1ee927c15 100644
@@ -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
 
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 21/41
#67 lore raw

Re: [Qemu-devel] [PATCH for-3.2 21/41] slirp: remove HAVE_SYS_FILIO_H

Quoted 5 lines · Marc-André Lureau
---
 slirp/slirp.h        | 2 +-
 slirp/slirp_config.h | 6 ------
 2 files changed, 1 insertion(+), 7 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#69 lore raw

PATCH 22/41 slirp: remove unused DECLARE_IOVEC

In reply to Marc-André Lureau

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

---
 slirp/slirp_config.h | 6 ------
 1 file changed, 6 deletions(-)
slirp/slirp_config.h +0 -6
index f1ee927c15..833f25a965 100644
@@ -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)
 
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 22/41
#70 lore raw

Re: [Qemu-devel] [PATCH for-3.2 22/41] slirp: remove unused DECLARE_IOVEC

Quoted 1 line · Marc-André Lureau

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.

Quoted 5 lines
---
 slirp/slirp_config.h | 6 ------
 1 file changed, 6 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#71 lore raw

Re: [Qemu-devel] [PATCH for-3.2 22/41] slirp: remove unused DECLARE_IOVEC

Daniel P. Berrangé, le mer. 14 nov. 2018 13:53:31 +0000, a ecrit:

Quoted 7 lines · Marc-André Lureau
Quoted 1 line

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.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
---
 slirp/slirp_config.h | 6 ------
 1 file changed, 6 deletions(-)

Applied to my tree, thanks!

#72 lore raw

PATCH 23/41 slirp: remove unused HAVE_INET_ATON

In reply to Marc-André Lureau
---
 slirp/slirp_config.h | 6 ------
 1 file changed, 6 deletions(-)
slirp/slirp_config.h +0 -6
index 833f25a965..5126711849 100644
@@ -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
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 23/41
#73 lore raw

Re: [Qemu-devel] [PATCH for-3.2 23/41] slirp: remove unused HAVE_INET_ATON

Quoted 4 lines · Marc-André Lureau
---
 slirp/slirp_config.h | 6 ------
 1 file changed, 6 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#75 lore raw

PATCH 24/41 slirp: replace HOST_WORDS_BIGENDIAN with glib equivalent

In reply to Marc-André Lureau

One more step towards making the project independent from QEMU.

---
 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(-)
slirp/ip.h +5 -3
index 59cf4aa918..83fc9cdfbf 100644
@@ -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
slirp/ip6.h +2 -1
index b1bea43b3c..14e9c78735 100644
@@ -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 */
slirp/ip6_icmp.h +3 -3
index b3378b17b5..32b0914055 100644
@@ -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;
slirp/slirp_config.h +0 -3
index 5126711849..b2def6d20c 100644
@@ -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)
slirp/tcp.h +3 -1
index 174d3d960c..47aaea6c5b 100644
@@ -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
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 24/41
#76 lore raw

Re: [Qemu-devel] [PATCH for-3.2 24/41] slirp: replace HOST_WORDS_BIGENDIAN with glib equivalent

Quoted 3 lines · Marc-André Lureau

One more step towards making the project independent from QEMU.

Quoted 129 lines
---
  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(-)
slirp/ip.h +5 -3
index 59cf4aa918..83fc9cdfbf 100644
@@ -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
slirp/ip6.h +2 -1
index b1bea43b3c..14e9c78735 100644
@@ -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 */
slirp/ip6_icmp.h +3 -3
index b3378b17b5..32b0914055 100644
@@ -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;
slirp/slirp_config.h +0 -3
index 5126711849..b2def6d20c 100644
@@ -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)
slirp/tcp.h +3 -1
index 174d3d960c..47aaea6c5b 100644
@@ -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
Reviewed-by on v1 24/41
#77 lore raw

Re: [Qemu-devel] [PATCH for-3.2 24/41] slirp: replace HOST_WORDS_BIGENDIAN with glib equivalent

In reply to Marc-André Lureau
Quoted 16 lines · Marc-André Lureau

One more step towards making the project independent from QEMU.

---
 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(-)
slirp/ip.h +0 -0
index 59cf4aa918..83fc9cdfbf 100644

slirp/ip.h line 38

Quoted 7 lines
slirp/ip.h +3 -1
@@ -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

Quoted 112 lines
slirp/ip.h +2 -2
 # 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
slirp/ip6.h +2 -1
index b1bea43b3c..14e9c78735 100644
@@ -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 */
slirp/ip6_icmp.h +3 -3
index b3378b17b5..32b0914055 100644
@@ -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;
slirp/slirp_config.h +0 -3
index 5126711849..b2def6d20c 100644
@@ -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)
slirp/tcp.h +3 -1
index 174d3d960c..47aaea6c5b 100644
@@ -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
Signature · 1 line
2.19.1.708.g4ede3d42df

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#78 lore raw

Re: [Qemu-devel] [PATCH for-3.2 24/41] slirp: replace HOST_WORDS_BIGENDIAN with glib equivalent

Philippe Mathieu-Daudé, le mer. 14 nov. 2018 14:14:16 +0100, a ecrit:

Quoted 6 lines · Marc-André Lureau
Quoted 3 lines

One more step towards making the project independent from QEMU.

Daniel P. Berrangé, le mer. 14 nov. 2018 13:32:29 +0000, a ecrit:

Quoted 1 line

Applied to my tree, thanks!

Samuel

#79 lore raw

PATCH 25/41 slirp: replace SIZEOF_CHAR_P with glib equivalent

In reply to Marc-André Lureau
---
 slirp/ip.h           | 2 +-
 slirp/slirp_config.h | 3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)
slirp/ip.h +1 -1
index 83fc9cdfbf..243b6c8b24 100644
@@ -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;
slirp/slirp_config.h +0 -3
index b2def6d20c..7147e0de04 100644
@@ -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)
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 25/41
#80 lore raw

Re: [Qemu-devel] [PATCH for-3.2 25/41] slirp: replace SIZEOF_CHAR_P with glib equivalent

Quoted 1 line · Marc-André Lureau
Quoted 30 lines
---
  slirp/ip.h           | 2 +-
  slirp/slirp_config.h | 3 ---
  2 files changed, 1 insertion(+), 4 deletions(-)
slirp/ip.h +1 -1
index 83fc9cdfbf..243b6c8b24 100644
@@ -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;
slirp/slirp_config.h +0 -3
index b2def6d20c..7147e0de04 100644
@@ -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)
#82 lore raw

PATCH 26/41 slirp: replace compile time DO_KEEPALIVE

In reply to Marc-André Lureau

Use a global variable instead (similar to slirp_debug)

---
 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
slirp/slirp.h +3 -3
index 1a336b2cf1..c328aac88a 100644
@@ -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 */
slirp/slirp_config.h deleted +0 -12
deleted file mode 100644
index 7147e0de04..0000000000
@@ -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
- */
slirp/slirp.c +3 -0
index 2d32debf2a..864a9b5a7a 100644
@@ -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 */
slirp/tcp_input.c +1 -1
index d073ef9525..922dbe32eb 100644
@@ -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;
slirp/tcp_timer.c +1 -1
index 52ef5f9100..d953a16386 100644
@@ -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;
 			/*
Signature · 1 line
2.19.1.708.g4ede3d42df
#83 lore raw

Re: [Qemu-devel] [PATCH for-3.2 26/41] slirp: replace compile time DO_KEEPALIVE

Marc-André Lureau, le mer. 14 nov. 2018 16:36:28 +0400, a ecrit:

Quoted 3 lines

Use a global variable instead (similar to slirp_debug)

Applied to my tree, thanks!

Reviewed-by on v1 27/41
#85 lore raw

Re: [Qemu-devel] [PATCH for-3.2 27/41] slirp: remove unused global slirp_instance

Quoted 4 lines · Marc-André Lureau
---
 slirp/slirp.h | 2 --
 1 file changed, 2 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#87 lore raw

PATCH 28/41 slirp: replace error_report() with g_critical()

In reply to Marc-André Lureau

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

---
 slirp/ip6_icmp.c | 2 +-
 slirp/misc.c     | 4 ++--
 slirp/slirp.c    | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
slirp/ip6_icmp.c +1 -1
index 71d95daef0..e2e23d57bd 100644
@@ -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;
 
slirp/misc.c +2 -2
index dd2b3512a8..17361b79a4 100644
@@ -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]);
slirp/slirp.c +3 -3
index 864a9b5a7a..b1270a0309 100644
@@ -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;
     }
 
Signature · 1 line
2.19.1.708.g4ede3d42df
#88 lore raw

Re: [Qemu-devel] [PATCH for-3.2 28/41] slirp: replace error_report() with g_critical()

Marc-André Lureau, le mer. 14 nov. 2018 16:36:30 +0400, a ecrit:

Quoted 4 lines

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

Applied to my tree, thanks!

#89 lore raw

PATCH 29/41 slirp: improve a bit the debug macros

In reply to Marc-André Lureau

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

---
 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(-)
slirp/debug.h +37 -10
index 6cfa61edb3..ca3a4b04da 100644
@@ -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
slirp/arp_table.c +6 -6
index f81963bb88..ce19e6e7c0 100644
@@ -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;
         }
     }
slirp/bootp.c +1 -2
index 7b1af73c95..5ab6692038 100644
@@ -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
slirp/cksum.c +2 -2
index 6d73abf4a0..b9466485b5 100644
@@ -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) {
slirp/dhcpv6.c +5 -6
index d266611e85..943a13bca8 100644
@@ -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]);
     }
 }
slirp/ip6_icmp.c +1 -1
index e2e23d57bd..6f20190a0a 100644
@@ -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)) {
slirp/ip_icmp.c +9 -9
index 9210eef3f3..af11cfcefe 100644
@@ -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);
slirp/mbuf.c +1 -1
index aa1f28afb1..d8d275e0e7 100644
@@ -232,7 +232,7 @@ dtom(Slirp *slirp, void *dat)
 	  }
 	}
 
-	DEBUG_ERROR((dfd, "dtom failed"));
+	DEBUG_ERROR("dtom failed");
 
 	return (struct mbuf *)0;
 }
slirp/ndp_table.c +9 -9
index e1676a0a7b..a4e6421fd3 100644
@@ -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;
         }
     }
slirp/slirp.c +6 -6
index b1270a0309..9a87abee27 100644
@@ -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;
slirp/socket.c +16 -16
index 7012c7c07d..677fd20c9d 100644
@@ -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:
slirp/tcp_input.c +7 -8
index 922dbe32eb..e33fb83df5 100644
@@ -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;
 }
slirp/tcp_output.c +1 -1
index 90b5c376f7..44da8a4e47 100644
@@ -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.
slirp/tcp_subr.c +2 -2
index 8d97f1f54e..98bceea9f6 100644
@@ -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);
             }
         }
slirp/udp.c +3 -3
index c47870a61b..a45ad81dda 100644
@@ -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;
slirp/udp6.c +3 -3
index 986010f0d3..473ba1586e 100644
@@ -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;
     }
Signature · 1 line
2.19.1.708.g4ede3d42df
#90 lore raw

Re: [Qemu-devel] [PATCH for-3.2 29/41] slirp: improve a bit the debug macros

Quoted 58 lines · Marc-André Lureau

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

---
 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(-)
slirp/debug.h +22 -5
index 6cfa61edb3..ca3a4b04da 100644
@@ -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__);       \

slirp/debug.h line 51

Quoted 10 lines
slirp/debug.h +10 -0
+        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

Signature · 3 lines
|: 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 :|
#91 lore raw

Re: [Qemu-devel] [PATCH for-3.2 29/41] slirp: improve a bit the debug macros

Hi

Quoted 75 lines · Daniel P. Berrangé
Quoted 58 lines · Marc-André Lureau

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

---
 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(-)
slirp/debug.h +22 -5
index 6cfa61edb3..ca3a4b04da 100644
@@ -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__);       \

slirp/debug.h line 51

Quoted 10 lines
slirp/debug.h +10 -0
+        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.

Quoted 2 lines

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)

Quoted 7 lines

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 :|
#93 lore raw

PATCH 30/41 slirp: replace trace functions with DEBUG calls

In reply to Marc-André Lureau

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

---
 slirp/tftp.c       | 7 ++++---
 Makefile.objs      | 1 -
 slirp/trace-events | 5 -----
 3 files changed, 4 insertions(+), 9 deletions(-)
 delete mode 100644 slirp/trace-events
slirp/tftp.c +4 -3
index 735b57aa55..dddb614b8a 100644
@@ -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) {
Makefile.objs +0 -1
index 31852eaf8f..1e1ff387d7 100644
@@ -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
slirp/trace-events deleted +0 -5
deleted file mode 100644
index ff8f656e8c..0000000000
@@ -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"
Signature · 1 line
2.19.1.708.g4ede3d42df
#94 lore raw

Re: [Qemu-devel] [PATCH for-3.2 30/41] slirp: replace trace functions with DEBUG calls

Marc-André Lureau, le mer. 14 nov. 2018 16:36:32 +0400, a ecrit:

Quoted 1 line

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

#95 lore raw

PATCH 31/41 slirp: add a callback to log guest errors

In reply to Marc-André Lureau
---
 slirp/libslirp.h | 1 +
 net/slirp.c      | 7 +++++++
 slirp/dhcpv6.c   | 6 +++---
 slirp/ip6_icmp.c | 7 +++----
 4 files changed, 14 insertions(+), 7 deletions(-)
slirp/libslirp.h +1 -0
index f2e7f94ebb..c7582e6516 100644
@@ -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;
 
 
net/slirp.c +7 -0
index 5ea8c255f6..b36092c948 100644
@@ -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,
slirp/dhcpv6.c +3 -3
index 943a13bca8..5d703e8ae6 100644
@@ -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;
     }
 
slirp/ip6_icmp.c +3 -4
index 6f20190a0a..d523852a1f 100644
@@ -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;
     }
 }
Signature · 1 line
2.19.1.708.g4ede3d42df
#97 lore raw

PATCH 32/41 slirp: remove unused sbflush()

In reply to Marc-André Lureau
---
 slirp/sbuf.h | 1 -
 1 file changed, 1 deletion(-)
slirp/sbuf.h +0 -1
index a722ecb629..644c201341 100644
@@ -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 {
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 32/41
#98 lore raw

Re: [Qemu-devel] [PATCH for-3.2 32/41] slirp: remove unused sbflush()

Quoted 4 lines · Marc-André Lureau
---
 slirp/sbuf.h | 1 -
 1 file changed, 1 deletion(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#100 lore raw

PATCH 33/41 slirp: replace qemu_notify_event() with a callback

In reply to Marc-André Lureau

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

---
 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(-)
slirp/libslirp.h +1 -0
index c7582e6516..7d04404340 100644
@@ -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;
 
 
slirp/sbuf.h +1 -1
index 644c201341..1cb9a42834 100644
@@ -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 *);
slirp/socket.h +1 -0
index 930ed95972..79b6fbd4c1 100644
@@ -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 */
net/slirp.c +1 -0
index b36092c948..4c39878933 100644
@@ -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,
slirp/sbuf.c +4 -2
index 912f235f65..17f28e97a6 100644
@@ -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
slirp/socket.c +7 -0
index 677fd20c9d..2b1b5052c4 100644
@@ -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();
+    }
+}
slirp/tcp_input.c +3 -3
index e33fb83df5..456d5829e7 100644
@@ -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;
 		}
Signature · 1 line
2.19.1.708.g4ede3d42df
#101 lore raw

Re: [Qemu-devel] [PATCH for-3.2 33/41] slirp: replace qemu_notify_event() with a callback

Marc-André Lureau, le mer. 14 nov. 2018 16:36:35 +0400, a ecrit:

Quoted 2 lines

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

#102 lore raw

PATCH 34/41 slirp: remove #if notdef dead code

In reply to Marc-André Lureau
---
 slirp/ip_input.c  | 200 ----------------------------------------------
 slirp/tcp_input.c |  39 ---------
 2 files changed, 239 deletions(-)
slirp/ip_input.c +0 -200
index 348e1dca5a..6831526320 100644
@@ -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.
slirp/tcp_input.c +0 -39
index 456d5829e7..de4ef92aba 100644
@@ -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.
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 34/41
#103 lore raw

Re: [Qemu-devel] [PATCH for-3.2 34/41] slirp: remove #if notdef dead code

Quoted 5 lines · Marc-André Lureau
---
 slirp/ip_input.c  | 200 ----------------------------------------------
 slirp/tcp_input.c |  39 ---------
 2 files changed, 239 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#104 lore raw

Re: [Qemu-devel] [PATCH for-3.2 34/41] slirp: remove #if notdef dead code

Daniel P. Berrangé, le mer. 14 nov. 2018 14:07:38 +0000, a ecrit:

Quoted 8 lines · Marc-André Lureau
Quoted 5 lines
---
 slirp/ip_input.c  | 200 ----------------------------------------------
 slirp/tcp_input.c |  39 ---------
 2 files changed, 239 deletions(-)

Applied to my tree, thanks!

#105 lore raw

PATCH 35/41 slirp: NULL is defined by glib (at least)

In reply to Marc-André Lureau
---
 slirp/slirp.h | 4 ----
 1 file changed, 4 deletions(-)
slirp/slirp.h +0 -4
index 4356b2f427..2a61a85995 100644
@@ -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);
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 35/41
#106 lore raw

Re: [Qemu-devel] [PATCH for-3.2 35/41] slirp: NULL is defined by glib (at least)

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

Quoted 4 lines · Marc-André Lureau
---
 slirp/slirp.h | 4 ----
 1 file changed, 4 deletions(-)
Quoted 20 lines
slirp/slirp.h +0 -4
index 4356b2f427..2a61a85995 100644
@@ -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);
Signature · 1 line
2.19.1.708.g4ede3d42df

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#107 lore raw

Re: [Qemu-devel] [PATCH for-3.2 35/41] slirp: NULL is defined by glib (at least)

Daniel P. Berrangé, le mer. 14 nov. 2018 14:11:34 +0000, a ecrit:

Quoted 11 lines

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

Quoted 4 lines · Marc-André Lureau
---
 slirp/slirp.h | 4 ----
 1 file changed, 4 deletions(-)

Applied to my tree, thanks!

#108 lore raw

PATCH 36/41 slirp: remove dead TCP_ACK_HACK code

In reply to Marc-André Lureau

Untouched since original introduction in 2004.

---
 slirp/tcp_input.c | 23 +----------------------
 1 file changed, 1 insertion(+), 22 deletions(-)
slirp/tcp_input.c +1 -22
index de4ef92aba..0d34abf8d7 100644
@@ -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);
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 36/41
#109 lore raw

Re: [Qemu-devel] [PATCH for-3.2 36/41] slirp: remove dead TCP_ACK_HACK code

Quoted 6 lines · Marc-André Lureau

Untouched since original introduction in 2004.

---
 slirp/tcp_input.c | 23 +----------------------
 1 file changed, 1 insertion(+), 22 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#110 lore raw

Re: [Qemu-devel] [PATCH for-3.2 36/41] slirp: remove dead TCP_ACK_HACK code

Daniel P. Berrangé, le mer. 14 nov. 2018 14:12:06 +0000, a ecrit:

Quoted 9 lines · Marc-André Lureau
Quoted 6 lines

Untouched since original introduction in 2004.

---
 slirp/tcp_input.c | 23 +----------------------
 1 file changed, 1 insertion(+), 22 deletions(-)

Applied to my tree, thanks!

#111 lore raw

PATCH 37/41 slirp: replace ARRAY_SIZE with G_N_ELEMENTS

In reply to Marc-André Lureau

Do not require QEMU macro.

---
 slirp/ncsi.c | 2 +-
 slirp/tftp.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
slirp/ncsi.c +1 -1
index 10decfb5ef..8594382270 100644
@@ -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;
slirp/tftp.c +2 -2
index dddb614b8a..ef8d0352b4 100644
@@ -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;
   }
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 37/41
#112 lore raw

Re: [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS

Quoted 3 lines · Marc-André Lureau

Do not require QEMU macro.

Quoted 41 lines
---
  slirp/ncsi.c | 2 +-
  slirp/tftp.c | 4 ++--
  2 files changed, 3 insertions(+), 3 deletions(-)
slirp/ncsi.c +1 -1
index 10decfb5ef..8594382270 100644
@@ -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;
slirp/tftp.c +2 -2
index dddb614b8a..ef8d0352b4 100644
@@ -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;
    }
Reviewed-by on v1 37/41
#113 lore raw

Re: [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS

In reply to Marc-André Lureau
Quoted 1 line · Marc-André Lureau

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.

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#114 lore raw

Re: [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS

Philippe Mathieu-Daudé, le mer. 14 nov. 2018 14:17:56 +0100, a ecrit:

Quoted 6 lines · Marc-André Lureau
Quoted 3 lines

Do not require QEMU macro.

Daniel P. Berrangé, le mer. 14 nov. 2018 14:15:15 +0000, a ecrit:

Quoted 1 line

Applied to my tree, thanks!

#115 lore raw

PATCH 38/41 net: do not depend on slirp internals

In reply to 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.

---
 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(-)
net/colo.h +1 -2
index 11c5226488..420d916af2 100644
@@ -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
 
net/util.h +55 -0

61 lines not on this page · raw message

net/colo-compare.c +1 -0
index a39191d522..3b6f596432 100644
@@ -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) \
net/colo.c +1 -0
index 49176bf07b..8196b35837 100644
@@ -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)
 {
net/filter-rewriter.c +1 -0
index bb8f4d93b1..9ccd8947db 100644
@@ -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)
net/slirp.c +1 -1
index 4c39878933..7524049e49 100644
@@ -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)
 {
stubs/slirp.c +1 -1
index 42f7e1afd0..70704346fd 100644
@@ -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)
 {
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by Tested-by on v1 38/41
#116 lore raw

Re: [Qemu-devel] [PATCH for-3.2 38/41] net: do not depend on slirp internals

Quoted 4 lines · 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.

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

Quoted 2 lines
Quoted 160 lines
---
  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(-)
net/colo.h +1 -2
index 11c5226488..420d916af2 100644
@@ -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
 
net/util.h +55 -0
index 60b73d372d..358185fd50 100644
@@ -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 */
net/colo-compare.c +1 -0
index a39191d522..3b6f596432 100644
@@ -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) \
net/colo.c +1 -0
index 49176bf07b..8196b35837 100644
@@ -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)
  {
net/filter-rewriter.c +1 -0
index bb8f4d93b1..9ccd8947db 100644
@@ -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)
net/slirp.c +1 -1
index 4c39878933..7524049e49 100644
@@ -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)
  {
stubs/slirp.c +1 -1
index 42f7e1afd0..70704346fd 100644
@@ -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)
  {
#118 lore raw

Re: [Qemu-devel] [PATCH for-3.2 38/41] net: do not depend on slirp internals

In reply to Marc-André Lureau
Quoted 6 lines · 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.

Quoted 9 lines
---
 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

#119 lore raw

PATCH 39/41 slirp: move QEMU state saving to a separate unit

In reply to 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)

---
 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
slirp/slirp.h +3 -0
index 2a61a85995..e5cd0cd334 100644
@@ -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
slirp/state.h new file +9 -0
new file mode 100644
index 0000000000..154866898f
@@ -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_ */
slirp/slirp.c +11 -360

404 lines not on this page · raw message

slirp/state.c new file +394 -0

394 lines not on this page · raw message

slirp/Makefile.objs +3 -1
index 28049b03cd..98a82d2615 100644
@@ -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
Signature · 1 line
2.19.1.708.g4ede3d42df
#120 lore raw

PATCH 40/41 slirp: replace remaining QEMU dependency

In reply to Marc-André Lureau

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

---
 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
slirp/ip.h +7 -7
index 243b6c8b24..cd6ddf2bb7 100644
@@ -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
slirp/ip6.h +2 -3
index 14e9c78735..e0a13dec1c 100644
@@ -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
slirp/ip6_icmp.h +8 -8
index 32b0914055..1f09b485e3 100644
@@ -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 */
slirp/libslirp.h +11 -1
index 7d04404340..419f7a7712 100644
@@ -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;
 
slirp/qtailq.h new file +218 -0

218 lines not on this page · raw message

slirp/slirp.h +5 -7
index e5cd0cd334..f82d295834 100644
@@ -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
 
slirp/util.h new file +145 -0

145 lines not on this page · raw message

slirp/arp_table.c +0 -1
index ce19e6e7c0..d657b559d1 100644
@@ -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])
slirp/bootp.c +0 -1
index 5ab6692038..083dd58984 100644
@@ -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)
slirp/cksum.c +0 -1
index b9466485b5..2cd3589297 100644
@@ -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"
 
 /*
slirp/dhcpv6.c +0 -2
index 5d703e8ae6..01b5916b1e 100644
@@ -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"
 
slirp/dnssearch.c +0 -1
index 8fb563321b..c459cece8d 100644
@@ -22,7 +22,6 @@
  * THE SOFTWARE.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 
 static const uint8_t RFC3397_OPT_DOMAIN_SEARCH = 119;
slirp/if.c +0 -2
index 1a9122a732..ec29a926f0 100644
@@ -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)
slirp/ip6_icmp.c +0 -4
index d523852a1f..328926f328 100644
@@ -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)
slirp/ip6_input.c +0 -1
index ac2e3ea882..4aa9f2eadc 100644
@@ -3,7 +3,6 @@
  * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 #include "ip6_icmp.h"
 
slirp/ip6_output.c +0 -2
index 762cbfe89c..2dd80f4649 100644
@@ -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
slirp/ip_icmp.c +3 -4
index af11cfcefe..41cdf665ce 100644
@@ -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
slirp/ip_input.c +0 -1
index 6831526320..cfda30fccd 100644
@@ -38,7 +38,6 @@
  * terms and conditions of the copyright.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 #include "ip_icmp.h"
 
slirp/ip_output.c +0 -1
index db403f04c1..f6ec141df5 100644
@@ -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
slirp/mbuf.c +0 -1
index d8d275e0e7..521c02c967 100644
@@ -15,7 +15,6 @@
  * the flags
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 
 #define MBUF_THRESH 30
slirp/misc.c +9 -12
index 17361b79a4..80a94194dd 100644
@@ -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;
 }
slirp/ncsi.c +0 -1
index 8594382270..327f17543c 100644
@@ -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"
slirp/ndp_table.c +0 -2
index a4e6421fd3..2dbc3805a5 100644
@@ -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,
slirp/sbuf.c +0 -2
index 17f28e97a6..51a9f0cc7d 100644
@@ -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);
 
slirp/slirp.c +0 -8
index 8b56f28d77..15386e5245 100644
@@ -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"
slirp/socket.c +8 -10
index 2b1b5052c4..c3860ba067 100644
@@ -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;
slirp/tcp_input.c +0 -1
index 0d34abf8d7..c9cbec205e 100644
@@ -38,7 +38,6 @@
  * terms and conditions of the copyright.
  */
 
-#include "qemu/osdep.h"
 #include "slirp.h"
 #include "ip_icmp.h"
 
slirp/tcp_output.c +0 -1
index 44da8a4e47..a1547c0b23 100644
@@ -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] = {
slirp/tcp_subr.c +6 -7
index 98bceea9f6..d8dd7d57a6 100644
@@ -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 */
slirp/tcp_timer.c +0 -1
index d953a16386..ebc9d16f06 100644
@@ -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);
slirp/tftp.c +4 -3
index ef8d0352b4..a78d06d2a4 100644
@@ -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)
 {
slirp/udp.c +3 -4
index a45ad81dda..1de3775add 100644
@@ -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;
slirp/udp6.c +0 -2
index 473ba1586e..d14329f05f 100644
@@ -3,8 +3,6 @@
  * Guillaume Subiron
  */
 
-#include "qemu/osdep.h"
-#include "qemu-common.h"
 #include "slirp.h"
 #include "udp.h"
 #include "dhcpv6.h"
slirp/util.c new file +176 -0

176 lines not on this page · raw message

slirp/Makefile.objs +1 -1
index 98a82d2615..446a33b879 100644
@@ -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
Signature · 1 line
2.19.1.708.g4ede3d42df
#121 lore raw

PATCH 41/41 build-sys: add a basic meson build

In reply to 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.

---
 slirp/meson.build | 48 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 slirp/meson.build
slirp/meson.build new file +48 -0
new file mode 100644
index 0000000000..aa6f1b39e2
@@ -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])
Signature · 1 line
2.19.1.708.g4ede3d42df
#122 lore raw
In reply to Marc-André Lureau
Quoted 20 lines · 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..

Quoted 6 lines

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"...

#123 lore raw
Quoted 24 lines · Markus Armbruster
Quoted 22 lines · 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:

Quoted 7 lines
Quoted 4 lines

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.

Signature · 5 lines
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/
#124 lore raw
In reply to Markus Armbruster
Quoted 24 lines · Markus Armbruster
Quoted 22 lines · 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:

Quoted 7 lines
Quoted 4 lines

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

#125 lore raw
Quoted 28 lines · Thomas Huth
Quoted 27 lines · Markus Armbruster
Quoted 25 lines · 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)

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

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.

Quoted 13 lines

- 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/)

Quoted 7 lines

... 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.

#126 lore raw
Quoted 35 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 33 lines · Thomas Huth
Quoted 31 lines · Markus Armbruster
Quoted 20 lines · 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..

Quoted 6 lines

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"...

Quoted 6 lines
Quoted 1 line

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

Quoted 21 lines
Quoted 13 lines

- 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/)

Quoted 7 lines

... 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.

Quoted 7 lines

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 / [email protected] / Manchester, UK

#127 lore raw
In reply to Markus Armbruster
Quoted 4 lines · Markus Armbruster

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.

Signature · 5 lines
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
#128 lore raw
In reply to Markus Armbruster
Quoted 32 lines · Markus Armbruster
Quoted 30 lines · Thomas Huth
Quoted 29 lines · Markus Armbruster
Quoted 26 lines · 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?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

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?

Quoted 3 lines

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

#129 lore raw
Quoted 36 lines · Thomas Huth
Quoted 35 lines · Markus Armbruster
Quoted 33 lines · Thomas Huth
Quoted 31 lines · Markus Armbruster
Quoted 20 lines · 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..

Quoted 6 lines

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"...

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

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 ...

Quoted 3 lines

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:

Quoted 3 lines
Quoted 3 lines

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.

Quoted 5 lines

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.

[...]

Quoted 6 lines · I'm afraid we're in violent agreement there. I
Quoted 6 lines

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.

#130 lore raw
Quoted 60 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 36 lines · Thomas Huth
Quoted 35 lines · Markus Armbruster
Quoted 33 lines · Thomas Huth
Quoted 31 lines · Markus Armbruster
Quoted 20 lines · 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..

Quoted 6 lines

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"...

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

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 ...

Quoted 3 lines

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:

Quoted 3 lines
Quoted 3 lines

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.

Quoted 15 lines
Quoted 5 lines

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.

[...]

Quoted 6 lines · I'm afraid we're in violent agreement there. I
Quoted 6 lines

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 / [email protected] / Manchester, UK

#131 lore raw
In reply to Marc-André Lureau
Quoted 5 lines · 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.

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.

Quoted 9 lines

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.

Quoted 3 lines

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
Quoted 4 lines

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

Quoted 1 line

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

Signature · 3 lines
|: 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 :|
#132 lore raw
Quoted 6 lines · Daniel P. Berrangé
Quoted 5 lines · 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.

Marc-André, thanks for working on this!

Quoted 15 lines

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.

Quoted 9 lines

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.

Quoted 4 lines

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

#133 lore raw
Quoted 1 line

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.

Quoted 1 line

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 <[email protected]>:

Quoted 58 lines
Quoted 6 lines · Daniel P. Berrangé
Quoted 5 lines · 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.

Marc-André, thanks for working on this!

Quoted 9 lines

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.

Quoted 4 lines

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.

Quoted 10 lines
Quoted 5 lines

(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

#134 lore raw
In reply to Marc-André Lureau
Quoted 20 lines · 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..

Quoted 6 lines

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.

#135 lore raw
Quoted 26 lines · Stefan Hajnoczi
Quoted 25 lines · 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)

Quoted 7 lines
Quoted 1 line

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

Signature · 3 lines
|: 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 :|
#136 lore raw
Quoted 2 lines · Daniel P. Berrangé
Quoted 1 line · Stefan Hajnoczi

On Wed, Nov 14, 2018 at 04:36:02PM +0400, Marc-André Lureau wrote:

[...]

Quoted 9 lines
Quoted 4 lines

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.