Commit Graph

931 Commits

Author SHA1 Message Date
Pau Espin ee10347957 ipa_asp_fsm: Support server starting handshake with ID_GET or ID_ACK
The behavior here since to have changed at least a couple times in
history, always apparently breaking some compatibility:

* libosmo-sccp.git a0dd986f55
  (SCCPLite MSC sends IPA ID ACK at startup) [10th July 2018]
* libosmo-sccp.git 9c0fae14d1
  (Reverts back to sending IPA ID GET at startup [29th April 2021]
* osmo-ttcn3-hacks.git 3bf31d216a18c1d6a6e298a592f873beea322939
  (Changes server emulation to send IPA ID ACK when BSC connects to it) [24th August 2018)

So it seems the proper way is to start handshake:
CLI <- SRV: IPA ID GET
CLI -> SRV: IPA ID RESP
CLI <- SRV: IPA ID ACK
CLI -> SRV: IPA ID ACK

However, it seems some SCCPLite MSCs (acting as IPA srv) skip the first
ID GET + ID RESP handshake and go directly for ACKs:
CLI <- SRV: IPA ID ACK
CLI -> SRV: IPA ID ACK

So, let's make everybody happy and support both cases in the client FSM.
If server sends us IPA ID ACK first, simply send back an IPA ID ACK and
be done with it, otherwise if it sends us an IPA ID GET, go for the full
handshake.

Change-Id: Ie9968ce8cd8582deb583024ff3e46736a07883fe
2021-06-09 13:40:27 +02:00
Pau Espin e4e047bbec cosmetic: xua_asp_fsm.c: reorder functions in file
Reorder functions to follow usual order in FSM files:
1- structs and helper functions
2- for each state: first _oneneter, then the action func
3- generic state fsm functions (timers, all_state)
4- struct osmo_fsm_state
5- FSM allocator and public functions

Change-Id: Ic143db3dda48750effddaa0cafadf960f5b5c38c
2021-06-09 12:59:50 +02:00
Vadim Yanitskiy ce72cdff6e VTY: write_one_asp(): fix 1 << 31 cannot be represented by 'int'
Change-Id: Ib144df42baed16aeffa5b56afd0c17960ee6004e
Closes: OS#5158
2021-05-21 17:54:47 +02:00
Harald Welte 2f8b645ecb sccp_scrc: Ensure we have not just SSN but at least OPC+SSN in CallingParty
There are implementations out there which send us traffic, specifically
in this case SCMG (SST) that has only SSN in both Called and Calling
Party. This means the inbound SST message is routed correctly to the
local SCCP user of libosmo-sigtran. But when that local SCCP user
responds with inverting Called/Calling Party, the new destination again
just contains a SSN.

As a result, we don't know where to route the message (we always need a PC).

Change-Id: Id66ae960ebe3cb3b09c6dd5454f9ac9c073f46d7
Closes: OS#5146
2021-05-13 22:00:14 +02:00
Harald Welte 3639af549c m3ua/sua: Add new snm_inactive quirk
This quirk allows the M3UA + SUA code to accept SSNM/SNM traffic despite
being in AS-INACTIVE state.  This is forbidden by the RFCs but there
are some implementations that apparently just don't care what is
specified.

Change-Id: I193dd546b3e3c00e29f192d0d1bf7819b3e194be
Closes: OS#5148
2021-05-13 18:11:53 +02:00
Harald Welte 0f769392a5 m3ua/sua: Add quirk for allowing inbound DAUD from SG in ASP role.
The M3UA RFC talks about this message being used in ASP->SG direction,
not the other way around.

Closes: OS#5147
Change-Id: I36ff172b47142a877b37bbd149073bef35b36a74
2021-05-13 18:11:53 +02:00
Harald Welte e9b21ff256 osmo_ss7: introduce notion of configurable 'quirks'
A quirk is an implementation work-around in order to establish
interoperability with another implementation, either a buggy one or
one that follows a different interpretation of a given spec.

For now, we introduce a first quirk affecting when we (in ASP role)
send an ASP-ACTIVE message to the SG.

Closes: OS#5145
Change-Id: Idd947ea39d743eb1bc9342ad9d098036821da45b
2021-05-13 18:11:51 +02:00
Harald Welte 2cf796a2a5 ss7_asp_test.vty: Allow more asp node commands after shutdown
this will be required once we add new commands (quirk) in the
next few patches.

Change-Id: If1068cd94782df236948101166a76586e9845762
2021-05-11 20:36:31 +02:00
Harald Welte ab85cdf1ab Constrain connection ID allocation to 24 bits
We currently use the local connection ID on the SCU SAP also as local
reference on the wire-line SCCP messages.  However, the latter only has
a 24 bit range, so we should make sure to wrap accordingly on
allocation.

Change-Id: I414d29271da48ac0b05a688ce9e949a66e4d0d92
Closes: OS#3921
Related: OS#3871
2021-05-10 11:14:01 +02:00
Harald Welte a7c4f97348 ss7_vty: Print actual connected port number in case of IPA server
In IPA, unlike M3UA/SUA, we often have clients connecting from
random/unknown ports. In such cases, the configured remote port is '0'.

Let's use getsockname to determine the actual source ip/port of the
connected client (if any) during "show ... asp"

Change-Id: I1327a46d0b74c572d2ad828a958090af53b9fa37
Closes: SYS#5429
2021-05-03 19:31:56 +00:00
Harald Welte c288852320 Revert "osmo_ss7: free the sock_name string once an ASP socket is closed"
This reverts commit 03e3b04234.

It caused a regression, as apparently some code is using the sock_name
string even after the close:

DLSS7 osmo_ss7.c:1676 0: asp-asp-dyn-0: xua_srv_conn_cb(): sctp_recvmsg() returned 12 (flags=0x8080)
DLSS7 osmo_ss7.c:1608 0: asp-asp-dyn-0: xUA SRV SCTP NOTIFICATION 32773 flags=0x0
DLSS7 osmo_ss7.c:1621 0: asp-asp-dyn-0: xUA SRV SHUTDOWN_EVENT
DLSS7 osmo_ss7.c:1875 asp-dyn-0: connection closed
DLSS7 osmo_ss7.c:1881 XUA_ASP(asp-dyn-0){ASP_INACTIVE}: Received Event SCTP-COMM_DOWN.ind
DLSS7 xua_asp_fsm.c:669 XUA_ASP(asp-dyn-0){ASP_INACTIVE}: state_chg to ASP_DOWN
DLSS7 xua_asp_fsm.c:113 0: asp-asp-dyn-0: No Layer Manager, dropping M-ASP_DOWN.indication
DLSS7 xua_asp_fsm.c:113 0: asp-asp-dyn-0: No Layer Manager, dropping M-SCTP_RELEASE.indication
DLSS7 osmo_ss7.c:1442 0: asp-asp-dyn-0: Destroying ASP
DLSS7 osmo_ss7.c:1449 XUA_ASP(asp-dyn-0){ASP_DOWN}: Terminating (cause = OSMO_FSM_TERM_REQUEST)
DLSS7 osmo_ss7.c:1449 XUA_ASP(asp-dyn-0){ASP_DOWN}: Freeing instance
DLSS7 fsm.c:573 XUA_ASP(asp-dyn-0){ASP_DOWN}: Deallocated
=================================================================
==2928584==ERROR: AddressSanitizer: heap-use-after-free on address 0x618000004d28 at pc 0x7fd6cddeaff8 bp 0x7ffe978fbad0 sp 0x7ffe978fbac8
READ of size 8 at 0x618000004d28 thread T0
    #0 0x7fd6cddeaff7 in xua_srv_conn_closed_cb (/space/home/laforge/projects/git/libosmo-sccp/src/.libs/libosmo-sigtran.so.5+0x17bff7)
    #1 0x7fd6cc443d0f in osmo_stream_srv_destroy (/usr/local/lib/libosmonetif.so.8+0x7ed0f)
    #2 0x7fd6cdde8ce8 in xua_srv_conn_cb (/space/home/laforge/projects/git/libosmo-sccp/src/.libs/libosmo-sigtran.so.5+0x179ce8)
    #3 0x7fd6cc44285e in osmo_stream_srv_read (/usr/local/lib/libosmonetif.so.8+0x7d85e)
    #4 0x7fd6cc44331d in osmo_stream_srv_cb (/usr/local/lib/libosmonetif.so.8+0x7e31d)
    #5 0x7fd6cd88a1c7 in poll_disp_fds (/usr/local/lib/libosmocore.so.17+0x10d1c7)
    #6 0x7fd6cd88a30d in _osmo_select_main (/usr/local/lib/libosmocore.so.17+0x10d30d)
    #7 0x7fd6cd88a32c in osmo_select_main (/usr/local/lib/libosmocore.so.17+0x10d32c)
    #8 0x557aab05c078 in main /space/home/laforge/projects/git/libosmo-sccp/stp/stp_main.c:267
    #9 0x7fd6ccc50d09 in __libc_start_main ../csu/libc-start.c:308
    #10 0x557aab05b389 in _start (/space/home/laforge/projects/git/libosmo-sccp/stp/.libs/osmo-stp+0x3389)

Change-Id: I72f83114408e7a54d1f3072338fa6f189bf4064f
2021-04-30 15:51:22 +02:00
Harald Welte 03e3b04234 osmo_ss7: free the sock_name string once an ASP socket is closed
It's confusing to keep around a string representation of what peer the
socket was previously connected to.

Change-Id: I00d47fc355bfe24915653767ad75c1f491c060d5
2021-04-30 12:06:20 +02:00
Harald Welte a25251a15b don't do explicit NULL checks before calling talloc_free()
Change-Id: I97a072ca32820ad34785ac6a54b00ed51b519305
2021-04-30 12:03:07 +02:00
Harald Welte 9c0fae14d1 xua_asp_fsm: Fix IPA client role
The IPA server worked as expected, but the IPA client has some clear
logic bug that prevented it from working.  It shows that we never
really use any of that IPA/SCCPlite stuff after years in spec-compliant
SIGTRAN land.

A client now first waits for the IPA_REQ, sends its IPA_RESP, then
waits for the ACK, ...

Change-Id: Icfc32cad7d65c94dc21754b8f879afcf34d34a92
2021-04-29 21:10:30 +02:00
Harald Welte d9098703fa xua_as_fsm: Only delete a route for an IPA AS if we created one earlier
The current code would potentially delete a route that was statically present in the
configuration in the following situation:

* route exists in config
* identical route is attempted to be added at AS-ACTIVE time, but fails
* route is unconditionally deleted at AS-DOWN time
* user now does 'write file' and has lost a route

Let's make sure we only delete the route if we added it previously.

Change-Id: I9ad5f7ebe0790e6c186b8ea1b12f204860a00cd2
Related: SYS#5422
2021-04-29 21:10:30 +02:00
Harald Welte 40c4461c3a osmo_ss7: Truncate route 'mask' to point code bit length
Otherwise we run into the problem that a route with mask 0xffffff
differs from one with a mask of 0x3fff despite having only 14 bit
point code length and them being logically equal.

Change-Id: I5d5c828de45724d93a0461bb0dd7858fd8378acd
Related: SYS#5422
2021-04-29 20:07:34 +02:00
Harald Welte 5b0ec1ce67 ipa: Move automatic route add/del from ASP to AS level
SS7 routes operate on AS level, not ASP level.  However, the
automatic SS7 route creation/destruction for IPA was implemented
at the ASP level.  This works for single-connection ASs, but
obviously fails in load-share situations:  We attempt to add the
same route several times, and we delete it at the first ASP
disconnect, even while other ASPs still exist.

This patch moves the IPA route creation/deletion from the ASP level
to the AS level.  When the AS becomes active, the route is added;
when it goes to DOWN state, it is removed.

Change-Id: Idb602beae3e9bc19f7bd96355c02ec8dfd9c5d6c
2021-04-26 19:43:31 +00:00
Harald Welte 6b799aeb67 Don't create duplicate routes in osmo_ss7_route_create()
Let's refuse to create exactly identical routes

Change-Id: I520415d4499a4017dfdbdfc3cd67522e1bbd1627
Related: SYS#5422
2021-04-26 13:06:57 +02:00
Harald Welte 37a3b1f07d ipa_asp_fsm: Fix AS lookup from IPA ASP
Contrary to proper SIGTRAN, IPA/SCCPlite cannot support multiple
AS within one ASP.  When looking up the AS from the ASP, we cannot
blindly use routing context 0 to find the AS, as there may very well
be multiple IPA AS, and all of those have routing context 0.

As a result, the exiting look-up by osmo_ss7_as_find_by_rctx(inst, 0)
will return the wrong AS, and we will try to add/delete routes for
a completely different AS when ASPs are coming up or going down.

Instead, we need to use xua_find_as_for_asp() in order do the look-up:
It will resolve the single AS within the ASP.

Change-Id: Id295daf84f6ba1cc56cbe1761f874bea329e17ea
Cloess: SYS#5422
2021-04-26 08:54:09 +00:00
Harald Welte 8a43eb4186 osmo_ss7: Log route destruction (like we log route creation)
Change-Id: I503cc97db5f907610074cb513299a3a8505e00e5
2021-04-25 18:49:17 +02:00
Harald Welte f414447bfd don't log "SCTP connection close" if an IPA/TCP connection closes
The xua_srv_conn_closed_cb() function is shared/generic.  Let's simply
write "connection closed" to avoid any confusion.  As the ASP name is
printed, it should be clear which L4 protocol was used.

Change-Id: I506ccc2665a6b0af0fde3961e7e7937af7a81219
2021-04-25 18:49:17 +02:00
Harald Welte fe770ee0b1 ipa_asp_fsm_del_route(): Log what happens if we bail out early
Let's inform the user about situations in which we'd want to delete
the route for an IPA client, but we run into some problem and
bail out early.

Change-Id: Ie3f57d22901f169afb2c844476b5839cc36752aa
Related: SYS#5422
2021-04-25 15:01:33 +02:00
Harald Welte 9db6213620 ipa: Use VTY-configured default network indicator
When we receive a message from an IPA/SCCPlite connection, we only
have SCCP global titles and no underlying M3UA.  We since have
to introduce a fake M3UA header.  While we correctly set the SI,
OPC and DPC, we didn't set the NI to what is configured as default
for the cs7 instance in the VTY.  For international, this problem
was hidden by the fact that international is '0' and hence our
default memory initialization.

Change-Id: I02c618fa0a0aa2a859fcd56397df9637043c8e6e
Closes: SYS#5421
2021-04-25 14:29:30 +02:00
Harald Welte e5ffedf526 Add README.md describing what this repo is about
Change-Id: I965dadf1ef4a8340f6995ec745607c28e7bb1f89
2021-03-21 22:56:42 +01:00
Pau Espin 6304393363 Bump version: 1.3.0.51-6858-dirty → 1.4.0
Change-Id: I017147905ffb69829d010f3e8416c8c5d80e7040
2021-02-23 17:57:33 +01:00
Pau Espin 685816f97f stp: generate coredump and exit upon SIGABRT received
Previous code relied on abort() switching sigaction to SIG_FDL +
retriggering SIGABRT in case the signal handler returns, which would
then generate the coredump + terminate the process.
However, if a SIGABRT is received from somewhere else (kill -SIGABRT),
then the process would print the talloc report and continue running,
which is not desired.

Change-Id: Idca8e360968cb6998591737348ce520954e251b2
Fixes: OS#4865
2021-02-23 17:40:46 +01:00
Harald Welte 2181d644bc manuals: generate vty reference xml at build time
Rremove osmo-stp_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-stp --vty-ref-xml cmdline switch.

Change-Id: I5bcbbdf7b737d2ce36ea877bc78c8cf191a64e1b
Depends: I613d692328050a036d05b49a436ab495fc2087ba
Related: OS#5041
2021-02-23 17:20:08 +01:00
Harald Welte 6d8d9b3ced main: add --vty-ref-mode, use vty_dump_xml_ref_mode()
Change-Id: Ia5abf7457ee7e97ec3fcd5520e5ef82ef808667a
Related: OS#5041
Depends: Ie2022a7f9e167e5ceacf15350c037dd43768ff40
2021-02-23 17:20:08 +01:00
Harald Welte 7eedb6b03c Add osmo_ss7_pointcode_print_buf() to API
Like osmo_ss7_pointcode_print(), but prints into an user-supplied
buffer.

Change-Id: I5fc7d7746eb90a9d404b6b50bf9ded6789a1c33c
2021-02-23 17:20:08 +01:00
Pau Espin d7ecf7a150 tests: Replace deprecated API log_set_print_filename
Change-Id: Id09f903fc5008d074763441a26d71c4fbaf394d8
2021-02-19 13:10:35 +01:00
Pau Espin 25234f9158 gitignore: Ignore autofoo *~ churn
Change-Id: Ia9f01761b595d9b082d78b05d71ff549b8e33d91
2021-02-19 13:06:27 +01:00
Pau Espin 5cac145d2c tests: Explicitly drop category from log
Let's disable category here since we don't care about its formatting here.

In any case, every test relying on logging output validation should
always explicitly state the config to avoid issues in the future if
default values change.

Change-Id: I899e63ab2702bf25514f6585fb45f5bbf60a9ac9
Related: OS#5034
2021-02-19 13:06:02 +01:00
Harald Welte afbcc5d532 xua_snm: Implement handling of DUPU messages
A DUPU message in SUA and M3UA indicates the unavailability of
a (MTP-level) user, i.e. the entire SCCP, ISUP, ... is not available.

If we receive a DUPU (destination user part unavailable) message in ASP
role, then we must
 * distribute it to any other ASPs for which we operate in SG mode
 * pass it as MTP-STATUS.ind to SCCP, which can then generates
   N-PCSTATE.ind to the SCCP User

Change-Id: I1559ed0f761a8495b222df48c6bd43798e220471
2021-02-10 19:58:38 +01:00
Harald Welte 7daae9bd67 sccp: more SCMG handling: SSA and SSP message handling
When a SSP (Subsystem Prohibited) or SSA (Subsystem Available) SCMG
message is received, we must generate the respective primitives towards
the SCCP user.

Change-Id: I149166a25113f5d3e3536f9297bf89ff3139b9e3
2021-02-10 19:58:00 +01:00
Harald Welte 0d53666108 sua: per-ssn DUNA/DAVA notification
Unlike M3UA, in SUA a DUNA/DAVA message can contain not just the point
code that became available / unavailable, but it can also include a SSN.

In that case, it is just the SSN that became available/unavailable, and
not the entire point code.  Hence, a N-STATE.ind and not a N-PCSTATE.ind
must be delivered to the SCCP user.

Change-Id: Ie9a45b905bc17e7b695e15fe12ba4bbadcd032bf
2021-02-10 19:56:03 +01:00
Harald Welte bf85d6f433 xua: introduce xua_msg_get_u32p() helper
Change-Id: Id7780074b82bc668ae148456750b1a01799decd1
2021-02-08 18:11:12 +01:00
Harald Welte d2dc5ed987 sccp: Add minimalistic SCMG implementation
SCMG (SCCP Management) is a special sub-system that normally resides
at SSN=1.  In Osmocom we so far ignored its existence.  However,
in terms of interop with other implementation, we should implement
at least some basic features.

The only procedure implemented in this initial commit is the response
to an incoming SST (Subsystem Test) message.  If we don't respond to
this message, a remote SCCP entity could assume the SSN is dead on
our side, rendering communication impossible.

Change-Id: I04b162476f7652ef0540b5ea7299e9447efd1d09
2021-02-08 18:11:08 +01:00
Harald Welte 943affdd48 sccp: Notify users of point code available/unavailable
* add N-PCSTATE.ind and N-STATE.ind definitions to SCCP user SAP
* add minimal SCMG (SCCP Management) and LBCS (Local Broadcast)
* generate MTP-PAUSE.ind/MTP-RESUME.ind based on received xUA DUNA/DAVA
* generate N-PCSTATE.ind towards the local SCCP users

Change-Id: Idb799f7d7ab329ad12f07b7cbe6336da0891ae92
Related: OS#2623, OS#3403, OS#4701
2021-02-08 18:00:56 +01:00
Harald Welte 6cb841b92b xua: Implement SNM availability/unavailability messaging
M3UA and SUA have one sub-protocol called [S]SNM, through which the
SG informs the ASP about certain destinations (point codes) becoming
available (DAVA) or unavailable (DUNA) in the SS7 network.

This patch adds support for
* generating DAVA/DUAN on a SGP when the AS FSM changes to/from AS-ACTIVE
* receiving DAVA/DUNA on an ASP and informing other "SG role" AS/ASP
* processing DAUD from ASP received by SG, generating relate DAVA/DUNA
  responses

Related: OS#2623
Change-Id: Id92be4691b0fd77598a6edb642c028bbd8c5b623
2021-02-08 18:00:56 +01:00
Harald Welte f5d90c46e1 SUA: Verify routing context IE of incoming CL and CO messages
When receiving user-data (connectionless / connection-oriented),
we must make sure that there either
a) no routing context IE in the message, and only one AS within the ASP, or
b) a valid routing context IE for an AS within the ASP

This important input validation has been done in M3UA for a long time,
but somehow never been implemented on the SUA side so far.

Change-Id: Icc232250513009137add3b45fecbb5d2a07c0645
2021-02-08 11:42:33 +01:00
Harald Welte a0228a74e0 m3ua: Move find_as_for_asp() to shared xua_find_as_for_asp()
This way the function can be re-used by SUA.

Change-Id: I0dfc5a7a24dd068002e837dc47eb0778c503cac5
2021-02-08 11:42:30 +01:00
Harald Welte aabb38a77b m3ua: re-factor m3ua_rx_xfer(): Externalize AS for ASP lookup
Let's factor-out the lookup of the AS into the separate function
find_as_for_asp().  This enables us to reuse this code in upcoming
support for SNM messages.

Change-Id: If58ea24efe7d54994a7ca2f0a97944bd297a8cc6
2021-02-08 10:41:03 +00:00
Harald Welte bdf5ae5f02 Introduce osmo_ss7_asp_get_log_subsys()
This will allow us to write generic code that uses DLM3UA/DSUA depending
on the ASP protocol.

Change-Id: I7c015b3a2727deff4fc4e6f3bc7bdeeb57e86166
2021-02-08 10:40:46 +00:00
Harald Welte 1153675012 xua_msg: Add xua_msg*_get_str() to obtain string IE
We copy the contents to a static thread-local buffer to ensure
zero termination of the string received by a remote entity.

