diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-08-24 21:58:14 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-08-24 23:18:46 +0200 |
commit | f7a1e57e1f864c2aa6d77838d3ce3ea6d89be3c6 (patch) | |
tree | 3bad9348ecda9fa87269745f290dd8d7052f1785 /src/shared | |
parent | conf-parser: introduce config_parse_uint32_flag() (diff) | |
download | systemd-f7a1e57e1f864c2aa6d77838d3ce3ea6d89be3c6.tar.xz systemd-f7a1e57e1f864c2aa6d77838d3ce3ea6d89be3c6.zip |
conf-parser: move config_parse_ip_protocol() from network/netdev/fou-tunnel.c
The function is generic enough. Currently it is used at only one place.
But it will be used at another place.
Diffstat (limited to '')
-rw-r--r-- | src/shared/conf-parser.c | 37 | ||||
-rw-r--r-- | src/shared/conf-parser.h | 1 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index ac0df88b4d..c4633fc52f 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -24,6 +24,7 @@ #include "hostname-util.h" #include "id128-util.h" #include "in-addr-util.h" +#include "ip-protocol-list.h" #include "log.h" #include "macro.h" #include "missing_network.h" @@ -2082,3 +2083,39 @@ int config_parse_timezone( return free_and_strdup_warn(tz, rvalue); } + +int config_parse_ip_protocol( + 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) { + + uint8_t *proto = ASSERT_PTR(data); + int r; + + r = isempty(rvalue) ? 0 : parse_ip_protocol_full(rvalue, /* relaxed= */ ltype); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Failed to parse '%s=%s', ignoring: %m", + lvalue, rvalue); + return 0; + } + + if (r > UINT8_MAX) { + /* linux/fib_rules.h and linux/fou.h define the netlink field as one byte, so we need to + * reject protocols numbers that don't fit in one byte. */ + log_syntax(unit, LOG_WARNING, filename, line, r, + "Invalid '%s=%s', allowed range is 0..255, ignoring.", + lvalue, rvalue); + return 0; + } + + *proto = r; + return 1; /* done. */ +} diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index ad40c6224c..937bdc73ed 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -290,6 +290,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_pid); CONFIG_PARSER_PROTOTYPE(config_parse_sec_fix_0); CONFIG_PARSER_PROTOTYPE(config_parse_timezone); CONFIG_PARSER_PROTOTYPE(config_parse_calendar); +CONFIG_PARSER_PROTOTYPE(config_parse_ip_protocol); typedef enum Disabled { DISABLED_CONFIGURATION, |