Commit Graph

55 Commits

Author SHA1 Message Date
Max 8d0343872e Make pointcode width function public
That's useful for external programs veryfying pointcode validity. For
example if used as part of BSS-related identity in GCR construction by
LCLS code we should be able to double.check that no significant bits off
pointcode are lost/ignored.

Change-Id: I5a9981dd2c1d78966c61a3f6b50c7c0d9b542caf
2018-11-19 05:50:13 +00:00
Stefan Sperling 56ac82056a return error code from xua_srv_conn_cb() if conn is freed
Allow callers of xua_srv_conn_cb() to tell whether conn
was freed by returning error code EBADF, which is also
used elsewhere in osmocom programs for this purpose.

This is necessary because xua_srv_conn_cb() might be running
inside of a loop which checks for read and then write events
on the connection. If the connection is freed by xua_srv_conn_cb()
as part of processing a read event, callers should avoid further
processing of events. But if we don't return an error we are leaving
callers none the wiser and with a dangling conn pointer.

Change-Id: I7359667b2f25d6c45acc70049b2a4ee2f376a1df
Related: OS#3685
2018-11-09 15:43:30 +01:00
Neels Hofmeyr 6d867d1d08 cosmetic: allocate ss7->sccp in one common function
Instead of allocating ss7->sccp in various places, unify that in one common
function. We shouldn't spread the decision what to pass as priv pointer around
everywhere.  There is no functional difference.

This is preparation for a patch where the sccp_instance gets allocated from the
telnet VTY: I would prefer to hide all allocation details from that code; which
also makes sense for the other callers of osmo_sccp_instance_create().

Change-Id: Ie912898c66d31ce4ac8eeeea5a6ddc3f821c06f7
2018-09-27 14:44:30 +02:00
Harald Welte 5d571ce044 Introduce osmo_ss7_register_rx_unknown_cb() for unknown PPID/StreamID
Applications may be interested in handling data for those SCTP PPID or
IPA StreamID which libosmo-sigtran doesn't implement
natively/internally.

Let's add osmo_ss7_register_rx_unknown_cb() using which applications
can register a call-back to implement whatever behaviour they'd want for
those PPID/StreamIDs.

Change-Id: I8616f914192000df0ec6547ff4ada80e0f9042a2
2018-06-08 18:47:44 +00:00
Harald Welte 3baa5da96d osmo_ss7: Register 5000 as default port for IPA/SCCPlite
Makes sure that in absence of a user-specified port number,
osmo_ss7_asp_protocol_port() will return 5000 as default port number.

Change-Id: I628ee095603742a652fd971887e02cc17d1f71b8
2018-05-26 11:37:00 +02:00
Max 7f0b908480 SS7: clarify handling of stream opening error
Add comment clarifying why we've just logged error but continued anyway.

Change-Id: I2ce55983b255b0b50fd5142d6ddf188dc8ee20b9
2018-02-15 12:31:35 +00:00
Pau Espin 10d4815bb1 ss7: Re-bind xUA server socket after setting new IP
In osmo-stp, cmd "local-ip" inside node "listen m3ua 2905" was actually
not being applied, because the server was created + bound at "listen" command
time using NULL as IP, and at "local-ip" time the IP was changed but the
server was not re-bound using the new IP, so it kept listening at
0.0.0.0.

With this patch, we defer binding the socket to "local-ip" cmd time,
after the IP has been applied.

As a result, if no "local-ip" command is provided, then the bind never
happens, which means it is now mandatory that users of osmo_ss7_xua_server_create
API not using osmo_ss7_xua_server_set_local_host call new provided API
osmo_ss7_xua_server_bind. Another new API osmo_ss7_bind_all_instances is
provided to easily make sure all servers are bound after configuration
process. This is specially important for servers which doesn't contain
the "local-ip" parameter.

Users of osmo_sccp_simple_server API are not affected by this change,
and they not requrie to call any new API.

Furthermore, using osmo_ss7_xua_server_bind in VTY code ensures the xUA
server is automatically bound to the new address if the operator changes
the "local-ip" cmd at runtime.

Related: OS#2647

