Commit Graph

434 Commits

Author SHA1 Message Date
Harald Welte db736f432a implement unit tests for osmo_sccp_addr_{parse,encode}()
The recent bug with chopped-off point codes in SCCP Address handling
has shown that this code could need proper test cases.  This patch
adds a testsuite for SCCP address encoding and decoding.

Related: OS#2441
Change-Id: I612352736ab33462ca0dd97798a2c437eadccb86
2017-10-27 18:00:12 +02:00
Harald Welte 212d0c4c76 osmo_sccp_addr_encode(): Catch some more errors and log them
Log errors in case the user provides global title indicators or
nature-of-address indicators that exceed the permitted value range

Change-Id: I493b7810bdc58e448f496565ded36f9dce2c1226
2017-10-27 18:00:12 +02:00
Harald Welte c755c1d1b0 osmo_sccp_addr_encode(): Fix truncation of point codes
In osmo_sccp_addr_encode(), we accidentially truncated all point
codes to 10 bits, where in reality we should have truncated them to
14 bits: One 'f' was missing in the bit-mask.

Closes: OS#2441
Change-Id: Iad67b674b5b5fd41996aa898a131e98900842dd8
2017-10-27 14:36:26 +00:00
Harald Welte 4e1dfa8677 osmo_sccp_addr_encode(): Check for more erroneous situations
... and bail out + log an error.

Change-Id: I2a419343e55edad39c59e763d11046c5a439444d
2017-10-27 14:36:26 +00:00
Neels Hofmeyr a8929fdb56 sccp_scrc: fix Network Indicator in SIO composition
Since the NI is in bits DC, not BA, it needs to be shifted by 6, not 4, to end
up in the two most significant bits. Also, NI is two bits wide, hence & 0x3.
(The m3ua.c side of this is already correct.)

See ITU-T Recommendation Q.704 (07/96), 14.2 "Service information octet".

Before this patch, NI was always sent as 00 == International regardless of the
VTY configuration.

This patch was verified to work by a wireshark trace of osmo-bsc connecting to
osmo-msc, showing the NI decoded as configured by an osmo-bsc.cfg file in the
BSSMAP Reset message MTP 3 / Protocol data.

Change-Id: I7bb4eb6518a1e0d74313bda776d2a6acd0b02e1b
2017-10-26 17:34:28 +02:00
Max 793cf8a259 Add doxygen docs
Make sure doxygen generates library documentation by default (can be
disabled at compile time).

Change-Id: I2bf7438bcdde19dc88b9bc14c8ad9c8f49099f8a
Related: OS#2572
2017-10-18 10:42:52 +02:00
Harald Welte d966b0fd06 Makefile.am: Link libosmo-sigtran against libvty
libosmo-sigtran is using symbols from libosmo-vty, so make sure that
we explicitly link against libosmo-vty to ensure the dependency shows
up in `ldd` of the library.

Change-Id: I4d96612a0df5a1232ed8fe280c5d592f462ef7b1
2017-10-04 11:40:51 +08:00
Pau Espin 54fa75b85c contrib: Add osmo-stp systemd service file
Change-Id: If6423222b5f1574701c48b5e93eb6c4918879d6c
2017-09-27 12:04:54 +02:00
Philipp Maier ba57d31b35 simple client: prevent overwriting asp settings
If the user does not create an AS, but creates an ASP with a name
that is equal to the default name, then the simple client detects
that and trys to use this ASP. However, unfortunately it then
overwrites the settings of the ASP with the default settings.

If the detected ASP is not created by the simple client, use it,
but preseve the settings of that ASP.

Change-Id: I53d73059f804c3bbea6cb43dc73ad49a753b3b15
2017-09-14 13:53:32 +02:00
Neels Hofmeyr 3488cf5b85 vty: add 'asp' / 'local-ip' command
We can set the ASP's remote IP (i.e. where to reach osmo-stp), but so far the
only way to specify the local IP address to bind to can only be set from C code
(e.g. the simple client). Allow setting the local address via VTY.

For example, this is desired for the osmo-gsm-tester, to not use arbitrary IP
addresses.

Change-Id: I3f71897dfacafcf3126e51894d6ca756b02dcd7d
2017-09-11 01:46:32 +02:00
Harald Welte 769e9354ab sccp_sap.h: Fix SSN for BSSAP and BSSAP-LE
* BSSAP is 254 on both MSC and BSC side: Add missing define
* BSSAP-LE (LCS Extension) has 250/251, adjust name to add -LE suffix

