Skip to content

Commit da96ad5

Browse files
committed
util: rename socket_protocol_{from,to}_name() to ip_protocol_{from,to}_name()
1 parent 5dd9527 commit da96ad5

12 files changed

+73
-73
lines changed

src/core/dbus-socket.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#include "dbus-socket.h"
99
#include "dbus-util.h"
1010
#include "fd-util.h"
11+
#include "ip-protocol-list.h"
1112
#include "parse-util.h"
1213
#include "path-util.h"
1314
#include "socket.h"
14-
#include "socket-protocol-list.h"
1515
#include "socket-util.h"
1616
#include "string-util.h"
1717
#include "unit.h"
@@ -138,14 +138,14 @@ static inline bool check_size_t_truncation(uint64_t t) {
138138
return (size_t) t == t;
139139
}
140140

141-
static inline const char* supported_socket_protocol_to_string(int32_t i) {
141+
static inline const char* socket_protocol_to_string(int32_t i) {
142142
if (i == IPPROTO_IP)
143143
return "";
144144

145145
if (!IN_SET(i, IPPROTO_UDPLITE, IPPROTO_SCTP))
146146
return NULL;
147147

148-
return socket_protocol_to_name(i);
148+
return ip_protocol_to_name(i);
149149
}
150150

151151
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,
155155
static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(fdname, fdname_is_valid);
156156
static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(ifname, ifname_valid);
157157
static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(ip_tos, "i", int32_t, int, "%" PRIi32, ip_tos_to_string_alloc);
158-
static BUS_DEFINE_SET_TRANSIENT_TO_STRING(socket_protocol, "i", int32_t, int, "%" PRIi32, supported_socket_protocol_to_string);
158+
static BUS_DEFINE_SET_TRANSIENT_TO_STRING(socket_protocol, "i", int32_t, int, "%" PRIi32, socket_protocol_to_string);
159159

160160
static int bus_socket_set_transient_property(
161161
Socket *s,

src/core/load-fragment.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "hexdecoct.h"
3535
#include "io-util.h"
3636
#include "ioprio.h"
37+
#include "ip-protocol-list.h"
3738
#include "journal-util.h"
3839
#include "load-fragment.h"
3940
#include "log.h"
@@ -48,7 +49,6 @@
4849
#include "securebits.h"
4950
#include "securebits-util.h"
5051
#include "signal-util.h"
51-
#include "socket-protocol-list.h"
5252
#include "stat-util.h"
5353
#include "string-util.h"
5454
#include "strv.h"
@@ -57,13 +57,13 @@
5757
#include "user-util.h"
5858
#include "web-util.h"
5959

60-
static int supported_socket_protocol_from_string(const char *s) {
60+
static int socket_protocol_from_string(const char *s) {
6161
int r;
6262

6363
if (isempty(s))
6464
return IPPROTO_IP;
6565

66-
r = socket_protocol_from_name(s);
66+
r = ip_protocol_from_name(s);
6767
if (r < 0)
6868
return r;
6969
if (!IN_SET(r, IPPROTO_UDPLITE, IPPROTO_SCTP))
@@ -72,7 +72,7 @@ static int supported_socket_protocol_from_string(const char *s) {
7272
return r;
7373
}
7474

75-
DEFINE_CONFIG_PARSE(config_parse_socket_protocol, supported_socket_protocol_from_string, "Failed to parse socket protocol");
75+
DEFINE_CONFIG_PARSE(config_parse_socket_protocol, socket_protocol_from_string, "Failed to parse socket protocol");
7676
DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits, secure_bits_from_string, "Failed to parse secure bits");
7777
DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode, collect_mode, CollectMode, "Failed to parse garbage collection mode");
7878
DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy, cgroup_device_policy, CGroupDevicePolicy, "Failed to parse device policy");

src/core/socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "fs-util.h"
2525
#include "in-addr-util.h"
2626
#include "io-util.h"
27+
#include "ip-protocol-list.h"
2728
#include "label.h"
2829
#include "log.h"
2930
#include "missing.h"
@@ -35,7 +36,6 @@
3536
#include "serialize.h"
3637
#include "signal-util.h"
3738
#include "smack-util.h"
38-
#include "socket-protocol-list.h"
3939
#include "socket.h"
4040
#include "special.h"
4141
#include "string-table.h"
@@ -814,7 +814,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
814814
prefix, format_timespan(time_string, FORMAT_TIMESPAN_MAX, s->trigger_limit.interval, USEC_PER_SEC),
815815
prefix, s->trigger_limit.burst);
816816

