summaryrefslogtreecommitdiff
path: root/src/nspawn
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-11-09 18:21:15 +0100
committerLennart Poettering <lennart@poettering.net>2021-11-09 18:32:10 +0100
commita1dfd585c4a3a737b0c4b61e82148bbdfd201733 (patch)
treeef5087c0ceafce097c89dd6aa2556cd4c15f92c5 /src/nspawn
parent8c1e088ac9ca2722122774d6839fae3ccf6b48fc (diff)
downloadsystemd-a1dfd585c4a3a737b0c4b61e82148bbdfd201733.tar.gz
nspawn: add helper settings_network_configured()
The new helper returns whether the settings file had *any* networking setting configured at all. We already have a similar helper settings_private_network() which returns a similar result. The difference is that the new helper will return true when the private network was explicitly turned off, while the old one will only return true if configured and enabled. We'll reuse the helper a 2nd time later on, but even without it it makes things a bit more readable.
Diffstat (limited to 'src/nspawn')
-rw-r--r--src/nspawn/nspawn-settings.c21
-rw-r--r--src/nspawn/nspawn-settings.h2
-rw-r--r--src/nspawn/nspawn.c10
3 files changed, 24 insertions, 9 deletions
diff --git a/src/nspawn/nspawn-settings.c b/src/nspawn/nspawn-settings.c
index fc9e9fc54f..c63b8da23a 100644
--- a/src/nspawn/nspawn-settings.c
+++ b/src/nspawn/nspawn-settings.c
@@ -170,6 +170,8 @@ Settings* settings_free(Settings *s) {
bool settings_private_network(Settings *s) {
assert(s);
+ /* Determines whether we shall open up our own private network */
+
return
s->private_network > 0 ||
s->network_veth > 0 ||
@@ -190,6 +192,25 @@ bool settings_network_veth(Settings *s) {
s->network_zone;
}
+bool settings_network_configured(Settings *s) {
+ assert(s);
+
+ /* Determines whether any network configuration setting was used. (i.e. in contrast to
+ * settings_private_network() above this might also indicate if private networking was explicitly
+ * turned off.) */
+
+ return
+ s->private_network >= 0 ||
+ s->network_veth >= 0 ||
+ s->network_bridge ||
+ s->network_zone ||
+ s->network_interfaces ||
+ s->network_macvlan ||
+ s->network_ipvlan ||
+ s->network_veth_extra ||
+ s->network_namespace_path;
+}
+
int settings_allocate_properties(Settings *s) {
_cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
int r;
diff --git a/src/nspawn/nspawn-settings.h b/src/nspawn/nspawn-settings.h
index 1b3ace5f8f..797e383401 100644
--- a/src/nspawn/nspawn-settings.h
+++ b/src/nspawn/nspawn-settings.h
@@ -242,6 +242,8 @@ Settings* settings_free(Settings *s);
bool settings_network_veth(Settings *s);
bool settings_private_network(Settings *s);
+bool settings_network_configured(Settings *s);
+
int settings_allocate_properties(Settings *s);
DEFINE_TRIVIAL_CLEANUP_FUNC(Settings*, settings_free);
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 1f327b0952..f8f9e72421 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -4407,15 +4407,7 @@ static int merge_settings(Settings *settings, const char *path) {
}
if ((arg_settings_mask & SETTING_NETWORK) == 0 &&
- (settings->private_network >= 0 ||
- settings->network_veth >= 0 ||
- settings->network_bridge ||
- settings->network_zone ||
- settings->network_interfaces ||
- settings->network_macvlan ||
- settings->network_ipvlan ||
- settings->network_veth_extra ||
- settings->network_namespace_path)) {
+ settings_network_configured(settings)) {
if (!arg_settings_trusted)
log_warning("Ignoring network settings, file %s is not trusted.", path);