Commit Graph

209 Commits

Author SHA1 Message Date
Pau Espin b4f7404b6c cbc_vty: write peer config nodes at the end
This way we end up with more "global" configs at the start of the file,
which are read/applied first, and later all the per-peer information,
which is a list of variable length.

Change-Id: I7623ea5874552e57764327e94a9c3a4de7b71d67
2022-07-21 20:33:42 +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 85bc27d394 cbc_vty: print correct protocol when writing config
Change-Id: Id9fc0b42827f9a74ff1de4b35339de02aeeefee2
2022-07-20 21:02:53 +02:00
Pau Espin 053018abeb cbc_vty: Use value_string to define proto names used in vty
This will be used in other places in a follow up patch.

Change-Id: I125c7e5ca1f86c2ef390a85975465330c3ae1eb0
2022-07-20 21:02:21 +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
Pau Espin d3be026b93 Rename CBSP,SABP,SBcAP structs and APIs
Rename osmo_*_cbc -> cbc_*_mgr:
Now they only hold TCP/SCTP server related conns, but will also hold
TCP/SCTP client conns in the near future.

Rename osmo_cbc_*_client -> cbc_*_link:
The term "client" is confusing, since it doesn't exist in CBSP/SBcAP,
and will later support connecting to server at TCP/SCTP level.
Let's use "link" instead, similar to what's used in osmo-bsc which
already supports both TCP client and server modes.

Change-Id: Ia9d26dc1593c8ee08dce348fe9f5f4c9398ea2a5
2022-07-20 20:10:13 +02:00
Pau Espin 0f17a212d1 cbsp_server.c: Drop unused code
This will be properly implemented soon.

Change-Id: I5165e3c64d2c933027019264f68f94fb0c18e0e9
2022-07-20 19:48:02 +02:00
Pau Espin 782d431068 sbcap_server.h: Remove unused fields
Change-Id: I3086a264557b976985d166e56fb7f70ad96b81df
2022-07-20 19:23:36 +02:00
Pau Espin 881d5bab4b Get rid of internal.h
Let's create missing header files and move stuff around to have a clear
view of who implements what.

Change-Id: Ib32091d716b33bca58e2d3acf8840b52824c0bd3
2022-07-20 19:23:36 +02:00
Pau Espin 36be606dd4 Split cbc_message related code to its own .c and .h file
Change-Id: I41f6e169b1ee6731cd472f6b72ea922260e30ceb
2022-07-20 19:23:36 +02:00
Pau Espin 28ccced217 Move vty stuff to its own header cbc_vty.h
Change-Id: Ib793a74befb7eaad66d19967c28acb4baf52ea69
2022-07-20 19:23:36 +02:00
Pau Espin a346b88b42 Move function defined in rest_it_op.c to rest_it_op.h
Change-Id: I434357d995a3c90342dbc7d2ac7e568c049ff7ae
2022-07-20 19:23:36 +02:00
Pau Espin f9d73a1cc1 cbc_peer: Close SBcAP conn when removing active peer
Change-Id: I50751856ba10640ecf036ab587c5e821d37863e2
2022-07-20 19:23:27 +02:00
Pau Espin 1486ac0191 Split cbc_peer to its own .c and .h files
Change-Id: I41c890d81e76ac1a1c89d42af70a1f0631e9724e
2022-07-20 17:58:45 +02:00
Pau Espin f4741401e2 sbcap_server: Fix double-free of rx msg if conn is destroyed
In sbcap_cbc_read_cb(), if sctp_recvmsg() fails and we end up calling
osmo_stream_srv_destroy(conn), then both conn and client will end up
being freed by sbcap_cbc_closed_cb(), so we cannot use them anymore
after calling osmo_stream_srv_destroy(conn).
Furthermore, since msg was allocated with "client" ctx as parent, it
would also be freed when "client" was freed.
Let's make the logic easier and alloc it under g_cbc, which is
guaranteed to always be kept there.

