Skip to content

Commit e5413cf

Browse files
committed
Add a per client connection max exempt list cript
This updates our build system to be able to make pre-compiled cripts. Thus, adding a cript is now as easy as adding a plugin. Simply use add_cript instead of add_atsplugin in CMakeLists.txt, and it will build your cript for you. As a part of this, this adds connection_exempt_list.cript, our first cript plugin that sets the per client exempt list.
1 parent 960350e commit e5413cf

File tree

22 files changed

+368
-19
lines changed

22 files changed

+368
-19
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ rc/trafficserver.service
170170
.libs/
171171

172172
.svn/
173-
.vscode/
174173
target
175174

176175
tsxs

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"files.associations": {
3+
"*.cript": "cpp",
4+
"*.test.py": "python",
5+
"*.test.ext": "python"
6+
}
7+
}

cmake/ExperimentalPlugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ auto_option(ACCESS_CONTROL FEATURE_VAR BUILD_ACCESS_CONTROL DEFAULT ${_DEFAULT})
3131
auto_option(BLOCK_ERRORS FEATURE_VAR BUILD_BLOCK_ERRORS DEFAULT ${_DEFAULT})
3232
auto_option(CACHE_FILL FEATURE_VAR BUILD_CACHE_FILL DEFAULT ${_DEFAULT})
3333
auto_option(CERT_REPORTING_TOOL FEATURE_VAR BUILD_CERT_REPORTING_TOOL DEFAULT ${_DEFAULT})
34+
auto_option(CONNECTION_EXEMPT_LIST FEATURE_VAR BUILD_CONNECTION_EXEMPT_LIST DEFAULT ${_DEFAULT})
3435
auto_option(COOKIE_REMAP FEATURE_VAR BUILD_COOKIE_REMAP DEFAULT ${_DEFAULT})
3536
auto_option(CUSTOM_REDIRECT FEATURE_VAR BUILD_CUSTOM_REDIRECT DEFAULT ${_DEFAULT})
3637
auto_option(FQ_PACING FEATURE_VAR BUILD_FQ_PACING DEFAULT ${_DEFAULT})

cmake/add_cript.cmake

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#######################
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor license
4+
# agreements. See the NOTICE file distributed with this work for additional information regarding
5+
# copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software distributed under the License
12+
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13+
# or implied. See the License for the specific language governing permissions and limitations under
14+
# the License.
15+
#
16+
#######################
17+
18+
# Function to build pre-compiled cript scripts
19+
function(add_cript name source_file)
20+
# Check if ENABLE_CRIPTS is ON, if not, skip
21+
if(NOT ENABLE_CRIPTS)
22+
message(STATUS "Skipping cript ${name} - ENABLE_CRIPTS is OFF")
23+
return()
24+
endif()
25+
26+
# Use the standard ATS plugin macro and link with cripts
27+
add_atsplugin(${name} ${source_file})
28+
target_link_libraries(${name} PRIVATE ts::cripts)
29+
30+
# Tell CMake that .cript files are C++ files
31+
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE CXX)
32+
set_source_files_properties(${source_file} PROPERTIES LANGUAGE CXX)
33+
34+
verify_remap_plugin(${name})
35+
endfunction()

doc/Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ INPUT_ENCODING = UTF-8
768768
# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf,
769769
# *.qsf, *.as and *.js.
770770

771-
FILE_PATTERNS = *.c *.cc *.h *.h.in *.i
771+
FILE_PATTERNS = *.c *.cc *.h *.h.in *.i *.cript
772772

