Commit Graph

244 Commits

Author SHA1 Message Date
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
Philipp Maier 2b74a5fdc0 cosmetic: remove comment
The vty command string already says it all, remove the comment entirely.

Change-Id: I8ecad584a1bc9b97693b199abd1ec2e5f6ce156d
2017-07-20 10:40:31 +02:00
Philipp Maier 6823dd9f44 vty: make addressbook available for _sg and _asp
The installation of the vty commands for the sccp addressbook is
currently located in osmo_ss7_vty_init_sg(), which is normally
only used in signalling gateway applications. An ASP would lack
the addressbook functionality.

Make SCCP addressbook available for both SG and ASP

Change-Id: Ib49ab623055e9ada7f95e0163ba7e33c5f6f99cb
2017-07-19 12:08:18 +00:00
Pau Espin eebbec23a5 sccp_scoc: Fix compilation warning and leave a pragma message
Following warning was being printed:
warning: statement will never be executed [-Wswitch-unreachable]

The code in there seems not to be finished, so better leave the code and a
pragma message to get notified when we compile.

Change-Id: I4e2c482803954c984cb6792b11b4ea0fe674e269
2017-07-08 10:46:31 +00:00
Pau Espin 698045d205 sccp_scoc: Fix trailing whitespace
Change-Id: Ia93bb7d59e4e2c31b693e2c3424d34386762d02e
2017-07-08 10:46:31 +00:00
Philipp Maier 4f30f785c8 vty: Check returncode of osmo_ss7_pointcode_parse()
The result of osmo_ss7_pointcode_parse() is currently not
checked. This means that -EINVAL could end up as value
in the pointcode configuration.

Check the return code of osmo_ss7_pointcode_parse() and
exit the VTY command with CMD_WARNING if the returned
pointcode is < 0

Change-Id: Iae6d92b1d135063dfd0a26bc23a89802cb3b1a78
2017-07-07 10:11:35 +02:00
Philipp Maier cbb7b79e19 simple-client/server: be able to decide on which ss7 instance to bind
osmo_sccp_simple_client() and osmo_sccp_simple_server() are binding
on the ss7 instance with the id 1 by default. If the instance does
not exist, it is created automatically.

Allow choosing the ss7 instance by supplying the id number as
function parameter. Add two new functions:

osmo_sccp_simple_client_on_ss7_id()
osmo_sccp_simple_server_on_ss7_id()

Change-Id: I62e608253212415bddbb4c7dcf5d3b5e79c8d28e
2017-07-05 13:41:28 +02:00
Neels Hofmeyr 81c0bcab06 Revert "SCOC: When sending a CORE/CR, SUA SRC_ADDR == CallingPartyAddress"
This reverts commit 5527df78ad.

I tried some time to figure out what other changes are needed to make this
commit work and fix a confusion, until I noticed:

The commit's *log message* is correct that SRC == calling, but the *patch*
modifies callED addr to be the SRC, which is wrong. So reverting this commit is
indeed the correct way to fix our addresses.

Change-Id: Ic76aacc81f87f8885fe04121aead5c79a761ef07
2017-06-27 21:25:03 +00:00
Neels Hofmeyr 38d2aabd4a sccp_user.c: add missing error logging
Change-Id: I98e400e297f8fa83037a8e74a936e4ecc137099c
2017-06-25 22:35:05 +02:00
Neels Hofmeyr c5b26c9959 gen_mtp_transfer_req_xua(): add addr to error log for missing DPC
Change-Id: Icfd45bcbecc440b94893db2aca537a162f210abd
2017-06-25 22:35:05 +02:00
Neels Hofmeyr 3468d5dce4 add/tweak various logging to help figure out complex routing
Add function osmo_ss7_point_code_print2() to be able to print two point codes
in the same log message.

Change signatures of two static functions to aid logging:
add invalid ref arg to sccp_scoc_rx_inval_src_ref(),
pass conn instead of inst to sccp_scoc_rx_inval_opc().

Change-Id: Ia3243606d6cad7721f7da7f6caba2caa90ae2bbd
2017-06-25 22:35:01 +02:00
Philipp Maier 4248838327 ss7: Fix compilation error (warning)
In osmo_ss7_route_create() as is only initalized if lset can not
be initalized. If lset can be initalized, as will not be used so
everything is fine. However, the compiler complains that as may
not be initalized. Initalizing as to NULL solves the problem.

