diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2023-06-12 14:10:08 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2023-06-12 14:10:08 +0200 |
commit | 90b0404e8d656f2cc48bcc6b98577158930f08ea (patch) | |
tree | ef52b4b25db562741155a231ba5bdcad8ec5157b | |
parent | bbfd1377b48ae8ce22dbc7e351daae2358da79f3 (diff) |
Squashed 'src/n-dhcp4/' changes from b2a382ac4500..2707213e3ee0
2707213e3ee0 n-dhcp4: close packet socket after timeout
git-subtree-dir: src/n-dhcp4
git-subtree-split: 2707213e3ee04d9a76ad7df027def93e4dea739f
-rw-r--r-- | src/n-dhcp4-c-connection.c | 16 | ||||
-rw-r--r-- | src/n-dhcp4-private.h | 1 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/n-dhcp4-c-connection.c b/src/n-dhcp4-c-connection.c index 65328286e8..5abd6f5991 100644 --- a/src/n-dhcp4-c-connection.c +++ b/src/n-dhcp4-c-connection.c @@ -152,6 +152,7 @@ int n_dhcp4_c_connection_listen(NDhcp4CConnection *connection) { if (connection->fd_packet >= 0) { epoll_ctl(connection->fd_epoll, EPOLL_CTL_DEL, connection->fd_packet, NULL); connection->fd_packet = c_close(connection->fd_packet); + connection->ns_drain_timeout = 0; } if (connection->fd_udp >= 0) { @@ -211,6 +212,7 @@ int n_dhcp4_c_connection_connect(NDhcp4CConnection *connection, } connection->state = N_DHCP4_C_CONNECTION_STATE_DRAINING; + connection->ns_drain_timeout = n_dhcp4_gettime(CLOCK_BOOTTIME) + UINT64_C(10000000000); connection->fd_udp = fd_udp; fd_udp = -1; connection->client_ip = client->s_addr; @@ -231,6 +233,7 @@ void n_dhcp4_c_connection_close(NDhcp4CConnection *connection) { connection->fd_epoll = -1; connection->state = N_DHCP4_C_CONNECTION_STATE_CLOSED; + connection->ns_drain_timeout = 0; } static int n_dhcp4_c_connection_verify_incoming(NDhcp4CConnection *connection, @@ -325,7 +328,7 @@ void n_dhcp4_c_connection_get_timeout(NDhcp4CConnection *connection, size_t n_send; if (!connection->request) { - *timeoutp = 0; + *timeoutp = connection->ns_drain_timeout; return; } @@ -369,6 +372,9 @@ void n_dhcp4_c_connection_get_timeout(NDhcp4CConnection *connection, c_assert(0); } + if (connection->ns_drain_timeout != 0 && connection->ns_drain_timeout < timeout) + timeout = connection->ns_drain_timeout; + *timeoutp = timeout; } @@ -1122,6 +1128,13 @@ int n_dhcp4_c_connection_dispatch_timer(NDhcp4CConnection *connection, uint64_t timeout; int r; + if (connection->ns_drain_timeout != 0 && connection->ns_drain_timeout < timestamp) { + epoll_ctl(connection->fd_epoll, EPOLL_CTL_DEL, connection->fd_packet, NULL); + connection->fd_packet = c_close(connection->fd_packet); + connection->state = N_DHCP4_C_CONNECTION_STATE_UDP; + connection->ns_drain_timeout = 0; + } + if (!connection->request) return 0; @@ -1189,6 +1202,7 @@ int n_dhcp4_c_connection_dispatch_io(NDhcp4CConnection *connection, c_assert(!r); connection->fd_packet = c_close(connection->fd_packet); connection->state = N_DHCP4_C_CONNECTION_STATE_UDP; + connection->ns_drain_timeout = 0; /* fall-through */ case N_DHCP4_C_CONNECTION_STATE_UDP: diff --git a/src/n-dhcp4-private.h b/src/n-dhcp4-private.h index 6b366884be..8b17a1a25f 100644 --- a/src/n-dhcp4-private.h +++ b/src/n-dhcp4-private.h @@ -331,6 +331,7 @@ struct NDhcp4CConnection { NDhcp4Outgoing *request; /* current request */ + uint64_t ns_drain_timeout; /* timeout for closing packet socket */ uint32_t client_ip; /* client IP address, or 0 */ uint32_t server_ip; /* server IP address, or 0 */ uint16_t mtu; /* client mtu, or 0 */ |