F5 – BigIP LTM basic iRules hacks

=============================

when HTTP_RESPONSE {
if { [HTTP::status] [== 404} {
HTTP::redirect “http://www.example.com/newlocation.html”
}
}

=====================================================
when RULE_INIT {
set cookie_name “piy_which_resolved”
}

when HTTP_REQUEST {
if { [IP::addr [IP::client_addr] equals 122.122.122.221] } {
HTTP::cookie insert name $::cookie_name value india_piy path “/”
} elseif {[IP::addr [IP::client_addr] equals 122.122.122.222] } {
HTTP::cookie insert name $::cookie_name value us_piy path “/”
}
}

when HTTP_REQUEST {

# Check if requested path is /
if {[HTTP::path] eq “/”}{
HTTP::cookie insert name $::cookie_name value us_piy path “/”
} else {
virtual myvip
}

==========================================
Rule for VIP1

when RULE_INIT {
set cookie_name “fromwhere”
}

when HTTP_REQUEST {

# Check if requested path is /
if {[HTTP::path] eq “/”}{
HTTP::cookie insert name $::cookie_name value india_piy path “/”
}

log local0. “Client Connected, IP: [IP::client_addr]”
log local0. “Local Address, IP: [IP::local_addr]”
log local0. “Virtual Server: [virtual]”

}
===============================================
Rule for VIP2

when RULE_INIT {
set cookie_name “fromwhere”
}
when HTTP_REQUEST {

# Check if requested path is /
if {[HTTP::path] eq “/”}{
HTTP::cookie insert name $::cookie_name value us_piy path “/”
}

log local0. “Client Connected, IP: [IP::client_addr]”
log local0. “Local Address, IP: [IP::local_addr]”
log local0. “Virtual Server: [virtual]”

}

===============================================

when HTTP_REQUEST {
if { [IP::addr [IP::remote_addr] equals 10.0.0.10] } {
HTTP::redirect “http://my.vip.example.com/”
}
}

=====================================================

when CLIENT_ACCEPTED {
set server_ip [ IP::local_addr ]
set client_ip [ IP::client_addr ]
if {$client_ip ==”0.0.0.0″} {
discard
return
}

if { [ matchclass $server_ip equals $::host_for_transparent_proxy ] } {
#log local0.info ” (TPROXY ROUTE)’$client_ip’ —> Divert to MSP ‘$server_ip'”
use node 10.217.164.212 8080
return
} elseif { [ matchclass $client_ip equals $::net_for_mobile_ip_test0045_apn ] } {
#log local0.info ” (WA-Proxy ROUTE)’$client_ip’ —> Divert to WA ‘$server_ip'”
persist source_addr
use pool WA_8080_pool
return
} else {
#log local0.info ” (TPROXY ROUTE)’$client_ip’ —> Forward to ‘$server_ip'”
virtual ANY-Forward
}
}

===============================================================