gtp: add initial driver for datapath of GPRS Tunneling Protocol (GTP-U)
Subsystems (4)
Pablo Neira Ayuso
maintainerPATCH v2 1/1 gtp: add initial driver for datapath of GPRS Tunneling Protocol (GTP-U)
This is an initial implementation of a netdev driver for GTP datapath (GTP-U) v0 and v1, according to the GSM TS 09.60 and 3GPP TS 29.060 standards. This tunneling protocol is used to prevent subscribers from accessing mobile carrier core network infrastructure.
This implementation requires a GGSN userspace daemon that implements the signaling protocol (GTP-C), such as OpenGGSN [1]. This userspace daemon updates the PDP context database that represents active subscriber sessions through a genetlink interface.
For more context on this tunneling protocol, you can check the slides that were presented during the NetDev 1.1 [2].
Only IPv4 is supported at this time.
[1] http://git.osmocom.org/openggsn/
[2] http://www.netdevconf.org/1.1/proceedings/slides/schultz-welte-osmocom-gtp.pdf
---
v2: Rebase on top of current HEAD to resolve minor conflict with recent PPP
updates in include/uapi/linux/if_link.h so this applies cleanly.
drivers/net/Kconfig | 17 + drivers/net/Makefile | 1 + drivers/net/gtp.c | 1364 ++++++++++++++++++++++++++++++++++++++++++ include/net/gtp.h | 34 ++ include/uapi/linux/Kbuild | 1 + include/uapi/linux/gtp.h | 33 + include/uapi/linux/if_link.h | 10 + include/uapi/linux/udp.h | 3 +- 8 files changed, 1462 insertions(+), 1 deletion(-) create mode 100644 drivers/net/gtp.c create mode 100644 include/net/gtp.h create mode 100644 include/uapi/linux/gtp.h
drivers/net/Kconfig +17 -0
@@ -192,6 +192,23 @@ config GENEVE To compile this driver as a module, choose M here: the module will be called geneve. +config GTP + tristate "GPRS Tunneling Protocol datapath (GTP-U)" + depends on INET && NET_UDP_TUNNEL + select NET_IP_TUNNEL + ---help--- + This allows one to create gtp virtual interfaces that provide + the GPRS Tunneling Protocol datapath (GTP-U). This tunneling protocol + is used to prevent subscribers from accessing mobile carrier core + network infrastructure. This driver requires a userspace software that + implements the signaling protocol (GTP-C) to update its PDP context + base, such as OpenGGSN <http://git.osmocom.org/openggsn/). This + tunneling protocol is implemented according to the GSM TS 09.60 and + 3GPP TS 29.060 standards. + + To compile this drivers as a module, choose M here: the module + wil be called gtp. + config MACSEC tristate "IEEE 802.1AE MAC-level encryption (MACsec)" select CRYPTO
drivers/net/Makefile +1 -0
@@ -25,6 +25,7 @@ obj-$(CONFIG_VETH) += veth.o obj-$(CONFIG_VIRTIO_NET) += virtio_net.o obj-$(CONFIG_VXLAN) += vxlan.o obj-$(CONFIG_GENEVE) += geneve.o +obj-$(CONFIG_GTP) += gtp.o obj-$(CONFIG_NLMON) += nlmon.o obj-$(CONFIG_NET_VRF) += vrf.o
drivers/net/gtp.c new file +1364 -0
1,364 lines not on this page · raw message
include/net/gtp.h new file +34 -0
@@ -0,0 +1,34 @@ +#ifndef _GTP_H_ +#define _GTP_H + +/* General GTP protocol related definitions. */ + +#define GTP0_PORT 3386 +#define GTP1U_PORT 2152 + +#define GTP_TPDU 255 + +struct gtp0_header {/* According to GSM TS 09.60. */ +__u8 flags; +__u8 type; +__be16 length; +__be16 seq; +__be16 flow; +__u8 number; +__u8 spare[3 ]; +__be64 tid; +} __attribute__ ((packed)); + +struct gtp1_header {/* According to 3GPP TS 29.060. */ +__u8 flags; +__u8 type; +__be16 length; +__be32 tid; +} __attribute__ ((packed)); + +#define GTP1_F_NPDU 0x01 +#define GTP1_F_SEQ 0x02 +#define GTP1_F_EXTHDR 0x04 +#define GTP1_F_MASK 0x07 + +#endif
include/uapi/linux/Kbuild +1 -0
@@ -141,6 +141,7 @@ header-y += gfs2_ondisk.h header-y += gigaset_dev.h header-y += gpio.h header-y += gsmmux.h +header-y += gtp.h header-y += hdlcdrv.h header-y += hdlc.h header-y += hdreg.h
include/uapi/linux/gtp.h new file +33 -0
@@ -0,0 +1,33 @@ +#ifndef _UAPI_LINUX_GTP_H_ +#define _UAPI_LINUX_GTP_H__ + +enum gtp_genl_cmds { +GTP_CMD_NEWPDP , +GTP_CMD_DELPDP , +GTP_CMD_GETPDP , + +GTP_CMD_MAX , +}; + +enum gtp_version { +GTP_V0 =0 , +GTP_V1 , +}; + +enum gtp_attrs { +GTPA_UNSPEC =0 , +GTPA_LINK , +GTPA_VERSION , +GTPA_TID ,/* for GTPv0 only */ +GTPA_SGSN_ADDRESS , +GTPA_MS_ADDRESS , +GTPA_FLOW , +GTPA_NET_NS_FD , +GTPA_I_TEI ,/* for GTPv1 only */ +GTPA_O_TEI ,/* for GTPv1 only */ +GTPA_PAD , + __GTPA_MAX, +}; +#define GTPA_MAX (__GTPA_MAX + 1) + +#endif /* _UAPI_LINUX_GTP_H_ */
include/uapi/linux/if_link.h +10 -0
@@ -529,6 +529,16 @@ enum { };#define IFLA_PPP_MAX (__IFLA_PPP_MAX - 1) +/* GTP section */ +enum { +IFLA_GTP_UNSPEC , +IFLA_GTP_FD0 , +IFLA_GTP_FD1 , +IFLA_GTP_PDP_HASHSIZE , + __IFLA_GTP_MAX, +}; +#define IFLA_GTP_MAX (__IFLA_GTP_MAX - 1) +/* Bonding section */ enum {
include/uapi/linux/udp.h +2 -1
@@ -36,6 +36,7 @@ struct udphdr {#define UDP_ENCAP_ESPINUDP_NON_IKE 1/* draft-ietf-ipsec-nat-t-ike-00/01 */ #define UDP_ENCAP_ESPINUDP 2/* draft-ietf-ipsec-udp-encaps-06 */ #define UDP_ENCAP_L2TPINUDP 3/* rfc2661 */ - +#define UDP_ENCAP_GTP0 4/* GSM TS 09.60 */ +#define UDP_ENCAP_GTP1U 5/* 3GPP TS 29.060 */ #endif /* _UAPI_LINUX_UDP_H */
Signature · 1 line
2.1.4
From: Pablo Neira Ayuso <[email protected]>
Date: Mon, 9 May 2016 00:55:48 +0200
Quoted 15 lines
This is an initial implementation of a netdev driver for GTP datapath (GTP-U) v0 and v1, according to the GSM TS 09.60 and 3GPP TS 29.060 standards. This tunneling protocol is used to prevent subscribers from accessing mobile carrier core network infrastructure.
This implementation requires a GGSN userspace daemon that implements the signaling protocol (GTP-C), such as OpenGGSN [1]. This userspace daemon updates the PDP context database that represents active subscriber sessions through a genetlink interface.
For more context on this tunneling protocol, you can check the slides that were presented during the NetDev 1.1 [2].
Only IPv4 is supported at this time.
Quoted 7 lines
[1] http://git.osmocom.org/openggsn/
[2] http://www.netdevconf.org/1.1/proceedings/slides/schultz-welte-osmocom-gtp.pdfSigned-off-by Pablo Neira Ayuso <[email protected]>---
v2: Rebase on top of current HEAD to resolve minor conflict with recent PPP
updates ininclude/uapi/linux/if_link.hso this applies cleanly.
Applied, thanks.
Quoted 18 lines · David Miller
From: Pablo Neira Ayuso <[email protected]>
Date: Mon, 9 May 2016 00:55:48 +0200Quoted 15 lines
This is an initial implementation of a netdev driver for GTP datapath (GTP-U) v0 and v1, according to the GSM TS 09.60 and 3GPP TS 29.060 standards. This tunneling protocol is used to prevent subscribers from accessing mobile carrier core network infrastructure.
This implementation requires a GGSN userspace daemon that implements the signaling protocol (GTP-C), such as OpenGGSN [1]. This userspace daemon updates the PDP context database that represents active subscriber sessions through a genetlink interface.
For more context on this tunneling protocol, you can check the slides that were presented during the NetDev 1.1 [2].
Only IPv4 is supported at this time.
Is there a timeline for adding IPv6 support?
Tom
Quoted 9 lines
Quoted 7 lines
[1] http://git.osmocom.org/openggsn/
[2] http://www.netdevconf.org/1.1/proceedings/slides/schultz-welte-osmocom-gtp.pdfSigned-off-by Pablo Neira Ayuso <[email protected]>---
v2: Rebase on top of current HEAD to resolve minor conflict with recent PPP
updates ininclude/uapi/linux/if_link.hso this applies cleanly.Applied, thanks.
Pablo Neira Ayuso
maintainerQuoted 14 lines · Tom Herbert
Quoted 13 lines · David Miller
From: Pablo Neira Ayuso <[email protected]>
Date: Mon, 9 May 2016 00:55:48 +0200Quoted 10 lines
This is an initial implementation of a netdev driver for GTP datapath (GTP-U) v0 and v1, according to the GSM TS 09.60 and 3GPP TS 29.060 standards. This tunneling protocol is used to prevent subscribers from accessing mobile carrier core network infrastructure.
This implementation requires a GGSN userspace daemon that implements the signaling protocol (GTP-C), such as OpenGGSN [1]. This userspace daemon updates the PDP context database that represents active subscriber sessions through a genetlink interface.
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
For more context on this tunneling protocol, you can check the slides that were presented during the NetDev 1.1 [2].
Only IPv4 is supported at this time.
Is there a timeline for adding IPv6 support?
There is a preliminary kernel patch to add IPv6 that seems to be untested yet, I can share it with you or anyone else want to have a look. Specifically, there are missing bits on the netlink side of the PDP context database to support SGSN and MS IPv6 address, but that shouldn't be much of a problem.
On the userspace side, the userspace daemon OpenGGSN still doesn't support IPv6. Adding IPv6 support to this daemon is a bit of a PITA, several people using it in production told me that the daemon runs stable for production, but from a developer perspective the current codebase look not easy to extend (quite many stuff very IPv4 specific, I already spend time trying to refactor it two years ago to prepare this support). Meanwhile, this triggered a new daemon daemon implementation osmo-ggsn to replace it, I posted a proof-of-concept on the openbsc mailing list, but nobody jumped on this to support this development effort so far.
Quoted 22 lines · Pablo Neira Ayuso
drivers/net/gtp.c new file +22
-0+static int gtp1u_udp_encap_recv (struct gtp_dev *gtp,struct sk_buff *skb, +bool xnet) +{ +unsigned int hdrlen =sizeof (struct udphdr ) + +sizeof (struct gtp1_header ); +struct gtp1_header *gtp1; +struct pdp_ctx *pctx; +int ret =0 ; + +if (!pskb_may_pull (skb, hdrlen)) +return -1 ; + + gtp1 = (struct gtp1_header *)(skb->data +sizeof (struct udphdr )); + +if ((gtp1->flags >>5 ) !=GTP_V1 ) +return 1 ; + +if (gtp1->type !=GTP_TPDU ) +return 1 ; + +/* 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.".
drivers/net/gtp.c line 254
Quoted 10 lines
drivers/net/gtp.c new file +10
-0+* +* If any of the bit is set, then the remaining ones also have to be +* set. +*/ +if (gtp1->flags >P1_F_MASK ) + hdrlen +=4 ; + +/* Make sure the header is larger enough, including extensions. */ +if (!pskb_may_pull (skb, hdrlen)) +return -1 ;
You need to reload gtp1 here, as the previous pskb_may_pull() might have reallocated skb->head
drivers/net/gtp.c line 257
Quoted 3 lines
drivers/net/gtp.c new file +3
-0+ +rcu_read_lock (); + pctx =gtp1_pdp_find (gtp,ntohl (gtp1->tid));
Or risk a use after free here.
Quoted 19 lines
drivers/net/gtp.c new file +19
-0+if (!pctx) { +netdev_dbg (gtp->dev,"No PDP ctx to decap skb=%p\n" , skb); + ret =-1 ; + goto out_rcu; + } + +if (!gtp_check_src_ms (skb, pctx, hdrlen)) { +netdev_dbg (gtp->dev,"No PDP ctx for this MS\n" ); + ret =-1 ; + goto out_rcu; + } +rcu_read_unlock (); + +/* Get rid of the GTP + UDP headers. */ +return iptunnel_pull_header (skb, hdrlen, skb->protocol, xnet); +out_rcu: +rcu_read_unlock (); +return ret; +}
Quoted 2 lines · Pablo Neira Ayuso
drivers/net/gtp.c new file +2
-0+static int gtp_genl_new_pdp (struct sk_buff *skb,struct genl_info *info) +{
...
drivers/net/gtp.c line 1032
Quoted 11 lines
drivers/net/gtp.c new file +11
-0+ + 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 ) +return -ENODEV ; + +return ipv4_pdp_add (dev, info);
Seems you are leaking struct net at least in the error path.