Change-Id: I79738963d633bec70705ff159c5b2127cd498aa2
2017-12-20 16:04:08 +00:00
Harald Welte b393b3f4cc Add SPDX-License-Identifier + missing copyright statements
Change-Id: I113232bbeaa7a835871df7f9b883ba573d8a2534
2017-11-13 01:25:47 +09: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 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 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
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
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
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 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 3a57553145 introduce new osmo_ss7_asp_disconnect() function
Higher-layer code shouldn't have to worry between client and server
difference.  It just wants to close the underlying connection for a
given ASP - which it now can by means of osmo_ss7_asp_disconnect().

Change-Id: I36b089abd281b8edac8830fda2d8e57cc06cd0a7
2017-04-15 23:01:13 +02:00
Harald Welte 03eda14b26 Add new ASP event XUA_ASP_E_SCTP_EST_IND
For classic xUA this is not needed, as the server doesn't have to react
to establishment of the SCTP connection.  The client will start with an
ASP_UP_REQ.  However, in upcoming IPA support, the FSM will need to
react on this event.

Change-Id: Ib10914b27f8761ea44a0fdba96c045821223722a
2017-04-15 23:01:13 +02:00
Harald Welte f7abfe1bb1 osmo_ss7: avoid crash during disconnect after unknown ASP
Change-Id: Ib201f9f480f25ede0f26d4918007ff22fea28824
2017-04-15 23:01:13 +02:00
Harald Welte 5012416b7e osmo_ss7: Fix protocol of dynamically allocated ASPs
When dynamically allocating ASPs, we used the hardcoded M3UA protocol,
which is of course wrong in case of SUA or other protocols.  Let's use
the xua_server's configured protocol for the created ASPs.

Change-Id: I07832cbaf1ca42f0c7df399e4f96599034b72816
2017-04-15 23:01:13 +02:00
Harald Welte 58f225b2f0 osmo_ss7: Clean up all ASPs established via xua_server upon destroy
When we destroy a xua_server, we would like to close and destroy any
ASPs that were established via that xua_server.   In order to do so, we
need to add a list of ASPs to the xua_server, which we can iterate.

Change-Id: Iff3ed099b817e54e563b70d9ab40f63af63cc2fb
2017-04-15 23:01:09 +02:00
Harald Welte 05ad104c58 get rid of global osmo_ss7_xua_servers variable
By moving this variable into the SS7 instance, we avoid one more global
variable, and we also fix a bug where the xua servers would be saved
multiple times (once per instance).

Change-Id: Icbab59d773f23cc8514cbeb6e21e25ca35dd337f
2017-04-14 22:48:46 +02:00
Harald Welte 146bb5cebd Don't overwrite existing data in osmo_ss7_instance_find_or_create()
If we actually found an instance for the specified ID, return it fast
and don't (re)initialize all linked list heads, etc.

Change-Id: I91b6aabdb873ed8dd103918ee5e40b7ad3946735
2017-04-14 17:11:21 +02:00
Harald Welte 57620b6b98 STP: re-structure VTY interface; introduce 'cs7 instance' node
This properly integrates the concept of multiple SS7 instances (each
with their own point code format, address indicator, ...) into the VTY.
At the same time, this also removes the stp-global "g_s7i" instance
that existed so far, moving the VTY code more into the direction of also
being able to be used outside the STP - which is underlined by splitting
the vty commands between those generally useful, and those useful only
for a STP or only for a simpla ASP (client).

Change-Id: I30966fbf2e143318cd9127eb8c17cccb24407106
2017-04-14 14:53:59 +02:00
Harald Welte e316635f07 osmo_ss7: Release any dynamically-allocated ASs
When RKM dynamically allocates ASs on the SGP based on RKM registration
requests, we must make sure to properly destroy those at the time the
related ASP disconnects.  Also, make sure to send
XUA_ASP_E_SCTP_COMM_DOWN_IND to the layer manager (if any).

Change-Id: Ie6505680bb6890814ae36858c54a2a6d2850f5cf
2017-04-13 18:05:13 +02:00
Harald Welte ed15c74a01 Add a default layer manager using RKM to register PC with SG
This "default layer manager" can optionally be used by a xUA ASP. It
will handle the xUA Layer Manager (xlm) primitives and use them to
behave as follows:

