TCL error: invalid command name "1" on GTM

Hi,

I have the following irule on my GTM:

when DNS_REQUEST {

if { [[active_members Global-webservices.landsbanki.is_A10_pool] = 0] and [[active_members Global-webservices.landsbanki.is_RB_pool] = 0] } {

drop

}

elseif { [IP::addr [IP::remote_addr]/24 equals 89.104.145.0/24] } {

if { [active_members Global-webservices.landsbanki.is_A10_pool] >= 1 } {

pool Global-webservices.landsbanki.is_A10_pool

}

else {

pool Global-webservices.landsbanki.is_RB_pool

}

return

}

elseif { [IP::addr [IP::remote_addr]/24 equals 89.104.148.0/24] } {

if { [active_members Global-webservices.landsbanki.is_RB_pool] >= 1 } {

pool Global-webservices.landsbanki.is_RB_pool

}

else {

pool Global-webservices.landsbanki.is_A10_pool

}

return

}

elseif { not [[IP::addr [IP::remote_addr]/16 equals 172.27.0.0/16] or [IP::addr [IP::remote_addr]/19 equals 89.104.128.0/19]] } {

drop

}

}

But I always get this error in the /var/log/gtm file:

gtmd[1818]: 011a7001:3: TCL error: Rule Global_Webservice_millinet_irule - invalid command name “1” while executing “[active_members Global-webservices.landsbanki.is_A10_pool] = 0”

and I know that the error comes on the first (bolded above) : [active_members Global-webservices.landsbanki.is_A10_pool] = 0]

Can anyone tell me what is wrong with this ??

I don’t understand the error - where is this command name “1” ??

Hi Arnor,

The square braces execute the text within as a command and return the value. So if you have [$command1] or [$command2] it will return true or false (0 or 1). If you have [[$command1] or [$command2]] it will try to execute 0 or 1 and return an invalid command error as 0 and 1 aren’t valid commands. If you want to do logical grouping, use parentheses instead.

Also, when using the IP::addr command, only put the /subnet on the network--not a host address like IP::remote_addr. Lastly, when checking the result of the active_members command, you should use == to do a numeric comparison not just =.

Can you try this?

when DNS_REQUEST {
   if { [active_members Global-webservices.landsbanki.is_A10_pool] == 0 and [active_members Global-webservices.landsbanki.is_RB_pool] == 0 } {
      drop
   } elseif { [IP::addr [IP::remote_addr] equals 89.104.145.0/24] } {
      if { [active_members Global-webservices.landsbanki.is_A10_pool] >= 1 } {
         pool Global-webservices.landsbanki.is_A10_pool
      } else {
         pool Global-webservices.landsbanki.is_RB_pool
      } 
      return
   } elseif { [IP::addr [IP::remote_addr] equals 89.104.148.0/24] } {
      if { [active_members Global-webservices.landsbanki.is_RB_pool] >= 1 } {
         pool Global-webservices.landsbanki.is_RB_pool
      } else {
         pool Global-webservices.landsbanki.is_A10_pool
      } 
      return
   } elseif { not ([IP::addr [IP::remote_addr] equals 172.27.0.0/16]  or [IP::addr [IP::remote_addr] equals 89.104.128.0/19]) } {
      drop
   }
}

Aaron

Excellent Aaron, thank you - of course this was the issue - works perfectly now :slight_smile:

I always get a bit confused with all the braces and parentheses :frowning:

Thanks,

Arnór

Just remember that square braces are to execute commands and return the value, and parentheses are used for logical grouping :slight_smile:

Aaron

Now I have a new twist on this - and maybe I should open a case for this, but I’ll try it here first.

I just upgraded the GTM’s from 9.4.8 to 10.2.2 and after that, I am not able to edit this rule (above) through the GUI.

It works fine if I edit it with iRule editor and save it, but when editing it in the GUI and pressing ‘update’ I get this error:

