tc: jsonify skbedit action

v2:
   FIxed strings format in print_string()

Signed-off-by: Roman Mashak <mrv@mojatatu.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
Roman Mashak 2018-04-10 14:04:29 -04:00 committed by David Ahern
parent 8feb516bfc
commit 7b17701717
1 changed files with 29 additions and 24 deletions

View File

@ -168,9 +168,8 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
struct rtattr *tb[TCA_SKBEDIT_MAX + 1]; struct rtattr *tb[TCA_SKBEDIT_MAX + 1];
SPRINT_BUF(b1); SPRINT_BUF(b1);
__u32 *priority; __u32 priority;
__u32 *mark; __u16 ptype;
__u16 *queue_mapping, *ptype;
struct tc_skbedit *p = NULL; struct tc_skbedit *p = NULL;
if (arg == NULL) if (arg == NULL)
@ -179,43 +178,49 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
parse_rtattr_nested(tb, TCA_SKBEDIT_MAX, arg); parse_rtattr_nested(tb, TCA_SKBEDIT_MAX, arg);
if (tb[TCA_SKBEDIT_PARMS] == NULL) { if (tb[TCA_SKBEDIT_PARMS] == NULL) {
fprintf(f, "[NULL skbedit parameters]"); print_string(PRINT_FP, NULL, "%s", "[NULL skbedit parameters]");
return -1; return -1;
} }
p = RTA_DATA(tb[TCA_SKBEDIT_PARMS]); p = RTA_DATA(tb[TCA_SKBEDIT_PARMS]);
fprintf(f, " skbedit"); print_string(PRINT_ANY, "kind", "%s ", "skbedit");
if (tb[TCA_SKBEDIT_QUEUE_MAPPING] != NULL) { if (tb[TCA_SKBEDIT_QUEUE_MAPPING] != NULL) {
queue_mapping = RTA_DATA(tb[TCA_SKBEDIT_QUEUE_MAPPING]); print_uint(PRINT_ANY, "queue_mapping", "queue_mapping %u",
fprintf(f, " queue_mapping %u", *queue_mapping); rta_getattr_u16(tb[TCA_SKBEDIT_QUEUE_MAPPING]));
} }
if (tb[TCA_SKBEDIT_PRIORITY] != NULL) { if (tb[TCA_SKBEDIT_PRIORITY] != NULL) {
priority = RTA_DATA(tb[TCA_SKBEDIT_PRIORITY]); priority = rta_getattr_u32(tb[TCA_SKBEDIT_PRIORITY]);
fprintf(f, " priority %s", sprint_tc_classid(*priority, b1)); print_string(PRINT_ANY, "priority", " priority %s",
sprint_tc_classid(priority, b1));
} }
if (tb[TCA_SKBEDIT_MARK] != NULL) { if (tb[TCA_SKBEDIT_MARK] != NULL) {
mark = RTA_DATA(tb[TCA_SKBEDIT_MARK]); print_uint(PRINT_ANY, "mark", " mark %u",
fprintf(f, " mark %d", *mark); rta_getattr_u32(tb[TCA_SKBEDIT_MARK]));
} }
if (tb[TCA_SKBEDIT_PTYPE] != NULL) { if (tb[TCA_SKBEDIT_PTYPE] != NULL) {
ptype = RTA_DATA(tb[TCA_SKBEDIT_PTYPE]); ptype = rta_getattr_u16(tb[TCA_SKBEDIT_PTYPE]);
if (*ptype == PACKET_HOST) if (ptype == PACKET_HOST)
fprintf(f, " ptype host"); print_string(PRINT_ANY, "ptype", " ptype %s", "host");
else if (*ptype == PACKET_BROADCAST) else if (ptype == PACKET_BROADCAST)
fprintf(f, " ptype broadcast"); print_string(PRINT_ANY, "ptype", " ptype %s",
else if (*ptype == PACKET_MULTICAST) "broadcast");
fprintf(f, " ptype multicast"); else if (ptype == PACKET_MULTICAST)
else if (*ptype == PACKET_OTHERHOST) print_string(PRINT_ANY, "ptype", " ptype %s",
fprintf(f, " ptype otherhost"); "multicast");
else if (ptype == PACKET_OTHERHOST)
print_string(PRINT_ANY, "ptype", " ptype %s",
"otherhost");
else else
fprintf(f, " ptype %d", *ptype); print_uint(PRINT_ANY, "ptype", " ptype %u", ptype);
} }
print_action_control(f, " ", p->action, ""); print_action_control(f, " ", p->action, "");
fprintf(f, "\n\t index %u ref %d bind %d", print_string(PRINT_FP, NULL, "%s", _SL_);
p->index, p->refcnt, p->bindcnt); 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 (show_stats) {
if (tb[TCA_SKBEDIT_TM]) { if (tb[TCA_SKBEDIT_TM]) {
@ -225,7 +230,7 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
} }
} }
fprintf(f, "\n "); print_string(PRINT_FP, NULL, "%s", _SL_);
return 0; return 0;
} }