Commit Graph

806 Commits

Author SHA1 Message Date
Harald Welte 5d547a4358 osmo_oap_decode(): Use common argument ordering
In general, if a function generates output data like a msgb (or in this
case filling an osmo_oap_message structure), the output argument
precedes the source.  This is what we use all over libosmo*, and it is
modelled after memcpy(), where dst is the first argument, before src.

Let's align osmo_oap_decode().  Intestingly, osmo_oap_encode was already
correct, so the encode/decode functions used different conventions
before.
2016-04-29 13:10:37 +02:00
Harald Welte d8aa412c46 OAP: Various coding style fixes
* we always declare stack variables at the top of the function / block
* 'switch' is not a function, so there's space ahead of the opening (
2016-04-29 13:10:37 +02:00
Harald Welte 564c06525b OAP: use osmo_oap_ prefix for OAP, rather than plain oap_
this is in preparation of moving related code to libosmocore.
2016-04-29 13:10:37 +02:00
Harald Welte 31760a1f60 oap_message.h: Remove dependency to openbsc include
This is a first step to moving oap_messages.h to libosmocore
2016-04-29 13:10:37 +02:00
Harald Welte 23d77d56ea Move osmo_gsup_messages.[ch] to libosmocore
This requires the corresponding commit in libosmocore.
2016-04-29 13:10:37 +02:00
Harald Welte 50f1c0af56 move utils.h functions to libosmocore
This needs the corresponding commit in libosmocore which imports
the related functions
2016-04-29 13:10:37 +02:00
Harald Welte eff215a8bb osmo_gsup_messge.[ch] documentation update (doxygen) 2016-04-29 13:10:37 +02:00
Harald Welte 7ca035deca gsup_messages: Add UMTS AKA related encoding/decoding support 2016-04-29 13:10:37 +02:00
Harald Welte 85234a32db move osmo_shift_* / osmo_match_shift_* to libosmogsm 2016-04-29 13:10:37 +02:00
Harald Welte 842674b8b3 rename gprs_shift_*() to osmo_shift_*()
This rename is the first step of moving the associated functions into
libosmocore.

Also, rename gprs_match_* to osmo_match_shift_* to indicate that it is
not just matching the TLV, but also shifting the data portion.
2016-04-29 13:10:37 +02:00
Harald Welte 28903a99ea Rename gprs_gsup_* to osmo_gsup_*
This is a preparation to move the related code to libosmocore, whilst
at the same time generalizing it from GPRS Subscriber Update Protocol
to the Osmocom Generic Subscriber Update Protoco.
2016-04-29 13:10:37 +02:00
Harald Welte d3fa84dbba use new libosmocore gsm_23_003.h for IMEI/IMSI length
... rather than our private definitions everwhere.  As an added benefit,
gprs_gsup_messages.h is now free of any header dependencies within
openbsc.
2016-04-29 13:10:37 +02:00
Harald Welte 53373bca8f move gsm_04_08_gprs.h to libosmocore
This requres the corresponding commit in libosmocore.
2016-04-29 13:10:37 +02:00
Harald Welte 121e9a4164 Start to use struct osmo_auth_vector from gsm_auth_tuple
Rather than having a 'private' structure for kc, sres and rand, we
now finally (with 4 years delay) use osmo_auth_vector from libosmogsm,
which encapsulates authentication vectors that can be either GSM
triplets or UMTS quintuples or a combination of both.

gsm_auth_tuple becomes a wrapper around osmo_auth_vector, adding
use_count and key_seq to it.

key_seq is no longer initialized inside gprs_gsup_messages.c, as there
is no CKSN / key_seq inside the message anyway.  If a usre of the code
needs key_seq, they need to manage it themselves.
2016-04-29 13:10:37 +02:00
Neels Hofmeyr 312bf6ce8b gtphub_unmap_header_tei(): don't dereference unmapped_tei arg if not present (CID #57687) 2016-04-16 13:33:14 +02:00
Neels Hofmeyr 961bd0b121 04.08: apply new transaction id inline functions
libosmocore recently added inline functions to relieve callers from applying
bitmasks and bit shifts to access the transaction id of a GSM 04.08 header.
Apply these functions.
2016-03-15 14:18:52 +01:00
Neels Hofmeyr 531734a547 04.08: apply new bitmask functions, fix bitmask use
Replace hardcoded protocol discriminator and message type bitmasks with
function calls recently introduced in libosmocore.

