Commit Graph

119 Commits

Author SHA1 Message Date
Pau Espin a884a95a7b gtp.c: Log unsupported GTP version number
Change-Id: Idbc6e4c912b958bde5916b87ec53c3c4db70bee0
2018-01-25 17:28:26 +01:00
Pau Espin a4aada0b5f gtp.c: Determine GTP version from header
Change-Id: I843071a090e877fd529e1e0b799df3585bf836d8
2018-01-25 17:24:38 +01:00
Pau Espin 732131d4d0 gtp.c: Fix trailing whitespace
Change-Id: I636c81d0c0ff53c97e6aedbc00f90c1325a3d607
2018-01-25 17:23:09 +01:00
Max e661277b48 Add GTP message names
Change-Id: I65eb80db4bcdc6da4d267bef3b907d3f98942a2e
2018-01-17 09:42:40 +00:00
Harald Welte bd228244da gtp: Explicit OSMO_ASSERT to ensure pdp variable is set
Change-Id: I09e37e25fd118ac0a54ab788304d3f5083463050
Fixes: Coverity CID#174335
2017-11-06 03:16:49 +09:00
Harald Welte a06120de77 gtp: Fix buffer overflow in imsi_gtp2str()
The string buffer allocated for the IMSI must be sized for a length
twice the number of input bytes (each byte has two nibbles) plus 1
byte for NUL.  We missed the "twice" part :/

Change-Id: I1ecaa811815ae522af71feabc5d0c1ea8b4edde9
Fixes: Coverity CID#174336
2017-11-06 03:12:54 +09:00
Harald Welte cee7546f15 Replace EUA magic numbers for IETF, IPv4 and IPv6 with #defines
Change-Id: I33f65e404217e717bd795e5229c8d9456a7b3739
2017-10-01 18:19:07 +08:00
Harald Welte 3c1cce245e libgtp: Allow each PDP context to specify if it transmits G-PDU sequence numbers
GTP sequence numbers on GTP-U are optional for G-PDU type messages (i.e.
user-ip messages).  Let's allow the user to specify this behavior by
a new pdu_t.tx_gpdu_seq flag.  The flag is enabled by default to stay
compatible with the prior behaviour.

Related: OS#2519
Change-Id: Icf22a2ddd5c4a968ef5bda7c202b921d93fb49e6
2017-09-24 23:10:01 +08:00
Harald Welte fed598f41d gtp: Avoid magic numbers when operating on GTP header flags
Let's introduce a couple of #defines that make the code much more
readable.

Change-Id: I3635d679fd54507274b46e99a02bdbbe41d7684e
2017-09-24 16:53:16 +08:00
Harald Welte 471e349ecc libgtp: Avoid extra memcpy() in gtp_data_req() by using sendmsg()
Adresses two "TODO Should be avoided" comments about an extra memcpy()
before sendto() that can be replaced by a single sendmsg() call with an
iovec array: 1 record for the GTP header + 1 record for the user payload.

Change-Id: Ie332a6b15972330fcf540753898eb84ecb84fe24
2017-09-24 16:12:39 +08:00
Harald Welte 632e843e5f Rename OpenGGSN to OsmoGGSN
Osmocom has maintained this program since about 7 years now, while
the original author / copyright holder has completely disappeared.

With the introduction of Osmocom-style CTRL and VTY interfaces,
the way how the program is used and configured has substantially
changed.  In order to avoid confusion in terms of configuration file
format etc, let's rename it to OsmoGGSN.

Change-Id: I2da30f7d4828e185bfac1a4e2d8414b01cbe4f9d
2017-09-06 09:17:15 +02:00
Harald Welte e257be1d69 libgtp: Add back-reference to gsn from pdp context
This is required once one wants to support multiple GSNs in a single
application.

WARNING: This breaks ABI compatibility, LIBVERSION must be adjusted

Change-Id: I68ae49a765828fa681054c68bf7f5e74dbe48ad2
2017-09-05 23:13:14 +02:00
Max 14b1b63710 libgtp: expand logging
* print destination address on sendto error
* print address length on conversion error
* log listening address
* log GTP version on PDP context errors
* fix incorrect logging message for unknown GSN peer

Related: SYS#3610
Change-Id: I0f8ad8687acb7f6f0eeeb962f007e87cca0c4c27
2017-08-22 10:07:28 +00:00
Harald Welte 37d5b1557b libgtp: Delete PDP context on receiving GTPv1 Error Indication
When a peer GSN receives a GPDU for an unknown PDP context, it sends
a GTP Error Indication.  This Error Indication should be used to
delete the offending PDP context locally.

