Forum Discussion
Question about creating a guid in iRules
Hi there,
I found in this discussion group a way of creating a guid in iRules which is like so...
proc CreateGuid {
append s [clock seconds] [IP::local_addr] [IP::client_addr] [expr { int(100000000 * rand()) }] [clock clicks]
set s [md5 $s]
binary scan $s c* s
lset s 8 [expr {([lindex $s 8] & 0x7F) | 0x40}]
lset s 6 [expr {([lindex $s 6] & 0x0F) | 0x40}]
set s [binary format c* $s]
binary scan $s H* s
append u [substr $s 0 8] "-" [substr $s 8 4] "-" [substr $s 12 4] "-" [substr $s 16 4] "-" [substr $s 20 12]
unset s
return $u
}
It seems to work really well, however in the logging it gives this warning...
Warning generated : /Common/Irule_App:1: warning: [The following errors were not caught before. Please correct the script in order to avoid future disruption. "unexpected end of arguments;expected argument spec:PROC_SCRIPT"0 476][proc CreateGuid {
1. Any ideas what this relates to?
2. Sorry an extra question: how important in general is it to use 'unset' if i've been using lots of local variables in one of my biggest iRules? Does the memory for these local variables get free'd up at some point anyway after each request and response have been processed?
Thanks!
Toni
- Lucas_ThompsonEmployee
Interesting one! It seems like the parser gives this sort of error when it's defined with no input variables, though it does seem to function correctly anyway. Adding a dummy input variable eliminates the error. It's not very clear from our docs if it's supposed to require one or not.
This version of the script with just a dummy input variable added doesn't produce any errors or warnings:
proc CreateGuid foo {
append s [clock seconds] [IP::local_addr] [IP::client_addr] [expr { int(100000000 * rand()) }] [clock clicks]
set s [md5 $s]
binary scan $s c* s
lset s 8 [expr {([lindex $s 8] & 0x7F) | 0x40}]
lset s 6 [expr {([lindex $s 6] & 0x0F) | 0x40}]
set s [binary format c* $s]
binary scan $s H* s
append u [substr $s 0 8] "-" [substr $s 8 4] "-" [substr $s 12 4] "-" [substr $s 16 4] "-" [substr $s 20 12]
unset s
return $u
}
when HTTP_REQUEST {
log local0. "function return: [call CreateGuid 1]"
}For clearing variables: The TCL variables are associated with the conn flow and will become un-set automatically when the flow expires. I still like to think that it's good programming practice to free all of your variables explicitly, so I usually try to remember to do it anyway, just in case some issue happens where a lot of connections are made at once, or whatever.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com