aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/netlink.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/netlink.h')
-rw-r--r--include/net/netlink.h124
1 files changed, 107 insertions, 17 deletions
diff --git a/include/net/netlink.h b/include/net/netlink.h
index 640c26a90cf1..11dc2e7f679a 100644
--- a/include/net/netlink.h
+++ b/include/net/netlink.h
@@ -35,12 +35,15 @@
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 *
41 * Message Sending: 43 * Message Sending:
42 * nlmsg_multicast() multicast message to several groups 44 * nlmsg_multicast() multicast message to several groups
43 * nlmsg_unicast() unicast a message to a single socket 45 * nlmsg_unicast() unicast a message to a single socket
46 * nlmsg_notify() send notification message
44 * 47 *
45 * Message Length Calculations: 48 * Message Length Calculations:
46 * nlmsg_msg_size(payload) length of message w/o padding 49 * nlmsg_msg_size(payload) length of message w/o padding
@@ -62,6 +65,9 @@
62 * nlmsg_validate() validate netlink message incl. attrs 65 * nlmsg_validate() validate netlink message incl. attrs
63 * nlmsg_for_each_attr() loop over all attributes 66 * nlmsg_for_each_attr() loop over all attributes
64 * 67 *
68 * Misc:
69 * nlmsg_report() report back to application?
70 *
65 * ------------------------------------------------------------------------ 71 * ------------------------------------------------------------------------
66 * Attributes Interface 72 * Attributes Interface
67 * ------------------------------------------------------------------------ 73 * ------------------------------------------------------------------------
@@ -80,8 +86,10 @@
80 * struct nlattr netlink attribtue header 86 * struct nlattr netlink attribtue header
81 * 87 *
82 * Attribute Construction: 88 * Attribute Construction:
83 * nla_reserve(skb, type, len) reserve skb tailroom for an attribute 89 * nla_reserve(skb, type, len) reserve room for an attribute
90 * nla_reserve_nohdr(skb, len) reserve room for an attribute w/o hdr
84 * nla_put(skb, type, len, data) add attribute to skb 91 * nla_put(skb, type, len, data) add attribute to skb
92 * nla_put_nohdr(skb, len, data) add attribute w/o hdr
85 * 93 *
86 * Attribute Construction for Basic Types: 94 * Attribute Construction for Basic Types:
87 * nla_put_u8(skb, type, value) add u8 attribute to skb 95 * nla_put_u8(skb, type, value) add u8 attribute to skb
@@ -139,6 +147,7 @@
139 * nla_next(nla, remaining) get next netlink attribute 147 * nla_next(nla, remaining) get next netlink attribute
140 * nla_validate() validate a stream of attributes 148 * nla_validate() validate a stream of attributes
141 * nla_find() find attribute in stream of attributes 149 * nla_find() find attribute in stream of attributes
150 * nla_find_nested() find attribute in nested attributes
142 * nla_parse() parse and validate stream of attrs 151 * nla_parse() parse and validate stream of attrs
143 * nla_parse_nested() parse nested attribuets 152 * nla_parse_nested() parse nested attribuets
144 * nla_for_each_attr() loop over all attributes 153 * nla_for_each_attr() loop over all attributes
@@ -158,6 +167,7 @@ enum {
158 NLA_FLAG, 167 NLA_FLAG,
159 NLA_MSECS, 168 NLA_MSECS,
160 NLA_NESTED, 169 NLA_NESTED,
170 NLA_NUL_STRING,
161 __NLA_TYPE_MAX, 171 __NLA_TYPE_MAX,
162}; 172};
163 173
@@ -166,21 +176,37 @@ enum {
166/** 176/**
167 * struct nla_policy - attribute validation policy 177 * struct nla_policy - attribute validation policy
168 * @type: Type of attribute or NLA_UNSPEC 178 * @type: Type of attribute or NLA_UNSPEC
169 * @minlen: Minimal length of payload required to be available 179 * @len: Type specific length of payload
170 * 180 *
171 * Policies are defined as arrays of this struct, the array must be 181 * Policies are defined as arrays of this struct, the array must be
172 * accessible by attribute type up to the highest identifier to be expected. 182 * accessible by attribute type up to the highest identifier to be expected.
173 * 183 *
184 * Meaning of `len' field:
185 * NLA_STRING Maximum length of string
186 * NLA_NUL_STRING Maximum length of string (excluding NUL)
187 * NLA_FLAG Unused
188 * All other Exact length of attribute payload
189 *
174 * Example: 190 * Example:
175 * static struct nla_policy my_policy[ATTR_MAX+1] __read_mostly = { 191 * static struct nla_policy my_policy[ATTR_MAX+1] __read_mostly = {
176 * [ATTR_FOO] = { .type = NLA_U16 }, 192 * [ATTR_FOO] = { .type = NLA_U16 },
177 * [ATTR_BAR] = { .type = NLA_STRING }, 193 * [ATTR_BAR] = { .type = NLA_STRING, len = BARSIZ },
178 * [ATTR_BAZ] = { .minlen = sizeof(struct mystruct) }, 194 * [ATTR_BAZ] = { .len = sizeof(struct mystruct) },
179 * }; 195 * };
180 */ 196 */
181struct nla_policy { 197struct nla_policy {
182 u16 type; 198 u16 type;
183 u16 minlen; 199 u16 len;
200};
201
202/**
203 * struct nl_info - netlink source information
204 * @nlh: Netlink message header of original request
205 * @pid: Netlink PID of requesting application
206 */
207struct nl_info {
208 struct nlmsghdr *nlh;
209 u32 pid;
184}; 210};
185 211
186extern void netlink_run_queue(struct sock *sk, unsigned int *qlen, 212extern void netlink_run_queue(struct sock *sk, unsigned int *qlen,
@@ -188,6 +214,9 @@ extern void netlink_run_queue(struct sock *sk, unsigned int *qlen,
188 struct nlmsghdr *, int *)); 214 struct nlmsghdr *, int *));
189extern void netlink_queue_skip(struct nlmsghdr *nlh, 215extern void netlink_queue_skip(struct nlmsghdr *nlh,
190 struct sk_buff *skb); 216 struct sk_buff *skb);
217extern int nlmsg_notify(struct sock *sk, struct sk_buff *skb,
218 u32 pid, unsigned int group, int report,
219 gfp_t flags);
191 220
192extern int nla_validate(struct nlattr *head, int len, int maxtype, 221extern int nla_validate(struct nlattr *head, int len, int maxtype,
193 struct nla_policy *policy); 222 struct nla_policy *policy);
@@ -203,12 +232,18 @@ extern int nla_memcmp(const struct nlattr *nla, const void *data,
203extern int nla_strcmp(const struct nlattr *nla, const char *str); 232extern int nla_strcmp(const struct nlattr *nla, const char *str);
204extern struct nlattr * __nla_reserve(struct sk_buff *skb, int attrtype, 233extern struct nlattr * __nla_reserve(struct sk_buff *skb, int attrtype,
205 int attrlen); 234 int attrlen);
235extern void * __nla_reserve_nohdr(struct sk_buff *skb, int attrlen);
206extern struct nlattr * nla_reserve(struct sk_buff *skb, int attrtype, 236extern struct nlattr * nla_reserve(struct sk_buff *skb, int attrtype,
207 int attrlen); 237 int attrlen);
238extern void * nla_reserve_nohdr(struct sk_buff *skb, int attrlen);
208extern void __nla_put(struct sk_buff *skb, int attrtype, 239extern void __nla_put(struct sk_buff *skb, int attrtype,
209 int attrlen, const void *data); 240 int attrlen, const void *data);
241extern void __nla_put_nohdr(struct sk_buff *skb, int attrlen,
242 const void *data);
210extern int nla_put(struct sk_buff *skb, int attrtype, 243extern int nla_put(struct sk_buff *skb, int attrtype,
211 int attrlen, const void *data); 244 int attrlen, const void *data);
245extern int nla_put_nohdr(struct sk_buff *skb, int attrlen,
246 const void *data);
212 247
213/************************************************************************** 248/**************************************************************************
214 * Netlink Messages 249 * Netlink Messages
@@ -364,6 +399,17 @@ static inline int nlmsg_validate(struct nlmsghdr *nlh, int hdrlen, int maxtype,
364} 399}
365 400
366/** 401/**
402 * nlmsg_report - need to report back to application?
403 * @nlh: netlink message header
404 *
405 * Returns 1 if a report back to the application is requested.
406 */
407static inline int nlmsg_report(struct nlmsghdr *nlh)
408{
409 return !!(nlh->nlmsg_flags & NLM_F_ECHO);
410}
411
412/**
367 * nlmsg_for_each_attr - iterate over a stream of attributes 413 * nlmsg_for_each_attr - iterate over a stream of attributes
368 * @pos: loop counter, set to current attribute 414 * @pos: loop counter, set to current attribute
369 * @nlh: netlink message header 415 * @nlh: netlink message header
@@ -453,12 +499,13 @@ static inline struct nlmsghdr *nlmsg_put_answer(struct sk_buff *skb,
453/** 499/**
454 * nlmsg_new - Allocate a new netlink message 500 * nlmsg_new - Allocate a new netlink message
455 * @size: maximum size of message 501 * @size: maximum size of message
502 * @flags: the type of memory to allocate.
456 * 503 *
457 * Use NLMSG_GOODSIZE if size isn't know and you need a good default size. 504 * Use NLMSG_GOODSIZE if size isn't know and you need a good default size.
458 */ 505 */
459static inline struct sk_buff *nlmsg_new(int size) 506static inline struct sk_buff *nlmsg_new(int size, gfp_t flags)
460{ 507{
461 return alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); 508 return alloc_skb(size, flags);
462} 509}
463 510
464/** 511/**
@@ -480,6 +527,32 @@ static inline int nlmsg_end(struct sk_buff *skb, struct nlmsghdr *nlh)
480} 527}
481 528
482/** 529/**
530 * nlmsg_get_pos - return current position in netlink message
531 * @skb: socket buffer the message is stored in
532 *
533 * Returns a pointer to the current tail of the message.
534 */
535static inline void *nlmsg_get_pos(struct sk_buff *skb)
536{
537 return skb->tail;
538}
539
540/**
541 * nlmsg_trim - Trim message to a mark
542 * @skb: socket buffer the message is stored in
543 * @mark: mark to trim to
544 *
545 * Trims the message to the provided mark. Returns -1.
546 */
547static inline int nlmsg_trim(struct sk_buff *skb, void *mark)
548{
549 if (mark)
550 skb_trim(skb, (unsigned char *) mark - skb->data);
551
552 return -1;
553}
554
555/**
483 * nlmsg_cancel - Cancel construction of a netlink message 556 * nlmsg_cancel - Cancel construction of a netlink message
484 * @skb: socket buffer the message is stored in 557 * @skb: socket buffer the message is stored in
485 * @nlh: netlink message header 558 * @nlh: netlink message header
@@ -489,9 +562,7 @@ static inline int nlmsg_end(struct sk_buff *skb, struct nlmsghdr *nlh)
489 */ 562 */
490static inline int nlmsg_cancel(struct sk_buff *skb, struct nlmsghdr *nlh) 563static inline int nlmsg_cancel(struct sk_buff *skb, struct nlmsghdr *nlh)
491{ 564{
492 skb_trim(skb, (unsigned char *) nlh - skb->data); 565 return nlmsg_trim(skb, nlh);
493
494 return -1;
495} 566}
496 567
497/** 568/**
@@ -509,15 +580,16 @@ static inline void nlmsg_free(struct sk_buff *skb)
509 * @skb: netlink message as socket buffer 580 * @skb: netlink message as socket buffer
510 * @pid: own netlink pid to avoid sending to yourself 581 * @pid: own netlink pid to avoid sending to yourself
511 * @group: multicast group id 582 * @group: multicast group id
583 * @flags: allocation flags
512 */ 584 */
513static inline int nlmsg_multicast(struct sock *sk, struct sk_buff *skb, 585static inline int nlmsg_multicast(struct sock *sk, struct sk_buff *skb,
514 u32 pid, unsigned int group) 586 u32 pid, unsigned int group, gfp_t flags)
515{ 587{
516 int err; 588 int err;
517 589
518 NETLINK_CB(skb).dst_group = group; 590 NETLINK_CB(skb).dst_group = group;
519 591
520 err = netlink_broadcast(sk, skb, pid, group, GFP_KERNEL); 592 err = netlink_broadcast(sk, skb, pid, group, flags);
521 if (err > 0) 593 if (err > 0)
522 err = 0; 594 err = 0;
523 595
@@ -631,6 +703,18 @@ static inline struct nlattr *nla_next(const struct nlattr *nla, int *remaining)
631} 703}
632 704
633/** 705/**
706 * nla_find_nested - find attribute in a set of nested attributes
707 * @nla: attribute containing the nested attributes
708 * @attrtype: type of attribute to look for
709 *
710 * Returns the first attribute which matches the specified type.
711 */
712static inline struct nlattr *nla_find_nested(struct nlattr *nla, int attrtype)
713{
714 return nla_find(nla_data(nla), nla_len(nla), attrtype);
715}
716
717/**
634 * nla_parse_nested - parse nested attributes 718 * nla_parse_nested - parse nested attributes
635 * @tb: destination array with maxtype+1 elements 719 * @tb: destination array with maxtype+1 elements
636 * @maxtype: maximum attribute type to be expected 720 * @maxtype: maximum attribute type to be expected
@@ -751,7 +835,7 @@ static inline int nla_put_msecs(struct sk_buff *skb, int attrtype,
751#define NLA_PUT_STRING(skb, attrtype, value) \ 835#define NLA_PUT_STRING(skb, attrtype, value) \
752 NLA_PUT(skb, attrtype, strlen(value) + 1, value) 836 NLA_PUT(skb, attrtype, strlen(value) + 1, value)
753 837
754#define NLA_PUT_FLAG(skb, attrtype, value) \ 838#define NLA_PUT_FLAG(skb, attrtype) \
755 NLA_PUT(skb, attrtype, 0, NULL) 839 NLA_PUT(skb, attrtype, 0, NULL)
756 840
757#define NLA_PUT_MSECS(skb, attrtype, jiffies) \ 841#define NLA_PUT_MSECS(skb, attrtype, jiffies) \
@@ -862,10 +946,7 @@ static inline int nla_nest_end(struct sk_buff *skb, struct nlattr *start)
862 */ 946 */
863static inline int nla_nest_cancel(struct sk_buff *skb, struct nlattr *start) 947static inline int nla_nest_cancel(struct sk_buff *skb, struct nlattr *start)
864{ 948{
865 if (start) 949 return nlmsg_trim(skb, start);
866 skb_trim(skb, (unsigned char *) start - skb->data);
867
868 return -1;
869} 950}
870 951
871/** 952/**
@@ -880,4 +961,13 @@ static inline int nla_nest_cancel(struct sk_buff *skb, struct nlattr *start)
880 nla_ok(pos, rem); \ 961 nla_ok(pos, rem); \
881 pos = nla_next(pos, &(rem))) 962 pos = nla_next(pos, &(rem)))
882 963
964/**
965 * nla_for_each_nested - iterate over nested attributes
966 * @pos: loop counter, set to current attribute
967 * @nla: attribute containing the nested attributes
968 * @rem: initialized to len, holds bytes currently remaining in stream
969 */
970#define nla_for_each_nested(pos, nla, rem) \
971 nla_for_each_attr(pos, nla_data(nla), nla_len(nla), rem)
972
883#endif 973#endif