naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

Blame SOURCES/0124-tc-flower-Allow-_mac-options-to-accept-a-mask.patch

4aca6e
From b4c8e306b3e226076d12128aae38ca94e9eb69be Mon Sep 17 00:00:00 2001
4aca6e
From: Phil Sutter <psutter@redhat.com>
4aca6e
Date: Fri, 17 Mar 2017 13:23:54 +0100
4aca6e
Subject: [PATCH] tc: flower: Allow *_mac options to accept a mask
4aca6e
4aca6e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1422629
4aca6e
Upstream Status: iproute2.git commit c2078f8dc48c5
4aca6e
4aca6e
commit c2078f8dc48c572a5016c79c3a2a878b6e39e8ee
4aca6e
Author: Simon Horman <simon.horman@netronome.com>
4aca6e
Date:   Fri Dec 16 14:54:37 2016 +0100
4aca6e
4aca6e
    tc: flower: Allow *_mac options to accept a mask
4aca6e
4aca6e
    * The argument to src_mac and dst_mac may now take an optional mask
4aca6e
      to limit the scope of matching.
4aca6e
    * This address is is documented as a LLADDR in keeping with ip-link(8).
4aca6e
    * The formats accepted match those already output when dumping flower
4aca6e
      filters from the kernel.
4aca6e
4aca6e
    Example of use of LLADDR with and without a mask:
4aca6e
4aca6e
    tc qdisc add dev eth0 ingress
4aca6e
    tc filter add dev eth0 protocol ip parent ffff: flower indev eth0 \
4aca6e
            src_mac 52:54:01:00:00:00/ff:ff:00:00:00:01 action drop
4aca6e
    tc filter add dev eth0 protocol ip parent ffff: flower indev eth0 \
4aca6e
            src_mac 52:54:00:00:00:00/23 action drop
4aca6e
    tc filter add dev eth0 protocol ip parent ffff: flower indev eth0 \
4aca6e
            src_mac 52:54:00:00:00:00 action drop
4aca6e
4aca6e
    Signed-off-by: Simon Horman <simon.horman@netronome.com>
4aca6e
---
4aca6e
 man/man8/tc-flower.8 | 13 +++++++++----
4aca6e
 tc/f_flower.c        | 43 ++++++++++++++++++++++++++++++++++++-------
4aca6e
 2 files changed, 45 insertions(+), 11 deletions(-)
4aca6e
4aca6e
diff --git a/man/man8/tc-flower.8 b/man/man8/tc-flower.8
4aca6e
index 3841ff2..3310496 100644
4aca6e
--- a/man/man8/tc-flower.8
4aca6e
+++ b/man/man8/tc-flower.8
4aca6e
@@ -22,7 +22,7 @@ flower \- flow based traffic control filter
4aca6e
 .BR skip_sw " | " skip_hw
4aca6e
 .R " | { "
4aca6e
 .BR dst_mac " | " src_mac " } "
4aca6e
-.IR mac_address " | "
4aca6e
+.IR MASKED_LLADDR " | "
4aca6e
 .B vlan_id
4aca6e
 .IR VID " | "
4aca6e
 .B vlan_prio
4aca6e
@@ -74,10 +74,15 @@ filter, or TC offload is not enabled for the interface, operation will fail.
4aca6e
 .BI skip_hw
4aca6e
 Do not process filter by hardware.
4aca6e
 .TP
4aca6e
-.BI dst_mac " mac_address"
4aca6e
+.BI dst_mac " MASKED_LLADDR"
4aca6e
 .TQ
4aca6e
-.BI src_mac " mac_address"
4aca6e
-Match on source or destination MAC address.
4aca6e
+.BI src_mac " MASKED_LLADDR"
4aca6e
+Match on source or destination MAC address.  A mask may be optionally
4aca6e
+provided to limit the bits of the address which are matched. A mask is
4aca6e
+provided by following the address with a slash and then the mask. It may be
4aca6e
+provided in LLADDR format, in which case it is a bitwise mask, or as a
4aca6e
+number of high bits to match. If the mask is missing then a match on all
4aca6e
+bits is assumed.
4aca6e
 .TP
4aca6e
 .BI vlan_id " VID"
4aca6e
 Match on vlan tag id.
