Skip to content

Commit 82f4064

Browse files
committed
clang fixes
1 parent 710bece commit 82f4064

3 files changed

Lines changed: 55 additions & 37 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Configuration Files
3333
plugin.config.en
3434
records.yaml.en
3535
remap.config.en
36+
remap.yaml.en
3637
splitdns.config.en
3738
ssl_multicert.config.en
3839
sni.yaml.en
@@ -69,6 +70,9 @@ Configuration Files
6970
:doc:`remap.config.en`
7071
Defines mapping rules used by |TS| to properly route all incoming requests.
7172

73+
:doc:`remap.yaml.en`
74+
Defines mapping rules used by |TS| to properly route all incoming requests in YAML format
75+
7276
:doc:`splitdns.config.en`
7377
Configures DNS servers to use under specific conditions.
7478

doc/admin-guide/files/remap.yaml.en.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Optional Fields
185185
---------------
186186

187187
``acl_filter``
188-
~~~~~~~~~~
188+
~~~~~~~~~~~~~~
189189

190190
Inline ACL filter definition for a single remap rule. See `ACL Filters`_ for details.
191191

src/proxy/http/remap/RemapYamlConfig.cc

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,13 @@ remap_validate_yaml_filter_args(acl_filter_rule **rule_pp, const YAML::Node &nod
194194
}
195195

196196
if (!node || !node.IsMap()) {
197+
if (new_rule_flg) {
198+
delete rule;
199+
*rule_pp = nullptr;
200+
}
197201
return swoc::Errata("filters must be a map");
198202
}
199203

