Skip to contentSkip to conversation

slirp: Add query-usernet QMP command

PATCH In review Fam Zheng 3 participants 10 messages May 4, 2018 – May 16, 2018 Networking

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

v6 cover slirp: Add query-usernet QMP command

v6: Rename QAPI enum: TCPS -> UsernetTcpState. [Daniel]

v5: Fix QAPI example in comments. [Eric]
v4: vlan -> hub. [Samuel]
Free 'info. [Samuel]

v3: - Add Eric's rev-by to patch 2.
- Address Eric's comments on patch 1:
* Fix spell/grammar: "programmed", "awaiting".
* Fix include "qapi/qapi-commands-net.h".
* Underscores to dashes.
* "Since 2.13" now.

v2: Fix compiler error. [patchew]

The command is a counterpart of HMP "info usernet" and is at least very useful for the VM tests. So add it.

Fam Zheng (4):
qapi: Introduce UsernetTcpState
slirp: Use QAPI enum to replace TCPS_* macros
slirp: Add "query-usernet" QMP command
tests: Use query-usernet instead of 'info usernet'

 net/slirp.c        |  26 +++++++
 qapi/net.json      | 214 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 slirp/libslirp.h   |   2 +
 slirp/misc.c       | 159 ++++++++++++++++++++++++++++-----------
 slirp/tcp.h        |  21 +-----
 slirp/tcp_input.c  | 103 +++++++++++++-------------
 slirp/tcp_subr.c   |  25 ++++---
 slirp/tcp_timer.c  |   7 +-
 tests/vm/basevm.py |  14 ++--
 9 files changed, 435 insertions(+), 136 deletions(-)
Signature · 1 line
2.14.3
author
#1 lore raw

PATCH v6 1/4 qapi: Introduce UsernetTcpState

This will be a drop-in replacement for the current TCPS_ macro/enum and what we will return to users in the coming qmp command.

The next patch will drop TCPS_ to avoid duplication and keep further refactoring simple.

---
 qapi/net.json | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
qapi/net.json +34 -0
index 9117c56972..fcddce62d6 100644
@@ -689,3 +689,37 @@
 ##
 { 'event': 'NIC_RX_FILTER_CHANGED',
   'data': { '*name': 'str', 'path': 'str' } }
+
+##
+# @UsernetTcpState:
+#
+# TCP States of a SLIRP connection.
+#
+# - States where connections are not established: none, closed, listen, syn-sent,
+#   syn-received
+#
+# - States where user has closed: fin-wait-1, closing, last-ack, fin-wait-2,
+#   time-wait
+#
+# - States awaiting ACK of FIN: fin-wait-1, closing, last-ack
+#
+# 'none' state is used only when host forwarding
+#
+# Since 2.13
+#
+##
+{ 'enum': 'UsernetTcpState',
+  'data':
+   ['closed',
+    'listen',
+    'syn-sent',
+    'syn-received',
+    'established',
+    'close-wait',
+    'fin-wait-1',
+    'closing',
+    'last-ack',
+    'fin-wait-2',
+    'time-wait',
+    'none'
+   ] }
Signature · 1 line
2.14.3
author
#2 lore raw

PATCH v6 2/4 slirp: Use QAPI enum to replace TCPS_* macros

In reply to Fam Zheng

This is a mechanical patch that does search-and-replace and adding necessary "#include" for pulling in the QAPI enum definition. The string lookup could use the QAPI helper, and is left for the next patch.

---
 slirp/misc.c      |  23 ++++++------
 slirp/tcp.h       |  21 ++---------
 slirp/tcp_input.c | 103 +++++++++++++++++++++++++++---------------------------
 slirp/tcp_subr.c  |  25 ++++++-------
 slirp/tcp_timer.c |   7 ++--
 5 files changed, 84 insertions(+), 95 deletions(-)
slirp/misc.c +12 -11
index 260187b6b6..ee617bc3c4 100644
@@ -11,6 +11,7 @@
 #include "monitor/monitor.h"
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
+#include "qapi/qapi-commands-net.h"
 
 #ifdef DEBUG
 int slirp_debug = DBG_CALL|DBG_MISC|DBG_ERROR;
@@ -208,17 +209,17 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
 void slirp_connection_info(Slirp *slirp, Monitor *mon)
 {
     const char * const tcpstates[] = {
-        [TCPS_CLOSED]       = "CLOSED",
-        [TCPS_LISTEN]       = "LISTEN",
-        [TCPS_SYN_SENT]     = "SYN_SENT",
-        [TCPS_SYN_RECEIVED] = "SYN_RCVD",
-        [TCPS_ESTABLISHED]  = "ESTABLISHED",
-        [TCPS_CLOSE_WAIT]   = "CLOSE_WAIT",
-        [TCPS_FIN_WAIT_1]   = "FIN_WAIT_1",
-        [TCPS_CLOSING]      = "CLOSING",
-        [TCPS_LAST_ACK]     = "LAST_ACK",
-        [TCPS_FIN_WAIT_2]   = "FIN_WAIT_2",
-        [TCPS_TIME_WAIT]    = "TIME_WAIT",
+        [USERNET_TCP_STATE_CLOSED]       = "CLOSED",
+        [USERNET_TCP_STATE_LISTEN]       = "LISTEN",
+        [USERNET_TCP_STATE_SYN_SENT]     = "SYN_SENT",
+        [USERNET_TCP_STATE_SYN_RECEIVED] = "SYN_RCVD",
+        [USERNET_TCP_STATE_ESTABLISHED]  = "ESTABLISHED",
+        [USERNET_TCP_STATE_CLOSE_WAIT]   = "CLOSE_WAIT",
+        [USERNET_TCP_STATE_FIN_WAIT_1]   = "FIN_WAIT_1",
+        [USERNET_TCP_STATE_CLOSING]      = "CLOSING",
+        [USERNET_TCP_STATE_LAST_ACK]     = "LAST_ACK",
+        [USERNET_TCP_STATE_FIN_WAIT_2]   = "FIN_WAIT_2",
+        [USERNET_TCP_STATE_TIME_WAIT]    = "TIME_WAIT",
     };
     struct in_addr dst_addr;
     struct sockaddr_in src;
slirp/tcp.h +3 -18
index 174d3d960c..f766e684e6 100644
@@ -133,24 +133,9 @@ struct tcphdr {
 
 #define TCP_NSTATES     11
 
-#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 */
-
-#define TCPS_HAVERCVDSYN(s)     ((s) >= TCPS_SYN_RECEIVED)
-#define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED)
-#define TCPS_HAVERCVDFIN(s)     ((s) >= TCPS_TIME_WAIT)
+#define TCPS_HAVERCVDSYN(s)     ((s) >= USERNET_TCP_STATE_SYN_RECEIVED)
+#define TCPS_HAVEESTABLISHED(s) ((s) >= USERNET_TCP_STATE_ESTABLISHED)
+#define TCPS_HAVERCVDFIN(s)     ((s) >= USERNET_TCP_STATE_TIME_WAIT)
 
 /*
  * TCP sequence numbers are 32 bit integers operated
slirp/tcp_input.c +52 -51

295 lines not on this page · raw message

slirp/tcp_subr.c +13 -12
index da0d53743f..8dd5a70044 100644
@@ -40,6 +40,7 @@
 
 #include "qemu/osdep.h"
 #include "slirp.h"
+#include "qapi/qapi-commands-net.h"
 
 /* patchable/settable parameters for tcp */
 /* Don't do rfc1323 performance enhancements */
@@ -282,7 +283,7 @@ tcp_newtcpcb(struct socket *so)
 
 	tp->snd_cwnd = TCP_MAXWIN << TCP_MAX_WINSHIFT;
 	tp->snd_ssthresh = TCP_MAXWIN << TCP_MAX_WINSHIFT;
-	tp->t_state = TCPS_CLOSED;
+	tp->t_state = USERNET_TCP_STATE_CLOSED;
 
 	so->so_tcpcb = tp;
 
@@ -301,7 +302,7 @@ struct tcpcb *tcp_drop(struct tcpcb *tp, int err)
 	DEBUG_ARG("errno = %d", errno);
 
 	if (TCPS_HAVERCVDSYN(tp->t_state)) {
-		tp->t_state = TCPS_CLOSED;
+		tp->t_state = USERNET_TCP_STATE_CLOSED;
 		(void) tcp_output(tp);
 	}
 	return (tcp_close(tp));
@@ -371,20 +372,20 @@ tcp_sockclosed(struct tcpcb *tp)
 
 	switch (tp->t_state) {
 
-	case TCPS_CLOSED:
-	case TCPS_LISTEN:
-	case TCPS_SYN_SENT:
-		tp->t_state = TCPS_CLOSED;
+	case USERNET_TCP_STATE_CLOSED:
+	case USERNET_TCP_STATE_LISTEN:
+	case USERNET_TCP_STATE_SYN_SENT:
+		tp->t_state = USERNET_TCP_STATE_CLOSED;
 		tp = tcp_close(tp);
 		break;
 
-	case TCPS_SYN_RECEIVED:
-	case TCPS_ESTABLISHED:
-		tp->t_state = TCPS_FIN_WAIT_1;
+	case USERNET_TCP_STATE_SYN_RECEIVED:
+	case USERNET_TCP_STATE_ESTABLISHED:
+		tp->t_state = USERNET_TCP_STATE_FIN_WAIT_1;
 		break;
 
-	case TCPS_CLOSE_WAIT:
-		tp->t_state = TCPS_LAST_ACK;
+	case USERNET_TCP_STATE_CLOSE_WAIT:
+		tp->t_state = USERNET_TCP_STATE_LAST_ACK;
 		break;
 	}
 	tcp_output(tp);
@@ -513,7 +514,7 @@ void tcp_connect(struct socket *inso)
 
     tcp_template(tp);
 
-    tp->t_state = TCPS_SYN_SENT;
+    tp->t_state = USERNET_TCP_STATE_SYN_SENT;
     tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
     tp->iss = slirp->tcp_iss;
     slirp->tcp_iss += TCP_ISSINCR/2;
slirp/tcp_timer.c +4 -3
index 52ef5f9100..d45dfe2da8 100644
@@ -32,6 +32,7 @@
 
 #include "qemu/osdep.h"
 #include "slirp.h"
+#include "qapi/qapi-commands-net.h"
 
 static struct tcpcb *tcp_timers(register struct tcpcb *tp, int timer);
 
@@ -135,7 +136,7 @@ tcp_timers(register struct tcpcb *tp, int timer)
 	 * control block.  Otherwise, check again in a bit.
 	 */
 	case TCPT_2MSL:
-		if (tp->t_state != TCPS_TIME_WAIT &&
+		if (tp->t_state != USERNET_TCP_STATE_TIME_WAIT &&
 		    tp->t_idle <= TCP_MAXIDLE)
 			tp->t_timer[TCPT_2MSL] = TCPTV_KEEPINTVL;
 		else
@@ -259,10 +260,10 @@ tcp_timers(register struct tcpcb *tp, int timer)
 	 * or drop connection if idle for too long.
 	 */
 	case TCPT_KEEP:
-		if (tp->t_state < TCPS_ESTABLISHED)
+		if (tp->t_state < USERNET_TCP_STATE_ESTABLISHED)
 			goto dropit;
 
-		if ((SO_OPTIONS) && tp->t_state <= TCPS_CLOSE_WAIT) {
+		if ((SO_OPTIONS) && tp->t_state <= USERNET_TCP_STATE_CLOSE_WAIT) {
 		    	if (tp->t_idle >= TCPTV_KEEP_IDLE + TCP_MAXIDLE)
 				goto dropit;
 			/*
Signature · 1 line
2.14.3
#3 lore raw

Re: [Qemu-devel] [PATCH v6 2/4] slirp: Use QAPI enum to replace TCPS_* macros

Quoted 18 lines · Fam Zheng

This is a mechanical patch that does search-and-replace and adding necessary "#include" for pulling in the QAPI enum definition. The string lookup could use the QAPI helper, and is left for the next patch.

---
 slirp/misc.c      |  23 ++++++------
 slirp/tcp.h       |  21 ++---------
 slirp/tcp_input.c | 103 +++++++++++++++++++++++++++---------------------------
 slirp/tcp_subr.c  |  25 ++++++-------
 slirp/tcp_timer.c |   7 ++--
 5 files changed, 84 insertions(+), 95 deletions(-)
slirp/misc.c +0 -0
index 260187b6b6..ee617bc3c4 100644

slirp/misc.c line 14

Quoted 4 lines
slirp/misc.c +1 -0
@@ -11,6 +11,7 @@
 #include "monitor/monitor.h"
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
+#include "qapi/qapi-commands-net.h"

Uh, why doesn't "qapi/qapi-types-net.h" suffice?

Same elsewhere.

Quoted 22 lines
slirp/misc.c +4 -11
 #ifdef DEBUG
 int slirp_debug = DBG_CALL|DBG_MISC|DBG_ERROR;
@@ -208,17 +209,17 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
 void slirp_connection_info(Slirp *slirp, Monitor *mon)
 {
     const char * const tcpstates[] = {
-        [TCPS_CLOSED]       = "CLOSED",
-        [TCPS_LISTEN]       = "LISTEN",
-        [TCPS_SYN_SENT]     = "SYN_SENT",
-        [TCPS_SYN_RECEIVED] = "SYN_RCVD",
-        [TCPS_ESTABLISHED]  = "ESTABLISHED",
-        [TCPS_CLOSE_WAIT]   = "CLOSE_WAIT",
-        [TCPS_FIN_WAIT_1]   = "FIN_WAIT_1",
-        [TCPS_CLOSING]      = "CLOSING",
-        [TCPS_LAST_ACK]     = "LAST_ACK",
-        [TCPS_FIN_WAIT_2]   = "FIN_WAIT_2",
-        [TCPS_TIME_WAIT]    = "TIME_WAIT",
+        [USERNET_TCP_STATE_CLOSED]       = "CLOSED",
+        [USERNET_TCP_STATE_LISTEN]       = "LISTEN",
+        [USERNET_TCP_STATE_SYN_SENT]     = "SYN_SENT",
+        [USERNET_TCP_STATE_SYN_RECEIVED] = "SYN_RCVD",

slirp/misc.c fork_exec(struct socket *so, const char *ex, int do_pty) · line 225

Quoted 10 lines
slirp/misc.c +7 -0
+        [USERNET_TCP_STATE_ESTABLISHED]  = "ESTABLISHED",
+        [USERNET_TCP_STATE_CLOSE_WAIT]   = "CLOSE_WAIT",
+        [USERNET_TCP_STATE_FIN_WAIT_1]   = "FIN_WAIT_1",
+        [USERNET_TCP_STATE_CLOSING]      = "CLOSING",
+        [USERNET_TCP_STATE_LAST_ACK]     = "LAST_ACK",
+        [USERNET_TCP_STATE_FIN_WAIT_2]   = "FIN_WAIT_2",
+        [USERNET_TCP_STATE_TIME_WAIT]    = "TIME_WAIT",
     };
     struct in_addr dst_addr;
     struct sockaddr_in src;

This is "the string lookup" mentioned in the commit message.

slirp/tcp.h struct tcphdr {

Quoted 5 lines
slirp/tcp.h +0 -0
index 174d3d960c..f766e684e6 100644
@@ -133,24 +133,9 @@ struct tcphdr {

/*
* TCP FSM state definitions.
* Per RFC793, September, 1981.
*/

slirp/tcp.h struct tcphdr { · line 134

Quoted 2 lines
slirp/tcp.h +0 -0
 #define TCP_NSTATES     11

Let's replace this one by USERNET_TCP_STATE_NONE or USERNET_TCP_STATE__MAX - 1.

Quoted 5 lines
slirp/tcp.h +0 -4
-#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 */

slirp/tcp.h struct tcphdr { · line 149

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

The replacements added in the previous patch lack these comments. Should we copy them over? Including the reference to RFC793 above.

slirp/tcp.h struct tcphdr { · line 138

Quoted 7 lines
slirp/tcp.h +3 -4
-
-#define TCPS_HAVERCVDSYN(s)     ((s) >= TCPS_SYN_RECEIVED)
-#define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED)
-#define TCPS_HAVERCVDFIN(s)     ((s) >= TCPS_TIME_WAIT)
+#define TCPS_HAVERCVDSYN(s)     ((s) >= USERNET_TCP_STATE_SYN_RECEIVED)
+#define TCPS_HAVEESTABLISHED(s) ((s) >= USERNET_TCP_STATE_ESTABLISHED)
+#define TCPS_HAVERCVDFIN(s)     ((s) >= USERNET_TCP_STATE_TIME_WAIT)

New in the previous patch is USERNET_TCP_STATE_NONE. Are these macros prepared for it? The comments on _NONE make me doubt:

+# - States where connections are not established: none, closed, listen, syn-sent,
+# syn-received

Yet TCPS_HAVEESTABLISHED(USERNET_TCP_STATE_NONE) yields true.

+# 'none' state is used only when host forwarding

Should we document that it must not be passed to these macros?

Do we really need USERNET_TCP_STATE_NONE? See next patch.

slirp/tcp.h struct tcphdr { · line 141

Quoted 3 lines
slirp/tcp.h +0 -0
 /*
  * TCP sequence numbers are 32 bit integers operated

[Remainder of the patch snipped; it looks completely mechanical]

author
#4 lore raw

PATCH v6 3/4 slirp: Add "query-usernet" QMP command

In reply to Fam Zheng

HMP "info usernet" has been available but it isn't ideal for programmed use cases. This closes the gap in QMP by adding a counterpart "query-usernet" command. It is basically translated from
the HMP slirp_connection_info() loop, which now calls the QMP implementation and prints the data, just like other HMP info_* commands.

---
 net/slirp.c      |  26 ++++++++
 qapi/net.json    | 180 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 slirp/libslirp.h |   2 +
 slirp/misc.c     | 158 ++++++++++++++++++++++++++++++++++--------------
 4 files changed, 321 insertions(+), 45 deletions(-)
net/slirp.c +26 -0
index 8991816bbf..9c48a882ec 100644
@@ -36,6 +36,7 @@
 #include "monitor/monitor.h"
 #include "qemu/error-report.h"
 #include "qemu/sockets.h"
+#include "slirp/slirp.h"
 #include "slirp/libslirp.h"
 #include "slirp/ip6.h"
 #include "chardev/char-fe.h"
@@ -43,6 +44,7 @@
 #include "qemu/cutils.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
+#include "qapi/qapi-commands-net.h"
 
 static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
 {
@@ -864,6 +866,30 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str,
     return -1;
 }
 
+UsernetInfoList *qmp_query_usernet(Error **errp)
+{
+    SlirpState *s;
+    UsernetInfoList *list = NULL;
+    UsernetInfoList **p = &list;
+
+    QTAILQ_FOREACH(s, &slirp_stacks, entry) {
+        int hub;
+        UsernetInfoList *il = g_new0(UsernetInfoList, 1);
+        UsernetInfo *info = il->value = g_new0(UsernetInfo, 1);
+
+        info->id = g_strdup(s->nc.name);
+        if (!net_hub_id_for_client(&s->nc, &hub)) {
+            info->hub = hub;
+        } else {
+            info->hub = -1;
+        }
+        usernet_get_info(s->slirp, info);
+        *p = il;
+        p = &il->next;
+    }
+    return list;
+}
+
 void hmp_info_usernet(Monitor *mon, const QDict *qdict)
 {
     SlirpState *s;
qapi/net.json +180 -0

183 lines not on this page · raw message

slirp/libslirp.h +2 -0
index 540b3e5903..3ba361ea41 100644
@@ -2,6 +2,7 @@
 #define LIBSLIRP_H
 
 #include "qemu-common.h"
+#include "qapi/qapi-commands-net.h"
 
 typedef struct Slirp Slirp;
 
@@ -37,6 +38,7 @@ int slirp_add_exec(Slirp *slirp, int do_pty, const void *args,
                    struct in_addr *guest_addr, int guest_port);
 
 void slirp_connection_info(Slirp *slirp, Monitor *mon);
+void usernet_get_info(Slirp *slirp, UsernetInfo *info);
 
 void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr,
                        int guest_port, const uint8_t *buf, int size);
slirp/misc.c +113 -45

198 lines not on this page · raw message

Signature · 1 line
2.14.3
#5 lore raw

Re: [Qemu-devel] [PATCH v6 3/4] slirp: Add "query-usernet" QMP command

Quoted 55 lines · Fam Zheng

HMP "info usernet" has been available but it isn't ideal for programmed use cases. This closes the gap in QMP by adding a counterpart "query-usernet" command. It is basically translated from
the HMP slirp_connection_info() loop, which now calls the QMP implementation and prints the data, just like other HMP info_* commands.

---
 net/slirp.c      |  26 ++++++++
 qapi/net.json    | 180 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 slirp/libslirp.h |   2 +
 slirp/misc.c     | 158 ++++++++++++++++++++++++++++++++++--------------
 4 files changed, 321 insertions(+), 45 deletions(-)
net/slirp.c +19 -0
index 8991816bbf..9c48a882ec 100644
@@ -36,6 +36,7 @@
 #include "monitor/monitor.h"
 #include "qemu/error-report.h"
 #include "qemu/sockets.h"
+#include "slirp/slirp.h"
 #include "slirp/libslirp.h"
 #include "slirp/ip6.h"
 #include "chardev/char-fe.h"
@@ -43,6 +44,7 @@
 #include "qemu/cutils.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
+#include "qapi/qapi-commands-net.h"
 
 static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
 {
@@ -864,6 +866,30 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str,
     return -1;
 }
 
+UsernetInfoList *qmp_query_usernet(Error **errp)
+{
+    SlirpState *s;
+    UsernetInfoList *list = NULL;
+    UsernetInfoList **p = &list;
+
+    QTAILQ_FOREACH(s, &slirp_stacks, entry) {
+        int hub;
+        UsernetInfoList *il = g_new0(UsernetInfoList, 1);
+        UsernetInfo *info = il->value = g_new0(UsernetInfo, 1);
+
+        info->id = g_strdup(s->nc.name);
+        if (!net_hub_id_for_client(&s->nc, &hub)) {
+            info->hub = hub;
+        } else {
+            info->hub = -1;
+        }

net/slirp.c static int slirp_guestfwd(SlirpState *s, const char *config_str, · line 895

Quoted 10 lines
net/slirp.c +7 -0
+        usernet_get_info(s->slirp, info);
+        *p = il;
+        p = &il->next;
+    }
+    return list;
+}
+
 void hmp_info_usernet(Monitor *mon, const QDict *qdict)
 {
     SlirpState *s;
       QTAILQ_FOREACH(s, &slirp_stacks, entry) {
           int id;
           bool got_hub_id = net_hub_id_for_client(&s->nc, &id) == 0;
           monitor_printf(mon, "Hub %d (%s):\n",
                          got_hub_id ? id : -1,
                          s->nc.name);
           slirp_connection_info(s->slirp, mon);
       }

}

Our policy is to have HMP commands wrap themselves around QMP commands, or at least common helpers. That way, "QMP can do everything HMP can do" is trivial.

hmp_info_usernet() uses common helpers net_hub_id_for_client(), s->nc.name, usernet_get_info(), the latter via slirp_connection_info(). I guess that's okay, although wrapping around qmp_query_usernet() would be cleaner.

Quoted 9 lines
qapi/net.json +1 -0
index fcddce62d6..3cdcda125d 100644
@@ -723,3 +723,183 @@
     'time-wait',
     'none'
    ] }
+

qapi/net.json line 736

Quoted 10 lines
qapi/net.json +10 -0
+##
+# @UsernetTCPConnection:
+#
+# SLIRP TCP information.
+#
+# @state: tcp connection state
+#
+# @hostfwd: whether this connection has host port forwarding
+#
+# @fd: the file descriptor of the connection

Why is @fd useful? Hmm, I guess the argument is "info usernet has always printed it". Is it useful there?

Quoted 12 lines
qapi/net.json +12 -0
+#
+# @src-addr: source address of host port forwarding
+#
+# @src-port: source port of host port forwarding
+#
+# @dest-addr: destination address of host port forwarding
+#
+# @dest-port: destination port of host port forwarding
+#
+# @recv-buffered: number of bytes queued in the receive buffer
+#
+# @send-buffered: number of bytes queued in the send buffer

qapi/net.json line 758

Quoted 10 lines
qapi/net.json +10 -0
+#
+# Since: 2.13
+##
+{ 'struct': 'UsernetTCPConnection',
+  'data': {
+    'state': 'UsernetTcpState',
+    'hostfwd': 'bool',
+    'fd': 'int',
+    'src-addr': 'str',
+    'src-port': 'int',

Shouldn't these two be an InetSocketAddressBase instead?

qapi/net.json line 760

Quoted 2 lines
qapi/net.json +2 -0
+    'dest-addr': 'str',
+    'dest-port': 'int',

Likewise.

qapi/net.json line 762

Quoted 2 lines
qapi/net.json +2 -0
+    'recv-buffered': 'int',
+    'send-buffered': 'int'

Make these 'uint32' to match the type of struct sbuf member sb_cc.

Quoted 21 lines
qapi/net.json +21 -0
+  } }
+
+##
+# @UsernetUDPConnection:
+#
+# SLIRP UDP information.
+#
+# @hostfwd: whether this connection has host port forwarding
+#
+# @expire-time-ms: time in microseconds after which this connection will expire
+#
+# @fd: the file descriptor of the connection
+#
+# @src-addr: source address of host port forwarding
+#
+# @src-port: source port of host port forwarding
+#
+# @dest-addr: destination address of host port forwarding
+#
+# @dest-port: destination port of host port forwarding
+#

qapi/net.json line 793

Quoted 10 lines
qapi/net.json +10 -0
+# @recv-buffered: number of bytes queued in the receive buffer
+#
+# @send-buffered: number of bytes queued in the send buffer
+#
+# Since: 2.13
+##
+{ 'struct': 'UsernetUDPConnection',
+  'data': {
+    'hostfwd': 'bool',
+    'expire-time-ms': 'int',

'uint', to match the type of so->so_expire - curtime.

qapi/net.json line 763

Quoted 8 lines
qapi/net.json +8 -0
+    'fd': 'int',
+    'src-addr': 'str',
+    'src-port': 'int',
+    'dest-addr': 'str',
+    'dest-port': 'int',
+    'recv-buffered': 'int',
+    'send-buffered': 'int'
+    } }

Remarks on UsernetTCPConnection apply.

Quoted 19 lines
qapi/net.json +19 -0
+
+##
+# @UsernetICMPConnection:
+#
+# SLIRP ICMP information.
+#
+# @expire-time-ms: time in microseconds after which this connection will expire
+#
+# @fd: the file descriptor of the connection
+#
+# @src-addr: source address of host port forwarding
+#
+# @dest-addr: destination address of host port forwarding
+#
+# @recv-buffered: number of bytes queued in the receive buffer
+#
+# @send-buffered: number of bytes queued in the send buffer
+#
+# Since: 2.13

qapi/net.json line 830

Quoted 10 lines
qapi/net.json +10 -0
+##
+{ 'struct': 'UsernetICMPConnection',
+  'data': {
+    'expire-time-ms': 'int',
+    'fd': 'int',
+    'src-addr': 'str',
+    'dest-addr': 'str',
+    'recv-buffered': 'int',
+    'send-buffered': 'int'
+    } }

Remarks on UsernetTCPConnection and UsernetUDPConnection apply.

Quoted 80 lines
qapi/net.json +75 -0
+
+##
+# @UsernetType:
+#
+# Available netdev drivers.
+#
+# Since: 2.13
+##
+{ 'enum': 'UsernetType',
+  'data': [ 'tcp', 'udp', 'icmp' ] }
+
+##
+# @UsernetConnection:
+#
+# SLIRP usernet connection information.
+#
+# Since: 2.13
+##
+{ 'union': 'UsernetConnection',
+  'discriminator': 'type',
+  'base': { 'type': 'UsernetType' },
+  'data': {
+    'tcp':     'UsernetTCPConnection',
+    'udp':     'UsernetUDPConnection',
+    'icmp':    'UsernetICMPConnection'
+    } }
+
+##
+# @UsernetInfo:
+#
+# SLIRP usernet information.
+#
+# Since: 2.13
+##
+{ 'struct': 'UsernetInfo',
+  'data': {
+    'id':              'str',
+    'hub':             'int',
+    'connections':     ['UsernetConnection']
+} }
+
+##
+# @query-usernet:
+#
+# Return SLIRP network information.
+#
+# Since: 2.13
+#
+# Example:
+#
+# -> { "execute": "query-usernet", "arguments": { } }
+# <- { "return": [
+#      {
+#        "hub": -1,
+#        "connections": [
+#          {
+#            "dest-addr": "10.0.2.15",
+#            "recv-buffered": 0,
+#            "src-port": 10022,
+#            "state": "closed",
+#            "fd": 16,
+#            "src-addr": "*",
+#            "send-buffered": 0,
+#            "dest-port": 22,
+#            "type": "tcp",
+#            "hostfwd": true
+#          }
+#        ],
+#        "id": "vnet"
+#      }
+#   ]}
+#
+##
+{ 'command': 'query-usernet',
+  'returns': ['UsernetInfo'] }
slirp/libslirp.h +0 -0
index 540b3e5903..3ba361ea41 100644

slirp/libslirp.h line 5

Quoted 4 lines
slirp/libslirp.h +1 -0
@@ -2,6 +2,7 @@
 #define LIBSLIRP_H
 
 #include "qemu-common.h"
+#include "qapi/qapi-commands-net.h"

"qapi/qapi-types-net.h"?

slirp/libslirp.h int slirp_add_exec(Slirp *slirp, int do_pty, const void *args, · line 44

Quoted 11 lines
slirp/libslirp.h +1 -0
 typedef struct Slirp Slirp;
 
@@ -37,6 +38,7 @@ int slirp_add_exec(Slirp *slirp, int do_pty, const void *args,
                    struct in_addr *guest_addr, int guest_port);
 
 void slirp_connection_info(Slirp *slirp, Monitor *mon);
+void usernet_get_info(Slirp *slirp, UsernetInfo *info);
 
 void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr,
                        int guest_port, const uint8_t *buf, int size);

I'm only skimming the remainder of this patch for now.

Quoted 90 lines
slirp/misc.c +27 -31
index ee617bc3c4..1d310d7d1f 100644
@@ -206,39 +206,28 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
 }
 #endif
 
-void slirp_connection_info(Slirp *slirp, Monitor *mon)
+void usernet_get_info(Slirp *slirp, UsernetInfo *info)
 {
-    const char * const tcpstates[] = {
-        [USERNET_TCP_STATE_CLOSED]       = "CLOSED",
-        [USERNET_TCP_STATE_LISTEN]       = "LISTEN",
-        [USERNET_TCP_STATE_SYN_SENT]     = "SYN_SENT",
-        [USERNET_TCP_STATE_SYN_RECEIVED] = "SYN_RCVD",
-        [USERNET_TCP_STATE_ESTABLISHED]  = "ESTABLISHED",
-        [USERNET_TCP_STATE_CLOSE_WAIT]   = "CLOSE_WAIT",
-        [USERNET_TCP_STATE_FIN_WAIT_1]   = "FIN_WAIT_1",
-        [USERNET_TCP_STATE_CLOSING]      = "CLOSING",
-        [USERNET_TCP_STATE_LAST_ACK]     = "LAST_ACK",
-        [USERNET_TCP_STATE_FIN_WAIT_2]   = "FIN_WAIT_2",
-        [USERNET_TCP_STATE_TIME_WAIT]    = "TIME_WAIT",
-    };
     struct in_addr dst_addr;
     struct sockaddr_in src;
     socklen_t src_len;
     uint16_t dst_port;
     struct socket *so;
-    const char *state;
-    char buf[20];
-
-    monitor_printf(mon, "  Protocol[State]    FD  Source Address  Port   "
-                        "Dest. Address  Port RecvQ SendQ\n");
+    UsernetConnectionList **p_next = &info->connections;
 
     for (so = slirp->tcb.so_next; so != &slirp->tcb; so = so->so_next) {
+        UsernetConnection *conn = g_new0(UsernetConnection, 1);
+        UsernetTCPConnection *tcp = &conn->u.tcp;
+        UsernetConnectionList *list = g_new0(UsernetConnectionList, 1);
+
+        list->value = conn;
         if (so->so_state & SS_HOSTFWD) {
-            state = "HOST_FORWARD";
+            tcp->hostfwd = true;
+            tcp->state = so->so_tcpcb->t_state;
         } else if (so->so_tcpcb) {
-            state = tcpstates[so->so_tcpcb->t_state];
+            tcp->state = so->so_tcpcb->t_state;
         } else {
-            state = "NONE";
+            tcp->state = USERNET_TCP_STATE_NONE;
         }
         if (so->so_state & (SS_HOSTFWD | SS_INCOMING)) {
             src_len = sizeof(src);
@@ -251,46 +240,125 @@ void slirp_connection_info(Slirp *slirp, Monitor *mon)
             dst_addr = so->so_faddr;
             dst_port = so->so_fport;
         }
-        snprintf(buf, sizeof(buf), "  TCP[%s]", state);
-        monitor_printf(mon, "%-19s %3d %15s %5d ", buf, so->s,
-                       src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*",
-                       ntohs(src.sin_port));
-        monitor_printf(mon, "%15s %5d %5d %5d\n",
-                       inet_ntoa(dst_addr), ntohs(dst_port),
-                       so->so_rcv.sb_cc, so->so_snd.sb_cc);
+        tcp->fd = so->s;
+        tcp->src_addr =
+            g_strdup(src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*");
+        tcp->src_port = ntohs(src.sin_port);
+        tcp->dest_addr = g_strdup(inet_ntoa(dst_addr));
+        tcp->dest_port = ntohs(dst_port);
+        tcp->recv_buffered = so->so_rcv.sb_cc;
+        tcp->send_buffered = so->so_snd.sb_cc;
+        *p_next = list;
+        p_next = &list->next;
     }
-
     for (so = slirp->udb.so_next; so != &slirp->udb; so = so->so_next) {
+        UsernetConnection *conn = g_new0(UsernetConnection, 1);
+        UsernetUDPConnection *udp = &conn->u.udp;
+        UsernetConnectionList *list = g_new0(UsernetConnectionList, 1);
+
+        list->value = conn;
         if (so->so_state & SS_HOSTFWD) {
-            snprintf(buf, sizeof(buf), "  UDP[HOST_FORWARD]");
+            udp->hostfwd = true;
             src_len = sizeof(src);
             getsockname(so->s, (struct sockaddr *)&src, &src_len);
             dst_addr = so->so_laddr;

slirp/misc.c void slirp_connection_info(Slirp *slirp, Monitor *mon) · line 272

Quoted 10 lines
slirp/misc.c +1 -2
             dst_port = so->so_lport;
         } else {
-            snprintf(buf, sizeof(buf), "  UDP[%d sec]",
-                         (so->so_expire - curtime) / 1000);
+            udp->expire_time_ms = so->so_expire - curtime;
             src.sin_addr = so->so_laddr;
             src.sin_port = so->so_lport;
             dst_addr = so->so_faddr;
             dst_port = so->so_fport;
         }

@expire_time_ms appears to be left at zero when @hostfwd is true. Should it be optional?

Quoted 104 lines
slirp/misc.c +85 -12
-        monitor_printf(mon, "%-19s %3d %15s %5d ", buf, so->s,
-                       src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*",
-                       ntohs(src.sin_port));
-        monitor_printf(mon, "%15s %5d %5d %5d\n",
-                       inet_ntoa(dst_addr), ntohs(dst_port),
-                       so->so_rcv.sb_cc, so->so_snd.sb_cc);
+        udp->fd = so->s;
+        udp->src_addr =
+            g_strdup(src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*");
+        udp->src_port = ntohs(src.sin_port);
+        udp->dest_addr = g_strdup(inet_ntoa(dst_addr));
+        udp->dest_port = ntohs(dst_port);
+        udp->recv_buffered = so->so_rcv.sb_cc;
+        udp->send_buffered = so->so_snd.sb_cc;
+        *p_next = list;
+        p_next = &list->next;
     }
 
     for (so = slirp->icmp.so_next; so != &slirp->icmp; so = so->so_next) {
-        snprintf(buf, sizeof(buf), "  ICMP[%d sec]",
-                     (so->so_expire - curtime) / 1000);
+        UsernetConnection *conn = g_new0(UsernetConnection, 1);
+        UsernetICMPConnection *icmp = &conn->u.icmp;
+        UsernetConnectionList *list = g_new0(UsernetConnectionList, 1);
+
+        icmp->expire_time_ms = so->so_expire - curtime;
         src.sin_addr = so->so_laddr;
         dst_addr = so->so_faddr;
-        monitor_printf(mon, "%-19s %3d %15s  -    ", buf, so->s,
-                       src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*");
-        monitor_printf(mon, "%15s  -    %5d %5d\n", inet_ntoa(dst_addr),
-                       so->so_rcv.sb_cc, so->so_snd.sb_cc);
+        icmp->fd = so->s;
+        icmp->src_addr =
+            g_strdup(src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*");
+        icmp->dest_addr = g_strdup(inet_ntoa(dst_addr));
+        icmp->recv_buffered = so->so_rcv.sb_cc;
+        icmp->send_buffered = so->so_snd.sb_cc;
+        *p_next = list;
+        p_next = &list->next;
     }
 }
+
+
+void slirp_connection_info(Slirp *slirp, Monitor *mon)
+{
+    const char *state;
+    char buf[64];
+    UsernetInfo *info = g_new0(UsernetInfo, 1);
+    UsernetConnectionList *cl;
+
+    monitor_printf(mon, "  Protocol[State]    FD  Source Address  Port   "
+                        "Dest. Address  Port RecvQ SendQ\n");
+
+    usernet_get_info(slirp, info);
+    for (cl = info->connections; cl && cl->value; cl = cl->next) {
+        UsernetConnection *conn = cl->value;
+
+        if (conn->type == USERNET_TYPE_TCP) {
+            UsernetTCPConnection *tcp = &conn->u.tcp;
+
+            if (tcp->hostfwd) {
+                state = "HOST_FORWARD";
+            } else {
+                state = UsernetTcpState_str(tcp->state);
+            }
+            snprintf(buf, sizeof(buf), "  TCP[%s]", state);
+            monitor_printf(mon, "%-19s %3" PRId64 " %15s %5" PRId64 " ",
+                           buf, tcp->fd,
+                           tcp->src_addr, tcp->src_port);
+            monitor_printf(mon, "%15s %5" PRId64 " %5" PRId64 " %5" PRId64 "\n",
+                           tcp->dest_addr, tcp->dest_port,
+                           tcp->recv_buffered, tcp->send_buffered);
+        } else if (conn->type == USERNET_TYPE_UDP) {
+            UsernetUDPConnection *udp = &conn->u.udp;
+
+            if (udp->hostfwd) {
+                snprintf(buf, sizeof(buf), "  UDP[HOST_FORWARD]");
+            } else {
+                snprintf(buf, sizeof(buf), "  UDP[%" PRId64 " sec]",
+                         udp->expire_time_ms / 1000);
+            }
+            monitor_printf(mon, "%-19s %3" PRId64 " %15s %5" PRId64 " ",
+                           buf, udp->fd,
+                           udp->src_addr, udp->src_port);
+            monitor_printf(mon, "%15s %5" PRId64 " %5" PRId64 " %5" PRId64 "\n",
+                           udp->dest_addr, udp->dest_port,
+                           udp->recv_buffered, udp->send_buffered);
+        } else {
+            UsernetICMPConnection *icmp = &conn->u.icmp;
+
+            assert(conn->type == USERNET_TYPE_ICMP);
+            snprintf(buf, sizeof(buf), "  ICMP[%" PRId64 " sec]",
+                     icmp->expire_time_ms / 1000);
+            monitor_printf(mon, "%-19s %3" PRId64 " %15s  -    ", buf, icmp->fd,
+                           icmp->src_addr);
+            monitor_printf(mon, "%15s  -    %5" PRId64 " %5" PRId64 "\n",
+                           icmp->dest_addr,
+                           icmp->recv_buffered, icmp->send_buffered);
+        }
+    }
+
+    qapi_free_UsernetInfo(info);
+}
author
#6 lore raw

PATCH v6 4/4 tests: Use query-usernet instead of 'info usernet'

In reply to Fam Zheng
---
 tests/vm/basevm.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
tests/vm/basevm.py +7 -7
index 3a2d508c35..dcfa6597ad 100755
@@ -101,7 +101,7 @@ class BaseVM(object):
                    "-o", "StrictHostKeyChecking=no",
                    "-o", "UserKnownHostsFile=" + os.devnull,
                    "-o", "ConnectTimeout=1",
-                   "-p", self.ssh_port, "-i", self._ssh_key_file]
+                   "-p", str(self.ssh_port), "-i", self._ssh_key_file]
         if interactive:
             ssh_cmd += ['-t']
         assert not isinstance(cmd, str)
@@ -163,13 +163,13 @@ class BaseVM(object):
             raise
         atexit.register(self.shutdown)
         self._guest = guest
-        usernet_info = guest.qmp("human-monitor-command",
-                                 command_line="info usernet")
+        usernet_info = guest.qmp("query-usernet")
         self.ssh_port = None
-        for l in usernet_info["return"].splitlines():
-            fields = l.split()
-            if "TCP[HOST_FORWARD]" in fields and "22" in fields:
-                self.ssh_port = l.split()[3]
+        for i in usernet_info["return"]:
+            if i.get("id") != "vnet":
+                continue
+            self.ssh_port = i["connections"][0]["src_port"]
+            break
         if not self.ssh_port:
             raise Exception("Cannot find ssh port from 'info usernet':\n%s" % \
                             usernet_info)
Signature · 1 line
2.14.3
#7 lore raw
In reply to Fam Zheng
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v6 0/4] slirp: Add query-usernet QMP command

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
c08e6e3a7f tests: Use query-usernet instead of 'info usernet' c493a69267 slirp: Add "query-usernet" QMP command 5150e445b4 slirp: Use QAPI enum to replace TCPS_* macros 0f3b1a240b qapi: Introduce UsernetTcpState

=== OUTPUT BEGIN ===
Checking PATCH 1/4: qapi: Introduce UsernetTcpState... Checking PATCH 2/4: slirp: Use QAPI enum to replace TCPS_* macros...
ERROR: code indent should never use tabs
#112: FILE: slirp/tcp_input.c:88:
+^I (tp)->t_state == USERNET_TCP_STATE_ESTABLISHED) { \$

ERROR: code indent should never use tabs
#121: FILE: slirp/tcp_input.c:193:
+^Iif (tp->t_state == USERNET_TCP_STATE_SYN_RECEIVED && ti->ti_len)$

ERROR: code indent should never use tabs
#130: FILE: slirp/tcp_input.c:460:
+^I tp->t_state = USERNET_TCP_STATE_LISTEN;$

ERROR: code indent should never use tabs
#139: FILE: slirp/tcp_input.c:476:
+^Iif (tp->t_state == USERNET_TCP_STATE_CLOSED)$

ERROR: braces {} are necessary for all arms of this statement #139: FILE: slirp/tcp_input.c:476:
+ if (tp->t_state == USERNET_TCP_STATE_CLOSED)
[...]

ERROR: code indent should never use tabs
#148: FILE: slirp/tcp_input.c:495:
+^Iif (optp && tp->t_state != USERNET_TCP_STATE_LISTEN)$

ERROR: braces {} are necessary for all arms of this statement #148: FILE: slirp/tcp_input.c:495:
+ if (optp && tp->t_state != USERNET_TCP_STATE_LISTEN)
[...]

ERROR: code indent should never use tabs
#157: FILE: slirp/tcp_input.c:516:
+^Iif (tp->t_state == USERNET_TCP_STATE_ESTABLISHED &&$

ERROR: code indent should never use tabs
#166: FILE: slirp/tcp_input.c:618:
+^Icase USERNET_TCP_STATE_LISTEN: {$

ERROR: code indent should never use tabs
#175: FILE: slirp/tcp_input.c:729:
+^I tp->t_state = USERNET_TCP_STATE_SYN_RECEIVED;$

ERROR: code indent should never use tabs #184: FILE: slirp/tcp_input.c:763:
+^I tp->t_state = USERNET_TCP_STATE_SYN_RECEIVED;$

ERROR: code indent should never use tabs
#188: FILE: slirp/tcp_input.c:766:
+^I} /* case USERNET_TCP_STATE_LISTEN */$

ERROR: code indent should never use tabs
#197: FILE: slirp/tcp_input.c:780:
+^Icase USERNET_TCP_STATE_SYN_SENT:$

ERROR: code indent should never use tabs #206: FILE: slirp/tcp_input.c:807:
+^I^I^Itp->t_state = USERNET_TCP_STATE_ESTABLISHED;$

ERROR: code indent should never use tabs #215: FILE: slirp/tcp_input.c:818:
+^I^I^Itp->t_state = USERNET_TCP_STATE_SYN_RECEIVED;$

ERROR: code indent should never use tabs
#224: FILE: slirp/tcp_input.c:888:
+^I tp->t_state > USERNET_TCP_STATE_CLOSE_WAIT && ti->ti_len) {$

ERROR: code indent should never use tabs
#233: FILE: slirp/tcp_input.c:907:
+^I^I^I tp->t_state == USERNET_TCP_STATE_TIME_WAIT &&$

ERROR: code indent should never use tabs
#247: FILE: slirp/tcp_input.c:943:
+^Icase USERNET_TCP_STATE_SYN_RECEIVED:$

ERROR: code indent should never use tabs
#248: FILE: slirp/tcp_input.c:944:
+^Icase USERNET_TCP_STATE_ESTABLISHED:$

ERROR: code indent should never use tabs
#249: FILE: slirp/tcp_input.c:945:
+^Icase USERNET_TCP_STATE_FIN_WAIT_1:$

ERROR: code indent should never use tabs
#250: FILE: slirp/tcp_input.c:946:
+^Icase USERNET_TCP_STATE_FIN_WAIT_2:$

ERROR: code indent should never use tabs
#251: FILE: slirp/tcp_input.c:947:
+^Icase USERNET_TCP_STATE_CLOSE_WAIT:$

ERROR: code indent should never use tabs
#252: FILE: slirp/tcp_input.c:948:
+^I^Itp->t_state = USERNET_TCP_STATE_CLOSED;$

ERROR: code indent should never use tabs
#259: FILE: slirp/tcp_input.c:952:
+^Icase USERNET_TCP_STATE_CLOSING:$

ERROR: code indent should never use tabs
#260: FILE: slirp/tcp_input.c:953:
+^Icase USERNET_TCP_STATE_LAST_ACK:$

ERROR: code indent should never use tabs
#261: FILE: slirp/tcp_input.c:954:
+^Icase USERNET_TCP_STATE_TIME_WAIT:$

ERROR: code indent should never use tabs
#270: FILE: slirp/tcp_input.c:982:
+^Icase USERNET_TCP_STATE_SYN_RECEIVED:$

ERROR: code indent should never use tabs #276: FILE: slirp/tcp_input.c:987:
+^I^Itp->t_state = USERNET_TCP_STATE_ESTABLISHED;$

ERROR: code indent should never use tabs
#285: FILE: slirp/tcp_input.c:1007:
+^I^I tp->t_state = USERNET_TCP_STATE_FIN_WAIT_1;$

ERROR: code indent should never use tabs
#300: FILE: slirp/tcp_input.c:1027:
+^Icase USERNET_TCP_STATE_ESTABLISHED:$

ERROR: code indent should never use tabs
#301: FILE: slirp/tcp_input.c:1028:
+^Icase USERNET_TCP_STATE_FIN_WAIT_1:$

ERROR: code indent should never use tabs
#302: FILE: slirp/tcp_input.c:1029:
+^Icase USERNET_TCP_STATE_FIN_WAIT_2:$

ERROR: code indent should never use tabs
#303: FILE: slirp/tcp_input.c:1030:
+^Icase USERNET_TCP_STATE_CLOSE_WAIT:$

ERROR: code indent should never use tabs
#304: FILE: slirp/tcp_input.c:1031:
+^Icase USERNET_TCP_STATE_CLOSING:$

ERROR: code indent should never use tabs
#305: FILE: slirp/tcp_input.c:1032:
+^Icase USERNET_TCP_STATE_LAST_ACK:$

ERROR: code indent should never use tabs
#306: FILE: slirp/tcp_input.c:1033:
+^Icase USERNET_TCP_STATE_TIME_WAIT:$

ERROR: code indent should never use tabs
#315: FILE: slirp/tcp_input.c:1164:
+^I^Icase USERNET_TCP_STATE_FIN_WAIT_1:$

ERROR: code indent should never use tabs #324: FILE: slirp/tcp_input.c:1176:
+^I^I^I^Itp->t_state = USERNET_TCP_STATE_FIN_WAIT_2;$

ERROR: code indent should never use tabs
#333: FILE: slirp/tcp_input.c:1186:
+^I^Icase USERNET_TCP_STATE_CLOSING:$

ERROR: code indent should never use tabs #336: FILE: slirp/tcp_input.c:1188:
+^I^I^I^Itp->t_state = USERNET_TCP_STATE_TIME_WAIT;$

ERROR: code indent should never use tabs
#345: FILE: slirp/tcp_input.c:1200:
+^I^Icase USERNET_TCP_STATE_LAST_ACK:$

ERROR: code indent should never use tabs
#354: FILE: slirp/tcp_input.c:1212:
+^I^Icase USERNET_TCP_STATE_TIME_WAIT:$

WARNING: line over 80 characters
#363: FILE: slirp/tcp_input.c:1320:
+ * will got to USERNET_TCP_STATE_LAST_ACK, and use tcp_output()

ERROR: code indent should never use tabs
#363: FILE: slirp/tcp_input.c:1320:
+^I^I^I * will got to USERNET_TCP_STATE_LAST_ACK, and use tcp_output()$

ERROR: code indent should never use tabs
#373: FILE: slirp/tcp_input.c:1334:
+^I^Icase USERNET_TCP_STATE_SYN_RECEIVED:$

ERROR: code indent should never use tabs
#374: FILE: slirp/tcp_input.c:1335:
+^I^Icase USERNET_TCP_STATE_ESTABLISHED:$

ERROR: code indent should never use tabs
#377: FILE: slirp/tcp_input.c:1337:
+^I^I tp->t_state = USERNET_TCP_STATE_LAST_ACK;$

ERROR: code indent should never use tabs
#380: FILE: slirp/tcp_input.c:1339:
+^I^I tp->t_state = USERNET_TCP_STATE_CLOSE_WAIT;$

ERROR: code indent should never use tabs
#389: FILE: slirp/tcp_input.c:1346:
+^I^Icase USERNET_TCP_STATE_FIN_WAIT_1:$

ERROR: code indent should never use tabs
#390: FILE: slirp/tcp_input.c:1347:
+^I^I^Itp->t_state = USERNET_TCP_STATE_CLOSING;$

ERROR: code indent should never use tabs
#400: FILE: slirp/tcp_input.c:1355:
+^I^Icase USERNET_TCP_STATE_FIN_WAIT_2:$

ERROR: code indent should never use tabs #401: FILE: slirp/tcp_input.c:1356:
+^I^I^Itp->t_state = USERNET_TCP_STATE_TIME_WAIT;$

ERROR: code indent should never use tabs
#410: FILE: slirp/tcp_input.c:1364:
+^I^Icase USERNET_TCP_STATE_TIME_WAIT:$

ERROR: code indent should never use tabs
#431: FILE: slirp/tcp_subr.c:286:
+^Itp->t_state = USERNET_TCP_STATE_CLOSED;$

ERROR: code indent should never use tabs
#440: FILE: slirp/tcp_subr.c:305:
+^I^Itp->t_state = USERNET_TCP_STATE_CLOSED;$

ERROR: code indent should never use tabs
#452: FILE: slirp/tcp_subr.c:375:
+^Icase USERNET_TCP_STATE_CLOSED:$

ERROR: code indent should never use tabs
#453: FILE: slirp/tcp_subr.c:376:
+^Icase USERNET_TCP_STATE_LISTEN:$

ERROR: code indent should never use tabs
#454: FILE: slirp/tcp_subr.c:377:
+^Icase USERNET_TCP_STATE_SYN_SENT:$

ERROR: code indent should never use tabs
#455: FILE: slirp/tcp_subr.c:378:
+^I^Itp->t_state = USERNET_TCP_STATE_CLOSED;$

ERROR: code indent should never use tabs
#462: FILE: slirp/tcp_subr.c:382:
+^Icase USERNET_TCP_STATE_SYN_RECEIVED:$

ERROR: code indent should never use tabs
#463: FILE: slirp/tcp_subr.c:383:
+^Icase USERNET_TCP_STATE_ESTABLISHED:$

ERROR: code indent should never use tabs
#464: FILE: slirp/tcp_subr.c:384:
+^I^Itp->t_state = USERNET_TCP_STATE_FIN_WAIT_1;$

ERROR: code indent should never use tabs
#469: FILE: slirp/tcp_subr.c:387:
+^Icase USERNET_TCP_STATE_CLOSE_WAIT:$

ERROR: code indent should never use tabs
#470: FILE: slirp/tcp_subr.c:388:
+^I^Itp->t_state = USERNET_TCP_STATE_LAST_ACK;$

ERROR: code indent should never use tabs
#500: FILE: slirp/tcp_timer.c:139:
+^I^Iif (tp->t_state != USERNET_TCP_STATE_TIME_WAIT &&$

ERROR: code indent should never use tabs #509: FILE: slirp/tcp_timer.c:263:
+^I^Iif (tp->t_state < USERNET_TCP_STATE_ESTABLISHED)$

WARNING: line over 80 characters
#513: FILE: slirp/tcp_timer.c:266:
+ if ((SO_OPTIONS) && tp->t_state <= USERNET_TCP_STATE_CLOSE_WAIT) {

ERROR: code indent should never use tabs
#513: FILE: slirp/tcp_timer.c:266:
+^I^Iif ((SO_OPTIONS) && tp->t_state <= USERNET_TCP_STATE_CLOSE_WAIT) {$

total: 66 errors, 2 warnings, 444 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 3/4: slirp: Add "query-usernet" QMP command... Checking PATCH 4/4: tests: Use query-usernet instead of 'info usernet'... === OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

author
#8 lore raw
Quoted 4 lines · On Fri, 05/04 00:49, [email protected] wrote:

Hi,

This series seems to have some coding style problems. See output below for more information:

Code indentation issues are due to the pre-existing style in the file and is not changed by the patch.

Fam

Quoted 332 lines

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v6 0/4] slirp: Add query-usernet QMP command

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
c08e6e3a7f tests: Use query-usernet instead of 'info usernet' c493a69267 slirp: Add "query-usernet" QMP command 5150e445b4 slirp: Use QAPI enum to replace TCPS_* macros 0f3b1a240b qapi: Introduce UsernetTcpState

=== OUTPUT BEGIN ===
Checking PATCH 1/4: qapi: Introduce UsernetTcpState... Checking PATCH 2/4: slirp: Use QAPI enum to replace TCPS_* macros...
ERROR: code indent should never use tabs
#112: FILE: slirp/tcp_input.c:88:
+^I (tp)->t_state == USERNET_TCP_STATE_ESTABLISHED) { \$

ERROR: code indent should never use tabs
#121: FILE: slirp/tcp_input.c:193:
+^Iif (tp->t_state == USERNET_TCP_STATE_SYN_RECEIVED && ti->ti_len)$

ERROR: code indent should never use tabs
#130: FILE: slirp/tcp_input.c:460:
+^I tp->t_state = USERNET_TCP_STATE_LISTEN;$

ERROR: code indent should never use tabs
#139: FILE: slirp/tcp_input.c:476:
+^Iif (tp->t_state == USERNET_TCP_STATE_CLOSED)$

ERROR: braces {} are necessary for all arms of this statement #139: FILE: slirp/tcp_input.c:476:

(quoted diff) +1 -0
+	if (tp->t_state == USERNET_TCP_STATE_CLOSED)
[...]

ERROR: code indent should never use tabs
#148: FILE: slirp/tcp_input.c:495:
+^Iif (optp && tp->t_state != USERNET_TCP_STATE_LISTEN)$

ERROR: braces {} are necessary for all arms of this statement #148: FILE: slirp/tcp_input.c:495:

(quoted diff) +1 -0
+	if (optp && tp->t_state != USERNET_TCP_STATE_LISTEN)
[...]

ERROR: code indent should never use tabs
#157: FILE: slirp/tcp_input.c:516:
+^Iif (tp->t_state == USERNET_TCP_STATE_ESTABLISHED &&$

ERROR: code indent should never use tabs
#166: FILE: slirp/tcp_input.c:618:
+^Icase USERNET_TCP_STATE_LISTEN: {$

ERROR: code indent should never use tabs
#175: FILE: slirp/tcp_input.c:729:
+^I tp->t_state = USERNET_TCP_STATE_SYN_RECEIVED;$

ERROR: code indent should never use tabs #184: FILE: slirp/tcp_input.c:763:
+^I tp->t_state = USERNET_TCP_STATE_SYN_RECEIVED;$

ERROR: code indent should never use tabs
#188: FILE: slirp/tcp_input.c:766:
+^I} /* case USERNET_TCP_STATE_LISTEN */$

ERROR: code indent should never use tabs
#197: FILE: slirp/tcp_input.c:780:
+^Icase USERNET_TCP_STATE_SYN_SENT:$

ERROR: code indent should never use tabs #206: FILE: slirp/tcp_input.c:807:
+^I^I^Itp->t_state = USERNET_TCP_STATE_ESTABLISHED;$

ERROR: code indent should never use tabs #215: FILE: slirp/tcp_input.c:818:
+^I^I^Itp->t_state = USERNET_TCP_STATE_SYN_RECEIVED;$

ERROR: code indent should never use tabs
#224: FILE: slirp/tcp_input.c:888:
+^I tp->t_state > USERNET_TCP_STATE_CLOSE_WAIT && ti->ti_len) {$

ERROR: code indent should never use tabs
#233: FILE: slirp/tcp_input.c:907:
+^I^I^I tp->t_state == USERNET_TCP_STATE_TIME_WAIT &&$

ERROR: code indent should never use tabs
#247: FILE: slirp/tcp_input.c:943:
+^Icase USERNET_TCP_STATE_SYN_RECEIVED:$

ERROR: code indent should never use tabs
#248: FILE: slirp/tcp_input.c:944:
+^Icase USERNET_TCP_STATE_ESTABLISHED:$

ERROR: code indent should never use tabs
#249: FILE: slirp/tcp_input.c:945:
+^Icase USERNET_TCP_STATE_FIN_WAIT_1:$

ERROR: code indent should never use tabs
#250: FILE: slirp/tcp_input.c:946:
+^Icase USERNET_TCP_STATE_FIN_WAIT_2:$

ERROR: code indent should never use tabs
#251: FILE: slirp/tcp_input.c:947:
+^Icase USERNET_TCP_STATE_CLOSE_WAIT:$

ERROR: code indent should never use tabs
#252: FILE: slirp/tcp_input.c:948:
+^I^Itp->t_state = USERNET_TCP_STATE_CLOSED;$

ERROR: code indent should never use tabs
#259: FILE: slirp/tcp_input.c:952:
+^Icase USERNET_TCP_STATE_CLOSING:$

ERROR: code indent should never use tabs
#260: FILE: slirp/tcp_input.c:953:
+^Icase USERNET_TCP_STATE_LAST_ACK:$

ERROR: code indent should never use tabs
#261: FILE: slirp/tcp_input.c:954:
+^Icase USERNET_TCP_STATE_TIME_WAIT:$

ERROR: code indent should never use tabs
#270: FILE: slirp/tcp_input.c:982:
+^Icase USERNET_TCP_STATE_SYN_RECEIVED:$

ERROR: code indent should never use tabs #276: FILE: slirp/tcp_input.c:987:
+^I^Itp->t_state = USERNET_TCP_STATE_ESTABLISHED;$

ERROR: code indent should never use tabs
#285: FILE: slirp/tcp_input.c:1007:
+^I^I tp->t_state = USERNET_TCP_STATE_FIN_WAIT_1;$

ERROR: code indent should never use tabs
#300: FILE: slirp/tcp_input.c:1027:
+^Icase USERNET_TCP_STATE_ESTABLISHED:$

ERROR: code indent should never use tabs
#301: FILE: slirp/tcp_input.c:1028:
+^Icase USERNET_TCP_STATE_FIN_WAIT_1:$

ERROR: code indent should never use tabs
#302: FILE: slirp/tcp_input.c:1029:
+^Icase USERNET_TCP_STATE_FIN_WAIT_2:$

ERROR: code indent should never use tabs
#303: FILE: slirp/tcp_input.c:1030:
+^Icase USERNET_TCP_STATE_CLOSE_WAIT:$

ERROR: code indent should never use tabs
#304: FILE: slirp/tcp_input.c:1031:
+^Icase USERNET_TCP_STATE_CLOSING:$

ERROR: code indent should never use tabs
#305: FILE: slirp/tcp_input.c:1032:
+^Icase USERNET_TCP_STATE_LAST_ACK:$

ERROR: code indent should never use tabs
#306: FILE: slirp/tcp_input.c:1033:
+^Icase USERNET_TCP_STATE_TIME_WAIT:$

ERROR: code indent should never use tabs
#315: FILE: slirp/tcp_input.c:1164:
+^I^Icase USERNET_TCP_STATE_FIN_WAIT_1:$

ERROR: code indent should never use tabs #324: FILE: slirp/tcp_input.c:1176:
+^I^I^I^Itp->t_state = USERNET_TCP_STATE_FIN_WAIT_2;$

ERROR: code indent should never use tabs
#333: FILE: slirp/tcp_input.c:1186:
+^I^Icase USERNET_TCP_STATE_CLOSING:$

ERROR: code indent should never use tabs #336: FILE: slirp/tcp_input.c:1188:
+^I^I^I^Itp->t_state = USERNET_TCP_STATE_TIME_WAIT;$

ERROR: code indent should never use tabs
#345: FILE: slirp/tcp_input.c:1200:
+^I^Icase USERNET_TCP_STATE_LAST_ACK:$

ERROR: code indent should never use tabs
#354: FILE: slirp/tcp_input.c:1212:
+^I^Icase USERNET_TCP_STATE_TIME_WAIT:$

WARNING: line over 80 characters
#363: FILE: slirp/tcp_input.c:1320:

(quoted diff) +1 -0
+			 * will got to USERNET_TCP_STATE_LAST_ACK, and use tcp_output()

ERROR: code indent should never use tabs
#363: FILE: slirp/tcp_input.c:1320:
+^I^I^I * will got to USERNET_TCP_STATE_LAST_ACK, and use tcp_output()$

ERROR: code indent should never use tabs
#373: FILE: slirp/tcp_input.c:1334:
+^I^Icase USERNET_TCP_STATE_SYN_RECEIVED:$

ERROR: code indent should never use tabs
#374: FILE: slirp/tcp_input.c:1335:
+^I^Icase USERNET_TCP_STATE_ESTABLISHED:$

ERROR: code indent should never use tabs
#377: FILE: slirp/tcp_input.c:1337:
+^I^I tp->t_state = USERNET_TCP_STATE_LAST_ACK;$

ERROR: code indent should never use tabs
#380: FILE: slirp/tcp_input.c:1339:
+^I^I tp->t_state = USERNET_TCP_STATE_CLOSE_WAIT;$

ERROR: code indent should never use tabs
#389: FILE: slirp/tcp_input.c:1346:
+^I^Icase USERNET_TCP_STATE_FIN_WAIT_1:$

ERROR: code indent should never use tabs
#390: FILE: slirp/tcp_input.c:1347:
+^I^I^Itp->t_state = USERNET_TCP_STATE_CLOSING;$

ERROR: code indent should never use tabs
#400: FILE: slirp/tcp_input.c:1355:
+^I^Icase USERNET_TCP_STATE_FIN_WAIT_2:$

ERROR: code indent should never use tabs #401: FILE: slirp/tcp_input.c:1356:
+^I^I^Itp->t_state = USERNET_TCP_STATE_TIME_WAIT;$

ERROR: code indent should never use tabs
#410: FILE: slirp/tcp_input.c:1364:
+^I^Icase USERNET_TCP_STATE_TIME_WAIT:$

ERROR: code indent should never use tabs
#431: FILE: slirp/tcp_subr.c:286:
+^Itp->t_state = USERNET_TCP_STATE_CLOSED;$

ERROR: code indent should never use tabs
#440: FILE: slirp/tcp_subr.c:305:
+^I^Itp->t_state = USERNET_TCP_STATE_CLOSED;$

ERROR: code indent should never use tabs
#452: FILE: slirp/tcp_subr.c:375:
+^Icase USERNET_TCP_STATE_CLOSED:$

ERROR: code indent should never use tabs
#453: FILE: slirp/tcp_subr.c:376:
+^Icase USERNET_TCP_STATE_LISTEN:$

ERROR: code indent should never use tabs
#454: FILE: slirp/tcp_subr.c:377:
+^Icase USERNET_TCP_STATE_SYN_SENT:$

ERROR: code indent should never use tabs
#455: FILE: slirp/tcp_subr.c:378:
+^I^Itp->t_state = USERNET_TCP_STATE_CLOSED;$

ERROR: code indent should never use tabs
#462: FILE: slirp/tcp_subr.c:382:
+^Icase USERNET_TCP_STATE_SYN_RECEIVED:$

ERROR: code indent should never use tabs
#463: FILE: slirp/tcp_subr.c:383:
+^Icase USERNET_TCP_STATE_ESTABLISHED:$

ERROR: code indent should never use tabs
#464: FILE: slirp/tcp_subr.c:384:
+^I^Itp->t_state = USERNET_TCP_STATE_FIN_WAIT_1;$

ERROR: code indent should never use tabs
#469: FILE: slirp/tcp_subr.c:387:
+^Icase USERNET_TCP_STATE_CLOSE_WAIT:$

ERROR: code indent should never use tabs
#470: FILE: slirp/tcp_subr.c:388:
+^I^Itp->t_state = USERNET_TCP_STATE_LAST_ACK;$

ERROR: code indent should never use tabs
#500: FILE: slirp/tcp_timer.c:139:
+^I^Iif (tp->t_state != USERNET_TCP_STATE_TIME_WAIT &&$

ERROR: code indent should never use tabs #509: FILE: slirp/tcp_timer.c:263:
+^I^Iif (tp->t_state < USERNET_TCP_STATE_ESTABLISHED)$

WARNING: line over 80 characters
#513: FILE: slirp/tcp_timer.c:266:

(quoted diff) +1 -0
+		if ((SO_OPTIONS) && tp->t_state <= USERNET_TCP_STATE_CLOSE_WAIT) {

ERROR: code indent should never use tabs
#513: FILE: slirp/tcp_timer.c:266:
+^I^Iif ((SO_OPTIONS) && tp->t_state <= USERNET_TCP_STATE_CLOSE_WAIT) {$

total: 66 errors, 2 warnings, 444 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 3/4: slirp: Add "query-usernet" QMP command... Checking PATCH 4/4: tests: Use query-usernet instead of 'info usernet'... === OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]