Commit Graph

87 Commits

Author SHA1 Message Date
Oliver Smith 0dbaaadc06 mgcp_client: mgcp_msg_gen: add more error logs
While adding CSD, this failed for me in add_lco without a descriptive
log message, so add more error messages.

Related: OS#4393
Change-Id: I4873a2db95525aab3e13046b645dd8f90e951466
2023-02-27 08:30:08 +00:00
Oliver Smith 26d6b2b5ce mgcp_client: add new clearmode codec
Set 120 as payload type, as specified in 3GPP TS 48.103 table 5.4.2.2.1.

Related: OS#4395
Related: https://www.rfc-editor.org/rfc/rfc4040#section-5
Change-Id: I55f9fe241a405935dbedc3947b0a4f4986acd5cb
2023-01-24 18:18:11 +01:00
Pau Espin 8e74c63e15 mgcp-client: Use random free local port by default
Deprecate mgcp_client_connect2() and all the related messy system where
configured port is incremented until a free port is found.
Let's simply use local_port=0 by default and let the kernel take care of
doing all that.
The mgcp_client_connect2() is actually not being used anywhere outside
of libosmo-mgcp-client, so it's not a real problem deprecating it. We
could poitentially remove it too.

This helps in fixing a regression in recent refactoring commit
f48cd95bbc, which unified calls to
mgcp_client_connect() and in the process dropped the code path which was
setting the retry_n_ports=99.
As a result, since all libosmo-mgcp-client instances set local_port=2727
and addr=NULL by default, using MGW pooling or having several osmo-bsc
or osmo-msc processes would make creating the socket fail.

Change-Id: I5683bcf3b2c4e8058338433f2cd1b143753f6512
2022-10-17 19:22:41 +02:00
Pau Espin c7c8e649f1 osmux: Erase references to bsc-nat
Change-Id: I21ab7134de577278175132fc78431a249de76731
2022-10-06 18:24:24 +02:00
Pau Espin 147184eb06 mgcp-client: Remove impossible code path
read(4096 - 128) cannot return > 4096 - 128.

Change-Id: I352c3b28c8de6482277cb84cd0f51893494dc929
2022-06-29 18:45:02 +02:00
Philipp Maier 1de5ed6f97 mgcp_client: add new codec IUFP as VND.3GPP.IUFP
3GPP TS 25.414 5.1.3.3.1.6 specifies that IuUP can use RTP as transport.
The payload type is specified from 96-127, which shall be ignored on the
receiving end anyway.

The payload type number we use shall be 96 by default.

Change-Id: Ifd1210a897743396899f34457c96e6fd2109c6b3
Related: SYS#5152
2022-01-04 15:50:39 +01:00
Philipp Maier df9192efee mgcp_client: add MGW name as logging context
Usually only one MGCP client per application is present. Then the log
lines from mgcp_client.c will be distinguishable without additional
information. When the application is using a pool of MGWs, then the
various MGCP Client instances become hard to distinguish.

- Add a possibility to set a description (name) for each MGW pool
  member. When no description is set, use the domain name.

- Output the pool member name on each log line in mgcp_client.c
  and mgcp_client_pool.c

Change-Id: I53ff5445c8e5faffa4ef908ffb1fdb1f47ea2904
Related: SYS#5091
2021-09-14 07:01:04 +00:00
Philipp Maier fa495d669f mgcp_client: fix typo in doxygen comment
Change-Id: I4431502ebbaa980f2abfdb98acba0f55ca658292
2021-09-02 10:09:28 +02:00
Philipp Maier 3f4a4cb49c libosmo-mgcp-client: extend the mgcp_client for MGW pooling
At the moment the MGCP Client only supports one MGW per application.
Depending on the requirements of the application one MGW might not offer
the performance needed. Lets add support for an MGCP Client pool that is
backward compatible to existing applications.

Change-Id: Icaaba0e470e916eefddfee750b83f5f65291a6b0
Related: SYS#5091
2021-08-16 16:22:31 +02:00
Philipp Maier 3d2b76fd95 mgcp_client: refactor function init_socket
The function init_socket has an arbitrary retry count when opening the
socket. After each retry the local port is incremented by one. The
intention behind this is to find a useable local port in case the
configured port is used by another process.

The maximum number of retrys is hardcoded. The upcomming MGW pooling
patch requires to set the maximum retry count.

Change-Id: Ifd65511daa92fbe610f52da1c4c3b6a7c761d890
Related: SYS#5091
2021-08-16 16:22:31 +02:00
Philipp Maier 276a414aa3 mgcp_client: do not print (null) when address is ANY
When the address is set to ANY, the address string is NULL. The log then
prints "(null)" where the address normaly would be. This looks odd, lets
print "(any)" instead.