Change-Id: Iccec75cfc0cf16bd717a9bd4606d1e772c332ccc
2017-09-03 21:20:32 +02:00
Harald Welte d8552d7011 osmo-stp: Fix process termination on SIGINT+SIGTERM
In commit eed8c1bfae we introduced
some singal handling code for (among others) SIGINT and SIGTERM.

This code causes the process to hang rather than terminate, as it
only dispatches a signal that nobody handles yet in libosmo-sccp.

Until a proper implementation is made, let's terminate the process
as expected.

Change-Id: Iff79c8ac0b347660333912c9258073a013ea799b
2017-08-31 20:25:52 +02:00
Max 02e029708a Use release helper from libosmocore
See
https://osmocom.org/projects/cellular-infrastructure/wiki/Make_a_new_release
for details.

Change-Id: I39b3bfa8a1ccf376215a3ce220cb3cf7a85471cb
Related: OS#1861
2017-08-29 12:48:21 +00:00
Neels Hofmeyr 6d46ac8951 cosmetic: aggressively set vty->index to NULL in osmo_ss7_vty_go_parent()
Change-Id: I579482f679cd43edfbe796a5806ef360335f1c55
2017-08-28 19:06:43 +02:00
Max 72dd761fe1 Use value string check from osmo-ci
Change-Id: I1a2223b1a059fbb832948decf11f9237fad389f2
2017-08-26 06:10:29 +00:00
Philipp Maier 4d8cccc650 sccp: again fix handling of default IP addresses in osmo_sccp_simple_client()
The previous fix (I312caf9d54cedb02034e4ef88fdd2e6ad9ca1c34) caused the default
addresses to be discarded. Actually talloc_strdup() the default addresses to
use them if not NULL.

Change-Id: Ic8563ab272d5256a1b8ceefd5fee37da61e1bd26
2017-08-24 19:07:27 +00:00
Neels Hofmeyr 56384469e9 osmo_ss7_vty: fix 'as' / 'routing-key' command
The VTY definition for this command is flawed and breaks osmo-msc VTY tests.

The small problem is a stray '}' in the definition, the bigger problem is that
square brackets indicating optional arguments must not enclose more than one
argument.

Split up the command in several separate definitions with si arg, with ssn arg,
with both, and with neither.

If si and/or ssn are not passed, set them to zero.

See https://lists.osmocom.org/pipermail/openbsc/2017-August/011026.html
"optional vty items are stricter than expected"

Change-Id: Idc68bfae5457960a9eae5d9648586d6ce719ad68
2017-08-23 03:22:03 +02:00
Neels Hofmeyr 18db4ad72d vty: fix doc for 'xua rkm routing-key-allocation'
A doc element is missing, which fails the VTY tests in osmo-msc at Change-Id
I5ae4e05ee7c57cad341ea5e86af37c1f6b0ffa77.

Change-Id: I16aa74244ed5332bdc1fddd538e17b86f62ec3b2
2017-08-22 14:45:50 +02:00
Harald Welte eed8c1bfae OsmoSTP: Install our default set of signal handlers
Change-Id: Id5e37dc35923fd689e2cecd9923154774efd7f51
2017-08-20 20:57:09 +02:00
Harald Welte 485a1be9d8 Fix SCCP client crash on xUA server (STP) disconnect
When the server (STP) disappears from a live SCCP client,
then the xUA default layer manager receives LM_E_SCTP_DISC_IND,
which is traversing retart_asp().  In there, we first terminate
the current instance of the layer manager FSM, and then re-initialize
the ASP to use the default layer manager using
osmo_ss7_asp_use_default_lm().

However, osmo_ss7_asp_use_default_lm() uses the presence of an
asp->lm_priv pointer as a sign that the old layer manager is still
running and attempts to terminate it - despite being terminated
just before in restart_as().

So let's simply remove the termination from restart_asp(), and
leave it to osmo_ss7_asp_use_default_lm().

Fixes: OS#2402
Change-Id: I062d3af17539de864b56d079fe9b8d76ad99cf1e
2017-08-15 23:30:10 +02:00
Philipp Maier 52d1ee9617 vty: fix (null) string in vty config
The asp->cfg.remote.host is allowed to be NULL in cases where the
localhost is used.

Check if asp->cfg.remote.host is NULL when writing the config file
and omit it when it is set to NULL.

Change-Id: I18f79cc4d4f1db8f2858e8e95098c5821d50594f
2017-08-15 10:45:34 +02:00
Philipp Maier 3219e52dcf sccp: fixup for osmo_sccp_get_ss7()
osmo_sccp_get_ss7() has the risk of a nullpointer dereference, when
sccp is NULL.

Return NULL when the sccp instance is NULL.

Add doxygen comment

