laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/36145?usp=email )
Change subject: cbsp: Add osmo_cbsp_segmentation_cb for message segmentation
......................................................................
cbsp: Add osmo_cbsp_segmentation_cb for message segmentation
This call-back can for example be used as segmentation call-back
for libosmo-netif stream_cli/stream_srv or directly for osmo_io.
Related: OS#5755
Change-Id: I5e922c54b3431d759b38e81e55076125c5a34008
---
M include/osmocom/gsm/cbsp.h
M src/gsm/cbsp.c
M src/gsm/libosmogsm.map
3 files changed, 34 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/45/36145/1
diff --git a/include/osmocom/gsm/cbsp.h b/include/osmocom/gsm/cbsp.h
index 536c54d..efa4ce6 100644
--- a/include/osmocom/gsm/cbsp.h
+++ b/include/osmocom/gsm/cbsp.h
@@ -312,3 +312,4 @@
struct osmo_cbsp_decoded *osmo_cbsp_decoded_alloc(void *ctx, enum cbsp_msg_type msg_type);
int osmo_cbsp_recv_buffered(void *ctx, int fd, struct msgb **rmsg, struct msgb **tmp_msg);
+int osmo_cbsp_segmentation_cb(struct msgb *msg);
diff --git a/src/gsm/cbsp.c b/src/gsm/cbsp.c
index 28852f6..90541e3 100644
--- a/src/gsm/cbsp.c
+++ b/src/gsm/cbsp.c
@@ -1567,6 +1567,25 @@
return rc;
}
+/*! call-back function to segment the data at message boundaries.
+ * Returns the size of the next message. If it returns -EAGAIN or a value larger than msgb_length() (message
+ * is incomplete), the caller (e.g. osmo_io) has to wait for more data to be read. */
+int osmo_cbsp_segmentation_cb(struct msgb *msg)
+{
+ const struct cbsp_header *h;
+ int len;
+
+ if (msgb_length(msg) < sizeof(*h))
+ return -EAGAIN;
+
+ h = (const struct cbsp_header *) msg->data;
+ msg->l2h = msg->data + sizeof(*h);
+ /* then read the length as specified in the header */
+ len = h->len[0] << 16 | h->len[1] << 8 | h->len[2];
+
+ return sizeof(*h) + len;
+}
+
/*! value_string[] for enum osmo_cbsp_cause. */
const struct value_string osmo_cbsp_cause_names[] = {
{ OSMO_CBSP_CAUSE_PARAM_NOT_RECOGNISED, "Parameter-not-recognised" },
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index db2dbcb..2c4c621 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -793,6 +793,7 @@
osmo_cbsp_decode;
osmo_cbsp_recv_buffered;
osmo_cbsp_errstr;
+osmo_cbsp_segmentation_cb;
osmo_i460_demux_in;
osmo_i460_mux_enqueue;
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/36145?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I5e922c54b3431d759b38e81e55076125c5a34008
Gerrit-Change-Number: 36145
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange
Attention is currently required from: jolly.
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/36132?usp=email )
Change subject: osmo_io_uring: Check if osmo_fd_register fails at iofd_uring_notify_connected()
......................................................................
Patch Set 2: Code-Review+2
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/36132?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I34e8cc9a2b9df0c624841e5f9268a15c32418da1
Gerrit-Change-Number: 36132
Gerrit-PatchSet: 2
Gerrit-Owner: jolly <andreas(a)eversberg.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Attention: jolly <andreas(a)eversberg.eu>
Gerrit-Comment-Date: Sat, 02 Mar 2024 10:16:32 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: jolly, pespin.
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/36123?usp=email )
Change subject: stream_cli: Do not try to send msg, if not connected
......................................................................
Patch Set 4: Code-Review+1
(1 comment)
File src/stream_cli.c:
https://gerrit.osmocom.org/c/libosmo-netif/+/36123/comment/e041ae26_cd2e9bc8
PS4, Line 998: if (cli->state != STREAM_CLI_STATE_CONNECTED) {
> Is this really a problem? or will the socket enqueue the data and transmit it automatically after co […]
I think with the osmo_fd mode it is indeed just enqueued in our own internal write_queue which might be drained once connect is complete.
However, for osmo_io, there is no in-application/library write_queue. Instead we immediately submit the write into the io_uring submission queue.
It's illegal to do a write on a socket before it is connected.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html:
[ECONNRESET]
A write was attempted on a socket that is not connected.
--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/36123?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I9e5f5db9b45615dacb05115c4de8ff3f715815c8
Gerrit-Change-Number: 36123
Gerrit-PatchSet: 4
Gerrit-Owner: jolly <andreas(a)eversberg.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-CC: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: jolly <andreas(a)eversberg.eu>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Comment-Date: Sat, 02 Mar 2024 09:33:43 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: comment
Attention is currently required from: jolly.
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/36132?usp=email )
Change subject: osmo_io_uring: Check if osmo_fd_register fails at iofd_uring_notify_connected()
......................................................................
Patch Set 2: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/36132?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I34e8cc9a2b9df0c624841e5f9268a15c32418da1
Gerrit-Change-Number: 36132
Gerrit-PatchSet: 2
Gerrit-Owner: jolly <andreas(a)eversberg.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Attention: jolly <andreas(a)eversberg.eu>
Gerrit-Comment-Date: Sat, 02 Mar 2024 09:29:33 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: jolly.
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/36131?usp=email )
Change subject: osmo_io: do check_mode_callback_compat() only if ioops is set at osmo_iofd_setup()
......................................................................
Patch Set 2: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/36131?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I1e25f3e420f25a44cbf73a4da9a498b7561e9ddd
Gerrit-Change-Number: 36131
Gerrit-PatchSet: 2
Gerrit-Owner: jolly <andreas(a)eversberg.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Attention: jolly <andreas(a)eversberg.eu>
Gerrit-Comment-Date: Sat, 02 Mar 2024 09:29:23 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/36125?usp=email )
(
4 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
)Change subject: stream_{cli,srv}: Free received messages when not forwarded
......................................................................
stream_{cli,srv}: Free received messages when not forwarded
If a message is not forwarded (to a read callback function, it must be
freed, to prevent memory leaks.
The message musst be freed before calling osmo_stream_srv_destroy() or
stream_cli_handle_connecting(), because within the function calls the
client/server instance may get destroyed and the message is 'owned' by
it. Calling msgb_free(msg) afterwards may result in double free bug.
Related: OS#5753
Change-Id: Ic043f11cdba0df9e0b78cac8db7206800098e0ba
---
M src/stream_cli.c
M src/stream_srv.c
2 files changed, 26 insertions(+), 0 deletions(-)
Approvals:
laforge: Looks good to me, but someone else must approve
pespin: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/src/stream_cli.c b/src/stream_cli.c
index eef442c..1197b53 100644
--- a/src/stream_cli.c
+++ b/src/stream_cli.c
@@ -438,6 +438,7 @@
switch (cli->state) {
case STREAM_CLI_STATE_CONNECTING:
+ msgb_free(msg);
stream_cli_handle_connecting(cli, res);
break;
case STREAM_CLI_STATE_CONNECTED:
@@ -445,6 +446,8 @@
osmo_stream_cli_reconnect(cli);
else if (cli->iofd_read_cb)
cli->iofd_read_cb(cli, msg);
+ else
+ msgb_free(msg);
break;
default:
osmo_panic("%s() called with unexpected state %d\n", __func__, cli->state);
@@ -486,6 +489,7 @@
switch (cli->state) {
case STREAM_CLI_STATE_CONNECTING:
+ msgb_free(msg);
stream_cli_handle_connecting(cli, res);
break;
case STREAM_CLI_STATE_CONNECTED:
@@ -494,6 +498,8 @@
/* Forward message to read callback, also if the connection failed. */
if (cli->iofd_read_cb)
cli->iofd_read_cb(cli, msg);
+ else
+ msgb_free(msg);
break;
default:
osmo_panic("%s() called with unexpected state %d\n", __func__, cli->state);
diff --git a/src/stream_srv.c b/src/stream_srv.c
index 33494fa..95a2cbb 100644
--- a/src/stream_srv.c
+++ b/src/stream_srv.c
@@ -562,6 +562,7 @@
if (OSMO_UNLIKELY(res <= 0)) {
/* This connection is dead, destroy it. */
+ msgb_free(msg);
osmo_stream_srv_destroy(conn);
} else {
if (conn->flags & OSMO_STREAM_SRV_F_FLUSH_DESTROY) {
@@ -609,6 +610,7 @@
if (OSMO_UNLIKELY(res <= 0)) {
/* This connection is dead, destroy it. */
+ msgb_free(msg);
osmo_stream_srv_destroy(conn);
} else {
if (conn->flags & OSMO_STREAM_SRV_F_FLUSH_DESTROY) {
--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/36125?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: Ic043f11cdba0df9e0b78cac8db7206800098e0ba
Gerrit-Change-Number: 36125
Gerrit-PatchSet: 5
Gerrit-Owner: jolly <andreas(a)eversberg.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged