From: Eli Britstein Date: Thu, 14 Nov 2019 12:44:38 +0000 (+0200) Subject: tc_util: add an option to print masked numbers with/without a newline X-Git-Tag: v5.4.0~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=746e6c0fd312ccb091c5ce6b639623aa7f0abfd3;p=thirdparty%2Fiproute2.git tc_util: add an option to print masked numbers with/without a newline 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 Reviewed-by: Roi Dayan Acked-by: Jiri Pirko Signed-off-by: Stephen Hemminger --- diff --git a/tc/f_flower.c b/tc/f_flower.c index a2a230162..41b81217e 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 d79eb5e36..8df2f6103 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 6bd098fef..e9f3e5a22 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; @@ -939,23 +939,24 @@ static void print_masked_type(__u32 type_max, char mask_name[SPRINT_BSIZE-6]; sprintf(mask_name, "%s_mask", name); - print_string(PRINT_FP, NULL, "%s ", _SL_); - sprintf(namefrm, "%s %%u", mask_name); + if (newline) + print_string(PRINT_FP, NULL, "%s ", _SL_); + sprintf(namefrm, " %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); - - print_string(PRINT_FP, NULL, "%s ", _SL_); - sprintf(namefrm, "%s %%s", name); + if (newline) + print_string(PRINT_FP, NULL, "%s ", _SL_); + sprintf(namefrm, " %s %%s", 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); @@ -972,12 +973,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); @@ -994,7 +995,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); } @@ -1004,8 +1005,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 7e5d93cba..9adf2ab42 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