Forum Discussion
Brian_Mayer_841
Nimbostratus
Aug 19, 2008Conditional logic based on source IP
Hi guys,
We'd like to implement an iRule that triggers on the presence of two or three specific strings in the URI. When any of the strings are found, we next want to check the source IP. If the IPs are part of a data group, then we want to allow the traffic to reach the site. All other IPs should be dropped.
Any idea if this is possible?
Thanks in advance guys,
B
- Nicolas_Menant
Employee
Hi,when HTTP_REQUEST { if {[HTTP::uri] starts_with "/appli1" } { if {[matchclass [IP::addr [IP::client_addr]/16] equals $::autorized_IPs]} { pool web_pool } else { reject } }
- Brian_Mayer_841
Nimbostratus
Sounds good. I'll drop this in today and let you know how it goes. Thanks! - Brian_Mayer_841
Nimbostratus
So I've created an iRule but it's not quite working. Here's it is: - Brian_Mayer_841
Nimbostratus
Bump, any help guys? - The_Bhattman
Nimbostratus
Haven't test this, but have you tried:when HTTP_REQUEST { if {([matchclass [HTTP::uri] contains $::cm2prod_filtered_URI]) and (not [matchclass [IP::client_addr] eq $::corporate_external_net])} { discard } }
when HTTP_REQUEST { if {([matchclass [HTTP::uri] contains $::cm2prod_filtered_URI]) and (![matchclass [IP::client_addr] equals $::corporate_external_net])}{ discard } }
when HTTP_REQUEST { if {[matchclass [HTTP::uri] contains $::cm2prod_filtered_URI] and (not [matchclass [IP::client_addr] equals $::corporate_external_net])} { discard } }
when HTTP_REQUEST { if {([matchclass [HTTP::uri] contains $::cm2prod_filtered_URI]) and (not [matchclass [IP::client_addr] equals $::corporate_external_net])} { discard } }
- Brian_Mayer_841
Nimbostratus
I've simplified the iRule a lot and it still doesn't work as expected: - hoolio
Cirrostratus
If you want to check the URI for one string, you wouldn't reference the class or use matchclass. Also, if the above examples aren't working, break each check into a separate 'if' statement and add logging to figure out what's happening.when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: request to [HTTP::host], [HTTP::uri]" if {[HTTP::uri] contains "/init/"]}{ log local0. "[IP::client_addr]:[TCP::client_port]: URI contained /init/, dropped request" discard } }
when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: -------------------------------------" log local0. "[IP::client_addr]:[TCP::client_port]: \$::cm2prod_filtered_URI contents: $::cm2prod_filtered_URI" log local0. "[IP::client_addr]:[TCP::client_port]: \$::corporate_external_net contents: $::corporate_external_net" log local0. "[IP::client_addr]:[TCP::client_port]: request to [HTTP::host], [HTTP::uri]" if {([matchclass [HTTP::uri] contains $::cm2prod_filtered_URI])}{ log local0. "[IP::client_addr]:[TCP::client_port]: matched URI to class if {(not [matchclass [IP::client_addr] equals $::corporate_external_net])}{ log local0. "[IP::client_addr]:[TCP::client_port]: didn't match client to external networks class discard } } }
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