aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/osmo-bsc_nat
AgeCommit message (Collapse)AuthorFilesLines
2015-07-01nat: Use RAND_bytes instead of /dev/urandomHolger Hans Peter Freyther2-21/+7
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 Freyther2-4/+89
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 Freyther2-19/+31
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 Freyther5-24/+24
2015-05-03filter: Remove bsc_connection from the filter APIHolger Hans Peter Freyther1-2/+16
Remove the last occurence of NAT datastructures in the filtering module and add the ctx to the filter request structure.
2015-05-03filter: Remove nat_sccp_connection from public APIHolger Hans Peter Freyther3-13/+16
2015-05-03filter: Separate SCCP/BSSAP extraction and gsm48 codeHolger Hans Peter Freyther2-1/+106
For the BSC we will have the gsm48_hdr and don't need to find data within SCCP. For legacy reasons we need to initialize con_type, imsi, reject causes early on and need to do the same in the filter method.
2015-05-03filter: More renaming and remove of "NAT" from itHolger Hans Peter Freyther2-8/+8
2015-05-03filter: Remove nat from bsc_nat_acc_lst and replace with msgHolger Hans Peter Freyther4-13/+13
2015-05-03filter: Cease out "struct bsc_nat" from the APIHolger Hans Peter Freyther2-2/+2
This means we need to require a talloc context and simply operate on the list. I had considered creating a structure to hold the list head but I didn't find any other members so omitted it for now.
2015-05-03filter: Move VTY code into the filter moduleHolger Hans Peter Freyther1-110/+2
2015-05-03filter: Move the access list management aroundHolger Hans Peter Freyther2-88/+1
2015-05-03filter: Move the method definition to the filter moduleHolger Hans Peter Freyther4-0/+4
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-05-03filter: Move the gsm 04.08 filter to a common placeHolger Hans Peter Freyther2-444/+2
For customer requirements we want to be able to do filtering on the BSC as well. The same messages need to be scanned and the same access-lists will be looked at. In the future we might even split traffic based on the IMSI. Begin with moving the code to a new top level directory and then renaming and removing the nat dependency.
2015-04-23nat: Make mode-set patching optionalHolger Hans Peter Freyther3-4/+32
2015-04-10nitb: Fix IMSI/IMEI buffer handling (Coverity)Jacob Erlbeck1-1/+1
Currently the handling of the buffers is not done consistently. Some code assumes that the whole buffer may be used to store the string while at other places, the last buffer byte is left untouched in the assumption that it contains a terminating NUL-character. The latter is the correct behaviour. This commit changes to code to not touch the last byte in the buffers and to rely on the last byte being NUL. So the maximum IMSI/IMEI length is GSM_IMSI_LENGTH-1/GSM_IMEI_LENGTH-1. For information: We assume that we allocate the structure with talloc_zero. This means we have NULed the entire imsi array and then only write sizeof - 1 characters to it. So the last byte remains NUL. Fixes: Coverity CID 1206568, 1206567 Sponsored-by: On-Waves ehf
2015-04-07nat: Fix timeslot range in 'show bsc mgcp' VTY commandJacob Erlbeck1-1/+1
Currently the inner loop in show_bsc_mgcp iterates of the timeslot interval [0, 31]. Timeslot 0 is not valid, which causes mgcp_timeslot_to_endpoint to generate a corresponding warning and to return an invalid endp value. That value causes an out-of-bound read access, possibly hitting unallocated memory. This patch fixes the loop range by starting with timeslot 1. Note that this does not prevent mgcp_timeslot_to_endpoint from returning an invalid endpoint index when called with arguments not within its domain. Addresses: <000b> ../../include/openbsc/mgcp.h:250 Timeslot should not be 0 [...] vty=0xb4203db0, argc=1, argv=0xbfffebb0) at bsc_nat_vty.c:256 max = 1 con = 0xb4a004f0 i = 0 j = 0 [...] ==15700== ERROR: AddressSanitizer: heap-use-after-free on address 0xb520be4f at pc 0x8062a42 bp 0xbfffeb18 sp 0xbfffeb0c Sponsored-by: On-Waves ehf
2015-04-07nat: Check for the access list in set command as wellHolger Hans Peter Freyther1-1/+8
I omitted the check as this was already done by the verify function for this command. Please Coverity and do the check again even if it is not necessary. I begin to doubt the usage of a "dedicated" verify method as well. Silences: Coverity CID 1293150
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: Add ctrl command to save the configurationHolger Hans Peter Freyther1-0/+31
$ bsc_control.py -d localhost -p 4250 -s net.0.save-configuration 0
2015-04-05nat: Add a ctrl command to add to an existing ACC listHolger Hans Peter Freyther1-0/+62
We want to have a program add entries to the allow list this can be done using: $ bsc_control.py -d localhost -p 4250 -s net.0.add.allow.access-list.NAME "^IMSI$"
2015-04-05nat: Inform others if an IMSI is rejectedHolger Hans Peter Freyther2-0/+22
In case one wants to monitor the access lists one there is now a trap for the IMSI.
2015-04-05nat: The reject cause of "-1" has failure meaning, change itHolger Hans Peter Freyther1-1/+1
bsc_stat_reject is treating -1 as parsing failure but for the global barring. Change it to another return value so it is not counted as parsing failure.
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
2015-01-21osmux: Initialize the socket only onceHolger Hans Peter Freyther1-3/+5
The per BSC code didn't guard against the init already having been executed. This lead to: Adding a osmo_fd that is already in the list. <000b> bsc_nat_vty.c:1200 Setting up OSMUX socket So a new socket got created and the old one leaked. Luckily Linux appears to allow to bind multiple times so we were able to just read from the new one. Use the same guard that is used on the MGCP MGW. Re-order the log message to say "Setting up" before we actually do that. I manually verified that osmux_init is called at most once. The log message was spotted by Roch
2014-11-11bsc: Move gsm_subscriber_base.c to libcommonJacob Erlbeck1-1/+2
Since it is planned to use struct gsm_subscriber to manage subscriber data in the SGSN, this file which contains the generic subscriber related methods is moved to libcommon. Sponsored-by: On-Waves ehf
2014-09-02mgcp: Move the "codec" params to a structHolger Hans Peter Freyther1-2/+2
We might be offered multiple codecs by the remote and need to switch between them once we receive data. Do this by moving it to a struct so we can separate between proposed and current codec. In SDP we can have multiple codecs but a global ptime. The current code doesn't separate that clearly instead we write it to the main codec.
2014-08-29nat: Introduce a config free for the test and fix valgrind issuesHolger Hans Peter Freyther1-0/+28
The talloc_free on the nat lead to the freeing of the bsc_config which lead to freeing of the rate_ctr_group. The rate_ctr_group remained in a global list and the next creation of a bsc_config would access dead memory. Fix it. The free routine is only meant to be used by the test, for the real nat we would need to make sure that all connections and other state that refers to the cfg is removed/closed first. Fix various memleaks in the test while we are at it. There are still some to fix. ==7195== Invalid write of size 4 ==7195== at 0x4043171: rate_ctr_group_alloc (linuxlist.h:65) ==7195== by 0x804D893: bsc_config_alloc (bsc_nat_utils.c:174) ==7195== by 0x804B5D2: main (bsc_nat_test.c:954) ==7195== Address 0x4311cbc is 52 bytes inside a block of size 208 free'd ==7195== at 0x4029D28: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==7195== by 0x4048D98: _talloc_free (talloc.c:609) ==7195== by 0x4052806: talloc_free (talloc.c:578) ==7195== by 0x804B58A: main (bsc_nat_test.c:940)
2014-08-29nat: Remove the entry from the list before we destroy itHolger Hans Peter Freyther1-0/+1
2014-08-29nat: Fix compiler warning about unknown prototypeHolger Hans Peter Freyther1-0/+1
bsc_nat_ctrl.c: In function ‘set_net_cfg_cmd’: bsc_nat_ctrl.c:360:3: warning: implicit declaration of function ‘bsc_replace_string’ [-Wimplicit-function-declaration] bsc_replace_string(bsc_cfg, &bsc_cfg->acc_lst_name, cmd->value); ^
2014-08-28osmux: remove redundant log message when bsc doesn't want to use OsmuxPablo Neira Ayuso1-3/+1
Remove redundant information log message: <000b> bsc_mgcp_utils.c:647 BSC doesn't want to use Osmux, failing back to RTP <000b> bsc_mgcp_utils.c:669 bsc didn't accept to use Osmux (cid=0) One single log message is just fine. The error path already indicates the precise reason not to accept the request to use Osmux.
2014-08-28osmux: add osmux circuit ID management and resolve NAT problemsPablo Neira Ayuso1-21/+75
This patch includes several osmux fixes that are interdependent: 1) This adds Osmux circuit ID, this is allocated from the bsc-nat. This announces the circuit ID in the CRCX MGCP message. This aims to resolve the lack of uniqueness due to the use of endp->ci, which is local to the bsc. This ID is notified via X-Osmux: NUM where NUM is the osmux circuit ID. 2) The dummy load routines are now used to setup osmux both in bsc and bsc-nat to resolve source port NAT issues as suggested by Holger. The source port that is used from the bsc is not known until the first voice message is sent to the bsc-nat, therefore enabling osmux from the MGCP plane breaks when a different source port is used. 3) Add refcnt to struct osmux_handle, several endpoints can be using the same input RTP osmux handle to perform the batching. Remove it from the osmux handle list once nobody is using it anymore to clean it up. 4) Add a simple Osmux state-machine with three states. The initial state is disabled, then if the bsc-nat requests Osmux, both sides enters activating. The final enabled state is reached once the bsc-nat sees the dummy load message that tells what source port is used by the bsc. 5) The osmux input handle (which transforms RTP messages to one Osmux batch) is now permanently attached to the endpoint when Osmux is set up from the dummy load path, so we skip a lookup for each message. This simplifies osmux_xfrm_to_osmux(). After this patch, the workflow to setup Osmux is the following: bsc bsc-nat | | |<------ CRCX ----------| | X-Osmux: 3 | (where 3 is the Osmux circuit ID | | that the bsc-nat has allocated) |------- resp --------->| | X-Osmux: 3 | (the bsc confirm that it can | | use Osmux). . . | | setup osmux |----- dummy load ----->| setup osmux | Osmux CID: 3 | In two steps: 1st) Allocate the Osmux Circuit ID (CID): The bsc-nat allocates an unique Osmux CID that is notified to the bsc through the 'X-Osmux:' extension. The bsc-nat annotates this circuit ID in the endpoint object. The bsc replies back with the 'X-Osmux:' to confirm that it agrees to use Osmux. If the bsc doesn't want to use Osmux, it doesn't include the extension so the bsc-nat knows that it has to use to RTP. 2nd) The dummy load is used to convey the Osmux CID. This needs to happen at this stage since the bsc-nat needs to know what source port the bsc uses to get this working since the bsc may use a different source port due to NAT. Unfortunately, this can't be done from the MGCP signal plane since the real source port is not known that the bsc uses is not known. This patch also reverts the MDCX handling until it is clear that we need this special handling for this case.
2014-08-27osmux: move osmux socket initialization out of osmux_enable_endpoint()Pablo Neira Ayuso1-0/+16
In the bsc-nat side, the osmux socket initialization can be done from the vty. This ensure that the osmux socket is available by the time the bsc-nt receives the dummy load that confirms that the osmux flow has been set up. This change is required by the follow up patch. This change ensures that the Osmux socket in the bsc-nat is already in place by the time this receives the dummy load.
2014-08-24Use port number #defines for VTY and CTRL portsHarald Welte2-2/+4
.. as defined in libosmocore
2014-08-21move libctrl from openbsc to libosmoctrl (libosmocore.git)Harald Welte4-9/+11
2014-08-20adopt recent IPA related symbol renameHarald Welte4-10/+13
... which happened during recent migration of IPA functionality from libosmo-abis into libosmocore.
2014-07-22mgcp: Change API to remove memory management from the nameHolger Hans Peter Freyther1-3/+3
Jacob pointed out that "free_endp" refers to the memory of the endpoint being freed. What we want is actually a way to release an endpoint (and the resource it allocated) or in the case of the testcase/testapp initialize the data structure correctly. Introduce two names for that.
2014-07-07nat: Fix the documentation issue with the osmux commandHolger Hans Peter Freyther1-1/+1
Documentation error (missing docs): <command id='osmux (on|off)'> <param name='off' doc='(null)' />
2014-07-07libbsc, osmo-bsc{, _nat}: Prevent unaligned access when casting TLVP_VALDaniel Willmann1-1/+1
foo = *((uintXX_t *) TLVP_VAL(...) can lead to unaligned access. To prevent that use tlvp_valXX_unal() to get the values.
2014-05-22mgcp: add voice muxer supportPablo Neira Ayuso3-12/+44
This patch adds the voice muxer. You can use this to batch RTP traffic to reduce bandwidth comsuption. Basically, osmux transforms RTP flows to a compact batch format, that is later on decompacted to its original form. Port UDP/1984 is used for the muxer traffic between osmo-bsc_nat and osmo-bsc_mgcp (in the BSC side). This feature depends on libosmo-netif, which contains the osmux core support. Osmux is requested on-demand via the MGCP CRCX/MDCX messages (using the vendor-specific extension X-Osmux: on) coming from the BSC-NAT, so you can selectively enable osmux per BSC from one the bsc-nat.cfg file, so we have a centralized point to enable/disable osmux. First thing you need to do is to accept requests to use Osmux, this can be done from VTY interface of osmo-bsc_nat and osmo-bsc_mgcp by adding the following line: mgcp ... osmux on osmux batch-factor 4 This just initializes the osmux engine. You still have to specify what BSC uses osmux from osmo-bsc_nat configuration file: ... bsc 1 osmux on bsc 2 ... bsc 3 osmux on In this case, bsc 1 and 3 should use osmux if possible, bsc 2 does not have osmux enabled. Thus, you can selectively enable osmux depending on the BSC, and we have a centralized point for configuration from the bsc-nat to enable osmux on demand, as suggested by Holger. At this moment, this patch contains heavy debug logging for each RTP packet that can be removed later to save cycles. The RTP ssrc/seqnum/timestamp is randomly allocated for each MDCX that is received to configure an endpoint.
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 Erlbeck2-6/+21
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