From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SJ2PR03CU001.outbound.protection.outlook.com (mail-westusazon11012017.outbound.protection.outlook.com [52.101.43.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCD2B42B759 for ; Wed, 21 Jan 2026 22:08:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.43.17 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769033323; cv=fail; b=ukV2hwMlkRoqz6w7Xm52/RWCIZr10Wbj4VaB9HKG+IF9vaiE66bPxMy3MAaF6js+R6TOdyv3s9Oafc1pGSLN+wOw5Yjchcpi1J1l3JU1mXK+NONWWvjLAkvdGKEGRNvzjgpuqppNmD0jikC0iRilo7WUUZIVTp1hta+mkmpGUQ4= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769033323; c=relaxed/simple; bh=LeP2JpmiXIOsVn/KRCASGin/ya20Wgb9BVULNDM3zeE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GNZIoi1S81FDFy4xUlfuASUujHGOnyMTviHHxCfTv9nto9XUUitmXRlFQgcTzYvk5jWfGdjZJ8Mwz6y5R5W+NKn+WfLPnCo6Ed2O/QQqYjeane7ym+5ogozS85H/aEcXwebN3FzyA6wkumCPAsd59n2kjnN9TaexijRDSuOZfQE= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=t/MeOSFB; arc=fail smtp.client-ip=52.101.43.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="t/MeOSFB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wgTdQb8PY8B9BUIEK2c5e5cFhqlIejHqzM4SybUJmtkXiHBTCq597B5gliAjoqF9g8u/pn0Sy3VYpgfrgyFwJdfufwtyLDsW6yV4mlNJ8N7PVhtKKZiEOnyEfQRVjU+n/0e39rV3h25wh+YFs8TwumH8M5eDfa3qseMgx8SU+MQtBfLOcrMT83Q96sdFyxawnr10Xwiscz3BZGut1ctPVvGnCwWzqPK/9LrQImTUp+XCBEBTYHYCjaS9YnqKvKsXikUGTr1UqjPUq2Pb9zYuRZyYhyjQdjgquupvPLlPz+sBoPnkmtQGlqNWjbv5QDudU4ZdGd2/JwIM/W4ietSIig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dBLo8ZRlZbQ+IygqLsc45GUi9Yc/U6Izc2TqErKasTo=; b=Zq88kOHG5Br12uReQINPFP8HGJ1rJm4Rg10zgaAaE99KVeZrA8tdevyoZddVW6uIO9Kz3USzw7pS9lHl9F04zMuIy73SOBSUQBSVnEzyYJcC/oMuRLMrJxuW2Al7bx3vwju2YkZkihAueW+35/Bst2qKi0teT/NBMAibgTIFZmDXR5lzT1SQE1IRPg4J6v9evdpxwwGzYLDjhdIftdRkdK+iRnS+Y4w5igJCEd6VCoN5kBC3QohAG+7V+fVjblIkleKLefBoWH1hUAkxxVbh2EsGVrOD7TO5ygaH50w9JHiEpyHgiIXMfNJRgawIe9pCcTKxI6UwhAGUtvgL/DZ0VQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dBLo8ZRlZbQ+IygqLsc45GUi9Yc/U6Izc2TqErKasTo=; b=t/MeOSFBf2qaEO9Jc3CZhEH8EeqNuvdkhEAeukIj8fQyfv0aIWMB/GeUIwZfrND6BRYxrHCBodrOMD31M3amGRxkGsBCgKc6zQY6BwPpIUKAQf67sj+dinJH8zChf0SMdmD0JJ2lM4oUHBhDmM17Cloy1Vr/YmL4zvMtCo5HVvHSFO9mYozFgLPgeMBJRlrtR/njgmQAJ70mUwwrTVza9L1e/CdmofNUF35pD0N7U5HT6cn7JEDPhLP+0h0qGG0LqgyMOkJ8xPXYsHfbSQzGQt767I0UjxKUJB3adN55/UjiyFGXtNlVID19p4J7dyTB6GsOjnjiAYJvDV03Dmvd5w== Received: from BL1PR13CA0195.namprd13.prod.outlook.com (2603:10b6:208:2be::20) by DM4PR12MB7646.namprd12.prod.outlook.com (2603:10b6:8:106::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.9; Wed, 21 Jan 2026 22:08:19 +0000 Received: from BL02EPF00021F6B.namprd02.prod.outlook.com (2603:10b6:208:2be:cafe::9a) by BL1PR13CA0195.outlook.office365.com (2603:10b6:208:2be::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9564.2 via Frontend Transport; Wed, 21 Jan 2026 22:08:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL02EPF00021F6B.mail.protection.outlook.com (10.167.249.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Wed, 21 Jan 2026 22:08:19 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 21 Jan 2026 14:07:55 -0800 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 21 Jan 2026 14:07:54 -0800 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 21 Jan 2026 14:07:53 -0800 From: Daniel Jurgens To: , , , CC: , , , , , , , , , , , "Daniel Jurgens" Subject: [PATCH net-next v16 11/12] virtio_net: Add support for TCP and UDP ethtool rules Date: Wed, 21 Jan 2026 16:06:51 -0600 Message-ID: <20260121220652.894364-12-danielj@nvidia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260121220652.894364-1-danielj@nvidia.com> References: <20260121220652.894364-1-danielj@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00021F6B:EE_|DM4PR12MB7646:EE_ X-MS-Office365-Filtering-Correlation-Id: ebbe95cf-7236-486e-e5cb-08de593995c2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?zY/fnYDaiN1RDwhr4z1HSDTCOs0pXO/FikWkQddP24j8vt+TXATq5xPSCDBD?= =?us-ascii?Q?uS25pjKvf2OPz9bQLH+NUfg+JzgPHqAAg6xCw099OvBY2022mSCLLxi+3IqC?= =?us-ascii?Q?GFsGVQFsmIwLzxhmwgt6s1KEG77ox2VpWW7S8qIWF9MLdfgS7QkZfKHylZdY?= =?us-ascii?Q?GvrAKWOxAToEsrsR3r5toqd7w1uSv8YSYCgZJ1tmlxVi7iDIqi+6pzLbGwWy?= =?us-ascii?Q?sJRfvUBmYMOGtyy4b5Mhovm2cj5/RIaOk4c2bOGvowHoEAMZskN74912h1x5?= =?us-ascii?Q?vqlLzOgm/5EA3E0xsODXR1xu6PuzwdBIKEefAbUSWiQZ1+6InBp7YP4Ab1bS?= =?us-ascii?Q?gB60UFJ+8petDd8O3b9bDGDFNBqtBBlxHA+po97+X/C4wD+mft5/y9lJU26o?= =?us-ascii?Q?gCXGn+mGtMsa5NuESsKRJ1RhDV4ZbtxnuuCU6HKfNAv3mJ97zhW+WfBSL3ih?= =?us-ascii?Q?4eGlslswTiMx4FD42Ztjtzd0s2Fi3V+DomINKNddf8g/noXDJ38fOo0Rfbcy?= =?us-ascii?Q?5AdiWfYduVz4YvTxni/f7WtIjjbJrz2XfInY+LNKG0x5UrNwsKcv2Zpmg0GN?= =?us-ascii?Q?omt6hv4RbKOgtvfuSUUoR0dc6f95lxwLerDPlhm4Q0zxnQ12UZ8mD9K0eAA7?= =?us-ascii?Q?cLFjOs02LRyBQBvYtuF/0DhKpe3GCvrvQmz/YdLedhDE4mjHgN3APEnMRmoG?= =?us-ascii?Q?Yf1Z/W0iwFE1TjBPZtSaCmLC8F9kLLKgvc1OhsbbpP/x8yWs8HMmNGak6ZBC?= =?us-ascii?Q?2yrSGn+Ffe5+QvJLaARYFupxofhdEfvIS7UX8mH/2FXq76aVpasDII0H1tE7?= =?us-ascii?Q?7E965nX+5q/efPQdbgV5aloltJ51RTIhjNwQOs+FWDkv1p8FiZEnfUS0iehE?= =?us-ascii?Q?3NOXuaoFn/Bg6mIO7wrJQbMgMLkArvdrpgsh3jWhWyZ1r1uIHc45wXwJ54wc?= =?us-ascii?Q?9wMoI1LzjIWhqVcrCm8D8D0r4v1UQM2Fo8IaawDag+h/IPpJcXpIX7+XcvGP?= =?us-ascii?Q?HCMASnKLPzbpXAL0KHhPdV9mhhqO5ahV6k2ZnqBhS90VVTCCsL2d0he4jsSx?= =?us-ascii?Q?JG/i/rmU03beNDVMRLb9V29Gv8qJOoIXHub5hoh5E74xu6DtRWGcfvSAaiuS?= =?us-ascii?Q?cpfd8z9bUAdG03CrGy7T95Z7V5YXvTCkq6I/V66aDn6c6JoTPdftnJ7lkAKZ?= =?us-ascii?Q?7ODRz5Yw3LR0cz5SooG8icfSyn+i7tQaAULHPOk1kEh02rlVF/vNBKrWN5+4?= =?us-ascii?Q?X1w5ueHxdEnorzTHG6lcXeYSACe0Jp2YOPMQ1H/5gMLYPKARErRJUiOuerKm?= =?us-ascii?Q?I1YqDIgUCSUya9nEbVC0elsA8rTGCU8lnaCmF6cNIX/CXH/87KuY9va4t44N?= =?us-ascii?Q?3hWSPZyG4PEkZFyUCPZDQdHgRbUuq+pmhxxdsb2O0HNXZPuVbKT/dgv7Yzfm?= =?us-ascii?Q?OzrfyGgSn2FYpCB/HAGGY/zgP3+GPaS8DIr0q6aXsGDPpaGl1cOwthy35/ki?= =?us-ascii?Q?arEPiePAOWWcnuIcuei02+WfKxj999x+rUv611BNTIRYNp9kjF5Bev9+2l1X?= =?us-ascii?Q?f6BAdw+Y5ZqmJ8NYMusoVS7H7yL/gW+H+fkpW5I82dYP8Dzbb3+8jmo3z7by?= =?us-ascii?Q?uNj7R28iAeuVCMz45qbriygSAvSBepiT2tOpETx+exYmxulbQ1to5ouVCFHk?= =?us-ascii?Q?AvgA8A=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(7416014)(376014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jan 2026 22:08:19.2043 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ebbe95cf-7236-486e-e5cb-08de593995c2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF00021F6B.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7646 Implement TCP and UDP V4/V6 ethtool flow types. Examples: $ ethtool -U ens9 flow-type udp4 dst-ip 192.168.5.2 dst-port\ 4321 action 20 Added rule with ID 4 This example directs IPv4 UDP traffic with the specified address and port to queue 20. $ ethtool -U ens9 flow-type tcp6 src-ip 2001:db8::1 src-port 1234 dst-ip\ 2001:db8::2 dst-port 4321 action 12 Added rule with ID 5 This example directs IPv6 TCP traffic with the specified address and port to queue 12. Signed-off-by: Daniel Jurgens Reviewed-by: Parav Pandit Reviewed-by: Shahar Shitrit Reviewed-by: Xuan Zhuo --- v4: (*num_hdrs)++ to ++(*num_hdrs) v12: - Refactor calculate_flow_sizes. MST - Refactor build_and_insert to remove goto validate. MST - Move parse_ip4/6 l3_mask check here. MST v14: - Add tcp and udp includes. MST - Don't set l3_mask in parse_ipv?. The field isn't in the tcpip?_spec structures. It's fine to remove since it is set explicitly in setup_ip_key_mask. Simon Hormon/Claude Code --- --- drivers/net/virtio_net.c | 221 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 207 insertions(+), 14 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 4878ade43ac1..1d95cc7d285c 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include @@ -5879,6 +5881,52 @@ static bool validate_ip6_mask(const struct virtnet_ff *ff, return true; } +static bool validate_tcp_mask(const struct virtnet_ff *ff, + const struct virtio_net_ff_selector *sel, + const struct virtio_net_ff_selector *sel_cap) +{ + bool partial_mask = !!(sel_cap->flags & VIRTIO_NET_FF_MASK_F_PARTIAL_MASK); + struct tcphdr *cap, *mask; + + cap = (struct tcphdr *)&sel_cap->mask; + mask = (struct tcphdr *)&sel->mask; + + if (mask->source && + !check_mask_vs_cap(&mask->source, &cap->source, + sizeof(cap->source), partial_mask)) + return false; + + if (mask->dest && + !check_mask_vs_cap(&mask->dest, &cap->dest, + sizeof(cap->dest), partial_mask)) + return false; + + return true; +} + +static bool validate_udp_mask(const struct virtnet_ff *ff, + const struct virtio_net_ff_selector *sel, + const struct virtio_net_ff_selector *sel_cap) +{ + bool partial_mask = !!(sel_cap->flags & VIRTIO_NET_FF_MASK_F_PARTIAL_MASK); + struct udphdr *cap, *mask; + + cap = (struct udphdr *)&sel_cap->mask; + mask = (struct udphdr *)&sel->mask; + + if (mask->source && + !check_mask_vs_cap(&mask->source, &cap->source, + sizeof(cap->source), partial_mask)) + return false; + + if (mask->dest && + !check_mask_vs_cap(&mask->dest, &cap->dest, + sizeof(cap->dest), partial_mask)) + return false; + + return true; +} + static bool validate_mask(const struct virtnet_ff *ff, const struct virtio_net_ff_selector *sel) { @@ -5896,11 +5944,45 @@ static bool validate_mask(const struct virtnet_ff *ff, case VIRTIO_NET_FF_MASK_TYPE_IPV6: return validate_ip6_mask(ff, sel, sel_cap); + + case VIRTIO_NET_FF_MASK_TYPE_TCP: + return validate_tcp_mask(ff, sel, sel_cap); + + case VIRTIO_NET_FF_MASK_TYPE_UDP: + return validate_udp_mask(ff, sel, sel_cap); } return false; } +static void set_tcp(struct tcphdr *mask, struct tcphdr *key, + __be16 psrc_m, __be16 psrc_k, + __be16 pdst_m, __be16 pdst_k) +{ + if (psrc_m) { + mask->source = psrc_m; + key->source = psrc_k; + } + if (pdst_m) { + mask->dest = pdst_m; + key->dest = pdst_k; + } +} + +static void set_udp(struct udphdr *mask, struct udphdr *key, + __be16 psrc_m, __be16 psrc_k, + __be16 pdst_m, __be16 pdst_k) +{ + if (psrc_m) { + mask->source = psrc_m; + key->source = psrc_k; + } + if (pdst_m) { + mask->dest = pdst_m; + key->dest = pdst_k; + } +} + static void parse_ip4(struct iphdr *mask, struct iphdr *key, const struct ethtool_rx_flow_spec *fs) { @@ -5942,12 +6024,26 @@ static void parse_ip6(struct ipv6hdr *mask, struct ipv6hdr *key, static bool has_ipv4(u32 flow_type) { - return flow_type == IP_USER_FLOW; + return flow_type == TCP_V4_FLOW || + flow_type == UDP_V4_FLOW || + flow_type == IP_USER_FLOW; } static bool has_ipv6(u32 flow_type) { - return flow_type == IPV6_USER_FLOW; + return flow_type == TCP_V6_FLOW || + flow_type == UDP_V6_FLOW || + flow_type == IPV6_USER_FLOW; +} + +static bool has_tcp(u32 flow_type) +{ + return flow_type == TCP_V4_FLOW || flow_type == TCP_V6_FLOW; +} + +static bool has_udp(u32 flow_type) +{ + return flow_type == UDP_V4_FLOW || flow_type == UDP_V6_FLOW; } static int setup_classifier(struct virtnet_ff *ff, @@ -6087,6 +6183,10 @@ static bool supported_flow_type(const struct ethtool_rx_flow_spec *fs) case ETHER_FLOW: case IP_USER_FLOW: case IPV6_USER_FLOW: + case TCP_V4_FLOW: + case TCP_V6_FLOW: + case UDP_V4_FLOW: + case UDP_V6_FLOW: return true; } @@ -6128,6 +6228,12 @@ static void calculate_flow_sizes(struct ethtool_rx_flow_spec *fs, size += sizeof(struct iphdr); else if (has_ipv6(fs->flow_type)) size += sizeof(struct ipv6hdr); + + if (has_tcp(fs->flow_type) || has_udp(fs->flow_type)) { + ++(*num_hdrs); + size += has_tcp(fs->flow_type) ? sizeof(struct tcphdr) : + sizeof(struct udphdr); + } } BUG_ON(size > 0xff); @@ -6167,7 +6273,8 @@ static void setup_eth_hdr_key_mask(struct virtio_net_ff_selector *selector, static int setup_ip_key_mask(struct virtio_net_ff_selector *selector, u8 *key, - const struct ethtool_rx_flow_spec *fs) + const struct ethtool_rx_flow_spec *fs, + int num_hdrs) { struct ipv6hdr *v6_m = (struct ipv6hdr *)&selector->mask; struct iphdr *v4_m = (struct iphdr *)&selector->mask; @@ -6179,27 +6286,99 @@ static int setup_ip_key_mask(struct virtio_net_ff_selector *selector, selector->length = sizeof(struct ipv6hdr); /* exclude tclass, it's not exposed properly struct ip6hdr */ - if (fs->h_u.usr_ip6_spec.l4_4_bytes || - fs->m_u.usr_ip6_spec.l4_4_bytes || - fs->h_u.usr_ip6_spec.tclass || + if (fs->h_u.usr_ip6_spec.tclass || fs->m_u.usr_ip6_spec.tclass || - fs->h_u.usr_ip6_spec.l4_proto || - fs->m_u.usr_ip6_spec.l4_proto) + (num_hdrs == 2 && (fs->h_u.usr_ip6_spec.l4_4_bytes || + fs->m_u.usr_ip6_spec.l4_4_bytes || + fs->h_u.usr_ip6_spec.l4_proto || + fs->m_u.usr_ip6_spec.l4_proto))) return -EINVAL; parse_ip6(v6_m, v6_k, fs); + + if (num_hdrs > 2) { + v6_m->nexthdr = 0xff; + if (has_tcp(fs->flow_type)) + v6_k->nexthdr = IPPROTO_TCP; + else + v6_k->nexthdr = IPPROTO_UDP; + } } else { selector->type = VIRTIO_NET_FF_MASK_TYPE_IPV4; selector->length = sizeof(struct iphdr); - if (fs->h_u.usr_ip4_spec.l4_4_bytes || - fs->h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4 || - fs->m_u.usr_ip4_spec.l4_4_bytes || - fs->m_u.usr_ip4_spec.ip_ver || - fs->m_u.usr_ip4_spec.proto) + if (num_hdrs == 2 && + (fs->h_u.usr_ip4_spec.l4_4_bytes || + fs->h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4 || + fs->m_u.usr_ip4_spec.l4_4_bytes || + fs->m_u.usr_ip4_spec.ip_ver || + fs->m_u.usr_ip4_spec.proto)) return -EINVAL; parse_ip4(v4_m, v4_k, fs); + + if (num_hdrs > 2) { + v4_m->protocol = 0xff; + if (has_tcp(fs->flow_type)) + v4_k->protocol = IPPROTO_TCP; + else + v4_k->protocol = IPPROTO_UDP; + } + } + + return 0; +} + +static int setup_transport_key_mask(struct virtio_net_ff_selector *selector, + u8 *key, + struct ethtool_rx_flow_spec *fs) +{ + struct tcphdr *tcp_m = (struct tcphdr *)&selector->mask; + struct udphdr *udp_m = (struct udphdr *)&selector->mask; + const struct ethtool_tcpip6_spec *v6_l4_mask; + const struct ethtool_tcpip4_spec *v4_l4_mask; + const struct ethtool_tcpip6_spec *v6_l4_key; + const struct ethtool_tcpip4_spec *v4_l4_key; + struct tcphdr *tcp_k = (struct tcphdr *)key; + struct udphdr *udp_k = (struct udphdr *)key; + + if (has_tcp(fs->flow_type)) { + selector->type = VIRTIO_NET_FF_MASK_TYPE_TCP; + selector->length = sizeof(struct tcphdr); + + if (has_ipv6(fs->flow_type)) { + v6_l4_mask = &fs->m_u.tcp_ip6_spec; + v6_l4_key = &fs->h_u.tcp_ip6_spec; + + set_tcp(tcp_m, tcp_k, v6_l4_mask->psrc, v6_l4_key->psrc, + v6_l4_mask->pdst, v6_l4_key->pdst); + } else { + v4_l4_mask = &fs->m_u.tcp_ip4_spec; + v4_l4_key = &fs->h_u.tcp_ip4_spec; + + set_tcp(tcp_m, tcp_k, v4_l4_mask->psrc, v4_l4_key->psrc, + v4_l4_mask->pdst, v4_l4_key->pdst); + } + + } else if (has_udp(fs->flow_type)) { + selector->type = VIRTIO_NET_FF_MASK_TYPE_UDP; + selector->length = sizeof(struct udphdr); + + if (has_ipv6(fs->flow_type)) { + v6_l4_mask = &fs->m_u.udp_ip6_spec; + v6_l4_key = &fs->h_u.udp_ip6_spec; + + set_udp(udp_m, udp_k, v6_l4_mask->psrc, v6_l4_key->psrc, + v6_l4_mask->pdst, v6_l4_key->pdst); + } else { + v4_l4_mask = &fs->m_u.udp_ip4_spec; + v4_l4_key = &fs->h_u.udp_ip4_spec; + + set_udp(udp_m, udp_k, v4_l4_mask->psrc, v4_l4_key->psrc, + v4_l4_mask->pdst, v4_l4_key->pdst); + } + } else { + return -EOPNOTSUPP; } return 0; @@ -6239,6 +6418,7 @@ static int build_and_insert(struct virtnet_ff *ff, struct virtio_net_ff_selector *selector; struct virtnet_classifier *c; size_t classifier_size; + size_t key_offset; int num_hdrs; u8 key_size; u8 *key; @@ -6271,11 +6451,24 @@ static int build_and_insert(struct virtnet_ff *ff, setup_eth_hdr_key_mask(selector, key, fs, num_hdrs); if (has_ipv4(fs->flow_type) || has_ipv6(fs->flow_type)) { + key_offset = selector->length; selector = next_selector(selector); - err = setup_ip_key_mask(selector, key + sizeof(struct ethhdr), fs); + err = setup_ip_key_mask(selector, key + key_offset, + fs, num_hdrs); if (err) goto err_classifier; + + if (has_udp(fs->flow_type) || has_tcp(fs->flow_type)) { + key_offset += selector->length; + selector = next_selector(selector); + + err = setup_transport_key_mask(selector, + key + key_offset, + fs); + if (err) + goto err_classifier; + } } err = validate_classifier_selectors(ff, classifier, num_hdrs); -- 2.50.1