817-
str = socket_protocol_to_name(s->socket_protocol);
817+
str = ip_protocol_to_name(s->socket_protocol);
818818
if (str)
819819
fprintf(f, "%sSocketProtocol: %s\n", prefix, str);
820820

src/network/networkd-routing-policy-rule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
#include "alloc-util.h"
77
#include "conf-parser.h"
88
#include "fileio.h"
9+
#include "ip-protocol-list.h"
910
#include "networkd-routing-policy-rule.h"
1011
#include "netlink-util.h"
1112
#include "networkd-manager.h"
1213
#include "parse-util.h"
13-
#include "socket-protocol-list.h"
1414
#include "socket-util.h"
1515
#include "string-util.h"
1616
#include "strv.h"
@@ -958,7 +958,7 @@ int config_parse_routing_policy_rule_protocol(
958958
if (r < 0)
959959
return r;
960960

961-
r = socket_protocol_from_name(rvalue);
961+
r = ip_protocol_from_name(rvalue);
962962
if (r < 0) {
963963
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse routing policy rule protocol, ignoring: %s", rvalue);
964964
return 0;

src/shared/bus-unit-util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "hexdecoct.h"
1616
#include "hostname-util.h"
1717
#include "in-addr-util.h"
18+
#include "ip-protocol-list.h"
1819
#include "list.h"
1920
#include "locale-util.h"
2021
#include "mountpoint-util.h"
@@ -25,7 +26,6 @@
2526
#include "rlimit-util.h"
2627
#include "securebits-util.h"
2728
#include "signal-util.h"
28-
#include "socket-protocol-list.h"
2929
#include "string-util.h"
3030
#include "syslog-util.h"
3131
#include "terminal-util.h"
@@ -103,7 +103,7 @@ DEFINE_BUS_APPEND_PARSE("i", parse_errno);
103103
DEFINE_BUS_APPEND_PARSE("i", sched_policy_from_string);
104104
DEFINE_BUS_APPEND_PARSE("i", secure_bits_from_string);
105105
DEFINE_BUS_APPEND_PARSE("i", signal_from_string);
106-
DEFINE_BUS_APPEND_PARSE("i", socket_protocol_from_name);
106+
DEFINE_BUS_APPEND_PARSE("i", ip_protocol_from_name);
107107
DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, ioprio_parse_priority);
108108
DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, parse_nice);
109109
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
14661466

14671467
if (streq(field, "SocketProtocol"))
14681468

1469-
return bus_append_socket_protocol_from_name(m, field, eq);
1469+
return bus_append_ip_protocol_from_name(m, field, eq);
14701470