In GTPv1, the Error Indication contains some mandatory IEs using
which we can look up the PDP context and delete it.

The existing code only dealt with GTPv0 Error Indications which lack
those IEs and use the TEI in the header instead.

Change-Id: I3e843f9ef1d6fd7868cc992e083c0891d16b6da9
Closes: OS#2426
2017-08-13 00:01:35 +02:00
Harald Welte 54d082e5e8 libgtp: Add missing mandatory IEs in GTP Error Indication
Change-Id: Iadd1fe3de7c476576a4409f22f5e84e9eade6b6e
2017-08-12 22:53:59 +02:00
Harald Welte b10ee08c2f Properly format IMSI before using it in trap
For some reason Max' commits introducing the CTRL/trap interface
about one year ago didn't convert the IMSI to its actual textual
representation before usign it in the CTRL interface.

Let's clean that up by properly interpreting the IMSI.

Change-Id: I8b20d2e47a29de266d93a7ddd5e6877f7e346a63
2017-08-12 22:53:54 +02:00
Max 283188790b libgtp: improve error logging and propagation
* propagate error code from gtp_new() to caller instead of always
  returning -1
* on socket-related failures log explicitly which kind of socket caused
  error
* log expected GTP version for unexpected packets

Change-Id: Ie07f1e4246eb178838b7df21946a08a1f60f2084
related: SYS#3610
2017-06-09 08:53:10 +00:00
Harald Welte bf5c0bb4b9 gtp.c: Don't print ""Unknown packet flags" error message in get_seq()
get_seq() is called also from contexts where GTP-U is used, and GTP-U
doesn't have sequence numbers.  Thus, it is perfectly normal if no
sequence number and/or no S flag in the header is present.

Change-Id: Ie19b95bbb4427e547843a019f5213a231a9f83da
2017-02-23 21:11:05 +01:00
Harald Welte d37b80a6d2 gtp.c: Improve debug statements about GTP header flags
* as there are muptiple flags in the field, use plural
* print the flags as hex value, not decimal.  Hex is customary for bitfields.

Change-Id: Ib23d80fae32b4e9fa146d82d8f5a1dada1a3cb2b
2016-12-15 20:55:54 +01:00
Neels Hofmeyr f41f5866ce gsn_restart file: wrap umask change tightly around file creation
An fopen("w") error used to omit the umask() call to reinstate the previous
umask. Also an fopen("r") at the top will never create a file and hence does
not need a umask set.

Instead, wrap the umask change and change-back tightly around the single
fopen("w") call.

Change-Id: If7d948e2f2ba47ecebba5614f18235a53b273d14
2016-10-14 11:39:49 +00:00
Neels Hofmeyr f7611c3cee fix gsn_restart file buffer overflow and missing path sep
Fix errors during gsn_restart file path composition:

- possible buffer overflow because the wrong remaining length was fed to
  strncat().
- missing path separator: put restart file in dir/gsn_restart instead of
  ../dirgsn_restart.

This assumes that the path separator is '/'.

Use talloc_asprintf() to fix all filename length problems and shorten the code.

In order to free the allocated path, add a free_filename label, and jump there
instead of returning from the fopen("w") failure branch. Also don't return from
"fclose failed" branch in order to free the path, remove the if {} braces.

Change-Id: Idf0a64ff45720aa818f2f9de1e8ba2fe2c82631b
2016-10-14 11:39:49 +00:00
Daniel Willmann d997552d29 gtp: Handle gtpv1 in gtp_update_pdp_conf() correctly
libgtp cannot understand its own update pdp request (in gtp v1)
Only require the conditional and mandatory fields for gtpv1 and not
others.
Refer to 3GPP TS 29.060 Ch. 7.3.4
2016-02-05 07:48:20 +01:00
Daniel Willmann 05f3ef3eb8 gtp: Make gtp_update_pdp_conf() work for gtp0 and gtp1 connections
pdp_getgtp1(&pdp, get_tei(pack)) works like pdp_getgtp0 for gtp0
connections.
Using get_hlen() for gtpie_decaps is used in other places to decode ies
for both version 0 and 1.
2016-02-04 13:17:19 +01:00
Daniel Willmann 134a7752fd gtp: Pass pdp along when calling gtp_req() in gtp_update_context()
With no pdp parameter gtp_req() will send the packet to TEID 0 which is
not what we want. When trying to modify an established pdp context the
correct TEID of that context must be used.
2016-02-04 13:17:02 +01:00
Holger Hans Peter Freyther 8ddb6805a9 gtp: Do not leak the restart counter file handle in case of error
If the file exists but can not be read the file would not be closed.
Jump to a label that will close f.