Note that the release 98 bitmasks slightly differ from the release 99 bitmasks.
This patch uses the "default" gsm48_hdr_msg_type invocation, thus it depends on
libosmocore whether 98 or 99 bitmasks are used.

In some places, use of the bitmask was erratic. Fix these implicitly by
employing the bitmask functions:

 * silent_call.c: silent_call_reroute(): add missing bitmask for MM.
 * bsc_msg_filter.c: bsc_msg_filter_initial(): RR vs. MM messages.
 * osmo_bsc_filter.c: bsc_find_msc() and bsc_scan_bts_msg(): RR vs. MM
   messages.
 * bsc_nat_rewrite.c: bsc_nat_rewrite_msg(): SMS vs. CC messages.
 * bsc_ussd.c: no bitmask is applicable for the message types used here.
 * gb_proxy.c: gbproxy_imsi_acquisition(): missing bit mask for pdisc.

In gprs_gb_parse.c: gprs_gb_parse_dtap(), add a log notice for unexpected
message types.
2016-03-15 14:15:00 +01:00
Neels Hofmeyr 73828152d9 enable ctrl bind config for various programs
Add ctrl_vty_init() calls and feed the ctrl_vty_get_bind_addr() return value to
ctrl_interface_setup() in the following programs:

  osmo-bsc
  osmo-bsc_nat
  osmo-nitb
  osmo-sgsn

For osmo-sgsn, move the control interface setup invocation below the config
parsing, so that the ctrl_vty_get_bind_addr() can return the configured
address.
2016-02-25 12:18:04 +01:00
Neels Hofmeyr fa0f71526c enable telnet VTY bind address config for various programs
Following the 'line vty'/'bind A.B.C.D' command added in libosmocore, use the
configured address to set the telnet bind for the VTY line. It is now possible
to publish the VTY on a specific local interface (including 0.0.0.0 aka "any").

Implement in all of:
  osmo-gbproxy
  osmo-gtphub
  osmo-sgsn
  osmo-bsc
  osmo-bsc_nat
  osmo-bsc_mgcp
  osmo-nitb

In some of these main programs, move the telnet initialization below the
configuration parsing.

Historically, this was not a good idea for programs using bsc_init.c (aka
bsc_bootstrap_network()), since they expected a gsm_network struct pointer in
((struct telnet_connection*)vty->priv)->priv, so that telnet had to be either
initialized or replaced by a dummy struct. In the meantime, the gsm_network
struct is not actually looked up in a priv pointer but in the static bsc_vty.c
scope (bsc_gsmnet), so this limitation is mere legacy (even though said legacy
is still there in an "#if 0" chunk).

In the other binaries I have briefly looked at the init sequence dependencies
and found no reason to initialize telnet above the config file parsing. In any
case, I have tested every single one of abovementioned binaries to verify that
they still parse the example config successfully and launch, allowing VTY
connections on the configured address(es). I hope this suffices.

In all of the above, log VTY address and port. LOGL_INFO is disabled by default
in some of the logging scopes, and since it is a single log message right at
program launch, I decided for the slightly more aggressive LOGL_NOTICE.
2016-02-25 12:18:03 +01:00
Neels Hofmeyr 69da1d453c gtphub: tweak default logging level 2016-02-23 13:28:04 +01:00
Neels Hofmeyr 03933a49de gtphub: include ports.h instead of redefining OSMO_VTY_PORT_GTPHUB 2016-02-23 13:26:02 +01:00
Jacob Erlbeck 5ac4aadd1a sgsn: Re-add searching for MM ctx based on TLLI / P-TMSI matches
If an MM context cannot be found based on BBSGP info and a RA UPDATE
REQUEST is received, try to find an MM context with an P-TMSI from
which the TLLI could have been derived. This also checks, whether the
routing area matches.

This is similar to the old behaviour removed by the commits
"sgsn: Only look at TLLIs in sgsn_mm_ctx_by_tlli" and
"sgsn: Remove tlli_foreign2local", except that this will only
be done for RA UPDATE REQUESTs now.