Change-Id: I201f44efa24a514e0087b6dcd01115b9b2b8e9db
2022-07-20 17:58:45 +02:00
Pau Espin f955099737 sbcap_server: Log all sctp notif
Change-Id: Ibe73f1e976f088154c2a20e2c7dd98b39a475c08
2022-07-20 17:58:45 +02:00
Pau Espin 5c39ea182d sbcap_server.c: Remove unneeded goto
Change-Id: I02cf8e7ec05d5189d9c6dcc9a7b1e4def80220d7
2022-07-20 17:58:45 +02:00
Pau Espin 3f7eb33673 Improve example osmo-cbc.cfg file
Change-Id: I585ef7a6195891df36751999ee91ded799612c66
2022-07-20 16:05:01 +02:00
Vadim Yanitskiy bd20466a2e tests/sbcap: fix wrong operator used in OSMO_ASSERT statement
Change-Id: I6fe9080302166ad9bdc305eab736d51496dd1ff8
Related: CID#274972, CID#274971
2022-07-20 05:05:44 +07:00
Pau Espin dcf9014f1d sbcap: Update asn1c skeleton files
Update skeleton files using newest asn1c with APER support [1],
commit eb4cd0c2a891a7dbfe90b4cb8cca545879b6d622.

This contains APER fixes for 32bit architectures.

[1] https://github.com/mouse07410/asn1c/tree/vlm_master/

Change-Id: I9ca556dec639223a8d37badb908fab254826192e
2022-07-19 20:32:50 +02:00
Pau Espin 75f3c1da5a vty: Fix call to OSMO_STRBUF_PRINTF
"""
osmo-cbc/src/cbc_vty.c:61:3: error: format not a string literal and no format arguments [-Werror=format-security]
   61 |   OSMO_STRBUF_PRINTF(sb, peer->remote_host[i]);
"""

Change-Id: I90e7bdbe9f01dae9269ae4850bc2d7391fee71ec
2022-07-19 09:10:12 +00:00
Pau Espin 3df34be9ce Fix printf format in 32bit arch
Change-Id: I1273a42da2362c2b65169343e3b8d856338b3973
2022-07-19 09:10:12 +00:00
Pau Espin 384cff745e doc: Document SBc-AP support and config
Change-Id: Ic14ec2766fce251a6fe52a77d7bc0bbcd8d3afbf
2022-07-19 09:10:12 +00:00
Pau Espin c47c6a9e2e doc: user manual: fix typo
Change-Id: I20e595581f7d6145a01e9c0a6b0eb2af7637bfd9
2022-07-19 09:10:12 +00:00
Pau Espin 6e59534d6b Add initial SBc-AP support to osmo-cbc
This patch makes use of the newly introduced sbcap library, and
introduces new code (and extends existing one) to handle all the aspects
of MME peers talking SBc-AP and its underlaying SCTP connection.

This commit doesn't aim to implement all the SBc-AP features, but to
implement a minimal subset of features already available for CBSP in
osmo-cbc, in order to have similar support level for both 2G and 4G
networks.

Related: OS#4945
Change-Id: Ib278bc1d1a74459814016fef7a8fe21cc29d46c9
2022-07-19 09:10:12 +00:00
Oliver Smith ac2f4037bc libosmo-sbcap.pc.in: new file
Related: OS#4945
Change-Id: I9a7cf40e68cc246cab81f8c93485b83f75dcf778
2022-07-18 13:57:04 +00:00
Oliver Smith 3f0839d1cb debian: add subpackages libosmo-sbcap0/-dev
Related: OS#4945
Change-Id: Ic0e80000b377f80c3914e607e94e998e9862ceac
2022-07-18 13:57:04 +00:00
Oliver Smith 88613b7d44 contrib/osmo-cbc.spec: add libosmo-sbcap0/-dev
Fix for:
  error: Installed (but unpackaged) file(s) found:
  ...

Related: OS#4945
Change-Id: I789b32c9a9e1fd3f11db8593da3c3ac9a20aeb3d
2022-07-18 13:57:04 +00:00
Pau Espin 3c846a7f36 sbcap: Update asn1c skeleton files
Update skeleton files using newest asn1c with APER support [1],
commit 24247e2813a7510ebabe6a9b6b6b29fffa0eb27b.