Change-Id: I8cbb7aeaf0cb64db0ce01c21e5fca9ab3cd932b6
2021-02-08 10:40:46 +00:00
Harald Welte 2aebd133ac sccp_sap: Fix string for N-PCSTATE primitive
Change-Id: Ib42f46661e27b1730badc3647ca2e021e93021b7
2021-02-07 18:28:48 +00:00
Harald Welte 3bd913398a osmo_ss7: const-ify input arguments to osmo_ss7_as_has_asp()
Change-Id: Id23d90ffea855680cd7d4a16b89e652eed0cf39f
2021-02-07 12:43:47 +01:00
Harald Welte 30c2edb099 xua_msg: const-ify input arguments to xua_*_get_u32()
Change-Id: I517943bd11d73195de9418fb1c5d4151dab77873
2021-02-07 12:43:47 +01:00
Harald Welte c584d87d0c xua_msg_add_data() Mark input argument as 'const'
We only read from it.

Change-Id: I12c17273b9d64a084f59d91fc06ae1512d70855b
2021-02-06 17:45:33 +01:00
Oliver Smith 20642478f3 xua_test: fix gcc 4 + -std=gnu11 error
Fix 'error: initializer element is not constant' with debian 8's gcc
4.9.2, triggered by XUA_HDR. Create a new _XUA_HDR without the type cast,
and use it inside of const struct definitions in xua_test.c. The new
macro is needed, because removing the type cast from the original
XUA_HDR would break other uses.

Related: OS#5004
Change-Id: I890432ee976043d012b01023f7dd2cfecf79d115
2021-02-02 16:22:01 +01:00
Oliver Smith ed11cc8385 configure.ac: set -std=gnu11
Change-Id: Iabe929a29a3c7fed2726329215097f7254cf20ca
2021-01-28 09:28:00 +00:00