1 #ifndef _IP_SET_COMMENT_H
2 #define _IP_SET_COMMENT_H
4 /* Copyright (C) 2013 Oliver Smith <oliver@8.c.9.b.0.7.4.0.1.0.0.2.ip6.arpa>
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.
14 ip_set_comment_uget(struct nlattr *tb)
19 /* Called from uadd only, protected by the set spinlock.
20 * The kadt functions don't use the comment extensions in any way.
23 ip_set_init_comment(struct ip_set *set, struct ip_set_comment *comment,
24 const struct ip_set_ext *ext)
26 struct ip_set_comment_rcu *c = rcu_dereference_protected(comment->c, 1);
27 size_t len = ext->comment ? strlen(ext->comment) : 0;
30 set->ext_size -= sizeof(*c) + strlen(c->str) + 1;
32 rcu_assign_pointer(comment->c, NULL);
36 if (unlikely(len > IPSET_MAX_COMMENT_SIZE))
37 len = IPSET_MAX_COMMENT_SIZE;
38 c = kmalloc(sizeof(*c) + len + 1, GFP_ATOMIC);
41 strlcpy(c->str, ext->comment, len + 1);
42 set->ext_size += sizeof(*c) + strlen(c->str) + 1;
43 rcu_assign_pointer(comment->c, c);
46 /* Used only when dumping a set, protected by rcu_read_lock() */
48 ip_set_put_comment(struct sk_buff *skb, const struct ip_set_comment *comment)
50 struct ip_set_comment_rcu *c = rcu_dereference(comment->c);
54 return nla_put_string(skb, IPSET_ATTR_COMMENT, c->str);
57 /* Called from uadd/udel, flush or the garbage collectors protected
58 * by the set spinlock.
59 * Called when the set is destroyed and when there can't be any user
60 * of the set data anymore.
63 ip_set_comment_free(struct ip_set *set, struct ip_set_comment *comment)
65 struct ip_set_comment_rcu *c;
67 c = rcu_dereference_protected(comment->c, 1);
70 set->ext_size -= sizeof(*c) + strlen(c->str) + 1;
72 rcu_assign_pointer(comment->c, NULL);