[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191113101245.182025-3-roid@mellanox.com>
Date: Wed, 13 Nov 2019 12:12:42 +0200
From: Roi Dayan <roid@...lanox.com>
To: netdev@...r.kernel.org
Cc: David Ahern <dsahern@...il.com>,
Stephen Hemminger <stephen@...workplumber.org>,
Jiri Pirko <jiri@...lanox.com>,
Eli Britstein <elibr@...lanox.com>,
Roi Dayan <roid@...lanox.com>
Subject: [PATCH iproute2 2/5] tc_util: add an option to print masked numbers with/without a newline
From: Eli Britstein <elibr@...lanox.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@...lanox.com>
Reviewed-by: Roi Dayan <roid@...lanox.com>
Acked-by: Jiri Pirko <jiri@...lanox.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
Powered by blists - more mailing lists