Commit Graph

30 Commits

Author SHA1 Message Date
Holger Hans Peter Freyther 7b7eef62c1 nat: Change MGCP DLCX handling and send dummy MDCX to the BTS.
When setting a new MSC timeslot to a SCCP connection check if
any of the existing connections have this timeslot, if so we will
send a DLCX down the stream to make sure it is closed there, when
we will CRCX this new timeslot we will happily reallocate it.

When the SCCP connection goes away, or we get a DLCX from the
network, or the BSC is gone we will send a DLCX message down the
stream as well.

When we receive a CRCX from the network we will forward the CRCX
as usual and send a dummy MDCX after it.

For the DLCX and the dummy MDCX we send a custom MGCP message
that will not provoke an answer. Even if the downstream MGCP GW
will answer we will ignore it due the dummy transaction id that
is not used anywhere else.

This change should make sure that we close the dowstream endpoint
all the time, even when the DLCX arrives after the SCCP connection
is torndown.
2010-06-15 20:24:16 +08:00
Holger Hans Peter Freyther 842c0c020f [nat] Reword warning when we had a pending transaction and forget about it. 2010-06-15 20:24:15 +08:00
Holger Hans Peter Freyther 317ae72c47 nat: Clear the connection on a DLCX
We can forget about the timeslot/multiplex when getting
the DLCX. This way we make room for the next connection
that might need to reuse this address.
2010-06-15 20:24:15 +08:00
Holger Hans Peter Freyther 08a1b16674 nat: Return the SCCP Connection again...
We will reset the multiplex in a DLCX message and then
we can reset the multiplex as well...even if the MGCP
connection is staying open. or at least this is a theory.

The MSC likes to leave a connection open during CallControl
when hanging up early enough in the process.
2010-06-15 20:24:14 +08:00
Holger Hans Peter Freyther eb52e89c3a nat: Return the newest SCCP connection...
In case we have a stale SCCP connection with an Endpoint that
we want to reassign...use the newest (last) occurence of that
as it is most likely the one we want to handle.
2010-06-15 20:24:14 +08:00
Holger Hans Peter Freyther 1395948e18 Use osmocore tlv definition for GSM0808. 2010-06-15 20:24:14 +08:00
Holger Hans Peter Freyther 290d84e15f nat: Set a dummy bts_ip to avoid misdetection of the bts...
It was possible that the nat detected the core network
gateway as the bts just due being the first to send data
to the port. Fix it by setting a dummy bts_ip to force
the mgcp_network code to compare the in_addr.
2010-06-15 20:24:13 +08:00
Holger Hans Peter Freyther 2896df7605 nat: Attempt to have a single BSC write method
This method currently prepends the IPA header and sends
the data. In the future we might be able to use SCTP for
it.

We have to remove the IPA header from the static messages
for that to work.

This code is untested.
2010-06-15 20:24:13 +08:00
Holger Hans Peter Freyther bba593406b nat: Allow to realloc already allocated endpoints
E.g. when the MGCP on the BSS is not responding we could block
all of our endpoints. As we are mostly in the middle and forward
bits we will happily reallocate the endpoints.
2010-06-15 20:24:12 +08:00
Holger Hans Peter Freyther dd16b425c8 nat: Attempt to make MGCP forwarding more robust
When not being able to allocate the msgb for the forwarded data
there is no point in keeping and preparing the transaction. So
we can move the msg creation a bit up and only do the allocations
after having done the msgb allocation.

When receiving a DLCX we will now delete the endpoint right away. This
means when a BSS does not respond to the DLCX our endpoint will not
be blocked. E.g. this could happen when the MGCP is restarting or
in similiar conditions. When the BSS is not responding we move the
burden up the chain to the CallAgent. We have to still keep track
of the transaction id and the bsc pointer to keep the mgcp forward
routine working.
2010-06-15 20:24:12 +08:00
Holger Hans Peter Freyther 2066b8c267 nat: Fix thinko... use the right fd to determine the IP of the bts
Use the fd of the BSC Connection to determine the IP address of the
BTS as we are seeing it.
2010-06-15 20:24:12 +08:00
Holger Hans Peter Freyther 92febd3ea4 nat: Improve the log message and print the errno/strerror(errno) 2010-06-15 20:24:12 +08:00
Holger Hans Peter Freyther 4ad5850d63 nat: Set the MGCP audio payload to -1.
This value is copied into the bts_audio_payload when allocating
a BTS MGCP endpoint. For the nat we have actually no interest in
patching MGCP messages. We will patch them to the network because
the code will do it anyway, we will not patch things back to the
BTS.
2010-06-15 20:24:12 +08:00
Holger Hans Peter Freyther d2dd6e878c Revert "nat: Remember where the BTS is listening for things."
Remove the code to parse port as we need to discover the
BTS behind the nat and most likely it will have a different
port than the one advertised by the BTS.

