Commit Graph

523 Commits

Author SHA1 Message Date
Harald Welte 9214c6c7ef Fix expected test output after new 'logging print file 1' vty command
Ever since libosmocore Change-Id I1c931bff1f1723aa82bead9dfe548e4cc5b685e0
was merged, the VTY tests were broken. Let's fix that by adjusting
the expected test output.

Change-Id: I929ca7f366220b5d1238d43eddc96fa9dde916b6
2018-02-09 14:27:22 +01:00
Alexander Huemer 79fc6984ac Add missing build products in .gitignore
Change-Id: I48b93adc280c1b0521e7f5acc1f66ce5db462915
2018-01-29 09:29:18 +01:00
Neels Hofmeyr ba1605afdc fix build: db_test: missing LIBOSMOABIS_CFLAGS and _LIBS
Change-Id: I2539f5dc7a512a57ad36c460a11195ccbd84d7d6
2018-01-16 13:35:46 +01:00
Max b6265d1a55 Enable sanitize for CI tests
Change-Id: I112307b5eaf494062b2e8498ff2e9217fb8db925
2018-01-08 13:09:24 +00:00
Neels Hofmeyr 6c84da5942 ctrl test: fix: adjust expectations after stricter ctrl parsing
After libosmocore I96a9b6b6a3a5e0b80513aa9eaa727ae8c9c7d7a1 the CTRL interface
returns stricter errors. Adjust the expectations of
test_subscriber_errors.ctrl to fix the external tests on master.

Change-Id: I9337b6b4f3fa8822c91760deb01f18a77a073d19
2018-01-07 22:27:08 +01:00
Neels Hofmeyr 84c2f43d00 fix debug log: put 'deriving 2G from 3G' in proper place
Don't log "deriving 2G from 3G" when we're actually calculating separately; log
it when we're actually deriving from 3G.

Add log "calculating 2G separately" in the right place.

The test output changes show that each test said "separate 2G" at the top while
logging "deriving 2G from 3G" further down, which was obviously wrong.

Change-Id: I6679d7ef8fdcae39a0c2aff7ac638e63dddb10dc
2017-12-20 00:10:34 +01:00
Neels Hofmeyr 63f68ccc4c fix test_subscriber_errors.ctrl after libosmocore change
libosmocore Ie35a02555b76913bb12734a76fc40fde7ffb244d
"ctrl: on parse errors, return a detailed message to sender"
the test_subscriber_errors.ctrl test fails.

Adjust the expected error message.

Change-Id: I3aee1507721cd073f72369150d0fb3cff0fdf66f
2017-12-19 15:50:57 +01:00
Pau Espin b5d77012d1 contrib:jenkins.sh: Enable Werror
Change-Id: I61688a4c9b50f6f3705bd18c96c00f8703ef5042
2017-12-15 19:06:59 +01:00
Pau Espin fc96f688d4 luop.c: Transform FIXME from warning to pragma message
This way the issue is still visible but we can enable Werror to avoid
introducing new warnings.

Change-Id: I6c9b195bf0e3f853e202cdbdb72d35d83cd2a2ab
2017-12-15 19:05:12 +01:00
Max 43bd6069e8 Remove unused ipa.py
Change-Id: I0a6c22f38480ae75ae9efb452e4eeacb39ae4f42
2017-12-01 12:05:51 +00:00
Neels Hofmeyr 2dee60ef44 db_test: also test db_get_auc() return values
Verify that it returns -ENOENT on non-existing IMSI and -ENOKEY for no auth
data.

Move the auc_compute_vectors() stub to the top near the db_get_auc() call, and
just return num_vec to get a successful return value when auth data is present.

Change-Id: Ic0158228afbd78b8ca21f62dffa9f868674682b9
2017-11-29 16:22:52 +00:00
Neels Hofmeyr ab4d509a83 osmo-hlr: log details for unknown IMSI / no auth data / db error
For unknown IMSI and no auth data for a known IMSI, log respective messages on
NOTICE level.

