Commit Graph

115 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
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
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
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
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 4dfb938f9c cosmetic: Fix extra empty line
Change-Id: Ibd499fc9376523e6dcfe8ba6792603c237db59f5
2021-10-05 15:59:02 +02: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 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 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 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 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
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 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 3bd913398a osmo_ss7: const-ify input arguments to osmo_ss7_as_has_asp()
Change-Id: Id23d90ffea855680cd7d4a16b89e652eed0cf39f
2021-02-07 12:43:47 +01:00
Pau Espin d94d58c523 Fix matching IPv6 anyaddr :: in osmo_ss7_asp_find_by_socket_addr
Change-Id: I36dd8f1978e3b7b785660745378c9cf77a21a566
2020-08-28 17:14:32 +02:00
Pau Espin 2d5b4ef2be Validate correctly against IPv6 addresses in osmo_ss7_asp_peer_set_hosts()
Until now, host list validation was only taking into account a set of
ipv4-only addresses. As a set can contain now IPv4 and Ipv6 addresses at
the same time, we need to do ANYADDAR validation against addresses of
that specific version inside the set.

Change-Id: I18f3cc59149d478259d7afc456bdc5213c1406e5
2020-08-28 17:14:32 +02:00
Pau Espin ce88150c05 Fix finding ASP on IPv6 connections
Change-Id: I09226a5cecc37dd4676acd61c2051befe5234cb3
2020-08-24 10:34:54 +02:00
Harald Welte e80adc7039 osmo_ss7: remove use-after-free of stream_server after close_cb
In I9b3ae6dfcf6efeabb7fb6c33503d1d7924fec2fa we fixed some problems
regarding rapid open/close cycles of inbound M3UA client connections.
Unfortunately the fix now triggered another bug.

xua_srv_conn_closed_cb() is called by libosmo-netif stream code whenever
a connection (socket) is closed.  As the stream_server is de-allocated
right after this call-back, the call-back must make sure to remove
any pending references to the stream_server.

Change-Id: I2464cf524f1f91bfad10ff1861a03bf1461dfed8
Related: OS#4625
2020-06-25 13:15:09 +02:00
Harald Welte 6ebfc047dd Fix race during fast re-establishment of inbound M3UA connections
When a client closes and instantaneously re-opens a SCTP socket for an
M3UA connection, there is a chance that both the "shutdwon event" (old
connection socket becomes readable for sctp event) and the "init event"
(listen-fd becomes readable) happen during the same scheduler interval /
select() cycle.  As there is no guaranteed order by which we call our
file descriptor callbacks, it means that we may end up processing
then new connection (accept) before we get the notification that the
old one is dead.

The fact that the fd number of the accept-fd is mostly lower than the fd
number of the individual per-client connection actually makes it likely
that the order is exactly the opposite of what would feel "logical".

As the ASP is identified by the tuple of (src-port, src-ip, dst-port, dst-ip),
both the old connection and the new connection map to the same ASP
object.  So we need to handle this situation gracefully:  If we get a
new connection for a tuple that we already [think we still] have one,
close the old one and use the new.

Change-Id: I9b3ae6dfcf6efeabb7fb6c33503d1d7924fec2fa
Closes: OS#4625
2020-06-24 21:36:54 +02:00
Pau Espin 4c273d6437 ss7: Improve checks in osmo_ss7_asp_peer_add_host()
* Introduce check to make sure we don't write out of peer->host bounds.
* Clean up any/specific address checks, it should be more clear now.

Change-Id: I3ecb94267acbec6ecf2134b08110f24f131cd8cf
2020-01-13 12:58:35 +01:00
Pau Espin 191a305cb5 ss7: Set ASP addresses using asp_peer APIs
Change-Id: I4736cb107a1987dab123744b98fb2b06a5e1167a
2020-01-13 12:43:59 +01:00
Pau Espin 7b56b75f36 ss7: Introduce APIs to manage asp_peer hosts
The code managing addresses is decoupled from xua_server since they will
also be used to manage addresses for ASPs.

