Commit Graph

139 Commits

Author SHA1 Message Date
Jacob Erlbeck e827812051 ipa: Use enhanced ipa_msg_recv_buffered() to cope with partioned IPA messages
The old ipa_msg_recv() implementation didn't support partial receive,
so IPA connections got disconnected when this happened.

This patch adds the handling of the temporary message buffers and uses
ipa_msg_recv_buffered().

It has been successfully tested by jerlbeck with osmo-nitb and
osmo-bsc.

Ticket: OW#768
Sponsored-by: On-Waves ehf
2014-04-01 13:40:59 +02:00
Holger Hans Peter Freyther 49f9e5b6b4 ctrl: Move the lookup into a separate file in preparation for GPRS
For GPRS the look-up via bts/trx does not make any sense and would
introduce bad depdencies for the SGSN. Move the look-up code to a
new file and introduce new setup methods.
2014-03-23 16:25:16 +01:00
Holger Hans Peter Freyther 472f3bd198 nat: Introduce command to remove an access-list-name 2014-03-04 20:39:38 +01:00
Holger Hans Peter Freyther bc3780a73f nat: Implement setting the access-control-name through CTRL interface
For operation we want to switch the access-list of a BSC at runtime
in a programatic way.

Sponsored-by: On-Waves ehf
2014-03-04 20:39:27 +01:00
Holger Hans Peter Freyther 6419018e68 nat: Make the access-list deny cause configurable
Add two optional arguments to the imsi-deny rule
for the reject cause and verify that it is saved
out.
2014-01-20 10:14:05 +01:00
Holger Hans Peter Freyther 415cd2eebb nat: Introduce reject cause to bsc_nat_acc_lst_entry
The filtering architecture already allowed to specify a reject
reason but this has not been used for the access-lists. Extend
the access-list to include a reject reason and extend the test
case to honor it.
2014-01-20 10:13:36 +01:00
Jacob Erlbeck 3dff27d38d mgcp/nat: Take payload type from SDP data
So far the payload type used in RTP streams has been taken from the
trunk configuration in NAT mode.

This patch changes the implementation to use the payload type
announced in the SDP part of MGCP messages and responses. SDP
descriptions more than one m=audio line are not yet supported
properly (always the last one is taken).

Ticket: OW#466
Sponsored-by: On-Waves ehf
2013-12-05 10:28:48 +01:00
Jacob Erlbeck 36722e13da vty: Use vty_install_default() instead of bsc_install_default()
Remove ournode_exit_cmd, ournode_end_cmd, and bsc_install_default()
since this functionality is provided by the current libosmocore.

Replace calls to bsc_install_default() by call to
vty_install_default() with the following semantic patch:

    @rule1@
    expression N;
    @@
    - bsc_install_default(N);
    + vty_install_default(N);

Ticket: OW#952
Sponsored-by: On-Waves ehf
2013-10-30 15:19:00 +01:00
Holger Hans Peter Freyther 1b9902c128 nat: Remember the original dest local reference in the parsed struct
In case of the RLSD coming from the MSC we are patching the address
in-situ but for local calls set con = NULL. We then answered the RLSD
with the wrong reference and the MSC kept on trying.
2013-09-03 15:04:43 +02:00
Holger Hans Peter Freyther ff98b3cffa nat: Fix the log message of the code in case of an allocation failure
This wrong log message appears to be the result of copy and paste
2013-09-03 15:04:31 +02:00
Holger Hans Peter Freyther c1a8687cb8 bsc_msc: Add a name field to the MSC Connection to differentiate links
Assign a static name to a MSC Connection and use it. In case there
are multiple connections we can now more easily identify them.

This is only used for the NAT right now, the BSC could start to
name the various MSC connections too.
2013-09-03 15:02:46 +02:00
Jacob Erlbeck 4c9dff5d8e vty: Rename 'mgcp-through-msc-ipa' command to 'use-msc-ipa-for-mgcp'
Currently the 'mgcp' command fails in the 'config-nat' node, because
it get confused with 'mgcp-through-msc-ipa' which is executed
instead because of the prefix based command selection. Thus the
latter command is renamed by this patch to avoid the common prefix.

