Commit Graph

133 Commits

Author SHA1 Message Date
Harald Welte f5a268a96d Bump version: 1.2.2.44-6da8-dirty → 1.3.0
Change-Id: Ie12af1d57df178a9ab27937ef0b764c98dd96e32
2019-01-20 21:34:23 +01:00
Stefan Sperling 3730c550cd fix a format string directives in queue_seqset()
Coverity pointed out that a format string used inappropriate
format string directives for variables of type size_t.

Change-Id: I889019aad963932fdc032421e60a72c809a93bca
Related: CID#135197
2018-11-22 13:17:18 +00:00
Alexander Couzens e1412d9493 libgtp: implement gtp_clear_queues to clear req/resp queue
Clearing the request and response queue is useful for debugging
to reset "some" state. Otherwise some tests will get un-expected
packets.

Change-Id: I279d1d7cbf5d37dd5609c2b968f317fe9a0e348d
2018-09-16 10:30:10 +00:00
Pau Espin b5f93346df gtp: Add new replacement cb_recovery2 for cb_recovery
Sometimes the originating pdp ctx causing the Recovery Procedure is
required, in order to drop all pdp ctx but this one, which specs specify
should be handled as valid:
"""
The SGSN receiving the Recovery information element shall handle it as when an
Echo Response message is received but shall consider the PDP context being created as active if the response indicates
successful context activation at the GGSN.
"""

Change-Id: I53e92298f2f6b84d662a3300d922e8c2ccb178bc
2018-07-23 11:25:53 +02:00
Pau Espin 8e8c7ef3c7 gtp: Add new API to avoid freeing pdp contexts during DEL CTX REQ
With this API, user is expectd to free the PDP ctx when the confirmation
for the release has been received (cb_conf time). This way user can
maintain the pdp ctx alive during all this time. Extra code is added to
gtp_delete_pdp_resp() since it's now possible to match it and push it up
to the user cb_conf.

This way, cb_conf() can be used for locally-initiated DEL CTX REQ, while
delete_context() cb is left for remotely-initiated DEL CTX REQ. In this
later case, when the DEL CTX RESP is sent the ctx is deleted and the
delete_context() is called, where the user can do related actions or
trigger consequence events (in the case of SGSN, it will drop all
related GGSN bits for that PDP ctx and forward the DEACT PDP CTX to the
MS).

Change-Id: I29d366253bb98dcba328c7ce8aa3e4daf8f75e6c
2018-07-21 17:22:54 +00:00
Pau Espin d1bd6fce9c gtp: Log ignore CTX DEL REQ due to no teardown and only 1 ctx active
Change-Id: Ic950c04d309d5686bfbeab332f79c48678e743ae
2018-07-13 19:11:59 +02:00
Pau Espin a32e4c4fb8 gtp: Allow recv DEL CTX REQ in sgsn and DEL CTX RSP in ggsn
According to 3GPP TS 29.060 section "7.3.5
Delete PDP Context Request", both directions are valid in both GSNs.

This allows osmo-sgsn receive delete ctx indication (cb_delete_context)
in order to implement GGSN initiated requests.

Change-Id: I6927c07be4ddf74defe338d01d947056e15cd14d
2018-07-13 19:05:03 +02:00
Pau Espin 3b84e92ab3 gtp: Log type name of unexpected signalling message
Change-Id: Iae0f045e4128cf97aa7824d7d774b59bf966cbe8
2018-07-13 18:32:38 +02:00
Pau Espin 36c4fac9c9 debian/rules: Fix debian packaging after 1.2.0 release
The 1.2.0 release bumped lib version to 3 and updated the debian package
file accordingly, but forgot to increase dh_strip line in debian/rules.

Change-Id: Ib54f231943348c06acecd6f413b2c96b24f6db28
2018-05-04 11:28:24 +02:00
Pau Espin a06b2d3877 Bump version: 1.1.0.90-5468-dirty → 1.2.0
Change-Id: I2af8c8ff75d5153456b814b9dfe4fbddafe5af7a
2018-05-03 16:05:28 +02:00
Pau Espin 5b1ef9589c ggsn: Validate packet src addr from MS
Closes: OS#2422

Change-Id: Ie658a7f161103bb6f631ab0508e45e55fb42a442
2018-01-26 18:20:22 +00:00
Pau Espin 07730bb9cc gtp/gtp.c: Use uint8_t for version param in static functions
Change-Id: I9afc36e2304f1060615219e88dd28821fb74e300
2018-01-26 18:20:21 +00:00
Pau Espin 7b38af5cd3 gtp/gtp.c: Mark non exported functions as static
Functions not exported in gtp.h should be static.
There's no need to mark functions as extern in the .c file.

Change-Id: Ie61d5c6e0ae45ef3885911cedf71c826ed1705d0
2018-01-26 18:20:21 +00:00
Pau Espin 85ef5833cb gtp/gtp.c: Remove unused function char2ul_t
Change-Id: I0d7493404ea05ce2e795958041bbb6cb75a04d31
2018-01-26 18:20:21 +00:00
Pau Espin 282d4e3dda gtp.c: gtp_gpdu_ind: Early return to avoid use of uninitialized var
If the version received is not known, pdp is then uninitalized so we
should not be using it. Let's return an error to inform the caller.

