]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
conf-parser: move config_parse_ip_protocol() from network/netdev/fou-tunnel.c
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 24 Aug 2024 19:58:14 +0000 (04:58 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 24 Aug 2024 21:18:46 +0000 (06:18 +0900)
The function is generic enough. Currently it is used at only one place.
But it will be used at another place.

src/network/netdev/fou-tunnel.c
src/network/netdev/fou-tunnel.h
src/network/netdev/netdev-gperf.gperf
src/shared/conf-parser.c
src/shared/conf-parser.h

index bddee5e98cde0bb560bf0438a016ba3829817165..969a4e6de648129e3836e83965cbe2ee434aa10a 100644 (file)
@@ -142,47 +142,6 @@ static int netdev_fou_tunnel_create(NetDev *netdev) {
         return 0;
 }
 
-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) {
-
-        assert(filename);
-        assert(section);
-        assert(lvalue);
-        assert(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 (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;
-        }
-
-        *proto = r;
-        return 0;
-}
-
 int config_parse_fou_tunnel_address(
                 const char *unit,
                 const char *filename,
index 72cb315e5fc7b0f2d1c70a55061f43bb3dd8c7df..1dd2e3b927d33e8377576dae6c71be2422c35c5f 100644 (file)
@@ -38,5 +38,4 @@ const char* fou_encap_type_to_string(FooOverUDPEncapType d) _const_;
 FooOverUDPEncapType fou_encap_type_from_string(const char *d) _pure_;
 
 CONFIG_PARSER_PROTOTYPE(config_parse_fou_encap_type);
-CONFIG_PARSER_PROTOTYPE(config_parse_ip_protocol);
 CONFIG_PARSER_PROTOTYPE(config_parse_fou_tunnel_address);
index 03a4791ee48ac790cee9a99e64e5aac5dc2967ae..be010665c5d153a77012b672872e8d563eb88076 100644 (file)
@@ -99,7 +99,7 @@ Tunnel.ERSPANHardwareId,                  config_parse_erspan_hwid,
 Tunnel.SerializeTunneledPackets,          config_parse_tristate,                     0,                             offsetof(Tunnel, gre_erspan_sequence)
 Tunnel.ISATAP,                            config_parse_tristate,                     0,                             offsetof(Tunnel, isatap)
 Tunnel.External,                          config_parse_bool,                         0,                             offsetof(Tunnel, external)
-FooOverUDP.Protocol,                      config_parse_ip_protocol,                  0,                             offsetof(FouTunnel, fou_protocol)
+FooOverUDP.Protocol,                      config_parse_ip_protocol,                  /* relax = */ true,            offsetof(FouTunnel, fou_protocol)
 FooOverUDP.Encapsulation,                 config_parse_fou_encap_type,               0,                             offsetof(FouTunnel, fou_encap_type)
 FooOverUDP.Port,                          config_parse_ip_port,                      0,                             offsetof(FouTunnel, port)
 FooOverUDP.PeerPort,                      config_parse_ip_port,                      0,                             offsetof(FouTunnel, peer_port)
index ac0df88b4d583afd224fdfae521d28a011bbfd80..c4633fc52f1e969d4ca6d021dd88795f4e89a2ab 100644 (file)
@@ -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. */
+}
index ad40c6224c5df25e6c166f03ef7c1cca9cd4e0d1..937bdc73ed6dbb81adbce4a908d6086a239dcb3d 100644 (file)
@@ -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,