1 #ifndef __NET_NETLINK_WRAPPER_H
2 #define __NET_NETLINK_WRAPPER_H 1
4 #include <linux/version.h>
5 #include_next <net/netlink.h>
7 #ifndef HAVE_NLA_NUL_STRING
8 #define NLA_NUL_STRING NLA_STRING
10 static inline int VERIFY_NUL_STRING(struct nlattr *attr)
12 return (!attr || (nla_len(attr)
13 && memchr(nla_data(attr), '\0', nla_len(attr)))
17 static inline int VERIFY_NUL_STRING(struct nlattr *attr)
21 #endif /* !HAVE_NLA_NUL_STRING */
24 #define NLA_PUT_BE16(skb, attrtype, value) \
25 NLA_PUT_TYPE(skb, __be16, attrtype, value)
26 #endif /* !NLA_PUT_BE16 */
28 #ifndef HAVE_NLA_GET_BE16
30 * nla_get_be16 - return payload of __be16 attribute
31 * @nla: __be16 netlink attribute
33 static inline __be16 nla_get_be16(const struct nlattr *nla)
35 return *(__be16 *) nla_data(nla);
37 #endif /* !HAVE_NLA_GET_BE16 */
39 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
41 * nla_get_be32 - return payload of __be32 attribute
42 * @nla: __be32 netlink attribute
44 static inline __be32 nla_get_be32(const struct nlattr *nla)
46 return *(__be32 *) nla_data(nla);
50 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
51 /* These functions' nlattr source arguments weren't "const" before 2.6.29, so
52 * cast their arguments to the non-"const" versions. Using macros for this
53 * isn't exactly a brilliant idea, but it seems less error-prone than copying
54 * the definitions of all umpteen functions. */
55 #define nla_get_u64(nla) (nla_get_u64) ((struct nlattr *) (nla))
56 #define nla_get_u32(nla) (nla_get_u32) ((struct nlattr *) (nla))
57 #define nla_get_u16(nla) (nla_get_u16) ((struct nlattr *) (nla))
58 #define nla_get_u8(nla) (nla_get_u8) ((struct nlattr *) (nla))
59 /* nla_get_be64 is handled separately below. */
60 #define nla_get_be32(nla) (nla_get_be32) ((struct nlattr *) (nla))
61 #define nla_get_be16(nla) (nla_get_be16) ((struct nlattr *) (nla))
62 #define nla_get_be8(nla) (nla_get_be8) ((struct nlattr *) (nla))
63 #define nla_get_flag(nla) (nla_get_flag) ((struct nlattr *) (nla))
64 #define nla_get_msecs(nla) (nla_get_msecs)((struct nlattr *) (nla))
65 #define nla_memcpy(dst, src, count) \
66 (nla_memcpy)(dst, (struct nlattr *)(src), count)
69 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34)
70 /* This function was introduced in 2.6.31, but initially it performed an
71 * unaligned access, so we replace it up to 2.6.34 where it was fixed. */
72 #define nla_get_be64 rpl_nla_get_be64
73 static inline __be64 nla_get_be64(const struct nlattr *nla)
77 /* The additional cast is necessary because */
78 nla_memcpy(&tmp, (struct nlattr *) nla, sizeof(tmp));
84 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
86 * nla_type - attribute type
87 * @nla: netlink attribute
89 static inline int nla_type(const struct nlattr *nla)
91 return nla->nla_type & NLA_TYPE_MASK;
95 #endif /* net/netlink.h */