GNS3
http://forum.gns3.net/

Patches for Qemu
http://forum.gns3.net/topic3224-20.html
Page 3 of 6

Author:  benjamin [ Thu Jun 23, 2011 2:18 pm ]
Post subject:  Patches for Qemu

Hi, I had some troubles with the patch here, so I decided to split it into several files, my attachment contains all patches, or you can copy/pastes them here:

QEMU 0.14.1

Makefile.objs
Quote:
--- qemu-0.14.1/Makefile.objs.orig Thu Jun 23 17:44:50 2011
+++ qemu-0.14.1/Makefile.objs Thu Jun 23 17:45:01 2011
@@ -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


block/raw-win32.c
Quote:
--- qemu-0.14.1/block/raw-win32.c.orig Thu Jun 23 17:04:36 2011
+++ qemu-0.14.1/block/raw-win32.c Thu Jun 23 17:05:31 2011
@@ -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();


hw/e1000.c
Quote:
--- qemu-0.14.1/hw/e1000.c.orig Thu Jun 23 17:01:19 2011
+++ qemu-0.14.1/hw/e1000.c Thu Jun 23 17:02:30 2011
@@ -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) // promiscuous mcast
return 1;

if ((rctl & E1000_RCTL_BAM) && !memcmp(buf, bcast, sizeof bcast))


net/udp.c
Quote:
--- qemu-0.14.1/net/udp.c.orig Thu Jun 23 17:09:02 2011
+++ qemu-0.14.1/net/udp.c Thu Jun 23 17:10:17 2011
@@ -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;
+}


net/udp.h
Quote:
--- qemu-0.14.1/net/udp.h.orig Thu Jun 23 17:12:45 2011
+++ qemu-0.14.1/net/udp.h Thu Jun 23 17:12:28 2011
@@ -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 */


net.c
Quote:
--- qemu-0.14.1/net.c.orig Thu Jun 23 17:16:49 2011
+++ qemu-0.14.1/net.c Thu Jun 23 17:22:17 2011
@@ -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"
@@ -1087,6 +1088,26 @@
{ /* 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,


net.h
Quote:
--- qemu-0.14.1/net.h.orig Thu Jun 23 17:23:17 2011
+++ qemu-0.14.1/net.h Thu Jun 23 17:23:43 2011
@@ -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;


To apply everything, take a bourne-like shell:
Code:
for i in `echo qemu-0.14.1_*`; do patch < $i; done


It works on OpenBSD and should work everywhere else, however I'd like people to test it and report here. Thanks in advance.

We tried some time ago to get those patches into qemu, without success. A forum member who knew a former qemu developer tried to get some help:
Quote:
I never had significant success getting my patches into qemu, their development process certainly does not work for me and I gave up on it.
If some of my patches did end up in qemu that was pure luck.
Since in addition my current employer for its own reasons discourages involvement with qemu I'm afraid I can't help, sorry.
But I expect that if you ask persistently enough on their mailing list someone will ultimately feel pity and at least try to help :-)


So if someone can deal with the qemu folks on their mailing list and ask them some help, we could hope for our patches to get in ;).

PS: http://www.4shared.com/file/EYuhhfii/qemu-0141p3.html for openbsd 4.9/i386 patched qemu, i don't know if it'll stay available tho

Attachments:
qemu-0.14.1-gns3_patches.tgz [2.98 KiB]
Downloaded 5016 times

Author:  garrymar [ Tue Jul 12, 2011 7:15 pm ]
Post subject:  Re: Patch for Qemu 0.14.X

It works in Gentoo. Patched without problems.
Two QEMU hosts connected via 2600 Router with NM-16ESW module. Hosts can ping themselves successfully.

P.S.: I can't find note about '-net udp' in help list.

Author:  Technologov [ Fri Jul 22, 2011 11:18 am ]
Post subject:  Re: Patch for Qemu 0.14.X

No idea. I don't use this patch for 0.14.1 (but I use older Qemu 0.13 with patch).

Author:  benjamin [ Sun Sep 11, 2011 9:20 am ]
Post subject:  Re: Patch for Qemu 0.14.X

Update for 0.15.0
You can find the patches here: http://code.gns3.net/qemu-patches/
Thanks for testing, if you have any problems send me a PM on the forum!

On FreeBSD, qemu is already patched by default, if you'd like your system to do the same, contact the maintainer or the developers and ask them, this could be difficult as all patches should be integrated upstream instead.

EDIT: The help output is now fixed

Author:  joeblow [ Thu Sep 15, 2011 3:55 am ]
Post subject:  Re: Patches for Qemu

apologies for a dumb question, but after patching qemu-0.14.1 with the udp-mcast patches, is there a configure option that must be used?

My usual configure is:

./configure --enable-kvm <cr>

Do I need an --enable-udp-mcast or something like that? The source doesn't seem to show that, but I'm not fluent in that stuff yet.

Thanks.

Author:  benjamin [ Thu Sep 15, 2011 2:23 pm ]
Post subject:  Re: Patches for Qemu

joeblow wrote:
apologies for a dumb question, but after patching qemu-0.14.1 with the udp-mcast patches, is there a configure option that must be used?

My usual configure is:

./configure --enable-kvm <cr>

Do I need an --enable-udp-mcast or something like that? The source doesn't seem to show that, but I'm not fluent in that stuff yet.

Thanks.


If the patches were applied without errors you don't have to do anything else.
Build and install Qemu as you would have done without the patches.

Cheers

Author:  joeblow [ Thu Sep 15, 2011 8:30 pm ]
Post subject:  Re: Patches for Qemu

Ok, thanks. Although it means that my problem(s) is elsewhere. Was hoping the unknown config setting was the answer to topic4033.html

thx again.

Author:  lamrau [ Thu Sep 15, 2011 8:52 pm ]
Post subject:  Re: Patches for Qemu

Trying to boot olive with any qemu higher than 0.11 I got this error:

em3: <Intel(R) PRO/1000 Network Connection Version - 3.2.18> port 0xe0000-0xe003f mem 0xc2080000-0xc209ffff irq 9 at device 6.0 on pci0
em3: Memory Access and/or Bus Master bits were not set!
em3: Unable to allocate bus resource: ioport
em3: Allocation of PCI resources failed
device_attach: em3 attach returned 6

Does anyone know what might cause this ?
I have tried 0.13, 0.15 (both patched) and always end up with no interfaces :(

Author:  benjamin [ Fri Sep 16, 2011 9:45 am ]
Post subject:  Re: Patches for Qemu

joeblow wrote:
Ok, thanks. Although it means that my problem(s) is elsewhere. Was hoping the unknown config setting was the answer to topic4033.html

thx again.


Yes, check your QEMU configuration in GNS3 preferences. I don't think it's related to the patches.

lamrau wrote:
I have tried 0.13, 0.15 (both patched) and always end up with no interfaces :(


Do you mind trying with the unpatched versions of Qemu ? Try to launch it from the terminal instead, if you have the same error then you should turn to the Qemu folks instead. If not we'll need more debug data, I suggest you create another topic.

Author:  benjamin [ Thu Sep 22, 2011 12:26 pm ]
Post subject:  Re: Patches for Qemu

bump, a little fix was pushed, please patch qemu with it instead.

Page 3 of 6 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/