if (!a) {
if (!iface->no_dynamic_dhcp || l) {
/* Create new binding */
- a = calloc(1, sizeof(*a));
+ a = alloc_assignment(0);
if (!a) {
- syslog(LOG_ERR, "Failed to calloc binding on interface %s",
+ syslog(LOG_ERR, "Failed to alloc assignment on interface %s",
iface->ifname);
return NULL;
}
} else if (((a->addr & iface->dhcpv4_mask.s_addr) !=
(iface->dhcpv4_start_ip.s_addr & iface->dhcpv4_mask.s_addr)) &&
!(a->flags & OAF_STATIC)) {
- list_del(&a->head);
+ list_del_init(&a->head);
a->addr = INADDR_ANY;
assigned = dhcpv4_assign(iface, a, reqaddr);
struct dhcp_assignment *border;
if (list_empty(&iface->ia_assignments)) {
- border = calloc(1, sizeof(*border));
+ border = alloc_assignment(0);
if (!border) {
- syslog(LOG_ERR, "Calloc failed for border on %s", iface->name);
+ syslog(LOG_ERR, "Failed to alloc border on %s", iface->name);
return -1;
}
while (!list_empty(&reassign)) {
c = list_first_entry(&reassign, struct dhcp_assignment, head);
- list_del(&c->head);
+ list_del_init(&c->head);
if (!assign_pd(iface, c)) {
c->assigned = 0;
list_add(&c->head, &iface->ia_assignments);
if ((!iface->no_dynamic_dhcp || (l && is_na)) &&
(iface->dhcpv6_pd || iface->dhcpv6_na)) {
/* Create new binding */
- a = calloc(1, sizeof(*a) + clid_len);
+ a = alloc_assignment(clid_len);
if (a) {
a->clid_len = clid_len;
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);
+ list_del(&a->head);
+ list_del(&a->lease_list);
if (a->dhcp_free_cb)
a->dhcp_free_cb(a);
free(a);
}
+inline static struct dhcp_assignment *alloc_assignment(size_t extra_len)
+{
+ struct dhcp_assignment *a = calloc(1, sizeof(*a) + extra_len);
+
+ if (!a)
+ return NULL;
+
+ INIT_LIST_HEAD(&a->head);
+ INIT_LIST_HEAD(&a->lease_list);
+
+ return a;
+}
+
// Exported main functions
int odhcpd_register(struct odhcpd_event *event);
int odhcpd_deregister(struct odhcpd_event *event);