|
|
4aca6e |
From 468bed9790e23ca37ab4e1b52b012dd8b22df800 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 parser helper
|
|
|
4aca6e |
|
|
|
4aca6e |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1422629
|
|
|
4aca6e |
Upstream Status: iproute2.git commit 180136e540ca1
|
|
|
4aca6e |
|
|
|
4aca6e |
commit 180136e540ca16826c0069644222878ea8236f93
|
|
|
4aca6e |
Author: Simon Horman <simon.horman@netronome.com>
|
|
|
4aca6e |
Date: Thu Feb 9 14:48:59 2017 +0100
|
|
|
4aca6e |
|
|
|
4aca6e |
tc: flower: provide generic masked u8 parser helper
|
|
|
4aca6e |
|
|
|
4aca6e |
Provide generic masked u8 paser helper and use it to parse arp operations.
|
|
|
4aca6e |
|
|
|
4aca6e |
Also 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 | 55 ++++++++++++++++++++++++++++++++++++++++---------------
|
|
|
4aca6e |
1 file changed, 40 insertions(+), 15 deletions(-)
|
|
|
4aca6e |
|
|
|
4aca6e |
diff --git a/tc/f_flower.c b/tc/f_flower.c
|
|
|
4aca6e |
index a2b2132..b233ec1 100644
|
|
|
4aca6e |
--- a/tc/f_flower.c
|
|
|
4aca6e |
+++ b/tc/f_flower.c
|
|
|
4aca6e |
@@ -309,33 +309,30 @@ static int flower_parse_arp_ip_addr(char *str, __be16 eth_type,
|
|
|
4aca6e |
TCA_FLOWER_UNSPEC, TCA_FLOWER_UNSPEC, n);
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
-static int flower_parse_arp_op(char *str, __be16 eth_type,
|
|
|
4aca6e |
- int op_type, int mask_type,
|
|
|
4aca6e |
- struct nlmsghdr *n)
|
|
|
4aca6e |
+static int flower_parse_u8(char *str, int value_type, int mask_type,
|
|
|
4aca6e |
+ int (*value_from_name)(const char *str,
|
|
|
4aca6e |
+ __u8 *value),
|
|
|
4aca6e |
+ bool (*value_validate)(__u8 value),
|
|
|
4aca6e |
+ struct nlmsghdr *n)
|
|
|
4aca6e |
{
|
|
|
4aca6e |
char *slash;
|
|
|
4aca6e |
int ret, err = -1;
|
|
|
4aca6e |
- uint8_t value, mask;
|
|
|
4aca6e |
+ __u8 value, mask;
|
|
|
4aca6e |
|
|
|
4aca6e |
slash = strchr(str, '/');
|
|
|
4aca6e |
if (slash)
|
|
|
4aca6e |
*slash = '\0';
|
|
|
4aca6e |
|
|
|
4aca6e |
- if (!flower_eth_type_arp(eth_type))
|
|
|
4aca6e |
- goto err;
|
|
|
4aca6e |
-
|
|
|
4aca6e |
- if (!strcmp(str, "request")) {
|
|
|
4aca6e |
- value = ARPOP_REQUEST;
|
|
|
4aca6e |
- } else if (!strcmp(str, "reply")) {
|
|
|
4aca6e |
- value = ARPOP_REPLY;
|
|
|
4aca6e |
- } else {
|
|
|
4aca6e |
+ ret = value_from_name ? value_from_name(str, &value) : -1;
|
|
|
4aca6e |
+ if (ret < 0) {
|
|
|
4aca6e |
ret = get_u8(&value, str, 10);
|
|
|
4aca6e |
if (ret)
|
|
|
4aca6e |
goto err;
|
|
|
4aca6e |
- if (value && value != ARPOP_REQUEST && value != ARPOP_REPLY)
|
|
|
4aca6e |
- goto err;
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
+ if (value_validate && !value_validate(value))
|
|
|
4aca6e |
+ goto err;
|
|
|
4aca6e |
+
|
|
|
4aca6e |
if (slash) {
|
|
|
4aca6e |
ret = get_u8(&mask, slash + 1, 10);
|
|
|
4aca6e |
if (ret)
|
|
|
4aca6e |
@@ -345,7 +342,7 @@ static int flower_parse_arp_op(char *str, __be16 eth_type,
|
|
|
4aca6e |
mask = UINT8_MAX;
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
- addattr8(n, MAX_MSG, op_type, value);
|
|
|
4aca6e |
+ addattr8(n, MAX_MSG, value_type, value);
|
|
|
4aca6e |
addattr8(n, MAX_MSG, mask_type, mask);
|
|
|
4aca6e |
|
|
|
4aca6e |
err = 0;
|
|
|
4aca6e |
@@ -355,6 +352,34 @@ err:
|
|
|
4aca6e |
return err;
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
+static int flower_arp_op_from_name(const char *name, __u8 *op)
|
|
|
4aca6e |
+{
|
|
|
4aca6e |
+ if (!strcmp(name, "request"))
|
|
|
4aca6e |
+ *op = ARPOP_REQUEST;
|
|
|
4aca6e |
+ else if (!strcmp(name, "reply"))
|
|
|
4aca6e |
+ *op = ARPOP_REPLY;
|
|
|
4aca6e |
+ else
|
|
|
4aca6e |
+ return -1;
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+ return 0;
|
|
|
4aca6e |
+}
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+static bool flow_arp_op_validate(__u8 op)
|
|
|
4aca6e |
+{
|
|
|
4aca6e |
+ return !op || op == ARPOP_REQUEST || op == ARPOP_REPLY;
|
|
|
4aca6e |
+}
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+static int flower_parse_arp_op(char *str, __be16 eth_type,
|
|
|
4aca6e |
+ int op_type, int mask_type,
|
|
|
4aca6e |
+ struct nlmsghdr *n)
|
|
|
4aca6e |
+{
|
|
|
4aca6e |
+ if (!flower_eth_type_arp(eth_type))
|
|
|
4aca6e |
+ return -1;
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+ return flower_parse_u8(str, op_type, mask_type, flower_arp_op_from_name,
|
|
|
4aca6e |
+ flow_arp_op_validate, n);
|
|
|
4aca6e |
+}
|
|
|
4aca6e |
+
|
|
|
4aca6e |
static int flower_icmp_attr_type(__be16 eth_type, __u8 ip_proto,
|
|
|
4aca6e |
enum flower_icmp_field field)
|
|
|
4aca6e |
{
|
|
|
4aca6e |
--
|
|
|
4aca6e |
1.8.3.1
|
|
|
4aca6e |
|