Change-Id: I4af2a6915ac57c7baa67343bd9414c65154d67f7
2020-01-13 12:41:51 +01:00
Pau Espin 3862b32fd1 ss7: Return value from child function in osmo_ss7_xua_server_set_local_host
It doesn't really change old behavior since it's impossible the child
function returned an error with current implementation, but let's better
return the return code in case new error paths are added.

Change-Id: I24747578b3412b385c1ea1a14922f543f9023a27
2020-01-13 12:27:13 +01:00
Harald Welte a4555c3430 check for osmo_fsm_register() failures and propagate error
Change-Id: Id8861144e4880383a173b7e6ae7860beebac09d9
2019-12-01 17:36:50 +01:00
Harald Welte 58de416ff0 osmo_ss7: Add osmo_ss7_asp_find()
This is like osmo_ss7_asp_find_and_create(), i.e. it's doing a full
match for an ASP within the specified SS7 instance, of the specified
port numbers.  It just doesn't create it if it is missing.

Change-Id: I1ed3cf2b69ee622d6f9d8b50487f392fe913ae90
Related: OS#4271
2019-11-19 01:28:05 +01:00
Vadim Yanitskiy c19962e1e1 osmo_ss7_vty.c: implement 'active' filter for show_cs7_as_cmd
Change-Id: I356d90642a500be6a70f60c8240ce1211fd0d934
2019-11-14 22:31:40 +00:00
Pau Espin 30275e13ef ss7: Set correct local addr and port during dynamic ASP creation
Change-Id: I54aada351d5fb74f5015fdfe691d0b237354743c
2019-11-12 14:18:39 +00:00
Pau Espin 6090d7e6b7 ss7: Improve log formatting during ASP restart
Since it may act sometimes as a server and sometimes as a client, let's
better use one more neutral (2-side arrow) connector, and mark which
address is the local and which is the remote. We already use same
formatting in other osmocom code.

Change-Id: I42feaa16790f02b98bcda65281de8cd9295ddcb6
2019-11-12 14:18:39 +00:00
Vadim Yanitskiy ed6cc3e51e osmo_ss7.c: fix xua_accept_cb(): properly assign role
Most likely, we want all dynamically allocated ASPs to play the SG
role by default. Otherwise when using the following configuration:

  cs7 instance 0
   xua rkm routing-key-allocation dynamic-permitted
   listen m3ua 2905
    accept-asp-connections dynamic-permitted

both OsmoMSC and OsmoBSC fail to establish connections.

Change-Id: Ib904ecf0e5d192a1024863f6f0fdf79301055655
Fixes: I2df9cd9747ad5c9a05d567d9a71bab6184c53674
Related: OS#4247
2019-11-06 15:53:59 +00:00
Vadim Yanitskiy bd8dff2751 osmo_ss7.c: fix copy-paste error in xua_accept_cb()
Change-Id: I3d991849459378b35a5b4f248cc208f956e494be
2019-11-06 22:02:31 +07:00
Vadim Yanitskiy 348af264d2 osmo_ss7.c: cosmetic: fix typo in xua_accept_cb()
Change-Id: Id925d09b9232b5e0124b977fa482e8cdc3c8b835
2019-11-06 19:34:21 +07:00
Pau Espin 6c4fabc826 xua: loadshare: select ASP for tx only if active
Change-Id: I4f1d1aa9395698e5b6b930a5092a4b914dd15fb3
2019-11-06 04:55:37 +00:00
Harald Welte 1a822635f8 Allow ASP role to be configured
So far, we had a static role model:
* SCTP servers (listening, such as OsmoSTP) are role SGW
* SCTP clients (connecting, such as OsmoMSC) are role ASP

While this is customary, it is not actually required by the
specification.  The SGW can establish the SCTP connection to an ASP
but still remain "SG" role.

Let's make things more flexible by having the role configurable.

