Commit Graph

4656 Commits

Author SHA1 Message Date
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
Jacob Erlbeck f4d60c8788 gbproxy: Support a secondary SGSN
This patch refactors SGSN NSEI handling to support a secondary SGSN.

It adds the following VTY commands:
  - secondary-sgsn nsei <0-65534>
  - no secondary-sgsn

Sending messages to the secondary SGSN is not yet implemented, but
received messages from such a SGSN would be forwarded to the BSS
peers.

Sponsored-by: On-Waves ehf
2014-09-08 09:11:59 +02:00
Jacob Erlbeck 5930064700 gbproxy: Add missing gbprox_process_bssgp_ul() return check
This should have been part of the 'Implement IMSI acquisition'
commit, where a similar change has been made for BSS originated PTP
messages.

Sponsored-by: On-Waves ehf
2014-09-08 09:04:01 +02:00
Jacob Erlbeck 1a8dbc4fc9 gbproxy: Fix warnings
This patch fixes the remaining 'unused' warnings.

Sponsored-by: On-Waves ehf
2014-09-07 10:46:10 +02:00
Holger Hans Peter Freyther 56cb729907 bsc: Add a "IPA PING" to the SCCP CR messages
We want to reduce the background traffic and might set the ping
interval to be in the range of minutes. But this means that if
the TCP connection is frozen several "SCCP CR CM Service Requests"
will be stuck in the send queue without ever being answered. I
could have used the logic of not receiving the "SCCP CC" to close
the connection but instead I am introducing an overload to schedule
the ping as part of the normal SCCP connection establishment.

The VTY write case has been manually verified, I have also looked
at a single trace to see that the SCCP CR and the IPA PING is
transfered in the same ethernet frame.
2014-09-05 12:25:32 +02:00
Holger Hans Peter Freyther 0169971a59 mgcp: Re-load the state after the transcoding change
Jacob ran the tests with ASAN and noticed that the state is
dead. This is on purpose as we have forced a change in the
transcoding. Re-load the state and verify that it has not
changed in the other cases.
2014-09-05 12:25:32 +02:00
Holger Hans Peter Freyther 0454e32861 mgcp: Use l16 in the test
G729 might not be available, so execute the test with codecs that
are always available.
2014-09-02 12:16:22 +02:00
Jacob Erlbeck 5f4ef321a6 gbproxy: Implement IMSI acquisition
To modify or route messages based on the IMSI the latter must be known
when the action shall take place.

This patch modifies the gbproxy to optionally retain and enqueue
messages from the MS while initiating an identification procedure.
Further message processing of the LLC PTP link towards the SGSN will
be done, when the identity of the MS has been acquired.

Note that the N(U) of the LLC GMM SAPI are not adjusted, so it is
possible that adjacent messages of a single LLC link arriving either
at the BSS or the SGSN have the same N(U) and might get discarded,
leading to retransmissions and additional delay.

Note also that retransmissions and packet loss are not yet handled
explicitely. If for instance the generated IDENT REQ gets lost, the
gbproxy will not act on its own. In this case, the MS will time out
and eventually resend the Attach Request on which the gbproxy will
act exactly like before (thus having two Attach Req messages in its
queue, which will both be sent after the Ident Resp arrives).

This has been tested successfully with an E71, needing one
retransmission by the SGSN due to an N(U) collision.

Ticket: OW#1261
Sponsored-by: On-Waves ehf
2014-09-02 09:53:47 +02:00
Jacob Erlbeck 28fe98891f gbproxy/test: Add a test for IMSI acquisition
This patch copies test_gbproxy_ptmsi_patching to
test_gbproxy_imsi_acquisition as a base for a later test for IMSI
acquisition (which is not yet implemented). The idea behind this is
to make the different behaviour visible in the ok file without
compromising the P-TMSI test.

Sponsored-by: On-Waves ehf
2014-09-02 09:53:42 +02:00
Jacob Erlbeck 4b663ac34a gbproxy: Create STATUS message with original PDU
Currently when patching is enabled and an error happens when
receiving a message from the SGSN, the patched message is sent back
with the PDU_IN_ERROR IE.

This patch modifies gbprox_rx_sig_from_sgsn() to copy the message
before it is patched, so that the original message can be used with
the STATUS message. gbprox_rx_ptp_from_sgsn() does all checks before
the message is patched, so copying is not necessary.

Since gbprox_rx_sig_from_sgsn() is not called for BSSGP UNITDATA
messages and the msgb is already been copied in the gbprox_relay2peer
function, the relative performance impact is expected to be low.

Note that the PDU IE of STATUS messages received from an MS and
forwarded to the SGSN will not be patched. STATUS messages from the
SGSN are only logged and not forwarded to the MS.

