Selective SNAT rule

Hi all,

I am new to iRules and just implemented my first one today to resolve a problem we’ve been seeing with NAT. However, I need to create another one and I need to know the correct syntax to use. The setup is as such:

If I have a pool as such:

pool MB_pool {

lb method member ratio

snat disable

member 172.19.10.11:smtp monitor smtp_10.11

member 172.19.10.12:smtp monitor smtp_10.12

member 172.19.10.13:smtp monitor smtp_10.13

member 192.0.2.25:smtp session disable

}

How can I construct a rule that will prevent SNAT from occuring on the 172.19.x.x addresses, but will allow it on the 192.0.2.25 address? The 172.19.x.x addresses are physically located behind the BigIP, but the 192.0.2.25 address is on a remote network (a dummy VIP on a remote F5).

TIA,

eric

Try: (untested!)

when LB_SELECTED {
   if {[IP::addr [IP::remote_addr] equals "172.19.10.0/24"]} {
       snat disable
   }
}

You’ll need to enable snat on the pool definition, though, to allow the snat to occur to 192.0.2.25, unless you want to add that into the rule as well

I tried your suggestion, but that didn’t work. I had to modify the ‘snat disable’ to be ‘snat none’, but that didn’t work, either. Here is what I have now (using example IPs):

SiteA VIP: 192.0.2.10

SiteA Dummy VIP: 192.0.2.11

SiteB VIP: 192.0.2.24

SiteB Dummy VIP: 192.0.2.25

…

pool MB_pool {
   lb method member ratio
   member 172.19.10.11:smtp monitor smtp_10.11
   member 172.19.10.12:smtp monitor smtp_10.12
   member 172.19.10.13:smtp monitor smtp_10.13
   member 192.0.2.25:smtp monitor smtp_2.25
}
snat MB {
   translation 192.0.2.10
   origin 172.19.10.11
   origin 172.19.10.12
   origin 172.19.10.13
   vlan internal enable
}
...
when LB_SELECTED {
   if { not [IP::addr [IP::remote_addr] equals "192.0.2.25/32"]} {
     snat none
   }
   else {
     use snat 192.0.2.10
   }
}

I could not get the ‘snat none’ to work until negating the ‘if’ statement and changing the remote_addr. The ‘snat none’ now properly disables SNAT for anything incoming, but does not use the 192.0.2.10 SNAT address for packets chosen to go to the remote dummy VIP.

Try using this:

when LB_SELECTED {
   if {[IP::addr [IP::remote_addr] equals "172.19.10.0/24"]} {
       LB:reselect snat none
   }
}

Thanks for the suggestion, but that doesn’t work, either. I get an “undefined procedure” error when I try to save the rule. I think it’s getting hung up on the “LB:reselect”. I tried putting a double-colon in there, but then I get a different error, “line 3: [command is not valid in current event context (LB_SELECTED)] [LB::reselect snat none”.

In this situation, because the LB_SELECTED event is in the server “context”, and they want to check the client IP address, do they need to specify: clientside {IP::remote_addr}?

Thanks,

Brian

Eric: I apologize. This was only just changed in 9.2. You can work around it by disabling Rule validation with the following command:

[root@gumby:Active] config  bigpipe db Rule.Validation none

You do need to use LB::reselect because when the LB_SELECTED event is triggered, both the server and snat have already been picked. Using just the snat command will not change the snat behavior at that point.

Note: In 9.2, the LB_SELECTED event will be fired again after the LB::reselect (this is because a new LB decision is being made). You should add some logic to not reselect the snat if it has already happened once otherwise you’ll create an indefinite loop (using a variable is usually easiest).

Brian: He actually wants to disable snat based on the server that was picked, not the clientside source address.

Yeah.

Just for clarification these are levels available:

strict - Check context, dependencies, syntax, etc. (the default).

check - Check the dependencies and syntax.

syntax - Tcl Syntax checking only.

none - No checking.

Thanks, I disabled rule validation and it lets me save the rule now. However, the rule still doesn’t work. I currently have SNAT enabled at the pool level and the rule is entered as:

when LB_SELECTED {
   if {[IP::addr [IP::remote_addr] equals "172.19.10.0/24"]} {
       LB::reselect snat none
   }
}

but this does not appear to disable SNAT for incoming connections for 172.19.10.0/24. tcpdump on a 172.19.10/24 server shows connections coming from the LB (172.19.10.1) as opposed to the original IP.

You should add some logic to not reselect the snat if it has already happened once otherwise you’ll create an indefinite loop (using a variable is usually easiest).

At the risk of sounding like a bonehead, how do I do this? Can you point me to some examples of this and maybe I can figure it out on my own?

Ok, you should try the negative logic (ie - don’t select a snat until the LB_SELECTED event and then to a reselect). There could be a bug in the reselect logic for disabling the snat.

You don’t need to worry about the loop until you move to 9.2. You would basically add something like this:

when LB_SELECTED {
   if { not [info exists already_reselected] } {
       put the logic for the first time here.  eg - code from above
      set already_reselected 1
   }
}

Well, I tried many different permutations of the rule, using the negative logic and enabling/disabling SNAT and nothing works. I either A) can’t get the snat to work to the remote dummy VIP, B) end up enabling snat for all nodes, or C) end up disabling snat for all nodes.

