🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
9 messages
9 total messages Started by Peter Jeremy Mon, 29 Jul 1996 00:00
Problems with Netscape 2.0x and INN1.4
#9722
Author: Peter Jeremy
Date: Mon, 29 Jul 1996 00:00
33 lines
2054 bytes
I have found my news logs getting filled with messages like
Jul 29 09:59:11 gsms01 nnrpd[13643]: ? cant getpeername Connection reset by peer
Jul 29 10:00:41 gsms01 innd: ME cant accept RCreader Protocol error
sometimes more than 100 log entries in 5 seconds.

Looking at what is going on, it seems that some versions of Netscape 2.0x
are opening excessive numbers of connections to the NNTP port, and closing
them almost immediately.

Has anyone else seen this behaviour?

I feel that forking an nnrpd solely so that it can report that it's input
channel was closed before it could even determine who was at the other end
is a waste of system resources - especially when this is being done about
as fast as the system can spawn nnrpd's.

Has anyone come up with a way of alleviating this problem?  Telling users
to upgrade to a `fixed' version of Netscape doesn't seem to work.  What I
would like is something that lets me restrict the number and rate of
incoming NNTP connect requests, without needing more system resources that
the current nnrpd takes to die.  Given the architecture of INN, this tends
to imply some sort of leaky bucket, indexed by IP address, in innd.

If anyone has any ideas (or better still, some solutions), please send me
some E-mail.
-- 
Peter Jeremy (VK2PJ)                    peter.jeremy@alcatel.com.au
Alcatel Australia Limited
41 Mandible St                          Phone: +61 2 690 5019
ALEXANDRIA  NSW  2015                   Fax:   +61 2 690 5247

Re: Problems with Netscape 2.0x and INN1.4
#9866
Author: John T. Stapleton
Date: Sun, 04 Aug 1996 00:00
747 lines
23817 bytes
In article <4tha01$hrd@gsms01.alcatel.com.au>,
Peter Jeremy <jeremyp@gsms01.alcatel.com.au> wrote:
>I have found my news logs getting filled with messages like
>Jul 29 09:59:11 gsms01 nnrpd[13643]: ? cant getpeername Connection reset by peer
>Jul 29 10:00:41 gsms01 innd: ME cant accept RCreader Protocol error
>sometimes more than 100 log entries in 5 seconds.
>
>Looking at what is going on, it seems that some versions of Netscape 2.0x
>are opening excessive numbers of connections to the NNTP port, and closing
>them almost immediately.
>
>Has anyone else seen this behaviour?

Yes, I've seen this behaviour.  It sometimes wipes out my server with
out-of-swap-space and I have 512MB of swap.  In the process, it took
my server's load average to over to 200.

>I feel that forking an nnrpd solely so that it can report that it's input
>channel was closed before it could even determine who was at the other end
>is a waste of system resources - especially when this is being done about
>as fast as the system can spawn nnrpd's.

It's worse when the other end is most likely a PC and doesn't close
the connection, but never sends a command.  Then you wind up with
nnrpd's sitting around doing nothing except comsuming memory, swap,
and a process slot until they timeout.

>Has anyone come up with a way of alleviating this problem?  Telling users
>to upgrade to a `fixed' version of Netscape doesn't seem to work.  What I
>would like is something that lets me restrict the number and rate of
>incoming NNTP connect requests, without needing more system resources that
>the current nnrpd takes to die.  Given the architecture of INN, this tends
>to imply some sort of leaky bucket, indexed by IP address, in innd.
>
>If anyone has any ideas (or better still, some solutions), please send me
>some E-mail.

I came up with a solution, namely a patch, which has also been sent to
ISC to be included in the next test release of INN 1.5.  Here are the
patches retrofitted to INN 1.4sec.  My original patches to 1.4sec were
a bit more awkward.  I rewrote them for 1.5, then I retrofitted them
to 1.4.

The rest of this article is the README file and the patches.

Stapes

----Beginning of README
	 Limiting the number of incoming connects per minute
		    on a total or per host basis.

There are three new option flags for limiting the number of incoming
connects per minute.

This code was developed as a fix to protect innd from news reader
client programs that make too many connects.  In particular, Netscape
V2.0 and up can cause major problems for innd if you are running
streaming.  While your server is receiving news from a feed, it does
not respond fast enough to connects from Netscape.  If the person
using Netscape is rapidly clicking ``Next'', then your server can fall
behind with disastrous results.  I've seen my server go from a load
average between 5.00 and 10.00 to over 200.00 in under 90 seconds.

The problem is that Netscape will abandon a connect and initiate
another connect before your server can respond.  It will keep doing
this if the user keeps clicking ``Next'' rapidly.  Meanwhile, your
server will keep forking nnrpd's thereby overloading your server.

If you are not having a problem, you should probably not bother to
enable this option.  Also, some systems are better able to cope with
this problem than others.  My ULTRIX news server needs this option,
but Digital UNIX seems to deal with it fine if you have the nnrpd
initial timeout patch which is also included.  That patch sets the
timeout for the first read to a small number of seconds, then reverts
to the standard timeout.

The table used for these checks is fixed at 128 entries and is used as
a ring.  The size was chosen to make calculating the index easy and to
be pretty sure you won't run out of space.  In practice, it is
doubtful that you will use even half the table at any given moment.

The ``-H'' flag limits the number of times a host is allowed to
connect to the server per ``-X'' seconds.  The default is 2.

The ``-T'' flag limits the total number of incoming connects to innd
per ``-X'' seconds.  The maximum value is 128.  The default is 60.

The ``-X'' sets the number of seconds used by the ``-H'' and ``-T''
flags.  A value of zero turns off checking.  The default is 0.  If you
are having a problem with too many connects, I suggest you start this
option at 60 and see how it goes.
----End of README

Here are the diffs:
-------------------
*** doc/innd.8.dist	Thu Mar 18 16:03:40 EST 1993
--- doc/innd.8	Sun Aug  4 12:26:06 EDT 1996
***************
*** 52,57 ****
--- 52,66 ----
  [
  .B \-x
  ]
