Browse Source

[tcp] Discard all TCP connections on shutdown

Allow detection of genuine memory leaks by ensuring that all TCP
connections are freed on shutdown.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
8a0331c29b
1 changed files with 22 additions and 0 deletions
  1. 22
    0
      src/net/tcp.c

+ 22
- 0
src/net/tcp.c View File

7
 #include <ipxe/timer.h>
7
 #include <ipxe/timer.h>
8
 #include <ipxe/iobuf.h>
8
 #include <ipxe/iobuf.h>
9
 #include <ipxe/malloc.h>
9
 #include <ipxe/malloc.h>
10
+#include <ipxe/init.h>
10
 #include <ipxe/retry.h>
11
 #include <ipxe/retry.h>
11
 #include <ipxe/refcnt.h>
12
 #include <ipxe/refcnt.h>
12
 #include <ipxe/xfer.h>
13
 #include <ipxe/xfer.h>
343
 
344
 
344
 		/* Remove from list and drop reference */
345
 		/* Remove from list and drop reference */
345
 		stop_timer ( &tcp->timer );
346
 		stop_timer ( &tcp->timer );
347
+		stop_timer ( &tcp->wait );
346
 		list_del ( &tcp->list );
348
 		list_del ( &tcp->list );
347
 		ref_put ( &tcp->refcnt );
349
 		ref_put ( &tcp->refcnt );
348
 		DBGC ( tcp, "TCP %p connection deleted\n", tcp );
350
 		DBGC ( tcp, "TCP %p connection deleted\n", tcp );
1261
 	.discard = tcp_discard,
1263
 	.discard = tcp_discard,
1262
 };
1264
 };
1263
 
1265
 
1266
+/**
1267
+ * Shut down all TCP connections
1268
+ *
1269
+ */
1270
+static void tcp_shutdown ( int booting __unused ) {
1271
+	struct tcp_connection *tcp;
1272
+
1273
+	while ( ( tcp = list_first_entry ( &tcp_conns, struct tcp_connection,
1274
+					   list ) ) != NULL ) {
1275
+		tcp->tcp_state = TCP_CLOSED;
1276
+		tcp_dump_state ( tcp );
1277
+		tcp_close ( tcp, -ECANCELED );
1278
+	}
1279
+}
1280
+
1281
+/** TCP shutdown function */
1282
+struct startup_fn tcp_startup_fn __startup_fn ( STARTUP_EARLY ) = {
1283
+	.shutdown = tcp_shutdown,
1284
+};
1285
+
1264
 /***************************************************************************
1286
 /***************************************************************************
1265
  *
1287
  *
1266
  * Data transfer interface
1288
  * Data transfer interface

Loading…
Cancel
Save