It is currently Tue Dec 12, 2017 10:27 am


All times are UTC




Post new topic Reply to topic  [ 56 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject: Patches for Qemu
PostPosted: Thu Mar 03, 2011 9:06 pm 
Offline

Joined: Tue Jul 20, 2010 5:50 pm
Posts: 93
Hello,

below is the e1000 multicast + udp networking patch for Qemu 0.14.0 sources. Unfortunately I have not been able to test anything as it looks like the syntax for some commands has changed and qemu is complaining with:
Code:
drive with bus=0, unit=0 (index=0) exists

which I think basically means that the commands without "-" such as no-acpi auto no-graphics are parsed incorrectly.
In case somebody wan'ts to play with it, here is how to compile:

  • download and unzip qemu 0.14 sources
    Code:
    wget http://download.savannah.gnu.org/releases/qemu/qemu-0.14.0.tar.gz
    tar xvzf qemu-0.14.0.tar.gz
    cd qemu-0.14.0
  • Copy and paste the patch below into a file called qemu-14-0-patch-multicast-udp and insert it into the qemu directory above
  • Patch&compile&install the code
    Code:
    patch -p1 -i qemu-14-0-patch-multicast-udp
    ./configure --target-list=i386-softmmu
    make
    make install


e1000 multicast + udp networking patch for Qemu 0.14.0
Code:
diff -ruNB qemu-0.14.0/block/raw-win32.c qemu-0.14.0-patched/block/raw-win32.c
--- qemu-0.14.0/block/raw-win32.c   2011-02-16 15:44:04.000000000 +0100
+++ qemu-0.14.0-patched/block/raw-win32.c   2011-03-03 19:56:26.867873736 +0100
@@ -93,7 +93,7 @@
     else if (!(flags & BDRV_O_CACHE_WB))
         overlapped |= FILE_FLAG_WRITE_THROUGH;
     s->hfile = CreateFile(filename, access_flags,
-                          FILE_SHARE_READ, NULL,
+                          FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
                           OPEN_EXISTING, overlapped, NULL);
     if (s->hfile == INVALID_HANDLE_VALUE) {
         int err = GetLastError();
@@ -354,7 +354,7 @@
     else if (!(flags & BDRV_O_CACHE_WB))
         overlapped |= FILE_FLAG_WRITE_THROUGH;
     s->hfile = CreateFile(filename, access_flags,
-                          FILE_SHARE_READ, NULL,
+                          FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
                           create_flags, overlapped, NULL);
     if (s->hfile == INVALID_HANDLE_VALUE) {
         int err = GetLastError();
diff -ruNB qemu-0.14.0/hw/e1000.c qemu-0.14.0-patched/hw/e1000.c
--- qemu-0.14.0/hw/e1000.c   2011-02-16 15:44:04.000000000 +0100
+++ qemu-0.14.0-patched/hw/e1000.c   2011-03-03 19:42:36.017873734 +0100
@@ -573,7 +573,7 @@
     if (rctl & E1000_RCTL_UPE)         // promiscuous
         return 1;

-    if ((buf[0] & 1) && (rctl & E1000_RCTL_MPE))   // promiscuous mcast
+    if ((buf[0] & 1)) //&& (rctl & E1000_RCTL_MPE))   // promiscuous mcast
         return 1;

     if ((rctl & E1000_RCTL_BAM) && !memcmp(buf, bcast, sizeof bcast))
diff -ruNB qemu-0.14.0/Makefile.objs qemu-0.14.0-patched/Makefile.objs
--- qemu-0.14.0/Makefile.objs   2011-02-16 15:44:04.000000000 +0100
+++ qemu-0.14.0-patched/Makefile.objs   2011-03-03 19:43:34.067873738 +0100
@@ -34,6 +34,7 @@
net-nested-y = queue.o checksum.o util.o
net-nested-y += socket.o
net-nested-y += dump.o
+net-nested-y += udp.o
net-nested-$(CONFIG_POSIX) += tap.o
net-nested-$(CONFIG_LINUX) += tap-linux.o
net-nested-$(CONFIG_WIN32) += tap-win32.o
diff -ruNB qemu-0.14.0/net/udp.c qemu-0.14.0-patched/net/udp.c
--- qemu-0.14.0/net/udp.c   1970-01-01 01:00:00.000000000 +0100
+++ qemu-0.14.0-patched/net/udp.c   2011-03-03 19:44:36.957873740 +0100
@@ -0,0 +1,138 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "net/udp.h"
+
+#include "config-host.h"
+
+#ifndef _WIN32
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <netinet/udp.h>
+#endif
+
+#include "net.h"
+#include "qemu-char.h"
+#include "qemu-common.h"
+#include "qemu-option.h"
+#include "qemu_socket.h"
+#include "sysemu.h"
+
+
+typedef struct UDPState {
+    VLANClientState nc;
+    int rfd;
+    struct sockaddr_in sender;
+} UDPState;
+
+static void udp_to_qemu(void *opaque)
+{
+    UDPState *s = opaque;
+    uint8_t buf[4096];
+    int size;
+
+    size = recvfrom(s->rfd, (char *)buf, sizeof(buf), 0, NULL, NULL);
+    if (size > 0) {
+        qemu_send_packet(&s->nc, buf, size);
+    }
+}
+
+static ssize_t udp_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
+{
+    UDPState *s = DO_UPCAST(UDPState, nc, nc);
+    int ret;
+
+    do {
+      ret = sendto(s->rfd, (const char *)buf, size, 0, (struct sockaddr *)&s->sender, sizeof (s->sender));
+    } while (ret < 0 && errno == EINTR);
+
+    return ret;
+}
+
+static void udp_cleanup(VLANClientState *nc)
+{
+    UDPState *s = DO_UPCAST(UDPState, nc, nc);
+    qemu_set_fd_handler(s->rfd, NULL, NULL, NULL);
+    close(s->rfd);
+}
+
+static NetClientInfo net_udp_info = {
+    .type = NET_CLIENT_TYPE_UDP,
+    .size = sizeof(UDPState),
+    .receive = udp_receive,
+    .cleanup = udp_cleanup,
+};
+
+static int net_udp_init(VLANState *vlan, const char *model,
+          const char *name, int sport,
+          const char *daddr, int dport)
+{
+    VLANClientState *nc;
+    UDPState *s;
+    struct sockaddr_in receiver;
+    int ret;
+   
+    nc = qemu_new_net_client(&net_udp_info, vlan, NULL, model, name);
+
+    snprintf(nc->info_str, sizeof(nc->info_str),"udp: %i->%s:%i",
+        sport, daddr, dport);
+
+    s = DO_UPCAST(UDPState, nc, nc);
+
+    s->rfd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
+    receiver.sin_family = AF_INET;
+    receiver.sin_addr.s_addr = INADDR_ANY;
+    receiver.sin_port = htons(sport);
+    ret = bind(s->rfd, (struct sockaddr *)&receiver, sizeof(receiver));
+   
+    if (ret == -1) {
+      fprintf (stderr, "bind error:%s\n", strerror(errno));
+      return ret;
+    }
+
+    memset((char*)&s->sender, 0,sizeof(s->sender));
+    s->sender.sin_family = AF_INET;
+    s->sender.sin_port = htons(dport);
+    inet_aton(daddr, &s->sender.sin_addr);
+
+    qemu_set_fd_handler(s->rfd, udp_to_qemu, NULL, s);
+
+    return 0;
+}
+
+int net_init_udp(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)
+{
+    const char *daddr;
+    int sport, dport;
+
+    daddr  = qemu_opt_get(opts, "daddr");
+
+    sport = qemu_opt_get_number(opts, "sport", 0);
+    dport = qemu_opt_get_number(opts, "dport", 0);
+
+    if (net_udp_init(vlan, "udp", name, sport, daddr, dport) == -1) {
+        return -1;
+    }
+
+    return 0;
+}
diff -ruNB qemu-0.14.0/net/udp.h qemu-0.14.0-patched/net/udp.h
--- qemu-0.14.0/net/udp.h   1970-01-01 01:00:00.000000000 +0100
+++ qemu-0.14.0-patched/net/udp.h   2011-03-03 19:48:29.377873745 +0100
@@ -0,0 +1,32 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef QEMU_NET_UDP_H
+#define QEMU_NET_UDP_H
+
+#include "qemu-common.h"
+#include "qemu-option.h"
+
+int net_init_udp(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan);
+
+#endif /* QEMU_NET_UDP_H */
diff -ruNB qemu-0.14.0/net.c qemu-0.14.0-patched/net.c
--- qemu-0.14.0/net.c   2011-02-16 15:44:05.000000000 +0100
+++ qemu-0.14.0-patched/net.c   2011-03-03 19:54:26.057873750 +0100
@@ -30,6 +30,7 @@
#include "net/dump.h"
#include "net/slirp.h"
#include "net/vde.h"
+#include "net/udp.h"
#include "net/util.h"
#include "monitor.h"
#include "sysemu.h"
@@ -1081,6 +1082,26 @@
                 .help = "permissions for socket",
             },
             { /* end of list */ }
+        },{
+
+        .type = "udp",
+        .init = net_init_udp,
+        .desc = {
+            NET_COMMON_PARAMS_DESC,
+            {
+                .name = "sport",
+                .type = QEMU_OPT_NUMBER,
+                .help = "source port number",
+            }, {
+                .name = "daddr",
+                .type = QEMU_OPT_STRING,
+                .help = "destination IP address",
+            }, {
+                .name = "dport",
+                .type = QEMU_OPT_NUMBER,
+                .help = "destination port number",
+            },
+            { /* end of list */ }
         },
#endif
     }, {
diff -ruNB qemu-0.14.0/net.h qemu-0.14.0-patched/net.h
--- qemu-0.14.0/net.h   2011-02-16 15:44:05.000000000 +0100
+++ qemu-0.14.0-patched/net.h   2011-03-03 19:51:47.047873738 +0100
@@ -35,6 +35,7 @@
     NET_CLIENT_TYPE_TAP,
     NET_CLIENT_TYPE_SOCKET,
     NET_CLIENT_TYPE_VDE,
+    NET_CLIENT_TYPE_UDP,
     NET_CLIENT_TYPE_DUMP
} net_client_type;

diff -ruNB qemu-0.14.0/qemu-options.hx qemu-0.14.0-patched/qemu-options.hx
--- qemu-0.14.0/qemu-options.hx   2011-02-16 15:44:05.000000000 +0100
+++ qemu-0.14.0-patched/qemu-options.hx   2011-03-03 19:47:18.847873730 +0100
@@ -1070,6 +1070,8 @@
     "-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 udp[,vlan=n]sport=sport,dport=dport,daddr=host\n"
+    "           connect the vlan 'n' to a UDP tunnel (for Dynamips/GNS3)\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"




Top
 Profile  
 
 Post subject: Re: Patch for Qemu 0.14.0
PostPosted: Mon Mar 28, 2011 10:56 am 
Offline

Joined: Fri Mar 11, 2011 7:39 pm
Posts: 603
Location: Israel
Hello,

I have a big request for you, people.

Can you please patch VirtualBox code so it supports UDP network mode ?
I will help with QA effort here.

This will allow to write VBoxWrapper in python for GNS3. (similarly to QemuWrapper)

-Technologov


Top
 Profile  
 
 Post subject: Re: Patch for Qemu 0.14.0
PostPosted: Mon Mar 28, 2011 4:58 pm 
Offline
Site Admin

Joined: Sat Oct 11, 2008 1:41 pm
Posts: 2668
Location: Canada
Hello,

This is in the pipe (TODO list) but don't be to impatient as this could take some time, especially if I am the only one who want to work on it ;)

Cheers,

_________________
Jeremy, GNS3 Programmer & Benevolent Dictator for Life.


Top
 Profile  
 
 Post subject: Re: Patch for Qemu 0.14.0
PostPosted: Tue May 10, 2011 1:56 pm 
Offline

Joined: Wed Feb 16, 2011 5:07 pm
Posts: 114
i'm wondering... what's the issue with upstream?

Technologov told me it gets rejected.. any particular reason for that?


Top
 Profile  
 
 Post subject: Re: Patch for Qemu 0.14.0
PostPosted: Wed May 11, 2011 4:29 am 
Offline

Joined: Fri Mar 11, 2011 7:39 pm
Posts: 603
Location: Israel
Since no one answers, I will.

anubisg1: If you know C coding, you should submit the patch yourself. It will help GNS3 community.


Top
 Profile  
 
 Post subject: Re: Patch for Qemu 0.14.0
PostPosted: Wed May 11, 2011 8:26 am 
Offline

Joined: Wed Feb 16, 2011 5:07 pm
Posts: 114
building with this patch, any way fail like that:

Code:
gcc -m64 -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing   -fstack-protector-all -Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits  -I/usr/src/packages/BUILD/qemu-0.14.1/slirp -I. -I/usr/src/packages/BUILD/qemu-0.14.1 -MMD -MP -MT net.o -MF ./net.d -O2 -g  -c -o net.o net.c
net.c:1089:9: error: extra brace group at end of initializer
net.c:1089:9: error: (near initialization for 'net_client_types[5]')
net.c:1093:9: error: extra brace group at end of initializer
net.c:1093:9: error: (near initialization for 'net_client_types[5]')
net.c:1094:13: error: extra brace group at end of initializer
net.c:1094:13: error: (near initialization for 'net_client_types[5]')
net.c:1094:13: error: extra brace group at end of initializer
net.c:1094:13: error: (near initialization for 'net_client_types[5]')
net.c:1094:13: error: extra brace group at end of initializer
net.c:1094:13: error: (near initialization for 'net_client_types[5]')
net.c:1095:13: error: extra brace group at end of initializer
net.c:1095:13: error: (near initialization for 'net_client_types[5]')
net.c:1099:13: error: extra brace group at end of initializer
net.c:1099:13: error: (near initialization for 'net_client_types[5]')
net.c:1103:13: error: extra brace group at end of initializer
net.c:1103:13: error: (near initialization for 'net_client_types[5]')
net.c:1108:13: error: extra brace group at end of initializer
net.c:1108:13: error: (near initialization for 'net_client_types[5]')
net.c:1111:5: warning: excess elements in struct initializer
net.c:1111:5: warning: (near initialization for 'net_client_types[5]')
net.c:1111:5: error: extra brace group at end of initializer
net.c:1111:5: error: (near initialization for 'net_client_types[5]')
net.c:1114:9: error: extra brace group at end of initializer
net.c:1114:9: error: (near initialization for 'net_client_types[5]')
net.c:1115:13: error: extra brace group at end of initializer
net.c:1115:13: error: (near initialization for 'net_client_types[5]')
net.c:1115:13: error: extra brace group at end of initializer
net.c:1115:13: error: (near initialization for 'net_client_types[5]')
net.c:1115:13: error: extra brace group at end of initializer
net.c:1115:13: error: (near initialization for 'net_client_types[5]')
net.c:1116:13: error: extra brace group at end of initializer
net.c:1116:13: error: (near initialization for 'net_client_types[5]')
net.c:1120:13: error: extra brace group at end of initializer
net.c:1120:13: error: (near initialization for 'net_client_types[5]')
net.c:1125:13: error: extra brace group at end of initializer
net.c:1125:13: error: (near initialization for 'net_client_types[5]')
net.c:1127:5: warning: excess elements in struct initializer
net.c:1127:5: warning: (near initialization for 'net_client_types[5]')
net.c:1128:5: error: extra brace group at end of initializer
net.c:1128:5: error: (near initialization for 'net_client_types[5]')
net.c:1128:5: warning: excess elements in struct initializer
net.c:1128:5: warning: (near initialization for 'net_client_types[5]')
net.c:1129:2: error: expected '}' before ';' token


it fail as soon as it reach the changes made in net.c


Top
 Profile  
 
 Post subject: Re: Patch for Qemu 0.14.0
PostPosted: Wed May 11, 2011 9:01 am 
Offline

Joined: Fri Mar 11, 2011 7:39 pm
Posts: 603
Location: Israel
True.

Try the patch for Qemu 0.13.0 (it compiles, but not works), or patch for Qemu 0.11 (which works).


Top
 Profile  
 
 Post subject: Re: Patch for Qemu 0.14.0
PostPosted: Wed May 11, 2011 9:46 am 
Offline

Joined: Wed Feb 16, 2011 5:07 pm
Posts: 114
Technologov wrote:
True.

Try the patch for Qemu 0.13.0 (it compiles, but not works), or patch for Qemu 0.11 (which works).


as i'm working to have those things on next opensuse i need a patch for latest qemu 0.14.1 ..

0.13.0 as you said doesn't work.. so i bet i useless isn't it? the one for qemu 0.11 simply doesn't apply on new sources...

uff...


Top
 Profile  
 
 Post subject: Re: Patch for Qemu 0.14.0
PostPosted: Wed May 11, 2011 1:40 pm 
Offline

Joined: Wed Feb 16, 2011 5:07 pm
Posts: 114
found the problem.. there is a missing }

