Commit Graph

20 Commits

Author SHA1 Message Date
Neels Hofmeyr 7c5346cd70 vlr_subscr: use osmo_use_count
Depends: Ife31e6798b4e728a23913179e346552a7dd338c0 (libosmocore)
Change-Id: Ib06d030e8464abe415ff597d462ed40eeddef475
2019-04-12 02:15:25 +02:00
Vadim Yanitskiy 0cd761c604 libmsc/db.c: cosmetic: mark missing breaks in switch as intended
Change-Id: I3f4f34ecd0c5bb2d1a675ad5c4669fcffb87f292
Closes: Coverity CID#148209
2018-11-21 19:48:16 +07:00
Max 98f7467ac8 Wrap osmo_strlcpy() calls
Using following semantic patch:
@@ expression A, B, C; @@
- osmo_strlcpy(A, B, sizeof(A));
+ OSMO_STRLCPY_ARRAY(A, B);

Which was applied using following command:
spatch --dir src -I src --sp-file strlcpy.spatch --in-place --recursive-includes

All the calls to osmo_strlcpy() which use destination buffer obtained
via sizeof() were replaced with the corresponding wrapper macro.

Change-Id: I67b482dedfa11237ac21894fc5930039e12434ab
Related: OS#2864
2018-02-05 12:57:06 +01:00
Stefan Sperling 14e051776f Delete expired SMS automatically.
Delete expired SMS whenever we are done processing an SMS-related signal.
In order to minimize additional latency only one SMS is removed at a time.

Change-Id: I56cbe716e52b679c4b94f6cbb4a171306975be2e
Related: OS#2354
2018-01-25 20:30:40 +00:00
Stefan Sperling 87cba1f105 Add a VTY command which deletes all expired SMS.
We already delete SMS which have been sent successfully. However, there
are plans to accept SMS for any subscriber in order to fix the problem
described in https://osmocom.org/issues/2354 ("SMSC: Store&Forward not
working for subscribed but unregistered MS").

This means we may end up storing SMS which never get sent, e.g. because
the B subscriber doesn't actually exist. This could lead to a higher
degree of SMS database growth over time, and therefore we need a way
to keep database size under control.

As a first step, introduce a DB function which removes an expired SMS,
and add a VTY command which removes all expired SMS from the DB.

Later commits will build upon this to remove expired SMS automatically.

The SMS expiry time period is currently hard-coded to 2 weeks.
We could make this configurable in the future if desired.

Change-Id: Icd6093b7b5d8db84b19a0aa47c68182566113ee2
Related: OS#2354
2018-01-25 16:16:15 +00:00
Stefan Sperling 3b26f34950 Fix value of stored SMS validity time.
Quote the argument to sqlite's datetime(). Otherwise, the timestamp
stored in the database reads back as a negative value for some reason.

Before:

1032            validity_timestamp = dbi_result_get_datetime(result, "valid_until");
(gdb) p validity_timestamp
$2 = -1516814654

After:

1032            validity_timestamp = dbi_result_get_datetime(result, "valid_until");
(gdb) p validity_timestamp
$2 = 1516814654

Change-Id: Icf786f9b1efabfe7407fb6414ec0d326d8f7244a
2018-01-23 16:57:52 +00:00
Stefan Sperling d494162c9c Store/retrieve SMS validity time in the SMS datebase
Compute a validity timestamp based on SMS validity time.
Store the computed value in the database and recompute the validity
time when an SMS is read from the database.

Change-Id: Id27c250d3a64cd109416450e8ca155b18a8b9568
2018-01-20 15:02:40 +00:00
Stefan Sperling 6ba2d5a9f7 Delete SMS from the database once they were sent successfully
Currently the SMS database keeps accumulating entries for each SMS.
These entries are never deleted automatically. With this change, we
start deleting SMS which have successfully been sent to subscriber B.

Change-Id: I3749855fe25d9d4e37ec96b0c2bffbc692b66a78
2018-01-18 18:55:26 +01:00
Stefan Sperling 832046d383 Improve an error message in db_init().
If we cannot open a connection to the sqlite3 database, show the name of the
database we failed to access, and also hint at the fact that a likely reason
for the problem is a missing sqlite3 driver for libdbi.