Change-Id: I84d484e4441fd37443fff8c67e17df8fb15d5b2e
2017-08-11 17:49:38 +02:00
Philipp Maier c34bcd42e4 sccp: function to get sccp instance from sccp user
It is currently impossible to find out which SCCP instance handles
a particular user.

Introduce function to lookup the SCCP instance from a given SCCP
user.

Change-Id: I9562c4f1d00e2ebb3252c5dea598b643aa393719
2017-08-11 17:42:35 +02:00
Philipp Maier 564ff61800 sccp: make osmo_sccp_addr_name() available
osmo_sccp_addr_name() is not listed in any header file.

Add osmo_sccp_addr_name() to sccp_helpers.h in order to make
it available.

Change-Id: I092dd55948faeeff78f28f7d50c5b84b9e69ef24
2017-08-11 14:31:35 +02:00
Philipp Maier f0d67969ad sccp: add doxgen comments for osmo_sccp_simple_client()
Some of the functons in sccp_user.c have already
doygen comments on them.

Add doxygen comments for the simple client functions as well

Change-Id: I9143bdc54d729f9f50e69fe38cd1798e065f2497
2017-08-11 12:22:00 +02:00
Philipp Maier d40d19d014 sccp: check for valid point code in osmo_sccp_simple_client()
The point-code is not checked in the beginning, only the ASP
checks the point code at a very late stage and fails in case
an invalid point-code is detected.

Remove the check in the ASP creation.

Add a new check after the SS7 initalization that checks the
point-code. If none is set, the default point-code will be
used.

Change-Id: I334d90e769bd9952f67c51b12a945f22bd268fa8
2017-08-11 11:54:12 +02:00
Philipp Maier eafa10dd17 sccp: fix handling of default IP addresses in osmo_sccp_simple_client()
When the default IP addresses (remote or local) the respective
struct value should be set to NULL.

Fix wrong ?:-notation.

Change-Id: I312caf9d54cedb02034e4ef88fdd2e6ad9ca1c34
2017-08-11 11:30:26 +02:00
Philipp Maier 130c680854 sccp: prefix default parameters of osmo_sccp_simple_client()
The simple client takes certain parameters (pc, ip and port
numbers) which serve as a fallback default in case the user
did not configure any suitable parameters via the VTY.

Prefix all default variables with default_ to make the
purpose clear to the API user

Change-Id: Id9e697e8b198e4f58a79e59aaf2e649e84a3eb63
2017-08-10 18:14:53 +02:00
Neels Hofmeyr ba12716882 safer osmo_sccp_make_addr_pc_ssn(): clear all values
Make sure that all values of the resulting sccp_addr are cleared to obtain a
clean PC+SSN address. Before this, gt and ip remained unset/random, e.g. in
osmo_sccp_tx_unitdata_ranap()

Change-Id: I37395169d364050e45e99793c495a9848a4f8601
2017-08-09 20:41:57 +00:00
Philipp Maier 50a40f9218 vty: hide SG commands when running as ASP
The SG (signal gateway) requires an extra set of VTY commands in
order to be fully configurable. These VTY commands do not make
sense in a situation where libosmo-sccp is used to implement an
ASP (application server process).

Detect in which role libosmo-sccp is used by which of the VTY
initalization functions are called:

osmo_ss7_vty_init_asp() ==> ASP
osmo_ss7_vty_init_sg() ==> SG

Prevent writing back of SG specific configuration when in
running as ASP. Only write back the full parameter set when
running as SG.

Change-Id: I707bcd790f4c6d0f618e41163b51d2179ea3aeaf
2017-08-09 19:01:27 +02:00
Philipp Maier bb8329e91c sccp: fix creating of the default route in simple client
The simple client (osmo_sccp_simple_client_on_ss7_id() and
osmo_sccp_simple_client) does not create a default route if
the user has already created an AS via VTY.

Check the presence of a default route independently of the
AS. If no default route exists, create one.

Change-Id: I7516fa5509bade4ba10e9d8eaa3e46cfe3696b3a
2017-08-09 19:01:22 +02:00
Neels Hofmeyr 9d1a3f6645 cosmetic: ws in log
Change-Id: If5a56ec170d4e91ce070f6fa9c9cfe5bbc121186
2017-08-09 13:54:44 +02:00
Neels Hofmeyr 2373f2778a sccp_helpers: check buf len in append_to_buf()
Change-Id: I2e6d656871f952be8e719573fedf2154832841d7
2017-08-09 13:54:44 +02:00
Neels Hofmeyr e634a6f325 sccp-addr vty: set RI to SSN_PC when setting a point-code
Change-Id: I75c67d289693f1c2a049ac61cf2b2097d6e5687d
2017-08-09 13:54:44 +02:00
Neels Hofmeyr 037d46abc1 fix osmo_sccp_addr_dump(): actually print RI
Adjust xua_test accordingly.

