]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
socket-bind: use lowercase "ipv4"/"ipv6" spelling
authorLennart Poettering <lennart@poettering.net>
Mon, 10 May 2021 14:33:24 +0000 (16:33 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 11 May 2021 13:37:31 +0000 (15:37 +0200)
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
src/core/cgroup.c
src/core/load-fragment.c
src/shared/bus-unit-util.c
src/systemctl/systemctl-show.c
src/test/test-socket-bind.c

index d9b570e232cac4efc903a91dcc1be576ba1e14fc..827f343a50a98bd09470d8433aef09506871926c 100644 (file)
@@ -775,7 +775,7 @@ BPFProgram=bind6:/sys/fs/bpf/sock-addr-hook
 
           <para><replaceable>bind-rule</replaceable> := [<replaceable>address-family</replaceable><constant>:</constant>]<replaceable>ip-ports</replaceable></para>
 
-          <para><replaceable>address-family</replaceable> := { <constant>IPv4</constant> | <constant>IPv6</constant> }</para>
+          <para><replaceable>address-family</replaceable> := { <constant>ipv4</constant> | <constant>ipv6</constant> }</para>
 
           <para><replaceable>ip-ports</replaceable> := { <replaceable>ip-port</replaceable> | <replaceable>ip-port-range</replaceable> |
           <constant>any</constant> }</para>
@@ -812,7 +812,7 @@ BPFProgram=bind6:/sys/fs/bpf/sock-addr-hook
           <para>Examples:<programlisting>…
 # 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]
index a44cf9368c71a49a9a8d648b06da54e6059f1c37..87e8cdf7eeb1d3a434cf7d2f64ce7a3a75299ee4 100644 (file)
@@ -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);
index 2399089492e6a6f12bc079137a7ead1f7e393b4d..a7d1cb6f121e27b329ae0f9742080078a45d3af4 100644 (file)
@@ -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;
                 }
 
index 20d368efcae818e5fcc9a1b6ea500d5761344114..4d53aaa3da554506f7029b77bd8fa951c4c437f0 100644 (file)
@@ -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;
index 2df05464c6106dd55f81fc4ae736f6b93b70ae89..d43f1cf09476115912f51292eddb3e3147009ae6 100644 (file)
@@ -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)
index bfe5072bc3de01a5bb5e912545368ecd54786ac1..16cfea777993efe85820cd9aebfb57a88aa74875 100644 (file)
@@ -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);