4aca6e
diff --git a/tc/f_flower.c b/tc/f_flower.c
4aca6e
index 5d93568..2774905 100644
4aca6e
--- a/tc/f_flower.c
4aca6e
+++ b/tc/f_flower.c
4aca6e
@@ -45,8 +45,8 @@ static void explain(void)
4aca6e
 		"                       vlan_id VID |\n"
4aca6e
 		"                       vlan_prio PRIORITY |\n"
4aca6e
 		"                       vlan_ethtype [ ipv4 | ipv6 | ETH-TYPE ] |\n"
4aca6e
-		"                       dst_mac MAC-ADDR |\n"
4aca6e
-		"                       src_mac MAC-ADDR |\n"
4aca6e
+		"                       dst_mac MASKED-LLADDR |\n"
4aca6e
+		"                       src_mac MASKED-LLADDR |\n"
4aca6e
 		"                       ip_proto [tcp | udp | sctp | icmp | icmpv6 | IP-PROTO ] |\n"
4aca6e
 		"                       dst_ip PREFIX |\n"
4aca6e
 		"                       src_ip PREFIX |\n"
4aca6e
@@ -58,6 +58,7 @@ static void explain(void)
4aca6e
 		"                       enc_src_ip [ IPV4-ADDR | IPV6-ADDR ] |\n"
4aca6e
 		"                       enc_key_id [ KEY-ID ] }\n"
4aca6e
 		"       FILTERID := X:Y:Z\n"
4aca6e
+		"       MASKED_LLADDR := { LLADDR | LLADDR/MASK | LLADDR/BITS }\n"
4aca6e
 		"       ACTION-SPEC := ... look at individual actions\n"
4aca6e
 		"\n"
4aca6e
 		"NOTE: CLASSID, IP-PROTO are parsed as hexadecimal input.\n"
4aca6e
@@ -68,16 +69,44 @@ static void explain(void)
4aca6e
 static int flower_parse_eth_addr(char *str, int addr_type, int mask_type,
4aca6e
 				 struct nlmsghdr *n)
4aca6e
 {
4aca6e
-	int ret;
4aca6e
-	char addr[ETH_ALEN];
4aca6e
+	int ret, err = -1;
4aca6e
+	char addr[ETH_ALEN], *slash;
4aca6e
+
4aca6e
+	slash = strchr(str, '/');
4aca6e
+	if (slash)
4aca6e
+		*slash = '\0';
4aca6e
 
4aca6e
 	ret = ll_addr_a2n(addr, sizeof(addr), str);
4aca6e
 	if (ret < 0)
4aca6e
-		return -1;
4aca6e
+		goto err;
4aca6e
 	addattr_l(n, MAX_MSG, addr_type, addr, sizeof(addr));
4aca6e
-	memset(addr, 0xff, ETH_ALEN);
4aca6e
+
4aca6e
+	if (slash) {
4aca6e
+		unsigned bits;
4aca6e
+
4aca6e
+		if (!get_unsigned(&bits, slash + 1, 10)) {
4aca6e
+			uint64_t mask;
4aca6e
+
4aca6e
+			/* Extra 16 bit shift to push mac address into
4aca6e
+			 * high bits of uint64_t
4aca6e
+			 */
4aca6e
+			mask = htonll(0xffffffffffffULL << (16 + 48 - bits));
4aca6e
+			memcpy(addr, &mask, ETH_ALEN);
4aca6e
+		} else {
4aca6e
+			ret = ll_addr_a2n(addr, sizeof(addr), slash + 1);
4aca6e
+			if (ret < 0)
4aca6e
+				goto err;
4aca6e
+		}
4aca6e
+	} else {
4aca6e
+		memset(addr, 0xff, ETH_ALEN);
4aca6e
+	}
4aca6e
 	addattr_l(n, MAX_MSG, mask_type, addr, sizeof(addr));
4aca6e
-	return 0;
4aca6e
+
4aca6e
+	err = 0;
4aca6e
+err:
4aca6e
+	if (slash)
4aca6e
+		*slash = '/';
4aca6e
+	return err;
4aca6e
 }
4aca6e
 
4aca6e
 static int flower_parse_vlan_eth_type(char *str, __be16 eth_type, int type,
4aca6e
-- 
4aca6e
1.8.3.1
4aca6e