Forum Discussion
Ian_Smith
Aug 23, 2006Ret. Employee
curious results from md5
when I do this on 9.1.2 or 9.2.3:
when CLIENT_ACCEPTED {
set client [IP::client_addr]
set clienthash [md5 [IP::client_addr]]
log "the client is: $client the clienthash is: $clienthash "
}
I get log entries like this:
the client is: 10.10.91.1 the clienthash is: "ª¨4ÙÁWh²ÄÒ(·èr
but I expect that clienthash should be:
db6e0e56e15da22be2bae7fb51139b6e
Are my expectations wrong, or is something not working right?
- unRuleY_95363Historic F5 AccountUnfortunately, we return the raw result of the MD5. I'm not sure what we would ever use that for... Instead, you simply need to b64 encode it. Try this instead:
set clienthash [b64encode [md5 [IP::client_addr]]]
- Colin_Walker_12Historic F5 AccountDoes that mean that the -hex argument isn't valid?
when CLIENT_ACCEPTED { set client [IP::client_addr] set clienthash [md5 -hex [IP::client_addr] ] log "the client is: $client the clienthash is: $clienthash " }
- unRuleY_95363Historic F5 AccountBecause we already had the b64encode command and it's not a performance improvement to do it within the md5 command...
- Craig_Holland_2
Nimbostratus
Ya - but it would be really handy to be able to do mod and other match on the md5 hashes for persistence and pool selection. The b64encode outputs alpha-numeric, so you are hobbled in what you could do with the string. - unRuleY_95363Historic F5 AccountThen perhaps you want to binary scan it into a variable...
This will return the MD5 hash into 4 32-bit values as a list in md5ary. If you are only interested in using, say the first 4 bytes of the hash, then you could do:binary scan [md5 [IP::client_addr]] i4 md5ary
This will put the first 4 bytes into the variable md5var and the rest in junk. Note: this would also be the equivalent of [lindex 0 md5ary] from the first example.binary scan [md5 [IP::client_addr]] ii3 md5var junk
- AndrewM_4835
Nimbostratus
Has the behaviour of the md5 command changed in 9.4? In 9.2 I am seeing the broken raw strings as expected above. However there is an article series referring to md5[URI]%server persistence - and I don't see how this would work if the md5 command does not return an integer.... - spark_86682Historic F5 AccountHrm. It's possible that the "Typical Hash iRule" article originally had "crc32" instead of "md5", which should work fine. crc32 has bad properties for using it in Election Hash iRules, though. I'll poke deb to correct that article if she doesn't see this instead...
- what was the final word regarding md5 in the Election Hash iRule? should md5 be working? was it meant to be crc32? Also, what are the 'bad properties' for using crc32 in Election Hash iRules?
- spark_86682Historic F5 AccountIt was meant to be md5, it just needs/needed the output converted to a numeric value.
- NathanM_65949
Nimbostratus
Spark called it. crc32 is a cheaper operation than MD5, roughly %40 less CPU if I remember correctly. That makes the election hash iRule scale much better. But the downside to crc32 is that it often results in collisions. Practically speaking, this means that you will get an uneven distribution. If you have a bunch servers, some will get as much as %80 more than others even after a normalization of millions of queries. MD5 is meant to be cryptographically secure, hence very few collisions, which means for use as a load balancing algorithm, near perfect distribution of queries across servers.
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects