netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nft v2 2/2] src: Allow list single stateful object
@ 2017-01-24 13:42 Elise Lennion
  0 siblings, 0 replies; only message in thread
From: Elise Lennion @ 2017-01-24 13:42 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel

Currently the stateful objects can only be listed in groups. With this
patch listing a single object is allowed:

$ nft list counter filter https-traffic
table ip filter {
	counter https-traffic {
		packets 4014 bytes 228948
	}
}

$ nft list quota filter https-quota
table ip filter {
	quota https-quota {
		25 mbytes used 278 kbytes
	}
}

Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
---

 v2: No change on this one.

 src/evaluate.c | 18 ++++++++++++++++++
 src/rule.c     |  6 +++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/evaluate.c b/src/evaluate.c
index 9a9927b..3cf5075 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -2936,6 +2936,24 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
 			return cmd_error(ctx, "Could not process rule: Chain '%s' does not exist",
 					 cmd->handle.chain);
 		return 0;
+	case CMD_OBJ_COUNTER:
+		table = table_lookup(&cmd->handle);
+		if (table == NULL)
+			return cmd_error(ctx, "Could not process rule: Table '%s' does not exist",
+					 cmd->handle.table);
+		if (obj_lookup(table, cmd->handle.obj, NFT_OBJECT_COUNTER) == NULL)
+			return cmd_error(ctx, "Could not process rule: Counter '%s' does not exist",
+					 cmd->handle.obj);
+		return 0;
+	case CMD_OBJ_QUOTA:
+		table = table_lookup(&cmd->handle);
+		if (table == NULL)
+			return cmd_error(ctx, "Could not process rule: Table '%s' does not exist",
+					 cmd->handle.table);
+		if (obj_lookup(table, cmd->handle.obj, NFT_OBJECT_QUOTA) == NULL)
+			return cmd_error(ctx, "Could not process rule: Quota '%s' does not exist",
+					 cmd->handle.obj);
+		return 0;
 	case CMD_OBJ_CHAINS:
 	case CMD_OBJ_SETS:
 	case CMD_OBJ_COUNTERS:
diff --git a/src/rule.c b/src/rule.c
index cd76983..665b1d9 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -1276,7 +1276,9 @@ static int do_list_obj(struct netlink_ctx *ctx, struct cmd *cmd, uint32_t type)
 		print_table = false;
 
 		list_for_each_entry(obj, &table->objs, list) {
-			if (obj->type != type)
+			if (obj->type != type ||
+			    (cmd->handle.obj != NULL &&
+			     strcmp(cmd->handle.obj, obj->handle.obj)))
 				continue;
 
 			if (!print_table) {
@@ -1426,8 +1428,10 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
 		return do_list_sets(ctx, cmd);
 	case CMD_OBJ_MAP:
 		return do_list_set(ctx, cmd, table);
+	case CMD_OBJ_COUNTER:
 	case CMD_OBJ_COUNTERS:
 		return do_list_obj(ctx, cmd, NFT_OBJECT_COUNTER);
+	case CMD_OBJ_QUOTA:
 	case CMD_OBJ_QUOTAS:
 		return do_list_obj(ctx, cmd, NFT_OBJECT_QUOTA);
 	default:
-- 
2.7.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-01-24 13:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-24 13:42 [PATCH nft v2 2/2] src: Allow list single stateful object Elise Lennion

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).