2 * lxc: linux Container library
3 * (C) Copyright IBM Corp. 2007, 2008
6 * Daniel Lezcano <daniel.lezcano at free.fr>
7 * Serge Hallyn <serge@hallyn.com>
8 * Christian Brauner <christian.brauner@ubuntu.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #define __STDC_FORMAT_MACROS
39 #include <arpa/inet.h>
41 #include <netinet/in.h>
42 #include <sys/param.h>
44 #include <sys/types.h>
45 #include <sys/utsname.h>
50 #include "confile_legacy.h"
51 #include "confile_utils.h"
53 #include "lxcseccomp.h"
62 #include <../include/ifaddrs.h>
65 #if HAVE_SYS_PERSONALITY_H
66 #include <sys/personality.h>
69 lxc_log_define(lxc_confile
, lxc
);
71 #define lxc_config_define(name) \
72 static int set_config_##name(const char *, const char *, \
73 struct lxc_conf *, void *); \
74 static int get_config_##name(const char *, char *, int, \
75 struct lxc_conf *, void *); \
76 static int clr_config_##name(const char *, struct lxc_conf *, void *);
78 lxc_config_define(autodev
);
79 lxc_config_define(apparmor_allow_incomplete
);
80 lxc_config_define(apparmor_profile
);
81 lxc_config_define(cap_drop
);
82 lxc_config_define(cap_keep
);
83 lxc_config_define(cgroup_controller
);
84 lxc_config_define(cgroup_dir
);
85 lxc_config_define(console_logfile
);
86 lxc_config_define(console_rotate
);
87 lxc_config_define(console_buffer_logfile
);
88 lxc_config_define(console_buffer_size
);
89 lxc_config_define(console_path
);
90 lxc_config_define(environment
);
91 lxc_config_define(ephemeral
);
92 lxc_config_define(execute_cmd
);
93 lxc_config_define(group
);
94 lxc_config_define(hooks
);
95 lxc_config_define(idmaps
);
96 lxc_config_define(includefiles
);
97 lxc_config_define(init_cmd
);
98 lxc_config_define(init_cwd
);
99 lxc_config_define(init_gid
);
100 lxc_config_define(init_uid
);
101 lxc_config_define(log_file
);
102 lxc_config_define(log_level
);
103 lxc_config_define(log_syslog
);
104 lxc_config_define(monitor
);
105 lxc_config_define(mount
);
106 lxc_config_define(mount_auto
);
107 lxc_config_define(mount_fstab
);
108 lxc_config_define(namespace);
109 lxc_config_define(net
);
110 lxc_config_define(net_flags
);
111 lxc_config_define(net_hwaddr
);
112 lxc_config_define(net_ipv4_address
);
113 lxc_config_define(net_ipv4_gateway
);
114 lxc_config_define(net_ipv6_address
);
115 lxc_config_define(net_ipv6_gateway
);
116 lxc_config_define(net_link
);
117 lxc_config_define(net_macvlan_mode
);
118 lxc_config_define(net_mtu
);
119 lxc_config_define(net_name
);
120 lxc_config_define(net_nic
);
121 lxc_config_define(net_script_down
);
122 lxc_config_define(net_script_up
);
123 lxc_config_define(net_type
);
124 lxc_config_define(net_veth_pair
);
125 lxc_config_define(net_vlan_id
);
126 lxc_config_define(no_new_privs
);
127 lxc_config_define(noop
);
128 lxc_config_define(personality
);
129 lxc_config_define(prlimit
);
130 lxc_config_define(pty_max
);
131 lxc_config_define(rootfs_backend
);
132 lxc_config_define(rootfs_mount
);
133 lxc_config_define(rootfs_options
);
134 lxc_config_define(rootfs_path
);
135 lxc_config_define(seccomp_profile
);
136 lxc_config_define(selinux_context
);
137 lxc_config_define(signal_halt
);
138 lxc_config_define(signal_reboot
);
139 lxc_config_define(signal_stop
);
140 lxc_config_define(start
);
141 lxc_config_define(tty_max
);
142 lxc_config_define(tty_dir
);
143 lxc_config_define(uts_name
);
145 static struct lxc_config_t config
[] = {
146 /* REMOVE in LXC 3.0 */
147 { "lxc.arch", false, set_config_personality
, get_config_personality
, clr_config_personality
, },
148 { "lxc.apparmor.profile", false, set_config_apparmor_profile
, get_config_apparmor_profile
, clr_config_apparmor_profile
, },
149 { "lxc.apparmor.allow_incomplete", false, set_config_apparmor_allow_incomplete
, get_config_apparmor_allow_incomplete
, clr_config_apparmor_allow_incomplete
, },
150 { "lxc.autodev", false, set_config_autodev
, get_config_autodev
, clr_config_autodev
, },
151 { "lxc.cap.drop", false, set_config_cap_drop
, get_config_cap_drop
, clr_config_cap_drop
, },
152 { "lxc.cap.keep", false, set_config_cap_keep
, get_config_cap_keep
, clr_config_cap_keep
, },
153 { "lxc.cgroup.dir", false, set_config_cgroup_dir
, get_config_cgroup_dir
, clr_config_cgroup_dir
, },
154 { "lxc.cgroup", false, set_config_cgroup_controller
, get_config_cgroup_controller
, clr_config_cgroup_controller
, },
155 { "lxc.console.buffer.logfile", false, set_config_console_buffer_logfile
, get_config_console_buffer_logfile
, clr_config_console_buffer_logfile
, },
156 { "lxc.console.buffer.size", false, set_config_console_buffer_size
, get_config_console_buffer_size
, clr_config_console_buffer_size
, },
157 { "lxc.console.logfile", false, set_config_console_logfile
, get_config_console_logfile
, clr_config_console_logfile
, },
158 { "lxc.console.path", false, set_config_console_path
, get_config_console_path
, clr_config_console_path
, },
159 { "lxc.console.rotate", false, set_config_console_rotate
, get_config_console_rotate
, clr_config_console_rotate
, },
160 { "lxc.environment", false, set_config_environment
, get_config_environment
, clr_config_environment
, },
161 { "lxc.ephemeral", false, set_config_ephemeral
, get_config_ephemeral
, clr_config_ephemeral
, },
162 { "lxc.execute.cmd", false, set_config_execute_cmd
, get_config_execute_cmd
, clr_config_execute_cmd
, },
163 { "lxc.group", false, set_config_group
, get_config_group
, clr_config_group
, },
164 { "lxc.hook.autodev", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
165 { "lxc.hook.clone", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
166 { "lxc.hook.destroy", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
167 { "lxc.hook.mount", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
168 { "lxc.hook.post-stop", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
169 { "lxc.hook.start-host", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
170 { "lxc.hook.pre-start", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
171 { "lxc.hook.pre-mount", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
172 { "lxc.hook.start", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
173 { "lxc.hook.stop", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
174 { "lxc.hook", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
175 { "lxc.idmap", false, set_config_idmaps
, get_config_idmaps
, clr_config_idmaps
, },
176 { "lxc.include", false, set_config_includefiles
, get_config_includefiles
, clr_config_includefiles
, },
177 { "lxc.init.cmd", false, set_config_init_cmd
, get_config_init_cmd
, clr_config_init_cmd
, },
178 { "lxc.init.gid", false, set_config_init_gid
, get_config_init_gid
, clr_config_init_gid
, },
179 { "lxc.init.uid", false, set_config_init_uid
, get_config_init_uid
, clr_config_init_uid
, },
180 { "lxc.init.cwd", false, set_config_init_cwd
, get_config_init_cwd
, clr_config_init_cwd
, },
181 { "lxc.log.file", false, set_config_log_file
, get_config_log_file
, clr_config_log_file
, },
182 { "lxc.log.level", false, set_config_log_level
, get_config_log_level
, clr_config_log_level
, },
183 { "lxc.log.syslog", false, set_config_log_syslog
, get_config_log_syslog
, clr_config_log_syslog
, },
184 { "lxc.monitor.unshare", false, set_config_monitor
, get_config_monitor
, clr_config_monitor
, },
185 { "lxc.mount.auto", false, set_config_mount_auto
, get_config_mount_auto
, clr_config_mount_auto
, },
186 { "lxc.mount.entry", false, set_config_mount
, get_config_mount
, clr_config_mount
, },
187 { "lxc.mount.fstab", false, set_config_mount_fstab
, get_config_mount_fstab
, clr_config_mount_fstab
, },
188 { "lxc.namespace", false, set_config_namespace
, get_config_namespace
, clr_config_namespace
, },
190 /* [START]: REMOVE IN LXC 3.0 */
191 { "lxc.network.type", true, set_config_network_legacy_type
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
192 { "lxc.network.flags", true, set_config_network_legacy_flags
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
193 { "lxc.network.link", true, set_config_network_legacy_link
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
194 { "lxc.network.name", true, set_config_network_legacy_name
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
195 { "lxc.network.macvlan.mode", true, set_config_network_legacy_macvlan_mode
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
196 { "lxc.network.veth.pair", true, set_config_network_legacy_veth_pair
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
197 { "lxc.network.script.up", true, set_config_network_legacy_script_up
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
198 { "lxc.network.script.down", true, set_config_network_legacy_script_down
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
199 { "lxc.network.hwaddr", true, set_config_network_legacy_hwaddr
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
200 { "lxc.network.mtu", true, set_config_network_legacy_mtu
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
201 { "lxc.network.vlan.id", true, set_config_network_legacy_vlan_id
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
202 { "lxc.network.ipv4.gateway", true, set_config_network_legacy_ipv4_gateway
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
203 { "lxc.network.ipv4", true, set_config_network_legacy_ipv4
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
204 { "lxc.network.ipv6.gateway", true, set_config_network_legacy_ipv6_gateway
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
205 { "lxc.network.ipv6", true, set_config_network_legacy_ipv6
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
206 { "lxc.network.", true, set_config_network_legacy_nic
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
207 { "lxc.network", true, set_config_network_legacy
, get_config_network_legacy
, clr_config_network_legacy
, },
208 /* [END]: REMOVE IN LXC 3.0 */
210 { "lxc.net.flags", false, set_config_net_flags
, get_config_net_flags
, clr_config_net_flags
, },
211 { "lxc.net.hwaddr", false, set_config_net_hwaddr
, get_config_net_hwaddr
, clr_config_net_hwaddr
, },
212 { "lxc.net.ipv4.address", false, set_config_net_ipv4_address
, get_config_net_ipv4_address
, clr_config_net_ipv4_address
, },
213 { "lxc.net.ipv4.gateway", false, set_config_net_ipv4_gateway
, get_config_net_ipv4_gateway
, clr_config_net_ipv4_gateway
, },
214 { "lxc.net.ipv6.address", false, set_config_net_ipv6_address
, get_config_net_ipv6_address
, clr_config_net_ipv6_address
, },
215 { "lxc.net.ipv6.gateway", false, set_config_net_ipv6_gateway
, get_config_net_ipv6_gateway
, clr_config_net_ipv6_gateway
, },
216 { "lxc.net.link", false, set_config_net_link
, get_config_net_link
, clr_config_net_link
, },
217 { "lxc.net.macvlan.mode", false, set_config_net_macvlan_mode
, get_config_net_macvlan_mode
, clr_config_net_macvlan_mode
, },
218 { "lxc.net.mtu", false, set_config_net_mtu
, get_config_net_mtu
, clr_config_net_mtu
, },
219 { "lxc.net.name", false, set_config_net_name
, get_config_net_name
, clr_config_net_name
, },
220 { "lxc.net.script.down", false, set_config_net_script_down
, get_config_net_script_down
, clr_config_net_script_down
, },
221 { "lxc.net.script.up", false, set_config_net_script_up
, get_config_net_script_up
, clr_config_net_script_up
, },
222 { "lxc.net.type", false, set_config_net_type
, get_config_net_type
, clr_config_net_type
, },
223 { "lxc.net.vlan.id", false, set_config_net_vlan_id
, get_config_net_vlan_id
, clr_config_net_vlan_id
, },
224 { "lxc.net.veth.pair", false, set_config_net_veth_pair
, get_config_net_veth_pair
, clr_config_net_veth_pair
, },
225 { "lxc.net.", false, set_config_net_nic
, get_config_net_nic
, clr_config_net_nic
, },
226 { "lxc.net", false, set_config_net
, get_config_net
, clr_config_net
, },
227 { "lxc.no_new_privs", false, set_config_no_new_privs
, get_config_no_new_privs
, clr_config_no_new_privs
, },
228 { "lxc.prlimit", false, set_config_prlimit
, get_config_prlimit
, clr_config_prlimit
, },
229 { "lxc.pty.max", false, set_config_pty_max
, get_config_pty_max
, clr_config_pty_max
, },
230 { "lxc.rootfs.mount", false, set_config_rootfs_mount
, get_config_rootfs_mount
, clr_config_rootfs_mount
, },
231 { "lxc.rootfs.options", false, set_config_rootfs_options
, get_config_rootfs_options
, clr_config_rootfs_options
, },
232 { "lxc.rootfs.path", false, set_config_rootfs_path
, get_config_rootfs_path
, clr_config_rootfs_path
, },
233 { "lxc.seccomp.profile", false, set_config_seccomp_profile
, get_config_seccomp_profile
, clr_config_seccomp_profile
, },
234 { "lxc.selinux.context", false, set_config_selinux_context
, get_config_selinux_context
, clr_config_selinux_context
, },
235 { "lxc.signal.halt", false, set_config_signal_halt
, get_config_signal_halt
, clr_config_signal_halt
, },
236 { "lxc.signal.reboot", false, set_config_signal_reboot
, get_config_signal_reboot
, clr_config_signal_reboot
, },
237 { "lxc.signal.stop", false, set_config_signal_stop
, get_config_signal_stop
, clr_config_signal_stop
, },
238 { "lxc.start.auto", false, set_config_start
, get_config_start
, clr_config_start
, },
239 { "lxc.start.delay", false, set_config_start
, get_config_start
, clr_config_start
, },
240 { "lxc.start.order", false, set_config_start
, get_config_start
, clr_config_start
, },
241 { "lxc.tty.dir", false, set_config_tty_dir
, get_config_tty_dir
, clr_config_tty_dir
, },
242 { "lxc.tty.max", false, set_config_tty_max
, get_config_tty_max
, clr_config_tty_max
, },
243 { "lxc.uts.name", false, set_config_uts_name
, get_config_uts_name
, clr_config_uts_name
, },
245 /* [START]: REMOVE IN LXC 3.0 */
246 { "lxc.pts", true, set_config_pty_max
, get_config_pty_max
, clr_config_pty_max
, },
247 { "lxc.devttydir", true, set_config_tty_dir
, get_config_tty_dir
, clr_config_tty_dir
, },
248 { "lxc.tty", true, set_config_tty_max
, get_config_tty_max
, clr_config_tty_max
, },
249 { "lxc.aa_profile", true, set_config_lsm_aa_profile
, get_config_lsm_aa_profile
, clr_config_lsm_aa_profile
, },
250 { "lxc.aa_allow_incomplete", true, set_config_lsm_aa_incomplete
, get_config_lsm_aa_incomplete
, clr_config_lsm_aa_incomplete
, },
251 { "lxc.se_context", true, set_config_lsm_se_context
, get_config_lsm_se_context
, clr_config_lsm_se_context
, },
252 { "lxc.id_map", true, set_config_idmaps
, get_config_idmaps
, clr_config_idmaps
, },
253 { "lxc.mount", true, set_config_mount_fstab
, get_config_mount_fstab
, clr_config_mount_fstab
, },
254 { "lxc.rootfs.backend", true, set_config_rootfs_backend
, get_config_rootfs_backend
, clr_config_rootfs_backend
, },
255 { "lxc.rootfs", true, set_config_rootfs_path
, get_config_rootfs_path
, clr_config_rootfs_path
, },
256 { "lxc.utsname", true, set_config_uts_name
, get_config_uts_name
, clr_config_uts_name
, },
257 { "lxc.seccomp", true, set_config_seccomp_profile
, get_config_seccomp_profile
, clr_config_seccomp_profile
, },
258 { "lxc.console", true, set_config_console_path
, get_config_console_path
, clr_config_console_path
, },
259 { "lxc.haltsignal", true, set_config_signal_halt
, get_config_signal_halt
, clr_config_signal_halt
, },
260 { "lxc.rebootsignal", true, set_config_signal_reboot
, get_config_signal_reboot
, clr_config_signal_reboot
, },
261 { "lxc.stopsignal", true, set_config_signal_stop
, get_config_signal_stop
, clr_config_signal_stop
, },
262 { "lxc.syslog", true, set_config_log_syslog
, get_config_log_syslog
, clr_config_log_syslog
, },
263 { "lxc.kmsg", true, set_config_noop
, get_config_noop
, clr_config_noop
, },
264 { "lxc.loglevel", true, set_config_log_level
, get_config_log_level
, clr_config_log_level
, },
265 { "lxc.logfile", true, set_config_log_file
, get_config_log_file
, clr_config_log_file
, },
266 { "lxc.init_cmd", true, set_config_init_cmd
, get_config_init_cmd
, clr_config_init_cmd
, },
267 { "lxc.init_uid", true, set_config_init_uid
, get_config_init_uid
, clr_config_init_uid
, },
268 { "lxc.init_gid", true, set_config_init_gid
, get_config_init_gid
, clr_config_init_gid
, },
269 { "lxc.limit", true, set_config_limit
, get_config_limit
, clr_config_limit
, },
270 { "lxc.pivotdir", true, set_config_noop
, get_config_noop
, clr_config_noop
, },
271 /* [END]: REMOVE IN LXC 3.0 */
279 static const struct signame signames
[] = {
312 { SIGSTKFLT
, "STKFLT" },
327 { SIGVTALRM
, "VTALRM" },
333 { SIGWINCH
, "WINCH" },
351 { SIGUNUSED
, "UNUSED" },
358 static const size_t config_size
= sizeof(config
) / sizeof(struct lxc_config_t
);
360 struct lxc_config_t
*lxc_get_config(const char *key
)
364 for (i
= 0; i
< config_size
; i
++)
365 if (!strncmp(config
[i
].name
, key
, strlen(config
[i
].name
)))
371 static int set_config_net(const char *key
, const char *value
,
372 struct lxc_conf
*lxc_conf
, void *data
)
374 if (!lxc_config_value_empty(value
)) {
375 ERROR("lxc.net must not have a value");
379 return clr_config_net(key
, lxc_conf
, data
);
382 static int set_config_net_type(const char *key
, const char *value
,
383 struct lxc_conf
*lxc_conf
, void *data
)
385 struct lxc_netdev
*netdev
;
387 if (lxc_config_value_empty(value
))
388 return clr_config_net_type(key
, lxc_conf
, data
);
397 if (!strcmp(value
, "veth")) {
398 netdev
->type
= LXC_NET_VETH
;
399 } else if (!strcmp(value
, "macvlan")) {
400 netdev
->type
= LXC_NET_MACVLAN
;
401 lxc_macvlan_mode_to_flag(&netdev
->priv
.macvlan_attr
.mode
,
403 } else if (!strcmp(value
, "vlan")) {
404 netdev
->type
= LXC_NET_VLAN
;
405 } else if (!strcmp(value
, "phys")) {
406 netdev
->type
= LXC_NET_PHYS
;
407 } else if (!strcmp(value
, "empty")) {
408 netdev
->type
= LXC_NET_EMPTY
;
409 } else if (!strcmp(value
, "none")) {
410 netdev
->type
= LXC_NET_NONE
;
412 ERROR("invalid network type %s", value
);
419 static int set_config_net_flags(const char *key
, const char *value
,
420 struct lxc_conf
*lxc_conf
, void *data
)
422 struct lxc_netdev
*netdev
;
424 if (lxc_config_value_empty(value
))
425 return clr_config_net_flags(key
, lxc_conf
, data
);
434 netdev
->flags
|= IFF_UP
;
439 static int create_matched_ifnames(const char *value
, struct lxc_conf
*lxc_conf
,
440 struct lxc_netdev
*netdev
)
442 struct ifaddrs
*ifaddr
, *ifa
;
445 const char *type_key
= "lxc.net.type";
446 const char *link_key
= "lxc.net.link";
447 const char *tmpvalue
= "phys";
449 if (getifaddrs(&ifaddr
) == -1) {
450 SYSERROR("Get network interfaces failed");
454 for (ifa
= ifaddr
, n
= 0; ifa
!= NULL
; ifa
= ifa
->ifa_next
, n
++) {
457 if (ifa
->ifa_addr
->sa_family
!= AF_PACKET
)
460 if (!strncmp(value
, ifa
->ifa_name
, strlen(value
) - 1)) {
461 ret
= set_config_net_type(type_key
, tmpvalue
, lxc_conf
,
464 ret
= set_config_net_link(
465 link_key
, ifa
->ifa_name
, lxc_conf
, netdev
);
467 ERROR("failed to create matched ifnames");
471 ERROR("failed to create matched ifnames");
483 static int set_config_net_link(const char *key
, const char *value
,
484 struct lxc_conf
*lxc_conf
, void *data
)
486 struct lxc_netdev
*netdev
;
489 if (lxc_config_value_empty(value
))
490 return clr_config_net_link(key
, lxc_conf
, data
);
499 if (value
[strlen(value
) - 1] == '+' && netdev
->type
== LXC_NET_PHYS
)
500 ret
= create_matched_ifnames(value
, lxc_conf
, netdev
);
502 ret
= network_ifname(netdev
->link
, value
);
507 static int set_config_net_name(const char *key
, const char *value
,
508 struct lxc_conf
*lxc_conf
, void *data
)
510 struct lxc_netdev
*netdev
;
512 if (lxc_config_value_empty(value
))
513 return clr_config_net_name(key
, lxc_conf
, data
);
522 return network_ifname(netdev
->name
, value
);
525 static int set_config_net_veth_pair(const char *key
, const char *value
,
526 struct lxc_conf
*lxc_conf
, void *data
)
528 struct lxc_netdev
*netdev
;
530 if (lxc_config_value_empty(value
))
531 return clr_config_net_veth_pair(key
, lxc_conf
, data
);
540 return network_ifname(netdev
->priv
.veth_attr
.pair
, value
);
543 static int set_config_net_macvlan_mode(const char *key
, const char *value
,
544 struct lxc_conf
*lxc_conf
, void *data
)
546 struct lxc_netdev
*netdev
;
548 if (lxc_config_value_empty(value
))
549 return clr_config_net_macvlan_mode(key
, lxc_conf
, data
);
558 return lxc_macvlan_mode_to_flag(&netdev
->priv
.macvlan_attr
.mode
, value
);
561 static int set_config_net_hwaddr(const char *key
, const char *value
,
562 struct lxc_conf
*lxc_conf
, void *data
)
564 struct lxc_netdev
*netdev
;
567 if (lxc_config_value_empty(value
))
568 return clr_config_net_hwaddr(key
, lxc_conf
, data
);
577 new_value
= strdup(value
);
581 rand_complete_hwaddr(new_value
);
583 if (lxc_config_value_empty(new_value
)) {
585 netdev
->hwaddr
= NULL
;
589 netdev
->hwaddr
= new_value
;
593 static int set_config_net_vlan_id(const char *key
, const char *value
,
594 struct lxc_conf
*lxc_conf
, void *data
)
597 struct lxc_netdev
*netdev
;
599 if (lxc_config_value_empty(value
))
600 return clr_config_net_vlan_id(key
, lxc_conf
, data
);
609 ret
= get_u16(&netdev
->priv
.vlan_attr
.vid
, value
, 0);
616 static int set_config_net_mtu(const char *key
, const char *value
,
617 struct lxc_conf
*lxc_conf
, void *data
)
619 struct lxc_netdev
*netdev
;
621 if (lxc_config_value_empty(value
))
622 return clr_config_net_mtu(key
, lxc_conf
, data
);
631 return set_config_string_item(&netdev
->mtu
, value
);
634 static int set_config_net_ipv4_address(const char *key
, const char *value
,
635 struct lxc_conf
*lxc_conf
, void *data
)
638 struct lxc_netdev
*netdev
;
639 struct lxc_inetdev
*inetdev
;
640 struct lxc_list
*list
;
641 char *cursor
, *slash
;
642 char *addr
= NULL
, *bcast
= NULL
, *prefix
= NULL
;
644 if (lxc_config_value_empty(value
))
645 return clr_config_net_ipv4_address(key
, lxc_conf
, data
);
654 inetdev
= malloc(sizeof(*inetdev
));
658 memset(inetdev
, 0, sizeof(*inetdev
));
660 list
= malloc(sizeof(*list
));
667 list
->elem
= inetdev
;
669 addr
= strdup(value
);
676 cursor
= strstr(addr
, " ");
682 slash
= strstr(addr
, "/");
688 ret
= inet_pton(AF_INET
, addr
, &inetdev
->addr
);
689 if (!ret
|| ret
< 0) {
690 SYSERROR("Invalid ipv4 address \"%s\"", value
);
698 ret
= inet_pton(AF_INET
, bcast
, &inetdev
->bcast
);
699 if (!ret
|| ret
< 0) {
700 SYSERROR("Invalid ipv4 broadcast address \"%s\"", value
);
709 /* No prefix specified, determine it from the network class. */
711 ret
= lxc_safe_uint(prefix
, &inetdev
->prefix
);
715 inetdev
->prefix
= config_ip_prefix(&inetdev
->addr
);
718 /* If no broadcast address, let compute one from the
719 * prefix and address.
722 inetdev
->bcast
.s_addr
= inetdev
->addr
.s_addr
;
723 inetdev
->bcast
.s_addr
|= htonl(INADDR_BROADCAST
>> inetdev
->prefix
);
726 lxc_list_add_tail(&netdev
->ipv4
, list
);
732 static int set_config_net_ipv4_gateway(const char *key
, const char *value
,
733 struct lxc_conf
*lxc_conf
, void *data
)
735 struct lxc_netdev
*netdev
;
737 if (lxc_config_value_empty(value
))
738 return clr_config_net_ipv4_gateway(key
, lxc_conf
, data
);
747 free(netdev
->ipv4_gateway
);
749 if (!strcmp(value
, "auto")) {
750 netdev
->ipv4_gateway
= NULL
;
751 netdev
->ipv4_gateway_auto
= true;
756 gw
= malloc(sizeof(*gw
));
760 ret
= inet_pton(AF_INET
, value
, gw
);
761 if (!ret
|| ret
< 0) {
762 SYSERROR("Invalid ipv4 gateway address \"%s\"", value
);
767 netdev
->ipv4_gateway
= gw
;
768 netdev
->ipv4_gateway_auto
= false;
774 static int set_config_net_ipv6_address(const char *key
, const char *value
,
775 struct lxc_conf
*lxc_conf
, void *data
)
778 struct lxc_netdev
*netdev
;
779 struct lxc_inet6dev
*inet6dev
;
780 struct lxc_list
*list
;
781 char *slash
, *valdup
, *netmask
;
783 if (lxc_config_value_empty(value
))
784 return clr_config_net_ipv6_address(key
, lxc_conf
, data
);
793 inet6dev
= malloc(sizeof(*inet6dev
));
797 memset(inet6dev
, 0, sizeof(*inet6dev
));
799 list
= malloc(sizeof(*list
));
806 list
->elem
= inet6dev
;
808 valdup
= strdup(value
);
815 inet6dev
->prefix
= 64;
816 slash
= strstr(valdup
, "/");
820 if (lxc_safe_uint(netmask
, &inet6dev
->prefix
) < 0)
824 ret
= inet_pton(AF_INET6
, valdup
, &inet6dev
->addr
);
825 if (!ret
|| ret
< 0) {
826 SYSERROR("Invalid ipv6 address \"%s\"", valdup
);
833 lxc_list_add_tail(&netdev
->ipv6
, list
);
839 static int set_config_net_ipv6_gateway(const char *key
, const char *value
,
840 struct lxc_conf
*lxc_conf
, void *data
)
842 struct lxc_netdev
*netdev
;
844 if (lxc_config_value_empty(value
))
845 return clr_config_net_ipv6_gateway(key
, lxc_conf
, data
);
854 free(netdev
->ipv6_gateway
);
856 if (!strcmp(value
, "auto")) {
857 netdev
->ipv6_gateway
= NULL
;
858 netdev
->ipv6_gateway_auto
= true;
863 gw
= malloc(sizeof(*gw
));
867 ret
= inet_pton(AF_INET6
, value
, gw
);
868 if (!ret
|| ret
< 0) {
869 SYSERROR("Invalid ipv6 gateway address \"%s\"", value
);
874 netdev
->ipv6_gateway
= gw
;
875 netdev
->ipv6_gateway_auto
= false;
881 static int set_config_net_script_up(const char *key
, const char *value
,
882 struct lxc_conf
*lxc_conf
, void *data
)
884 struct lxc_netdev
*netdev
;
886 if (lxc_config_value_empty(value
))
887 return clr_config_net_script_up(key
, lxc_conf
, data
);
896 return set_config_string_item(&netdev
->upscript
, value
);
899 static int set_config_net_script_down(const char *key
, const char *value
,
900 struct lxc_conf
*lxc_conf
, void *data
)
902 struct lxc_netdev
*netdev
;
904 if (lxc_config_value_empty(value
))
905 return clr_config_net_script_down(key
, lxc_conf
, data
);
914 return set_config_string_item(&netdev
->downscript
, value
);
917 static int add_hook(struct lxc_conf
*lxc_conf
, int which
, char *hook
)
919 struct lxc_list
*hooklist
;
921 hooklist
= malloc(sizeof(*hooklist
));
927 hooklist
->elem
= hook
;
928 lxc_list_add_tail(&lxc_conf
->hooks
[which
], hooklist
);
932 static int set_config_seccomp_profile(const char *key
, const char *value
,
933 struct lxc_conf
*lxc_conf
, void *data
)
935 return set_config_path_item(&lxc_conf
->seccomp
, value
);
938 static int set_config_execute_cmd(const char *key
, const char *value
,
939 struct lxc_conf
*lxc_conf
, void *data
)
941 return set_config_path_item(&lxc_conf
->execute_cmd
, value
);
944 static int set_config_init_cmd(const char *key
, const char *value
,
945 struct lxc_conf
*lxc_conf
, void *data
)
947 return set_config_path_item(&lxc_conf
->init_cmd
, value
);
950 static int set_config_init_cwd(const char *key
, const char *value
,
951 struct lxc_conf
*lxc_conf
, void *data
)
953 return set_config_path_item(&lxc_conf
->init_cwd
, value
);
956 static int set_config_init_uid(const char *key
, const char *value
,
957 struct lxc_conf
*lxc_conf
, void *data
)
959 unsigned int init_uid
;
961 if (lxc_config_value_empty(value
)) {
962 lxc_conf
->init_uid
= 0;
966 if (lxc_safe_uint(value
, &init_uid
) < 0)
969 lxc_conf
->init_uid
= init_uid
;
974 static int set_config_init_gid(const char *key
, const char *value
,
975 struct lxc_conf
*lxc_conf
, void *data
)
977 unsigned int init_gid
;
979 if (lxc_config_value_empty(value
)) {
980 lxc_conf
->init_gid
= 0;
984 if (lxc_safe_uint(value
, &init_gid
) < 0)
987 lxc_conf
->init_gid
= init_gid
;
992 static int set_config_hooks(const char *key
, const char *value
,
993 struct lxc_conf
*lxc_conf
, void *data
)
997 if (lxc_config_value_empty(value
))
998 return lxc_clear_hooks(lxc_conf
, key
);
1000 if (strcmp(key
+ 4, "hook") == 0) {
1001 ERROR("lxc.hook must not have a value");
1005 copy
= strdup(value
);
1009 if (strcmp(key
+ 9, "pre-start") == 0)
1010 return add_hook(lxc_conf
, LXCHOOK_PRESTART
, copy
);
1011 else if (strcmp(key
+ 9, "start-host") == 0)
1012 return add_hook(lxc_conf
, LXCHOOK_START_HOST
, copy
);
1013 else if (strcmp(key
+ 9, "pre-mount") == 0)
1014 return add_hook(lxc_conf
, LXCHOOK_PREMOUNT
, copy
);
1015 else if (strcmp(key
+ 9, "autodev") == 0)
1016 return add_hook(lxc_conf
, LXCHOOK_AUTODEV
, copy
);
1017 else if (strcmp(key
+ 9, "mount") == 0)
1018 return add_hook(lxc_conf
, LXCHOOK_MOUNT
, copy
);
1019 else if (strcmp(key
+ 9, "start") == 0)
1020 return add_hook(lxc_conf
, LXCHOOK_START
, copy
);
1021 else if (strcmp(key
+ 9, "stop") == 0)
1022 return add_hook(lxc_conf
, LXCHOOK_STOP
, copy
);
1023 else if (strcmp(key
+ 9, "post-stop") == 0)
1024 return add_hook(lxc_conf
, LXCHOOK_POSTSTOP
, copy
);
1025 else if (strcmp(key
+ 9, "clone") == 0)
1026 return add_hook(lxc_conf
, LXCHOOK_CLONE
, copy
);
1027 else if (strcmp(key
+ 9, "destroy") == 0)
1028 return add_hook(lxc_conf
, LXCHOOK_DESTROY
, copy
);
1034 static int set_config_personality(const char *key
, const char *value
,
1035 struct lxc_conf
*lxc_conf
, void *data
)
1037 signed long personality
= lxc_config_parse_arch(value
);
1039 if (personality
>= 0)
1040 lxc_conf
->personality
= personality
;
1042 WARN("Unsupported personality \"%s\"", value
);
1047 static int set_config_pty_max(const char *key
, const char *value
,
1048 struct lxc_conf
*lxc_conf
, void *data
)
1050 if (lxc_config_value_empty(value
)) {
1055 if (lxc_safe_uint(value
, &lxc_conf
->pts
) < 0)
1061 /* We only need to check whether the first byte of the key after the lxc.start.
1062 * prefix matches our expectations since they fortunately all start with a
1063 * different letter. If anything was wrong with the key we would have already
1064 * noticed when the callback was called.
1066 static int set_config_start(const char *key
, const char *value
,
1067 struct lxc_conf
*lxc_conf
, void *data
)
1071 is_empty
= lxc_config_value_empty(value
);
1073 if (*(key
+ 10) == 'a') { /* lxc.start.auto */
1075 lxc_conf
->start_auto
= 0;
1079 if (lxc_safe_uint(value
, &lxc_conf
->start_auto
) < 0)
1082 if (lxc_conf
->start_auto
> 1)
1086 } else if (*(key
+ 10) == 'd') { /* lxc.start.delay */
1088 lxc_conf
->start_delay
= 0;
1092 return lxc_safe_uint(value
, &lxc_conf
->start_delay
);
1093 } else if (*(key
+ 10) == 'o') { /* lxc.start.order */
1095 lxc_conf
->start_order
= 0;
1099 return lxc_safe_int(value
, &lxc_conf
->start_order
);
1105 static int set_config_monitor(const char *key
, const char *value
,
1106 struct lxc_conf
*lxc_conf
, void *data
)
1108 if (lxc_config_value_empty(value
)) {
1109 lxc_conf
->monitor_unshare
= 0;
1113 if (strcmp(key
+ 12, "unshare") == 0)
1114 return lxc_safe_uint(value
, &lxc_conf
->monitor_unshare
);
1119 static int set_config_group(const char *key
, const char *value
,
1120 struct lxc_conf
*lxc_conf
, void *data
)
1122 char *groups
, *groupptr
, *sptr
, *token
;
1123 struct lxc_list
*grouplist
;
1126 if (lxc_config_value_empty(value
))
1127 return lxc_clear_groups(lxc_conf
);
1129 groups
= strdup(value
);
1133 /* In case several groups are specified in a single line split these
1134 * groups in a single element for the list.
1136 for (groupptr
= groups
;; groupptr
= NULL
) {
1137 token
= strtok_r(groupptr
, " \t", &sptr
);
1143 grouplist
= malloc(sizeof(*grouplist
));
1147 grouplist
->elem
= strdup(token
);
1148 if (!grouplist
->elem
) {
1153 lxc_list_add_tail(&lxc_conf
->groups
, grouplist
);
1160 static int set_config_environment(const char *key
, const char *value
,
1161 struct lxc_conf
*lxc_conf
, void *data
)
1163 struct lxc_list
*list_item
= NULL
;
1165 if (lxc_config_value_empty(value
))
1166 return lxc_clear_environment(lxc_conf
);
1168 list_item
= malloc(sizeof(*list_item
));
1172 list_item
->elem
= strdup(value
);
1174 if (!list_item
->elem
)
1177 lxc_list_add_tail(&lxc_conf
->environment
, list_item
);
1186 static int set_config_tty_max(const char *key
, const char *value
,
1187 struct lxc_conf
*lxc_conf
, void *data
)
1189 if (lxc_config_value_empty(value
)) {
1194 return lxc_safe_uint(value
, &lxc_conf
->tty
);
1197 static int set_config_tty_dir(const char *key
, const char *value
,
1198 struct lxc_conf
*lxc_conf
, void *data
)
1200 return set_config_string_item_max(&lxc_conf
->ttydir
, value
,
1204 static int set_config_apparmor_profile(const char *key
, const char *value
,
1205 struct lxc_conf
*lxc_conf
, void *data
)
1207 return set_config_string_item(&lxc_conf
->lsm_aa_profile
, value
);
1210 static int set_config_apparmor_allow_incomplete(const char *key
,
1212 struct lxc_conf
*lxc_conf
,
1215 if (lxc_config_value_empty(value
)) {
1216 lxc_conf
->lsm_aa_allow_incomplete
= 0;
1220 if (lxc_safe_uint(value
, &lxc_conf
->lsm_aa_allow_incomplete
) < 0)
1223 if (lxc_conf
->lsm_aa_allow_incomplete
> 1)
1229 static int set_config_selinux_context(const char *key
, const char *value
,
1230 struct lxc_conf
*lxc_conf
, void *data
)
1232 return set_config_string_item(&lxc_conf
->lsm_se_context
, value
);
1235 static int set_config_log_file(const char *key
, const char *value
,
1236 struct lxc_conf
*c
, void *data
)
1240 if (lxc_config_value_empty(value
)) {
1246 /* Store these values in the lxc_conf, and then try to set for actual
1249 ret
= set_config_path_item(&c
->logfile
, value
);
1251 ret
= lxc_log_set_file(&c
->logfd
, c
->logfile
);
1256 static int set_config_log_level(const char *key
, const char *value
,
1257 struct lxc_conf
*lxc_conf
, void *data
)
1261 if (lxc_config_value_empty(value
)) {
1262 lxc_conf
->loglevel
= LXC_LOG_LEVEL_NOTSET
;
1266 if (value
[0] >= '0' && value
[0] <= '9') {
1267 if (lxc_safe_int(value
, &newlevel
) < 0)
1270 newlevel
= lxc_log_priority_to_int(value
);
1273 /* Store these values in the lxc_conf, and then try to set for actual
1276 lxc_conf
->loglevel
= newlevel
;
1277 return lxc_log_set_level(&lxc_conf
->loglevel
, newlevel
);
1280 static int set_config_autodev(const char *key
, const char *value
,
1281 struct lxc_conf
*lxc_conf
, void *data
)
1283 if (lxc_config_value_empty(value
)) {
1284 lxc_conf
->autodev
= 0;
1288 if (lxc_safe_uint(value
, &lxc_conf
->autodev
) < 0)
1291 if (lxc_conf
->autodev
> 1)
1297 static int sig_num(const char *sig
)
1299 unsigned int signum
;
1301 if (lxc_safe_uint(sig
, &signum
) < 0)
1307 static int rt_sig_num(const char *signame
)
1309 int rtmax
= 0, sig_n
= 0;
1311 if (strncasecmp(signame
, "max-", 4) == 0) {
1316 if (!isdigit(*signame
))
1319 sig_n
= sig_num(signame
);
1320 sig_n
= rtmax
? SIGRTMAX
- sig_n
: SIGRTMIN
+ sig_n
;
1321 if (sig_n
> SIGRTMAX
|| sig_n
< SIGRTMIN
)
1327 static int sig_parse(const char *signame
)
1331 if (isdigit(*signame
)) {
1332 return sig_num(signame
);
1333 } else if (strncasecmp(signame
, "sig", 3) == 0) {
1335 if (strncasecmp(signame
, "rt", 2) == 0)
1336 return rt_sig_num(signame
+ 2);
1337 for (n
= 0; n
< sizeof(signames
) / sizeof((signames
)[0]); n
++) {
1338 if (strcasecmp(signames
[n
].name
, signame
) == 0)
1339 return signames
[n
].num
;
1346 static int set_config_signal_halt(const char *key
, const char *value
,
1347 struct lxc_conf
*lxc_conf
, void *data
)
1351 if (lxc_config_value_empty(value
)) {
1352 lxc_conf
->haltsignal
= 0;
1356 sig_n
= sig_parse(value
);
1360 lxc_conf
->haltsignal
= sig_n
;
1365 static int set_config_signal_reboot(const char *key
, const char *value
,
1366 struct lxc_conf
*lxc_conf
, void *data
)
1370 if (lxc_config_value_empty(value
)) {
1371 lxc_conf
->rebootsignal
= 0;
1375 sig_n
= sig_parse(value
);
1379 lxc_conf
->rebootsignal
= sig_n
;
1384 static int set_config_signal_stop(const char *key
, const char *value
,
1385 struct lxc_conf
*lxc_conf
, void *data
)
1389 if (lxc_config_value_empty(value
)) {
1390 lxc_conf
->stopsignal
= 0;
1394 sig_n
= sig_parse(value
);
1398 lxc_conf
->stopsignal
= sig_n
;
1403 static int set_config_cgroup_controller(const char *key
, const char *value
,
1404 struct lxc_conf
*lxc_conf
, void *data
)
1407 char *token
= "lxc.cgroup.";
1408 struct lxc_list
*cglist
= NULL
;
1409 struct lxc_cgroup
*cgelem
= NULL
;
1411 if (lxc_config_value_empty(value
))
1412 return lxc_clear_cgroups(lxc_conf
, key
);
1414 subkey
= strstr(key
, token
);
1418 if (!strlen(subkey
))
1421 if (strlen(subkey
) == strlen(token
))
1424 subkey
+= strlen(token
);
1426 cglist
= malloc(sizeof(*cglist
));
1430 cgelem
= malloc(sizeof(*cgelem
));
1433 memset(cgelem
, 0, sizeof(*cgelem
));
1435 cgelem
->subsystem
= strdup(subkey
);
1436 cgelem
->value
= strdup(value
);
1438 if (!cgelem
->subsystem
|| !cgelem
->value
)
1441 cglist
->elem
= cgelem
;
1443 lxc_list_add_tail(&lxc_conf
->cgroup
, cglist
);
1450 free(cgelem
->subsystem
);
1451 free(cgelem
->value
);
1458 static int set_config_cgroup_dir(const char *key
, const char *value
,
1459 struct lxc_conf
*lxc_conf
, void *data
)
1461 if (lxc_config_value_empty(value
))
1462 return clr_config_cgroup_dir(key
, lxc_conf
, NULL
);
1464 return set_config_string_item(&lxc_conf
->cgroup_meta
.dir
, value
);
1467 static int set_config_prlimit(const char *key
, const char *value
,
1468 struct lxc_conf
*lxc_conf
, void *data
)
1470 struct lxc_list
*iter
;
1471 struct rlimit limit
;
1473 struct lxc_list
*limlist
= NULL
;
1474 struct lxc_limit
*limelem
= NULL
;
1476 if (lxc_config_value_empty(value
))
1477 return lxc_clear_limits(lxc_conf
, key
);
1479 if (strncmp(key
, "lxc.prlimit.", sizeof("lxc.prlimit.") - 1) != 0)
1482 key
+= sizeof("lxc.prlimit.") - 1;
1484 /* soft limit comes first in the value */
1485 if (!parse_limit_value(&value
, &limit_value
))
1487 limit
.rlim_cur
= limit_value
;
1489 /* skip spaces and a colon */
1490 while (isspace(*value
))
1495 else if (*value
) /* any other character is an error here */
1498 while (isspace(*value
))
1501 /* optional hard limit */
1503 if (!parse_limit_value(&value
, &limit_value
))
1505 limit
.rlim_max
= limit_value
;
1507 /* check for trailing garbage */
1508 while (isspace(*value
))
1514 /* a single value sets both hard and soft limit */
1515 limit
.rlim_max
= limit
.rlim_cur
;
1518 /* find existing list element */
1519 lxc_list_for_each(iter
, &lxc_conf
->limits
)
1521 limelem
= iter
->elem
;
1522 if (!strcmp(key
, limelem
->resource
)) {
1523 limelem
->limit
= limit
;
1528 /* allocate list element */
1529 limlist
= malloc(sizeof(*limlist
));
1533 limelem
= malloc(sizeof(*limelem
));
1536 memset(limelem
, 0, sizeof(*limelem
));
1538 limelem
->resource
= strdup(key
);
1539 if (!limelem
->resource
)
1541 limelem
->limit
= limit
;
1543 limlist
->elem
= limelem
;
1545 lxc_list_add_tail(&lxc_conf
->limits
, limlist
);
1552 free(limelem
->resource
);
1558 static int set_config_idmaps(const char *key
, const char *value
,
1559 struct lxc_conf
*lxc_conf
, void *data
)
1561 unsigned long hostid
, nsid
, range
;
1564 struct lxc_list
*idmaplist
= NULL
;
1565 struct id_map
*idmap
= NULL
;
1567 if (lxc_config_value_empty(value
))
1568 return lxc_clear_idmaps(lxc_conf
);
1570 idmaplist
= malloc(sizeof(*idmaplist
));
1574 idmap
= malloc(sizeof(*idmap
));
1577 memset(idmap
, 0, sizeof(*idmap
));
1579 ret
= parse_idmaps(value
, &type
, &nsid
, &hostid
, &range
);
1583 INFO("Read uid map: type %c nsid %lu hostid %lu range %lu", type
, nsid
, hostid
, range
);
1585 idmap
->idtype
= ID_TYPE_UID
;
1586 else if (type
== 'g')
1587 idmap
->idtype
= ID_TYPE_GID
;
1591 idmap
->hostid
= hostid
;
1593 idmap
->range
= range
;
1594 idmaplist
->elem
= idmap
;
1595 lxc_list_add_tail(&lxc_conf
->id_map
, idmaplist
);
1607 static int set_config_mount_fstab(const char *key
, const char *value
,
1608 struct lxc_conf
*lxc_conf
, void *data
)
1610 if (lxc_config_value_empty(value
)) {
1611 clr_config_mount_fstab(key
, lxc_conf
, NULL
);
1615 return set_config_path_item(&lxc_conf
->fstab
, value
);
1618 static int set_config_mount_auto(const char *key
, const char *value
,
1619 struct lxc_conf
*lxc_conf
, void *data
)
1621 char *autos
, *autoptr
, *sptr
, *token
;
1628 } allowed_auto_mounts
[] = {
1629 { "proc", LXC_AUTO_PROC_MASK
, LXC_AUTO_PROC_MIXED
},
1630 { "proc:mixed", LXC_AUTO_PROC_MASK
, LXC_AUTO_PROC_MIXED
},
1631 { "proc:rw", LXC_AUTO_PROC_MASK
, LXC_AUTO_PROC_RW
},
1632 { "sys", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_MIXED
},
1633 { "sys:ro", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_RO
},
1634 { "sys:mixed", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_MIXED
},
1635 { "sys:rw", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_RW
},
1636 { "cgroup", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_NOSPEC
},
1637 { "cgroup:mixed", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_MIXED
},
1638 { "cgroup:ro", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_RO
},
1639 { "cgroup:rw", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_RW
},
1640 { "cgroup-full", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_NOSPEC
},
1641 { "cgroup-full:mixed", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_MIXED
},
1642 { "cgroup-full:ro", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_RO
},
1643 { "cgroup-full:rw", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_RW
},
1644 /* For adding anything that is just a single on/off, but has no
1645 * options: keep mask and flag identical and just define the enum
1646 * value as an unused bit so far
1651 if (lxc_config_value_empty(value
)) {
1652 lxc_conf
->auto_mounts
= 0;
1656 autos
= strdup(value
);
1660 for (autoptr
= autos
;; autoptr
= NULL
) {
1661 token
= strtok_r(autoptr
, " \t", &sptr
);
1667 for (i
= 0; allowed_auto_mounts
[i
].token
; i
++) {
1668 if (!strcmp(allowed_auto_mounts
[i
].token
, token
))
1672 if (!allowed_auto_mounts
[i
].token
) {
1673 ERROR("Invalid filesystem to automount \"%s\"", token
);
1677 lxc_conf
->auto_mounts
&= ~allowed_auto_mounts
[i
].mask
;
1678 lxc_conf
->auto_mounts
|= allowed_auto_mounts
[i
].flag
;
1685 static int set_config_mount(const char *key
, const char *value
,
1686 struct lxc_conf
*lxc_conf
, void *data
)
1689 struct lxc_list
*mntlist
;
1691 if (lxc_config_value_empty(value
))
1692 return lxc_clear_mount_entries(lxc_conf
);
1694 mntlist
= malloc(sizeof(*mntlist
));
1698 mntelem
= strdup(value
);
1703 mntlist
->elem
= mntelem
;
1705 lxc_list_add_tail(&lxc_conf
->mount_list
, mntlist
);
1710 static int set_config_cap_keep(const char *key
, const char *value
,
1711 struct lxc_conf
*lxc_conf
, void *data
)
1713 char *keepcaps
, *keepptr
, *sptr
, *token
;
1714 struct lxc_list
*keeplist
;
1717 if (lxc_config_value_empty(value
))
1718 return lxc_clear_config_keepcaps(lxc_conf
);
1720 keepcaps
= strdup(value
);
1724 /* In case several capability keep is specified in a single line
1725 * split these caps in a single element for the list.
1727 for (keepptr
= keepcaps
;; keepptr
= NULL
) {
1728 token
= strtok_r(keepptr
, " \t", &sptr
);
1734 if (!strcmp(token
, "none"))
1735 lxc_clear_config_keepcaps(lxc_conf
);
1737 keeplist
= malloc(sizeof(*keeplist
));
1741 keeplist
->elem
= strdup(token
);
1742 if (!keeplist
->elem
) {
1747 lxc_list_add_tail(&lxc_conf
->keepcaps
, keeplist
);
1755 static int set_config_cap_drop(const char *key
, const char *value
,
1756 struct lxc_conf
*lxc_conf
, void *data
)
1758 char *dropcaps
, *dropptr
, *sptr
, *token
;
1759 struct lxc_list
*droplist
;
1762 if (lxc_config_value_empty(value
))
1763 return lxc_clear_config_caps(lxc_conf
);
1765 dropcaps
= strdup(value
);
1769 /* In case several capability drop is specified in a single line
1770 * split these caps in a single element for the list.
1772 for (dropptr
= dropcaps
;; dropptr
= NULL
) {
1773 token
= strtok_r(dropptr
, " \t", &sptr
);
1779 droplist
= malloc(sizeof(*droplist
));
1783 droplist
->elem
= strdup(token
);
1784 if (!droplist
->elem
) {
1789 lxc_list_add_tail(&lxc_conf
->caps
, droplist
);
1797 static int set_config_console_path(const char *key
, const char *value
,
1798 struct lxc_conf
*lxc_conf
, void *data
)
1800 return set_config_path_item(&lxc_conf
->console
.path
, value
);
1803 static int set_config_console_rotate(const char *key
, const char *value
,
1804 struct lxc_conf
*lxc_conf
, void *data
)
1806 if (lxc_config_value_empty(value
)) {
1807 lxc_conf
->console
.log_rotate
= 0;
1811 if (lxc_safe_uint(value
, &lxc_conf
->console
.log_rotate
) < 0)
1814 if (lxc_conf
->console
.log_rotate
> 1) {
1815 ERROR("The \"lxc.console.rotate\" config key can only be set "
1823 static int set_config_console_logfile(const char *key
, const char *value
,
1824 struct lxc_conf
*lxc_conf
, void *data
)
1826 return set_config_path_item(&lxc_conf
->console
.log_path
, value
);
1829 static int set_config_console_buffer_size(const char *key
, const char *value
,
1830 struct lxc_conf
*lxc_conf
, void *data
)
1834 uint64_t buffer_size
, pgsz
;
1836 if (lxc_config_value_empty(value
)) {
1837 lxc_conf
->console
.buffer_size
= 0;
1841 /* If the user specified "auto" the default log size is 2^17 = 128 Kib */
1842 if (!strcmp(value
, "auto")) {
1843 lxc_conf
->console
.buffer_size
= 1 << 17;
1847 ret
= parse_byte_size_string(value
, &size
);
1854 /* must be at least a page size */
1855 pgsz
= lxc_getpagesize();
1856 if ((uint64_t)size
< pgsz
) {
1857 NOTICE("Requested ringbuffer size for the console is %" PRId64
1858 " but must be at least %" PRId64
1859 " bytes. Setting ringbuffer size to %" PRId64
" bytes",
1864 buffer_size
= lxc_find_next_power2((uint64_t)size
);
1865 if (buffer_size
== 0)
1868 if (buffer_size
!= size
)
1869 NOTICE("Passed size was not a power of 2. Rounding log size to "
1870 "next power of two: %" PRIu64
" bytes", buffer_size
);
1872 lxc_conf
->console
.buffer_size
= buffer_size
;
1876 static int set_config_console_buffer_logfile(const char *key
, const char *value
,
1877 struct lxc_conf
*lxc_conf
,
1880 return set_config_path_item(&lxc_conf
->console
.buffer_log_file
, value
);
1883 int append_unexp_config_line(const char *line
, struct lxc_conf
*conf
)
1885 size_t len
= conf
->unexpanded_len
, linelen
= strlen(line
);
1887 update_hwaddr(line
);
1889 while (conf
->unexpanded_alloced
<= len
+ linelen
+ 2) {
1890 char *tmp
= realloc(conf
->unexpanded_config
,
1891 conf
->unexpanded_alloced
+ 1024);
1895 if (!conf
->unexpanded_config
)
1897 conf
->unexpanded_config
= tmp
;
1898 conf
->unexpanded_alloced
+= 1024;
1900 strcat(conf
->unexpanded_config
, line
);
1901 conf
->unexpanded_len
+= linelen
;
1902 if (line
[linelen
- 1] != '\n') {
1903 strcat(conf
->unexpanded_config
, "\n");
1904 conf
->unexpanded_len
++;
1910 static int do_includedir(const char *dirp
, struct lxc_conf
*lxc_conf
)
1912 struct dirent
*direntp
;
1914 char path
[MAXPATHLEN
];
1918 dir
= opendir(dirp
);
1922 while ((direntp
= readdir(dir
))) {
1927 fnam
= direntp
->d_name
;
1928 if (!strcmp(fnam
, "."))
1931 if (!strcmp(fnam
, ".."))
1935 if (len
< 6 || strncmp(fnam
+ len
- 5, ".conf", 5) != 0)
1938 len
= snprintf(path
, MAXPATHLEN
, "%s/%s", dirp
, fnam
);
1939 if (len
< 0 || len
>= MAXPATHLEN
) {
1944 ret
= lxc_config_read(path
, lxc_conf
, true);
1956 static int set_config_includefiles(const char *key
, const char *value
,
1957 struct lxc_conf
*lxc_conf
, void *data
)
1959 if (lxc_config_value_empty(value
)) {
1960 clr_config_includefiles(key
, lxc_conf
, NULL
);
1965 return do_includedir(value
, lxc_conf
);
1967 return lxc_config_read(value
, lxc_conf
, true);
1970 static int set_config_rootfs_path(const char *key
, const char *value
,
1971 struct lxc_conf
*lxc_conf
, void *data
)
1973 return set_config_path_item(&lxc_conf
->rootfs
.path
, value
);
1976 static int set_config_rootfs_mount(const char *key
, const char *value
,
1977 struct lxc_conf
*lxc_conf
, void *data
)
1979 return set_config_path_item(&lxc_conf
->rootfs
.mount
, value
);
1982 static int set_config_rootfs_options(const char *key
, const char *value
,
1983 struct lxc_conf
*lxc_conf
, void *data
)
1985 return set_config_string_item(&lxc_conf
->rootfs
.options
, value
);
1988 static int set_config_rootfs_backend(const char *key
, const char *value
,
1989 struct lxc_conf
*lxc_conf
, void *data
)
1994 static int set_config_uts_name(const char *key
, const char *value
,
1995 struct lxc_conf
*lxc_conf
, void *data
)
1997 struct utsname
*utsname
;
1999 if (lxc_config_value_empty(value
)) {
2000 clr_config_uts_name(key
, lxc_conf
, NULL
);
2004 utsname
= malloc(sizeof(*utsname
));
2008 if (strlen(value
) >= sizeof(utsname
->nodename
)) {
2013 strcpy(utsname
->nodename
, value
);
2014 free(lxc_conf
->utsname
);
2015 lxc_conf
->utsname
= utsname
;
2020 static int set_config_namespace(const char *key
, const char *value
,
2021 struct lxc_conf
*lxc_conf
, void *data
)
2024 const char *namespace;
2026 if (lxc_config_value_empty(value
))
2027 return clr_config_namespace(key
, lxc_conf
, data
);
2029 namespace = key
+ sizeof("lxc.namespace.") - 1;
2030 ns_idx
= lxc_namespace_2_ns_idx(namespace);
2034 return set_config_string_item(&lxc_conf
->inherit_ns
[ns_idx
], value
);
2037 struct parse_line_conf
{
2038 struct lxc_conf
*conf
;
2042 static int parse_line(char *buffer
, void *data
)
2044 char *dot
, *key
, *line
, *linep
, *value
;
2046 struct lxc_config_t
*config
;
2049 struct parse_line_conf
*plc
= data
;
2051 /* If there are newlines in the config file we should keep them. */
2052 empty_line
= lxc_is_line_empty(dup
);
2056 /* We have to dup the buffer otherwise, at the re-exec for reboot we
2057 * modified the original string on the stack by replacing '=' by '\0'
2060 linep
= line
= strdup(dup
);
2064 if (!plc
->from_include
) {
2065 ret
= append_unexp_config_line(line
, plc
->conf
);
2073 line
+= lxc_char_left_gc(line
, strlen(line
));
2075 /* ignore comments */
2079 /* martian option - don't add it to the config itself */
2080 if (strncmp(line
, "lxc.", 4))
2085 dot
= strchr(line
, '=');
2087 ERROR("Invalid configuration line: %s", line
);
2095 key
[lxc_char_right_gc(key
, strlen(key
))] = '\0';
2097 value
+= lxc_char_left_gc(value
, strlen(value
));
2098 value
[lxc_char_right_gc(value
, strlen(value
))] = '\0';
2100 if (*value
== '\'' || *value
== '\"') {
2103 len
= strlen(value
);
2104 if (len
> 1 && value
[len
- 1] == *value
) {
2105 value
[len
- 1] = '\0';
2110 config
= lxc_get_config(key
);
2112 ERROR("Unknown configuration key \"%s\"", key
);
2116 /* [START]: REMOVE IN LXC 3.0 */
2117 if (config
->is_legacy_key
&& !plc
->conf
->contains_legacy_key
) {
2118 plc
->conf
->contains_legacy_key
= true;
2119 if (getenv("LXC_UPDATE_CONFIG_FORMAT")) {
2120 /* Warn the user once loud and clear that there is at
2121 * least one legacy configuration item in the
2122 * configuration file and then an update is required.
2124 fprintf(stderr
, "The configuration file contains "
2125 "legacy configuration keys.\nPlease "
2126 "update your configuration file!\nThe "
2127 "update script lxc-update-config -c "
2128 "<path-to-config> can be used for "
2132 /* [END]: REMOVE IN LXC 3.0 */
2134 ret
= config
->set(key
, value
, plc
->conf
, NULL
);
2141 static int lxc_config_readline(char *buffer
, struct lxc_conf
*conf
)
2143 struct parse_line_conf c
;
2146 c
.from_include
= false;
2148 return parse_line(buffer
, &c
);
2151 int lxc_config_read(const char *file
, struct lxc_conf
*conf
, bool from_include
)
2154 struct parse_line_conf c
;
2157 c
.from_include
= from_include
;
2159 ret
= access(file
, R_OK
);
2163 /* Catch only the top level config file name in the structure. */
2165 conf
->rcfile
= strdup(file
);
2167 return lxc_file_for_each_line(file
, parse_line
, &c
);
2170 int lxc_config_define_add(struct lxc_list
*defines
, char *arg
)
2172 struct lxc_list
*dent
;
2174 dent
= malloc(sizeof(struct lxc_list
));
2179 lxc_list_add_tail(defines
, dent
);
2183 int lxc_config_define_load(struct lxc_list
*defines
, struct lxc_conf
*conf
)
2185 struct lxc_list
*it
, *next
;
2188 lxc_list_for_each(it
, defines
) {
2189 ret
= lxc_config_readline(it
->elem
, conf
);
2194 lxc_list_for_each_safe(it
, defines
, next
) {
2202 signed long lxc_config_parse_arch(const char *arch
)
2204 #if HAVE_SYS_PERSONALITY_H
2210 { "x86", PER_LINUX32
},
2211 { "linux32", PER_LINUX32
},
2212 { "i386", PER_LINUX32
},
2213 { "i486", PER_LINUX32
},
2214 { "i586", PER_LINUX32
},
2215 { "i686", PER_LINUX32
},
2216 { "athlon", PER_LINUX32
},
2217 { "mips", PER_LINUX32
},
2218 { "mipsel", PER_LINUX32
},
2219 { "ppc", PER_LINUX32
},
2220 { "arm", PER_LINUX32
},
2221 { "armv7l", PER_LINUX32
},
2222 { "armhf", PER_LINUX32
},
2223 { "armel", PER_LINUX32
},
2224 { "powerpc", PER_LINUX32
},
2225 { "linux64", PER_LINUX
},
2226 { "x86_64", PER_LINUX
},
2227 { "amd64", PER_LINUX
},
2228 { "mips64", PER_LINUX
},
2229 { "mips64el", PER_LINUX
},
2230 { "ppc64", PER_LINUX
},
2231 { "ppc64le", PER_LINUX
},
2232 { "ppc64el", PER_LINUX
},
2233 { "powerpc64", PER_LINUX
},
2234 { "s390x", PER_LINUX
},
2235 { "aarch64", PER_LINUX
},
2236 { "arm64", PER_LINUX
},
2238 size_t len
= sizeof(pername
) / sizeof(pername
[0]);
2240 for (i
= 0; i
< len
; i
++) {
2241 if (!strcmp(pername
[i
].name
, arch
))
2242 return pername
[i
].per
;
2249 int lxc_fill_elevated_privileges(char *flaglist
, int *flags
)
2251 char *token
, *saveptr
= NULL
;
2257 { "CGROUP", LXC_ATTACH_MOVE_TO_CGROUP
},
2258 { "CAP", LXC_ATTACH_DROP_CAPABILITIES
},
2259 { "LSM", LXC_ATTACH_LSM_EXEC
},
2264 /* For the sake of backward compatibility, drop all privileges
2265 * if none is specified.
2267 for (i
= 0; all_privs
[i
].token
; i
++)
2268 *flags
|= all_privs
[i
].flag
;
2273 token
= strtok_r(flaglist
, "|", &saveptr
);
2276 for (i
= 0; all_privs
[i
].token
; i
++)
2277 if (!strcmp(all_privs
[i
].token
, token
))
2278 aflag
= all_privs
[i
].flag
;
2284 token
= strtok_r(NULL
, "|", &saveptr
);
2290 /* Write out a configuration file. */
2291 void write_config(FILE *fout
, struct lxc_conf
*c
)
2294 size_t len
= c
->unexpanded_len
;
2299 ret
= fwrite(c
->unexpanded_config
, 1, len
, fout
);
2301 SYSERROR("Failed to write configuration file");
2304 bool do_append_unexp_config_line(struct lxc_conf
*conf
, const char *key
,
2311 len
= strlen(key
) + strlen(v
) + 4;
2314 if (lxc_config_value_empty(v
))
2315 ret
= snprintf(tmp
, len
, "%s =", key
);
2317 ret
= snprintf(tmp
, len
, "%s = %s", key
, v
);
2318 if (ret
< 0 || ret
>= len
)
2321 /* Save the line verbatim into unexpanded_conf */
2322 if (append_unexp_config_line(tmp
, conf
))
2328 void clear_unexp_config_line(struct lxc_conf
*conf
, const char *key
,
2332 char *lstart
= conf
->unexpanded_config
;
2334 if (!conf
->unexpanded_config
)
2338 lend
= strchr(lstart
, '\n');
2341 lend
= lstart
+ strlen(lstart
);
2344 if (strncmp(lstart
, key
, strlen(key
)) != 0) {
2349 v
= lstart
[strlen(key
)];
2350 if (!isspace(v
) && v
!= '=') {
2355 conf
->unexpanded_len
-= (lend
- lstart
);
2356 if (*lend
== '\0') {
2360 memmove(lstart
, lend
, strlen(lend
) + 1);
2364 bool clone_update_unexp_ovl_paths(struct lxc_conf
*conf
, const char *oldpath
,
2365 const char *newpath
, const char *oldname
,
2366 const char *newname
, const char *ovldir
)
2369 char *lend
, *newdir
, *olddir
, *p
, *q
;
2370 size_t newdirlen
, olddirlen
;
2371 char *lstart
= conf
->unexpanded_config
;
2372 const char *key
= "lxc.mount.entry";
2374 olddirlen
= strlen(ovldir
) + strlen(oldpath
) + strlen(oldname
) + 2;
2375 olddir
= alloca(olddirlen
+ 1);
2376 ret
= snprintf(olddir
, olddirlen
+ 1, "%s=%s/%s", ovldir
, oldpath
,
2378 if (ret
< 0 || ret
>= olddirlen
+ 1)
2381 newdirlen
= strlen(ovldir
) + strlen(newpath
) + strlen(newname
) + 2;
2382 newdir
= alloca(newdirlen
+ 1);
2383 ret
= snprintf(newdir
, newdirlen
+ 1, "%s=%s/%s", ovldir
, newpath
,
2385 if (ret
< 0 || ret
>= newdirlen
+ 1)
2388 if (!conf
->unexpanded_config
)
2392 lend
= strchr(lstart
, '\n');
2394 lend
= lstart
+ strlen(lstart
);
2398 if (strncmp(lstart
, key
, strlen(key
)) != 0)
2401 p
= strchr(lstart
+ strlen(key
), '=');
2412 /* Whenever an lxc.mount.entry entry is found in a line we check
2413 * if the substring " overlay" or the substring " aufs" is
2414 * present before doing any further work. We check for "
2415 * overlay" and " aufs" since both substrings need to have at
2416 * least one space before them in a valid overlay
2417 * lxc.mount.entry (/A B overlay). When the space before is
2418 * missing it is very likely that these substrings are part of a
2419 * path or something else. (Checking q >= lend ensures that we
2420 * only count matches in the current line.) */
2421 if ((!(q
= strstr(p
, " overlay")) || q
>= lend
) &&
2422 (!(q
= strstr(p
, " aufs")) || q
>= lend
))
2425 if (!(q
= strstr(p
, olddir
)) || (q
>= lend
))
2428 /* replace the olddir with newdir */
2429 if (olddirlen
>= newdirlen
) {
2430 size_t diff
= olddirlen
- newdirlen
;
2431 memcpy(q
, newdir
, newdirlen
);
2432 if (olddirlen
!= newdirlen
) {
2433 memmove(q
+ newdirlen
, q
+ newdirlen
+ diff
,
2434 strlen(q
) - newdirlen
- diff
+ 1);
2436 conf
->unexpanded_len
-= diff
;
2440 size_t diff
= newdirlen
- olddirlen
;
2441 size_t oldlen
= conf
->unexpanded_len
;
2442 size_t newlen
= oldlen
+ diff
;
2443 size_t poffset
= q
- conf
->unexpanded_config
;
2445 new = realloc(conf
->unexpanded_config
, newlen
+ 1);
2449 conf
->unexpanded_len
= newlen
;
2450 conf
->unexpanded_alloced
= newlen
+ 1;
2451 new[newlen
- 1] = '\0';
2452 lend
= new + (lend
- conf
->unexpanded_config
);
2453 /* Move over the remainder to make room for the newdir.
2455 memmove(new + poffset
+ newdirlen
,
2456 new + poffset
+ olddirlen
,
2457 oldlen
- poffset
- olddirlen
+ 1);
2458 conf
->unexpanded_config
= new;
2459 memcpy(new + poffset
, newdir
, newdirlen
);
2469 bool clone_update_unexp_hooks(struct lxc_conf
*conf
, const char *oldpath
,
2470 const char *newpath
, const char *oldname
,
2471 const char *newname
)
2474 char *lend
, *newdir
, *olddir
, *p
;
2475 char *lstart
= conf
->unexpanded_config
;
2476 size_t newdirlen
, olddirlen
;
2477 const char *key
= "lxc.hook";
2479 olddirlen
= strlen(oldpath
) + strlen(oldname
) + 1;
2480 olddir
= alloca(olddirlen
+ 1);
2481 ret
= snprintf(olddir
, olddirlen
+ 1, "%s/%s", oldpath
, oldname
);
2482 if (ret
< 0 || ret
>= olddirlen
+ 1)
2485 newdirlen
= strlen(newpath
) + strlen(newname
) + 1;
2486 newdir
= alloca(newdirlen
+ 1);
2487 ret
= snprintf(newdir
, newdirlen
+ 1, "%s/%s", newpath
, newname
);
2488 if (ret
< 0 || ret
>= newdirlen
+ 1)
2491 if (!conf
->unexpanded_config
)
2495 lend
= strchr(lstart
, '\n');
2497 lend
= lstart
+ strlen(lstart
);
2501 if (strncmp(lstart
, key
, strlen(key
)) != 0)
2504 p
= strchr(lstart
+ strlen(key
), '=');
2515 if (strncmp(p
, olddir
, strlen(olddir
)) != 0)
2518 /* replace the olddir with newdir */
2519 if (olddirlen
>= newdirlen
) {
2520 size_t diff
= olddirlen
- newdirlen
;
2521 memcpy(p
, newdir
, newdirlen
);
2522 if (olddirlen
!= newdirlen
) {
2523 memmove(p
+ newdirlen
, p
+ newdirlen
+ diff
,
2524 strlen(p
) - newdirlen
- diff
+ 1);
2526 conf
->unexpanded_len
-= diff
;
2530 size_t diff
= newdirlen
- olddirlen
;
2531 size_t oldlen
= conf
->unexpanded_len
;
2532 size_t newlen
= oldlen
+ diff
;
2533 size_t poffset
= p
- conf
->unexpanded_config
;
2535 new = realloc(conf
->unexpanded_config
, newlen
+ 1);
2539 conf
->unexpanded_len
= newlen
;
2540 conf
->unexpanded_alloced
= newlen
+ 1;
2541 new[newlen
- 1] = '\0';
2542 lend
= new + (lend
- conf
->unexpanded_config
);
2543 /* Move over the remainder to make room for the newdir.
2545 memmove(new + poffset
+ newdirlen
,
2546 new + poffset
+ olddirlen
,
2547 oldlen
- poffset
- olddirlen
+ 1);
2548 conf
->unexpanded_config
= new;
2549 memcpy(new + poffset
, newdir
, newdirlen
);
2562 ERROR("Error writing to new config"); \
2567 /* This is called only from clone. We wish to update all hwaddrs in the
2568 * unexpanded config file. We can't/don't want to update any which come from
2569 * lxc.includes (there shouldn't be any).
2570 * We can't just walk the c->lxc-conf->network list because that includes netifs
2571 * from the include files. So we update the ones which we find in the unexp
2572 * config file, then find the original macaddr in the conf->network, and update
2573 * that to the same value.
2575 bool network_new_hwaddrs(struct lxc_conf
*conf
)
2577 char *lend
, *p
, *p2
;
2578 struct lxc_list
*it
;
2579 char *lstart
= conf
->unexpanded_config
;
2581 if (!conf
->unexpanded_config
)
2585 char newhwaddr
[18], oldhwaddr
[17];
2587 lend
= strchr(lstart
, '\n');
2589 lend
= lstart
+ strlen(lstart
);
2593 if (!lxc_config_net_hwaddr(lstart
)) {
2598 p
= strchr(lstart
, '=');
2611 while (*p2
&& !isblank(*p2
) && *p2
!= '\n')
2614 if ((p2
- p
) != 17) {
2615 WARN("Bad hwaddr entry");
2620 memcpy(oldhwaddr
, p
, 17);
2622 if (!new_hwaddr(newhwaddr
))
2625 memcpy(p
, newhwaddr
, 17);
2626 lxc_list_for_each(it
, &conf
->network
) {
2627 struct lxc_netdev
*n
= it
->elem
;
2629 if (n
->hwaddr
&& memcmp(oldhwaddr
, n
->hwaddr
, 17) == 0)
2630 memcpy(n
->hwaddr
, newhwaddr
, 17);
2639 static int set_config_ephemeral(const char *key
, const char *value
,
2640 struct lxc_conf
*lxc_conf
, void *data
)
2642 if (lxc_config_value_empty(value
)) {
2643 lxc_conf
->ephemeral
= 0;
2647 if (lxc_safe_uint(value
, &lxc_conf
->ephemeral
) < 0)
2650 if (lxc_conf
->ephemeral
> 1)
2656 static int set_config_log_syslog(const char *key
, const char *value
,
2657 struct lxc_conf
*lxc_conf
, void *data
)
2661 if (lxc_conf
->syslog
) {
2662 free(lxc_conf
->syslog
);
2663 lxc_conf
->syslog
= NULL
;
2666 if (lxc_config_value_empty(value
))
2669 facility
= lxc_syslog_priority_to_int(value
);
2670 if (facility
== -EINVAL
)
2673 lxc_log_syslog(facility
);
2674 return set_config_string_item(&lxc_conf
->syslog
, value
);
2677 static int set_config_no_new_privs(const char *key
, const char *value
,
2678 struct lxc_conf
*lxc_conf
, void *data
)
2682 if (lxc_config_value_empty(value
)) {
2683 lxc_conf
->no_new_privs
= false;
2687 if (lxc_safe_uint(value
, &v
) < 0)
2693 lxc_conf
->no_new_privs
= v
? true : false;
2698 static int set_config_noop(const char *key
, const char *value
,
2699 struct lxc_conf
*lxc_conf
, void *data
)
2704 /* Callbacks to get configuration items. */
2705 static int get_config_personality(const char *key
, char *retv
, int inlen
,
2706 struct lxc_conf
*c
, void *data
)
2713 memset(retv
, 0, inlen
);
2715 #if HAVE_SYS_PERSONALITY_H
2718 switch (c
->personality
) {
2720 strprint(retv
, inlen
, "i686");
2723 strprint(retv
, inlen
, "x86_64");
2733 static int get_config_pty_max(const char *key
, char *retv
, int inlen
,
2734 struct lxc_conf
*c
, void *data
)
2736 return lxc_get_conf_int(c
, retv
, inlen
, c
->pts
);
2739 static int get_config_tty_max(const char *key
, char *retv
, int inlen
,
2740 struct lxc_conf
*c
, void *data
)
2742 return lxc_get_conf_int(c
, retv
, inlen
, c
->tty
);
2745 static int get_config_tty_dir(const char *key
, char *retv
, int inlen
,
2746 struct lxc_conf
*c
, void *data
)
2748 return lxc_get_conf_str(retv
, inlen
, c
->ttydir
);
2751 static int get_config_apparmor_profile(const char *key
, char *retv
, int inlen
,
2752 struct lxc_conf
*c
, void *data
)
2754 return lxc_get_conf_str(retv
, inlen
, c
->lsm_aa_profile
);
2757 static int get_config_apparmor_allow_incomplete(const char *key
, char *retv
,
2758 int inlen
, struct lxc_conf
*c
,
2761 return lxc_get_conf_int(c
, retv
, inlen
,
2762 c
->lsm_aa_allow_incomplete
);
2765 static int get_config_selinux_context(const char *key
, char *retv
, int inlen
,
2766 struct lxc_conf
*c
, void *data
)
2768 return lxc_get_conf_str(retv
, inlen
, c
->lsm_se_context
);
2771 /* If you ask for a specific cgroup value, i.e. lxc.cgroup.devices.list, then
2772 * just the value(s) will be printed. Since there still could be more than one,
2773 * it is newline-separated.
2774 * (Maybe that's ambigous, since some values, i.e. devices.list, will already
2776 * If you ask for 'lxc.cgroup", then all cgroup entries will be printed, in
2777 * 'lxc.cgroup.subsystem.key = value' format.
2779 static int get_config_cgroup_controller(const char *key
, char *retv
, int inlen
,
2780 struct lxc_conf
*c
, void *data
)
2782 struct lxc_list
*it
;
2785 bool get_all
= false;
2790 memset(retv
, 0, inlen
);
2792 if (!strcmp(key
, "lxc.cgroup"))
2794 else if (!strncmp(key
, "lxc.cgroup.", 11))
2799 lxc_list_for_each(it
, &c
->cgroup
) {
2800 struct lxc_cgroup
*cg
= it
->elem
;
2803 strprint(retv
, inlen
, "lxc.cgroup.%s = %s\n",
2804 cg
->subsystem
, cg
->value
);
2805 } else if (!strcmp(cg
->subsystem
, key
)) {
2806 strprint(retv
, inlen
, "%s\n", cg
->value
);
2813 static int get_config_cgroup_dir(const char *key
, char *retv
, int inlen
,
2814 struct lxc_conf
*lxc_conf
, void *data
)
2822 memset(retv
, 0, inlen
);
2824 strprint(retv
, inlen
, "%s", lxc_conf
->cgroup_meta
.dir
);
2829 static int get_config_idmaps(const char *key
, char *retv
, int inlen
,
2830 struct lxc_conf
*c
, void *data
)
2832 struct lxc_list
*it
;
2833 int len
, listlen
, ret
;
2835 /* "u 1000 1000000 65536"
2837 * let's render this as
2855 #define __LXC_IDMAP_STR_BUF (3 * LXC_NUMSTRLEN64 + 3 + 1 + 1)
2856 char buf
[__LXC_IDMAP_STR_BUF
];
2861 memset(retv
, 0, inlen
);
2863 listlen
= lxc_list_len(&c
->id_map
);
2864 lxc_list_for_each(it
, &c
->id_map
)
2866 struct id_map
*map
= it
->elem
;
2867 ret
= snprintf(buf
, __LXC_IDMAP_STR_BUF
, "%c %lu %lu %lu",
2868 (map
->idtype
== ID_TYPE_UID
) ? 'u' : 'g',
2869 map
->nsid
, map
->hostid
, map
->range
);
2870 if (ret
< 0 || ret
>= __LXC_IDMAP_STR_BUF
)
2873 strprint(retv
, inlen
, "%s%s", buf
, (listlen
-- > 1) ? "\n" : "");
2878 static int get_config_log_level(const char *key
, char *retv
, int inlen
,
2879 struct lxc_conf
*c
, void *data
)
2882 v
= lxc_log_priority_to_string(c
->loglevel
);
2883 return lxc_get_conf_str(retv
, inlen
, v
);
2886 static int get_config_log_file(const char *key
, char *retv
, int inlen
,
2887 struct lxc_conf
*c
, void *data
)
2889 return lxc_get_conf_str(retv
, inlen
, c
->logfile
);
2892 static int get_config_mount_fstab(const char *key
, char *retv
, int inlen
,
2893 struct lxc_conf
*c
, void *data
)
2895 return lxc_get_conf_str(retv
, inlen
, c
->fstab
);
2898 static int get_config_mount_auto(const char *key
, char *retv
, int inlen
,
2899 struct lxc_conf
*c
, void *data
)
2901 int len
, fulllen
= 0;
2902 const char *sep
= "";
2907 memset(retv
, 0, inlen
);
2909 if (!(c
->auto_mounts
& LXC_AUTO_ALL_MASK
))
2912 switch (c
->auto_mounts
& LXC_AUTO_PROC_MASK
) {
2913 case LXC_AUTO_PROC_MIXED
:
2914 strprint(retv
, inlen
, "%sproc:mixed", sep
);
2917 case LXC_AUTO_PROC_RW
:
2918 strprint(retv
, inlen
, "%sproc:rw", sep
);
2925 switch (c
->auto_mounts
& LXC_AUTO_SYS_MASK
) {
2926 case LXC_AUTO_SYS_RO
:
2927 strprint(retv
, inlen
, "%ssys:ro", sep
);
2930 case LXC_AUTO_SYS_RW
:
2931 strprint(retv
, inlen
, "%ssys:rw", sep
);
2934 case LXC_AUTO_SYS_MIXED
:
2935 strprint(retv
, inlen
, "%ssys:mixed", sep
);
2942 switch (c
->auto_mounts
& LXC_AUTO_CGROUP_MASK
) {
2943 case LXC_AUTO_CGROUP_NOSPEC
:
2944 strprint(retv
, inlen
, "%scgroup", sep
);
2947 case LXC_AUTO_CGROUP_MIXED
:
2948 strprint(retv
, inlen
, "%scgroup:mixed", sep
);
2951 case LXC_AUTO_CGROUP_RO
:
2952 strprint(retv
, inlen
, "%scgroup:ro", sep
);
2955 case LXC_AUTO_CGROUP_RW
:
2956 strprint(retv
, inlen
, "%scgroup:rw", sep
);
2959 case LXC_AUTO_CGROUP_FULL_NOSPEC
:
2960 strprint(retv
, inlen
, "%scgroup-full", sep
);
2963 case LXC_AUTO_CGROUP_FULL_MIXED
:
2964 strprint(retv
, inlen
, "%scgroup-full:mixed", sep
);
2967 case LXC_AUTO_CGROUP_FULL_RO
:
2968 strprint(retv
, inlen
, "%scgroup-full:ro", sep
);
2971 case LXC_AUTO_CGROUP_FULL_RW
:
2972 strprint(retv
, inlen
, "%scgroup-full:rw", sep
);
2982 static int get_config_mount(const char *key
, char *retv
, int inlen
,
2983 struct lxc_conf
*c
, void *data
)
2985 int len
, fulllen
= 0;
2986 struct lxc_list
*it
;
2991 memset(retv
, 0, inlen
);
2993 lxc_list_for_each(it
, &c
->mount_list
) {
2994 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3000 static int get_config_rootfs_path(const char *key
, char *retv
, int inlen
,
3001 struct lxc_conf
*c
, void *data
)
3003 return lxc_get_conf_str(retv
, inlen
, c
->rootfs
.path
);
3006 static int get_config_rootfs_mount(const char *key
, char *retv
, int inlen
,
3007 struct lxc_conf
*c
, void *data
)
3009 return lxc_get_conf_str(retv
, inlen
, c
->rootfs
.mount
);
3012 static int get_config_rootfs_options(const char *key
, char *retv
, int inlen
,
3013 struct lxc_conf
*c
, void *data
)
3015 return lxc_get_conf_str(retv
, inlen
, c
->rootfs
.options
);
3018 static int get_config_rootfs_backend(const char *key
, char *retv
, int inlen
,
3019 struct lxc_conf
*c
, void *data
)
3024 static int get_config_uts_name(const char *key
, char *retv
, int inlen
,
3025 struct lxc_conf
*c
, void *data
)
3027 return lxc_get_conf_str(
3029 c
->utsname
? c
->utsname
->nodename
: NULL
);
3032 static int get_config_hooks(const char *key
, char *retv
, int inlen
,
3033 struct lxc_conf
*c
, void *data
)
3036 int len
, fulllen
= 0, found
= -1;
3037 struct lxc_list
*it
;
3040 subkey
= strchr(key
, '.');
3042 subkey
= strchr(subkey
+ 1, '.');
3048 for (i
= 0; i
< NUM_LXC_HOOKS
; i
++) {
3049 if (strcmp(lxchook_names
[i
], subkey
) == 0) {
3060 memset(retv
, 0, inlen
);
3062 lxc_list_for_each(it
, &c
->hooks
[found
]) {
3063 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3068 static int get_config_net(const char *key
, char *retv
, int inlen
,
3069 struct lxc_conf
*c
, void *data
)
3071 int len
, fulllen
= 0;
3072 struct lxc_list
*it
;
3077 memset(retv
, 0, inlen
);
3079 lxc_list_for_each(it
, &c
->network
) {
3080 struct lxc_netdev
*n
= it
->elem
;
3081 const char *t
= lxc_net_type_to_str(n
->type
);
3082 strprint(retv
, inlen
, "%s\n", t
? t
: "(invalid)");
3088 static int get_config_cap_drop(const char *key
, char *retv
, int inlen
,
3089 struct lxc_conf
*c
, void *data
)
3091 int len
, fulllen
= 0;
3092 struct lxc_list
*it
;
3097 memset(retv
, 0, inlen
);
3099 lxc_list_for_each(it
, &c
->caps
) {
3100 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3106 static int get_config_cap_keep(const char *key
, char *retv
, int inlen
,
3107 struct lxc_conf
*c
, void *data
)
3109 int len
, fulllen
= 0;
3110 struct lxc_list
*it
;
3115 memset(retv
, 0, inlen
);
3117 lxc_list_for_each(it
, &c
->keepcaps
) {
3118 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3124 static int get_config_console_path(const char *key
, char *retv
, int inlen
,
3125 struct lxc_conf
*c
, void *data
)
3127 return lxc_get_conf_str(retv
, inlen
, c
->console
.path
);
3130 static int get_config_console_logfile(const char *key
, char *retv
, int inlen
,
3131 struct lxc_conf
*c
, void *data
)
3133 return lxc_get_conf_str(retv
, inlen
, c
->console
.log_path
);
3136 static int get_config_console_rotate(const char *key
, char *retv
, int inlen
,
3137 struct lxc_conf
*c
, void *data
)
3139 return lxc_get_conf_int(c
, retv
, inlen
, c
->console
.log_rotate
);
3143 static int get_config_console_buffer_size(const char *key
, char *retv
,
3144 int inlen
, struct lxc_conf
*c
,
3147 return lxc_get_conf_uint64(c
, retv
, inlen
, c
->autodev
);
3150 static int get_config_console_buffer_logfile(const char *key
, char *retv
,
3151 int inlen
, struct lxc_conf
*c
,
3154 return lxc_get_conf_str(retv
, inlen
, c
->console
.buffer_log_file
);
3157 static int get_config_seccomp_profile(const char *key
, char *retv
, int inlen
,
3158 struct lxc_conf
*c
, void *data
)
3160 return lxc_get_conf_str(retv
, inlen
, c
->seccomp
);
3163 static int get_config_autodev(const char *key
, char *retv
, int inlen
,
3164 struct lxc_conf
*c
, void *data
)
3166 return lxc_get_conf_int(c
, retv
, inlen
, c
->autodev
);
3169 static int get_config_signal_halt(const char *key
, char *retv
, int inlen
,
3170 struct lxc_conf
*c
, void *data
)
3172 return lxc_get_conf_int(c
, retv
, inlen
, c
->haltsignal
);
3175 static int get_config_signal_reboot(const char *key
, char *retv
, int inlen
,
3176 struct lxc_conf
*c
, void *data
)
3178 return lxc_get_conf_int(c
, retv
, inlen
, c
->rebootsignal
);
3181 static int get_config_signal_stop(const char *key
, char *retv
, int inlen
,
3182 struct lxc_conf
*c
, void *data
)
3184 return lxc_get_conf_int(c
, retv
, inlen
, c
->stopsignal
);
3187 static int get_config_start(const char *key
, char *retv
, int inlen
,
3188 struct lxc_conf
*c
, void *data
)
3190 if (strcmp(key
+ 10, "auto") == 0)
3191 return lxc_get_conf_int(c
, retv
, inlen
, c
->start_auto
);
3192 else if (strcmp(key
+ 10, "delay") == 0)
3193 return lxc_get_conf_int(c
, retv
, inlen
, c
->start_delay
);
3194 else if (strcmp(key
+ 10, "order") == 0)
3195 return lxc_get_conf_int(c
, retv
, inlen
, c
->start_order
);
3200 static int get_config_log_syslog(const char *key
, char *retv
, int inlen
,
3201 struct lxc_conf
*c
, void *data
)
3203 return lxc_get_conf_str(retv
, inlen
, c
->syslog
);
3206 static int get_config_monitor(const char *key
, char *retv
, int inlen
,
3207 struct lxc_conf
*c
, void *data
)
3209 return lxc_get_conf_int(c
, retv
, inlen
, c
->monitor_unshare
);
3212 static int get_config_group(const char *key
, char *retv
, int inlen
,
3213 struct lxc_conf
*c
, void *data
)
3215 int len
, fulllen
= 0;
3216 struct lxc_list
*it
;
3221 memset(retv
, 0, inlen
);
3223 lxc_list_for_each(it
, &c
->groups
) {
3224 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3230 static int get_config_environment(const char *key
, char *retv
, int inlen
,
3231 struct lxc_conf
*c
, void *data
)
3233 int len
, fulllen
= 0;
3234 struct lxc_list
*it
;
3239 memset(retv
, 0, inlen
);
3241 lxc_list_for_each(it
, &c
->environment
) {
3242 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3248 static int get_config_execute_cmd(const char *key
, char *retv
, int inlen
,
3249 struct lxc_conf
*c
, void *data
)
3251 return lxc_get_conf_str(retv
, inlen
, c
->execute_cmd
);
3254 static int get_config_init_cmd(const char *key
, char *retv
, int inlen
,
3255 struct lxc_conf
*c
, void *data
)
3257 return lxc_get_conf_str(retv
, inlen
, c
->init_cmd
);
3260 static int get_config_init_cwd(const char *key
, char *retv
, int inlen
,
3261 struct lxc_conf
*c
, void *data
)
3263 return lxc_get_conf_str(retv
, inlen
, c
->init_cwd
);
3266 static int get_config_init_uid(const char *key
, char *retv
, int inlen
,
3267 struct lxc_conf
*c
, void *data
)
3269 return lxc_get_conf_int(c
, retv
, inlen
, c
->init_uid
);
3272 static int get_config_init_gid(const char *key
, char *retv
, int inlen
,
3273 struct lxc_conf
*c
, void *data
)
3275 return lxc_get_conf_int(c
, retv
, inlen
, c
->init_gid
);
3278 static int get_config_ephemeral(const char *key
, char *retv
, int inlen
,
3279 struct lxc_conf
*c
, void *data
)
3281 return lxc_get_conf_int(c
, retv
, inlen
, c
->ephemeral
);
3284 static int get_config_no_new_privs(const char *key
, char *retv
, int inlen
,
3285 struct lxc_conf
*c
, void *data
)
3287 return lxc_get_conf_int(c
, retv
, inlen
, c
->no_new_privs
);
3290 /* If you ask for a specific value, i.e. lxc.prlimit.nofile, then just the value
3291 * will be printed. If you ask for 'lxc.prlimit', then all limit entries will be
3292 * printed, in 'lxc.prlimit.resource = value' format.
3294 static int get_config_prlimit(const char *key
, char *retv
, int inlen
,
3295 struct lxc_conf
*c
, void *data
)
3297 int fulllen
= 0, len
;
3298 bool get_all
= false;
3299 struct lxc_list
*it
;
3304 memset(retv
, 0, inlen
);
3306 if (!strcmp(key
, "lxc.prlimit"))
3308 else if (strncmp(key
, "lxc.prlimit.", 12) == 0)
3313 lxc_list_for_each(it
, &c
->limits
) {
3314 char buf
[LXC_NUMSTRLEN64
* 2 + 2]; /* 2 colon separated 64 bit
3315 integers or the word
3318 struct lxc_limit
*lim
= it
->elem
;
3320 if (lim
->limit
.rlim_cur
== RLIM_INFINITY
) {
3321 memcpy(buf
, "unlimited", sizeof("unlimited"));
3322 partlen
= sizeof("unlimited") - 1;
3324 partlen
= sprintf(buf
, "%" PRIu64
,
3325 (uint64_t)lim
->limit
.rlim_cur
);
3327 if (lim
->limit
.rlim_cur
!= lim
->limit
.rlim_max
) {
3328 if (lim
->limit
.rlim_max
== RLIM_INFINITY
)
3329 memcpy(buf
+ partlen
, ":unlimited",
3330 sizeof(":unlimited"));
3332 sprintf(buf
+ partlen
, ":%" PRIu64
,
3333 (uint64_t)lim
->limit
.rlim_max
);
3337 strprint(retv
, inlen
, "lxc.prlimit.%s = %s\n",
3338 lim
->resource
, buf
);
3339 } else if (!strcmp(lim
->resource
, key
)) {
3340 strprint(retv
, inlen
, "%s", buf
);
3347 static int get_config_noop(const char *key
, char *retv
, int inlen
,
3348 struct lxc_conf
*c
, void *data
)
3353 static int get_config_namespace(const char *key
, char *retv
, int inlen
,
3354 struct lxc_conf
*c
, void *data
)
3357 const char *namespace;
3363 memset(retv
, 0, inlen
);
3365 namespace = key
+ sizeof("lxc.namespace.") - 1;
3366 ns_idx
= lxc_namespace_2_ns_idx(namespace);
3370 strprint(retv
, inlen
, "%s", c
->inherit_ns
[ns_idx
]);
3375 /* Callbacks to clear config items. */
3376 static inline int clr_config_personality(const char *key
, struct lxc_conf
*c
,
3379 c
->personality
= -1;
3383 static inline int clr_config_pty_max(const char *key
, struct lxc_conf
*c
,
3390 static inline int clr_config_tty_max(const char *key
, struct lxc_conf
*c
,
3397 static inline int clr_config_tty_dir(const char *key
, struct lxc_conf
*c
,
3405 static inline int clr_config_apparmor_profile(const char *key
,
3406 struct lxc_conf
*c
, void *data
)
3408 free(c
->lsm_aa_profile
);
3409 c
->lsm_aa_profile
= NULL
;
3413 static inline int clr_config_apparmor_allow_incomplete(const char *key
,
3417 c
->lsm_aa_allow_incomplete
= 0;
3421 static inline int clr_config_selinux_context(const char *key
,
3422 struct lxc_conf
*c
, void *data
)
3424 free(c
->lsm_se_context
);
3425 c
->lsm_se_context
= NULL
;
3429 static inline int clr_config_cgroup_controller(const char *key
,
3430 struct lxc_conf
*c
, void *data
)
3432 return lxc_clear_cgroups(c
, key
);
3435 static int clr_config_cgroup_dir(const char *key
, struct lxc_conf
*lxc_conf
,
3438 if (lxc_conf
->cgroup_meta
.dir
) {
3439 free(lxc_conf
->cgroup_meta
.dir
);
3440 lxc_conf
->cgroup_meta
.dir
= NULL
;
3446 static inline int clr_config_idmaps(const char *key
, struct lxc_conf
*c
,
3449 return lxc_clear_idmaps(c
);
3452 static inline int clr_config_log_level(const char *key
, struct lxc_conf
*c
,
3455 c
->loglevel
= LXC_LOG_LEVEL_NOTSET
;
3459 static inline int clr_config_log_file(const char *key
, struct lxc_conf
*c
,
3467 static inline int clr_config_mount(const char *key
, struct lxc_conf
*c
,
3470 return lxc_clear_mount_entries(c
);
3473 static inline int clr_config_mount_auto(const char *key
, struct lxc_conf
*c
,
3476 return lxc_clear_automounts(c
);
3479 static inline int clr_config_mount_fstab(const char *key
, struct lxc_conf
*c
,
3487 static inline int clr_config_rootfs_path(const char *key
, struct lxc_conf
*c
,
3490 free(c
->rootfs
.path
);
3491 c
->rootfs
.path
= NULL
;
3495 static inline int clr_config_rootfs_mount(const char *key
, struct lxc_conf
*c
,
3498 free(c
->rootfs
.mount
);
3499 c
->rootfs
.mount
= NULL
;
3503 static inline int clr_config_rootfs_options(const char *key
, struct lxc_conf
*c
,
3506 free(c
->rootfs
.options
);
3507 c
->rootfs
.options
= NULL
;
3511 static inline int clr_config_rootfs_backend(const char *key
, struct lxc_conf
*c
,
3517 static inline int clr_config_uts_name(const char *key
, struct lxc_conf
*c
,
3525 static inline int clr_config_hooks(const char *key
, struct lxc_conf
*c
,
3528 return lxc_clear_hooks(c
, key
);
3531 static inline int clr_config_net(const char *key
, struct lxc_conf
*c
,
3534 lxc_free_networks(&c
->network
);
3539 static inline int clr_config_cap_drop(const char *key
, struct lxc_conf
*c
,
3542 return lxc_clear_config_caps(c
);
3545 static inline int clr_config_cap_keep(const char *key
, struct lxc_conf
*c
,
3548 return lxc_clear_config_keepcaps(c
);
3551 static inline int clr_config_console_path(const char *key
, struct lxc_conf
*c
,
3554 free(c
->console
.path
);
3555 c
->console
.path
= NULL
;
3559 static inline int clr_config_console_logfile(const char *key
,
3560 struct lxc_conf
*c
, void *data
)
3562 free(c
->console
.log_path
);
3563 c
->console
.log_path
= NULL
;
3567 static inline int clr_config_console_rotate(const char *key
, struct lxc_conf
*c
,
3570 c
->console
.log_rotate
= 0;
3574 static inline int clr_config_console_buffer_size(const char *key
,
3575 struct lxc_conf
*c
, void *data
)
3577 c
->console
.buffer_size
= 0;
3581 static inline int clr_config_console_buffer_logfile(const char *key
,
3585 free(c
->console
.buffer_log_file
);
3586 c
->console
.buffer_log_file
= NULL
;
3590 static inline int clr_config_seccomp_profile(const char *key
,
3591 struct lxc_conf
*c
, void *data
)
3598 static inline int clr_config_autodev(const char *key
, struct lxc_conf
*c
,
3605 static inline int clr_config_signal_halt(const char *key
, struct lxc_conf
*c
,
3612 static inline int clr_config_signal_reboot(const char *key
, struct lxc_conf
*c
,
3615 c
->rebootsignal
= 0;
3619 static inline int clr_config_signal_stop(const char *key
, struct lxc_conf
*c
,
3626 static inline int clr_config_start(const char *key
, struct lxc_conf
*c
,
3629 if (strcmp(key
+ 10, "auto") == 0)
3631 else if (strcmp(key
+ 10, "delay") == 0)
3633 else if (strcmp(key
+ 10, "order") == 0)
3639 static inline int clr_config_log_syslog(const char *key
, struct lxc_conf
*c
,
3647 static inline int clr_config_monitor(const char *key
, struct lxc_conf
*c
,
3650 c
->monitor_unshare
= 0;
3654 static inline int clr_config_group(const char *key
, struct lxc_conf
*c
,
3657 return lxc_clear_groups(c
);
3660 static inline int clr_config_environment(const char *key
, struct lxc_conf
*c
,
3663 return lxc_clear_environment(c
);
3666 static inline int clr_config_execute_cmd(const char *key
, struct lxc_conf
*c
,
3669 free(c
->execute_cmd
);
3670 c
->execute_cmd
= NULL
;
3674 static inline int clr_config_init_cmd(const char *key
, struct lxc_conf
*c
,
3682 static inline int clr_config_init_cwd(const char *key
, struct lxc_conf
*c
,
3690 static inline int clr_config_init_uid(const char *key
, struct lxc_conf
*c
,
3697 static inline int clr_config_init_gid(const char *key
, struct lxc_conf
*c
,
3704 static inline int clr_config_ephemeral(const char *key
, struct lxc_conf
*c
,
3711 static inline int clr_config_no_new_privs(const char *key
, struct lxc_conf
*c
,
3714 c
->no_new_privs
= false;
3718 static inline int clr_config_prlimit(const char *key
, struct lxc_conf
*c
,
3721 return lxc_clear_limits(c
, key
);
3724 static inline int clr_config_includefiles(const char *key
, struct lxc_conf
*c
,
3727 lxc_clear_includes(c
);
3731 static inline int clr_config_noop(const char *key
, struct lxc_conf
*c
,
3737 static int clr_config_namespace(const char *key
, struct lxc_conf
*lxc_conf
,
3741 const char *namespace;
3743 namespace = key
+ sizeof("lxc.namespace.") - 1;
3744 ns_idx
= lxc_namespace_2_ns_idx(namespace);
3748 free(lxc_conf
->inherit_ns
[ns_idx
]);
3749 lxc_conf
->inherit_ns
[ns_idx
] = NULL
;
3754 static int get_config_includefiles(const char *key
, char *retv
, int inlen
,
3755 struct lxc_conf
*c
, void *data
)
3760 static struct lxc_config_t
*get_network_config_ops(const char *key
,
3761 struct lxc_conf
*lxc_conf
,
3763 char **deindexed_key
)
3766 unsigned int tmpidx
;
3768 char *copy
, *idx_start
, *idx_end
;
3769 struct lxc_config_t
*config
= NULL
;
3771 /* check that this is a sensible network key */
3772 if (strncmp("lxc.net.", key
, 8)) {
3773 ERROR("Invalid network configuration key \"%s\"", key
);
3779 ERROR("Failed to duplicate string \"%s\"", key
);
3784 if (!isdigit(*(key
+ 8))) {
3785 ERROR("Failed to detect digit in string \"%s\"", key
+ 8);
3789 /* beginning of index string */
3790 idx_start
= (copy
+ 7);
3793 /* end of index string */
3794 idx_end
= strchr((copy
+ 8), '.');
3798 /* parse current index */
3799 ret
= lxc_safe_uint((idx_start
+ 1), &tmpidx
);
3801 ERROR("Failed to parse usigned integer from string \"%s\": %s",
3802 idx_start
+ 1, strerror(-ret
));
3807 /* This, of course is utterly nonsensical on so many levels, but
3808 * better safe than sorry.
3809 * (Checking for INT_MAX here is intentional.)
3811 if (tmpidx
== INT_MAX
) {
3812 SYSERROR("Number of configured networks would overflow the "
3818 numstrlen
= strlen((idx_start
+ 1));
3820 /* repair configuration key */
3823 /* lxc.net.<idx>.<subkey> */
3826 if (strlen(idx_end
+ 1) == 0) {
3827 ERROR("No subkey in network configuration key \"%s\"", key
);
3831 memmove(copy
+ 8, idx_end
+ 1, strlen(idx_end
+ 1));
3832 copy
[strlen(key
) - numstrlen
+ 1] = '\0';
3834 config
= lxc_get_config(copy
);
3836 ERROR("Unknown network configuration key \"%s\"", key
);
3842 *deindexed_key
= copy
;
3851 /* Config entry is something like "lxc.net.0.ipv4" the key 'lxc.net.' was
3852 * found. So we make sure next comes an integer, find the right callback (by
3853 * rewriting the key), and call it.
3855 static int set_config_net_nic(const char *key
, const char *value
,
3856 struct lxc_conf
*lxc_conf
, void *data
)
3859 const char *idxstring
;
3860 struct lxc_config_t
*config
;
3861 struct lxc_netdev
*netdev
;
3863 char *deindexed_key
= NULL
;
3865 idxstring
= key
+ 8;
3866 if (!isdigit(*idxstring
))
3869 if (lxc_config_value_empty(value
))
3870 return clr_config_net_nic(key
, lxc_conf
, data
);
3872 config
= get_network_config_ops(key
, lxc_conf
, &idx
, &deindexed_key
);
3873 if (!config
|| idx
< 0)
3876 netdev
= lxc_get_netdev_by_idx(lxc_conf
, (unsigned int)idx
, true);
3878 free(deindexed_key
);
3882 ret
= config
->set(deindexed_key
, value
, lxc_conf
, netdev
);
3883 free(deindexed_key
);
3887 static int clr_config_net_nic(const char *key
, struct lxc_conf
*lxc_conf
,
3891 const char *idxstring
;
3892 struct lxc_config_t
*config
;
3893 struct lxc_netdev
*netdev
;
3895 char *deindexed_key
= NULL
;
3897 idxstring
= key
+ 8;
3898 if (!isdigit(*idxstring
))
3901 /* The left conjunct is pretty self-explanatory. The right conjunct
3902 * checks whether the two pointers are equal. If they are we know that
3903 * this is not a key that is namespaced any further and so we are
3904 * supposed to clear the whole network.
3906 if (isdigit(*idxstring
) && (strrchr(key
, '.') == (idxstring
- 1))) {
3907 unsigned int rmnetdevidx
;
3909 if (lxc_safe_uint(idxstring
, &rmnetdevidx
) < 0)
3912 /* Remove network from network list. */
3913 lxc_remove_nic_by_idx(lxc_conf
, rmnetdevidx
);
3917 config
= get_network_config_ops(key
, lxc_conf
, &idx
, &deindexed_key
);
3918 if (!config
|| idx
< 0)
3921 netdev
= lxc_get_netdev_by_idx(lxc_conf
, (unsigned int)idx
, false);
3923 free(deindexed_key
);
3927 ret
= config
->clr(deindexed_key
, lxc_conf
, netdev
);
3928 free(deindexed_key
);
3932 static int clr_config_net_type(const char *key
, struct lxc_conf
*lxc_conf
,
3935 struct lxc_netdev
*netdev
;
3949 static int clr_config_net_name(const char *key
, struct lxc_conf
*lxc_conf
,
3952 struct lxc_netdev
*netdev
;
3961 netdev
->name
[0] = '\0';
3966 static int clr_config_net_flags(const char *key
, struct lxc_conf
*lxc_conf
,
3969 struct lxc_netdev
*netdev
;
3983 static int clr_config_net_link(const char *key
, struct lxc_conf
*lxc_conf
,
3986 struct lxc_netdev
*netdev
;
3995 netdev
->link
[0] = '\0';
4000 static int clr_config_net_macvlan_mode(const char *key
,
4001 struct lxc_conf
*lxc_conf
, void *data
)
4003 struct lxc_netdev
*netdev
;
4012 if (netdev
->type
!= LXC_NET_MACVLAN
)
4015 netdev
->priv
.macvlan_attr
.mode
= -1;
4020 static int clr_config_net_veth_pair(const char *key
, struct lxc_conf
*lxc_conf
,
4023 struct lxc_netdev
*netdev
;
4032 netdev
->priv
.veth_attr
.pair
[0] = '\0';
4037 static int clr_config_net_script_up(const char *key
, struct lxc_conf
*lxc_conf
,
4040 struct lxc_netdev
*netdev
;
4049 free(netdev
->upscript
);
4050 netdev
->upscript
= NULL
;
4055 static int clr_config_net_script_down(const char *key
,
4056 struct lxc_conf
*lxc_conf
, void *data
)
4058 struct lxc_netdev
*netdev
;
4067 free(netdev
->downscript
);
4068 netdev
->downscript
= NULL
;
4073 static int clr_config_net_hwaddr(const char *key
, struct lxc_conf
*lxc_conf
,
4076 struct lxc_netdev
*netdev
;
4085 free(netdev
->hwaddr
);
4086 netdev
->hwaddr
= NULL
;
4091 static int clr_config_net_mtu(const char *key
, struct lxc_conf
*lxc_conf
,
4094 struct lxc_netdev
*netdev
;
4109 static int clr_config_net_vlan_id(const char *key
, struct lxc_conf
*lxc_conf
,
4112 struct lxc_netdev
*netdev
;
4121 netdev
->priv
.vlan_attr
.vid
= 0;
4126 static int clr_config_net_ipv4_gateway(const char *key
,
4127 struct lxc_conf
*lxc_conf
, void *data
)
4129 struct lxc_netdev
*netdev
;
4138 free(netdev
->ipv4_gateway
);
4139 netdev
->ipv4_gateway
= NULL
;
4144 static int clr_config_net_ipv4_address(const char *key
,
4145 struct lxc_conf
*lxc_conf
, void *data
)
4147 struct lxc_netdev
*netdev
;
4148 struct lxc_list
*cur
, *next
;
4157 lxc_list_for_each_safe(cur
, &netdev
->ipv4
, next
) {
4166 static int clr_config_net_ipv6_gateway(const char *key
,
4167 struct lxc_conf
*lxc_conf
, void *data
)
4169 struct lxc_netdev
*netdev
;
4178 free(netdev
->ipv6_gateway
);
4179 netdev
->ipv6_gateway
= NULL
;
4184 static int clr_config_net_ipv6_address(const char *key
,
4185 struct lxc_conf
*lxc_conf
, void *data
)
4187 struct lxc_netdev
*netdev
;
4188 struct lxc_list
*cur
, *next
;
4197 lxc_list_for_each_safe(cur
, &netdev
->ipv6
, next
) {
4206 static int get_config_net_nic(const char *key
, char *retv
, int inlen
,
4207 struct lxc_conf
*c
, void *data
)
4210 const char *idxstring
;
4211 struct lxc_config_t
*config
;
4212 struct lxc_netdev
*netdev
;
4214 char *deindexed_key
= NULL
;
4216 idxstring
= key
+ 8;
4217 if (!isdigit(*idxstring
))
4220 config
= get_network_config_ops(key
, c
, &idx
, &deindexed_key
);
4221 if (!config
|| idx
< 0)
4224 netdev
= lxc_get_netdev_by_idx(c
, (unsigned int)idx
, false);
4226 free(deindexed_key
);
4230 ret
= config
->get(deindexed_key
, retv
, inlen
, c
, netdev
);
4231 free(deindexed_key
);
4235 static int get_config_net_type(const char *key
, char *retv
, int inlen
,
4236 struct lxc_conf
*c
, void *data
)
4238 int len
, fulllen
= 0;
4239 struct lxc_netdev
*netdev
;
4244 memset(retv
, 0, inlen
);
4253 strprint(retv
, inlen
, "%s", lxc_net_type_to_str(netdev
->type
));
4258 static int get_config_net_flags(const char *key
, char *retv
, int inlen
,
4259 struct lxc_conf
*c
, void *data
)
4261 int len
, fulllen
= 0;
4262 struct lxc_netdev
*netdev
;
4267 memset(retv
, 0, inlen
);
4276 if (netdev
->flags
& IFF_UP
)
4277 strprint(retv
, inlen
, "up");
4282 static int get_config_net_link(const char *key
, char *retv
, int inlen
,
4283 struct lxc_conf
*c
, void *data
)
4285 int len
, fulllen
= 0;
4286 struct lxc_netdev
*netdev
;
4291 memset(retv
, 0, inlen
);
4300 if (netdev
->link
[0] != '\0')
4301 strprint(retv
, inlen
, "%s", netdev
->link
);
4306 static int get_config_net_name(const char *key
, char *retv
, int inlen
,
4307 struct lxc_conf
*c
, void *data
)
4309 int len
, fulllen
= 0;
4310 struct lxc_netdev
*netdev
;
4315 memset(retv
, 0, inlen
);
4324 if (netdev
->name
[0] != '\0')
4325 strprint(retv
, inlen
, "%s", netdev
->name
);
4330 static int get_config_net_macvlan_mode(const char *key
, char *retv
, int inlen
,
4331 struct lxc_conf
*c
, void *data
)
4334 int len
, fulllen
= 0;
4335 struct lxc_netdev
*netdev
;
4340 memset(retv
, 0, inlen
);
4349 if (netdev
->type
!= LXC_NET_MACVLAN
)
4352 switch (netdev
->priv
.macvlan_attr
.mode
) {
4353 case MACVLAN_MODE_PRIVATE
:
4356 case MACVLAN_MODE_VEPA
:
4359 case MACVLAN_MODE_BRIDGE
:
4362 case MACVLAN_MODE_PASSTHRU
:
4370 strprint(retv
, inlen
, "%s", mode
);
4375 static int get_config_net_veth_pair(const char *key
, char *retv
, int inlen
,
4376 struct lxc_conf
*c
, void *data
)
4378 int len
, fulllen
= 0;
4379 struct lxc_netdev
*netdev
;
4384 memset(retv
, 0, inlen
);
4393 if (netdev
->type
!= LXC_NET_VETH
)
4396 strprint(retv
, inlen
, "%s",
4397 netdev
->priv
.veth_attr
.pair
[0] != '\0'
4398 ? netdev
->priv
.veth_attr
.pair
4399 : netdev
->priv
.veth_attr
.veth1
);
4404 static int get_config_net_script_up(const char *key
, char *retv
, int inlen
,
4405 struct lxc_conf
*c
, void *data
)
4407 int len
, fulllen
= 0;
4408 struct lxc_netdev
*netdev
;
4413 memset(retv
, 0, inlen
);
4422 if (netdev
->upscript
)
4423 strprint(retv
, inlen
, "%s", netdev
->upscript
);
4428 static int get_config_net_script_down(const char *key
, char *retv
, int inlen
,
4429 struct lxc_conf
*c
, void *data
)
4431 int len
, fulllen
= 0;
4432 struct lxc_netdev
*netdev
;
4437 memset(retv
, 0, inlen
);
4446 if (netdev
->downscript
)
4447 strprint(retv
, inlen
, "%s", netdev
->downscript
);
4452 static int get_config_net_hwaddr(const char *key
, char *retv
, int inlen
,
4453 struct lxc_conf
*c
, void *data
)
4455 int len
, fulllen
= 0;
4456 struct lxc_netdev
*netdev
;
4461 memset(retv
, 0, inlen
);
4471 strprint(retv
, inlen
, "%s", netdev
->hwaddr
);
4476 static int get_config_net_mtu(const char *key
, char *retv
, int inlen
,
4477 struct lxc_conf
*c
, void *data
)
4479 int len
, fulllen
= 0;
4480 struct lxc_netdev
*netdev
;
4485 memset(retv
, 0, inlen
);
4495 strprint(retv
, inlen
, "%s", netdev
->mtu
);
4500 static int get_config_net_vlan_id(const char *key
, char *retv
, int inlen
,
4501 struct lxc_conf
*c
, void *data
)
4503 int len
, fulllen
= 0;
4504 struct lxc_netdev
*netdev
;
4509 memset(retv
, 0, inlen
);
4518 if (netdev
->type
!= LXC_NET_VLAN
)
4521 strprint(retv
, inlen
, "%d", netdev
->priv
.vlan_attr
.vid
);
4526 static int get_config_net_ipv4_gateway(const char *key
, char *retv
, int inlen
,
4527 struct lxc_conf
*c
, void *data
)
4529 int len
, fulllen
= 0;
4530 char buf
[INET_ADDRSTRLEN
];
4531 struct lxc_netdev
*netdev
;
4536 memset(retv
, 0, inlen
);
4545 if (netdev
->ipv4_gateway_auto
) {
4546 strprint(retv
, inlen
, "auto");
4547 } else if (netdev
->ipv4_gateway
) {
4548 inet_ntop(AF_INET
, netdev
->ipv4_gateway
, buf
, sizeof(buf
));
4549 strprint(retv
, inlen
, "%s", buf
);
4555 static int get_config_net_ipv4_address(const char *key
, char *retv
, int inlen
,
4556 struct lxc_conf
*c
, void *data
)
4558 int len
, fulllen
= 0;
4560 char buf
[INET_ADDRSTRLEN
];
4561 struct lxc_netdev
*netdev
;
4562 struct lxc_list
*it
;
4567 memset(retv
, 0, inlen
);
4576 listlen
= lxc_list_len(&netdev
->ipv4
);
4577 lxc_list_for_each(it
, &netdev
->ipv4
) {
4578 struct lxc_inetdev
*i
= it
->elem
;
4579 inet_ntop(AF_INET
, &i
->addr
, buf
, sizeof(buf
));
4580 strprint(retv
, inlen
, "%s/%u%s", buf
, i
->prefix
,
4581 (listlen
-- > 1) ? "\n" : "");
4587 static int get_config_net_ipv6_gateway(const char *key
, char *retv
, int inlen
,
4588 struct lxc_conf
*c
, void *data
)
4590 int len
, fulllen
= 0;
4591 char buf
[INET6_ADDRSTRLEN
];
4592 struct lxc_netdev
*netdev
;
4597 memset(retv
, 0, inlen
);
4606 if (netdev
->ipv6_gateway_auto
) {
4607 strprint(retv
, inlen
, "auto");
4608 } else if (netdev
->ipv6_gateway
) {
4609 inet_ntop(AF_INET6
, netdev
->ipv6_gateway
, buf
, sizeof(buf
));
4610 strprint(retv
, inlen
, "%s", buf
);
4616 static int get_config_net_ipv6_address(const char *key
, char *retv
, int inlen
,
4617 struct lxc_conf
*c
, void *data
)
4619 int len
, fulllen
= 0;
4621 char buf
[INET6_ADDRSTRLEN
];
4622 struct lxc_netdev
*netdev
;
4623 struct lxc_list
*it
;
4628 memset(retv
, 0, inlen
);
4637 listlen
= lxc_list_len(&netdev
->ipv6
);
4638 lxc_list_for_each(it
, &netdev
->ipv6
) {
4639 struct lxc_inet6dev
*i
= it
->elem
;
4640 inet_ntop(AF_INET6
, &i
->addr
, buf
, sizeof(buf
));
4641 strprint(retv
, inlen
, "%s/%u%s", buf
, i
->prefix
,
4642 (listlen
-- > 1) ? "\n" : "");
4648 int lxc_list_config_items(char *retv
, int inlen
)
4657 memset(retv
, 0, inlen
);
4659 for (i
= 0; i
< config_size
; i
++) {
4660 char *s
= config
[i
].name
;
4662 if (s
[strlen(s
) - 1] == '.')
4665 strprint(retv
, inlen
, "%s\n", s
);
4671 int lxc_list_subkeys(struct lxc_conf
*conf
, const char *key
, char *retv
,
4680 memset(retv
, 0, inlen
);
4682 if (!strcmp(key
, "lxc.apparmor")) {
4683 strprint(retv
, inlen
, "allow_incomplete\n");
4684 strprint(retv
, inlen
, "profile\n");
4685 } else if (!strcmp(key
, "lxc.cgroup")) {
4686 strprint(retv
, inlen
, "dir\n");
4687 } else if (!strcmp(key
, "lxc.selinux")) {
4688 strprint(retv
, inlen
, "context\n");
4689 } else if (!strcmp(key
, "lxc.mount")) {
4690 strprint(retv
, inlen
, "auto\n");
4691 strprint(retv
, inlen
, "entry\n");
4692 strprint(retv
, inlen
, "fstab\n");
4693 } else if (!strcmp(key
, "lxc.rootfs")) {
4694 strprint(retv
, inlen
, "mount\n");
4695 strprint(retv
, inlen
, "options\n");
4696 strprint(retv
, inlen
, "path\n");
4697 } else if (!strcmp(key
, "lxc.uts")) {
4698 strprint(retv
, inlen
, "name\n");
4699 } else if (!strcmp(key
, "lxc.hook")) {
4700 strprint(retv
, inlen
, "autodev\n");
4701 strprint(retv
, inlen
, "clone\n");
4702 strprint(retv
, inlen
, "destroy\n");
4703 strprint(retv
, inlen
, "mount\n");
4704 strprint(retv
, inlen
, "post-stop\n");
4705 strprint(retv
, inlen
, "pre-mount\n");
4706 strprint(retv
, inlen
, "pre-start\n");
4707 strprint(retv
, inlen
, "start-host\n");
4708 strprint(retv
, inlen
, "start\n");
4709 strprint(retv
, inlen
, "stop\n");
4710 } else if (!strcmp(key
, "lxc.cap")) {
4711 strprint(retv
, inlen
, "drop\n");
4712 strprint(retv
, inlen
, "keep\n");
4713 } else if (!strcmp(key
, "lxc.console")) {
4714 strprint(retv
, inlen
, "logfile\n");
4715 strprint(retv
, inlen
, "path\n");
4716 } else if (!strcmp(key
, "lxc.seccomp")) {
4717 strprint(retv
, inlen
, "profile\n");
4718 } else if (!strcmp(key
, "lxc.signal")) {
4719 strprint(retv
, inlen
, "halt\n");
4720 strprint(retv
, inlen
, "reboot\n");
4721 strprint(retv
, inlen
, "stop\n");
4722 } else if (!strcmp(key
, "lxc.start")) {
4723 strprint(retv
, inlen
, "auto\n");
4724 strprint(retv
, inlen
, "delay\n");
4725 strprint(retv
, inlen
, "order\n");
4726 } else if (!strcmp(key
, "lxc.monitor")) {
4727 strprint(retv
, inlen
, "unshare\n");
4735 int lxc_list_net(struct lxc_conf
*c
, const char *key
, char *retv
, int inlen
)
4738 const char *idxstring
;
4739 struct lxc_netdev
*netdev
;
4743 idxstring
= key
+ 8;
4744 if (!isdigit(*idxstring
))
4747 (void)get_network_config_ops(key
, c
, &idx
, NULL
);
4751 netdev
= lxc_get_netdev_by_idx(c
, (unsigned int)idx
, false);
4758 memset(retv
, 0, inlen
);
4760 strprint(retv
, inlen
, "type\n");
4761 strprint(retv
, inlen
, "script.up\n");
4762 strprint(retv
, inlen
, "script.down\n");
4763 if (netdev
->type
!= LXC_NET_EMPTY
) {
4764 strprint(retv
, inlen
, "flags\n");
4765 strprint(retv
, inlen
, "link\n");
4766 strprint(retv
, inlen
, "name\n");
4767 strprint(retv
, inlen
, "hwaddr\n");
4768 strprint(retv
, inlen
, "mtu\n");
4769 strprint(retv
, inlen
, "ipv6.address\n");
4770 strprint(retv
, inlen
, "ipv6.gateway\n");
4771 strprint(retv
, inlen
, "ipv4.address\n");
4772 strprint(retv
, inlen
, "ipv4.gateway\n");
4775 switch (netdev
->type
) {
4777 strprint(retv
, inlen
, "veth.pair\n");
4779 case LXC_NET_MACVLAN
:
4780 strprint(retv
, inlen
, "macvlan.mode\n");
4783 strprint(retv
, inlen
, "vlan.id\n");