Forum Discussion

lizunjjg_280139's avatar
lizunjjg_280139
Icon for Nimbostratus rankNimbostratus
Oct 23, 2018

what mean this irules

set len_msg [binary format B* $bitVal_msg] log local0. "len_msg:$len_msg" if {![regexp {^[0-9]+$} [substr $len_msg 0 1]] or ![regexp {^[0-9]+$} [substr $len_msg 1 1]] or ![regexp {^[0-9]+$} [substr $len_msg 2 1]] or ![regexp {^[0-9]+$} [substr $len_msg 3 1]] } { log local0. "packet_wrong" TCP::collect return

 

  • I can't say what the iRule is for, but I can maybe give a hint into what it's doing.

    The full details of the operations can be found here: http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm

    set len_msg [binary format B* $bitVal_msg] 
    

    Take some presumably binary message and converts that to a binary string of bytes.

    if {
        ![regexp {^[0-9]+$} [substr $len_msg 0 1]] or 
        ![regexp {^[0-9]+$} [substr $len_msg 1 1]] or 
        ![regexp {^[0-9]+$} [substr $len_msg 2 1]] or 
        ![regexp {^[0-9]+$} [substr $len_msg 3 1]] 
    } { 
    

    The regular expression ^[0-9]+$ is testing if a value is a number (contains all numbers), so the above is testing each byte in a series of 4 bytes in the extracted string to see if it's a number.

    log local0. "packet_wrong" 
    TCP::collect return
    

    So if the first byte isn't a number, or the second byte isn't a number, or the third byte isn't a number, or the fourth byte isn't a number, send a log message and return. Also presumably this is happening inside a _DATA event (CLIENT_DATA, SERVER_DATA), so would exit this event.