Forum Discussion

Perry_B__8260's avatar
Perry_B__8260
Icon for Nimbostratus rankNimbostratus
Nov 28, 2007

Logical Operator or Pipebar?

Hi -- I want to listen on VIP for TCP::client_port (445,1051,1052,10521) and direct to a Pool. Would it be required to use OR and braces for each eq statement -- or is this possible --

 

 

iRule my_iRule {

 

when CLIENT_ACCEPTED

 

if { [TCP::client_port] eq 445 || eq 1051 || eq 1052 || eq 10521 } {

 

pool my_POOL

 

}

 

else {

 

TCP::close

 

}

 

}

 

 

Thank you...

 

1 Reply

  • Hi,

    You can use 'or' or || in TCL, but you'd need to have each condition listed fully. Also, if you're wanting to restrict which ports the virtual server accepts traffic on, you should use TCP::local_port in the clientside context (Click here). For your scenario, using a switch would be cleaner than a set of if's (Click here). Here are two versions:

    
    when CLIENT_ACCEPTED {
       if { [TCP::local_port] eq 445 || [TCP::local_port] eq 1051 || [TCP::local_port] eq 1052 || [TCP::local_port] eq 10521 } {
          pool my_POOL
       } else {
          TCP::close
       }
    }

    
    when CLIENT_ACCEPTED {
       switch [TCP::local_port] {
          445 -
          1051 -
          1052 -
          10521 {
             log local0. "allowed [IP::client_addr]:[TCP::client_port] -> [IP::local_addr]:[TCP::local_port]"
             pool my_pool
          }
          default {
             log local0. "dropped [IP::client_addr]:[TCP::client_port] -> [IP::local_addr]:[TCP::local_port]"
             drop
          }
       }
    }

    Aaron