This reverts commit c6a1fe773d.
2010-06-15 20:24:11 +08:00
Holger Hans Peter Freyther 26a43896cd nat: Close all endpoints used by a BSC when the BSC is gone
Cleanup all endpoints that belonged to a given BSC. This is
one part of the cleanup, the other is to bring down the SCCP
link properly.
2010-06-15 20:24:11 +08:00
Holger Hans Peter Freyther 5cc94fb86a nat: Remember a pending delete on an endpoint and carry it out later 2010-06-15 20:24:11 +08:00
Holger Hans Peter Freyther 3f7c7d07d8 nat: Avoid crashing when we have no pending transaction 2010-06-15 20:24:11 +08:00
Holger Hans Peter Freyther b9ac37d22f nat: Logging improvement for the nat.
Print some more information, e.g. when a BSC is connected
and authenticated, print the SCCP ref number.
2010-06-15 20:24:11 +08:00
Holger Hans Peter Freyther f05506eceb nat: Remember where the BTS is listening for things.
Extract the port from the BSS's MGCP Gateway so we know
where to forward the data to.
2010-06-15 20:24:11 +08:00
Holger Hans Peter Freyther 806aca94c2 nat: No need to match \r\n when parsing the C: N 2010-06-15 20:24:11 +08:00
Holger Hans Peter Freyther 9e5300ada6 nat: Remove the broken empty line check, follow \n vs \r\n of input
Instead of checking the token for NULL we need to check if running
was set to null. Look at the data of the token and check if the line
was ending with a \r\n or \n and then when rewriting a line use that
line ending as well. Add a new test for that.
2010-06-15 20:24:11 +08:00
Holger Hans Peter Freyther b3e0a032d0 nat: Use a ptr that was allocated by talloc
The endp is part of an array allocated by talloc and simple
array members do not qualify as a context start address.
2010-06-15 20:24:10 +08:00
Holger Hans Peter Freyther 8d20065c4b nat: Make rewrite work on string, read to a string first, copy to msgb
The MGCP protocol parsing is adding '\0' to make sure we do not
parse beyond where we should parse. This does not mix with strtok
or similiar routines.
For now we will read the msg into a global array first, then copy
it to the msgb for mgcp protocol handling and if we are required
to forward it to the MGCP we have a untouched copy we will modify
into our own msgb.
2010-06-15 20:24:10 +08:00
Holger Hans Peter Freyther 3c3bce10bd nat: Return MGCP messages to the call agent
Attempt to find the message by transaction id, then patch
the response and use the IP/PORT of the local network, update
the ci with the one from the BSC.

This is currently not tracking any state of the MGCP and will
not handle two bsc's... this will need to happen later.

With this in we should be feature complete and now enter the
mode of making all of this work reliable and fixing thinko's
and other bugs.
2010-06-15 20:24:10 +08:00
Holger Hans Peter Freyther a0df82d48d nat: Handle CRCX/MDCX/DLCX at the nat
* Forward a rewritten msg to the BSS. We change the IP and port
  to point to the NAT instead of the core network. We also keep
  track of the BSC and the transacition id.
* Handle the case where we have not found a SCCP connection and
  need to send a response ourselves.
2010-06-15 20:24:10 +08:00
Holger Hans Peter Freyther 76c8354863 nat: Test rewriting of MGCP messages to patch ip and port
Add code to change the ip and port for audio data inside
MGCP messages. This is needed because the BSS might be
behind the NAT and can not reach the network directly and
might be behind a nat so the announced sourceport is not
the one as we see it.
2010-06-15 20:24:10 +08:00
Holger Hans Peter Freyther fc9bd23000 nat: Add code to find a BSC connection by the given msc multiplex 2010-06-15 20:24:10 +08:00
Holger Hans Peter Freyther a7f8018eb2 nat: First go at handling MGCP inside the nat
Listen on the MGCP gateway port and let our protocol stack
handle everything for now. We will need to have some more
control over things though.
2010-06-15 20:24:10 +08:00
Holger Hans Peter Freyther 241e13005a nat: In the case of losing the MSC, reset all endpoints
When losing the SCCP connection make sure that we free all
endpoints. The disconnection of the BSC should already make
sure they are closed but this makes sure everything is
properly reset.
2010-06-15 20:24:10 +08:00
Holger Hans Peter Freyther 465313e48c nat: Look at the assignment command and remember on which timeslot the data is
This information will be needed when we are trying to forward
MGCP connections to and from the BSC through the IPA protocol.
2010-06-15 20:24:09 +08:00