diff options
author | Pablo Neira Ayuso <pablo@gnumonks.org> | 2012-08-19 19:49:07 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@gnumonks.org> | 2012-08-19 20:14:25 +0200 |
commit | 9ae91e594c129ddffaf3217da5834bf6d7d822f0 (patch) | |
tree | 01f4fe75ef0ade5731f3bbd8d84aa24c2f168b92 /src/ipa.c | |
parent | 7a3e8d01f54e68997c22036b1291f7f90a018def (diff) |
ipa: add osmo_ipa_process_msg and remove osmo_ipa_recv_msg
This patch removes osmo_ipa_recv_msg, it performs two syscall invocations
and it's stream generic. Now we use the specific receival function
we want to use (no matter if stream or datagram based) and then we
call osmo_ipa_process_msg to check that the IPA message correct.
Diffstat (limited to 'src/ipa.c')
-rw-r--r-- | src/ipa.c | 38 |
1 files changed, 12 insertions, 26 deletions
@@ -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) |