Forum Discussion

HA13029's avatar
HA13029
Icon for Nimbostratus rankNimbostratus
Dec 11, 2017

Datagroup and switch command

Hello,

 

I created different datagroup (list of TCP ports) and based on this setting, selecting the correct pool within my irule.

 

ltm data-group internal DG_TCP-010901-10902 { records { 10901 { } 10902 { } } type string }

 

when CLIENT_ACCEPTED { switch [TCP::local_port] { DG_TCP-010901-10902 { pool P_010901-10902 } etc etc default { reject } } }

 

Unfortunatly, it doesn't work...

 

If I change the irule to the following it works... when CLIENT_ACCEPTED { switch [TCP::local_port] { "10901" { pool P_010901-10902 } "10902" { pool P_010901-10902 } etc etc default { reject } } }

 

Regards,

 

I prefer to use the switch command instead of if commands and using datagroup to avoid mistake when editing irule...

 

HA

 

  • You cant really use datagroups in a switch statement (unless you nest an

    if
    within the switch)

    To look up a datagroup you'll need to use the

    class
    command

     when CLIENT_ACCEPTED {
        if {[class match [TCP::local_port] equals "DG_TCP-010901-10902"]} {
            reject
        }
    
  • You can try with this code:

     

    when CLIENT_ACCEPTED { 
        switch [TCP::local_port] { 
            "10901" -
            "10902" { pool P_010901-10902 }
            default { reject } 
        } 
    }

    or use a data group containing pool name as value

     

    ltm data-group internal DG_TCP { 
        records { 
            10901 {P_010901-10902} 
            10902 {P_010901-10902} 
            XXXX {P_XXXX} 
        } 
        type string 
    }
    
    when CLIENT_ACCEPTED {
        if {[set pool [class match -value [TCP::local_port] equals "DG_TCP"]] ne ""} {
            pool $pool
        } else {
            reject
        }
    }
  • Hi,

     

    Thanks Stanislas, it works fine !!

     

    Regards

     

    Hedi

     

  • One last question... Can I use datagroup to reference some URLs (sometimes with wildcard) and based on the result, select the correct pool ?? Example : if the uri match /000552/1743* then select the pool P_0005521743 What's the irule looks like ??

     

    Regards,

     

    HA

     

  • Hello,

     

    Do you think it's ok with the following ??

     

    ltm data-group internal DG_URI { records { "/000042/16001" {pool P_name } } type string }

     

    when HTTP_REQUEST { if {[set pool [class match [HTTP::uri] starts_with "DG_URI"]} { pool $pool } else { pool default } }

     

    Regards,

     

    HA