From: Andreas Schultz <aschultz@tpip.net>
To: Pablo Neira <pablo@netfilter.org>
Cc: netdev@vger.kernel.org, Harald Welte <laforge@gnumonks.org>,
Lionel Gauthier <Lionel.Gauthier@eurecom.fr>,
osmocom-net-gprs@lists.osmocom.org,
Jonas Bonn <jonas@southpole.se>
Subject: [PATCH net-next v3 6/8] gtp: unify genl_find_pdp and prepare for per socket lookup
Date: Mon, 13 Feb 2017 16:36:22 +0100 [thread overview]
Message-ID: <20170213153624.14170-7-aschultz@tpip.net> (raw)
In-Reply-To: <20170213153624.14170-1-aschultz@tpip.net>
This unifies duplicate code into a helper. It also prepares the
groundwork to add a lookup version that uses the socket to find
attache pdp contexts.
Signed-off-by: Andreas Schultz <aschultz@tpip.net>
---
drivers/net/gtp.c | 124 +++++++++++++++++++++++-------------------------------
1 file changed, 53 insertions(+), 71 deletions(-)
diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c
index e21b663..d3c384e 100644
--- a/drivers/net/gtp.c
+++ b/drivers/net/gtp.c
@@ -1039,55 +1039,70 @@ static int gtp_genl_new_pdp(struct sk_buff *skb, struct genl_info *info)
return err;
}
+static struct pdp_ctx *gtp_genl_find_pdp_by_link(struct sk_buff *skb,
+ struct genl_info *info)
+{
+ struct gtp_dev *gtp;
+
+ gtp = gtp_genl_find_dev(sock_net(skb->sk), info->attrs);
+ if (!gtp)
+ return ERR_PTR(-ENODEV);
+
+ if (info->attrs[GTPA_MS_ADDRESS]) {
+ __be32 ip = nla_get_be32(info->attrs[GTPA_MS_ADDRESS]);
+
+ return ipv4_pdp_find(gtp, ip);
+ } else if (info->attrs[GTPA_VERSION]) {
+ u32 gtp_version = nla_get_u32(info->attrs[GTPA_VERSION]);
+
+ if (gtp_version == GTP_V0 && info->attrs[GTPA_TID])
+ return gtp0_pdp_find(gtp, nla_get_u64(
+ info->attrs[GTPA_TID]));
+ else if (gtp_version == GTP_V1 && info->attrs[GTPA_I_TEI])
+ return gtp1_pdp_find(gtp, nla_get_u32(
+ info->attrs[GTPA_I_TEI]));
+ }
+
+ return ERR_PTR(-EINVAL);
+}
+
+static struct pdp_ctx *gtp_genl_find_pdp(struct sk_buff *skb,
+ struct genl_info *info)
+{
+ struct pdp_ctx *pctx;
+
+ if (info->attrs[GTPA_LINK])
+ pctx = gtp_genl_find_pdp_by_link(skb, info);
+ else
+ pctx = ERR_PTR(-EINVAL);
+
+ if (!pctx)
+ pctx = ERR_PTR(-ENOENT);
+
+ return pctx;
+}
+
static int gtp_genl_del_pdp(struct sk_buff *skb, struct genl_info *info)
{
struct pdp_ctx *pctx;
- struct gtp_dev *gtp;
int err = 0;
- if (!info->attrs[GTPA_VERSION] ||
- !info->attrs[GTPA_LINK])
+ if (!info->attrs[GTPA_VERSION])
return -EINVAL;
rcu_read_lock();
- gtp = gtp_genl_find_dev(sock_net(skb->sk), info->attrs);
- if (!gtp) {
- err = -ENODEV;
- goto out_unlock;
- }
-
- switch (nla_get_u32(info->attrs[GTPA_VERSION])) {
- case GTP_V0:
- if (!info->attrs[GTPA_TID]) {
- err = -EINVAL;
- goto out_unlock;
- }
- pctx = gtp0_pdp_find(gtp, nla_get_u64(info->attrs[GTPA_TID]));
- break;
- case GTP_V1:
- if (!info->attrs[GTPA_I_TEI]) {
- err = -EINVAL;
- goto out_unlock;
- }
- pctx = gtp1_pdp_find(gtp, nla_get_u64(info->attrs[GTPA_I_TEI]));
- break;
-
- default:
- err = -EINVAL;
- goto out_unlock;
- }
-
- if (!pctx) {
- err = -ENOENT;
+ pctx = gtp_genl_find_pdp(skb, info);
+ if (IS_ERR(pctx)) {
+ err = PTR_ERR(pctx);
goto out_unlock;
}
if (pctx->gtp_version == GTP_V0)
- netdev_dbg(gtp->dev, "GTPv0-U: deleting tunnel id = %llx (pdp %p)\n",
+ netdev_dbg(pctx->dev, "GTPv0-U: deleting tunnel id = %llx (pdp %p)\n",
pctx->u.v0.tid, pctx);
else if (pctx->gtp_version == GTP_V1)
- netdev_dbg(gtp->dev, "GTPv1-U: deleting tunnel id = %x/%x (pdp %p)\n",
+ netdev_dbg(pctx->dev, "GTPv1-U: deleting tunnel id = %x/%x (pdp %p)\n",
pctx->u.v1.i_tei, pctx->u.v1.o_tei, pctx);
hlist_del_rcu(&pctx->hlist_tid);
@@ -1141,49 +1156,16 @@ static int gtp_genl_get_pdp(struct sk_buff *skb, struct genl_info *info)
{
struct pdp_ctx *pctx = NULL;
struct sk_buff *skb2;
- struct gtp_dev *gtp;
- u32 gtp_version;
int err;
- if (!info->attrs[GTPA_VERSION] ||
- !info->attrs[GTPA_LINK])
+ if (!info->attrs[GTPA_VERSION])
return -EINVAL;
- gtp_version = nla_get_u32(info->attrs[GTPA_VERSION]);
- switch (gtp_version) {
- case GTP_V0:
- case GTP_V1:
- break;
- default:
- return -EINVAL;
- }
-
rcu_read_lock();
- gtp = gtp_genl_find_dev(sock_net(skb->sk), info->attrs);
- if (!gtp) {
- err = -ENODEV;
- goto err_unlock;
- }
-
- if (gtp_version == GTP_V0 &&
- info->attrs[GTPA_TID]) {
- u64 tid = nla_get_u64(info->attrs[GTPA_TID]);
-
- pctx = gtp0_pdp_find(gtp, tid);
- } else if (gtp_version == GTP_V1 &&
- info->attrs[GTPA_I_TEI]) {
- u32 tid = nla_get_u32(info->attrs[GTPA_I_TEI]);
-
- pctx = gtp1_pdp_find(gtp, tid);
- } else if (info->attrs[GTPA_MS_ADDRESS]) {
- __be32 ip = nla_get_be32(info->attrs[GTPA_MS_ADDRESS]);
-
- pctx = ipv4_pdp_find(gtp, ip);
- }
-
- if (pctx == NULL) {
- err = -ENOENT;
+ pctx = gtp_genl_find_pdp(skb, info);
+ if (IS_ERR(pctx)) {
+ err = PTR_ERR(pctx);
goto err_unlock;
}
--
2.10.2
next prev parent reply other threads:[~2017-02-13 15:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-13 15:36 [PATCH net-next v3 0/8] gtp: misc improvements Andreas Schultz
2017-02-13 15:36 ` [PATCH net-next v3 1/8] gtp: add documentation Andreas Schultz
2017-02-20 16:15 ` Harald Welte
2017-02-20 17:28 ` Andreas Schultz
2017-02-21 1:12 ` Neels Hofmeyr
2017-02-22 8:36 ` Harald Welte
2017-02-22 11:30 ` Andreas Schultz
2017-02-13 15:36 ` [PATCH net-next v3 2/8] gtp: switch from struct socket to struct sock for the GTP sockets Andreas Schultz
2017-02-14 17:48 ` David Miller
2017-02-15 7:04 ` Andreas Schultz
2017-02-15 16:07 ` David Miller
2017-02-13 15:36 ` [PATCH net-next v3 3/8] gtp: make GTP sockets in gtp_newlink optional Andreas Schultz
2017-02-13 15:36 ` [PATCH net-next v3 4/8] gtp: merge gtp_get_net and gtp_genl_find_dev Andreas Schultz
2017-02-13 15:36 ` [PATCH net-next v3 5/8] gtp: consolidate gtp socket rx path Andreas Schultz
2017-02-13 15:36 ` Andreas Schultz [this message]
2017-02-13 15:36 ` [PATCH net-next v3 7/8] gtp: consolidate pdp context destruction into helper Andreas Schultz
2017-02-13 15:36 ` [PATCH net-next v3 8/8] gtp: add socket to pdp context Andreas Schultz
2017-02-16 21:38 ` [PATCH net-next v3 0/8] gtp: misc improvements Andreas Schultz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170213153624.14170-7-aschultz@tpip.net \
--to=aschultz@tpip.net \
--cc=Lionel.Gauthier@eurecom.fr \
--cc=jonas@southpole.se \
--cc=laforge@gnumonks.org \
--cc=netdev@vger.kernel.org \
--cc=osmocom-net-gprs@lists.osmocom.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).