Commit Graph

91 Commits

Author SHA1 Message Date
Neels Hofmeyr 5336f57f05 fix mgcp_verify_ci(): off-by-one in max len check
MGCP_CONN_ID_MAXLEN actually includes a terminating nul, so we need to compare
strlen() against MGCP_CONN_ID_MAXLEN-1.

Log the length if it is too long.

Add MDCX_TOO_LONG_CI test to mgcp_test.c, testing a conn id of 33 characters.
Before this patch, the test returns error code 515 meaning "not found", while
now it returns 510 meaning "invalid", showing the off-by-one. Same is
illustrated by the error log ("not found" before, "too long" now), but the
error log is not verified by mgcp_test.c.

Change-Id: I8d6cc96be252bb486e94f343a8c7cae641ff9429
2018-09-03 23:08:08 +02:00
Neels Hofmeyr b861db97ea mgcp_test: fix get_conn_id_from_response() CI length
This function is set on conn ID length of 32 characters. Make it detect a
shorter length also when parsing 'o=-' headers. Before, this failed to
recognize a space as the end of the conn ID, now sees any non-hex char as end.

Related: OS#3507
Change-Id: I762c273bac172acb6d0aae6ea6267603ab654cbf
2018-08-30 14:23:12 +00:00
Neels Hofmeyr 08e07046f9 mgcp_test: fix log of conn_id presence
Flip logic to accurately log whether an 'I:' is included, instead of logging
the opposite.

Note that it isn't possible to log the actual conn ID, because they are random
and differ in every test run, which would collide with the fixed expected
output file mgcp_test.ok.

Change-Id: Idcd731b9daf618b97d8f7e6a776266071cd29e08
2018-08-30 14:23:12 +00:00
Neels Hofmeyr f2388eab71 X-Osmo-IGN: rather parse items by token, not char
Adjust the X-Osmo-IGN parsing to use string tokens instead of parsing single
characters.

Reconsidering the first implementation as a poor choice, rather specify the
format of X-Osmo-IGN as any-length string tokens separated by spaces, which is
more flexible and more future proof.

See also osmo-gsm-manuals If15a88c3b5b40fd1d24ad0f94f3231f678669ab1 which
defines the X-Osmo-IGN format as string tokens, matching this patch.

In mgcp_test, add an unknown X-Osmo-IGN item. Though the output is not checked
by the testsuite.at, running manually shows the error log about the unkown
X-Osmo-IGN item.

Change-Id: Ia6fe5ead4b601931c1bf41b29fc1b237aac37d2c
2018-08-28 19:38:22 +00:00
Neels Hofmeyr e6d8e91b3a add X-Osmo-IGN MGCP header to ignore CallID
The format is

  CRCX ...
  C: ...
  M: ...
  X-Osmo-IGN: C

So far the only ignorable element is C, i.e. the CallID. Any other items may be
added in the future.

(I initially intended to also add '@' to ignore the endpoint name's domain
part, but in the osmo-mgw code base the domain part is verified long before any
additional headers are even parsed, so sparing that refactoring for now.)

The intention is that osmo-bsc will issue "X-Osmo-IGN: C" for all SCCPlite
calls, because we are unable to retrieve the CallID that the MSC sends to
osmo-mgw for the network side of the endpoint.

Testing with a specific SCCPlite MSC, I actually observe that all CallIDs are
1, even for concurrent calls. So, an alternative hacky solution would have been
to always pass CallID == 1 for SCCPlite connections from osmo-bsc.

Related: I257ad574d8060fef19afce9798bd8a5a7f8c99fe (osmo-bsc)
Change-Id: Id7ae275ffde8ea9389270cfe3db087ee8db00b51
2018-08-25 16:47:44 +02:00
Philipp Maier a74c0ea2db mgcp_test: release endpoints after use
The test function test_multilple_codec() in mgcp_test.c creates a
lot of connections, but it never releases them. Just freeing the
cfg object is not enough since the UDP ports stay open and this
may interfere with other tests that also create connections
(port numbers).

- Make sure all endpoints are released when test_multilple_codec()
  is done.