Change-Id: I2ea138827ee5b9f40d352bf594364ee930520609
2021-08-16 16:22:31 +02:00
Philipp Maier 3f2c15f275 mgcp_client: allow to reset endpoints on startup
Depending on the usecase of osmo_mpcg_client it may be helpful to send a
DLCX to certain endpoints. Usually this would be a wildcarded endpoint
that resets the entire trunk to drop lingering RTP flows which may still
present after a restart/crash, but it might be also a group of specific
endpoints. The user may specify an arbitrary amount of endpoints where
the mgcp client will send a DLCX to. It does not matter if the endpoints
are wildcarded or not.

Change-Id: I47e7ff858d5067b46d52329be5f362ff61c0dff8
Related: SYS#5535
2021-08-16 16:22:31 +02:00
Philipp Maier c824fe4eb0 mgcp_client: fix typo Initalize -> Initialize
Change-Id: If57f8c0e54dbb5d37f40e36d968a6e6b75eec066
2021-08-04 08:04:10 +00:00
Philipp Maier a8739fc7be mgcp_lient: remove unsubstantial FIXME note
Change-Id: Ibc73a8a95d93c4a0f8a891bfba6fd1293ae6f1b5
2021-07-22 13:46:43 +00:00
Neels Hofmeyr d57310731f mgcp_client: add logging on received MGCP messages
There is verbose debug logging on MGCP messages sent out to the MGW, but
none on received MGCP messages. Add Rx logging.

Related: SYS#5529
Change-Id: Id76230896aa87c1a12bd5ad87a62430c048a2873
2021-07-15 11:36:15 +02:00
Philipp Maier 7d86d4c523 mgcp_client: fix error handling in mgcp message generation
The functions add_lco and add_sdp assert when the codec string can not
be generated. This is the case when an unexpected codec is addressed in
the input parameter mgcp_msg for mgcp_msg_gen(). Even though the API
user is expected only to use the codec identifiers in mgcp_client.h the
check should not be done with an assert. Instead mgcp_msg_gen() should
just return NULL imediately.

Also all generation functions should not use magic numbers as return
codes. Instead constants from errno.h should be used. It is also
problematic that the return codes from msgb_printf are added up.
Depending. It makes more sense to use an OR operator since msgb_printf
only returns 0 or -EINVAL, so the end result will be -EINVAL if one or
more msgb_printf fail and not just a random negative value.

Change-Id: Ibb788343e0bec9c0eaf33e6e4727d4d36c100017
Related: OS#5119
2021-06-11 15:16:13 +02:00
Philipp Maier eb984bd630 mgcp_client: drop nunnecessary else statement
There is an elarly return statement, so there is no need for an else
branch.

Change-Id: I96d0d468ccab302f9add206164f4d5b1b768bb48
2021-06-11 12:22:51 +02:00
Philipp Maier 92a73cd637 mgcp_client: get rid of magic numbers for E1 slots
use NUM_E1_TS-1 instead of 31 in relation of E1 timeslot count

Change-Id: Iee134d70f05883fcd2e58e0b9c78ed70aea16695
2020-12-10 15:23:17 +00:00
Harald Welte c2a8f59560 use osmo_fd_setup() whenever applicable
Change-Id: I1586e855d37670af2602fc26b5d1fc72a32d1929
2020-10-21 11:56:17 +00:00
Pau Espin 74d0e5c318 mgcp_client: Deprecate unused IPv4-only API
The API and related implementation fields are not used internally nor
externally, and only support IPv4. Let's simply deprecate the API and
drop all the uneeded implementation.

Change-Id: I905d4c4efabb6b4a4bc5c02e956808777243cadc
2020-09-07 15:55:30 +02:00
Pau Espin 531470a0ca mgcp_client: Allow setting IPv6 addresses
Change-Id: I257218b2ad7cbdd0ac4ae7fa75802bed74ce983f
2020-09-07 15:55:30 +02:00
Pau Espin 9dc73593a3 mgcp_client: Allow submitting and parsing IPv6 addr in SDP
Existing mgcp_client_test code required the '.' to trigger the same code
path, since with this commit we do extra checks and without a dot the
address is not accepted as IPv4 by osmo_ip_str_type().

Change-Id: I936bf57d37f5f0607dfe7fc66c37e424c3793f9b
2020-09-07 15:55:30 +02:00
Pau Espin 8667d5169d mgcp_client: Use INET6_ADDRSTRLEN to store addresses in str format
Warning: This breaks libosmo-mgcp-cli ABI!