Change-Id: I93e0aa706867e7b1de7f7a6071e3c8af89772af0
2017-08-09 13:54:44 +02:00
Neels Hofmeyr 603e065f43 add osmo_sccp_addr_name() and three value_string[]s
osmo_sccp_addr_dump() just prints the raw values. In osmo_sccp_addr_name(), use
osmo_ss7_pointcode_print() and newly added RI, SSN and GT value_string[] to
print more human readable log output.

Change-Id: Ie1aedd7894acd69ddc887cd65a8a0df4b888838c
2017-08-09 13:54:44 +02:00
Neels Hofmeyr c881c49127 introduce OSMO_SCCP_RI_NONE to indicate unset RI
Allows to automatically set an RI in future change
I75c67d289693f1c2a049ac61cf2b2097d6e5687d
"sccp-addr vty: set RI to SSN_PC when setting a point-code"

Change-Id: I6e2f31b023b08cba2f2ee8234e6108efcaca41c0
2017-08-09 13:54:44 +02:00
Neels Hofmeyr 775ac6f6b1 constify ss7_instance arg of osmo_ss7_pointcode_print()
Change-Id: I8c6b7188d004033e75e9c41f4a65c418d13a79c5
2017-08-09 13:54:44 +02:00
Neels Hofmeyr a212398f7c consistency: use OSMO_SS7_PC_INVALID for osmo_sccp_user
A previous patch added ss7_instance primary_pc validity checks by means of
OSMO_SS7_PC_INVALID. To be consistent, also adjust sccp_user accordingly.
(see I7f0f0c89b7335d9da24161bfac8234be214ca00c)

Remove the osmo_sccp_user's pc_valid field, replaced by pc=OSMO_SS7_PC_INVALID.
Adjust all code paths.

Simplify some log printing, using the fact that osmo_ss7_pointcode_print() now
outputs "(no PC)" for unset point codes.

Change-Id: I8684c9b559712072c772012890bbf7efa7c8eb35
2017-08-09 13:54:44 +02:00
Neels Hofmeyr b352ca030d ensure valid primary_pc in osmo_ss7_instance
Initialize osmo_ss7_instance.cfg.primary_pc = OSMO_SS7_PC_INVALID.
Adjust all code paths using primary_pc to ensure it is indeed valid.

Rationale:

It looks like we are going to use the primary point-code of an SS7 instance to
derive a local SCCP address, e.g. for osmo-bsc and osmo-hnbgw.

 cs7-instance 1
  point-code 1.2.3   ! sets osmo_ss7_instance.primary_pc = 1.2.3
  sccp-address msc
   point-code 0.0.1
   routing-indicator PC

 hnb
  iucs
   remote-addr msc   ! derives cs7 instance 1 and local pc 1.2.3

If 'point-code 1.2.3' is omitted, this becomes '0.0.0' without the user
noticing, and this happens for each client that omits it. I would like to barf
when no local PC is set.

Change-Id: I7f0f0c89b7335d9da24161bfac8234be214ca00c
2017-08-09 13:54:44 +02:00
Neels Hofmeyr b711e14504 add OSMO_SS7_PC_INVALID, add osmo_ss7_pc_is_valid()
Introduce OSMO_SS7_PC_INVALID to mark an unset point code.

Add static osmo_ss7_pc_is_valid() (name matches schema of
osmo_ss7_pc_is_local()).

In osmo_ss7_pointcode_print(), return "(no PC)" if !osmo_ss7_pc_is_valid(), for
convenient printing of any PC state.

Subsequent patches will use this for
osmo_ss7_instance (I7f0f0c89b7335d9da24161bfac8234be214ca00c)
as well as osmo_sccp_user (I8684c9b559712072c772012890bbf7efa7c8eb35).

Rationale:

Currently, in osmo_ss7_vty.c we had "if (inst->cfg.primary_pc)" suggesting 0 is
invalid, but in struct osmo_sccp_user we have flag pc_valid suggesting 0 is
indeed valid. All known point code formats are <= 24bit, so we can easily use
0xffffffff as indicator for an unset PC, which removes the need to remember to
set a second field for validity and keeps the structs nice and lean.

Change-Id: Ib5715bf03a4de7713a7a809dfd821c700255ba8c
2017-08-09 13:53:26 +02:00
Philipp Maier 81a029a4e4 sccp: add function to check sccp addresses
In order to catch invalid CS7 configurations, It is necessary
to check if sccp addresses contain plausible address data.

