For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Paul_Slosberg_8's avatar
Paul_Slosberg_8
Historic F5 Account
May 17, 2007

A better way

Greetings,

Im trying to grab the last octect of the client adress so I can then use that to send the thraffic to the proper pool. I will have 254 pools that I need to send traffic too. Im trying to use variables to stream line this i-Rule any help or sugestions would be great. I will be using a nework virtual server and 254 port spcific pools. ie (4001-4254)


when CLIENT_ACCEPTED {
set port_info [getfield [IP::client_addr] "." 4]
set poolname "mypool_"
if  
{ $port_info matches_regex "[ 1-9]"}
{ pool $poolname400$portinfo } 
elseif
{ $port_info matches_regex "[ 10-99]"}
{pool $poolname40$port_info}
else 
{ $port_info matches_regex "[ 100-254]"}{
pool $poolname4$portinfo}
   }
 }

13 Replies

  • Paul_Slosberg_8's avatar
    Paul_Slosberg_8
    Historic F5 Account
    Ok sorry to be vague. I was told that by removing the [brackets] from a command I can set values such as HTTP::uri /something/here. I then thought I may be able to use the same logic to the TCP::local_port command. I actually have this iRule saved on my 9.3 machine.

    
    when CLIENT_ACCEPTED { 
    TCP::local_port  4[format "%.3d" [getfield [IP::local_addr] "." 4]]}

    I didn't think it was going to work and I was surprised that it saved with out error.

    On the VS and pool issue. The iRule that you wrote is great and it works perfectly. I have a network virtual 192.168.1.0/24:any and pools mypool_4001 mypool_4100 ect. Works great.

    What I was trying to accomplish with translating the port. Was the further reduction in objects on the configuration.

    It was a shot in the dark.

    I was hoping to have a network virtual

    192.168.1.0/24:any

    that would point to a

    default pool with servers X Y Z

    When a request that was destined to the 192.168.1.0/24 network with an IP adress of 192.168.1.123

    BIP-IP would inturn translate the port to 4123 and send to the default pool member. Not sure if this is possible.

    thanks

  • Ok, I might have something for you. You can specify the node you are connecting to with the node command.

    You could do this in the CLIENT_ACCEPTED event but then you would have to know the address of the node you want to connect to. But, if you wait until a LB decision has been made, you can get the targeted pool member, override the target with the same member but a different port.

    Here's something that might just work for a general case (be warned, I haven't fully tested it out).

    when LB_SELECTED  {
      set server [LB::server]
      log local0. "Server: $server"
      set list [split $server " "]
      set member [lindex $list 1]
      log local0. "Node: $member"
      set port 4[format "%.3d" [getfield [IP::client_addr] "." 4]]
      log local0. "Port: $port"
      switch [llength $list] {
        "3" {
          log local0. "First pass server format 'pool member port'"
          node $member $port
           must call LB::reselect to trigger a new lb decision
           based on the previous node command
          LB::reselect
        }
      }
    }

    The LB::reselect with trigger a second LB_SELECTED event with the value of "LB::server" being just the member and port (as opposed to in the first pass where it's the pool, member and port.

    Now, if you know the address of your node that you are connecting to, then it's really easy as you can issue the node command from the CLIENT_ACCEPTED event.

    when CLIENT_ACCEPTED {
      node 10.10.10.10 4[format "%.3d" [getfield [IP::client_addr] "." 4]]
    }

    where 10.10.10.10 is the address of your node.

    Just something completely off the top of my head but worth a shot. Let me know if any of this works out...

    -Joe
  • Maybe it's not required in this case, but I've found that I need to do an LB::detach before the reselect for the member/port to actually be reassigned in this event.