netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Demonstration code on how to trigger tcp6_sock leak
@ 2004-01-24 13:13 Erik Hensema
  2004-01-25  5:25 ` YOSHIFUJI Hideaki / 吉藤英明
  2004-01-26 20:30 ` FIX (was Re: Demonstration code on how to trigger tcp6_sock leak) David S. Miller
  0 siblings, 2 replies; 5+ messages in thread
From: Erik Hensema @ 2004-01-24 13:13 UTC (permalink / raw)
  To: netdev

[-- Attachment #1: Type: text/plain, Size: 370 bytes --]

Hi,

I wrote some quick&dirty code showing the tcp6_sock leak in Linux 2.6.x.
The server part listens for incoming connections and accept()'s them. The
client will simply connect() to the server and close the connection.

Do a 'grep tcp6_sock /proc/slabinfo' before and after running the programs,
and you will clearly see the leak.

-- 
Erik Hensema (erik@hensema.net)

[-- Attachment #2: server.c --]
[-- Type: text/plain, Size: 752 bytes --]

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <strings.h>
#include <stdio.h>

#define port 4000

int
main(
		int argc,
		char **argv
    )
{
	int fd;
	struct sockaddr_in6 myaddr;
	struct sockaddr addr;
	socklen_t len;
	int i;

	if((fd = socket(PF_INET6, SOCK_STREAM, 0)) < 0) {
		perror("socket");
	}

	bzero(&myaddr, sizeof(myaddr));
	myaddr.sin6_family = AF_INET6;
	myaddr.sin6_port = htons(port);
	myaddr.sin6_addr = in6addr_any;

	if(bind(fd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) {
		perror("bind");
	}

	if(listen(fd, 32) < 0) {
		perror("listen");
	}

	for(i = 0; i < 1000; i++) {
		if(accept(fd, &addr, &len) < 0) {
			perror("accept");
		} else {
			printf("Accept: %d\n", i);
		}
	}

	return 0;
}

[-- Attachment #3: client.c --]
[-- Type: text/plain, Size: 692 bytes --]

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

#define port 4000

int
main(
		int argc,
		char **argv
    )
{
	int fd;
	struct sockaddr_in6 srvaddr;
	int i;


	bzero(&srvaddr, sizeof(srvaddr));

	srvaddr.sin6_family = AF_INET6;
	srvaddr.sin6_port = htons(port);
	srvaddr.sin6_addr = in6addr_loopback;

	for(i = 0; 1; i++) {
		if((fd = socket(PF_INET6, SOCK_STREAM, 0)) < 0) {
			perror("socket");
			exit(0);
		}

		if(connect(fd, (const struct sockaddr *)&srvaddr, sizeof(srvaddr)) < 0) {
			perror("connect");
		} else {
			printf("Connect %d\n", i);
			close(fd);
		}
	}

	return 0;
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-01-27  2:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-24 13:13 Demonstration code on how to trigger tcp6_sock leak Erik Hensema
2004-01-25  5:25 ` YOSHIFUJI Hideaki / 吉藤英明
2004-01-26 20:30 ` FIX (was Re: Demonstration code on how to trigger tcp6_sock leak) David S. Miller
2004-01-26 22:01   ` FIX YOSHIFUJI Hideaki / 吉藤英明
2004-01-27  2:57     ` FIX Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).