Commit Graph

89 Commits

Author SHA1 Message Date
Holger Hans Peter Freyther 47dd4944ae nat: Store the config in the connection instead of the lac
This allows that we can print the Nr. next to the lac
and it allows us to change the lac at runtime without
reconnecting the BSC.
2010-06-15 20:24:12 +08:00
Holger Hans Peter Freyther a7c377d593 nat: Close the filedescriptor when ignoring the request. 2010-06-15 20:24:12 +08:00
Holger Hans Peter Freyther 5f291d5077 nat: Add logging commands for the nat as well. 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 530c4b1aad nat: Print the unknown byte as a integer instead of charachter
The value might be a non printable one.
2010-06-15 20:24:11 +08:00
Holger Hans Peter Freyther f46ce5329d nat: Patch IT messages as well..
We need to patch the source/dest reference inside the messages
as well otherwise we will see failures in the SCCP connection
on long calls.
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 9d51855f66 nat: remove is called on already patched connections..
Fix the test to search for the original message instead
of the already patched one that should not find any items
anyway.

The remove is called on already patched connections so we
need to match it with the patch reference count.
2010-06-15 20:24:11 +08:00
Holger Hans Peter Freyther 560af50422 nat: Print the SCCP ref's as hex numbers
This allows to more easily compare the numbers with traces
seen in wireshark.
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 32d343644d nat: Print the MSC multiplex as well 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 bbb9d398e1 nat: Check the authentication bit later...
When moving it up here the code started to reject
the identity responses of the bsc and we would
never authenticate. Move it back down.
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 a128d91f98 nat: Allow to send MGCP messages from the BSC to the network 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 f4cfc4f201 nat: bsc_mgcp_clear is called from within the remove function
No need to call it twice... All endpoints should be properly
freed as part of the SCCP disconnection.
2010-06-15 20:24:09 +08:00
Holger Hans Peter Freyther d131b79fc2 [nat] Send a RSIP down to the BSC after it connects
Make sure the MGCP attached to the BSC is resetting all
endpoints whenever the BSC is connecting to us as we assume
that all endpoints are available.
2010-06-15 20:24:09 +08:00
Holger Hans Peter Freyther f7d3335817 nat: Add MGCP code and parsing to the nat code..
For the nat we will have NAT and MGCP in the same process
and this commit starts with that. We are linking in the MGCP
code and one can embed MGCP config snippets...
2010-06-15 20:24:09 +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
Holger Hans Peter Freyther 23fe7be1ca sccp: Move the destruction of the sccp connection to a new place 2010-06-15 20:24:09 +08:00
Holger Hans Peter Freyther 49c7fb52f0 nat: Return the SCCP connection, change order of patching and updating
* Return the SCCP connection. This will be needed to store the
  assigned timeslot in there.
* Update code to work with this change
* This uncovered a bug in the CC handling, at the time the BSC was
  passed it was still a null pointer and the code would have failed.
2010-06-15 20:24:09 +08:00
Holger Hans Peter Freyther 72ba1624b3 misc: Do not prepend 0x when using %p in printf. 2010-06-15 20:24:09 +08:00
Holger Hans Peter Freyther d7657ffc84 nat: Fail more early in the case of not being authenticated
This is also fixing a possible memory leak.
2010-06-15 20:24:09 +08:00
Holger Hans Peter Freyther e9be5175ff nat: Some more input validation... on the paging command. 2010-06-15 20:24:09 +08:00
Holger Hans Peter Freyther 39ee87783f nat: Verify that the configured LACs are unique across the nat 2010-06-15 20:24:09 +08:00
Holger Hans Peter Freyther bae9da49b9 nat: Move paging by lac handling code into the utils file
Moving it here means we can more easily test this code, there is one
behaviour change with the code that we only support paging messages
with one LAC and will silently ignore the others.
2010-06-15 20:24:09 +08:00
Holger Hans Peter Freyther 64622e42ed nat: Fix the lookup of connections to and from the BSC
When sending a message to the MSC in the case of DT1
messages we only have the address of the MSC, so we
need to go with that, otherwise (e.g. in case of a CR, RLC)
we do have the source address and need to patch it.

When forwarding a message to the BSC we do receive
a msg that should contain the patched address, we need
to unpatch it...
2010-06-15 20:24:09 +08:00
Holger Hans Peter Freyther 16a6f70834 nat: Keep track of both sides of the connection
On a CC message we will need to remeber where the source local
reference of the network belonged so we can properly identify
the connection when receiving UDT messages.
2010-06-15 20:24:08 +08:00
Holger Hans Peter Freyther f8048d9f5c nat: Assign the connection inside the new helper function. 2010-06-15 20:24:08 +08:00
Holger Hans Peter Freyther 58a56797a8 nat: Actually add the connection to the SCCP list of active connections
Add the connection to the list of active connections. Otherwise
we are not able to find the connection.
2010-06-15 20:24:08 +08:00
Holger Hans Peter Freyther 0dc569abc2 filter: Move logging level down to INFO 2010-06-15 20:24:08 +08:00
Holger Hans Peter Freyther ea8cbd5e72 nat: Compare the IPA size with the actual size of the data...
One sanity check that was needed in my test case..
2010-06-15 20:24:08 +08:00
Holger Hans Peter Freyther dcf8a7db43 nat: Move creation of the structs to a separate file
This way one can create the bsc_nat structure in unit tests..
2010-06-15 20:24:08 +08:00
Holger Hans Peter Freyther 0ab6babbde nat: Move SCCP patching to a new file, log updates
Move patching and reassigning of messages to a new file which
will making testing this functionality more easy.
2010-06-15 20:24:08 +08:00
Holger Hans Peter Freyther cd895377ca nat: Handle MSC disconnect by closing all NAT connections
When we disconnect from the MSC handle it by pushing the problem
to our connected clients. We will simply close all connections,
reject all new BSC connections and attempt to reconnect to the MSC.
2010-06-15 20:24:08 +08:00
Holger Hans Peter Freyther baf2abe4c4 msc: Create a real interface for BSC MSC and start handling reconnects
Create a BSC<->MSC interface and use it for the BSC MSC IP and the
BSC NAT to reduce code duplication on handling reconnects to the MSC
and cleaning up the local state. The code is only partially tested
and will contain bugs. Currently both the BSC and the NAT will just
exit on connection loss and this way have the current behavior.
2010-06-15 20:24:08 +08:00