Load Balancing based off TCP Payload entity

Hello,

I believe I constructed an irule to properly a variable from text captured from two distinct points in the TCP Payload but I am not 100% certain the Irule will is persisting off this entity. can someone take a look below and see if this looks correct? I added the message load balancing profile on as well.

The expectations are tat after collecting tcp payload for a new connection search for a string and then persists that string to a certain pool ( contains 2 servers). all subsequent matches for that same string in payload need to go to that pool. I also want the pool to load balance diverse entities so not everything is on the same pool member. Does this look correct ?

when CLIENT_ACCEPTED {
  TCP::collect 
}

when CLIENT_DATA {
   set payload [TCP::payload]
   set entityID [findstr $payload "@"  1 ","]
   log local0. "$entityID: $entityID"
   pool XYZ
   persist uie $entityID
   log local4.info " Entity Session routing $entityID and setting persistence"
      TCP::release
      TCP::notify request
}

A few thoughts:

  1. It looks like the iRule should work as it is. Are you seeing different or just questioning if it could fail?

  2. Unless you’re specifically doing mblb, I don’t think you need the TCP::notify. TCP load balancing is by default session-based, so all traffic within a single TCP session will stick to the same node after an initial decision. I threw in some additional logging to show what the persistence record actually points to per TCP session.

    when CLIENT_ACCEPTED {
        TCP::collect
    }
    when CLIENT_DATA {
        set entityID [findstr [TCP::payload] "User-Agent: " 12 " "]
        log local0. "entityID = $entityID"
    
        persist uie $entityID
        log local0. "using persistence for entityId ($entityID): [persist lookup uie $entityID]"
    
        TCP::release
    }
    

Are you 100% sure there will always be an '@" in the first stream of data sent by the client?

Yes after the intial SSL handshake the first TCP payload will contain the entity and it will be after the “@” sign and before the “,”

I think what Giltjr is asking is if the entityID value will be in every TCP packet? Load balancing persistence is (TCP) session-based. Beyond that you need some pervasive mechanism to maintain that persistence across multiple TCP sessions. The client must pass some unique and persistent value in every new TCP session for this to work.

the entity ID will only be available in the first few TCP packets then it will no longer appear.

That could potentially be a problem. You’ll need some piece of information from the client in each new TCP session after the initial load balancing decision to maintain that persistence. Is this a protocol that maintains one long TCP session, or is it like HTTP and can have multiple TCP sessions over the life of the application session?

If the latter, is there anything else unique about the client that can be used, or is supported by the client for persistence? Is source address an option?

First, just add a log local0. [TCP::payload] statement in your CLIENT_DATA event. I’m also guessing from this output that the collected data isn’t text, and more important, there’s more than one TCP session. Before going any further, add that additional log statement and see what the payload actually looks like.

i think if one client-side connection has multiple id (one id per packet), you need LB::detach or mblb.

also if there is multiple id per packet, i think you have to use mblb.

this is mblb example.

config

root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
ltm virtual bar {
    destination 172.28.24.10:7
    ip-protocol tcp
    mask 255.255.255.255
    pool foo
    profiles {
        mblb { }
        tcp { }
    }
    rules {
        qux
    }
    source 0.0.0.0/0
    source-address-translation {
        type automap
    }
    vs-index 47
}
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo
ltm pool foo {
    members {
        200.200.200.101:7 {
            address 200.200.200.101
        }
        200.200.200.111:7 {
            address 200.200.200.111
        }
    }
}
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
ltm rule qux {
    when CLIENT_ACCEPTED {
  log local0. ""
  TCP::collect
}
when CLIENT_DATA {
  log local0. ""
  set id [findstr [TCP::payload] @ 1 ,]
  persist uie $id
  TCP::release
  TCP::notify eom
  TCP::collect
}
when SERVER_CONNECTED {
  log local0. ""
  TCP::collect
}
when SERVER_DATA {
  log local0. "id=$id server=[IP::server_addr]:[TCP::server_port]"
  TCP::release
  TCP::notify eom
  TCP::collect
}
}

 persistence

