From: Lennart Poettering Date: Fri, 20 Apr 2018 14:31:17 +0000 (+0200) Subject: conf-parse: add a generic config_parse_mtu() conf file parser function X-Git-Tag: v239~350^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=79138a384f0c6a0d47cf97cf5a917f32ec4a9ba9;p=thirdparty%2Fsystemd.git conf-parse: add a generic config_parse_mtu() conf file parser function 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. --- diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index a5b38604cae..45885618901 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -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; +} diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index 150fa07e7eb..094b9cbc447 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -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,