This contains some APER decoding and encoding fixes for length
determinants. See [2] for more information.

[1] https://github.com/mouse07410/asn1c/tree/vlm_master/
[2] https://github.com/mouse07410/asn1c/issues/94

Change-Id: I581fc53b124a443e150508811df4cca4593038c4
2022-07-18 11:49:08 +02:00
Pau Espin ca432adbcb Add unit tests for sbcap
This commit adds some minimum unit tests to validate encoding and
decoding of SBc-AP ASN.1 APER format is working properly.

Related: OS#4945
Change-Id: I5a26d008b7282da637c3781ae77435c6a69cf65d
2022-07-15 15:53:39 +02:00
Pau Espin 4b8175d189 Add sbcap library
This commit adds initial support to encode/decode SBc-AP messages in the
form of a library, under src/sbcap/ (includes in
include/osmocom/sbcap/).
asn1c is used to generate all suport code and structures for ASN.1 APER
encoding/decoding, based on asn files obtained from 3GPP TS 29.168 and
stored under src/sbcap/asn1/.
Currently, mainstream asn1c doesn't yet support ASN.1 APER
encoding/decoding, hence mouse07410 's fork is used [1]. Furthermore,
several encdoing/decoding bugs where found during the process and fixed,
which means asn1.c git >= 30219de2d3da888b4f1eea0dd79f2a505000401a must
be used to generate proper code.

