aboutsummaryrefslogtreecommitdiffstats
path: root/gtp/gtp.c
AgeCommit message (Collapse)AuthorFilesLines
2019-09-05gtp: Manage queue timers internallyPau Espin Pedrol1-70/+123
Currently each user (application) of libgtp needs to manage its own timers in order to call gtp_retrans_timeout() and gtp_retrans() and maintain retransmit and duplicate queues working correctly. This adds unnecesary complexity to applications since nowadays, as a libosmocore user, libgtp can handle this internally in an easy way. Furthermore, keeping the timers internal to the library allows for easier extension of features as well as re-implementation of related code in the future. Last but not least, it was detected that existing known applications (osmo-sgsn, osmo-ggsn, sgsnemu) are not using correctly the API, since they should be updating their timers through gtp_retrans_timeout() everytime a message is enqueued/transmitted, otherwise they may fire gtp_retrans() for retransmition too late in some cases. Related: OS#4178 Change-Id: Ife7cfd66d6356f413263fe5bda9e43091f5c9e98
2019-09-02gtp/gtp.c: cosmetic: use get_tid() where we need TIDVadim Yanitskiy1-6/+3
Change-Id: I39e92f25ed51665c8a615826ed52f35024bdd54b
2019-09-02gtp_error_ind_conf(): fix: guard against an unknown GTP versionVadim Yanitskiy1-0/+3
This change fixes the following compiler warnings (found by Clang): gtp.c:2747:13: warning: variable 'pdp' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] } else if (version == 1) { gtp.c:2781:14: note: uninitialized use occurs here OSMO_ASSERT(pdp); ^^^ Shall not happen in general, but let's make Clang happy. Change-Id: Id471b22afd4c45435589a4edda0a804e66be3a7a
2019-09-02gtp_update_pdp_ind(): fix NULL-pointer dereferenceVadim Yanitskiy1-5/+4
As stated in the comment above, we need to use the tunnel identifier to find a GTP context, and derive both IMSI and NSAPI from that TID, when speaking GTP version 0. This change fixes the following warnings (found with Clang): gtp.c:2115:22: warning: variable 'pdp' is uninitialized when used here [-Wuninitialized] pdp_set_imsi_nsapi(pdp, tid); ^^^ gtp.c:2118:34: warning: variable 'imsi' is uninitialized when used here [-Wuninitialized] if (gtp_pdp_getimsi(gsn, &pdp, imsi, nsapi)) ^^^^ gtp.c:2118:40: warning: variable 'nsapi' is uninitialized when used here [-Wuninitialized] if (gtp_pdp_getimsi(gsn, &pdp, imsi, nsapi)) ^^^^^ Change-Id: I8f1c8d0ba2e8189d97fe1bb5c872680e5ad1cd7a
2019-08-29cosmetic: gtp: Improve documentation of gtp_delete_context_req2()Pau Espin Pedrol1-2/+3
Change-Id: I1f85c7cc7684e146fca4f17914927d45410dbb84
2019-08-29cosmetic: gtp: Drop commented out code calling pdp_freepdp()Pau Espin Pedrol1-26/+0
That code was commented out in 0b076a331e1e7f955580313a5da416c170b3b4ce (year 2003), and indeed it makes no sense to call those in current pdp lifecycle (they are expected to be freed by the application). Change-Id: I096d8cb8d749ff9b737d6f3f96b1d423660ece37
2019-08-28gtp: Log msg retransmits and timeoutsPau Espin Pedrol1-0/+4
Change-Id: Ie768ddb45313582b4b5358b97a981080be64fd42
2019-08-28libgtp: Introduce cb_recovery3Pau Espin Pedrol1-0/+17
Since osmo-ggsn can manage several GSN structures simultaneously, it needs the gsn_t pointer to know the ggsn it should forward the call to. Related: OS#4165 Change-Id: I33b4fe594d5833993af01cce34737e61e597b320
2019-08-23libgtp: announce pdp ctx deletion upon CreatePdpCtx being rejectedPau Espin Pedrol1-3/+2
The libgtp application may have already allocated related resources associated to the pdp context, so we need to signal its deletion in order to let the application free the resources. This should fix the duplication of pdp contexts seen in osmo-ggsn when "show pdp-context" related VTY commands are used. It was spotted due to some MS requesting a v4v6 context on a v4-only APN, where first v4 address was allocated, and then upon v6 allocation create_context_ind() called gtp_create_context_resp(GTPCAUSE_MISSING_APN) but the first address was not freed. Upon receiving the callback, osmo-ggsn should now free the related resources. Related: OS#4154 Change-Id: I6c6215a4ce478afabc78ffaf5ffb0cf829e41226
2019-08-23libgtp: Remove packets in tx queue belonging pdp being freedPau Espin Pedrol1-0/+5
Doing so should avoid the crash seen in OS#3956, where a message is received in osmo-sgsn gtp iface after having received a DeleteCtxAccept message where pdp and associated cbp is freed. As a result, when new confirmation arrives, it can still be matched against an old request and be sent to upper layers providing an already freed cbp. With this patch, since all queued messages belonging to that pdp are dropped, confirmation won't find a match and be discarded in libgtp. In order to be able to drop all req messages belonging to a pdp, a new list is added to pdp_t and qmsg_t are added to that list when inserted into the per-gsn req transmit queue. This way upon pdp free time it's simply a matter of iterating over that list to remove all messages. There's no need to do same for resp queue, and it'd be actually counter-productive, because it wouldn't be possible to detect and discard duplicates anymore after pdp ctx has been freed. Related: OS#3956 Change-Id: Id86d0b241454d3ad49c64c28087fd2710fa2d17a
2019-06-04gtp: Make use of new libgtp APIs with multi-gsn supportPau Espin Pedrol1-23/+22
Drop use of deprecated APIs everywhere in libgtp and use the new ones instead. Related: OS#2873 Change-Id: Ibf56a063f01d1f95a2a3271416da6e062e85fdfa
2019-06-04gtp: Introduce new pdp APIs (and deprecate old ones) to support multiple GSNPau Espin Pedrol1-10/+4
Move static global pdp storage arrays to be per GSN. This way now several GSN per process are supported without collisions. * pdp_init() is defined in public API but it's actually only intended for use (and currently only used) internally in gtp_new(). So let's document that and re-use it for backward compatibility with now deprecated API, where only one GSN per process is supported. * Back pointer to gsn_t (pdp->gsn) moved from gtp.c:gtp_new() to gtp_pdp_newpdp(), since it makes more sense to have it there. This way backpointer is always set, even in case were app calls pdp_newpdp() API directly instead of creating them through gtp.c, like osmo-sgsn does. * Create new versions of required APIs with a pointer to gsn_t where the pdp ctx is to be created/found. Some APIs receiving a pointer to a pdp ctx can be left intact because we have a backpointer to its gsn_t. * pdp_getpdp() is nowhere used, and makes little sense now that we have pdpa reachable in gsn->pdpa, so let's deprecate it without adding a replacement. * Deprecate gtp.h gtp_newpdp(), since it's nowhere used and useless (does same as new gtp_pdp_newpdp() and doesn't allow for old_pdp to be passed as parameter). Fixes: OS#2873 Change-Id: I653cbdc185165592d985e3efab6e3f1add97877b
2019-05-31ggsn: Use gtp_delete_context_req2() everywhereOliver Smith1-2/+4
Replace calls to gtp_delete_context_req() with gtp_delete_context_req2(). Related: OS#2741 Change-Id: Iecc8c5ac45207e7e20129559c4ac7f3c67dfb36a
2019-05-31gtp: Re-arrange free pdp ctx code in non-teardown scenarioPau Espin Pedrol1-13/+14
Code modified actually behaves the same, since gtp_freepdp() also calls delete cb, and this way it's more consistent with rest of the code base. Change-Id: I299765816e9d885497110d2e834f7ccdc943052c
2019-05-31cosmetic: gtp: Document free pdp ctx in non-teardown scenarioPau Espin Pedrol1-1/+25
Change-Id: Ia47ac792111fe1e9aa68222b32b5da823642206b
2019-05-31gtp: Refactor code to use gtp_freepdp(_teardown) APIsPau Espin Pedrol1-50/+31
* API gtp_freepdp was already there but was not really being used by anyone currently, so we can change its behaviour to call cb_delete_ctx. It makes sense to call the cb in there too to be consistent with rest of APIs. * Add API gtp_freepdp_teardown, which calls gtp_freepdp on pdp and its secondary contexts. It will also be used later on by osmo-ggsn. * Use new APIs in internal code to simplify it. Change-Id: I9f0b774e9385a7a8d81ec9702f158e2f9a50d571
2019-05-31gtp_create_pdp_ind: simplify code by reordering and compacting parsingPau Espin Pedrol1-99/+71
Move all parsing with same conditions under same blocks to make code easier to follow and make it more compact. Change-Id: I52d5a3543ce6cf764bd84303b5a0d8b0643d998d
2019-05-31pdp: Introduce new API pdp_count_secondaryPau Espin Pedrol1-10/+4
Change-Id: Id2d84ad1cdb0f3b500efeda4cc0fbccb24ae0c61
2019-05-31gtp: Fix typo dublicate->duplicatePau Espin Pedrol1-11/+11
Change-Id: Ic572c216e74fa937dfd12f9f3dc03de18b6b123e
2019-05-31gtp: Take queue_resp into account to schedule retrans timerPau Espin Pedrol1-3/+15
Before this patch they were not taken into account, which means some resp messages could stay more time than required enqueued. Change-Id: Iebf405b2310a34785f3b363cc2a9f415281f6030
2019-05-30gtp: Document spec reasoning drop of Rx DeleteCtxReqPau Espin Pedrol1-0/+8
Change-Id: I563fc0b48595d71ebdf56a50f4e9984eee423676
2018-09-16libgtp: implement gtp_clear_queues to clear req/resp queueAlexander Couzens1-0/+18
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-07-23gtp: Add new replacement cb_recovery2 for cb_recoveryPau Espin Pedrol1-12/+39
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-21gtp: Add new API to avoid freeing pdp contexts during DEL CTX REQPau Espin Pedrol1-36/+68
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-13gtp: Log ignore CTX DEL REQ due to no teardown and only 1 ctx activePau Espin Pedrol1-0/+3
Change-Id: Ic950c04d309d5686bfbeab332f79c48678e743ae
2018-07-13gtp: Allow recv DEL CTX REQ in sgsn and DEL CTX RSP in ggsnPau Espin Pedrol1-8/+4
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-13gtp: Log type name of unexpected signalling messagePau Espin Pedrol1-4/+8
Change-Id: Iae0f045e4128cf97aa7824d7d774b59bf966cbe8
2018-01-26ggsn: Validate packet src addr from MSPau Espin Pedrol1-1/+0
Closes: OS#2422 Change-Id: Ie658a7f161103bb6f631ab0508e45e55fb42a442
2018-01-26gtp/gtp.c: Use uint8_t for version param in static functionsPau Espin Pedrol1-13/+13
Change-Id: I9afc36e2304f1060615219e88dd28821fb74e300
2018-01-26gtp/gtp.c: Mark non exported functions as staticPau Espin Pedrol1-15/+15
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-26gtp/gtp.c: Remove unused function char2ul_tPau Espin Pedrol1-9/+0
Change-Id: I0d7493404ea05ce2e795958041bbb6cb75a04d31
2018-01-25gtp.c: gtp_gpdu_ind: Early return to avoid use of uninitialized varPau Espin Pedrol1-1/+2
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-25gtp.c: gtp_gpdu_ind: Convert ifelse to switch statementPau Espin Pedrol1-3/+6
Change-Id: I99b73f7a6d4100789fa92021c6ec9117869c881b
2018-01-25gtp.c: Log unsupported GTP version numberPau Espin Pedrol1-10/+10
Change-Id: Idbc6e4c912b958bde5916b87ec53c3c4db70bee0
2018-01-25gtp.c: Determine GTP version from headerPau Espin Pedrol1-8/+14
Change-Id: I843071a090e877fd529e1e0b799df3585bf836d8
2018-01-25gtp.c: Fix trailing whitespacePau Espin Pedrol1-28/+28
Change-Id: I636c81d0c0ff53c97e6aedbc00f90c1325a3d607
2018-01-17Add GTP message namesMax1-0/+45
Change-Id: I65eb80db4bcdc6da4d267bef3b907d3f98942a2e
2017-11-06gtp: Explicit OSMO_ASSERT to ensure pdp variable is setHarald Welte1-0/+6
Change-Id: I09e37e25fd118ac0a54ab788304d3f5083463050 Fixes: Coverity CID#174335
2017-11-06gtp: Fix buffer overflow in imsi_gtp2str()Harald Welte1-1/+1
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-10-01Replace EUA magic numbers for IETF, IPv4 and IPv6 with #definesHarald Welte1-3/+3
Change-Id: I33f65e404217e717bd795e5229c8d9456a7b3739
2017-09-24libgtp: Allow each PDP context to specify if it transmits G-PDU sequence numbersHarald Welte1-6/+16
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-24gtp: Avoid magic numbers when operating on GTP header flagsHarald Welte1-26/+33
Let's introduce a couple of #defines that make the code much more readable. Change-Id: I3635d679fd54507274b46e99a02bdbbe41d7684e
2017-09-24libgtp: Avoid extra memcpy() in gtp_data_req() by using sendmsg()Harald Welte1-29/+20
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-06Rename OpenGGSN to OsmoGGSNHarald Welte1-1/+3
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-05libgtp: Add back-reference to gsn from pdp contextHarald Welte1-1/+7
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-08-22libgtp: expand loggingMax1-10/+7
* 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-13libgtp: Delete PDP context on receiving GTPv1 Error IndicationHarald Welte1-6/+33
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-12libgtp: Add missing mandatory IEs in GTP Error IndicationHarald Welte1-1/+11
Change-Id: Iadd1fe3de7c476576a4409f22f5e84e9eade6b6e
2017-08-12Properly format IMSI before using it in trapHarald Welte1-0/+28
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-06-09libgtp: improve error logging and propagationMax1-13/+13
* 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