For database error, log on ERROR level.

Change-Id: I3838fa78567e7e92d797d90b8b90865d9ebba90a
2017-11-29 16:22:46 +00:00
Neels Hofmeyr bd1dca0859 db_get_auth_data / db_get_auc: clarify return values
Differentiate between "IMSI unknown" and "IMSI has no auth data": in case of
known IMSI lacking auth data, return -ENOKEY instead of -ENOENT.

Fix API doc comments to reflect what the functions actually return, on top of
adding the -ENOKEY detail.

Adjust db_test expectations from -ENOENT to -ENOKEY where appropriate.

Adjust VTY and CTRL command rc evaluation.

A subsequent patch will use these return values to log details on each of these
situations.

Change-Id: Icf6304d23585f2ed45e050fa27c787f2d66fd3f7
2017-11-29 16:22:29 +00:00
Max 33eeeef9dc Remove unused check
We do not test on FreeBSD in jenkins anymore.

Change-Id: I1578306244f6ee218e464a6c378ff60605cf1d5c
2017-11-24 11:30:50 +01:00
Neels Hofmeyr 33cbde9ced return GMM_CAUSE_IMSI_UNKNOWN if there is no auth data
If we have a subscriber entry that lacks auth data, we currently return
GMM_CAUSE_NET_FAIL, which in the MSC log looks like the HLR is not connected or
something grave. Instead, return GMM_CAUSE_IMSI_UNKNOWN.

This changes the OsmoMSC log in this way:
Before:

  DVLR <001e> VLR_Authenticate(901700000014701)[0x5555558dabb0]{VLR_SUB_AS_NEEDS_AUTH_WAIT_AI}: GSUP: rx Auth Info Error cause: 17: Network failure

After:

  DVLR <001e> VLR_Authenticate(901700000014701)[0x5555558dabb0]{VLR_SUB_AS_NEEDS_AUTH_WAIT_AI}: GSUP: rx Auth Info Error cause: 2: IMSI unknown in HLR

A better cause value would be something that says "IMSI known, but we have no
auth data", but since such cause value is not defined, the plain "IMSI unknown"
seems to be the best match.

Change-Id: I90df7b255317df1e5d968e7ce3b9d2c404b98db8
2017-11-22 20:49:43 +01:00
Neels Hofmeyr 671db90ac3 cosmetic: rx_send_auth_info(): decide error cause with switch()
Prepare for tweaking error handling in a subsequent patch: use switch() instead
of if().

Prepares-for: I90df7b255317df1e5d968e7ce3b9d2c404b98db8
Change-Id: I1f628aa9d62b778951726bebec8cf338444fc897
2017-11-22 20:42:49 +01:00
Neels Hofmeyr d3814b936b db_test: don't verify SQLite issued error messages, they might change
A user on openbsc@ complained that with SQLite 3.8.2, the db_test fails with

  --- expected
  +++ stderr
  -DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
  +DDB (2067) abort at 35 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi

i.e. a trivial difference in the error message issued by SQLite.

For db_test, don't output any SQLite error messages: Add argument
enable_sqlite_logging, pass as true, except in db_test.c.
Remove the SQLite error messages from expected output.

(Note that there is a src/db_test.c program that's not of interest here, this
is about the tests/db/db_test.c)

Change-Id: I2513d71cc0072aef8d08f47d0a1959f311176229
2017-11-21 12:33:45 +01:00
Neels Hofmeyr 6f3e8d6297 add --enable-sanitize config option
Change-Id: I12b7b0e751f274a05e88c79299fd8388667cc542
2017-11-18 10:19:13 +00:00
Alexander Couzens db5dae6c99 debian: install osmo-hlr.cfg to /etc/osmocom
Change-Id: Ifa1094da9b286a17a5c9a1ee300ec13a4a10a9a7
2017-11-17 14:27:49 +00:00
Alexander Couzens 38f08770a3 doc: install example .cfg files to $(docdir)/examples/
Change-Id: I8671ce33b9bf28c89f767dd1b4a1463aeb275158
2017-11-17 14:27:40 +00:00
Alexander Couzens aee7be901b debian: include systemd service osmo-hlr.service
Change-Id: I6d9fd34aa42b911f074557b526adde05e03d58b9
2017-11-16 00:38:32 +01:00
Neels Hofmeyr 8db490695d db-tool: error-exit on too many arguments
Each arg parsing should increment optind, so if there are any surplus args in
the end, that's an error.

Change-Id: I9fc0a87d11db8c35061568e3f8b5a5547931a961
2017-11-12 14:22:00 +00:00
Neels Hofmeyr c82e6ad190 db-tool: cosmetic: tweak printf output
Say <nitb.db> to indicate a filename.
No need to print the cmd and arg count, really.

Change-Id: I3be31754db5297b3f6028877068f97ce1be4d74b
2017-11-12 14:22:00 +00:00
Neels Hofmeyr 0959e8b354 db-tool: add command 'create'
Change-Id: Ic4997d17763e50fb63c36fc0001570230bf64a12
2017-11-12 14:22:00 +00:00
Neels Hofmeyr 4f3841c153 cosmetic: add comment on ignored return value
Coverity wants us to evaluate sqlite3_reset, but it is of no use to do so.

Related: coverity CID#178653
Change-Id: I64ac8c148f48be60f9c0d346df0c5152bb527494
2017-11-11 23:25:06 +00:00
Harald Welte bd0d5bf5d8 hlr.c: Avoid overflow of lu_operation.subscr.imsi
It appears that hlr_subscriber.imsi is 16 buffers in size:
15 chars for IMSI + 1 byte NUL.  However,  osmo_gsup_message.imsi
is 17 bytes (for whatever reason), so we cannot simply do a strpy()
as this might overflow the hlr_subscriber.imsi field!

TODO: check if weactually ever receive a too-long IMSI in GSUP and
reject that at an earlier time in the code flow.

Fixes: Coverity CID#164746

Change-Id: I9ff94e6bb0ad2ad2a7c010d3ea7dad9af0f3c048
2017-11-10 21:26:53 +00:00
Neels Hofmeyr 87a04b6b95 hlr_db_tool: fix error log strerror invocation
The db API returns negative errno values, need to flip the sign before feeding
to strerror.

Fixes: coverity CID#178658
Change-Id: Iaab46f565a1112d8a7def8ea90a5cd440c0a3b41
2017-11-08 02:29:05 +00:00
Neels Hofmeyr 85e8a64bb4 vty: skip installing cmds now always installed by default
vty_install_default() and install_default() will soon be deprecated.

Depends: I5021c64a787b63314e0f2f1cba0b8fc7bff4f09b
Change-Id: I09762f110c7bcaf85c0ef2f472eb43ac543c74e9
2017-11-01 00:50:13 +01:00
Harald Welte 0dcbd47a1e Tag/Release version 0.1.0
This is the first real version tag of osmo-hlr.

Change-Id: Ie0aff33ab9c36cd9219258a4d869de36612b6095
2017-10-28 20:43:12 +02:00
Harald Welte 71b5f5b923 Debian: Make sure we include osmo-hlr-db-tool in the package
Change-Id: Ia67ae6d4b1af982db8c342f2d8fd29deb83ccaff
2017-10-28 20:43:12 +02:00
Neels Hofmeyr 73d14af278 add osmo-hlr-db-tool, program to migrate from osmo-nitb db
Move macro copy_sqlite3_text_to_buf() to db.h, so it can be used in
hlr_db_tool.c.

Add _dbd_decode_binary() from libdbi to avoid depending on the entire libdbi
just for KI BLOB decoding. Add it in a separate file, copying its own license,
the lGPL.

Offer commandline option "import-nitb-db" to read in an old osmo-nitb database
and copy subscriber IMSIs and 2G auth data to OsmoHLR db format.

Anticipate future command line options like "import-csv", so keep the code
generalized.

Change-Id: I0dfa6ec033dd93161c1adc2ce1637195fe5b7a63
2017-10-28 20:34:01 +02:00
Neels Hofmeyr 6eb231eccc fix default logging levels to NOTICE, not DEBUG
Tweak unit test binaries to still used DEBUG loglevels, so that their expected
outputs remain unchanged (and nicely verbose).

Adjust test_nodes.vty, now expecting the 'notice' log levels upon
'show running-config'.

Change-Id: Ic061e61c9625b49cef8bc2a2c0b936e262c22268
2017-10-28 16:49:46 +00:00
Neels Hofmeyr dbced93b5f cosmetic: rename SL3_TXT macro, use osmo_strlcpy()
Rename SL3_TXT to more accurate copy_sqlite3_text_to_buf(), and use
osmo_strlcpy() instead of essentially dup'ing it.

The macro will also be used by hlr_db_tool.c in upcoming patch. This patch
prepares for a move to db.h.

Change-Id: I1dadeddddcfe0109195c09c0e706201b0df009cc
2017-10-28 16:49:33 +00:00
Neels Hofmeyr 88c91f6fb2 cosmetic: sql/hlr.sql: move comments
By moving the comments inside the table row definitions, they are dumped back
during 'sqlite3 hlr.db .dump'. When they are between SQL statements like before
this patch, the comments are lost.

Tweak wording.

Change-Id: I280c2e2d3e9b7f1dc632722724d9e1c54d041820
2017-10-28 16:49:33 +00:00
Neels Hofmeyr 7750d2cedc automatically create db tables on osmo-hlr invocation
If a database file is missing, osmo-hlr creates it, as is the default sqlite3
API behavior -- before this patch, that db file is created, but lacks useful
tables. Actually also create initial tables in it, as osmo-nitb did.

In effect, the 'vty-test' target in tests/Makefile.am no longer needs to create
a database manually. (The 'ctrl-test' still does, because it also wants to add
subscriber data on top of the bare tables.)

Note: it could be desirable to bail if the desired database file does not
exist. That is however a different semantic from this patch; this is not
changing the fact that a db file is created, this just creates a usable one.

Note: I am about to add osmo-hlr-db-tool to do database migration from
osmo-nitb. For that, it is desirable to bootstrap a usable database, which is
the core reason for this patch.

Don't plainly duplicate hlr.sql to .c, but create db_bootstrap.h as a
BUILT_SOURCE from reading in sql/hlr.sql and mangling via sed to a list of SQL
statement strings. On each db_open(), run this bootstrap sequence.

In sql/hlr.sql, these tweaks are necessary:
* Add 'IF NOT EXISTS' to 'CREATE TABLE', so that the bootstrap sequence can be
  run on an already bootstrapped db.
* Drop the final comment at the bottom, which ended up being an empty SQL
  statement and causing sqlite3 API errors, seemed to have no purpose anyway.

Note: by composing the statement strings as multiline and including the SQL
comments, sqlite3 actually retains the comments contained in table definitions
and prints them back during 'sqlite3 hlr.db .dump'.

Change-Id: If77dbbfe1af3e66aaec91cb6295b687f37678636
2017-10-28 16:49:33 +00:00
Neels Hofmeyr cd7fa4502c db_test: fix *FLAGS
The -I includes should be in CFLAGS, not CPPFLAGS.

I noticed problems with it when trying to add an -I$(builddir) in an upcoming
patch that adds a BUILT_SOURCE, If77dbbfe1af3e66aaec91cb6295b687f37678636.

