Commit Graph

4849 Commits

Author SHA1 Message Date
Jacob Erlbeck f8562e362b gbproxy: Rename the field 'enabled_tllis' to 'logical_links'
This field in struct gbproxy_patch_state has involved and holds a
list of all tracked logical links now. Thus the name is modified
accordingly.

Sponsored-by: On-Waves ehf
2014-10-09 17:45:14 +02:00
Jacob Erlbeck 91d2f8a704 gbproxy: Use the term 'link' instead of 'tlli'
Currently in many places where 'tlli' (Temporary Logical Link
Identifier) within identifiers is used, the logical link itself is
meant instead. For instance, the tlli_info contain information about
an LLC logical link including up to four individual TLLI.

To avoid confusion between these concepts, this patch replaces all
'tlli_info' by 'link_info' and a few 'tlli' by 'link'.

Sponsored-by: On-Waves ehf
2014-10-09 17:44:57 +02:00
Jacob Erlbeck 9a7b0d5641 gbproxy: Rename functions related to tlli_info
This patch replaces 'tlli' by 'tlli_info' within the following
function identifiers:
  - gbproxy_delete_tlli
  - gbproxy_delete_tllis
  - gbproxy_remove_stale_tllis
  - gbproxy_touch_tlli
  - gbproxy_unregister_tlli
  - gbproxy_remove_matching_tllis
  - gbproxy_find_tlli -> gbproxy_tlli_info_by_tlli
  - gbproxy_find_tlli_by_* -> gbproxy_tlli_info_by_*

These functions refer to the whole logical link info rather than to a
certain TLLI. So they are renamed to be named consistently with
gbproxy_attach_tlli_info and others.

Sponsored-by: On-Waves ehf
2014-10-09 17:43:53 +02:00
Jacob Erlbeck 9a6b763507 gbproxy: Remove sgsn_nsei parameter
The function gbproxy_imsi_acquisition() has a parameter sgsn_nsei
that is alyways equal to tlli_info->sgsn_nsei (if tlli_info is not
NULL).

This patch removes this parameter from gbproxy_imsi_acquisition() and
gbproxy_flush_stored_messages() and accesses tlli_info->sgsn_nsei
instead within these functions.

Sponsored-by: On-Waves ehf
2014-10-09 17:43:34 +02:00
Jacob Erlbeck 8992f30866 gbproxy: Rename identifiers related to IMSI matching
This patch renames gbproxy_check_tlli() to
gbproxy_imsi_matches() and struct tlli_info's
enable_patching to imsi_matches.

It's meant to be more obvious and consistent this way.

Sponsored-by: On-Waves ehf
2014-10-09 17:43:12 +02:00
Jacob Erlbeck 08fbeb8fa4 gbproxy/sgsn: Enforce termination when creating a P-TMSI/TLLI
Currently the number of iterations when creating a P-TMSI/TLLI is not
limited. It is nevertheless very unlikely that the loop will not
terminate. On the other hand, the number of iterations of every loop
should have an upper bound (loop variant) which wouldn't be the case
here if an arbitrary random generator was used.

This patch limits the number of iterations to 23 and logs an error if
the creation of the indentifier was aborted due to this limit.

Sponsored-by: On-Waves ehf
2014-10-09 17:42:23 +02:00
Jacob Erlbeck e27ab916d6 gbproxy: Restart IMSI acquisition on RA UDP REQ
Currently the IMSI acquisition is not restarted when a RA Update
Request is received. This leads to repeated N(U) in the generated
Ident Request message, which in turn causes the MS to drop the
second of these message. This is bad, when the first Ident Response
has been lost between MS and gbproxy.

This patch changes gbproxy_imsi_acquisition() to handle RA Update
Request messages like Attach Requests.

