Netdev List
 help / color / mirror / Atom feed
From: Roman Mashak <mrv@mojatatu.com>
To: dsahern@gmail.com
Cc: stephen@networkplumber.org, netdev@vger.kernel.org,
	kernel@mojatatu.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com,
	jiri@resnulli.us, Roman Mashak <mrv@mojatatu.com>
Subject: [PATCH iproute2-next 1/1] tc: jsonify ife action
Date: Fri, 13 Apr 2018 17:40:05 -0400	[thread overview]
Message-ID: <1523655605-20765-1-git-send-email-mrv@mojatatu.com> (raw)

Signed-off-by: Roman Mashak <mrv@mojatatu.com>
---
 tc/m_ife.c | 54 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 32 insertions(+), 22 deletions(-)

diff --git a/tc/m_ife.c b/tc/m_ife.c
index d7e61703f666..15d09a167450 100644
--- a/tc/m_ife.c
+++ b/tc/m_ife.c
@@ -240,22 +240,24 @@ static int print_ife(struct action_util *au, FILE *f, struct rtattr *arg)
 	parse_rtattr_nested(tb, TCA_IFE_MAX, arg);
 
 	if (tb[TCA_IFE_PARMS] == NULL) {
-		fprintf(f, "[NULL ife parameters]");
+		print_string(PRINT_FP, NULL, "%s", "[NULL ife parameters]");
 		return -1;
 	}
 	p = RTA_DATA(tb[TCA_IFE_PARMS]);
 
-	fprintf(f, "ife %s ", p->flags & IFE_ENCODE ? "encode" : "decode");
+	print_string(PRINT_ANY, "kind", "%s ", "ife");
+	print_string(PRINT_ANY, "mode", "%s",
+		     p->flags & IFE_ENCODE ? "encode" : "decode");
 	print_action_control(f, "action ", p->action, " ");
 
 	if (tb[TCA_IFE_TYPE]) {
 		ife_type = rta_getattr_u16(tb[TCA_IFE_TYPE]);
 		has_optional = 1;
-		fprintf(f, "type 0x%X ", ife_type);
+		print_0xhex(PRINT_ANY, "type", "type 0x%X ", ife_type);
 	}
 
 	if (has_optional)
-		fprintf(f, "\n\t ");
+		print_string(PRINT_FP, NULL, "%s\t", _SL_);
 
 	if (tb[TCA_IFE_METALST]) {
 		struct rtattr *metalist[IFE_META_MAX + 1];
@@ -268,9 +270,11 @@ static int print_ife(struct action_util *au, FILE *f, struct rtattr *arg)
 			len = RTA_PAYLOAD(metalist[IFE_META_SKBMARK]);
 			if (len) {
 				mmark = rta_getattr_u32(metalist[IFE_META_SKBMARK]);
-				fprintf(f, "use mark %u ", mmark);
+				print_uint(PRINT_ANY, "mark", "use mark %u ",
+					   mmark);
 			} else
-				fprintf(f, "allow mark ");
+				print_string(PRINT_ANY, "mark", "%s mark ",
+					     "allow");
 		}
 
 		if (metalist[IFE_META_TCINDEX]) {
@@ -278,41 +282,47 @@ static int print_ife(struct action_util *au, FILE *f, struct rtattr *arg)
 			if (len) {
 				mtcindex =
 					rta_getattr_u16(metalist[IFE_META_TCINDEX]);
-				fprintf(f, "use tcindex %d ", mtcindex);
+				print_uint(PRINT_ANY, "tcindex",
+					   "use tcindex %u ", mtcindex);
 			} else
-				fprintf(f, "allow tcindex ");
+				print_string(PRINT_ANY, "tcindex",
+					     "%s tcindex ", "allow");
 		}
 
 		if (metalist[IFE_META_PRIO]) {
 			len = RTA_PAYLOAD(metalist[IFE_META_PRIO]);
 			if (len) {
 				mprio = rta_getattr_u32(metalist[IFE_META_PRIO]);
-				fprintf(f, "use prio %u ", mprio);
+				print_uint(PRINT_ANY, "prio", "use prio %u ",
+					   mprio);
 			} else
-				fprintf(f, "allow prio ");
+				print_string(PRINT_ANY, "prio", "%s prio ",
+					     "allow");
 		}
 
 	}
 
 	if (tb[TCA_IFE_DMAC]) {
 		has_optional = 1;
-		fprintf(f, "dst %s ",
-			ll_addr_n2a(RTA_DATA(tb[TCA_IFE_DMAC]),
-				    RTA_PAYLOAD(tb[TCA_IFE_DMAC]), 0, b2,
-				    sizeof(b2)));
-
+		print_string(PRINT_ANY, "dst", "dst %s ",
+			     ll_addr_n2a(RTA_DATA(tb[TCA_IFE_DMAC]),
+					 RTA_PAYLOAD(tb[TCA_IFE_DMAC]), 0, b2,
+					 sizeof(b2)));
 	}
 
 	if (tb[TCA_IFE_SMAC]) {
 		has_optional = 1;
-		fprintf(f, "src %s ",
-			ll_addr_n2a(RTA_DATA(tb[TCA_IFE_SMAC]),
-				    RTA_PAYLOAD(tb[TCA_IFE_SMAC]), 0, b2,
-				    sizeof(b2)));
+		print_string(PRINT_ANY, "src", "src %s ",
+			     ll_addr_n2a(RTA_DATA(tb[TCA_IFE_SMAC]),
+					 RTA_PAYLOAD(tb[TCA_IFE_SMAC]), 0, b2,
+					 sizeof(b2)));
 	}
 
-	fprintf(f, "\n\t index %u ref %d bind %d", p->index, p->refcnt,
-		p->bindcnt);
+	print_string(PRINT_FP, NULL, "%s", _SL_);
+	print_uint(PRINT_ANY, "index", "\t index %u", p->index);
+	print_int(PRINT_ANY, "ref", " ref %d", p->refcnt);
+	print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt);
+
 	if (show_stats) {
 		if (tb[TCA_IFE_TM]) {
 			struct tcf_t *tm = RTA_DATA(tb[TCA_IFE_TM]);
@@ -321,7 +331,7 @@ static int print_ife(struct action_util *au, FILE *f, struct rtattr *arg)
 		}
 	}
 
-	fprintf(f, "\n");
+	print_string(PRINT_FP, NULL, "%s", _SL_);
 
 	return 0;
 }
-- 
2.7.4

             reply	other threads:[~2018-04-13 21:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-13 21:40 Roman Mashak [this message]
2018-04-16  0:24 ` [PATCH iproute2-next 1/1] tc: jsonify ife action David Ahern

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=1523655605-20765-1-git-send-email-mrv@mojatatu.com \
    --to=mrv@mojatatu.com \
    --cc=dsahern@gmail.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kernel@mojatatu.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    --cc=xiyou.wangcong@gmail.com \
    /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