Fixes: CID#57917
2016-01-23 10:40:52 +01:00
Alexander Huemer db852a14fe fix some format specifiers 2015-11-07 12:40:48 +01:00
Neels Hofmeyr 0dc4748447 add todo comments 2015-11-02 14:13:31 +01:00
Neels Hofmeyr e845cb9505 gtp.c: fix an error log.
Fix: the code handles fd1u but prints fd1c.
2015-10-12 14:23:54 +02:00
Neels Hofmeyr 9b09738891 gtp.c: improve 3 error logs.
It would print the memory location of the address buffer. Instead, print the
human readable host address and port.

The current code base supports only IPv4, and thread safety is apparently not
required, hence just use inet_ntoa(). (The IPv6 and thread capable version is 4
times longer and harder to read.)
2015-10-12 14:09:57 +02:00
Holger Hans Peter Freyther 01b40d0690 gtp: Make these regions runtime debuggable 2014-12-04 16:49:37 +01:00
Holger Hans Peter Freyther 752314ac43 gtp: Kill unused and non public method 2014-12-04 16:46:30 +01:00
Holger Hans Peter Freyther 42ca1d1a38 gtp: Move to using LOGP for logging GTP packages
Make libgtp depend on libosmocore and use the generic logging
infrastructure for it.
2014-12-04 16:45:59 +01:00
Holger Hans Peter Freyther 5816bcfaff gtp: Speculative FreeBSD compile fix for htobe64 2014-04-04 11:43:09 +02:00
Pablo Neira Ayuso 746b944ad6 gtp: add pdp_set_imsi_nsapi
Encapsulate code to handle the teid with GTPv0.
2014-03-24 17:59:19 +01:00
Pablo Neira Ayuso 1a1ba02292 gtp: fix endianness in teid field of GTPv0 header
This field needs to be in network byte order as well.
2014-03-20 14:11:25 +01:00
Harald Welte 95848bafce GTP: don't use magic numbers for T3-REQUESTS and N3-REQUEST 2011-11-02 18:17:50 +01:00
Harald Welte d88e11d819 GTP: use socklen_t where appropriate
this fixes some compiler warnings
2011-11-02 13:09:43 +01:00
Harald Welte bed35df298 Convert all code to Linux coding style
After so many years of silence, we don't expect the original author to
return to the project.  To make things a bit simpler for us, we convert
the coding style to what we are used to (Linux style).

The conversion was made using the 'Lindent' script which is part of the
Linux kernel.
2011-11-02 13:06:18 +01:00
Harald Welte 3a4c67b4bf optionally do not send recovery with sgsnemu
According to 3GPP TS 29.060 recovery is optional, add command line option --norecovery to remove this field in sgsnemu

Signed-off-by: Yann BONNAMY <yann_bonnamy@yahoo.fr>
Signed-off-by: Harald Welte <laforge@gnumonks.org>
2011-10-07 18:45:54 +02:00
Harald Welte 41af5691ef Add optional RAI Field
Routing Area Information is an optional Field described in 3GPP TS 29.060 7.7.3
it can be added with command line option rai, in the dot separated format MCC.MNC.LAC.RAC
example :  --rai 208.10.65535.255

Signed-off-by: Yann BONNAMY <yann_bonnamy@yahoo.fr>
Signed-off-by: Harald Welte <laforge@gnumonks.org>
2011-10-07 18:42:34 +02:00
Isabelle Kraemer fe50409675 GTP: Fix bug in update PDP context procedure
I use OpenGGSN to create/update/delete PDP context and I found a bug
in the implementation: when the sgsnemu sends an "update PDP context"
request, it receives back a "create PDP context" response. Below is
the correction I made, I hope it helps.
2011-07-29 16:41:38 +02:00
Harald Welte 629e986ea4 libgtp: introduce cb_recovery() callback
The cb_recovery() callback enables the user application to detect
a change in the restart counter and thus start the appropriate
recovery procedures.
2010-12-24 20:58:09 +01:00
Yann BONNAMY 944dce3e66 Add support for GTP IE's from 3GPP R7
This adds support for the followng new GTP Information Elements:
	RAT_TYPE, USER_LOC, MS_TZ, IMEI_SV

Furthermore, it allows to specify those fields as sgsnemu command line
arguments.
2010-10-29 17:07:44 +02:00
Emmanuel Bretelle 111e054543 Fix warning on unused fscanf return code
Relevant output of make:

gtp.c: In function ‘log_restart’:
gtp.c:697: warning: ignoring return value of ‘fscanf’, declared with
attribute warn_unused_result

