* [PATCH iproute2 1/5] tc_util: introduce a function to print JSON/non-JSON masked numbers
2019-11-13 10:12 [PATCH iproute2 0/5] fix json output for tos and ttl Roi Dayan
@ 2019-11-13 10:12 ` Roi Dayan
2019-11-13 17:18 ` Stephen Hemminger
2019-11-13 17:20 ` Stephen Hemminger
2019-11-13 10:12 ` [PATCH iproute2 2/5] tc_util: add an option to print masked numbers with/without a newline Roi Dayan
` (4 subsequent siblings)
5 siblings, 2 replies; 11+ messages in thread
From: Roi Dayan @ 2019-11-13 10:12 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Stephen Hemminger, Jiri Pirko, Eli Britstein, Roi Dayan
From: Eli Britstein <elibr@mellanox.com>
Introduce a function to print masked number with a different output for
JSON or non-JSON methods, as a pre-step towards printing numbers using
this common function.
Signed-off-by: Eli Britstein <elibr@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
tc/tc_util.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
tc/tc_util.h | 2 ++
2 files changed, 50 insertions(+)
diff --git a/tc/tc_util.c b/tc/tc_util.c
index 0eb530408d05..2b391f182b96 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -915,6 +915,42 @@ compat_xstats:
*xstats = tb[TCA_XSTATS];
}
+static void print_masked_type(__u32 type_max,
+ __u32 (*rta_getattr_type)(const struct rtattr *),
+ const char *name, struct rtattr *attr,
+ struct rtattr *mask_attr)
+{
+ SPRINT_BUF(namefrm);
+ __u32 value, mask;
+ SPRINT_BUF(out);
+ size_t done;
+
+ if (attr) {
+ value = rta_getattr_type(attr);
+ mask = mask_attr ? rta_getattr_type(mask_attr) : type_max;
+
+ if (is_json_context()) {
+ sprintf(namefrm, "\n %s %%u", name);
+ print_hu(PRINT_ANY, name, namefrm,
+ rta_getattr_type(attr));
+ if (mask != type_max) {
+ char mask_name[SPRINT_BSIZE-6];
+
+ sprintf(mask_name, "%s_mask", name);
+ sprintf(namefrm, "\n %s %%u", mask_name);
+ print_hu(PRINT_ANY, mask_name, namefrm, mask);
+ }
+ } else {
+ done = sprintf(out, "%u", value);
+ if (mask != type_max)
+ sprintf(out + done, "/0x%x", mask);
+
+ sprintf(namefrm, "\n %s %%s", name);
+ print_string(PRINT_ANY, name, namefrm, out);
+ }
+ }
+}
+
void print_masked_u32(const char *name, struct rtattr *attr,
struct rtattr *mask_attr)
{
@@ -958,3 +994,15 @@ void print_masked_u16(const char *name, struct rtattr *attr,
sprintf(namefrm, " %s %%s", name);
print_string(PRINT_ANY, name, namefrm, out);
}
+
+static __u32 __rta_getattr_u8_u32(const struct rtattr *attr)
+{
+ return rta_getattr_u8(attr);
+}
+
+void print_masked_u8(const char *name, struct rtattr *attr,
+ struct rtattr *mask_attr)
+{
+ print_masked_type(UINT8_MAX, __rta_getattr_u8_u32, name, attr,
+ mask_attr);
+}
diff --git a/tc/tc_util.h b/tc/tc_util.h
index 0c3425abc62f..7e5d93cbac66 100644
--- a/tc/tc_util.h
+++ b/tc/tc_util.h
@@ -131,4 +131,6 @@ void print_masked_u32(const char *name, struct rtattr *attr,
struct rtattr *mask_attr);
void print_masked_u16(const char *name, struct rtattr *attr,
struct rtattr *mask_attr);
+void print_masked_u8(const char *name, struct rtattr *attr,
+ struct rtattr *mask_attr);
#endif
--
2.8.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH iproute2 1/5] tc_util: introduce a function to print JSON/non-JSON masked numbers
2019-11-13 10:12 ` [PATCH iproute2 1/5] tc_util: introduce a function to print JSON/non-JSON masked numbers Roi Dayan
@ 2019-11-13 17:18 ` Stephen Hemminger
2019-11-14 8:24 ` Roi Dayan
2019-11-13 17:20 ` Stephen Hemminger
1 sibling, 1 reply; 11+ messages in thread
From: Stephen Hemminger @ 2019-11-13 17:18 UTC (permalink / raw)
To: Roi Dayan; +Cc: netdev, David Ahern, Jiri Pirko, Eli Britstein
On Wed, 13 Nov 2019 12:12:41 +0200
Roi Dayan <roid@mellanox.com> wrote:
> +static void print_masked_type(__u32 type_max,
> + __u32 (*rta_getattr_type)(const struct rtattr *),
> + const char *name, struct rtattr *attr,
> + struct rtattr *mask_attr)
> +{
> + SPRINT_BUF(namefrm);
> + __u32 value, mask;
> + SPRINT_BUF(out);
> + size_t done;
> +
> + if (attr) {
code is cleaner if you use short circuit return here. i.e
if (!attr)
return;
...
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH iproute2 1/5] tc_util: introduce a function to print JSON/non-JSON masked numbers
2019-11-13 17:18 ` Stephen Hemminger
@ 2019-11-14 8:24 ` Roi Dayan
0 siblings, 0 replies; 11+ messages in thread
From: Roi Dayan @ 2019-11-14 8:24 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev, David Ahern, Jiri Pirko, Eli Britstein
On 2019-11-13 7:18 PM, Stephen Hemminger wrote:
> On Wed, 13 Nov 2019 12:12:41 +0200
> Roi Dayan <roid@mellanox.com> wrote:
>
>> +static void print_masked_type(__u32 type_max,
>> + __u32 (*rta_getattr_type)(const struct rtattr *),
>> + const char *name, struct rtattr *attr,
>> + struct rtattr *mask_attr)
>> +{
>> + SPRINT_BUF(namefrm);
>> + __u32 value, mask;
>> + SPRINT_BUF(out);
>> + size_t done;
>> +
>> + if (attr) {
>
> code is cleaner if you use short circuit return here. i.e
>
> if (!attr)
> return;
>
> ...
>
right. thanks for the comments. we'll fix it.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH iproute2 1/5] tc_util: introduce a function to print JSON/non-JSON masked numbers
2019-11-13 10:12 ` [PATCH iproute2 1/5] tc_util: introduce a function to print JSON/non-JSON masked numbers Roi Dayan
2019-11-13 17:18 ` Stephen Hemminger
@ 2019-11-13 17:20 ` Stephen Hemminger
2019-11-14 9:38 ` Roi Dayan
1 sibling, 1 reply; 11+ messages in thread
From: Stephen Hemminger @ 2019-11-13 17:20 UTC (permalink / raw)
To: Roi Dayan; +Cc: netdev, David Ahern, Jiri Pirko, Eli Britstein
On Wed, 13 Nov 2019 12:12:41 +0200
Roi Dayan <roid@mellanox.com> wrote:
> +
> + if (is_json_context()) {
> + sprintf(namefrm, "\n %s %%u", name);
> + print_hu(PRINT_ANY, name, namefrm,
> + rta_getattr_type(attr));
> + if (mask != type_max) {
> + char mask_name[SPRINT_BSIZE-6];
> +
> + sprintf(mask_name, "%s_mask", name);
> + sprintf(namefrm, "\n %s %%u", mask_name);
> + print_hu(PRINT_ANY, mask_name, namefrm, mask);
Should use _SL_ to handle single line output format case (instead of \n)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH iproute2 1/5] tc_util: introduce a function to print JSON/non-JSON masked numbers
2019-11-13 17:20 ` Stephen Hemminger
@ 2019-11-14 9:38 ` Roi Dayan
0 siblings, 0 replies; 11+ messages in thread
From: Roi Dayan @ 2019-11-14 9:38 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev, David Ahern, Jiri Pirko, Eli Britstein
On 2019-11-13 7:20 PM, Stephen Hemminger wrote:
> On Wed, 13 Nov 2019 12:12:41 +0200
> Roi Dayan <roid@mellanox.com> wrote:
>
>> +
>> + if (is_json_context()) {
>> + sprintf(namefrm, "\n %s %%u", name);
>> + print_hu(PRINT_ANY, name, namefrm,
>> + rta_getattr_type(attr));
>> + if (mask != type_max) {
>> + char mask_name[SPRINT_BSIZE-6];
>> +
>> + sprintf(mask_name, "%s_mask", name);
>> + sprintf(namefrm, "\n %s %%u", mask_name);
>> + print_hu(PRINT_ANY, mask_name, namefrm, mask);
>
> Should use _SL_ to handle single line output format case (instead of \n)
>
now i see there are more places using \n instead of _SL_ which breaks
oneline output. not related to this change so i'll prepare fixes for
those later.
thanks.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH iproute2 2/5] tc_util: add an option to print masked numbers with/without a newline
2019-11-13 10:12 [PATCH iproute2 0/5] fix json output for tos and ttl Roi Dayan
2019-11-13 10:12 ` [PATCH iproute2 1/5] tc_util: introduce a function to print JSON/non-JSON masked numbers Roi Dayan
@ 2019-11-13 10:12 ` Roi Dayan
2019-11-13 10:12 ` [PATCH iproute2 3/5] tc: flower: fix newline prints for ct-mark and ct-zone Roi Dayan
` (3 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Roi Dayan @ 2019-11-13 10:12 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Stephen Hemminger, Jiri Pirko, Eli Britstein, Roi Dayan
From: Eli Britstein <elibr@mellanox.com>
Add an option to print masked numbers with or without a newline, as a
pre-step towards using a common function.
Signed-off-by: Eli Britstein <elibr@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
tc/f_flower.c | 4 ++--
tc/m_ct.c | 4 ++--
tc/tc_util.c | 17 +++++++++--------
tc/tc_util.h | 6 +++---
4 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/tc/f_flower.c b/tc/f_flower.c
index a2a230162f78..41b81217e47e 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -1847,13 +1847,13 @@ static void flower_print_ct_label(struct rtattr *attr,
static void flower_print_ct_zone(struct rtattr *attr,
struct rtattr *mask_attr)
{
- print_masked_u16("ct_zone", attr, mask_attr);
+ print_masked_u16("ct_zone", attr, mask_attr, false);
}
static void flower_print_ct_mark(struct rtattr *attr,
struct rtattr *mask_attr)
{
- print_masked_u32("ct_mark", attr, mask_attr);
+ print_masked_u32("ct_mark", attr, mask_attr, false);
}
static void flower_print_key_id(const char *name, struct rtattr *attr)
diff --git a/tc/m_ct.c b/tc/m_ct.c
index d79eb5e361ac..8df2f6103601 100644
--- a/tc/m_ct.c
+++ b/tc/m_ct.c
@@ -466,8 +466,8 @@ static int print_ct(struct action_util *au, FILE *f, struct rtattr *arg)
print_string(PRINT_ANY, "action", " %s", "clear");
}
- print_masked_u32("mark", tb[TCA_CT_MARK], tb[TCA_CT_MARK_MASK]);
- print_masked_u16("zone", tb[TCA_CT_ZONE], NULL);
+ print_masked_u32("mark", tb[TCA_CT_MARK], tb[TCA_CT_MARK_MASK], false);
+ print_masked_u16("zone", tb[TCA_CT_ZONE], NULL, false);
ct_print_labels(tb[TCA_CT_LABELS], tb[TCA_CT_LABELS_MASK]);
ct_print_nat(ct_action, tb);
diff --git a/tc/tc_util.c b/tc/tc_util.c
index 2b391f182b96..d1ef4fac13f6 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -918,7 +918,7 @@ compat_xstats:
static void print_masked_type(__u32 type_max,
__u32 (*rta_getattr_type)(const struct rtattr *),
const char *name, struct rtattr *attr,
- struct rtattr *mask_attr)
+ struct rtattr *mask_attr, bool newline)
{
SPRINT_BUF(namefrm);
__u32 value, mask;
@@ -945,14 +945,15 @@ static void print_masked_type(__u32 type_max,
if (mask != type_max)
sprintf(out + done, "/0x%x", mask);
- sprintf(namefrm, "\n %s %%s", name);
+ sprintf(namefrm, "%s %s %%s", newline ? "\n " : "",
+ name);
print_string(PRINT_ANY, name, namefrm, out);
}
}
}
void print_masked_u32(const char *name, struct rtattr *attr,
- struct rtattr *mask_attr)
+ struct rtattr *mask_attr, bool newline)
{
__u32 value, mask;
SPRINT_BUF(namefrm);
@@ -969,12 +970,12 @@ void print_masked_u32(const char *name, struct rtattr *attr,
if (mask != UINT32_MAX)
sprintf(out + done, "/0x%x", mask);
- sprintf(namefrm, " %s %%s", name);
+ sprintf(namefrm, "%s %s %%s", newline ? "\n " : "", name);
print_string(PRINT_ANY, name, namefrm, out);
}
void print_masked_u16(const char *name, struct rtattr *attr,
- struct rtattr *mask_attr)
+ struct rtattr *mask_attr, bool newline)
{
__u16 value, mask;
SPRINT_BUF(namefrm);
@@ -991,7 +992,7 @@ void print_masked_u16(const char *name, struct rtattr *attr,
if (mask != UINT16_MAX)
sprintf(out + done, "/0x%x", mask);
- sprintf(namefrm, " %s %%s", name);
+ sprintf(namefrm, "%s %s %%s", newline ? "\n " : "", name);
print_string(PRINT_ANY, name, namefrm, out);
}
@@ -1001,8 +1002,8 @@ static __u32 __rta_getattr_u8_u32(const struct rtattr *attr)
}
void print_masked_u8(const char *name, struct rtattr *attr,
- struct rtattr *mask_attr)
+ struct rtattr *mask_attr, bool newline)
{
print_masked_type(UINT8_MAX, __rta_getattr_u8_u32, name, attr,
- mask_attr);
+ mask_attr, newline);
}
diff --git a/tc/tc_util.h b/tc/tc_util.h
index 7e5d93cbac66..9adf2ab42138 100644
--- a/tc/tc_util.h
+++ b/tc/tc_util.h
@@ -128,9 +128,9 @@ int action_a2n(char *arg, int *result, bool allow_num);
bool tc_qdisc_block_exists(__u32 block_index);
void print_masked_u32(const char *name, struct rtattr *attr,
- struct rtattr *mask_attr);
+ struct rtattr *mask_attr, bool newline);
void print_masked_u16(const char *name, struct rtattr *attr,
- struct rtattr *mask_attr);
+ struct rtattr *mask_attr, bool newline);
void print_masked_u8(const char *name, struct rtattr *attr,
- struct rtattr *mask_attr);
+ struct rtattr *mask_attr, bool newline);
#endif
--
2.8.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH iproute2 3/5] tc: flower: fix newline prints for ct-mark and ct-zone
2019-11-13 10:12 [PATCH iproute2 0/5] fix json output for tos and ttl Roi Dayan
2019-11-13 10:12 ` [PATCH iproute2 1/5] tc_util: introduce a function to print JSON/non-JSON masked numbers Roi Dayan
2019-11-13 10:12 ` [PATCH iproute2 2/5] tc_util: add an option to print masked numbers with/without a newline Roi Dayan
@ 2019-11-13 10:12 ` Roi Dayan
2019-11-13 10:12 ` [PATCH iproute2 4/5] tc_util: fix JSON " Roi Dayan
` (2 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Roi Dayan @ 2019-11-13 10:12 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Stephen Hemminger, Jiri Pirko, Eli Britstein, Roi Dayan
From: Eli Britstein <elibr@mellanox.com>
Matches of ct-mark and ct-zone were printed all in the same line. Fix
that so each ct match is printed in a separate line.
Example:
$ tc qdisc add dev eth0 ingress
$ tc filter add dev eth0 protocol ip parent ffff: prio 1 flower skip_hw \
ct_zone 5 ct_mark 6/0xf action ct commit zone 7 mark 8/0xf drop
Before:
$ tc -s filter show dev eth0 parent ffff:
filter protocol ip pref 1 flower chain 0
filter protocol ip pref 1 flower chain 0 handle 0x1
eth_type ipv4 ct_zone 5 ct_mark 6/0xf
skip_hw
not_in_hw
action order 1: ct commit mark 8/0xf zone 7 drop
index 1 ref 1 bind 1 installed 31 sec used 31 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
After:
$ tc -s filter show dev eth0 parent ffff:
filter protocol ip pref 1 flower chain 0
filter protocol ip pref 1 flower chain 0 handle 0x1
eth_type ipv4
ct_zone 5
ct_mark 6/0xf
skip_hw
not_in_hw
action order 1: ct commit mark 8/0xf zone 7 drop
index 1 ref 1 bind 1 installed 108 sec used 108 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
Fixes: c8a494314c40 ("tc: Introduce tc ct action")
Signed-off-by: Eli Britstein <elibr@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
tc/f_flower.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tc/f_flower.c b/tc/f_flower.c
index 41b81217e47e..724577563c27 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -1847,13 +1847,13 @@ static void flower_print_ct_label(struct rtattr *attr,
static void flower_print_ct_zone(struct rtattr *attr,
struct rtattr *mask_attr)
{
- print_masked_u16("ct_zone", attr, mask_attr, false);
+ print_masked_u16("ct_zone", attr, mask_attr, true);
}
static void flower_print_ct_mark(struct rtattr *attr,
struct rtattr *mask_attr)
{
- print_masked_u32("ct_mark", attr, mask_attr, false);
+ print_masked_u32("ct_mark", attr, mask_attr, true);
}
static void flower_print_key_id(const char *name, struct rtattr *attr)
--
2.8.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH iproute2 4/5] tc_util: fix JSON prints for ct-mark and ct-zone
2019-11-13 10:12 [PATCH iproute2 0/5] fix json output for tos and ttl Roi Dayan
` (2 preceding siblings ...)
2019-11-13 10:12 ` [PATCH iproute2 3/5] tc: flower: fix newline prints for ct-mark and ct-zone Roi Dayan
@ 2019-11-13 10:12 ` Roi Dayan
2019-11-13 10:12 ` [PATCH iproute2 5/5] tc: flower: fix output for ip tos and ttl Roi Dayan
2019-11-13 10:16 ` [PATCH iproute2 0/5] fix json output for " Roi Dayan
5 siblings, 0 replies; 11+ messages in thread
From: Roi Dayan @ 2019-11-13 10:12 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Stephen Hemminger, Jiri Pirko, Eli Britstein, Roi Dayan
From: Eli Britstein <elibr@mellanox.com>
Fix the output of ct-mark and ct-zone (both for matches and actions) to
be different in JSON/non-JSON mode.
Example:
$ tc qdisc add dev eth0 ingress
$ tc filter add dev eth0 protocol ip parent ffff: prio 1 flower skip_hw \
ct_zone 5 ct_mark 6/0xf action ct commit zone 7 mark 8/0xf drop
Non JSON format remains the same:
$ tc filter show dev eth0 parent ffff:
$ tc -s filter show dev ens1f0_0 parent ffff:
filter protocol ip pref 1 flower chain 0
filter protocol ip pref 1 flower chain 0 handle 0x1
eth_type ipv4
ct_zone 5
ct_mark 6/0xf
skip_hw
not_in_hw
action order 1: ct commit mark 8/0xf zone 7 drop
index 1 ref 1 bind 1 installed 108 sec used 108 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
JSON format is changed (partial output):
$ tc -p -j filter show dev eth0 parent ffff:
Before:
"options": {
"keys": {
"ct_zone": "5",
"ct_mark": "6/0xf"
...
"actions": [ {
"order": 1,
"kind": "ct",
"action": "commit",
"mark": "8/0xf",
"zone": "7",
...
After:
"options": {
"keys": {
"ct_zone": 5,
"ct_mark": 6,
"ct_mark_mask": 15
...
"actions": [ {
"order": 1,
"kind": "ct",
"action": "commit",
"mark": 8,
"mark_mask": 15,
"zone": 7,
...
Fixes: c8a494314c40 ("tc: Introduce tc ct action")
Signed-off-by: Eli Britstein <elibr@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
tc/tc_util.c | 41 ++++++++---------------------------------
1 file changed, 8 insertions(+), 33 deletions(-)
diff --git a/tc/tc_util.c b/tc/tc_util.c
index d1ef4fac13f6..13834234665f 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -955,45 +955,20 @@ static void print_masked_type(__u32 type_max,
void print_masked_u32(const char *name, struct rtattr *attr,
struct rtattr *mask_attr, bool newline)
{
- __u32 value, mask;
- SPRINT_BUF(namefrm);
- SPRINT_BUF(out);
- size_t done;
-
- if (!attr)
- return;
-
- value = rta_getattr_u32(attr);
- mask = mask_attr ? rta_getattr_u32(mask_attr) : UINT32_MAX;
-
- done = sprintf(out, "%u", value);
- if (mask != UINT32_MAX)
- sprintf(out + done, "/0x%x", mask);
+ print_masked_type(UINT32_MAX, rta_getattr_u32, name, attr, mask_attr,
+ newline);
+}
- sprintf(namefrm, "%s %s %%s", newline ? "\n " : "", name);
- print_string(PRINT_ANY, name, namefrm, out);
+static __u32 __rta_getattr_u16_u32(const struct rtattr *attr)
+{
+ return rta_getattr_u16(attr);
}
void print_masked_u16(const char *name, struct rtattr *attr,
struct rtattr *mask_attr, bool newline)
{
- __u16 value, mask;
- SPRINT_BUF(namefrm);
- SPRINT_BUF(out);
- size_t done;
-
- if (!attr)
- return;
-
- value = rta_getattr_u16(attr);
- mask = mask_attr ? rta_getattr_u16(mask_attr) : UINT16_MAX;
-
- done = sprintf(out, "%u", value);
- if (mask != UINT16_MAX)
- sprintf(out + done, "/0x%x", mask);
-
- sprintf(namefrm, "%s %s %%s", newline ? "\n " : "", name);
- print_string(PRINT_ANY, name, namefrm, out);
+ print_masked_type(UINT16_MAX, __rta_getattr_u16_u32, name, attr,
+ mask_attr, newline);
}
static __u32 __rta_getattr_u8_u32(const struct rtattr *attr)
--
2.8.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH iproute2 5/5] tc: flower: fix output for ip tos and ttl
2019-11-13 10:12 [PATCH iproute2 0/5] fix json output for tos and ttl Roi Dayan
` (3 preceding siblings ...)
2019-11-13 10:12 ` [PATCH iproute2 4/5] tc_util: fix JSON " Roi Dayan
@ 2019-11-13 10:12 ` Roi Dayan
2019-11-13 10:16 ` [PATCH iproute2 0/5] fix json output for " Roi Dayan
5 siblings, 0 replies; 11+ messages in thread
From: Roi Dayan @ 2019-11-13 10:12 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Stephen Hemminger, Jiri Pirko, Eli Britstein, Roi Dayan
From: Eli Britstein <elibr@mellanox.com>
Fix the output for ip tos and ttl to be numbers in JSON format.
Example:
$ tc qdisc add dev eth0 ingress
$ tc filter add dev eth0 protocol ip parent ffff: prio 1 flower skip_hw \
ip_tos 5/0xf action drop
Non JSON format remains the same:
$ tc filter show dev eth0 parent ffff:
filter protocol ip pref 1 flower chain 0
filter protocol ip pref 1 flower chain 0 handle 0x1
eth_type ipv4
ip_tos 5/0xf
skip_hw
not_in_hw
action order 1: gact action drop
random type none pass val 0
index 1 ref 1 bind 1
JSON format is changed (partial output):
$ tc -p -j filter show dev eth0 parent ffff:
Before:
"options": {
"keys": {
"ip_tos": "0x5/f",
...
After:
"options": {
"keys": {
"ip_tos": 5,
"ip_tos_mask": 15,
...
Fixes: 6ea2c2b1cff6 ("tc: flower: add support for matching on ip tos and ttl")
Signed-off-by: Eli Britstein <elibr@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
tc/f_flower.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)
diff --git a/tc/f_flower.c b/tc/f_flower.c
index 724577563c27..1b518ef30583 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -1617,20 +1617,7 @@ static void flower_print_ip_proto(__u8 *p_ip_proto,
static void flower_print_ip_attr(const char *name, struct rtattr *key_attr,
struct rtattr *mask_attr)
{
- SPRINT_BUF(namefrm);
- SPRINT_BUF(out);
- size_t done;
-
- if (!key_attr)
- return;
-
- done = sprintf(out, "0x%x", rta_getattr_u8(key_attr));
- if (mask_attr)
- sprintf(out + done, "/%x", rta_getattr_u8(mask_attr));
-
- print_string(PRINT_FP, NULL, "%s ", _SL_);
- sprintf(namefrm, "%s %%s", name);
- print_string(PRINT_ANY, name, namefrm, out);
+ print_masked_u8(name, key_attr, mask_attr, true);
}
static void flower_print_matching_flags(char *name,
--
2.8.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH iproute2 0/5] fix json output for tos and ttl
2019-11-13 10:12 [PATCH iproute2 0/5] fix json output for tos and ttl Roi Dayan
` (4 preceding siblings ...)
2019-11-13 10:12 ` [PATCH iproute2 5/5] tc: flower: fix output for ip tos and ttl Roi Dayan
@ 2019-11-13 10:16 ` Roi Dayan
5 siblings, 0 replies; 11+ messages in thread
From: Roi Dayan @ 2019-11-13 10:16 UTC (permalink / raw)
To: netdev; +Cc: David Ahern, Stephen Hemminger, Jiri Pirko, Eli Britstein
On 2019-11-13 12:12 PM, Roi Dayan wrote:
> Hi,
>
> This series is fixing output for tos and ttl in json format.
also fixing output for ct_zone and ct_mark.
forgot to mention it here.
>
> Thanks,
> Roi
>
> Eli Britstein (5):
> tc_util: introduce a function to print JSON/non-JSON masked numbers
> tc_util: add an option to print masked numbers with/without a newline
> tc: flower: fix newline prints for ct-mark and ct-zone
> tc_util: fix JSON prints for ct-mark and ct-zone
> tc: flower: fix output for ip tos and ttl
>
> tc/f_flower.c | 19 +++-----------
> tc/m_ct.c | 4 +--
> tc/tc_util.c | 80 ++++++++++++++++++++++++++++++++++++++---------------------
> tc/tc_util.h | 6 +++--
> 4 files changed, 61 insertions(+), 48 deletions(-)
>
^ permalink raw reply [flat|nested] 11+ messages in thread