openvswitch_headers = \
actions.h \
checksum.h \
+ compat.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 -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. */
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. */
#include <linux/version.h>
#include "checksum.h"
+#include "compat.h"
#include "flow.h"
#include "dp_sysfs.h"
#include "vlan.h"
#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)
#include <linux/list.h>
#include <linux/rtnetlink.h>
+#include "compat.h"
#include "datapath.h"
#include "vport.h"
#include "vport-generic.h"
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]);