Forum Discussion
LillyM_9417
Altostratus
Dec 14, 2011switch & swith -globe question
Hello,
I could not manage to work this irule. Please help me to make it run.
Thanks
Lilly
=============================
**************
**************
**************
when CLIENT_DATA {
set pay1 [TCP::payload 8]
binary scan $pay1 IA4 len1 trx1
switch [IP::addr [IP::client_addr]]{
"x.x.x.x/24"{
switch -glob [class match $trx1 ] {
"A"{
do smthng}
}
"B" {
do something
}
"C" {
do something
}
default {
do something
}
}
}
"y.y.y.y/24"{
switch -glob [class match $trx1 ] {
"D"{
do something
}
"E" {
do something
}
"F" {
do something
}
default {
do something
}
}
}
}
}
=============================
13 Replies
- Michael_Yates
Nimbostratus
Hi LillyM,
You cannot switch an IP::addr command the way that you were doing it. See this conversation switch statement, [IP::addr], and varying subnet masks.
The class command (class match $trx1), works with Data Groups. The $trx1, is the variable set in your binary scan. So you can switch off of it, but not perform a class match against it.
Try something like this and let us know if it works for you:when CLIENT_DATA { set pay1 [TCP::payload 8] binary scan $pay1 IA4 len1 trx1 if { [IP::addr [IP::client_addr] equals "x.x.x.x/24" ] } { switch -glob [ $trx1 ] { "A" { do something } "B" { do something } "C" { do something } default { do something else } } } elseif { [IP::addr [IP::client_addr] equals "y.y.y.y/24" ] } { switch -glob [ $trx1 ] { "D" { do something } "E" { do something } "F" { do something } default { do something else } } } }
Hope this helps! - LillyM_9417
Altostratus
Hi Micheal,
It gave some error, I am trying to figure them out. If I could, then I will let you know in a few minutes.
Otherwise, I will send you the error and the code that I modified.
Million thanks
Lilly - LillyM_9417
Altostratus
Hi again Micheal,
I am taking the following error for these lines: " switch -glob [$trx1] {"
[invalid list: list element in quotes followed by "{" instead of space] []
I will appreciate it if you could help on this too..
Thanks
Lilly
=============================================================
when CLIENT_DATA {
set pay1 [TCP::payload 8]
binary scan $pay1 IA4 len1 trx1
if { [IP::addr [IP::client_addr] equals X.X.X.X/24]}{
switch -glob [$trx1] {
"A"{
do something
}
"B" {
do something
}
"C" {
do something
}
default {
do something else
}
}
}
if { [IP::addr [IP::client_addr] equals Y.Y.Y.Y/24]}{
switch -glob [$trx1] {
"D"{
do something
}
"E" {
do something
}
"F" {
do something
}
default {
do something else
}
}
}
}
============================================================= - Michael_Yates
Nimbostratus
You should investigate your binary scan command and possibly log the value to your LTM Log to see what you are getting.
TCL Reference Manual: binary - LillyM_9417
Altostratus
4 character ascii command and no problem in it. It seems to me that it is related with switch -globe command and the error also says like this.
Why do you think it is about binary scan?
Thanks - Michael_Yates
Nimbostratus
Can you post the error that it is logging? - LillyM_9417
Altostratus
I cannot even load and save this IRULE, I got the following error:
[invalid list: list element in quotes followed by "{" instead of space] []
Thanks
Lilly - hoolio
Cirrostratus
You should just need to remove the square braces from the switch string:when CLIENT_DATA { set pay1 [TCP::payload 8] binary scan $pay1 IA4 len1 trx1 if { [IP::addr [IP::client_addr] equals "x.x.x.x/24" ] } { switch -glob $trx1 { "A" { do something } "B" { do something } "C" { do something } default { do something else } } } elseif { [IP::addr [IP::client_addr] equals "y.y.y.y/24" ] } { switch -glob $trx1 { "D" { do something } "E" { do something } "F" { do something } default { do something else } } } }
Aaron - Michael_Yates
Nimbostratus
I would have thought that the square brackets could have caused that problem.
Learn something new all the time.
Can you let us know if Hoolio's suggestion works?
- LillyM_9417
Altostratus
Hello All,
Firstly I want to thank you for your help and suggestions. In that case (the last one ,Hoolio's suggestion I meant) I only compare the $trx with some strings A, B,C etc.
But What I really want to do is, comparing with the content of an external file Like "class match $trx1"does.
Is this possible?
Thanks a lot..
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
