From a893c121edcab567cabf17184a1ae041d0ce2468 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sat, 16 Sep 2023 12:48:07 +0200 Subject: 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. --- src/network/netdev/fou-tunnel.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'src/network') 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; } -- cgit v1.2.3