1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

firewall-util: several cleanups for config_parse_nft_set()

- use log_syntax_parse_error(),
- return 1 on success,
- drop unnecessary or redundant assertions,
- add missing log_oom().
This commit is contained in:
Yu Watanabe 2024-09-01 21:37:33 +09:00
parent ff616da459
commit 174c5c5f06

View File

@ -1284,16 +1284,11 @@ int config_parse_nft_set(
NFTSetContext *nft_set_context = ASSERT_PTR(data);
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(nft_set_context);
assert(IN_SET(ltype, NFT_SET_PARSE_NETWORK, NFT_SET_PARSE_CGROUP));
if (isempty(rvalue)) {
nft_set_context_clear(nft_set_context);
return 0;
return 1;
}
for (const char *p = rvalue;;) {
@ -1303,17 +1298,10 @@ int config_parse_nft_set(
NFTSetSource source;
r = extract_first_word(&p, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
if (r == -ENOMEM)
return log_oom();
if (r < 0) {
_cleanup_free_ char *esc = NULL;
esc = cescape(rvalue);
log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax %s=%s, ignoring: %m", lvalue, strna(esc));
return 0;
}
if (r < 0)
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
if (r == 0)
return 0;
return 1;
q = tuple;
r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE, &source_str, &family_str, &table, &set);
@ -1365,7 +1353,7 @@ int config_parse_nft_set(
r = nft_set_add(nft_set_context, source, nfproto, table, set);
if (r < 0)
return r;
return log_oom();
}
assert_not_reached();