]> err.no Git - linux-2.6/blobdiff - include/net/netlink.h
V4L/DVB (4865): Fix: Slot 0 not NULL on disconnecting SN9C10x PC Camera
[linux-2.6] / include / net / netlink.h
index bcb27e3a312e42a90ddb8e0831a67886da058928..ce5cba19c393cf5206643300263e3971e50661d1 100644 (file)
  *   nla_ok(nla, remaining)            does nla fit into remaining bytes?
  *   nla_next(nla, remaining)          get next netlink attribute
  *   nla_validate()                    validate a stream of attributes
+ *   nla_validate_nested()             validate a stream of nested attributes
  *   nla_find()                                find attribute in stream of attributes
  *   nla_find_nested()                 find attribute in nested attributes
  *   nla_parse()                       parse and validate stream of attrs
  *   nla_parse_nested()                        parse nested attribuets
  *   nla_for_each_attr()               loop over all attributes
+ *   nla_for_each_nested()             loop over the nested attributes
  *=========================================================================
  */
 
@@ -167,6 +169,7 @@ enum {
        NLA_FLAG,
        NLA_MSECS,
        NLA_NESTED,
+       NLA_NUL_STRING,
        __NLA_TYPE_MAX,
 };
 
@@ -175,21 +178,27 @@ enum {
 /**
  * struct nla_policy - attribute validation policy
  * @type: Type of attribute or NLA_UNSPEC
- * @minlen: Minimal length of payload required to be available
+ * @len: Type specific length of payload
  *
  * Policies are defined as arrays of this struct, the array must be
  * accessible by attribute type up to the highest identifier to be expected.
  *
+ * Meaning of `len' field:
+ *    NLA_STRING           Maximum length of string
+ *    NLA_NUL_STRING       Maximum length of string (excluding NUL)
+ *    NLA_FLAG             Unused
+ *    All other            Exact length of attribute payload
+ *
  * Example:
  * static struct nla_policy my_policy[ATTR_MAX+1] __read_mostly = {
  *     [ATTR_FOO] = { .type = NLA_U16 },
- *     [ATTR_BAR] = { .type = NLA_STRING },
- *     [ATTR_BAZ] = { .minlen = sizeof(struct mystruct) },
+ *     [ATTR_BAR] = { .type = NLA_STRING, len = BARSIZ },
+ *     [ATTR_BAZ] = { .len = sizeof(struct mystruct) },
  * };
  */
 struct nla_policy {
        u16             type;
-       u16             minlen;
+       u16             len;
 };
 
 /**
@@ -822,6 +831,9 @@ static inline int nla_put_msecs(struct sk_buff *skb, int attrtype,
 #define NLA_PUT_U32(skb, attrtype, value) \
        NLA_PUT_TYPE(skb, u32, attrtype, value)
 
+#define NLA_PUT_BE32(skb, attrtype, value) \
+       NLA_PUT_TYPE(skb, __be32, attrtype, value)
+
 #define NLA_PUT_U64(skb, attrtype, value) \
        NLA_PUT_TYPE(skb, u64, attrtype, value)
 
@@ -843,6 +855,15 @@ static inline u32 nla_get_u32(struct nlattr *nla)
        return *(u32 *) nla_data(nla);
 }
 
+/**
+ * nla_get_be32 - return payload of __be32 attribute
+ * @nla: __be32 netlink attribute
+ */
+static inline __be32 nla_get_be32(struct nlattr *nla)
+{
+       return *(__be32 *) nla_data(nla);
+}
+
 /**
  * nla_get_u16 - return payload of u16 attribute
  * @nla: u16 netlink attribute
@@ -942,6 +963,24 @@ static inline int nla_nest_cancel(struct sk_buff *skb, struct nlattr *start)
        return nlmsg_trim(skb, start);
 }
 
+/**
+ * nla_validate_nested - Validate a stream of nested attributes
+ * @start: container attribute
+ * @maxtype: maximum attribute type to be expected
+ * @policy: validation policy
+ *
+ * Validates all attributes in the nested attribute stream against the
+ * specified policy. Attributes with a type exceeding maxtype will be
+ * ignored. See documenation of struct nla_policy for more details.
+ *
+ * Returns 0 on success or a negative error code.
+ */
+static inline int nla_validate_nested(struct nlattr *start, int maxtype,
+                                     struct nla_policy *policy)
+{
+       return nla_validate(nla_data(start), nla_len(start), maxtype, policy);
+}
+
 /**
  * nla_for_each_attr - iterate over a stream of attributes
  * @pos: loop counter, set to current attribute