From patchwork Wed Aug 14 12:52:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13763457 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2083.outbound.protection.outlook.com [40.107.95.83]) (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 24BF11AE039; Wed, 14 Aug 2024 12:53:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723640014; cv=fail; b=eiwvPu/X131kZgNSY200yvrdfiouoH8K9FxvcgAsJeVsDKpvQyPK2Sp2QPLKGVL/qDjpg02TqFdMEtngyznSzVbU3CDMVkIph6ykxXt0iGY4t5m26uJXUkUlweejc1KuBfYpKWokvkajU+IPfhPkDVwVsNPdfPxHsdNBkjA0SDs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723640014; c=relaxed/simple; bh=Lw2yEYq09oMkwm9UB6Kk0O7Wl7RjoHOSbXpRcsVFDqA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lhkRZ4nDi6F+NP+WnwSKmSCPxxSvUfbmegytiDTpheMxeSla8SM2LwWIBAjkdYDEvHTEQvpsKv09y3exhIp4VgZs2+Y702szm96ggq1Ite5MV+dRr9sINJwxkTWtKXGyXDhyn8wreu2PTg4DAkNkwJV0XmXJvaTnUe9X/az0tLw= 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=X68e3d8Y; arc=fail smtp.client-ip=40.107.95.83 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="X68e3d8Y" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JIO+I02nkL2xJijytrUjF2iIe0k2OYByqIJP320AkcIt3DaFpjAaOu8I5skx+FHEv3PAWHiLNtjt10fqUDPycUZ+Kh3q33K0Vx69FVYsqVVHs53CDCu9kG4cF5M5np1GGDSfDA3LMbyHJjZcwlzQ0hsJyRQb7ivgXu4/XDZjPvvPvfWEkViPFPaKJEE6Z0u3mFE2lsUgCvoWw87Xl8vaM2uaasL42wiBzQPodPP5wstfi2eVFWxoddbSxDA0I55cqAEBrZAfTrHwIkjygw+LOvz1C/MO7OxnDYBGGhQuLNWJM2c6NegZTFFrxB6xhAiMeoGyua61gRUii5C74n2fcQ== 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=RPsCXL2T94tERnfsJVNnKkP09hq5Voi6iU2WPn51Xpg=; b=n41OyusH4F3vk8xHBEzwk7EgwTMQ5WhSxXDQ4FRrOeAp1DE5RLj6dHFS9zdNb4AYjv8xx9XWvV3nxy/mxTz7v2W6l+n8jg/Hcw1G44g/FhjVRpm5dVDpSXRjs2R06cB5KWbfHwqSEe7q/GdSlIlG33hgT8bkHHCTKS8rPWahcybmLHCS15ya5nX1h8H1WnyJ2LA6qYWmOYvQCfkR8uEyT8r66Oe0bcWOlVP9Ar2yBocvSpuw+k+qfoX4YbwFGCOw44Y8ae2u8aD+h1bi02lpMKslOXmoqBOeoUcXCe0PuJFsdyK85UyjRX2XKotfTQ7/CnC3N33b69rDDtkqqhcBUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=RPsCXL2T94tERnfsJVNnKkP09hq5Voi6iU2WPn51Xpg=; b=X68e3d8YMN+6HfyqOvopgjU2X7gTQIAjho2EBEB226OGP+874MCi5wekzHXIiYxOFzcD7s9ltGkb61SGCtsbONKzlA0Yx6sGSvb24XwxRGDyHfr1ul0ASD9iW4wey2p8ziRDIEMoEWuZYBX2nE98L8DC3aUWu9r2hCFQmU2aUQcXDN0lpOYqn2k0YR3Hhx4YDCc00FJwHfjsLZSUFs8FGOT+RCP+MH68sJ76/mBm1D2yRn1hHVjqC4ki3AP5vwb9yqgxbfvE0+Eyw1/0xzNmWgyTFLDCGHEg+OavDuLi8Mmz4TrovJ04t9UHMLqahc6dKcDRKAFA4+o+2BPh64tQiA== Received: from BY5PR17CA0072.namprd17.prod.outlook.com (2603:10b6:a03:167::49) by CH3PR12MB8657.namprd12.prod.outlook.com (2603:10b6:610:172::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.23; Wed, 14 Aug 2024 12:53:22 +0000 Received: from SJ1PEPF00002323.namprd03.prod.outlook.com (2603:10b6:a03:167:cafe::3e) by BY5PR17CA0072.outlook.office365.com (2603:10b6:a03:167::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22 via Frontend Transport; Wed, 14 Aug 2024 12:53:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by SJ1PEPF00002323.mail.protection.outlook.com (10.167.242.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.19 via Frontend Transport; Wed, 14 Aug 2024 12:53:22 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 14 Aug 2024 05:53:07 -0700 Received: from shredder.lan (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 14 Aug 2024 05:53:01 -0700 From: Ido Schimmel To: , CC: , , , , , , , , , Ido Schimmel Subject: [PATCH net-next v2 1/3] ipv4: Mask upper DSCP bits and ECN bits in NETLINK_FIB_LOOKUP family Date: Wed, 14 Aug 2024 15:52:22 +0300 Message-ID: <20240814125224.972815-2-idosch@nvidia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240814125224.972815-1-idosch@nvidia.com> References: <20240814125224.972815-1-idosch@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00002323:EE_|CH3PR12MB8657:EE_ X-MS-Office365-Filtering-Correlation-Id: 3493249a-8135-4fd3-20e3-08dcbc60145b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: fvd1Fr/OtpXQjR8QQdjuFrEPMeVA/QrD+fcvZvTBBJ6oX7OTBaXsZk3/anla8lw2pMLlYJdMZoaJp3GPonOzLDXf4Fm68RveFETDNR91T1SHRHwVW2u4kZ4mpZArDbS1bud1L92IuTwGUBsJFNevXPWfAtfECAFL7VbtLyaHyv2mzaeHA//I7xo4RWEbBFd/zN1Q+DfYCjCzTzqQmZkKgNRqdUFvSVZm82/MmpHaM3JV7UMOnrrVowv4PBBVFc6OSlOk7mcrPrVQLT1YbxiCfgOiMBXJQiYzTGKGLddx4xcZJ+1s+IpYVyim9CQEK0HiD7xJW1rqZOG547exmAU3MMad1gDFWGom85Nr4jORyno6OIkCL3/wXvImgiF2RKq8qf2SzZm+0zORx8d/HNOnFOnt8bdbcgNuJrap/83QqSNMdrvXQrIne6NJ2uXpKKsCVf3WfgVhvvS6JCTVFopRRl8WVxesmeJjlqMKJ77GOhrvu+JwQDByzc9yyfCC6YSVvUvUxfP3aMCYJAFXJeZRMlVNMH0VtR20HBCrZbTHApO5BT02daWIiu467r9vP7HxPYUzZ07QtTcXO49hu8nHH0gOnu8vmnwMAjTVmv03P3JoczY5tOMcvoikZSNq4rJ9bZb5I7e1RC/dX6I3Fs61ndOZPrcqdOaAHQHuIqQWAOxUQEVRZ5ULrlkLvCvJCikOG32eXEnX9HrlWyfUpekdbDLqcWhlbUV2L7J24t16AMr0CSeUCZB3WlJ3YkQQ9VAmlPLk8zkqRgzctw10CLGYDP/fF16mrrevfQLGt51F1RuaQVq7kuDK9kjO2FOOe2dtGO9Bs9WYmW4QVopXTRxgsITPP1s8sXVZiZaLGWw4aRbX2mdmKIEn6rppybaoI+15uVJd1zCP1M/UtlCpL7r0JF2yyIIVwCcGZDXft3T0RIyeRRLg1KX95AJSma3U/UkVRN/zAtQNH46w2LVlVPjUe5UMftviWejWHM+Xt9kAoxM4zmAfwbn33+djzx9PN/YgzmAr2q6VcUN7A4OAhhZCErhHN7LMebgZbpLff65IT8vQRh9HaEWFoLOjymLqcsaXqRTTi4Vuq0P06dHkwlPCskMRKTMSwbFJYnturflfqscopY1RaxNlcepiQZGamRU+qk+Xq7h47KtUjdWp2XgnFEyXdpyWgKngKEqXQ0XyNMKKvPATCyQvY1yo+4HA1Nu1hwzGyyggHBVWS+D8QI1pTxk7A30XyGlx82UxMe551LLrQSw1/92xxoOBFwjRoT0efjV2bZKP5EBHe5YSha36/UArANdR+e3mNRXvXaDJOYSbMdx10/6Ez86iW5sa8B0hegF+RCo9nMtKWh0Kg8dAMPrqLGGPGrDO+mG2Nl6JbSkX6g6v5bTPDerZHhg2+MEaKJZTVEYvYveuPKeIfsj6/bCR2XXOv/9LyscYDvQTiOwBZT4T94KLGLAvDZpXMsUq X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2024 12:53:22.2604 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3493249a-8135-4fd3-20e3-08dcbc60145b 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00002323.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8657 X-Patchwork-Delegate: kuba@kernel.org The NETLINK_FIB_LOOKUP netlink family can be used to perform a FIB lookup according to user provided parameters and communicate the result back to user space. However, unlike other users of the FIB lookup API, the upper DSCP bits and the ECN bits of the DS field are not masked, which can result in the wrong result being returned. Solve this by masking the upper DSCP bits and the ECN bits using IPTOS_RT_MASK. The structure that communicates the request and the response is not exported to user space, so it is unlikely that this netlink family is actually in use [1]. [1] https://lore.kernel.org/netdev/ZpqpB8vJU%2FQ6LSqa@debian/ Signed-off-by: Ido Schimmel Reviewed-by: Guillaume Nault --- net/ipv4/fib_frontend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c index 7ad2cafb9276..da540ddb7af6 100644 --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -1343,7 +1343,7 @@ static void nl_fib_lookup(struct net *net, struct fib_result_nl *frn) struct flowi4 fl4 = { .flowi4_mark = frn->fl_mark, .daddr = frn->fl_addr, - .flowi4_tos = frn->fl_tos, + .flowi4_tos = frn->fl_tos & IPTOS_RT_MASK, .flowi4_scope = frn->fl_scope, }; struct fib_table *tb; From patchwork Wed Aug 14 12:52:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13763456 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2087.outbound.protection.outlook.com [40.107.223.87]) (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 430F71AED23; Wed, 14 Aug 2024 12:53:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723640014; cv=fail; b=st3uRtaVqyZf8Mm2rPtFaie7Rm73fl+h9Nv9U2wmZQw1OnRe+ro8tE1eeWFjtNKLSf37floSnUszVp01PpxtwXFUIgOVF3p3HNhs127JQx8JgAo+lo4mOTSn99rdLR/1HEbvUAF0r4jRe7aXP6o5NTlgEjq2Qj9R6tSvNHgq5og= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723640014; c=relaxed/simple; bh=YvgX64vkyPEAF6zL5FpfADD1/bxjqzeklhAZ3T1hjXU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cBEQeLEXGU/3GPq7jRpIEUeXLXK0MB7b5Tb3nAzJsAhPrRlDAqTnLR5SwIJtkrARvs5OwEDEf0MUfy8qaqoW0NvGkN13uHxSv2hJQpcfmpSOZOVjwdAUr5sjVAtNPONDV+VcKawW8H9kJ9iLo2xV52iK94ibX69lTc0XF3dENvc= 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=P1Itf9LI; arc=fail smtp.client-ip=40.107.223.87 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="P1Itf9LI" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fQ7ze5bGQN2EjE6V9ptrUmsLZ+/U/t+mJLCgrBFx72Qfl8dIVw2whK89S4KqnEw2tN/kg7v6QhWrEBp4748aqyc2XGGcsXveBikaOV+UurKHZCJDk3aQO0wyKGQWtw28nTU1y4861RRYWOemLhfhxJ4GE4Uzr/g43FMZNfC0H3J4dR/3iGxbT5SzpvIM7pB3tRE6d+r1vOyLq0H7bQ3437GosnJ0M5Xkev1HwfEjwnOwxBcpBVlpFrx088O8KDJMHKoj5dxek2se681fa0dbFjHf6aZtAYs7dkPZohzMjr2QRzb8+Lhgx8opMFEhBha1Cguy2ac7paHK5mydBY0CwQ== 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=wRsBs5jDqs8MqUdlQJAA/Q4OtgDzlwnf5u4Et3KEBY4=; b=QFVnUMbHIgeMysd4dPTa9WVRRUlWcM9upxbIOxB8bQgc9HL+G32PLZRW9rWbZWgN+5LdH9PYjulLuAsWqyyij2gHJP0XaYVZeiVhKk4Sxcw62S+cWwlhUIGLB6MOb0CIISJ77bDYDXbmMmHddzh2NQW/14Xj+yCj2wWtVAZVrQDKkYG2mDQx6p+My0rDKmJGYC02kbggI7Mnv0s0TxX712fxUYLvl8unqTg9/vJxxAT4N1sjBy2on/pLfDAiQdIqhysAY4DRBHRQMWx6onjCSF+NKm8fN23UK7ri6WkXpxPtjL/Gb1xJh5Bz6NzakYdIRbBRKTGXO3KK3jNVuPw/Xw== 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=wRsBs5jDqs8MqUdlQJAA/Q4OtgDzlwnf5u4Et3KEBY4=; b=P1Itf9LIg+6/OV5HQx1uXgOgyVcbNzpkXYWktYO2sSsfxgyvhq3CSqzKIYeJz7r+uQ2sjd8WorEFS4DUdYTFKWkjeWTcRZTwVMqfF0xymsyqJyPUqJMoPu86dydA5NqlSSmGwGQgOhsbkr98TDg1lCZ2jEt+64jKhw7NAJcgL03M263/gdBRD6dpWFN6IaqtyetWhDRDn5QXpHHOGmrPoGcBjH+XK7Cp0j/obZYByiLFXmCedzSnOtThCcm7SCU42aGRNyApzdYajZRAecVUhjKDuVtCdc5aON727YbAxagIvzY8y3ENtp+1+YxQNRTSQRa6ZIZ2atEPp1p4XriaJA== Received: from BN0PR07CA0012.namprd07.prod.outlook.com (2603:10b6:408:141::34) by IA0PR12MB7673.namprd12.prod.outlook.com (2603:10b6:208:435::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.24; Wed, 14 Aug 2024 12:53:25 +0000 Received: from BL02EPF0001A0FB.namprd03.prod.outlook.com (2603:10b6:408:141::4) by BN0PR07CA0012.outlook.office365.com (2603:10b6:408:141::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22 via Frontend Transport; Wed, 14 Aug 2024 12:53:25 +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 BL02EPF0001A0FB.mail.protection.outlook.com (10.167.242.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.19 via Frontend Transport; Wed, 14 Aug 2024 12:53:25 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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.1544.4; Wed, 14 Aug 2024 05:53:13 -0700 Received: from shredder.lan (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 14 Aug 2024 05:53:07 -0700 From: Ido Schimmel To: , CC: , , , , , , , , , Ido Schimmel Subject: [PATCH net-next v2 2/3] netfilter: nft_fib: Mask upper DSCP bits before FIB lookup Date: Wed, 14 Aug 2024 15:52:23 +0300 Message-ID: <20240814125224.972815-3-idosch@nvidia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240814125224.972815-1-idosch@nvidia.com> References: <20240814125224.972815-1-idosch@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A0FB:EE_|IA0PR12MB7673:EE_ X-MS-Office365-Filtering-Correlation-Id: c2ca16d2-4181-40aa-be47-08dcbc601619 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: 3u2fv8J7TZads5Eh7mc/upD3HolgkOwo/zG+O8AXLDiUJo2GkPrnpa/YSYKPprZgv+w1SFqvDv695Pur+xsGF0eSM2GgzYcw+jb17ENaslLnnAZ5hOBu9rJSWENYqPr899XCjhzilUvm8aLoaGiW1At52O4oYlvkEbFqoaCLz6SZ6RYhvvBQfpVbS3bxjy+K03K+eZquiduzrIMwqYqv9sLjTLYq9ihwjxkpTEh2LQQRQFiddLBz7NAWCfpvrVJF11yNl9KVFKuejwhDPZdjXTYNtfiCI++AdAMOwVs6WPtmL7hL5pN3rovLLvyAboNOnpEoUSPuMV4jw4c9tCb1WrTADNLMQg85R4xBtNs7VoJYFB0CK0KI9NqA1lE960kPpNcxGbaegGTzDX87vsTdt/L9CxyKBzXPYDo78dJcTlSND+DwSN0G67p9xKKblhcSR/sn3lbpEI9xjYFv+FwYWBjwGn5877y2V2rPpdMfs727/JdK1aPOiWfpD5KbYNQlMOB5EmOJxmPOjPLzJPPSZtgnNvS/jDyCRFOa3Qgy4Ku9Fn9sa5BDuIJ17fy7g9Zn/jK9MoDvpbTHS8q3MbDbq+Swb5iRv8JBGePqemRIDfs7Vmt0fgk4ms0gN+EcS9oOWzX8jx37RTin8ELVu6N6g9m+MIcIg1B5X20zmCaqmxWmI8yppKeoLKWk8ziZ09Afv3jKYvorEAoRrxO5lP0HklJ/LQrB2qDTnrpa9XSGvbLjz3SyZ9Ijwmtvs0JsjQBrXklr9g1IAlvXpJfvcrUrCMmeoOO2Tr+8BkjBwRjoMS1Y79QqTkQ9qJO8G11yLZ/OtNjKVgE1YuP35LCnjidapR5T+N2SJ0yuwb8ApD7U8W4g78gcj3AfwhHc68QBIicJ6YF+D2NCva0XQCAKjyrrwVwhK/N9GzPROvlq0zkmSQJmoRKfOpwx+EEt0VvHMNcRE3kNwEm2qAo25PEOUtwGQDYrKKL26oBV4O+TsI4gKkYNUANGfyOvOHkHQDK21mCmA0p4TKnhwqPESq7C8zYWlDKuGm+iMwqQ58Do6sQl0jpk3IgIeXEjcDAE8sWgtGAWrUKUOJ3N8YMe4C0bY3vkQYww8Tslou0BKHt3JNJjKe+6/cn8t2QwMO1GACMlRTSXku6O+q+D6fP938ToZvmfc94miz+FuYCPI00EszoB27vjL0234PraXjWV6sDhh1wiGGPc51ew/VTqSjjwmD+M2UeJBMfc/BEAcylnsfovNtxBlV7R5UX7As1twm/lPyx4ROr/XczqZbaCZaKitUrk14H9xw74iq/NoB4aLqSSEAwS1wyFFA+kd/K8sBCEzWSZSLX9odRUeWyjLBxsq8mwop6Y2Lk1cpmAH9s51sjf7OrAQEZ1efOqCfiA6YpCm6QwEBfNwcmXpy2kfKg5aNDwaBGZoQfD7laTmpUbq9qnZe7UUnBnwGvGQXtdk1F+mfyT 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: 14 Aug 2024 12:53:25.2029 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c2ca16d2-4181-40aa-be47-08dcbc601619 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: BL02EPF0001A0FB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7673 X-Patchwork-Delegate: kuba@kernel.org As part of its functionality, the nftables FIB expression module performs a FIB lookup, but unlike other users of the FIB lookup API, it does so without masking the upper DSCP bits. In particular, this differs from the equivalent iptables match ("rpfilter") that does mask the upper DSCP bits before the FIB lookup. Align the module to other users of the FIB lookup API and mask the upper DSCP bits using IPTOS_RT_MASK before the lookup. No regressions in nft_fib.sh: # ./nft_fib.sh PASS: fib expression did not cause unwanted packet drops PASS: fib expression did drop packets for 1.1.1.1 PASS: fib expression did drop packets for 1c3::c01d PASS: fib expression forward check with policy based routing Signed-off-by: Ido Schimmel Reviewed-by: Guillaume Nault --- net/ipv4/netfilter/nft_fib_ipv4.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/net/ipv4/netfilter/nft_fib_ipv4.c b/net/ipv4/netfilter/nft_fib_ipv4.c index 9eee535c64dd..df94bc28c3d7 100644 --- a/net/ipv4/netfilter/nft_fib_ipv4.c +++ b/net/ipv4/netfilter/nft_fib_ipv4.c @@ -22,8 +22,6 @@ static __be32 get_saddr(__be32 addr) return addr; } -#define DSCP_BITS 0xfc - void nft_fib4_eval_type(const struct nft_expr *expr, struct nft_regs *regs, const struct nft_pktinfo *pkt) { @@ -110,7 +108,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs, if (priv->flags & NFTA_FIB_F_MARK) fl4.flowi4_mark = pkt->skb->mark; - fl4.flowi4_tos = iph->tos & DSCP_BITS; + fl4.flowi4_tos = iph->tos & IPTOS_RT_MASK; if (priv->flags & NFTA_FIB_F_DADDR) { fl4.daddr = iph->daddr; From patchwork Wed Aug 14 12:52:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13763458 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2089.outbound.protection.outlook.com [40.107.100.89]) (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 32C5A1AE039; Wed, 14 Aug 2024 12:53:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723640025; cv=fail; b=kBmMnoqevqWdO2q6gM0iS4tjTc1QXjVEv9bpuKhR6xRPfaGRQ59Hi+nkbowwUwR0GBHv/Rj4J4ePUMjfG3ABAwz2eACdtYc+1yYrZsDBiZ3lWytN7U70UwaIcsXcvIQcLKNsQX7HcCOecNMdp4SrYxWyj9V/zKiV0UjVk4+NZs8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723640025; c=relaxed/simple; bh=3plnB6xqZRtwzBlAL2UeWAkg41a4SJz6bCPKDWvuPzc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KDUP0dga97gZyK9Kq42iOBIu68ryjIyXppB3QsyS/ifuEXVuHsh+LHSPsxFBKylrQJAQMT/eEzdPnT+y90AihOS7feAG9E1QnJ1/nJ55lcp+RnMpGKe1hB6s6pJsEAPVmxLclKe+2oS+S39y2l17JvmUWpg7XFnG6JMXXLl2KgM= 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=RmYGlHpr; arc=fail smtp.client-ip=40.107.100.89 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="RmYGlHpr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bPFNG60yTi53fBZRWr1otnQ2eEK+Ash3qosElOOYSxTplNQY7YyeZQHDZzzdeC9NK8aNjATvxX7J7vz4adZ+2RLibJwVtdR4PxGXKbxY1i9yxJH3gCEaSnJYcqVwB5YqHyLDnpT8u/SqK/hnmtYcaq1RRddAjhffxpOlUMxwPhIAjNNDQFCtWCz0o2tE7pEBuEUioTGMNr15HI9b2r7sMOl0IbzOEkCyRhH1cI63YCt2dRzYtrgsWPWN/osgcw+bMJzhfX8DlUuuxZr1Npy4KCWFTHQNrm8mIiF2FvNbVz5JSp0ga7NVFbj+58nPXpi3y/3GoRk5sw1w31Vf4Vm/tA== 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=xMfTB57IYat7gsejzQEfxKSVA+XOHdOW3uuLIo8KwKM=; b=busZzMARnuoZmmvCgSohD9uD3LAgDtaI5KZPZkY8bcE9uvphpz6v9wKf/r6XMWR4H6zipgyh8ZjqKjzT2/uWhiPnHITSQHseh4KNZy73dQGXwOQ9CqR1Xm2l3DH7WbCT0yA5EIXFHNh6cNipwoJ1SbKIWU4/pBXYtJEGePV8DArZnXhzUiPpEK6kLM2mjW0UBOGU8Z2fSWZlGbonWcGdKY77Z/mCkqZB/qsbCDnmFz/9Nz/u2PIkFNktDZPtilQ0vsxQTHAGpDQWxieXFx+IOHZbMZ2IPEpb1eWLhea9g3eYpHrUwLBGoC01AJsDVjOa+le3W8C7kapURSZLlEnLMg== 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=xMfTB57IYat7gsejzQEfxKSVA+XOHdOW3uuLIo8KwKM=; b=RmYGlHprRS7M9YvNFVG02d/9CyCIjSgEXvtUV3N9kAZmhSThZ3iPkpJdKWIH1HRRH/YQ0SM+rk9Qc4FTJuSzQfZ3UJKs6qh8yXHiw/5n7jhhKKfGeiUSjKFGvCCGHmvJ3qTtkcy2QY/pL9tEGnTRu1kZojjC+JXfREOxQsSzD0mv5d6Tp7WmJIHNdBJh5sO3yZyJbQaAek4f4g1Hpn2UusSjju2g6k/FBnou2vJS0szhthKl4H5iE5X6k7aEZLfhVNYuzqLKU5cI+FIl1HPmYoDIYFC24fY2U2fT0/DyzrzNsje7zbZOuAb6AZjU8nEQdPf5rMWd2HT1QZB/JQ+TYg== Received: from BN8PR16CA0036.namprd16.prod.outlook.com (2603:10b6:408:4c::49) by DS0PR12MB7581.namprd12.prod.outlook.com (2603:10b6:8:13d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.18; Wed, 14 Aug 2024 12:53:38 +0000 Received: from BL02EPF0001A0FC.namprd03.prod.outlook.com (2603:10b6:408:4c:cafe::8d) by BN8PR16CA0036.outlook.office365.com (2603:10b6:408:4c::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22 via Frontend Transport; Wed, 14 Aug 2024 12:53:38 +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 BL02EPF0001A0FC.mail.protection.outlook.com (10.167.242.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.19 via Frontend Transport; Wed, 14 Aug 2024 12:53:37 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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.1544.4; Wed, 14 Aug 2024 05:53:19 -0700 Received: from shredder.lan (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 14 Aug 2024 05:53:13 -0700 From: Ido Schimmel To: , CC: , , , , , , , , , Ido Schimmel Subject: [PATCH net-next v2 3/3] ipv4: Centralize TOS matching Date: Wed, 14 Aug 2024 15:52:24 +0300 Message-ID: <20240814125224.972815-4-idosch@nvidia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240814125224.972815-1-idosch@nvidia.com> References: <20240814125224.972815-1-idosch@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A0FC:EE_|DS0PR12MB7581:EE_ X-MS-Office365-Filtering-Correlation-Id: 27d38872-a6bd-45b6-bf6f-08dcbc601da8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|7416014|376014; X-Microsoft-Antispam-Message-Info: HTbgyKLYmQvu2MAsSsaltB57ArU8IM3oWd2N4LtUdXSTGb7u1evXmi4g+2n+4o5UwDDhYZETA+sScxujUsQHItXiTTgEhKV9TbtTq1lo4ztfmaNTi1vNabG6EGLhgTUEPDDLd0tIa52mW78v6UBQDgyZZ9UwLdnU8KdwP1IUlcwGp04KvR0kenisVp1jym+8+2OJiAMd988YDv5d69bb9OGUCN0vKYvu8vJDBmIwp0TcnCxHpr87w3ihvMkJqzRPfJjJTz29meaEMVWE4G2YueBiFo0qK6Y7O4YgCGhTShoCzz3HIRHkyfHILj8PpwdEQ4puWH+S4wRFwCHiTzpguDJH3xNumFp8zIOqPp8iUniCCjd1wB4V5BcaQVN9G5mrd3J1X6wvCeMy0GEjAagDFaHZoJwDyO6RqQW4Ql6kxgxgA6g4Oet+GM4sNYsgqzBdPMg5jJvoJUlCPWY7vNCiWM37kjOGn75ph7f5IA+BDD5LbzUCMTyjvEya8I6Gd/SP1Ogj+ey9k9qnQ4CqlBywKV/m1XVfiuU+27eMJb34lLl3YhFQjd6DTERW/Hjc9CJDs9fpqVg5t6qhHUr15FJXkF1zPAsOgkjaHjgzkWc0hVdU9YQRRT1XPGJm7s91TH3LorXZJ3wZN+QwcNz1AYrF7EN7H25t1YC7KrFA+nafNaq5yqadLpuYkkvIpoF/V6Id5MRWS83ncuhtssxJArJ578nP6SZHw517kJBIdmk+PbbUwt3Irb8sFT4UWEvPB9ZcpLImr6oD+mVZgBLqjE63CAckOtthjDjAuY79zWr4uwNJhq8NsTRJ0FvpinHeUmUe4dGCRQNvng7BlTgSz0x2GvbcjHvxzxTSQctoclm8JiOgX8x1RXvx9zvCdpIY+DWlyVxwz5jBUFE9vEfcpfXgcc6mNGJFp3Q5iqfGPJoXWWWHEIkotnu9aqEYqNwUpQJZeLqnHxbWmg56ia7J1chTPplFxRJdpdTOiPrHwD7ofzLMjxFFsCLeGzakwUXKXBs9V0/k18f4VLmYEIrLxYmbhrElN8SoMDGIUuzaU/2NAVcJW8J0nis+Nb8muqTg5W6tdmH+wR714cIRHZaswLdgTPVK/5beHXcdF+4uZindX+rX0ccn2yZ4nbW4fy6U8Nv6f0VmOztuujTeUNQ2psGGS/tQJam6eDOQt0+6+6g9iR5oOcHUcMgy515FyIcUG0Lx5QcL5lAvU5zP3/T6OZcR8hw8SWSFH9chS2xc+bIAVpSl6skfVO3VffDJZYREWIs8T3V/nZOS9vFymBXHD2giCfNDrHfpYh0fBEVmXSyiQ2jzdaH/QM9cjY3nlUEHUt5UJWrTwg0uFlno7L45gDrNvdIfBdqWi7P7N1lm9lL+xOoQYa/fzWA2BdqfjwNFe1SoCC7jeJAuqwJNXqUGlAV+C868zjRBcVu1Cc84HsRoXR6FRfLK6jVL5qeE3kk20gdR 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)(36860700013)(1800799024)(82310400026)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2024 12:53:37.8217 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 27d38872-a6bd-45b6-bf6f-08dcbc601da8 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: BL02EPF0001A0FC.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7581 X-Patchwork-Delegate: kuba@kernel.org The TOS field in the IPv4 flow information structure ('flowi4_tos') is matched by the kernel against the TOS selector in IPv4 rules and routes. The field is initialized differently by different call sites. Some treat it as DSCP (RFC 2474) and initialize all six DSCP bits, some treat it as RFC 1349 TOS and initialize it using RT_TOS() and some treat it as RFC 791 TOS and initialize it using IPTOS_RT_MASK. What is common to all these call sites is that they all initialize the lower three DSCP bits, which fits the TOS definition in the initial IPv4 specification (RFC 791). Therefore, the kernel only allows configuring IPv4 FIB rules that match on the lower three DSCP bits which are always guaranteed to be initialized by all call sites: # ip -4 rule add tos 0x1c table 100 # ip -4 rule add tos 0x3c table 100 Error: Invalid tos. While this works, it is unlikely to be very useful. RFC 791 that initially defined the TOS and IP precedence fields was updated by RFC 2474 over twenty five years ago where these fields were replaced by a single six bits DSCP field. Extending FIB rules to match on DSCP can be done by adding a new DSCP selector while maintaining the existing semantics of the TOS selector for applications that rely on that. A prerequisite for allowing FIB rules to match on DSCP is to adjust all the call sites to initialize the high order DSCP bits and remove their masking along the path to the core where the field is matched on. However, making this change alone will result in a behavior change. For example, a forwarded IPv4 packet with a DS field of 0xfc will no longer match a FIB rule that was configured with 'tos 0x1c'. This behavior change can be avoided by masking the upper three DSCP bits in 'flowi4_tos' before comparing it against the TOS selectors in FIB rules and routes. Implement the above by adding a new function that checks whether a given DSCP value matches the one specified in the IPv4 flow information structure and invoke it from the three places that currently match on 'flowi4_tos'. Use RT_TOS() for the masking of 'flowi4_tos' instead of IPTOS_RT_MASK since the latter is not uAPI and we should be able to remove it at some point. Include in since the former defines IPTOS_TOS_MASK which is used in the definition of RT_TOS() in . No regressions in FIB tests: # ./fib_tests.sh [...] Tests passed: 218 Tests failed: 0 And FIB rule tests: # ./fib_rule_tests.sh [...] Tests passed: 116 Tests failed: 0 Signed-off-by: Ido Schimmel Reviewed-by: Guillaume Nault --- v2: Include in instead of including it in net/ip_fib.h --- include/net/ip_fib.h | 6 ++++++ include/uapi/linux/in_route.h | 2 ++ net/ipv4/fib_rules.c | 2 +- net/ipv4/fib_semantics.c | 3 +-- net/ipv4/fib_trie.c | 3 +-- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 72af2f223e59..269ec10f63e4 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -22,6 +22,7 @@ #include #include #include +#include struct fib_config { u8 fc_dst_len; @@ -434,6 +435,11 @@ static inline bool fib4_rules_early_flow_dissect(struct net *net, #endif /* CONFIG_IP_MULTIPLE_TABLES */ +static inline bool fib_dscp_masked_match(dscp_t dscp, const struct flowi4 *fl4) +{ + return dscp == inet_dsfield_to_dscp(RT_TOS(fl4->flowi4_tos)); +} + /* Exported by fib_frontend.c */ extern const struct nla_policy rtm_ipv4_policy[]; void ip_fib_init(void); diff --git a/include/uapi/linux/in_route.h b/include/uapi/linux/in_route.h index 0cc2c23b47f8..10bdd7e7107f 100644 --- a/include/uapi/linux/in_route.h +++ b/include/uapi/linux/in_route.h @@ -2,6 +2,8 @@ #ifndef _LINUX_IN_ROUTE_H #define _LINUX_IN_ROUTE_H +#include + /* IPv4 routing cache flags */ #define RTCF_DEAD RTNH_F_DEAD diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c index 5bdd1c016009..c26776b71e97 100644 --- a/net/ipv4/fib_rules.c +++ b/net/ipv4/fib_rules.c @@ -186,7 +186,7 @@ INDIRECT_CALLABLE_SCOPE int fib4_rule_match(struct fib_rule *rule, ((daddr ^ r->dst) & r->dstmask)) return 0; - if (r->dscp && r->dscp != inet_dsfield_to_dscp(fl4->flowi4_tos)) + if (r->dscp && !fib_dscp_masked_match(r->dscp, fl4)) return 0; if (rule->ip_proto && (rule->ip_proto != fl4->flowi4_proto)) diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index 2b57cd2b96e2..0f70341cb8b5 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -2066,8 +2066,7 @@ static void fib_select_default(const struct flowi4 *flp, struct fib_result *res) if (fa->fa_slen != slen) continue; - if (fa->fa_dscp && - fa->fa_dscp != inet_dsfield_to_dscp(flp->flowi4_tos)) + if (fa->fa_dscp && !fib_dscp_masked_match(fa->fa_dscp, flp)) continue; if (fa->tb_id != tb->tb_id) continue; diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index 8f30e3f00b7f..09e31757e96c 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c @@ -1580,8 +1580,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, if (index >= (1ul << fa->fa_slen)) continue; } - if (fa->fa_dscp && - inet_dscp_to_dsfield(fa->fa_dscp) != flp->flowi4_tos) + if (fa->fa_dscp && !fib_dscp_masked_match(fa->fa_dscp, flp)) continue; /* Paired with WRITE_ONCE() in fib_release_info() */ if (READ_ONCE(fi->fib_dead))