xref: /OK3568_Linux_fs/kernel/Documentation/networking/gtp.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun=====================================
4*4882a593SmuzhiyunThe Linux kernel GTP tunneling module
5*4882a593Smuzhiyun=====================================
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunDocumentation by
8*4882a593Smuzhiyun		 Harald Welte <laforge@gnumonks.org> and
9*4882a593Smuzhiyun		 Andreas Schultz <aschultz@tpip.net>
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunIn 'drivers/net/gtp.c' you are finding a kernel-level implementation
12*4882a593Smuzhiyunof a GTP tunnel endpoint.
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunWhat is GTP
15*4882a593Smuzhiyun===========
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunGTP is the Generic Tunnel Protocol, which is a 3GPP protocol used for
18*4882a593Smuzhiyuntunneling User-IP payload between a mobile station (phone, modem)
19*4882a593Smuzhiyunand the interconnection between an external packet data network (such
20*4882a593Smuzhiyunas the internet).
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunSo when you start a 'data connection' from your mobile phone, the
23*4882a593Smuzhiyunphone will use the control plane to signal for the establishment of
24*4882a593Smuzhiyunsuch a tunnel between that external data network and the phone.  The
25*4882a593Smuzhiyuntunnel endpoints thus reside on the phone and in the gateway.  All
26*4882a593Smuzhiyunintermediate nodes just transport the encapsulated packet.
27*4882a593Smuzhiyun
28*4882a593SmuzhiyunThe phone itself does not implement GTP but uses some other
29*4882a593Smuzhiyuntechnology-dependent protocol stack for transmitting the user IP
30*4882a593Smuzhiyunpayload, such as LLC/SNDCP/RLC/MAC.
31*4882a593Smuzhiyun
32*4882a593SmuzhiyunAt some network element inside the cellular operator infrastructure
33*4882a593Smuzhiyun(SGSN in case of GPRS/EGPRS or classic UMTS, hNodeB in case of a 3G
34*4882a593Smuzhiyunfemtocell, eNodeB in case of 4G/LTE), the cellular protocol stacking
35*4882a593Smuzhiyunis translated into GTP *without breaking the end-to-end tunnel*.  So
36*4882a593Smuzhiyunintermediate nodes just perform some specific relay function.
37*4882a593Smuzhiyun
38*4882a593SmuzhiyunAt some point the GTP packet ends up on the so-called GGSN (GSM/UMTS)
39*4882a593Smuzhiyunor P-GW (LTE), which terminates the tunnel, decapsulates the packet
40*4882a593Smuzhiyunand forwards it onto an external packet data network.  This can be
41*4882a593Smuzhiyunpublic internet, but can also be any private IP network (or even
42*4882a593Smuzhiyuntheoretically some non-IP network like X.25).
43*4882a593Smuzhiyun
44*4882a593SmuzhiyunYou can find the protocol specification in 3GPP TS 29.060, available
45*4882a593Smuzhiyunpublicly via the 3GPP website at http://www.3gpp.org/DynaReport/29060.htm
46*4882a593Smuzhiyun
47*4882a593SmuzhiyunA direct PDF link to v13.6.0 is provided for convenience below:
48*4882a593Smuzhiyunhttp://www.etsi.org/deliver/etsi_ts/129000_129099/129060/13.06.00_60/ts_129060v130600p.pdf
49*4882a593Smuzhiyun
50*4882a593SmuzhiyunThe Linux GTP tunnelling module
51*4882a593Smuzhiyun===============================
52*4882a593Smuzhiyun
53*4882a593SmuzhiyunThe module implements the function of a tunnel endpoint, i.e. it is
54*4882a593Smuzhiyunable to decapsulate tunneled IP packets in the uplink originated by
55*4882a593Smuzhiyunthe phone, and encapsulate raw IP packets received from the external
56*4882a593Smuzhiyunpacket network in downlink towards the phone.
57*4882a593Smuzhiyun
58*4882a593SmuzhiyunIt *only* implements the so-called 'user plane', carrying the User-IP
59*4882a593Smuzhiyunpayload, called GTP-U.  It does not implement the 'control plane',
60*4882a593Smuzhiyunwhich is a signaling protocol used for establishment and teardown of
61*4882a593SmuzhiyunGTP tunnels (GTP-C).
62*4882a593Smuzhiyun
63*4882a593SmuzhiyunSo in order to have a working GGSN/P-GW setup, you will need a
64*4882a593Smuzhiyunuserspace program that implements the GTP-C protocol and which then
65*4882a593Smuzhiyunuses the netlink interface provided by the GTP-U module in the kernel
66*4882a593Smuzhiyunto configure the kernel module.
67*4882a593Smuzhiyun
68*4882a593SmuzhiyunThis split architecture follows the tunneling modules of other
69*4882a593Smuzhiyunprotocols, e.g. PPPoE or L2TP, where you also run a userspace daemon
70*4882a593Smuzhiyunto handle the tunnel establishment, authentication etc. and only the
71*4882a593Smuzhiyundata plane is accelerated inside the kernel.
72*4882a593Smuzhiyun
73*4882a593SmuzhiyunDon't be confused by terminology:  The GTP User Plane goes through
74*4882a593Smuzhiyunkernel accelerated path, while the GTP Control Plane goes to
75*4882a593SmuzhiyunUserspace :)
76*4882a593Smuzhiyun
77*4882a593SmuzhiyunThe official homepage of the module is at
78*4882a593Smuzhiyunhttps://osmocom.org/projects/linux-kernel-gtp-u/wiki
79*4882a593Smuzhiyun
80*4882a593SmuzhiyunUserspace Programs with Linux Kernel GTP-U support
81*4882a593Smuzhiyun==================================================
82*4882a593Smuzhiyun
83*4882a593SmuzhiyunAt the time of this writing, there are at least two Free Software
84*4882a593Smuzhiyunimplementations that implement GTP-C and can use the netlink interface
85*4882a593Smuzhiyunto make use of the Linux kernel GTP-U support:
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun* OpenGGSN (classic 2G/3G GGSN in C):
88*4882a593Smuzhiyun  https://osmocom.org/projects/openggsn/wiki/OpenGGSN
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun* ergw (GGSN + P-GW in Erlang):
91*4882a593Smuzhiyun  https://github.com/travelping/ergw
92*4882a593Smuzhiyun
93*4882a593SmuzhiyunUserspace Library / Command Line Utilities
94*4882a593Smuzhiyun==========================================
95*4882a593Smuzhiyun
96*4882a593SmuzhiyunThere is a userspace library called 'libgtpnl' which is based on
97*4882a593Smuzhiyunlibmnl and which implements a C-language API towards the netlink
98*4882a593Smuzhiyuninterface provided by the Kernel GTP module:
99*4882a593Smuzhiyun
100*4882a593Smuzhiyunhttp://git.osmocom.org/libgtpnl/
101*4882a593Smuzhiyun
102*4882a593SmuzhiyunProtocol Versions
103*4882a593Smuzhiyun=================
104*4882a593Smuzhiyun
105*4882a593SmuzhiyunThere are two different versions of GTP-U: v0 [GSM TS 09.60] and v1
106*4882a593Smuzhiyun[3GPP TS 29.281].  Both are implemented in the Kernel GTP module.
107*4882a593SmuzhiyunVersion 0 is a legacy version, and deprecated from recent 3GPP
108*4882a593Smuzhiyunspecifications.
109*4882a593Smuzhiyun
110*4882a593SmuzhiyunGTP-U uses UDP for transporting PDUs.  The receiving UDP port is 2151
111*4882a593Smuzhiyunfor GTPv1-U and 3386 for GTPv0-U.
112*4882a593Smuzhiyun
113*4882a593SmuzhiyunThere are three versions of GTP-C: v0, v1, and v2.  As the kernel
114*4882a593Smuzhiyundoesn't implement GTP-C, we don't have to worry about this.  It's the
115*4882a593Smuzhiyunresponsibility of the control plane implementation in userspace to
116*4882a593Smuzhiyunimplement that.
117*4882a593Smuzhiyun
118*4882a593SmuzhiyunIPv6
119*4882a593Smuzhiyun====
120*4882a593Smuzhiyun
121*4882a593SmuzhiyunThe 3GPP specifications indicate either IPv4 or IPv6 can be used both
122*4882a593Smuzhiyunon the inner (user) IP layer, or on the outer (transport) layer.
123*4882a593Smuzhiyun
124*4882a593SmuzhiyunUnfortunately, the Kernel module currently supports IPv6 neither for
125*4882a593Smuzhiyunthe User IP payload, nor for the outer IP layer.  Patches or other
126*4882a593SmuzhiyunContributions to fix this are most welcome!
127*4882a593Smuzhiyun
128*4882a593SmuzhiyunMailing List
129*4882a593Smuzhiyun============
130*4882a593Smuzhiyun
131*4882a593SmuzhiyunIf you have questions regarding how to use the Kernel GTP module from
132*4882a593Smuzhiyunyour own software, or want to contribute to the code, please use the
133*4882a593Smuzhiyunosmocom-net-grps mailing list for related discussion. The list can be
134*4882a593Smuzhiyunreached at osmocom-net-gprs@lists.osmocom.org and the mailman
135*4882a593Smuzhiyuninterface for managing your subscription is at
136*4882a593Smuzhiyunhttps://lists.osmocom.org/mailman/listinfo/osmocom-net-gprs
137*4882a593Smuzhiyun
138*4882a593SmuzhiyunIssue Tracker
139*4882a593Smuzhiyun=============
140*4882a593Smuzhiyun
141*4882a593SmuzhiyunThe Osmocom project maintains an issue tracker for the Kernel GTP-U
142*4882a593Smuzhiyunmodule at
143*4882a593Smuzhiyunhttps://osmocom.org/projects/linux-kernel-gtp-u/issues
144*4882a593Smuzhiyun
145*4882a593SmuzhiyunHistory / Acknowledgements
146*4882a593Smuzhiyun==========================
147*4882a593Smuzhiyun
148*4882a593SmuzhiyunThe Module was originally created in 2012 by Harald Welte, but never
149*4882a593Smuzhiyuncompleted.  Pablo came in to finish the mess Harald left behind.  But
150*4882a593Smuzhiyundoe to a lack of user interest, it never got merged.
151*4882a593Smuzhiyun
152*4882a593SmuzhiyunIn 2015, Andreas Schultz came to the rescue and fixed lots more bugs,
153*4882a593Smuzhiyunextended it with new features and finally pushed all of us to get it
154*4882a593Smuzhiyunmainline, where it was merged in 4.7.0.
155*4882a593Smuzhiyun
156*4882a593SmuzhiyunArchitectural Details
157*4882a593Smuzhiyun=====================
158*4882a593Smuzhiyun
159*4882a593SmuzhiyunLocal GTP-U entity and tunnel identification
160*4882a593Smuzhiyun--------------------------------------------
161*4882a593Smuzhiyun
162*4882a593SmuzhiyunGTP-U uses UDP for transporting PDU's. The receiving UDP port is 2152
163*4882a593Smuzhiyunfor GTPv1-U and 3386 for GTPv0-U.
164*4882a593Smuzhiyun
165*4882a593SmuzhiyunThere is only one GTP-U entity (and therefor SGSN/GGSN/S-GW/PDN-GW
166*4882a593Smuzhiyuninstance) per IP address. Tunnel Endpoint Identifier (TEID) are unique
167*4882a593Smuzhiyunper GTP-U entity.
168*4882a593Smuzhiyun
169*4882a593SmuzhiyunA specific tunnel is only defined by the destination entity. Since the
170*4882a593Smuzhiyundestination port is constant, only the destination IP and TEID define
171*4882a593Smuzhiyuna tunnel. The source IP and Port have no meaning for the tunnel.
172*4882a593Smuzhiyun
173*4882a593SmuzhiyunTherefore:
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun  * when sending, the remote entity is defined by the remote IP and
176*4882a593Smuzhiyun    the tunnel endpoint id. The source IP and port have no meaning and
177*4882a593Smuzhiyun    can be changed at any time.
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun  * when receiving the local entity is defined by the local
180*4882a593Smuzhiyun    destination IP and the tunnel endpoint id. The source IP and port
181*4882a593Smuzhiyun    have no meaning and can change at any time.
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun[3GPP TS 29.281] Section 4.3.0 defines this so::
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun  The TEID in the GTP-U header is used to de-multiplex traffic
186*4882a593Smuzhiyun  incoming from remote tunnel endpoints so that it is delivered to the
187*4882a593Smuzhiyun  User plane entities in a way that allows multiplexing of different
188*4882a593Smuzhiyun  users, different packet protocols and different QoS levels.
189*4882a593Smuzhiyun  Therefore no two remote GTP-U endpoints shall send traffic to a
190*4882a593Smuzhiyun  GTP-U protocol entity using the same TEID value except
191*4882a593Smuzhiyun  for data forwarding as part of mobility procedures.
192*4882a593Smuzhiyun
193*4882a593SmuzhiyunThe definition above only defines that two remote GTP-U endpoints
194*4882a593Smuzhiyun*should not* send to the same TEID, it *does not* forbid or exclude
195*4882a593Smuzhiyunsuch a scenario. In fact, the mentioned mobility procedures make it
196*4882a593Smuzhiyunnecessary that the GTP-U entity accepts traffic for TEIDs from
197*4882a593Smuzhiyunmultiple or unknown peers.
198*4882a593Smuzhiyun
199*4882a593SmuzhiyunTherefore, the receiving side identifies tunnels exclusively based on
200*4882a593SmuzhiyunTEIDs, not based on the source IP!
201*4882a593Smuzhiyun
202*4882a593SmuzhiyunAPN vs. Network Device
203*4882a593Smuzhiyun======================
204*4882a593Smuzhiyun
205*4882a593SmuzhiyunThe GTP-U driver creates a Linux network device for each Gi/SGi
206*4882a593Smuzhiyuninterface.
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun[3GPP TS 29.281] calls the Gi/SGi reference point an interface. This
209*4882a593Smuzhiyunmay lead to the impression that the GGSN/P-GW can have only one such
210*4882a593Smuzhiyuninterface.
211*4882a593Smuzhiyun
212*4882a593SmuzhiyunCorrect is that the Gi/SGi reference point defines the interworking
213*4882a593Smuzhiyunbetween +the 3GPP packet domain (PDN) based on GTP-U tunnel and IP
214*4882a593Smuzhiyunbased networks.
215*4882a593Smuzhiyun
216*4882a593SmuzhiyunThere is no provision in any of the 3GPP documents that limits the
217*4882a593Smuzhiyunnumber of Gi/SGi interfaces implemented by a GGSN/P-GW.
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun[3GPP TS 29.061] Section 11.3 makes it clear that the selection of a
220*4882a593Smuzhiyunspecific Gi/SGi interfaces is made through the Access Point Name
221*4882a593Smuzhiyun(APN)::
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun  2. each private network manages its own addressing. In general this
224*4882a593Smuzhiyun     will result in different private networks having overlapping
225*4882a593Smuzhiyun     address ranges. A logically separate connection (e.g. an IP in IP
226*4882a593Smuzhiyun     tunnel or layer 2 virtual circuit) is used between the GGSN/P-GW
227*4882a593Smuzhiyun     and each private network.
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun     In this case the IP address alone is not necessarily unique.  The
230*4882a593Smuzhiyun     pair of values, Access Point Name (APN) and IPv4 address and/or
231*4882a593Smuzhiyun     IPv6 prefixes, is unique.
232*4882a593Smuzhiyun
233*4882a593SmuzhiyunIn order to support the overlapping address range use case, each APN
234*4882a593Smuzhiyunis mapped to a separate Gi/SGi interface (network device).
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun.. note::
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun   The Access Point Name is purely a control plane (GTP-C) concept.
239*4882a593Smuzhiyun   At the GTP-U level, only Tunnel Endpoint Identifiers are present in
240*4882a593Smuzhiyun   GTP-U packets and network devices are known
241*4882a593Smuzhiyun
242*4882a593SmuzhiyunTherefore for a given UE the mapping in IP to PDN network is:
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun  * network device + MS IP -> Peer IP + Peer TEID,
245*4882a593Smuzhiyun
246*4882a593Smuzhiyunand from PDN to IP network:
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun  * local GTP-U IP + TEID  -> network device
249*4882a593Smuzhiyun
250*4882a593SmuzhiyunFurthermore, before a received T-PDU is injected into the network
251*4882a593Smuzhiyundevice the MS IP is checked against the IP recorded in PDP context.
252