From: Eric Dumazet <dada1@cosmosbay.com>
To: Howard Chu <hyc@symas.com>
Cc: netdev@vger.kernel.org
Subject: Re: TCP 2MSL on loopback
Date: Tue, 6 Mar 2007 11:42:00 +0100 [thread overview]
Message-ID: <200703061142.00261.dada1@cosmosbay.com> (raw)
In-Reply-To: <45ED32CA.5080709@symas.com>
[-- Attachment #1: Type: text/plain, Size: 937 bytes --]
On Tuesday 06 March 2007 10:22, Howard Chu wrote:
>
> It's a combination of 2MSL and /proc/sys/net/ipv4/ip_local_port_range -
> on my system the default port range is 32768-61000. That means if I use
> up 28232 ports in less than 2MSL then everything stops. netstat will
> show that all the available port numbers are in TIME_WAIT state. And
> this is particularly bad because while waiting for the timeout, I can't
> initiate any new outbound connections of any kind at all - telnet, ssh,
> whatever, you have to wait for at least one port to free up.
> (Interesting denial of service there....)
>
> Granted, I was running my test on 2.6.18, perhaps 2.6.21 behaves
> differently.
Could you try this attached program and tell me whats happen ?
$ gcc -O2 -o socktest socktest.c -lpthread
$ time ./socktest -n 100000
nb_conn=99999 nb_accp=99999
real 0m5.058s
user 0m0.212s
sys 0m4.844s
(on my small machine, dell d610 :) )
[-- Attachment #2: socktest.c --]
[-- Type: text/plain, Size: 3408 bytes --]
/*
Copyright (C) 2007 Eric Dumazet
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <pthread.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/poll.h>
#include <sys/sendfile.h>
#include <sys/epoll.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include <ctype.h>
#include <netdb.h>
int fd __attribute__((aligned(64)));
int port = 9999;
unsigned long nb_acc __attribute__((aligned(64)));
unsigned long nb_conn1 __attribute__((aligned(64)));
unsigned long nb_conn2 __attribute__((aligned(64)));
unsigned long nb_conn3 __attribute__((aligned(64)));
int limit = 10000/3;
void *do_accept(void *arg)
{
int s;
struct sockaddr_in sa;
socklen_t addrlen ;
int flags;
char buffer[1024];
while (1) {
addrlen = sizeof(sa);
s = accept(fd, (struct sockaddr *)&sa, &addrlen);
if (s == -1) continue;
flags = 0;
recv(s, buffer, 1024, 0);
send(s, "Answer\r\n", 8, 0);
close(s);
nb_acc++;
}
}
void *do_conn(void *arg)
{
int i;
int on = 1;
struct sockaddr_in sa;
unsigned long *cpt = (unsigned long *)arg;
for (i = 0 ; i < limit ; i++) {
int s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
int res;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, 4);
memset(&sa, 0, sizeof(sa));
sa.sin_addr.s_addr = htonl(0x7f000001);
sa.sin_port = htons(port);
sa.sin_family = AF_INET;
res = connect(s, (struct sockaddr *)&sa, sizeof(sa));
if (res == 0) {
char buffer[1024];
send(s, "question\r\n", 10, 0);
recv(s, buffer, sizeof(buffer), 0);
(*cpt)++;
}
else {
static int errcnt = 0;
if (errcnt++ < 10) printf("connect error %d\n", errno);
}
close(s);
}
}
int main(int argc, char *argv[])
{
int on = 1;
struct sockaddr_in sa;
pthread_t tid, tid1, tid2, tid3;
int i;
void *res;
while ((i = getopt(argc, argv, "Vn:")) != EOF) {
if (i == 'n')
limit = atoi(optarg) / 3;
}
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, 4);
memset(&sa, 0, sizeof(sa));
sa.sin_port = htons(port);
sa.sin_family = AF_INET;
if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
perror("bind");
return 1;
}
listen(fd, 30000);
pthread_create(&tid, NULL, do_accept, NULL);
pthread_create(&tid1, NULL, do_conn, &nb_conn1);
pthread_create(&tid2, NULL, do_conn, &nb_conn2);
pthread_create(&tid3, NULL, do_conn, &nb_conn3);
pthread_join(tid1, &res);
pthread_join(tid2, &res);
pthread_join(tid3, &res);
printf("nb_conn=%lu nb_accp=%lu\n", nb_conn1 + nb_conn2 + nb_conn3, nb_acc);
return 0;
}
next prev parent reply other threads:[~2007-03-06 10:42 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-05 11:20 TCP 2MSL on loopback Howard Chu
2007-03-05 14:28 ` Eric Dumazet
2007-03-05 15:09 ` [PATCH] twcal_jiffie should be unsigned long, not int Eric Dumazet
2007-03-05 21:33 ` David Miller
2007-03-06 9:22 ` TCP 2MSL on loopback Howard Chu
2007-03-06 10:42 ` Eric Dumazet [this message]
2007-03-06 18:39 ` Howard Chu
2007-03-06 20:07 ` Eric Dumazet
2007-03-06 20:28 ` Howard Chu
2007-03-06 20:39 ` Eric Dumazet
2007-03-06 21:05 ` Howard Chu
2007-03-06 21:25 ` Rick Jones
2007-03-06 21:35 ` David Miller
2007-03-06 22:07 ` Howard Chu
2007-03-06 22:54 ` Stephen Hemminger
2007-03-06 23:22 ` Howard Chu
2007-03-06 18:04 ` David Miller
2007-03-06 18:46 ` Rick Jones
2007-03-06 19:25 ` Howard Chu
2007-03-06 20:41 ` Rick Jones
2007-03-07 3:36 ` Howard Chu
2007-03-05 20:59 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200703061142.00261.dada1@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=hyc@symas.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.