Commit Graph

418 Commits

Author SHA1 Message Date
Harald Welte 227034c88e gtp-kernel: Add function name to pdp_debug() function calls
This allows us to distinguish "add" from "del" operatons in the log

Change-Id: Ibe2e76a6eecc7b5fa5f44ab2c1578597138e30b9
2017-11-14 00:08:51 +09:00
Harald Welte 3dad951171 gtp-kernel: Get rid of SYS_ERR where not applicable
SYS_ERR is for logging an error from the (operating) system including
the errno value.  For general logging, we have DEBUGP/LOGP.  Let's
convert the gtp-kernel logging over.  This also fixes the related line
ending mess-up as SYS_ERR adds a LF while LOGP/DEBUGP don't.

Change-Id: Idb4069a28227b770e20d62bf306cd294f47146ae
2017-11-14 00:08:51 +09:00
Harald Welte 318795635e gtp-kernel: proper cleanup in error path
When genl_socket_open() succeeds but genl_lookup_family() fails,
we have to clean up the socket that we just opened.

This requires a new version of libgtpnl :/

Change-Id: I31df046530347f88cb7b16c37a899b456ed1b080
2017-11-14 00:08:51 +09:00
Harald Welte 22e1573831 gtp-kernel: Make sure repeated calls to gtp_kernel_init() are safe
We have to factor out the "run once" code and make sure to really
only run that once, while the per-device code remains in the
gtp_kernel_init() function.

Change-Id: Iba5bd71e4b725eef59fe4f233fbb965e396a06c3
2017-11-14 00:08:51 +09:00
Harald Welte c85e89961a gtp-kernel: Avoid global state variable
Whether or not GTP kernel support is enabled is the property of a
given APN, and not a global state variable.

Change-Id: Iff3bd8a52bd6c20f9811ee41ff700486d08591f3
2017-11-14 00:08:51 +09:00
Harald Welte 2fc2bc6bc4 gtp-kernel: Align logging for APN start in kernel-gtp case with that of TUN
Change-Id: Ie53d37f151e8b6448636a8cde5777b3841989d05
2017-11-14 00:08:51 +09:00
Harald Welte 0d0e242685 gtp-kernel: shut down kernel GTP device in apn_down()
When we take the APN down, we should also take the GTP device down.

Change-Id: Idd250dd454a1603834d388884a24a63e044fdd7b
2017-11-14 00:08:51 +09:00
Harald Welte 698a2339eb gtp-kernel: Get rid of hard-coded kernel GTP device name
The existing kernel GTP support code inherited from OpenGGSN was overly
simplistic and didn't support multiple GTP devices or user-defined GTP
device names.  Let's remove that restriction in this patch

Change-Id: I51df223788fd5b7cf8099463b8aa0ca4a4fd1c96
2017-11-14 00:08:48 +09:00
Harald Welte 490782d18e gtp-kernel: Re-add support for kernel GTP-U acceleration
When we branched off osmo-ggsn from the old openggsn code base, the
support for kernel-gtp got temporarily removed.  This patch
re-introduces support for handling the GTP-U plane in the Linux kernel
by means of libgtpnl + the kernel GTP-U driver.

This only works for IPv4 at the moment, until the kernel GTP-U code
gains IPv6 support.

Kernel GTP currently also is restricted to a single APN per GSN.

Change-Id: Ieb1bc1bd0d51d41947f0abd6ebbc2e5d102592d6
2017-11-13 23:59:40 +09:00
Harald Welte e3c5918aee gtp_kernel: Change gtp_kernel_init() function signature
Rather than taking an explicit in_addr, prefix_length and a
string-formatted prefix, let's pass in an in46_prefix and derive
the other representations from it.

Also, don't refer to a no-longer-existing global 'ipup' variable but
add it as a function argument.

Change-Id: Ife87142c86589b4fa4062d62afe3670467548589
2017-11-13 23:57:58 +09:00
Harald Welte e2a1de5ca5 Properly NULL-out blacklist in alloc_ippool_blacklist()
This ensures that in case of error, any caller can still safely
call talloc_free() on the blacklist pointerm as free on NULL
is well-defined.  With the code prior to this patch we fear
a double-free.

Change-Id: Idc511cb3f0dfb922920aba8f88ea77df1722ecdc
2017-11-13 23:57:58 +09:00
Harald Welte 4c7d29107f factor out netdev_ip_local_get() from tun_ip_local_get()
netdev_ip_local_get() is a generalized version of tun_ip_local_get()
which supports the net device as argument, rather than a tun_t.

Change-Id: I072aa1a55e7bf110706e9207021b776d9b977fb6
2017-11-13 23:57:58 +09:00
Harald Welte f55a039048 remove unused argument to alloc_ippool_blacklist()
Change-Id: I4d3ea077ba46446e537ec9a6de6f4080fcaa428c
2017-11-13 23:57:58 +09:00
Harald Welte fc6676c4a0 ippool: Correctly compute size of static pool
* we have to use stataddr, not addr (dynamic)
* we have to multiply the length of the address by 8 to get its bit length
* we can simplify the -1 +1 logic (like dynamic)

