From: Ana Rey <anarey@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: Ana Rey <anarey@gmail.com>
Subject: [PATCH] nftables: Fix list of sets by family
Date: Fri, 28 Mar 2014 08:57:54 +0100 [thread overview]
Message-ID: <dfe65abd0921773564be9ebfe55b55233380bd40.1395993386.git.anarey@gmail.com> (raw)
Fix the result of command line 'nft list sets FAMILY'. It shows the
following error message:
"Error: syntax error, unexpected end of file, expecting string"
Use set_print function to show the list of set by family (ip, ip6, arp,
bridge).
The set_print function is used in the following command line:
* sudo nft list table FAMILY table_name
* sudo nft list set FAMILY table_name set_name
* sudo nft list sets FAMILY
In 'nft list table FAMILY table_name' and 'nft list set FAMILY
table_name set_name' command line is necessary a extra indent that is
not necessary in 'nft list sets FAMILY'.
Thus, It fixes this indent problem in the set_print function and now, it is
possible show right this information:
$ sudo nft list sets ip
et set_test {
type ipv4_address
elements = { 192.168.3.45, 192.168.3.43, 192.168.3.42, 192.168.3.4}
}
set set_test2 {
type ipv4_address
elements = { 192.168.3.43, 192.168.3.42, 192.168.3.4}
}
set set0 {
type ipv4_address
flags constant
elements = { 127.0.0.12, 172.0.0.13}
}
$ sudo nft list set ip test set_test
set set_test {
type ipv4_address
elements = { 192.168.3.45, 192.168.3.43, 192.168.3.42, 192.168.3.4}
}
$ sudo nft list table ip test
table ip test {
set set_test {
type ipv4_address
elements = { 192.168.3.45, 192.168.3.43, 192.168.3.42, 192.168.3.4}
}
set set_test2 {
type ipv4_address
elements = { 192.168.3.43, 192.168.3.42, 192.168.3.4}
}
chain input {
ip daddr { 127.0.0.12, 172.0.0.13} drop
}
}
Signed-off-by: Ana Rey <anarey@gmail.com>
---
include/rule.h | 2 +-
src/parser.y | 2 +-
src/rule.c | 26 ++++++++++++++++----------
3 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/include/rule.h b/include/rule.h
index ecf801f..b283421 100644
--- a/include/rule.h
+++ b/include/rule.h
@@ -194,7 +194,7 @@ extern struct set *set_get(struct set *set);
extern void set_free(struct set *set);
extern void set_add_hash(struct set *set, struct table *table);
extern struct set *set_lookup(const struct table *table, const char *name);
-extern void set_print(const struct set *set);
+extern void set_print(const struct set *set, bool indent);
/**
* enum cmd_ops - command operations
diff --git a/src/parser.y b/src/parser.y
index db6f493..af34857 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -719,7 +719,7 @@ list_cmd : TABLE table_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_CHAIN, &$2, &@$, NULL);
}
- | SETS table_spec
+ | SETS tables_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$2, &@$, NULL);
}
diff --git a/src/rule.c b/src/rule.c
index b719040..68f2696 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -93,21 +93,23 @@ struct set *set_lookup(const struct table *table, const char *name)
return NULL;
}
-void set_print(const struct set *set)
+void set_print(const struct set *set, bool indent)
{
const char *delim = "";
const char *type;
type = set->flags & SET_F_MAP ? "map" : "set";
- printf("\t%s %s {\n", type, set->handle.set);
+ printf("%s%s %s {\n", indent ? "\t" : "", type, set->handle.set);
+
+ printf("%s\ttype %s", indent ? "\t" : "", set->keytype->name);
- printf("\t\ttype %s", set->keytype->name);
if (set->flags & SET_F_MAP)
printf(" : %s", set->datatype->name);
printf("\n");
if (set->flags & (SET_F_CONSTANT | SET_F_INTERVAL)) {
- printf("\t\tflags ");
+ printf("%s\tflags ", indent ? "\t" : "");
+
if (set->flags & SET_F_CONSTANT) {
printf("%sconstant", delim);
delim = ",";
@@ -120,11 +122,11 @@ void set_print(const struct set *set)
}
if (set->init != NULL && set->init->size > 0) {
- printf("\t\telements = ");
+ printf("%s\telements = ", indent ? "\t" : "");
expr_print(set->init);
printf("\n");
}
- printf("\t}\n");
+ printf("%s}\n", indent ? "\t" : "");
}
struct rule *rule_alloc(const struct location *loc, const struct handle *h)
@@ -414,7 +416,7 @@ static void table_print(const struct table *table)
if (set->flags & SET_F_ANONYMOUS)
continue;
printf("%s", delim);
- set_print(set);
+ set_print(set, true);
delim = "\n";
}
list_for_each_entry(chain, &table->chains, list) {
@@ -668,8 +670,12 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
case CMD_OBJ_SETS:
if (netlink_list_sets(ctx, &cmd->handle, &cmd->location) < 0)
return -1;
- list_for_each_entry_safe(set, nset, &ctx->list, list)
- list_move_tail(&set->list, &table->sets);
+ list_for_each_entry(set, &ctx->list, list){
+ if (netlink_get_setelems(ctx, &set->handle,
+ &cmd->location, set) < 0)
+ return -1;
+ set_print(set, false);
+ }
break;
case CMD_OBJ_SET:
if (netlink_get_set(ctx, &cmd->handle, &cmd->location) < 0)
@@ -678,7 +684,7 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
if (netlink_get_setelems(ctx, &cmd->handle,
&cmd->location, set) < 0)
return -1;
- set_print(set);
+ set_print(set, false);
}
return 0;
default:
--
1.9.0
next reply other threads:[~2014-03-28 7:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-28 7:57 Ana Rey [this message]
2014-03-28 10:25 ` [PATCH] nftables: Fix list of sets by family Patrick McHardy
2014-03-28 11:37 ` Arturo Borrero Gonzalez
2014-03-28 11:40 ` Patrick McHardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dfe65abd0921773564be9ebfe55b55233380bd40.1395993386.git.anarey@gmail.com \
--to=anarey@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).