Forum Discussion

Democritus_Per1's avatar
Democritus_Per1
Icon for Nimbostratus rankNimbostratus
Sep 25, 2012

binary scan irule with findstr

Hello Community,

 

 

We would like to implement the irule bellow in order to use for ensuring persistency based on an ICAP Header. Previus attempts on using HTTP:headers irules failed since the HTTP profile failed to handle the continuation ICAP packets .

 

 

Therefore we are thinking of applying the following binary scan irule in order to retrieve the string between "X-SESSION_ID: " and /r/n , that is the desired session ID :

 

 

rule Persist_BinaryScan_irule {

 

 

 

when CLIENT_ACCEPTED {

 

TCP::collect 200

 

}

 

 

when CLIENT_DATA {

 

 

set payload [TCP::payload]

 

 

binary scan $payload H* h_payload

 

set sess_id [findstr $h_payload 582d53455353494f4e5f49443a20 29 0d0a]

 

log local0. " $sess_id"

 

persist $sess_id

 

}

 

 

TCP::release

 

}

 

 

Sample ICAP request :

 

---------------------

 

RESPMOD icap://10.11.1.20:1344/df ICAP/1.0

 

 

Allow: 204

 

 

Host: 10.11.1.20

 

 

X-SESSION_ID: 10.20.44.245:1340175464

 

 

Preview:64

 

 

Encapsulated: req-hdr=0, res-hdr=1033, res-body=1408

 

 

 

Is there any comment/alterative suggestion on the proposed approach ? Do you see this as a performance intensive solution ?

 

 

Thanks in advance ,

 

Dimos

 

 

 

 

 

 

 

 

2 Replies

  • Hi Dimos,

     

     

    I think that's a reasonably efficient way to parse the content. Though have you tried using findstr against the raw payload without converting to hex?

     

     

    set sess_id [findstr [TCP::payload] "X-SESSION_ID: " 15 "\r\n"]

     

     

    Aaron
  • ie, here's what I'm thinking:

    
    when CLIENT_ACCEPTED {
    TCP::collect 200
    }
    
    when CLIENT_DATA {
    
    if {[set sess_id [findstr [TCP::payload] "X-SESSION_ID: " 14 "\r\n"]] ne ""}{
    log local0. "$sess_id"
    persist $sess_id
    }
    TCP::release
    }
    

    Aaron