Related: OS#2005
Change-Id: I2df9cd9747ad5c9a05d567d9a71bab6184c53674
2019-11-05 20:50:51 +00:00
Harald Welte 79fb8a66f3 introduce public enum osmo_ss7_asp_role for ASP/SG/IPSP
This supersedes the library-internal enum xua_asp_role.

Change-Id: I28b0888b8f8206e9dd67ef64ce0f71ba9a7105ce
2019-11-05 20:50:37 +00:00
Harald Welte ebd2fc6046 M3UA: Reject ASP activation + RKM registration for incompatible traffic-mode
If the AS is e.g. configured as broadcast, then individual ASPs cannot
be activated in loadshare or override.  Everyone must agree.

Change-Id: Ic73410fbc88d50710202453f759fa132ce14db4c
2019-11-05 20:50:26 +00:00
Pau Espin 2b139a65f0 ss7: Only override traffic mode from recv REG REQ if not set by VTY
RFC 4666 (SS7/MTP3/M3UA) states in isection 4.3.4.3 ASP Active Procedures:
"""
If the traffic handling mode of the Application Server is not already known via
configuration data, then the traffic handling mode indicated in the
first ASP Active message causing the transition of the Application
Server state to AS-ACTIVE MAY be used to set the mode.
"""

In section 3.6.1 Registration Request (REG REQ), no related information
is provided on how to handle it, but still makes sense to apply same
behavior as in 4.3.4.3.

Related: OS#4220
Change-Id: Iaebe3a93ad8d2d84ae01e41b02674f8ece9dfc95
2019-10-24 13:23:09 +02:00
Pau Espin c99724a9ec ss7: Set default traffic-mode to override
Change-Id: I8570ed6634eb20c0f9e4b712de6592b6c3b77227
2019-10-24 13:23:09 +02:00
Harald Welte d98960d189 Log correct protocol during xua_accept_cb()
This function is used for both actual SIGTRAN (M3UA, SUA over SCTP)
as well as for IPA/SCCPLITE (over TCP).  Having a static "SCTP"
string in the log lines is confusing.

Change-Id: Ic34ddbcd528cd871d9772665e1d0863896f33203
2019-10-23 18:11:17 +00:00
Pau Espin f0a0a4cdd7 ss7: Fix finding asp by socket addr if it has no remote hosts configured
Fixes: 80b1355819
Change-Id: I14a0132a4667cea75fc212dfeeef76d8509b991d
2019-10-23 18:10:10 +00:00
Pau Espin 6168660986 ss7: Fix finding asp by socket addr if local ip addr is 0.0.0.0
Fixes: 80b1355819
Change-Id: I319e4983b35f63846ed7e8bfa8e8e3688c5d16e6
2019-10-23 18:10:10 +00:00
Pau Espin 51efa023c9 ss7: Fix osmo_ss7_asp_peer_snprintf() output if peer has zero IP addr assigned
If no IP addr is assigned yet, until know it'd print "(:3456". Let's
print ":34456" in that scenario.

Change-Id: Iae85d231093b6f3ce6b969324699858e525c14ea
2019-10-23 18:10:10 +00:00
Pau Espin dec38c1416 ss7: Log local and remote address set upon ASP restart
Change-Id: I35c2581923ed3e1f7aff6c137ddf356882bac621
2019-10-22 19:38:53 +00:00
Pau Espin 80b1355819 ss7: Support multiple addresses in SCTP connections
After this patch, Several "local-ip" and "remote-ip" lines are accepted
under "listen" and "asp" VTY nodes, allowing to configure an SCTP
connection with multiple connections, hence allowing control of SCTP
multi-homing features.
libosmo-sccp clients such as osmo-bsc and osmo-msc also gain support for
this feature with this commit.

Related: OS#3608
Depends: libosmocore.git Ic8681d9e093216c99c6bca4be81c31ef83688ed1
Depends: libosmo-netif.git I0fe62f518e195db4e34f3b0ad1762bb57ba9d92a
Change-Id: Ibd15de7a4e00dbec78ff2e2dd6a686b0f3af22de
2019-10-22 19:38:53 +00:00