summaryrefslogtreecommitdiff
path: root/gdhcp/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdhcp/server.c')
-rw-r--r--gdhcp/server.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/gdhcp/server.c b/gdhcp/server.c
index aa40488..0171b5f 100644
--- a/gdhcp/server.c
+++ b/gdhcp/server.c
@@ -65,6 +65,7 @@ struct _GDHCPServer {
GHashTable *nip_lease_hash;
GHashTable *option_hash; /* Options send to client */
GDHCPSaveLeaseFunc save_lease_func;
+ GDHCPSaveACKLeaseFunc save_ack_lease_func;
GDHCPDebugFunc debug_func;
gpointer debug_data;
};
@@ -398,6 +399,7 @@ GDHCPServer *g_dhcp_server_new(GDHCPType type,
dhcp_server->listener_watch = -1;
dhcp_server->listener_channel = NULL;
dhcp_server->save_lease_func = NULL;
+ dhcp_server->save_ack_lease_func = NULL;
dhcp_server->debug_func = NULL;
dhcp_server->debug_data = NULL;
@@ -646,9 +648,12 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition,
struct dhcp_packet packet;
struct dhcp_lease *lease;
uint32_t requested_nip = 0;
- uint8_t type, *server_id_option, *request_ip_option;
+ uint8_t type, *server_id_option, *request_ip_option, *host_name;
int re;
+ GDHCPOptionType option_type;
+ char *option_value;
+
if (condition & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
dhcp_server->listener_watch = 0;
return FALSE;
@@ -693,8 +698,21 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition,
if (lease && requested_nip == lease->lease_nip) {
debug(dhcp_server, "Sending ACK");
+
+ host_name = dhcp_get_option(&packet, DHCP_HOST_NAME);
+ option_type = dhcp_get_code_type(DHCP_HOST_NAME);
+ option_value = malloc_option_value_string(host_name,
+ option_type);
send_ACK(dhcp_server, &packet,
lease->lease_nip);
+
+ if (dhcp_server->save_ack_lease_func)
+ dhcp_server->save_ack_lease_func(
+ option_value,
+ lease->lease_mac,
+ lease->lease_nip);
+ g_free(option_value);
+
break;
}
@@ -814,6 +832,15 @@ void g_dhcp_server_set_save_lease(GDHCPServer *dhcp_server,
dhcp_server->save_lease_func = func;
}
+void g_dhcp_server_set_save_ack_lease(GDHCPServer *dhcp_server,
+ GDHCPSaveACKLeaseFunc func, gpointer user_data)
+{
+ if (dhcp_server == NULL)
+ return;
+
+ dhcp_server->save_ack_lease_func = func;
+}
+
GDHCPServer *g_dhcp_server_ref(GDHCPServer *dhcp_server)
{
if (!dhcp_server)