aboutsummaryrefslogtreecommitdiffstats
path: root/src/gsm/ipa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gsm/ipa.c')
-rw-r--r--src/gsm/ipa.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/gsm/ipa.c b/src/gsm/ipa.c
index 447e8e3d..93e34df2 100644
--- a/src/gsm/ipa.c
+++ b/src/gsm/ipa.c
@@ -30,6 +30,7 @@
#include <stdint.h>
#include <errno.h>
#include <stdlib.h>
+#include <inttypes.h>
#include <sys/types.h>
@@ -718,4 +719,32 @@ struct msgb *ipa_msg_alloc(int headroom)
return nmsg;
}
+/*! Segmentation callback used by libosmo-netif streaming backend
+ * See definition of `struct osmo_io_ops` for callback semantics
+ * \param[in] msg Original `struct msgb` received via osmo_io
+ * \returns The total packet length indicated by the first header,
+ * otherwise
+ * -EAGAIN, if the header has not been read yet,
+ * -ENOBUFS, if the header declares a payload too large
+ */
+int ipa_segmentation_cb(struct msgb *msg)
+{
+ const struct ipaccess_head *hh = (const struct ipaccess_head *) msg->data;
+ size_t payload_len, total_len;
+ size_t available = msgb_length(msg) + msgb_tailroom(msg);
+ if (msgb_length(msg) < sizeof(*hh)) {
+ /* Haven't even read the entire header */
+ return -EAGAIN;
+ }
+ payload_len = osmo_ntohs(hh->len);
+ total_len = sizeof(*hh) + payload_len;
+ if (OSMO_UNLIKELY(available < total_len)) {
+ LOGP(DLINP, LOGL_ERROR, "Not enough space left in message buffer. "
+ "Have %zu octets, but need %zu\n",
+ available, total_len);
+ return -ENOBUFS;
+ }
+ return total_len;
+}
+
/*! @} */