Related: SYS#4915
Change-Id: Ib778e9a72764103b52a462ea3c7fb56b23c1bcd6
2020-08-31 17:10:08 +02:00
Vadim Yanitskiy ffbc618a13 libosmo-mgcp-client: mgcp_client_tx(): return rc on error
Change-Id: Ic2080241ceb9e00109a5222b78c35b7971320c21
2020-07-31 10:21:49 +00:00
Harald Welte 563ffc51b5 libosmo-mgcp-client: fix memleak in case if no response is received
This problem was noticed while running several LCLS test cases from
ttcn3-bsc-test.  Every test case makes osmo-bsc leak at least two
chunks named 'struct mgcp_response_pending'.

Here is the related osmo-bsc output with additional debug messages:

  DRLL ERROR mgcp_client_fsm.c:525 MGCP_CONN(to-MSC)[0x612000016120]{ST_READY}:
             MGW/DLCX: abrupt FSM termination with connections still present,
             sending unconditional DLCX...
  DLMGCP DEBUG mgcp_client.c:1010 mgcp_client_next_trans_id(id=35): new trans ID
  DLMGCP DEBUG mgcp_client.c:918 mgcp_client_pending_add(id=35): allocated and queued
  DLMGCP DEBUG mgcp_client.c:962 Queued 53 bytes for MGCP GW
  DLMGCP DEBUG mgcp_client.c:725 Tx MGCP: r=127.0.0.1:2427<->l=127.0.0.1:2727:
               len=53 'DLCX 35 rtpbridge/1@mgw MGCP 1.0\r\nC: 5\r\nI:'...
  DLMGCP ERROR mgcp_client.c:704 Failed to read: r=127.0.0.1:2427<->l=127.0.0.1:2727:
               111='Connection refused'

The MGCP client FSM enqueues a DLCX from its fsm_cleanup_cb(), and
terminates.  Thus if the remote MGCP peer becomes unavailable (e.g.
due to a network failure), we would never get a response, and since
the FSM is already terminated, nobody would pop and free() the
response handler from the queue (mgcp->responses_pending).

As a simple workaround, let's avoid allocating dummy entries of
'struct mgcp_response_pending' without a response handler.  The
only case where an MGCP message is sent without a handler is
exactly during the FSM termination.

Change-Id: I83938ff47fa8570b8d9dc810a184864a0c0b58aa
Related: OS#4619
2020-07-31 10:21:49 +00:00
Philipp Maier 4863591c23 mgcp_client: add function to generate e1-endpoint names
mgcp_client.h offers functions to generate endpoint names for wildcarded
request. This is used in osmo-bsc, lets now also add a function that can
generate e1-endpoint names.

Change-Id: Iec35b5bae8a7b07ddb3559f7114a24dcd10e8f14
Related: OS#2547
2020-07-16 11:56:39 +00:00
Harald Welte 827da2c867 mgcp_client_pending_add(): Consider "talloc returns NULL" case
Change-Id: I43a4715fa41fba5a5506fc08e3c21ef6f9ca2521
2020-07-15 10:57:08 +02:00
Harald Welte efe1571b7b mgcp_client_init(): consider "talloc returns NULL" case
Change-Id: I131019b3c04a7860a118991c8f3bb31185fb11e4
2020-07-15 10:56:45 +02:00
Philipp Maier a466f57007 mgcp_client: add docstring for mgcp_client_rtpbridge_wildcard()
Change-Id: I2d811b6ddda5b330054145abff37c996c54c3e3a
2020-06-26 10:50:06 +02:00
Vadim Yanitskiy e674345e29 libosmo-mgcp-client: fix use-after-free in mgcp_msg_gen()
Change-Id: Ib8b6c25489a6a704912aa1763d7430c8055d54e3
2020-06-18 11:40:37 +00:00
Vadim Yanitskiy 3f8139c55f libosmo-mgcp-client: fix use-after-free in mgcp_client_tx()
This function calls mgcp_client_pending_add(), that in its turn
allocates a 'mgcp_response_pending' and appends it to the queue.

In case of an error, it calls mgcp_client_handle_response() that
would free the 'mgcp_response_pending', but this structure would
still remain in the linked list (the queue).

Change-Id: Id94bb93a6b0ea7b7241cf7868112e9bec3e60f0b
2020-06-18 11:40:37 +00:00
Pau Espin a7152e055a Use OSMO_FD_* instead of deprecated BSC_FD_*
New define is available since libosmocore 1.1.0, and we already require
1.1.0, so no need to update dependenices.
Let's change it to avoid people re-using old BSC_FD_* symbols when
copy-pasting somewhere else.

