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>
openvswitch_headers = \
actions.h \
checksum.h \
openvswitch_headers = \
actions.h \
checksum.h \
datapath.h \
dp_sysfs.h \
flow.h \
datapath.h \
dp_sysfs.h \
flow.h \
--- /dev/null
+/*
+ * 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 */
- 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. */
}
/* Called with genl_mutex and optionally with RTNL lock also. */
static int odp_vport_cmd_validate(struct nlattr *a[ODP_VPORT_ATTR_MAX + 1])
{
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. */
}
/* Called with RTNL lock or RCU read lock. */
#include <linux/version.h>
#include "checksum.h"
#include <linux/version.h>
#include "checksum.h"
#include "flow.h"
#include "dp_sysfs.h"
#include "vlan.h"
#include "flow.h"
#include "dp_sysfs.h"
#include "vlan.h"
#define NLA_NESTED NLA_UNSPEC
#endif
#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)
#ifndef NLA_PUT_BE16
#define NLA_PUT_BE16(skb, attrtype, value) \
NLA_PUT_TYPE(skb, __be16, attrtype, value)
#include <linux/list.h>
#include <linux/rtnetlink.h>
#include <linux/list.h>
#include <linux/rtnetlink.h>
#include "datapath.h"
#include "vport.h"
#include "vport-generic.h"
#include "datapath.h"
#include "vport.h"
#include "vport-generic.h"
- 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]);
return -EINVAL;
peer_name = nla_data(a[ODP_PATCH_ATTR_PEER]);