chiark / gitweb /
sd-dhcp-server: add RELEASE support
authorTom Gundersen <teg@jklm.no>
Mon, 26 May 2014 13:18:47 +0000 (15:18 +0200)
committerTom Gundersen <teg@jklm.no>
Fri, 13 Jun 2014 15:07:20 +0000 (17:07 +0200)
src/libsystemd-network/sd-dhcp-server.c

index cb014e2..4ce1054 100644 (file)
@@ -544,7 +544,7 @@ static int get_pool_offset(sd_dhcp_server *server, be32_t requested_ip) {
 
         if (be32toh(requested_ip) < be32toh(server->pool_start) ||
             be32toh(requested_ip) >= be32toh(server->pool_start) +
-                                                  + server->pool_size)
+                                             + server->pool_size)
                 return -EINVAL;
 
         return be32toh(requested_ip) - be32toh(server->pool_start);
@@ -743,6 +743,31 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
 
                 break;
         }
+        case DHCP_RELEASE: {
+                int pool_offset;
+
+                log_dhcp_server(server, "RELEASE (0x%x)",
+                                be32toh(req->message->xid));
+
+                if (!existing_lease)
+                        return 0;
+
+                if (existing_lease->address != req->message->ciaddr)
+                        return 0;
+
+                pool_offset = get_pool_offset(server, req->message->ciaddr);
+                if (pool_offset < 0)
+                        return 0;
+
+                if (server->bound_leases[pool_offset] == existing_lease) {
+                        server->bound_leases[pool_offset] = NULL;
+                        hashmap_remove(server->leases_by_client_id, existing_lease);
+                        dhcp_lease_free(existing_lease);
+
+                        return 1;
+                } else
+                        return 0;
+        }
         }
 
         return 0;