Emad
May 18, 2016Cirrostratus
FQDN Node with Route Domains
How can we add route domain in FQDN based nodes. In Address based node it can be added with %1 but how this will be done in FQDN based nodes.
Here's my attempt at it...
Rule Name: MY_RD_FQDN_IRULE
Rule Date: 01/07/2016
Rule Version: 1.0
Rule Description: This iRule is designed to lookup an IP for an FQDN and then use the IP for the serverside connection.
Simply edit the RULE_INIT variables to modify for your needs.
Test before using in any environment. This rule is provided *as-is* without warranty or liability.
Rule History: 1.0 - 01/07/2016 - C.Spathas (Ardenta) - Initial Version inspired by DevCentral
https://devcentral.f5.com/questions/dynamic-pool-members-with-dns-resolution
when RULE_INIT {
Set some static variables and lists
set static::MY_RD_FQDN_GBLVAR "www.google.com"
set static::MY_RD_FQDN_ROUTE_DOMAIN_GBLVAR "%1"
set static::MY_RD_FQDN_DNS_SRV_GBLST {8.8.8.8 8.8.4.4}
Set debug logging on/off (0 for none, 1 for drop/deny/error and 2 for all logging)
set static::MY_RD_FQDN_DEBUG_GBLVAR 2
}
when CLIENT_ACCEPTED {
Select a DNS server from the list and sppend the Route Domain
set DNS_SERVER_LCLVAR "[lindex $static::MY_RD_FQDN_DNS_SRV_GBLST [expr {int(rand()*[llength $static::MY_RD_FQDN_DNS_SRV_GBLST])}]]$static::MY_RD_FQDN_ROUTE_DOMAIN_GBLVAR"
Debug Logging
if {$static::MY_RD_FQDN_DEBUG_GBLVAR==2}{log local0. "DNS Server selected was $DNS_SERVER_LCLVAR"}
Perform the Lookup and append the Route Domain
set FQDN_IP_LCLVAR "[lindex [RESOLV::lookup @$DNS_SERVER_LCLVAR -a $static::MY_RD_FQDN_GBLVAR] 0]$static::MY_RD_FQDN_ROUTE_DOMAIN_GBLVAR"
Debug Logging
if {$static::MY_RD_FQDN_DEBUG_GBLVAR==2}{log local0. "The resolved IP for FQDN $static::MY_RD_FQDN_GBLVAR is $FQDN_IP_LCLVAR"}
Perform some rudimentary error checking
if { $FQDN_IP_LCLVAR ne "" } {
Use the FQDN IP as the node if there is one
node $FQDN_IP_LCLVAR
Debug Logging
if {$static::MY_RD_FQDN_DEBUG_GBLVAR==2}{log local0. "The connection for [IP::client_addr]:[TCP::client_port] was sent to $FQDN_IP_LCLVAR"}
} else {
If there is no FQDN IP then drop the connection
drop
Debug Logging
if {$static::MY_RD_FQDN_DEBUG_GBLVAR>0}{log local0. "No IP was resolved."}
}
}