sd-dhcp-client: listen on UDP socket as soon as a lease is acquired
This is necessary in order to listen for FORCERENEW events.
This commit is contained in:
parent
076adf013a
commit
0af03ba57f
|
@ -731,8 +731,8 @@ error:
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int client_initialize_events(sd_dhcp_client *client,
|
||||
sd_event_io_handler_t io_callback) {
|
||||
static int client_initialize_io_events(sd_dhcp_client *client,
|
||||
sd_event_io_handler_t io_callback) {
|
||||
int r;
|
||||
|
||||
assert(client);
|
||||
|
@ -749,6 +749,19 @@ static int client_initialize_events(sd_dhcp_client *client,
|
|||
if (r < 0)
|
||||
goto error;
|
||||
|
||||
error:
|
||||
if (r < 0)
|
||||
client_stop(client, r);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int client_initialize_time_events(sd_dhcp_client *client) {
|
||||
int r;
|
||||
|
||||
assert(client);
|
||||
assert(client->event);
|
||||
|
||||
client->timeout_resend = sd_event_source_unref(client->timeout_resend);
|
||||
|
||||
r = sd_event_add_time(client->event,
|
||||
|
@ -770,6 +783,14 @@ error:
|
|||
|
||||
}
|
||||
|
||||
static int client_initialize_events(sd_dhcp_client *client,
|
||||
sd_event_io_handler_t io_callback) {
|
||||
client_initialize_io_events(client, io_callback);
|
||||
client_initialize_time_events(client);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int client_start(sd_dhcp_client *client) {
|
||||
int r;
|
||||
|
||||
|
@ -846,16 +867,7 @@ static int client_timeout_t1(sd_event_source *s, uint64_t usec,
|
|||
client->state = DHCP_STATE_RENEWING;
|
||||
client->attempt = 1;
|
||||
|
||||
r = dhcp_network_bind_udp_socket(client->lease->address,
|
||||
DHCP_PORT_CLIENT);
|
||||
if (r < 0) {
|
||||
log_dhcp_client(client, "could not bind UDP socket");
|
||||
return 0;
|
||||
}
|
||||
|
||||
client->fd = r;
|
||||
|
||||
return client_initialize_events(client, client_receive_message_udp);
|
||||
return client_initialize_time_events(client);
|
||||
}
|
||||
|
||||
static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer,
|
||||
|
@ -1175,15 +1187,23 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message,
|
|||
if (r < 0)
|
||||
goto error;
|
||||
|
||||
r = dhcp_network_bind_udp_socket(client->lease->address,
|
||||
DHCP_PORT_CLIENT);
|
||||
if (r < 0) {
|
||||
log_dhcp_client(client, "could not bind UDP socket");
|
||||
goto error;
|
||||
}
|
||||
|
||||
client->fd = r;
|
||||
|
||||
client_initialize_io_events(client, client_receive_message_udp);
|
||||
|
||||
if (notify_event) {
|
||||
client_notify(client, notify_event);
|
||||
if (client->state == DHCP_STATE_STOPPED)
|
||||
return 0;
|
||||
}
|
||||
|
||||
client->receive_message =
|
||||
sd_event_source_unref(client->receive_message);
|
||||
client->fd = asynchronous_close(client->fd);
|
||||
} else if (r == -EADDRNOTAVAIL) {
|
||||
/* got a NAK, let's restart the client */
|
||||
client->timeout_resend =
|
||||
|
|
Loading…
Reference in a new issue