Forum Discussion

David_Stout's avatar
David_Stout
Icon for Nimbostratus rankNimbostratus
Oct 31, 2012

TCL error - Can't read variable

I am trying to re-write some iRules for CMP by removing the global variables however I'd like to know why I am getting this error. I'm not a complete TCL expert so some assistance is appreciated.

 

 

Oct 31 10:42:27 local/tmm err tmm[4996]: 01220001:3: TCL error: devdrmssi.dr.com - can't read "org": no such variable while executing "if { ([matchclass $subject_dn contains devdrmssi_trusted_certs]) and ($subject_dn contains $org) } { log "Http Request for devdrmssi accepted from..."

 

 

 

This is the iRule

 

when RULE_INIT {

 

set org "O=companyname"

 

set subject_dn ""

 

log "devdrmssi.dr.com irule initialized"

 

}

 

when CLIENTSSL_CLIENTCERT {

 

if { [SSL::cert count] != 0 }{

 

set subject_dn [X509::subject [SSL::cert 0]]

 

if { $subject_dn != "" }{

 

log "Client Certificate Received: $subject_dn"

 

}

 

}

 

}

 

when HTTP_REQUEST {

 

if { ([matchclass $subject_dn contains devdrmssi_trusted_certs]) and ($subject_dn contains $org) } {

 

log "Http Request for devdrmssi accepted from Client Certificate $subject_dn"

 

pool devdrmssi.dr.com

 

} else {

 

reject

 

}

 

}

 

 

 

 

5 Replies

  • It doesn't help explain the issue but can't you move ' set org "O=companyname"' to the HTTP_REQUEST event?
  • Moving the variable to after the HTTP_REQUEST worked ... I guess that only Global Variables can be set in the RULE_INIT section ... Now it makes some sense by moving it into the iRule itself so it can be processed as a local variable and I'm truly not going mad.

     

     

    Thanks for the pointer :)
  • i understand variable which is defined in RULE_INIT will be treated as global variable. so, we have to use $:: when referencing. what Steve suggested is totally right.

    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when RULE_INIT {
       set org "test"
    }
    when HTTP_REQUEST {
       log local0. "\$::org is $::org"
    }
    }
    [root@ve10:Active] config  cat /var/log/ltm
    Oct 31 21:23:59 local/tmm info tmm[7926]: Rule myrule : $::org is test
    
  • You could also use the static namespace in RULE_INIT if you want a globa-like variable that's CMP compatible:

     

     

    https://devcentral.f5.com/wiki/iRules.static.ashx

     

     

    Aaron