Sponsored-by: On-Waves ehf
2016-02-22 10:52:08 +01:00
Jacob Erlbeck d35957a7d9 sgsn: Change handling of missing mmctx in gsm48_rx_gmm_ra_upd_req
Currently the MM context is just overwritten by a call to
sgsn_mm_ctx_by_tlli(msgb_tlli(msg), &old_ra_id) even if it
has already been found by using the BSSGP info. With the changes
made to sgsn_mm_ctx_by_tlli this will never find a MM context if
the routing area has changed. If the routing area has not changed,
the mmctx has already been found if it exists.

This commit splits searching for an MM context (if it hasn't been
found already) from checking, whether a found one can really be
used. The actual search is removed, so that the MS will be forced to
restart the attach procedure, which is less efficient but safe.

Sponsored-by: On-Waves ehf
2016-02-22 10:52:08 +01:00
Jacob Erlbeck d58c033305 sgsn: Only look at TLLIs in sgsn_mm_ctx_by_tlli
Currently the code also matches the TLLI against LOCAL and FOREIGN
mappings of the P-TMSI, thus eventually finding MM contexts not
consistent with the TLLI (both tlli and tlli_new differ). On
the other hand, tlli_new is not checked at all.

This commit changes the function to only look at mmctx->tlli,
mmctx->tlli_new, and the routing area.

Sponsored-by: On-Waves ehf
2016-02-22 10:52:08 +01:00
Jacob Erlbeck e7bcdc3bda sgsn: Make ra_id_equals available as gprs_ra_id_equals
The function is moved to gprs_utils.c, renamed, and made non-static
to be usable in other modules, too.

Sponsored-by: On-Waves ehf
2016-02-22 10:52:08 +01:00
Jacob Erlbeck 3fbf0a3735 sgsn: Remove tlli_foreign2local
Currently foreign TLLI are sometimes mapped to local TLLI in the
hope that they will match. This seems to sometimes introduce
inconsisties, possibly leading to a failing assertion in
_bssgp_tx_dl_ud.

This mapping should probably reduce the allocation of additional
LLME during routing area changes.

This commit removes tlli_foreign2local.

Sponsored-by: On-Waves ehf
2016-02-22 10:52:08 +01:00
Holger Hans Peter Freyther 8239e063b9 gsm0408: Provide unique strings for the gsm 04.08 message
At Rhizomatica we see that some GSM 04.08 messages are leaked and
have no other indication if that is Call Control, SMS or something
else.
2016-01-30 09:57:49 +01:00
Alexander Huemer 1bf8617610 gprs: use libgtp cflags 2016-01-26 11:05:14 +01:00
Holger Hans Peter Freyther de76661cf3 gtphub: Fix use after free on failure
Even if fclose fails the stream is inaccessible and the second fclose
might cause memory violation.

Linux manpage says:
Upon  successful  completion 0 is returned.  Otherwise, EOF is returned
and errno is set to indicate the error.  In either case any further
access (including another call to fclose()) to the stream results in
undefined behavior.

Fixes: CID#57958
2016-01-23 10:28:09 +01:00
Holger Hans Peter Freyther fec29ab4e9 gtphub: Make the two setter static as well
Same as with the previous gtphub commit. Make these static to deal
with the new semantic of inline in gcc5.
2016-01-22 23:36:22 +01:00
Holger Hans Peter Freyther 91e0e1b038 gtphub: Fix compilation using gcc5
The semantic of inline has changed and we need to make it static
to not end up with undefined references.
2016-01-22 23:32:36 +01:00
Neels Hofmeyr cdc548cb0a gtphub VTY: add newlines to some VTY docs' final lines 2015-12-14 16:11:47 +01:00
Neels Hofmeyr 69a720f3be gtphub VTY: fix doc strings for show cmds 2015-12-14 15:52:01 +01:00
Neels Hofmeyr 36948bf7c7 gtphub: log: limit length of hex dumps.
The debug log prints the received/sent bytes in hex. When this data surpasses
the buffer size available for the log string (4096), the log is truncated
and lacks a newline character. Limit the amount of dumped bytes to 1000.

Sponsored-by: On-Waves ehi
2015-12-08 12:21:15 +01:00
Neels Hofmeyr 4d2b3ff6a2 gtphub: add VTY show for peers and peer stats.
Sponsored-by: On-Waves ehi
2015-12-07 13:37:28 +01:00
Neels Hofmeyr d010c49407 gtphub: improve handling of restarted peer.
Handle peer restart earlier, so that all the tunnels are deleted by the restart
code path, instead of the first one being deleted due to reused TEI. That
caused confusing logging messages.

