Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / include / linux / netfilter / ipset / ip_set_comment.h
1 #ifndef _IP_SET_COMMENT_H
2 #define _IP_SET_COMMENT_H
3
4 /* Copyright (C) 2013 Oliver Smith <oliver@8.c.9.b.0.7.4.0.1.0.0.2.ip6.arpa>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #ifdef __KERNEL__
12
13 static inline char*
14 ip_set_comment_uget(struct nlattr *tb)
15 {
16         return nla_data(tb);
17 }
18
19 static inline void
20 ip_set_init_comment(struct ip_set_comment *comment,
21                     const struct ip_set_ext *ext)
22 {
23         size_t len = ext->comment ? strlen(ext->comment) : 0;
24
25         if (unlikely(comment->str)) {
26                 kfree(comment->str);
27                 comment->str = NULL;
28         }
29         if (!len)
30                 return;
31         if (unlikely(len > IPSET_MAX_COMMENT_SIZE))
32                 len = IPSET_MAX_COMMENT_SIZE;
33         comment->str = kzalloc(len + 1, GFP_ATOMIC);
34         if (unlikely(!comment->str))
35                 return;
36         strlcpy(comment->str, ext->comment, len + 1);
37 }
38
39 static inline int
40 ip_set_put_comment(struct sk_buff *skb, struct ip_set_comment *comment)
41 {
42         if (!comment->str)
43                 return 0;
44         return nla_put_string(skb, IPSET_ATTR_COMMENT, comment->str);
45 }
46
47 static inline void
48 ip_set_comment_free(struct ip_set_comment *comment)
49 {
50         if (unlikely(!comment->str))
51                 return;
52         kfree(comment->str);
53         comment->str = NULL;
54 }
55
56 #endif
57 #endif