uint8_t *start = odhcp6c_get_state(state, &len);
for (struct odhcp6c_entry *c = (struct odhcp6c_entry*)start;
- (uint8_t*)c < &start[len] && &c->auxtarget[c->auxlen] <= &start[len];
- c = (struct odhcp6c_entry*)(&c->auxtarget[c->auxlen]))
+ (uint8_t*)c < &start[len] &&
+ (uint8_t*)odhcp6c_next_entry(c) <= &start[len];
+ c = odhcp6c_next_entry(c))
if (!memcmp(c, new, cmplen) && !memcmp(c->auxtarget, new->auxtarget, new->auxlen))
return c;
x->t2 = new->t2;
x->iaid = new->iaid;
} else {
- odhcp6c_add_state(state, new, sizeof(*new) + new->auxlen);
+ odhcp6c_add_state(state, new, odhcp6c_entry_size(new));
}
} else if (x) {
- odhcp6c_remove_state(state, ((uint8_t*)x) - start, sizeof(*x) + x->auxlen);
+ odhcp6c_remove_state(state, ((uint8_t*)x) - start, odhcp6c_entry_size(x));
}
return true;
}
size_t len;
uint8_t *start = odhcp6c_get_state(state, &len);
for (struct odhcp6c_entry *c = (struct odhcp6c_entry*)start;
- (uint8_t*)c < &start[len] && &c->auxtarget[c->auxlen] <= &start[len];
+ (uint8_t*)c < &start[len] &&
+ (uint8_t*)odhcp6c_next_entry(c) <= &start[len];
) {
if (c->t1 < elapsed)
c->t1 = 0;
c->valid -= elapsed;
if (!c->valid) {
- odhcp6c_remove_state(state, ((uint8_t*)c) - start, sizeof(*c) + c->auxlen);
+ odhcp6c_remove_state(state, ((uint8_t*)c) - start, odhcp6c_entry_size(c));
start = odhcp6c_get_state(state, &len);
} else {
- c = (struct odhcp6c_entry*)(&c->auxtarget[c->auxlen]);
+ c = odhcp6c_next_entry(c);
}
}
}
uint8_t auxtarget[];
};
+// Include padding after auxtarget to align the next entry
+#define odhcp6c_entry_size(entry) \
+ (sizeof(struct odhcp6c_entry) + (((entry)->auxlen + 3) & ~3))
+
+#define odhcp6c_next_entry(entry) \
+ ((struct odhcp6c_entry *)((uint8_t *)(entry) + odhcp6c_entry_size(entry)))
+
+
struct odhcp6c_request_prefix {
uint32_t iaid;
uint16_t length;
size_t ra_dns_len;
uint8_t *start = odhcp6c_get_state(states[i], &ra_dns_len);
for (struct odhcp6c_entry *c = (struct odhcp6c_entry*)start;
- (uint8_t*)c < &start[ra_dns_len] && &c->auxtarget[c->auxlen] <= &start[ra_dns_len];
- c = (struct odhcp6c_entry*)(&c->auxtarget[c->auxlen]))
+ (uint8_t*)c < &start[ra_dns_len] &&
+ (uint8_t*)odhcp6c_next_entry(c) <= &start[ra_dns_len];
+ c = odhcp6c_next_entry(c))
if (IN6_ARE_ADDR_EQUAL(&c->router, &from.sin6_addr) &&
c->valid > router_valid)
c->valid = router_valid;
*c++ = '=';
for (struct odhcp6c_entry *e = (struct odhcp6c_entry*)start;
- (uint8_t*)e < &start[len] && &e->auxtarget[e->auxlen] <= &start[len];
- e = (struct odhcp6c_entry*)(&e->auxtarget[e->auxlen])) {
+ (uint8_t*)e < &start[len] &&
+ (uint8_t*)odhcp6c_next_entry(e) <= &start[len];
+ e = odhcp6c_next_entry(e)) {
c = mempcpy(c, e->auxtarget, e->auxlen);
*c++ = ' ';
}