9
0
Fork 0
Commit Graph

94 Commits

Author SHA1 Message Date
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
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
Max 727417dd28 Add control interface
Only generation of TRAP messages over Control Interface is supported so
far.

Note: requires corresponding version of libosmoctrl.

Change-Id: Ia76f841d2c9cd14394e9316fcd39f4060e23c898
Related: OS#1646
2016-10-12 09:30:30 +00:00
Max 395e213894 Remove unused function
Change-Id: Iff0f1499660b12a47277b16a435efecb42fab038
2016-10-11 15:31:49 +02:00
BJovke 03dbafb000 Add 'Bearer Control Mode' IE
This IE is known to be sent by a Cisco GGSN, and was added in
ETSI TS 129 060 V7.17.0 (2011-10) /
3GPP TS 29.060 version 7.17.0 Release 7

See https://lists.osmocom.org/pipermail/osmocom-net-gprs/2016-September/000711.html
Subject "sgsnemu failing to create PDP context with Cisco GGSN"
Tue Sep 13 08:00:37 UTC 2016

Tweaked-by: Neels Hofmeyr <nhofmeyr@sysmocom.de>
2016-09-15 13:53:13 +02:00
Alexander Couzens 86540de7f3 gtp/queue/queue_seqdel(): fix element check which was always true
Fix an apparent typo that prevented queue iteration to find the correct item to
be removed. Instead, the first item was always returned. Calling code has been
analyzed to find that mostly this fault is not visible, since usually, the
first item is indeed the correct item to be returned. See mail thread
http://lists.osmocom.org/pipermail/osmocom-net-gprs/2016-June/000618.html
Date: Wed Jun 1 11:51:38 UTC 2016
Subject: "[PATCH] gtp/queue/queue_seqdel(): fix element check which always was true"
2016-06-06 00:45:10 +02:00
Pablo Neira Ayuso 0eaa5b8e6c gtp: fix several compilation warnings
CC       gtpie.lo
gtpie.c: In function 'gtpie_encaps':
gtpie.c:437:22: warning: variable 'm' set but not used [-Wunused-but-set-variable]
  union gtpie_member *m;
                      ^
gtpie.c: In function 'gtpie_encaps2':
gtpie.c:537:22: warning: variable 'm' set but not used [-Wunused-but-set-variable]
  union gtpie_member *m;
                      ^

lookup.c: In function ‘lookup’:
lookup.c:40:24: warning: typedef ‘ub1’ locally defined but not used [-Wunused-local-typedefs]
  typedef unsigned char ub1; /* unsigned 1-byte quantities */
                        ^

Still one compilation warning left in cmdline.c, but that code
is autogenerated.
2016-05-12 17:02:34 +02:00
Neels Hofmeyr f89dc4e127 queue_new(): fix NULL dereference on allocation failure
Coverity complains about a 'Dereference before null check' on *queue.
So, push the NULL check further up.

Though I doubt that 'return EOF' is the proper way to handle allocation
failure, this patch is only about the NULL dereference.

Fixes: CID#57918
2016-04-29 13:01:06 +02: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
Holger Hans Peter Freyther 3a9befb516 gtp: Fix a bunch of compiler warnings when just including gtp.h
Attempt to fix a bunch of compiler warnings in OpenBSC.
‘struct pdp_t’ declared inside parameter list
2016-01-23 10:16:53 +01:00
Alexander Huemer db852a14fe fix some format specifiers 2015-11-07 12:40:48 +01:00
Holger Hans Peter Freyther cd14094bb6 Dump dead code and never look at it again
This seems to be a wrong search. It seems to assume that there are
no buckets. Let's just remove it before looking at it too much.
2015-11-02 14:13:31 +01:00
Neels Hofmeyr 0dc4748447 add todo comments 2015-11-02 14:13:31 +01:00
Neels Hofmeyr 6c06d25667 make install: also install gtpie.h 2015-10-27 14:57:18 +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 b18e811e24 gtp.h: rename gsn_t.dublicate to duplicate.
Fix spelling dublicate -> duplicate.

This is potentially breaking API compat, but currently, no users of
gsn_t.dublicate are known.
2015-10-12 14:10:27 +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
Pablo Neira Ayuso 0674f0b56c gtp: fix wrong binary layout for struct gtp0_header in x86_64
struct gtp0_header needs __attribute__((packed)) to make sure that
gcc doesn't add a hole of 4 bytes to align the 64-bits teid, resulting
in 24 bytes instead of 20 bytes. This was breaking gtpv0 in my gprs
testbed with my x86_64 laptop.

While at it, add also attribute packed to other headers just to
make sure that gcc doesn't pad the structures with holes.
2014-03-20 14:11:25 +01:00
Holger Hans Peter Freyther 0382996e10 gtp: Use struct ul16_t/struct ul66_t to avoid compiler warnings in OsmoSGSN
This is fixing various compiler warnings:
In file included from sgsn_libgtp.c:49:0:
include/gtp.h:397:48: warning: ‘struct ul66_t’ declared inside parameter list [enabled by default]
include/gtp.h:397:48: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
include/gtp.h:398:49: warning: ‘struct ul66_t’ declared inside parameter list [enabled by default]
include/gtp.h:399:53: warning: ‘struct ul16_t’ declared inside parameter list [enabled by default]
include/gtp.h:400:53: warning: ‘struct ul16_t’ declared inside parameter list [enabled by default]

include/gtp.h:397:48: warning: ‘struct ul66_t’ declared inside parameter list [enabled by default]
include/gtp.h:397:48: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
include/gtp.h:398:49: warning: ‘struct ul66_t’ declared inside parameter list [enabled by default]
include/gtp.h:399:53: warning: ‘struct ul16_t’ declared inside parameter list [enabled by default]
include/gtp.h:400:53: warning: ‘struct ul16_t’ declared inside parameter list [enabled by default]
2013-07-27 20:02:19 +02:00
Holger Hans Peter Freyther d7566b8280 pdp: Mark the data as static as only pdp.c should access this data 2012-11-06 14:17:45 +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 ef71162a74 queue: fix copy+paste mistake in debug statements 2011-11-02 18:07:02 +01:00
Harald Welte b841e57f0b queue: Add some more comments throughout the code (doxygen style) 2011-11-02 13:45:50 +01:00
Harald Welte bb47c354b6 queue: mark non-public functions as static
This makes it a bit more explicit about what is the 'user API' of the
code and what is just used internally.
2011-11-02 13:30:37 +01:00
Harald Welte e65c7390ca queue: use %p format string when printing a pointer 2011-11-02 13:12:53 +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
Yann BONNAMY ad18ccb9df RAI fix
fix ggsn handling of create pdp context when RAI is included and Recovery field is absent

Signed-off-by: Yann BONNAMY <yann_bonnamy@yahoo.fr>
2011-10-07 18:34:02 +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