Also, when receiving Delete confirmations from the peer that didn't restart,
don't complain about unknown peer, but acknowledge and remove the half
invalidated tunnel. This means that the pending delete entry from the restart
code path is not needed / not used, so don't bother to add pending delete
entries upon peer restart.

The test test_peer_restarted_reusing_tei() hits the situation where a tunnel is
removed because of a reused TEI rather than the restart counter. Adjust the
test to expect the "out-of-band" delete request earlier on, and to still see
the half invalidated tunnel around. Enhance the test by adding the delete
response from the peer that didn't restart, and add a final tunnels_are()
verification.

Sponsored-by: On-Waves ehi
2015-12-07 13:37:15 +01:00
Neels Hofmeyr bee75969cc gtphub: log most common message type names.
Sponsored-by: On-Waves ehi
2015-12-07 13:37:13 +01:00
Neels Hofmeyr ee07e4f75d gtphub: simplify/fix: one TEI mapping per tunnel.
Because the sender is known, one unique TEI per tunnel suffices to map the TEIs
that the peers are sending to gtphub, instead of previously 4 (SGSN<->GGSN
interaction on User and Ctrl plane, where each had an own unique TEI).

Also, previously, a tunnel's endpoints should also have been checked against
each other for TEI reuse, not only against the endpoints of other tunnels. This
simplification fixes that problem for free.

Thus simplify TEI reuse detection and improve VTY show readability and
debugging.

Adjust log and VTY output for tunnels.
Adjust tests accordingly.

Suggested-by: Holger Hans Peter Freyther <holger@moiji-mobile.com>
Sponsored-by: On-Waves ehi
2015-12-07 13:37:11 +01:00
Neels Hofmeyr f6e4d08219 gtphub: fix: when checking TEIs, skip 0.
Sponsored-by: On-Waves ehi
2015-12-07 13:37:10 +01:00
Neels Hofmeyr 328d2f78c1 gtphub: log: add TEI reuse msg, fix another TEI msg.
Sponsored-by: On-Waves ehi
2015-12-07 13:37:09 +01:00
Neels Hofmeyr ee1e5d758e gtphub: log: add side str to msg for reused TEI
Sponsored-by: On-Waves ehi
2015-12-07 13:37:06 +01:00
Neels Hofmeyr e38fb66f4b gtphub: add more detailed I/O rate counters.
Count bytes and packets per peer port, as well es per tunnel enpoint, which
adds two more levels of detail.

Sponsored-by: On-Waves ehi
2015-12-07 13:37:05 +01:00
Neels Hofmeyr 956d856b61 gtphub: be strict about unknown cmdline args
Sponsored-by: On-Waves ehi
2015-12-07 13:37:04 +01:00
Neels Hofmeyr ba0525e3d8 gtphub: tweak logging.
Less spaces in tunnel strings, adjust tests accordingly.

Use side_idx to remove code dup in rate counter output.

Sponsored-by: On-Waves ehi
2015-12-07 13:37:03 +01:00
Neels Hofmeyr 28a70f20cd gtphub: logging: have one newline per log.
Some logging was multiline to ease human reading of debug output. However,
in the VTY output, these newlines lack a CR motion. Split multiline logs into
separate lines.

Also add one missing space.

Sponsored-by: On-Waves ehi
2015-12-07 13:37:01 +01:00
Neels Hofmeyr 9d8f506f7f gtphub: fix missing newline in log output
Sponsored-by: On-Waves ehi
2015-12-07 13:36:57 +01:00
Neels Hofmeyr e1ba781f7b gtphub: tweak startup log for sgsn_use_sender 2015-12-03 14:48:27 +01:00
Neels Hofmeyr ca2361c237 gtphub: implement sgsn_use_sender for NAT.
If an SGSN is behind NAT, we cannot rely on the default ports. Specifically,
if a GGSN sends a message, the forwarding to the SGSN should go to whichever
port the SGSN last sent from (whether sequence nr is known or not).

Add sgsn_use_sender config and VTY command, and store the sender instead
of the GSN Address IE and default port if set.

