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: 719222 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by ozlabs.org (Postfix) with ESMTP id 3v7BvR2YRqz9sxS for ; Wed, 25 Jan 2017 02:30:11 +1100 (AEDT) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 1DA3A280B2; Tue, 24 Jan 2017 15:30:10 +0000 (UTC) Authentication-Results: lists.osmocom.org; dmarc=none header.from=tpip.net X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=92.43.49.48; helo=mail.tpip.net; envelope-from=aschultz@tpip.net; receiver=openbsc@lists.osmocom.org Authentication-Results: lists.osmocom.org; dmarc=none header.from=tpip.net Received: from mail.tpip.net (mail.tpip.net [92.43.49.48]) by lists.osmocom.org (Postfix) with ESMTP id 7241129F92 for ; Tue, 24 Jan 2017 15:28:58 +0000 (UTC) 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 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> X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Development of OpenBSC, OsmoBSC, OsmoNITB, OsmoCSCN" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, openbsc@lists.osmocom.org, Lionel Gauthier Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" 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); }