Commit Graph

4688 Commits

Author SHA1 Message Date
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
Jacob Erlbeck 52f070a099 gbproxy/test: Extend P-TMSI patch test by a sequence of RA UDP REQ
This adds a sequence of two RA update procedures to
test_gbproxy_ptmsi_patching(). Each of them assigns a new P-TMSI.

Note that the implementation fails to patch the RAI within the
message labelled 'RA UDP ACC (P-TMSI 3)' and logs 'TLLI sent by the
SGSN is unknown'.

Sponsored-by: On-Waves ehf
2014-09-08 13:34:13 +02:00
Jacob Erlbeck cd9e1c94e5 gbproxy: Reorganize VTY commands
Since the secondary SGSN selection and APN patching can both be
enable/disabled by IMSI matching, this patch introduces a separate
match-imsi command and removes the corresponding variant of the
core-access-point-name command.

P-TMSI patching and IMSI acquisition are enabled/disabled by
match-imsi resp. secondary-sgsn. The patch-ptmsi and acquire-imsi
commands are still available for internal testing but are subject to
being removed.

Sponsored-by: On-Waves ehf
2014-09-08 10:54:20 +02:00
Jacob Erlbeck 146e30736d gbproxy: Show number of stored messages in VTY show
This patch extends the 'show gbproxy tllis' command to display the
number of stored messages per tlli_info if there are any.

Sponsored-by: On-Waves ehf
2014-09-08 10:20:18 +02:00
Jacob Erlbeck 1e65b0e7a1 gbproxy: Forward SGSN originated STATUS messages with BVCI
Currently all STATUS messages coming from the SGSN are just logged
and dropped. This prevents the PCU from recognising that the
(secondary) SGSN doesn't know about a certain BVCI and might require
a reset procedure.

This patch changes gbprox_rx_sig_from_bss() to forward STATUS
messages with cause "Invalid BVCI" containing a BVCI to the BSS.

Note that this will not forward broken "Invalid BVCI"
messages which do not include a BVCI IE.

Sponsored-by: On-Waves ehf
2014-09-08 10:20:18 +02:00
Jacob Erlbeck 17b42b81f0 gbproxy: Make STATUS messages spec compliant
Currently the gbproxy sends STATUS messages that are not compliant to
GSM 08.18, 10.4.14.1: The BVCI must be included if (and only if) the
cause is either "BVCI blocked" or "BVCI unknown".

This patch adds a missing BVCI to UNKNOWN_BVCI and BVCI_BLOCKED
status messages if the BVCI is available. Otherwise, INV_MAND_INF is
used instead.

Sponsored-by: On-Waves ehf
2014-09-08 10:20:18 +02:00
Jacob Erlbeck 18a3787296 gbproxy: Check tlli_info when patching, fix APN patching
Currently the numeric TLLI or tlli_info's enable_patching flag is
used to decide, whether a APN shall be patched or the secondary SGSN
shall be used. Using the numeric TLLI imposes a problem, when
TLLI/P-TMSI patching is used, since gbproxy_check_tlli uses the BSS
side TLLI namespace when trying to get the tlli_info.

This patch modifies the gbproxy_check_tlli() function to accept a
tlli_info pointer instead of a numeric TLLI. The tlli_info is already
available when the function is called. Since this a similar approach
has been used by accessing the enable_patching flag directly, this
commit unifies checking by always using this function instead of the
flag outside of gb_proxy_tlli.c.

This fixes the APN patching that doesn't work currently when P-TMSI
patching is enabled.

Sponsored-by: On-Waves ehf
2014-09-08 10:20:16 +02:00
Jacob Erlbeck 82add78f89 gbproxy/test: Check APN patching while P-TMSI patching is enabled
This commit adds a single ACT PDP CTX REQ message to
test_gbproxy_ptmsi_patching() to check whether APN patching works in
this case, too.

Note that this doesn't work currently, the APN patch count is not
incremented.

Sponsored-by: On-Waves ehf
2014-09-08 09:27:41 +02:00
Jacob Erlbeck 25f98e618a gbproxy: Add missing commands to VTY write
Currently the new command acquire-imsi and secondary-sgsn are not
included into the write command's output.

This is fixed by this commit.

Sponsored-by: On-Waves ehf
2014-09-08 09:27:41 +02:00
Jacob Erlbeck c1c57d3a26 gbproxy: Copy uplink messages to SGSN 2
Some messages that are related to the BVC itself must be forwarded to
the secondary SGSN, too.

This patch implements this for BVC-RESET (BVCI != 0) and FLOW-CONTROL-BVC
messages. The resulting acknowledgement messages from the secondary
SGSN are silently dropped. The idea behind this is that the primary
SGSN is responsible for setting up and maintaining the BVC whereas
the secondary SGSN is rather passive and just has to accept it.

Ticket: OW#1258
Sponsored-by: On-Waves ehf
2014-09-08 09:27:41 +02:00
Jacob Erlbeck cabd24b33f gbproxy: Use secondary SGSN if IMSI matches
This patch modifies gbprox_process_bssgp_ul() to send the message to
the secondary SGSN if the IMSI has matched and routing to the
secondary SGSN is enabled. The destination for stored messages is
modified accordingly.

Ticket: OW#1261
Sponsored-by: On-Waves ehf
2014-09-08 09:27:36 +02:00
Jacob Erlbeck f181f9ec2a gbproxy/test: Add test case for secondary SGSN
This patch adds a case to test the establishment (and shutdown) of
connection between 2 MS and 2 SGSN, where the assignment is based
on each IMSI. Since BVC-RESET and FLOW-CONTROL-BVC will have to be
sent to both SGSN, an ACK is simulated for both.

New functions to generate FLOW-CONTROL-BVC(-ACK) messages are
provided.

It modifies dump_peers to add the string "IMSI matches" to a TLLI dump
line if appropriate.

Note that there is no real support to use a secondary SGSN in the
gbproxy yet, but the test code reflects the expected behaviour when
the feature is implemented.

Sponsored-by: On-Waves ehf
2014-09-08 09:12:02 +02:00