Commit Graph

11 Commits

Author SHA1 Message Date
Pau Espin 28d3a53dc5 cbsp/sbcap: Fail if trying to Tx on non-connected (connecting) link
This way upper layers know right away that the message could not be
transmitted to that peer.

Change-Id: I1d2285d18ee064fd78191765e8cb833bf5ee08a4
2022-08-02 11:48:59 +02:00
Pau Espin caba7fc493 cbsp/sbcap: Set link fsm id with peer's name
Otherwise the id is left unset.

Change-Id: I8a6850293cbe01c66e4fb545d646d63743ddaecb
2022-08-02 11:48:59 +02:00
Pau Espin cb4e11f984 cbsp: Fix heap-use-after-free closing cli conn in connecting state
if conn is not in STREAM_CLI_STATE_CONNECTED state, it won't call disconnect_cb during
osmo_stream_cli_destroy(), hence the osmo-cbc pointers holding are not
nullified correctly.

"""
20220801174147247 DCBSP NOTICE ttcn3-bsc-server: Disconnected. (cbsp_link.c:101)
20220801174147247 DCBSP NOTICE ttcn3-bsc-server: Reconnecting... (cbsp_link.c:102)
20220801174147247 DLINP INFO [WAIT_RECONNECT] osmo_stream_cli_reconnect(): retrying in 5 seconds... (stream.c:287)
20220801174152235 DCBSP DEBUG CBSP-Link[0x612000002c20]{RESET_PENDING}: Timeout of T3 (fsm.c:317)
20220801174152236 DCBSP DEBUG CBSP-Link[0x612000002c20]{RESET_PENDING}: timer_cb requested termination (fsm.c:327)
20220801174152236 DCBSP DEBUG CBSP-Link[0x612000002c20]{RESET_PENDING}: Terminating (cause = OSMO_FSM_TERM_TIMEOUT) (fsm.c:332)
=================================================================
==17==ERROR: AddressSanitizer: heap-use-after-free on address 0x6180000024f0 at pc 0x7fbd28a05d01 bp 0x7ffe247352b0 sp 0x7ffe247352a8
READ of size 4 at 0x6180000024f0 thread T0
    #0 0x7fbd28a05d00 in osmo_stream_cli_close /tmp/libosmo-netif/src/stream.c:307
    #1 0x7fbd28a0a5b3 in osmo_stream_cli_destroy /tmp/libosmo-netif/src/stream.c:714
    #2 0x55c3534a0322 in cbc_cbsp_link_close /tmp/osmo-cbc/src/cbsp_link.c:356
    #3 0x55c3534a16e1 in cbsp_link_fsm_cleanup /tmp/osmo-cbc/src/cbsp_link_fsm.c:199
    #4 0x7fbd28bf5085 in _osmo_fsm_inst_term /tmp/libosmocore/src/fsm.c:947
    #5 0x7fbd28be6881 in fsm_tmr_cb /tmp/libosmocore/src/fsm.c:332
    #6 0x7fbd28bc70ab in osmo_timers_update /tmp/libosmocore/src/timer.c:269
    #7 0x7fbd28bcba5b in _osmo_select_main /tmp/libosmocore/src/select.c:394
    #8 0x7fbd28bcbb31 in osmo_select_main /tmp/libosmocore/src/select.c:438
    #9 0x55c35348bce8 in main /tmp/osmo-cbc/src/cbc_main.c:314
    #10 0x7fbd27a4cd09 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26d09)
    #11 0x55c353488ce9 in _start (/usr/local/bin/osmo-cbc+0x68ce9)
"""

Change-Id: Ic13578e958345207892465644b5e1f28537c032d
2022-08-01 20:36:49 +02:00
Pau Espin 20705a0877 cbsp/sbcap: Fix memleak in error condition (tx without link)
Change-Id: I95f6ab4e642529afc583b0747450b83af1e8f32e
2022-08-01 10:54:02 +02:00
Pau Espin e86af042fd Propagate error to caller when tx cbsp/sbcap Write-Replace-Req fails
Change-Id: Ie40c8e41c297398bbec48f7bb2c60cfdc703fa5d
2022-07-29 17:55:33 +02:00
Pau Espin 3ef5020007 Support CBSP/TCP and SBc-AP/SCTP client mode
This patch adds support to set up a CBSP link so that osmo-cbc connects
as a TCP client to the BSC, which runs as a TCP server.
Similary, support to set up a SBc-AP link so that osmo-cbc connects
as a SCTP client to the MME, which runs as SCTP server.

A new "mode (client|server|disabled)" VTY command is added to use one
mother or the other, and also to disable the link and hence the peer
until it is set again. This is useful if the peer is under manintenance
for instance.

client sockets are created automatically when the "peer" vty node is
exited if the link is not yet created, hence creating it at startup or
if moved back from "disabled" mode. If client socket dies, it will
keep attempting reconnect every 5 seconds.

Related: OS#4945
Change-Id: I3ec54b615b41b56f7a9c64298e3fcaac37f4b60e
2022-07-25 16:27:26 +02:00
Pau Espin a97e166ee7 Split cbsp/sbcap server socket creation from struct allocation
This will be needed when we add client support, since clients will
require the mgr structs to be available during VTY parsing.

Change-Id: I14e49d8d2e603925d7f06a7edb710c0eceb02ea3
2022-07-22 16:13:15 +02:00
Pau Espin 678a9cb385 Refactor {cbsp,sbcap}_cbc_accept_cb
Delay allocating the structures until really needed.
First do checks agains the opened connection, and if an issue is
detected simply close the fd.
Next, fetch or allocate the related peer.
Finally, create the link from the fd.
This makes it easier to add early extra checks later when peers will
contain info on link_mode (client|server|disabled) later on.

Change-Id: Id4f83ec6b0b14e556b1caa9c80e7f68d062fec57
2022-07-21 20:33:38 +02:00
Pau Espin 351b2c8c2b Use cbc_{cbsp,sbcap}_link_close when possible
This way we abstract whether the underlaying stream is a TCP/SCTP client
or server.

Change-Id: Ie020b9b5ee93ae8d0c9e7266177728185e8635f2
2022-07-20 20:27:50 +02:00
Pau Espin 907c4013c4 Rename fields in cbc_{cbsp,sbcap}_mgr
* link -> srv_link to avoid confusing with cbsp/sbcap links
* clients -> links, since it holds links, which in the future will be
  both TCP/SCTP clients and servers.

Change-Id: I4717f49413af45b45059c1601a667f4161b4ca8a
2022-07-20 20:16:35 +02:00
Pau Espin 5f6dfe77d4 Rename {cbsp,sbcap}_server(_fsm).h s/server/link/
Change-Id: I1e56dd1fcba23f6efd209e9d4dcdc88c8866d250
2022-07-20 20:10:16 +02:00