From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2052.outbound.protection.outlook.com [40.107.102.52]) (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 7BE39313281 for ; Mon, 8 Sep 2025 16:43:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.52 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757349805; cv=fail; b=BH4sCG6KJaSMN4pkzO3R98aEPSOZgaeQyFrSQoDkhE7UrGhDfNIRmn/fqjq/h9pW3Xcz72XMKGiAIRR+tScWSvq4VUqit1Cy/ctcWHyOzZQmHra+wi9yDKHaoQCdqMhACNI2YnNR1T5xEJ3ZiEJFYScWVNBR+98hXr3SURC9KTQ= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757349805; c=relaxed/simple; bh=IxhzmhUJUIg9ahpc5nlveZsoODl2R8aVCGqTTNfaHZo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WqpSNPUIKkD3oiP+zSug+IYfrvpn8lweGOkm4CGa/bm7PgG2pAA02LB68/uhr63Fvz0oWxiO5muMLXKM1t23I7+M+c52DByNCM5whSiHv9x48XJHE2KvYxHFVLM/O/YuDzeTbKwxlqsFYP8hD8YMwHAnKUe+TnH3x+zcOIA7Kjo= 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=E6ZTIzOq; arc=fail smtp.client-ip=40.107.102.52 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="E6ZTIzOq" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=No+WEFanct2mnHSJSpH6gcrwXDkI5BV7avrohrH27kwyO/eQV1dmlft6botyaS9bKKyNsiOB+xjjXJpPSbEWJpuk+P9P5p4eHYbI2Fr/LnHcIMK5ogCwqCzncSOJwvb0r7JcYQyEXgF2hmKBIAelt1dwppUGWnfup9DcVbSI3HGvXv6HzNW1OULEkbw05QXxl/6fA0l7uQr9gFbuyR6NBnf0zIltjgHF5K88tDtxt129fU4MDuGlASieW8U7h+IL6gA3hlGDW6JP6iR+JMCIij0UoRC5xMB5zAdkOvMOexlfylGOi6Gek1Uy3e5z9k4S9wRwURsNq/m3suIni++yGg== 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=c7qYr+3ZtFBgzb6Hp2KinvxCxxFRk8CwgyTOpo38L/g=; b=rkj8PnXtRVzviYuyqCwUPtIlOGJCYmmZIR2rqe/BVF4LZyzR0pHkP69cMxae33UlRkVZvVbJrkHt/Atl/K3DkQEREZ6DquYezM9qTtMIhRaKL12A8U8F2eeijaV3m0RIMxpl5K2w/zKmEsBMEmunegPjOt+369UyICt3g1mLkVR8Rq8ie0HzbEWtirFkwoTNscvb0ffpAlRuhIOwpwMQnnyMYAB/ptVUfrkpUccD7cGEtThpp+TJx0KGb7rXEKQXFC7fQpvGChIzVShCejTPBPOyme851QeN/+rkI7hyoGXZlnJSLEN/kd5qgMgq4yiDp0DowWraW00Taz0ffMeHAw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) 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=c7qYr+3ZtFBgzb6Hp2KinvxCxxFRk8CwgyTOpo38L/g=; b=E6ZTIzOqXt5hD6rVS/5hatAhDdQ0zcZ4TE5CalWvigGzG6HCRijET2iiGw4ZfCyfn9F42pqTiU+BCnyHA1tm/PPGQhpfGzFGO/2tOtS01LPAtiL43XpJzHHzNzobogiExPFv8+sJJAZSf7EhWf2Kh0Zau/ZyFQxJjjkjVKODsZ1Q/KtD2XBGcQ4n5etf2/MMpuXHM82iuq4LLz3MwqQtjgXvmMEeCxVAvgodRVjs4SuT6/MrcUuwM4Yrucb6CK+TSMTAVsuSVcK1BTJCz2WITz3cjcF7xOna8UOIKmSXiEP8iSLKNGrFmCvCCqKjE8yFrcTxZaVbXck84SNPwD+r2Q== Received: from SJ0PR03CA0125.namprd03.prod.outlook.com (2603:10b6:a03:33c::10) by IA1PR12MB6435.namprd12.prod.outlook.com (2603:10b6:208:3ad::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9094.22; Mon, 8 Sep 2025 16:43:17 +0000 Received: from CO1PEPF000044F1.namprd05.prod.outlook.com (2603:10b6:a03:33c:cafe::ad) by SJ0PR03CA0125.outlook.office365.com (2603:10b6:a03:33c::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9094.22 via Frontend Transport; Mon, 8 Sep 2025 16:43:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by CO1PEPF000044F1.mail.protection.outlook.com (10.167.241.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.13 via Frontend Transport; Mon, 8 Sep 2025 16:43:16 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 8 Sep 2025 09:42:46 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 8 Sep 2025 09:42:45 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Mon, 8 Sep 2025 09:42:45 -0700 From: Daniel Jurgens To: , , , , , CC: , , , "Daniel Jurgens" Subject: [PATCH net-next v2 10/11] virtio_net: Add support for TCP and UDP ethtool rules Date: Mon, 8 Sep 2025 11:40:45 -0500 Message-ID: <20250908164046.25051-11-danielj@nvidia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250908164046.25051-1-danielj@nvidia.com> References: <20250908164046.25051-1-danielj@nvidia.com> Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev 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: CO1PEPF000044F1:EE_|IA1PR12MB6435:EE_ X-MS-Office365-Filtering-Correlation-Id: 221a8d83-7ace-44ce-73e4-08ddeef6cf70 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?7nm1Hs7Iv0MuZC/xX0Vyi+iviT4QmuRSQgPQiJwo6n6dhnIwWDaCqMMCOIi+?= =?us-ascii?Q?W3utMKnKh1AW9xPHj9dS1082ldrP1OgMjZf3zZ5ZGPN+ayueTIeLs0C1qGsT?= =?us-ascii?Q?55GY3cWw2j5WLp9qF3IImp0ukkDwHd4tJrxx4QhD8eapgs84yzGAVS47dgRV?= =?us-ascii?Q?shGgm28MlL2TSGM4lktx4Cbt9YJE6V1m3fW2Bb1w/BmF5fIj2z6z17S7fC8/?= =?us-ascii?Q?H5EOj8nJZrYWL9751fq/RGwVKKbp8P1NzckgxHYBxUslyEkEOZZtiqp9vvdJ?= =?us-ascii?Q?yk9YTzUggfjCtGBimGD5f/xK34cdz+8nAYvxuLA8GntI94ym2gb/GpITeOOa?= =?us-ascii?Q?kjXd3eVmPnjwhxSrm2yJ7EiARiPL/ftYcFXrOoD6vLNVUCVoLCGeIo+o39sL?= =?us-ascii?Q?kMSwMw7mMm5vZEhU7WfbAo1PjbIAV2HZExos4aq1W78TBg8NpTEG5Mv+S2JK?= =?us-ascii?Q?Wmke22CmRX2cPmwRRVHn72Ma5bqFp7pLGis7Lxsa4V2SVLatLaem7e0ylPYd?= =?us-ascii?Q?IEGMOIdDLTCGPooMk4oidy4chW7F6Wr2OdQ8bc5YNem6mrog8/+UuktOfJOP?= =?us-ascii?Q?303fVF4XaMiQKMWcUn7l4hqXZkvdfs8cuaB/s2dtyBCLPsln1uzJ2NaHc2nZ?= =?us-ascii?Q?k6ofFZEYX2+wuOsWGUAurC+fP8jS4PUzBRSk+l4wT0fJsj5m0ZLylbnPNSoQ?= =?us-ascii?Q?kZW1EAFOUh1nAR7hqhLSZuFEtjEYLu0pwINLBTCO7XMFNp2x/nnDliojTu4Y?= =?us-ascii?Q?cZy5v+lEyYzP3rTUkzSJiXcv9Z0dMYPJa4mvfZKbCCWEG6/QeKJGl5np2scD?= =?us-ascii?Q?r9lbFh5m5O5nLK+BcqC/DLfl7/+KNl+R2HuabfthE07U+K9H349IJDTHpLOj?= =?us-ascii?Q?dsyu0iPNLumGl2uzRm7Z+ayWtDvkIXkhwi7SIKKoUjFg9FeToV2tvsshNhck?= =?us-ascii?Q?u6pQ2Ip9PPHho+4bRirUIJattoxd31W9f76owHT0pkg9lQKLmOqdFPvLm/Xd?= =?us-ascii?Q?x1CE+hp1AD1ZXKFfcf1vjQRAx8LQ3rF4oBcs1UnKDOJWzVqakKEGmaKQxwD0?= =?us-ascii?Q?ZJawfHYqVCV+PjZDHrvw04rrKdBRkurF3dOjNIxvkAqy1/IdGQAAbPld3CVM?= =?us-ascii?Q?Lz7leY+jSN4ddPXAgsv4UA29BSw7AhHP85BE7gAiimhoIpV/PDJUPLiPhoHC?= =?us-ascii?Q?+5JRDZeLC8JWkWnqqfon6v+Iz99JVlu91p2akIpkANMsCqSPFNikXmM/dcaK?= =?us-ascii?Q?9jl38w8rYJAQORnrJ2zRsftMT6Yll4E+89f6D0DhsEqnDvGClqlShDZxhaw2?= =?us-ascii?Q?4LcC5+6iPHZcdH3MJe9qH/Y4+g8qQkFByarovEBkpqD2+lPP2QIENp5chnZv?= =?us-ascii?Q?G3Z1I08cw0SLoqMyNy2G2wWpTtHy5C88pQoQllPQaIjBpbZjzFmnT2lwfB/h?= =?us-ascii?Q?XQzeQKIcpTIDPWsHP0kwcLvEJm3+/WIBZfkqxjm/AsjtEd3f/MxRjOLZoqZt?= =?us-ascii?Q?wROt2MCJ7GoEBaJj5Tnx0xov+l87gT6sE3KW?= X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Sep 2025 16:43:16.5580 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 221a8d83-7ace-44ce-73e4-08ddeef6cf70 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044F1.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6435 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 --- v2: ethtools->ethtool in commit message --- drivers/net/virtio_net/virtio_net_ff.c | 207 +++++++++++++++++++++++-- 1 file changed, 198 insertions(+), 9 deletions(-) diff --git a/drivers/net/virtio_net/virtio_net_ff.c b/drivers/net/virtio_net/virtio_net_ff.c index ce59fb36dae9..d4a34958cc42 100644 --- a/drivers/net/virtio_net/virtio_net_ff.c +++ b/drivers/net/virtio_net/virtio_net_ff.c @@ -146,6 +146,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) { @@ -163,11 +209,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) { @@ -209,12 +289,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, @@ -350,6 +444,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; } @@ -393,6 +491,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); + } done: *key_size = size; /* @@ -427,7 +531,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; @@ -438,21 +543,93 @@ static int setup_ip_key_mask(struct virtio_net_ff_selector *selector, selector->type = VIRTIO_NET_FF_MASK_TYPE_IPV6; selector->length = sizeof(struct ipv6hdr); - if (fs->h_u.usr_ip6_spec.l4_4_bytes || - fs->h_u.usr_ip6_spec.tclass) + if (num_hdrs == 2 && (fs->h_u.usr_ip6_spec.l4_4_bytes || + fs->h_u.usr_ip6_spec.tclass)) return -EOPNOTSUPP; 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.tos || - fs->h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4) + if (num_hdrs == 2 && + (fs->h_u.usr_ip4_spec.l4_4_bytes || + fs->h_u.usr_ip4_spec.tos || + fs->h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4)) return -EOPNOTSUPP; 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; @@ -495,6 +672,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; size_t key_size; int num_hdrs; u8 *key; @@ -528,9 +706,20 @@ static int build_and_insert(struct virtnet_ff *ff, if (num_hdrs == 1) goto validate; + key_offset = selector->length; + selector = next_selector(selector); + + err = setup_ip_key_mask(selector, key + key_offset, fs, num_hdrs); + if (err) + goto err_classifier; + + if (num_hdrs == 2) + goto validate; + + key_offset += selector->length; selector = next_selector(selector); - err = setup_ip_key_mask(selector, key + sizeof(struct ethhdr), fs); + err = setup_transport_key_mask(selector, key + key_offset, fs); if (err) goto err_classifier; -- 2.50.1