]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: rename socket_protocol_{from,to}_name() to ip_protocol_{from,to}_name()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 29 Nov 2018 14:58:43 +0000 (15:58 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 2 Dec 2018 04:48:27 +0000 (05:48 +0100)
12 files changed:
src/core/dbus-socket.c
src/core/load-fragment.c
src/core/socket.c
src/network/networkd-routing-policy-rule.c
src/shared/bus-unit-util.c
src/shared/generate-ip-protocol-list.sh [moved from src/shared/generate-socket-protocol-list.sh with 100% similarity]
src/shared/ip-protocol-list.c [new file with mode: 0644]
src/shared/ip-protocol-list.h [new file with mode: 0644]
src/shared/ip-protocol-to-name.awk [moved from src/shared/socket-protocol-to-name.awk with 62% similarity]
src/shared/meson.build
src/shared/socket-protocol-list.c [deleted file]
src/shared/socket-protocol-list.h [deleted file]

index 3819653908fd850558f9c4cc21d86b5d2a5e0252..37cf9d204c726a66c6e0216398c21858c8065a62 100644 (file)
@@ -8,10 +8,10 @@
 #include "dbus-socket.h"
 #include "dbus-util.h"
 #include "fd-util.h"
+#include "ip-protocol-list.h"
 #include "parse-util.h"
 #include "path-util.h"
 #include "socket.h"
-#include "socket-protocol-list.h"
 #include "socket-util.h"
 #include "string-util.h"
 #include "unit.h"
@@ -138,14 +138,14 @@ static inline bool check_size_t_truncation(uint64_t t) {
         return (size_t) t == t;
 }
 
-static inline const char* supported_socket_protocol_to_string(int32_t i) {
+static inline const char* socket_protocol_to_string(int32_t i) {
         if (i == IPPROTO_IP)
                 return "";
 
         if (!IN_SET(i, IPPROTO_UDPLITE, IPPROTO_SCTP))
                 return NULL;
 
-        return socket_protocol_to_name(i);
+        return ip_protocol_to_name(i);
 }
 
 static BUS_DEFINE_SET_TRANSIENT(int, "i", int32_t, int, "%" PRIi32);
@@ -155,7 +155,7 @@ static BUS_DEFINE_SET_TRANSIENT_PARSE(bind_ipv6_only, SocketAddressBindIPv6Only,
 static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(fdname, fdname_is_valid);
 static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(ifname, ifname_valid);
 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(ip_tos, "i", int32_t, int, "%" PRIi32, ip_tos_to_string_alloc);
-static BUS_DEFINE_SET_TRANSIENT_TO_STRING(socket_protocol, "i", int32_t, int, "%" PRIi32, supported_socket_protocol_to_string);
+static BUS_DEFINE_SET_TRANSIENT_TO_STRING(socket_protocol, "i", int32_t, int, "%" PRIi32, socket_protocol_to_string);
 
 static int bus_socket_set_transient_property(
                 Socket *s,
index 273d0b96fc79fdb7537a599d9a49866959244daa..e3e9b4e53148837a8917b31891a62d296d3942cb 100644 (file)
@@ -34,6 +34,7 @@
 #include "hexdecoct.h"
 #include "io-util.h"
 #include "ioprio.h"
+#include "ip-protocol-list.h"
 #include "journal-util.h"
 #include "load-fragment.h"
 #include "log.h"
@@ -48,7 +49,6 @@
 #include "securebits.h"
 #include "securebits-util.h"
 #include "signal-util.h"
-#include "socket-protocol-list.h"
 #include "stat-util.h"
 #include "string-util.h"
 #include "strv.h"
 #include "user-util.h"
 #include "web-util.h"
 
-static int supported_socket_protocol_from_string(const char *s) {
+static int socket_protocol_from_string(const char *s) {
         int r;
 
         if (isempty(s))
                 return IPPROTO_IP;
 
-        r = socket_protocol_from_name(s);
+        r = ip_protocol_from_name(s);
         if (r < 0)
                 return r;
         if (!IN_SET(r, IPPROTO_UDPLITE, IPPROTO_SCTP))
@@ -72,7 +72,7 @@ static int supported_socket_protocol_from_string(const char *s) {
         return r;
 }
 
-DEFINE_CONFIG_PARSE(config_parse_socket_protocol, supported_socket_protocol_from_string, "Failed to parse socket protocol");
+DEFINE_CONFIG_PARSE(config_parse_socket_protocol, socket_protocol_from_string, "Failed to parse socket protocol");
 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits, secure_bits_from_string, "Failed to parse secure bits");
 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode, collect_mode, CollectMode, "Failed to parse garbage collection mode");
 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy, cgroup_device_policy, CGroupDevicePolicy, "Failed to parse device policy");
index f725c9eb009cdf7428722c3c6596bf352f086eef..ba48a25641cf1408116a6764db0b511e4b9a59f7 100644 (file)
@@ -24,6 +24,7 @@
 #include "fs-util.h"
 #include "in-addr-util.h"
 #include "io-util.h"
+#include "ip-protocol-list.h"
 #include "label.h"
 #include "log.h"
 #include "missing.h"
@@ -35,7 +36,6 @@
 #include "serialize.h"
 #include "signal-util.h"
 #include "smack-util.h"
-#include "socket-protocol-list.h"
 #include "socket.h"
 #include "special.h"
 #include "string-table.h"
@@ -814,7 +814,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
                 prefix, format_timespan(time_string, FORMAT_TIMESPAN_MAX, s->trigger_limit.interval, USEC_PER_SEC),
                 prefix, s->trigger_limit.burst);
 
-        str = socket_protocol_to_name(s->socket_protocol);
+        str = ip_protocol_to_name(s->socket_protocol);
         if (str)
                 fprintf(f, "%sSocketProtocol: %s\n", prefix, str);
 
index e84612d41df3c9f3c394e1b3582b528c8055382a..c4572a6aad5f4f94d6c335f6ff35c9ab40ddfbea 100644 (file)
@@ -6,11 +6,11 @@
 #include "alloc-util.h"
 #include "conf-parser.h"
 #include "fileio.h"
+#include "ip-protocol-list.h"
 #include "networkd-routing-policy-rule.h"
 #include "netlink-util.h"
 #include "networkd-manager.h"
 #include "parse-util.h"
-#include "socket-protocol-list.h"
 #include "socket-util.h"
 #include "string-util.h"
 #include "strv.h"
@@ -958,7 +958,7 @@ int config_parse_routing_policy_rule_protocol(
         if (r < 0)
                 return r;
 
-        r = socket_protocol_from_name(rvalue);
+        r = ip_protocol_from_name(rvalue);
         if (r < 0) {
                 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse routing policy rule protocol, ignoring: %s", rvalue);
                 return 0;
index 78a2be341cd2da4afcd034c729311ca0aa76fc17..a50b9f416ed517ad2cbbf206aa99a30afe4502fa 100644 (file)
@@ -15,6 +15,7 @@
 #include "hexdecoct.h"
 #include "hostname-util.h"
 #include "in-addr-util.h"
+#include "ip-protocol-list.h"
 #include "list.h"
 #include "locale-util.h"
 #include "mountpoint-util.h"
@@ -25,7 +26,6 @@
 #include "rlimit-util.h"
 #include "securebits-util.h"
 #include "signal-util.h"
-#include "socket-protocol-list.h"
 #include "string-util.h"
 #include "syslog-util.h"
 #include "terminal-util.h"
@@ -103,7 +103,7 @@ DEFINE_BUS_APPEND_PARSE("i", parse_errno);
 DEFINE_BUS_APPEND_PARSE("i", sched_policy_from_string);
 DEFINE_BUS_APPEND_PARSE("i", secure_bits_from_string);
 DEFINE_BUS_APPEND_PARSE("i", signal_from_string);
-DEFINE_BUS_APPEND_PARSE("i", socket_protocol_from_name);
+DEFINE_BUS_APPEND_PARSE("i", ip_protocol_from_name);
 DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, ioprio_parse_priority);
 DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, parse_nice);
 DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, safe_atoi);
@@ -1466,7 +1466,7 @@ static int bus_append_socket_property(sd_bus_message *m, const char *field, cons
 
         if (streq(field, "SocketProtocol"))
 
-                return bus_append_socket_protocol_from_name(m, field, eq);
+                return bus_append_ip_protocol_from_name(m, field, eq);
 
         if (STR_IN_SET(field,
                        "ListenStream", "ListenDatagram", "ListenSequentialPacket", "ListenNetlink",
diff --git a/src/shared/ip-protocol-list.c b/src/shared/ip-protocol-list.c
new file mode 100644 (file)
index 0000000..9a1c11b
--- /dev/null
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include <errno.h>
+#include <netinet/in.h>
+#include <string.h>
+
+#include "ip-protocol-list.h"
+#include "macro.h"
+
+static const struct ip_protocol_name* lookup_ip_protocol(register const char *str, register GPERF_LEN_TYPE len);
+
+#include "ip-protocol-from-name.h"
+#include "ip-protocol-to-name.h"
+
+const char *ip_protocol_to_name(int id) {
+
+        if (id < 0)
+                return NULL;
+
+        if (id >= (int) ELEMENTSOF(ip_protocol_names))
+                return NULL;
+
+        return ip_protocol_names[id];
+}
+
+int ip_protocol_from_name(const char *name) {
+        const struct ip_protocol_name *sc;
+
+        assert(name);
+
+        sc = lookup_ip_protocol(name, strlen(name));
+        if (!sc)
+                return -EINVAL;
+
+        return sc->id;
+}
diff --git a/src/shared/ip-protocol-list.h b/src/shared/ip-protocol-list.h
new file mode 100644 (file)
index 0000000..dfe3467
--- /dev/null
@@ -0,0 +1,5 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#pragma once
+
+const char *ip_protocol_to_name(int id);
+int ip_protocol_from_name(const char *name);
similarity index 62%
rename from src/shared/socket-protocol-to-name.awk
rename to src/shared/ip-protocol-to-name.awk
index 4848a7631a86e908bf702726ce1242ed95423b29..824f811f5ca4071e87adfc1c50d915ac331074b8 100644 (file)
@@ -1,5 +1,5 @@
 BEGIN{
-        print "static const char* const socket_protocol_names[] = { "
+        print "static const char* const ip_protocol_names[] = { "
 }
 !/HOPOPTS/ {
         printf "        [IPPROTO_%s] = \"%s\",\n", $1, tolower($1)
index 85c546eb5bb8a9fd678cae62b4479bad1d454954..ea8f959129766fcbcdc2a5515df3d9982c0ab267 100644 (file)
@@ -127,8 +127,8 @@ shared_sources = files('''
         serialize.h
         sleep-config.c
         sleep-config.h
-        socket-protocol-list.c
-        socket-protocol-list.h
+        ip-protocol-list.c
+        ip-protocol-list.h
         spawn-ask-password-agent.c
         spawn-ask-password-agent.h
         spawn-polkit-agent.c
@@ -188,39 +188,39 @@ if conf.get('HAVE_KMOD') == 1
         shared_sources += files('module-util.c')
 endif
 
-generate_socket_protocol_list = find_program('generate-socket-protocol-list.sh')
-socket_protocol_list_txt = custom_target(
-        'socket-protocol-list.txt',
-        output : 'socket-protocol-list.txt',
-        command : [generate_socket_protocol_list, cpp],
+generate_ip_protocol_list = find_program('generate-ip-protocol-list.sh')
+ip_protocol_list_txt = custom_target(
+        'ip-protocol-list.txt',
+        output : 'ip-protocol-list.txt',
+        command : [generate_ip_protocol_list, cpp],
         capture : true)
 
-fname = 'socket-protocol-from-name.gperf'
+fname = 'ip-protocol-from-name.gperf'
 gperf_file = custom_target(
         fname,
-        input : socket_protocol_list_txt,
+        input : ip_protocol_list_txt,
         output : fname,
-        command : [generate_gperfs, 'socket_protocol', 'IPPROTO_', '@INPUT@'],
+        command : [generate_gperfs, 'ip_protocol', 'IPPROTO_', '@INPUT@'],
         capture : true)
 
-fname = 'socket-protocol-from-name.h'
+fname = 'ip-protocol-from-name.h'
 target1 = custom_target(
         fname,
         input : gperf_file,
         output : fname,
         command : [gperf,
                    '-L', 'ANSI-C', '-t', '--ignore-case',
-                   '-N', 'lookup_socket_protocol',
-                   '-H', 'hash_socket_protocol_name',
+                   '-N', 'lookup_ip_protocol',
+                   '-H', 'hash_ip_protocol_name',
                    '-p', '-C',
                    '@INPUT@'],
         capture : true)
 
-fname = 'socket-protocol-to-name.h'
-awkscript = 'socket-protocol-to-name.awk'
+fname = 'ip-protocol-to-name.h'
+awkscript = 'ip-protocol-to-name.awk'
 target2 = custom_target(
         fname,
-        input : [awkscript, socket_protocol_list_txt],
+        input : [awkscript, ip_protocol_list_txt],
         output : fname,
         command : [awk, '-f', '@INPUT0@', '@INPUT1@'],
         capture : true)
diff --git a/src/shared/socket-protocol-list.c b/src/shared/socket-protocol-list.c
deleted file mode 100644 (file)
index 0a8570b..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
-
-#include <errno.h>
-#include <netinet/in.h>
-#include <string.h>
-
-#include "socket-protocol-list.h"
-#include "macro.h"
-
-static const struct socket_protocol_name* lookup_socket_protocol(register const char *str, register GPERF_LEN_TYPE len);
-
-#include "socket-protocol-from-name.h"
-#include "socket-protocol-to-name.h"
-
-const char *socket_protocol_to_name(int id) {
-
-        if (id < 0)
-                return NULL;
-
-        if (id >= (int) ELEMENTSOF(socket_protocol_names))
-                return NULL;
-
-        return socket_protocol_names[id];
-}
-
-int socket_protocol_from_name(const char *name) {
-        const struct socket_protocol_name *sc;
-
-        assert(name);
-
-        sc = lookup_socket_protocol(name, strlen(name));
-        if (!sc)
-                return -EINVAL;
-
-        return sc->id;
-}
diff --git a/src/shared/socket-protocol-list.h b/src/shared/socket-protocol-list.h
deleted file mode 100644 (file)
index 08b36e1..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
-#pragma once
-
-const char *socket_protocol_to_name(int id);
-int socket_protocol_from_name(const char *name);