]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
conf-parse: add a generic config_parse_mtu() conf file parser function
authorLennart Poettering <lennart@poettering.net>
Fri, 20 Apr 2018 14:31:17 +0000 (16:31 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 26 Apr 2018 11:51:44 +0000 (13:51 +0200)
It's mostly a wrapper around parse_mtu() but with some nicer logging.

The address family is initialized from the "ltype" parameter, so that
configuration file parser tables can be easily declare it.

src/shared/conf-parser.c
src/shared/conf-parser.h

index a5b38604cae3bce993005fe3b58ff8235785cd43..45885618901fb3b5448be86dcb3649dbfebf6105 100644 (file)
@@ -1158,3 +1158,38 @@ int config_parse_join_controllers(
 
         return 0;
 }
+
+int config_parse_mtu(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        uint32_t *mtu = data;
+        int r;
+
+        assert(rvalue);
+        assert(mtu);
+
+        r = parse_mtu(ltype, rvalue, mtu);
+        if (r == -ERANGE) {
+                log_syntax(unit, LOG_ERR, filename, line, r,
+                           "Maximum transfer unit (MTU) value out of range. Permitted range is %" PRIu32 "…%" PRIu32 ", ignoring: %s",
+                           (uint32_t) (ltype == AF_INET6 ? IPV6_MIN_MTU : IPV4_MIN_MTU), (uint32_t) UINT32_MAX,
+                           rvalue);
+                return 0;
+        }
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, r,
+                           "Failed to parse MTU value '%s', ignoring: %m", rvalue);
+                return 0;
+        }
+
+        return 0;
+}
index 150fa07e7eb63b657830349682d7c1c7c5546999..094b9cbc447467d2126edb387fb94fbcb108a52e 100644 (file)
@@ -146,6 +146,7 @@ int config_parse_personality(GENERIC_PARSER_ARGS);
 int config_parse_ifname(GENERIC_PARSER_ARGS);
 int config_parse_ip_port(GENERIC_PARSER_ARGS);
 int config_parse_join_controllers(GENERIC_PARSER_ARGS);
+int config_parse_mtu(GENERIC_PARSER_ARGS);
 
 typedef enum Disabled {
         DISABLED_CONFIGURATION,