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
This commit is contained in:
parent
ffa227307c
commit
df404c4296
17
ggsn/ggsn.c
17
ggsn/ggsn.c
|
@ -462,18 +462,23 @@ enum pco_protocols {
|
||||||
PCO_P_REL_DATA_SVC = 0x0018,
|
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 */
|
/* 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)
|
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 */
|
/* iterate over PCO and check if protocol contained */
|
||||||
while (cur + 3 <= pco->v + pco->l) {
|
while (cur + sizeof(struct pco_element) <= pco->v + pco->l) {
|
||||||
uint16_t cur_prot = osmo_load16be(cur);
|
const struct pco_element *elem = (const struct pco_element *)cur;
|
||||||
uint8_t cur_len = cur[2];
|
if (ntohs(elem->protocol_id) == prot && elem->length >= prot_minlen)
|
||||||
if (cur_prot == prot && cur_len >= prot_minlen)
|
|
||||||
return cur;
|
return cur;
|
||||||
cur += cur_len + 3;
|
cur += elem->length + sizeof(struct pco_element);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue