1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 #define __STDC_FORMAT_MACROS
14 #include <netinet/in.h>
19 #include <sys/param.h>
21 #include <sys/types.h>
22 #include <sys/utsname.h>
31 #include "confile_utils.h"
32 #include "../include/netns_ifaddrs.h"
34 #include "lxcseccomp.h"
36 #include "memory_utils.h"
42 #if HAVE_SYS_PERSONALITY_H
43 #include <sys/personality.h>
47 #include "include/strlcpy.h"
51 #include "include/strlcat.h"
54 lxc_log_define(confile
, lxc
);
56 #define lxc_config_define(name) \
57 __hot static int set_config_##name(const char *, const char *, \
58 struct lxc_conf *, void *); \
59 __hot static int get_config_##name(const char *, char *, int, \
60 struct lxc_conf *, void *); \
61 __hot static int clr_config_##name(const char *, struct lxc_conf *, \
64 lxc_config_define(autodev
);
65 lxc_config_define(autodev_tmpfs_size
);
66 lxc_config_define(apparmor_allow_incomplete
);
67 lxc_config_define(apparmor_allow_nesting
);
68 lxc_config_define(apparmor_profile
);
69 lxc_config_define(apparmor_raw
);
70 lxc_config_define(cap_drop
);
71 lxc_config_define(cap_keep
);
72 lxc_config_define(cgroup_controller
);
73 lxc_config_define(cgroup2_controller
);
74 lxc_config_define(cgroup_dir
);
75 lxc_config_define(cgroup_monitor_dir
);
76 lxc_config_define(cgroup_container_dir
);
77 lxc_config_define(cgroup_container_inner_dir
);
78 lxc_config_define(cgroup_relative
);
79 lxc_config_define(console_buffer_size
);
80 lxc_config_define(console_logfile
);
81 lxc_config_define(console_path
);
82 lxc_config_define(console_rotate
);
83 lxc_config_define(console_size
);
84 lxc_config_define(environment
);
85 lxc_config_define(ephemeral
);
86 lxc_config_define(execute_cmd
);
87 lxc_config_define(group
);
88 lxc_config_define(hooks
);
89 lxc_config_define(hooks_version
);
90 lxc_config_define(idmaps
);
91 lxc_config_define(includefiles
);
92 lxc_config_define(init_cmd
);
93 lxc_config_define(init_cwd
);
94 lxc_config_define(init_gid
);
95 lxc_config_define(init_uid
);
96 lxc_config_define(keyring_session
);
97 lxc_config_define(log_file
);
98 lxc_config_define(log_level
);
99 lxc_config_define(log_syslog
);
100 lxc_config_define(monitor
);
101 lxc_config_define(monitor_signal_pdeath
);
102 lxc_config_define(mount
);
103 lxc_config_define(mount_auto
);
104 lxc_config_define(mount_fstab
);
105 lxc_config_define(namespace_clone
);
106 lxc_config_define(namespace_keep
);
107 lxc_config_define(time_offset_boot
);
108 lxc_config_define(time_offset_monotonic
);
109 lxc_config_define(namespace_share
);
110 lxc_config_define(net
);
111 lxc_config_define(net_flags
);
112 lxc_config_define(net_hwaddr
);
113 lxc_config_define(net_ipv4_address
);
114 lxc_config_define(net_ipv4_gateway
);
115 lxc_config_define(net_ipv6_address
);
116 lxc_config_define(net_ipv6_gateway
);
117 lxc_config_define(net_link
);
118 lxc_config_define(net_l2proxy
);
119 lxc_config_define(net_macvlan_mode
);
120 lxc_config_define(net_ipvlan_mode
);
121 lxc_config_define(net_ipvlan_isolation
);
122 lxc_config_define(net_mtu
);
123 lxc_config_define(net_name
);
124 lxc_config_define(net_nic
);
125 lxc_config_define(net_script_down
);
126 lxc_config_define(net_script_up
);
127 lxc_config_define(net_type
);
128 lxc_config_define(net_veth_mode
);
129 lxc_config_define(net_veth_pair
);
130 lxc_config_define(net_veth_ipv4_route
);
131 lxc_config_define(net_veth_ipv6_route
);
132 lxc_config_define(net_veth_vlan_id
);
133 lxc_config_define(net_veth_vlan_tagged_id
);
134 lxc_config_define(net_vlan_id
);
135 lxc_config_define(no_new_privs
);
136 lxc_config_define(personality
);
137 lxc_config_define(prlimit
);
138 lxc_config_define(pty_max
);
139 lxc_config_define(rootfs_managed
);
140 lxc_config_define(rootfs_mount
);
141 lxc_config_define(rootfs_options
);
142 lxc_config_define(rootfs_path
);
143 lxc_config_define(seccomp_profile
);
144 lxc_config_define(seccomp_allow_nesting
);
145 lxc_config_define(seccomp_notify_cookie
);
146 lxc_config_define(seccomp_notify_proxy
);
147 lxc_config_define(selinux_context
);
148 lxc_config_define(selinux_context_keyring
);
149 lxc_config_define(signal_halt
);
150 lxc_config_define(signal_reboot
);
151 lxc_config_define(signal_stop
);
152 lxc_config_define(start
);
153 lxc_config_define(tty_max
);
154 lxc_config_define(tty_dir
);
155 lxc_config_define(uts_name
);
156 lxc_config_define(sysctl
);
157 lxc_config_define(proc
);
161 * If a new config option is added to this table, be aware that
162 * the order in which the options are places into the table matters.
163 * That means that more specific options of a namespace have to be
164 * placed above more generic ones.
166 * For instance: If lxc.ab is placed before lxc.ab.c, the config option
167 * lxc.ab.c will always be matched to lxc.ab. That is, the lxc.ab.c option
168 * has to be placed above lxc.ab.
170 static struct lxc_config_t config_jump_table
[] = {
171 { "lxc.arch", set_config_personality
, get_config_personality
, clr_config_personality
, },
172 { "lxc.apparmor.profile", set_config_apparmor_profile
, get_config_apparmor_profile
, clr_config_apparmor_profile
, },
173 { "lxc.apparmor.allow_incomplete", set_config_apparmor_allow_incomplete
, get_config_apparmor_allow_incomplete
, clr_config_apparmor_allow_incomplete
, },
174 { "lxc.apparmor.allow_nesting", set_config_apparmor_allow_nesting
, get_config_apparmor_allow_nesting
, clr_config_apparmor_allow_nesting
, },
175 { "lxc.apparmor.raw", set_config_apparmor_raw
, get_config_apparmor_raw
, clr_config_apparmor_raw
, },
176 { "lxc.autodev.tmpfs.size", set_config_autodev_tmpfs_size
, get_config_autodev_tmpfs_size
, clr_config_autodev_tmpfs_size
, },
177 { "lxc.autodev", set_config_autodev
, get_config_autodev
, clr_config_autodev
, },
178 { "lxc.cap.drop", set_config_cap_drop
, get_config_cap_drop
, clr_config_cap_drop
, },
179 { "lxc.cap.keep", set_config_cap_keep
, get_config_cap_keep
, clr_config_cap_keep
, },
180 { "lxc.cgroup2", set_config_cgroup2_controller
, get_config_cgroup2_controller
, clr_config_cgroup2_controller
, },
181 { "lxc.cgroup.dir.monitor", set_config_cgroup_monitor_dir
, get_config_cgroup_monitor_dir
, clr_config_cgroup_monitor_dir
, },
182 { "lxc.cgroup.dir.container.inner", set_config_cgroup_container_inner_dir
, get_config_cgroup_container_inner_dir
, clr_config_cgroup_container_inner_dir
, },
183 { "lxc.cgroup.dir.container", set_config_cgroup_container_dir
, get_config_cgroup_container_dir
, clr_config_cgroup_container_dir
, },
184 { "lxc.cgroup.dir", set_config_cgroup_dir
, get_config_cgroup_dir
, clr_config_cgroup_dir
, },
185 { "lxc.cgroup.relative", set_config_cgroup_relative
, get_config_cgroup_relative
, clr_config_cgroup_relative
, },
186 { "lxc.cgroup", set_config_cgroup_controller
, get_config_cgroup_controller
, clr_config_cgroup_controller
, },
187 { "lxc.console.buffer.size", set_config_console_buffer_size
, get_config_console_buffer_size
, clr_config_console_buffer_size
, },
188 { "lxc.console.logfile", set_config_console_logfile
, get_config_console_logfile
, clr_config_console_logfile
, },
189 { "lxc.console.path", set_config_console_path
, get_config_console_path
, clr_config_console_path
, },
190 { "lxc.console.rotate", set_config_console_rotate
, get_config_console_rotate
, clr_config_console_rotate
, },
191 { "lxc.console.size", set_config_console_size
, get_config_console_size
, clr_config_console_size
, },
192 { "lxc.environment", set_config_environment
, get_config_environment
, clr_config_environment
, },
193 { "lxc.ephemeral", set_config_ephemeral
, get_config_ephemeral
, clr_config_ephemeral
, },
194 { "lxc.execute.cmd", set_config_execute_cmd
, get_config_execute_cmd
, clr_config_execute_cmd
, },
195 { "lxc.group", set_config_group
, get_config_group
, clr_config_group
, },
196 { "lxc.hook.autodev", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
197 { "lxc.hook.clone", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
198 { "lxc.hook.destroy", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
199 { "lxc.hook.mount", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
200 { "lxc.hook.post-stop", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
201 { "lxc.hook.pre-mount", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
202 { "lxc.hook.pre-start", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
203 { "lxc.hook.start", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
204 { "lxc.hook.start-host", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
205 { "lxc.hook.stop", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
206 { "lxc.hook.version", set_config_hooks_version
, get_config_hooks_version
, clr_config_hooks_version
, },
207 { "lxc.hook", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
208 { "lxc.idmap", set_config_idmaps
, get_config_idmaps
, clr_config_idmaps
, },
209 { "lxc.include", set_config_includefiles
, get_config_includefiles
, clr_config_includefiles
, },
210 { "lxc.init.cmd", set_config_init_cmd
, get_config_init_cmd
, clr_config_init_cmd
, },
211 { "lxc.init.gid", set_config_init_gid
, get_config_init_gid
, clr_config_init_gid
, },
212 { "lxc.init.uid", set_config_init_uid
, get_config_init_uid
, clr_config_init_uid
, },
213 { "lxc.init.cwd", set_config_init_cwd
, get_config_init_cwd
, clr_config_init_cwd
, },
214 { "lxc.keyring.session", set_config_keyring_session
, get_config_keyring_session
, clr_config_keyring_session
},
215 { "lxc.log.file", set_config_log_file
, get_config_log_file
, clr_config_log_file
, },
216 { "lxc.log.level", set_config_log_level
, get_config_log_level
, clr_config_log_level
, },
217 { "lxc.log.syslog", set_config_log_syslog
, get_config_log_syslog
, clr_config_log_syslog
, },
218 { "lxc.monitor.unshare", set_config_monitor
, get_config_monitor
, clr_config_monitor
, },
219 { "lxc.monitor.signal.pdeath", set_config_monitor_signal_pdeath
, get_config_monitor_signal_pdeath
, clr_config_monitor_signal_pdeath
, },
220 { "lxc.mount.auto", set_config_mount_auto
, get_config_mount_auto
, clr_config_mount_auto
, },
221 { "lxc.mount.entry", set_config_mount
, get_config_mount
, clr_config_mount
, },
222 { "lxc.mount.fstab", set_config_mount_fstab
, get_config_mount_fstab
, clr_config_mount_fstab
, },
223 { "lxc.namespace.clone", set_config_namespace_clone
, get_config_namespace_clone
, clr_config_namespace_clone
, },
224 { "lxc.namespace.keep", set_config_namespace_keep
, get_config_namespace_keep
, clr_config_namespace_keep
, },
225 { "lxc.namespace.share", set_config_namespace_share
, get_config_namespace_share
, clr_config_namespace_share
, },
226 { "lxc.time.offset.boot", set_config_time_offset_boot
, get_config_time_offset_boot
, clr_config_time_offset_boot
, },
227 { "lxc.time.offset.monotonic", set_config_time_offset_monotonic
, get_config_time_offset_monotonic
, clr_config_time_offset_monotonic
, },
228 { "lxc.net.flags", set_config_net_flags
, get_config_net_flags
, clr_config_net_flags
, },
229 { "lxc.net.hwaddr", set_config_net_hwaddr
, get_config_net_hwaddr
, clr_config_net_hwaddr
, },
230 { "lxc.net.ipv4.address", set_config_net_ipv4_address
, get_config_net_ipv4_address
, clr_config_net_ipv4_address
, },
231 { "lxc.net.ipv4.gateway", set_config_net_ipv4_gateway
, get_config_net_ipv4_gateway
, clr_config_net_ipv4_gateway
, },
232 { "lxc.net.ipv6.address", set_config_net_ipv6_address
, get_config_net_ipv6_address
, clr_config_net_ipv6_address
, },
233 { "lxc.net.ipv6.gateway", set_config_net_ipv6_gateway
, get_config_net_ipv6_gateway
, clr_config_net_ipv6_gateway
, },
234 { "lxc.net.link", set_config_net_link
, get_config_net_link
, clr_config_net_link
, },
235 { "lxc.net.l2proxy", set_config_net_l2proxy
, get_config_net_l2proxy
, clr_config_net_l2proxy
, },
236 { "lxc.net.macvlan.mode", set_config_net_macvlan_mode
, get_config_net_macvlan_mode
, clr_config_net_macvlan_mode
, },
237 { "lxc.net.ipvlan.mode", set_config_net_ipvlan_mode
, get_config_net_ipvlan_mode
, clr_config_net_ipvlan_mode
, },
238 { "lxc.net.ipvlan.isolation", set_config_net_ipvlan_isolation
, get_config_net_ipvlan_isolation
, clr_config_net_ipvlan_isolation
, },
239 { "lxc.net.mtu", set_config_net_mtu
, get_config_net_mtu
, clr_config_net_mtu
, },
240 { "lxc.net.name", set_config_net_name
, get_config_net_name
, clr_config_net_name
, },
241 { "lxc.net.script.down", set_config_net_script_down
, get_config_net_script_down
, clr_config_net_script_down
, },
242 { "lxc.net.script.up", set_config_net_script_up
, get_config_net_script_up
, clr_config_net_script_up
, },
243 { "lxc.net.type", set_config_net_type
, get_config_net_type
, clr_config_net_type
, },
244 { "lxc.net.vlan.id", set_config_net_vlan_id
, get_config_net_vlan_id
, clr_config_net_vlan_id
, },
245 { "lxc.net.veth.mode", set_config_net_veth_mode
, get_config_net_veth_mode
, clr_config_net_veth_mode
, },
246 { "lxc.net.veth.pair", set_config_net_veth_pair
, get_config_net_veth_pair
, clr_config_net_veth_pair
, },
247 { "lxc.net.veth.ipv4.route", set_config_net_veth_ipv4_route
, get_config_net_veth_ipv4_route
, clr_config_net_veth_ipv4_route
, },
248 { "lxc.net.veth.ipv6.route", set_config_net_veth_ipv6_route
, get_config_net_veth_ipv6_route
, clr_config_net_veth_ipv6_route
, },
249 { "lxc.net.veth.vlan.id", set_config_net_veth_vlan_id
, get_config_net_veth_vlan_id
, clr_config_net_veth_vlan_id
, },
250 { "lxc.net.veth.vlan.tagged.id", set_config_net_veth_vlan_tagged_id
, get_config_net_veth_vlan_tagged_id
, clr_config_net_veth_vlan_tagged_id
, },
251 { "lxc.net.", set_config_net_nic
, get_config_net_nic
, clr_config_net_nic
, },
252 { "lxc.net", set_config_net
, get_config_net
, clr_config_net
, },
253 { "lxc.no_new_privs", set_config_no_new_privs
, get_config_no_new_privs
, clr_config_no_new_privs
, },
254 { "lxc.prlimit", set_config_prlimit
, get_config_prlimit
, clr_config_prlimit
, },
255 { "lxc.pty.max", set_config_pty_max
, get_config_pty_max
, clr_config_pty_max
, },
256 { "lxc.rootfs.managed", set_config_rootfs_managed
, get_config_rootfs_managed
, clr_config_rootfs_managed
, },
257 { "lxc.rootfs.mount", set_config_rootfs_mount
, get_config_rootfs_mount
, clr_config_rootfs_mount
, },
258 { "lxc.rootfs.options", set_config_rootfs_options
, get_config_rootfs_options
, clr_config_rootfs_options
, },
259 { "lxc.rootfs.path", set_config_rootfs_path
, get_config_rootfs_path
, clr_config_rootfs_path
, },
260 { "lxc.seccomp.allow_nesting", set_config_seccomp_allow_nesting
, get_config_seccomp_allow_nesting
, clr_config_seccomp_allow_nesting
, },
261 { "lxc.seccomp.notify.cookie", set_config_seccomp_notify_cookie
, get_config_seccomp_notify_cookie
, clr_config_seccomp_notify_cookie
, },
262 { "lxc.seccomp.notify.proxy", set_config_seccomp_notify_proxy
, get_config_seccomp_notify_proxy
, clr_config_seccomp_notify_proxy
, },
263 { "lxc.seccomp.profile", set_config_seccomp_profile
, get_config_seccomp_profile
, clr_config_seccomp_profile
, },
264 { "lxc.selinux.context.keyring", set_config_selinux_context_keyring
, get_config_selinux_context_keyring
, clr_config_selinux_context_keyring
},
265 { "lxc.selinux.context", set_config_selinux_context
, get_config_selinux_context
, clr_config_selinux_context
, },
266 { "lxc.signal.halt", set_config_signal_halt
, get_config_signal_halt
, clr_config_signal_halt
, },
267 { "lxc.signal.reboot", set_config_signal_reboot
, get_config_signal_reboot
, clr_config_signal_reboot
, },
268 { "lxc.signal.stop", set_config_signal_stop
, get_config_signal_stop
, clr_config_signal_stop
, },
269 { "lxc.start.auto", set_config_start
, get_config_start
, clr_config_start
, },
270 { "lxc.start.delay", set_config_start
, get_config_start
, clr_config_start
, },
271 { "lxc.start.order", set_config_start
, get_config_start
, clr_config_start
, },
272 { "lxc.tty.dir", set_config_tty_dir
, get_config_tty_dir
, clr_config_tty_dir
, },
273 { "lxc.tty.max", set_config_tty_max
, get_config_tty_max
, clr_config_tty_max
, },
274 { "lxc.uts.name", set_config_uts_name
, get_config_uts_name
, clr_config_uts_name
, },
275 { "lxc.sysctl", set_config_sysctl
, get_config_sysctl
, clr_config_sysctl
, },
276 { "lxc.proc", set_config_proc
, get_config_proc
, clr_config_proc
, },
279 static const size_t config_jump_table_size
= sizeof(config_jump_table
) / sizeof(struct lxc_config_t
);
281 struct lxc_config_t
*lxc_get_config_exact(const char *key
)
285 for (i
= 0; i
< config_jump_table_size
; i
++)
286 if (!strcmp(config_jump_table
[i
].name
, key
))
287 return &config_jump_table
[i
];
293 struct lxc_config_t
*lxc_get_config(const char *key
)
297 for (i
= 0; i
< config_jump_table_size
; i
++)
298 if (!strncmp(config_jump_table
[i
].name
, key
, strlen(config_jump_table
[i
].name
)))
299 return &config_jump_table
[i
];
304 static int set_config_net(const char *key
, const char *value
,
305 struct lxc_conf
*lxc_conf
, void *data
)
307 if (!lxc_config_value_empty(value
)) {
308 ERROR("lxc.net must not have a value");
312 return clr_config_net(key
, lxc_conf
, data
);
315 static int set_config_net_type(const char *key
, const char *value
,
316 struct lxc_conf
*lxc_conf
, void *data
)
318 struct lxc_netdev
*netdev
= data
;
320 if (lxc_config_value_empty(value
))
321 return clr_config_net_type(key
, lxc_conf
, data
);
326 if (strcmp(value
, "veth") == 0) {
327 netdev
->type
= LXC_NET_VETH
;
328 lxc_list_init(&netdev
->priv
.veth_attr
.ipv4_routes
);
329 lxc_list_init(&netdev
->priv
.veth_attr
.ipv6_routes
);
330 lxc_list_init(&netdev
->priv
.veth_attr
.vlan_tagged_ids
);
331 if (!lxc_veth_flag_to_mode(netdev
->priv
.veth_attr
.mode
))
332 lxc_veth_mode_to_flag(&netdev
->priv
.veth_attr
.mode
, "bridge");
333 } else if (strcmp(value
, "macvlan") == 0) {
334 netdev
->type
= LXC_NET_MACVLAN
;
335 if (!lxc_macvlan_flag_to_mode(netdev
->priv
.veth_attr
.mode
))
336 lxc_macvlan_mode_to_flag(&netdev
->priv
.macvlan_attr
.mode
, "private");
337 } else if (strcmp(value
, "ipvlan") == 0) {
338 netdev
->type
= LXC_NET_IPVLAN
;
339 if (!lxc_ipvlan_flag_to_mode(netdev
->priv
.ipvlan_attr
.mode
))
340 lxc_ipvlan_mode_to_flag(&netdev
->priv
.ipvlan_attr
.mode
, "l3");
341 if (!lxc_ipvlan_flag_to_isolation(netdev
->priv
.ipvlan_attr
.isolation
))
342 lxc_ipvlan_isolation_to_flag(&netdev
->priv
.ipvlan_attr
.isolation
, "bridge");
343 } else if (strcmp(value
, "vlan") == 0) {
344 netdev
->type
= LXC_NET_VLAN
;
345 } else if (strcmp(value
, "phys") == 0) {
346 netdev
->type
= LXC_NET_PHYS
;
347 } else if (strcmp(value
, "empty") == 0) {
348 netdev
->type
= LXC_NET_EMPTY
;
349 } else if (strcmp(value
, "none") == 0) {
350 netdev
->type
= LXC_NET_NONE
;
352 ERROR("Invalid network type %s", value
);
359 static int set_config_net_flags(const char *key
, const char *value
,
360 struct lxc_conf
*lxc_conf
, void *data
)
362 struct lxc_netdev
*netdev
= data
;
364 if (lxc_config_value_empty(value
))
365 return clr_config_net_flags(key
, lxc_conf
, data
);
370 netdev
->flags
|= IFF_UP
;
375 static int create_matched_ifnames(const char *value
, struct lxc_conf
*lxc_conf
,
376 struct lxc_netdev
*netdev
)
378 struct netns_ifaddrs
*ifaddr
, *ifa
;
381 const char *type_key
= "lxc.net.type";
382 const char *link_key
= "lxc.net.link";
383 const char *tmpvalue
= "phys";
385 if (netns_getifaddrs(&ifaddr
, -1, &(bool){false}) < 0) {
386 SYSERROR("Failed to get network interfaces");
390 for (ifa
= ifaddr
, n
= 0; ifa
!= NULL
; ifa
= ifa
->ifa_next
, n
++) {
394 if (ifa
->ifa_addr
->sa_family
!= AF_PACKET
)
397 if (!strncmp(value
, ifa
->ifa_name
, strlen(value
) - 1)) {
398 ret
= set_config_net_type(type_key
, tmpvalue
, lxc_conf
,
401 ret
= set_config_net_link(
402 link_key
, ifa
->ifa_name
, lxc_conf
, netdev
);
404 ERROR("Failed to create matched ifnames");
408 ERROR("Failed to create matched ifnames");
414 netns_freeifaddrs(ifaddr
);
420 static int set_config_net_link(const char *key
, const char *value
,
421 struct lxc_conf
*lxc_conf
, void *data
)
423 struct lxc_netdev
*netdev
= data
;
426 if (lxc_config_value_empty(value
))
427 return clr_config_net_link(key
, lxc_conf
, data
);
432 if (value
[strlen(value
) - 1] == '+' && netdev
->type
== LXC_NET_PHYS
)
433 ret
= create_matched_ifnames(value
, lxc_conf
, netdev
);
435 ret
= network_ifname(netdev
->link
, value
, sizeof(netdev
->link
));
440 static int set_config_net_l2proxy(const char *key
, const char *value
,
441 struct lxc_conf
*lxc_conf
, void *data
)
443 struct lxc_netdev
*netdev
= data
;
444 unsigned int val
= 0;
447 if (lxc_config_value_empty(value
))
448 return clr_config_net_l2proxy(key
, lxc_conf
, data
);
451 return ret_set_errno(-1, EINVAL
);
453 ret
= lxc_safe_uint(value
, &val
);
455 return ret_set_errno(-1, -ret
);
459 netdev
->l2proxy
= false;
462 netdev
->l2proxy
= true;
466 return ret_set_errno(-1, EINVAL
);
469 static int set_config_net_name(const char *key
, const char *value
,
470 struct lxc_conf
*lxc_conf
, void *data
)
472 struct lxc_netdev
*netdev
= data
;
474 if (lxc_config_value_empty(value
))
475 return clr_config_net_name(key
, lxc_conf
, data
);
480 return network_ifname(netdev
->name
, value
, sizeof(netdev
->name
));
484 static int set_config_net_veth_mode(const char *key
, const char *value
,
485 struct lxc_conf
*lxc_conf
, void *data
)
487 struct lxc_netdev
*netdev
= data
;
489 if (lxc_config_value_empty(value
))
490 return clr_config_net_veth_mode(key
, lxc_conf
, data
);
495 return lxc_veth_mode_to_flag(&netdev
->priv
.veth_attr
.mode
, value
);
498 static int set_config_net_veth_pair(const char *key
, const char *value
,
499 struct lxc_conf
*lxc_conf
, void *data
)
501 struct lxc_netdev
*netdev
= data
;
503 if (lxc_config_value_empty(value
))
504 return clr_config_net_veth_pair(key
, lxc_conf
, data
);
509 return network_ifname(netdev
->priv
.veth_attr
.pair
, value
, sizeof(netdev
->priv
.veth_attr
.pair
));
512 static int set_config_net_veth_vlan_id(const char *key
, const char *value
,
513 struct lxc_conf
*lxc_conf
, void *data
)
516 struct lxc_netdev
*netdev
= data
;
519 return ret_errno(EINVAL
);
521 if (lxc_config_value_empty(value
))
522 return clr_config_net_veth_vlan_id(key
, lxc_conf
, data
);
524 if (strcmp(value
, "none") == 0) {
525 netdev
->priv
.veth_attr
.vlan_id
= BRIDGE_VLAN_NONE
;
527 unsigned short vlan_id
;
528 ret
= get_u16(&vlan_id
, value
, 0);
530 return ret_errno(EINVAL
);
532 if (vlan_id
> BRIDGE_VLAN_ID_MAX
)
533 return ret_errno(EINVAL
);
535 netdev
->priv
.veth_attr
.vlan_id
= vlan_id
;
538 netdev
->priv
.veth_attr
.vlan_id_set
= true;
542 static int set_config_net_veth_vlan_tagged_id(const char *key
, const char *value
,
543 struct lxc_conf
*lxc_conf
, void *data
)
545 __do_free
struct lxc_list
*list
= NULL
;
547 unsigned short vlan_id
;
548 struct lxc_netdev
*netdev
= data
;
551 return ret_errno(EINVAL
);
553 if (lxc_config_value_empty(value
))
554 return clr_config_net_veth_vlan_tagged_id(key
, lxc_conf
, data
);
556 ret
= get_u16(&vlan_id
, value
, 0);
560 if (vlan_id
> BRIDGE_VLAN_ID_MAX
)
563 list
= malloc(sizeof(*list
));
565 return ret_errno(ENOMEM
);
568 list
->elem
= UINT_TO_PTR(vlan_id
);
570 lxc_list_add_tail(&netdev
->priv
.veth_attr
.vlan_tagged_ids
, move_ptr(list
));
575 static int set_config_net_macvlan_mode(const char *key
, const char *value
,
576 struct lxc_conf
*lxc_conf
, void *data
)
578 struct lxc_netdev
*netdev
= data
;
580 if (lxc_config_value_empty(value
))
581 return clr_config_net_macvlan_mode(key
, lxc_conf
, data
);
586 return lxc_macvlan_mode_to_flag(&netdev
->priv
.macvlan_attr
.mode
, value
);
589 static int set_config_net_ipvlan_mode(const char *key
, const char *value
,
590 struct lxc_conf
*lxc_conf
, void *data
)
592 struct lxc_netdev
*netdev
= data
;
594 if (lxc_config_value_empty(value
))
595 return clr_config_net_ipvlan_mode(key
, lxc_conf
, data
);
598 return ret_set_errno(-1, EINVAL
);
600 if (netdev
->type
!= LXC_NET_IPVLAN
) {
601 SYSERROR("Invalid ipvlan mode \"%s\", can only be used with ipvlan network", value
);
602 return ret_set_errno(-1, EINVAL
);
605 return lxc_ipvlan_mode_to_flag(&netdev
->priv
.ipvlan_attr
.mode
, value
);
608 static int set_config_net_ipvlan_isolation(const char *key
, const char *value
,
609 struct lxc_conf
*lxc_conf
, void *data
)
611 struct lxc_netdev
*netdev
= data
;
613 if (lxc_config_value_empty(value
))
614 return clr_config_net_ipvlan_isolation(key
, lxc_conf
, data
);
617 return ret_set_errno(-1, EINVAL
);
619 if (netdev
->type
!= LXC_NET_IPVLAN
) {
620 SYSERROR("Invalid ipvlan isolation \"%s\", can only be used with ipvlan network", value
);
621 return ret_set_errno(-1, EINVAL
);
624 return lxc_ipvlan_isolation_to_flag(&netdev
->priv
.ipvlan_attr
.isolation
, value
);
627 static int set_config_net_hwaddr(const char *key
, const char *value
,
628 struct lxc_conf
*lxc_conf
, void *data
)
630 struct lxc_netdev
*netdev
= data
;
633 if (lxc_config_value_empty(value
))
634 return clr_config_net_hwaddr(key
, lxc_conf
, data
);
639 new_value
= strdup(value
);
643 rand_complete_hwaddr(new_value
);
645 if (lxc_config_value_empty(new_value
)) {
647 netdev
->hwaddr
= NULL
;
651 netdev
->hwaddr
= new_value
;
656 static int set_config_net_vlan_id(const char *key
, const char *value
,
657 struct lxc_conf
*lxc_conf
, void *data
)
660 struct lxc_netdev
*netdev
= data
;
662 if (lxc_config_value_empty(value
))
663 return clr_config_net_vlan_id(key
, lxc_conf
, data
);
668 ret
= get_u16(&netdev
->priv
.vlan_attr
.vid
, value
, 0);
675 static int set_config_net_mtu(const char *key
, const char *value
,
676 struct lxc_conf
*lxc_conf
, void *data
)
678 struct lxc_netdev
*netdev
= data
;
680 if (lxc_config_value_empty(value
))
681 return clr_config_net_mtu(key
, lxc_conf
, data
);
686 return set_config_string_item(&netdev
->mtu
, value
);
689 static int set_config_net_ipv4_address(const char *key
, const char *value
,
690 struct lxc_conf
*lxc_conf
, void *data
)
693 struct lxc_netdev
*netdev
= data
;
694 struct lxc_inetdev
*inetdev
;
695 struct lxc_list
*list
;
696 char *cursor
, *slash
;
697 char *addr
= NULL
, *bcast
= NULL
, *prefix
= NULL
;
699 if (lxc_config_value_empty(value
))
700 return clr_config_net_ipv4_address(key
, lxc_conf
, data
);
705 inetdev
= malloc(sizeof(*inetdev
));
708 memset(inetdev
, 0, sizeof(*inetdev
));
710 list
= malloc(sizeof(*list
));
717 list
->elem
= inetdev
;
719 addr
= strdup(value
);
726 cursor
= strstr(addr
, " ");
732 slash
= strstr(addr
, "/");
738 ret
= inet_pton(AF_INET
, addr
, &inetdev
->addr
);
739 if (!ret
|| ret
< 0) {
740 SYSERROR("Invalid ipv4 address \"%s\"", value
);
748 ret
= inet_pton(AF_INET
, bcast
, &inetdev
->bcast
);
749 if (!ret
|| ret
< 0) {
750 SYSERROR("Invalid ipv4 broadcast address \"%s\"", value
);
759 /* No prefix specified, determine it from the network class. */
761 ret
= lxc_safe_uint(prefix
, &inetdev
->prefix
);
769 inetdev
->prefix
= config_ip_prefix(&inetdev
->addr
);
772 /* If no broadcast address, let compute one from the
773 * prefix and address.
776 inetdev
->bcast
.s_addr
= inetdev
->addr
.s_addr
;
777 inetdev
->bcast
.s_addr
|= htonl(INADDR_BROADCAST
>> inetdev
->prefix
);
780 lxc_list_add_tail(&netdev
->ipv4
, list
);
786 static int set_config_net_ipv4_gateway(const char *key
, const char *value
,
787 struct lxc_conf
*lxc_conf
, void *data
)
789 struct lxc_netdev
*netdev
= data
;
791 if (lxc_config_value_empty(value
))
792 return clr_config_net_ipv4_gateway(key
, lxc_conf
, data
);
797 free(netdev
->ipv4_gateway
);
799 if (strcmp(value
, "auto") == 0) {
800 netdev
->ipv4_gateway
= NULL
;
801 netdev
->ipv4_gateway_auto
= true;
802 } else if (strcmp(value
, "dev") == 0) {
803 netdev
->ipv4_gateway
= NULL
;
804 netdev
->ipv4_gateway_auto
= false;
805 netdev
->ipv4_gateway_dev
= true;
810 gw
= malloc(sizeof(*gw
));
814 ret
= inet_pton(AF_INET
, value
, gw
);
815 if (!ret
|| ret
< 0) {
816 SYSERROR("Invalid ipv4 gateway address \"%s\"", value
);
821 netdev
->ipv4_gateway
= gw
;
822 netdev
->ipv4_gateway_auto
= false;
828 static int set_config_net_veth_ipv4_route(const char *key
, const char *value
,
829 struct lxc_conf
*lxc_conf
, void *data
)
831 __do_free
char *valdup
= NULL
;
832 __do_free
struct lxc_inetdev
*inetdev
= NULL
;
833 __do_free
struct lxc_list
*list
= NULL
;
835 char *netmask
, *slash
;
836 struct lxc_netdev
*netdev
= data
;
838 if (lxc_config_value_empty(value
))
839 return clr_config_net_veth_ipv4_route(key
, lxc_conf
, data
);
842 return ret_set_errno(-1, EINVAL
);
844 if (netdev
->type
!= LXC_NET_VETH
) {
845 SYSERROR("Invalid ipv4 route \"%s\", can only be used with veth network", value
);
846 return ret_set_errno(-1, EINVAL
);
849 inetdev
= malloc(sizeof(*inetdev
));
852 memset(inetdev
, 0, sizeof(*inetdev
));
854 list
= malloc(sizeof(*list
));
859 list
->elem
= inetdev
;
861 valdup
= strdup(value
);
865 slash
= strchr(valdup
, '/');
867 return ret_set_errno(-1, EINVAL
);
872 return ret_set_errno(-1, EINVAL
);
876 ret
= lxc_safe_uint(netmask
, &inetdev
->prefix
);
877 if (ret
< 0 || inetdev
->prefix
> 32)
878 return ret_set_errno(-1, EINVAL
);
880 ret
= inet_pton(AF_INET
, valdup
, &inetdev
->addr
);
882 return ret_set_errno(-1, EINVAL
);
884 lxc_list_add_tail(&netdev
->priv
.veth_attr
.ipv4_routes
, list
);
891 static int set_config_net_ipv6_address(const char *key
, const char *value
,
892 struct lxc_conf
*lxc_conf
, void *data
)
895 struct lxc_netdev
*netdev
= data
;
896 struct lxc_inet6dev
*inet6dev
;
897 struct lxc_list
*list
;
898 char *slash
, *valdup
, *netmask
;
900 if (lxc_config_value_empty(value
))
901 return clr_config_net_ipv6_address(key
, lxc_conf
, data
);
906 inet6dev
= malloc(sizeof(*inet6dev
));
909 memset(inet6dev
, 0, sizeof(*inet6dev
));
911 list
= malloc(sizeof(*list
));
918 list
->elem
= inet6dev
;
920 valdup
= strdup(value
);
927 inet6dev
->prefix
= 64;
928 slash
= strstr(valdup
, "/");
933 ret
= lxc_safe_uint(netmask
, &inet6dev
->prefix
);
942 ret
= inet_pton(AF_INET6
, valdup
, &inet6dev
->addr
);
943 if (!ret
|| ret
< 0) {
944 SYSERROR("Invalid ipv6 address \"%s\"", valdup
);
951 lxc_list_add_tail(&netdev
->ipv6
, list
);
957 static int set_config_net_ipv6_gateway(const char *key
, const char *value
,
958 struct lxc_conf
*lxc_conf
, void *data
)
960 struct lxc_netdev
*netdev
= data
;
962 if (lxc_config_value_empty(value
))
963 return clr_config_net_ipv6_gateway(key
, lxc_conf
, data
);
968 free(netdev
->ipv6_gateway
);
970 if (strcmp(value
, "auto") == 0) {
971 netdev
->ipv6_gateway
= NULL
;
972 netdev
->ipv6_gateway_auto
= true;
973 } else if (strcmp(value
, "dev") == 0) {
974 netdev
->ipv6_gateway
= NULL
;
975 netdev
->ipv6_gateway_auto
= false;
976 netdev
->ipv6_gateway_dev
= true;
981 gw
= malloc(sizeof(*gw
));
985 ret
= inet_pton(AF_INET6
, value
, gw
);
986 if (!ret
|| ret
< 0) {
987 SYSERROR("Invalid ipv6 gateway address \"%s\"", value
);
992 netdev
->ipv6_gateway
= gw
;
993 netdev
->ipv6_gateway_auto
= false;
999 static int set_config_net_veth_ipv6_route(const char *key
, const char *value
,
1000 struct lxc_conf
*lxc_conf
, void *data
)
1002 __do_free
char *valdup
= NULL
;
1003 __do_free
struct lxc_inet6dev
*inet6dev
= NULL
;
1004 __do_free
struct lxc_list
*list
= NULL
;
1006 char *netmask
, *slash
;
1007 struct lxc_netdev
*netdev
= data
;
1009 if (lxc_config_value_empty(value
))
1010 return clr_config_net_veth_ipv6_route(key
, lxc_conf
, data
);
1013 return ret_set_errno(-1, EINVAL
);
1015 if (netdev
->type
!= LXC_NET_VETH
) {
1016 SYSERROR("Invalid ipv6 route \"%s\", can only be used with veth network", value
);
1017 return ret_set_errno(-1, EINVAL
);
1020 inet6dev
= malloc(sizeof(*inet6dev
));
1023 memset(inet6dev
, 0, sizeof(*inet6dev
));
1025 list
= malloc(sizeof(*list
));
1029 lxc_list_init(list
);
1030 list
->elem
= inet6dev
;
1032 valdup
= strdup(value
);
1036 slash
= strchr(valdup
, '/');
1038 return ret_set_errno(-1, EINVAL
);
1043 return ret_set_errno(-1, EINVAL
);
1047 ret
= lxc_safe_uint(netmask
, &inet6dev
->prefix
);
1048 if (ret
< 0 || inet6dev
->prefix
> 128)
1049 return ret_set_errno(-1, EINVAL
);
1051 ret
= inet_pton(AF_INET6
, valdup
, &inet6dev
->addr
);
1052 if (!ret
|| ret
< 0)
1053 return ret_set_errno(-1, EINVAL
);
1055 lxc_list_add_tail(&netdev
->priv
.veth_attr
.ipv6_routes
, list
);
1062 static int set_config_net_script_up(const char *key
, const char *value
,
1063 struct lxc_conf
*lxc_conf
, void *data
)
1065 struct lxc_netdev
*netdev
= data
;
1067 if (lxc_config_value_empty(value
))
1068 return clr_config_net_script_up(key
, lxc_conf
, data
);
1073 return set_config_string_item(&netdev
->upscript
, value
);
1076 static int set_config_net_script_down(const char *key
, const char *value
,
1077 struct lxc_conf
*lxc_conf
, void *data
)
1079 struct lxc_netdev
*netdev
= data
;
1081 if (lxc_config_value_empty(value
))
1082 return clr_config_net_script_down(key
, lxc_conf
, data
);
1087 return set_config_string_item(&netdev
->downscript
, value
);
1090 static int add_hook(struct lxc_conf
*lxc_conf
, int which
, char *hook
)
1092 struct lxc_list
*hooklist
;
1094 hooklist
= malloc(sizeof(*hooklist
));
1100 hooklist
->elem
= hook
;
1101 lxc_list_add_tail(&lxc_conf
->hooks
[which
], hooklist
);
1106 static int set_config_seccomp_allow_nesting(const char *key
, const char *value
,
1107 struct lxc_conf
*lxc_conf
, void *data
)
1110 if (lxc_config_value_empty(value
))
1111 return clr_config_seccomp_allow_nesting(key
, lxc_conf
, NULL
);
1113 if (lxc_safe_uint(value
, &lxc_conf
->seccomp
.allow_nesting
) < 0)
1116 if (lxc_conf
->seccomp
.allow_nesting
> 1)
1117 return ret_set_errno(-1, EINVAL
);
1126 static int set_config_seccomp_notify_cookie(const char *key
, const char *value
,
1127 struct lxc_conf
*lxc_conf
, void *data
)
1129 #ifdef HAVE_SECCOMP_NOTIFY
1130 return set_config_string_item(&lxc_conf
->seccomp
.notifier
.cookie
, value
);
1132 return ret_set_errno(-1, ENOSYS
);
1136 static int set_config_seccomp_notify_proxy(const char *key
, const char *value
,
1137 struct lxc_conf
*lxc_conf
, void *data
)
1139 #ifdef HAVE_SECCOMP_NOTIFY
1142 if (lxc_config_value_empty(value
))
1143 return clr_config_seccomp_notify_proxy(key
, lxc_conf
, NULL
);
1145 if (strncmp(value
, "unix:", 5) != 0)
1146 return ret_set_errno(-1, EINVAL
);
1149 if (lxc_unix_sockaddr(&lxc_conf
->seccomp
.notifier
.proxy_addr
, offset
) < 0)
1154 return ret_set_errno(-1, ENOSYS
);
1158 static int set_config_seccomp_profile(const char *key
, const char *value
,
1159 struct lxc_conf
*lxc_conf
, void *data
)
1161 return set_config_path_item(&lxc_conf
->seccomp
.seccomp
, value
);
1164 static int set_config_execute_cmd(const char *key
, const char *value
,
1165 struct lxc_conf
*lxc_conf
, void *data
)
1167 return set_config_path_item(&lxc_conf
->execute_cmd
, value
);
1170 static int set_config_init_cmd(const char *key
, const char *value
,
1171 struct lxc_conf
*lxc_conf
, void *data
)
1173 return set_config_path_item(&lxc_conf
->init_cmd
, value
);
1176 static int set_config_init_cwd(const char *key
, const char *value
,
1177 struct lxc_conf
*lxc_conf
, void *data
)
1179 return set_config_path_item(&lxc_conf
->init_cwd
, value
);
1182 static int set_config_init_uid(const char *key
, const char *value
,
1183 struct lxc_conf
*lxc_conf
, void *data
)
1185 unsigned int init_uid
;
1187 if (lxc_config_value_empty(value
)) {
1188 lxc_conf
->init_uid
= 0;
1192 if (lxc_safe_uint(value
, &init_uid
) < 0)
1195 lxc_conf
->init_uid
= init_uid
;
1200 static int set_config_init_gid(const char *key
, const char *value
,
1201 struct lxc_conf
*lxc_conf
, void *data
)
1203 unsigned int init_gid
;
1205 if (lxc_config_value_empty(value
)) {
1206 lxc_conf
->init_gid
= 0;
1210 if (lxc_safe_uint(value
, &init_gid
) < 0)
1213 lxc_conf
->init_gid
= init_gid
;
1218 static int set_config_hooks(const char *key
, const char *value
,
1219 struct lxc_conf
*lxc_conf
, void *data
)
1223 if (lxc_config_value_empty(value
))
1224 return lxc_clear_hooks(lxc_conf
, key
);
1226 if (strcmp(key
+ 4, "hook") == 0) {
1227 ERROR("lxc.hook must not have a value");
1231 copy
= strdup(value
);
1235 if (strcmp(key
+ 9, "pre-start") == 0)
1236 return add_hook(lxc_conf
, LXCHOOK_PRESTART
, copy
);
1237 else if (strcmp(key
+ 9, "start-host") == 0)
1238 return add_hook(lxc_conf
, LXCHOOK_START_HOST
, copy
);
1239 else if (strcmp(key
+ 9, "pre-mount") == 0)
1240 return add_hook(lxc_conf
, LXCHOOK_PREMOUNT
, copy
);
1241 else if (strcmp(key
+ 9, "autodev") == 0)
1242 return add_hook(lxc_conf
, LXCHOOK_AUTODEV
, copy
);
1243 else if (strcmp(key
+ 9, "mount") == 0)
1244 return add_hook(lxc_conf
, LXCHOOK_MOUNT
, copy
);
1245 else if (strcmp(key
+ 9, "start") == 0)
1246 return add_hook(lxc_conf
, LXCHOOK_START
, copy
);
1247 else if (strcmp(key
+ 9, "stop") == 0)
1248 return add_hook(lxc_conf
, LXCHOOK_STOP
, copy
);
1249 else if (strcmp(key
+ 9, "post-stop") == 0)
1250 return add_hook(lxc_conf
, LXCHOOK_POSTSTOP
, copy
);
1251 else if (strcmp(key
+ 9, "clone") == 0)
1252 return add_hook(lxc_conf
, LXCHOOK_CLONE
, copy
);
1253 else if (strcmp(key
+ 9, "destroy") == 0)
1254 return add_hook(lxc_conf
, LXCHOOK_DESTROY
, copy
);
1261 static int set_config_hooks_version(const char *key
, const char *value
,
1262 struct lxc_conf
*lxc_conf
, void *data
)
1267 if (lxc_config_value_empty(value
))
1268 return clr_config_hooks_version(key
, lxc_conf
, NULL
);
1270 ret
= lxc_safe_uint(value
, &tmp
);
1275 ERROR("Invalid hook version specified. Currently only 0 "
1276 "(legacy) and 1 are supported");
1280 lxc_conf
->hooks_version
= tmp
;
1285 static int set_config_personality(const char *key
, const char *value
,
1286 struct lxc_conf
*lxc_conf
, void *data
)
1288 signed long personality
= lxc_config_parse_arch(value
);
1290 if (personality
>= 0)
1291 lxc_conf
->personality
= personality
;
1293 WARN("Unsupported personality \"%s\"", value
);
1298 static int set_config_pty_max(const char *key
, const char *value
,
1299 struct lxc_conf
*lxc_conf
, void *data
)
1302 unsigned int max
= 0;
1304 if (lxc_config_value_empty(value
)) {
1305 lxc_conf
->pty_max
= 0;
1309 ret
= lxc_safe_uint(value
, &max
);
1313 lxc_conf
->pty_max
= max
;
1318 /* We only need to check whether the first byte of the key after the lxc.start.
1319 * prefix matches our expectations since they fortunately all start with a
1320 * different letter. If anything was wrong with the key we would have already
1321 * noticed when the callback was called.
1323 static int set_config_start(const char *key
, const char *value
,
1324 struct lxc_conf
*lxc_conf
, void *data
)
1328 is_empty
= lxc_config_value_empty(value
);
1330 if (*(key
+ 10) == 'a') { /* lxc.start.auto */
1332 lxc_conf
->start_auto
= 0;
1336 if (lxc_safe_uint(value
, &lxc_conf
->start_auto
) < 0)
1339 if (lxc_conf
->start_auto
> 1)
1343 } else if (*(key
+ 10) == 'd') { /* lxc.start.delay */
1345 lxc_conf
->start_delay
= 0;
1349 return lxc_safe_uint(value
, &lxc_conf
->start_delay
);
1350 } else if (*(key
+ 10) == 'o') { /* lxc.start.order */
1352 lxc_conf
->start_order
= 0;
1356 return lxc_safe_int(value
, &lxc_conf
->start_order
);
1362 static int set_config_monitor(const char *key
, const char *value
,
1363 struct lxc_conf
*lxc_conf
, void *data
)
1365 if (lxc_config_value_empty(value
)) {
1366 lxc_conf
->monitor_unshare
= 0;
1370 if (strcmp(key
+ 12, "unshare") == 0)
1371 return lxc_safe_uint(value
, &lxc_conf
->monitor_unshare
);
1376 static int set_config_monitor_signal_pdeath(const char *key
, const char *value
,
1377 struct lxc_conf
*lxc_conf
, void *data
)
1379 if (lxc_config_value_empty(value
)) {
1380 lxc_conf
->monitor_signal_pdeath
= 0;
1384 if (strcmp(key
+ 12, "signal.pdeath") == 0) {
1387 sig_n
= sig_parse(value
);
1391 lxc_conf
->monitor_signal_pdeath
= sig_n
;
1398 static int set_config_group(const char *key
, const char *value
,
1399 struct lxc_conf
*lxc_conf
, void *data
)
1401 char *groups
, *token
;
1402 struct lxc_list
*grouplist
;
1405 if (lxc_config_value_empty(value
))
1406 return lxc_clear_groups(lxc_conf
);
1408 groups
= strdup(value
);
1412 /* In case several groups are specified in a single line split these
1413 * groups in a single element for the list.
1415 lxc_iterate_parts(token
, groups
, " \t") {
1416 grouplist
= malloc(sizeof(*grouplist
));
1422 grouplist
->elem
= strdup(token
);
1423 if (!grouplist
->elem
) {
1429 lxc_list_add_tail(&lxc_conf
->groups
, grouplist
);
1437 static int set_config_environment(const char *key
, const char *value
,
1438 struct lxc_conf
*lxc_conf
, void *data
)
1440 struct lxc_list
*list_item
= NULL
;
1442 if (lxc_config_value_empty(value
))
1443 return lxc_clear_environment(lxc_conf
);
1445 list_item
= malloc(sizeof(*list_item
));
1449 if (!strchr(value
, '=')) {
1450 const char *env_val
;
1451 const char *env_key
= value
;
1452 const char *env_var
[3] = {0};
1454 env_val
= getenv(env_key
);
1458 env_var
[0] = env_key
;
1459 env_var
[1] = env_val
;
1460 list_item
->elem
= lxc_string_join("=", env_var
, false);
1462 list_item
->elem
= strdup(value
);
1465 if (!list_item
->elem
)
1468 lxc_list_add_tail(&lxc_conf
->environment
, list_item
);
1478 static int set_config_tty_max(const char *key
, const char *value
,
1479 struct lxc_conf
*lxc_conf
, void *data
)
1482 unsigned int nbtty
= 0;
1484 if (lxc_config_value_empty(value
)) {
1485 lxc_conf
->ttys
.max
= 0;
1489 ret
= lxc_safe_uint(value
, &nbtty
);
1493 lxc_conf
->ttys
.max
= nbtty
;
1498 static int set_config_tty_dir(const char *key
, const char *value
,
1499 struct lxc_conf
*lxc_conf
, void *data
)
1501 return set_config_string_item_max(&lxc_conf
->ttys
.dir
, value
,
1505 static int set_config_apparmor_profile(const char *key
, const char *value
,
1506 struct lxc_conf
*lxc_conf
, void *data
)
1508 return set_config_string_item(&lxc_conf
->lsm_aa_profile
, value
);
1511 static int set_config_apparmor_allow_incomplete(const char *key
,
1513 struct lxc_conf
*lxc_conf
,
1516 if (lxc_config_value_empty(value
)) {
1517 lxc_conf
->lsm_aa_allow_incomplete
= 0;
1521 if (lxc_safe_uint(value
, &lxc_conf
->lsm_aa_allow_incomplete
) < 0)
1524 if (lxc_conf
->lsm_aa_allow_incomplete
> 1)
1530 static int set_config_apparmor_allow_nesting(const char *key
,
1532 struct lxc_conf
*lxc_conf
,
1535 if (lxc_config_value_empty(value
))
1536 return clr_config_apparmor_allow_nesting(key
, lxc_conf
, NULL
);
1538 if (lxc_safe_uint(value
, &lxc_conf
->lsm_aa_allow_nesting
) < 0)
1541 if (lxc_conf
->lsm_aa_allow_nesting
> 1)
1547 static int set_config_apparmor_raw(const char *key
,
1549 struct lxc_conf
*lxc_conf
,
1553 struct lxc_list
*list
;
1555 if (lxc_config_value_empty(value
))
1556 return lxc_clear_apparmor_raw(lxc_conf
);
1558 list
= malloc(sizeof(*list
));
1564 elem
= strdup(value
);
1571 lxc_list_add_tail(&lxc_conf
->lsm_aa_raw
, list
);
1576 static int set_config_selinux_context(const char *key
, const char *value
,
1577 struct lxc_conf
*lxc_conf
, void *data
)
1579 return set_config_string_item(&lxc_conf
->lsm_se_context
, value
);
1582 static int set_config_selinux_context_keyring(const char *key
, const char *value
,
1583 struct lxc_conf
*lxc_conf
, void *data
)
1585 return set_config_string_item(&lxc_conf
->lsm_se_keyring_context
, value
);
1588 static int set_config_keyring_session(const char *key
, const char *value
,
1589 struct lxc_conf
*lxc_conf
, void *data
)
1591 return set_config_bool_item(&lxc_conf
->keyring_disable_session
, value
, false);
1594 static int set_config_log_file(const char *key
, const char *value
,
1595 struct lxc_conf
*c
, void *data
)
1599 if (lxc_config_value_empty(value
)) {
1605 /* Store these values in the lxc_conf, and then try to set for actual
1608 ret
= set_config_path_item(&c
->logfile
, value
);
1610 ret
= lxc_log_set_file(&c
->logfd
, c
->logfile
);
1615 static int set_config_log_level(const char *key
, const char *value
,
1616 struct lxc_conf
*lxc_conf
, void *data
)
1620 if (lxc_config_value_empty(value
)) {
1621 lxc_conf
->loglevel
= LXC_LOG_LEVEL_NOTSET
;
1625 if (value
[0] >= '0' && value
[0] <= '9') {
1626 if (lxc_safe_int(value
, &newlevel
) < 0)
1629 newlevel
= lxc_log_priority_to_int(value
);
1632 /* Store these values in the lxc_conf, and then try to set for actual
1635 lxc_conf
->loglevel
= newlevel
;
1637 return lxc_log_set_level(&lxc_conf
->loglevel
, newlevel
);
1640 static int set_config_autodev(const char *key
, const char *value
,
1641 struct lxc_conf
*lxc_conf
, void *data
)
1643 if (lxc_config_value_empty(value
)) {
1644 lxc_conf
->autodev
= 0;
1648 if (lxc_safe_uint(value
, &lxc_conf
->autodev
) < 0)
1651 if (lxc_conf
->autodev
> 1)
1657 static int set_config_autodev_tmpfs_size(const char *key
, const char *value
,
1658 struct lxc_conf
*lxc_conf
, void *data
)
1660 if (lxc_config_value_empty(value
)) {
1661 lxc_conf
->autodevtmpfssize
= 500000;
1665 if (lxc_safe_int(value
, &lxc_conf
->autodevtmpfssize
) < 0)
1666 lxc_conf
->autodevtmpfssize
= 500000;
1671 static int set_config_signal_halt(const char *key
, const char *value
,
1672 struct lxc_conf
*lxc_conf
, void *data
)
1676 if (lxc_config_value_empty(value
)) {
1677 lxc_conf
->haltsignal
= 0;
1681 sig_n
= sig_parse(value
);
1685 lxc_conf
->haltsignal
= sig_n
;
1690 static int set_config_signal_reboot(const char *key
, const char *value
,
1691 struct lxc_conf
*lxc_conf
, void *data
)
1695 if (lxc_config_value_empty(value
)) {
1696 lxc_conf
->rebootsignal
= 0;
1700 sig_n
= sig_parse(value
);
1704 lxc_conf
->rebootsignal
= sig_n
;
1709 static int set_config_signal_stop(const char *key
, const char *value
,
1710 struct lxc_conf
*lxc_conf
, void *data
)
1714 if (lxc_config_value_empty(value
)) {
1715 lxc_conf
->stopsignal
= 0;
1719 sig_n
= sig_parse(value
);
1723 lxc_conf
->stopsignal
= sig_n
;
1728 static int __set_config_cgroup_controller(const char *key
, const char *value
,
1729 struct lxc_conf
*lxc_conf
, int version
)
1731 const char *subkey
, *token
;
1733 struct lxc_list
*cglist
= NULL
;
1734 struct lxc_cgroup
*cgelem
= NULL
;
1736 if (lxc_config_value_empty(value
))
1737 return lxc_clear_cgroups(lxc_conf
, key
, version
);
1739 if (version
== CGROUP2_SUPER_MAGIC
) {
1740 token
= "lxc.cgroup2.";
1742 } else if (version
== CGROUP_SUPER_MAGIC
) {
1743 token
= "lxc.cgroup.";
1749 if (strncmp(key
, token
, token_len
) != 0)
1752 subkey
= key
+ token_len
;
1753 if (*subkey
== '\0')
1756 cglist
= malloc(sizeof(*cglist
));
1760 cgelem
= malloc(sizeof(*cgelem
));
1763 memset(cgelem
, 0, sizeof(*cgelem
));
1765 cgelem
->subsystem
= strdup(subkey
);
1766 if (!cgelem
->subsystem
)
1769 cgelem
->value
= strdup(value
);
1773 cgelem
->version
= version
;
1775 lxc_list_add_elem(cglist
, cgelem
);
1777 if (version
== CGROUP2_SUPER_MAGIC
)
1778 lxc_list_add_tail(&lxc_conf
->cgroup2
, cglist
);
1780 lxc_list_add_tail(&lxc_conf
->cgroup
, cglist
);
1787 free(cgelem
->subsystem
);
1788 free(cgelem
->value
);
1795 static int set_config_cgroup_controller(const char *key
, const char *value
,
1796 struct lxc_conf
*lxc_conf
, void *data
)
1798 return __set_config_cgroup_controller(key
, value
, lxc_conf
,
1799 CGROUP_SUPER_MAGIC
);
1802 static int set_config_cgroup2_controller(const char *key
, const char *value
,
1803 struct lxc_conf
*lxc_conf
, void *data
)
1805 return __set_config_cgroup_controller(key
, value
, lxc_conf
,
1806 CGROUP2_SUPER_MAGIC
);
1810 static int set_config_cgroup_dir(const char *key
, const char *value
,
1811 struct lxc_conf
*lxc_conf
, void *data
)
1813 if (lxc_config_value_empty(value
))
1814 return clr_config_cgroup_dir(key
, lxc_conf
, NULL
);
1816 return set_config_string_item(&lxc_conf
->cgroup_meta
.dir
, value
);
1819 static int set_config_cgroup_monitor_dir(const char *key
, const char *value
,
1820 struct lxc_conf
*lxc_conf
, void *data
)
1822 if (lxc_config_value_empty(value
))
1823 return clr_config_cgroup_monitor_dir(key
, lxc_conf
, NULL
);
1825 return set_config_string_item(&lxc_conf
->cgroup_meta
.monitor_dir
,
1829 static int set_config_cgroup_container_dir(const char *key
, const char *value
,
1830 struct lxc_conf
*lxc_conf
,
1833 if (lxc_config_value_empty(value
))
1834 return clr_config_cgroup_container_dir(key
, lxc_conf
, NULL
);
1836 return set_config_string_item(&lxc_conf
->cgroup_meta
.container_dir
,
1840 static int set_config_cgroup_container_inner_dir(const char *key
,
1842 struct lxc_conf
*lxc_conf
,
1845 if (lxc_config_value_empty(value
))
1846 return clr_config_cgroup_container_inner_dir(key
, lxc_conf
, NULL
);
1848 if (strchr(value
, '/') ||
1849 strcmp(value
, ".") == 0 ||
1850 strcmp(value
, "..") == 0)
1851 return log_error_errno(-EINVAL
, EINVAL
, "lxc.cgroup.dir.container.inner must be a single directory name");
1853 return set_config_string_item(&lxc_conf
->cgroup_meta
.namespace_dir
, value
);
1856 static int set_config_cgroup_relative(const char *key
, const char *value
,
1857 struct lxc_conf
*lxc_conf
, void *data
)
1859 unsigned int converted
;
1862 if (lxc_config_value_empty(value
))
1863 return clr_config_cgroup_relative(key
, lxc_conf
, NULL
);
1865 ret
= lxc_safe_uint(value
, &converted
);
1869 if (converted
== 1) {
1870 lxc_conf
->cgroup_meta
.relative
= true;
1874 if (converted
== 0) {
1875 lxc_conf
->cgroup_meta
.relative
= false;
1882 static bool parse_limit_value(const char **value
, rlim_t
*res
)
1884 char *endptr
= NULL
;
1886 if (strncmp(*value
, "unlimited", STRLITERALLEN("unlimited")) == 0) {
1887 *res
= RLIM_INFINITY
;
1888 *value
+= STRLITERALLEN("unlimited");
1893 *res
= strtoull(*value
, &endptr
, 10);
1894 if (errno
|| !endptr
)
1902 static int set_config_prlimit(const char *key
, const char *value
,
1903 struct lxc_conf
*lxc_conf
, void *data
)
1905 struct lxc_list
*iter
;
1906 struct rlimit limit
;
1908 struct lxc_list
*limlist
= NULL
;
1909 struct lxc_limit
*limelem
= NULL
;
1911 if (lxc_config_value_empty(value
))
1912 return lxc_clear_limits(lxc_conf
, key
);
1914 if (strncmp(key
, "lxc.prlimit.", STRLITERALLEN("lxc.prlimit.")) != 0)
1917 key
+= STRLITERALLEN("lxc.prlimit.");
1919 /* soft limit comes first in the value */
1920 if (!parse_limit_value(&value
, &limit_value
))
1923 limit
.rlim_cur
= limit_value
;
1925 /* skip spaces and a colon */
1926 while (isspace(*value
))
1931 else if (*value
) /* any other character is an error here */
1934 while (isspace(*value
))
1937 /* optional hard limit */
1939 if (!parse_limit_value(&value
, &limit_value
))
1942 limit
.rlim_max
= limit_value
;
1944 /* check for trailing garbage */
1945 while (isspace(*value
))
1951 /* a single value sets both hard and soft limit */
1952 limit
.rlim_max
= limit
.rlim_cur
;
1955 /* find existing list element */
1956 lxc_list_for_each(iter
, &lxc_conf
->limits
) {
1957 limelem
= iter
->elem
;
1958 if (!strcmp(key
, limelem
->resource
)) {
1959 limelem
->limit
= limit
;
1964 /* allocate list element */
1965 limlist
= malloc(sizeof(*limlist
));
1969 limelem
= malloc(sizeof(*limelem
));
1972 memset(limelem
, 0, sizeof(*limelem
));
1974 limelem
->resource
= strdup(key
);
1975 if (!limelem
->resource
)
1978 limelem
->limit
= limit
;
1979 lxc_list_add_elem(limlist
, limelem
);;
1980 lxc_list_add_tail(&lxc_conf
->limits
, limlist
);
1988 free(limelem
->resource
);
1995 static int set_config_sysctl(const char *key
, const char *value
,
1996 struct lxc_conf
*lxc_conf
, void *data
)
1998 struct lxc_list
*iter
;
1999 char *replace_value
= NULL
;
2000 struct lxc_list
*sysctl_list
= NULL
;
2001 struct lxc_sysctl
*sysctl_elem
= NULL
;
2003 if (lxc_config_value_empty(value
))
2004 return clr_config_sysctl(key
, lxc_conf
, NULL
);
2006 if (strncmp(key
, "lxc.sysctl.", STRLITERALLEN("lxc.sysctl.")) != 0)
2009 key
+= STRLITERALLEN("lxc.sysctl.");
2011 /* find existing list element */
2012 lxc_list_for_each(iter
, &lxc_conf
->sysctls
) {
2013 sysctl_elem
= iter
->elem
;
2015 if (strcmp(key
, sysctl_elem
->key
) != 0)
2018 replace_value
= strdup(value
);
2022 free(sysctl_elem
->value
);
2023 sysctl_elem
->value
= replace_value
;
2028 /* allocate list element */
2029 sysctl_list
= malloc(sizeof(*sysctl_list
));
2033 sysctl_elem
= malloc(sizeof(*sysctl_elem
));
2036 memset(sysctl_elem
, 0, sizeof(*sysctl_elem
));
2038 sysctl_elem
->key
= strdup(key
);
2039 if (!sysctl_elem
->key
)
2042 sysctl_elem
->value
= strdup(value
);
2043 if (!sysctl_elem
->value
)
2046 lxc_list_add_elem(sysctl_list
, sysctl_elem
);
2047 lxc_list_add_tail(&lxc_conf
->sysctls
, sysctl_list
);
2055 free(sysctl_elem
->key
);
2056 free(sysctl_elem
->value
);
2063 static int set_config_proc(const char *key
, const char *value
,
2064 struct lxc_conf
*lxc_conf
, void *data
)
2067 struct lxc_list
*proclist
= NULL
;
2068 struct lxc_proc
*procelem
= NULL
;
2070 if (lxc_config_value_empty(value
))
2071 return clr_config_proc(key
, lxc_conf
, NULL
);
2073 if (strncmp(key
, "lxc.proc.", STRLITERALLEN("lxc.proc.")) != 0)
2076 subkey
= key
+ STRLITERALLEN("lxc.proc.");
2077 if (*subkey
== '\0')
2080 proclist
= malloc(sizeof(*proclist
));
2084 procelem
= malloc(sizeof(*procelem
));
2087 memset(procelem
, 0, sizeof(*procelem
));
2089 procelem
->filename
= strdup(subkey
);
2090 procelem
->value
= strdup(value
);
2092 if (!procelem
->filename
|| !procelem
->value
)
2095 proclist
->elem
= procelem
;
2097 lxc_list_add_tail(&lxc_conf
->procs
, proclist
);
2105 free(procelem
->filename
);
2106 free(procelem
->value
);
2113 static int set_config_idmaps(const char *key
, const char *value
,
2114 struct lxc_conf
*lxc_conf
, void *data
)
2116 unsigned long hostid
, nsid
, range
;
2119 struct lxc_list
*idmaplist
= NULL
;
2120 struct id_map
*idmap
= NULL
;
2122 if (lxc_config_value_empty(value
))
2123 return lxc_clear_idmaps(lxc_conf
);
2125 idmaplist
= malloc(sizeof(*idmaplist
));
2129 idmap
= malloc(sizeof(*idmap
));
2132 memset(idmap
, 0, sizeof(*idmap
));
2134 ret
= parse_idmaps(value
, &type
, &nsid
, &hostid
, &range
);
2136 ERROR("Failed to parse id mappings");
2140 INFO("Read uid map: type %c nsid %lu hostid %lu range %lu", type
, nsid
, hostid
, range
);
2142 idmap
->idtype
= ID_TYPE_UID
;
2143 else if (type
== 'g')
2144 idmap
->idtype
= ID_TYPE_GID
;
2148 idmap
->hostid
= hostid
;
2150 idmap
->range
= range
;
2151 idmaplist
->elem
= idmap
;
2152 lxc_list_add_tail(&lxc_conf
->id_map
, idmaplist
);
2154 if (!lxc_conf
->root_nsuid_map
&& idmap
->idtype
== ID_TYPE_UID
)
2155 if (idmap
->nsid
== 0)
2156 lxc_conf
->root_nsuid_map
= idmap
;
2158 if (!lxc_conf
->root_nsgid_map
&& idmap
->idtype
== ID_TYPE_GID
)
2159 if (idmap
->nsid
== 0)
2160 lxc_conf
->root_nsgid_map
= idmap
;
2173 static int set_config_mount_fstab(const char *key
, const char *value
,
2174 struct lxc_conf
*lxc_conf
, void *data
)
2176 if (lxc_config_value_empty(value
)) {
2177 clr_config_mount_fstab(key
, lxc_conf
, NULL
);
2181 return set_config_path_item(&lxc_conf
->fstab
, value
);
2184 static int set_config_mount_auto(const char *key
, const char *value
,
2185 struct lxc_conf
*lxc_conf
, void *data
)
2187 char *autos
, *token
;
2194 } allowed_auto_mounts
[] = {
2195 { "proc", LXC_AUTO_PROC_MASK
, LXC_AUTO_PROC_MIXED
},
2196 { "proc:mixed", LXC_AUTO_PROC_MASK
, LXC_AUTO_PROC_MIXED
},
2197 { "proc:rw", LXC_AUTO_PROC_MASK
, LXC_AUTO_PROC_RW
},
2198 { "sys", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_MIXED
},
2199 { "sys:ro", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_RO
},
2200 { "sys:mixed", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_MIXED
},
2201 { "sys:rw", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_RW
},
2202 { "cgroup", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_NOSPEC
},
2203 { "cgroup:mixed", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_MIXED
},
2204 { "cgroup:ro", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_RO
},
2205 { "cgroup:rw", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_RW
},
2206 { "cgroup:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_NOSPEC
| LXC_AUTO_CGROUP_FORCE
},
2207 { "cgroup:mixed:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_MIXED
| LXC_AUTO_CGROUP_FORCE
},
2208 { "cgroup:ro:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_RO
| LXC_AUTO_CGROUP_FORCE
},
2209 { "cgroup:rw:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_RW
| LXC_AUTO_CGROUP_FORCE
},
2210 { "cgroup-full", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_NOSPEC
},
2211 { "cgroup-full:mixed", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_MIXED
},
2212 { "cgroup-full:ro", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_RO
},
2213 { "cgroup-full:rw", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_RW
},
2214 { "cgroup-full:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_NOSPEC
| LXC_AUTO_CGROUP_FORCE
},
2215 { "cgroup-full:mixed:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_MIXED
| LXC_AUTO_CGROUP_FORCE
},
2216 { "cgroup-full:ro:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_RO
| LXC_AUTO_CGROUP_FORCE
},
2217 { "cgroup-full:rw:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_RW
| LXC_AUTO_CGROUP_FORCE
},
2218 { "shmounts:", LXC_AUTO_SHMOUNTS_MASK
, LXC_AUTO_SHMOUNTS
},
2219 /* For adding anything that is just a single on/off, but has no
2220 * options: keep mask and flag identical and just define the enum
2221 * value as an unused bit so far
2226 if (lxc_config_value_empty(value
)) {
2227 lxc_conf
->auto_mounts
= 0;
2231 autos
= strdup(value
);
2235 lxc_iterate_parts(token
, autos
, " \t") {
2236 bool is_shmounts
= false;
2238 for (i
= 0; allowed_auto_mounts
[i
].token
; i
++) {
2239 if (!strcmp(allowed_auto_mounts
[i
].token
, token
))
2242 if (strcmp("shmounts:", allowed_auto_mounts
[i
].token
) == 0 &&
2243 strncmp("shmounts:", token
, STRLITERALLEN("shmounts:")) == 0) {
2249 if (!allowed_auto_mounts
[i
].token
) {
2250 ERROR("Invalid filesystem to automount \"%s\"", token
);
2254 lxc_conf
->auto_mounts
&= ~allowed_auto_mounts
[i
].mask
;
2255 lxc_conf
->auto_mounts
|= allowed_auto_mounts
[i
].flag
;
2258 char *container_path
;
2261 host_path
= token
+ STRLITERALLEN("shmounts:");
2262 if (*host_path
== '\0') {
2263 SYSERROR("Failed to copy shmounts host path");
2267 container_path
= strchr(host_path
, ':');
2268 if (!container_path
|| *(container_path
+ 1) == '\0')
2269 container_path
= "/dev/.lxc-mounts";
2271 *container_path
++ = '\0';
2273 lxc_conf
->shmount
.path_host
= strdup(host_path
);
2274 if (!lxc_conf
->shmount
.path_host
) {
2275 SYSERROR("Failed to copy shmounts host path");
2279 lxc_conf
->shmount
.path_cont
= strdup(container_path
);
2280 if(!lxc_conf
->shmount
.path_cont
) {
2281 SYSERROR("Failed to copy shmounts container path");
2295 static int set_config_mount(const char *key
, const char *value
,
2296 struct lxc_conf
*lxc_conf
, void *data
)
2299 struct lxc_list
*mntlist
;
2301 if (lxc_config_value_empty(value
))
2302 return lxc_clear_mount_entries(lxc_conf
);
2304 mntlist
= malloc(sizeof(*mntlist
));
2308 mntelem
= strdup(value
);
2313 mntlist
->elem
= mntelem
;
2315 lxc_list_add_tail(&lxc_conf
->mount_list
, mntlist
);
2320 int add_elem_to_mount_list(const char *value
, struct lxc_conf
*lxc_conf
) {
2321 return set_config_mount(NULL
, value
, lxc_conf
, NULL
);
2324 static int set_config_cap_keep(const char *key
, const char *value
,
2325 struct lxc_conf
*lxc_conf
, void *data
)
2327 char *keepcaps
, *token
;
2328 struct lxc_list
*keeplist
;
2331 if (lxc_config_value_empty(value
))
2332 return lxc_clear_config_keepcaps(lxc_conf
);
2334 keepcaps
= strdup(value
);
2338 /* In case several capability keep is specified in a single line
2339 * split these caps in a single element for the list.
2341 lxc_iterate_parts(token
, keepcaps
, " \t") {
2342 if (!strcmp(token
, "none"))
2343 lxc_clear_config_keepcaps(lxc_conf
);
2345 keeplist
= malloc(sizeof(*keeplist
));
2349 keeplist
->elem
= strdup(token
);
2350 if (!keeplist
->elem
) {
2355 lxc_list_add_tail(&lxc_conf
->keepcaps
, keeplist
);
2366 static int set_config_cap_drop(const char *key
, const char *value
,
2367 struct lxc_conf
*lxc_conf
, void *data
)
2369 char *dropcaps
, *token
;
2370 struct lxc_list
*droplist
;
2373 if (lxc_config_value_empty(value
))
2374 return lxc_clear_config_caps(lxc_conf
);
2376 dropcaps
= strdup(value
);
2380 /* In case several capability drop is specified in a single line
2381 * split these caps in a single element for the list.
2383 lxc_iterate_parts(token
, dropcaps
, " \t") {
2384 droplist
= malloc(sizeof(*droplist
));
2388 droplist
->elem
= strdup(token
);
2389 if (!droplist
->elem
) {
2394 lxc_list_add_tail(&lxc_conf
->caps
, droplist
);
2405 static int set_config_console_path(const char *key
, const char *value
,
2406 struct lxc_conf
*lxc_conf
, void *data
)
2408 return set_config_path_item(&lxc_conf
->console
.path
, value
);
2411 static int set_config_console_rotate(const char *key
, const char *value
,
2412 struct lxc_conf
*lxc_conf
, void *data
)
2414 if (lxc_config_value_empty(value
)) {
2415 lxc_conf
->console
.log_rotate
= 0;
2419 if (lxc_safe_uint(value
, &lxc_conf
->console
.log_rotate
) < 0)
2422 if (lxc_conf
->console
.log_rotate
> 1) {
2423 ERROR("The \"lxc.console.rotate\" config key can only be set "
2431 static int set_config_console_logfile(const char *key
, const char *value
,
2432 struct lxc_conf
*lxc_conf
, void *data
)
2434 return set_config_path_item(&lxc_conf
->console
.log_path
, value
);
2437 static int set_config_console_buffer_size(const char *key
, const char *value
,
2438 struct lxc_conf
*lxc_conf
, void *data
)
2442 uint64_t buffer_size
, pgsz
;
2444 if (lxc_config_value_empty(value
)) {
2445 lxc_conf
->console
.buffer_size
= 0;
2449 /* If the user specified "auto" the default log size is 2^17 = 128 Kib */
2450 if (!strcmp(value
, "auto")) {
2451 lxc_conf
->console
.buffer_size
= 1 << 17;
2455 ret
= parse_byte_size_string(value
, &size
);
2462 /* must be at least a page size */
2463 pgsz
= lxc_getpagesize();
2464 if ((uint64_t)size
< pgsz
) {
2465 NOTICE("Requested ringbuffer size for the console is %" PRId64
2466 " but must be at least %" PRId64
2467 " bytes. Setting ringbuffer size to %" PRId64
" bytes",
2472 buffer_size
= lxc_find_next_power2((uint64_t)size
);
2473 if (buffer_size
== 0)
2476 if (buffer_size
!= size
)
2477 NOTICE("Passed size was not a power of 2. Rounding log size to "
2478 "next power of two: %" PRIu64
" bytes", buffer_size
);
2480 lxc_conf
->console
.buffer_size
= buffer_size
;
2485 static int set_config_console_size(const char *key
, const char *value
,
2486 struct lxc_conf
*lxc_conf
, void *data
)
2490 uint64_t log_size
, pgsz
;
2492 if (lxc_config_value_empty(value
)) {
2493 lxc_conf
->console
.log_size
= 0;
2497 /* If the user specified "auto" the default log size is 2^17 = 128 Kib */
2498 if (!strcmp(value
, "auto")) {
2499 lxc_conf
->console
.log_size
= 1 << 17;
2503 ret
= parse_byte_size_string(value
, &size
);
2510 /* must be at least a page size */
2511 pgsz
= lxc_getpagesize();
2512 if ((uint64_t)size
< pgsz
) {
2513 NOTICE("Requested ringbuffer size for the console is %" PRId64
2514 " but must be at least %" PRId64
2515 " bytes. Setting ringbuffer size to %" PRId64
" bytes",
2520 log_size
= lxc_find_next_power2((uint64_t)size
);
2524 if (log_size
!= size
)
2525 NOTICE("Passed size was not a power of 2. Rounding log size to "
2526 "next power of two: %" PRIu64
" bytes", log_size
);
2528 lxc_conf
->console
.log_size
= log_size
;
2534 * If we find a lxc.net.[i].hwaddr or lxc.network.hwaddr in the original config
2535 * file, we expand it in the unexpanded_config, so that after a save_config we
2536 * store the hwaddr for re-use.
2537 * This is only called when reading the config file, not when executing a
2539 * 'x' and 'X' are substituted in-place.
2541 static void update_hwaddr(const char *line
)
2545 line
+= lxc_char_left_gc(line
, strlen(line
));
2549 if (!lxc_config_net_is_hwaddr(line
))
2552 /* Let config_net_hwaddr raise the error. */
2553 p
= strchr(line
, '=');
2564 rand_complete_hwaddr(p
);
2567 int append_unexp_config_line(const char *line
, struct lxc_conf
*conf
)
2570 size_t len
= conf
->unexpanded_len
;
2572 update_hwaddr(line
);
2574 linelen
= strlen(line
);
2575 while (conf
->unexpanded_alloced
<= len
+ linelen
+ 2) {
2576 char *tmp
= realloc(conf
->unexpanded_config
,
2577 conf
->unexpanded_alloced
+ 1024);
2581 if (!conf
->unexpanded_config
)
2584 conf
->unexpanded_config
= tmp
;
2585 conf
->unexpanded_alloced
+= 1024;
2588 memcpy(conf
->unexpanded_config
+ conf
->unexpanded_len
, line
, linelen
);
2589 conf
->unexpanded_len
+= linelen
;
2590 if (line
[linelen
- 1] != '\n')
2591 conf
->unexpanded_config
[conf
->unexpanded_len
++] = '\n';
2592 conf
->unexpanded_config
[conf
->unexpanded_len
] = '\0';
2597 static int do_includedir(const char *dirp
, struct lxc_conf
*lxc_conf
)
2599 __do_closedir
DIR *dir
= NULL
;
2600 struct dirent
*direntp
;
2601 char path
[PATH_MAX
];
2605 dir
= opendir(dirp
);
2609 while ((direntp
= readdir(dir
))) {
2612 fnam
= direntp
->d_name
;
2613 if (!strcmp(fnam
, "."))
2616 if (!strcmp(fnam
, ".."))
2620 if (len
< 6 || strncmp(fnam
+ len
- 5, ".conf", 5) != 0)
2623 len
= snprintf(path
, PATH_MAX
, "%s/%s", dirp
, fnam
);
2624 if (len
< 0 || len
>= PATH_MAX
)
2627 ret
= lxc_config_read(path
, lxc_conf
, true);
2635 static int set_config_includefiles(const char *key
, const char *value
,
2636 struct lxc_conf
*lxc_conf
, void *data
)
2638 if (lxc_config_value_empty(value
)) {
2639 clr_config_includefiles(key
, lxc_conf
, NULL
);
2644 return do_includedir(value
, lxc_conf
);
2646 return lxc_config_read(value
, lxc_conf
, true);
2649 static int set_config_rootfs_path(const char *key
, const char *value
,
2650 struct lxc_conf
*lxc_conf
, void *data
)
2654 const char *container_path
;
2656 if (lxc_config_value_empty(value
)) {
2657 free(lxc_conf
->rootfs
.path
);
2658 lxc_conf
->rootfs
.path
= NULL
;
2662 dup
= strdup(value
);
2666 /* Split <storage type>:<container path> into <storage type> and
2667 * <container path>. Set "rootfs.bdev_type" to <storage type> and
2668 * "rootfs.path" to <container path>.
2670 tmp
= strchr(dup
, ':');
2674 ret
= set_config_path_item(&lxc_conf
->rootfs
.bdev_type
, dup
);
2681 container_path
= tmp
;
2683 container_path
= value
;
2686 ret
= set_config_path_item(&lxc_conf
->rootfs
.path
, container_path
);
2692 static int set_config_rootfs_managed(const char *key
, const char *value
,
2693 struct lxc_conf
*lxc_conf
, void *data
)
2695 return set_config_bool_item(&lxc_conf
->rootfs
.managed
, value
, true);
2698 static int set_config_rootfs_mount(const char *key
, const char *value
,
2699 struct lxc_conf
*lxc_conf
, void *data
)
2701 return set_config_path_item(&lxc_conf
->rootfs
.mount
, value
);
2704 static int set_config_rootfs_options(const char *key
, const char *value
,
2705 struct lxc_conf
*lxc_conf
, void *data
)
2707 unsigned long mflags
= 0, pflags
= 0;
2708 char *mdata
= NULL
, *opts
= NULL
;
2710 struct lxc_rootfs
*rootfs
= &lxc_conf
->rootfs
;
2712 ret
= parse_mntopts(value
, &mflags
, &mdata
);
2716 ret
= parse_propagationopts(value
, &pflags
);
2722 ret
= set_config_string_item(&opts
, value
);
2728 rootfs
->mountflags
= mflags
| pflags
;
2729 rootfs
->options
= opts
;
2730 rootfs
->data
= mdata
;
2735 static int set_config_uts_name(const char *key
, const char *value
,
2736 struct lxc_conf
*lxc_conf
, void *data
)
2738 struct utsname
*utsname
;
2740 if (lxc_config_value_empty(value
)) {
2741 clr_config_uts_name(key
, lxc_conf
, NULL
);
2745 utsname
= malloc(sizeof(*utsname
));
2749 if (strlen(value
) >= sizeof(utsname
->nodename
)) {
2754 (void)strlcpy(utsname
->nodename
, value
, sizeof(utsname
->nodename
));
2755 free(lxc_conf
->utsname
);
2756 lxc_conf
->utsname
= utsname
;
2761 static int set_config_namespace_clone(const char *key
, const char *value
,
2762 struct lxc_conf
*lxc_conf
, void *data
)
2767 if (lxc_config_value_empty(value
))
2768 return clr_config_namespace_clone(key
, lxc_conf
, data
);
2770 if (lxc_conf
->ns_keep
!= 0) {
2772 SYSERROR("Cannot set both \"lxc.namespace.clone\" and "
2773 "\"lxc.namespace.keep\"");
2781 lxc_iterate_parts(token
, ns
, " \t") {
2782 token
+= lxc_char_left_gc(token
, strlen(token
));
2783 token
[lxc_char_right_gc(token
, strlen(token
))] = '\0';
2784 cloneflag
= lxc_namespace_2_cloneflag(token
);
2785 if (cloneflag
< 0) {
2789 lxc_conf
->ns_clone
|= cloneflag
;
2796 static int set_config_namespace_keep(const char *key
, const char *value
,
2797 struct lxc_conf
*lxc_conf
, void *data
)
2802 if (lxc_config_value_empty(value
))
2803 return clr_config_namespace_keep(key
, lxc_conf
, data
);
2805 if (lxc_conf
->ns_clone
!= 0) {
2807 SYSERROR("Cannot set both \"lxc.namespace.clone\" and "
2808 "\"lxc.namespace.keep\"");
2816 lxc_iterate_parts(token
, ns
, " \t") {
2817 token
+= lxc_char_left_gc(token
, strlen(token
));
2818 token
[lxc_char_right_gc(token
, strlen(token
))] = '\0';
2819 cloneflag
= lxc_namespace_2_cloneflag(token
);
2820 if (cloneflag
< 0) {
2824 lxc_conf
->ns_keep
|= cloneflag
;
2831 static int set_config_time_offset_boot(const char *key
, const char *value
,
2832 struct lxc_conf
*lxc_conf
, void *data
)
2837 char buf
[STRLITERALLEN("ms") + 1];
2839 if (lxc_config_value_empty(value
))
2840 return clr_config_time_offset_boot(key
, lxc_conf
, data
);
2842 ret
= lxc_safe_int64_residual(value
, &offset
, 10, buf
, sizeof(buf
));
2846 unit
= lxc_trim_whitespace_in_place(buf
);
2847 if (strcmp(unit
, "h") == 0) {
2848 if (!multiply_overflow(offset
, 3600, &lxc_conf
->timens
.s_boot
))
2850 } else if (strcmp(unit
, "m") == 0) {
2851 if (!multiply_overflow(offset
, 60, &lxc_conf
->timens
.s_boot
))
2853 } else if (strcmp(unit
, "s") == 0) {
2854 lxc_conf
->timens
.s_boot
= offset
;
2855 } else if (strcmp(unit
, "ms") == 0) {
2856 if (!multiply_overflow(offset
, 1000000, &lxc_conf
->timens
.ns_boot
))
2858 } else if (strcmp(unit
, "us") == 0) {
2859 if (!multiply_overflow(offset
, 1000, &lxc_conf
->timens
.ns_boot
))
2861 } else if (strcmp(unit
, "ns") == 0) {
2862 lxc_conf
->timens
.ns_boot
= offset
;
2864 return ret_errno(EINVAL
);
2870 static int set_config_time_offset_monotonic(const char *key
, const char *value
,
2871 struct lxc_conf
*lxc_conf
, void *data
)
2876 char buf
[STRLITERALLEN("ms") + 1];
2878 if (lxc_config_value_empty(value
))
2879 return clr_config_time_offset_monotonic(key
, lxc_conf
, data
);
2881 ret
= lxc_safe_int64_residual(value
, &offset
, 10, buf
, sizeof(buf
));
2885 unit
= lxc_trim_whitespace_in_place(buf
);
2886 if (strcmp(unit
, "h") == 0) {
2887 if (!multiply_overflow(offset
, 3600, &lxc_conf
->timens
.s_monotonic
))
2889 } else if (strcmp(unit
, "m") == 0) {
2890 if (!multiply_overflow(offset
, 60, &lxc_conf
->timens
.s_monotonic
))
2892 } else if (strcmp(unit
, "s") == 0) {
2893 lxc_conf
->timens
.s_monotonic
= offset
;
2894 } else if (strcmp(unit
, "ms") == 0) {
2895 if (!multiply_overflow(offset
, 1000000, &lxc_conf
->timens
.ns_monotonic
))
2897 } else if (strcmp(unit
, "us") == 0) {
2898 if (!multiply_overflow(offset
, 1000, &lxc_conf
->timens
.ns_monotonic
))
2900 } else if (strcmp(unit
, "ns") == 0) {
2901 lxc_conf
->timens
.ns_monotonic
= offset
;
2903 return ret_errno(EINVAL
);
2909 static int set_config_namespace_share(const char *key
, const char *value
,
2910 struct lxc_conf
*lxc_conf
, void *data
)
2913 const char *namespace;
2915 if (lxc_config_value_empty(value
))
2916 return clr_config_namespace_share(key
, lxc_conf
, data
);
2918 namespace = key
+ STRLITERALLEN("lxc.namespace.share.");
2919 ns_idx
= lxc_namespace_2_ns_idx(namespace);
2923 return set_config_string_item(&lxc_conf
->ns_share
[ns_idx
], value
);
2926 struct parse_line_conf
{
2927 struct lxc_conf
*conf
;
2931 static int parse_line(char *buffer
, void *data
)
2933 char *dot
, *key
, *line
, *linep
, *value
;
2935 struct lxc_config_t
*config
;
2938 struct parse_line_conf
*plc
= data
;
2940 /* If there are newlines in the config file we should keep them. */
2941 empty_line
= lxc_is_line_empty(dup
);
2945 /* We have to dup the buffer otherwise, at the re-exec for reboot we
2946 * modified the original string on the stack by replacing '=' by '\0'
2949 linep
= line
= strdup(dup
);
2953 if (!plc
->from_include
) {
2954 ret
= append_unexp_config_line(line
, plc
->conf
);
2962 line
+= lxc_char_left_gc(line
, strlen(line
));
2964 /* ignore comments */
2968 /* martian option - don't add it to the config itself */
2969 if (strncmp(line
, "lxc.", 4))
2974 dot
= strchr(line
, '=');
2976 ERROR("Invalid configuration line: %s", line
);
2984 key
[lxc_char_right_gc(key
, strlen(key
))] = '\0';
2986 value
+= lxc_char_left_gc(value
, strlen(value
));
2987 value
[lxc_char_right_gc(value
, strlen(value
))] = '\0';
2989 if (*value
== '\'' || *value
== '\"') {
2992 len
= strlen(value
);
2993 if (len
> 1 && value
[len
- 1] == *value
) {
2994 value
[len
- 1] = '\0';
2999 config
= lxc_get_config(key
);
3001 ERROR("Unknown configuration key \"%s\"", key
);
3005 ret
= config
->set(key
, value
, plc
->conf
, NULL
);
3013 static struct new_config_item
*parse_new_conf_line(char *buffer
)
3015 char *dot
, *key
, *line
, *linep
, *value
;
3018 struct new_config_item
*new = NULL
;
3020 linep
= line
= strdup(dup
);
3024 line
+= lxc_char_left_gc(line
, strlen(line
));
3026 /* martian option - don't add it to the config itself */
3027 if (strncmp(line
, "lxc.", 4))
3031 dot
= strchr(line
, '=');
3033 ERROR("Invalid configuration item: %s", line
);
3041 key
[lxc_char_right_gc(key
, strlen(key
))] = '\0';
3043 value
+= lxc_char_left_gc(value
, strlen(value
));
3044 value
[lxc_char_right_gc(value
, strlen(value
))] = '\0';
3046 if (*value
== '\'' || *value
== '\"') {
3049 len
= strlen(value
);
3050 if (len
> 1 && value
[len
- 1] == *value
) {
3051 value
[len
- 1] = '\0';
3057 new = malloc(sizeof(struct new_config_item
));
3061 new->key
= strdup(key
);
3062 new->val
= strdup(value
);
3063 if (!new->val
|| !new->key
)
3071 if (ret
< 0 && new) {
3081 int lxc_config_read(const char *file
, struct lxc_conf
*conf
, bool from_include
)
3083 struct parse_line_conf c
;
3086 c
.from_include
= from_include
;
3088 /* Catch only the top level config file name in the structure. */
3090 conf
->rcfile
= strdup(file
);
3092 return lxc_file_for_each_line_mmap(file
, parse_line
, &c
);
3095 int lxc_config_define_add(struct lxc_list
*defines
, char *arg
)
3097 struct lxc_list
*dent
;
3099 dent
= malloc(sizeof(struct lxc_list
));
3103 dent
->elem
= parse_new_conf_line(arg
);
3109 lxc_list_add_tail(defines
, dent
);
3114 bool lxc_config_define_load(struct lxc_list
*defines
, struct lxc_container
*c
)
3116 struct lxc_list
*it
;
3119 lxc_list_for_each(it
, defines
) {
3120 struct new_config_item
*new_item
= it
->elem
;
3121 bret
= c
->set_config_item(c
, new_item
->key
, new_item
->val
);
3126 lxc_config_define_free(defines
);
3131 void lxc_config_define_free(struct lxc_list
*defines
)
3133 struct lxc_list
*it
, *next
;
3135 lxc_list_for_each_safe(it
, defines
, next
) {
3136 struct new_config_item
*new_item
= it
->elem
;
3137 free(new_item
->key
);
3138 free(new_item
->val
);
3144 signed long lxc_config_parse_arch(const char *arch
)
3146 #if HAVE_SYS_PERSONALITY_H
3152 { "arm", PER_LINUX32
},
3153 { "armel", PER_LINUX32
},
3154 { "armhf", PER_LINUX32
},
3155 { "armv7l", PER_LINUX32
},
3156 { "athlon", PER_LINUX32
},
3157 { "i386", PER_LINUX32
},
3158 { "i486", PER_LINUX32
},
3159 { "i586", PER_LINUX32
},
3160 { "i686", PER_LINUX32
},
3161 { "linux32", PER_LINUX32
},
3162 { "mips", PER_LINUX32
},
3163 { "mipsel", PER_LINUX32
},
3164 { "ppc", PER_LINUX32
},
3165 { "powerpc", PER_LINUX32
},
3166 { "x86", PER_LINUX32
},
3167 { "amd64", PER_LINUX
},
3168 { "arm64", PER_LINUX
},
3169 { "linux64", PER_LINUX
},
3170 { "mips64", PER_LINUX
},
3171 { "mips64el", PER_LINUX
},
3172 { "ppc64", PER_LINUX
},
3173 { "ppc64el", PER_LINUX
},
3174 { "ppc64le", PER_LINUX
},
3175 { "powerpc64", PER_LINUX
},
3176 { "s390x", PER_LINUX
},
3177 { "x86_64", PER_LINUX
},
3179 size_t len
= sizeof(pername
) / sizeof(pername
[0]);
3181 for (i
= 0; i
< len
; i
++)
3182 if (!strcmp(pername
[i
].name
, arch
))
3183 return pername
[i
].per
;
3189 int lxc_fill_elevated_privileges(char *flaglist
, int *flags
)
3197 { "CGROUP", LXC_ATTACH_MOVE_TO_CGROUP
},
3198 { "CAP", LXC_ATTACH_DROP_CAPABILITIES
},
3199 { "LSM", LXC_ATTACH_LSM_EXEC
},
3204 /* For the sake of backward compatibility, drop all privileges
3205 * if none is specified.
3207 for (i
= 0; all_privs
[i
].token
; i
++)
3208 *flags
|= all_privs
[i
].flag
;
3213 lxc_iterate_parts(token
, flaglist
, "|") {
3216 for (i
= 0; all_privs
[i
].token
; i
++)
3217 if (!strcmp(all_privs
[i
].token
, token
))
3218 aflag
= all_privs
[i
].flag
;
3229 /* Write out a configuration file. */
3230 int write_config(int fd
, const struct lxc_conf
*conf
)
3233 size_t len
= conf
->unexpanded_len
;
3238 ret
= lxc_write_nointr(fd
, conf
->unexpanded_config
, len
);
3240 SYSERROR("Failed to write configuration file");
3247 bool do_append_unexp_config_line(struct lxc_conf
*conf
, const char *key
,
3250 __do_free
char *tmp
= NULL
;
3254 len
= strlen(key
) + strlen(v
) + 4;
3255 tmp
= must_realloc(NULL
, len
);
3257 if (lxc_config_value_empty(v
))
3258 ret
= snprintf(tmp
, len
, "%s =", key
);
3260 ret
= snprintf(tmp
, len
, "%s = %s", key
, v
);
3261 if (ret
< 0 || ret
>= len
)
3264 /* Save the line verbatim into unexpanded_conf */
3265 if (append_unexp_config_line(tmp
, conf
))
3271 void clear_unexp_config_line(struct lxc_conf
*conf
, const char *key
,
3275 char *lstart
= conf
->unexpanded_config
;
3277 if (!conf
->unexpanded_config
)
3281 lend
= strchr(lstart
, '\n');
3285 lend
= lstart
+ strlen(lstart
);
3289 if (strncmp(lstart
, key
, strlen(key
)) != 0) {
3295 v
= lstart
[strlen(key
)];
3296 if (!isspace(v
) && v
!= '=') {
3302 conf
->unexpanded_len
-= (lend
- lstart
);
3304 if (*lend
== '\0') {
3309 memmove(lstart
, lend
, strlen(lend
) + 1);
3313 bool clone_update_unexp_ovl_paths(struct lxc_conf
*conf
, const char *oldpath
,
3314 const char *newpath
, const char *oldname
,
3315 const char *newname
, const char *ovldir
)
3317 __do_free
char *newdir
= NULL
,
3321 size_t newdirlen
, olddirlen
;
3322 char *lstart
= conf
->unexpanded_config
;
3323 const char *key
= "lxc.mount.entry";
3325 olddirlen
= strlen(ovldir
) + strlen(oldpath
) + strlen(oldname
) + 2;
3326 olddir
= must_realloc(NULL
, olddirlen
+ 1);
3327 ret
= snprintf(olddir
, olddirlen
+ 1, "%s=%s/%s", ovldir
, oldpath
,
3329 if (ret
< 0 || ret
>= olddirlen
+ 1)
3332 newdirlen
= strlen(ovldir
) + strlen(newpath
) + strlen(newname
) + 2;
3333 newdir
= must_realloc(NULL
, newdirlen
+ 1);
3334 ret
= snprintf(newdir
, newdirlen
+ 1, "%s=%s/%s", ovldir
, newpath
,
3336 if (ret
< 0 || ret
>= newdirlen
+ 1)
3339 if (!conf
->unexpanded_config
)
3343 lend
= strchr(lstart
, '\n');
3345 lend
= lstart
+ strlen(lstart
);
3349 if (strncmp(lstart
, key
, strlen(key
)) != 0)
3352 p
= strchr(lstart
+ strlen(key
), '=');
3363 /* Whenever a lxc.mount.entry entry is found in a line we check
3364 * if the substring "overlay" is present before doing any
3365 * further work. We check for "overlay" because substrings need
3366 * to have at least one space before them in a valid overlay
3367 * lxc.mount.entry (/A B overlay). When the space before is
3368 * missing it is very likely that these substrings are part of a
3369 * path or something else. (Checking q >= lend ensures that we
3370 * only count matches in the current line.) */
3371 q
= strstr(p
, " overlay");
3372 if (!q
|| q
>= lend
)
3375 if (!(q
= strstr(p
, olddir
)) || (q
>= lend
))
3378 /* replace the olddir with newdir */
3379 if (olddirlen
>= newdirlen
) {
3380 size_t diff
= olddirlen
- newdirlen
;
3381 memcpy(q
, newdir
, newdirlen
);
3383 if (olddirlen
!= newdirlen
) {
3384 memmove(q
+ newdirlen
, q
+ newdirlen
+ diff
,
3385 strlen(q
) - newdirlen
- diff
+ 1);
3387 conf
->unexpanded_len
-= diff
;
3391 size_t diff
= newdirlen
- olddirlen
;
3392 size_t oldlen
= conf
->unexpanded_len
;
3393 size_t newlen
= oldlen
+ diff
;
3394 size_t poffset
= q
- conf
->unexpanded_config
;
3396 new = realloc(conf
->unexpanded_config
, newlen
+ 1);
3400 conf
->unexpanded_len
= newlen
;
3401 conf
->unexpanded_alloced
= newlen
+ 1;
3402 new[newlen
- 1] = '\0';
3403 lend
= new + (lend
- conf
->unexpanded_config
);
3405 /* Move over the remainder to make room for the newdir.
3407 memmove(new + poffset
+ newdirlen
,
3408 new + poffset
+ olddirlen
,
3409 oldlen
- poffset
- olddirlen
+ 1);
3410 conf
->unexpanded_config
= new;
3412 memcpy(new + poffset
, newdir
, newdirlen
);
3423 bool clone_update_unexp_hooks(struct lxc_conf
*conf
, const char *oldpath
,
3424 const char *newpath
, const char *oldname
,
3425 const char *newname
)
3427 __do_free
char *newdir
= NULL
,
3431 char *lstart
= conf
->unexpanded_config
;
3432 size_t newdirlen
, olddirlen
;
3433 const char *key
= "lxc.hook";
3435 olddirlen
= strlen(oldpath
) + strlen(oldname
) + 1;
3436 olddir
= must_realloc(NULL
, olddirlen
+ 1);
3437 ret
= snprintf(olddir
, olddirlen
+ 1, "%s/%s", oldpath
, oldname
);
3438 if (ret
< 0 || ret
>= olddirlen
+ 1)
3441 newdirlen
= strlen(newpath
) + strlen(newname
) + 1;
3442 newdir
= must_realloc(NULL
, newdirlen
+ 1);
3443 ret
= snprintf(newdir
, newdirlen
+ 1, "%s/%s", newpath
, newname
);
3444 if (ret
< 0 || ret
>= newdirlen
+ 1)
3447 if (!conf
->unexpanded_config
)
3451 lend
= strchr(lstart
, '\n');
3453 lend
= lstart
+ strlen(lstart
);
3457 if (strncmp(lstart
, key
, strlen(key
)) != 0)
3460 p
= strchr(lstart
+ strlen(key
), '=');
3471 if (strncmp(p
, olddir
, strlen(olddir
)) != 0)
3474 /* replace the olddir with newdir */
3475 if (olddirlen
>= newdirlen
) {
3476 size_t diff
= olddirlen
- newdirlen
;
3477 memcpy(p
, newdir
, newdirlen
);
3479 if (olddirlen
!= newdirlen
) {
3480 memmove(p
+ newdirlen
, p
+ newdirlen
+ diff
,
3481 strlen(p
) - newdirlen
- diff
+ 1);
3483 conf
->unexpanded_len
-= diff
;
3487 size_t diff
= newdirlen
- olddirlen
;
3488 size_t oldlen
= conf
->unexpanded_len
;
3489 size_t newlen
= oldlen
+ diff
;
3490 size_t poffset
= p
- conf
->unexpanded_config
;
3492 new = realloc(conf
->unexpanded_config
, newlen
+ 1);
3496 conf
->unexpanded_len
= newlen
;
3497 conf
->unexpanded_alloced
= newlen
+ 1;
3498 new[newlen
- 1] = '\0';
3499 lend
= new + (lend
- conf
->unexpanded_config
);
3501 /* Move over the remainder to make room for the newdir.
3503 memmove(new + poffset
+ newdirlen
,
3504 new + poffset
+ olddirlen
,
3505 oldlen
- poffset
- olddirlen
+ 1);
3506 conf
->unexpanded_config
= new;
3508 memcpy(new + poffset
, newdir
, newdirlen
);
3522 ERROR("Error writing to new config"); \
3527 /* This is called only from clone. We wish to update all hwaddrs in the
3528 * unexpanded config file. We can't/don't want to update any which come from
3529 * lxc.includes (there shouldn't be any).
3530 * We can't just walk the c->lxc-conf->network list because that includes netifs
3531 * from the include files. So we update the ones which we find in the unexp
3532 * config file, then find the original macaddr in the conf->network, and update
3533 * that to the same value.
3535 bool network_new_hwaddrs(struct lxc_conf
*conf
)
3537 char *lend
, *p
, *p2
;
3538 struct lxc_list
*it
;
3539 char *lstart
= conf
->unexpanded_config
;
3541 if (!conf
->unexpanded_config
)
3545 char newhwaddr
[18], oldhwaddr
[17];
3547 lend
= strchr(lstart
, '\n');
3549 lend
= lstart
+ strlen(lstart
);
3553 if (!lxc_config_net_is_hwaddr(lstart
)) {
3558 p
= strchr(lstart
, '=');
3571 while (*p2
&& !isblank(*p2
) && *p2
!= '\n')
3574 if ((p2
- p
) != 17) {
3575 WARN("Bad hwaddr entry");
3580 memcpy(oldhwaddr
, p
, 17);
3582 if (!new_hwaddr(newhwaddr
))
3585 memcpy(p
, newhwaddr
, 17);
3586 lxc_list_for_each(it
, &conf
->network
) {
3587 struct lxc_netdev
*n
= it
->elem
;
3589 if (n
->hwaddr
&& memcmp(oldhwaddr
, n
->hwaddr
, 17) == 0)
3590 memcpy(n
->hwaddr
, newhwaddr
, 17);
3599 static int set_config_ephemeral(const char *key
, const char *value
,
3600 struct lxc_conf
*lxc_conf
, void *data
)
3602 if (lxc_config_value_empty(value
)) {
3603 lxc_conf
->ephemeral
= 0;
3607 if (lxc_safe_uint(value
, &lxc_conf
->ephemeral
) < 0)
3610 if (lxc_conf
->ephemeral
> 1)
3616 static int set_config_log_syslog(const char *key
, const char *value
,
3617 struct lxc_conf
*lxc_conf
, void *data
)
3621 if (lxc_conf
->syslog
) {
3622 free(lxc_conf
->syslog
);
3623 lxc_conf
->syslog
= NULL
;
3626 if (lxc_config_value_empty(value
))
3629 facility
= lxc_syslog_priority_to_int(value
);
3630 if (facility
== -EINVAL
)
3633 lxc_log_syslog(facility
);
3635 return set_config_string_item(&lxc_conf
->syslog
, value
);
3638 static int set_config_no_new_privs(const char *key
, const char *value
,
3639 struct lxc_conf
*lxc_conf
, void *data
)
3643 if (lxc_config_value_empty(value
)) {
3644 lxc_conf
->no_new_privs
= false;
3648 if (lxc_safe_uint(value
, &v
) < 0)
3654 lxc_conf
->no_new_privs
= v
? true : false;
3659 /* Callbacks to get configuration items. */
3660 static int get_config_personality(const char *key
, char *retv
, int inlen
,
3661 struct lxc_conf
*c
, void *data
)
3668 memset(retv
, 0, inlen
);
3670 #if HAVE_SYS_PERSONALITY_H
3673 switch (c
->personality
) {
3675 strprint(retv
, inlen
, "i686");
3678 strprint(retv
, inlen
, "x86_64");
3688 static int get_config_pty_max(const char *key
, char *retv
, int inlen
,
3689 struct lxc_conf
*c
, void *data
)
3691 return lxc_get_conf_size_t(c
, retv
, inlen
, c
->pty_max
);
3694 static int get_config_tty_max(const char *key
, char *retv
, int inlen
,
3695 struct lxc_conf
*c
, void *data
)
3697 return lxc_get_conf_size_t(c
, retv
, inlen
, c
->ttys
.max
);
3700 static int get_config_tty_dir(const char *key
, char *retv
, int inlen
,
3701 struct lxc_conf
*c
, void *data
)
3703 return lxc_get_conf_str(retv
, inlen
, c
->ttys
.dir
);
3706 static int get_config_apparmor_profile(const char *key
, char *retv
, int inlen
,
3707 struct lxc_conf
*c
, void *data
)
3709 return lxc_get_conf_str(retv
, inlen
, c
->lsm_aa_profile
);
3712 static int get_config_apparmor_allow_incomplete(const char *key
, char *retv
,
3713 int inlen
, struct lxc_conf
*c
,
3716 return lxc_get_conf_int(c
, retv
, inlen
,
3717 c
->lsm_aa_allow_incomplete
);
3720 static int get_config_apparmor_allow_nesting(const char *key
, char *retv
,
3721 int inlen
, struct lxc_conf
*c
,
3724 return lxc_get_conf_int(c
, retv
, inlen
,
3725 c
->lsm_aa_allow_nesting
);
3728 static int get_config_apparmor_raw(const char *key
, char *retv
,
3729 int inlen
, struct lxc_conf
*c
,
3733 struct lxc_list
*it
;
3739 memset(retv
, 0, inlen
);
3741 lxc_list_for_each(it
, &c
->lsm_aa_raw
) {
3742 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3748 static int get_config_selinux_context(const char *key
, char *retv
, int inlen
,
3749 struct lxc_conf
*c
, void *data
)
3751 return lxc_get_conf_str(retv
, inlen
, c
->lsm_se_context
);
3754 static int get_config_selinux_context_keyring(const char *key
, char *retv
, int inlen
,
3755 struct lxc_conf
*c
, void *data
)
3757 return lxc_get_conf_str(retv
, inlen
, c
->lsm_se_keyring_context
);
3760 static int get_config_keyring_session(const char *key
, char *retv
, int inlen
,
3761 struct lxc_conf
*c
, void *data
)
3763 return lxc_get_conf_bool(c
, retv
, inlen
, c
->keyring_disable_session
);
3767 /* If you ask for a specific cgroup value, i.e. lxc.cgroup.devices.list, then
3768 * just the value(s) will be printed. Since there still could be more than one,
3769 * it is newline-separated.
3770 * (Maybe that's ambiguous, since some values, i.e. devices.list, will already
3772 * If you ask for 'lxc.cgroup", then all cgroup entries will be printed, in
3773 * 'lxc.cgroup.subsystem.key = value' format.
3775 static int __get_config_cgroup_controller(const char *key
, char *retv
,
3776 int inlen
, struct lxc_conf
*c
,
3780 size_t namespaced_token_len
;
3781 char *global_token
, *namespaced_token
;
3782 struct lxc_list
*it
;
3784 bool get_all
= false;
3789 memset(retv
, 0, inlen
);
3791 if (version
== CGROUP2_SUPER_MAGIC
) {
3792 global_token
= "lxc.cgroup2";
3793 namespaced_token
= "lxc.cgroup2.";
3794 namespaced_token_len
= STRLITERALLEN("lxc.cgroup2.");
3795 } else if (version
== CGROUP_SUPER_MAGIC
) {
3796 global_token
= "lxc.cgroup";
3797 namespaced_token
= "lxc.cgroup.";
3798 namespaced_token_len
= STRLITERALLEN("lxc.cgroup.");
3803 if (strcmp(key
, global_token
) == 0)
3805 else if (strncmp(key
, namespaced_token
, namespaced_token_len
) == 0)
3806 key
+= namespaced_token_len
;
3810 lxc_list_for_each(it
, &c
->cgroup
) {
3811 struct lxc_cgroup
*cg
= it
->elem
;
3814 if (version
!= cg
->version
)
3817 strprint(retv
, inlen
, "%s.%s = %s\n", global_token
,
3818 cg
->subsystem
, cg
->value
);
3819 } else if (strcmp(cg
->subsystem
, key
) == 0) {
3820 strprint(retv
, inlen
, "%s\n", cg
->value
);
3827 static int get_config_cgroup_controller(const char *key
, char *retv
, int inlen
,
3828 struct lxc_conf
*c
, void *data
)
3830 return __get_config_cgroup_controller(key
, retv
, inlen
, c
,
3831 CGROUP_SUPER_MAGIC
);
3834 static int get_config_cgroup2_controller(const char *key
, char *retv
, int inlen
,
3835 struct lxc_conf
*c
, void *data
)
3837 return __get_config_cgroup_controller(key
, retv
, inlen
, c
,
3838 CGROUP2_SUPER_MAGIC
);
3841 static int get_config_cgroup_dir(const char *key
, char *retv
, int inlen
,
3842 struct lxc_conf
*lxc_conf
, void *data
)
3850 memset(retv
, 0, inlen
);
3852 strprint(retv
, inlen
, "%s", lxc_conf
->cgroup_meta
.dir
);
3857 static int get_config_cgroup_monitor_dir(const char *key
, char *retv
, int inlen
,
3858 struct lxc_conf
*lxc_conf
, void *data
)
3866 memset(retv
, 0, inlen
);
3868 strprint(retv
, inlen
, "%s", lxc_conf
->cgroup_meta
.monitor_dir
);
3873 static int get_config_cgroup_container_dir(const char *key
, char *retv
,
3875 struct lxc_conf
*lxc_conf
,
3884 memset(retv
, 0, inlen
);
3886 strprint(retv
, inlen
, "%s", lxc_conf
->cgroup_meta
.container_dir
);
3891 static int get_config_cgroup_container_inner_dir(const char *key
, char *retv
,
3893 struct lxc_conf
*lxc_conf
,
3902 memset(retv
, 0, inlen
);
3904 strprint(retv
, inlen
, "%s", lxc_conf
->cgroup_meta
.namespace_dir
);
3909 static inline int get_config_cgroup_relative(const char *key
, char *retv
,
3910 int inlen
, struct lxc_conf
*lxc_conf
,
3913 return lxc_get_conf_int(lxc_conf
, retv
, inlen
,
3914 lxc_conf
->cgroup_meta
.relative
);
3917 static int get_config_idmaps(const char *key
, char *retv
, int inlen
,
3918 struct lxc_conf
*c
, void *data
)
3920 struct lxc_list
*it
;
3921 int len
, listlen
, ret
;
3923 /* "u 1000 1000000 65536"
3925 * let's render this as
3943 #define __LXC_IDMAP_STR_BUF (3 * INTTYPE_TO_STRLEN(uint32_t) + 3 + 1 + 1)
3944 char buf
[__LXC_IDMAP_STR_BUF
];
3949 memset(retv
, 0, inlen
);
3951 listlen
= lxc_list_len(&c
->id_map
);
3952 lxc_list_for_each(it
, &c
->id_map
) {
3953 struct id_map
*map
= it
->elem
;
3954 ret
= snprintf(buf
, __LXC_IDMAP_STR_BUF
, "%c %lu %lu %lu",
3955 (map
->idtype
== ID_TYPE_UID
) ? 'u' : 'g',
3956 map
->nsid
, map
->hostid
, map
->range
);
3957 if (ret
< 0 || ret
>= __LXC_IDMAP_STR_BUF
)
3960 strprint(retv
, inlen
, "%s%s", buf
, (listlen
-- > 1) ? "\n" : "");
3966 static int get_config_log_level(const char *key
, char *retv
, int inlen
,
3967 struct lxc_conf
*c
, void *data
)
3970 v
= lxc_log_priority_to_string(c
->loglevel
);
3971 return lxc_get_conf_str(retv
, inlen
, v
);
3974 static int get_config_log_file(const char *key
, char *retv
, int inlen
,
3975 struct lxc_conf
*c
, void *data
)
3977 return lxc_get_conf_str(retv
, inlen
, c
->logfile
);
3980 static int get_config_mount_fstab(const char *key
, char *retv
, int inlen
,
3981 struct lxc_conf
*c
, void *data
)
3983 return lxc_get_conf_str(retv
, inlen
, c
->fstab
);
3986 static int get_config_mount_auto(const char *key
, char *retv
, int inlen
,
3987 struct lxc_conf
*c
, void *data
)
3989 int len
, fulllen
= 0;
3990 const char *sep
= "";
3995 memset(retv
, 0, inlen
);
3997 if (!(c
->auto_mounts
& LXC_AUTO_ALL_MASK
))
4000 switch (c
->auto_mounts
& LXC_AUTO_PROC_MASK
) {
4001 case LXC_AUTO_PROC_MIXED
:
4002 strprint(retv
, inlen
, "%sproc:mixed", sep
);
4005 case LXC_AUTO_PROC_RW
:
4006 strprint(retv
, inlen
, "%sproc:rw", sep
);
4013 switch (c
->auto_mounts
& LXC_AUTO_SYS_MASK
) {
4014 case LXC_AUTO_SYS_RO
:
4015 strprint(retv
, inlen
, "%ssys:ro", sep
);
4018 case LXC_AUTO_SYS_RW
:
4019 strprint(retv
, inlen
, "%ssys:rw", sep
);
4022 case LXC_AUTO_SYS_MIXED
:
4023 strprint(retv
, inlen
, "%ssys:mixed", sep
);
4030 switch (c
->auto_mounts
& LXC_AUTO_CGROUP_MASK
) {
4031 case LXC_AUTO_CGROUP_NOSPEC
:
4032 strprint(retv
, inlen
, "%scgroup", sep
);
4034 case LXC_AUTO_CGROUP_MIXED
:
4035 strprint(retv
, inlen
, "%scgroup:mixed", sep
);
4037 case LXC_AUTO_CGROUP_RO
:
4038 strprint(retv
, inlen
, "%scgroup:ro", sep
);
4040 case LXC_AUTO_CGROUP_RW
:
4041 strprint(retv
, inlen
, "%scgroup:rw", sep
);
4043 case LXC_AUTO_CGROUP_FULL_NOSPEC
:
4044 strprint(retv
, inlen
, "%scgroup-full", sep
);
4046 case LXC_AUTO_CGROUP_FULL_MIXED
:
4047 strprint(retv
, inlen
, "%scgroup-full:mixed", sep
);
4049 case LXC_AUTO_CGROUP_FULL_RO
:
4050 strprint(retv
, inlen
, "%scgroup-full:ro", sep
);
4052 case LXC_AUTO_CGROUP_FULL_RW
:
4053 strprint(retv
, inlen
, "%scgroup-full:rw", sep
);
4062 static int get_config_mount(const char *key
, char *retv
, int inlen
,
4063 struct lxc_conf
*c
, void *data
)
4065 int len
, fulllen
= 0;
4066 struct lxc_list
*it
;
4071 memset(retv
, 0, inlen
);
4073 lxc_list_for_each(it
, &c
->mount_list
) {
4074 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
4080 static int get_config_rootfs_path(const char *key
, char *retv
, int inlen
,
4081 struct lxc_conf
*c
, void *data
)
4083 return lxc_get_conf_str(retv
, inlen
, c
->rootfs
.path
);
4086 static int get_config_rootfs_managed(const char *key
, char *retv
, int inlen
,
4087 struct lxc_conf
*c
, void *data
)
4089 return lxc_get_conf_bool(c
, retv
, inlen
, c
->rootfs
.managed
);
4092 static int get_config_rootfs_mount(const char *key
, char *retv
, int inlen
,
4093 struct lxc_conf
*c
, void *data
)
4095 return lxc_get_conf_str(retv
, inlen
, c
->rootfs
.mount
);
4098 static int get_config_rootfs_options(const char *key
, char *retv
, int inlen
,
4099 struct lxc_conf
*c
, void *data
)
4101 return lxc_get_conf_str(retv
, inlen
, c
->rootfs
.options
);
4104 static int get_config_uts_name(const char *key
, char *retv
, int inlen
,
4105 struct lxc_conf
*c
, void *data
)
4107 return lxc_get_conf_str(
4109 c
->utsname
? c
->utsname
->nodename
: NULL
);
4112 static int get_config_hooks(const char *key
, char *retv
, int inlen
,
4113 struct lxc_conf
*c
, void *data
)
4116 int len
, fulllen
= 0, found
= -1;
4117 struct lxc_list
*it
;
4120 subkey
= strchr(key
, '.');
4124 subkey
= strchr(subkey
+ 1, '.');
4128 if (*subkey
== '\0')
4131 for (i
= 0; i
< NUM_LXC_HOOKS
; i
++) {
4132 if (strcmp(lxchook_names
[i
], subkey
) == 0) {
4144 memset(retv
, 0, inlen
);
4146 lxc_list_for_each(it
, &c
->hooks
[found
]) {
4147 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
4153 static int get_config_hooks_version(const char *key
, char *retv
, int inlen
,
4154 struct lxc_conf
*c
, void *data
)
4156 return lxc_get_conf_int(c
, retv
, inlen
, c
->hooks_version
);
4159 static int get_config_net(const char *key
, char *retv
, int inlen
,
4160 struct lxc_conf
*c
, void *data
)
4162 int len
, fulllen
= 0;
4163 struct lxc_list
*it
;
4168 memset(retv
, 0, inlen
);
4170 lxc_list_for_each(it
, &c
->network
) {
4171 struct lxc_netdev
*n
= it
->elem
;
4172 const char *t
= lxc_net_type_to_str(n
->type
);
4173 strprint(retv
, inlen
, "%s\n", t
? t
: "(invalid)");
4179 static int get_config_cap_drop(const char *key
, char *retv
, int inlen
,
4180 struct lxc_conf
*c
, void *data
)
4182 int len
, fulllen
= 0;
4183 struct lxc_list
*it
;
4188 memset(retv
, 0, inlen
);
4190 lxc_list_for_each(it
, &c
->caps
) {
4191 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
4197 static int get_config_cap_keep(const char *key
, char *retv
, int inlen
,
4198 struct lxc_conf
*c
, void *data
)
4200 int len
, fulllen
= 0;
4201 struct lxc_list
*it
;
4206 memset(retv
, 0, inlen
);
4208 lxc_list_for_each(it
, &c
->keepcaps
) {
4209 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
4215 static int get_config_console_path(const char *key
, char *retv
, int inlen
,
4216 struct lxc_conf
*c
, void *data
)
4218 return lxc_get_conf_str(retv
, inlen
, c
->console
.path
);
4221 static int get_config_console_logfile(const char *key
, char *retv
, int inlen
,
4222 struct lxc_conf
*c
, void *data
)
4224 return lxc_get_conf_str(retv
, inlen
, c
->console
.log_path
);
4227 static int get_config_console_rotate(const char *key
, char *retv
, int inlen
,
4228 struct lxc_conf
*c
, void *data
)
4230 return lxc_get_conf_int(c
, retv
, inlen
, c
->console
.log_rotate
);
4234 static int get_config_console_buffer_size(const char *key
, char *retv
,
4235 int inlen
, struct lxc_conf
*c
,
4238 return lxc_get_conf_uint64(c
, retv
, inlen
, c
->console
.buffer_size
);
4241 static int get_config_console_size(const char *key
, char *retv
, int inlen
,
4242 struct lxc_conf
*c
, void *data
)
4244 return lxc_get_conf_uint64(c
, retv
, inlen
, c
->console
.log_size
);
4247 static int get_config_seccomp_allow_nesting(const char *key
, char *retv
,
4248 int inlen
, struct lxc_conf
*c
,
4252 return lxc_get_conf_int(c
, retv
, inlen
, c
->seccomp
.allow_nesting
);
4259 static int get_config_seccomp_notify_cookie(const char *key
, char *retv
, int inlen
,
4260 struct lxc_conf
*c
, void *data
)
4262 #ifdef HAVE_SECCOMP_NOTIFY
4263 return lxc_get_conf_str(retv
, inlen
, c
->seccomp
.notifier
.cookie
);
4265 return ret_set_errno(-1, ENOSYS
);
4269 static int get_config_seccomp_notify_proxy(const char *key
, char *retv
, int inlen
,
4270 struct lxc_conf
*c
, void *data
)
4272 #ifdef HAVE_SECCOMP_NOTIFY
4273 return lxc_get_conf_str(retv
, inlen
,
4274 (c
->seccomp
.notifier
.proxy_addr
.sun_path
[0]) == '/'
4275 ? &c
->seccomp
.notifier
.proxy_addr
.sun_path
[0]
4276 : &c
->seccomp
.notifier
.proxy_addr
.sun_path
[1]);
4278 return ret_set_errno(-1, ENOSYS
);
4282 static int get_config_seccomp_profile(const char *key
, char *retv
, int inlen
,
4283 struct lxc_conf
*c
, void *data
)
4285 return lxc_get_conf_str(retv
, inlen
, c
->seccomp
.seccomp
);
4288 static int get_config_autodev(const char *key
, char *retv
, int inlen
,
4289 struct lxc_conf
*c
, void *data
)
4291 return lxc_get_conf_int(c
, retv
, inlen
, c
->autodev
);
4294 static int get_config_autodev_tmpfs_size(const char *key
, char *retv
, int inlen
,
4295 struct lxc_conf
*c
, void *data
)
4297 return lxc_get_conf_int(c
, retv
, inlen
, c
->autodevtmpfssize
);
4300 static int get_config_signal_halt(const char *key
, char *retv
, int inlen
,
4301 struct lxc_conf
*c
, void *data
)
4303 return lxc_get_conf_int(c
, retv
, inlen
, c
->haltsignal
);
4306 static int get_config_signal_reboot(const char *key
, char *retv
, int inlen
,
4307 struct lxc_conf
*c
, void *data
)
4309 return lxc_get_conf_int(c
, retv
, inlen
, c
->rebootsignal
);
4312 static int get_config_signal_stop(const char *key
, char *retv
, int inlen
,
4313 struct lxc_conf
*c
, void *data
)
4315 return lxc_get_conf_int(c
, retv
, inlen
, c
->stopsignal
);
4318 static int get_config_start(const char *key
, char *retv
, int inlen
,
4319 struct lxc_conf
*c
, void *data
)
4321 if (strcmp(key
+ 10, "auto") == 0)
4322 return lxc_get_conf_int(c
, retv
, inlen
, c
->start_auto
);
4323 else if (strcmp(key
+ 10, "delay") == 0)
4324 return lxc_get_conf_int(c
, retv
, inlen
, c
->start_delay
);
4325 else if (strcmp(key
+ 10, "order") == 0)
4326 return lxc_get_conf_int(c
, retv
, inlen
, c
->start_order
);
4331 static int get_config_log_syslog(const char *key
, char *retv
, int inlen
,
4332 struct lxc_conf
*c
, void *data
)
4334 return lxc_get_conf_str(retv
, inlen
, c
->syslog
);
4337 static int get_config_monitor(const char *key
, char *retv
, int inlen
,
4338 struct lxc_conf
*c
, void *data
)
4340 return lxc_get_conf_int(c
, retv
, inlen
, c
->monitor_unshare
);
4343 static int get_config_monitor_signal_pdeath(const char *key
, char *retv
,
4344 int inlen
, struct lxc_conf
*c
,
4347 return lxc_get_conf_int(c
, retv
, inlen
, c
->monitor_signal_pdeath
);
4350 static int get_config_group(const char *key
, char *retv
, int inlen
,
4351 struct lxc_conf
*c
, void *data
)
4353 int len
, fulllen
= 0;
4354 struct lxc_list
*it
;
4359 memset(retv
, 0, inlen
);
4361 lxc_list_for_each(it
, &c
->groups
) {
4362 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
4368 static int get_config_environment(const char *key
, char *retv
, int inlen
,
4369 struct lxc_conf
*c
, void *data
)
4371 int len
, fulllen
= 0;
4372 struct lxc_list
*it
;
4377 memset(retv
, 0, inlen
);
4379 lxc_list_for_each(it
, &c
->environment
) {
4380 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
4386 static int get_config_execute_cmd(const char *key
, char *retv
, int inlen
,
4387 struct lxc_conf
*c
, void *data
)
4389 return lxc_get_conf_str(retv
, inlen
, c
->execute_cmd
);
4392 static int get_config_init_cmd(const char *key
, char *retv
, int inlen
,
4393 struct lxc_conf
*c
, void *data
)
4395 return lxc_get_conf_str(retv
, inlen
, c
->init_cmd
);
4398 static int get_config_init_cwd(const char *key
, char *retv
, int inlen
,
4399 struct lxc_conf
*c
, void *data
)
4401 return lxc_get_conf_str(retv
, inlen
, c
->init_cwd
);
4404 static int get_config_init_uid(const char *key
, char *retv
, int inlen
,
4405 struct lxc_conf
*c
, void *data
)
4407 return lxc_get_conf_int(c
, retv
, inlen
, c
->init_uid
);
4410 static int get_config_init_gid(const char *key
, char *retv
, int inlen
,
4411 struct lxc_conf
*c
, void *data
)
4413 return lxc_get_conf_int(c
, retv
, inlen
, c
->init_gid
);
4416 static int get_config_ephemeral(const char *key
, char *retv
, int inlen
,
4417 struct lxc_conf
*c
, void *data
)
4419 return lxc_get_conf_int(c
, retv
, inlen
, c
->ephemeral
);
4422 static int get_config_no_new_privs(const char *key
, char *retv
, int inlen
,
4423 struct lxc_conf
*c
, void *data
)
4425 return lxc_get_conf_int(c
, retv
, inlen
, c
->no_new_privs
);
4428 /* If you ask for a specific value, i.e. lxc.prlimit.nofile, then just the value
4429 * will be printed. If you ask for 'lxc.prlimit', then all limit entries will be
4430 * printed, in 'lxc.prlimit.resource = value' format.
4432 static int get_config_prlimit(const char *key
, char *retv
, int inlen
,
4433 struct lxc_conf
*c
, void *data
)
4435 int fulllen
= 0, len
;
4436 bool get_all
= false;
4437 struct lxc_list
*it
;
4442 memset(retv
, 0, inlen
);
4444 if (!strcmp(key
, "lxc.prlimit"))
4446 else if (strncmp(key
, "lxc.prlimit.", 12) == 0)
4451 lxc_list_for_each(it
, &c
->limits
) {
4452 /* 2 colon separated 64 bit integers or the word 'unlimited' */
4453 char buf
[INTTYPE_TO_STRLEN(uint64_t) * 2 + 2];
4455 struct lxc_limit
*lim
= it
->elem
;
4457 if (lim
->limit
.rlim_cur
== RLIM_INFINITY
) {
4458 memcpy(buf
, "unlimited", STRLITERALLEN("unlimited") + 1);
4459 partlen
= STRLITERALLEN("unlimited");
4461 partlen
= sprintf(buf
, "%" PRIu64
,
4462 (uint64_t)lim
->limit
.rlim_cur
);
4465 if (lim
->limit
.rlim_cur
!= lim
->limit
.rlim_max
) {
4466 if (lim
->limit
.rlim_max
== RLIM_INFINITY
)
4467 memcpy(buf
+ partlen
, ":unlimited",
4468 STRLITERALLEN(":unlimited") + 1);
4470 sprintf(buf
+ partlen
, ":%" PRIu64
,
4471 (uint64_t)lim
->limit
.rlim_max
);
4475 strprint(retv
, inlen
, "lxc.prlimit.%s = %s\n",
4476 lim
->resource
, buf
);
4477 } else if (strcmp(lim
->resource
, key
) == 0) {
4478 strprint(retv
, inlen
, "%s", buf
);
4485 /* If you ask for a specific value, i.e. lxc.sysctl.net.ipv4.ip_forward, then
4486 * just the value will be printed. If you ask for 'lxc.sysctl', then all sysctl
4487 * entries will be printed, in 'lxc.sysctl.key = value' format.
4489 static int get_config_sysctl(const char *key
, char *retv
, int inlen
,
4490 struct lxc_conf
*c
, void *data
)
4493 struct lxc_list
*it
;
4495 bool get_all
= false;
4500 memset(retv
, 0, inlen
);
4502 if (strcmp(key
, "lxc.sysctl") == 0)
4504 else if (strncmp(key
, "lxc.sysctl.", STRLITERALLEN("lxc.sysctl.")) == 0)
4505 key
+= STRLITERALLEN("lxc.sysctl.");
4509 lxc_list_for_each(it
, &c
->sysctls
) {
4510 struct lxc_sysctl
*elem
= it
->elem
;
4512 strprint(retv
, inlen
, "lxc.sysctl.%s = %s\n", elem
->key
,
4514 } else if (strcmp(elem
->key
, key
) == 0) {
4515 strprint(retv
, inlen
, "%s", elem
->value
);
4522 static int get_config_proc(const char *key
, char *retv
, int inlen
,
4523 struct lxc_conf
*c
, void *data
)
4525 struct lxc_list
*it
;
4528 bool get_all
= false;
4533 memset(retv
, 0, inlen
);
4535 if (strcmp(key
, "lxc.proc") == 0)
4537 else if (strncmp(key
, "lxc.proc.", STRLITERALLEN("lxc.proc.")) == 0)
4538 key
+= STRLITERALLEN("lxc.proc.");
4542 lxc_list_for_each(it
, &c
->procs
) {
4543 struct lxc_proc
*proc
= it
->elem
;
4546 strprint(retv
, inlen
, "lxc.proc.%s = %s\n",
4547 proc
->filename
, proc
->value
);
4548 } else if (strcmp(proc
->filename
, key
) == 0) {
4549 strprint(retv
, inlen
, "%s", proc
->value
);
4556 static int get_config_namespace_clone(const char *key
, char *retv
, int inlen
,
4557 struct lxc_conf
*c
, void *data
)
4565 memset(retv
, 0, inlen
);
4567 for (i
= 0; i
< LXC_NS_MAX
; i
++) {
4568 if (c
->ns_clone
& ns_info
[i
].clone_flag
)
4569 strprint(retv
, inlen
, "%s\n", ns_info
[i
].proc_name
);
4575 static int get_config_namespace_keep(const char *key
, char *retv
, int inlen
,
4576 struct lxc_conf
*c
, void *data
)
4584 memset(retv
, 0, inlen
);
4586 for (i
= 0; i
< LXC_NS_MAX
; i
++) {
4587 if (c
->ns_keep
& ns_info
[i
].clone_flag
)
4588 strprint(retv
, inlen
, "%s\n", ns_info
[i
].proc_name
);
4594 static int get_config_time_offset_boot(const char *key
, char *retv
, int inlen
, struct lxc_conf
*c
,
4603 memset(retv
, 0, inlen
);
4605 if (c
->timens
.s_boot
) {
4606 strprint(retv
, inlen
, "%" PRId64
" s\n", c
->timens
.s_boot
);
4608 strprint(retv
, inlen
, "%" PRId64
" ns\n", c
->timens
.ns_boot
);
4614 static int get_config_time_offset_monotonic(const char *key
, char *retv
, int inlen
,
4615 struct lxc_conf
*c
, void *data
)
4623 memset(retv
, 0, inlen
);
4625 if (c
->timens
.s_monotonic
) {
4626 strprint(retv
, inlen
, "%" PRId64
"s\n", c
->timens
.s_monotonic
);
4628 strprint(retv
, inlen
, "%" PRId64
"ns\n", c
->timens
.ns_monotonic
);
4634 static int get_config_namespace_share(const char *key
, char *retv
, int inlen
,
4635 struct lxc_conf
*c
, void *data
)
4638 const char *namespace;
4644 memset(retv
, 0, inlen
);
4646 namespace = key
+ STRLITERALLEN("lxc.namespace.share.");
4647 ns_idx
= lxc_namespace_2_ns_idx(namespace);
4651 strprint(retv
, inlen
, "%s", c
->ns_share
[ns_idx
]);
4656 /* Callbacks to clear config items. */
4657 static inline int clr_config_personality(const char *key
, struct lxc_conf
*c
,
4660 c
->personality
= -1;
4664 static inline int clr_config_pty_max(const char *key
, struct lxc_conf
*c
,
4671 static inline int clr_config_tty_max(const char *key
, struct lxc_conf
*c
,
4678 static inline int clr_config_tty_dir(const char *key
, struct lxc_conf
*c
,
4686 static inline int clr_config_apparmor_profile(const char *key
,
4687 struct lxc_conf
*c
, void *data
)
4689 free(c
->lsm_aa_profile
);
4690 c
->lsm_aa_profile
= NULL
;
4694 static inline int clr_config_apparmor_allow_incomplete(const char *key
,
4698 c
->lsm_aa_allow_incomplete
= 0;
4702 static inline int clr_config_apparmor_allow_nesting(const char *key
,
4706 c
->lsm_aa_allow_nesting
= 0;
4710 static inline int clr_config_apparmor_raw(const char *key
,
4714 return lxc_clear_apparmor_raw(c
);
4717 static inline int clr_config_selinux_context(const char *key
,
4718 struct lxc_conf
*c
, void *data
)
4720 free(c
->lsm_se_context
);
4721 c
->lsm_se_context
= NULL
;
4725 static inline int clr_config_selinux_context_keyring(const char *key
,
4726 struct lxc_conf
*c
, void *data
)
4728 free(c
->lsm_se_keyring_context
);
4729 c
->lsm_se_keyring_context
= NULL
;
4733 static inline int clr_config_keyring_session(const char *key
,
4734 struct lxc_conf
*c
, void *data
)
4736 c
->keyring_disable_session
= false;
4740 static inline int clr_config_cgroup_controller(const char *key
,
4741 struct lxc_conf
*c
, void *data
)
4743 return lxc_clear_cgroups(c
, key
, CGROUP_SUPER_MAGIC
);
4746 static inline int clr_config_cgroup2_controller(const char *key
,
4747 struct lxc_conf
*c
, void *data
)
4749 return lxc_clear_cgroups(c
, key
, CGROUP2_SUPER_MAGIC
);
4752 static int clr_config_cgroup_dir(const char *key
, struct lxc_conf
*lxc_conf
,
4755 if (lxc_conf
->cgroup_meta
.dir
) {
4756 free(lxc_conf
->cgroup_meta
.dir
);
4757 lxc_conf
->cgroup_meta
.dir
= NULL
;
4763 static int clr_config_cgroup_monitor_dir(const char *key
,
4764 struct lxc_conf
*lxc_conf
,
4767 free_disarm(lxc_conf
->cgroup_meta
.monitor_dir
);
4771 static int clr_config_cgroup_container_dir(const char *key
,
4772 struct lxc_conf
*lxc_conf
,
4775 free_disarm(lxc_conf
->cgroup_meta
.container_dir
);
4779 static int clr_config_cgroup_container_inner_dir(const char *key
,
4780 struct lxc_conf
*lxc_conf
,
4783 free_disarm(lxc_conf
->cgroup_meta
.namespace_dir
);
4787 static inline int clr_config_cgroup_relative(const char *key
,
4788 struct lxc_conf
*lxc_conf
,
4791 lxc_conf
->cgroup_meta
.relative
= false;
4795 static inline int clr_config_idmaps(const char *key
, struct lxc_conf
*c
,
4798 return lxc_clear_idmaps(c
);
4801 static inline int clr_config_log_level(const char *key
, struct lxc_conf
*c
,
4804 c
->loglevel
= LXC_LOG_LEVEL_NOTSET
;
4808 static inline int clr_config_log_file(const char *key
, struct lxc_conf
*c
,
4816 static inline int clr_config_mount(const char *key
, struct lxc_conf
*c
,
4819 return lxc_clear_mount_entries(c
);
4822 static inline int clr_config_mount_auto(const char *key
, struct lxc_conf
*c
,
4825 return lxc_clear_automounts(c
);
4828 static inline int clr_config_mount_fstab(const char *key
, struct lxc_conf
*c
,
4836 static inline int clr_config_rootfs_path(const char *key
, struct lxc_conf
*c
,
4839 free(c
->rootfs
.path
);
4840 c
->rootfs
.path
= NULL
;
4844 static inline int clr_config_rootfs_managed(const char *key
, struct lxc_conf
*c
,
4847 c
->rootfs
.managed
= true;
4851 static inline int clr_config_rootfs_mount(const char *key
, struct lxc_conf
*c
,
4854 free(c
->rootfs
.mount
);
4855 c
->rootfs
.mount
= NULL
;
4859 static inline int clr_config_rootfs_options(const char *key
, struct lxc_conf
*c
,
4862 free(c
->rootfs
.options
);
4863 c
->rootfs
.options
= NULL
;
4865 free(c
->rootfs
.data
);
4866 c
->rootfs
.data
= NULL
;
4871 static inline int clr_config_uts_name(const char *key
, struct lxc_conf
*c
,
4879 static inline int clr_config_hooks(const char *key
, struct lxc_conf
*c
,
4882 return lxc_clear_hooks(c
, key
);
4885 static inline int clr_config_hooks_version(const char *key
, struct lxc_conf
*c
,
4888 /* default to legacy hooks version */
4889 c
->hooks_version
= 0;
4893 static inline int clr_config_net(const char *key
, struct lxc_conf
*c
,
4896 lxc_free_networks(&c
->network
);
4901 static inline int clr_config_cap_drop(const char *key
, struct lxc_conf
*c
,
4904 return lxc_clear_config_caps(c
);
4907 static inline int clr_config_cap_keep(const char *key
, struct lxc_conf
*c
,
4910 return lxc_clear_config_keepcaps(c
);
4913 static inline int clr_config_console_path(const char *key
, struct lxc_conf
*c
,
4916 free(c
->console
.path
);
4917 c
->console
.path
= NULL
;
4921 static inline int clr_config_console_logfile(const char *key
,
4922 struct lxc_conf
*c
, void *data
)
4924 free(c
->console
.log_path
);
4925 c
->console
.log_path
= NULL
;
4929 static inline int clr_config_console_rotate(const char *key
, struct lxc_conf
*c
,
4932 c
->console
.log_rotate
= 0;
4936 static inline int clr_config_console_buffer_size(const char *key
,
4937 struct lxc_conf
*c
, void *data
)
4939 c
->console
.buffer_size
= 0;
4943 static inline int clr_config_console_size(const char *key
, struct lxc_conf
*c
,
4946 c
->console
.log_size
= 0;
4950 static inline int clr_config_seccomp_allow_nesting(const char *key
,
4951 struct lxc_conf
*c
, void *data
)
4954 c
->seccomp
.allow_nesting
= 0;
4962 static inline int clr_config_seccomp_notify_cookie(const char *key
,
4963 struct lxc_conf
*c
, void *data
)
4965 #ifdef HAVE_SECCOMP_NOTIFY
4966 free(c
->seccomp
.notifier
.cookie
);
4967 c
->seccomp
.notifier
.cookie
= NULL
;
4970 return ret_set_errno(-1, ENOSYS
);
4974 static inline int clr_config_seccomp_notify_proxy(const char *key
,
4975 struct lxc_conf
*c
, void *data
)
4977 #ifdef HAVE_SECCOMP_NOTIFY
4978 memset(&c
->seccomp
.notifier
.proxy_addr
, 0,
4979 sizeof(c
->seccomp
.notifier
.proxy_addr
));
4982 return ret_set_errno(-1, ENOSYS
);
4986 static inline int clr_config_seccomp_profile(const char *key
,
4987 struct lxc_conf
*c
, void *data
)
4989 free(c
->seccomp
.seccomp
);
4990 c
->seccomp
.seccomp
= NULL
;
4994 static inline int clr_config_autodev(const char *key
, struct lxc_conf
*c
,
5001 static inline int clr_config_autodev_tmpfs_size(const char *key
, struct lxc_conf
*c
,
5004 c
->autodevtmpfssize
= 500000;
5008 static inline int clr_config_signal_halt(const char *key
, struct lxc_conf
*c
,
5015 static inline int clr_config_signal_reboot(const char *key
, struct lxc_conf
*c
,
5018 c
->rebootsignal
= 0;
5022 static inline int clr_config_signal_stop(const char *key
, struct lxc_conf
*c
,
5029 static inline int clr_config_start(const char *key
, struct lxc_conf
*c
,
5032 if (strcmp(key
+ 10, "auto") == 0)
5034 else if (strcmp(key
+ 10, "delay") == 0)
5036 else if (strcmp(key
+ 10, "order") == 0)
5042 static inline int clr_config_log_syslog(const char *key
, struct lxc_conf
*c
,
5050 static inline int clr_config_monitor(const char *key
, struct lxc_conf
*c
,
5053 c
->monitor_unshare
= 0;
5057 static inline int clr_config_monitor_signal_pdeath(const char *key
,
5058 struct lxc_conf
*c
, void *data
)
5060 c
->monitor_signal_pdeath
= 0;
5064 static inline int clr_config_group(const char *key
, struct lxc_conf
*c
,
5067 return lxc_clear_groups(c
);
5070 static inline int clr_config_environment(const char *key
, struct lxc_conf
*c
,
5073 return lxc_clear_environment(c
);
5076 static inline int clr_config_execute_cmd(const char *key
, struct lxc_conf
*c
,
5079 free(c
->execute_cmd
);
5080 c
->execute_cmd
= NULL
;
5084 static inline int clr_config_init_cmd(const char *key
, struct lxc_conf
*c
,
5092 static inline int clr_config_init_cwd(const char *key
, struct lxc_conf
*c
,
5100 static inline int clr_config_init_uid(const char *key
, struct lxc_conf
*c
,
5107 static inline int clr_config_init_gid(const char *key
, struct lxc_conf
*c
,
5114 static inline int clr_config_ephemeral(const char *key
, struct lxc_conf
*c
,
5121 static inline int clr_config_no_new_privs(const char *key
, struct lxc_conf
*c
,
5124 c
->no_new_privs
= false;
5128 static inline int clr_config_prlimit(const char *key
, struct lxc_conf
*c
,
5131 return lxc_clear_limits(c
, key
);
5134 static inline int clr_config_sysctl(const char *key
, struct lxc_conf
*c
,
5137 return lxc_clear_sysctls(c
, key
);
5140 static inline int clr_config_proc(const char *key
, struct lxc_conf
*c
,
5143 return lxc_clear_procs(c
, key
);
5146 static inline int clr_config_includefiles(const char *key
, struct lxc_conf
*c
,
5149 lxc_clear_includes(c
);
5153 static int clr_config_namespace_clone(const char *key
,
5154 struct lxc_conf
*lxc_conf
, void *data
)
5156 lxc_conf
->ns_clone
= 0;
5160 static int clr_config_namespace_keep(const char *key
, struct lxc_conf
*lxc_conf
,
5163 lxc_conf
->ns_keep
= 0;
5167 static int clr_config_time_offset_boot(const char *key
, struct lxc_conf
*lxc_conf
, void *data
)
5169 lxc_conf
->timens
.s_boot
= 0;
5170 lxc_conf
->timens
.ns_boot
= 0;
5174 static int clr_config_time_offset_monotonic(const char *key
, struct lxc_conf
*lxc_conf
, void *data
)
5176 lxc_conf
->timens
.s_monotonic
= 0;
5177 lxc_conf
->timens
.ns_monotonic
= 0;
5181 static int clr_config_namespace_share(const char *key
,
5182 struct lxc_conf
*lxc_conf
, void *data
)
5185 const char *namespace;
5187 namespace = key
+ STRLITERALLEN("lxc.namespace.share.");
5188 ns_idx
= lxc_namespace_2_ns_idx(namespace);
5192 free(lxc_conf
->ns_share
[ns_idx
]);
5193 lxc_conf
->ns_share
[ns_idx
] = NULL
;
5198 static int get_config_includefiles(const char *key
, char *retv
, int inlen
,
5199 struct lxc_conf
*c
, void *data
)
5204 static struct lxc_config_t
*get_network_config_ops(const char *key
,
5205 struct lxc_conf
*lxc_conf
,
5207 char **deindexed_key
)
5210 unsigned int tmpidx
;
5212 char *copy
, *idx_start
, *idx_end
;
5213 struct lxc_config_t
*config
= NULL
;
5215 /* check that this is a sensible network key */
5216 if (strncmp("lxc.net.", key
, 8)) {
5217 ERROR("Invalid network configuration key \"%s\"", key
);
5223 ERROR("Failed to duplicate string \"%s\"", key
);
5228 if (!isdigit(*(key
+ 8))) {
5229 ERROR("Failed to detect digit in string \"%s\"", key
+ 8);
5233 /* beginning of index string */
5234 idx_start
= (copy
+ 7);
5237 /* end of index string */
5238 idx_end
= strchr((copy
+ 8), '.');
5242 /* parse current index */
5243 ret
= lxc_safe_uint((idx_start
+ 1), &tmpidx
);
5246 SYSERROR("Failed to parse unsigned integer from string \"%s\"",
5252 /* This, of course is utterly nonsensical on so many levels, but
5253 * better safe than sorry.
5254 * (Checking for INT_MAX here is intentional.)
5256 if (tmpidx
== INT_MAX
) {
5257 SYSERROR("Number of configured networks would overflow the "
5263 numstrlen
= strlen((idx_start
+ 1));
5265 /* repair configuration key */
5268 /* lxc.net.<idx>.<subkey> */
5271 if (strlen(idx_end
+ 1) == 0) {
5272 ERROR("No subkey in network configuration key \"%s\"", key
);
5276 memmove(copy
+ 8, idx_end
+ 1, strlen(idx_end
+ 1));
5277 copy
[strlen(key
) - (numstrlen
+ 1)] = '\0';
5279 config
= lxc_get_config(copy
);
5281 ERROR("Unknown network configuration key \"%s\"", key
);
5287 *deindexed_key
= copy
;
5296 /* Config entry is something like "lxc.net.0.ipv4" the key 'lxc.net.' was
5297 * found. So we make sure next comes an integer, find the right callback (by
5298 * rewriting the key), and call it.
5300 static int set_config_net_nic(const char *key
, const char *value
,
5301 struct lxc_conf
*lxc_conf
, void *data
)
5304 const char *idxstring
;
5305 struct lxc_config_t
*config
;
5306 struct lxc_netdev
*netdev
;
5308 char *deindexed_key
= NULL
;
5310 idxstring
= key
+ 8;
5311 if (!isdigit(*idxstring
))
5314 if (lxc_config_value_empty(value
))
5315 return clr_config_net_nic(key
, lxc_conf
, data
);
5317 config
= get_network_config_ops(key
, lxc_conf
, &idx
, &deindexed_key
);
5318 if (!config
|| idx
< 0)
5321 netdev
= lxc_get_netdev_by_idx(lxc_conf
, (unsigned int)idx
, true);
5323 free(deindexed_key
);
5327 ret
= config
->set(deindexed_key
, value
, lxc_conf
, netdev
);
5328 free(deindexed_key
);
5333 static int clr_config_net_nic(const char *key
, struct lxc_conf
*lxc_conf
,
5337 const char *idxstring
;
5338 struct lxc_config_t
*config
;
5339 struct lxc_netdev
*netdev
;
5341 char *deindexed_key
= NULL
;
5343 idxstring
= key
+ 8;
5344 if (!isdigit(*idxstring
))
5347 /* The left conjunct is pretty self-explanatory. The right conjunct
5348 * checks whether the two pointers are equal. If they are we know that
5349 * this is not a key that is namespaced any further and so we are
5350 * supposed to clear the whole network.
5352 if (isdigit(*idxstring
) && (strrchr(key
, '.') == (idxstring
- 1))) {
5353 unsigned int rmnetdevidx
;
5355 if (lxc_safe_uint(idxstring
, &rmnetdevidx
) < 0)
5358 /* Remove network from network list. */
5359 lxc_remove_nic_by_idx(lxc_conf
, rmnetdevidx
);
5363 config
= get_network_config_ops(key
, lxc_conf
, &idx
, &deindexed_key
);
5364 if (!config
|| idx
< 0)
5367 netdev
= lxc_get_netdev_by_idx(lxc_conf
, (unsigned int)idx
, false);
5369 free(deindexed_key
);
5373 ret
= config
->clr(deindexed_key
, lxc_conf
, netdev
);
5374 free(deindexed_key
);
5379 static int clr_config_net_type(const char *key
, struct lxc_conf
*lxc_conf
,
5382 struct lxc_netdev
*netdev
= data
;
5392 static int clr_config_net_name(const char *key
, struct lxc_conf
*lxc_conf
,
5395 struct lxc_netdev
*netdev
= data
;
5400 netdev
->name
[0] = '\0';
5405 static int clr_config_net_flags(const char *key
, struct lxc_conf
*lxc_conf
,
5408 struct lxc_netdev
*netdev
= data
;
5418 static int clr_config_net_link(const char *key
, struct lxc_conf
*lxc_conf
,
5421 struct lxc_netdev
*netdev
= data
;
5426 netdev
->link
[0] = '\0';
5431 static int clr_config_net_l2proxy(const char *key
, struct lxc_conf
*lxc_conf
,
5434 struct lxc_netdev
*netdev
= data
;
5437 return ret_set_errno(-1, EINVAL
);
5439 netdev
->l2proxy
= false;
5444 static int clr_config_net_macvlan_mode(const char *key
,
5445 struct lxc_conf
*lxc_conf
, void *data
)
5447 struct lxc_netdev
*netdev
= data
;
5452 if (netdev
->type
!= LXC_NET_MACVLAN
)
5455 netdev
->priv
.macvlan_attr
.mode
= -1;
5460 static int clr_config_net_ipvlan_mode(const char *key
,
5461 struct lxc_conf
*lxc_conf
, void *data
)
5463 struct lxc_netdev
*netdev
= data
;
5466 return ret_set_errno(-1, EINVAL
);
5468 if (netdev
->type
!= LXC_NET_IPVLAN
)
5471 netdev
->priv
.ipvlan_attr
.mode
= -1;
5476 static int clr_config_net_ipvlan_isolation(const char *key
,
5477 struct lxc_conf
*lxc_conf
, void *data
)
5479 struct lxc_netdev
*netdev
= data
;
5482 return ret_set_errno(-1, EINVAL
);
5484 if (netdev
->type
!= LXC_NET_IPVLAN
)
5487 netdev
->priv
.ipvlan_attr
.isolation
= -1;
5492 static int clr_config_net_veth_mode(const char *key
,
5493 struct lxc_conf
*lxc_conf
, void *data
)
5495 struct lxc_netdev
*netdev
= data
;
5498 return ret_set_errno(-1, EINVAL
);
5500 if (netdev
->type
!= LXC_NET_VETH
)
5503 netdev
->priv
.veth_attr
.mode
= -1;
5508 static int clr_config_net_veth_pair(const char *key
, struct lxc_conf
*lxc_conf
,
5511 struct lxc_netdev
*netdev
= data
;
5516 netdev
->priv
.veth_attr
.pair
[0] = '\0';
5521 static int clr_config_net_veth_vlan_id(const char *key
, struct lxc_conf
*lxc_conf
,
5524 struct lxc_netdev
*netdev
= data
;
5527 return ret_errno(EINVAL
);
5529 netdev
->priv
.veth_attr
.vlan_id
= 0;
5530 netdev
->priv
.veth_attr
.vlan_id_set
= false;
5535 static int clr_config_net_veth_vlan_tagged_id(const char *key
,
5536 struct lxc_conf
*lxc_conf
, void *data
)
5538 struct lxc_netdev
*netdev
= data
;
5539 struct lxc_list
*cur
, *next
;
5542 return ret_errno(EINVAL
);
5544 lxc_list_for_each_safe(cur
, &netdev
->priv
.veth_attr
.vlan_tagged_ids
, next
) {
5553 static int clr_config_net_script_up(const char *key
, struct lxc_conf
*lxc_conf
,
5556 struct lxc_netdev
*netdev
= data
;
5561 free(netdev
->upscript
);
5562 netdev
->upscript
= NULL
;
5567 static int clr_config_net_script_down(const char *key
,
5568 struct lxc_conf
*lxc_conf
, void *data
)
5570 struct lxc_netdev
*netdev
= data
;
5575 free(netdev
->downscript
);
5576 netdev
->downscript
= NULL
;
5581 static int clr_config_net_hwaddr(const char *key
, struct lxc_conf
*lxc_conf
,
5584 struct lxc_netdev
*netdev
= data
;
5589 free(netdev
->hwaddr
);
5590 netdev
->hwaddr
= NULL
;
5595 static int clr_config_net_mtu(const char *key
, struct lxc_conf
*lxc_conf
,
5598 struct lxc_netdev
*netdev
= data
;
5609 static int clr_config_net_vlan_id(const char *key
, struct lxc_conf
*lxc_conf
,
5612 struct lxc_netdev
*netdev
= data
;
5617 netdev
->priv
.vlan_attr
.vid
= 0;
5622 static int clr_config_net_ipv4_gateway(const char *key
,
5623 struct lxc_conf
*lxc_conf
, void *data
)
5625 struct lxc_netdev
*netdev
= data
;
5630 free(netdev
->ipv4_gateway
);
5631 netdev
->ipv4_gateway
= NULL
;
5636 static int clr_config_net_ipv4_address(const char *key
,
5637 struct lxc_conf
*lxc_conf
, void *data
)
5639 struct lxc_netdev
*netdev
= data
;
5640 struct lxc_list
*cur
, *next
;
5645 lxc_list_for_each_safe(cur
, &netdev
->ipv4
, next
) {
5654 static int clr_config_net_veth_ipv4_route(const char *key
,
5655 struct lxc_conf
*lxc_conf
, void *data
)
5657 struct lxc_netdev
*netdev
= data
;
5658 struct lxc_list
*cur
, *next
;
5663 lxc_list_for_each_safe(cur
, &netdev
->priv
.veth_attr
.ipv4_routes
, next
) {
5672 static int clr_config_net_ipv6_gateway(const char *key
,
5673 struct lxc_conf
*lxc_conf
, void *data
)
5675 struct lxc_netdev
*netdev
= data
;
5680 free(netdev
->ipv6_gateway
);
5681 netdev
->ipv6_gateway
= NULL
;
5686 static int clr_config_net_ipv6_address(const char *key
,
5687 struct lxc_conf
*lxc_conf
, void *data
)
5689 struct lxc_netdev
*netdev
= data
;
5690 struct lxc_list
*cur
, *next
;
5695 lxc_list_for_each_safe(cur
, &netdev
->ipv6
, next
) {
5704 static int clr_config_net_veth_ipv6_route(const char *key
,
5705 struct lxc_conf
*lxc_conf
, void *data
)
5707 struct lxc_netdev
*netdev
= data
;
5708 struct lxc_list
*cur
, *next
;
5713 lxc_list_for_each_safe(cur
, &netdev
->priv
.veth_attr
.ipv6_routes
, next
) {
5722 static int get_config_net_nic(const char *key
, char *retv
, int inlen
,
5723 struct lxc_conf
*c
, void *data
)
5726 const char *idxstring
;
5727 struct lxc_config_t
*config
;
5728 struct lxc_netdev
*netdev
;
5730 char *deindexed_key
= NULL
;
5732 idxstring
= key
+ 8;
5733 if (!isdigit(*idxstring
))
5736 config
= get_network_config_ops(key
, c
, &idx
, &deindexed_key
);
5737 if (!config
|| idx
< 0)
5740 netdev
= lxc_get_netdev_by_idx(c
, (unsigned int)idx
, false);
5742 free(deindexed_key
);
5746 ret
= config
->get(deindexed_key
, retv
, inlen
, c
, netdev
);
5747 free(deindexed_key
);
5752 static int get_config_net_type(const char *key
, char *retv
, int inlen
,
5753 struct lxc_conf
*c
, void *data
)
5757 struct lxc_netdev
*netdev
= data
;
5762 memset(retv
, 0, inlen
);
5767 strprint(retv
, inlen
, "%s", lxc_net_type_to_str(netdev
->type
));
5772 static int get_config_net_flags(const char *key
, char *retv
, int inlen
,
5773 struct lxc_conf
*c
, void *data
)
5777 struct lxc_netdev
*netdev
= data
;
5782 memset(retv
, 0, inlen
);
5787 if (netdev
->flags
& IFF_UP
)
5788 strprint(retv
, inlen
, "up");
5793 static int get_config_net_link(const char *key
, char *retv
, int inlen
,
5794 struct lxc_conf
*c
, void *data
)
5798 struct lxc_netdev
*netdev
= data
;
5803 memset(retv
, 0, inlen
);
5808 if (netdev
->link
[0] != '\0')
5809 strprint(retv
, inlen
, "%s", netdev
->link
);
5814 static int get_config_net_l2proxy(const char *key
, char *retv
, int inlen
,
5815 struct lxc_conf
*c
, void *data
)
5817 struct lxc_netdev
*netdev
= data
;
5818 return lxc_get_conf_bool(c
, retv
, inlen
, netdev
->l2proxy
);
5821 static int get_config_net_name(const char *key
, char *retv
, int inlen
,
5822 struct lxc_conf
*c
, void *data
)
5826 struct lxc_netdev
*netdev
= data
;
5831 memset(retv
, 0, inlen
);
5836 if (netdev
->name
[0] != '\0')
5837 strprint(retv
, inlen
, "%s", netdev
->name
);
5842 static int get_config_net_macvlan_mode(const char *key
, char *retv
, int inlen
,
5843 struct lxc_conf
*c
, void *data
)
5848 struct lxc_netdev
*netdev
= data
;
5853 memset(retv
, 0, inlen
);
5858 if (netdev
->type
!= LXC_NET_MACVLAN
)
5861 switch (netdev
->priv
.macvlan_attr
.mode
) {
5862 case MACVLAN_MODE_PRIVATE
:
5865 case MACVLAN_MODE_VEPA
:
5868 case MACVLAN_MODE_BRIDGE
:
5871 case MACVLAN_MODE_PASSTHRU
:
5879 strprint(retv
, inlen
, "%s", mode
);
5884 static int get_config_net_ipvlan_mode(const char *key
, char *retv
, int inlen
,
5885 struct lxc_conf
*c
, void *data
)
5890 struct lxc_netdev
*netdev
= data
;
5895 memset(retv
, 0, inlen
);
5898 return ret_set_errno(-1, EINVAL
);
5900 if (netdev
->type
!= LXC_NET_IPVLAN
)
5903 switch (netdev
->priv
.ipvlan_attr
.mode
) {
5904 case IPVLAN_MODE_L3
:
5907 case IPVLAN_MODE_L3S
:
5910 case IPVLAN_MODE_L2
:
5918 strprint(retv
, inlen
, "%s", mode
);
5923 static int get_config_net_ipvlan_isolation(const char *key
, char *retv
, int inlen
,
5924 struct lxc_conf
*c
, void *data
)
5929 struct lxc_netdev
*netdev
= data
;
5934 memset(retv
, 0, inlen
);
5937 return ret_set_errno(-1, EINVAL
);
5939 if (netdev
->type
!= LXC_NET_IPVLAN
)
5942 switch (netdev
->priv
.ipvlan_attr
.isolation
) {
5943 case IPVLAN_ISOLATION_BRIDGE
:
5946 case IPVLAN_ISOLATION_PRIVATE
:
5949 case IPVLAN_ISOLATION_VEPA
:
5957 strprint(retv
, inlen
, "%s", mode
);
5962 static int get_config_net_veth_mode(const char *key
, char *retv
, int inlen
,
5963 struct lxc_conf
*c
, void *data
)
5968 struct lxc_netdev
*netdev
= data
;
5973 memset(retv
, 0, inlen
);
5976 return ret_set_errno(-1, EINVAL
);
5978 if (netdev
->type
!= LXC_NET_VETH
)
5981 switch (netdev
->priv
.veth_attr
.mode
) {
5982 case VETH_MODE_BRIDGE
:
5985 case VETH_MODE_ROUTER
:
5993 strprint(retv
, inlen
, "%s", mode
);
5998 static int get_config_net_veth_pair(const char *key
, char *retv
, int inlen
,
5999 struct lxc_conf
*c
, void *data
)
6003 struct lxc_netdev
*netdev
= data
;
6008 memset(retv
, 0, inlen
);
6013 if (netdev
->type
!= LXC_NET_VETH
)
6016 strprint(retv
, inlen
, "%s",
6017 netdev
->priv
.veth_attr
.pair
[0] != '\0'
6018 ? netdev
->priv
.veth_attr
.pair
6019 : netdev
->priv
.veth_attr
.veth1
);
6024 static int get_config_net_veth_vlan_id(const char *key
, char *retv
, int inlen
,
6025 struct lxc_conf
*c
, void *data
)
6029 struct lxc_netdev
*netdev
= data
;
6032 return ret_errno(EINVAL
);
6034 if (netdev
->type
!= LXC_NET_VETH
)
6040 memset(retv
, 0, inlen
);
6042 strprint(retv
, inlen
, "%d", netdev
->priv
.veth_attr
.vlan_id
);
6047 static int get_config_net_veth_vlan_tagged_id(const char *key
, char *retv
, int inlen
,
6048 struct lxc_conf
*c
, void *data
)
6052 struct lxc_list
*it
;
6054 struct lxc_netdev
*netdev
= data
;
6057 return ret_errno(EINVAL
);
6059 if (netdev
->type
!= LXC_NET_VETH
)
6065 memset(retv
, 0, inlen
);
6067 listlen
= lxc_list_len(&netdev
->priv
.veth_attr
.vlan_tagged_ids
);
6069 lxc_list_for_each(it
, &netdev
->priv
.veth_attr
.vlan_tagged_ids
) {
6070 unsigned short i
= PTR_TO_USHORT(it
->elem
);
6071 strprint(retv
, inlen
, "%u%s", i
,
6072 (listlen
-- > 1) ? "\n" : "");
6078 static int get_config_net_script_up(const char *key
, char *retv
, int inlen
,
6079 struct lxc_conf
*c
, void *data
)
6083 struct lxc_netdev
*netdev
= data
;
6088 memset(retv
, 0, inlen
);
6093 if (netdev
->upscript
)
6094 strprint(retv
, inlen
, "%s", netdev
->upscript
);
6099 static int get_config_net_script_down(const char *key
, char *retv
, int inlen
,
6100 struct lxc_conf
*c
, void *data
)
6104 struct lxc_netdev
*netdev
= data
;
6109 memset(retv
, 0, inlen
);
6114 if (netdev
->downscript
)
6115 strprint(retv
, inlen
, "%s", netdev
->downscript
);
6120 static int get_config_net_hwaddr(const char *key
, char *retv
, int inlen
,
6121 struct lxc_conf
*c
, void *data
)
6125 struct lxc_netdev
*netdev
= data
;
6130 memset(retv
, 0, inlen
);
6136 strprint(retv
, inlen
, "%s", netdev
->hwaddr
);
6141 static int get_config_net_mtu(const char *key
, char *retv
, int inlen
,
6142 struct lxc_conf
*c
, void *data
)
6146 struct lxc_netdev
*netdev
= data
;
6151 memset(retv
, 0, inlen
);
6157 strprint(retv
, inlen
, "%s", netdev
->mtu
);
6162 static int get_config_net_vlan_id(const char *key
, char *retv
, int inlen
,
6163 struct lxc_conf
*c
, void *data
)
6167 struct lxc_netdev
*netdev
= data
;
6172 memset(retv
, 0, inlen
);
6177 if (netdev
->type
!= LXC_NET_VLAN
)
6180 strprint(retv
, inlen
, "%d", netdev
->priv
.vlan_attr
.vid
);
6185 static int get_config_net_ipv4_gateway(const char *key
, char *retv
, int inlen
,
6186 struct lxc_conf
*c
, void *data
)
6189 char buf
[INET_ADDRSTRLEN
];
6191 struct lxc_netdev
*netdev
= data
;
6196 memset(retv
, 0, inlen
);
6201 if (netdev
->ipv4_gateway_auto
) {
6202 strprint(retv
, inlen
, "auto");
6203 } else if (netdev
->ipv4_gateway_dev
) {
6204 strprint(retv
, inlen
, "dev");
6205 } else if (netdev
->ipv4_gateway
) {
6206 inet_ntop(AF_INET
, netdev
->ipv4_gateway
, buf
, sizeof(buf
));
6207 strprint(retv
, inlen
, "%s", buf
);
6213 static int get_config_net_ipv4_address(const char *key
, char *retv
, int inlen
,
6214 struct lxc_conf
*c
, void *data
)
6218 char buf
[INET_ADDRSTRLEN
];
6219 struct lxc_list
*it
;
6221 struct lxc_netdev
*netdev
= data
;
6226 memset(retv
, 0, inlen
);
6231 listlen
= lxc_list_len(&netdev
->ipv4
);
6233 lxc_list_for_each(it
, &netdev
->ipv4
) {
6234 struct lxc_inetdev
*i
= it
->elem
;
6235 inet_ntop(AF_INET
, &i
->addr
, buf
, sizeof(buf
));
6236 strprint(retv
, inlen
, "%s/%u%s", buf
, i
->prefix
,
6237 (listlen
-- > 1) ? "\n" : "");
6243 static int get_config_net_veth_ipv4_route(const char *key
, char *retv
, int inlen
,
6244 struct lxc_conf
*c
, void *data
)
6248 char buf
[INET_ADDRSTRLEN
];
6249 struct lxc_list
*it
;
6251 struct lxc_netdev
*netdev
= data
;
6256 memset(retv
, 0, inlen
);
6259 return ret_set_errno(-1, EINVAL
);
6261 if (netdev
->type
!= LXC_NET_VETH
)
6264 listlen
= lxc_list_len(&netdev
->priv
.veth_attr
.ipv4_routes
);
6266 lxc_list_for_each(it
, &netdev
->priv
.veth_attr
.ipv4_routes
) {
6267 struct lxc_inetdev
*i
= it
->elem
;
6268 inet_ntop(AF_INET
, &i
->addr
, buf
, sizeof(buf
));
6269 strprint(retv
, inlen
, "%s/%u%s", buf
, i
->prefix
,
6270 (listlen
-- > 1) ? "\n" : "");
6276 static int get_config_net_ipv6_gateway(const char *key
, char *retv
, int inlen
,
6277 struct lxc_conf
*c
, void *data
)
6280 char buf
[INET6_ADDRSTRLEN
];
6282 struct lxc_netdev
*netdev
= data
;
6287 memset(retv
, 0, inlen
);
6292 if (netdev
->ipv6_gateway_auto
) {
6293 strprint(retv
, inlen
, "auto");
6294 } else if (netdev
->ipv6_gateway_dev
) {
6295 strprint(retv
, inlen
, "dev");
6296 } else if (netdev
->ipv6_gateway
) {
6297 inet_ntop(AF_INET6
, netdev
->ipv6_gateway
, buf
, sizeof(buf
));
6298 strprint(retv
, inlen
, "%s", buf
);
6304 static int get_config_net_ipv6_address(const char *key
, char *retv
, int inlen
,
6305 struct lxc_conf
*c
, void *data
)
6309 char buf
[INET6_ADDRSTRLEN
];
6310 struct lxc_list
*it
;
6312 struct lxc_netdev
*netdev
= data
;
6317 memset(retv
, 0, inlen
);
6322 listlen
= lxc_list_len(&netdev
->ipv6
);
6324 lxc_list_for_each(it
, &netdev
->ipv6
) {
6325 struct lxc_inet6dev
*i
= it
->elem
;
6326 inet_ntop(AF_INET6
, &i
->addr
, buf
, sizeof(buf
));
6327 strprint(retv
, inlen
, "%s/%u%s", buf
, i
->prefix
,
6328 (listlen
-- > 1) ? "\n" : "");
6334 static int get_config_net_veth_ipv6_route(const char *key
, char *retv
, int inlen
,
6335 struct lxc_conf
*c
, void *data
)
6339 char buf
[INET6_ADDRSTRLEN
];
6340 struct lxc_list
*it
;
6342 struct lxc_netdev
*netdev
= data
;
6347 memset(retv
, 0, inlen
);
6350 return ret_set_errno(-1, EINVAL
);
6352 if (netdev
->type
!= LXC_NET_VETH
)
6355 listlen
= lxc_list_len(&netdev
->priv
.veth_attr
.ipv6_routes
);
6357 lxc_list_for_each(it
, &netdev
->priv
.veth_attr
.ipv6_routes
) {
6358 struct lxc_inet6dev
*i
= it
->elem
;
6359 inet_ntop(AF_INET6
, &i
->addr
, buf
, sizeof(buf
));
6360 strprint(retv
, inlen
, "%s/%u%s", buf
, i
->prefix
,
6361 (listlen
-- > 1) ? "\n" : "");
6367 int lxc_list_config_items(char *retv
, int inlen
)
6376 memset(retv
, 0, inlen
);
6378 for (i
= 0; i
< config_jump_table_size
; i
++) {
6379 char *s
= config_jump_table
[i
].name
;
6381 if (s
[strlen(s
) - 1] == '.')
6384 strprint(retv
, inlen
, "%s\n", s
);
6390 int lxc_list_subkeys(struct lxc_conf
*conf
, const char *key
, char *retv
,
6399 memset(retv
, 0, inlen
);
6401 if (!strcmp(key
, "lxc.apparmor")) {
6402 strprint(retv
, inlen
, "allow_incomplete\n");
6403 strprint(retv
, inlen
, "allow_nesting\n");
6404 strprint(retv
, inlen
, "profile\n");
6405 strprint(retv
, inlen
, "raw\n");
6406 } else if (!strcmp(key
, "lxc.cgroup")) {
6407 strprint(retv
, inlen
, "dir\n");
6408 } else if (!strcmp(key
, "lxc.selinux")) {
6409 strprint(retv
, inlen
, "context\n");
6410 strprint(retv
, inlen
, "context.keyring\n");
6411 } else if (!strcmp(key
, "lxc.mount")) {
6412 strprint(retv
, inlen
, "auto\n");
6413 strprint(retv
, inlen
, "entry\n");
6414 strprint(retv
, inlen
, "fstab\n");
6415 } else if (!strcmp(key
, "lxc.rootfs")) {
6416 strprint(retv
, inlen
, "mount\n");
6417 strprint(retv
, inlen
, "options\n");
6418 strprint(retv
, inlen
, "path\n");
6419 } else if (!strcmp(key
, "lxc.uts")) {
6420 strprint(retv
, inlen
, "name\n");
6421 } else if (!strcmp(key
, "lxc.hook")) {
6422 strprint(retv
, inlen
, "autodev\n");
6423 strprint(retv
, inlen
, "autodevtmpfssize\n");
6424 strprint(retv
, inlen
, "clone\n");
6425 strprint(retv
, inlen
, "destroy\n");
6426 strprint(retv
, inlen
, "mount\n");
6427 strprint(retv
, inlen
, "post-stop\n");
6428 strprint(retv
, inlen
, "pre-mount\n");
6429 strprint(retv
, inlen
, "pre-start\n");
6430 strprint(retv
, inlen
, "start-host\n");
6431 strprint(retv
, inlen
, "start\n");
6432 strprint(retv
, inlen
, "stop\n");
6433 } else if (!strcmp(key
, "lxc.cap")) {
6434 strprint(retv
, inlen
, "drop\n");
6435 strprint(retv
, inlen
, "keep\n");
6436 } else if (!strcmp(key
, "lxc.console")) {
6437 strprint(retv
, inlen
, "logfile\n");
6438 strprint(retv
, inlen
, "path\n");
6439 } else if (!strcmp(key
, "lxc.seccomp")) {
6440 strprint(retv
, inlen
, "profile\n");
6441 } else if (!strcmp(key
, "lxc.signal")) {
6442 strprint(retv
, inlen
, "halt\n");
6443 strprint(retv
, inlen
, "reboot\n");
6444 strprint(retv
, inlen
, "stop\n");
6445 } else if (!strcmp(key
, "lxc.start")) {
6446 strprint(retv
, inlen
, "auto\n");
6447 strprint(retv
, inlen
, "delay\n");
6448 strprint(retv
, inlen
, "order\n");
6449 } else if (!strcmp(key
, "lxc.monitor")) {
6450 strprint(retv
, inlen
, "unshare\n");
6451 } else if (!strcmp(key
, "lxc.keyring")) {
6452 strprint(retv
, inlen
, "session\n");
6460 int lxc_list_net(struct lxc_conf
*c
, const char *key
, char *retv
, int inlen
)
6463 const char *idxstring
;
6464 struct lxc_netdev
*netdev
;
6468 idxstring
= key
+ 8;
6469 if (!isdigit(*idxstring
))
6472 (void)get_network_config_ops(key
, c
, &idx
, NULL
);
6476 netdev
= lxc_get_netdev_by_idx(c
, (unsigned int)idx
, false);
6483 memset(retv
, 0, inlen
);
6485 strprint(retv
, inlen
, "type\n");
6486 strprint(retv
, inlen
, "script.up\n");
6487 strprint(retv
, inlen
, "script.down\n");
6489 if (netdev
->type
!= LXC_NET_EMPTY
) {
6490 strprint(retv
, inlen
, "flags\n");
6491 strprint(retv
, inlen
, "link\n");
6492 strprint(retv
, inlen
, "name\n");
6493 strprint(retv
, inlen
, "hwaddr\n");
6494 strprint(retv
, inlen
, "mtu\n");
6495 strprint(retv
, inlen
, "ipv6.address\n");
6496 strprint(retv
, inlen
, "ipv6.gateway\n");
6497 strprint(retv
, inlen
, "ipv4.address\n");
6498 strprint(retv
, inlen
, "ipv4.gateway\n");
6501 switch (netdev
->type
) {
6503 strprint(retv
, inlen
, "veth.pair\n");
6504 strprint(retv
, inlen
, "veth.ipv4.route\n");
6505 strprint(retv
, inlen
, "veth.ipv6.route\n");
6506 strprint(retv
, inlen
, "veth.vlan.id\n");
6508 case LXC_NET_MACVLAN
:
6509 strprint(retv
, inlen
, "macvlan.mode\n");
6511 case LXC_NET_IPVLAN
:
6512 strprint(retv
, inlen
, "ipvlan.mode\n");
6513 strprint(retv
, inlen
, "ipvlan.isolation\n");
6516 strprint(retv
, inlen
, "vlan.id\n");