Change-Id: Ib3e23b61a3521bd3c9002d3165ca8eff4361a35e
2018-01-25 18:20:55 +01:00
Pau Espin 42d3250d17 gtp.c: gtp_gpdu_ind: Convert ifelse to switch statement
Change-Id: I99b73f7a6d4100789fa92021c6ec9117869c881b
2018-01-25 18:18:07 +01:00
Pau Espin 5aed8de11d gtp/pdp: Remove unused APIs pdp_ntoeua pdp_euaton
Change-Id: I00db99ba8de3f3d90e85bf593ed31555eedb439b
2018-01-25 18:09:51 +01:00
Pau Espin 5f5fcff5f3 gtp/pdp: Fix trailing whitespace
Change-Id: I1bc65ef9af1144779ee91a2c9b9887233ad15671
2018-01-25 18:09:02 +01:00
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
Pau Espin 2d6a69e69a Add support for IPv4v6 End User Addresses
Before this commit, when an MS requested an ipv4v6 context osmo-ggsn
returned an error stating the type was unknown, and this text was
printed in the log:
Processing create PDP context request for APN 'ims'
Cannot decode EUA from MS/SGSN: f1 8d

This patch has been tested with an MS running the 3 types of addresses:
- IPv4 and IPv6: no regressions observed, the context is activated and
packets are sent to the ggsn.
- IPv4v6: Wireshark correctly parses request and reponse, and then
ICMPv6 traffic from both sides. Finally I see the MS using the IPv4 and
IPv6 DNS addresses advertised and TCP traffic over IPv4 (because
probably my IPv6 network setup is not correct). I also checked I can
disable/enable data (pdp ctx delete and activate) several times without
any issue.

Change-Id: Ic820759167fd3bdf329cb11d4b942e903fe50af5
2017-12-11 11:39:18 +01: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 f6c5f9524f gtpie_{encaps,encaps2}(): RAI is a fixe 6-byte length field, not 8 bytes
gtpie_decaps() always had this right, but the encapsulation functions
treated it as 8-byte fixed length IE.

I hope we had a chance to convert all of this to the normal libosmogsm
tlv_parser one day.  This would have one description table for all TLV
types which then is used from encoder and decoder.

Change-Id: I48471f2735511806ac424b5ffc1929e85bb156f3
2017-10-14 07:59:07 +02:00
Harald Welte bc41c8d581 gtpie.h: Add IE identifier definitions up to 29.60 v11.8.0 Release 11
Change-Id: I6ab7bfb31f93f52f9f6b1b5880dcb2c232bba794
2017-10-14 07:49:15 +02:00
Harald Welte 89e1abcb18 Allow Common flags 0x94 and ignore them in PDP activation
extended from https://github.com/osmocom/openggsn/pull/2

Change-Id: I31b3e4b378e74bb5a0a2f54af6d2a15b629876cf
2017-10-14 07:43:58 +02:00
Harald Welte 8376972050 gtpie: Add missing #include of <arpa/inet.h> for htonl() and friends
Change-Id: Id69d957d0860ee49e7f0db5c64ab8ba976f8c8d6
2017-10-13 16:36:43 +02:00
Harald Welte a964027344 gtpie_decaps: const-ify pointer to input packet data
Change-Id: Ia048abcd80f29581c6ac02cd7f534f2617005671
2017-10-13 16:36:43 +02:00
Harald Welte c5150cecc5 gtpie: Add doxygen API documentation
libgtp should have proper API documentation, let's start with the
gtpie.[ch] parts.

Change-Id: I97df5bd3c8dcc5c97a114c8c6abadabf33147b05
2017-10-13 16:36:43 +02:00
Harald Welte 02af9b3ca2 gtpie_tlv() gtpie_tv0(): const-ify read-only input argument
Change-Id: Ide487e34884c8356694246f43c3f1f562357304c
2017-10-13 16:36:43 +02: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
Max 6a21527a2d Move extended PDP logging macro to header
It might be useful for any user of libgtp who uses libosmocore so let's
make generalized version of it available as part of installable header.

Change-Id: I79aba10ef989384a28f059c30899e65c771ae5e1
Related: SYS#3610
2017-09-25 10:35:34 +02: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 bd60930f36 libgtp: Bump major LIBVERSION for recent API/ABI breakage
in Change-Id I68ae49a765828fa681054c68bf7f5e74dbe48ad2 we introduced
a new struct member that breks ABI and API.

Change-Id: Ie631880155513b1b78d1e9dd473dc5dc50e05943
2017-09-06 12:22:05 +02: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
Harald Welte 8a03ea8a32 libgtp: Remove ctrl_handle from gsn_t, replace with private context
The control interface handle never belonged into libgtp in the first
place.  Commit 727417dd28 should not
have added this to the shared library (used by sgsnemu, osmo-sgsn, ...),
but to some private state of the GGSN.

Introducing a private context pointer at the same location will keep
ABI compatibilty.

Change-Id: I4f17516dae3e04114564828a3e5f6e2ea54212a5
2017-09-05 23:13:10 +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
Holger Hans Peter Freyther 68d244d302 abi/debian: Bump ABI version of libgtp after struct size change
The gsn_t changed the size with the addition of the ctrl pointer.
Bump the SO version to not break osmo-sgsn/ggsn on upgrade.

Call the -dev package libgtp-dev to follow the rest of Osmocom and
to ease making releases here.

Change-Id: Iac4d6d2effde1a6b2f60b1e1b49c91513d5ca8c3
2017-01-26 11:14:59 +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