Because the BIG-IP is a normally a full-proxy, for the load-balancing function, the client establishes a connection to the BIG-IP, then an LB decision is made, then the server connection is established. For each incoming segment from the client, data may be collected, modified, then forwarded toward the server. So the trick here is to grab the data from the first segment after the three way handshake and insert your header, followed by whatever data was in that segment. Thereafter, you may allow the flow to continue without alteration. The event where you may manipulate data from the client-side (before sending it to the server) is CLIENT_DATA, which is triggered when TCP::collect is invoked. In this case, it makes sense to do so in the CLIENT_ACCEPTED event, just as you had.
So, this should achieve what you're after:
when CLIENT_ACCEPTED {
TCP::collect
}
when CLIENT_DATA {
TCP::payload replace 0 0 [binary format "a*SIIIIIIIc4S" "IP36" 0x01 0x0 0x0 0x0 0x0 0x0 0x0000ffff 0x0 [split [IP::client_addr] .] [TCP::client_port]]
TCP::release
}
The 0x01 is the "operation code". I used the value of 1 because I don't know what you wish that to be. I also assume that the IPv4 address is high-order padded (it's 64 bits, so I assume the first 32-bits are zero followed by the 32-bit IPv4 address). Finally, I assume all values should be encoded in network byte-order.