From f80a206aa497c1a1ce2a7bfc024ea2080f357aeb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 10 May 2021 16:33:24 +0200 Subject: [PATCH] socket-bind: use lowercase "ipv4"/"ipv6" spelling In most of our codebase when we referenced "ipv4" and "ipv6" on the right-hand-side of an assignment, we lowercases it (on the left-hand-side we used CamelCase, and thus "IPv4" and "IPv6"). In particular all across the networkd codebase the various "per-protocol booleans" use the lower-case spelling. Hence, let's use lower-case for SocketBindAllow=/SocketBindDeny= too, just make sure things feel like they belong together better. (This work is not included in any released version, hence let's fix this now, before any fixes in this area would be API breakage) Follow-up for #17655 --- man/systemd.resource-control.xml | 6 +++--- src/core/cgroup.c | 5 +++-- src/core/load-fragment.c | 6 +++--- src/shared/bus-unit-util.c | 11 +++++------ src/systemctl/systemctl-show.c | 2 +- src/test/test-socket-bind.c | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/man/systemd.resource-control.xml b/man/systemd.resource-control.xml index d9b570e232c..827f343a50a 100644 --- a/man/systemd.resource-control.xml +++ b/man/systemd.resource-control.xml @@ -775,7 +775,7 @@ BPFProgram=bind6:/sys/fs/bpf/sock-addr-hook bind-rule := [address-family:]ip-ports - address-family := { IPv4 | IPv6 } + address-family := { ipv4 | ipv6 } ip-ports := { ip-port | ip-port-range | any } @@ -812,7 +812,7 @@ BPFProgram=bind6:/sys/fs/bpf/sock-addr-hook Examples:… # Allow binding IPv6 socket addresses with a port greater than or equal to 10000. [Service] -SocketBindAllow=IPv6:10000-65535 +SocketBindAllow=ipv6:10000-65535 SocketBindDeny=any … # Allow binding IPv4 and IPv6 socket addresses with 1234 and 4321 ports. @@ -823,7 +823,7 @@ SocketBindDeny=any … # Deny binding IPv6 socket addresses. [Service] -SocketBindDeny=IPv6:any +SocketBindDeny=ipv6:any … # Deny binding IPv4 and IPv6 socket addresses. [Service] diff --git a/src/core/cgroup.c b/src/core/cgroup.c index a44cf9368c7..87e8cdf7eeb 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -594,8 +594,9 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { } void cgroup_context_dump_socket_bind_item(const CGroupSocketBindItem *item, FILE *f) { - const char *family = item->address_family == AF_INET ? "IPv4:" : - item->address_family == AF_INET6 ? "IPv6:" : ""; + const char *family = + item->address_family == AF_INET ? "ipv4:" : + item->address_family == AF_INET6 ? "ipv6:" : ""; if (item->nr_ports == 0) fprintf(f, " %sany", family); diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 2399089492e..a7d1cb6f121 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -5661,13 +5661,13 @@ int config_parse_cgroup_socket_bind( } if (rvalue) { - if (streq(word, "IPv4")) + if (streq(word, "ipv4")) af = AF_INET; - else if (streq(word, "IPv6")) + else if (streq(word, "ipv6")) af = AF_INET6; else { log_syntax(unit, LOG_WARNING, filename, line, 0, - "Only IPv4 and IPv6 protocols are supported, ignoring."); + "Only \"ipv4\" and \"ipv6\" protocols are supported, ignoring."); return 0; } diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 20d368efcae..4d53aaa3da5 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -879,14 +879,13 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons address_family = eq ? word : NULL; if (address_family) { - if (!STR_IN_SET(address_family, "IPv4", "IPv6")) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "Only IPv4 and IPv6 protocols are supported"); - - if (streq(address_family, "IPv4")) + if (streq(address_family, "ipv4")) family = AF_INET; - else + else if (streq(address_family, "ipv6")) family = AF_INET6; + else + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Only \"ipv4\" and \"ipv6\" protocols are supported"); } user_port = eq ? eq : word; diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index 2df05464c61..d43f1cf0947 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -1717,7 +1717,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m if (r < 0) return bus_log_parse_error(r); while ((r = sd_bus_message_read(m, "(iqq)", &af, &nr_ports, &port_min)) > 0) { - family = af == AF_INET ? "IPv4:" : af == AF_INET6 ? "IPv6:" : ""; + family = af == AF_INET ? "ipv4:" : af == AF_INET6 ? "ipv6:" : ""; if (nr_ports == 0) bus_print_property_valuef(name, expected_value, flags, "%sany", family); else if (nr_ports == 1) diff --git a/src/test/test-socket-bind.c b/src/test/test-socket-bind.c index bfe5072bc3d..16cfea77799 100644 --- a/src/test/test-socket-bind.c +++ b/src/test/test-socket-bind.c @@ -141,8 +141,8 @@ int main(int argc, char *argv[]) { assert_se(manager_startup(m, NULL, NULL) >= 0); assert_se(test_socket_bind(m, "socket_bind_test.service", netcat_path, "2000", STRV_MAKE("2000"), STRV_MAKE("any")) >= 0); - assert_se(test_socket_bind(m, "socket_bind_test.service", netcat_path, "2000", STRV_MAKE("IPv6:2001-2002"), STRV_MAKE("any")) >= 0); - assert_se(test_socket_bind(m, "socket_bind_test.service", netcat_path, "6666", STRV_MAKE("IPv4:6666", "6667"), STRV_MAKE("any")) >= 0); + assert_se(test_socket_bind(m, "socket_bind_test.service", netcat_path, "2000", STRV_MAKE("ipv6:2001-2002"), STRV_MAKE("any")) >= 0); + assert_se(test_socket_bind(m, "socket_bind_test.service", netcat_path, "6666", STRV_MAKE("ipv4:6666", "6667"), STRV_MAKE("any")) >= 0); assert_se(test_socket_bind(m, "socket_bind_test.service", netcat_path, "6666", STRV_MAKE("6667", "6668", ""), STRV_MAKE("any")) >= 0); assert_se(test_socket_bind(m, "socket_bind_test.service", netcat_path, "7777", STRV_MAKE_EMPTY, STRV_MAKE_EMPTY) >= 0); assert_se(test_socket_bind(m, "socket_bind_test.service", netcat_path, "8888", STRV_MAKE("any"), STRV_MAKE("any")) >= 0); -- 2.47.3