From: Ben Pfaff Date: Wed, 23 Apr 2008 21:25:27 +0000 (-0700) Subject: Support NETLINK_ADD_MEMBERSHIP even when compiled with old kernel headers. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15bf0e0b5d8a040953fca5f6b0c18c0630e9887f;p=openvswitch Support NETLINK_ADD_MEMBERSHIP even when compiled with old kernel headers. Commit 0a9024a2d7, "Changes based on feedback from GigaFin," added support for compiling on a system that lacked up-to-date Linux kernel headers, by dropping support for a feature only in newer kernels on such a system. But the code already supported such a system properly; only the lack of a macro definition kept it from compiling. So define the macro ourselves instead of disabling the feature. To elaborate, there are two issues here. The first is kernel support for NETLINK_ADD_MEMBERSHIP. Older kernels don't support this. But NETLINK_ADD_MEMBERSHIP was added at the same time as support for more than 32 netlink multicast groups. Netlink multicast groups numbered less than 32 can be subscribed using a different mechanism, and in fact we do that for such groups. Thus, attempting to use NETLINK_ADD_MEMBERSHIP on an older kernel basically can't happen, and if it did it would be a bug in the OpenFlow kernel module for telling userspace to subscribe to a multicast group that cannot exist on that kernel. The second is the kernel headers that the userspace programs are compiled with. Without the change quoted below, the userspace programs will silently fail if they are compiled with 2.4.x headers and then run on a 2.6.x kernel and given a multicast group numbered above 32, because they will not even try to subscribe to that group. With the change, the userspace programs will work properly when run on 2.4.x or 2.6.x kernels regardless of the multicast group number and regardless of whether the headers they were compiled against were from 2.4.x or 2.6.x. --- diff --git a/lib/netlink.c b/lib/netlink.c index 898f7400..36754ee4 100644 --- a/lib/netlink.c +++ b/lib/netlink.c @@ -150,7 +150,13 @@ nl_sock_create(int protocol, int multicast_group, goto error_free_pid; } -#ifdef NETLINK_ADD_MEMBERSHIP + /* Older kernel headers failed to define this macro. We want our programs + * to support the newer kernel features even if compiled with older + * headers, so define it ourselves in such a case. */ +#ifndef NETLINK_ADD_MEMBERSHIP +#define NETLINK_ADD_MEMBERSHIP 1 +#endif + /* This method of joining multicast groups is only supported by newish * kernels, but it allows for an arbitrary number of multicast groups. */ if (multicast_group > 32 @@ -160,7 +166,6 @@ nl_sock_create(int protocol, int multicast_group, multicast_group, strerror(errno)); goto error_free_pid; } -#endif *sockp = sock; return 0;