* bring the ASP into state "INACTIVE"
* see if the SG can match our connection (based on IP address + port
  information) to a statically configured ASP configuration with
  associated AS(s).  If yes, it will send us a NOTIFY message with
  AS-INACTIVE.
* if the above doesn't work, try to dynamically register a routing key
  using RKM for the point code that was locally confiured on the
  ASP/client.   If that works, the SG will now have created ASP and AS
  objects as well as a routing key and be able to serve us, sending the
  NOTIFY with the AS-INACTIVE state.
* After either of the two above, we will attempt to transition into
  ASP-ACTIVE.  The SG should send us an AS-ACTIVE notification in return
* if anything fails, abort and disconnect the SCTP connection, restart
  related FSMs and start from scratch

Change-Id: I78d4623dd213b5c59007a026a6cc3cfe5c04af50
2017-04-13 18:05:13 +02:00
Harald Welte 9654e65feb Add osmo-stp executable as new "Osmocom Signaling Transfer Point"
osmo-stp is able to define multiple M3UA and/or SUA application servers
(AS) as well as application server processes (ASPs).  Clients can then
connect via M3UA or SUA, perform the respective ASPSM / ASPTM state
changes and finally exchange MTP signaling such as ISUP or SCCP on top
of it.  Routing is currently only based on point codes (PC).  Routing table
is fully configurable with Destination PC and mask.

Shortcomings:
* xUA: only "override" traffic mode supported, no load-balance or broadcast
* xUA: no SNM supported, i.e. DAVA/DUNA/... messages are neither parsed
  nor generated
* SCCP: no Global Title based Routing (GTR) yet
* SCCP: no Global Title Translation (GTT) yet
* no M2PA / M2UA sigtran dialects
* no classic CS7 based signaling links(E1/T1 TDM)

Change-Id: If32227b8d3127c6178e4ee45527ce65f69bc7b1e
2017-04-13 18:05:01 +02:00
Harald Welte 2e6ada753c osmo_ss7: Fix SCTP PPID byte width
In 17df5953ff we fixed endianness issues
with the Stream ID field, but at the same time mistook the PPID field
for 16bits.  In reality it is 32bits, and hence our 'htons' is rendering
wrong PPID values.

Change-Id: Ief04486e752e6b7e0a853b1fa9ca525ad47800f6
2017-04-12 12:11:14 +02:00
Harald Welte 47d05fae4f osmo_ss7: Allocate local routing key ID and use it as lookup key for AS
In M3UA RKM we need a "Local Routing Key ID" which uniquely identifies a
given routing key locally at the node. Allocate this value and store it
in each osmo_ss7_as, as well as add a lookup function for it.

Change-Id: I89a0abcf66228ce092126a497cc7971df3a6af71
2017-04-11 23:27:05 +02:00
Harald Welte fb82880905 osmo_ss7: destroy any ASPs allocated dynamically at accept() time
When we accept SCTP connections from clients for whose IP/port we have
no matching local configurations, and it is permitted by local
configuration, we dynamically allocate osmo_ss7_asp's in this case.
Make sure to properly destroy them at the time the SCTP connection is
lost.

Change-Id: I07d69a0cd52a049a7a4bb0d996e95d39fee9a106
2017-04-11 23:27:05 +02:00
Harald Welte bba8fe8166 osmo_ss7: Make sure to start server-side ASP FSM for dynamically created ASPs
Change-Id: I5dd079158a8c6b176a94dc251748924ef3e9c937
2017-04-11 23:27:05 +02:00
Harald Welte 2c2ae5997c osmo_ss7: When destroying an AS or a linkset, delete all routes
When we destroy a linkset, it make sense to remove all associated routes
pointing to the linkset, as they would point to nowhere anyway.

Change-Id: I393400bc758c28997e16bc78e3142719b6a61be8
2017-04-11 23:27:05 +02:00
Harald Welte 8af8d643de osmo_ss7: Fix memory leak with sock_name on clients at re-connect time
We cannot use osmo_talloc_replace_string() together with
osmo_sock_get_name(), as the latter already creates a dynamically
allocated string, and the former will then make a copy of that
allocation.