Change-Id: Ic6245288b0171eae10aa708403c1ddb584c92f38
2017-08-09 09:53:35 +00:00
Neels Hofmeyr 41b6803fd5 osmo_ss7_vty_init: ensure a talloc ctx is set by user
Drop the separate osmo_ss7_set_vty_alloc_ctx() because we are likely to forget
calling it. Instead, incorporate into osmo_ss7_vty_init_*() with a new ctx arg,
and set the static context var in vty_init_shared().

Change-Id: Id4e7f47979001f7856b0b3665c9e94982e75e490
2017-08-07 16:04:39 +02:00
Neels Hofmeyr 473048d0d2 add osmo_sccp_addr_set_ssn()
Will be used by e.g. osmo-hnbgw to add an SSN to addresses obtained from the
sccp address book.

Change-Id: I85b46269dbe7909e52873ace3f720f6292a4516c
2017-08-07 16:04:39 +02:00
Philipp Maier 882f340b6c sccp: derive local address from given sccp instance
The most important parts of an SCCP address are the routing
indicator and the pointcode. The latter one is always available
via the SS7 instance, so a basic local address can be derived
from there.

Add function osmo_sccp_local_addr_by_instance() to derive a basic
local SCCP address from a given SCCP instance

Change-Id: I371dc9132871aad3d8321ea13cf9fd69d76eff8f
2017-08-01 11:08:05 +00:00
Installation Owner 738756984f sccp: fix possible nullpointer deref
check input parameters local_ip and remote_ip of the function
osmo_sccp_simple_client_on_ss7_id() before using them with
talloc_strdup()

Change-Id: I1a5dd1ea3167513bf9e7ae153f83e1ae3136c905
2017-07-31 11:56:03 +02:00
Philipp Maier b06c887cf0 sccp: ensure addressbook entry names are unique
It is possible to add two (or more) different
sccp-addresses under the same name, when the
addresses are defined in different cs7 instances.

Add a check to make sure an address name is not
used multiple times

Change-Id: I63227cd87bc24f7d9ac995430b869f0393818335
2017-07-26 15:14:49 +00:00
Philipp Maier dcb360a9db xua: fix possible memory leak in seems osmo_ss7_asp_use_default_lm()
The function seems osmo_ss7_asp_use_default_lm() does not guard
against an asp->lm_priv FSM instance already existing. If this
function is called a second time, it will overwrite asp->lm_priv,
causing the original fsm instance to leaked.

Check if asp->lm_priv already exists and terminate (free) the
FSM if present.

Change-Id: I4ad435c042a435c4e641c6e5c53b91265dd23d40
2017-07-22 09:08:13 +00:00
Philipp Maier dae7491c14 sccp: make simple client configurable via VTY
The osmo_sccp_simple_client_on_ss7_id and osmo_sccp_simple_client
are not entirely configurable via VTY commands. The relation to
the VTY is implicit. The user may set up instance objects via
VTY (cs7/ss7, AS, ASP), which are then automatically created on
startup.

Each cs7 instance gets its own ID via the VTY configuration. When
osmo_sccp_simple_client_on_ss7_id() is called with the cs7 instance
id. (for osmo_sccp_simple_client() the ID will be hardcoded to 1),
the function automatically checks if the CS7 instance is present,
if not it will create one automatically using the caller supplied
parameters as a defult. If a CS7 instance is present, the function
checks for the presence of an AS and an ASP. These objects are
present, they will be used. If not, new objects will be created.

Both functions must not be called if an SCCP instance is already
present. Since there can only be one SCCP instance per CS7 instance,
this is an error condition.

Add additional logic that checks to detect an already existing, valid
configuration. If no or an insufficient configuration is detected,
use the caller supplied parameters as default configuration.

Change-Id: I293f3526ce6182dca74a169a23449dbc7af57c7c
2017-07-22 09:08:13 +00:00
Philipp Maier 9fc351de69 sccp: global addressbook search + api fix
The sccp-addressbook only allows defining addresses for a specific
ss7 instance. It is not possible to use an sscp-address, that is
defined in the one ss7 instance in another ss7 instance.

Add a second global list where all sscp-addresses are added,
regardless on which instance they are defined.

Fixup the search functions so that they always search the global
list.

Change the API, so that the address data is written to a
destination pointer. This protects the stored address from
unintentional changes. Also return the ss7 instance, where the
address is associated with.

Change-Id: I5acc1e5abc3b3081149a9f476038e4e53d23b763
2017-07-20 12:38:37 +02:00