Sponsored-by: On-Waves ehi
2015-12-03 14:14:43 +01:00
Neels Hofmeyr d53c6046bc gtphub: prepare: keep tunnel ref in gtp_packet_desc.
Rather than passing a tunnel pointer as function arguments, keep it in the
gtp_packet_desc struct passed around anyway.

Reason: in the next commit (will add sgsn_use_sender), I need the tunnel to be
passed back out to gtphub_handle_buf(), and besides simplifying existing code,
this also makes passing the tunnel back out trivial.

Sponsored-by: On-Waves ehi
2015-12-03 13:59:50 +01:00
Neels Hofmeyr e5a0798c9c gtphub: tweak an error log message 2015-12-03 13:47:05 +01:00
Neels Hofmeyr 8c5b073072 gtphub: Del PDP: replace unnecessary lookup with asserts. 2015-12-03 13:45:15 +01:00
Neels Hofmeyr 59c1b645e2 gtphub: check TEI presence in Create PDP Ctx Response
Sponsored-by: On-Waves ehi
2015-12-03 11:47:30 +01:00
Neels Hofmeyr 87c83d0b89 gtphub: improve logging for invalid packet
Sponsored-by: On-Waves ehi
2015-12-03 11:47:25 +01:00
Neels Hofmeyr d8660ef090 gtphub: cosmetic
During the peer review session with Holger, these things were deemed fixable.

No need to have a static gtp_packet_desc in gtphub_handle_buf.

No need to memcpy, direct assignment does the job.

Remove obsolete comments.

Fix a stray space.

Sponsored-by: On-Waves ehi
2015-12-03 11:47:19 +01:00
Neels Hofmeyr c6d51f5fb4 gtphub: fix restart cleanup peer matching.
Adjust test expectations accordingly.

Sponsored-by: On-Waves ehi
2015-12-03 11:47:16 +01:00
Neels Hofmeyr 996ec1d731 gtphub: wrap gtphub_write() for test suite.
Sponsored-by: On-Waves ehi
2015-12-03 11:47:12 +01:00
Neels Hofmeyr 18d3049612 gtphub: fix use after free.
A tunnel pointer was still being checked after deleting by a call to
expiring_item_del(). 'continue' to the next tun.

Sponsored-by: On-Waves ehi
2015-12-03 11:47:08 +01:00
Neels Hofmeyr 936b890f71 gtphub: Add a debug log
Sponsored-by: On-Waves ehi
2015-12-03 11:46:29 +01:00
Neels Hofmeyr 4573ca8834 gtphub: fix: add a missing NULL check
Sponsored-by: On-Waves ehi
2015-12-03 11:46:19 +01:00
Neels Hofmeyr 52c0bd3025 gtphub: cosmetic: early continue for less indent
Sponsored-by: On-Waves ehi
2015-12-03 11:44:39 +01:00
Neels Hofmeyr bc44330671 gtphub: monitor GSNs' restart counters.
If a GSN indicates that it has reset, tear down each known tunnel for that GSN
individually (don't send the GSNs on the other side a different restart
counter, because they represent more than just this GSN).

Sponsored-by: On-Waves ehi
2015-12-03 11:44:37 +01:00
Neels Hofmeyr 3fdba2ed5a gtphub: cosmetic
Move the SGSN read callback next to the GGSN read callback.

Comments.

Tweak an initialization to NULL.

Sponsored-by: On-Waves ehi
2015-12-03 11:44:28 +01:00
Neels Hofmeyr 10fc024472 gtphub: handle Delete PDP Context.
During resolution of the header TEI, also return the tunnel struct that
resolved the TEI, so the Delete PDP Ctx code does not need to look it up
again.

Upon Delete PDP Ctx Request, remember the IEs and that a request was made.
Upon Delete PDP Ctx Response, find the pending delete and remove the
corresponding tunnel, iff the response indicates success.

Add a context deletion to regression tests, rename the test appropriately.

Sponsored-by: On-Waves ehi
2015-12-03 11:44:19 +01:00
Neels Hofmeyr 2f67125c32 gtphub: remove obsolete todo comment
Sponsored-by: On-Waves ehi
2015-12-03 11:44:13 +01:00
Neels Hofmeyr 800126b1f3 gtphub: fix segfault when empty config.
gsn_addr_from_str(): return error upon NULL string.
Add some debug logging.

