Commit Graph

812 Commits

Author SHA1 Message Date
Pau Espin 64dda770c3 Add ss7 instances to osmo_ss7_instances in creation order
Otherwise when configuring ss7 instances in numerical order in the VTY
and then printing the VTY configuration they end up ordered this way:
cs7 instance 2
cs7 instance 1
cs7 instance 0

Related: SYS#5912
Change-Id: Id4d0a20cc5b0811b505b2d1051d496f8bd17d54c
2022-03-29 13:13:56 +02:00
Harald Welte 218789e833 sccp_demo_user: enable stats / rate_counter timers
Change-Id: I135704d401de2cf439e51882e22323b31db14a2a
2022-02-24 20:40:24 +01:00
Harald Welte a1bf0c96ec sccp_demo_user: Allow user to specify logmask on command line
Change-Id: Ie1cf37b3501e26330b038b7ee17a5273d81c92d8
2022-02-24 20:40:24 +01:00
Harald Welte 3424c5ed99 sccp_demo_user: make sure the command-line specified point codes are used
Change-Id: I983066199e5d8f056895fdad370e3b4439b4dba4
2022-02-24 20:40:24 +01:00
Harald Welte d8c7a40a60 sccp_demo_user: Add 'show stats' to VTY
this allows us to inspect statistics of the demo user via VTY

Change-Id: Ica48d4e0c9cedb9adb94ae08c5201207b8836e1c
2022-02-24 20:40:24 +01:00
Harald Welte d0cd3157b7 sccp_demo_user: Add command line argument to specify protocol (m3ua/ipa)
Change-Id: Iecb03df43709903b1cfe248e68d6624b995c563d
2022-02-21 22:27:57 +01:00
Pau Espin 7b4aea4aa6 xua_asp_fsm: Fix gcc false positive warning
As of GCC 11.1.0, it starts printing a warning about uninitialized
variable. It is a false positive since tmode is really only used in the
case where traffic_mode is not zero, in which case tmode is set.

Let's restrict the scope of tmode to fix the issue and also make it
clearer where the variable is used.

"""
In file included from /git/libosmo-sccp/src/xua_asp_fsm.c:25:
/git/libosmo-sccp/src/xua_asp_fsm.c: In function ‘xua_asp_fsm_inactive’:
/git/libosmo-sccp/include/osmocom/sigtran/osmo_ss7.h:274:16: error: ‘tmode’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  274 |         return get_value_string(osmo_ss7_as_traffic_mode_vals, mode);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/git/libosmo-sccp/src/xua_asp_fsm.c:476:39: note: ‘tmode’ was declared here
  476 |         enum osmo_ss7_as_traffic_mode tmode;
      |
"""

Change-Id: I4fc38724aba3a3f178ba0b45444e1394db44d039
2022-02-01 16:59:52 +00:00
Oliver Smith ebccb824a0 osmo_ss7_vty: add osmo_sccp_addr_by_name_local
Add a new function similar to osmo_sccp_addr_by_name, but search in a
specific ss7 instance's addressbook instead of searching in the global
address book. This is needed for osmo-bsc-nat, which uses two separate
instances at the same time.

Related: SYS#5560
Change-Id: I0f38b0d038b0dd8cd355e7284e5b56d438811bd9
2022-02-01 11:08:34 +00:00
Oliver Smith e3e79e2806 include/osmocom/sigtran/sccp_sap.h: cosmetic fixes
Move return type to the same line as the name of the function to follow
coding guidelines.

Change-Id: I10475aa395a1cfd49ff62c758f99f9689a0038d0
2022-02-01 11:08:34 +00:00
Philipp Maier 5cac653a98 sccp_user: do not force the role ASP when configured differently
The current implementation of osmo_sccp_simple_client forces the ASP to
run in ASP role. Even then when the user has configured it differently
via VTY. The osmo_sccp_simple_client should respect the VTY
configuration.

