Skip to content

Commit 5c17ee4

Browse files
bneradtbneradt
authored andcommitted
traffic_ctl config convert remap
Move ATS core off the remaining remap-only parsing path and route remap.config loading through the shared src/config remap parser. This lets traffic_ctl and traffic_server use the same conversion logic while leaving only runtime regex-mapping helpers in the remap loader. This builds off of the work to support remap.yaml here: #12997
1 parent efeeffa commit 5c17ee4

18 files changed

Lines changed: 1230 additions & 1485 deletions

File tree

include/config/remap.h

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/** @file
2+
3+
Shared remap configuration parsing and marshalling.
4+
5+
@section license License
6+
7+
Licensed to the Apache Software Foundation (ASF) under one
8+
or more contributor license agreements. See the NOTICE file
9+
distributed with this work for additional information
10+
regarding copyright ownership. The ASF licenses this file
11+
to you under the Apache License, Version 2.0 (the
12+
"License"); you may not use this file except in compliance
13+
with the License. You may obtain a copy of the License at
14+
15+
http://www.apache.org/licenses/LICENSE-2.0
16+
17+
Unless required by applicable law or agreed to in writing, software
18+
distributed under the License is distributed on an "AS IS" BASIS,
19+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
See the License for the specific language governing permissions and
21+
limitations under the License.
22+
*/
23+
24+
#pragma once
25+
26+
#include <string>
27+
#include <string_view>
28+
29+
#include <yaml-cpp/yaml.h>
30+
31+
#include "config/config_result.h"
32+
33+
namespace config
34+
{
35+
36+
using RemapConfig = YAML::Node;
37+
38+
/**
39+
* Parser for remap.yaml / remap.config configuration files.
40+
*
41+
* The parser normalizes the legacy remap.config format into the YAML tree shape
42+
* consumed by the remap.yaml loader so both traffic_server and traffic_ctl can
43+
* share one conversion path.
44+
*/
45+
class RemapParser
46+
{
47+
public:
48+
/**
49+
* Parse a remap configuration file.
50+
*
51+
* The format is auto-detected based on the filename extension and content.
52+
*
53+
* @param[in] filename Path to the configuration file.
54+
* @return ConfigResult containing the parsed configuration tree or errors.
55+
*/
56+
ConfigResult<RemapConfig> parse(std::string const &filename);
57+
58+
/**
59+
* Parse remap configuration content from a string.
60+
*
61+
* The format is auto-detected from @a filename and @a content.
62+
*
63+
* @param[in] content The configuration content to parse.
64+
* @param[in] filename Synthetic filename used for format detection.
65+
* @return ConfigResult containing the parsed configuration tree or errors.
66+
*/
67+
ConfigResult<RemapConfig> parse_content(std::string_view content, std::string const &filename = "remap.yaml");
68+
69+
private:
70+
enum class Format { YAML, Legacy };
71+
72+
Format detect_format(std::string_view content, std::string const &filename) const;
73+
ConfigResult<RemapConfig> parse_yaml(std::string_view content) const;
74+
ConfigResult<RemapConfig> parse_legacy(std::string_view content) const;
75+
};
76+
77+
/**
78+
* Marshaller for remap configuration.
79+
*/
80+
class RemapMarshaller
81+
{
82+
public:
83+
/**
84+
* Serialize configuration to YAML format.
85+
*
86+
* @param[in] config The configuration tree to serialize.
87+
* @return YAML string representation.
88+
*/
89+
std::string to_yaml(RemapConfig const &config);
90+
};
91+
92+
} // namespace config

include/proxy/http/remap/RemapConfig.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,6 @@
2727

2828
class UrlRewrite;
2929

