|
|
cd1737 |
From f8e5b20689cdc1f488140d9da4adf6f3ca421d3f Mon Sep 17 00:00:00 2001
|
|
|
cd1737 |
From: Kamal Heib <kheib@redhat.com>
|
|
|
cd1737 |
Date: Thu, 9 Nov 2017 04:44:32 -0500
|
|
|
cd1737 |
Subject: [PATCH] tc: flower: add support for matching on ip tos and ttl
|
|
|
cd1737 |
|
|
|
cd1737 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1456539
|
|
|
cd1737 |
|
|
|
cd1737 |
commit 6ea2c2b1cff676be2d01029a01cbd84d0675213c
|
|
|
cd1737 |
Author: Or Gerlitz <ogerlitz@mellanox.com>
|
|
|
cd1737 |
Date: Wed Jun 7 15:17:54 2017 +0300
|
|
|
cd1737 |
|
|
|
cd1737 |
tc: flower: add support for matching on ip tos and ttl
|
|
|
cd1737 |
|
|
|
cd1737 |
Allow users to set flower classifier filter rules which
|
|
|
cd1737 |
include matches for ip tos and ttl.
|
|
|
cd1737 |
|
|
|
cd1737 |
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
|
|
|
cd1737 |
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
|
|
|
cd1737 |
|
|
|
cd1737 |
Signed-off-by: Kamal Heib <kheib@redhat.com>
|
|
|
cd1737 |
---
|
|
|
cd1737 |
man/man8/tc-flower.8 | 17 +++++++++++-
|
|
|
cd1737 |
tc/f_flower.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
cd1737 |
2 files changed, 91 insertions(+), 1 deletion(-)
|
|
|
cd1737 |
|
|
|
cd1737 |
diff --git a/man/man8/tc-flower.8 b/man/man8/tc-flower.8
|
|
|
cd1737 |
index 7648079..be46f02 100644
|
|
|
cd1737 |
--- a/man/man8/tc-flower.8
|
|
|
cd1737 |
+++ b/man/man8/tc-flower.8
|
|
|
cd1737 |
@@ -30,7 +30,11 @@ flower \- flow based traffic control filter
|
|
|
cd1737 |
.BR vlan_ethtype " { " ipv4 " | " ipv6 " | "
|
|
|
cd1737 |
.IR ETH_TYPE " } | "
|
|
|
cd1737 |
.BR ip_proto " { " tcp " | " udp " | " sctp " | " icmp " | " icmpv6 " | "
|
|
|
cd1737 |
-.IR IP_PROTO " } | { "
|
|
|
cd1737 |
+.IR IP_PROTO " } | "
|
|
|
cd1737 |
+.B ip_tos
|
|
|
cd1737 |
+.IR MASKED_IP_TOS " | "
|
|
|
cd1737 |
+.B ip_ttl
|
|
|
cd1737 |
+.IR MASKED_IP_TTL " | { "
|
|
|
cd1737 |
.BR dst_ip " | " src_ip " } "
|
|
|
cd1737 |
.IR PREFIX " | { "
|
|
|
cd1737 |
.BR dst_port " | " src_port " } "
|
|
|
cd1737 |
@@ -122,6 +126,17 @@ may be
|
|
|
cd1737 |
.BR tcp ", " udp ", " sctp ", " icmp ", " icmpv6
|
|
|
cd1737 |
or an unsigned 8bit value in hexadecimal format.
|
|
|
cd1737 |
.TP
|
|
|
cd1737 |
+.BI ip_tos " MASKED_IP_TOS"
|
|
|
cd1737 |
+Match on ipv4 TOS or ipv6 traffic-class - eight bits in hexadecimal format.
|
|
|
cd1737 |
+A mask may be optionally provided to limit the bits which are matched. A mask
|
|
|
cd1737 |
+is provided by following the value with a slash and then the mask. If the mask
|
|
|
cd1737 |
+is missing then a match on all bits is assumed.
|
|
|
cd1737 |
+.TP
|
|
|
cd1737 |
+.BI ip_ttl " MASKED_IP_TTL"
|
|
|
cd1737 |
+Match on ipv4 TTL or ipv6 hop-limit - eight bits value in decimal or hexadecimal format.
|
|
|
cd1737 |
+A mask may be optionally provided to limit the bits which are matched. Same
|
|
|
cd1737 |
+logic is used for the mask as with matching on ip_tos.
|
|
|
cd1737 |
+.TP
|
|
|
cd1737 |
.BI dst_ip " PREFIX"
|
|
|
cd1737 |
.TQ
|
|
|
cd1737 |
.BI src_ip " PREFIX"
|
|
|
cd1737 |
diff --git a/tc/f_flower.c b/tc/f_flower.c
|
|
|
cd1737 |
index 1b6b46e..5be693a 100644
|
|
|
cd1737 |
--- a/tc/f_flower.c
|
|
|
cd1737 |
+++ b/tc/f_flower.c
|
|
|
cd1737 |
@@ -53,6 +53,8 @@ static void explain(void)
|
|
|
cd1737 |
" dst_mac MASKED-LLADDR |\n"
|
|
|
cd1737 |
" src_mac MASKED-LLADDR |\n"
|
|
|
cd1737 |
" ip_proto [tcp | udp | sctp | icmp | icmpv6 | IP-PROTO ] |\n"
|
|
|
cd1737 |
+ " ip_tos MASKED-IP_TOS |\n"
|
|
|
cd1737 |
+ " ip_ttl MASKED-IP_TTL |\n"
|
|
|
cd1737 |
" dst_ip PREFIX |\n"
|
|
|
cd1737 |
" src_ip PREFIX |\n"
|
|
|
cd1737 |
" dst_port PORT-NUMBER |\n"
|
|
|
cd1737 |
@@ -510,6 +512,41 @@ err:
|
|
|
cd1737 |
return err;
|
|
|
cd1737 |
}
|
|
|
cd1737 |
|
|
|
cd1737 |
+static int flower_parse_ip_tos_ttl(char *str, int key_type, int mask_type,
|
|
|
cd1737 |
+ struct nlmsghdr *n)
|
|
|
cd1737 |
+{
|
|
|
cd1737 |
+ char *slash;
|
|
|
cd1737 |
+ int ret, err = -1;
|
|
|
cd1737 |
+ __u8 tos_ttl;
|
|
|
cd1737 |
+
|
|
|
cd1737 |
+ slash = strchr(str, '/');
|
|
|
cd1737 |
+ if (slash)
|
|
|
cd1737 |
+ *slash = '\0';
|
|
|
cd1737 |
+
|
|
|
cd1737 |
+ ret = get_u8(&tos_ttl, str, 10);
|
|
|
cd1737 |
+ if (ret < 0)
|
|
|
cd1737 |
+ ret = get_u8(&tos_ttl, str, 16);
|
|
|
cd1737 |
+ if (ret < 0)
|
|
|
cd1737 |
+ goto err;
|
|
|
cd1737 |
+
|
|
|
cd1737 |
+ addattr8(n, MAX_MSG, key_type, tos_ttl);
|
|
|
cd1737 |
+
|
|
|
cd1737 |
+ if (slash) {
|
|
|
cd1737 |
+ ret = get_u8(&tos_ttl, slash + 1, 16);
|
|
|
cd1737 |
+ if (ret < 0)
|
|
|
cd1737 |
+ goto err;
|
|
|
cd1737 |
+ } else {
|
|
|
cd1737 |
+ tos_ttl = 0xff;
|
|
|
cd1737 |
+ }
|
|
|
cd1737 |
+ addattr8(n, MAX_MSG, mask_type, tos_ttl);
|
|
|
cd1737 |
+
|
|
|
cd1737 |
+ err = 0;
|
|
|
cd1737 |
+err:
|
|
|
cd1737 |
+ if (slash)
|
|
|
cd1737 |
+ *slash = '/';
|
|
|
cd1737 |
+ return err;
|
|
|
cd1737 |
+}
|
|
|
cd1737 |
+
|
|
|
cd1737 |
static int flower_parse_key_id(const char *str, int type, struct nlmsghdr *n)
|
|
|
cd1737 |
{
|
|
|
cd1737 |
int ret;
|
|
|
cd1737 |
@@ -665,6 +702,26 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
|
|
|
cd1737 |
fprintf(stderr, "Illegal \"ip_proto\"\n");
|
|
|
cd1737 |
return -1;
|
|
|
cd1737 |
}
|
|
|
cd1737 |
+ } else if (matches(*argv, "ip_tos") == 0) {
|
|
|
cd1737 |
+ NEXT_ARG();
|
|
|
cd1737 |
+ ret = flower_parse_ip_tos_ttl(*argv,
|
|
|
cd1737 |
+ TCA_FLOWER_KEY_IP_TOS,
|
|
|
cd1737 |
+ TCA_FLOWER_KEY_IP_TOS_MASK,
|
|
|
cd1737 |
+ n);
|
|
|
cd1737 |
+ if (ret < 0) {
|
|
|
cd1737 |
+ fprintf(stderr, "Illegal \"ip_tos\"\n");
|
|
|
cd1737 |
+ return -1;
|
|
|
cd1737 |
+ }
|
|
|
cd1737 |
+ } else if (matches(*argv, "ip_ttl") == 0) {
|
|
|
cd1737 |
+ NEXT_ARG();
|
|
|
cd1737 |
+ ret = flower_parse_ip_tos_ttl(*argv,
|
|
|
cd1737 |
+ TCA_FLOWER_KEY_IP_TTL,
|
|
|
cd1737 |
+ TCA_FLOWER_KEY_IP_TTL_MASK,
|
|
|
cd1737 |
+ n);
|
|
|
cd1737 |
+ if (ret < 0) {
|
|
|
cd1737 |
+ fprintf(stderr, "Illegal \"ip_ttl\"\n");
|
|
|
cd1737 |
+ return -1;
|
|
|
cd1737 |
+ }
|
|
|
cd1737 |
} else if (matches(*argv, "dst_ip") == 0) {
|
|
|
cd1737 |
NEXT_ARG();
|
|
|
cd1737 |
ret = flower_parse_ip_addr(*argv, vlan_ethtype ?
|
|
|
cd1737 |
@@ -963,6 +1020,19 @@ static void flower_print_ip_proto(FILE *f, __u8 *p_ip_proto,
|
|
|
cd1737 |
*p_ip_proto = ip_proto;
|
|
|
cd1737 |
}
|
|
|
cd1737 |
|
|
|
cd1737 |
+static void flower_print_ip_attr(FILE *f, char *name,
|
|
|
cd1737 |
+ struct rtattr *key_attr,
|
|
|
cd1737 |
+ struct rtattr *mask_attr)
|
|
|
cd1737 |
+{
|
|
|
cd1737 |
+ if (!key_attr)
|
|
|
cd1737 |
+ return;
|
|
|
cd1737 |
+
|
|
|
cd1737 |
+ fprintf(f, "\n %s %x", name, rta_getattr_u8(key_attr));
|
|
|
cd1737 |
+ if (!mask_attr)
|
|
|
cd1737 |
+ return;
|
|
|
cd1737 |
+ fprintf(f, "/%x", rta_getattr_u8(mask_attr));
|
|
|
cd1737 |
+}
|
|
|
cd1737 |
+
|
|
|
cd1737 |
static void flower_print_matching_flags(FILE *f, char *name,
|
|
|
cd1737 |
enum flower_matching_flags type,
|
|
|
cd1737 |
struct rtattr *attr,
|
|
|
cd1737 |
@@ -1150,6 +1220,11 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
|
|
|
cd1737 |
flower_print_eth_type(f, ð_type, tb[TCA_FLOWER_KEY_ETH_TYPE]);
|
|
|
cd1737 |
flower_print_ip_proto(f, &ip_proto, tb[TCA_FLOWER_KEY_IP_PROTO]);
|
|
|
cd1737 |
|
|
|
cd1737 |
+ flower_print_ip_attr(f, "ip_tos", tb[TCA_FLOWER_KEY_IP_TOS],
|
|
|
cd1737 |
+ tb[TCA_FLOWER_KEY_IP_TOS_MASK]);
|
|
|
cd1737 |
+ flower_print_ip_attr(f, "ip_ttl", tb[TCA_FLOWER_KEY_IP_TTL],
|
|
|
cd1737 |
+ tb[TCA_FLOWER_KEY_IP_TTL_MASK]);
|
|
|
cd1737 |
+
|
|
|
cd1737 |
flower_print_ip_addr(f, "dst_ip", eth_type,
|
|
|
cd1737 |
tb[TCA_FLOWER_KEY_IPV4_DST],
|
|
|
cd1737 |
tb[TCA_FLOWER_KEY_IPV4_DST_MASK],
|
|
|
cd1737 |
--
|
|
|
cd1737 |
1.8.3.1
|
|
|
cd1737 |
|