773773
# The RECURSIVE tag can be used to specify whether or not subdirectories should
774774
# be searched for input files as well.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
.. include:: ../../common.defs
2+
3+
.. _admin-plugins-connection-exempt-list:
4+
5+
Connection Exempt List Plugin
6+
******************************
7+
8+
.. Licensed to the Apache Software Foundation (ASF) under one
9+
or more contributor license agreements. See the NOTICE file
10+
distributed with this work for additional information
11+
regarding copyright ownership. The ASF licenses this file
12+
to you under the Apache License, Version 2.0 (the
13+
"License"); you may not use this file except in compliance
14+
with the License. You may obtain a copy of the License at
15+
16+
http://www.apache.org/licenses/LICENSE-2.0
17+
18+
Unless required by applicable law or agreed to in writing,
19+
software distributed under the License is distributed on an
20+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21+
KIND, either express or implied. See the License for the
22+
specific language governing permissions and limitations
23+
under the License.
24+
25+
Description
26+
===========
27+
28+
:ts:cv:`proxy.config.http.per_client.connection.exempt_list` allows
29+
administrators to set exemptions to the per-client connection limit. However,
30+
for large networks, managing this as a comma-separated string in
31+
:file:`records.yaml` can be cumbersome. This plugin allows administrators to set
32+
the exemption list :ts:cv:`proxy.config.http.per_client.connection.exempt_list`
33+
value via an external YAML file.
34+
35+
Plugin Configuration
36+
====================
37+
38+
The plugin is configured as a global plugin and requires a path to a YAML
39+
configuration file. Load the plugin by adding a line to the
40+
:file:`plugin.config`:
41+
42+
.. code-block:: text
43+
44+
connection_exempt_list.so /path/to/exempt_list.yaml
45+
46+
Configuration File Format
47+
==========================
48+
49+
The exempt list configuration file must be in YAML format with the following
50+
simple structure:
51+
52+
.. code-block:: yaml
53+
54+
exempt_list:
55+
- 127.0.0.1
56+
- ::1
57+
- 192.168.1.0/24
58+
- 10.0.0.0/8
59+
60+
The configuration file supports the same range formats as
61+
:ts:cv:`proxy.config.http.per_client.connection.exempt_list`.
62+
63+
* Individual IPv4 addresses (e.g., ``192.168.1.100``)
64+
* Individual IPv6 addresses (e.g., ``::1``, ``2001:db8::1``)
65+
* IPv4 CIDR ranges (e.g., ``192.168.0.0/16``)
66+
* Ranges as a dash-separated string (e.g., ``10.0.0.0-10.0.0.255``)
67+
68+
Example Usage
69+
=============
70+
71+
1. Create an exempt list configuration file (e.g.,
72+
``/opt/ats/etc/trafficserver/exempt_localhost.yaml``):
73+
74+
.. code-block:: yaml
75+
76+
exempt_list:
77+
- 127.0.0.1
78+
- ::1
79+
80+
2. Enable the plugin in :file:`plugin.config`:
81+
82+
.. code-block:: text
83+
84+
connection_exempt_list.so /opt/ats/etc/trafficserver/exempt_localhost.yaml
85+
86+
3. Configure per-client connection limits in :file:`records.yaml`:
87+
88+
.. code-block:: yaml
89+
90+
records:
91+
net:
92+
per_client:
93+
max_connections_in: 300
94+
95+
4. Start |TS|. The plugin will load the exempt list and not apply the per-client
96+
connection limit to the exempted IP addresses and ranges.
97+
98+
See Also
99+
========
100+
101+
* :ts:cv:`proxy.config.net.per_client.max_connections_in`
102+
* :ts:cv:`proxy.config.http.per_client.connection.exempt_list`
103+
* :doc:`../files/plugin.config.en`

doc/admin-guide/plugins/index.en.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ directory of the |TS| source tree. Experimental plugins can be compiled by passi
171171
Cache Fill <cache_fill.en>
172172
Certifier <certifier.en>
173173
Cert Reporting Tool <cert_reporting_tool.en>
174+
Connection Exempt List <connection_exempt_list.en>
174175
Cookie Remap <cookie_remap.en>
175176
GeoIP ACL <geoip_acl.en>
176177
FQ Pacing <fq_pacing.en>
@@ -208,6 +209,10 @@ directory of the |TS| source tree. Experimental plugins can be compiled by passi
208209
:doc:`Cert Reporting Tool <cert_reporting_tool.en>`
209210
Examines and logs information on loaded certificates.
210211

212+
:doc:`Connection Exempt List <connection_exempt_list.en>`
213+
Provides a way for administrators to set
214+
:ts:cv:`proxy.config.http.per_client.connection.exempt_list` via a YAML file.
215+
211216
:doc:`Cookie Remap <cookie_remap.en>`
212217
Makes decisions on destinations based on cookies.
213218

include/cripts/Epilogue.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,10 +752,12 @@ TSPluginInit(int argc, const char *argv[])
752752
inst->NeedCallback(enabled_txn_hooks);
753753
TSContDataSet(contp, context);
754754
TSHttpHookAdd(TS_HTTP_TXN_START_HOOK, contp); // This acts similarly to the DoRemap callback
755+
} else if (needs_glb_init) {
756+
CDebug("[%s] - No global hooks, but there is a global init callback", info.plugin_name);
755757
} else {
758+
TSError("[%s] - No global hooks, no global init callback", info.plugin_name);
756759
delete context;
757760
delete inst;
758-
TSError("[%s] - No global hooks enabled", info.plugin_name);
759761
}
760762
}
761763

plugins/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#######################
1717

1818
include(add_atsplugin)
19+
include(add_cript)
1920

2021
# The experimental plugins are handled in cmake/ExperimentalPlugins.cmake.
2122

plugins/experimental/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ endif()
2929
if(BUILD_CERT_REPORTING_TOOL)
3030
add_subdirectory(cert_reporting_tool)
3131
endif()
32+
if(BUILD_CONNECTION_EXEMPT_LIST)
33+
add_subdirectory(connection_exempt_list)
34+
endif()
3235
if(BUILD_COOKIE_REMAP)
3336
add_subdirectory(cookie_remap)
3437
endif()

0 commit comments

Comments
 (0)