netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <simon.horman@netronome.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: Dinan Gunawardena <dinan.gunawardena@netronome.com>,
	netdev@vger.kernel.org, oss-drivers@netronome.com,
	Simon Horman <simon.horman@netronome.com>
Subject: [PATCH iproute2/net-next 4/7] tc: flower: provide generic masked u8 print helper
Date: Thu,  2 Feb 2017 11:38:37 +0100	[thread overview]
Message-ID: <1486031920-10784-5-git-send-email-simon.horman@netronome.com> (raw)
In-Reply-To: <1486031920-10784-1-git-send-email-simon.horman@netronome.com>

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@netronome.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

  parent reply	other threads:[~2017-02-02 10:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-02 10:38 [PATCH iproute2/net-next 0/7] tc: flower: Masked ICMP match and ND match Simon Horman
2017-02-02 10:38 ` [PATCH iproute2/net-next 1/7] tc: flower: Update documentation to indicate ARP takes IPv4 prefixes Simon Horman
2017-02-02 10:38 ` [PATCH iproute2/net-next 2/7] tc: flower: use correct type when calling flower_icmp_attr_type Simon Horman
2017-02-02 10:38 ` [PATCH iproute2/net-next 3/7] tc: flower: provide generic masked u8 parser helper Simon Horman
2017-02-02 10:38 ` Simon Horman [this message]
2017-02-02 10:38 ` [PATCH iproute2/net-next 5/7] tc: flower: support masked ICMP code and type match Simon Horman
2017-02-02 10:38 ` [PATCH iproute2/net-next 6/7] tc: flower: Add TCA_FLOWER_KEY_ND_* Simon Horman
2017-02-02 10:38 ` [PATCH iproute2/net-next 7/7] tc: flower: Support matching on ND Simon Horman
2017-02-02 17:27   ` Jiri Pirko
2017-02-06  8:44     ` Simon Horman
2017-02-06  9:44       ` Jiri Pirko
2017-02-06 10:09         ` [oss-drivers] " Simon Horman
2017-02-07 16:50       ` Stephen Hemminger
2017-02-06 22:28 ` [PATCH iproute2/net-next 0/7] tc: flower: Masked ICMP match and ND match Stephen Hemminger
2017-02-07  7:52   ` Simon Horman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1486031920-10784-5-git-send-email-simon.horman@netronome.com \
    --to=simon.horman@netronome.com \
    --cc=dinan.gunawardena@netronome.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).