datapath: Rename last_action() as nla_is_last() and move to netlink.h
[cascardo/ovs.git] / datapath / linux / compat / 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_GET_BE16
8 /**
9  * nla_get_be16 - return payload of __be16 attribute
10  * @nla: __be16 netlink attribute
11  */
12 static inline __be16 nla_get_be16(const struct nlattr *nla)
13 {
14         return *(__be16 *) nla_data(nla);
15 }
16 #endif  /* !HAVE_NLA_GET_BE16 */
17
18 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34)
19 /* This function was introduced in 2.6.31, but initially it performed an
20  * unaligned access, so we replace it up to 2.6.34 where it was fixed.  */
21 #define nla_get_be64 rpl_nla_get_be64
22 static inline __be64 nla_get_be64(const struct nlattr *nla)
23 {
24         __be64 tmp;
25
26         /* The additional cast is necessary because  */
27         nla_memcpy(&tmp, (struct nlattr *) nla, sizeof(tmp));
28
29         return tmp;
30 }
31 #endif
32
33 #ifndef HAVE_NLA_PUT_BE16
34 static inline int nla_put_be16(struct sk_buff *skb, int attrtype, __be16 value)
35 {
36         return nla_put(skb, attrtype, sizeof(__be16), &value);
37 }
38 #endif
39
40 #ifndef HAVE_NLA_PUT_BE32
41 static inline int nla_put_be32(struct sk_buff *skb, int attrtype, __be32 value)
42 {
43         return nla_put(skb, attrtype, sizeof(__be32), &value);
44 }
45 #endif
46
47 #ifndef HAVE_NLA_PUT_BE64
48 static inline int nla_put_be64(struct sk_buff *skb, int attrtype, __be64 value)
49 {
50         return nla_put(skb, attrtype, sizeof(__be64), &value);
51 }
52 #endif
53
54 #ifndef nla_for_each_nested
55 #define nla_for_each_nested(pos, nla, rem) \
56         nla_for_each_attr(pos, nla_data(nla), nla_len(nla), rem)
57 #endif
58
59 #ifndef HAVE_NLA_FIND_NESTED
60 static inline struct nlattr *nla_find_nested(struct nlattr *nla, int attrtype)
61 {
62         return nla_find(nla_data(nla), nla_len(nla), attrtype);
63 }
64 #endif
65
66 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,18,0)
67 static inline bool nla_is_last(const struct nlattr *nla, int rem)
68 {
69         return nla->nla_len == rem;
70 }
71 #endif
72
73 #endif /* net/netlink.h */