Change-Id: I6798221ccb3c70186c1c51dd34b7823fefd6df58
2017-04-11 23:27:05 +02:00
Harald Welte ed18c11de9 osmo_ss7: Generate M-SCTP_RESTART.ind towards Layer Manager
The M3UA RFC defines this primitive to the layer manager, but we so far
didn't generate it.  Let's inform the Layer Manager about such events,
in case it wants to take appropriate action.

Change-Id: I4e4e86f9b9d8ef4639c835878749ce8d8cc76f7c
2017-04-11 23:27:05 +02:00
Harald Welte 1978e3a320 osmo_ss7: Instruct libosmo-netif to use {TCP,SCTP}_NODELAY on all sockets
If we don't do this, we get some nasty packet delays, which are
sufficient enough to trigger re-transmissions of an M3UA ASP-UP packet
even over loopback/localhost on an otherwise unloaded system.

Change-Id: I6aa4eb421ecb483d3da1b0ce3aa6511d161c3750
2017-04-11 23:27:05 +02:00
Harald Welte b650dd9d77 osmo_ss7: Use proper string name for dynamically-created ASP
Change-Id: Id346002c79ba2aba2183ebd46bead372a727316d
2017-04-11 23:27:05 +02:00
Harald Welte 5181c5fe1b osmo_ss7: Send M-SCTP_RELEASE.ind for close of xUA client or server socket
Change-Id: I31e7de136545279a75a5faca0927d3dbf11ff46d
2017-04-11 23:26:58 +02:00
Harald Welte 17df5953ff xUA: Fix endianness handling of PPID and STREAM_ID
In their infinite wisdom, the inventors of SCTP designed an API (the
sockets API described in RFC6458), where some members are in host byte
order (like the stream identifier), while other members are in network
byte order (like the PPID).

Let's handle this properly (we assumed both are network byte order), and
also use 16-bit htons/ntohs fo the PPID, rather than htonl/ntohl.

Change-Id: I51c87314ef9ba6415e7e89980699ab07e787ed5d
2017-04-10 17:52:30 +02:00
Harald Welte 9ecb11bd6d Allow clients to specify local IP/port
Change-Id: Ief7ce8181442fd0f51c34cf598269ed3a6beacea
2017-04-10 11:48:36 +02:00
Harald Welte 632ab5a359 osmo_ss7: Fix msgb memory leaks in error paths (asp not connected)
Change-Id: I031d90348ea243ac5dbdde14365528f3ec8e3709
2017-04-10 11:48:35 +02:00
Harald Welte ac00448f19 osmo_ss7: default point-code format for parsing/printing without ss7_instance
osmo_ss7_pointcode_print() osmo_ss7_pointcode_parse() etc. now support
passing a NULL ss7-instance which will lead to application of the
default ITU 3.8.3 point code format.

Change-Id: Ifb739e92e31eaaa0343dc57c9af8c9164d00175f
2017-04-10 11:48:35 +02:00
Harald Welte e2d1cc8b0e send M-SCTP_ESTABLISH.ind to Layer Manager
Change-Id: I2904f8ebd97036690ba8a9525b31354c0252123b
2017-04-10 11:48:35 +02:00
Harald Welte a5b5dac5b3 osmo_ss7: Add support for dynamic ASP registration
if osmo_xua_server.cfg.accept_dyn_reg is set, then ASPs are permitted
to connect without having a pre-configured matching ASP definition in
the vty.  This helps particularly in cases where RKM is used for
dynamica registration of a RC (and hence AS).

Change-Id: Ie48898202acbdbfe144fdd5851dfedbb554b11aa
2017-04-10 11:48:35 +02:00
Harald Welte a40df808d5 Add osmo_ss7_find_free_rctx() function to get unused rctx
Change-Id: I0186e25a1b3a325c6b0e3f50ef1590c4de6dbef6
2017-04-10 11:48:35 +02:00
Harald Welte 9aee15c23d osmo_ss7: Fix segfault when routing MTP-TRANSFER.req to ASP without sctp connection
Change-Id: I142a11b09672864b54b927b8334b1975c8cd6022
2017-04-10 11:48:35 +02:00
Harald Welte ca88edb0fd xua_srv_conn_cb(): Print sctp_recvmsg flags (line in xua_cli_conn_cb())
Change-Id: I91920c6ad665abc791a1dbf386d52cf0aece9133
2017-04-10 11:48:35 +02:00