]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
firewall-util: several cleanups for config_parse_nft_set()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 1 Sep 2024 12:37:33 +0000 (21:37 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 6 Sep 2024 01:35:02 +0000 (10:35 +0900)
- use log_syntax_parse_error(),
- return 1 on success,
- drop unnecessary or redundant assertions,
- add missing log_oom().

src/shared/firewall-util-nft.c

index e9bd2867866676905438621a6ca551eaf97169f1..daf73c5b7b92ee6dd9e7de72212ea94eb7e7ea2f 100644 (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();