diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2019-02-18 18:22:24 +0100 |
---|---|---|
committer | Hans Dedecker <dedeckeh@gmail.com> | 2019-02-19 09:04:47 +0100 |
commit | afbd7dd2a0f26f603ee21685ede2bba14a41a34a (patch) | |
tree | f78b78b0debb51d98bc0cdb7b6ee7921d69b78cf /src/dhcpv6-ia.c | |
parent | 1f01299c677653cf6d67c82c2df7b7e028508876 (diff) |
dhcp: rework assignment free logic
Replace the separate dhcpv4/dhcpv6 assignment free functions by
the function free_assignment which calls the dhcp specific
free function via a callback
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src/dhcpv6-ia.c')
-rw-r--r-- | src/dhcpv6-ia.c | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index 4cc6fab..9db6a54 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -67,7 +67,7 @@ int dhcpv6_ia_setup_interface(struct interface *iface, bool enable) while (!list_empty(&iface->ia_assignments)) { c = list_first_entry(&iface->ia_assignments, struct dhcp_assignment, head); - dhcpv6_ia_free_assignment(c); + free_assignment(c); } } @@ -201,25 +201,17 @@ static int send_reconf(struct dhcp_assignment *assign) return odhcpd_send(iface->dhcpv6_event.uloop.fd, &assign->peer, &iov, 1, iface); } -void dhcpv6_ia_free_assignment(struct dhcp_assignment *a) +static void dhcpv6_ia_free_assignment(struct dhcp_assignment *a) { if (a->managed_sock.fd.registered) { ustream_free(&a->managed_sock.stream); close(a->managed_sock.fd.fd); } - if (a->head.next) - list_del(&a->head); - - if (a->lease_list.next) - list_del(&a->lease_list); - if (a->reconf_cnt) stop_reconf(a); free(a->managed); - free(a->hostname); - free(a); } void dhcpv6_ia_enum_addrs(struct interface *iface, struct dhcp_assignment *c, @@ -534,7 +526,7 @@ static void managed_handle_pd_data(struct ustream *s, _unused int bytes_new) } if (first && c->managed_size == 0) - dhcpv6_ia_free_assignment(c); + free_assignment(c); else if (first && !(c->flags & OAF_STATIC)) c->valid_until = now + 150; } @@ -786,7 +778,7 @@ static void valid_until_cb(struct uloop_timeout *event) if (!INFINITE_VALID(a->valid_until) && a->valid_until < now) { if ((a->length < 128 && a->clid_len > 0) || (a->length == 128 && a->clid_len == 0)) - dhcpv6_ia_free_assignment(a); + free_assignment(a); } } @@ -1231,7 +1223,7 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac } if (l && a && a->lease != l) { - dhcpv6_ia_free_assignment(a); + free_assignment(a); a = NULL; } @@ -1261,6 +1253,7 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac /* Set valid time to 0 for static lease indicating */ /* infinite lifetime otherwise current time */ a->valid_until = l ? 0 : now; + a->dhcp_free_cb = dhcpv6_ia_free_assignment; a->iface = iface; a->flags = OAF_DHCPV6; @@ -1365,7 +1358,7 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac apply_lease(iface, a, true); } else if (!assigned && a && a->managed_size == 0) { /* Cleanup failed assignment */ - dhcpv6_ia_free_assignment(a); + free_assignment(a); a = NULL; } } else if (hdr->msg_type == DHCPV6_MSG_RENEW || |