* Re: [Qemu-devel] [PATCH v3] Support for UDP unicast network backend
2011-11-29 19:55 [Qemu-devel] [PATCH v3] Support for UDP unicast network backend Benjamin
@ 2011-11-29 11:52 ` Stefan Hajnoczi
2012-01-10 16:21 ` Benjamin
2012-01-06 19:16 ` Kamil Rytarowski
1 sibling, 1 reply; 7+ messages in thread
From: Stefan Hajnoczi @ 2011-11-29 11:52 UTC (permalink / raw)
To: Benjamin; +Cc: andreas.faerber, jan.kiszka, qemu-devel
On Tue, Nov 29, 2011 at 7:55 PM, Benjamin <mlspirat42@gmail.com> wrote:
>
> Signed-off-by: Benjamin <mlspirat42@gmail.com>
> ---
> net.c | 6 ++++-
> net/socket.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
> qemu-options.hx | 2 +
> 3 files changed, 78 insertions(+), 3 deletions(-)
Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> + s = net_socket_fd_init(vlan, model, name, fd, 0);
> + if (!s) {
> + return -1;
> + }
I'll add a TODO to my list about net_socket_fd_init(). It does not
consistently take ownership of fd. It may return NULL without closing
it, but then again it might close it on error in another code path :(.
Don't worry about this for now.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH v3] Support for UDP unicast network backend
@ 2011-11-29 19:55 Benjamin
2011-11-29 11:52 ` Stefan Hajnoczi
2012-01-06 19:16 ` Kamil Rytarowski
0 siblings, 2 replies; 7+ messages in thread
From: Benjamin @ 2011-11-29 19:55 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, andreas.faerber, jan.kiszka, Benjamin
Signed-off-by: Benjamin <mlspirat42@gmail.com>
---
net.c | 6 ++++-
net/socket.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
qemu-options.hx | 2 +
3 files changed, 78 insertions(+), 3 deletions(-)
diff --git a/net.c b/net.c
index cb52050..8e957b2 100644
--- a/net.c
+++ b/net.c
@@ -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 */ }
},
diff --git a/net/socket.c b/net/socket.c
index e9ef128..69a03e6 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -524,6 +524,57 @@ static int net_socket_mcast_init(VLANState *vlan,
}
+static int net_socket_udp_init(VLANState *vlan,
+ const char *model,
+ const char *name,
+ const char *rhost,
+ const char *lhost)
+{
+ NetSocketState *s;
+ int fd, val, ret;
+ struct sockaddr_in laddr, raddr;
+
+ if (parse_host_port(&laddr, lhost) < 0) {
+ return -1;
+ }
+
+ if (parse_host_port(&raddr, rhost) < 0) {
+ return -1;
+ }
+
+ 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)");
+ closesocket(fd);
+ return -1;
+ }
+ ret = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr));
+ if (ret < 0) {
+ perror("bind");
+ closesocket(fd);
+ return -1;
+ }
+
+ s = net_socket_fd_init(vlan, model, name, fd, 0);
+ if (!s) {
+ return -1;
+ }
+
+ s->dgram_dst = raddr;
+
+ snprintf(s->nc.info_str, sizeof(s->nc.info_str),
+ "socket: udp=%s:%d",
+ inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port));
+ return 0;
+}
+
int net_init_socket(QemuOpts *opts,
Monitor *mon,
const char *name,
@@ -597,10 +648,28 @@ int net_init_socket(QemuOpts *opts,
if (net_socket_mcast_init(vlan, "socket", name, mcast, localaddr) == -1) {
return -1;
}
+ } else if (qemu_opt_get(opts, "udp")) {
+ const char *udp, *localaddr;
+
+ if (qemu_opt_get(opts, "fd") ||
+ qemu_opt_get(opts, "connect") ||
+ qemu_opt_get(opts, "listen") ||
+ qemu_opt_get(opts, "mcast")) {
+ error_report("fd=, connect=, listen=\
+ and mcast= is invalid with udp=");
+ return -1;
+ }
+
+ udp = qemu_opt_get(opts, "udp");
+ localaddr = qemu_opt_get(opts, "localaddr");
+
+ if (net_socket_udp_init(vlan, "udp", name, udp, localaddr) == -1) {
+ return -1;
+ }
} else {
- error_report("-socket requires fd=, listen=, connect= or mcast=");
+ error_report("-socket requires fd=, listen=, \
+ connect=, mcast= or udp=");
return -1;
}
-
return 0;
}
diff --git a/qemu-options.hx b/qemu-options.hx
index 681eaf1..5495368 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -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"
--
1.7.6
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v3] Support for UDP unicast network backend
2011-11-29 19:55 [Qemu-devel] [PATCH v3] Support for UDP unicast network backend Benjamin
2011-11-29 11:52 ` Stefan Hajnoczi
@ 2012-01-06 19:16 ` Kamil Rytarowski
2012-01-06 19:46 ` Stefan Hajnoczi
1 sibling, 1 reply; 7+ messages in thread
From: Kamil Rytarowski @ 2012-01-06 19:16 UTC (permalink / raw)
To: qemu-devel; +Cc: Benjamin MARSILI
W dniu 29.11.2011 20:55, Benjamin pisze:
> Signed-off-by: Benjamin<mlspirat42@gmail.com>
> ---
> net.c | 6 ++++-
> net/socket.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
> qemu-options.hx | 2 +
> 3 files changed, 78 insertions(+), 3 deletions(-)
>
> diff --git a/net.c b/net.c
> index cb52050..8e957b2 100644
> --- a/net.c
> +++ b/net.c
> @@ -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 */ }
> },
> diff --git a/net/socket.c b/net/socket.c
> index e9ef128..69a03e6 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -524,6 +524,57 @@ static int net_socket_mcast_init(VLANState *vlan,
>
> }
>
> +static int net_socket_udp_init(VLANState *vlan,
> + const char *model,
> + const char *name,
> + const char *rhost,
> + const char *lhost)
> +{
> + NetSocketState *s;
> + int fd, val, ret;
> + struct sockaddr_in laddr, raddr;
> +
> + if (parse_host_port(&laddr, lhost)< 0) {
> + return -1;
> + }
> +
> + if (parse_host_port(&raddr, rhost)< 0) {
> + return -1;
> + }
> +
> + 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)");
> + closesocket(fd);
> + return -1;
> + }
> + ret = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr));
> + if (ret< 0) {
> + perror("bind");
> + closesocket(fd);
> + return -1;
> + }
> +
> + s = net_socket_fd_init(vlan, model, name, fd, 0);
> + if (!s) {
> + return -1;
> + }
> +
> + s->dgram_dst = raddr;
> +
> + snprintf(s->nc.info_str, sizeof(s->nc.info_str),
> + "socket: udp=%s:%d",
> + inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port));
> + return 0;
> +}
> +
> int net_init_socket(QemuOpts *opts,
> Monitor *mon,
> const char *name,
> @@ -597,10 +648,28 @@ int net_init_socket(QemuOpts *opts,
> if (net_socket_mcast_init(vlan, "socket", name, mcast, localaddr) == -1) {
> return -1;
> }
> + } else if (qemu_opt_get(opts, "udp")) {
> + const char *udp, *localaddr;
> +
> + if (qemu_opt_get(opts, "fd") ||
> + qemu_opt_get(opts, "connect") ||
> + qemu_opt_get(opts, "listen") ||
> + qemu_opt_get(opts, "mcast")) {
> + error_report("fd=, connect=, listen=\
> + and mcast= is invalid with udp=");
> + return -1;
> + }
> +
> + udp = qemu_opt_get(opts, "udp");
> + localaddr = qemu_opt_get(opts, "localaddr");
> +
> + if (net_socket_udp_init(vlan, "udp", name, udp, localaddr) == -1) {
> + return -1;
> + }
> } else {
> - error_report("-socket requires fd=, listen=, connect= or mcast=");
> + error_report("-socket requires fd=, listen=, \
> + connect=, mcast= or udp=");
> return -1;
> }
> -
> return 0;
> }
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 681eaf1..5495368 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -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"
ping!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v3] Support for UDP unicast network backend
2012-01-06 19:16 ` Kamil Rytarowski
@ 2012-01-06 19:46 ` Stefan Hajnoczi
0 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2012-01-06 19:46 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Kamil Rytarowski, qemu-devel, Benjamin MARSILI
On Fri, Jan 6, 2012 at 7:16 PM, Kamil Rytarowski <n54@gmx.com> wrote:
> ping!
Looks good to me.
Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v3] Support for UDP unicast network backend
2012-01-10 16:21 ` Benjamin
@ 2012-01-10 10:59 ` Andreas Färber
2012-01-10 11:11 ` Stefan Hajnoczi
0 siblings, 1 reply; 7+ messages in thread
From: Andreas Färber @ 2012-01-10 10:59 UTC (permalink / raw)
To: Benjamin, Stefan Hajnoczi; +Cc: jan.kiszka, qemu-devel
Am 10.01.2012 17:21, schrieb Benjamin:
> On 11/29/11 20:52, Stefan Hajnoczi wrote:
>> On Tue, Nov 29, 2011 at 7:55 PM, Benjamin<mlspirat42@gmail.com> wrote:
>>>
>>> Signed-off-by: Benjamin<mlspirat42@gmail.com>
A minor nit: the SoB is a legal assertion that you not stole, etc. the
code, and as such it should include first and last name.
>>> ---
>>> net.c | 6 ++++-
>>> net/socket.c | 73
>>> +++++++++++++++++++++++++++++++++++++++++++++++++++++-
>>> qemu-options.hx | 2 +
>>> 3 files changed, 78 insertions(+), 3 deletions(-)
>>
>> Reviewed-by: Stefan Hajnoczi<stefanha@linux.vnet.ibm.com>
>>
>>> + s = net_socket_fd_init(vlan, model, name, fd, 0);
>>> + if (!s) {
>>> + return -1;
>>> + }
>>
>> I'll add a TODO to my list about net_socket_fd_init(). It does not
>> consistently take ownership of fd. It may return NULL without closing
>> it, but then again it might close it on error in another code path :(.
Hasn't this been taken care of in the meantime? Any changes needed for
that, Stefan?
> Me again, is it supposed to take that long before the patch is
> accepted?
Not supposed to, but sometimes it does...
Andreas
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v3] Support for UDP unicast network backend
2012-01-10 10:59 ` Andreas Färber
@ 2012-01-10 11:11 ` Stefan Hajnoczi
0 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2012-01-10 11:11 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Andreas Färber, jan.kiszka, Benjamin, qemu-devel
On Tue, Jan 10, 2012 at 10:59 AM, Andreas Färber <andreas.faerber@web.de> wrote:
> Am 10.01.2012 17:21, schrieb Benjamin:
>> On 11/29/11 20:52, Stefan Hajnoczi wrote:
>>> On Tue, Nov 29, 2011 at 7:55 PM, Benjamin<mlspirat42@gmail.com> wrote:
>>>>
>>>> Signed-off-by: Benjamin<mlspirat42@gmail.com>
>
> A minor nit: the SoB is a legal assertion that you not stole, etc. the
> code, and as such it should include first and last name.
>
>>>> ---
>>>> net.c | 6 ++++-
>>>> net/socket.c | 73
>>>> +++++++++++++++++++++++++++++++++++++++++++++++++++++-
>>>> qemu-options.hx | 2 +
>>>> 3 files changed, 78 insertions(+), 3 deletions(-)
>>>
>>> Reviewed-by: Stefan Hajnoczi<stefanha@linux.vnet.ibm.com>
>>>
>>>> + s = net_socket_fd_init(vlan, model, name, fd, 0);
>>>> + if (!s) {
>>>> + return -1;
>>>> + }
>>>
>>> I'll add a TODO to my list about net_socket_fd_init(). It does not
>>> consistently take ownership of fd. It may return NULL without closing
>>> it, but then again it might close it on error in another code path :(.
>
> Hasn't this been taken care of in the meantime? Any changes needed for
> that, Stefan?
It's been taken care of, no changes are needed to this patch.
>> Me again, is it supposed to take that long before the patch is
>> accepted?
>
> Not supposed to, but sometimes it does...
This is ready to merge, we need a committer to take a look and apply it.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v3] Support for UDP unicast network backend
2011-11-29 11:52 ` Stefan Hajnoczi
@ 2012-01-10 16:21 ` Benjamin
2012-01-10 10:59 ` Andreas Färber
0 siblings, 1 reply; 7+ messages in thread
From: Benjamin @ 2012-01-10 16:21 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: andreas.faerber, jan.kiszka, qemu-devel
On 11/29/11 20:52, Stefan Hajnoczi wrote:
> On Tue, Nov 29, 2011 at 7:55 PM, Benjamin<mlspirat42@gmail.com> wrote:
>>
>> Signed-off-by: Benjamin<mlspirat42@gmail.com>
>> ---
>> net.c | 6 ++++-
>> net/socket.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
>> qemu-options.hx | 2 +
>> 3 files changed, 78 insertions(+), 3 deletions(-)
>
> Reviewed-by: Stefan Hajnoczi<stefanha@linux.vnet.ibm.com>
>
>> + s = net_socket_fd_init(vlan, model, name, fd, 0);
>> + if (!s) {
>> + return -1;
>> + }
>
> I'll add a TODO to my list about net_socket_fd_init(). It does not
> consistently take ownership of fd. It may return NULL without closing
> it, but then again it might close it on error in another code path :(.
> Don't worry about this for now.
>
> Stefan
Me again, is it supposed to take that long before the patch is
accepted? Did I forget something?
Regards,
Benjamin
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-01-10 11:11 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-29 19:55 [Qemu-devel] [PATCH v3] Support for UDP unicast network backend Benjamin
2011-11-29 11:52 ` Stefan Hajnoczi
2012-01-10 16:21 ` Benjamin
2012-01-10 10:59 ` Andreas Färber
2012-01-10 11:11 ` Stefan Hajnoczi
2012-01-06 19:16 ` Kamil Rytarowski
2012-01-06 19:46 ` Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).