aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/osmo-bsc_nat/bsc_nat.c
AgeCommit message (Collapse)AuthorFilesLines
2015-07-01nat: Use RAND_bytes instead of /dev/urandomHolger Hans Peter Freyther1-19/+5
We don't need to consume all the entropy of the kernel but can use libcrypto (OpenSSL) to generate random data. It is not clear if we need to call RAND_load_file but I think we can assume that our Unices have a /dev/urandom. This takes less CPU time, provides good enough entropy (in theory) and leaves some in the kernel entropy pool.
2015-07-01nat: After we identified the bsc check the keyHolger Hans Peter Freyther1-2/+59
We are using the token to find the right bsc_config and then we can use the last_rand of the bsc_connection to calculate the expected result and try to compare it with a time constant(???) memcmp.
2015-07-01bsc: Check for the rand and then generate a resHolger Hans Peter Freyther1-1/+1
Check if the NAT has sent 16 bytes of RAND and if a key has been configured in the system and then generate a result using milenage. The milenage res will be sent and noth the four byte GSM SRES derivation.
2015-07-01nat: Send 16 bytes of rand to the BSC and remember itHolger Hans Peter Freyther1-3/+37
Generate 16 byte of random data to be used for A3A8 by the BSC in the response. We can't know which BSC it is at this point and I don't want to send another message once the token has been received so always send the data with an undefined code. The old BSCs don't parse the message and will happily ignore the RAND. /dev/urandom can give short reads on Linux so loop around it until the bytes have been read from the kernel.
2015-07-01nat: Provide access to /dev/urandom for the codeHolger Hans Peter Freyther1-0/+9
Instead of doing open/read/close all the time, open the FD in the beginning and keep it open. To scare me even more I have seen /dev/urandom actually providing a short read and then blocking but it seems to be the best way to get the random byes we need for authentication. So one should/could run the cheap random generator on the system (e.g. haveged) or deal with the NAT process to block.
2015-07-01bsc/nat: Fix the structure of the identity request messageHolger Hans Peter Freyther1-4/+11
Unfortunately the basic structure of the response is broken. There is a two byte length followed by data. The concept of a 'tag' happens to be the first byte of the data. This means we want to write strlen of the token, then we want to write the NUL and then we need to account for the tag in front. Introduce a flag if the new or old format should be used. This will allow to have new BSCs talk to old NATs without an additional change. In the long run we can clean that up.
2015-07-01nat: Close the connection after we couldn't find the userHolger Hans Peter Freyther1-0/+1
In case the token was not correct, just close the connection. It is not clear that forcing a new TCP connection is going to give us any extra security here. But with the upcoming auth handling it does make sense to have both case look similar.
2015-07-01nat: Factor out the config by token searchHolger Hans Peter Freyther1-19/+13
In the upcoming authentication improvements it is nice to separate the finding of the config from the post-allow handling of it.
2015-07-01nat: Add size check for the payloadHolger Hans Peter Freyther1-1/+1
The msgb will always have these bytes but it is better practice to verify that the message really has space for the two bytes.
2015-05-03filter: Move the con_type into the filter_stateHolger Hans Peter Freyther1-6/+6
2015-05-03filter: Remove nat_sccp_connection from public APIHolger Hans Peter Freyther1-5/+7
2015-05-03filter: More renaming and remove of "NAT" from itHolger Hans Peter Freyther1-3/+3
2015-05-03filter: Move the method definition to the filter moduleHolger Hans Peter Freyther1-0/+1
Move the filter methods to the filter module. This is still only usable for the NAT and the _dt/_cr filter routines need to move back to the bsc_nat in the long run.
2015-04-23nat: Make mode-set patching optionalHolger Hans Peter Freyther1-0/+3
2015-04-07nat: Check the con->imsi for the tracked IMSIHolger Hans Peter Freyther1-2/+2
On DT messages we directly write into the tracked SCCP connection. This means "imsi" will always be NULL at this check. Change the code to use con->imsi Fixes: Coverity CID 1293151
2015-04-05nat: Inform others if an IMSI is rejectedHolger Hans Peter Freyther1-0/+4
In case one wants to monitor the access lists one there is now a trap for the IMSI.
2015-02-08nat: getopt returns "static" data no need to copy itHolger Hans Peter Freyther1-1/+1
I used strdup in case the data would not be valid from after the call to getopt and this creates a potential leak if a user is specifying multiple configuration files. If I depend on the fact that the string is a pointer into the argv[] array I can kill the strdup and fix the unlikely leak. Fixes: Coverity CID 1206578
2014-08-24Use port number #defines for VTY and CTRL portsHarald Welte1-1/+2
.. as defined in libosmocore
2014-08-21move libctrl from openbsc to libosmoctrl (libosmocore.git)Harald Welte1-2/+2
2014-08-20adopt recent IPA related symbol renameHarald Welte1-7/+7
... which happened during recent migration of IPA functionality from libosmo-abis into libosmocore.
2014-05-06nat/bsc: Check proto before calling ipaccess_rcvmsg_baseHolger Hans Peter Freyther1-1/+1
The code in the BSC/NAT called ipaccess_rcvmsg_base without checking if the protocol is IPA. This lead the BSC to respond to SCCP messages with an "ID ACK". From a quick look neither the code of ipaccess_rcvmsg_base in OpenBSC nor the copy of libosmo-abis ever checked the protocol header. So this code has been wrong since initially being created in 2010.
2014-04-03ipa: Be consistent in checking conn->cfg (Coverity)Jacob Erlbeck1-1/+1
Coverity complains about checking connection->cfg in bsc_close_connection() at one place but not at the second. This patch fixes this by adding a check before accessing cfg when generating the 'partial message' log message. Fixes: Coverity CID 1195180 Sponsored-by: On-Waves ehf
2014-04-03nat: Mention the the BSC the SCCP connection was onHolger Hans Peter Freyther1-3/+5
The log message lacked a lot of context. A SCCP connection is created on behalf of a configured BSC. This way we should be able to always list this information.
2014-04-01ipa: Use enhanced ipa_msg_recv_buffered() to cope with partioned IPA messagesJacob Erlbeck1-4/+15
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
2013-09-03nat: Remember the original dest local reference in the parsed structHolger Hans Peter Freyther1-1/+2
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-03nat: Fix the log message of the code in case of an allocation failureHolger Hans Peter Freyther1-1/+1
This wrong log message appears to be the result of copy and paste
2013-09-03bsc_msc: Add a name field to the MSC Connection to differentiate linksHolger Hans Peter Freyther1-3/+10
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-02nat: Attempt to follow the MODULE_METHOD pattern for methodsHolger Hans Peter Freyther1-3/+3
Rename methods to be like bsc_ussd_ACTION.
2013-08-27libmgcp: add enum mgcp_rolePablo Neira Ayuso1-1/+1
This enum indicates if the mgcp is running on the BSC or the BSC-NAT.
2013-07-31nat: Introduce a prefix lookup tree (trie) for number rewritingHolger Hans Peter Freyther1-0/+3
* 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-05nat: The con variable is not assigned at this pointHolger Hans Peter Freyther1-5/+0
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-05-13nat: fix use after free in forward_sccp_to_btsPablo Neira Ayuso1-2/+5
valgrind detected an use after free in the path of forward_sccp_to_bts. The 'parsed' object is referenced from update_con_authorize.
2013-04-16nat: Extract the LAC/CI from the Complete Layer3 InformationHolger Hans Peter Freyther1-2/+3
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-16nat: Rename "struct sccp_connections" to "struct nat_sccp_connection"Holger Hans Peter Freyther1-16/+16
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-16nat: Allow to daemonize the NAT processHolger Hans Peter Freyther1-1/+5
Add handling for the 'D' option
2013-04-16nat: Make it possible to send MGCP messages through the IPA multiplexHolger Hans Peter Freyther1-1/+10
Instead of handling MGCP through the UDP socket, read and write messages through the ipa connection to the MSC.
2013-04-02nat: Fix authentication by-pass using shorter tokensHolger Hans Peter Freyther1-2/+20
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-01-15nat: Fail if the control interface can not be initializedHolger Hans Peter Freyther1-0/+4
2013-01-07nat: Send a CM Service Reject for NAT_CON_TYPE_SSA as wellHolger Hans Peter Freyther1-1/+1
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-07nat: Allow the filter to select the reject causeHolger Hans Peter Freyther1-11/+19
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.
2012-11-12nat: Move the ctrl handling code into a separate fileHolger Hans Peter Freyther1-280/+3
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-09-11nat: Change the ctrl command pathDaniel Willmann1-13/+12
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-11ctrl: Improve error handling if controlif setup failsDaniel Willmann1-1/+10
2012-09-11nat: Add support for traps to the natDaniel Willmann1-0/+7
2012-09-11libctrl: Change controlif_setup so it returns the ctrl handleDaniel Willmann1-2/+4
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
2011-08-22libctrl: Mark the cmd set/get/verify functions staticDaniel Willmann1-3/+3
2011-08-22nat: Fix error in get_next_free_bsc_idDaniel Willmann1-15/+20
The new function now mimcis the behaviour of assign_src_local_reference from bsc_sccp.c
2011-08-19src: port openBSC over libosmo-abis0.9.15Pablo Neira Ayuso1-14/+19
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-07-18misc: Remove the osmocom/core/process.h includeHolger Hans Peter Freyther1-1/+0
The osmo_daemonize moved from process.h to application.h (that is already included), remove the process.h include.
2011-07-13[bsc-nat] ctrlif: use llist_entry() macro and fix overly-long linesHarald Welte1-4/+9