linma / rpms / iproute

Forked from rpms/iproute 4 years ago
Clone

Blame SOURCES/0138-tc-flower-provide-generic-masked-u8-print-helper.patch

4aca6e
From bfbb2c88f986f3e6145cbdb213d8cd4129bb0e87 Mon Sep 17 00:00:00 2001
4aca6e
From: Phil Sutter <psutter@redhat.com>
4aca6e
Date: Fri, 17 Mar 2017 13:25:13 +0100
4aca6e
Subject: [PATCH] tc: flower: provide generic masked u8 print helper
4aca6e
4aca6e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1422629
4aca6e
Upstream Status: iproute2.git commit 9d36e54f36b83
4aca6e
4aca6e
commit 9d36e54f36b8360766519bba79028aeb9ec3a762
4aca6e
Author: Simon Horman <simon.horman@netronome.com>
4aca6e
Date:   Thu Feb 9 14:49:00 2017 +0100
4aca6e
4aca6e
    tc: flower: provide generic masked u8 print helper
4aca6e
4aca6e
    Provide generic masked u8 print helper and use it to print arp operations.
4aca6e
4aca6e
    Also:
4aca6e
    * Make name parameter of arp op print helper const.
4aca6e
    * Consistently use __u8 rather than uint8_t, in keeping with the
4aca6e
      pervasive style in the file.
4aca6e
4aca6e
    Signed-off-by: Simon Horman <simon.horman@netronome.com>
4aca6e
---
4aca6e
 tc/f_flower.c | 44 +++++++++++++++++++++++++++++++++-----------
4aca6e
 1 file changed, 33 insertions(+), 11 deletions(-)
4aca6e
4aca6e
diff --git a/tc/f_flower.c b/tc/f_flower.c
4aca6e
index b233ec1..9c13e53 100644
4aca6e
--- a/tc/f_flower.c
4aca6e
+++ b/tc/f_flower.c
4aca6e
@@ -352,6 +352,18 @@ err:
4aca6e
 	return err;
4aca6e
 }
4aca6e
 
4aca6e
+static const char *flower_print_arp_op_to_name(__u8 op)
4aca6e
+{
4aca6e
+	switch (op) {
4aca6e
+	case ARPOP_REQUEST:
4aca6e
+		return "request";
4aca6e
+	case ARPOP_REPLY:
4aca6e
+		return "reply";
4aca6e
+	default:
4aca6e
+		return NULL;
4aca6e
+	}
4aca6e
+}
4aca6e
+
4aca6e
 static int flower_arp_op_from_name(const char *name, __u8 *op)
4aca6e
 {
4aca6e
 	if (!strcmp(name, "request"))
4aca6e
@@ -994,31 +1006,41 @@ static void flower_print_icmp(FILE *f, char *name, struct rtattr *attr)
4aca6e
 		fprintf(f, "\n  %s %d", name, rta_getattr_u8(attr));
4aca6e
 }
4aca6e
 
4aca6e
-static void flower_print_arp_op(FILE *f, char *name,
4aca6e
-				struct rtattr *op_attr,
4aca6e
-				struct rtattr *mask_attr)
4aca6e
+static void flower_print_masked_u8(FILE *f, const char *name,
4aca6e
+				   struct rtattr *attr,
4aca6e
+				   struct rtattr *mask_attr,
4aca6e
+				   const char *(*value_to_str)(__u8 value))
4aca6e
 {
4aca6e
-	uint8_t op, mask;
4aca6e
+	const char *value_str = NULL;
4aca6e
+	__u8 value, mask;
4aca6e
 
4aca6e
-	if (!op_attr)
4aca6e
+	if (!attr)
4aca6e
 		return;
4aca6e
 
4aca6e
-	op = rta_getattr_u8(op_attr);
4aca6e
+	value = rta_getattr_u8(attr);
4aca6e
 	mask = mask_attr ? rta_getattr_u8(mask_attr) : UINT8_MAX;
4aca6e
+	if (mask == UINT8_MAX && value_to_str)
4aca6e
+		value_str = value_to_str(value);
4aca6e
 
4aca6e
 	fprintf(f, "\n  %s ", name);
4aca6e
 
4aca6e
-	if (mask == UINT8_MAX && op == ARPOP_REQUEST)
4aca6e
-		fprintf(f, "request");
4aca6e
-	else if (mask == UINT8_MAX && op == ARPOP_REPLY)
4aca6e
-		fprintf(f, "reply");
4aca6e
+	if (value_str)
4aca6e
+		fputs(value_str, f);
4aca6e
 	else
4aca6e
-		fprintf(f, "%d", op);
4aca6e
+		fprintf(f, "%d", value);
4aca6e
 
4aca6e
 	if (mask != UINT8_MAX)
4aca6e
 		fprintf(f, "/%d", mask);
4aca6e
 }
4aca6e
 
4aca6e
+static void flower_print_arp_op(FILE *f, const char *name,
4aca6e
+				struct rtattr *op_attr,
4aca6e
+				struct rtattr *mask_attr)
4aca6e
+{
4aca6e
+	flower_print_masked_u8(f, name, op_attr, mask_attr,
4aca6e
+			       flower_print_arp_op_to_name);
4aca6e
+}
4aca6e
+
4aca6e
 static int flower_print_opt(struct filter_util *qu, FILE *f,
4aca6e
 			    struct rtattr *opt, __u32 handle)
4aca6e
 {
4aca6e
-- 
4aca6e
1.8.3.1
4aca6e