Forum Discussion
Philippe_CLOUP
Employee
Sep 17, 2007looking inside persistence table, through different Virtual Servers
I have created an irule to store, using universal persistence, the 2 things:
- the Client-IP adress connected to the VS.
- the Mac adress of the "lasthop" that sent the request to the VS.
Why ?
Because i need to send all the trafic generated from the server inside the pool, to the client IP, THROUGH THE SAME EQUIPMENT THAT SENT the incoming connection.
I created a second iRule, to catch the persistence created on the incoming VS, each time the server is generating an outgoing connection (created a wildcard VS, in perf L4, with "any protocols" - CLIENT_ACCEPTED event, persist across virtuals selected).
The problem is that i cannot find the entry in the persistence table (persist lookup uie ....). If i try to add it in the table via this irule, the only entry i find is the incoming one, with the "aging time" resetted.
DO YOU THINK THE PERSISTENCE TABLE CANNOT BE SHARED THROUGH THE OTHER VS, IF THEY ARE ON DIFFERENT VLANS WITH DIFFERENT NODES AND POOLS ?
Thanks.
- hoolio
Cirrostratus
Do you have a universal persistence profile with "Match Across Virtual Servers" (and possibly "Match across services" if the pool on the incoming VIP is defined on a specific port) enabled, to both virtual servers? - Philippe_CLOUP
Employee
Here is a part of the bigip_base.conf from my test lab: - Deb_Allen_18Historic F5 AccountThe config shown is the inside pair of a firewall sandwich.
The class will be used for direct outbound node selection by IP based on inbound lasthop MAC.class fw_MAC2IP { 00:00:00:00:00:00 192.168.100.200 00:00:00:00:00:00 192.168.100.201 }
rule bidirectional_firewall_persistence { when RULE_INIT { set ::timeout 86400 } when CLIENT_ACCEPTED { set server "" set origin_vlan [LINK::vlan_id] log local0. "vlan ID: $origin_vlan client: [IP::remote_addr]" if {$origin_vlan == "4094"}{ for client originated connections, use server pool & simple persistence set session_key [IP::remote_addr] log local0. "client connecting from vlan $origin_vlan - session_key = >$session_key<" select inbound pool by name & apply simple persistence pool RTR-OUT persist source_addr 86400 create/update session table entry for reciprocal traffic session add uie {$session_key any virtual} [LINK::lasthop] $::timeout log local0. "RTR-OUT pool selected, source_addr persistence & session table entry added for $session_key" } else { for server originated conns, look up nexthop MAC for that dest IP in session table set session_key [IP::local_addr] log local0. "server connecting from vlan $origin_vlan - session_key = >$session_key<" set fwMAC [session lookup uie {$session_key any virtual}] log local0. "fwMAC found: >$fwMAC< - session_key = >$session_key<" if {$fwMAC != ""}{ If session table entry already exists, refresh to update timeout session add uie {$session_key any virtual} $fwMAC $::timeout log local0. "session table entry refreshed - session_key = >$session_key<" then look up fw IP address in class by MAC set fwIP [findclass $fwMAC $::fw_MAC2IP " "] log local0. "fw IP >$fwIP< found for MAC $fwMAC - session_key = >$session_key<" if {$fwIP != ""}{ if fw IP address is found in the class for this MAC, directly select fw node log local0. "directly selecting fw node $fwIP - session_key = >$session_key<" node $fwIP 0 } else { if no fw IP address was found in the class for this MAC, log an error This should never happen if class list contains the correct data in the correct format log local0. "No IP address found for MAC $fwMAC Check class list for proper entries." log local0. "LB'ing outbound conn to rtr_f5 pool - session_key = >$session_key<" select outbound pool by name pool rtr_f5 } } else { if no session table entry found, load balance the connection log local0. "No session table entry for $session_key. LB'ing outbound conn to rtr_f5 pool." select outbound pool by name pool rtr_f5 } } } when LB_FAILED { detach and choose a new server if the selected server fails to respond. LB::detach LB::reselect } }
- Philippe_CLOUP
Employee
The result of this iRule is the following: - Deb_Allen_18Historic F5 Accounthmm, I have used that syntax before & not had a issue w/variable expansion... What version are you on?
session add uie {[list $session_key] any virtual} ....
- leozou_80567Historic F5 AccountHi deb,
- Deb_Allen_18Historic F5 Accounthmm....
against a modified class:set fwIP [findclass [getfield $fwMAC ":" 6] $::fw_MAC2IP " "]
class fw_MAC2IP { 10.9.1.11 f7 10.9.1.12 f8 }
- hoolio
Cirrostratus
Here's an updated but untested version of the iRule for 10.1.0 or higher:rule bidirectional_firewall_persistence { when RULE_INIT { Log debug to /var/log/ltm? (2=all including debug, 1=only log missing mac2ip datagroup entries, 0=none) set static::fw_debug 1 Time in seconds to store mappings for set static::timeout 86400 Pool name for outbound routers set static::outbound_pool "outbound_pool" Pool name for inbound routers set static::inbound_pool "inbound_pool" Name of string datagroup which maps mac addresses to IP addresses for the routers set static::mac2ip_class "mac2ip_class" VLAN ID of upstream clients set static::client_vlanid 4094 } when CLIENT_ACCEPTED { set server "" set origin_vlan [LINK::vlan_id] if {$static::fw_debug}{log local0. "vlan ID: $origin_vlan client: [IP::client_addr]"} Check if this a client originated connection by VLAN ID if {$origin_vlan == $static::client_vlanid}{ for client originated connections, use server pool & simple persistence set session_key [IP::client_addr] if {$static::fw_debug}{log local0. "client connecting from vlan $origin_vlan - session_key = \"$session_key\""} select inbound pool by name & apply simple persistence pool $static::ingbound_pool persist source_addr 86400 create/update session table entry for reciprocal traffic session add uie [list $session_key any virtual] [LINK::lasthop] $static::timeout if {$static::fw_debug}{log local0. "$static::router_out_pool pool selected, source_addr persistence & session table entry added for $session_key"} } else { for server originated conns, look up nexthop MAC for that dest IP in session table set session_key [IP::local_addr] if {$static::fw_debug}{log local0. "server connecting from vlan $origin_vlan - session_key = \"$session_key\""} set fwMAC [session lookup uie [list $session_key any virtual]] if {$static::fw_debug}{log local0. "fwMAC found: \"$fwMAC\" - session_key = \"$session_key\""} if {$fwMAC ne ""}{ If session table entry already exists, refresh to update timeout session add uie [list $session_key any virtual] $fwMAC $static::timeout if {$static::fw_debug}{log local0. "session table entry refreshed - session_key = \"$session_key\""} then look up firewall MAC address in the datagroup to get the firewall IP address set fwIP [class match -value $fwMAC equals $static::mac2ip_class] if {$static::fw_debug}{log local0. "fw IP \"$fwIP\" found for MAC $fwMAC - session_key = \"$session_key\""} if {$fwIP ne ""}{ if fw IP address is found in the class for this MAC, directly select fw node if {$static::fw_debug}{log local0. "directly selecting fw node $fwIP - session_key = \"$session_key\""} node $fwIP 0 } else { if no fw IP address was found in the class for this MAC, log an error This should never happen if class list contains the correct data in the correct format if {$static::fw_debug}{log local0. "No IP address found for MAC $fwMAC Check class list for proper entries."} if {$static::fw_debug}{log local0. "LB'ing outbound conn to $static::outbound_pool pool - session_key = \"$session_key\""} select outbound pool by name pool $static::outbound_pool } } else { if no session table entry found, load balance the connection if {$static::fw_debug}{log local0. "No session table entry for $session_key. LB'ing outbound conn to $static::outbound_pool pool."} select outbound pool by name pool $static::outbound_pool } } } when LB_FAILED { detach and choose a new server if the selected server fails to respond. LB::detach LB::reselect } }
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