📄 netlink.h
字号:
* See nla_parse() */static inline int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, const struct nla_policy *policy){ return nla_parse(tb, maxtype, nla_data(nla), nla_len(nla), policy);}/** * nla_parse_nested_compat - parse nested compat attributes * @tb: destination array with maxtype+1 elements * @maxtype: maximum attribute type to be expected * @nla: attribute containing the nested attributes * @data: pointer to point to contained structure * @len: length of contained structure * @policy: validation policy * * Parse a nested compat attribute. The compat attribute contains a structure * and optionally a set of nested attributes. On success the data pointer * points to the nested data and tb contains the parsed attributes * (see nla_parse). */static inline int __nla_parse_nested_compat(struct nlattr *tb[], int maxtype, struct nlattr *nla, const struct nla_policy *policy, int len){ if (nla_len(nla) < len) return -1; if (nla_len(nla) >= NLA_ALIGN(len) + sizeof(struct nlattr)) return nla_parse_nested(tb, maxtype, nla_data(nla) + NLA_ALIGN(len), policy); memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1)); return 0;}#define nla_parse_nested_compat(tb, maxtype, nla, policy, data, len) \({ data = nla_len(nla) >= len ? nla_data(nla) : NULL; \ __nla_parse_nested_compat(tb, maxtype, nla, policy, len); })/** * nla_put_u8 - Add a u8 netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type * @value: numeric value */static inline int nla_put_u8(struct sk_buff *skb, int attrtype, u8 value){ return nla_put(skb, attrtype, sizeof(u8), &value);}/** * nla_put_u16 - Add a u16 netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type * @value: numeric value */static inline int nla_put_u16(struct sk_buff *skb, int attrtype, u16 value){ return nla_put(skb, attrtype, sizeof(u16), &value);}/** * nla_put_u32 - Add a u32 netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type * @value: numeric value */static inline int nla_put_u32(struct sk_buff *skb, int attrtype, u32 value){ return nla_put(skb, attrtype, sizeof(u32), &value);}/** * nla_put_64 - Add a u64 netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type * @value: numeric value */static inline int nla_put_u64(struct sk_buff *skb, int attrtype, u64 value){ return nla_put(skb, attrtype, sizeof(u64), &value);}/** * nla_put_string - Add a string netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type * @str: NUL terminated string */static inline int nla_put_string(struct sk_buff *skb, int attrtype, const char *str){ return nla_put(skb, attrtype, strlen(str) + 1, str);}/** * nla_put_flag - Add a flag netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type */static inline int nla_put_flag(struct sk_buff *skb, int attrtype){ return nla_put(skb, attrtype, 0, NULL);}/** * nla_put_msecs - Add a msecs netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type * @jiffies: number of msecs in jiffies */static inline int nla_put_msecs(struct sk_buff *skb, int attrtype, unsigned long jiffies){ u64 tmp = jiffies_to_msecs(jiffies); return nla_put(skb, attrtype, sizeof(u64), &tmp);}#define NLA_PUT(skb, attrtype, attrlen, data) \ do { \ if (nla_put(skb, attrtype, attrlen, data) < 0) \ goto nla_put_failure; \ } while(0)#define NLA_PUT_TYPE(skb, type, attrtype, value) \ do { \ type __tmp = value; \ NLA_PUT(skb, attrtype, sizeof(type), &__tmp); \ } while(0)#define NLA_PUT_U8(skb, attrtype, value) \ NLA_PUT_TYPE(skb, u8, attrtype, value)#define NLA_PUT_U16(skb, attrtype, value) \ NLA_PUT_TYPE(skb, u16, attrtype, value)#define NLA_PUT_LE16(skb, attrtype, value) \ NLA_PUT_TYPE(skb, __le16, attrtype, value)#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)#define NLA_PUT_STRING(skb, attrtype, value) \ NLA_PUT(skb, attrtype, strlen(value) + 1, value)#define NLA_PUT_FLAG(skb, attrtype) \ NLA_PUT(skb, attrtype, 0, NULL)#define NLA_PUT_MSECS(skb, attrtype, jiffies) \ NLA_PUT_U64(skb, attrtype, jiffies_to_msecs(jiffies))/** * nla_get_u32 - return payload of u32 attribute * @nla: u32 netlink attribute */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 */static inline u16 nla_get_u16(struct nlattr *nla){ return *(u16 *) nla_data(nla);}/** * nla_get_le16 - return payload of __le16 attribute * @nla: __le16 netlink attribute */static inline __le16 nla_get_le16(struct nlattr *nla){ return *(__le16 *) nla_data(nla);}/** * nla_get_u8 - return payload of u8 attribute * @nla: u8 netlink attribute */static inline u8 nla_get_u8(struct nlattr *nla){ return *(u8 *) nla_data(nla);}/** * nla_get_u64 - return payload of u64 attribute * @nla: u64 netlink attribute */static inline u64 nla_get_u64(struct nlattr *nla){ u64 tmp; nla_memcpy(&tmp, nla, sizeof(tmp)); return tmp;}/** * nla_get_flag - return payload of flag attribute * @nla: flag netlink attribute */static inline int nla_get_flag(struct nlattr *nla){ return !!nla;}/** * nla_get_msecs - return payload of msecs attribute * @nla: msecs netlink attribute * * Returns the number of milliseconds in jiffies. */static inline unsigned long nla_get_msecs(struct nlattr *nla){ u64 msecs = nla_get_u64(nla); return msecs_to_jiffies((unsigned long) msecs);}/** * nla_nest_start - Start a new level of nested attributes * @skb: socket buffer to add attributes to * @attrtype: attribute type of container * * Returns the container attribute */static inline struct nlattr *nla_nest_start(struct sk_buff *skb, int attrtype){ struct nlattr *start = (struct nlattr *)skb_tail_pointer(skb); if (nla_put(skb, attrtype, 0, NULL) < 0) return NULL; return start;}/** * nla_nest_end - Finalize nesting of attributes * @skb: socket buffer the attributes are stored in * @start: container attribute * * Corrects the container attribute header to include the all * appeneded attributes. * * Returns the total data length of the skb. */static inline int nla_nest_end(struct sk_buff *skb, struct nlattr *start){ start->nla_len = skb_tail_pointer(skb) - (unsigned char *)start; return skb->len;}/** * nla_nest_compat_start - Start a new level of nested compat attributes * @skb: socket buffer to add attributes to * @attrtype: attribute type of container * @attrlen: length of structure * @data: pointer to structure * * Start a nested compat attribute that contains both a structure and * a set of nested attributes. * * Returns the container attribute */static inline struct nlattr *nla_nest_compat_start(struct sk_buff *skb, int attrtype, int attrlen, const void *data){ struct nlattr *start = (struct nlattr *)skb_tail_pointer(skb); if (nla_put(skb, attrtype, attrlen, data) < 0) return NULL; if (nla_nest_start(skb, attrtype) == NULL) { nlmsg_trim(skb, start); return NULL; } return start;}/** * nla_nest_compat_end - Finalize nesting of compat attributes * @skb: socket buffer the attributes are stored in * @start: container attribute * * Corrects the container attribute header to include the all * appeneded attributes. * * Returns the total data length of the skb. */static inline int nla_nest_compat_end(struct sk_buff *skb, struct nlattr *start){ struct nlattr *nest = (void *)start + NLMSG_ALIGN(start->nla_len); start->nla_len = skb_tail_pointer(skb) - (unsigned char *)start; return nla_nest_end(skb, nest);}/** * nla_nest_cancel - Cancel nesting of attributes * @skb: socket buffer the message is stored in * @start: container attribute * * Removes the container attribute and including all nested * attributes. Returns -1. */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, const 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 * @head: head of attribute stream * @len: length of attribute stream * @rem: initialized to len, holds bytes currently remaining in stream */#define nla_for_each_attr(pos, head, len, rem) \ for (pos = head, rem = len; \ nla_ok(pos, rem); \ pos = nla_next(pos, &(rem)))/** * nla_for_each_nested - iterate over nested attributes * @pos: loop counter, set to current attribute * @nla: attribute containing the nested attributes * @rem: initialized to len, holds bytes currently remaining in stream */#define nla_for_each_nested(pos, nla, rem) \ nla_for_each_attr(pos, nla_data(nla), nla_len(nla), rem)#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -