Change in osmo-ggsn[master]: ggsn: Remove magic numbers from pco_contains_proto()
Harald Welte has submitted this change and it was merged. ( 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(-) Approvals: Jenkins Builder: Verified Pau Espin Pedrol: Looks good to me, approved diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c index 423f0c0..65e15c3 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: merged Gerrit-Change-Id: I9871ffced677320aa82438332bfdb951ab129f04 Gerrit-Change-Number: 13567 Gerrit-PatchSet: 2 Gerrit-Owner: Harald Welte Gerrit-Reviewer: Harald Welte Gerrit-Reviewer: Jenkins Builder (102) Gerrit-Reviewer: Pau Espin Pedrol
Change in osmo-ggsn[master]: ggsn: Remove magic numbers from pco_contains_proto()
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
Change in osmo-ggsn[master]: ggsn: Remove magic numbers from pco_contains_proto()
Pau Espin Pedrol has posted comments on this change. ( https://gerrit.osmocom.org/13567 ) Change subject: ggsn: Remove magic numbers from pco_contains_proto() .. Patch Set 1: (1 comment) https://gerrit.osmocom.org/#/c/13567/1/ggsn/ggsn.c File ggsn/ggsn.c: https://gerrit.osmocom.org/#/c/13567/1/ggsn/ggsn.c@474 PS1, Line 474: uint8_t *cur = pco->v + 1 /*length*/ + offset; I think we can drop cur completely. struct pco_element *elem = (struct pco_element *) pco->v + 1 /*length*/ + offset; while (elem + sizeof(*elem) <= pco->v+ pco->l) { if (ntohs(elem->protocol_id) == prot && elem->length >= prot_minlen) return (uint8_t*) elem; elem = elem + elem->length + sizeof(*elem); } 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: comment Gerrit-Change-Id: I9871ffced677320aa82438332bfdb951ab129f04 Gerrit-Change-Number: 13567 Gerrit-PatchSet: 1 Gerrit-Owner: Harald Welte Gerrit-Reviewer: Jenkins Builder (102) Gerrit-Reviewer: Pau Espin Pedrol Gerrit-Comment-Date: Thu, 11 Apr 2019 14:18:00 + Gerrit-HasComments: Yes Gerrit-HasLabels: No
Change in osmo-ggsn[master]: ggsn: Remove magic numbers from pco_contains_proto()
Harald Welte has posted comments on this change. ( https://gerrit.osmocom.org/13567 ) Change subject: ggsn: Remove magic numbers from pco_contains_proto() .. Patch Set 1: (1 comment) https://gerrit.osmocom.org/#/c/13567/1/ggsn/ggsn.c File ggsn/ggsn.c: https://gerrit.osmocom.org/#/c/13567/1/ggsn/ggsn.c@474 PS1, Line 474: uint8_t *cur = pco->v + 1 /*length*/ + offset; > I think we can drop cur completely. […] I'm removing this function a few patches later, so I don't think it's worth to spend time on it anymore. -- 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: comment Gerrit-Change-Id: I9871ffced677320aa82438332bfdb951ab129f04 Gerrit-Change-Number: 13567 Gerrit-PatchSet: 1 Gerrit-Owner: Harald Welte Gerrit-Reviewer: Harald Welte Gerrit-Reviewer: Jenkins Builder (102) Gerrit-Reviewer: Pau Espin Pedrol Gerrit-Comment-Date: Thu, 11 Apr 2019 15:01:01 + Gerrit-HasComments: Yes Gerrit-HasLabels: No
Change in osmo-ggsn[master]: ggsn: Remove magic numbers from pco_contains_proto()
Pau Espin Pedrol has posted comments on this change. ( https://gerrit.osmocom.org/13567 ) Change subject: ggsn: Remove magic numbers from pco_contains_proto() .. Patch Set 1: Code-Review+2 -- 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: comment Gerrit-Change-Id: I9871ffced677320aa82438332bfdb951ab129f04 Gerrit-Change-Number: 13567 Gerrit-PatchSet: 1 Gerrit-Owner: Harald Welte Gerrit-Reviewer: Harald Welte Gerrit-Reviewer: Jenkins Builder (102) Gerrit-Reviewer: Pau Espin Pedrol Gerrit-Comment-Date: Thu, 11 Apr 2019 15:52:18 + Gerrit-HasComments: No Gerrit-HasLabels: Yes