Change-Id: I174102051bef95f7df34b7d7c480a00ae408be7d
Fixes: Coverity CID#174189
2017-11-06 03:38:54 +09:00
Harald Welte 1af543f44c tun: Don't copy 16byte IPv6 address to 'struct in_addr'
The 'struct tun' curently only has an in_addr (v4-only) member to
store the address of the tun device, so let's not attempt to store
an IPv6 address in it.

FIXME: This entire code needs an overhaul. The assumption that there's
only one address, and only either v6 or v4 is broken to begin with.

Change-Id: If0b626d688841d6e0a3867834f4cb1b70084050e
Fixes: Coverity CID#174278
2017-11-06 03:32:52 +09: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 b589e78f13 sgsnemu: Free strings in error path
In create_pdp_conf(), we have to free() any strings both in the
success and in the error case.

Change-Id: If59cc8d6d151c123f46c1d029091209fd82b3c8e
Fixes: Coverity CID#187636, CID#187633
2017-11-06 03:10:31 +09:00
Harald Welte b11ed0f132 sgsnemu: Make sure buffer has space for terminating-NUL
In proc_ipv6_conf_read() we allocatea buffer on the stack but
forgot the terminating NUL byte.

Change-Id: I54126d8bc08c137859f2de4b47ef23fc0714fdd7
Fixes: Coverity CID#178641
2017-11-06 03:07:26 +09:00
Harald Welte 9c332104eb sgsnemu: Fix format string in printing tun-device name
Change-Id: Ie05050a78a135a1a76473337a341fd723bbe4976
Fixes: Coverity CID#178654
2017-11-06 02:44:42 +09:00
Harald Welte 51127ea962 sgsnemu: Don't leak FILE handle in proc_read()
Change-Id: Ie22e6a9bc172427e867e7a4001b6c710477a232b
Fixes: Coverity CID#178660
2017-11-06 02:42:59 +09:00
Neels Hofmeyr dabb8b4860 fix compiler warnings: return 0 in main(), in 3 tests
Change-Id: I9e49ceba6b0a8dffd331e5707667d9bb007f3ec7
2017-10-31 01:02:00 +01:00
Harald Welte ff069172ce Tag/Release Version 1.1.0
Change-Id: I30a9e72fa9c3d6fc755c5531844b663c08c3ac06
2017-10-28 19:01:30 +02:00
Harald Welte 7bee06e1cc Debian: include the systemd service file for osmo-ggsn
Change-Id: I5ebee0135e638b7327a16218bdce466ada9aee56
2017-10-28 18:58:38 +02:00
Harald Welte 6c10aa0e6f Debian: package libgtp debug symbols as libgtp-dbg
... and some more Description for debian/control

Change-Id: I099735f8550134441a77c29e8c4d4d3c2490e379
2017-10-28 18:58:38 +02:00
Harald Welte a4e24f5546 Debian: libgtp is libgtp2 for some time, not libgtp1 anymore
In Change-Id Ie631880155513b1b78d1e9dd473dc5dc50e05943 we changed
LIBVERSION but didn't update debian/control.

Change-Id: I7a1349e9609cb455c0fe9d63d085e7c44dff96ef
2017-10-28 18:34:08 +02:00
Neels Hofmeyr 29caaab817 jenkins: use osmo-clean-workspace.sh before and after build
See osmo-ci change I2409b2928b4d7ebbd6c005097d4ad7337307dd93 for rationale.

Depends: I2409b2928b4d7ebbd6c005097d4ad7337307dd93
Change-Id: I1424dff06c7d4f695af0936671ad6faa504aaf16
2017-10-27 22:54:29 +02:00
Pau Espin 859f9b0752 ippool: Implement and use blacklist instead of blindly using IPPOOL_NOGATEWAY
Commit dda21ed7d4 modified previous calls
to ippool_new() removing the pass of flags to avoid allocating certain
problematic IPs from the pool to MS, such as the network, gateway and
broadcast IPs.

Today I did some unsucessful tests with osmo-ggsn with a pool "ip prefix
dynamic 176.16.222.0/24", and thus IP 176.16.222.0 was being assigned to
the MS. De-capsulated DNS packets were received in the tun interface,
but the Linux system in there was unable to correctly forward the
packets to the gateway interface connected to the Internet. However,
adding a second MS which got 176.16.222.1 had its packets forwarded
correctly.

However, previous implementation relies on flag IPPOOL_NOGATEWAY flag to
blindly blacklist first IP after the network ip (ie, .0 and .1 are
removed), which limits the IP reserved for the tun device to be .1. If a
different IP in the range is assigned, it may cause issues. As a result,
a blacklist is introduced in this commit to dynamically fetch the tun IP
address and exlucde it from the pool of available IPs.

Change-Id: I8e91f7280d60490c858a769dd578c1c8e54e9243
2017-10-17 19:10:24 +02:00
Pau Espin a037e5908a tun: Convert tun_ipv6_linklocal_get to be more generic
Add support for IPv4 and IPv6 global IPs. Also return the prefix length
of the IP address by using a in46_prefix.

