Support for UDP unicast network backend
Subsystems (2)
PATCH v2 1/1 Support for UDP unicast network backend
From: Benjamin MARSILI <[email protected]>
--- net.c | 6 ++++- net/socket.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++- qemu-options.hx | 2 + 3 files changed, 76 insertions(+), 3 deletions(-)
net.c +5 -1
@@ -999,7 +999,11 @@ static const struct { }, { .name = "localaddr", .type = QEMU_OPT_STRING, - .help = "source address for multicast packets", + .help = "source address and port for multicast and udp packets", + }, { + .name = "udp", + .type = QEMU_OPT_STRING, + .help = "UDP unicast address and port number", }, {/* end of list */ } },
net/socket.c +69 -2
85 lines not on this page · raw message
qemu-options.hx +2 -0
@@ -1217,6 +1217,8 @@ DEF("net", HAS_ARG, QEMU_OPTION_net, "-net socket[,vlan=n][,name=str][,fd=h][,mcast=maddr:port[,localaddr=addr]]\n" " connect the vlan 'n' to multicast maddr and port\n" " use 'localaddr=addr' to specify the host address to send packets from\n" + "-net socket[,vlan=n][,name=str][,fd=h][,udp=host:port][,localaddr=host:port]\n" + " connect the vlan 'n' to another VLAN using an UDP tunnel\n" #ifdef CONFIG_VDE "-net vde[,vlan=n][,name=str][,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n" " connect the vlan 'n' to port 'n' of a vde switch running\n"
Signature · 1 line
1.7.3.5
Quoted 10 lines · Benjamin
+ fd =
qemu_socket(PF_INET, SOCK_DGRAM, 0);
+ if (fd < 0) {
+ perror("socket(PF_INET,SOCK_DGRAM)");
+ return -1;
+ }
+ val = 1;
+ ret = setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,
+ (const char *)&val, sizeof(val));
+ if (ret < 0) {
+ perror("setsockopt(SOL_SOCKET,SO_REUSEADDR)");
Please avoid leaking the file descriptor on error:
closesocket(fd);
Since existing code also does this it may be more appropriate to send a follow-up patch that cleans up all of net/socket.c.
Stefan
Quoted 15 lines · Stefan Hajnoczi
net/socket.c static int net_socket_mcast_init(VLANState *vlan, · line 554
Quoted 10 lines · Benjamin
net/socket.c +10
-0+ fd =qemu_socket (PF_INET ,SOCK_DGRAM ,0 ); +if (fd<0 ) { +perror ("socket(PF_INET, SOCK_DGRAM)" ); +return -1 ; + } + val =1 ; + ret =setsockopt (fd,SOL_SOCKET ,SO_REUSEADDR , + (const char *)&val,sizeof (val)); +if (ret<0 ) { +perror ("setsockopt(SOL_SOCKET, SO_REUSEADDR)" );Please avoid leaking the file descriptor on error:
closesocket(fd);
Quoted 6 lines
Since existing code also does this it may be more appropriate to send a follow-up patch that cleans up all of
net/socket.c.Reviewed-by Stefan Hajnoczi<[email protected]>Stefan
I can do that. However is it really a leak considering the fact that the program will call exit just after?
If it's a matter of consistency and coding style I would understand though.
One more thing, git-format-patch added a "From" field to the header and caused this glitch in the mail. I thought git-send-mail or the mail server would handle it well but apparently not:
From 2f5b85fcadcfee3b75a6a21dc86d10b945c99f0f Mon Sep 17 00:00:00 2001
From: Benjamin MARSILI <[email protected]>
git-am didn't complain with the patch that I sent but it may break after gmail relayed it (http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg03152.html).
The second from header is interpreted as text... Should I remove the first "From" field before sending the patch?
Sorry for the noise on the ML and thanks to all those who helped me get involved.
Benjamin
Quoted 24 lines · Benjamin
Quoted 23 lines · Stefan Hajnoczi
Quoted 11 lines · Benjamin
+ fd =
qemu_socket(PF_INET, SOCK_DGRAM, 0);
+ if (fd< 0) {
+ perror("socket(PF_INET,SOCK_DGRAM)");
+ return -1;
+ }
+ val = 1;
+ ret = setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,
+ (const char *)&val, sizeof(val));
+ if (ret< 0) {
+ perror("setsockopt(SOL_SOCKET,SO_REUSEADDR)");Please avoid leaking the file descriptor on error:
closesocket(fd);Since existing code also does this it may be more appropriate to send a follow-up patch that cleans up all of
net/socket.c.Reviewed-by Stefan Hajnoczi<[email protected]>
Quoted 7 lines
Quoted 1 line
Stefan
I can do that. However is it really a leak considering the fact that the program will call exit just after?
If it's a matter of consistency and coding style I would understand though.
net/socket.c should not make assumptions about the main program exiting after an error. NICs can be added at runtime using netdev_add and that should not leak file descriptors.
Quoted 4 lines
One more thing, git-format-patch added a "From" field to the header and caused this glitch in the mail. I thought git-send-mail or the mail server would handle it well but apparently not:
Quoted 8 lines
From
2f5b85fcadcfee3b75a6a21dc86d10b945c99f0fMon Sep 17 00:00:00 2001
From: Benjamin MARSILI <[email protected]>git-am didn't complain with the patch that I sent but it may break after gmail relayed it
(http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg03152.html).
The second from header is interpreted as text... Should I remove the first "From" field before sending the patch?
This is normal and is not a problem. Your git commit is authored by Benjamin MARSILI <[email protected]> but you sent the mail from Benjamin <[email protected]>.
git-am will apply the patch with Benjamin MARSILI <[email protected]> as the author and it will forget about Benjamin <[email protected]>. This is usually what you want - it let's you credit commits to other people but send the patch emails on their behalf.
Stefan
Quoted 28 lines · Stefan Hajnoczi
Quoted 27 lines · Benjamin
Quoted 24 lines · Stefan Hajnoczi
net/socket.c static int net_socket_mcast_init(VLANState *vlan, · line 554
Quoted 11 lines · Benjamin
net/socket.c +10
-0+ fd =qemu_socket (PF_INET ,SOCK_DGRAM ,0 ); +if (fd<0 ) { +perror ("socket(PF_INET, SOCK_DGRAM)" ); +return -1 ; + } + val =1 ; + ret =setsockopt (fd,SOL_SOCKET ,SO_REUSEADDR , + (const char *)&val,sizeof (val)); +if (ret<0 ) { +perror ("setsockopt(SOL_SOCKET, SO_REUSEADDR)" );Please avoid leaking the file descriptor on error:
closesocket(fd);Since existing code also does this it may be more appropriate to send a follow-up patch that cleans up all of
net/socket.c.Reviewed-by Stefan Hajnoczi<[email protected]>Stefan
Quoted 9 lines
Quoted 4 lines
I can do that. However is it really a leak considering the fact that the program will call exit just after?
If it's a matter of consistency and coding style I would understand though.
net/socket.cshould not make assumptions about the main program exiting after an error. NICs can be added at runtime usingnetdev_addand that should not leak file descriptors.
Ah, indeed, I mixed up "err" and "perror" since I'm used to calling "warn" instead of perror.
Quoted 17 lines
Quoted 4 lines
One more thing, git-format-patch added a "From" field to the header and caused this glitch in the mail. I thought git-send-mail or the mail server would handle it well but apparently not:
Quoted 8 lines
From
2f5b85fcadcfee3b75a6a21dc86d10b945c99f0fMon Sep 17 00:00:00 2001
From: Benjamin MARSILI<[email protected]>git-am didn't complain with the patch that I sent but it may break after gmail relayed it
(http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg03152.html).
The second from header is interpreted as text... Should I remove the first "From" field before sending the patch?This is normal and is not a problem. Your git commit is authored by Benjamin MARSILI<[email protected]> but you sent the mail from Benjamin<[email protected]>.
Quoted 7 lines
git-am will apply the patch with Benjamin MARSILI <[email protected]> as the author and it will forget about Benjamin <[email protected]>. This is usually what you want - it let's you credit commits to other people but send the patch emails on their behalf.
Stefan
Great, thank you, sending v3 soon.
Benjamin