From patchwork Mon Jul 30 12:45:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 10549025 X-Patchwork-Delegate: idosch@idosch.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EDFD213B8 for ; Mon, 30 Jul 2018 12:45:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC04B296E2 for ; Mon, 30 Jul 2018 12:45:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF97629715; Mon, 30 Jul 2018 12:45:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 06CBE296E2 for ; Mon, 30 Jul 2018 12:45:36 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41fK6k1y2kzF153 for ; Mon, 30 Jul 2018 22:45:34 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="I6w1Cm/7"; dkim-atps=neutral X-Original-To: linux-mlxsw@lists.ozlabs.org Delivered-To: linux-mlxsw@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=mellanox.com (client-ip=40.107.4.59; helo=eur03-db5-obe.outbound.protection.outlook.com; envelope-from=petrm@mellanox.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="I6w1Cm/7"; dkim-atps=neutral Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40059.outbound.protection.outlook.com [40.107.4.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41fK6K2k6MzF0gv for ; Mon, 30 Jul 2018 22:45:12 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QpMk2yDNTUw+Le7wObvllE+OodmOLzFLzS5tJZYz7do=; b=I6w1Cm/70LqM4te6YjsMJGxGMcGS6koZ0Dw12AStULpmJsFXOVw6Ld261OO8angUCZE5FkdflavYV782WADgL8CmyfyMMqE/qLg5ru90Z+tm2gLZVSsbuTRPyc3fsd8Dr92VsJVuDqTs3DUnFgFIRF4/rxfv7ViUD1WvUO89Ecg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=petrm@mellanox.com; Received: from t540p (78.45.160.211) by DB7PR05MB4187.eurprd05.prod.outlook.com (2603:10a6:5:18::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.16; Mon, 30 Jul 2018 12:45:06 +0000 From: Petr Machata To: Subject: [PATCH net-next mlxsw v3 1/7] net: ipv4: Control SKB reprioritization after forwarding In-Reply-To: References: Message-Id: <6c112814d8b67a8ff0246a518ae1c96fa247c72a.1532953818.git.petrm@mellanox.com> Date: Mon, 30 Jul 2018 14:45:02 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 X-Originating-IP: [78.45.160.211] X-ClientProxiedBy: AM0PR02CA0030.eurprd02.prod.outlook.com (2603:10a6:208:3e::43) To DB7PR05MB4187.eurprd05.prod.outlook.com (2603:10a6:5:18::28) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bdad9804-bb2d-4176-99cb-08d5f61a473b X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600074)(711020)(4618075)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:DB7PR05MB4187; X-Microsoft-Exchange-Diagnostics: 1; DB7PR05MB4187; 3:UeYtM8CV01rQhtxsxNn2/ZYha73GpUuWsHsx9WvNwUv4C4zAHn7dGH6ZmjkO6pFUQdshb/5jPj/PWf1wz0lsqFovchnO8AjXj5RRk5CWNixpV4Zx9LuKtx2pt2zSVUsYCxdyofJYRuVvmuGgaB/HKHOBoPbfaaOuDaDEeWuuCyZO7NQV5LWWDkWD2F+dmZ0MK36wi2REDelTaEceJpkJl5xF9cWpRq9X22WasNSAZm+KKZa6s6qnv9K8hhPqNdU1; 25:Qw5DQHTOmObTI8Fusd43ApXz4JTxuutBLI5mgh+7WGlvwzkPkFg3lpUs9Xs93gWttPJNG+pANusmqAWH++KFw6KdCgpWiG5uT2tb7L04ZMneRuL4kJiEnPIuC5tyh64aDqjl3gzL2vHKMKr2HGkx5wQQSg+4Lf+IGDUHSN0PSp0LLEA5ay99/VwDDuud47g2jzIjnqG79KVTumc+2dPMkSoqXsdFfTMfnQVjlGw+9/dQoxJDsMeFX+9HnoREo+7AkkKmGxdXlYfOjDF9X+JznMeU454qN4XTAxBL5gesBeFwRjO8wL+Dd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X1pFKX0EF0DxEs6gT52FN9I43hKvQsfHGH7oD/GY+FXWcG3qe5Z9h2IXQAhx/5u+xxEhiQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231311)(944501410)(52105095)(3002001)(10201501046)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(20161123562045)(6072148)(201708071742011)(7699016); SRVR:DB7PR05MB4187; BCL:0; PCL:0; RULEID:; SRVR:DB7PR05MB4187; X-Forefront-PRVS: 0749DC2CE6 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(366004)(136003)(396003)(346002)(376002)(199004)(189003)(5660300001)(81166006)(81156014)(48376002)(26005)(186003)(8676002)(16526019)(50466002)(6636002)(6666003)(97736004)(36756003)(68736007)(8936002)(956004)(86362001)(11346002)(575784001)(476003)(2351001)(486006)(14444005)(2616005)(316002)(106356001)(118296001)(446003)(76176011)(386003)(25786009)(478600001)(16586007)(53936002)(6486002)(6862004)(105586002)(37006003)(58126008)(305945005)(47776003)(7736002)(66066001)(6116002)(51416003)(2906002)(6496006)(3846002)(52116002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR05MB4187; H:t540p; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB7PR05MB4187; 23:yj50zTiEKlkKbqonxUkbkliQrHzpK/ZUNaZHzYQh/?= z3yzKiG0i0tTv0pElnEjSWCRi5+yBdCJRpSLCa58xRJNtT1aGxuXbmr7ITjA9aslVIRq6XopIknE1DzEN6K84NHOFC10lWeph51kPn/Ict7GpAGqFic3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FzcMe06zQr2Gs=; 7:QbilFqht8esBVAEquypFOkPYQSZmvnhuhAi82bNqC4kDBEzVV9lEHeaGOzolIP8c2pDVbNZz06aDWdPOQG5Knd91b5DhylRby/ICdjR6inXgqmn0Fu2qupXInVpde1fCzt7CCkb6d6BZGAfnfBCjGOIbbVT3U2zQE5EH1s3ZJt/9u1rg4jOILQIkZkeYVYvvkQKyIbher/Uejp6XfKo6R+KhGThwO0VYTG5ATadgOd090bLElWOLnovZseE+TNY3 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2018 12:45:06.4964 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bdad9804-bb2d-4176-99cb-08d5f61a473b X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR05MB4187 X-BeenThere: linux-mlxsw@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: mlxsw driver development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-mlxsw-bounces+patchwork-linux-mlxsw=patchwork.kernel.org@lists.ozlabs.org X-Virus-Scanned: ClamAV using ClamSMTP After IPv4 packets are forwarded, the priority of the corresponding SKB is updated according to the TOS field of IPv4 header. This overrides any prioritization done earlier by e.g. an skbedit action or ingress-qos-map defined at a vlan device. Such overriding may not always be desirable. Even if the packet ends up being routed, which implies this is an L3 network node, an administrator may wish to preserve whatever prioritization was done earlier on in the pipeline. Therefore introduce a sysctl that controls this behavior. Keep the default value at 1 to maintain backward-compatible behavior. Signed-off-by: Petr Machata --- Documentation/networking/ip-sysctl.txt | 9 +++++++++ include/net/netns/ipv4.h | 1 + net/ipv4/af_inet.c | 1 + net/ipv4/ip_forward.c | 3 ++- net/ipv4/sysctl_net_ipv4.c | 9 +++++++++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt index 77c37fb0b6a6..e74515ecaa9c 100644 --- a/Documentation/networking/ip-sysctl.txt +++ b/Documentation/networking/ip-sysctl.txt @@ -81,6 +81,15 @@ fib_multipath_hash_policy - INTEGER 0 - Layer 3 1 - Layer 4 +ip_forward_update_priority - INTEGER + Whether to update SKB priority from "TOS" field in IPv4 header after it + is forwarded. The new SKB priority is mapped from TOS field value + according to an rt_tos2priority table (see e.g. man tc-prio). + Default: 1 (Update priority.) + Possible values: + 0 - Do not update priority. + 1 - Update priority. + route/max_size - INTEGER Maximum number of routes allowed in the kernel. Increase this when using large numbers of interfaces and/or routes. diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h index 661348f23ea5..e47503b4e4d1 100644 --- a/include/net/netns/ipv4.h +++ b/include/net/netns/ipv4.h @@ -98,6 +98,7 @@ struct netns_ipv4 { int sysctl_ip_default_ttl; int sysctl_ip_no_pmtu_disc; int sysctl_ip_fwd_use_pmtu; + int sysctl_ip_fwd_update_priority; int sysctl_ip_nonlocal_bind; /* Shall we try to damage output packets if routing dev changes? */ int sysctl_ip_dynaddr; diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index f2a0a3bab6b5..d3cfbd89ca3a 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1802,6 +1802,7 @@ static __net_init int inet_init_net(struct net *net) * We set them here, in case sysctl is not compiled. */ net->ipv4.sysctl_ip_default_ttl = IPDEFTTL; + net->ipv4.sysctl_ip_fwd_update_priority = true; net->ipv4.sysctl_ip_dynaddr = 0; net->ipv4.sysctl_ip_early_demux = 1; net->ipv4.sysctl_udp_early_demux = 1; diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c index b54b948b0596..32662e9e5d21 100644 --- a/net/ipv4/ip_forward.c +++ b/net/ipv4/ip_forward.c @@ -143,7 +143,8 @@ int ip_forward(struct sk_buff *skb) !skb_sec_path(skb)) ip_rt_send_redirect(skb); - skb->priority = rt_tos2priority(iph->tos); + if (net->ipv4.sysctl_ip_fwd_update_priority) + skb->priority = rt_tos2priority(iph->tos); return NF_HOOK(NFPROTO_IPV4, NF_INET_FORWARD, net, NULL, skb, skb->dev, rt->dst.dev, diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index 5fa335fd3852..e21dda015513 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -664,6 +664,15 @@ static struct ctl_table ipv4_net_table[] = { .proc_handler = proc_dointvec, }, { + .procname = "ip_forward_update_priority", + .data = &init_net.ipv4.sysctl_ip_fwd_update_priority, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one, + }, + { .procname = "ip_nonlocal_bind", .data = &init_net.ipv4.sysctl_ip_nonlocal_bind, .maxlen = sizeof(int),