Forum Discussion
Matt_Williamson
Nimbostratus
Mar 29, 2005iRule to persist on tcp_content
Hi all, I'm trying to write a rule that will search the first 2500 bytes of tcp_content for the "USERNAME=" string and then persist on the next 7 characters after that. Here is my original attempt.
rule client_tcpusrid_persist {
when CLIENT_ACCEPTED {
set usrid {findstr [tcp_content(2500) contains "USERNAME="] "USERNAME=" 7 "t"}
if {tcp_content(2500) contains "USERNAME="} {
persist uie $usrid
log local0. "Persisting $userid"
}
}
}
Here's the error I'm getting...
01070151:3: Rule [getfield_test] error: line 1: [undefined procedure: rule] [rule client_tcpusrid_persist {
when CLIENT_ACCEPTED {
set usrid {findstr [tcp_content(2500) contains "USERNAME="] "USERNAME=" 7 "t"}
if {tcp_content(2500) contains "USERNAME="} {
persist uie $usrid
log local0. "Persisting $userid"
}
}
}]
Any help you can give would be great. Thanks.
Matt
- unRuleY_95363Historic F5 AccountOk, you have a couple of problems.
when CLIENT_ACCEPTED { TCP::collect 2500 } when CLIENT_DATA { set usrid [findstr [TCP::payload] "USERNAME=" 9 "t"] if {$usrid ne ""} { persist uie $usrid log local0. "Persisting $userid" } }
- Matt_Williamson
Nimbostratus
Thank you so much for the help! It works! - vinny_murphy_96
Nimbostratus
Hi, - JRahm
Admin
Check the doc Using UIE Function Commands under Tech Tips. Gives the syntax for the findstr command. An excerpt: - Matt_Williamson
Nimbostratus
Hi, the script searches for the string "USERNAME=" in the 2500 bytes of tcp data collected. The way the actual stream looks is like this...... - vinny_murphy_96
Nimbostratus
Thanks, Matt, Jason,=========================================================== Do not declare the rule in the script this is just for clarity rule NonKeep-alivePersistence { Rule entry point when CLIENT_ACCEPTED { TCP::collect } when CLIENT_DATA { TCP::collect 25 log local0. "persisting:" set hashKey [findstr [TCP::payload] "X-Client-IP" 13 "\r"] if the hashKey is not equal to a whitespace/delimiter if {$hashKey ne ""} { persist uie $hashKey 1200 pool TestPool log local0. "Key to persist: $hashKey" } Flush collect data and release event hook point TCP::release } }
- vinny_murphy_96
Nimbostratus
Hi again,Rule entry point when SERVER_CONNECTED { TCP::collect } when SERVER_DATA { Collect 30 bytes to see if its an OPTIONS response TCP::collect 30 set identifier [findstr [TCP::payload] "OPTIONS" 7 "\r"] if {$identifier ne " "} { if its an OPTIONS response, process the TCP.. TCP::collect 250 250 bytes should give me the Max-Connections header } else { [[TCP::payload] contains "Max-Connections:"]} { set MaxConn [[TCP::payload] value "Max-Connections:"] TCP::respond $MaxConn log local0. "OptionResponse: $MaxConn" } Flush collect data and release event hook point TCP::release }
- unRuleY_95363Historic F5 AccountIn the particular example above, you do not need the TCP::release because there is an implied release if a new collect was not issued in the CLIENT_DATA event. However, doing the TCP::release is certainly not harmful in any way.
- vinny_murphy_96
Nimbostratus
Hi unRuleY,when CLIENT_ACCEPTED { TCP::collect } when CLIENT_DATA { For requests arriving using a Content-Length header if { [TCP::payload contains "Content-Length:"] } { set ConLen [TCP::payload value "Content-Length:"] set hashKey [findstr [TCP::payload] "X-Client-IP" 13 "\r"] if {$hashKey ne ""} { persist uie $hashKey 1200 } else { [TCP::payload contains "Encapsulated: req-hdr="] } { set hdrStart [TCP::payload value "Encapsulated: req-hdr="] set hashKey1 [findstr [TCP::payload] "X-Client-IP" 13 "\r"] if {$hashKey1 ne ""} { persist uie $hashKey1 1200 } } elseif { [TCP::payload contains "Encapsulated: req-hdr=0, null-body="] } { set hdrOSet [TCP::payload value "Encapsulated: req-hdr=0, null-body="] set hashKey2 [findstr [TCP::payload] "X-Client-IP" 13 "\r"] if {$hashKey2 ne ""} { persist uie $hashKey2 1200 } } } TCP::release }
- unRuleY_95363Historic F5 AccountWow, that is some complicated iRule you've developed...
set ConLen [TCP::payload value "Content-Length:"]
set ConLen [findstr [TCP::payload] "Content-Length:" 15 "\r"]
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