From patchwork Wed Oct 18 20:10:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 827811 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@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; dkim=pass (2048-bit key; unprotected) header.d=quantonium-net.20150623.gappssmtp.com header.i=@quantonium-net.20150623.gappssmtp.com header.b="TFPWnj0w"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yHNWF59tdz9t48 for ; Thu, 19 Oct 2017 07:11:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751687AbdJRULL (ORCPT ); Wed, 18 Oct 2017 16:11:11 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:55284 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750960AbdJRULD (ORCPT ); Wed, 18 Oct 2017 16:11:03 -0400 Received: by mail-pg0-f66.google.com with SMTP id l24so5153740pgu.11 for ; Wed, 18 Oct 2017 13:11:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quantonium-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0Vs249g8KFibi/hTwDBA/hTAfGlB+QSLg+DbDOQBVYE=; b=TFPWnj0wRcH1gY2k2CwRYfAceZGJVWfH1qL8h/MhCaY8Xon7iBT50NyeapbMKhTB4z 6XiBu9lbYmFF9oCJ6QhbcmEP5qf5LndgxHr+bg3qi65vwIBMZstnbyERDN3l9doxXezG ia4uaB2sCFqRlV5/eAgGphXGzWUHS00bG7vif46dyj/IR4FMMxYKHZckqZ/ecNp4+tAo RanXBI6yW4OUseIHO0gZqv3XRd6xQYBoP/XLnVixRDUCekmYJCysAX3awh9hj9TAJUqj wojSpyMmu5e/4fzBtLkB65b3qRScW+xNZIr/3mjYrR8Nlvx1FdfxZRrYGVOxGcMmPhra WESQ== 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=0Vs249g8KFibi/hTwDBA/hTAfGlB+QSLg+DbDOQBVYE=; b=e7eGjWITgSiyKqnJcOPF01Y7P6dMx04V/PfE4tAZadve3Qwx279IuI9t8NoCUOx6YQ 1d79ZebjR1tSlCJ5kCaW2Fp1uooOEzcWS0LKUrtwNiVNvLUwIRBt+96UNAavH2nymZ+0 D8qGilvWU2NFmF3mV0mMFr3kY0uq6zEiSWo674CgWWOy99sdD4XPQn6VOjZmbvA5oRk4 KrczcBvepFDy3qLU+30fSKbvSGS8O9ruIzV2TmSbohSlvq3UNFZBiPm4TTQGXbbx9cvk FpDvzpvZOSG9cOW1nJIajTchn4QTpbDv8YR0bV8xOUspfBHtODdGI6giBq3rdQL2sUqW IwNA== X-Gm-Message-State: AMCzsaUixOExaG0FDXx16WeZ1pm3dfx/jtRPazzLdpVBhKr4XtAQ1UNQ g2XIawPQu1w8XfLJEHlwsEY7sg== X-Google-Smtp-Source: ABhQp+SEONa+rd+7FyYKKUxG/mFpCjuaEKtI9JsuB9nQsE112Y00mxlztIyOkrBYgruwSRBG6Br32A== X-Received: by 10.98.80.21 with SMTP id e21mr2544386pfb.208.1508357463264; Wed, 18 Oct 2017 13:11:03 -0700 (PDT) Received: from localhost.localdomain (c-73-162-13-107.hsd1.ca.comcast.net. [73.162.13.107]) by smtp.gmail.com with ESMTPSA id l79sm26424108pfb.33.2017.10.18.13.11.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 13:11:02 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net Cc: pablo@netfilter.org, laforge@gnumonks.org, aschultz@tpip.net, netdev@vger.kernel.org, rohit@quantonium.net, Tom Herbert Subject: [PATCH v5 net-next 03/12] gtp: Call common functions to get tunnel routes and add dst_cache Date: Wed, 18 Oct 2017 13:10:09 -0700 Message-Id: <20171018201018.5692-4-tom@quantonium.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171018201018.5692-1-tom@quantonium.net> References: <20171018201018.5692-1-tom@quantonium.net> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Call ip_tunnel_get_route and dst_cache to pdp context which should improve performance by obviating the need to perform a route lookup on every packet. Signed-off-by: Tom Herbert --- drivers/net/gtp.c | 62 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index f38e32a7ec9c..6dabd605607c 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -63,6 +63,8 @@ struct pdp_ctx { atomic_t tx_seq; struct rcu_head rcu_head; + + struct dst_cache dst_cache; }; /* One instance of the GTP device. */ @@ -379,20 +381,6 @@ static void gtp_dev_uninit(struct net_device *dev) free_percpu(dev->tstats); } -static struct rtable *ip4_route_output_gtp(struct flowi4 *fl4, - const struct sock *sk, - __be32 daddr) -{ - memset(fl4, 0, sizeof(*fl4)); - fl4->flowi4_oif = sk->sk_bound_dev_if; - fl4->daddr = daddr; - fl4->saddr = inet_sk(sk)->inet_saddr; - fl4->flowi4_tos = RT_CONN_FLAGS(sk); - fl4->flowi4_proto = sk->sk_protocol; - - return ip_route_output_key(sock_net(sk), fl4); -} - static inline void gtp0_push_header(struct sk_buff *skb, struct pdp_ctx *pctx) { int payload_len = skb->len; @@ -479,6 +467,8 @@ static int gtp_build_skb_ip4(struct sk_buff *skb, struct net_device *dev, struct rtable *rt; struct flowi4 fl4; struct iphdr *iph; + struct sock *sk; + __be32 saddr; __be16 df; int mtu; @@ -498,19 +488,30 @@ static int gtp_build_skb_ip4(struct sk_buff *skb, struct net_device *dev, } netdev_dbg(dev, "found PDP context %p\n", pctx); - rt = ip4_route_output_gtp(&fl4, pctx->sk, pctx->peer_addr_ip4.s_addr); - if (IS_ERR(rt)) { - netdev_dbg(dev, "no route to SSGN %pI4\n", - &pctx->peer_addr_ip4.s_addr); - dev->stats.tx_carrier_errors++; - goto err; - } + sk = pctx->sk; + saddr = inet_sk(sk)->inet_saddr; - if (rt->dst.dev == dev) { - netdev_dbg(dev, "circular route to SSGN %pI4\n", - &pctx->peer_addr_ip4.s_addr); - dev->stats.collisions++; - goto err_rt; + /* Source address returned by route lookup is ignored since + * we get the address from a socket. + */ + rt = ip_tunnel_get_route(dev, skb, sk->sk_protocol, + sk->sk_bound_dev_if, RT_CONN_FLAGS(sk), + pctx->peer_addr_ip4.s_addr, &saddr, + pktinfo->gtph_port, pktinfo->gtph_port, + &pctx->dst_cache, NULL); + + if (IS_ERR(rt)) { + if (rt == ERR_PTR(-ELOOP)) { + netdev_dbg(dev, "circular route to SSGN %pI4\n", + &pctx->peer_addr_ip4.s_addr); + dev->stats.collisions++; + goto err_rt; + } else { + netdev_dbg(dev, "no route to SSGN %pI4\n", + &pctx->peer_addr_ip4.s_addr); + dev->stats.tx_carrier_errors++; + goto err; + } } skb_dst_drop(skb); @@ -543,7 +544,7 @@ static int gtp_build_skb_ip4(struct sk_buff *skb, struct net_device *dev, goto err_rt; } - gtp_set_pktinfo_ipv4(pktinfo, pctx->sk, iph, pctx, rt, &fl4, dev); + gtp_set_pktinfo_ipv4(pktinfo, sk, iph, pctx, rt, &fl4, dev); gtp_push_header(skb, pktinfo); return 0; @@ -917,6 +918,7 @@ static int ipv4_pdp_add(struct gtp_dev *gtp, struct sock *sk, struct pdp_ctx *pctx; bool found = false; __be32 ms_addr; + int err; ms_addr = nla_get_be32(info->attrs[GTPA_MS_ADDRESS]); hash_ms = ipv4_hashfn(ms_addr) % gtp->hash_size; @@ -951,6 +953,12 @@ static int ipv4_pdp_add(struct gtp_dev *gtp, struct sock *sk, if (pctx == NULL) return -ENOMEM; + err = dst_cache_init(&pctx->dst_cache, GFP_KERNEL); + if (err) { + kfree(pctx); + return err; + } + sock_hold(sk); pctx->sk = sk; pctx->dev = gtp->dev;