]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
socket: resolve unit specifiers in BindToDevice
authorPaul Fertser <fercerpav@gmail.com>
Tue, 11 Feb 2025 13:33:15 +0000 (13:33 +0000)
committerLennart Poettering <lennart@poettering.net>
Wed, 12 Feb 2025 11:03:42 +0000 (12:03 +0100)
There are cases where templated Socket unit files are used for network services
with interface name used as an instance. This patch allows using %i for
BindToDevice setting to limit the scope automatically.

src/core/load-fragment.c

index fe60f2725975d9b2672d3e160906c78edfa92dae..a5b9f9eca9af0d6a86b21cfbfa5f2417155f2a56 100644 (file)
@@ -1091,7 +1091,9 @@ int config_parse_socket_bindtodevice(
                 void *data,
                 void *userdata) {
 
+        _cleanup_free_ char *p = NULL;
         Socket *s = ASSERT_PTR(data);
+        int r;
 
         assert(filename);
         assert(lvalue);
@@ -1102,12 +1104,18 @@ int config_parse_socket_bindtodevice(
                 return 0;
         }
 
-        if (!ifname_valid(rvalue)) {
-                log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid interface name, ignoring: %s", rvalue);
+        r = unit_full_printf(UNIT(s), rvalue, &p);
+        if (r < 0) {
+                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue);
+                return 0;
+        }
+
+        if (!ifname_valid(p)) {
+                log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid interface name, ignoring: %s", p);
                 return 0;
         }
 
-        return free_and_strdup_warn(&s->bind_to_device, rvalue);
+        return free_and_replace(s->bind_to_device, p);
 }
 
 int config_parse_exec_input(