Commit Graph

294 Commits

Author SHA1 Message Date
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 8dec5a8ec5 xua_rkm: Make dynamic registration of Routing Keys work
The existign xua_rkm code was merged a bit pre-maturely as it was not
properly tested.  This adds a lot of fixes to make it work at all in the
first place, as well as the configurable option for fully dynamic
routing key management, where ASs and routing keys must not be
configured statically by administrative means, but clients (ASPs) can
simply come and register for whatever point code they want.

Change-Id: I79a070fa7b271b44995511f7b3ff7cc6beec8278
2017-04-13 18:05:13 +02:00
Harald Welte 2346850ae2 xua_rkm: Improve comments about functions
Change-Id: I2f17baae37718e277eae54d4d225f8fcb2eb4aae
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 51302c883c osmo_ss7_vty: 'show' commands for AS, ASP, route
Change-Id: Ideb74c9396e5385f6a7c30ff8608d34ededa1f4d
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 7fa3c9972d sua2sccp: Only encode SCCP options permitted for given msg type
The SCCP spec clearly defines which optional information element each of
the messages supports.  We must make sure to not include any other
options when converting from SUA.  SUA has more relaxed rules about
this, and e.g. supports SRC and DEST ADDR in the COAK, while the SCCP CC
only permits a CalledParty, but not CallingParty.

This was found when interoperating against the Ericsson TTCN-3 SCCP
implementation for Eclipse Titan.

Change-Id: I7d9e23dec1d3e786d291abd270a261704593befc
2017-04-13 15:59:52 +02:00
Harald Welte 9692449599 sccp_test_server: Don't use '0' as local reference
the '0' confuses the Ericsson SCCP code for Eclipse Titan, even though
the spec considers it permitted.

Change-Id: I21269a7d610a4bf52555ffcef4f8acc55824515e
2017-04-13 15:59:52 +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 282d1c2ffa sccp_user: Make sure to create client-side AS with primary PC
When we are on the ASP (client) side, we must initialize the routing key
of the AS with the proper primary point code of the system.  Only this
way, the correct point code will be used during dynamic routing key
registration via RKM.

Change-Id: If586ac9f3449254973a19654dd13dce5793f285f
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 b5e569ee67 xua: Add value_string for routing key [de]registration results
Change-Id: If8f0a0ad0837810388cfe65a7b571b6ce4df33e3
2017-04-11 21:45:25 +02:00
Harald Welte 4012ea51a5 SCRC: Print NOTICE log message if we attempt to use (missing) GT routing
Change-Id: I4dc954cc3f10860dea518f95e53f72c6a9a3de95
2017-04-11 21:45:25 +02:00
Harald Welte dff8f995ef SCCP SCOC: Ensure user primitive msgb->l2h always poinst to tail
In case there is no user data in a CONNECT.conf primitive (or other CO
primitives), we must make sure that msgb->l2h = msgb->tail so that the
SCCP User can use msgb_l2len(msg) == 0 as indicator to verify if user
data is present or not.

Change-Id: Ie512fe063391e3a634097f555b9b0089d2981de9
2017-04-11 21:45:25 +02:00
Harald Welte 996dcf3ba6 Fix for SCCP CC without user data
When sending messages like CC (or SUA COAK) without user data, we must
make sure to not include the optional data part - as opposed to
including one with zero length.

Change-Id: If91edb526cbcd792ec5ebcb4518cf848feb69391
2017-04-11 09:42:09 +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 0be0a4e035 m3ua: cosmetic clanup. We can simply return the M3UA errror code
Change-Id: I6ed04a4f78e618938484aeab62dbcfb3f310998d
2017-04-10 11:48:36 +02:00
Harald Welte 63c6cb27a6 M3UA: Reject Message Class XFER / Type != DATA
This was discovered (and fix validated) using m3ua-sgp-mtr-i-003 of
Michael Tuexen's m3ua-testtol.

Change-Id: I7498f606b031f5a6dfb538d9900c744da6aed36f
2017-04-10 11:48:36 +02:00
Harald Welte 1710c7e71f M3UA: Ensure XFER messages are not sent on stream 0
According to the RFC, Stream ID 0 MUST not be used for XFER/DATA
messages.

This was discovered (and fix validated) using m3ua-sgp-mtr-v-003-alternate
of Michale Tuexen's m3ua-testtool.

Change-Id: I80b941426b5106e091bd1becff0ae97958aff97c
2017-04-10 11:48:36 +02:00
Harald Welte 440771f18a M3UA: Properly reject invalid/unknown routing context
This was discovered (and fix validated) using m3ua-sgp-asptm-i-005 of
Michael Tuexne's m3ua-testtool.

