--- ucspi-tls-0.70-orig/src/sslserver.c 2006-10-16 13:42:10.000000000 +0200 +++ ucspi-tls-0.70/src/sslserver.c 2006-10-16 13:57:31.000000000 +0200 @@ -8,6 +8,7 @@ #include #include "ssl.h" #include "uint16.h" +#include "uint32.h" #include "str.h" #include "byte.h" #include "fmt.h" @@ -451,6 +452,7 @@ sslserver: usage: sslserver \ [ -13UXpPhHrRoOdDqQviIeEsSnN ] \ [ -c limit ] \ +[ -m perip limit ] \ [ -x rules.cdb ] \ [ -B banner ] \ [ -g gid ] \ @@ -465,8 +467,24 @@ } unsigned long limit = 40; +unsigned long periplimit = 0; unsigned long numchildren = 0; +typedef struct +{ + pid_t pid; + int offset; +} connections; + +typedef struct +{ + uint32 ipaddr; + unsigned long num; +} ipchildren; + +connections *children; +ipchildren *numipchildren; + int flag1 = 0; int flag3 = 0; unsigned long backlog = 20; @@ -487,6 +505,7 @@ void sigchld(void) { int wstat; int pid; + int i; while ((pid = wait_nohang(&wstat)) > 0) { if (verbosity >= 2) { @@ -495,6 +514,12 @@ strerr_warn4("sslserver: end ",strnum," status ",strnum2,0); } if (numchildren) --numchildren; printstatus(); + for (i=0;ifd = -1; - + + if (!periplimit) + periplimit = limit; + if (limit= limit) sig_pause(); sig_unblock(sig_child); @@ -699,9 +743,43 @@ sig_block(sig_child); if (t == -1) continue; + + for (i=0;iipaddr || !ipcount->num) + lastempty = i; + else if (ipcount->ipaddr == ipaddr) { + ++ipcount->num; + break; + } + } + if (i == limit) { + if (lastempty) { + i = lastempty; + ipcount = &numipchildren[i]; + ipcount->ipaddr = ipaddr; + ipcount->num = 1; + } else + /* never reached */ + strerr_die2x(111,DROP,"internal problem"); + } + if (ipcount->num > periplimit) { + remoteipstr[ip4_fmt(remoteipstr,remoteip)] = 0; + strerr_warn3(DROP, "per ip limit reached for ", remoteipstr, 0); + close(t); + --ipcount->num; + continue; + } ++numchildren; printstatus(); - switch(fork()) { + switch(pid = fork()) { case 0: close(s); doit(t); @@ -709,6 +787,10 @@ case -1: strerr_warn2(DROP,"unable to fork: ",&strerr_sys); --numchildren; printstatus(); + break; + default: + children[freechild].pid = pid; + children[freechild].offset = i; } close(t); }