X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=src%2Fodhcp6c.c;h=ba568bd4499acd962e975edebc7ace89561bcfef;hb=5564b13149da1754694a5c5eabbba2159f07bf7a;hp=1714d629b7cc38a7b3816cfaac58af5a2420baa0;hpb=23aa0c218808361c1252b73a8ba82a91ac9039e7;p=odhcp6c.git diff --git a/src/odhcp6c.c b/src/odhcp6c.c index 1714d62..ba568bd 100644 --- a/src/odhcp6c.c +++ b/src/odhcp6c.c @@ -570,8 +570,9 @@ static struct odhcp6c_entry* odhcp6c_find_entry(enum odhcp6c_state state, const 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; @@ -604,10 +605,10 @@ bool odhcp6c_update_entry(enum odhcp6c_state state, struct odhcp6c_entry *new, 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; } @@ -618,8 +619,9 @@ static void odhcp6c_expire_list(enum odhcp6c_state state, uint32_t elapsed) 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]; - c = (struct odhcp6c_entry*)(&c->auxtarget[c->auxlen])) { + (uint8_t*)c < &start[len] && + (uint8_t*)odhcp6c_next_entry(c) <= &start[len]; + ) { if (c->t1 < elapsed) c->t1 = 0; else if (c->t1 != UINT32_MAX) @@ -640,8 +642,12 @@ static void odhcp6c_expire_list(enum odhcp6c_state state, uint32_t elapsed) else if (c->valid != UINT32_MAX) c->valid -= elapsed; - if (!c->valid) - odhcp6c_remove_state(state, ((uint8_t*)c) - start, sizeof(*c) + c->auxlen); + if (!c->valid) { + odhcp6c_remove_state(state, ((uint8_t*)c) - start, odhcp6c_entry_size(c)); + start = odhcp6c_get_state(state, &len); + } else { + c = odhcp6c_next_entry(c); + } } }