ipa: Use enhanced ipa_msg_recv_buffered() to cope with partioned IPA messages
The old ipa_msg_recv() implementation didn't support partial receive,
so IPA connections got disconnected when this happened.
This patch adds the handling of the temporary message buffers and uses
ipa_msg_recv_buffered().
It has been successfully tested by jerlbeck with osmo-nitb and
osmo-bsc.
Ticket: OW#768
Sponsored-by: On-Waves ehf
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat.c b/openbsc/src/osmo-bsc_nat/bsc_nat.c
index d9fc0ca..524186a 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat.c
@@ -796,14 +796,16 @@
static int ipaccess_msc_read_cb(struct osmo_fd *bfd)
{
struct bsc_msc_connection *msc_con;
- struct msgb *msg;
+ struct msgb *msg = NULL;
struct ipaccess_head *hh;
int ret;
msc_con = (struct bsc_msc_connection *) bfd->data;
- ret = ipa_msg_recv(bfd->fd, &msg);
+ ret = ipa_msg_recv_buffered(bfd->fd, &msg, &msc_con->pending_msg);
if (ret <= 0) {
+ if (ret == -EAGAIN)
+ return 0;
if (ret == 0)
LOGP(DNAT, LOGL_FATAL,
"The connection the MSC(%s) was lost, exiting\n",
@@ -912,6 +914,13 @@
osmo_wqueue_clear(&connection->write_queue);
llist_del(&connection->list_entry);
+ if (connection->pending_msg) {
+ LOGP(DNAT, LOGL_ERROR, "Dropping partial message on connection %d.\n",
+ connection->cfg->nr);
+ msgb_free(connection->pending_msg);
+ connection->pending_msg = NULL;
+ }
+
talloc_free(connection);
}
@@ -1206,13 +1215,15 @@
static int ipaccess_bsc_read_cb(struct osmo_fd *bfd)
{
struct bsc_connection *bsc = bfd->data;
- struct msgb *msg;
+ struct msgb *msg = NULL;
struct ipaccess_head *hh;
struct ipaccess_head_ext *hh_ext;
int ret;
- ret = ipa_msg_recv(bfd->fd, &msg);
+ ret = ipa_msg_recv_buffered(bfd->fd, &msg, &bsc->pending_msg);
if (ret <= 0) {
+ if (ret == -EAGAIN)
+ return 0;
if (ret == 0)
LOGP(DNAT, LOGL_ERROR,
"The connection to the BSC Nr: %d was lost. Cleaning it\n",