diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-09-16 12:48:07 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-09-22 08:17:42 +0200 |
commit | a893c121edcab567cabf17184a1ae041d0ce2468 (patch) | |
tree | ecb8e6a889f483eb02beae36b4d39dfb87459add | |
parent | shared/ip-procotol-list: generalize and rework parse_ip_protocol() (diff) | |
download | systemd-a893c121edcab567cabf17184a1ae041d0ce2468.tar.xz systemd-a893c121edcab567cabf17184a1ae041d0ce2468.zip |
network/fou-tunnel: simplify parsing of protocol number
Previously, we would call parse_ip_protocol(), which internally calls
safe_atoi(), and then call safe_atou(). This isn't terrible, but it's also
slightly confusing. Use parse_ip_protocol_full() to avoid the second call.
-rw-r--r-- | src/network/netdev/fou-tunnel.c | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/src/network/netdev/fou-tunnel.c b/src/network/netdev/fou-tunnel.c index 2786bf6bb8..12e8e462a2 100644 --- a/src/network/netdev/fou-tunnel.c +++ b/src/network/netdev/fou-tunnel.c @@ -156,37 +156,32 @@ int config_parse_ip_protocol( void *data, void *userdata) { - uint8_t *ret = ASSERT_PTR(data); - unsigned protocol; - /* linux/fou.h defines the netlink field as one byte, so we need to reject protocols numbers that - * don't fit in one byte. */ - int r; - assert(filename); assert(section); assert(lvalue); assert(rvalue); - r = parse_ip_protocol(rvalue); - if (r >= 0) - protocol = r; - else { - r = safe_atou(rvalue, &protocol); - if (r < 0) - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse IP protocol '%s' for FooOverUDP tunnel, " - "ignoring assignment: %m", rvalue); + uint8_t *proto = ASSERT_PTR(data); + int r; + + r = parse_ip_protocol_full(rvalue, /* relaxed= */ true); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Failed to parse '%s=%s', ignoring: %m", + lvalue, rvalue); return 0; } - if (protocol > UINT8_MAX) { - log_syntax(unit, LOG_WARNING, filename, line, 0, - "IP protocol '%s' for FooOverUDP tunnel out of range, " - "ignoring assignment: %m", rvalue); + if (r > UINT8_MAX) { + /* linux/fou.h defines 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; } - *ret = protocol; + *proto = r; return 0; } |