200-
bool action_flag = false;
201-
202204
// Parse method
203205
auto parse_method = [&](const std::string &method_str) {
204206
int m = hdrtoken_tokenize(method_str.c_str(), method_str.length(), nullptr) - HTTP_WKSIDX_CONNECT;
@@ -226,10 +228,6 @@ remap_validate_yaml_filter_args(acl_filter_rule **rule_pp, const YAML::Node &nod
226228
auto parse_src_ip = [&](const std::string &ip_str, bool invert) -> swoc::Errata {
227229
if (rule->src_ip_cnt >= ACL_FILTER_MAX_SRC_IP) {
228230
Dbg(dbg_ctl_url_rewrite, "[validate_filter_args] Too many \"src_ip=\" filters");
229-
if (new_rule_flg) {
230-
delete rule;
231-
*rule_pp = nullptr;
232-
}
233231
return swoc::Errata("Defined more than {} src_ip filters", ACL_FILTER_MAX_SRC_IP);
234232
}
235233

@@ -242,10 +240,6 @@ remap_validate_yaml_filter_args(acl_filter_rule **rule_pp, const YAML::Node &nod
242240
ipi->match_all_addresses = true;
243241
} else if (ats_ip_range_parse(arg, ipi->start, ipi->end) != 0) {
244242
Dbg(dbg_ctl_url_rewrite, "[validate_filter_args] Unable to parse IP value in %s", ip_str.c_str());
245-
if (new_rule_flg) {
246-
delete rule;
247-
*rule_pp = nullptr;
248-
}
249243
return swoc::Errata("Unable to parse IP value: {}", ip_str);
250244
}
251245
for (j = 0; j < rule->src_ip_cnt; j++) {
@@ -266,12 +260,20 @@ remap_validate_yaml_filter_args(acl_filter_rule **rule_pp, const YAML::Node &nod
266260
for (const auto &src_ip : node["src_ip"]) {
267261
auto errata = parse_src_ip(src_ip.as<std::string>(), false);
268262
if (!errata.is_ok()) {
263+
if (new_rule_flg) {
264+
delete rule;
265+
*rule_pp = nullptr;
266+
}
269267
return errata;
270268
}
271269
}
272270
} else {
273271
auto errata = parse_src_ip(node["src_ip"].as<std::string>(), false);
274272
if (!errata.is_ok()) {
273+
if (new_rule_flg) {
274+
delete rule;
275+
*rule_pp = nullptr;
276+
}
275277
return errata;
276278
}
277279
}
@@ -282,12 +284,20 @@ remap_validate_yaml_filter_args(acl_filter_rule **rule_pp, const YAML::Node &nod
282284
for (const auto &src_ip_invert : node["src_ip_invert"]) {
283285
auto errata = parse_src_ip(src_ip_invert.as<std::string>(), true);
284286
if (!errata.is_ok()) {
287+
if (new_rule_flg) {
288+
delete rule;
289+
*rule_pp = nullptr;
290+
}
285291
return errata;
286292
}
287293
}
288294
} else {
289295
auto errata = parse_src_ip(node["src_ip_invert"].as<std::string>(), true);
290296
if (!errata.is_ok()) {
297+
if (new_rule_flg) {
298+
delete rule;
299+
*rule_pp = nullptr;
300+
}
291301
return errata;
292302
}
293303
}
@@ -297,10 +307,6 @@ remap_validate_yaml_filter_args(acl_filter_rule **rule_pp, const YAML::Node &nod
297307
auto parse_src_ip_category = [&](const std::string &ip_category, bool invert) -> swoc::Errata {
298308
if (rule->src_ip_category_cnt >= ACL_FILTER_MAX_SRC_IP) {
299309
Dbg(dbg_ctl_url_rewrite, "[validate_filter_args] Too many \"src_ip_category=\" filters");
300-
if (new_rule_flg) {
301-
delete rule;
302-
*rule_pp = nullptr;
303-
}
304310
return swoc::Errata("Defined more than {} src_ip_category filters", ACL_FILTER_MAX_SRC_IP);
305311
}
306312
src_ip_category_info_t *ipi = &rule->src_ip_category_array[rule->src_ip_category_cnt];
@@ -324,13 +330,21 @@ remap_validate_yaml_filter_args(acl_filter_rule **rule_pp, const YAML::Node &nod
324330
if (node["src_ip_category"]) {
325331
auto errata = parse_src_ip_category(node["src_ip_category"].as<std::string>(), false);
326332
if (!errata.is_ok()) {
333+
if (new_rule_flg) {
334+
delete rule;
335+
*rule_pp = nullptr;
336+
}
327337
return errata;
328338
}
329339
}
330340

331341
if (node["src_ip_category_invert"]) {
332342
auto errata = parse_src_ip_category(node["src_ip_category_invert"].as<std::string>(), true);
333343
if (!errata.is_ok()) {
344+
if (new_rule_flg) {
345+
delete rule;
346+
*rule_pp = nullptr;
347+
}
334348
return errata;
335349
}
336350
}
@@ -339,10 +353,6 @@ remap_validate_yaml_filter_args(acl_filter_rule **rule_pp, const YAML::Node &nod
339353
auto parse_in_ip = [&](const std::string &in_ip, bool invert) -> swoc::Errata {
340354
if (rule->in_ip_cnt >= ACL_FILTER_MAX_IN_IP) {
341355
Dbg(dbg_ctl_url_rewrite, "[validate_filter_args] Too many \"in_ip=\" filters");
342-
if (new_rule_flg) {
343-
delete rule;
344-
*rule_pp = nullptr;
345-
}
346356
return swoc::Errata("Defined more than {} in_ip filters", ACL_FILTER_MAX_IN_IP);
347357
}
348358
src_ip_info_t *ipi = &rule->in_ip_array[rule->in_ip_cnt];
@@ -355,10 +365,6 @@ remap_validate_yaml_filter_args(acl_filter_rule **rule_pp, const YAML::Node &nod
355365
ipi->match_all_addresses = true;
356366
} else if (ats_ip_range_parse(arg, ipi->start, ipi->end) != 0) {
357367
Dbg(dbg_ctl_url_rewrite, "[validate_filter_args] Unable to parse IP value in %s", in_ip.c_str());
358-
if (new_rule_flg) {
359-
delete rule;
360-
*rule_pp = nullptr;
361-
}
362368
return swoc::Errata("Unable to parse IP value: {}", in_ip);
363369
}
364370
for (j = 0; j < rule->in_ip_cnt; j++) {
@@ -379,12 +385,20 @@ remap_validate_yaml_filter_args(acl_filter_rule **rule_pp, const YAML::Node &nod
379385
for (const auto &in_ip : node["in_ip"]) {
380386
auto errata = parse_in_ip(in_ip.as<std::string>(), false);
381387
if (!errata.is_ok()) {
388+
if (new_rule_flg) {
389+
delete rule;
390+
*rule_pp = nullptr;
391+
}
382392
return errata;
383393
}
384394
}
385395
} else {
386396
auto errata = parse_in_ip(node["in_ip"].as<std::string>(), false);
387397
if (!errata.is_ok()) {
398+
if (new_rule_flg) {
399+
delete rule;
400+
*rule_pp = nullptr;
401+
}
388402
return errata;
389403
}
390404
}
@@ -395,28 +409,27 @@ remap_validate_yaml_filter_args(acl_filter_rule **rule_pp, const YAML::Node &nod
395409
for (const auto &in_ip_invert : node["in_ip_invert"]) {
396410
auto errata = parse_in_ip(in_ip_invert.as<std::string>(), true);
397411
if (!errata.is_ok()) {
412+
if (new_rule_flg) {
413+
delete rule;
414+
*rule_pp = nullptr;
415+
}
398416
return errata;
399417
}
400418
}
401419
} else {
402420
auto errata = parse_in_ip(node["in_ip_invert"].as<std::string>(), true);
403421
if (!errata.is_ok()) {
422+
if (new_rule_flg) {
423+
delete rule;
424+
*rule_pp = nullptr;
425+
}
404426
return errata;
405427
}
406428
}
407429
}
408430

409431
// Parse action
410432
if (node["action"]) {
411-
if (action_flag) {
412-
Dbg(dbg_ctl_url_rewrite, "Only one action: is allowed per remap ACL");
413-
if (new_rule_flg) {
414-
delete rule;
415-
*rule_pp = nullptr;
416-
}
417-
return swoc::Errata("Only one action is allowed per remap ACL");
418-
}
419-
action_flag = true;
420433
std::string action_str = node["action"].as<std::string>();
421434
if (behavior_policy == ACLBehaviorPolicy::ACL_BEHAVIOR_MODERN) {
422435
// With the new matching policy, we don't allow the legacy "allow" and
@@ -652,9 +665,9 @@ parse_yaml_define_directive(const YAML::Node &node, BUILD_TABLE_INFO *bti)
652665

653666
// When iterating over a YAML map, each element is a key-value pair
654667
// We expect a single-entry map here
655-
auto it = node.begin();
656-
std::string filter_name = it->first.as<std::string>();
657-
const YAML::Node &filter_spec = it->second;
668+
auto it = node.begin();
669+
std::string filter_name = it->first.as<std::string>();
670+
const YAML::Node filter_spec = it->second;
658671

659672
flg = ((rp = acl_filter_rule::find_byname(bti->rules_list, filter_name.c_str())) == nullptr) ? true : false;
660673
// coverity[alloc_arg]
@@ -1030,7 +1043,8 @@ parse_yaml_remap_rule(const YAML::Node &node, BUILD_TABLE_INFO *bti)
10301043
if (node["plugins"] && (maptype == mapping_type::FORWARD_MAP || maptype == mapping_type::FORWARD_MAP_REFERER ||
10311044
maptype == mapping_type::FORWARD_MAP_WITH_RECV_PORT)) {
10321045
if (!node["plugins"] || !node["plugins"].IsSequence()) {
1033-
return swoc::Errata("plugins must be a sequence");
1046+
errStr = "plugins must be a sequence";
1047+
goto MAP_ERROR;
10341048
}
10351049

10361050
for (const auto &plugin : node["plugins"]) {
@@ -1048,7 +1062,7 @@ parse_yaml_remap_rule(const YAML::Node &node, BUILD_TABLE_INFO *bti)
10481062
goto MAP_ERROR;
10491063
}
10501064

1051-
fromHost_lower_ptr = static_cast<char *>(ats_free_null(fromHost_lower_ptr));
1065+
ats_free_null(fromHost_lower_ptr);
10521066

10531067
Dbg(dbg_ctl_remap_yaml, "Successfully added mapping rule");
10541068
return {};

0 commit comments

Comments
 (0)