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_gid
);
99 lxc_config_define(init_uid
);
100 lxc_config_define(log_file
);
101 lxc_config_define(log_level
);
102 lxc_config_define(log_syslog
);
103 lxc_config_define(monitor
);
104 lxc_config_define(mount
);
105 lxc_config_define(mount_auto
);
106 lxc_config_define(mount_fstab
);
107 lxc_config_define(namespace);
108 lxc_config_define(net
);
109 lxc_config_define(net_flags
);
110 lxc_config_define(net_hwaddr
);
111 lxc_config_define(net_ipv4_address
);
112 lxc_config_define(net_ipv4_gateway
);
113 lxc_config_define(net_ipv6_address
);
114 lxc_config_define(net_ipv6_gateway
);
115 lxc_config_define(net_link
);
116 lxc_config_define(net_macvlan_mode
);
117 lxc_config_define(net_mtu
);
118 lxc_config_define(net_name
);
119 lxc_config_define(net_nic
);
120 lxc_config_define(net_script_down
);
121 lxc_config_define(net_script_up
);
122 lxc_config_define(net_type
);
123 lxc_config_define(net_veth_pair
);
124 lxc_config_define(net_vlan_id
);
125 lxc_config_define(no_new_privs
);
126 lxc_config_define(noop
);
127 lxc_config_define(personality
);
128 lxc_config_define(prlimit
);
129 lxc_config_define(pty_max
);
130 lxc_config_define(rootfs_backend
);
131 lxc_config_define(rootfs_mount
);
132 lxc_config_define(rootfs_options
);
133 lxc_config_define(rootfs_path
);
134 lxc_config_define(seccomp_profile
);
135 lxc_config_define(selinux_context
);
136 lxc_config_define(signal_halt
);
137 lxc_config_define(signal_reboot
);
138 lxc_config_define(signal_stop
);
139 lxc_config_define(start
);
140 lxc_config_define(tty_max
);
141 lxc_config_define(tty_dir
);
142 lxc_config_define(uts_name
);
144 static struct lxc_config_t config
[] = {
145 /* REMOVE in LXC 3.0 */
146 { "lxc.arch", false, set_config_personality
, get_config_personality
, clr_config_personality
, },
147 { "lxc.apparmor.profile", false, set_config_apparmor_profile
, get_config_apparmor_profile
, clr_config_apparmor_profile
, },
148 { "lxc.apparmor.allow_incomplete", false, set_config_apparmor_allow_incomplete
, get_config_apparmor_allow_incomplete
, clr_config_apparmor_allow_incomplete
, },
149 { "lxc.autodev", false, set_config_autodev
, get_config_autodev
, clr_config_autodev
, },
150 { "lxc.cap.drop", false, set_config_cap_drop
, get_config_cap_drop
, clr_config_cap_drop
, },
151 { "lxc.cap.keep", false, set_config_cap_keep
, get_config_cap_keep
, clr_config_cap_keep
, },
152 { "lxc.cgroup.dir", false, set_config_cgroup_dir
, get_config_cgroup_dir
, clr_config_cgroup_dir
, },
153 { "lxc.cgroup", false, set_config_cgroup_controller
, get_config_cgroup_controller
, clr_config_cgroup_controller
, },
154 { "lxc.console.buffer.logfile", false, set_config_console_buffer_logfile
, get_config_console_buffer_logfile
, clr_config_console_buffer_logfile
, },
155 { "lxc.console.buffer.size", false, set_config_console_buffer_size
, get_config_console_buffer_size
, clr_config_console_buffer_size
, },
156 { "lxc.console.logfile", false, set_config_console_logfile
, get_config_console_logfile
, clr_config_console_logfile
, },
157 { "lxc.console.path", false, set_config_console_path
, get_config_console_path
, clr_config_console_path
, },
158 { "lxc.console.rotate", false, set_config_console_rotate
, get_config_console_rotate
, clr_config_console_rotate
, },
159 { "lxc.environment", false, set_config_environment
, get_config_environment
, clr_config_environment
, },
160 { "lxc.ephemeral", false, set_config_ephemeral
, get_config_ephemeral
, clr_config_ephemeral
, },
161 { "lxc.execute.cmd", false, set_config_execute_cmd
, get_config_execute_cmd
, clr_config_execute_cmd
, },
162 { "lxc.group", false, set_config_group
, get_config_group
, clr_config_group
, },
163 { "lxc.hook.autodev", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
164 { "lxc.hook.clone", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
165 { "lxc.hook.destroy", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
166 { "lxc.hook.mount", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
167 { "lxc.hook.post-stop", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
168 { "lxc.hook.start-host", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
169 { "lxc.hook.pre-start", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
170 { "lxc.hook.pre-mount", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
171 { "lxc.hook.start", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
172 { "lxc.hook.stop", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
173 { "lxc.hook", false, set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
174 { "lxc.idmap", false, set_config_idmaps
, get_config_idmaps
, clr_config_idmaps
, },
175 { "lxc.include", false, set_config_includefiles
, get_config_includefiles
, clr_config_includefiles
, },
176 { "lxc.init.cmd", false, set_config_init_cmd
, get_config_init_cmd
, clr_config_init_cmd
, },
177 { "lxc.init.gid", false, set_config_init_gid
, get_config_init_gid
, clr_config_init_gid
, },
178 { "lxc.init.uid", false, set_config_init_uid
, get_config_init_uid
, clr_config_init_uid
, },
179 { "lxc.log.file", false, set_config_log_file
, get_config_log_file
, clr_config_log_file
, },
180 { "lxc.log.level", false, set_config_log_level
, get_config_log_level
, clr_config_log_level
, },
181 { "lxc.log.syslog", false, set_config_log_syslog
, get_config_log_syslog
, clr_config_log_syslog
, },
182 { "lxc.monitor.unshare", false, set_config_monitor
, get_config_monitor
, clr_config_monitor
, },
183 { "lxc.mount.auto", false, set_config_mount_auto
, get_config_mount_auto
, clr_config_mount_auto
, },
184 { "lxc.mount.entry", false, set_config_mount
, get_config_mount
, clr_config_mount
, },
185 { "lxc.mount.fstab", false, set_config_mount_fstab
, get_config_mount_fstab
, clr_config_mount_fstab
, },
186 { "lxc.namespace", false, set_config_namespace
, get_config_namespace
, clr_config_namespace
, },
188 /* [START]: REMOVE IN LXC 3.0 */
189 { "lxc.network.type", true, set_config_network_legacy_type
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
190 { "lxc.network.flags", true, set_config_network_legacy_flags
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
191 { "lxc.network.link", true, set_config_network_legacy_link
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
192 { "lxc.network.name", true, set_config_network_legacy_name
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
193 { "lxc.network.macvlan.mode", true, set_config_network_legacy_macvlan_mode
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
194 { "lxc.network.veth.pair", true, set_config_network_legacy_veth_pair
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
195 { "lxc.network.script.up", true, set_config_network_legacy_script_up
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
196 { "lxc.network.script.down", true, set_config_network_legacy_script_down
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
197 { "lxc.network.hwaddr", true, set_config_network_legacy_hwaddr
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
198 { "lxc.network.mtu", true, set_config_network_legacy_mtu
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
199 { "lxc.network.vlan.id", true, set_config_network_legacy_vlan_id
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
200 { "lxc.network.ipv4.gateway", true, set_config_network_legacy_ipv4_gateway
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
201 { "lxc.network.ipv4", true, set_config_network_legacy_ipv4
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
202 { "lxc.network.ipv6.gateway", true, set_config_network_legacy_ipv6_gateway
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
203 { "lxc.network.ipv6", true, set_config_network_legacy_ipv6
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
204 { "lxc.network.", true, set_config_network_legacy_nic
, get_config_network_legacy_item
, clr_config_network_legacy_item
, },
205 { "lxc.network", true, set_config_network_legacy
, get_config_network_legacy
, clr_config_network_legacy
, },
206 /* [END]: REMOVE IN LXC 3.0 */
208 { "lxc.net.flags", false, set_config_net_flags
, get_config_net_flags
, clr_config_net_flags
, },
209 { "lxc.net.hwaddr", false, set_config_net_hwaddr
, get_config_net_hwaddr
, clr_config_net_hwaddr
, },
210 { "lxc.net.ipv4.address", false, set_config_net_ipv4_address
, get_config_net_ipv4_address
, clr_config_net_ipv4_address
, },
211 { "lxc.net.ipv4.gateway", false, set_config_net_ipv4_gateway
, get_config_net_ipv4_gateway
, clr_config_net_ipv4_gateway
, },
212 { "lxc.net.ipv6.address", false, set_config_net_ipv6_address
, get_config_net_ipv6_address
, clr_config_net_ipv6_address
, },
213 { "lxc.net.ipv6.gateway", false, set_config_net_ipv6_gateway
, get_config_net_ipv6_gateway
, clr_config_net_ipv6_gateway
, },
214 { "lxc.net.link", false, set_config_net_link
, get_config_net_link
, clr_config_net_link
, },
215 { "lxc.net.macvlan.mode", false, set_config_net_macvlan_mode
, get_config_net_macvlan_mode
, clr_config_net_macvlan_mode
, },
216 { "lxc.net.mtu", false, set_config_net_mtu
, get_config_net_mtu
, clr_config_net_mtu
, },
217 { "lxc.net.name", false, set_config_net_name
, get_config_net_name
, clr_config_net_name
, },
218 { "lxc.net.script.down", false, set_config_net_script_down
, get_config_net_script_down
, clr_config_net_script_down
, },
219 { "lxc.net.script.up", false, set_config_net_script_up
, get_config_net_script_up
, clr_config_net_script_up
, },
220 { "lxc.net.type", false, set_config_net_type
, get_config_net_type
, clr_config_net_type
, },
221 { "lxc.net.vlan.id", false, set_config_net_vlan_id
, get_config_net_vlan_id
, clr_config_net_vlan_id
, },
222 { "lxc.net.veth.pair", false, set_config_net_veth_pair
, get_config_net_veth_pair
, clr_config_net_veth_pair
, },
223 { "lxc.net.", false, set_config_net_nic
, get_config_net_nic
, clr_config_net_nic
, },
224 { "lxc.net", false, set_config_net
, get_config_net
, clr_config_net
, },
225 { "lxc.no_new_privs", false, set_config_no_new_privs
, get_config_no_new_privs
, clr_config_no_new_privs
, },
226 { "lxc.prlimit", false, set_config_prlimit
, get_config_prlimit
, clr_config_prlimit
, },
227 { "lxc.pty.max", false, set_config_pty_max
, get_config_pty_max
, clr_config_pty_max
, },
228 { "lxc.rootfs.mount", false, set_config_rootfs_mount
, get_config_rootfs_mount
, clr_config_rootfs_mount
, },
229 { "lxc.rootfs.options", false, set_config_rootfs_options
, get_config_rootfs_options
, clr_config_rootfs_options
, },
230 { "lxc.rootfs.path", false, set_config_rootfs_path
, get_config_rootfs_path
, clr_config_rootfs_path
, },
231 { "lxc.seccomp.profile", false, set_config_seccomp_profile
, get_config_seccomp_profile
, clr_config_seccomp_profile
, },
232 { "lxc.selinux.context", false, set_config_selinux_context
, get_config_selinux_context
, clr_config_selinux_context
, },
233 { "lxc.signal.halt", false, set_config_signal_halt
, get_config_signal_halt
, clr_config_signal_halt
, },
234 { "lxc.signal.reboot", false, set_config_signal_reboot
, get_config_signal_reboot
, clr_config_signal_reboot
, },
235 { "lxc.signal.stop", false, set_config_signal_stop
, get_config_signal_stop
, clr_config_signal_stop
, },
236 { "lxc.start.auto", false, set_config_start
, get_config_start
, clr_config_start
, },
237 { "lxc.start.delay", false, set_config_start
, get_config_start
, clr_config_start
, },
238 { "lxc.start.order", false, set_config_start
, get_config_start
, clr_config_start
, },
239 { "lxc.tty.dir", false, set_config_tty_dir
, get_config_tty_dir
, clr_config_tty_dir
, },
240 { "lxc.tty.max", false, set_config_tty_max
, get_config_tty_max
, clr_config_tty_max
, },
241 { "lxc.uts.name", false, set_config_uts_name
, get_config_uts_name
, clr_config_uts_name
, },
243 /* [START]: REMOVE IN LXC 3.0 */
244 { "lxc.pts", true, set_config_pty_max
, get_config_pty_max
, clr_config_pty_max
, },
245 { "lxc.devttydir", true, set_config_tty_dir
, get_config_tty_dir
, clr_config_tty_dir
, },
246 { "lxc.tty", true, set_config_tty_max
, get_config_tty_max
, clr_config_tty_max
, },
247 { "lxc.aa_profile", true, set_config_lsm_aa_profile
, get_config_lsm_aa_profile
, clr_config_lsm_aa_profile
, },
248 { "lxc.aa_allow_incomplete", true, set_config_lsm_aa_incomplete
, get_config_lsm_aa_incomplete
, clr_config_lsm_aa_incomplete
, },
249 { "lxc.se_context", true, set_config_lsm_se_context
, get_config_lsm_se_context
, clr_config_lsm_se_context
, },
250 { "lxc.id_map", true, set_config_idmaps
, get_config_idmaps
, clr_config_idmaps
, },
251 { "lxc.mount", true, set_config_mount_fstab
, get_config_mount_fstab
, clr_config_mount_fstab
, },
252 { "lxc.rootfs.backend", true, set_config_rootfs_backend
, get_config_rootfs_backend
, clr_config_rootfs_backend
, },
253 { "lxc.rootfs", true, set_config_rootfs_path
, get_config_rootfs_path
, clr_config_rootfs_path
, },
254 { "lxc.utsname", true, set_config_uts_name
, get_config_uts_name
, clr_config_uts_name
, },
255 { "lxc.seccomp", true, set_config_seccomp_profile
, get_config_seccomp_profile
, clr_config_seccomp_profile
, },
256 { "lxc.console", true, set_config_console_path
, get_config_console_path
, clr_config_console_path
, },
257 { "lxc.haltsignal", true, set_config_signal_halt
, get_config_signal_halt
, clr_config_signal_halt
, },
258 { "lxc.rebootsignal", true, set_config_signal_reboot
, get_config_signal_reboot
, clr_config_signal_reboot
, },
259 { "lxc.stopsignal", true, set_config_signal_stop
, get_config_signal_stop
, clr_config_signal_stop
, },
260 { "lxc.syslog", true, set_config_log_syslog
, get_config_log_syslog
, clr_config_log_syslog
, },
261 { "lxc.kmsg", true, set_config_noop
, get_config_noop
, clr_config_noop
, },
262 { "lxc.loglevel", true, set_config_log_level
, get_config_log_level
, clr_config_log_level
, },
263 { "lxc.logfile", true, set_config_log_file
, get_config_log_file
, clr_config_log_file
, },
264 { "lxc.init_cmd", true, set_config_init_cmd
, get_config_init_cmd
, clr_config_init_cmd
, },
265 { "lxc.init_uid", true, set_config_init_uid
, get_config_init_uid
, clr_config_init_uid
, },
266 { "lxc.init_gid", true, set_config_init_gid
, get_config_init_gid
, clr_config_init_gid
, },
267 { "lxc.limit", true, set_config_limit
, get_config_limit
, clr_config_limit
, },
268 { "lxc.pivotdir", true, set_config_noop
, get_config_noop
, clr_config_noop
, },
269 /* [END]: REMOVE IN LXC 3.0 */
277 static const struct signame signames
[] = {
310 { SIGSTKFLT
, "STKFLT" },
325 { SIGVTALRM
, "VTALRM" },
331 { SIGWINCH
, "WINCH" },
349 { SIGUNUSED
, "UNUSED" },
356 static const size_t config_size
= sizeof(config
) / sizeof(struct lxc_config_t
);
358 struct lxc_config_t
*lxc_get_config(const char *key
)
362 for (i
= 0; i
< config_size
; i
++)
363 if (!strncmp(config
[i
].name
, key
, strlen(config
[i
].name
)))
369 static int set_config_net(const char *key
, const char *value
,
370 struct lxc_conf
*lxc_conf
, void *data
)
372 if (!lxc_config_value_empty(value
)) {
373 ERROR("lxc.net must not have a value");
377 return clr_config_net(key
, lxc_conf
, data
);
380 static int set_config_net_type(const char *key
, const char *value
,
381 struct lxc_conf
*lxc_conf
, void *data
)
383 struct lxc_netdev
*netdev
;
385 if (lxc_config_value_empty(value
))
386 return clr_config_net_type(key
, lxc_conf
, data
);
395 if (!strcmp(value
, "veth")) {
396 netdev
->type
= LXC_NET_VETH
;
397 } else if (!strcmp(value
, "macvlan")) {
398 netdev
->type
= LXC_NET_MACVLAN
;
399 lxc_macvlan_mode_to_flag(&netdev
->priv
.macvlan_attr
.mode
,
401 } else if (!strcmp(value
, "vlan")) {
402 netdev
->type
= LXC_NET_VLAN
;
403 } else if (!strcmp(value
, "phys")) {
404 netdev
->type
= LXC_NET_PHYS
;
405 } else if (!strcmp(value
, "empty")) {
406 netdev
->type
= LXC_NET_EMPTY
;
407 } else if (!strcmp(value
, "none")) {
408 netdev
->type
= LXC_NET_NONE
;
410 ERROR("invalid network type %s", value
);
417 static int set_config_net_flags(const char *key
, const char *value
,
418 struct lxc_conf
*lxc_conf
, void *data
)
420 struct lxc_netdev
*netdev
;
422 if (lxc_config_value_empty(value
))
423 return clr_config_net_flags(key
, lxc_conf
, data
);
432 netdev
->flags
|= IFF_UP
;
437 static int create_matched_ifnames(const char *value
, struct lxc_conf
*lxc_conf
,
438 struct lxc_netdev
*netdev
)
440 struct ifaddrs
*ifaddr
, *ifa
;
443 const char *type_key
= "lxc.net.type";
444 const char *link_key
= "lxc.net.link";
445 const char *tmpvalue
= "phys";
447 if (getifaddrs(&ifaddr
) == -1) {
448 SYSERROR("Get network interfaces failed");
452 for (ifa
= ifaddr
, n
= 0; ifa
!= NULL
; ifa
= ifa
->ifa_next
, n
++) {
455 if (ifa
->ifa_addr
->sa_family
!= AF_PACKET
)
458 if (!strncmp(value
, ifa
->ifa_name
, strlen(value
) - 1)) {
459 ret
= set_config_net_type(type_key
, tmpvalue
, lxc_conf
,
462 ret
= set_config_net_link(
463 link_key
, ifa
->ifa_name
, lxc_conf
, netdev
);
465 ERROR("failed to create matched ifnames");
469 ERROR("failed to create matched ifnames");
481 static int set_config_net_link(const char *key
, const char *value
,
482 struct lxc_conf
*lxc_conf
, void *data
)
484 struct lxc_netdev
*netdev
;
487 if (lxc_config_value_empty(value
))
488 return clr_config_net_link(key
, lxc_conf
, data
);
497 if (value
[strlen(value
) - 1] == '+' && netdev
->type
== LXC_NET_PHYS
)
498 ret
= create_matched_ifnames(value
, lxc_conf
, netdev
);
500 ret
= network_ifname(netdev
->link
, value
);
505 static int set_config_net_name(const char *key
, const char *value
,
506 struct lxc_conf
*lxc_conf
, void *data
)
508 struct lxc_netdev
*netdev
;
510 if (lxc_config_value_empty(value
))
511 return clr_config_net_name(key
, lxc_conf
, data
);
520 return network_ifname(netdev
->name
, value
);
523 static int set_config_net_veth_pair(const char *key
, const char *value
,
524 struct lxc_conf
*lxc_conf
, void *data
)
526 struct lxc_netdev
*netdev
;
528 if (lxc_config_value_empty(value
))
529 return clr_config_net_veth_pair(key
, lxc_conf
, data
);
538 return network_ifname(netdev
->priv
.veth_attr
.pair
, value
);
541 static int set_config_net_macvlan_mode(const char *key
, const char *value
,
542 struct lxc_conf
*lxc_conf
, void *data
)
544 struct lxc_netdev
*netdev
;
546 if (lxc_config_value_empty(value
))
547 return clr_config_net_macvlan_mode(key
, lxc_conf
, data
);
556 return lxc_macvlan_mode_to_flag(&netdev
->priv
.macvlan_attr
.mode
, value
);
559 static int set_config_net_hwaddr(const char *key
, const char *value
,
560 struct lxc_conf
*lxc_conf
, void *data
)
562 struct lxc_netdev
*netdev
;
565 if (lxc_config_value_empty(value
))
566 return clr_config_net_hwaddr(key
, lxc_conf
, data
);
575 new_value
= strdup(value
);
579 rand_complete_hwaddr(new_value
);
581 if (lxc_config_value_empty(new_value
)) {
583 netdev
->hwaddr
= NULL
;
587 netdev
->hwaddr
= new_value
;
591 static int set_config_net_vlan_id(const char *key
, const char *value
,
592 struct lxc_conf
*lxc_conf
, void *data
)
595 struct lxc_netdev
*netdev
;
597 if (lxc_config_value_empty(value
))
598 return clr_config_net_vlan_id(key
, lxc_conf
, data
);
607 ret
= get_u16(&netdev
->priv
.vlan_attr
.vid
, value
, 0);
614 static int set_config_net_mtu(const char *key
, const char *value
,
615 struct lxc_conf
*lxc_conf
, void *data
)
617 struct lxc_netdev
*netdev
;
619 if (lxc_config_value_empty(value
))
620 return clr_config_net_mtu(key
, lxc_conf
, data
);
629 return set_config_string_item(&netdev
->mtu
, value
);
632 static int set_config_net_ipv4_address(const char *key
, const char *value
,
633 struct lxc_conf
*lxc_conf
, void *data
)
636 struct lxc_netdev
*netdev
;
637 struct lxc_inetdev
*inetdev
;
638 struct lxc_list
*list
;
639 char *cursor
, *slash
;
640 char *addr
= NULL
, *bcast
= NULL
, *prefix
= NULL
;
642 if (lxc_config_value_empty(value
))
643 return clr_config_net_ipv4_address(key
, lxc_conf
, data
);
652 inetdev
= malloc(sizeof(*inetdev
));
656 memset(inetdev
, 0, sizeof(*inetdev
));
658 list
= malloc(sizeof(*list
));
665 list
->elem
= inetdev
;
667 addr
= strdup(value
);
674 cursor
= strstr(addr
, " ");
680 slash
= strstr(addr
, "/");
686 ret
= inet_pton(AF_INET
, addr
, &inetdev
->addr
);
687 if (!ret
|| ret
< 0) {
688 SYSERROR("Invalid ipv4 address \"%s\"", value
);
696 ret
= inet_pton(AF_INET
, bcast
, &inetdev
->bcast
);
697 if (!ret
|| ret
< 0) {
698 SYSERROR("Invalid ipv4 broadcast address \"%s\"", value
);
707 /* No prefix specified, determine it from the network class. */
709 ret
= lxc_safe_uint(prefix
, &inetdev
->prefix
);
713 inetdev
->prefix
= config_ip_prefix(&inetdev
->addr
);
716 /* If no broadcast address, let compute one from the
717 * prefix and address.
720 inetdev
->bcast
.s_addr
= inetdev
->addr
.s_addr
;
721 inetdev
->bcast
.s_addr
|= htonl(INADDR_BROADCAST
>> inetdev
->prefix
);
724 lxc_list_add_tail(&netdev
->ipv4
, list
);
730 static int set_config_net_ipv4_gateway(const char *key
, const char *value
,
731 struct lxc_conf
*lxc_conf
, void *data
)
733 struct lxc_netdev
*netdev
;
735 if (lxc_config_value_empty(value
))
736 return clr_config_net_ipv4_gateway(key
, lxc_conf
, data
);
745 free(netdev
->ipv4_gateway
);
747 if (!strcmp(value
, "auto")) {
748 netdev
->ipv4_gateway
= NULL
;
749 netdev
->ipv4_gateway_auto
= true;
754 gw
= malloc(sizeof(*gw
));
758 ret
= inet_pton(AF_INET
, value
, gw
);
759 if (!ret
|| ret
< 0) {
760 SYSERROR("Invalid ipv4 gateway address \"%s\"", value
);
765 netdev
->ipv4_gateway
= gw
;
766 netdev
->ipv4_gateway_auto
= false;
772 static int set_config_net_ipv6_address(const char *key
, const char *value
,
773 struct lxc_conf
*lxc_conf
, void *data
)
776 struct lxc_netdev
*netdev
;
777 struct lxc_inet6dev
*inet6dev
;
778 struct lxc_list
*list
;
779 char *slash
, *valdup
, *netmask
;
781 if (lxc_config_value_empty(value
))
782 return clr_config_net_ipv6_address(key
, lxc_conf
, data
);
791 inet6dev
= malloc(sizeof(*inet6dev
));
795 memset(inet6dev
, 0, sizeof(*inet6dev
));
797 list
= malloc(sizeof(*list
));
804 list
->elem
= inet6dev
;
806 valdup
= strdup(value
);
813 inet6dev
->prefix
= 64;
814 slash
= strstr(valdup
, "/");
818 if (lxc_safe_uint(netmask
, &inet6dev
->prefix
) < 0)
822 ret
= inet_pton(AF_INET6
, valdup
, &inet6dev
->addr
);
823 if (!ret
|| ret
< 0) {
824 SYSERROR("Invalid ipv6 address \"%s\"", valdup
);
831 lxc_list_add_tail(&netdev
->ipv6
, list
);
837 static int set_config_net_ipv6_gateway(const char *key
, const char *value
,
838 struct lxc_conf
*lxc_conf
, void *data
)
840 struct lxc_netdev
*netdev
;
842 if (lxc_config_value_empty(value
))
843 return clr_config_net_ipv6_gateway(key
, lxc_conf
, data
);
852 free(netdev
->ipv6_gateway
);
854 if (!strcmp(value
, "auto")) {
855 netdev
->ipv6_gateway
= NULL
;
856 netdev
->ipv6_gateway_auto
= true;
861 gw
= malloc(sizeof(*gw
));
865 ret
= inet_pton(AF_INET6
, value
, gw
);
866 if (!ret
|| ret
< 0) {
867 SYSERROR("Invalid ipv6 gateway address \"%s\"", value
);
872 netdev
->ipv6_gateway
= gw
;
873 netdev
->ipv6_gateway_auto
= false;
879 static int set_config_net_script_up(const char *key
, const char *value
,
880 struct lxc_conf
*lxc_conf
, void *data
)
882 struct lxc_netdev
*netdev
;
884 if (lxc_config_value_empty(value
))
885 return clr_config_net_script_up(key
, lxc_conf
, data
);
894 return set_config_string_item(&netdev
->upscript
, value
);
897 static int set_config_net_script_down(const char *key
, const char *value
,
898 struct lxc_conf
*lxc_conf
, void *data
)
900 struct lxc_netdev
*netdev
;
902 if (lxc_config_value_empty(value
))
903 return clr_config_net_script_down(key
, lxc_conf
, data
);
912 return set_config_string_item(&netdev
->downscript
, value
);
915 static int add_hook(struct lxc_conf
*lxc_conf
, int which
, char *hook
)
917 struct lxc_list
*hooklist
;
919 hooklist
= malloc(sizeof(*hooklist
));
925 hooklist
->elem
= hook
;
926 lxc_list_add_tail(&lxc_conf
->hooks
[which
], hooklist
);
930 static int set_config_seccomp_profile(const char *key
, const char *value
,
931 struct lxc_conf
*lxc_conf
, void *data
)
933 return set_config_path_item(&lxc_conf
->seccomp
, value
);
936 static int set_config_execute_cmd(const char *key
, const char *value
,
937 struct lxc_conf
*lxc_conf
, void *data
)
939 return set_config_path_item(&lxc_conf
->execute_cmd
, value
);
942 static int set_config_init_cmd(const char *key
, const char *value
,
943 struct lxc_conf
*lxc_conf
, void *data
)
945 return set_config_path_item(&lxc_conf
->init_cmd
, value
);
948 static int set_config_init_uid(const char *key
, const char *value
,
949 struct lxc_conf
*lxc_conf
, void *data
)
951 unsigned int init_uid
;
953 if (lxc_config_value_empty(value
)) {
954 lxc_conf
->init_uid
= 0;
958 if (lxc_safe_uint(value
, &init_uid
) < 0)
961 lxc_conf
->init_uid
= init_uid
;
966 static int set_config_init_gid(const char *key
, const char *value
,
967 struct lxc_conf
*lxc_conf
, void *data
)
969 unsigned int init_gid
;
971 if (lxc_config_value_empty(value
)) {
972 lxc_conf
->init_gid
= 0;
976 if (lxc_safe_uint(value
, &init_gid
) < 0)
979 lxc_conf
->init_gid
= init_gid
;
984 static int set_config_hooks(const char *key
, const char *value
,
985 struct lxc_conf
*lxc_conf
, void *data
)
989 if (lxc_config_value_empty(value
))
990 return lxc_clear_hooks(lxc_conf
, key
);
992 if (strcmp(key
+ 4, "hook") == 0) {
993 ERROR("lxc.hook must not have a value");
997 copy
= strdup(value
);
1001 if (strcmp(key
+ 9, "pre-start") == 0)
1002 return add_hook(lxc_conf
, LXCHOOK_PRESTART
, copy
);
1003 else if (strcmp(key
+ 9, "start-host") == 0)
1004 return add_hook(lxc_conf
, LXCHOOK_START_HOST
, copy
);
1005 else if (strcmp(key
+ 9, "pre-mount") == 0)
1006 return add_hook(lxc_conf
, LXCHOOK_PREMOUNT
, copy
);
1007 else if (strcmp(key
+ 9, "autodev") == 0)
1008 return add_hook(lxc_conf
, LXCHOOK_AUTODEV
, copy
);
1009 else if (strcmp(key
+ 9, "mount") == 0)
1010 return add_hook(lxc_conf
, LXCHOOK_MOUNT
, copy
);
1011 else if (strcmp(key
+ 9, "start") == 0)
1012 return add_hook(lxc_conf
, LXCHOOK_START
, copy
);
1013 else if (strcmp(key
+ 9, "stop") == 0)
1014 return add_hook(lxc_conf
, LXCHOOK_STOP
, copy
);
1015 else if (strcmp(key
+ 9, "post-stop") == 0)
1016 return add_hook(lxc_conf
, LXCHOOK_POSTSTOP
, copy
);
1017 else if (strcmp(key
+ 9, "clone") == 0)
1018 return add_hook(lxc_conf
, LXCHOOK_CLONE
, copy
);
1019 else if (strcmp(key
+ 9, "destroy") == 0)
1020 return add_hook(lxc_conf
, LXCHOOK_DESTROY
, copy
);
1026 static int set_config_personality(const char *key
, const char *value
,
1027 struct lxc_conf
*lxc_conf
, void *data
)
1029 signed long personality
= lxc_config_parse_arch(value
);
1031 if (personality
>= 0)
1032 lxc_conf
->personality
= personality
;
1034 WARN("Unsupported personality \"%s\"", value
);
1039 static int set_config_pty_max(const char *key
, const char *value
,
1040 struct lxc_conf
*lxc_conf
, void *data
)
1042 if (lxc_config_value_empty(value
)) {
1047 if (lxc_safe_uint(value
, &lxc_conf
->pts
) < 0)
1053 /* We only need to check whether the first byte of the key after the lxc.start.
1054 * prefix matches our expectations since they fortunately all start with a
1055 * different letter. If anything was wrong with the key we would have already
1056 * noticed when the callback was called.
1058 static int set_config_start(const char *key
, const char *value
,
1059 struct lxc_conf
*lxc_conf
, void *data
)
1063 is_empty
= lxc_config_value_empty(value
);
1065 if (*(key
+ 10) == 'a') { /* lxc.start.auto */
1067 lxc_conf
->start_auto
= 0;
1071 if (lxc_safe_uint(value
, &lxc_conf
->start_auto
) < 0)
1074 if (lxc_conf
->start_auto
> 1)
1078 } else if (*(key
+ 10) == 'd') { /* lxc.start.delay */
1080 lxc_conf
->start_delay
= 0;
1084 return lxc_safe_uint(value
, &lxc_conf
->start_delay
);
1085 } else if (*(key
+ 10) == 'o') { /* lxc.start.order */
1087 lxc_conf
->start_order
= 0;
1091 return lxc_safe_int(value
, &lxc_conf
->start_order
);
1097 static int set_config_monitor(const char *key
, const char *value
,
1098 struct lxc_conf
*lxc_conf
, void *data
)
1100 if (lxc_config_value_empty(value
)) {
1101 lxc_conf
->monitor_unshare
= 0;
1105 if (strcmp(key
+ 12, "unshare") == 0)
1106 return lxc_safe_uint(value
, &lxc_conf
->monitor_unshare
);
1111 static int set_config_group(const char *key
, const char *value
,
1112 struct lxc_conf
*lxc_conf
, void *data
)
1114 char *groups
, *groupptr
, *sptr
, *token
;
1115 struct lxc_list
*grouplist
;
1118 if (lxc_config_value_empty(value
))
1119 return lxc_clear_groups(lxc_conf
);
1121 groups
= strdup(value
);
1125 /* In case several groups are specified in a single line split these
1126 * groups in a single element for the list.
1128 for (groupptr
= groups
;; groupptr
= NULL
) {
1129 token
= strtok_r(groupptr
, " \t", &sptr
);
1135 grouplist
= malloc(sizeof(*grouplist
));
1139 grouplist
->elem
= strdup(token
);
1140 if (!grouplist
->elem
) {
1145 lxc_list_add_tail(&lxc_conf
->groups
, grouplist
);
1152 static int set_config_environment(const char *key
, const char *value
,
1153 struct lxc_conf
*lxc_conf
, void *data
)
1155 struct lxc_list
*list_item
= NULL
;
1157 if (lxc_config_value_empty(value
))
1158 return lxc_clear_environment(lxc_conf
);
1160 list_item
= malloc(sizeof(*list_item
));
1164 list_item
->elem
= strdup(value
);
1166 if (!list_item
->elem
)
1169 lxc_list_add_tail(&lxc_conf
->environment
, list_item
);
1178 static int set_config_tty_max(const char *key
, const char *value
,
1179 struct lxc_conf
*lxc_conf
, void *data
)
1181 if (lxc_config_value_empty(value
)) {
1186 return lxc_safe_uint(value
, &lxc_conf
->tty
);
1189 static int set_config_tty_dir(const char *key
, const char *value
,
1190 struct lxc_conf
*lxc_conf
, void *data
)
1192 return set_config_string_item_max(&lxc_conf
->ttydir
, value
,
1196 static int set_config_apparmor_profile(const char *key
, const char *value
,
1197 struct lxc_conf
*lxc_conf
, void *data
)
1199 return set_config_string_item(&lxc_conf
->lsm_aa_profile
, value
);
1202 static int set_config_apparmor_allow_incomplete(const char *key
,
1204 struct lxc_conf
*lxc_conf
,
1207 if (lxc_config_value_empty(value
)) {
1208 lxc_conf
->lsm_aa_allow_incomplete
= 0;
1212 if (lxc_safe_uint(value
, &lxc_conf
->lsm_aa_allow_incomplete
) < 0)
1215 if (lxc_conf
->lsm_aa_allow_incomplete
> 1)
1221 static int set_config_selinux_context(const char *key
, const char *value
,
1222 struct lxc_conf
*lxc_conf
, void *data
)
1224 return set_config_string_item(&lxc_conf
->lsm_se_context
, value
);
1227 static int set_config_log_file(const char *key
, const char *value
,
1228 struct lxc_conf
*c
, void *data
)
1232 if (lxc_config_value_empty(value
)) {
1238 /* Store these values in the lxc_conf, and then try to set for actual
1241 ret
= set_config_path_item(&c
->logfile
, value
);
1243 ret
= lxc_log_set_file(&c
->logfd
, c
->logfile
);
1248 static int set_config_log_level(const char *key
, const char *value
,
1249 struct lxc_conf
*lxc_conf
, void *data
)
1253 if (lxc_config_value_empty(value
)) {
1254 lxc_conf
->loglevel
= LXC_LOG_LEVEL_NOTSET
;
1258 if (value
[0] >= '0' && value
[0] <= '9') {
1259 if (lxc_safe_int(value
, &newlevel
) < 0)
1262 newlevel
= lxc_log_priority_to_int(value
);
1265 /* Store these values in the lxc_conf, and then try to set for actual
1268 lxc_conf
->loglevel
= newlevel
;
1269 return lxc_log_set_level(&lxc_conf
->loglevel
, newlevel
);
1272 static int set_config_autodev(const char *key
, const char *value
,
1273 struct lxc_conf
*lxc_conf
, void *data
)
1275 if (lxc_config_value_empty(value
)) {
1276 lxc_conf
->autodev
= 0;
1280 if (lxc_safe_uint(value
, &lxc_conf
->autodev
) < 0)
1283 if (lxc_conf
->autodev
> 1)
1289 static int sig_num(const char *sig
)
1291 unsigned int signum
;
1293 if (lxc_safe_uint(sig
, &signum
) < 0)
1299 static int rt_sig_num(const char *signame
)
1301 int rtmax
= 0, sig_n
= 0;
1303 if (strncasecmp(signame
, "max-", 4) == 0) {
1308 if (!isdigit(*signame
))
1311 sig_n
= sig_num(signame
);
1312 sig_n
= rtmax
? SIGRTMAX
- sig_n
: SIGRTMIN
+ sig_n
;
1313 if (sig_n
> SIGRTMAX
|| sig_n
< SIGRTMIN
)
1319 static int sig_parse(const char *signame
)
1323 if (isdigit(*signame
)) {
1324 return sig_num(signame
);
1325 } else if (strncasecmp(signame
, "sig", 3) == 0) {
1327 if (strncasecmp(signame
, "rt", 2) == 0)
1328 return rt_sig_num(signame
+ 2);
1329 for (n
= 0; n
< sizeof(signames
) / sizeof((signames
)[0]); n
++) {
1330 if (strcasecmp(signames
[n
].name
, signame
) == 0)
1331 return signames
[n
].num
;
1338 static int set_config_signal_halt(const char *key
, const char *value
,
1339 struct lxc_conf
*lxc_conf
, void *data
)
1343 if (lxc_config_value_empty(value
)) {
1344 lxc_conf
->haltsignal
= 0;
1348 sig_n
= sig_parse(value
);
1352 lxc_conf
->haltsignal
= sig_n
;
1357 static int set_config_signal_reboot(const char *key
, const char *value
,
1358 struct lxc_conf
*lxc_conf
, void *data
)
1362 if (lxc_config_value_empty(value
)) {
1363 lxc_conf
->rebootsignal
= 0;
1367 sig_n
= sig_parse(value
);
1371 lxc_conf
->rebootsignal
= sig_n
;
1376 static int set_config_signal_stop(const char *key
, const char *value
,
1377 struct lxc_conf
*lxc_conf
, void *data
)
1381 if (lxc_config_value_empty(value
)) {
1382 lxc_conf
->stopsignal
= 0;
1386 sig_n
= sig_parse(value
);
1390 lxc_conf
->stopsignal
= sig_n
;
1395 static int set_config_cgroup_controller(const char *key
, const char *value
,
1396 struct lxc_conf
*lxc_conf
, void *data
)
1399 char *token
= "lxc.cgroup.";
1400 struct lxc_list
*cglist
= NULL
;
1401 struct lxc_cgroup
*cgelem
= NULL
;
1403 if (lxc_config_value_empty(value
))
1404 return lxc_clear_cgroups(lxc_conf
, key
);
1406 subkey
= strstr(key
, token
);
1410 if (!strlen(subkey
))
1413 if (strlen(subkey
) == strlen(token
))
1416 subkey
+= strlen(token
);
1418 cglist
= malloc(sizeof(*cglist
));
1422 cgelem
= malloc(sizeof(*cgelem
));
1425 memset(cgelem
, 0, sizeof(*cgelem
));
1427 cgelem
->subsystem
= strdup(subkey
);
1428 cgelem
->value
= strdup(value
);
1430 if (!cgelem
->subsystem
|| !cgelem
->value
)
1433 cglist
->elem
= cgelem
;
1435 lxc_list_add_tail(&lxc_conf
->cgroup
, cglist
);
1442 free(cgelem
->subsystem
);
1443 free(cgelem
->value
);
1450 static int set_config_cgroup_dir(const char *key
, const char *value
,
1451 struct lxc_conf
*lxc_conf
, void *data
)
1453 if (lxc_config_value_empty(value
))
1454 return clr_config_cgroup_dir(key
, lxc_conf
, NULL
);
1456 return set_config_string_item(&lxc_conf
->cgroup_meta
.dir
, value
);
1459 static int set_config_prlimit(const char *key
, const char *value
,
1460 struct lxc_conf
*lxc_conf
, void *data
)
1462 struct lxc_list
*iter
;
1463 struct rlimit limit
;
1465 struct lxc_list
*limlist
= NULL
;
1466 struct lxc_limit
*limelem
= NULL
;
1468 if (lxc_config_value_empty(value
))
1469 return lxc_clear_limits(lxc_conf
, key
);
1471 if (strncmp(key
, "lxc.prlimit.", sizeof("lxc.prlimit.") - 1) != 0)
1474 key
+= sizeof("lxc.prlimit.") - 1;
1476 /* soft limit comes first in the value */
1477 if (!parse_limit_value(&value
, &limit_value
))
1479 limit
.rlim_cur
= limit_value
;
1481 /* skip spaces and a colon */
1482 while (isspace(*value
))
1487 else if (*value
) /* any other character is an error here */
1490 while (isspace(*value
))
1493 /* optional hard limit */
1495 if (!parse_limit_value(&value
, &limit_value
))
1497 limit
.rlim_max
= limit_value
;
1499 /* check for trailing garbage */
1500 while (isspace(*value
))
1506 /* a single value sets both hard and soft limit */
1507 limit
.rlim_max
= limit
.rlim_cur
;
1510 /* find existing list element */
1511 lxc_list_for_each(iter
, &lxc_conf
->limits
)
1513 limelem
= iter
->elem
;
1514 if (!strcmp(key
, limelem
->resource
)) {
1515 limelem
->limit
= limit
;
1520 /* allocate list element */
1521 limlist
= malloc(sizeof(*limlist
));
1525 limelem
= malloc(sizeof(*limelem
));
1528 memset(limelem
, 0, sizeof(*limelem
));
1530 limelem
->resource
= strdup(key
);
1531 if (!limelem
->resource
)
1533 limelem
->limit
= limit
;
1535 limlist
->elem
= limelem
;
1537 lxc_list_add_tail(&lxc_conf
->limits
, limlist
);
1544 free(limelem
->resource
);
1550 static int set_config_idmaps(const char *key
, const char *value
,
1551 struct lxc_conf
*lxc_conf
, void *data
)
1553 unsigned long hostid
, nsid
, range
;
1556 struct lxc_list
*idmaplist
= NULL
;
1557 struct id_map
*idmap
= NULL
;
1559 if (lxc_config_value_empty(value
))
1560 return lxc_clear_idmaps(lxc_conf
);
1562 idmaplist
= malloc(sizeof(*idmaplist
));
1566 idmap
= malloc(sizeof(*idmap
));
1569 memset(idmap
, 0, sizeof(*idmap
));
1571 ret
= parse_idmaps(value
, &type
, &nsid
, &hostid
, &range
);
1575 INFO("Read uid map: type %c nsid %lu hostid %lu range %lu", type
, nsid
, hostid
, range
);
1577 idmap
->idtype
= ID_TYPE_UID
;
1578 else if (type
== 'g')
1579 idmap
->idtype
= ID_TYPE_GID
;
1583 idmap
->hostid
= hostid
;
1585 idmap
->range
= range
;
1586 idmaplist
->elem
= idmap
;
1587 lxc_list_add_tail(&lxc_conf
->id_map
, idmaplist
);
1599 static int set_config_mount_fstab(const char *key
, const char *value
,
1600 struct lxc_conf
*lxc_conf
, void *data
)
1602 if (lxc_config_value_empty(value
)) {
1603 clr_config_mount_fstab(key
, lxc_conf
, NULL
);
1607 return set_config_path_item(&lxc_conf
->fstab
, value
);
1610 static int set_config_mount_auto(const char *key
, const char *value
,
1611 struct lxc_conf
*lxc_conf
, void *data
)
1613 char *autos
, *autoptr
, *sptr
, *token
;
1620 } allowed_auto_mounts
[] = {
1621 { "proc", LXC_AUTO_PROC_MASK
, LXC_AUTO_PROC_MIXED
},
1622 { "proc:mixed", LXC_AUTO_PROC_MASK
, LXC_AUTO_PROC_MIXED
},
1623 { "proc:rw", LXC_AUTO_PROC_MASK
, LXC_AUTO_PROC_RW
},
1624 { "sys", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_MIXED
},
1625 { "sys:ro", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_RO
},
1626 { "sys:mixed", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_MIXED
},
1627 { "sys:rw", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_RW
},
1628 { "cgroup", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_NOSPEC
},
1629 { "cgroup:mixed", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_MIXED
},
1630 { "cgroup:ro", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_RO
},
1631 { "cgroup:rw", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_RW
},
1632 { "cgroup-full", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_NOSPEC
},
1633 { "cgroup-full:mixed", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_MIXED
},
1634 { "cgroup-full:ro", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_RO
},
1635 { "cgroup-full:rw", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_RW
},
1636 /* For adding anything that is just a single on/off, but has no
1637 * options: keep mask and flag identical and just define the enum
1638 * value as an unused bit so far
1643 if (lxc_config_value_empty(value
)) {
1644 lxc_conf
->auto_mounts
= 0;
1648 autos
= strdup(value
);
1652 for (autoptr
= autos
;; autoptr
= NULL
) {
1653 token
= strtok_r(autoptr
, " \t", &sptr
);
1659 for (i
= 0; allowed_auto_mounts
[i
].token
; i
++) {
1660 if (!strcmp(allowed_auto_mounts
[i
].token
, token
))
1664 if (!allowed_auto_mounts
[i
].token
) {
1665 ERROR("Invalid filesystem to automount \"%s\"", token
);
1669 lxc_conf
->auto_mounts
&= ~allowed_auto_mounts
[i
].mask
;
1670 lxc_conf
->auto_mounts
|= allowed_auto_mounts
[i
].flag
;
1677 static int set_config_mount(const char *key
, const char *value
,
1678 struct lxc_conf
*lxc_conf
, void *data
)
1681 struct lxc_list
*mntlist
;
1683 if (lxc_config_value_empty(value
))
1684 return lxc_clear_mount_entries(lxc_conf
);
1686 mntlist
= malloc(sizeof(*mntlist
));
1690 mntelem
= strdup(value
);
1695 mntlist
->elem
= mntelem
;
1697 lxc_list_add_tail(&lxc_conf
->mount_list
, mntlist
);
1702 static int set_config_cap_keep(const char *key
, const char *value
,
1703 struct lxc_conf
*lxc_conf
, void *data
)
1705 char *keepcaps
, *keepptr
, *sptr
, *token
;
1706 struct lxc_list
*keeplist
;
1709 if (lxc_config_value_empty(value
))
1710 return lxc_clear_config_keepcaps(lxc_conf
);
1712 keepcaps
= strdup(value
);
1716 /* In case several capability keep is specified in a single line
1717 * split these caps in a single element for the list.
1719 for (keepptr
= keepcaps
;; keepptr
= NULL
) {
1720 token
= strtok_r(keepptr
, " \t", &sptr
);
1726 if (!strcmp(token
, "none"))
1727 lxc_clear_config_keepcaps(lxc_conf
);
1729 keeplist
= malloc(sizeof(*keeplist
));
1733 keeplist
->elem
= strdup(token
);
1734 if (!keeplist
->elem
) {
1739 lxc_list_add_tail(&lxc_conf
->keepcaps
, keeplist
);
1747 static int set_config_cap_drop(const char *key
, const char *value
,
1748 struct lxc_conf
*lxc_conf
, void *data
)
1750 char *dropcaps
, *dropptr
, *sptr
, *token
;
1751 struct lxc_list
*droplist
;
1754 if (lxc_config_value_empty(value
))
1755 return lxc_clear_config_caps(lxc_conf
);
1757 dropcaps
= strdup(value
);
1761 /* In case several capability drop is specified in a single line
1762 * split these caps in a single element for the list.
1764 for (dropptr
= dropcaps
;; dropptr
= NULL
) {
1765 token
= strtok_r(dropptr
, " \t", &sptr
);
1771 droplist
= malloc(sizeof(*droplist
));
1775 droplist
->elem
= strdup(token
);
1776 if (!droplist
->elem
) {
1781 lxc_list_add_tail(&lxc_conf
->caps
, droplist
);
1789 static int set_config_console_path(const char *key
, const char *value
,
1790 struct lxc_conf
*lxc_conf
, void *data
)
1792 return set_config_path_item(&lxc_conf
->console
.path
, value
);
1795 static int set_config_console_rotate(const char *key
, const char *value
,
1796 struct lxc_conf
*lxc_conf
, void *data
)
1798 if (lxc_config_value_empty(value
)) {
1799 lxc_conf
->console
.log_rotate
= 0;
1803 if (lxc_safe_uint(value
, &lxc_conf
->console
.log_rotate
) < 0)
1806 if (lxc_conf
->console
.log_rotate
> 1) {
1807 ERROR("The \"lxc.console.rotate\" config key can only be set "
1815 static int set_config_console_logfile(const char *key
, const char *value
,
1816 struct lxc_conf
*lxc_conf
, void *data
)
1818 return set_config_path_item(&lxc_conf
->console
.log_path
, value
);
1821 static int set_config_console_buffer_size(const char *key
, const char *value
,
1822 struct lxc_conf
*lxc_conf
, void *data
)
1826 uint64_t buffer_size
, pgsz
;
1828 if (lxc_config_value_empty(value
)) {
1829 lxc_conf
->console
.buffer_size
= 0;
1833 /* If the user specified "auto" the default log size is 2^17 = 128 Kib */
1834 if (!strcmp(value
, "auto")) {
1835 lxc_conf
->console
.buffer_size
= 1 << 17;
1839 ret
= parse_byte_size_string(value
, &size
);
1846 /* must be at least a page size */
1847 pgsz
= lxc_getpagesize();
1848 if ((uint64_t)size
< pgsz
) {
1849 NOTICE("Requested ringbuffer size for the console is %" PRId64
1850 " but must be at least %" PRId64
1851 " bytes. Setting ringbuffer size to %" PRId64
" bytes",
1856 buffer_size
= lxc_find_next_power2((uint64_t)size
);
1857 if (buffer_size
== 0)
1860 if (buffer_size
!= size
)
1861 NOTICE("Passed size was not a power of 2. Rounding log size to "
1862 "next power of two: %" PRIu64
" bytes", buffer_size
);
1864 lxc_conf
->console
.buffer_size
= buffer_size
;
1868 static int set_config_console_buffer_logfile(const char *key
, const char *value
,
1869 struct lxc_conf
*lxc_conf
,
1872 return set_config_path_item(&lxc_conf
->console
.buffer_log_file
, value
);
1875 int append_unexp_config_line(const char *line
, struct lxc_conf
*conf
)
1877 size_t len
= conf
->unexpanded_len
, linelen
= strlen(line
);
1879 update_hwaddr(line
);
1881 while (conf
->unexpanded_alloced
<= len
+ linelen
+ 2) {
1882 char *tmp
= realloc(conf
->unexpanded_config
,
1883 conf
->unexpanded_alloced
+ 1024);
1887 if (!conf
->unexpanded_config
)
1889 conf
->unexpanded_config
= tmp
;
1890 conf
->unexpanded_alloced
+= 1024;
1892 strcat(conf
->unexpanded_config
, line
);
1893 conf
->unexpanded_len
+= linelen
;
1894 if (line
[linelen
- 1] != '\n') {
1895 strcat(conf
->unexpanded_config
, "\n");
1896 conf
->unexpanded_len
++;
1902 static int do_includedir(const char *dirp
, struct lxc_conf
*lxc_conf
)
1904 struct dirent
*direntp
;
1906 char path
[MAXPATHLEN
];
1910 dir
= opendir(dirp
);
1914 while ((direntp
= readdir(dir
))) {
1919 fnam
= direntp
->d_name
;
1920 if (!strcmp(fnam
, "."))
1923 if (!strcmp(fnam
, ".."))
1927 if (len
< 6 || strncmp(fnam
+ len
- 5, ".conf", 5) != 0)
1930 len
= snprintf(path
, MAXPATHLEN
, "%s/%s", dirp
, fnam
);
1931 if (len
< 0 || len
>= MAXPATHLEN
) {
1936 ret
= lxc_config_read(path
, lxc_conf
, true);
1948 static int set_config_includefiles(const char *key
, const char *value
,
1949 struct lxc_conf
*lxc_conf
, void *data
)
1951 if (lxc_config_value_empty(value
)) {
1952 clr_config_includefiles(key
, lxc_conf
, NULL
);
1957 return do_includedir(value
, lxc_conf
);
1959 return lxc_config_read(value
, lxc_conf
, true);
1962 static int set_config_rootfs_path(const char *key
, const char *value
,
1963 struct lxc_conf
*lxc_conf
, void *data
)
1965 return set_config_path_item(&lxc_conf
->rootfs
.path
, value
);
1968 static int set_config_rootfs_mount(const char *key
, const char *value
,
1969 struct lxc_conf
*lxc_conf
, void *data
)
1971 return set_config_path_item(&lxc_conf
->rootfs
.mount
, value
);
1974 static int set_config_rootfs_options(const char *key
, const char *value
,
1975 struct lxc_conf
*lxc_conf
, void *data
)
1977 return set_config_string_item(&lxc_conf
->rootfs
.options
, value
);
1980 static int set_config_rootfs_backend(const char *key
, const char *value
,
1981 struct lxc_conf
*lxc_conf
, void *data
)
1986 static int set_config_uts_name(const char *key
, const char *value
,
1987 struct lxc_conf
*lxc_conf
, void *data
)
1989 struct utsname
*utsname
;
1991 if (lxc_config_value_empty(value
)) {
1992 clr_config_uts_name(key
, lxc_conf
, NULL
);
1996 utsname
= malloc(sizeof(*utsname
));
2000 if (strlen(value
) >= sizeof(utsname
->nodename
)) {
2005 strcpy(utsname
->nodename
, value
);
2006 free(lxc_conf
->utsname
);
2007 lxc_conf
->utsname
= utsname
;
2012 static int set_config_namespace(const char *key
, const char *value
,
2013 struct lxc_conf
*lxc_conf
, void *data
)
2016 const char *namespace;
2018 if (lxc_config_value_empty(value
))
2019 return clr_config_namespace(key
, lxc_conf
, data
);
2021 namespace = key
+ sizeof("lxc.namespace.") - 1;
2022 ns_idx
= lxc_namespace_2_ns_idx(namespace);
2026 return set_config_string_item(&lxc_conf
->inherit_ns
[ns_idx
], value
);
2029 struct parse_line_conf
{
2030 struct lxc_conf
*conf
;
2034 static int parse_line(char *buffer
, void *data
)
2036 char *dot
, *key
, *line
, *linep
, *value
;
2038 struct lxc_config_t
*config
;
2041 struct parse_line_conf
*plc
= data
;
2043 /* If there are newlines in the config file we should keep them. */
2044 empty_line
= lxc_is_line_empty(dup
);
2048 /* We have to dup the buffer otherwise, at the re-exec for reboot we
2049 * modified the original string on the stack by replacing '=' by '\0'
2052 linep
= line
= strdup(dup
);
2056 if (!plc
->from_include
) {
2057 ret
= append_unexp_config_line(line
, plc
->conf
);
2065 line
+= lxc_char_left_gc(line
, strlen(line
));
2067 /* ignore comments */
2071 /* martian option - don't add it to the config itself */
2072 if (strncmp(line
, "lxc.", 4))
2077 dot
= strchr(line
, '=');
2079 ERROR("Invalid configuration line: %s", line
);
2087 key
[lxc_char_right_gc(key
, strlen(key
))] = '\0';
2089 value
+= lxc_char_left_gc(value
, strlen(value
));
2090 value
[lxc_char_right_gc(value
, strlen(value
))] = '\0';
2092 if (*value
== '\'' || *value
== '\"') {
2095 len
= strlen(value
);
2096 if (len
> 1 && value
[len
- 1] == *value
) {
2097 value
[len
- 1] = '\0';
2102 config
= lxc_get_config(key
);
2104 ERROR("Unknown configuration key \"%s\"", key
);
2108 /* [START]: REMOVE IN LXC 3.0 */
2109 if (config
->is_legacy_key
&& !plc
->conf
->contains_legacy_key
) {
2110 plc
->conf
->contains_legacy_key
= true;
2111 if (getenv("LXC_UPDATE_CONFIG_FORMAT")) {
2112 /* Warn the user once loud and clear that there is at
2113 * least one legacy configuration item in the
2114 * configuration file and then an update is required.
2116 fprintf(stderr
, "The configuration file contains "
2117 "legacy configuration keys.\nPlease "
2118 "update your configuration file!\nThe "
2119 "update script lxc-update-config -c "
2120 "<path-to-config> can be used for "
2124 /* [END]: REMOVE IN LXC 3.0 */
2126 ret
= config
->set(key
, value
, plc
->conf
, NULL
);
2133 static int lxc_config_readline(char *buffer
, struct lxc_conf
*conf
)
2135 struct parse_line_conf c
;
2138 c
.from_include
= false;
2140 return parse_line(buffer
, &c
);
2143 int lxc_config_read(const char *file
, struct lxc_conf
*conf
, bool from_include
)
2146 struct parse_line_conf c
;
2149 c
.from_include
= from_include
;
2151 ret
= access(file
, R_OK
);
2155 /* Catch only the top level config file name in the structure. */
2157 conf
->rcfile
= strdup(file
);
2159 return lxc_file_for_each_line(file
, parse_line
, &c
);
2162 int lxc_config_define_add(struct lxc_list
*defines
, char *arg
)
2164 struct lxc_list
*dent
;
2166 dent
= malloc(sizeof(struct lxc_list
));
2171 lxc_list_add_tail(defines
, dent
);
2175 int lxc_config_define_load(struct lxc_list
*defines
, struct lxc_conf
*conf
)
2177 struct lxc_list
*it
, *next
;
2180 lxc_list_for_each(it
, defines
) {
2181 ret
= lxc_config_readline(it
->elem
, conf
);
2186 lxc_list_for_each_safe(it
, defines
, next
) {
2194 signed long lxc_config_parse_arch(const char *arch
)
2196 #if HAVE_SYS_PERSONALITY_H
2202 { "x86", PER_LINUX32
},
2203 { "linux32", PER_LINUX32
},
2204 { "i386", PER_LINUX32
},
2205 { "i486", PER_LINUX32
},
2206 { "i586", PER_LINUX32
},
2207 { "i686", PER_LINUX32
},
2208 { "athlon", PER_LINUX32
},
2209 { "mips", PER_LINUX32
},
2210 { "mipsel", PER_LINUX32
},
2211 { "ppc", PER_LINUX32
},
2212 { "arm", PER_LINUX32
},
2213 { "armv7l", PER_LINUX32
},
2214 { "armhf", PER_LINUX32
},
2215 { "armel", PER_LINUX32
},
2216 { "powerpc", PER_LINUX32
},
2217 { "linux64", PER_LINUX
},
2218 { "x86_64", PER_LINUX
},
2219 { "amd64", PER_LINUX
},
2220 { "mips64", PER_LINUX
},
2221 { "mips64el", PER_LINUX
},
2222 { "ppc64", PER_LINUX
},
2223 { "ppc64le", PER_LINUX
},
2224 { "ppc64el", PER_LINUX
},
2225 { "powerpc64", PER_LINUX
},
2226 { "s390x", PER_LINUX
},
2227 { "aarch64", PER_LINUX
},
2228 { "arm64", PER_LINUX
},
2230 size_t len
= sizeof(pername
) / sizeof(pername
[0]);
2232 for (i
= 0; i
< len
; i
++) {
2233 if (!strcmp(pername
[i
].name
, arch
))
2234 return pername
[i
].per
;
2241 int lxc_fill_elevated_privileges(char *flaglist
, int *flags
)
2243 char *token
, *saveptr
= NULL
;
2249 { "CGROUP", LXC_ATTACH_MOVE_TO_CGROUP
},
2250 { "CAP", LXC_ATTACH_DROP_CAPABILITIES
},
2251 { "LSM", LXC_ATTACH_LSM_EXEC
},
2256 /* For the sake of backward compatibility, drop all privileges
2257 * if none is specified.
2259 for (i
= 0; all_privs
[i
].token
; i
++)
2260 *flags
|= all_privs
[i
].flag
;
2265 token
= strtok_r(flaglist
, "|", &saveptr
);
2268 for (i
= 0; all_privs
[i
].token
; i
++)
2269 if (!strcmp(all_privs
[i
].token
, token
))
2270 aflag
= all_privs
[i
].flag
;
2276 token
= strtok_r(NULL
, "|", &saveptr
);
2282 /* Write out a configuration file. */
2283 void write_config(FILE *fout
, struct lxc_conf
*c
)
2286 size_t len
= c
->unexpanded_len
;
2291 ret
= fwrite(c
->unexpanded_config
, 1, len
, fout
);
2293 SYSERROR("Failed to write configuration file");
2296 bool do_append_unexp_config_line(struct lxc_conf
*conf
, const char *key
,
2303 len
= strlen(key
) + strlen(v
) + 4;
2306 if (lxc_config_value_empty(v
))
2307 ret
= snprintf(tmp
, len
, "%s =", key
);
2309 ret
= snprintf(tmp
, len
, "%s = %s", key
, v
);
2310 if (ret
< 0 || ret
>= len
)
2313 /* Save the line verbatim into unexpanded_conf */
2314 if (append_unexp_config_line(tmp
, conf
))
2320 void clear_unexp_config_line(struct lxc_conf
*conf
, const char *key
,
2324 char *lstart
= conf
->unexpanded_config
;
2326 if (!conf
->unexpanded_config
)
2330 lend
= strchr(lstart
, '\n');
2333 lend
= lstart
+ strlen(lstart
);
2336 if (strncmp(lstart
, key
, strlen(key
)) != 0) {
2341 v
= lstart
[strlen(key
)];
2342 if (!isspace(v
) && v
!= '=') {
2347 conf
->unexpanded_len
-= (lend
- lstart
);
2348 if (*lend
== '\0') {
2352 memmove(lstart
, lend
, strlen(lend
) + 1);
2356 bool clone_update_unexp_ovl_paths(struct lxc_conf
*conf
, const char *oldpath
,
2357 const char *newpath
, const char *oldname
,
2358 const char *newname
, const char *ovldir
)
2361 char *lend
, *newdir
, *olddir
, *p
, *q
;
2362 size_t newdirlen
, olddirlen
;
2363 char *lstart
= conf
->unexpanded_config
;
2364 const char *key
= "lxc.mount.entry";
2366 olddirlen
= strlen(ovldir
) + strlen(oldpath
) + strlen(oldname
) + 2;
2367 olddir
= alloca(olddirlen
+ 1);
2368 ret
= snprintf(olddir
, olddirlen
+ 1, "%s=%s/%s", ovldir
, oldpath
,
2370 if (ret
< 0 || ret
>= olddirlen
+ 1)
2373 newdirlen
= strlen(ovldir
) + strlen(newpath
) + strlen(newname
) + 2;
2374 newdir
= alloca(newdirlen
+ 1);
2375 ret
= snprintf(newdir
, newdirlen
+ 1, "%s=%s/%s", ovldir
, newpath
,
2377 if (ret
< 0 || ret
>= newdirlen
+ 1)
2380 if (!conf
->unexpanded_config
)
2384 lend
= strchr(lstart
, '\n');
2386 lend
= lstart
+ strlen(lstart
);
2390 if (strncmp(lstart
, key
, strlen(key
)) != 0)
2393 p
= strchr(lstart
+ strlen(key
), '=');
2404 /* Whenever an lxc.mount.entry entry is found in a line we check
2405 * if the substring " overlay" or the substring " aufs" is
2406 * present before doing any further work. We check for "
2407 * overlay" and " aufs" since both substrings need to have at
2408 * least one space before them in a valid overlay
2409 * lxc.mount.entry (/A B overlay). When the space before is
2410 * missing it is very likely that these substrings are part of a
2411 * path or something else. (Checking q >= lend ensures that we
2412 * only count matches in the current line.) */
2413 if ((!(q
= strstr(p
, " overlay")) || q
>= lend
) &&
2414 (!(q
= strstr(p
, " aufs")) || q
>= lend
))
2417 if (!(q
= strstr(p
, olddir
)) || (q
>= lend
))
2420 /* replace the olddir with newdir */
2421 if (olddirlen
>= newdirlen
) {
2422 size_t diff
= olddirlen
- newdirlen
;
2423 memcpy(q
, newdir
, newdirlen
);
2424 if (olddirlen
!= newdirlen
) {
2425 memmove(q
+ newdirlen
, q
+ newdirlen
+ diff
,
2426 strlen(q
) - newdirlen
- diff
+ 1);
2428 conf
->unexpanded_len
-= diff
;
2432 size_t diff
= newdirlen
- olddirlen
;
2433 size_t oldlen
= conf
->unexpanded_len
;
2434 size_t newlen
= oldlen
+ diff
;
2435 size_t poffset
= q
- conf
->unexpanded_config
;
2437 new = realloc(conf
->unexpanded_config
, newlen
+ 1);
2441 conf
->unexpanded_len
= newlen
;
2442 conf
->unexpanded_alloced
= newlen
+ 1;
2443 new[newlen
- 1] = '\0';
2444 lend
= new + (lend
- conf
->unexpanded_config
);
2445 /* Move over the remainder to make room for the newdir.
2447 memmove(new + poffset
+ newdirlen
,
2448 new + poffset
+ olddirlen
,
2449 oldlen
- poffset
- olddirlen
+ 1);
2450 conf
->unexpanded_config
= new;
2451 memcpy(new + poffset
, newdir
, newdirlen
);
2461 bool clone_update_unexp_hooks(struct lxc_conf
*conf
, const char *oldpath
,
2462 const char *newpath
, const char *oldname
,
2463 const char *newname
)
2466 char *lend
, *newdir
, *olddir
, *p
;
2467 char *lstart
= conf
->unexpanded_config
;
2468 size_t newdirlen
, olddirlen
;
2469 const char *key
= "lxc.hook";
2471 olddirlen
= strlen(oldpath
) + strlen(oldname
) + 1;
2472 olddir
= alloca(olddirlen
+ 1);
2473 ret
= snprintf(olddir
, olddirlen
+ 1, "%s/%s", oldpath
, oldname
);
2474 if (ret
< 0 || ret
>= olddirlen
+ 1)
2477 newdirlen
= strlen(newpath
) + strlen(newname
) + 1;
2478 newdir
= alloca(newdirlen
+ 1);
2479 ret
= snprintf(newdir
, newdirlen
+ 1, "%s/%s", newpath
, newname
);
2480 if (ret
< 0 || ret
>= newdirlen
+ 1)
2483 if (!conf
->unexpanded_config
)
2487 lend
= strchr(lstart
, '\n');
2489 lend
= lstart
+ strlen(lstart
);
2493 if (strncmp(lstart
, key
, strlen(key
)) != 0)
2496 p
= strchr(lstart
+ strlen(key
), '=');
2507 if (strncmp(p
, olddir
, strlen(olddir
)) != 0)
2510 /* replace the olddir with newdir */
2511 if (olddirlen
>= newdirlen
) {
2512 size_t diff
= olddirlen
- newdirlen
;
2513 memcpy(p
, newdir
, newdirlen
);
2514 if (olddirlen
!= newdirlen
) {
2515 memmove(p
+ newdirlen
, p
+ newdirlen
+ diff
,
2516 strlen(p
) - newdirlen
- diff
+ 1);
2518 conf
->unexpanded_len
-= diff
;
2522 size_t diff
= newdirlen
- olddirlen
;
2523 size_t oldlen
= conf
->unexpanded_len
;
2524 size_t newlen
= oldlen
+ diff
;
2525 size_t poffset
= p
- conf
->unexpanded_config
;
2527 new = realloc(conf
->unexpanded_config
, newlen
+ 1);
2531 conf
->unexpanded_len
= newlen
;
2532 conf
->unexpanded_alloced
= newlen
+ 1;
2533 new[newlen
- 1] = '\0';
2534 lend
= new + (lend
- conf
->unexpanded_config
);
2535 /* Move over the remainder to make room for the newdir.
2537 memmove(new + poffset
+ newdirlen
,
2538 new + poffset
+ olddirlen
,
2539 oldlen
- poffset
- olddirlen
+ 1);
2540 conf
->unexpanded_config
= new;
2541 memcpy(new + poffset
, newdir
, newdirlen
);
2554 ERROR("Error writing to new config"); \
2559 /* This is called only from clone. We wish to update all hwaddrs in the
2560 * unexpanded config file. We can't/don't want to update any which come from
2561 * lxc.includes (there shouldn't be any).
2562 * We can't just walk the c->lxc-conf->network list because that includes netifs
2563 * from the include files. So we update the ones which we find in the unexp
2564 * config file, then find the original macaddr in the conf->network, and update
2565 * that to the same value.
2567 bool network_new_hwaddrs(struct lxc_conf
*conf
)
2569 char *lend
, *p
, *p2
;
2570 struct lxc_list
*it
;
2571 char *lstart
= conf
->unexpanded_config
;
2573 if (!conf
->unexpanded_config
)
2577 char newhwaddr
[18], oldhwaddr
[17];
2579 lend
= strchr(lstart
, '\n');
2581 lend
= lstart
+ strlen(lstart
);
2585 if (!lxc_config_net_hwaddr(lstart
)) {
2590 p
= strchr(lstart
, '=');
2603 while (*p2
&& !isblank(*p2
) && *p2
!= '\n')
2606 if ((p2
- p
) != 17) {
2607 WARN("Bad hwaddr entry");
2612 memcpy(oldhwaddr
, p
, 17);
2614 if (!new_hwaddr(newhwaddr
))
2617 memcpy(p
, newhwaddr
, 17);
2618 lxc_list_for_each(it
, &conf
->network
) {
2619 struct lxc_netdev
*n
= it
->elem
;
2621 if (n
->hwaddr
&& memcmp(oldhwaddr
, n
->hwaddr
, 17) == 0)
2622 memcpy(n
->hwaddr
, newhwaddr
, 17);
2631 static int set_config_ephemeral(const char *key
, const char *value
,
2632 struct lxc_conf
*lxc_conf
, void *data
)
2634 if (lxc_config_value_empty(value
)) {
2635 lxc_conf
->ephemeral
= 0;
2639 if (lxc_safe_uint(value
, &lxc_conf
->ephemeral
) < 0)
2642 if (lxc_conf
->ephemeral
> 1)
2648 static int set_config_log_syslog(const char *key
, const char *value
,
2649 struct lxc_conf
*lxc_conf
, void *data
)
2653 if (lxc_conf
->syslog
) {
2654 free(lxc_conf
->syslog
);
2655 lxc_conf
->syslog
= NULL
;
2658 if (lxc_config_value_empty(value
))
2661 facility
= lxc_syslog_priority_to_int(value
);
2662 if (facility
== -EINVAL
)
2665 lxc_log_syslog(facility
);
2666 return set_config_string_item(&lxc_conf
->syslog
, value
);
2669 static int set_config_no_new_privs(const char *key
, const char *value
,
2670 struct lxc_conf
*lxc_conf
, void *data
)
2674 if (lxc_config_value_empty(value
)) {
2675 lxc_conf
->no_new_privs
= false;
2679 if (lxc_safe_uint(value
, &v
) < 0)
2685 lxc_conf
->no_new_privs
= v
? true : false;
2690 static int set_config_noop(const char *key
, const char *value
,
2691 struct lxc_conf
*lxc_conf
, void *data
)
2696 /* Callbacks to get configuration items. */
2697 static int get_config_personality(const char *key
, char *retv
, int inlen
,
2698 struct lxc_conf
*c
, void *data
)
2705 memset(retv
, 0, inlen
);
2707 #if HAVE_SYS_PERSONALITY_H
2710 switch (c
->personality
) {
2712 strprint(retv
, inlen
, "i686");
2715 strprint(retv
, inlen
, "x86_64");
2725 static int get_config_pty_max(const char *key
, char *retv
, int inlen
,
2726 struct lxc_conf
*c
, void *data
)
2728 return lxc_get_conf_int(c
, retv
, inlen
, c
->pts
);
2731 static int get_config_tty_max(const char *key
, char *retv
, int inlen
,
2732 struct lxc_conf
*c
, void *data
)
2734 return lxc_get_conf_int(c
, retv
, inlen
, c
->tty
);
2737 static int get_config_tty_dir(const char *key
, char *retv
, int inlen
,
2738 struct lxc_conf
*c
, void *data
)
2740 return lxc_get_conf_str(retv
, inlen
, c
->ttydir
);
2743 static int get_config_apparmor_profile(const char *key
, char *retv
, int inlen
,
2744 struct lxc_conf
*c
, void *data
)
2746 return lxc_get_conf_str(retv
, inlen
, c
->lsm_aa_profile
);
2749 static int get_config_apparmor_allow_incomplete(const char *key
, char *retv
,
2750 int inlen
, struct lxc_conf
*c
,
2753 return lxc_get_conf_int(c
, retv
, inlen
,
2754 c
->lsm_aa_allow_incomplete
);
2757 static int get_config_selinux_context(const char *key
, char *retv
, int inlen
,
2758 struct lxc_conf
*c
, void *data
)
2760 return lxc_get_conf_str(retv
, inlen
, c
->lsm_se_context
);
2763 /* If you ask for a specific cgroup value, i.e. lxc.cgroup.devices.list, then
2764 * just the value(s) will be printed. Since there still could be more than one,
2765 * it is newline-separated.
2766 * (Maybe that's ambigous, since some values, i.e. devices.list, will already
2768 * If you ask for 'lxc.cgroup", then all cgroup entries will be printed, in
2769 * 'lxc.cgroup.subsystem.key = value' format.
2771 static int get_config_cgroup_controller(const char *key
, char *retv
, int inlen
,
2772 struct lxc_conf
*c
, void *data
)
2774 struct lxc_list
*it
;
2777 bool get_all
= false;
2782 memset(retv
, 0, inlen
);
2784 if (!strcmp(key
, "lxc.cgroup"))
2786 else if (!strncmp(key
, "lxc.cgroup.", 11))
2791 lxc_list_for_each(it
, &c
->cgroup
) {
2792 struct lxc_cgroup
*cg
= it
->elem
;
2795 strprint(retv
, inlen
, "lxc.cgroup.%s = %s\n",
2796 cg
->subsystem
, cg
->value
);
2797 } else if (!strcmp(cg
->subsystem
, key
)) {
2798 strprint(retv
, inlen
, "%s\n", cg
->value
);
2805 static int get_config_cgroup_dir(const char *key
, char *retv
, int inlen
,
2806 struct lxc_conf
*lxc_conf
, void *data
)
2814 memset(retv
, 0, inlen
);
2816 strprint(retv
, inlen
, "%s", lxc_conf
->cgroup_meta
.dir
);
2821 static int get_config_idmaps(const char *key
, char *retv
, int inlen
,
2822 struct lxc_conf
*c
, void *data
)
2824 struct lxc_list
*it
;
2825 int len
, listlen
, ret
;
2827 /* "u 1000 1000000 65536"
2829 * let's render this as
2847 #define __LXC_IDMAP_STR_BUF (3 * LXC_NUMSTRLEN64 + 3 + 1 + 1)
2848 char buf
[__LXC_IDMAP_STR_BUF
];
2853 memset(retv
, 0, inlen
);
2855 listlen
= lxc_list_len(&c
->id_map
);
2856 lxc_list_for_each(it
, &c
->id_map
)
2858 struct id_map
*map
= it
->elem
;
2859 ret
= snprintf(buf
, __LXC_IDMAP_STR_BUF
, "%c %lu %lu %lu",
2860 (map
->idtype
== ID_TYPE_UID
) ? 'u' : 'g',
2861 map
->nsid
, map
->hostid
, map
->range
);
2862 if (ret
< 0 || ret
>= __LXC_IDMAP_STR_BUF
)
2865 strprint(retv
, inlen
, "%s%s", buf
, (listlen
-- > 1) ? "\n" : "");
2870 static int get_config_log_level(const char *key
, char *retv
, int inlen
,
2871 struct lxc_conf
*c
, void *data
)
2874 v
= lxc_log_priority_to_string(c
->loglevel
);
2875 return lxc_get_conf_str(retv
, inlen
, v
);
2878 static int get_config_log_file(const char *key
, char *retv
, int inlen
,
2879 struct lxc_conf
*c
, void *data
)
2881 return lxc_get_conf_str(retv
, inlen
, c
->logfile
);
2884 static int get_config_mount_fstab(const char *key
, char *retv
, int inlen
,
2885 struct lxc_conf
*c
, void *data
)
2887 return lxc_get_conf_str(retv
, inlen
, c
->fstab
);
2890 static int get_config_mount_auto(const char *key
, char *retv
, int inlen
,
2891 struct lxc_conf
*c
, void *data
)
2893 int len
, fulllen
= 0;
2894 const char *sep
= "";
2899 memset(retv
, 0, inlen
);
2901 if (!(c
->auto_mounts
& LXC_AUTO_ALL_MASK
))
2904 switch (c
->auto_mounts
& LXC_AUTO_PROC_MASK
) {
2905 case LXC_AUTO_PROC_MIXED
:
2906 strprint(retv
, inlen
, "%sproc:mixed", sep
);
2909 case LXC_AUTO_PROC_RW
:
2910 strprint(retv
, inlen
, "%sproc:rw", sep
);
2917 switch (c
->auto_mounts
& LXC_AUTO_SYS_MASK
) {
2918 case LXC_AUTO_SYS_RO
:
2919 strprint(retv
, inlen
, "%ssys:ro", sep
);
2922 case LXC_AUTO_SYS_RW
:
2923 strprint(retv
, inlen
, "%ssys:rw", sep
);
2926 case LXC_AUTO_SYS_MIXED
:
2927 strprint(retv
, inlen
, "%ssys:mixed", sep
);
2934 switch (c
->auto_mounts
& LXC_AUTO_CGROUP_MASK
) {
2935 case LXC_AUTO_CGROUP_NOSPEC
:
2936 strprint(retv
, inlen
, "%scgroup", sep
);
2939 case LXC_AUTO_CGROUP_MIXED
:
2940 strprint(retv
, inlen
, "%scgroup:mixed", sep
);
2943 case LXC_AUTO_CGROUP_RO
:
2944 strprint(retv
, inlen
, "%scgroup:ro", sep
);
2947 case LXC_AUTO_CGROUP_RW
:
2948 strprint(retv
, inlen
, "%scgroup:rw", sep
);
2951 case LXC_AUTO_CGROUP_FULL_NOSPEC
:
2952 strprint(retv
, inlen
, "%scgroup-full", sep
);
2955 case LXC_AUTO_CGROUP_FULL_MIXED
:
2956 strprint(retv
, inlen
, "%scgroup-full:mixed", sep
);
2959 case LXC_AUTO_CGROUP_FULL_RO
:
2960 strprint(retv
, inlen
, "%scgroup-full:ro", sep
);
2963 case LXC_AUTO_CGROUP_FULL_RW
:
2964 strprint(retv
, inlen
, "%scgroup-full:rw", sep
);
2974 static int get_config_mount(const char *key
, char *retv
, int inlen
,
2975 struct lxc_conf
*c
, void *data
)
2977 int len
, fulllen
= 0;
2978 struct lxc_list
*it
;
2983 memset(retv
, 0, inlen
);
2985 lxc_list_for_each(it
, &c
->mount_list
) {
2986 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
2992 static int get_config_rootfs_path(const char *key
, char *retv
, int inlen
,
2993 struct lxc_conf
*c
, void *data
)
2995 return lxc_get_conf_str(retv
, inlen
, c
->rootfs
.path
);
2998 static int get_config_rootfs_mount(const char *key
, char *retv
, int inlen
,
2999 struct lxc_conf
*c
, void *data
)
3001 return lxc_get_conf_str(retv
, inlen
, c
->rootfs
.mount
);
3004 static int get_config_rootfs_options(const char *key
, char *retv
, int inlen
,
3005 struct lxc_conf
*c
, void *data
)
3007 return lxc_get_conf_str(retv
, inlen
, c
->rootfs
.options
);
3010 static int get_config_rootfs_backend(const char *key
, char *retv
, int inlen
,
3011 struct lxc_conf
*c
, void *data
)
3016 static int get_config_uts_name(const char *key
, char *retv
, int inlen
,
3017 struct lxc_conf
*c
, void *data
)
3019 return lxc_get_conf_str(
3021 c
->utsname
? c
->utsname
->nodename
: NULL
);
3024 static int get_config_hooks(const char *key
, char *retv
, int inlen
,
3025 struct lxc_conf
*c
, void *data
)
3028 int len
, fulllen
= 0, found
= -1;
3029 struct lxc_list
*it
;
3032 subkey
= strchr(key
, '.');
3034 subkey
= strchr(subkey
+ 1, '.');
3040 for (i
= 0; i
< NUM_LXC_HOOKS
; i
++) {
3041 if (strcmp(lxchook_names
[i
], subkey
) == 0) {
3052 memset(retv
, 0, inlen
);
3054 lxc_list_for_each(it
, &c
->hooks
[found
]) {
3055 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3060 static int get_config_net(const char *key
, char *retv
, int inlen
,
3061 struct lxc_conf
*c
, void *data
)
3063 int len
, fulllen
= 0;
3064 struct lxc_list
*it
;
3069 memset(retv
, 0, inlen
);
3071 lxc_list_for_each(it
, &c
->network
) {
3072 struct lxc_netdev
*n
= it
->elem
;
3073 const char *t
= lxc_net_type_to_str(n
->type
);
3074 strprint(retv
, inlen
, "%s\n", t
? t
: "(invalid)");
3080 static int get_config_cap_drop(const char *key
, char *retv
, int inlen
,
3081 struct lxc_conf
*c
, void *data
)
3083 int len
, fulllen
= 0;
3084 struct lxc_list
*it
;
3089 memset(retv
, 0, inlen
);
3091 lxc_list_for_each(it
, &c
->caps
) {
3092 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3098 static int get_config_cap_keep(const char *key
, char *retv
, int inlen
,
3099 struct lxc_conf
*c
, void *data
)
3101 int len
, fulllen
= 0;
3102 struct lxc_list
*it
;
3107 memset(retv
, 0, inlen
);
3109 lxc_list_for_each(it
, &c
->keepcaps
) {
3110 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3116 static int get_config_console_path(const char *key
, char *retv
, int inlen
,
3117 struct lxc_conf
*c
, void *data
)
3119 return lxc_get_conf_str(retv
, inlen
, c
->console
.path
);
3122 static int get_config_console_logfile(const char *key
, char *retv
, int inlen
,
3123 struct lxc_conf
*c
, void *data
)
3125 return lxc_get_conf_str(retv
, inlen
, c
->console
.log_path
);
3128 static int get_config_console_rotate(const char *key
, char *retv
, int inlen
,
3129 struct lxc_conf
*c
, void *data
)
3131 return lxc_get_conf_int(c
, retv
, inlen
, c
->console
.log_rotate
);
3135 static int get_config_console_buffer_size(const char *key
, char *retv
,
3136 int inlen
, struct lxc_conf
*c
,
3139 return lxc_get_conf_uint64(c
, retv
, inlen
, c
->autodev
);
3142 static int get_config_console_buffer_logfile(const char *key
, char *retv
,
3143 int inlen
, struct lxc_conf
*c
,
3146 return lxc_get_conf_str(retv
, inlen
, c
->console
.buffer_log_file
);
3149 static int get_config_seccomp_profile(const char *key
, char *retv
, int inlen
,
3150 struct lxc_conf
*c
, void *data
)
3152 return lxc_get_conf_str(retv
, inlen
, c
->seccomp
);
3155 static int get_config_autodev(const char *key
, char *retv
, int inlen
,
3156 struct lxc_conf
*c
, void *data
)
3158 return lxc_get_conf_int(c
, retv
, inlen
, c
->autodev
);
3161 static int get_config_signal_halt(const char *key
, char *retv
, int inlen
,
3162 struct lxc_conf
*c
, void *data
)
3164 return lxc_get_conf_int(c
, retv
, inlen
, c
->haltsignal
);
3167 static int get_config_signal_reboot(const char *key
, char *retv
, int inlen
,
3168 struct lxc_conf
*c
, void *data
)
3170 return lxc_get_conf_int(c
, retv
, inlen
, c
->rebootsignal
);
3173 static int get_config_signal_stop(const char *key
, char *retv
, int inlen
,
3174 struct lxc_conf
*c
, void *data
)
3176 return lxc_get_conf_int(c
, retv
, inlen
, c
->stopsignal
);
3179 static int get_config_start(const char *key
, char *retv
, int inlen
,
3180 struct lxc_conf
*c
, void *data
)
3182 if (strcmp(key
+ 10, "auto") == 0)
3183 return lxc_get_conf_int(c
, retv
, inlen
, c
->start_auto
);
3184 else if (strcmp(key
+ 10, "delay") == 0)
3185 return lxc_get_conf_int(c
, retv
, inlen
, c
->start_delay
);
3186 else if (strcmp(key
+ 10, "order") == 0)
3187 return lxc_get_conf_int(c
, retv
, inlen
, c
->start_order
);
3192 static int get_config_log_syslog(const char *key
, char *retv
, int inlen
,
3193 struct lxc_conf
*c
, void *data
)
3195 return lxc_get_conf_str(retv
, inlen
, c
->syslog
);
3198 static int get_config_monitor(const char *key
, char *retv
, int inlen
,
3199 struct lxc_conf
*c
, void *data
)
3201 return lxc_get_conf_int(c
, retv
, inlen
, c
->monitor_unshare
);
3204 static int get_config_group(const char *key
, char *retv
, int inlen
,
3205 struct lxc_conf
*c
, void *data
)
3207 int len
, fulllen
= 0;
3208 struct lxc_list
*it
;
3213 memset(retv
, 0, inlen
);
3215 lxc_list_for_each(it
, &c
->groups
) {
3216 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3222 static int get_config_environment(const char *key
, char *retv
, int inlen
,
3223 struct lxc_conf
*c
, void *data
)
3225 int len
, fulllen
= 0;
3226 struct lxc_list
*it
;
3231 memset(retv
, 0, inlen
);
3233 lxc_list_for_each(it
, &c
->environment
) {
3234 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3240 static int get_config_execute_cmd(const char *key
, char *retv
, int inlen
,
3241 struct lxc_conf
*c
, void *data
)
3243 return lxc_get_conf_str(retv
, inlen
, c
->execute_cmd
);
3246 static int get_config_init_cmd(const char *key
, char *retv
, int inlen
,
3247 struct lxc_conf
*c
, void *data
)
3249 return lxc_get_conf_str(retv
, inlen
, c
->init_cmd
);
3252 static int get_config_init_uid(const char *key
, char *retv
, int inlen
,
3253 struct lxc_conf
*c
, void *data
)
3255 return lxc_get_conf_int(c
, retv
, inlen
, c
->init_uid
);
3258 static int get_config_init_gid(const char *key
, char *retv
, int inlen
,
3259 struct lxc_conf
*c
, void *data
)
3261 return lxc_get_conf_int(c
, retv
, inlen
, c
->init_gid
);
3264 static int get_config_ephemeral(const char *key
, char *retv
, int inlen
,
3265 struct lxc_conf
*c
, void *data
)
3267 return lxc_get_conf_int(c
, retv
, inlen
, c
->ephemeral
);
3270 static int get_config_no_new_privs(const char *key
, char *retv
, int inlen
,
3271 struct lxc_conf
*c
, void *data
)
3273 return lxc_get_conf_int(c
, retv
, inlen
, c
->no_new_privs
);
3276 /* If you ask for a specific value, i.e. lxc.prlimit.nofile, then just the value
3277 * will be printed. If you ask for 'lxc.prlimit', then all limit entries will be
3278 * printed, in 'lxc.prlimit.resource = value' format.
3280 static int get_config_prlimit(const char *key
, char *retv
, int inlen
,
3281 struct lxc_conf
*c
, void *data
)
3283 int fulllen
= 0, len
;
3284 bool get_all
= false;
3285 struct lxc_list
*it
;
3290 memset(retv
, 0, inlen
);
3292 if (!strcmp(key
, "lxc.prlimit"))
3294 else if (strncmp(key
, "lxc.prlimit.", 12) == 0)
3299 lxc_list_for_each(it
, &c
->limits
) {
3300 char buf
[LXC_NUMSTRLEN64
* 2 + 2]; /* 2 colon separated 64 bit
3301 integers or the word
3304 struct lxc_limit
*lim
= it
->elem
;
3306 if (lim
->limit
.rlim_cur
== RLIM_INFINITY
) {
3307 memcpy(buf
, "unlimited", sizeof("unlimited"));
3308 partlen
= sizeof("unlimited") - 1;
3310 partlen
= sprintf(buf
, "%" PRIu64
,
3311 (uint64_t)lim
->limit
.rlim_cur
);
3313 if (lim
->limit
.rlim_cur
!= lim
->limit
.rlim_max
) {
3314 if (lim
->limit
.rlim_max
== RLIM_INFINITY
)
3315 memcpy(buf
+ partlen
, ":unlimited",
3316 sizeof(":unlimited"));
3318 sprintf(buf
+ partlen
, ":%" PRIu64
,
3319 (uint64_t)lim
->limit
.rlim_max
);
3323 strprint(retv
, inlen
, "lxc.prlimit.%s = %s\n",
3324 lim
->resource
, buf
);
3325 } else if (!strcmp(lim
->resource
, key
)) {
3326 strprint(retv
, inlen
, "%s", buf
);
3333 static int get_config_noop(const char *key
, char *retv
, int inlen
,
3334 struct lxc_conf
*c
, void *data
)
3339 static int get_config_namespace(const char *key
, char *retv
, int inlen
,
3340 struct lxc_conf
*c
, void *data
)
3343 const char *namespace;
3349 memset(retv
, 0, inlen
);
3351 namespace = key
+ sizeof("lxc.namespace.") - 1;
3352 ns_idx
= lxc_namespace_2_ns_idx(namespace);
3356 strprint(retv
, inlen
, "%s", c
->inherit_ns
[ns_idx
]);
3361 /* Callbacks to clear config items. */
3362 static inline int clr_config_personality(const char *key
, struct lxc_conf
*c
,
3365 c
->personality
= -1;
3369 static inline int clr_config_pty_max(const char *key
, struct lxc_conf
*c
,
3376 static inline int clr_config_tty_max(const char *key
, struct lxc_conf
*c
,
3383 static inline int clr_config_tty_dir(const char *key
, struct lxc_conf
*c
,
3391 static inline int clr_config_apparmor_profile(const char *key
,
3392 struct lxc_conf
*c
, void *data
)
3394 free(c
->lsm_aa_profile
);
3395 c
->lsm_aa_profile
= NULL
;
3399 static inline int clr_config_apparmor_allow_incomplete(const char *key
,
3403 c
->lsm_aa_allow_incomplete
= 0;
3407 static inline int clr_config_selinux_context(const char *key
,
3408 struct lxc_conf
*c
, void *data
)
3410 free(c
->lsm_se_context
);
3411 c
->lsm_se_context
= NULL
;
3415 static inline int clr_config_cgroup_controller(const char *key
,
3416 struct lxc_conf
*c
, void *data
)
3418 return lxc_clear_cgroups(c
, key
);
3421 static int clr_config_cgroup_dir(const char *key
, struct lxc_conf
*lxc_conf
,
3424 if (lxc_conf
->cgroup_meta
.dir
) {
3425 free(lxc_conf
->cgroup_meta
.dir
);
3426 lxc_conf
->cgroup_meta
.dir
= NULL
;
3432 static inline int clr_config_idmaps(const char *key
, struct lxc_conf
*c
,
3435 return lxc_clear_idmaps(c
);
3438 static inline int clr_config_log_level(const char *key
, struct lxc_conf
*c
,
3441 c
->loglevel
= LXC_LOG_LEVEL_NOTSET
;
3445 static inline int clr_config_log_file(const char *key
, struct lxc_conf
*c
,
3453 static inline int clr_config_mount(const char *key
, struct lxc_conf
*c
,
3456 return lxc_clear_mount_entries(c
);
3459 static inline int clr_config_mount_auto(const char *key
, struct lxc_conf
*c
,
3462 return lxc_clear_automounts(c
);
3465 static inline int clr_config_mount_fstab(const char *key
, struct lxc_conf
*c
,
3473 static inline int clr_config_rootfs_path(const char *key
, struct lxc_conf
*c
,
3476 free(c
->rootfs
.path
);
3477 c
->rootfs
.path
= NULL
;
3481 static inline int clr_config_rootfs_mount(const char *key
, struct lxc_conf
*c
,
3484 free(c
->rootfs
.mount
);
3485 c
->rootfs
.mount
= NULL
;
3489 static inline int clr_config_rootfs_options(const char *key
, struct lxc_conf
*c
,
3492 free(c
->rootfs
.options
);
3493 c
->rootfs
.options
= NULL
;
3497 static inline int clr_config_rootfs_backend(const char *key
, struct lxc_conf
*c
,
3503 static inline int clr_config_uts_name(const char *key
, struct lxc_conf
*c
,
3511 static inline int clr_config_hooks(const char *key
, struct lxc_conf
*c
,
3514 return lxc_clear_hooks(c
, key
);
3517 static inline int clr_config_net(const char *key
, struct lxc_conf
*c
,
3520 lxc_free_networks(&c
->network
);
3525 static inline int clr_config_cap_drop(const char *key
, struct lxc_conf
*c
,
3528 return lxc_clear_config_caps(c
);
3531 static inline int clr_config_cap_keep(const char *key
, struct lxc_conf
*c
,
3534 return lxc_clear_config_keepcaps(c
);
3537 static inline int clr_config_console_path(const char *key
, struct lxc_conf
*c
,
3540 free(c
->console
.path
);
3541 c
->console
.path
= NULL
;
3545 static inline int clr_config_console_logfile(const char *key
,
3546 struct lxc_conf
*c
, void *data
)
3548 free(c
->console
.log_path
);
3549 c
->console
.log_path
= NULL
;
3553 static inline int clr_config_console_rotate(const char *key
, struct lxc_conf
*c
,
3556 c
->console
.log_rotate
= 0;
3560 static inline int clr_config_console_buffer_size(const char *key
,
3561 struct lxc_conf
*c
, void *data
)
3563 c
->console
.buffer_size
= 0;
3567 static inline int clr_config_console_buffer_logfile(const char *key
,
3571 free(c
->console
.buffer_log_file
);
3572 c
->console
.buffer_log_file
= NULL
;
3576 static inline int clr_config_seccomp_profile(const char *key
,
3577 struct lxc_conf
*c
, void *data
)
3584 static inline int clr_config_autodev(const char *key
, struct lxc_conf
*c
,
3591 static inline int clr_config_signal_halt(const char *key
, struct lxc_conf
*c
,
3598 static inline int clr_config_signal_reboot(const char *key
, struct lxc_conf
*c
,
3601 c
->rebootsignal
= 0;
3605 static inline int clr_config_signal_stop(const char *key
, struct lxc_conf
*c
,
3612 static inline int clr_config_start(const char *key
, struct lxc_conf
*c
,
3615 if (strcmp(key
+ 10, "auto") == 0)
3617 else if (strcmp(key
+ 10, "delay") == 0)
3619 else if (strcmp(key
+ 10, "order") == 0)
3625 static inline int clr_config_log_syslog(const char *key
, struct lxc_conf
*c
,
3633 static inline int clr_config_monitor(const char *key
, struct lxc_conf
*c
,
3636 c
->monitor_unshare
= 0;
3640 static inline int clr_config_group(const char *key
, struct lxc_conf
*c
,
3643 return lxc_clear_groups(c
);
3646 static inline int clr_config_environment(const char *key
, struct lxc_conf
*c
,
3649 return lxc_clear_environment(c
);
3652 static inline int clr_config_execute_cmd(const char *key
, struct lxc_conf
*c
,
3655 free(c
->execute_cmd
);
3656 c
->execute_cmd
= NULL
;
3660 static inline int clr_config_init_cmd(const char *key
, struct lxc_conf
*c
,
3668 static inline int clr_config_init_uid(const char *key
, struct lxc_conf
*c
,
3675 static inline int clr_config_init_gid(const char *key
, struct lxc_conf
*c
,
3682 static inline int clr_config_ephemeral(const char *key
, struct lxc_conf
*c
,
3689 static inline int clr_config_no_new_privs(const char *key
, struct lxc_conf
*c
,
3692 c
->no_new_privs
= false;
3696 static inline int clr_config_prlimit(const char *key
, struct lxc_conf
*c
,
3699 return lxc_clear_limits(c
, key
);
3702 static inline int clr_config_includefiles(const char *key
, struct lxc_conf
*c
,
3705 lxc_clear_includes(c
);
3709 static inline int clr_config_noop(const char *key
, struct lxc_conf
*c
,
3715 static int clr_config_namespace(const char *key
, struct lxc_conf
*lxc_conf
,
3719 const char *namespace;
3721 namespace = key
+ sizeof("lxc.namespace.") - 1;
3722 ns_idx
= lxc_namespace_2_ns_idx(namespace);
3726 free(lxc_conf
->inherit_ns
[ns_idx
]);
3727 lxc_conf
->inherit_ns
[ns_idx
] = NULL
;
3732 static int get_config_includefiles(const char *key
, char *retv
, int inlen
,
3733 struct lxc_conf
*c
, void *data
)
3738 static struct lxc_config_t
*get_network_config_ops(const char *key
,
3739 struct lxc_conf
*lxc_conf
,
3741 char **deindexed_key
)
3744 unsigned int tmpidx
;
3746 char *copy
, *idx_start
, *idx_end
;
3747 struct lxc_config_t
*config
= NULL
;
3749 /* check that this is a sensible network key */
3750 if (strncmp("lxc.net.", key
, 8)) {
3751 ERROR("Invalid network configuration key \"%s\"", key
);
3757 ERROR("Failed to duplicate string \"%s\"", key
);
3762 if (!isdigit(*(key
+ 8))) {
3763 ERROR("Failed to detect digit in string \"%s\"", key
+ 8);
3767 /* beginning of index string */
3768 idx_start
= (copy
+ 7);
3771 /* end of index string */
3772 idx_end
= strchr((copy
+ 8), '.');
3776 /* parse current index */
3777 ret
= lxc_safe_uint((idx_start
+ 1), &tmpidx
);
3779 ERROR("Failed to parse usigned integer from string \"%s\": %s",
3780 idx_start
+ 1, strerror(-ret
));
3785 /* This, of course is utterly nonsensical on so many levels, but
3786 * better safe than sorry.
3787 * (Checking for INT_MAX here is intentional.)
3789 if (tmpidx
== INT_MAX
) {
3790 SYSERROR("Number of configured networks would overflow the "
3796 numstrlen
= strlen((idx_start
+ 1));
3798 /* repair configuration key */
3801 /* lxc.net.<idx>.<subkey> */
3804 if (strlen(idx_end
+ 1) == 0) {
3805 ERROR("No subkey in network configuration key \"%s\"", key
);
3809 memmove(copy
+ 8, idx_end
+ 1, strlen(idx_end
+ 1));
3810 copy
[strlen(key
) - numstrlen
+ 1] = '\0';
3812 config
= lxc_get_config(copy
);
3814 ERROR("Unknown network configuration key \"%s\"", key
);
3820 *deindexed_key
= copy
;
3829 /* Config entry is something like "lxc.net.0.ipv4" the key 'lxc.net.' was
3830 * found. So we make sure next comes an integer, find the right callback (by
3831 * rewriting the key), and call it.
3833 static int set_config_net_nic(const char *key
, const char *value
,
3834 struct lxc_conf
*lxc_conf
, void *data
)
3837 const char *idxstring
;
3838 struct lxc_config_t
*config
;
3839 struct lxc_netdev
*netdev
;
3841 char *deindexed_key
= NULL
;
3843 idxstring
= key
+ 8;
3844 if (!isdigit(*idxstring
))
3847 if (lxc_config_value_empty(value
))
3848 return clr_config_net_nic(key
, lxc_conf
, data
);
3850 config
= get_network_config_ops(key
, lxc_conf
, &idx
, &deindexed_key
);
3851 if (!config
|| idx
< 0)
3854 netdev
= lxc_get_netdev_by_idx(lxc_conf
, (unsigned int)idx
, true);
3856 free(deindexed_key
);
3860 ret
= config
->set(deindexed_key
, value
, lxc_conf
, netdev
);
3861 free(deindexed_key
);
3865 static int clr_config_net_nic(const char *key
, struct lxc_conf
*lxc_conf
,
3869 const char *idxstring
;
3870 struct lxc_config_t
*config
;
3871 struct lxc_netdev
*netdev
;
3873 char *deindexed_key
= NULL
;
3875 idxstring
= key
+ 8;
3876 if (!isdigit(*idxstring
))
3879 /* The left conjunct is pretty self-explanatory. The right conjunct
3880 * checks whether the two pointers are equal. If they are we know that
3881 * this is not a key that is namespaced any further and so we are
3882 * supposed to clear the whole network.
3884 if (isdigit(*idxstring
) && (strrchr(key
, '.') == (idxstring
- 1))) {
3885 unsigned int rmnetdevidx
;
3887 if (lxc_safe_uint(idxstring
, &rmnetdevidx
) < 0)
3890 /* Remove network from network list. */
3891 lxc_remove_nic_by_idx(lxc_conf
, rmnetdevidx
);
3895 config
= get_network_config_ops(key
, lxc_conf
, &idx
, &deindexed_key
);
3896 if (!config
|| idx
< 0)
3899 netdev
= lxc_get_netdev_by_idx(lxc_conf
, (unsigned int)idx
, false);
3901 free(deindexed_key
);
3905 ret
= config
->clr(deindexed_key
, lxc_conf
, netdev
);
3906 free(deindexed_key
);
3910 static int clr_config_net_type(const char *key
, struct lxc_conf
*lxc_conf
,
3913 struct lxc_netdev
*netdev
;
3927 static int clr_config_net_name(const char *key
, struct lxc_conf
*lxc_conf
,
3930 struct lxc_netdev
*netdev
;
3939 netdev
->name
[0] = '\0';
3944 static int clr_config_net_flags(const char *key
, struct lxc_conf
*lxc_conf
,
3947 struct lxc_netdev
*netdev
;
3961 static int clr_config_net_link(const char *key
, struct lxc_conf
*lxc_conf
,
3964 struct lxc_netdev
*netdev
;
3973 netdev
->link
[0] = '\0';
3978 static int clr_config_net_macvlan_mode(const char *key
,
3979 struct lxc_conf
*lxc_conf
, void *data
)
3981 struct lxc_netdev
*netdev
;
3990 if (netdev
->type
!= LXC_NET_MACVLAN
)
3993 netdev
->priv
.macvlan_attr
.mode
= -1;
3998 static int clr_config_net_veth_pair(const char *key
, struct lxc_conf
*lxc_conf
,
4001 struct lxc_netdev
*netdev
;
4010 netdev
->priv
.veth_attr
.pair
[0] = '\0';
4015 static int clr_config_net_script_up(const char *key
, struct lxc_conf
*lxc_conf
,
4018 struct lxc_netdev
*netdev
;
4027 free(netdev
->upscript
);
4028 netdev
->upscript
= NULL
;
4033 static int clr_config_net_script_down(const char *key
,
4034 struct lxc_conf
*lxc_conf
, void *data
)
4036 struct lxc_netdev
*netdev
;
4045 free(netdev
->downscript
);
4046 netdev
->downscript
= NULL
;
4051 static int clr_config_net_hwaddr(const char *key
, struct lxc_conf
*lxc_conf
,
4054 struct lxc_netdev
*netdev
;
4063 free(netdev
->hwaddr
);
4064 netdev
->hwaddr
= NULL
;
4069 static int clr_config_net_mtu(const char *key
, struct lxc_conf
*lxc_conf
,
4072 struct lxc_netdev
*netdev
;
4087 static int clr_config_net_vlan_id(const char *key
, struct lxc_conf
*lxc_conf
,
4090 struct lxc_netdev
*netdev
;
4099 netdev
->priv
.vlan_attr
.vid
= 0;
4104 static int clr_config_net_ipv4_gateway(const char *key
,
4105 struct lxc_conf
*lxc_conf
, void *data
)
4107 struct lxc_netdev
*netdev
;
4116 free(netdev
->ipv4_gateway
);
4117 netdev
->ipv4_gateway
= NULL
;
4122 static int clr_config_net_ipv4_address(const char *key
,
4123 struct lxc_conf
*lxc_conf
, void *data
)
4125 struct lxc_netdev
*netdev
;
4126 struct lxc_list
*cur
, *next
;
4135 lxc_list_for_each_safe(cur
, &netdev
->ipv4
, next
) {
4144 static int clr_config_net_ipv6_gateway(const char *key
,
4145 struct lxc_conf
*lxc_conf
, void *data
)
4147 struct lxc_netdev
*netdev
;
4156 free(netdev
->ipv6_gateway
);
4157 netdev
->ipv6_gateway
= NULL
;
4162 static int clr_config_net_ipv6_address(const char *key
,
4163 struct lxc_conf
*lxc_conf
, void *data
)
4165 struct lxc_netdev
*netdev
;
4166 struct lxc_list
*cur
, *next
;
4175 lxc_list_for_each_safe(cur
, &netdev
->ipv6
, next
) {
4184 static int get_config_net_nic(const char *key
, char *retv
, int inlen
,
4185 struct lxc_conf
*c
, void *data
)
4188 const char *idxstring
;
4189 struct lxc_config_t
*config
;
4190 struct lxc_netdev
*netdev
;
4192 char *deindexed_key
= NULL
;
4194 idxstring
= key
+ 8;
4195 if (!isdigit(*idxstring
))
4198 config
= get_network_config_ops(key
, c
, &idx
, &deindexed_key
);
4199 if (!config
|| idx
< 0)
4202 netdev
= lxc_get_netdev_by_idx(c
, (unsigned int)idx
, false);
4204 free(deindexed_key
);
4208 ret
= config
->get(deindexed_key
, retv
, inlen
, c
, netdev
);
4209 free(deindexed_key
);
4213 static int get_config_net_type(const char *key
, char *retv
, int inlen
,
4214 struct lxc_conf
*c
, void *data
)
4216 int len
, fulllen
= 0;
4217 struct lxc_netdev
*netdev
;
4222 memset(retv
, 0, inlen
);
4231 strprint(retv
, inlen
, "%s", lxc_net_type_to_str(netdev
->type
));
4236 static int get_config_net_flags(const char *key
, char *retv
, int inlen
,
4237 struct lxc_conf
*c
, void *data
)
4239 int len
, fulllen
= 0;
4240 struct lxc_netdev
*netdev
;
4245 memset(retv
, 0, inlen
);
4254 if (netdev
->flags
& IFF_UP
)
4255 strprint(retv
, inlen
, "up");
4260 static int get_config_net_link(const char *key
, char *retv
, int inlen
,
4261 struct lxc_conf
*c
, void *data
)
4263 int len
, fulllen
= 0;
4264 struct lxc_netdev
*netdev
;
4269 memset(retv
, 0, inlen
);
4278 if (netdev
->link
[0] != '\0')
4279 strprint(retv
, inlen
, "%s", netdev
->link
);
4284 static int get_config_net_name(const char *key
, char *retv
, int inlen
,
4285 struct lxc_conf
*c
, void *data
)
4287 int len
, fulllen
= 0;
4288 struct lxc_netdev
*netdev
;
4293 memset(retv
, 0, inlen
);
4302 if (netdev
->name
[0] != '\0')
4303 strprint(retv
, inlen
, "%s", netdev
->name
);
4308 static int get_config_net_macvlan_mode(const char *key
, char *retv
, int inlen
,
4309 struct lxc_conf
*c
, void *data
)
4312 int len
, fulllen
= 0;
4313 struct lxc_netdev
*netdev
;
4318 memset(retv
, 0, inlen
);
4327 if (netdev
->type
!= LXC_NET_MACVLAN
)
4330 switch (netdev
->priv
.macvlan_attr
.mode
) {
4331 case MACVLAN_MODE_PRIVATE
:
4334 case MACVLAN_MODE_VEPA
:
4337 case MACVLAN_MODE_BRIDGE
:
4340 case MACVLAN_MODE_PASSTHRU
:
4348 strprint(retv
, inlen
, "%s", mode
);
4353 static int get_config_net_veth_pair(const char *key
, char *retv
, int inlen
,
4354 struct lxc_conf
*c
, void *data
)
4356 int len
, fulllen
= 0;
4357 struct lxc_netdev
*netdev
;
4362 memset(retv
, 0, inlen
);
4371 if (netdev
->type
!= LXC_NET_VETH
)
4374 strprint(retv
, inlen
, "%s",
4375 netdev
->priv
.veth_attr
.pair
[0] != '\0'
4376 ? netdev
->priv
.veth_attr
.pair
4377 : netdev
->priv
.veth_attr
.veth1
);
4382 static int get_config_net_script_up(const char *key
, char *retv
, int inlen
,
4383 struct lxc_conf
*c
, void *data
)
4385 int len
, fulllen
= 0;
4386 struct lxc_netdev
*netdev
;
4391 memset(retv
, 0, inlen
);
4400 if (netdev
->upscript
)
4401 strprint(retv
, inlen
, "%s", netdev
->upscript
);
4406 static int get_config_net_script_down(const char *key
, char *retv
, int inlen
,
4407 struct lxc_conf
*c
, void *data
)
4409 int len
, fulllen
= 0;
4410 struct lxc_netdev
*netdev
;
4415 memset(retv
, 0, inlen
);
4424 if (netdev
->downscript
)
4425 strprint(retv
, inlen
, "%s", netdev
->downscript
);
4430 static int get_config_net_hwaddr(const char *key
, char *retv
, int inlen
,
4431 struct lxc_conf
*c
, void *data
)
4433 int len
, fulllen
= 0;
4434 struct lxc_netdev
*netdev
;
4439 memset(retv
, 0, inlen
);
4449 strprint(retv
, inlen
, "%s", netdev
->hwaddr
);
4454 static int get_config_net_mtu(const char *key
, char *retv
, int inlen
,
4455 struct lxc_conf
*c
, void *data
)
4457 int len
, fulllen
= 0;
4458 struct lxc_netdev
*netdev
;
4463 memset(retv
, 0, inlen
);
4473 strprint(retv
, inlen
, "%s", netdev
->mtu
);
4478 static int get_config_net_vlan_id(const char *key
, char *retv
, int inlen
,
4479 struct lxc_conf
*c
, void *data
)
4481 int len
, fulllen
= 0;
4482 struct lxc_netdev
*netdev
;
4487 memset(retv
, 0, inlen
);
4496 if (netdev
->type
!= LXC_NET_VLAN
)
4499 strprint(retv
, inlen
, "%d", netdev
->priv
.vlan_attr
.vid
);
4504 static int get_config_net_ipv4_gateway(const char *key
, char *retv
, int inlen
,
4505 struct lxc_conf
*c
, void *data
)
4507 int len
, fulllen
= 0;
4508 char buf
[INET_ADDRSTRLEN
];
4509 struct lxc_netdev
*netdev
;
4514 memset(retv
, 0, inlen
);
4523 if (netdev
->ipv4_gateway_auto
) {
4524 strprint(retv
, inlen
, "auto");
4525 } else if (netdev
->ipv4_gateway
) {
4526 inet_ntop(AF_INET
, netdev
->ipv4_gateway
, buf
, sizeof(buf
));
4527 strprint(retv
, inlen
, "%s", buf
);
4533 static int get_config_net_ipv4_address(const char *key
, char *retv
, int inlen
,
4534 struct lxc_conf
*c
, void *data
)
4536 int len
, fulllen
= 0;
4538 char buf
[INET_ADDRSTRLEN
];
4539 struct lxc_netdev
*netdev
;
4540 struct lxc_list
*it
;
4545 memset(retv
, 0, inlen
);
4554 listlen
= lxc_list_len(&netdev
->ipv4
);
4555 lxc_list_for_each(it
, &netdev
->ipv4
) {
4556 struct lxc_inetdev
*i
= it
->elem
;
4557 inet_ntop(AF_INET
, &i
->addr
, buf
, sizeof(buf
));
4558 strprint(retv
, inlen
, "%s/%u%s", buf
, i
->prefix
,
4559 (listlen
-- > 1) ? "\n" : "");
4565 static int get_config_net_ipv6_gateway(const char *key
, char *retv
, int inlen
,
4566 struct lxc_conf
*c
, void *data
)
4568 int len
, fulllen
= 0;
4569 char buf
[INET6_ADDRSTRLEN
];
4570 struct lxc_netdev
*netdev
;
4575 memset(retv
, 0, inlen
);
4584 if (netdev
->ipv6_gateway_auto
) {
4585 strprint(retv
, inlen
, "auto");
4586 } else if (netdev
->ipv6_gateway
) {
4587 inet_ntop(AF_INET6
, netdev
->ipv6_gateway
, buf
, sizeof(buf
));
4588 strprint(retv
, inlen
, "%s", buf
);
4594 static int get_config_net_ipv6_address(const char *key
, char *retv
, int inlen
,
4595 struct lxc_conf
*c
, void *data
)
4597 int len
, fulllen
= 0;
4599 char buf
[INET6_ADDRSTRLEN
];
4600 struct lxc_netdev
*netdev
;
4601 struct lxc_list
*it
;
4606 memset(retv
, 0, inlen
);
4615 listlen
= lxc_list_len(&netdev
->ipv6
);
4616 lxc_list_for_each(it
, &netdev
->ipv6
) {
4617 struct lxc_inet6dev
*i
= it
->elem
;
4618 inet_ntop(AF_INET6
, &i
->addr
, buf
, sizeof(buf
));
4619 strprint(retv
, inlen
, "%s/%u%s", buf
, i
->prefix
,
4620 (listlen
-- > 1) ? "\n" : "");
4626 int lxc_list_config_items(char *retv
, int inlen
)
4635 memset(retv
, 0, inlen
);
4637 for (i
= 0; i
< config_size
; i
++) {
4638 char *s
= config
[i
].name
;
4640 if (s
[strlen(s
) - 1] == '.')
4643 strprint(retv
, inlen
, "%s\n", s
);
4649 int lxc_list_subkeys(struct lxc_conf
*conf
, const char *key
, char *retv
,
4658 memset(retv
, 0, inlen
);
4660 if (!strcmp(key
, "lxc.apparmor")) {
4661 strprint(retv
, inlen
, "allow_incomplete\n");
4662 strprint(retv
, inlen
, "profile\n");
4663 } else if (!strcmp(key
, "lxc.cgroup")) {
4664 strprint(retv
, inlen
, "dir\n");
4665 } else if (!strcmp(key
, "lxc.selinux")) {
4666 strprint(retv
, inlen
, "context\n");
4667 } else if (!strcmp(key
, "lxc.mount")) {
4668 strprint(retv
, inlen
, "auto\n");
4669 strprint(retv
, inlen
, "entry\n");
4670 strprint(retv
, inlen
, "fstab\n");
4671 } else if (!strcmp(key
, "lxc.rootfs")) {
4672 strprint(retv
, inlen
, "mount\n");
4673 strprint(retv
, inlen
, "options\n");
4674 strprint(retv
, inlen
, "path\n");
4675 } else if (!strcmp(key
, "lxc.uts")) {
4676 strprint(retv
, inlen
, "name\n");
4677 } else if (!strcmp(key
, "lxc.hook")) {
4678 strprint(retv
, inlen
, "autodev\n");
4679 strprint(retv
, inlen
, "clone\n");
4680 strprint(retv
, inlen
, "destroy\n");
4681 strprint(retv
, inlen
, "mount\n");
4682 strprint(retv
, inlen
, "post-stop\n");
4683 strprint(retv
, inlen
, "pre-mount\n");
4684 strprint(retv
, inlen
, "pre-start\n");
4685 strprint(retv
, inlen
, "start-host\n");
4686 strprint(retv
, inlen
, "start\n");
4687 strprint(retv
, inlen
, "stop\n");
4688 } else if (!strcmp(key
, "lxc.cap")) {
4689 strprint(retv
, inlen
, "drop\n");
4690 strprint(retv
, inlen
, "keep\n");
4691 } else if (!strcmp(key
, "lxc.console")) {
4692 strprint(retv
, inlen
, "logfile\n");
4693 strprint(retv
, inlen
, "path\n");
4694 } else if (!strcmp(key
, "lxc.seccomp")) {
4695 strprint(retv
, inlen
, "profile\n");
4696 } else if (!strcmp(key
, "lxc.signal")) {
4697 strprint(retv
, inlen
, "halt\n");
4698 strprint(retv
, inlen
, "reboot\n");
4699 strprint(retv
, inlen
, "stop\n");
4700 } else if (!strcmp(key
, "lxc.start")) {
4701 strprint(retv
, inlen
, "auto\n");
4702 strprint(retv
, inlen
, "delay\n");
4703 strprint(retv
, inlen
, "order\n");
4704 } else if (!strcmp(key
, "lxc.monitor")) {
4705 strprint(retv
, inlen
, "unshare\n");
4713 int lxc_list_net(struct lxc_conf
*c
, const char *key
, char *retv
, int inlen
)
4716 const char *idxstring
;
4717 struct lxc_netdev
*netdev
;
4721 idxstring
= key
+ 8;
4722 if (!isdigit(*idxstring
))
4725 (void)get_network_config_ops(key
, c
, &idx
, NULL
);
4729 netdev
= lxc_get_netdev_by_idx(c
, (unsigned int)idx
, false);
4736 memset(retv
, 0, inlen
);
4738 strprint(retv
, inlen
, "type\n");
4739 strprint(retv
, inlen
, "script.up\n");
4740 strprint(retv
, inlen
, "script.down\n");
4741 if (netdev
->type
!= LXC_NET_EMPTY
) {
4742 strprint(retv
, inlen
, "flags\n");
4743 strprint(retv
, inlen
, "link\n");
4744 strprint(retv
, inlen
, "name\n");
4745 strprint(retv
, inlen
, "hwaddr\n");
4746 strprint(retv
, inlen
, "mtu\n");
4747 strprint(retv
, inlen
, "ipv6.address\n");
4748 strprint(retv
, inlen
, "ipv6.gateway\n");
4749 strprint(retv
, inlen
, "ipv4.address\n");
4750 strprint(retv
, inlen
, "ipv4.gateway\n");
4753 switch (netdev
->type
) {
4755 strprint(retv
, inlen
, "veth.pair\n");
4757 case LXC_NET_MACVLAN
:
4758 strprint(retv
, inlen
, "macvlan.mode\n");
4761 strprint(retv
, inlen
, "vlan.id\n");