Commit Graph

49 Commits

Author SHA1 Message Date
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 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
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 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 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 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 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 bdf764a025 nat: Allow the filter to select the reject cause
In preparation for another kind of black-list allow the filter code
to decide how the connection should be rejected. Introduce a new struct
that will carry the reject causes for certain operations.
2013-01-07 15:02:34 +01:00
Holger Hans Peter Freyther 98da544992 nat: Move the ctrl handling code into a separate file
Move to the control command handling out of the main file into
a dedicated module. There are still some calls embedded into the
main code but it will be moved soon.
2012-11-12 10:49:10 +01:00
Daniel Willmann 6dc6910b79 nat: Change the ctrl command path
The commands net.<netid>.bsc.<bscid>.* are now forwarded to the
appropriate osmo-bsc. <netid> for now is just 0. <bscid> is not the LAC
anymore (since that could be ambiguous), but instead the number as
configured in bsc-nat.cfg
2012-09-11 16:20:46 +02:00
Daniel Willmann 5e95f45af0 ctrl: Improve error handling if controlif setup fails 2012-09-11 15:20:55 +02:00
Daniel Willmann d79da3baac nat: Add support for traps to the nat 2012-09-11 13:09:03 +02:00
Daniel Willmann 6fc4a98fc5 libctrl: Change controlif_setup so it returns the ctrl handle
nat: Catch up with controlif_setup API change
We now save a control handle reference in the nat
osmo-bsc: Catch up with controlif_setup API change
We now save a control handle reference in the gsm network
2012-09-11 12:52:23 +02:00
Daniel Willmann 5763093285 libctrl: Mark the cmd set/get/verify functions static 2011-08-22 23:45:56 +02:00
Daniel Willmann e54db171ee nat: Fix error in get_next_free_bsc_id
The new function now mimcis the behaviour of
assign_src_local_reference from bsc_sccp.c
2011-08-22 23:45:56 +02:00
Pablo Neira Ayuso ed5cacb240 src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.

The main changes are:

- The directory libabis/ has been removed as it now lives in
  libosmo-abis.

- new configuration file format for nanoBTS and HSL femto, we
  need to define the virtual e1_line and attach it to the OML
  link.

- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
  BS11 and rbs2000) now use the new libosmo-abis framework.

- use r232 input driver available in libosmo-abis for bs11_config.

- use ipa_msg_recv instead of old ipaccess_read_msg function.

- delete definition of gsm_e1_subslot and input_signal_data.
  These structures now lives in libosmo-abis.

Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.

This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:

- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node

This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-19 22:38:35 +02:00
Holger Hans Peter Freyther 95fd72b9f7 misc: Remove the osmocom/core/process.h include
The osmo_daemonize moved from process.h to application.h (that
is already included), remove the process.h include.
2011-07-18 10:40:13 +02:00
Harald Welte 7017fa7c9d [bsc-nat] ctrlif: use llist_entry() macro and fix overly-long lines 2011-07-13 14:53:16 +02:00
Harald Welte f071e16f23 [bsc-nat] ctrlif: save ourselves one level of indentation 2011-07-13 14:53:16 +02:00
Harald Welte 6552047d44 [bsc-nat] ctrlif: use the 'err' label consistently
and propagate -ENOMEM in case we have no memory
2011-07-13 14:53:16 +02:00
Harald Welte f8e49dd187 bsc-nat: ctrlif: split out handle_ctrlif_msg() from ipaccess_bsc_read_cb()
We want to avoid spaghetti code by creating smaller functions,
which also helps with the line lengths / indentation levels.
2011-07-13 14:53:16 +02:00
Harald Welte 1b5e5c3727 controlif: declare controlif_setup() in control_cmd.h
this avoids us to copy+paste external declarations over all 'main'
files.
2011-07-13 14:53:16 +02:00
Daniel Willmann a86bc39cc9 nat: Use libctrl and add command forwarding to osmo-bsc
Passes commands beginning with "bsc.<num>" to the bsc that is
responsible for LAC <num>.
2011-07-13 14:07:11 +02:00
Holger Hans Peter Freyther df8e6e9e4a nat: Prepare to patch more than the CC Setup message
Refactor the code to allow having different handlers. The goal
is to be able to patch some SMS messages too.
2011-06-01 20:41:30 +02:00
Holger Hans Peter Freyther 67cd75f9fa misc: Use the osmo_init code for signals and logging
Use the libosmocore code to ignore certain signals by
default (e.g. SIGHUP, SIGPIPE) and use the new code to
create a default stderr logging target and initialize
it properly.
2011-05-12 16:11:14 +02:00
Pablo Neira Ayuso c0d17f2266 src: use namespace prefix osmo_* for misc utils
Summary of changes:

