Forum Discussion
Asif_Thobhani_7
Nimbostratus
Jun 03, 2006F5 Cookie encoding
Hi,
Is there a method or an easy way in iRule to encode the IP:Port that is compatible with F5.
From BigIP documentation:
--------------------------
Alternatively, you can perform the encoding using the following equation
for address (a.b.c.d):
d*(256^3) + c*(256^2) + b*256 +a
The way to encode the port is to take the two bytes that store the port and
reverse them. Thus, port 80 becomes 80 * 256 + 0 = 20480. Port 1433
(instead of 5 * 256 + 153) becomes 153 * 256 + 5 = 39173.
I am wondering if there is already a method that would do this?
Thanks in advance.
-Asif
1 Reply
- Asif_Thobhani_7
Nimbostratus
After some trial and error, I got the following and it seems to be working...
I will appreciate any comments/corrections!
$nodePort is in format: XXXX
$nodeIP is in format: XXX.XXX.XXX.XXX
Encode the Port for F5
set a $nodePort
set b [expr {[expr {($a) & 0xff00}] >> 8}]
set c [expr {[expr {($a) & 0x00ff}] << 8}]
set encodedPort [expr {$b+$c}]
if { $::DebugFlag } {log LOCAL0. "nodePort: $a, b: $b, c: $c, encodedPort: $encodedPort" }
Encode the IP for F5
set ip [split $nodeIP "."]
set a [getfield $ip " " 1]
set b [getfield $ip " " 2]
set c [getfield $ip " " 3]
set d [getfield $ip " " 4]
set b1 [expr {$b << 8}]
set c1 [expr {$c << 12}]
set d1 [expr {$d << 24}]
if { $::DebugFlag } {log LOCAL0. "a: $a, b1: $b1, c1: $c1, d1: $d1"}
set encodedIP [expr {$a + [expr {$b << 8}] + [expr {$c << 16}] + [expr {$d << 24}]}]
if { $::DebugFlag } {log LOCAL0. "nodeIP: $nodeIP, a: $a, b: $b, c: $c, d: $d, and encodedIP=$encodedIP" }
set encodedIPPort "$encodedIP.$encodedPort.0000"
if { $::DebugFlag } {log LOCAL0. "F5 encodedIP and Port: $encodedIPPort"}
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