Change-Id: I9b6463af713f76c06a144bdbf202c0d91eef4d21
2020-05-09 19:15:50 +02:00
Neels Hofmeyr 3abced8d64 allow larger MGCP client wqueue: 10 -> 1024
Enlarge the MGCP client workqueue maximum limit by factor 100.

During Abis load testing, a BSC trying to DLCX 200 conns at the same time hit
the limit of 10 very very quickly, and everything broke down.

Change-Id: I8980cce37bae0757828b28455b25c77bcb6316d0
2020-03-10 03:55:35 +01:00
Neels Hofmeyr e827831514 accept MGCP without SDP
SDP is an optional part of MGCP messages. Do not fail when there is no SDP part.

Practically this is useful to compose simpler MGCP responses from TTCN3 tests.
osmo-mgw itself always includes SDP, so there is no real impact on operating
libosmo-mgcp-client with osmo-mgw from osmo-bsc or osmo-msc.

Change-Id: I608001626459ea72415fb142f857550bbb90c683
2019-11-01 17:37:40 +01:00
Neels Hofmeyr 3ab8ca4d84 SDP: store all ptmap entries
If a ptmap appears in the SDP, always store it in the ptmap array. No longer
attempt to drop entries if they match the conventional payload type number.

- One reason is that the past code only matched full explicit "FOO/8000/1"
  strings, while the channel number "/1" can be omitted to imply 1; by simply
  storing everything received in the SDP, there is no need to add complexity
  to match both "FOO/8000" and "FOO/8000/1".

- The other reason is to rather parse exactly what was received, instead of
  filtering entries, to take away a degree of implied magic.

Change-Id: I2a69c21e68c602daf804744212d335ab1eafd81b
2019-08-28 04:57:19 +02:00
Neels Hofmeyr 23f4048b57 tweak mgcp_parse_audio_ptime_rtpmap()
- move the error logging up to the actual errors. Each appear only once, no
  goto labels needed.

- instead of strstr("rtpmap"), use osmo_str_startswith("a=rtpmap:") to more
  concisely trigger on the actual syntax of the audio parameters. Same for
  "a=ptime:".

Change-Id: I730111e245da8485c1b5e8811f75d140e379cec6
2019-08-28 04:57:19 +02:00
Pau Espin a2b1c5e6f6 Fix return variable of strtoul()
Return variable specified by strtoul() is "unsigned long int". If
"unsigned int" is used, according to Coverity the return value can never
be ULONG_MAX:

CID 202173:  Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
"pt == 18446744073709551615UL /* 9223372036854775807L * 2UL + 1UL */" is always false regardless of the values of its operands. This occurs as the logical second operand of "&&".

Furthermore, PT is 7 bit in RTP header [1], so let's avoid accepting
incorrect values.

[1] https://tools.ietf.org/html/rfc3550#section-5

Fixes: c5c1430a1c ("Catch unsigned integer MGCP parsing errors with strtoul")
Fixes: Coverity CID#202172
FIxes: Coverity CID#202173
Change-Id: Ice9eee6a252fab73dbab5ebf3cfc83c1b354fd08
2019-07-29 18:33:38 +02:00
Pau Espin c5c1430a1c Catch unsigned integer MGCP parsing errors with strtoul
Checks to find if strotul failed are taken both from:
man strtoul
man strtol