s/bcd2char/osmo_bcd2char/g
s/char2bcd/osmo_char2bcd/g
s/hexparse/osmo_hexparse/g
s/hexdump/osmo_hexdump/g
s/hexdump_nospc/osmo_hexdump_nospc/g
s/ubit_dump/osmo_ubit_dump/g
s/static_assert/osmo_static_assert/g
2011-05-07 12:58:59 +02:00
Pablo Neira Ayuso dfb342c19a src: use namespace prefix osmo_counter*
Summary of changes:

s/struct counter/struct osmo_counter/g
s/counter_inc/osmo_counter_inc/g
s/counter_get/osmo_counter_get/g
s/counter_reset/osmo_counter_reset/g
s/counter_alloc/osmo_counter_alloc/g
s/counter_free/osmo_counter_free
2011-05-06 12:14:16 +02:00
Pablo Neira Ayuso e1273b1f3c src: use namespace prefix osmo_wqueue*
Summary of changes:

s/struct write_queue/struct osmo_wqueue/g
s/write_queue_init/osmo_wqueue_init/g
s/write_queue_clear/osmo_wqueue_clear/g
s/write_queue_enqueue/osmo_wqueue_enqueue/g
s/write_queue_bfd_cb/osmo_wqueue_bfd_cb/g
2011-05-06 12:12:49 +02:00
Pablo Neira Ayuso 4db9299286 src: use namespace prefix osmo_fd* and osmo_select*
Summary of changes:

s/struct bsc_fd/struct osmo_fd/g
s/bsc_register_fd/osmo_fd_register/g
s/bsc_unregister_fd/osmo_fd_unregister/g
s/bsc_select_main/osmo_select_main/g
2011-05-06 12:11:23 +02:00
Pablo Neira Ayuso bf540cb7c3 src: use namespace prefix osmo_timer* for timer functions
Summary of changes:

