diff mbox

Support for UDP unicast network backend

Message ID 4EBA93FF.4050801@gmail.com
State New
Headers show

Commit Message

Benjamin Nov. 9, 2011, 2:53 p.m. UTC
On 11/09/11 15:26, Benjamin wrote:
> Oh, I forgot to remove a line from the old patch, when I wanted to
> introduce -netdev udp. Now it's just -net[dev] socket.
> Here's the updated patch, my apologies.
> It didn't break anything, it's just useless, use this instead.
>
>

I sent the old one again...
This one is correct.
Sorry for the noise.

Support for UDP unicast network backend

Signed-off-by: Benjamin MARSILI <marsil_b@epitech.eu>
Acked-by: Jan Kiszka<jan.kiszka@siemens.com>

---
  net.c           |    6 ++++-
  net/socket.c    |   71 
+++++++++++++++++++++++++++++++++++++++++++++++++++++-
  qemu-options.hx |    2 +
  3 files changed, 76 insertions(+), 3 deletions(-)

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"

Comments

Andreas Färber Nov. 9, 2011, 10:41 a.m. UTC | #1
Am 09.11.2011 15:53, schrieb Benjamin:
> On 11/09/11 15:26, Benjamin wrote:
>> Oh, I forgot to remove a line from the old patch, when I wanted to
>> introduce -netdev udp. Now it's just -net[dev] socket.
>> Here's the updated patch, my apologies.
>> It didn't break anything, it's just useless, use this instead.
>>
>>
> 
> I sent the old one again...
> This one is correct.
> Sorry for the noise.
> 
> Support for UDP unicast network backend
> 
> Signed-off-by: Benjamin MARSILI <marsil_b@epitech.eu>
> Acked-by: Jan Kiszka<jan.kiszka@siemens.com>
> 
> ---

Actually, revised patches like any others should be submitted with
git-send-email. That is, make the description commit'able and put all
personal comments, questions, quotations below the --- line. That way it
can be applied with git-am. Also use --subject-prefix="PATCH v2" and so
on to identify different patch versions.
I'd also suggest to prefix your subject with "net: " to make clear which
part it touches.

Regards,
Andreas
diff mbox

Patch

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..ca183f2 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -524,6 +524,55 @@  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 +646,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