Skip to contentSkip to conversation

src: limit stateful object support

PATCH Applied Pablo M. Bermudo Garay 2 participants 2 messages Aug 23, 2017 – Sep 4, 2017 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 src: limit stateful object support

This patch adds support for a new type of stateful object: limit.

---
 include/libnftnl/object.h           |   8 ++
 include/linux/netfilter/nf_tables.h |   3 +-
 include/obj.h                       |   8 ++
 src/Makefile.am                     |   1 +
 src/obj/limit.c                     | 238 ++++++++++++++++++++++++++++++++++++
 src/object.c                        |   3 +-
 6 files changed, 259 insertions(+), 2 deletions(-)
 create mode 100644 src/obj/limit.c
include/libnftnl/object.h +8 -0
index ccd9d19..1c3bc7c 100644
@@ -40,6 +40,14 @@ enum {
 	NFTNL_OBJ_CT_HELPER_L4PROTO,
 };
 
+enum {
+	NFTNL_OBJ_LIMIT_RATE	= NFTNL_OBJ_BASE,
+	NFTNL_OBJ_LIMIT_UNIT,
+	NFTNL_OBJ_LIMIT_BURST,
+	NFTNL_OBJ_LIMIT_TYPE,
+	NFTNL_OBJ_LIMIT_FLAGS,
+};
+
 struct nftnl_obj;
 
 struct nftnl_obj *nftnl_obj_alloc(void);
include/linux/netfilter/nf_tables.h +2 -1
index 2e174d8..874fa3f 100644
@@ -1278,7 +1278,8 @@ enum nft_ct_helper_attributes {
 #define NFT_OBJECT_COUNTER	1
 #define NFT_OBJECT_QUOTA	2
 #define NFT_OBJECT_CT_HELPER	3
-#define __NFT_OBJECT_MAX	4
+#define NFT_OBJECT_LIMIT	4
+#define __NFT_OBJECT_MAX	5
 #define NFT_OBJECT_MAX		(__NFT_OBJECT_MAX - 1)
 
 /**
include/obj.h +8 -0
index d90919f..d17d63a 100644
@@ -35,6 +35,13 @@ struct nftnl_obj {
 			uint8_t		l4proto;
 			char		name[16];
 		} ct_helper;
+		struct nftnl_obj_limit {
+			uint64_t	rate;
+			uint64_t	unit;
+			uint32_t	burst;
+			uint32_t	type;
+			uint32_t	flags;
+		} limit;
 	} data;
 };
 
@@ -55,6 +62,7 @@ struct obj_ops {
 extern struct obj_ops obj_ops_counter;
 extern struct obj_ops obj_ops_quota;
 extern struct obj_ops obj_ops_ct_helper;
+extern struct obj_ops obj_ops_limit;
 
 #define nftnl_obj_data(obj) (void *)&obj->data
 
src/Makefile.am +1 -0
index 77b67b2..59ddf6a 100644
@@ -55,4 +55,5 @@ libnftnl_la_SOURCES = utils.c		\
 		      obj/counter.c	\
 		      obj/ct_helper.c	\
 		      obj/quota.c	\
+		      obj/limit.c	\
 		      libnftnl.map
src/obj/limit.c new file +238 -0

238 lines not on this page · raw message

src/object.c +2 -1
index e1a5ac4..9dc5b41 100644
@@ -29,11 +29,12 @@ static struct obj_ops *obj_ops[] = {
 	[NFT_OBJECT_COUNTER]	= &obj_ops_counter,
 	[NFT_OBJECT_QUOTA]	= &obj_ops_quota,
 	[NFT_OBJECT_CT_HELPER]	= &obj_ops_ct_helper,
+	[NFT_OBJECT_LIMIT]	= &obj_ops_limit,
 };
 
 static struct obj_ops *nftnl_obj_ops_lookup(uint32_t type)
 {
-	if (type > NFT_OBJECT_CT_HELPER)
+	if (type > NFT_OBJECT_MAX)
 		return NULL;
 
 	return obj_ops[type];
Signature · 1 line
2.14.1
maintainer Applied
#1 lore raw
Quoted 1 line · Pablo M. Bermudo Garay

This patch adds support for a new type of stateful object: limit.

Applied, thanks.