Signed-off-by: Emmanuel Bretelle <chantra@debuntu.org>
2010-10-20 11:04:51 +02:00
Harald Welte 7b3347b083 [libgtp] add comments with references to the GTP specification sections 2010-05-15 12:18:46 +02:00
Harald Welte cc9f083be0 sgsnemu: delete pdp context - teardown must be before NSAPI
in front of Cisco and Alcatel GGSN's, we meet the following error :

5 packets transmitted
Disconnecting PDP context #0
openggsn[24940]: gtp.c: 2417: Unexpected cause value received: 193. Packet from 172.29.5.130:2123, length: 14, content: 32 15 00 06 00 00 00 01 04 02 00 00 01 c1

it is because in the sgsnemu requests packet, the teardown field is after the NSAPI field :

No. Time Source Destination Protocol Info
24 10.940094 172.21.5.1 172.29.5.130 GTP Delete PDP context request

Frame 24 (58 bytes on wire, 58 bytes captured)
Ethernet II, Src: HewlettP_55:23:8d (00:11:0a:55:23:8d), Dst: Alcatel-_f6:8e:32 (00:d0:95:f6:8e:32)
Internet Protocol, Src: 172.21.5.1 (172.21.5.1), Dst: 172.29.5.130 (172.29.5.130)
User Datagram Protocol, Src Port: gtp-control (2123), Dst Port: gtp-control (2123)
GPRS Tunneling Protocol
Flags: 0x32
Message Type: Delete PDP context request (0x14)
Length: 8
TEID: 0x00000739
Sequence number: 0xbc02
N-PDU Number: 0x00
Next extension header type: No more extension headers (0x00)
[--- end of GTP header, beginning of extension headers ---]
NSAPI: 0
Teardown Indicator: True
[Response In: 25]

Taken from http://sourceforge.net/tracker/index.php?func=detail&aid=2865662&group_id=68956&atid=522957
2010-05-04 11:16:09 +02:00
Harald Welte f54a1f4d43 Fix various compiler warnings throughout the code
Mostly signed/unsigned and typecasting issues

Taken from http://sourceforge.net/tracker/index.php?func=detail&aid=1811517&group_id=68956&atid=522957
2010-05-04 11:08:38 +02:00
jjako 0fe0df0079 qos length bugfix and apple support plus header cleanup 2004-09-17 11:30:40 +00:00
jjako 9b4971d4a6 Charging characteristics made optional 2004-05-27 20:30:19 +00:00
jjako 1f1586458f Added IP address alias capability for FreeBSD 2004-02-05 20:39:57 +00:00
jjako 1ea6634851 Added FreeBSD route capability 2004-01-28 09:27:34 +00:00
jjako d48c5ff86b Fixed long constant warning on FreeBSD 2004-01-26 22:25:40 +00:00
jjako 06e9f12588 FreeBSD porting and IMSI bugfix 2004-01-19 18:37:58 +00:00
jjako 98200dfdf9 Fix NSAPI bug in create pdp context 2004-01-09 15:18:42 +00:00
jjako be61ef25a8 Removed NSAPI from version 0 create pdp context request 2004-01-09 12:22:29 +00:00
jjako bae2cd4c6a Removed stdint.h include 2004-01-09 12:04:39 +00:00
jjako b7b93fc78f Rename u_int to uint 2004-01-09 11:56:48 +00:00
jjako 193e8b1b01 Added --net, --nsapi, --gtpversion options 2003-11-10 12:31:41 +00:00
jjako 0b076a331e Fixed sgsnemu freepdp on failed create context. 2003-10-25 15:59:31 +00:00
jjako ccc564f878 Fixed deallocation of pdp context on failed create context. 2003-10-25 15:40:48 +00:00
jjako 581c9f0e29 sgsnemu timelimit bug fix. Readme update 2003-10-22 11:28:20 +00:00
jjako 2c3813354e GTP1 functionality 2003-10-21 19:09:53 +00:00
jjako 08d331db63 First attempt at a GTP1 implementation 2003-10-13 20:33:30 +00:00
jjako 0a120b211f Mode checking i gtp_new() 2003-07-10 18:35:50 +00:00
jjako 1db1c81302 Improved GTP error handling 2003-07-06 20:53:57 +00:00
jjako a7cd249501 added ippool.h and ippool.c 2003-04-11 09:40:12 +00:00
jjako 3c13e30b57 Include config.h 2003-01-28 22:17:29 +00:00
jjako 2e840a3cb9 Paranoid buffer overflow checking improvements. 2003-01-28 16:05:18 +00:00
jjako 52c2414f6c Initial revision 2002-12-16 13:33:51 +00:00