lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20171125144835.5045-9-jiri@resnulli.us>
Date:   Sat, 25 Nov 2017 15:48:32 +0100
From:   Jiri Pirko <jiri@...nulli.us>
To:     netdev@...r.kernel.org
Cc:     stephen@...workplumber.org, jhs@...atatu.com, mlxsw@...lanox.com
Subject: [patch iproute2 08/11] tc: jsonify actions core

From: Jiri Pirko <jiri@...lanox.com>

Add json output to actions core.

Signed-off-by: Jiri Pirko <jiri@...lanox.com>
---
 tc/m_action.c | 22 +++++++++++++++-------
 tc/tc_util.c  | 34 ++++++++++++++++++++++++----------
 2 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/tc/m_action.c b/tc/m_action.c
index e6d9149..0940a39 100644
--- a/tc/m_action.c
+++ b/tc/m_action.c
@@ -301,17 +301,19 @@ static int tc_print_one_action(FILE *f, struct rtattr *arg)
 		return err;
 
 	if (show_stats && tb[TCA_ACT_STATS]) {
-		fprintf(f, "\tAction statistics:\n");
+		print_string(PRINT_FP, NULL, "\tAction statistics:\n", NULL);
+		open_json_object("stats");
 		print_tcstats2_attr(f, tb[TCA_ACT_STATS], "\t", NULL);
-		fprintf(f, "\n");
+		close_json_object();
+		print_string(PRINT_FP, NULL, "\n", NULL);
 	}
 	if (tb[TCA_ACT_COOKIE]) {
 		int strsz = RTA_PAYLOAD(tb[TCA_ACT_COOKIE]);
 		char b1[strsz * 2 + 1];
 
-		fprintf(f, "\tcookie %s\n",
-			hexstring_n2a(RTA_DATA(tb[TCA_ACT_COOKIE]),
-				      strsz, b1, sizeof(b1)));
+		print_string(PRINT_ANY, "cookie", "\tcookie %s\n",
+			     hexstring_n2a(RTA_DATA(tb[TCA_ACT_COOKIE]),
+					   strsz, b1, sizeof(b1)));
 	}
 
 	return 0;
@@ -362,15 +364,21 @@ tc_print_action(FILE *f, const struct rtattr *arg, unsigned short tot_acts)
 	if (tab_flush && NULL != tb[0]  && NULL == tb[1])
 		return tc_print_action_flush(f, tb[0]);
 
+	open_json_array(PRINT_JSON, "actions");
 	for (i = 0; i < tot_acts; i++) {
 		if (tb[i]) {
-			fprintf(f, "\n\taction order %d: ", i);
+			open_json_object(NULL);
+			print_uint(PRINT_ANY, "order",
+				   "\n\taction order %u: ", i);
 			if (tc_print_one_action(f, tb[i]) < 0) {
-				fprintf(f, "Error printing action\n");
+				print_string(PRINT_FP, NULL,
+					     "Error printing action\n", NULL);
 			}
+			close_json_object();
 		}
 
 	}
+	close_json_object();
 
 	return 0;
 }
diff --git a/tc/tc_util.c b/tc/tc_util.c
index d276987..1887905 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -709,12 +709,17 @@ int parse_action_control_slash(int *argc_p, char ***argv_p,
 void print_action_control(FILE *f, const char *prefix,
 			  int action, const char *suffix)
 {
-	fprintf(f, "%s%s", prefix, action_n2a(action));
+	print_string(PRINT_FP, NULL, "%s", prefix);
+	open_json_object("control_action");
+	print_string(PRINT_ANY, "type", "%s", action_n2a(action));
 	if (TC_ACT_EXT_CMP(action, TC_ACT_GOTO_CHAIN))
-		fprintf(f, " chain %u", action & TC_ACT_EXT_VAL_MASK);
+		print_uint(PRINT_ANY, "chain", " chain %u",
+			   action & TC_ACT_EXT_VAL_MASK);
 	if (TC_ACT_EXT_CMP(action, TC_ACT_JUMP))
-		fprintf(f, " %u", action & TC_ACT_EXT_VAL_MASK);
-	fprintf(f, "%s", suffix);
+		print_uint(PRINT_ANY, "jump", " %u",
+			   action & TC_ACT_EXT_VAL_MASK);
+	close_json_object();
+	print_string(PRINT_FP, NULL, "%s", suffix);
 }
 
 int get_linklayer(unsigned int *val, const char *arg)
@@ -762,12 +767,21 @@ void print_tm(FILE *f, const struct tcf_t *tm)
 {
 	int hz = get_user_hz();
 
-	if (tm->install != 0)
-		fprintf(f, " installed %u sec", (unsigned int)(tm->install/hz));
-	if (tm->lastuse != 0)
-		fprintf(f, " used %u sec", (unsigned int)(tm->lastuse/hz));
-	if (tm->expires != 0)
-		fprintf(f, " expires %u sec", (unsigned int)(tm->expires/hz));
+	if (tm->install != 0) {
+		print_uint(PRINT_JSON, "installed", NULL, tm->install);
+		print_uint(PRINT_FP, NULL, " installed %u sec",
+			   (unsigned int)(tm->install/hz));
+	}
+	if (tm->lastuse != 0) {
+		print_uint(PRINT_JSON, "last_used", NULL, tm->lastuse);
+		print_uint(PRINT_FP, NULL, " used %u sec",
+			   (unsigned int)(tm->lastuse/hz));
+	}
+	if (tm->expires != 0) {
+		print_uint(PRINT_JSON, "expires", NULL, tm->expires);
+		print_uint(PRINT_FP, NULL, " expires %u sec",
+			   (unsigned int)(tm->expires/hz));
+	}
 }
 
 void print_tcstats2_attr(FILE *fp, struct rtattr *rta, char *prefix, struct rtattr **xstats)
-- 
2.9.5

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