1 #ifndef __NET_NETLINK_H
2 #define __NET_NETLINK_H
4 #include <linux/types.h>
5 #include <linux/netlink.h>
178 #define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1)
236 int len,
int maxtype,
243 int len,
int attrtype);
257 int attrlen,
const void *
data);
261 int attrlen,
const void *
data);
275 static inline int nlmsg_msg_size(
int payload)
284 static inline int nlmsg_total_size(
int payload)
293 static inline int nlmsg_padlen(
int payload)
295 return nlmsg_total_size(payload) - nlmsg_msg_size(payload);
302 static inline void *nlmsg_data(
const struct nlmsghdr *nlh)
311 static inline int nlmsg_len(
const struct nlmsghdr *nlh)
321 static inline struct nlattr *nlmsg_attrdata(
const struct nlmsghdr *nlh,
324 unsigned char *
data = nlmsg_data(nlh);
333 static inline int nlmsg_attrlen(
const struct nlmsghdr *nlh,
int hdrlen)
343 static inline int nlmsg_ok(
const struct nlmsghdr *nlh,
int remaining)
345 return (remaining >= (
int)
sizeof(
struct nlmsghdr) &&
359 nlmsg_next(
const struct nlmsghdr *nlh,
int *remaining)
365 return (
struct nlmsghdr *) ((
unsigned char *) nlh + totlen);
378 static inline int nlmsg_parse(
const struct nlmsghdr *nlh,
int hdrlen,
382 if (nlh->
nlmsg_len < nlmsg_msg_size(hdrlen))
385 return nla_parse(tb, maxtype, nlmsg_attrdata(nlh, hdrlen),
386 nlmsg_attrlen(nlh, hdrlen), policy);
397 static inline struct nlattr *nlmsg_find_attr(
const struct nlmsghdr *nlh,
398 int hdrlen,
int attrtype)
400 return nla_find(nlmsg_attrdata(nlh, hdrlen),
401 nlmsg_attrlen(nlh, hdrlen), attrtype);
411 static inline int nlmsg_validate(
const struct nlmsghdr *nlh,
412 int hdrlen,
int maxtype,
415 if (nlh->
nlmsg_len < nlmsg_msg_size(hdrlen))
419 nlmsg_attrlen(nlh, hdrlen), maxtype, policy);
428 static inline int nlmsg_report(
const struct nlmsghdr *nlh)
440 #define nlmsg_for_each_attr(pos, nlh, hdrlen, rem) \
441 nla_for_each_attr(pos, nlmsg_attrdata(nlh, hdrlen), \
442 nlmsg_attrlen(nlh, hdrlen), rem)
459 if (
unlikely(skb_tailroom(skb) < nlmsg_total_size(payload)))
462 return __nlmsg_put(skb, portid, seq, type, payload, flags);
478 int type,
int payload,
482 type, payload, flags);
493 static inline struct sk_buff *nlmsg_new(
size_t payload,
gfp_t flags)
495 return alloc_skb(nlmsg_total_size(payload), flags);
511 nlh->
nlmsg_len = skb_tail_pointer(skb) - (
unsigned char *)nlh;
522 static inline void *nlmsg_get_pos(
struct sk_buff *skb)
524 return skb_tail_pointer(skb);
534 static inline void nlmsg_trim(
struct sk_buff *skb,
const void *
mark)
548 static inline void nlmsg_cancel(
struct sk_buff *skb,
struct nlmsghdr *nlh)
550 nlmsg_trim(skb, nlh);
557 static inline void nlmsg_free(
struct sk_buff *skb)
570 static inline int nlmsg_multicast(
struct sock *
sk,
struct sk_buff *skb,
590 static inline int nlmsg_unicast(
struct sock *sk,
struct sk_buff *skb,
u32 portid)
608 #define nlmsg_for_each_msg(pos, head, len, rem) \
609 for (pos = head, rem = len; \
610 nlmsg_ok(pos, rem); \
611 pos = nlmsg_next(pos, &(rem)))
645 static inline int nla_attr_size(
int payload)
654 static inline int nla_total_size(
int payload)
656 return NLA_ALIGN(nla_attr_size(payload));
663 static inline int nla_padlen(
int payload)
665 return nla_total_size(payload) - nla_attr_size(payload);
672 static inline int nla_type(
const struct nlattr *
nla)
681 static inline void *nla_data(
const struct nlattr *
nla)
690 static inline int nla_len(
const struct nlattr *nla)
700 static inline int nla_ok(
const struct nlattr *nla,
int remaining)
702 return remaining >= (
int)
sizeof(*nla) &&
703 nla->
nla_len >=
sizeof(*nla) &&
715 static inline struct nlattr *nla_next(
const struct nlattr *nla,
int *remaining)
720 return (
struct nlattr *) ((
char *) nla + totlen);
730 static inline struct nlattr *
731 nla_find_nested(
const struct nlattr *nla,
int attrtype)
745 static inline int nla_parse_nested(
struct nlattr *tb[],
int maxtype,
758 static inline int nla_put_u8(
struct sk_buff *skb,
int attrtype,
u8 value)
760 return nla_put(skb, attrtype,
sizeof(
u8), &value);
769 static inline int nla_put_u16(
struct sk_buff *skb,
int attrtype,
u16 value)
771 return nla_put(skb, attrtype,
sizeof(
u16), &value);
780 static inline int nla_put_be16(
struct sk_buff *skb,
int attrtype,
__be16 value)
791 static inline int nla_put_net16(
struct sk_buff *skb,
int attrtype,
__be16 value)
802 static inline int nla_put_le16(
struct sk_buff *skb,
int attrtype,
__le16 value)
813 static inline int nla_put_u32(
struct sk_buff *skb,
int attrtype,
u32 value)
815 return nla_put(skb, attrtype,
sizeof(
u32), &value);
824 static inline int nla_put_be32(
struct sk_buff *skb,
int attrtype,
__be32 value)
835 static inline int nla_put_net32(
struct sk_buff *skb,
int attrtype,
__be32 value)
846 static inline int nla_put_le32(
struct sk_buff *skb,
int attrtype,
__le32 value)
857 static inline int nla_put_u64(
struct sk_buff *skb,
int attrtype,
u64 value)
859 return nla_put(skb, attrtype,
sizeof(
u64), &value);
868 static inline int nla_put_be64(
struct sk_buff *skb,
int attrtype,
__be64 value)
879 static inline int nla_put_net64(
struct sk_buff *skb,
int attrtype,
__be64 value)
890 static inline int nla_put_le64(
struct sk_buff *skb,
int attrtype,
__le64 value)
901 static inline int nla_put_s8(
struct sk_buff *skb,
int attrtype,
s8 value)
903 return nla_put(skb, attrtype,
sizeof(
s8), &value);
912 static inline int nla_put_s16(
struct sk_buff *skb,
int attrtype,
s16 value)
914 return nla_put(skb, attrtype,
sizeof(
s16), &value);
923 static inline int nla_put_s32(
struct sk_buff *skb,
int attrtype,
s32 value)
925 return nla_put(skb, attrtype,
sizeof(
s32), &value);
934 static inline int nla_put_s64(
struct sk_buff *skb,
int attrtype,
s64 value)
936 return nla_put(skb, attrtype,
sizeof(
s64), &value);
945 static inline int nla_put_string(
struct sk_buff *skb,
int attrtype,
956 static inline int nla_put_flag(
struct sk_buff *skb,
int attrtype)
967 static inline int nla_put_msecs(
struct sk_buff *skb,
int attrtype,
968 unsigned long jiffies)
971 return nla_put(skb, attrtype,
sizeof(
u64), &tmp);
978 static inline u32 nla_get_u32(
const struct nlattr *nla)
980 return *(
u32 *) nla_data(nla);
987 static inline __be32 nla_get_be32(
const struct nlattr *nla)
989 return *(
__be32 *) nla_data(nla);
996 static inline u16 nla_get_u16(
const struct nlattr *nla)
998 return *(
u16 *) nla_data(nla);
1005 static inline __be16 nla_get_be16(
const struct nlattr *nla)
1007 return *(
__be16 *) nla_data(nla);
1014 static inline __le16 nla_get_le16(
const struct nlattr *nla)
1016 return *(
__le16 *) nla_data(nla);
1023 static inline u8 nla_get_u8(
const struct nlattr *nla)
1025 return *(
u8 *) nla_data(nla);
1032 static inline u64 nla_get_u64(
const struct nlattr *nla)
1045 static inline __be64 nla_get_be64(
const struct nlattr *nla)
1058 static inline s32 nla_get_s32(
const struct nlattr *nla)
1060 return *(
s32 *) nla_data(nla);
1067 static inline s16 nla_get_s16(
const struct nlattr *nla)
1069 return *(
s16 *) nla_data(nla);
1076 static inline s8 nla_get_s8(
const struct nlattr *nla)
1078 return *(
s8 *) nla_data(nla);
1085 static inline s64 nla_get_s64(
const struct nlattr *nla)
1098 static inline int nla_get_flag(
const struct nlattr *nla)
1109 static inline unsigned long nla_get_msecs(
const struct nlattr *nla)
1111 u64 msecs = nla_get_u64(nla);
1123 static inline struct nlattr *nla_nest_start(
struct sk_buff *skb,
int attrtype)
1143 static inline int nla_nest_end(
struct sk_buff *skb,
struct nlattr *start)
1145 start->
nla_len = skb_tail_pointer(skb) - (
unsigned char *)start;
1157 static inline void nla_nest_cancel(
struct sk_buff *skb,
struct nlattr *start)
1159 nlmsg_trim(skb, start);
1174 static inline int nla_validate_nested(
const struct nlattr *start,
int maxtype,
1187 #define nla_for_each_attr(pos, head, len, rem) \
1188 for (pos = head, rem = len; \
1190 pos = nla_next(pos, &(rem)))
1198 #define nla_for_each_nested(pos, nla, rem) \
1199 nla_for_each_attr(pos, nla_data(nla), nla_len(nla), rem)