Forum Discussion
jpavel
Jan 10, 2012Nimbostratus
iRule based on SMTP receiver domain
Hello iRule experts,
unfortunately I am an irule beginner and therefore I need some help.
One of our customers would like to direct traffic based on the SMTP receiver domain.
Emails for the receiver "user@east.com" for example should be load balanced to server pool "pool_east" and emails for "user@west.com" should be load balanced to server pool "pool_west".
In my opinion irule is a way to accomplish that.
Can anybody give me an idea how this irule has to look like?
Many thanks in advance
Joerg
- nitassEmployeehave you seen this one? even it is based on sender domain, i think it may be helpful.
- jpavelNimbostratusHi nitass,
- Colin_Walker_12Historic F5 AccountUnfortunately, given the way that SMTP works, there isn't a simple way to go about what you're looking for. The recipient is not sent in the first communication, rather it takes multiple responses from the server for the client to actually send the data you're looking to route based on. This means that you have to impersonate the server within the iRule, and replay all necessary requests from the client to the server once you've selected a server. This, as you can imagine, gets complex.
- jpavelNimbostratusHi Colin,
- Colin_Walker_12Historic F5 AccountSure thing! I wish I had a better answer for you, but some protocols are just more difficult to imitate than others. ;)
- nitassEmployeei just cut small part from James and put it in smtp proxy codeshare. hoping it might be easier for you to see how it works.
[root@ve1023:Active] config b virtual bar list virtual bar { snat automap destination 172.28.19.79:25 ip protocol 6 rules myrule } [root@ve1023:Active] config b rule myrule list rule myrule { when CLIENT_ACCEPTED { set chelo "" set cfrom "" set crcpt "" TCP::respond "220\r\n" log local0. "client accepted" TCP::collect } when CLIENT_DATA { set cdata [TCP::payload] if { [ string length $cdata ] <= 0 } { return } if { not ( $cdata contains "\r\n" ) } { log local0. "get $cdata so far" return } 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] "" return } if { $cdata starts_with "MAIL FROM:" } { set cfrom [TCP::payload] log local0. "get from $cfrom" TCP::respond "250 OK\r\n" TCP::payload replace 0 [string length $cfrom] "" return } if { $cdata starts_with "RCPT TO:" } { set crcpt "$crcpt[TCP::payload]" log local0. "get rcpt $crcpt" set rcptaddr [regsub -all \[\\r\\n\\s\] [TCP::payload] ""] set rcptaddr [findstr $rcptaddr ":" 1] set rcptdomain [findstr $rcptaddr "@" 1] log local0. "get rcpt domain $rcptdomain" TCP::respond "250 OK\r\n" TCP::payload replace 0 [string length [TCP::payload]] "" if {$rcptdomain equals "abc.com"} { log local0. "foo1" pool foo1 } else { log local0. "foo2" pool foo2 } return } if { $cdata starts_with "DATA" } { log local0. "get data $cdata" TCP::payload replace 0 0 $chelo$cfrom$crcpt } log local0. "payload [TCP::payload]" TCP::release TCP::collect } when SERVER_CONNECTED { log "server connected" TCP::collect } when SERVER_DATA { set sdata [TCP::payload] if { $sdata starts_with "220" } { log local0. "get data $sdata" TCP::payload replace 0 [string length $sdata] "" return } if { $sdata contains "\r\n354 " } { log local0. "get data $sdata" TCP::payload replace 0 [string length $sdata] "354\r\n" } if { [ string length $sdata ] <= 0 } { return } log local0. "payload [TCP::payload]" TCP::release TCP::collect } when CLIENT_CLOSED { log local0. "client closed" } } [root@ve1023:Active] config b pool foo1 list bpool foo1 { members 200.200.200.101:25 {} } [root@ve1023:Active] config b pool foo2 list pool foo2 { members 200.200.200.102:25 {} } [root@ve1023:Active] config tail -f /var/log/ltm Jan 13 04:07:34 local/tmm info tmm[26866]: Rule myrule CLIENT_ACCEPTED: client accepted Jan 13 04:07:39 local/tmm info tmm[26866]: Rule myrule CLIENT_DATA: get helo HELO me Jan 13 04:08:08 local/tmm info tmm[26866]: Rule myrule CLIENT_DATA: get from MAIL FROM:goldenretriever@f5.com Jan 13 04:08:19 local/tmm info tmm[26866]: Rule myrule CLIENT_DATA: get rcpt RCPT TO:superman@abc.com Jan 13 04:08:19 local/tmm info tmm[26866]: Rule myrule CLIENT_DATA: get rcpt domain abc.com Jan 13 04:08:19 local/tmm info tmm[26866]: Rule myrule CLIENT_DATA: foo1 [root@ve1023:Active] config tail -f /var/log/ltm Jan 13 04:09:27 local/tmm info tmm[26866]: Rule myrule CLIENT_ACCEPTED: client accepted Jan 13 04:09:29 local/tmm info tmm[26866]: Rule myrule CLIENT_DATA: get helo HELO me Jan 13 04:09:37 local/tmm info tmm[26866]: Rule myrule CLIENT_DATA: get from MAIL FROM:goldenretriever@f5.com Jan 13 04:09:48 local/tmm info tmm[26866]: Rule myrule CLIENT_DATA: get rcpt RCPT TO:santa@xyz.com Jan 13 04:09:48 local/tmm info tmm[26866]: Rule myrule CLIENT_DATA: get rcpt domain xyz.com Jan 13 04:09:48 local/tmm info tmm[26866]: Rule myrule CLIENT_DATA: foo2
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects