From patchwork Wed Apr 18 00:33:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 899798 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="g60sLvLA"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40Qjn03dswz9ryr for ; Wed, 18 Apr 2018 10:34:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753289AbeDRAem (ORCPT ); Tue, 17 Apr 2018 20:34:42 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:36982 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752833AbeDRAdz (ORCPT ); Tue, 17 Apr 2018 20:33:55 -0400 Received: by mail-pl0-f68.google.com with SMTP id f7-v6so23769plr.4 for ; Tue, 17 Apr 2018 17:33:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Yuqdc2L6I3K7ahLSiHM1hBa1yw96zcuEy0WaSibHfKc=; b=g60sLvLAZO/n3DipEb5ZuVYDRD/lykCFFXzBOEEFr46JeIfUuT8V9Trglnp6fhwAjt Ej3qGzCqAfSt5CTzToMQftuPysXV1JNlvUkpE6srRI/hfpUxBmLdZpJ7y/Y+CCxkwMtL a9o793KqwiljPbz1EEKBtKhxXXOiVeg2gzcMTy6fP6kQw4JuY/7IndtoTqaBcrjWlng6 eMxXHuo+Zxnwvks4UgFwEkLT3QGf6kQMr6GVPiHOs935UawyONqsejqX1+b1wIsb8tho LBS7ktTYnSu7BH/nXvzIk5q7EiSlRKp5Eq5w9FKi1ENeHYKK3tlSsnRYHmg/kS46AexZ +LyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Yuqdc2L6I3K7ahLSiHM1hBa1yw96zcuEy0WaSibHfKc=; b=RMwTLKZHox5OC+I/y+NzZao8eTO1yGU4YKrAn34OILTZWXdGrbD953jAU8Jej+Fga6 FGKs1dqICt6C6PJJ05FvFbNZqziUjuWbETpHMpNLslV+A+ea45JAQSTDd6Xa69MQ9mIB RLfaRud0ju6Y3pSsqpOXtyx1w76bIsp/HPd5GtJT40U0EPHcXfKY/oX8o7lPJyZG6v2v ZVgHzxh1lcpjDvm2ka4gQt1+qmTQPcppVndC6EM6OoHX1BD6rz0TnzpC1pe4JTbnYu0u 3OFqdt/DskeBJAknw2WxTQh8px1Y8j63vVjJ98gjpfooXqmzynKDHz7dSY9rLG3JMARj F09g== X-Gm-Message-State: ALQs6tCoHow6ehXRKXgce6NfrxIj6AbZBFYcbpI5jBGnOeKFAQop97th X6+IbLd0SjsgWE2lwcmX7TZvOw== X-Google-Smtp-Source: AIpwx48ScnrL67NQ16GjNlihGswjZHjsY3p7nfJcAMP7sDsvwR1Pr1T5509Q3mmYvdYu1EI6CZqQvg== X-Received: by 2002:a17:902:7290:: with SMTP id d16-v6mr3929149pll.43.1524011634443; Tue, 17 Apr 2018 17:33:54 -0700 (PDT) Received: from kenny.it.cumulusnetworks.com. (fw.cumulusnetworks.com. [216.129.126.126]) by smtp.googlemail.com with ESMTPSA id o64sm20891pfb.62.2018.04.17.17.33.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Apr 2018 17:33:53 -0700 (PDT) From: David Ahern To: netdev@vger.kernel.org Cc: davem@davemloft.net, idosch@idosch.org, roopa@cumulusnetworks.com, eric.dumazet@gmail.com, weiwan@google.com, kafai@fb.com, yoshfuji@linux-ipv6.org, David Ahern Subject: [PATCH net-next v2 13/21] net/ipv6: Add rt6_info create function for ip6_pol_route_lookup Date: Tue, 17 Apr 2018 17:33:19 -0700 Message-Id: <20180418003327.19992-14-dsahern@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180418003327.19992-1-dsahern@gmail.com> References: <20180418003327.19992-1-dsahern@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org ip6_pol_route_lookup is the lookup function for ip6_route_lookup and rt6_lookup. At the moment it returns either a reference to a FIB entry or a cached exception. To move FIB entries to a separate struct, this lookup function needs to convert FIB entries to an rt6_info that is returned to the caller. Signed-off-by: David Ahern --- net/ipv6/route.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 7c141394d4f1..e293692174ba 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -1055,6 +1055,19 @@ static bool ip6_hold_safe(struct net *net, struct rt6_info **prt, return false; } +/* called with rcu_lock held */ +static struct rt6_info *ip6_create_rt_rcu(struct rt6_info *rt) +{ + struct net_device *dev = rt->fib6_nh.nh_dev; + struct rt6_info *nrt; + + nrt = __ip6_dst_alloc(dev_net(dev), dev, 0); + if (nrt) + ip6_rt_copy_init(nrt, rt); + + return nrt; +} + static struct rt6_info *ip6_pol_route_lookup(struct net *net, struct fib6_table *table, struct flowi6 *fl6, @@ -1087,18 +1100,26 @@ static struct rt6_info *ip6_pol_route_lookup(struct net *net, } /* Search through exception table */ rt_cache = rt6_find_cached_rt(rt, &fl6->daddr, &fl6->saddr); - if (rt_cache) + if (rt_cache) { rt = rt_cache; + if (ip6_hold_safe(net, &rt, true)) + dst_use_noref(&rt->dst, jiffies); + } else if (dst_hold_safe(&rt->dst)) { + struct rt6_info *nrt; - if (ip6_hold_safe(net, &rt, true)) - dst_use_noref(&rt->dst, jiffies); + nrt = ip6_create_rt_rcu(rt); + dst_release(&rt->dst); + rt = nrt; + } else { + rt = net->ipv6.ip6_null_entry; + dst_hold(&rt->dst); + } rcu_read_unlock(); trace_fib6_table_lookup(net, rt, table, fl6); return rt; - } struct dst_entry *ip6_route_lookup(struct net *net, struct flowi6 *fl6,