Sponsored-by: On-Waves ehf
2014-10-09 17:41:41 +02:00
Jacob Erlbeck 2ec2757def gbproxy/test: Test IMSI acquisition for RA UDP REQ
When a MS is state GMM_REGISTERED enters a new RA, it sends a RA
Update Request which is then handled by a gbproxy that possibly
doesn't have a matching tlli_info. In this case, depending on the
configuration an identification procedure to acquire the IMSI must be
started.

This adds tests to test_gbproxy_imsi_acquisition():
 - IMSI acquisition triggered by a RA Update Request message
 - Reaction to repeated RA Update Request messages, like it could be
   caused by packet loss between PCU and gbproxy.

Sponsored-by: On-Waves ehf
2014-10-09 17:41:06 +02:00
Jacob Erlbeck 258ce3ded5 sgsn: Free MM context after receiving a Detach Request
On a Detach/Re-attach cycle the Address Sanitizer detected a
use-after-free kind of problem. That is because we tried to
destroy the LLME twice. The first time it is destroyed as part
of the Detach handling ans the second time it is destroyed as
part of destroying the old MM context.

In case the GPRS GMM detach message is lost the SGSN needs
to reply besides not having a MM entry.

The alternative would have been to add NULL checks for all
usages of ctx->llme which would not have helped with the
readability.

Sponsored-by: On-Waves ehf
2014-10-09 17:22:34 +02:00
Holger Hans Peter Freyther fe92133132 sgsn: Add test that exposes a dangling pointer to the LLME
On detach the LLME get's unassigned (and hence destroyed) but the
GMM context will still point to that dead structure.
2014-10-09 17:22:34 +02:00
Holger Hans Peter Freyther 4299c0560f sgsn: Create testcase that verifies that llmes get deleted
On an "unassignment" this code verifies that the LLME will vanish
from the list of LLMEs. We assume that this doesn't create a
memory leak.
2014-10-09 17:22:34 +02:00
Holger Hans Peter Freyther 68c6f887c2 sgsn: Add boilerplate code for a SGSN test 2014-10-09 17:22:34 +02:00
Holger Hans Peter Freyther 7b76f82b6e mgcp: Count the incoming data instead of the modified one
For jitter, transit and packet loss we should count the data
that arrived and not the data we send towards the remote. This
is changing the jitter timings to what they were before the
re-factoring.

For forced timing we might willingly add jumps in the sequence
number but for jitter and packet loss we are more interested
in the data that traveled through the wire/air.
2014-10-09 17:22:33 +02:00
Holger Hans Peter Freyther 05d481a42c mgcp: Do not detect the initial package as a wrap around
The Annex A code has a probation period but we don't have it. When
starting with seq_no==0 do not assume that the sequence numbers
have wrapped. Do it by moving the entire checking code into the
else.
2014-10-09 17:22:33 +02:00
Holger Hans Peter Freyther a5a59c9a05 mgcp: Move Annex A counting out of patch/count method
mgcp_patch_and_count has grown due supporting linearizing timestamps,
ssrc and other things for equipment like the ip.access nanoBTS. Fight
back and move the Annex A code into a dedicated method.

The result is updated as we now count after all the patching and for
the Annex A code no change in SSRC can be detected.
2014-10-09 17:22:33 +02:00
Holger Hans Peter Freyther 2a7ab868e3 mgcp: We only look at the RTP header use that in the comment 2014-10-09 17:22:33 +02:00
Ruben Pollan ed04a0d060 nitb: Add subscriber delete command 2014-10-03 09:15:28 +02:00
Holger Hans Peter Freyther 47c624b561 bsc: Let the VTY verify that the timeout is a number
Before the old code allowed to specify "timeout-ping bla" which
would be parsed as '0' which would trigger a flood of pings. Use
the VTY code to parse it as a number.
2014-10-02 12:08:29 +02:00
Daniel Willmann f8070f4793 gprs: Move log message about mm context after NULL check
Fixes: CID#1240205
2014-09-25 14:24:55 +02:00
Daniel Willmann 465531403c gprs: Improve loglevels and log messages for SGSN
Many log levels were DEBUG without any good reason. Also where possible
the details of the MM or PDP context are now logged with LOGMM/PDPCTXP.
2014-09-22 10:47:11 +02:00
Daniel Willmann b15ceec33f gprs_sgsn.h: Add two macros to log details of MM/PDP contexts 2014-09-22 10:47:11 +02:00
Jacob Erlbeck 25ad52cf6a sgsn: Reset local LLC parameters when sending XID reset
Currently when gprs_llgmm_reset() is invoked an XID reset is sent but
the local LLC parameters (e.g. V(U)) are not cleared (see GSM 04.64,
8.5.3.1). This can lead to discarded messages on the SGSN side.

