Need some help creating an iRule. The idea is that I have a VS, and I will be associating a iRule to do a redirect, but I dont want to do a redirect if a the IP/Subnet is in the iRule data group. I think I have something close, but would like someones feedback.
when HTTP_REQUEST {
if { ([matchclass [IP::remote_addr] equals $::Whitelist_Sorry]) } {
As I’ve learned recently, in this type of case it’s simpler (and a shorter irule) to use Not. So, if you’re not in the whitelist redirect. This is because a similar post came up very recently (DevCentral).
Also, not sure what version you’re running but know that matchlass was deprecated in v10 by class match. Two examples below.
v9.x
when HTTP_REQUEST {
if {not ([matchclass [IP::remote_addr] equals $::Whitelist_Sorry]) } {
If you’re on 9.4.4 or higher make sure to remove the $:: prefix from the data group name. You can add debug logging to figure out why the iRule isn’t working. Here’s a version 10 or higher example:
when HTTP_REQUEST {
if { [class match [IP::client_addr] equals Whitelist_Sorry] } {
log local0. "[IP::client_addr]:[TCP::client_port]: Client is in data group so do not redirect. DG: [class get Whitelist_Sorry]"
} else {
log local0. "[IP::client_addr]:[TCP::client_port]: Client is not in data group so redirect"
HTTP::redirect
}
}
Also, [IP::client_addr] and [IP::remote_addr] will return the same value in clientside events like CLIENT_ACCEPTED and HTTP_REQUEST.