Change-Id: I277af191dc611b6bbcb83479f4ae338083740322
2017-10-16 17:45:48 +02:00
Pau Espin 2e7b9ff891 lib/in46a: Introduce in46a_netmasklen API
Change-Id: I06e3e038afd8f7afaec2a3fa67b1616500c8db80
2017-10-16 17:45:40 +02:00
Pau Espin 361cb9e910 lib/ippool: Fix listsize calculated 1 elem too small
Take the chance this commit is changing test output to also remove use
of IPPOOL_NOGATEWAY which is going to be removed soon, and instead test
IPPOOL_NOBROADCAST.

Change-Id: I95c24bc690490155bec9e3933d678e4668d7745f
2017-10-16 11:59:43 +02:00
Harald Welte 5bacb59a6c Merge "sgsnemu: Use getprotobynumber() in print_ipprot()" 2017-10-15 16:01:08 +00:00
Harald Welte 5b0096a236 Merge "sgsnemu: Remove dead code: encaps_printf()" 2017-10-15 16:01:08 +00:00
Harald Welte df6a105024 Merge "sgsnemu: Mark local functions 'static'" 2017-10-15 16:01:08 +00:00
Harald Welte 226e95af1f Merge "sgsnemu: Make use of "dependon" feature in gengetopt" 2017-10-15 16:01:08 +00:00
Harald Welte e37f48eaf9 sgsnemu: Use getprotobynumber() in print_ipprot()
There's no point in sgsnemu doing a poor mans reimplementation
of what the C library provides already by means of getprotobynumber()

Change-Id: I8cdc460e4fa5d86d80addf6e5f341d2d80093a35
2017-10-14 16:39:07 +02:00
Harald Welte 8a55263a1b sgsnemu: Remove dead code: encaps_printf()
This function is never used/called, remove it.

Change-Id: I37a447e4d5387e3fc5f4433ab20ceba7c446684b
2017-10-14 16:39:07 +02:00
Harald Welte fed3389112 sgsnemu: Mark local functions 'static'
We don't need to export those to the global name space as they're
not called from code in other files.

Change-Id: I454249335ba46abdb3afbc669c4a06a06f39ae72
2017-10-14 16:39:07 +02:00
Harald Welte 081f30cba4 sgsnemu: Print warnings on broken IPv6 configuration (acept_ra)
When sgsnemu is used for an IPv6 pdp context, we rely on the router
discovery procedure and SLAAC to set the correct IPv6 address/prefix
on the tun device.  This requires the system to be configure to accept
router-advertisements on the tun device.  Let's print a warning
if accept_ra for the specific tun device is set to a wrong value.

We're leaving it up to the user to either set a system-wide
/proc/sys/net/ipv6/conf/default/accept_ra or to configure this in an
ip-up script used together with sgsnemu.

Change-Id: I563092ca35bc74f035a5023e11256779aac46e11
2017-10-14 16:39:07 +02:00
Harald Welte ea0c26a436 sgsnemu: Make use of "dependon" feature in gengetopt
The gengetopt syntax can specify that a particular command line argument
depends on some other argument/option present.  We can use this to
provide useful feedback to the user at the command line parsing state,
like --pingrate making no sense without --pinghost being specified.

Change-Id: Ief27275e90e6bce23aed1e83874dbac98dd0926b
2017-10-14 16:39:07 +02:00
Harald Welte 9d9d91b8e8 ggsn: Avoid crash on wrong EUA type
If the EUA in the Create PDP Context Request was not supported by
the given APN (e.g. IPv6 request for a v4-only APN), we crashed.

Avoid this and add proper handling of this error case.

Change-Id: I8d1f7ec727c5d2d4427232015f81ed57d3440dff
2017-10-14 16:39:07 +02:00
Harald Welte 73abc38dc5 sgsnemu: Add '--tun-device' option to specify TUN device name
This way, multiple sgsnemu instances can be runnig in parallel, each
of them creating a different tun device for their respective PDP context

Change-Id: Id12fbadf924a60db255b6d51b9f647aa51dd2e16
2017-10-14 08:17:07 +02:00
Harald Welte be4baa6d97 Merge "Add unit tests for libgtp gtpie.[ch] functions" 2017-10-14 06:16:36 +00:00
Harald Welte d369013250 Merge "gtpie_{encaps,encaps2}(): RAI is a fixe 6-byte length field, not 8 bytes" 2017-10-14 06:16:36 +00:00
Harald Welte 8afec5f86d Merge "gtpie.h: Add IE identifier definitions up to 29.60 v11.8.0 Release 11" 2017-10-14 06:16:36 +00:00
Harald Welte 5943cbb73f Add unit tests for libgtp gtpie.[ch] functions
This doesn't yet cover all the functions in gtpie.[ch], but testing half
of them is better than not testing any of them, so let's merge this
current state with a couple of TDOO's on what we still need to test.

Change-Id: I30a6dd8a01b7a074ef2d3936d186dfff6c79e6c0
2017-10-14 08:11:13 +02: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