Sponsored-by: On-Waves ehf
2014-09-02 09:53:38 +02:00
Jacob Erlbeck 299389a99f gbproxy/test: Test patching BSSGP SUSPEND/LLC-DISCARDED
Currently messages like these with a TLLI IE (BSSGP) are not
tested (properly) with TLLI patching.

This patch extends the send_bssgp_suspend* functions to accept a
TLLI as argument and adds the send_bssgp_llc_discarded function.
These are then used in test_gbproxy_ptmsi_patching() with a valid
TLLI.

Note that the TLLI IE patching doesn't work currently.

Sponsored-by: On-Waves ehf
2014-09-02 09:53:34 +02:00
Jacob Erlbeck 46f1d6fddb gbproxy: Move PTP message handling into separate functions
This patch adds gbprox_rx_data_from_sgsn() and
gbprox_rx_ptp_from_bss() which contain the PTP message processing
of gbprox_rcvmsg(). The calls to gbprox_process_bssgp_ul() are moved
from gbprox_relay2sgsn() to gbprox_rx_ptp_from_bss() and
gbprox_rx_sig_from_bss().

The goal is, to do all patching (and calls to gbprox_process_bssgp_*)
from within the gbprox_rx_* functions. Doing the patching from within
gbprox_relay2sgsn has the drawback, that the patching code cannot
call gbprox_relay2sgsn() which is needed if a single message shall
trigger a sequence of messages.

Sponsored-by: On-Waves ehf
2014-09-02 09:53:30 +02:00
Jacob Erlbeck 48bb3a37da gbproxy: Remove nonnull attributes
The compiler also uses this attribute for code elimination. If the
nonnull attribute has been given erroneously for an parameter, that
is later been checked against NULL, this check is removed silently
by the gcc if optimization is enabled. This can lead to hard-to-find
segmentation violation faults.

To be on the safe side, this patch removes all uses of the nonnull
attribute in openbsc.

Compiler:
  - gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1): no warning, segfault
  - clang 3.4 (3.4-1ubuntu3): no warning, no segfault, asm ok

Example:
  /* foo.c */
  int f(int* p) __attribute((nonnull));
  int f(int *p) {
      if (!p)
          return 0;

      return *p;
  }

  /* main.c */
  int f(int* p) __attribute((nonnull));
  int g () {
      return f(arg);
  }

  int main() {
      return g(NULL);
  }

When these files are compiled into an executable, no warnungs are
issued but it will fail with a segfault when -O2 is used (unless LTO
is active).

Compiler output (gcc -O2):
  int f(int *p) {
    0:  8b 44 24 04             mov    0x4(%esp),%eax
    4:  8b 00                   mov    (%eax),%eax
    6:  c3                      ret
  }

Sponsored-by: On-Waves ehf
2014-09-02 09:53:18 +02:00
Holger Hans Peter Freyther e3283ec3eb Merge branch 'zecke/features/dynamic-codec-switch' 2014-09-02 09:28:44 +02:00
Holger Hans Peter Freyther 4680121fe6 mgcp: Deal with receiving another payload type
In case we get offered G729 and G711 we might have selected
G729 as the audio codec. The first packet we receive might be
G711 though. In that case we will need to change. But only if
we have a matching alternate codec payload_type. E.g. in the
case of comfort noise we will receive the PT=11 and we don't
want to change.
2014-09-02 09:27:45 +02:00
Holger Hans Peter Freyther e46bc2714d mgcp: Store one more codec/payload type if it is present
In case of some RTP proxy from time to time we are offered both
G729 and G711 but only one of them will work. I intend to adjust
the codec at runtime in case we receive the wrong codec.
2014-09-02 09:22:19 +02:00
Holger Hans Peter Freyther fa80d07de0 mgcp: Group codec reset and put it to a separate method. 2014-09-02 08:25:49 +02:00
Holger Hans Peter Freyther cac2438b0c mgcp: Move the "codec" params to a struct
We might be offered multiple codecs by the remote and need to
switch between them once we receive data. Do this by moving it
to a struct so we can separate between proposed and current
codec. In SDP we can have multiple codecs but a global ptime.
The current code doesn't separate that clearly instead we write
it to the main codec.
2014-09-02 08:25:49 +02:00
Holger Hans Peter Freyther 3713f78ac2 mgcp: Use the rtp_hdr structure and extract ts/seq from there
Use the rtp_hdr structure. The basic alignment issue remains
and I need to merge/cherry-pick Jacob's getters for the ts,
sequence number and other attributes.
2014-09-02 08:25:49 +02:00
Pablo Neira Ayuso c20a661272 osmux: osmux batch-factor can't be higher than 8
The osmux header uses a counter of 3 bits, so you can put up to
8 message in it.
2014-09-01 20:07:27 +02:00
Pablo Neira Ayuso fcec6d85d0 osmux: save specific osmux configuration options if osmux is enabled
Just like other options do, to avoid polluting the configuration file
with unused options if osmux is disabled.
2014-09-01 20:06:43 +02:00
Pablo Neira Ayuso 9224010859 configure: fix unrecognized option --enable-external-tests
./configure --help indicates:

  --enable-external-tests Include the VTY/CTRL tests in make check
                          [default=no]