This patch modifies gprs_llgmm_reset to clear vu_send, vu_recv,
oc_ui_send, oc_ui_recv.

Sponsored-by: On-Waves ehf
2014-09-19 11:55:21 +02:00
Jacob Erlbeck 91a0e8639a gbproxy: Separate SGSN numeric namespaces
Currently the SGSN side message's TLLI are searched without checking
the originating SGSN. This leads to collisions if both SGSN use the
same P-TMSI for different MS.

With this patch, the SGSN NSEI is stored within the tlli_info and is
used in comparisons to separate the namespaces.

Note that this type of collision cannot happen with BSS numbers,
since the tlli_info are already separated and stored per (BSS) peer.

Sponsored-by: On-Waves ehf
2014-09-19 11:21:35 +02:00
Jacob Erlbeck af952baffc gbproxy/test: Add a test with a P-TMSI collision between two SGSNs
This patch extends test_gbproxy_secondary_sgsn() by the establishment
of a third MS connection using a P-TMSI that has been assigned by the
other SGSN already. It is expected that the entries do not
interfere and are properly retrieved.

Note that these collisions are not handled properly yet.

Sponsored-by: On-Waves ehf
2014-09-19 11:21:24 +02:00
Jacob Erlbeck 2bb4543809 gbproxy/test: Fix Identification Response
At one place, the reply to the second Ident Req contains the wrong
IMSI. That is fixed by this patch.

Sponsored-by: On-Waves ehf
2014-09-19 11:21:13 +02:00
Jacob Erlbeck 1a02442f66 gbproxy: Check other tlli_infos for matching TLLI/P-TMSI
Currently it is possible to create serveral entries referring to the
same P-TMSI/TLLI by using P-TMSI assigment via Attach Accept or
RA Update Accept messages. This can lead to the use of the wrong
tlli_info.

This patch adds gbproxy_remove_matching_tllis() that removes all
conflicting entries. This function is called after the P-TMSIs and
the resulting TLLIs has been set up.

Sponsored-by: On-Waves ehf
2014-09-19 11:21:01 +02:00
Jacob Erlbeck 04f679be73 gbproxy/test: Add test case for P-TMSI assigment
This tests P-TMSI assignment when P-TMSI patching is disabled. A test
with colliding P-TMSI in Attach Accept messages is included.

Note that P-TMSI collisions are not handled properly yet.

Sponsored-by: On-Waves ehf
2014-09-19 11:20:50 +02:00
Jacob Erlbeck 85e5c8f905 gbproxy: Parse RA_UPD_REJ and invalidate TLLI
Since this message puts the MS into DEREGISTERED state (like a detach
procedure), this message is parsed and the invalidate_tlli field is
set accordingly.

Sponsored-by: On-Waves ehf
2014-09-19 11:20:31 +02:00
Jacob Erlbeck cdd37837b3 gbproxy: Delete and show detached entries via VTY
This commit adds/modifies the following VTY commands:

  - delete-gbproxy-tlli <NSEI> de-registered : Delete all
    de-registered entries
  - show gbproxy tllis : Display 'DE-REGISTERED' when appropriate

In addition, the implementation of the delete-gbproxy-tlli command
has been split into two functions (with and without TLLI/IMSI
value).

