# Selecting pool using custom protocol over SSL

**URL:** <https://community.f5.com/t/selecting-pool-using-custom-protocol-over-ssl/34530>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [January 25, 2011, 1:22pm UTC](https://community.f5.com/t/selecting-pool-using-custom-protocol-over-ssl/34530 "2011-01-25T13:22:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Robin\_8](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Stephen\_Robin\_8](https://community.f5.com/u/Stephen_Robin_8)\
**Post date:** [January 25, 2011, 1:22pm UTC](https://community.f5.com/t/selecting-pool-using-custom-protocol-over-ssl/34530/1 "2011-01-25T13:22:39Z")

</div>

Our application uses a custom protocol (NOT HTTP) between clients and servers. We’re investigating using a BIG-IP device to:

(1) Encrypt the traffic between the client and the BIG-IP using SSL.

(2) Select the server that will handle the connection based on the contents of the first packet that is sent after the SSL connection is established.

First I tried selecting a pool without using SSL. This iRule works fine:

```tcl
when CLIENT_ACCEPTED {
  log local0. "Connection accepted from [IP::client_addr]:[TCP::client_port]"
  TCP::collect 10
}

when CLIENT_DATA {
  log local0. "Data received [TCP::payload]"

   We would select the pool here based on the payload.

  pool StephenTest
  TCP::release
}

when SERVER_CONNECTED {
  log local0. "Connection mapped to [serverside {IP::local_addr}]:[serverside {TCP::local_port}]"
}

```

Then I tried encrypting using SSL. I changed my client to use SSL and selected an SSL profile for the virtual server. The new iRule does not work:

```tcl
when CLIENTSSL_HANDSHAKE {
  log local0. "[IP::client_addr]:[TCP::client_port]: SSL handshake completed, collecting SSL payload"
  SSL::collect 10
}

when CLIENTSSL_DATA {
  log local0. "Data received [SSL::payload]"

   We would select the pool here based on the payload.

  pool "StephenTest"
  SSL::release
}

when LB_FAILED {
  log local0. "LB failed"
}

when SERVER_CONNECTED {
  log local0. "Connection mapped to [serverside {IP::local_addr}]:[serverside {TCP::local_port}]"
}

```

No data is received by the server process. The client process authenticates the server but fails when it sends the first packet because the BIG-IP has closed the connection. The log shows the CLIENTSSL\_HANDSHAKE and LB\_FAILED events firing.

If I move the pool statement from the CLIENTSSL\_DATA event to the end of the CLIENTSSL\_HANDSHAKE event then the server process receives the data as expected and the log shows the CLIENTSSL\_HANDSHAKE, CLIENTSSL\_DATA and SERVER\_CONNECTED firing with the expected payload. Obviously, I can’t then select a pool based on the data.

Any help would be greatly appreciated.

Thanks

Stephen

---

<div class="post-metadata">

**Author:** ![Stephen\_Robin\_8](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Stephen\_Robin\_8](https://community.f5.com/u/Stephen_Robin_8)\
**Post date:** [January 25, 2011, 1:53pm UTC](https://community.f5.com/t/selecting-pool-using-custom-protocol-over-ssl/34530/2 "2011-01-25T13:53:51Z")

</div>

Hi Stefan,

Yup, I have a Client Side SSL profile on the Virtual Server so the BIG-IP handles SSL. The first rule does still work when using SSL. However, the CLIENT\_DATA event receives encrypted traffic, not the decrypted SSL payload. I need to route to a particular pool based on the decrypted traffic.

Thanks

Stephen

---

<div class="post-metadata">

**Author:** ![Chris\_Miller](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/chris_miller/32/14702_2.png) [@Chris\_Miller](https://community.f5.com/u/Chris_Miller)\
**Post date:** [January 25, 2011, 2:13pm UTC](https://community.f5.com/t/selecting-pool-using-custom-protocol-over-ssl/34530/3 "2011-01-25T14:13:27Z")

</div>

Is your log statement from CLIENTSSL\_DATA logging anything? Since we’re hitting LB\_FAILED, I’ll assume not?

---

<div class="post-metadata">

**Author:** ![Stephen\_Robin\_8](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Stephen\_Robin\_8](https://community.f5.com/u/Stephen_Robin_8)\
**Post date:** [January 25, 2011, 2:16pm UTC](https://community.f5.com/t/selecting-pool-using-custom-protocol-over-ssl/34530/4 "2011-01-25T14:16:13Z")

</div>

Hi Chris,

No it’s not, the only log messages are from CLIENTSSL\_HANDSHAKE and LB\_FAILED.

Thanks

Stephen

---

<div class="post-metadata">

**Author:** ![Chris\_Miller](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/chris_miller/32/14702_2.png) [@Chris\_Miller](https://community.f5.com/u/Chris_Miller)\
**Post date:** [January 25, 2011, 2:22pm UTC](https://community.f5.com/t/selecting-pool-using-custom-protocol-over-ssl/34530/5 "2011-01-25T14:22:20Z")

</div>

Just looked at the wiki page for pool and it’s not usable from CLIENTSSL\_DATA,

[http://devcentral.f5.com/wiki/default.aspx/iRules/pool.html](http://devcentral.f5.com/wiki/default.aspx/iRules/pool.html)

This might sound ridiculous but I wonder if we can do something from LB\_FAILED here.

From CLIENTSSL\_DATA, perhaps setting a variable to SSL::payload and calling that variable from LB\_FAILED. If I think of something better, I’ll let you know.

---

<div class="post-metadata">

**Author:** ![Stephen\_Robin\_8](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Stephen\_Robin\_8](https://community.f5.com/u/Stephen_Robin_8)\
**Post date:** [January 25, 2011, 3:30pm UTC](https://community.f5.com/t/selecting-pool-using-custom-protocol-over-ssl/34530/6 "2011-01-25T15:30:28Z")

</div>

Thanks Chris. The documentation says that it’s not available from CLIENTSSL\_HANDSHAKE either, but it seems to work.

> **[DevCentral - An F5 Technical Community](https://community.f5.com/)**
>
> DevCentral is an online technical community where engineers and practitioners collaborate, share knowledge, and solve problems related to F5 technologies and industry trends.

I’ve tried from LB\_FAILED too and can’t make it work yet.

---

<div class="post-metadata">

**Author:** ![Colin\_Walker\_12](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@Colin\_Walker\_12](https://community.f5.com/u/Colin_Walker_12)\
**Post date:** [January 25, 2011, 6:09pm UTC](https://community.f5.com/t/selecting-pool-using-custom-protocol-over-ssl/34530/7 "2011-01-25T18:09:05Z")

</div>

What about making use of the LB::reselect command inside the LB\_SELECTED event? Set up a default pool for the VIP and then change your code a little bit:

```tcl
when CLIENTSSL_HANDSHAKE {
  log local0. "[IP::client_addr]:[TCP::client_port]: SSL handshake completed, collecting SSL payload"
  SSL::collect 10
}

when CLIENTSSL_DATA {
  log local0. "Data received [SSL::payload]"

  Store whatever data you need to make an LB decision in local variables here

  SSL::release

}

when LB_SELECTED {
   We would select the pool here based on the local variables you set in the CLIENTSSL_DATA event

  LB::reselect pool "StephenTest"
}

when LB_FAILED {
  log local0. "LB failed"
}

when SERVER_CONNECTED {
  log local0. "Connection mapped to [serverside {IP::local_addr}]:[serverside {TCP::local_port}]"
}

```

This should effectively do the same thing as your original rule, I believe.

Colin

---

<div class="post-metadata">

**Author:** ![spark\_86682](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@spark\_86682](https://community.f5.com/u/spark_86682)\
**Post date:** [January 25, 2011, 7:55pm UTC](https://community.f5.com/t/selecting-pool-using-custom-protocol-over-ssl/34530/8 "2011-01-25T19:55:07Z")

</div>

This really sounds like ID 224958, which is fixed in 10.2.0 HF2. Basically, SSL::collect is (erroneously) not holding up the connection, so a server pick is attempted before CLIENTSSL\_DATA ever fires, and since there’s no pool (since you’re trying to specify one in CLIENTSSL\_DATA), the connection fails. Also, as you’ve found, you can’t just specify a pool earlier, because the server connection will already be established (or be in the process of getting established) by the time CLIENTSSL\_DATA fires. You \*might\* be able to do something like specify a default pool, and then when CLIENTSSL\_DATA fires do an LB::detach and then specify a new pool, but I’d do a lot of testing before putting that sort of a solution into production. Your best bet is to just upgrade. Hope this helps!

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [January 25, 2011, 8:01pm UTC](https://community.f5.com/t/selecting-pool-using-custom-protocol-over-ssl/34530/9 "2011-01-25T20:01:21Z")

</div>

It looks like ID 224958 is also fixed in 10.2.1:

> **[404 Page not found | BIG-IP Documentation](https://techdocs.f5.com/kb/en-us/products/big-ip%5C_ltm/releasenotes/product/relnote%5C_10%5C_2%5C_1%5C_ltm.html)**
>
> Usage information and technical documentation for BIG-IP and other related F5 products

Unconfigured pool or profile and CLIENTSSL\_DATA (ID 224958)

The CLIENTSSL\_DATA event now fires correctly regardless of whether or not a pool or profile is configured.

Aaron
