net: add the support for -netdev socket, listen
Subsystems (2)
PATCH v4 1/1 net: add the support for -netdev socket, listen
From: Zhi Yong Wu <[email protected]>
The -net socket,listen option does not work with the newer -netdev syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.html
This patch makes it work now.
For the case where one vlan has multiple listenning sockets, the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0 3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
--- net.c | 24 +++++++++++ net.h | 3 + net/socket.c | 123 ++++++++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 117 insertions(+), 33 deletions(-)
net.c +24 -0
@@ -190,6 +190,30 @@ static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,int iovcnt, void *opaque); +VLANClientState *qemu_lookup_net_client (VLANState *vlan, +const char *name) +{ +VLANClientState *vc =NULL ; + +if (vlan) { + QTAILQ_FOREACH(vc, &vlan->clients, next) { +if ((vc->info->type ==NET_CLIENT_TYPE_SOCKET ) + && (!vc->consumed)) { +return vc; + } + } + }else { + QTAILQ_FOREACH(vc, &non_vlan_clients, next) { +if (!strcmp (vc->name, name) + && (!vc->consumed)) { +return vc; + } + } + } + +return NULL ; +} + VLANClientState *qemu_new_net_client(NetClientInfo *info, VLANState *vlan, VLANClientState *peer,
net.h +3 -0
@@ -72,6 +72,7 @@ struct VLANClientState {char *name;char info_str[256 ]; unsigned receive_disabled : 1; +bool consumed; }; typedef struct NICState {
@@ -90,6 +91,8 @@ struct VLANState {VLANState *qemu_find_vlan (int id,int allocate);VLANClientState *qemu_find_netdev (const char *id); +VLANClientState *qemu_lookup_net_client (VLANState *vlan, +const char *name); VLANClientState *qemu_new_net_client(NetClientInfo *info, VLANState *vlan, VLANClientState *peer,
net/socket.c +90 -33
283 lines not on this page · raw message
Signature · 1 line
1.7.6
Quoted 16 lines · On Wed, Jun 06, 2012 at 09:26:23PM +0800, [email protected] wrote:
From: Zhi Yong Wu <[email protected]>
The -net socket,listen option does not work with the newer -netdev syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.htmlThis patch makes it work now.
For the case where one vlan has multiple listenning sockets, the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0 3.) -netdev socket,listen=127.0.0.1:1234,id=socket0
Quoted 7 lines
Suggested-by Stefan Hajnoczi <[email protected]>Signed-off-by Zhi Yong Wu <[email protected]>--- net.c | 24 +++++++++++ net.h | 3 + net/socket.c | 123 ++++++++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 117 insertions(+), 33 deletions(-)
Please include changelogs in new versions of patches.
It looks like you have implemented "1 connection at a time" semantics. This is good, I think it maps best to the netdev peer model. Allowing multiple clients to connect to a single listen socket at the same time doesn't fit into the netdev peer model.
I think the patch can be simplified a lot though. There's no need to modify net.c or add consumed booleans.
Instead, drop the NetSocketListenState struct and add a listen_fd field to NetSocketState. When a -netdev socket,listen= instance is created there will be a NetSocketState with fd=-1 and a valid listen_fd. The net_socket_accept() handler waits for listen_fd to become readable and then accepts the connection. When this state transition happens, we no longer monitor listen_fd for incoming connections...until the client disconnects again.
This approach doesn't need to change net.c or VLANClientState. It also makes memory allocation simpler because we only have 1 struct:
NetSocketState.
Stefan
Quoted 32 lines · Stefan Hajnoczi
Quoted 16 lines · On Wed, Jun 06, 2012 at 09:26:23PM +0800, [email protected] wrote:
From: Zhi Yong Wu <[email protected]>
The -net socket,listen option does not work with the newer -netdev syntax:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01508.htmlThis patch makes it work now.
For the case where one vlan has multiple listenning sockets, the patch will also provide the support.
Supported syntax:
1.) -net socket,listen=127.0.0.1:1234,vlan=0
2.) -net socket,listen=127.0.0.1:1234,vlan=0 -net socket,listen=127.0.0.1:1235,vlan=0 3.) -netdev socket,listen=127.0.0.1:1234,id=socket0Quoted 7 lines
Suggested-by Stefan Hajnoczi <[email protected]>Signed-off-by Zhi Yong Wu <[email protected]>---
net.c | 24 +++++++++++
net.h | 3 +
net/socket.c | 123 ++++++++++++++++++++++++++++++++++++++++++---------------3 files changed, 117 insertions(+), 33 deletions(-)Please include changelogs in new versions of patches.
It looks like you have implemented "1 connection at a time" semantics. This is good, I think it maps best to the netdev peer model. Allowing multiple clients to connect to a single listen socket at the same time doesn't fit into the netdev peer model.
Quoted 6 lines
I think the patch can be simplified a lot though. There's no need to modify
net.cor add consumed booleans.Instead, drop the NetSocketListenState struct and add a
listen_fdfield to NetSocketState. When a -netdev socket,listen= instance is created there will be a NetSocketState with fd=-1 and a validlisten_fd. The
Have you considered the case where there're mulitple -net socket,listen= instance in one vlan?
Quoted 11 lines
net_socket_accept()handler waits forlisten_fdto become readable and then accepts the connection. When this state transition happens, we no longer monitorlisten_fdfor incoming connections...until the client disconnects again.This approach doesn't need to change
net.cor VLANClientState. It also makes memory allocation simpler because we only have 1 struct:
NetSocketState.Stefan
Signature · 3 lines
Regards, Zhi Yong Wu
Il 07/06/2012 14:49, Zhi Yong Wu ha scritto:
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Instead, drop the NetSocketListenState struct and add a
listen_fdfield to NetSocketState. When a -netdev socket,listen= instance is created there will be a NetSocketState with fd=-1 and a validlisten_fd. TheHave you considered the case where there're mulitple -net socket,listen= instance in one vlan?
Why should that matter? They will have different NetSocketState and different listen_fds. Each socket will discard incoming packets until the other side connects.
Paolo
Quoted 10 lines · Paolo Bonzini
Il 07/06/2012 14:49, Zhi Yong Wu ha scritto:
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Instead, drop the NetSocketListenState struct and add a
listen_fdfield to NetSocketState. When a -netdev socket,listen= instance is created there will be a NetSocketState with fd=-1 and a validlisten_fd. TheHave you considered the case where there're mulitple -net socket,listen= instance in one vlan?
Why should that matter? They will have different NetSocketState and different
listen_fds. Each socket will discard incoming packets until the other side connects.
You are correct, thanks, please see next version.
Quoted 3 lines
Paolo
Signature · 3 lines
Regards, Zhi Yong Wu
Quoted 10 lines · Paolo Bonzini
Il 07/06/2012 14:49, Zhi Yong Wu ha scritto:
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Instead, drop the NetSocketListenState struct and add a
listen_fdfield to NetSocketState. When a -netdev socket,listen= instance is created there will be a NetSocketState with fd=-1 and a validlisten_fd. TheHave you considered the case where there're mulitple -net socket,listen= instance in one vlan?
Why should that matter? They will have different NetSocketState and different
listen_fds. Each socket will discard incoming packets until the other side connects.
Exactly, the key is that each -netdev has its own state struct.
Stefan