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>,
openbsc@lists.osmocom.org
Subject: [PATCH net-next v2 2/6] gtp: merge gtp_get_net and gtp_genl_find_dev
Date: Mon, 30 Jan 2017 17:37:09 +0100 [thread overview]
Message-ID: <20170130163713.17524-3-aschultz@tpip.net> (raw)
In-Reply-To: <20170130163713.17524-1-aschultz@tpip.net>
Both function are always used together with the final goal to
get the gtp_dev. This simplifies the code by merging them together.
The netdevice lookup is changed to use the regular dev_get_by_index.
The gtp netdevice list is now only used to find the PDP contexts for
imcomming packets. It can be completely eliminated Once the TEID
hash is moved into the GTP socket.
Signed-off-by: Andreas Schultz <aschultz@tpip.net>
---
drivers/net/gtp.c | 170 ++++++++++++++++++++++++++----------------------------
1 file changed, 81 insertions(+), 89 deletions(-)
diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c
index 18944f4..c96c71f 100644
--- a/drivers/net/gtp.c
+++ b/drivers/net/gtp.c
@@ -745,21 +745,6 @@ static struct rtnl_link_ops gtp_link_ops __read_mostly = {
.fill_info = gtp_fill_info,
};
-static struct net *gtp_genl_get_net(struct net *src_net, struct nlattr *tb[])
-{
- struct net *net;
-
- /* Examine the link attributes and figure out which network namespace
- * we are talking about.
- */
- if (tb[GTPA_NET_NS_FD])
- net = get_net_ns_by_fd(nla_get_u32(tb[GTPA_NET_NS_FD]));
- else
- net = get_net(src_net);
-
- return net;
-}
-
static int gtp_hashtable_new(struct gtp_dev *gtp, int hsize)
{
int i;
@@ -870,16 +855,31 @@ static int gtp_encap_enable(struct gtp_dev *gtp, struct nlattr *data[])
return 0;
}
-static struct net_device *gtp_find_dev(struct net *net, int ifindex)
+static struct gtp_dev *gtp_genl_find_dev(struct net *src_net,
+ struct nlattr *tb[])
{
- struct gtp_net *gn = net_generic(net, gtp_net_id);
- struct gtp_dev *gtp;
-
- list_for_each_entry_rcu(gtp, &gn->gtp_dev_list, list) {
- if (ifindex == gtp->dev->ifindex)
- return gtp->dev;
- }
- return NULL;
+ struct net *net;
+ struct net_device *dev;
+ struct gtp_dev *gtp = NULL;
+
+ /* Examine the link attributes and figure out which network namespace
+ * we are talking about.
+ */
+ if (tb[GTPA_NET_NS_FD])
+ net = get_net_ns_by_fd(nla_get_u32(tb[GTPA_NET_NS_FD]));
+ else
+ net = get_net(src_net);
+
+ if (IS_ERR(net))
+ return NULL;
+
+ /* Check if there's an existing gtpX device to configure */
+ dev = dev_get_by_index_rcu(net, nla_get_u32(tb[GTPA_LINK]));
+ if (dev->netdev_ops == >p_netdev_ops)
+ gtp = netdev_priv(dev);
+
+ put_net(net);
+ return gtp;
}
static void ipv4_pdp_fill(struct pdp_ctx *pctx, struct genl_info *info)
@@ -909,9 +909,8 @@ static void ipv4_pdp_fill(struct pdp_ctx *pctx, struct genl_info *info)
}
}
-static int ipv4_pdp_add(struct net_device *dev, struct genl_info *info)
+static int ipv4_pdp_add(struct gtp_dev *gtp, struct genl_info *info)
{
- struct gtp_dev *gtp = netdev_priv(dev);
u32 hash_ms, hash_tid = 0;
struct pdp_ctx *pctx;
bool found = false;
@@ -936,11 +935,11 @@ static int ipv4_pdp_add(struct net_device *dev, struct genl_info *info)
ipv4_pdp_fill(pctx, info);
if (pctx->gtp_version == GTP_V0)
- netdev_dbg(dev, "GTPv0-U: update tunnel id = %llx (pdp %p)\n",
- pctx->u.v0.tid, pctx);
+ pr_debug("GTPv0-U: update tunnel id = %llx (pdp %p)\n",
+ pctx->u.v0.tid, pctx);
else if (pctx->gtp_version == GTP_V1)
- netdev_dbg(dev, "GTPv1-U: update tunnel id = %x/%x (pdp %p)\n",
- pctx->u.v1.i_tei, pctx->u.v1.o_tei, pctx);
+ pr_debug("GTPv1-U: update tunnel id = %x/%x (pdp %p)\n",
+ pctx->u.v1.i_tei, pctx->u.v1.o_tei, pctx);
return 0;
@@ -972,14 +971,14 @@ static int ipv4_pdp_add(struct net_device *dev, struct genl_info *info)
switch (pctx->gtp_version) {
case GTP_V0:
- netdev_dbg(dev, "GTPv0-U: new PDP ctx id=%llx ssgn=%pI4 ms=%pI4 (pdp=%p)\n",
- pctx->u.v0.tid, &pctx->sgsn_addr_ip4,
- &pctx->ms_addr_ip4, pctx);
+ pr_debug("GTPv0-U: new PDP ctx id=%llx ssgn=%pI4 ms=%pI4 (pdp=%p)\n",
+ pctx->u.v0.tid, &pctx->sgsn_addr_ip4,
+ &pctx->ms_addr_ip4, pctx);
break;
case GTP_V1:
- netdev_dbg(dev, "GTPv1-U: new PDP ctx id=%x/%x ssgn=%pI4 ms=%pI4 (pdp=%p)\n",
- pctx->u.v1.i_tei, pctx->u.v1.o_tei,
- &pctx->sgsn_addr_ip4, &pctx->ms_addr_ip4, pctx);
+ pr_debug("GTPv1-U: new PDP ctx id=%x/%x ssgn=%pI4 ms=%pI4 (pdp=%p)\n",
+ pctx->u.v1.i_tei, pctx->u.v1.o_tei,
+ &pctx->sgsn_addr_ip4, &pctx->ms_addr_ip4, pctx);
break;
}
@@ -988,8 +987,8 @@ static int ipv4_pdp_add(struct net_device *dev, struct genl_info *info)
static int gtp_genl_new_pdp(struct sk_buff *skb, struct genl_info *info)
{
- struct net_device *dev;
- struct net *net;
+ struct gtp_dev *gtp;
+ int err;
if (!info->attrs[GTPA_VERSION] ||
!info->attrs[GTPA_LINK] ||
@@ -1013,77 +1012,79 @@ static int gtp_genl_new_pdp(struct sk_buff *skb, struct genl_info *info)
return -EINVAL;
}
- net = gtp_genl_get_net(sock_net(skb->sk), info->attrs);
- if (IS_ERR(net))
- return PTR_ERR(net);
+ rcu_read_lock();
- /* Check if there's an existing gtpX device to configure */
- dev = gtp_find_dev(net, nla_get_u32(info->attrs[GTPA_LINK]));
- if (dev == NULL) {
- put_net(net);
- return -ENODEV;
+ gtp = gtp_genl_find_dev(sock_net(skb->sk), info->attrs);
+ if (!gtp) {
+ err = -ENODEV;
+ goto out_unlock;
}
- put_net(net);
- return ipv4_pdp_add(dev, info);
+ err = ipv4_pdp_add(gtp, info);
+
+out_unlock:
+ rcu_read_unlock();
+ return err;
}
static int gtp_genl_del_pdp(struct sk_buff *skb, struct genl_info *info)
{
- struct net_device *dev;
struct pdp_ctx *pctx;
struct gtp_dev *gtp;
- struct net *net;
+ int err = 0;
if (!info->attrs[GTPA_VERSION] ||
!info->attrs[GTPA_LINK])
return -EINVAL;
- net = gtp_genl_get_net(sock_net(skb->sk), info->attrs);
- if (IS_ERR(net))
- return PTR_ERR(net);
+ rcu_read_lock();
- /* Check if there's an existing gtpX device to configure */
- dev = gtp_find_dev(net, nla_get_u32(info->attrs[GTPA_LINK]));
- if (dev == NULL) {
- put_net(net);
- return -ENODEV;
+ gtp = gtp_genl_find_dev(sock_net(skb->sk), info->attrs);
+ if (!gtp) {
+ err = -ENODEV;
+ goto out_unlock;
}
- put_net(net);
-
- gtp = netdev_priv(dev);
switch (nla_get_u32(info->attrs[GTPA_VERSION])) {
case GTP_V0:
- if (!info->attrs[GTPA_TID])
- return -EINVAL;
+ 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])
- return -EINVAL;
+ 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:
- return -EINVAL;
+ err = -EINVAL;
+ goto out_unlock;
}
- if (pctx == NULL)
- return -ENOENT;
+ if (!pctx) {
+ err = -ENOENT;
+ goto out_unlock;
+ }
if (pctx->gtp_version == GTP_V0)
- netdev_dbg(dev, "GTPv0-U: deleting tunnel id = %llx (pdp %p)\n",
- pctx->u.v0.tid, pctx);
+ pr_debug("GTPv0-U: deleting tunnel id = %llx (pdp %p)\n",
+ pctx->u.v0.tid, pctx);
else if (pctx->gtp_version == GTP_V1)
- netdev_dbg(dev, "GTPv1-U: deleting tunnel id = %x/%x (pdp %p)\n",
- pctx->u.v1.i_tei, pctx->u.v1.o_tei, pctx);
+ pr_debug("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);
hlist_del_rcu(&pctx->hlist_addr);
kfree_rcu(pctx, rcu_head);
- return 0;
+out_unlock:
+ rcu_read_unlock();
+ return err;
}
static struct genl_family gtp_genl_family;
@@ -1127,11 +1128,9 @@ static int gtp_genl_fill_info(struct sk_buff *skb, u32 snd_portid, u32 snd_seq,
static int gtp_genl_get_pdp(struct sk_buff *skb, struct genl_info *info)
{
struct pdp_ctx *pctx = NULL;
- struct net_device *dev;
struct sk_buff *skb2;
struct gtp_dev *gtp;
u32 gtp_version;
- struct net *net;
int err;
if (!info->attrs[GTPA_VERSION] ||
@@ -1147,21 +1146,14 @@ static int gtp_genl_get_pdp(struct sk_buff *skb, struct genl_info *info)
return -EINVAL;
}
- net = gtp_genl_get_net(sock_net(skb->sk), info->attrs);
- if (IS_ERR(net))
- return PTR_ERR(net);
-
- /* Check if there's an existing gtpX device to configure */
- dev = gtp_find_dev(net, nla_get_u32(info->attrs[GTPA_LINK]));
- if (dev == NULL) {
- put_net(net);
- return -ENODEV;
- }
- put_net(net);
-
- gtp = netdev_priv(dev);
-
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]);
--
2.10.2
next prev parent reply other threads:[~2017-01-30 16:37 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-30 16:37 [PATCH net-next v2 0/6] gtp: misc improvements Andreas Schultz
2017-01-30 16:37 ` [PATCH net-next v2 1/6] gtp: make GTP sockets in gtp_newlink optional Andreas Schultz
2017-02-02 14:10 ` Pablo Neira Ayuso
2017-02-02 14:30 ` Andreas Schultz
2017-02-02 14:32 ` Pablo Neira Ayuso
2017-02-06 13:51 ` Harald Welte
2017-01-30 16:37 ` Andreas Schultz [this message]
2017-02-06 13:55 ` [PATCH net-next v2 2/6] gtp: merge gtp_get_net and gtp_genl_find_dev Harald Welte
2017-02-13 14:13 ` Andreas Schultz
2017-02-13 14:51 ` Pablo Neira Ayuso
2017-01-30 16:37 ` [PATCH net-next v2 3/6] gtp: unify genl_find_pdp and prepare for per socket lookup Andreas Schultz
2017-02-02 14:19 ` Pablo Neira Ayuso
2017-02-02 14:27 ` Andreas Schultz
2017-02-02 14:31 ` Pablo Neira Ayuso
2017-02-06 13:56 ` Harald Welte
2017-01-30 16:37 ` [PATCH net-next v2 4/6] gtp: consolidate pdp context destruction into helper Andreas Schultz
2017-02-06 13:58 ` Harald Welte
2017-02-13 14:14 ` Andreas Schultz
2017-01-30 16:37 ` [PATCH net-next v2 5/6] gtp: add socket to pdp context Andreas Schultz
2017-02-02 13:56 ` Pablo Neira Ayuso
2017-02-02 14:12 ` Andreas Schultz
2017-02-02 14:28 ` Pablo Neira Ayuso
2017-02-02 14:38 ` Andreas Schultz
2017-02-02 14:46 ` Pablo Neira Ayuso
2017-02-02 15:07 ` Andreas Schultz
2017-02-06 14:04 ` Harald Welte
2017-01-30 16:37 ` [PATCH net-next v2 6/6] gtp: consolidate gtp socket rx path Andreas Schultz
2017-01-31 18:05 ` [PATCH net-next v2 0/6] gtp: misc improvements David Miller
2017-02-06 13:46 ` Harald Welte
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=20170130163713.17524-3-aschultz@tpip.net \
--to=aschultz@tpip.net \
--cc=Lionel.Gauthier@eurecom.fr \
--cc=laforge@gnumonks.org \
--cc=netdev@vger.kernel.org \
--cc=openbsc@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).