root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) show ltm persistence persist-records
Sys::Persistent Connections
universal  3  172.28.24.10:7  200.200.200.111:7  (tmm: 1)
universal  1  172.28.24.10:7  200.200.200.111:7  (tmm: 1)
universal  2  172.28.24.10:7  200.200.200.101:7  (tmm: 1)
Total records returned: 3

 /var/log/ltm

[root@ve11a:Active:In Sync] config  tail -f /var/log/ltm
Jul  6 00:15:25 ve11a info tmm1[29362]: Rule /Common/qux :
Jul  6 00:15:26 ve11a info tmm1[29362]: Rule /Common/qux :
Jul  6 00:15:26 ve11a info tmm1[29362]: Rule /Common/qux :
Jul  6 00:15:26 ve11a info tmm1[29362]: Rule /Common/qux : id=1 server=200.200.200.111:7
Jul  6 00:15:30 ve11a info tmm1[29362]: Rule /Common/qux :
Jul  6 00:15:30 ve11a info tmm1[29362]: Rule /Common/qux :
Jul  6 00:15:30 ve11a info tmm1[29362]: Rule /Common/qux : id=2 server=200.200.200.101:7
Jul  6 00:15:33 ve11a info tmm1[29362]: Rule /Common/qux :
Jul  6 00:15:33 ve11a info tmm1[29362]: Rule /Common/qux : id=1 server=200.200.200.111:7
Jul  6 00:15:36 ve11a info tmm1[29362]: Rule /Common/qux :
Jul  6 00:15:36 ve11a info tmm1[29362]: Rule /Common/qux : id=1 server=200.200.200.111:7
Jul  6 00:15:38 ve11a info tmm1[29362]: Rule /Common/qux :
Jul  6 00:15:38 ve11a info tmm1[29362]: Rule /Common/qux : id=2 server=200.200.200.101:7
Jul  6 00:15:43 ve11a info tmm1[29362]: Rule /Common/qux :
Jul  6 00:15:43 ve11a info tmm1[29362]: Rule /Common/qux : id=3 server=200.200.200.111:7

this is LB::detach example.

config

root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
ltm virtual bar {
    destination 172.28.24.10:7
    ip-protocol tcp
    mask 255.255.255.255
    pool foo
    profiles {
        tcp { }
    }
    rules {
        qux
    }
    source 0.0.0.0/0
    source-address-translation {
        type automap
    }
    vs-index 47
}
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo
ltm pool foo {
    members {
        200.200.200.101:7 {
            address 200.200.200.101
        }
        200.200.200.111:7 {
            address 200.200.200.111
        }
    }
}
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
ltm rule qux {
    when CLIENT_ACCEPTED {
  log local0. ""
  TCP::collect
}
when CLIENT_DATA {
  log local0. ""
  set id [findstr [TCP::payload] @ 1 ,]
  persist uie $id
  TCP::release
  TCP::collect
}
when SERVER_CONNECTED {
  log local0. ""
  TCP::collect
}
when SERVER_DATA {
  log local0. "id=$id server=[IP::server_addr]:[TCP::server_port]"
  TCP::release
  LB::detach
  TCP::collect
}
}

 persistence

root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) show ltm persistence persist-records
Sys::Persistent Connections
universal  3  172.28.24.10:7  200.200.200.111:7  (tmm: 1)
universal  1  172.28.24.10:7  200.200.200.111:7  (tmm: 1)
universal  2  172.28.24.10:7  200.200.200.101:7  (tmm: 1)
Total records returned: 3

 /var/log/ltm
[root@ve11a:Active:In Sync] config  tail -f /var/log/ltm
Jul  6 00:23:32 ve11a info tmm[29362]: Rule /Common/qux :
Jul  6 00:23:34 ve11a info tmm[29362]: Rule /Common/qux :
Jul  6 00:23:34 ve11a info tmm[29362]: Rule /Common/qux :
Jul  6 00:23:34 ve11a info tmm[29362]: Rule /Common/qux : id=1 server=200.200.200.111:7
Jul  6 00:23:36 ve11a info tmm[29362]: Rule /Common/qux :
Jul  6 00:23:36 ve11a info tmm[29362]: Rule /Common/qux :
Jul  6 00:23:36 ve11a info tmm[29362]: Rule /Common/qux : id=2 server=200.200.200.101:7
Jul  6 00:23:38 ve11a info tmm[29362]: Rule /Common/qux :
Jul  6 00:23:38 ve11a info tmm[29362]: Rule /Common/qux :
Jul  6 00:23:38 ve11a info tmm[29362]: Rule /Common/qux : id=1 server=200.200.200.111:7
Jul  6 00:23:40 ve11a info tmm[29362]: Rule /Common/qux :
Jul  6 00:23:40 ve11a info tmm[29362]: Rule /Common/qux :
Jul  6 00:23:40 ve11a info tmm[29362]: Rule /Common/qux : id=1 server=200.200.200.111:7
Jul  6 00:23:43 ve11a info tmm[29362]: Rule /Common/qux :
Jul  6 00:23:43 ve11a info tmm[29362]: Rule /Common/qux :
Jul  6 00:23:43 ve11a info tmm[29362]: Rule /Common/qux : id=2 server=200.200.200.101:7
Jul  6 00:23:44 ve11a info tmm[29362]: Rule /Common/qux :
Jul  6 00:23:45 ve11a info tmm[29362]: Rule /Common/qux :
Jul  6 00:23:45 ve11a info tmm[29362]: Rule /Common/qux : id=3 server=200.200.200.111:7

Thanks Kevin & Nitass. let me try this and post back when I have some better results.

I added the log statement as recommended and also added MBLB profile as well. still the output from the ltm logs shows garbled. I am including the TCP payload from the packet capture as this data s text based and there is no reason the ltm should show garbled text. Here is the first push-ack from the GUI to the LTM after the 3 way handshake. the string I need to load balance is right there.

ltm virtual test1 {
    destination 5.5.5.5:https
    ip-protocol tcp
    mask 255.255.255.255
    pool test_Pool
    profiles {
        SSL_GUI {
            context clientside
        }
        RT_TCP { }
        mblb { }
    }
    rules {
        Test_Irule
    }
    source 0.0.0.0/0
    source-address-translation {
        pool snat_pool
        type snat
    }
    vlans {
        test_vlan
    }
    vlans-enabled
    vs-index 2199
}

just to be safe i tried viewing the log output from a different ssh client. both ssh tectia and Putty show slightly different formats of the payload. I am wondering if the LTM is simply not formatting the output correctly but is actually parsing correctly ?

SSH Tectia Client:

