Commit Graph

35 Commits

Author SHA1 Message Date
Harald Welte 189515f199 rspro_client_fsm: Fix integer overflow calculating re-establishment delay
Fixes: CID#307493: Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
Change-Id: Ib1cca5ac0d27807936a52e0c013f0442350ecc00
2023-07-18 13:34:14 +02:00
James Tavares b890018456 rspro_client: implement re-establish delay
- add new SRVC_ST_REESTABLISH_DELAY state with delay stipulated by table
k_reestablish_delay_s[], that implements a simple exponential-like back-off
with an upper bound.
- new function srvc_do_reestablish() is used to initiate a reestablish, and
apply the appropriate delay, if any.
- takes external delays (such as TCP connect() delay) into account, and does
not double-penalize.
- delay is reset to shortest possible if there has been no reestablish
initiated in a long time (2x greater than our longest delay). Allows for
fast reconnects even if a delay was used to connect.
- addresses issues https://osmocom.org/issues/5348 and https://osmocom.org/issues/5610

Change-Id: I86cdc3ba37482e6577b429194d273a2399f32208
2022-11-19 09:21:04 +00:00
Harald Welte f5f5805f0c rspro_client_fsm: Log clientConnectResult != ok
This should aid debugging.

Related: SYS#5950
Change-Id: I8f584640758be0cceab61dcb333c81374da3288b
2022-05-05 19:19:33 +02:00
Harald Welte a9bb9a9348 cosmetic: various typo/spelling fixes
Change-Id: Idc4db138d83be0c7c0b0ff6dfbb9f094b21d6fa9
2022-05-03 18:09:14 +02:00
Oliver Smith 0c832fe737 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: I2e98f89f6738d03c45a2106820af0912692093f3
2021-12-14 12:20:35 +01:00
Harald Welte 46122ab94e Add separate log category for RSPRO protocol
Change-Id: I2e158f5181a24ae2256aae12d26865c4907eabad
2021-12-08 21:16:00 +01:00
Harald Welte 8934412ce5 rspro_client_fsm: Differentiate different log levels
Raw Rx/Tx of messages should be LOGL_DEBUG, while connection
establishment/loss should be something like LOGL_NOTICE.

Change-Id: I1bc6d491a8a748cbd729cbdeede60d32bd760a15
2021-12-08 20:44:26 +01:00
Harald Welte 0e968cce38 client: major restructuring around new main_fsm
The remsim_client code already used FSMs for the connections
to both remsim-server and remsim-bankd.  However the 'main' part of the
program was not yet implemented as a FSM, making it somewhat difficult
to perform the right actions in every possible situation.

This commit re-structures the code around a central main_fsm, which
gets notified from the per-connection FSMs and which handles the common
processing.  It also handles the execution of external script commands,
and hence further unifies the code base between the different backends
(simtrace2, ifd_handler, shell)

Closes: #4414

Change-Id: I44a430bc5674dea00ed72a0b28729ac8bcb4e022
2020-03-04 18:02:21 +01:00
Harald Welte b266d508be rspro_client_fsm: Add optional notifiation of parent on connect/disconnect
This will be useful once we introduce a 'main' client FSM that is a
parent to the rspro_client_fsms.

Change-Id: Ifddb8e0b5c991e5348392c9e44612669ce207bc4
2020-03-04 16:21:34 +01:00
Harald Welte 8da220911d rspro_client_fsm: Migrate to ipa_client_conn_create2()
libosmo-abis 0.8.0 has deprecated ipa_client_conn_create() and this
follow-up patch avoids the related deprecation compiler warnings.

Change-Id: I0057c5b6a79e7226e87983c14eb2b0ed2af2a131
2020-03-04 16:21:34 +01:00
Harald Welte 16c81ea52b rspro_client_fsm: Add SRVC_E_DISCONNECT to disconnect from RSPRO server
This is in preparation of other patches which will actually issue the
SRVC_E_DISCONNET event towards this FSM.

