Forum Discussion
Srikanth_79730
Feb 06, 2012Nimbostratus
iRules to verify binary data from TCP::payload
Hey Folks,
Good day. I am newbie to F5/irules. Need help from you guys to solve my first task on irule :)
I have a pool of 3 servers. The incoming traffic is a TCP binary stream. The idea is to collect the first two bytes of data after client side TCP connection setup and based on that determine which server to redirect to in the pool.
For example:
1. if the first two bytes are "00000000 000000001", then direct traffic to Server 1.
2. if the first two bytes are "00000000 000000010", then direct traffic to Server 2.
3. if the first two bytes are "00000000 000000011", then direct traffic to Server 3.
I have written a simple irule as below, but its not working. I tried comparing using regexp and operators such as "contains/equals/starts_with". But it doesnt seem to compare well. I know that this is a string formatting problem. (I read the documentation of TCP::payload, it talks about the default format is UTF8, but somehow could not figure a fix)
Can you please help me out here on how to compare the binary data received from TCP::payload.
-------------------------------------------------
when CLIENT_ACCEPTED
{
TCP::collect 2
}
when CLIENT_DATA
{
set msid [TCP::payload 2]
if { [regexp "\x00\x00" $msid] }
{
pool lb-pool member 10.224.115.141 30003
}
elseif { [regexp -indices "\x00\x01" $msid] }
{
pool lb-pool member 10.224.115.142 30003
}
elseif { [regexp -indices "\x00\x10" $msid] }
{
pool lb-pool member 10.224.115.143 30003
}
else
{
pool ss-blitz01-pool-30003 member 10.224.115.140 30003
}
TCP::release
}
-------------------------------------
- Thanks in advance
Srikanth
- nitassEmployeecan you add log command something like this?
[root@ve1023:Active] config b rule myrule list rule myrule { when CLIENT_ACCEPTED { TCP::collect 2 } when CLIENT_DATA { set msid [TCP::payload 2] binary scan $msid H* msid_hex log local0. "\$msid: $msid" log local0. "\$msid_hex: $msid_hex" TCP::release } } [root@ve1023:Active] config cat /var/log/ltm Feb 5 23:56:26 local/tmm info tmm[4369]: Rule myrule CLIENT_DATA: $msid: GE Feb 5 23:56:26 local/tmm info tmm[4369]: Rule myrule CLIENT_DATA: $msid_hex: 4745
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