Simple Sideband - iRule sideband the easy way
Code is community submitted, community supported, and recognized as ‘Use At Your Own Risk’.
Short Description
Simple Sideband is a helper iRule which makes getting started with doing iRule based sideband fast and simple.
Problem solved by this Code Snippet
Sideband can be difficult to get started - it requires knowledge of low-level networking, using the Sideband iRule commands, or possibly the HSSR plugin to do HTTP parsing for you. With simple sideband, you can add the iRule as a library and call the functions to do the hard work for you.
How to use this Code Snippet
Imagine you want to query a web server from your irule, you install the Simple Sideband iRule library on the platform as /Common/simple_sideband and use and iRule on your virtual server which calls the library like so:
when HTTP_REQUEST {
# Create HTTP request
set response [call /Common/simple_sideband::http_req 10.67.182.10:80 "/" {} ]
if { [lindex $response 0] == 200 } {
HTTP::respond 200 content $response
} else {
HTTP::respond 500 content $response
}
}
Example output:
200 {Server BigIP Connection Keep-Alive Content-Length 20} {hello world! port:80}
You can easily access the response status code, the headers and the body with a few lines of code.
Or you may want to send a DNS request:
when HTTP_REQUEST {
# Create DNS request
set q [call /Common/simple_sideband::dns_query "www.example.com" ]
binary scan $q H* qhex
log local0.debug "query:$qhex"
# Send request to DNS server
set response [call /Common/simple_sideband::udp_req 10.67.182.10:53 $q {recv_bytes 1} ]
if { [lindex $response 0] == 0 } {
# Successful response - decode the DNS esponse
set data [lindex $response 1]
binary scan $data H* data_hex
log local0.debug "Success!: $data_hex"
set r [call /Common/simple_sideband::dns_response $data ]
HTTP::respond 200 content $r
} else {
HTTP::respond 500 content {failure}
}
}
Output:
# curl 10.67.182.40
{18766 32776 1 1 0 0} {www.example.com 1 1} {{1 1 12 1.2.3.4}} {} {}
Logs:
Jul 14 08:54:26 simple-sideband-bigip1.pwhite debug tmm[30491]: Rule /Common/sideband_test <HTTP_REQUEST>: query:494e0008000100000000000003777777076578616d706c6503636f6d0000010001
Jul 14 08:54:27 simple-sideband-bigip1.pwhite debug tmm[30491]: Rule /Common/sideband_test <HTTP_REQUEST>: Success!: 494e8008000100010000000003777777076578616d706c6503636f6d0000010001c00c000100010000000c000401020304
To download the code, to see the options and detailed examples, go to my Github page at Simple-Sideband
Code Snippet Meta Information
- Version: v11+
- Coding Language: iRules