not sure if it works.. i need someone testing it..

it apply and build on qemu 0.14.1 please provide some feedback

Code:
diff -uNr old-qemu-0.14.1//block/raw-win32.c qemu-0.14.1/block/raw-win32.c
--- old-qemu-0.14.1//block/raw-win32.c   2011-05-06 21:01:43.000000000 +0200
+++ qemu-0.14.1/block/raw-win32.c   2011-05-11 15:41:45.744749392 +0200
@@ -93,7 +93,7 @@
     else if (!(flags & BDRV_O_CACHE_WB))
         overlapped |= FILE_FLAG_WRITE_THROUGH;
     s->hfile = CreateFile(filename, access_flags,
-                          FILE_SHARE_READ, NULL,
+                          FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
                           OPEN_EXISTING, overlapped, NULL);
     if (s->hfile == INVALID_HANDLE_VALUE) {
         int err = GetLastError();
@@ -354,7 +354,7 @@
     else if (!(flags & BDRV_O_CACHE_WB))
         overlapped |= FILE_FLAG_WRITE_THROUGH;
     s->hfile = CreateFile(filename, access_flags,
-                          FILE_SHARE_READ, NULL,
+                          FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
                           create_flags, overlapped, NULL);
     if (s->hfile == INVALID_HANDLE_VALUE) {
         int err = GetLastError();
diff -uNr old-qemu-0.14.1//hw/e1000.c qemu-0.14.1/hw/e1000.c
--- old-qemu-0.14.1//hw/e1000.c   2011-05-06 21:01:43.000000000 +0200
+++ qemu-0.14.1/hw/e1000.c   2011-05-11 15:41:45.744749392 +0200
@@ -573,7 +573,7 @@
     if (rctl & E1000_RCTL_UPE)         // promiscuous
         return 1;

-    if ((buf[0] & 1) && (rctl & E1000_RCTL_MPE))   // promiscuous mcast
+    if ((buf[0] & 1)) //&& (rctl & E1000_RCTL_MPE))   // promiscuous mcast
         return 1;

     if ((rctl & E1000_RCTL_BAM) && !memcmp(buf, bcast, sizeof bcast))
diff -uNr old-qemu-0.14.1//Makefile.objs qemu-0.14.1/Makefile.objs
--- old-qemu-0.14.1//Makefile.objs   2011-05-06 21:01:43.000000000 +0200
+++ qemu-0.14.1/Makefile.objs   2011-05-11 15:41:45.751749392 +0200
@@ -34,6 +34,7 @@
net-nested-y = queue.o checksum.o util.o
net-nested-y += socket.o
net-nested-y += dump.o
+net-nested-y += udp.o
net-nested-$(CONFIG_POSIX) += tap.o
net-nested-$(CONFIG_LINUX) += tap-linux.o
net-nested-$(CONFIG_WIN32) += tap-win32.o
diff -uNr old-qemu-0.14.1//net/udp.c qemu-0.14.1/net/udp.c
--- old-qemu-0.14.1//net/udp.c   1970-01-01 01:00:00.000000000 +0100
+++ qemu-0.14.1/net/udp.c   2011-05-11 15:41:45.752749392 +0200
@@ -0,0 +1,138 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "net/udp.h"
+
+#include "config-host.h"
+
+#ifndef _WIN32
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <netinet/udp.h>
+#endif
+
+#include "net.h"
+#include "qemu-char.h"
+#include "qemu-common.h"
+#include "qemu-option.h"
+#include "qemu_socket.h"
+#include "sysemu.h"
+
+
+typedef struct UDPState {
+    VLANClientState nc;
+    int rfd;
+    struct sockaddr_in sender;
+} UDPState;
+
+static void udp_to_qemu(void *opaque)
+{
+    UDPState *s = opaque;
+    uint8_t buf[4096];
+    int size;
+
+    size = recvfrom(s->rfd, (char *)buf, sizeof(buf), 0, NULL, NULL);
+    if (size > 0) {
+        qemu_send_packet(&s->nc, buf, size);
+    }
+}
+
+static ssize_t udp_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
+{
+    UDPState *s = DO_UPCAST(UDPState, nc, nc);
+    int ret;
+
+    do {
+      ret = sendto(s->rfd, (const char *)buf, size, 0, (struct sockaddr *)&s->sender, sizeof (s->sender));
+    } while (ret < 0 && errno == EINTR);
+
+    return ret;
+}
+
+static void udp_cleanup(VLANClientState *nc)
+{
+    UDPState *s = DO_UPCAST(UDPState, nc, nc);
+    qemu_set_fd_handler(s->rfd, NULL, NULL, NULL);
+    close(s->rfd);
+}
+
+static NetClientInfo net_udp_info = {
+    .type = NET_CLIENT_TYPE_UDP,
+    .size = sizeof(UDPState),
+    .receive = udp_receive,
+    .cleanup = udp_cleanup,
+};
+
+static int net_udp_init(VLANState *vlan, const char *model,
+          const char *name, int sport,
+          const char *daddr, int dport)
+{
+    VLANClientState *nc;
+    UDPState *s;
+    struct sockaddr_in receiver;
+    int ret;
+   
+    nc = qemu_new_net_client(&net_udp_info, vlan, NULL, model, name);
+
+    snprintf(nc->info_str, sizeof(nc->info_str),"udp: %i->%s:%i",
+        sport, daddr, dport);
+
+    s = DO_UPCAST(UDPState, nc, nc);
+
+    s->rfd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
+    receiver.sin_family = AF_INET;
+    receiver.sin_addr.s_addr = INADDR_ANY;
+    receiver.sin_port = htons(sport);
+    ret = bind(s->rfd, (struct sockaddr *)&receiver, sizeof(receiver));
+   
+    if (ret == -1) {
+      fprintf (stderr, "bind error:%s\n", strerror(errno));
+      return ret;
+    }
+
+    memset((char*)&s->sender, 0,sizeof(s->sender));
+    s->sender.sin_family = AF_INET;
+    s->sender.sin_port = htons(dport);
+    inet_aton(daddr, &s->sender.sin_addr);
+
+    qemu_set_fd_handler(s->rfd, udp_to_qemu, NULL, s);
+
+    return 0;
+}
+
+int net_init_udp(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)
+{
+    const char *daddr;
+    int sport, dport;
+
+    daddr  = qemu_opt_get(opts, "daddr");
+
+    sport = qemu_opt_get_number(opts, "sport", 0);
+    dport = qemu_opt_get_number(opts, "dport", 0);
+
+    if (net_udp_init(vlan, "udp", name, sport, daddr, dport) == -1) {
+        return -1;
+    }
+
+    return 0;
+}
diff -uNr old-qemu-0.14.1//net/udp.h qemu-0.14.1/net/udp.h
--- old-qemu-0.14.1//net/udp.h   1970-01-01 01:00:00.000000000 +0100
+++ qemu-0.14.1/net/udp.h   2011-05-11 15:41:45.752749392 +0200
@@ -0,0 +1,32 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef QEMU_NET_UDP_H
+#define QEMU_NET_UDP_H
+
+#include "qemu-common.h"
+#include "qemu-option.h"
+
+int net_init_udp(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan);
+
+#endif /* QEMU_NET_UDP_H */
diff -uNr old-qemu-0.14.1//net.c qemu-0.14.1/net.c
--- old-qemu-0.14.1//net.c   2011-05-06 21:01:44.000000000 +0200
+++ qemu-0.14.1/net.c   2011-05-11 15:42:53.145749408 +0200
@@ -30,6 +30,7 @@
#include "net/dump.h"
#include "net/slirp.h"
#include "net/vde.h"
+#include "net/udp.h"
#include "net/util.h"
#include "monitor.h"
#include "sysemu.h"
@@ -1085,9 +1086,31 @@
                 .help = "permissions for socket",
             },
             { /* end of list */ }
-        },
+       },
#endif
     }, {
+
+        .type = "udp",
+        .init = net_init_udp,
+        .desc = {
+            NET_COMMON_PARAMS_DESC,
+            {
+                .name = "sport",
+                .type = QEMU_OPT_NUMBER,
+     
+            .help = "source port number",
+            }, {
+                .name = "daddr",
+                .type = QEMU_OPT_STRING,
+                .help = "destination IP address",
+            }, {
+                .name = "dport",
+                .type = QEMU_OPT_NUMBER,
+                .help = "destination port number",
+            },
+            { /* end of list */ }
+        },
+    }, {
         .type = "dump",
         .init = net_init_dump,
         .desc = {
diff -uNr old-qemu-0.14.1//net.h qemu-0.14.1/net.h
--- old-qemu-0.14.1//net.h   2011-05-06 21:01:44.000000000 +0200
+++ qemu-0.14.1/net.h   2011-05-11 15:41:45.754749392 +0200
@@ -35,6 +35,7 @@
     NET_CLIENT_TYPE_TAP,
     NET_CLIENT_TYPE_SOCKET,
     NET_CLIENT_TYPE_VDE,
+    NET_CLIENT_TYPE_UDP,
     NET_CLIENT_TYPE_DUMP
} net_client_type;

diff -uNr old-qemu-0.14.1//qemu-options.hx qemu-0.14.1/qemu-options.hx
--- old-qemu-0.14.1//qemu-options.hx   2011-05-06 21:01:44.000000000 +0200
+++ qemu-0.14.1/qemu-options.hx   2011-05-11 15:41:45.755749392 +0200
@@ -1070,6 +1070,8 @@
     "-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 udp[,vlan=n]sport=sport,dport=dport,daddr=host\n"
+    "           connect the vlan 'n' to a UDP tunnel (for Dynamips/GNS3)\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"


Top
 Profile  
 
 Post subject: Re: Patch for Qemu 0.14.0
PostPosted: Wed May 11, 2011 1:44 pm 
Offline

Joined: Wed Feb 16, 2011 5:07 pm
Posts: 114
@ Technologov

if you use openSUSE, and you can test it, can you be so kind to use my repo "home:anubisg1:networking" ?

the packages are safe, are the same ones existing in the main repos (i am the one maintaining them any way)...

my changes are:

kvm --> enabled vde2 support
qemu --> enabled vde2 support and apply the patch for udp...

thanks

p.s. it's building right now.. it will take a little before it finish and the get published.

-- edit --

succesfully built and published




Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 56 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

phpBB SEO