list_for_each_entry_safe(a, tmp, &l->assignments, lease_list) {
if (a->flags & flag)
-#ifdef DHCPV4_SUPPORT
- v6 ? dhcpv6_ia_free_assignment(a) : dhcpv4_free_assignment(a);
-#else
- dhcpv6_ia_free_assignment(a);
-#endif
+ free_assignment(a);
}
}
{
struct dhcp_assignment *a;
- list_for_each_entry(a, &l->assignments, lease_list) {
- if (a->flags & OAF_DHCPV6)
- dhcpv6_ia_free_assignment(a);
-#ifdef DHCPV4_SUPPORT
- else if (a->flags & OAF_DHCPV4)
- dhcpv4_free_assignment(a);
-#endif
- }
+ list_for_each_entry(a, &l->assignments, lease_list)
+ free_assignment(a);
free_lease(l);
}
odhcpd_register(&iface->dhcpv4_event);
} else if (iface->dhcpv4_assignments.next) {
while (!list_empty(&iface->dhcpv4_assignments))
- dhcpv4_free_assignment(list_first_entry(&iface->dhcpv4_assignments,
+ free_assignment(list_first_entry(&iface->dhcpv4_assignments,
struct dhcp_assignment, head));
}
struct dhcp_assignment *a, *n;
list_for_each_entry_safe(a, n, &iface->dhcpv4_assignments, head) {
if (!INFINITE_VALID(a->valid_until) && a->valid_until < now)
- dhcpv4_free_assignment(a);
+ free_assignment(a);
}
}
uloop_timeout_set(event, 1000);
}
}
-void dhcpv4_free_assignment(struct dhcp_assignment *a)
+static void dhcpv4_free_assignment(struct dhcp_assignment *a)
{
- if (a->head.next)
- list_del(&a->head);
-
- if (a->lease_list.next)
- list_del(&a->lease_list);
-
if (a->fr_ip)
dhcpv4_fr_stop(a);
-
- free(a->hostname);
- free(a);
}
static void dhcpv4_put(struct dhcpv4_message *msg, uint8_t **cookie,
time_t now = odhcpd_time();
if (l && a && a->lease != l) {
- dhcpv4_free_assignment(a);
+ free_assignment(a);
a = NULL;
}
/* Set valid time to 0 for static lease indicating */
/* infinite lifetime otherwise current time */
a->valid_until = l ? 0 : now;
+ a->dhcp_free_cb = dhcpv4_free_assignment;
a->iface = iface;
a->flags = OAF_DHCPV4;
a->addr = l ? l->ipaddr : INADDR_ANY;
}
} else if (!assigned && a) {
/* Cleanup failed assignment */
- dhcpv4_free_assignment(a);
+ free_assignment(a);
a = NULL;
}
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);
}
}
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,
}
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;
}
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);
}
}
}
if (l && a && a->lease != l) {
- dhcpv6_ia_free_assignment(a);
+ free_assignment(a);
a = NULL;
}
/* 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;
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 ||
struct list_head head;
struct list_head lease_list;
+ void (*dhcp_free_cb)(struct dhcp_assignment *a);
+
struct interface *iface;
struct lease *lease;
#define RA_MANAGED_MFLAG 1
#define RA_MANAGED_NO_AFLAG 2
+inline static void free_assignment(struct dhcp_assignment *a)
+{
+ if (a->head.next)
+ list_del(&a->head);
+
+ if (a->lease_list.next)
+ list_del(&a->lease_list);
+
+ if (a->dhcp_free_cb)
+ a->dhcp_free_cb(a);
+
+ free(a->hostname);
+ free(a);
+}
// Exported main functions
int odhcpd_register(struct odhcpd_event *event);
void dhcpv6_ia_enum_addrs(struct interface *iface, struct dhcp_assignment *c, time_t now,
dhcpv6_binding_cb_handler_t func, void *arg);
void dhcpv6_ia_write_statefile(void);
-void dhcpv6_ia_free_assignment(struct dhcp_assignment *c);
int netlink_add_netevent_handler(struct netevent_handler *hdlr);
ssize_t netlink_get_interface_addrs(const int ifindex, bool v6,
int ndp_init(void);
#ifdef DHCPV4_SUPPORT
int dhcpv4_init(void);
-void dhcpv4_free_assignment(struct dhcp_assignment *a);
int dhcpv4_setup_interface(struct interface *iface, bool enable);
#endif