qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] Solution for qemu mcast / ipv6?


From: Christian Perle
Subject: [Qemu-devel] Solution for qemu mcast / ipv6?
Date: Tue, 10 Mar 2009 16:50:33 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

Hello there,

We are using qemu's multicast networking feature (-net socket,mcast=...) to
connect some qemu instances (running linux guests) to each other. Qemu's
multicast networking code sets socket option IP_MULTICAST_LOOP to make
communication between local qemu instances possible. So each qemu gets
all the traffic, including its own.

This works fine as long as no ipv6 is used. Because ipv6 has a built-in
duplicate address detection (DAD) and each qemu instance sees its own
traffic, DAD will always detect a ipv6 address collision although there
is none.

Our solution is to patch the function qemu_send_packet() so it drops
packets from source mac address X if the network interface the packet
is being sent to has the same mac address X.

The patch adds a new member "macaddress" to the VLANClientState struct
which is filled by qemu_format_nic_info_str() during interface
initialization. An additional check in qemu_send_packet() decides if
the packet must be dropped.

----------------------------------------------------------------------
diff -ru qemu-0.10.0.orig/net.c qemu-0.10.0/net.c
--- qemu-0.10.0.orig/net.c      2009-03-04 23:54:45.000000000 +0100
+++ qemu-0.10.0/net.c   2009-03-06 16:38:09.000000000 +0100
@@ -303,6 +303,13 @@
              vc->model,
              macaddr[0], macaddr[1], macaddr[2],
              macaddr[3], macaddr[4], macaddr[5]);
+    /* copy mac address into struct for quick matching */
+    vc->macaddress[0] = macaddr[0];
+    vc->macaddress[1] = macaddr[1];
+    vc->macaddress[2] = macaddr[2];
+    vc->macaddress[3] = macaddr[3];
+    vc->macaddress[4] = macaddr[4];
+    vc->macaddress[5] = macaddr[5];
 }
 
 static char *assign_name(VLANClientState *vc1, const char *model)
@@ -407,6 +414,19 @@
 #endif
     for(vc = vlan->first_client; vc != NULL; vc = vc->next) {
         if (vc != vc1 && !vc->link_down) {
+           /*
+            * Workaround for IPv6 DAD problem
+            * note: this assumes offset 6 for src mac
+            */
+           if (size >= 12) {
+               if (0 == memcmp(buf+6, &(vc->macaddress),
+                       sizeof(vc->macaddress))) {
+#ifdef DEBUG_NET
+                       printf("ignore own packet for %s\n", vc->info_str);
+#endif
+                       continue;
+               }
+           }
             vc->fd_read(vc->opaque, buf, size);
         }
     }
diff -ru qemu-0.10.0.orig/net.h qemu-0.10.0/net.h
--- qemu-0.10.0.orig/net.h      2009-03-04 23:54:45.000000000 +0100
+++ qemu-0.10.0/net.h   2009-03-06 16:06:04.000000000 +0100
@@ -24,6 +24,8 @@
     struct VLANState *vlan;
     char *model;
     char *name;
+    /* mac address in binary format for quick matching */
+    uint8_t macaddress[6];
     char info_str[256];
 };
 
----------------------------------------------------------------------

Now the question: Is this a proper solution? Does it break anything?
So far we haven't seen any regression. It would be nice to have
this in standard qemu, maybe as a configurable option.

Greetings,
  Chris
-- 
Christian Perle                                    chris AT linuxinfotag.de
010111                                              http://chris.silmor.de/
101010                          LinuxGuitarKitesBicyclesBeerPizzaRaytracing




reply via email to

[Prev in Thread] Current Thread [Next in Thread]