Looks like I have no choice but to go the more complicated route by using multiple pools with a combination of snat enabled/snat disabled.

Okay, here’s what I’ve got:

virtual test_snat {
   destination 192.0.2.10:smtp
   ip protocol tcp
   profile fastL4
   pool test_snat
   rule disable_snat
}
pool test_snat {
   monitor all tcp
   member 172.19.10.11:smtp
   member 192.0.2.25:smtp
}

1. snat is enabled on the VIP and on the pool.

2. I’m using no persistence.

3. What’s the difference between a backend server and a backend node?

4. I’ll try this.

5. The reselect is necessary if it is required to disable snat for only certain nodes in a pool.

Just to reiterate, I have a remote ‘dummy’ VIP set up on a remote BIGIP which is load balanced among three servers that are local to that remote BIGIP. I only need snat to occur on the 192.0.2.25 node, as it’s in a remote location, on a different IP subnet.

Two things I notice…

1) I would suggest defining the default SNAT for the VIP. (We’ll disable snat in the rule - The overhead is minimal).

Add one of the following to your virtual definition:

- snatpool snat_pool (Let me know if you want to be implicit)

- snat automap (I use this all the time, works like a charm. You need to make sure you have configured an automap IP. Let me know if you need help with this.)

2) I’ve had difficulty using the fastL4 profile with iRules… Are you sure this is supported? I would suggest getting rid of this profile.

As for your questions:

3) No difference

5) Why is the reselect neccesary? I am confused…

Thanks,

Brian

Oh yeah one more question… What do you mean by “dummy” VIP?

OK, I suppose I wasn’t clear in my previous posts…sorry!

I have two sites:

SiteA Network: 192.0.2.0/28

SiteA VIP: 192.0.2.10

SiteA “Dummy” VIP: 192.0.2.11

SiteA Internal Nodes: 172.16.10.0/24

SiteB Network: 192.0.2.16/28

SiteB VIP: 192.0.2.24

SiteB “Dummy” VIP: 192.0.2.25

SiteB Internal Nodes: 172.19.10.0/24

We’re load balancing SMTP between 6 physical servers at two geographically dispersed locations (3 at each site). Primary MX is 192.0.2.10 and secondary MX is 192.0.2.24. Because little traffic should actually go to the backup during normal operation, we want to use these servers in the primary MX pool so we don’t have these boxes sitting around twiddling their thumbs, so to speak. These are obviously just example IPs and networks, BTW…

SiteA has two VIPs configured, as does SiteB. SiteA is the primary MX and SiteB is the backup MX. SiteA is load-balanced to a pool configured with three local servers (172.16.10.11, .12, and .13) and one remote server (192.0.2.25). The second VIP, what I call a “dummy” VIP, is configured with only the three local servers. SiteB is configured similarly.

The dummy VIP exists as an loop-prevention mechanism. It exists because if I use the secondary MX as a node in my primary MX VIP, the possibility exists that the backup MX will choose the primary MX node upon receipt of a TCP session. To avoid this, we made a fourth node (the dummy VIP) which consists solely of the three remote servers at each location.

We cannot use SNAT on the sessions which are load-balanced to the servers local to each BIGIP - the sessions appear to come from the BIGIP and the servers start denying connections because there’s too many from a single address. This could be changed in the server configs, but there’s side-effects to that which I won’t go into.

We need to use SNAT for the sessions which are load-balanced to the *remote* nodes, because if we don’t, the original IP is sent in the packet, so the remote dummy VIP attempts to send the ACKs to the original IP - which obviously doesn’t work because no pre-existing TCP session exists with the remote dummy VIP.

I’m sorry for the long explanation - I hope this clears things up at least a little.

5) He needs to do a reselect because at the time LB_SELECTED is evaluated, the LB parameters have been locked down. Just doing “snat none” will have no effect because it’s already been chosen based on the settings before LB_SELECTED was triggered. Doing an LB::reselect indicates that LB needs to be redone with new parameters. One of the things that happens in LB, is that the pool parameters is replaced with a pool member parameter. So, as long as the pool or pool member are not LB::reselected, the existing pool member chosen in the first place will still be used.

At some point, I’ll try to verify that all this is in fact working as advertised. It’s probably the first time someone has tried to tweak the snat based on which pool member was selected.

This has probably been asked before, but is there a flowchart available for the different events and at what point in the traffic flow they occur at? I attempted to search for this, but didn’t find anything, probably because I was using the wrong terminology.

Also - if I log in an iRule, where does that information go? I don’t see it logged anywhere in the /var/log directory or in the logs that the WebUI shows. The documentation states it logs it to the Syslog facility, but which one and which file?

it will go to /var/log/tmm unless otherwise specified.

Posted By citizen_elah on 10/13/2005 10:08 AM

it will go to /var/log/tmm unless otherwise specified.

Hmm…then something isn’t right. With the log settings above, I don’t see anything pop up in the tmm file. I’m not specifying another facility, so I would assume that would just dump into that tmm log.

sorry, I meant /var/log/ltm