+struct odhcp6c_entry* odhcp6c_find_entry(enum odhcp6c_state state, const struct odhcp6c_entry *new)
+{
+ size_t len, cmplen = offsetof(struct odhcp6c_entry, target) + new->length / 8;
+ struct odhcp6c_entry *start = odhcp6c_get_state(state, &len);
+ struct odhcp6c_entry *x = NULL;
+
+ for (struct odhcp6c_entry *c = start; !x && c < &start[len/sizeof(*c)]; ++c)
+ if (!memcmp(c, new, cmplen))
+ return c;
+
+ return NULL;
+}
+
+
+void odhcp6c_update_entry_safe(enum odhcp6c_state state, struct odhcp6c_entry *new, uint32_t safe)
+{
+ size_t len;
+ struct odhcp6c_entry *x = odhcp6c_find_entry(state, new);
+ struct odhcp6c_entry *start = odhcp6c_get_state(state, &len);
+
+ if (x && x->valid > new->valid && new->valid < safe)
+ new->valid = safe;
+
+ if (new->valid > 0) {
+ if (x) {
+ x->valid = new->valid;
+ x->preferred = new->preferred;
+ x->prefix_class = new->prefix_class;
+ } else {
+ odhcp6c_add_state(state, new, sizeof(*new));
+ }
+ } else if (x) {
+ odhcp6c_remove_state(state, (x - start) * sizeof(*x), sizeof(*x));
+ }
+}
+
+
+void odhcp6c_update_entry(enum odhcp6c_state state, struct odhcp6c_entry *new)