diff options
author | Álvaro Neira Ayuso <anayuso@sysmocom.de> | 2014-05-20 07:40:47 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2014-05-20 09:37:30 +0200 |
commit | 13a224063dfcee0be529fba1c8fb9be9c1fb261e (patch) | |
tree | dca65fa1192a3c9068af571f721a79dab58daac8 | |
parent | 0a1699ff8a5462c167c24e8b28186abb26331698 (diff) |
sysmobts: Separate IPA and OML check into two methods
I have split the function check_oml_msg, in two functions. One for
checking if the ipa header is well-formed and in check_oml_msg,
Signed-off-by: Alvaro Neira Ayuso <anayuso@sysmocom.de>
-rw-r--r-- | src/osmo-bts-sysmo/main.c | 11 | ||||
-rw-r--r-- | src/osmo-bts-sysmo/utils.c | 50 | ||||
-rw-r--r-- | src/osmo-bts-sysmo/utils.h | 1 |
3 files changed, 38 insertions, 24 deletions
diff --git a/src/osmo-bts-sysmo/main.c b/src/osmo-bts-sysmo/main.c index bd6a1818..797f1741 100644 --- a/src/osmo-bts-sysmo/main.c +++ b/src/osmo-bts-sysmo/main.c @@ -317,7 +317,16 @@ static int read_sock(struct osmo_fd *fd, unsigned int what) msgb_put(msg, rc); - if (check_oml_msg(msg) < 0) { + rc = check_ipa_header(msg); + if (rc < 0) { + LOGP(DL1C, LOGL_ERROR, "Malformed receive message: Ipa hdr\n"); + goto err; + } + + msgb_pull(msg, sizeof(struct ipaccess_head)); + + rc = check_oml_msg(msg); + if (rc < 0) { LOGP(DL1C, LOGL_ERROR, "Malformed receive message\n"); goto err; } diff --git a/src/osmo-bts-sysmo/utils.c b/src/osmo-bts-sysmo/utils.c index 2da1228c..1fa57960 100644 --- a/src/osmo-bts-sysmo/utils.c +++ b/src/osmo-bts-sysmo/utils.c @@ -181,33 +181,10 @@ void prepend_oml_ipa_header(struct msgb *msg) int check_oml_msg(struct msgb *msg) { - struct ipaccess_head *hh; struct abis_om_hdr *omh; int abis_oml_hdr_len; char label_id[255]; - if (msg->len < sizeof(struct ipaccess_head)) { - LOGP(DL1C, LOGL_ERROR, "Ipa header insufficient space %d %d\n", - msg->len, sizeof(struct ipaccess_head)); - return -1; - } - - hh = (struct ipaccess_head *)msg->data; - - if (hh->proto != IPAC_PROTO_OML) { - LOGP(DL1C, LOGL_ERROR, "Incorrect ipa header protocol %x %x\n", - hh->proto, IPAC_PROTO_OML); - return -1; - } - - if (ntohs(hh->len) != msg->len - sizeof(struct ipaccess_head)) { - LOGP(DL1C, LOGL_ERROR, "Incorrect ipa header msg size %d %d\n", - ntohs(hh->len), msg->len - sizeof(struct ipaccess_head)); - return -1; - } - - msgb_pull(msg, sizeof(struct ipaccess_head)); - abis_oml_hdr_len = sizeof(struct abis_om_hdr); if (msg->len < abis_oml_hdr_len) { @@ -287,6 +264,33 @@ int check_oml_msg(struct msgb *msg) return 0; } +int check_ipa_header(struct msgb *msg) +{ + struct ipaccess_head *hh; + + if (msg->len < sizeof(struct ipaccess_head)) { + LOGP(DL1C, LOGL_ERROR, "Ipa header insufficient space %d %d\n", + msg->len, sizeof(struct ipaccess_head)); + return -1; + } + + hh = (struct ipaccess_head *)msg->data; + + if (hh->proto != IPAC_PROTO_OML) { + LOGP(DL1C, LOGL_ERROR, "Incorrect ipa header protocol %x %x\n", + hh->proto, IPAC_PROTO_OML); + return -1; + } + + if (ntohs(hh->len) != msg->len - sizeof(struct ipaccess_head)) { + LOGP(DL1C, LOGL_ERROR, "Incorrect ipa header msg size %d %d\n", + ntohs(hh->len), msg->len - sizeof(struct ipaccess_head)); + return -1; + } + + return 0; +} + int add_manufacturer_id_label(struct msgb *msg, int manuf_type_id) { uint8_t *manuf; diff --git a/src/osmo-bts-sysmo/utils.h b/src/osmo-bts-sysmo/utils.h index 85a5e880..4f2293aa 100644 --- a/src/osmo-bts-sysmo/utils.h +++ b/src/osmo-bts-sysmo/utils.h @@ -29,4 +29,5 @@ int add_manufacturer_id_label(struct msgb *msg, int manuf_type_id); void prepend_oml_ipa_header(struct msgb *msg); int check_oml_msg(struct msgb *msg); +int check_ipa_header(struct msgb *msg); #endif |