Forum Discussion

Snl's avatar
Snl
Icon for Cirrostratus rankCirrostratus
Apr 03, 2016

Irule issue for if statement error

Hello folks

 

need help on below , i am getting undefined procedure in line3 and missing script after if error line 2

 

when HTTP_REQUEST { if { ([HTTP::uri] contains "/dfg") and !([matchclass [IP::remote_addr] equals IP_Range]) } { HTTP::redirect "https://abc.com" } pool ab-Pool }

 

any help appreciated

 

2 Replies

  • It's likely caused by the way the rule is flattened. When I create a rule as follows on 11.5.3, it works fine:

    when HTTP_REQUEST { 
        if { ([HTTP::uri] contains "/dfg") and !([matchclass [IP::remote_addr] equals IP_Range]) } { 
            HTTP::redirect "https://abc.com" 
        }
        
        pool ab-Pool
    }
    

    Newlines (and semi-colons) are statement delimiters in Tcl, and somewhat counter-intuitively,

    if
    is a command in Tcl, as is
    pool
    . Therefore, the
    if { ... } { ... }
    is one statements, and the
    pool ...
    in another.

    Having said that, note that

    matchclass
    is deprecated, as explained here:

    You should use

    class match
    , instead.

    Moreover, the

    pool
    command at the end is essentially a noop if you assigned that pool to the associated Virtual Server. Assuming this is the only iRule associated with the VS, you should remove the
    pool
    command, and if you've not done so already, assign the pool to the VS. It is clearer and more performant.

  • The syntax is essentially the same:

        if { [class match [IP::remote_addr] equals IP_Range] } {
           ...
        }
    

    (assuming that IP_Range is the name of the data-group.