but

./configure ... --enable-external-tests
configure: WARNING: unrecognized options: --enable-external-tests

the name of the option seems to be --enable-ext-tests.
2014-09-01 18:35:15 +02:00
Pablo Neira Ayuso 08726e2837 osmux: initialize osmux_batch_size in mgcp config
The library allows to indicate zero as batch size if you want to use
the default size, however openbsc saves 'osmux batch-size 0' which is
not good as input.

Use OSMUX_BATCH_DEFAULT_MAX to explicitly initialize the batch size
from mgcp_parse_config().
2014-08-30 07:59:41 +02:00
Pablo Neira Ayuso 03ab79abac osmux: add 'osmux batch-size NUM' option to mgcp vty
This allows you to specify the osmux batch frame size. If zero, the
library uses the default value.
2014-08-29 12:30:38 +02:00
Pablo Neira Ayuso 308d5f8912 osmux: set default port from mgcp_parse_config() 2014-08-29 12:21:58 +02:00
Holger Hans Peter Freyther 73ec6980d5 nat: Introduce a config free for the test and fix valgrind issues
The talloc_free on the nat lead to the freeing of the bsc_config
which lead to freeing of the rate_ctr_group. The rate_ctr_group
remained in a global list and the next creation of a bsc_config
would access dead memory. Fix it.

The free routine is only meant to be used by the test, for the
real nat we would need to make sure that all connections and
other state that refers to the cfg is removed/closed first.

Fix various memleaks in the test while we are at it. There are
still some to fix.

==7195== Invalid write of size 4
==7195==    at 0x4043171: rate_ctr_group_alloc (linuxlist.h:65)
==7195==    by 0x804D893: bsc_config_alloc (bsc_nat_utils.c:174)
==7195==    by 0x804B5D2: main (bsc_nat_test.c:954)
==7195==  Address 0x4311cbc is 52 bytes inside a block of size 208 free'd
==7195==    at 0x4029D28: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==7195==    by 0x4048D98: _talloc_free (talloc.c:609)
==7195==    by 0x4052806: talloc_free (talloc.c:578)
==7195==    by 0x804B58A: main (bsc_nat_test.c:940)
2014-08-29 11:42:34 +02:00
Holger Hans Peter Freyther dc16bdd369 nat: Remove the entry from the list before we destroy it 2014-08-29 11:42:26 +02:00
Holger Hans Peter Freyther cd48525ecb nat: Fix compiler warning about unknown prototype
bsc_nat_ctrl.c: In function ‘set_net_cfg_cmd’:
bsc_nat_ctrl.c:360:3: warning: implicit declaration of function ‘bsc_replace_string’ [-Wimplicit-function-declaration]
   bsc_replace_string(bsc_cfg, &bsc_cfg->acc_lst_name, cmd->value);
   ^
2014-08-29 11:42:26 +02:00
Holger Hans Peter Freyther fcc30a3df7 gprs: Document the stale option in delete-gbproxy-tlli 2014-08-29 10:51:44 +02:00
Pablo Neira Ayuso dfa91df289 tests: bsc-nat: fix bsc_mgcp_rewrite() with osmux
Pass -1 to indicate no osmux, before ("b769f3c osmux: add osmux
circuit ID management and resolve NAT problems"), 0 was indicating
no osmux.
2014-08-29 09:14:37 +02:00
Jacob Erlbeck ecbd56c625 gbproxy: Fix issues found by Coverity
gbproxy_patch_bssgp: Move a check for tlli_info in front of the first
conditional that depends on it, and return immediately if it is NULL.

gbproxy_register_tlli: Initialize tlli_already_known to 0.

Fixes: Coverity CID 1232691
Fixes: Coverity CID 1232692
Sponsored-by: On-Waves ehf
2014-08-29 08:50:40 +02:00
Pablo Neira Ayuso 3ba3cf85e1 osmux: fix unchecked return value in mgcp_parse_osmux_cid()
** CID 1232804:  Unchecked return value  (CHECKED_RETURN)
/src/libmgcp/mgcp_protocol.c: 888 in mgcp_parse_osmux_cid()
2014-08-29 08:46:54 +02:00
Pablo Neira Ayuso 4ef66b1c5f osmux: fix leak in osmux_deliver()
The callback is responsible for releasing the batch message that
libosmo-netif builds.
2014-08-28 20:14:12 +02:00