Change-Id: Ic13b4368162149ec36c93f4188fa4c71166e08d5
2018-08-02 12:01:31 +00:00
Philipp Maier 6931f9a7a4 mgcp_network: translate payload type numbers in RTP packets
Since no transcoding is in place osmo-mgw forwards the incoming rtp
packets as they are (there may be minor modifications of the header) from
an ingress connection to an egress connection.

This works without problems as long as both connections use the same
payload type. For IANA defined fixed payload type numbers this is
usually the case, but for dynemic payload type numbers both ends may set
up the same codecs but with different payload type numbers.

When different payload type numbers are set up, and the packet is passed
through without modification, it will have the wrong payload type when
it is sent. The receiving end may then toss the packet since it expects
packets with the payload type it has configured.

The machanism, which is introduced with this patch looks up actual codec
inside the struct data of the ingress connection and then looks for the
matching codec in the struct data of the egress connection. When it
finds the codec there it looks up the payload type of this codec. The
header of the RTP packet is then patched with the correct payoad type.

- Add function mgcp_codec_pt_translate() to look up the payload type
- Add unit-test for function mgcp_codec_pt_translate()
- Add payload type translation to mgcp_network.c

Change-Id: I3a874e59fa07bcc2a67c376cafa197360036f539
Related: OS#2728
Related: OS#3384
2018-07-31 17:18:14 +00:00
Philipp Maier cede2a4b7c stats: replace packet statistic counters with libosmocore rate counters
In struct mgcp_rtp_end one finds unsigned int counters. Those should
be replaced with libosmocore rate counters

- replace packets_rx, octets_rx, packets_tx, octets_tx and
  dropped_packets with libosmocore rate counters.

Change-Id: I47c5c9006df5044e59ddebb895e62adb849d72d5
Related: OS#2517
2018-07-05 15:55:19 +02:00
Philipp Maier bc0346e080 mgw: clean up codec negotiation (sdp)
The codec negotiation via SDP is currently in a neglected state. Also
osmo-mgw does some kind of codec decision wile the SDP is parsed, the
result is information for one codec, even when there are multiple codecs
negotiated. This is problematic because we loose all information about
alternate codecs while we parse. This should be untangled and the
information should be presevered. Also we are not really capable
picking a default. Wehen we do not supply any codec information (not
even LCO), then we should pick a sane default codec.

- separate the codec decision from the sdp parser and concentrate
  codec related code in a separate c file
- add support for multiple codecs in one SDP negotiation
- do not initalize "magic" codec defaults during conn allocation
- do not allow invalid payload types, especially not 255. When
  someone tries to select an invalid payload type, do not fail
  hard, just pick a sane default.
- handle the codec decision in protocol.c, pick a sane default
  codec when no (valid) codec has been negotiated (no LCO, no SDP)

Change-Id: If730d022ba6bdb217ad4e20b3fbbd1114dbb4b8f
Closes: OS#2658
Related: OS#3114
Related: OS#2728
2018-06-23 11:39:44 +00:00
Philipp Maier 3d7b58d77a protocol: reject illegal lco options
At the moment osmo-mgw will accept multiple lco options. (e.g.
p:10, a:PCMU, p:10) If LCO appear multiple times, than the first
appearance of will be parsed and used, all following appearances
will be ignored. However, having multiple appearances of LCO is
illegal and affected requests should be rejected. Also osmo-mgw
should reject illegal formatted LCO strings

- make sure that multiple appearances of LCOs will be rejected
- make sure that illegal formated LCOs are rejected
- add testcases with garbeled LCO and valid LCO examples

Change-Id: Iae2fddfa5f2bcfc952f8ab217b3056694e5f7812
Closes: OS#3119
2018-06-06 16:41:04 +02:00
Philipp Maier dbd70c7b68 sdp: remove unused alt_codec field from struct mgcp_rtp_end
The alt_codec field is not used anywhere in the code

- remove unused alt_codec field

Change-Id: I5ff2899e3e61f33eb86f284b50ad8a94a949ed16
Related: OS#3114
2018-05-25 11:07:31 +02:00
Philipp Maier 9e1d164469 stats: use libosmocore rate counter for in/out_stream.err_ts_counter
The two counters: in_stream.err_ts_counter and out_stream.err_ts_counter
are still handcoded. To make them better accessible they should
 be replaced with libosmocore rate counters.

- replace state.in_stream.err_ts_counter with libosmocore rate counter
- replace state.out_stream.err_ts_counter with libosmocore rate counter

