From: Tom Herbert <tom@quantonium.net>
To: davem@davemloft.net
Cc: pablo@netfilter.org, laforge@gnumonks.org, aschultz@tpip.net,
netdev@vger.kernel.org, rohit@quantonium.net,
Tom Herbert <tom@quantonium.net>
Subject: [PATCH v6 net-next 07/12] gtp: udp recv clean up
Date: Thu, 26 Oct 2017 12:09:24 -0700 [thread overview]
Message-ID: <20171026190929.11619-8-tom@quantonium.net> (raw)
In-Reply-To: <20171026190929.11619-1-tom@quantonium.net>
Create separate UDP receive functions for GTP version 0 and version 1.
Set encap_rcv appropriately when configuring a socket.
Signed-off-by: Tom Herbert <tom@quantonium.net>
---
drivers/net/gtp.c | 100 ++++++++++++++++++++++++++----------------------------
1 file changed, 49 insertions(+), 51 deletions(-)
diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c
index 00e5ea5cb935..a6e2e0a1f424 100644
--- a/drivers/net/gtp.c
+++ b/drivers/net/gtp.c
@@ -225,14 +225,20 @@ static int gtp_rx(struct pdp_ctx *pctx, struct sk_buff *skb,
return 0;
}
-/* 1 means pass up to the stack, -1 means drop and 0 means decapsulated. */
-static int gtp0_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb)
+/* UDP encapsulation receive handler for GTPv0-U . See net/ipv4/udp.c.
+ * Return codes: 0: success, <0: error, >0: pass up to userspace UDP socket.
+ */
+static int gtp0_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
{
+ struct gtp_dev *gtp = rcu_dereference_sk_user_data(sk);
unsigned int hdrlen = sizeof(struct udphdr) +
sizeof(struct gtp0_header);
struct gtp0_header *gtp0;
struct pdp_ctx *pctx;
+ if (!gtp)
+ goto pass;
+
if (!pskb_may_pull(skb, hdrlen))
goto drop;
@@ -244,26 +250,41 @@ static int gtp0_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb)
if (gtp0->type != GTP_TPDU)
goto pass;
+ netdev_dbg(gtp->dev, "received GTP0 packet\n");
+
pctx = gtp0_pdp_find(gtp, be64_to_cpu(gtp0->tid));
if (!pctx) {
netdev_dbg(gtp->dev, "No PDP ctx to decap skb=%p\n", skb);
goto pass;
}
- return gtp_rx(pctx, skb, hdrlen, gtp->role);
+ if (!gtp_rx(pctx, skb, hdrlen, gtp->role)) {
+ /* Successfully received */
+ return 0;
+ }
+
drop:
- return -1;
+ kfree_skb(skb);
+ return 0;
+
pass:
return 1;
}
-static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb)
+/* UDP encapsulation receive handler for GTPv0-U . See net/ipv4/udp.c.
+ * Return codes: 0: success, <0: error, >0: pass up to userspace UDP socket.
+ */
+static int gtp1u_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
{
+ struct gtp_dev *gtp = rcu_dereference_sk_user_data(sk);
unsigned int hdrlen = sizeof(struct udphdr) +
sizeof(struct gtp1_header);
struct gtp1_header *gtp1;
struct pdp_ctx *pctx;
+ if (!gtp)
+ goto pass;
+
if (!pskb_may_pull(skb, hdrlen))
goto drop;
@@ -275,6 +296,8 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb)
if (gtp1->type != GTP_TPDU)
goto pass;
+ netdev_dbg(gtp->dev, "received GTP1 packet\n");
+
/* From 29.060: "This field shall be present if and only if any one or
* more of the S, PN and E flags are set.".
*
@@ -296,9 +319,15 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb)
goto drop;
}
- return gtp_rx(pctx, skb, hdrlen, gtp->role);
+ if (!gtp_rx(pctx, skb, hdrlen, gtp->role)) {
+ /* Successfully received */
+ return 0;
+ }
+
drop:
- return -1;
+ kfree_skb(skb);
+ return 0;
+
pass:
return 1;
}
@@ -329,49 +358,6 @@ static void gtp_encap_disable(struct gtp_dev *gtp)
gtp_encap_disable_sock(gtp->sk1u);
}
-/* UDP encapsulation receive handler. See net/ipv4/udp.c.
- * Return codes: 0: success, <0: error, >0: pass up to userspace UDP socket.
- */
-static int gtp_encap_recv(struct sock *sk, struct sk_buff *skb)
-{
- struct gtp_dev *gtp;
- int ret = 0;
-
- gtp = rcu_dereference_sk_user_data(sk);
- if (!gtp)
- return 1;
-
- netdev_dbg(gtp->dev, "encap_recv sk=%p\n", sk);
-
- switch (udp_sk(sk)->encap_type) {
- case UDP_ENCAP_GTP0:
- netdev_dbg(gtp->dev, "received GTP0 packet\n");
- ret = gtp0_udp_encap_recv(gtp, skb);
- break;
- case UDP_ENCAP_GTP1U:
- netdev_dbg(gtp->dev, "received GTP1U packet\n");
- ret = gtp1u_udp_encap_recv(gtp, skb);
- break;
- default:
- ret = -1; /* Shouldn't happen. */
- }
-
- switch (ret) {
- case 1:
- netdev_dbg(gtp->dev, "pass up to the process\n");
- break;
- case 0:
- break;
- case -1:
- netdev_dbg(gtp->dev, "GTP packet has been dropped\n");
- kfree_skb(skb);
- ret = 0;
- break;
- }
-
- return ret;
-}
-
static int gtp_dev_init(struct net_device *dev)
{
struct gtp_dev *gtp = netdev_priv(dev);
@@ -824,9 +810,21 @@ static struct sock *gtp_encap_enable_socket(int fd, int type,
sk = sock->sk;
sock_hold(sk);
+ switch (type) {
+ case UDP_ENCAP_GTP0:
+ tuncfg.encap_rcv = gtp0_udp_encap_recv;
+ break;
+ case UDP_ENCAP_GTP1U:
+ tuncfg.encap_rcv = gtp1u_udp_encap_recv;
+ break;
+ default:
+ pr_debug("Unknown encap type %u\n", type);
+ sk = ERR_PTR(-EINVAL);
+ goto out_sock;
+ }
+
tuncfg.sk_user_data = gtp;
tuncfg.encap_type = type;
- tuncfg.encap_rcv = gtp_encap_recv;
tuncfg.encap_destroy = gtp_encap_destroy;
setup_udp_tunnel_sock(sock_net(sock->sk), sock, &tuncfg);
--
2.11.0
next prev parent reply other threads:[~2017-10-26 19:10 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-26 19:09 [PATCH v6 net-next 00/12] gtp: Additional feature support - Part I Tom Herbert
2017-10-26 19:09 ` [PATCH v6 net-next 01/12] iptunnel: Add common functions to get a tunnel route Tom Herbert
2017-10-26 19:09 ` [PATCH v6 net-next 02/12] vxlan: Call common functions to get tunnel routes Tom Herbert
2017-10-31 11:40 ` kbuild test robot
2017-10-26 19:09 ` [PATCH v6 net-next 03/12] gtp: Call common functions to get tunnel routes and add dst_cache Tom Herbert
2017-10-26 19:09 ` [PATCH v6 net-next 04/12] iptunnel: Generalize tunnel update pmtu Tom Herbert
2017-10-26 19:09 ` [PATCH v6 net-next 05/12] gtp: Change to use gro_cells Tom Herbert
2017-10-26 19:35 ` Subash Abhinov Kasiviswanathan
2017-10-26 19:51 ` Tom Herbert
2017-10-26 19:09 ` [PATCH v6 net-next 06/12] gtp: Use goto for exceptions in gtp_udp_encap_recv funcs Tom Herbert
2017-10-26 19:09 ` Tom Herbert [this message]
2017-10-26 19:09 ` [PATCH v6 net-next 08/12] gtp: Call function to update path mtu Tom Herbert
2017-10-26 19:09 ` [PATCH v6 net-next 09/12] gtp: Eliminate pktinfo and add port configuration Tom Herbert
2017-10-26 19:09 ` [PATCH v6 net-next 10/12] gtp: Experimental encapsulation of IPv6 packets Tom Herbert
2017-10-26 19:09 ` [PATCH v6 net-next 11/12] gtp: Experimental support encpasulating over IPv6 Tom Herbert
2017-10-26 19:09 ` [PATCH v6 net-next 12/12] gtp: Allow configuring GTP interface as standalone Tom Herbert
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=20171026190929.11619-8-tom@quantonium.net \
--to=tom@quantonium.net \
--cc=aschultz@tpip.net \
--cc=davem@davemloft.net \
--cc=laforge@gnumonks.org \
--cc=netdev@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=rohit@quantonium.net \
/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