Change-Id: I217ae287e22371e36dda0f87a7737b62fb1bf2d6
2017-04-10 11:48:35 +02:00
Harald Welte 312fd7e4b9 M3UA: Handle opportunistic ASPIA in INACTIVE state
This was discovered (and fix validated) using m3ua-sgp-asptm-o-003
of Michale Tuexen's m3ua-testtool.

Change-Id: If231072655170fe52dae738882dd63b1d0a60cf9
2017-04-10 11:48:35 +02:00
Harald Welte fbb2bddce6 M3UA: Send opportunistic ASPACT-ACK to ASPACT-REQ in ACTIVE state
This was discovered (and fix validated) using m3ua-sgp-asptm-o-001 of
Michael Tuexen's m3ua-testtool.

Change-Id: I6d254f7a33856e036329aa717a9c03efb1f1289d
2017-04-10 11:48:35 +02:00
Harald Welte 2cef54f4cc M3UA: Send "Unexpected Message" when receiving ASP_UP-ACK in ACTIVE
Change-Id: Ibcda68b7acb02bf1580a832baff06ff21cbac713
2017-04-10 11:48:35 +02:00
Harald Welte 6f8c84b27e M3UA: Make sure to reject unsupported traffic mode types
This was discovered (and fix validated) using m3ua-sgp-asptm-i-004 of
Michael Tuexen's m3ua-testtool.

Change-Id: I76c01189b75ff3084cd4d3944314ec9b9f811dbf
2017-04-10 11:48:35 +02:00
Harald Welte f21eaabe24 M3UA: Respond with "Unexpected Message" if ASPTM is received too soon
This was discovered (and fix validated) using m3ua-sgp-aspsm-i-003
of Michale Tuexen's m3ua-testtool.

Change-Id: I8b63e7b5e39a7ef8dd66bf014110a04f5f3dc2a2
2017-04-10 11:48:35 +02:00
Harald Welte dde5fda513 osmo_sccp_make_addr_pc_ssn(): Set routing indicator
When we crate a sccp address with PC+SSN, we should also set the routing
indicator accordingly (OSMO_SCCP_RI_SSN_PC).

Change-Id: Ie179df7158624520e90093da063c57f1e3efa0bd
2017-04-10 11:48:35 +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 72f12f7543 m3ua: Remove inbound routing context before routing
After verifying the routing context of an incoming M3UA message, remove
the routing context before passing into MTP routing.  In the forwarding
case, we might want to set a new routing context on the outbound link,
and we don't want the routing context IE to show up twice.

Change-Id: I7a534cb1da275369c70766c059aaae8157ce6833
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 082dc7f170 move layer_manager from xua_asp_fsm priv to osmo_ss7_asp
... this way it is publicly accessible/reachable

Change-Id: I00ec1689bfb068b9067d893fdba14d12d59f73f0
2017-04-10 11:48:35 +02:00
Harald Welte d36571a776 xua: report N-ERROR and N-NOTIFY primitives to layer manager
Change-Id: I5c2060f0397d2bf510b085a5bb07e7ab176f2742
2017-04-10 11:48:35 +02:00
Harald Welte 02e7530671 xua: move notfiy parameters from xua_internal to sigtran_sap and rename them
Change-Id: I295b9d6755a4bb52a817d2791a302bdd9fc775dd
2017-04-10 11:48:35 +02:00
Harald Welte 3e463a3862 M3UA: RKM DEREG-REQ should contain routing context, not routing key
The mandatory IE checking is requiring the wrong IE

Change-Id: I73ecd163e2143341687ee4bca15a0bc69719c594
2017-04-10 11:48:35 +02:00
Harald Welte 4e818c3cfd Add M3UA RKM (routing key management) support, SGW side only
Change-Id: I9b1cf438a42519c0fe2f555c1672fafa499122a1
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 1e25c3a0ac xua_msg: Add xua_from_nested() helper function for nested IEs
... and add a test case to ensure it continues to work.

Change-Id: Iee434886598b528d23ddce0490dcc782e0f5d6ae
2017-04-10 11:48:35 +02:00
Harald Welte 5c3baf86f2 protocol/m3ua.h: Add definition for RKM reg/dereg result codes
Change-Id: I16db7847e20501b89cc487029b29c8796b10bb84
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 07903bb2ad m3ua_example: Add talloc reporting
This can be used to check for memory leaks while running the example
code.

Change-Id: I87caa76a2be3c92c93e419242595107d744bad97
2017-04-10 11:48:35 +02:00