Throttling qmail SMTP receive bandwidth

jwatte's picture

I wrote the program "throttle.c," which you can insert into the tcpserver chain of commands for a qmail smtpd server. It takes one argument: the number of kilobytes per second to let through on the incoming file descriptor. Throttle does not throttle the outgoing file descriptor, because that's usually just status from your mail server.

Additionally, throttle will set an alarm, so that any session longer than 15 minutes will expire and disconnect. This affords some amount of protection against lingering sessions that eat up your parallelism limit; I've seen such sessions from presumably trojaned DSL machines connecting to the mail server to send spam.

To use the program, simply compile it:
gcc -o throttle throttle.c
The put the binary ("throttle") where you can get to it:
cp -pf throttle /usr/local/bin/throttle
Finally, on your tcpserver command line, make "throttle XX" one of the stages in the chain. Here's what mine looks like:
nice -5 /usr/local/bin/tcpserver -R -h -p -x
/var/qmail/tcprules/smtp.cdb 0 25
/usr/local/bin/rhost-check /usr/local/bin/throttle 30
/usr/local/bin/rblsmtpd -r
/bin/checkpassword /bin/true 2>&1 |
/var/qmail/bin/splogger qmail &

throttle.zip1.44 KB