slirp: Add query-usernet QMP command
v2 cover slirp: Add query-usernet QMP command
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 (2):
slirp: Add "query-usernet" QMP command
tests: Use query-usernet instead of 'info usernet'
net/slirp.c | 26 +++++++ qapi/net.json | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++ slirp/libslirp.h | 1 + slirp/misc.c | 156 +++++++++++++++++++++++++++++------------ slirp/tcp.h | 15 ---- tests/vm/basevm.py | 14 ++-- 6 files changed, 346 insertions(+), 67 deletions(-)
Signature · 1 line
2.14.3
PATCH v2 1/2 slirp: Add "query-usernet" QMP command
HMP "info usernet" has been available but it isn't ideal for programed 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.
The TCPS_* macros are now defined as a QAPI enum.
--- net/slirp.c | 26 +++++++ qapi/net.json | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ slirp/libslirp.h | 1 + slirp/misc.c | 156 +++++++++++++++++++++++++++++------------- slirp/tcp.h | 15 ----- 5 files changed, 339 insertions(+), 60 deletions(-)
net/slirp.c +26 -0
@@ -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 "qmp-commands.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 vlan; +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, &vlan)) { + info->vlan = vlan; + }else { + info->vlan =-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 +201 -0
204 lines not on this page · raw message
slirp/libslirp.h +1 -0
@@ -37,6 +37,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 +111 -45
196 lines not on this page · raw message
slirp/tcp.h +0 -15
@@ -133,21 +133,6 @@ 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)
Signature · 1 line
2.14.3
PATCH v2 2/2 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
@@ -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)
@@ -166,13 +166,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
Gentle ping..
Quoted 20 lines · Fam Zheng
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 (2):
slirp: Add "query-usernet" QMP command
tests: Use query-usernet instead of 'info usernet'net/slirp.c | 26 +++++++ qapi/net.json | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++ slirp/libslirp.h | 1 + slirp/misc.c | 156 +++++++++++++++++++++++++++++------------ slirp/tcp.h | 15 ---- tests/vm/basevm.py | 14 ++-- 6 files changed, 346 insertions(+), 67 deletions(-)Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH v2 1/2] slirp: Add "query-usernet" QMP command
In reply to Fam ZhengQuoted 1 line · Fam Zheng
HMP "info usernet" has been available but it isn't ideal for programed
s/programed/programmed/
Quoted 27 lines
use cases. This closes the gap in QMP by adding a counterpart "query-usernet" command. It is basically translated from
the HMPslirp_connection_info()loop, which now calls the QMP implementation and prints the data, just like other HMP info_* commands.The TCPS_* macros are now defined as a QAPI enum.
Signed-off-by Fam Zheng <[email protected]>--- net/slirp.c | 26 +++++++ qapi/net.json | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ slirp/libslirp.h | 1 + slirp/misc.c | 156 +++++++++++++++++++++++++++++------------- slirp/tcp.h | 15 ----- 5 files changed, 339 insertions(+), 60 deletions(-)+++
b/net/slirp.cnet/slirp.c +1
-0@@ -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"
net/slirp.c line 47
Quoted 4 lines
net/slirp.c +1
-0@@ -43,6 +44,7 @@#include "qemu/cutils.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" +#include "qmp-commands.h"
Needs rebasing to master, although off-hand I think it is probably as simple as a switch to qapi/qapi-net-commands.h
Quoted 8 lines
qapi/net.json +4
-0+++ b/qapi/net.json@@ -706,3 +706,204 @@ ## { 'event': 'NIC_RX_FILTER_CHANGED', 'data': { '*name': 'str', 'path': 'str' } } + +## +# @TCPS:
qapi/net.json line 721
Quoted 10 lines
qapi/net.json +10
-0+# +# 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 await ACK of FIN: fin_wait_1, closing, last_ack
s/await/awaiting/
qapi/net.json line 732
Quoted 11 lines
qapi/net.json +11
-0+# +# 'none' state is used only when host forwarding +# +# Since 2.12 +# +## +{ 'enum': 'TCPS', + 'data': + ['closed', + 'listen', + 'syn_sent',
Probably nicer to spell this 'syn-sent'; it results in the same C code, but is more consistent with modern QMP naming.
qapi/net.json line 740
Quoted 8 lines
qapi/net.json +8
-0+ 'syn_received', + 'established', + 'close_wait', + 'fin_wait_1', + 'closing', + 'last_ack', + 'fin_wait_2', + 'time_wait',
Likewise for these _.
Quoted 5 lines
qapi/net.json +5
-0+ 'none' + ] } + +## +# @UsernetTCPConnection:
qapi/net.json line 755
Quoted 10 lines
qapi/net.json +10
-0+# +# SLIRP TCP information. +# +# @state: tcp connection state +# +# @hostfwd: whether this connection has host port forwarding +# +# @fd: the file descriptor of the connection +# +# @src_addr: source address of host port forwarding
Likewise, for src-addr and friends.
Quoted 24 lines
qapi/net.json +24
-0+# +# @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 +# +# Since: 2.12 +## +{ 'struct': 'UsernetTCPConnection', + 'data': { + 'state': 'TCPS', + 'hostfwd': 'bool', + 'fd': 'int', + 'src_addr': 'str', + 'src_port': 'int', + 'dest_addr': 'str', + 'dest_port': 'int', + 'recv_buffered': 'int', + 'send_buffered': 'int'
qapi/net.json line 789
Quoted 10 lines
qapi/net.json +10
-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
And again.
Quoted 26 lines
qapi/net.json +26
-0+# +# @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 +# +# @recv_buffered: number of bytes queued in the receive buffer +# +# @send_buffered: number of bytes queued in the send buffer +# +# Since: 2.12 +## +{ 'struct': 'UsernetUDPConnection', + 'data': { + 'hostfwd': 'bool', + 'expire_time_ms': 'int', + 'fd': 'int', + 'src_addr': 'str', + 'src_port': 'int', + 'dest_addr': 'str', + 'dest_port': 'int',
qapi/net.json line 825
Quoted 10 lines
qapi/net.json +10
-0+ 'recv_buffered': 'int', + 'send_buffered': 'int' + } } + +## +# @UsernetICMPConnection: +# +# SLIRP ICMP information. +# +# @expire_time_ms: time in microseconds after which this connection will expire
Etc.
Quoted 19 lines
qapi/net.json +19
-0+# +# @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.12 +## +{ 'struct': 'UsernetICMPConnection', + 'data': { + 'expire_time_ms': 'int', + 'fd': 'int', + 'src_addr': 'str', + 'dest_addr': 'str',
qapi/net.json line 854
Quoted 10 lines
qapi/net.json +10
-0+ 'recv_buffered': 'int', + 'send_buffered': 'int' + } } + +## +# @UsernetType: +# +# Available netdev drivers. +# +# Since: 2.7
Since 2.7? Why not 2.12?
Quoted 9 lines
qapi/net.json +9
-0+## +{ 'enum': 'UsernetType', + 'data': [ 'tcp', 'udp', 'icmp' ] } + +## +# @UsernetConnection: +# +# SLIRP usernet connection information. +#
qapi/net.json line 873
Quoted 10 lines
qapi/net.json +10
-0+# Since: 2.12 +## +{ 'union': 'UsernetConnection', + 'discriminator': 'type', + 'base': { 'type': 'UsernetType' }, + 'data': { + 'tcp': 'UsernetTCPConnection', + 'udp': 'UsernetUDPConnection', + 'icmp': 'UsernetICMPConnection' + } }
Looks good.
Quoted 11 lines
qapi/net.json +11
-0+ +## +# @UsernetInfo: +# +# SLIRP usernet information. +# +# Since: 2.12 +## +{ 'struct': 'UsernetInfo', + 'data': { + 'id': 'str',
qapi/net.json line 894
Quoted 10 lines
qapi/net.json +10
-0+ 'vlan': 'int', + 'connections': ['UsernetConnection'] +} } + +## +# @query-usernet: +# +# Return SLIRP network information. +# +# Since: 2.11
2.12
qapi/net.json line 903
Quoted 9 lines
qapi/net.json +9
-0+# +# Example: +# +# -> { "execute": "query-usernet", "arguments": { } } +# <- { "return": [ +# { +# "promiscuous": true, +# "name": "vnet0", +# }
Trailing comma is not valid JSON; is the example incomplete? And doesn't match the UsernetInfo struct, which would have "id", "vlan", and "connections" instead of "promiscuous" and "name".
qapi/net.json line 909
Quoted 6 lines
qapi/net.json +6
-0+# ] +# } +# +## +{ 'command': 'query-usernet', + 'returns': ['UsernetInfo'] }
The idea makes sense, but you'll need a v3.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v2 2/2] tests: Use query-usernet instead of 'info usernet'
In reply to Fam ZhengQuoted 5 lines · Fam Zheng
Signed-off-by Fam Zheng <[email protected]>--- tests/vm/basevm.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
I think this series can go through either my QAPI tree, or through the Jason's net tree, once v3 fixes the issues I pointed out on 1/2.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org