]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
tc: flower: provide generic masked u8 print helper
authorSimon Horman <simon.horman@netronome.com>
Thu, 9 Feb 2017 13:49:00 +0000 (14:49 +0100)
committerStephen Hemminger <sthemmin@microsoft.com>
Fri, 17 Feb 2017 23:32:03 +0000 (15:32 -0800)
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

index 5554cc05118ba32f6831e75e162e2e45f325ef4d..6a0bedcc4d5d0afbdb236f4fce8cd1fc358472d3 100644 (file)
@@ -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)
 {