30-
#define BUILD_TABLE_MAX_ARGS 2048
31-
32-
// Remap inline options
33-
#define REMAP_OPTFLG_MAP_WITH_REFERER 0x0001u /* "map_with_referer" option */
34-
#define REMAP_OPTFLG_PLUGIN 0x0002u /* "plugin=" option (per remap plugin) */
35-
#define REMAP_OPTFLG_PPARAM 0x0004u /* "pparam=" option (per remap plugin option) */
36-
#define REMAP_OPTFLG_METHOD 0x0008u /* "method=" option (used for ACL filtering) */
37-
#define REMAP_OPTFLG_SRC_IP 0x0010u /* "src_ip=" option (used for ACL filtering) */
38-
#define REMAP_OPTFLG_SRC_IP_CATEGORY 0x0020u /* "src_ip_category=" option (used for ACL filtering) */
39-
#define REMAP_OPTFLG_ACTION 0x0040u /* "action=" option (used for ACL filtering) */
40-
#define REMAP_OPTFLG_INTERNAL 0x0080u /* only allow internal requests to hit this remap */
41-
#define REMAP_OPTFLG_IN_IP 0x0100u /* "in_ip=" option (used for ACL filtering)*/
42-
#define REMAP_OPTFLG_STRATEGY 0x0200u /* "strategy=" the name of the nexthop selection strategy */
43-
#define REMAP_OPTFLG_VOLUME 0x0400u /* "volume=" cache volume override */
44-
#define REMAP_OPTFLG_MAP_ID 0x0800u /* associate a map ID with this rule */
45-
#define REMAP_OPTFLG_INVERT 0x80000000u /* "invert" the rule (for src_ip and src_ip_category at least) */
46-
#define REMAP_OPTFLG_ALL_FILTERS \
47-
(REMAP_OPTFLG_METHOD | REMAP_OPTFLG_SRC_IP | REMAP_OPTFLG_SRC_IP_CATEGORY | REMAP_OPTFLG_ACTION | REMAP_OPTFLG_INTERNAL)
48-
4930
enum class ACLBehaviorPolicy {
5031
ACL_BEHAVIOR_LEGACY = 0,
5132
ACL_BEHAVIOR_MODERN,
@@ -55,12 +36,6 @@ struct BUILD_TABLE_INFO {
5536
BUILD_TABLE_INFO();
5637
~BUILD_TABLE_INFO();
5738

58-
unsigned long remap_optflg = 0;
59-
int paramc = 0;
60-
int argc = 0;
61-
char *paramv[BUILD_TABLE_MAX_ARGS];
62-
char *argv[BUILD_TABLE_MAX_ARGS];
63-
6439
ACLBehaviorPolicy behavior_policy{ACLBehaviorPolicy::ACL_BEHAVIOR_LEGACY}; // Default 0.
6540
bool ip_allow_check_enabled_p = true;
6641
bool accept_check_p = true;
@@ -79,17 +54,6 @@ struct BUILD_TABLE_INFO {
7954
BUILD_TABLE_INFO &operator=(const BUILD_TABLE_INFO &) = delete; // disabled
8055
};
8156

82-
const char *remap_parse_directive(BUILD_TABLE_INFO *bti, char *errbuf, size_t errbufsize);
83-
bool remap_parse_config_bti(const char *path, BUILD_TABLE_INFO *bti);
84-
85-
const char *remap_validate_filter_args(acl_filter_rule **rule_pp, const char *const *argv, int argc, char *errStrBuf,
86-
size_t errStrBufSize, ACLBehaviorPolicy behavior_policy);
87-
88-
unsigned long remap_check_option(const char *const *argv, int argc, unsigned long findmode = 0, int *_ret_idx = nullptr,
89-
const char **argptr = nullptr);
90-
91-
bool remap_parse_config(const char *path, UrlRewrite *rewrite);
92-
9357
using load_remap_file_func = void (*)(const char *, const char *);
9458

9559
extern load_remap_file_func load_remap_file_cb;

include/proxy/http/remap/UrlRewrite.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,6 @@ class UrlRewrite : public RefCountObjInHeap
265265

266266
void url_rewrite_remap_request(const UrlMappingContainer &mapping_container, URL *request_url, int scheme = -1);
267267

268-
mapping_type get_mapping_type(const char *type_str, BUILD_TABLE_INFO *bti);
268+
mapping_type get_mapping_type(const char *type_str);
269269

270270
bool process_regex_mapping_config(const char *from_host_lower, url_mapping *new_mapping, UrlRewrite::RegexMapping *reg_map);

src/config/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
set(CONFIG_PUBLIC_HEADERS
1919
${PROJECT_SOURCE_DIR}/include/config/config_result.h ${PROJECT_SOURCE_DIR}/include/config/ssl_multicert.h
20-
${PROJECT_SOURCE_DIR}/include/config/storage.h
20+
${PROJECT_SOURCE_DIR}/include/config/storage.h ${PROJECT_SOURCE_DIR}/include/config/remap.h
2121
)
2222

23-
add_library(tsconfig ssl_multicert.cc storage.cc)
23+
add_library(tsconfig ssl_multicert.cc storage.cc remap.cc)
2424

2525
add_library(ts::config ALIAS tsconfig)
2626

@@ -48,7 +48,7 @@ endif()
4848
clang_tidy_check(tsconfig)
4949

5050
if(BUILD_TESTING)
51-
add_executable(test_tsconfig unit_tests/test_ssl_multicert.cc unit_tests/test_storage.cc)
51+
add_executable(test_tsconfig unit_tests/test_ssl_multicert.cc unit_tests/test_storage.cc unit_tests/test_remap.cc)
5252

5353
target_link_libraries(test_tsconfig PRIVATE tsconfig ts::tscore Catch2::Catch2WithMain)
5454

0 commit comments

Comments
 (0)