Forum Discussion
Drop single request based on header value
We are trying to setup an iRule that will drop a request that has a matching IP in a datagroup. In this scenario, the connections are persistent so all of the HTTP requests are coming down the same connection. We want to drop the request, NOT the connection. Is the below correct for this scenario?
when HTTP_REQUEST {
if { [HTTP::header exists "True-Client-IP"] and not ([string equal [HTTP::header "True-Client-IP"] "127.0.0.1"]) } {
set trueIP [HTTP::header "True-Client-IP"]
} else {
set trueIP [IP::client_addr]
}
if { [class match $trueIP equals block_list] } {
HSL::send [HSL::open -proto UDP -pool corp_pool_accelops_syslog] "DSA_BLOCK: Rejecting connection from $trueIP based on matching entry in block_list..."
discard
}
}
1 Reply
- Kevin_Stewart
Employee
Yours should work, but here's a minor modification:
when HTTP_REQUEST { if { ( [HTTP::header exists True-Client-IP] ) and not ( [HTTP::header True-Client-IP] equals "127.0.0.1" ) } { set trueIP [HTTP::header True-Client-IP] } else { set trueIP [IP::client_addr] } if { [class match $trueIP equals block_list] } { discard } }You're allowing the client, or perhaps an upstream proxy, to set a header (True-Client-IP). If that header exists, use it in the class match, otherwise use the client's IPas seen by the F5. If a match is found, discard the request. Is that your intention?
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