Commit Graph

105 Commits

Author SHA1 Message Date
Philipp Maier 14b27a8893 osmo-mgw: rename struct mgcp_trunk_config and symbol tcfg
rename struct mgcp_trunk_config to struct mgcp_trunk and the related
symbol name "tcfg" to "trunk" in order to better match the reality.

Change-Id: I02889dbf8149e139b1bd0326e13ce4c1aec867d1
Related: OS#2659
2020-06-02 20:30:58 +02:00
Harald Welte c39b1bffec mgcp_protocol: Avoid code duplication between virtual + other trunks
There were two code paths that were supposed to do exactly the same,
but then in Change-Id I3994af016fb96427263edbba05f560743f85fdd4 only
one of the two was modified, resulting in OS#4034

Let's
* dynamically allocate the virtual trunk
* rename mgcp_config.trunk to mgcp_config.virt_trunk to clarify
* as a result, abolish copy+pasted code for trunk initialization

Change-Id: I54762af6d417b849a24b6e71b6c5c996a5cb3fa6
Related: OS#4034
2020-05-28 09:23:25 +00:00
Alexander Chemeris ebb9bf3f12 rtp_bridge: Demote a chatty ERROR log message to DEBUG level.
Not having a second leg of an MGCP endpoint is a normal situtation
and can't be treated as an ERROR message, especially not as an ERROR
message logged on every RTP packet. This happens routinely at
the beginning of call setup and we get tens of ERROR messages in
the logs for every call.

Change-Id: If741a742208772bda4e59236345d7ae650368d5a
2020-05-11 18:14:31 +03:00
Alexander Chemeris 61cf9bb5f1 mgcp_network: Fix a typo in the comment bahviour -> behaviour
Change-Id: I59a06b95e9bbf90c038c5c9234f5c857315d5f07
2020-05-11 18:13:53 +03: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
Harald Welte a48ff4a738 Update per-trunk global packet/byte counters in real-time
We used to update only the per-connection rx/tx packet/byte counters
on-the-fly, but not the per-trunk global counters.  The latter would
only be updated at the end of a connection.  As MGCP connections
can last quite long (think of a long phone call) this is maybe
not the best of ideas.

Note: The all_rtp:err_tstmp_in and all_rt:err_tstmp_out are still
only updated at the end of a connection.

