162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci=====================================
462306a36Sopenharmony_ciThe Linux kernel GTP tunneling module
562306a36Sopenharmony_ci=====================================
662306a36Sopenharmony_ci
762306a36Sopenharmony_ciDocumentation by
862306a36Sopenharmony_ci		 Harald Welte <laforge@gnumonks.org> and
962306a36Sopenharmony_ci		 Andreas Schultz <aschultz@tpip.net>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ciIn 'drivers/net/gtp.c' you are finding a kernel-level implementation
1262306a36Sopenharmony_ciof a GTP tunnel endpoint.
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciWhat is GTP
1562306a36Sopenharmony_ci===========
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ciGTP is the Generic Tunnel Protocol, which is a 3GPP protocol used for
1862306a36Sopenharmony_citunneling User-IP payload between a mobile station (phone, modem)
1962306a36Sopenharmony_ciand the interconnection between an external packet data network (such
2062306a36Sopenharmony_cias the internet).
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ciSo when you start a 'data connection' from your mobile phone, the
2362306a36Sopenharmony_ciphone will use the control plane to signal for the establishment of
2462306a36Sopenharmony_cisuch a tunnel between that external data network and the phone.  The
2562306a36Sopenharmony_citunnel endpoints thus reside on the phone and in the gateway.  All
2662306a36Sopenharmony_ciintermediate nodes just transport the encapsulated packet.
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ciThe phone itself does not implement GTP but uses some other
2962306a36Sopenharmony_citechnology-dependent protocol stack for transmitting the user IP
3062306a36Sopenharmony_cipayload, such as LLC/SNDCP/RLC/MAC.
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ciAt some network element inside the cellular operator infrastructure
3362306a36Sopenharmony_ci(SGSN in case of GPRS/EGPRS or classic UMTS, hNodeB in case of a 3G
3462306a36Sopenharmony_cifemtocell, eNodeB in case of 4G/LTE), the cellular protocol stacking
3562306a36Sopenharmony_ciis translated into GTP *without breaking the end-to-end tunnel*.  So
3662306a36Sopenharmony_ciintermediate nodes just perform some specific relay function.
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ciAt some point the GTP packet ends up on the so-called GGSN (GSM/UMTS)
3962306a36Sopenharmony_cior P-GW (LTE), which terminates the tunnel, decapsulates the packet
4062306a36Sopenharmony_ciand forwards it onto an external packet data network.  This can be
4162306a36Sopenharmony_cipublic internet, but can also be any private IP network (or even
4262306a36Sopenharmony_citheoretically some non-IP network like X.25).
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ciYou can find the protocol specification in 3GPP TS 29.060, available
4562306a36Sopenharmony_cipublicly via the 3GPP website at http://www.3gpp.org/DynaReport/29060.htm
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ciA direct PDF link to v13.6.0 is provided for convenience below:
4862306a36Sopenharmony_cihttp://www.etsi.org/deliver/etsi_ts/129000_129099/129060/13.06.00_60/ts_129060v130600p.pdf
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ciThe Linux GTP tunnelling module
5162306a36Sopenharmony_ci===============================
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ciThe module implements the function of a tunnel endpoint, i.e. it is
5462306a36Sopenharmony_ciable to decapsulate tunneled IP packets in the uplink originated by
5562306a36Sopenharmony_cithe phone, and encapsulate raw IP packets received from the external
5662306a36Sopenharmony_cipacket network in downlink towards the phone.
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ciIt *only* implements the so-called 'user plane', carrying the User-IP
5962306a36Sopenharmony_cipayload, called GTP-U.  It does not implement the 'control plane',
6062306a36Sopenharmony_ciwhich is a signaling protocol used for establishment and teardown of
6162306a36Sopenharmony_ciGTP tunnels (GTP-C).
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ciSo in order to have a working GGSN/P-GW setup, you will need a
6462306a36Sopenharmony_ciuserspace program that implements the GTP-C protocol and which then
6562306a36Sopenharmony_ciuses the netlink interface provided by the GTP-U module in the kernel
6662306a36Sopenharmony_cito configure the kernel module.
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ciThis split architecture follows the tunneling modules of other
6962306a36Sopenharmony_ciprotocols, e.g. PPPoE or L2TP, where you also run a userspace daemon
7062306a36Sopenharmony_cito handle the tunnel establishment, authentication etc. and only the
7162306a36Sopenharmony_cidata plane is accelerated inside the kernel.
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ciDon't be confused by terminology:  The GTP User Plane goes through
7462306a36Sopenharmony_cikernel accelerated path, while the GTP Control Plane goes to
7562306a36Sopenharmony_ciUserspace :)
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ciThe official homepage of the module is at
7862306a36Sopenharmony_cihttps://osmocom.org/projects/linux-kernel-gtp-u/wiki
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ciUserspace Programs with Linux Kernel GTP-U support
8162306a36Sopenharmony_ci==================================================
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ciAt the time of this writing, there are at least two Free Software
8462306a36Sopenharmony_ciimplementations that implement GTP-C and can use the netlink interface
8562306a36Sopenharmony_cito make use of the Linux kernel GTP-U support:
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci* OpenGGSN (classic 2G/3G GGSN in C):
8862306a36Sopenharmony_ci  https://osmocom.org/projects/openggsn/wiki/OpenGGSN
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci* ergw (GGSN + P-GW in Erlang):
9162306a36Sopenharmony_ci  https://github.com/travelping/ergw
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ciUserspace Library / Command Line Utilities
9462306a36Sopenharmony_ci==========================================
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ciThere is a userspace library called 'libgtpnl' which is based on
9762306a36Sopenharmony_cilibmnl and which implements a C-language API towards the netlink
9862306a36Sopenharmony_ciinterface provided by the Kernel GTP module:
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_cihttp://git.osmocom.org/libgtpnl/
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ciProtocol Versions
10362306a36Sopenharmony_ci=================
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ciThere are two different versions of GTP-U: v0 [GSM TS 09.60] and v1
10662306a36Sopenharmony_ci[3GPP TS 29.281].  Both are implemented in the Kernel GTP module.
10762306a36Sopenharmony_ciVersion 0 is a legacy version, and deprecated from recent 3GPP
10862306a36Sopenharmony_cispecifications.
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ciGTP-U uses UDP for transporting PDUs.  The receiving UDP port is 2151
11162306a36Sopenharmony_cifor GTPv1-U and 3386 for GTPv0-U.
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ciThere are three versions of GTP-C: v0, v1, and v2.  As the kernel
11462306a36Sopenharmony_cidoesn't implement GTP-C, we don't have to worry about this.  It's the
11562306a36Sopenharmony_ciresponsibility of the control plane implementation in userspace to
11662306a36Sopenharmony_ciimplement that.
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ciIPv6
11962306a36Sopenharmony_ci====
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ciThe 3GPP specifications indicate either IPv4 or IPv6 can be used both
12262306a36Sopenharmony_cion the inner (user) IP layer, or on the outer (transport) layer.
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ciUnfortunately, the Kernel module currently supports IPv6 neither for
12562306a36Sopenharmony_cithe User IP payload, nor for the outer IP layer.  Patches or other
12662306a36Sopenharmony_ciContributions to fix this are most welcome!
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ciMailing List
12962306a36Sopenharmony_ci============
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ciIf you have questions regarding how to use the Kernel GTP module from
13262306a36Sopenharmony_ciyour own software, or want to contribute to the code, please use the
13362306a36Sopenharmony_ciosmocom-net-grps mailing list for related discussion. The list can be
13462306a36Sopenharmony_cireached at osmocom-net-gprs@lists.osmocom.org and the mailman
13562306a36Sopenharmony_ciinterface for managing your subscription is at
13662306a36Sopenharmony_cihttps://lists.osmocom.org/mailman/listinfo/osmocom-net-gprs
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ciIssue Tracker
13962306a36Sopenharmony_ci=============
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ciThe Osmocom project maintains an issue tracker for the Kernel GTP-U
14262306a36Sopenharmony_cimodule at
14362306a36Sopenharmony_cihttps://osmocom.org/projects/linux-kernel-gtp-u/issues
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ciHistory / Acknowledgements
14662306a36Sopenharmony_ci==========================
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ciThe Module was originally created in 2012 by Harald Welte, but never
14962306a36Sopenharmony_cicompleted.  Pablo came in to finish the mess Harald left behind.  But
15062306a36Sopenharmony_cidoe to a lack of user interest, it never got merged.
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ciIn 2015, Andreas Schultz came to the rescue and fixed lots more bugs,
15362306a36Sopenharmony_ciextended it with new features and finally pushed all of us to get it
15462306a36Sopenharmony_cimainline, where it was merged in 4.7.0.
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ciArchitectural Details
15762306a36Sopenharmony_ci=====================
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ciLocal GTP-U entity and tunnel identification
16062306a36Sopenharmony_ci--------------------------------------------
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ciGTP-U uses UDP for transporting PDU's. The receiving UDP port is 2152
16362306a36Sopenharmony_cifor GTPv1-U and 3386 for GTPv0-U.
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ciThere is only one GTP-U entity (and therefore SGSN/GGSN/S-GW/PDN-GW
16662306a36Sopenharmony_ciinstance) per IP address. Tunnel Endpoint Identifier (TEID) are unique
16762306a36Sopenharmony_ciper GTP-U entity.
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ciA specific tunnel is only defined by the destination entity. Since the
17062306a36Sopenharmony_cidestination port is constant, only the destination IP and TEID define
17162306a36Sopenharmony_cia tunnel. The source IP and Port have no meaning for the tunnel.
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ciTherefore:
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci  * when sending, the remote entity is defined by the remote IP and
17662306a36Sopenharmony_ci    the tunnel endpoint id. The source IP and port have no meaning and
17762306a36Sopenharmony_ci    can be changed at any time.
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci  * when receiving the local entity is defined by the local
18062306a36Sopenharmony_ci    destination IP and the tunnel endpoint id. The source IP and port
18162306a36Sopenharmony_ci    have no meaning and can change at any time.
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci[3GPP TS 29.281] Section 4.3.0 defines this so::
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci  The TEID in the GTP-U header is used to de-multiplex traffic
18662306a36Sopenharmony_ci  incoming from remote tunnel endpoints so that it is delivered to the
18762306a36Sopenharmony_ci  User plane entities in a way that allows multiplexing of different
18862306a36Sopenharmony_ci  users, different packet protocols and different QoS levels.
18962306a36Sopenharmony_ci  Therefore no two remote GTP-U endpoints shall send traffic to a
19062306a36Sopenharmony_ci  GTP-U protocol entity using the same TEID value except
19162306a36Sopenharmony_ci  for data forwarding as part of mobility procedures.
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ciThe definition above only defines that two remote GTP-U endpoints
19462306a36Sopenharmony_ci*should not* send to the same TEID, it *does not* forbid or exclude
19562306a36Sopenharmony_cisuch a scenario. In fact, the mentioned mobility procedures make it
19662306a36Sopenharmony_cinecessary that the GTP-U entity accepts traffic for TEIDs from
19762306a36Sopenharmony_cimultiple or unknown peers.
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ciTherefore, the receiving side identifies tunnels exclusively based on
20062306a36Sopenharmony_ciTEIDs, not based on the source IP!
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ciAPN vs. Network Device
20362306a36Sopenharmony_ci======================
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ciThe GTP-U driver creates a Linux network device for each Gi/SGi
20662306a36Sopenharmony_ciinterface.
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci[3GPP TS 29.281] calls the Gi/SGi reference point an interface. This
20962306a36Sopenharmony_cimay lead to the impression that the GGSN/P-GW can have only one such
21062306a36Sopenharmony_ciinterface.
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ciCorrect is that the Gi/SGi reference point defines the interworking
21362306a36Sopenharmony_cibetween +the 3GPP packet domain (PDN) based on GTP-U tunnel and IP
21462306a36Sopenharmony_cibased networks.
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_ciThere is no provision in any of the 3GPP documents that limits the
21762306a36Sopenharmony_cinumber of Gi/SGi interfaces implemented by a GGSN/P-GW.
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci[3GPP TS 29.061] Section 11.3 makes it clear that the selection of a
22062306a36Sopenharmony_cispecific Gi/SGi interfaces is made through the Access Point Name
22162306a36Sopenharmony_ci(APN)::
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci  2. each private network manages its own addressing. In general this
22462306a36Sopenharmony_ci     will result in different private networks having overlapping
22562306a36Sopenharmony_ci     address ranges. A logically separate connection (e.g. an IP in IP
22662306a36Sopenharmony_ci     tunnel or layer 2 virtual circuit) is used between the GGSN/P-GW
22762306a36Sopenharmony_ci     and each private network.
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci     In this case the IP address alone is not necessarily unique.  The
23062306a36Sopenharmony_ci     pair of values, Access Point Name (APN) and IPv4 address and/or
23162306a36Sopenharmony_ci     IPv6 prefixes, is unique.
23262306a36Sopenharmony_ci
23362306a36Sopenharmony_ciIn order to support the overlapping address range use case, each APN
23462306a36Sopenharmony_ciis mapped to a separate Gi/SGi interface (network device).
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_ci.. note::
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_ci   The Access Point Name is purely a control plane (GTP-C) concept.
23962306a36Sopenharmony_ci   At the GTP-U level, only Tunnel Endpoint Identifiers are present in
24062306a36Sopenharmony_ci   GTP-U packets and network devices are known
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ciTherefore for a given UE the mapping in IP to PDN network is:
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci  * network device + MS IP -> Peer IP + Peer TEID,
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_ciand from PDN to IP network:
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci  * local GTP-U IP + TEID  -> network device
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_ciFurthermore, before a received T-PDU is injected into the network
25162306a36Sopenharmony_cidevice the MS IP is checked against the IP recorded in PDP context.
252