Forum Discussion
What_Lies_Bene1
Cirrostratus
Feb 01, 2006Combining Logical Operators
Hi all. Hope you're all well.
I'd like to reduce some scripts I have that are used to restrict and redirect traffic. Access is based on domain name and client IP address. We've multiple domain names pointing to a single VS and restricted URI's too, as well as multiple clients, none of whom should see each others sites.
So, I've got something like that below. We check the IP against the data group and then evaluation the host and uri. Based on the results we redirect accordingly. Then we have to do the same for every different host and every different uri. A nightmare.
It's never gonna be great (we're simply running too much through a single VS) however, I'm sure some of the checks could be reduced. For instance [matchclass [IP::client_addr] equals $::AAA_HOSTS or BBB_HOSTS or CCC_HOSTS]. Is it possible?
(We can combine the data groups by the way, we'd lose track of who's who - unless we could reference data groups from within data groups??)
if {[matchclass [IP::client_addr] equals $::AAA_HOSTS] && "[HTTP::host]" equals "HOSTA" && "[HTTP::uri]" equals "/"}
{
log local0. "blah blah"
HTTP::redirect https://blah blah
}
elseif {[matchclass [IP::client_addr] equals $::BBB_HOSTS] && "[HTTP::host]" equals "HOSTA" && "[HTTP::uri]" equals "/"}
{
HTTP::redirect https://somewhere else
}
if
Thanks in advance
- Gerald_Chisholm
Nimbostratus
I am trying to generalize some rules, to do this I think a "class" needs to be created. The "class" would be loaded into an array to be referenced by the rule. The size of the class would be unknown and have a format something like this: - Data Groups (or classes) can be operated on as if they were a TCL list. You can use the TCL list commands to get the length of the list and extract elements. I'm unsure why you want to use an array for this.
class port_mappings { "10.10.10.10,4111,4121", "10.10.10.20,5111,5121" } *** BEGIN iRule *** when HTTP_REQUEST { iterate through port_mappings class (as a list) foreach line $::port_mappings { Create a list from the current line set item_list [split $line ","] Extract item 0 (ip address) set ip [lindex $item_list 0] iterate through all the port numbers. for {set x 1} {$x<[llength $item_list]} {incr x} { set port [lindex $src_list $x] } } } *** END iRule ***
- Gerald_Chisholm
Nimbostratus
I think this is just what I wanted. We are in the process of moving from 4.5.x to 9.x.y and have more than 50 rules per LB, they are all tweaked a little for each VIP. I would like to generalize to about 5 - 10 rules, to do this I need variable data per VIP. - What_Lies_Bene1
Cirrostratus
Thanks for the reply Colin. I think the first option is the most appropriate, it will still simplify things alot, nice one. The second isn't really useable as two IP's (it's all client web proxies) needs access to multiple domains pointing to a single VS but only specific URI's on those domains, another single IP needs access to only one of those domains and on and on and on. That covers a client, their call centre provider and their IVR system. Then you have another client, different domains, same VS, same URI restrictions and so on. Every client has a slightly different setup and trust levels for their IVR providers etc are also different. - What_Lies_Bene1
Cirrostratus
Worth noting for anyone who found this useful that my LB's (running 9.05) didn't like the round brackets () at all. Simply removing them solved the problem. Cheers - Colin_Walker_12Historic F5 AccountReally? Your BIG-IP had problems with the parenthesis " ) "? That's surprising.
- Gerald_Chisholm
Nimbostratus
This question is about matchclass using a class having an incorrect format: - Colin_Walker_12Historic F5 AccountIf you're using matchclass you should get a result of 0 or 1 depending on the match. If you're using findclass with a delimiter specified, then you should get whatever comes after said delimiter.
- Gerald_Chisholm
Nimbostratus
I am using a findclass, and mistakenly entered a record in the class table with no space: - Gerald_Chisholm
Nimbostratus
I have it now, after speaking with (Anthony Gerace F5) I can test if the index into the class is equal to the returned value to test for the missing space.
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