Re: tcpsvd - Allow only x connections from somebody/hour

Laurent Bercot <[email protected]>
Newsgroups gmane.comp.misc.pape.general
Message-ID <[email protected]>
> i think this is an interesting problem.  the djb-style suggests something like
> this:
> 
>   tcpserver <host> <port> limitip <service-program>
> 
> where "limitip" is a program i'm trying to dream up.  it's supposed to:
> 
> *  keep a persistent database of TCP connections
> *  get its parameters from environment variables set in tcprules
> *  won't grow its database beyond a configuration time computable size
> *  be simple

 Although I'm a fan of the "one job, one program" approach, I don't
think it's a good idea to separate 'limitip' from 'tcpserver'. I
believe that the 'limitip' functionality should be included into
'tcpserver', just as tcpsvd does. Why ?

 - No persistent data.
limitip needs a persistent database in the filesystem. The database
must be up-to-date at any time. What happens if the machine reboots ?
Stale data. You don't want that. And you don't want a timestamp thing
to check whether the database entry is up-to-date - too complex.

 - Use less resources.
The point of limitip is to limit resource consumption. If you separate
it from tcpserver, you'll fork & exec for every connection, even the
ones that will just be dropped by limitip. You don't want that.
Moreover:
How do you know a connection has been freed and it's OK to accept a new
one from the same IP ? You know because tcpserver's child has died.
limitip needs to know to update its database... so it has to fork & exec
the real server, and stay alive the whole connection time. That means
2 processes by connection instead of one, and another read/write round-
trip for data going through. Ugh.

 Limiting connections by IP is a useful feature, but it's a job for
the super-server. tcpsvd does it well.

 Now, about Maurice's idea : I don't know what would be simpler.
 - Either patch tcpsvd to add a 'max connection per amount of time'
configuration option.
 - Or write a program executed between tcpsvd and its child, that
would update tcpsvd's configuration directory. That wouldn't be as
simple as it seems : it would probably have to be persistent too,
which is a bad idea. (Not even counting the permissions problem if
tcpsvd setuid()'s before exec'ing.)

-- 
 Ska
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.