aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/ipa-stream-client.c7
-rw-r--r--examples/ipa-stream-server.c9
-rw-r--r--include/osmocom/netif/ipa.h3
-rw-r--r--src/channel/abis/ipa_stream_client.c10
-rw-r--r--src/channel/abis/ipa_stream_server.c9
-rw-r--r--src/ipa.c38
6 files changed, 39 insertions, 37 deletions
diff --git a/examples/ipa-stream-client.c b/examples/ipa-stream-client.c
index b771fa3..db1ce62 100644
--- a/examples/ipa-stream-client.c
+++ b/examples/ipa-stream-client.c
@@ -96,7 +96,6 @@ static int connect_cb(struct osmo_stream_cli *conn)
static int read_cb(struct osmo_stream_cli *conn)
{
struct msgb *msg;
- struct osmo_fd *ofd = osmo_stream_cli_get_ofd(conn);
LOGP(DIPATEST, LOGL_DEBUG, "received message from stream\n");
@@ -105,10 +104,14 @@ static int read_cb(struct osmo_stream_cli *conn)
LOGP(DIPATEST, LOGL_ERROR, "cannot allocate message\n");
return 0;
}
- if (osmo_ipa_msg_recv(ofd->fd, msg) <= 0) {
+ if (osmo_stream_cli_recv(conn, msg) <= 0) {
LOGP(DIPATEST, LOGL_ERROR, "cannot receive message\n");
return 0;
}
+ if (osmo_ipa_process_msg(msg) < 0) {
+ LOGP(DIPATEST, LOGL_ERROR, "bad IPA message\n");
+ return 0;
+ }
int num;
struct msg_sent *cur, *tmp, *found = NULL;
diff --git a/examples/ipa-stream-server.c b/examples/ipa-stream-server.c
index 69e0280..c370d5f 100644
--- a/examples/ipa-stream-server.c
+++ b/examples/ipa-stream-server.c
@@ -46,7 +46,6 @@ void sighandler(int foo)
int read_cb(struct osmo_stream_srv *conn)
{
struct msgb *msg;
- struct osmo_fd *ofd = osmo_stream_srv_get_ofd(conn);
LOGP(DSTREAMTEST, LOGL_DEBUG, "received message from stream\n");
@@ -55,12 +54,18 @@ int read_cb(struct osmo_stream_srv *conn)
LOGP(DSTREAMTEST, LOGL_ERROR, "cannot allocate message\n");
return 0;
}
- if (osmo_ipa_msg_recv(ofd->fd, msg) <= 0) {
+ if (osmo_stream_srv_recv(conn, msg) <= 0) {
LOGP(DSTREAMTEST, LOGL_ERROR, "cannot receive message\n");
osmo_stream_srv_destroy(conn);
msgb_free(msg);
return 0;
}
+ if (osmo_ipa_process_msg(msg) < 0) {
+ LOGP(DSTREAMTEST, LOGL_ERROR, "Bad IPA message\n");
+ msgb_free(msg);
+ return 0;
+ }
+
osmo_stream_srv_send(conn, msg);
return 0;
}
diff --git a/include/osmocom/netif/ipa.h b/include/osmocom/netif/ipa.h
index 5c815cd..ea06c22 100644
--- a/include/osmocom/netif/ipa.h
+++ b/include/osmocom/netif/ipa.h
@@ -47,7 +47,8 @@ enum ipaccess_id_tags {
struct msgb *osmo_ipa_msg_alloc(int headroom);
void osmo_ipa_msg_push_header(struct msgb *msg, uint8_t proto);
-int osmo_ipa_msg_recv(int fd, struct msgb *msg);
+
+int osmo_ipa_process_msg(struct msgb *msg);
struct ipaccess_unit {
uint16_t site_id;
diff --git a/src/channel/abis/ipa_stream_client.c b/src/channel/abis/ipa_stream_client.c
index e6565c4..5745e2a 100644
--- a/src/channel/abis/ipa_stream_client.c
+++ b/src/channel/abis/ipa_stream_client.c
@@ -288,7 +288,6 @@ static int read_cb(struct osmo_stream_cli *conn, int type)
{
int ret;
struct msgb *msg;
- struct osmo_fd *ofd = osmo_stream_cli_get_ofd(conn);
struct osmo_chan *chan = osmo_stream_cli_get_data(conn);
struct chan_abis_ipa_cli *s;
struct ipa_head *hh;
@@ -300,8 +299,7 @@ static int read_cb(struct osmo_stream_cli *conn, int type)
LOGP(DLINP, LOGL_ERROR, "cannot allocate message\n");
return 0;
}
- /* XXX replace with generic stream reader */
- ret = osmo_ipa_msg_recv(ofd->fd, msg);
+ ret = osmo_stream_cli_recv(conn, msg);
if (ret < 0) {
LOGP(DLINP, LOGL_ERROR, "cannot receive message\n");
msgb_free(msg);
@@ -314,6 +312,12 @@ static int read_cb(struct osmo_stream_cli *conn, int type)
return 0;
}
+ if (osmo_ipa_process_msg(msg) < 0) {
+ LOGP(DLINP, LOGL_ERROR, "Bad IPA message\n");
+ msgb_free(msg);
+ return -EIO;
+ }
+
hh = (struct ipa_head *) msg->data;
if (hh->proto == IPAC_PROTO_IPACCESS) {
abis_ipa_cli_rcvmsg(chan, conn, msg, type);
diff --git a/src/channel/abis/ipa_stream_server.c b/src/channel/abis/ipa_stream_server.c
index a47b0f6..21a82f8 100644
--- a/src/channel/abis/ipa_stream_server.c
+++ b/src/channel/abis/ipa_stream_server.c
@@ -341,7 +341,6 @@ static int read_cb(struct osmo_stream_srv *conn, int type)
{
int ret;
struct msgb *msg;
- struct osmo_fd *ofd = osmo_stream_srv_get_ofd(conn);
struct osmo_ipa_unit *unit = osmo_stream_srv_get_data(conn);
struct chan_abis_ipa_srv_conn *inst;
struct ipa_head *hh;
@@ -353,7 +352,7 @@ static int read_cb(struct osmo_stream_srv *conn, int type)
LOGP(DLINP, LOGL_ERROR, "cannot allocate message\n");
return 0;
}
- ret = osmo_ipa_msg_recv(ofd->fd, msg);
+ ret = osmo_stream_srv_recv(conn, msg);
if (ret < 0) {
LOGP(DLINP, LOGL_ERROR, "cannot receive message\n");
msgb_free(msg);
@@ -369,7 +368,11 @@ static int read_cb(struct osmo_stream_srv *conn, int type)
return 0;
}
- /* XXX: missing IPA message validation */
+ ret = osmo_ipa_process_msg(msg);
+ if (ret < 0) {
+ LOGP(DLINP, LOGL_ERROR, "invalid IPA message\n");
+ msgb_free(msg);
+ }
hh = (struct ipa_head *) msg->data;
if (hh->proto == IPAC_PROTO_IPACCESS) {
diff --git a/src/ipa.c b/src/ipa.c
index 955ae84..e5305cf 100644
--- a/src/ipa.c
+++ b/src/ipa.c
@@ -88,41 +88,27 @@ void osmo_ipa_msg_push_header(struct msgb *msg, uint8_t proto)
hh->len = htons(msgb_l2len(msg));
}
-int osmo_ipa_msg_recv(int fd, struct msgb *msg)
+int osmo_ipa_process_msg(struct msgb *msg)
{
struct ipa_head *hh;
- int len, ret;
+ int len;
- /* first read our 3-byte header */
- hh = (struct ipa_head *) msg->data;
- ret = recv(fd, msg->data, sizeof(*hh), 0);
- if (ret <= 0) {
- return ret;
- } else if (ret != sizeof(*hh)) {
- LOGP(DLINP, LOGL_ERROR, "too small message received\n");
+ if (msg->len < sizeof(struct ipa_head)) {
+ LOGP(DLINP, LOGL_ERROR, "too small IPA message\n");
return -EIO;
}
- msgb_put(msg, ret);
-
- /* then read the length as specified in header */
- msg->l2h = msg->data + sizeof(*hh);
- len = ntohs(hh->len);
+ hh = (struct ipa_head *) msg->data;
- if (len < 0 || IPA_ALLOC_SIZE < len + sizeof(*hh)) {
- LOGP(DLINP, LOGL_ERROR, "bad message length of %d bytes, "
- "received %d bytes\n", len, ret);
+ len = sizeof(struct ipa_head) + ntohs(hh->len);
+ if (len > msg->len) {
+ LOGP(DLINP, LOGL_ERROR, "bad IPA message header "
+ "hdrlen=%u < datalen=%u\n",
+ len, msg->len);
return -EIO;
}
+ msg->l2h = msg->data + sizeof(*hh);
- ret = recv(fd, msg->l2h, len, 0);
- if (ret <= 0) {
- return ret;
- } else if (ret < len) {
- LOGP(DLINP, LOGL_ERROR, "trunked message received\n");
- return -EIO;
- }
- msgb_put(msg, ret);
- return ret;
+ return 0;
}
int osmo_ipa_idtag_parse(struct tlv_parsed *dec, unsigned char *buf, int len)