Change-Id: Ie57a04b7efc7a1e16cf0e3625d8ad2f0ef0089b0
2017-10-28 16:49:33 +00:00
Neels Hofmeyr 99a14c8ca1 tests/Makefile: use test db var instead of repeating the path
Change-Id: I9859b522b5ffa7f2c9ed33ab849199d4b4e6696c
2017-10-28 16:49:32 +00:00
Neels Hofmeyr c6a6d26f50 jenkins: use osmo-clean-workspace.sh before and after build
See osmo-ci change I2409b2928b4d7ebbd6c005097d4ad7337307dd93 for rationale.

Depends: I2409b2928b4d7ebbd6c005097d4ad7337307dd93
Change-Id: I9d35913f9cd60ff121d29f357919a0b0d62d6835
2017-10-28 04:37:41 +02:00
Neels Hofmeyr 3f697cdc71 test_subscriber.ctrl: test against octal/hex interpretation of id
Add a large enough subscriber id and add a test that ensures a leading zero is
not interpreted as octal, and that a leading 0x is invalid and not interpreted
as hexadecimal.

Change-Id: Ib468b7cb595cf52331ebb41e6de0e8f57f69e173
2017-10-27 02:37:20 +02:00
Neels Hofmeyr 446eb0f1bc ctrl: completely replace all CTRL commands
The previous commands are not conforming to how the CTRL interface is intended
to work:

  SET enable-ps <IMSI>
  SET disable-ps <IMSI>
  SET status-ps <IMSI>

'status-ps' is a write-only command even though it returns the status.
'enable-ps' / 'disable-ps' indicate the value instead of a variable name of an
entity. The entity <IMSI> takes the place of the variable value.

See also https://lists.osmocom.org/pipermail/openbsc/2017-September/011236.html

Instead, replace with

  SET subscriber.by-imsi-123456.ps-enabled {0,1}
  GET subscriber.by-imsi-123456.ps-enabled

and also provide further CTRL functions while at it:

  {SET,GET} subscriber.by-{imsi,msisdn,id}-123456.{cs,ps}-enabled {0,1}
  GET subscriber.by-{imsi,msisdn,id}-123456.{info,info-aud,info-all}

Provide CTRL tests in the form of transcripts.

