[ovs-dev] [netlink v4 46/52] datapath: Extend compatibility code for genl_register_mc_group().

Ben Pfaff blp at nicira.com
Wed Jan 12 05:49:58 UTC 2011


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 at nicira.com>
---
 datapath/linux-2.6/Modules.mk                      |    3 +-
 datapath/linux-2.6/compat-2.6/genetlink-brcompat.c |   16 ++----------
 .../linux-2.6/compat-2.6/genetlink-openvswitch.c   |   24 ++-----------------
 datapath/linux-2.6/compat-2.6/genetlink.inc        |   19 +++++++++++++++
 .../linux-2.6/compat-2.6/include/net/genetlink.h   |    6 -----
 5 files changed, 27 insertions(+), 41 deletions(-)
 create mode 100644 datapath/linux-2.6/compat-2.6/genetlink.inc

diff --git a/datapath/linux-2.6/Modules.mk b/datapath/linux-2.6/Modules.mk
index 1bc092e..48d3284 100644
--- a/datapath/linux-2.6/Modules.mk
+++ b/datapath/linux-2.6/Modules.mk
@@ -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 = \
diff --git a/datapath/linux-2.6/compat-2.6/genetlink-brcompat.c b/datapath/linux-2.6/compat-2.6/genetlink-brcompat.c
index c43b3ce..31108cd 100644
--- a/datapath/linux-2.6/compat-2.6/genetlink-brcompat.c
+++ b/datapath/linux-2.6/compat-2.6/genetlink-brcompat.c
@@ -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"
diff --git a/datapath/linux-2.6/compat-2.6/genetlink-openvswitch.c b/datapath/linux-2.6/compat-2.6/genetlink-openvswitch.c
index 9e09215..3e687b7 100644
--- a/datapath/linux-2.6/compat-2.6/genetlink-openvswitch.c
+++ b/datapath/linux-2.6/compat-2.6/genetlink-openvswitch.c
@@ -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
index 0000000..1a2edfc
--- /dev/null
+++ b/datapath/linux-2.6/compat-2.6/genetlink.inc
@@ -0,0 +1,19 @@
+#include <net/genetlink.h>
+#include <linux/version.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
+int genl_register_mc_group(struct genl_family *family,
+			   struct genl_multicast_group *grp)
+{
+	/* This code runs single-threaded. */
+	static int next_group = GENL_FIRST_MCGROUP;
+
+	grp->id = next_group;
+	grp->family = family;
+
+	if (++next_group > GENL_LAST_MCGROUP)
+		next_group = GENL_FIRST_MCGROUP;
+
+	return 0;
+}
+#endif /* kernel < 2.6.23 */
diff --git a/datapath/linux-2.6/compat-2.6/include/net/genetlink.h b/datapath/linux-2.6/compat-2.6/include/net/genetlink.h
index 4f20366..038fd46 100644
--- a/datapath/linux-2.6/compat-2.6/include/net/genetlink.h
+++ b/datapath/linux-2.6/compat-2.6/include/net/genetlink.h
@@ -10,12 +10,6 @@
 
 #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
-- 
1.7.1





More information about the dev mailing list