Skip to content

Commit 28b7e0a

Browse files
randallzwoop
authored andcommitted
rate_limit: convert to using TSVConnSslSniGet (#8414)
(cherry picked from commit a62541f)
1 parent 4f505bd commit 28b7e0a

5 files changed

Lines changed: 3 additions & 60 deletions

File tree

plugins/experimental/rate_limit/rate_limit.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
#include "txn_limiter.h"
2626
#include "utilities.h"
2727

28-
// Needs special OpenSSL APIs as a global plugin for early CLIENT_HELLO inspection
29-
#if TS_USE_HELLO_CB
30-
3128
#include "sni_selector.h"
3229
#include "sni_limiter.h"
3330

@@ -84,8 +81,6 @@ TSPluginInit(int argc, const char *argv[])
8481
}
8582
}
8683

87-
#endif
88-
8984
///////////////////////////////////////////////////////////////////////////////
9085
// Setup stuff for the remap plugin
9186
//

plugins/experimental/rate_limit/sni_limiter.cc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
*/
1818
#include "tscore/ink_config.h"
1919

20-
// Needs special OpenSSL APIs as a global plugin for early CLIENT_HELLO inspection
21-
#if TS_USE_HELLO_CB
22-
2320
#include <unistd.h>
2421
#include <getopt.h>
2522
#include <cstdlib>
@@ -43,9 +40,9 @@ sni_limit_cont(TSCont contp, TSEvent event, void *edata)
4340

4441
switch (event) {
4542
case TS_EVENT_SSL_CLIENT_HELLO: {
46-
TSSslConnection ssl_conn = TSVConnSslConnectionGet(vc);
47-
SSL *ssl = reinterpret_cast<SSL *>(ssl_conn);
48-
std::string_view sni_name = getSNI(ssl);
43+
int len;
44+
const char *server_name = TSVConnSslSniGet(vc, &len);
45+
std::string_view sni_name(server_name, len);
4946

5047
if (!sni_name.empty()) { // This should likely always succeed, but without it we can't do anything
5148
SniRateLimiter *limiter = selector->find(sni_name);
@@ -128,5 +125,3 @@ SniRateLimiter::initialize(int argc, const char *argv[])
128125

129126
return true;
130127
}
131-
132-
#endif

plugins/experimental/rate_limit/sni_selector.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
*/
1818
#include "tscore/ink_config.h"
1919

20-
// Needs special OpenSSL APIs as a global plugin for early CLIENT_HELLO inspection
21-
#if TS_USE_HELLO_CB
22-
2320
#include <cstring>
2421

2522
#include "sni_limiter.h"
@@ -136,5 +133,3 @@ SniSelector::setupQueueCont()
136133
_action = TSContScheduleEveryOnPool(_queue_cont, QUEUE_DELAY_TIME.count(), TS_THREAD_POOL_TASK);
137134
}
138135
}
139-
140-
#endif

plugins/experimental/rate_limit/utilities.cc

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,6 @@
2121
#include "ts/remap.h"
2222
#include "utilities.h"
2323

24-
// Needs special OpenSSL APIs as a global plugin for early CLIENT_HELLO inspection
25-
#if TS_USE_HELLO_CB
26-
27-
std::string_view
28-
getSNI(SSL *ssl)
29-
{
30-
const char *servername = nullptr;
31-
const unsigned char *p;
32-
size_t remaining, len = 0;
33-
34-
// Parse the server name if the get extension call succeeds and there are more than 2 bytes to parse
35-
if (SSL_client_hello_get0_ext(ssl, TLSEXT_TYPE_server_name, &p, &remaining) && remaining > 2) {
36-
// Parse to get to the name, originally from test/handshake_helper.c in openssl tree
37-
/* Extract the length of the supplied list of names. */
38-
len = *(p++) << 8;
39-
len += *(p++);
40-
if (len + 2 == remaining) {
41-
remaining = len;
42-
/*
43-
* The list in practice only has a single element, so we only consider
44-
* the first one.
45-
*/
46-
if (*p++ == TLSEXT_NAMETYPE_host_name) {
47-
remaining--;
48-
/* Now we can finally pull out the byte array with the actual hostname. */
49-
if (remaining > 2) {
50-
len = *(p++) << 8;
51-
len += *(p++);
52-
if (len + 2 <= remaining) {
53-
servername = reinterpret_cast<const char *>(p);
54-
}
55-
}
56-
}
57-
}
58-
}
59-
60-
return std::string_view(servername, servername ? len : 0);
61-
}
62-
63-
#endif
64-
6524
///////////////////////////////////////////////////////////////////////////////
6625
// Add a header with the delay imposed on this transaction. This can be used
6726
// for logging, and other types of metrics.

plugins/experimental/rate_limit/utilities.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@
2424

2525
constexpr char const PLUGIN_NAME[] = "rate_limit";
2626

27-
std::string_view getSNI(SSL *ssl);
2827
void delayHeader(TSHttpTxn txnp, std::string &header, std::chrono::milliseconds delay);
2928
void retryAfter(TSHttpTxn txnp, unsigned retry);

0 commit comments

Comments
 (0)