Skip to content

Commit 3ecbfd6

Browse files
hs256ummakynes
authored andcommitted
netfilter: nf_tables: allocate handle and delete objects via handle
This patch allows deletion of objects via unique handle which can be listed via '-a' option. Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent cc2d586 commit 3ecbfd6

3 files changed

Lines changed: 153 additions & 14 deletions

File tree

‎include/net/netfilter/nf_tables.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ void nft_unregister_set(struct nft_set_type *type);
374374
* @list: table set list node
375375
* @bindings: list of set bindings
376376
* @name: name of the set
377+
* @handle: unique handle of the set
377378
* @ktype: key type (numeric type defined by userspace, not used in the kernel)
378379
* @dtype: data type (verdict or numeric type defined by userspace)
379380
* @objtype: object type (see NFT_OBJECT_* definitions)
@@ -396,6 +397,7 @@ struct nft_set {
396397
struct list_head list;
397398
struct list_head bindings;
398399
char *name;
400+
u64 handle;
399401
u32 ktype;
400402
u32 dtype;
401403
u32 objtype;
@@ -946,6 +948,7 @@ unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);
946948
* @objects: stateful objects in the table
947949
* @flowtables: flow tables in the table
948950
* @hgenerator: handle generator state
951+
* @handle: table handle
949952
* @use: number of chain references to this table
950953
* @flags: table flag (see enum nft_table_flags)
951954
* @genmask: generation mask
@@ -959,6 +962,7 @@ struct nft_table {
959962
struct list_head objects;
960963
struct list_head flowtables;
961964
u64 hgenerator;
965+
u64 handle;
962966
u32 use;
963967
u16 family:6,
964968
flags:8,
@@ -983,16 +987,17 @@ int nft_verdict_dump(struct sk_buff *skb, int type,
983987
* @name: name of this stateful object
984988
* @genmask: generation mask
985989
* @use: number of references to this stateful object
986-
* @data: object data, layout depends on type
990+
* @handle: unique object handle
987991
* @ops: object operations
988-
* @data: pointer to object data
992+
* @data: object data, layout depends on type
989993
*/
990994
struct nft_object {
991995
struct list_head list;
992996
char *name;
993997
struct nft_table *table;
994998
u32 genmask:2,
995999
use:30;
1000+
u64 handle;
9961001
/* runtime data below here */
9971002
const struct nft_object_ops *ops ____cacheline_aligned;
9981003
unsigned char data[]
@@ -1074,6 +1079,7 @@ void nft_unregister_obj(struct nft_object_type *obj_type);
10741079
* @ops_len: number of hooks in array
10751080
* @genmask: generation mask
10761081
* @use: number of references to this flow table
1082+
* @handle: unique object handle
10771083
* @data: rhashtable and garbage collector
10781084
* @ops: array of hooks
10791085
*/
@@ -1086,6 +1092,7 @@ struct nft_flowtable {
10861092
int ops_len;
10871093
u32 genmask:2,
10881094
use:30;
1095+
u64 handle;
10891096
/* runtime data below here */
10901097
struct nf_hook_ops *ops ____cacheline_aligned;
10911098
struct nf_flowtable data;

‎include/uapi/linux/netfilter/nf_tables.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ enum nft_table_attributes {
174174
NFTA_TABLE_NAME,
175175
NFTA_TABLE_FLAGS,
176176
NFTA_TABLE_USE,
177+
NFTA_TABLE_HANDLE,
178+
NFTA_TABLE_PAD,
177179
__NFTA_TABLE_MAX
178180
};
179181
#define NFTA_TABLE_MAX (__NFTA_TABLE_MAX - 1)
@@ -317,6 +319,7 @@ enum nft_set_desc_attributes {
317319
* @NFTA_SET_GC_INTERVAL: garbage collection interval (NLA_U32)
318320
* @NFTA_SET_USERDATA: user data (NLA_BINARY)
319321
* @NFTA_SET_OBJ_TYPE: stateful object type (NLA_U32: NFT_OBJECT_*)
322+
* @NFTA_SET_HANDLE: set handle (NLA_U64)
320323
*/
321324
enum nft_set_attributes {
322325
NFTA_SET_UNSPEC,
@@ -335,6 +338,7 @@ enum nft_set_attributes {
335338
NFTA_SET_USERDATA,
336339
NFTA_SET_PAD,
337340
NFTA_SET_OBJ_TYPE,
341+
NFTA_SET_HANDLE,
338342
__NFTA_SET_MAX
339343
};
340344
#define NFTA_SET_MAX (__NFTA_SET_MAX - 1)
@@ -1314,6 +1318,7 @@ enum nft_ct_helper_attributes {
13141318
* @NFTA_OBJ_TYPE: stateful object type (NLA_U32)
13151319
* @NFTA_OBJ_DATA: stateful object data (NLA_NESTED)
13161320
* @NFTA_OBJ_USE: number of references to this expression (NLA_U32)
1321+
* @NFTA_OBJ_HANDLE: object handle (NLA_U64)
13171322
*/
13181323
enum nft_object_attributes {
13191324
NFTA_OBJ_UNSPEC,
@@ -1322,6 +1327,8 @@ enum nft_object_attributes {
13221327
NFTA_OBJ_TYPE,
13231328
NFTA_OBJ_DATA,
13241329
NFTA_OBJ_USE,
1330+
NFTA_OBJ_HANDLE,
1331+
NFTA_OBJ_PAD,
13251332
__NFTA_OBJ_MAX
13261333
};
13271334
#define NFTA_OBJ_MAX (__NFTA_OBJ_MAX - 1)
@@ -1333,13 +1340,16 @@ enum nft_object_attributes {
13331340
* @NFTA_FLOWTABLE_NAME: name of this flow table (NLA_STRING)
13341341
* @NFTA_FLOWTABLE_HOOK: netfilter hook configuration(NLA_U32)
13351342
* @NFTA_FLOWTABLE_USE: number of references to this flow table (NLA_U32)
1343+
* @NFTA_FLOWTABLE_HANDLE: object handle (NLA_U64)
13361344
*/
13371345
enum nft_flowtable_attributes {
13381346
NFTA_FLOWTABLE_UNSPEC,
13391347
NFTA_FLOWTABLE_TABLE,
13401348
NFTA_FLOWTABLE_NAME,
13411349
NFTA_FLOWTABLE_HOOK,
13421350
NFTA_FLOWTABLE_USE,
1351+
NFTA_FLOWTABLE_HANDLE,
1352+
NFTA_FLOWTABLE_PAD,
13431353
__NFTA_FLOWTABLE_MAX
13441354
};
13451355
#define NFTA_FLOWTABLE_MAX (__NFTA_FLOWTABLE_MAX - 1)

0 commit comments

Comments
 (0)