Change-Id: I9fbd65bf2f4d1e015a05996db4c1f7ff20be2c95
Related: OS#2517
2018-05-16 11:32:36 +02:00
Alexander Couzens 8d064dfd24 Revert "stats: use libosmocore rate counter for in/out_stream.err_ts_counter"
This reverts commit 7181cc1f02.
The tests are broken on i686, arm (non 64bit systems).

Change-Id: I15f3c78f8410d709733ed5692ba94ba17559d7e1
2018-04-21 20:26:17 +02:00
Philipp Maier 7181cc1f02 stats: use libosmocore rate counter for in/out_stream.err_ts_counter
The two counters: in_stream.err_ts_counter and out_stream.err_ts_counter
are still handcoded. To make them better accessible they should
be replaced with libosmocore rate counters.

- replace state.in_stream.err_ts_counter with libosmocore rate counter
- replace state.out_stream.err_ts_counter with libosmocore rate counter

Change-Id: I67aa7a8602f60366ef3ba2c5b1319b1b85719f64
Related: OS#2517
2018-04-17 16:43:59 +02:00
Neels Hofmeyr 60f8e31a2f use osmo_init_logging2() with proper talloc ctx
Change-Id: I3e2a9aef5242efdf11a64536f79099a6e9cec53f
2018-04-01 16:05:05 +02:00
Pau Espin 2da99a2946 mgcp_stat: Don't print osmux stats if it is off
Otherwise we get Osmux stats during a session using RTP, which is
confusing.

Change-Id: I6fcd680a073fbf8769488ffa2b2b32098c87edf4
2018-02-20 13:12:02 +01:00
Philipp Maier 37d11c80da cosmetic: rename mgcp_ep.c/h to mgcp_endp.c/h
The short term of endpoint has always been "endp" througout the whole
project and not "ep".

- rename mcgp_ep.c to mgcp_endp.c

- rename mgcp_ep.h to mgcp_endp.h

Change-Id: Id52047bb2d0407655ac272c858ed3412b8ae9e6d
2018-02-05 10:32:42 +01:00
Philipp Maier 1355d7e4f7 cosmetic: rename mgcp_release_endp to mgcp_endp_release
In order to allow clean prefixes for future endpoint related
functions the "rlease" should be moved to the end of the
function name.

- rename mgcp_release_endp to mgcp_endp_release

Change-Id: I22e938e702f57ad76d38c9f4a1370b110ac1ba11
2018-02-05 10:32:42 +01:00
Philipp Maier c3cfae2cf8 protocol: fix missing carriage return
Some of the line breaks lack the \r character, which leads to an
inconsistancy. While our software and even wireshark does ignore
the problem, other third party implementations might reject those
messages.

- Add the missing \r characters to make the message format
  consistant.

Change-Id: I0cd80afae65accd3b4ddc5d82e5d30385879141c
2018-01-26 00:32:22 +00:00
Philipp Maier 55295f7b07 mgcp: permit wildcarded endpoint assignment (CRCX)
The mgcp protocol in general allows wildcarded endpoints on CRCX.
osmo-mgw does not support this feature yet.

- when the endpoint name contains a wildcard character, search
  a free endpoint automatically

- return the resulting endpoint name in the parameter section of
  the mgcp response

- add parsing support for the returned endpoint names

- Be more concious about the parameters that are returned with
  each response. Do not unnecessarily attach known parameters.
  Return the connection ID only on CRCX commands. Only return
  the endpoint ID on CRCX commands that are wildcarded.

Change-Id: Iebc95043569191b6f5fbc8fe266b13fcfcab2e48
related: OS#2631
2018-01-26 00:31:22 +00:00
Philipp Maier 12943ea0c1 mgcp: make domain name configurable
At the moment the MGW has a fixed domain name string that is not even
checked properly.

- Make domain name configurable, use the current "mgw" string as
  defualt to maintain compatibility

- Check the domain name with each request. If the endpoint contains
  an unexpected domain name, the request must be rejected.

Change-Id: Ia91ac428ba83ac1f9b52a0ec8dbf00ef7876da9e
2018-01-19 10:15:47 +01:00
Harald Welte abbb6b9088 centralize handling of common errors like "endpoint not found"
Previously we
* did not distinguish between the cause of errors in mgcp_header_parse
* common errors were not handled in mgcp_handle_message() but in
  individual per-verb functions

