aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2019-06-27 16:07:11 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2019-07-01 12:13:56 +0200
commit36e12d4db849b75541998b433bf38a77f57c0c3d (patch)
tree53e9dc486d4507f24ed8fe9fba43d1f1d8f748a6
parent2404c5b0b7550b29c06f19f1ca7804a2cd14e326 (diff)
ggsn: Use structures instead of raw arrays when parsing ipcp_hdr
We have a structure to handle that data type, so let's use it. Change-Id: I991e53544b733df7773d66280ffa19a2a5123d97
-rw-r--r--ggsn/ggsn.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index 78987e4..1c6bc4d 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -419,13 +419,13 @@ struct ipcp_hdr {
} __attribute__ ((packed));
/* determine if IPCP contains given option */
-static const uint8_t *ipcp_contains_option(const uint8_t *ipcp, size_t ipcp_len,
+static const uint8_t *ipcp_contains_option(const struct ipcp_hdr *ipcp, size_t ipcp_len,
enum ipcp_options opt, size_t opt_minlen)
{
- const uint8_t *cur_opt = ipcp + sizeof(struct ipcp_hdr);
+ const uint8_t *cur_opt = ipcp->options;
/* iterate over Options and check if protocol contained */
- while (cur_opt + sizeof(struct ipcp_option_hdr) <= ipcp + ipcp_len) {
+ while (cur_opt + sizeof(struct ipcp_option_hdr) <= (uint8_t*)ipcp + ipcp_len) {
const struct ipcp_option_hdr *cur_opt_hdr = (const struct ipcp_option_hdr *)cur_opt;
/* length value includes 2 bytes type/length */
if (cur_opt_hdr->len < sizeof(struct ipcp_option_hdr))
@@ -588,7 +588,7 @@ static void process_pco_element_ipcp(const struct pco_element *pco_elem, struct
const struct in46_addr *dns1 = &apn->v4.cfg.dns[0];
const struct in46_addr *dns2 = &apn->v4.cfg.dns[1];
uint8_t *start = resp->tail;
- const uint8_t *ipcp;
+ const struct ipcp_hdr *ipcp;
uint16_t ipcp_len;
uint8_t *len1, *len2;
unsigned int len_appended;
@@ -600,10 +600,10 @@ static void process_pco_element_ipcp(const struct pco_element *pco_elem, struct
return;
}
- ipcp = pco_elem->data;
- consumed = (ipcp - &pdp->pco_req.v[0]);
+ ipcp = (const struct ipcp_hdr *)pco_elem->data;
+ consumed = (pco_elem->data - &pdp->pco_req.v[0]);
remain = sizeof(pdp->pco_req.v) - consumed;
- ipcp_len = osmo_load16be(ipcp + 2); /* 1=code + 1=id */
+ ipcp_len = osmo_load16be(&ipcp->len);
if (remain < 0 || remain < ipcp_len) {
LOGPPDP(LOGL_ERROR, pdp, "Malformed IPCP, ignoring\n");
return;
@@ -614,7 +614,7 @@ static void process_pco_element_ipcp(const struct pco_element *pco_elem, struct
len1 = msgb_put(resp, 1); /* Length of contents: delay */
msgb_put_u8(resp, 0x02); /* ACK */
- msgb_put_u8(resp, ipcp[1]); /* ID: Needs to match request */
+ msgb_put_u8(resp, ipcp->id); /* ID: Needs to match request */
msgb_put_u8(resp, 0x00); /* Length MSB */
len2 = msgb_put(resp, 1); /* Length LSB: delay */