[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1486031920-10784-5-git-send-email-simon.horman@netronome.com>
Date: Thu, 2 Feb 2017 11:38:37 +0100
From: Simon Horman <simon.horman@...ronome.com>
To: Stephen Hemminger <stephen@...workplumber.org>
Cc: Dinan Gunawardena <dinan.gunawardena@...ronome.com>,
netdev@...r.kernel.org, oss-drivers@...ronome.com,
Simon Horman <simon.horman@...ronome.com>
Subject: [PATCH iproute2/net-next 4/7] tc: flower: provide generic masked u8 print helper
Provide generic masked u8 print helper and use it to print arp operations.
Also:
* Make name parameter of arp op print helper const.
* Consistently use __u8 rather than uint8_t, in keeping with the
pervasive style in the file.
Signed-off-by: Simon Horman <simon.horman@...ronome.com>
---
tc/f_flower.c | 44 +++++++++++++++++++++++++++++++++-----------
1 file changed, 33 insertions(+), 11 deletions(-)
diff --git a/tc/f_flower.c b/tc/f_flower.c
index 5554cc05118b..6a0bedcc4d5d 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -352,6 +352,18 @@ err:
return err;
}
+static const char *flower_print_arp_op_to_name(__u8 op)
+{
+ switch (op) {
+ case ARPOP_REQUEST:
+ return "request";
+ case ARPOP_REPLY:
+ return "reply";
+ default:
+ return NULL;
+ }
+}
+
static int flower_arp_op_from_name(const char *name, __u8 *op)
{
if (!strcmp(name, "request"))
@@ -993,31 +1005,41 @@ static void flower_print_icmp(FILE *f, char *name, struct rtattr *attr)
fprintf(f, "\n %s %d", name, rta_getattr_u8(attr));
}
-static void flower_print_arp_op(FILE *f, char *name,
- struct rtattr *op_attr,
- struct rtattr *mask_attr)
+static void flower_print_masked_u8(FILE *f, const char *name,
+ struct rtattr *attr,
+ struct rtattr *mask_attr,
+ const char *(*value_to_str)(__u8 value))
{
- uint8_t op, mask;
+ const char *value_str = NULL;
+ __u8 value, mask;
- if (!op_attr)
+ if (!attr)
return;
- op = rta_getattr_u8(op_attr);
+ value = rta_getattr_u8(attr);
mask = mask_attr ? rta_getattr_u8(mask_attr) : UINT8_MAX;
+ if (mask == UINT8_MAX && value_to_str)
+ value_str = value_to_str(value);
fprintf(f, "\n %s ", name);
- if (mask == UINT8_MAX && op == ARPOP_REQUEST)
- fprintf(f, "request");
- else if (mask == UINT8_MAX && op == ARPOP_REPLY)
- fprintf(f, "reply");
+ if (value_str)
+ fputs(value_str, f);
else
- fprintf(f, "%d", op);
+ fprintf(f, "%d", value);
if (mask != UINT8_MAX)
fprintf(f, "/%d", mask);
}
+static void flower_print_arp_op(FILE *f, const char *name,
+ struct rtattr *op_attr,
+ struct rtattr *mask_attr)
+{
+ flower_print_masked_u8(f, name, op_attr, mask_attr,
+ flower_print_arp_op_to_name);
+}
+
static int flower_print_opt(struct filter_util *qu, FILE *f,
struct rtattr *opt, __u32 handle)
{
--
2.7.0.rc3.207.g0ac5344
Powered by blists - more mailing lists