Compare commits

..

125 Commits

Author SHA1 Message Date
Pau Espin Pedrol
ed939154f8 Bump version: 1.5.0.19-268a-dirty → 1.6.0
Change-Id: Ide480a902bbfadefa396f3a0cb925f5dceab4f9c
2023-02-07 16:49:15 +01:00
Alexander Couzens
268a33e58b Add vty reject-cause to set the reject cause
Allow to set the LU reject cause independently for both of the
following cases; either when an IMSI is unknown to the HLR or
when the mslookup client does not a receive a timely response
to a GSUP request for the remote home HLR.

Original patchset modified by <keith@rhizomatica.org>

Change-Id: Icea39020c23fbbea9e92847df76af8986fdbf48a
2023-01-20 14:03:01 +00:00
Neels Hofmeyr
8804a2335a fix memleak of proxy_subscr_listentry
Patch-by: whytek
Related: OS#5854
Change-Id: Ic1ec4911fa5ae91cc75aa865c8201edd83af41ed
2023-01-15 22:45:31 +01:00
Keith
c27bc90ae6 Vty: Fixup config shown/written from vty
This commit fixes the following errors:
Missing timeout param for mslookup.
Fails to start reading a written config if an msc node
is configured in the mslookup server.
Places the individual msc node services in the
top-level wildcard node due to incorrect indentation.

* Add missing timeout param.
* Add missing "ipa-name" part to mslookup-server-msc section.
* Add one extra space indentation for msc services.

This commit also adds a DEFINE for the default timeout value.

Change-Id: Ibb60e74a0803f05f37ac13ca529d77b4cb736025
2022-12-27 17:03:08 +00:00
Oliver Smith
f80ab768d0 osmo_mdns_rfc_record/question_encode: remove ctx
Remove the ctx argument to both functions, as it's not used anymore.

Related: OS#5821
Change-Id: I5e3dd18bf08f7aa42f49c262e13250778ea0c6a2
2022-12-23 13:51:28 +01:00
Oliver Smith
5decd49713 mslookup: use apn functions from libosmocore
Use the apn functions from libosmocore to encode and decode qnames to
avoid code duplication and to avoid unnecessary dynamic allocation.

The unit tests for encoding and decoding rfc_question / rfc_record are
still passing and have the same output.

Fixes: OS#5821
Change-Id: I09d3c617fd6eb4075084ee106d3f3c5803861d2f
2022-12-23 13:51:22 +01:00
Oliver Smith
c5f034b13d osmo_mdns_rfc_record_decode: proper free on err
Free the whole talloc tree of ret if we can't allocate memory for
ret->rdata.

Related: OS#5821
Change-Id: Iefc89e3c75a4bf4ffee3871c7b551a2a608f7d5f
2022-12-23 13:38:19 +01:00
Oliver Smith
01155eaee6 osmo_mdns_rfc_record_decode: check ret of talloc
Related: OS#5821
Change-Id: Icd0f54a8eb80ca50976f248e017f6e5c727385f3
2022-12-23 13:38:15 +01:00
arehbein
e4143234c8 osmo-hlr: Transition to use of 'telnet_init_default'
Related: OS#5809
Change-Id: I5cee719a9c4437712915f0f9760d606f6ec2dd43
2022-12-23 11:13:19 +00:00
Max
6263cf350a ctrl: take both address and port from vty config
Change-Id: Iecae15333a4e77b38d9bce8c8e591af3d5fcf347
2022-12-17 20:59:00 +03:00
Harald Welte
63eefabdde Add -Werror=implicit-int -Werror=int-conversion -Werror=old-style-definition
... if --enable-werror is used

Change-Id: Id465254bf12eb84acb116c86711a5b52b4d3ad35
2022-11-03 12:56:24 +01:00
Harald Welte
7a4765325d Support building with -Werror=strict-prototypes / -Werror=old-style-definition
Unfortunately "-std=c99" is not sufficient to make gcc ignore code that
uses constructs of earlier C standards, which were abandoned in C99.

See https://lwn.net/ml/fedora-devel/Y1kvF35WozzGBpc8@redhat.com/ for
some related discussion.

Change-Id: I861be39275b40c522c02f553074c5a4489e87127
2022-11-03 12:56:24 +01:00
Max
53f6067e97 hlr_vty.c: fix typo
Change-Id: If79ebd9a8998e64be55e52af43e426f37e3972af
2022-09-24 01:55:46 +00:00
Max
8023d246f2 Debian: install osmo-hlr-dgsm.cfg as example config
Related: OS#4107
Change-Id: Ia64f14ada006acb31c5f725dfa0d52f482d3e8b4
2022-09-18 20:19:42 +07:00
Max
00aea9e0d9 systemd: enable basic hardening
This ensures that systemd will not allow us to modify
/home, /root and /run/user which we shouldn't be doing anyway.
See https://www.freedesktop.org/software/systemd/man/systemd.exec.html
for details.

It should also should silence corresponding lintian warning.

Related: OS#4107
Change-Id: Ida5f13bdb9e5bd956c440a381d94eecc18f0b2ef
2022-09-18 19:23:52 +07:00
Max
023c6524a2 Debian: reformat package description
Shorten the lines of package description to comply with
Debian Policy Manual section 3.4.1

Related: OS#4107
Change-Id: Id6bbfc0b013f0e8da80af76206d3ac7fd6b6b0d4
2022-09-18 19:23:52 +07:00
Max
1d02b51a68 Debian: bump copyright year to match current
Related: OS#4107
Change-Id: I581e62b5410a9dddc6b5fd974081d633cc20416d
2022-09-18 19:23:23 +07:00
Max
78a9f92fda Ignore .deb build byproducts
Change-Id: Id36f55cd55be25f764c2b9515eff84d106bab1dc
2022-09-09 22:08:35 +07:00
Max
ad8866e86e Set working directory in systemd service file
By default systemd will execute service with root directory (or home directory for user instance) which might result in
attempts to create files in unexpected place. Let's set it to 'osmocom' subdir of state directory (/var/lib for system
instance) instead.

Related: OS#4821
Change-Id: I40b5d50470cb55ca94af5e17f21658181a02d4c2
2022-08-29 19:45:03 +07:00
Vadim Yanitskiy
6156950634 db_auc: hexparse_stmt(): check value returned by osmo_hexparse()
Change-Id: I78bb3aff9dd57a38278bb34113ea764e0a54c439
Fixes: CID#272997
2022-06-29 11:30:12 +00:00
Pau Espin Pedrol
65f51535d0 Bump version: 1.4.0.16-3863-dirty → 1.5.0
Change-Id: I016ddf4fd955c3b518e620a35f9a817f489e81c4
2022-06-28 18:38:31 +02:00
Pau Espin Pedrol
386381662c doc: Document new subscriber CTRL commands
Related: SYS#5993
Change-Id: I3e38d067bbc2ebb7f788dc56a5d56e1e4cafdc9c
2022-06-21 10:35:40 +02:00
Pau Espin Pedrol
777860ddb5 ctrl: Introduce CTRL command subscriber.by-*.aud3g <algo[,KI,(op|opc),OP_C[,ind_bitlen]]>
This command provides getter and setter to set and retrieve the
authentication data for 3g subscribers.

Change-Id: Ibe7aeec3cabab0406eb7a84ecd24e529ef1696c2
Related: SYS#5993
2022-06-21 10:35:40 +02:00
Pau Espin Pedrol
1d0a030aa4 ctrl: Introduce CTRL command subscriber.by-*.aud2g <algo[,ki]>
This command provides getter and setter to set and retrieve the
authentication data for 2g subscribers.

Change-Id: Ibebac232fa173bce8a075cacf477214d5bdb590f
Related: SYS#5993
2022-06-21 10:35:18 +02:00
Pau Espin Pedrol
3ca9a1fd4f ctrl: Introduce cmd SET subscriber.delete <imsi>
On success SET_REPLY contains the ID of the deleted subscriber.

Related: SYS#5993
Change-Id: I24c6149d7c223a12549d712a7929666220c0210f
2022-06-20 18:05:36 +02:00
Pau Espin Pedrol
b74769f1b4 cosmetic: hlr_vty_subscr.c: Fix trailing whitespace
Change-Id: Id751d227a52f39e3a8874d8b78c633b8d3eb9e74
2022-06-20 18:05:36 +02:00
Pau Espin Pedrol
140dffd8f7 ctrl: Introduce CTRL command subscriber.by-*.msisdn
This command provides getter and setter to set and retrieve the MSISDN
of a subscriber.

Related: SYS#5993
Change-Id: I5f2e807859f7e28e0984c8dc37edc69319fd8e10
2022-06-20 13:37:59 +02:00
Pau Espin Pedrol
d63ec88dba ctrl: Introduce cmd SET subscriber.create <imsi>
Create a new subscriber from CTRL, similar to VTY command
"imsi IDENT create".

On success SET_REPLY contains the ID of the newly created subscriber.

Related: SYS#5993
Change-Id: Id1b760cd07712245a0eeabaac7891bce93c1fe8e
2022-06-20 13:37:53 +02:00
Harald Welte
e427bb299f update git URLs (git -> https; gitea)
Change-Id: Iaab27a8e258a29a0bb51ee8d9f5faeb2c025f139
2022-06-18 12:08:31 +02:00
Pau Espin Pedrol
d456fced21 Fix db_subscr_create() not returning -EEXIST expected by VTY subscriber create cmd
As a result, the -EEXIST code path printing a specific error for
inserting already existing subscribers was not being triggered.

Change-Id: Id24dc6e0ff5115c8c9025404dd7296250d2b03ee
2022-06-17 19:09:39 +02:00
Pau Espin Pedrol
c772e525ef tests/ctrl: Move ERROR test scenario to proper file
Change-Id: I26ba561c22c40877d99f2aed27be2df9faaa4bec
2022-06-17 17:07:56 +02:00
Pau Espin Pedrol
83a41471da tests: Allow specyfing specific ctrl test to run
Similar to what's already available for vty tests.

Change-Id: I3b01edfb22197f4d46bd24e15bdcd37ea0382e4a
2022-06-17 17:03:25 +02:00
Pau Espin Pedrol
b4f25a0d1a ctrl: Mark function as static
Also move it more towards the end, where it is more expected as usually
done in ctrl/vty code.

Change-Id: Ieb956fb855752cfbe83d11aa0326685229a115e3
2022-06-17 15:56:27 +02:00
Vadim Yanitskiy
b246580900 tests: use 'check_PROGRAMS' instead of 'noinst_PROGRAMS'
When using 'check_PROGRAMS', autoconf/automake generates smarter
Makefiles, so that the test programs are not being compiled during
the normal 'make all', but only during 'make check'.

Change-Id: I70cf75b3cb6ae59c92248cc529546750fb0da07b
2022-04-14 02:22:14 +03:00
Vadim Yanitskiy
0c13953ed0 debian: add new 'osmo-mslookup-utils' package
Change-Id: I9dbe00187678a5032fb4ae32b496892fdc86ddb7
Related: OS#4706
2022-02-08 13:51:31 +06:00
Vadim Yanitskiy
77a1bf66e6 fixup: debian: remove unneeded dependency libdbd-sqlite3
Change-Id: I3ece7c32151f6f334d0595fdbf9099c930b22bb9
Fixes: I5bfe9c71740c1ced5bad0a41dfca568b9e00070c
2022-02-05 22:52:22 +06:00
Oliver Smith
37a5b70195 treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I4b20c685b6370bf5dc472a42664e2665eb0d8f8c
2021-12-14 12:15:54 +01:00
Pau Espin Pedrol
4d7cbfcc9a Bump version: 1.3.0.7-bfee → 1.4.0
Change-Id: I39bbc42009bf6291884f652618bfdf94b329a295
2021-11-16 14:56:41 +01:00
Oliver Smith
bfeea69cab debian/control: remove dh-systemd build-depend
Related: OS#5223
Change-Id: Ieb8669a9a43ea1acc6b2d8d2e363f2466c51697a
2021-09-01 16:07:06 +02:00
Neels Hofmeyr
3f9d1977df db v6: determine 3G AUC IND from VLR name
Each VLR requesting auth tuples should use a distinct IND pool for 3G
auth.  So far we tied the IND to the GSUP peer connection; MSC and SGSN
were always distinct GSUP peers, they ended up using distinct INDs.

However, we have implemented a GSUP proxy, so that, in a distributed
setup, a remotely roaming subscriber has only one direct GSUP peer
proxying for both remote MSC and SGSN. That means as soon as a
subscriber roams to a different site, we would use the GSUP proxy name
to determine the IND instead of the separate MSC and SGSN. The site's
MSC and SGSN appear as the same client, get the same IND bucket, waste
SQNs rapidly and cause auth tuple generation load.

So instead of using the local client as IND, persistently keep a list of
VLR names and assign a different IND to each. Use the
gsup_req->source_name as indicator, which reflects the actual remote
VLR's name (remote MSC or SGSN).

Persist the site <-> IND assignments in the database.

Add an IND test to db_test.c

There was an earlier patch version that separated the IND pools by
cn_domain, but it turned out to add complex semantics, while only
solving one aspect of the "adjacent VLR" problem. We need a solution not
only for CS vs PS, but also for 2,3G vs 4G, and for sites that are
physically adjacent to each other. This patch version does not offer any
automatic solution for that -- as soon as more than 2^IND_bitlen
(usually 32) VLRs show up, it is the responsibility of the admin to
ensure the 'ind' table in the hlr.db does not have unfortunate IND
assignments. So far no VTY commands exist for that, they may be added in
the future.

Related: OS#4319
Change-Id: I6f0a6bbef3a27507605c3b4a0e1a89bdfd468374
2021-07-19 09:01:06 +00:00
Pau Espin Pedrol
608e2e483f db: Avoid use uninitialized rc if running 0 statements
Caught by new gcc 11.1.0:
/git/osmo-hlr/src/db.c:257:16: error: ‘rc’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  257 |         return rc;
      |                ^~

Change-Id: I45e1fede234cd4446a7061fb908bf344eee72f5a
2021-07-15 13:33:16 +02:00
Oliver Smith
60673e7f77 Add post-upgrade script for automatic db upgrade
Closes: OS#5138
Change-Id: I34e943e5020285f63a2162010eb42675af1520bf
2021-06-01 09:29:00 +02:00
Keith
ca8e6efca6 vty: enable show subscribers filtered by IMEI
In 89fda3024a I added a
vty command to show a summary of filtered subscribers by imsi
or msisdn. In practice there is a also need to be able to
filter on IMEI.

The idea here is not to replace every operation that could be
done directly on the sql database in the vty, but this one
is useful.

Change-Id: Ic4a11d3ebcf8909c68e9f4617e94dc822491e008
2021-05-13 18:00:43 +00:00
Harald Welte
ed2e36316b add README.md file as customary for cgit, github, gitlab, etc.
Change-Id: Ide03584aae21d5972e96e7862feb86e1265c29b3
2021-03-21 22:46:07 +01:00
Keith
649c335602 Correct configuration written from vty
osmo-hlr would not read back written configuration due to
bad indentation in the mslookup->server->service section.

Also ipa-name was missing.

Change-Id: Ied4b9504f06a51c3895054a8b9d07a67eda3aeeb
2021-02-26 01:21:41 +01:00
Pau Espin Pedrol
6240465503 Bump version: 1.2.0.78-8c90-dirty → 1.3.0
Change-Id: Iffdee17c1f70f472fb9cfe722b77967c2634ea37
2021-02-23 18:13:54 +01:00
Harald Welte
8c9087dd16 manuals: generate vty reference xml at build time
Move 'doc' subdir further down to "make sure" the osmo-hlr binary is built
before the docs

Remove hlr_vty_reference from the source tree.

In manuals//Makefile.am use the new BUILT_REFERENCE_XML feature recently added
to osmo-gsm-manuals, and add a build target to generate the XML using the new
osmo-hlr --vty-ref-xml cmdline switch.

Change-Id: I02c9862ced48ce4271b328a0963d5f09086b295c
Depends: I613d692328050a036d05b49a436ab495fc2087ba
Related: OS#5041
2021-02-23 16:48:36 +00:00
Harald Welte
2bd1a45553 main: add --vty-ref-mode, use vty_dump_xml_ref_mode()
Change-Id: I939f75d6c03145dbe185d849b95b2dd99782f35c
Depends: Ie2022a7f9e167e5ceacf15350c037dd43768ff40
Related: OS#5041
2021-02-23 16:48:36 +00:00
Pau Espin Pedrol
d6993ea4b5 tests: Replace deprecated API log_set_print_filename
log_set_print_category_hex(0) is added in some places since the old API
used to set that internally to keep backward compatiblity.

Change-Id: I3cf46b7c24452254319d5c3eacceff418211bcf7
2021-02-19 13:31:13 +01:00
Pau Espin Pedrol
f551ccf9fb .gitignore: Ignore new autofoo tmp files
Change-Id: I155e9fd644263a8b47301f6b0986b9beb5a45d0f
2021-02-04 12:46:34 +01:00
Keith
b5a5676cff Fix Coverity Warnings
Explicitly check filter_type is not NULL even though the current code
never passed a NULL filter_type unless filter was also NULL.

Remove unreachable code.

Change-Id: Ib2bd9b2d6e9e559e61a895a25235669dae05fdf6
Related: coverity CID#216865
Related: coverity CID#216867
2021-01-30 07:35:26 +01:00
Keith
89fda3024a Add vty command to show summary of all or filtered subscribers
Adds the following commands:

show subscribers all - Display summary of all entries in HLR
show subscribers (imsi|msisdn|cs|ps) ... As above but filter on search field/string
show subscribers last seen - Display only subscribers with data in
Last LU update field, and sorts by Last LU.

Change-Id: I7f0573381a6d0d13841ac6d42d50f0e8389decf4
2021-01-29 21:26:08 +00:00
Oliver Smith
dd746949d0 configure.ac: set -std=gnu11
Change-Id: I5ea5365338248e29591a40ec1e19db95f8ae6877
2021-01-28 09:28:12 +00:00
Keith
cc90bfd0f4 Correct vty inline help for show subscriber
Change-Id: I035435859b60ce6d54da307c0d6397d4bd515439
2021-01-19 07:18:50 +00:00
Oliver Smith
f4d64cb98b contrib/jenkins: don't build osmo-gsm-manuals
Related: OS#4912
Change-Id: I22246f3ff105183a7a7a0279fd6c5cde9cd19952
2021-01-13 13:15:54 +01:00
Harald Welte
bd94b41fa8 auc_test.c: Add some comments on what the test cases actually do
Change-Id: Id2b9cf12823e05aeadc6f15df396f8a46ae1639d
2021-01-04 14:03:25 +01:00
Harald Welte
6e237d3a90 support the XOR algorithm for UMTS AKA
Test USIMs as specified by 3GPP use the XOR algorithm not only for 2G
but also for 3G.  libosmocore includes the XOR-3G support since v1.3.0,
but osmo-hlr somehow never made use of it.

Change-Id: I3a452af9c18cd90d00ab4766d6bd1679456bc1a2
Closes: OS#4924
2020-12-28 22:40:09 +01:00
Vadim Yanitskiy
dac855e5c8 USSD: add special 'idle' handler to IUSE for testing
Change-Id: I0d566a60e95ce2da951f22ad47c6155c5b6a338c
2020-11-17 18:50:27 +07:00
Vadim Yanitskiy
6a6c7f87ca USSD: fix handle_ussd(): do not free() unconditionally
An internal handler may want to continue session, e.g. to request
more information from the MS.  Let's make the handlers responsible
for session state management, and check that state before calling
ss_session_free(), so a session can remain alive.

Before this patch ss->state was not set/used at all...

Change-Id: I49262e7fe26f29dedbf126087cfb8f3bb3c548dc
2020-11-17 18:47:58 +07:00
Vadim Yanitskiy
6cfef3ac26 doc/manuals: re-organize description of internal USSD handlers
Change-Id: Ieddde02f3f41e0eb05b7223026da4252c17c3712
2020-11-17 18:47:58 +07:00
Vadim Yanitskiy
66f0b5fbea doc/manuals: fix s/There/The/ in 'USSD Configuration'
Change-Id: Idbff93b6be5f546f18642ee330746e8734378b39
2020-11-17 18:47:58 +07:00
Vadim Yanitskiy
c47d5c0d77 cosmetic: fix spelling in logging message: existAnt -> existEnt
Change-Id: Id803d0c71f3762b8353289853918ea78859780b4
2020-10-29 18:05:22 +07:00
Harald Welte
dfbc2cbbc2 Use OSMO_FD_* instead of deprecated BSC_FD_*
Change-Id: I24a9a81382ea723ad20b8caa61fb5c2abcdd86d0
2020-10-18 22:39:01 +02:00
Pau Espin Pedrol
89649ea997 contrib/jenkins: Enable parallel make in make distcheck
Change-Id: I1973e7a2a3be07b2db1db1cf5f05fd29101ee06a
Related: OS#4421
2020-10-12 19:29:36 +02:00
Pau Espin Pedrol
23ac586522 Set TCP NODELAY sockopt to GSUP cli and srv connections
GSUP is message based on top of IPA, and hence TCP. We don't want to
have Nagle algorithm enabled, since we are interested in having messages
sent as quickly as possible and there's no need for lower layers to wait
for more data (because we send all the message data at once).

Related: OS#4499
Change-Id: I4653b95ef0d4e1184f81f28408e9eb5d665206ec
2020-10-12 16:39:58 +02:00
Keith
de50b20116 osmo-hlr-db-tool: Make import from osmo-nitb less "lossy"
Include the IMEI and the last seen time in an import from
an osmo-nitb database.

Change-Id: Ic47e549be3551ae43ab6a84228d47ae03e9652a6
2020-09-23 19:41:27 +02:00
Pau Espin Pedrol
ed18fa908c Support setting rt-prio and cpu-affinity mask through VTY
Change-Id: I33101aae3e2851febc335f6fbf96228eab7cf6df
Depends: libosmocore.git Change-Id If76a4bd2cc7b3c7adf5d84790a944d78be70e10a
Depends: osmo-gsm-masnuals.git Change-Id Icd75769ef630c3fa985fc5e2154d5521689cdd3c
Related: SYS#4986
2020-08-18 13:25:34 +02:00
Pau Espin Pedrol
f464fff173 doc: Update VTY reference xml file
Change-Id: Ifdefba331ae2542b1cdc5860d0f9e53ef9f703c4
2020-08-18 12:50:21 +02:00
Pau Espin Pedrol
e893eeb1b3 configure.ac: Fix trailing whitespace
Change-Id: If0569167922695bb88c8f168f89fa300dd181c72
2020-08-18 12:49:05 +02:00
Vadim Yanitskiy
b77d568196 debian/control: change maintainer to the Osmocom team / mailing list
Change-Id: I6b38640b57480c6950be491eeb3c5167be1c6aab
2020-08-13 16:09:02 +07:00
Neels Hofmeyr
80cb6c93b9 manual: describe subscriber import by SQL
It seems a bad idea to cement the internal SQL structure in the user manual,
but since we currently lack a safe and portable import mechanism (like CSV
import in osmo-hlr-db-tool), this is currently valuable info to users.

Change-Id: I3246e6d5364215a71c33b5aca876deab7b6cfd70
2020-06-29 17:12:06 +02:00
Neels Hofmeyr
565cf83a42 osmo-mslookup-client: fix segfault for respond_error() caller
respond_error() passes r == 0. On error, consider it the last response for that
request.

Change-Id: I1acb0b8aa00c098d1f1f1cc17035daa38ce29fd3
2020-06-03 18:38:56 +02:00
Vadim Yanitskiy
fa20702e67 gsup_server: fix typo: s/omso_gsup_message/osmo_gsup_message/
Change-Id: I77eac6df9836f2361d87df7ba5ab6fc14ba06b1d
2020-05-31 18:52:38 +00:00
Oliver Smith
949a53cdf0 Makefile.am: EXTRA_DIST: debian, contrib/*.spec.in
Change-Id: I401a4849ae186bddd667446ff7247976090e1db7
2020-05-22 13:40:09 +02:00
Oliver Smith
102e362943 contrib: integrate RPM spec
Remove OpenSUSE bug report link, set version to @VERSION@, make it build
with CentOS 8 etc.

Related: OS#4550
Change-Id: I38f80d0f867a2bbaa09b5a42cad5028f23a8effa
2020-05-19 17:08:28 +02:00
Oliver Smith
2f7fb2e36b contrib: import RPM spec
Copy the RPM spec file from:
https://build.opensuse.org/project/show/home:mnhauke:osmocom:nightly

Related: OS#4550
Change-Id: Icb6f4335d5157f058b39701e9fcb332264911ba3
2020-05-19 17:08:28 +02:00
Philipp Maier
377fe5a645 doc: do not use loglevel info for log category ss
The log category ss uses info as loglevel vor ss, this is to verbose,
lets use notice instead.

Change-Id: I192a5f07cb7f45adb6f3af1c511b706738bdadf4
2020-05-12 13:34:13 +02:00
Neels Hofmeyr
c7ea21357a esme_dgsm.py: add --always-fail option for debugging SMPP
Change-Id: Ibacf2676cae40712c89b57ced34085311d9a416d
2020-05-09 21:07:53 +00:00
Neels Hofmeyr
9b8e7b4e39 hlr_subscr_nam(): fix condition to fix nam=false notifications
Firstly, vlr_number[] is an array and we need to check the first char for nul
instead of the pointer.

Also, osmo_ipa_name_set_str() returns zero on success, so the condition is
reversed.

hlr_subscr_nam() was rewritten in I3a8dff3d4a1cbe10d6ab08257a0138d6b2a082d9
ad868e29ba and this likely fixes a bug introduced
there.

Related: coverity CID#210169
Change-Id: I3a0e9ed4b865c88aa4a6341a3bf1a96c10d20ed9
2020-05-04 19:24:26 +02:00
Neels Hofmeyr
010ceb8206 osmo_mslookup_server_mdns_rx(): handle read() rc == 0
Coverity says "tainted buffer", I hope it means the case of read() returning
zero.

Related: coverity CID#210170
Change-Id: Ia2d57cb8bbacc6f54dc410047da69a983aedd24d
2020-05-04 19:15:29 +02:00
Neels Hofmeyr
1bd3ec49b1 gsup_server.c: properly handle negative rc from osmo_gsup_conn_ccm_get()
Related: coverity CID#210171
Change-Id: I5b56fe33cbc75679a3fffc034a53f06cd0e4043b
2020-05-04 17:53:52 +02:00
Neels Hofmeyr
dfe6f41c81 osmo_gsup_req_new(): require from_peer != NULL
In practice, from_peer is always non-NULL, yet some conditions checked against
NULL, looking like a possible NULL deref. Require non-NULL.

Related: coverity CID#210172
Change-Id: I3cb73ec0d31f84d4b613ecb026169c944d240e4c
2020-05-04 17:37:15 +02:00
Neels Hofmeyr
3e79a38440 make osmo_cni_peer_id_cmp() NULL safe
Related: coverity CID#210172
Change-Id: I400b23ac3f0eb68d5e4c757ea02d130fbe12f80b
2020-05-04 17:33:36 +02:00
Neels Hofmeyr
a450a85956 auc3g: officially wrap IND around IND_bitlen space
To determine distinct IND pools for each connected VLR, we need to pick ever
increasing values for any new peer showing up. Each subscriber's individual
IND_bitlen is then required to modulo the least significant N of bits that fit
in its IND_bitlen to effectively round-robin in the available IND pool space.
So far we did that but issued a warning message. This is actually exactly what
we want and it doesn't need to be treated like it weren't so.

Change-Id: I716d8a8a249235c8093d7a6a78b3535d893d867e
2020-04-30 19:22:24 +02:00
Neels Hofmeyr
26b4905e7f vty: show subscriber: show lu d,h,m,s ago, not just seconds
Change-Id: I0fe34e0f065160ef959b2b7b4dd040f3f2985f43
2020-04-30 19:22:24 +02:00
Neels Hofmeyr
d9b3606234 vty: show subscriber: change format of 'last LU seen'
So far, the time string format comes from ctime_r, and we manually add "UTC" to it.

The ctime_r format is wildly chaotic IMHO, mixing weekday, day-of-month and
hour and year in very unsorted ways.

Adding "UTC" to it is non-standard.

Instead use an ISO-8601 standardized time string via strftime().

Change-Id: I6731968f05050399f4dd43b241290186e0c59e1a
2020-04-30 19:22:24 +02:00
Neels Hofmeyr
0d82a87c0d drop error log for when a subscriber does not exist
Checking for existence of a subscriber and seeing that there is none is not
inherently an error. However, osmo-hlr currently logs on all occasions:

  DAUC ERROR Cannot read subscriber from db: MSISDN='1001': No such subscriber

This spams the ERROR log level. Particularly when a D-GSM setup does subscriber
existence checks for every incoming mslookup request, that potentially creates
constant ERROR logging.

The "No such subscriber" part comes from db_sel(), which might also return an
sqlite3_errmsg(). We still want those sqlite3_errmsg()es in the ERROR log.

Hence print an ERROR log only if db_sel() returns an rc != -ENOENT.

Change-Id: I5044e9b4519b948edc4e451cef0f7830d315619b
2020-04-30 19:22:24 +02:00
Neels Hofmeyr
9489a9ce4b adoc: add D-GSM chapter to osmohlr-usermanual
Change-Id: I392b5523870c2ef3267179160028d26f3f761b77
2020-04-30 19:22:24 +02:00
Oliver Smith
edc27ef390 hlr_vty_subscr: prettier output for last LU seen
Extend the "last LU seen on ..." line with the amount of seconds that
passed since now, or "(invalid timestamp)".

Patch split from Id7fc50567211a0870ac0524f6dee94d4513781ba, because it
depends on timestamp_age which was just added in
Ife4a61d71926d08f310a1aeed9d9f1974f64178b.

Change-Id: I24f9e86c1aa0b1576290094e024562f41b988f37
2020-04-30 19:22:24 +02:00
Neels Hofmeyr
af748923bd gsup_server: send routing error back to the correct peer
If a peer attempts to add a route to an ipa-name that we already have in the
routing system, don't send the routing error to the peer that already has the
name, but to the peer that attempts to re-use it and would cause the collision.

This is fixing a situation where for example a locally attached MSC has name
'MSC-1', and a remote site is proxying GSUP here for a remote MSC that also has
the name 'MSC-1'. Send the routing error back to the proxy, not local 'MSC-1'.

Change-Id: Icafaedc11b5925149d338bdcb987ae985a7323d6
2020-04-30 19:22:24 +02:00
Neels Hofmeyr
76328bdc91 D-GSM 3/n: implement roaming by mslookup in osmo-hlr
Add mslookup client to find remote home HLRs of unknown IMSIs, and
proxy/forward GSUP for those to the right remote HLR instances.

Add remote_hlr.c to manage one GSUP client per remote HLR GSUP address.

Add proxy.c to keep state about remotely handled IMSIs (remote GSUP address,
MSISDN, and probably more in future patches).  The mslookup_server that
determines whether a given MSISDN is attached locally now also needs to look in
the proxy record: it is always the osmo-hlr immediately peering for the MSC
that should respond to mslookup service address queries like SIP and SMPP.
(Only gsup.hlr service is always answered by the home HLR.)

Add dgsm.c to set up an mdns mslookup client, ask for IMSI homes, and to decide
which GSUP is handled locally and which needs to go to a remote HLR.

Add full VTY config and VTY tests.

For a detailed overview of the D-GSM and mslookup related files, please see the
elaborate comment at the top of mslookup.c (already added in an earlier patch).

Change-Id: I2fe453553c90e6ee527ed13a13089900efd488aa
2020-04-30 19:22:24 +02:00
Neels Hofmeyr
407925dcab D-GSM 2/n: implement mDNS method of mslookup server
Implement the mslookup server's mDNS responder, to actually service remote
mslookup requests:
- VTY mslookup/server config with service names,
- the mslookup_mdns_server listening for mslookup requests,

For a detailed overview of the D-GSM and mslookup related files, please see the
elaborate comment at the top of mslookup.c (already added in an earlier patch).

Change-Id: I5cae6459090588b4dd292be90a5e8903432669d2
2020-04-30 19:22:24 +02:00
Neels Hofmeyr
ab7dc40f16 D-GSM 1/n: add mslookup server in osmo-hlr
Implement the mslookup server to service remote mslookup requests.

This patch merely adds the logic to answer incoming mslookup requests, an
actual method to receive requests (mDNS) follows in a subsequent patch.

- API to configure service names and addresses for the local site (per MSC).
- determine whether a subscriber is on a local MSC
  (checking the local proxy will be added in subsequent patch that adds proxy
  capability).
- VTY config follows in a subsequent patch.

For a detailed overview of the D-GSM and mslookup related files, please see the
elaborate comment at the top of mslookup.c (already added in an earlier patch).

Change-Id: Ife4a61d71926d08f310a1aeed9d9f1974f64178b
2020-04-30 19:22:24 +02:00
Neels Hofmeyr
86b507b6ea test_nodes.vty: remove cruft
This stuff is not testing osmo-hlr specific nodes, remove.

Change-Id: Ia11a209778b78ab02424e2abf3f9004fe97cf570
2020-04-30 19:22:24 +02:00
Neels Hofmeyr
d017d7b215 enlarge the GSUP message headroom
Make room for (more) arbitrary IPA headers, like longer IPA names as configured
by the user.

Change-Id: I7d86f2dadcae29fe1550ea2c9773394ab31a837b
2020-04-30 19:22:24 +02:00
Neels Hofmeyr
04c2375b38 db v5: prep for D-GSM: add vlr_via_proxy and sgsn_via_proxy
D-GSM will store in the HLR DB whether a locally connected MSC has attached the
subscriber (last_lu_seen[_ps]), or whether the attach happened via a GSUP proxy
from a different site.

Add columns for this separately in this patch.

Change-Id: I98c7b3870559ede84adf56e4bf111f53c7487745
2020-04-30 19:22:24 +02:00
Neels Hofmeyr
939f508f00 gsup client: add up_down_cb(), add osmo_gsup_client_create3()
For the GSUP clients in upcoming D-GSM enabled osmo-hlr, it will be necessary
to trigger an event as soon as a GSUP client connection becomes ready for
communication. Add the osmo_gsup_client->up_down_cb.

Add osmo_gsup_client_create3() to pass the up_down_cb in the arguments. Also
add a cb data argument to populate the already existing osmo_gsup_client->data
item directly from osmo_gsup_client_create3().

We need the callbacks and data pointer in the osmo_gsup_client_create()
function right before startup, because this function immediately starts up the
connection. Who knows whether callbacks might trigger right away.

Because there are so many arguments, and to prevent the need for ever new
versions of this function, pass the arguments as an extendable struct.

Change-Id: I6f181e42b678465bc9945f192559dc57d2083c6d
2020-04-30 19:21:18 +02:00
Neels Hofmeyr
c79bcdedc9 2/2: wrap ipa_name in osmo_cni_peer_id with type enum and union
To be prepared for the future in public API, wrap the new osmo_ipa_name struct
in an enum-type and union called osmo_cni_peer.

During code review it was requested to insert an ability to handle different
kinds of peer id, in order to be able to add a Global Title in the future.

Use the generic osmo_cni_peer only in the publicly visible API. For osmo-hlr
internal code, I intend to postpone implementing this into the future, when a
different peer identification actually gets introduced.

This way we don't need to implement it now in all osmo-hlr code paths (save
time now), but still make all external API users aware that this type may be
extended in the future.

Change-Id: Ide9dcdca283ab989240cfc6e53e9211862a199c5
2020-04-30 19:19:17 +02:00
Neels Hofmeyr
ad868e29ba 1/2: refactor: add and use lu_fsm, osmo_gsup_req, osmo_ipa_name
These are seemingly orthogonal changes in one patch, because they are in fact
sufficiently intertwined that we are not willing to spend the time to separate
them. They are also refactoring changes, unlikely to make sense on their own.

** lu_fsm:

Attempting to make luop.c keep state about incoming GSUP requests made me find
shortcomings in several places:
- since it predates osmo_fsm, it is a state machine that does not strictly
  enforce the order of state transitions or the right sequence of incoming
  events.
- several places OSMO_ASSERT() on data received from the network.
- modifies the subscriber state before a LU is accepted.
- dead code about canceling a subscriber in a previous VLR. That would be a
  good thing to actually do, which should also be trivial now that we record
  vlr_name and sgsn_name, but I decided to remove the dead code for now.

To both step up the LU game *and* make it easier for me to integrate
osmo_gsup_req handling, I decided to create a lu_fsm, drawing from my, by now,
ample experience of writing osmo_fsms.

** osmo_gsup_req:

Prepare for D-GSM, where osmo-hlr will do proxy routing for remote HLRs /
communicate with remote MSCs via a proxy:

a) It is important that a response that osmo-hlr generates and that is sent
back to a requesting MSC contains all IEs that are needed to route it back to
the requester. Particularly source_name must become destination_name in the
response to be able to even reach the requesting MSC. Other fields are also
necessary to match, which were so far taken care of in individual numerous code
paths.

b) For some operations, the response to a GSUP request is generated
asynchronously (like Update Location Request -> Response, or taking the
response from an EUSE, or the upcoming proxying to a remote HLR). To be able to
feed a request message's information back into the response, we must thus keep
the request data around. Since struct osmo_gsup_message references a lot of
external data, usually with pointers directly into the received msgb, it is not
so trivial to pass GSUP message data around asynchronously, on its own.

osmo_gsup_req is the combined solution for both a and b: it keeps all data for
a GSUP message by taking ownership of the incoming msgb, and it provides an
explicit API "forcing" callers to respond with osmo_gsup_req_respond(), so that
all code paths trivially are definitely responding with the correct IEs set to
match the request's routing (by using osmo_gsup_make_response() recently added
to libosmocore).

Adjust all osmo-hlr code paths to use *only* osmo_gsup_req to respond to
incoming requests received on the GSUP server (above LU code being one of
them).

In fact, the same should be done on the client side. Hence osmo_gsup_req is
implemented in a server/client agnostic way, and is placed in
libosmo-gsupclient. As soon as we see routing errors in complex GSUP setups,
using osmo_gsup_req in the related GSUP client is likely to resolve those
problems without much thinking required beyond making all code paths use it.

libosmo-gsupclient is hence added to osmo-hlr binary's own library
dependencies. It would have been added by the D-GSM proxy routing anyway, we
are just doing it a little sooner.

** cni_peer_id.c / osmo_ipa_name:

We so far handle an IPA unit name as pointer + size, or as just pointer with
implicit talloc size. To ease working with GSUP peer identification data, I
require:

- a non-allocated storage of an IPA Name. It brings the drawback of being
  size limited, but our current implementation is anyway only able to handle
  MSC and SGSN names of 31 characters (see struct hlr_subscriber).
- a single-argument handle for IPA Name,
- easy to use utility functions like osmo_ipa_name_to_str(), osmo_ipa_name_cmp(), and copying
  by simple assignment, a = b.

Hence this patch adds a osmo_ipa_name in cni_peer_id.h and cni_peer_id.c. Heavily
used in LU and osmo_gsup_req.

Depends: libosmocore Id9692880079ea0f219f52d81b1923a76fc640566
Change-Id: I3a8dff3d4a1cbe10d6ab08257a0138d6b2a082d9
2020-04-30 19:16:09 +02:00
Oliver Smith
0c27a4c2d1 Cosmetic: mention OS#4491 in location cancel code
Change-Id: Idce0816172b92699d86ba3574a4fded0b73333cf
2020-04-16 09:16:27 +02:00
Eric
08358b2752 configure.ac: fix libtool issue with clang and sanitizer
As pointed out at https://github.com/libexpat/libexpat/issues/312
libtool does not play nice with clang sanitizer builds at all.
For those builds LD shoud be set to clang too (and LDFLAGS needs the
sanitizer flags as well), because the clang compiler driver knows how
linking to the sanitizer libs works, but then at a later stage libtool
fails to actually produce the shared libraries and the build fails. This
is fixed by this patch.

Addtionally LD_LIBRARY_PATH has no effect on conftest runs during
configure time, so the rpath needs to be set to the asan library path to
ensure the configure run does not fail due to a missing asan library,
i.e.:

SANS='-fsanitize=memory -fsanitize-recover=all -shared-libsan'
export CC=clang-10
ASANPATH=$(dirname `$CC -print-file-name=libclang_rt.asan-x86_64.so`)
export LDFLAGS="-Wl,-rpath,$ASANPATH $SANS $LDFLAGS"

Change-Id: Ib98b84ac156f52ecdbb7ae49eaaea35442527b22
2020-04-11 18:11:26 +00:00
Oliver Smith
5424dcb879 mslookup_client_mdns_test: no automatic skip
Exit with error code if multicast is disabled. The test is disabled by
default already, so when explicitly enabling it, we should not
automatically skip it.

Related: OS#4385
Change-Id: I82022c23fa9c40535f922b12d917efd7e229912b
2020-02-14 11:16:47 +00:00
Oliver Smith
f0e90e6bd5 mslookup_client_mdns_test: disable by default
Only build and run the test, if --enable-mslookup-client-mdns-test is
passed to ./configure. Enable that option in jenkins.sh.

Related: OS#4385
Change-Id: Ie0cd4b0c55a1fbb00c215aeec7dcd0c15805add3
2020-02-14 11:16:47 +00:00
Vadim Yanitskiy
15ad7bef5f db: fix possible SQLite3 allocated memory leak in db_open()
From https://sqlite.org/c3ref/exec.html:

  To avoid memory leaks, the application should invoke sqlite3_free()
  on error message strings returned through the 5th parameter of
  sqlite3_exec() after the error message string is no longer needed.
  If the 5th parameter to sqlite3_exec() is not NULL and no errors
  occur, then sqlite3_exec() sets the pointer in its 5th parameter
  to NULL before returning.

Change-Id: Ic9ed9bad3165bc4a637fe963f51e923f012e19ac
Fixes: CID#208182
2020-02-09 05:32:48 +07:00
Oliver Smith
74e7072f63 mdns_rfc.c: fix possible access of uninit. mem
Fixes: CID#207548
Change-Id: Ifa269d8a88d84c01349668cdd8d1f1d24c12c6d8
2020-01-31 15:27:50 +00:00
Neels Hofmeyr
4fa9653733 gsup_client.c: fix deprecation for client create func
Change-Id: Iab9f416519b5df3bd4683592b2976f16675d9be7
2020-01-29 12:48:26 +01:00
Oliver Smith
5e5ce4aef2 mdns_sock.c: fix resource leak of sock
Fixes: CID#207542
Change-Id: I0216b17c3ff67910a39520e2f2a5a16e23575a86
2020-01-14 08:43:52 +01:00
Oliver Smith
9e533f666d osmo-mslookup-client: fix dereferencing null
Fixes: CID#207543
Change-Id: Ia9ff5b2c767853dd00f577a7bc3583f408e061b5
2020-01-14 08:40:34 +01:00
Oliver Smith
544b15d3fa osmo-mslookup-client.c: fix dereferencing null
Fixes: CID#207544
Change-Id: I51b974420975e670708f0d2318f63615d281922c
2020-01-14 08:40:19 +01:00
Oliver Smith
89afb7f78b mslookup_client_mdns.c: fix dereferencing null
Fixes: CID#207545
Change-Id: I0f7fbbdb663304bd5214cba4a6e4abe1dd165cfa
2020-01-13 15:00:37 +01:00
Oliver Smith
b1775162ea mdns_msg.c: always call va_end
Fixes: CID#207546
Change-Id: I39829e78619a6412618e1140ff9b1185bad975bd
2020-01-13 14:57:18 +01:00
Oliver Smith
f55f605931 mslookup_client.c: fix dereferencing null pointer
Fixes: CID#207547
Change-Id: If19e1e68fad76a3d65788ac208da7dde1f8745c1
2020-01-13 14:52:51 +01:00
Neels Hofmeyr
fbe4929543 fix missing braces in LOGP_GSUP_FWD
Change-Id: I8634ea8822c8ccba4081014c5540f2b6a229fc7e
2020-01-13 14:12:00 +01:00
Oliver Smith
e53a34a7e1 contrib/dgsm/ add example esme and dialplan
Add example scripts for the distributed GSM network:

esme_dgsm.py: connect to the SMPP port of OsmoMSC A and forward SMS to the SMPP
port of OsmoMSC B. The IP and port of OsmoMSC B is retrieved by the receiver's
MSISDN using osmo-mslookup-client.

contrib/dgsm/freeswitch_dialplan_dgsm.py: resolve the destination SIP servers
of calls with osmo-mslookup-client and bridge the calls accordingly.

For a detailed overview of the D-GSM and mslookup related files, please see the
elaborate comment at the top of mslookup.c (already added in an earlier patch).

Related: OS#4254
Related: OS#4255
Change-Id: I26e8dd8d9a08187fccb3e74ee91366bc24f6c608
2020-01-13 14:12:00 +01:00
Neels Hofmeyr
52ef60fe96 add osmo-mslookup-client program (#2)
Standalone program using libosmo-mslookup to easily integrate with programs
that want to connect services (SIP, SMS,...) to the current location of a
subscriber. Also useful for manual testing.

For a detailed overview of the D-GSM and mslookup related files, please see the
elaborate comment at the top of mslookup.c (already added in an earlier patch).

Resubmit of 637bbfcd92 after revert in
41fe362591.

Change-Id: Ie39d30e20461ab10ae3584863d8bfc6b76a12f37
2020-01-13 14:11:48 +01:00
Oliver Smith
3a9f267983 add mDNS lookup method to libosmo-mslookup (#2)
Add the first actually useful lookup method to the mslookup library: multicast
DNS.

The server side is added in a subsequent commit, when the mslookup server is
implemented for the osmo-hlr program.

Use custom DNS encoding instead of libc-ares (which we use in OsmoSGSN
already), because libc-ares is only a DNS client implementation and we will
need both client and server.

Resubmit of f10463c5fc after being
reverted in 110a49f69f. This new version
skips the mslookup_client_mdns test if multicast is not supported in the
build environment. I have verified that it doesn't break the build
anymore in my own OBS namespace.

Related: OS#4237, OS#4361
Patch-by: osmith, nhofmeyr
Change-Id: I3c340627181b632dd6a0d577aa2ea2a7cd035c0c
2020-01-13 14:10:50 +01:00
Oliver Smith
5436c77a96 Makefile.am: fix pkgconfig_DATA
Fix building debian packages:
	dh_install: Cannot find (any matches for) "usr/lib/*/pkgconfig/libosmo-mslookup.pc" (tried in "." and "debian/tmp")
	dh_install: libosmo-mslookup-dev missing files: usr/lib/*/pkgconfig/libosmo-mslookup.pc
	dh_install: missing files, aborting

Fixes: bf7deda0fc ("add libosmo-mslookup abstract client")
Change-Id: Ib0bce2d09b41834f7331969eaf7c57a9787f7efb
2020-01-13 14:08:27 +01:00
Harald Welte
110a49f69f Revert "add mDNS lookup method to libosmo-mslookup"
This reverts commit f10463c5fc, as it
causes all OBS osmo-hlr builds to fail in the mslookup_client_mdns test.

Change-Id: I5aec5b59f304c7f732c4a31131beedf29c966d9d
2020-01-12 16:27:42 +01:00
Harald Welte
41fe362591 Revert "add osmo-mslookup-client program"
This reverts commit 637bbfcd92, as it
is a follow-up commit to Change-Id I03a0ffa1d4dc1b24ac78a5ad0975bca90a49c728
which causes all OBS osmo-hlr builds to fail in the mslookup_client_mdns test.

Change-Id: I43084ac3b24684f17df43fefc82019e44baaa236
2020-01-12 16:26:52 +01:00
Alexander Couzens
0bb8fce2f1 hlr: remove unused internal USSD list
struct hlr.iuse_list is not used at all.

Change-Id: I7b51c195bbc107beb0a0bde72b266757fc4fd5e2
2020-01-11 23:48:38 +01:00
Neels Hofmeyr
637bbfcd92 add osmo-mslookup-client program
Standalone program using libosmo-mslookup to easily integrate with programs
that want to connect services (SIP, SMS,...) to the current location of a
subscriber. Also useful for manual testing.

For a detailed overview of the D-GSM and mslookup related files, please see the
elaborate comment at the top of mslookup.c (already added in an earlier patch).

Change-Id: Ie68a5c1db04fb4dff00dc3c774a1162f5b9fabf7
2020-01-10 16:07:40 +00:00
Oliver Smith
f10463c5fc add mDNS lookup method to libosmo-mslookup
Add the first actually useful lookup method to the mslookup library: multicast
DNS.

The server side is added in a subsequent commit, when the mslookup server is
implemented for the osmo-hlr program.

Use custom DNS encoding instead of libc-ares (which we use in OsmoSGSN
already), because libc-ares is only a DNS client implementation and we will
need both client and server.

Related: OS#4237
Patch-by: osmith, nhofmeyr
Change-Id: I03a0ffa1d4dc1b24ac78a5ad0975bca90a49c728
2020-01-10 16:07:40 +00:00
Oliver Smith
bf7deda0fc add libosmo-mslookup abstract client
mslookup is a key concept in Distributed GSM, which allows querying the current
location of a subscriber in a number of cooperating but independent core
network sites, by arbitrary service names and by MSISDN/IMSI.

Add the abstract mslookup client library. An actual lookup method (besides
mslookup_client_fake.c) is added in a subsequent patch.

For a detailed overview of this and upcoming patches, please see the elaborate
comment at the top of mslookup.c.

Add as separate library, libosmo-mslookup, to allow adding D-GSM capability to
arbitrary client programs.

osmo-hlr will be the only mslookup server implementation, added in a subsequent
patch.

osmo-hlr itself will also use this library and act as an mslookup client, when
requesting the home HLR for locally unknown IMSIs.

Related: OS#4237
Patch-by: osmith, nhofmeyr
Change-Id: I83487ab8aad1611eb02e997dafbcb8344da13df1
2020-01-10 16:07:40 +00:00
Alexander Couzens
81b92bbe69 hlr: respect the num_auth_vectors requested
Previous the hlr always returned the maximum possible auth vectors (5)
to the client. Even when only asked for a single auth vector.

Change-Id: I20c2b648456bc7ba1fc1321a7d42852158a3523c
2020-01-10 07:51:07 +01:00
Pau Espin Pedrol
3a66698d87 Bump version: 1.1.0.26-276c-dirty → 1.2.0
Change-Id: I5778895237511c62903784e8bed6920ecf058a50
2020-01-03 12:37:35 +01:00
109 changed files with 2858 additions and 3638 deletions

19
.gitignore vendored
View File

@@ -26,6 +26,7 @@ m4
*.m4
missing
.deps
*~
*.pc
.libs
@@ -67,3 +68,21 @@ doc/manuals/generated/
doc/manuals/osmomsc-usermanual.xml
doc/manuals/common
doc/manuals/build
contrib/osmo-hlr.spec
/debian/.debhelper/
/debian/libosmo-gsup-client-dev/
/debian/files
/debian/autoreconf.after
/debian/autoreconf.before
/debian/libosmo-gsup-client0/
/debian/libosmo-mslookup0/
/debian/osmo-hlr-dbg/
/debian/tmp/
/doc/manuals/vty/hlr_vty_reference.xml
/debian/libosmo-mslookup-dev/
/debian/osmo-hlr-doc/
/debian/osmo-hlr/
/debian/osmo-mslookup-utils/
/debian/*.log
/debian/*.substvars

View File

@@ -1,9 +1,9 @@
AUTOMAKE_OPTIONS = foreign dist-bzip2
SUBDIRS = \
doc \
src \
include \
doc \
sql \
contrib \
tests \
@@ -11,13 +11,16 @@ SUBDIRS = \
EXTRA_DIST = \
.version \
contrib/osmo-hlr.spec.in \
debian \
$(NULL)
AM_DISTCHECK_CONFIGURE_FLAGS = \
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libosmo-gsup-client.pc
pkgconfig_DATA = libosmo-gsup-client.pc \
libosmo-mslookup.pc
@RELMAKE@

65
README.md Normal file
View File

@@ -0,0 +1,65 @@
osmo-hlr - Osmocom HLR Implementation
=====================================
This repository contains a C-language implementation of a GSM Home
Location Register (HLR). It is part of the
[Osmocom](https://osmocom.org/) Open Source Mobile Communications
project.
Warning: While the HLR logical functionality is implemented, OsmoHLR
does not use the ETSI/3GPP TCAP/MAP protocol stack. Instead, a much
simpler custom protocol (GSUP) is used. This means, OsmoHLR is of
no use outside the context of an Osmocom core network. You can use
it with OsmoMSC, OsmoSGSN etc. - but not with third party components.
Homepage
--------
The official homepage of the project is
https://osmocom.org/projects/osmo-hlr/wiki
GIT Repository
--------------
You can clone from the official osmo-hlr.git repository using
git clone https://gitea.osmocom.org/cellular-infrastructure/osmo-hlr
There is a web interface at <https://gitea.osmocom.org/cellular-infrastructure/osmo-hlr>
Documentation
-------------
User Manuals and VTY reference manuals are [optionally] built in PDF form
as part of the build process.
Pre-rendered PDF version of the current "master" can be found at
[User Manual](https://ftp.osmocom.org/docs/latest/osmohlr-usermanual.pdf)
as well as the VTY reference manuals
* [VTY Reference Manual for osmo-hlr](https://ftp.osmocom.org/docs/latest/osmohlr-vty-reference.pdf)
Mailing List
------------
Discussions related to osmo-hlr are happening on the
openbsc@lists.osmocom.org mailing list, please see
https://lists.osmocom.org/mailman/listinfo/openbsc for subscription
options and the list archive.
Please observe the [Osmocom Mailing List
Rules](https://osmocom.org/projects/cellular-infrastructure/wiki/Mailing_List_Rules)
when posting.
Contributing
------------
Our coding standards are described at
https://osmocom.org/projects/cellular-infrastructure/wiki/Coding_standards
We us a gerrit based patch submission/review process for managing
contributions. Please see
https://osmocom.org/projects/cellular-infrastructure/wiki/Gerrit for
more details
The current patch queue for osmo-hlr can be seen at
https://gerrit.osmocom.org/#/q/project:osmo-hlr+status:open

9
TODO-RELEASE Normal file
View File

@@ -0,0 +1,9 @@
# When cleaning up this file: bump API version in corresponding Makefile.am and rename corresponding debian/lib*.install
# according to https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info
# In short:
# LIBVERSION=c:r:a
# If the library source code has changed at all since the last update, then increment revision: c:r + 1:a.
# If any interfaces have been added, removed, or changed since the last update: c + 1:0:0.
# If any interfaces have been added since the last public release: c:r:a + 1.
# If any interfaces have been removed or changed since the last public release: c:r:0.
#library what description / commit summary line

View File

@@ -12,6 +12,8 @@ AM_INIT_AUTOMAKE([foreign dist-bzip2 no-dist-gzip 1.9])
AC_CONFIG_TESTDIR(tests)
CFLAGS="$CFLAGS -std=gnu11"
dnl kernel style compile messages
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
@@ -25,6 +27,11 @@ AC_PROG_MKDIR_P
AC_PROG_CC
AC_PROG_INSTALL
dnl patching ${archive_cmds} to affect generation of file "libtool" to fix linking with clang
AS_CASE(["$LD"],[*clang*],
[AS_CASE(["${host_os}"],
[*linux*],[archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib'])])
dnl check for pkg-config (explained in detail in libosmocore/configure.ac)
AC_PATH_PROG(PKG_CONFIG_INSTALLED, pkg-config, no)
if test "x$PKG_CONFIG_INSTALLED" = "xno"; then
@@ -34,11 +41,11 @@ PKG_PROG_PKG_CONFIG([0.20])
PKG_CHECK_MODULES(TALLOC, [talloc >= 2.0.1])
PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.2.0)
PKG_CHECK_MODULES(LIBOSMOGSM, libosmogsm >= 1.2.0)
PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 1.2.0)
PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl >= 1.2.0)
PKG_CHECK_MODULES(LIBOSMOABIS, libosmoabis >= 0.6.0)
PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.8.0)
PKG_CHECK_MODULES(LIBOSMOGSM, libosmogsm >= 1.8.0)
PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 1.8.0)
PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl >= 1.8.0)
PKG_CHECK_MODULES(LIBOSMOABIS, libosmoabis >= 1.4.0)
PKG_CHECK_MODULES(SQLITE3, sqlite3)
@@ -86,6 +93,7 @@ AC_ARG_ENABLE(werror,
if test x"$werror" = x"yes"
then
WERROR_FLAGS="-Werror"
WERROR_FLAGS+=" -Werror=implicit-int -Werror=int-conversion -Werror=old-style-definition"
WERROR_FLAGS+=" -Wno-error=deprecated -Wno-error=deprecated-declarations"
WERROR_FLAGS+=" -Wno-error=cpp" # "#warning"
CFLAGS="$CFLAGS $WERROR_FLAGS"
@@ -100,13 +108,22 @@ if test "x$enable_ext_tests" = "xyes" ; then
AM_PATH_PYTHON
AC_CHECK_PROG(OSMOTESTEXT_CHECK,osmotestvty.py,yes)
if test "x$OSMOTESTEXT_CHECK" != "xyes" ; then
AC_MSG_ERROR([Please install git://osmocom.org/python/osmo-python-tests to run the VTY/CTRL tests.])
AC_MSG_ERROR([Please install https://gitea.osmocom.org/cellular-infrastructure/osmo-python-tests to run the VTY/CTRL tests.])
fi
fi
AC_MSG_CHECKING([whether to enable VTY/CTRL tests])
AC_MSG_RESULT([$enable_ext_tests])
AM_CONDITIONAL(ENABLE_EXT_TESTS, test "x$enable_ext_tests" = "xyes")
# mslookup_client_mdns_test (OS#4385: does not work everywhere)
AC_ARG_ENABLE([mslookup_client_mdns_test],
AC_HELP_STRING([--enable-mslookup-client-mdns-test],
[Include the mslookup_client_mdns_test in make check [default=no]]),
[enable_mslookup_client_mdns_test="$enableval"],[enable_mslookup_client_mdns_test="no"])
AC_MSG_CHECKING([whether to enable mslookup_client_mdns_test])
AC_MSG_RESULT([$enable_mslookup_client_mdns_test])
AM_CONDITIONAL(ENABLE_MSLOOKUP_CLIENT_MDNS_TEST, test "x$enable_mslookup_client_mdns_test" = "xyes")
# Generate manuals
AC_ARG_ENABLE(manuals,
[AS_HELP_STRING(
@@ -186,10 +203,10 @@ AC_OUTPUT(
contrib/Makefile
contrib/systemd/Makefile
contrib/dgsm/Makefile
contrib/osmo-hlr.spec
tests/Makefile
tests/auc/Makefile
tests/auc/gen_ts_55_205_test_sets/Makefile
tests/gsup_server/Makefile
tests/gsup/Makefile
tests/db/Makefile
tests/db_upgrade/Makefile

View File

@@ -2,3 +2,13 @@ SUBDIRS = \
systemd \
dgsm \
$(NULL)
EXTRA_DIST = osmo-hlr-post-upgrade.sh
install-data-hook:
install -Dm755 $(srcdir)/osmo-hlr-post-upgrade.sh \
-t $(DESTDIR)$(datadir)/osmocom/
uninstall-hook:
@$(PRE_UNINSTALL)
$(RM) $(DESTDIR)$(datadir)/osmocom/osmo-hlr-post-upgrade.sh

View File

@@ -1,13 +1,13 @@
#!/usr/bin/env python3
"""
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: MIT
Copyright 2019 sysmocom s.f.m.c GmbH <info@sysmocom.de>
WARNING: this is just a proof-of-concept implementation, it blocks for every
received SMPP request and is not suitable for servicing more than one request
at a time.
Based on esme.py from RCCN:
Based on esme.py from RCCN (license changed with permission from author):
https://github.com/Rhizomatica/rccn/blob/master/rccn/esme.py
Copyright 2017 keith <keith@rhizomatica.org>
@@ -39,13 +39,7 @@ import time
def can_handle_pdu(pdu):
if not isinstance(pdu, smpplib.command.DeliverSM):
logging.info('PDU is not a DeliverSM. Is OsmoMSC configured properly?')
return False
# Multipart SMS etc. not handled here (see RCCN's esme.py)
if pdu.esm_class & smpplib.consts.SMPP_GSMFEAT_UDHI:
logging.info("UDH (User Data Header) handling not implemented in this"
" example, dropping message.")
logging.info('PDU is not a DeliverSM, ignoring')
return False
if int(pdu.dest_addr_ton) == smpplib.consts.SMPP_TON_INTL:
@@ -69,7 +63,8 @@ def query_mslookup(service_type, id, id_type='msisdn'):
return json.loads(result_line)
def tx_sms(dst_host, dst_port, source, destination, unicode_text):
def tx_sms(dst_host, dst_port, source, destination, registered_delivery,
unicode_text):
smpp_client = smpplib.client.Client(dst_host, dst_port, 90)
smpp_client.connect()
smpp_client.bind_transceiver(system_id=args.dst_id, password=args.dst_pass)
@@ -84,7 +79,7 @@ def tx_sms(dst_host, dst_port, source, destination, unicode_text):
dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
destination_addr=destination.decode(),
short_message=unicode_text,
registered_delivery=False,
registered_delivery=registered_delivery,
)
smpp_client.unbind()
@@ -105,6 +100,9 @@ def rx_deliver_sm(pdu):
time.sleep(args.sleep)
logging.info("Sleep done")
if args.always_fail is not None:
return args.always_fail
result = query_mslookup("smpp.sms", msisdn)
if 'v4' not in result or not result['v4']:
logging.info('No IPv4 result from mslookup! This example only'
@@ -113,7 +111,8 @@ def rx_deliver_sm(pdu):
dst_host, dst_port = result['v4']
tx_sms(dst_host, dst_port, pdu.source_addr,
pdu.destination_addr, pdu.short_message)
pdu.destination_addr, int(pdu.registered_delivery),
pdu.short_message)
return smpplib.consts.SMPP_ESME_ROK
@@ -151,12 +150,35 @@ def main():
parser.add_argument('--sleep', default=0, type=float,
help='sleep time in seconds before forwarding an SMS,'
' to test multithreading (default: 0)')
parser.add_argument('--always-fail', default=None, metavar='SMPP_ESME_ERRCODE',
help='test delivery failure: always return an error code on Deliver-SM,'
' pass an smpplib error code name like RDELIVERYFAILURE (see smpplib/consts.py),'
' or an SMPP error code in hex digits')
args = parser.parse_args()
logging.basicConfig(level=logging.INFO, format='[%(asctime)s]'
' (%(threadName)s) %(message)s', datefmt="%H:%M:%S")
if args.always_fail:
resolved = None
name = 'SMPP_ESME_' + args.always_fail
if hasattr(smpplib.consts, name):
resolved = getattr(smpplib.consts, name)
if resolved is None:
try:
resolved = int(args.always_fail, 16)
except ValueError:
resolved = None
if resolved is None:
print('Invalid argument for --always-fail: %r' % args.always_fail)
exit(1)
args.always_fail = resolved
logging.info('--always-fail: returning error code %s to all Deliver-SM' % hex(args.always_fail))
smpp_bind()
if __name__ == "__main__":
main()
# vim: expandtab tabstop=4 shiftwidth=4

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: MIT
Copyright 2019 sysmocom s.f.m.c GmbH <info@sysmocom.de>
This is a freeswitch dialplan implementation, see:

View File

@@ -35,7 +35,6 @@ osmo-build-dep.sh libosmo-abis
# Additional configure options and depends
CONFIG=""
if [ "$WITH_MANUALS" = "1" ]; then
osmo-build-dep.sh osmo-gsm-manuals
CONFIG="--enable-manuals"
fi
@@ -49,14 +48,19 @@ set -x
cd "$base"
autoreconf --install --force
./configure --enable-sanitize --enable-external-tests --enable-werror $CONFIG
./configure \
--enable-sanitize \
--enable-external-tests \
--enable-mslookup-client-mdns-test \
--enable-werror \
$CONFIG
$MAKE $PARALLEL_MAKE
$MAKE check || cat-testlogs.sh
DISTCHECK_CONFIGURE_FLAGS="$CONFIG" $MAKE distcheck || cat-testlogs.sh
DISTCHECK_CONFIGURE_FLAGS="$CONFIG" $MAKE $PARALLEL_MAKE distcheck || cat-testlogs.sh
if [ "$WITH_MANUALS" = "1" ] && [ "$PUBLISH" = "1" ]; then
make -C "$base/doc/manuals" publish
fi
$MAKE maintainer-clean
$MAKE $PARALLEL_MAKE maintainer-clean
osmo-clean-workspace.sh

View File

@@ -0,0 +1,95 @@
#!/bin/sh -e
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright 2021 sysmocom s.f.m.c GmbH <info@sysmocom.de>
#
# Packagers are supposed to call this script in post-upgrade, so it can safely
# upgrade the database scheme if required.
DB="/var/lib/osmocom/hlr.db"
IS_ACTIVE=0
msg() {
echo "osmo-hlr-post-upgrade: $@"
}
err() {
msg "ERROR: $@"
}
open_db() {
# Attempt to open the database with osmo-hlr-db-tool, it will fail if
# upgrading the schema is required
osmo-hlr-db-tool -s -l "$DB" create
}
check_upgrade_required() {
if ! [ -e "$DB" ]; then
msg "nothing to do (no existing database)"
exit 0
fi
if open_db 2>/dev/null; then
msg "nothing to do (database version is up to date)"
exit 0
fi
msg "database upgrade is required"
}
stop_service() {
if systemctl is-active -q osmo-hlr; then
IS_ACTIVE=1
msg "stopping osmo-hlr service"
systemctl stop osmo-hlr
# Verify that it stopped
for i in $(seq 1 100); do
if ! systemctl is-active -q osmo-hlr; then
return
fi
sleep 0.1
done
err "failed to stop osmo-hlr service"
exit 1
else
msg "osmo-hlr service is not running"
fi
}
create_backup() {
backup="$DB.$(date +%Y%m%d%H%M%S).bak"
msg "creating backup: $backup"
if [ -e "$backup" ]; then
err "backup already exists: $backup"
exit 1
fi
cp "$DB" "$backup"
}
upgrade() {
msg "performing database upgrade"
osmo-hlr-db-tool -s -U -l "$DB" create
if ! open_db 2>/dev/null; then
err "failed to open the database after upgrade"
err "osmo-hlr-db-tool output:"
open_db
# exit because of "set -e"
fi
msg "database upgrade successful"
}
start_service() {
if [ "$IS_ACTIVE" = "1" ]; then
msg "starting osmo-hlr service"
systemctl start osmo-hlr
fi
}
check_upgrade_required
stop_service
create_backup
upgrade
start_service

195
contrib/osmo-hlr.spec.in Normal file
View File

@@ -0,0 +1,195 @@
#
# spec file for package osmo-hlr
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2016, Martin Hauke <mardnh@gmx.de>
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
Name: osmo-hlr
Version: @VERSION@
Release: 0
Summary: Osmocom Home Location Register for GSUP protocol towards OsmoSGSN and OsmoCSCN
License: AGPL-3.0-or-later AND GPL-2.0-or-later
Group: Productivity/Telephony/Servers
URL: https://osmocom.org/projects/osmo-hlr
Source: %{name}-%{version}.tar.xz
BuildRequires: autoconf
BuildRequires: automake
BuildRequires: libtool
BuildRequires: pkgconfig >= 0.20
BuildRequires: python3
%if 0%{?suse_version}
BuildRequires: systemd-rpm-macros
%endif
BuildRequires: pkgconfig(libosmoabis) >= 1.4.0
BuildRequires: pkgconfig(libosmocore) >= 1.8.0
BuildRequires: pkgconfig(libosmoctrl) >= 1.8.0
BuildRequires: pkgconfig(libosmogsm) >= 1.8.0
BuildRequires: pkgconfig(libosmovty) >= 1.8.0
BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(talloc) >= 2.0.1
# only needed for populate_hlr_db.pl
Requires: libdbi-drivers-dbd-sqlite3
%{?systemd_requires}
%description
The GSUP HLR is a stand-alone HLR (Home Location Register) for SIM
and USIM based subscribers which exposes the GSUP protocol towards
its users. OsmoSGSN supports this protocol.
osmo-gsup-hlr is still very simplistic. It is a single-threaded
architecture and uses only sqlite3 tables as back-end. It is suitable
for installations of the scale that OsmoNITB was able to handle. It
also lacks various features like fine-grained control of subscribed
services (like supplementary services).
%package -n libosmo-gsup-client0
Summary: Osmocom GSUP (General Subscriber Update Protocol) client library
License: GPL-2.0-or-later
Group: System/Libraries
%description -n libosmo-gsup-client0
This is a shared library that can be used to implement client programs for
the GSUP protocol. The typical GSUP server is OsmoHLR, with OsmoMSC, OsmoSGSN
and External USSD Entities (EUSEs) using this library to implement clients.
%package -n libosmo-gsup-client-devel
Summary: Development files for the Osmocom GSUP client library
License: GPL-2.0-or-later
Group: Development/Libraries/C and C++
Requires: libosmo-gsup-client0 = %{version}
%description -n libosmo-gsup-client-devel
This is a shared library that can be used to implement client programs for
the GSUP protocol. The typical GSUP server is OsmoHLR, with OsmoMSC, OsmoSGSN
and External USSD Entities (EUSEs) using this library to implement clients.
This subpackage contains libraries and header files for developing
applications that want to make use of libosmo-gsup-client.
%package -n libosmo-mslookup1
Summary: Osmocom MS lookup library
License: GPL-2.0-or-later
Group: System/Libraries
%description -n libosmo-mslookup1
This shared library contains routines for looking up mobile subscribers.
%package -n libosmo-mslookup-devel
Summary: Development files for the Osmocom MS lookup library
License: GPL-2.0-or-later
Group: Development/Libraries/C and C++
Requires: libosmo-mslookup1 = %{version}
%description -n libosmo-mslookup-devel
This shared library contains routines for looking up mobile subscribers.
This subpackage contains libraries and header files for developing
applications that want to make use of libosmo-mslookup.
%package -n osmo-mslookup-client
Summary: Standalone program using libosmo-mslookup
License: GPL-2.0-or-later
Group: Development/Libraries/C and C++
%description -n osmo-mslookup-client
Standalone program using libosmo-mslookup to easily integrate with programs
that want to connect services (SIP, SMS,...) to the current location of a
subscriber.
%prep
%setup -q
%build
echo "%{version}" >.tarball-version
autoreconf -fi
%configure \
--docdir="%{_docdir}/%{name}" \
--with-systemdsystemunitdir=%{_unitdir} \
--enable-shared \
--disable-static
make V=1 %{?_smp_mflags}
%install
%make_install
install -d "%{buildroot}/%{_localstatedir}/lib/osmocom"
find %{buildroot} -type f -name "*.la" -delete -print
%check
make %{?_smp_mflags} check || (find . -name testsuite.log -exec cat {} +)
%if 0%{?suse_version}
%preun
%service_del_preun %{name}.service
%postun
%service_del_postun %{name}.service
%pre
%service_add_pre %{name}.service
%endif
%post
%if 0%{?suse_version}
%service_add_post %{name}.service
%endif
/usr/share/osmocom/osmo-hlr-post-upgrade.sh
%post -n libosmo-gsup-client0 -p /sbin/ldconfig
%postun -n libosmo-gsup-client0 -p /sbin/ldconfig
%post -n libosmo-mslookup1 -p /sbin/ldconfig
%postun -n libosmo-mslookup1 -p /sbin/ldconfig
%files
%license COPYING
%dir %{_docdir}/%{name}
%dir %{_docdir}/%{name}/examples
%{_docdir}/%{name}/examples/osmo-hlr.cfg
%{_docdir}/%{name}/examples/osmo-hlr-dgsm.cfg
%dir %{_docdir}/%{name}/sql
%{_docdir}/%{name}/sql/hlr.sql
%{_docdir}/%{name}/sql//hlr_data.sql
%dir %{_sysconfdir}/osmocom
%dir %{_localstatedir}/lib/osmocom
%{_bindir}/osmo-hlr
%{_bindir}/osmo-hlr-db-tool
%dir %{_sysconfdir}/osmocom
%config %{_sysconfdir}/osmocom/osmo-hlr.cfg
%{_unitdir}/osmo-hlr.service
%dir %{_datadir}/osmocom
%{_datadir}/osmocom/osmo-hlr-post-upgrade.sh
%files -n libosmo-gsup-client0
%{_libdir}/libosmo-gsup-client.so.0*
%files -n libosmo-gsup-client-devel
%{_bindir}/osmo-euse-demo
%dir %{_includedir}/osmocom
%dir %{_includedir}/osmocom/gsupclient
%{_includedir}/osmocom/gsupclient/*.h
%{_libdir}/libosmo-gsup-client.so
%{_libdir}/pkgconfig/libosmo-gsup-client.pc
%files -n libosmo-mslookup1
%{_libdir}/libosmo-mslookup.so.1*
%files -n libosmo-mslookup-devel
%dir %{_includedir}/osmocom
%dir %{_includedir}/osmocom/mslookup
%{_includedir}/osmocom/mslookup/*.h
%{_libdir}/libosmo-mslookup.so
%{_libdir}/pkgconfig/libosmo-mslookup.pc
%files -n osmo-mslookup-client
%{_bindir}/osmo-mslookup-client
%changelog

View File

@@ -5,8 +5,11 @@ Documentation=https://osmocom.org/projects/osmo-hlr/wiki/OsmoHLR
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/osmo-hlr -U -c /etc/osmocom/osmo-hlr.cfg -l /var/lib/osmocom/hlr.db
StateDirectory=osmocom
WorkingDirectory=%S/osmocom
ExecStart=/usr/bin/osmo-hlr -c /etc/osmocom/osmo-hlr.cfg -l /var/lib/osmocom/hlr.db
RestartSec=2
ProtectHome=true
[Install]
WantedBy=multi-user.target

230
debian/changelog vendored
View File

@@ -1,3 +1,233 @@
osmo-hlr (1.6.0) unstable; urgency=medium
[ Vadim Yanitskiy ]
* db_auc: hexparse_stmt(): check value returned by osmo_hexparse()
[ Max ]
* Set working directory in systemd service file
* Ignore .deb build byproducts
* Debian: bump copyright year to match current
* Debian: reformat package description
* systemd: enable basic hardening
* Debian: install osmo-hlr-dgsm.cfg as example config
* hlr_vty.c: fix typo
* ctrl: take both address and port from vty config
[ Harald Welte ]
* Support building with -Werror=strict-prototypes / -Werror=old-style-definition
* Add -Werror=implicit-int -Werror=int-conversion -Werror=old-style-definition
[ arehbein ]
* osmo-hlr: Transition to use of 'telnet_init_default'
[ Oliver Smith ]
* osmo_mdns_rfc_record_decode: check ret of talloc
* osmo_mdns_rfc_record_decode: proper free on err
* mslookup: use apn functions from libosmocore
* osmo_mdns_rfc_record/question_encode: remove ctx
[ Keith ]
* Vty: Fixup config shown/written from vty
[ Neels Hofmeyr ]
* fix memleak of proxy_subscr_listentry
[ Alexander Couzens ]
* Add vty `reject-cause` to set the reject cause
-- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 07 Feb 2023 16:49:14 +0100
osmo-hlr (1.5.0) unstable; urgency=medium
[ Oliver Smith ]
* treewide: remove FSF address
[ Vadim Yanitskiy ]
* fixup: debian: remove unneeded dependency libdbd-sqlite3
* debian: add new 'osmo-mslookup-utils' package
* tests: use 'check_PROGRAMS' instead of 'noinst_PROGRAMS'
[ Pau Espin Pedrol ]
* ctrl: Mark function as static
* tests: Allow specyfing specific ctrl test to run
* tests/ctrl: Move ERROR test scenario to proper file
* Fix db_subscr_create() not returning -EEXIST expected by VTY subscriber create cmd
* ctrl: Introduce cmd SET subscriber.create <imsi>
* ctrl: Introduce CTRL command subscriber.by-*.msisdn
* cosmetic: hlr_vty_subscr.c: Fix trailing whitespace
* ctrl: Introduce cmd SET subscriber.delete <imsi>
* ctrl: Introduce CTRL command subscriber.by-*.aud2g <algo[,ki]>
* ctrl: Introduce CTRL command subscriber.by-*.aud3g <algo[,KI,(op|opc),OP_C[,ind_bitlen]]>
* doc: Document new subscriber CTRL commands
[ Harald Welte ]
* update git URLs (git -> https; gitea)
-- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 28 Jun 2022 18:38:31 +0200
osmo-hlr (1.4.0) unstable; urgency=medium
[ Keith ]
* Correct configuration written from vty
* vty: enable show subscribers filtered by IMEI
[ Harald Welte ]
* add README.md file as customary for cgit, github, gitlab, etc.
[ Oliver Smith ]
* Add post-upgrade script for automatic db upgrade
* debian/control: remove dh-systemd build-depend
[ Pau Espin Pedrol ]
* db: Avoid use uninitialized rc if running 0 statements
[ Neels Hofmeyr ]
* db v6: determine 3G AUC IND from VLR name
-- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 16 Nov 2021 14:56:41 +0100
osmo-hlr (1.3.0) unstable; urgency=medium
[ Alexander Couzens ]
* hlr: respect the num_auth_vectors requested
* hlr: remove unused internal USSD list
[ Oliver Smith ]
* add libosmo-mslookup abstract client
* add mDNS lookup method to libosmo-mslookup
* Makefile.am: fix pkgconfig_DATA
* add mDNS lookup method to libosmo-mslookup (#2)
* contrib/dgsm/ add example esme and dialplan
* mslookup_client.c: fix dereferencing null pointer
* mdns_msg.c: always call va_end
* mslookup_client_mdns.c: fix dereferencing null
* osmo-mslookup-client.c: fix dereferencing null
* osmo-mslookup-client: fix dereferencing null
* mdns_sock.c: fix resource leak of sock
* mdns_rfc.c: fix possible access of uninit. mem
* mslookup_client_mdns_test: disable by default
* mslookup_client_mdns_test: no automatic skip
* Cosmetic: mention OS#4491 in location cancel code
* hlr_vty_subscr: prettier output for last LU seen
* contrib: import RPM spec
* contrib: integrate RPM spec
* Makefile.am: EXTRA_DIST: debian, contrib/*.spec.in
* contrib/jenkins: don't build osmo-gsm-manuals
* configure.ac: set -std=gnu11
[ Neels Hofmeyr ]
* add osmo-mslookup-client program
* add osmo-mslookup-client program (#2)
* fix missing braces in LOGP_GSUP_FWD
* gsup_client.c: fix deprecation for client create func
* 1/2: refactor: add and use lu_fsm, osmo_gsup_req, osmo_ipa_name
* 2/2: wrap ipa_name in osmo_cni_peer_id with type enum and union
* gsup client: add up_down_cb(), add osmo_gsup_client_create3()
* db v5: prep for D-GSM: add vlr_via_proxy and sgsn_via_proxy
* enlarge the GSUP message headroom
* test_nodes.vty: remove cruft
* D-GSM 1/n: add mslookup server in osmo-hlr
* D-GSM 2/n: implement mDNS method of mslookup server
* D-GSM 3/n: implement roaming by mslookup in osmo-hlr
* gsup_server: send routing error back to the correct peer
* adoc: add D-GSM chapter to osmohlr-usermanual
* drop error log for when a subscriber does not exist
* vty: show subscriber: change format of 'last LU seen'
* vty: show subscriber: show lu d,h,m,s ago, not just seconds
* auc3g: officially wrap IND around IND_bitlen space
* make osmo_cni_peer_id_cmp() NULL safe
* osmo_gsup_req_new(): require from_peer != NULL
* gsup_server.c: properly handle negative rc from osmo_gsup_conn_ccm_get()
* osmo_mslookup_server_mdns_rx(): handle read() rc == 0
* hlr_subscr_nam(): fix condition to fix nam=false notifications
* esme_dgsm.py: add --always-fail option for debugging SMPP
* osmo-mslookup-client: fix segfault for respond_error() caller
* manual: describe subscriber import by SQL
[ Harald Welte ]
* Revert "add osmo-mslookup-client program"
* Revert "add mDNS lookup method to libosmo-mslookup"
* Use OSMO_FD_* instead of deprecated BSC_FD_*
* support the XOR algorithm for UMTS AKA
* auc_test.c: Add some comments on what the test cases actually do
* main: add --vty-ref-mode, use vty_dump_xml_ref_mode()
* manuals: generate vty reference xml at build time
[ Vadim Yanitskiy ]
* db: fix possible SQLite3 allocated memory leak in db_open()
* gsup_server: fix typo: s/omso_gsup_message/osmo_gsup_message/
* debian/control: change maintainer to the Osmocom team / mailing list
* cosmetic: fix spelling in logging message: existAnt -> existEnt
* doc/manuals: fix s/There/The/ in 'USSD Configuration'
* doc/manuals: re-organize description of internal USSD handlers
* USSD: fix handle_ussd(): do not free() unconditionally
* USSD: add special 'idle' handler to IUSE for testing
[ Eric ]
* configure.ac: fix libtool issue with clang and sanitizer
[ Philipp Maier ]
* doc: do not use loglevel info for log category ss
[ Pau Espin Pedrol ]
* configure.ac: Fix trailing whitespace
* doc: Update VTY reference xml file
* Support setting rt-prio and cpu-affinity mask through VTY
* Set TCP NODELAY sockopt to GSUP cli and srv connections
* contrib/jenkins: Enable parallel make in make distcheck
* .gitignore: Ignore new autofoo tmp files
* tests: Replace deprecated API log_set_print_filename
[ Keith ]
* osmo-hlr-db-tool: Make import from osmo-nitb less "lossy"
* Correct vty inline help for show subscriber
* Add vty command to show summary of all or filtered subscribers
* Fix Coverity Warnings
-- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 23 Feb 2021 18:13:53 +0100
osmo-hlr (1.2.0) unstable; urgency=medium
[ Ruben Undheim ]
* Fix test for return codes on mipsel and alpha archs
[ Thorsten Alteholz ]
* fix spelling errors detected by lintian
[ Pau Espin Pedrol ]
* tests: Fix db_test err file to expect error code name instead of value
[ Oliver Smith ]
* tests/test_nodes.vty: check less libosmocore cmds
* tests/db_upgrade: disable for old sqlite versions
* gitignore: add tests/db_upgrade/*.dump
* gsup_client.h: fix license header: GPLv2+
* tests/auc: change back to python3
[ Neels Hofmeyr ]
* fix double free in osmo_gsup_client_enc_send()
* db upgrade to v2: log version 2, not 1
* fix upgrade to version 2: imei column default value
* add --db-check option
* hlr.sql: move comment
* add db_upgrade test
* hlr db schema 3: hlr_number -> msc_number
* db.c: code dup: add db_run_statements() for arrays of statements
* move headers to include/osmocom/hlr
* fix upgrade test in presence of ~/.sqliterc
* db upgrade: remove some code dup
* add osmo_gsup_msgb_alloc()
* Makefile convenience: add VTY_TEST var to run only one test
* remove gsup_test
* test_nodes.vty: tweak: add some '?' checks
* db v4: add column last_lu_seen_ps
[ Harald Welte ]
* AUC: Add support for setting the AMF separation bit to '1' for EUTRAN
* hlr: exit(2) on unsupported positional arguments on command line
-- Pau Espin Pedrol <pespin@sysmocom.de> Fri, 03 Jan 2020 12:37:35 +0100
osmo-hlr (1.1.0) unstable; urgency=medium
[ Oliver Smith ]

36
debian/control vendored
View File

@@ -1,30 +1,30 @@
Source: osmo-hlr
Section: net
Priority: optional
Maintainer: Max Suraev <msuraev@sysmocom.de>
Maintainer: Osmocom team <openbsc@lists.osmocom.org>
Build-Depends: debhelper (>= 9),
pkg-config,
dh-autoreconf,
dh-systemd (>= 1.5),
autotools-dev,
python3-minimal,
libosmocore-dev,
libosmo-abis-dev,
libosmo-netif-dev,
libosmocore-dev (>= 1.8.0),
libosmo-abis-dev (>= 1.4.0),
libosmo-netif-dev (>= 1.3.0),
libsqlite3-dev,
sqlite3,
osmo-gsm-manuals-dev
osmo-gsm-manuals-dev (>= 1.4.0)
Standards-Version: 3.9.6
Vcs-Browser: http://cgit.osmocom.org/osmo-hlr
Vcs-Git: git://git.osmocom.org/osmo-hlr
Vcs-Browser: https://gitea.osmocom.org/cellular-infrastructure/osmo-hlr
Vcs-Git: https://gitea.osmocom.org/cellular-infrastructure/osmo-hlr
Homepage: https://projects.osmocom.org/projects/osmo-hlr
Package: osmo-hlr
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libdbd-sqlite3
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Osmocom Home Location Register
OsmoHLR is a Osmocom implementation of HLR (Home Location Registrar) which works over GSUP
protocol. The subscribers are store in sqlite DB. It supports both 2G and 3G authentication.
OsmoHLR is a Osmocom implementation of HLR (Home Location Registrar) which
works over GSUP protocol. The subscribers are store in sqlite DB.
It supports both 2G and 3G authentication.
Package: osmo-hlr-dbg
Architecture: any
@@ -59,7 +59,7 @@ Description: Development headers of Osmocom GSUP client library
.
This package contains the development headers.
Package: libosmo-mslookup0
Package: libosmo-mslookup1
Section: libs
Architecture: any
Multi-Arch: same
@@ -73,7 +73,7 @@ Package: libosmo-mslookup-dev
Architecture: any
Multi-Arch: same
Depends: ${misc:Depends},
libosmo-mslookup0 (= ${binary:Version}),
libosmo-mslookup1 (= ${binary:Version}),
libosmocore-dev
Pre-Depends: ${misc:Pre-Depends}
Description: Development headers of Osmocom MS lookup library
@@ -81,6 +81,16 @@ Description: Development headers of Osmocom MS lookup library
.
This package contains the development headers.
Package: osmo-mslookup-utils
Architecture: any
Section: utils
Depends: ${shlibs:Depends},
libosmo-mslookup1 (= ${binary:Version}),
${misc:Depends}
Multi-Arch: same
Description: Utilities for Osmocom MS lookup
This package contains a simple MS lookup client utility.
Package: osmo-hlr-doc
Architecture: all
Section: doc

2
debian/copyright vendored
View File

@@ -3,7 +3,7 @@ Upstream-Name: OsmoHLR
Source: http://cgit.osmocom.org/osmo-hlr/
Files: *
Copyright: 2016-2017 Sysmocom s. f. m. c. GmbH <info@sysmocom.de>
Copyright: 2016-2022 Sysmocom s. f. m. c. GmbH <info@sysmocom.de>
License: AGPL-3+
License: AGPL-3+

View File

@@ -5,4 +5,5 @@
/usr/share/doc/osmo-hlr/sql/hlr.sql
/usr/share/doc/osmo-hlr/sql/hlr_data.sql
/usr/share/doc/osmo-hlr/examples/osmo-hlr.cfg
/var/lib/osmocom
/usr/share/doc/osmo-hlr/examples/osmo-hlr-dgsm.cfg
/usr/share/osmocom/osmo-hlr-post-upgrade.sh

1
debian/osmo-mslookup-utils.install vendored Normal file
View File

@@ -0,0 +1 @@
usr/bin/osmo-mslookup-client

5
debian/postinst vendored Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh -e
# Debian's postinst script is called on both installation and upgrade. Call the
# post-upgrade script in both cases, it won't do anything if there is nothing
# to do.
/usr/share/osmocom/osmo-hlr-post-upgrade.sh

View File

@@ -0,0 +1,22 @@
# OsmoHLR example configuration for Distributed GSM (mslookup)
hlr
gsup
# For D-GSM roaming, osmo-hlr's GSUP must listen on a public IP:
bind ip 10.9.8.7
# Each HLR should identify with a distinct name
ipa-name hlr-23
mslookup
# Bind mslookup mDNS server and client on default multicast address and port:
# 239.192.23.42 port 4266
mdns bind
# Tell the mslookup server in osmo-hlr which IP+ports to return when a
# remote voice call or SMS wants to deliver to a local subscriber:
server
# local osmo-sip-connector SIP port
service sip.voice at 10.9.8.7 5060
# local osmo-msc SMPP port
service smpp.sms at 10.9.8.7 2775
# experimental: SMS-over-GSUP: this HLR's GSUP port
service gsup.sms at 10.9.8.7 4222
# only required if different from above 'gsup'/'bind ip':
#service gsup.hlr at 10.9.8.7 4222

View File

@@ -12,7 +12,7 @@ log stderr
logging level main notice
logging level db notice
logging level auc notice
logging level ss info
logging level ss notice
logging level linp error
!
line vty
@@ -24,10 +24,3 @@ hlr
bind ip 127.0.0.1
ussd route prefix *#100# internal own-msisdn
ussd route prefix *#101# internal own-imsi
ussd route prefix *#102# internal get-ran
ussd route prefix *#200# internal gsm-off
ussd route prefix *#201# internal gsm-on
ussd route prefix *#300# internal umts-off
ussd route prefix *#301# internal umts-on
ussd route prefix *#400# internal lte-off
ussd route prefix *#401# internal lte-on

View File

@@ -1,6 +1,10 @@
EXTRA_DIST = example_subscriber_add_update_delete.vty \
EXTRA_DIST = \
example_subscriber_add_update_delete.vty \
example_subscriber_aud2g.ctrl \
example_subscriber_aud3g.ctrl \
example_subscriber_cs_ps_enabled.ctrl \
example_subscriber_info.ctrl \
example_subscriber_msisdn.ctrl \
osmohlr-usermanual.adoc \
osmohlr-usermanual-docinfo.xml \
osmohlr-vty-reference.xml \
@@ -14,6 +18,12 @@ if BUILD_MANUALS
include $(OSMO_GSM_MANUALS_DIR)/build/Makefile.asciidoc.inc
VTY_REFERENCE = osmohlr-vty-reference.xml
BUILT_REFERENCE_XML = $(builddir)/vty/hlr_vty_reference.xml
$(builddir)/vty/hlr_vty_reference.xml: $(top_builddir)/src/osmo-hlr
mkdir -p $(builddir)/vty
$(top_builddir)/src/osmo-hlr --vty-ref-xml > $@
include $(OSMO_GSM_MANUALS_DIR)/build/Makefile.vty-reference.inc
OSMO_REPOSITORY = osmo-hlr

View File

@@ -5,6 +5,16 @@ The actual protocol is described in <<common-control-if>>, the variables common
to all programs using it are described in <<ctrl_common_vars>>. This section
describes the CTRL interface variables specific to OsmoHLR.
Subscribers can be created and deleted using the following SET commands:
.Subscriber management commands available on OsmoHLR's Control interface
[options="header",width="100%",cols="35%,65%"]
|===
|Command|Comment
|subscriber.create '123456'|Create a new subscriber with IMSI "123456" to the database. Returns database ID of the subscriber being created.
|subscriber.delete '123456'|Delete subscriber with IMSI "123456" from database. Returns database ID of the subscriber being deleted.
|===
All subscriber variables are available by different selectors, which are freely
interchangeable:
@@ -28,6 +38,9 @@ Each of the above selectors feature all of these control variables:
|subscriber.by-\*.*info-all*|R|No||List both 'info' and 'info-aud' in one
|subscriber.by-\*.*cs-enabled*|RW|No|'1' or '0'|Enable/disable circuit-switched access
|subscriber.by-\*.*ps-enabled*|RW|No|'1' or '0'|Enable/disable packet-switched access
|subscriber.by-\*.*msisdn*|RW|No|valid MSISDN string|Get/Set assigned MSISDN
|subscriber.by-\*.*aud2g*|RW|No|'algo[,KI]'|Get/Set 2g Authentication Data
|subscriber.by-\*.*aud2g*|RW|No|'algo[,KI,("op"|"opc"),OP_C[,ind_bitlen]]'|Get/Set 3g Authentication Data
|===
=== subscriber.by-*.info, info-aud, info-all
@@ -104,3 +117,63 @@ commands:
----
include::../example_subscriber_cs_ps_enabled.ctrl[]
----
=== subscriber.by-*.msisdn
Get or set the MSISDN currently assigned to a subscriber.
This is an example transcript that illustrates use of this command:
----
include::../example_subscriber_msisdn.ctrl[]
----
=== subscriber.by-*.aud2g
Get or set the 2G Authentication data of a subscriber.
The information is stored/retrieved as a comma separated list of fields:
----
algo[,KI]
----
Where::
* *KI* is the KI as a hexadecimal string.
* *algo* is one of the following algorithms: _none, xor, comp128v1, comp128v2,
comp128v3_.
All values are case insensitive.
This is an example transcript that illustrates use of this command:
----
include::../example_subscriber_aud2g.ctrl[]
----
=== subscriber.by-*.aud3g
Get or set the 3G Authentication data of a subscriber.
The information is stored/retrieved as a comma separated list of fields:
----
algo[,KI,("op"|"opc"),OP_C[,ind_bitlen]]
----
Where:
* *KI* is the KI as a hexadecimal string.
* *algo* is one of the following algorithms: _none, xor, milenage_.
* "op" or "opc" indicates whether next field is an OP or OPC value.
* *OP_C* contains an OP or OPC values as hexadecimal string, based on what the
previous field specifies.
* *ind_bitlen* is set to 5 by default if not provided.
All values are case insensitive.
This is an example transcript that illustrates use of this command:
----
include::../example_subscriber_aud3g.ctrl[]
----

View File

@@ -38,7 +38,7 @@ There are two fundamentally distinct subscriber lookups provided by the mslookup
----
digraph G {
rankdir=LR
subgraph cluster_village_b {
label="Village B"
ms_bob [label="Bob\n(from village B)",shape=box]
@@ -113,7 +113,7 @@ msc {
----
digraph G {
rankdir=LR
subgraph cluster_village_b {
label="Village B"
@@ -214,6 +214,12 @@ port, but beware that the IP address must be from a multicast range, see <<ietf-
mslookup
mdns bind 239.192.23.42 4266
Domain names generated from mslookup queries (e.g. "sip.voice.123.msisdn") should not collide with IANA permitted
domains. Therefore we add the "mdns.osmocom.org" suffix. It can be overridden as follows:
mslookup
mdns domain-suffix mdns.osmocom.org
==== Server: Site Services
The mslookup server requires a list of service addresses provided at the local site, in order to respond to service
@@ -224,23 +230,25 @@ requests matching locally attached subscribers.
service sip.voice at 10.9.8.7 5060
service smpp.sms at 10.9.8.7 2775
In this example, "10.9.8.7 5060" would be the IP address and port on which the local site's PBX is bound to receive SIP
Invite requests; "10.9.8.7 2775" would be the local site's OsmoMSC SMPP bind address and port.
In this example:
Obviously, these IP addresses must be routable back to this site from all other sites. If, for example, the PBX is
configured to bind on "0.0.0.0", it won't work to enter the same as service address -- remote sites cannot route to
0.0.0.0. Instead, the mslookup service requires a public IP address of a local interface. For the same reasons, never
add link-local addresses like 127.0.0.1 as mslookup services.
- "10.9.8.7 5060" are the IP address and port on which the local site's osmo-sip-connector is bound to receive SIP
Invite requests.
- "10.9.8.7 2775" are the local site's OsmoMSC SMPP bind address and port.
Obviously, these IP addresses must be routable back to this site from all other sites. Using link-local or "ANY"
addresses, like 127.0.0.1 or 0.0.0.0, will not work here. Instead, each service config requires a public IP address that
all remote requestors are able to reach (not necessarily on the host that osmo-hlr is running on).
If a site has more than one MSC, services can also be configured for each MSC individually, keyed by the IPA unit name
that each MSC sends on the GSUP link:
mslookup
server
msc msc-262-42-0
msc ipa-name msc-262-42-0
service sip.voice at 10.11.12.13 5060
service smpp.sms at 10.11.12.13 2775
msc msc-901-70-0
msc ipa-name msc-901-70-0
service sip.voice at 10.9.8.7 5060
service smpp.sms at 10.9.8.7 2775
@@ -324,7 +332,7 @@ The mslookup ID types are fixed, while service names can be chosen arbitrarily.
|===
|Service Name|Protocol|Description
|gsup.hlr | GSUP | Home HLR's GSUP server, to handle Location Updating related procedures
|sip.voice | SIP | SIP PBX or OsmoSIPConnector, to receive a SIP Invite (MT side of a call)
|sip.voice | SIP | OsmoSIPConnector, to receive a SIP Invite (MT side of a call)
|smpp.sms | SMPP | Destination OsmoMSC (or other SMPP server) to deliver an SMS to the recipient
|gsup.sms | GSUP | GSUP peer to deliver an SMS to the recipient using SMS-over-GSUP
|===
@@ -412,6 +420,7 @@ dialplan implementation. An example dialplan implementation for FreeSWITCH that
osmo-hlr source tree under `contrib`, called `freeswitch_dialplan_dgsm.py`.
To integrate it with your FREESWITCH setup, add a new `extension` block to your `dialplan/public.xml`:
----
<extension name="outbound">
<condition field="destination_number" expression=".*">
@@ -425,6 +434,7 @@ To integrate it with your FREESWITCH setup, add a new `extension` block to your
Make sure that the dir containing `freeswitch_dialplan_dgsm.py` is in your `PYTHONPATH` environment variable, and start
the server:
----
$ export PYTHONPATH="$PYTHONPATH:/home/user/code/osmo-hlr/contrib/dgsm"
$ freeswitch -nf -nonat -nonatmap -nocal -nort -c

View File

@@ -54,7 +54,7 @@ this database file will be created in the current working directory.
Alternatively, you may use the `osmo-hlr-db-tool`, which is installed along
with `osmo-hlr`, to bootstrap an empty database, or to migrate subscriber data
from an old 'OsmoNITB' database. See `osmo-hlr-db-tool --help`.
from an old 'OsmoNITB' database. See <<db_import_nitb>>.
=== Multiple instances

View File

@@ -127,3 +127,83 @@ OsmoHLR# subscriber imei 35761300444848 show
----
<1> Randomly generated 5 digit MSISDN
<2> Disabled CS and PS NAM prevent the subscriber from accessing the network
=== Import Subscriber Data
==== Scripted Import
WARNING: It is not generally a good idea to depend on the HLR database's internal table structure, but in the lack of an
automated import procedure, this example is provided as an ad-hoc method to aid automated subscriber import. This is not
guaranteed to remain valid.
NOTE: We may add CSV and other import methods to the `osmo-hlr-db-tool`, but so far that is not implemented. Contact the
community if you are interested in such a feature being implemented.
NOTE: `sqlite3` is available from your distribution packages or `sqlite.org`.
Currently, probably the easiest way to automatically import subscribers to OsmoHLR is to write out a text file with SQL
commands per subscriber, and feed that to `sqlite3`, as described below.
A difficulty is to always choose subscriber IDs that are not yet in use. For an initial import, the subscriber ID may be
incremented per subscriber record. If adding more subscribers to an existing database, it is necessary to choose
subscriber IDs that are not yet in use. Get the highest ID in use with:
----
sqlite3 hlr.db 'select max(id) from subscriber'
----
A full SQL example of adding a single subscriber with id 23, IMSI 001010123456789, MSISDN 1234, Ki for COMP128v1, and K
and OPC for Milenage:
----
INSERT subscriber (id, imsi, msisdn) VALUES (23, '001010123456789', '1234');
INSERT INTO auc_2g (subscriber_id, algo_id_2g, ki)
VALUES(23, 1, '0123456789abcdef0123456789abcdef');
INSERT INTO auc_3g (subscriber_id, algo_id_3g, k, op, opc)
VALUES(23, 5, '0123456789abcdef0123456789abcdef',NULL,'0123456789abcdef0123456789abcdef');
----
Table entries to `auc_2g` and/or `auc_3g` may be omitted if no such key material is required.
UMTS Milenage auth (on both 2G and 3G RAN) is configured by the `auc_3g` table. `algo_id_3g` must currently always be 5
(MILENAGE).
The algorithm IDs for `algo_id_2g` and `algo_id_3g` are:
.Algorithm IDs in OsmoHLR's database
[options="header",width="50%",cols="40%,60%"]
|===
|`algo_id_2g` / `algo_id_3g` | Authentication Algorithm
| 1 | COMP128v1
| 2 | COMP128v2
| 3 | COMP128v3
| 4 | XOR
| 5 | MILENAGE
|===
Create an empty HLR database with
----
osmo-hlr-db-tool -l hlr.db create
----
Repeat above SQL commands per subscriber, incrementing the subscriber ID for each block, then feed the SQL commands for
the subscribers to be imported to the `sqlite3` command line tool:
----
sqlite3 hlr.db < subscribers.sql
----
[[db_import_nitb]]
==== Import OsmoNITB database
To upgrade from old OsmoNITB to OsmoHLR, use `osmo-hlr-db-tool`:
----
osmo-hlr-db-tool -l hlr.db import-nitb-db nitb.db
----
Be aware that the import is lossy, only the IMSI, MSISDN, nam_cs/ps and 2G auth data are set.

View File

@@ -50,15 +50,29 @@ prefix route to the named EUSE. All USSD short codes starting with *123 will be
routed to the named EUSE.
`ussd route prefix *#100# internal own-msisdn` installs a prefix route
to the named internal USSD handler. There above command will restore
to the named internal USSD handler. The above command will restore
the old behavior, in which *#100# will return a text message containing
the subscribers own phone number. There is one other handler called
`own-imsi` which will return the IMSI instead of the MSISDN.
the subscribers own phone number. More information on internal USSD
handlers can be found in <<iuse_handlers>>.
`ussd default-route external foobar-00-00-00-00-00-00` installs a
default route to the named EUSE. This means that all USSD codes for
which no more specific route exists will be routed to the named EUSE.
[[iuse_handlers]]
=== Built-in USSD handlers
OsmoHLR has an Internal USSD Entity (IUSE) that allows to handle some
USSD requests internally. It features a set of simple handlers, which
can be assigned to one or more USSD request prefixes:
* `own-msisdn` returns subscriber's MSISDN (if assigned);
* `own-imsi` returns subscriber's IMSI;
* `test-idle` keeps the session idle until the MS terminates it, or
the guard timer expires (may be useful for testing).
Additional handlers can be added on request.
=== Example EUSE program
We have provided an example EUSE developed in C language using existing

View File

@@ -0,0 +1,14 @@
GET 1 subscriber.by-imsi-901991234567891.aud2g
GET_REPLY 1 subscriber.by-imsi-901991234567891.aud2g none
SET 2 subscriber.by-imsi-901991234567891.aud2g xor,c01ffedc1cadaeac1d1f1edacac1ab0a
SET_REPLY 2 subscriber.by-imsi-901991234567891.aud2g OK
GET 3 subscriber.by-imsi-901991234567891.aud2g
GET_REPLY 3 subscriber.by-imsi-901991234567891.aud2g XOR,c01ffedc1cadaeac1d1f1edacac1ab0a
SET 4 subscriber.by-imsi-901991234567891.aud2g none
SET_REPLY 4 subscriber.by-imsi-901991234567891.aud2g OK
GET 5 subscriber.by-imsi-901991234567891.aud2g
GET_REPLY 5 subscriber.by-imsi-901991234567891.aud2g none

View File

@@ -0,0 +1,20 @@
GET 117 subscriber.by-imsi-901991234567891.aud3g
GET_REPLY 117 subscriber.by-imsi-901991234567891.aud3g none
SET 118 subscriber.by-imsi-901991234567891.aud3g milenage,c01ffedc1cadaeac1d1f1edacac1ab0a,OP,FB2A3D1B360F599ABAB99DB8669F8308
SET_REPLY 118 subscriber.by-imsi-901991234567891.aud3g OK
GET 119 subscriber.by-imsi-901991234567891.aud3g
GET_REPLY 119 subscriber.by-imsi-901991234567891.aud3g MILENAGE,c01ffedc1cadaeac1d1f1edacac1ab0a,OP,fb2a3d1b360f599abab99db8669f8308,5
SET 120 subscriber.by-imsi-901991234567891.aud3g milenage,c01ffedc1cadaeac1d1f1edacac1ab0a,OPC,FB2A3D1B360F599ABAB99DB8669F8308,7
SET_REPLY 120 subscriber.by-imsi-901991234567891.aud3g OK
GET 121 subscriber.by-imsi-901991234567891.aud3g
GET_REPLY 121 subscriber.by-imsi-901991234567891.aud3g MILENAGE,c01ffedc1cadaeac1d1f1edacac1ab0a,OPC,fb2a3d1b360f599abab99db8669f8308,7
SET 122 subscriber.by-imsi-901991234567891.aud3g none
SET_REPLY 122 subscriber.by-imsi-901991234567891.aud3g OK
GET 123 subscriber.by-imsi-901991234567891.aud3g
GET_REPLY 123 subscriber.by-imsi-901991234567891.aud3g none

View File

@@ -0,0 +1,8 @@
GET 1 subscriber.by-imsi-901991234567891.msisdn
GET_REPLY 1 subscriber.by-imsi-901991234567891.msisdn none
SET 2 subscriber.by-imsi-901991234567891.msisdn 555666
SET_REPLY 2 subscriber.by-imsi-901991234567891.msisdn OK
GET 3 subscriber.by-imsi-901991234567891.msisdn
GET_REPLY 3 subscriber.by-imsi-901991234567891.msisdn 555666

View File

@@ -28,6 +28,8 @@ include::{srcdir}/chapters/dgsm.adoc[]
include::./common/chapters/gsup.adoc[]
include::./common/chapters/vty_cpu_sched.adoc[]
include::./common/chapters/port_numbers.adoc[]
include::./common/chapters/bibliography.adoc[]
@@ -35,4 +37,3 @@ include::./common/chapters/bibliography.adoc[]
include::./common/chapters/glossary.adoc[]
include::./common/chapters/gfdl.adoc[]

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
SUBDIRS = osmocom
nobase_include_HEADERS = \
osmocom/gsupclient/gsup_peer_id.h \
osmocom/gsupclient/cni_peer_id.h \
osmocom/gsupclient/gsup_client.h \
osmocom/gsupclient/gsup_req.h \
osmocom/mslookup/mdns.h \

View File

@@ -32,33 +32,35 @@ struct osmo_ipa_name {
uint8_t val[128];
};
bool osmo_ipa_name_is_empty(struct osmo_ipa_name *ipa_name);
bool osmo_ipa_name_is_empty(const struct osmo_ipa_name *ipa_name);
int osmo_ipa_name_set(struct osmo_ipa_name *ipa_name, const uint8_t *val, size_t len);
int osmo_ipa_name_set_str(struct osmo_ipa_name *ipa_name, const char *str_fmt, ...);
int osmo_ipa_name_cmp(const struct osmo_ipa_name *a, const struct osmo_ipa_name *b);
const char *osmo_ipa_name_to_str_c(void *ctx, const struct osmo_ipa_name *ipa_name);
const char *osmo_ipa_name_to_str(const struct osmo_ipa_name *ipa_name);
enum osmo_gsup_peer_id_type {
OSMO_GSUP_PEER_ID_EMPTY=0,
OSMO_GSUP_PEER_ID_IPA_NAME,
/* OSMO_GSUP_PEER_ID_GLOBAL_TITLE, <-- currently not implemented, but likely future possibility */
enum osmo_cni_peer_id_type {
OSMO_CNI_PEER_ID_EMPTY=0,
OSMO_CNI_PEER_ID_IPA_NAME,
/* OSMO_CNI_PEER_ID_GLOBAL_TITLE, <-- currently not implemented, but likely future possibility */
};
extern const struct value_string osmo_gsup_peer_id_type_names[];
static inline const char *osmo_gsup_peer_id_type_name(enum osmo_gsup_peer_id_type val)
{ return get_value_string(osmo_gsup_peer_id_type_names, val); }
extern const struct value_string osmo_cni_peer_id_type_names[];
static inline const char *osmo_cni_peer_id_type_name(enum osmo_cni_peer_id_type val)
{ return get_value_string(osmo_cni_peer_id_type_names, val); }
struct osmo_gsup_peer_id {
enum osmo_gsup_peer_id_type type;
struct osmo_cni_peer_id {
enum osmo_cni_peer_id_type type;
union {
struct osmo_ipa_name ipa_name;
};
};
bool osmo_gsup_peer_id_is_empty(struct osmo_gsup_peer_id *gsup_peer_id);
int osmo_gsup_peer_id_set(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_gsup_peer_id_type type,
bool osmo_cni_peer_id_is_empty(const struct osmo_cni_peer_id *cni_peer_id);
int osmo_cni_peer_id_set(struct osmo_cni_peer_id *cni_peer_id, enum osmo_cni_peer_id_type type,
const uint8_t *val, size_t len);
int osmo_gsup_peer_id_set_str(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_gsup_peer_id_type type,
int osmo_cni_peer_id_set_str(struct osmo_cni_peer_id *cni_peer_id, enum osmo_cni_peer_id_type type,
const char *str_fmt, ...);
int osmo_gsup_peer_id_cmp(const struct osmo_gsup_peer_id *a, const struct osmo_gsup_peer_id *b);
const char *osmo_gsup_peer_id_to_str(const struct osmo_gsup_peer_id *gsup_peer_id);
int osmo_cni_peer_id_cmp(const struct osmo_cni_peer_id *a, const struct osmo_cni_peer_id *b);
const char *osmo_cni_peer_id_to_str(const struct osmo_cni_peer_id *cni_peer_id);
const char *osmo_cni_peer_id_to_str_c(void *ctx, const struct osmo_cni_peer_id *cni_peer_id);

View File

@@ -19,14 +19,14 @@
#pragma once
#include <osmocom/gsm/gsup.h>
#include <osmocom/gsupclient/gsup_peer_id.h>
#include <osmocom/gsupclient/cni_peer_id.h>
struct osmo_gsup_req;
#define LOG_GSUP_REQ_CAT_SRC(req, subsys, level, file, line, fmt, args...) \
LOGPSRC(subsys, level, file, line, "GSUP %u: %s: IMSI-%s %s: " fmt, \
(req) ? (req)->nr : 0, \
(req) ? osmo_gsup_peer_id_to_str(&(req)->source_name) : "NULL", \
(req) ? osmo_cni_peer_id_to_str(&(req)->source_name) : "NULL", \
(req) ? (req)->gsup.imsi : "NULL", \
(req) ? osmo_gsup_message_type_name((req)->gsup.message_type) : "NULL", \
##args)
@@ -56,11 +56,11 @@ struct osmo_gsup_req {
/* The ultimate source of this message: the source_name form the GSUP message, or, if not present, then the
* immediate GSUP peer. GSUP messages going via a proxy reflect the initial source in the source_name.
* This source_name is implicitly added to the routes for the conn the message was received on. */
struct osmo_gsup_peer_id source_name;
struct osmo_cni_peer_id source_name;
/* If the source_name is not an immediate GSUP peer, this is set to the closest intermediate peer between here
* and source_name. */
struct osmo_gsup_peer_id via_proxy;
struct osmo_cni_peer_id via_proxy;
/* Identify this request by number, for logging. */
unsigned int nr;
@@ -82,24 +82,28 @@ struct osmo_gsup_req {
struct msgb *msg;
};
struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_gsup_peer_id *from_peer, struct msgb *msg,
struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_cni_peer_id *from_peer, struct msgb *msg,
osmo_gsup_req_send_response_t send_response_cb, void *cb_data,
struct llist_head *add_to_list);
void osmo_gsup_req_free(struct osmo_gsup_req *req);
/*! Call _osmo_gsup_req_respond() to convey the sender's source file and line in the logs. */
/*! See _osmo_gsup_req_respond() for details.
* Call _osmo_gsup_req_respond(), passing the caller's source file and line for logging. */
#define osmo_gsup_req_respond(REQ, RESPONSE, ERROR, FINAL_RESPONSE) \
_osmo_gsup_req_respond(REQ, RESPONSE, ERROR, FINAL_RESPONSE, __FILE__, __LINE__)
int _osmo_gsup_req_respond(struct osmo_gsup_req *req, struct osmo_gsup_message *response,
bool error, bool final_response, const char *file, int line);
/*! Call _osmo_gsup_req_respond_msgt() to convey the sender's source file and line in the logs. */
/*! See _osmo_gsup_req_respond_msgt() for details.
* Call _osmo_gsup_req_respond_msgt(), passing the caller's source file and line for logging. */
#define osmo_gsup_req_respond_msgt(REQ, MESSAGE_TYPE, FINAL_RESPONSE) \
_osmo_gsup_req_respond_msgt(REQ, MESSAGE_TYPE, FINAL_RESPONSE, __FILE__, __LINE__)
int _osmo_gsup_req_respond_msgt(struct osmo_gsup_req *req, enum osmo_gsup_message_type message_type,
bool final_response, const char *file, int line);
/*! Log an error message, and call _osmo_gsup_req_respond() to convey the sender's source file and line in the logs. */
/*! See _osmo_gsup_req_respond_err() for details.
* Log an error message, and call _osmo_gsup_req_respond_err(), passing the caller's source file and line for logging.
*/
#define osmo_gsup_req_respond_err(REQ, CAUSE, FMT, args...) do { \
LOG_GSUP_REQ(REQ, LOGL_ERROR, "%s: " FMT "\n", \
get_value_string(gsm48_gmm_cause_names, CAUSE), ##args); \

View File

@@ -16,6 +16,5 @@ noinst_HEADERS = \
proxy.h \
rand.h \
remote_hlr.h \
sms_over_gsup.h \
timestamp.h \
$(NULL)

View File

@@ -30,5 +30,4 @@ enum hlr_ctrl_node {
_LAST_CTRL_NODE_HLR
};
int hlr_ctrl_cmds_install();
struct ctrl_handle *hlr_controlif_setup(struct hlr *hlr);

View File

@@ -3,13 +3,19 @@
#include <stdbool.h>
#include <sqlite3.h>
#include <osmocom/gsupclient/gsup_peer_id.h>
#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/gsm/gsup.h>
#include <osmocom/gsm/gsm_utils.h>
struct hlr;
enum stmt_idx {
DB_STMT_SEL_ALL,
DB_STMT_SEL_ALL_ORDER_LAST_SEEN,
DB_STMT_SEL_FILTER_MSISDN,
DB_STMT_SEL_FILTER_IMSI,
DB_STMT_SEL_FILTER_IMEI,
DB_STMT_SEL_FILTER_CS,
DB_STMT_SEL_FILTER_PS,
DB_STMT_SEL_BY_IMSI,
DB_STMT_SEL_BY_MSISDN,
DB_STMT_SEL_BY_ID,
@@ -38,8 +44,6 @@ enum stmt_idx {
DB_STMT_IND_ADD,
DB_STMT_IND_SELECT,
DB_STMT_IND_DEL,
DB_STMT_UPD_RAT_FLAG,
DB_STMT_RAT_BY_ID,
_NUM_DB_STMT
};
@@ -107,18 +111,11 @@ struct hlr_subscriber {
bool ms_purged_ps;
time_t last_lu_seen;
time_t last_lu_seen_ps;
char last_lu_rat_cs[128];
char last_lu_rat_ps[128];
/* talloc'd IPA unit name */
struct osmo_ipa_name vlr_via_proxy;
struct osmo_ipa_name sgsn_via_proxy;
bool rat_types[OSMO_RAT_COUNT];
};
static const struct hlr_subscriber hlr_subscriber_empty = {
.rat_types = { true, true, true },
};
/* A format string for use with strptime(3). This format string is
* used to parse the last_lu_seen column stored in the HLR database.
* See https://sqlite.org/lang_datefunc.html, function datetime(). */
@@ -162,6 +159,9 @@ int db_subscr_update_imei_by_imsi(struct db_context *dbc, const char* imsi, cons
int db_subscr_exists_by_imsi(struct db_context *dbc, const char *imsi);
int db_subscr_exists_by_msisdn(struct db_context *dbc, const char *msisdn);
int db_subscrs_get(struct db_context *dbc, const char *filter_type, const char *filter,
void (*get_cb)(struct hlr_subscriber *subscr, void *data), void *data,
int *count, const char **err);
int db_subscr_get_by_imsi(struct db_context *dbc, const char *imsi,
struct hlr_subscriber *subscr);
int db_subscr_get_by_msisdn(struct db_context *dbc, const char *msisdn,
@@ -172,18 +172,13 @@ int db_subscr_get_by_imei(struct db_context *dbc, const char *imei, struct hlr_s
int db_subscr_nam(struct db_context *dbc, const char *imsi, bool nam_val, bool is_ps);
int db_subscr_lu(struct db_context *dbc, int64_t subscr_id,
const struct osmo_ipa_name *vlr_name, bool is_ps,
const struct osmo_ipa_name *via_proxy,
const enum osmo_rat_type rat_types[], size_t rat_types_len);
const struct osmo_ipa_name *via_proxy);
int db_subscr_purge(struct db_context *dbc, const char *by_imsi,
bool purge_val, bool is_ps);
int db_ind(struct db_context *dbc, const struct osmo_gsup_peer_id *vlr, unsigned int *ind);
int db_ind_del(struct db_context *dbc, const struct osmo_gsup_peer_id *vlr);
int db_subscr_set_rat_type_flag(struct db_context *dbc, int64_t subscr_id, enum osmo_rat_type rat, bool allowed);
int db_subscr_get_rat_types(struct db_context *dbc, struct hlr_subscriber *subscr);
int hlr_subscr_rat_flag(struct hlr *hlr, struct hlr_subscriber *subscr, enum osmo_rat_type rat, bool allowed);
int db_ind(struct db_context *dbc, const struct osmo_cni_peer_id *vlr, unsigned int *ind);
int db_ind_del(struct db_context *dbc, const struct osmo_cni_peer_id *vlr);
/*! Call sqlite3_column_text() and copy result to a char[].
* \param[out] buf A char[] used as sizeof() arg(!) and osmo_strlcpy() target.

View File

@@ -22,9 +22,10 @@
#include <osmocom/mslookup/mslookup.h>
#include <osmocom/hlr/gsup_server.h>
#include <osmocom/hlr/logging.h>
#include <osmocom/gsupclient/gsup_peer_id.h>
#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/gsupclient/gsup_req.h>
#define OSMO_DGSM_DEFAULT_RESULT_TIMEOUT_MS 2000
#define LOG_DGSM(imsi, level, fmt, args...) \
LOGP(DDGSM, level, "(IMSI-%s) " fmt, imsi, ##args)

View File

@@ -5,7 +5,7 @@
#include <osmocom/abis/ipa.h>
#include <osmocom/abis/ipaccess.h>
#include <osmocom/gsm/gsup.h>
#include <osmocom/gsupclient/gsup_peer_id.h>
#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/gsupclient/gsup_req.h>
#ifndef OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN
@@ -42,8 +42,6 @@ struct osmo_gsup_conn {
//struct oap_state oap_state;
struct tlv_parsed ccm;
unsigned int auc_3g_ind; /*!< IND index used for UMTS AKA SQN */
/* Set when Location Update is received: */
bool supports_cs; /* client supports OSMO_GSUP_CN_DOMAIN_CS */
bool supports_ps; /* client supports OSMO_GSUP_CN_DOMAIN_PS */
@@ -74,5 +72,5 @@ int osmo_gsup_create_insert_subscriber_data_msg(struct osmo_gsup_message *gsup,
uint8_t *msisdn_enc, size_t msisdn_enc_size,
uint8_t *apn_buf, size_t apn_buf_size,
enum osmo_gsup_cn_domain cn_domain);
int osmo_gsup_forward_to_local_peer(struct osmo_gsup_server *server, const struct osmo_gsup_peer_id *to_peer,
int osmo_gsup_forward_to_local_peer(struct osmo_gsup_server *server, const struct osmo_cni_peer_id *to_peer,
struct osmo_gsup_req *req, struct osmo_gsup_message *modified_gsup);

View File

@@ -23,6 +23,7 @@
#pragma once
#include <stdbool.h>
#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/gsm/ipa.h>
#include <osmocom/core/tdef.h>
@@ -48,7 +49,6 @@ struct hlr {
/* Control Interface */
struct ctrl_handle *ctrl;
const char *ctrl_bind_addr;
/* Local bind addr */
char *gsup_bind_addr;
@@ -56,7 +56,8 @@ struct hlr {
struct llist_head euse_list;
struct hlr_euse *euse_default;
struct llist_head iuse_list;
enum gsm48_gmm_cause reject_cause;
enum gsm48_gmm_cause no_proxy_reject_cause;
/* NCSS (call independent) session guard timeout value */
int ncss_guard_timeout;
@@ -112,14 +113,6 @@ struct hlr {
} mdns;
} client;
} mslookup;
struct {
/* FIXME actually use branch fixeria/sms for SMSC routing. completely unimplemented */
struct osmo_gsup_peer_id smsc;
/* If no SMSC is present / responsible, try punching the SMS through directly when this is true. */
bool try_direct_delivery;
} sms_over_gsup;
};
extern struct hlr *g_hlr;

View File

@@ -37,7 +37,13 @@ enum hlr_vty_node {
MSLOOKUP_CLIENT_NODE,
};
#define A38_XOR_MIN_KEY_LEN 12
#define A38_XOR_MAX_KEY_LEN 16
#define A38_COMP128_KEY_LEN 16
#define MILENAGE_KEY_LEN 16
int hlr_vty_is_config_node(struct vty *vty, int node);
int hlr_vty_go_parent(struct vty *vty);
void hlr_vty_init(void);
void hlr_vty_init(void *hlr_ctx);
void dgsm_vty_init(void);

View File

@@ -11,6 +11,7 @@ enum {
DMSLOOKUP,
DLU,
DDGSM,
DCTRL,
};
extern const struct log_info hlr_log_info;

View File

@@ -19,7 +19,7 @@
#pragma once
#include <osmocom/gsupclient/gsup_peer_id.h>
#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/mslookup/mslookup.h>
struct osmo_mslookup_query;

View File

@@ -22,7 +22,7 @@
#include <time.h>
#include <osmocom/gsm/protocol/gsm_23_003.h>
#include <osmocom/core/sockaddr_str.h>
#include <osmocom/gsupclient/gsup_peer_id.h>
#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/hlr/timestamp.h>
struct osmo_gsup_req;

View File

@@ -1,8 +0,0 @@
#pragma once
#include <stdbool.h>
#include <osmocom/gsupclient/gsup_req.h>
#define OSMO_MSLOOKUP_SERVICE_SMS_GSUP "gsup.sms"
bool sms_over_gsup_check_handle_msg(struct osmo_gsup_req *req);

View File

@@ -99,15 +99,12 @@ struct osmo_mdns_rfc_record {
uint8_t *rdata;
};
char *osmo_mdns_rfc_qname_encode(void *ctx, const char *domain);
char *osmo_mdns_rfc_qname_decode(void *ctx, const char *qname, size_t qname_len);
void osmo_mdns_rfc_header_encode(struct msgb *msg, const struct osmo_mdns_rfc_header *hdr);
int osmo_mdns_rfc_header_decode(const uint8_t *data, size_t data_len, struct osmo_mdns_rfc_header *hdr);
int osmo_mdns_rfc_question_encode(void *ctx, struct msgb *msg, const struct osmo_mdns_rfc_question *qst);
int osmo_mdns_rfc_question_encode(struct msgb *msg, const struct osmo_mdns_rfc_question *qst);
struct osmo_mdns_rfc_question *osmo_mdns_rfc_question_decode(void *ctx, const uint8_t *data, size_t data_len);
int osmo_mdns_rfc_record_encode(void *ctx, struct msgb *msg, const struct osmo_mdns_rfc_record *rec);
int osmo_mdns_rfc_record_encode(struct msgb *msg, const struct osmo_mdns_rfc_record *rec);
struct osmo_mdns_rfc_record *osmo_mdns_rfc_record_decode(void *ctx, const uint8_t *data, size_t data_len,
size_t *record_len);

View File

@@ -45,12 +45,6 @@ CREATE TABLE subscriber (
last_lu_seen TIMESTAMP default NULL,
last_lu_seen_ps TIMESTAMP default NULL,
-- Last Radio Access Type list as sent during Location Updating Request.
-- This is usually just one RAT name, but can be a comma separated list of strings
-- of all the RAT types sent during Location Updating Request.
last_lu_rat_cs TEXT default NULL,
last_lu_rat_ps TEXT default NULL,
-- When a LU was received via a proxy, that proxy's hlr_number is stored here,
-- while vlr_number reflects the MSC on the far side of that proxy.
vlr_via_proxy VARCHAR,
@@ -93,17 +87,8 @@ CREATE TABLE ind (
UNIQUE (vlr)
);
-- Optional: add subscriber entries to allow or disallow specific RATs (2G or 3G or ...).
-- If a subscriber has no entry, that means that all RATs are allowed (backwards compat).
CREATE TABLE subscriber_rat (
subscriber_id INTEGER, -- subscriber.id
rat TEXT CHECK(rat in ('GERAN-A', 'UTRAN-Iu','EUTRAN-SGs')) NOT NULL, -- Radio Access Technology, see enum ran_type
allowed BOOLEAN CHECK(allowed in (0, 1)) NOT NULL DEFAULT 0
);
CREATE UNIQUE INDEX idx_subscr_imsi ON subscriber (imsi);
CREATE UNIQUE INDEX idx_subscr_rat_flag ON subscriber_rat (subscriber_id, rat);
-- Set HLR database schema version number
-- Note: This constant is currently duplicated in src/db.c and must be kept in sync!
PRAGMA user_version = 8;
PRAGMA user_version = 6;

View File

@@ -1,8 +0,0 @@
CREATE TABLE subscriber_rat (
subscriber_id INTEGER, -- subscriber.id
rat TEXT CHECK(rat in ('GERAN-A', 'UTRAN-Iu')) NOT NULL, -- Radio Access Technology, see enum ran_type
allowed BOOLEAN NOT NULL DEFAULT 0,
);
PRAGMA user_version = 3;

View File

@@ -61,7 +61,6 @@ osmo_hlr_SOURCES = \
mslookup_server.c \
mslookup_server_mdns.c \
dgsm_vty.c \
sms_over_gsup.c \
$(NULL)
osmo_hlr_LDADD = \
@@ -83,7 +82,7 @@ osmo_hlr_db_tool_SOURCES = \
logging.c \
rand_urandom.c \
dbd_decode_binary.c \
$(srcdir)/gsupclient/gsup_peer_id.c \
$(srcdir)/gsupclient/cni_peer_id.c \
$(NULL)
osmo_hlr_db_tool_LDADD = \

View File

@@ -31,12 +31,16 @@
#include <osmocom/hlr/hlr.h>
#include <osmocom/hlr/ctrl.h>
#include <osmocom/hlr/db.h>
#include <osmocom/hlr/hlr_vty.h>
#define SEL_BY "by-"
#define SEL_BY_IMSI SEL_BY "imsi-"
#define SEL_BY_MSISDN SEL_BY "msisdn-"
#define SEL_BY_ID SEL_BY "id-"
extern bool auth_algo_parse(const char *alg_str, enum osmo_auth_algo *algo,
int *minlen, int *maxlen);
#define hexdump_buf(buf) osmo_hexdump_nospc((void*)buf, sizeof(buf))
static bool startswith(const char *str, const char *start)
@@ -197,6 +201,77 @@ static void print_subscr_info_aud3g(struct ctrl_cmd *cmd, struct osmo_sub_auth_d
aud->u.umts.sqn);
}
CTRL_CMD_DEFINE_WO_NOVRF(subscr_create, "create");
static int set_subscr_create(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *imsi = cmd->value;
int rc;
if (!osmo_imsi_str_valid(imsi)) {
cmd->reply = "Invalid IMSI value.";
return CTRL_CMD_ERROR;
}
/* Create the subscriber in the DB */
rc = db_subscr_create(g_hlr->dbc, imsi, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS);
if (rc) {
if (rc == -EEXIST)
cmd->reply = "Subscriber already exists.";
else
cmd->reply = "Cannot create subscriber.";
return CTRL_CMD_ERROR;
}
LOGP(DCTRL, LOGL_INFO, "Created subscriber IMSI='%s'\n",
imsi);
/* Retrieve data of newly created subscriber: */
rc = db_subscr_get_by_imsi(hlr->dbc, imsi, &subscr);
if (rc < 0) {
cmd->reply = "Failed retrieving ID of newly created subscriber.";
return CTRL_CMD_ERROR;
}
cmd->reply = talloc_asprintf(cmd, "%" PRIu64, subscr.id);
return CTRL_CMD_REPLY;
}
CTRL_CMD_DEFINE_WO_NOVRF(subscr_delete, "delete");
static int set_subscr_delete(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *imsi = cmd->value;
int rc;
if (!osmo_imsi_str_valid(imsi)) {
cmd->reply = "Invalid IMSI value.";
return CTRL_CMD_ERROR;
}
/* Retrieve data of newly created subscriber: */
rc = db_subscr_get_by_imsi(hlr->dbc, imsi, &subscr);
if (rc < 0) {
cmd->reply = "Subscriber doesn't exist.";
return CTRL_CMD_ERROR;
}
/* Create the subscriber in the DB */
rc = db_subscr_delete_by_id(g_hlr->dbc, subscr.id);
if (rc) {
cmd->reply = "Cannot delete subscriber.";
return CTRL_CMD_ERROR;
}
LOGP(DCTRL, LOGL_INFO, "Deleted subscriber IMSI='%s'\n",
imsi);
cmd->reply = talloc_asprintf(cmd, "%" PRIu64, subscr.id);
return CTRL_CMD_REPLY;
}
CTRL_CMD_DEFINE_RO(subscr_info, "info");
static int get_subscr_info(struct ctrl_cmd *cmd, void *data)
{
@@ -351,17 +426,302 @@ static int set_subscr_cs_enabled(struct ctrl_cmd *cmd, void *data)
return set_subscr_cs_ps_enabled(cmd, data, false);
}
int hlr_ctrl_cmds_install()
CTRL_CMD_DEFINE(subscr_msisdn, "msisdn");
static int verify_subscr_msisdn(struct ctrl_cmd *cmd, const char *value, void *data)
{
int rc = 0;
struct hlr_subscriber subscr;
if (!value)
return 1;
if (strlen(value) > sizeof(subscr.msisdn) - 1)
return 1;
if (strcmp(value, "none") != 0 && !osmo_msisdn_str_valid(value))
return 1;
return 0;
}
static int get_subscr_msisdn(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info_aud);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info_all);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_ps_enabled);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_cs_enabled);
if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
return CTRL_CMD_ERROR;
return rc;
if (strlen(subscr.msisdn) == 0)
snprintf(subscr.msisdn, sizeof(subscr.msisdn), "none");
cmd->reply = talloc_asprintf(cmd, "%s", subscr.msisdn);
return CTRL_CMD_REPLY;
}
static int set_subscr_msisdn(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
const char *msisdn;
if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
return CTRL_CMD_ERROR;
if (strcmp(cmd->value, "none") == 0)
msisdn = NULL;
else
msisdn = cmd->value;
if (db_subscr_update_msisdn_by_imsi(g_hlr->dbc, subscr.imsi, msisdn)) {
cmd->reply = "Update MSISDN failed";
return CTRL_CMD_ERROR;
}
cmd->reply = "OK";
return CTRL_CMD_REPLY;
}
/* value format: <algo[,KI]> */
CTRL_CMD_DEFINE(subscr_aud2g, "aud2g");
static int verify_subscr_aud2g(struct ctrl_cmd *cmd, const char *value, void *data)
{
if (!value)
return 1;
if (strcasecmp(value, "none") != 0 && !strchr(value, ','))
return 1;
return 0;
}
static int get_subscr_aud2g(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
struct osmo_sub_auth_data aud2g;
struct osmo_sub_auth_data aud3g_unused;
int rc;
if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
return CTRL_CMD_ERROR;
rc = db_get_auth_data(hlr->dbc, subscr.imsi, &aud2g, &aud3g_unused, NULL);
switch (rc) {
case 0:
break;
case -ENOENT:
case -ENOKEY:
aud2g.algo = OSMO_AUTH_ALG_NONE;
break;
default:
cmd->reply = "Error retrieving data from database.";
return CTRL_CMD_ERROR;
}
if (aud2g.algo == OSMO_AUTH_ALG_NONE) {
cmd->reply = "none";
return CTRL_CMD_REPLY;
}
cmd->reply = talloc_asprintf(cmd, "%s,%s", osmo_auth_alg_name(aud2g.algo),
hexdump_buf(aud2g.u.gsm.ki));
return CTRL_CMD_REPLY;
}
static int set_subscr_aud2g(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
char *tmp = NULL, *tok, *saveptr;
int minlen = 0;
int maxlen = 0;
struct sub_auth_data_str aud2g = {
.type = OSMO_AUTH_TYPE_GSM
};
if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
return CTRL_CMD_ERROR;
tmp = talloc_strdup(cmd, cmd->value);
if (!tmp) {
cmd->reply = "OOM";
return CTRL_CMD_ERROR;
}
/* Parse alg_type: */
tok = strtok_r(tmp, ",", &saveptr);
if (!tok) {
cmd->reply = "Invalid format";
return CTRL_CMD_ERROR;
}
if (strcmp(tok, "none") == 0) {
aud2g.algo = OSMO_AUTH_ALG_NONE;
} else if (!auth_algo_parse(tok, &aud2g.algo, &minlen, &maxlen)) {
cmd->reply = "Unknown auth algorithm.";
return CTRL_CMD_ERROR;
}
if (aud2g.algo != OSMO_AUTH_ALG_NONE) {
tok = strtok_r(NULL, "\0", &saveptr);
if (!tok) {
cmd->reply = "Invalid format.";
return CTRL_CMD_ERROR;
}
aud2g.u.gsm.ki = tok;
if (!osmo_is_hexstr(aud2g.u.gsm.ki, minlen * 2, maxlen * 2, true)) {
cmd->reply = "Invalid KI.";
return CTRL_CMD_ERROR;
}
}
if (db_subscr_update_aud_by_id(g_hlr->dbc, subscr.id, &aud2g)) {
cmd->reply = "Update aud2g failed.";
return CTRL_CMD_ERROR;
}
cmd->reply = "OK";
return CTRL_CMD_REPLY;
}
/* value format: <algo[,KI,(op|opc),OP_C[,ind_bitlen]]> */
CTRL_CMD_DEFINE(subscr_aud3g, "aud3g");
static int verify_subscr_aud3g(struct ctrl_cmd *cmd, const char *value, void *data)
{
if (!value)
return 1;
if (strcasecmp(value, "none") != 0 && !strchr(value, ','))
return 1;
return 0;
}
static int get_subscr_aud3g(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
struct osmo_sub_auth_data aud2g_unused;
struct osmo_sub_auth_data aud3g;
int rc;
if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
return CTRL_CMD_ERROR;
rc = db_get_auth_data(hlr->dbc, subscr.imsi, &aud2g_unused, &aud3g, NULL);
switch (rc) {
case 0:
break;
case -ENOENT:
case -ENOKEY:
aud3g.algo = OSMO_AUTH_ALG_NONE;
break;
default:
cmd->reply = "Error retrieving data from database.";
return CTRL_CMD_ERROR;
}
if (aud3g.algo == OSMO_AUTH_ALG_NONE) {
cmd->reply = "none";
return CTRL_CMD_REPLY;
}
cmd->reply = talloc_asprintf(cmd, "%s,%s,%s,%s,%u", osmo_auth_alg_name(aud3g.algo),
osmo_hexdump_nospc_c(cmd, aud3g.u.umts.k, sizeof(aud3g.u.umts.k)),
aud3g.u.umts.opc_is_op ? "OP" : "OPC",
osmo_hexdump_nospc_c(cmd, aud3g.u.umts.opc, sizeof(aud3g.u.umts.opc)),
aud3g.u.umts.ind_bitlen);
return CTRL_CMD_REPLY;
}
static int set_subscr_aud3g(struct ctrl_cmd *cmd, void *data)
{
struct hlr_subscriber subscr;
struct hlr *hlr = data;
const char *by_selector = cmd->node;
char *tmp = NULL, *tok, *saveptr;
int minlen = 0;
int maxlen = 0;
struct sub_auth_data_str aud3g = {
.type = OSMO_AUTH_TYPE_UMTS,
.u.umts = {
.ind_bitlen = 5,
},
};
bool ind_bitlen_present;
if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
return CTRL_CMD_ERROR;
tmp = talloc_strdup(cmd, cmd->value);
if (!tmp) {
cmd->reply = "OOM";
return CTRL_CMD_ERROR;
}
/* Parse alg_type: */
tok = strtok_r(tmp, ",", &saveptr);
if (!tok) {
cmd->reply = "Invalid format.";
return CTRL_CMD_ERROR;
}
if (strcmp(tok, "none") == 0) {
aud3g.algo = OSMO_AUTH_ALG_NONE;
} else if (!auth_algo_parse(tok, &aud3g.algo, &minlen, &maxlen)) {
cmd->reply = "Unknown auth algorithm.";
return CTRL_CMD_ERROR;
}
if (aud3g.algo != OSMO_AUTH_ALG_NONE) {
/* Parse K */
tok = strtok_r(NULL, ",", &saveptr);
if (!tok) {
cmd->reply = "Invalid format.";
return CTRL_CMD_ERROR;
}
aud3g.u.umts.k = tok;
if (!osmo_is_hexstr(aud3g.u.umts.k, minlen * 2, maxlen * 2, true)) {
cmd->reply = "Invalid KI.";
return CTRL_CMD_ERROR;
}
/* Parse OP/OPC choice */
tok = strtok_r(NULL, ",", &saveptr);
if (!tok) {
cmd->reply = "Invalid format.";
return CTRL_CMD_ERROR;
}
if (strcasecmp(tok, "op") == 0) {
aud3g.u.umts.opc_is_op = true;
} else if (strcasecmp(tok, "opc") == 0) {
aud3g.u.umts.opc_is_op = false;
} else {
cmd->reply = "Invalid format.";
return CTRL_CMD_ERROR;
}
/* Parse OP/OPC value */
ind_bitlen_present = !!strchr(saveptr, ',');
tok = strtok_r(NULL, ind_bitlen_present ? "," : "\0", &saveptr);
if (!tok) {
cmd->reply = "Invalid format.";
return CTRL_CMD_ERROR;
}
aud3g.u.umts.opc = tok;
if (!osmo_is_hexstr(aud3g.u.umts.opc, MILENAGE_KEY_LEN * 2, MILENAGE_KEY_LEN * 2, true)) {
cmd->reply = talloc_asprintf(cmd, "Invalid OP/OPC.");
return CTRL_CMD_ERROR;
}
if (ind_bitlen_present) {
/* Parse bitlen_ind */
tok = strtok_r(NULL, "\0", &saveptr);
if (!tok || tok[0] == '\0') {
cmd->reply = "Invalid format.";
return CTRL_CMD_ERROR;
}
aud3g.u.umts.ind_bitlen = atoi(tok);
}
}
if (db_subscr_update_aud_by_id(g_hlr->dbc, subscr.id, &aud3g)) {
cmd->reply = "Update aud3g failed.";
return CTRL_CMD_ERROR;
}
cmd->reply = "OK";
return CTRL_CMD_REPLY;
}
static int hlr_ctrl_node_lookup(void *data, vector vline, int *node_type,
@@ -389,14 +749,30 @@ static int hlr_ctrl_node_lookup(void *data, vector vline, int *node_type,
return 1;
}
static int hlr_ctrl_cmds_install(void)
{
int rc = 0;
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR, &cmd_subscr_create);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR, &cmd_subscr_delete);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info_aud);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info_all);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_ps_enabled);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_cs_enabled);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_msisdn);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_aud2g);
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_aud3g);
return rc;
}
struct ctrl_handle *hlr_controlif_setup(struct hlr *hlr)
{
int rc;
struct ctrl_handle *hdl = ctrl_interface_setup_dynip2(hlr,
hlr->ctrl_bind_addr,
OSMO_CTRL_PORT_HLR,
hlr_ctrl_node_lookup,
_LAST_CTRL_NODE_HLR);
struct ctrl_handle *hdl = ctrl_interface_setup2(hlr, OSMO_CTRL_PORT_HLR, hlr_ctrl_node_lookup,
_LAST_CTRL_NODE_HLR);
if (!hdl)
return NULL;

View File

@@ -22,15 +22,13 @@
#include <stdbool.h>
#include <sqlite3.h>
#include <string.h>
#include <errno.h>
#include <osmocom/hlr/logging.h>
#include <osmocom/hlr/db.h>
#include "db_bootstrap.h"
/* This constant is currently duplicated in sql/hlr.sql and must be kept in sync! */
#define CURRENT_SCHEMA_VERSION 8
#define CURRENT_SCHEMA_VERSION 6
#define SEL_COLUMNS \
"id," \
@@ -49,12 +47,18 @@
"ms_purged_ps," \
"last_lu_seen," \
"last_lu_seen_ps," \
"last_lu_rat_cs," \
"last_lu_rat_ps," \
"vlr_via_proxy," \
"sgsn_via_proxy"
static const char *stmt_sql[] = {
[DB_STMT_SEL_ALL] = "SELECT " SEL_COLUMNS " FROM subscriber;",
[DB_STMT_SEL_ALL_ORDER_LAST_SEEN] = "SELECT " SEL_COLUMNS " FROM subscriber "
"WHERE last_lu_seen IS NOT NULL ORDER BY last_lu_seen;",
[DB_STMT_SEL_FILTER_MSISDN] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE msisdn LIKE $search ORDER BY msisdn",
[DB_STMT_SEL_FILTER_IMSI] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE imsi LIKE $search ORDER BY imsi",
[DB_STMT_SEL_FILTER_IMEI] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE imei LIKE $search ORDER BY imei",
[DB_STMT_SEL_FILTER_CS] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE nam_cs = $search ORDER BY last_lu_seen",
[DB_STMT_SEL_FILTER_PS] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE nam_ps = $search ORDER BY last_lu_seen",
[DB_STMT_SEL_BY_IMSI] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE imsi = ?",
[DB_STMT_SEL_BY_MSISDN] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE msisdn = ?",
[DB_STMT_SEL_BY_ID] = "SELECT " SEL_COLUMNS " FROM subscriber WHERE id = ?",
@@ -85,23 +89,13 @@ static const char *stmt_sql[] = {
"INSERT INTO auc_3g (subscriber_id, algo_id_3g, k, op, opc, ind_bitlen)"
" VALUES($subscriber_id, $algo_id_3g, $k, $op, $opc, $ind_bitlen)",
[DB_STMT_AUC_3G_DELETE] = "DELETE FROM auc_3g WHERE subscriber_id = $subscriber_id",
[DB_STMT_SET_LAST_LU_SEEN] = "UPDATE subscriber SET last_lu_seen = datetime($val, 'unixepoch'),"
" last_lu_rat_cs = $rat"
" WHERE id = $subscriber_id",
[DB_STMT_SET_LAST_LU_SEEN_PS] = "UPDATE subscriber SET last_lu_seen_ps = datetime($val, 'unixepoch'),"
" last_lu_rat_ps = $rat"
" WHERE id = $subscriber_id",
[DB_STMT_SET_LAST_LU_SEEN] = "UPDATE subscriber SET last_lu_seen = datetime($val, 'unixepoch') WHERE id = $subscriber_id",
[DB_STMT_SET_LAST_LU_SEEN_PS] = "UPDATE subscriber SET last_lu_seen_ps = datetime($val, 'unixepoch') WHERE id = $subscriber_id",
[DB_STMT_EXISTS_BY_IMSI] = "SELECT 1 FROM subscriber WHERE imsi = $imsi",
[DB_STMT_EXISTS_BY_MSISDN] = "SELECT 1 FROM subscriber WHERE msisdn = $msisdn",
[DB_STMT_IND_ADD] = "INSERT INTO ind (vlr) VALUES ($vlr)",
[DB_STMT_IND_SELECT] = "SELECT ind FROM ind WHERE vlr = $vlr",
[DB_STMT_IND_DEL] = "DELETE FROM ind WHERE vlr = $vlr",
[DB_STMT_UPD_RAT_FLAG] = "INSERT OR REPLACE INTO subscriber_rat (subscriber_id, rat, allowed)"
" VALUES ($subscriber_id, $rat, $allowed)",
[DB_STMT_RAT_BY_ID] =
"SELECT rat, allowed"
" FROM subscriber_rat"
" WHERE subscriber_id = $subscriber_id",
};
static void sql3_error_log_cb(void *arg, int err_code, const char *msg)
@@ -243,7 +237,7 @@ void db_close(struct db_context *dbc)
static int db_run_statements(struct db_context *dbc, const char **statements, size_t statements_count)
{
int rc;
int rc = 0;
int i;
for (i = 0; i < statements_count; i++) {
const char *stmt_str = statements[i];
@@ -519,46 +513,6 @@ static int db_upgrade_v6(struct db_context *dbc)
return rc;
}
static int db_upgrade_v7(struct db_context *dbc)
{
int rc;
const char *statements[] = {
"-- Optional: add subscriber entries to allow or disallow specific RATs (2G or 3G or ...).\n"
"-- If a subscriber has no entry, that means that all RATs are allowed (backwards compat).\n"
"CREATE TABLE subscriber_rat (\n"
" subscriber_id INTEGER, -- subscriber.id\n"
" rat TEXT CHECK(rat in ('GERAN-A', 'UTRAN-Iu')) NOT NULL, -- Radio Access Technology, see enum ran_type\n"
" allowed BOOLEAN CHECK(allowed in (0, 1)) NOT NULL DEFAULT 0\n"
")",
"CREATE UNIQUE INDEX idx_subscr_rat_flag ON subscriber_rat (subscriber_id, rat)",
"PRAGMA user_version = 7",
};
rc = db_run_statements(dbc, statements, ARRAY_SIZE(statements));
if (rc != SQLITE_DONE) {
LOGP(DDB, LOGL_ERROR, "Unable to update HLR database schema to version 7\n");
return rc;
}
return rc;
}
static int db_upgrade_v8(struct db_context *dbc)
{
int rc;
const char *statements[] = {
"ALTER TABLE subscriber ADD COLUMN last_lu_rat_cs TEXT default NULL",
"ALTER TABLE subscriber ADD COLUMN last_lu_rat_ps TEXT default NULL",
"PRAGMA user_version = 8",
};
rc = db_run_statements(dbc, statements, ARRAY_SIZE(statements));
if (rc != SQLITE_DONE) {
LOGP(DDB, LOGL_ERROR, "Unable to update HLR database schema to version 7\n");
return rc;
}
return rc;
}
typedef int (*db_upgrade_func_t)(struct db_context *dbc);
static db_upgrade_func_t db_upgrade_path[] = {
db_upgrade_v1,
@@ -567,8 +521,6 @@ static db_upgrade_func_t db_upgrade_path[] = {
db_upgrade_v4,
db_upgrade_v5,
db_upgrade_v6,
db_upgrade_v7,
db_upgrade_v8,
};
static int db_get_user_version(struct db_context *dbc)
@@ -657,9 +609,11 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logg
char *err_msg;
rc = sqlite3_exec(dbc->db, "PRAGMA journal_mode=WAL; PRAGMA synchonous = NORMAL;", 0, 0, &err_msg);
if (rc != SQLITE_OK)
if (rc != SQLITE_OK) {
LOGP(DDB, LOGL_ERROR, "Unable to set Write-Ahead Logging: %s\n",
err_msg);
sqlite3_free(err_msg);
}
version = db_get_user_version(dbc);
if (version < 0) {
@@ -697,9 +651,9 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logg
if (version < CURRENT_SCHEMA_VERSION) {
LOGP(DDB, LOGL_NOTICE, "HLR DB schema version %d is outdated\n", version);
if (!allow_upgrade) {
LOGP(DDB, LOGL_ERROR, "Not upgrading HLR database from schema version %d to %d; "
LOGP(DDB, LOGL_ERROR, "Not upgrading HLR database to schema version %d; "
"use the --db-upgrade option to allow HLR database upgrades\n",
version, CURRENT_SCHEMA_VERSION);
CURRENT_SCHEMA_VERSION);
}
} else
LOGP(DDB, LOGL_ERROR, "HLR DB schema version %d is unknown\n", version);

View File

@@ -95,7 +95,10 @@ static int hexparse_stmt(uint8_t *dst, size_t dst_len, sqlite3_stmt *stmt, int c
LOGAUC(imsi, LOGL_ERROR, "Error reading %s\n", col_name);
return -EIO;
}
osmo_hexparse((void *)text, dst, dst_len);
if (osmo_hexparse((void *)text, dst, dst_len) != col_len)
return -EINVAL;
return 0;
}

View File

@@ -37,7 +37,7 @@
#include <osmocom/hlr/logging.h>
#include <osmocom/hlr/hlr.h>
#include <osmocom/hlr/db.h>
#include <osmocom/gsupclient/gsup_peer_id.h>
#include <osmocom/gsupclient/cni_peer_id.h>
#define LOGHLR(imsi, level, fmt, args ...) LOGP(DAUC, level, "IMSI='%s': " fmt, imsi, ## args)
@@ -45,7 +45,8 @@
* \param[in,out] dbc database context.
* \param[in] imsi ASCII string of IMSI digits, is validated.
* \param[in] flags Bitmask of DB_SUBSCR_FLAG_*.
* \returns 0 on success, -EINVAL on invalid IMSI, -EIO on database error.
* \returns 0 on success, -EINVAL on invalid IMSI, -EEXIST if subscriber with
* provided imsi already exists, -EIO on other database errors.
*/
int db_subscr_create(struct db_context *dbc, const char *imsi, uint8_t flags)
{
@@ -73,6 +74,8 @@ int db_subscr_create(struct db_context *dbc, const char *imsi, uint8_t flags)
if (rc != SQLITE_DONE) {
LOGHLR(imsi, LOGL_ERROR, "Cannot create subscriber: SQL error: (%d) %s\n",
rc, sqlite3_errmsg(dbc->db));
if (rc == SQLITE_CONSTRAINT_UNIQUE)
return -EEXIST;
return -EIO;
}
@@ -264,11 +267,11 @@ int db_subscr_update_aud_by_id(struct db_context *dbc, int64_t subscr_id,
switch (aud->algo) {
case OSMO_AUTH_ALG_NONE:
case OSMO_AUTH_ALG_MILENAGE:
case OSMO_AUTH_ALG_XOR:
break;
case OSMO_AUTH_ALG_COMP128v1:
case OSMO_AUTH_ALG_COMP128v2:
case OSMO_AUTH_ALG_COMP128v3:
case OSMO_AUTH_ALG_XOR:
LOGP(DAUC, LOGL_ERROR, "Cannot update auth tokens:"
" auth algo not suited for 3G: %s\n",
osmo_auth_alg_name(aud->algo));
@@ -483,7 +486,7 @@ static int db_sel(struct db_context *dbc, sqlite3_stmt *stmt, struct hlr_subscri
if (!subscr)
goto out;
*subscr = hlr_subscriber_empty;
*subscr = (struct hlr_subscriber){};
/* obtain the various columns */
subscr->id = sqlite3_column_int64(stmt, 0);
@@ -505,17 +508,12 @@ static int db_sel(struct db_context *dbc, sqlite3_stmt *stmt, struct hlr_subscri
subscr->imsi, "CS");
parse_last_lu_seen(&subscr->last_lu_seen_ps, (const char *)sqlite3_column_text(stmt, 15),
subscr->imsi, "PS");
copy_sqlite3_text_to_buf(subscr->last_lu_rat_cs, stmt, 16);
copy_sqlite3_text_to_buf(subscr->last_lu_rat_ps, stmt, 17);
copy_sqlite3_text_to_ipa_name(&subscr->vlr_via_proxy, stmt, 18);
copy_sqlite3_text_to_ipa_name(&subscr->sgsn_via_proxy, stmt, 19);
copy_sqlite3_text_to_ipa_name(&subscr->vlr_via_proxy, stmt, 16);
copy_sqlite3_text_to_ipa_name(&subscr->sgsn_via_proxy, stmt, 17);
out:
db_remove_reset(stmt);
if (ret == 0)
db_subscr_get_rat_types(dbc, subscr);
switch (ret) {
case 0:
*err = NULL;
@@ -630,6 +628,94 @@ int db_subscr_get_by_msisdn(struct db_context *dbc, const char *msisdn,
return rc;
}
/*! Retrieve subscriber data from the HLR database.
* \param[in,out] dbc database context.
* \param[in] filter_type ASCII string of identifier type to search.
* \param[in] filter ASCII string to search.
* \param[in] get_cb pointer to call back function for data.
* \param[in,out] data pointer to pass to callback function.
* \param[in,out] count counter for number of matched subscribers.
* \param[in,our] err
* \returns 0 on success, -ENOENT if no subscriber was found, -EIO on
* database error.
*/
int db_subscrs_get(struct db_context *dbc, const char *filter_type, const char *filter,
void (*get_cb)(struct hlr_subscriber *subscr, void *data), void *data,
int *count, const char **err)
{
sqlite3_stmt *stmt;
char search[256];
int rc;
struct hlr_subscriber subscr;
bool show_ls = false;
if (!filter_type) {
stmt = dbc->stmt[DB_STMT_SEL_ALL];
} else if (strcmp(filter_type, "imei") == 0) {
stmt = dbc->stmt[DB_STMT_SEL_FILTER_IMEI];
} else if (strcmp(filter_type, "imsi") == 0) {
stmt = dbc->stmt[DB_STMT_SEL_FILTER_IMSI];
} else if (strcmp(filter_type, "msisdn") == 0) {
stmt = dbc->stmt[DB_STMT_SEL_FILTER_MSISDN];
} else if (strcmp(filter_type, "cs") == 0) {
stmt = dbc->stmt[DB_STMT_SEL_FILTER_CS];
} else if (strcmp(filter_type, "ps") == 0) {
stmt = dbc->stmt[DB_STMT_SEL_FILTER_PS];
} else if (strcmp(filter_type, "last_lu_seen") == 0) {
show_ls = true;
stmt = dbc->stmt[DB_STMT_SEL_ALL_ORDER_LAST_SEEN];
} else {
return -EIO;
}
if (filter_type && filter && strcmp(filter_type, "last_lu_seen") != 0) {
if (strcmp(filter, "on") == 0) {
sprintf(search, "%s", "1");
} else if (strcmp(filter, "off") == 0) {
sprintf(search, "%s", "0");
} else {
sprintf(search, "%%%s%%", filter);
}
if (!db_bind_text(stmt, "$search", search)) {
*err = sqlite3_errmsg(dbc->db);
return -EIO;
}
}
rc = sqlite3_step(stmt);
if (rc == SQLITE_DONE) {
db_remove_reset(stmt);
*err = "No matching subscriber(s)";
return -ENOENT;
}
while (rc == SQLITE_ROW) {
subscr = (struct hlr_subscriber){
.id = sqlite3_column_int64(stmt, 0),};
copy_sqlite3_text_to_buf(subscr.imsi, stmt, 1);
copy_sqlite3_text_to_buf(subscr.msisdn, stmt, 2);
copy_sqlite3_text_to_buf(subscr.imei, stmt, 3);
subscr.nam_cs = sqlite3_column_int(stmt, 9);
subscr.nam_ps = sqlite3_column_int(stmt, 10);
if (show_ls)
parse_last_lu_seen(&subscr.last_lu_seen, (const char *)sqlite3_column_text(stmt, 14),
subscr.imsi, "CS");
get_cb(&subscr, data);
rc = sqlite3_step(stmt);
(*count)++;
}
db_remove_reset(stmt);
if (rc != SQLITE_DONE) {
*err = sqlite3_errmsg(dbc->db);
LOGP(DAUC, LOGL_ERROR, "Cannot read subscribers from db:: %s\n", *err);
return rc;
}
*err = NULL;
return 0;
}
/*! Retrieve subscriber data from the HLR database.
* \param[in,out] dbc database context.
* \param[in] id ID of the subscriber in the HLR db.
@@ -742,14 +828,11 @@ out:
*/
int db_subscr_lu(struct db_context *dbc, int64_t subscr_id,
const struct osmo_ipa_name *vlr_name, bool is_ps,
const struct osmo_ipa_name *via_proxy,
const enum osmo_rat_type rat_types[], size_t rat_types_len)
const struct osmo_ipa_name *via_proxy)
{
sqlite3_stmt *stmt;
int rc, ret = 0;
struct timespec localtime;
char rat_types_str[128] = "";
int i;
stmt = dbc->stmt[is_ps ? DB_STMT_UPD_SGSN_BY_ID
: DB_STMT_UPD_VLR_BY_ID];
@@ -811,21 +894,6 @@ int db_subscr_lu(struct db_context *dbc, int64_t subscr_id,
goto out;
}
for (i = 0; i < rat_types_len; i++) {
char *pos = rat_types_str + strnlen(rat_types_str, sizeof(rat_types_str));
int len = sizeof(rat_types_str) - (pos - rat_types_str);
rc = snprintf(pos, len, "%s%s", pos == rat_types_str ? "" : ",", osmo_rat_type_name(rat_types[i]));
if (rc > len) {
osmo_strlcpy(rat_types_str + sizeof(rat_types_str) - 4, "...", 4);
break;
}
}
if (!db_bind_text(stmt, "$rat", rat_types_str)) {
ret = -EIO;
goto out;
}
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) {
LOGP(DAUC, LOGL_ERROR,
@@ -962,14 +1030,14 @@ out:
return ret;
}
int _db_ind(struct db_context *dbc, const struct osmo_gsup_peer_id *vlr,
int _db_ind(struct db_context *dbc, const struct osmo_cni_peer_id *vlr,
unsigned int *ind, bool del)
{
const char *vlr_name = NULL;
int rc;
switch (vlr->type) {
case OSMO_GSUP_PEER_ID_IPA_NAME:
case OSMO_CNI_PEER_ID_IPA_NAME:
if (vlr->ipa_name.len < 2 || vlr->ipa_name.val[vlr->ipa_name.len - 1] != '\0') {
LOGP(DDB, LOGL_ERROR, "Expecting VLR ipa_name to be zero terminated; found %s\n",
osmo_ipa_name_to_str(&vlr->ipa_name));
@@ -978,8 +1046,8 @@ int _db_ind(struct db_context *dbc, const struct osmo_gsup_peer_id *vlr,
vlr_name = (const char*)vlr->ipa_name.val;
break;
default:
LOGP(DDB, LOGL_ERROR, "Unsupported osmo_gsup_peer_id type: %s\n",
osmo_gsup_peer_id_type_name(vlr->type));
LOGP(DDB, LOGL_ERROR, "Unsupported osmo_cni_peer_id type: %s\n",
osmo_cni_peer_id_type_name(vlr->type));
return -ENOTSUP;
}
@@ -1001,128 +1069,12 @@ int _db_ind(struct db_context *dbc, const struct osmo_gsup_peer_id *vlr,
return _db_ind_get(dbc, vlr_name, ind);
}
int db_ind(struct db_context *dbc, const struct osmo_gsup_peer_id *vlr, unsigned int *ind)
int db_ind(struct db_context *dbc, const struct osmo_cni_peer_id *vlr, unsigned int *ind)
{
return _db_ind(dbc, vlr, ind, false);
}
int db_ind_del(struct db_context *dbc, const struct osmo_gsup_peer_id *vlr)
int db_ind_del(struct db_context *dbc, const struct osmo_cni_peer_id *vlr)
{
return _db_ind(dbc, vlr, NULL, true);
}
int db_subscr_set_rat_type_flag(struct db_context *dbc, int64_t subscr_id, enum osmo_rat_type rat, bool allowed)
{
int rc;
int ret = 0;
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_UPD_RAT_FLAG];
if (!db_bind_int64(stmt, "$subscriber_id", subscr_id))
return -EIO;
OSMO_ASSERT(rat >= 0 && rat < OSMO_RAT_COUNT);
if (!db_bind_text(stmt, "$rat", osmo_rat_type_name(rat)))
return -EIO;
if (!db_bind_int(stmt, "$allowed", allowed ? 1 : 0))
return -EIO;
/* execute the statement */
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) {
LOGP(DDB, LOGL_ERROR, "%s %s: SQL error: %s\n",
allowed ? "enable" : "disable", osmo_rat_type_name(rat),
sqlite3_errmsg(dbc->db));
ret = -EIO;
goto out;
}
/* verify execution result */
rc = sqlite3_changes(dbc->db);
if (!rc) {
LOGP(DDB, LOGL_ERROR, "Cannot %s %s: no such subscriber: ID=%" PRIu64 "\n",
allowed ? "enable" : "disable", osmo_rat_type_name(rat),
subscr_id);
ret = -ENOENT;
goto out;
} else if (rc != 1) {
LOGP(DDB, LOGL_ERROR, "%s %s: SQL modified %d rows (expected 1)\n",
allowed ? "enable" : "disable", osmo_rat_type_name(rat),
rc);
ret = -EIO;
}
out:
db_remove_reset(stmt);
return ret;
}
int db_subscr_get_rat_types(struct db_context *dbc, struct hlr_subscriber *subscr)
{
int rc;
int ret = 0;
int i;
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_RAT_BY_ID];
if (!db_bind_int64(stmt, "$subscriber_id", subscr->id))
return -EIO;
for (i = 0; i < OSMO_RAT_COUNT; i++)
subscr->rat_types[i] = true;
/* execute the statement */
while (1) {
enum osmo_rat_type rat;
bool allowed;
rc = sqlite3_step(stmt);
if (rc == SQLITE_DONE)
break;
if (rc != SQLITE_ROW)
return -rc;
rc = get_string_value(osmo_rat_type_names, (const char*)sqlite3_column_text(stmt, 0));
if (rc == -EINVAL) {
ret = -EINVAL;
goto out;
}
if (rc <= 0 || rc >= OSMO_RAT_COUNT) {
ret = -EINVAL;
goto out;
}
rat = rc;
allowed = sqlite3_column_int(stmt, 1);
subscr->rat_types[rat] = allowed;
LOGP(DAUC, LOGL_DEBUG, "db: imsi='%s' %s %s\n",
subscr->imsi, osmo_rat_type_name(rat), allowed ? "allowed" : "forbidden");
}
out:
db_remove_reset(stmt);
return ret;
}
int hlr_subscr_rat_flag(struct hlr *hlr, struct hlr_subscriber *subscr, enum osmo_rat_type rat, bool allowed)
{
int rc;
OSMO_ASSERT(rat >= 0 && rat < OSMO_RAT_COUNT);
db_subscr_get_rat_types(hlr->dbc, subscr);
if (subscr->rat_types[rat] == allowed) {
LOGHLR(subscr->imsi, LOGL_DEBUG, "Already has the requested value when asked to %s %s\n",
allowed ? "enable" : "disable", osmo_rat_type_name(rat));
return -ENOEXEC;
}
rc = db_subscr_set_rat_type_flag(hlr->dbc, subscr->id, rat, allowed);
if (rc)
return rc > 0? -rc : rc;
/* FIXME: If we're disabling, send message to VLR to detach subscriber */
return 0;
}

View File

@@ -18,10 +18,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: dbd_helper.c,v 1.44 2011/08/09 11:14:14 mhoenicka Exp $
*/

View File

@@ -22,7 +22,7 @@
#include <osmocom/mslookup/mslookup_client.h>
#include <osmocom/mslookup/mslookup_client_mdns.h>
#include <osmocom/gsupclient/gsup_client.h>
#include <osmocom/gsupclient/gsup_peer_id.h>
#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/hlr/logging.h>
#include <osmocom/hlr/hlr.h>
#include <osmocom/hlr/db.h>
@@ -170,7 +170,7 @@ void dgsm_init(void *ctx)
g_hlr->mslookup.server.local_attach_max_age = 60 * 60;
g_hlr->mslookup.client.result_timeout_milliseconds = 2000;
g_hlr->mslookup.client.result_timeout_milliseconds = OSMO_DGSM_DEFAULT_RESULT_TIMEOUT_MS;
g_hlr->gsup_unit_name.unit_name = "HLR";
g_hlr->gsup_unit_name.serno = "unnamed-HLR";
@@ -191,7 +191,7 @@ void dgsm_start(void *ctx)
dgsm_mdns_client_config_apply();
}
void dgsm_stop()
void dgsm_stop(void)
{
g_hlr->mslookup.allow_startup = false;
mslookup_server_mdns_config_apply();

View File

@@ -24,7 +24,7 @@
#include <osmocom/hlr/hlr_vty.h>
#include <osmocom/hlr/mslookup_server.h>
#include <osmocom/hlr/mslookup_server_mdns.h>
#include <osmocom/gsupclient/gsup_peer_id.h>
#include <osmocom/gsupclient/cni_peer_id.h>
struct cmd_node mslookup_node = {
MSLOOKUP_NODE,
@@ -119,7 +119,7 @@ DEFUN(cfg_mslookup_mdns_domain_suffix,
DEFUN(cfg_mslookup_no_mdns,
cfg_mslookup_no_mdns_cmd,
"no mdns",
"no mdns bind",
NO_STR "Disable both server and client for mDNS mslookup\n")
{
g_hlr->mslookup.server.mdns.enable = false;
@@ -178,9 +178,9 @@ DEFUN(cfg_mslookup_server_mdns_domain_suffix,
return CMD_SUCCESS;
}
DEFUN(cfg_mslookup_server_no_mdns,
cfg_mslookup_server_no_mdns_cmd,
"no mdns",
DEFUN(cfg_mslookup_server_no_mdns_bind,
cfg_mslookup_server_no_mdns_bind_cmd,
"no mdns bind",
NO_STR "Disable server for mDNS mslookup (do not answer remote requests)\n")
{
g_hlr->mslookup.server.mdns.enable = false;
@@ -196,8 +196,9 @@ struct cmd_node mslookup_server_msc_node = {
DEFUN(cfg_mslookup_server_msc,
cfg_mslookup_server_msc_cmd,
"msc .UNIT_NAME",
"msc ipa-name .IPA_NAME",
"Configure services for individual local MSCs\n"
"Identify locally connected MSC by IPA Unit Name\n"
"IPA Unit Name of the local MSC to configure\n")
{
struct osmo_ipa_name msc_name;
@@ -365,8 +366,8 @@ DEFUN(cfg_mslookup_client_timeout,
vty_out(vty, "%% 'exit' this node to apply changes%s", VTY_NEWLINE)
DEFUN(cfg_mslookup_client_mdns,
cfg_mslookup_client_mdns_cmd,
DEFUN(cfg_mslookup_client_mdns_bind,
cfg_mslookup_client_mdns_bind_cmd,
"mdns bind [IP] [<1-65535>]",
MDNS_STR
"Enable mDNS client, and configure multicast address to send mDNS mslookup requests to\n"
@@ -387,9 +388,9 @@ DEFUN(cfg_mslookup_client_mdns_domain_suffix,
return CMD_SUCCESS;
}
DEFUN(cfg_mslookup_client_no_mdns,
cfg_mslookup_client_no_mdns_cmd,
"no mdns",
DEFUN(cfg_mslookup_client_no_mdns_bind,
cfg_mslookup_client_no_mdns_bind_cmd,
"no mdns bind",
NO_STR "Disable mDNS client, do not query remote services by mDNS\n")
{
g_hlr->mslookup.client.mdns.enable = false;
@@ -441,13 +442,13 @@ int config_write_mslookup(struct vty *vty)
msc = mslookup_server_msc_get(&mslookup_server_msc_wildcard, false);
if (msc)
config_write_msc_services(vty, " ", msc);
config_write_msc_services(vty, " ", msc);
llist_for_each_entry(msc, &g_hlr->mslookup.server.local_site_services, entry) {
if (!osmo_ipa_name_cmp(&mslookup_server_msc_wildcard, &msc->name))
continue;
vty_out(vty, " msc %s%s", osmo_ipa_name_to_str(&msc->name), VTY_NEWLINE);
config_write_msc_services(vty, " ", msc);
vty_out(vty, " msc ipa-name %s%s", osmo_ipa_name_to_str(&msc->name), VTY_NEWLINE);
config_write_msc_services(vty, " ", msc);
}
/* If the server is disabled, still output the above to not lose the service config. */
@@ -466,7 +467,7 @@ int config_write_mslookup(struct vty *vty)
if (g_hlr->mslookup.client.mdns.enable
&& osmo_sockaddr_str_is_nonzero(&g_hlr->mslookup.client.mdns.query_addr))
vty_out(vty, " mdns to %s %u%s",
vty_out(vty, " mdns bind %s %u%s",
g_hlr->mslookup.client.mdns.query_addr.ip,
g_hlr->mslookup.client.mdns.query_addr.port,
VTY_NEWLINE);
@@ -474,6 +475,10 @@ int config_write_mslookup(struct vty *vty)
vty_out(vty, " mdns domain-suffix %s%s",
g_hlr->mslookup.client.mdns.domain_suffix,
VTY_NEWLINE);
if (g_hlr->mslookup.client.result_timeout_milliseconds != OSMO_DGSM_DEFAULT_RESULT_TIMEOUT_MS)
vty_out(vty, " timeout %u%s",
g_hlr->mslookup.client.result_timeout_milliseconds,
VTY_NEWLINE);
}
return CMD_SUCCESS;
@@ -534,7 +539,7 @@ DEFUN(do_mslookup_show_services,
llist_for_each_entry(msc, &g_hlr->mslookup.server.local_site_services, entry) {
if (!osmo_ipa_name_cmp(&mslookup_server_msc_wildcard, &msc->name))
continue;
vty_out(vty, "msc %s%s", osmo_ipa_name_to_str(&msc->name), VTY_NEWLINE);
vty_out(vty, "msc ipa-name %s%s", osmo_ipa_name_to_str(&msc->name), VTY_NEWLINE);
config_write_msc_services(vty, " ", msc);
}
return CMD_SUCCESS;
@@ -554,7 +559,7 @@ void dgsm_vty_init(void)
install_node(&mslookup_server_node, NULL);
install_element(MSLOOKUP_SERVER_NODE, &cfg_mslookup_server_mdns_bind_cmd);
install_element(MSLOOKUP_SERVER_NODE, &cfg_mslookup_server_mdns_domain_suffix_cmd);
install_element(MSLOOKUP_SERVER_NODE, &cfg_mslookup_server_no_mdns_cmd);
install_element(MSLOOKUP_SERVER_NODE, &cfg_mslookup_server_no_mdns_bind_cmd);
install_element(MSLOOKUP_SERVER_NODE, &cfg_mslookup_server_msc_service_cmd);
install_element(MSLOOKUP_SERVER_NODE, &cfg_mslookup_server_msc_no_service_cmd);
install_element(MSLOOKUP_SERVER_NODE, &cfg_mslookup_server_msc_no_service_addr_cmd);
@@ -569,9 +574,9 @@ void dgsm_vty_init(void)
install_element(MSLOOKUP_NODE, &cfg_mslookup_no_client_cmd);
install_node(&mslookup_client_node, NULL);
install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_timeout_cmd);
install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_mdns_cmd);
install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_mdns_bind_cmd);
install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_mdns_domain_suffix_cmd);
install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_no_mdns_cmd);
install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_no_mdns_bind_cmd);
install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_gateway_proxy_cmd);
install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_no_gateway_proxy_cmd);

View File

@@ -18,6 +18,8 @@
*/
#include <errno.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/logging.h>
@@ -65,13 +67,13 @@ int osmo_gsup_conn_send(struct osmo_gsup_conn *conn, struct msgb *msg)
static void gsup_server_send_req_response(struct osmo_gsup_req *req, struct osmo_gsup_message *response)
{
struct osmo_gsup_server *server = req->cb_data;
struct osmo_gsup_peer_id *routing;
struct osmo_cni_peer_id *routing;
struct osmo_gsup_conn *conn = NULL;
struct msgb *msg = osmo_gsup_msgb_alloc("GSUP Tx");
int rc;
if (response->message_type == OSMO_GSUP_MSGT_ROUTING_ERROR
&& !osmo_gsup_peer_id_is_empty(&req->via_proxy)) {
&& !osmo_cni_peer_id_is_empty(&req->via_proxy)) {
/* If a routing error occured, we need to route back via the immediate sending peer, not via the
* intended final recipient -- because one source of routing errors is a duplicate name for a recipient.
* If we resolve to req->source_name, we may send to a completely unrelated recipient. */
@@ -80,12 +82,12 @@ static void gsup_server_send_req_response(struct osmo_gsup_req *req, struct osmo
routing = &req->source_name;
}
switch (routing->type) {
case OSMO_GSUP_PEER_ID_IPA_NAME:
case OSMO_CNI_PEER_ID_IPA_NAME:
conn = gsup_route_find_by_ipa_name(server, &routing->ipa_name);
break;
default:
LOG_GSUP_REQ(req, LOGL_ERROR, "GSUP peer id kind not supported: %s\n",
osmo_gsup_peer_id_type_name(routing->type));
osmo_cni_peer_id_type_name(routing->type));
break;
}
@@ -111,22 +113,22 @@ static void gsup_server_send_req_response(struct osmo_gsup_req *req, struct osmo
struct osmo_gsup_req *osmo_gsup_conn_rx(struct osmo_gsup_conn *conn, struct msgb *msg)
{
struct osmo_gsup_req *req;
struct osmo_gsup_peer_id gpi = {
.type = OSMO_GSUP_PEER_ID_IPA_NAME,
struct osmo_cni_peer_id cpi = {
.type = OSMO_CNI_PEER_ID_IPA_NAME,
.ipa_name = conn->peer_name,
};
req = osmo_gsup_req_new(conn->server, &gpi, msg, gsup_server_send_req_response, conn->server, NULL);
req = osmo_gsup_req_new(conn->server, &cpi, msg, gsup_server_send_req_response, conn->server, NULL);
if (!req)
return NULL;
if (!osmo_gsup_peer_id_is_empty(&req->via_proxy)) {
if (!osmo_cni_peer_id_is_empty(&req->via_proxy)) {
switch (req->via_proxy.type) {
case OSMO_GSUP_PEER_ID_IPA_NAME:
case OSMO_CNI_PEER_ID_IPA_NAME:
break;
default:
LOG_GSUP_REQ(req, LOGL_ERROR, "GSUP peer id kind not supported: %s\n",
osmo_gsup_peer_id_type_name(req->source_name.type));
osmo_cni_peer_id_type_name(req->source_name.type));
osmo_gsup_req_respond_msgt(req, OSMO_GSUP_MSGT_ROUTING_ERROR, true);
return NULL;
}
@@ -137,7 +139,7 @@ struct osmo_gsup_req *osmo_gsup_conn_rx(struct osmo_gsup_conn *conn, struct msgb
LOG_GSUP_REQ(req, LOGL_ERROR,
"GSUP message received from %s via peer %s, but there already exists a"
" different route to this source, message is not routable\n",
osmo_gsup_peer_id_to_str(&req->source_name),
osmo_cni_peer_id_to_str(&req->source_name),
osmo_ipa_name_to_str(&conn->peer_name));
osmo_gsup_req_respond_msgt(req, OSMO_GSUP_MSGT_ROUTING_ERROR, true);
return NULL;
@@ -274,7 +276,7 @@ static int osmo_gsup_server_ccm_cb(struct ipa_server_conn *conn,
{
struct osmo_gsup_conn *clnt = (struct osmo_gsup_conn *)conn->data;
uint8_t *addr = NULL;
size_t addr_len;
int addr_len;
LOGP(DLGSUP, LOGL_INFO, "CCM Callback\n");
@@ -315,41 +317,17 @@ static int osmo_gsup_server_closed_cb(struct ipa_server_conn *conn)
return 0;
}
/* Add conn to the clients list in a way that conn->auc_3g_ind takes the lowest
* unused integer and the list of clients remains sorted by auc_3g_ind.
* Keep this function non-static to allow linking in a unit test. */
void osmo_gsup_server_add_conn(struct llist_head *clients,
struct osmo_gsup_conn *conn)
static void update_fd_settings(int fd)
{
struct osmo_gsup_conn *c;
struct osmo_gsup_conn *prev_conn;
int ret;
int val;
c = llist_first_entry_or_null(clients, struct osmo_gsup_conn, list);
/*TODO: Set keepalive settings here. See OS#4312 */
/* Is the first index, 0, unused? */
if (!c || c->auc_3g_ind > 0) {
conn->auc_3g_ind = 0;
llist_add(&conn->list, clients);
return;
}
/* Look for a gap later on */
prev_conn = NULL;
llist_for_each_entry(c, clients, list) {
/* skip first item, we know it has auc_3g_ind == 0. */
if (!prev_conn) {
prev_conn = c;
continue;
}
if (c->auc_3g_ind > prev_conn->auc_3g_ind + 1)
break;
prev_conn = c;
}
OSMO_ASSERT(prev_conn);
conn->auc_3g_ind = prev_conn->auc_3g_ind + 1;
llist_add(&conn->list, &prev_conn->list);
val = 1;
ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
if (ret < 0)
LOGP(DLGSUP, LOGL_ERROR, "Failed to set TCP_NODELAY: %s\n", strerror(errno));
}
/* a client has connected to the server socket and we have accept()ed it */
@@ -371,10 +349,11 @@ static int osmo_gsup_server_accept_cb(struct ipa_server_link *link, int fd)
/* link data structure with server structure */
conn->server = gsups;
osmo_gsup_server_add_conn(&gsups->clients, conn);
llist_add_tail(&conn->list, &gsups->clients);
LOGP(DLGSUP, LOGL_INFO, "New GSUP client %s:%d (IND=%u)\n",
conn->conn->addr, conn->conn->port, conn->auc_3g_ind);
LOGP(DLGSUP, LOGL_INFO, "New GSUP client %s:%d\n", conn->conn->addr, conn->conn->port);
update_fd_settings(fd);
/* request the identity of the client */
rc = ipa_ccm_send_id_req(fd);
@@ -459,10 +438,9 @@ int osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup,
return 0;
}
/**
* Populate a gsup message structure with an Insert Subscriber Data Message.
* All required memory buffers for data pointed to by pointers in struct omso_gsup_message
* All required memory buffers for data pointed to by pointers in struct osmo_gsup_message
* must be allocated by the caller and should have the same lifetime as the gsup parameter.
*
* \param[out] gsup The gsup message to populate.
@@ -476,46 +454,46 @@ int osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup,
* \returns 0 on success, and negative on error.
*/
int osmo_gsup_create_insert_subscriber_data_msg(struct osmo_gsup_message *gsup, const char *imsi, const char *msisdn,
uint8_t *msisdn_enc, size_t msisdn_enc_size,
uint8_t *apn_buf, size_t apn_buf_size,
enum osmo_gsup_cn_domain cn_domain)
uint8_t *msisdn_enc, size_t msisdn_enc_size,
uint8_t *apn_buf, size_t apn_buf_size,
enum osmo_gsup_cn_domain cn_domain)
{
int len;
int len;
OSMO_ASSERT(gsup);
*gsup = (struct osmo_gsup_message){
.message_type = OSMO_GSUP_MSGT_INSERT_DATA_REQUEST,
};
OSMO_ASSERT(gsup);
*gsup = (struct osmo_gsup_message){
.message_type = OSMO_GSUP_MSGT_INSERT_DATA_REQUEST,
};
osmo_strlcpy(gsup->imsi, imsi, sizeof(gsup->imsi));
osmo_strlcpy(gsup->imsi, imsi, sizeof(gsup->imsi));
if (msisdn_enc_size < OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN)
return -ENOSPC;
if (msisdn_enc_size < OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN)
return -ENOSPC;
OSMO_ASSERT(msisdn_enc);
len = gsm48_encode_bcd_number(msisdn_enc, msisdn_enc_size, 0, msisdn);
if (len < 1) {
LOGP(DLGSUP, LOGL_ERROR, "%s: Error: cannot encode MSISDN '%s'\n", imsi, msisdn);
return -ENOSPC;
}
gsup->msisdn_enc = msisdn_enc;
gsup->msisdn_enc_len = len;
OSMO_ASSERT(msisdn_enc);
len = gsm48_encode_bcd_number(msisdn_enc, msisdn_enc_size, 0, msisdn);
if (len < 1) {
LOGP(DLGSUP, LOGL_ERROR, "%s: Error: cannot encode MSISDN '%s'\n", imsi, msisdn);
return -ENOSPC;
}
gsup->msisdn_enc = msisdn_enc;
gsup->msisdn_enc_len = len;
#pragma message "FIXME: deal with encoding the following data: gsup.hlr_enc"
#pragma message "FIXME: deal with encoding the following data: gsup.hlr_enc"
gsup->cn_domain = cn_domain;
if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS) {
OSMO_ASSERT(apn_buf_size >= APN_MAXLEN);
OSMO_ASSERT(apn_buf);
/* FIXME: PDP infos - use more fine-grained access control
instead of wildcard APN */
osmo_gsup_configure_wildcard_apn(gsup, apn_buf, apn_buf_size);
}
gsup->cn_domain = cn_domain;
if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS) {
OSMO_ASSERT(apn_buf_size >= APN_MAXLEN);
OSMO_ASSERT(apn_buf);
/* FIXME: PDP infos - use more fine-grained access control
instead of wildcard APN */
osmo_gsup_configure_wildcard_apn(gsup, apn_buf, apn_buf_size);
}
return 0;
return 0;
}
int osmo_gsup_forward_to_local_peer(struct osmo_gsup_server *server, const struct osmo_gsup_peer_id *to_peer,
int osmo_gsup_forward_to_local_peer(struct osmo_gsup_server *server, const struct osmo_cni_peer_id *to_peer,
struct osmo_gsup_req *req, struct osmo_gsup_message *modified_gsup)
{
int rc;
@@ -524,22 +502,22 @@ int osmo_gsup_forward_to_local_peer(struct osmo_gsup_server *server, const struc
* is required to return this as gsup->destination_name so that the reply gets routed to the original sender. */
struct osmo_gsup_message forward = *(modified_gsup? : &req->gsup);
if (req->source_name.type != OSMO_GSUP_PEER_ID_IPA_NAME) {
if (req->source_name.type != OSMO_CNI_PEER_ID_IPA_NAME) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_NET_FAIL, "Unsupported GSUP peer id type: %s",
osmo_gsup_peer_id_type_name(req->source_name.type));
osmo_cni_peer_id_type_name(req->source_name.type));
rc = -ENOTSUP;
goto routing_error;
}
forward.source_name = req->source_name.ipa_name.val;
forward.source_name_len = req->source_name.ipa_name.len;
if (to_peer->type != OSMO_GSUP_PEER_ID_IPA_NAME) {
if (to_peer->type != OSMO_CNI_PEER_ID_IPA_NAME) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_NET_FAIL, "Unsupported GSUP peer id type: %s",
osmo_gsup_peer_id_type_name(to_peer->type));
osmo_cni_peer_id_type_name(to_peer->type));
rc = -ENOTSUP;
goto routing_error;
}
LOG_GSUP_REQ(req, LOGL_INFO, "Forwarding to %s\n", osmo_gsup_peer_id_to_str(to_peer));
LOG_GSUP_REQ(req, LOGL_INFO, "Forwarding to %s\n", osmo_cni_peer_id_to_str(to_peer));
rc = osmo_gsup_enc_send_to_ipa_name(server, &to_peer->ipa_name, &forward);
if (rc)
goto routing_error;

View File

@@ -1,7 +1,7 @@
# This is _NOT_ the library release version, it's an API version.
# Please read chapter "Library interface versions" of the libtool documentation
# before making any modifications: https://www.gnu.org/software/libtool/manual/html_node/Versioning.html
LIBVERSION=0:0:0
LIBVERSION=1:0:1
AM_CFLAGS = -Wall $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)/include \
$(TALLOC_CFLAGS) $(LIBOSMOCORE_CFLAGS) $(LIBOSMOABIS_CFLAGS)
@@ -9,7 +9,7 @@ AM_CFLAGS = -Wall $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)/incl
lib_LTLIBRARIES = libosmo-gsup-client.la
libosmo_gsup_client_la_SOURCES = \
gsup_peer_id.c \
cni_peer_id.c \
gsup_client.c \
gsup_req.c \
$(NULL)

View File

@@ -19,9 +19,9 @@
#include <errno.h>
#include <string.h>
#include <osmocom/core/utils.h>
#include <osmocom/gsupclient/gsup_peer_id.h>
#include <osmocom/gsupclient/cni_peer_id.h>
bool osmo_ipa_name_is_empty(struct osmo_ipa_name *ipa_name)
bool osmo_ipa_name_is_empty(const struct osmo_ipa_name *ipa_name)
{
return (!ipa_name) || (!ipa_name->len);
}
@@ -90,55 +90,61 @@ int osmo_ipa_name_cmp(const struct osmo_ipa_name *a, const struct osmo_ipa_name
}
}
/* Return an unquoted string, not including the terminating zero. Used for writing VTY config. */
/* Call osmo_ipa_name_to_str_c with OTC_SELECT. */
const char *osmo_ipa_name_to_str(const struct osmo_ipa_name *ipa_name)
{
return osmo_ipa_name_to_str_c(OTC_SELECT, ipa_name);
}
/* Return an unquoted string, not including the terminating zero. Used for writing VTY config. */
const char *osmo_ipa_name_to_str_c(void *ctx, const struct osmo_ipa_name *ipa_name)
{
size_t len = ipa_name->len;
if (!len)
return "";
return talloc_strdup(ctx, "");
if (ipa_name->val[len-1] == '\0')
len--;
return osmo_escape_str_c(OTC_SELECT, (char*)ipa_name->val, len);
return osmo_escape_str_c(ctx, (char*)ipa_name->val, len);
}
bool osmo_gsup_peer_id_is_empty(struct osmo_gsup_peer_id *gsup_peer_id)
bool osmo_cni_peer_id_is_empty(const struct osmo_cni_peer_id *cni_peer_id)
{
if (!gsup_peer_id)
if (!cni_peer_id)
return true;
switch (gsup_peer_id->type) {
case OSMO_GSUP_PEER_ID_EMPTY:
switch (cni_peer_id->type) {
case OSMO_CNI_PEER_ID_EMPTY:
return true;
case OSMO_GSUP_PEER_ID_IPA_NAME:
return osmo_ipa_name_is_empty(&gsup_peer_id->ipa_name);
case OSMO_CNI_PEER_ID_IPA_NAME:
return osmo_ipa_name_is_empty(&cni_peer_id->ipa_name);
default:
return false;
}
}
int osmo_gsup_peer_id_set(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_gsup_peer_id_type type,
int osmo_cni_peer_id_set(struct osmo_cni_peer_id *cni_peer_id, enum osmo_cni_peer_id_type type,
const uint8_t *val, size_t len)
{
gsup_peer_id->type = type;
cni_peer_id->type = type;
switch (type) {
case OSMO_GSUP_PEER_ID_IPA_NAME:
return osmo_ipa_name_set(&gsup_peer_id->ipa_name, val, len);
case OSMO_CNI_PEER_ID_IPA_NAME:
return osmo_ipa_name_set(&cni_peer_id->ipa_name, val, len);
default:
return -EINVAL;
}
}
int osmo_gsup_peer_id_set_str(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_gsup_peer_id_type type,
int osmo_cni_peer_id_set_str(struct osmo_cni_peer_id *cni_peer_id, enum osmo_cni_peer_id_type type,
const char *str_fmt, ...)
{
va_list ap;
int rc;
*gsup_peer_id = (struct osmo_gsup_peer_id){};
*cni_peer_id = (struct osmo_cni_peer_id){};
switch (type) {
case OSMO_GSUP_PEER_ID_IPA_NAME:
gsup_peer_id->type = OSMO_GSUP_PEER_ID_IPA_NAME;
case OSMO_CNI_PEER_ID_IPA_NAME:
cni_peer_id->type = OSMO_CNI_PEER_ID_IPA_NAME;
va_start(ap, str_fmt);
rc = osmo_ipa_name_set_str_va(&gsup_peer_id->ipa_name, str_fmt, ap);
rc = osmo_ipa_name_set_str_va(&cni_peer_id->ipa_name, str_fmt, ap);
va_end(ap);
return rc;
default:
@@ -146,30 +152,42 @@ int osmo_gsup_peer_id_set_str(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_
}
}
int osmo_gsup_peer_id_cmp(const struct osmo_gsup_peer_id *a, const struct osmo_gsup_peer_id *b)
int osmo_cni_peer_id_cmp(const struct osmo_cni_peer_id *a, const struct osmo_cni_peer_id *b)
{
if (a == b)
return 0;
if (!a)
return -1;
if (!b)
return 1;
if (a->type != b->type)
return OSMO_CMP(a->type, b->type);
switch (a->type) {
case OSMO_GSUP_PEER_ID_IPA_NAME:
case OSMO_CNI_PEER_ID_IPA_NAME:
return osmo_ipa_name_cmp(&a->ipa_name, &b->ipa_name);
default:
return -EINVAL;
}
}
const struct value_string osmo_gsup_peer_id_type_names[] = {
{ OSMO_GSUP_PEER_ID_IPA_NAME, "IPA-name" },
const struct value_string osmo_cni_peer_id_type_names[] = {
{ OSMO_CNI_PEER_ID_IPA_NAME, "IPA-name" },
{}
};
/* Return an unquoted string, not including the terminating zero. Used for writing VTY config. */
const char *osmo_gsup_peer_id_to_str(const struct osmo_gsup_peer_id *gpi)
/* Call osmo_cni_peer_id_to_str_c with OTC_SELECT */
const char *osmo_cni_peer_id_to_str(const struct osmo_cni_peer_id *cpi)
{
switch (gpi->type) {
case OSMO_GSUP_PEER_ID_IPA_NAME:
return osmo_ipa_name_to_str(&gpi->ipa_name);
return osmo_cni_peer_id_to_str_c(OTC_SELECT, cpi);
}
/* Return an unquoted string, not including the terminating zero. Used for writing VTY config. */
const char *osmo_cni_peer_id_to_str_c(void *ctx, const struct osmo_cni_peer_id *cpi)
{
switch (cpi->type) {
case OSMO_CNI_PEER_ID_IPA_NAME:
return osmo_ipa_name_to_str_c(ctx, &cpi->ipa_name);
default:
return osmo_gsup_peer_id_type_name(gpi->type);
return talloc_strdup(ctx, osmo_cni_peer_id_type_name(cpi->type));
}
}

View File

@@ -31,6 +31,8 @@
#include <errno.h>
#include <string.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
static void start_test_procedure(struct osmo_gsup_client *gsupc);
@@ -129,6 +131,19 @@ static void gsup_client_oap_register(struct osmo_gsup_client *gsupc)
client_send(gsupc, IPAC_PROTO_EXT_OAP, msg_tx);
}
static void update_fd_settings(int fd)
{
int ret;
int val;
/*TODO: Set keepalive settings here. See OS#4312 */
val = 1;
ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
if (ret < 0)
LOGP(DLGSUP, LOGL_ERROR, "Failed to set TCP_NODELAY: %s\n", strerror(errno));
}
static void gsup_client_updown_cb(struct ipa_client_conn *link, int up)
{
struct osmo_gsup_client *gsupc = link->data;
@@ -139,6 +154,7 @@ static void gsup_client_updown_cb(struct ipa_client_conn *link, int up)
gsupc->is_connected = up;
if (up) {
update_fd_settings(link->ofd->fd);
start_test_procedure(gsupc);
if (gsupc->oap_state.state == OSMO_OAP_INITIALIZED)

View File

@@ -25,26 +25,81 @@
#include <osmocom/gsupclient/gsup_req.h>
/*! Create a new osmo_gsup_req record, decode GSUP and add to a provided list of requests.
*
* Rationales:
*
* - osmo_gsup_req makes it easy to handle GSUP requests asynchronously. Before this, a GSUP message struct would be
* valid only within a read callback function, and would not survive asynchronous handling, because the struct often
* points directly into the received msgb. An osmo_gsup_req takes ownership of the msgb and ensures that the data
* remains valid, so that it can easily be queued for later handling.
* - osmo_gsup_req unifies the composition of response messages to ensure that all IEs that identify it to belong to
* the initial request are preserved / derived, like the source_name, destination_name, session_id, etc (see
* osmo_gsup_make_response() for details).
* - Deallocation of an osmo_gsup_req is implicit upon sending a response. The idea is that msgb memory leaks are a
* recurring source of bugs. By enforcing a request-response relation with implicit deallocation, osmo_gsup_req aims
* to help avoid most such memory leaks implicitly.
*
* The typical GSUP message sequence is:
* -> rx request,
* <- tx response.
*
* With osmo_gsup_req we can easily expand to:
* -> rx request,
* ... wait asynchronously,
* <- tx response.
*
* Only few GSUP conversations go beyond a 1:1 request-response match. But some have a session (e.g. USSD) or more
* negotiation may happen before the initial request is completed (e.g. Update Location with interleaved Insert
* Subscriber Data), so osmo_gsup_req also allows passing non-final responses.
* The final_response flag allows for:
* -> rx request,
* ... wait async,
* <- tx intermediate message to same peer (final_response = false, req remains open),
* ... wait async,
* -> rx intermediate response,
* ... wait async,
* <- tx final response (final_response = true, req is deallocated).
*
* This function takes ownership of the msgb, which will, on success, be owned by the returned osmo_gsup_req instance
* until osmo_gsup_req_free(). If a decoding error occurs, send an error response immediately, and return NULL.
*
* When this function returns, the original sender is found in req->source_name. If this is not the immediate peer name,
* then req->via_proxy is set to the immediate peer, and it is the responsibility of the caller to add req->source_name
* to the GSUP routes that are serviced by req->via_proxy (usually not relevant for clients with a single GSUP conn).
* The original CNI entity that sent the message is found in req->source_name. If the message was passed on by an
* intermediate CNI peer, then req->via_proxy is set to the immediate peer, and it is the responsibility of the caller
* to add req->source_name to the GSUP routes that are serviced by req->via_proxy (usually not relevant for clients with
* a single GSUP conn).
* Examples:
*
* "msc" ---> here
* source_name = "msc"
* via_proxy = <empty>
*
* "msc" ---> "proxy-HLR" ---> here (e.g. home HLR)
* source_name = "msc"
* via_proxy = "proxy-HLR"
*
* "msc" ---> "proxy-HLR" ---> "home-HLR" ---> here (e.g. EUSE)
* source_name = "msc"
* via_proxy = "home-HLR"
*
* An osmo_gsup_req must be concluded (and deallocated) by calling one of the osmo_gsup_req_respond* functions.
*
* Note: osmo_gsup_req API makes use of OTC_SELECT to allocate volatile buffers for logging. Use of
* osmo_select_main_ctx() is mandatory when using osmo_gsup_req.
*
* \param[in] ctx Talloc context for allocation of the new request.
* \param[in] from_peer The IPA unit name of the immediate GSUP peer from which this msgb was received.
* \param[in] msg The GSUP message buffer.
* \param[in] msg The message buffer containing the received GSUP message, where msgb_l2() shall point to the GSUP
* message start. The caller no longer owns the msgb when it is passed to this function: on error, the
* msgb is freed immediately, and on success, the msgb is owned by the returned osmo_gsup_req.
* \param[in] send_response_cb User specific method to send a GSUP response message, invoked upon
* osmo_gsup_req_respond*() functions.
* osmo_gsup_req_respond*() functions. Typically this invokes encoding and transmitting the
* GSUP message over a network socket. See for example gsup_server_send_req_response().
* \param[inout] cb_data Context data to be used freely by the caller.
* \param[inout] add_to_list List to which to append this request, or NULL for no list.
* \return a newly allocated osmo_gsup_req, or NULL on error.
* \return a newly allocated osmo_gsup_req, or NULL on error. If NULL is returned, an error response has already been
* dispatched to the send_response_cb.
*/
struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_gsup_peer_id *from_peer, struct msgb *msg,
struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_cni_peer_id *from_peer, struct msgb *msg,
osmo_gsup_req_send_response_t send_response_cb, void *cb_data,
struct llist_head *add_to_list)
{
@@ -52,9 +107,15 @@ struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_gsup_peer_i
struct osmo_gsup_req *req;
int rc;
if (!from_peer) {
LOGP(DLGSUP, LOGL_ERROR, "Rx GSUP from NULL peer is not allowed\n");
msgb_free(msg);
return NULL;
}
if (!msgb_l2(msg) || !msgb_l2len(msg)) {
LOGP(DLGSUP, LOGL_ERROR, "Rx GSUP from %s: missing or empty L2 data\n",
osmo_gsup_peer_id_to_str(from_peer));
osmo_cni_peer_id_to_str(from_peer));
msgb_free(msg);
return NULL;
}
@@ -66,11 +127,10 @@ struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_gsup_peer_i
req->msg = msg;
req->send_response_cb = send_response_cb;
req->cb_data = cb_data;
if (from_peer)
req->source_name = *from_peer;
req->source_name = *from_peer;
rc = osmo_gsup_decode(msgb_l2(req->msg), msgb_l2len(req->msg), (struct osmo_gsup_message*)&req->gsup);
if (rc < 0) {
LOGP(DLGSUP, LOGL_ERROR, "Rx GSUP from %s: cannot decode (rc=%d)\n", osmo_gsup_peer_id_to_str(from_peer), rc);
LOGP(DLGSUP, LOGL_ERROR, "Rx GSUP from %s: cannot decode (rc=%d)\n", osmo_cni_peer_id_to_str(from_peer), rc);
osmo_gsup_req_free(req);
return NULL;
}
@@ -78,18 +138,18 @@ struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_gsup_peer_i
LOG_GSUP_REQ(req, LOGL_DEBUG, "new request: {%s}\n", osmo_gsup_message_to_str_c(OTC_SELECT, &req->gsup));
if (req->gsup.source_name_len) {
if (osmo_gsup_peer_id_set(&req->source_name, OSMO_GSUP_PEER_ID_IPA_NAME,
if (osmo_cni_peer_id_set(&req->source_name, OSMO_CNI_PEER_ID_IPA_NAME,
req->gsup.source_name, req->gsup.source_name_len)) {
LOGP(DLGSUP, LOGL_ERROR,
"Rx GSUP from %s: failed to decode source_name, message is not routable\n",
osmo_gsup_peer_id_to_str(from_peer));
osmo_cni_peer_id_to_str(from_peer));
osmo_gsup_req_respond_msgt(req, OSMO_GSUP_MSGT_ROUTING_ERROR, true);
return NULL;
}
/* The source of the GSUP message is not the immediate GSUP peer; the peer is our proxy for that source.
*/
if (osmo_gsup_peer_id_cmp(&req->source_name, from_peer))
if (osmo_cni_peer_id_cmp(&req->source_name, from_peer))
req->via_proxy = *from_peer;
}
@@ -104,6 +164,8 @@ struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_gsup_peer_i
return req;
}
/*! Free an osmo_gsup_req and its msgb -- this is usually implicit in osmo_gsup_req_resond_*(), it should not be
* necessary to call this directly. */
void osmo_gsup_req_free(struct osmo_gsup_req *req)
{
LOG_GSUP_REQ(req, LOGL_DEBUG, "free\n");
@@ -114,6 +176,25 @@ void osmo_gsup_req_free(struct osmo_gsup_req *req)
talloc_free(req);
}
/*! Send a response to a GSUP request.
*
* Ensure that the response message contains all GSUP IEs that identify it as a response for the request req, by calling
* osmo_gsup_make_response().
*
* The final complete response message is passed to req->send_response_cb() to take care of the transmission.
*
* \param req Request as previously initialized by osmo_gsup_req_new().
* \param response Buffer to compose the response, possibly with some pre-configured IEs.
* Any missing IEs are added via osmo_gsup_make_response().
* Must not be NULL. Does not need to remain valid memory beyond the function call,
* i.e. this can just be a local variable in the calling function.
* \param error True when the response message indicates an error response (error message type).
* \param final_response True when the request is concluded by this response, which deallocates the req.
* False when the request should remain open after this response.
* For most plain request->response GSUP messages, this should be True.
* \param file Source file for logging as in __FILE__, added by osmo_gsup_req_respond() macro.
* \param line Source line for logging as in __LINE__, added by osmo_gsup_req_respond() macro.
*/
int _osmo_gsup_req_respond(struct osmo_gsup_req *req, struct osmo_gsup_message *response,
bool error, bool final_response, const char *file, int line)
{
@@ -144,6 +225,18 @@ exit_cleanup:
return rc;
}
/*! Shorthand for _osmo_gsup_req_respond() with no additional IEs and a fixed message type.
* Set the message type in a local osmo_gsup_message and feed it to _osmo_gsup_req_respond().
* That will ensure to add all IEs that identify it as a response to req.
*
* \param req Request as previously initialized by osmo_gsup_req_new().
* \param message_type The GSUP message type discriminator to respond with.
* \param final_response True when the request is concluded by this response, which deallocates the req.
* False when the request should remain open after this response.
* For most plain request->response GSUP messages, this should be True.
* \param file Source file for logging as in __FILE__, added by osmo_gsup_req_respond_msgt() macro.
* \param line Source line for logging as in __LINE__, added by osmo_gsup_req_respond_msgt() macro.
*/
int _osmo_gsup_req_respond_msgt(struct osmo_gsup_req *req, enum osmo_gsup_message_type message_type,
bool final_response, const char *file, int line)
{
@@ -154,6 +247,17 @@ int _osmo_gsup_req_respond_msgt(struct osmo_gsup_req *req, enum osmo_gsup_messag
file, line);
}
/*! Shorthand for _osmo_gsup_req_respond() with an error cause IEs and using the req's matched error message type.
* Set the error cause in a local osmo_gsup_message and feed it to _osmo_gsup_req_respond().
* That will ensure to add all IEs that identify it as a response to req.
*
* Responding with an error always implies a final response: req is implicitly deallocated.
*
* \param req Request as previously initialized by osmo_gsup_req_new().
* \param cause The error cause to include in a OSMO_GSUP_CAUSE_IE.
* \param file Source file for logging as in __FILE__, added by osmo_gsup_req_respond_err() macro.
* \param line Source line for logging as in __LINE__, added by osmo_gsup_req_respond_err() macro.
*/
void _osmo_gsup_req_respond_err(struct osmo_gsup_req *req, enum gsm48_gmm_cause cause,
const char *file, int line)
{

View File

@@ -31,6 +31,7 @@
#include <osmocom/vty/command.h>
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/ports.h>
#include <osmocom/vty/cpu_sched_vty.h>
#include <osmocom/ctrl/control_vty.h>
#include <osmocom/gsm/apn.h>
#include <osmocom/gsm/gsm48_ie.h>
@@ -38,7 +39,7 @@
#include <osmocom/gsm/gsm23003.h>
#include <osmocom/mslookup/mslookup_client.h>
#include <osmocom/gsupclient/gsup_peer_id.h>
#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/hlr/db.h>
#include <osmocom/hlr/hlr.h>
#include <osmocom/hlr/ctrl.h>
@@ -51,7 +52,6 @@
#include <osmocom/hlr/dgsm.h>
#include <osmocom/hlr/proxy.h>
#include <osmocom/hlr/lu_fsm.h>
#include <osmocom/hlr/sms_over_gsup.h>
#include <osmocom/mslookup/mdns.h>
struct hlr *g_hlr;
@@ -269,9 +269,9 @@ int hlr_subscr_nam(struct hlr *hlr, struct hlr_subscriber *subscr, bool nam_val,
if (nam_val)
return 0;
if (subscr->vlr_number && osmo_ipa_name_set_str(&vlr_name, subscr->vlr_number))
if (subscr->vlr_number[0] && !osmo_ipa_name_set_str(&vlr_name, subscr->vlr_number))
osmo_gsup_enc_send_to_ipa_name(g_hlr->gs, &vlr_name, &gsup_del_data);
if (subscr->sgsn_number && osmo_ipa_name_set_str(&vlr_name, subscr->sgsn_number))
if (subscr->sgsn_number[0] && !osmo_ipa_name_set_str(&vlr_name, subscr->sgsn_number))
osmo_gsup_enc_send_to_ipa_name(g_hlr->gs, &vlr_name, &gsup_del_data);
return 0;
}
@@ -287,6 +287,7 @@ static int rx_send_auth_info(struct osmo_gsup_req *req)
.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT,
};
bool separation_bit = false;
int num_auth_vectors = OSMO_GSUP_MAX_NUM_AUTH_INFO;
unsigned int auc_3g_ind;
int rc;
@@ -295,18 +296,21 @@ static int rx_send_auth_info(struct osmo_gsup_req *req)
if (req->gsup.current_rat_type == OSMO_RAT_EUTRAN_SGS)
separation_bit = true;
if (req->gsup.num_auth_vectors > 0 &&
req->gsup.num_auth_vectors <= OSMO_GSUP_MAX_NUM_AUTH_INFO)
num_auth_vectors = req->gsup.num_auth_vectors;
rc = db_ind(g_hlr->dbc, &req->source_name, &auc_3g_ind);
if (rc) {
LOG_GSUP_REQ(req, LOGL_ERROR,
"Unable to determine 3G auth IND for source %s (rc=%d),"
" generating tuples with IND = 0\n",
osmo_gsup_peer_id_to_str(&req->source_name), rc);
osmo_cni_peer_id_to_str(&req->source_name), rc);
auc_3g_ind = 0;
}
rc = db_get_auc(g_hlr->dbc, req->gsup.imsi, auc_3g_ind,
gsup_out.auth_vectors,
ARRAY_SIZE(gsup_out.auth_vectors),
num_auth_vectors,
req->gsup.rand, req->gsup.auts, separation_bit);
if (rc <= 0) {
@@ -320,7 +324,7 @@ static int rx_send_auth_info(struct osmo_gsup_req *req)
" Returning slightly inaccurate cause 'IMSI Unknown' via GSUP");
return rc;
case -ENOENT:
osmo_gsup_req_respond_err(req, GMM_CAUSE_ROAMING_NOTALLOWED, "IMSI unknown");
osmo_gsup_req_respond_err(req, g_hlr->reject_cause, "IMSI unknown");
return rc;
default:
osmo_gsup_req_respond_err(req, GMM_CAUSE_NET_FAIL, "failure to look up IMSI in db");
@@ -372,7 +376,7 @@ static int rx_purge_ms_req(struct osmo_gsup_req *req)
if (rc == 0)
osmo_gsup_req_respond_msgt(req, OSMO_GSUP_MSGT_PURGE_MS_RESULT, true);
else if (rc == -ENOENT)
osmo_gsup_req_respond_err(req, GMM_CAUSE_ROAMING_NOTALLOWED, "IMSI unknown");
osmo_gsup_req_respond_err(req, GMM_CAUSE_IMSI_UNKNOWN, "IMSI unknown");
else
osmo_gsup_req_respond_err(req, GMM_CAUSE_NET_FAIL, "db error");
return rc;
@@ -454,8 +458,8 @@ static int read_cb_forward(struct osmo_gsup_req *req)
struct osmo_ipa_name destination_name;
/* Check for routing IEs */
if (!req->gsup.source_name[0] || !req->gsup.source_name_len
|| !req->gsup.destination_name[0] || !req->gsup.destination_name_len) {
if (!req->gsup.source_name || !req->gsup.source_name_len
|| !req->gsup.destination_name || !req->gsup.destination_name_len) {
LOGP_GSUP_FWD(&req->gsup, LOGL_ERROR, "missing routing IEs\n");
goto routing_error;
}
@@ -509,10 +513,6 @@ static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
}
}
/* SMS over GSUP */
if (sms_over_gsup_check_handle_msg(req))
return 0;
/* Distributed GSM: check whether to proxy for / lookup a remote HLR.
* It would require less database hits to do this only if a local-only operation fails with "unknown IMSI", but
* it becomes semantically easier if we do this once-off ahead of time. */
@@ -568,12 +568,12 @@ static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
return 0;
}
static void print_usage()
static void print_usage(void)
{
printf("Usage: osmo-hlr\n");
}
static void print_help()
static void print_help(void)
{
printf(" -h --help This text.\n");
printf(" -c --config-file filename The config file to use.\n");
@@ -586,6 +586,10 @@ static void print_help()
printf(" -U --db-upgrade Allow HLR database schema upgrades.\n");
printf(" -C --db-check Quit after opening (and upgrading) the database.\n");
printf(" -V --version Print the version of OsmoHLR.\n");
printf("\nVTY reference generation:\n");
printf(" --vty-ref-mode MODE VTY reference generation mode (e.g. 'expert').\n");
printf(" --vty-ref-xml Generate the VTY reference XML output and exit.\n");
}
static struct {
@@ -601,10 +605,37 @@ static struct {
.db_upgrade = false,
};
static void handle_long_options(const char *prog_name, const int long_option)
{
static int vty_ref_mode = VTY_REF_GEN_MODE_DEFAULT;
switch (long_option) {
case 1:
vty_ref_mode = get_string_value(vty_ref_gen_mode_names, optarg);
if (vty_ref_mode < 0) {
fprintf(stderr, "%s: Unknown VTY reference generation "
"mode '%s'\n", prog_name, optarg);
exit(2);
}
break;
case 2:
fprintf(stderr, "Generating the VTY reference in mode '%s' (%s)\n",
get_value_string(vty_ref_gen_mode_names, vty_ref_mode),
get_value_string(vty_ref_gen_mode_desc, vty_ref_mode));
vty_dump_xml_ref_mode(stdout, (enum vty_ref_gen_mode) vty_ref_mode);
exit(0);
default:
fprintf(stderr, "%s: error parsing cmdline options\n", prog_name);
exit(2);
}
}
static void handle_options(int argc, char **argv)
{
while (1) {
int option_index = 0, c;
static int long_option = 0;
static struct option long_options[] = {
{"help", 0, 0, 'h'},
{"config-file", 1, 0, 'c'},
@@ -617,6 +648,8 @@ static void handle_options(int argc, char **argv)
{"db-upgrade", 0, 0, 'U' },
{"db-check", 0, 0, 'C' },
{"version", 0, 0, 'V' },
{"vty-ref-mode", 1, &long_option, 1},
{"vty-ref-xml", 0, &long_option, 2},
{0, 0, 0, 0}
};
@@ -626,6 +659,9 @@ static void handle_options(int argc, char **argv)
break;
switch (c) {
case 0:
handle_long_options(argv[0], long_option);
break;
case 'h':
print_usage();
print_help();
@@ -717,19 +753,18 @@ int main(int argc, char **argv)
g_hlr = talloc_zero(hlr_ctx, struct hlr);
INIT_LLIST_HEAD(&g_hlr->euse_list);
INIT_LLIST_HEAD(&g_hlr->iuse_list);
INIT_LLIST_HEAD(&g_hlr->ss_sessions);
INIT_LLIST_HEAD(&g_hlr->ussd_routes);
INIT_LLIST_HEAD(&g_hlr->mslookup.server.local_site_services);
g_hlr->db_file_path = talloc_strdup(g_hlr, HLR_DEFAULT_DB_FILE_PATH);
g_hlr->mslookup.server.mdns.domain_suffix = talloc_strdup(g_hlr, OSMO_MDNS_DOMAIN_SUFFIX_DEFAULT);
g_hlr->mslookup.client.mdns.domain_suffix = talloc_strdup(g_hlr, OSMO_MDNS_DOMAIN_SUFFIX_DEFAULT);
g_hlr->reject_cause = GMM_CAUSE_IMSI_UNKNOWN;
g_hlr->no_proxy_reject_cause = GMM_CAUSE_IMSI_UNKNOWN;
/* Init default (call independent) SS session guard timeout value */
g_hlr->ncss_guard_timeout = NCSS_GUARD_TIMEOUT_DEFAULT;
g_hlr->sms_over_gsup.try_direct_delivery = true;
rc = osmo_init_logging2(hlr_ctx, &hlr_log_info);
if (rc < 0) {
fprintf(stderr, "Error initializing logging\n");
@@ -742,9 +777,10 @@ int main(int argc, char **argv)
osmo_stats_init(hlr_ctx);
vty_init(&vty_info);
ctrl_vty_init(hlr_ctx);
handle_options(argc, argv);
hlr_vty_init();
hlr_vty_init(hlr_ctx);
dgsm_vty_init();
osmo_cpu_sched_vty_init(hlr_ctx);
handle_options(argc, argv);
rc = vty_read_config_file(cmdline_opts.config_file, NULL);
if (rc < 0) {
@@ -782,8 +818,7 @@ int main(int argc, char **argv)
}
/* start telnet after reading config for vty_get_bind_addr() */
rc = telnet_init_dynif(hlr_ctx, NULL, vty_get_bind_addr(),
OSMO_VTY_PORT_HLR);
rc = telnet_init_default(hlr_ctx, NULL, OSMO_VTY_PORT_HLR);
if (rc < 0)
return rc;
@@ -796,7 +831,6 @@ int main(int argc, char **argv)
}
proxy_init(g_hlr->gs);
g_hlr->ctrl_bind_addr = ctrl_vty_get_bind_addr();
g_hlr->ctrl = hlr_controlif_setup(g_hlr);
dgsm_start(hlr_ctx);

View File

@@ -25,6 +25,7 @@
#include <getopt.h>
#include <inttypes.h>
#include <string.h>
#include <errno.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/application.h>
@@ -50,7 +51,7 @@ static struct {
.db_upgrade = false,
};
static void print_help()
static void print_help(void)
{
printf("\n");
printf("Usage: osmo-hlr-db-tool [-l <hlr.db>] [create|import-nitb-db <nitb.db>]\n");
@@ -70,8 +71,9 @@ static void print_help()
printf(" (All commands imply this if none exists yet.)\n");
printf("\n");
printf(" import-nitb-db <nitb.db> Add OsmoNITB db's subscribers to OsmoHLR db.\n");
printf(" Be aware that the import is lossy, only the\n");
printf(" IMSI, MSISDN, nam_cs/ps and 2G auth data are set.\n");
printf(" Be aware that the import is somewhat lossy, only the IMSI,\n");
printf(" MSISDN, IMEI, nam_cs/ps, 2G auth data and last seen LU are set.\n");
printf(" The most recently associated IMEI from the Equipment table is used.\n");
}
static void print_version(int print_copyright)
@@ -212,9 +214,15 @@ enum nitb_stmt {
static const char *nitb_stmt_sql[] = {
[NITB_SELECT_SUBSCR] =
"SELECT imsi, id, extension, authorized"
" FROM Subscriber"
" ORDER BY id",
"SELECT s.imsi, s.id, s.extension, s.authorized,"
" SUBSTR(e.imei,0,15), STRFTIME('%s', s.expire_lu)"
" FROM Subscriber s LEFT JOIN"
" (SELECT imei, subscriber_id, MAX(Equipment.updated) AS updated"
" FROM Equipment,EquipmentWatch"
" WHERE Equipment.id = EquipmentWatch.equipment_id"
" GROUP BY EquipmentWatch.subscriber_id) e"
" ON e.subscriber_id = s.id"
" ORDER by s.id",
[NITB_SELECT_AUTH_KEYS] =
"SELECT algorithm_id, a3a8_ki from authkeys"
" WHERE subscriber_id = $subscr_id",
@@ -222,8 +230,65 @@ static const char *nitb_stmt_sql[] = {
sqlite3_stmt *nitb_stmt[ARRAY_SIZE(nitb_stmt_sql)] = {};
enum hlr_db_stmt {
HLR_DB_STMT_SET_IMPLICIT_LU_BY_IMSI,
};
static const char *hlr_db_stmt_sql[] = {
[HLR_DB_STMT_SET_IMPLICIT_LU_BY_IMSI] =
"UPDATE subscriber SET last_lu_seen = datetime($last_lu, 'unixepoch') WHERE imsi = $imsi",
};
sqlite3_stmt *hlr_db_stmt[ARRAY_SIZE(hlr_db_stmt_sql)] = {};
size_t _dbd_decode_binary(const unsigned char *in, unsigned char *out);
/*! Set a subscriber's LU timestamp in the HLR database.
* In normal operations there is never any need to explicitly
* update the value of last_lu_seen, so this function can live here.
*
* \param[in,out] dbc database context.
* \param[in] imsi ASCII string of IMSI digits
* \param[in] imei ASCII string of identifier digits, or NULL to remove the IMEI.
* \returns 0 on success, -ENOENT when the given subscriber does not exist,
* -EIO on database errors.
*/
int db_subscr_update_lu_by_imsi(struct db_context *dbc, const char* imsi, const int last_lu)
{
int rc, ret = 0;
sqlite3_stmt *stmt = hlr_db_stmt[HLR_DB_STMT_SET_IMPLICIT_LU_BY_IMSI];
if (!db_bind_text(stmt, "$imsi", imsi))
return -EIO;
if (last_lu && !db_bind_int(stmt, "$last_lu", last_lu))
return -EIO;
/* execute the statement */
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) {
LOGP(DAUC, LOGL_ERROR, "Update last_lu_seen for subscriber IMSI='%s': SQL Error: %s\n", imsi,
sqlite3_errmsg(dbc->db));
ret = -EIO;
goto out;
}
/* verify execution result */
rc = sqlite3_changes(dbc->db);
if (!rc) {
LOGP(DAUC, LOGL_ERROR, "Cannot update last_lu_seen for subscriber IMSI='%s': no such subscriber\n", imsi);
ret = -ENOENT;
} else if (rc != 1) {
LOGP(DAUC, LOGL_ERROR, "Update last_lu_seen for subscriber IMSI='%s': SQL modified %d rows (expected 1)\n",
imsi, rc);
ret = -EIO;
}
out:
db_remove_reset(stmt);
return ret;
}
void import_nitb_subscr_aud(sqlite3 *nitb_db, const char *imsi, int64_t nitb_id, int64_t hlr_id)
{
int rc;
@@ -297,6 +362,7 @@ void import_nitb_subscr(sqlite3 *nitb_db, sqlite3_stmt *stmt)
int64_t imsi;
char imsi_str[32];
bool authorized;
int last_lu_int;
imsi = sqlite3_column_int64(stmt, 0);
@@ -315,8 +381,18 @@ void import_nitb_subscr(sqlite3 *nitb_db, sqlite3_stmt *stmt)
nitb_id = sqlite3_column_int64(stmt, 1);
copy_sqlite3_text_to_buf(subscr.msisdn, stmt, 2);
authorized = sqlite3_column_int(stmt, 3) ? true : false;
copy_sqlite3_text_to_buf(subscr.imei, stmt, 4);
/* Default periodic LU was 30 mins and the expire_lu
* was twice that + 1 min
*/
last_lu_int = sqlite3_column_int(stmt, 5) - 3660;
db_subscr_update_msisdn_by_imsi(dbc, imsi_str, subscr.msisdn);
/* In case the subscriber was somehow never seen, invent an IMEI */
if (strlen(subscr.imei) == 14)
db_subscr_update_imei_by_imsi(dbc, imsi_str, subscr.imei);
db_subscr_update_lu_by_imsi(dbc, imsi_str, last_lu_int);
db_subscr_nam(dbc, imsi_str, authorized, true);
db_subscr_nam(dbc, imsi_str, authorized, false);
@@ -361,6 +437,17 @@ int import_nitb_db(void)
}
}
for (i = 0; i < ARRAY_SIZE(hlr_db_stmt_sql); i++) {
sql = hlr_db_stmt_sql[i];
rc = sqlite3_prepare_v2(g_hlr_db_tool_ctx->dbc->db, hlr_db_stmt_sql[i], -1,
&hlr_db_stmt[i], NULL);
if (rc != SQLITE_OK) {
LOGP(DDB, LOGL_ERROR, "OsmoHLR DB: Unable to prepare SQL statement '%s'\n", sql);
ret = -1;
goto out_free;
}
}
stmt = nitb_stmt[NITB_SELECT_SUBSCR];
while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
@@ -387,6 +474,7 @@ int main(int argc, char **argv)
{
int rc;
int (*main_action)(void);
int i;
main_action = NULL;
g_hlr_db_tool_ctx = talloc_zero(NULL, struct hlr_db_tool_ctx);
@@ -430,6 +518,11 @@ int main(int argc, char **argv)
if (main_action)
rc = (*main_action)();
/* db_close will only finalize statments in g_hlr_db_tool_ctx->dbc->stmt
* it is ok to call finalize on NULL */
for (i = 0; i < ARRAY_SIZE(hlr_db_stmt); i++) {
sqlite3_finalize(hlr_db_stmt[i]);
}
db_close(g_hlr_db_tool_ctx->dbc);
log_fini();
exit(rc ? EXIT_FAILURE : EXIT_SUCCESS);

View File

@@ -252,6 +252,7 @@ static int ss_gsup_send_to_ms(struct ss_session *ss, struct osmo_gsup_server *gs
rc = osmo_gsup_encode(msg, gsup);
if (rc) {
LOGPSS(ss, LOGL_ERROR, "Failed to encode GSUP message\n");
msgb_free(msg);
return rc;
}
@@ -278,20 +279,20 @@ static int ss_gsup_send_to_ms(struct ss_session *ss, struct osmo_gsup_server *gs
}
static int ss_tx_to_ms(struct ss_session *ss, enum osmo_gsup_message_type gsup_msg_type,
bool final, struct msgb *ss_msg)
struct msgb *ss_msg)
{
struct osmo_gsup_message resp = {
.message_type = gsup_msg_type,
.session_id = ss->session_id,
};
struct osmo_gsup_message resp;
int rc;
resp = (struct osmo_gsup_message) {
.message_type = gsup_msg_type,
.session_id = ss->session_id,
.session_state = ss->state,
};
OSMO_STRLCPY_ARRAY(resp.imsi, ss->imsi);
if (final)
resp.session_state = OSMO_GSUP_SESSION_STATE_END;
else
resp.session_state = OSMO_GSUP_SESSION_STATE_CONTINUE;
if (ss_msg) {
resp.ss_info = msgb_data(ss_msg);
resp.ss_info_len = msgb_length(ss_msg);
@@ -311,7 +312,8 @@ static int ss_tx_reject(struct ss_session *ss, int invoke_id, uint8_t problem_ta
LOGPSS(ss, LOGL_NOTICE, "Tx Reject(%u, 0x%02x, 0x%02x)\n", invoke_id,
problem_tag, problem_code);
OSMO_ASSERT(msg);
return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, true, msg);
ss->state = OSMO_GSUP_SESSION_STATE_END;
return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, msg);
}
#endif
@@ -320,15 +322,16 @@ static int ss_tx_to_ms_error(struct ss_session *ss, uint8_t invoke_id, uint8_t e
struct msgb *msg = gsm0480_gen_return_error(invoke_id, error_code);
LOGPSS(ss, LOGL_NOTICE, "Tx ReturnError(%u, 0x%02x)\n", invoke_id, error_code);
OSMO_ASSERT(msg);
return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, true, msg);
ss->state = OSMO_GSUP_SESSION_STATE_END;
return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, msg);
}
static int ss_tx_to_ms_ussd_7bit(struct ss_session *ss, bool final, uint8_t invoke_id, const char *text)
static int ss_tx_to_ms_ussd_7bit(struct ss_session *ss, uint8_t invoke_id, const char *text)
{
struct msgb *msg = gsm0480_gen_ussd_resp_7bit(invoke_id, text);
LOGPSS(ss, LOGL_INFO, "Tx USSD '%s'\n", text);
OSMO_ASSERT(msg);
return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, final, msg);
return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, msg);
}
/***********************************************************************
@@ -344,6 +347,8 @@ static int handle_ussd_own_msisdn(struct ss_session *ss,
char buf[GSM0480_USSD_7BIT_STRING_LEN+1];
int rc;
ss->state = OSMO_GSUP_SESSION_STATE_END;
rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &subscr);
switch (rc) {
case 0:
@@ -351,7 +356,7 @@ static int handle_ussd_own_msisdn(struct ss_session *ss,
snprintf(buf, sizeof(buf), "You have no MSISDN!");
else
snprintf(buf, sizeof(buf), "Your extension is %s", subscr.msisdn);
ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id, buf);
ss_tx_to_ms_ussd_7bit(ss, req->invoke_id, buf);
break;
case -ENOENT:
ss_tx_to_ms_error(ss, req->invoke_id, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER);
@@ -369,208 +374,22 @@ static int handle_ussd_own_imsi(struct ss_session *ss,
{
char buf[GSM0480_USSD_7BIT_STRING_LEN+1];
snprintf(buf, sizeof(buf), "Your IMSI is %s", ss->imsi);
ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id, buf);
ss->state = OSMO_GSUP_SESSION_STATE_END;
ss_tx_to_ms_ussd_7bit(ss, req->invoke_id, buf);
return 0;
}
static int handle_ussd_get_ran(struct ss_session *ss,
const struct osmo_gsup_message *gsup,
const struct ss_request *req)
/* This handler just keeps the session idle unless the guard timer expires. */
static int handle_ussd_test_idle(struct ss_session *ss,
const struct osmo_gsup_message *gsup,
const struct ss_request *req)
{
struct hlr_subscriber subscr;
char response[512];
int rc;
const char *rat;
rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &subscr);
switch (rc) {
case 0:
if (!*subscr.last_lu_rat_cs)
rat = "nothing, you don't exist";
else if (!strcmp(subscr.last_lu_rat_cs, "GERAN-A"))
rat = "2G";
else if (!strcmp(subscr.last_lu_rat_cs, "UTRAN-Iu"))
rat = "3G";
else if (!strcmp(subscr.last_lu_rat_cs, "EUTRAN-SGs"))
rat = "4G";
else
rat = subscr.last_lu_rat_cs;
snprintf(response, sizeof(response),
"Now on %s. Available:%s%s%s.",
rat,
subscr.rat_types[OSMO_RAT_GERAN_A]? " 2G" : "",
subscr.rat_types[OSMO_RAT_UTRAN_IU]? " 3G" : "",
subscr.rat_types[OSMO_RAT_EUTRAN_SGS]? " 4G" : "");
rc = ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id, response);
break;
case -ENOENT:
rc = ss_tx_to_ms_error(ss, true, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER);
break;
case -EIO:
default:
rc = ss_tx_to_ms_error(ss, true, GSM0480_ERR_CODE_SYSTEM_FAILURE);
break;
}
return rc;
}
static int handle_ussd_gsm_on(struct ss_session *ss,
const struct osmo_gsup_message *gsup,
const struct ss_request *req)
{
struct hlr_subscriber subscr;
int rc;
rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &subscr);
switch (rc) {
case 0:
hlr_subscr_rat_flag(g_hlr, &subscr, OSMO_RAT_GERAN_A, true);
rc = ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id,
"Enabled GERAN-A (2G)");
break;
case -ENOENT:
rc = ss_tx_to_ms_error(ss, true, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER);
break;
case -EIO:
default:
rc = ss_tx_to_ms_error(ss, true, GSM0480_ERR_CODE_SYSTEM_FAILURE);
break;
}
return rc;
}
static int handle_ussd_gsm_off(struct ss_session *ss,
const struct osmo_gsup_message *gsup,
const struct ss_request *req)
{
struct hlr_subscriber subscr;
int rc;
rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &subscr);
switch (rc) {
case 0:
hlr_subscr_rat_flag(g_hlr, &subscr, OSMO_RAT_GERAN_A, false);
rc = ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id,
"Disabled GERAN-A (2G)");
break;
case -ENOENT:
rc = ss_tx_to_ms_error(ss, true, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER);
break;
case -EIO:
default:
rc = ss_tx_to_ms_error(ss, true, GSM0480_ERR_CODE_SYSTEM_FAILURE);
break;
}
return rc;
}
static int handle_ussd_umts_on(struct ss_session *ss,
const struct osmo_gsup_message *gsup,
const struct ss_request *req)
{
struct hlr_subscriber subscr;
int rc;
rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &subscr);
switch (rc) {
case 0:
hlr_subscr_rat_flag(g_hlr, &subscr, OSMO_RAT_UTRAN_IU, true);
rc = ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id,
"Enabled UTRAN-Iu (3G)");
break;
case -ENOENT:
rc = ss_tx_to_ms_error(ss, true, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER);
break;
case -EIO:
default:
rc = ss_tx_to_ms_error(ss, true, GSM0480_ERR_CODE_SYSTEM_FAILURE);
break;
}
return rc;
}
static int handle_ussd_umts_off(struct ss_session *ss,
const struct osmo_gsup_message *gsup,
const struct ss_request *req)
{
struct hlr_subscriber subscr;
int rc;
rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &subscr);
switch (rc) {
case 0:
hlr_subscr_rat_flag(g_hlr, &subscr, OSMO_RAT_UTRAN_IU, false);
rc = ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id,
"Disabled UTRAN-Iu (3G)");
break;
case -ENOENT:
rc = ss_tx_to_ms_error(ss, true, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER);
break;
case -EIO:
default:
rc = ss_tx_to_ms_error(ss, true, GSM0480_ERR_CODE_SYSTEM_FAILURE);
break;
}
return rc;
}
static int handle_ussd_lte_on(struct ss_session *ss,
const struct osmo_gsup_message *gsup,
const struct ss_request *req)
{
struct hlr_subscriber subscr;
int rc;
rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &subscr);
switch (rc) {
case 0:
hlr_subscr_rat_flag(g_hlr, &subscr, OSMO_RAT_EUTRAN_SGS, true);
rc = ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id,
"Enabled EUTRAN-SGs (4G)");
break;
case -ENOENT:
rc = ss_tx_to_ms_error(ss, true, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER);
break;
case -EIO:
default:
rc = ss_tx_to_ms_error(ss, true, GSM0480_ERR_CODE_SYSTEM_FAILURE);
break;
}
return rc;
}
static int handle_ussd_lte_off(struct ss_session *ss,
const struct osmo_gsup_message *gsup,
const struct ss_request *req)
{
struct hlr_subscriber subscr;
int rc;
rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &subscr);
switch (rc) {
case 0:
hlr_subscr_rat_flag(g_hlr, &subscr, OSMO_RAT_EUTRAN_SGS, false);
rc = ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id,
"Disabled EUTRAN-SGs (4G)");
break;
case -ENOENT:
rc = ss_tx_to_ms_error(ss, true, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER);
break;
case -EIO:
default:
rc = ss_tx_to_ms_error(ss, true, GSM0480_ERR_CODE_SYSTEM_FAILURE);
break;
}
return rc;
char buf[GSM0480_USSD_7BIT_STRING_LEN + 1];
snprintf(buf, sizeof(buf), "Keeping your session idle, it will expire "
"at most in %u seconds.", g_hlr->ncss_guard_timeout);
ss->state = OSMO_GSUP_SESSION_STATE_CONTINUE;
ss_tx_to_ms_ussd_7bit(ss, req->invoke_id, buf);
return 0;
}
@@ -584,32 +403,8 @@ static const struct hlr_iuse hlr_iuses[] = {
.handle_ussd = handle_ussd_own_imsi,
},
{
.name = "get-ran",
.handle_ussd = handle_ussd_get_ran,
},
{
.name = "gsm-on",
.handle_ussd = handle_ussd_gsm_on,
},
{
.name = "gsm-off",
.handle_ussd = handle_ussd_gsm_off,
},
{
.name = "umts-on",
.handle_ussd = handle_ussd_umts_on,
},
{
.name = "umts-off",
.handle_ussd = handle_ussd_umts_off,
},
{
.name = "lte-on",
.handle_ussd = handle_ussd_lte_on,
},
{
.name = "lte-off",
.handle_ussd = handle_ussd_lte_off,
.name = "test-idle",
.handle_ussd = handle_ussd_test_idle,
},
};
@@ -644,22 +439,22 @@ static bool ss_op_is_ussd(uint8_t opcode)
}
/* is this GSUP connection an EUSE (true) or not (false)? */
static bool peer_name_is_euse(const struct osmo_gsup_peer_id *peer_name)
static bool peer_name_is_euse(const struct osmo_cni_peer_id *peer_name)
{
if (peer_name->type != OSMO_GSUP_PEER_ID_IPA_NAME)
if (peer_name->type != OSMO_CNI_PEER_ID_IPA_NAME)
return false;
if (peer_name->ipa_name.len <= 5)
return false;
return strncmp((char *)(peer_name->ipa_name.val), "EUSE-", 5) == 0;
}
static struct hlr_euse *euse_by_name(const struct osmo_gsup_peer_id *peer_name)
static struct hlr_euse *euse_by_name(const struct osmo_cni_peer_id *peer_name)
{
if (!peer_name_is_euse(peer_name))
return NULL;
/* above peer_name_is_euse() ensures this: */
OSMO_ASSERT(peer_name->type == OSMO_GSUP_PEER_ID_IPA_NAME);
OSMO_ASSERT(peer_name->type == OSMO_CNI_PEER_ID_IPA_NAME);
return euse_find(g_hlr, (const char*)(peer_name->ipa_name.val)+5);
}
@@ -724,9 +519,9 @@ static int handle_ussd(struct ss_session *ss, bool is_euse_originated, const str
} else {
/* Handle internally */
ss->u.iuse->handle_ussd(ss, gsup, req);
/* Release session immediately */
ss_session_free(ss);
return 0;
/* Release session if the handler has changed its state to END */
if (ss->state == OSMO_GSUP_SESSION_STATE_END)
ss_session_free(ss);
}
}
@@ -750,10 +545,10 @@ void rx_proc_ss_req(struct osmo_gsup_req *gsup_req)
LOGP(DSS, LOGL_DEBUG, "%s/0x%08x: Process SS (%s)\n", gsup->imsi, gsup->session_id,
osmo_gsup_session_state_name(gsup->session_state));
if (gsup_req->source_name.type != OSMO_GSUP_PEER_ID_IPA_NAME) {
if (gsup_req->source_name.type != OSMO_CNI_PEER_ID_IPA_NAME) {
LOGP(DSS, LOGL_ERROR, "%s/0x%082x: Unable to process SS request: Unsupported GSUP peer id type%s\n",
gsup->imsi, gsup->session_id,
osmo_gsup_peer_id_type_name(gsup_req->source_name.type));
osmo_cni_peer_id_type_name(gsup_req->source_name.type));
osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_PROTO_ERR_UNSPEC, "error processing SS request");
return;
}
@@ -795,7 +590,7 @@ void rx_proc_ss_req(struct osmo_gsup_req *gsup_req)
if (!is_euse_originated) {
ss->initial_req_from_ms = gsup_req;
free_gsup_req = NULL;
OSMO_ASSERT(gsup_req->source_name.type == OSMO_GSUP_PEER_ID_IPA_NAME); /* checked above */
OSMO_ASSERT(gsup_req->source_name.type == OSMO_CNI_PEER_ID_IPA_NAME); /* checked above */
ss->vlr_name = gsup_req->source_name.ipa_name;
} else {
ss->initial_req_from_euse = gsup_req;

View File

@@ -25,7 +25,10 @@
*
*/
#include <errno.h>
#include <osmocom/core/talloc.h>
#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
#include <osmocom/vty/vty.h>
#include <osmocom/vty/stats.h>
#include <osmocom/vty/command.h>
@@ -40,6 +43,36 @@
#include <osmocom/hlr/hlr_ussd.h>
#include <osmocom/hlr/gsup_server.h>
static const struct value_string gsm48_gmm_cause_vty_names[] = {
{ GMM_CAUSE_IMSI_UNKNOWN, "imsi-unknown" },
{ GMM_CAUSE_ILLEGAL_MS, "illegal-ms" },
{ GMM_CAUSE_PLMN_NOTALLOWED, "plmn-not-allowed" },
{ GMM_CAUSE_LA_NOTALLOWED, "la-not-allowed" },
{ GMM_CAUSE_ROAMING_NOTALLOWED, "roaming-not-allowed" },
{ GMM_CAUSE_NO_SUIT_CELL_IN_LA, "no-suitable-cell-in-la" },
{ GMM_CAUSE_NET_FAIL, "net-fail" },
{ GMM_CAUSE_CONGESTION, "congestion" },
{ GMM_CAUSE_GSM_AUTH_UNACCEPT, "auth-unacceptable" },
{ GMM_CAUSE_PROTO_ERR_UNSPEC, "proto-error-unspec" },
{ 0, NULL },
};
/* TS 24.008 4.4.4.7 */
static const struct value_string gsm48_gmm_cause_vty_descs[] = {
{ GMM_CAUSE_IMSI_UNKNOWN, " #02: (IMSI unknown in HLR)" },
{ GMM_CAUSE_ILLEGAL_MS, " #03 (Illegal MS)" },
{ GMM_CAUSE_PLMN_NOTALLOWED, " #11: (PLMN not allowed)" },
{ GMM_CAUSE_LA_NOTALLOWED, " #12: (Location Area not allowed)" },
{ GMM_CAUSE_ROAMING_NOTALLOWED, " #13: (Roaming not allowed in this location area)" },
{ GMM_CAUSE_NO_SUIT_CELL_IN_LA, " #15: (No Suitable Cells In Location Area [continue search in PLMN])." },
{ GMM_CAUSE_NET_FAIL, " #17: (Network Failure)" },
{ GMM_CAUSE_CONGESTION, " #22: (Congestion)" },
{ GMM_CAUSE_GSM_AUTH_UNACCEPT, " #23: (GSM authentication unacceptable [UMTS])" },
{ GMM_CAUSE_PROTO_ERR_UNSPEC, "#111: (Protocol error, unspecified)" },
{ 0, NULL },
};
struct cmd_node hlr_node = {
HLR_NODE,
"%s(config-hlr)# ",
@@ -73,6 +106,15 @@ DEFUN(cfg_gsup,
static int config_write_hlr(struct vty *vty)
{
vty_out(vty, "hlr%s", VTY_NEWLINE);
if (g_hlr->reject_cause != GMM_CAUSE_IMSI_UNKNOWN)
vty_out(vty, " reject-cause not-found %s%s",
get_value_string_or_null(gsm48_gmm_cause_vty_names,
(uint32_t) g_hlr->reject_cause), VTY_NEWLINE);
if (g_hlr->no_proxy_reject_cause != GMM_CAUSE_IMSI_UNKNOWN)
vty_out(vty, " reject-cause no-proxy %s%s",
get_value_string_or_null(gsm48_gmm_cause_vty_names,
(uint32_t) g_hlr->no_proxy_reject_cause), VTY_NEWLINE);
if (g_hlr->store_imei)
vty_out(vty, " store-imei%s", VTY_NEWLINE);
if (g_hlr->db_file_path && strcmp(g_hlr->db_file_path, HLR_DEFAULT_DB_FILE_PATH))
@@ -102,6 +144,8 @@ static int config_write_hlr_gsup(struct vty *vty)
vty_out(vty, " gsup%s", VTY_NEWLINE);
if (g_hlr->gsup_bind_addr)
vty_out(vty, " bind ip %s%s", g_hlr->gsup_bind_addr, VTY_NEWLINE);
if (g_hlr->gsup_unit_name.serno)
vty_out(vty, " ipa-name %s%s", g_hlr->gsup_unit_name.serno, VTY_NEWLINE);
return CMD_SUCCESS;
}
@@ -114,8 +158,8 @@ static void show_one_conn(struct vty *vty, const struct osmo_gsup_conn *conn)
rc = osmo_gsup_conn_ccm_get(conn, (uint8_t **) &name, IPAC_IDTAG_SERNR);
OSMO_ASSERT(rc);
vty_out(vty, " '%s' from %s:%5u, CS=%u, PS=%u, 3G_IND=%u%s",
name, isc->addr, isc->port, conn->supports_cs, conn->supports_ps, conn->auc_3g_ind,
vty_out(vty, " '%s' from %s:%5u, CS=%u, PS=%u%s",
name, isc->addr, isc->port, conn->supports_cs, conn->supports_ps,
VTY_NEWLINE);
}
@@ -156,7 +200,7 @@ DEFUN(cfg_hlr_gsup_ipa_name,
{
if (vty->type != VTY_FILE) {
vty_out(vty, "gsup/ipa-name: The GSUP IPA name cannot be changed at run-time; "
"It can only be set in the configuraton file.%s", VTY_NEWLINE);
"It can only be set in the configuration file.%s", VTY_NEWLINE);
return CMD_WARNING;
}
@@ -174,17 +218,11 @@ DEFUN(cfg_hlr_gsup_ipa_name,
#define UROUTE_STR "Routing Configuration\n"
#define PREFIX_STR "Prefix-Matching Route\n" "USSD Prefix\n"
#define INT_CHOICE "(own-msisdn|own-imsi|get-ran|gsm-on|gsm-off|umts-on|umts-off|lte-on|lte-off)"
#define INT_CHOICE "(own-msisdn|own-imsi|test-idle)"
#define INT_STR "Internal USSD Handler\n" \
"Respond with subscribers' own MSISDN\n" \
"Respond with subscribers' own IMSI\n" \
"Respond with available RAN types\n" \
"Enable GSM service\n" \
"Disable GSM service\n" \
"Enable UMTS service\n" \
"Disable UMTS service\n" \
"Enable LTE service\n" \
"Disable LTE service\n"
"Keep the session idle (useful for testing)\n"
#define EXT_STR "External USSD Handler\n" \
"Name of External USSD Handler (IPA CCM ID)\n"
@@ -312,7 +350,7 @@ DEFUN(cfg_no_euse, cfg_no_euse_cmd,
{
struct hlr_euse *euse = euse_find(g_hlr, argv[0]);
if (!euse) {
vty_out(vty, "%% Cannot remove non-existant EUSE %s%s", argv[0], VTY_NEWLINE);
vty_out(vty, "%% Cannot remove non-existent EUSE %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
if (g_hlr->euse_default == euse) {
@@ -362,6 +400,21 @@ DEFUN(cfg_ncss_guard_timeout, cfg_ncss_guard_timeout_cmd,
return CMD_SUCCESS;
}
DEFUN(cfg_reject_cause, cfg_reject_cause_cmd,
"reject-cause TYPE CAUSE", "") /* Dynamically Generated */
{
int cause_code = get_string_value(gsm48_gmm_cause_vty_names, argv[1]);
OSMO_ASSERT(cause_code >= 0);
if (strcmp(argv[0], "not-found") == 0)
g_hlr->reject_cause = (enum gsm48_gmm_cause) cause_code;
if (strcmp(argv[0], "no-proxy") == 0)
g_hlr->no_proxy_reject_cause = (enum gsm48_gmm_cause) cause_code;
return CMD_SUCCESS;
}
DEFUN(cfg_store_imei, cfg_store_imei_cmd,
"store-imei",
"Save the IMEI in the database when receiving Check IMEI requests. Note that an MSC does not necessarily send"
@@ -454,8 +507,22 @@ int hlr_vty_is_config_node(struct vty *vty, int node)
}
}
void hlr_vty_init(void)
void hlr_vty_init(void *hlr_ctx)
{
cfg_reject_cause_cmd.string =
vty_cmd_string_from_valstr(hlr_ctx,
gsm48_gmm_cause_vty_names,
"reject-cause (not-found|no-proxy) (", "|", ")",
VTY_DO_LOWER);
cfg_reject_cause_cmd.doc =
vty_cmd_string_from_valstr(hlr_ctx,
gsm48_gmm_cause_vty_descs,
"GSUP/GMM cause to be sent\n"
"in the case the IMSI could not be found in the database\n"
"in the case no remote HLR reponded to mslookup GSUP request\n",
"\n", "", 0);
logging_vty_add_cmds();
osmo_talloc_vty_add_cmds();
osmo_stats_vty_add_cmds();
@@ -482,6 +549,7 @@ void hlr_vty_init(void)
install_element(HLR_NODE, &cfg_ussd_defaultroute_cmd);
install_element(HLR_NODE, &cfg_ussd_no_defaultroute_cmd);
install_element(HLR_NODE, &cfg_ncss_guard_timeout_cmd);
install_element(HLR_NODE, &cfg_reject_cause_cmd);
install_element(HLR_NODE, &cfg_store_imei_cmd);
install_element(HLR_NODE, &cfg_no_store_imei_cmd);
install_element(HLR_NODE, &cfg_subscr_create_on_demand_cmd);

View File

@@ -27,11 +27,11 @@
#include <osmocom/vty/vty.h>
#include <osmocom/vty/command.h>
#include <osmocom/core/utils.h>
#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/hlr/hlr.h>
#include <osmocom/hlr/db.h>
#include <osmocom/hlr/timestamp.h>
#include <osmocom/hlr/hlr_vty.h>
struct vty;
@@ -39,25 +39,22 @@ struct vty;
static char *get_datestr(const time_t *t, char *buf, size_t bufsize)
{
struct tm *tm;
tm = gmtime(t);
if (!tm)
return "UNKNOWN";
strftime(buf, bufsize, "%FT%T+00:00", tm);
struct tm tm;
gmtime_r(t, &tm);
strftime(buf, bufsize, "%FT%T+00:00", &tm);
return buf;
}
static void dump_last_lu_seen(struct vty *vty, const char *domain_label, time_t last_lu_seen, const char *last_lu_rat)
static void dump_last_lu_seen(struct vty *vty, const char *domain_label, time_t last_lu_seen, bool only_age)
{
uint32_t age;
char datebuf[32];
if (!last_lu_seen)
return;
vty_out(vty, " last LU seen on %s: %s", domain_label, get_datestr(&last_lu_seen, datebuf, sizeof(datebuf)));
if (!only_age)
vty_out(vty, " last LU seen on %s: %s", domain_label, get_datestr(&last_lu_seen, datebuf, sizeof(datebuf)));
if (!timestamp_age(&last_lu_seen, &age))
vty_out(vty, " (invalid timestamp)");
vty_out(vty, " (invalid timestamp)%s", VTY_NEWLINE);
else {
vty_out(vty, " (");
#define UNIT_AGO(UNITNAME, UNITVAL) \
@@ -69,18 +66,17 @@ static void dump_last_lu_seen(struct vty *vty, const char *domain_label, time_t
UNIT_AGO("h", 60*60);
UNIT_AGO("m", 60);
UNIT_AGO("s", 1);
vty_out(vty, " ago)");
if (!only_age)
vty_out(vty, " ago)%s", VTY_NEWLINE);
else
vty_out(vty, " ago)");
#undef UNIT_AGO
}
if (last_lu_rat && *last_lu_rat != '\0')
vty_out(vty, " on %s", last_lu_rat);
vty_out(vty, "%s", VTY_NEWLINE);
}
static void subscr_dump_full_vty(struct vty *vty, struct hlr_subscriber *subscr)
{
int rc;
int i;
struct osmo_sub_auth_data aud2g;
struct osmo_sub_auth_data aud3g;
@@ -117,12 +113,8 @@ static void subscr_dump_full_vty(struct vty *vty, struct hlr_subscriber *subscr)
vty_out(vty, " PS disabled%s", VTY_NEWLINE);
if (subscr->ms_purged_ps)
vty_out(vty, " PS purged%s", VTY_NEWLINE);
dump_last_lu_seen(vty, "CS", subscr->last_lu_seen, subscr->last_lu_rat_cs);
dump_last_lu_seen(vty, "PS", subscr->last_lu_seen_ps, subscr->last_lu_rat_ps);
for (i = OSMO_RAT_UNKNOWN + 1; i < ARRAY_SIZE(subscr->rat_types); i++) {
vty_out(vty, " %s: %s%s", osmo_rat_type_name(i), subscr->rat_types[i] ? "allowed" : "forbidden",
VTY_NEWLINE);
}
dump_last_lu_seen(vty, "CS", subscr->last_lu_seen, false);
dump_last_lu_seen(vty, "PS", subscr->last_lu_seen_ps, false);
if (!*subscr->imsi)
return;
@@ -172,6 +164,28 @@ static void subscr_dump_full_vty(struct vty *vty, struct hlr_subscriber *subscr)
}
}
static void subscr_dump_summary_vty(struct hlr_subscriber *subscr, void *data)
{
struct vty *vty = data;
vty_out(vty, "%-5"PRIu64" %-12s %-16s", subscr->id,
*subscr->msisdn ? subscr->msisdn : "none",
*subscr->imsi ? subscr->imsi : "none");
if (*subscr->imei) {
char checksum = osmo_luhn(subscr->imei, 14);
if (checksum == -EINVAL)
vty_out(vty, " %-14s (INVALID LENGTH!)", subscr->imei);
else
vty_out(vty, " %-14s%c", subscr->imei, checksum);
} else {
vty_out(vty," ------------- ");
}
vty_out(vty, " %-2s%-2s ", subscr->nam_cs ? "CS" : "", subscr->nam_ps ? "PS" : "");
if (subscr->last_lu_seen)
dump_last_lu_seen(vty, "CS", subscr->last_lu_seen, true);
vty_out_newline(vty);
}
static int get_subscr_by_argv(struct vty *vty, const char *type, const char *id, struct hlr_subscriber *subscr)
{
char imei_buf[GSM23003_IMEI_NUM_DIGITS_NO_CHK+1];
@@ -199,10 +213,52 @@ static int get_subscr_by_argv(struct vty *vty, const char *type, const char *id,
return rc;
}
static void dump_summary_table_vty(struct vty *vty, bool header, bool show_ls)
{
const char *texts = "ID MSISDN IMSI IMEI NAM";
const char *lines = "----- ------------ ---------------- ---------------- -----";
const char *ls_text = " LAST SEEN";
const char *ls_line = " ------------";
if (header) {
if (!show_ls)
vty_out(vty, "%s%s%s%s", texts, VTY_NEWLINE, lines, VTY_NEWLINE);
else
vty_out(vty, "%s%s%s%s%s%s", texts, ls_text, VTY_NEWLINE, lines, ls_line, VTY_NEWLINE);
} else {
if (!show_ls)
vty_out(vty, "%s%s%s%s", lines, VTY_NEWLINE, texts, VTY_NEWLINE);
else
vty_out(vty, "%s%s%s%s%s%s", lines, ls_line, VTY_NEWLINE, texts, ls_text, VTY_NEWLINE);
}
}
static int get_subscrs(struct vty *vty, const char *filter_type, const char *filter)
{
int rc = -1;
int count = 0;
const char *err;
bool show_ls = (filter_type && strcmp(filter_type, "last_lu_seen") == 0);
dump_summary_table_vty(vty, true, show_ls);
rc = db_subscrs_get(g_hlr->dbc, filter_type, filter, subscr_dump_summary_vty, vty, &count, &err);
if (count > 40) {
dump_summary_table_vty(vty, false, show_ls);
}
if (count > 0)
vty_out(vty, " Subscribers Shown: %d%s", count, VTY_NEWLINE);
if (rc)
vty_out(vty, "%% %s%s", err, VTY_NEWLINE);
return rc;
}
#define SUBSCR_CMD "subscriber "
#define SUBSCR_CMD_HELP "Subscriber management commands\n"
#define SUBSCR_SHOW_HELP "Show subscriber information\n"
#define SUBSCRS_SHOW_HELP "Show all subscribers (with filter possibility)\n"
#define SUBSCR_ID "(imsi|msisdn|id|imei) IDENT"
#define SUBSCR_FILTER "(imei|imsi|msisdn) FILTER"
#define SUBSCR_ID_HELP \
"Identify subscriber by IMSI\n" \
"Identify subscriber by MSISDN (phone number)\n" \
@@ -220,7 +276,7 @@ static int get_subscr_by_argv(struct vty *vty, const char *type, const char *id,
DEFUN(subscriber_show,
subscriber_show_cmd,
SUBSCR "show",
SUBSCR_HELP "Show subscriber information\n")
SUBSCR_HELP SUBSCR_SHOW_HELP)
{
struct hlr_subscriber subscr;
const char *id_type = argv[0];
@@ -235,7 +291,50 @@ DEFUN(subscriber_show,
ALIAS(subscriber_show, show_subscriber_cmd,
"show " SUBSCR_CMD SUBSCR_ID,
SHOW_STR SUBSCR_CMD_HELP SUBSCR_ID_HELP);
SHOW_STR SUBSCR_SHOW_HELP SUBSCR_ID_HELP);
DEFUN(show_subscriber_all,
show_subscriber_all_cmd,
"show subscribers all",
SHOW_STR SUBSCRS_SHOW_HELP "Show summary of all subscribers\n")
{
if (get_subscrs(vty, NULL, NULL))
return CMD_WARNING;
return CMD_SUCCESS;
}
DEFUN(show_subscriber_filtered,
show_subscriber_filtered_cmd,
"show subscribers " SUBSCR_FILTER,
SHOW_STR SUBSCRS_SHOW_HELP
"Filter Subscribers by IMEI\n" "Filter Subscribers by IMSI\n" "Filter Subscribers by MSISDN\n"
"String to match in imei, imsi or msisdn\n")
{
const char *filter_type = argv[0];
const char *filter = argv[1];
if (get_subscrs(vty, filter_type, filter))
return CMD_WARNING;
return CMD_SUCCESS;
}
ALIAS(show_subscriber_filtered, show_subscriber_filtered_cmd2,
"show subscribers (cs|ps) (on|off)",
SHOW_STR SUBSCR_SHOW_HELP
"Filter Subscribers by CS Network Access Mode\n" "Filter Subscribers by PS Network Access Mode\n"
"Authorised\n" "Not Authorised\n");
DEFUN(show_subscriber_order_last_seen, show_subscriber_order_last_seen_cmd,
"show subscribers last-seen",
SHOW_STR SUBSCR_SHOW_HELP "Show Subscribers Ordered by Last Seen Time\n")
{
if (get_subscrs(vty, "last_lu_seen", NULL))
return CMD_WARNING;
return CMD_SUCCESS;
}
DEFUN(subscriber_create,
subscriber_create_cmd,
@@ -248,7 +347,7 @@ DEFUN(subscriber_create,
int rc;
struct hlr_subscriber subscr;
const char *imsi = argv[0];
if (!osmo_imsi_str_valid(imsi)) {
vty_out(vty, "%% Not a valid IMSI: %s%s", imsi, VTY_NEWLINE);
return CMD_WARNING;
@@ -372,14 +471,8 @@ static bool is_hexkey_valid(struct vty *vty, const char *label,
#define AUTH_ALG_TYPES_3G_HELP \
"Use Milenage algorithm\n"
#define A38_XOR_MIN_KEY_LEN 12
#define A38_XOR_MAX_KEY_LEN 16
#define A38_COMP128_KEY_LEN 16
#define MILENAGE_KEY_LEN 16
static bool auth_algo_parse(const char *alg_str, enum osmo_auth_algo *algo,
int *minlen, int *maxlen)
bool auth_algo_parse(const char *alg_str, enum osmo_auth_algo *algo,
int *minlen, int *maxlen)
{
if (!strcasecmp(alg_str, "none")) {
*algo = OSMO_AUTH_ALG_NONE;
@@ -538,7 +631,7 @@ DEFUN(subscriber_aud3g,
.ind_bitlen = ind_bitlen,
},
};
if (!auth_algo_parse(alg_type, &aud3g.algo, &minlen, &maxlen)) {
vty_out(vty, "%% Unknown auth algorithm: '%s'%s", alg_type, VTY_NEWLINE);
return CMD_WARNING;
@@ -564,6 +657,55 @@ DEFUN(subscriber_aud3g,
return CMD_SUCCESS;
}
DEFUN(subscriber_aud3g_xor,
subscriber_aud3g_xor_cmd,
SUBSCR_UPDATE "aud3g xor k K"
" [ind-bitlen] [<0-28>]",
SUBSCR_UPDATE_HELP
"Set UMTS authentication data (3G, and 2G with UMTS AKA)\n"
"Use XOR algorithm\n"
"Set Encryption Key K\n" "K as 32 hexadecimal characters\n"
"Set IND bit length\n" "IND bit length value (default: 5)\n")
{
struct hlr_subscriber subscr;
int minlen = 0;
int maxlen = 0;
int rc;
const char *id_type = argv[0];
const char *id = argv[1];
const char *k = argv[2];
int ind_bitlen = argc > 4? atoi(argv[4]) : 5;
struct sub_auth_data_str aud3g = {
.type = OSMO_AUTH_TYPE_UMTS,
.u.umts = {
.k = k,
.opc_is_op = 0,
.opc = "00000000000000000000000000000000",
.ind_bitlen = ind_bitlen,
},
};
if (!auth_algo_parse("xor", &aud3g.algo, &minlen, &maxlen)) {
vty_out(vty, "%% Unknown auth algorithm: '%s'%s", "xor", VTY_NEWLINE);
return CMD_WARNING;
}
if (!is_hexkey_valid(vty, "K", aud3g.u.umts.k, minlen, maxlen))
return CMD_WARNING;
if (get_subscr_by_argv(vty, id_type, id, &subscr))
return CMD_WARNING;
rc = db_subscr_update_aud_by_id(g_hlr->dbc, subscr.id, &aud3g);
if (rc) {
vty_out(vty, "%% Error: cannot set 3G auth data for IMSI='%s'%s",
subscr.imsi, VTY_NEWLINE);
return CMD_WARNING;
}
return CMD_SUCCESS;
}
DEFUN(subscriber_imei,
subscriber_imei_cmd,
SUBSCR_UPDATE "imei (none|IMEI)",
@@ -639,50 +781,12 @@ DEFUN(subscriber_nam,
}
DEFUN(subscriber_rat,
subscriber_rat_cmd,
SUBSCR_UPDATE "rat (geran-a|utran-iu|eutran-sgs) (allowed|forbidden)",
SUBSCR_UPDATE_HELP
"Allow or forbid specific Radio Access Types\n"
"Set access to GERAN-A\n"
"Set access to UTRAN-Iu\n"
"Set access to EUTRAN-SGs\n"
"Allow access\n"
"Forbid access\n")
{
struct hlr_subscriber subscr;
const char *id_type = argv[0];
const char *id = argv[1];
const char *rat_str = argv[2];
const char *allowed_forbidden = argv[3];
enum osmo_rat_type rat = OSMO_RAT_UNKNOWN;
bool allowed;
int rc;
if (strcmp(rat_str, "geran-a") == 0)
rat = OSMO_RAT_GERAN_A;
else if (strcmp(rat_str, "utran-iu") == 0)
rat = OSMO_RAT_UTRAN_IU;
else if (strcmp(rat_str, "eutran-sgs") == 0)
rat = OSMO_RAT_EUTRAN_SGS;
allowed = (strcmp(allowed_forbidden, "allowed") == 0);
if (get_subscr_by_argv(vty, id_type, id, &subscr))
return CMD_WARNING;
rc = hlr_subscr_rat_flag(g_hlr, &subscr, rat, allowed);
if (rc && rc != -ENOEXEC) {
vty_out(vty, "%% Error: cannot set %s to %s%s",
osmo_rat_type_name(rat), allowed ? "allowed" : "forbidden", VTY_NEWLINE);
return CMD_WARNING;
}
return CMD_SUCCESS;
}
void hlr_vty_subscriber_init(void)
{
install_element_ve(&show_subscriber_all_cmd);
install_element_ve(&show_subscriber_filtered_cmd);
install_element_ve(&show_subscriber_filtered_cmd2);
install_element_ve(&show_subscriber_order_last_seen_cmd);
install_element_ve(&subscriber_show_cmd);
install_element_ve(&show_subscriber_cmd);
install_element(ENABLE_NODE, &subscriber_create_cmd);
@@ -692,7 +796,7 @@ void hlr_vty_subscriber_init(void)
install_element(ENABLE_NODE, &subscriber_aud2g_cmd);
install_element(ENABLE_NODE, &subscriber_no_aud3g_cmd);
install_element(ENABLE_NODE, &subscriber_aud3g_cmd);
install_element(ENABLE_NODE, &subscriber_aud3g_xor_cmd);
install_element(ENABLE_NODE, &subscriber_imei_cmd);
install_element(ENABLE_NODE, &subscriber_nam_cmd);
install_element(ENABLE_NODE, &subscriber_rat_cmd);
}

View File

@@ -43,6 +43,12 @@ const struct log_info_cat hlr_log_info_cat[] = {
.color = "\033[1;35m",
.enabled = 1, .loglevel = LOGL_NOTICE,
},
[DCTRL] = {
.name = "DCTRL",
.description = "Osmocom CTRL interface",
.color = "\033[1;30m",
.enabled = 1, .loglevel = LOGL_NOTICE,
},
};
const struct log_info hlr_log_info = {

View File

@@ -26,7 +26,7 @@
#include <osmocom/gsm/apn.h>
#include <osmocom/gsm/gsm48_ie.h>
#include <osmocom/gsupclient/gsup_peer_id.h>
#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/gsupclient/gsup_req.h>
#include <osmocom/hlr/logging.h>
#include <osmocom/hlr/hlr.h>
@@ -52,11 +52,11 @@ struct lu {
bool is_ps;
/* VLR requesting the LU. */
struct osmo_gsup_peer_id vlr_name;
struct osmo_cni_peer_id vlr_name;
/* If the LU request was received via a proxy and not immediately from a local VLR, this indicates the closest
* peer that forwarded the GSUP message. */
struct osmo_gsup_peer_id via_proxy;
struct osmo_cni_peer_id via_proxy;
};
LLIST_HEAD(g_all_lu);
@@ -108,8 +108,6 @@ static void lu_start(struct osmo_gsup_req *update_location_req)
{
struct osmo_fsm_inst *fi;
struct lu *lu;
bool any_rat_allowed;
int i;
OSMO_ASSERT(update_location_req);
OSMO_ASSERT(update_location_req->gsup.message_type == OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST);
@@ -132,13 +130,13 @@ static void lu_start(struct osmo_gsup_req *update_location_req)
osmo_fsm_inst_update_id_f_sanitize(fi, '_', "%s:IMSI-%s", lu->is_ps ? "PS" : "CS", update_location_req->gsup.imsi);
if (osmo_gsup_peer_id_is_empty(&lu->vlr_name)) {
if (osmo_cni_peer_id_is_empty(&lu->vlr_name)) {
lu_failure(lu, GMM_CAUSE_NET_FAIL, "LU without a VLR");
return;
}
if (db_subscr_get_by_imsi(g_hlr->dbc, update_location_req->gsup.imsi, &lu->subscr) < 0) {
lu_failure(lu, GMM_CAUSE_ROAMING_NOTALLOWED, "Subscriber does not exist");
lu_failure(lu, g_hlr->reject_cause, "Subscriber does not exist");
return;
}
@@ -153,32 +151,10 @@ static void lu_start(struct osmo_gsup_req *update_location_req)
return;
}
/* Check if any available RAT type is allowed. See 3GPP TS 29.010 3.2 'Routeing area updating' and 3.8 'Location
* update' for the "No Suitable cells in location area" error code. */
any_rat_allowed = false;
for (i = 0; i < update_location_req->gsup.supported_rat_types_len; i++) {
enum osmo_rat_type rat = update_location_req->gsup.supported_rat_types[i];
if (rat <= 0 || rat >= OSMO_RAT_COUNT) {
lu_failure(lu, GMM_CAUSE_COND_IE_ERR, "Invalid RAT type in GSUP request: %s",
osmo_rat_type_name(rat));
return;
}
if (lu->subscr.rat_types[rat]) {
any_rat_allowed = true;
LOG_LU(lu, LOGL_DEBUG, "subscriber allowed on %s\n", osmo_rat_type_name(rat));
} else {
LOG_LU(lu, LOGL_DEBUG, "subscriber not allowed on %s\n", osmo_rat_type_name(rat));
}
}
if (!any_rat_allowed && update_location_req->gsup.supported_rat_types_len > 0) {
lu_failure(lu, GMM_CAUSE_NO_SUIT_CELL_IN_LA, "subscriber not allowed on any available RAT type");
return;
}
/* TODO: Set subscriber tracing = deactive in VLR/SGSN */
#if 0
/* Cancel in old VLR/SGSN, if new VLR/SGSN differs from old */
/* Cancel in old VLR/SGSN, if new VLR/SGSN differs from old (FIXME: OS#4491) */
if (!lu->is_ps && strcmp(subscr->vlr_number, vlr_number)) {
lu_op_tx_cancel_old(lu);
} else if (lu->is_ps && strcmp(subscr->sgsn_number, sgsn_number)) {
@@ -187,31 +163,30 @@ static void lu_start(struct osmo_gsup_req *update_location_req)
#endif
/* Store the VLR / SGSN number with the subscriber, so we know where it was last seen. */
if (!osmo_gsup_peer_id_is_empty(&lu->via_proxy)) {
if (!osmo_cni_peer_id_is_empty(&lu->via_proxy)) {
LOG_GSUP_REQ(update_location_req, LOGL_DEBUG, "storing %s = %s, via proxy %s\n",
lu->is_ps ? "SGSN number" : "VLR number",
osmo_gsup_peer_id_to_str(&lu->vlr_name),
osmo_gsup_peer_id_to_str(&lu->via_proxy));
osmo_cni_peer_id_to_str(&lu->vlr_name),
osmo_cni_peer_id_to_str(&lu->via_proxy));
} else {
LOG_GSUP_REQ(update_location_req, LOGL_DEBUG, "storing %s = %s\n",
lu->is_ps ? "SGSN number" : "VLR number",
osmo_gsup_peer_id_to_str(&lu->vlr_name));
osmo_cni_peer_id_to_str(&lu->vlr_name));
}
if (osmo_gsup_peer_id_is_empty(&lu->vlr_name)
|| (lu->vlr_name.type != OSMO_GSUP_PEER_ID_IPA_NAME)) {
if (osmo_cni_peer_id_is_empty(&lu->vlr_name)
|| (lu->vlr_name.type != OSMO_CNI_PEER_ID_IPA_NAME)) {
lu_failure(lu, GMM_CAUSE_PROTO_ERR_UNSPEC, "Unsupported GSUP peer id type for vlr_name: %s",
osmo_gsup_peer_id_type_name(lu->vlr_name.type));
osmo_cni_peer_id_type_name(lu->vlr_name.type));
return;
}
if (!osmo_gsup_peer_id_is_empty(&lu->via_proxy) && (lu->via_proxy.type != OSMO_GSUP_PEER_ID_IPA_NAME)) {
if (!osmo_cni_peer_id_is_empty(&lu->via_proxy) && (lu->via_proxy.type != OSMO_CNI_PEER_ID_IPA_NAME)) {
lu_failure(lu, GMM_CAUSE_PROTO_ERR_UNSPEC, "Unsupported GSUP peer id type for via_proxy: %s",
osmo_gsup_peer_id_type_name(lu->via_proxy.type));
osmo_cni_peer_id_type_name(lu->via_proxy.type));
return;
}
if (db_subscr_lu(g_hlr->dbc, lu->subscr.id, &lu->vlr_name.ipa_name, lu->is_ps,
osmo_gsup_peer_id_is_empty(&lu->via_proxy)? NULL : &lu->via_proxy.ipa_name,
update_location_req->gsup.supported_rat_types, update_location_req->gsup.supported_rat_types_len)) {
osmo_cni_peer_id_is_empty(&lu->via_proxy)? NULL : &lu->via_proxy.ipa_name)) {
lu_failure(lu, GMM_CAUSE_NET_FAIL, "Cannot update %s in the database",
lu->is_ps ? "SGSN number" : "VLR number");
return;
@@ -339,7 +314,7 @@ static struct osmo_fsm lu_fsm = {
.cleanup = lu_fsm_cleanup,
};
static __attribute__((constructor)) void lu_fsm_init()
static __attribute__((constructor)) void lu_fsm_init(void)
{
OSMO_ASSERT(osmo_fsm_register(&lu_fsm) == 0);
}

View File

@@ -1,7 +1,7 @@
# This is _NOT_ the library release version, it's an API version.
# Please read chapter "Library interface versions" of the libtool documentation
# before making any modifications: https://www.gnu.org/software/libtool/manual/html_node/Versioning.html
LIBVERSION=0:0:0
LIBVERSION=1:0:0
AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)/include
AM_CFLAGS = -fPIC -Wall $(PCSC_CFLAGS) $(TALLOC_CFLAGS) $(LIBOSMOCORE_CFLAGS)

View File

@@ -40,7 +40,7 @@ int osmo_mdns_msg_request_encode(void *ctx, struct msgb *msg, const struct osmo_
qst.domain = req->domain;
qst.qtype = req->type;
qst.qclass = OSMO_MDNS_RFC_CLASS_IN;
if (osmo_mdns_rfc_question_encode(ctx, msg, &qst) != 0)
if (osmo_mdns_rfc_question_encode(msg, &qst) != 0)
return -EINVAL;
return 0;
@@ -106,7 +106,7 @@ int osmo_mdns_msg_answer_encode(void *ctx, struct msgb *msg, const struct osmo_m
rec.rdlength = ans_record->length;
rec.rdata = ans_record->data;
if (osmo_mdns_rfc_record_encode(ctx, msg, &rec) != 0)
if (osmo_mdns_rfc_record_encode(msg, &rec) != 0)
return -EINVAL;
}
@@ -213,9 +213,9 @@ struct osmo_mdns_record *osmo_mdns_record_txt_keyval_encode(void *ctx, const cha
va_start(ap, value_fmt);
value = talloc_vasprintf(ctx, value_fmt, ap);
va_end(ap);
if (!value)
return NULL;
va_end(ap);
r = _osmo_mdns_record_txt_encode(ctx, key, value);
talloc_free(value);
return r;

View File

@@ -27,86 +27,9 @@
#include <osmocom/core/msgb.h>
#include <osmocom/core/bitvec.h>
#include <osmocom/core/logging.h>
#include <osmocom/gsm/apn.h>
#include <osmocom/mslookup/mdns_rfc.h>
/*
* Encode/decode IEs
*/
/*! Encode a domain string as qname (RFC 1035 4.1.2).
* \param[in] domain multiple labels separated by dots, e.g. "sip.voice.1234.msisdn".
* \returns allocated buffer with length-value pairs for each label (e.g. 0x03 "sip" 0x05 "voice" ...), NULL on error.
*/
char *osmo_mdns_rfc_qname_encode(void *ctx, const char *domain)
{
char *domain_dup;
char *domain_iter;
char buf[OSMO_MDNS_RFC_MAX_NAME_LEN + 2] = ""; /* len(qname) is len(domain) +1 */
struct osmo_strbuf sb = { .buf = buf, .len = sizeof(buf) };
char *label;
if (strlen(domain) > OSMO_MDNS_RFC_MAX_NAME_LEN)
return NULL;
domain_iter = domain_dup = talloc_strdup(ctx, domain);
while ((label = strsep(&domain_iter, "."))) {
size_t len = strlen(label);
/* Empty domain, dot at start, two dots in a row, or ending with a dot */
if (!len)
goto error;
OSMO_STRBUF_PRINTF(sb, "%c%s", (char)len, label);
}
talloc_free(domain_dup);
return talloc_strdup(ctx, buf);
error:
talloc_free(domain_dup);
return NULL;
}
/*! Decode a domain string from a qname (RFC 1035 4.1.2).
* \param[in] qname buffer with length-value pairs for each label (e.g. 0x03 "sip" 0x05 "voice" ...)
* \param[in] qname_max_len amount of bytes that can be read at most from the memory location that qname points to.
* \returns allocated buffer with domain string, multiple labels separated by dots (e.g. "sip.voice.1234.msisdn"),
* NULL on error.
*/
char *osmo_mdns_rfc_qname_decode(void *ctx, const char *qname, size_t qname_max_len)
{
const char *next_label, *qname_end = qname + qname_max_len;
char buf[OSMO_MDNS_RFC_MAX_NAME_LEN + 1];
int i = 0;
if (qname_max_len < 1)
return NULL;
while (*qname) {
size_t len = *qname;
next_label = qname + len + 1;
if (next_label >= qname_end || i + len > OSMO_MDNS_RFC_MAX_NAME_LEN)
return NULL;
if (i) {
/* Two dots in a row is not allowed */
if (buf[i - 1] == '.')
return NULL;
buf[i] = '.';
i++;
}
memcpy(buf + i, qname + 1, len);
i += len;
qname = next_label;
}
buf[i] = '\0';
return talloc_strdup(ctx, buf);
}
/*
* Encode/decode message sections
*/
@@ -146,20 +69,17 @@ int osmo_mdns_rfc_header_decode(const uint8_t *data, size_t data_len, struct osm
/*! Encode question section (RFC 1035 4.1.2).
* \param[in] msgb mesage buffer to which the encoded data will be appended.
*/
int osmo_mdns_rfc_question_encode(void *ctx, struct msgb *msg, const struct osmo_mdns_rfc_question *qst)
int osmo_mdns_rfc_question_encode(struct msgb *msg, const struct osmo_mdns_rfc_question *qst)
{
char *qname;
size_t qname_len;
uint8_t *qname_buf;
uint8_t *buf;
size_t buf_len;
/* qname */
qname = osmo_mdns_rfc_qname_encode(ctx, qst->domain);
if (!qname)
buf_len = strlen(qst->domain) + 1;
buf = msgb_put(msg, buf_len);
if (osmo_apn_from_str(buf, buf_len, qst->domain) < 0)
return -EINVAL;
qname_len = strlen(qname) + 1;
qname_buf = msgb_put(msg, qname_len);
memcpy(qname_buf, qname, qname_len);
talloc_free(qname);
msgb_put_u8(msg, 0x00);
/* qtype and qclass */
msgb_put_u16(msg, qst->qtype);
@@ -177,21 +97,25 @@ struct osmo_mdns_rfc_question *osmo_mdns_rfc_question_decode(void *ctx, const ui
if (data_len < 6)
return NULL;
/* qname */
ret = talloc_zero(ctx, struct osmo_mdns_rfc_question);
if (!ret)
return NULL;
ret->domain = osmo_mdns_rfc_qname_decode(ret, (const char *)data, qname_len);
if (!ret->domain) {
talloc_free(ret);
return NULL;
}
/* qname */
ret->domain = talloc_size(ret, qname_len - 1);
if (!ret->domain)
goto error;
if (!osmo_apn_to_str(ret->domain, data, qname_len - 1))
goto error;
/* qtype and qclass */
ret->qtype = osmo_load16be(data + qname_len);
ret->qclass = osmo_load16be(data + qname_len + 2);
return ret;
error:
talloc_free(ret);
return NULL;
}
/*
@@ -201,20 +125,17 @@ struct osmo_mdns_rfc_question *osmo_mdns_rfc_question_decode(void *ctx, const ui
/*! Encode one resource record (RFC 1035 4.1.3).
* \param[in] msgb mesage buffer to which the encoded data will be appended.
*/
int osmo_mdns_rfc_record_encode(void *ctx, struct msgb *msg, const struct osmo_mdns_rfc_record *rec)
int osmo_mdns_rfc_record_encode(struct msgb *msg, const struct osmo_mdns_rfc_record *rec)
{
char *name;
size_t name_len;
uint8_t *buf;
size_t buf_len;
/* name */
name = osmo_mdns_rfc_qname_encode(ctx, rec->domain);
if (!name)
buf_len = strlen(rec->domain) + 1;
buf = msgb_put(msg, buf_len);
if (osmo_apn_from_str(buf, buf_len, rec->domain) < 0)
return -EINVAL;
name_len = strlen(name) + 1;
buf = msgb_put(msg, name_len);
memcpy(buf, name, name_len);
talloc_free(name);
msgb_put_u8(msg, 0x00);
/* type, class, ttl, rdlength */
msgb_put_u16(msg, rec->type);
@@ -232,15 +153,26 @@ int osmo_mdns_rfc_record_encode(void *ctx, struct msgb *msg, const struct osmo_m
struct osmo_mdns_rfc_record *osmo_mdns_rfc_record_decode(void *ctx, const uint8_t *data, size_t data_len,
size_t *record_len)
{
struct osmo_mdns_rfc_record *ret = talloc_zero(ctx, struct osmo_mdns_rfc_record);
struct osmo_mdns_rfc_record *ret;
size_t name_len;
/* name */
ret->domain = osmo_mdns_rfc_qname_decode(ret, (const char *)data, data_len - 10);
/* name length: represented as a series of labels, and terminated by a
* label with zero length (RFC 1035 3.3). A label with zero length is a
* NUL byte. */
name_len = strnlen((const char *)data, data_len - 10) + 1;
if (data[name_len])
return NULL;
/* allocate ret + ret->domain */
ret = talloc_zero(ctx, struct osmo_mdns_rfc_record);
if (!ret)
return NULL;
ret->domain = talloc_size(ctx, name_len - 1);
if (!ret->domain)
goto error;
name_len = strlen(ret->domain) + 2;
if (name_len + 10 > data_len)
/* name */
if (!osmo_apn_to_str(ret->domain, data, name_len - 1))
goto error;
/* type, class, ttl, rdlength */
@@ -254,7 +186,7 @@ struct osmo_mdns_rfc_record *osmo_mdns_rfc_record_decode(void *ctx, const uint8_
/* rdata */
ret->rdata = talloc_memdup(ret, data + name_len + 10, ret->rdlength);
if (!ret->rdata)
return NULL;
goto error;
*record_len = name_len + 10 + ret->rdlength;
return ret;

View File

@@ -84,7 +84,7 @@ struct osmo_mdns_sock *osmo_mdns_sock_init(void *ctx, const char *ip, unsigned i
rc = setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, (char*)&iface, sizeof(iface));
if (rc == -1) {
LOGP(DMSLOOKUP, LOGL_ERROR, "osmo_mdns_sock_init: setsockopt: %s\n", strerror(errno));
goto error;
goto error_sock;
}
memcpy(&multicast_req.imr_multiaddr, &((struct sockaddr_in*)(ret->ai->ai_addr))->sin_addr,
sizeof(multicast_req.imr_multiaddr));
@@ -92,7 +92,7 @@ struct osmo_mdns_sock *osmo_mdns_sock_init(void *ctx, const char *ip, unsigned i
rc = setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&multicast_req, sizeof(multicast_req));
if (rc == -1) {
LOGP(DMSLOOKUP, LOGL_ERROR, "osmo_mdns_sock_init: setsockopt: %s\n", strerror(errno));
goto error;
goto error_sock;
}
/* Always allow binding the same IP and port twice. This is needed in OsmoHLR (where the code becomes cleaner by
@@ -102,20 +102,22 @@ struct osmo_mdns_sock *osmo_mdns_sock_init(void *ctx, const char *ip, unsigned i
rc = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&y, sizeof(y));
if (rc == -1) {
LOGP(DMSLOOKUP, LOGL_ERROR, "osmo_mdns_sock_init: setsockopt: %s\n", strerror(errno));
goto error;
goto error_sock;
}
/* Bind and register osmo_fd callback */
rc = bind(sock, ret->ai->ai_addr, ret->ai->ai_addrlen);
if (rc == -1) {
LOGP(DMSLOOKUP, LOGL_ERROR, "osmo_mdns_sock_init: bind: %s\n", strerror(errno));
goto error;
goto error_sock;
}
osmo_fd_setup(&ret->osmo_fd, sock, OSMO_FD_READ, cb, data, priv_nr);
if (osmo_fd_register(&ret->osmo_fd) != 0)
goto error;
goto error_sock;
return ret;
error_sock:
close(sock);
error:
if (ret->ai)
freeaddrinfo(ret->ai);

View File

@@ -205,9 +205,9 @@ size_t osmo_mslookup_result_to_str_buf(char *buf, size_t buflen,
if (result && result->rc == OSMO_MSLOOKUP_RC_NONE)
result = NULL;
if (result) {
if (result->rc != OSMO_MSLOOKUP_RC_RESULT)
if (result->rc != OSMO_MSLOOKUP_RC_RESULT) {
OSMO_STRBUF_PRINTF(sb, " %s", osmo_mslookup_result_code_name(result->rc));
if (result->rc == OSMO_MSLOOKUP_RC_RESULT) {
} else {
if (result->host_v4.ip[0]) {
OSMO_STRBUF_PRINTF(sb, " -> ipv4: " OSMO_SOCKADDR_STR_FMT,
OSMO_SOCKADDR_STR_FMT_ARGS(&result->host_v4));
@@ -260,6 +260,8 @@ static int token(char *dest, size_t dest_size, const char *start, const char *en
/*! Parse a string like "foo.moo.goo.123456789012345.msisdn" into service="foo.moo.goo", id="123456789012345" and
* id_type="msisdn", placed in a struct osmo_mslookup_query.
* \param q Write parsed query to this osmo_mslookup_query.
* \param domain Human readable domain string like "sip.voice.12345678.msisdn".
* \returns 0 on success, negative on error.
*/
int osmo_mslookup_query_init_from_domain_str(struct osmo_mslookup_query *q, const char *domain)

View File

@@ -146,7 +146,7 @@ void osmo_mslookup_client_rx_result(struct osmo_mslookup_client *client, uint32_
if (!req) {
LOGP(DMSLOOKUP, LOGL_ERROR,
"Internal error: Got mslookup result for a request that does not exist (handle %u)\n",
req->request_handle);
request_handle);
return;
}

View File

@@ -114,6 +114,7 @@ static void mdns_method_request(struct osmo_mslookup_client_method *method, cons
if (!msg) {
LOGP(DMSLOOKUP, LOGL_ERROR, "Cannot encode request: %s\n",
osmo_mslookup_result_name_b(buf, sizeof(buf), query, NULL));
return;
}
/* Send over the wire */

View File

@@ -53,7 +53,7 @@ static void print_version(void)
"\n");
}
static void print_help()
static void print_help(void)
{
print_version();
printf(
@@ -315,17 +315,18 @@ int do_send(int argc, char ** argv)
struct msgb *msg = osmo_mdns_result_encode(ctx, 0, &q, &r, cmdline_opts.mdns_domain_suffix);
if (!msg) {
print_error("unable to encode mDNS response\n");
goto exit_cleanup;
goto exit_cleanup_sock;
}
if (osmo_mdns_sock_send(sock, msg)) {
print_error("unable to send mDNS message\n");
goto exit_cleanup;
goto exit_cleanup_sock;
}
rc = 0;
exit_cleanup:
exit_cleanup_sock:
osmo_mdns_sock_cleanup(sock);
exit_cleanup:
talloc_free(ctx);
return rc;
}
@@ -455,6 +456,11 @@ static int socket_read_cb(struct osmo_fd *ofd)
rxbuf[rc] = '\0';
query_with_timeout = strtok(rxbuf, "\r\n");
if (!query_with_timeout) {
print_error("ERROR: failed to read line from socket\n");
goto close;
}
at = strchr(query_with_timeout, '@');
query_str = at ? at + 1 : query_with_timeout;
@@ -481,7 +487,7 @@ static int socket_cb(struct osmo_fd *ofd, unsigned int flags)
{
int rc = 0;
if (flags & BSC_FD_READ)
if (flags & OSMO_FD_READ)
rc = socket_read_cb(ofd);
if (rc < 0)
return rc;
@@ -506,7 +512,7 @@ int socket_accept(struct osmo_fd *ofd, unsigned int flags)
c = talloc_zero(globals.ctx, struct socket_client);
OSMO_ASSERT(c);
c->ofd.fd = rc;
c->ofd.when = BSC_FD_READ;
c->ofd.when = OSMO_FD_READ;
c->ofd.cb = socket_cb;
c->ofd.data = c;
@@ -537,7 +543,7 @@ int socket_init(const char *sock_path)
return -1;
}
ofd->when = BSC_FD_READ;
ofd->when = OSMO_FD_READ;
ofd->cb = socket_accept;
rc = osmo_fd_register(ofd);
@@ -549,7 +555,7 @@ int socket_init(const char *sock_path)
return 0;
}
void socket_close()
void socket_close(void)
{
struct socket_client *c, *n;
llist_for_each_entry_safe(c, n, &globals.socket_clients, entry)
@@ -578,11 +584,11 @@ void respond_result(const char *query_str, const struct osmo_mslookup_result *r)
llist_for_each_entry_safe(c, n, &globals.socket_clients, entry) {
if (!strcmp(query_str, c->query_str)) {
socket_client_respond_result(c, g_buf);
if (r->last)
if (!r || r->last)
socket_client_close(c);
}
}
if (r->last)
if (!r || r->last)
globals.requests_handled++;
}

View File

@@ -49,7 +49,7 @@ static void set_result(struct osmo_mslookup_result *result,
result->age = age;
}
const struct mslookup_service_host *mslookup_server_get_local_gsup_addr()
const struct mslookup_service_host *mslookup_server_get_local_gsup_addr(void)
{
static struct mslookup_service_host gsup_bind = {};
struct mslookup_service_host *host;
@@ -261,6 +261,7 @@ static bool subscriber_has_done_lu_here_hlr(const struct osmo_mslookup_query *qu
if (!subscr->vlr_number[0]) {
LOGP(DMSLOOKUP, LOGL_DEBUG, "%s: not attached (vlr_number unset)\n",
osmo_mslookup_result_name_c(OTC_SELECT, query, NULL));
return false;
}
if (subscr->vlr_via_proxy.len) {

View File

@@ -71,7 +71,7 @@ static int osmo_mslookup_server_mdns_rx(struct osmo_fd *osmo_fd, unsigned int wh
/* Parse the message and print it */
n = read(osmo_fd->fd, buffer, sizeof(buffer));
if (n < 0)
if (n <= 0)
return n;
ctx = talloc_named_const(server, 0, __func__);
@@ -121,7 +121,7 @@ void osmo_mslookup_server_mdns_stop(struct osmo_mslookup_server_mdns *server)
talloc_free(server);
}
void mslookup_server_mdns_config_apply()
void mslookup_server_mdns_config_apply(void)
{
/* Check whether to start/stop/restart mDNS server */
bool should_run;
@@ -148,7 +148,7 @@ void mslookup_server_mdns_config_apply()
g_hlr->mslookup.server.mdns.domain_suffix);
if (!g_hlr->mslookup.server.mdns.running)
LOGP(DMSLOOKUP, LOGL_ERROR, "Failed to start mslookup mDNS server on " OSMO_SOCKADDR_STR_FMT "\n",
OSMO_SOCKADDR_STR_FMT_ARGS(&g_hlr->mslookup.server.mdns.running->bind_addr));
OSMO_SOCKADDR_STR_FMT_ARGS(&g_hlr->mslookup.server.mdns.bind_addr));
else
LOGP(DMSLOOKUP, LOGL_NOTICE, "Started mslookup mDNS server, receiving mDNS requests at multicast "
OSMO_SOCKADDR_STR_FMT "\n",

View File

@@ -29,6 +29,7 @@
#include <osmocom/gsupclient/gsup_client.h>
#include <osmocom/gsupclient/gsup_req.h>
#include <osmocom/hlr/hlr.h>
#include <osmocom/hlr/logging.h>
#include <osmocom/hlr/proxy.h>
#include <osmocom/hlr/remote_hlr.h>
@@ -80,7 +81,19 @@ static void proxy_deferred_gsup_req_add(struct proxy *proxy, struct osmo_gsup_re
static void proxy_pending_req_remote_hlr_connect_result(struct osmo_gsup_req *req, struct remote_hlr *remote_hlr)
{
if (!remote_hlr || !remote_hlr_is_up(remote_hlr)) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_ROAMING_NOTALLOWED, "Proxy: Failed to connect to home HLR");
/* Do not respond with an error to a CHECK_IMEI_REQUEST as osmo-msc will send a LU Reject Cause #6
* Just respond ACK and deal with the IMSI check that comes next. */
if (req->gsup.message_type == OSMO_GSUP_MSGT_CHECK_IMEI_REQUEST) {
/* Accept all IMEIs */
struct osmo_gsup_message gsup_reply = (struct osmo_gsup_message){
.message_type = OSMO_GSUP_MSGT_CHECK_IMEI_RESULT,
.imei_result = OSMO_GSUP_IMEI_RESULT_ACK,
};
osmo_gsup_req_respond(req, &gsup_reply, false, true);
return;
}
osmo_gsup_req_respond_err(req, g_hlr->no_proxy_reject_cause,
"Proxy: Failed to connect to home HLR");
return;
}
@@ -190,6 +203,7 @@ int proxy_subscr_create_or_update(struct proxy *proxy, const struct proxy_subscr
int _proxy_subscr_del(struct proxy_subscr_listentry *e)
{
llist_del(&e->entry);
talloc_free(e);
return 0;
}
@@ -263,10 +277,10 @@ static int proxy_acknowledge_gsup_to_remote_hlr(struct proxy *proxy, const struc
bool cs;
int rc;
if (req->source_name.type != OSMO_GSUP_PEER_ID_IPA_NAME) {
if (req->source_name.type != OSMO_CNI_PEER_ID_IPA_NAME) {
LOG_PROXY_SUBSCR_MSG(proxy_subscr, &req->gsup, LOGL_ERROR,
"Unsupported GSUP peer id type: %s\n",
osmo_gsup_peer_id_type_name(req->source_name.type));
osmo_cni_peer_id_type_name(req->source_name.type));
return -ENOTSUP;
}
@@ -303,7 +317,7 @@ static int proxy_acknowledge_gsup_to_remote_hlr(struct proxy *proxy, const struc
"%s: preliminary VLR name for%s%s to %s\n",
rc ? "failed to update" : "updated",
cs ? " CS" : "", ps ? " PS" : "",
osmo_gsup_peer_id_to_str(&req->source_name));
osmo_cni_peer_id_to_str(&req->source_name));
break;
/* TODO: delete proxy entry in case of a Purge Request? */
default:
@@ -483,13 +497,13 @@ int proxy_subscr_forward_to_remote_hlr(struct proxy *proxy, const struct proxy_s
return 0;
}
if (!osmo_gsup_peer_id_is_empty(&req->via_proxy)) {
if (!osmo_cni_peer_id_is_empty(&req->via_proxy)) {
LOG_PROXY_SUBSCR_MSG(proxy_subscr, &req->gsup, LOGL_INFO, "VLR->HLR: forwarding from %s via proxy %s\n",
osmo_gsup_peer_id_to_str(&req->source_name),
osmo_gsup_peer_id_to_str(&req->via_proxy));
osmo_cni_peer_id_to_str(&req->source_name),
osmo_cni_peer_id_to_str(&req->via_proxy));
} else {
LOG_PROXY_SUBSCR_MSG(proxy_subscr, &req->gsup, LOGL_INFO, "VLR->HLR: forwarding from %s\n",
osmo_gsup_peer_id_to_str(&req->source_name));
osmo_cni_peer_id_to_str(&req->source_name));
}
/* We could always store in the defer queue and empty the queue if the connection is already up.

View File

@@ -233,9 +233,9 @@ void remote_hlr_gsup_forward_to_remote_hlr(struct remote_hlr *remote_hlr, struct
else
forward = req->gsup;
if (req->source_name.type != OSMO_GSUP_PEER_ID_IPA_NAME) {
if (req->source_name.type != OSMO_CNI_PEER_ID_IPA_NAME) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_NET_FAIL, "Unsupported GSUP peer id type: %s",
osmo_gsup_peer_id_type_name(req->source_name.type));
osmo_cni_peer_id_type_name(req->source_name.type));
return;
}
forward.source_name = req->source_name.ipa_name.val;

View File

@@ -1,423 +0,0 @@
#include <osmocom/core/linuxlist.h>
#include <osmocom/gsm/gsm48_ie.h>
#include <osmocom/gsm/gsm23003.h>
#include <osmocom/gsm/gsm0411_utils.h>
#include <osmocom/gsm/protocol/gsm_04_11.h>
#include <osmocom/mslookup/mslookup_client.h>
#include <osmocom/hlr/hlr.h>
#include <osmocom/hlr/remote_hlr.h>
#include <osmocom/hlr/mslookup_server.h>
#include <osmocom/hlr/db.h>
#include <osmocom/hlr/sms_over_gsup.h>
static int sms_extract_destination_msisdn(char *msisdn, size_t msisdn_size, struct osmo_gsup_req *req)
{
int rc;
if (req->gsup.sm_rp_da_type == OSMO_GSUP_SMS_SM_RP_ODA_MSISDN
&& req->gsup.sm_rp_da_len > 0) {
LOG_GSUP_REQ(req, LOGL_INFO, "Extracting destination MSISDN from GSUP SM_RP_DA IE: %s\n",
osmo_hexdump(req->gsup.sm_rp_da, req->gsup.sm_rp_da_len));
rc = gsm48_decode_bcd_number2(msisdn, msisdn_size, req->gsup.sm_rp_da, req->gsup.sm_rp_da_len, 0);
if (!rc)
LOG_GSUP_REQ(req, LOGL_INFO, "success -> %s\n", msisdn);
else
LOG_GSUP_REQ(req, LOGL_ERROR, "fail %d\n", rc);
return rc;
}
/* The DA was not an MSISDN -- get from inside the SMS PDU */
if (req->gsup.sm_rp_ui_len > 3) {
const uint8_t *da = req->gsup.sm_rp_ui + 2;
uint8_t da_len = *da;
uint8_t da_len_bytes;
uint8_t address_lv[12] = {};
da_len_bytes = 2 + da_len/2 + da_len%2;
if (da_len_bytes < 4 || da_len_bytes > 12
|| da_len_bytes > req->gsup.sm_rp_ui_len - 2) {
LOG_GSUP_REQ(req, LOGL_ERROR, "Invalid da_len_bytes %u\n", da_len_bytes);
return -EINVAL;
}
memcpy(address_lv, da, da_len_bytes);
address_lv[0] = da_len_bytes - 1;
LOG_GSUP_REQ(req, LOGL_INFO, "Extracting destination MSISDN from SMS PDU DA: %s\n",
osmo_hexdump(address_lv, da_len_bytes));
rc = gsm48_decode_bcd_number2(msisdn, msisdn_size, address_lv, da_len_bytes, 1);
if (!rc)
LOG_GSUP_REQ(req, LOGL_INFO, "success -> %s\n", msisdn);
else
LOG_GSUP_REQ(req, LOGL_ERROR, "fail %d\n", rc);
return rc;
}
LOG_GSUP_REQ(req, LOGL_ERROR, "fail: no SM_RP_DA nor SMS PDU (sm_rp_ui_len > 3)\n");
return -ENOTSUP;
}
static int sms_extract_sender_msisdn(char *msisdn, size_t msisdn_size, struct osmo_gsup_req *req)
{
int rc;
if (req->gsup.sm_rp_oa_type == OSMO_GSUP_SMS_SM_RP_ODA_MSISDN
&& req->gsup.sm_rp_oa_len > 0) {
LOG_GSUP_REQ(req, LOGL_INFO, "Extracting sender MSISDN from GSUP SM_RP_OA IE: %s\n",
osmo_hexdump(req->gsup.sm_rp_oa, req->gsup.sm_rp_oa_len));
rc = gsm48_decode_bcd_number2(msisdn, msisdn_size, req->gsup.sm_rp_oa, req->gsup.sm_rp_oa_len, 0);
if (!rc)
LOG_GSUP_REQ(req, LOGL_INFO, "success -> %s\n", msisdn);
else
LOG_GSUP_REQ(req, LOGL_ERROR, "fail %d\n", rc);
return rc;
}
LOG_GSUP_REQ(req, LOGL_ERROR, "fail: no MSISDN obtained from SM_RP_OA\n");
return -ENOTSUP;
}
static struct msgb *sms_mo_pdu_to_mt_pdu(const uint8_t *mo_pdu, size_t mo_pdu_len, const char *sender_msisdn)
{
/* Hacky shortened copy-paste of osmo-msc's gsm340_rx_tpdu() */
uint8_t protocol_id;
uint8_t data_coding_scheme;
uint8_t user_data_len;
uint8_t user_data_octet_len;
const uint8_t *user_data;
uint8_t status_rep_req;
uint8_t ud_hdr_ind;
{
const uint8_t *smsp = mo_pdu;
enum sms_alphabet sms_alphabet;
uint8_t sms_vpf;
uint8_t da_len_bytes;
sms_vpf = (*smsp & 0x18) >> 3;
status_rep_req = (*smsp & 0x20) >> 5;
ud_hdr_ind = (*smsp & 0x40);
smsp += 2;
/* length in bytes of the destination address */
da_len_bytes = 2 + *smsp/2 + *smsp%2;
if (da_len_bytes < 4 || da_len_bytes > 12)
return NULL;
smsp += da_len_bytes;
protocol_id = *smsp++;
data_coding_scheme = *smsp++;
sms_alphabet = gsm338_get_sms_alphabet(data_coding_scheme);
if (sms_alphabet == 0xffffffff)
return NULL;
switch (sms_vpf) {
case GSM340_TP_VPF_RELATIVE:
smsp++;
break;
case GSM340_TP_VPF_ABSOLUTE:
case GSM340_TP_VPF_ENHANCED:
/* the additional functionality indicator... */
if (sms_vpf == GSM340_TP_VPF_ENHANCED && *smsp & (1<<7))
smsp++;
smsp += 7;
break;
case GSM340_TP_VPF_NONE:
break;
default:
return NULL;
}
/* As per 3GPP TS 03.40, section 9.2.3.16, TP-User-Data-Length (TP-UDL)
* may indicate either the number of septets, or the number of octets,
* depending on Data Coding Scheme. We store TP-UDL value as-is,
* so this should be kept in mind to avoid buffer overruns. */
user_data_len = *smsp++;
user_data = smsp;
if (user_data_len > 0) {
if (sms_alphabet == DCS_7BIT_DEFAULT) {
/* TP-UDL is indicated in septets (up to 160) */
if (user_data_len > GSM340_UDL_SPT_MAX) {
user_data_len = GSM340_UDL_SPT_MAX;
}
user_data_octet_len = gsm_get_octet_len(user_data_len);
} else {
/* TP-UDL is indicated in octets (up to 140) */
if (user_data_len > GSM340_UDL_OCT_MAX) {
user_data_len = GSM340_UDL_OCT_MAX;
}
user_data_octet_len = user_data_len;
}
}
}
{
/* The following is a hacky copy pasted and shortened version of osmo-msc's gsm340_gen_sms_deliver_tpdu() */
struct msgb *msg = gsm411_msgb_alloc();
uint8_t *smsp;
uint8_t oa[12]; /* max len per 03.40 */
int oa_len;
if (!msg)
return NULL;
/* generate first octet with masked bits */
smsp = msgb_put(msg, 1);
/* TP-MTI (message type indicator) */
*smsp = GSM340_SMS_DELIVER_SC2MS;
/* TP-MMS (more messages to send) */
if (0 /* FIXME */)
*smsp |= 0x04;
/* TP-SRI(deliver)/SRR(submit) */
if (status_rep_req)
*smsp |= 0x20;
/* TP-UDHI (indicating TP-UD contains a header) */
if (ud_hdr_ind)
*smsp |= 0x40;
/* generate originator address */
oa_len = gsm340_gen_oa(oa, sizeof(oa), 0, 0, sender_msisdn);
if (oa_len < 0) {
msgb_free(msg);
return NULL;
}
smsp = msgb_put(msg, oa_len);
memcpy(smsp, oa, oa_len);
/* generate TP-PID */
smsp = msgb_put(msg, 1);
*smsp = protocol_id;
/* generate TP-DCS */
smsp = msgb_put(msg, 1);
*smsp = data_coding_scheme;
/* generate TP-SCTS */
smsp = msgb_put(msg, 7);
gsm340_gen_scts(smsp, time(NULL));
/* generate TP-UDL */
smsp = msgb_put(msg, 1);
*smsp = user_data_len;
smsp = msgb_put(msg, user_data_octet_len);
memcpy(smsp, user_data, user_data_octet_len);
return msg;
}
}
static void sms_recipient_up_cb(const struct osmo_sockaddr_str *addr, struct remote_hlr *remote_hlr, void *data)
{
struct osmo_gsup_req *req = data;
struct osmo_gsup_message modified_gsup = req->gsup;
// struct msgb *mt_pdu = NULL;
if (!remote_hlr) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_MSC_TEMP_NOTREACH,
"Failed to connect to SMS recipient: " OSMO_SOCKADDR_STR_FMT,
OSMO_SOCKADDR_STR_FMT_ARGS(addr));
return;
}
/* We must not send out another MO request, to make sure we don't send the request in an infinite loop. */
#if 0
if (req->gsup.message_type == OSMO_GSUP_MSGT_MO_FORWARD_SM_REQUEST) {
char sender_msisdn[GSM23003_MSISDN_MAX_DIGITS+1];
if (sms_extract_sender_msisdn(sender_msisdn, sizeof(sender_msisdn), req)) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_INV_MAND_INFO, "Cannot find sender MSISDN");
return;
}
mt_pdu = sms_mo_pdu_to_mt_pdu(req->gsup.sm_rp_ui, req->gsup.sm_rp_ui_len, sender_msisdn);
if (!mt_pdu) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_INV_MAND_INFO,
"Cannot translate PDU to a DELIVER PDU");
return;
}
modified_gsup.message_type = OSMO_GSUP_MSGT_MT_FORWARD_SM_REQUEST;
modified_gsup.sm_rp_ui = mt_pdu->data;
modified_gsup.sm_rp_ui_len = mt_pdu->len;
}
#endif
LOG_GSUP_REQ(req, LOGL_INFO, "Forwarding to remote HLR " OSMO_SOCKADDR_STR_FMT "\n",
OSMO_SOCKADDR_STR_FMT_ARGS(&remote_hlr->addr));
remote_hlr_gsup_forward_to_remote_hlr(remote_hlr, req, &modified_gsup);
}
static void sms_over_gsup_mt(struct osmo_gsup_req *req)
{
/* Find a locally connected MSC that knows this MSISDN. */
uint32_t lu_age;
struct osmo_gsup_peer_id local_msc_id;
struct osmo_mslookup_query query = {
.service = OSMO_MSLOOKUP_SERVICE_SMS_GSUP,
.id = {
.type = OSMO_MSLOOKUP_ID_MSISDN,
},
};
struct osmo_gsup_message modified_gsup = req->gsup;
struct msgb *mt_pdu = NULL;
if (sms_extract_destination_msisdn(query.id.msisdn, sizeof(query.id.msisdn), req)) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_INV_MAND_INFO, "invalid MSISDN");
return;
}
LOG_GSUP_REQ(req, LOGL_NOTICE, "SMS to MSISDN: %s\n", query.id.msisdn);
/* If a local attach is found, write the subscriber's IMSI to the modified_gsup buffer */
if (!subscriber_has_done_lu_here(&query, &lu_age, &local_msc_id.ipa_name,
modified_gsup.imsi, sizeof(modified_gsup.imsi))) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_MSC_TEMP_NOTREACH,
"SMS recipient not reachable: %s\n",
osmo_mslookup_result_name_c(OTC_SELECT, &query, NULL));
return;
}
local_msc_id.type = OSMO_GSUP_PEER_ID_IPA_NAME;
/* A local MSC indeed has an active subscription for the recipient. Deliver there. */
if (modified_gsup.message_type == OSMO_GSUP_MSGT_MO_FORWARD_SM_REQUEST) {
/* This is a direct local delivery, and sms_over_gsup_mo_directly_to_mt() just passed the MO request
* altough here we are on the MT side. We must not send out another MO request, to make sure we don't
* send the request in an infinite loop.
* Also patch in the recipient's IMSI.
*/
char sender_msisdn[GSM23003_MSISDN_MAX_DIGITS+1];
if (sms_extract_sender_msisdn(sender_msisdn, sizeof(sender_msisdn), req)) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_INV_MAND_INFO, "Cannot find sender MSISDN");
return;
}
mt_pdu = sms_mo_pdu_to_mt_pdu(req->gsup.sm_rp_ui, req->gsup.sm_rp_ui_len, sender_msisdn);
if (!mt_pdu) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_INV_MAND_INFO,
"Cannot translate PDU to a DELIVER PDU");
return;
}
modified_gsup.message_type = OSMO_GSUP_MSGT_MT_FORWARD_SM_REQUEST;
modified_gsup.sm_rp_ui = mt_pdu->data;
modified_gsup.sm_rp_ui_len = mt_pdu->len;
}
osmo_gsup_forward_to_local_peer(g_hlr->gs, &local_msc_id, req, &modified_gsup);
if (mt_pdu)
msgb_free(mt_pdu);
}
static void resolve_sms_recipient_cb(struct osmo_mslookup_client *client,
uint32_t request_handle,
const struct osmo_mslookup_query *query,
const struct osmo_mslookup_result *result)
{
struct osmo_gsup_req *req = query->priv;
const struct osmo_sockaddr_str *remote_hlr_addr = NULL;
const struct mslookup_service_host *local_gsup;
if (result->rc == OSMO_MSLOOKUP_RC_RESULT) {
if (osmo_sockaddr_str_is_nonzero(&result->host_v4))
remote_hlr_addr = &result->host_v4;
else if (osmo_sockaddr_str_is_nonzero(&result->host_v6))
remote_hlr_addr = &result->host_v6;
}
if (!remote_hlr_addr) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_MSC_TEMP_NOTREACH,
"Failed to resolve SMS recipient: %s\n",
osmo_mslookup_result_name_c(OTC_SELECT, query, result));
return;
}
/* Possibly, this HLR here has responded to itself via mslookup. Don't make a GSUP connection to ourselves,
* instead go directly to the MT path. */
local_gsup = mslookup_server_get_local_gsup_addr();
LOG_GSUP_REQ(req, LOGL_NOTICE, "local_gsup " OSMO_SOCKADDR_STR_FMT " " OSMO_SOCKADDR_STR_FMT
" remote_hlr_addr " OSMO_SOCKADDR_STR_FMT "\n",
OSMO_SOCKADDR_STR_FMT_ARGS(&local_gsup->host_v4),
OSMO_SOCKADDR_STR_FMT_ARGS(&local_gsup->host_v6),
OSMO_SOCKADDR_STR_FMT_ARGS(remote_hlr_addr));
if (local_gsup
&& (!osmo_sockaddr_str_cmp(&local_gsup->host_v4, remote_hlr_addr)
|| !osmo_sockaddr_str_cmp(&local_gsup->host_v6, remote_hlr_addr))) {
sms_over_gsup_mt(req);
return;
}
remote_hlr_get_or_connect(remote_hlr_addr, true, sms_recipient_up_cb, req);
}
static void sms_over_gsup_mo_directly_to_mt(struct osmo_gsup_req *req)
{
/* Figure out the location of the SMS recipient by mslookup */
if (osmo_mslookup_client_active(g_hlr->mslookup.client.client)) {
/* D-GSM is active. Kick off an mslookup for the current location of the MSISDN. */
uint32_t request_handle;
struct osmo_mslookup_query_handling handling = {
.min_wait_milliseconds = g_hlr->mslookup.client.result_timeout_milliseconds,
.result_cb = resolve_sms_recipient_cb,
};
struct osmo_mslookup_query query = {
.id = {
.type = OSMO_MSLOOKUP_ID_MSISDN,
},
.priv = req,
};
if (sms_extract_destination_msisdn(query.id.msisdn, sizeof(query.id.msisdn), req)
|| !osmo_msisdn_str_valid(query.id.msisdn)) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_INV_MAND_INFO, "invalid MSISDN");
return;
}
OSMO_STRLCPY_ARRAY(query.service, OSMO_MSLOOKUP_SERVICE_SMS_GSUP);
request_handle = osmo_mslookup_client_request(g_hlr->mslookup.client.client, &query, &handling);
if (request_handle) {
/* Querying succeeded. Wait for resolve_sms_recipient_cb() to be called. */
return;
}
/* Querying failed. Try whether delivering to a locally connected MSC works out. */
LOG_DGSM(req->gsup.imsi, LOGL_ERROR,
"Error dispatching mslookup query for SMS: %s -- trying local delivery\n",
osmo_mslookup_result_name_c(OTC_SELECT, &query, NULL));
}
/* Attempt direct delivery */
sms_over_gsup_mt(req);
}
static void sms_over_gsup_mo(struct osmo_gsup_req *req)
{
if (!osmo_gsup_peer_id_is_empty(&g_hlr->sms_over_gsup.smsc)) {
/* Forward to SMSC */
/* FIXME actually use branch fixeria/sms for this */
osmo_gsup_forward_to_local_peer(g_hlr->gs, &g_hlr->sms_over_gsup.smsc, req, NULL);
return;
}
if (!g_hlr->sms_over_gsup.try_direct_delivery) {
osmo_gsup_req_respond_err(req, GMM_CAUSE_PROTO_ERR_UNSPEC,
"cannot deliver SMS over GSUP: No SMSC (and direct delivery disabled)");
return;
}
sms_over_gsup_mo_directly_to_mt(req);
}
bool sms_over_gsup_check_handle_msg(struct osmo_gsup_req *req)
{
switch (req->gsup.message_type) {
case OSMO_GSUP_MSGT_MO_FORWARD_SM_REQUEST:
sms_over_gsup_mo(req);
return true;
case OSMO_GSUP_MSGT_MT_FORWARD_SM_REQUEST:
sms_over_gsup_mt(req);
return true;
default:
return false;
}
}

View File

@@ -1,6 +1,5 @@
SUBDIRS = \
auc \
gsup_server \
db \
gsup \
db_upgrade \
@@ -70,6 +69,9 @@ vty-test:
CTRL_TEST_DB = hlr_ctrl_test.db
# Run a specific test with: 'make ctrl-test CTRL_TEST=test_subscriber.ctrl'
CTRL_TEST ?= *.ctrl
# To update the CTRL script from current application behavior,
# pass -u to ctrl_script_runner.py by doing:
# make ctrl-test U=-u
@@ -80,7 +82,7 @@ ctrl-test:
osmo_verify_transcript_ctrl.py -v \
-p 4259 \
-r "$(top_builddir)/src/osmo-hlr -c $(top_srcdir)/doc/examples/osmo-hlr.cfg -l $(CTRL_TEST_DB)" \
$(U) $(srcdir)/*.ctrl
$(U) $(srcdir)/$(CTRL_TEST)
-rm -f $(CTRL_TEST_DB)
-rm $(CTRL_TEST_DB)-*

View File

@@ -23,9 +23,7 @@ EXTRA_DIST = \
auc_ts_55_205_test_sets.err \
$(NULL)
check_PROGRAMS = auc_ts_55_205_test_sets
noinst_PROGRAMS = auc_test
check_PROGRAMS = auc_test auc_ts_55_205_test_sets
auc_test_SOURCES = \
auc_test.c \

View File

@@ -113,6 +113,7 @@ int rand_get(uint8_t *rand, unsigned int len)
return len;
}
/* Subscriber with 2G-only (COMP128v1) authentication data */
static void test_gen_vectors_2g_only(void)
{
struct osmo_sub_auth_data aud2g;
@@ -174,6 +175,8 @@ static void test_gen_vectors_2g_only(void)
comment_end();
}
/* Subscriber with separate 2G (COMP128v1) and 3G (MILENAGE) authentication data,
* reflects the default configuration of sysmoUSIM-SJS1 */
static void test_gen_vectors_2g_plus_3g(void)
{
struct osmo_sub_auth_data aud2g;
@@ -284,6 +287,9 @@ void _test_gen_vectors_3g_only__expect_vecs(struct osmo_auth_vector vecs[3])
);
}
/* Subscriber with only 3G (MILENAGE) authentication data,
* reflects the default configuration of sysmoISIM-SJA2. Resulting
* tuples are suitable for both 2G and 3G authentication */
static void test_gen_vectors_3g_only(void)
{
struct osmo_sub_auth_data aud2g;
@@ -454,7 +460,56 @@ static void test_gen_vectors_3g_only(void)
comment_end();
}
void test_gen_vectors_bad_args()
/* Subscriber with only 3G (XOR) authentication data,
* reflects the default configuration of sysmoTSIM-SJAx as well
* as many "Test USIM" cards. Resulting tuples are suitable for both
* 2G and 3G authentication */
static void test_gen_vectors_3g_xor(void)
{
struct osmo_sub_auth_data aud2g;
struct osmo_sub_auth_data aud3g;
struct osmo_auth_vector vec;
int rc;
comment_start();
aud2g = (struct osmo_sub_auth_data){ 0 };
aud3g = (struct osmo_sub_auth_data){
.type = OSMO_AUTH_TYPE_UMTS,
.algo = OSMO_AUTH_ALG_XOR,
.u.umts.sqn = 0,
};
osmo_hexparse("000102030405060708090a0b0c0d0e0f",
aud3g.u.umts.k, sizeof(aud3g.u.umts.k));
osmo_hexparse("00000000000000000000000000000000",
aud3g.u.umts.opc, sizeof(aud3g.u.umts.opc));
next_rand("b5039c57e4a75051551d1a390a71ce48", true);
vec = (struct osmo_auth_vector){ {0} };
VERBOSE_ASSERT(aud3g.u.umts.sqn, == 0, "%"PRIu64);
rc = auc_compute_vectors(&vec, 1, &aud2g, &aud3g, NULL, NULL);
VERBOSE_ASSERT(rc, == 1, "%d");
VERBOSE_ASSERT(aud3g.u.umts.sqn, == 0, "%"PRIu64);
VEC_IS(&vec,
" rand: b5039c57e4a75051551d1a390a71ce48\n"
" autn: 54e0a256565d0000b5029e54e0a25656\n"
" ck: 029e54e0a256565d141032067cc047b5\n"
" ik: 9e54e0a256565d141032067cc047b502\n"
" res: b5029e54e0a256565d141032067cc047\n"
" res_len: 10\n"
" kc: 98e880384887f9fe\n"
" sres: 0ec81877\n"
" auth_types: 03000000\n"
);
comment_end();
}
/* Test a variety of invalid authentication data combinations */
void test_gen_vectors_bad_args(void)
{
struct osmo_auth_vector vec;
uint8_t auts[14];
@@ -613,15 +668,20 @@ int main(int argc, char **argv)
void *tall_ctx = talloc_named_const(NULL, 1, "auc_test");
osmo_init_logging2(tall_ctx, &hlr_log_info);
log_set_print_filename(osmo_stderr_target, cmdline_opts.verbose);
log_set_print_filename2(osmo_stderr_target,
cmdline_opts.verbose ?
LOG_FILENAME_BASENAME :
LOG_FILENAME_NONE);
log_set_print_timestamp(osmo_stderr_target, 0);
log_set_use_color(osmo_stderr_target, 0);
log_set_print_category_hex(osmo_stderr_target, 0);
log_set_print_category(osmo_stderr_target, 1);
log_parse_category_mask(osmo_stderr_target, "DMAIN,1:DDB,1:DAUC,1");
test_gen_vectors_2g_only();
test_gen_vectors_2g_plus_3g();
test_gen_vectors_3g_only();
test_gen_vectors_3g_xor();
test_gen_vectors_bad_args();
printf("Done\n");

View File

@@ -217,6 +217,29 @@ DAUC vector [2]: auth_types = 0x3
===== test_gen_vectors_3g_only: SUCCESS
===== test_gen_vectors_3g_xor
aud3g.u.umts.sqn == 0
DAUC Computing 1 auth vector: 3G only (2G derived from 3G keys)
DAUC 3G: k = 000102030405060708090a0b0c0d0e0f
DAUC 3G: opc = 00000000000000000000000000000000
DAUC 3G: for sqn ind 0, previous sqn was 0
DAUC vector [0]: rand = b5039c57e4a75051551d1a390a71ce48
DAUC vector [0]: sqn = 0
DAUC vector [0]: autn = 54e0a256565d0000b5029e54e0a25656
DAUC vector [0]: ck = 029e54e0a256565d141032067cc047b5
DAUC vector [0]: ik = 9e54e0a256565d141032067cc047b502
DAUC vector [0]: res = b5029e54e0a256565d141032067cc047
DAUC vector [0]: res_len = 16
DAUC vector [0]: deriving 2G from 3G
DAUC vector [0]: kc = 98e880384887f9fe
DAUC vector [0]: sres = 0ec81877
DAUC vector [0]: auth_types = 0x3
rc == 1
aud3g.u.umts.sqn == 0
vector matches expectations
===== test_gen_vectors_3g_xor: SUCCESS
===== test_gen_vectors_bad_args
- no auth data (a)

View File

@@ -100,15 +100,16 @@ int rand_get(uint8_t *rand, unsigned int len)
FUNCTIONS
int main()
int main(int argc, char **argv)
{
printf("3GPP TS 55.205 Test Sets\n");
void *tall_ctx = talloc_named_const(NULL, 1, "test");
msgb_talloc_ctx_init(tall_ctx, 0);
osmo_init_logging2(tall_ctx, &hlr_log_info);
log_set_print_filename(osmo_stderr_target, 0);
log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
log_set_print_timestamp(osmo_stderr_target, 0);
log_set_use_color(osmo_stderr_target, 0);
log_set_print_category_hex(osmo_stderr_target, 0);
log_set_print_category(osmo_stderr_target, 1);
log_parse_category_mask(osmo_stderr_target, "DMAIN,1:DDB,1:DAUC,1");

View File

@@ -30,7 +30,7 @@ db_test_LDADD = \
$(top_builddir)/src/db_auc.o \
$(top_builddir)/src/db_hlr.o \
$(top_builddir)/src/db.o \
$(top_builddir)/src/gsup_peer_id.o \
$(top_builddir)/src/cni_peer_id.o \
$(LIBOSMOCORE_LIBS) \
$(LIBOSMOGSM_LIBS) \
$(LIBOSMOABIS_LIBS) \

View File

@@ -27,7 +27,7 @@
#include <osmocom/core/utils.h>
#include <osmocom/core/logging.h>
#include <osmocom/gsupclient/gsup_peer_id.h>
#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/hlr/db.h>
#include <osmocom/hlr/logging.h>
@@ -173,8 +173,6 @@ void dump_subscr(struct hlr_subscriber *subscr)
Pfo(lmsi, "0x%x", subscr);
Pb(true, ms_purged_cs);
Pb(true, ms_purged_ps);
Ps(last_lu_rat_cs);
Ps(last_lu_rat_ps);
fprintf(stderr, "}\n");
#undef Ps
#undef Pd
@@ -245,10 +243,10 @@ static int db_subscr_lu_str(struct db_context *dbc, int64_t subscr_id,
{
struct osmo_ipa_name vlr_nr;
osmo_ipa_name_set_str(&vlr_nr, vlr_or_sgsn_number);
return db_subscr_lu(dbc, subscr_id, &vlr_nr, is_ps, NULL, NULL, 0);
return db_subscr_lu(dbc, subscr_id, &vlr_nr, is_ps, NULL);
}
static void test_subscr_create_update_sel_delete()
static void test_subscr_create_update_sel_delete(void)
{
int64_t id0, id1, id2, id_short;
comment_start();
@@ -264,13 +262,13 @@ static void test_subscr_create_update_sel_delete()
ASSERT_RC(db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), 0);
ASSERT_SEL(imsi, imsi2, 0);
id2 = g_subscr.id;
ASSERT_RC(db_subscr_create(dbc, imsi0, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EIO);
ASSERT_RC(db_subscr_create(dbc, imsi0, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EEXIST);
ASSERT_SEL(imsi, imsi0, 0);
ASSERT_RC(db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EIO);
ASSERT_RC(db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EIO);
ASSERT_RC(db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EEXIST);
ASSERT_RC(db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EEXIST);
ASSERT_SEL(imsi, imsi1, 0);
ASSERT_RC(db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EIO);
ASSERT_RC(db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EIO);
ASSERT_RC(db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EEXIST);
ASSERT_RC(db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EEXIST);
ASSERT_SEL(imsi, imsi2, 0);
ASSERT_RC(db_subscr_create(dbc, "123456789 000003", DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS), -EINVAL);
@@ -543,7 +541,7 @@ static const struct sub_auth_data_str *mk_aud_3g(enum osmo_auth_algo algo,
return &aud;
}
static void test_subscr_aud()
static void test_subscr_aud(void)
{
int64_t id;
@@ -785,7 +783,7 @@ static void test_subscr_aud()
/* Make each key too short in this test. Note that we can't set them longer than the allowed size without changing the
* table structure. */
static void test_subscr_aud_invalid_len()
static void test_subscr_aud_invalid_len(void)
{
int64_t id;
@@ -847,7 +845,7 @@ static void test_subscr_aud_invalid_len()
comment_end();
}
static void test_subscr_sqn()
static void test_subscr_sqn(void)
{
int64_t id;
@@ -920,22 +918,22 @@ static void test_subscr_sqn()
comment_end();
}
static void test_ind()
static void test_ind(void)
{
comment_start();
#define ASSERT_IND(VLR, IND) do { \
unsigned int ind; \
struct osmo_gsup_peer_id vlr; \
OSMO_ASSERT(!osmo_gsup_peer_id_set_str(&vlr, OSMO_GSUP_PEER_ID_IPA_NAME, VLR)); \
struct osmo_cni_peer_id vlr; \
OSMO_ASSERT(!osmo_cni_peer_id_set_str(&vlr, OSMO_CNI_PEER_ID_IPA_NAME, VLR)); \
ASSERT_RC(db_ind(dbc, &vlr, &ind), 0); \
fprintf(stderr, "%s ind = %u\n\n", osmo_quote_str((char*)vlr.ipa_name.val, vlr.ipa_name.len), ind); \
if (ind != (IND)) \
fprintf(stderr, " ERROR: expected " #IND "\n"); \
} while (0)
#define IND_DEL(VLR) do { \
struct osmo_gsup_peer_id vlr; \
OSMO_ASSERT(!osmo_gsup_peer_id_set_str(&vlr, OSMO_GSUP_PEER_ID_IPA_NAME, VLR)); \
struct osmo_cni_peer_id vlr; \
OSMO_ASSERT(!osmo_cni_peer_id_set_str(&vlr, OSMO_CNI_PEER_ID_IPA_NAME, VLR)); \
ASSERT_RC(db_ind_del(dbc, &vlr), 0); \
fprintf(stderr, "%s ind deleted\n\n", osmo_quote_str((char*)vlr.ipa_name.val, vlr.ipa_name.len)); \
} while (0)
@@ -1026,9 +1024,13 @@ int main(int argc, char **argv)
handle_options(argc, argv);
osmo_init_logging2(ctx, &hlr_log_info);
log_set_print_filename(osmo_stderr_target, cmdline_opts.verbose);
log_set_print_filename2(osmo_stderr_target,
cmdline_opts.verbose ?
LOG_FILENAME_BASENAME :
LOG_FILENAME_NONE);
log_set_print_timestamp(osmo_stderr_target, 0);
log_set_use_color(osmo_stderr_target, 0);
log_set_print_category_hex(osmo_stderr_target, 0);
log_set_print_category(osmo_stderr_target, 1);
log_parse_category_mask(osmo_stderr_target, "DMAIN,1:DDB,1:DAUC,1");

View File

@@ -27,7 +27,7 @@ struct hlr_subscriber {
.imsi = '123456789000002',
}
db_subscr_create(dbc, imsi0, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EIO
db_subscr_create(dbc, imsi0, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EEXIST
DAUC IMSI='123456789000000': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
@@ -36,10 +36,10 @@ struct hlr_subscriber {
.imsi = '123456789000000',
}
db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EIO
db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EEXIST
DAUC IMSI='123456789000001': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EIO
db_subscr_create(dbc, imsi1, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EEXIST
DAUC IMSI='123456789000001': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
db_subscr_get_by_imsi(dbc, imsi1, &g_subscr) --> 0
@@ -48,10 +48,10 @@ struct hlr_subscriber {
.imsi = '123456789000001',
}
db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EIO
db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EEXIST
DAUC IMSI='123456789000002': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EIO
db_subscr_create(dbc, imsi2, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS) --> -EEXIST
DAUC IMSI='123456789000002': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
db_subscr_get_by_imsi(dbc, imsi2, &g_subscr) --> 0

View File

@@ -4,9 +4,6 @@ OsmoHLR# subscriber imsi 123456789012345 create
ID: 1
IMSI: 123456789012345
MSISDN: none
GERAN-A: allowed
UTRAN-Iu: allowed
EUTRAN-SGs: allowed
OsmoHLR# subscriber imsi 123456789012345 update msisdn 098765432109876
% Updated subscriber IMSI='123456789012345' to MSISDN='098765432109876'
OsmoHLR# subscriber imsi 123456789012345 update aud2g comp128v1 ki BeefedCafeFaceAcedAddedDecadeFee
@@ -16,17 +13,11 @@ OsmoHLR# subscriber imsi 111111111 create
ID: 2
IMSI: 111111111
MSISDN: none
GERAN-A: allowed
UTRAN-Iu: allowed
EUTRAN-SGs: allowed
OsmoHLR# subscriber imsi 222222222 create
% Created subscriber 222222222
ID: 3
IMSI: 222222222
MSISDN: none
GERAN-A: allowed
UTRAN-Iu: allowed
EUTRAN-SGs: allowed
OsmoHLR# subscriber imsi 222222222 update msisdn 22222
% Updated subscriber IMSI='222222222' to MSISDN='22222'
OsmoHLR# subscriber imsi 333333 create
@@ -34,9 +25,6 @@ OsmoHLR# subscriber imsi 333333 create
ID: 4
IMSI: 333333
MSISDN: none
GERAN-A: allowed
UTRAN-Iu: allowed
EUTRAN-SGs: allowed
OsmoHLR# subscriber imsi 333333 update msisdn 3
% Updated subscriber IMSI='333333' to MSISDN='3'
OsmoHLR# subscriber imsi 333333 update aud2g comp128v2 ki 33333333333333333333333333333333
@@ -45,9 +33,6 @@ OsmoHLR# subscriber imsi 444444444444444 create
ID: 5
IMSI: 444444444444444
MSISDN: none
GERAN-A: allowed
UTRAN-Iu: allowed
EUTRAN-SGs: allowed
OsmoHLR# subscriber imsi 444444444444444 update msisdn 4444
% Updated subscriber IMSI='444444444444444' to MSISDN='4444'
OsmoHLR# subscriber imsi 444444444444444 update aud3g milenage k 44444444444444444444444444444444 op 44444444444444444444444444444444
@@ -56,9 +41,6 @@ OsmoHLR# subscriber imsi 5555555 create
ID: 6
IMSI: 5555555
MSISDN: none
GERAN-A: allowed
UTRAN-Iu: allowed
EUTRAN-SGs: allowed
OsmoHLR# subscriber imsi 5555555 update msisdn 55555555555555
% Updated subscriber IMSI='5555555' to MSISDN='55555555555555'
OsmoHLR# subscriber imsi 5555555 update aud2g xor ki 55555555555555555555555555555555

View File

@@ -86,8 +86,6 @@ DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 3
DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 4
DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 5
DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 6
DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 7
DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 8
DMAIN Cmdline option --db-check: Database was opened successfully, quitting.
Resulting db:
@@ -135,8 +133,6 @@ id|INTEGER|0||1
imei|VARCHAR(14)|0||0
imeisv|VARCHAR|0||0
imsi|VARCHAR(15)|1||0
last_lu_rat_cs|TEXT|0|NULL|0
last_lu_rat_ps|TEXT|0|NULL|0
last_lu_seen|TIMESTAMP|0|NULL|0
last_lu_seen_ps|TIMESTAMP|0|NULL|0
lmsi|INTEGER|0||0
@@ -156,13 +152,13 @@ vlr_number|VARCHAR(15)|0||0
vlr_via_proxy|VARCHAR|0||0
Table subscriber contents:
ggsn_number|gmlc_number|id|imei|imeisv|imsi|last_lu_rat_cs|last_lu_rat_ps|last_lu_seen|last_lu_seen_ps|lmsi|ms_purged_cs|ms_purged_ps|msc_number|msisdn|nam_cs|nam_ps|periodic_lu_tmr|periodic_rau_tau_tmr|sgsn_address|sgsn_number|sgsn_via_proxy|smsc_number|vlr_number|vlr_via_proxy
||1|||123456789012345||||||0|0||098765432109876|1|1|||||||MSC-1|
||2|||111111111||||||1|0|||1|1||||||||
||3|||222222222||||||0|1||22222|1|1||||||||
||4|||333333||||||0|0||3|0|1||||||||
||5|||444444444444444||||||0|0||4444|1|0||||||||
||6|||5555555||||||0|0||55555555555555|0|0||||||||
ggsn_number|gmlc_number|id|imei|imeisv|imsi|last_lu_seen|last_lu_seen_ps|lmsi|ms_purged_cs|ms_purged_ps|msc_number|msisdn|nam_cs|nam_ps|periodic_lu_tmr|periodic_rau_tau_tmr|sgsn_address|sgsn_number|sgsn_via_proxy|smsc_number|vlr_number|vlr_via_proxy
||1|||123456789012345||||0|0||098765432109876|1|1|||||||MSC-1|
||2|||111111111||||1|0|||1|1||||||||
||3|||222222222||||0|1||22222|1|1||||||||
||4|||333333||||0|0||3|0|1||||||||
||5|||444444444444444||||0|0||4444|1|0||||||||
||6|||5555555||||0|0||55555555555555|0|0||||||||
Table: subscriber_apn
name|type|notnull|dflt_value|pk
@@ -178,18 +174,10 @@ subscriber_id|INTEGER|0||0
Table subscriber_multi_msisdn contents:
Table: subscriber_rat
name|type|notnull|dflt_value|pk
allowed|BOOLEAN|1|0|0
rat|TEXT|1||0
subscriber_id|INTEGER|0||0
Table subscriber_rat contents:
Verify that osmo-hlr can open it:
osmo-hlr --database $db --db-check --config-file $srcdir/osmo-hlr.cfg
rc = 0
DMAIN hlr starting
DDB using database: <PATH>test.db
DDB Database <PATH>test.db' has HLR DB schema version 8
DDB Database <PATH>test.db' has HLR DB schema version 6
DMAIN Cmdline option --db-check: Database was opened successfully, quitting.

View File

@@ -17,7 +17,7 @@ EXTRA_DIST = \
gsup_test.err \
$(NULL)
noinst_PROGRAMS = \
check_PROGRAMS = \
gsup_test \
$(NULL)

View File

@@ -101,7 +101,7 @@ int main(int argc, char **argv)
{
ctx = talloc_named_const(NULL, 0, "gsup_test");
osmo_init_logging2(ctx, &info);
log_set_print_filename(osmo_stderr_target, 0);
log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
log_set_print_timestamp(osmo_stderr_target, 0);
log_set_use_color(osmo_stderr_target, 0);
log_set_print_category(osmo_stderr_target, 1);

View File

@@ -1,44 +0,0 @@
AM_CPPFLAGS = \
$(all_includes) \
$(NULL)
AM_CFLAGS = \
-Wall \
-ggdb3 \
-I$(top_srcdir)/include \
$(LIBOSMOCORE_CFLAGS) \
$(LIBOSMOGSM_CFLAGS) \
$(LIBOSMOABIS_CFLAGS) \
$(NULL)
AM_LDFLAGS = \
-no-install \
$(NULL)
EXTRA_DIST = \
gsup_server_test.ok \
gsup_server_test.err \
$(NULL)
noinst_PROGRAMS = \
gsup_server_test \
$(NULL)
gsup_server_test_SOURCES = \
gsup_server_test.c \
$(NULL)
gsup_server_test_LDADD = \
$(top_srcdir)/src/gsup_server.c \
$(top_srcdir)/src/gsup_router.c \
$(top_srcdir)/src/gsup_send.c \
$(top_srcdir)/src/gsupclient/gsup_peer_id.c \
$(top_srcdir)/src/gsupclient/gsup_req.c \
$(LIBOSMOCORE_LIBS) \
$(LIBOSMOGSM_LIBS) \
$(LIBOSMOABIS_LIBS) \
$(NULL)
.PHONY: update_exp
update_exp:
$(builddir)/gsup_server_test >"$(srcdir)/gsup_server_test.ok" 2>"$(srcdir)/gsup_server_test.err"

View File

@@ -1,145 +0,0 @@
/* (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
* All Rights Reserved
*
* Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdio.h>
#include <osmocom/core/utils.h>
#include <osmocom/hlr/gsup_server.h>
#define comment_start() printf("\n===== %s\n", __func__)
#define comment_end() printf("===== %s: SUCCESS\n\n", __func__)
#define btw(fmt, args...) printf("\n" fmt "\n", ## args)
#define VERBOSE_ASSERT(val, expect_op, fmt) \
do { \
printf(#val " == " fmt "\n", (val)); \
OSMO_ASSERT((val) expect_op); \
} while (0)
void osmo_gsup_server_add_conn(struct llist_head *clients,
struct osmo_gsup_conn *conn);
static void test_add_conn(void)
{
struct llist_head _list;
struct llist_head *clients = &_list;
struct osmo_gsup_conn conn_inst[23] = {};
struct osmo_gsup_conn *conn;
unsigned int i;
comment_start();
INIT_LLIST_HEAD(clients);
btw("Add 10 items");
for (i = 0; i < 10; i++) {
osmo_gsup_server_add_conn(clients, &conn_inst[i]);
printf("conn_inst[%u].auc_3g_ind == %u\n", i, conn_inst[i].auc_3g_ind);
OSMO_ASSERT(clients->next == &conn_inst[0].list);
}
btw("Expecting a list of 0..9");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
OSMO_ASSERT(conn->auc_3g_ind == i);
OSMO_ASSERT(conn == &conn_inst[i]);
i++;
}
btw("Punch two holes in the sequence in arbitrary order,"
" a larger one from 2..4 and a single one at 7.");
llist_del(&conn_inst[4].list);
llist_del(&conn_inst[2].list);
llist_del(&conn_inst[3].list);
llist_del(&conn_inst[7].list);
btw("Expecting a list of 0,1, 5,6, 8,9");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
i++;
}
btw("Add conns, expecting them to take the open slots");
osmo_gsup_server_add_conn(clients, &conn_inst[12]);
VERBOSE_ASSERT(conn_inst[12].auc_3g_ind, == 2, "%u");
osmo_gsup_server_add_conn(clients, &conn_inst[13]);
VERBOSE_ASSERT(conn_inst[13].auc_3g_ind, == 3, "%u");
osmo_gsup_server_add_conn(clients, &conn_inst[14]);
VERBOSE_ASSERT(conn_inst[14].auc_3g_ind, == 4, "%u");
osmo_gsup_server_add_conn(clients, &conn_inst[17]);
VERBOSE_ASSERT(conn_inst[17].auc_3g_ind, == 7, "%u");
osmo_gsup_server_add_conn(clients, &conn_inst[18]);
VERBOSE_ASSERT(conn_inst[18].auc_3g_ind, == 10, "%u");
btw("Expecting a list of 0..10");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
OSMO_ASSERT(conn->auc_3g_ind == i);
i++;
}
btw("Does it also work for the first item?");
llist_del(&conn_inst[0].list);
btw("Expecting a list of 1..10");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
OSMO_ASSERT(conn->auc_3g_ind == i + 1);
i++;
}
btw("Add another conn, should take auc_3g_ind == 0");
osmo_gsup_server_add_conn(clients, &conn_inst[20]);
VERBOSE_ASSERT(conn_inst[20].auc_3g_ind, == 0, "%u");
btw("Expecting a list of 0..10");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
OSMO_ASSERT(conn->auc_3g_ind == i);
i++;
}
btw("If a client reconnects, it will (likely) get the same auc_3g_ind");
VERBOSE_ASSERT(conn_inst[5].auc_3g_ind, == 5, "%u");
llist_del(&conn_inst[5].list);
conn_inst[5].auc_3g_ind = 423;
osmo_gsup_server_add_conn(clients, &conn_inst[5]);
VERBOSE_ASSERT(conn_inst[5].auc_3g_ind, == 5, "%u");
comment_end();
}
int main(int argc, char **argv)
{
printf("test_gsup_server.c\n");
test_add_conn();
printf("Done\n");
return 0;
}

View File

@@ -1,94 +0,0 @@
test_gsup_server.c
===== test_add_conn
Add 10 items
conn_inst[0].auc_3g_ind == 0
conn_inst[1].auc_3g_ind == 1
conn_inst[2].auc_3g_ind == 2
conn_inst[3].auc_3g_ind == 3
conn_inst[4].auc_3g_ind == 4
conn_inst[5].auc_3g_ind == 5
conn_inst[6].auc_3g_ind == 6
conn_inst[7].auc_3g_ind == 7
conn_inst[8].auc_3g_ind == 8
conn_inst[9].auc_3g_ind == 9
Expecting a list of 0..9
conn[0].auc_3g_ind == 0
conn[1].auc_3g_ind == 1
conn[2].auc_3g_ind == 2
conn[3].auc_3g_ind == 3
conn[4].auc_3g_ind == 4
conn[5].auc_3g_ind == 5
conn[6].auc_3g_ind == 6
conn[7].auc_3g_ind == 7
conn[8].auc_3g_ind == 8
conn[9].auc_3g_ind == 9
Punch two holes in the sequence in arbitrary order, a larger one from 2..4 and a single one at 7.
Expecting a list of 0,1, 5,6, 8,9
conn[0].auc_3g_ind == 0
conn[1].auc_3g_ind == 1
conn[2].auc_3g_ind == 5
conn[3].auc_3g_ind == 6
conn[4].auc_3g_ind == 8
conn[5].auc_3g_ind == 9
Add conns, expecting them to take the open slots
conn_inst[12].auc_3g_ind == 2
conn_inst[13].auc_3g_ind == 3
conn_inst[14].auc_3g_ind == 4
conn_inst[17].auc_3g_ind == 7
conn_inst[18].auc_3g_ind == 10
Expecting a list of 0..10
conn[0].auc_3g_ind == 0
conn[1].auc_3g_ind == 1
conn[2].auc_3g_ind == 2
conn[3].auc_3g_ind == 3
conn[4].auc_3g_ind == 4
conn[5].auc_3g_ind == 5
conn[6].auc_3g_ind == 6
conn[7].auc_3g_ind == 7
conn[8].auc_3g_ind == 8
conn[9].auc_3g_ind == 9
conn[10].auc_3g_ind == 10
Does it also work for the first item?
Expecting a list of 1..10
conn[0].auc_3g_ind == 1
conn[1].auc_3g_ind == 2
conn[2].auc_3g_ind == 3
conn[3].auc_3g_ind == 4
conn[4].auc_3g_ind == 5
conn[5].auc_3g_ind == 6
conn[6].auc_3g_ind == 7
conn[7].auc_3g_ind == 8
conn[8].auc_3g_ind == 9
conn[9].auc_3g_ind == 10
Add another conn, should take auc_3g_ind == 0
conn_inst[20].auc_3g_ind == 0
Expecting a list of 0..10
conn[0].auc_3g_ind == 0
conn[1].auc_3g_ind == 1
conn[2].auc_3g_ind == 2
conn[3].auc_3g_ind == 3
conn[4].auc_3g_ind == 4
conn[5].auc_3g_ind == 5
conn[6].auc_3g_ind == 6
conn[7].auc_3g_ind == 7
conn[8].auc_3g_ind == 8
conn[9].auc_3g_ind == 9
conn[10].auc_3g_ind == 10
If a client reconnects, it will (likely) get the same auc_3g_ind
conn_inst[5].auc_3g_ind == 5
conn_inst[5].auc_3g_ind == 5
===== test_add_conn: SUCCESS
Done

View File

@@ -24,7 +24,6 @@ EXTRA_DIST = \
check_PROGRAMS = \
mdns_test \
mslookup_client_mdns_test \
mslookup_client_test \
mslookup_test \
$(NULL)
@@ -45,14 +44,6 @@ mslookup_client_test_LDADD = \
$(LIBOSMOGSM_LIBS) \
$(NULL)
mslookup_client_mdns_test_SOURCES = \
mslookup_client_mdns_test.c \
$(NULL)
mslookup_client_mdns_test_LDADD = \
$(top_builddir)/src/mslookup/libosmo-mslookup.la \
$(LIBOSMOGSM_LIBS) \
$(NULL)
mdns_test_SOURCES = \
mdns_test.c \
$(NULL)
@@ -61,6 +52,18 @@ mdns_test_LDADD = \
$(LIBOSMOGSM_LIBS) \
$(NULL)
if ENABLE_MSLOOKUP_CLIENT_MDNS_TEST
check_PROGRAMS += mslookup_client_mdns_test
mslookup_client_mdns_test_SOURCES = \
mslookup_client_mdns_test.c \
$(NULL)
mslookup_client_mdns_test_LDADD = \
$(top_builddir)/src/mslookup/libosmo-mslookup.la \
$(LIBOSMOGSM_LIBS) \
$(NULL)
endif
.PHONY: update_exp
update_exp:
for i in $(check_PROGRAMS); do \

View File

@@ -32,148 +32,6 @@ struct qname_enc_dec_test {
size_t qname_max_len; /* default: strlen(qname) + 1 */
};
static const struct qname_enc_dec_test qname_enc_dec_test_data[] = {
{
/* OK: typical mslookup domain */
.domain = "hlr.1234567.imsi",
.qname = "\x03" "hlr" "\x07" "1234567" "\x04" "imsi",
},
{
/* Wrong format: double dot */
.domain = "hlr..imsi",
.qname = NULL,
},
{
/* Wrong format: double dot */
.domain = "hlr",
.qname = "\x03hlr\0\x03imsi",
},
{
/* Wrong format: dot at end */
.domain = "hlr.",
.qname = NULL,
},
{
/* Wrong format: dot at start */
.domain = ".hlr",
.qname = NULL,
},
{
/* Wrong format: empty */
.domain = "",
.qname = NULL,
},
{
/* OK: maximum length */
.domain =
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"12345"
,
.qname =
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\x05" "12345"
},
{
/* Error: too long domain */
.domain =
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"123456789." "123456789." "123456789." "123456789." "123456789."
"12345toolong"
,
.qname = NULL,
},
{
/* Error: too long qname */
.domain = NULL,
.qname =
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
"\t123456789\t123456789\t123456789\t123456789\t123456789"
},
{
/* Error: wrong token length in qname */
.domain = NULL,
.qname = "\x03" "hlr" "\x07" "1234567" "\x05" "imsi",
},
{
/* Error: wrong token length in qname */
.domain = NULL,
.qname = "\x02" "hlr" "\x07" "1234567" "\x04" "imsi",
},
{
/* Wrong format: token length at end of qname */
.domain = NULL,
.qname = "\x03hlr\x03",
},
{
/* Error: overflow in label length */
.domain = NULL,
.qname = "\x03" "hlr" "\x07" "1234567" "\x04" "imsi",
.qname_max_len = 17,
},
};
void test_enc_dec_rfc_qname(void *ctx)
{
char quote_buf[300];
int i;
fprintf(stderr, "-- %s --\n", __func__);
for (i = 0; i < ARRAY_SIZE(qname_enc_dec_test_data); i++) {
const struct qname_enc_dec_test *t = &qname_enc_dec_test_data[i];
char *res;
if (t->domain) {
fprintf(stderr, "domain: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), t->domain, -1));
fprintf(stderr, "exp: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), t->qname, -1));
res = osmo_mdns_rfc_qname_encode(ctx, t->domain);
fprintf(stderr, "res: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), res, -1));
if (t->qname == res || (t->qname && res && strcmp(t->qname, res) == 0))
fprintf(stderr, "=> OK\n");
else
fprintf(stderr, "=> ERROR\n");
if (res)
talloc_free(res);
fprintf(stderr, "\n");
}
if (t->qname) {
size_t qname_max_len = t->qname_max_len;
if (qname_max_len)
fprintf(stderr, "qname_max_len: %lu\n", qname_max_len);
else
qname_max_len = strlen(t->qname) + 1;
fprintf(stderr, "qname: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), t->qname, -1));
fprintf(stderr, "exp: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), t->domain, -1));
res = osmo_mdns_rfc_qname_decode(ctx, t->qname, qname_max_len);
fprintf(stderr, "res: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), res, -1));
if (t->domain == res || (t->domain && res && strcmp(t->domain, res) == 0))
fprintf(stderr, "=> OK\n");
else
fprintf(stderr, "=> ERROR\n");
if (res)
talloc_free(res);
fprintf(stderr, "\n");
}
}
}
#define PRINT_HDR(hdr, name) \
fprintf(stderr, "header %s:\n" \
".id = %i\n" \
@@ -216,7 +74,7 @@ static const struct osmo_mdns_rfc_header header_enc_dec_test_data[] = {
},
};
void test_enc_dec_rfc_header()
void test_enc_dec_rfc_header(void)
{
int i;
@@ -241,7 +99,7 @@ void test_enc_dec_rfc_header()
}
}
void test_enc_dec_rfc_header_einval()
void test_enc_dec_rfc_header_einval(void)
{
struct osmo_mdns_rfc_header out = {0};
struct msgb *msg = msgb_alloc(4096, "dns_test");
@@ -289,7 +147,7 @@ void test_enc_dec_rfc_question(void *ctx)
struct msgb *msg = msgb_alloc(4096, "dns_test");
PRINT_QST(&in, "in");
assert(osmo_mdns_rfc_question_encode(ctx, msg, &in) == 0);
assert(osmo_mdns_rfc_question_encode(msg, &in) == 0);
fprintf(stderr, "encoded: %s\n", osmo_hexdump(msgb_data(msg), msgb_length(msg)));
out = osmo_mdns_rfc_question_decode(ctx, msgb_data(msg), msgb_length(msg));
assert(out);
@@ -353,7 +211,7 @@ void test_enc_dec_rfc_record(void *ctx)
size_t record_len;
PRINT_REC(&in, "in");
assert(osmo_mdns_rfc_record_encode(ctx, msg, &in) == 0);
assert(osmo_mdns_rfc_record_encode(msg, &in) == 0);
fprintf(stderr, "encoded: %s\n", osmo_hexdump(msgb_data(msg), msgb_length(msg)));
out = osmo_mdns_rfc_record_decode(ctx, msgb_data(msg), msgb_length(msg), &record_len);
fprintf(stderr, "record_len: %lu\n", record_len);
@@ -578,18 +436,17 @@ static void test_result_from_answer(void *ctx)
}
}
int main()
int main(int argc, char **argv)
{
void *ctx = talloc_named_const(NULL, 0, "main");
osmo_init_logging2(ctx, NULL);
log_set_print_filename(osmo_stderr_target, 0);
log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
log_set_print_level(osmo_stderr_target, 1);
log_set_print_category(osmo_stderr_target, 1);
log_set_print_category_hex(osmo_stderr_target, 0);
log_set_use_color(osmo_stderr_target, 0);
test_enc_dec_rfc_qname(ctx);
test_enc_dec_rfc_header();
test_enc_dec_rfc_header_einval();
test_enc_dec_rfc_question(ctx);

Some files were not shown because too many files have changed in this diff Show More