preload
Dec 01

If you do any amount of work with F5 Nework’s iRules scripting language, eventually you run into the need to print out the contents of a packet you are working with to make sure you are processing the packet correctly, getting the fields lined up, getting sent the values you think you are being sent, etc.  Personally, I’m used to using a very common hexdump format that I’ve created Ruby methods for in the past…but I could not find anything similar for iRules, so I wrote my own.

The following code implements the hexdump:

if { $static::DEBUG eq 1 } {
        #  The hexbinary code we want to decode is stored in $payload
        ##
        ## format string for hexdump output
        ##
        set p 0     ;## buf ptr
        set sl [string length $payload]
        set inPkt "\n\n"
        while { $p < $sl } {
            set s [string range $payload $p [expr {$p+16}] ]
            binary scan $s H*@0a* hex ascii
            regsub -all -- {[^[:graph:] ]} $ascii {.} ascii
            set hex1   [string range $hex   0 15]
            set hex2   [string range $hex  16 31]
            set ascii1 [string range $ascii 0  7]
            set ascii2 [string range $ascii 8 15]
            # Convert the hex to pairs of hex digits
            regsub -all -- {..} $hex1 {& } hex1
            regsub -all -- {..} $hex2 {& } hex2
            append inPkt "[format {%08x  %-24s %-24s %-8s %-8s} $p $hex1 $hex2 $ascii1 $ascii2]\n"
            set p [expr {$p + 16}]
        }
        ###
        puts "Input PKT: $inPkt"            ;## print the output to /var/log/tmm
}

Continue reading »

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with:
Sep 13

When I’m writing iRules programs on my MacBook Pro as part of my job at F5 Networks, I like to copy in configuration and setup information as part of documenting the program.  This entails cutting and pasting in multi-line config file sections and then adding the ‘#’ comment character to the start of each line.  Well, after doing that a couple of times, I knew there was a way to automate that.  Enter some Applescript:

(*  Comment/Uncomment Block
    Add & remove '# ' in Selection. Good for iRules comments.
	Assign to a key for best use.

	John Allen, F5 Networks
	Sept. 12, 2011
*)

tell application "BBEdit"
	activate
	repeat with x in lines of selection of window 1 of text document 1
		if exists character 1 of text of x then
			set start to character 1 of text of x as text
		else
			set start to ""
		end if
		if start is not "#" then
			replace "^" using "# " searching in text of x options {search mode:grep}
		else
			replace "^# " using "" searching in text of x options {search mode:grep}
		end if
	end repeat
end tell

Of course, you can modify this to work with any programming language.

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with: