You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2023/03/07 16:55:11 UTC

[trafficserver] branch 9.2.x updated: Properly support multiple instantiation in plugins.config (#9494)

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/9.2.x by this push:
     new ab60eb050 Properly support multiple instantiation in plugins.config (#9494)
ab60eb050 is described below

commit ab60eb0501b1e14104959ae6210157ce9862ea8c
Author: Leif Hedstrom <zw...@apache.org>
AuthorDate: Tue Mar 7 09:54:44 2023 -0700

    Properly support multiple instantiation in plugins.config (#9494)
    
    (cherry picked from commit 051fa9d37738ae56f71e7ac0c36be66fdfd5ac54)
---
 plugins/experimental/rate_limit/rate_limit.cc   | 25 +++++++++++++++----------
 plugins/experimental/rate_limit/sni_selector.cc |  2 +-
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/plugins/experimental/rate_limit/rate_limit.cc b/plugins/experimental/rate_limit/rate_limit.cc
index a3c94d094..7dc8ab3db 100644
--- a/plugins/experimental/rate_limit/rate_limit.cc
+++ b/plugins/experimental/rate_limit/rate_limit.cc
@@ -32,6 +32,7 @@
 // As a global plugin, things works a little different since we don't setup
 // per transaction or via remap.config.
 extern int gVCIdx;
+SniSelector *gSNISelector = nullptr;
 
 void
 TSPluginInit(int argc, const char *argv[])
@@ -47,27 +48,31 @@ TSPluginInit(int argc, const char *argv[])
     return;
   }
 
-  TSUserArgIndexReserve(TS_USER_ARGS_VCONN, PLUGIN_NAME, "VConn state information", &gVCIdx);
+  if (-1 == gVCIdx) {
+    TSUserArgIndexReserve(TS_USER_ARGS_VCONN, PLUGIN_NAME, "VConn state information", &gVCIdx);
+  }
 
   if (argc > 1) {
     if (!strncasecmp(argv[1], "SNI=", 4)) {
-      TSCont sni_cont       = TSContCreate(sni_limit_cont, nullptr);
-      SniSelector *selector = new SniSelector();
+      if (gSNISelector == nullptr) {
+        TSCont sni_cont = TSContCreate(sni_limit_cont, nullptr);
+        gSNISelector    = new SniSelector();
+
+        TSReleaseAssert(sni_cont);
+        TSContDataSet(sni_cont, gSNISelector);
 
-      TSReleaseAssert(sni_cont);
-      TSContDataSet(sni_cont, selector);
+        TSHttpHookAdd(TS_SSL_CLIENT_HELLO_HOOK, sni_cont);
+        TSHttpHookAdd(TS_VCONN_CLOSE_HOOK, sni_cont);
+      }
 
       // Have to skip the first one, which is considered the 'program' name
       --argc;
       ++argv;
 
-      size_t num_sni = selector->factory(argv[0] + 4, argc, argv);
+      size_t num_sni = gSNISelector->factory(argv[0] + 4, argc, argv);
       TSDebug(PLUGIN_NAME, "Finished loading %zu SNIs", num_sni);
 
-      TSHttpHookAdd(TS_SSL_CLIENT_HELLO_HOOK, sni_cont);
-      TSHttpHookAdd(TS_VCONN_CLOSE_HOOK, sni_cont);
-
-      selector->setupQueueCont(); // Start the queue processing continuation
+      gSNISelector->setupQueueCont(); // Start the queue processing continuation if needed
     } else if (!strncasecmp(argv[1], "HOST=", 5)) {
       // TODO: Do we need to implement this ?? Or can we just defer this to the remap version?
       --argc; // Skip the "HOST" arg of course when parsing the real parameters
diff --git a/plugins/experimental/rate_limit/sni_selector.cc b/plugins/experimental/rate_limit/sni_selector.cc
index e4c22d02d..d87ee8ceb 100644
--- a/plugins/experimental/rate_limit/sni_selector.cc
+++ b/plugins/experimental/rate_limit/sni_selector.cc
@@ -135,7 +135,7 @@ SniSelector::factory(const char *sni_list, int argc, const char *argv[])
 void
 SniSelector::setupQueueCont()
 {
-  if (_needs_queue_cont) {
+  if (_needs_queue_cont && !_queue_cont) {
     _queue_cont = TSContCreate(sni_queue_cont, TSMutexCreate());
     TSReleaseAssert(_queue_cont);
     TSContDataSet(_queue_cont, this);