]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/fou-tunnel: simplify parsing of protocol number
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 16 Sep 2023 10:48:07 +0000 (12:48 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 22 Sep 2023 06:17:42 +0000 (08:17 +0200)
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

index 2786bf6bb885f0af0037e7c61b3eedffd3855043..12e8e462a217326f585f81dc500a29edd6158c66 100644 (file)
@@ -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;
 }