With an empty config, no bind addresses were set, and the address parser
did not check for a NULL pointer, resulting in a segfault.

Sponsored-by: On-Waves ehi
2015-12-03 11:44:08 +01:00
Neels Hofmeyr cd865d62f0 gtphub: be more fatal about not finding an unused TEI.
Sponsored-by: On-Waves ehi
2015-12-03 11:44:03 +01:00
Neels Hofmeyr 085500807c gtphub: fix some style complaints from cppcheck
Sponsored-by: On-Waves ehi
2015-12-03 11:43:57 +01:00
Neels Hofmeyr ff4b630de9 gtphub: add two stubs for Delete PDP msgs
Sponsored-by: On-Waves ehi
2015-12-03 11:43:49 +01:00
Neels Hofmeyr 817bc32696 gtphub: vty: add missing SGSN-proxy output.
Sponsored-by: On-Waves ehi
2015-12-03 11:43:40 +01:00
Neels Hofmeyr a9905a51f9 gtphub: refactor: use side_idx everywhere.
This is a mostly cosmetic change. Instead of separate buffer handling
functions, reduce some code duplication by using a side_idx just like the
plane_idx, with arrays.

Sponsored-by: On-Waves ehi
2015-12-03 11:43:25 +01:00
Neels Hofmeyr 7174b169e0 gtphub: make sure mapped TEIs aren't occupied (incomplete).
This could be done way better, discussion is pending/ongoing. It is indeed
quite unlikely that any user will ever hit this situation, so there is no
strong drive to invest effort in a more comprehensive implementation.

Sponsored-by: On-Waves ehi
2015-12-03 11:40:24 +01:00
Neels Hofmeyr d121ea6124 gtphub: use a single TEI pool across planes.
There's no need to keep two separate number pools when both can be fed
from the same pool. User and Ctrl plane TEIs can technically overlap without
colliding, but it doesn't hurt if they don't overlap, either.

Sponsored-by: On-Waves ehi
2015-12-03 11:40:22 +01:00
Neels Hofmeyr f977320736 gtphub: cosmetic: for_each_side,_plane macros.
Simplify looping over sides and planes. I'm tired of typing the same for
loops all the time.

Sponsored-by: On-Waves ehi
2015-12-03 11:40:18 +01:00
Neels Hofmeyr ba9e9f63bc gtphub: implement restart counter properly.
Force passing a restart counter, by adding such arg to gtphub_start() (test
suite is not affected by this).

In gtphub_main.c, add -r,--restart-file <path> and next_restart_count() to
maintain the counter file. While at it, tweak the cmdline help to unify the
formatting (mostly commas and a missing line break).

Send gtphub's own restart counter. So far, the sender's restart counter was
copied through, which would break as soon as more than one GSN would talk to
the same peer with differing restart counters.

Also fix the in-mem restart counter data type (one octet, not two).

Sponsored-by: On-Waves ehi
2015-12-03 11:40:15 +01:00
Neels Hofmeyr 8d1ffbd3ba gtphub: complain about excess cmdline args.
Sponsored-by: On-Waves ehi
2015-12-03 11:40:12 +01:00
Neels Hofmeyr 005f175c3b gtphub: fix a conditional for log output
Sponsored-by: On-Waves ehi
2015-12-03 11:40:09 +01:00
Neels Hofmeyr fc1be3a0c1 gtphub: avoid segfault for incomplete tunnels.
Sponsored-by: On-Waves ehi
2015-12-03 11:40:05 +01:00
Neels Hofmeyr e54cd1555a gtphub: track tunnels explicitly.
So far, gtphub worked perfectly by only tracking single TEIs ... for probably
most uses. But a Ctrl plane tunnel may have expired despite a still active
corresponding User plane tunnel. The User plane would continue to work
indefinitely, but if any Ctrl messages followed after more than six hours of
Ctrl silence, they would have been dropped due to an expired TEI mapping.

We want to
- combine expiry of a user TEI with its ctrl TEI. (done in this patch)
- upon delete PDP context, remove both user and ctrl TEI mappings. (future)
- when a peer indicates a restart counter bump, invalidate its tunnels.
  (future)

