1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-31 14:50:15 +03:00

socket: resolve unit specifiers in BindToDevice

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.
This commit is contained in:
Paul Fertser 2025-02-11 13:33:15 +00:00 committed by Lennart Poettering
parent 6cbd126b0b
commit a3aad16c6e

View 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;
}
return free_and_strdup_warn(&s->bind_to_device, rvalue);
if (!ifname_valid(p)) {
log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid interface name, ignoring: %s", p);
return 0;
}
return free_and_replace(s->bind_to_device, p);
}
int config_parse_exec_input(