diff options
Diffstat (limited to 'include/net/netlink.h')
-rw-r--r-- | include/net/netlink.h | 74 |
1 files changed, 64 insertions, 10 deletions
diff --git a/include/net/netlink.h b/include/net/netlink.h index 640c26a90cf1..3a5e40b1e045 100644 --- a/include/net/netlink.h +++ b/include/net/netlink.h | |||
@@ -35,6 +35,8 @@ | |||
35 | * nlmsg_put() add a netlink message to an skb | 35 | * nlmsg_put() add a netlink message to an skb |
36 | * nlmsg_put_answer() callback based nlmsg_put() | 36 | * nlmsg_put_answer() callback based nlmsg_put() |
37 | * nlmsg_end() finanlize netlink message | 37 | * nlmsg_end() finanlize netlink message |
38 | * nlmsg_get_pos() return current position in message | ||
39 | * nlmsg_trim() trim part of message | ||
38 | * nlmsg_cancel() cancel message construction | 40 | * nlmsg_cancel() cancel message construction |
39 | * nlmsg_free() free a netlink message | 41 | * nlmsg_free() free a netlink message |
40 | * | 42 | * |
@@ -80,8 +82,10 @@ | |||
80 | * struct nlattr netlink attribtue header | 82 | * struct nlattr netlink attribtue header |
81 | * | 83 | * |
82 | * Attribute Construction: | 84 | * Attribute Construction: |
83 | * nla_reserve(skb, type, len) reserve skb tailroom for an attribute | 85 | * nla_reserve(skb, type, len) reserve room for an attribute |
86 | * nla_reserve_nohdr(skb, len) reserve room for an attribute w/o hdr | ||
84 | * nla_put(skb, type, len, data) add attribute to skb | 87 | * nla_put(skb, type, len, data) add attribute to skb |
88 | * nla_put_nohdr(skb, len, data) add attribute w/o hdr | ||
85 | * | 89 | * |
86 | * Attribute Construction for Basic Types: | 90 | * Attribute Construction for Basic Types: |
87 | * nla_put_u8(skb, type, value) add u8 attribute to skb | 91 | * nla_put_u8(skb, type, value) add u8 attribute to skb |
@@ -139,6 +143,7 @@ | |||
139 | * nla_next(nla, remaining) get next netlink attribute | 143 | * nla_next(nla, remaining) get next netlink attribute |
140 | * nla_validate() validate a stream of attributes | 144 | * nla_validate() validate a stream of attributes |
141 | * nla_find() find attribute in stream of attributes | 145 | * nla_find() find attribute in stream of attributes |
146 | * nla_find_nested() find attribute in nested attributes | ||
142 | * nla_parse() parse and validate stream of attrs | 147 | * nla_parse() parse and validate stream of attrs |
143 | * nla_parse_nested() parse nested attribuets | 148 | * nla_parse_nested() parse nested attribuets |
144 | * nla_for_each_attr() loop over all attributes | 149 | * nla_for_each_attr() loop over all attributes |
@@ -203,12 +208,18 @@ extern int nla_memcmp(const struct nlattr *nla, const void *data, | |||
203 | extern int nla_strcmp(const struct nlattr *nla, const char *str); | 208 | extern int nla_strcmp(const struct nlattr *nla, const char *str); |
204 | extern struct nlattr * __nla_reserve(struct sk_buff *skb, int attrtype, | 209 | extern struct nlattr * __nla_reserve(struct sk_buff *skb, int attrtype, |
205 | int attrlen); | 210 | int attrlen); |
211 | extern void * __nla_reserve_nohdr(struct sk_buff *skb, int attrlen); | ||
206 | extern struct nlattr * nla_reserve(struct sk_buff *skb, int attrtype, | 212 | extern struct nlattr * nla_reserve(struct sk_buff *skb, int attrtype, |
207 | int attrlen); | 213 | int attrlen); |
214 | extern void * nla_reserve_nohdr(struct sk_buff *skb, int attrlen); | ||
208 | extern void __nla_put(struct sk_buff *skb, int attrtype, | 215 | extern void __nla_put(struct sk_buff *skb, int attrtype, |
209 | int attrlen, const void *data); | 216 | int attrlen, const void *data); |
217 | extern void __nla_put_nohdr(struct sk_buff *skb, int attrlen, | ||
218 | const void *data); | ||
210 | extern int nla_put(struct sk_buff *skb, int attrtype, | 219 | extern int nla_put(struct sk_buff *skb, int attrtype, |
211 | int attrlen, const void *data); | 220 | int attrlen, const void *data); |
221 | extern int nla_put_nohdr(struct sk_buff *skb, int attrlen, | ||
222 | const void *data); | ||
212 | 223 | ||
213 | /************************************************************************** | 224 | /************************************************************************** |
214 | * Netlink Messages | 225 | * Netlink Messages |
@@ -453,12 +464,13 @@ static inline struct nlmsghdr *nlmsg_put_answer(struct sk_buff *skb, | |||
453 | /** | 464 | /** |
454 | * nlmsg_new - Allocate a new netlink message | 465 | * nlmsg_new - Allocate a new netlink message |
455 | * @size: maximum size of message | 466 | * @size: maximum size of message |
467 | * @flags: the type of memory to allocate. | ||
456 | * | 468 | * |
457 | * Use NLMSG_GOODSIZE if size isn't know and you need a good default size. | 469 | * Use NLMSG_GOODSIZE if size isn't know and you need a good default size. |
458 | */ | 470 | */ |
459 | static inline struct sk_buff *nlmsg_new(int size) | 471 | static inline struct sk_buff *nlmsg_new(int size, gfp_t flags) |
460 | { | 472 | { |
461 | return alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); | 473 | return alloc_skb(size, flags); |
462 | } | 474 | } |
463 | 475 | ||
464 | /** | 476 | /** |
@@ -480,6 +492,32 @@ static inline int nlmsg_end(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
480 | } | 492 | } |
481 | 493 | ||
482 | /** | 494 | /** |
495 | * nlmsg_get_pos - return current position in netlink message | ||
496 | * @skb: socket buffer the message is stored in | ||
497 | * | ||
498 | * Returns a pointer to the current tail of the message. | ||
499 | */ | ||
500 | static inline void *nlmsg_get_pos(struct sk_buff *skb) | ||
501 | { | ||
502 | return skb->tail; | ||
503 | } | ||
504 | |||
505 | /** | ||
506 | * nlmsg_trim - Trim message to a mark | ||
507 | * @skb: socket buffer the message is stored in | ||
508 | * @mark: mark to trim to | ||
509 | * | ||
510 | * Trims the message to the provided mark. Returns -1. | ||
511 | */ | ||
512 | static inline int nlmsg_trim(struct sk_buff *skb, void *mark) | ||
513 | { | ||
514 | if (mark) | ||
515 | skb_trim(skb, (unsigned char *) mark - skb->data); | ||
516 | |||
517 | return -1; | ||
518 | } | ||
519 | |||
520 | /** | ||
483 | * nlmsg_cancel - Cancel construction of a netlink message | 521 | * nlmsg_cancel - Cancel construction of a netlink message |
484 | * @skb: socket buffer the message is stored in | 522 | * @skb: socket buffer the message is stored in |
485 | * @nlh: netlink message header | 523 | * @nlh: netlink message header |
@@ -489,9 +527,7 @@ static inline int nlmsg_end(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
489 | */ | 527 | */ |
490 | static inline int nlmsg_cancel(struct sk_buff *skb, struct nlmsghdr *nlh) | 528 | static inline int nlmsg_cancel(struct sk_buff *skb, struct nlmsghdr *nlh) |
491 | { | 529 | { |
492 | skb_trim(skb, (unsigned char *) nlh - skb->data); | 530 | return nlmsg_trim(skb, nlh); |
493 | |||
494 | return -1; | ||
495 | } | 531 | } |
496 | 532 | ||
497 | /** | 533 | /** |
@@ -631,6 +667,18 @@ static inline struct nlattr *nla_next(const struct nlattr *nla, int *remaining) | |||
631 | } | 667 | } |
632 | 668 | ||
633 | /** | 669 | /** |
670 | * nla_find_nested - find attribute in a set of nested attributes | ||
671 | * @nla: attribute containing the nested attributes | ||
672 | * @attrtype: type of attribute to look for | ||
673 | * | ||
674 | * Returns the first attribute which matches the specified type. | ||
675 | */ | ||
676 | static inline struct nlattr *nla_find_nested(struct nlattr *nla, int attrtype) | ||
677 | { | ||
678 | return nla_find(nla_data(nla), nla_len(nla), attrtype); | ||
679 | } | ||
680 | |||
681 | /** | ||
634 | * nla_parse_nested - parse nested attributes | 682 | * nla_parse_nested - parse nested attributes |
635 | * @tb: destination array with maxtype+1 elements | 683 | * @tb: destination array with maxtype+1 elements |
636 | * @maxtype: maximum attribute type to be expected | 684 | * @maxtype: maximum attribute type to be expected |
@@ -862,10 +910,7 @@ static inline int nla_nest_end(struct sk_buff *skb, struct nlattr *start) | |||
862 | */ | 910 | */ |
863 | static inline int nla_nest_cancel(struct sk_buff *skb, struct nlattr *start) | 911 | static inline int nla_nest_cancel(struct sk_buff *skb, struct nlattr *start) |
864 | { | 912 | { |
865 | if (start) | 913 | return nlmsg_trim(skb, start); |
866 | skb_trim(skb, (unsigned char *) start - skb->data); | ||
867 | |||
868 | return -1; | ||
869 | } | 914 | } |
870 | 915 | ||
871 | /** | 916 | /** |
@@ -880,4 +925,13 @@ static inline int nla_nest_cancel(struct sk_buff *skb, struct nlattr *start) | |||
880 | nla_ok(pos, rem); \ | 925 | nla_ok(pos, rem); \ |
881 | pos = nla_next(pos, &(rem))) | 926 | pos = nla_next(pos, &(rem))) |
882 | 927 | ||
928 | /** | ||
929 | * nla_for_each_nested - iterate over nested attributes | ||
930 | * @pos: loop counter, set to current attribute | ||
931 | * @nla: attribute containing the nested attributes | ||
932 | * @rem: initialized to len, holds bytes currently remaining in stream | ||
933 | */ | ||
934 | #define nla_for_each_nested(pos, nla, rem) \ | ||
935 | nla_for_each_attr(pos, nla_data(nla), nla_len(nla), rem) | ||
936 | |||
883 | #endif | 937 | #endif |