Let's centralize the handling of generating error responses and remove
that burden from the individual per-verb handler functions.

Change-Id: I463b27306e10ae3b021583ed102977e7299e5e66
2017-12-28 14:00:37 +01:00
Harald Welte a0ac30faa5 mgcp_rtp_end: Group statistics members into 'stats' sub-struct
Change-Id: I4e0ecdcd9a75fe08abc55b730780c01617f3d4af
2017-12-25 10:10:29 +01:00
Harald Welte 49e3d5a9c9 mgcp_rtp_state: grup 'stats' members into sub-structure
Change-Id: I92a1bead01c6b85bf237b6edf64a1b76b9e97c78
2017-12-25 10:10:29 +01:00
Philipp Maier a330b864e5 mgcp_test: fix possible double free
Change-Id: I2d044382c0bb66e190400e3397449c3f2387359a
2017-12-04 17:34:11 +01:00
Philipp Maier 7df419b434 mgcp_test: add returncode check
The returncode of get_conn_id_from_response() is unchecked, which
is intentional since some of the test messages will intentionally cause
this function to fail (the response does not inclde a connection
identifier). This means it makes no sense to assert this function
to a fixed value.

In order to spot regressions better print a log message depending
on the return code.

Change-Id: I9bce9ca39b7751b557374b7ab57c6c9005bcdb7d
Fixes: Coverity CID#180534
2017-12-04 17:34:11 +01:00
Philipp Maier 7cedfd753b mgcp_test: fix nullpointer dereference
Change-Id: Ic2ee79eaaca2fada673baf6ff4c226aa16c26269
Fixes: Coverity CID#180536
2017-12-04 17:33:59 +01:00
Philipp Maier 23b8e29835 mgcp_test: fix wrong strcmp() parameters
The CRCX string parameter lacks the quotes and the result of
the function call is not checked against zero. Also the
return code of get_conn_id_from_response() is not asserted.

Fixes: Coverity CID#180534

Change-Id: If4f3ed2c3572da196160569a9705b7a302b700a9
2017-12-04 16:51:40 +01:00
Philipp Maier ffd75e420c libosmo-mgcp: Connection Identifiers are allocated by MGW, not CA
The MGCP connection identifier is allocated by the MGW while processing
the CRCX, see RFC3435 2.1.3.2:. Including/Accepting a connection
identifier in CRCX is "forbidden" as per RFC3435 Section 3.2.2.

So the MGW side must *reject* a CRCX message with 'I' parameter, and
allocate a connection identifier which is subsequently returned in the
response.

Closes: OS#2648
Change-Id: Iab6a6038e7610c62f34e642cd49c93d11151252c
2017-12-01 11:58:24 +00:00
Philipp Maier 01d24a3281 MGCP: Connection Identifiers are hex strings
The MGCP spec in RFC3435 is quite clear: Connection Identifiers are
hexadecimal strings of up to 32 characters. We should not print and
parse them as integers on either client or server.

Change the internal uint32_t representation of connection identifiers
to a string representation in the client and also in the server.

Closes: OS#2649
Change-Id: I0531a1b670d00cec50078423a2868207135b2436
2017-12-01 11:58:23 +00:00
Philipp Maier fcd0655176 vty: do not change number_endpoints at runtime
The variable number_endpoints is used as a length indicator
for the array that contains the trunk endpoints at all times.
When osmo-mgw is startet up, the variable is set and osmo-mgw
will allocate the memory for the endpoints. However, it is
still possible to manipulate the variable via the telnet
interface. When the value is increased osmo-mgw might start
using unallocated memory at some point.

Store subsequent changes of number_enspoints in a separate
variable in order to write them to the config file. The
changes will then take effect after a restart.

Closes: OS#2632
Change-Id: I3994af016fb96427263edbba05f560743f85fdd4
2017-11-27 14:38:29 +00:00
Neels Hofmeyr 465446b4b4 mgcp_test: sanitize: free msgb_ctx
Ensure that all msgb were cleaned up, then free the overall msgb_ctx, in order
to not leave any memory leaks the sanitizer build complains about.

