From: Jan Kiszka <jan.kiszka@web.de>
To: Benjamin <mlspirat42@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] Support for UDP unicast network backend
Date: Mon, 07 Nov 2011 12:23:36 +0100 [thread overview]
Message-ID: <4EB7BFB8.8060204@web.de> (raw)
In-Reply-To: <4EB7E4C3.2090605@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 5521 bytes --]
On 2011-11-07 15:01, Benjamin wrote:
> Here is the updated patch, using only localaddr. mcast expects it to be
> addr whereas udp expects addr:port. It's documented in the help output.
>
> I also corrected the error message when checking udp parameters.
Sorry, missed that: please never forget to run your patches through
checkpatch.pl. Once fixed, consider this
Acked-by: Jan Kiszka <jan.kiszka@siemens.com>
>
> Signed-off-by: Benjamin MARSILI <marsil_b@epitech.eu>
> ---
> net.c | 9 +++++-
> net/socket.c | 66
> +++++++++++++++++++++++++++++++++++++++++++++++++++++-
> qemu-options.hx | 2 +
> 3 files changed, 73 insertions(+), 4 deletions(-)
>
> diff --git a/net.c b/net.c
> index cb52050..c75be08 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 */ }
> },
> @@ -1070,7 +1074,8 @@ int net_client_init(Monitor *mon, QemuOpts *opts,
> int is_netdev)
> #ifdef CONFIG_VDE
> strcmp(type, "vde") != 0 &&
> #endif
> - strcmp(type, "socket") != 0) {
> + strcmp(type, "socket") != 0 &&
> + strcmp(type, "udp") != 0) {
> qerror_report(QERR_INVALID_PARAMETER_VALUE, "type",
> "a netdev backend type");
> return -1;
> diff --git a/net/socket.c b/net/socket.c
> index e9ef128..3601228 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -524,6 +524,52 @@ 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)");
> + return -1;
> + }
> + ret = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr));
> + if (ret < 0) {
> + perror("bind");
> + 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 +643,26 @@ 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.3.5
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
next prev parent reply other threads:[~2011-11-07 12:23 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-06 17:08 [Qemu-devel] Integrating Dynamips and GNS3 UDP tunnels (Patches) Benjamin Epitech
2011-10-07 8:35 ` Jan Kiszka
2011-10-08 17:31 ` Benjamin
2011-10-08 9:29 ` Jan Kiszka
2011-10-09 17:02 ` Benjamin
2011-11-06 20:55 ` [Qemu-devel] [PATCH] Support for UDP unicast network backend Benjamin
2011-11-06 13:54 ` Jan Kiszka
2011-11-07 14:01 ` Benjamin
2011-11-07 11:23 ` Jan Kiszka [this message]
2011-11-07 22:03 ` Benjamin
2011-11-08 10:52 ` Jan Kiszka
2011-11-09 14:26 ` Benjamin
2011-11-09 14:53 ` Benjamin
2011-11-09 10:41 ` Andreas Färber
2011-11-24 1:02 ` [Qemu-devel] [PATCH v2] " Benjamin
2011-11-24 9:13 ` Stefan Hajnoczi
2011-11-06 14:28 ` [Qemu-devel] [PATCH] " Benjamin Epitech
2011-10-08 9:37 ` [Qemu-devel] Integrating Dynamips and GNS3 UDP tunnels (Patches) Stefan Weil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4EB7BFB8.8060204@web.de \
--to=jan.kiszka@web.de \
--cc=mlspirat42@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).