From patchwork Tue Jan 24 15:28:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schultz X-Patchwork-Id: 719198 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 3v7BtM74Qdz9sxS for ; Wed, 25 Jan 2017 02:29:15 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751198AbdAXP3O (ORCPT ); Tue, 24 Jan 2017 10:29:14 -0500 Received: from mail.tpip.net ([92.43.49.48]:56579 "EHLO mail.tpip.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751165AbdAXP27 (ORCPT ); Tue, 24 Jan 2017 10:28:59 -0500 Received: from office.tpip.net (unknown [153.92.65.89]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.tpip.net (Postfix) with ESMTPS id 32E574F408; Tue, 24 Jan 2017 15:28:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by office.tpip.net (Postfix) with ESMTP id CED24A2CC0; Tue, 24 Jan 2017 16:28:57 +0100 (CET) Received: from office.tpip.net ([127.0.0.1]) by localhost (office.tpip.net [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Paz3f5VLMEan; Tue, 24 Jan 2017 16:28:57 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by office.tpip.net (Postfix) with ESMTP id 7C696A2CC1; Tue, 24 Jan 2017 16:28:57 +0100 (CET) X-Virus-Scanned: amavisd-new at tpip.net Received: from office.tpip.net ([127.0.0.1]) by localhost (office.tpip.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id blSxBjBBBIxh; Tue, 24 Jan 2017 16:28:57 +0100 (CET) Received: from localhost.localdomain (pd95c9392.dip0.t-ipconnect.de [217.92.147.146]) by office.tpip.net (Postfix) with ESMTPSA id 320D6A2CC2; Tue, 24 Jan 2017 16:28:57 +0100 (CET) From: Andreas Schultz To: Pablo Neira Cc: netdev@vger.kernel.org, Lionel Gauthier , openbsc@lists.osmocom.org, Harald Welte Subject: [PATCH v2 18/18] gtp: add dst_cache support Date: Tue, 24 Jan 2017 16:28:48 +0100 Message-Id: <20170124152848.6120-19-aschultz@tpip.net> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170124152848.6120-1-aschultz@tpip.net> References: <20170124152848.6120-1-aschultz@tpip.net> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Andreas Schultz --- drivers/net/gtp.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 4637ce7..c3e40cc 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -61,6 +61,10 @@ struct pdp_ctx { struct net_device *dev; struct sock *sk; +#ifdef CONFIG_DST_CACHE + struct dst_cache dst_cache; +#endif + atomic_t tx_seq; struct rcu_head rcu_head; }; @@ -485,12 +489,18 @@ 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->sgsn_addr_ip4.s_addr); - if (IS_ERR(rt)) { - netdev_dbg(dev, "no route to SSGN %pI4\n", - &pctx->sgsn_addr_ip4.s_addr); - dev->stats.tx_carrier_errors++; - goto err; + rt = dst_cache_get_ip4(&pctx->dst_cache, &pctx->sgsn_addr_ip4.s_addr); + if (!rt) { + rt = ip4_route_output_gtp(&fl4, pctx->sk, pctx->sgsn_addr_ip4.s_addr); + if (IS_ERR(rt)) { + netdev_dbg(dev, "no route to SSGN %pI4\n", + &pctx->sgsn_addr_ip4.s_addr); + dev->stats.tx_carrier_errors++; + goto err; + } + + dst_cache_set_ip4(&pctx->dst_cache, &rt->dst, + pctx->sgsn_addr_ip4.s_addr); } if (rt->dst.dev == dev) { @@ -883,6 +893,8 @@ static void ipv4_pdp_fill(struct pdp_ctx *pctx, struct genl_info *info) pctx->ms_addr_ip4.s_addr = nla_get_be32(info->attrs[GTPA_MS_ADDRESS]); + dst_cache_reset(&pctx->dst_cache); + switch (pctx->gtp_version) { case GTP_V0: /* According to TS 09.60, sections 7.5.1 and 7.5.2, the flow @@ -910,6 +922,7 @@ static int ipv4_pdp_add(struct net_device *dev, struct sock *sk, struct pdp_ctx *pctx; bool found = false; __be32 ms_addr; + int err; gsk = rcu_dereference_sk_user_data(sk); if (!gsk) @@ -948,6 +961,12 @@ static int ipv4_pdp_add(struct net_device *dev, 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 = dev; @@ -992,6 +1011,7 @@ static void pdp_context_free(struct rcu_head *head) struct pdp_ctx *pctx = container_of(head, struct pdp_ctx, rcu_head); sock_put(pctx->sk); + dst_cache_destroy(&pctx->dst_cache); kfree(pctx); }