Change-Id: I53373023a6c3f490d6d6cb1c283db5dfb915882c
2017-11-22 02:59:03 +01:00
Neels Hofmeyr b597b4fc9d mgcp_test: test_no_cycle: sanitize: free endp
Release endpoint to avoid sanitizer errors.

Change-Id: I78d16ffc435c0f967fe99c6e38dde829b6fa0dc9
2017-11-22 02:58:27 +01:00
Neels Hofmeyr d20910c655 mgcp_test: test_packet_error_detection: sanitize: free all conns
Don't leave any memory leaks a sanitizer build will complain about.

Change-Id: I6823653d5efcebaed40471123d21a9321cf633fd
2017-11-18 21:27:55 +01:00
Philipp Maier 3d9b656a1c mgcp_test: do not send rtp packets
The sendto() override in mgcp_test sends rtp packets out. This
might be a problem for some test hosts. e.g. on OBS, sending packets
fails with an error message, which exits sendto() early and hence fails
to send the expected amount of "Dummy Packets". Interestingly enough
calling the real sendto is not necessary to run the test at all.

Remove the execution of the real_sendto and just return len.

Related: OS#2561
Change-Id: Ia8fa0770f9bc75725cc6b0cd445e753f7e029ca5
2017-10-13 18:41:52 +00:00
Neels Hofmeyr 020e89bce9 mgcp_test: tweak test failure output
Change-Id: Ibfc80f06b2811cc32fe38518b11efd6764b347ee
2017-10-11 02:02:22 +02:00
Neels Hofmeyr 6779354245 drop code dup between libosmo-mgcp-client and libosmo-mgcp
Remove mgcp_common.c and replace with mgcp_common.h.

Move mgcp_common.h from mgcp_client/ to mgcp/;
Place a compile-time copy of it back in mgcp_client/.

Add builddir/include to compiler -I paths to find generated header.

Rationale:
- Keep separate copies of the file for each of the library to not require
  debian dependencies between the two libraries.
- Avoid code dup by copying during 'make' (think: a generated header, BUILT_SOURCE).
- The copy does not have implications for linking (like mgcp_common.c did) nor
  is it a source for build confusion or fallout in other projects, because it
  does not reach across several git source trees (like gsm_data_shared.h did).

mgcp_connection_mode_strs are not actually used in libosmo-mgcp, so drop them.
(It would make semantic sense to have then in mgcp, but we can add it when it
is needed. A similar value string array remains in libosmo-mgcp-client.)

Change-Id: I7a5d3b9a2eb90be7e34b95efa529429f2e6c3ed8
2017-10-05 19:32:58 +02:00
Philipp Maier 87bd9be0b0 Initially implement the new osmo-mgw and libosmo-mgcp
Leave the old osmo-bsc_mgcp and libosmo-legacy-mgcp as it is; on a copy thereof
(added by a previous commit), apply changes to initially implement the new
osmo-mgw.

Adjust build system and debian packaging to accomodate the new libosmo-mgcp and
osmo-mgw.

The main differences:

*) use a list to manage rtp connections.

Aggregate all rtp related information inside a single struct.

Use a linked list to manage the both connections (net and bts).
The idea behind using a list is that we might support conference
calls at some later point.

Store the linked list in struct mgcp_endpoint, have a private linked
list for each endpoint. The list contains connection items which are
implemented in struct mgcp_conn. A connection is allocated and freed
using the functions in mgcp_conn.c. A connection is allocated on the
reception of a CRCX command and freed with the reception of a DLCX
command.

*) remove external transcoder feature

Fortunatelly the external transcoder feature is not needed
anymore. This patch removes the related code.

*) vty: get rid of CONN_BTS and CONN_NET

Since the new connection model does not make a difference
between BTS and NET connections the VTY should not use
the fixed CONN_BTS and CONN_NET constants.

- Handle the conns list inside the endpoint directly
- introduce function to dump basic rtp connection info
- introduce human readable names for connections

Parts of the code adjusted to use generalized connections instead of explicit
BTS/NET ones:

- teach mgcp_send_dummy() to send dummy packets to any RTP connection
- network: generalize mgcp_bind_net/bts_rtp_port()
- network: generalize mgcp_send()
- tap: generalize call tapping feature
- stat: generalize statistics
- Replace rtp_data_net() and rtp_data_bts() with generalized rtp_data_rx()