s/struct timer_list/struct osmo_timer_list/g
s/bsc_add_timer/osmo_timer_add/g
s/bsc_schedule_timer/osmo_timer_schedule/g
s/bsc_del_timer/osmo_timer_del/g
s/bsc_timer_pending/osmo_timer_pending/g
s/bsc_nearest_timer/osmo_timers_nearest/g
s/bsc_prepare_timers/osmo_timers_prepare/g
s/bsc_update_timers/osmo_timers_update/g
s/bsc_timer_check/osmo_timers_check/g
2011-05-06 12:11:06 +02:00
Holger Hans Peter Freyther 0dc36f1e3a nat: Keep track of the error message. 2011-05-04 11:34:44 +02:00
Holger Hans Peter Freyther 1ffe98c175 nat: Rewrite the paging handling.
The current code tries to find _one_ bsc for a paging message
and then continues. The new code will try to find multiple BSCs
for each LAC. This is done in preparation of having two BSCs
handle the same LAC. This code right now is O(m*n) but it will
be worse once paging groups are landed.
The code to test the function was reduced to just test the lac
lookup code as the other part can not be tested in a standalone
setup anymore.
2011-05-02 19:19:15 +02:00
Holger Hans Peter Freyther e188010512 bsc: Allow to have a list of MSCs/MUXs to connect to
Be able to configure a list of destinations (duplicates allowed)
that will be tried in a round robin fashion. The change is in
the bsc_msc_connection to operate on a list. We achieve the
round robin nature with the same trick used in the paging code
to delete and append the current entry. The nat code was updated
to compile but one can only configure one destination.
2011-04-26 09:36:19 +02:00
Holger Hans Peter Freyther de2b860dff nat: Introduce a block on the NAT to slowly get rid of BSCs
For restarting the NAT we can now block it, it will not accept
new connections and for existing connections it will attempt
to drop them over time. A blocked NAT will end up with no BSC
connections left and then can be safely restarted.
2011-04-26 09:33:47 +02:00
Holger Hans Peter Freyther 0b03f16cdb ussd: Ignore connection release/clear from the MSC
In case this is a local USSD connection we will ignore
the clear command and respond with a RLC to any RLSD but
will never forward that to the BSC. This way the external
USSD is fully in charge of the connection.
There are theoretical issues if there are multiple transactions
on the same SCCP Connection but this can not be solved properly
right now.
2011-04-21 17:13:51 +02:00
Holger Hans Peter Freyther 123bc32834 ussd: Keep track of used TIs for USSD and forward messages
Keep track of the used transaction identifier and always forward
messages to the USSD provider. E.g. this can be used to have a
dialogue going. Right now it is still possible that the MSC will
close down the connection.
2011-04-19 13:06:47 +02:00
Holger Hans Peter Freyther 91b9a45be4 nat: Inform the USSD Provider about lost connections 2011-04-18 17:32:40 +02:00
Holger Hans Peter Freyther e5d324981d nat: Remove magic numbers, use enum values for conn classification
Remove the usage of 0, 1, 2 and start using enum values. We can
still assume con_local is a number.
2011-04-18 17:32:38 +02:00
Holger Hans Peter Freyther 5cde92cb0e nat: And out the skip_indicator/transaction id from the gsm48 header
We need to and out the protocol discriminator as call control
might have use transactions. This has only failed for the USSD
filter so far as this must deal with transactions.
2011-04-13 18:56:13 +02:00
Pablo Neira Ayuso ca05d432d7 src: more robust ipaccess_idtag_parse()
Now ipaccess_idtag_parse() returns -EINVAL instead of -1. We also
check for the return value of this function in every invocation to
skip further processing in case of messages with malformed TLVs.

This idea was suggested by Zecke.
2011-04-12 21:50:46 +02:00
Holger Hans Peter Freyther 7d73642d0e nat: Fix the call to make_sock and pass a 0 priv_nr and the nat as data 2011-04-07 22:14:58 +02:00
Holger Hans Peter Freyther ef38e85542 nat: Remember if the MSC accepted the connection on principle
For the USSD module we only want to handle requests that are
legitimate. This is achieved by looking for the CM Service Accept
or the BSSAP CIPHER MODE COMMAND.
2011-04-06 11:29:46 +02:00
Harald Welte d36ff76f9d Fix build of bsc-nat and GPRS code after include path change
The last patch changed the osmocore include paths, this fixes some build
problems caused by it
2011-03-23 18:33:26 +01:00
Pablo Neira Ayuso 136f453dd2 src: use new library libosmogsm and new path to headers in libosmocore
libosmogsm is a new library that is distributed in the libosmocore.
Now, openbsc depends on it. This patch gets openbsc with this
change.

This patch also rewrites all include path to the new
osmocom/[gsm|core]

Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
2011-03-23 18:17:56 +01:00
Pablo Neira Ayuso 739a566961 bsc: change bsc_vty_init to take logging categories as parameter
This change is required to finish the integration of the VTY and
the per-application logging categories that provides:

"vty: integration with logging framework"

in libosmocore.

It has been tested with osmo-nitb. The other just compiled tested.
2011-03-19 18:50:38 -03:00
Harald Welte a17faf8512 Rename bsc_nat -> osmo-bsc_nat and bsc_mgcp -> osmo-bsc_mgcp
This now enforces a unique structure: All of our main daemon
programs start with an "osmo-" prefix.
2011-03-03 23:36:48 +01:00