Forum Discussion
Get information about Self-IPs in iRule
I have a need for an iRule that enables SNAT if the client and server addresses are in the same subnet. In practice, this only happens if the client and server addresses are on directly connected subnets.
I expect the iRule would look something like this:
when LB_SELECTED {
set client_net [ class match -name [IP::client_addr] equals "self-ip-nets" ]
set server_net [ class match -name [IP::server_addr] equals "self-ip-nets" ]
if { client_net eq server_net } {
snat automap
}
}
But that depends on the existence of a class called "self-ip-nets" that I would have to maintain separately from the actual device configuration, and that's an administrative overhead that's likely to break down.
I can't just assume that all subnets are of a particular size, because they're not.
Is there any way to get information about the locally connected networks on the LTM, specifically including netmask information, inside an iRule?
5 Replies
- Mohamed_Lrhazi
Altocumulus
You probably dont need to know the selfip, it is the same subnet as the server right?
when LB_SELECTED { set ClientIP [clientside {IP::remote_addr}] set VirtualIP [clientside {IP::local_addr}] set NodeIP [LB::server addr] if { [IP::addr $ClientIP/24 equals $NodeIP/24] } { if { $static::debug != 0 } { log local0. "SNAT Client: $ClientIP to VIP: $VirtualIP targeting Node: $NodeIP" } snat $VirtualIP } } - IheartF5_45022
Nacreous
Hi I think this might work for you - I have assumed that you use a mix of 24/25/26 masks - you adjust as appropriate (following code not tested BTW);-
when LB_SELECTED { foreach mask [26 25 24] { if {[IP::addr [clientside {IP::remote_addr}]/$mask equals [IP::remote_addr]/$mask]}{ snat automap break } } }- wfaulk_98141
Altostratus
The problem with this idea is that if two hosts are in two different narrow networks that happen to be in the same supernet, it will SNAT unnecessarily. As a concrete example, if I have two hosts, 192.168.0.2/26 and 192.168.0.254/26, your iRule will SNAT those hosts even though they aren't in the same subnet. This is why I want to be able to get information about the Self-IPs: in order to get netmask information. - IheartF5_45022
Nacreous
Right. Good point. I'm afraid you are out of luck - you can't get the self-ip info from an iRule. You'll either need to snat everything or maintain a list of networks (which I agree is unwieldy).
- IheartF5_45022
Nacreous
Actually I do have one more idea which would only work if your pools only contain members from a single subnet.
Set yourself a pool naming standard that includes the mask length of the members subnets in a consistent position ie. pl_dns_26, pl_mysite_http_24. Then you can extract the mask info from the pool name.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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