2 * lxc: linux Container library
3 * (C) Copyright IBM Corp. 2007, 2008
6 * Daniel Lezcano <daniel.lezcano at free.fr>
7 * Serge Hallyn <serge@hallyn.com>
8 * Christian Brauner <christian.brauner@ubuntu.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #define __STDC_FORMAT_MACROS
29 #include <arpa/inet.h>
36 #include <netinet/in.h>
41 #include <sys/param.h>
43 #include <sys/types.h>
44 #include <sys/utsname.h>
53 #include "confile_utils.h"
54 #include "../include/netns_ifaddrs.h"
56 #include "lxcseccomp.h"
57 #include "memory_utils.h"
63 #if HAVE_SYS_PERSONALITY_H
64 #include <sys/personality.h>
68 #include "include/strlcpy.h"
72 #include "include/strlcat.h"
75 lxc_log_define(confile
, lxc
);
77 #define lxc_config_define(name) \
78 __hot static int set_config_##name(const char *, const char *, \
79 struct lxc_conf *, void *); \
80 __hot static int get_config_##name(const char *, char *, int, \
81 struct lxc_conf *, void *); \
82 __hot static int clr_config_##name(const char *, struct lxc_conf *, \
85 lxc_config_define(autodev
);
86 lxc_config_define(apparmor_allow_incomplete
);
87 lxc_config_define(apparmor_allow_nesting
);
88 lxc_config_define(apparmor_profile
);
89 lxc_config_define(apparmor_raw
);
90 lxc_config_define(cap_drop
);
91 lxc_config_define(cap_keep
);
92 lxc_config_define(cgroup_controller
);
93 lxc_config_define(cgroup2_controller
);
94 lxc_config_define(cgroup_dir
);
95 lxc_config_define(cgroup_relative
);
96 lxc_config_define(console_buffer_size
);
97 lxc_config_define(console_logfile
);
98 lxc_config_define(console_path
);
99 lxc_config_define(console_rotate
);
100 lxc_config_define(console_size
);
101 lxc_config_define(environment
);
102 lxc_config_define(ephemeral
);
103 lxc_config_define(execute_cmd
);
104 lxc_config_define(group
);
105 lxc_config_define(hooks
);
106 lxc_config_define(hooks_version
);
107 lxc_config_define(idmaps
);
108 lxc_config_define(includefiles
);
109 lxc_config_define(init_cmd
);
110 lxc_config_define(init_cwd
);
111 lxc_config_define(init_gid
);
112 lxc_config_define(init_uid
);
113 lxc_config_define(log_file
);
114 lxc_config_define(log_level
);
115 lxc_config_define(log_syslog
);
116 lxc_config_define(monitor
);
117 lxc_config_define(monitor_signal_pdeath
);
118 lxc_config_define(mount
);
119 lxc_config_define(mount_auto
);
120 lxc_config_define(mount_fstab
);
121 lxc_config_define(namespace_clone
);
122 lxc_config_define(namespace_keep
);
123 lxc_config_define(namespace_share
);
124 lxc_config_define(net
);
125 lxc_config_define(net_flags
);
126 lxc_config_define(net_hwaddr
);
127 lxc_config_define(net_ipv4_address
);
128 lxc_config_define(net_ipv4_gateway
);
129 lxc_config_define(net_ipv6_address
);
130 lxc_config_define(net_ipv6_gateway
);
131 lxc_config_define(net_link
);
132 lxc_config_define(net_macvlan_mode
);
133 lxc_config_define(net_mtu
);
134 lxc_config_define(net_name
);
135 lxc_config_define(net_nic
);
136 lxc_config_define(net_script_down
);
137 lxc_config_define(net_script_up
);
138 lxc_config_define(net_type
);
139 lxc_config_define(net_veth_pair
);
140 lxc_config_define(net_veth_ipv4_route
);
141 lxc_config_define(net_veth_ipv6_route
);
142 lxc_config_define(net_vlan_id
);
143 lxc_config_define(no_new_privs
);
144 lxc_config_define(personality
);
145 lxc_config_define(prlimit
);
146 lxc_config_define(pty_max
);
147 lxc_config_define(rootfs_managed
);
148 lxc_config_define(rootfs_mount
);
149 lxc_config_define(rootfs_options
);
150 lxc_config_define(rootfs_path
);
151 lxc_config_define(seccomp_profile
);
152 lxc_config_define(seccomp_allow_nesting
);
153 lxc_config_define(seccomp_notify_proxy
);
154 lxc_config_define(selinux_context
);
155 lxc_config_define(signal_halt
);
156 lxc_config_define(signal_reboot
);
157 lxc_config_define(signal_stop
);
158 lxc_config_define(start
);
159 lxc_config_define(tty_max
);
160 lxc_config_define(tty_dir
);
161 lxc_config_define(uts_name
);
162 lxc_config_define(sysctl
);
163 lxc_config_define(proc
);
165 static struct lxc_config_t config_jump_table
[] = {
166 { "lxc.arch", set_config_personality
, get_config_personality
, clr_config_personality
, },
167 { "lxc.apparmor.profile", set_config_apparmor_profile
, get_config_apparmor_profile
, clr_config_apparmor_profile
, },
168 { "lxc.apparmor.allow_incomplete", set_config_apparmor_allow_incomplete
, get_config_apparmor_allow_incomplete
, clr_config_apparmor_allow_incomplete
, },
169 { "lxc.apparmor.allow_nesting", set_config_apparmor_allow_nesting
, get_config_apparmor_allow_nesting
, clr_config_apparmor_allow_nesting
, },
170 { "lxc.apparmor.raw", set_config_apparmor_raw
, get_config_apparmor_raw
, clr_config_apparmor_raw
, },
171 { "lxc.autodev", set_config_autodev
, get_config_autodev
, clr_config_autodev
, },
172 { "lxc.cap.drop", set_config_cap_drop
, get_config_cap_drop
, clr_config_cap_drop
, },
173 { "lxc.cap.keep", set_config_cap_keep
, get_config_cap_keep
, clr_config_cap_keep
, },
174 { "lxc.cgroup2", set_config_cgroup2_controller
, get_config_cgroup2_controller
, clr_config_cgroup2_controller
, },
175 { "lxc.cgroup.dir", set_config_cgroup_dir
, get_config_cgroup_dir
, clr_config_cgroup_dir
, },
176 { "lxc.cgroup.relative", set_config_cgroup_relative
, get_config_cgroup_relative
, clr_config_cgroup_relative
, },
177 { "lxc.cgroup", set_config_cgroup_controller
, get_config_cgroup_controller
, clr_config_cgroup_controller
, },
178 { "lxc.console.buffer.size", set_config_console_buffer_size
, get_config_console_buffer_size
, clr_config_console_buffer_size
, },
179 { "lxc.console.logfile", set_config_console_logfile
, get_config_console_logfile
, clr_config_console_logfile
, },
180 { "lxc.console.path", set_config_console_path
, get_config_console_path
, clr_config_console_path
, },
181 { "lxc.console.rotate", set_config_console_rotate
, get_config_console_rotate
, clr_config_console_rotate
, },
182 { "lxc.console.size", set_config_console_size
, get_config_console_size
, clr_config_console_size
, },
183 { "lxc.environment", set_config_environment
, get_config_environment
, clr_config_environment
, },
184 { "lxc.ephemeral", set_config_ephemeral
, get_config_ephemeral
, clr_config_ephemeral
, },
185 { "lxc.execute.cmd", set_config_execute_cmd
, get_config_execute_cmd
, clr_config_execute_cmd
, },
186 { "lxc.group", set_config_group
, get_config_group
, clr_config_group
, },
187 { "lxc.hook.autodev", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
188 { "lxc.hook.clone", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
189 { "lxc.hook.destroy", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
190 { "lxc.hook.mount", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
191 { "lxc.hook.post-stop", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
192 { "lxc.hook.pre-mount", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
193 { "lxc.hook.pre-start", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
194 { "lxc.hook.start", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
195 { "lxc.hook.start-host", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
196 { "lxc.hook.stop", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
197 { "lxc.hook.version", set_config_hooks_version
, get_config_hooks_version
, clr_config_hooks_version
, },
198 { "lxc.hook", set_config_hooks
, get_config_hooks
, clr_config_hooks
, },
199 { "lxc.idmap", set_config_idmaps
, get_config_idmaps
, clr_config_idmaps
, },
200 { "lxc.include", set_config_includefiles
, get_config_includefiles
, clr_config_includefiles
, },
201 { "lxc.init.cmd", set_config_init_cmd
, get_config_init_cmd
, clr_config_init_cmd
, },
202 { "lxc.init.gid", set_config_init_gid
, get_config_init_gid
, clr_config_init_gid
, },
203 { "lxc.init.uid", set_config_init_uid
, get_config_init_uid
, clr_config_init_uid
, },
204 { "lxc.init.cwd", set_config_init_cwd
, get_config_init_cwd
, clr_config_init_cwd
, },
205 { "lxc.log.file", set_config_log_file
, get_config_log_file
, clr_config_log_file
, },
206 { "lxc.log.level", set_config_log_level
, get_config_log_level
, clr_config_log_level
, },
207 { "lxc.log.syslog", set_config_log_syslog
, get_config_log_syslog
, clr_config_log_syslog
, },
208 { "lxc.monitor.unshare", set_config_monitor
, get_config_monitor
, clr_config_monitor
, },
209 { "lxc.monitor.signal.pdeath", set_config_monitor_signal_pdeath
, get_config_monitor_signal_pdeath
, clr_config_monitor_signal_pdeath
, },
210 { "lxc.mount.auto", set_config_mount_auto
, get_config_mount_auto
, clr_config_mount_auto
, },
211 { "lxc.mount.entry", set_config_mount
, get_config_mount
, clr_config_mount
, },
212 { "lxc.mount.fstab", set_config_mount_fstab
, get_config_mount_fstab
, clr_config_mount_fstab
, },
213 { "lxc.namespace.clone", set_config_namespace_clone
, get_config_namespace_clone
, clr_config_namespace_clone
, },
214 { "lxc.namespace.keep", set_config_namespace_keep
, get_config_namespace_keep
, clr_config_namespace_keep
, },
215 { "lxc.namespace.share", set_config_namespace_share
, get_config_namespace_share
, clr_config_namespace_share
, },
216 { "lxc.net.flags", set_config_net_flags
, get_config_net_flags
, clr_config_net_flags
, },
217 { "lxc.net.hwaddr", set_config_net_hwaddr
, get_config_net_hwaddr
, clr_config_net_hwaddr
, },
218 { "lxc.net.ipv4.address", set_config_net_ipv4_address
, get_config_net_ipv4_address
, clr_config_net_ipv4_address
, },
219 { "lxc.net.ipv4.gateway", set_config_net_ipv4_gateway
, get_config_net_ipv4_gateway
, clr_config_net_ipv4_gateway
, },
220 { "lxc.net.ipv6.address", set_config_net_ipv6_address
, get_config_net_ipv6_address
, clr_config_net_ipv6_address
, },
221 { "lxc.net.ipv6.gateway", set_config_net_ipv6_gateway
, get_config_net_ipv6_gateway
, clr_config_net_ipv6_gateway
, },
222 { "lxc.net.link", set_config_net_link
, get_config_net_link
, clr_config_net_link
, },
223 { "lxc.net.macvlan.mode", set_config_net_macvlan_mode
, get_config_net_macvlan_mode
, clr_config_net_macvlan_mode
, },
224 { "lxc.net.mtu", set_config_net_mtu
, get_config_net_mtu
, clr_config_net_mtu
, },
225 { "lxc.net.name", set_config_net_name
, get_config_net_name
, clr_config_net_name
, },
226 { "lxc.net.script.down", set_config_net_script_down
, get_config_net_script_down
, clr_config_net_script_down
, },
227 { "lxc.net.script.up", set_config_net_script_up
, get_config_net_script_up
, clr_config_net_script_up
, },
228 { "lxc.net.type", set_config_net_type
, get_config_net_type
, clr_config_net_type
, },
229 { "lxc.net.vlan.id", set_config_net_vlan_id
, get_config_net_vlan_id
, clr_config_net_vlan_id
, },
230 { "lxc.net.veth.pair", set_config_net_veth_pair
, get_config_net_veth_pair
, clr_config_net_veth_pair
, },
231 { "lxc.net.veth.ipv4.route", set_config_net_veth_ipv4_route
, get_config_net_veth_ipv4_route
, clr_config_net_veth_ipv4_route
, },
232 { "lxc.net.veth.ipv6.route", set_config_net_veth_ipv6_route
, get_config_net_veth_ipv6_route
, clr_config_net_veth_ipv6_route
, },
233 { "lxc.net.", set_config_net_nic
, get_config_net_nic
, clr_config_net_nic
, },
234 { "lxc.net", set_config_net
, get_config_net
, clr_config_net
, },
235 { "lxc.no_new_privs", set_config_no_new_privs
, get_config_no_new_privs
, clr_config_no_new_privs
, },
236 { "lxc.prlimit", set_config_prlimit
, get_config_prlimit
, clr_config_prlimit
, },
237 { "lxc.pty.max", set_config_pty_max
, get_config_pty_max
, clr_config_pty_max
, },
238 { "lxc.rootfs.managed", set_config_rootfs_managed
, get_config_rootfs_managed
, clr_config_rootfs_managed
, },
239 { "lxc.rootfs.mount", set_config_rootfs_mount
, get_config_rootfs_mount
, clr_config_rootfs_mount
, },
240 { "lxc.rootfs.options", set_config_rootfs_options
, get_config_rootfs_options
, clr_config_rootfs_options
, },
241 { "lxc.rootfs.path", set_config_rootfs_path
, get_config_rootfs_path
, clr_config_rootfs_path
, },
242 { "lxc.seccomp.allow_nesting", set_config_seccomp_allow_nesting
, get_config_seccomp_allow_nesting
, clr_config_seccomp_allow_nesting
, },
243 { "lxc.seccomp.notify.proxy", set_config_seccomp_notify_proxy
, get_config_seccomp_notify_proxy
, clr_config_seccomp_notify_proxy
, },
244 { "lxc.seccomp.profile", set_config_seccomp_profile
, get_config_seccomp_profile
, clr_config_seccomp_profile
, },
245 { "lxc.selinux.context", set_config_selinux_context
, get_config_selinux_context
, clr_config_selinux_context
, },
246 { "lxc.signal.halt", set_config_signal_halt
, get_config_signal_halt
, clr_config_signal_halt
, },
247 { "lxc.signal.reboot", set_config_signal_reboot
, get_config_signal_reboot
, clr_config_signal_reboot
, },
248 { "lxc.signal.stop", set_config_signal_stop
, get_config_signal_stop
, clr_config_signal_stop
, },
249 { "lxc.start.auto", set_config_start
, get_config_start
, clr_config_start
, },
250 { "lxc.start.delay", set_config_start
, get_config_start
, clr_config_start
, },
251 { "lxc.start.order", set_config_start
, get_config_start
, clr_config_start
, },
252 { "lxc.tty.dir", set_config_tty_dir
, get_config_tty_dir
, clr_config_tty_dir
, },
253 { "lxc.tty.max", set_config_tty_max
, get_config_tty_max
, clr_config_tty_max
, },
254 { "lxc.uts.name", set_config_uts_name
, get_config_uts_name
, clr_config_uts_name
, },
255 { "lxc.sysctl", set_config_sysctl
, get_config_sysctl
, clr_config_sysctl
, },
256 { "lxc.proc", set_config_proc
, get_config_proc
, clr_config_proc
, },
259 static const size_t config_jump_table_size
= sizeof(config_jump_table
) / sizeof(struct lxc_config_t
);
261 struct lxc_config_t
*lxc_get_config(const char *key
)
265 for (i
= 0; i
< config_jump_table_size
; i
++)
266 if (!strncmp(config_jump_table
[i
].name
, key
, strlen(config_jump_table
[i
].name
)))
267 return &config_jump_table
[i
];
272 static int set_config_net(const char *key
, const char *value
,
273 struct lxc_conf
*lxc_conf
, void *data
)
275 if (!lxc_config_value_empty(value
)) {
276 ERROR("lxc.net must not have a value");
280 return clr_config_net(key
, lxc_conf
, data
);
283 static int set_config_net_type(const char *key
, const char *value
,
284 struct lxc_conf
*lxc_conf
, void *data
)
286 struct lxc_netdev
*netdev
= data
;
288 if (lxc_config_value_empty(value
))
289 return clr_config_net_type(key
, lxc_conf
, data
);
294 if (!strcmp(value
, "veth")) {
295 netdev
->type
= LXC_NET_VETH
;
296 lxc_list_init(&netdev
->priv
.veth_attr
.ipv4_routes
);
297 lxc_list_init(&netdev
->priv
.veth_attr
.ipv6_routes
);
298 } else if (!strcmp(value
, "macvlan")) {
299 netdev
->type
= LXC_NET_MACVLAN
;
300 lxc_macvlan_mode_to_flag(&netdev
->priv
.macvlan_attr
.mode
,
302 } else if (!strcmp(value
, "vlan")) {
303 netdev
->type
= LXC_NET_VLAN
;
304 } else if (!strcmp(value
, "phys")) {
305 netdev
->type
= LXC_NET_PHYS
;
306 } else if (!strcmp(value
, "empty")) {
307 netdev
->type
= LXC_NET_EMPTY
;
308 } else if (!strcmp(value
, "none")) {
309 netdev
->type
= LXC_NET_NONE
;
311 ERROR("Invalid network type %s", value
);
318 static int set_config_net_flags(const char *key
, const char *value
,
319 struct lxc_conf
*lxc_conf
, void *data
)
321 struct lxc_netdev
*netdev
= data
;
323 if (lxc_config_value_empty(value
))
324 return clr_config_net_flags(key
, lxc_conf
, data
);
329 netdev
->flags
|= IFF_UP
;
334 static int create_matched_ifnames(const char *value
, struct lxc_conf
*lxc_conf
,
335 struct lxc_netdev
*netdev
)
337 struct netns_ifaddrs
*ifaddr
, *ifa
;
340 const char *type_key
= "lxc.net.type";
341 const char *link_key
= "lxc.net.link";
342 const char *tmpvalue
= "phys";
344 if (netns_getifaddrs(&ifaddr
, -1, &(bool){false}) < 0) {
345 SYSERROR("Failed to get network interfaces");
349 for (ifa
= ifaddr
, n
= 0; ifa
!= NULL
; ifa
= ifa
->ifa_next
, n
++) {
353 if (ifa
->ifa_addr
->sa_family
!= AF_PACKET
)
356 if (!strncmp(value
, ifa
->ifa_name
, strlen(value
) - 1)) {
357 ret
= set_config_net_type(type_key
, tmpvalue
, lxc_conf
,
360 ret
= set_config_net_link(
361 link_key
, ifa
->ifa_name
, lxc_conf
, netdev
);
363 ERROR("Failed to create matched ifnames");
367 ERROR("Failed to create matched ifnames");
373 netns_freeifaddrs(ifaddr
);
379 static int set_config_net_link(const char *key
, const char *value
,
380 struct lxc_conf
*lxc_conf
, void *data
)
382 struct lxc_netdev
*netdev
= data
;
385 if (lxc_config_value_empty(value
))
386 return clr_config_net_link(key
, lxc_conf
, data
);
391 if (value
[strlen(value
) - 1] == '+' && netdev
->type
== LXC_NET_PHYS
)
392 ret
= create_matched_ifnames(value
, lxc_conf
, netdev
);
394 ret
= network_ifname(netdev
->link
, value
, sizeof(netdev
->link
));
399 static int set_config_net_name(const char *key
, const char *value
,
400 struct lxc_conf
*lxc_conf
, void *data
)
402 struct lxc_netdev
*netdev
= data
;
404 if (lxc_config_value_empty(value
))
405 return clr_config_net_name(key
, lxc_conf
, data
);
410 return network_ifname(netdev
->name
, value
, sizeof(netdev
->name
));
413 static int set_config_net_veth_pair(const char *key
, const char *value
,
414 struct lxc_conf
*lxc_conf
, void *data
)
416 struct lxc_netdev
*netdev
= data
;
418 if (lxc_config_value_empty(value
))
419 return clr_config_net_veth_pair(key
, lxc_conf
, data
);
424 return network_ifname(netdev
->priv
.veth_attr
.pair
, value
, sizeof(netdev
->priv
.veth_attr
.pair
));
427 static int set_config_net_macvlan_mode(const char *key
, const char *value
,
428 struct lxc_conf
*lxc_conf
, void *data
)
430 struct lxc_netdev
*netdev
= data
;
432 if (lxc_config_value_empty(value
))
433 return clr_config_net_macvlan_mode(key
, lxc_conf
, data
);
438 return lxc_macvlan_mode_to_flag(&netdev
->priv
.macvlan_attr
.mode
, value
);
441 static int set_config_net_hwaddr(const char *key
, const char *value
,
442 struct lxc_conf
*lxc_conf
, void *data
)
444 struct lxc_netdev
*netdev
= data
;
447 if (lxc_config_value_empty(value
))
448 return clr_config_net_hwaddr(key
, lxc_conf
, data
);
453 new_value
= strdup(value
);
457 rand_complete_hwaddr(new_value
);
459 if (lxc_config_value_empty(new_value
)) {
461 netdev
->hwaddr
= NULL
;
465 netdev
->hwaddr
= new_value
;
470 static int set_config_net_vlan_id(const char *key
, const char *value
,
471 struct lxc_conf
*lxc_conf
, void *data
)
474 struct lxc_netdev
*netdev
= data
;
476 if (lxc_config_value_empty(value
))
477 return clr_config_net_vlan_id(key
, lxc_conf
, data
);
482 ret
= get_u16(&netdev
->priv
.vlan_attr
.vid
, value
, 0);
489 static int set_config_net_mtu(const char *key
, const char *value
,
490 struct lxc_conf
*lxc_conf
, void *data
)
492 struct lxc_netdev
*netdev
= data
;
494 if (lxc_config_value_empty(value
))
495 return clr_config_net_mtu(key
, lxc_conf
, data
);
500 return set_config_string_item(&netdev
->mtu
, value
);
503 static int set_config_net_ipv4_address(const char *key
, const char *value
,
504 struct lxc_conf
*lxc_conf
, void *data
)
507 struct lxc_netdev
*netdev
= data
;
508 struct lxc_inetdev
*inetdev
;
509 struct lxc_list
*list
;
510 char *cursor
, *slash
;
511 char *addr
= NULL
, *bcast
= NULL
, *prefix
= NULL
;
513 if (lxc_config_value_empty(value
))
514 return clr_config_net_ipv4_address(key
, lxc_conf
, data
);
519 inetdev
= malloc(sizeof(*inetdev
));
522 memset(inetdev
, 0, sizeof(*inetdev
));
524 list
= malloc(sizeof(*list
));
531 list
->elem
= inetdev
;
533 addr
= strdup(value
);
540 cursor
= strstr(addr
, " ");
546 slash
= strstr(addr
, "/");
552 ret
= inet_pton(AF_INET
, addr
, &inetdev
->addr
);
553 if (!ret
|| ret
< 0) {
554 SYSERROR("Invalid ipv4 address \"%s\"", value
);
562 ret
= inet_pton(AF_INET
, bcast
, &inetdev
->bcast
);
563 if (!ret
|| ret
< 0) {
564 SYSERROR("Invalid ipv4 broadcast address \"%s\"", value
);
573 /* No prefix specified, determine it from the network class. */
575 ret
= lxc_safe_uint(prefix
, &inetdev
->prefix
);
583 inetdev
->prefix
= config_ip_prefix(&inetdev
->addr
);
586 /* If no broadcast address, let compute one from the
587 * prefix and address.
590 inetdev
->bcast
.s_addr
= inetdev
->addr
.s_addr
;
591 inetdev
->bcast
.s_addr
|= htonl(INADDR_BROADCAST
>> inetdev
->prefix
);
594 lxc_list_add_tail(&netdev
->ipv4
, list
);
600 static int set_config_net_ipv4_gateway(const char *key
, const char *value
,
601 struct lxc_conf
*lxc_conf
, void *data
)
603 struct lxc_netdev
*netdev
= data
;
605 if (lxc_config_value_empty(value
))
606 return clr_config_net_ipv4_gateway(key
, lxc_conf
, data
);
611 free(netdev
->ipv4_gateway
);
613 if (!strcmp(value
, "auto")) {
614 netdev
->ipv4_gateway
= NULL
;
615 netdev
->ipv4_gateway_auto
= true;
620 gw
= malloc(sizeof(*gw
));
624 ret
= inet_pton(AF_INET
, value
, gw
);
625 if (!ret
|| ret
< 0) {
626 SYSERROR("Invalid ipv4 gateway address \"%s\"", value
);
631 netdev
->ipv4_gateway
= gw
;
632 netdev
->ipv4_gateway_auto
= false;
638 static int set_config_net_veth_ipv4_route(const char *key
, const char *value
,
639 struct lxc_conf
*lxc_conf
, void *data
)
641 __do_free
char *valdup
= NULL
;
642 __do_free
struct lxc_inetdev
*inetdev
= NULL
;
643 __do_free
struct lxc_list
*list
= NULL
;
645 char *netmask
, *slash
;
646 struct lxc_netdev
*netdev
= data
;
648 if (lxc_config_value_empty(value
))
649 return clr_config_net_veth_ipv4_route(key
, lxc_conf
, data
);
652 return minus_one_set_errno(EINVAL
);
654 if (netdev
->type
!= LXC_NET_VETH
) {
655 SYSERROR("Invalid ipv4 route \"%s\", can only be used with veth network", value
);
656 return minus_one_set_errno(EINVAL
);
659 inetdev
= malloc(sizeof(*inetdev
));
662 memset(inetdev
, 0, sizeof(*inetdev
));
664 list
= malloc(sizeof(*list
));
669 list
->elem
= inetdev
;
671 valdup
= strdup(value
);
675 slash
= strchr(valdup
, '/');
677 return minus_one_set_errno(EINVAL
);
682 return minus_one_set_errno(EINVAL
);
686 ret
= lxc_safe_uint(netmask
, &inetdev
->prefix
);
687 if (ret
< 0 || inetdev
->prefix
> 32)
688 return minus_one_set_errno(EINVAL
);
690 ret
= inet_pton(AF_INET
, valdup
, &inetdev
->addr
);
692 return minus_one_set_errno(EINVAL
);
694 lxc_list_add_tail(&netdev
->priv
.veth_attr
.ipv4_routes
, list
);
701 static int set_config_net_ipv6_address(const char *key
, const char *value
,
702 struct lxc_conf
*lxc_conf
, void *data
)
705 struct lxc_netdev
*netdev
= data
;
706 struct lxc_inet6dev
*inet6dev
;
707 struct lxc_list
*list
;
708 char *slash
, *valdup
, *netmask
;
710 if (lxc_config_value_empty(value
))
711 return clr_config_net_ipv6_address(key
, lxc_conf
, data
);
716 inet6dev
= malloc(sizeof(*inet6dev
));
719 memset(inet6dev
, 0, sizeof(*inet6dev
));
721 list
= malloc(sizeof(*list
));
728 list
->elem
= inet6dev
;
730 valdup
= strdup(value
);
737 inet6dev
->prefix
= 64;
738 slash
= strstr(valdup
, "/");
743 ret
= lxc_safe_uint(netmask
, &inet6dev
->prefix
);
752 ret
= inet_pton(AF_INET6
, valdup
, &inet6dev
->addr
);
753 if (!ret
|| ret
< 0) {
754 SYSERROR("Invalid ipv6 address \"%s\"", valdup
);
761 lxc_list_add_tail(&netdev
->ipv6
, list
);
767 static int set_config_net_ipv6_gateway(const char *key
, const char *value
,
768 struct lxc_conf
*lxc_conf
, void *data
)
770 struct lxc_netdev
*netdev
= data
;
772 if (lxc_config_value_empty(value
))
773 return clr_config_net_ipv6_gateway(key
, lxc_conf
, data
);
778 free(netdev
->ipv6_gateway
);
780 if (!strcmp(value
, "auto")) {
781 netdev
->ipv6_gateway
= NULL
;
782 netdev
->ipv6_gateway_auto
= true;
787 gw
= malloc(sizeof(*gw
));
791 ret
= inet_pton(AF_INET6
, value
, gw
);
792 if (!ret
|| ret
< 0) {
793 SYSERROR("Invalid ipv6 gateway address \"%s\"", value
);
798 netdev
->ipv6_gateway
= gw
;
799 netdev
->ipv6_gateway_auto
= false;
805 static int set_config_net_veth_ipv6_route(const char *key
, const char *value
,
806 struct lxc_conf
*lxc_conf
, void *data
)
808 __do_free
char *valdup
;
809 __do_free
struct lxc_inet6dev
*inet6dev
;
810 __do_free
struct lxc_list
*list
;
812 char *netmask
, *slash
;
813 struct lxc_netdev
*netdev
= data
;
815 if (lxc_config_value_empty(value
))
816 return clr_config_net_veth_ipv6_route(key
, lxc_conf
, data
);
819 return minus_one_set_errno(EINVAL
);
821 if (netdev
->type
!= LXC_NET_VETH
) {
822 SYSERROR("Invalid ipv6 route \"%s\", can only be used with veth network", value
);
823 return minus_one_set_errno(EINVAL
);
826 inet6dev
= malloc(sizeof(*inet6dev
));
829 memset(inet6dev
, 0, sizeof(*inet6dev
));
831 list
= malloc(sizeof(*list
));
836 list
->elem
= inet6dev
;
838 valdup
= strdup(value
);
842 slash
= strchr(valdup
, '/');
844 return minus_one_set_errno(EINVAL
);
849 return minus_one_set_errno(EINVAL
);
853 ret
= lxc_safe_uint(netmask
, &inet6dev
->prefix
);
854 if (ret
< 0 || inet6dev
->prefix
> 128)
855 return minus_one_set_errno(EINVAL
);
857 ret
= inet_pton(AF_INET6
, valdup
, &inet6dev
->addr
);
859 return minus_one_set_errno(EINVAL
);
861 lxc_list_add_tail(&netdev
->priv
.veth_attr
.ipv6_routes
, list
);
868 static int set_config_net_script_up(const char *key
, const char *value
,
869 struct lxc_conf
*lxc_conf
, void *data
)
871 struct lxc_netdev
*netdev
= data
;
873 if (lxc_config_value_empty(value
))
874 return clr_config_net_script_up(key
, lxc_conf
, data
);
879 return set_config_string_item(&netdev
->upscript
, value
);
882 static int set_config_net_script_down(const char *key
, const char *value
,
883 struct lxc_conf
*lxc_conf
, void *data
)
885 struct lxc_netdev
*netdev
= data
;
887 if (lxc_config_value_empty(value
))
888 return clr_config_net_script_down(key
, lxc_conf
, data
);
893 return set_config_string_item(&netdev
->downscript
, value
);
896 static int add_hook(struct lxc_conf
*lxc_conf
, int which
, char *hook
)
898 struct lxc_list
*hooklist
;
900 hooklist
= malloc(sizeof(*hooklist
));
906 hooklist
->elem
= hook
;
907 lxc_list_add_tail(&lxc_conf
->hooks
[which
], hooklist
);
912 static int set_config_seccomp_allow_nesting(const char *key
, const char *value
,
913 struct lxc_conf
*lxc_conf
, void *data
)
915 if (lxc_config_value_empty(value
))
916 return clr_config_seccomp_allow_nesting(key
, lxc_conf
, NULL
);
918 if (lxc_safe_uint(value
, &lxc_conf
->seccomp_allow_nesting
) < 0)
921 if (lxc_conf
->seccomp_allow_nesting
> 1)
922 return minus_one_set_errno(EINVAL
);
927 static int set_config_seccomp_notify_proxy(const char *key
, const char *value
,
928 struct lxc_conf
*lxc_conf
, void *data
)
930 #if HAVE_DECL_SECCOMP_NOTIF_GET_FD
933 if (lxc_config_value_empty(value
))
934 return clr_config_seccomp_notify_proxy(key
, lxc_conf
, NULL
);
936 if (strncmp(value
, "unix:", 5) != 0)
937 return minus_one_set_errno(EINVAL
);
940 if (lxc_unix_sockaddr(&lxc_conf
->seccomp_notify_proxy_addr
, offset
) < 0)
945 return minus_one_set_errno(ENOSYS
);
949 static int set_config_seccomp_profile(const char *key
, const char *value
,
950 struct lxc_conf
*lxc_conf
, void *data
)
952 return set_config_path_item(&lxc_conf
->seccomp
, value
);
955 static int set_config_execute_cmd(const char *key
, const char *value
,
956 struct lxc_conf
*lxc_conf
, void *data
)
958 return set_config_path_item(&lxc_conf
->execute_cmd
, value
);
961 static int set_config_init_cmd(const char *key
, const char *value
,
962 struct lxc_conf
*lxc_conf
, void *data
)
964 return set_config_path_item(&lxc_conf
->init_cmd
, value
);
967 static int set_config_init_cwd(const char *key
, const char *value
,
968 struct lxc_conf
*lxc_conf
, void *data
)
970 return set_config_path_item(&lxc_conf
->init_cwd
, value
);
973 static int set_config_init_uid(const char *key
, const char *value
,
974 struct lxc_conf
*lxc_conf
, void *data
)
976 unsigned int init_uid
;
978 if (lxc_config_value_empty(value
)) {
979 lxc_conf
->init_uid
= 0;
983 if (lxc_safe_uint(value
, &init_uid
) < 0)
986 lxc_conf
->init_uid
= init_uid
;
991 static int set_config_init_gid(const char *key
, const char *value
,
992 struct lxc_conf
*lxc_conf
, void *data
)
994 unsigned int init_gid
;
996 if (lxc_config_value_empty(value
)) {
997 lxc_conf
->init_gid
= 0;
1001 if (lxc_safe_uint(value
, &init_gid
) < 0)
1004 lxc_conf
->init_gid
= init_gid
;
1009 static int set_config_hooks(const char *key
, const char *value
,
1010 struct lxc_conf
*lxc_conf
, void *data
)
1014 if (lxc_config_value_empty(value
))
1015 return lxc_clear_hooks(lxc_conf
, key
);
1017 if (strcmp(key
+ 4, "hook") == 0) {
1018 ERROR("lxc.hook must not have a value");
1022 copy
= strdup(value
);
1026 if (strcmp(key
+ 9, "pre-start") == 0)
1027 return add_hook(lxc_conf
, LXCHOOK_PRESTART
, copy
);
1028 else if (strcmp(key
+ 9, "start-host") == 0)
1029 return add_hook(lxc_conf
, LXCHOOK_START_HOST
, copy
);
1030 else if (strcmp(key
+ 9, "pre-mount") == 0)
1031 return add_hook(lxc_conf
, LXCHOOK_PREMOUNT
, copy
);
1032 else if (strcmp(key
+ 9, "autodev") == 0)
1033 return add_hook(lxc_conf
, LXCHOOK_AUTODEV
, copy
);
1034 else if (strcmp(key
+ 9, "mount") == 0)
1035 return add_hook(lxc_conf
, LXCHOOK_MOUNT
, copy
);
1036 else if (strcmp(key
+ 9, "start") == 0)
1037 return add_hook(lxc_conf
, LXCHOOK_START
, copy
);
1038 else if (strcmp(key
+ 9, "stop") == 0)
1039 return add_hook(lxc_conf
, LXCHOOK_STOP
, copy
);
1040 else if (strcmp(key
+ 9, "post-stop") == 0)
1041 return add_hook(lxc_conf
, LXCHOOK_POSTSTOP
, copy
);
1042 else if (strcmp(key
+ 9, "clone") == 0)
1043 return add_hook(lxc_conf
, LXCHOOK_CLONE
, copy
);
1044 else if (strcmp(key
+ 9, "destroy") == 0)
1045 return add_hook(lxc_conf
, LXCHOOK_DESTROY
, copy
);
1052 static int set_config_hooks_version(const char *key
, const char *value
,
1053 struct lxc_conf
*lxc_conf
, void *data
)
1058 if (lxc_config_value_empty(value
))
1059 return clr_config_hooks_version(key
, lxc_conf
, NULL
);
1061 ret
= lxc_safe_uint(value
, &tmp
);
1066 ERROR("Invalid hook version specified. Currently only 0 "
1067 "(legacy) and 1 are supported");
1071 lxc_conf
->hooks_version
= tmp
;
1076 static int set_config_personality(const char *key
, const char *value
,
1077 struct lxc_conf
*lxc_conf
, void *data
)
1079 signed long personality
= lxc_config_parse_arch(value
);
1081 if (personality
>= 0)
1082 lxc_conf
->personality
= personality
;
1084 WARN("Unsupported personality \"%s\"", value
);
1089 static int set_config_pty_max(const char *key
, const char *value
,
1090 struct lxc_conf
*lxc_conf
, void *data
)
1093 unsigned int max
= 0;
1095 if (lxc_config_value_empty(value
)) {
1096 lxc_conf
->pty_max
= 0;
1100 ret
= lxc_safe_uint(value
, &max
);
1104 lxc_conf
->pty_max
= max
;
1109 /* We only need to check whether the first byte of the key after the lxc.start.
1110 * prefix matches our expectations since they fortunately all start with a
1111 * different letter. If anything was wrong with the key we would have already
1112 * noticed when the callback was called.
1114 static int set_config_start(const char *key
, const char *value
,
1115 struct lxc_conf
*lxc_conf
, void *data
)
1119 is_empty
= lxc_config_value_empty(value
);
1121 if (*(key
+ 10) == 'a') { /* lxc.start.auto */
1123 lxc_conf
->start_auto
= 0;
1127 if (lxc_safe_uint(value
, &lxc_conf
->start_auto
) < 0)
1130 if (lxc_conf
->start_auto
> 1)
1134 } else if (*(key
+ 10) == 'd') { /* lxc.start.delay */
1136 lxc_conf
->start_delay
= 0;
1140 return lxc_safe_uint(value
, &lxc_conf
->start_delay
);
1141 } else if (*(key
+ 10) == 'o') { /* lxc.start.order */
1143 lxc_conf
->start_order
= 0;
1147 return lxc_safe_int(value
, &lxc_conf
->start_order
);
1153 static int set_config_monitor(const char *key
, const char *value
,
1154 struct lxc_conf
*lxc_conf
, void *data
)
1156 if (lxc_config_value_empty(value
)) {
1157 lxc_conf
->monitor_unshare
= 0;
1161 if (strcmp(key
+ 12, "unshare") == 0)
1162 return lxc_safe_uint(value
, &lxc_conf
->monitor_unshare
);
1167 static int set_config_monitor_signal_pdeath(const char *key
, const char *value
,
1168 struct lxc_conf
*lxc_conf
, void *data
)
1170 if (lxc_config_value_empty(value
)) {
1171 lxc_conf
->monitor_signal_pdeath
= 0;
1175 if (strcmp(key
+ 12, "signal.pdeath") == 0) {
1178 sig_n
= sig_parse(value
);
1182 lxc_conf
->monitor_signal_pdeath
= sig_n
;
1189 static int set_config_group(const char *key
, const char *value
,
1190 struct lxc_conf
*lxc_conf
, void *data
)
1192 char *groups
, *token
;
1193 struct lxc_list
*grouplist
;
1196 if (lxc_config_value_empty(value
))
1197 return lxc_clear_groups(lxc_conf
);
1199 groups
= strdup(value
);
1203 /* In case several groups are specified in a single line split these
1204 * groups in a single element for the list.
1206 lxc_iterate_parts(token
, groups
, " \t") {
1207 grouplist
= malloc(sizeof(*grouplist
));
1213 grouplist
->elem
= strdup(token
);
1214 if (!grouplist
->elem
) {
1220 lxc_list_add_tail(&lxc_conf
->groups
, grouplist
);
1228 static int set_config_environment(const char *key
, const char *value
,
1229 struct lxc_conf
*lxc_conf
, void *data
)
1231 struct lxc_list
*list_item
= NULL
;
1233 if (lxc_config_value_empty(value
))
1234 return lxc_clear_environment(lxc_conf
);
1236 list_item
= malloc(sizeof(*list_item
));
1240 if (!strchr(value
, '=')) {
1241 const char *env_val
;
1242 const char *env_key
= value
;
1243 const char *env_var
[3] = {0};
1245 env_val
= getenv(env_key
);
1249 env_var
[0] = env_key
;
1250 env_var
[1] = env_val
;
1251 list_item
->elem
= lxc_string_join("=", env_var
, false);
1253 list_item
->elem
= strdup(value
);
1256 if (!list_item
->elem
)
1259 lxc_list_add_tail(&lxc_conf
->environment
, list_item
);
1269 static int set_config_tty_max(const char *key
, const char *value
,
1270 struct lxc_conf
*lxc_conf
, void *data
)
1273 unsigned int nbtty
= 0;
1275 if (lxc_config_value_empty(value
)) {
1276 lxc_conf
->ttys
.max
= 0;
1280 ret
= lxc_safe_uint(value
, &nbtty
);
1284 lxc_conf
->ttys
.max
= nbtty
;
1289 static int set_config_tty_dir(const char *key
, const char *value
,
1290 struct lxc_conf
*lxc_conf
, void *data
)
1292 return set_config_string_item_max(&lxc_conf
->ttys
.dir
, value
,
1296 static int set_config_apparmor_profile(const char *key
, const char *value
,
1297 struct lxc_conf
*lxc_conf
, void *data
)
1299 return set_config_string_item(&lxc_conf
->lsm_aa_profile
, value
);
1302 static int set_config_apparmor_allow_incomplete(const char *key
,
1304 struct lxc_conf
*lxc_conf
,
1307 if (lxc_config_value_empty(value
)) {
1308 lxc_conf
->lsm_aa_allow_incomplete
= 0;
1312 if (lxc_safe_uint(value
, &lxc_conf
->lsm_aa_allow_incomplete
) < 0)
1315 if (lxc_conf
->lsm_aa_allow_incomplete
> 1)
1321 static int set_config_apparmor_allow_nesting(const char *key
,
1323 struct lxc_conf
*lxc_conf
,
1326 if (lxc_config_value_empty(value
))
1327 return clr_config_apparmor_allow_nesting(key
, lxc_conf
, NULL
);
1329 if (lxc_safe_uint(value
, &lxc_conf
->lsm_aa_allow_nesting
) < 0)
1332 if (lxc_conf
->lsm_aa_allow_nesting
> 1)
1338 static int set_config_apparmor_raw(const char *key
,
1340 struct lxc_conf
*lxc_conf
,
1344 struct lxc_list
*list
;
1346 if (lxc_config_value_empty(value
))
1347 return lxc_clear_apparmor_raw(lxc_conf
);
1349 list
= malloc(sizeof(*list
));
1355 elem
= strdup(value
);
1362 lxc_list_add_tail(&lxc_conf
->lsm_aa_raw
, list
);
1367 static int set_config_selinux_context(const char *key
, const char *value
,
1368 struct lxc_conf
*lxc_conf
, void *data
)
1370 return set_config_string_item(&lxc_conf
->lsm_se_context
, value
);
1373 static int set_config_log_file(const char *key
, const char *value
,
1374 struct lxc_conf
*c
, void *data
)
1378 if (lxc_config_value_empty(value
)) {
1384 /* Store these values in the lxc_conf, and then try to set for actual
1387 ret
= set_config_path_item(&c
->logfile
, value
);
1389 ret
= lxc_log_set_file(&c
->logfd
, c
->logfile
);
1394 static int set_config_log_level(const char *key
, const char *value
,
1395 struct lxc_conf
*lxc_conf
, void *data
)
1399 if (lxc_config_value_empty(value
)) {
1400 lxc_conf
->loglevel
= LXC_LOG_LEVEL_NOTSET
;
1404 if (value
[0] >= '0' && value
[0] <= '9') {
1405 if (lxc_safe_int(value
, &newlevel
) < 0)
1408 newlevel
= lxc_log_priority_to_int(value
);
1411 /* Store these values in the lxc_conf, and then try to set for actual
1414 lxc_conf
->loglevel
= newlevel
;
1416 return lxc_log_set_level(&lxc_conf
->loglevel
, newlevel
);
1419 static int set_config_autodev(const char *key
, const char *value
,
1420 struct lxc_conf
*lxc_conf
, void *data
)
1422 if (lxc_config_value_empty(value
)) {
1423 lxc_conf
->autodev
= 0;
1427 if (lxc_safe_uint(value
, &lxc_conf
->autodev
) < 0)
1430 if (lxc_conf
->autodev
> 1)
1436 static int set_config_signal_halt(const char *key
, const char *value
,
1437 struct lxc_conf
*lxc_conf
, void *data
)
1441 if (lxc_config_value_empty(value
)) {
1442 lxc_conf
->haltsignal
= 0;
1446 sig_n
= sig_parse(value
);
1450 lxc_conf
->haltsignal
= sig_n
;
1455 static int set_config_signal_reboot(const char *key
, const char *value
,
1456 struct lxc_conf
*lxc_conf
, void *data
)
1460 if (lxc_config_value_empty(value
)) {
1461 lxc_conf
->rebootsignal
= 0;
1465 sig_n
= sig_parse(value
);
1469 lxc_conf
->rebootsignal
= sig_n
;
1474 static int set_config_signal_stop(const char *key
, const char *value
,
1475 struct lxc_conf
*lxc_conf
, void *data
)
1479 if (lxc_config_value_empty(value
)) {
1480 lxc_conf
->stopsignal
= 0;
1484 sig_n
= sig_parse(value
);
1488 lxc_conf
->stopsignal
= sig_n
;
1493 static int __set_config_cgroup_controller(const char *key
, const char *value
,
1494 struct lxc_conf
*lxc_conf
, int version
)
1496 const char *subkey
, *token
;
1498 struct lxc_list
*cglist
= NULL
;
1499 struct lxc_cgroup
*cgelem
= NULL
;
1501 if (lxc_config_value_empty(value
))
1502 return lxc_clear_cgroups(lxc_conf
, key
, version
);
1504 if (version
== CGROUP2_SUPER_MAGIC
) {
1505 token
= "lxc.cgroup2.";
1507 } else if (version
== CGROUP_SUPER_MAGIC
) {
1508 token
= "lxc.cgroup.";
1514 if (strncmp(key
, token
, token_len
) != 0)
1517 subkey
= key
+ token_len
;
1518 if (*subkey
== '\0')
1521 cglist
= malloc(sizeof(*cglist
));
1525 cgelem
= malloc(sizeof(*cgelem
));
1528 memset(cgelem
, 0, sizeof(*cgelem
));
1530 cgelem
->subsystem
= strdup(subkey
);
1531 if (!cgelem
->subsystem
)
1534 cgelem
->value
= strdup(value
);
1538 cgelem
->version
= version
;
1540 lxc_list_add_elem(cglist
, cgelem
);
1542 if (version
== CGROUP2_SUPER_MAGIC
)
1543 lxc_list_add_tail(&lxc_conf
->cgroup2
, cglist
);
1545 lxc_list_add_tail(&lxc_conf
->cgroup
, cglist
);
1552 free(cgelem
->subsystem
);
1553 free(cgelem
->value
);
1560 static int set_config_cgroup_controller(const char *key
, const char *value
,
1561 struct lxc_conf
*lxc_conf
, void *data
)
1563 return __set_config_cgroup_controller(key
, value
, lxc_conf
,
1564 CGROUP_SUPER_MAGIC
);
1567 static int set_config_cgroup2_controller(const char *key
, const char *value
,
1568 struct lxc_conf
*lxc_conf
, void *data
)
1570 return __set_config_cgroup_controller(key
, value
, lxc_conf
,
1571 CGROUP2_SUPER_MAGIC
);
1575 static int set_config_cgroup_dir(const char *key
, const char *value
,
1576 struct lxc_conf
*lxc_conf
, void *data
)
1578 if (lxc_config_value_empty(value
))
1579 return clr_config_cgroup_dir(key
, lxc_conf
, NULL
);
1581 return set_config_string_item(&lxc_conf
->cgroup_meta
.dir
, value
);
1584 static int set_config_cgroup_relative(const char *key
, const char *value
,
1585 struct lxc_conf
*lxc_conf
, void *data
)
1587 unsigned int converted
;
1590 if (lxc_config_value_empty(value
))
1591 return clr_config_cgroup_relative(key
, lxc_conf
, NULL
);
1593 ret
= lxc_safe_uint(value
, &converted
);
1597 if (converted
== 1) {
1598 lxc_conf
->cgroup_meta
.relative
= true;
1602 if (converted
== 0) {
1603 lxc_conf
->cgroup_meta
.relative
= false;
1610 static bool parse_limit_value(const char **value
, rlim_t
*res
)
1612 char *endptr
= NULL
;
1614 if (strncmp(*value
, "unlimited", STRLITERALLEN("unlimited")) == 0) {
1615 *res
= RLIM_INFINITY
;
1616 *value
+= STRLITERALLEN("unlimited");
1621 *res
= strtoull(*value
, &endptr
, 10);
1622 if (errno
|| !endptr
)
1630 static int set_config_prlimit(const char *key
, const char *value
,
1631 struct lxc_conf
*lxc_conf
, void *data
)
1633 struct lxc_list
*iter
;
1634 struct rlimit limit
;
1636 struct lxc_list
*limlist
= NULL
;
1637 struct lxc_limit
*limelem
= NULL
;
1639 if (lxc_config_value_empty(value
))
1640 return lxc_clear_limits(lxc_conf
, key
);
1642 if (strncmp(key
, "lxc.prlimit.", STRLITERALLEN("lxc.prlimit.")) != 0)
1645 key
+= STRLITERALLEN("lxc.prlimit.");
1647 /* soft limit comes first in the value */
1648 if (!parse_limit_value(&value
, &limit_value
))
1651 limit
.rlim_cur
= limit_value
;
1653 /* skip spaces and a colon */
1654 while (isspace(*value
))
1659 else if (*value
) /* any other character is an error here */
1662 while (isspace(*value
))
1665 /* optional hard limit */
1667 if (!parse_limit_value(&value
, &limit_value
))
1670 limit
.rlim_max
= limit_value
;
1672 /* check for trailing garbage */
1673 while (isspace(*value
))
1679 /* a single value sets both hard and soft limit */
1680 limit
.rlim_max
= limit
.rlim_cur
;
1683 /* find existing list element */
1684 lxc_list_for_each(iter
, &lxc_conf
->limits
) {
1685 limelem
= iter
->elem
;
1686 if (!strcmp(key
, limelem
->resource
)) {
1687 limelem
->limit
= limit
;
1692 /* allocate list element */
1693 limlist
= malloc(sizeof(*limlist
));
1697 limelem
= malloc(sizeof(*limelem
));
1700 memset(limelem
, 0, sizeof(*limelem
));
1702 limelem
->resource
= strdup(key
);
1703 if (!limelem
->resource
)
1706 limelem
->limit
= limit
;
1707 lxc_list_add_elem(limlist
, limelem
);;
1708 lxc_list_add_tail(&lxc_conf
->limits
, limlist
);
1716 free(limelem
->resource
);
1723 static int set_config_sysctl(const char *key
, const char *value
,
1724 struct lxc_conf
*lxc_conf
, void *data
)
1726 struct lxc_list
*iter
;
1727 char *replace_value
= NULL
;
1728 struct lxc_list
*sysctl_list
= NULL
;
1729 struct lxc_sysctl
*sysctl_elem
= NULL
;
1731 if (lxc_config_value_empty(value
))
1732 return clr_config_sysctl(key
, lxc_conf
, NULL
);
1734 if (strncmp(key
, "lxc.sysctl.", STRLITERALLEN("lxc.sysctl.")) != 0)
1737 key
+= STRLITERALLEN("lxc.sysctl.");
1739 /* find existing list element */
1740 lxc_list_for_each(iter
, &lxc_conf
->sysctls
) {
1741 sysctl_elem
= iter
->elem
;
1743 if (strcmp(key
, sysctl_elem
->key
) != 0)
1746 replace_value
= strdup(value
);
1750 free(sysctl_elem
->value
);
1751 sysctl_elem
->value
= replace_value
;
1756 /* allocate list element */
1757 sysctl_list
= malloc(sizeof(*sysctl_list
));
1761 sysctl_elem
= malloc(sizeof(*sysctl_elem
));
1764 memset(sysctl_elem
, 0, sizeof(*sysctl_elem
));
1766 sysctl_elem
->key
= strdup(key
);
1767 if (!sysctl_elem
->key
)
1770 sysctl_elem
->value
= strdup(value
);
1771 if (!sysctl_elem
->value
)
1774 lxc_list_add_elem(sysctl_list
, sysctl_elem
);
1775 lxc_list_add_tail(&lxc_conf
->sysctls
, sysctl_list
);
1783 free(sysctl_elem
->key
);
1784 free(sysctl_elem
->value
);
1791 static int set_config_proc(const char *key
, const char *value
,
1792 struct lxc_conf
*lxc_conf
, void *data
)
1795 struct lxc_list
*proclist
= NULL
;
1796 struct lxc_proc
*procelem
= NULL
;
1798 if (lxc_config_value_empty(value
))
1799 return clr_config_proc(key
, lxc_conf
, NULL
);
1801 if (strncmp(key
, "lxc.proc.", STRLITERALLEN("lxc.proc.")) != 0)
1804 subkey
= key
+ STRLITERALLEN("lxc.proc.");
1805 if (*subkey
== '\0')
1808 proclist
= malloc(sizeof(*proclist
));
1812 procelem
= malloc(sizeof(*procelem
));
1815 memset(procelem
, 0, sizeof(*procelem
));
1817 procelem
->filename
= strdup(subkey
);
1818 procelem
->value
= strdup(value
);
1820 if (!procelem
->filename
|| !procelem
->value
)
1823 proclist
->elem
= procelem
;
1825 lxc_list_add_tail(&lxc_conf
->procs
, proclist
);
1833 free(procelem
->filename
);
1834 free(procelem
->value
);
1841 static int set_config_idmaps(const char *key
, const char *value
,
1842 struct lxc_conf
*lxc_conf
, void *data
)
1844 unsigned long hostid
, nsid
, range
;
1847 struct lxc_list
*idmaplist
= NULL
;
1848 struct id_map
*idmap
= NULL
;
1850 if (lxc_config_value_empty(value
))
1851 return lxc_clear_idmaps(lxc_conf
);
1853 idmaplist
= malloc(sizeof(*idmaplist
));
1857 idmap
= malloc(sizeof(*idmap
));
1860 memset(idmap
, 0, sizeof(*idmap
));
1862 ret
= parse_idmaps(value
, &type
, &nsid
, &hostid
, &range
);
1864 ERROR("Failed to parse id mappings");
1868 INFO("Read uid map: type %c nsid %lu hostid %lu range %lu", type
, nsid
, hostid
, range
);
1870 idmap
->idtype
= ID_TYPE_UID
;
1871 else if (type
== 'g')
1872 idmap
->idtype
= ID_TYPE_GID
;
1876 idmap
->hostid
= hostid
;
1878 idmap
->range
= range
;
1879 idmaplist
->elem
= idmap
;
1880 lxc_list_add_tail(&lxc_conf
->id_map
, idmaplist
);
1882 if (!lxc_conf
->root_nsuid_map
&& idmap
->idtype
== ID_TYPE_UID
)
1883 if (idmap
->nsid
== 0)
1884 lxc_conf
->root_nsuid_map
= idmap
;
1886 if (!lxc_conf
->root_nsgid_map
&& idmap
->idtype
== ID_TYPE_GID
)
1887 if (idmap
->nsid
== 0)
1888 lxc_conf
->root_nsgid_map
= idmap
;
1901 static int set_config_mount_fstab(const char *key
, const char *value
,
1902 struct lxc_conf
*lxc_conf
, void *data
)
1904 if (lxc_config_value_empty(value
)) {
1905 clr_config_mount_fstab(key
, lxc_conf
, NULL
);
1909 return set_config_path_item(&lxc_conf
->fstab
, value
);
1912 static int set_config_mount_auto(const char *key
, const char *value
,
1913 struct lxc_conf
*lxc_conf
, void *data
)
1915 char *autos
, *token
;
1922 } allowed_auto_mounts
[] = {
1923 { "proc", LXC_AUTO_PROC_MASK
, LXC_AUTO_PROC_MIXED
},
1924 { "proc:mixed", LXC_AUTO_PROC_MASK
, LXC_AUTO_PROC_MIXED
},
1925 { "proc:rw", LXC_AUTO_PROC_MASK
, LXC_AUTO_PROC_RW
},
1926 { "sys", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_MIXED
},
1927 { "sys:ro", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_RO
},
1928 { "sys:mixed", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_MIXED
},
1929 { "sys:rw", LXC_AUTO_SYS_MASK
, LXC_AUTO_SYS_RW
},
1930 { "cgroup", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_NOSPEC
},
1931 { "cgroup:mixed", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_MIXED
},
1932 { "cgroup:ro", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_RO
},
1933 { "cgroup:rw", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_RW
},
1934 { "cgroup:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_NOSPEC
| LXC_AUTO_CGROUP_FORCE
},
1935 { "cgroup:mixed:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_MIXED
| LXC_AUTO_CGROUP_FORCE
},
1936 { "cgroup:ro:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_RO
| LXC_AUTO_CGROUP_FORCE
},
1937 { "cgroup:rw:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_RW
| LXC_AUTO_CGROUP_FORCE
},
1938 { "cgroup-full", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_NOSPEC
},
1939 { "cgroup-full:mixed", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_MIXED
},
1940 { "cgroup-full:ro", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_RO
},
1941 { "cgroup-full:rw", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_RW
},
1942 { "cgroup-full:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_NOSPEC
| LXC_AUTO_CGROUP_FORCE
},
1943 { "cgroup-full:mixed:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_MIXED
| LXC_AUTO_CGROUP_FORCE
},
1944 { "cgroup-full:ro:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_RO
| LXC_AUTO_CGROUP_FORCE
},
1945 { "cgroup-full:rw:force", LXC_AUTO_CGROUP_MASK
, LXC_AUTO_CGROUP_FULL_RW
| LXC_AUTO_CGROUP_FORCE
},
1946 { "shmounts:", LXC_AUTO_SHMOUNTS_MASK
, LXC_AUTO_SHMOUNTS
},
1947 /* For adding anything that is just a single on/off, but has no
1948 * options: keep mask and flag identical and just define the enum
1949 * value as an unused bit so far
1954 if (lxc_config_value_empty(value
)) {
1955 lxc_conf
->auto_mounts
= 0;
1959 autos
= strdup(value
);
1963 lxc_iterate_parts(token
, autos
, " \t") {
1964 bool is_shmounts
= false;
1966 for (i
= 0; allowed_auto_mounts
[i
].token
; i
++) {
1967 if (!strcmp(allowed_auto_mounts
[i
].token
, token
))
1970 if (strcmp("shmounts:", allowed_auto_mounts
[i
].token
) == 0 &&
1971 strncmp("shmounts:", token
, STRLITERALLEN("shmounts:")) == 0) {
1977 if (!allowed_auto_mounts
[i
].token
) {
1978 ERROR("Invalid filesystem to automount \"%s\"", token
);
1982 lxc_conf
->auto_mounts
&= ~allowed_auto_mounts
[i
].mask
;
1983 lxc_conf
->auto_mounts
|= allowed_auto_mounts
[i
].flag
;
1986 char *container_path
;
1989 host_path
= token
+ STRLITERALLEN("shmounts:");
1990 if (*host_path
== '\0') {
1991 SYSERROR("Failed to copy shmounts host path");
1995 container_path
= strchr(host_path
, ':');
1996 if (!container_path
|| *(container_path
+ 1) == '\0')
1997 container_path
= "/dev/.lxc-mounts";
1999 *container_path
++ = '\0';
2001 lxc_conf
->shmount
.path_host
= strdup(host_path
);
2002 if (!lxc_conf
->shmount
.path_host
) {
2003 SYSERROR("Failed to copy shmounts host path");
2007 lxc_conf
->shmount
.path_cont
= strdup(container_path
);
2008 if(!lxc_conf
->shmount
.path_cont
) {
2009 SYSERROR("Failed to copy shmounts container path");
2023 static int set_config_mount(const char *key
, const char *value
,
2024 struct lxc_conf
*lxc_conf
, void *data
)
2027 struct lxc_list
*mntlist
;
2029 if (lxc_config_value_empty(value
))
2030 return lxc_clear_mount_entries(lxc_conf
);
2032 mntlist
= malloc(sizeof(*mntlist
));
2036 mntelem
= strdup(value
);
2041 mntlist
->elem
= mntelem
;
2043 lxc_list_add_tail(&lxc_conf
->mount_list
, mntlist
);
2048 int add_elem_to_mount_list(const char *value
, struct lxc_conf
*lxc_conf
) {
2049 return set_config_mount(NULL
, value
, lxc_conf
, NULL
);
2052 static int set_config_cap_keep(const char *key
, const char *value
,
2053 struct lxc_conf
*lxc_conf
, void *data
)
2055 char *keepcaps
, *token
;
2056 struct lxc_list
*keeplist
;
2059 if (lxc_config_value_empty(value
))
2060 return lxc_clear_config_keepcaps(lxc_conf
);
2062 keepcaps
= strdup(value
);
2066 /* In case several capability keep is specified in a single line
2067 * split these caps in a single element for the list.
2069 lxc_iterate_parts(token
, keepcaps
, " \t") {
2070 if (!strcmp(token
, "none"))
2071 lxc_clear_config_keepcaps(lxc_conf
);
2073 keeplist
= malloc(sizeof(*keeplist
));
2077 keeplist
->elem
= strdup(token
);
2078 if (!keeplist
->elem
) {
2083 lxc_list_add_tail(&lxc_conf
->keepcaps
, keeplist
);
2094 static int set_config_cap_drop(const char *key
, const char *value
,
2095 struct lxc_conf
*lxc_conf
, void *data
)
2097 char *dropcaps
, *token
;
2098 struct lxc_list
*droplist
;
2101 if (lxc_config_value_empty(value
))
2102 return lxc_clear_config_caps(lxc_conf
);
2104 dropcaps
= strdup(value
);
2108 /* In case several capability drop is specified in a single line
2109 * split these caps in a single element for the list.
2111 lxc_iterate_parts(token
, dropcaps
, " \t") {
2112 droplist
= malloc(sizeof(*droplist
));
2116 droplist
->elem
= strdup(token
);
2117 if (!droplist
->elem
) {
2122 lxc_list_add_tail(&lxc_conf
->caps
, droplist
);
2133 static int set_config_console_path(const char *key
, const char *value
,
2134 struct lxc_conf
*lxc_conf
, void *data
)
2136 return set_config_path_item(&lxc_conf
->console
.path
, value
);
2139 static int set_config_console_rotate(const char *key
, const char *value
,
2140 struct lxc_conf
*lxc_conf
, void *data
)
2142 if (lxc_config_value_empty(value
)) {
2143 lxc_conf
->console
.log_rotate
= 0;
2147 if (lxc_safe_uint(value
, &lxc_conf
->console
.log_rotate
) < 0)
2150 if (lxc_conf
->console
.log_rotate
> 1) {
2151 ERROR("The \"lxc.console.rotate\" config key can only be set "
2159 static int set_config_console_logfile(const char *key
, const char *value
,
2160 struct lxc_conf
*lxc_conf
, void *data
)
2162 return set_config_path_item(&lxc_conf
->console
.log_path
, value
);
2165 static int set_config_console_buffer_size(const char *key
, const char *value
,
2166 struct lxc_conf
*lxc_conf
, void *data
)
2170 uint64_t buffer_size
, pgsz
;
2172 if (lxc_config_value_empty(value
)) {
2173 lxc_conf
->console
.buffer_size
= 0;
2177 /* If the user specified "auto" the default log size is 2^17 = 128 Kib */
2178 if (!strcmp(value
, "auto")) {
2179 lxc_conf
->console
.buffer_size
= 1 << 17;
2183 ret
= parse_byte_size_string(value
, &size
);
2190 /* must be at least a page size */
2191 pgsz
= lxc_getpagesize();
2192 if ((uint64_t)size
< pgsz
) {
2193 NOTICE("Requested ringbuffer size for the console is %" PRId64
2194 " but must be at least %" PRId64
2195 " bytes. Setting ringbuffer size to %" PRId64
" bytes",
2200 buffer_size
= lxc_find_next_power2((uint64_t)size
);
2201 if (buffer_size
== 0)
2204 if (buffer_size
!= size
)
2205 NOTICE("Passed size was not a power of 2. Rounding log size to "
2206 "next power of two: %" PRIu64
" bytes", buffer_size
);
2208 lxc_conf
->console
.buffer_size
= buffer_size
;
2213 static int set_config_console_size(const char *key
, const char *value
,
2214 struct lxc_conf
*lxc_conf
, void *data
)
2218 uint64_t log_size
, pgsz
;
2220 if (lxc_config_value_empty(value
)) {
2221 lxc_conf
->console
.log_size
= 0;
2225 /* If the user specified "auto" the default log size is 2^17 = 128 Kib */
2226 if (!strcmp(value
, "auto")) {
2227 lxc_conf
->console
.log_size
= 1 << 17;
2231 ret
= parse_byte_size_string(value
, &size
);
2238 /* must be at least a page size */
2239 pgsz
= lxc_getpagesize();
2240 if ((uint64_t)size
< pgsz
) {
2241 NOTICE("Requested ringbuffer size for the console is %" PRId64
2242 " but must be at least %" PRId64
2243 " bytes. Setting ringbuffer size to %" PRId64
" bytes",
2248 log_size
= lxc_find_next_power2((uint64_t)size
);
2252 if (log_size
!= size
)
2253 NOTICE("Passed size was not a power of 2. Rounding log size to "
2254 "next power of two: %" PRIu64
" bytes", log_size
);
2256 lxc_conf
->console
.log_size
= log_size
;
2262 * If we find a lxc.net.[i].hwaddr or lxc.network.hwaddr in the original config
2263 * file, we expand it in the unexpanded_config, so that after a save_config we
2264 * store the hwaddr for re-use.
2265 * This is only called when reading the config file, not when executing a
2267 * 'x' and 'X' are substituted in-place.
2269 static void update_hwaddr(const char *line
)
2273 line
+= lxc_char_left_gc(line
, strlen(line
));
2277 if (!lxc_config_net_is_hwaddr(line
))
2280 /* Let config_net_hwaddr raise the error. */
2281 p
= strchr(line
, '=');
2292 rand_complete_hwaddr(p
);
2295 int append_unexp_config_line(const char *line
, struct lxc_conf
*conf
)
2298 size_t len
= conf
->unexpanded_len
;
2300 update_hwaddr(line
);
2302 linelen
= strlen(line
);
2303 while (conf
->unexpanded_alloced
<= len
+ linelen
+ 2) {
2304 char *tmp
= realloc(conf
->unexpanded_config
,
2305 conf
->unexpanded_alloced
+ 1024);
2309 if (!conf
->unexpanded_config
)
2312 conf
->unexpanded_config
= tmp
;
2313 conf
->unexpanded_alloced
+= 1024;
2316 memcpy(conf
->unexpanded_config
+ conf
->unexpanded_len
, line
, linelen
);
2317 conf
->unexpanded_len
+= linelen
;
2318 if (line
[linelen
- 1] != '\n')
2319 conf
->unexpanded_config
[conf
->unexpanded_len
++] = '\n';
2320 conf
->unexpanded_config
[conf
->unexpanded_len
] = '\0';
2325 static int do_includedir(const char *dirp
, struct lxc_conf
*lxc_conf
)
2327 struct dirent
*direntp
;
2329 char path
[PATH_MAX
];
2333 dir
= opendir(dirp
);
2337 while ((direntp
= readdir(dir
))) {
2340 fnam
= direntp
->d_name
;
2341 if (!strcmp(fnam
, "."))
2344 if (!strcmp(fnam
, ".."))
2348 if (len
< 6 || strncmp(fnam
+ len
- 5, ".conf", 5) != 0)
2351 len
= snprintf(path
, PATH_MAX
, "%s/%s", dirp
, fnam
);
2352 if (len
< 0 || len
>= PATH_MAX
) {
2357 ret
= lxc_config_read(path
, lxc_conf
, true);
2369 static int set_config_includefiles(const char *key
, const char *value
,
2370 struct lxc_conf
*lxc_conf
, void *data
)
2372 if (lxc_config_value_empty(value
)) {
2373 clr_config_includefiles(key
, lxc_conf
, NULL
);
2378 return do_includedir(value
, lxc_conf
);
2380 return lxc_config_read(value
, lxc_conf
, true);
2383 static int set_config_rootfs_path(const char *key
, const char *value
,
2384 struct lxc_conf
*lxc_conf
, void *data
)
2388 const char *container_path
;
2390 if (lxc_config_value_empty(value
)) {
2391 free(lxc_conf
->rootfs
.path
);
2392 lxc_conf
->rootfs
.path
= NULL
;
2396 dup
= strdup(value
);
2400 /* Split <storage type>:<container path> into <storage type> and
2401 * <container path>. Set "rootfs.bdev_type" to <storage type> and
2402 * "rootfs.path" to <container path>.
2404 tmp
= strchr(dup
, ':');
2408 ret
= set_config_path_item(&lxc_conf
->rootfs
.bdev_type
, dup
);
2415 container_path
= tmp
;
2417 container_path
= value
;
2420 ret
= set_config_path_item(&lxc_conf
->rootfs
.path
, container_path
);
2426 static int set_config_rootfs_managed(const char *key
, const char *value
,
2427 struct lxc_conf
*lxc_conf
, void *data
)
2429 unsigned int val
= 0;
2431 if (lxc_config_value_empty(value
)) {
2432 lxc_conf
->rootfs
.managed
= true;
2436 if (lxc_safe_uint(value
, &val
) < 0)
2441 lxc_conf
->rootfs
.managed
= false;
2444 lxc_conf
->rootfs
.managed
= true;
2451 static int set_config_rootfs_mount(const char *key
, const char *value
,
2452 struct lxc_conf
*lxc_conf
, void *data
)
2454 return set_config_path_item(&lxc_conf
->rootfs
.mount
, value
);
2457 static int set_config_rootfs_options(const char *key
, const char *value
,
2458 struct lxc_conf
*lxc_conf
, void *data
)
2461 unsigned long mflags
= 0, pflags
= 0;
2462 char *mdata
= NULL
, *opts
= NULL
;
2463 struct lxc_rootfs
*rootfs
= &lxc_conf
->rootfs
;
2465 ret
= parse_mntopts(value
, &mflags
, &mdata
);
2469 ret
= parse_propagationopts(value
, &pflags
);
2475 ret
= set_config_string_item(&opts
, value
);
2481 rootfs
->mountflags
= mflags
| pflags
;
2482 rootfs
->options
= opts
;
2483 rootfs
->data
= mdata
;
2488 static int set_config_uts_name(const char *key
, const char *value
,
2489 struct lxc_conf
*lxc_conf
, void *data
)
2491 struct utsname
*utsname
;
2493 if (lxc_config_value_empty(value
)) {
2494 clr_config_uts_name(key
, lxc_conf
, NULL
);
2498 utsname
= malloc(sizeof(*utsname
));
2502 if (strlen(value
) >= sizeof(utsname
->nodename
)) {
2507 (void)strlcpy(utsname
->nodename
, value
, sizeof(utsname
->nodename
));
2508 free(lxc_conf
->utsname
);
2509 lxc_conf
->utsname
= utsname
;
2514 static int set_config_namespace_clone(const char *key
, const char *value
,
2515 struct lxc_conf
*lxc_conf
, void *data
)
2520 if (lxc_config_value_empty(value
))
2521 return clr_config_namespace_clone(key
, lxc_conf
, data
);
2523 if (lxc_conf
->ns_keep
!= 0) {
2525 SYSERROR("Cannot set both \"lxc.namespace.clone\" and "
2526 "\"lxc.namespace.keep\"");
2534 lxc_iterate_parts(token
, ns
, " \t") {
2535 token
+= lxc_char_left_gc(token
, strlen(token
));
2536 token
[lxc_char_right_gc(token
, strlen(token
))] = '\0';
2537 cloneflag
= lxc_namespace_2_cloneflag(token
);
2538 if (cloneflag
< 0) {
2542 lxc_conf
->ns_clone
|= cloneflag
;
2549 static int set_config_namespace_keep(const char *key
, const char *value
,
2550 struct lxc_conf
*lxc_conf
, void *data
)
2555 if (lxc_config_value_empty(value
))
2556 return clr_config_namespace_keep(key
, lxc_conf
, data
);
2558 if (lxc_conf
->ns_clone
!= 0) {
2560 SYSERROR("Cannot set both \"lxc.namespace.clone\" and "
2561 "\"lxc.namespace.keep\"");
2569 lxc_iterate_parts(token
, ns
, " \t") {
2570 token
+= lxc_char_left_gc(token
, strlen(token
));
2571 token
[lxc_char_right_gc(token
, strlen(token
))] = '\0';
2572 cloneflag
= lxc_namespace_2_cloneflag(token
);
2573 if (cloneflag
< 0) {
2577 lxc_conf
->ns_keep
|= cloneflag
;
2584 static int set_config_namespace_share(const char *key
, const char *value
,
2585 struct lxc_conf
*lxc_conf
, void *data
)
2588 const char *namespace;
2590 if (lxc_config_value_empty(value
))
2591 return clr_config_namespace_share(key
, lxc_conf
, data
);
2593 namespace = key
+ STRLITERALLEN("lxc.namespace.share.");
2594 ns_idx
= lxc_namespace_2_ns_idx(namespace);
2598 return set_config_string_item(&lxc_conf
->ns_share
[ns_idx
], value
);
2601 struct parse_line_conf
{
2602 struct lxc_conf
*conf
;
2606 static int parse_line(char *buffer
, void *data
)
2608 char *dot
, *key
, *line
, *linep
, *value
;
2610 struct lxc_config_t
*config
;
2613 struct parse_line_conf
*plc
= data
;
2615 /* If there are newlines in the config file we should keep them. */
2616 empty_line
= lxc_is_line_empty(dup
);
2620 /* We have to dup the buffer otherwise, at the re-exec for reboot we
2621 * modified the original string on the stack by replacing '=' by '\0'
2624 linep
= line
= strdup(dup
);
2628 if (!plc
->from_include
) {
2629 ret
= append_unexp_config_line(line
, plc
->conf
);
2637 line
+= lxc_char_left_gc(line
, strlen(line
));
2639 /* ignore comments */
2643 /* martian option - don't add it to the config itself */
2644 if (strncmp(line
, "lxc.", 4))
2649 dot
= strchr(line
, '=');
2651 ERROR("Invalid configuration line: %s", line
);
2659 key
[lxc_char_right_gc(key
, strlen(key
))] = '\0';
2661 value
+= lxc_char_left_gc(value
, strlen(value
));
2662 value
[lxc_char_right_gc(value
, strlen(value
))] = '\0';
2664 if (*value
== '\'' || *value
== '\"') {
2667 len
= strlen(value
);
2668 if (len
> 1 && value
[len
- 1] == *value
) {
2669 value
[len
- 1] = '\0';
2674 config
= lxc_get_config(key
);
2676 ERROR("Unknown configuration key \"%s\"", key
);
2680 ret
= config
->set(key
, value
, plc
->conf
, NULL
);
2688 static struct new_config_item
*parse_new_conf_line(char *buffer
)
2690 char *dot
, *key
, *line
, *linep
, *value
;
2693 struct new_config_item
*new = NULL
;
2695 linep
= line
= strdup(dup
);
2699 line
+= lxc_char_left_gc(line
, strlen(line
));
2701 /* martian option - don't add it to the config itself */
2702 if (strncmp(line
, "lxc.", 4))
2706 dot
= strchr(line
, '=');
2708 ERROR("Invalid configuration item: %s", line
);
2716 key
[lxc_char_right_gc(key
, strlen(key
))] = '\0';
2718 value
+= lxc_char_left_gc(value
, strlen(value
));
2719 value
[lxc_char_right_gc(value
, strlen(value
))] = '\0';
2721 if (*value
== '\'' || *value
== '\"') {
2724 len
= strlen(value
);
2725 if (len
> 1 && value
[len
- 1] == *value
) {
2726 value
[len
- 1] = '\0';
2732 new = malloc(sizeof(struct new_config_item
));
2736 new->key
= strdup(key
);
2737 new->val
= strdup(value
);
2738 if (!new->val
|| !new->key
)
2746 if (ret
< 0 && new) {
2756 int lxc_config_read(const char *file
, struct lxc_conf
*conf
, bool from_include
)
2758 struct parse_line_conf c
;
2761 c
.from_include
= from_include
;
2763 /* Catch only the top level config file name in the structure. */
2765 conf
->rcfile
= strdup(file
);
2767 return lxc_file_for_each_line_mmap(file
, parse_line
, &c
);
2770 int lxc_config_define_add(struct lxc_list
*defines
, char *arg
)
2772 struct lxc_list
*dent
;
2774 dent
= malloc(sizeof(struct lxc_list
));
2778 dent
->elem
= parse_new_conf_line(arg
);
2784 lxc_list_add_tail(defines
, dent
);
2789 bool lxc_config_define_load(struct lxc_list
*defines
, struct lxc_container
*c
)
2791 struct lxc_list
*it
;
2794 lxc_list_for_each(it
, defines
) {
2795 struct new_config_item
*new_item
= it
->elem
;
2796 bret
= c
->set_config_item(c
, new_item
->key
, new_item
->val
);
2801 lxc_config_define_free(defines
);
2806 void lxc_config_define_free(struct lxc_list
*defines
)
2808 struct lxc_list
*it
, *next
;
2810 lxc_list_for_each_safe(it
, defines
, next
) {
2811 struct new_config_item
*new_item
= it
->elem
;
2812 free(new_item
->key
);
2813 free(new_item
->val
);
2819 signed long lxc_config_parse_arch(const char *arch
)
2821 #if HAVE_SYS_PERSONALITY_H
2827 { "arm", PER_LINUX32
},
2828 { "armel", PER_LINUX32
},
2829 { "armhf", PER_LINUX32
},
2830 { "armv7l", PER_LINUX32
},
2831 { "athlon", PER_LINUX32
},
2832 { "i386", PER_LINUX32
},
2833 { "i486", PER_LINUX32
},
2834 { "i586", PER_LINUX32
},
2835 { "i686", PER_LINUX32
},
2836 { "linux32", PER_LINUX32
},
2837 { "mips", PER_LINUX32
},
2838 { "mipsel", PER_LINUX32
},
2839 { "ppc", PER_LINUX32
},
2840 { "powerpc", PER_LINUX32
},
2841 { "x86", PER_LINUX32
},
2842 { "amd64", PER_LINUX
},
2843 { "arm64", PER_LINUX
},
2844 { "linux64", PER_LINUX
},
2845 { "mips64", PER_LINUX
},
2846 { "mips64el", PER_LINUX
},
2847 { "ppc64", PER_LINUX
},
2848 { "ppc64el", PER_LINUX
},
2849 { "ppc64le", PER_LINUX
},
2850 { "powerpc64", PER_LINUX
},
2851 { "s390x", PER_LINUX
},
2852 { "x86_64", PER_LINUX
},
2854 size_t len
= sizeof(pername
) / sizeof(pername
[0]);
2856 for (i
= 0; i
< len
; i
++)
2857 if (!strcmp(pername
[i
].name
, arch
))
2858 return pername
[i
].per
;
2864 int lxc_fill_elevated_privileges(char *flaglist
, int *flags
)
2872 { "CGROUP", LXC_ATTACH_MOVE_TO_CGROUP
},
2873 { "CAP", LXC_ATTACH_DROP_CAPABILITIES
},
2874 { "LSM", LXC_ATTACH_LSM_EXEC
},
2879 /* For the sake of backward compatibility, drop all privileges
2880 * if none is specified.
2882 for (i
= 0; all_privs
[i
].token
; i
++)
2883 *flags
|= all_privs
[i
].flag
;
2888 lxc_iterate_parts(token
, flaglist
, "|") {
2891 for (i
= 0; all_privs
[i
].token
; i
++)
2892 if (!strcmp(all_privs
[i
].token
, token
))
2893 aflag
= all_privs
[i
].flag
;
2904 /* Write out a configuration file. */
2905 int write_config(int fd
, const struct lxc_conf
*conf
)
2908 size_t len
= conf
->unexpanded_len
;
2913 ret
= lxc_write_nointr(fd
, conf
->unexpanded_config
, len
);
2915 SYSERROR("Failed to write configuration file");
2922 bool do_append_unexp_config_line(struct lxc_conf
*conf
, const char *key
,
2925 __do_free
char *tmp
= NULL
;
2929 len
= strlen(key
) + strlen(v
) + 4;
2930 tmp
= must_realloc(NULL
, len
);
2932 if (lxc_config_value_empty(v
))
2933 ret
= snprintf(tmp
, len
, "%s =", key
);
2935 ret
= snprintf(tmp
, len
, "%s = %s", key
, v
);
2936 if (ret
< 0 || ret
>= len
)
2939 /* Save the line verbatim into unexpanded_conf */
2940 if (append_unexp_config_line(tmp
, conf
))
2946 void clear_unexp_config_line(struct lxc_conf
*conf
, const char *key
,
2950 char *lstart
= conf
->unexpanded_config
;
2952 if (!conf
->unexpanded_config
)
2956 lend
= strchr(lstart
, '\n');
2960 lend
= lstart
+ strlen(lstart
);
2964 if (strncmp(lstart
, key
, strlen(key
)) != 0) {
2970 v
= lstart
[strlen(key
)];
2971 if (!isspace(v
) && v
!= '=') {
2977 conf
->unexpanded_len
-= (lend
- lstart
);
2979 if (*lend
== '\0') {
2984 memmove(lstart
, lend
, strlen(lend
) + 1);
2988 bool clone_update_unexp_ovl_paths(struct lxc_conf
*conf
, const char *oldpath
,
2989 const char *newpath
, const char *oldname
,
2990 const char *newname
, const char *ovldir
)
2992 __do_free
char *newdir
= NULL
,
2996 size_t newdirlen
, olddirlen
;
2997 char *lstart
= conf
->unexpanded_config
;
2998 const char *key
= "lxc.mount.entry";
3000 olddirlen
= strlen(ovldir
) + strlen(oldpath
) + strlen(oldname
) + 2;
3001 olddir
= must_realloc(NULL
, olddirlen
+ 1);
3002 ret
= snprintf(olddir
, olddirlen
+ 1, "%s=%s/%s", ovldir
, oldpath
,
3004 if (ret
< 0 || ret
>= olddirlen
+ 1)
3007 newdirlen
= strlen(ovldir
) + strlen(newpath
) + strlen(newname
) + 2;
3008 newdir
= must_realloc(NULL
, newdirlen
+ 1);
3009 ret
= snprintf(newdir
, newdirlen
+ 1, "%s=%s/%s", ovldir
, newpath
,
3011 if (ret
< 0 || ret
>= newdirlen
+ 1)
3014 if (!conf
->unexpanded_config
)
3018 lend
= strchr(lstart
, '\n');
3020 lend
= lstart
+ strlen(lstart
);
3024 if (strncmp(lstart
, key
, strlen(key
)) != 0)
3027 p
= strchr(lstart
+ strlen(key
), '=');
3038 /* Whenever a lxc.mount.entry entry is found in a line we check
3039 * if the substring "overlay" is present before doing any
3040 * further work. We check for "overlay" because substrings need
3041 * to have at least one space before them in a valid overlay
3042 * lxc.mount.entry (/A B overlay). When the space before is
3043 * missing it is very likely that these substrings are part of a
3044 * path or something else. (Checking q >= lend ensures that we
3045 * only count matches in the current line.) */
3046 q
= strstr(p
, " overlay");
3047 if (!q
|| q
>= lend
)
3050 if (!(q
= strstr(p
, olddir
)) || (q
>= lend
))
3053 /* replace the olddir with newdir */
3054 if (olddirlen
>= newdirlen
) {
3055 size_t diff
= olddirlen
- newdirlen
;
3056 memcpy(q
, newdir
, newdirlen
);
3058 if (olddirlen
!= newdirlen
) {
3059 memmove(q
+ newdirlen
, q
+ newdirlen
+ diff
,
3060 strlen(q
) - newdirlen
- diff
+ 1);
3062 conf
->unexpanded_len
-= diff
;
3066 size_t diff
= newdirlen
- olddirlen
;
3067 size_t oldlen
= conf
->unexpanded_len
;
3068 size_t newlen
= oldlen
+ diff
;
3069 size_t poffset
= q
- conf
->unexpanded_config
;
3071 new = realloc(conf
->unexpanded_config
, newlen
+ 1);
3075 conf
->unexpanded_len
= newlen
;
3076 conf
->unexpanded_alloced
= newlen
+ 1;
3077 new[newlen
- 1] = '\0';
3078 lend
= new + (lend
- conf
->unexpanded_config
);
3080 /* Move over the remainder to make room for the newdir.
3082 memmove(new + poffset
+ newdirlen
,
3083 new + poffset
+ olddirlen
,
3084 oldlen
- poffset
- olddirlen
+ 1);
3085 conf
->unexpanded_config
= new;
3087 memcpy(new + poffset
, newdir
, newdirlen
);
3098 bool clone_update_unexp_hooks(struct lxc_conf
*conf
, const char *oldpath
,
3099 const char *newpath
, const char *oldname
,
3100 const char *newname
)
3102 __do_free
char *newdir
= NULL
,
3106 char *lstart
= conf
->unexpanded_config
;
3107 size_t newdirlen
, olddirlen
;
3108 const char *key
= "lxc.hook";
3110 olddirlen
= strlen(oldpath
) + strlen(oldname
) + 1;
3111 olddir
= must_realloc(NULL
, olddirlen
+ 1);
3112 ret
= snprintf(olddir
, olddirlen
+ 1, "%s/%s", oldpath
, oldname
);
3113 if (ret
< 0 || ret
>= olddirlen
+ 1)
3116 newdirlen
= strlen(newpath
) + strlen(newname
) + 1;
3117 newdir
= must_realloc(NULL
, newdirlen
+ 1);
3118 ret
= snprintf(newdir
, newdirlen
+ 1, "%s/%s", newpath
, newname
);
3119 if (ret
< 0 || ret
>= newdirlen
+ 1)
3122 if (!conf
->unexpanded_config
)
3126 lend
= strchr(lstart
, '\n');
3128 lend
= lstart
+ strlen(lstart
);
3132 if (strncmp(lstart
, key
, strlen(key
)) != 0)
3135 p
= strchr(lstart
+ strlen(key
), '=');
3146 if (strncmp(p
, olddir
, strlen(olddir
)) != 0)
3149 /* replace the olddir with newdir */
3150 if (olddirlen
>= newdirlen
) {
3151 size_t diff
= olddirlen
- newdirlen
;
3152 memcpy(p
, newdir
, newdirlen
);
3154 if (olddirlen
!= newdirlen
) {
3155 memmove(p
+ newdirlen
, p
+ newdirlen
+ diff
,
3156 strlen(p
) - newdirlen
- diff
+ 1);
3158 conf
->unexpanded_len
-= diff
;
3162 size_t diff
= newdirlen
- olddirlen
;
3163 size_t oldlen
= conf
->unexpanded_len
;
3164 size_t newlen
= oldlen
+ diff
;
3165 size_t poffset
= p
- conf
->unexpanded_config
;
3167 new = realloc(conf
->unexpanded_config
, newlen
+ 1);
3171 conf
->unexpanded_len
= newlen
;
3172 conf
->unexpanded_alloced
= newlen
+ 1;
3173 new[newlen
- 1] = '\0';
3174 lend
= new + (lend
- conf
->unexpanded_config
);
3176 /* Move over the remainder to make room for the newdir.
3178 memmove(new + poffset
+ newdirlen
,
3179 new + poffset
+ olddirlen
,
3180 oldlen
- poffset
- olddirlen
+ 1);
3181 conf
->unexpanded_config
= new;
3183 memcpy(new + poffset
, newdir
, newdirlen
);
3197 ERROR("Error writing to new config"); \
3202 /* This is called only from clone. We wish to update all hwaddrs in the
3203 * unexpanded config file. We can't/don't want to update any which come from
3204 * lxc.includes (there shouldn't be any).
3205 * We can't just walk the c->lxc-conf->network list because that includes netifs
3206 * from the include files. So we update the ones which we find in the unexp
3207 * config file, then find the original macaddr in the conf->network, and update
3208 * that to the same value.
3210 bool network_new_hwaddrs(struct lxc_conf
*conf
)
3212 char *lend
, *p
, *p2
;
3213 struct lxc_list
*it
;
3214 char *lstart
= conf
->unexpanded_config
;
3216 if (!conf
->unexpanded_config
)
3220 char newhwaddr
[18], oldhwaddr
[17];
3222 lend
= strchr(lstart
, '\n');
3224 lend
= lstart
+ strlen(lstart
);
3228 if (!lxc_config_net_is_hwaddr(lstart
)) {
3233 p
= strchr(lstart
, '=');
3246 while (*p2
&& !isblank(*p2
) && *p2
!= '\n')
3249 if ((p2
- p
) != 17) {
3250 WARN("Bad hwaddr entry");
3255 memcpy(oldhwaddr
, p
, 17);
3257 if (!new_hwaddr(newhwaddr
))
3260 memcpy(p
, newhwaddr
, 17);
3261 lxc_list_for_each(it
, &conf
->network
) {
3262 struct lxc_netdev
*n
= it
->elem
;
3264 if (n
->hwaddr
&& memcmp(oldhwaddr
, n
->hwaddr
, 17) == 0)
3265 memcpy(n
->hwaddr
, newhwaddr
, 17);
3274 static int set_config_ephemeral(const char *key
, const char *value
,
3275 struct lxc_conf
*lxc_conf
, void *data
)
3277 if (lxc_config_value_empty(value
)) {
3278 lxc_conf
->ephemeral
= 0;
3282 if (lxc_safe_uint(value
, &lxc_conf
->ephemeral
) < 0)
3285 if (lxc_conf
->ephemeral
> 1)
3291 static int set_config_log_syslog(const char *key
, const char *value
,
3292 struct lxc_conf
*lxc_conf
, void *data
)
3296 if (lxc_conf
->syslog
) {
3297 free(lxc_conf
->syslog
);
3298 lxc_conf
->syslog
= NULL
;
3301 if (lxc_config_value_empty(value
))
3304 facility
= lxc_syslog_priority_to_int(value
);
3305 if (facility
== -EINVAL
)
3308 lxc_log_syslog(facility
);
3310 return set_config_string_item(&lxc_conf
->syslog
, value
);
3313 static int set_config_no_new_privs(const char *key
, const char *value
,
3314 struct lxc_conf
*lxc_conf
, void *data
)
3318 if (lxc_config_value_empty(value
)) {
3319 lxc_conf
->no_new_privs
= false;
3323 if (lxc_safe_uint(value
, &v
) < 0)
3329 lxc_conf
->no_new_privs
= v
? true : false;
3334 /* Callbacks to get configuration items. */
3335 static int get_config_personality(const char *key
, char *retv
, int inlen
,
3336 struct lxc_conf
*c
, void *data
)
3343 memset(retv
, 0, inlen
);
3345 #if HAVE_SYS_PERSONALITY_H
3348 switch (c
->personality
) {
3350 strprint(retv
, inlen
, "i686");
3353 strprint(retv
, inlen
, "x86_64");
3363 static int get_config_pty_max(const char *key
, char *retv
, int inlen
,
3364 struct lxc_conf
*c
, void *data
)
3366 return lxc_get_conf_size_t(c
, retv
, inlen
, c
->pty_max
);
3369 static int get_config_tty_max(const char *key
, char *retv
, int inlen
,
3370 struct lxc_conf
*c
, void *data
)
3372 return lxc_get_conf_size_t(c
, retv
, inlen
, c
->ttys
.max
);
3375 static int get_config_tty_dir(const char *key
, char *retv
, int inlen
,
3376 struct lxc_conf
*c
, void *data
)
3378 return lxc_get_conf_str(retv
, inlen
, c
->ttys
.dir
);
3381 static int get_config_apparmor_profile(const char *key
, char *retv
, int inlen
,
3382 struct lxc_conf
*c
, void *data
)
3384 return lxc_get_conf_str(retv
, inlen
, c
->lsm_aa_profile
);
3387 static int get_config_apparmor_allow_incomplete(const char *key
, char *retv
,
3388 int inlen
, struct lxc_conf
*c
,
3391 return lxc_get_conf_int(c
, retv
, inlen
,
3392 c
->lsm_aa_allow_incomplete
);
3395 static int get_config_apparmor_allow_nesting(const char *key
, char *retv
,
3396 int inlen
, struct lxc_conf
*c
,
3399 return lxc_get_conf_int(c
, retv
, inlen
,
3400 c
->lsm_aa_allow_nesting
);
3403 static int get_config_apparmor_raw(const char *key
, char *retv
,
3404 int inlen
, struct lxc_conf
*c
,
3408 struct lxc_list
*it
;
3414 memset(retv
, 0, inlen
);
3416 lxc_list_for_each(it
, &c
->lsm_aa_raw
) {
3417 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3423 static int get_config_selinux_context(const char *key
, char *retv
, int inlen
,
3424 struct lxc_conf
*c
, void *data
)
3426 return lxc_get_conf_str(retv
, inlen
, c
->lsm_se_context
);
3429 /* If you ask for a specific cgroup value, i.e. lxc.cgroup.devices.list, then
3430 * just the value(s) will be printed. Since there still could be more than one,
3431 * it is newline-separated.
3432 * (Maybe that's ambiguous, since some values, i.e. devices.list, will already
3434 * If you ask for 'lxc.cgroup", then all cgroup entries will be printed, in
3435 * 'lxc.cgroup.subsystem.key = value' format.
3437 static int __get_config_cgroup_controller(const char *key
, char *retv
,
3438 int inlen
, struct lxc_conf
*c
,
3442 size_t namespaced_token_len
;
3443 char *global_token
, *namespaced_token
;
3444 struct lxc_list
*it
;
3446 bool get_all
= false;
3451 memset(retv
, 0, inlen
);
3453 if (version
== CGROUP2_SUPER_MAGIC
) {
3454 global_token
= "lxc.cgroup2";
3455 namespaced_token
= "lxc.cgroup2.";
3456 namespaced_token_len
= STRLITERALLEN("lxc.cgroup2.");
3457 } else if (version
== CGROUP_SUPER_MAGIC
) {
3458 global_token
= "lxc.cgroup";
3459 namespaced_token
= "lxc.cgroup.";
3460 namespaced_token_len
= STRLITERALLEN("lxc.cgroup.");
3465 if (strcmp(key
, global_token
) == 0)
3467 else if (strncmp(key
, namespaced_token
, namespaced_token_len
) == 0)
3468 key
+= namespaced_token_len
;
3472 lxc_list_for_each(it
, &c
->cgroup
) {
3473 struct lxc_cgroup
*cg
= it
->elem
;
3476 if (version
!= cg
->version
)
3479 strprint(retv
, inlen
, "%s.%s = %s\n", global_token
,
3480 cg
->subsystem
, cg
->value
);
3481 } else if (strcmp(cg
->subsystem
, key
) == 0) {
3482 strprint(retv
, inlen
, "%s\n", cg
->value
);
3489 static int get_config_cgroup_controller(const char *key
, char *retv
, int inlen
,
3490 struct lxc_conf
*c
, void *data
)
3492 return __get_config_cgroup_controller(key
, retv
, inlen
, c
,
3493 CGROUP_SUPER_MAGIC
);
3496 static int get_config_cgroup2_controller(const char *key
, char *retv
, int inlen
,
3497 struct lxc_conf
*c
, void *data
)
3499 return __get_config_cgroup_controller(key
, retv
, inlen
, c
,
3500 CGROUP2_SUPER_MAGIC
);
3503 static int get_config_cgroup_dir(const char *key
, char *retv
, int inlen
,
3504 struct lxc_conf
*lxc_conf
, void *data
)
3512 memset(retv
, 0, inlen
);
3514 strprint(retv
, inlen
, "%s", lxc_conf
->cgroup_meta
.dir
);
3519 static inline int get_config_cgroup_relative(const char *key
, char *retv
,
3520 int inlen
, struct lxc_conf
*lxc_conf
,
3523 return lxc_get_conf_int(lxc_conf
, retv
, inlen
,
3524 lxc_conf
->cgroup_meta
.relative
);
3527 static int get_config_idmaps(const char *key
, char *retv
, int inlen
,
3528 struct lxc_conf
*c
, void *data
)
3530 struct lxc_list
*it
;
3531 int len
, listlen
, ret
;
3533 /* "u 1000 1000000 65536"
3535 * let's render this as
3553 #define __LXC_IDMAP_STR_BUF (3 * INTTYPE_TO_STRLEN(uint32_t) + 3 + 1 + 1)
3554 char buf
[__LXC_IDMAP_STR_BUF
];
3559 memset(retv
, 0, inlen
);
3561 listlen
= lxc_list_len(&c
->id_map
);
3562 lxc_list_for_each(it
, &c
->id_map
) {
3563 struct id_map
*map
= it
->elem
;
3564 ret
= snprintf(buf
, __LXC_IDMAP_STR_BUF
, "%c %lu %lu %lu",
3565 (map
->idtype
== ID_TYPE_UID
) ? 'u' : 'g',
3566 map
->nsid
, map
->hostid
, map
->range
);
3567 if (ret
< 0 || ret
>= __LXC_IDMAP_STR_BUF
)
3570 strprint(retv
, inlen
, "%s%s", buf
, (listlen
-- > 1) ? "\n" : "");
3576 static int get_config_log_level(const char *key
, char *retv
, int inlen
,
3577 struct lxc_conf
*c
, void *data
)
3580 v
= lxc_log_priority_to_string(c
->loglevel
);
3581 return lxc_get_conf_str(retv
, inlen
, v
);
3584 static int get_config_log_file(const char *key
, char *retv
, int inlen
,
3585 struct lxc_conf
*c
, void *data
)
3587 return lxc_get_conf_str(retv
, inlen
, c
->logfile
);
3590 static int get_config_mount_fstab(const char *key
, char *retv
, int inlen
,
3591 struct lxc_conf
*c
, void *data
)
3593 return lxc_get_conf_str(retv
, inlen
, c
->fstab
);
3596 static int get_config_mount_auto(const char *key
, char *retv
, int inlen
,
3597 struct lxc_conf
*c
, void *data
)
3599 int len
, fulllen
= 0;
3600 const char *sep
= "";
3605 memset(retv
, 0, inlen
);
3607 if (!(c
->auto_mounts
& LXC_AUTO_ALL_MASK
))
3610 switch (c
->auto_mounts
& LXC_AUTO_PROC_MASK
) {
3611 case LXC_AUTO_PROC_MIXED
:
3612 strprint(retv
, inlen
, "%sproc:mixed", sep
);
3615 case LXC_AUTO_PROC_RW
:
3616 strprint(retv
, inlen
, "%sproc:rw", sep
);
3623 switch (c
->auto_mounts
& LXC_AUTO_SYS_MASK
) {
3624 case LXC_AUTO_SYS_RO
:
3625 strprint(retv
, inlen
, "%ssys:ro", sep
);
3628 case LXC_AUTO_SYS_RW
:
3629 strprint(retv
, inlen
, "%ssys:rw", sep
);
3632 case LXC_AUTO_SYS_MIXED
:
3633 strprint(retv
, inlen
, "%ssys:mixed", sep
);
3640 switch (c
->auto_mounts
& LXC_AUTO_CGROUP_MASK
) {
3641 case LXC_AUTO_CGROUP_NOSPEC
:
3642 strprint(retv
, inlen
, "%scgroup", sep
);
3644 case LXC_AUTO_CGROUP_MIXED
:
3645 strprint(retv
, inlen
, "%scgroup:mixed", sep
);
3647 case LXC_AUTO_CGROUP_RO
:
3648 strprint(retv
, inlen
, "%scgroup:ro", sep
);
3650 case LXC_AUTO_CGROUP_RW
:
3651 strprint(retv
, inlen
, "%scgroup:rw", sep
);
3653 case LXC_AUTO_CGROUP_FULL_NOSPEC
:
3654 strprint(retv
, inlen
, "%scgroup-full", sep
);
3656 case LXC_AUTO_CGROUP_FULL_MIXED
:
3657 strprint(retv
, inlen
, "%scgroup-full:mixed", sep
);
3659 case LXC_AUTO_CGROUP_FULL_RO
:
3660 strprint(retv
, inlen
, "%scgroup-full:ro", sep
);
3662 case LXC_AUTO_CGROUP_FULL_RW
:
3663 strprint(retv
, inlen
, "%scgroup-full:rw", sep
);
3672 static int get_config_mount(const char *key
, char *retv
, int inlen
,
3673 struct lxc_conf
*c
, void *data
)
3675 int len
, fulllen
= 0;
3676 struct lxc_list
*it
;
3681 memset(retv
, 0, inlen
);
3683 lxc_list_for_each(it
, &c
->mount_list
) {
3684 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3690 static int get_config_rootfs_path(const char *key
, char *retv
, int inlen
,
3691 struct lxc_conf
*c
, void *data
)
3693 return lxc_get_conf_str(retv
, inlen
, c
->rootfs
.path
);
3696 static int get_config_rootfs_managed(const char *key
, char *retv
, int inlen
,
3697 struct lxc_conf
*c
, void *data
)
3699 return lxc_get_conf_bool(c
, retv
, inlen
, c
->rootfs
.managed
);
3702 static int get_config_rootfs_mount(const char *key
, char *retv
, int inlen
,
3703 struct lxc_conf
*c
, void *data
)
3705 return lxc_get_conf_str(retv
, inlen
, c
->rootfs
.mount
);
3708 static int get_config_rootfs_options(const char *key
, char *retv
, int inlen
,
3709 struct lxc_conf
*c
, void *data
)
3711 return lxc_get_conf_str(retv
, inlen
, c
->rootfs
.options
);
3714 static int get_config_uts_name(const char *key
, char *retv
, int inlen
,
3715 struct lxc_conf
*c
, void *data
)
3717 return lxc_get_conf_str(
3719 c
->utsname
? c
->utsname
->nodename
: NULL
);
3722 static int get_config_hooks(const char *key
, char *retv
, int inlen
,
3723 struct lxc_conf
*c
, void *data
)
3726 int len
, fulllen
= 0, found
= -1;
3727 struct lxc_list
*it
;
3730 subkey
= strchr(key
, '.');
3734 subkey
= strchr(subkey
+ 1, '.');
3738 if (*subkey
== '\0')
3741 for (i
= 0; i
< NUM_LXC_HOOKS
; i
++) {
3742 if (strcmp(lxchook_names
[i
], subkey
) == 0) {
3754 memset(retv
, 0, inlen
);
3756 lxc_list_for_each(it
, &c
->hooks
[found
]) {
3757 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3763 static int get_config_hooks_version(const char *key
, char *retv
, int inlen
,
3764 struct lxc_conf
*c
, void *data
)
3766 return lxc_get_conf_int(c
, retv
, inlen
, c
->hooks_version
);
3769 static int get_config_net(const char *key
, char *retv
, int inlen
,
3770 struct lxc_conf
*c
, void *data
)
3772 int len
, fulllen
= 0;
3773 struct lxc_list
*it
;
3778 memset(retv
, 0, inlen
);
3780 lxc_list_for_each(it
, &c
->network
) {
3781 struct lxc_netdev
*n
= it
->elem
;
3782 const char *t
= lxc_net_type_to_str(n
->type
);
3783 strprint(retv
, inlen
, "%s\n", t
? t
: "(invalid)");
3789 static int get_config_cap_drop(const char *key
, char *retv
, int inlen
,
3790 struct lxc_conf
*c
, void *data
)
3792 int len
, fulllen
= 0;
3793 struct lxc_list
*it
;
3798 memset(retv
, 0, inlen
);
3800 lxc_list_for_each(it
, &c
->caps
) {
3801 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3807 static int get_config_cap_keep(const char *key
, char *retv
, int inlen
,
3808 struct lxc_conf
*c
, void *data
)
3810 int len
, fulllen
= 0;
3811 struct lxc_list
*it
;
3816 memset(retv
, 0, inlen
);
3818 lxc_list_for_each(it
, &c
->keepcaps
) {
3819 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3825 static int get_config_console_path(const char *key
, char *retv
, int inlen
,
3826 struct lxc_conf
*c
, void *data
)
3828 return lxc_get_conf_str(retv
, inlen
, c
->console
.path
);
3831 static int get_config_console_logfile(const char *key
, char *retv
, int inlen
,
3832 struct lxc_conf
*c
, void *data
)
3834 return lxc_get_conf_str(retv
, inlen
, c
->console
.log_path
);
3837 static int get_config_console_rotate(const char *key
, char *retv
, int inlen
,
3838 struct lxc_conf
*c
, void *data
)
3840 return lxc_get_conf_int(c
, retv
, inlen
, c
->console
.log_rotate
);
3844 static int get_config_console_buffer_size(const char *key
, char *retv
,
3845 int inlen
, struct lxc_conf
*c
,
3848 return lxc_get_conf_uint64(c
, retv
, inlen
, c
->console
.buffer_size
);
3851 static int get_config_console_size(const char *key
, char *retv
, int inlen
,
3852 struct lxc_conf
*c
, void *data
)
3854 return lxc_get_conf_uint64(c
, retv
, inlen
, c
->console
.log_size
);
3857 static int get_config_seccomp_allow_nesting(const char *key
, char *retv
,
3858 int inlen
, struct lxc_conf
*c
,
3861 return lxc_get_conf_int(c
, retv
, inlen
, c
->seccomp_allow_nesting
);
3864 static int get_config_seccomp_notify_proxy(const char *key
, char *retv
, int inlen
,
3865 struct lxc_conf
*c
, void *data
)
3867 #if HAVE_DECL_SECCOMP_NOTIF_GET_FD
3868 return lxc_get_conf_str(retv
, inlen
,
3869 (c
->seccomp_notify_proxy_addr
.sun_path
[0]) == '/'
3870 ? &c
->seccomp_notify_proxy_addr
.sun_path
[0]
3871 : &c
->seccomp_notify_proxy_addr
.sun_path
[1]);
3873 return minus_one_set_errno(ENOSYS
);
3877 static int get_config_seccomp_profile(const char *key
, char *retv
, int inlen
,
3878 struct lxc_conf
*c
, void *data
)
3880 return lxc_get_conf_str(retv
, inlen
, c
->seccomp
);
3883 static int get_config_autodev(const char *key
, char *retv
, int inlen
,
3884 struct lxc_conf
*c
, void *data
)
3886 return lxc_get_conf_int(c
, retv
, inlen
, c
->autodev
);
3889 static int get_config_signal_halt(const char *key
, char *retv
, int inlen
,
3890 struct lxc_conf
*c
, void *data
)
3892 return lxc_get_conf_int(c
, retv
, inlen
, c
->haltsignal
);
3895 static int get_config_signal_reboot(const char *key
, char *retv
, int inlen
,
3896 struct lxc_conf
*c
, void *data
)
3898 return lxc_get_conf_int(c
, retv
, inlen
, c
->rebootsignal
);
3901 static int get_config_signal_stop(const char *key
, char *retv
, int inlen
,
3902 struct lxc_conf
*c
, void *data
)
3904 return lxc_get_conf_int(c
, retv
, inlen
, c
->stopsignal
);
3907 static int get_config_start(const char *key
, char *retv
, int inlen
,
3908 struct lxc_conf
*c
, void *data
)
3910 if (strcmp(key
+ 10, "auto") == 0)
3911 return lxc_get_conf_int(c
, retv
, inlen
, c
->start_auto
);
3912 else if (strcmp(key
+ 10, "delay") == 0)
3913 return lxc_get_conf_int(c
, retv
, inlen
, c
->start_delay
);
3914 else if (strcmp(key
+ 10, "order") == 0)
3915 return lxc_get_conf_int(c
, retv
, inlen
, c
->start_order
);
3920 static int get_config_log_syslog(const char *key
, char *retv
, int inlen
,
3921 struct lxc_conf
*c
, void *data
)
3923 return lxc_get_conf_str(retv
, inlen
, c
->syslog
);
3926 static int get_config_monitor(const char *key
, char *retv
, int inlen
,
3927 struct lxc_conf
*c
, void *data
)
3929 return lxc_get_conf_int(c
, retv
, inlen
, c
->monitor_unshare
);
3932 static int get_config_monitor_signal_pdeath(const char *key
, char *retv
,
3933 int inlen
, struct lxc_conf
*c
,
3936 return lxc_get_conf_int(c
, retv
, inlen
, c
->monitor_signal_pdeath
);
3939 static int get_config_group(const char *key
, char *retv
, int inlen
,
3940 struct lxc_conf
*c
, void *data
)
3942 int len
, fulllen
= 0;
3943 struct lxc_list
*it
;
3948 memset(retv
, 0, inlen
);
3950 lxc_list_for_each(it
, &c
->groups
) {
3951 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3957 static int get_config_environment(const char *key
, char *retv
, int inlen
,
3958 struct lxc_conf
*c
, void *data
)
3960 int len
, fulllen
= 0;
3961 struct lxc_list
*it
;
3966 memset(retv
, 0, inlen
);
3968 lxc_list_for_each(it
, &c
->environment
) {
3969 strprint(retv
, inlen
, "%s\n", (char *)it
->elem
);
3975 static int get_config_execute_cmd(const char *key
, char *retv
, int inlen
,
3976 struct lxc_conf
*c
, void *data
)
3978 return lxc_get_conf_str(retv
, inlen
, c
->execute_cmd
);
3981 static int get_config_init_cmd(const char *key
, char *retv
, int inlen
,
3982 struct lxc_conf
*c
, void *data
)
3984 return lxc_get_conf_str(retv
, inlen
, c
->init_cmd
);
3987 static int get_config_init_cwd(const char *key
, char *retv
, int inlen
,
3988 struct lxc_conf
*c
, void *data
)
3990 return lxc_get_conf_str(retv
, inlen
, c
->init_cwd
);
3993 static int get_config_init_uid(const char *key
, char *retv
, int inlen
,
3994 struct lxc_conf
*c
, void *data
)
3996 return lxc_get_conf_int(c
, retv
, inlen
, c
->init_uid
);
3999 static int get_config_init_gid(const char *key
, char *retv
, int inlen
,
4000 struct lxc_conf
*c
, void *data
)
4002 return lxc_get_conf_int(c
, retv
, inlen
, c
->init_gid
);
4005 static int get_config_ephemeral(const char *key
, char *retv
, int inlen
,
4006 struct lxc_conf
*c
, void *data
)
4008 return lxc_get_conf_int(c
, retv
, inlen
, c
->ephemeral
);
4011 static int get_config_no_new_privs(const char *key
, char *retv
, int inlen
,
4012 struct lxc_conf
*c
, void *data
)
4014 return lxc_get_conf_int(c
, retv
, inlen
, c
->no_new_privs
);
4017 /* If you ask for a specific value, i.e. lxc.prlimit.nofile, then just the value
4018 * will be printed. If you ask for 'lxc.prlimit', then all limit entries will be
4019 * printed, in 'lxc.prlimit.resource = value' format.
4021 static int get_config_prlimit(const char *key
, char *retv
, int inlen
,
4022 struct lxc_conf
*c
, void *data
)
4024 int fulllen
= 0, len
;
4025 bool get_all
= false;
4026 struct lxc_list
*it
;
4031 memset(retv
, 0, inlen
);
4033 if (!strcmp(key
, "lxc.prlimit"))
4035 else if (strncmp(key
, "lxc.prlimit.", 12) == 0)
4040 lxc_list_for_each(it
, &c
->limits
) {
4041 /* 2 colon separated 64 bit integers or the word 'unlimited' */
4042 char buf
[INTTYPE_TO_STRLEN(uint64_t) * 2 + 2];
4044 struct lxc_limit
*lim
= it
->elem
;
4046 if (lim
->limit
.rlim_cur
== RLIM_INFINITY
) {
4047 memcpy(buf
, "unlimited", STRLITERALLEN("unlimited") + 1);
4048 partlen
= STRLITERALLEN("unlimited");
4050 partlen
= sprintf(buf
, "%" PRIu64
,
4051 (uint64_t)lim
->limit
.rlim_cur
);
4054 if (lim
->limit
.rlim_cur
!= lim
->limit
.rlim_max
) {
4055 if (lim
->limit
.rlim_max
== RLIM_INFINITY
)
4056 memcpy(buf
+ partlen
, ":unlimited",
4057 STRLITERALLEN(":unlimited") + 1);
4059 sprintf(buf
+ partlen
, ":%" PRIu64
,
4060 (uint64_t)lim
->limit
.rlim_max
);
4064 strprint(retv
, inlen
, "lxc.prlimit.%s = %s\n",
4065 lim
->resource
, buf
);
4066 } else if (strcmp(lim
->resource
, key
) == 0) {
4067 strprint(retv
, inlen
, "%s", buf
);
4074 /* If you ask for a specific value, i.e. lxc.sysctl.net.ipv4.ip_forward, then
4075 * just the value will be printed. If you ask for 'lxc.sysctl', then all sysctl
4076 * entries will be printed, in 'lxc.sysctl.key = value' format.
4078 static int get_config_sysctl(const char *key
, char *retv
, int inlen
,
4079 struct lxc_conf
*c
, void *data
)
4082 struct lxc_list
*it
;
4084 bool get_all
= false;
4089 memset(retv
, 0, inlen
);
4091 if (strcmp(key
, "lxc.sysctl") == 0)
4093 else if (strncmp(key
, "lxc.sysctl.", STRLITERALLEN("lxc.sysctl.")) == 0)
4094 key
+= STRLITERALLEN("lxc.sysctl.");
4098 lxc_list_for_each(it
, &c
->sysctls
) {
4099 struct lxc_sysctl
*elem
= it
->elem
;
4101 strprint(retv
, inlen
, "lxc.sysctl.%s = %s\n", elem
->key
,
4103 } else if (strcmp(elem
->key
, key
) == 0) {
4104 strprint(retv
, inlen
, "%s", elem
->value
);
4111 static int get_config_proc(const char *key
, char *retv
, int inlen
,
4112 struct lxc_conf
*c
, void *data
)
4114 struct lxc_list
*it
;
4117 bool get_all
= false;
4122 memset(retv
, 0, inlen
);
4124 if (strcmp(key
, "lxc.proc") == 0)
4126 else if (strncmp(key
, "lxc.proc.", STRLITERALLEN("lxc.proc.")) == 0)
4127 key
+= STRLITERALLEN("lxc.proc.");
4131 lxc_list_for_each(it
, &c
->procs
) {
4132 struct lxc_proc
*proc
= it
->elem
;
4135 strprint(retv
, inlen
, "lxc.proc.%s = %s\n",
4136 proc
->filename
, proc
->value
);
4137 } else if (strcmp(proc
->filename
, key
) == 0) {
4138 strprint(retv
, inlen
, "%s", proc
->value
);
4145 static int get_config_namespace_clone(const char *key
, char *retv
, int inlen
,
4146 struct lxc_conf
*c
, void *data
)
4154 memset(retv
, 0, inlen
);
4156 for (i
= 0; i
< LXC_NS_MAX
; i
++) {
4157 if (c
->ns_clone
& ns_info
[i
].clone_flag
)
4158 strprint(retv
, inlen
, "%s\n", ns_info
[i
].proc_name
);
4164 static int get_config_namespace_keep(const char *key
, char *retv
, int inlen
,
4165 struct lxc_conf
*c
, void *data
)
4173 memset(retv
, 0, inlen
);
4175 for (i
= 0; i
< LXC_NS_MAX
; i
++) {
4176 if (c
->ns_keep
& ns_info
[i
].clone_flag
)
4177 strprint(retv
, inlen
, "%s\n", ns_info
[i
].proc_name
);
4183 static int get_config_namespace_share(const char *key
, char *retv
, int inlen
,
4184 struct lxc_conf
*c
, void *data
)
4187 const char *namespace;
4193 memset(retv
, 0, inlen
);
4195 namespace = key
+ STRLITERALLEN("lxc.namespace.share.");
4196 ns_idx
= lxc_namespace_2_ns_idx(namespace);
4200 strprint(retv
, inlen
, "%s", c
->ns_share
[ns_idx
]);
4205 /* Callbacks to clear config items. */
4206 static inline int clr_config_personality(const char *key
, struct lxc_conf
*c
,
4209 c
->personality
= -1;
4213 static inline int clr_config_pty_max(const char *key
, struct lxc_conf
*c
,
4220 static inline int clr_config_tty_max(const char *key
, struct lxc_conf
*c
,
4227 static inline int clr_config_tty_dir(const char *key
, struct lxc_conf
*c
,
4235 static inline int clr_config_apparmor_profile(const char *key
,
4236 struct lxc_conf
*c
, void *data
)
4238 free(c
->lsm_aa_profile
);
4239 c
->lsm_aa_profile
= NULL
;
4243 static inline int clr_config_apparmor_allow_incomplete(const char *key
,
4247 c
->lsm_aa_allow_incomplete
= 0;
4251 static inline int clr_config_apparmor_allow_nesting(const char *key
,
4255 c
->lsm_aa_allow_nesting
= 0;
4259 static inline int clr_config_apparmor_raw(const char *key
,
4263 return lxc_clear_apparmor_raw(c
);
4266 static inline int clr_config_selinux_context(const char *key
,
4267 struct lxc_conf
*c
, void *data
)
4269 free(c
->lsm_se_context
);
4270 c
->lsm_se_context
= NULL
;
4274 static inline int clr_config_cgroup_controller(const char *key
,
4275 struct lxc_conf
*c
, void *data
)
4277 return lxc_clear_cgroups(c
, key
, CGROUP_SUPER_MAGIC
);
4280 static inline int clr_config_cgroup2_controller(const char *key
,
4281 struct lxc_conf
*c
, void *data
)
4283 return lxc_clear_cgroups(c
, key
, CGROUP2_SUPER_MAGIC
);
4286 static int clr_config_cgroup_dir(const char *key
, struct lxc_conf
*lxc_conf
,
4289 if (lxc_conf
->cgroup_meta
.dir
) {
4290 free(lxc_conf
->cgroup_meta
.dir
);
4291 lxc_conf
->cgroup_meta
.dir
= NULL
;
4297 static inline int clr_config_cgroup_relative(const char *key
,
4298 struct lxc_conf
*lxc_conf
,
4301 lxc_conf
->cgroup_meta
.relative
= false;
4305 static inline int clr_config_idmaps(const char *key
, struct lxc_conf
*c
,
4308 return lxc_clear_idmaps(c
);
4311 static inline int clr_config_log_level(const char *key
, struct lxc_conf
*c
,
4314 c
->loglevel
= LXC_LOG_LEVEL_NOTSET
;
4318 static inline int clr_config_log_file(const char *key
, struct lxc_conf
*c
,
4326 static inline int clr_config_mount(const char *key
, struct lxc_conf
*c
,
4329 return lxc_clear_mount_entries(c
);
4332 static inline int clr_config_mount_auto(const char *key
, struct lxc_conf
*c
,
4335 return lxc_clear_automounts(c
);
4338 static inline int clr_config_mount_fstab(const char *key
, struct lxc_conf
*c
,
4346 static inline int clr_config_rootfs_path(const char *key
, struct lxc_conf
*c
,
4349 free(c
->rootfs
.path
);
4350 c
->rootfs
.path
= NULL
;
4354 static inline int clr_config_rootfs_managed(const char *key
, struct lxc_conf
*c
,
4357 c
->rootfs
.managed
= true;
4361 static inline int clr_config_rootfs_mount(const char *key
, struct lxc_conf
*c
,
4364 free(c
->rootfs
.mount
);
4365 c
->rootfs
.mount
= NULL
;
4369 static inline int clr_config_rootfs_options(const char *key
, struct lxc_conf
*c
,
4372 free(c
->rootfs
.options
);
4373 c
->rootfs
.options
= NULL
;
4375 free(c
->rootfs
.data
);
4376 c
->rootfs
.data
= NULL
;
4381 static inline int clr_config_uts_name(const char *key
, struct lxc_conf
*c
,
4389 static inline int clr_config_hooks(const char *key
, struct lxc_conf
*c
,
4392 return lxc_clear_hooks(c
, key
);
4395 static inline int clr_config_hooks_version(const char *key
, struct lxc_conf
*c
,
4398 /* default to legacy hooks version */
4399 c
->hooks_version
= 0;
4403 static inline int clr_config_net(const char *key
, struct lxc_conf
*c
,
4406 lxc_free_networks(&c
->network
);
4411 static inline int clr_config_cap_drop(const char *key
, struct lxc_conf
*c
,
4414 return lxc_clear_config_caps(c
);
4417 static inline int clr_config_cap_keep(const char *key
, struct lxc_conf
*c
,
4420 return lxc_clear_config_keepcaps(c
);
4423 static inline int clr_config_console_path(const char *key
, struct lxc_conf
*c
,
4426 free(c
->console
.path
);
4427 c
->console
.path
= NULL
;
4431 static inline int clr_config_console_logfile(const char *key
,
4432 struct lxc_conf
*c
, void *data
)
4434 free(c
->console
.log_path
);
4435 c
->console
.log_path
= NULL
;
4439 static inline int clr_config_console_rotate(const char *key
, struct lxc_conf
*c
,
4442 c
->console
.log_rotate
= 0;
4446 static inline int clr_config_console_buffer_size(const char *key
,
4447 struct lxc_conf
*c
, void *data
)
4449 c
->console
.buffer_size
= 0;
4453 static inline int clr_config_console_size(const char *key
, struct lxc_conf
*c
,
4456 c
->console
.log_size
= 0;
4460 static inline int clr_config_seccomp_allow_nesting(const char *key
,
4461 struct lxc_conf
*c
, void *data
)
4463 c
->seccomp_allow_nesting
= 0;
4467 static inline int clr_config_seccomp_notify_proxy(const char *key
,
4468 struct lxc_conf
*c
, void *data
)
4470 #if HAVE_DECL_SECCOMP_NOTIF_GET_FD
4471 memset(&c
->seccomp_notify_proxy_addr
, 0,
4472 sizeof(c
->seccomp_notify_proxy_addr
));
4475 return minus_one_set_errno(ENOSYS
);
4479 static inline int clr_config_seccomp_profile(const char *key
,
4480 struct lxc_conf
*c
, void *data
)
4487 static inline int clr_config_autodev(const char *key
, struct lxc_conf
*c
,
4494 static inline int clr_config_signal_halt(const char *key
, struct lxc_conf
*c
,
4501 static inline int clr_config_signal_reboot(const char *key
, struct lxc_conf
*c
,
4504 c
->rebootsignal
= 0;
4508 static inline int clr_config_signal_stop(const char *key
, struct lxc_conf
*c
,
4515 static inline int clr_config_start(const char *key
, struct lxc_conf
*c
,
4518 if (strcmp(key
+ 10, "auto") == 0)
4520 else if (strcmp(key
+ 10, "delay") == 0)
4522 else if (strcmp(key
+ 10, "order") == 0)
4528 static inline int clr_config_log_syslog(const char *key
, struct lxc_conf
*c
,
4536 static inline int clr_config_monitor(const char *key
, struct lxc_conf
*c
,
4539 c
->monitor_unshare
= 0;
4543 static inline int clr_config_monitor_signal_pdeath(const char *key
,
4544 struct lxc_conf
*c
, void *data
)
4546 c
->monitor_signal_pdeath
= 0;
4550 static inline int clr_config_group(const char *key
, struct lxc_conf
*c
,
4553 return lxc_clear_groups(c
);
4556 static inline int clr_config_environment(const char *key
, struct lxc_conf
*c
,
4559 return lxc_clear_environment(c
);
4562 static inline int clr_config_execute_cmd(const char *key
, struct lxc_conf
*c
,
4565 free(c
->execute_cmd
);
4566 c
->execute_cmd
= NULL
;
4570 static inline int clr_config_init_cmd(const char *key
, struct lxc_conf
*c
,
4578 static inline int clr_config_init_cwd(const char *key
, struct lxc_conf
*c
,
4586 static inline int clr_config_init_uid(const char *key
, struct lxc_conf
*c
,
4593 static inline int clr_config_init_gid(const char *key
, struct lxc_conf
*c
,
4600 static inline int clr_config_ephemeral(const char *key
, struct lxc_conf
*c
,
4607 static inline int clr_config_no_new_privs(const char *key
, struct lxc_conf
*c
,
4610 c
->no_new_privs
= false;
4614 static inline int clr_config_prlimit(const char *key
, struct lxc_conf
*c
,
4617 return lxc_clear_limits(c
, key
);
4620 static inline int clr_config_sysctl(const char *key
, struct lxc_conf
*c
,
4623 return lxc_clear_sysctls(c
, key
);
4626 static inline int clr_config_proc(const char *key
, struct lxc_conf
*c
,
4629 return lxc_clear_procs(c
, key
);
4632 static inline int clr_config_includefiles(const char *key
, struct lxc_conf
*c
,
4635 lxc_clear_includes(c
);
4639 static int clr_config_namespace_clone(const char *key
,
4640 struct lxc_conf
*lxc_conf
, void *data
)
4642 lxc_conf
->ns_clone
= 0;
4646 static int clr_config_namespace_keep(const char *key
, struct lxc_conf
*lxc_conf
,
4649 lxc_conf
->ns_keep
= 0;
4653 static int clr_config_namespace_share(const char *key
,
4654 struct lxc_conf
*lxc_conf
, void *data
)
4657 const char *namespace;
4659 namespace = key
+ STRLITERALLEN("lxc.namespace.share.");
4660 ns_idx
= lxc_namespace_2_ns_idx(namespace);
4664 free(lxc_conf
->ns_share
[ns_idx
]);
4665 lxc_conf
->ns_share
[ns_idx
] = NULL
;
4670 static int get_config_includefiles(const char *key
, char *retv
, int inlen
,
4671 struct lxc_conf
*c
, void *data
)
4676 static struct lxc_config_t
*get_network_config_ops(const char *key
,
4677 struct lxc_conf
*lxc_conf
,
4679 char **deindexed_key
)
4682 unsigned int tmpidx
;
4684 char *copy
, *idx_start
, *idx_end
;
4685 struct lxc_config_t
*config
= NULL
;
4687 /* check that this is a sensible network key */
4688 if (strncmp("lxc.net.", key
, 8)) {
4689 ERROR("Invalid network configuration key \"%s\"", key
);
4695 ERROR("Failed to duplicate string \"%s\"", key
);
4700 if (!isdigit(*(key
+ 8))) {
4701 ERROR("Failed to detect digit in string \"%s\"", key
+ 8);
4705 /* beginning of index string */
4706 idx_start
= (copy
+ 7);
4709 /* end of index string */
4710 idx_end
= strchr((copy
+ 8), '.');
4714 /* parse current index */
4715 ret
= lxc_safe_uint((idx_start
+ 1), &tmpidx
);
4718 SYSERROR("Failed to parse unsigned integer from string \"%s\"",
4724 /* This, of course is utterly nonsensical on so many levels, but
4725 * better safe than sorry.
4726 * (Checking for INT_MAX here is intentional.)
4728 if (tmpidx
== INT_MAX
) {
4729 SYSERROR("Number of configured networks would overflow the "
4735 numstrlen
= strlen((idx_start
+ 1));
4737 /* repair configuration key */
4740 /* lxc.net.<idx>.<subkey> */
4743 if (strlen(idx_end
+ 1) == 0) {
4744 ERROR("No subkey in network configuration key \"%s\"", key
);
4748 memmove(copy
+ 8, idx_end
+ 1, strlen(idx_end
+ 1));
4749 copy
[strlen(key
) - numstrlen
+ 1] = '\0';
4751 config
= lxc_get_config(copy
);
4753 ERROR("Unknown network configuration key \"%s\"", key
);
4759 *deindexed_key
= copy
;
4768 /* Config entry is something like "lxc.net.0.ipv4" the key 'lxc.net.' was
4769 * found. So we make sure next comes an integer, find the right callback (by
4770 * rewriting the key), and call it.
4772 static int set_config_net_nic(const char *key
, const char *value
,
4773 struct lxc_conf
*lxc_conf
, void *data
)
4776 const char *idxstring
;
4777 struct lxc_config_t
*config
;
4778 struct lxc_netdev
*netdev
;
4780 char *deindexed_key
= NULL
;
4782 idxstring
= key
+ 8;
4783 if (!isdigit(*idxstring
))
4786 if (lxc_config_value_empty(value
))
4787 return clr_config_net_nic(key
, lxc_conf
, data
);
4789 config
= get_network_config_ops(key
, lxc_conf
, &idx
, &deindexed_key
);
4790 if (!config
|| idx
< 0)
4793 netdev
= lxc_get_netdev_by_idx(lxc_conf
, (unsigned int)idx
, true);
4795 free(deindexed_key
);
4799 ret
= config
->set(deindexed_key
, value
, lxc_conf
, netdev
);
4800 free(deindexed_key
);
4805 static int clr_config_net_nic(const char *key
, struct lxc_conf
*lxc_conf
,
4809 const char *idxstring
;
4810 struct lxc_config_t
*config
;
4811 struct lxc_netdev
*netdev
;
4813 char *deindexed_key
= NULL
;
4815 idxstring
= key
+ 8;
4816 if (!isdigit(*idxstring
))
4819 /* The left conjunct is pretty self-explanatory. The right conjunct
4820 * checks whether the two pointers are equal. If they are we know that
4821 * this is not a key that is namespaced any further and so we are
4822 * supposed to clear the whole network.
4824 if (isdigit(*idxstring
) && (strrchr(key
, '.') == (idxstring
- 1))) {
4825 unsigned int rmnetdevidx
;
4827 if (lxc_safe_uint(idxstring
, &rmnetdevidx
) < 0)
4830 /* Remove network from network list. */
4831 lxc_remove_nic_by_idx(lxc_conf
, rmnetdevidx
);
4835 config
= get_network_config_ops(key
, lxc_conf
, &idx
, &deindexed_key
);
4836 if (!config
|| idx
< 0)
4839 netdev
= lxc_get_netdev_by_idx(lxc_conf
, (unsigned int)idx
, false);
4841 free(deindexed_key
);
4845 ret
= config
->clr(deindexed_key
, lxc_conf
, netdev
);
4846 free(deindexed_key
);
4851 static int clr_config_net_type(const char *key
, struct lxc_conf
*lxc_conf
,
4854 struct lxc_netdev
*netdev
= data
;
4864 static int clr_config_net_name(const char *key
, struct lxc_conf
*lxc_conf
,
4867 struct lxc_netdev
*netdev
= data
;
4872 netdev
->name
[0] = '\0';
4877 static int clr_config_net_flags(const char *key
, struct lxc_conf
*lxc_conf
,
4880 struct lxc_netdev
*netdev
= data
;
4890 static int clr_config_net_link(const char *key
, struct lxc_conf
*lxc_conf
,
4893 struct lxc_netdev
*netdev
= data
;
4898 netdev
->link
[0] = '\0';
4903 static int clr_config_net_macvlan_mode(const char *key
,
4904 struct lxc_conf
*lxc_conf
, void *data
)
4906 struct lxc_netdev
*netdev
= data
;
4911 if (netdev
->type
!= LXC_NET_MACVLAN
)
4914 netdev
->priv
.macvlan_attr
.mode
= -1;
4919 static int clr_config_net_veth_pair(const char *key
, struct lxc_conf
*lxc_conf
,
4922 struct lxc_netdev
*netdev
= data
;
4927 netdev
->priv
.veth_attr
.pair
[0] = '\0';
4932 static int clr_config_net_script_up(const char *key
, struct lxc_conf
*lxc_conf
,
4935 struct lxc_netdev
*netdev
= data
;
4940 free(netdev
->upscript
);
4941 netdev
->upscript
= NULL
;
4946 static int clr_config_net_script_down(const char *key
,
4947 struct lxc_conf
*lxc_conf
, void *data
)
4949 struct lxc_netdev
*netdev
= data
;
4954 free(netdev
->downscript
);
4955 netdev
->downscript
= NULL
;
4960 static int clr_config_net_hwaddr(const char *key
, struct lxc_conf
*lxc_conf
,
4963 struct lxc_netdev
*netdev
= data
;
4968 free(netdev
->hwaddr
);
4969 netdev
->hwaddr
= NULL
;
4974 static int clr_config_net_mtu(const char *key
, struct lxc_conf
*lxc_conf
,
4977 struct lxc_netdev
*netdev
= data
;
4988 static int clr_config_net_vlan_id(const char *key
, struct lxc_conf
*lxc_conf
,
4991 struct lxc_netdev
*netdev
= data
;
4996 netdev
->priv
.vlan_attr
.vid
= 0;
5001 static int clr_config_net_ipv4_gateway(const char *key
,
5002 struct lxc_conf
*lxc_conf
, void *data
)
5004 struct lxc_netdev
*netdev
= data
;
5009 free(netdev
->ipv4_gateway
);
5010 netdev
->ipv4_gateway
= NULL
;
5015 static int clr_config_net_ipv4_address(const char *key
,
5016 struct lxc_conf
*lxc_conf
, void *data
)
5018 struct lxc_netdev
*netdev
= data
;
5019 struct lxc_list
*cur
, *next
;
5024 lxc_list_for_each_safe(cur
, &netdev
->ipv4
, next
) {
5033 static int clr_config_net_veth_ipv4_route(const char *key
,
5034 struct lxc_conf
*lxc_conf
, void *data
)
5036 struct lxc_netdev
*netdev
= data
;
5037 struct lxc_list
*cur
, *next
;
5042 lxc_list_for_each_safe(cur
, &netdev
->priv
.veth_attr
.ipv4_routes
, next
) {
5051 static int clr_config_net_ipv6_gateway(const char *key
,
5052 struct lxc_conf
*lxc_conf
, void *data
)
5054 struct lxc_netdev
*netdev
= data
;
5059 free(netdev
->ipv6_gateway
);
5060 netdev
->ipv6_gateway
= NULL
;
5065 static int clr_config_net_ipv6_address(const char *key
,
5066 struct lxc_conf
*lxc_conf
, void *data
)
5068 struct lxc_netdev
*netdev
= data
;
5069 struct lxc_list
*cur
, *next
;
5074 lxc_list_for_each_safe(cur
, &netdev
->ipv6
, next
) {
5083 static int clr_config_net_veth_ipv6_route(const char *key
,
5084 struct lxc_conf
*lxc_conf
, void *data
)
5086 struct lxc_netdev
*netdev
= data
;
5087 struct lxc_list
*cur
, *next
;
5092 lxc_list_for_each_safe(cur
, &netdev
->priv
.veth_attr
.ipv6_routes
, next
) {
5101 static int get_config_net_nic(const char *key
, char *retv
, int inlen
,
5102 struct lxc_conf
*c
, void *data
)
5105 const char *idxstring
;
5106 struct lxc_config_t
*config
;
5107 struct lxc_netdev
*netdev
;
5109 char *deindexed_key
= NULL
;
5111 idxstring
= key
+ 8;
5112 if (!isdigit(*idxstring
))
5115 config
= get_network_config_ops(key
, c
, &idx
, &deindexed_key
);
5116 if (!config
|| idx
< 0)
5119 netdev
= lxc_get_netdev_by_idx(c
, (unsigned int)idx
, false);
5121 free(deindexed_key
);
5125 ret
= config
->get(deindexed_key
, retv
, inlen
, c
, netdev
);
5126 free(deindexed_key
);
5131 static int get_config_net_type(const char *key
, char *retv
, int inlen
,
5132 struct lxc_conf
*c
, void *data
)
5136 struct lxc_netdev
*netdev
= data
;
5141 memset(retv
, 0, inlen
);
5146 strprint(retv
, inlen
, "%s", lxc_net_type_to_str(netdev
->type
));
5151 static int get_config_net_flags(const char *key
, char *retv
, int inlen
,
5152 struct lxc_conf
*c
, void *data
)
5156 struct lxc_netdev
*netdev
= data
;
5161 memset(retv
, 0, inlen
);
5166 if (netdev
->flags
& IFF_UP
)
5167 strprint(retv
, inlen
, "up");
5172 static int get_config_net_link(const char *key
, char *retv
, int inlen
,
5173 struct lxc_conf
*c
, void *data
)
5177 struct lxc_netdev
*netdev
= data
;
5182 memset(retv
, 0, inlen
);
5187 if (netdev
->link
[0] != '\0')
5188 strprint(retv
, inlen
, "%s", netdev
->link
);
5193 static int get_config_net_name(const char *key
, char *retv
, int inlen
,
5194 struct lxc_conf
*c
, void *data
)
5198 struct lxc_netdev
*netdev
= data
;
5203 memset(retv
, 0, inlen
);
5208 if (netdev
->name
[0] != '\0')
5209 strprint(retv
, inlen
, "%s", netdev
->name
);
5214 static int get_config_net_macvlan_mode(const char *key
, char *retv
, int inlen
,
5215 struct lxc_conf
*c
, void *data
)
5220 struct lxc_netdev
*netdev
= data
;
5225 memset(retv
, 0, inlen
);
5230 if (netdev
->type
!= LXC_NET_MACVLAN
)
5233 switch (netdev
->priv
.macvlan_attr
.mode
) {
5234 case MACVLAN_MODE_PRIVATE
:
5237 case MACVLAN_MODE_VEPA
:
5240 case MACVLAN_MODE_BRIDGE
:
5243 case MACVLAN_MODE_PASSTHRU
:
5251 strprint(retv
, inlen
, "%s", mode
);
5256 static int get_config_net_veth_pair(const char *key
, char *retv
, int inlen
,
5257 struct lxc_conf
*c
, void *data
)
5261 struct lxc_netdev
*netdev
= data
;
5266 memset(retv
, 0, inlen
);
5271 if (netdev
->type
!= LXC_NET_VETH
)
5274 strprint(retv
, inlen
, "%s",
5275 netdev
->priv
.veth_attr
.pair
[0] != '\0'
5276 ? netdev
->priv
.veth_attr
.pair
5277 : netdev
->priv
.veth_attr
.veth1
);
5282 static int get_config_net_script_up(const char *key
, char *retv
, int inlen
,
5283 struct lxc_conf
*c
, void *data
)
5287 struct lxc_netdev
*netdev
= data
;
5292 memset(retv
, 0, inlen
);
5297 if (netdev
->upscript
)
5298 strprint(retv
, inlen
, "%s", netdev
->upscript
);
5303 static int get_config_net_script_down(const char *key
, char *retv
, int inlen
,
5304 struct lxc_conf
*c
, void *data
)
5308 struct lxc_netdev
*netdev
= data
;
5313 memset(retv
, 0, inlen
);
5318 if (netdev
->downscript
)
5319 strprint(retv
, inlen
, "%s", netdev
->downscript
);
5324 static int get_config_net_hwaddr(const char *key
, char *retv
, int inlen
,
5325 struct lxc_conf
*c
, void *data
)
5329 struct lxc_netdev
*netdev
= data
;
5334 memset(retv
, 0, inlen
);
5340 strprint(retv
, inlen
, "%s", netdev
->hwaddr
);
5345 static int get_config_net_mtu(const char *key
, char *retv
, int inlen
,
5346 struct lxc_conf
*c
, void *data
)
5350 struct lxc_netdev
*netdev
= data
;
5355 memset(retv
, 0, inlen
);
5361 strprint(retv
, inlen
, "%s", netdev
->mtu
);
5366 static int get_config_net_vlan_id(const char *key
, char *retv
, int inlen
,
5367 struct lxc_conf
*c
, void *data
)
5371 struct lxc_netdev
*netdev
= data
;
5376 memset(retv
, 0, inlen
);
5381 if (netdev
->type
!= LXC_NET_VLAN
)
5384 strprint(retv
, inlen
, "%d", netdev
->priv
.vlan_attr
.vid
);
5389 static int get_config_net_ipv4_gateway(const char *key
, char *retv
, int inlen
,
5390 struct lxc_conf
*c
, void *data
)
5393 char buf
[INET_ADDRSTRLEN
];
5395 struct lxc_netdev
*netdev
= data
;
5400 memset(retv
, 0, inlen
);
5405 if (netdev
->ipv4_gateway_auto
) {
5406 strprint(retv
, inlen
, "auto");
5407 } else if (netdev
->ipv4_gateway
) {
5408 inet_ntop(AF_INET
, netdev
->ipv4_gateway
, buf
, sizeof(buf
));
5409 strprint(retv
, inlen
, "%s", buf
);
5415 static int get_config_net_ipv4_address(const char *key
, char *retv
, int inlen
,
5416 struct lxc_conf
*c
, void *data
)
5420 char buf
[INET_ADDRSTRLEN
];
5421 struct lxc_list
*it
;
5423 struct lxc_netdev
*netdev
= data
;
5428 memset(retv
, 0, inlen
);
5433 listlen
= lxc_list_len(&netdev
->ipv4
);
5435 lxc_list_for_each(it
, &netdev
->ipv4
) {
5436 struct lxc_inetdev
*i
= it
->elem
;
5437 inet_ntop(AF_INET
, &i
->addr
, buf
, sizeof(buf
));
5438 strprint(retv
, inlen
, "%s/%u%s", buf
, i
->prefix
,
5439 (listlen
-- > 1) ? "\n" : "");
5445 static int get_config_net_veth_ipv4_route(const char *key
, char *retv
, int inlen
,
5446 struct lxc_conf
*c
, void *data
)
5450 char buf
[INET_ADDRSTRLEN
];
5451 struct lxc_list
*it
;
5453 struct lxc_netdev
*netdev
= data
;
5458 memset(retv
, 0, inlen
);
5461 return minus_one_set_errno(EINVAL
);
5463 if (netdev
->type
!= LXC_NET_VETH
)
5466 listlen
= lxc_list_len(&netdev
->priv
.veth_attr
.ipv4_routes
);
5468 lxc_list_for_each(it
, &netdev
->priv
.veth_attr
.ipv4_routes
) {
5469 struct lxc_inetdev
*i
= it
->elem
;
5470 inet_ntop(AF_INET
, &i
->addr
, buf
, sizeof(buf
));
5471 strprint(retv
, inlen
, "%s/%u%s", buf
, i
->prefix
,
5472 (listlen
-- > 1) ? "\n" : "");
5478 static int get_config_net_ipv6_gateway(const char *key
, char *retv
, int inlen
,
5479 struct lxc_conf
*c
, void *data
)
5482 char buf
[INET6_ADDRSTRLEN
];
5484 struct lxc_netdev
*netdev
= data
;
5489 memset(retv
, 0, inlen
);
5494 if (netdev
->ipv6_gateway_auto
) {
5495 strprint(retv
, inlen
, "auto");
5496 } else if (netdev
->ipv6_gateway
) {
5497 inet_ntop(AF_INET6
, netdev
->ipv6_gateway
, buf
, sizeof(buf
));
5498 strprint(retv
, inlen
, "%s", buf
);
5504 static int get_config_net_ipv6_address(const char *key
, char *retv
, int inlen
,
5505 struct lxc_conf
*c
, void *data
)
5509 char buf
[INET6_ADDRSTRLEN
];
5510 struct lxc_list
*it
;
5512 struct lxc_netdev
*netdev
= data
;
5517 memset(retv
, 0, inlen
);
5522 listlen
= lxc_list_len(&netdev
->ipv6
);
5524 lxc_list_for_each(it
, &netdev
->ipv6
) {
5525 struct lxc_inet6dev
*i
= it
->elem
;
5526 inet_ntop(AF_INET6
, &i
->addr
, buf
, sizeof(buf
));
5527 strprint(retv
, inlen
, "%s/%u%s", buf
, i
->prefix
,
5528 (listlen
-- > 1) ? "\n" : "");
5534 static int get_config_net_veth_ipv6_route(const char *key
, char *retv
, int inlen
,
5535 struct lxc_conf
*c
, void *data
)
5539 char buf
[INET6_ADDRSTRLEN
];
5540 struct lxc_list
*it
;
5542 struct lxc_netdev
*netdev
= data
;
5547 memset(retv
, 0, inlen
);
5550 return minus_one_set_errno(EINVAL
);
5552 if (netdev
->type
!= LXC_NET_VETH
)
5555 listlen
= lxc_list_len(&netdev
->priv
.veth_attr
.ipv6_routes
);
5557 lxc_list_for_each(it
, &netdev
->priv
.veth_attr
.ipv6_routes
) {
5558 struct lxc_inet6dev
*i
= it
->elem
;
5559 inet_ntop(AF_INET6
, &i
->addr
, buf
, sizeof(buf
));
5560 strprint(retv
, inlen
, "%s/%u%s", buf
, i
->prefix
,
5561 (listlen
-- > 1) ? "\n" : "");
5567 int lxc_list_config_items(char *retv
, int inlen
)
5576 memset(retv
, 0, inlen
);
5578 for (i
= 0; i
< config_jump_table_size
; i
++) {
5579 char *s
= config_jump_table
[i
].name
;
5581 if (s
[strlen(s
) - 1] == '.')
5584 strprint(retv
, inlen
, "%s\n", s
);
5590 int lxc_list_subkeys(struct lxc_conf
*conf
, const char *key
, char *retv
,
5599 memset(retv
, 0, inlen
);
5601 if (!strcmp(key
, "lxc.apparmor")) {
5602 strprint(retv
, inlen
, "allow_incomplete\n");
5603 strprint(retv
, inlen
, "allow_nesting\n");
5604 strprint(retv
, inlen
, "profile\n");
5605 strprint(retv
, inlen
, "raw\n");
5606 } else if (!strcmp(key
, "lxc.cgroup")) {
5607 strprint(retv
, inlen
, "dir\n");
5608 } else if (!strcmp(key
, "lxc.selinux")) {
5609 strprint(retv
, inlen
, "context\n");
5610 } else if (!strcmp(key
, "lxc.mount")) {
5611 strprint(retv
, inlen
, "auto\n");
5612 strprint(retv
, inlen
, "entry\n");
5613 strprint(retv
, inlen
, "fstab\n");
5614 } else if (!strcmp(key
, "lxc.rootfs")) {
5615 strprint(retv
, inlen
, "mount\n");
5616 strprint(retv
, inlen
, "options\n");
5617 strprint(retv
, inlen
, "path\n");
5618 } else if (!strcmp(key
, "lxc.uts")) {
5619 strprint(retv
, inlen
, "name\n");
5620 } else if (!strcmp(key
, "lxc.hook")) {
5621 strprint(retv
, inlen
, "autodev\n");
5622 strprint(retv
, inlen
, "clone\n");
5623 strprint(retv
, inlen
, "destroy\n");
5624 strprint(retv
, inlen
, "mount\n");
5625 strprint(retv
, inlen
, "post-stop\n");
5626 strprint(retv
, inlen
, "pre-mount\n");
5627 strprint(retv
, inlen
, "pre-start\n");
5628 strprint(retv
, inlen
, "start-host\n");
5629 strprint(retv
, inlen
, "start\n");
5630 strprint(retv
, inlen
, "stop\n");
5631 } else if (!strcmp(key
, "lxc.cap")) {
5632 strprint(retv
, inlen
, "drop\n");
5633 strprint(retv
, inlen
, "keep\n");
5634 } else if (!strcmp(key
, "lxc.console")) {
5635 strprint(retv
, inlen
, "logfile\n");
5636 strprint(retv
, inlen
, "path\n");
5637 } else if (!strcmp(key
, "lxc.seccomp")) {
5638 strprint(retv
, inlen
, "profile\n");
5639 } else if (!strcmp(key
, "lxc.signal")) {
5640 strprint(retv
, inlen
, "halt\n");
5641 strprint(retv
, inlen
, "reboot\n");
5642 strprint(retv
, inlen
, "stop\n");
5643 } else if (!strcmp(key
, "lxc.start")) {
5644 strprint(retv
, inlen
, "auto\n");
5645 strprint(retv
, inlen
, "delay\n");
5646 strprint(retv
, inlen
, "order\n");
5647 } else if (!strcmp(key
, "lxc.monitor")) {
5648 strprint(retv
, inlen
, "unshare\n");
5656 int lxc_list_net(struct lxc_conf
*c
, const char *key
, char *retv
, int inlen
)
5659 const char *idxstring
;
5660 struct lxc_netdev
*netdev
;
5664 idxstring
= key
+ 8;
5665 if (!isdigit(*idxstring
))
5668 (void)get_network_config_ops(key
, c
, &idx
, NULL
);
5672 netdev
= lxc_get_netdev_by_idx(c
, (unsigned int)idx
, false);
5679 memset(retv
, 0, inlen
);
5681 strprint(retv
, inlen
, "type\n");
5682 strprint(retv
, inlen
, "script.up\n");
5683 strprint(retv
, inlen
, "script.down\n");
5685 if (netdev
->type
!= LXC_NET_EMPTY
) {
5686 strprint(retv
, inlen
, "flags\n");
5687 strprint(retv
, inlen
, "link\n");
5688 strprint(retv
, inlen
, "name\n");
5689 strprint(retv
, inlen
, "hwaddr\n");
5690 strprint(retv
, inlen
, "mtu\n");
5691 strprint(retv
, inlen
, "ipv6.address\n");
5692 strprint(retv
, inlen
, "ipv6.gateway\n");
5693 strprint(retv
, inlen
, "ipv4.address\n");
5694 strprint(retv
, inlen
, "ipv4.gateway\n");
5697 switch (netdev
->type
) {
5699 strprint(retv
, inlen
, "veth.pair\n");
5700 strprint(retv
, inlen
, "veth.ipv4.route\n");
5701 strprint(retv
, inlen
, "veth.ipv6.route\n");
5703 case LXC_NET_MACVLAN
:
5704 strprint(retv
, inlen
, "macvlan.mode\n");
5707 strprint(retv
, inlen
, "vlan.id\n");