*) mgcp_protocol.c fixes:

- check ci string before it is converted:
  In case of missing ci, a nullpointer is delivered to strtoul().
  Add a function that takes ci, checks it and converts it to an
  uint32_t. Use the return code to react on missing ci.
- output error message on missing CI.
- when parsing the mode, print log message when mode is missing.
- use mode_orig when mode is missing.
- fix ptime formatstring to use %u rather than %d.
- cosmetic: log when connection is deleted on DLCX.
- change loglevels of CRCX, MDCX, DLCX events from DEBUG to NOTICE.

*) mgcp_test

- apply rename of strline_r() to mgcp_strline().
- MGCP command macros:
  - Add 'I: 1' parameters.
  - Use proper port numbers:
    from m=audio 0 RTP/AVP 126
    to   m=audio 16002 RTP/AVP 128
  - Change ptime to 'a=ptime:40' because this is what the MGW currently
    returns.  CRCX generally feed a ptime:40 and this is expected to be
    returned.
- struct mgcp_test: Use only one ptype, there are no explicit BTS and NET
  endpoints anymore.
  Hence remove one column from tests[].
- test_messages():
  - Enable: remove '#if 0'
  - Remove concept of BTS and NET endpoints: test only one conn, as they are
    now interchangeable anyway.
  - remove endpoint init, now done internally.
  - add false asserts in error cases.
- test_retransmission():
  - remove endpoint init, now done internally.
  - add false asserts in error cases.
- test_packet_error_detection():
  - Remove concept of BTS and NET endpoints: test only one conn, as they are
    now interchangeable anyway. Use arbitrary conn ids (e.g. 4711).
  - remove endpoint init, now done internally.
  - add false assert in error case.
  - Assert that a conn really vanishes on DLCX, previously the conn would
    remain and just be unused, now it is actually discarded.
- test_no_cycle()
  - Remove concept of BTS and NET endpoints: test only one conn, as they are
    now interchangeable anyway. Use arbitrary conn ids (e.g. 4711).
- test_no_name()
  - Enable: remove '#if 0'.
  - remove endpoint init, now done internally.
  - add false assert in error case.
- mgcp_test.ok: adjust expected results to status quo:
  - We now see two dummy packets instead of one, now sent to both sides because
    we don't know of BTS or NET side. (maybe drop dummy packets later...)
  - packet duration, conn mode: now sane defaults show instead of unset.
- various whitespace and formatting changes from lindent.

Change-Id: Ie008599136c7ed8a0dfbb0cf803188975a499fc5
2017-10-05 01:40:43 +00:00
Neels Hofmeyr f83ec56212 create libosmo-mgcp and osmo-mgw by copying legacy code
This a cosmetic commit, copying libosmo-legacy-mgcp to libosmo-mgcp and
osmo-bsc_mgcp to osmo-mgw 1:1 at first, to provide a basis for next patches
that highlight the changes from legacy to new code.

Until osmo-msc and osmo-bsc are adjusted to operate with the new code, we will
keep the legacy code alongside the new code. The legacy code might be dropped
later.

Change-Id: Idf54481754a1765bdb2d0d7033bc0d7dc2018024
2017-10-05 01:40:43 +00:00
Neels Hofmeyr e9920f24b1 split off osmo-mgw: remove files, apply build, rename
Add vty and logging previously used from libcommon

Rename libmgcp to libosmo-legacy-mgcp and install.

Use DLMGCP, not DMGCP.

Slim down the public mgcpgw_client API, move all elements not actually used by
current callers to private headers / static c.

Depends: libosmocore I09c587e2d59472cbde852d467d457254746d9e67
Change-Id: I71a0a16ebaaef881c34235849601fc40aa12cfd7
2017-08-30 15:04:52 +02:00
Neels Hofmeyr 85929a7be7 move openbsc/* to repos root
This is the first step in creating this repository from the legacy openbsc.git.

Like all other Osmocom repositories, keep the autoconf and automake files in
the repository root. openbsc.git has been the sole exception, which ends now.

Change-Id: I9c6f2a448d9cb1cc088cf1cf6918b69d7e69b4e7
2017-08-27 17:44:55 +02:00