Forum Discussion

Thomas_Schaefer's avatar
Thomas_Schaefer
Icon for Nimbostratus rankNimbostratus
Apr 23, 2009

Make a Dummy SMTP server in an iRule?

I have a need to create a dummy SMTP server in an iRule. My thought was to use the SMTP proxy iRule and instead of forward the messages on to the SMTP server to discard them.

I am trying to do this because I have a DR system that I would like the apps that send mail to think they did send the mail, but I just want to eat the messages. I need to respond with the correct things to them (like the proxy), but I do not want to send the traffic on. This is essentially a mock object for SMTP.

I thought I could just add a discard statement before the return statement in the

SMTP Proxy like this:

 
 if { $cdata starts_with "HELO" } { 
 set chelo [TCP::payload] 
 log local0. "get helo <$cdata>" 
 TCP::respond "250 OK\r\n" 
 TCP::payload replace 0 [string length $chelo] "" 
 discard 
 return

I am concerned that discard will terminate the connection.

My question is should this work?

Thanks,

Tom Schaefer

@thomasmschaefer
  • Thanks! That worked with just some minor modifications. My client tries to send EHLO and expects that response. All I did was reject the EHLO with a 500 error and it sends back the HELO command. I also had to respond to QUIT with a 221. Here is the updated code:

     

     
     switch -glob [string toupper [TCP::payload]] { 
     DATA* { 
     set respond "354 Start mail input; end with .\r\n" 
     set data 1 
     } 
     EHLO* { 
     set respond "500 Syntax error, command unrecognized\r\n" 
     } 
     QUIT* { 
     set respond "221 Bye\r\n" 
     } 
     default { 
     set respond "250 Ok\r\n" 
     } 
     } 
     

     

     

    Also, Can you tell me what the second TCP::collect is doing in the client_data event. My guess is that is how to make sure we never try to send the data to anything beyond, but it seemed like the whole thing would hang with that.

     

     

    I tested this with no server and I ever removed the pool from my virtual server. Thanks again for the help.

     

     

    Tom Schaefer
  • TCP::collect in CLIENT_DATA is to make sure we keep collecting data so that CLIENT_DATA is called again and never send the data (never TCP::release)

     

     

    regarding hang problem... maybe you can try something like this...

     

     

    QUIT* {

     

    TCP::payload replace 0 [TCP::payload length] ""

     

    TCP::respond "221 Bye\r\n"

     

    TCP::close

     

    return

     

    }

     

     

    (sorry, not tested)