Harald Welte has uploaded this change for review. ( https://gerrit.osmocom.org/13567
Change subject: ggsn: Remove magic numbers from pco_contains_proto() ...................................................................... ggsn: Remove magic numbers from pco_contains_proto() Let's remove some magic numbers and use a data structure to describe the PCO element header. Change-Id: I9871ffced677320aa82438332bfdb951ab129f04 --- M ggsn/ggsn.c 1 file changed, 11 insertions(+), 6 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-ggsn refs/changes/67/13567/1 diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c index 2ee9b1a..c31831a 100644 --- a/ggsn/ggsn.c +++ b/ggsn/ggsn.c @@ -462,18 +462,23 @@ PCO_P_REL_DATA_SVC = 0x0018, }; +struct pco_element { + uint16_t protocol_id; /* network byte order */ + uint8_t length; /* length of data below */ + uint8_t data[0]; +} __attribute__((packed)); + /* determine if PCO contains given protocol */ static uint8_t *pco_contains_proto(struct ul255_t *pco, size_t offset, uint16_t prot, size_t prot_minlen) { - uint8_t *cur = pco->v + 1 + offset; + uint8_t *cur = pco->v + 1 /*length*/ + offset; /* iterate over PCO and check if protocol contained */ - while (cur + 3 <= pco->v + pco->l) { - uint16_t cur_prot = osmo_load16be(cur); - uint8_t cur_len = cur[2]; - if (cur_prot == prot && cur_len >= prot_minlen) + while (cur + sizeof(struct pco_element) <= pco->v + pco->l) { + const struct pco_element *elem = (const struct pco_element *)cur; + if (ntohs(elem->protocol_id) == prot && elem->length >= prot_minlen) return cur; - cur += cur_len + 3; + cur += elem->length + sizeof(struct pco_element); } return NULL; } -- To view, visit https://gerrit.osmocom.org/13567 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-ggsn Gerrit-Branch: master Gerrit-MessageType: newchange Gerrit-Change-Id: I9871ffced677320aa82438332bfdb951ab129f04 Gerrit-Change-Number: 13567 Gerrit-PatchSet: 1 Gerrit-Owner: Harald Welte <lafo...@gnumonks.org>