Forum Discussion

chris_connell_1's avatar
chris_connell_1
Icon for Nimbostratus rankNimbostratus
Aug 10, 2009

if/else vs case statement.

Hello

 

 

I'm wandering if its better to try and use a case statement for this irule, so if the dest ip is in the blacklist we discard, if the source is in $client_sources we send to ingress pool etc.

 

 

 

rule new-rule {

 

when CLIENT_ACCEPTED {

 

if { [matchclass [IP::local_addr] equals $::blacklist] } {

 

discard

 

} elseif { [matchclass [IP::remote_addr] equals $::client_sources] and [active_members Ingress] >= 48 } {

 

pool Ingress

 

} elseif { [matchclass [IP::remote_addr] equals $::client_test] } {

 

pool Ingress-test

 

} else {

 

forward

 

}

 

}

 

 

However with case statements I thought they are only useful if the variable is the same. So because I am using 2 different tests i.e. local_addr and remote_addr the case couldnt be used for this?

 

Thx

 

 

 

 

 

1 Reply

  • As you mentioned you are using 2 different conditions which means switch statement will add no value in your code.