ovsdb: Synchronize comments and code in ovsdb_file_commit().
[sliver-openvswitch.git] / datapath / linux-2.6 / compat-2.6 / include / net / netlink.h
index 1f588fe..10558b0 100644 (file)
@@ -4,30 +4,30 @@
 #include <linux/version.h>
 #include_next <net/netlink.h>
 
-#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 */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
+/* Before v2.6.29, a NLA_NESTED attribute, if it was present, was not allowed
+ * to be empty.  However, OVS depends on the ability to accept empty
+ * attributes.  For example, a present but empty ODP_FLOW_ATTR_ACTIONS on
+ * ODP_FLOW_CMD_SET replaces the existing set of actions by an empty "drop"
+ * action, whereas a missing ODP_FLOW_ATTR_ACTIONS leaves the existing
+ * actions, if any, unchanged.
+ *
+ * NLA_NESTED is different from NLA_UNSPEC in only two ways:
+ *
+ * - If the size of the nested attributes is zero, no further size checks
+ *   are performed.
+ *
+ * - If the size of the nested attributes is not zero and no length
+ *   parameter is specified the minimum size of nested attributes is
+ *   NLA_HDRLEN.
+ *
+ * nla_parse_nested() validates that there is at least enough space for
+ * NLA_HDRLEN, so neither of these conditions are important, and we might
+ * as well use NLA_UNSPEC with old kernels.
+ */
+#undef NLA_NESTED
+#define NLA_NESTED NLA_UNSPEC
+#endif
 
 #ifndef NLA_PUT_BE16
 #define NLA_PUT_BE16(skb, attrtype, value) \
@@ -111,41 +111,62 @@ static inline int nla_type(const struct nlattr *nla)
 }
 #endif
 
-/* The following nla_put_be{16,32,64} functions are not in any version of Linux
- * (although NLA_PUT_BE{16,32,64} are), so we will probably want to add them
- * as part of the patch series when we submit Open vSwitch upstream. */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
+#define nla_parse_nested(tb, maxtype, nla, policy) \
+       nla_parse_nested(tb, maxtype, (struct nlattr *)(nla), (struct nla_policy *)(policy))
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
+#define nla_parse_nested(tb, maxtype, nla, policy) \
+       nla_parse_nested(tb, maxtype, (struct nlattr *)(nla), policy)
+#endif
 
-/**
- * nla_put_be16 - Add a be16 netlink attribute to a socket buffer
- * @skb: socket buffer to add attribute to
- * @attrtype: attribute type
- * @value: numeric value
- */
-static inline int nla_put_be16(struct sk_buff *skb, int attrtype, __be16 value)
+#ifndef nla_for_each_nested
+#define nla_for_each_nested(pos, nla, rem) \
+       nla_for_each_attr(pos, nla_data(nla), nla_len(nla), rem)
+#endif
+
+#ifndef HAVE_NLA_FIND_NESTED
+static inline struct nlattr *nla_find_nested(struct nlattr *nla, int attrtype)
 {
-       return nla_put(skb, attrtype, sizeof(__be16), &value);
+       return nla_find(nla_data(nla), nla_len(nla), attrtype);
 }
+#endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
 /**
- * nla_put_be32 - Add a be32 netlink attribute to a socket buffer
- * @skb: socket buffer to add attribute to
- * @attrtype: attribute type
- * @value: numeric value
+ * nlmsg_report - need to report back to application?
+ * @nlh: netlink message header
+ *
+ * Returns 1 if a report back to the application is requested.
  */
-static inline int nla_put_be32(struct sk_buff *skb, int attrtype, __be32 value)
+static inline int nlmsg_report(const struct nlmsghdr *nlh)
 {
-       return nla_put(skb, attrtype, sizeof(__be32), &value);
+       return !!(nlh->nlmsg_flags & NLM_F_ECHO);
 }
 
-/**
- * nla_put_64 - Add a be64 netlink attribute to a socket buffer
- * @skb: socket buffer to add attribute to
- * @attrtype: attribute type
- * @value: numeric value
- */
-static inline int nla_put_be64(struct sk_buff *skb, int attrtype, __be64 value)
+extern int             nlmsg_notify(struct sock *sk, struct sk_buff *skb,
+                                    u32 pid, unsigned int group, int report,
+                                    gfp_t flags);
+#endif /* linux kernel < 2.6.19 */
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
+/* Before 2.6.19 the 'flags' parameter was missing, so replace it.  We have to
+ * #include <net/genetlink.h> first because the 2.6.18 version of that header
+ * has an inline call to nlmsg_multicast() without, of course, any 'flags'
+ * argument. */
+#define nlmsg_multicast rpl_nlmsg_multicast
+static inline int nlmsg_multicast(struct sock *sk, struct sk_buff *skb,
+                                 u32 pid, unsigned int group, gfp_t flags)
 {
-       return nla_put(skb, attrtype, sizeof(__be64), &value);
+       int err;
+
+       NETLINK_CB(skb).dst_group = group;
+
+       err = netlink_broadcast(sk, skb, pid, group, flags);
+       if (err > 0)
+               err = 0;
+
+       return err;
 }
+#endif /* linux kernel < 2.6.19 */
 
 #endif /* net/netlink.h */