Adjust tests/test_subscriber.sql to feature nonzero SQN, to see some values for
SQN in the CTRL transcript tests. (This does not affect the VTY tests, because
that creates its own subscribers, and there's no VTY command to set the SQN.)

This is the first time an application uses CTRL_NODE ids that are defined
outside of libosmocore, see 'Depends' below.

Implementation choice: the first idea was to have a '.' between the 'by-xxx'
and the value, like:

  subscriber.by-xxx.123456.function

but the difficulty with subscribers is that they are not in RAM, and I can't
just point node_data at a struct instance that is always there (like, say, a
global bts[0] struct in osmo-bsc). Instead, I want to store the selector and
later decide whether to read from the DB or whatever. With a '.' separating
things, the only way in a ctrl function to obtain both 'by-xxx' and '123456'
for picking a subscriber record would be to parse the entire variable path
string elements, including 'subscriber' and 'function', which would then also
clumsily fix at which node level we hook these commands; there could have been
separate CTRL_NODE_SUBSCR_BY_{IMSI,MSISDN,ID} parent nodes, but we cannot
introspect the current parent node dynamically within a ctrl function handler
(plus I'm not sure whether it's possible and a good idea to have the same
command under multiple parent nodes).

Rather than that, I store the 'by-foo-123' token in the node_data pointer to
have both bits of information pointed at by a single pointer; I use the
incoming command parsing to get this token pre-separated from surrounding node
names, and no need to re-allocate it, since the vector of tokens lives until
after command execution is complete. Each leaf command obtains this token from
cmd->node (aka node_data), and feeds this token to a common static function to
parse selector and value from it and to retrieve a subscriber record as needed.

(BTW, I have mentioned on the mailing list that this way might be necessary to
avoid numeric-only CTRL node names, but we don't need to, and that is not at
all related to this choice of structure.)

Depends: libosmocore I1bd62ae0d4eefde7e1517db15a2155640a1bab58
         libosmocore Ic9dba0e4a1eb5a7dc3cee2f181b9024ed4fc7005
Change-Id: I98ee6a06b3aa6a67adb868e0b63b0e04eb42eb50
2017-10-27 02:35:49 +02:00
Neels Hofmeyr 234f9cb701 cosmetic: tweak params of hlr_controlif_setup()
Cosmetically prepare for adding new CTRL commands in hlr_controlif_setup():
- drop unused 'gs' param.
- use ctrl_interface_setup_dynip2(), so far with default CTRL nodes; custom
  nodes will be added soon.

Prepares: I98ee6a06b3aa6a67adb868e0b63b0e04eb42eb50
Change-Id: I63004a7953b04988449697dbc5d55d7ed0c6d82d
2017-10-27 00:35:01 +00:00
Neels Hofmeyr 16140f70c5 db api: fix/add API docs
Change-Id: I854fafd8e56bd0b8394f8ed79d023c11c2fdbdca
2017-10-25 19:21:40 +02:00
Neels Hofmeyr 36bec87104 vty: fix output of empty IMSI
Check *subscr->imsi, not subscr->imsi, since it is a char[]; same as msisdn
below already does.

Was introduced in change I42b3b70a0439a8f2e4964d7cc31e593c1f0d7537 / commit
183e7009af.

Fixes: coverity CID 178166
Change-Id: I72e13efefbac0495b8dd1949a39fa44ebfd46b56
2017-10-23 18:47:58 +02:00
Neels Hofmeyr 00b1d43435 add hlr_subsrc_nam to put GSUP client notification in proper API
This code should not live in a CTRL interface function but be proper hlr_* API.

Change-Id: I4c9b8f9ad51d49517474e8b51afc3cc2e1c9299a
2017-10-17 02:28:43 +00:00
Neels Hofmeyr 7ae8d878cf api doc: say that lu_op_tx_del_subscr_data() doesn't free
Change-Id: Ia341d8e5bfc6eb0dc59945281ce88eecfaab057e
2017-10-17 02:03:42 +02:00
Neels Hofmeyr 68f87915e4 fix mem leak in handle_cmd_ps(): free luop
Each GSUP client creates a luop, but since lu_op_tx_del_subscr_data() doesn't
free the luop, each allocated luop leaks memory.

Change-Id: If912dc992bc7f18c49d22ec0436d9679c1cd04f6
2017-10-17 02:03:01 +02:00
Neels Hofmeyr e86437cae4 luop: fix mem leak upon error in lu_op_alloc_conn()
Free allocated luop if osmo_gsup_conn_ccm_get() fails.

Change-Id: I3ebd5fb5e313be452de893248dd58b2bb73ba94a
2017-10-17 02:01:48 +02:00
Neels Hofmeyr 200f56e995 add lu_op_free(), use in luop.c
Add to luop.h, it will be used in db_hlr.c in an upcoming patch.

Change-Id: Ib44d9062edc957d2e0710b7e485604f97e4d5612
2017-10-17 02:01:08 +02:00
Neels Hofmeyr 50e4de7e49 replace ctrl_test_runner.py with transcript test_subscriber.ctrl
Use the new osmo_verify_transcript_ctrl.py from osmo-python-tests to completely
replace current ctrl_test_runner.py with a CTRL interaction transcript.

Add missing EXTRA_DIST entry of test_subscriber.sql.

Depends: osmo-python-tests Id47331009910e651372b9c9c76e12f2e8964cc2c
Change-Id: Iff93abe370b8f3ecf42082d1d0eaa1fbeca5b122
2017-10-17 01:07:32 +02:00
Neels Hofmeyr 86d09ec266 add test_nodes.vty
Automatically picked up by the vty-test target, by file name extension.

Change-Id: I8dba373cee1be954504f79c3305b0111071757e7
2017-10-17 00:59:00 +02:00