Forum Discussion

yammy1688_99834's avatar
yammy1688_99834
Icon for Nimbostratus rankNimbostratus
Mar 30, 2011

class variable pairs possible?

when CLIENT_ACCEPTED {

 

if {[IP::addr [IP::client_addr] equals "10.64.40.0/24"] } {

 

node 10.64.40.2

 

} elseif {[IP::addr [IP::client_addr] equals "10.64.41.0/24"] } {

 

node 10.64.41.2

 

}

 

}

 

 

 

etc...

 

 

 

Is it possible to use class with a pair of matched variables? I'm going to have quite a number of these statements and would prefer to keep the irule as small as possible.

 

 

 

Thanks,

 

 

 

-Ken

 

  • Hi Ken,

    You can use the IP host/subnet = value format (name = value pairing) in 10.1+:

    
    class ip_subnets_class {
       {
          host 1.1.1.1 { "10.11.0.1" }
          network 2.2.2.0/24 { "10.10.10.10" }
       }
    }
    

    You can then use something like 'set dest [class match -value [IP::client_addr] equals ip_subnets_class]' to do the lookup.

    Aaron
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    So to re-write your current iRule using hoolio's (sweet and simple) logic above:

    
    when CLIENT_ACCEPTED {
      set dest [class match -value [IP::client_addr] equals ip_subnets_class]
      node $dest
    }
    

    Nice work hoolio, as always.

    Colin

  • Thanks!

     

     

    Didn't work when I defined the class in the irule itself, but worked fine if I defined it in the data group list from the GUI.

     

     

     

     

     

  • Yes, by design, datagroups/classes are separate objects from iRules, so they need to be defined independently.

     

     

    Glad it's working for you.

     

     

    Aaron
  • made a small change to it too, otherwise it broke other stuff since it's being applied to a 0.0.0.0/0.0.0.0 forwarding VS.

     

     

    when CLIENT_ACCEPTED {

     

    if {[class match [IP::client_addr] equals subnets] } {

     

    set dest [class match -value [IP::client_addr] equals subnets]

     

    node $dest

     

    }

     

    }

     

     

     

     

     

     

  • Hi Yammy,

    You could try this to eliminate the second class lookup:

    
    when CLIENT_ACCEPTED {
    
       set dest [class match -value [IP::client_addr] equals subnets]
       if {$dest ne ""} {
          node $dest
       }  
    }
    

    Aaron
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Good to know it's working, thanks. And yes, classes are intentionally separate config objects.

     

     

    Colin