The workaround in the test suite is removed.
2013-09-02 20:25:51 +02:00
Jacob Erlbeck 0ae92a950a vty: Use generic 'end' and 'exit' commands
Add bsc_install_default() and replace all install_default()

This patch adds bsc_install_default() which calls install_default()
and add 'exit' and 'end'. All other calls to install_default() are
replaced by calls to bsc_install_default().

Since 'exit' and 'end' are now added automatically to each node, the
explicit registrations of these commands are removed by this patch,
too.

The related tests succeed now without work-arounds (except for the
'config' node itself which is part of libosmocore).
2013-09-02 20:25:35 +02:00
Holger Hans Peter Freyther 6fcc3a9e8a nat: Attempt to follow the MODULE_METHOD pattern for methods
Rename methods to be like bsc_ussd_ACTION.
2013-09-02 11:11:16 +02:00
Holger Hans Peter Freyther 5741256703 nat: Use bsc_nat_msc_is_connected instead of accessing it directly 2013-09-02 11:00:09 +02:00
Pablo Neira Ayuso 326b5d80b3 libmgcp: add enum mgcp_role
This enum indicates if the mgcp is running on the BSC or the BSC-NAT.
2013-08-27 12:21:43 +02:00
Jacob Erlbeck 6cb2cccc8d nat/ussd: Add 'show ussd-connection' vty command
This command returns the current state of the connection to the USSD
side channel provider. It shows whether a provider has been connected
and authorized or not.

Fixes: OW#953
2013-08-14 12:07:07 +02:00
Holger Hans Peter Freyther 27876a2df0 nat: Fix potential memory leak when reading a message
Spotted while going through the code with Jacob. We could have
leaked the msgb in case of error.
2013-08-13 14:48:44 +02:00
Holger Hans Peter Freyther 9962151230 nat: Misc changes spotted while going through the file with Jacob
* Spell Configure correctly
* Use %s and VTY_NEWLINE instead of \n
2013-08-13 11:36:33 +02:00
Holger Hans Peter Freyther 52f705eaab nat: Use the DCC region for number rewriting and increase debug output 2013-07-31 16:36:40 +02:00
Holger Hans Peter Freyther 67e423c256 nat: Implement a post-routing for the NAT software
* The post-routing is applied after the first re-writing. To do this
  the new number is copied back into the called data structure.

* Add a testcase that goes from 0172 to 0049 and then back to 0049
  using the post rule with a table lookup.
2013-07-31 16:36:40 +02:00
Holger Hans Peter Freyther ddf191eafc nat: Allow to use the prefix lookup to rewrite numbers
* Increase the rewritten rule to five digits (this is the easiest
  for the unit test). This will add another 40kb to the runtime size.

* Create a unit test that tests adding and removing the prefix rules.

* Use the regexp match to replace from one package
2013-07-31 16:36:40 +02:00
Holger Hans Peter Freyther 85d3b34ed2 nat: Introduce a prefix lookup tree (trie) for number rewriting
* It is a trie. The max depth of the trie is the length of the
longest prefix. The lookup is O(lookuped_prefix), but as the prefix
length is limited, the lookup time is constant.

* Each node can hold the entire prefix, has place for the rewrite
  rule with up to three digits.

* A trie with 20k entries will take about 3MB ram.

* Filling the trie 100 times takes ~800ms on my i7 laptop

* 10.000.000 lookups take 315ms.. (for the same prefix).

* 93/99 lines are tested, 6/6 functions are tested, 49 of 54 branches
  are tested. Only memory allocation failures are not covered

* A late addition is to handle the '+' sign and to increase the number
  of chars in the rewrite prefix. The timing/line coverage has not
  been updated after this change.