Sponsored-by: On-Waves ehf
2014-09-19 10:54:21 +02:00
Jacob Erlbeck d3bde96b36 gbproxy: Replace LOGP by LOGPC for continued lines
gprs_gb_log_parse_context() uses a sequence of LOGP calls to compose
a single message line. This leads to cluttered log output.

This patch replaces all but the first LOGP applications in this
function by applications of LOGPC.

Sponsored-by: On-Waves ehf
2014-09-19 10:49:17 +02:00
Jacob Erlbeck 16a3cd3847 gbproxy: Avoid multiple tlli_info entries with the same IMSI
Currently it is possible to create several tlli_info entries with the
same IMSI.

This patch disables this by adding a check before the imsi field
is updated.

Sponsored-by: On-Waves ehf
2014-09-19 10:49:12 +02:00
Jacob Erlbeck 7430da621a gbproxy: Keep tlli_info after detach
Currently a tlli_info entry is deleted when the TLLI gets invalidated
by a Detach message.

This patch introduces the possibility to keep tlli_info entries in
the list. Those entries then have cleared TLLI fields, are marked as
de-registered, and can only be retrieved by a message containing an
IMSI or a P-TMSI.

The following VTY configuration commands are added to the gbproxy
node:
  - tlli-list keep-mode never : Don't keep the entries (default)
  - tlli-list keep-mode re-attach : Only keep them, when a Detach
    message with re-attach required has been received
  - tlli-list keep-mode identified : Only keep entries which are
    associated with an IMSI
  - tlli-list keep-mode always : Keep all entries

Note that at least one of max-length or max-age should be set when
this feature is used to limit the number of entries.

Sponsored-by: On-Waves ehf
2014-09-19 10:46:23 +02:00
Jacob Erlbeck cba4c0cc60 gbproxy: Only patch what has been configured
Currently when patching is basically enabled P-TMSI and TLLI gets
patched even when P-TMSI patching is not enabled. Albeit the result
is correct in this case (the same value is re-written), the counter
shows unexpected results.

This patch adds configuration checks for P-TMSI and TLLI patching. It
also reorders the code of gbproxy_patch_raid to return early if there
is nothing to patch.

Sponsored-by: On-Waves ehf
2014-09-18 13:46:09 +02:00
Jacob Erlbeck 772a22b529 gbproxy/test: Add test case for tlli_info persistence
This test case consists of a sequence of several attach and detach
procedures. The kind of detach varies (mobile originated, mobile
terminated re-attach required, mobile terminated re-attach not
required, routing area update reject). To main focus is to check that
the tlli_info is de-registered correctly (not accessible via the
TLLI) and that can be re-used afterwards (which is not implemented
yet).

Sponsored-by: On-Waves ehf
2014-09-18 13:40:03 +02:00
Jacob Erlbeck a42fe9f61e gbproxy: Remove gbproxy_register_tlli
This function is a remainder of the initial implemenation that was
not meant for TLLI patching and can be used for the BSS side only.
The SGSN side is already using a composition of more flexible
single purpose functions.

This patch changes the implementation to use a similar approach. The
function is moved to gbproxy_test.c and renamed to register_tlli to
keep the tests intact.

Sponsored-by: On-Waves ehf
2014-09-18 13:21:17 +02:00
Jacob Erlbeck 2a5096dfc6 gbproxy: Send DETACH_ACC if the IMSI has not been acquired
If IMSI acquisition is enabled and the gbproxy receives a Detach
request from the MS, it cannot pass it to the SGSN since the
acquisition has not yet been completed.

This patch implements the generation of a Detach Accept message and
for this case and updates the TLLI state accordingly.

Sponsored-by: On-Waves ehf
2014-09-18 13:21:16 +02:00
Jacob Erlbeck 948c07f490 gbproxy: Fixed RAI patching in Attach Request messages
Currently the RAI in the LLC part of the message is not updated if
the message has been taken from the list of stored messages. The
reason is, that old_raid_matches is update in
gbprox_process_bssgp_ul() but not in gbproxy_flush_stored_messages().