To facilitate these, track tunnels, complete with both SGSN's and GGSN's
address, original and replaced TEIs, all for both user and ctrl plane, in a
single struct. A single expiry entry handles the entire tunnel, instead of
previously four separate expiries for each endpoint identifier.

Add the concept of a "side", being either GGSN or SGSN, to index tunnel
endpoint structs, and so on.

Track the originating side in the gtp_packet_desc.

Add header_tei_rx: set_tei() overwrites header_tei, but the originally received
header TEI is still needed to match a Create PDP Context Response up with its
Request (and for logging).

Adjust the test suite to expect tunnel listing strings instead of TEI mappings,
with a bonus of making it a lot easier to grok, and including the IP addresses.

Add regression test for refreshing tunnel expiry upon use.

Note: the current implementation is as slow as can possibly be, iterating all
the tunnels all the time. Optimizations are kept for a future commit, on
purpose.

BTW, the sequence number mapping/unmapping structures remain unchanged.

Sponsored-by: On-Waves ehi
2015-12-03 11:40:03 +01:00
Neels Hofmeyr 2c8b58139f gtphub: cosmetic/prepare: rename expiry queues.
The expiry queues are already used for resolved GGSN addresses, and will
soon enlist tunnel structs. Hence the naming should be more general.

Sponsored-by: On-Waves ehi
2015-12-03 11:39:57 +01:00
Neels Hofmeyr 1aa0e47104 gtphub: add assertion to ensure expiry ordering.
Make 100% sure the user adds expiring_items in chronological order by asserting
that a newly added expiry is >= the last expiry in the queue. Add llist_last()
to facilitate.

Sponsored-by: On-Waves ehi
2015-12-03 11:39:55 +01:00
Neels Hofmeyr 508514c7c5 gtphub: cosmetic/prepare: add nr_map_refresh().
Sponsored-by: On-Waves ehi
2015-12-03 11:39:49 +01:00
Neels Hofmeyr 29d926be12 gtphub: move timestamp into packet struct.
Instead of passing the current time around in function arguments ('now'),
rather store the current time once upon decoding a GTP packet in the
gtp_packet_desc passed around anyway ('p->timestamp').

Sponsored-by: On-Waves ehi
2015-12-03 11:39:47 +01:00
Neels Hofmeyr 4b2cbdab3e gtphub: first vty show commands.
Start adding VTY commands to show rate counters / statistics / cache dumps.

Sponsored-by: On-Waves ehi
2015-12-03 11:39:41 +01:00
Neels Hofmeyr 1ba50c6598 gtphub: add first rate counters
Sponsored-by: On-Waves ehi
2015-12-03 11:39:39 +01:00
Neels Hofmeyr dba6d1af69 gtphub: cosmetic: clarify bind pointer naming.
Some gtphub_bind pointers point to an array of binds, some point directly at
instances. Make the distinction between the two more obvious by adding an
'_arr' suffix to the array ones.

Partly in preparation for upcoming rate counters.

Sponsored-by: On-Waves ehi
2015-12-03 11:39:38 +01:00
Neels Hofmeyr 20bd6bfef5 gtphub: add explicit cleanup handles.
Clean up functionality is added for the test suite only, to be able to clean
out all allocations and test against memory leaks.

So far, it was sufficient to expire everything to free a gtphub. In preparation
for the upcoming rate counters, which will need to be freed explicitly, add
gtphub functions to clean up everything.

As added bonus, also close the sockets explicitly -- not really needed upon
program exit, neither by the test suite, but *if* we have a cleanup function,
it should clean up everything properly.

Closing the sockets is however kept separate, for the test suite.
gtphub_start() and gtphub_stop() are for normal use (published in gtphub.h),
and gtphub_init() and gtphub_free() are for the test suite, without sockets.
(gtphub_stop() will probably never be called by anyone, but its existence
completes the picture.)

In gtphub_test.c, have a function to clean up the testing gtphub struct. First,
expire everything by timeout, assert emptiness, then call the cleanup function.
Call from each test in the end.

Sponsored-by: On-Waves ehi
2015-12-03 11:39:36 +01:00
Neels Hofmeyr 1ed9a8673d gtphub: ensure cleanup of peer addresses.
Upon calling gtphub_peer_del(), all addresses and ports should already have
expired (by force). Make sure the code heeds that with a so far missing
assertion.

