[ovs-dev] [tunid64 v3 3/8] netlink: New function nl_attr_type().

Ben Pfaff blp at nicira.com
Thu Dec 9 22:48:27 UTC 2010


Linux since v2.6.24 has a couple of couple of bits at the top of
nla_type that one is apparently supposed to ignore.  This commit
starts doing that in Open vSwitch userspace.

Acked-by: Jesse Gross <jesse at nicira.com>
---
 lib/netlink-protocol.h |    7 +++++++
 lib/netlink.c          |   12 ++++++++++--
 lib/netlink.h          |    1 +
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/lib/netlink-protocol.h b/lib/netlink-protocol.h
index 77f5c89..6281fb2 100644
--- a/lib/netlink-protocol.h
+++ b/lib/netlink-protocol.h
@@ -150,4 +150,11 @@ enum {
 #define CTRL_ATTR_OP_MAX (__CTRL_ATTR_OP_MAX - 1)
 #endif  /* !HAVE_NETLINK */
 
+/* These were introduced all together in 2.6.24. */
+#ifndef NLA_TYPE_MASK
+#define NLA_F_NESTED		(1 << 15)
+#define NLA_F_NET_BYTEORDER	(1 << 14)
+#define NLA_TYPE_MASK		~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
+#endif
+
 #endif /* netlink-protocol.h */
diff --git a/lib/netlink.c b/lib/netlink.c
index 405f493..e25dcb7 100644
--- a/lib/netlink.c
+++ b/lib/netlink.c
@@ -919,6 +919,14 @@ nl_msg_next(struct ofpbuf *buffer, struct ofpbuf *msg)
 
 /* Attributes. */
 
+/* Returns the bits of 'nla->nla_type' that are significant for determining its
+ * type. */
+int
+nl_attr_type(const struct nlattr *nla)
+{
+    return nla->nla_type & NLA_TYPE_MASK;
+}
+
 /* Returns the first byte in the payload of attribute 'nla'. */
 const void *
 nl_attr_get(const struct nlattr *nla)
@@ -1100,12 +1108,12 @@ nl_policy_parse(const struct ofpbuf *msg, size_t nla_offset,
         if (aligned_len > (char*)tail - (char*)p) {
             VLOG_DBG_RL(&rl, "%zu: attr %"PRIu16" aligned data len (%zu) "
                         "> bytes left (%tu)",
-                        offset, nla->nla_type, aligned_len,
+                        offset, nl_attr_type(nla), aligned_len,
                         (char*)tail - (char*)p);
             return false;
         }
 
-        type = nla->nla_type;
+        type = nl_attr_type(nla);
         if (type < n_attrs && policy[type].type != NL_A_NO_ATTR) {
             const struct nl_policy *e = &policy[type];
             size_t min_len, max_len;
diff --git a/lib/netlink.h b/lib/netlink.h
index 56e4e0e..d469c23 100644
--- a/lib/netlink.h
+++ b/lib/netlink.h
@@ -117,6 +117,7 @@ enum nl_attr_type
 };
 
 /* Netlink attribute parsing. */
+int nl_attr_type(const struct nlattr *);
 const void *nl_attr_get(const struct nlattr *);
 size_t nl_attr_get_size(const struct nlattr *);
 const void *nl_attr_get_unspec(const struct nlattr *, size_t size);
-- 
1.7.1





More information about the dev mailing list