Change-Id: Ib57c513407747d36e503a4fb01c50c69dea0cb85
Related: SYS#5796
2022-01-26 11:02:02 +01:00
Pau Espin d9e54d7a34 xua_default_lm_fsm.c: Fix typo in comment
Change-Id: I4095878fb05c3128be556ab36dfc7ab88d309c9a
2022-01-21 10:57:03 +01:00
Oliver Smith 853ce2ec13 osmo_ss7_instance_destroy: use for_each_entry_safe
Fix segfault in each loop.

Change-Id: Ieaec3584375b0e6b943638fe1e50b4d74a627216
2021-12-21 18:58:20 +01:00
Oliver Smith 0aa3164b93 src/sccp_scmg: fix typo
Change-Id: Ifd6264da2da2e7cc62485dcde9b6c462d4858626
2021-12-21 18:58:20 +01:00
Oliver Smith 043275129c treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: Ia450b630e0b60b38835f599c93985bbe97c50d2f
2021-12-14 12:54:05 +00:00
Pau Espin 77700b6eb5 ss7: Use sctp value_string from libosmo-netif
Depends: libosmo-netif Change-Id Ica6f01851fb94e31f4ef097494bb1b8a95597ba6
Change-Id: I42323eb5d02d4f67daac7b0a4365f5f6f6057666
2021-11-23 15:50:04 +01:00
Pau Espin 2d9e84b703 Bump version: 1.4.0.39-484f-dirty → 1.5.0
Change-Id: I963499ba9f78924660127312f4469b0781fed805
2021-11-16 14:44:42 +01:00
Harald Welte 484fc3875b osmo_ss7: properly unlink rate_counter on AS/ASP free
When introducing rate_couters, I forgot to call
rate_ctr_group_free().  I thought free'ing the parent object
via talloc is sufficient, but that obviously misses the point that
rate_counters have an internal linked list from which they must be
unlinked.

Change-Id: I8d27f025c22776d0153d867e36c073ef716eb974
2021-11-16 11:20:11 +01:00
Harald Welte e9727688cd rate_ctr: Use legal counter group prefixes / names (no '.' allowed)
This avoids log messages like
DLGLOBAL <0016> rate_ctr.c:92 'sigtran.as' is not a valid counter group identifier

Change-Id: I08666a1c3c1345cd3b0e55d544f6ac4a6df62fbf
2021-11-16 11:13:11 +01:00
Harald Welte f71096a2b0 spelling fixes in comments
Change-Id: I4ecd9a1c5241cfd3a3e1daf05f7826876371369f
2021-11-15 18:05:04 +01:00
Harald Welte ff7404c742 stp: Add basic RX/TX rate counters on AS and ASP level
This adds some very basic rx/px rate counters to the SS7 AS and ASP

OsmoSTP> show rate-counters
SIGTRAN Application Server 0 (as-rkm-1):
             rx:msu:total:      86078 (1888/s 86078/m 0/h 0/d)
             tx:msu:total:          0 (0/s 0/m 0/h 0/d)
SIGTRAN Application Server Process 0 (asp-dyn-0):
         rx:packets:total:      86081 (1888/s 86081/m 0/h 0/d)
         tx:packets:total:          5 (0/s 5/m 0/h 0/d)

Change-Id: Idb811ca81adfe47152d484f6b981e661dc569e15
2021-11-15 18:05:01 +01:00
Harald Welte 5ad97995e9 sccp_scmg: Add missing line eneding to log statement
Change-Id: I7ec5c86fbef429cd1e23be87b773823f2e736f2f
2021-11-14 20:36:21 +01:00
Harald Welte 8aa64eb92a sccp: Add minimalistic support for XUDT / XUDTS
XUDT and XUDTS can be used in two situations:

a) because the sender wants to use segmentation
b) because the sender wants to include a hop counter

In this patch, we implement support for case "b" only.

