slirp: Add query-usernet QMP command
v3 cover slirp: Add query-usernet QMP command
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 (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 | 2 + slirp/misc.c | 156 +++++++++++++++++++++++++++++------------ slirp/tcp.h | 15 ---- tests/vm/basevm.py | 14 ++-- 6 files changed, 347 insertions(+), 67 deletions(-)
Signature · 1 line
2.14.3
PATCH v3 1/2 slirp: Add "query-usernet" QMP command
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.
The TCPS_* macros are now defined as a QAPI enum.
--- net/slirp.c | 26 +++++++ qapi/net.json | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ slirp/libslirp.h | 2 + slirp/misc.c | 156 +++++++++++++++++++++++++++++------------- slirp/tcp.h | 15 ----- 5 files changed, 340 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 "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 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 +2 -0
@@ -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 +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
Re: [Qemu-devel] [PATCH for-2.13 v3 1/2] slirp: Add "query-usernet" QMP command
Hello,
I'm sorry I didn't find the time to have a look at it before.
In general it looks good, just a few things:
Samuel
Fam Zheng, le ven. 16 mars 2018 14:28:21 +0800, a ecrit:
Quoted 1 line
+ if (!net_hub_id_for_client(&s->nc, &vlan)) {
That makes me think that IIUC, we shouldn't call them vlan, as mentioned in the recent vlan->hub renaming patches.
qapi/net.json line 868
Quoted 4 lines
qapi/net.json +4
-0+{ 'struct': 'UsernetInfo', + 'data': { + 'id': 'str', + 'vlan': 'int',
and here as well, I guess.
slirp/misc.c void slirp_connection_info(Slirp *slirp, Monitor *mon) · line 314
Quoted 11 lines
slirp/misc.c +11
-0+void slirp_connection_info (Slirp *slirp,Monitor *mon) +{ +const char *state; +char buf[64 ]; +UsernetInfo info = { }; +UsernetConnectionList *cl; + +monitor_printf (mon," Protocol[State] FD Source Address Port " +"Dest. Address Port RecvQ SendQ\n" ); + +usernet_get_info (slirp, &info);
Mmm, I don't see the content of info being freed here?
Samuel
Re: [Qemu-devel] [PATCH for-2.13 v3 1/2] slirp: Add "query-usernet" QMP command
Quoted 14 lines · Samuel Thibault
Hello,
I'm sorry I didn't find the time to have a look at it before.
In general it looks good, just a few things:
Samuel
Fam Zheng, le ven. 16 mars 2018 14:28:21 +0800, a ecrit:
Quoted 1 line
+ if (!net_hub_id_for_client(&s->nc, &vlan)) {
That makes me think that IIUC, we shouldn't call them vlan, as mentioned in the recent
vlan->hubrenaming patches.
Quoted 6 lines
qapi/net.json line 868
Quoted 4 lines
qapi/net.json +4
-0+{ 'struct': 'UsernetInfo', + 'data': { + 'id': 'str', + 'vlan': 'int',and here as well, I guess.
OK, so rename this to hub? (I'm not familiar with the naming issue you pointed out).
Quoted 14 lines
slirp/misc.c void slirp_connection_info(Slirp *slirp, Monitor *mon) · line 314
Quoted 12 lines
slirp/misc.c +11
-0+void slirp_connection_info (Slirp *slirp,Monitor *mon) +{ +const char *state; +char buf[64 ]; +UsernetInfo info = { }; +UsernetConnectionList *cl; + +monitor_printf (mon," Protocol[State] FD Source Address Port " +"Dest. Address Port RecvQ SendQ\n" ); + +usernet_get_info (slirp, &info);Mmm, I don't see the content of info being freed here?
You're right, will fix.
Fam
Re: [Qemu-devel] [PATCH for-2.13 v3 1/2] slirp: Add "query-usernet" QMP command
Quoted 20 lines · Fam Zheng
Quoted 19 lines · Samuel Thibault
Hello,
I'm sorry I didn't find the time to have a look at it before.
In general it looks good, just a few things:
Samuel
Fam Zheng, le ven. 16 mars 2018 14:28:21 +0800, a ecrit:
Quoted 1 line
+ if (!net_hub_id_for_client(&s->nc, &vlan)) {
That makes me think that IIUC, we shouldn't call them vlan, as mentioned in the recent
vlan->hubrenaming patches.Quoted 4 lines
qapi/net.json +4
-0+{ 'struct': 'UsernetInfo', + 'data': { + 'id': 'str', + 'vlan': 'int',
Quoted 4 lines
Quoted 1 line
and here as well, I guess.
OK, so rename this to hub? (I'm not familiar with the naming issue you pointed out).
Yes, please rename it to "hub". See:
https://lists.gnu.org/archive/html/qemu-devel/2018-04/msg05448.html
Thomas
Re: [Qemu-devel] [PATCH for-2.13 v3 1/2] slirp: Add "query-usernet" QMP command
Quoted 21 lines · Thomas Huth
Quoted 20 lines · Fam Zheng
Quoted 19 lines · Samuel Thibault
Hello,
I'm sorry I didn't find the time to have a look at it before.
In general it looks good, just a few things:
Samuel
Fam Zheng, le ven. 16 mars 2018 14:28:21 +0800, a ecrit:
Quoted 1 line
+ if (!net_hub_id_for_client(&s->nc, &vlan)) {
That makes me think that IIUC, we shouldn't call them vlan, as mentioned in the recent
vlan->hubrenaming patches.Quoted 4 lines
qapi/net.json +4
-0+{ 'struct': 'UsernetInfo', + 'data': { + 'id': 'str', + 'vlan': 'int',
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
and here as well, I guess.
OK, so rename this to hub? (I'm not familiar with the naming issue you pointed out).
Yes, please rename it to "hub". See:
https://lists.gnu.org/archive/html/qemu-devel/2018-04/msg05448.html
OK, thanks. I've posted v4 with it renamed.
Fam
Re: [Qemu-devel] [PATCH for-2.13 v3 1/2] slirp: Add "query-usernet" QMP command
In reply to Fam ZhengFam Zheng, le mer. 02 mai 2018 15:29:36 +0800, a ecrit:
Quoted 18 lines · Samuel Thibault
Quoted 17 lines
I'm sorry I didn't find the time to have a look at it before.
In general it looks good, just a few things:
Samuel
Fam Zheng, le ven. 16 mars 2018 14:28:21 +0800, a ecrit:
Quoted 1 line
+ if (!net_hub_id_for_client(&s->nc, &vlan)) {
That makes me think that IIUC, we shouldn't call them vlan, as mentioned in the recent
vlan->hubrenaming patches.Quoted 4 lines
qapi/net.json +4
-0+{ 'struct': 'UsernetInfo', + 'data': { + 'id': 'str', + 'vlan': 'int',
Quoted 4 lines
Quoted 1 line
and here as well, I guess.
OK, so rename this to hub? (I'm not familiar with the naming issue you pointed out).
I am not either :)
Please check with the thread
http://lists.nongnu.org/archive/html/qemu-devel/2018-04/msg02126.html
Samuel
Re: [Qemu-devel] [PATCH for-2.13 v3 1/2] slirp: Add "query-usernet" QMP command
Quoted 19 lines · Samuel Thibault
Fam Zheng, le mer. 02 mai 2018 15:29:36 +0800, a ecrit:
Quoted 18 lines · Samuel Thibault
Quoted 17 lines
I'm sorry I didn't find the time to have a look at it before.
In general it looks good, just a few things:
Samuel
Fam Zheng, le ven. 16 mars 2018 14:28:21 +0800, a ecrit:
Quoted 1 line
+ if (!net_hub_id_for_client(&s->nc, &vlan)) {
That makes me think that IIUC, we shouldn't call them vlan, as mentioned in the recent
vlan->hubrenaming patches.Quoted 4 lines
qapi/net.json +4
-0+{ 'struct': 'UsernetInfo', + 'data': { + 'id': 'str', + 'vlan': 'int',
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
and here as well, I guess.
OK, so rename this to hub? (I'm not familiar with the naming issue you pointed out).
I am not either :)
The problem is that when people read the term "vlan", they think automatically of some kind of wrapped IP packets like in IEEE 802.1Q. But that's not what QEMU is doing here, it rather simulates a virtual hub. So to avoid this confusion, we should use the term "hub" in QEMU instead.
Thomas
PATCH v3 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
Quoted 16 lines · Fam Zheng
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 (2):
slirp: Add "query-usernet" QMP command
tests: Use query-usernet instead of 'info usernet'
Quoted 8 lines
net/slirp.c | 26 +++++++ qapi/net.json | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++ slirp/libslirp.h | 2 + slirp/misc.c | 156 +++++++++++++++++++++++++++++------------ slirp/tcp.h | 15 ---- tests/vm/basevm.py | 14 ++-- 6 files changed, 347 insertions(+), 67 deletions(-)
Hi Samuel:
Does this looks good for you? I believe it's better to be merged through your tree.
Thanks