This patch moves the check to gprs_gb_parse_bssgp() which is called
at both places and where other fields like parse_ctx->tlli are set,
too.

In addition, old_raid_matches is replaced by old_raid_is_foreign
since this is clearer in the case when there is no old RAI at all.

Several RAI patch counter assertions are also added to
test_gbproxy_ra_patching().

Sponsored-by: On-Waves ehf
2014-09-18 13:20:58 +02:00
Jacob Erlbeck 991606b57a gbproxy/test: Add/modify test cases
Add a Attach Request message to test_gbproxy_ra_patching, where the
BSSGP RAI differs from the old RAI signalled in the LLC part. This
case had not been tested explicitely yet.

Change the RAI in the first Attach Request in
test_gbproxy_imsi_acquisition from rai_unknown to rai_bss.

Add Detach Requests to test_gbproxy_imsi_acquisition, one for a
incomplete attach procedure and one for an unknown (fresh) TLLI.
In these cases, the acquisition of a IMSI is not necessary and also
doesn't work properly with an E71.

Sponsored-by: On-Waves ehf
2014-09-18 11:26:07 +02:00
Jacob Erlbeck 2fd1ba4c6d gbproxy: Replace 'mi_data' by 'imsi'
Since at all places where mi_data/mi_data_len is used it will always
contain an IMSI. Thus the names of the identifiers have been updated
accordingly for clarity.

Sponsored-by: On-Waves ehf
2014-09-18 11:22:15 +02:00
Jacob Erlbeck 6bafa4ce0d gbproxy: Rework gbproxy_imsi_acquisition
This commit changes gbproxy_imsi_acquisition as follows:

tlli_info->mi_data_len is used instead of parse_ctx->imsi to check,
whether the IMSI is known already. Since the function is always
called after gbproxy_update_tlli_ul(), the two values are already
synchronized.

Messages are always flushed when the IMSI gets known, if the current
message is IDENT RESP discard it, otherwise continue processing as
usual.

The 'if' clauses are simplified for better readability.

Sponsored-by: On-Waves ehf
2014-09-18 11:21:57 +02:00
Jacob Erlbeck 0b243a106a gbproxy: Refactor gbprox_process_bssgp_ul into smaller functions
gbprox_process_bssgp_ul has grown quite large mainly by the addition
of IMSI acquisition.

This patch moves that code into several smaller functions. In
addition, the peer resolution which is similar to that in
gbprox_process_bssgp_dl is moved into a separate function, too.

Sponsored-by: On-Waves ehf
2014-09-18 08:49:21 +02:00
Pablo Neira Ayuso ee11bc0f5c osmux: send osmux stats in MGCP DLCX responses
This allows us to know what number of messages and bytes has been
received per active osmux endpoint.

Note that an Osmux message is composed of several chunks. Each chunk
contains an osmux header plus several voice data frames.

 P: PS=385, OS=11188, PR=195, OR=5655, PL=0, JI=49
 X-Osmo-CP: EC TIS=0, TOS=0, TIR=0, TOR=0
 X-Osmux-ST: CR=51, BR=3129

The new 'X-Osmux-ST:' notifies the received chunks and bytes.
2014-09-17 19:34:25 +02:00
Holger Hans Peter Freyther 8d2fe43c7f nitb: Don't mention the broken PCAP generation option
The PCAP option doesn't seem to work for TCP/IP based BTS. Don't
mention it to not confuse people that search for a way.
2014-09-16 18:13:44 +02:00
Pablo Neira Ayuso 115e81ee19 osmux: account extracted traffic from the osmux batch
Use struct mgcp_rtp_end statistics to account the RTP messages
that has been extracted from the osmux batch and transmitted.
2014-09-16 14:32:37 +02:00
Jacob Erlbeck 1abfdc218e gbproxy: Remove patch_mode, update initial checks
This patch removes the patch_mode feature including the related VTY
command patch-mode. Where sensible, the other configuration flags are
queried instead.