Related: OS#4399
Change-Id: I080f9e85987bbbe7aef84c32ce84b69d949ff561
2020-02-18 23:02:51 +01:00
Harald Welte f7598fe417 remsim-client: move from common 'src' directory to 'src/client'
As both the bankd and the server already are in src/bankd and
src/server, respectively: Let's unify this and have the client
also in its own sub-directory.

Change-Id: I67a3a5941434f09f7099c2cdb19c126cea305a73
2020-02-16 15:41:12 +01:00
Harald Welte b8ec65ae8f rspro_client_fsm: Fix handling of IPA keepalive
We cannot rely on the implicit IPA keepalive FSM termination, as that
somehow gets the termination order wrong and we end up accessing free'd
memory.

Let's handle the termination explicitly:  We register a callback with
the IPA keepalive FSM, and once that callback gets hit, we ask the
core to *not* terminate the FSM implicitly.  We are anyway terminating
it explicitly in st_reestablish_onenter().

Change-Id: Ia745ccb44c0d0224d1e7ab6b6da3713474111d41
2019-12-15 00:11:43 +01:00
Harald Welte 9cdd094516 rspro_client_fsm: Fix uninitialized return variable use
rspro_client_fsm.c:180:9: warning: ‘rc’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  180 |  return rc;
      |         ^~

Change-Id: I64b275b06b2aa40bd7c6e1dd42afba5ffebd7b00
2019-12-15 00:11:43 +01:00
Harald Welte 071892974a rspro_client_fsm(): Remove outdated/wrong comment from code
Since Change-Id I55d5d61922053fd94e2b5a8cdf0d799b29feec98,
rspro_dec_msg() is no longer taking ownership of the msgb.

Change-Id: Ic1e9f35a2ae82b28dbb4b2ba850c257fa9629cbf
2019-12-15 00:06:09 +01:00
Harald Welte 6d61b166c8 rspro_client_fsm: Mark ipa_client_conn_send_rspro() as static
Change-Id: Icc2f9e984dee4a2f1f604beee6c9081ecf032dd2
2019-12-15 00:06:09 +01:00
Harald Welte a3b14d1890 rspro_client_fsm: Make RSPRO transmit use FSM event
This way we can easily guarantee that RSPRO transmit will only happen
in the fully established state, and that violations of that rule will
generate error logs by means of osmo_fsm core logging code.

Change-Id: I3c403507fa11c068d7503107857fbd5676ce135f
2019-12-05 08:56:27 +01:00
Harald Welte d2192e27ce rspro_client_fsm: Disable automatic connect on FSM allocation
So far, the rspor_client_fsm immediately attempted to establish a
TCP connection to the RSPRO server when calling server_conn_fsm_alloc().

Let's make this implicit auto-connect an explicit request to connect
using the newly-introduced SRVC_E_ESTABLISH.

Let's also change all three existing users of server_conn_fsm_alloc()
to send SRVC_E_ESTABLISH after calling it.

The rationale of this change is to use the same rspro_client_fsm also
for the client->bankd RSPRO connection, where we don't want to
automatically connect at startup, but connect only at a later point, after the
server a has told us to do so.

Change-Id: Icd882405f2ef54e10a66054829c089e4985f1d1f
2019-12-05 08:56:27 +01:00
Harald Welte 0a68497324 cosmetic: more comments; spelling fixes in comments
Change-Id: I4939a386ac48e4e66bce9784d9a1539426c41aae
2019-12-02 23:10:31 +01:00
Harald Welte 4ccd2fca84 Check for osmo_fsm_register() error return value
Change-Id: Idda1a4050cf9d285225ae48a4ba6f48c04f9598b
2019-12-01 13:34:32 +01:00
Harald Welte 573a5b9ed9 rspro_dec_msg: Simplify msgb ownership handling
Initially it seemed like a good idea that rspro_dec_msg() takes care
of freeing the input msgb when generating a new decoded output
structure.  However, in reality this made the implementation of
every caller more complicated, as it had to treat messages going into
rspro_dec_msg() differently than messages going elsewhere.

Adding to that, not every caller got it right, and the comments were
disagreeing about what happens to msgb ownership in erroneous cases.

Change-Id: I55d5d61922053fd94e2b5a8cdf0d799b29feec98
2019-09-12 20:27:58 +02:00
Harald Welte cacbc2b37d rspro_client_fsm: Fix another memory leak
We basically must ensure that all code paths *except* the path leading
to rspro_dec_msg() must call msgb_free(msg).  This was not the case
in two situations, as fixed now.

Change-Id: I29f8413bb43b3ebf827be0bceda1a4db1e6e2b7c
2019-07-24 18:42:02 +02:00
Harald Welte 9392e08011 rspro_client_fsm/remsim_client: Fix double-free
respro_dec_msg() takes ownership of the input msgb in both
successful and unsuccessful cases, so we must not call talloc_free
on the resulting msgb.

Change-Id: Id54d1b73395da1329a998d213c190da49eb90a93
2019-07-23 18:16:40 +02:00
Harald Welte 1b86ba81a0 rspro_client_fsm: Fix memory leak processing RSPRO
Change-Id: I2c3710d152ce31d293a3693a70718c8712e2ac2b
Closes: OS#4097
2019-07-18 19:05:33 +02:00
Harald Welte f51166790e cosmetic: remove some FIXME that actually are already fixed
Change-Id: I62ac36aae6da374b83e27b71ff52b0c3d52bf346
2019-04-02 20:56:16 +02:00
Harald Welte 4fa407a750 bankd: Use configured bank_id/nr_slots in ConnectBankReq
The code used hard-coded defaults instead of the user-configured values.

Change-Id: I86383aed4d5bb08ac1540eaecc0975a18e560baa
2019-04-01 21:07:02 +02:00
Harald Welte a8b86ceff2 client/server: log failed attempts to transmit/encode RSPRO
Change-Id: Iac56ddf7417fdee637660db34a7f0e6bdb9c4ab5
2019-03-31 14:59:20 +02:00
Harald Welte 2eee4507ca bankd/client: Fix memory leak if rspro_enc_msg() fails
Change-Id: Ib72b077d82939be0627b9dd7c905fb2a33db9ca5
2019-03-30 08:50:35 +01:00
Harald Welte e57334ed9d rspro_client_fsm: Use osmocom logging API instead of direct printf
Change-Id: Iaf004e1839340371052d4e36baed4faee9f3744e
2019-03-27 22:58:10 +01:00
Harald Welte 4e7a285427 rspro_client_fsm: Disconnect if Connect{Client,Bank}Res != ok
Change-Id: Id199f9c4cb4c86fd0dba8939334ac69878f4a3f5
2019-03-17 21:01:50 +01:00
Harald Welte a025e7008d rspro_client_fsm: Ensure close + reconnect on missing Connect*Res from server
Change-Id: I7f9bbdf246eb206342bd94be0b13ae45dd40084e
2019-03-09 21:39:09 +01:00
Harald Welte b49ac9c6bb rspro_util: Add rspro_msgt_name() to get RSPRO message type name + use it
Change-Id: I4b270addd024f9766923183a75381b71ffe1cfae
2019-03-09 20:36:07 +01:00
Harald Welte a844bb07d8 Introduce {server,bankd}_conn_send_rspro()
Change-Id: I8cae6f67567dcbf4b6d62fb5a76f5b7134b16f5d
2019-03-09 13:40:34 +01:00
Harald Welte 3dcdd20343 add missing copyright / license headers everywhere
Change-Id: I5c1fceead0ee799a948995f55c6ebee441cfb79a
2019-03-09 13:11:56 +01:00
Harald Welte 3cded63aa6 naming: Distinguish "rspro client" from "remsim client"
"remsim-client" is the client program running next to a phone/modem
which is attaching to the SIM slot.

"RSPRO client" is a protocl-level client of the RSPRO protocol:
* the remsim-client connects as RSPRO client to the remsim-server
* the remsim-client connects as RSPRO client to the remsim-bankd
* the remsim-bankd connects as RSPRO client to the remsim-server

Let's clarify this in naming.

Change-Id: I10462d4669a0a30c46f3f8d3df67e9c1d4ce8c4b
2019-03-09 13:11:56 +01:00