2013-07-31 16:36:40 +02:00
Holger Hans Peter Freyther b718ad397e nat: Add a no number-rewrite command and call it through a VTY test
The test is just testing the invocation but does not verify that
the side effect of this call. It is good enought for now.
2013-07-31 16:36:13 +02:00
Holger Hans Peter Freyther 096dc3a466 nat: The con variable is not assigned at this point
Coverity pointed out that this code is logically dead. Quickly
judging the code we will forward the RSLD message anyway. Remove
the code for now and next time I work on the NAT/USSD bridge I
will have a look at the flow of the RLSD messages.

Fixes: Coverity CID 1042327
2013-07-05 08:22:03 +02:00
Holger Hans Peter Freyther 7346081ba3 nat: number could point to an address on the stack that can be reused
The number = int_number assignment will make the number point to
the stack and as the int_number goes out of scope at the end of
the if statement other code could re-use this stack for other memory.

Fixes: Coverity CID 1042325
2013-07-05 07:50:30 +02:00
Holger Hans Peter Freyther 9bec10ecd3 nat: Address coverity warning about uninitialized addr
Use memset on the addr to initialize the entire structure.

Fixes: Coverity CID 1042324
2013-07-05 07:48:04 +02:00
Holger Hans Peter Freyther b0b8a34dd5 nat: Please coverity and initialize the saveptr to NULL
Coverity complains about the saveptr used in the strtok_r. This
is not a bug because we pass a string as part of the first call
to strtok_r but it is easier to just initialize it.

Addresses: Coverity CID 1042323
2013-07-05 07:45:08 +02:00
Holger Hans Peter Freyther a164d5291e nat: Fix compiler warning and cast uint16_t to uint8_t 2013-07-03 16:18:37 +02:00
Alexander Huemer a1c09a401d Makefile.am: Use AM_CPPFLAGS
Since automake 1.13 INCLUDES is depricates and causes a warning
2013-06-12 09:16:27 +02:00
Pablo Neira Ayuso 0a244b40c9 nat: fix use after free in forward_sccp_to_bts
valgrind detected an use after free in the path of forward_sccp_to_bts.
The 'parsed' object is referenced from update_con_authorize.
2013-05-13 01:13:27 +02:00
Holger Hans Peter Freyther 7a0010bdd4 nat: Include LAC/CI as TV values at the end of the 'status' message
Extend the status message and send LAC/CI as part of the status
message. It is using TV to allow sending more fields in the feature.
We only need to encode the data and this is why there is no tlv
description yet.
2013-04-29 20:40:44 +02:00
Holger Hans Peter Freyther 2bc90c274d nat: Use memcmp for the token on the USSD interface as well
This is similar to the token on the A-interface. There are no more
token based authentication in the NAT.
2013-04-22 10:54:32 +02:00
Holger Hans Peter Freyther ab22335378 nat: Move the callstats to a new header file due sccp usage
The bsc_nat.h is included by common_vty.c so we may not used
sccp_types.h in the bsc_nat.h header file. Move the callstats
to a new file and include it where it is needed.
2013-04-22 09:07:39 +02:00
Holger Hans Peter Freyther b2b291d3ef nat: Extract the LAC/CI from the Complete Layer3 Information
Find the Cell Identifier from the Complete Layer3 Information and
store it for future reference. We could begin to verify that the
LAC/CI used really belongs to the BSC.
2013-04-16 14:14:17 +02:00
Holger Hans Peter Freyther c279e39c12 nat: Rename "struct sccp_connections" to "struct nat_sccp_connection"
The name sccp_connection is used in the osmo-sccp code, sccp_connections
was used in the NAT for tracking a sccp_connection. Rename it so it is
obvious that the struct belongs to the nat.

The rename was done with sed:
$ sed -i s,"struct sccp_connections","struct nat_sccp_connection",g \
		include/openbsc/*.h src/osmo-bsc_nat/* tests/*/*
2013-04-16 09:53:13 +02:00
Holger Hans Peter Freyther dbd9449a16 nat: Allow to re-write international numbers in the CC Setup messages
Prepend the international number with a '+' and then do the normal
re-writing on it. There are a couple of ways to handle this:

	\+([0-9]), \+[0-9][0-9]([0-9]), \+49([0-9])

