🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #18434

Re: Increasing 1.5.1 Performance (1/1)

#18434
From: z
Date: Thu, 12 Jun 1997 00:00
9257 lines
280193 bytes

----=_339fa94d27155633002c52519.MFSBCHJLHS
Content-Type: text/plain; charset=us-ascii; name=config.data
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=config.data

## Sample config.data for linux 2.0.18

##
##  1.  MAKE CONFIG PARAMETERS
##  Where the DBZ sources are, from C News.  INN has a (maybe old) copy.
#### =()<DBZDIR			@<DBZDIR>@>()=
DBZDIR			../dbz
##  If you have a parallel make, set this to "&"
#### =()<P			@<P>@>()=
P			
##  C pre-processor flags
#### =()<DEFS			@<DEFS>@>()=
DEFS			-I../include
##  C compiler
#### =()<CC			@<CC>@>()=
CC			gcc
##  Does your compiler properly do "char const *"? Pick DO DONT or DUNNO
#### =()<USE_CHAR_CONST		@<USE_CHAR_CONST>@>()=
USE_CHAR_CONST		DO
##  C compiler flags
#### =()<CFLAGS			@<CFLAGS>@>()=
CFLAGS			$(DEFS) -O3 -m486 -DCPU=686 -fexpensive-optimizations
##  C compiler flags to use when compiling dbz
#### =()<DBZCFLAGS			@<DBZCFLAGS>@>()=
DBZCFLAGS			$(CFLAGS) -DMMAP
##  What flags to use if profiling; -p or -pg, e.g.
#### =()<PROF			@<PROF>@>()=
PROF			-p
##  Flags for the "cc -o" line; e.g., -Bstatic on SunOS4.x while debugging.
#### =()<LDFLAGS			@<LDFLAGS>@>()=
LDFLAGS			-O3 -m486 -DCPU=686 -fexpensive-optimizations
##  If you use the standard NNTP way of connecting, where is the library?
#### =()<NNTPLIB		@<NNTPLIB>@>()=
NNTPLIB		
##  If you need to link in other libraries, add them here.
##  On NetBSD and FreeBSD, you must add the -lcrypt directive here
##  -lutil on BSD/OS gives you setproctitle() see HAVE_SETPROCTITLE.
#### =()<LIBS			@<LIBS>@>()=
LIBS			/usr/lib/libc.a
##  How to make a lint library; pick BSD, SYSV, or NONE.
#### =()<LINTLIBSTYLE		@<LINTLIBSTYLE>@>()=
LINTLIBSTYLE		NONE
##  Flags for lint.  AIX wants "-wkD"; it and others don't want "-z".
#### =()<LINTFLAGS		@<LINTFLAGS>@>()=
LINTFLAGS		
##  Some lints insist on putting out the filename and other crap.
##  Possible values:
##	LINTFILTER              | sed -n -f ../sedf.aix
##	LINTFILTER              | sed -n -f ../sedf.osx
##	LINTFILTER              | sed -n -f ../sedf.sun
##	LINTFILTER              | sed -n -f ../sedf.sysv
##	LINTFILTER              
####  =()<LINTFILTER		@<LINTFILTER>@>()=
LINTFILTER		
##  How to install manpages; pick SOURCE, NROFF-PACK, NROFF-PACK-SCO,
##  BSD4.4 or NONE.
#### =()<MANPAGESTYLE		@<MANPAGESTYLE>@>()=
MANPAGESTYLE		SOURCE
##  Where various manpages should go
#### =()<MAN1			@<MAN1>@>()=
MAN1			/usr/news/man/man1
#### =()<MAN3			@<MAN3>@>()=
MAN3			/usr/news/man/man3
#### =()<MAN5			@<MAN5>@>()=
MAN5			/usr/news/man/man5
#### =()<MAN8			@<MAN8>@>()=
MAN8			/usr/news/man/man8
##  Ranlib command.  Use echo if you don't need ranlib.
#### =()<RANLIB			@<RANLIB>@>()=
RANLIB			ranlib
##  YACC (yet another config control?)
#### =()<YACC			@<YACC>@>()=
YACC			yacc
##  Ctags command.  Use echo if you don't have ctags.
#### =()<CTAGS			@<CTAGS>@>()=
CTAGS			ctags -t -w


##
##  2.  LOGGING LEVELS
##  Facility innd should log under.
#### =()<LOG_INN_SERVER		@<LOG_INN_SERVER>@>()=
LOG_INN_SERVER		LOG_NEWS
##  Facility all other programs should log under.
#### =()<LOG_INN_PROG		@<LOG_INN_PROG>@>()=
LOG_INN_PROG		LOG_NEWS
##  Flags to use in opening the logs; some programs add LOG_PID.
#### =()<L_OPENLOG_FLAGS		@<L_OPENLOG_FLAGS>@>()=
L_OPENLOG_FLAGS		(LOG_CONS | LOG_NDELAY)
##  Log a fatal error; program is about to exit.
#### =()<L_FATAL			@<L_FATAL>@>()=
L_FATAL			LOG_CRIT
##  Log an error that might mean one or more articles get lost.
#### =()<L_ERROR			@<L_ERROR>@>()=
L_ERROR			LOG_ERR
##  Informational notice, usually not worth caring about.
#### =()<L_NOTICE		@<L_NOTICE>@>()=
L_NOTICE		LOG_WARNING
##  A protocol trace.
#### =()<L_TRACE			@<L_TRACE>@>()=
L_TRACE			LOG_DEBUG
##  All incoming control commands (ctlinnd, etc).
#### =()<L_CC_CMD		@<L_CC_CMD>@>()=
L_CC_CMD		LOG_INFO


##
##  3.  OWNERSHIPS AND FILE MODES
##  Owner of articles and directories and _PATH_INNDDIR
#### =()<NEWSUSER			@<NEWSUSER>@>()=
NEWSUSER			news
##  Group, for same purpose
#### =()<NEWSGROUP		@<NEWSGROUP>@>()=
NEWSGROUP		news
##  Who gets email from news.daily and about control messages.
#### =()<NEWSMASTER		@<NEWSMASTER>@>()=
NEWSMASTER		usenet
##  Who gets email on the Path line?
#### =()<PATHMASTER		@<PATHMASTER>@>()=
PATHMASTER		not-for-mail
##  Umask to set.
#### =()<NEWSUMASK		@<NEWSUMASK>@>()=
NEWSUMASK		02
##  Mode that incoming articles are created under.
#### =()<ARTFILE_MODE		@<ARTFILE_MODE>@>()=
ARTFILE_MODE		0664
##  Mode that batch files are created under.
#### =()<BATCHFILE_MODE		@<BATCHFILE_MODE>@>()=
BATCHFILE_MODE		0664
##  Mode that directories are created under.
#### =()<GROUPDIR_MODE		@<GROUPDIR_MODE>@>()=
GROUPDIR_MODE		0775


##
##  4.  C LIBRARY DIFFERENCES
##  Use stdargs, varargs, or neither?  Pick VARARGS STDARGS or NONE.
##  You need vfprintf and vfsprintf if not NONE.
#### =()<VAR_STYLE		@<VAR_STYLE>@>()=
VAR_STYLE		STDARGS
##  If you don't have <string.h>, set this to "mystring.h"
#### =()<STR_HEADER		@<STR_HEADER>@>()=
STR_HEADER		<string.h>
##  If you don't have <memory.h>, set this to "mymemory.h"
#### =()<MEM_HEADER		@<MEM_HEADER>@>()=
MEM_HEADER		<memory.h>
##  What is a file offset?  MUST BE LONG FOR NOW.
#### =()<OFFSET_T		@<OFFSET_T>@>()=
OFFSET_T		long
##  What is the type of an object size? Usually size_t or unsigned int.
#### =()<SIZE_T			@<SIZE_T>@>()=
SIZE_T			size_t
##  What is the type of a passwd uid and gid, for use in chown(2)?
#### =()<UID_T			@<UID_T>@>()=
UID_T			uid_t
#### =()<GID_T			@<GID_T>@>()=
GID_T			gid_t
##  Type of a pid, for use in kill(2).
#### =()<PID_T			@<PID_T>@>()=
PID_T			pid_t
##  Generic pointer, used by memcpy, malloc, etc.  Usually char or void.
#### =()<POINTER			@<POINTER>@>()=
POINTER			void
##  Worst-case alignment, in order to shut lint up
#### =()<ALIGNPTR		@<ALIGNPTR>@>()=
ALIGNPTR		int
##  What should a signal handler return?  Usually int or void.
#### =()<SIGHANDLER		@<SIGHANDLER>@>()=
SIGHANDLER		void
##  Type of variables can be modified in a signal handler? sig_atomic_t
#### =()<SIGVAR			@<SIGVAR>@>()=
SIGVAR			sig_atomic_t
##  Function that returns no value, and a pointer to it.  Pick int or void
#### =()<FUNCTYPE		@<FUNCTYPE>@>()=
FUNCTYPE		void
##  Type of 32 bit unsigned integer.
#### =()<U_INT32_T			@<U_INT32_T>@>()=
U_INT32_T			unsigned int
##  Type of 32 bit signed integer.
#### =()<INT32_T			@<INT32_T>@>()=
INT32_T			int
##  Use BSD4.2 or Posix directory names?  Pick DIRENT or DIRECT.
#### =()<DIR_STYLE		@<DIR_STYLE>@>()=
DIR_STYLE		DIRENT
##  Use flock, lockf, or nothing to lock files?
##  Pick FLOCK, LOCKF, FCNTL, or NONE
#### =()<LOCK_STYLE		@<LOCK_STYLE>@>()=
LOCK_STYLE		FLOCK
##  Do you have <unistd.h>?  Pick DO or DONT
#### =()<HAVE_UNISTD		@<HAVE_UNISTD>@>()=
HAVE_UNISTD		DO
##  Do you have setbuffer?  Pick DO or DONT.
#### =()<HAVE_SETBUFFER		@<HAVE_SETBUFFER>@>()=
HAVE_SETBUFFER		DO
##  Do you have gettimeofday?  Pick DO or DONT.
#### =()<HAVE_GETTIMEOFDAY	@<HAVE_GETTIMEOFDAY>@>()=
HAVE_GETTIMEOFDAY	DO
##  Do you have setproctitle()?  Pick DO or DONT.
##  You may need to adjust LIBS for this.
#### =()<HAVE_SETPROCTITLE	@<HAVE_SETPROCTITLE>@>()=
HAVE_SETPROCTITLE	DONT
##  Do you have fchmod?  Pick DO or DONT.
#### =()<HAVE_FCHMOD		@<HAVE_FCHMOD>@>()=
HAVE_FCHMOD		DO
##  Do you have setsid()?  Pick DO or DONT.
#### =()<HAVE_SETSID		@<HAVE_SETSID>@>()=
HAVE_SETSID		DO
##  Does your (struct tm) have a tm_gmtoff field?  Pick DO or DONT.
#### =()<HAVE_TM_GMTOFF		@<HAVE_TM_GMTOFF>@>()=
HAVE_TM_GMTOFF		DONT
##  Does your (struct stat) have a st_blksize field?  Pick DO or DONT.
#### =()<HAVE_ST_BLKSIZE		@<HAVE_ST_BLKSIZE>@>()=
HAVE_ST_BLKSIZE		DO
##  Use waitpid instead of wait3?  Pick DO or DONT.
#### =()<HAVE_WAITPID		@<HAVE_WAITPID>@>()=
HAVE_WAITPID		DO
##  Use "union wait" instead of int?  Pick DO or DONT.
#### =()<USE_UNION_WAIT		@<USE_UNION_WAIT>@>()=
USE_UNION_WAIT		DO
##  How to fork?  Pick fork or vfork.
#### =()<FORK			@<FORK>@>()=
FORK			vfork
##  Do you have <vfork.h>?  Pick DO or DONT.
#### =()<HAVE_VFORK		@<HAVE_VFORK>@>()=
HAVE_VFORK		DO
##  Do you have symbolic links?  Pick DO or DONT.
#### =()<HAVE_SYMLINK		@<HAVE_SYMLINK>@>()=
HAVE_SYMLINK		DO
##  Do you have Unix-domain sockets?  Pick DO or DONT.
#### =()<HAVE_UNIX_DOMAIN	@<HAVE_UNIX_DOMAIN>@>()=
HAVE_UNIX_DOMAIN	DO
##  Does your AF_UNIX bind use sizeof for the socket size?  Pick DO or DONT.
#### =()<BIND_USE_SIZEOF		@<BIND_USE_SIZEOF>@>()=
BIND_USE_SIZEOF		DONT
##  How should close-on-exec be done?  Pick IOCTL or FCNTL.
#### =()<CLX_STYLE		@<CLX_STYLE>@>()=
CLX_STYLE		FCNTL
##  How should non-blocking I/O be done?  Pick IOCTL or FCNTL.
#### =()<NBIO_STYLE		@<NBIO_STYLE>@>()=
NBIO_STYLE		IOCTL
##  How should resource-totalling be done?  Pick RUSAGE or TIMES
#### =()<RES_STYLE		@<RES_STYLE>@>()=
RES_STYLE		TIMES
##  How to get number of available descriptors?
##  Pick GETDTAB, GETRLIMIT, SYSCONF, ULIMIT, or CONSTANT.
####  =()<FDCOUNT_STYLE		@<FDCOUNT_STYLE>@>()=
FDCOUNT_STYLE		GETRLIMIT
##  If greater than -1, then use [gs]etrlimit to set that many descriptors.
##  If -1, then no [gs]etrlimit calls are done.
#### =()<NOFILE_LIMIT		@<NOFILE_LIMIT>@>()=
NOFILE_LIMIT		1023
##  Do you need <time.h> as well as <sys/time.h>?  Pick DO or DONT.
#### =()<NEED_TIME		@<NEED_TIME>@>()=
NEED_TIME		DO
##  What predicate, if any, the <ctype.h> macros need
#### =()<CTYPE			@<CTYPE>@>()=
CTYPE			isXXXXX((c))
#CTYPE			((c) > 0 && isXXXXX((c)))
#CTYPE			isXXXXX((c))
##  What's the return type of abort?  Usually int or void.
#### =()<ABORTVAL		@<ABORTVAL>@>()=
ABORTVAL		void
##  What's the return type of alarm?  Usually int or unsigned int.
#### =()<ALARMVAL		@<ALARMVAL>@>()=
ALARMVAL		unsigned int
##  What's the return type of getpid?  Usually int or unsigned int.
#### =()<GETPIDVAL		@<GETPIDVAL>@>()=
GETPIDVAL		pid_t
##  What's the return type of sleep?  Usually int or unsigned int.
#### =()<SLEEPVAL		@<SLEEPVAL>@>()=
SLEEPVAL		unsigned int
##  What's the return type of  qsort?  Usually int or void.
#### =()<QSORTVAL		@<QSORTVAL>@>()=
QSORTVAL		void
##  What's the return type of lseek?  Usually long or off_t.
#### =()<LSEEKVAL		@<LSEEKVAL>@>()=
LSEEKVAL		off_t
##  What's the return type of free?  Usually int or void.
#### =()<FREEVAL			@<FREEVAL>@>()=
FREEVAL			void
##  What's the return type of exit?  Usually int or void.
##  (For gcc (not pedantic ANSI) use "volatile void" in EXITVAL and _EXITVAL.)
#### =()<EXITVAL			@<EXITVAL>@>()=
EXITVAL			void
##  What's the return type of _exit?  Usually int or void.
#### =()<_EXITVAL		@<_EXITVAL>@>()=
_EXITVAL		void


##
##  5.  C LIBRARY OMISSIONS
##  Possible values:
##	MISSING_MAN		strcasecmp.3 syslog.3
##	MISSING_SRC		strcasecmp.c syslog.c strerror.c getdtab.c
##	MISSING_OBJ		strcasecmp.o syslog.o strerror.o getdtab.c
##  getdtab has a getdtablesize() routine if you need it; see the lib
##  directory and Install.ms for others.
##  OSx systems should add $(OSXATTOBJ) to MISSING_OBJ.
#### =()<MISSING_MAN		@<MISSING_MAN>@>()=
MISSING_MAN		
#### =()<MISSING_SRC		@<MISSING_SRC>@>()=
MISSING_SRC		malloc.c getdtab.c
#### =()<MISSING_OBJ		@<MISSING_OBJ>@>()=
MISSING_OBJ		malloc.o getdtab.o


##
##  6.  MISCELLANEOUS CONFIG DATA
##
##  Use read/write to update the active file, or mmap?  Pick READ or MMAP.
#### =()<ACT_STYLE		@<ACT_STYLE>@>()=
ACT_STYLE		MMAP
##  Do you want mail notifications of bad control messages. DO or DONT
##  Setting it to do results in a lot of mail with the number of spammers
##  out there.
#### =()<MAIL_BADCONTROLS	@<MAIL_BADCONTROLS>@>()=
MAIL_BADCONTROLS	DONT
##  What type of pointer does mmap() manage? Normally ``caddr_t'' or ``void *''
##  or ``char *''
#### =()<MMAP_PTR		@<MMAP_PTR>@>()=
MMAP_PTR		void *
##  Should we msync when using mmap? Pick DO or DONT. Useful
##  with some slightly broken mmap implementations. (like HPUX and BSD/OS).
#### =()<MMAP_SYNC		@<MMAP_SYNC>@>()=
MMAP_SYNC		DONT
##  Should we call your msync() with 3 args? (addr,len,flags)
##  Choose DO or DONT.
#### =()<MSYNC_3_ARG		@<MSYNC_3_ARG>@>()=
MSYNC_3_ARG		DONT
##  Do clients use our NNTP-server-open routine, or the one in NNTP?
##  INND is nicer, but you must install inn.conf files everywhere; NNTP
##  is better if you already have lots of /usr/lib/news/server files.
##  Pick INND or NNTP.
#### =()<REM_STYLE		@<REM_STYLE>@>()=
REM_STYLE		INND
##  Should rnews save articles that the server rejects?  Pick DO or DONT.
#### =()<RNEWS_SAVE_BAD		@<RNEWS_SAVE_BAD>@>()=
RNEWS_SAVE_BAD		DONT
##  Should rnews log articles innd already has?  Pick SYSLOG, FILE, OR DONT.
#### =()<RNEWS_LOG_DUPS		@<RNEWS_LOG_DUPS>@>()=
RNEWS_LOG_DUPS		DONT
##  Look in _PATH_RNEWSPROGS for rnews unpackers?  Pick DO or DONT.
#### =()<RNEWSPROGS		@<RNEWSPROGS>@>()=
RNEWSPROGS		DO
##  Should rnews try the local host?  Pick DO or DONT.
#### =()<RNEWSLOCALCONNECT	@<RNEWSLOCALCONNECT>@>()=
RNEWSLOCALCONNECT	DO
##  Environment variable that has remote hostname for rnews.
#### =()<_ENV_UUCPHOST		@<_ENV_UUCPHOST>@>()=
_ENV_UUCPHOST		UU_MACHINE
##  Require posts to have under 50% inclusion (">") lines?  Pick DO OR DONT.
##  (This is only for inews and nnrpd.)
#### =()<CHECK_INCLUDED_TEXT	@<CHECK_INCLUDED_TEXT>@>()=
CHECK_INCLUDED_TEXT	DO
##  Put hosts in the inews Path header?  Pick DO or DONT.
#### =()<INEWS_PATH		@<INEWS_PATH>@>()=
INEWS_PATH		DO
##  Munge the gecos field of password entry?  Pick DO or DONT.
#### =()<MUNGE_GECOS		@<MUNGE_GECOS>@>()=
MUNGE_GECOS		DO
##  How many times to try to fork before giving up
#### =()<MAX_FORKS		@<MAX_FORKS>@>()=
MAX_FORKS		10
##  Largest acceptable article size; 0 allows any size
#### =()<MAX_ART_SIZE		@<MAX_ART_SIZE>@>()=
MAX_ART_SIZE		0
##  Value of dbzincore(FLAG) call in innd.  Pick 1 or 0.
#### =()<INND_DBZINCORE		@<INND_DBZINCORE>@>()=
INND_DBZINCORE		1
##  Should sub-processes get a nice(2) value?  Pick DO or DONT.
#### =()<INND_NICE_KIDS		@<INND_NICE_KIDS>@>()=
INND_NICE_KIDS		DO
##  Value for nice(2) call in innd.
#### =()<INND_NICE_VALUE		@<INND_NICE_VALUE>@>()=
INND_NICE_VALUE		-5
##  Null-terminated list of unknown commands to not log to syslog.
##	INND_QUIET_BADLIST	"xstream", "xfoo", NULL
#### =()<INND_QUIET_BADLIST	@<INND_QUIET_BADLIST>@>()=
INND_QUIET_BADLIST	NULL
##  Null-terminated set of illegal distribution patterns for local postings.
#### =()<BAD_DISTRIBS		@<BAD_DISTRIBS>@>()=
BAD_DISTRIBS		"*.*",NULL
##  Verify that the poster is the person doing the cancel?  Pick DO or DONT.
##  (Can't do this if cancel arrives before the article does, by the way,
##  in which case the early cancel will be ignored.)
#### =()<VERIFY_CANCELS		@<VERIFY_CANCELS>@>()=
VERIFY_CANCELS		DONT
##  Log "ctlinnd cancel" commands to syslog?  Pick DO or DONT.
#### =()<LOG_CANCEL_COMMANDS	@<LOG_CANCEL_COMMANDS>@>()=
LOG_CANCEL_COMMANDS	DONT
##  File unknown "to.*" groups into the "to" newsgroup?  Pick DO or DONT.
#### =()<MERGE_TO_GROUPS		@<MERGE_TO_GROUPS>@>()=
MERGE_TO_GROUPS		DONT
##  File articles in unknown newsgroups into junk?  Pick DO or DONT.
#### =()<WANT_TRASH		@<WANT_TRASH>@>()=
WANT_TRASH		DO
##  Record rejected articles in history?  Pick DO or DONT.
#### =()<REMEMBER_TRASH		@<REMEMBER_TRASH>@>()=
REMEMBER_TRASH		DONT
##  Check the linecount against the Lines header?  Pick DO or DONT.
#### =()<CHECK_LINECOUNT		@<CHECK_LINECOUNT>@>()=
CHECK_LINECOUNT		DONT
##  If checking, the error must be within LINECOUNT_FUZZ lines.
##  Five is number of .signature lines + 1.
#### =()<LINECOUNT_FUZZ		@<LINECOUNT_FUZZ>@>()=
LINECOUNT_FUZZ		5
##  Have innd throttle itself after this many I/O errors.
#### =()<IO_ERROR_COUNT		@<IO_ERROR_COUNT>@>()=
IO_ERROR_COUNT		50
##  Default value for ctlinnd -t flag; use 0 to wait and poll.
#### =()<CTLINND_TIMEOUT		@<CTLINND_TIMEOUT>@>()=
CTLINND_TIMEOUT		0
##  Flush logs if we go this long with no I/O.
#### =()<DEFAULT_TIMEOUT		@<DEFAULT_TIMEOUT>@>()=
DEFAULT_TIMEOUT		300
##  INND closes channel if inactive this long (seconds).
#### =()<PEER_TIMEOUT		@<PEER_TIMEOUT>@>()=
PEER_TIMEOUT		(1 * 60 * 60)
##  NNRP exits if first command doesn't arrive within this time (seconds).
#### =()<INIT_CLIENT_TIMEOUT	@<INIT_CLIENT_TIMEOUT>@>()=
INIT_CLIENT_TIMEOUT	30
##  NNRP exits if inactive for this long (seconds).
#### =()<CLIENT_TIMEOUT		@<CLIENT_TIMEOUT>@>()=
CLIENT_TIMEOUT		(20 * 60)
##  Allow nnrpd readers when paused or throttled?  Pick DO or DONT.
#### =()<ALLOW_READERS		@<ALLOW_READERS>@>()=
ALLOW_READERS		DO
##  Refuse newsreader connections if load is higher then this; -1 disables.
#### =()<NNRP_LOADLIMIT		@<NNRP_LOADLIMIT>@>()=
NNRP_LOADLIMIT		16
##  Don't readdir() spool dir if same group within this many secs.
#### =()<NNRP_RESCAN_DELAY	@<NNRP_RESCAN_DELAY>@>()=
NNRP_RESCAN_DELAY	60
##  Do gethostbyaddr on client adresses in nnrp?   Pick DO or DONT.
##  (If DONT, then use only IP addresses in hosts.nnrp)
#### =()<NNRP_GETHOSTBYADDR	@<NNRP_GETHOSTBYADDR>@>()=
NNRP_GETHOSTBYADDR	DO
##  How many Message-ID retrievals until nnrpd does a dbzincore?  Set
##  to -1 to never do incore.
#### =()<NNRP_DBZINCORE_DELAY	@<NNRP_DBZINCORE_DELAY>@>()=
NNRP_DBZINCORE_DELAY	40
##  Strip Sender from posts that didn't authenticate?  Pick DO or DONT.
#### =()<NNRP_AUTH_SENDER	@<NNRP_AUTH_SENDER>@>()=
NNRP_AUTH_SENDER	DO
##  Do you want to make life easy for peers to pull feeds from you (it's
##  harder on your machine). Pick DO or DONT. With DONT, you get a small
##  sleep inserted before each ARTICLE command is processed. (With
##  apologies to the Australians in the audience).
#### =()<LIKE_PULLERS		@<LIKE_PULLERS>@>()=
LIKE_PULLERS		DO
##  Allow the NEWNEWS NNTP command?   Pick DO or DONT.
##  (RFC 977 says you should; your server performance may not agree...)
#### =()<ALLOW_NEWNEWS		@<ALLOW_NEWNEWS>@>()=
ALLOW_NEWNEWS		DONT
##  How many read/write failures until channel is put to sleep or closed?
#### =()<BAD_IO_COUNT		@<BAD_IO_COUNT>@>()=
BAD_IO_COUNT		5
##  Multiplier for sleep in EWOULDBLOCK writes (seconds).
#### =()<BLOCK_BACKOFF		@<BLOCK_BACKOFF>@>()=
BLOCK_BACKOFF		(2 * 60)
##  How many article-writes between active and history updates?
#### =()<ICD_SYNC_COUNT		@<ICD_SYNC_COUNT>@>()=
ICD_SYNC_COUNT		100
##  Tell resolver _res.options to be fast?  Pick DO or DONT.
#### =()<FAST_RESOLV		@<FAST_RESOLV>@>()=
FAST_RESOLV		DONT
##  Drop articles that were posted this many days ago.
#### =()<DEFAULT_CUTOFF		@<DEFAULT_CUTOFF>@>()=
DEFAULT_CUTOFF		7
##  Maximum number of incoming NNTP connections.
#### =()<DEFAULT_CONNECTIONS	@<DEFAULT_CONNECTIONS>@>()=
DEFAULT_CONNECTIONS	50
##  Wait this many seconds before channel restarts.
#### =()<CHANNEL_RETRY_TIME	@<CHANNEL_RETRY_TIME>@>()=
CHANNEL_RETRY_TIME	(5 * 60)
##  Wait this many seconds before seeing if pause is ended.
#### =()<PAUSE_RETRY_TIME	@<PAUSE_RETRY_TIME>@>()=
PAUSE_RETRY_TIME	(5 * 60)
##  Wait this many seconds between noticing inactive channels.
#### =()<CHANNEL_INACTIVE_TIME	@<CHANNEL_INACTIVE_TIME>@>()=
CHANNEL_INACTIVE_TIME	(10 * 60)
##  Put nntplink info (filename) into the log?
#### =()<NNTPLINK_LOG		@<NNTPLINK_LOG>@>()=
NNTPLINK_LOG		DONT
##  Put article size into the log?
#### =()<LOG_SIZE		@<LOG_SIZE>@>()=
LOG_SIZE		DO
##  Log by host IP address, rather than from Path line?
#### =()<IPADDR_LOG		@<IPADDR_LOG>@>()=
IPADDR_LOG		DO
##  Log NNTP activity after this many articles.
#### =()<NNTP_ACTIVITY_SYNC	@<NNTP_ACTIVITY_SYNC>@>()=
NNTP_ACTIVITY_SYNC	400
##  Free buffers bigger than this when we're done with them.
#### =()<BIG_BUFFER		@<BIG_BUFFER>@>()=
BIG_BUFFER		(2 * START_BUFF_SIZE)
##  A general small buffer.
#### =()<SMBUF			@<SMBUF>@>()=
SMBUF			256
##  Buffer for a single article name.
#### =()<MAXARTFNAME		@<MAXARTFNAME>@>()=
MAXARTFNAME		10
##  Buffer for a single pathname in the spool directory.
#### =()<SPOOLNAMEBUFF		@<SPOOLNAMEBUFF>@>()=
SPOOLNAMEBUFF		512
##  Maximum size of a single header.
#### =()<MAXHEADERSIZE		@<MAXHEADERSIZE>@>()=
MAXHEADERSIZE		1024
##  Byte limit on locally-posted articles; 0 to disable the check.
#### =()<LOCAL_MAX_ARTSIZE	@<LOCAL_MAX_ARTSIZE>@>()=
LOCAL_MAX_ARTSIZE	0
##  Default number of bytes to hold in memory when buffered.
#### =()<SITE_BUFFER_SIZE	@<SITE_BUFFER_SIZE>@>()=
SITE_BUFFER_SIZE	(256 * 1024)
##  Do you have uustat, or just uuq?  Pick DO or DONT
#### =()<HAVE_UUSTAT		@<HAVE_UUSTAT>@>()=
HAVE_UUSTAT		DO
##  Should INN do some setsockopts on network connections. Pick DO or DONT.
##  Some versions of Solaris should set to DONT (pre 2.4 it seems)
#### =()<SET_SOCKOPT		@<SET_SOCKOPT>@>()=
SET_SOCKOPT		DO


##
##  7.  PATHS TO COMMON PROGRAMS
##  Where the raison d'etre for this distribution lives.
#### =()<_PATH_INND		@<_PATH_INND>@>()=
_PATH_INND		/usr/news/bin/innd
##  Where the optional front-end that exec's innd lives.
#### =()<_PATH_INNDSTART		@<_PATH_INNDSTART>@>()=
_PATH_INNDSTART		/usr/news/bin/inndstart
##  Where news boot-up script should be installed.
#### =()<_PATH_NEWSBOOT		@<_PATH_NEWSBOOT>@>()=
_PATH_NEWSBOOT		/usr/news/bin/rc.news
##  Where sendmail, or a look-alike, lives.
##  The -t is optional and says to read message for recipients
#### =()<_PATH_SENDMAIL		@<_PATH_SENDMAIL>@>()=
_PATH_SENDMAIL		/usr/sbin/sendmail -t
##  Where the shell is.
#### =()<_PATH_SH		@<_PATH_SH>@>()=
_PATH_SH		/bin/sh
##  Where the compress program lives.
#### =()<_PATH_COMPRESS		@<_PATH_COMPRESS>@>()=
_PATH_COMPRESS		/usr/bin/compress
##  What extension your compress appends
#### =()<_PATH_COMPRESSEXT	@<_PATH_COMPRESSEXT>@>()=
_PATH_COMPRESSEXT	.Z
##  Where egrep lives (you might need the FSF one; see scanlogs)
#### =()<_PATH_EGREP		@<_PATH_EGREP>@>()=
_PATH_EGREP		/usr/bin/egrep
##  Where perl lives
#### =()<_PATH_PERL		@<_PATH_PERL>@>()=
_PATH_PERL		/usr/bin/perl
##  Where awk lives
#### =()<_PATH_AWK		@<_PATH_AWK>@>()=
_PATH_AWK		/usr/bin/awk
##  Where sed lives (you might need the FSF one)
#### =()<_PATH_SED		@<_PATH_SED>@>()=
_PATH_SED		/usr/bin/sed
##  Where sort lives (you may want the FSF one).
#### =()<_PATH_SORT		@<_PATH_SORT>@>()=
_PATH_SORT		/usr/bin/sort
##  Where inews lives.
#### =()<_PATH_INEWS		@<_PATH_INEWS>@>()=
_PATH_INEWS		/usr/news/bin/inews
##  Where rnews lives.
#### =()<_PATH_RNEWS		@<_PATH_RNEWS>@>()=
_PATH_RNEWS		/usr/news/bin/rnews
##  Where generic authentication programs live.
#### =()<_PATH_AUTHDIR		@<_PATH_AUTHDIR>@>()=
_PATH_AUTHDIR		/usr/news/bin/auth
##  Where the NNRP server lives.
#### =()<_PATH_NNRPD		@<_PATH_NNRPD>@>()=
_PATH_NNRPD		/usr/news/bin/nnrpd
##  The path of the process run when an unknown host connects to innd.
##  Usually the same as _PATH_NNRPD, but may be, e.g., the path to
##  nntpd from the reference implementation.
#### =()<_PATH_NNTPD		@<_PATH_NNTPD>@>()=
_PATH_NNTPD		/usr/news/bin/nnrpd
##  Where the NNQR server lives.  Make same as _PATH_NNRPD for now
#### =()<_PATH_NNQRD		@<_PATH_NNRPD>@>()=
_PATH_NNQRD		/usr/news/bin/nnrpd
##  Where most other programs live.
##  See also _PATH_RNEWSPROGS and _PATH_CONTROLPROGS, below.
#### =()<_PATH_NEWSBIN		@<_PATH_NEWSBIN>@>()=
_PATH_NEWSBIN		/usr/news/bin
##  Where temporary files live on the server
#### =()<_PATH_TMP		@<_PATH_TMP>@>()=
_PATH_TMP		/var/tmp
##  Command to send mail (with -s "subject" allowed)
#### =()<_PATH_MAILCMD		@<_PATH_MAILCMD>@>()=
_PATH_MAILCMD		/usr/bin/Mail
##  Where scripts should have shlock create locks.
#### =()<_PATH_LOCKS		@<_PATH_LOCKS>@>()=
_PATH_LOCKS		/var/news/locks
##  Where your GNU gzip binary is (for rnews to run on gzipped batches).
#### =()<_PATH_GZIP		@<_PATH_GZIP>@>()=
_PATH_GZIP		/bin/gzip

##
##  8.  PATHS RELATED TO THE SPOOL DIRECTORY
##  Spool directory, where articles live.
#### =()<_PATH_SPOOL		@<_PATH_SPOOL>@>()=
_PATH_SPOOL		/var/news/spool/articles
##  Spool directory where overview data lives.
#### =()<_PATH_OVERVIEWDIR	@<_PATH_OVERVIEWDIR>@>()=
_PATH_OVERVIEWDIR	/var/news/etc/oview
##  Name of overview file within its spool directory.
#### =()<_PATH_OVERVIEW		@<_PATH_OVERVIEW>@>()=
_PATH_OVERVIEW		.overview
##  Where rnews spools its input.
#### =()<_PATH_SPOOLNEWS		@<_PATH_SPOOLNEWS>@>()=
_PATH_SPOOLNEWS		/var/news/spool/in.coming
##  Where rnews creates temporary files until finished
#### =()<_PATH_SPOOLTEMP		@<_PATH_SPOOLTEMP>@>()=
_PATH_SPOOLTEMP		/var/tmp
##  Where rnews puts bad input.
#### =()<_PATH_BADNEWS		@<_PATH_BADNEWS>@>()=
_PATH_BADNEWS		/var/news/spool/in.coming/bad
##  Where rnews puts bad input, relative to _PATH_SPOOLNEWS.
#### =()<_PATH_RELBAD		@<_PATH_RELBAD>@>()=
_PATH_RELBAD		bad
## Where the XBATCH command should put the batches. Normally same as
## _PATH_SPOOLNEWS so that 'rnews -U' can find it.
#### =()<_PATH_XBATCHES		@<_PATH_XBATCHES>@>()=
_PATH_XBATCHES		/var/news/spool/in.coming


##
##  9.  EXECUTION PATHS FOR INND AND RNEWS
##  Pathname where dups are logged if RNEWS_LOG_DUPS is FILE.
#### =()<_PATH_RNEWS_DUP_LOG	@<_PATH_RNEWS_DUP_LOG>@>()=
_PATH_RNEWS_DUP_LOG	/dev/null
##  Rnews may execute any program in this directory; see RNEWSPROGS.
#### =()<_PATH_RNEWSPROGS	@<_PATH_RNEWSPROGS>@>()=
_PATH_RNEWSPROGS	/usr/news/bin/rnews.libexec
##  Path to control messages scripts.
#### =()<_PATH_CONTROLPROGS	@<_PATH_CONTROLPROGS>@>()=
_PATH_CONTROLPROGS	/usr/news/bin/control
##  Default "unknown/illegal" control script, within _PATH_CONTROLPROGS.
#### =()<_PATH_BADCONTROLPROG	@<_PATH_BADCONTROLPROG>@>()=
_PATH_BADCONTROLPROG	default


##
##  10.  SOCKETS CREATED BY INND OR CLIENTS
#### =()<_PATH_INNDDIR		@<_PATH_INNDDIR>@>()=
_PATH_INNDDIR		/var/news/run
##  Unix-domain stream socket that rnews connects to.
#### =()<_PATH_NNTPCONNECT	@<_PATH_NNTPCONNECT>@>()=
_PATH_NNTPCONNECT	/var/news/run/nntpin
##  Unix-domain datagram socket that ctlinnd to.
#### =()<_PATH_NEWSCONTROL	@<_PATH_NEWSCONTROL>@>()=
_PATH_NEWSCONTROL	/var/news/run/control
##  Temporary socket created by ctlinnd; run through mktemp
#### =()<_PATH_TEMPSOCK		@<_PATH_TEMPSOCK>@>()=
_PATH_TEMPSOCK		/var/news/run/ctlinndXXXXXX


##
##  11.  LOG AND CONFIG FILES
##  Shell script that sets most of these as shell vars
#### =()<_PATH_SHELLVARS		@<_PATH_SHELLVARS>@>()=
_PATH_SHELLVARS		/var/news/etc/innshellvars
##  Perl script that sets most of these as perl variables
#### =()<_PATH_PERL_SHELLVARS	@<_PATH_PERL_SHELLVARS>@>()=
_PATH_PERL_SHELLVARS	/var/news/etc/innshellvars.pl
##  TCL script that sets most of these as tcl variables
#### =()<_PATH_TCL_SHELLVARS	@<_PATH_TCL_SHELLVARS>@>()=
_PATH_TCL_SHELLVARS	/var/news/etc/innshellvars.tcl
##  csh script that sets most of these as csh variables
#### =()<_PATH_CSH_SHELLVARS	@<_PATH_CSH_SHELLVARS>@>()=
_PATH_CSH_SHELLVARS	/var/news/etc/innshellvars.csh
##  Where most config and data files are usually stored; not required
##  to the home directory of NEWSUSER.
#### =()<_PATH_NEWSLIB		@<_PATH_NEWSLIB>@>()=
_PATH_NEWSLIB		/var/news/etc
## The group owner of the rnews program. Usually uucp.
#### =()<RNEWS_GROUP		@<RNEWS_GROUP>@>()=
RNEWS_GROUP		uucp
##  The server's log file.
#### =()<_PATH_LOGFILE		@<_PATH_LOGFILE>@>()=
_PATH_LOGFILE		/var/log/news/news
##  The server's error log file.
#### =()<_PATH_ERRLOG		@<_PATH_ERRLOG>@>()=
_PATH_ERRLOG		/var/log/news/errlog
##  Where most sylog log files go; see also scanlogs, innstat, etc.
#### =()<_PATH_MOST_LOGS		@<_PATH_MOST_LOGS>@>()=
_PATH_MOST_LOGS		/var/log/news
##  How many generates of log files to keep.
#### =()<LOG_CYCLES		@<LOG_CYCLES>@>()=
LOG_CYCLES		3
##  Text value of the server's pid.
#### =()<_PATH_SERVERPID		@<_PATH_SERVERPID>@>()=
_PATH_SERVERPID		/var/news/run/innd.pid
##  The newsfeeds file, on the server host.
#### =()<_PATH_NEWSFEEDS		@<_PATH_NEWSFEEDS>@>()=
_PATH_NEWSFEEDS		/var/news/etc/newsfeeds
##  The article history database, on the server host.
#### =()<_PATH_HISTORY		@<_PATH_HISTORY>@>()=
_PATH_HISTORY		/var/news/etc/history
##  File listing the sites that feed us news.
#### =()<_PATH_INNDHOSTS		@<_PATH_INNDHOSTS>@>()=
_PATH_INNDHOSTS		/var/news/etc/hosts.nntp
##  The active file, on the server host.
#### =()<_PATH_ACTIVE		@<_PATH_ACTIVE>@>()=
_PATH_ACTIVE		/var/news/etc/active
##  A temporary active file, for writing on the server host.
#### =()<_PATH_NEWACTIVE		@<_PATH_NEWACTIVE>@>()=
_PATH_NEWACTIVE		/var/news/etc/active.tmp
##  An old active file on the server host.
#### =()<_PATH_OLDACTIVE		@<_PATH_OLDACTIVE>@>()=
_PATH_OLDACTIVE		/var/news/etc/active.old
##  The log of when groups are created.
#### =()<_PATH_ACTIVETIMES	@<_PATH_ACTIVETIMES>@>()=
_PATH_ACTIVETIMES	/var/news/etc/active.times
##  Where batch files are located.
#### =()<_PATH_BATCHDIR		@<_PATH_BATCHDIR>@>()=
_PATH_BATCHDIR		/var/news/spool/out.going
##  Where archives are kept.
#### =()<_PATH_ARCHIVEDIR	@<_PATH_ARCHIVEDIR>@>()=
_PATH_ARCHIVEDIR	/var/news/spool/archive
##  Where NNRP distributions file is
#### =()<_PATH_NNRPDIST		@<_PATH_NNRPDIST>@>()=
_PATH_NNRPDIST		/var/news/etc/distributions
##  Where the NNRP automatic subscriptions file is
#### =()<_PATH_NNRPSUBS		@<_PATH_NNRPSUBS>@>()=
_PATH_NNRPSUBS		/var/news/etc/subscriptions
##  Where the default Distribution assignments file is
#### =()<_PATH_DISTPATS		@<_PATH_DISTPATS>@>()=
_PATH_DISTPATS		/var/news/etc/distrib.pats
#### =()<_PATH_NEWSGROUPS	@<_PATH_NEWSGROUPS>@>()=
_PATH_NEWSGROUPS	/var/news/etc/newsgroups
##  File where client configuration parameters can be read.
#### =()<_PATH_CONFIG		@<_PATH_CONFIG>@>()=
_PATH_CONFIG		/var/news/etc/inn.conf
##  The possible active file, on clients (NFS-mounted, e.g.).
#### =()<_PATH_CLIENTACTIVE	@<_PATH_CLIENTACTIVE>@>()=
_PATH_CLIENTACTIVE	/var/news/etc/active
##  A temporary file, for client inews to use.
#### =()<_PATH_TEMPACTIVE	@<_PATH_TEMPACTIVE>@>()=
_PATH_TEMPACTIVE	/var/tmp/activeXXXXXX
##  Where to mail to the moderators.
#### =()<_PATH_MODERATORS	@<_PATH_MODERATORS>@>()=
_PATH_MODERATORS	/var/news/etc/moderators
##  A temporary file, for client inews to use.
#### =()<_PATH_TEMPMODERATORS	@<_PATH_TEMPMODERATORS>@>()=
_PATH_TEMPMODERATORS	/var/tmp/moderatorsXXXXXX
##  Where NNTP puts the name of the server.
#### =()<_PATH_SERVER		@<_PATH_SERVER>@>()=
_PATH_SERVER		/var/news/etc/server
##  File with name/password for all remote connections.
#### =()<_PATH_NNTPPASS		@<_PATH_NNTPPASS>@>()=
_PATH_NNTPPASS		/var/news/etc/passwd.nntp
##  NNRP access file.
#### =()<_PATH_NNRPACCESS	@<_PATH_NNRPACCESS>@>()=
_PATH_NNRPACCESS	/var/news/etc/nnrp.access
##  Default expire control file.
#### =()<_PATH_EXPIRECTL		@<_PATH_EXPIRECTL>@>()=
_PATH_EXPIRECTL		/var/news/etc/expire.ctl
##  Prolog to parse control scripts
#### =()<_PATH_PARSECTL		@<_PATH_PARSECTL>@>()=
_PATH_PARSECTL		/var/news/etc/parsecontrol
##  Access control file for control scripts.
#### =()<_PATH_CONTROLCTL	@<_PATH_CONTROLCTL>@>()=
_PATH_CONTROLCTL	/var/news/etc/control.ctl
##  Innwatch control file.
#### =()<_PATH_CTLWATCH		@<_PATH_CTLWATCH>@>()=
_PATH_CTLWATCH		/var/news/etc/innwatch.ctl
##  Where innwatch writes its own pid.
#### =()<_PATH_WATCHPID		@<_PATH_WATCHPID>@>()=
_PATH_WATCHPID		/var/news/run/innwatch.pid
##  Where innwatch writes status when it gets an interrupt
#### =()<_PATH_INNWSTATUS	@<_PATH_INNWSTATUS>@>()=
_PATH_INNWSTATUS	/var/news/run/innwatch.status
##  Format of news overview database
#### =()<_PATH_SCHEMA		@<_PATH_SCHEMA>@>()=
_PATH_SCHEMA		/var/news/etc/overview.fmt


##
##  12.  INNWATCH CONFIGURATION
##  Load average (* 100) at which innd should be paused.
#### =()<INNWATCH_PAUSELOAD	@<INNWATCH_PAUSELOAD>@>()=
INNWATCH_PAUSELOAD	1500
##  Load average (* 100) at which innd should be throttled.
#### =()<INNWATCH_HILOAD		@<INNWATCH_HILOAD>@>()=
INNWATCH_HILOAD		2000
##  Load average (* 100) at which to restart innd (pause/throttle undone).
#### =()<INNWATCH_LOLOAD		@<INNWATCH_LOLOAD>@>()=
INNWATCH_LOLOAD		1000
##  Space, in df output units, at which to throttle innd on _PATH_SPOOL 
##  or _PATH_OVERVIEWDIR.
#### =()<INNWATCH_SPOOLSPACE	@<INNWATCH_SPOOLSPACE>@>()=
INNWATCH_SPOOLSPACE	8000
##  Space, in df output units, at which to throttle innd on _PATH_BATCHDIR.
#### =()<INNWATCH_BATCHSPACE	@<INNWATCH_BATCHSPACE>@>()=
INNWATCH_BATCHSPACE	800
##  Space, in df output units, at which to throttle innd on _PATH_NEWSLIB.
#### =()<INNWATCH_LIBSPACE	@<INNWATCH_LIBSPACE>@>()=
INNWATCH_LIBSPACE	25000
##  Number of inodes at which to throttle innd on _PATH_SPOOL.
#### =()<INNWATCH_SPOOLNODES	@<INNWATCH_SPOOLNODES>@>()=
INNWATCH_SPOOLNODES	200
##  How long to sleep between innwatch iterations.
#### =()<INNWATCH_SLEEPTIME	@<INNWATCH_SLEEPTIME>@>()=
INNWATCH_SLEEPTIME	600
##  How inn (not just innwatch anymore) gets disk space usage 
##  (SVR4 machine would probably use /usr/ucb/df)
#### =()<INNWATCH_DF		@<INNWATCH_DF>@>()=
INNWATCH_DF		/bin/df
##  Field number of INNWATCH_DF (with -i) output that gives free
##  inodes (starting at 1).
#### =()<INNWATCH_INODES		@<INNWATCH_INODES>@>()=
INNWATCH_INODES		4
##  Field number of INNWATCH_DF output that gives the free block count.
##### =()<INNWATCH_BLOCKS		@<INNWATCH_BLOCKS>@>()=
INNWATCH_BLOCKS		4



##
##  13.  TCL Configuration
##  Do you want TCL support?  Pick DO or DONT
#### =()<TCL_SUPPORT		@<TCL_SUPPORT>@>()=
TCL_SUPPORT		DONT
##  Where your tcl header file live. Blank if no TCL
### =()<TCL_INC		@<TCL_INC>@>()=
TCL_INC		
# TCL_INC		-I/usr/local/include
##  How do you get the TCL library?  Probably -ltcl -lm, blank if no TCL
#### =()<TCL_LIB		@<TCL_LIB>@>()=
TCL_LIB		
# TCL_LIB		-ltcl -lm
##  TCL Startup File. Should probably be prefixed with the same value as
##  _PATH_CONTROLPROGS. 
#### =()<_PATH_TCL_STARTUP	@<_PATH_TCL_STARTUP>@>()=
_PATH_TCL_STARTUP	/usr/news/bin/control/startup.tcl
##  TCL Filter File. Should probably be prefixed with the same value as
##  _PATH_CONTROLPROGS.
#### =()<_PATH_TCL_FILTER	@<_PATH_TCL_FILTER>@>()=
_PATH_TCL_FILTER	/usr/news/bin/control/filter.tcl


##
##  14. PGP Configuration
##

## Do you want PGP verification of control messages? Pick DO or DONT
## If you change this then you need to fiddle with control.ctl.
## Setting it DONT is a really bad idea with all the miscreants out there...
#### =()<WANT_PGPVERIFY		@<WANT_PGPVERIFY>@>()=
WANT_PGPVERIFY		DO
##  PGP binary.
#### =()<_PATH_PGP		@<_PATH_PGP>@>()=
_PATH_PGP		/usr/local/bin/pgp

##
##  15. Local Configuration
##

##  Home of the NEWSUSER
#### =()<_PATH_NEWSHOME		@<_PATH_NEWSHOME>@>()=
_PATH_NEWSHOME		/usr/news


##
## 16. Actsync Configuration.
##

##  Host to synchoronize active file with (see actsync and actsyncd manpages).
#### =()<ACTSYNC_HOST		@<ACTSYNC_HOST>@>()=
ACTSYNC_HOST		news.foo.bar.com
##  Flags actsyncd is to pass to actsync.
#### =()<ACTSYNC_FLAGS		@<ACTSYNC_FLAGS>@>()=
ACTSYNC_FLAGS		-v 2 -q 2 -b 0 -d 0 -g 7 -s 79 -t 2
## Actsyncd config file.
#### =()<_PATH_ACTSYNC_CFG	@<_PATH_ACTSYNC_CFG>@>()=
_PATH_ACTSYNC_CFG	/var/news/etc/actsync.cfg
## Actsyncd ignore file.
#### =()<_PATH_ACTSYNC_IGN	@<_PATH_ACTSYNC_IGN>@>()=
_PATH_ACTSYNC_IGN	/var/news/etc/actsync.ign



##  17.  Perl Configuration
##  Do you want Perl support?  Pick DO or DONT
#### =()<PERL_SUPPORT		@<PERL_SUPPORT>@>()=
PERL_SUPPORT		DONT
##  How do you get the PERL libraries?  Probably -lperl -lm, blank if no PERL
#### =()<PERL_LIB	@<PERL_LIB>@>()=
PERL_LIB	
#PERL_LIB	-L/usr/local/gnu/lib/perl5/i386-bsdos/5.003/CORE -lperl -lm
##  Core directory (includes, libs). See perlembed(1)
#### =()<PERL_INC	@<PERL_INC>@>()=
PERL_INC	
#PERL_INC		-I/usr/local/gnu/lib/perl5/i386-bsdos/5.003/CORE
##  Perl Filter Files. Should probably be prefixed with the same value as
##  _PATH_CONTROLPROGS.
#### =()<_PATH_PERL_STARTUP_INND		@<_PATH_PERL_STARTUP_INND>@>()=
_PATH_PERL_STARTUP_INND		/usr/news/bin/control/startup_innd.pl
#### =()<_PATH_PERL_FILTER_INND		@<_PATH_PERL_FILTER_INND>@>()=
_PATH_PERL_FILTER_INND		/usr/news/bin/control/filter_innd.pl
#### =()<_PATH_PERL_FILTER_NNRPD		@<_PATH_PERL_FILTER_NNRPD>@>()=
_PATH_PERL_FILTER_NNRPD		/usr/news/bin/control/filter_nnrpd.pl

----=_339fa94d27155633002c52519.MFSBCHJLHS
Content-Type: text/plain; charset=us-ascii; name=memcpy-patch-2_0_21.txt
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=memcpy-patch-2_0_21.txt

Index: linux/arch/i386/config.in
diff -u linux/arch/i386/config.in:1.1.1.41 linux/arch/i386/config.in:1.24
--- linux/arch/i386/config.in:1.1.1.41	Mon May 13 12:08:17 1996
+++ linux/arch/i386/config.in	Mon May 13 13:01:33 1996
@@ -43,6 +43,11 @@
 	 486		CONFIG_M486	\
 	 Pentium	CONFIG_M586	\
 	 PPro		CONFIG_M686" Pentium
+if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
+  if [ "$CONFIG_M586" = "y" ]; then
+    bool 'Use Pentium-optimized copy routine' CONFIG_M586_COPY y
+  fi
+fi
 endmenu
 
 source drivers/block/Config.in
Index: linux/arch/i386/lib/Makefile
diff -u linux/arch/i386/lib/Makefile:1.1.1.3 linux/arch/i386/lib/Makefile:1.2
--- linux/arch/i386/lib/Makefile:1.1.1.3	Mon Sep  4 17:37:13 1995
+++ linux/arch/i386/lib/Makefile	Wed Sep  6 14:27:31 1995
@@ -13,4 +13,8 @@
 L_TARGET = lib.a
 L_OBJS  = checksum.o semaphore.o
 
+ifdef CONFIG_M586_COPY
+L_OBJS += copy.o
+endif
+
 include $(TOPDIR)/Rules.make
Index: linux/arch/i386/lib/copy.c
diff -u /dev/null linux/arch/i386/lib/copy.c:1.15
--- /dev/null	Tue Jun 11 22:06:11 1996
+++ linux/arch/i386/lib/copy.c	Tue Jun 11 21:41:41 1996
@@ -0,0 +1,344 @@
+/*
+ * copy.c -- fast memcpy routines for Pentium using FPU
+ * Copyright (c) 1995 Robert Krawitz <rlk@tiac.net>
+ * May be used and redistributed under the terms of the GNU Public License
+ */
+
+#include <sys/types.h>
+
+#define CACHELINE 32
+#define CACHEMASK (CACHELINE - 1)
+#define BIGMASK (~255)
+#define SMALLMASK (~31)
+
+/*
+ * In zero_chunk only st(0) is modified. It should be sufficient
+ * to save only 387-environment and st(0).
+ */
+#define USE_FSTENV 1
+
+/*
+ * Clearing and restoring the TS bit in the cr0 register fixes a memory
+ * corruption bug, per Gerhard Koerting
+ * <G.Koerting@koerting.techem.ruhr-uni-bochum.de>
+ *
+ * Function must return its first argument, as memset does.
+ * Fixed by Regis Duchesne, at VIA, ECP, France <regis@via.ecp.fr>
+ */
+
+void *
+___zero_chunk (void *_to, size_t _bytes)
+{
+  unsigned long temp0, temp1;
+  register unsigned long to asm("di") = (unsigned long)_to;
+  register unsigned long bytes asm ("dx") = (unsigned long)_bytes;
+#ifdef USE_FSTENV
+  char save[42];
+#else
+  char save[108];
+#endif
+  unsigned long zbuf[2]={0,0};
+  temp0 = to & 7;
+  if (temp0) {
+     bytes -= temp0;
+     asm __volatile__ (
+        "cld\n\t"
+        "rep; stosb\n\t"
+         : "=D" (to)
+         : "D" (to), "a" (0), "c" (temp0)
+         : "cx" );
+  }
+  asm __volatile__ (
+       "shrl $3, %0\n\t"
+#ifdef USE_FSTENV
+       "fstenv %4\n\t"
+       "fstpt 32+%4\n\t"
+#else
+       "fsave %4\n\t"
+#endif
+       "movl (%1), %2\n\t"
+       "fildq %3\n"
+       "2:\n\t"
+       "fstl (%1)\n\t"
+       "addl $8, %1\n\t"
+       "decl %0\n\t"
+       "jne 2b\n\t"
+#ifdef USE_FSTENV
+       "fstpl %%st\n\t"
+       "fldt 32+%4\n\t"
+       "fldenv %4\n\t"
+#else
+       "frstor %4\n\t"
+#endif
+       : "=&r" (temp0), "=&r" (to), "=&r" (temp1)
+       : "m" (*(char *)zbuf), "m" (*(char *)save), "0" (bytes), "1" (to)
+       );
+   bytes &= 7;
+   if (bytes) {
+      asm __volatile__ (
+        "shrl $2, %%ecx\n\t"
+        "cld\n\t"
+        "rep ; stosl\n\t"
+        "testb $2,%%dl\n\t"
+        "je 111f\n\t"
+        "stosw\n"
+        "111:\ttestb $1,%%dl\n\t"
+        "je 112f\n\t"
+        "stosb\n"
+        "112:"
+        : "=D" (to)
+        : "D" (to), "a" (0), "c" (bytes), "d" (bytes)
+        : "cx","memory");
+    }
+  return _to;
+}
+
+void *
+__memcpy_g (char *_to, const char *_from, size_t _bytes)
+{
+  register unsigned long from asm ("si") = (unsigned long)_from;
+  register unsigned long to   asm ("di") = (unsigned long)_to;
+  register unsigned long bytes asm ("dx") = (unsigned long)_bytes;
+  if (bytes >= 1024) {
+     unsigned long temp0, temp1;
+     char save[108];
+
+     temp0 = to & 7;
+     if (temp0) {
+        bytes -= temp0;
+        asm __volatile__ (
+           "cld\n\t"
+           "rep; movsb\n\t"
+            : "=D" (to), "=S" (from)
+            : "D" (to), "S" (from), "c" (temp0)
+            : "cx" );
+     }
+     asm __volatile__ (
+        "shrl $8, %0\n\t"
+        "movl (%2), %3\n\t"
+        "movl (%1), %3\n\t"
+        "fsave %4\n"
+        "1:\n\t"
+        "movl $4, %3\n"
+        "2:\n\t"
+
+        "fildq 0x0(%2)\n\t"
+        "fildq 0x20(%2)\n\t"
+        "fildq 0x40(%2)\n\t"
+        "fildq 0x60(%2)\n\t"
+        "fildq 0x80(%2)\n\t"
+        "fildq 0xa0(%2)\n\t"
+        "fildq 0xc0(%2)\n\t"
+        "fildq 0xe0(%2)\n\t"
+        "fxch\n\t"
+        "fistpq 0xc0(%1)\n\t"
+        "fistpq 0xe0(%1)\n\t"
+        "fistpq 0xa0(%1)\n\t"
+        "fistpq 0x80(%1)\n\t"
+        "fistpq 0x60(%1)\n\t"
+        "fistpq 0x40(%1)\n\t"
+        "fistpq 0x20(%1)\n\t"
+        "fistpq 0x0(%1)\n\t"
+
+        "addl $8, %2\n\t"
+        "addl $8, %1\n\t"
+        "decl %3\n\t"
+        "jne 2b\n\t"
+
+        "addl $224, %2\n\t"
+        "addl $224, %1\n\t"
+        "decl %0\n\t"
+        "jne 1b\n\t"
+        "frstor %4\n\t"
+        : "=&r" (temp0), "=&r" (to), "=&r" (from), "=&r" (temp1)
+        : "m" (save[0]), "0" (bytes), "1" (to), "2" (from)
+        : "memory" );             
+     bytes &= 255;
+   }
+   if (bytes) {
+      asm __volatile__ (
+        "shrl $2, %%ecx\n\t"
+        "cld\n\t"
+        "rep ; movsl\n\t"
+        "testb $2,%%dl\n\t"
+        "je 111f\n\t"
+        "movsw\n"
+        "111:\ttestb $1,%%dl\n\t"
+        "je 112f\n\t"
+        "movsb\n"
+        "112:"
+        : "=D" (to), "=S" (from)
+        : "D" (to), "S" (from), "c" (bytes), "d" (bytes)
+        : "cx","memory");
+    }
+  return _to;
+}
+
+void 
+__generic_memcpy_fromfs (void *_to, const void *_from, size_t _bytes)
+{
+  register unsigned long from asm ("si") = (unsigned long)_from;
+  register unsigned long to   asm ("di") = (unsigned long)_to;
+  register unsigned long bytes asm ("dx") = (unsigned long)_bytes;
+
+  if (bytes >= 1024) {
+     unsigned long temp0, temp1;
+     char save[108];
+
+     temp0 = to & 7;
+     if (temp0) {
+        bytes -= temp0;
+        asm __volatile__ (
+           "cld\n\t"
+           "rep; fs; movsb\n\t"
+            : "=D" (to), "=S" (from)
+            : "D" (to), "S" (from), "c" (temp0)
+            : "cx" );
+     }
+     asm __volatile__ (
+        "shrl $8, %0\n\t"
+        "fs; movl (%2), %3\n\t"
+        "es; movl (%1), %3\n\t"
+        "fsave %4\n"
+        "1:\n\t"
+        "movl $4, %3\n"
+        "2:\n\t"
+
+        "fs; fildq 0x0(%2)\n\t"
+        "fs; fildq 0x20(%2)\n\t"
+        "fs; fildq 0x40(%2)\n\t"
+        "fs; fildq 0x60(%2)\n\t"
+        "fs; fildq 0x80(%2)\n\t"
+        "fs; fildq 0xa0(%2)\n\t"
+        "fs; fildq 0xc0(%2)\n\t"
+        "fs; fildq 0xe0(%2)\n\t"
+        "fxch\n\t"
+        "es; fistpq 0xc0(%1)\n\t"
+        "es; fistpq 0xe0(%1)\n\t"
+        "es; fistpq 0xa0(%1)\n\t"
+        "es; fistpq 0x80(%1)\n\t"
+        "es; fistpq 0x60(%1)\n\t"
+        "es; fistpq 0x40(%1)\n\t"
+        "es; fistpq 0x20(%1)\n\t"
+        "es; fistpq 0x0(%1)\n\t"
+
+        "addl $8, %2\n\t"
+        "addl $8, %1\n\t"
+        "decl %3\n\t"
+        "jne 2b\n\t"
+
+        "addl $224, %2\n\t"
+        "addl $224, %1\n\t"
+        "decl %0\n\t"
+        "jne 1b\n\t"
+        "frstor %4\n\t"
+        : "=&r" (temp0), "=&r" (to), "=&r" (from), "=&r" (temp1)
+        : "m" (save[0]), "0" (bytes), "1" (to), "2" (from)
+        : "memory" );             
+     bytes &= 255;
+   }
+   if (bytes) {
+      asm __volatile__ (
+        "shrl $2, %%ecx\n\t"
+        "cld\n\t"
+        "rep; fs; movsl\n\t"
+        "testb $2,%%dl\n\t"
+        "je 111f\n\t"
+        "fs; movsw\n"
+        "111:\ttestb $1,%%dl\n\t"
+        "je 112f\n\t"
+        "fs; movsb\n"
+        "112:"
+        : "=D" (to), "=S" (from)
+        : "D" (to), "S" (from), "c" (bytes), "d" (bytes)
+        : "cx","memory");
+    }
+}
+
+void 
+__generic_memcpy_tofs (void *_to, const void *_from, size_t _bytes)
+{
+  register unsigned long from asm ("si") = (unsigned long)_from;
+  register unsigned long to   asm ("di") = (unsigned long)_to;
+  register unsigned long bytes asm ("dx") = (unsigned long)_bytes;
+  if (bytes >= 1024) {
+     unsigned long temp0, temp1;
+     char save[108];
+
+     temp0 = to & 7;
+     if (temp0) {
+        bytes -= temp0;
+        asm __volatile__ (
+           "push %%es\n\t"
+           "push %%fs\n\t"
+           "pop %%es\n\t"
+           "cld\n\t"
+           "rep; movsb\n\t"
+           "pop %%es\n\t"
+            : "=D" (to), "=S" (from)
+            : "D" (to), "S" (from), "c" (temp0)
+            : "cx" );
+     }
+     asm __volatile__ (
+        "shrl $8, %0\n\t"
+        "movl (%2), %3\n\t"
+        "fs; movl (%1), %3\n\t"
+        "fsave %4\n"
+        "1:\n\t"
+        "movl $4, %3\n"
+        "2:\n\t"
+
+        "fildq 0x0(%2)\n\t"
+        "fildq 0x20(%2)\n\t"
+        "fildq 0x40(%2)\n\t"
+        "fildq 0x60(%2)\n\t"
+        "fildq 0x80(%2)\n\t"
+        "fildq 0xa0(%2)\n\t"
+        "fildq 0xc0(%2)\n\t"
+        "fildq 0xe0(%2)\n\t"
+        "fxch\n\t"
+        "fs; fistpq 0xc0(%1)\n\t"
+        "fs; fistpq 0xe0(%1)\n\t"
+        "fs; fistpq 0xa0(%1)\n\t"
+        "fs; fistpq 0x80(%1)\n\t"
+        "fs; fistpq 0x60(%1)\n\t"
+        "fs; fistpq 0x40(%1)\n\t"
+        "fs; fistpq 0x20(%1)\n\t"
+        "fs; fistpq 0x0(%1)\n\t"
+
+        "addl $8, %2\n\t"
+        "addl $8, %1\n\t"
+        "decl %3\n\t"
+        "jne 2b\n\t"
+
+        "addl $224, %2\n\t"
+        "addl $224, %1\n\t"
+        "decl %0\n\t"
+        "jne 1b\n\t"
+        "frstor %4\n\t"
+        : "=&r" (temp0), "=&r" (to), "=&r" (from), "=&r" (temp1)
+        : "m" (save[0]), "0" (bytes), "1" (to), "2" (from)
+        : "memory" );             
+     bytes &= 255;
+   }
+   if (bytes) {
+      asm __volatile__ (
+        "push %%es\n\t"
+        "push %%fs\n\t"
+        "pop %%es\n\t"
+        "shrl $2, %%ecx\n\t"
+        "cld\n\t"
+        "rep; movsl\n\t"
+        "testb $2,%%dl\n\t"
+        "je 111f\n\t"
+        "movsw\n"
+        "111:\ttestb $1,%%dl\n\t"
+        "je 112f\n\t"
+        "movsb\n"
+        "112:"
+        "pop %%es\n\t"
+        : "=D" (to), "=S" (from)
+        : "D" (to), "S" (from), "c" (bytes), "d" (bytes)
+        : "cx","memory");
+    }
+}
Index: linux/include/asm-i386/segment.h
diff -u linux/include/asm-i386/segment.h:1.1.1.6 linux/include/asm-i386/segment.h:1.6
--- linux/include/asm-i386/segment.h:1.1.1.6	Wed Apr 10 18:49:16 1996
+++ linux/include/asm-i386/segment.h	Wed Apr 10 18:58:25 1996
@@ -1,6 +1,9 @@
 #ifndef _ASM_SEGMENT_H
 #define _ASM_SEGMENT_H
 
+#include "linux/autoconf.h"
+#include <linux/config.h>
+
 #define KERNEL_CS	0x10
 #define KERNEL_DS	0x18
 
@@ -80,6 +83,10 @@
 	}
 }
 
+#ifdef CONFIG_M586_COPY
+extern void __generic_memcpy_tofs(void *to, const void *from, unsigned long n);
+
+#else
 static inline void __generic_memcpy_tofs(void * to, const void * from, unsigned long n)
 {
     __asm__ volatile
@@ -106,6 +113,8 @@
 	:"cx","di","si");
 }
 
+#endif
+
 static inline void __constant_memcpy_tofs(void * to, const void * from, unsigned long n)
 {
 	switch (n) {
@@ -169,6 +178,11 @@
 #undef COMMON
 }
 
+#ifdef CONFIG_M586_COPY
+
+extern void __generic_memcpy_fromfs(void *to, const void *from, unsigned long n);
+
+#else
 static inline void __generic_memcpy_fromfs(void * to, const void * from, unsigned long n)
 {
     __asm__ volatile
@@ -191,6 +205,8 @@
 	:"cx","di","si", "memory");
 }
 
+#endif
+
 static inline void __constant_memcpy_fromfs(void * to, const void * from, unsigned long n)
 {
 	switch (n) {
@@ -251,12 +267,12 @@
 }
 
 #define memcpy_fromfs(to, from, n) \
-(__builtin_constant_p(n) ? \
+((((n) < 256) && __builtin_constant_p(n)) ? \
  __constant_memcpy_fromfs((to),(from),(n)) : \
  __generic_memcpy_fromfs((to),(from),(n)))
 
 #define memcpy_tofs(to, from, n) \
-(__builtin_constant_p(n) ? \
+((((n) < 256) && __builtin_constant_p(n)) ? \
  __constant_memcpy_tofs((to),(from),(n)) : \
  __generic_memcpy_tofs((to),(from),(n)))
 
Index: linux/include/asm-i386/string-486.h
diff -u linux/include/asm-i386/string-486.h:1.1.1.1 linux/include/asm-i386/string-486.h:1.7
--- linux/include/asm-i386/string-486.h:1.1.1.1	Tue Feb 27 11:56:16 1996
+++ linux/include/asm-i386/string-486.h	Tue Feb 27 19:41:22 1996
@@ -1,6 +1,9 @@
 #ifndef _I386_STRING_I486_H_
 #define _I386_STRING_I486_H_
 
+#include "linux/autoconf.h"
+#include <linux/config.h>
+
 /*
  * This string-include defines all string functions as inline
  * functions. Use gcc. It also assumes ds=es=data space, this should be
@@ -414,7 +417,7 @@
 
 #define __HAVE_ARCH_MEMCPY
 #define memcpy(d,s,count) \
-(__builtin_constant_p(count) ? \
+((((count) < 256) && (__builtin_constant_p(count))) ? \
  __memcpy_c((d),(s),(count)) : \
  __memcpy_g((d),(s),(count)))
 
@@ -460,6 +463,9 @@
 return (to);
 }
 
+#ifdef CONFIG_M586_COPY
+extern void *__memcpy_g(void *to, const void *from, size_t n);
+#else
 extern inline void * __memcpy_g(void * to, const void * from, size_t n)
 {
 register void *tmp = (void *)to;
@@ -478,6 +484,7 @@
 	:"cx","di","si","memory");
 return (to);
 }
+#endif
 
 
 #define __HAVE_ARCH_MEMMOVE
@@ -552,6 +559,19 @@
   __memset_gg((s),(c),(count))))
 
 #define __HAVE_ARCH_MEMSET
+#ifdef CONFIG_M586_COPY
+extern void * ___zero_chunk(void *to, size_t bytes);
+#define memset(s, c, count) \
+((((c) == 0) && !(((unsigned long) s) & 7) && !((count) & 7) && ((count) >= 512)) ? \
+ ___zero_chunk((s),(count)) : \
+(__builtin_constant_p(c) ? \
+ (__builtin_constant_p(count) ? \
+  __memset_cc((s),(c),(count)) : \
+  __memset_cg((s),(c),(count))) : \
+ (__builtin_constant_p(count) ? \
+  __memset_gc((s),(c),(count)) : \
+  __memset_gg((s),(c),(count)))))
+#else
 #define memset(s,c,count) \
 (__builtin_constant_p(c) ? \
  (__builtin_constant_p(count) ? \
@@ -560,6 +580,7 @@
  (__builtin_constant_p(count) ? \
   __memset_gc((s),(c),(count)) : \
   __memset_gg((s),(c),(count))))
+#endif
 
 extern inline void * __memset_cc_by4(void * s, char c, size_t count)
 {
Index: linux/include/asm-i386/string.h
diff -u linux/include/asm-i386/string.h:1.1.1.10 linux/include/asm-i386/string.h:1.12
--- linux/include/asm-i386/string.h:1.1.1.10	Wed Apr 10 18:49:17 1996
+++ linux/include/asm-i386/string.h	Tue Jun 11 21:42:10 1996
@@ -1,6 +1,7 @@
 #ifndef _I386_STRING_H_
 #define _I386_STRING_H_
 
+#include <linux/config.h>
 /*
  * On a 486 or Pentium, we are better off not using the
  * byte string operations. But on a 386 or a PPro the
@@ -362,6 +363,10 @@
 return __res;
 }
 
+#ifdef CONFIG_M586_COPY
+#define __memcpy __memcpy_g
+extern void *__memcpy(void *to, const void *from, size_t n);
+#else
 extern inline void * __memcpy(void * to, const void * from, size_t n)
 {
 __asm__ __volatile__(
@@ -379,6 +384,7 @@
 	: "cx","di","si","memory");
 return (to);
 }
+#endif
 
 /*
  * This looks horribly ugly, but the compiler can optimize it totally,
@@ -444,7 +450,7 @@
 
 #define __HAVE_ARCH_MEMCPY
 #define memcpy(t, f, n) \
-(__builtin_constant_p(n) ? \
+(((__builtin_constant_p(n)) && ((n) < 256)) ? \
  __constant_memcpy((t),(f),(n)) : \
  __memcpy((t),(f),(n)))
 
@@ -602,10 +608,20 @@
  __memset_generic((s),(c),(count)))
 
 #define __HAVE_ARCH_MEMSET
+#ifdef CONFIG_M586_COPY
+extern void * ___zero_chunk(void *to, size_t bytes);
+#define memset(s, c, count) \
+(((c) == 0) && ((count) >= 512) ? \
+ ___zero_chunk((s),(count)) : \
+ __builtin_constant_p(c) ? \
+  __constant_c_x_memset((s),(0x01010101UL*(unsigned char)c),(count)) : \
+  __memset((s),(c),(count)))
+#else
 #define memset(s, c, count) \
 (__builtin_constant_p(c) ? \
  __constant_c_x_memset((s),(0x01010101UL*(unsigned char)c),(count)) : \
  __memset((s),(c),(count)))
+#endif
 
 /*
  * find the first occurrence of byte 'c', or 1 past the area if none
Index: linux/kernel/ksyms.c
diff -u linux/kernel/ksyms.c:1.1.1.58 linux/kernel/ksyms.c:1.39
--- linux/kernel/ksyms.c:1.1.1.58	Sun Jun  2 18:46:03 1996
+++ linux/kernel/ksyms.c	Sun Jun  2 19:10:01 1996
@@ -77,6 +77,10 @@
 
 extern void hard_reset_now(void);
 
+#ifdef CONFIG_M586_COPY
+#include <asm/string.h>
+#endif
+
 struct symbol_table symbol_table = {
 #include <linux/symtab_begin.h>
 #ifdef MODVERSIONS
@@ -354,6 +358,14 @@
 	/* binfmt_aout */
 	X(get_write_access),
 	X(put_write_access),
+
+#ifdef CONFIG_M586_COPY
+	/* Pentium memcpy */
+	X(___zero_chunk),
+	X(__memcpy_g),
+	X(__generic_memcpy_fromfs),
+	X(__generic_memcpy_tofs),
+#endif
 
 	/********************************************************
 	 * Do not add anything below this line,

----=_339fa94d27155633002c52519.MFSBCHJLHS
Content-Type: text/plain; charset=us-ascii; name=patch-2_0-ISS_test4
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=patch-2_0-ISS_test4

diff -u --recursive --new-file vanilla/v2.0.29/linux/Documentation/Configure.help linux/Documentation/Configure.help
--- vanilla/v2.0.29/linux/Documentation/Configure.help	Sun Dec  1 08:58:05 1996
+++ linux/Documentation/Configure.help	Wed Mar  5 07:42:28 1997
@@ -436,6 +436,35 @@
   any machine being run as a router and not on a host. If unsure, say
   N.
 
+SYN flood protection
+CONFIG_SYN_COOKIES
+  Normal TCP/IP networking is open to an attack known as SYN flooding.
+  This attack prevents legitimate users from being able to connect to
+  your computer and requires very little work for the attacker.
+  SYN cookies provide protection against this type of attack. With
+  this option turned on the TCP/IP stack will use a cryptographic
+  challange protocol know as SYN cookies to enable legitimate users
+  to continue to connect, even when your machine is under attack.
+  The RST_COOKIES option provides an alternative method to accomplish
+  the same end. SYN cookies use less space than RST cookies,
+  but have a small probability of introducing an non timed-out
+  failure to connect in the remote TCP. You can use both options
+  simultatenously.
+
+SYN flood protection
+CONFIG_RST_COOKIES
+  Normal TCP/IP networking is open to an attack known as SYN flooding.
+  This attack prevents legitimate users from being able to connect to
+  your computer and requires very little work for the attacker.
+  SYN cookies provide protection against this type of attack. With
+  this option turned on the TCP/IP stack will use a cryptographic
+  challange protocol know as RST cookies to enable legitimate users
+  to continue to connect, even when your machine is under attack.
+  The SYN_COOKIES option provides an alternative method to accomplish
+  the same end. RST cookies use more space than SYN cookies on your
+  machine, but never increase the probability of a frozen connection
+  in a remote TCP. You can use both options simultatenously.
+
 Sun floppy controller support
 CONFIG_BLK_DEV_SUNFD
   This is support for floppy drives on Sun Sparc workstations. Say Y
@@ -893,7 +922,7 @@
   rules (using the ipfwadm utility) and/or by doing an appropriate
   bind() system call.
 
-IP: masquerading (EXPERIMENTAL)
+IP: masquerading
 CONFIG_IP_MASQUERADE
   If one of the computers on your local network for which your Linux
   box acts as a firewall wants to send something to the outside, your
@@ -912,8 +941,28 @@
   from ftp://sunsite.unc.edu/pub/Linux/system/Network/serial/].)
   Details on how to set things up are contained in the
   IP Masquerading FAQ, available at http://www.indyramp.com/masq/
-  This is EXPERIMENTAL code, which means that it need not be completely
-  stable. If you want this, say Y.
+  To use masquerading you must also enable Network Firewalls, IP
+  forwarding/gatewaying, IP firewalling and (ideally, but optionally)
+  IP always defragment.
+  If you want this, say Y.
+
+IP: ipautofw masquerade support
+CONFIG_IP_MASQUERADE_IPAUTOFW
+  ipautofw is a program by Richard Lynch allowing additional
+  support for masquerading protocols which do not (as yet)
+  have additional protocol helpers.  
+  Information and source for ipautofw is available from
+  ftp://ftp.netis.com/pub/members/rlynch/
+  If you want this, say Y.
+
+IP: ICMP masquerading
+CONFIG_IP_MASQUERADE_ICMP
+  The basic masquerade code described for CONFIG_IP_MASQUERADE only
+  handles TCP or UDP packets (and ICMP errors for existing 
+  connections).  This option adds additional support for masquerading
+  ICMP packets, such as ping or the probes used by the Windows 95
+  tracert program.
+  If you want this, say Y.
 
 IP: always defragment 
 CONFIG_IP_ALWAYS_DEFRAG 
diff -u --recursive --new-file vanilla/v2.0.29/linux/Documentation/networking/00-INDEX linux/Documentation/networking/00-INDEX
--- vanilla/v2.0.29/linux/Documentation/networking/00-INDEX	Thu Jun  6 07:57:43 1996
+++ linux/Documentation/networking/00-INDEX	Wed Mar  5 07:42:28 1997
@@ -14,6 +14,8 @@
 	- info on using AX.25 and NET/ROM code for Linux
 framerelay.txt
 	- info on using Frame Relay/Data Link Connection Identifier (DLCI).
+masquerading.txt
+	- using IP masquerading, multiple machines using a single IP address.
 ncsa-telnet
 	- notes on how NCSA telnet (DOS) breaks with MTU discovery enabled.
 net-modules.txt
diff -u --recursive --new-file vanilla/v2.0.29/linux/Documentation/networking/masquerading.txt linux/Documentation/networking/masquerading.txt
--- vanilla/v2.0.29/linux/Documentation/networking/masquerading.txt	Wed Dec 31 19:00:00 1969
+++ linux/Documentation/networking/masquerading.txt	Wed Mar  5 07:42:28 1997
@@ -0,0 +1,51 @@
+IP Masquerading lets you run multiple machines on a network behind a
+Linux box so that all the machines (including the Linux masquerade box)
+appear as a single IP address to the outside world.
+
+The main use of masquerading is when your ISP only gives you one IP
+address and wants to charge like a wounded bull for multiple IP
+addresses.  Instead of paying your ISP large amounts of money for a
+separate address for each of your machines, funnel them all through a
+Linux box running IP masquerading.  Even when you have multiple IP
+addresses, you can still use masquerading if you want to hide your
+internal networks from the rest of the world.
+
+To activate IP masquerading, compile the kernel with IP Forwarding, IP
+Firewalling and IP Masquerading, the first two options must be on
+before you can see the masquerade option.  Also consider using the
+ipautofw and ICMP masquerading suboptions.
+
+Some of the masq code is in the kernel, some is in modules so you have
+to make zImage and make modules.  There are masq helper modules to
+handle special protocols, you only need to load a helper module if you
+want to use the corresponding protocol.  Helper modules have to be
+explicitly loaded (usually from somewhere in /etc/rc.d), they cannot be
+loaded using kerneld.  The current helper modules are ip_masq_ftp,
+ip_masq_irc, ip_masq_raudio, ip_masq_cuseeme, ip_masq_vdolive,
+ip_masq_quake.
+
+All of the modules can take a parameter specifying the port they work
+on - ie ftp handles connections to port 21 by default.  This parameter,
+which can be ommitted to take the default port(s) makes the command
+line look like this
+	insmod ip_masq_raudio.o ports=7070,7071,7072
+Up to 12 ports can be specified (this value can be changed if you 
+recompile).
+
+Masquerading is more of a server function than a single user function.
+Using it correctly requires some knowledge of TCP, UDP, IP and a high
+level understanding of some protocols.  For more details on IP
+masquerading, visit 
+	http://www.indyramp.com/masq/
+and read the HOWTO.
+
+There is a mailing list covering use of masqueraing, information can
+be found on the indyramp web site given above - please read the basic
+information before posting to the mailing list.
+
+Other information on masquerading can be found at
+	http://www.wwonline.com/~achau/ipmasq/
+
+							March 5, 1997
+							Keith Owens
+							Nigel Metheringham
diff -u --recursive --new-file vanilla/v2.0.29/linux/Makefile linux/Makefile
--- vanilla/v2.0.29/linux/Makefile	Tue Jan 14 18:13:12 1997
+++ linux/Makefile	Mon Mar  3 06:14:36 1997
@@ -229,7 +236,7 @@
 	@mv -f .ver $@
 
 include/linux/version.h: ./Makefile
-	@echo \#define UTS_RELEASE \"$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)\" > .ver
+	@echo \#define UTS_RELEASE \"$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)-ISS\" > .ver
 	@echo \#define LINUX_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)` >> .ver
 	@mv -f .ver $@
 
@@ -274,7 +281,7 @@
 
 modules_install:
 	@( \
-	MODLIB=/lib/modules/$(VERSION).$(PATCHLEVEL).$(SUBLEVEL); \
+	MODLIB=/lib/modules/$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)-ISS; \
 	cd modules; \
 	MODULES=""; \
 	inst_mod() { These="`cat $$1`"; MODULES="$$MODULES $$These"; \
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/char/random.c linux/drivers/char/random.c
--- vanilla/v2.0.29/linux/drivers/char/random.c	Fri Sep 20 10:00:34 1996
+++ linux/drivers/char/random.c	Tue Mar  4 12:30:51 1997
@@ -1345,6 +1345,139 @@
 	return (seq);
 }
 
+#ifdef CONFIG_RST_COOKIES
+/*
+ * TCP security probe sequence number picking. Losely based upon
+ * secure sequence number algorithm above.
+ */
+__u32 secure_tcp_probe_number(__u32 saddr, __u32 daddr,
+		 __u16 sport, __u16 dport, __u32 sseq, int validate)
+{
+	static int	is_init = 0;
+	static int	valid_secret[2];
+	static __u32	secret_timestamp[2];
+	static __u32	secret[2][16];
+	static int	offset = 0;
+	__u32 		tmp[16];
+	__u32		seq;
+
+	/*
+	 * Pick a random secret the first time we open a TCP
+	 * connection, and expire secretes older than 5 minutes.
+	 */
+	if (is_init == 0 || jiffies-secret_timestamp[offset] > 600*HZ) {
+		if (is_init == 0) valid_secret[0] = valid_secret[1] = 0;
+		else offset = (offset+1)%2;
+		get_random_bytes(&secret[offset], sizeof(secret[offset]));
+		valid_secret[offset] = 1;
+		secret_timestamp[offset] = jiffies;
+		is_init = 1;
+	}
+
+	memcpy(tmp, secret[offset], sizeof(tmp));
+	/*
+	 * Pick a unique starting offset for each
+	 * TCP connection endpoints (saddr, daddr, sport, dport)
+	 */
+	tmp[8]=saddr;
+	tmp[9]=daddr;
+	tmp[10]=(sport << 16) + dport;
+	HASH_TRANSFORM(tmp, tmp);
+	seq = tmp[1];
+
+	if (!validate) {
+		if (seq == sseq) seq++;
+#if 0
+		printk("init_seq(%lx, %lx, %d, %d, %d) = %d\n",
+		       saddr, daddr, sport, dport, sseq, seq);
+#endif
+		return (seq);
+	} else {
+		if (seq == sseq || (seq+1) == sseq) {
+			printk("validated probe(%lx, %lx, %d, %d, %d)\n",
+		       		saddr, daddr, sport, dport, sseq);
+			return 1;
+		}
+		if (jiffies-secret_timestamp[(offset+1)%2] <= 1200*HZ) {
+			memcpy(tmp, secret[(offset+1)%2], sizeof(tmp));
+			tmp[8]=saddr;
+			tmp[9]=daddr;
+			tmp[10]=(sport << 16) + dport;
+			HASH_TRANSFORM(tmp, tmp);
+			seq = tmp[1];
+			if (seq == sseq || (seq+1) == sseq) {
+#ifdef 0
+				printk("validated probe(%lx, %lx, %d, %d, %d)\n",
+		       			saddr, daddr, sport, dport, sseq);
+#endif
+				return 1;
+			}
+		}
+#ifdef 0
+		printk("failed validation on probe(%lx, %lx, %d, %d, %d)\n",
+			saddr, daddr, sport, dport, sseq);
+#endif
+		return 0;
+	}
+}
+#endif
+
+#ifdef CONFIG_SYN_COOKIES
+/*
+ * Secure SYN cookie computation. This is the algorithm worked out by
+ * Dan Bernstien and Eric Schenk.
+ *
+ * For linux I implement the 1 minute counter by looking at the jiffies clock.
+ * The count is passed in as a parameter;
+ *
+ */
+__u32 secure_tcp_syn_cookie(__u32 saddr, __u32 daddr,
+		 __u16 sport, __u16 dport, __u32 sseq, __u32 count)
+{
+	static int	is_init = 0;
+	static __u32	secret[2][16];
+	__u32 		tmp[16];
+	__u32		seq;
+
+	/*
+	 * Pick two random secret the first time we open a TCP connection.
+	 */
+	if (is_init == 0) {
+		get_random_bytes(&secret[0], sizeof(secret[0]));
+		get_random_bytes(&secret[1], sizeof(secret[1]));
+		is_init = 1;
+	}
+
+	/*
+	 * Compute the secure sequence number.
+	 * The output should be:
+   	 *   MD5(sec1,saddr,sport,daddr,dport,sec1) + their sequence number
+         *      + (count * 2^24)
+	 *      + (MD5(sec2,saddr,sport,daddr,dport,count,sec2) % 2^24).
+	 * Where count increases every minute by 1.
+	 */
+
+	memcpy(tmp, secret[0], sizeof(tmp));
+	tmp[8]=saddr;
+	tmp[9]=daddr;
+	tmp[10]=(sport << 16) + dport;
+	HASH_TRANSFORM(tmp, tmp);
+	seq = tmp[1];
+
+	memcpy(tmp, secret[1], sizeof(tmp));
+	tmp[8]=saddr;
+	tmp[9]=daddr;
+	tmp[10]=(sport << 16) + dport;
+	tmp[11]=count;	/* minute counter */
+	HASH_TRANSFORM(tmp, tmp);
+
+	seq += sseq + (count << 24) + (tmp[1] & 0x00ffffff);
+
+	/* Zap lower 3 bits to leave room for the MSS representation */
+	return (seq & 0xfffff8);
+}
+#endif
+
 #ifdef RANDOM_BENCHMARK
 /*
  * This is so we can do some benchmarking of the random driver, to see
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/3c59x.c linux/drivers/net/3c59x.c
--- vanilla/v2.0.29/linux/drivers/net/3c59x.c	Thu Nov  7 04:25:21 1996
+++ linux/drivers/net/3c59x.c	Sat Mar  8 20:50:05 1997
@@ -775,12 +775,14 @@
 			/* Issue TX_RESET and TX_START commands. */
 			outw(TxReset, ioaddr + EL3_CMD);
 			for (i = 20; i >= 0 ; i--)
-				if ( ! inw(ioaddr + EL3_STATUS) & CmdInProgress)                                        break;
+				if ( ! inw(ioaddr + EL3_STATUS) & CmdInProgress)
+						break;
 			outw(TxEnable, ioaddr + EL3_CMD);
 			dev->trans_start = jiffies;
 			dev->tbusy = 0;
 			vp->stats.tx_errors++;
 			vp->stats.tx_dropped++;
+			dev_kfree_skb(skb, FREE_WRITE);
 			return 0;			/* Yes, silently *drop* the packet! */
 		}
 		dev->tbusy = 0;
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/a2065.c linux/drivers/net/a2065.c
--- vanilla/v2.0.29/linux/drivers/net/a2065.c	Mon May 20 00:54:28 1996
+++ linux/drivers/net/a2065.c	Sat Mar  8 20:51:16 1997
@@ -536,7 +536,7 @@
 
 		dev->tbusy = 0;
 		dev->trans_start = jiffies;
-
+		dev_kfree_skb(skb, FREE_WRITE);
 		return(0);
 	}
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/ariadne.c linux/drivers/net/ariadne.c
--- vanilla/v2.0.29/linux/drivers/net/ariadne.c	Mon May 20 00:54:28 1996
+++ linux/drivers/net/ariadne.c	Sat Mar  8 20:51:33 1997
@@ -578,7 +578,7 @@
 
 	dev->tbusy = 0;
 	dev->trans_start = jiffies;
-
+	dev_kfree_skb(skb, FREE_WRITE);
 	return(0);
     }
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/atarilance.c linux/drivers/net/atarilance.c
--- vanilla/v2.0.29/linux/drivers/net/atarilance.c	Fri Apr 26 05:12:25 1996
+++ linux/drivers/net/atarilance.c	Sat Mar  8 20:51:54 1997
@@ -756,7 +756,7 @@
 
 		dev->tbusy = 0;
 		dev->trans_start = jiffies;
-
+		dev_kfree_skb(skb, FREE_WRITE);
 		return( 0 );
 	}
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/defxx.c linux/drivers/net/defxx.c
--- vanilla/v2.0.29/linux/drivers/net/defxx.c	Tue Oct 29 20:42:40 1996
+++ linux/drivers/net/defxx.c	Sat Mar  8 20:48:23 1997
@@ -3138,6 +3138,7 @@
 		printk("%s: Invalid packet length - %lu bytes\n", dev->name, skb->len);
 		bp->xmt_length_errors++;	/* bump error counter */
 		dev_tint(dev);				/* dequeue packets from xmt queue and send them */
+		dev_kfree_skb(skb, FREE_WRITE);
 		return(0);					/* return "success" */
 		}
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/depca.c linux/drivers/net/depca.c
--- vanilla/v2.0.29/linux/drivers/net/depca.c	Sat Nov  9 12:31:38 1996
+++ linux/drivers/net/depca.c	Sat Mar  8 20:49:08 1997
@@ -797,6 +797,7 @@
       dev->tbusy=0;
       dev->trans_start = jiffies;
       InitRestartDepca(dev);
+      dev_kfree_skb(skb, FREE_WRITE);
     }
     return status;
   } else if (skb == NULL) {
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/eexpress.c linux/drivers/net/eexpress.c
--- vanilla/v2.0.29/linux/drivers/net/eexpress.c	Fri Jun  7 07:21:04 1996
+++ linux/drivers/net/eexpress.c	Sat Mar  8 21:15:44 1997
@@ -1,4 +1,4 @@
-/* $Id: eexpress.c,v 1.13 1996/05/19 15:59:51 phil Exp $
+/* $Id: eexpress.c,v 1.13.2.1 1997/03/09 02:14:21 davem Exp $
  *
  * Intel EtherExpress device driver for Linux
  *
@@ -447,6 +447,7 @@
 		}
 		dev_tint(dev);
 		outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
+		dev_kfree_skb(skb, FREE_WRITE);
 		return 0;
 	}
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/ewrk3.c linux/drivers/net/ewrk3.c
--- vanilla/v2.0.29/linux/drivers/net/ewrk3.c	Sat Nov  9 12:31:38 1996
+++ linux/drivers/net/ewrk3.c	Sat Mar  8 20:58:49 1997
@@ -757,6 +757,7 @@
 
       dev->tbusy=0;
       dev->trans_start = jiffies;
+      dev_kfree_skb(skb, FREE_WRITE);
     }
   } else if (skb == NULL) {
     dev_tint(dev);
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/hydra.c linux/drivers/net/hydra.c
--- vanilla/v2.0.29/linux/drivers/net/hydra.c	Mon May 20 00:54:28 1996
+++ linux/drivers/net/hydra.c	Sat Mar  8 21:00:12 1997
@@ -441,7 +441,7 @@
 
 	dev->tbusy = 0;
 	dev->trans_start = jiffies;
-
+	dev_kfree_skb(skb, FREE_WRITE);
 	return(0);
 	}
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/ibmtr.c linux/drivers/net/ibmtr.c
--- vanilla/v2.0.29/linux/drivers/net/ibmtr.c	Thu Aug 29 12:15:14 1996
+++ linux/drivers/net/ibmtr.c	Sat Mar  8 21:00:52 1997
@@ -1460,9 +1460,10 @@
 		return 0;
 	}
 	
-	if (set_bit(0,(void *)&dev->tbusy)!=0)
+	if (set_bit(0,(void *)&dev->tbusy)!=0) {
+		dev_kfree_skb(skb, FREE_WRITE);
 		DPRINTK("Transmitter access conflict\n");
-	else {
+	} else {
 		/* Save skb; we'll need it when the adapter asks for the data */
 		ti->current_skb=skb; 
 		writeb(XMIT_UI_FRAME, ti->srb + offsetof(struct srb_xmit, command));
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/lance.c linux/drivers/net/lance.c
--- vanilla/v2.0.29/linux/drivers/net/lance.c	Thu Aug 29 12:15:14 1996
+++ linux/drivers/net/lance.c	Sat Mar  8 21:01:10 1997
@@ -816,7 +816,7 @@
 
 		dev->tbusy=0;
 		dev->trans_start = jiffies;
-
+		dev_kfree_skb(skb, FREE_WRITE);
 		return 0;
 	}
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/lance32.c linux/drivers/net/lance32.c
--- vanilla/v2.0.29/linux/drivers/net/lance32.c	Thu Jul  4 01:52:04 1996
+++ linux/drivers/net/lance32.c	Sat Mar  8 21:01:38 1997
@@ -479,7 +479,7 @@
 
 		dev->tbusy=0;
 		dev->trans_start = jiffies;
-
+		dev_kfree_skb(skb, FREE_WRITE);
 		return 0;
 	}
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/ni52.c linux/drivers/net/ni52.c
--- vanilla/v2.0.29/linux/drivers/net/ni52.c	Fri Apr 12 02:49:38 1996
+++ linux/drivers/net/ni52.c	Sat Mar  8 21:04:12 1997
@@ -1133,6 +1133,7 @@
       ni_attn586();
       WAIT_4_SCB_CMD();
       dev->trans_start = jiffies;
+      dev_kfree_skb(skb, FREE_WRITE);
       return 0;
     }
     else
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/plip.c linux/drivers/net/plip.c
--- vanilla/v2.0.29/linux/drivers/net/plip.c	Sat Aug 10 03:03:15 1996
+++ linux/drivers/net/plip.c	Sat Mar  8 21:15:54 1997
@@ -1,4 +1,4 @@
-/* $Id: plip.c,v 1.16 1996-04-06 15:36:57+09 gniibe Exp $ */
+/* $Id: plip.c,v 1.8.2.1 1997/03/09 02:14:32 davem Exp $ */
 /* PLIP: A parallel port "network" driver for Linux. */
 /* This driver is for parallel port with 5-bit cable (LapLink (R) cable). */
 /*
@@ -904,6 +904,7 @@
 	if (skb->len > dev->mtu + dev->hard_header_len) {
 		printk("%s: packet too big, %d.\n", dev->name, (int)skb->len);
 		dev->tbusy = 0;
+		dev_kfree_skb(skb, FREE_WRITE);
 		return 0;
 	}
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/sdla.c linux/drivers/net/sdla.c
--- vanilla/v2.0.29/linux/drivers/net/sdla.c	Sun Sep 15 03:34:18 1996
+++ linux/drivers/net/sdla.c	Sat Mar  8 21:07:02 1997
@@ -658,8 +658,10 @@
    if (skb == NULL) 
       return(0);
 
-   if (set_bit(0, (void*)&dev->tbusy) != 0)
+   if (set_bit(0, (void*)&dev->tbusy) != 0) {
       printk(KERN_WARNING "%s: transmitter access conflict.\n", dev->name);
+      dev_kfree_skb(skb, FREE_WRITE);
+   }
    else
    {
       /*
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/tulip.c linux/drivers/net/tulip.c
--- vanilla/v2.0.29/linux/drivers/net/tulip.c	Fri Dec 20 03:49:03 1996
+++ linux/drivers/net/tulip.c	Sat Mar  8 21:11:49 1997
@@ -817,6 +817,7 @@
 			if (!tp->port_fix) dev->if_port ++;
 			tp->port_select(dev);
 			dev->trans_start = jiffies;
+			dev_kfree_skb(skb, FREE_WRITE);
 			return(0);
 		}
 		printk("%s: transmit timed out, status %8.8x,"
@@ -846,6 +847,7 @@
 
 		dev->tbusy=0;
 		dev->trans_start = jiffies;
+		dev_kfree_skb(skb, FREE_WRITE);
 		return(0);
 	}
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/drivers/net/wic.c linux/drivers/net/wic.c
--- vanilla/v2.0.29/linux/drivers/net/wic.c	Tue Jul  2 12:08:42 1996
+++ linux/drivers/net/wic.c	Sat Mar  8 21:16:03 1997
@@ -1,4 +1,4 @@
-/* $Id: wic.c,v 1.0 1995/02/11 10:26:05 hayes Exp $ */
+/* $Id: wic.c,v 1.3.2.1 1997/03/09 02:14:40 davem Exp $ */
 /* WIC: A parallel port "network" driver for Linux. */
 /* based on the plip network driver */
 /* Modified for Linux 1.3.x by Alan Cox <Alan.Cox@linux.org> */
@@ -964,6 +964,7 @@
 	if (skb->len > dev->mtu) {
 		printk("%s: packet too big, %d.\n", dev->name, (int)skb->len);
 		dev->tbusy = 0;
+		dev_kfree_skb(skb, FREE_WRITE);
 		return 0;
 	}
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/fs/Config.in linux/fs/Config.in
--- vanilla/v2.0.29/linux/fs/Config.in	Sun Dec  1 08:58:05 1996
+++ linux/fs/Config.in	Fri Feb  7 23:05:15 1997
@@ -9,6 +9,9 @@
 tristate 'Minix fs support' CONFIG_MINIX_FS
 tristate 'Extended fs support' CONFIG_EXT_FS
 tristate 'Second extended fs support' CONFIG_EXT2_FS
+if [ "$CONFIG_EXT2_FS" = "y" ]; then
+	bool '	NO_ATIME support for ext2 filesystems' CONFIG_EXT2_NOATIME
+fi
 tristate 'xiafs filesystem support' CONFIG_XIA_FS
 
 # msdos filesystems
diff -u --recursive --new-file vanilla/v2.0.29/linux/fs/ext2/dir.c linux/fs/ext2/dir.c
--- vanilla/v2.0.29/linux/fs/ext2/dir.c	Fri Dec 22 06:00:19 1995
+++ linux/fs/ext2/dir.c	Sat Mar  8 22:45:06 1997
@@ -17,6 +17,8 @@
 
 #include <asm/segment.h>
 
+#include <linux/autoconf.h>	/* For CONFIG_EXT2_NOATIME if enabled. */
+
 #include <linux/errno.h>
 #include <linux/fs.h>
 #include <linux/ext2_fs.h>
@@ -206,7 +210,11 @@
 		offset = 0;
 		brelse (bh);
 	}
+#ifdef CONFIG_EXT2_NOATIME
+	if (!IS_RDONLY(inode) && !test_opt(sb,NO_ATIME)) {
+#else
 	if (!IS_RDONLY(inode)) {
+#endif
 		inode->i_atime = CURRENT_TIME;
 		inode->i_dirt = 1;
 	}
diff -u --recursive --new-file vanilla/v2.0.29/linux/fs/ext2/super.c linux/fs/ext2/super.c
--- vanilla/v2.0.29/linux/fs/ext2/super.c	Sun Jul  7 04:06:53 1996
+++ linux/fs/ext2/super.c	Fri Feb  7 23:05:28 1997
@@ -21,6 +24,8 @@
 #include <asm/segment.h>
 #include <asm/system.h>
 
+#include <linux/autoconf.h>	/* For CONFIG_EXT2_NOATIME if enabled. */
+
 #include <linux/errno.h>
 #include <linux/fs.h>
 #include <linux/ext2_fs.h>
@@ -252,6 +259,13 @@
 					value);
 				return 0;
 			}
+#ifdef CONFIG_EXT2_NOATIME
+		} else if (!strcmp (this_char, "no_atime")) {
+			set_opt (*mount_options, NO_ATIME);
+		}
+		else if (!strcmp (this_char, "update_atime")) {
+			clear_opt (*mount_options, NO_ATIME);
+#endif
 		}
 		/* Silently ignore the quota options */
 		else if (!strcmp (this_char, "grpquota")
diff -u --recursive --new-file vanilla/v2.0.29/linux/fs/ext2/symlink.c linux/fs/ext2/symlink.c
--- vanilla/v2.0.29/linux/fs/ext2/symlink.c	Fri Apr 12 03:33:26 1996
+++ linux/fs/ext2/symlink.c	Fri Feb  7 23:05:28 1997
@@ -17,6 +17,8 @@
 
 #include <asm/segment.h>
 
+#include <linux/autoconf.h>	/* For CONFIG_EXT2_NOATIME if enabled. */
+
 #include <linux/errno.h>
 #include <linux/fs.h>
 #include <linux/ext2_fs.h>
@@ -86,7 +88,11 @@
 		link = bh->b_data;
 	} else
 		link = (char *) inode->u.ext2_i.i_data;
+#ifdef CONFIG_EXT2_NOATIME
+	if (!IS_RDONLY(inode) && !test_opt(inode->i_sb,NO_ATIME)) {
+#else
 	if (!IS_RDONLY(inode)) {
+#endif
 		inode->i_atime = CURRENT_TIME;
 		inode->i_dirt = 1;
 	}
@@ -127,7 +133,11 @@
 		i++;
 		put_user (c, buffer++);
 	}
+#ifdef CONFIG_EXT2_NOATIME
+	if (!IS_RDONLY(inode) && !test_opt(inode->i_sb,NO_ATIME)) {
+#else
 	if (!IS_RDONLY(inode)) {
+#endif
 		inode->i_atime = CURRENT_TIME;
 		inode->i_dirt = 1;
 	}
diff -u --recursive --new-file vanilla/v2.0.29/linux/include/linux/ext2_fs.h linux/include/linux/ext2_fs.h
--- vanilla/v2.0.29/linux/include/linux/ext2_fs.h	Sat Nov 30 05:21:23 1996
+++ linux/include/linux/ext2_fs.h	Fri Feb  7 23:17:26 1997
@@ -296,6 +296,7 @@
 #define EXT2_MOUNT_ERRORS_RO		0x0020	/* Remount fs ro on errors */
 #define EXT2_MOUNT_ERRORS_PANIC		0x0040	/* Panic on errors */
 #define EXT2_MOUNT_MINIX_DF		0x0080	/* Mimics the Minix statfs */
+#define EXT2_MOUNT_NO_ATIME		0x0100  /* Don't update the atime */
 
 #define clear_opt(o, opt)		o &= ~EXT2_MOUNT_##opt
 #define set_opt(o, opt)			o |= EXT2_MOUNT_##opt
diff -u --recursive --new-file vanilla/v2.0.29/linux/include/linux/ip_fw.h linux/include/linux/ip_fw.h
--- vanilla/v2.0.29/linux/include/linux/ip_fw.h	Sun Dec  1 13:06:22 1996
+++ linux/include/linux/ip_fw.h	Sat Mar  8 21:32:55 1997
@@ -57,6 +57,7 @@
 #include <linux/ip.h>
 #include <linux/tcp.h>
 #include <linux/udp.h>
+#include <linux/config.h>
 
 struct ip_fw 
 {
@@ -127,6 +128,9 @@
 #define IP_FW_OUT		2
 #define IP_FW_ACCT		3
 #define IP_FW_CHAINS		4	/* total number of ip_fw chains */
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+#define IP_FW_AUTOFW		5
+#endif
 
 #define IP_FW_INSERT		(IP_FW_BASE_CTL)
 #define IP_FW_APPEND		(IP_FW_BASE_CTL+1)
@@ -167,6 +171,12 @@
 #define IP_ACCT_FLUSH		(IP_FW_FLUSH  | (IP_FW_ACCT << IP_FW_SHIFT))
 #define IP_ACCT_ZERO		(IP_FW_ZERO   | (IP_FW_ACCT << IP_FW_SHIFT))
 
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+#define IP_AUTOFW_ADD		(IP_FW_APPEND | (IP_FW_AUTOFW << IP_FW_SHIFT))
+#define IP_AUTOFW_DEL		(IP_FW_DELETE | (IP_FW_AUTOFW << IP_FW_SHIFT))
+#define IP_AUTOFW_FLUSH  	(IP_FW_FLUSH  | (IP_FW_AUTOFW << IP_FW_SHIFT))
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
+
 struct ip_fwpkt
 {
 	struct iphdr fwp_iph;			/* IP header */
@@ -197,7 +207,6 @@
 #define IP_FW_MODE_ACCT_OUT	0x02	/* accounting (outgoing) */
 #define IP_FW_MODE_CHK		0x04	/* check requested by user */
 
-#include <linux/config.h>
 #ifdef CONFIG_IP_FIREWALL
 extern struct ip_fw *ip_fw_in_chain;
 extern struct ip_fw *ip_fw_out_chain;
@@ -207,6 +216,9 @@
 extern int ip_fw_fwd_policy;
 extern int ip_fw_ctl(int, void *, int);
 #endif
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+extern int ip_autofw_ctl(int, void *, int);
+#endif
 #ifdef CONFIG_IP_ACCT
 extern struct ip_fw *ip_acct_chain;
 extern int ip_acct_ctl(int, void *, int);
@@ -216,4 +228,29 @@
 extern void ip_fw_init(void);
 #endif /* KERNEL */
 
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+#define IP_FWD_RANGE 		1
+#define IP_FWD_PORT		2
+#define IP_FWD_DIRECT		3
+
+#define IP_AUTOFW_ACTIVE	1
+#define IP_AUTOFW_USETIME	2
+#define IP_AUTOFW_SECURE	4
+
+struct ip_autofw {
+	struct ip_autofw * next;
+	__u16 type;
+	__u16 low;
+	__u16 hidden;
+	__u16 high;
+	__u16 visible;
+	__u16 protocol;
+	__u32 lastcontact;
+	__u32 where;
+	__u16 ctlproto;
+	__u16 ctlport;
+	__u16 flags;
+	struct timer_list timer;
+};
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
 #endif /* _IP_FW_H */
diff -u --recursive --new-file vanilla/v2.0.29/linux/include/linux/proc_fs.h linux/include/linux/proc_fs.h
--- vanilla/v2.0.29/linux/include/linux/proc_fs.h	Sun Dec  1 12:59:28 1996
+++ linux/include/linux/proc_fs.h	Sat Mar  8 21:24:19 1997
@@ -104,6 +104,7 @@
 	PROC_NET_IP_MASQ_APP,
 	PROC_NET_STRIP_STATUS,
 	PROC_NET_STRIP_TRACE,
+	PROC_NET_IPAUTOFW,
 	PROC_NET_LAST
 };
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/include/linux/random.h linux/include/linux/random.h
--- vanilla/v2.0.29/linux/include/linux/random.h	Thu Jun  6 06:42:15 1996
+++ linux/include/linux/random.h	Tue Mar  4 12:30:51 1997
@@ -55,6 +55,14 @@
 
 extern __u32 secure_tcp_sequence_number(__u32 saddr, __u32 daddr,
 					__u16 sport, __u16 dport);
+#ifdef CONFIG_RST_COOKIES
+__u32 secure_tcp_probe_number(__u32 saddr, __u32 daddr,
+                 __u16 sport, __u16 dport, __u32 sseq, int validate);
+#endif
+#ifdef CONFIG_SYN_COOKIES
+__u32 secure_tcp_syn_cookie(__u32 saddr, __u32 daddr,
+                 __u16 sport, __u16 dport, __u32 sseq, __u32 count);
+#endif
 
 #ifndef MODULE
 extern struct file_operations random_fops, urandom_fops;
diff -u --recursive --new-file vanilla/v2.0.29/linux/include/net/ip_masq.h linux/include/net/ip_masq.h
--- vanilla/v2.0.29/linux/include/net/ip_masq.h	Sun Dec  1 13:06:22 1996
+++ linux/include/net/ip_masq.h	Sat Mar  8 21:32:55 1997
@@ -8,18 +8,37 @@
 #include <linux/types.h>
 #include <linux/netdevice.h>
 #include <linux/skbuff.h>
+#include <linux/config.h>
+
+/*
+ * This define affects the number of ports that can be handled
+ * by each of the protocol helper modules.
+ */
+#define MAX_MASQ_APP_PORTS 12
 
 /*
  *	Linux ports don't normally get allocated above 32K.
  *	I used an extra 4K port-space
  */
- 
+
 #define PORT_MASQ_BEGIN	61000
 #define PORT_MASQ_END	(PORT_MASQ_BEGIN+4096)
 
+/*
+ * Default timeouts for masquerade functions The control channels now
+ * expire the same as TCP channels (other than being updated by
+ * packets on their associated data channels.
+ */
 #define MASQUERADE_EXPIRE_TCP     15*60*HZ
 #define MASQUERADE_EXPIRE_TCP_FIN  2*60*HZ
 #define MASQUERADE_EXPIRE_UDP      5*60*HZ
+/* 
+ * ICMP can no longer be modified on the fly using an ioctl - this
+ * define is the only way to change the timeouts 
+ */
+#define MASQUERADE_EXPIRE_ICMP      125*HZ
+
+#define IP_AUTOFW_EXPIRE	     15*HZ
 
 #define IP_MASQ_F_OUT_SEQ              	0x01	/* must do output seq adjust */
 #define IP_MASQ_F_IN_SEQ              	0x02	/* must do input seq adjust */
@@ -32,6 +51,9 @@
 #define IP_MASQ_F_SAW_FIN		(IP_MASQ_F_SAW_FIN_IN | \
 					 IP_MASQ_F_SAW_FIN_OUT)
 						/* tcp fin pkts seen */
+#define IP_MASQ_F_CONTROL		0x100 	/* this is a control channel */
+#define IP_MASQ_F_NO_SPORT    		0x200	/* no sport set yet */
+#define IP_MASQ_F_FTP_PASV	    	0x400	/* ftp PASV command just issued */
 
 #ifdef __KERNEL__
 
@@ -59,6 +81,7 @@
 	struct ip_masq_app *app;	/* bound ip_masq_app object */
 	void		*app_data;	/* Application private data */
 	unsigned  flags;        	/* status flags */
+	struct ip_masq	*control;	/* Corresponding control connection */
 };
 
 /*
@@ -76,9 +99,10 @@
 /*
  *	[0]: UDP free_ports
  *	[1]: TCP free_ports
+ *	[2]: ICMP free ids
  */
 
-extern int ip_masq_free_ports[2];
+extern int ip_masq_free_ports[3];
 
 /*
  *	ip_masq initializer (registers symbols and /proc/net entries)
@@ -98,6 +122,9 @@
 extern struct ip_masq *ip_masq_new(struct device *dev, int proto, __u32 saddr, __u16 sport, __u32 daddr, __u16 dport, unsigned flags);
 extern void ip_masq_set_expire(struct ip_masq *ms, unsigned long tout);
 
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+extern void ip_autofw_expire(unsigned long data);
+#endif
 
 /*
  * 	
@@ -166,6 +193,10 @@
  *	a segment of skb.
  */
 extern struct sk_buff * ip_masq_skb_replace(struct sk_buff *skb, int pri, char *o_buf, int o_len, char *n_buf, int n_len);
+
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+extern struct ip_autofw * ip_autofw_hosts;
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
 
 #endif /* __KERNEL__ */
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/include/net/raw.h linux/include/net/raw.h
--- vanilla/v2.0.29/linux/include/net/raw.h	Mon Sep 11 13:15:53 1995
+++ linux/include/net/raw.h	Mon Mar  3 02:57:25 1997
@@ -31,4 +31,14 @@
 extern int 	raw_rcv(struct sock *, struct sk_buff *, struct device *, 
 			__u32, __u32);
 
+/* Note: v4 ICMP wants to get at this stuff, if you change the
+ *       hashing mechanism, make sure you update icmp.c as well.
+ */
+#define RAWV4_HTABLE_SIZE	MAX_INET_PROTOS
+extern struct sock *raw_v4_htable[RAWV4_HTABLE_SIZE];
+
+
+extern struct sock *raw_v4_lookup(struct sock *sk, unsigned short num,
+				  unsigned long raddr, unsigned long laddr);
+
 #endif	/* _RAW_H */
diff -u --recursive --new-file vanilla/v2.0.29/linux/include/net/sock.h linux/include/net/sock.h
--- vanilla/v2.0.29/linux/include/net/sock.h	Sun Dec  1 13:01:21 1996
+++ linux/include/net/sock.h	Sat Mar  8 21:26:18 1997
@@ -22,6 +22,7 @@
  *		Alan Cox	:	New fields for options
  *	Pauline Middelink	:	identd support
  *		Alan Cox	:	Eliminate low level recv/recvfrom
+ *		David S. Miller	:	New socket lookup architecture for ISS.
  *
  *		This program is free software; you can redistribute it and/or
  *		modify it under the terms of the GNU General Public License
@@ -59,10 +60,6 @@
 
 #include <asm/atomic.h>
 
-/* Think big (also on some systems a byte is faster) */
-#define SOCK_ARRAY_SIZE	256
-
-
 /*
  *	The AF_UNIX specific socket options
  */
@@ -155,6 +152,10 @@
  */
 struct sock 
 {
+	/* This must be first. */
+	struct sock		*sklist_next;
+	struct sock		*sklist_prev;
+
 	struct options		*opt;
 	atomic_t		wmem_alloc;
 	atomic_t		rmem_alloc;
@@ -193,9 +194,14 @@
 				bsdism;
 	unsigned long	        lingertime;
 	int			proc;
+
 	struct sock		*next;
-	struct sock		*prev; /* Doubly linked chain.. */
+	struct sock		**pprev;
+	struct sock		*bind_next;
+	struct sock		**bind_pprev;
 	struct sock		*pair;
+	int			hashent;
+	struct sock		*prev;
 	struct sk_buff		* volatile send_head;
 	struct sk_buff		* volatile send_next;
 	struct sk_buff		* volatile send_tail;
@@ -337,6 +343,10 @@
  
 struct proto 
 {
+	/* These must be first. */
+	struct sock		*sklist_next;
+	struct sock		*sklist_prev;
+
 	void			(*close)(struct sock *sk, unsigned long timeout);
 	int			(*build_header)(struct sk_buff *skb,
 					__u32 saddr,
@@ -372,11 +382,18 @@
 	int			(*recvmsg)(struct sock *sk, struct msghdr *msg, int len,
 					int noblock, int flags, int *addr_len);
 	int			(*bind)(struct sock *sk, struct sockaddr *uaddr, int addr_len);
+
+	/* Keeping track of sk's, looking them up, and port selection methods. */
+	void			(*hash)(struct sock *sk);
+	void			(*unhash)(struct sock *sk);
+	void			(*rehash)(struct sock *sk);
+	unsigned short		(*good_socknum)(void);
+	int			(*verify_bind)(struct sock *sk, unsigned short snum);
+
 	unsigned short		max_header;
 	unsigned long		retransmits;
 	char			name[32];
 	int			inuse, highestinuse;
-	struct sock *		sock_array[SOCK_ARRAY_SIZE];
 };
 
 #define TIME_WRITE	1
@@ -402,6 +419,46 @@
 #define RCV_SHUTDOWN	1
 #define SEND_SHUTDOWN	2
 
+/* Per-protocol hash table implementations use this to make sure
+ * nothing changes.
+ */
+#define SOCKHASH_LOCK()		start_bh_atomic()
+#define SOCKHASH_UNLOCK()	end_bh_atomic()
+
+/* Some things in the kernel just want to get at a protocols
+ * entire socket list commensurate, thus...
+ */
+static __inline__ void add_to_prot_sklist(struct sock *sk)
+{
+	SOCKHASH_LOCK();
+	if(!sk->sklist_next) {
+		struct proto *p = sk->prot;
+
+		sk->sklist_prev = (struct sock *) p;
+		sk->sklist_next = p->sklist_next;
+		p->sklist_next->sklist_prev = sk;
+		p->sklist_next = sk;
+
+		/* Charge the protocol. */
+		sk->prot->inuse += 1;
+		if(sk->prot->highestinuse < sk->prot->inuse)
+			sk->prot->highestinuse = sk->prot->inuse;
+	}
+	SOCKHASH_UNLOCK();
+}
+
+static __inline__ void del_from_prot_sklist(struct sock *sk)
+{
+	SOCKHASH_LOCK();
+	if(sk->sklist_next) {
+		sk->sklist_next->sklist_prev = sk->sklist_prev;
+		sk->sklist_prev->sklist_next = sk->sklist_next;
+		sk->sklist_next = NULL;
+		sk->prot->inuse--;
+	}
+	SOCKHASH_UNLOCK();
+}
+
 /*
  * Used by processes to "lock" a socket state, so that
  * interrupts and bottom half handlers won't change it
@@ -449,18 +506,6 @@
 extern struct sock *		sk_alloc(int priority);
 extern void			sk_free(struct sock *sk);
 extern void			destroy_sock(struct sock *sk);
-extern unsigned short		get_new_socknum(struct proto *,
-						unsigned short);
-extern void			put_sock(unsigned short, struct sock *); 
-extern struct sock		*get_sock(struct proto *, unsigned short,
-					  unsigned long, unsigned short,
-					  unsigned long,
-					  unsigned long, unsigned short);
-extern struct sock		*get_sock_mcast(struct sock *, unsigned short,
-					  unsigned long, unsigned short,
-					  unsigned long);
-extern struct sock		*get_sock_raw(struct sock *, unsigned short,
-					  unsigned long, unsigned long);
 
 extern struct sk_buff		*sock_wmalloc(struct sock *sk,
 					      unsigned long size, int force,
diff -u --recursive --new-file vanilla/v2.0.29/linux/include/net/tcp.h linux/include/net/tcp.h
--- vanilla/v2.0.29/linux/include/net/tcp.h	Sun Dec  1 13:01:21 1996
+++ linux/include/net/tcp.h	Sat Mar  8 21:31:58 1997
@@ -21,6 +21,87 @@
 #include <linux/tcp.h>
 #include <net/checksum.h>
 
+/* This is for all connections with a full identity, no wildcards. */
+#define TCP_HTABLE_SIZE		256
+
+/* This is for listening sockets, thus all sockets which possess wildcards. */
+#define TCP_LHTABLE_SIZE	32	/* Yes, really, this is all you need. */
+
+/* This is for all sockets, to keep track of the local port allocations. */
+#define TCP_BHTABLE_SIZE	64
+
+/* tcp_ipv4.c: These need to be shared by v4 and v6 because the lookup
+ *             and hashing code needs to work with different AF's yet
+ *             the port space is shared.
+ */
+extern struct sock *tcp_established_hash[TCP_HTABLE_SIZE];
+extern struct sock *tcp_listening_hash[TCP_LHTABLE_SIZE];
+extern struct sock *tcp_bound_hash[TCP_BHTABLE_SIZE];
+
+/* These are AF independant. */
+static __inline__ int tcp_bhashfn(__u16 lport)
+{
+	return (lport ^ (lport >> 7)) & (TCP_BHTABLE_SIZE - 1);
+}
+
+static __inline__ int tcp_sk_bhashfn(struct sock *sk)
+{
+	__u16 lport = sk->num;
+	return tcp_bhashfn(lport);
+}
+
+/* These can have wildcards, don't try too hard.
+ * XXX deal with thousands of IP aliases for listening ports later
+ */
+static __inline__ int tcp_lhashfn(unsigned short num)
+{
+	return num & (TCP_LHTABLE_SIZE - 1);
+}
+
+static __inline__ int tcp_sk_listen_hashfn(struct sock *sk)
+{
+	return tcp_lhashfn(sk->num);
+}
+
+/* This is IPv4 specific. */
+static __inline__ int tcp_hashfn(__u32 laddr, __u16 lport,
+				 __u32 faddr, __u16 fport)
+{
+	return ((laddr ^ lport) ^ (faddr ^ fport)) & (TCP_HTABLE_SIZE - 1);
+}
+
+static __inline__ int tcp_sk_hashfn(struct sock *sk)
+{
+	__u32 laddr = sk->rcv_saddr;
+	__u16 lport = sk->num;
+	__u32 faddr = sk->daddr;
+	__u16 fport = sk->dummy_th.dest;
+
+	return tcp_hashfn(laddr, lport, faddr, fport);
+}
+
+/* Only those holding the sockhash lock call these two things here.
+ * Note the slightly gross overloading of sk->prev, AF_UNIX is the
+ * only other main benefactor of that member of SK, so who cares.
+ */
+static __inline__ void tcp_sk_bindify(struct sock *sk)
+{
+	int hashent = tcp_sk_bhashfn(sk);
+	struct sock **htable = &tcp_bound_hash[hashent];
+
+	if((sk->bind_next = *htable) != NULL)
+		(*htable)->bind_pprev = &sk->bind_next;
+	*htable = sk;
+	sk->bind_pprev = htable;
+}
+
+static __inline__ void tcp_sk_unbindify(struct sock *sk)
+{
+	if(sk->bind_next)
+		sk->bind_next->bind_pprev = sk->bind_pprev;
+	*(sk->bind_pprev) = sk->bind_next;
+}
+
 /*
  * 40 is maximal IP options size
  * 4  is TCP option size (MSS)
@@ -65,7 +146,7 @@
 #define TCP_WRITE_TIME	(30*HZ)	/* initial time to wait for an ACK,
 			         * after last transmit			*/
 #define TCP_TIMEOUT_INIT (3*HZ)	/* RFC 1122 initial timeout value	*/
-#define TCP_SYN_RETRIES	 10	/* number of times to retry opening a
+#define TCP_SYN_RETRIES	 5	/* number of times to retry opening a
 				 * connection 	(TCP_RETR2-....)	*/
 #define TCP_PROBEWAIT_LEN (1*HZ)/* time to wait between probes when
 				 * I've got something to write and
@@ -128,6 +209,8 @@
 extern struct proto tcp_prot;
 extern struct tcp_mib tcp_statistics;
 
+extern unsigned short		tcp_good_socknum(void);
+
 extern void	tcp_err(int type, int code, unsigned char *header, __u32 daddr,
 			__u32, struct inet_protocol *protocol, int len);
 extern void	tcp_shutdown (struct sock *sk, int how);
@@ -152,7 +235,7 @@
 extern void tcp_send_partial(struct sock *);
 extern void tcp_write_wakeup(struct sock *);
 extern void tcp_send_fin(struct sock *sk);
-extern void tcp_send_synack(struct sock *, struct sock *, struct sk_buff *);
+extern void tcp_send_synack(struct sock *, struct sock *, struct sk_buff *, int);
 extern void tcp_send_skb(struct sock *, struct sk_buff *);
 extern void tcp_send_ack(struct sock *sk);
 extern void tcp_send_delayed_ack(struct sock *sk, int max_timeout, unsigned long timeout);
@@ -163,9 +246,6 @@
 extern struct sk_buff * tcp_dequeue_partial(struct sock *);
 extern void tcp_shrink_skb(struct sock *,struct sk_buff *,u32);
 
-/* tcp_input.c */
-extern void tcp_cache_zap(void);
-
 /* CONFIG_IP_TRANSPARENT_PROXY */
 extern int tcp_chkaddr(struct sk_buff *);
 
@@ -262,7 +342,6 @@
 		break;
 
 	case TCP_CLOSE:
-		tcp_cache_zap();
 		/* Should be about 2 rtt's */
 		reset_timer(sk, TIME_DONE, min(sk->rtt * 2, TCP_DONE_TIME));
 		/* fall through */
diff -u --recursive --new-file vanilla/v2.0.29/linux/include/net/udp.h linux/include/net/udp.h
--- vanilla/v2.0.29/linux/include/net/udp.h	Thu Nov 14 08:20:10 1996
+++ linux/include/net/udp.h	Mon Mar  3 03:01:40 1997
@@ -24,6 +24,15 @@
 
 #include <linux/udp.h>
 
+#define UDP_HTABLE_SIZE		128
+
+/* udp.c: This needs to be shared by v4 and v6 because the lookup
+ *        and hashing code needs to work with different AF's yet
+ *        the port space is shared.
+ */
+extern struct sock *udp_hash[UDP_HTABLE_SIZE];
+
+extern unsigned short udp_good_socknum(void);
 
 #define UDP_NO_CHECK	0
 
@@ -47,7 +56,6 @@
 			unsigned short len, __u32 saddr, int redo,
 			struct inet_protocol *protocol);
 extern int	udp_ioctl(struct sock *sk, int cmd, unsigned long arg);
-extern void	udp_cache_zap(void);	/* Remove udp last socket cache */
 
 /* CONFIG_IP_TRANSPARENT_PROXY */
 extern int	udp_chkaddr(struct sk_buff *skb);
diff -u --recursive --new-file vanilla/v2.0.29/linux/kernel/sched.c linux/kernel/sched.c
--- vanilla/v2.0.29/linux/kernel/sched.c	Thu Feb  6 10:21:29 1997
+++ linux/kernel/sched.c	Sat Mar  8 14:13:45 1997
@@ -4,6 +4,7 @@
  *  Copyright (C) 1991, 1992  Linus Torvalds
  *
  *  1996-04-21	Modified by Ulrich Windl to make NTP work
+ *  1997-01-28  Modified by Finn Arne Gangstad to make timers scale better.
  */
 
 /*
@@ -596,70 +594,170 @@
 	__sleep_on(p,TASK_UNINTERRUPTIBLE);
 }
 
-/*
- * The head for the timer-list has a "expires" field of MAX_UINT,
- * and the sorting routine counts on this..
- */
-static struct timer_list timer_head = { &timer_head, &timer_head, ~0, 0, NULL };
+#define TVN_BITS 6
+#define TVR_BITS 8
+#define TVN_SIZE (1 << TVN_BITS)
+#define TVR_SIZE (1 << TVR_BITS)
+#define TVN_MASK (TVN_SIZE - 1)
+#define TVR_MASK (TVR_SIZE - 1)
+
 #define SLOW_BUT_DEBUGGING_TIMERS 0
 
-void add_timer(struct timer_list * timer)
+struct timer_vec {
+        int index;
+        struct timer_list *vec[TVN_SIZE];
+};
+
+struct timer_vec_root {
+        int index;
+        struct timer_list *vec[TVR_SIZE];
+};
+
+static struct timer_vec tv5 = { 0 };
+static struct timer_vec tv4 = { 0 };
+static struct timer_vec tv3 = { 0 };
+static struct timer_vec tv2 = { 0 };
+static struct timer_vec_root tv1 = { 0 };
+
+static struct timer_vec * const tvecs[] = {
+	(struct timer_vec *)&tv1, &tv2, &tv3, &tv4, &tv5
+};
+
+#define NOOF_TVECS (sizeof(tvecs) / sizeof(tvecs[0]))
+
+static unsigned long timer_jiffies = 0;
+
+static inline void insert_timer(struct timer_list *timer,
+				struct timer_list **vec, int idx)
 {
-	unsigned long flags;
-	struct timer_list *p;
+	if ((timer->next = vec[idx]))
+		vec[idx]->prev = timer;
+	vec[idx] = timer;
+	timer->prev = (struct timer_list *)&vec[idx];
+}
 
-#if SLOW_BUT_DEBUGGING_TIMERS
-	if (timer->next || timer->prev) {
-		printk("add_timer() called with non-zero list from %p\n",
-			__builtin_return_address(0));
-		return;
+static inline void internal_add_timer(struct timer_list *timer)
+{
+	/*
+	 * must be cli-ed when calling this
+	 */
+	unsigned long expires = timer->expires;
+	unsigned long idx = expires - timer_jiffies;
+
+	if (idx < TVR_SIZE) {
+		int i = expires & TVR_MASK;
+		insert_timer(timer, tv1.vec, i);
+	} else if (idx < 1 << (TVR_BITS + TVN_BITS)) {
+		int i = (expires >> TVR_BITS) & TVN_MASK;
+		insert_timer(timer, tv2.vec, i);
+	} else if (idx < 1 << (TVR_BITS + 2 * TVN_BITS)) {
+		int i = (expires >> (TVR_BITS + TVN_BITS)) & TVN_MASK;
+		insert_timer(timer, tv3.vec, i);
+	} else if (idx < 1 << (TVR_BITS + 3 * TVN_BITS)) {
+		int i = (expires >> (TVR_BITS + 2 * TVN_BITS)) & TVN_MASK;
+		insert_timer(timer, tv4.vec, i);
+	} else if (expires < timer_jiffies) {
+		/* can happen if you add a timer with expires == jiffies,
+		 * or you set a timer to go off in the past
+		 */
+		insert_timer(timer, tv1.vec, tv1.index);
+	} else if (idx < 0xffffffffUL) {
+		int i = (expires >> (TVR_BITS + 3 * TVN_BITS)) & TVN_MASK;
+		insert_timer(timer, tv5.vec, i);
+	} else {
+		/* Can only get here on architectures with 64-bit jiffies */
+		timer->next = timer->prev = timer;
 	}
-#endif
-	p = &timer_head;
+}
+
+void add_timer(struct timer_list *timer)
+{
+	unsigned long flags;
 	save_flags(flags);
 	cli();
-	do {
-		p = p->next;
-	} while (timer->expires > p->expires);
-	timer->next = p;
-	timer->prev = p->prev;
-	p->prev = timer;
-	timer->prev->next = timer;
+#if SLOW_BUT_DEBUGGING_TIMERS
+        if (timer->next || timer->prev) {
+                printk("add_timer() called with non-zero list from %p\n",
+		       __builtin_return_address(0));
+		goto out;
+        }
+#endif
+	internal_add_timer(timer);
+#if SLOW_BUT_DEBUGGING_TIMERS
+out:
+#endif
 	restore_flags(flags);
 }
 
-int del_timer(struct timer_list * timer)
+static inline int detach_timer(struct timer_list *timer)
 {
 	int ret = 0;
-	if (timer->next) {
-		unsigned long flags;
-		struct timer_list * next;
-		save_flags(flags);
-		cli();
-		if ((next = timer->next) != NULL) {
-			(next->prev = timer->prev)->next = next;
-			timer->next = timer->prev = NULL;
-			ret = 1;
-		}
-		restore_flags(flags);
+	struct timer_list *next, *prev;
+	next = timer->next;
+	prev = timer->prev;
+	if (next) {
+		next->prev = prev;
+	}
+	if (prev) {
+		ret = 1;
+		prev->next = next;
 	}
 	return ret;
 }
 
-static inline void run_timer_list(void)
+
+int del_timer(struct timer_list * timer)
+{
+	int ret;
+	unsigned long flags;
+	save_flags(flags);
+	cli();
+	ret = detach_timer(timer);
+	timer->next = timer->prev = 0;
+	restore_flags(flags);
+	return ret;
+}
+
+static inline void cascade_timers(struct timer_vec *tv)
 {
-	struct timer_list * timer;
+        /* cascade all the timers from tv up one level */
+        struct timer_list *timer;
+        timer = tv->vec[tv->index];
+        /*
+         * We are removing _all_ timers from the list, so we don't  have to
+         * detach them individually, just clear the list afterwards.
+         */
+        while (timer) {
+                struct timer_list *tmp = timer;
+                timer = timer->next;
+                internal_add_timer(tmp);
+        }
+        tv->vec[tv->index] = NULL;
+        tv->index = (tv->index + 1) & TVN_MASK;
+}
 
+static inline void run_timer_list(void)
+{
 	cli();
-	while ((timer = timer_head.next) != &timer_head && timer->expires <= jiffies) {
-		void (*fn)(unsigned long) = timer->function;
-		unsigned long data = timer->data;
-		timer->next->prev = timer->prev;
-		timer->prev->next = timer->next;
-		timer->next = timer->prev = NULL;
-		sti();
-		fn(data);
-		cli();
+	while ((long)(jiffies - timer_jiffies) >= 0) {
+		struct timer_list *timer;
+		if (!tv1.index) {
+			int n = 1;
+			do {
+				cascade_timers(tvecs[n]);
+			} while (tvecs[n]->index == 1 && ++n < NOOF_TVECS);
+		}
+		while ((timer = tv1.vec[tv1.index])) {
+			void (*fn)(unsigned long) = timer->function;
+			unsigned long data = timer->data;
+			detach_timer(timer);
+			timer->next = timer->prev = NULL;
+			sti();
+			fn(data);
+			cli();
+		}
+		++timer_jiffies; 
+		tv1.index = (tv1.index + 1) & TVR_MASK;
 	}
 	sti();
 }
diff -u --recursive --new-file vanilla/v2.0.29/linux/mm/filemap.c linux/mm/filemap.c
--- vanilla/v2.0.29/linux/mm/filemap.c	Wed Sep 11 10:57:19 1996
+++ linux/mm/filemap.c	Fri Feb  7 23:08:02 1997
@@ -9,6 +9,8 @@
  * most "normal" filesystems (but you don't /have/ to use this:
  * the NFS filesystem does this differently, for example)
  */
+#include <linux/autoconf.h>	/* For CONFIG_EXT2_NOATIME if enabled. */
+
 #include <linux/stat.h>
 #include <linux/sched.h>
 #include <linux/kernel.h>
@@ -743,6 +745,14 @@
 	filp->f_reada = 1;
 	if (page_cache)
 		free_page(page_cache);
+#ifdef CONFIG_EXT2_NOATIME
+	if (inode->i_sb->s_magic==EXT2_SUPER_MAGIC) {
+		if (!IS_RDONLY(inode) && !test_opt(inode->i_sb, NO_ATIME)) {
+			inode->i_atime = CURRENT_TIME;
+			inode->i_dirt = 1;
+		}
+	} else
+#endif
 	if (!IS_RDONLY(inode)) {
 		inode->i_atime = CURRENT_TIME;
 		inode->i_dirt = 1;
@@ -1178,6 +1188,14 @@
 		return -EACCES;
 	if (!inode->i_op || !inode->i_op->readpage)
 		return -ENOEXEC;
+#ifdef CONFIG_EXT2_NOATIME
+	if (inode->i_sb->s_magic==EXT2_SUPER_MAGIC) {
+		if (!IS_RDONLY(inode) && !test_opt(inode->i_sb, NO_ATIME)) {
+			inode->i_atime = CURRENT_TIME;
+			inode->i_dirt = 1;
+		}
+	} else
+#endif
 	if (!IS_RDONLY(inode)) {
 		inode->i_atime = CURRENT_TIME;
 		inode->i_dirt = 1;
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/core/skbuff.c linux/net/core/skbuff.c
--- vanilla/v2.0.29/linux/net/core/skbuff.c	Thu Jun  6 02:45:39 1996
+++ linux/net/core/skbuff.c	Sat Mar  8 19:31:24 1997
@@ -575,6 +575,8 @@
 
 void kfree_skb(struct sk_buff *skb, int rw)
 {
+	unsigned long flags;
+
 	if (skb == NULL)
 	{
 		printk(KERN_CRIT "kfree_skb: skb = NULL (from %p)\n",
@@ -584,12 +586,15 @@
 #if CONFIG_SKB_CHECK
 	IS_SKB(skb);
 #endif
+	save_flags(flags); cli();
 	if (skb->lock)
 	{
 		skb->free = 3;    /* Free when unlocked */
 		net_free_locked++;
+		restore_flags(flags);
 		return;
   	}
+	restore_flags(flags);
   	if (skb->free == 2)
 		printk(KERN_WARNING "Warning: kfree_skb passed an skb that nobody set the free flag on! (from %p)\n",
 			__builtin_return_address(0));
@@ -831,21 +836,29 @@
 
 void skb_device_lock(struct sk_buff *skb)
 {
+	unsigned long flags;
+
+	save_flags(flags); cli();
 	if(skb->lock)
 		printk("double lock on device queue, lock=%d caller=%p\n",
 			skb->lock, (&skb)[-1]);
 	else
 		net_locked++;
 	skb->lock++;
+	restore_flags(flags);
 }
 
 void skb_device_unlock(struct sk_buff *skb)
 {
+	unsigned long flags;
+
+	save_flags(flags); cli();
 	if(skb->lock==0)
 		printk("double unlock on device queue!\n");
 	skb->lock--;
 	if(skb->lock==0)
 		net_locked--;
+	restore_flags(flags);
 }
 
 void dev_kfree_skb(struct sk_buff *skb, int mode)
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/Config.in linux/net/ipv4/Config.in
--- vanilla/v2.0.29/linux/net/ipv4/Config.in	Fri Jul 19 01:24:05 1996
+++ linux/net/ipv4/Config.in	Wed Mar  5 07:42:33 1997
@@ -3,14 +3,18 @@
 #
 bool 'IP: forwarding/gatewaying' CONFIG_IP_FORWARD
 bool 'IP: multicasting' CONFIG_IP_MULTICAST
+bool 'IP: syn cookies' CONFIG_SYN_COOKIES
+bool 'IP: rst cookies' CONFIG_RST_COOKIES
 if [ "$CONFIG_FIREWALL" = "y" ]; then
   bool 'IP: firewalling' CONFIG_IP_FIREWALL
   if [ "$CONFIG_IP_FIREWALL" = "y" ]; then
     bool 'IP: firewall packet logging' CONFIG_IP_FIREWALL_VERBOSE
-    if [ "$CONFIG_EXPERIMENTAL" = "y" -a "$CONFIG_IP_FORWARD" = "y" ]; then
-      bool 'IP: masquerading (EXPERIMENTAL)' CONFIG_IP_MASQUERADE
+    if [ "$CONFIG_IP_FORWARD" = "y" ]; then
+      bool 'IP: masquerading' CONFIG_IP_MASQUERADE
       if [ "$CONFIG_IP_MASQUERADE" != "n" ]; then
         comment 'Protocol-specific masquerading support will be built as modules.'
+        bool 'IP: ipautofw masq support' CONFIG_IP_MASQUERADE_IPAUTOFW
+        bool 'IP: ICMP masquerading' CONFIG_IP_MASQUERADE_ICMP
       fi
       bool 'IP: transparent proxy support (EXPERIMENTAL)' CONFIG_IP_TRANSPARENT_PROXY
       bool 'IP: always defragment' CONFIG_IP_ALWAYS_DEFRAG
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/Makefile linux/net/ipv4/Makefile
--- vanilla/v2.0.29/linux/net/ipv4/Makefile	Fri May 31 06:46:27 1996
+++ linux/net/ipv4/Makefile	Tue Mar  4 05:51:40 1997
@@ -40,7 +40,8 @@
 
 ifeq ($(CONFIG_IP_MASQUERADE),y)
 IPV4_OBJS += ip_masq.o ip_masq_app.o
-M_OBJS += ip_masq_ftp.o ip_masq_irc.o ip_masq_raudio.o
+M_OBJS += ip_masq_ftp.o ip_masq_irc.o ip_masq_raudio.o ip_masq_cuseeme.o 
+M_OBJS += ip_masq_vdolive.o ip_masq_quake.o
 endif
 
 ifeq ($(CONFIG_IP_ALIAS),y)
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/af_inet.c linux/net/ipv4/af_inet.c
--- vanilla/v2.0.29/linux/net/ipv4/af_inet.c	Fri Oct 18 00:18:54 1996
+++ linux/net/ipv4/af_inet.c	Sat Mar  8 20:27:56 1997
@@ -50,6 +50,7 @@
  *		Alan Cox	:	Loosened bind a little.
  *		Mike McLagan	:	ADD/DEL DLCI Ioctls
  *	Willy Konynenberg	:	Transparent proxying support.
+ *		David S. Miller	:	New socket lookup architecture for ISS.
  *
  *		This program is free software; you can redistribute it and/or
  *		modify it under the terms of the GNU General Public License
@@ -125,236 +126,27 @@
 int (*rarp_ioctl_hook)(unsigned int,void*) = NULL;
 
 /*
- *	See if a socket number is in use.
- */
- 
-static int sk_inuse(struct proto *prot, int num)
-{
-	struct sock *sk;
-
-	for(sk = prot->sock_array[num & (SOCK_ARRAY_SIZE -1 )];
-		sk != NULL;  sk=sk->next) 
-	{
-		if (sk->num == num) 
-			return(1);
-	}
-	return(0);
-}
-
-
-/*
- *	Pick a new socket number
- */
-
-unsigned short get_new_socknum(struct proto *prot, unsigned short base)
-{
-	static int start=0;
-
-	/*
-	 * Used to cycle through the port numbers so the
-	 * chances of a confused connection drop.
-	 */
-	 
-	int i, j;
-	int best = 0;
-	int size = 32767; /* a big num. */
-	struct sock *sk;
-
-	if (base == 0) 
-		base = PROT_SOCK+1+(start & 1023);
-	if (base <= PROT_SOCK) 
-	{
-		base += PROT_SOCK+(start & 1023);
-	}
-
-	/*
-	 *	Now look through the entire array and try to find an empty ptr. 
-	 */
-	 
-	for(i=0; i < SOCK_ARRAY_SIZE; i++) 
-	{
-		j = 0;
-		sk = prot->sock_array[(i+base+1) &(SOCK_ARRAY_SIZE -1)];
-		while(sk != NULL) 
-		{
-			sk = sk->next;
-			j++;
-		}
-		if (j == 0) 
-		{
-			start =(i+1+start )&1023;
-			return(i+base+1);
-		}
-		if (j < size) 
-		{
-			best = i;
-			size = j;
-		}
-	}
-
-	/* Now make sure the one we want is not in use. */
-
-	while(sk_inuse(prot, base +best+1)) 
-	{
-		best += SOCK_ARRAY_SIZE;
-	}
-	return(best+base+1);
-}
-
-/*
- *	Add a socket into the socket tables by number.
- */
-
-void put_sock(unsigned short num, struct sock *sk)
-{
-	struct sock **skp, *tmp;
-	int mask;
-	unsigned long flags;
-	
-	if(sk->type==SOCK_PACKET)
-		return;
-
-	sk->num = num;
-	sk->next = NULL;
-	num = num &(SOCK_ARRAY_SIZE -1);
-
-	/* 
-	 *	We can't have an interrupt re-enter here. 
-	 */
-	 
-	save_flags(flags);
-	cli();
-
-	sk->prot->inuse += 1;
-	if (sk->prot->highestinuse < sk->prot->inuse)
-		sk->prot->highestinuse = sk->prot->inuse;
-
-	if (sk->prot->sock_array[num] == NULL) 
-	{
-		sk->prot->sock_array[num] = sk;
-		restore_flags(flags);
-		return;
-	}
-	
-	restore_flags(flags);
-	for(mask = 0xff000000; mask != 0xffffffff; mask = (mask >> 8) | mask) 
-	{
-		if ((mask & sk->rcv_saddr) &&
-		    (mask & sk->rcv_saddr) != (mask & 0xffffffff)) 
-		{
-			mask = mask << 8;
-			break;
-		}
-	}
-
-	/*
-	 * add the socket to the sock_array[]..
-	 */
-	skp = sk->prot->sock_array + num;
-	cli();
-	while ((tmp = *skp) != NULL) {
-		if (!(tmp->rcv_saddr & mask))
-			break;
-		skp = &tmp->next;
-	}
-	sk->next = tmp;
-	*skp = sk;
-	sti();
-}
-
-/*
- *	Remove a socket from the socket tables.
- */
-
-static void remove_sock(struct sock *sk1)
-{
-	struct sock **p;
-	unsigned long flags;
-
-	if (sk1->type==SOCK_PACKET)
-		return;
-		
-	if (!sk1->prot) 
-	{
-		NETDEBUG(printk("sock.c: remove_sock: sk1->prot == NULL\n"));
-		return;
-	}
-
-	/* We can't have this changing out from under us. */
-	save_flags(flags);
-	cli();
-	
-	p=&(sk1->prot->sock_array[sk1->num & (SOCK_ARRAY_SIZE -1)]);
-	
-	while(*p!=NULL)
-	{
-		if(*p==sk1)
-		{
-			sk1->prot->inuse--;
-			*p=sk1->next;
-			break;
-		}
-		p=&((*p)->next);
-	}
-	restore_flags(flags);
-}
-
-/*
  *	Destroy an AF_INET socket
  */
  
-void destroy_sock(struct sock *sk)
+static __inline__ void kill_sk_queues(struct sock *sk)
 {
 	struct sk_buff *skb;
 
-	lock_sock(sk);			/* just to be safe. */
-
-  	remove_sock(sk);
-  
-  	/*
-  	 *	Now we can no longer get new packets or once the
-  	 *	timers are killed, send them.
-  	 */
-  	 
-  	delete_timer(sk);
-	del_timer(&sk->delack_timer);
-	del_timer(&sk->retransmit_timer);
-	
-	/*
-	 *	Drain any partial frames
-	 */
-	 
-	while ((skb = tcp_dequeue_partial(sk)) != NULL) 
-	{
-		IS_SKB(skb);
+	while((skb = tcp_dequeue_partial(sk)) != NULL)
 		kfree_skb(skb, FREE_WRITE);
-	}
 
-	/*
-	 *	Cleanup up the write buffer. 
-	 */
-	 
-  	while((skb = skb_dequeue(&sk->write_queue)) != NULL) {
-		IS_SKB(skb);
+	/* Next, the write queue. */
+	while((skb = skb_dequeue(&sk->write_queue)) != NULL)
 		kfree_skb(skb, FREE_WRITE);
-  	}
-  	
-  	/*
-  	 *	Clean up the read buffer.
-  	 */
 
-	while((skb=skb_dequeue(&sk->receive_queue))!=NULL) 
-	{
-		/*
-		 * This will take care of closing sockets that were
+	/* Then, the receive queue. */
+	while((skb = skb_dequeue(&sk->receive_queue)) != NULL) {
+		/* This will take care of closing sockets that were
 		 * listening and didn't accept everything.
 		 */
-		if (skb->sk != NULL && skb->sk != sk) 
-		{
-			IS_SKB(skb);
+		if (skb->sk != NULL && skb->sk != sk)
 			skb->sk->prot->close(skb->sk, 0);
-		}
-		IS_SKB(skb);
 		kfree_skb(skb, FREE_READ);
 	}
 
@@ -386,16 +178,61 @@
 	sk->send_next = NULL;
 	sti();
 
+  	/* Finally, the backlog. */
+  	while((skb=skb_dequeue(&sk->back_log)) != NULL) {
+		/* skb->sk = NULL; */
+		kfree_skb(skb, FREE_READ);
+	}
+}
+
+static __inline__ void kill_sk_now(struct sock *sk)
+{
+	/* No longer exists. */
+	del_from_prot_sklist(sk);
+
+	/* This is gross, but needed for SOCK_PACKET -DaveM */
+	if(sk->prot->unhash)
+		sk->prot->unhash(sk);
+
+	if(sk->opt)
+		kfree(sk->opt);
+	ip_rt_put(sk->ip_route_cache);
+	sk_free(sk);
+}
+
+static __inline__ void kill_sk_later(struct sock *sk)
+{
+	/* this should never happen. */
+	/* actually it can if an ack has just been sent. */
+	/* 
+	 * It's more normal than that...
+	 * It can happen because a skb is still in the device queues
+	 * [PR]
+	 */
+		  
+	NETDEBUG(printk("Socket destroy delayed (r=%d w=%d)\n",
+			sk->rmem_alloc, sk->wmem_alloc));
+
+	sk->destroy = 1;
+	sk->ack_backlog = 0;
+	release_sock(sk);
+	reset_timer(sk, TIME_DESTROY, SOCK_DESTROY_TIME);
+}
+
+void destroy_sock(struct sock *sk)
+{
+	lock_sock(sk);			/* just to be safe. */
+
   	/*
-  	 *	Now the backlog. 
+  	 *	Now we can no longer get new packets or once the
+  	 *	timers are killed, send them.
   	 */
   	 
-  	while((skb=skb_dequeue(&sk->back_log))!=NULL) 
-  	{
-		/* this should [almost] never happen. */
-		skb->sk = NULL;
-		kfree_skb(skb, FREE_READ);
-	}
+  	delete_timer(sk);
+	del_timer(&sk->delack_timer);
+	del_timer(&sk->retransmit_timer);
+	
+	kill_sk_queues(sk);
 
 	/*
 	 *	Now if it has a half accepted/ closed socket. 
@@ -414,28 +251,9 @@
 	 */
 
 	if (sk->rmem_alloc == 0 && sk->wmem_alloc == 0) 
-	{
-		if(sk->opt)
-			kfree(sk->opt);
-		ip_rt_put(sk->ip_route_cache);
-		/*
-		 *	This one is pure paranoia. I'll take it out
-		 *	later once I know the bug is buried.
-		 */
-		tcp_cache_zap();
-		sk_free(sk);
-	} 
-	else 
-	{
-		/* this should never happen. */
-		/* actually it can if an ack has just been sent. */
-		NETDEBUG(printk("Socket destroy delayed (r=%d w=%d)\n",
-			sk->rmem_alloc, sk->wmem_alloc));
-		sk->destroy = 1;
-		sk->ack_backlog = 0;
-		release_sock(sk);
-		reset_timer(sk, TIME_DESTROY, SOCK_DESTROY_TIME);
-  	}
+		kill_sk_now(sk);
+	else
+		kill_sk_later(sk);
 }
 
 /*
@@ -508,15 +326,13 @@
 static int inet_autobind(struct sock *sk)
 {
 	/* We may need to bind the socket. */
-	if (sk->num == 0) 
-	{
-		sk->num = get_new_socknum(sk->prot, 0);
+	if (sk->num == 0) {
+		sk->num = sk->prot->good_socknum();
 		if (sk->num == 0) 
 			return(-EAGAIN);
-		udp_cache_zap();
-		tcp_cache_zap();
-		put_sock(sk->num, sk);
 		sk->dummy_th.source = ntohs(sk->num);
+		sk->prot->rehash(sk);
+		add_to_prot_sklist(sk);
 	}
 	return 0;
 }
@@ -529,7 +345,7 @@
 {
 	struct sock *sk = (struct sock *) sock->data;
 
-	if(inet_autobind(sk)!=0)
+	if(inet_autobind(sk) != 0)
 		return -EAGAIN;
 
 	/* We might as well re use these. */ 
@@ -538,16 +354,17 @@
 	 * somewhere. We might as well truncate it to what everybody
 	 * else does..
 	 * Now truncate to 128 not 5. 
+	 *
+	 * This was wrong, truncate both cases to SOMAXCONN. -DaveM
 	 */
-	if ((unsigned) backlog == 0)	/* BSDism */
-		backlog = 1;
-	if ((unsigned) backlog > SOMAXCONN)
+	if (((unsigned) backlog == 0) || ((unsigned) backlog > SOMAXCONN))
 		backlog = SOMAXCONN;
 	sk->max_ack_backlog = backlog;
-	if (sk->state != TCP_LISTEN)
-	{
+	if (sk->state != TCP_LISTEN) {
 		sk->ack_backlog = 0;
 		sk->state = TCP_LISTEN;
+		sk->prot->rehash(sk);
+		add_to_prot_sklist(sk);
 	}
 	return(0);
 }
@@ -592,76 +409,41 @@
 {
 	struct sock *sk;
 	struct proto *prot;
-	int err;
 
 	sk = sk_alloc(GFP_KERNEL);
 	if (sk == NULL) 
-		return(-ENOBUFS);
+		goto do_oom;
+#if 0 /* sk_alloc() does this for us. -DaveM */
 	memset(sk,0,sizeof(*sk));	/* Efficient way to set most fields to zero */
+#endif
 	/*
 	 *	Note for tcp that also wiped the dummy_th block for us.
 	 */
-	switch(sock->type) 
-	{
-		case SOCK_STREAM:
-		case SOCK_SEQPACKET:
-			if (protocol && protocol != IPPROTO_TCP) 
-			{
-				sk_free(sk);
-				return(-EPROTONOSUPPORT);
-			}
-			protocol = IPPROTO_TCP;
-			sk->no_check = TCP_NO_CHECK;
-			prot = &tcp_prot;
-			break;
-
-		case SOCK_DGRAM:
-			if (protocol && protocol != IPPROTO_UDP) 
-			{
-				sk_free(sk);
-				return(-EPROTONOSUPPORT);
-			}
-			protocol = IPPROTO_UDP;
-			sk->no_check = UDP_NO_CHECK;
-			prot=&udp_prot;
-			break;
-      
-		case SOCK_RAW:
-			if (!suser()) 
-			{
-				sk_free(sk);
-				return(-EPERM);
-			}
-			if (!protocol) 
-			{
-				sk_free(sk);
-				return(-EPROTONOSUPPORT);
-			}
-			prot = &raw_prot;
-			sk->reuse = 1;
-			sk->num = protocol;
-			break;
-
-		case SOCK_PACKET:
-			if (!suser()) 
-			{
-				sk_free(sk);
-				return(-EPERM);
-			}
-			if (!protocol) 
-			{
-				sk_free(sk);
-				return(-EPROTONOSUPPORT);
-			}
-			prot = &packet_prot;
-			sk->reuse = 1;
-			sk->num = protocol;
-			break;
-
-		default:
-			sk_free(sk);
-			return(-ESOCKTNOSUPPORT);
+	if(sock->type == SOCK_STREAM || sock->type == SOCK_SEQPACKET) {
+		if (protocol && protocol != IPPROTO_TCP) 
+			goto free_and_noproto;
+		protocol = IPPROTO_TCP;
+		sk->no_check = TCP_NO_CHECK;
+		prot = &tcp_prot;
+	} else if(sock->type == SOCK_DGRAM) {
+		if (protocol && protocol != IPPROTO_UDP) 
+			goto free_and_noproto;
+		protocol = IPPROTO_UDP;
+		sk->no_check = UDP_NO_CHECK;
+		prot=&udp_prot;
+	} else if(sock->type == SOCK_RAW || sock->type == SOCK_PACKET) {
+		if (!suser()) 
+			goto free_and_badperm;
+		if (!protocol) 
+			goto free_and_noproto;
+		prot = &raw_prot;
+		prot = (sock->type == SOCK_RAW) ? &raw_prot : &packet_prot;
+		sk->reuse = 1;
+		sk->num = protocol;
+	} else {
+		goto free_and_badtype;
 	}
+
 	sk->socket = sock;
 #ifdef CONFIG_TCP_NAGLE_OFF
 	sk->nonagle = 1;
@@ -717,28 +499,43 @@
 	sk->write_space = def_callback3;
 	sk->error_report = def_callback1;
 
-	if (sk->num) 
-	{
-	/*
-	 * It assumes that any protocol which allows
-	 * the user to assign a number at socket
-	 * creation time automatically
-	 * shares.
-	 */
-		put_sock(sk->num, sk);
+	if (sk->num) {
+		/* It assumes that any protocol which allows
+		 * the user to assign a number at socket
+		 * creation time automatically
+		 * shares.
+		 */
 		sk->dummy_th.source = ntohs(sk->num);
+
+		/* This is gross, but needed for SOCK_PACKET -DaveM */
+		if(sk->prot->hash)
+			sk->prot->hash(sk);
+		add_to_prot_sklist(sk);
 	}
 
-	if (sk->prot->init) 
-	{
-		err = sk->prot->init(sk);
-		if (err != 0) 
-		{
+	if (sk->prot->init) {
+		int err = sk->prot->init(sk);
+		if (err != 0) {
 			destroy_sock(sk);
 			return(err);
 		}
 	}
 	return(0);
+
+free_and_badtype:
+	sk_free(sk);
+	return -ESOCKTNOSUPPORT;
+
+free_and_badperm:
+	sk_free(sk);
+	return -EPERM;
+
+free_and_noproto:
+	sk_free(sk);
+	return -EPROTONOSUPPORT;
+
+do_oom:
+	return -ENOBUFS;
 }
 
 
@@ -759,191 +556,103 @@
  
 static int inet_release(struct socket *sock, struct socket *peer)
 {
-	unsigned long timeout;
 	struct sock *sk = (struct sock *) sock->data;
 
-	if (sk == NULL) 
-		return(0);
+	if (sk) {
+		unsigned long timeout;
 
-	sk->state_change(sk);
+		sk->state_change(sk);
 
-	/* Start closing the connection.  This may take a while. */
+		/* Start closing the connection.  This may take a while. */
 
 #ifdef CONFIG_IP_MULTICAST
-	/* Applications forget to leave groups before exiting */
-	ip_mc_drop_socket(sk);
+		/* Applications forget to leave groups before exiting */
+		ip_mc_drop_socket(sk);
 #endif
-	/*
-	 * If linger is set, we don't return until the close
-	 * is complete.  Otherwise we return immediately. The
-	 * actually closing is done the same either way.
-	 *
-	 * If the close is due to the process exiting, we never
-	 * linger..
-	 */
-	timeout = 0;
-	if (sk->linger) {
-		timeout = ~0UL;
-		if (!sk->lingertime)
-			timeout = jiffies + HZ*sk->lingertime;
-	}
-	if (current->flags & PF_EXITING)
+		/*
+		 * If linger is set, we don't return until the close
+		 * is complete.  Otherwise we return immediately. The
+		 * actually closing is done the same either way.
+		 *
+		 * If the close is due to the process exiting, we never
+		 * linger..
+		 */
 		timeout = 0;
+		if (sk->linger && !(current->flags & PF_EXITING)) {
+			if (sk->lingertime)
+				timeout = jiffies + HZ*sk->lingertime;
+		}
 
-	sock->data = NULL;
-	sk->socket = NULL;
+		sock->data = NULL;
+		sk->socket = NULL;
 
-	sk->prot->close(sk, timeout);
+		sk->prot->close(sk, timeout);
+	}
 	return(0);
 }
 
 
-static int inet_bind(struct socket *sock, struct sockaddr *uaddr,
-	       int addr_len)
+static int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 {
 	struct sockaddr_in *addr=(struct sockaddr_in *)uaddr;
-	struct sock *sk=(struct sock *)sock->data, *sk2;
-	unsigned short snum = 0 /* Stoopid compiler.. this IS ok */;
+	struct sock *sk=(struct sock *)sock->data;
+	unsigned short snum;
 	int chk_addr_ret;
 
-	/*
-	 *	If the socket has its own bind function then use it.
-	 */
-	 
+	/* If the socket has its own bind function then use it. (RAW AND PACKET) */
 	if(sk->prot->bind)
-		return sk->prot->bind(sk,uaddr, addr_len);
+		return sk->prot->bind(sk, uaddr, addr_len);
 		
-	/* check this error. */
-	if (sk->state != TCP_CLOSE)
-		return(-EINVAL);
-	if(addr_len<sizeof(struct sockaddr_in))
+	/* Check these errors (active socket, bad address length, double bind). */
+	if ((sk->state != TCP_CLOSE)			||
+	    (addr_len < sizeof(struct sockaddr_in))	||
+	    (sk->num != 0))
 		return -EINVAL;
-		
-	if(sock->type != SOCK_RAW)
-	{
-		if (sk->num != 0) 
-			return(-EINVAL);
 
-		snum = ntohs(addr->sin_port);
-		
+	snum = ntohs(addr->sin_port);
 #ifdef CONFIG_IP_MASQUERADE
-		/*
-		 *	The kernel masquerader needs some ports
-		 */		
-		if(snum>=PORT_MASQ_BEGIN && snum<=PORT_MASQ_END)
-			return -EADDRINUSE;
+	/* The kernel masquerader needs some ports. */		
+	if(snum>=PORT_MASQ_BEGIN && snum<=PORT_MASQ_END)
+		return -EADDRINUSE;
 #endif		 
-
-		if (snum == 0) 
-			snum = get_new_socknum(sk->prot, 0);
-		if (snum < PROT_SOCK && !suser()) 
-			return(-EACCES);
-	}
+	if (snum == 0) 
+		snum = sk->prot->good_socknum();
+	if (snum < PROT_SOCK && !suser()) 
+		return(-EACCES);
 	
 	chk_addr_ret = ip_chk_addr(addr->sin_addr.s_addr);
+	if (addr->sin_addr.s_addr != 0 && chk_addr_ret != IS_MYADDR &&
+	    chk_addr_ret != IS_MULTICAST && chk_addr_ret != IS_BROADCAST) {
 #ifdef CONFIG_IP_TRANSPARENT_PROXY
-	/*
-	 * Superuser may bind to any address to allow transparent proxying.
-	 */
-	if (addr->sin_addr.s_addr != 0 && chk_addr_ret != IS_MYADDR && chk_addr_ret != IS_MULTICAST && chk_addr_ret != IS_BROADCAST && !suser())
-#else
-	if (addr->sin_addr.s_addr != 0 && chk_addr_ret != IS_MYADDR && chk_addr_ret != IS_MULTICAST && chk_addr_ret != IS_BROADCAST)
+		/* Superuser may bind to any address to allow transparent proxying. */
+		if(!suser())
 #endif
-		return(-EADDRNOTAVAIL);	/* Source address MUST be ours! */
-
-#ifndef CONFIG_IP_TRANSPARENT_PROXY
-	/*
-	 * Am I just thick or is this test really always true after the one
-	 * above?  Just taking the test out appears to be the easiest way to
-	 * make binds to remote addresses for transparent proxying work.
-	 */
-	if (chk_addr_ret || addr->sin_addr.s_addr == 0)
-	{
-#endif
-		/*
-		 *      We keep a pair of addresses. rcv_saddr is the one
-		 *      used by get_sock_*(), and saddr is used for transmit.
-		 *
-		 *      In the BSD API these are the same except where it
-		 *      would be illegal to use them (multicast/broadcast) in
-		 *      which case the sending device address is used.
-		 */
-		sk->rcv_saddr = addr->sin_addr.s_addr;
-		if(chk_addr_ret==IS_MULTICAST||chk_addr_ret==IS_BROADCAST)
-			sk->saddr = 0;  /* Use device */
-		else
-			sk->saddr = addr->sin_addr.s_addr;
-#ifndef CONFIG_IP_TRANSPARENT_PROXY
+			return(-EADDRNOTAVAIL);	/* Source address MUST be ours! */
 	}
-#endif
-	if(sock->type != SOCK_RAW)
-	{
-		/* Make sure we are allowed to bind here. */
-		cli();
-		for(sk2 = sk->prot->sock_array[snum & (SOCK_ARRAY_SIZE -1)];
-					sk2 != NULL; sk2 = sk2->next) 
-		{
-			/*
-			 *	Hash collision or real match ?
-			 */
-			 
-			if (sk2->num != snum) 
-				continue;
-				
-			/*
-			 *	Either bind on the port is wildcard means
-			 *	they will overlap and thus be in error
-			 */			
-			 
-			if (!sk2->rcv_saddr || !sk->rcv_saddr)
-			{
-				/*
-				 *	Allow only if both are setting reuse.
-				 */
-				if(sk2->reuse && sk->reuse && sk2->state!=TCP_LISTEN)
-					continue;
-				sti();
-				return(-EADDRINUSE);
-			}
-
-			/*
-			 *	Two binds match ?
-			 */
 
-			if (sk2->rcv_saddr != sk->rcv_saddr) 
-				continue;
-			/*
-			 *	Reusable port ?
-			 */
-
-			if (!sk->reuse)
-			{
-				sti();
-				return(-EADDRINUSE);
-			}
-			
-			/*
-			 *	Reuse ?
-			 */
-			 
-			if (!sk2->reuse || sk2->state==TCP_LISTEN)
-			{
-				sti();
-				return(-EADDRINUSE);
-			}
-		}
-		sti();
+	/*
+	 *      We keep a pair of addresses. rcv_saddr is the one
+	 *      used by hash lookups, and saddr is used for transmit.
+	 *
+	 *      In the BSD API these are the same except where it
+	 *      would be illegal to use them (multicast/broadcast) in
+	 *      which case the sending device address is used.
+	 */
+	sk->rcv_saddr = sk->saddr = addr->sin_addr.s_addr;
+	if(chk_addr_ret == IS_MULTICAST || chk_addr_ret == IS_BROADCAST)
+		sk->saddr = 0;  /* Use device */
+
+	/* Make sure we are allowed to bind here. */
+	if(sk->prot->verify_bind(sk, snum))
+		return -EADDRINUSE;
+
+	sk->num = snum;
+	sk->dummy_th.source = ntohs(sk->num);
+	sk->daddr = 0;
+	sk->dummy_th.dest = 0;
+	sk->prot->rehash(sk);
+	add_to_prot_sklist(sk);
 
-		remove_sock(sk);
-		if(sock->type==SOCK_DGRAM)
-			udp_cache_zap();
-		if(sock->type==SOCK_STREAM)
-			tcp_cache_zap();
-		put_sock(snum, sk);
-		sk->dummy_th.source = ntohs(sk->num);
-		sk->daddr = 0;
-		sk->dummy_th.dest = 0;
-	}
 	ip_rt_put(sk->ip_route_cache);
 	sk->ip_route_cache=NULL;
 	return(0);
@@ -961,23 +670,21 @@
 	int err;
 	sock->conn = NULL;
 
-	if (sock->state == SS_CONNECTING && tcp_connected(sk->state))
-	{
+	if (sock->state == SS_CONNECTING && tcp_connected(sk->state)) {
 		sock->state = SS_CONNECTED;
 		/* Connection completing after a connect/EINPROGRESS/select/connect */
 		return 0;	/* Rock and roll */
 	}
 
-	if (sock->state == SS_CONNECTING && sk->protocol == IPPROTO_TCP && (flags & O_NONBLOCK))
-	{
+	if (sock->state == SS_CONNECTING && sk->protocol == IPPROTO_TCP && (flags & O_NONBLOCK)) {
 		if(sk->err!=0)
 			return sock_error(sk);
 		return -EALREADY;	/* Connecting is currently in progress */
   	}
-	if (sock->state != SS_CONNECTING) 
-	{
+
+	if (sock->state != SS_CONNECTING) {
 		/* We may need to bind the socket. */
-		if(inet_autobind(sk)!=0)
+		if(inet_autobind(sk) != 0)
 			return(-EAGAIN);
 		if (sk->prot->connect == NULL) 
 			return(-EOPNOTSUPP);
@@ -987,8 +694,7 @@
   		sock->state = SS_CONNECTING;
 	}
 	
-	if (sk->state > TCP_FIN_WAIT2 && sock->state==SS_CONNECTING)
-	{
+	if (sk->state > TCP_FIN_WAIT2 && sock->state==SS_CONNECTING) {
 		sock->state=SS_UNCONNECTED;
 		return sock_error(sk);
 	}
@@ -997,18 +703,15 @@
 	  	return(-EINPROGRESS);
 
 	cli(); /* avoid the race condition */
-	while(sk->state == TCP_SYN_SENT || sk->state == TCP_SYN_RECV) 
-	{
+	while(sk->state == TCP_SYN_SENT || sk->state == TCP_SYN_RECV) {
 		interruptible_sleep_on(sk->sleep);
-		if (current->signal & ~current->blocked) 
-		{
+		if (current->signal & ~current->blocked) {
 			sti();
 			return(-ERESTARTSYS);
 		}
 		/* This fixes a nasty in the tcp/ip code. There is a hideous hassle with
 		   icmp error packets wanting to close a tcp or udp socket. */
-		if(sk->err && sk->protocol == IPPROTO_TCP)
-		{
+		if(sk->err && sk->protocol == IPPROTO_TCP) {
 			sock->state = SS_UNCONNECTED;
 			sti();
 			return sock_error(sk); /* set by tcp_err() */
@@ -1017,8 +720,7 @@
 	sti();
 	sock->state = SS_CONNECTED;
 
-	if (sk->state != TCP_ESTABLISHED && sk->err) 
-	{
+	if (sk->state != TCP_ESTABLISHED && sk->err) {
 		sock->state = SS_UNCONNECTED;
 		return sock_error(sk);
 	}
@@ -1049,8 +751,7 @@
 	 *	its own when it accepts one.
 	 */
 	 
-	if (newsock->data)
-	{
+	if (newsock->data) {
 	  	struct sock *sk=(struct sock *)newsock->data;
 	  	newsock->data=NULL;
 	  	destroy_sock(sk);
@@ -1063,18 +764,13 @@
 	 *	Restore the state if we have been interrupted, and then returned. 
 	 */
 	 
-	if (sk1->pair != NULL ) 
-	{
+	if (sk1->pair != NULL) {
 		sk2 = sk1->pair;
 		sk1->pair = NULL;
-	} 
-	else
-	{
+	} else {
 		sk2 = sk1->prot->accept(sk1,flags);
-		if (sk2 == NULL) 
-		{
+		if (sk2 == NULL)
 			return sock_error(sk1);
-		}
 	}
 	newsock->data = (void *)sk2;
 	sk2->sleep = newsock->wait;
@@ -1084,11 +780,9 @@
 		return(0);
 
 	cli(); /* avoid the race. */
-	while(sk2->state == TCP_SYN_RECV) 
-	{
+	while(sk2->state == TCP_SYN_RECV) {
 		interruptible_sleep_on(sk2->sleep);
-		if (current->signal & ~current->blocked) 
-		{
+		if (current->signal & ~current->blocked) {
 			sti();
 			sk1->pair = sk2;
 			sk2->sleep = NULL;
@@ -1099,15 +793,14 @@
 	}
 	sti();
 
-	if (sk2->state != TCP_ESTABLISHED && sk2->err > 0) 
-	{
+	if (sk2->state != TCP_ESTABLISHED && sk2->err > 0) {
 		err = sock_error(sk2);
 		destroy_sock(sk2);
 		newsock->data = NULL;
 		return err;
 	}
-	if (sk2->state == TCP_CLOSE)
-	{
+
+	if (sk2->state == TCP_CLOSE) {
 		destroy_sock(sk2);
 		newsock->data=NULL;
 		return -ECONNABORTED;
@@ -1129,15 +822,12 @@
   
 	sin->sin_family = AF_INET;
 	sk = (struct sock *) sock->data;
-	if (peer) 
-	{
+	if (peer) {
 		if (!tcp_connected(sk->state)) 
 			return(-ENOTCONN);
 		sin->sin_port = sk->dummy_th.dest;
 		sin->sin_addr.s_addr = sk->daddr;
-	} 
-	else 
-	{
+	} else {
 		__u32 addr = sk->rcv_saddr;
 		if (!addr) {
 			addr = sk->saddr;
@@ -1162,9 +852,11 @@
 		return(-EOPNOTSUPP);
 	if(sk->err)
 		return sock_error(sk);
+
 	/* We may need to bind the socket. */
-	if(inet_autobind(sk)!=0)
+	if(inet_autobind(sk) != 0)
 		return(-EAGAIN);
+
 	return(sk->prot->recvmsg(sk, ubuf, size, noblock, flags,addr_len));
 }
 
@@ -1173,8 +865,7 @@
 	   int flags)
 {
 	struct sock *sk = (struct sock *) sock->data;
-	if (sk->shutdown & SEND_SHUTDOWN) 
-	{
+	if (sk->shutdown & SEND_SHUTDOWN) {
 		send_sig(SIGPIPE, current, 1);
 		return(-EPIPE);
 	}
@@ -1182,9 +873,11 @@
 		return(-EOPNOTSUPP);
 	if(sk->err)
 		return sock_error(sk);
+
 	/* We may need to bind the socket. */
-	if(inet_autobind(sk)!=0)
+	if(inet_autobind(sk) != 0)
 		return -EAGAIN;
+
 	return(sk->prot->sendmsg(sk, msg, size, noblock, flags));
 			   
 }
@@ -1218,9 +911,8 @@
 {
 	struct sock *sk=(struct sock *) sock->data;
 	if (sk->prot->select == NULL) 
-	{
 		return(0);
-	}
+
 	return(sk->prot->select(sk, sel_type, wait));
 }
 
@@ -1354,222 +1046,6 @@
 	return(0);
 }
 
-#ifdef CONFIG_IP_TRANSPARENT_PROXY
-/*
- * Some routines for the for loop in get_sock which sometimes needs to walk
- * two linked lists in sequence.  Could use macros as well.
- * Does anyone know a nicer way to code this?
- */
-static __inline__ struct sock *secondlist(unsigned short hpnum, struct sock *s,
-				int *pfirstpass, struct proto *prot)
-{
-	if (hpnum && s == NULL && (*pfirstpass)-- )
-		return prot->sock_array[hpnum & (SOCK_ARRAY_SIZE - 1)];
-	else
-		return s;
-}
-static __inline__ struct sock *get_sock_loop_init(unsigned short hnum,
-			unsigned short hpnum, struct sock *s,
-			int *pfirstpass, struct proto *prot)
-{
-	s = prot->sock_array[hnum & (SOCK_ARRAY_SIZE - 1)];
-	return secondlist(hpnum, s, pfirstpass, prot);
-}
-static __inline__ struct sock *get_sock_loop_next(unsigned short hnum,
-			unsigned short hpnum, struct sock *s,
-			int *pfirstpass, struct proto *prot)
-{
-	s = s->next;
-	return secondlist(hpnum, s, pfirstpass, prot);
-}
-#endif
-
-/*
- * This routine must find a socket given a TCP or UDP header.
- * Everything is assumed to be in net order.
- *
- * We give priority to more closely bound ports: if some socket
- * is bound to a particular foreign address, it will get the packet
- * rather than somebody listening to any address..
- */
-
-struct sock *get_sock(struct proto *prot, unsigned short num,
-				unsigned long raddr,
-				unsigned short rnum, unsigned long laddr,
-				unsigned long paddr, unsigned short pnum)
-{
-	struct sock *s = 0;
-	struct sock *result = NULL;
-	int badness = -1;
-	unsigned short hnum;
-#ifdef CONFIG_IP_TRANSPARENT_PROXY
-	unsigned short hpnum;
-	int firstpass = 1;
-#endif 
-
-	hnum = ntohs(num);
-#ifdef CONFIG_IP_TRANSPARENT_PROXY
-	hpnum = ntohs(pnum);
-#endif 
-
-	/*
-	 * SOCK_ARRAY_SIZE must be a power of two.  This will work better
-	 * than a prime unless 3 or more sockets end up using the same
-	 * array entry.  This should not be a problem because most
-	 * well known sockets don't overlap that much, and for
-	 * the other ones, we can just be careful about picking our
-	 * socket number when we choose an arbitrary one.
-	 */
-
-#ifdef CONFIG_IP_TRANSPARENT_PROXY
-	for(s = get_sock_loop_init(hnum, hpnum, s, &firstpass, prot);
-		s != NULL;
-		s = get_sock_loop_next(hnum, hpnum, s, &firstpass, prot))
-#else
-	for(s = prot->sock_array[hnum & (SOCK_ARRAY_SIZE - 1)];
-			s != NULL; s = s->next) 
-#endif
-	{
-		int score = 0;
-
-#ifdef CONFIG_IP_TRANSPARENT_PROXY
-		/* accept the addressed port or the redirect (proxy) port */
-		if (s->num != hnum && (hpnum == 0 || s->num != hpnum))
-#else
-		if (s->num != hnum) 
-#endif
-			continue;
-
-		if(s->dead && (s->state == TCP_CLOSE))
-			continue;
-		/* local address matches? */
-		if (s->rcv_saddr) {
-#ifdef CONFIG_IP_TRANSPARENT_PROXY
-			/*
-			 * If this is redirected traffic, it must either
-			 * match on the redirected port/ip-address or on
-			 * the actual destination, not on a mixture.
-			 * There must be a simpler way to express this...
-			 */
-			if (hpnum
-			    ? ((s->num != hpnum || s->rcv_saddr != paddr)
-			      && (s->num != hnum || s->rcv_saddr != laddr))
-			    : (s->rcv_saddr != laddr))
-#else
-			if (s->rcv_saddr != laddr)
-#endif
-				continue;
-			score++;
-		}
-		/* remote address matches? */
-		if (s->daddr) {
-			if (s->daddr != raddr)
-				continue;
-			score++;
-		}
-		/* remote port matches? */
-		if (s->dummy_th.dest) {
-			if (s->dummy_th.dest != rnum)
-				continue;
-			score++;
-		}
-		/* perfect match? */
-#ifdef CONFIG_IP_TRANSPARENT_PROXY
-		if (score == 3 && s->num == hnum)
-#else
-		if (score == 3)
-#endif
-			return s;
-		/* no, check if this is the best so far.. */
-		if (score <= badness)
-			continue;
-#ifdef CONFIG_IP_TRANSPARENT_PROXY
-		/* don't accept near matches on the actual destination
-		 * port with IN_ADDR_ANY for redirected traffic, but do
-		 * allow explicit remote address listens.  (disputable)
-		 */
-		if (hpnum && s->num != hpnum && !s->rcv_saddr)
-			continue;
-#endif
-		result = s;
-		badness = score;
-  	}
-  	return result;
-}
-
-/*
- *	Deliver a datagram to raw sockets.
- */
- 
-struct sock *get_sock_raw(struct sock *sk, 
-				unsigned short num,
-				unsigned long raddr,
-				unsigned long laddr)
-{
-	struct sock *s;
-
-	s=sk;
-
-	for(; s != NULL; s = s->next) 
-	{
-		if (s->num != num) 
-			continue;
-		if(s->dead && (s->state == TCP_CLOSE))
-			continue;
-		if(s->daddr && s->daddr!=raddr)
-			continue;
- 		if(s->rcv_saddr && s->rcv_saddr != laddr)
-			continue;
-		return(s);
-  	}
-  	return(NULL);
-}
-
-#ifdef CONFIG_IP_MULTICAST
-/*
- *	Deliver a datagram to broadcast/multicast sockets.
- */
- 
-struct sock *get_sock_mcast(struct sock *sk, 
-				unsigned short num,
-				unsigned long raddr,
-				unsigned short rnum, unsigned long laddr)
-{
-	struct sock *s;
-	unsigned short hnum;
-
-	hnum = ntohs(num);
-
-	/*
-	 * SOCK_ARRAY_SIZE must be a power of two.  This will work better
-	 * than a prime unless 3 or more sockets end up using the same
-	 * array entry.  This should not be a problem because most
-	 * well known sockets don't overlap that much, and for
-	 * the other ones, we can just be careful about picking our
-	 * socket number when we choose an arbitrary one.
-	 */
-	
-	s=sk;
-
-	for(; s != NULL; s = s->next) 
-	{
-		if (s->num != hnum) 
-			continue;
-		if(s->dead && (s->state == TCP_CLOSE))
-			continue;
-		if(s->daddr && s->daddr!=raddr)
-			continue;
-		if (s->dummy_th.dest != rnum && s->dummy_th.dest != 0) 
-			continue;
- 		if(s->rcv_saddr  && s->rcv_saddr != laddr)
-			continue;
-		return(s);
-  	}
-  	return(NULL);
-}
-
-#endif
-
 static struct proto_ops inet_proto_ops = {
 	AF_INET,
 
@@ -1601,8 +1077,6 @@
 void inet_proto_init(struct net_proto *pro)
 {
 	struct inet_protocol *p;
-	int i;
-
 
 	printk("Swansea University Computer Society TCP/IP for NET3.034\n");
 
@@ -1618,19 +1092,6 @@
 	 *	Add all the protocols. 
 	 */
 	 
-	for(i = 0; i < SOCK_ARRAY_SIZE; i++) 
-	{
-		tcp_prot.sock_array[i] = NULL;
-		udp_prot.sock_array[i] = NULL;
-		raw_prot.sock_array[i] = NULL;
-  	}
-	tcp_prot.inuse = 0;
-	tcp_prot.highestinuse = 0;
-	udp_prot.inuse = 0;
-	udp_prot.highestinuse = 0;
-	raw_prot.inuse = 0;
-	raw_prot.highestinuse = 0;
-
 	printk("IP Protocols: ");
 	for(p = inet_protocol_base; p != NULL;) 
 	{
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/arp.c linux/net/ipv4/arp.c
--- vanilla/v2.0.29/linux/net/ipv4/arp.c	Tue Feb  4 09:29:49 1997
+++ linux/net/ipv4/arp.c	Sat Mar  8 21:20:53 1997
@@ -61,6 +61,7 @@
  *		Stuart Cheshire	:	Metricom and grat arp fixes
  *					*** FOR 2.1 clean this up ***
  *		Lawrence V. Stefani: (08/12/96) Added FDDI support.
+ *		David S. Miller	:	Fix skb leakage in arp_find.
  */
 
 /* RFC1122 Status:
@@ -1430,6 +1431,7 @@
 			else
 			{
 				icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0, dev);
+				skb_device_unlock(skb); /* else it is lost forever */
 				dev_kfree_skb(skb, FREE_WRITE);
 			}
 		}
@@ -1439,8 +1441,10 @@
 
 	entry = arp_new_entry(paddr, dev, NULL, skb);
 
-	if (skb != NULL && !entry)
+	if (skb != NULL && !entry) {
+		skb_device_unlock(skb); /* else it is lost forever */
 		dev_kfree_skb(skb, FREE_WRITE);
+	}
 
 	arp_unlock();
 	return 1;
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/icmp.c linux/net/ipv4/icmp.c
--- vanilla/v2.0.29/linux/net/ipv4/icmp.c	Thu Nov 14 08:20:10 1996
+++ linux/net/ipv4/icmp.c	Mon Mar  3 03:49:22 1997
@@ -989,6 +989,10 @@
  *	in udp.c or tcp.c...
  */
 
+/* This should work with the new hashes now. -DaveM */
+extern struct sock *tcp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport);
+extern struct sock *udp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport);
+
 int icmp_chkaddr(struct sk_buff *skb)
 {
 	struct icmphdr *icmph=(struct icmphdr *)(skb->h.raw + skb->h.iph->ihl*4);
@@ -1003,8 +1007,7 @@
 			{
 			struct tcphdr *th = (struct tcphdr *)(((unsigned char *)iph)+(iph->ihl<<2));
 
-			sk = get_sock(&tcp_prot, th->source, iph->daddr,
-						th->dest, iph->saddr, 0, 0);
+			sk = tcp_v4_lookup(iph->saddr, th->source, iph->daddr, th->dest);
 			if (!sk) return 0;
 			if (sk->saddr != iph->saddr) return 0;
 			if (sk->daddr != iph->daddr) return 0;
@@ -1018,8 +1021,7 @@
 			{
 			struct udphdr *uh = (struct udphdr *)(((unsigned char *)iph)+(iph->ihl<<2));
 
-			sk = get_sock(&udp_prot, uh->source, iph->daddr,
-						uh->dest, iph->saddr, 0, 0);
+			sk = udp_v4_lookup(iph->saddr, uh->source, iph->daddr, uh->dest);
 			if (!sk) return 0;
 			if (sk->saddr != iph->saddr && ip_chk_addr(iph->saddr) != IS_MYADDR)
 				return 0;
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/ip_forward.c linux/net/ipv4/ip_forward.c
--- vanilla/v2.0.29/linux/net/ipv4/ip_forward.c	Tue Oct 29 20:42:42 1996
+++ linux/net/ipv4/ip_forward.c	Tue Mar  4 05:51:40 1997
@@ -264,6 +264,13 @@
 		 */
 		if (iph->protocol == IPPROTO_ICMP)
 		{
+#ifdef CONFIG_IP_MASQUERADE_ICMP
+#define icmph ((struct icmphdr *)((char *)iph + (iph->ihl<<2)))
+                     if ((icmph->type==ICMP_DEST_UNREACH)||
+                         (icmph->type==ICMP_SOURCE_QUENCH)||
+                         (icmph->type==ICMP_TIME_EXCEEDED))
+                       {
+#endif
 			if ((fw_res = ip_fw_masq_icmp(&skb, dev2)) < 0)
 			{
 				if (rt)
@@ -275,6 +282,9 @@
 			if (fw_res)
 				/* ICMP matched - skip firewall */
 				goto skip_call_fw_firewall;
+#ifdef CONFIG_IP_MASQUERADE_ICMP
+                       }
+#endif				
 		}
 #endif
 		fw_res=call_fw_firewall(PF_INET, dev2, iph, NULL);
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/ip_fw.c linux/net/ipv4/ip_fw.c
--- vanilla/v2.0.29/linux/net/ipv4/ip_fw.c	Thu Aug 29 12:15:15 1996
+++ linux/net/ipv4/ip_fw.c	Tue Mar  4 06:25:59 1997
@@ -37,6 +37,8 @@
  *		Willy Konynenberg <willy@xos.nl> 10/5/96.
  *	Make separate accounting on incoming and outgoing packets possible.
  *		Jos Vos <jos@xos.nl> 18/5/1996.
+ *	Add timeout reprieve for idle control channels.
+ *		Keith Owens <kaos@audio.apana.org.au> 05/07/1996.
  *
  *
  * Masquerading functionality
@@ -885,6 +887,87 @@
 	return(EINVAL);
 }
 #endif
+
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+
+int ip_autofw_add(struct ip_autofw * af)
+{
+	struct ip_autofw * newaf;
+	init_timer(&af->timer);
+	newaf = kmalloc( sizeof(struct ip_autofw), GFP_ATOMIC );
+	memcpy(newaf, af, sizeof(struct ip_autofw));
+	newaf->timer.data = (unsigned long) newaf;
+	newaf->timer.function = ip_autofw_expire;
+	newaf->timer.expires = 0;
+	newaf->lastcontact=0;
+	newaf->next=ip_autofw_hosts;
+	ip_autofw_hosts=newaf;
+	return(0);
+}
+
+int ip_autofw_del(struct ip_autofw * af)
+{
+	struct ip_autofw * prev, * curr;
+	prev=NULL;
+	curr=ip_autofw_hosts;
+	while (curr)
+	{
+		if (af->type     == curr->type &&
+		    af->low      == curr->low &&
+		    af->high     == curr->high &&
+		    af->hidden   == curr->hidden &&
+		    af->visible  == curr->visible &&
+		    af->protocol == curr->protocol &&
+		    af->where    == curr->where &&
+		    af->ctlproto == curr->ctlproto &&
+		    af->ctlport  == curr->ctlport)
+		{
+			if (prev)
+			{
+				prev->next=curr->next;
+	 			kfree_s(curr,sizeof(struct ip_autofw));
+				return(0);
+			}
+			else
+			{
+	 			kfree_s(ip_autofw_hosts,sizeof(struct ip_autofw));
+				ip_autofw_hosts=curr->next;
+				return(0);
+			}
+		}
+		prev=curr;
+		curr=curr->next;
+	}
+	return(EINVAL);
+}
+
+int ip_autofw_flush(void)
+{
+	struct ip_autofw * af;
+	while (ip_autofw_hosts)
+	{
+		af=ip_autofw_hosts;
+		ip_autofw_hosts=ip_autofw_hosts->next;
+		kfree_s(af,sizeof(struct ip_autofw));
+	}
+	return(0);
+}
+
+int ip_autofw_ctl(int stage, void *m, int len)
+{
+	if (stage == IP_AUTOFW_ADD)
+		return (ip_autofw_add((struct ip_autofw *) m));
+
+	if (stage == IP_AUTOFW_DEL)
+		return (ip_autofw_del((struct ip_autofw *) m));
+	
+	if (stage == IP_AUTOFW_FLUSH)
+		return (ip_autofw_flush());
+	
+	return(EINVAL);
+}
+
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
 
 #ifdef CONFIG_IP_FIREWALL
 int ip_fw_ctl(int stage, void *m, int len)
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/ip_input.c linux/net/ipv4/ip_input.c
--- vanilla/v2.0.29/linux/net/ipv4/ip_input.c	Tue Feb  4 09:30:48 1997
+++ linux/net/ipv4/ip_input.c	Mon Mar  3 03:52:10 1997
@@ -575,32 +575,34 @@
 		 *	RFC 1122: SHOULD pass TOS value up to the transport layer.
 		 */
  
-		hash = iph->protocol & (SOCK_ARRAY_SIZE-1);
+		/* Note: See raw.c and net/raw.h, RAWV4_HTABLE_SIZE==MAX_INET_PROTOS */
+		hash = iph->protocol & (MAX_INET_PROTOS - 1);
 
 		/* 
 		 *	If there maybe a raw socket we must check - if not we don't care less 
 		 */
 		 
-		if((raw_sk=raw_prot.sock_array[hash])!=NULL)
-		{
-			struct sock *sknext=NULL;
+		if((raw_sk = raw_v4_htable[hash]) != NULL) {
+			struct sock *sknext = NULL;
 			struct sk_buff *skb1;
-			raw_sk=get_sock_raw(raw_sk, iph->protocol,  iph->saddr, iph->daddr);
-			if(raw_sk)	/* Any raw sockets */
-			{
-				do
-				{
+
+			raw_sk = raw_v4_lookup(raw_sk, iph->protocol,
+					       iph->saddr, iph->daddr);
+			if(raw_sk) {	/* Any raw sockets */
+				do {
 					/* Find the next */
-					sknext=get_sock_raw(raw_sk->next, iph->protocol, iph->saddr, iph->daddr);
+					sknext = raw_v4_lookup(raw_sk->next,
+							       iph->protocol,
+							       iph->saddr,
+							       iph->daddr);
 					if(sknext)
-						skb1=skb_clone(skb, GFP_ATOMIC);
+						skb1 = skb_clone(skb, GFP_ATOMIC);
 					else
 						break;	/* One pending raw socket left */
 					if(skb1)
 						raw_rcv(raw_sk, skb1, dev, iph->saddr,daddr);
-					raw_sk=sknext;
-				}
-				while(raw_sk!=NULL);
+					raw_sk = sknext;
+				} while(raw_sk!=NULL);
 				
 				/*
 				 *	Here either raw_sk is the last raw socket, or NULL if none 
@@ -616,7 +618,6 @@
 		 *	skb->h.raw now points at the protocol beyond the IP header.
 		 */
 	
-		hash = iph->protocol & (MAX_INET_PROTOS -1);
 		for (ipprot = (struct inet_protocol *)inet_protos[hash];ipprot != NULL;ipprot=(struct inet_protocol *)ipprot->next)
 		{
 			struct sk_buff *skb2;
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/ip_masq.c linux/net/ipv4/ip_masq.c
--- vanilla/v2.0.29/linux/net/ipv4/ip_masq.c	Thu Jun  6 09:23:49 1996
+++ linux/net/ipv4/ip_masq.c	Tue Mar  4 06:54:04 1997
@@ -12,9 +12,13 @@
  *	Juan Jose Ciarlante	:	Added hashed lookup by proto,maddr,mport and proto,saddr,sport
  *	Juan Jose Ciarlante	:	Fixed deadlock if free ports get exhausted
  *	Juan Jose Ciarlante	:	Added NO_ADDR status flag.
+ *	Richard Lynch		:	Added IP Autoforward
  *	Nigel Metheringham	:	Added ICMP handling for demasquerade
  *	Nigel Metheringham	:	Checksum checking of masqueraded data
  *	Nigel Metheringham	:	Better handling of timeouts of TCP conns
+ *	Keith Owens		:	Keep control channels alive if any related data entries.
+ *	Delian Delchev		:	Added support for ICMP requests and replys
+ *	Nigel Metheringham	:	ICMP in ICMP handling, tidy ups, bug fixes, made ICMP optional
  *
  *	
  */
@@ -37,6 +41,7 @@
 #include <net/udp.h>
 #include <net/checksum.h>
 #include <net/ip_masq.h>
+#include <linux/ip_fw.h>
 
 #define IP_MASQ_TAB_SIZE 256    /* must be power of 2 */
 
@@ -44,11 +49,54 @@
  *	Implement IP packet masquerading
  */
 
-static const char *strProt[] = {"UDP","TCP"};
+static const char *strProt[] = {"UDP","TCP","ICMP"};
 
-static __inline__ const char * masq_proto_name(unsigned proto)
+/*
+ * masq_proto_num returns 0 for UDP, 1 for TCP, 2 for ICMP
+ */
+
+static int masq_proto_num(unsigned proto)
+{
+   switch (proto)
+   {
+      case IPPROTO_UDP:  return (0); break;
+      case IPPROTO_TCP:  return (1); break;
+      case IPPROTO_ICMP: return (2); break;
+      default:           return (-1); break;
+   }
+}
+
+#ifdef CONFIG_IP_MASQUERADE_ICMP
+/*
+ * Converts an ICMP reply code into the equivalent request code
+ */
+static __inline__ const __u8 icmp_type_request(__u8 type)
+{
+   switch (type)
+   {
+      case ICMP_ECHOREPLY: return ICMP_ECHO; break;
+      case ICMP_TIMESTAMPREPLY: return ICMP_TIMESTAMP; break;
+      case ICMP_INFO_REPLY: return ICMP_INFO_REQUEST; break;
+      case ICMP_ADDRESSREPLY: return ICMP_ADDRESS; break;
+      default: return (255); break;
+   }
+}
+
+/*
+ * Helper macros - attempt to make code clearer! 
+ */
+
+/* ID used in ICMP lookups */
+#define icmp_id(icmph)		((icmph->un).echo.id)
+/* (port) hash value using in ICMP lookups for requests */
+#define icmp_hv_req(icmph)	((__u16)(icmph->code+(__u16)(icmph->type<<8)))
+/* (port) hash value using in ICMP lookups for replies */
+#define icmp_hv_rep(icmph)	((__u16)(icmph->code+(__u16)(icmp_type_request(icmph->type)<<8)))
+#endif
+
+static __inline__ const char *masq_proto_name(unsigned proto)
 {
-        return strProt[proto==IPPROTO_TCP];
+        return strProt[masq_proto_num(proto)];
 }
 
 /*
@@ -69,9 +117,10 @@
  *	
  */
 
-int ip_masq_free_ports[2] = {
+int ip_masq_free_ports[3] = {
         PORT_MASQ_END - PORT_MASQ_BEGIN, 	/* UDP */
-        PORT_MASQ_END - PORT_MASQ_BEGIN 	/* TCP */
+        PORT_MASQ_END - PORT_MASQ_BEGIN, 	/* TCP */
+        PORT_MASQ_END - PORT_MASQ_BEGIN		/* ICMP */
 };
 
 static struct symbol_table ip_masq_syms = {
@@ -103,12 +152,108 @@
 
 struct ip_fw_masq *ip_masq_expire = &ip_masq_dummy;
 
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+/*
+ *	Auto-forwarding table
+ */
+
+struct ip_autofw * ip_autofw_hosts = NULL;
+
+/*
+ *	Check if a masq entry should be created for a packet
+ */
+
+struct ip_autofw * ip_autofw_check_range (__u32 where, __u16 port, __u16 protocol, int reqact)
+{
+	struct ip_autofw *af;
+	af=ip_autofw_hosts;
+	port=ntohs(port);
+	while (af)
+	{
+		if (af->type==IP_FWD_RANGE && 
+		     port>=af->low && 
+		     port<=af->high && 
+		     protocol==af->protocol && 
+		     /* it's ok to create masq entries after the timeout if we're in insecure mode */
+		     (af->flags & IP_AUTOFW_ACTIVE || !reqact || !(af->flags & IP_AUTOFW_SECURE)) &&  
+		     (!(af->flags & IP_AUTOFW_SECURE) || af->lastcontact==where || !reqact))
+			return(af);
+		af=af->next;
+	}
+	return(NULL);
+}
+
+struct ip_autofw * ip_autofw_check_port (__u16 port, __u16 protocol)
+{
+	struct ip_autofw *af;
+	af=ip_autofw_hosts;
+	port=ntohs(port);
+	while (af)
+	{
+		if (af->type==IP_FWD_PORT && port==af->visible && protocol==af->protocol)
+			return(af);
+		af=af->next;
+	}
+	return(NULL);
+}
+
+struct ip_autofw * ip_autofw_check_direct (__u16 port, __u16 protocol)
+{
+	struct ip_autofw *af;
+	af=ip_autofw_hosts;
+	port=ntohs(port);
+	while (af)
+	{
+		if (af->type==IP_FWD_DIRECT && af->low<=port && af->high>=port)
+			return(af);
+		af=af->next;
+	}
+	return(NULL);
+}
+
+void ip_autofw_update_out (__u32 who, __u32 where, __u16 port, __u16 protocol)
+{
+	struct ip_autofw *af;
+	af=ip_autofw_hosts;
+	port=ntohs(port);
+	while (af)
+	{
+		if (af->type==IP_FWD_RANGE && af->ctlport==port && af->ctlproto==protocol)
+		{
+			if (af->flags & IP_AUTOFW_USETIME)
+			{
+				if (af->timer.expires)
+					del_timer(&af->timer);
+				af->timer.expires=jiffies+IP_AUTOFW_EXPIRE;
+				add_timer(&af->timer);
+			}
+			af->flags|=IP_AUTOFW_ACTIVE;
+			af->lastcontact=where;
+			af->where=who;
+		}
+		af=af->next;
+	}
+}
+
+void ip_autofw_update_in (__u32 where, __u16 port, __u16 protocol)
+{
+/*	struct ip_autofw *af;
+	af=ip_autofw_check_range(where, port,protocol);
+	if (af)
+	{
+		del_timer(&af->timer);
+		af->timer.expires=jiffies+IP_AUTOFW_EXPIRE;
+		add_timer(&af->timer);
+	}*/
+}
+
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
+
 /*
  *	Returns hash value
  */
 
 static __inline__ unsigned
-
 ip_masq_hash_key(unsigned proto, __u32 addr, __u16 port)
 {
         return (proto^ntohl(addr)^ntohs(port)) & (IP_MASQ_TAB_SIZE-1);
@@ -219,7 +364,7 @@
  *	broken out of the ip/tcp headers or directly supplied for those
  *	pathological protocols with address/port in the data stream
  *	(ftp, irc).  addresses and ports are in network order.
- *	called for pkts coming from INside-to-outside the firewall.
+ *	called for pkts coming from outside-to-INside the firewall.
  *
  * 	NB. Cannot check destination address, just for the incoming port.
  * 	reason: archie.doc.ac.uk has 6 interfaces, you send to
@@ -236,12 +381,33 @@
 
         hash = ip_masq_hash_key(protocol, d_addr, d_port);
         for(ms = ip_masq_m_tab[hash]; ms ; ms = ms->m_link) {
- 		if ( protocol==ms->protocol &&
-		    (s_addr==ms->daddr || ms->flags & IP_MASQ_F_NO_DADDR) &&
-                    (s_port==ms->dport || ms->flags & IP_MASQ_F_NO_DPORT) &&
-                    (d_addr==ms->maddr && d_port==ms->mport))
+ 		if (protocol==ms->protocol &&
+		    ((s_addr==ms->daddr || ms->flags & IP_MASQ_F_NO_DADDR)
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+		     || (ms->dport==htons(1558))
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
+		     ) &&
+		    (s_port==ms->dport || ms->flags & IP_MASQ_F_NO_DPORT) &&
+		    (d_addr==ms->maddr && d_port==ms->mport)) {
+#ifdef DEBUG_IP_MASQUERADE_VERBOSE
+			printk("MASQ: look/in %d %08X:%04hX->%08X:%04hX OK\n",
+			       protocol,
+			       s_addr,
+			       s_port,
+			       d_addr,
+			       d_port);
+#endif
                         return ms;
+		}
         }
+#ifdef DEBUG_IP_MASQUERADE_VERBOSE
+	printk("MASQ: look/in %d %08X:%04hX->%08X:%04hX fail\n",
+	       protocol,
+	       s_addr,
+	       s_port,
+	       d_addr,
+	       d_port);
+#endif
         return NULL;
 }
 
@@ -274,6 +440,12 @@
  *	pathological protocols with address/port in the data stream
  *	(ftp, irc).  addresses and ports are in network order.
  *	called for pkts coming from inside-to-OUTside the firewall.
+ *
+ *	Normally we know the source address and port but for some protocols
+ *	(e.g. ftp PASV) we do not know the source port initially.  Alas the
+ *	hash is keyed on source port so if the first lookup fails then try again
+ *	with a zero port, this time only looking at entries marked "no source
+ *	port".
  */
 
 struct ip_masq *
@@ -282,14 +454,48 @@
         unsigned hash;
         struct ip_masq *ms;
 
+
         hash = ip_masq_hash_key(protocol, s_addr, s_port);
         for(ms = ip_masq_s_tab[hash]; ms ; ms = ms->s_link) {
 		if (protocol == ms->protocol &&
 		    s_addr == ms->saddr && s_port == ms->sport &&
-                    d_addr == ms->daddr && d_port == ms->dport )
+                    d_addr == ms->daddr && d_port == ms->dport ) {
+#ifdef DEBUG_IP_MASQUERADE_VERBOSE
+			printk("MASQ: lk/out1 %d %08X:%04hX->%08X:%04hX OK\n",
+			       protocol,
+			       s_addr,
+			       s_port,
+			       d_addr,
+			       d_port);
+#endif
                         return ms;
+		}
         }
-
+        hash = ip_masq_hash_key(protocol, s_addr, 0);
+        for(ms = ip_masq_s_tab[hash]; ms ; ms = ms->s_link) {
+		if (ms->flags & IP_MASQ_F_NO_SPORT &&
+		    protocol == ms->protocol &&
+		    s_addr == ms->saddr && 
+                    d_addr == ms->daddr && d_port == ms->dport ) {
+#ifdef DEBUG_IP_MASQUERADE_VERBOSE
+			printk("MASQ: lk/out2 %d %08X:%04hX->%08X:%04hX OK\n",
+			       protocol,
+			       s_addr,
+			       s_port,
+			       d_addr,
+			       d_port);
+#endif
+                        return ms;
+		}
+        }
+#ifdef DEBUG_IP_MASQUERADE_VERBOSE
+	printk("MASQ: lk/out1 %d %08X:%04hX->%08X:%04hX fail\n",
+	       protocol,
+	       s_addr,
+	       s_port,
+	       d_addr,
+	       d_port);
+#endif
         return NULL;
 }
 
@@ -315,41 +521,90 @@
 
 static void masq_expire(unsigned long data)
 {
-	struct ip_masq *ms = (struct ip_masq *)data;
+	struct ip_masq *ms = (struct ip_masq *)data, *ms_data;
 	unsigned long flags;
 
+	if (ms->flags & IP_MASQ_F_CONTROL) {
+		/* a control channel is about to expire */
+		int idx = 0, reprieve = 0;
 #ifdef DEBUG_CONFIG_IP_MASQUERADE
-	printk("Masqueraded %s %lX:%X expired\n",
-			masq_proto_name(ms->protocol),
-			ntohl(ms->saddr),ntohs(ms->sport));
+		printk("Masquerade control %s %lX:%X about to expire\n",
+				masq_proto_name(ms->protocol),
+				ntohl(ms->saddr),ntohs(ms->sport));
+#endif
+		save_flags(flags);
+		cli();
+
+		/*
+		 * If any other masquerade entry claims that the expiring entry
+		 * is its control channel then keep the control entry alive.
+		 * Useful for long running data channels with inactive control
+		 * links which we don't want to lose, e.g. ftp.
+		 * Assumption: loops such as a->b->a or a->a will never occur.
+		 */
+		for (idx = 0; idx < IP_MASQ_TAB_SIZE && !reprieve; idx++) {
+			for (ms_data = ip_masq_m_tab[idx]; ms_data ; ms_data = ms_data->m_link) {
+				if (ms_data->control == ms) {
+					reprieve = 1;	/* this control connection can live a bit longer */
+					ip_masq_set_expire(ms, ip_masq_expire->tcp_timeout);
+#ifdef DEBUG_CONFIG_IP_MASQUERADE
+					printk("Masquerade control %s %lX:%X expiry reprieved\n",
+							masq_proto_name(ms->protocol),
+							ntohl(ms->saddr),ntohs(ms->sport));
+#endif
+					break;
+				}
+			}
+		}
+		restore_flags(flags);
+		if (reprieve)
+			return;
+	}
+
+#ifdef DEBUG_CONFIG_IP_MASQUERADE
+	printk("Masqueraded %s %lX:%X expired\n",masq_proto_name(ms->protocol),ntohl(ms->saddr),ntohs(ms->sport));
 #endif
 	
 	save_flags(flags);
 	cli();
 
         if (ip_masq_unhash(ms)) {
-                ip_masq_free_ports[ms->protocol==IPPROTO_TCP]++;
-                ip_masq_unbind_app(ms);
+                ip_masq_free_ports[masq_proto_num(ms->protocol)]++;
+                if (ms->protocol != IPPROTO_ICMP)
+                             ip_masq_unbind_app(ms);
                 kfree_s(ms,sizeof(*ms));
         }
 
 	restore_flags(flags);
 }
 
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+void ip_autofw_expire(unsigned long data)
+{
+	struct ip_autofw * af;
+	af=(struct ip_autofw *) data;
+	af->flags&=0xFFFF ^ IP_AUTOFW_ACTIVE;
+	af->timer.expires=0;
+	af->lastcontact=0;
+	if (af->flags & IP_AUTOFW_SECURE)
+		af->where=0;
+}
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
+
 /*
  * 	Create a new masquerade list entry, also allocate an
  * 	unused mport, keeping the portnumber between the
  * 	given boundaries MASQ_BEGIN and MASQ_END.
  */
 
-struct ip_masq * ip_masq_new(struct device *dev, int proto, __u32 saddr, __u16 sport, __u32 daddr, __u16 dport, unsigned mflags)
+struct ip_masq * ip_masq_new_enh(struct device *dev, int proto, __u32 saddr, __u16 sport, __u32 daddr, __u16 dport, unsigned mflags, __u16 matchport)
 {
         struct ip_masq *ms, *mst;
         int ports_tried, *free_ports_p;
 	unsigned long flags;
         static int n_fails = 0;
 
-        free_ports_p = &ip_masq_free_ports[proto==IPPROTO_TCP];
+        free_ports_p = &ip_masq_free_ports[masq_proto_num(proto)];
 
         if (*free_ports_p == 0) {
                 if (++n_fails < 5)
@@ -375,6 +630,7 @@
         ms->dport	   = dport;
         ms->flags	   = mflags;
         ms->app_data	   = NULL;
+	ms->control	   = NULL;
 
         if (proto == IPPROTO_UDP)
                 ms->flags |= IP_MASQ_F_NO_DADDR;
@@ -389,8 +645,11 @@
 		/*
                  *	Try the next available port number
                  */
-                
-		ms->mport = htons(masq_port++);
+                if (!matchport || ports_tried)
+			ms->mport = htons(masq_port++);
+		else
+			ms->mport = matchport;
+			
 		if (masq_port==PORT_MASQ_END) masq_port = PORT_MASQ_BEGIN;
                 
                 restore_flags(flags);
@@ -413,7 +672,8 @@
                         
                         restore_flags(flags);
                         
-                        ip_masq_bind_app(ms);
+                        if (proto != IPPROTO_ICMP)
+                              ip_masq_bind_app(ms);
                         n_fails = 0;
                         return ms;
                 }
@@ -426,6 +686,11 @@
         return NULL;
 }
 
+struct ip_masq * ip_masq_new(struct device *dev, int proto, __u32 saddr, __u16 sport, __u32 daddr, __u16 dport, unsigned mflags)
+{
+	return (ip_masq_new_enh(dev, proto, saddr, sport, daddr, dport, mflags, 0) );
+}
+
 /*
  * 	Set masq expiration (deletion) and adds timer,
  *	if timeout==0 cancel expiration.
@@ -467,6 +732,8 @@
 	 * We may need to consider masq-ing some ICMP related to masq-ed protocols
 	 */
 
+        if (iph->protocol==IPPROTO_ICMP) 
+            return (ip_fw_masq_icmp(skb_ptr,dev));
 	if (iph->protocol!=IPPROTO_UDP && iph->protocol!=IPPROTO_TCP)
 		return -1;
 
@@ -483,19 +750,59 @@
 #endif
 
         ms = ip_masq_out_get(iph);
-        if (ms!=NULL)
+	if (ms!=NULL) {
                 ip_masq_set_expire(ms,0);
 
+		/*
+		 *      Set sport if not defined yet (e.g. ftp PASV).  Because
+		 *	masq entries are hashed on sport, unhash with old value
+		 *	and hash with new.
+		 */
+
+		if ( ms->flags & IP_MASQ_F_NO_SPORT && ms->protocol == IPPROTO_TCP ) {
+			unsigned long flags;
+			ms->flags &= ~IP_MASQ_F_NO_SPORT;
+			save_flags(flags);
+			cli();
+			ip_masq_unhash(ms);
+			ms->sport = portptr[0];
+			ip_masq_hash(ms);	/* hash on new sport */
+			restore_flags(flags);
+#ifdef DEBUG_CONFIG_IP_MASQUERADE
+			printk("ip_fw_masquerade(): filled sport=%d\n",
+			       ntohs(ms->sport));
+#endif
+		}
+	}
+
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+	/* update any ipautofw entries .. */
+	ip_autofw_update_out(iph->saddr, iph->daddr, portptr[1], 
+			     iph->protocol);
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
+
 	/*
 	 *	Nope, not found, create a new entry for it
 	 */
 	
 	if (ms==NULL)
 	{
-                ms = ip_masq_new(dev, iph->protocol,
-                                 iph->saddr, portptr[0],
-                                 iph->daddr, portptr[1],
-                                 0);
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+		/* if the source port is supposed to match the masq port, then
+		   make it so */
+		if (ip_autofw_check_direct(portptr[1],iph->protocol))
+	                ms = ip_masq_new_enh(dev, iph->protocol,
+        	                         iph->saddr, portptr[0],
+                	                 iph->daddr, portptr[1],
+                        	         0,
+                        	         portptr[0]);
+                else
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
+	                ms = ip_masq_new_enh(dev, iph->protocol,
+        	                         iph->saddr, portptr[0],
+                	                 iph->daddr, portptr[1],
+                        	         0,
+                        	         0);
                 if (ms == NULL)
 			return -1;
  	}
@@ -530,7 +837,7 @@
  	 *	Adjust packet accordingly to protocol
  	 */
  	
- 	if (iph->protocol==IPPROTO_UDP)
+ 	if (masq_proto_num(iph->protocol)==0)
  	{
                 timeout = ip_masq_expire->udp_timeout;
  		recalc_check((struct udphdr *)portptr,iph->saddr,iph->daddr,size);
@@ -596,12 +903,63 @@
 	struct ip_masq	*ms;
 	unsigned short   len   = ntohs(iph->tot_len) - (iph->ihl * 4);
 
-#ifdef DEBUG_CONFIG_IP_MASQUERADE
- 	printk("Incoming forward ICMP (%d) %lX -> %lX\n",
-	        icmph->type,
+#ifdef DEBUG_CONFIG_IP_MASQUERADE_ICMP
+ 	printk("Incoming forward ICMP (%d,%d) %lX -> %lX\n",
+	        icmph->type, ntohs(icmp_id(icmph)),
  		ntohl(iph->saddr), ntohl(iph->daddr));
 #endif
 
+#ifdef CONFIG_IP_MASQUERADE_ICMP		
+	if ((icmph->type == ICMP_ECHO ) ||
+	    (icmph->type == ICMP_TIMESTAMP ) ||
+	    (icmph->type == ICMP_INFO_REQUEST ) ||
+	    (icmph->type == ICMP_ADDRESS )) {
+#ifdef DEBUG_CONFIG_IP_MASQUERADE_ICMP
+		printk("MASQ: icmp request rcv %lX->%lX id %d type %d\n",
+		       ntohl(iph->saddr),
+		       ntohl(iph->daddr),
+		       ntohs(icmp_id(icmph)),
+		       icmph->type);
+#endif
+		ms = ip_masq_out_get_2(iph->protocol,
+				       iph->saddr,
+				       icmp_id(icmph),
+				       iph->daddr,
+				       icmp_hv_req(icmph));
+		if (ms == NULL) {
+			ms = ip_masq_new(dev,
+					 iph->protocol,
+					 iph->saddr,
+					 icmp_id(icmph),
+					 iph->daddr,
+					 icmp_hv_req(icmph),
+					 0);
+			if (ms == NULL)
+				return (-1);
+#ifdef DEBUG_CONFIG_IP_MASQUERADE_ICMP
+			printk("MASQ: Create new icmp entry\n");
+#endif	              
+		}
+		ip_masq_set_expire(ms, 0);
+		/* Rewrite source address */
+		iph->saddr = ms->maddr;
+		ip_send_check(iph);
+		/* Rewrite port (id) */
+		(icmph->un).echo.id = ms->mport;
+		icmph->checksum = 0;
+		icmph->checksum = ip_compute_csum((unsigned char *)icmph, len);
+		ip_masq_set_expire(ms, MASQUERADE_EXPIRE_ICMP);
+#ifdef DEBUG_CONFIG_IP_MASQUERADE_ICMP
+		printk("MASQ: icmp request rwt %lX->%lX id %d type %d\n",
+		       ntohl(iph->saddr),
+		       ntohl(iph->daddr),
+		       ntohs(icmp_id(icmph)),
+		       icmph->type);
+#endif
+		return (1);
+	}
+#endif
+
 	/* 
 	 * Work through seeing if this is for us.
 	 * These checks are supposed to be in an order that
@@ -618,6 +976,57 @@
 	/* Now find the contained IP header */
 	ciph = (struct iphdr *) (icmph + 1);
 
+#ifdef CONFIG_IP_MASQUERADE_ICMP
+	if (ciph->protocol == IPPROTO_ICMP) {
+		/*
+		 * This section handles ICMP errors for ICMP packets
+		 */
+		struct icmphdr  *cicmph = (struct icmphdr *)((char *)ciph + 
+							     (ciph->ihl<<2));
+
+#ifdef DEBUG_CONFIG_IP_MASQUERADE_ICMP
+		printk("MASQ: fw icmp/icmp rcv %lX->%lX id %d type %d\n",
+		       ntohl(ciph->saddr),
+		       ntohl(ciph->daddr),
+		       ntohs(icmp_id(cicmph)),
+		       cicmph->type);
+#endif
+		ms = ip_masq_out_get_2(ciph->protocol, 
+				      ciph->daddr,
+				      icmp_id(cicmph),
+				      ciph->saddr,
+				      icmp_hv_rep(cicmph));
+
+		if (ms == NULL)
+			return 0;
+
+		/* Now we do real damage to this packet...! */
+		/* First change the source IP address, and recalc checksum */
+		iph->saddr = ms->maddr;
+		ip_send_check(iph);
+	
+		/* Now change the *dest* address in the contained IP */
+		ciph->daddr = ms->maddr;
+		ip_send_check(ciph);
+
+		/* Change the ID to the masqed one! */
+		(cicmph->un).echo.id = ms->mport;
+	
+		/* And finally the ICMP checksum */
+		icmph->checksum = 0;
+		icmph->checksum = ip_compute_csum((unsigned char *) icmph, len);
+
+#ifdef DEBUG_CONFIG_IP_MASQUERADE_ICMP
+		printk("MASQ: fw icmp/icmp rwt %lX->%lX id %d type %d\n",
+		       ntohl(ciph->saddr),
+		       ntohl(ciph->daddr),
+		       ntohs(icmp_id(cicmph)),
+		       cicmph->type);
+#endif
+		return 1;
+	}
+#endif /* CONFIG_IP_MASQUERADE_ICMP */
+
 	/* We are only interested ICMPs generated from TCP or UDP packets */
 	if ((ciph->protocol != IPPROTO_UDP) && (ciph->protocol != IPPROTO_TCP))
 		return 0;
@@ -629,8 +1038,8 @@
 	 */
 	pptr = (__u16 *)&(((char *)ciph)[ciph->ihl*4]);
 	if (ntohs(pptr[1]) < PORT_MASQ_BEGIN ||
- 	    ntohs(pptr[1]) > PORT_MASQ_END)
- 		return 0;
+	    ntohs(pptr[1]) > PORT_MASQ_END)
+		return 0;
 
 	/* Ensure the checksum is correct */
 	if (ip_compute_csum((unsigned char *) icmph, len)) 
@@ -642,13 +1051,17 @@
 	}
 
 #ifdef DEBUG_CONFIG_IP_MASQUERADE
- 	printk("Handling forward ICMP for %lX:%X -> %lX:%X\n",
+	printk("Handling forward ICMP for %lX:%X -> %lX:%X\n",
 	       ntohl(ciph->saddr), ntohs(pptr[0]),
 	       ntohl(ciph->daddr), ntohs(pptr[1]));
 #endif
 
 	/* This is pretty much what ip_masq_in_get() does */
-	ms = ip_masq_in_get_2(ciph->protocol, ciph->saddr, pptr[0], ciph->daddr, pptr[1]);
+	ms = ip_masq_out_get_2(ciph->protocol, 
+			      ciph->saddr, 
+			       pptr[0], 
+			       ciph->daddr, 
+			       pptr[1]);
 
 	if (ms == NULL)
 		return 0;
@@ -670,7 +1083,7 @@
 	icmph->checksum = ip_compute_csum((unsigned char *) icmph, len);
 
 #ifdef DEBUG_CONFIG_IP_MASQUERADE
- 	printk("Rewrote forward ICMP to %lX:%X -> %lX:%X\n",
+	printk("Rewrote forward ICMP to %lX:%X -> %lX:%X\n",
 	       ntohl(ciph->saddr), ntohs(pptr[0]),
 	       ntohl(ciph->daddr), ntohs(pptr[1]));
 #endif
@@ -695,22 +1108,124 @@
 	struct ip_masq	*ms;
 	unsigned short   len   = ntohs(iph->tot_len) - (iph->ihl * 4);
 
-#ifdef DEBUG_CONFIG_IP_MASQUERADE
- 	printk("Incoming reverse ICMP (%d) %lX -> %lX\n",
-	        icmph->type,
+#ifdef DEBUG_CONFIG_IP_MASQUERADE_ICMP
+ 	printk("MASQ: icmp in/rev (%d,%d) %lX -> %lX\n",
+	        icmph->type, ntohs(icmp_id(icmph)),
  		ntohl(iph->saddr), ntohl(iph->daddr));
 #endif
 
-	if ((icmph->type != ICMP_DEST_UNREACH) &&
-	    (icmph->type != ICMP_SOURCE_QUENCH) &&
-	    (icmph->type != ICMP_TIME_EXCEEDED))
-		return 0;
+#ifdef CONFIG_IP_MASQUERADE_ICMP		
+	if ((icmph->type == ICMP_ECHOREPLY) ||
+	    (icmph->type == ICMP_TIMESTAMPREPLY) ||
+	    (icmph->type == ICMP_INFO_REPLY) ||
+	    (icmph->type == ICMP_ADDRESSREPLY))	{
+#ifdef DEBUG_CONFIG_IP_MASQUERADE_ICMP
+		printk("MASQ: icmp reply rcv %lX->%lX id %d type %d, req %d\n",
+		       ntohl(iph->saddr),
+		       ntohl(iph->daddr),
+		       ntohs(icmp_id(icmph)),
+		       icmph->type,
+		       icmp_type_request(icmph->type));
+#endif
+		ms = ip_masq_in_get_2(iph->protocol,
+				      iph->saddr,
+				      icmp_hv_rep(icmph),
+				      iph->daddr,
+				      icmp_id(icmph));
+		if (ms == NULL)
+			return 0;
 
-	/* Now find the contained IP header */
+		ip_masq_set_expire(ms,0);
+
+		/* Reset source address */
+		iph->daddr = ms->saddr;
+		/* Redo IP header checksum */
+		ip_send_check(iph);
+		/* Set ID to fake port number */
+		(icmph->un).echo.id = ms->sport;
+		/* Reset ICMP checksum and set expiry */
+		icmph->checksum=0;
+		icmph->checksum=ip_compute_csum((unsigned char *)icmph,len);
+		ip_masq_set_expire(ms, MASQUERADE_EXPIRE_ICMP);
+#ifdef DEBUG_CONFIG_IP_MASQUERADE_ICMP
+		printk("MASQ: icmp reply rwt %lX->%lX id %d type %d\n",
+		       ntohl(iph->saddr),
+		       ntohl(iph->daddr),
+		       ntohs(icmp_id(icmph)),
+		       icmph->type);
+#endif
+		return 1;
+	} else {
+#endif
+		if ((icmph->type != ICMP_DEST_UNREACH) &&
+		    (icmph->type != ICMP_SOURCE_QUENCH) &&
+		    (icmph->type != ICMP_TIME_EXCEEDED))
+			return 0;
+#ifdef CONFIG_IP_MASQUERADE_ICMP
+	}
+#endif
+	/*
+	 * If we get here we have an ICMP error of one of the above 3 types
+	 * Now find the contained IP header
+	 */
 	ciph = (struct iphdr *) (icmph + 1);
 
+#ifdef CONFIG_IP_MASQUERADE_ICMP
+	if (ciph->protocol == IPPROTO_ICMP) {
+		/*
+		 * This section handles ICMP errors for ICMP packets
+		 *
+		 * First get a new ICMP header structure out of the IP packet
+		 */
+		struct icmphdr  *cicmph = (struct icmphdr *)((char *)ciph + 
+							     (ciph->ihl<<2));
+
+#ifdef DEBUG_CONFIG_IP_MASQUERADE_ICMP
+		printk("MASQ: rv icmp/icmp rcv %lX->%lX id %d type %d\n",
+		       ntohl(ciph->saddr),
+		       ntohl(ciph->daddr),
+		       ntohs(icmp_id(cicmph)),
+		       cicmph->type);
+#endif
+		ms = ip_masq_in_get_2(ciph->protocol, 
+				      ciph->daddr, 
+				      icmp_hv_req(cicmph),
+				      ciph->saddr, 
+				      icmp_id(cicmph));
+
+		if (ms == NULL)
+			return 0;
+
+		/* Now we do real damage to this packet...! */
+		/* First change the dest IP address, and recalc checksum */
+		iph->daddr = ms->saddr;
+		ip_send_check(iph);
+	
+		/* Now change the *source* address in the contained IP */
+		ciph->saddr = ms->saddr;
+		ip_send_check(ciph);
+
+		/* Change the ID to the original one! */
+		(cicmph->un).echo.id = ms->sport;
+
+		/* And finally the ICMP checksum */
+		icmph->checksum = 0;
+		icmph->checksum = ip_compute_csum((unsigned char *) icmph, len);
+
+#ifdef DEBUG_CONFIG_IP_MASQUERADE_ICMP
+		printk("MASQ: rv icmp/icmp rwt %lX->%lX id %d type %d\n",
+		       ntohl(ciph->saddr),
+		       ntohl(ciph->daddr),
+		       ntohs(icmp_id(cicmph)),
+		       cicmph->type);
+#endif
+		return 1;
+	}
+#endif /* CONFIG_IP_MASQUERADE_ICMP */
+
 	/* We are only interested ICMPs generated from TCP or UDP packets */
-	if ((ciph->protocol != IPPROTO_UDP) && (ciph->protocol != IPPROTO_TCP))
+	if ((ciph->protocol != IPPROTO_UDP) && 
+	    (ciph->protocol != IPPROTO_TCP))
 		return 0;
 
 	/* 
@@ -786,6 +1301,9 @@
  	struct ip_masq	*ms;
 	unsigned short len;
 	unsigned long 	timeout;
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW 
+ 	struct ip_autofw *af;
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
 
 	switch (iph->protocol) {
 	case IPPROTO_ICMP:
@@ -794,9 +1312,17 @@
 	case IPPROTO_UDP:
 		/* Make sure packet is in the masq range */
 		portptr = (__u16 *)&(((char *)iph)[iph->ihl*4]);
-		if (ntohs(portptr[1]) < PORT_MASQ_BEGIN ||
-		    ntohs(portptr[1]) > PORT_MASQ_END)
+		if ((ntohs(portptr[1]) < PORT_MASQ_BEGIN ||
+		     ntohs(portptr[1]) > PORT_MASQ_END)
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW 
+		    && !ip_autofw_check_range(iph->saddr, portptr[1], 
+					      iph->protocol, 0)
+		    && !ip_autofw_check_direct(portptr[1], iph->protocol)
+		    && !ip_autofw_check_port(portptr[1], iph->protocol)
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
+			)
 			return 0;
+
 		/* Check that the checksum is OK */
 		len = ntohs(iph->tot_len) - (iph->ihl * 4);
 		if ((iph->protocol == IPPROTO_UDP) && (portptr[3] == 0))
@@ -836,8 +1362,31 @@
 
         ms = ip_masq_in_get(iph);
 
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW 
+        if (ms == NULL && (af=ip_autofw_check_range(iph->saddr, portptr[1],
+						    iph->protocol, 0))) {
+        	ms = ip_masq_new_enh(dev, iph->protocol,
+        			     af->where, portptr[1],
+        			     iph->saddr, portptr[0],
+        			     0,
+        			     portptr[1]);
+        }
+        if ( ms == NULL && (af=ip_autofw_check_port(portptr[1], 
+						    iph->protocol)) ) {
+        	ms = ip_masq_new_enh(dev, iph->protocol,
+        			     af->where, htons(af->hidden),
+        			     iph->saddr, portptr[0],
+        			     0,
+        			     htons(af->visible));
+        }
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
+
         if (ms != NULL)
         {
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW 
+        	ip_autofw_update_in(iph->saddr, portptr[1], iph->protocol);
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
+        	
 		/* Stop the timer ticking.... */
 		ip_masq_set_expire(ms,0);
 
@@ -848,7 +1397,7 @@
                 if ( ms->flags & IP_MASQ_F_NO_DPORT && ms->protocol == IPPROTO_TCP ) {
                         ms->flags &= ~IP_MASQ_F_NO_DPORT;
                         ms->dport = portptr[0];
-#if DEBUG_CONFIG_IP_MASQUERADE
+#ifdef DEBUG_CONFIG_IP_MASQUERADE
                         printk("ip_fw_demasquerade(): filled dport=%d\n",
                                ntohs(ms->dport));
 #endif
@@ -856,7 +1405,7 @@
                 if (ms->flags & IP_MASQ_F_NO_DADDR && ms->protocol == IPPROTO_TCP)  {
                         ms->flags &= ~IP_MASQ_F_NO_DADDR;
                         ms->daddr = iph->saddr;
-#if DEBUG_CONFIG_IP_MASQUERADE
+#ifdef DEBUG_CONFIG_IP_MASQUERADE
                         printk("ip_fw_demasquerade(): filled daddr=%X\n",
                                ntohs(ms->daddr));
 #endif
@@ -886,7 +1435,7 @@
 		 * timeouts.
 		 * If a TCP RST is seen collapse the tunnel (by using short timeout)!
                  */
-                if (iph->protocol==IPPROTO_UDP)
+                if (masq_proto_num(iph->protocol)==0)
 		{
                         recalc_check((struct udphdr *)portptr,iph->saddr,iph->daddr,len);
 			timeout = ip_masq_expire->udp_timeout;
@@ -933,9 +1482,54 @@
 }
 
 /*
- *	/proc/net entry
+ *	/proc/net entries
  */
 
+
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+
+static int ip_autofw_procinfo(char *buffer, char **start, off_t offset,
+			      int length, int unused)
+{
+	off_t pos=0, begin=0;
+	struct ip_autofw * af;
+	int len=0;
+	
+	len=sprintf(buffer,"Type Prot Low  High Vis  Hid  Where    Last     CPto CPrt Timer Flags\n"); 
+        
+        for(af = ip_autofw_hosts; af ; af = af->next)
+	{
+		len+=sprintf(buffer+len,"%4X %4X %04X-%04X/%04X %04X %08lX %08lX %04X %04X %6lu %4X\n",
+					af->type,
+					af->protocol,
+					af->low,
+					af->high,
+					af->visible,
+					af->hidden,
+					ntohl(af->where),
+					ntohl(af->lastcontact),
+					af->ctlproto,
+					af->ctlport,
+					(af->timer.expires<jiffies ? 0 : af->timer.expires-jiffies), 
+					af->flags);
+
+		pos=begin+len;
+		if(pos<offset) 
+		{
+ 			len=0;
+			begin=pos;
+		}
+		if(pos>offset+length)
+			break;
+        }
+	*start=buffer+(offset-begin);
+	len-=(offset-begin);
+	if(len>length)
+		len=length;
+	return len;
+}
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
+
 static int ip_msqhst_procinfo(char *buffer, char **start, off_t offset,
 			      int length, int unused)
 {
@@ -1007,6 +1601,14 @@
 		0, &proc_net_inode_operations,
 		ip_msqhst_procinfo
 	});
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+	proc_net_register(&(struct proc_dir_entry) {
+		PROC_NET_IPAUTOFW, 9, "ip_autofw",
+		S_IFREG | S_IRUGO, 1, 0, 0,
+		0, &proc_net_inode_operations,
+		ip_autofw_procinfo
+	});
+#endif /* CONFIG_IP_MASQUERADE_IPAUTOFW */
 #endif	
         ip_masq_app_init();
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/ip_masq_cuseeme.c linux/net/ipv4/ip_masq_cuseeme.c
--- vanilla/v2.0.29/linux/net/ipv4/ip_masq_cuseeme.c	Wed Dec 31 19:00:00 1969
+++ linux/net/ipv4/ip_masq_cuseeme.c	Tue Mar  4 05:51:40 1997
@@ -0,0 +1,180 @@
+/*
+ *		IP_MASQ_FTP CUSeeMe masquerading module
+ *
+ *
+ * Version:	@(#)ip_masq_cuseeme.c 0.02   07/23/96
+ *
+ * Author:	Richard Lynch
+ *		
+ *
+ * Fixes:
+ *	Richard Lynch     	:	Updated patch to conform to new module
+ *					specifications
+ *	Nigel Metheringham	:	Multiple port support
+ *	
+ *
+ *
+ *	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.
+ *	
+ * Multiple Port Support
+ *	The helper can be made to handle up to MAX_MASQ_APP_PORTS (normally 12)
+ *	with the port numbers being defined at module load time.  The module
+ *	uses the symbol "ports" to define a list of monitored ports, which can
+ *	be specified on the insmod command line as
+ *		ports=x1,x2,x3...
+ *	where x[n] are integer port numbers.  This option can be put into
+ *	/etc/conf.modules (or /etc/modules.conf depending on your config)
+ *	where modload will pick it up should you use modload to load your
+ *	modules.
+ *	
+ */
+
+#include <linux/module.h>
+#include <asm/system.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/skbuff.h>
+#include <linux/in.h>
+#include <linux/ip.h>
+#include <net/protocol.h>
+#include <net/udp.h>
+#include <net/ip_masq.h>
+
+#ifndef DEBUG_CONFIG_IP_MASQ_CUSEEME
+#define DEBUG_CONFIG_IP_MASQ_CUSEEME 0
+#endif
+
+/* 
+ * List of ports (up to MAX_MASQ_APP_PORTS) to be handled by helper
+ * First port is set to the default port.
+ */
+int ports[MAX_MASQ_APP_PORTS] = {7648}; /* I rely on the trailing items being set to zero */
+struct ip_masq_app *masq_incarnations[MAX_MASQ_APP_PORTS];
+
+static int
+masq_cuseeme_init_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
+{
+        MOD_INC_USE_COUNT;
+        return 0;
+}
+
+static int
+masq_cuseeme_done_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
+{
+        MOD_DEC_USE_COUNT;
+        return 0;
+}
+
+int
+masq_cuseeme_out (struct ip_masq_app *mapp, struct ip_masq *ms, struct sk_buff **skb_p, struct device *dev)
+{
+	struct sk_buff *skb = *skb_p;
+	struct iphdr *iph = skb->h.iph;
+	struct udphdr *uh = (struct udphdr *)&(((char *)iph)[iph->ihl*4]);
+	struct cu_header {
+		char dest[8];
+		short family;
+		u_short port;
+		u_long addr;
+	} *cu_head;
+	char *data=(char *)&uh[1];
+	
+	if (skb->len - ((unsigned char *) data - skb->h.raw) > 16)
+	{
+		cu_head         = (struct cu_header *) data;
+/*		printk("CUSeeMe orig: %lX:%X\n",ntohl(cu_head->addr),ntohs(cu_head->port));*/
+		cu_head->port   = ms->mport;
+		cu_head->addr = (u_long) dev->pa_addr;
+	}
+	return 0;
+}
+
+struct ip_masq_app ip_masq_cuseeme = {
+        NULL,			/* next */
+        "cuseeme",
+        0,                      /* type */
+        0,                      /* n_attach */
+        masq_cuseeme_init_1,	/* ip_masq_init_1 */
+        masq_cuseeme_done_1,	/* ip_masq_done_1 */
+        masq_cuseeme_out,	/* pkt_out */
+        NULL                    /* pkt_in */
+};
+
+
+/*
+ * 	ip_masq_cuseeme initialization
+ */
+
+int ip_masq_cuseeme_init(void)
+{
+	int i, j;
+
+	for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
+		if (ports[i]) {
+			if ((masq_incarnations[i] = kmalloc(sizeof(struct ip_masq_app),
+							    GFP_KERNEL)) == NULL)
+				return -ENOMEM;
+			memcpy(masq_incarnations[i], &ip_masq_cuseeme, sizeof(struct ip_masq_app));
+			if ((j = register_ip_masq_app(masq_incarnations[i], 
+						      IPPROTO_TCP, 
+						      ports[i]))) {
+				return j;
+			}
+#if DEBUG_CONFIG_IP_MASQ_CUSEEME
+			printk("CuSeeMe: loaded support on port[%d] = %d\n",
+			       i, ports[i]);
+#endif
+		} else {
+			/* To be safe, force the incarnation table entry to NULL */
+			masq_incarnations[i] = NULL;
+		}
+	}
+	return 0;
+}
+
+/*
+ * 	ip_masq_cuseeme fin.
+ */
+
+int ip_masq_cuseeme_done(void)
+{
+	int i, j, k;
+
+	k=0;
+	for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
+		if (masq_incarnations[i]) {
+			if ((j = unregister_ip_masq_app(masq_incarnations[i]))) {
+				k = j;
+			} else {
+				kfree(masq_incarnations[i]);
+				masq_incarnations[i] = NULL;
+#if DEBUG_CONFIG_IP_MASQ_CUSEEME
+				printk("CuSeeMe: unloaded support on port[%d] = %d\n",
+				       i, ports[i]);
+#endif
+			}
+		}
+	}
+	return k;
+}
+
+#ifdef MODULE
+
+int init_module(void)
+{
+        if (ip_masq_cuseeme_init() != 0)
+                return -EIO;
+        register_symtab(0);
+        return 0;
+}
+
+void cleanup_module(void)
+{
+        if (ip_masq_cuseeme_done() != 0)
+                printk("ip_masq_cuseeme: can't remove module");
+}
+
+#endif /* MODULE */
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/ip_masq_ftp.c linux/net/ipv4/ip_masq_ftp.c
--- vanilla/v2.0.29/linux/net/ipv4/ip_masq_ftp.c	Mon Apr 22 04:27:00 1996
+++ linux/net/ipv4/ip_masq_ftp.c	Tue Mar  4 05:51:40 1997
@@ -10,6 +10,8 @@
  * Fixes:
  *	Wouter Gadeyne		:	Fixed masquerading support of ftp PORT commands
  * 	Juan Jose Ciarlante	:	Code moved and adapted from ip_fw.c
+ * 	Keith Owens		:	Add keep alive for ftp control channel
+ *	Nigel Metheringham	:	Added multiple port support
  *	
  *
  *
@@ -18,6 +20,17 @@
  *	as published by the Free Software Foundation; either version
  *	2 of the License, or (at your option) any later version.
  *	
+ * Multiple Port Support
+ *	The helper can be made to handle up to MAX_MASQ_APP_PORTS (normally 12)
+ *	with the port numbers being defined at module load time.  The module
+ *	uses the symbol "ports" to define a list of monitored ports, which can
+ *	be specified on the insmod command line as
+ *		ports=x1,x2,x3...
+ *	where x[n] are integer port numbers.  This option can be put into
+ *	/etc/conf.modules (or /etc/modules.conf depending on your config)
+ *	where modload will pick it up should you use modload to load your
+ *	modules.
+ *	
  */
 
 #include <linux/module.h>
@@ -31,7 +44,16 @@
 #include <net/tcp.h>
 #include <net/ip_masq.h>
 
+#ifndef DEBUG_CONFIG_IP_MASQ_FTP
 #define DEBUG_CONFIG_IP_MASQ_FTP 0
+#endif
+
+/* 
+ * List of ports (up to MAX_MASQ_APP_PORTS) to be handled by helper
+ * First port is set to the default port.
+ */
+int ports[MAX_MASQ_APP_PORTS] = {21}; /* I rely on the trailing items being set to zero */
+struct ip_masq_app *masq_incarnations[MAX_MASQ_APP_PORTS];
 
 static int
 masq_ftp_init_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
@@ -66,8 +88,9 @@
 	iph = skb->h.iph;
         th = (struct tcphdr *)&(((char *)iph)[iph->ihl*4]);
         data = (char *)&th[1];
-
         data_limit = skb->h.raw + skb->len - 18;
+        if (skb->len >= 6 && (memcmp(data, "PASV\r\n", 6) == 0 || memcmp(data, "pasv\r\n", 6) == 0))
+        	ms->flags |= IP_MASQ_F_FTP_PASV;
 
 	while (data < data_limit)
 	{
@@ -123,6 +146,8 @@
 					
 			if (n_ms==NULL)
 				return 0;
+			n_ms->control = ms;		/* keepalive from data to the control channel */
+			ms->flags |= IP_MASQ_F_CONTROL;	/* this is a control channel */
 		}
 
                 /*
@@ -171,6 +196,108 @@
 
 }
 
+/*
+ * Look at incoming ftp packets to catch the response to a PASV command.  When
+ * we see one we build a masquerading entry for the client address, client port
+ * 0 (unknown at the moment), the server address and the server port.  Mark the
+ * current masquerade entry as a control channel and point the new entry at the
+ * control entry.  All this work just for ftp keepalive across masquerading.
+ *
+ * The incoming packet should be something like
+ * "227 Entering Passive Mode (xxx,xxx,xxx,xxx,ppp,ppp)".
+ * xxx,xxx,xxx,xxx is the server address, ppp,ppp is the server port number.
+ * ncftp 2.3.0 cheats by skipping the leading number then going 22 bytes into
+ * the data so we do the same.  If it's good enough for ncftp then it's good
+ * enough for me.
+ *
+ * In this case, the client is the source machine being masqueraded, the server
+ * is the destination for ftp requests.  It all depends on your point of view ...
+ */
+
+int
+masq_ftp_in (struct ip_masq_app *mapp, struct ip_masq *ms, struct sk_buff **skb_p, struct device *dev)
+{
+	struct sk_buff *skb;
+	struct iphdr *iph;
+	struct tcphdr *th;
+	char *data, *data_limit;
+	unsigned char p1,p2,p3,p4,p5,p6;
+	__u32 to;
+	__u16 port;
+	struct ip_masq *n_ms;
+
+	if (! ms->flags & IP_MASQ_F_FTP_PASV)
+		return 0;	/* quick exit if no outstanding PASV */
+
+	skb = *skb_p;
+	iph = skb->h.iph;
+	th = (struct tcphdr *)&(((char *)iph)[iph->ihl*4]);
+	data = (char *)&th[1];
+	data_limit = skb->h.raw + skb->len;
+
+	while (data < data_limit && *data != ' ')
+		++data;	
+	while (data < data_limit && *data == ' ')
+		++data;	
+	data += 22;
+	if (data >= data_limit || *data != '(')
+		return 0;
+	p1 = simple_strtoul(data+1, &data, 10);
+	if (data >= data_limit || *data != ',')
+		return 0;
+	p2 = simple_strtoul(data+1, &data, 10);
+	if (data >= data_limit || *data != ',')
+		return 0;
+	p3 = simple_strtoul(data+1, &data, 10);
+	if (data >= data_limit || *data != ',')
+		return 0;
+	p4 = simple_strtoul(data+1, &data, 10);
+	if (data >= data_limit || *data != ',')
+		return 0;
+	p5 = simple_strtoul(data+1, &data, 10);
+	if (data >= data_limit || *data != ',')
+		return 0;
+	p6 = simple_strtoul(data+1, &data, 10);
+	if (data >= data_limit || *data != ')')
+		return 0;
+
+	to = (p1<<24) | (p2<<16) | (p3<<8) | p4;
+	port = (p5<<8) | p6;
+
+	/*
+	 * Now update or create an masquerade entry for it
+	 */
+#if DEBUG_CONFIG_IP_MASQ_FTP
+	printk("PASV response %lX:%X %X:%X detected\n", ntohl(ms->saddr), 0, to, port);
+#endif	
+	n_ms = ip_masq_out_get_2(iph->protocol,
+				 ms->saddr, 0,
+				 htonl(to), htons(port));
+	if (n_ms) {
+		/* existing masquerade, clear timer */
+		ip_masq_set_expire(n_ms,0);
+	}
+	else {
+		n_ms = ip_masq_new(dev, IPPROTO_TCP,
+				   ms->saddr, 0,
+				   htonl(to), htons(port),
+				   IP_MASQ_F_NO_SPORT);
+
+		if (n_ms==NULL)
+			return 0;
+		n_ms->control = ms;		/* keepalive from data to the control channel */
+		ms->flags |= IP_MASQ_F_CONTROL;	/* this is a control channel */
+	}
+
+	/*
+	 * keep for a bit longer than tcp_fin, client may not issue open
+	 * to server port before tcp_fin_timeout.
+	 */
+	ip_masq_set_expire(n_ms, ip_masq_expire->tcp_fin_timeout*3);
+	ms->flags &= ~IP_MASQ_F_FTP_PASV;
+	return 0;	/* no diff required for incoming packets, thank goodness */
+}
+
 struct ip_masq_app ip_masq_ftp = {
         NULL,			/* next */
 	"ftp",			/* name */
@@ -179,7 +306,7 @@
         masq_ftp_init_1,        /* ip_masq_init_1 */
         masq_ftp_done_1,        /* ip_masq_done_1 */
         masq_ftp_out,           /* pkt_out */
-        NULL                    /* pkt_in */
+        masq_ftp_in,            /* pkt_in */
 };
 
 /*
@@ -188,7 +315,29 @@
 
 int ip_masq_ftp_init(void)
 {
-        return register_ip_masq_app(&ip_masq_ftp, IPPROTO_TCP, 21);
+	int i, j;
+
+	for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
+		if (ports[i]) {
+			if ((masq_incarnations[i] = kmalloc(sizeof(struct ip_masq_app),
+							    GFP_KERNEL)) == NULL)
+				return -ENOMEM;
+			memcpy(masq_incarnations[i], &ip_masq_ftp, sizeof(struct ip_masq_app));
+			if ((j = register_ip_masq_app(masq_incarnations[i], 
+						      IPPROTO_TCP, 
+						      ports[i]))) {
+				return j;
+			}
+#if DEBUG_CONFIG_IP_MASQ_FTP
+			printk("Ftp: loaded support on port[%d] = %d\n",
+			       i, ports[i]);
+#endif
+		} else {
+			/* To be safe, force the incarnation table entry to NULL */
+			masq_incarnations[i] = NULL;
+		}
+	}
+	return 0;
 }
 
 /*
@@ -197,7 +346,24 @@
 
 int ip_masq_ftp_done(void)
 {
-        return unregister_ip_masq_app(&ip_masq_ftp);
+	int i, j, k;
+
+	k=0;
+	for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
+		if (masq_incarnations[i]) {
+			if ((j = unregister_ip_masq_app(masq_incarnations[i]))) {
+				k = j;
+			} else {
+				kfree(masq_incarnations[i]);
+				masq_incarnations[i] = NULL;
+#if DEBUG_CONFIG_IP_MASQ_FTP
+				printk("Ftp: unloaded support on port[%d] = %d\n",
+				       i, ports[i]);
+#endif
+			}
+		}
+	}
+	return k;
 }
 
 #ifdef MODULE
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/ip_masq_irc.c linux/net/ipv4/ip_masq_irc.c
--- vanilla/v2.0.29/linux/net/ipv4/ip_masq_irc.c	Mon Apr 22 04:27:00 1996
+++ linux/net/ipv4/ip_masq_irc.c	Tue Mar  4 05:51:40 1997
@@ -9,6 +9,7 @@
  *
  * Fixes:
  *	- set NO_DADDR flag in ip_masq_new().
+ *	- Added multiple port support (Nigel Metheringham)
  *
  * FIXME:
  *	- detect also previous "PRIVMSG" string ?.
@@ -18,6 +19,17 @@
  *	as published by the Free Software Foundation; either version
  *	2 of the License, or (at your option) any later version.
  *	
+ * Multiple Port Support
+ *	The helper can be made to handle up to MAX_MASQ_APP_PORTS (normally 12)
+ *	with the port numbers being defined at module load time.  The module
+ *	uses the symbol "ports" to define a list of monitored ports, which can
+ *	be specified on the insmod command line as
+ *		ports=x1,x2,x3...
+ *	where x[n] are integer port numbers.  This option can be put into
+ *	/etc/conf.modules (or /etc/modules.conf depending on your config)
+ *	where modload will pick it up should you use modload to load your
+ *	modules.
+ *	
  */
 
 #include <linux/module.h>
@@ -32,7 +44,16 @@
 #include <net/tcp.h>
 #include <net/ip_masq.h>
 
+#ifndef DEBUG_CONFIG_IP_MASQ_IRC
 #define DEBUG_CONFIG_IP_MASQ_IRC 0
+#endif
+
+/* 
+ * List of ports (up to MAX_MASQ_APP_PORTS) to be handled by helper
+ * First port is set to the default port.
+ */
+int ports[MAX_MASQ_APP_PORTS] = {6667}; /* I rely on the trailing items being set to zero */
+struct ip_masq_app *masq_incarnations[MAX_MASQ_APP_PORTS];
 
 static int
 masq_irc_init_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
@@ -239,7 +260,29 @@
 
 int ip_masq_irc_init(void)
 {
-        return register_ip_masq_app(&ip_masq_irc, IPPROTO_TCP, 6667);
+	int i, j;
+
+	for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
+		if (ports[i]) {
+			if ((masq_incarnations[i] = kmalloc(sizeof(struct ip_masq_app),
+							    GFP_KERNEL)) == NULL)
+				return -ENOMEM;
+			memcpy(masq_incarnations[i], &ip_masq_irc, sizeof(struct ip_masq_app));
+			if ((j = register_ip_masq_app(masq_incarnations[i], 
+						      IPPROTO_TCP, 
+						      ports[i]))) {
+				return j;
+			}
+#if DEBUG_CONFIG_IP_MASQ_IRC
+			printk("Irc: loaded support on port[%d] = %d\n",
+			       i, ports[i]);
+#endif
+		} else {
+			/* To be safe, force the incarnation table entry to NULL */
+			masq_incarnations[i] = NULL;
+		}
+	}
+	return 0;
 }
 
 /*
@@ -248,8 +291,26 @@
 
 int ip_masq_irc_done(void)
 {
-        return unregister_ip_masq_app(&ip_masq_irc);
+	int i, j, k;
+
+	k=0;
+	for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
+		if (masq_incarnations[i]) {
+			if ((j = unregister_ip_masq_app(masq_incarnations[i]))) {
+				k = j;
+			} else {
+				kfree(masq_incarnations[i]);
+				masq_incarnations[i] = NULL;
+#if DEBUG_CONFIG_IP_MASQ_IRC
+				printk("Irc: unloaded support on port[%d] = %d\n",
+				       i, ports[i]);
+#endif
+			}
+		}
+	}
+	return k;
 }
+
 
 #ifdef MODULE
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/ip_masq_quake.c linux/net/ipv4/ip_masq_quake.c
--- vanilla/v2.0.29/linux/net/ipv4/ip_masq_quake.c	Wed Dec 31 19:00:00 1969
+++ linux/net/ipv4/ip_masq_quake.c	Tue Mar  4 05:51:40 1997
@@ -0,0 +1,215 @@
+/*
+ *		IP_MASQ_QUAKE quake masquerading module
+ *
+ *
+ * Version:	@(#)ip_masq_quake.c 0.02   22/02/97
+ *
+ * Author:	Harald Hoyer mailto:HarryH@Royal.Net
+ *		
+ *
+ * Fixes: 
+ *      Harald Hoyer            :       Check for QUAKE-STRING
+ *
+ *	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.
+ *  
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <asm/system.h>
+#include <linux/skbuff.h>
+#include <linux/in.h>
+#include <linux/ip.h>
+#include <net/protocol.h>
+#include <net/udp.h>
+#include <net/ip_masq.h>
+
+#ifndef DEBUG_CONFIG_IP_MASQ_QUAKE
+#define DEBUG_CONFIG_IP_MASQ_QUAKE 0
+#endif
+
+/* 
+ * List of ports (up to MAX_MASQ_APP_PORTS) to be handled by helper
+ * First ports are set to the default port.
+ */
+int ports[MAX_MASQ_APP_PORTS] = { 26000,   /* I rely on the trailing items */
+				  27000 }; /* being set to zero */
+struct ip_masq_app *masq_incarnations[MAX_MASQ_APP_PORTS];
+
+static int
+masq_quake_init_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
+{
+        MOD_INC_USE_COUNT;
+        return 0;
+}
+
+static int
+masq_quake_done_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
+{
+	MOD_DEC_USE_COUNT;
+	return 0;
+}
+
+int
+masq_quake_in (struct ip_masq_app *mapp, struct ip_masq *ms, struct sk_buff **skb_p, struct device *dev)
+{
+	struct sk_buff *skb;
+	struct iphdr *iph;
+	__u16 *portptr, s_port;
+
+	/* It's not for us if the flag is not set */
+	if(!(ms->flags & IP_MASQ_F_NO_DPORT))
+		return 0;
+
+	skb = *skb_p;
+	iph = skb->h.iph;
+   
+	portptr = (__u16 *)&(((char *)iph)[iph->ihl*4]);
+	s_port = portptr[0];
+
+        /* Server answers the first time with 26000 or 27000 */
+	/* If someone set IP_MASQ_F_NO_DPORT on a non-quake 
+	   connection nothing bad should happen */
+	if(s_port == ms->dport)
+		return 0;
+
+	/* Now set the correct port, otherwise a new masquerading
+	   port would be initiated */
+	ms->dport = s_port;
+
+	/* Clear the flag */
+	ms->flags &= ~IP_MASQ_F_NO_DPORT;
+
+	/* Now we never see a packet from this connection, because it
+	   doesn't match 26000 or 27000 anymore. */
+	return 0;
+}
+
+int
+masq_quake_out (struct ip_masq_app *mapp, struct ip_masq *ms, struct sk_buff **skb_p, struct device *dev)
+{
+	struct sk_buff *skb;
+	struct iphdr *iph;
+	struct udphdr *uh;
+	char *data;
+
+	/* check for string "?????QUAKE??" in datastream, which is sent 
+           to the server */
+        
+	if(!(ms->flags & IP_MASQ_F_NO_DPORT)) {
+		skb = *skb_p;
+
+		iph = skb->h.iph;
+		uh = (struct udphdr *)&(((char *)iph)[iph->ihl*4]);
+
+		/* Check for lenght */
+		if(ntohs(uh->len) < 12)
+		  return 0;
+
+		data = (char *)&uh[1];
+		data += 5; /* Skip unknown data */
+
+		/* Check for stomping string */
+		if(memcmp(data,"QUAKE",5))
+			return 0;
+
+		/* Next time the server answers with another port
+		   we are prepared (Maybe we should set another flag
+		   to correcter identify the port) */		
+		ms->flags |= IP_MASQ_F_NO_DPORT;
+	}
+
+	return 0;
+}
+
+struct ip_masq_app ip_masq_quake = {
+        NULL,			/* next */
+	"Quake",	       	/* name */
+        0,                      /* type */
+        0,                      /* n_attach */
+        masq_quake_init_1,      /* ip_masq_init_1 */
+        masq_quake_done_1,      /* ip_masq_done_1 */
+        masq_quake_out,         /* pkt_out */
+        masq_quake_in           /* pkt_in */
+};
+
+/*
+ * 	ip_masq_quake initialization
+ */
+
+int ip_masq_quake_init(void)
+{
+	int i, j;
+
+	for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
+		if (ports[i]) {
+			if ((masq_incarnations[i] = kmalloc(sizeof(struct ip_masq_app),
+							    GFP_KERNEL)) == NULL)
+				return -ENOMEM;
+			memcpy(masq_incarnations[i], &ip_masq_quake, sizeof(struct ip_masq_app));
+			if ((j = register_ip_masq_app(masq_incarnations[i], 
+						      IPPROTO_TCP, 
+						      ports[i]))) {
+				return j;
+			}
+#if DEBUG_CONFIG_IP_MASQ_QUAKE
+			printk("Quake: loaded support on port[%d] = %d\n",
+			       i, ports[i]);
+#endif
+		} else {
+			/* To be safe, force the incarnation table entry to NULL */
+			masq_incarnations[i] = NULL;
+		}
+	}
+	return 0;
+}
+
+/*
+ * 	ip_masq_quake fin.
+ */
+
+int ip_masq_quake_done(void)
+{
+	int i, j, k;
+
+	k=0;
+	for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
+		if (masq_incarnations[i]) {
+			if ((j = unregister_ip_masq_app(masq_incarnations[i]))) {
+				k = j;
+			} else {
+				kfree(masq_incarnations[i]);
+				masq_incarnations[i] = NULL;
+#if DEBUG_CONFIG_IP_MASQ_QUAKE
+				printk("Quake: unloaded support on port[%d] = %d\n",
+				       i, ports[i]);
+#endif
+			}
+		}
+	}
+	return k;
+}
+
+#ifdef MODULE
+
+int init_module(void)
+{
+        if (ip_masq_quake_init() != 0)
+                return -EIO;
+        register_symtab(0);
+        return 0;
+}
+
+void cleanup_module(void)
+{
+        if (ip_masq_quake_done() != 0)
+                printk("ip_masq_quake: can't remove module");
+}
+
+#endif /* MODULE */
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/ip_masq_raudio.c linux/net/ipv4/ip_masq_raudio.c
--- vanilla/v2.0.29/linux/net/ipv4/ip_masq_raudio.c	Fri May 31 06:46:27 1996
+++ linux/net/ipv4/ip_masq_raudio.c	Tue Mar  4 07:04:46 1997
@@ -2,12 +2,12 @@
  *		IP_MASQ_RAUDIO  - Real Audio masquerading module
  *
  *
- * Version:	@(#)$Id: ip_masq_raudio.c,v 1.3 1996/05/20 13:24:26 nigel Exp $
+ * Version:	@(#)$Id: ip_masq_raudio.c,v 1.1.2.1 1997/03/04 12:04:53 davem Exp $
  *
  * Author:	Nigel Metheringham
  *		[strongly based on ftp module by Juan Jose Ciarlante & Wouter Gadeyne]
  *		[Real Audio information taken from Progressive Networks firewall docs]
- *
+ *		[Kudos to Progressive Networks for making the protocol specs available]
  *
  *
  *
@@ -34,6 +34,23 @@
  *	When the link is up there appears to be enough control data 
  *	crossing the control link to keep it open even if a long audio
  *	piece is playing.
+ *
+ *	The Robust UDP support added in RealAudio 3.0 is supported, but due
+ *	to servers/clients not making great use of this has not been greatly
+ *	tested.  RealVideo (as used in the Real client version 4.0beta1) is
+ *	supported but again is not greatly tested (bandwidth requirements
+ *	appear to exceed that available at the sites supporting the protocol).
+ *
+ * Multiple Port Support
+ *	The helper can be made to handle up to MAX_MASQ_APP_PORTS (normally 12)
+ *	with the port numbers being defined at module load time.  The module
+ *	uses the symbol "ports" to define a list of monitored ports, which can
+ *	be specified on the insmod command line as
+ *		ports=x1,x2,x3...
+ *	where x[n] are integer port numbers.  This option can be put into
+ *	/etc/conf.modules (or /etc/modules.conf depending on your config)
+ *	where modload will pick it up should you use modload to load your
+ *	modules.
  *	
  */
 
@@ -55,10 +72,19 @@
 struct raudio_priv_data {
 	/* Associated data connection - setup but not used at present */
 	struct	ip_masq *data_conn;
+	/* UDP Error correction connection - setup but not used at present */
+	struct	ip_masq *error_conn;
 	/* Have we seen and performed setup */
 	short	seen_start;
 };
 
+/* 
+ * List of ports (up to MAX_MASQ_APP_PORTS) to be handled by helper
+ * First port is set to the default port.
+ */
+int ports[MAX_MASQ_APP_PORTS] = {7070}; /* I rely on the trailing items being set to zero */
+struct ip_masq_app *masq_incarnations[MAX_MASQ_APP_PORTS];
+
 static int
 masq_raudio_init_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
 {
@@ -72,6 +98,7 @@
 			(struct raudio_priv_data *)ms->app_data;
 		priv->seen_start = 0;
 		priv->data_conn = NULL;
+		priv->error_conn = NULL;
 	}
         return 0;
 }
@@ -106,7 +133,7 @@
         th = (struct tcphdr *)&(((char *)iph)[iph->ihl*4]);
         data = (char *)&th[1];
 
-        data_limit = skb->h.raw + skb->len - 18;
+        data_limit = skb->h.raw + skb->len;
 
 	/* Check to see if this is the first packet with protocol ID */
 	if (memcmp(data, "PNA", 3)) {
@@ -133,15 +160,26 @@
 	}
 
 	data += 2;
-	while (data < data_limit) {
+	while (data+4 < data_limit) {
 		memcpy(&msg_id, data, 2);
 		data += 2;
 		memcpy(&msg_len, data, 2);
 		data += 2;
+		if (ntohs(msg_id) == 0) {
+			/* The zero tag indicates the end of options */
+#if DEBUG_CONFIG_IP_MASQ_RAUDIO
+			printk("RealAudio: packet end tag seen\n");
+#endif
+			return 0;
+		}
 #if DEBUG_CONFIG_IP_MASQ_RAUDIO
 		printk("RealAudio: msg %d - %d byte\n",
 		       ntohs(msg_id), ntohs(msg_len));
 #endif
+		if (ntohs(msg_id) == 0) {
+			/* The zero tag indicates the end of options */
+			return 0;
+		}
 		p = data;
 		data += ntohs(msg_len);
 		if (data > data_limit)
@@ -149,9 +187,26 @@
 			printk(KERN_INFO "RealAudio: Packet too short for data\n");
 			return 0;
 		}
-		if (ntohs(msg_id) == 1) {
-			/* This is a message detailing the UDP port to be used */
+		if ((ntohs(msg_id) == 1) || (ntohs(msg_id) == 7)) {
+			/* 
+			 * MsgId == 1
+			 * Audio UDP data port on client
+			 *
+			 * MsgId == 7
+			 * Robust UDP error correction port number on client
+			 *
+			 * Since these messages are treated just the same, they
+			 * are bundled together here....
+			 */
 			memcpy(&udp_port, p, 2);
+
+			/* 
+			 * Sometimes a server sends a message 7 with a zero UDP port
+			 * Rather than do anything with this, just ignore it!
+			 */
+			if (udp_port == 0)
+				continue;
+
 			n_ms = ip_masq_new(dev, IPPROTO_UDP,
 					   ms->saddr, udp_port,
 					   ms->daddr, 0,
@@ -162,24 +217,19 @@
 
 			memcpy(p, &(n_ms->mport), 2);
 #if DEBUG_CONFIG_IP_MASQ_RAUDIO
-			printk("RealAudio: rewrote UDP port %d -> %d\n",
-			       ntohs(udp_port), ntohs(n_ms->mport));
+			printk("RealAudio: rewrote UDP port %d -> %d in msg %d\n",
+			       ntohs(udp_port), ntohs(n_ms->mport), ntohs(msg_id));
 #endif
 			ip_masq_set_expire(n_ms, ip_masq_expire->udp_timeout);
 
 			/* Make ref in application data to data connection */
-			if (priv)
-				priv->data_conn = n_ms;
-
-			/* 
-			 * There is nothing else useful we can do
-			 * Maybe a development could do more, but for now
-			 * we exit gracefully!
-			 */
-			return 0;
-
-		} else if (ntohs(msg_id) == 0)
-			return 0;
+			if (priv) {
+				if (ntohs(msg_id) == 1)
+					priv->data_conn = n_ms;
+				else
+					priv->error_conn = n_ms;
+			}
+		}
 	}
 	return 0;
 }
@@ -201,7 +251,29 @@
 
 int ip_masq_raudio_init(void)
 {
-        return register_ip_masq_app(&ip_masq_raudio, IPPROTO_TCP, 7070);
+	int i, j;
+
+	for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
+		if (ports[i]) {
+			if ((masq_incarnations[i] = kmalloc(sizeof(struct ip_masq_app),
+							    GFP_KERNEL)) == NULL)
+				return -ENOMEM;
+			memcpy(masq_incarnations[i], &ip_masq_raudio, sizeof(struct ip_masq_app));
+			if ((j = register_ip_masq_app(masq_incarnations[i], 
+						      IPPROTO_TCP, 
+						      ports[i]))) {
+				return j;
+			}
+#if DEBUG_CONFIG_IP_MASQ_RAUDIO
+			printk("RealAudio: loaded support on port[%d] = %d\n",
+			       i, ports[i]);
+#endif
+		} else {
+			/* To be safe, force the incarnation table entry to NULL */
+			masq_incarnations[i] = NULL;
+		}
+	}
+	return 0;
 }
 
 /*
@@ -210,7 +282,24 @@
 
 int ip_masq_raudio_done(void)
 {
-        return unregister_ip_masq_app(&ip_masq_raudio);
+	int i, j, k;
+
+	k=0;
+	for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
+		if (masq_incarnations[i]) {
+			if ((j = unregister_ip_masq_app(masq_incarnations[i]))) {
+				k = j;
+			} else {
+				kfree(masq_incarnations[i]);
+				masq_incarnations[i] = NULL;
+#if DEBUG_CONFIG_IP_MASQ_RAUDIO
+				printk("RealAudio: unloaded support on port[%d] = %d\n",
+				       i, ports[i]);
+#endif
+			}
+		}
+	}
+	return k;
 }
 
 #ifdef MODULE
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/ip_masq_vdolive.c linux/net/ipv4/ip_masq_vdolive.c
--- vanilla/v2.0.29/linux/net/ipv4/ip_masq_vdolive.c	Wed Dec 31 19:00:00 1969
+++ linux/net/ipv4/ip_masq_vdolive.c	Tue Mar  4 07:04:40 1997
@@ -0,0 +1,315 @@
+/*
+ *		IP_MASQ_VDOLIVE  - VDO Live masquerading module
+ *
+ *
+ * Version:	@(#)$Id: ip_masq_vdolive.c,v 1.1.2.1 1997/03/04 12:04:47 davem Exp $
+ *
+ * Author:	Nigel Metheringham <Nigel.Metheringham@ThePLAnet.net>
+ *		PLAnet Online Ltd
+ *
+ *	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.
+ *
+ * Thanks:
+ *	Thank you to VDOnet Corporation for allowing me access to
+ *	a protocol description without an NDA.  This means that
+ *	this module can be distributed as source - a great help!
+ *	
+ */
+
+#include <linux/module.h>
+#include <asm/system.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/skbuff.h>
+#include <linux/in.h>
+#include <linux/ip.h>
+#include <net/protocol.h>
+#include <net/tcp.h>
+#include <net/ip_masq.h>
+
+#ifndef DEBUG_CONFIG_IP_MASQ_VDOLIVE
+#define DEBUG_CONFIG_IP_MASQ_VDOLIVE 0
+#endif
+
+struct vdolive_priv_data {
+	/* Ports used */
+	unsigned short	origport;
+	unsigned short	masqport;
+	/* State of decode */
+	unsigned short	state;
+};
+
+/* 
+ * List of ports (up to MAX_MASQ_APP_PORTS) to be handled by helper
+ * First port is set to the default port.
+ */
+int ports[MAX_MASQ_APP_PORTS] = {7000}; /* I rely on the trailing items being set to zero */
+struct ip_masq_app *masq_incarnations[MAX_MASQ_APP_PORTS];
+
+static int
+masq_vdolive_init_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
+{
+        MOD_INC_USE_COUNT;
+	if ((ms->app_data = kmalloc(sizeof(struct vdolive_priv_data),
+				    GFP_ATOMIC)) == NULL) 
+		printk(KERN_INFO "VDOlive: No memory for application data\n");
+	else 
+	{
+		struct vdolive_priv_data *priv = 
+			(struct vdolive_priv_data *)ms->app_data;
+		priv->origport = 0;
+		priv->masqport = 0;
+		priv->state = 0;
+	}
+        return 0;
+}
+
+static int
+masq_vdolive_done_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
+{
+        MOD_DEC_USE_COUNT;
+	if (ms->app_data)
+		kfree_s(ms->app_data, sizeof(struct vdolive_priv_data));
+        return 0;
+}
+
+int
+masq_vdolive_out (struct ip_masq_app *mapp, struct ip_masq *ms, struct sk_buff **skb_p, struct device *dev)
+{
+        struct sk_buff *skb;
+	struct iphdr *iph;
+	struct tcphdr *th;
+	char *data, *data_limit;
+	unsigned int tagval;	/* This should be a 32 bit quantity */
+	struct ip_masq *n_ms;
+	struct vdolive_priv_data *priv = 
+		(struct vdolive_priv_data *)ms->app_data;
+
+	/* This doesn't work at all if no priv data was allocated on startup */
+	if (!priv)
+		return 0;
+
+	/* Everything running correctly already */
+	if (priv->state == 3)
+		return 0;
+
+        skb = *skb_p;
+	iph = skb->h.iph;
+        th = (struct tcphdr *)&(((char *)iph)[iph->ihl*4]);
+        data = (char *)&th[1];
+
+        data_limit = skb->h.raw + skb->len;
+
+	if (data+8 > data_limit) {
+#if DEBUG_CONFIG_IP_MASQ_VDOLIVE
+		printk("VDOlive: packet too short for ID %lx %lx\n",
+		       data, data_limit);
+#endif
+		return 0;
+	}
+	memcpy(&tagval, data+4, 4);
+#if DEBUG_CONFIG_IP_MASQ_VDOLIVE
+	printk("VDOlive: packet seen, tag %ld, in initial state %d\n",
+	       ntohl(tagval), priv->state);
+#endif
+
+	/* Check for leading packet ID */
+	if ((ntohl(tagval) != 6) && (ntohl(tagval) != 1)) {
+#if DEBUG_CONFIG_IP_MASQ_VDOLIVE
+		printk("VDOlive: unrecognised tag %ld, in initial state %d\n",
+		       ntohl(tagval), priv->state);
+#endif
+		return 0;
+	}
+		
+
+	/* Check packet is long enough for data - ignore if not */
+	if ((ntohl(tagval) == 6) && (data+36 > data_limit)) {
+#if DEBUG_CONFIG_IP_MASQ_VDOLIVE
+		printk("VDOlive: initial packet too short %lx %lx\n",
+		       data, data_limit);
+#endif
+		return 0;
+	} else if ((ntohl(tagval) == 1) && (data+20 > data_limit)) {
+#if DEBUG_CONFIG_IP_MASQ_VDOLIVE
+		printk("VDOlive: secondary packet too short %lx %lx\n",
+		       data, data_limit);
+#endif
+		return 0;
+	}
+
+	/* Adjust data pointers */
+	/*
+	 * I could check the complete protocol version tag 
+	 * in here however I am just going to look for the
+	 * "VDO Live" tag in the hope that this part will
+	 * remain constant even if the version changes
+	 */
+	if (ntohl(tagval) == 6) {
+		data += 24;
+#if DEBUG_CONFIG_IP_MASQ_VDOLIVE
+		printk("VDOlive: initial packet found\n");
+#endif
+	} else {
+		data += 8;
+#if DEBUG_CONFIG_IP_MASQ_VDOLIVE
+		printk("VDOlive: secondary packet found\n");
+#endif
+	}
+
+	if (memcmp(data, "VDO Live", 8) != 0) {
+#if DEBUG_CONFIG_IP_MASQ_VDOLIVE
+		printk("VDOlive: did not find tag\n");
+#endif
+		return 0;
+	}
+	/* 
+	 * The port number is the next word after the tag.
+	 * VDOlive encodes all of these values
+	 * in 32 bit words, so in this case I am
+	 * skipping the first 2 bytes of the next
+	 * word to get to the relevant 16 bits
+	 */
+	data += 10;
+
+	/*
+	 * If we have not seen the port already,
+	 * set the masquerading tunnel up
+	 */
+	if (!priv->origport) {
+		memcpy(&priv->origport, data, 2);
+
+#if DEBUG_CONFIG_IP_MASQ_VDOLIVE
+		printk("VDOlive: found port %d\n",
+		       ntohs(priv->origport));
+#endif
+
+		/* Open up a tunnel */
+		n_ms = ip_masq_new(dev, IPPROTO_UDP,
+				   ms->saddr, priv->origport,
+				   ms->daddr, 0,
+				   IP_MASQ_F_NO_DPORT);
+					
+		if (n_ms==NULL) {
+			printk("VDOlive: unable to build UDP tunnel for %x:%x\n",
+			       ms->saddr, priv->origport);
+			/* Leave state as unset */
+			priv->origport = 0;
+			return 0;
+		}
+
+		ip_masq_set_expire(n_ms, ip_masq_expire->udp_timeout);
+		priv->masqport = n_ms->mport;
+	} else if (memcmp(data, &(priv->origport), 2)) {
+		printk("VDOlive: ports do not match\n");
+		/* Write the port in anyhow!!! */
+	}
+
+	/*
+	 * Write masq port into packet
+	 */
+	memcpy(data, &(priv->masqport), 2);
+#if DEBUG_CONFIG_IP_MASQ_VDOLIVE
+	printk("VDOlive: rewrote port %d to %d, server %s\n",
+	       ntohs(priv->origport), ntohs(priv->masqport), in_ntoa(ms->saddr));
+#endif
+
+	/*
+	 * Set state bit to make which bit has been done
+	 */
+
+	priv->state |= (ntohl(tagval) == 6) ? 1 : 2;
+
+	return 0;
+}
+
+
+struct ip_masq_app ip_masq_vdolive = {
+        NULL,			/* next */
+	"VDOlive",	       	/* name */
+        0,                      /* type */
+        0,                      /* n_attach */
+        masq_vdolive_init_1,	/* ip_masq_init_1 */
+        masq_vdolive_done_1,	/* ip_masq_done_1 */
+        masq_vdolive_out,	/* pkt_out */
+        NULL                    /* pkt_in */
+};
+
+/*
+ * 	ip_masq_vdolive initialization
+ */
+
+int ip_masq_vdolive_init(void)
+{
+	int i, j;
+
+	for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
+		if (ports[i]) {
+			if ((masq_incarnations[i] = kmalloc(sizeof(struct ip_masq_app),
+							    GFP_KERNEL)) == NULL)
+				return -ENOMEM;
+			memcpy(masq_incarnations[i], &ip_masq_vdolive, sizeof(struct ip_masq_app));
+			if ((j = register_ip_masq_app(masq_incarnations[i], 
+						      IPPROTO_TCP, 
+						      ports[i]))) {
+				return j;
+			}
+#if DEBUG_CONFIG_IP_MASQ_VDOLIVE
+			printk("RealAudio: loaded support on port[%d] = %d\n",
+			       i, ports[i]);
+#endif
+		} else {
+			/* To be safe, force the incarnation table entry to NULL */
+			masq_incarnations[i] = NULL;
+		}
+	}
+	return 0;
+}
+
+/*
+ * 	ip_masq_vdolive fin.
+ */
+
+int ip_masq_vdolive_done(void)
+{
+	int i, j, k;
+
+	k=0;
+	for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
+		if (masq_incarnations[i]) {
+			if ((j = unregister_ip_masq_app(masq_incarnations[i]))) {
+				k = j;
+			} else {
+				kfree(masq_incarnations[i]);
+				masq_incarnations[i] = NULL;
+#if DEBUG_CONFIG_IP_MASQ_VDOLIVE
+				printk("VDOlive: unloaded support on port[%d] = %d\n",
+				       i, ports[i]);
+#endif
+			}
+		}
+	}
+	return k;
+}
+
+
+#ifdef MODULE
+
+int init_module(void)
+{
+        if (ip_masq_vdolive_init() != 0)
+                return -EIO;
+        register_symtab(0);
+        return 0;
+}
+
+void cleanup_module(void)
+{
+        if (ip_masq_vdolive_done() != 0)
+                printk("ip_masq_vdolive: can't remove module");
+}
+
+#endif /* MODULE */
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/ip_sockglue.c linux/net/ipv4/ip_sockglue.c
--- vanilla/v2.0.29/linux/net/ipv4/ip_sockglue.c	Thu Jul 11 01:54:18 1996
+++ linux/net/ipv4/ip_sockglue.c	Tue Mar  4 05:51:40 1997
@@ -407,6 +407,22 @@
 			return -err;	/* -0 is 0 after all */
 			
 #endif
+#ifdef CONFIG_IP_MASQUERADE_IPAUTOFW
+		case IP_AUTOFW_ADD:
+		case IP_AUTOFW_DEL:
+		case IP_AUTOFW_FLUSH:
+			if(!suser())
+				return -EPERM;
+			if(optlen>sizeof(tmp_fw) || optlen<1)
+				return -EINVAL;
+			err=verify_area(VERIFY_READ,optval,optlen);
+			if(err)
+				return err;
+			memcpy_fromfs(&tmp_fw,optval,optlen);
+			err=ip_autofw_ctl(optname, &tmp_fw,optlen);
+			return -err;	/* -0 is 0 after all */
+			
+#endif
 #ifdef CONFIG_IP_ACCT
 		case IP_ACCT_INSERT:
 		case IP_ACCT_APPEND:
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/packet.c linux/net/ipv4/packet.c
--- vanilla/v2.0.29/linux/net/ipv4/packet.c	Mon May  6 05:26:17 1996
+++ linux/net/ipv4/packet.c	Mon Mar  3 03:55:08 1997
@@ -479,28 +479,34 @@
  
 struct proto packet_prot = 
 {
-	packet_close,
-	ip_build_header,	/* Not actually used */
-	NULL,
-	NULL,
-	ip_queue_xmit,		/* These two are not actually used */
-	NULL,
-	NULL,
-	NULL,
-	NULL, 
-	datagram_select,
-	NULL,			/* No ioctl */
-	packet_init,
-	NULL,
-	NULL,			/* No set/get socket options */
-	NULL,
-	packet_sendmsg,		/* Sendmsg */
-	packet_recvmsg,		/* Recvmsg */
-	packet_bind,		/* Bind */
-	128,
-	0,
-	"PACKET",
-	0, 0
+	(struct sock *)&packet_prot,	/* sklist_next */
+	(struct sock *)&packet_prot,	/* sklist_prev */
+	packet_close,			/* close */
+	ip_build_header,		/* build_header, Not actually used */
+	NULL,				/* connect */
+	NULL,				/* accept */
+	ip_queue_xmit,			/* queue_xmit, These two are not actually used */
+	NULL,				/* retransmit */
+	NULL,				/* write_wakeup */
+	NULL,				/* read_wakeup */
+	NULL,				/* rcv */
+	datagram_select,		/* select */
+	NULL,				/* ioctl, No ioctl */
+	packet_init,			/* init */
+	NULL,				/* shutdown */
+	NULL,				/* setsockopt, No set/get socket options */
+	NULL,				/* getsockopt */
+	packet_sendmsg,			/* sendmsg */
+	packet_recvmsg,			/* recvmsg */
+	packet_bind,			/* bind */
+	NULL,				/* hash */
+	NULL,				/* unhash */
+	NULL,				/* rehash */
+	NULL,				/* good_socknum */
+	NULL,				/* verify_bind */
+	128,				/* max_header */
+	0,				/* retransmits */
+	"PACKET",			/* name */
+	0,				/* inuse */
+	0				/* highestinuse */
 };
-
-	
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/proc.c linux/net/ipv4/proc.c
--- vanilla/v2.0.29/linux/net/ipv4/proc.c	Mon Jun  3 07:23:42 1996
+++ linux/net/ipv4/proc.c	Mon Mar  3 04:32:44 1997
@@ -57,21 +57,16 @@
 static int
 get__netinfo(struct proto *pro, char *buffer, int format, char **start, off_t offset, int length)
 {
-	struct sock **s_array;
 	struct sock *sp;
-	int i;
-	int timer_active;
-	int timer_active1;
-	int timer_active2;
+	int timer_active, timer_active1, timer_active2;
 	unsigned long timer_expires;
 	unsigned long  dest, src;
 	unsigned short destp, srcp;
-	int len=0;
+	int len=0, i = 0;
 	off_t pos=0;
 	off_t begin;
 	char tmpbuf[129];
   
-	s_array = pro->sock_array;
 	if (offset < 128) 
 		len += sprintf(buffer, "%-127s\n",
 			       "  sl  local_address rem_address   st tx_queue "
@@ -83,71 +78,62 @@
  *	a memory timer destroy. Instead of playing with timers we just
  *	concede defeat and cli().
  */
-	for(i = 0; i < SOCK_ARRAY_SIZE; i++) 
-	{
-	  	cli();
-		sp = s_array[i];
-		while(sp != NULL) 
-		{
-			pos += 128;
-			if (pos < offset)
-			{
-				sp = sp->next;
-				continue;
-			}
-			dest  = sp->daddr;
-			src   = sp->saddr;
-			destp = sp->dummy_th.dest;
-			srcp  = sp->dummy_th.source;
-
-			/* Since we are Little Endian we need to swap the bytes :-( */
-			destp = ntohs(destp);
-			srcp  = ntohs(srcp);
-			timer_active1 = del_timer(&sp->retransmit_timer);
-			timer_active2 = del_timer(&sp->timer);
-			if (!timer_active1) sp->retransmit_timer.expires=0;
-			if (!timer_active2) sp->timer.expires=0;
-			timer_active=0;
-			timer_expires=(unsigned)-1;
-			if (timer_active1 &&
-			  sp->retransmit_timer.expires < timer_expires) {
-			    timer_active=timer_active1;
-			    timer_expires=sp->retransmit_timer.expires;
-			}
-			if (timer_active2 &&
-			  sp->timer.expires < timer_expires) {
-			    timer_active=timer_active2;
-			    timer_expires=sp->timer.expires;
-			}
-			sprintf(tmpbuf, "%4d: %08lX:%04X %08lX:%04X"
-				" %02X %08X:%08X %02X:%08lX %08X %5d %8d %ld",
-				i, src, srcp, dest, destp, sp->state, 
-				format==0?sp->write_seq-sp->rcv_ack_seq:sp->wmem_alloc, 
-				format==0?sp->acked_seq-sp->copied_seq:sp->rmem_alloc,
-				timer_active, timer_expires-jiffies, (unsigned) sp->retransmits,
-				(sp->socket&&SOCK_INODE(sp->socket))?SOCK_INODE(sp->socket)->i_uid:0,
-				timer_active?sp->timeout:0,
-				sp->socket && SOCK_INODE(sp->socket) ?
-				SOCK_INODE(sp->socket)->i_ino : 0);
-			if (timer_active1) add_timer(&sp->retransmit_timer);
-			if (timer_active2) add_timer(&sp->timer);
-			len += sprintf(buffer+len, "%-127s\n", tmpbuf);
-			/*
-			 * All sockets with (port mod SOCK_ARRAY_SIZE) = i
-			 * are kept in sock_array[i], so we must follow the
-			 * 'next' link to get them all.
-			 */
-			if(len >= length)
-				break;
-			sp = sp->next;
+	start_bh_atomic();
+	sp = pro->sklist_next;
+	while(sp != (struct sock *)pro) {
+		pos += 128;
+		if (pos < offset)
+			goto next;
+
+		dest  = sp->daddr;
+		src   = sp->saddr;
+		destp = sp->dummy_th.dest;
+		srcp  = sp->dummy_th.source;
+
+		/* Since we are Little Endian we need to swap the bytes :-( */
+		destp = ntohs(destp);
+		srcp  = ntohs(srcp);
+		timer_active1 = del_timer(&sp->retransmit_timer);
+		timer_active2 = del_timer(&sp->timer);
+		if (!timer_active1) sp->retransmit_timer.expires=0;
+		if (!timer_active2) sp->timer.expires=0;
+		timer_active=0;
+		timer_expires=(unsigned)-1;
+		if (timer_active1 &&
+		    sp->retransmit_timer.expires < timer_expires) {
+			timer_active=timer_active1;
+			timer_expires=sp->retransmit_timer.expires;
 		}
-		sti();	/* We only turn interrupts back on for a moment,
-			   but because the interrupt queues anything built
-			   up before this will clear before we jump back
-			   and cli(), so it's not as bad as it looks */
-		if(len>= length)
+		if (timer_active2 &&
+		    sp->timer.expires < timer_expires) {
+			timer_active=timer_active2;
+			timer_expires=sp->timer.expires;
+		}
+		sprintf(tmpbuf, "%4d: %08lX:%04X %08lX:%04X"
+			" %02X %08X:%08X %02X:%08lX %08X %5d %8d %ld",
+			i, src, srcp, dest, destp, sp->state, 
+			format==0?sp->write_seq-sp->rcv_ack_seq:sp->wmem_alloc, 
+			format==0?sp->acked_seq-sp->copied_seq:sp->rmem_alloc,
+			timer_active, timer_expires-jiffies, (unsigned) sp->retransmits,
+			(sp->socket&&SOCK_INODE(sp->socket))?SOCK_INODE(sp->socket)->i_uid:0,
+			timer_active?sp->timeout:0,
+			sp->socket && SOCK_INODE(sp->socket) ?
+			SOCK_INODE(sp->socket)->i_ino : 0);
+		if (timer_active1) add_timer(&sp->retransmit_timer);
+		if (timer_active2) add_timer(&sp->timer);
+		len += sprintf(buffer+len, "%-127s\n", tmpbuf);
+		/*
+		 * All sockets are kept in the protocols sklist, so we
+		 * follow the 'next' link to get them all.
+		 */
+		if(len >= length)
 			break;
+	next:
+		sp = sp->sklist_next;
+		i++;
 	}
+	end_bh_atomic();
+
 	begin = len - (pos - offset);
 	*start = buffer + begin;
 	len -= begin;
@@ -186,7 +172,6 @@
 
 	int len  = socket_get_info(buffer,start,offset,length);
 
-	len += sprintf(buffer+len,"SOCK_ARRAY_SIZE=%d\n",SOCK_ARRAY_SIZE);
 	len += sprintf(buffer+len,"TCP: inuse %d highest %d\n",
 		       tcp_prot.inuse, tcp_prot.highestinuse);
 	len += sprintf(buffer+len,"UDP: inuse %d highest %d\n",
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/raw.c linux/net/ipv4/raw.c
--- vanilla/v2.0.29/linux/net/ipv4/raw.c	Sun Oct  6 10:42:09 1996
+++ linux/net/ipv4/raw.c	Mon Mar  3 05:04:35 1997
@@ -30,6 +30,7 @@
  *		Alan Cox	:	Beginnings of mrouted support.
  *		Alan Cox	:	Added IP_HDRINCL option.
  *		Alan Cox	:	Skip broadcast check if BSDism set.
+ *		David S. Miller	:	New socket lookup architecture for ISS.
  *
  *		This program is free software; you can redistribute it and/or
  *		modify it under the terms of the GNU General Public License
@@ -58,12 +59,89 @@
 #include <net/sock.h>
 #include <net/icmp.h>
 #include <net/udp.h>
+#include <net/raw.h>
 #include <net/checksum.h>
 
 #ifdef CONFIG_IP_MROUTE
 struct sock *mroute_socket=NULL;
 #endif
 
+struct sock *raw_v4_htable[RAWV4_HTABLE_SIZE];
+
+static void raw_v4_hash(struct sock *sk)
+{
+	struct sock **skp;
+	int num = sk->num;
+
+	num &= (RAWV4_HTABLE_SIZE - 1);
+	skp = &raw_v4_htable[num];
+	SOCKHASH_LOCK();
+	sk->next = *skp;
+	*skp = sk;
+	sk->hashent = num;
+	SOCKHASH_UNLOCK();
+}
+
+static void raw_v4_unhash(struct sock *sk)
+{
+	struct sock **skp;
+	int num = sk->num;
+
+	num &= (RAWV4_HTABLE_SIZE - 1);
+	skp = &raw_v4_htable[num];
+
+	SOCKHASH_LOCK();
+	while(*skp != NULL) {
+		if(*skp == sk) {
+			*skp = sk->next;
+			break;
+		}
+		skp = &((*skp)->next);
+	}
+	SOCKHASH_UNLOCK();
+}
+
+static void raw_v4_rehash(struct sock *sk)
+{
+	struct sock **skp;
+	int num = sk->num;
+	int oldnum = sk->hashent;
+
+	num &= (RAWV4_HTABLE_SIZE - 1);
+	skp = &raw_v4_htable[oldnum];
+
+	SOCKHASH_LOCK();
+	while(*skp != NULL) {
+		if(*skp == sk) {
+			*skp = sk->next;
+			break;
+		}
+		skp = &((*skp)->next);
+	}
+	sk->next = raw_v4_htable[num];
+	raw_v4_htable[num] = sk;
+	sk->hashent = num;
+	SOCKHASH_UNLOCK();
+}
+
+/* Grumble... icmp and ip_input want to get at this... */
+struct sock *raw_v4_lookup(struct sock *sk, unsigned short num,
+			   unsigned long raddr, unsigned long laddr)
+{
+	struct sock *s = sk;
+
+	SOCKHASH_LOCK();
+	for(s = sk; s; s = s->next) {
+		if((s->num == num) 				&&
+		   !(s->dead && (s->state == TCP_CLOSE))	&&
+		   !(s->daddr && s->daddr != raddr) 		&&
+		   !(s->rcv_saddr && s->rcv_saddr != laddr))
+			break; /* gotcha */
+	}
+	SOCKHASH_UNLOCK();
+	return s;
+}
+
 static inline unsigned long min(unsigned long a, unsigned long b)
 {
 	if (a < b) 
@@ -137,6 +215,31 @@
 	return 0;
 }
 
+/* This gets rid of all the nasties in af_inet. -DaveM */
+static int raw_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
+{
+	struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
+	int chk_addr_ret;
+
+	if((sk->state != TCP_CLOSE) || (addr_len < sizeof(struct sockaddr_in)))
+		return -EINVAL;
+	chk_addr_ret = ip_chk_addr(addr->sin_addr.s_addr);
+	if(addr->sin_addr.s_addr != 0 && chk_addr_ret != IS_MYADDR &&
+	   chk_addr_ret != IS_MULTICAST && chk_addr_ret != IS_BROADCAST) {
+#ifdef CONFIG_IP_TRANSPARENT_PROXY
+		/* Superuser may bind to any address to allow transparent proxying. */
+		if(!suser())
+#endif
+			return -EADDRNOTAVAIL;
+	}
+	sk->rcv_saddr = sk->saddr = addr->sin_addr.s_addr;
+	if(chk_addr_ret == IS_MULTICAST || chk_addr_ret == IS_BROADCAST)
+		sk->saddr = 0;  /* Use device */
+	ip_rt_put(sk->ip_route_cache);
+	sk->ip_route_cache = NULL;
+	return 0;
+}
+
 /*
  *	This should be the easiest of all, all we do is
  *	copy it into a buffer. All demultiplexing is done
@@ -375,31 +478,38 @@
 
 
 struct proto raw_prot = {
-	raw_close,
-	ip_build_header,
-	udp_connect,
-	NULL,
-	ip_queue_xmit,
-	NULL,
-	NULL,
-	NULL,
-	raw_rcv_redo,
-	datagram_select,
+	(struct sock *)&raw_prot,	/* sklist_next */
+	(struct sock *)&raw_prot,	/* sklist_prev */
+	raw_close,			/* close */
+	ip_build_header,		/* build_header */
+	udp_connect,			/* connect */
+	NULL,				/* accept */
+	ip_queue_xmit,			/* queue_xmit */
+	NULL,				/* retransmit */
+	NULL,				/* write_wakeup */
+	NULL,				/* read_wakeup */
+	raw_rcv_redo,			/* rcv */
+	datagram_select,		/* select */
 #ifdef CONFIG_IP_MROUTE	
-	ipmr_ioctl,
+	ipmr_ioctl,			/* ioctl */
 #else
-	NULL,
+	NULL,				/* ioctl */
 #endif		
-	raw_init,
-	NULL,
-	ip_setsockopt,
-	ip_getsockopt,
-	raw_sendmsg,
-	raw_recvmsg,
-	NULL,		/* No special bind */
-	128,
-	0,
-	"RAW",
-	0, 0,
-	{NULL,}
+	raw_init,			/* init */
+	NULL,				/* shutdown */
+	ip_setsockopt,			/* setsockopt */
+	ip_getsockopt,			/* getsockopt */
+	raw_sendmsg,			/* sendmsg */
+	raw_recvmsg,			/* recvmsg */
+	raw_bind,			/* bind */
+	raw_v4_hash,			/* hash */
+	raw_v4_unhash,			/* unhash */
+	raw_v4_rehash,			/* rehash */
+	NULL,				/* good_socknum */
+	NULL,				/* verify_bind */
+	128,				/* max_header */
+	0,				/* retransmits */
+	"RAW",				/* name */
+	0,				/* inuse */
+	0				/* highestinuse */
 };
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/tcp.c linux/net/ipv4/tcp.c
--- vanilla/v2.0.29/linux/net/ipv4/tcp.c	Wed Nov 27 02:44:11 1996
+++ linux/net/ipv4/tcp.c	Thu Mar  6 22:07:19 1997
@@ -203,6 +203,8 @@
  *	Stefan Magdalinski	:	adjusted tcp_readable() to fix FIONREAD
  *	Willy Konynenberg	:	Transparent proxying support.
  *		Theodore Ts'o	:	Do secure TCP sequence numbers.
+ *		David S. Miller	:	New socket lookup architecture for ISS.
+ *					This code is dedicated to John Dyson.
  *					
  * To Fix:
  *		Fast path the code. Two things here - fix the window calculation
@@ -438,6 +440,203 @@
 unsigned long seq_offset;
 struct tcp_mib	tcp_statistics;
 
+/* This is for sockets with full identity only.  Sockets here will always
+ * be without wildcards and will have the following invariant:
+ *          TCP_ESTABLISHED <= sk->state < TCP_CLOSE
+ */
+struct sock *tcp_established_hash[TCP_HTABLE_SIZE];
+
+/* All sockets in TCP_LISTEN state will be in here.  This is the only table
+ * where wildcard'd TCP sockets can exist.  Hash function here is just local
+ * port number.  XXX Fix or we'll lose with thousands of IP aliases...
+ */
+struct sock *tcp_listening_hash[TCP_LHTABLE_SIZE];
+
+/* Ok, let's try this, I give up, we do need a local binding
+ * TCP hash as well as the others for fast bind/connect.
+ */
+struct sock *tcp_bound_hash[TCP_BHTABLE_SIZE];
+
+extern struct sock *tcp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport);
+
+static int tcp_v4_verify_bind(struct sock *sk, unsigned short snum)
+{
+	struct sock *sk2;
+	int retval = 0, sk_reuse = sk->reuse;
+
+	SOCKHASH_LOCK();
+	sk2 = tcp_bound_hash[tcp_bhashfn(snum)];
+	for(; sk2 != NULL; sk2 = sk2->bind_next) {
+		if((sk2->num == snum) && (sk2 != sk)) {
+			unsigned char state = sk2->state;
+			int sk2_reuse = sk2->reuse;
+
+			if(!sk2->rcv_saddr || !sk->rcv_saddr) {
+				if((!sk2_reuse)			||
+				   (!sk_reuse)			||
+				   (state == TCP_LISTEN)) {
+					retval = 1;
+					break;
+				}
+			} else if(sk2->rcv_saddr == sk->rcv_saddr) {
+				if((!sk_reuse)			||
+				   (!sk2_reuse)			||
+				   (state == TCP_LISTEN)) {
+					retval = 1;
+					break;
+				}
+			}
+		}
+	}
+	SOCKHASH_UNLOCK();
+
+	return retval;
+}
+
+static __inline__ int tcp_lport_inuse(int num)
+{
+	struct sock *sk = tcp_bound_hash[tcp_bhashfn(num)];
+
+	for(; sk != NULL; sk = sk->bind_next) {
+		if(sk->num == num)
+			return 1;
+	}
+	return 0;
+}
+
+/* Find a "good" local port, this is family independant.
+ * There are several strategies working in unison here to
+ * get the best possible performance.  The current socket
+ * load is kept track of, if it is zero there is a strong
+ * likely hood that there is a zero length chain we will
+ * find with a small amount of searching, else the load is
+ * what we shoot for for when the chains all have at least
+ * one entry.  The base helps us walk the chains in an
+ * order such that a good chain is found as quickly as possible.  -DaveM
+ */
+unsigned short tcp_good_socknum(void)
+{
+	static int start = PROT_SOCK;
+	static int binding_contour = 0;
+	int best = 0;
+	int size = 32767; /* a big num. */
+	int retval = 0, i, end, bc;
+
+	SOCKHASH_LOCK();
+	i = tcp_bhashfn(start);
+	end = i + TCP_BHTABLE_SIZE;
+	bc = binding_contour;
+	do {
+		struct sock *sk = tcp_bound_hash[tcp_bhashfn(i)];
+		if(!sk) {
+			retval = (start + i);
+			start  = (retval + 1);
+
+			/* Check for decreasing load. */
+			if(bc != 0)
+				binding_contour = 0;
+			goto done;
+		} else {
+			int j = 0;
+			do { sk = sk->bind_next; } while(++j < size && sk);
+			if(j < size) {
+				best = (start + i);
+				size = j;
+				if(bc && size <= bc) {
+					start = best + 1;
+					goto verify;
+				}
+			}
+		}
+	} while(++i != end);
+
+	/* Socket load is increasing, adjust our load average. */
+	binding_contour = size;
+verify:
+	if(size < binding_contour)
+		binding_contour = size;
+
+	if(best > 32767)
+		best -= (32768 - PROT_SOCK);
+
+	while(tcp_lport_inuse(best))
+		best += TCP_BHTABLE_SIZE;
+	retval = best;
+done:
+	if(start > 32767)
+		start -= (32768 - PROT_SOCK);
+
+	SOCKHASH_UNLOCK();
+
+	return retval;
+}
+
+void tcp_v4_hash(struct sock *sk)
+{
+	unsigned char state;
+
+	SOCKHASH_LOCK();
+	state = sk->state;
+	if(state != TCP_CLOSE || !sk->dead) {
+		struct sock **skp;
+
+		if(state == TCP_LISTEN)
+			skp = &tcp_listening_hash[tcp_sk_listen_hashfn(sk)];
+		else
+			skp = &tcp_established_hash[tcp_sk_hashfn(sk)];
+
+		if((sk->next = *skp) != NULL)
+			(*skp)->pprev = &sk->next;
+		*skp = sk;
+		sk->pprev = skp;
+		tcp_sk_bindify(sk);
+	}
+	SOCKHASH_UNLOCK();
+}
+
+void tcp_v4_unhash(struct sock *sk)
+{
+	SOCKHASH_LOCK();
+	if(sk->pprev) {
+		if(sk->next)
+			sk->next->pprev = sk->pprev;
+		*sk->pprev = sk->next;
+		sk->pprev = NULL;
+		tcp_sk_unbindify(sk);
+	}
+	SOCKHASH_UNLOCK();
+}
+
+void tcp_v4_rehash(struct sock *sk)
+{
+	unsigned char state;
+
+	SOCKHASH_LOCK();
+	state = sk->state;
+	if(sk->pprev) {
+		if(sk->next)
+			sk->next->pprev = sk->pprev;
+		*sk->pprev = sk->next;
+		sk->pprev = NULL;
+		tcp_sk_unbindify(sk);
+	}
+	if(state != TCP_CLOSE || !sk->dead) {
+		struct sock **skp;
+
+		if(state == TCP_LISTEN)
+			skp = &tcp_listening_hash[tcp_sk_listen_hashfn(sk)];
+		else
+			skp = &tcp_established_hash[tcp_sk_hashfn(sk)];
+
+		if((sk->next = *skp) != NULL)
+			(*skp)->pprev = &sk->next;
+		*skp = sk;
+		sk->pprev = skp;
+		tcp_sk_bindify(sk);
+	}
+	SOCKHASH_UNLOCK();
+}
+
 static void tcp_close(struct sock *sk, unsigned long timeout);
 
 /*
@@ -518,8 +717,7 @@
 	if (len < 8)	/* NOT sizeof(struct tcphdr) */
 		return;
 		
-	sk = get_sock(&tcp_prot, th->source, daddr, th->dest, saddr, 0, 0);
-
+	sk = tcp_v4_lookup(daddr, th->dest, saddr, th->source);
 	if (sk == NULL)
 		return;
 
@@ -1753,7 +1951,6 @@
 
 	lock_sock(sk);
 
-	tcp_cache_zap();
 	if(sk->state == TCP_LISTEN)
 	{
 		/* Special case */
@@ -1761,6 +1958,7 @@
 		tcp_close_pending(sk);
 		release_sock(sk);
 		sk->dead = 1;
+		tcp_v4_unhash(sk);
 		return;
 	}
 
@@ -1813,12 +2011,6 @@
 		sti();
 	}
 
-	/*
-	 * This will destroy it. The timers will take care of actually
-	 * free'ing up the memory.
-	 */
-	tcp_cache_zap();	/* Kill the cache again. */
-
 	/* Now that the socket is dead, if we are in the FIN_WAIT2 state
 	 * we may need to set up a timer.
          */
@@ -1833,6 +2025,9 @@
 
 	release_sock(sk);
 	sk->dead = 1;
+
+	if(sk->state == TCP_CLOSE)
+		tcp_v4_unhash(sk);
 }
 
 
@@ -1916,27 +2111,24 @@
  */
 static int tcp_unique_address(u32 saddr, u16 snum, u32 daddr, u16 dnum)
 {
-	int retval = 1;
+	int retval = 1, hashent = tcp_hashfn(saddr, snum, daddr, dnum);
 	struct sock * sk;
 
-	/* Make sure we are allowed to connect here. */
-	cli();
-	for (sk = tcp_prot.sock_array[snum & (SOCK_ARRAY_SIZE -1)];
-			sk != NULL; sk = sk->next)
-	{
-		/* hash collision? */
-		if (sk->num != snum)
-			continue;
-		if (sk->saddr != saddr)
-			continue;
-		if (sk->daddr != daddr)
-			continue;
-		if (sk->dummy_th.dest != dnum)
-			continue;
-		retval = 0;
-		break;
+	/* Make sure we are allowed to connect here.
+	 * But freeze the hash while we snoop around.
+	 */
+	SOCKHASH_LOCK();
+	sk = tcp_established_hash[hashent];
+	for (; sk != NULL; sk = sk->next) {
+		if(sk->daddr		== daddr		&& /* remote address */
+		   sk->dummy_th.dest	== dnum			&& /* remote port */
+		   sk->num		== snum			&& /* local port */
+		   sk->saddr		== saddr) {		   /* local address */
+			retval = 0;
+			break;
+		}
 	}
-	sti();
+	SOCKHASH_UNLOCK();
 	return retval;
 }
 
@@ -2077,12 +2269,13 @@
 	tcp_send_check(t1, sk->saddr, sk->daddr,
 		  sizeof(struct tcphdr) + 4, buff);
 
-	/*
-	 *	This must go first otherwise a really quick response will get reset.
+	tcp_set_state(sk,TCP_SYN_SENT);
+
+	/* Socket identity change complete, no longer
+	 * in TCP_CLOSE, so rehash.
 	 */
+	tcp_v4_rehash(sk);
 
-	tcp_cache_zap();
-	tcp_set_state(sk,TCP_SYN_SENT);
 	if(rt&&rt->rt_flags&RTF_IRTT)
 		sk->rto = rt->rt_irtt;
 	else
@@ -2174,27 +2367,34 @@
 
 
 struct proto tcp_prot = {
-	tcp_close,
-	ip_build_header,
-	tcp_connect,
-	tcp_accept,
-	ip_queue_xmit,
-	tcp_retransmit,
-	tcp_write_wakeup,
-	tcp_read_wakeup,
-	tcp_rcv,
-	tcp_select,
-	tcp_ioctl,
-	NULL,
-	tcp_shutdown,
-	tcp_setsockopt,
-	tcp_getsockopt,
-	tcp_sendmsg,
-	tcp_recvmsg,
-	NULL,		/* No special bind() */
-	128,
-	0,
-	"TCP",
-	0, 0,
-	{NULL,}
+	(struct sock *)&tcp_prot,	/* sklist_next */
+	(struct sock *)&tcp_prot,	/* sklist_prev */
+	tcp_close,			/* close */
+	ip_build_header,		/* build_header */
+	tcp_connect,			/* connect */
+	tcp_accept,			/* accept */
+	ip_queue_xmit,			/* queue_xmit */
+	tcp_retransmit,			/* retransmit */
+	tcp_write_wakeup,		/* write_wakeup */
+	tcp_read_wakeup,		/* read_wakeup */
+	tcp_rcv,			/* rcv */
+	tcp_select,			/* select */
+	tcp_ioctl,			/* ioctl */
+	NULL,				/* init */
+	tcp_shutdown,			/* shutdown */
+	tcp_setsockopt,			/* setsockopt */
+	tcp_getsockopt,			/* getsockopt */
+	tcp_sendmsg,			/* sendmsg */
+	tcp_recvmsg,			/* recvmsg */
+	NULL,				/* bind */
+	tcp_v4_hash,			/* hash */
+	tcp_v4_unhash,			/* unhash */
+	tcp_v4_rehash,			/* rehash */
+	tcp_good_socknum,		/* good_socknum */
+	tcp_v4_verify_bind,		/* verify_bind */
+	128,				/* max_header */
+	0,				/* retransmits */
+	"TCP",				/* name */
+	0,				/* inuse */
+	0				/* highestinuse */
 };
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/tcp_input.c linux/net/ipv4/tcp_input.c
--- vanilla/v2.0.29/linux/net/ipv4/tcp_input.c	Sat Nov 30 05:51:03 1996
+++ linux/net/ipv4/tcp_input.c	Thu Mar  6 21:44:31 1997
@@ -26,9 +26,13 @@
  *		Eric Schenk	:	Delayed ACK bug fixes.
  *		Eric Schenk	:	Floyd style fast retrans war avoidance.
  *		Eric Schenk	: 	Skip fast retransmit on small windows.
- *		Eric schenk	:	Fixes to retransmission code to
+ *		Eric Schenk	:	Fixes to retransmission code to
  *				:	avoid extra retransmission.
  *		Theodore Ts'o	:	Do secure TCP sequence numbers.
+ *		Eric Schenk	:	SYN and RST cookies for dealing
+ *				:	with SYN flooding attacks.
+ *		David S. Miller	:	New socket lookup architecture for ISS.
+ *					This code is dedicated to John Dyson.
  */
 
 #include <linux/config.h>
@@ -146,42 +150,200 @@
 	sk->backoff = 0;
 }
 
+#if defined(CONFIG_RST_COOKIES)
+
 /*
- *	Cached last hit socket
- */
- 
-static volatile unsigned long 	th_cache_saddr, th_cache_daddr;
-static volatile unsigned short  th_cache_dport, th_cache_sport;
-static volatile struct sock *th_cache_sk;
+ * This code needs to be a bit more clever.
+ * Does 2 minute timeouts now. Still just a circular buffer.
+ * At most 32 validations stored. New validations are ignored
+ * if all 32 validations are currently valid. To do otherwise
+ * allows a situation in which clearances are forgotten before
+ * they can be used (provided valid traffic is coming fast enough).
+ * The buffer should really be as long as the number of valid
+ * connections we want to accept in an 2 minute period.
+ * 32 is maybe to small. On the other hand, the validation check
+ * algorithm has to walk the whole table, which is also stupid.
+ * It would be better to have a combined hash/circular buffer.
+ * The hash could be used with chaining for fast lookup.
+ * Really this is probably an argument against using RST cookies
+ * at all, since they take up space for the clearances.
+ */
+
+static struct {
+	u32 saddr;
+	unsigned long tstamp;
+} clearances[32] = {
+{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
+{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
+{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
+{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}};
+
+static next_clearance = 0;
+/* Does the address saddr have an active security clearance? */
+int tcp_clearance(__u32 saddr)
+{
+	int i;
+	for (i = 0; i < 32; i++)
+		if (clearances[i].saddr == saddr
+		&& clearances[i].tstamp > jiffies-HZ*120)
+			return 1;
+	return 0;
+}
 
-void tcp_cache_zap(void)
+void add_clearance(__u32 saddr)
 {
-	th_cache_sk=NULL;
+	/*
+	 * If expired then we can add a new entry.
+	 */
+	if (clearances[next_clearance].tstamp <= jiffies-HZ*300) {
+		clearances[next_clearance].saddr = saddr;
+		clearances[next_clearance].tstamp = jiffies;
+		next_clearance = (next_clearance+1)%32;
+	}
 }
 
+#endif
+
+#ifdef CONFIG_SYN_COOKIES
 /*
- *	Find the socket, using the last hit cache if applicable. The cache is not quite
- *	right...
+ *	MTU values we can represent in fall back mode.
+ *	FIXME. I sort of picked these out of a hat. I should
+ *	probably look around for docs on what common values are.
  */
+static __u32 cookie_mtu[8] = { 64, 128, 256, 296, 512, 576, 1024, 1500 };
+#endif
 
-static inline struct sock * get_tcp_sock(u32 saddr, u16 sport, u32 daddr, u16 dport, u32 paddr, u16 pport)
+extern void tcp_v4_hash(struct sock *sk);
+extern void tcp_v4_unhash(struct sock *sk);
+extern void tcp_v4_rehash(struct sock *sk);
+
+/* Don't inline this cruft.  Here are some nice properties to
+ * exploit here.  The BSD API does not allow a listening TCP
+ * to specify the remote port nor the remote address for the
+ * connection.  So always assume those are both wildcarded
+ * during the search since they can never be otherwise.
+ *
+ * XXX Later on, hash on both local port _and_ local address,
+ * XXX to handle a huge IP alias'd box.  Keep in mind that
+ * XXX such a scheme will require us to run through the listener
+ * XXX hash twice, once for local addresses bound, and once for
+ * XXX the local address wildcarded (because the hash is different).
+ */
+static struct sock *tcp_v4_lookup_longway(u32 daddr, unsigned short hnum)
 {
-	struct sock * sk;
+	struct sock *sk = tcp_listening_hash[tcp_lhashfn(hnum)];
+	struct sock *result = NULL;
 
-	sk = (struct sock *) th_cache_sk;
-	if (!sk || saddr != th_cache_saddr || daddr != th_cache_daddr ||
-	    sport != th_cache_sport || dport != th_cache_dport) {
-		sk = get_sock(&tcp_prot, dport, saddr, sport, daddr, paddr, pport);
-		if (sk) {
-			th_cache_saddr=saddr;
-			th_cache_daddr=daddr;
-  			th_cache_dport=dport;
-			th_cache_sport=sport;
-			th_cache_sk=sk;
+	for(; sk; sk = sk->next) {
+		if(sk->num == hnum) {
+			__u32 rcv_saddr = sk->rcv_saddr;
+
+			if(rcv_saddr) {
+				if(rcv_saddr == daddr)
+					return sk; /* Best possible match. */
+			} else if(!result)
+				result = sk;
 		}
 	}
+	return result;
+}
+
+/* Sockets in TCP_CLOSE state are _always_ taken out of the hash, so
+ * we need not check it for TCP lookups anymore, thanks Alexey. -DaveM
+ */
+static inline struct sock *__tcp_v4_lookup(struct tcphdr *th,
+					   u32 saddr, u16 sport, u32 daddr, u16 dport)
+{
+	unsigned short hnum = ntohs(dport);
+	struct sock *sk;
+
+	/* Optimize here for direct hit, only listening connections can
+	 * have wildcards anyways.  It is assumed that this code only
+	 * gets called from within NET_BH.
+	 */
+	sk = tcp_established_hash[tcp_hashfn(daddr, hnum, saddr, sport)];
+	for(; sk; sk = sk->next)
+		if(sk->daddr		== saddr		&& /* remote address */
+		   sk->dummy_th.dest	== sport		&& /* remote port    */
+		   sk->num		== hnum			&& /* local port     */
+		   sk->rcv_saddr	== daddr)		   /* local address  */
+			goto hit; /* You sunk my battleship! */
+	sk = tcp_v4_lookup_longway(daddr, hnum);
+hit:
 	return sk;
 }
+ 
+__inline__ struct sock *tcp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport)
+{
+	return __tcp_v4_lookup(0, saddr, sport, daddr, dport);
+}
+
+#ifdef CONFIG_IP_TRANSPARENT_PROXY
+#define secondlist(hpnum, sk, fpass) \
+({ struct sock *s1; if(!(sk) && (fpass)--) \
+	s1 = tcp_bound_hash[tcp_bhashfn(hpnum)]; \
+   else \
+	s1 = (sk); \
+   s1; \
+})
+
+#define tcp_v4_proxy_loop_init(hnum, hpnum, sk, fpass) \
+	secondlist((hpnum), tcp_bound_hash[tcp_bhashfn(hnum)],(fpass))
+
+#define tcp_v4_proxy_loop_next(hnum, hpnum, sk, fpass) \
+	secondlist((hpnum),(sk)->next,(fpass))
+
+struct sock *tcp_v4_proxy_lookup(unsigned short num, unsigned long raddr,
+				 unsigned short rnum, unsigned long laddr,
+				 unsigned long paddr, unsigned short pnum)
+{
+	struct sock *s, *result = NULL;
+	int badness = -1;
+	unsigned short hnum = ntohs(num);
+	unsigned short hpnum = ntohs(pnum);
+	int firstpass = 1;
+
+	/* This code must run only from NET_BH. */
+	for(s = tcp_v4_proxy_loop_init(hnum, hpnum, s, firstpass);
+	    s != NULL;
+	    s = tcp_v4_proxy_loop_next(hnum, hpnum, s, firstpass)) {
+		if(s->num == hnum || s->num == hpnum) {
+			int score = 0;
+			if(s->dead && (s->state == TCP_CLOSE))
+				continue;
+			if(s->rcv_saddr) {
+				if((s->num != hpnum || s->rcv_saddr != paddr) &&
+				   (s->num != hnum || s->rcv_saddr != laddr))
+					continue;
+				score++;
+			}
+			if(s->daddr) {
+				if(s->daddr != raddr)
+					continue;
+				score++;
+			}
+			if(s->dummy_th.dest) {
+				if(s->dummy_th.dest != rnum)
+					continue;
+				score++;
+			}
+			if(score == 3 && s->num == hnum) {
+				result = s;
+				break;
+			} else if(score > badness && (s->num == hpnum || s->rcv_saddr)) {
+					result = s;
+					badness = score;
+			}
+		}
+	}
+	return result;
+}
+
+#undef secondlist
+#undef tcp_v4_proxy_loop_init
+#undef tcp_v4_proxy_loop_next
+
+#endif
 
 /*
  * React to a out-of-window TCP sequence number in an incoming packet
@@ -363,7 +525,10 @@
 	struct sock *newsk;
 	struct tcphdr *th;
 	struct rtable *rt;
-  
+#ifdef CONFIG_SYN_COOKIES
+	int send_cookie = 0;
+#endif
+
 	th = skb->h.th;
 
 	/* If the socket is dead, don't accept the connection. */
@@ -387,13 +552,59 @@
 	 *
 	 *	BSD does some funnies here and allows 3/2 times the
 	 *	set backlog as a fudge factor. That's just too gross.
+	 *
+         *	Well, now I'm making things even grosser for dealing
+	 *	with SYNACK flooding.
 	 */
 
-	if (sk->ack_backlog >= sk->max_ack_backlog) 
+	if (sk->ack_backlog >= sk->max_ack_backlog)
 	{
+#if defined(CONFIG_RST_COOKIES) || defined(CONFIG_SYN_COOKIES)
+		/* We may be experiencing SYNACK flooding.
+		 * We now must decide if we should accept this connection.
+		 * If we have a security clearance for the incoming
+		 * packet, i.e. it is from a location we where talking
+		 * to succesfully recently, or that has responded to
+		 * a security probe, then we go ahead and deal normally,
+		 * accepting up to 2*max in the backlog.
+		 * Otherwise, we send out either an RST security probe
+		 * or a SYN cookie, or both. (depending on configuration).
+		 * Note that we send out a cookie even if the backlog
+		 * is full up to 2*max, since the backlog may clear
+		 * by the time we get a response.
+		 * WARNING: This code changes the semantics of the backlog
+		 * a bit. I'm not entirely sure this is the right thing
+		 * to do here.
+	 	 */
+		extern void tcp_send_synack_probe(unsigned long saddr,
+						  unsigned long daddr, struct tcphdr *th,
+						  struct proto *prot,
+						  struct options *opt,
+						  struct device *dev, int tos, int ttl);
+
+#ifdef CONFIG_RST_COOKIES
+		if (!tcp_clearance(saddr)) {
+#endif
+			printk(KERN_INFO "Warning: possible SYN flooding. Sending cookies.\n");
+#ifdef CONFIG_RST_COOKIES
+			tcp_send_synack_probe(daddr, saddr, th, &tcp_prot,
+				opt, dev, skb->ip_hdr->tos, 255);
+#endif
+#ifdef CONFIG_SYN_COOKIES
+			send_cookie = 1;
+#endif
+#ifdef CONFIG_RST_COOKIES
+		} else if (sk->ack_backlog >= 2*sk->max_ack_backlog) {
+			tcp_statistics.TcpAttemptFails++;
+			kfree_skb(skb, FREE_READ);
+			return;
+		}
+#endif
+#else
 		tcp_statistics.TcpAttemptFails++;
 		kfree_skb(skb, FREE_READ);
 		return;
+#endif
 	}
 
 	/*
@@ -414,6 +625,10 @@
 	}
 
 	memcpy(newsk, sk, sizeof(*newsk));
+
+	/* Or else we die! -DaveM */
+	newsk->sklist_next = NULL;
+
 	newsk->opt = NULL;
 	newsk->ip_route_cache  = NULL;
 	if (opt && opt->optlen) 
@@ -483,9 +698,6 @@
 	newsk->state = TCP_SYN_RECV;
 	newsk->timeout = 0;
 	newsk->ip_xmit_timeout = 0;
-	newsk->write_seq = seq; 
-	newsk->window_seq = newsk->write_seq;
-	newsk->rcv_ack_seq = newsk->write_seq;
 	newsk->urg_data = 0;
 	newsk->retransmits = 0;
 	newsk->linger=0;
@@ -518,8 +730,9 @@
 	newsk->daddr = saddr;
 	newsk->saddr = daddr;
 	newsk->rcv_saddr = daddr;
+	tcp_v4_hash(newsk);
+	add_to_prot_sklist(newsk);
 
-	put_sock(newsk->num,newsk);
 	newsk->acked_seq = skb->seq + 1;
 	newsk->copied_seq = skb->seq + 1;
 	newsk->socket = NULL;
@@ -579,12 +792,244 @@
 	 */
 
 	tcp_options(newsk,skb->h.th);
-	
-	tcp_cache_zap();
-	tcp_send_synack(newsk, sk, skb);
+
+#ifdef CONFIG_SYN_COOKIES
+	if (send_cookie) {
+		int mtu_index = 0;
+		/* Pick the largest MTU smaller than sk->mtu that we
+		 * can represent in a cookies bottom 3 bits.
+		 */
+		while (newsk->mtu > cookie_mtu[mtu_index+1] && mtu_index < 7)
+			mtu_index++;
+		newsk->mtu = cookie_mtu[mtu_index];
+		/*
+		 * Choose a cookie.
+		 */
+		seq = secure_tcp_syn_cookie(daddr,saddr,
+        	        ntohs(th->source),ntohs(th->dest),ntohl(th->seq),jiffies/(60*HZ));
+		seq |= mtu_index;
+	}
+#endif
+
+	/* Set up the right sequence numbers */
+	newsk->write_seq = seq; 
+	newsk->window_seq = newsk->write_seq;
+	newsk->rcv_ack_seq = newsk->write_seq;
+
+#ifdef CONFIG_SYN_COOKIES
+	tcp_send_synack(newsk, sk, skb, send_cookie);
+#else
+	tcp_send_synack(newsk, sk, skb, 0);
+#endif
 }
 
 
+#ifdef CONFIG_SYN_COOKIES
+/*
+ *	This routine handles a faked connection request as a result
+ *	of a valid SYN cookie being seen. This sets up a socket in the
+ *	SYN_SENT state.
+ */
+ 
+static int tcp_conn_request_fake(struct sock *sk, struct sk_buff *skb,
+		 u32 daddr, u32 saddr, struct options *opt, struct device *dev, u32 seq, u32 mtu)
+{
+	struct sock *newsk;
+	struct sk_buff *newskb;
+	struct rtable *rt;
+
+	/* If the socket is dead, don't accept the connection. */
+	if (!sk->dead) 
+	{
+  		sk->data_ready(sk,0);
+	}
+	else 
+	{
+		if(sk->debug)
+			printk("Reset on %p: Connect on dead socket.\n",sk);
+		tcp_statistics.TcpAttemptFails++;
+		return 0;
+	}
+
+	/*
+	 * We need to build a new sock struct.
+	 * It is sort of bad to have a socket without an inode attached
+	 * to it, but the wake_up's will just wake up the listening socket,
+	 * and if the listening socket is destroyed before this is taken
+	 * off of the queue, this will take care of it.
+	 */
+
+	newsk = (struct sock *) kmalloc(sizeof(struct sock), GFP_ATOMIC);
+	if (newsk == NULL) 
+	{
+		/* Bad juju. If we ignore things now the remote side
+		 * will be frozen. Really we should retrans the cookie,
+		 * but that's a no go also, since we don't have enough
+		 * memory to receive it either. So, we're stuck with
+		 * this bad case, and a few others further down.
+		 * We just have to hope it is a low probability event.
+		 * Also, to avoid a loop we must not go down into
+		 * the recursive call to tcp_rcv in the caller to this
+		 * routine, so we should let them know we failed.
+		 */
+		tcp_statistics.TcpAttemptFails++;
+		return 0;
+	}
+
+	memcpy(newsk, sk, sizeof(*newsk));
+
+	/* Or else we die! -DaveM */
+	newsk->sklist_next = NULL;
+
+	newsk->opt = NULL;
+	newsk->ip_route_cache  = NULL;
+	if (opt && opt->optlen) 
+	{
+		sk->opt = (struct options*)kmalloc(sizeof(struct options)+opt->optlen, GFP_ATOMIC);
+		if (!sk->opt) 
+		{
+			/* More bad juju. */
+	        	kfree_s(newsk, sizeof(struct sock));
+			tcp_statistics.TcpAttemptFails++;
+			return 0;
+		}
+		if (ip_options_echo(sk->opt, opt, daddr, saddr, skb)) 
+		{
+			/* More bad juju. */
+			kfree_s(sk->opt, sizeof(struct options)+opt->optlen);
+	        	kfree_s(newsk, sizeof(struct sock));
+			tcp_statistics.TcpAttemptFails++;
+			return 0;
+		}
+	}
+	
+	skb_queue_head_init(&newsk->write_queue);
+	skb_queue_head_init(&newsk->receive_queue);
+	newsk->send_head = NULL;
+	newsk->send_tail = NULL;
+	newsk->send_next = NULL;
+	skb_queue_head_init(&newsk->back_log);
+	newsk->rtt = 0;
+	newsk->rto = TCP_TIMEOUT_INIT;
+	newsk->mdev = TCP_TIMEOUT_INIT;
+	newsk->max_window = 0;
+	/*
+	 * See draft-stevens-tcpca-spec-01 for discussion of the
+	 * initialization of these values.
+	 */
+	newsk->cong_window = 1;
+	newsk->cong_count = 0;
+	newsk->ssthresh = 0x7fffffff;
+
+	newsk->lrcvtime = 0;
+	newsk->idletime = 0;
+	newsk->high_seq = 0;
+	newsk->backoff = 0;
+	newsk->blog = 0;
+	newsk->intr = 0;
+	newsk->proc = 0;
+	newsk->done = 0;
+	newsk->partial = NULL;
+	newsk->pair = NULL;
+	newsk->wmem_alloc = 0;
+	newsk->rmem_alloc = 0;
+	newsk->localroute = sk->localroute;
+
+	newsk->max_unacked = MAX_WINDOW - TCP_WINDOW_DIFF;
+
+	newsk->err = 0;
+	newsk->shutdown = 0;
+	newsk->ack_backlog = 0;
+	newsk->acked_seq = skb->seq;
+	newsk->lastwin_seq = skb->seq;
+	newsk->delay_acks = 1;
+	newsk->copied_seq = skb->seq;
+	newsk->fin_seq = skb->seq-1;
+	newsk->syn_seq = skb->seq-1;
+	newsk->state = TCP_SYN_RECV;
+	newsk->timeout = 0;
+	newsk->ip_xmit_timeout = 0;
+	newsk->urg_data = 0;
+	newsk->retransmits = 0;
+	newsk->linger=0;
+	newsk->destroy = 0;
+	init_timer(&newsk->timer);
+	newsk->timer.data = (unsigned long)newsk;
+	newsk->timer.function = &net_timer;
+	init_timer(&newsk->delack_timer);
+	newsk->delack_timer.data = (unsigned long)newsk;
+	newsk->delack_timer.function = tcp_delack_timer;
+	init_timer(&newsk->retransmit_timer);
+	newsk->retransmit_timer.data = (unsigned long)newsk;
+	newsk->retransmit_timer.function = tcp_retransmit_timer;
+	newsk->dummy_th.source = skb->h.th->dest;
+	newsk->dummy_th.dest = skb->h.th->source;
+	newsk->users=0;
+	
+#ifdef CONFIG_IP_TRANSPARENT_PROXY
+	/* 
+	 *	Deal with possibly redirected traffic by setting num to
+	 *	the intended destination port of the received packet.
+	 */
+	newsk->num = ntohs(skb->h.th->dest);
+
+#endif
+	/*
+	 *	Swap these two, they are from our point of view. 
+	 */
+	 
+	newsk->daddr = saddr;
+	newsk->saddr = daddr;
+	newsk->rcv_saddr = daddr;
+	tcp_v4_hash(newsk);
+	add_to_prot_sklist(newsk);
+
+	newsk->acked_seq = skb->seq;
+	newsk->copied_seq = skb->seq;
+	newsk->socket = NULL;
+
+	/*
+	 *	Grab the ttl and tos values and use them 
+	 */
+
+	newsk->ip_ttl=sk->ip_ttl;
+	newsk->ip_tos=skb->ip_hdr->tos;
+
+	rt = ip_rt_route(newsk->opt && newsk->opt->srr ? newsk->opt->faddr : saddr, 0);
+	newsk->ip_route_cache = rt;
+	
+	if (rt!=NULL && (rt->rt_flags&RTF_WINDOW))
+		newsk->window_clamp = rt->rt_window;
+	else
+		newsk->window_clamp = 0;
+
+	newsk->mtu = mtu;
+
+	/* Set up the right sequence numbers.
+	 * Note that we have to make sure write_seq is correct for having
+ 	 * sent off the handshake!
+	 */
+	newsk->write_seq = seq+1; 
+	newsk->sent_seq = seq+1;
+	newsk->window_seq = seq;
+	newsk->rcv_ack_seq = seq;
+	newsk->max_unacked = 2 * newsk->mss;
+
+	tcp_select_window(newsk);
+
+	/* We need to get something into the receive queue to enable an
+	 * accept. Possibly we should be faking up a SYN packet, but
+	 * as far as I can tell the contents of this skb don't matter,
+	 * so long as it points to our new socket.
+	 */
+	newskb = skb_clone(skb,GFP_ATOMIC);
+	newskb->sk = newsk;
+	sk->ack_backlog++;
+	skb_queue_tail(&sk->receive_queue,newskb);
+	return 1;
+}
+#endif
+
 /*
  * Handle a TCP window that shrunk on us. It shouldn't happen,
  * but..
@@ -787,7 +1232,7 @@
 
 	if (sk->rcv_ack_seq == ack
 		&& sk->window_seq == window_seq
-		&& len != th->doff*4
+		&& len == th->doff*4
 		&& before(ack, sk->sent_seq)
 		&& after(ack, sk->high_seq))
 	{
@@ -830,7 +1275,8 @@
 	else
 	{
 		if (sk->rcv_ack_cnt > MAX_DUP_ACKS) {
-			sk->cong_window = sk->ssthresh;
+			/* Don't allow congestion window to drop to zero. */
+			sk->cong_window = max(sk->ssthresh, 1);
 		}
 		sk->window_seq = window_seq;
 		sk->rcv_ack_seq = ack;
@@ -1166,7 +1612,12 @@
 	{
 		tcp_set_state(sk, TCP_ESTABLISHED);
 		tcp_options(sk,th);
+
+#if 0
 		sk->dummy_th.dest=th->source;
+		tcp_v4_rehash(sk);
+#endif
+
 		sk->copied_seq = sk->acked_seq;
 		if(!sk->dead)
 			sk->state_change(sk);
@@ -1738,11 +2189,12 @@
 	struct tcphdr *th = (struct tcphdr *)(skb->h.raw + iph->ihl*4);
 	struct sock *sk;
 
-	sk = get_sock(&tcp_prot, th->dest, iph->saddr, th->source, iph->daddr, 0, 0);
-
-	if (!sk) return 0;
+	sk = tcp_v4_lookup(iph->saddr, th->source, iph->daddr, th->dest);
+	if (!sk)
+		return 0;
 	/* 0 means accept all LOCAL addresses here, not all the world... */
-	if (sk->rcv_saddr == 0) return 0;
+	if (sk->rcv_saddr == 0)
+		return 0;
 	return 1;
 }
 #endif
@@ -1771,6 +2223,11 @@
 	 */
 	th = skb->h.th;
 	sk = skb->sk;
+#ifdef CONFIG_RST_COOKIES
+	if (th->rst && secure_tcp_probe_number(saddr,daddr,ntohs(th->source),ntohs(th->dest),ntohl(th->seq),1)) {
+		add_clearance(saddr);
+	}
+#endif
 	if (!redo) {
 		tcp_statistics.TcpInSegs++;
 		if (skb->pkt_type!=PACKET_HOST)
@@ -1795,7 +2252,10 @@
 			default:
 				/* CHECKSUM_UNNECESSARY */
 		}
-		sk = get_tcp_sock(saddr, th->source, daddr, th->dest, dev->pa_addr, skb->redirport);
+#ifdef CONFIG_SYN_COOKIES
+retry_search:
+#endif
+		sk = __tcp_v4_lookup(th, saddr, th->source, daddr, th->dest);
 		if (!sk)
 			goto no_tcp_socket;
 		skb->sk = sk;
@@ -1828,8 +2288,9 @@
 	 *	exist so should cause resets as if the port was unreachable.
 	 */
 
-	if (sk->zapped || sk->state==TCP_CLOSE)
+	if (sk->zapped || sk->state==TCP_CLOSE) {
 		goto no_tcp_socket;
+	}
 
 	if (!sk->prot) 
 	{
@@ -1870,8 +2331,42 @@
 	 
 		if(sk->state==TCP_LISTEN)
 		{
-			if(th->ack)	/* These use the socket TOS.. might want to be the received TOS */
+			if (th->ack) {	/* These use the socket TOS.. might want to be the received TOS */
+#ifdef CONFIG_SYN_COOKIES
+				if (!th->syn && !th->rst) {
+					__u32 acked_seq = ntohl(th->ack_seq)-1;
+					int mtu_index = (acked_seq&0x7); /* extract MTU */
+					__u32 count = jiffies/(60*HZ);
+
+					acked_seq = acked_seq&0xfffffff8;
+
+					/* Any time in the last 2 minutes is OK */
+					if (acked_seq == secure_tcp_syn_cookie(daddr,
+					    saddr,ntohs(th->source),ntohs(th->dest),
+					    ntohl(th->seq)-1,count)
+					|| acked_seq == secure_tcp_syn_cookie(daddr,
+					    saddr,ntohs(th->source),ntohs(th->dest),
+					    ntohl(th->seq)-1,count-1)
+					|| acked_seq == secure_tcp_syn_cookie(daddr,
+					    saddr,ntohs(th->source),ntohs(th->dest),
+					    ntohl(th->seq)-1,count-2)) {
+						/* If this passes, we need to fake up the
+						* new socket in TCP_SYN_SENT state and
+						* call ourselves recursively to handle
+						* the move to ESTABLISHED using the
+						* current packet. Nasty, but a cleaner
+						* solution would require major rewrites.
+						*/
+						if (tcp_conn_request_fake(sk, skb, daddr, saddr, opt,
+						     			  dev, (acked_seq | mtu_index), cookie_mtu[mtu_index])) {
+
+							goto retry_search;
+						}
+					}
+				}
+#endif
 				tcp_send_reset(daddr,saddr,th,sk->prot,opt,dev,0, 255);
+			}
 
 			/*
 			 *	We don't care for RST, and non SYN are absorbed (old segments)
@@ -1987,7 +2482,12 @@
 				tcp_send_ack(sk);
 				tcp_set_state(sk, TCP_ESTABLISHED);
 				tcp_options(sk,th);
+
+#if 0
 				sk->dummy_th.dest=th->source;
+				tcp_v4_rehash(sk);
+#endif
+
 				sk->copied_seq = sk->acked_seq;
 				if(!sk->dead)
 				{
@@ -2063,12 +2563,22 @@
 			sk->err=ECONNRESET;
 			tcp_set_state(sk, TCP_CLOSE);
 			sk->shutdown = SHUTDOWN_MASK;
-			sk=get_sock(&tcp_prot, th->dest, saddr, th->source, daddr, dev->pa_addr, skb->redirport);
+#ifdef CONFIG_IP_TRANSPARENT_PROXY
+			sk = tcp_v4_proxy_lookup(th->dest, saddr, th->source, daddr,
+						 dev->pa_addr, skb->redirport);
+#else
+			sk = NULL;
+#endif
 			/* this is not really correct: we should check sk->users */
 			if (sk && sk->state==TCP_LISTEN)
 			{
 				skb->sk = sk;
 				atomic_add(skb->truesize, &sk->rmem_alloc);
+				/* FIXME: Is the sequence number addition
+				 * of 128000 here enough for fast networks?
+				 * Also, does this reduce the security of
+				 * our tcp sequence numbers?
+			 	 */
 				tcp_conn_request(sk, skb, daddr, saddr,opt, dev,seq+128000);
 				return 0;
 			}
@@ -2170,7 +2680,7 @@
 
 no_tcp_socket:
 	/*
-	 *	No such TCB. If th->rst is 0 send a reset (checked in tcp_send_reset)
+	 * No such TCB. If th->rst is 0 send a reset (checked in tcp_send_reset)
 	 */
 	tcp_send_reset(daddr, saddr, th, &tcp_prot, opt,dev,0,255);
 
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/tcp_output.c linux/net/ipv4/tcp_output.c
--- vanilla/v2.0.29/linux/net/ipv4/tcp_output.c	Mon Sep  2 08:18:26 1996
+++ linux/net/ipv4/tcp_output.c	Fri Mar  7 05:00:26 1997
@@ -21,6 +21,8 @@
  *
  * Fixes:	Eric Schenk	: avoid multiple retransmissions in one
  *				: round trip timeout.
+ *		Eric Schenk	: tcp rst and syn cookies to deal
+ *				: with synflooding attacks.
  */
 
 #include <linux/config.h>
@@ -28,7 +30,9 @@
 #include <linux/ip_fw.h>
 #include <linux/firewall.h>
 #include <linux/interrupt.h>
-
+#ifdef CONFIG_RST_COOKIES
+#include <linux/random.h>
+#endif
 
 /*
  * RFC 1122 says:
@@ -383,8 +387,11 @@
 			/*
 			 *	IP manages our queue for some crazy reason
 			 */
-			 
+#ifndef NO_DAVEM_FIX			 
+			sk->prot->queue_xmit(sk, skb->dev, skb, 0);
+#else
 			sk->prot->queue_xmit(sk, skb->dev, skb, skb->free);
+#endif
 
 			clear_delayed_acks(sk);
 
@@ -685,6 +692,73 @@
 	tcp_statistics.TcpOutSegs++;
 }
 
+#ifdef CONFIG_RST_COOKIES
+/*
+ *	This routine will send a bad SYNACK to the remote tcp
+ *	containing a secure sequence number.
+ *	This should evoke a reset with a cookie, so we can verify
+ *	the existence of the remote machine.
+ */
+ 
+void tcp_send_synack_probe(unsigned long saddr, unsigned long daddr, struct tcphdr *th,
+	  struct proto *prot, struct options *opt, struct device *dev, int tos, int ttl)
+{
+	struct sk_buff *buff;
+	struct tcphdr *t1;
+	int tmp;
+	struct device *ndev=NULL;
+
+	/*
+	 * We need to grab some memory, and put together a SYNACK,
+	 * and then put it into the queue to be sent.
+	 */
+
+	buff = alloc_skb(MAX_SYN_SIZE, GFP_ATOMIC);
+	if (buff == NULL) 
+	  	return;
+
+	buff->sk = NULL;
+	buff->dev = dev;
+	buff->localroute = 0;
+	buff->csum = 0;
+
+	/*
+	 *	Put in the IP header and routing stuff. 
+	 */
+
+	tmp = prot->build_header(buff, saddr, daddr, &ndev, IPPROTO_TCP, opt,
+			   sizeof(struct tcphdr),tos,ttl,NULL);
+	if (tmp < 0) 
+	{
+  		buff->free = 1;
+		sock_wfree(NULL, buff);
+		return;
+	}
+
+	t1 = (struct tcphdr *)skb_put(buff,sizeof(struct tcphdr));
+
+	memcpy(t1, th, sizeof(*t1));
+	/*
+	 *	Swap the send and the receive. 
+	 */
+	t1->dest = th->source;
+	t1->source = th->dest;
+	t1->ack_seq = t1->seq = htonl(secure_tcp_probe_number(daddr,saddr,
+		ntohs(th->source),ntohs(th->dest),ntohl(th->seq),0));
+	t1->window = htons(1024);	/* make up a window here. */
+	t1->syn = 1;
+	t1->ack = 1;
+	t1->urg = 0;
+	t1->rst = 0;
+	t1->psh = 0;
+	t1->doff = sizeof(*t1)/4;
+
+	tcp_send_check(t1, saddr, daddr, sizeof(*t1), buff);
+	prot->queue_xmit(NULL, ndev, buff, 1);
+	tcp_statistics.TcpOutSegs++;
+}
+#endif
+
 /*
  *	Send a fin.
  */
@@ -782,7 +856,7 @@
 }
 
 
-void tcp_send_synack(struct sock * newsk, struct sock * sk, struct sk_buff * skb)
+void tcp_send_synack(struct sock * newsk, struct sock * sk, struct sk_buff * skb, int destroy)
 {
 	struct tcphdr *t1;
 	unsigned char *ptr;
@@ -853,19 +927,31 @@
 	ptr[3] =(newsk->mtu) & 0xff;
 	buff->csum = csum_partial(ptr, 4, 0);
 	tcp_send_check(t1, newsk->saddr, newsk->daddr, sizeof(*t1)+4, buff);
-	newsk->prot->queue_xmit(newsk, ndev, buff, 0);
-	tcp_reset_xmit_timer(newsk, TIME_WRITE , TCP_TIMEOUT_INIT);
-	skb->sk = newsk;
+	newsk->prot->queue_xmit(newsk, ndev, buff, destroy);
 
-	/*
-	 *	Charge the sock_buff to newsk. 
-	 */
-	 
-	atomic_sub(skb->truesize, &sk->rmem_alloc);
-	atomic_add(skb->truesize, &newsk->rmem_alloc);
+
+#ifdef CONFIG_SYN_COOKIES
+	if (destroy) {
+		/*
+		 * Get rid of the newsk structure if this was a cookie.
+		 */
+		destroy_sock(newsk);
+	} else {
+#endif
+		tcp_reset_xmit_timer(newsk, TIME_WRITE , TCP_TIMEOUT_INIT);
+		skb->sk = newsk;
+
+		/*
+	 	 *	Charge the sock_buff to newsk. 
+	 	 */
+		atomic_sub(skb->truesize, &sk->rmem_alloc);
+		atomic_add(skb->truesize, &newsk->rmem_alloc);
 	
-	skb_queue_tail(&sk->receive_queue,skb);
-	sk->ack_backlog++;
+		skb_queue_tail(&sk->receive_queue,skb);
+		sk->ack_backlog++;
+#ifdef CONFIG_SYN_COOKIES
+	}
+#endif
 	tcp_statistics.TcpOutSegs++;
 }
 
@@ -1048,17 +1134,21 @@
 #endif
 	
 		/*
-		 *	How many bytes can we send ?
+		 *	Recover the buffer pointers
 		 */
 		 
-		win_size = sk->window_seq - sk->sent_seq;
+	    	iph = (struct iphdr *)skb->ip_hdr;
+	    	th = (struct tcphdr *)(((char *)iph) +(iph->ihl << 2));
 
 		/*
-		 *	Recover the buffer pointers
+		 *	How many bytes can we send ?
 		 */
 		 
-	    	iph = (struct iphdr *)skb->ip_hdr;
-	    	th = (struct tcphdr *)(((char *)iph) +(iph->ihl << 2));
+		/* During window probes, don't try to send more than is
+		 * actually in the skb we've taken off the send queue here.
+		 */
+		win_size = skb->len - (((unsigned char *) th) - skb->data);
+		win_size -= th->doff * 4;
 
 		/*
 		 *	Grab the data for a temporary frame
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/tcp_timer.c linux/net/ipv4/tcp_timer.c
--- vanilla/v2.0.29/linux/net/ipv4/tcp_timer.c	Sun Jun  2 06:23:13 1996
+++ linux/net/ipv4/tcp_timer.c	Tue Mar  4 12:30:51 1997
@@ -167,9 +167,15 @@
 	
 	/*
 	 *	Have we tried to SYN too many times (repent repent 8))
+	 *	NOTE: we must be careful to do this test for both
+	 *	the SYN_SENT and SYN_RECV states, otherwise we take
+	 *	23 minutes to timeout on the SYN_RECV state, which
+	 *	leaves us (more) open to denial of service attacks
+	 *	than we would like.
 	 */
 	 
-	if(sk->retransmits > TCP_SYN_RETRIES && sk->state==TCP_SYN_SENT)
+	if (sk->retransmits > TCP_SYN_RETRIES
+	&& (sk->state==TCP_SYN_SENT || sk->state==TCP_SYN_RECV))
 	{
 		if(sk->err_soft)
 			sk->err=sk->err_soft;
diff -u --recursive --new-file vanilla/v2.0.29/linux/net/ipv4/udp.c linux/net/ipv4/udp.c
--- vanilla/v2.0.29/linux/net/ipv4/udp.c	Thu Nov 14 08:20:11 1996
+++ linux/net/ipv4/udp.c	Mon Mar  3 05:05:14 1997
@@ -49,6 +49,9 @@
  *		Mike Shaver	:	RFC1122 checks.
  *		Alan Cox	:	Nonblocking error fix.
  *	Willy Konynenberg	:	Transparent proxying support.
+ *		David S. Miller	:	New socket lookup architecture for ISS.
+ *					Last socket cache retained as it
+ *					does have a high hit rate.
  *
  *
  *		This program is free software; you can redistribute it and/or
@@ -115,25 +118,292 @@
 
 struct udp_mib		udp_statistics;
 
-/*
- *	Cached last hit socket
+struct sock *udp_hash[UDP_HTABLE_SIZE];
+
+static int udp_v4_verify_bind(struct sock *sk, unsigned short snum)
+{
+	struct sock *sk2;
+	int retval = 0;
+
+	SOCKHASH_LOCK();
+	for(sk2 = udp_hash[snum & (UDP_HTABLE_SIZE - 1)]; sk2 != NULL; sk2 = sk2->next) {
+		if((sk2->num == snum) && (sk2 != sk)) {
+			if(!sk2->rcv_saddr || !sk->rcv_saddr) {
+				if(sk->reuse && sk->reuse && (sk2->state != TCP_LISTEN))
+					continue;
+				retval = 1;
+				break;
+			}
+			if((sk2->rcv_saddr == sk->rcv_saddr) &&
+			   (!sk->reuse || !sk2->reuse || (sk2->state == TCP_LISTEN))) {
+				retval = 1;
+				break;
+			}
+		}
+	}
+	SOCKHASH_UNLOCK();
+	return retval;
+}
+
+static inline int udp_lport_inuse(int num)
+{
+	struct sock *sk = udp_hash[num & (UDP_HTABLE_SIZE - 1)];
+
+	for(; sk != NULL; sk = sk->next) {
+		if(sk->num == num)
+			return 1;
+	}
+	return 0;
+}
+
+/* Shared by v4/v6 tcp. */
+unsigned short udp_good_socknum(void)
+{
+	static int start = 0;
+	unsigned short base;
+	int i, best = 0, size = 32767; /* a big num. */
+	int result;
+
+	base = PROT_SOCK + (start & 1023) + 1;
+
+	SOCKHASH_LOCK();
+	for(i = 0; i < UDP_HTABLE_SIZE; i++) {
+		struct sock *sk = udp_hash[i];
+		if(!sk) {
+			start = (i + 1 + start) & 1023;
+			result = i + base + 1;
+			goto out;
+		} else {
+			int j = 0;
+			do {
+				if(++j >= size)
+					goto next;
+			} while((sk = sk->next));
+			best = i;
+			size = j;
+		}
+	next:
+	}
+
+	while(udp_lport_inuse(base + best + 1))
+		best += UDP_HTABLE_SIZE;
+	result = (best + base + 1);
+out:
+	SOCKHASH_UNLOCK();
+	return result;
+}
+
+/* Last hit UDP socket cache, this is ipv4 specific so make it static. */
+static u32 uh_cache_saddr, uh_cache_daddr;
+static u16 uh_cache_dport, uh_cache_sport;
+static struct sock *uh_cache_sk = NULL;
+
+static void udp_v4_hash(struct sock *sk)
+{
+	struct sock **skp;
+	int num = sk->num;
+
+	num &= (UDP_HTABLE_SIZE - 1);
+	skp = &udp_hash[num];
+
+	SOCKHASH_LOCK();
+	sk->next = *skp;
+	*skp = sk;
+	sk->hashent = num;
+	SOCKHASH_UNLOCK();
+}
+
+static void udp_v4_unhash(struct sock *sk)
+{
+	struct sock **skp;
+	int num = sk->num;
+
+	num &= (UDP_HTABLE_SIZE - 1);
+	skp = &udp_hash[num];
+
+	SOCKHASH_LOCK();
+	while(*skp != NULL) {
+		if(*skp == sk) {
+			*skp = sk->next;
+			break;
+		}
+		skp = &((*skp)->next);
+	}
+	if(uh_cache_sk == sk)
+		uh_cache_sk = NULL;
+	SOCKHASH_UNLOCK();
+}
+
+static void udp_v4_rehash(struct sock *sk)
+{
+	struct sock **skp;
+	int num = sk->num;
+	int oldnum = sk->hashent;
+
+	num &= (UDP_HTABLE_SIZE - 1);
+	skp = &udp_hash[oldnum];
+
+	SOCKHASH_LOCK();
+	while(*skp != NULL) {
+		if(*skp == sk) {
+			*skp = sk->next;
+			break;
+		}
+		skp = &((*skp)->next);
+	}
+	sk->next = udp_hash[num];
+	udp_hash[num] = sk;
+	sk->hashent = num;
+	if(uh_cache_sk == sk)
+		uh_cache_sk = NULL;
+	SOCKHASH_UNLOCK();
+}
+
+/* UDP is nearly always wildcards out the wazoo, it makes no sense to try
+ * harder than this here plus the last hit cache. -DaveM
  */
- 
-volatile unsigned long 	uh_cache_saddr,uh_cache_daddr;
-volatile unsigned short  uh_cache_dport, uh_cache_sport;
-volatile struct sock *uh_cache_sk;
-
-void udp_cache_zap(void)
-{
-	unsigned long flags;
-	save_flags(flags);
-	cli();
-	uh_cache_saddr=0;
-	uh_cache_daddr=0;
-	uh_cache_dport=0;
-	uh_cache_sport=0;
-	uh_cache_sk=NULL;
-	restore_flags(flags);
+struct sock *udp_v4_lookup_longway(u32 saddr, u16 sport, u32 daddr, u16 dport)
+{
+	struct sock *sk, *result = NULL;
+	unsigned short hnum = ntohs(dport);
+	int badness = -1;
+
+	for(sk = udp_hash[hnum & (UDP_HTABLE_SIZE - 1)]; sk != NULL; sk = sk->next) {
+		if((sk->num == hnum) && !(sk->dead && (sk->state == TCP_CLOSE))) {
+			int score = 0;
+			if(sk->rcv_saddr) {
+				if(sk->rcv_saddr != daddr)
+					continue;
+				score++;
+			}
+			if(sk->daddr) {
+				if(sk->daddr != saddr)
+					continue;
+				score++;
+			}
+			if(sk->dummy_th.dest) {
+				if(sk->dummy_th.dest != sport)
+					continue;
+				score++;
+			}
+			if(score == 3) {
+				result = sk;
+				break;
+			} else if(score > badness) {
+				result = sk;
+				badness = score;
+			}
+		}
+	}
+	return result;
+}
+
+__inline__ struct sock *udp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport)
+{
+	struct sock *sk;
+
+	if(uh_cache_sk			&&
+	   uh_cache_saddr == saddr	&&
+	   uh_cache_sport == sport	&&
+	   uh_cache_dport == dport	&&
+	   uh_cache_daddr == daddr)
+		return uh_cache_sk;
+
+	sk = udp_v4_lookup_longway(saddr, sport, daddr, dport);
+	uh_cache_sk	= sk;
+	uh_cache_saddr	= saddr;
+	uh_cache_daddr	= daddr;
+	uh_cache_sport	= sport;
+	uh_cache_dport	= dport;
+	return sk;
+}
+
+#ifdef CONFIG_IP_TRANSPARENT_PROXY
+#define secondlist(hpnum, sk, fpass) \
+({ struct sock *s1; if(!(sk) && (fpass)--) \
+	s1 = udp_hash[(hpnum) & (TCP_HTABLE_SIZE - 1)]; \
+   else \
+	s1 = (sk); \
+   s1; \
+})
+
+#define udp_v4_proxy_loop_init(hnum, hpnum, sk, fpass) \
+	secondlist((hpnum), udp_hash[(hnum)&(TCP_HTABLE_SIZE-1)],(fpass))
+
+#define udp_v4_proxy_loop_next(hnum, hpnum, sk, fpass) \
+	secondlist((hpnum),(sk)->next,(fpass))
+
+struct sock *udp_v4_proxy_lookup(unsigned short num, unsigned long raddr,
+				 unsigned short rnum, unsigned long laddr,
+				 unsigned long paddr, unsigned short pnum)
+{
+	struct sock *s, *result = NULL;
+	int badness = -1;
+	unsigned short hnum = ntohs(num);
+	unsigned short hpnum = ntohs(pnum);
+	int firstpass = 1;
+
+	SOCKHASH_LOCK();
+	for(s = udp_v4_proxy_loop_init(hnum, hpnum, s, firstpass);
+	    s != NULL;
+	    s = udp_v4_proxy_loop_next(hnum, hpnum, s, firstpass)) {
+		if(s->num == hnum || s->num == hpnum) {
+			int score = 0;
+			if(s->dead && (s->state == TCP_CLOSE))
+				continue;
+			if(s->rcv_saddr) {
+				if((s->num != hpnum || s->rcv_saddr != paddr) &&
+				   (s->num != hnum || s->rcv_saddr != laddr))
+					continue;
+				score++;
+			}
+			if(s->daddr) {
+				if(s->daddr != raddr)
+					continue;
+				score++;
+			}
+			if(s->dummy_th.dest) {
+				if(s->dummy_th.dest != rnum)
+					continue;
+				score++;
+			}
+			if(score == 3 && s->num == hnum) {
+				result = s;
+				break;
+			} else if(score > badness && (s->num == hpnum || s->rcv_saddr)) {
+					result = s;
+					badness = score;
+			}
+		}
+	}
+	SOCKHASH_UNLOCK();
+	return result;
+}
+
+#undef secondlist
+#undef udp_v4_proxy_loop_init
+#undef udp_v4_proxy_loop_next
+
+#endif
+
+static inline struct sock *udp_v4_mcast_next(struct sock *sk,
+					     unsigned short num,
+					     unsigned long raddr,
+					     unsigned short rnum,
+					     unsigned long laddr)
+{
+	struct sock *s = sk;
+	unsigned short hnum = ntohs(num);
+	for(; s; s = s->next) {
+		if ((s->num != hnum)					||
+		    (s->dead && (s->state == TCP_CLOSE))		||
+		    (s->daddr && s->daddr!=raddr)			||
+		    (s->dummy_th.dest != rnum && s->dummy_th.dest != 0) ||
+		    (s->rcv_saddr  && s->rcv_saddr != laddr))
+			continue;
+		break;
+  	}
+  	return s;
 }
 
 #define min(a,b)	((a)<(b)?(a):(b))
@@ -165,8 +435,7 @@
 	
 	uh = (struct udphdr *)header;  
    
-	sk = get_sock(&udp_prot, uh->source, daddr, uh->dest, saddr, 0, 0);
-
+	sk = udp_v4_lookup(saddr, uh->source, daddr, uh->dest);
 	if (sk == NULL) 
 	  	return;	/* No socket for error */
   	
@@ -618,7 +887,8 @@
 	sk->daddr = usin->sin_addr.s_addr;
 	sk->dummy_th.dest = usin->sin_port;
 	sk->state = TCP_ESTABLISHED;
-	udp_cache_zap();
+	if(uh_cache_sk == sk)
+		uh_cache_sk = NULL;
 	sk->ip_route_cache = rt;
 	return(0);
 }
@@ -628,8 +898,8 @@
 {
 	lock_sock(sk);
 	sk->state = TCP_CLOSE;
-	if(uh_cache_sk==sk)
-		udp_cache_zap();
+	if(uh_cache_sk == sk)
+		uh_cache_sk = NULL;
 	release_sock(sk);
 	sk->dead = 1;
 	destroy_sock(sk);
@@ -679,15 +949,53 @@
 	struct udphdr *uh = (struct udphdr *)(skb->h.raw + iph->ihl*4);
 	struct sock *sk;
 
-	sk = get_sock(&udp_prot, uh->dest, iph->saddr, uh->source, iph->daddr, 0, 0);
-
-	if (!sk) return 0;
+	sk = udp_v4_lookup(iph->saddr, uh->source, iph->daddr, uh->dest);
+	if (!sk)
+		return 0;
 	/* 0 means accept all LOCAL addresses here, not all the world... */
-	if (sk->rcv_saddr == 0) return 0;
+	if (sk->rcv_saddr == 0)
+		return 0;
 	return 1;
 }
 #endif
 
+#ifdef CONFIG_IP_MULTICAST
+/*
+ *	Multicasts and broadcasts go to each listener.
+ */
+static int udp_v4_mcast_deliver(struct sk_buff *skb, struct udphdr *uh,
+				 u32 saddr, u32 daddr)
+{
+	struct sock *sk;
+	int given = 0;
+
+	SOCKHASH_LOCK();
+	sk = udp_hash[ntohs(uh->dest) & (UDP_HTABLE_SIZE - 1)];
+	sk = udp_v4_mcast_next(sk, uh->dest, saddr, uh->source, daddr);
+	if(sk) {
+		struct sock *sknext = NULL;
+
+		do {
+			struct sk_buff *skb1 = skb;
+
+			sknext = udp_v4_mcast_next(sk->next, uh->dest, saddr,
+						   uh->source, daddr);
+			if(sknext)
+				skb1 = skb_clone(skb, GFP_ATOMIC);
+
+			if(skb1)
+				udp_deliver(sk, skb1);
+			sk = sknext;
+		} while(sknext);
+		given = 1;
+	}
+	SOCKHASH_UNLOCK();
+	if(!given)
+		kfree_skb(skb, FREE_READ);
+	return 0;
+}
+#endif
+
 /*
  *	All we need to do is get the socket, and then do a checksum. 
  */
@@ -784,46 +1092,15 @@
 
 #ifdef CONFIG_IP_MULTICAST
 	if (addr_type==IS_BROADCAST || addr_type==IS_MULTICAST)
-	{
-		/*
-		 *	Multicasts and broadcasts go to each listener.
-		 */
-		struct sock *sknext=NULL;
-		sk=get_sock_mcast(udp_prot.sock_array[ntohs(uh->dest)&(SOCK_ARRAY_SIZE-1)], uh->dest,
-				saddr, uh->source, daddr);
-		if(sk)
-		{		
-			do
-			{
-				struct sk_buff *skb1;
-
-				sknext=get_sock_mcast(sk->next, uh->dest, saddr, uh->source, daddr);
-				if(sknext)
-					skb1=skb_clone(skb,GFP_ATOMIC);
-				else
-					skb1=skb;
-				if(skb1)
-					udp_deliver(sk, skb1);
-				sk=sknext;
-			}
-			while(sknext!=NULL);
-		}
-		else
-			kfree_skb(skb, FREE_READ);
-		return 0;
-	}	
+		return udp_v4_mcast_deliver(skb, uh, saddr, daddr);
 #endif
-	if(saddr==uh_cache_saddr && daddr==uh_cache_daddr && uh->dest==uh_cache_dport && uh->source==uh_cache_sport)
-		sk=(struct sock *)uh_cache_sk;
+#ifdef CONFIG_IP_TRANSPARENT_PROXY
+	if(skb->redirport)
+		sk = udp_v4_proxy_lookup(uh->dest, saddr, uh->source,
+					 daddr, dev->pa_addr, skb->redirport);
 	else
-	{
-	  	sk = get_sock(&udp_prot, uh->dest, saddr, uh->source, daddr, dev->pa_addr, skb->redirport);
-  		uh_cache_saddr=saddr;
-  		uh_cache_daddr=daddr;
-  		uh_cache_dport=uh->dest;
-  		uh_cache_sport=uh->source;
-  		uh_cache_sk=sk;
-	}
+#endif
+	sk = udp_v4_lookup(saddr, uh->source, daddr, uh->dest);
 	
 	if (sk == NULL) 
   	{
@@ -845,27 +1122,34 @@
 }
 
 struct proto udp_prot = {
-	udp_close,
-	ip_build_header,
-	udp_connect,
-	NULL,
-	ip_queue_xmit,
-	NULL,
-	NULL,
-	NULL,
-	udp_rcv,
-	datagram_select,
-	udp_ioctl,
-	NULL,
-	NULL,
-	ip_setsockopt,
-	ip_getsockopt,
-	udp_sendmsg,
-	udp_recvmsg,
-	NULL,		/* No special bind function */
-	128,
-	0,
-	"UDP",
-	0, 0,
-	{NULL,}
+	(struct sock *)&udp_prot,	/* sklist_next */
+	(struct sock *)&udp_prot,	/* sklist_prev */
+	udp_close,			/* close */
+	ip_build_header,		/* build_header */
+	udp_connect,			/* connect */
+	NULL,				/* accept */
+	ip_queue_xmit,			/* queue_xmit */
+	NULL,				/* retransmit */
+	NULL,				/* write_wakeup */
+	NULL,				/* read_wakeup */
+	udp_rcv,			/* rcv */
+	datagram_select,		/* select */
+	udp_ioctl,			/* ioctl */
+	NULL,				/* init */
+	NULL,				/* shutdown */
+	ip_setsockopt,			/* setsockopt */
+	ip_getsockopt,			/* getsockopt */
+	udp_sendmsg,			/* sendmsg */
+	udp_recvmsg,			/* recvmsg */
+	NULL,				/* bind */
+	udp_v4_hash,			/* hash */
+	udp_v4_unhash,			/* unhash */
+	udp_v4_rehash,			/* rehash */
+	udp_good_socknum,		/* good_socknum */
+	udp_v4_verify_bind,		/* verify_bind */
+	128,				/* max_header */
+	0,				/* retransmits */
+	"UDP",				/* name */
+	0,				/* inuse */
+	0				/* highestinuse */
 };

----=_339fa94d27155633002c52519.MFSBCHJLHS
Content-Type: application/octet-stream; name=aic7xxx-2.1.26-May8.tgz
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=aic7xxx-2.1.26-May8.tgz

<encoded_portion_removed>
zc/Nz83Pzc/Nz83Pzc/Nz83PX/jzfwGVjgwDAMgFAA==

----=_339fa94d27155633002c52519.MFSBCHJLHS--

Technical Details
Message-ID: <33a0a94e.271556862@news.winterlan.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
References: <339F27DA.3E95798C@shreve.net>

Show Full Headers
Complete Article Headers
Message-ID: <33a0a94e.271556862@news.winterlan.com>
Subject: Re: Increasing 1.5.1 Performance (1/1)
Date: Thu, 12 Jun 1997 00:00:00 +0000
From: paulp@winterlan.com (z)
References: <339F27DA.3E95798C@shreve.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 247854927
Newsgroups: news.software.nntp