14711471
if (STR_IN_SET(field,
14721472
"ListenStream", "ListenDatagram", "ListenSequentialPacket", "ListenNetlink",
File renamed without changes.

src/shared/ip-protocol-list.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* SPDX-License-Identifier: LGPL-2.1+ */
2+
3+
#include <errno.h>
4+
#include <netinet/in.h>
5+
#include <string.h>
6+
7+
#include "ip-protocol-list.h"
8+
#include "macro.h"
9+
10+
static const struct ip_protocol_name* lookup_ip_protocol(register const char *str, register GPERF_LEN_TYPE len);
11+
12+
#include "ip-protocol-from-name.h"
13+
#include "ip-protocol-to-name.h"
14+
15+
const char *ip_protocol_to_name(int id) {
16+
17+
if (id < 0)
18+
return NULL;
19+
20+
if (id >= (int) ELEMENTSOF(ip_protocol_names))
21+
return NULL;
22+
23+
return ip_protocol_names[id];
24+
}
25+
26+
int ip_protocol_from_name(const char *name) {
27+
const struct ip_protocol_name *sc;
28+
29+
assert(name);
30+
31+
sc = lookup_ip_protocol(name, strlen(name));
32+
if (!sc)
33+
return -EINVAL;
34+
35+
return sc->id;
36+
}

src/shared/ip-protocol-list.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* SPDX-License-Identifier: LGPL-2.1+ */
2+
#pragma once
3+
4+
const char *ip_protocol_to_name(int id);
5+
int ip_protocol_from_name(const char *name);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
BEGIN{
2-
print "static const char* const socket_protocol_names[] = { "
2+
print "static const char* const ip_protocol_names[] = { "
33
}
44
!/HOPOPTS/ {
55
printf " [IPPROTO_%s] = \"%s\",\n", $1, tolower($1)

src/shared/meson.build

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ shared_sources = files('''
127127
serialize.h
128128
sleep-config.c
129129
sleep-config.h
130-
socket-protocol-list.c
131-
socket-protocol-list.h
130+
ip-protocol-list.c
131+
ip-protocol-list.h
132132
spawn-ask-password-agent.c
133133
spawn-ask-password-agent.h
134134
spawn-polkit-agent.c
@@ -188,39 +188,39 @@ if conf.get('HAVE_KMOD') == 1
188188
shared_sources += files('module-util.c')
189189
endif
190190

191-
generate_socket_protocol_list = find_program('generate-socket-protocol-list.sh')
192-
socket_protocol_list_txt = custom_target(
193-
'socket-protocol-list.txt',
194-
output : 'socket-protocol-list.txt',
195-
command : [generate_socket_protocol_list, cpp],
191+
generate_ip_protocol_list = find_program('generate-ip-protocol-list.sh')
192+
ip_protocol_list_txt = custom_target(
193+
'ip-protocol-list.txt',
194+
output : 'ip-protocol-list.txt',
195+
command : [generate_ip_protocol_list, cpp],
196196
capture : true)
197197

198-
fname = 'socket-protocol-from-name.gperf'
198+
fname = 'ip-protocol-from-name.gperf'
199199
gperf_file = custom_target(
200200
fname,
201-
input : socket_protocol_list_txt,
201+
input : ip_protocol_list_txt,
202202
output : fname,
203-
command : [generate_gperfs, 'socket_protocol', 'IPPROTO_', '@INPUT@'],
203+
command : [generate_gperfs, 'ip_protocol', 'IPPROTO_', '@INPUT@'],
204204
capture : true)
205205

206-
fname = 'socket-protocol-from-name.h'
206+
fname = 'ip-protocol-from-name.h'
207207
target1 = custom_target(
208208
fname,
209209
input : gperf_file,
210210
output : fname,
211211
command : [gperf,
212212
'-L', 'ANSI-C', '-t', '--ignore-case',
213-
'-N', 'lookup_socket_protocol',
214-
'-H', 'hash_socket_protocol_name',
213+
'-N', 'lookup_ip_protocol',
214+
'-H', 'hash_ip_protocol_name',
215215
'-p', '-C',
216216
'@INPUT@'],
217217
capture : true)
218218

219-
fname = 'socket-protocol-to-name.h'
220-
awkscript = 'socket-protocol-to-name.awk'
219+
fname = 'ip-protocol-to-name.h'
220+
awkscript = 'ip-protocol-to-name.awk'
221221
target2 = custom_target(
222222
fname,
223-
input : [awkscript, socket_protocol_list_txt],
223+
input : [awkscript, ip_protocol_list_txt],
224224
output : fname,
225225
command : [awk, '-f', '@INPUT0@', '@INPUT1@'],
226226
capture : true)

0 commit comments

Comments
 (0)