chiark / gitweb /
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)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +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 1b09b20a5e37ec1d2a9e82063e7079d68ece9940..6c3dda5aea428e7c14ee698daf4666be9800d572 100644 (file)
@@ -1176,3 +1176,38 @@ int config_parse_join_controllers(
         return 0;
 }
 #endif // 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 aff673acc601ecb5eaec89dfec01109ddbdc23b8..38a82f6e3300ec2413f9c1cf27d875b010b34768 100644 (file)
@@ -162,6 +162,7 @@ int config_parse_ip_port(GENERIC_PARSER_ARGS);
 #if 0 /// UNNEEDED by elogind
 int config_parse_join_controllers(GENERIC_PARSER_ARGS);
 #endif // 0
+int config_parse_mtu(GENERIC_PARSER_ARGS);
 
 typedef enum Disabled {
         DISABLED_CONFIGURATION,