+ [
+ .BI \-H " count"
+ ]
+ [
+ .BI \-T " count"
+ ]
+ [
+ .BI \-X " seconds"
+ ]
  
  .B inndstart
  [
***************
*** 213,218 ****
--- 222,247 ----
  .PP
  If the ``\-x'' flag is used, then an Xref header will be added to all
  articles even if they are not cross-posted.
+ .PP
+ .PP
+ The ``\-H'', ``\-T'', and ``\-X'' flags control the number of connects per
+ minute allowed.
+ This code is meant to protect your server from newsreader clients that
+ make too many connects per minute to your server.  You should probably
+ not use it unless you are having a problem.
+ The table used for these checks is fixed at 128 entries and is used as
+ a ring.  The size was chosen to make calculating the index easy and to
+ be pretty sure you won't run out of space.  In practice, it is
+ doubtful that you will use even half the table at any given moment.
+ .PP
+ The ``\-H'' flag limits the number of times a host is allowed to connect
+ to the server per ``\-X'' seconds.  The default is 2.
+ .PP
+ The ``\-T'' flag limits the total number of incoming connects to innd
+ per ``\-X'' seconds.  The maximum value is 128.  The default is 60.
+ .PP
+ The ``\-X'' sets the number of seconds used by the ``\-H'' and ``-T''
+ flags.  A value of zero turns off checking.  The default is 0.
  .PP
  .I Inndstart
  is a small front-end program that opens the NNTP port, sets its
*** include/nntp.h.dist	Thu Mar 18 16:04:14 EST 1993
--- include/nntp.h	Sun Aug  4 13:04:23 EDT 1996
***************
*** 82,87 ****
--- 82,91 ----
  #define NNTP_NOPREV_VAL			422
  #define NNTP_CANTPOST			"440 Posting not allowed"
  #define NNTP_CANTPOST_VAL		440
+ #define NNTP_SERVER_TOOBUSY		"504 Server overloaded, try later"
+ #define NNTP_SERVER_TOOBUSY_VAL		504
+ #define NNTP_TOO_MANY_CONNECTS		"505 Connection rejected, you're making too many connects per minute"
+ #define NNTP_TOO_MANY_CONNECTS_VAL	505
  
  
  /*
*** innd/cc.c.dist	Thu Mar 18 16:04:22 EST 1993
--- innd/cc.c	Sun Aug  4 13:16:05 EDT 1996
***************
*** 566,571 ****
--- 566,572 ----
  	    case CTprocess:
  	    case CTfile:
  	    case CTnntp:
+ 	    case CTreject:
  		syslog(L_NOTICE, "%s hangup", p);
  		CHANclose(cp, p);
  		return NULL;
***************
*** 621,630 ****
      for (i = 0, h = 0; CHANiter(&h, CTnntp) != NULL; )
  	i++;
      *p++ = '\n';
!     (void)sprintf(p, "Parameters c %ld i %d (%d) l %ld o %d t %ld %s %s",
  	    (long)Cutoff / (24L * 60L * 60L),
  	    MaxIncoming, i,
  	    LargestArticle, MaxOutgoing, (long)TimeOut.tv_sec,
  	    AmSlave ? "slave" : "normal",
  	    AnyIncoming ? "any" : "specified");
      p += strlen(p);
--- 622,632 ----
      for (i = 0, h = 0; CHANiter(&h, CTnntp) != NULL; )
  	i++;
      *p++ = '\n';
!     (void)sprintf(p, "Parameters c %ld i %d (%d) l %ld o %d t %ld H %d T %d X %d %s %s",
  	    (long)Cutoff / (24L * 60L * 60L),
  	    MaxIncoming, i,
  	    LargestArticle, MaxOutgoing, (long)TimeOut.tv_sec,
+ 	    RemoteLimit, RemoteTotal, (int) RemoteTimer,
  	    AmSlave ? "slave" : "normal",
  	    AnyIncoming ? "any" : "specified");
      p += strlen(p);
***************
*** 839,844 ****
--- 841,861 ----
      case 't':
  	TimeOut.tv_sec = atol(p);
  	syslog(L_NOTICE, "%s changed -t %ld", LogName, (long)TimeOut.tv_sec);
+ 	break;
+     }
+     case 'H':
+ 	RemoteLimit = atoi(p);
+ 	syslog(L_NOTICE, "%s changed -H %d", LogName, RemoteLimit);
+ 	break;
+     case 'T':
+ 	RemoteTotal = atoi(p);
+ 	if (RemoteTotal > REMOTETABLESIZE)
+ 	    RemoteTotal = REMOTETABLESIZE;
+ 	syslog(L_NOTICE, "%s changed -T %d", LogName, RemoteTotal);
+ 	break;
+     case 'X':
+ 	RemoteTimer = (time_t) atoi(p);
+ 	syslog(L_NOTICE, "%s changed -X %d", LogName, (int) RemoteTimer);
  	break;
      }
      return NULL;
*** innd/chan.c.dist	Thu Mar 18 16:04:23 EST 1993
--- innd/chan.c	Sun Aug  4 13:23:39 EDT 1996
***************
*** 184,189 ****
--- 184,191 ----
  		"%s closed seconds %ld accepted %ld refused %ld rejected %ld",
  		name, (long)(Now.time - cp->Started),
  		cp->Received, cp->Refused, cp->Rejected);
+ 	else if (cp->Type == CTreject)
+ 	    syslog(L_NOTICE, "%s %ld", name, cp->Rejected);
  	else
  	    syslog(L_NOTICE, "%s closed", name);
  	WCHANremove(cp);
***************
*** 240,245 ****
--- 242,250 ----
      case CTremconn:
  	(void)sprintf(buff, "remconn:%d", cp->fd);
  	break;
+     case CTreject:
+ 	(void)sprintf(buff, "%s rejected", RChostname(cp));
+ 	break;
      case CTnntp:
  	(void)sprintf(buff, "%s:%d",
  		cp->Address.s_addr == 0 ? "localhost" : RChostname(cp),
***************
*** 616,621 ****
--- 621,627 ----
  	switch (cp->Type) {
  	default:
  	    break;
+ 	case CTreject:
  	case CTnntp:
  	case CTfile:
  	case CTexploder:
***************
*** 823,828 ****
--- 829,842 ----
  		cp->LastActive = Now.time;
  		SCHANremove(cp);
  		(*cp->Waker)(cp);
+ 	    }
+ 
+ 	    /* Toss CTreject channel early if it's inactive. */
+ 	    if (cp->Type == CTreject
+ 	     && cp->LastActive + REJECT_TIMEOUT < Now.time) {
+ 		p = CHANname(cp);
+ 		syslog(L_NOTICE, "%s timeout reject", p);
+ 		CHANclose(cp, p);
  	    }
  
  	    /* Has this channel been inactive very long? */
*** innd/innd.c.dist	Thu Mar 18 16:04:25 EST 1993
--- innd/innd.c	Sun Aug  4 13:32:03 EDT 1996
***************
*** 37,42 ****
--- 37,45 ----
  long		LargestArticle = MAX_ART_SIZE;
  OPERATINGMODE	Mode = OMrunning;
  time_t		Cutoff = DEFAULT_CUTOFF * 24 * 60 * 60;
+ int		RemoteLimit = REMOTELIMIT;
+ time_t		RemoteTimer = REMOTETIMER;
+ int		RemoteTotal = REMOTETOTAL;
  
  #if	defined(__CENTERLINE__)
  BOOL		Debug = TRUE;
***************
*** 616,622 ****
  
      /* Parse JCL. */
      CCcopyargv(av);
!     while ((i = getopt(ac, av, "ac:dfi:l:m:o:n:p:rsS:t:ux")) != EOF)
  	switch (i) {
  	default:
  	    Usage();
--- 619,625 ----
  
      /* Parse JCL. */
      CCcopyargv(av);
!     while ((i = getopt(ac, av, "ac:dfH:i:l:m:o:n:p:rsS:t:T:uxX:")) != EOF)
  	switch (i) {
  	default:
  	    Usage();
***************
*** 636,641 ****
--- 639,647 ----
  	case 'f':
  	    ShouldFork = FALSE;
  	    break;
+ 	case 'H':
+ 	    RemoteLimit = atoi(optarg);
+ 	    break;
  	case 'i':
  	    MaxIncoming = atoi(optarg);
  	    break;
***************
*** 691,701 ****
--- 697,713 ----
  	case 't':
  	    TimeOut.tv_sec = atol(optarg);
  	    break;
+ 	case 'T':
+ 	    RemoteTotal = atoi(optarg);
+ 	    break;
  	case 'u':
  	    BufferedLogs = FALSE;
  	    break;
  	case 'x':
  	    AlwaysCrosspost = TRUE;
+ 	    break;
+ 	case 'X':
+ 	    RemoteTimer = atoi(optarg);
  	    break;
  	}
      ac -= optind;
*** innd/innd.h.dist	Thu Mar 18 16:04:26 EST 1993
--- innd/innd.h	Sun Aug  4 13:36:37 EDT 1996
***************
*** 91,96 ****
--- 91,97 ----
      CTany,
      CTfree,
      CTremconn,
+     CTreject,
      CTnntp,
      CTlocalconn,
      CTcontrol,
***************
*** 400,405 ****
--- 401,424 ----
  EXTERN struct timeval	TimeOut;
  EXTERN TIMEINFO		Now;		/* Reasonably accurate time	*/
  extern time_t		Cutoff;
+ 
+ /*
+ ** Table size for limiting incoming connects.  Do not change the table
+ ** size unless you look at the code manipulating it in rc.c.
+ */
+ #define REMOTETABLESIZE 128
+ 
+ /*
+ ** Setup the default values.  The REMOTETIMER being zero turns off the
+ ** code to limit incoming connects.
+ */
+ #define REMOTELIMIT	2
+ #define REMOTETIMER	0
+ #define REMOTETOTAL	60
+ #define REJECT_TIMEOUT	10
+ extern int		RemoteLimit; /* Per host limit. */
+ extern time_t		RemoteTimer; /* How long to remember connects. */
+ extern int		RemoteTotal; /* Total limit. */
  
  
  /*
*** innd/rc.c.dist	Thu Mar 18 16:04:31 EST 1993
--- innd/rc.c	Sun Aug  4 13:44:59 EDT 1996
***************
*** 30,35 ****
--- 30,40 ----
      char	**Patterns;
  } REMOTEHOST;
  
+ typedef struct _REMOTETABLE {
+     INADDR	Address;
+     time_t	Expires;
+ } REMOTETABLE;
+ 
  STATIC INADDR		*RCmaster;
  STATIC int		RCnmaster;
  STATIC char		*RCslaveflag;
***************
*** 42,48 ****
--- 47,61 ----
  STATIC REMOTEHOST	*RCnolimitlist;
  STATIC int		RCnnolimitlist;
  
+ /*
+ ** Stuff needed for limiting incoming connects.
+ */
+ STATIC char		RCterm[] = "\r\n";
+ STATIC REMOTETABLE	remotetable[REMOTETABLESIZE];
+ STATIC int		remotecount;
+ STATIC int		remotefirst;
  
+ 
  /*
  **  See if the site properly entered the password.
  */
***************
*** 110,115 ****
--- 123,159 ----
  
  
  /*
+ **  Called when input is ready to read.  Shouldn't happen.
+ */
+ /* ARGSUSED0 */
+ STATIC FUNCTYPE
+ RCrejectreader(cp)
+     CHANNEL	*cp;
+ {
+     syslog(L_ERROR, "%s internal RCrejectreader", LogName);
+ }
+ 
+ 
+ /*
+ **  Write-done function for rejects.
+ */
+ STATIC FUNCTYPE
+ RCrejectwritedone(cp)
+     register CHANNEL	*cp;
+ {
+     switch (cp->State) {
+     default:
+ 	syslog(L_ERROR, "%s internal RCrejectwritedone state %d",
+ 	    CHANname(cp), cp->State);
+ 	break;
+     case CSwritegoodbye:
+ 	CHANclose(cp, CHANname(cp));
+ 	break;
+     }
+ }
+ 
+ 
+ /*
  **  Hand off a descriptor to NNRPD.
  */
  void
***************
*** 164,169 ****
--- 208,218 ----
      register REMOTEHOST	*rp;
      CHANNEL		*new;
      char		*name;
+     long		reject_val;
+     char		*reject_message;
+     int			count;
+     int			found;
+     time_t		now;
  
      if (cp != RCchan) {
  	syslog(L_ERROR, "%s internal RCreader wrong channel 0x%x not 0x%x",
***************
*** 175,180 ****
--- 224,317 ----
      size = sizeof remote;
      if ((fd = accept(cp->fd, (struct sockaddr *)&remote, &size)) < 0) {
  	syslog(L_ERROR, "%s cant accept RCreader %m", LogName);
+ 	return;
+     }
+ 
+     /*
+     ** If RemoteTimer is not zero, then check the limits on incoming
+     ** connections on a total and per host basis.
+     **
+     ** The incoming connection table is fixed at 128 entries to make
+     ** calculating the index easy (i + 1) & 7, and to be pretty sure
+     ** that you won't run out of space.  The table is used as a ring
+     ** with new entries being added to the end (wrapping around) and
+     ** expired entries being deleted from the front (again wrapping
+     ** around).  It is doubtful that you will ever use even half of
+     ** the table.
+     **
+     ** There are three parameters controlling the use of the table not
+     ** counting the starting index and count.
+     **
+     ** L = per host incoming connects per X seconds allowed
+     ** T = total incoming connects per X seconds allowed
+     ** X = number of seconds to remember a successful connect
+     **
+     ** First, one pass is made over the live entries deleting any that
+     ** are over X seconds old.  If the entry hasn't expired, compare
+     ** the incoming connection's host address with the entry's host
+     ** address.  If equal, increment the ``found'' counter.
+     **
+     ** Second, if the number of entries now in the table is equal to
+     ** the ``T'' parameter, reject the connection with the ``504''
+     ** error code.
+     **
+     ** 504 Server overloaded, try later
+     **
+     ** Third, if the number of entries now in the table which match
+     ** the incoming connection's host address is equal to the ``L''
+     ** parameter, reject the connection with the ``505'' error code.
+     **
+     ** 505 Connection rejected, you're making too many connects per minute
+     **
+     ** Finally, if neither rejection happened, add the entry to the
+     ** table, and continue on as a normal connect.
+     */
+     reject_message = NULL;
+     if (RemoteTimer != 0) {
+ 	now = time(NULL);
+ 	i = remotefirst;
+ 	count = remotecount;
+ 	found = 0;
+ 	while (count--) {
+ 	    if (remotetable[i].Expires < now) {
+ 		remotecount--;
+ 		remotefirst = (remotefirst + 1) & (REMOTETABLESIZE - 1);
+ 		i = (i + 1) & (REMOTETABLESIZE - 1);
+ 		continue;
+ 	    }
+ 	    if (remotetable[i].Address.s_addr == remote.sin_addr.s_addr)
+ 		found++;
+ 	    i = (i + 1) & (REMOTETABLESIZE - 1);
+ 	}
+ 	if (remotecount == RemoteTotal) {
+ 	    reject_val = NNTP_SERVER_TOOBUSY_VAL;
+ 	    reject_message = NNTP_SERVER_TOOBUSY;
+ 	}
+ 	else if (found >= RemoteLimit) {
+ 	    reject_val = NNTP_TOO_MANY_CONNECTS_VAL;
+ 	    reject_message = NNTP_TOO_MANY_CONNECTS;
+ 	}
+ 	else {
+ 	    i = (remotefirst + remotecount) & (REMOTETABLESIZE - 1);
+ 	    remotetable[i].Address = remote.sin_addr;
+ 	    remotetable[i].Expires = now + RemoteTimer;
+ 	    remotecount++;
+ 	}
+     }
+ 
+     /*
+     ** Create a reject channel to reject the connection.  This is done
+     ** to avoid a call to fork.  
+     */
+     if (reject_message) {
+ 	new = CHANcreate(fd, CTreject, CSwritegoodbye, RCrejectreader,
+ 	    RCrejectwritedone);
+ 	new->Address.s_addr = remote.sin_addr.s_addr;
+ 	new->Rejected = reject_val;
+ 	RCHANremove(new);
+ 	WCHANset(new, reject_message, (int)strlen(reject_message));
+ 	WCHANappend(new, RCterm, STRLEN(RCterm));
+ 	WCHANadd(new);
  	return;
      }
  
*** nnrpd/nnrpd.c.dist	Thu Mar 18 16:04:44 EST 1993
--- nnrpd/nnrpd.c	Sat Aug  3 23:54:42 EDT 1996
***************
*** 14,19 ****
--- 14,32 ----
  #endif	/* defined(HPUX) */
  
  
+ /*
+ ** Here is some defensive code to protect the news server from hosts,
+ ** mostly PC's, that sometimes make a connection and then never give
+ ** any commands.  The connection is abandoned, but we're never told
+ ** about it.  The first time the connection is read, it will have a
+ ** timeout value of INITIAL_TIMEOUT seconds.  All subsequent reads
+ ** will have the standard timeout of CLIENT_TIMEOUT seconds.
+ */
+ #if !defined(INITIAL_TIMEOUT)
+ #define INITIAL_TIMEOUT	10
+ #endif
+ 
+ 
  #define CMDany		-1
  
  
***************
*** 504,509 ****
--- 517,523 ----
      register int	i;
      char		*Reject;
      char		accesslist[BIG_BUFFER];
+     int			timeout;
  
  #if	!defined(HPUX)
      /* Save start and extent of argv for TITLEset. */
***************
*** 598,604 ****
  	   PERMcanpost ? "posting ok" : "no posting");
  
      /* Main dispatch loop. */
!     for (av = NULL; ; ) {
  	(void)fflush(stdout);
  	if (ChangeTrace) {
  	    Tracing = Tracing ? FALSE : TRUE;
--- 612,618 ----
  	   PERMcanpost ? "posting ok" : "no posting");
  
      /* Main dispatch loop. */
!     for (timeout = INITIAL_TIMEOUT, av = NULL; ; timeout = CLIENT_TIMEOUT) {
  	(void)fflush(stdout);
  	if (ChangeTrace) {
  	    Tracing = Tracing ? FALSE : TRUE;
***************
*** 605,618 ****
  	    syslog(L_TRACE, "trace %sabled", Tracing ? "en" : "dis");
  	    ChangeTrace = FALSE;
  	}
! 	switch (r = READline(buff, (int)sizeof buff, CLIENT_TIMEOUT)) {
  	default:
  	    syslog(L_ERROR, "%s internal %d in main", ClientHost, r);
  	    /* FALLTHROUGH */
  	case RTtimeout:
! 	    syslog(L_NOTICE, "%s timeout", ClientHost);
  	    Printf("%d Timeout after %d seconds, closing connection.\r\n",
! 		   NNTP_TEMPERR_VAL, CLIENT_TIMEOUT);
  	    ExitWithStats(1);
  	    break;
  	case RTlong:
--- 619,635 ----
  	    syslog(L_TRACE, "trace %sabled", Tracing ? "en" : "dis");
  	    ChangeTrace = FALSE;
  	}
! 	switch (r = READline(buff, (int)sizeof buff, timeout)) {
  	default:
  	    syslog(L_ERROR, "%s internal %d in main", ClientHost, r);
  	    /* FALLTHROUGH */
  	case RTtimeout:
! 	    if (timeout < CLIENT_TIMEOUT)
! 		syslog(L_NOTICE, "%s timeout short", ClientHost);
! 	    else
! 		syslog(L_NOTICE, "%s timeout", ClientHost);
  	    Printf("%d Timeout after %d seconds, closing connection.\r\n",
! 		   NNTP_TEMPERR_VAL, timeout);
  	    ExitWithStats(1);
  	    break;
  	case RTlong:
*** samples/innlog.awk.dist	Fri Jan 29 11:52:13 EST 1993
--- samples/innlog.awk	Sun Aug  4 00:10:48 EDT 1996
***************
*** 143,148 ****
--- 143,155 ----
  	next;
      }
  
+     # Catch the nnrpd's which timed out on the first read
+     if ($7 == "timeout" && $8 == "short") {
+ 	client_short = 1;
+ 	nnrp_short[host]++;
+ 	next;
+     }
+ 
      if ($7 == "timeout") {
  	client_timeout = 1;
  	nnrp_timeout[host]++;
***************
*** 242,247 ****
--- 249,271 ----
  	next;
      }
  
+     # Connections rejected because of the limiting incoming connect
+     # code can cause two different rejected messages:
+     #
+     # ... innd: HOSTADDR rejected cant write Broken pipe"
+     # ... innd: HOSTADDR rejected 505"
+     #
+     # They both mean the same thing.  The Broken pipe happens when
+     # the other end of the connection goes away first.
+     if ($7 == "rejected") {
+ 	if ($8 == "505" ||
+ 	    ($10 == "Broken" && $11 == "pipe")) {
+ 	    innd_505s[host]++;
+ 	    innd_505_flag = 1;
+ 	}
+ 	next;
+     }
+ 
      if ($7 == "flush") {
  	innd_flush[host]++;
  	next;
***************
*** 1337,1343 ****
--- 1361,1384 ----
  	}
  	printf("\n");
      }
+     if (innd_505_flag) {
+ 	printf("Hosts making too many connects per minute\n");
+ 	printf(" Conn System\n");
+ 	for ( ; ; ) {
+ 	    s = invalid;
+ 	    for (sortindex in innd_505s)
+ 		if (innd_505s[sortindex] >= 0 && sortindex < s)
+ 		    s = sortindex;
+ 	    if (s == invalid)
+ 		break;
  
+ 	    printf("%5d %s\n", innd_505s[s], s);
+ 
+ 	    innd_505s[s] = -1;
+ 	}
+ 	printf("\n");
+     }
+ 
      ##  NNRP statistics.
      if (nnrp) {
  	printf("NNRP readership statistics\n");
***************
*** 1490,1495 ****
--- 1531,1557 ----
  
  	    nnrp_timeout[s] = -1;
          }
+ 	printf("\n");
+     }
+     # Change the ``0'' to ``client_short'' if you want to see the report
+     if (0) {
+ 	printf("NNRP clients which timed out on the first read:\n");
+ 	printf(" Conn System\n");
+ 	sum = 0;
+ 	for ( ; ; ) {
+ 	    s = invalid;
+ 	    for (sortindex in nnrp_short)
+ 		if (nnrp_short[sortindex] >= 0 && sortindex < s)
+ 		    s = sortindex;
+             if (s == invalid)
+ 		break;
+ 
+ 	    printf("%5d %s\n", nnrp_short[s], s);
+ 	    sum += nnrp_short[s];
+ 
+ 	    nnrp_short[s] = -1;
+         }
+ 	printf("%5d TOTAL\n", sum);
  	printf("\n");
      }
      if (server_timeout) {

Re: Problems with Netscape 2.0x and INN1.4
#9884
Author: Andrew A. Vasilyev
Date: Mon, 05 Aug 1996 00:00
40 lines
1817 bytes
John T. Stapleton (stapes@mro.dec.com) wrote:
> I came up with a solution, namely a patch, which has also been sent to
> ISC to be included in the next test release of INN 1.5.  Here are the
> patches retrofitted to INN 1.4sec.  My original patches to 1.4sec were
> a bit more awkward.  I rewrote them for 1.5, then I retrofitted them
> to 1.4.

   Great job! But what about adding a check
     (rc.c near 291 line in your count):

> +     else if (found >= RemoteLimit && !RCnolimit(cp)) {
				      ^^^^^^^^^^^^^^^^^
   So your local mail2news server could connects as it used to do -
   5 times per second :))) Or sites feeding you in STREAM mode.

   And there is an (IMHO) extra bracket in your patch:

> *** innd/cc.c.dist	Thu Mar 18 16:04:22 EST 1993
> --- innd/cc.c	Sun Aug  4 13:16:05 EDT 1996
> ***************
> *** 839,844 ****
> --- 841,861 ----
>       case 't':
>   	TimeOut.tv_sec = atol(p);
>   	syslog(L_NOTICE, "%s changed -t %ld", LogName, (long)TimeOut.tv_sec);
> + 	break;
> +     }
^^^^^^^^^
  This one has no '{' :((

> +     case 'H':
...
> + 	syslog(L_NOTICE, "%s changed -X %d", LogName, (int) RemoteTimer);
>   	break;
>       }
________
	ANDY

Re: Problems with Netscape 2.0x and INN1.4
#9889
Author: Doug McClure
Date: Mon, 05 Aug 1996 00:00
18 lines
1193 bytes
<snip>

Almost all of our subscribers browse with Netscape 2.02. and the
RCreader does not appear - CCreader shows up instead. Is that a typo, or
is it interacting differently with your server? My peername errors are
also different, just as ubiquitous, but it's all Connection reset by
peer with a few Can't get peername. Because there's no overload or swap
problems with only 

total: 26.54m allocated + 77.76m add'l reserved = 104.29m bytes used,
96.09m bytes available

swap.

Doug

Re: Problems with Netscape 2.0x and INN1.4
#9925
Author: Andrew A. Vasilyev
Date: Tue, 06 Aug 1996 00:00
22 lines
1252 bytes
Andrew A. Vasilyev (andy@snm.demos.su) wrote:
>    Great job! But what about adding a check
>      (rc.c near 291 line in your count):
> > +     else if (found >= RemoteLimit && !RCnolimit(cp)) {
> 				      ^^^^^^^^^^^^^^^^^

  O-ops! Correcting myself :(((
  One should use additional variable for that check 'cause the
  cp->Address may be undefined. Something like:

    CHANNEL cp1;

    cp1.Address.s_addr = remote.sin_addr.s_addr; /* After accept() */
    ...
    else if (found >= RemoteLimit && !RCnolimit(&cp1)) {

  If one could suggest a better solution I would be happy.
_______
	ANDY

Re: Problems with Netscape 2.0x and INN1.4
#9932
Author: John T. Stapleton
Date: Tue, 06 Aug 1996 00:00
732 lines
22761 bytes
In article <4u5gpa$kkv@news.demos.su>,
Andrew A. Vasilyev <andy@snm.demos.su> wrote:
>John T. Stapleton (stapes@mro.dec.com) wrote:
>> [deleted]
>
>   Great job! But what about adding a check
>     (rc.c near 291 line in your count):
>
>> +     else if (found >= RemoteLimit && !RCnolimit(cp)) {
>				      ^^^^^^^^^^^^^^^^^

Done.  The attached patches contain the change.

>   So your local mail2news server could connects as it used to do -
>   5 times per second :))) Or sites feeding you in STREAM mode.

I don't know about mail2news, but a STREAM mode feed should not be
connecting 5 times per second.  Sending 5 articles per second, yes,
but not connecting 5 times per second.  This patch limits the number
of connects per X seconds.

>   And there is an (IMHO) extra bracket in your patch:
>
>> [deleted]

Yes, you are right.  A bit of clumsiness on my part.  The attached
patch is fixed.

The rest of this article is the README file and the patches (2nd version)
The first version of the patches were not identified as being any version.

Stapes

----Beginning of README
	 Limiting the number of incoming connects per minute
		    on a total or per host basis.

There are three new option flags for limiting the number of incoming
connects per minute.

This code was developed as a fix to protect innd from news reader
client programs that make too many connects.  In particular, Netscape
V2.0 and up can cause major problems for innd if you are running
streaming.  While your server is receiving news from a feed, it does
not respond fast enough to connects from Netscape.  If the person
using Netscape is rapidly clicking ``Next'', then your server can fall
behind with disastrous results.  I've seen my server go from a load
average between 5.00 and 10.00 to over 200.00 in under 90 seconds.

The problem is that Netscape will abandon a connect and initiate
another connect before your server can respond.  It will keep doing
this if the user keeps clicking ``Next'' rapidly.  Meanwhile, your
server will keep forking nnrpd's thereby overloading your server.

If you are not having a problem, you should probably not bother to
enable this option.  Also, some systems are better able to cope with
this problem than others.  My ULTRIX news server needs this option,
but Digital UNIX seems to deal with it fine if you have the nnrpd
initial timeout patch which is also included.  That patch sets the
timeout for the first read to a small number of seconds, then reverts
to the standard timeout.

The table used for these checks is fixed at 128 entries and is used as
a ring.  The size was chosen to make calculating the index easy and to
be pretty sure you won't run out of space.  In practice, it is
doubtful that you will use even half the table at any given moment.

The ``-H'' flag limits the number of times a host is allowed to
connect to the server per ``-X'' seconds.  The default is 2.

The ``-T'' flag limits the total number of incoming connects to innd
per ``-X'' seconds.  The maximum value is 128.  The default is 60.

The ``-X'' sets the number of seconds used by the ``-H'' and ``-T''
flags.  A value of zero turns off checking.  The default is 0.  If you
are having a problem with too many connects, I suggest you start this
option at 60 and see how it goes.
----End of README

Here are the diffs:
-------------------
*** doc/innd.8.dist	Thu Mar 18 16:03:40 EST 1993
--- doc/innd.8	Sun Aug  4 12:26:06 EDT 1996
***************
*** 52,57 ****
--- 52,66 ----
  [
  .B \-x
  ]
+ [
+ .BI \-H " count"
+ ]
+ [
+ .BI \-T " count"
+ ]
+ [
+ .BI \-X " seconds"
+ ]
  
  .B inndstart
  [
***************
*** 213,218 ****
--- 222,247 ----
  .PP
  If the ``\-x'' flag is used, then an Xref header will be added to all
  articles even if they are not cross-posted.
+ .PP
+ .PP
+ The ``\-H'', ``\-T'', and ``\-X'' flags control the number of connects per
+ minute allowed.
+ This code is meant to protect your server from newsreader clients that
+ make too many connects per minute to your server.  You should probably
+ not use it unless you are having a problem.
+ The table used for these checks is fixed at 128 entries and is used as
+ a ring.  The size was chosen to make calculating the index easy and to
+ be pretty sure you won't run out of space.  In practice, it is
+ doubtful that you will use even half the table at any given moment.
+ .PP
+ The ``\-H'' flag limits the number of times a host is allowed to connect
+ to the server per ``\-X'' seconds.  The default is 2.
+ .PP
+ The ``\-T'' flag limits the total number of incoming connects to innd
+ per ``\-X'' seconds.  The maximum value is 128.  The default is 60.
+ .PP
+ The ``\-X'' sets the number of seconds used by the ``\-H'' and ``-T''
+ flags.  A value of zero turns off checking.  The default is 0.
  .PP
  .I Inndstart
  is a small front-end program that opens the NNTP port, sets its
*** include/nntp.h.dist	Thu Mar 18 16:04:14 EST 1993
--- include/nntp.h	Sun Aug  4 13:04:23 EDT 1996
***************
*** 82,87 ****
--- 82,91 ----
  #define NNTP_NOPREV_VAL			422
  #define NNTP_CANTPOST			"440 Posting not allowed"
  #define NNTP_CANTPOST_VAL		440
+ #define NNTP_SERVER_TOOBUSY		"504 Server overloaded, try later"
+ #define NNTP_SERVER_TOOBUSY_VAL		504
+ #define NNTP_TOO_MANY_CONNECTS		"505 Connection rejected, you're making too many connects per minute"
+ #define NNTP_TOO_MANY_CONNECTS_VAL	505
  
  
  /*
*** innd/cc.c.dist	Thu Mar 18 16:04:22 EST 1993
--- innd/cc.c	Mon Aug  5 19:53:41 EDT 1996
***************
*** 566,571 ****
--- 566,572 ----
  	    case CTprocess:
  	    case CTfile:
  	    case CTnntp:
+ 	    case CTreject:
  		syslog(L_NOTICE, "%s hangup", p);
  		CHANclose(cp, p);
  		return NULL;
***************
*** 621,630 ****
      for (i = 0, h = 0; CHANiter(&h, CTnntp) != NULL; )
  	i++;
      *p++ = '\n';
!     (void)sprintf(p, "Parameters c %ld i %d (%d) l %ld o %d t %ld %s %s",
  	    (long)Cutoff / (24L * 60L * 60L),
  	    MaxIncoming, i,
  	    LargestArticle, MaxOutgoing, (long)TimeOut.tv_sec,
  	    AmSlave ? "slave" : "normal",
  	    AnyIncoming ? "any" : "specified");
      p += strlen(p);
--- 622,632 ----
      for (i = 0, h = 0; CHANiter(&h, CTnntp) != NULL; )
  	i++;
      *p++ = '\n';
!     (void)sprintf(p, "Parameters c %ld i %d (%d) l %ld o %d t %ld H %d T %d X %d %s %s",
  	    (long)Cutoff / (24L * 60L * 60L),
  	    MaxIncoming, i,
  	    LargestArticle, MaxOutgoing, (long)TimeOut.tv_sec,
+ 	    RemoteLimit, RemoteTotal, (int) RemoteTimer,
  	    AmSlave ? "slave" : "normal",
  	    AnyIncoming ? "any" : "specified");
      p += strlen(p);
***************
*** 839,844 ****
--- 841,860 ----
      case 't':
  	TimeOut.tv_sec = atol(p);
  	syslog(L_NOTICE, "%s changed -t %ld", LogName, (long)TimeOut.tv_sec);
+ 	break;
+     case 'H':
+ 	RemoteLimit = atoi(p);
+ 	syslog(L_NOTICE, "%s changed -H %d", LogName, RemoteLimit);
+ 	break;
+     case 'T':
+ 	RemoteTotal = atoi(p);
+ 	if (RemoteTotal > REMOTETABLESIZE)
+ 	    RemoteTotal = REMOTETABLESIZE;
+ 	syslog(L_NOTICE, "%s changed -T %d", LogName, RemoteTotal);
+ 	break;
+     case 'X':
+ 	RemoteTimer = (time_t) atoi(p);
+ 	syslog(L_NOTICE, "%s changed -X %d", LogName, (int) RemoteTimer);
  	break;
      }
      return NULL;
*** innd/chan.c.dist	Thu Mar 18 16:04:23 EST 1993
--- innd/chan.c	Sun Aug  4 13:23:39 EDT 1996
***************
*** 184,189 ****
--- 184,191 ----
  		"%s closed seconds %ld accepted %ld refused %ld rejected %ld",
  		name, (long)(Now.time - cp->Started),
  		cp->Received, cp->Refused, cp->Rejected);
+ 	else if (cp->Type == CTreject)
+ 	    syslog(L_NOTICE, "%s %ld", name, cp->Rejected);
  	else
  	    syslog(L_NOTICE, "%s closed", name);
  	WCHANremove(cp);
***************
*** 240,245 ****
--- 242,250 ----
      case CTremconn:
  	(void)sprintf(buff, "remconn:%d", cp->fd);
  	break;
+     case CTreject:
+ 	(void)sprintf(buff, "%s rejected", RChostname(cp));
+ 	break;
      case CTnntp:
  	(void)sprintf(buff, "%s:%d",
  		cp->Address.s_addr == 0 ? "localhost" : RChostname(cp),
***************
*** 616,621 ****
--- 621,627 ----
  	switch (cp->Type) {
  	default:
  	    break;
+ 	case CTreject:
  	case CTnntp:
  	case CTfile:
  	case CTexploder:
***************
*** 823,828 ****
--- 829,842 ----
  		cp->LastActive = Now.time;
  		SCHANremove(cp);
  		(*cp->Waker)(cp);
+ 	    }
+ 
+ 	    /* Toss CTreject channel early if it's inactive. */
+ 	    if (cp->Type == CTreject
+ 	     && cp->LastActive + REJECT_TIMEOUT < Now.time) {
+ 		p = CHANname(cp);
+ 		syslog(L_NOTICE, "%s timeout reject", p);
+ 		CHANclose(cp, p);
  	    }
  
  	    /* Has this channel been inactive very long? */
*** innd/innd.c.dist	Thu Mar 18 16:04:25 EST 1993
--- innd/innd.c	Sun Aug  4 13:32:03 EDT 1996
***************
*** 37,42 ****
--- 37,45 ----
  long		LargestArticle = MAX_ART_SIZE;
  OPERATINGMODE	Mode = OMrunning;
  time_t		Cutoff = DEFAULT_CUTOFF * 24 * 60 * 60;
+ int		RemoteLimit = REMOTELIMIT;
+ time_t		RemoteTimer = REMOTETIMER;
+ int		RemoteTotal = REMOTETOTAL;
  
  #if	defined(__CENTERLINE__)
  BOOL		Debug = TRUE;
***************
*** 616,622 ****
  
      /* Parse JCL. */
      CCcopyargv(av);
!     while ((i = getopt(ac, av, "ac:dfi:l:m:o:n:p:rsS:t:ux")) != EOF)
  	switch (i) {
  	default:
  	    Usage();
--- 619,625 ----
  
      /* Parse JCL. */
      CCcopyargv(av);
!     while ((i = getopt(ac, av, "ac:dfH:i:l:m:o:n:p:rsS:t:T:uxX:")) != EOF)
  	switch (i) {
  	default:
  	    Usage();
***************
*** 636,641 ****
--- 639,647 ----
  	case 'f':
  	    ShouldFork = FALSE;
  	    break;
+ 	case 'H':
+ 	    RemoteLimit = atoi(optarg);
+ 	    break;
  	case 'i':
  	    MaxIncoming = atoi(optarg);
  	    break;
***************
*** 691,701 ****
--- 697,713 ----
  	case 't':
  	    TimeOut.tv_sec = atol(optarg);
  	    break;
+ 	case 'T':
+ 	    RemoteTotal = atoi(optarg);
+ 	    break;
  	case 'u':
  	    BufferedLogs = FALSE;
  	    break;
  	case 'x':
  	    AlwaysCrosspost = TRUE;
+ 	    break;
+ 	case 'X':
+ 	    RemoteTimer = atoi(optarg);
  	    break;
  	}
      ac -= optind;
*** innd/innd.h.dist	Thu Mar 18 16:04:26 EST 1993
--- innd/innd.h	Sun Aug  4 13:36:37 EDT 1996
***************
*** 91,96 ****
--- 91,97 ----
      CTany,
      CTfree,
      CTremconn,
+     CTreject,
      CTnntp,
      CTlocalconn,
      CTcontrol,
***************
*** 400,405 ****
--- 401,424 ----
  EXTERN struct timeval	TimeOut;
  EXTERN TIMEINFO		Now;		/* Reasonably accurate time	*/
  extern time_t		Cutoff;
+ 
+ /*
+ ** Table size for limiting incoming connects.  Do not change the table
+ ** size unless you look at the code manipulating it in rc.c.
+ */
+ #define REMOTETABLESIZE 128
+ 
+ /*
+ ** Setup the default values.  The REMOTETIMER being zero turns off the
+ ** code to limit incoming connects.
+ */
+ #define REMOTELIMIT	2
+ #define REMOTETIMER	0
+ #define REMOTETOTAL	60
+ #define REJECT_TIMEOUT	10
+ extern int		RemoteLimit; /* Per host limit. */
+ extern time_t		RemoteTimer; /* How long to remember connects. */
+ extern int		RemoteTotal; /* Total limit. */
  
  
  /*
*** innd/rc.c.dist	Thu Mar 18 16:04:31 EST 1993
--- innd/rc.c	Mon Aug  5 20:01:33 EDT 1996
***************
*** 30,35 ****
--- 30,40 ----
      char	**Patterns;
  } REMOTEHOST;
  
+ typedef struct _REMOTETABLE {
+     INADDR	Address;
+     time_t	Expires;
+ } REMOTETABLE;
+ 
  STATIC INADDR		*RCmaster;
  STATIC int		RCnmaster;
  STATIC char		*RCslaveflag;
***************
*** 42,48 ****
--- 47,61 ----
  STATIC REMOTEHOST	*RCnolimitlist;
  STATIC int		RCnnolimitlist;
  
+ /*
+ ** Stuff needed for limiting incoming connects.
+ */
+ STATIC char		RCterm[] = "\r\n";
+ STATIC REMOTETABLE	remotetable[REMOTETABLESIZE];
+ STATIC int		remotecount;
+ STATIC int		remotefirst;
  
+ 
  /*
  **  See if the site properly entered the password.
  */
***************
*** 110,115 ****
--- 123,159 ----
  
  
  /*
+ **  Called when input is ready to read.  Shouldn't happen.
+ */
+ /* ARGSUSED0 */
+ STATIC FUNCTYPE
+ RCrejectreader(cp)
+     CHANNEL	*cp;
+ {
+     syslog(L_ERROR, "%s internal RCrejectreader", LogName);
+ }
+ 
+ 
+ /*
+ **  Write-done function for rejects.
+ */
+ STATIC FUNCTYPE
+ RCrejectwritedone(cp)
+     register CHANNEL	*cp;
+ {
+     switch (cp->State) {
+     default:
+ 	syslog(L_ERROR, "%s internal RCrejectwritedone state %d",
+ 	    CHANname(cp), cp->State);
+ 	break;
+     case CSwritegoodbye:
+ 	CHANclose(cp, CHANname(cp));
+ 	break;
+     }
+ }
+ 
+ 
+ /*
  **  Hand off a descriptor to NNRPD.
  */
  void
***************
*** 164,169 ****
--- 208,218 ----
      register REMOTEHOST	*rp;
      CHANNEL		*new;
      char		*name;
+     long		reject_val;
+     char		*reject_message;
+     int			count;
+     int			found;
+     time_t		now;
  
      if (cp != RCchan) {
  	syslog(L_ERROR, "%s internal RCreader wrong channel 0x%x not 0x%x",
***************
*** 175,180 ****
--- 224,317 ----
      size = sizeof remote;
      if ((fd = accept(cp->fd, (struct sockaddr *)&remote, &size)) < 0) {
  	syslog(L_ERROR, "%s cant accept RCreader %m", LogName);
+ 	return;
+     }
+ 
+     /*
+     ** If RemoteTimer is not zero, then check the limits on incoming
+     ** connections on a total and per host basis.
+     **
+     ** The incoming connection table is fixed at 128 entries to make
+     ** calculating the index easy (i + 1) & 7, and to be pretty sure
+     ** that you won't run out of space.  The table is used as a ring
+     ** with new entries being added to the end (wrapping around) and
+     ** expired entries being deleted from the front (again wrapping
+     ** around).  It is doubtful that you will ever use even half of
+     ** the table.
+     **
+     ** There are three parameters controlling the use of the table not
+     ** counting the starting index and count.
+     **
+     ** L = per host incoming connects per X seconds allowed
+     ** T = total incoming connects per X seconds allowed
+     ** X = number of seconds to remember a successful connect
+     **
+     ** First, one pass is made over the live entries deleting any that
+     ** are over X seconds old.  If the entry hasn't expired, compare
+     ** the incoming connection's host address with the entry's host
+     ** address.  If equal, increment the ``found'' counter.
+     **
+     ** Second, if the number of entries now in the table is equal to
+     ** the ``T'' parameter, reject the connection with the ``504''
+     ** error code.
+     **
+     ** 504 Server overloaded, try later
+     **
+     ** Third, if the number of entries now in the table which match
+     ** the incoming connection's host address is equal to the ``L''
+     ** parameter, reject the connection with the ``505'' error code.
+     **
+     ** 505 Connection rejected, you're making too many connects per minute
+     **
+     ** Finally, if neither rejection happened, add the entry to the
+     ** table, and continue on as a normal connect.
+     */
+     reject_message = NULL;
+     if (RemoteTimer != 0) {
+ 	now = time(NULL);
+ 	i = remotefirst;
+ 	count = remotecount;
+ 	found = 0;
+ 	while (count--) {
+ 	    if (remotetable[i].Expires < now) {
+ 		remotecount--;
+ 		remotefirst = (remotefirst + 1) & (REMOTETABLESIZE - 1);
+ 		i = (i + 1) & (REMOTETABLESIZE - 1);
+ 		continue;
+ 	    }
+ 	    if (remotetable[i].Address.s_addr == remote.sin_addr.s_addr)
+ 		found++;
+ 	    i = (i + 1) & (REMOTETABLESIZE - 1);
+ 	}
+ 	if (remotecount == RemoteTotal) {
+ 	    reject_val = NNTP_SERVER_TOOBUSY_VAL;
+ 	    reject_message = NNTP_SERVER_TOOBUSY;
+ 	}
+ 	else if (found >= RemoteLimit && !RCnolimit(cp)) {
+ 	    reject_val = NNTP_TOO_MANY_CONNECTS_VAL;
+ 	    reject_message = NNTP_TOO_MANY_CONNECTS;
+ 	}
+ 	else {
+ 	    i = (remotefirst + remotecount) & (REMOTETABLESIZE - 1);
+ 	    remotetable[i].Address = remote.sin_addr;
+ 	    remotetable[i].Expires = now + RemoteTimer;
+ 	    remotecount++;
+ 	}
+     }
+ 
+     /*
+     ** Create a reject channel to reject the connection.  This is done
+     ** to avoid a call to fork.  
+     */
+     if (reject_message) {
+ 	new = CHANcreate(fd, CTreject, CSwritegoodbye, RCrejectreader,
+ 	    RCrejectwritedone);
+ 	new->Address.s_addr = remote.sin_addr.s_addr;
+ 	new->Rejected = reject_val;
+ 	RCHANremove(new);
+ 	WCHANset(new, reject_message, (int)strlen(reject_message));
+ 	WCHANappend(new, RCterm, STRLEN(RCterm));
+ 	WCHANadd(new);
  	return;
      }
  
*** nnrpd/nnrpd.c.dist	Thu Mar 18 16:04:44 EST 1993
--- nnrpd/nnrpd.c	Sat Aug  3 23:54:42 EDT 1996
***************
*** 14,19 ****
--- 14,32 ----
  #endif	/* defined(HPUX) */
  
  
+ /*
+ ** Here is some defensive code to protect the news server from hosts,
+ ** mostly PC's, that sometimes make a connection and then never give
+ ** any commands.  The connection is abandoned, but we're never told
+ ** about it.  The first time the connection is read, it will have a
+ ** timeout value of INITIAL_TIMEOUT seconds.  All subsequent reads
+ ** will have the standard timeout of CLIENT_TIMEOUT seconds.
+ */
+ #if !defined(INITIAL_TIMEOUT)
+ #define INITIAL_TIMEOUT	10
+ #endif
+ 
+ 
  #define CMDany		-1
  
  
***************
*** 504,509 ****
--- 517,523 ----
      register int	i;
      char		*Reject;
      char		accesslist[BIG_BUFFER];
+     int			timeout;
  
  #if	!defined(HPUX)
      /* Save start and extent of argv for TITLEset. */
***************
*** 598,604 ****
  	   PERMcanpost ? "posting ok" : "no posting");
  
      /* Main dispatch loop. */
!     for (av = NULL; ; ) {
  	(void)fflush(stdout);
  	if (ChangeTrace) {
  	    Tracing = Tracing ? FALSE : TRUE;
--- 612,618 ----
  	   PERMcanpost ? "posting ok" : "no posting");
  
      /* Main dispatch loop. */
!     for (timeout = INITIAL_TIMEOUT, av = NULL; ; timeout = CLIENT_TIMEOUT) {
  	(void)fflush(stdout);
  	if (ChangeTrace) {
  	    Tracing = Tracing ? FALSE : TRUE;
***************
*** 605,618 ****
  	    syslog(L_TRACE, "trace %sabled", Tracing ? "en" : "dis");
  	    ChangeTrace = FALSE;
  	}
! 	switch (r = READline(buff, (int)sizeof buff, CLIENT_TIMEOUT)) {
  	default:
  	    syslog(L_ERROR, "%s internal %d in main", ClientHost, r);
  	    /* FALLTHROUGH */
  	case RTtimeout:
! 	    syslog(L_NOTICE, "%s timeout", ClientHost);
  	    Printf("%d Timeout after %d seconds, closing connection.\r\n",
! 		   NNTP_TEMPERR_VAL, CLIENT_TIMEOUT);
  	    ExitWithStats(1);
  	    break;
  	case RTlong:
--- 619,635 ----
  	    syslog(L_TRACE, "trace %sabled", Tracing ? "en" : "dis");
  	    ChangeTrace = FALSE;
  	}
! 	switch (r = READline(buff, (int)sizeof buff, timeout)) {
  	default:
  	    syslog(L_ERROR, "%s internal %d in main", ClientHost, r);
  	    /* FALLTHROUGH */
  	case RTtimeout:
! 	    if (timeout < CLIENT_TIMEOUT)
! 		syslog(L_NOTICE, "%s timeout short", ClientHost);
! 	    else
! 		syslog(L_NOTICE, "%s timeout", ClientHost);
  	    Printf("%d Timeout after %d seconds, closing connection.\r\n",
! 		   NNTP_TEMPERR_VAL, timeout);
  	    ExitWithStats(1);
  	    break;
  	case RTlong:
*** samples/innlog.awk.dist	Fri Jan 29 11:52:13 EST 1993
--- samples/innlog.awk	Sun Aug  4 00:10:48 EDT 1996
***************
*** 143,148 ****
--- 143,155 ----
  	next;
      }
  
+     # Catch the nnrpd's which timed out on the first read
+     if ($7 == "timeout" && $8 == "short") {
+ 	client_short = 1;
+ 	nnrp_short[host]++;
+ 	next;
+     }
+ 
      if ($7 == "timeout") {
  	client_timeout = 1;
  	nnrp_timeout[host]++;
***************
*** 242,247 ****
--- 249,271 ----
  	next;
      }
  
+     # Connections rejected because of the limiting incoming connect
+     # code can cause two different rejected messages:
+     #
+     # ... innd: HOSTADDR rejected cant write Broken pipe"
+     # ... innd: HOSTADDR rejected 505"
+     #
+     # They both mean the same thing.  The Broken pipe happens when
+     # the other end of the connection goes away first.
+     if ($7 == "rejected") {
+ 	if ($8 == "505" ||
+ 	    ($10 == "Broken" && $11 == "pipe")) {
+ 	    innd_505s[host]++;
+ 	    innd_505_flag = 1;
+ 	}
+ 	next;
+     }
+ 
      if ($7 == "flush") {
  	innd_flush[host]++;
  	next;
***************
*** 1337,1343 ****
--- 1361,1384 ----
  	}
  	printf("\n");
      }
+     if (innd_505_flag) {
+ 	printf("Hosts making too many connects per minute\n");
+ 	printf(" Conn System\n");
+ 	for ( ; ; ) {
+ 	    s = invalid;
+ 	    for (sortindex in innd_505s)
+ 		if (innd_505s[sortindex] >= 0 && sortindex < s)
+ 		    s = sortindex;
+ 	    if (s == invalid)
+ 		break;
  
+ 	    printf("%5d %s\n", innd_505s[s], s);
+ 
+ 	    innd_505s[s] = -1;
+ 	}
+ 	printf("\n");
+     }
+ 
      ##  NNRP statistics.
      if (nnrp) {
  	printf("NNRP readership statistics\n");
***************
*** 1490,1495 ****
--- 1531,1557 ----
  
  	    nnrp_timeout[s] = -1;
          }
+ 	printf("\n");
+     }
+     # Change the ``0'' to ``client_short'' if you want to see the report
+     if (0) {
+ 	printf("NNRP clients which timed out on the first read:\n");
+ 	printf(" Conn System\n");
+ 	sum = 0;
+ 	for ( ; ; ) {
+ 	    s = invalid;
+ 	    for (sortindex in nnrp_short)
+ 		if (nnrp_short[sortindex] >= 0 && sortindex < s)
+ 		    s = sortindex;
+             if (s == invalid)
+ 		break;
+ 
+ 	    printf("%5d %s\n", nnrp_short[s], s);
+ 	    sum += nnrp_short[s];
+ 
+ 	    nnrp_short[s] = -1;
+         }
+ 	printf("%5d TOTAL\n", sum);
  	printf("\n");
      }
      if (server_timeout) {

Re: Problems with Netscape 2.0x and INN1.4
#9945
Author: John T. Stapleton
Date: Wed, 07 Aug 1996 00:00
734 lines
22969 bytes
In article <4u62am$qae@news.demos.su>,
Andrew A. Vasilyev <andy@snm.demos.su> wrote:
>Andrew A. Vasilyev (andy@snm.demos.su) wrote:
>>    Great job! But what about adding a check
>>      (rc.c near 291 line in your count):
>> > +     else if (found >= RemoteLimit && !RCnolimit(cp)) {
>> 				      ^^^^^^^^^^^^^^^^^
>
>  O-ops! Correcting myself :(((
>  One should use additional variable for that check 'cause the
>  cp->Address may be undefined. Something like:
>
>    CHANNEL cp1;
>
>    cp1.Address.s_addr = remote.sin_addr.s_addr; /* After accept() */
>    ...
>    else if (found >= RemoteLimit && !RCnolimit(&cp1)) {
>
>  If one could suggest a better solution I would be happy.

Third time is the charm.  Here's the patch again (3rd version), fixing my
typo in the 1st version, and the error mentioned above (which was in the
2nd version of the patch.

The only thing that I changed from your suggestion is the name to tempchan
because it is a struct and not a pointer.

The rest of this article is the README file and the patches (3rd
version).  The second version was identified.  The first version of
the patches were not identified as being any version.

Stapes

----Beginning of README
	 Limiting the number of incoming connects per minute
		    on a total or per host basis.

There are three new option flags for limiting the number of incoming
connects per minute.

This code was developed as a fix to protect innd from news reader
client programs that make too many connects.  In particular, Netscape
V2.0 and up can cause major problems for innd if you are running
streaming.  While your server is receiving news from a feed, it does
not respond fast enough to connects from Netscape.  If the person
using Netscape is rapidly clicking ``Next'', then your server can fall
behind with disastrous results.  I've seen my server go from a load
average between 5.00 and 10.00 to over 200.00 in under 90 seconds.

The problem is that Netscape will abandon a connect and initiate
another connect before your server can respond.  It will keep doing
this if the user keeps clicking ``Next'' rapidly.  Meanwhile, your
server will keep forking nnrpd's thereby overloading your server.

If you are not having a problem, you should probably not bother to
enable this option.  Also, some systems are better able to cope with
this problem than others.  My ULTRIX news server needs this option,
but Digital UNIX seems to deal with it fine if you have the nnrpd
initial timeout patch which is also included.  That patch sets the
timeout for the first read to a small number of seconds, then reverts
to the standard timeout.

The table used for these checks is fixed at 128 entries and is used as
a ring.  The size was chosen to make calculating the index easy and to
be pretty sure you won't run out of space.  In practice, it is
doubtful that you will use even half the table at any given moment.

The ``-H'' flag limits the number of times a host is allowed to
connect to the server per ``-X'' seconds.  The default is 2.

The ``-T'' flag limits the total number of incoming connects to innd
per ``-X'' seconds.  The maximum value is 128.  The default is 60.

The ``-X'' sets the number of seconds used by the ``-H'' and ``-T''
flags.  A value of zero turns off checking.  The default is 0.  If you
are having a problem with too many connects, I suggest you start this
option at 60 and see how it goes.
----End of README

Here are the diffs:
-------------------
*** doc/innd.8.dist	Thu Mar 18 16:03:40 EST 1993
--- doc/innd.8	Sun Aug  4 12:26:06 EDT 1996
***************
*** 52,57 ****
--- 52,66 ----
  [
  .B \-x
  ]
+ [
+ .BI \-H " count"
+ ]
+ [
+ .BI \-T " count"
+ ]
+ [
+ .BI \-X " seconds"
+ ]
  
  .B inndstart
  [
***************
*** 213,218 ****
--- 222,247 ----
  .PP
  If the ``\-x'' flag is used, then an Xref header will be added to all
  articles even if they are not cross-posted.
+ .PP
+ .PP
+ The ``\-H'', ``\-T'', and ``\-X'' flags control the number of connects per
+ minute allowed.
+ This code is meant to protect your server from newsreader clients that
+ make too many connects per minute to your server.  You should probably
+ not use it unless you are having a problem.
+ The table used for these checks is fixed at 128 entries and is used as
+ a ring.  The size was chosen to make calculating the index easy and to
+ be pretty sure you won't run out of space.  In practice, it is
+ doubtful that you will use even half the table at any given moment.
+ .PP
+ The ``\-H'' flag limits the number of times a host is allowed to connect
+ to the server per ``\-X'' seconds.  The default is 2.
+ .PP
+ The ``\-T'' flag limits the total number of incoming connects to innd
+ per ``\-X'' seconds.  The maximum value is 128.  The default is 60.
+ .PP
+ The ``\-X'' sets the number of seconds used by the ``\-H'' and ``-T''
+ flags.  A value of zero turns off checking.  The default is 0.
  .PP
  .I Inndstart
  is a small front-end program that opens the NNTP port, sets its
*** include/nntp.h.dist	Thu Mar 18 16:04:14 EST 1993
--- include/nntp.h	Sun Aug  4 13:04:23 EDT 1996
***************
*** 82,87 ****
--- 82,91 ----
  #define NNTP_NOPREV_VAL			422
  #define NNTP_CANTPOST			"440 Posting not allowed"
  #define NNTP_CANTPOST_VAL		440
+ #define NNTP_SERVER_TOOBUSY		"504 Server overloaded, try later"
+ #define NNTP_SERVER_TOOBUSY_VAL		504
+ #define NNTP_TOO_MANY_CONNECTS		"505 Connection rejected, you're making too many connects per minute"
+ #define NNTP_TOO_MANY_CONNECTS_VAL	505
  
  
  /*
*** innd/cc.c.dist	Thu Mar 18 16:04:22 EST 1993
--- innd/cc.c	Mon Aug  5 19:53:41 EDT 1996
***************
*** 566,571 ****
--- 566,572 ----
  	    case CTprocess:
  	    case CTfile:
  	    case CTnntp:
+ 	    case CTreject:
  		syslog(L_NOTICE, "%s hangup", p);
  		CHANclose(cp, p);
  		return NULL;
***************
*** 621,630 ****
      for (i = 0, h = 0; CHANiter(&h, CTnntp) != NULL; )
  	i++;
      *p++ = '\n';
!     (void)sprintf(p, "Parameters c %ld i %d (%d) l %ld o %d t %ld %s %s",
  	    (long)Cutoff / (24L * 60L * 60L),
  	    MaxIncoming, i,
  	    LargestArticle, MaxOutgoing, (long)TimeOut.tv_sec,
  	    AmSlave ? "slave" : "normal",
  	    AnyIncoming ? "any" : "specified");
      p += strlen(p);
--- 622,632 ----
      for (i = 0, h = 0; CHANiter(&h, CTnntp) != NULL; )
  	i++;
      *p++ = '\n';
!     (void)sprintf(p, "Parameters c %ld i %d (%d) l %ld o %d t %ld H %d T %d X %d %s %s",
  	    (long)Cutoff / (24L * 60L * 60L),
  	    MaxIncoming, i,
  	    LargestArticle, MaxOutgoing, (long)TimeOut.tv_sec,
+ 	    RemoteLimit, RemoteTotal, (int) RemoteTimer,
  	    AmSlave ? "slave" : "normal",
  	    AnyIncoming ? "any" : "specified");
      p += strlen(p);
***************
*** 839,844 ****
--- 841,860 ----
      case 't':
  	TimeOut.tv_sec = atol(p);
  	syslog(L_NOTICE, "%s changed -t %ld", LogName, (long)TimeOut.tv_sec);
+ 	break;
+     case 'H':
+ 	RemoteLimit = atoi(p);
+ 	syslog(L_NOTICE, "%s changed -H %d", LogName, RemoteLimit);
+ 	break;
+     case 'T':
+ 	RemoteTotal = atoi(p);
+ 	if (RemoteTotal > REMOTETABLESIZE)
+ 	    RemoteTotal = REMOTETABLESIZE;
+ 	syslog(L_NOTICE, "%s changed -T %d", LogName, RemoteTotal);
+ 	break;
+     case 'X':
+ 	RemoteTimer = (time_t) atoi(p);
+ 	syslog(L_NOTICE, "%s changed -X %d", LogName, (int) RemoteTimer);
  	break;
      }
      return NULL;
*** innd/chan.c.dist	Thu Mar 18 16:04:23 EST 1993
--- innd/chan.c	Sun Aug  4 13:23:39 EDT 1996
***************
*** 184,189 ****
--- 184,191 ----
  		"%s closed seconds %ld accepted %ld refused %ld rejected %ld",
  		name, (long)(Now.time - cp->Started),
  		cp->Received, cp->Refused, cp->Rejected);
+ 	else if (cp->Type == CTreject)
+ 	    syslog(L_NOTICE, "%s %ld", name, cp->Rejected);
  	else
  	    syslog(L_NOTICE, "%s closed", name);
  	WCHANremove(cp);
***************
*** 240,245 ****
--- 242,250 ----
      case CTremconn:
  	(void)sprintf(buff, "remconn:%d", cp->fd);
  	break;
+     case CTreject:
+ 	(void)sprintf(buff, "%s rejected", RChostname(cp));
+ 	break;
      case CTnntp:
  	(void)sprintf(buff, "%s:%d",
  		cp->Address.s_addr == 0 ? "localhost" : RChostname(cp),
***************
*** 616,621 ****
--- 621,627 ----
  	switch (cp->Type) {
  	default:
  	    break;
+ 	case CTreject:
  	case CTnntp:
  	case CTfile:
  	case CTexploder:
***************
*** 823,828 ****
--- 829,842 ----
  		cp->LastActive = Now.time;
  		SCHANremove(cp);
  		(*cp->Waker)(cp);
+ 	    }
+ 
+ 	    /* Toss CTreject channel early if it's inactive. */
+ 	    if (cp->Type == CTreject
+ 	     && cp->LastActive + REJECT_TIMEOUT < Now.time) {
+ 		p = CHANname(cp);
+ 		syslog(L_NOTICE, "%s timeout reject", p);
+ 		CHANclose(cp, p);
  	    }
  
  	    /* Has this channel been inactive very long? */
*** innd/innd.c.dist	Thu Mar 18 16:04:25 EST 1993
--- innd/innd.c	Sun Aug  4 13:32:03 EDT 1996
***************
*** 37,42 ****
--- 37,45 ----
  long		LargestArticle = MAX_ART_SIZE;
  OPERATINGMODE	Mode = OMrunning;
  time_t		Cutoff = DEFAULT_CUTOFF * 24 * 60 * 60;
+ int		RemoteLimit = REMOTELIMIT;
+ time_t		RemoteTimer = REMOTETIMER;
+ int		RemoteTotal = REMOTETOTAL;
  
  #if	defined(__CENTERLINE__)
  BOOL		Debug = TRUE;
***************
*** 616,622 ****
  
      /* Parse JCL. */
      CCcopyargv(av);
!     while ((i = getopt(ac, av, "ac:dfi:l:m:o:n:p:rsS:t:ux")) != EOF)
  	switch (i) {
  	default:
  	    Usage();
--- 619,625 ----
  
      /* Parse JCL. */
      CCcopyargv(av);
!     while ((i = getopt(ac, av, "ac:dfH:i:l:m:o:n:p:rsS:t:T:uxX:")) != EOF)
  	switch (i) {
  	default:
  	    Usage();
***************
*** 636,641 ****
--- 639,647 ----
  	case 'f':
  	    ShouldFork = FALSE;
  	    break;
+ 	case 'H':
+ 	    RemoteLimit = atoi(optarg);
+ 	    break;
  	case 'i':
  	    MaxIncoming = atoi(optarg);
  	    break;
***************
*** 691,701 ****
--- 697,713 ----
  	case 't':
  	    TimeOut.tv_sec = atol(optarg);
  	    break;
+ 	case 'T':
+ 	    RemoteTotal = atoi(optarg);
+ 	    break;
  	case 'u':
  	    BufferedLogs = FALSE;
  	    break;
  	case 'x':
  	    AlwaysCrosspost = TRUE;
+ 	    break;
+ 	case 'X':
+ 	    RemoteTimer = atoi(optarg);
  	    break;
  	}
      ac -= optind;
*** innd/innd.h.dist	Thu Mar 18 16:04:26 EST 1993
--- innd/innd.h	Sun Aug  4 13:36:37 EDT 1996
***************
*** 91,96 ****
--- 91,97 ----
      CTany,
      CTfree,
      CTremconn,
+     CTreject,
      CTnntp,
      CTlocalconn,
      CTcontrol,
***************
*** 400,405 ****
--- 401,424 ----
  EXTERN struct timeval	TimeOut;
  EXTERN TIMEINFO		Now;		/* Reasonably accurate time	*/
  extern time_t		Cutoff;
+ 
+ /*
+ ** Table size for limiting incoming connects.  Do not change the table
+ ** size unless you look at the code manipulating it in rc.c.
+ */
+ #define REMOTETABLESIZE 128
+ 
+ /*
+ ** Setup the default values.  The REMOTETIMER being zero turns off the
+ ** code to limit incoming connects.
+ */
+ #define REMOTELIMIT	2
+ #define REMOTETIMER	0
+ #define REMOTETOTAL	60
+ #define REJECT_TIMEOUT	10
+ extern int		RemoteLimit; /* Per host limit. */
+ extern time_t		RemoteTimer; /* How long to remember connects. */
+ extern int		RemoteTotal; /* Total limit. */
  
  
  /*
*** innd/rc.c.dist	Thu Mar 18 16:04:31 EST 1993
--- innd/rc.c	Tue Aug  6 23:55:08 EDT 1996
***************
*** 30,35 ****
--- 30,40 ----
      char	**Patterns;
  } REMOTEHOST;
  
+ typedef struct _REMOTETABLE {
+     INADDR	Address;
+     time_t	Expires;
+ } REMOTETABLE;
+ 
  STATIC INADDR		*RCmaster;
  STATIC int		RCnmaster;
  STATIC char		*RCslaveflag;
***************
*** 42,48 ****
--- 47,61 ----
  STATIC REMOTEHOST	*RCnolimitlist;
  STATIC int		RCnnolimitlist;
  
+ /*
+ ** Stuff needed for limiting incoming connects.
+ */
+ STATIC char		RCterm[] = "\r\n";
+ STATIC REMOTETABLE	remotetable[REMOTETABLESIZE];
+ STATIC int		remotecount;
+ STATIC int		remotefirst;
  
+ 
  /*
  **  See if the site properly entered the password.
  */
***************
*** 110,115 ****
--- 123,159 ----
  
  
  /*
+ **  Called when input is ready to read.  Shouldn't happen.
+ */
+ /* ARGSUSED0 */
+ STATIC FUNCTYPE
+ RCrejectreader(cp)
+     CHANNEL	*cp;
+ {
+     syslog(L_ERROR, "%s internal RCrejectreader", LogName);
+ }
+ 
+ 
+ /*
+ **  Write-done function for rejects.
+ */
+ STATIC FUNCTYPE
+ RCrejectwritedone(cp)
+     register CHANNEL	*cp;
+ {
+     switch (cp->State) {
+     default:
+ 	syslog(L_ERROR, "%s internal RCrejectwritedone state %d",
+ 	    CHANname(cp), cp->State);
+ 	break;
+     case CSwritegoodbye:
+ 	CHANclose(cp, CHANname(cp));
+ 	break;
+     }
+ }
+ 
+ 
+ /*
  **  Hand off a descriptor to NNRPD.
  */
  void
***************
*** 164,169 ****
--- 208,219 ----
      register REMOTEHOST	*rp;
      CHANNEL		*new;
      char		*name;
+     long		reject_val;
+     char		*reject_message;
+     int			count;
+     int			found;
+     time_t		now;
+     CHANNEL		tempchan;
  
      if (cp != RCchan) {
  	syslog(L_ERROR, "%s internal RCreader wrong channel 0x%x not 0x%x",
***************
*** 175,180 ****
--- 225,319 ----
      size = sizeof remote;
      if ((fd = accept(cp->fd, (struct sockaddr *)&remote, &size)) < 0) {
  	syslog(L_ERROR, "%s cant accept RCreader %m", LogName);
+ 	return;
+     }
+ 
+     /*
+     ** If RemoteTimer is not zero, then check the limits on incoming
+     ** connections on a total and per host basis.
+     **
+     ** The incoming connection table is fixed at 128 entries to make
+     ** calculating the index easy (i + 1) & 7, and to be pretty sure
+     ** that you won't run out of space.  The table is used as a ring
+     ** with new entries being added to the end (wrapping around) and
+     ** expired entries being deleted from the front (again wrapping
+     ** around).  It is doubtful that you will ever use even half of
+     ** the table.
+     **
+     ** There are three parameters controlling the use of the table not
+     ** counting the starting index and count.
+     **
+     ** L = per host incoming connects per X seconds allowed
+     ** T = total incoming connects per X seconds allowed
+     ** X = number of seconds to remember a successful connect
+     **
+     ** First, one pass is made over the live entries deleting any that
+     ** are over X seconds old.  If the entry hasn't expired, compare
+     ** the incoming connection's host address with the entry's host
+     ** address.  If equal, increment the ``found'' counter.
+     **
+     ** Second, if the number of entries now in the table is equal to
+     ** the ``T'' parameter, reject the connection with the ``504''
+     ** error code.
+     **
+     ** 504 Server overloaded, try later
+     **
+     ** Third, if the number of entries now in the table which match
+     ** the incoming connection's host address is equal to the ``L''
+     ** parameter, reject the connection with the ``505'' error code.
+     **
+     ** 505 Connection rejected, you're making too many connects per minute
+     **
+     ** Finally, if neither rejection happened, add the entry to the
+     ** table, and continue on as a normal connect.
+     */
+     tempchan.Address.s_addr = remote.sin_addr.s_addr;
+     reject_message = NULL;
+     if (RemoteTimer != 0) {
+ 	now = time(NULL);
+ 	i = remotefirst;
+ 	count = remotecount;
+ 	found = 0;
+ 	while (count--) {
+ 	    if (remotetable[i].Expires < now) {
+ 		remotecount--;
+ 		remotefirst = (remotefirst + 1) & (REMOTETABLESIZE - 1);
+ 		i = (i + 1) & (REMOTETABLESIZE - 1);
+ 		continue;
+ 	    }
+ 	    if (remotetable[i].Address.s_addr == remote.sin_addr.s_addr)
+ 		found++;
+ 	    i = (i + 1) & (REMOTETABLESIZE - 1);
+ 	}
+ 	if (remotecount == RemoteTotal) {
+ 	    reject_val = NNTP_SERVER_TOOBUSY_VAL;
+ 	    reject_message = NNTP_SERVER_TOOBUSY;
+ 	}
+ 	else if (found >= RemoteLimit && !RCnolimit(&tempchan)) {
+ 	    reject_val = NNTP_TOO_MANY_CONNECTS_VAL;
+ 	    reject_message = NNTP_TOO_MANY_CONNECTS;
+ 	}
+ 	else {
+ 	    i = (remotefirst + remotecount) & (REMOTETABLESIZE - 1);
+ 	    remotetable[i].Address = remote.sin_addr;
+ 	    remotetable[i].Expires = now + RemoteTimer;
+ 	    remotecount++;
+ 	}
+     }
+ 
+     /*
+     ** Create a reject channel to reject the connection.  This is done
+     ** to avoid a call to fork.  
+     */
+     if (reject_message) {
+ 	new = CHANcreate(fd, CTreject, CSwritegoodbye, RCrejectreader,
+ 	    RCrejectwritedone);
+ 	new->Address.s_addr = remote.sin_addr.s_addr;
+ 	new->Rejected = reject_val;
+ 	RCHANremove(new);
+ 	WCHANset(new, reject_message, (int)strlen(reject_message));
+ 	WCHANappend(new, RCterm, STRLEN(RCterm));
+ 	WCHANadd(new);
  	return;
      }
  
*** nnrpd/nnrpd.c.dist	Thu Mar 18 16:04:44 EST 1993
--- nnrpd/nnrpd.c	Sat Aug  3 23:54:42 EDT 1996
***************
*** 14,19 ****
--- 14,32 ----
  #endif	/* defined(HPUX) */
  
  
+ /*
+ ** Here is some defensive code to protect the news server from hosts,
+ ** mostly PC's, that sometimes make a connection and then never give
+ ** any commands.  The connection is abandoned, but we're never told
+ ** about it.  The first time the connection is read, it will have a
+ ** timeout value of INITIAL_TIMEOUT seconds.  All subsequent reads
+ ** will have the standard timeout of CLIENT_TIMEOUT seconds.
+ */
+ #if !defined(INITIAL_TIMEOUT)
+ #define INITIAL_TIMEOUT	10
+ #endif
+ 
+ 
  #define CMDany		-1
  
  
***************
*** 504,509 ****
--- 517,523 ----
      register int	i;
      char		*Reject;
      char		accesslist[BIG_BUFFER];
+     int			timeout;
  
  #if	!defined(HPUX)
      /* Save start and extent of argv for TITLEset. */
***************
*** 598,604 ****
  	   PERMcanpost ? "posting ok" : "no posting");
  
      /* Main dispatch loop. */
!     for (av = NULL; ; ) {
  	(void)fflush(stdout);
  	if (ChangeTrace) {
  	    Tracing = Tracing ? FALSE : TRUE;
--- 612,618 ----
  	   PERMcanpost ? "posting ok" : "no posting");
  
      /* Main dispatch loop. */
!     for (timeout = INITIAL_TIMEOUT, av = NULL; ; timeout = CLIENT_TIMEOUT) {
  	(void)fflush(stdout);
  	if (ChangeTrace) {
  	    Tracing = Tracing ? FALSE : TRUE;
***************
*** 605,618 ****
  	    syslog(L_TRACE, "trace %sabled", Tracing ? "en" : "dis");
  	    ChangeTrace = FALSE;
  	}
! 	switch (r = READline(buff, (int)sizeof buff, CLIENT_TIMEOUT)) {
  	default:
  	    syslog(L_ERROR, "%s internal %d in main", ClientHost, r);
  	    /* FALLTHROUGH */
  	case RTtimeout:
! 	    syslog(L_NOTICE, "%s timeout", ClientHost);
  	    Printf("%d Timeout after %d seconds, closing connection.\r\n",
! 		   NNTP_TEMPERR_VAL, CLIENT_TIMEOUT);
  	    ExitWithStats(1);
  	    break;
  	case RTlong:
--- 619,635 ----
  	    syslog(L_TRACE, "trace %sabled", Tracing ? "en" : "dis");
  	    ChangeTrace = FALSE;
  	}
! 	switch (r = READline(buff, (int)sizeof buff, timeout)) {
  	default:
  	    syslog(L_ERROR, "%s internal %d in main", ClientHost, r);
  	    /* FALLTHROUGH */
  	case RTtimeout:
! 	    if (timeout < CLIENT_TIMEOUT)
! 		syslog(L_NOTICE, "%s timeout short", ClientHost);
! 	    else
! 		syslog(L_NOTICE, "%s timeout", ClientHost);
  	    Printf("%d Timeout after %d seconds, closing connection.\r\n",
! 		   NNTP_TEMPERR_VAL, timeout);
  	    ExitWithStats(1);
  	    break;
  	case RTlong:
*** samples/innlog.awk.dist	Fri Jan 29 11:52:13 EST 1993
--- samples/innlog.awk	Sun Aug  4 00:10:48 EDT 1996
***************
*** 143,148 ****
--- 143,155 ----
  	next;
      }
  
+     # Catch the nnrpd's which timed out on the first read
+     if ($7 == "timeout" && $8 == "short") {
+ 	client_short = 1;
+ 	nnrp_short[host]++;
+ 	next;
+     }
+ 
      if ($7 == "timeout") {
  	client_timeout = 1;
  	nnrp_timeout[host]++;
***************
*** 242,247 ****
--- 249,271 ----
  	next;
      }
  
+     # Connections rejected because of the limiting incoming connect
+     # code can cause two different rejected messages:
+     #
+     # ... innd: HOSTADDR rejected cant write Broken pipe"
+     # ... innd: HOSTADDR rejected 505"
+     #
+     # They both mean the same thing.  The Broken pipe happens when
+     # the other end of the connection goes away first.
+     if ($7 == "rejected") {
+ 	if ($8 == "505" ||
+ 	    ($10 == "Broken" && $11 == "pipe")) {
+ 	    innd_505s[host]++;
+ 	    innd_505_flag = 1;
+ 	}
+ 	next;
+     }
+ 
      if ($7 == "flush") {
  	innd_flush[host]++;
  	next;
***************
*** 1337,1343 ****
--- 1361,1384 ----
  	}
  	printf("\n");
      }
+     if (innd_505_flag) {
+ 	printf("Hosts making too many connects per minute\n");
+ 	printf(" Conn System\n");
+ 	for ( ; ; ) {
+ 	    s = invalid;
+ 	    for (sortindex in innd_505s)
+ 		if (innd_505s[sortindex] >= 0 && sortindex < s)
+ 		    s = sortindex;
+ 	    if (s == invalid)
+ 		break;
  
+ 	    printf("%5d %s\n", innd_505s[s], s);
+ 
+ 	    innd_505s[s] = -1;
+ 	}
+ 	printf("\n");
+     }
+ 
      ##  NNRP statistics.
      if (nnrp) {
  	printf("NNRP readership statistics\n");
***************
*** 1490,1495 ****
--- 1531,1557 ----
  
  	    nnrp_timeout[s] = -1;
          }
+ 	printf("\n");
+     }
+     # Change the ``0'' to ``client_short'' if you want to see the report
+     if (0) {
+ 	printf("NNRP clients which timed out on the first read:\n");
+ 	printf(" Conn System\n");
+ 	sum = 0;
+ 	for ( ; ; ) {
+ 	    s = invalid;
+ 	    for (sortindex in nnrp_short)
+ 		if (nnrp_short[sortindex] >= 0 && sortindex < s)
+ 		    s = sortindex;
+             if (s == invalid)
+ 		break;
+ 
+ 	    printf("%5d %s\n", nnrp_short[s], s);
+ 	    sum += nnrp_short[s];
+ 
+ 	    nnrp_short[s] = -1;
+         }
+ 	printf("%5d TOTAL\n", sum);
  	printf("\n");
      }
      if (server_timeout) {

Re: Problems with Netscape 2.0x and INN1.4
#10026
Author: Alan Brown
Date: Sat, 10 Aug 1996 00:00
14 lines
1151 bytes
In article <4ubodd$mul@blazing.mro.dec.com>,
John T. Stapleton <stapes@blazing.mro.dec.com> wrote:

>Third time is the charm.  Here's the patch again (3rd version), fixing my

Any chance of a patch for innlog.pl as well as innlog.awk?

AB
-- 
One net to rule them all, one net to find them, one net to bring them all,
using Unix to bind them.

Re: Problems with Netscape 2.0x and INN1.4
#10089
Author: Alan Brown
Date: Tue, 13 Aug 1996 00:00
38 lines
2102 bytes
In article <4ubodd$mul@blazing.mro.dec.com>,
John T. Stapleton <stapes@blazing.mro.dec.com> wrote:

John, that address doesn't exist when I tried to mail you about the patches.

>Third time is the charm.  Here's the patch again (3rd version), fixing my
>typo in the 1st version, and the error mentioned above (which was in the
>2nd version of the patch.

The posted patch is against inn1.4sec2(I think), not unoff4. 

Having said that, patching with a fuzz switch only failed in a couple of 
places in innd and only in areas dealing with extra switches introduced 
in the unoff series.

Problem dept:

#1: The excessive connection timer and the total connect patch are both 
    in innd. I use a proxy to shift incoming non newsfeed connects to 
    another port which then starts nnrpd out of inetd.conf.

(Having incorporated the patch which takes care of excessive wakeup delays
 in the face of streaming newsfeeds I may no longer need to do this, but
 "if it ain't broken....")

#2: If I enable the X timer, innd exits immediately it's started. No 
    corefile, no message in any of the logfiles. Just bang, dead.

Anyone got any ideas on this one at all?

AB

-- 
One net to rule them all, one net to find them, one net to bring them all,
using Unix to bind them.

Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads