gtp.txt 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. The Linux kernel GTP tunneling module
  2. ======================================================================
  3. Documentation by Harald Welte <laforge@gnumonks.org> and
  4. Andreas Schultz <aschultz@tpip.net>
  5. In 'drivers/net/gtp.c' you are finding a kernel-level implementation
  6. of a GTP tunnel endpoint.
  7. == What is GTP ==
  8. GTP is the Generic Tunnel Protocol, which is a 3GPP protocol used for
  9. tunneling User-IP payload between a mobile station (phone, modem)
  10. and the interconnection between an external packet data network (such
  11. as the internet).
  12. So when you start a 'data connection' from your mobile phone, the
  13. phone will use the control plane to signal for the establishment of
  14. such a tunnel between that external data network and the phone. The
  15. tunnel endpoints thus reside on the phone and in the gateway. All
  16. intermediate nodes just transport the encapsulated packet.
  17. The phone itself does not implement GTP but uses some other
  18. technology-dependent protocol stack for transmitting the user IP
  19. payload, such as LLC/SNDCP/RLC/MAC.
  20. At some network element inside the cellular operator infrastructure
  21. (SGSN in case of GPRS/EGPRS or classic UMTS, hNodeB in case of a 3G
  22. femtocell, eNodeB in case of 4G/LTE), the cellular protocol stacking
  23. is translated into GTP *without breaking the end-to-end tunnel*. So
  24. intermediate nodes just perform some specific relay function.
  25. At some point the GTP packet ends up on the so-called GGSN (GSM/UMTS)
  26. or P-GW (LTE), which terminates the tunnel, decapsulates the packet
  27. and forwards it onto an external packet data network. This can be
  28. public internet, but can also be any private IP network (or even
  29. theoretically some non-IP network like X.25).
  30. You can find the protocol specification in 3GPP TS 29.060, available
  31. publicly via the 3GPP website at http://www.3gpp.org/DynaReport/29060.htm
  32. A direct PDF link to v13.6.0 is provided for convenience below:
  33. http://www.etsi.org/deliver/etsi_ts/129000_129099/129060/13.06.00_60/ts_129060v130600p.pdf
  34. == The Linux GTP tunnelling module ==
  35. The module implements the function of a tunnel endpoint, i.e. it is
  36. able to decapsulate tunneled IP packets in the uplink originated by
  37. the phone, and encapsulate raw IP packets received from the external
  38. packet network in downlink towards the phone.
  39. It *only* implements the so-called 'user plane', carrying the User-IP
  40. payload, called GTP-U. It does not implement the 'control plane',
  41. which is a signaling protocol used for establishment and teardown of
  42. GTP tunnels (GTP-C).
  43. So in order to have a working GGSN/P-GW setup, you will need a
  44. userspace program that implements the GTP-C protocol and which then
  45. uses the netlink interface provided by the GTP-U module in the kernel
  46. to configure the kernel module.
  47. This split architecture follows the tunneling modules of other
  48. protocols, e.g. PPPoE or L2TP, where you also run a userspace daemon
  49. to handle the tunnel establishment, authentication etc. and only the
  50. data plane is accelerated inside the kernel.
  51. Don't be confused by terminology: The GTP User Plane goes through
  52. kernel accelerated path, while the GTP Control Plane goes to
  53. Userspace :)
  54. The official homepage of the module is at
  55. https://osmocom.org/projects/linux-kernel-gtp-u/wiki
  56. == Userspace Programs with Linux Kernel GTP-U support ==
  57. At the time of this writing, there are at least two Free Software
  58. implementations that implement GTP-C and can use the netlink interface
  59. to make use of the Linux kernel GTP-U support:
  60. * OpenGGSN (classic 2G/3G GGSN in C):
  61. https://osmocom.org/projects/openggsn/wiki/OpenGGSN
  62. * ergw (GGSN + P-GW in Erlang):
  63. https://github.com/travelping/ergw
  64. == Userspace Library / Command Line Utilities ==
  65. There is a userspace library called 'libgtpnl' which is based on
  66. libmnl and which implements a C-language API towards the netlink
  67. interface provided by the Kernel GTP module:
  68. http://git.osmocom.org/libgtpnl/
  69. == Protocol Versions ==
  70. There are two different versions of GTP-U: v0 [GSM TS 09.60] and v1
  71. [3GPP TS 29.281]. Both are implemented in the Kernel GTP module.
  72. Version 0 is a legacy version, and deprecated from recent 3GPP
  73. specifications.
  74. GTP-U uses UDP for transporting PDUs. The receiving UDP port is 2151
  75. for GTPv1-U and 3386 for GTPv0-U.
  76. There are three versions of GTP-C: v0, v1, and v2. As the kernel
  77. doesn't implement GTP-C, we don't have to worry about this. It's the
  78. responsibility of the control plane implementation in userspace to
  79. implement that.
  80. == IPv6 ==
  81. The 3GPP specifications indicate either IPv4 or IPv6 can be used both
  82. on the inner (user) IP layer, or on the outer (transport) layer.
  83. Unfortunately, the Kernel module currently supports IPv6 neither for
  84. the User IP payload, nor for the outer IP layer. Patches or other
  85. Contributions to fix this are most welcome!
  86. == Mailing List ==
  87. If yo have questions regarding how to use the Kernel GTP module from
  88. your own software, or want to contribute to the code, please use the
  89. osmocom-net-grps mailing list for related discussion. The list can be
  90. reached at osmocom-net-gprs@lists.osmocom.org and the mailman
  91. interface for managing your subscription is at
  92. https://lists.osmocom.org/mailman/listinfo/osmocom-net-gprs
  93. == Issue Tracker ==
  94. The Osmocom project maintains an issue tracker for the Kernel GTP-U
  95. module at
  96. https://osmocom.org/projects/linux-kernel-gtp-u/issues
  97. == History / Acknowledgements ==
  98. The Module was originally created in 2012 by Harald Welte, but never
  99. completed. Pablo came in to finish the mess Harald left behind. But
  100. doe to a lack of user interest, it never got merged.
  101. In 2015, Andreas Schultz came to the rescue and fixed lots more bugs,
  102. extended it with new features and finally pushed all of us to get it
  103. mainline, where it was merged in 4.7.0.
  104. == Architectural Details ==
  105. === Local GTP-U entity and tunnel identification ===
  106. GTP-U uses UDP for transporting PDU's. The receiving UDP port is 2152
  107. for GTPv1-U and 3386 for GTPv0-U.
  108. There is only one GTP-U entity (and therefor SGSN/GGSN/S-GW/PDN-GW
  109. instance) per IP address. Tunnel Endpoint Identifier (TEID) are unique
  110. per GTP-U entity.
  111. A specific tunnel is only defined by the destination entity. Since the
  112. destination port is constant, only the destination IP and TEID define
  113. a tunnel. The source IP and Port have no meaning for the tunnel.
  114. Therefore:
  115. * when sending, the remote entity is defined by the remote IP and
  116. the tunnel endpoint id. The source IP and port have no meaning and
  117. can be changed at any time.
  118. * when receiving the local entity is defined by the local
  119. destination IP and the tunnel endpoint id. The source IP and port
  120. have no meaning and can change at any time.
  121. [3GPP TS 29.281] Section 4.3.0 defines this so:
  122. > The TEID in the GTP-U header is used to de-multiplex traffic
  123. > incoming from remote tunnel endpoints so that it is delivered to the
  124. > User plane entities in a way that allows multiplexing of different
  125. > users, different packet protocols and different QoS levels.
  126. > Therefore no two remote GTP-U endpoints shall send traffic to a
  127. > GTP-U protocol entity using the same TEID value except
  128. > for data forwarding as part of mobility procedures.
  129. The definition above only defines that two remote GTP-U endpoints
  130. *should not* send to the same TEID, it *does not* forbid or exclude
  131. such a scenario. In fact, the mentioned mobility procedures make it
  132. necessary that the GTP-U entity accepts traffic for TEIDs from
  133. multiple or unknown peers.
  134. Therefore, the receiving side identifies tunnels exclusively based on
  135. TEIDs, not based on the source IP!
  136. == APN vs. Network Device ==
  137. The GTP-U driver creates a Linux network device for each Gi/SGi
  138. interface.
  139. [3GPP TS 29.281] calls the Gi/SGi reference point an interface. This
  140. may lead to the impression that the GGSN/P-GW can have only one such
  141. interface.
  142. Correct is that the Gi/SGi reference point defines the interworking
  143. between +the 3GPP packet domain (PDN) based on GTP-U tunnel and IP
  144. based networks.
  145. There is no provision in any of the 3GPP documents that limits the
  146. number of Gi/SGi interfaces implemented by a GGSN/P-GW.
  147. [3GPP TS 29.061] Section 11.3 makes it clear that the selection of a
  148. specific Gi/SGi interfaces is made through the Access Point Name
  149. (APN):
  150. > 2. each private network manages its own addressing. In general this
  151. > will result in different private networks having overlapping
  152. > address ranges. A logically separate connection (e.g. an IP in IP
  153. > tunnel or layer 2 virtual circuit) is used between the GGSN/P-GW
  154. > and each private network.
  155. >
  156. > In this case the IP address alone is not necessarily unique. The
  157. > pair of values, Access Point Name (APN) and IPv4 address and/or
  158. > IPv6 prefixes, is unique.
  159. In order to support the overlapping address range use case, each APN
  160. is mapped to a separate Gi/SGi interface (network device).
  161. NOTE: The Access Point Name is purely a control plane (GTP-C) concept.
  162. At the GTP-U level, only Tunnel Endpoint Identifiers are present in
  163. GTP-U packets and network devices are known
  164. Therefore for a given UE the mapping in IP to PDN network is:
  165. * network device + MS IP -> Peer IP + Peer TEID,
  166. and from PDN to IP network:
  167. * local GTP-U IP + TEID -> network device
  168. Furthermore, before a received T-PDU is injected into the network
  169. device the MS IP is checked against the IP recorded in PDP context.