From: Ben Pfaff Date: Tue, 18 Jan 2011 23:23:48 +0000 (-0800) Subject: datapath: Extend compatibility code for genl_register_mc_group(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f2e8c9ef975181317ded7d71c8b5bec172ccb8f;p=openvswitch datapath: Extend compatibility code for genl_register_mc_group(). 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 Acked-by: Jesse Gross --- diff --git a/datapath/linux-2.6/Modules.mk b/datapath/linux-2.6/Modules.mk index 2e779aa4..29cbd93d 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 c43b3ce4..31108cda 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 -#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 9e09215f..3e687b7e 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 -#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 00000000..e6ebe2ff --- /dev/null +++ b/datapath/linux-2.6/compat-2.6/genetlink.inc @@ -0,0 +1,26 @@ +/* -*- c -*- */ + +#include +#include + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) +#include + +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 */ 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 4f203662..038fd464 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 -/*---------------------------------------------------------------------------- - * 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