All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: pablo@netfilter.org
Subject: [nft RFC PATCH 2/6] rule: allow to print sets in plain format
Date: Tue, 18 Feb 2014 00:18:17 +0100	[thread overview]
Message-ID: <20140217231816.19943.70578.stgit@nfdev.cica.es> (raw)
In-Reply-To: <20140217231654.19943.18736.stgit@nfdev.cica.es>

Allow to print sets with or without format.

This is useful in situations where we want to print exactly the same the user
typed (IOW, in one single line, and with family/table info).

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
---
 include/rule.h |    1 +
 src/rule.c     |   44 +++++++++++++++++++++++++++++++++++---------
 2 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/include/rule.h b/include/rule.h
index 4891dc1..b263593 100644
--- a/include/rule.h
+++ b/include/rule.h
@@ -195,6 +195,7 @@ 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_plain(const struct set *s);
 
 /**
  * enum cmd_ops - command operations
diff --git a/src/rule.c b/src/rule.c
index 9ff2dd3..2c684d8 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -90,21 +90,30 @@ struct set *set_lookup(const struct table *table, const char *name)
 	return NULL;
 }
 
-void set_print(const struct set *set)
+static void do_set_print(const struct set *set, const char *tab,
+			 const char *nl, const char *family, const char *table)
 {
 	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", tab, type);
 
-	printf("\t\ttype %s", set->keytype->name);
+	if (family != NULL)
+		printf(" %s", family);
+
+	if (table != NULL)
+		printf(" %s", table);
+
+	printf(" %s {%s", set->handle.set, nl);
+
+	printf("%s%stype %s", tab, tab, set->keytype->name);
 	if (set->flags & SET_F_MAP)
 		printf(" : %s", set->datatype->name);
-	printf("\n");
+	printf("%s", nl);
 
 	if (set->flags & (SET_F_CONSTANT | SET_F_INTERVAL)) {
-		printf("\t\tflags ");
+		printf("%s%sflags ", tab, tab);
 		if (set->flags & SET_F_CONSTANT) {
 			printf("%sconstant", delim);
 			delim = ",";
@@ -113,15 +122,32 @@ void set_print(const struct set *set)
 			printf("%sinterval", delim);
 			delim = ",";
 		}
-		printf("\n");
+		printf("%s", nl);
 	}
 
 	if (set->init != NULL && set->init->size > 0) {
-		printf("\t\telements = ");
+		printf("%s%selements = ", tab, tab);
 		expr_print(set->init);
-		printf("\n");
+		printf("%s", nl);
 	}
-	printf("\t}\n");
+	printf("%s}%s", tab, nl);
+}
+
+void set_print(const struct set *s)
+{
+	const char *tab = "\t";
+	const char *nl = "\n";
+
+	do_set_print(s, tab, nl, NULL, NULL);
+}
+
+void set_print_plain(const struct set *s)
+{
+	const char *tab = "";
+	const char *nl = "";
+
+	do_set_print(s, tab, nl, family2str(s->handle.family),
+		     s->handle.table);
 }
 
 struct rule *rule_alloc(const struct location *loc, const struct handle *h)


  parent reply	other threads:[~2014-02-17 23:18 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-17 23:18 [nft RFC PATCH 0/6] events Arturo Borrero Gonzalez
2014-02-17 23:18 ` [nft RFC PATCH 1/6] rule: make family2str() public Arturo Borrero Gonzalez
2014-02-18  1:01   ` Pablo Neira Ayuso
2014-02-17 23:18 ` Arturo Borrero Gonzalez [this message]
2014-02-18  1:54   ` [nft RFC PATCH 2/6] rule: allow to print sets in plain format Patrick McHardy
2014-02-17 23:18 ` [nft RFC PATCH 3/6] netlink: add netlink_delinearize_set() func Arturo Borrero Gonzalez
2014-02-18  1:56   ` Patrick McHardy
2014-02-18  9:11     ` Arturo Borrero Gonzalez
2014-02-18  9:21       ` Patrick McHardy
2014-02-17 23:18 ` [nft RFC PATCH 4/6] rule: generalize chain_print() Arturo Borrero Gonzalez
2014-02-17 23:18 ` [nft RFC PATCH 5/6] netlink: add netlink_delinearize_rule() func Arturo Borrero Gonzalez
2014-02-17 23:18 ` [nft RFC PATCH 6/6] src: add events reporting Arturo Borrero Gonzalez
2014-02-18  1:10   ` Pablo Neira Ayuso
2014-02-18  2:03     ` Patrick McHardy
2014-02-18  9:28       ` Pablo Neira Ayuso
2014-02-18  9:33         ` Patrick McHardy
2014-02-18  9:43           ` Pablo Neira Ayuso
2014-02-18  9:52             ` Patrick McHardy
2014-02-18  9:58               ` Pablo Neira Ayuso
2014-02-18 10:12                 ` Patrick McHardy
2014-02-18 14:21                   ` Arturo Borrero Gonzalez
2014-02-18 14:46                     ` Patrick McHardy
2014-02-18  1:07 ` [nft RFC PATCH 0/6] events Pablo Neira Ayuso
2014-02-18  1:43 ` Patrick McHardy
2014-02-18  9:20   ` Arturo Borrero Gonzalez
2014-02-18  9:24     ` 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=20140217231816.19943.70578.stgit@nfdev.cica.es \
    --to=arturo.borrero.glez@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.