about summary refs log tree commit diff
path: root/src/n-dhcp4
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2023-08-09 21:56:59 +0200
committerMichael Biebl <biebl@debian.org>2023-08-09 21:56:59 +0200
commitb1206f287e4fae1f9a7e29ec0dc11b54d726a7f8 (patch)
treecc1d62cd21f10b2375c76484b5e2187f1e75f010 /src/n-dhcp4
parenta6d4d07b23485507f30ddb1ce99f5c82428714c8 (diff)
parent05e4a733f2141995181a551854d5df929f084adf (diff)
Update upstream source from tag 'upstream/1.44.0'
Update to upstream version '1.44.0'
with Debian dir e69e19b54914190e7696747b3e0508f95977f387
Diffstat (limited to 'src/n-dhcp4')
-rw-r--r--src/n-dhcp4/src/n-dhcp4-c-connection.c16
-rw-r--r--src/n-dhcp4/src/n-dhcp4-private.h1
2 files changed, 16 insertions, 1 deletions
diff --git a/src/n-dhcp4/src/n-dhcp4-c-connection.c b/src/n-dhcp4/src/n-dhcp4-c-connection.c
index 65328286..5abd6f59 100644
--- a/src/n-dhcp4/src/n-dhcp4-c-connection.c
+++ b/src/n-dhcp4/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/src/n-dhcp4-private.h b/src/n-dhcp4/src/n-dhcp4-private.h
index 6b366884..8b17a1a2 100644
--- a/src/n-dhcp4/src/n-dhcp4-private.h
+++ b/src/n-dhcp4/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 */