Change-Id: If1c0026e882984b4358ce116ec4a7ad40340517c
2018-01-16 14:21:16 +01:00
Max 753c15de2f Migrate from OpenSSL to osmo_get_rand_id()
This avoids potential licensing incompatibility and makes integration of
Debian packaging patches easier.

Related: OS#1694
Change-Id: I71cd631704a4dc155c6c752fee2a42cd6e2fa336
2017-12-27 11:11:14 +00:00
Pau Espin c22e54deab libmsc: db.c: Replace dbi APIs marked as deprecated
Several warning messages about those APIs being deprecated were printed
at compile time.

Change-Id: I6052159acf240cc7e8e2b3a3af10d8210708ddb6
2017-12-20 16:06:43 +00:00
Neels Hofmeyr db8272921d sms.db: silence libdbi warnings on out-of-range index
Apparently, since libdbi 0.9.0 aka 0.9.0-5 on debian-testing, osmo-msc barfs
numerous libdbi warnings whenever a query rightfully returns no rows.

Trivially query whether there are any rows first by adding an inline wrap
function next_row().

Silenced:

  DDB <000d> ../../../../src/osmo-msc/src/libmsc/db.c:188 DBI: -6: An invalid or out-of-range index was passed to libdbi
  DDB <000d> ../../../src/libosmocore/src/backtrace.c:47 backtrace() returned 11 addresses
  DDB <000d> ../../../src/libosmocore/src/backtrace.c:57        /usr/local/bin/osmo-msc(+0xfb81) [0x555555563b81]
  DDB <000d> ../../../src/libosmocore/src/backtrace.c:57        /usr/lib/x86_64-linux-gnu/libdbi.so.1(_error_handler+0x99) [0x7ffff63f5c39]
  DDB <000d> ../../../src/libosmocore/src/backtrace.c:57        /usr/lib/x86_64-linux-gnu/libdbi.so.1(dbi_result_next_row+0x3d) [0x7ffff63f785d]
  DDB <000d> ../../../src/libosmocore/src/backtrace.c:57        /usr/local/bin/osmo-msc(+0x11172) [0x555555565172]
  DDB <000d> ../../../src/libosmocore/src/backtrace.c:57        /usr/local/bin/osmo-msc(+0x1e6bc) [0x5555555726bc]
  DDB <000d> ../../../src/libosmocore/src/backtrace.c:57        /usr/local/bin/osmo-msc(+0x1e7f6) [0x5555555727f6]
  DDB <000d> ../../../src/libosmocore/src/backtrace.c:57        /usr/local/bin/osmo-msc(+0x1f1d2) [0x5555555731d2]
  DDB <000d> ../../../src/libosmocore/src/backtrace.c:57        /usr/local/bin/osmo-msc(+0xbb86) [0x55555555fb86]
  DDB <000d> ../../../src/libosmocore/src/backtrace.c:57        /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1) [0x7ffff5cfe561]
  DDB <000d> ../../../src/libosmocore/src/backtrace.c:57        /usr/local/bin/osmo-msc(+0xbfba) [0x55555555ffba]

Related: OS#2667
Change-Id: Ib8993c8db171d1e845a6297deef137d18506cda3
2017-12-10 14:45:15 +01:00
Neels Hofmeyr 50d0900916 sms db: properly quote MSISDN in various SQL queries
Related: OS#2706
Change-Id: I793a3863e6f4ccbabafc7dabaff97a8c79bbd8e0
2017-12-06 12:54:13 +00:00
Neels Hofmeyr f6704f1a50 sms db: don't attempt to query pending SMS for unset MSISDN
When the subscriber has no MSISDN, we might construct an invalid SQL statement
such as

  ... AND dest_addr= AND ...

Instead, don't even query for empty MSISDNs.

Related: OS#2706
Change-Id: I7d6169d774b2da04b3051957e364fe620feed51e
2017-12-06 12:51:17 +00:00
Neels Hofmeyr 9084396467 rename include/openbsc to include/osmocom/msc
Change-Id: I1f96a1285bbd1b4607614856bca935d5c26e2da9
2017-09-06 16:41:25 +02:00
Keith Whyte c601adcb89 libmsc: Use actual delivery time in delivery reports.
Set the time on the status report to the time the message was delivered, as
this may not be the same as the time when we are delivering the report to the
originating MS.

Change-Id: I9056429d40bf02731f004b7833f1de45a0d1add8
2017-08-27 02:33:50 +02:00
Pau Espin f113bcd671 libmsc: Remove comment not applying anymore
The change-id I7276d356d805a83ebeec72b02c8563b7135ea0b6 added msg_ref to
the databse but forgot to remove the comment stating it's not being
stored.

Change-Id: I204f098c8f2a480405446113e2181b2c53700cf3
2017-08-27 02:33:49 +02:00
Pablo Neira Ayuso 9891dae131 libmsc: update database to accomodate SMS status-report fields
SMPP DELIVER_SM messages with esm_class = Delivery Receipt need to send
this message reference (that the mobile phone allocates) to the ESME.
Thus, the ESME propagates it via SUBMIT_SM with esm_class = Delivery
Acknoledgment so that the SMSC sends the GSM 03.40 status-report to the
origin including this. Given this field is useful for status-reports, we
need to store it in the HLR database.

Moreover, we need a new field that specifies if the entry represents a
SMS status-report, to do the right handling from the gsm411_send_sms() -
such new handling comes in a follow up patch entitled "libmsc: handle
delivery ack via SMPP SUBMIT SM / send GSM 03.40 status report".

This patch includes the migration routines to the new database schema
revision 5, it's quite a bit of dbi boilerplate code - copied-pasted and
adapted.

Change-Id: I7276d356d805a83ebeec72b02c8563b7135ea0b6
2017-08-27 02:33:49 +02:00
Harald Welte 2483f1b050 Use libvlr in libmsc (large refactoring)
Original libvlr code is by Harald Welte <laforge@gnumonks.org>,
polished and tweaked by Neels Hofmeyr <nhofmeyr@sysmocom.de>.

This is a long series of trial-and-error development collapsed in one patch.
This may be split in smaller commits if reviewers prefer that. If we can keep
it as one, we have saved ourselves the additional separation work.

SMS:

The SQL based lookup of SMS for attached subscribers no longer works since the
SQL database no longer has the subscriber data. Replace with a round-robin on
the SMS recipient MSISDNs paired with a VLR subscriber RAM lookup whether the
subscriber is currently attached.

If there are many SMS for not-attached subscribers in the SMS database, this
will become inefficient: a DB hit returns a pending SMS, the RAM lookup will
reveal that the subscriber is not attached, after which the DB is hit for the
next SMS. It would become more efficient e.g. by having an MSISDN based hash
list for the VLR subscribers and by marking non-attached SMS recipients in the
SMS database so that they can be excluded with the SQL query already.

There is a sanity limit to do at most 100 db hits per attempt to find a pending
SMS. So if there are more than 100 stored SMS waiting for their recipients to
actually attach to the MSC, it may take more than one SMS queue trigger to
deliver SMS for subscribers that are actually attached.

This is not very beautiful, but is merely intended to carry us over to a time
when we have a proper separate SMSC entity.

Introduce gsm_subscriber_connection ref-counting in libmsc.

Remove/Disable VTY and CTRL commands to create subscribers, which is now a task
of the OsmoHLR. Adjust the python tests accordingly.

Remove VTY cmd subscriber-keep-in-ram.

Use OSMO_GSUP_PORT = 4222 instead of 2222. See
I4222e21686c823985be8ff1f16b1182be8ad6175.

So far use the LAC from conn->bts, will be replaced by conn->lac in
Id3705236350d5f69e447046b0a764bbabc3d493c.

Related: OS#1592 OS#1974
Change-Id: I639544a6cdda77a3aafc4e3446a55393f60e4050
2017-07-23 04:08:43 +02:00
Neels Hofmeyr 29b9206e80 move openbsc/* to repos root
This is the first step in creating this repository from the legacy openbsc.git.

Like all other Osmocom repositories, keep the autoconf and automake files in
the repository root. openbsc.git has been the sole exception, which ends now.

Change-Id: I9c6f2a448d9cb1cc088cf1cf6918b69d7e69b4e7
2017-07-12 23:17:10 +00:00