From patchwork Fri Sep 12 14:14:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Cavallari X-Patchwork-Id: 388680 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id E777A1401B1 for ; Sat, 13 Sep 2014 00:15:46 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754733AbaILOPn (ORCPT ); Fri, 12 Sep 2014 10:15:43 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:63715 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753637AbaILOPl (ORCPT ); Fri, 12 Sep 2014 10:15:41 -0400 Received: from evilbit.green-communications.fr ([193.51.194.208]) by mrelayeu.kundenserver.de (node=mreue102) with ESMTP (Nemesis) id 0LxfAZ-1YPIN51KVn-017EBA; Fri, 12 Sep 2014 16:15:08 +0200 From: Nicolas Cavallari To: netdev@vger.kernel.org Cc: "David S. Miller" , Alexey Kuznetsov , James Morris , Hideaki YOSHIFUJI , Patrick McHardy Subject: [RFC] ipv4: Do not cache routing failures due to disabled forwarding. Date: Fri, 12 Sep 2014 16:14:20 +0200 Message-Id: <1410531260-13794-2-git-send-email-nicolas.cavallari@green-communications.fr> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1410531260-13794-1-git-send-email-nicolas.cavallari@green-communications.fr> References: <1410531260-13794-1-git-send-email-nicolas.cavallari@green-communications.fr> X-Provags-ID: V02:K0:O12NaQx2WBLNZ+iH5pVIcdG7/uCnPve+rmcvRLZexFj N5Q5t+z46GvRVEo1HQsfHQ4wsJHiBDFzQWNiJtfRrVEW5iPxSh lpYeXtTfe3/E3HIstQACOAz2Y6+chHZUc3hcuT6m+8wHsmwIml QyErSaWdg98QePAscWU0odPtMQFiGaEKX6nf/gawLoRx+qsgiR +GpKjAqt1ybo5oCZ3dm+eK2YZnUU6aUW/Iw50hJvxeO807u8MO ZpLPUq5G0btJAIjCKByumBKmonCINxdzfoicjDHbT9WnyeWQbr DMPmCseWHjKLGFZFlsfVtXyNwUdwaNg9TxV8zjZlb0HNzzqP29 k63gqjNld9Z81f26jtOpR0TxzeXn/PHvG2ztXXK6THtLCmNot2 gPeYvlgqlC60bszGMZ5r7FwVOFPKRaA5x2hx31gU9AnGtaRzCI /brbJC50XVOdULWGEdhl2Mk9a3TyMZ9FMEf1Pk4yepNO1wyg2S vDJV/HX4QhNONTQsioF X-UI-Out-Filterresults: notjunk:1; Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If we cache them, the kernel will reuse them, independently of whether forwarding is enabled or not. Which means that if forwarding is disabled on the input interface where the first routing request comes from, then that unreachable result will be cached and reused for other interfaces, even if forwarding is enabled on them. This can be verified with two interfaces A and B and an output interface C, where B has forwarding enabled, but not A and trying ip route get $dst iif A from $src && ip route get $dst iif B from $src Signed-off-by: Nicolas Cavallari --- based on net-next, but not really tested on top of it. net/ipv4/route.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 234a43e..b537997 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1655,7 +1655,7 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr, struct rtable *rth; int err = -EINVAL; struct net *net = dev_net(dev); - bool do_cache; + bool do_cache = true; /* IP on this device is disabled. */ @@ -1723,6 +1723,7 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr, if (!IN_DEV_FORWARD(in_dev)) { err = -EHOSTUNREACH; + do_cache = false; goto no_route; } if (res.type != RTN_UNICAST) @@ -1746,16 +1747,14 @@ brd_input: RT_CACHE_STAT_INC(in_brd); local_input: - do_cache = false; - if (res.fi) { - if (!itag) { - rth = rcu_dereference(FIB_RES_NH(res).nh_rth_input); - if (rt_cache_valid(rth)) { - skb_dst_set_noref(skb, &rth->dst); - err = 0; - goto out; - } - do_cache = true; + if (!res.fi || itag) { + do_cache = false; + } else if (do_cache) { + rth = rcu_dereference(FIB_RES_NH(res).nh_rth_input); + if (rt_cache_valid(rth)) { + skb_dst_set_noref(skb, &rth->dst); + err = 0; + goto out; } }