Change-Id: Ifba1c1e3151d6f92f9da3d4ca2569a5908455ca8
2019-07-25 12:14:48 +00:00
Pau Espin 166077ea48 mgcp-cli: Support lowercase header parameters
MGCP RFC3435 (https://tools.ietf.org/html/rfc3435) states almost all
text has to be handled in a case-insensitive way, except SDP parts.

Related: OS#4001
Change-Id: I4f7b07b77c2946e9cd6f0eeca00011bd905126dd
2019-07-03 12:29:37 +02:00
Pau Espin 1b1d7ed98f mgcp-cli: Validate osmux cid value during mgcp_msg_gen
Change-Id: I5c4d39b346b94de933f86200902c6c0ea2e1d5df
2019-05-23 16:48:24 +02:00
Pau Espin c1bf4694e7 mgw, mgcp-li: Handle X-Osmux param name as case insensitive
RFC3435 states most text (except SDP) must be handled as case
insensitive.

Related: OS#4001
Change-Id: Iac073f1db46569b46eddeaecc9934a2986bd50f1
2019-05-14 20:35:13 +02:00
Pau Espin 91088c305f mgcp-cli: Parse X-Osmux on CRCX response
Change-Id: I6174d092b7425b8d3d6d02a55bf294be3e710e6a
2019-05-14 11:32:29 +02:00
Pau Espin 900cd6518a mgcp-cli: Allow submitting X-Osmux on CRCX request
Change-Id: I73b4c62baf39050da81d65553cbea07bc51163de
2019-05-14 11:29:44 +02:00
Neels Hofmeyr 84274e4e9b constify map_codec_to_pt() ptmap arg
Change-Id: I030843d2d692b7a73cca8f427df070d2806ab695
2019-04-30 02:25:05 +02:00
Pau Espin ca0818c760 mgcp-client: Sanitize implementation of mgcp_client_rtpbridge_wildcard
* Get rid of string define containing printf statements
* Split name from rest of checks to easily add new names later

Change-Id: I46e05a7a3432733976760bbf1c5deb4f7610db11
2019-04-16 19:45:29 +02:00
Pau Espin c12bfb7ffc mgcp-client: whitespace cleanup in mgcp_client.c
Change-Id: Ic3495d70cb9c4e12552c6d97481cc0cf04b79f94
2019-04-16 17:23:09 +02:00
Philipp Maier 228e591589 AMR: Add function to convert between bw-effient and octet aligned mode
RFC3267 specifies two framing modes for AMR packets. An octet aligned
mode is specified where all fields of the AMR packets are aligned to
octet boundaries. The second framing mode is the bandwith efficient mode
where the fields are directly packed one after another.

- add paring/generation functions for related SDP fmtp parameters
- add conversion function to convert AMR payload

Depends: libosmo-netif I5b5a0fa644d8dbb1f04f9d7e35312683c7b3d196
Change-Id: I622c01874b25f5049d4f59eb8157e0ea3cbe16ba
Related: OS#3807
2019-03-12 09:56:28 +01:00
Neels Hofmeyr 47642f245d make codec_table public as osmo_mgcpc_codec_names
These value_string[]s are also useful for printing chosen codecs in osmo-msc.

Change-Id: Ida0e59f9a1f2dd18efea0a51680a67b69f141efa
2019-03-04 22:25:06 +01:00
Neels Hofmeyr ed0c1aa9d5 mgcp_client: tweak some log levels INFO -> {DEBUG,ERROR}
Change-Id: Ie4ecb4b82a7a1e476c58d0a6056525733254adbb
2019-01-03 02:12:55 +01:00
Neels Hofmeyr ac69ea9cdf mgcp_client: make domain part of endpoint configurable
So far, both osmo-msc and osmo-bsc always pass endpoint names of the form
'...@mgw' to osmo-mgw. Allow configuring the 'mgw' part.

Note that the actual way to pass a differing name is to pass a composed
'rtpbridge/*@foo' to mgcp_msg_gen() in the struct mgcp_msg. So this merely adds
a common VTY config for the domain name part, changes to clients are necessary.

- add mgcp_client_rtpbridge_wildcard() (useful for AoIP endpoints)
- add mgcp_client_endpoint_domain() (useful for SCCPlite endpoints)
- add mgcp client vty cfg 'mgw endpoint-domain NAME'

Rationale: reading pcaps becomes so much easier when each of osmo-bsc and
osmo-msc address their MGW with differing domain names. Otherwise, both will
have a '0@mgw' endpoint and it gets really confusing.

Also: our MGCP clients osmo-bsc and osmo-msc use code dup to compose the
initial 'rtpbridge/*@mgw' rtpbridge wildcard. It should be defined by this API
instead.

This will be used by:
* osmo-msc I87ac11847d1a6d165ee9a2b5d8a4978e7ac73433
* osmo-bsc I492023e9dca0233ec0a077032455d9f2e3880f78

After these, with according configuration, there can be a '0@bsc' and a '0@msc'
endpoint on two separate osmo-mgw instances:

osmo-mgw-for-bsc.cfg:
 mgcp
  domain bsc

osmo-bsc.cfg:
 msc 0
  mgw endpoint-domain bsc

osmo-mgw-for-msc.cfg:
 mgcp
  domain msc

osmo-msc.cfg:
 msc
  mgw endpoint-domain msc

There can also be '0@bsc' and '1@msc' endpoints on one single osmo-mgw instance with:

osmo-mgw.cfg:
 mgcp
  domain *

and same osmo-{bsc,msc}.cfg as above.

(By default, everything will still use '@mgw')

Change-Id: Ia662016f29dd8727d9c4626d726729641e21e1f8
2019-01-03 02:11:23 +01:00