01070151:3: Rule [Global_Webservice_millinet_irule] error:

line 1: [undefined procedure: ] [{}]

All other irules work fine, but not this one !?

Any ideas ?

Can you post the exact rule you’re testing in [ code ] [/ code ] blocks (without the spaces)?

Aaron

Yes sure,

but actually - it is just a copy of what you wrote above :slightly_smiling_face:

Here it is:

when DNS_REQUEST {
if { [active_members Global-webservices.landsbanki.is_A10_pool] == 0 and [active_members Global-webservices.landsbanki.is_RB_pool] == 0 } {
drop
}
elseif { [IP::addr [IP::remote_addr] equals 89.104.145.0/24] } {
if { [active_members Global-webservices.landsbanki.is_A10_pool] >= 1 } {
pool Global-webservices.landsbanki.is_A10_pool
}
else {
pool Global-webservices.landsbanki.is_RB_pool
} 
return
}
elseif { [IP::addr [IP::remote_addr] equals 89.104.148.0/24] } {
if { [active_members Global-webservices.landsbanki.is_RB_pool] >= 1 } {
pool Global-webservices.landsbanki.is_RB_pool
}
else {
pool Global-webservices.landsbanki.is_A10_pool
} 
return
}
elseif { not ([IP::addr [IP::remote_addr] equals 172.27.0.0/16]  or [IP::addr [IP::remote_addr] equals 89.104.128.0/19]) } {
drop
}
}

This looks like a bug in the GTM iRule parser. Here’s a simple way to reproduce it:

when DNS_REQUEST {
    if { 1 == 1 } {
    }
}

Here’s a workaround:

when DNS_REQUEST {
    if { not [active_members Global-webservices.landsbanki.is_A10_pool] and not [active_members Global-webservices.landsbanki.is_RB_pool] } {
        drop
    }
    elseif { [IP::addr [IP::remote_addr] equals 89.104.145.0/24] } {
        if { [active_members Global-webservices.landsbanki.is_A10_pool] } {
            pool Global-webservices.landsbanki.is_A10_pool
        }
        else {
            pool Global-webservices.landsbanki.is_RB_pool
        } 
        return
    }
    elseif { [IP::addr [IP::remote_addr] equals 89.104.148.0/24] } {
        if { [active_members Global-webservices.landsbanki.is_RB_pool] } {
            pool Global-webservices.landsbanki.is_RB_pool
        }
        else {
            pool Global-webservices.landsbanki.is_A10_pool
        } 
        return
    }
    elseif { not ([IP::addr [IP::remote_addr] equals 172.27.0.0/16]  or [IP::addr [IP::remote_addr] equals 89.104.128.0/19]) } {
        drop
    }
}

You could open a case with F5 Support to have them look into the issue. It might be fixed already in the current v11 beta as I believe there has been a lot of work done on GTM iRules in the upcoming version.

Aaron

Thanks Aaron, that did the trick.

I’ll wait with opening a case, I always use the iRule editor anyways…

Arnór

If the unit isn’t in production, try running ‘b load’ with the original iRule that generates an error when trying to save via the GUI. Chances are if it errs via the GUI it won’t load either. I’d open a case on this sooner than later.

Aaron

…

…

Hi again Aaron,

I have been having some problem with letting the iRule work correctly after the changes, and actually two of the changes that you suggested that I do, resulted in the iRule working incorrectly.

Firstly - you suggested to change in the last ‘elseif’-line the outer braces to paratheses - it seems logical, I aggree on that, but the logic did not work as expected - when I put the braces back - this worked fine again:

So it works like this:

elseif { not [[IP::addr [IP::remote_addr] equals 172.27.0.0/16]  or [IP::addr [IP::remote_addr] equals 89.104.128.0/19]] } {

but not like this:

elseif { not ([IP::addr [IP::remote_addr] equals 172.27.0.0/16]  or [IP::addr [IP::remote_addr] equals 89.104.128.0/19]) } {

Secondly - you said:

when using the IP::addr command, only put the /subnet on the network--not a host address like IP::remote_addr.

But that did not work either - I tested this out by putting in log local0. lines at every step.

So I had to have it like this:

elseif { [IP::addr [IP::remote_addr]/24 equals 89.104.145.0/24] } {

but it did not work like this :

elseif { [IP::addr [IP::remote_addr] equals 89.104.145.0/24] } {

This makes sense, because this is not “equal”, and I don’t think there is an operator that you could use for this.

We need an inversed “contains” operator.

Maybe it would work to reverse this and put :

elseif { [ 89.104.145.0/24 contains IP::addr [IP::remote_addr] ] } {

?? I haven’t tried it, but that would make sense wouldn’t ?

Regards,

Arnór

Hi Arnor,

Your post got munged as the forums don’t handle multiple code blocks in the quick reply box. Can you just click Edit on your post and then Submit? This will force the post to be re-rendered correctly.

Thanks, Aaron

Posted By Arnor Arnason on 07/14/2011 04:32 AM

Hi again Aaron,

I have been having some problem with letting the iRule work correctly after the changes, and actually two of the changes that you suggested that I do, resulted in the iRule working incorrectly.

Firstly - you suggested to change in the last ‘elseif’-line the outer braces to paratheses - it seems logical, I aggree on that, but the logic did not work as expected - when I put the braces back - this worked fine again:

So it works like this:

elseif { not [[IP::addr [IP::remote_addr] equals 172.27.0.0/16]  or [IP::addr [IP::remote_addr] equals 89.104.128.0/19]] } {

but not like this:

elseif { not ([IP::addr [IP::remote_addr] equals 172.27.0.0/16]  or [IP::addr [IP::remote_addr] equals 89.104.128.0/19]) } {

Secondly - you said:

when using the IP::addr command, only put the /subnet on the network--not a host address like IP::remote_addr.

But that did not work either - I tested this out by putting in log local0. lines at every step.

So I had to have it like this:

elseif { [IP::addr [IP::remote_addr]/24 equals 89.104.145.0/24] } {

but it did not work like this :

elseif { [IP::addr [IP::remote_addr] equals 89.104.145.0/24] } {

This makes sense, because this is not “equal”, and I don’t think there is an operator that you could use for this.

We need an inversed “contains” operator.

Maybe it would work to reverse this and put :

elseif { [ 89.104.145.0/24 contains IP::addr [IP::remote_addr] ] } {

?? I haven’t tried it, but that would make sense wouldn’t ?

Regards,

Arnór test

Sorry - I didn’t see your replay right away, but I think it should be readable now ?

If this case gets executed it will trigger a runtime error:

elseif { not [[IP::addr [IP::remote_addr] equals 172.27.0.0/16] or [IP::addr [IP::remote_addr] equals 89.104.128.0/19]] } {

as this:

[IP::addr [IP::remote_addr] equals 172.27.0.0/16] or [IP::addr [IP::remote_addr] equals 89.104.128.0/19]

will return either 0 or 1 depending on the client IP. Then the outer square braces mean that return value will get executed. So you’ll get an error saying 1 or 0 isn’t a valid command.

Using parentheses will allow you to negate the expression within:

if { not (0 and 1) } {
log local0. "true"
} else {
log local0. "false"
}

Log output: true

As for IP::addr and the slash notation: both should work if you’re on 10.2.1:

: [IP::addr 89.104.145.10 equals 89.104.145.0/24]: 1

: [IP::addr 89.104.145.10/24 equals 89.104.145.0/24]: 1

But the first version where the subnet is only on the network address (not the host) will be more efficient (by up to 40%). See Jason’s article on this:

http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/1086449/iRules-IP-Comparison-Considerations-with-IPaddr-Command.aspx

Aaron