Jul 7 18:08:43 info tmm1[13133]: Rule /Common/Entity_Irule : o:t=)¾Ã¯c^¬ö|¤£ Jul 7 18:08:43 1 info tmm1[13133]: Rule /Common/Entity_Irule : À¾ÀÀºS»kWgâ ¬Â[ûÀÀ8à ÃÀ5ÃÃÀ9À8à ÃÀ/ÃÃÀ3À2ÃÃÀÃà ÃÀ Ãà ÀÀÀÀÿÀÀYÀ À4À2ÀÀÀÀÀÀÀÀ À ÀÀ À ÀÀ ÀÀÀÀÀÀÀÀÀÀÀ ÀÀÀÀÀÀÀÀqems.qa2.fxall.com Jul 7 18:08:48 1 info tmm5[13134]: Rule /Common/Entity_Irule : ÀÃÀÀÃS»pÃYÃJÃà ëþ·Â·Dü,K\¥µXmÂN «lì?oøáÃ}Iì)ELÃBõo à 1ÂYC$¿ÃÀ8à ÃÀ5ÃÃÀ9À8à ÃÀ/ÃÃÀ3À2ÃÃÀÃà ÃÀ Ãà ÀÀÀÀÿÀÀYÀ À4À2ÀÀÀÀÀÀÀÀ À ÀÀ À ÀÀ ÀÀÀÀÀÀÀÀÀÀÀ ÀÀÀÀÀÀÀÀqems.qa2.fxall.com Jul 7 18:08:48 info tmm5[13134]: Rule /Common/Entity_Irule : Jul 7 18:08:48 debug tmm5[13134]: Rule /Common/Entity_Irule : Entity Session routing and setting persistence ^[[?1;2cVT102VT102VT102^[[?1;2cVT102VT102VT102

Putty SSH Client Jul 7 17:46:22 info tmm7[13134]: Rule /Common/Entity_Irule : ▒Þ▒▒ÚS».a÷�sZ»®Õ÷J "°8vÉ�Þ�Âä� � «lì?oÀ�Ü}Iì)@Lèã�àXhÉ<1�YC$¿�▒8À À▒5ÀÀ▒9▒8À À▒/ÀÀ▒3▒2ÀÀ▒ÀÀ À▒ ÀÀ ▒▒▒▒ÿ▒▒Y▒ ▒4▒2▒▒▒▒▒▒▒▒ ▒ ▒▒ ▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒xxx.yyy.com

Jul 7 18:08:48 info tmm5[13134]: Rule /Common/Entity_Irule : ▒Þ▒▒ÚS»pÑYÉJßÄÏ«Ûþ·�·DÙ¼,K\¥µXm��N «lì?oÁ¸áÜ}Iì)ELßBõo� à1�YC$¿Ö▒8À À▒5ÀÀ▒9▒8À À▒/ÀÀ▒3▒2ÀÀ▒ÀÀ À▒ ÀÀ ▒▒▒▒ÿ▒▒Y▒ ▒4▒2▒▒▒▒▒▒▒▒ ▒ ▒▒ ▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒xxx.yyy.com

Jul 7 18:08:48 debug tmm5[13134]: Rule /Common/Entity_Irule : Entity Session routing and setting persistence PuTTYPuTTYPuTTY

Ahhhh. I may have missed this earlier, but I see you’re using a client SSL profile, which explains why the TCP data is garbled. TCP is OSI layer 4, but SSL offload doesn’t happen until layer 6. You can generally replace the TCP:: commands with SSL:: commands and accomplish the same thing (but after decryption). Take a look at the SSL::collect wiki page for an example.

Let me give that a go, will keep everyone posted.

I made some good progess with the SSL irule and now the entity is correctly parsed out, but i think im missing something still as the connection never truly completes.

Here is the current irule:

when CLIENTSSL_HANDSHAKE {
   log local0. "[IP::client_addr]:[TCP::client_port]: SSL handshake completed, collecting SSL payload"
   SSL::collect
}
when CLIENTSSL_DATA {
   set payload [SSL::payload]
   set entityID [findstr $payload "@" 1 ","]
   log local0. "$entityID: $entityID"
   pool xxx_yyyy_Pool
   log local0. "blha Entity Session routing $entityID and setting persistence"
   persist uie $entityID 64000
   SSL::release
   }

Here are the log output when logging in: (at times I commented out the persist line since it throws tcl errors below)

Jul 8 17:57:56 va-bigip01 info tmm2[13133]: Rule /Common/x_Entity_Irule : 10.65.59.202:56070: SSL handshake completed, collecting SSL payload Jul 8 17:57:56 va-bigip01 info tmm2[13133]: Rule /Common/x_Entity_Irule : QA-xxx-CUST1: QA-xxx-CUST1 Jul 8 17:57:56 va-bigip01 info tmm2[13133]: Rule /Common/x_Entity_Irule : x Entity Session routing QA-xxx-CUST1 and setting persistence Jul 8 17:58:01 va-bigip01 info tmm7[13134]: Rule /Common/x_Entity_Irule : 10.65.59.202:56074: SSL handshake completed, collecting SSL payload Jul 8 17:58:01 va-bigip01 info tmm7[13134]: Rule /Common/x_Entity_Irule : : Jul 8 17:58:01 va-bigip01 info tmm7[13134]: Rule /Common/xEntity_Irule : x Entity Session routing and setting persistence Jul 8 18:04:22 va-bigip01 info tmm5[13134]: Rule /Common/x_Entity_Irule : 10.65.59.202:53658: SSL handshake completed, collecting SSL payload Jul 8 18:04:22 va-bigip01 info tmm5[13134]: Rule /Common/x_Entity_Irule : QA-xxx-PROV1: QA-xxx-PROV1 Jul 8 18:04:22 va-bigip01 info tmm5[13134]: Rule /Common/x_Entity_Irule : x Entity Session routing QA-xxx-PROV1 and setting persistence Jul 8 18:04:26 va-bigip01 info tmm4[13134]: Rule /Common/x_Entity_Irule : 10.65.59.202:53668: SSL handshake completed, collecting SSL payload Jul 8 18:04:26 va-bigip01 info tmm4[13134]: Rule /Common/x_Entity_Irule : : Jul 8 18:04:26 va-bigip01 info tmm4[13134]: Rule /Common/x_Entity_Irule : x Entity Session routing and setting persistence Jul 8 18:04:26 va-bigip01 err tmm4[13134]: 01220001:3: TCL error: /Common/x_Entity_Irule - attempt to use empty persistence key (line 1) invoked from within “persist uie $entityID 64000”

I also noticed the unviersal persistence when set doesn’t seem to send the next entity to the next pool member even though the connection is not completing. in the output below I expect that all future uses matching CUST2 stay on 10.36.35:9820 but entity PROV1 be put on the other pool member 10.36.6.35:9820 not shown here

@(bigip01)(cfg-sync Changes Pending)(Active)(/Common)(tmos) show ltm persistence persist-records | grep universal universal QA-xxx-PROV1 10.195.127.9:443 10.36.6.35:9820 (tmm: 5) universal QA-xxx-CUST2 10.195.127.9:443 10.36.6.35:9820 (tmm: 2)

Okay, so given the log data (cleaned up for viewing):

10.65.59.202:56070: SSL handshake completed, collecting SSL payload 
QA-xxx-CUST1: QA-xxx-CUST1 
x Entity Session routing QA-xxx-CUST1 and setting persistence 
10.65.59.202:56074: SSL handshake completed, collecting SSL payload 
: 
x Entity Session routing and setting persistence 
10.65.59.202:53658: SSL handshake completed, collecting SSL payload 
QA-xxx-PROV1: QA-xxx-PROV1 
x Entity Session routing QA-xxx-PROV1 and setting persistence 
10.65.59.202:53668: SSL handshake completed, collecting SSL payload 
: 
x Entity Session routing and setting persistence 
TCL error: /Common/x_Entity_Irule - attempt to use empty persistence key (line 1) invoked from within "persist uie $entityID 64000"

Two things are evident:

  1. Every other TCP session is missing the entityID data in the payload. The source port is different each time, so is this a single client interaction, or are you testing repeatedly?
  2. You should probably check that the $entityID variable has something in it before attempting to use it for persistence

It may be more helpful at this point to spin up Wireshark to observe these interactions through a native connection (without LTM SSL offload). You can configure it to decrypt the SSL payload by inserting the private key into the RSA list of the SSL configuration. At a minimum you want to verify that the entityID is indeed in every request packet.

Hello Kevin

I ran a few GUI logins at the same time. I have a saved capture so let me pull that one up and ensure the entity is in each packet from the GUI.

OK i pulled the packets and see the following:

after initial 3 way handshake the GUI does send the entity ID as indicated by the logging result. subsequent packets from the GU are small 64 byte len and contain no readable payload until a few seconds later where the GUI send HB events that contain the entity ID. during this time the F5 is sending to the GUI all different data related to the application.

i guess what I am looking for is a way to persist the connection once the entityID is parsed and identified and stop collecting right after that point?

the entityID does have the string I need in it. right after we set the variable and log it i have a LB decision to be made but never see it complete, so i think its keeps collecting further and thats why it shows up emtpy the next time around.