diff options
author | Michael Brown | 2012-05-08 13:39:04 +0200 |
---|---|---|
committer | Michael Brown | 2012-05-08 13:49:01 +0200 |
commit | 8a0331c29b950b5f940dc2157f69b5b7610460c8 (patch) | |
tree | 68dd40b802fc2670299eb388d17f17772e94f38e /src/net/tcp.c | |
parent | [tcp] Fix potential NULL pointer dereference (diff) | |
download | ipxe-8a0331c29b950b5f940dc2157f69b5b7610460c8.tar.gz ipxe-8a0331c29b950b5f940dc2157f69b5b7610460c8.tar.xz ipxe-8a0331c29b950b5f940dc2157f69b5b7610460c8.zip |
[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>
Diffstat (limited to 'src/net/tcp.c')
-rw-r--r-- | src/net/tcp.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/net/tcp.c b/src/net/tcp.c index 5a9810b2..b1533915 100644 --- a/src/net/tcp.c +++ b/src/net/tcp.c @@ -7,6 +7,7 @@ #include <ipxe/timer.h> #include <ipxe/iobuf.h> #include <ipxe/malloc.h> +#include <ipxe/init.h> #include <ipxe/retry.h> #include <ipxe/refcnt.h> #include <ipxe/xfer.h> @@ -343,6 +344,7 @@ static void tcp_close ( struct tcp_connection *tcp, int rc ) { /* Remove from list and drop reference */ stop_timer ( &tcp->timer ); + stop_timer ( &tcp->wait ); list_del ( &tcp->list ); ref_put ( &tcp->refcnt ); DBGC ( tcp, "TCP %p connection deleted\n", tcp ); @@ -1261,6 +1263,26 @@ struct cache_discarder tcp_cache_discarder __cache_discarder = { .discard = tcp_discard, }; +/** + * Shut down all TCP connections + * + */ +static void tcp_shutdown ( int booting __unused ) { + struct tcp_connection *tcp; + + while ( ( tcp = list_first_entry ( &tcp_conns, struct tcp_connection, + list ) ) != NULL ) { + tcp->tcp_state = TCP_CLOSED; + tcp_dump_state ( tcp ); + tcp_close ( tcp, -ECANCELED ); + } +} + +/** TCP shutdown function */ +struct startup_fn tcp_startup_fn __startup_fn ( STARTUP_EARLY ) = { + .shutdown = tcp_shutdown, +}; + /*************************************************************************** * * Data transfer interface |