datapath: Use compat directory only for backported code.
authorJesse Gross <jesse@nicira.com>
Fri, 11 Mar 2011 22:58:18 +0000 (14:58 -0800)
committerJesse Gross <jesse@nicira.com>
Mon, 14 Mar 2011 16:53:23 +0000 (09:53 -0700)
Most necessary compatibility code is simply backported versions
of kernel functions from newer kernels.  These belong in the compat
directory, where they can be transparently picked up when necessary.
However, in some situations there is code that is different
depending on the kernel version but is always needed in some form.
Here it is desirable to segregate the code but it does not really
belong in the compat directory because it does not exist in upstream
kernels.  This moves those functions to a compat file, which makes
the meaning clear and prevents problems when Open vSwitch is integrated
into other projects.

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

index dbeec8f..587569f 100644 (file)
@@ -32,6 +32,7 @@ openvswitch_sources = \
 openvswitch_headers = \
        actions.h \
        checksum.h \
+       compat.h \
        datapath.h \
        dp_sysfs.h \
        flow.h \
diff --git a/datapath/compat.h b/datapath/compat.h
new file mode 100644 (file)
index 0000000..c484a5d
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2011 Nicira Networks.
+ * Distributed under the terms of the GNU GPL version 2.
+ *
+ * Significant portions of this file may be copied from parts of the Linux
+ * kernel, by Linus Torvalds and others.
+ */
+
+#ifndef COMPAT_H
+#define COMPAT_H 1
+
+#include <linux/netlink.h>
+
+#ifndef HAVE_NLA_NUL_STRING
+static inline int CHECK_NUL_STRING(struct nlattr *attr, int maxlen)
+{
+       char *s;
+       int len;
+       if (!attr)
+               return 0;
+
+       len = nla_len(attr);
+       if (len >= maxlen)
+               return -EINVAL;
+
+       s = nla_data(attr);
+       if (s[len - 1] != '\0')
+               return -EINVAL;
+
+       return 0;
+}
+#else
+static inline int CHECK_NUL_STRING(struct nlattr *attr, int maxlen)
+{
+       return 0;
+}
+#endif  /* !HAVE_NLA_NUL_STRING */
+
+#endif /* compat.h */
index b25b899..8a55001 100644 (file)
@@ -1304,7 +1304,7 @@ static int odp_dp_cmd_validate(struct nlattr *a[ODP_DP_ATTR_MAX + 1])
                        return -EINVAL;
        }
 
-       return VERIFY_NUL_STRING(a[ODP_DP_ATTR_NAME], IFNAMSIZ - 1);
+       return CHECK_NUL_STRING(a[ODP_DP_ATTR_NAME], IFNAMSIZ - 1);
 }
 
 /* Called with genl_mutex and optionally with RTNL lock also. */
@@ -1674,7 +1674,7 @@ static struct sk_buff *odp_vport_cmd_build_info(struct vport *vport, u32 pid,
 
 static int odp_vport_cmd_validate(struct nlattr *a[ODP_VPORT_ATTR_MAX + 1])
 {
-       return VERIFY_NUL_STRING(a[ODP_VPORT_ATTR_NAME], IFNAMSIZ - 1);
+       return CHECK_NUL_STRING(a[ODP_VPORT_ATTR_NAME], IFNAMSIZ - 1);
 }
 
 /* Called with RTNL lock or RCU read lock. */
index a779510..a064906 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/version.h>
 
 #include "checksum.h"
+#include "compat.h"
 #include "flow.h"
 #include "dp_sysfs.h"
 #include "vlan.h"
index aa7c09c..10558b0 100644 (file)
 #define NLA_NESTED NLA_UNSPEC
 #endif
 
-#ifndef HAVE_NLA_NUL_STRING
-static inline int VERIFY_NUL_STRING(struct nlattr *attr, int maxlen)
-{
-       char *s;
-       int len;
-       if (!attr)
-               return 0;
-
-       len = nla_len(attr);
-       if (len >= maxlen)
-               return -EINVAL;
-
-       s = nla_data(attr);
-       if (s[len - 1] != '\0')
-               return -EINVAL;
-
-       return 0;
-}
-#else
-static inline int VERIFY_NUL_STRING(struct nlattr *attr, int maxlen)
-{
-       return 0;
-}
-#endif /* !HAVE_NLA_NUL_STRING */
-
 #ifndef NLA_PUT_BE16
 #define NLA_PUT_BE16(skb, attrtype, value) \
         NLA_PUT_TYPE(skb, __be16, attrtype, value)
index 1c4d2c5..7cb221e 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/list.h>
 #include <linux/rtnetlink.h>
 
+#include "compat.h"
 #include "datapath.h"
 #include "vport.h"
 #include "vport-generic.h"
@@ -105,7 +106,8 @@ static int patch_set_config(struct vport *vport, const struct nlattr *options,
        if (err)
                return err;
 
-       if (!a[ODP_PATCH_ATTR_PEER] || VERIFY_NUL_STRING(a[ODP_PATCH_ATTR_PEER], IFNAMSIZ - 1))
+       if (!a[ODP_PATCH_ATTR_PEER] ||
+           CHECK_NUL_STRING(a[ODP_PATCH_ATTR_PEER], IFNAMSIZ - 1))
                return -EINVAL;
 
        peer_name = nla_data(a[ODP_PATCH_ATTR_PEER]);