In addition, this initial checks in gbprox_process_bssgp_dl() and
gbprox_process_bssgp_ul() have been updated.

The patch mode feature has not been used and was increasingly
difficult to maintain.

Sponsored-by: On-Waves ehf
2014-09-09 10:10:25 +02:00
Jacob Erlbeck 7fb26c2943 gbproxy/test: Add assertions, improve test coverage
This patch add explicit tests for
  - gbproxy_peer_by_bvci
  - gbproxy_peer_by_nsei
  - gbproxy_cleanup_peers
  - gbproxy_peer_by_rai
  - gbproxy_peer_by_lai
  - gbproxy_peer_by_lac
and for messages with an unknown TLLI sent by the SGSN.

Sponsored-by: On-Waves ehf
2014-09-09 10:10:12 +02:00
Jacob Erlbeck 31591142e9 gbproxy: Reset IMSI acquisition and free stored messages in tlli_info
Currently the stored messages are only removed, when IMSI acquisition
has succeeded. In addition, receiving two ATTACH_REQ messages in
sequence (e.g. due to loss of a Identity Req/Resp message) will not
restart the IMSI acquisition procedure.

This patch adds gbproxy_tlli_info_discard_messages() to clean up the
message list and calls it from gbproxy_delete_tlli() fixing a
potential memory leak. It is also called when an Attach Request
message has been received. In that case the imsi_acq_pending flag is
cleared, too. This would (re-)trigger the IMSI acquisition procedure
at each of these messages. If an Ident Response has been lost,
resending the Ident Request with the same N(U) will not work.
Therefore the N(U) gets incremented on each Ident Request generated
by the gbproxy. The first N(U) used is 256 which shouldn't collide
with the V(UT) used by the SGSN given that P-TMSI patching is enabled
(since a new random TLLI is used initially on every new (no
tlli_info) connection and V(U) starts with zero then).

Ticket: OW#1261
Sponsored-by: On-Waves ehf
2014-09-09 10:10:00 +02:00
Jacob Erlbeck ea1698e322 gbproxy/test: Add test cases for IMSI acquisition
If the Attach Request procedure gets restarted e.g. because of a lost
message, all of these messages are stored if IMSI acquisition is in
progress.

This patch adds a test for this case and modifies the dump_peers
function to output the number of stored messages.

Note that the number of stored messages currently increases with each
(repeatedly) received Attach Request which is not the desired behaviour.

Sponsored-by: On-Waves ehf
2014-09-09 10:09:50 +02:00
Jacob Erlbeck b1ee5cd3b6 gbproxy: Fix P-TMSI reassignment
Currently, a new P-TMSI within an Attach Accept or within an RA
Update Request is applied to the TLLI mapping (gbproxy_reassign_tlli)
_before_ patching is done. This can lead to inconsistent behaviour
when the TLLI validation has not been completed, which is the case
when subsequent RA UDP REQ are received. The new TLLI must not be
applied to the message itself yet, it should only be considered for
following messages.

This patch moves the TLLI reassignment to
gbproxy_update_tlli_state_after() to fix that.

It also separates the implementation of the feature that a new
tlli_info can be created when such a message is received from the
SGSN. This makes sense, when P-TMSI patching is not active and the
tlli_info entry has expired.

Sponsored-by: On-Waves ehf
2014-09-09 10:05:56 +02:00
Jacob Erlbeck 37fda77814 gbproxy: Change creation of tlli_info for SGSN originated messages
Currently tlli_info are created for SGSN originated messages when
the SGSN TLLI cannot be found and P-TMSI patching is active. This
doesn't make much sense, since the BSS side TLLI is not known in this
case. Given that the SGSN is working properly, that can only happen
if either the tlli_info has expired or the gbproxy has been
restarted.

This patch disables the creation of a tlli_info in this case.

Note that these messages are passed unmodified to the MS so far.

Sponsored-by: On-Waves ehf
2014-09-09 09:47:03 +02:00