Sponsored-by: On-Waves ehi
2015-12-03 11:39:34 +01:00
Neels Hofmeyr b6c2db569f gtphub: ares vty and init
From sgsn_vty.c, copy the cfg_grx_ggsn_cmd to add an ares server to the static
sgsn_instance.

This is sort of preliminary. As described in comments, the sgsn_ares functions
should actually be separated from the static sgsn structure. gtphub keeps such
an sgsn structure just for the sgsn_ares functions.

Sponsored-by: On-Waves ehi
2015-12-03 11:39:33 +01:00
Neels Hofmeyr d9b1d49485 gtphub: review some logging.
Sponsored-by: On-Waves ehi
2015-12-03 11:39:31 +01:00
Neels Hofmeyr 4960fab767 gtphub: cosmetic: rename a file.
gtphub_ext.c's initial purpose was to wrap a specific function. The file
then turned into everything related to DNS, which fits pretty well. Rename
to gtphub_ares.c.

Tweak the header comment to reflect the new file name.

Sponsored-by: On-Waves ehi
2015-12-03 11:39:30 +01:00
Neels Hofmeyr e2ed8e6cc3 gtphub: nr_map: add min,max and wrap.
Implement min/max bounds for nr_pool, adjust nr_pool_init() and current tests,
and create unit tests for nr_map wrapping.

Sequence numbers range from 0 to 65535, while TEIs range from 1 to 0xffffffff.
Both cause problems when the nr_pool surpasses the range: seq exit their valid
range, causing unmappings to fail, and a TEI would be mapped as zero (invalid).

Add a comment about TEI wrapping, and lose the comment about random TEIs (not
really important).

Sponsored-by: On-Waves ehi
2015-12-03 11:39:28 +01:00
Neels Hofmeyr 334af5dd9d gtphub: fix number map range for TEIs.
Use unsigned int for nr_map, just large enough to fit the TEI space.
Adjust log output formats and casts accordingly.

Fixes: TEIs are uint32_t, but the nr_map so far used int. This would cause TEIs
from 0x80000000 on to be handled and printed as a negative value.

Sponsored-by: On-Waves ehi
2015-12-03 11:39:24 +01:00
Neels Hofmeyr 8fbfaa51bb gtphub: remove another obsolete comment. 2015-11-26 22:59:10 +01:00
Neels Hofmeyr a4370dd969 gtphub: fix ares segfault: add missing initialization.
The struct gtphub_resolved_ggsn was not initialized properly, so that adding
it to a list caused a segmentation fault.
2015-11-24 12:52:13 +01:00
Harald Welte 97b6bfa996 Fix compilation with no libc-ares present on the system
This build failure was introduced with the OAP and gtphub changes.
2015-11-21 13:16:08 +01:00
Neels Hofmeyr 6187e010a8 gtphub: fix echo reply to SGSNs: wrong fd. Add test.
The actual fix is just one character, but also add a regression test against
this, on both CTRL and USER plane.
2015-11-20 01:15:03 +01:00
Neels Hofmeyr 3c820ee532 gtphub: fix three oversights (thanks to coverity).
- an unnecessary if-not-NULL check (1339764);
- a missing nul termination safety net (1339768);
- a typo resulting in the wrong proxy being logged (1339767).

Sponsored-by: On-Waves ehi
2015-11-18 17:34:43 +01:00
Neels Hofmeyr 3d3aa8fb88 gtphub: fix fatal log msg for SGSN proxy.
While reworking the logging, a stray comma found its way into the code.

Fixes coverity 1339765.

Sponsored-by: On-Waves ehi
2015-11-18 17:34:43 +01:00
Neels Hofmeyr 4034897038 gtphub: fix gtphub_read() semantics.
gtphub always wants to know the sender, hence make the from_addr pointer
mandatory.

Fixes two coverity complaints (1339766, 1339764).

Sponsored-by: On-Waves ehi
2015-11-18 17:34:43 +01:00
Neels Hofmeyr 9cfe037559 gtphub: cosmetic: break long lines.
Fit most of the code in 80 chars width. Some instances still leak past 80
characters because of long function names, inline comments or the like, "the
exception proves the rule."

Sponsored-by: On-Waves ehi
2015-11-16 15:18:24 +01:00