|
@@ -53,6 +53,8 @@ enum ip_set_extension {
|
|
|
IPSET_EXT_TIMEOUT = (1 << IPSET_EXT_BIT_TIMEOUT),
|
|
|
IPSET_EXT_BIT_COUNTER = 1,
|
|
|
IPSET_EXT_COUNTER = (1 << IPSET_EXT_BIT_COUNTER),
|
|
|
+ IPSET_EXT_BIT_COMMENT = 2,
|
|
|
+ IPSET_EXT_COMMENT = (1 << IPSET_EXT_BIT_COMMENT),
|
|
|
/* Mark set with an extension which needs to call destroy */
|
|
|
IPSET_EXT_BIT_DESTROY = 7,
|
|
|
IPSET_EXT_DESTROY = (1 << IPSET_EXT_BIT_DESTROY),
|
|
@@ -60,11 +62,13 @@ enum ip_set_extension {
|
|
|
|
|
|
#define SET_WITH_TIMEOUT(s) ((s)->extensions & IPSET_EXT_TIMEOUT)
|
|
|
#define SET_WITH_COUNTER(s) ((s)->extensions & IPSET_EXT_COUNTER)
|
|
|
+#define SET_WITH_COMMENT(s) ((s)->extensions & IPSET_EXT_COMMENT)
|
|
|
|
|
|
/* Extension id, in size order */
|
|
|
enum ip_set_ext_id {
|
|
|
IPSET_EXT_ID_COUNTER = 0,
|
|
|
IPSET_EXT_ID_TIMEOUT,
|
|
|
+ IPSET_EXT_ID_COMMENT,
|
|
|
IPSET_EXT_ID_MAX,
|
|
|
};
|
|
|
|
|
@@ -85,6 +89,7 @@ struct ip_set_ext {
|
|
|
u64 packets;
|
|
|
u64 bytes;
|
|
|
u32 timeout;
|
|
|
+ char *comment;
|
|
|
};
|
|
|
|
|
|
struct ip_set_counter {
|
|
@@ -92,20 +97,19 @@ struct ip_set_counter {
|
|
|
atomic64_t packets;
|
|
|
};
|
|
|
|
|
|
-struct ip_set;
|
|
|
+struct ip_set_comment {
|
|
|
+ char *str;
|
|
|
+};
|
|
|
|
|
|
-static inline void
|
|
|
-ip_set_ext_destroy(struct ip_set *set, void *data)
|
|
|
-{
|
|
|
- /* Check that the extension is enabled for the set and
|
|
|
- * call it's destroy function for its extension part in data.
|
|
|
- */
|
|
|
-}
|
|
|
+struct ip_set;
|
|
|
|
|
|
#define ext_timeout(e, s) \
|
|
|
(unsigned long *)(((void *)(e)) + (s)->offset[IPSET_EXT_ID_TIMEOUT])
|
|
|
#define ext_counter(e, s) \
|
|
|
(struct ip_set_counter *)(((void *)(e)) + (s)->offset[IPSET_EXT_ID_COUNTER])
|
|
|
+#define ext_comment(e, s) \
|
|
|
+(struct ip_set_comment *)(((void *)(e)) + (s)->offset[IPSET_EXT_ID_COMMENT])
|
|
|
+
|
|
|
|
|
|
typedef int (*ipset_adtfn)(struct ip_set *set, void *value,
|
|
|
const struct ip_set_ext *ext,
|
|
@@ -222,6 +226,36 @@ struct ip_set {
|
|
|
void *data;
|
|
|
};
|
|
|
|
|
|
+static inline void
|
|
|
+ip_set_ext_destroy(struct ip_set *set, void *data)
|
|
|
+{
|
|
|
+ /* Check that the extension is enabled for the set and
|
|
|
+ * call it's destroy function for its extension part in data.
|
|
|
+ */
|
|
|
+ if (SET_WITH_COMMENT(set))
|
|
|
+ ip_set_extensions[IPSET_EXT_ID_COMMENT].destroy(
|
|
|
+ ext_comment(data, set));
|
|
|
+}
|
|
|
+
|
|
|
+static inline int
|
|
|
+ip_set_put_flags(struct sk_buff *skb, struct ip_set *set)
|
|
|
+{
|
|
|
+ u32 cadt_flags = 0;
|
|
|
+
|
|
|
+ if (SET_WITH_TIMEOUT(set))
|
|
|
+ if (unlikely(nla_put_net32(skb, IPSET_ATTR_TIMEOUT,
|
|
|
+ htonl(set->timeout))))
|
|
|
+ return -EMSGSIZE;
|
|
|
+ if (SET_WITH_COUNTER(set))
|
|
|
+ cadt_flags |= IPSET_FLAG_WITH_COUNTERS;
|
|
|
+ if (SET_WITH_COMMENT(set))
|
|
|
+ cadt_flags |= IPSET_FLAG_WITH_COMMENT;
|
|
|
+
|
|
|
+ if (!cadt_flags)
|
|
|
+ return 0;
|
|
|
+ return nla_put_net32(skb, IPSET_ATTR_CADT_FLAGS, htonl(cadt_flags));
|
|
|
+}
|
|
|
+
|
|
|
static inline void
|
|
|
ip_set_add_bytes(u64 bytes, struct ip_set_counter *counter)
|
|
|
{
|
|
@@ -425,6 +459,7 @@ bitmap_bytes(u32 a, u32 b)
|
|
|
}
|
|
|
|
|
|
#include <linux/netfilter/ipset/ip_set_timeout.h>
|
|
|
+#include <linux/netfilter/ipset/ip_set_comment.h>
|
|
|
|
|
|
#define IP_SET_INIT_KEXT(skb, opt, set) \
|
|
|
{ .bytes = (skb)->len, .packets = 1, \
|