Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

Dynamic port selection not working

Hello All. I'm trying to compose an irule that will direct the traffic to a dynamically chosen port in a pool, according to the URL the user uses. After much searching I got to the point where the node and the port are correctly selected, but the NLB disregards the node command and directs the traffic to the original port.

The URL is made of 3 letters of the service and 3 digits of the wanted inside-component. Together they compose the destination port. The user uses HTTPS(443), but the NLB has to direct the traffic to the "member:composed-port" according to the URL.

The VIP has address and port translation enabled. To be sure of that I included those commands in the irule. The member in the pool is defined with "port=all services".

 when RULE_INIT {
    # 0 = none, 1 = debug, 2 = verbose
    set static::APsp_Debug 2
 }
 when CLIENT_ACCEPTED {
      translate address enable
      translate port enable
 }
 when HTTP_REQUEST priority 1 {
    # Extract the last 3 chars from the hostname (e.g. 200 from ADM200.company.com)
    set APsp_inside_code [string range [getfield [HTTP::host] "." 1] end-2 end]
    #  Extract the first 3 chars from the hostname (e.g. ADM from ADM200.company.com)
    set APsp_service_code [string range [getfield [HTTP::host] "." 1] 0 2 ]

    switch -glob [string tolower $APsp_service_code]
        { "adm" {set APsp_dest_port "60$APsp_inside_code" }
          "rst" {set APsp_dest_port "64$APsp_inside_code" }
           default { log local0.error "service code not found. [HTTP::host][HTTP::uri]"
             HTTP::respond 404 "Not Found" 
                   }
        }
  }
 when LB_SELECTED priority 1 {
    set APsp_dest_node [LB::server addr]
    # replace the host header so the server will think that this is the original request 
    HTTP::header replace Host "company.co.il"
    # go to load balanced member, but with the needed port

         if {$static::APsp_Debug > 0} {
             log local0.info "LBserver= [LB::server addr] node=$APsp_dest_node port=$APsp_dest_port"
         }
         node $APsp_dest_node:$APsp_dest_port
         log local0.info "after node command LBserver= [LB::server]"
 }
 when LB_FAILED { 
   log local0.error "Selected server $APsp_dest_node:$APsp_dest_port is not responding" 
   HTTP::respond 404 "Not Found" 
 }
 when SERVER_CONNECTED {
    if {$static::APsp_Debug > 0} {
             log local0.info "serverport: [TCP::server_port]"
         }

 }

Here are the Debug messages:

 Rule /Common/Event_Logger <HTTP_REQUEST>: Client 10.99.99.99:54565 requested http(s)://adm200.company.com/appbuilder/forms?code=8.
 Rule /Common/Event_Logger <HTTP_REQUEST>: Client 10.99.99.99:54565 request DIDN'T match any policy rule.
 Rule /Common/MY_select_port <LB_SELECTED>: LBserver= 10.237.214.28 node=10.237.214.28 port=60200
 Rule /Common/MY_select_port <LB_SELECTED>: after node command LBserver= 10.237.214.28 60200
 Rule /Common/Event_Logger <LB_SELECTED>: Client 10.99.99.99:54565 farwarded to 10.237.214.28 60200 /appbuilder/forms?code=8.
 Rule /Common/Event_Logger <SERVER_CONNECTED>: Client 10.99.99.99:54565 connected from 10.237.214.253:54565 to node 10.237.214.28:443.
 Rule /Common/MY_select_port <SERVER_CONNECTED>: serverport: 443
 Rule /Common/Event_Logger <HTTP_REQUEST_SEND>: Client 10.99.99.99:54565 sending request to 10.237.214.28:443.
 Rule /Common/Event_Logger <HTTP_REQUEST_RELEASE>: Client 10.99.99.99:54565 releasing request to 10.237.214.28:443.
 Rule /Common/Event_Logger <HTTP_RESPONSE>: Client 10.99.99.99:54565 got a response from 10.237.214.28:443.
 Rule /Common/Event_Logger <HTTP_RESPONSE_RELEASE>: Client 10.99.99.99:54565 404 response released from 10.237.214.28:443
 Rule /Common/Event_Logger <SERVER_CLOSED>: Connection from 10.237.214.253:54565 to Server 10.237.214.28:443 has closed.

As you can see, the node command did the correct selection but the server connect went on with port 443.

The pool definition:

   ltm pool /Common/service_pool {
       description 
       load-balancing-mode observed-member
       members {
           /Common/10.237.214.28:0 {
               address 10.237.214.28
           }
           /Common/10.237.214.29:0 {
               address 10.237.214.29
           }
       }
       monitor /Common/gateway_icmp
   }

Thanks in advance. Gil.

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi Gil, LB_SELECTED event is already after the node (and port) selection. Try the following command instead of the "node":

LB::reselect node [LB::server addr] $APsp_dest_port
0
Comments on this Answer
Comment made 1 week ago by gilbs 11

Thanks. the LB::reselect did the trick.

0