Change-Id: Ib3866cb8149d3257fcf39733846c97c33881c4ee
Related: OS#4437
2020-03-08 14:50:20 +01:00
Neels Hofmeyr 5a6220f43b mgcp_send(): stop looping on conversion error
If mgcp_send() runs a transcoder loop, break the loop if rfc5993_hr_convert()
or amr_oa_bwe_convert() return with error. Possibly fixes an infinite loop
situation for erratic packets? (Didn't check for that in detail.)

Change-Id: Iba115a0b1d74e7cefba5dcdd777e98ddea9eba8c
2019-08-21 23:06:02 +02:00
Neels Hofmeyr 7c6dd3c2c3 fix crashes: don't assert on incoming RTP packet size
Remove various OSMO_ASSERT() on size of incoming packets. Doing an assert on
incoming data is a DoS attack vector, absolute no-go. Instead, return -EINVAL
and keep running.

Change some return values to be able to distinguish successful operation from
invalid RTP sizes. In rtp_data_net(), make sure to return negative if the RTP
packet was invalid.

Some of the error return codes implemented here will only be used in upcoming
patch Iba115a0b1d74e7cefba5dcdd777e98ddea9eba8c.

Change-Id: I6bc6ee950ce07bcc2c585c30fad02b81153bdde2
2019-08-21 23:05:35 +02:00
Pau Espin 9aaaab6b3b osmux: Fix loopback for Osmux connections
Move code in RTP specific path to generic dispatch_rtp_cb. This way
loopback logic is applied both for Osmux and RTP connections.

Change-Id: Ia30f5a14f150e4d151eac4d1046ea834f1685a5f
2019-05-15 23:32:09 +02:00
Pau Espin a93c6e9263 osmux: Provide correct local port during mgcp resp
Also document some possible future improvements for local addr.

Change-Id: I12c8fcdc8b772b9f92a70774406d4662f44bd9a9
2019-05-14 11:36:33 +02:00
Pau Espin f1d301a9a6 cosmetic: mgcp_udp_send: Document port param is in network byte order
Change-Id: I7c4a388eba850ac066e60db089d46da0247773ec
2019-05-13 18:56:56 +02:00
Pau Espin 3239f6212e Introduce log fmt helpers LOGPENDP and LOGPCONN
Let's define macro once and use it everywhere instead of passing endp
information in different ways everywhere. Furthermore, use conn whenever
appropiate to have more information.

Change-Id: I1c49b1eb16bc5f1010376da5cf407ca6e31d81f2
2019-04-24 18:57:57 +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
Philipp Maier 58128258b0 mgcp_network: use mgcp_rtp_codec in downlink format callback
The callback function mgcp_get_format() is used to request the codec
parameters for a specific connection. This function returns the
parameters as idividual pointers. Since there is a struct that holds all
important codec information among the ones which are currently returned
by mgcp_get_format, lets just use this codec struct as single return
value.

Change-Id: I348f9141eb59ed1a986447b96ab4a24ddf326936
Related: OS#3807
2019-03-11 09:55:04 +01:00
Neels Hofmeyr e3f8bca424 log: don't spam with "can not patch PT" messages
currently, when looking at an osmo-mgw log output with a phone call working
completely fine, you see these messages on LOGL_ERROR for each RTP packet:

20190304221420619 DRTP ERROR endpoint:0x0 can not patch PT because no suitable egress codec was found. (mgcp_network.c:761)
20190304221420639 DRTP ERROR endpoint:0x1 can not patch PT because no suitable egress codec was found. (mgcp_network.c:761)
20190304221420639 DRTP ERROR endpoint:0x0 can not patch PT because no suitable egress codec was found. (mgcp_network.c:761)
20190304221420659 DRTP ERROR endpoint:0x1 can not patch PT because no suitable egress codec was found. (mgcp_network.c:761)
20190304221420659 DRTP ERROR endpoint:0x0 can not patch PT because no suitable egress codec was found. (mgcp_network.c:761)

Put these messages on DEBUG level instead. They currently do not convey useful
information.

Possibly our MGCP clients could use some changes in behavior regarding payload
types, but since that topic is quite unresolved, let's not spam the ERROR log
level with this.

Change-Id: I4afc41fd472ec8ba887b9263fbac62de50d7cef9
2019-03-04 22:25:06 +01:00
Philipp Maier 9fc8a02196 Add option to GSM HR frames to RFC5593 representation
There are different specifications around on how a GSM-HR frame should
be encapsulated into an RTP packet. RFC5593 specifies a ToC (Table of
Contents) byte to be prepended in front of the payload data.

The two formats can be distinguished easily by their length. Then the
data can be formatted into the corresponding opposite format and vice
versa.

- Add new VTY rtp-patch options
- Add conversion function

Change-Id: Iceef19e5619f8c92dfa7c8cdecb2e9b15f0a11a1
Related: OS#3807
2019-02-25 15:06:05 +01:00
Oliver Smith e36b775eae Inactive connection cleanup (disabled by default)
Add a watchdog timer to connections, and close these connections when
the watchdog timer expires. Kick the watchdog whenever RTP messages or
the relevant MGCP messages arrive. Add the currently remaining timeout
to "show mgcp stats" in the VTY.

This feature is disabled by default, as it is incompatible with LCLS
(connections in LCLS state appear to be inactive). Enable it with the
new "conn-timeout" VTY setting. In general, this feature can be used to
work around interoperability problems causing connections to stay open
forever, and slowly exhausting all available ports. This happened for
various reasons already.

MDCX is the only relevant MGCP message:
- CRCX creates the conn and timer
- DLCX deletes the conn and timer
- MDCX is the only remaining supported MGCP message that indicates a CI
- Can't easily generically parse a CI for all MGCP messages, parsing is
  done in handle_modify_con().

Related: OS#3429
Change-Id: I18886052e090466f73829133c24f011806cc1fe0
2019-02-06 12:01:06 +01:00
Neels Hofmeyr ad21a0e166 check_rtp: on IP:port errors, log the IP and port
Half of those are obviously zero, but I'd rather print the raw data instead of
adding string constants, even if the condition must always lead to 0.0.0.0:0.

Rationale: I had osmo-mgw listen on 0.0.0.0 and got the error message
  DRTP ERROR endpoint:0x1 destination IP-address is invalid
which didn't convey that 0.0.0.0 is regarded as invalid.

Change-Id: I9e98d464a27038904797c5c10735a98ef5b7b9c3
2018-12-17 13:38:12 +00:00
Harald Welte c26b665c0c check_rtp_origin(): Avoid using memcmp for comparing integer types
in_addr consists only of s_addr, which is an integer type that
can be compared directly.  By avoiding memcmp() here we would have
been able to catch Coverity CID#188874 even without Coverity, and
make the code more compact...

Change-Id: Ic6105d39ae2fb4b301f87448b16763fe9f695621
2018-10-21 12:01:04 +02:00
Harald Welte 0479b2a15f check_rtp_origin(): Don't memcmp sockadd_in and in_addr
We were comparing 16 bytes (sockaddr_in) in memcmp() rather than using
four bytes (struct in_addr in mgcp conn end).

This is a good example why we should actually simply use the == (equals)
operator rather than using memcmp which treats everything as void.

Change-Id: Ic64256619ef893d625400e8b1b573ea2c629ed9c
Fixes: Coverity CID#188874
2018-10-21 11:56:05 +02:00
Neels Hofmeyr efd645e5a8 log: avoid logging early media as error
When the peer address is still 0.0.0.0, the endpoint is not yet configured.
This commonly happens before bridging a call is complete, so instead of ERROR
logging about an invalid packet, rather INFO-log this as "early media".

Related: OS#3539
Change-Id: I335f6453bd599be76eef08fcf9e5daed071e5b6d
2018-09-10 13:37:26 +02:00
Neels Hofmeyr 0063ca2fb0 fix 3G hack: allow any IP for loopback and 0.0.0.0
HACK: for IuUP, we want to reply with an IuUP Initialization ACK upon the first RTP
message received. We currently hackishly accomplish that by putting the endpoint in
loopback mode and patching over the looped back RTP message to make it look like an
ack. We don't know the femto cell's IP address and port until the RAB Assignment
Response is received, but the nano3G expects an IuUP Initialization Ack before it even
sends the RAB Assignment Response. Hence, if the remote address is 0.0.0.0 and the
MGCP port is in loopback mode, allow looping back the packet to any source.

None of these are anything near nice, during call setup using a 3G femto cell,
we still lack a proper IuUP handling. See OS#2459, OS#1937. This is merely a
temporary hack to maintain 3G voice usability in a quick and dirty way.

Related: OS#3411
Change-Id: Ib25e6261855eae8ddb8d1c0b8838cc3e30332cf1
2018-08-24 10:37:03 +00:00
Philipp Maier fee4fa9492 Cosmetic: remove misplaced line break
Change-Id: I7eea5454cb0567a4a162fb9796f889b2daa21af7
2018-08-03 12:24:20 +02:00
Philipp Maier 4dba769577 network: check packets before further processing
When we receive a packet, we do not really check the contents. However,
we should at least do some basic checks.

- Check for short RTP packets
- Check if the length field of RTCP packets seems plausible
- Check if the packet type of RTCP packets makes sense (IANA)

Change-Id: Id47b9eee2164c542e6b673db24974859dd0a7618
Related: OS#3444
2018-08-03 12:20:52 +02:00
Philipp Maier da895b1151 network: do not patch PT of RTCP packets
At the moment all packets that are sent with mgcp_send are fed into
mgcp_patch_pt(). This functions corrects the payload type so that it
matches the codec configuration on the egress side. However, this
functions is only to be used with RTP packets and must not be used on
RTCP packets, which we currently do because we do not check if the
packet is RTCP or RTP.

- Check if the packet is RTP before running mgcp_patch_pt()

Change-Id: I55b8aa830e4e23f991373470bd04d4db12241c56
Related: OS#3444
2018-08-03 12:20:01 +02: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
Neels Hofmeyr 35a382968c IuUP hack: make RTP patching less general
We currently still patch over an RTP message to make it look like an IuUP
Initialization Ack specifically for the ip.access nano3G femto cell.

Be more specific about it:

- only patch over RTP in 'loopback' mode. osmo-msc specifically leaves the
  endpoint in loopback mode for this hack, so if we're not in 'loopback', then
  this hack is out of place.

- only patch over RTP if the header indicates an IuUP Initialization (check for
  0xe4 byte).

Change-Id: Ia9ec4debc138b34f6ca6a871a8778eafa6c0ba21
2018-07-23 18:32:23 +02:00
Neels Hofmeyr 7066af825a cosmetic: mgcp_network.c: merge one LOGPC to its preceding LOGP
Change-Id: I4dde8a060ec77e1234a373d7501c7082ae4c5028
2018-07-23 18:32:23 +02:00
Philipp Maier acc10353fe protocol: prevent unnecessary null pointer deref
The function setup_rtp_processing() in mgcp_protocol.c executes a
function pointer setup_rtp_processing_cb(). The function pointer
gets two struct mgcp_rtp_end pointers as parameter. To get those
parameters it has to dereference them from struct mgcp_conn_rtp
pointers. The variable conn_src is such a struct pointer and there
are conditions where this pointer may be NULL. The function at the
function pointer should get the conn pointers directly instead of
the dereferenced end (rtp) pointers. This also gives additional
flexibility to the implementation behind the function pointer,
which is not yet defined (the function pointer points always to
a stub function since we donot support transcoding yet.

- give conn pointers directly to setup_rtp_processing_cb() insed
  of dereferencing conn_src->end

Change-Id: Id46e9bfba88613387026639eb4957221cce6820a
Closes OS#3406
2018-07-19 18:15:23 +02: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 e6df0e47e7 mgcp_network: do not log destination invalid ip/port as error
It is legal to create connection without setting the destination
ip and port (this usually done later through MDCX). However, if
some other connection tries to deliver an RTP packet through a
a half open connection, then the fact that no destination ip is
set is logged as error even if it is a pretty normal situation.

- Check if destination ip and port are set to zero. If yes, we
  assume that the destination connection details are intentionally
  not set yet. Only when one value is set and the other one not,
  we log an error. Otherweise we log a message to debug.

Change-Id: If96e5a60b8ab92259d3bddaa143121893bb6c525
Related OS#3104
2018-05-29 14:09:13 +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
Philipp Maier 0ec1d4e17c network: independently initalize state->out_stream
The struct state->out_stream.ssrc is initalized by first initalizing
state->in_stream and then copying state->in_stream over to
state->out_stream. This works as long as no pointers to other objects
are added to struct mgcp_rtp_stream_state but we may add pointers to
struct mgcp_rtp_stream_state in the future.

- Initalize out_stream and in_stream independently from each other

Change-Id: I5deb27e609448ee0b9f7034e644ae96f1e57887a
Related: OS#2517
2018-05-16 11:32:12 +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
Philipp Maier df5d219f39 mgcp: fix use-after-free and add callback for endpoint cleanup
Since we will support multiple different types of endpoints in the
future, all these endpoints will handle connections slightly different
and there will be possibly state that needs to be kept consistant
when a connection is deleted.

In mgcp_network.c where we implement the callback that is used to
create an rtp-bride-endpoint. In that callback we cache the pointer
of the connection we where we want to bride to (opposite connection).
When one of the connections is deleted using a DLCX operation, the
pointer is still there and the next incoming packet causes a use-
after-free segfault.

- introduce an endpoint specific callback function that is executed
  before removing the connection.

- implement the endpoint specific callback for rtp bridge endpoints,
  so that the use-after-free is prevented.

Change-Id: I921d9bbe58be1c3298e164a37f3c974880b3759f
2018-02-06 08:21:24 +00: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
Neels Hofmeyr 5672563f7e cosmetic: mgcp_network: typo in log
Change-Id: Ia7675e52fe1082d21bd68dcf54fe34c0f0326f11
2018-01-17 10:51:09 +00:00
Harald Welte 8890dfa634 osmo-mgw: Use libosmocore socket abstraction
There's no need for us to use the sockets API directly:  We have
pretty nice socket helper functions in libosmocore, let's make
use of them.

Change-Id: I39d47b8a27f683060a2facf2dbecff8d00c19ce9
2018-01-08 12:52:18 +00:00
Harald Welte 1d1b98f4a4 libosmo-mgcp: Cosmetic spelling fixes in comments
Change-Id: Ic0469c2a4d69b55a6a90653ad7ea1ad89a34e4bc
2017-12-25 10:10:29 +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
Harald Welte 3338135ead strct mgcp_rtp_state: Group + document struct members related to patching
Change-Id: I403ddcafe0a11290103bb017568cfacaf5c04412
2017-12-25 10:10:29 +01:00
Philipp Maier 5dbfc78aff network: use originating RTP packet address for loopback
When a connection is created in loopback mode all incoming
packets should be reflected back to their origin. If the
user did not supply a destination address with the CRCX
command all incoming packets will be tossed because no
destination address is officially known yet.

If there is no destination address set and the connection
is in loopback mode. Then use the originating address of
the incoming packet as destination address.

Change-Id: I3d1abe56d016e28c97f60635eb574679d36e2c52
2017-12-12 16:27:14 +01:00
Philipp Maier 230e4fc270 cosmetic: clearly mark endpoint numbers as hex
The log prints the endpoint numbers as hexadecimal numbers, but
it does not prefix them with "0x".

Add "0x" prefixes to all endpoint number outputs in the log

Change-Id: I284627de02cd140a894445375e9152ff007a71e6
2017-12-01 11:58:24 +00:00
Philipp Maier f8bfbe8b14 client: use osmo_strlcpy instead of strncpy
simplify \nul termination of the ip_addr string

Change-Id: I94e3815f45d08e0d40faf41e580547de937c4ce8
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 e6f172dd57 network: remove unused return code
The function that forwards the tapped (voice ebug) traffic returns
its status (sendto) to the caller. However, none of the callers
seem need this info.

Remove the return code and print an error message on failure

Fixes: Coverity CID#178666
Change-Id: I16c12c4565bccbc0d75c412b43469bf70b6b7ea5
2017-11-08 19:14:06 +00:00
Philipp Maier b969455941 network: fix rtp packet length
When sending rtp packets sizeof(buf) is used as length. This causes
all RTP packets to be the size of the buffer (4096) containing the
rtp payload and random excess data from previoes memory usage

Use the actual length of the received RTP data, rather then the
full buffer size.

Change-Id: I47a15701f9a7e7a492df183b67ec971f5be61069
2017-11-08 16:57:31 +01:00
Philipp Maier 1cb1e38dbc network: autdetect rtp bind ip-address
Currently there are two ways to set the rtp bind ip-address (local
ip address where the rtp streams are bound to). It is possible to
set no set an rtp bind ip, if none no address is configured, then
the ip address where the mgcp service is bound to is used.

On a system with multiple network interfaces it is likely that
there are the remote end is not reachable through the interface
that has been configured. In this case rtp ip-probing can be
enabled via vty option in order to automatically detect the
ip address of the interface that points towards the remote end.

The autodetection can only work if the ip-address is known when
a CRCX is performed. For this the remote entity must include the
remote ip address in the sdp trailer.

Implement probing to determine te right local ip address
Add debug log to display which ip address is actually used
Add a VTY option for the probing functionality.

Change-Id: Ia57cf7dab8421fd3ab6e1515727db0080373485e
2017-11-02 17:16:04 +01:00
Philipp Maier c341388b30 network: add separate log category
the network (mgcp_network.c) part and the protocol part
(mgcp_protoocl.c) share a single loglevel DLMGCP. This
makes debuging hard because when debugging the protocol
we also get the log output from the RTP packets.

assign the network part a private loglevel and keep DLMGCP
for the directly MGCP related code

Change-Id: I55a2711798d1d1c2c9ef2f3b7ebb8fdd78bd6ea2
2017-11-02 11:47:44 +01: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