diff options
author | Thomas Graf <tgraf@suug.ch> | 2006-08-05 02:03:05 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-09-22 17:53:43 -0400 |
commit | fe4944e59c357f945f81bc67edb7ed1392e875ad (patch) | |
tree | 9634365d416ac574442fc7e21e1eaa26a71a26d1 /net | |
parent | e1ef4bf23b1ced0bf78a1c98289f746486e5c912 (diff) |
[NETLINK]: Extend netlink messaging interface
Adds:
nlmsg_get_pos() return current position in message
nlmsg_trim() trim part of message
nla_reserve_nohdr(skb, len) reserve room for an attribute w/o hdr
nla_put_nohdr(skb, len, data) add attribute w/o hdr
nla_find_nested() find attribute in nested attributes
Fixes nlmsg_new() to take allocation flags and consider size.
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/netlink/attr.c | 75 | ||||
-rw-r--r-- | net/netlink/genetlink.c | 2 |
2 files changed, 76 insertions, 1 deletions
diff --git a/net/netlink/attr.c b/net/netlink/attr.c index dddbd15135a8..136e529e5780 100644 --- a/net/netlink/attr.c +++ b/net/netlink/attr.c | |||
@@ -255,6 +255,26 @@ struct nlattr *__nla_reserve(struct sk_buff *skb, int attrtype, int attrlen) | |||
255 | } | 255 | } |
256 | 256 | ||
257 | /** | 257 | /** |
258 | * __nla_reserve_nohdr - reserve room for attribute without header | ||
259 | * @skb: socket buffer to reserve room on | ||
260 | * @attrlen: length of attribute payload | ||
261 | * | ||
262 | * Reserves room for attribute payload without a header. | ||
263 | * | ||
264 | * The caller is responsible to ensure that the skb provides enough | ||
265 | * tailroom for the payload. | ||
266 | */ | ||
267 | void *__nla_reserve_nohdr(struct sk_buff *skb, int attrlen) | ||
268 | { | ||
269 | void *start; | ||
270 | |||
271 | start = skb_put(skb, NLA_ALIGN(attrlen)); | ||
272 | memset(start, 0, NLA_ALIGN(attrlen)); | ||
273 | |||
274 | return start; | ||
275 | } | ||
276 | |||
277 | /** | ||
258 | * nla_reserve - reserve room for attribute on the skb | 278 | * nla_reserve - reserve room for attribute on the skb |
259 | * @skb: socket buffer to reserve room on | 279 | * @skb: socket buffer to reserve room on |
260 | * @attrtype: attribute type | 280 | * @attrtype: attribute type |
@@ -275,6 +295,24 @@ struct nlattr *nla_reserve(struct sk_buff *skb, int attrtype, int attrlen) | |||
275 | } | 295 | } |
276 | 296 | ||
277 | /** | 297 | /** |
298 | * nla_reserve - reserve room for attribute without header | ||
299 | * @skb: socket buffer to reserve room on | ||
300 | * @len: length of attribute payload | ||
301 | * | ||
302 | * Reserves room for attribute payload without a header. | ||
303 | * | ||
304 | * Returns NULL if the tailroom of the skb is insufficient to store | ||
305 | * the attribute payload. | ||
306 | */ | ||
307 | void *nla_reserve_nohdr(struct sk_buff *skb, int attrlen) | ||
308 | { | ||
309 | if (unlikely(skb_tailroom(skb) < NLA_ALIGN(attrlen))) | ||
310 | return NULL; | ||
311 | |||
312 | return __nla_reserve_nohdr(skb, attrlen); | ||
313 | } | ||
314 | |||
315 | /** | ||
278 | * __nla_put - Add a netlink attribute to a socket buffer | 316 | * __nla_put - Add a netlink attribute to a socket buffer |
279 | * @skb: socket buffer to add attribute to | 317 | * @skb: socket buffer to add attribute to |
280 | * @attrtype: attribute type | 318 | * @attrtype: attribute type |
@@ -293,6 +331,22 @@ void __nla_put(struct sk_buff *skb, int attrtype, int attrlen, | |||
293 | memcpy(nla_data(nla), data, attrlen); | 331 | memcpy(nla_data(nla), data, attrlen); |
294 | } | 332 | } |
295 | 333 | ||
334 | /** | ||
335 | * __nla_put_nohdr - Add a netlink attribute without header | ||
336 | * @skb: socket buffer to add attribute to | ||
337 | * @attrlen: length of attribute payload | ||
338 | * @data: head of attribute payload | ||
339 | * | ||
340 | * The caller is responsible to ensure that the skb provides enough | ||
341 | * tailroom for the attribute payload. | ||
342 | */ | ||
343 | void __nla_put_nohdr(struct sk_buff *skb, int attrlen, const void *data) | ||
344 | { | ||
345 | void *start; | ||
346 | |||
347 | start = __nla_reserve_nohdr(skb, attrlen); | ||
348 | memcpy(start, data, attrlen); | ||
349 | } | ||
296 | 350 | ||
297 | /** | 351 | /** |
298 | * nla_put - Add a netlink attribute to a socket buffer | 352 | * nla_put - Add a netlink attribute to a socket buffer |
@@ -313,15 +367,36 @@ int nla_put(struct sk_buff *skb, int attrtype, int attrlen, const void *data) | |||
313 | return 0; | 367 | return 0; |
314 | } | 368 | } |
315 | 369 | ||
370 | /** | ||
371 | * nla_put_nohdr - Add a netlink attribute without header | ||
372 | * @skb: socket buffer to add attribute to | ||
373 | * @attrlen: length of attribute payload | ||
374 | * @data: head of attribute payload | ||
375 | * | ||
376 | * Returns -1 if the tailroom of the skb is insufficient to store | ||
377 | * the attribute payload. | ||
378 | */ | ||
379 | int nla_put_nohdr(struct sk_buff *skb, int attrlen, const void *data) | ||
380 | { | ||
381 | if (unlikely(skb_tailroom(skb) < NLA_ALIGN(attrlen))) | ||
382 | return -1; | ||
383 | |||
384 | __nla_put_nohdr(skb, attrlen, data); | ||
385 | return 0; | ||
386 | } | ||
316 | 387 | ||
317 | EXPORT_SYMBOL(nla_validate); | 388 | EXPORT_SYMBOL(nla_validate); |
318 | EXPORT_SYMBOL(nla_parse); | 389 | EXPORT_SYMBOL(nla_parse); |
319 | EXPORT_SYMBOL(nla_find); | 390 | EXPORT_SYMBOL(nla_find); |
320 | EXPORT_SYMBOL(nla_strlcpy); | 391 | EXPORT_SYMBOL(nla_strlcpy); |
321 | EXPORT_SYMBOL(__nla_reserve); | 392 | EXPORT_SYMBOL(__nla_reserve); |
393 | EXPORT_SYMBOL(__nla_reserve_nohdr); | ||
322 | EXPORT_SYMBOL(nla_reserve); | 394 | EXPORT_SYMBOL(nla_reserve); |
395 | EXPORT_SYMBOL(nla_reserve_nohdr); | ||
323 | EXPORT_SYMBOL(__nla_put); | 396 | EXPORT_SYMBOL(__nla_put); |
397 | EXPORT_SYMBOL(__nla_put_nohdr); | ||
324 | EXPORT_SYMBOL(nla_put); | 398 | EXPORT_SYMBOL(nla_put); |
399 | EXPORT_SYMBOL(nla_put_nohdr); | ||
325 | EXPORT_SYMBOL(nla_memcpy); | 400 | EXPORT_SYMBOL(nla_memcpy); |
326 | EXPORT_SYMBOL(nla_memcmp); | 401 | EXPORT_SYMBOL(nla_memcmp); |
327 | EXPORT_SYMBOL(nla_strcmp); | 402 | EXPORT_SYMBOL(nla_strcmp); |
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c index a298f77cc3e3..75bb47a898dd 100644 --- a/net/netlink/genetlink.c +++ b/net/netlink/genetlink.c | |||
@@ -440,7 +440,7 @@ static struct sk_buff *ctrl_build_msg(struct genl_family *family, u32 pid, | |||
440 | struct sk_buff *skb; | 440 | struct sk_buff *skb; |
441 | int err; | 441 | int err; |
442 | 442 | ||
443 | skb = nlmsg_new(NLMSG_GOODSIZE); | 443 | skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
444 | if (skb == NULL) | 444 | if (skb == NULL) |
445 | return ERR_PTR(-ENOBUFS); | 445 | return ERR_PTR(-ENOBUFS); |
446 | 446 | ||