Change-Id: Ic5b9486f1aeb4bb90cfe702a7ce996f5d82ded2c
Related: OS#5281, SYS#5674
2021-10-26 16:27:14 +02:00
Pau Espin 8275949838 osmo_ss7.c: Fix typo in doc for osmo_ss7_asp_peer_add_host()
Change-Id: Idba9ed3dc1d8968d304f88fdb1ebef422dd982e9
2021-10-07 13:38:58 +02:00
Pau Espin f594b7dfd2 osmo_sccp_simple_client_on_ss7_id(): Allow set internally proper IPv4/v6 default hosts
Allow user apps to relay the decision of proper default local/remote
hosts values to the library. Proper configuration of these addresses can
be quite cumbersome to get correctly, or confusing at least. That's due
to the multi-homing feature of SCTP where both IPv4 and IPv6 are
involved.

We were already doing this kind of automatic setup in
osmo_ss7_vty_go_parent(), where we do validations and assign addresses
based on IPv6 availability.
On the other hand, apps using osmo_sccp_simple_client_on_ss7_id() API
usually pass  "localhost" as default address. In Linux, when IPv6 is enabled
localhost is resolved as "::1", and "127.0.0.1" when IPv6 is disabled.

Let's instead allow apps to relay the setup to the lib, so same addresses
can be applied both during VTY command as well as if there was no VTY
setup at all.

Related: OS#5186
Change-Id: I82e203612571b7651d758d8148661f706a1642ba
2021-10-07 13:38:32 +02:00
Pau Espin c83f3a870d cosmetic: Fix typos in documentation
Change-Id: I1164490c140cc5ca82e5977d24f5971ba216014b
2021-10-05 16:09:24 +02:00
Pau Espin 4dfb938f9c cosmetic: Fix extra empty line
Change-Id: Ibd499fc9376523e6dcfe8ba6792603c237db59f5
2021-10-05 15:59:02 +02:00
Oliver Smith 76985a9aa2 m3ua: fix m3ua_encode_dupu
Fix wrong header and swapped user / cause values (see RFC 4666). This
makes TC_ssnm_distribution_dupu pass.

Change-Id: I717b64d13d12a2781c90e4d2f83643331797bed4
2021-07-23 17:13:19 +02:00
Oliver Smith 1a75755f9b m3ua: reject deregistration of static routing keys
Make STP_Tests_M3UA.TC_rkm_unreg_never_registered pass.

Closes: OS#4239
Change-Id: Ie5d84d06e7d5d32c8a22f770f71a5449f4a78484
2021-07-23 10:02:16 +02:00
Eric Wild 387304c41d m3ua: fix leaky usage of m3ua_tx_xua_asp
m3ua_tx_xua_asp will at some point convert the xua msg to a msgb by
copying and then send it, the xua msg still needs to be freed by the
caller.

Closes: OS#5185
Change-Id: Id8584b99f30f2db602d4d129e4114821697272ab
2021-07-11 21:10:21 +02:00
Philipp Maier b3cb0c14bb osmo_ss7_vty: allow users to inspect routes also in ASP role
When libosmo-sigtran runs in ASP role, then the entire routing table
introspection (show) and routing table configuration VTY commands are
not present. Editing the routing table manually only makes sense in SG
role, but it is still useful to be able to inspect the routing table in
ASP and SG mode.

Change-Id: Ieaef4f0344b5b77ff5047013e9da1e938004e97c
Related: SYS#5392
2021-06-17 15:51:29 +02:00
Philipp Maier b4f1b2cb8b osmo_ss7_vty: automatically create routes for routing key
Operators may set up a routing key in each AS node. However, this does
not mean that there is also a route added to the routing table. If the
default route is not sufficient (e.g. if multiple AS are defined), then
operators are epected to put matching routes into the routing table.
However, when libosmo-sigtran runs in ASP role, the VTY commands that
allow to routing table changes are not present.

In an ASP role we are in an endpoint situation, so no complex routing
is required, in most cases (single AS) even the default route is enough
but to ensure that each AS will get a route, add routing tables
automatically when running in ASP role.

Change-Id: Ic60b36983232308250e591dbad576aaafdd6b586
Related: SYS#5392
2021-06-16 17:53:04 +02:00
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