Don't apply excess filter to DHCPv6 and unify odhcp6c_update_entry
authorSteven Barth <steven@midlink.org>
Wed, 10 Dec 2014 10:38:20 +0000 (11:38 +0100)
committerSteven Barth <steven@midlink.org>
Wed, 10 Dec 2014 10:38:20 +0000 (11:38 +0100)
src/dhcpv6.c
src/odhcp6c.c
src/odhcp6c.h
src/ra.c

index 597d239b5daa3451d4d00b3ce57407b779a21afd..5cda153bcdd5dcec3dd8bb4ea709fac62e418d18 100644 (file)
@@ -1213,7 +1213,7 @@ static int dhcpv6_parse_ia(void *opt, void *end)
                        }
 
                        if (ok) {
-                               odhcp6c_update_entry(STATE_IA_PD, &entry);
+                               odhcp6c_update_entry(STATE_IA_PD, &entry, 0, false);
                                parsed_ia++;
                        }
 
@@ -1248,7 +1248,7 @@ static int dhcpv6_parse_ia(void *opt, void *end)
                                        entry.class = sdata[0] << 8 | sdata[1];
 #endif
 
-                       odhcp6c_update_entry(STATE_IA_NA, &entry);
+                       odhcp6c_update_entry(STATE_IA_NA, &entry, 0, false);
                        parsed_ia++;
                }
        }
index 8149738ade5d6d84cc88d7c14c55a8639236c232..37128308f26666d8e75a7941bb758ff92635d9e9 100644 (file)
@@ -565,7 +565,8 @@ struct odhcp6c_entry* odhcp6c_find_entry(enum odhcp6c_state state, const struct
 }
 
 
-bool odhcp6c_update_entry_safe(enum odhcp6c_state state, struct odhcp6c_entry *new, uint32_t safe)
+bool odhcp6c_update_entry(enum odhcp6c_state state, struct odhcp6c_entry *new,
+               uint32_t safe, bool filterexcess)
 {
        size_t len;
        struct odhcp6c_entry *x = odhcp6c_find_entry(state, new);
@@ -576,7 +577,8 @@ bool odhcp6c_update_entry_safe(enum odhcp6c_state state, struct odhcp6c_entry *n
 
        if (new->valid > 0) {
                if (x) {
-                       if (new->valid >= x->valid && new->valid != UINT32_MAX &&
+                       if (filterexcess && new->valid >= x->valid &&
+                                       new->valid != UINT32_MAX &&
                                        new->valid - x->valid < min_update_interval &&
                                        new->preferred >= x->preferred &&
                                        new->preferred != UINT32_MAX &&
@@ -599,12 +601,6 @@ bool odhcp6c_update_entry_safe(enum odhcp6c_state state, struct odhcp6c_entry *n
 }
 
 
-bool odhcp6c_update_entry(enum odhcp6c_state state, struct odhcp6c_entry *new)
-{
-       return odhcp6c_update_entry_safe(state, new, 0);
-}
-
-
 static void odhcp6c_expire_list(enum odhcp6c_state state, uint32_t elapsed)
 {
        size_t len;
index 0efae10571727f392abbd1932f94b29c1f3dbab6..1fda72a2ae32f6b5e005a7ad22e782ff3895683f 100644 (file)
@@ -339,8 +339,7 @@ void* odhcp6c_get_state(enum odhcp6c_state state, size_t *len);
 
 // Entry manipulation
 struct odhcp6c_entry* odhcp6c_find_entry(enum odhcp6c_state state, const struct odhcp6c_entry *new);
-bool odhcp6c_update_entry(enum odhcp6c_state state, struct odhcp6c_entry *new);
-bool odhcp6c_update_entry_safe(enum odhcp6c_state state, struct odhcp6c_entry *new, uint32_t safe);
+bool odhcp6c_update_entry(enum odhcp6c_state state, struct odhcp6c_entry *new, uint32_t safe, bool filterexcess);
 
 void odhcp6c_expire(void);
 uint32_t odhcp6c_elapsed(void);
index 9c5eb220897552b629e66df8fb5bb3d7eda2ff6a..b21bc5615e5acb65ea1938e742437a80bac22f98 100644 (file)
--- a/src/ra.c
+++ b/src/ra.c
@@ -329,7 +329,7 @@ bool ra_process(void)
                        entry.priority = pref_to_priority(0);
                entry.valid = router_valid;
                entry.preferred = entry.valid;
-               changed |= odhcp6c_update_entry(STATE_RA_ROUTE, &entry);
+               changed |= odhcp6c_update_entry(STATE_RA_ROUTE, &entry, 0, true);
 
                // Parse hoplimit
                if (adv->nd_ra_curhoplimit)
@@ -367,7 +367,7 @@ bool ra_process(void)
                                        continue;
 
                                if (entry.priority > 0)
-                                       changed |= odhcp6c_update_entry(STATE_RA_ROUTE, &entry);
+                                       changed |= odhcp6c_update_entry(STATE_RA_ROUTE, &entry, 0, true);
                        } else if (opt->type == ND_OPT_PREFIX_INFORMATION && opt->len == 4) {
                                struct nd_opt_prefix_info *pinfo = (struct nd_opt_prefix_info*)opt;
                                entry.router = any;
@@ -384,7 +384,7 @@ bool ra_process(void)
                                        continue;
 
                                if (pinfo->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK)
-                                       changed |= odhcp6c_update_entry_safe(STATE_RA_ROUTE, &entry, 7200);
+                                       changed |= odhcp6c_update_entry(STATE_RA_ROUTE, &entry, 7200, true);
 
                                if (!(pinfo->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO) ||
                                                pinfo->nd_opt_pi_prefix_len != 64)
@@ -393,7 +393,7 @@ bool ra_process(void)
                                entry.target.s6_addr32[2] = lladdr.s6_addr32[2];
                                entry.target.s6_addr32[3] = lladdr.s6_addr32[3];
 
-                               changed |= odhcp6c_update_entry_safe(STATE_RA_PREFIX, &entry, 7200);
+                               changed |= odhcp6c_update_entry(STATE_RA_PREFIX, &entry, 7200, true);
                        } else if (opt->type == ND_OPT_RECURSIVE_DNS && opt->len > 2) {
                                entry.router = from.sin6_addr;
                                entry.priority = 0;
@@ -405,7 +405,7 @@ bool ra_process(void)
                                for (ssize_t i = 0; i < (opt->len - 1) / 2; ++i) {
                                        memcpy(&entry.target, &opt->data[6 + i * sizeof(entry.target)],
                                                        sizeof(entry.target));
-                                       changed |= odhcp6c_update_entry(STATE_RA_DNS, &entry);
+                                       changed |= odhcp6c_update_entry(STATE_RA_DNS, &entry, 0, true);
                                }
                        }
                }