Change-Id: Ibcb3ebf9aaa7717cb553242517abce1499bc9c2a
2017-06-22 22:47:45 +00:00
Pau Espin ad7fbd9b4d xua_internal.h: Add missing functions required by xua_test
Change-Id: Ic97de20c567bf67c513a45060e1e96e4b67b2311
2017-06-22 06:23:04 +00:00
Pau Espin b1510a1122 sccp_scrc: Fix warning: uneeded constant evaulation
translate function is always present in the same file, thus we can
remove this check.

Fixes following warning:
warning: the address of ‘translate’ will always evaluate as ‘true’ [-Waddress]
    if (translate &&

As requested by Harald, leave a comment there stating that there are some
checks missing and yet to be implemented. The translate function check
was used for this purpose.

Change-Id: I48a711f3a43496e2c0c637f34f56784f765938c4
2017-06-22 06:23:04 +00:00
Philipp Maier 34cb3c16a5 sccp: add addressbook functionality for sccp addresses
SCCP addresses are defined through a number of compoinents, not
just an IP-Address, there is also point code, ssn and more. To
simplify and unify the handling of such objects, this patch
introduces an addressbook functionality. The user can set up
multiple addresses per ss7 instance and give them names. Later
that name can be used to reference the address at a later point
in the config. This means that the usage of sccp-addresses from
the programmers point of view boils down to a VTY function that
reads the string name of a previously defined address. The
programmer can then use the API to get a pointer to the SCCP
address struct and use it normally.

For this feature, two additional VTY nodes are necessary,
this commit depends libosmocore change:
Change-Id I42aa29c0cccc97f284b85801c5329b015b189640

Change-Id: I068ed7f7d113dab88424a9d47bab7fc703bb7942
2017-06-21 18:02:05 +02:00
Philipp Maier b781b371fc cosmetic: fix typo in osmo_ss7_vty.c VTY doc
Change-Id: I931ccf6f765d4fe916ea94bde704314561e4537c
2017-06-18 02:03:25 +00:00
Harald Welte 872c6b2a8e SUA-to-SCCP: Fix use of Called/Calling vs. Src/Dest Address
SUA uses different semantics (source / destination) address, while SCCP
uses Calling/CalledParty. This leads to some confusion.  At least in the
CR/CORE and CREF/COREF case, the CallingParty equals the SRC_ADDR.

Change-Id: I1c641aac7b53c6de7c4e369aaf3004523bd85936
2017-05-04 09:07:21 +02:00
Harald Welte 5527df78ad SCOC: When sending a CORE/CR, SUA SRC_ADDR == CallingPartyAddress
SUA uses different semantics (source / destination) address, while SCCP
uses Calling/CalledParty. This leads to some confusion.  At least in the
CR/CORE case, the CallingParty equals the SRC_ADDR.

Change-Id: I5a3c27b112148dd539f092cce7618b4f62fde73c
2017-05-04 09:07:21 +02:00
Harald Welte b354652502 osmo_sccp_addr_parse() Fix point code integer precision handling
"(cur[1] << 8) & 0x3f" is always 0 regardless of the values of its
operands.

Change-Id: Ie47e632f4bca490baf4282dc5d55ee55ca7f1ae8
Fixes: coverity CID#166932
2017-04-27 12:31:01 +02:00
Harald Welte fa3325fb8b osmo_ss7_user_unregister(): Don't dereference NULL user
The 'user' argument to osmo_ss7_user_unregister() can be NULL, so let's
make sure we don't dereference it.

Change-Id: Ia34b181dcbcb179b2639e2f405364cc952069842
Fixes: coverity CID#166933
2017-04-27 12:24:38 +02:00
Harald Welte 982c0ce337 sccp_scoc: don't pass variable as argument if we know it's NULL
xua will always be NULL in one particular switch case of
scoc_fsm_conn_pend_out(), so let's use NULL directly rather than obscure
it though a variable that might be understood as this being non-NULL in
some cases.

Change-Id: Id6dc56442441489aefc706bcebc49197ca3dae1e
Fixes: coverity CID#166934
2017-04-27 12:17:20 +02:00
Harald Welte b30b011e34 m3ua_decode_notify(): Ensure status_ie is valid before using it
Change-Id: I3cdd0fbdffcbeeb68dbc979385de045220ea0b0c
Fixes: coverity CID#166939
2017-04-27 12:11:24 +02:00
Harald Welte 6fa1933178 sclc_rx_cldr(): Don't try to dereference user data_ie without check
While the SUA / SCCP2SUA code is ensuring that mandatory information
elements such as the user data IE in a CLD$ message, we might still have
current or future callers of sclc_rx_cldr() that don't comply with that.
So let's make sure data_ie is valid before dereferencing it.

Change-Id: I7c1010b0ac82ee0b7bd5e2c7413899695eae0070
Fixes: coverity CID#166940
2017-04-27 12:09:29 +02:00
Harald Welte 023d4f962b m3ua_to_xfer_ind(): don't use data_ie without checking it exists
Change-Id: I5f7551e49c1b4ea417bee3516da1b2ece5ee0699
Fixes: coverity CID#166941
2017-04-27 12:06:23 +02:00
Harald Welte 36a0ca83ab sclc_rx_cldt(): Don't try to dereference user data_ie without check
While the SUA / SCCP2SUA code is ensuring that mandatory information
elements such as the user data IE in a CLDT message, we might still have
current or future callers of sclc_rx_cldt() that don't comply with that.
So let's make sure data_ie is valid before dereferencing it.

Change-Id: Ia102f6c4cd5c6c3f823cb219635c42b9a87765f8
Fixes: coverity CID#166942
2017-04-27 12:02:47 +02:00
Harald Welte 8a1f5a72db scu_gen_encode_and_send(): Fix NULL pointer deref
We were using the 'xua' pointer before checkin if it actually is valid

Change-Id: I5cd3250afc0b787b78683cd8ab6b2512e0d5c69e
Fixes: coverity CID#166945
2017-04-27 11:52:43 +02:00
Harald Welte 48c72f1f5c deliver_to_mtp_user(): Fix null pointer dereference
We had used + derefernced the 'prim' pointer before checking its
validity.

Change-Id: I0ca5026091e91926924b297f9342bda5f9fd38c9
Fixes: coverity CID#166946
2017-04-27 11:50:51 +02:00
Harald Welte 4c880a02f4 osmo_sccp_user_sap_down(): Avoid uninitialized pointer deref
When receiving an unknown primitive, we end up de-referencing an
unassigned/uninitialized pointer for 'conn'.  Let's properly catch that
case and print an error message.

Change-Id: Id1f5f293ea9bce8601d45164be670a7062d91802
Fixes: coverity CID#166947
2017-04-27 11:48:15 +02:00
Harald Welte 48c720bffc sccp_user: Add missing 'break' statement
The missing break statement leads to an unintended fall-through which in
turn prints a wrong ERROR message.

Change-Id: I6618fa247b889d4162118278cd05dee85cf21899
Fixes: coverity CID#166948
2017-04-27 11:43:53 +02:00
Harald Welte bf849e4bf0 sccp2sua: Avoid array overruns in sccp_is_{mandatory,optional}()
Change-Id: Ied76c21e20332514c2ad364eea5fc17e24a3f4c6
Fixes: coverity CID#166943, CID#166980
2017-04-27 10:55:03 +02:00
Harald Welte 7c56ab30c9 xua_rkm: Fix handling of RK Registration with multiple Routing Keys
RKM permits multiple routing key IEs to be inside a single Routing Key
Registration message.  We were trying to handle this, but the counter we
used as array index into the 'newly_assigned_as' array was actually
always kept at zero.

Change-Id: I08a962d2f242cefb67fb2dc93818c1ed532e8990
Fixes: coverity CID#166991
2017-04-27 10:45:09 +02:00
Harald Welte 68e9aaa32d xua_default_lm_fsm: Missing printf() argument
Change-Id: I03c30a0d1e03ff56df80bdd1e8a7846142b6f79c
Fixes: coverity CID#166993
2017-04-27 10:27:35 +02:00
Harald Welte 5112d60ff7 Address some negative integer handling issues
If for some reason we cannot resolve the file descriptor for a given
FSM, we shouldn't attempt to send data through it.

Fixes: coverity CID#167155, CID#167154, CID#167153, CID#167152, CID#167151, CID#167151
Change-Id: I8b1a676b653bcdad21cb7927d549f499950a2b73
2017-04-27 10:21:42 +02:00
Max 37c53749f0 Fix debian builds
Add missing libosmogsm dependency.

Change-Id: I6e5cf393ffe81c582966ca0e9479e6deeffa9280
Fixes: OS#2182
2017-04-25 13:40:12 +02:00
Harald Welte 57d0449d4e IPA: Override/Set point codes
As an IPA SCCPlite message arrives without any MTP routing label, we
simply construct one artificially for all inbound IPA/SCCPlite packets:

* we set the SPC to the point-code of the routing key of the AS
  (as this is the PC we route to this IPA/SCCPlite client anyway)
* we set the DPC to a point-code from a new vty config command
  "point-code override dpc"

Change-Id: Id556398e1ded3e613cfde7ea8b71aff7a414ff90
2017-04-18 10:08:25 +00:00
Harald Welte 529adc67c4 osmo_ss7: Allocate message buffers with headroom
The use of m3ua_msgb_alloc() from generic code is a bit ugly, but I
really don't want to introduce yet another msgb_alloc wrapper.

Change-Id: Ic6dc9a1e7bbed2e1f73395bd18b727fa7892e25b
2017-04-18 10:08:25 +00:00
Harald Welte 6a77241cb1 osmo_ss7: make sure to re-set all state on client disconnect
When we disconnect a client, make sure that we always go through
xua_cli_close_and_reconnect(), which will make sure to notify the ASP
FSM using XUA_ASP_E_SCTP_COMM_DOWN_IND.

Change-Id: I6859b8549c8cbbe2e8279da0ede562387a066d04
2017-04-18 10:08:25 +00:00
Harald Welte 5f0a8df34c Add IPA/SCCPlite support as SIGTRAN alternative
This tries as good as possible to fit the IPA/SCCPlite stacking into the
existing SIGTRAN/SS7 code architecture/model.  To the user, the IPA
protocol looks like yet another protocol on the same level as the choice
between SUA and M3AU.  On the inside, things are obviously quite
different.

We need to handle TCP with IPA framing instead of SCTP for both server
and client.  We also implement an alternative "ASP FSM" for IPA, which
takes care of the CCM handshake (ID_REQ/ID_RESP/ID_ACK/ID_ACK2) for both
client and server mode.

In server mode, we use the 'unit name' as identifier to look up the AS,
similar to how we use a routing context to look up the AS in the xUA
case.

We also have to bypass activating the default layer manager in the
simple client to make sure we don't run into even more complexity.

What's missing right now is some way to manually override/set the point
codes.  As IPA/SCCPlite is missing any routing label, we currently
simply generate one with SPC=0/DPC=0, which will obviously not work in
most configurations.

Change-Id: I9098574cddeba10fcf8f1b6c196a7069a6805c56
2017-04-18 10:08:25 +00:00
Harald Welte afc3b85613 SUA: Our SUA implementation needs an SCCP instance in ss7_instance
So when we create a xua_server for SUA, we must make sure to create that
associated SCCP instance, if it doesn't already exist.  End-user
programs probably normally call this during their initialization anyway,
but in something like OsmoSTP, we need to auto-create it.

Change-Id: Ib575763dbd00f5bd7bfbf48f227a8f5ef9528e2a
2017-04-17 10:45:20 +02:00
Harald Welte 6548d1b9c4 SUA: Make sure to reject unknown CO message types
Found using sua-sgp-mtr-i-04 from Michael Tuexen's sua-testtool.

Change-Id: Iec5c8deb6cc48a1269fd85243c1350bafd1dd815
2017-04-17 10:33:10 +02:00
Harald Welte 161cd0dcd7 SUA: Reject unknown Connectionless Message Types
This was found by sua-sgp-mtr-i-03 of Michael Tuexen's sua-testtool.

Change-Id: I09e96a26d9f9398de07ab46cdc5af10b2ea5acc0
2017-04-17 10:26:59 +02:00