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 <elibr@mellanox.com> Reviewed-by: Roi Dayan <roid@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
parent
04b215015b
commit
746e6c0fd3
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
25
tc/tc_util.c
25
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue