datapath: Extend compatibility code for genl_register_mc_group().
authorBen Pfaff <blp@nicira.com>
Tue, 18 Jan 2011 23:23:48 +0000 (15:23 -0800)
committerBen Pfaff <blp@nicira.com>
Fri, 28 Jan 2011 05:08:41 +0000 (21:08 -0800)
The existing compatibility code for genl_register_mc_group() always returns
the same value because the only caller (in brcompat_mod) only needs a
single multicast group.  However, when the datapath is converted over to
using Netlink in an upcoming commit, openvswitch_mod will start needing a
number of multicast groups, so this commit adds this ability.

The multicast group ranges differ for brcompat_mod and openvswitch_mod so
that they don't interfere with one another.  (This would waste time in
ovs-brcompatd and ovs-vswitchd, although it would not be fatal.)

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jesse Gross <jesse@nicira.com>
datapath/linux-2.6/Modules.mk
datapath/linux-2.6/compat-2.6/genetlink-brcompat.c
datapath/linux-2.6/compat-2.6/genetlink-openvswitch.c
datapath/linux-2.6/compat-2.6/genetlink.inc [new file with mode: 0644]
datapath/linux-2.6/compat-2.6/include/net/genetlink.h

index 2e779aa..29cbd93 100644 (file)
@@ -51,7 +51,8 @@ openvswitch_headers += \
        linux-2.6/compat-2.6/include/net/ip.h \
        linux-2.6/compat-2.6/include/net/netlink.h \
        linux-2.6/compat-2.6/include/net/protocol.h \
-       linux-2.6/compat-2.6/include/net/route.h
+       linux-2.6/compat-2.6/include/net/route.h \
+       linux-2.6/compat-2.6/genetlink.inc
 
 both_modules += brcompat
 brcompat_sources = \
index c43b3ce..31108cd 100644 (file)
@@ -1,20 +1,10 @@
-#include "net/genetlink.h"
-
-#include <linux/version.h>
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
-
 /* We fix grp->id to 32 so that it doesn't collide with any of the multicast
  * groups selected by openvswitch_mod, which uses groups 16 through 31.
  * Collision isn't fatal--multicast listeners should check that the family is
  * the one that they want and discard others--but it wastes time and memory to
  * receive unwanted messages. */
-int genl_register_mc_group(struct genl_family *family,
-                          struct genl_multicast_group *grp)
-{
-       grp->id = 32;
-       grp->family = family;
 
-       return 0;
-}
+#define GENL_FIRST_MCGROUP 32
+#define GENL_LAST_MCGROUP  32
 
-#endif /* kernel < 2.6.23 */
+#include "genetlink.inc"
index 9e09215..3e687b7 100644 (file)
@@ -1,22 +1,4 @@
-#include "net/genetlink.h"
+#define GENL_FIRST_MCGROUP 16
+#define GENL_LAST_MCGROUP  31
 
-#include <linux/version.h>
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
-
-/* We use multicast groups 16 through 31 to avoid colliding with the multicast
- * group selected by brcompat_mod, which uses groups 32.  Collision isn't
- * fatal--multicast listeners should check that the family is the one that they
- * want and discard others--but it wastes time and memory to receive unwanted
- * messages. */
-int genl_register_mc_group(struct genl_family *family,
-                          struct genl_multicast_group *grp)
-{
-       /* This code is called single-threaded. */
-       static unsigned int next_id = 0;
-       grp->id = next_id++ % 16 + 16;
-       grp->family = family;
-
-       return 0;
-}
-
-#endif /* kernel < 2.6.23 */
+#include "genetlink.inc"
diff --git a/datapath/linux-2.6/compat-2.6/genetlink.inc b/datapath/linux-2.6/compat-2.6/genetlink.inc
new file mode 100644 (file)
index 0000000..e6ebe2f
--- /dev/null
@@ -0,0 +1,26 @@
+/* -*- c -*- */
+
+#include <net/genetlink.h>
+#include <linux/version.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
+#include <linux/mutex.h>
+
+static DEFINE_MUTEX(mc_group_mutex);
+
+int genl_register_mc_group(struct genl_family *family,
+                          struct genl_multicast_group *grp)
+{
+       static int next_group = GENL_FIRST_MCGROUP;
+
+       mutex_lock(&mc_group_mutex);
+       grp->id = next_group;
+       grp->family = family;
+
+       if (++next_group > GENL_LAST_MCGROUP)
+               next_group = GENL_FIRST_MCGROUP;
+       mutex_unlock(&mc_group_mutex);
+
+       return 0;
+}
+#endif /* kernel < 2.6.23 */
index 4f20366..038fd46 100644 (file)
 
 #include <linux/genetlink.h>
 
-/*----------------------------------------------------------------------------
- * In 2.6.23, registering of multicast groups was added.  Our compatability
- * layer just supports registering a single group, since that's all we
- * need.
- */
-
 /**
  * struct genl_multicast_group - generic netlink multicast group
  * @name: name of the multicast group, names are per-family