A new "make -C src/ gen" target is added which can be used to regenerate
all C code from the available ASN.1 files in src/sbcap/asn1/*.asn (after
properly setting configure.ac ASN_* variables if needed).

[1] https://github.com/mouse07410/asn1c

Related: OS#4945
Change-Id: If76f8619a9b2d46af6d94b8ae49348b8514e53aa
2022-07-15 15:53:35 +02:00
Oliver Smith 98d5b6143a checkpatch.conf: ignore sbcap generated files
Prepare to add sbcap library in
If76f8619a9b2d46af6d94b8ae49348b8514e53aa.

Change-Id: Icc5150b2c835f8a9c6b584da5e01ab2fd938ee45
2022-07-15 09:17:36 +00:00
Oliver Smith 4b19583188 gitreview: add new file
Change-Id: Ie1539f23b67dadce29d03f1e6542eb8077b25504
2022-07-15 09:14:07 +00:00
Pau Espin cc599727c7 rest_api: Fix cbs.data_user_len not set in 'payload_encoded'
This is later used in cbcmsg_to_cbsp(), but only set for type
'payload_decoded' in parse_payload_decoded().

Change-Id: I519cf300cd01e8c2728babeaa77b8486f47115be
2022-07-12 19:42:45 +02:00
Pau Espin a12affbc0f cbsp: Clean up conn closed paths
Change-Id: I08d1da97f0a2d83f7f48c59bc4dbd669f4f814b3
2022-07-07 16:22:36 +02:00
Pau Espin 2eb9c116d9 Improve error handling when forwarding ECBE msg to CBSP
Change-Id: Ie411409b3af8f7dd6913b522ea9ed3b58736dc9f
2022-07-06 16:37:54 +02:00
Pau Espin 8dc5648176 Move header files to include/osmocom/cbc/ dir
Change-Id: Id6c9f99805169d624a2c6e001fe1983e24fdc5c3
2022-07-04 13:35:47 +02:00
Pau Espin 18f144662e cbsp_server: Exit process gracefully if binding socket fails
Change-Id: I6fac793aa6975cacfeffc3389167bd00864a8a08
2022-07-01 17:24:28 +02:00
Pau Espin 9f2a1e3013 main: remove newline char in perror() call
perror() appends ":" immediatelly afterwards in order to append the
error string, so having a newline breaks the format.

Change-Id: I14874c2c86495c83030fa40c7060706e9dfe1968
2022-07-01 17:22:36 +02:00
Pau Espin b38bc5cb38 Fix typos in error messages
Change-Id: I42b201127535ae9fc61adbdc37e1d23897fd81d8
2022-07-01 17:15:26 +02:00
Pau Espin b1ab55d887 Move peer to DELETED state before signalling parent FSM with DELETE_(N)ACK
When receiving SMSCB_E_CBSP_DELETE_(N)ACK, smscb_message_fsm will iterate
over all peers to find out if some of them has still not ended, and in
that case delay sending an HTTP result.
However, the peer was sending the signal before moving to DELETED state,
and hence smscb_message_fsm would never send the HTTP result until T3
(T_WAIT_DELETE_ACK) would time out after it:
"""
20220629104312596 DCBSP INFO SMSCB-PEER(TTCN-3-44-ttcn3)[0x560b46c1f770]{WAIT_DELETE_ACK}: Received Event DELETE_ACK (cbsp_server_fsm.c:348)
20220629104312596 DCBSP INFO SMSCB(TTCN-3-44)[0x560b46c1f090]{WAIT_DELETE_ACK}: Received Event DELETE_ACK (smscb_peer_fsm.c:423)
20220629104312596 DCBSP INFO SMSCB-PEER(TTCN-3-44-ttcn3)[0x560b46c1f770]{WAIT_DELETE_ACK}: state_chg to DELETED (smscb_peer_fsm.c:424)
20220629104327599 DCBSP INFO SMSCB(TTCN-3-44)[0x560b46c1f090]{WAIT_DELETE_ACK}: Timeout of T3 (fsm.c:317)
20220629104327599 DREST DEBUG rest_it_op_complete(op=0x7fd09c001490) complete (rest_it_op.c:129)
20220629104327599 DCBSP INFO SMSCB(TTCN-3-44)[0x560b46c1f090]{WAIT_DELETE_ACK}: state_chg to DELETED (smscb_message_fsm.c:294)
20220629104327599 DREST DEBUG rest_it_op completed with 0 (HTTP 0) (rest_it_op.c:68)
"""

Change-Id: Idb418728e1242fc5436355ccf73f20b1419e1eb8
2022-06-30 16:46:31 +02:00
Pau Espin 14b862099e Configure libosmocore logging system as multithread
OsmoCBC uses libulfius, which creates its own thread(s).
Hence, we must set up osmocom logging system appropiately so that
relevant stuff is protected by locks.

Related: OS#5598
Change-Id: Ic06edc19d22b90e2b6b7de3a25d62cda5001f46e
2022-06-30 16:21:50 +02:00
Pau Espin 61f2f7123c Bump version: 0.2.3.13-aeea-dirty → 0.3.0
Change-Id: I3cbf26467dd90c3fc56dae76324f5eb9cdd0f4ef
2022-06-29 12:00:03 +02:00
Pau Espin aeea8b1145 .gitignore: add configure~
Change-Id: I2b4327fd78914b63040fb3e7d5e00b92bdb5e1c1
2022-06-23 14:09:14 +02:00
Pau Espin 5b25874c2b cbsp_server: Reorder logged message
log macro needs to be changed since it uses cbsp_cbc_client_name() which
accesses client->conn which is NULL in there.

Change-Id: Ic444c749476bb1626df5494c00021c5e1a9f24b9
2022-06-21 12:11:49 +02:00
Pau Espin b3ee9ca764 Rework cbsp_cbc_create() params
There's no need to pass the specific params. Let's simply get whatever
need from the global config in the function.
This makes it easier to extend it to more params if needed.
Also, when we add SBc-AP support, the params that have to be passed to
the counter part function are different, so let's simplify param
passing here.

While at it, rename also the callback function to contain "cbsp" on it,
since it is cbsp specific.

Change-Id: Ia2362757275e7cbce82b64c7c2a0798276d964c3
2022-06-21 12:11:49 +02:00
Pau Espin 6c7d06a50a cbsp_server.h: Move function to the proper section
Change-Id: I47f694c2ffa1df50394ff01977ddb85768657062
2022-06-21 09:39:21 +00:00
Harald Welte 9514e3e4ba update git URLs (git -> https; gitea)
Change-Id: Ife8212bcd6db51f5d4533c7bd8a52f9a21a8d144
2022-06-18 11:41:07 +02:00