table: support for the table owner flag
Pablo Neira Ayuso
maintainerPATCH 1/1 table: support for the table owner flag
Add new flag to allow userspace process to own tables: Tables that have an owner can only be updated/destroyed by the owner. The table is destroyed either if the owner process calls nft_ctx_free() or owner process is terminated (implicit table release).
The ruleset listing includes the program name that owns the table:
nft> list ruleset
table ip x { # progname nft
flags owner
chain y {
type filter hook input priority filter; policy accept;
counter packets 1 bytes 309
}}
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/owner.h | 6 ++ include/rule.h | 4 +- src/Makefile.am | 1 + src/netlink.c | 1 + src/owner.c | 173 +++++++++++++++++++++++++++++++++++++++++++++ src/parser_bison.y | 5 +- src/rule.c | 9 ++- 7 files changed, 196 insertions(+), 3 deletions(-) create mode 100644 include/owner.h create mode 100644 src/owner.c
include/owner.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _NFT_OWNER_H_ +#define _NFT_OWNER_H_ + +char *get_progname (uint32_t portid); + +#endif
include/rule.h +3 -1
@@ -131,8 +131,9 @@ struct symbol *symbol_get(const struct scope *scope, const char *identifier);enum table_flags {TABLE_F_DORMANT = (1 <<0 ), +TABLE_F_OWNER = (1 <<1 ), }; -#define TABLE_FLAGS_MAX 1 +#define TABLE_FLAGS_MAX 2const char *table_flag_name (uint32_t flag);
@@ -162,6 +163,7 @@ struct table {struct list_head chain_bindings;enum table_flags flags;unsigned int refcnt; +uint32_t owner;const char *comment; };
src/Makefile.am +1 -0
@@ -61,6 +61,7 @@ libnftables_la_SOURCES = \ netlink_delinearize.c \ misspell.c \ monitor.c \ + owner.c \ segtree.c \ rbtree.c \ gmputil.c \
src/netlink.c +1 -0
@@ -614,6 +614,7 @@ struct table *netlink_delinearize_table(struct netlink_ctx *ctx, table->handle.table.name =xstrdup (nftnl_table_get_str (nlt,NFTNL_TABLE_NAME )); table->flags =nftnl_table_get_u32 (nlt,NFTNL_TABLE_FLAGS ); table->handle.handle.id =nftnl_table_get_u64 (nlt,NFTNL_TABLE_HANDLE ); + table->owner =nftnl_table_get_u32 (nlt,NFTNL_TABLE_OWNER );if (nftnl_table_is_set (nlt,NFTNL_TABLE_USERDATA )) { udata =nftnl_table_get_data (nlt,NFTNL_TABLE_USERDATA , &ulen);
src/owner.c new file +173 -0
173 lines not on this page · raw message
src/parser_bison.y +4 -1
@@ -1553,7 +1553,10 @@ table_block_alloc : /* empty */ table_options : FLAGS STRING { if (strcmp($2, "dormant") == 0) { - $<table>0->flags = TABLE_F_DORMANT; + $<table>0->flags |= TABLE_F_DORMANT; + xfree($2); + } else if (strcmp($2, "owner") == 0) { + $<table>0->flags |= TABLE_F_OWNER; xfree($2); } else { erec_queue(error(&@2, "unknown table option %s", $2),
src/rule.c +8 -1
@@ -25,6 +25,7 @@#include <misspell.h> #include <json.h> #include <cache.h> +#include <owner.h> #include <libnftnl/common.h> #include <libnftnl/ruleset.h>
@@ -1407,6 +1408,7 @@ struct table *table_lookup_fuzzy(const struct handle *h,static const char *table_flags_name[TABLE_FLAGS_MAX ] = {"dormant" , +"owner" , };const char *table_flag_name (uint32_t flag)
@@ -1451,8 +1453,13 @@ static void table_print(const struct table *table, struct output_ctx *octx)const char *family =family2str (table->handle.family);nft_print (octx,"table %s %s {" , family, table->handle.table.name); +if (nft_output_handle (octx) || table->flags &TABLE_F_OWNER ) +nft_print (octx," #" );if (nft_output_handle (octx)) -nft_print (octx," # handle %" PRIu64, table->handle.handle.id); +nft_print (octx," handle %" PRIu64, table->handle.handle.id); +if (table->flags &TABLE_F_OWNER ) +nft_print (octx," progname %s" ,get_progname (table->owner)); +nft_print (octx,"\n" );table_print_flags (table, &delim, octx);
Signature · 1 line
2.20.1