Forum Discussion
Retrieve Value from Data Group record
Hi all
i am trying to write an irule to drop client paket by source IP, but instead of calling the IP in the rule as a condition , i want to add a location as a data value in the data group and apply the conditin on it my data group looks like :
ltm data-group internal Locations {
records {
10.1.1.0/24 {
data paris/allow
}
10.1.2.0/24 {
data ny/allow
}
10.10.1.100/32 {
data my_self/drop
}
172.16.1.0/24 {
data tokyo/allow
}
192.168.1.0/24 {
data London/drop
}
192.168.100.0/24 {
data moon/allow
}
}
type ip
}
the condition is stored in the data group
wy question is how to get data from the records and since we can have multiple match how can we get data.
hope my question is enough clear ...
3 Replies
- Vijay_E
Cirrus
Hello,
When using a data-group of
, the longest match wins.type ipIn the example data-group you provide, I don't see overlapping entries so I'll provide an example that does have entries that overlap.
Notesltm data-group internal Locations { records { 10.1.1.0/24 { data "paris allow" } 10.1.2.0/24 { data "ny allow" } 10.1.2.96/29 { data "lab drop" } 10.10.1.100/32 { data "my_self drop" } 172.16.1.0/24 { data "tokyo allow" } 192.168.1.0/24 { data "London drop" } 192.168.100.0/24 { data "moon allow" } } type ip } ltm rule ALLOW_BY_IP { when RULE_INIT { test Locations data-group if {[TMM::cmp_unit] == 0} { foreach IP {10.1.1.1 10.1.2.10 10.1.2.99 10.10.1.100 192.168.100.230 172.30.1.1} { log local0. "address ${IP}: matches entry \ \x22[class match -name $IP equals Locations]\x22 \ and has value of \x22[class lookup $IP Locations]\x22" } else { log local0. "no match found for address $IP" } } } when CLIENT_ACCEPTED { set VAL [class lookup [IP::client_addr] Locations] switch -- [lindex $VAL 1] { allow { log local0. "allow connection from [lindex $VAL 0] \ w/IP [IP::client_addr]: entry [class match -name [IP::client_addr] equals Locations]" } drop { log local0. "reject connection from [lindex $VAL 0] \ w/IP [IP::client_addr]: entry [class match -name [IP::client_addr] equals Locations]" reject } default { log locla0. "no match found or the match did not have allow/drop" } } } }- Instead of the syntax name/action, I chose "name action". This skips the step of having to split them manually in the iRule.
- Added a
event with a foreach loop to test several addresses and hopefully demonstrate how longest match functions. SinceRULE_INIT
fires once for each TMM, I useRULE_INIT
to only execute on TMM 0 so the test doesn't cause redundant logging.TMM::cmp_unit - In the
event, switch statement is used to matchCLIENT_ACCEPTED
/allow
or log if neither matched.drop
Is this what you were looking for?
- Azzeddine_S
Cirrus
thanks a lot
the answer is more than what i expected
i really apriciate the effort and i will give you a feed back about the result as soon i deploy it
once again thanks a lot
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