1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2015 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "alloc-util.h"
24 #include "conf-parser.h"
25 #include "nspawn-network.h"
26 #include "nspawn-settings.h"
27 #include "process-util.h"
31 int settings_load(FILE *f
, const char *path
, Settings
**ret
) {
32 _cleanup_(settings_freep
) Settings
*s
= NULL
;
38 s
= new0(Settings
, 1);
43 s
->personality
= PERSONALITY_INVALID
;
46 s
->volatile_mode
= _VOLATILE_MODE_INVALID
;
48 s
->private_network
= -1;
51 r
= config_parse(NULL
, path
, f
,
55 config_item_perf_lookup
, nspawn_gperf_lookup
,
69 Settings
* settings_free(Settings
*s
) {
74 strv_free(s
->parameters
);
75 strv_free(s
->environment
);
78 strv_free(s
->network_interfaces
);
79 strv_free(s
->network_macvlan
);
80 strv_free(s
->network_ipvlan
);
81 strv_free(s
->network_veth_extra
);
82 free(s
->network_bridge
);
83 expose_port_free_all(s
->expose_ports
);
85 custom_mount_free_all(s
->custom_mounts
, s
->n_custom_mounts
);
91 bool settings_private_network(Settings
*s
) {
95 s
->private_network
> 0 ||
96 s
->network_veth
> 0 ||
98 s
->network_interfaces
||
101 s
->network_veth_extra
;
104 bool settings_network_veth(Settings
*s
) {
108 s
->network_veth
> 0 ||
112 DEFINE_CONFIG_PARSE_ENUM(config_parse_volatile_mode
, volatile_mode
, VolatileMode
, "Failed to parse volatile mode");
114 int config_parse_expose_port(
116 const char *filename
,
119 unsigned section_line
,
133 r
= expose_port_parse(&s
->expose_ports
, rvalue
);
135 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Duplicate port specification, ignoring: %s", rvalue
);
139 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse host port %s: %m", rvalue
);
146 int config_parse_capability(
148 const char *filename
,
151 unsigned section_line
,
158 uint64_t u
= 0, *result
= data
;
166 _cleanup_free_
char *word
= NULL
;
169 r
= extract_first_word(&rvalue
, &word
, NULL
, 0);
171 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract capability string, ignoring: %s", rvalue
);
177 cap
= capability_from_name(word
);
179 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse capability, ignoring: %s", word
);
183 u
|= 1 << ((uint64_t) cap
);
193 int config_parse_id128(
195 const char *filename
,
198 unsigned section_line
,
205 sd_id128_t t
, *result
= data
;
212 r
= sd_id128_from_string(rvalue
, &t
);
214 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse 128bit ID/UUID, ignoring: %s", rvalue
);
222 int config_parse_bind(
224 const char *filename
,
227 unsigned section_line
,
234 Settings
*settings
= data
;
241 r
= bind_mount_parse(&settings
->custom_mounts
, &settings
->n_custom_mounts
, rvalue
, ltype
);
243 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid bind mount specification %s: %m", rvalue
);
250 int config_parse_tmpfs(
252 const char *filename
,
255 unsigned section_line
,
262 Settings
*settings
= data
;
269 r
= tmpfs_mount_parse(&settings
->custom_mounts
, &settings
->n_custom_mounts
, rvalue
);
271 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid temporary file system specification %s: %m", rvalue
);
278 int config_parse_veth_extra(
280 const char *filename
,
283 unsigned section_line
,
290 Settings
*settings
= data
;
297 r
= veth_extra_parse(&settings
->network_veth_extra
, rvalue
);
299 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid extra virtual Ethernet link specification %s: %m", rvalue
);