From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011041.outbound.protection.outlook.com [52.101.52.41]) (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 5AD9F23D7ED for ; Tue, 23 Sep 2025 14:20:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.41 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758637217; cv=fail; b=PPf+Yg0MGC+PzTVaNULXVdeAf2BCEHAyKDCgV+JIxx49Jsv9s3AIKhvtBkfGBz8PBIxhJkCvv6OF0iIly4zKmnDQdG915DP26U73c9PxoP4kIqO6DI1KuMDxEeFSV8jG0mV2Ct78IIefbkg/Sb/HJtFR74Qtrr4ufXNlY0LUsqo= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758637217; c=relaxed/simple; bh=nqYNvXWTc2RpfiqTWgXnfk4OyxE2uIKWIowMICzjtd8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DMTt763b3efOH1sAlttG9XkaSRKQDHXf39ZSjkm+d5xxL2KlFpyMN7VRV4bRQm5Fw4P2AucA+Qo8dIF8/3bpl74izX049CZnhAaR36l2NkT1k3/YU1Czwc+2lfeQA0Odz+1u2h6bLqZrk4H3zzRImXTZrlZk4Jtf6UbNYr97R4Y= 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=O/9wp09m; arc=fail smtp.client-ip=52.101.52.41 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="O/9wp09m" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OLcXD3XIaQFpIbVQeIstBQf+f2Fzozd0duCOEXMiPc7LWlw6/ndgxcfg3bMxIbiTO3vbEo1JYM3M4KfklS8hzlJqAjysdgJ6KGfbOAKrp6eBEAJqpfrXixxYDXiqR758i0UKmBZLUg3cyLFEZFuUYZfAtdBlOz455zzWiyt7jU9GAwCH7yWLisKWYCiU3M7wNgMjwIxnLzVj8q2nIRwDh6eQlawErt5Tkx1bIjMqagzQmW1cOJY3RsfT3/xMtoSWan78ooJx7dAHdjwldxFNLDer5WyzG1a+31yHQTek09F0c3ixcfAbcVW6vNwv/UAg7CPfnxePh+gxN7zFF4vGZQ== 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=AC4GkMg/Mt/ZJJ+2ZBZeAvhyoUd/2V6oIJGkLmZW0q4=; b=Uc2BJbHRvjI23XasbVtdN0t3BiGZR/Cjle5h89slSDXjzCeve587LQ/Y6KKfERkSxOsuP4VG4oBBGioIxzlEway7tSlu2fWVgUdUCroKXpeUlspZoegaBEUrm8ZqNOfM3G2D46egJ9Ow/ibqyg6g+Ba2C9cIPMfi0OD67LU441gBUb0cdMvg6fe2sdWtBuwrjvx2pzfILZ3KQT0Ruelbyt3MJS3Q/ePIsNu9P/NZ08XJROd2HB0h/cP9VLMTVmPupQ23MFVDX/nsF0e+RsxgtTrdfturuPd0r1njDB+ZjrVBRpTAN41P6Lr6YyW7xYoA7C7Js83+p3w8lp1kKBeqqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) 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=AC4GkMg/Mt/ZJJ+2ZBZeAvhyoUd/2V6oIJGkLmZW0q4=; b=O/9wp09mDt0AyFIlrVDjZiTkWIHfkznnYigBg3IeQBkWs/b+B53PeueFzW2jMoCLqvoPyJ+aTrugk++bG282wUSwgAaa4obGWm1x37VCgWJlCxU+9enFnPr7mQkjKTpC43/krFv4yXzybyr23xF/YZVBmcxG10q8pqiTE+3w5zt5VDxGsSpHc84KWfnVZrqAtwVtr70emz7w7FuRHLcxnfM/LQnC+aaHEyUzlfu5nSZC1cKO0KyrXd+s0/iLxaI3QqRb0+ocRmDgRe2iIQjDa6nZdOu3QXqKWwE/fENbc01bj6Yug2As1v2IT9Vut/LldPK95LoFEolvE1xAJMk6dw== Received: from SJ0PR05CA0088.namprd05.prod.outlook.com (2603:10b6:a03:332::33) by CY8PR12MB7753.namprd12.prod.outlook.com (2603:10b6:930:93::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9137.20; Tue, 23 Sep 2025 14:20:08 +0000 Received: from MWH0EPF000A6730.namprd04.prod.outlook.com (2603:10b6:a03:332:cafe::30) by SJ0PR05CA0088.outlook.office365.com (2603:10b6:a03:332::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9137.20 via Frontend Transport; Tue, 23 Sep 2025 14:20:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by MWH0EPF000A6730.mail.protection.outlook.com (10.167.249.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9137.12 via Frontend Transport; Tue, 23 Sep 2025 14:20:08 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Tue, 23 Sep 2025 07:19:49 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Tue, 23 Sep 2025 07:19:49 -0700 Received: from vdi.nvidia.com (10.127.8.13) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Tue, 23 Sep 2025 07:19:47 -0700 From: Daniel Jurgens To: , , , , CC: , , , , , , , , , , , , Daniel Jurgens Subject: [PATCH net-next v3 10/11] virtio_net: Add support for TCP and UDP ethtool rules Date: Tue, 23 Sep 2025 09:19:19 -0500 Message-ID: <20250923141920.283862-11-danielj@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20250923141920.283862-1-danielj@nvidia.com> References: <20250923141920.283862-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: MWH0EPF000A6730:EE_|CY8PR12MB7753:EE_ X-MS-Office365-Filtering-Correlation-Id: 38f2a326-a654-4651-14da-08ddfaac4c91 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|7416014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?7O5G2hKgTKP073Iw4ZqrazgrgAcyawbFnl/K+0zFC5q0lPshJ+AA6mnsCvVg?= =?us-ascii?Q?yDJc4egzOei/bgXX07e5P8nisNFDaj4VrS8IW7Oj8bu/h9e+v80XoNGAdVMO?= =?us-ascii?Q?1IG8gPghKTf5EN3OCbefzCRs7WmJvdSt/IEa76eHbobyCaZgKSYoYCMy+C/k?= =?us-ascii?Q?dKhIXYGrbCNv7M0h8OJ7csjK+ikqhz0Ka3FX2iVgcTrXiEOQX7YjfYnO3uiE?= =?us-ascii?Q?rSt40Gbg1Efo8f2f5MiXoqjHskoG//fMezgr2mhAdrGpaiuN3iueI4yf9Bxp?= =?us-ascii?Q?kZQW7RIn7qS1AOMaU9rG/OpRP2bnFUOBXcSHOJh6QdtXLm82CSv40pY2Iztz?= =?us-ascii?Q?DnlpxnS5AEw0cHpHlRAwswBSTXu49d/hRMEYs/VqkPjtIn2TthcvPqCf+DnV?= =?us-ascii?Q?K9vM16VEdzbMJHf7olxNOsxs8wAszjpuCfP3Fj2QaLFIVLUVWzyTsvfeP249?= =?us-ascii?Q?l336BixG5XKLw6MMU/9+cLJv0rnSQmtOCJeGvAw9LqF9bOSh3c77oT/cQWfP?= =?us-ascii?Q?8BKhj3j0a/usNeC0merY9EDmswxp1AOVZAzJ9zGX78UzBi3qNDF5VPCYv0TD?= =?us-ascii?Q?bgaY8Z/5R1sOXNM5bgryaRu0K1QVF9C3Qod43G4HhtdABQqMT7jKXSJcEgzC?= =?us-ascii?Q?YZxNmuu/QUE4BqVVnklntjSwkBdeS97uqfPZJkjXlpHJY6S+XMAHxHn0+Wlz?= =?us-ascii?Q?pQ/spDnFC/K3pl4770n0V5RfeUa9uCajbNpl4FFuNbq+8a0TTSl3x+r95XrZ?= =?us-ascii?Q?jojt1Za7qibmechsQNo5ATVlmUQ/qqgLQyM/Scu7bMILyNsAXE2wMvPdRWLF?= =?us-ascii?Q?N2xQX5PKowd6hQUnUoXXlrC9CQPNtKIqsI9FFhpM5SFxyFBUg6pPv3JIDUuT?= =?us-ascii?Q?mQlQYIAYkYNgTZRCL5z4iav5TFLIiN/+gqHCe7nJsKNcAAy87jZyHBzDG6vI?= =?us-ascii?Q?BsM8DgkqD6jhDYHygYS66cV7eiLuz3PI7JZfDwfESl1lR91EfwDDk3pD1ivs?= =?us-ascii?Q?CvAUOz3uRSDwAE/9ae9K2vlZbcSQ60mAHI8RCdBzzxvCUJBfRN+U2voftvle?= =?us-ascii?Q?zC78F5w42t5Kvqs+/oWCllRj3VubusB1IbJuNHkOaK+LxBynk4o3n+01/OIH?= =?us-ascii?Q?F4Xu0EpNBb7bMWICbS5kpEQHxgUw8OpSr6avgND1GJ2WXec4o/gQdBZiUyei?= =?us-ascii?Q?YyZmbhslR20+BaGK3KazpSpDQhSxI+NPzqpmYXf8ifNiTHPak52nQGjjwSGW?= =?us-ascii?Q?NqLspwWq4qaAL6RNobq7S50JxMyj3WHgVtPcTNO/kMl0e63YjGT6CK4/ocGX?= =?us-ascii?Q?om3Tr4MuaOISbzHjEfMC9jkqu041Bgp4y50VeKeaMsN6XAaoC7pAgAwPZgvr?= =?us-ascii?Q?y8WeY5tiRpYUU3hHvxSSbWZhye6CJtwoTBtMi7Dfuyi527cAAx8ksU0LTsnu?= =?us-ascii?Q?2NKzmKvLmw5fOv9v5J7iZ+SISa/xijzmXoALBOJxqeREtnkokl6qc6vZZWsw?= =?us-ascii?Q?3MMEQSpXd+MWQKkGFhjIl/u7E9+klOa46jRZ?= X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(376014)(7416014)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2025 14:20:08.1303 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 38f2a326-a654-4651-14da-08ddfaac4c91 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.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000A6730.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7753 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 --- 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.45.0