Add a test case for the international re-write based on an already
internationalized number.
2013-04-16 09:20:06 +02:00
Holger Hans Peter Freyther 27b6184225 nat: Allow to daemonize the NAT process
Add handling for the 'D' option
2013-04-16 09:20:00 +02:00
Holger Hans Peter Freyther ac04d8d55e nat: Name the variable more properly and begin with net.1.bsc.%d
We can identify the NAT and BSC given the types of the variable,
no need to put them into the value itself.
2013-04-16 09:17:21 +02:00
Holger Hans Peter Freyther 7d7054eafa nat: Include the sccp_src_ref and sccp_dst_ref for this call
This can help with some post analysis for failed calls and helps
finding the connection in the pcap trace.
2013-04-16 09:17:21 +02:00
Holger Hans Peter Freyther 7c831ecd19 nat: Do not allow the amount of pending responses to grow infinitely
Limit the amount of pending DLCX responses to three times the amount
of available endpoints. Currently all MGCP messages are sent and handled
in sequence.
2013-04-16 09:17:21 +02:00
Holger Hans Peter Freyther 931ad6ac33 nat: Reword the log messages as this is normal operation
The bsc_mgcp_dlcx method is called from the mgcp policy callback
but also from inside the nat core when the SCCP connection is going
away.
2013-04-16 09:17:21 +02:00
Holger Hans Peter Freyther 462b7d7158 nat: We want the remote to respond to our DLCX request
We want to send a TRAP with the MGCP statistics from the NAT and
the connected BSC. The BSC endpoint can be either released because
of a DLCX from the MGCP CallAgent or the SCCP Connection release on
the A-link.

This is why we need to queue the statistics when the deleting the
endpoint on the BSC. The processing is continued once the response
arrives. This code assumes that the response of the DLCX will be sent
by the remote side. The current amount of outstanding responses can be
seen on the VTY. This assumption is based on the fact that the BSC has
already responded to the CRCX and maybe to the MDCX.

The MGCP RFC is bended to prefix the transaction identifier with "nat-"
to easily detect the response and hand it to the handler. This will
then parse the response and generate the TRAP. The current version is
v1. We assume that the transaction space is big enough and we will
not re-assign the transaction identifier too early.
2013-04-16 09:17:21 +02:00
Holger Hans Peter Freyther c327187259 nat: Make it possible to send MGCP messages through the IPA multiplex
Instead of handling MGCP through the UDP socket, read and write messages
through the ipa connection to the MSC.
2013-04-16 09:17:21 +02:00
Holger Hans Peter Freyther 77956aa034 nat: Move all methods sending a response to the callagent to a single place
For testing it can be nice to handle MGCP messages through the IPA
protocol. Prepare the code to send the messages through other means.
2013-04-16 09:17:21 +02:00
Holger Hans Peter Freyther 6de9d0ba35 nat: Address the FIXME and send the MDCX down to the BSC 2013-04-16 09:17:21 +02:00
Holger Hans Peter Freyther d34adb2f9f nat: Fix authentication by-pass using shorter tokens
The token was compared with the configured one but only up to a
user supplied length. Compare the token sizes and then use memcmp
for the actual comparison to make sure to compare the right ammount
of characters.

There is no unit-test but there should be one.
2013-04-02 10:10:21 +02:00
Holger Hans Peter Freyther 036b25fb7f nat: Fail if the control interface can not be initialized 2013-01-15 13:48:18 +01:00
Holger Hans Peter Freyther aa191adce6 nat: Send a CM Service Reject for NAT_CON_TYPE_SSA as well
For USSD we remember that it is a supplementary service but this
means we sent no CM Service Reject down to the subscriber. Treat
NAT_CON_TYPE_CM_SERV_REQ and NAT_CON_TYPE_SSA the same and send
a cm service reject.
2013-01-07 15:02:34 +01:00
Holger Hans Peter Freyther 1f8276e588 nat: Introduce a global IMSI barr list using red-black trees 2013-01-07 15:02:34 +01:00