a23deee1251b80906f64188979e46b2590d94b7b
[sliver-openvswitch.git] / datapath / linux-2.6 / compat-2.6 / include / net / netlink.h
1 #ifndef __NET_NETLINK_WRAPPER_H
2 #define __NET_NETLINK_WRAPPER_H 1
3
4 #include <linux/version.h>
5 #include_next <net/netlink.h>
6
7 #ifndef HAVE_NLA_NUL_STRING
8 #define NLA_NUL_STRING NLA_STRING
9
10 static inline int VERIFY_NUL_STRING(struct nlattr *attr)
11 {
12         return (!attr || (nla_len(attr)
13                           && memchr(nla_data(attr), '\0', nla_len(attr)))
14                 ? 0 : -EINVAL);
15 }
16 #else
17 static inline int VERIFY_NUL_STRING(struct nlattr *attr)
18 {
19         return 0;
20 }
21 #endif  /* !HAVE_NLA_NUL_STRING */
22
23 #ifndef NLA_PUT_BE16
24 #define NLA_PUT_BE16(skb, attrtype, value) \
25         NLA_PUT_TYPE(skb, __be16, attrtype, value)
26 #endif  /* !NLA_PUT_BE16 */
27
28 #ifndef HAVE_NLA_GET_BE16
29 /**
30  * nla_get_be16 - return payload of __be16 attribute
31  * @nla: __be16 netlink attribute
32  */
33 static inline __be16 nla_get_be16(const struct nlattr *nla)
34 {
35         return *(__be16 *) nla_data(nla);
36 }
37 #endif  /* !HAVE_NLA_GET_BE16 */
38
39 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
40 /**
41  * nla_get_be32 - return payload of __be32 attribute
42  * @nla: __be32 netlink attribute
43  */
44 static inline __be32 nla_get_be32(const struct nlattr *nla)
45 {
46         return *(__be32 *) nla_data(nla);
47 }
48 #endif
49
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)
67 #endif
68
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)
74 {
75         __be64 tmp;
76
77         /* The additional cast is necessary because  */
78         nla_memcpy(&tmp, (struct nlattr *) nla, sizeof(tmp));
79
80         return tmp;
81 }
82 #endif
83
84 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
85 /**
86  * nla_type - attribute type
87  * @nla: netlink attribute
88  */
89 static inline int nla_type(const struct nlattr *nla)
90 {
91         return nla->nla_type & NLA_TYPE_MASK;
92 }
93 #endif
94
95 #endif /* net/netlink.h */