Forum Discussion

Martin_Woodhous's avatar
Martin_Woodhous
Icon for Nimbostratus rankNimbostratus
Mar 21, 2007

if, elseif and adding comments within.

I'm trying to write a rule to redirect users based on source IP subnet.

 

i've come up with the following, but i'd like to be able to add comments to identify each subnet to a name (this could be in a comment field or otherwise) to make it easier to (human) read.

 

I don't seem to be able to add comments within the "if" statement. Is this right or am i just formatting it wrong?

 

 

Also, is this the most efficient way to write the rule? or can i create a table of some kind and reference that? There may be more than one subnet going to a particular pool.

 

 

Thanks in advance!

 

 

rule redirect-based-on-source {

 

when CLIENT_ACCEPTED {

 

 

if { [IP::addr [IP::client_addr] equals 10.212.249.0/255.255.255.224] } {

 

pool Pool-1}

 

elseif { [IP::addr [IP::client_addr] equals 172.20.208.160/255.255.255.224] } {

 

pool Pool-2}

 

elseif { [IP::addr [IP::client_addr] equals 173.20.208.160/255.255.255.224] } {

 

pool Pool-3}

 

else {

 

pool Pool4

 

}

 

}

 

}

2 Replies

  • Hmm...interesting, I've added comments all over the place as follows:

    
    if { [ matchclass $my_uri contains $::some_class] } {
          if { $my_uri starts_with "/somestring" } {
             set my_host somenewhost
             set my_uri [HTTP::uri]
             HTTP::redirect "http://$my_host$myuri"
          } else {
             log local0. "URL: http://$my_host$my_uri"
             pool somepool
          }

    Perhaps it is the placement of the that is in question? Not sure, but this works for me.
  • Gentlemen, Thanks for the information - in the end i was placing the comments in the wrong place. It's taken me this long to get access to the system to be able to update it. Thanks for your help.