]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/parse_config_file.c
Add autodev.tmpfs.size config parameter
[mirror_lxc.git] / src / tests / parse_config_file.c
1 /* liblxcapi
2 *
3 * Copyright © 2017 Christian Brauner <christian.brauner@ubuntu.com>.
4 * Copyright © 2017 Canonical Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 #include <lxc/lxccontainer.h>
20
21 #include <errno.h>
22 #include <signal.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/types.h>
27 #include <sys/wait.h>
28 #include <unistd.h>
29 #include <libgen.h>
30
31 #include "conf.h"
32 #include "confile_utils.h"
33 #include "lxc/state.h"
34 #include "lxctest.h"
35 #include "utils.h"
36
37 static int set_get_compare_clear_save_load(struct lxc_container *c,
38 const char *key, const char *value,
39 const char *config_file,
40 bool compare)
41 {
42 char retval[4096] = {0};
43 int ret;
44
45 if (!c->set_config_item(c, key, value)) {
46 lxc_error("failed to set config item \"%s\" to \"%s\"\n", key,
47 value);
48 return -1;
49 }
50
51 ret = c->get_config_item(c, key, retval, sizeof(retval));
52 if (ret < 0) {
53 lxc_error("failed to get config item \"%s\"\n", key);
54 return -1;
55 }
56
57 if (compare) {
58 ret = strcmp(retval, value);
59 if (ret != 0) {
60 lxc_error(
61 "expected value \"%s\" and retrieved value \"%s\" "
62 "for config key \"%s\" do not match\n",
63 value, retval, key);
64 return -1;
65 }
66 }
67
68 if (config_file) {
69 if (!c->save_config(c, config_file)) {
70 lxc_error("%s\n", "failed to save config file");
71 return -1;
72 }
73
74 c->clear_config(c);
75 c->lxc_conf = NULL;
76
77 if (!c->load_config(c, config_file)) {
78 lxc_error("%s\n", "failed to load config file");
79 return -1;
80 }
81 }
82
83 if (!c->clear_config_item(c, key)) {
84 lxc_error("failed to clear config item \"%s\"\n", key);
85 return -1;
86 }
87
88 c->clear_config(c);
89 c->lxc_conf = NULL;
90
91 return 0;
92 }
93
94 static int set_and_clear_complete_netdev(struct lxc_container *c)
95 {
96 if (!c->set_config_item(c, "lxc.net.1.type", "veth")) {
97 lxc_error("%s\n", "lxc.net.1.type");
98 return -1;
99 }
100
101 if (!c->set_config_item(c, "lxc.net.1.ipv4.address", "10.0.2.3/24")) {
102 lxc_error("%s\n", "lxc.net.1.ipv4.address");
103 return -1;
104 }
105
106 if (!c->set_config_item(c, "lxc.net.1.ipv4.gateway", "10.0.2.2")) {
107 lxc_error("%s\n", "lxc.net.1.ipv4.gateway");
108 return -1;
109 }
110
111 if (!c->set_config_item(c, "lxc.net.1.ipv4.gateway", "auto")) {
112 lxc_error("%s\n", "lxc.net.1.ipv4.gateway");
113 return -1;
114 }
115
116 if (!c->set_config_item(c, "lxc.net.1.ipv4.gateway", "dev")) {
117 lxc_error("%s\n", "lxc.net.1.ipv4.gateway");
118 return -1;
119 }
120
121 if (!c->set_config_item(c, "lxc.net.1.ipv6.address",
122 "2003:db8:1:0:214:1234:fe0b:3596/64")) {
123 lxc_error("%s\n", "lxc.net.1.ipv6.address");
124 return -1;
125 }
126
127 if (!c->set_config_item(c, "lxc.net.1.ipv6.gateway",
128 "2003:db8:1:0::1")) {
129 lxc_error("%s\n", "lxc.net.1.ipv6.gateway");
130 return -1;
131 }
132
133 if (!c->set_config_item(c, "lxc.net.1.ipv6.gateway", "auto")) {
134 lxc_error("%s\n", "lxc.net.1.ipv6.gateway");
135 return -1;
136 }
137
138 if (!c->set_config_item(c, "lxc.net.1.ipv6.gateway", "dev")) {
139 lxc_error("%s\n", "lxc.net.1.ipv6.gateway");
140 return -1;
141 }
142
143 if (!c->set_config_item(c, "lxc.net.1.flags", "up")) {
144 lxc_error("%s\n", "lxc.net.1.flags");
145 return -1;
146 }
147
148 if (!c->set_config_item(c, "lxc.net.1.link", "br0")) {
149 lxc_error("%s\n", "lxc.net.1.link");
150 return -1;
151 }
152
153 if (!c->set_config_item(c, "lxc.net.1.veth.pair", "bla")) {
154 lxc_error("%s\n", "lxc.net.1.veth.pair");
155 return -1;
156 }
157
158 if (!c->set_config_item(c, "lxc.net.1.veth.ipv4.route", "192.0.2.1/32")) {
159 lxc_error("%s\n", "lxc.net.1.veth.ipv4.route");
160 return -1;
161 }
162
163 if (!c->set_config_item(c, "lxc.net.1.veth.ipv6.route", "2001:db8::1/128")) {
164 lxc_error("%s\n", "lxc.net.1.veth.ipv6.route");
165 return -1;
166 }
167
168 if (!c->set_config_item(c, "lxc.net.1.hwaddr",
169 "52:54:00:80:7a:5d")) {
170 lxc_error("%s\n", "lxc.net.1.hwaddr");
171 return -1;
172 }
173
174 if (!c->set_config_item(c, "lxc.net.1.mtu", "2000")) {
175 lxc_error("%s\n", "lxc.net.1.mtu");
176 return -1;
177 }
178
179 if (!c->clear_config_item(c, "lxc.net.1")) {
180 lxc_error("%s", "failed to clear \"lxc.net.1\"\n");
181 return -1;
182 }
183
184 c->clear_config(c);
185 c->lxc_conf = NULL;
186
187 return 0;
188 }
189
190 static int set_invalid_netdev(struct lxc_container *c) {
191 if (c->set_config_item(c, "lxc.net.0.asdf", "veth")) {
192 lxc_error("%s\n", "lxc.net.0.asdf should be invalid");
193 return -1;
194 }
195
196 if (c->set_config_item(c, "lxc.net.2147483647.type", "veth")) {
197 lxc_error("%s\n", "lxc.net.2147483647.type should be invalid");
198 return -1;
199 }
200
201 if (c->set_config_item(c, "lxc.net.0.", "veth")) {
202 lxc_error("%s\n", "lxc.net.0. should be invalid");
203 return -1;
204 }
205
206 c->clear_config(c);
207 c->lxc_conf = NULL;
208
209 return 0;
210 }
211
212 int test_idmap_parser(void)
213 {
214 size_t i;
215 struct idmap_check {
216 bool is_valid;
217 const char *idmap;
218 };
219 static struct idmap_check idmaps[] = {
220 /* valid idmaps */
221 { true, "u 0 0 1" },
222 { true, "g 0 0 1" },
223 { true, "u 1 100001 999999999" },
224 { true, "g 1 100001 999999999" },
225 { true, "u 0 0 0" },
226 { true, "g 0 0 0" },
227 { true, "u 1000 165536 65536" },
228 { true, "g 999 999 1" },
229 { true, "u 0 5000 100000" },
230 { true, "g 577 789 5" },
231 { true, "u 65536 65536 1 " },
232 /* invalid idmaps */
233 { false, "1u 0 0 0" },
234 { false, "1g 0 0 0a" },
235 { false, "1 u 0 0 0" },
236 { false, "1g 0 0 0 1" },
237 { false, "1u a0 b0 c0 d1" },
238 { false, "1g 0 b0 0 d1" },
239 { false, "1u a0 0 c0 1" },
240 { false, "g -1 0 -10" },
241 { false, "a 1 0 10" },
242 { false, "u 1 1 0 10" },
243 { false, "g 1 0 10 z " },
244 };
245
246 for (i = 0; i < sizeof(idmaps) / sizeof(struct idmap_check); i++) {
247 unsigned long hostid, nsid, range;
248 char type;
249 int ret;
250 ret = parse_idmaps(idmaps[i].idmap, &type, &nsid, &hostid,
251 &range);
252 if ((ret < 0 && idmaps[i].is_valid) ||
253 (ret == 0 && !idmaps[i].is_valid)) {
254 lxc_error("failed to parse idmap \"%s\"\n",
255 idmaps[i].idmap);
256 return -1;
257 }
258 }
259
260 return 0;
261 }
262
263 static int set_get_compare_clear_save_load_network(
264 struct lxc_container *c, const char *key, const char *value,
265 const char *config_file, bool compare, const char *network_type)
266 {
267 char retval[4096] = {0};
268 int ret;
269
270 if (!c->set_config_item(c, "lxc.net.0.type", network_type)) {
271 lxc_error("%s\n", "lxc.net.0.type");
272 return -1;
273 }
274
275 if (!c->set_config_item(c, key, value)) {
276 lxc_error("failed to set config item \"%s\" to \"%s\"\n", key,
277 value);
278 return -1;
279 }
280
281 ret = c->get_config_item(c, key, retval, sizeof(retval));
282 if (ret < 0) {
283 lxc_error("failed to get config item \"%s\"\n", key);
284 return -1;
285 }
286
287 if (compare) {
288 ret = strcmp(retval, value);
289 if (ret != 0) {
290 lxc_error(
291 "expected value \"%s\" and retrieved value \"%s\" "
292 "for config key \"%s\" do not match\n",
293 value, retval, key);
294 return -1;
295 }
296 }
297
298 if (config_file) {
299 if (!c->save_config(c, config_file)) {
300 lxc_error("%s\n", "failed to save config file");
301 return -1;
302 }
303
304 c->clear_config(c);
305 c->lxc_conf = NULL;
306
307 if (!c->load_config(c, config_file)) {
308 lxc_error("%s\n", "failed to load config file");
309 return -1;
310 }
311 }
312
313 if (!c->clear_config_item(c, key)) {
314 lxc_error("failed to clear config item \"%s\"\n", key);
315 return -1;
316 }
317
318 if (!c->clear_config_item(c, "lxc.net.0.type")) {
319 lxc_error("%s\n", "lxc.net.0.type");
320 return -1;
321 }
322
323 c->clear_config(c);
324 c->lxc_conf = NULL;
325
326 return 0;
327 }
328
329 int main(int argc, char *argv[])
330 {
331 int ret;
332 struct lxc_container *c;
333 int fd = -1, fret = EXIT_FAILURE;
334 char tmpf[] = "lxc-parse-config-file-XXXXXX";
335 char retval[4096] = {0};
336
337 fd = lxc_make_tmpfile(tmpf, false);
338 if (fd < 0) {
339 lxc_error("%s\n", "Could not create temporary file");
340 exit(fret);
341 }
342 close(fd);
343
344 c = lxc_container_new(tmpf, NULL);
345 if (!c) {
346 lxc_error("%s\n", "Failed to create new container");
347 exit(EXIT_FAILURE);
348 }
349
350 if (set_get_compare_clear_save_load(c, "lxc.arch", "x86_64", tmpf,
351 true) < 0) {
352 lxc_error("%s\n", "lxc.arch");
353 goto non_test_error;
354 }
355
356 if (set_get_compare_clear_save_load(c, "lxc.pty.max", "1000", tmpf, true) < 0) {
357 lxc_error("%s\n", "lxc.pty.max");
358 goto non_test_error;
359 }
360
361 if (set_get_compare_clear_save_load(c, "lxc.tty.max", "4", tmpf, true) < 0) {
362 lxc_error("%s\n", "lxc.tty.max");
363 goto non_test_error;
364 }
365
366 if (set_get_compare_clear_save_load(c, "lxc.tty.dir", "not-dev", tmpf, true) < 0) {
367 lxc_error("%s\n", "lxc.tty.dir");
368 goto non_test_error;
369 }
370
371 if (set_get_compare_clear_save_load(c, "lxc.apparmor.profile", "unconfined", tmpf, true) < 0) {
372 lxc_error("%s\n", "lxc.apparmor.profile");
373 goto non_test_error;
374 }
375
376 if (set_get_compare_clear_save_load(c, "lxc.apparmor.allow_incomplete", "1", tmpf, true) < 0) {
377 lxc_error("%s\n", "lxc.apparmor.allow_incomplete");
378 goto non_test_error;
379 }
380
381 if (set_get_compare_clear_save_load(c, "lxc.selinux.context", "system_u:system_r:lxc_t:s0:c22", tmpf, true) < 0) {
382 lxc_error("%s\n", "lxc.selinux.context");
383 goto non_test_error;
384 }
385
386 if (set_get_compare_clear_save_load(c, "lxc.cgroup.cpuset.cpus",
387 "1-100", tmpf, false) < 0) {
388 lxc_error("%s\n", "lxc.cgroup.cpuset.cpus");
389 goto non_test_error;
390 }
391
392 if (!c->set_config_item(c, "lxc.cgroup.cpuset.cpus", "1-100")) {
393 lxc_error("%s\n", "failed to set config item \"lxc.cgroup.cpuset.cpus\" to \"1-100\"");
394 return -1;
395 }
396
397 if (!c->set_config_item(c, "lxc.cgroup.memory.limit_in_bytes", "123456789")) {
398 lxc_error("%s\n", "failed to set config item \"lxc.cgroup.memory.limit_in_bytes\" to \"123456789\"");
399 return -1;
400 }
401
402 if (!c->get_config_item(c, "lxc.cgroup", retval, sizeof(retval))) {
403 lxc_error("%s\n", "failed to get config item \"lxc.cgroup\"");
404 return -1;
405 }
406
407 c->clear_config(c);
408 c->lxc_conf = NULL;
409
410 /* lxc.idmap
411 * We can't really save the config here since save_config() wants to
412 * chown the container's directory but we haven't created an on-disk
413 * container. So let's test set-get-clear.
414 */
415 if (set_get_compare_clear_save_load(c, "lxc.idmap", "u 0 100000 1000000000", NULL, false) < 0) {
416 lxc_error("%s\n", "lxc.idmap");
417 goto non_test_error;
418 }
419
420 if (!c->set_config_item(c, "lxc.idmap", "u 1 100000 10000000")) {
421 lxc_error("%s\n", "failed to set config item \"lxc.idmap\" to \"u 1 100000 10000000\"");
422 return -1;
423 }
424
425 if (!c->set_config_item(c, "lxc.idmap", "g 1 100000 10000000")) {
426 lxc_error("%s\n", "failed to set config item \"lxc.idmap\" to \"g 1 100000 10000000\"");
427 return -1;
428 }
429
430 if (!c->get_config_item(c, "lxc.idmap", retval, sizeof(retval))) {
431 lxc_error("%s\n", "failed to get config item \"lxc.idmap\"");
432 return -1;
433 }
434
435 c->clear_config(c);
436 c->lxc_conf = NULL;
437
438 if (set_get_compare_clear_save_load(c, "lxc.log.level", "DEBUG", tmpf, true) < 0) {
439 lxc_error("%s\n", "lxc.log.level");
440 goto non_test_error;
441 }
442
443 if (set_get_compare_clear_save_load(c, "lxc.log.file", "/some/path", tmpf, true) < 0) {
444 lxc_error("%s\n", "lxc.log.file");
445 goto non_test_error;
446 }
447
448 if (set_get_compare_clear_save_load(c, "lxc.mount.fstab", "/some/path", NULL, true) < 0) {
449 lxc_error("%s\n", "lxc.mount.fstab");
450 goto non_test_error;
451 }
452
453 /* lxc.mount.auto
454 * Note that we cannot compare the values since the getter for
455 * lxc.mount.auto does not preserve ordering.
456 */
457 if (set_get_compare_clear_save_load(c, "lxc.mount.auto", "proc:rw sys:rw cgroup-full:rw", tmpf, false) < 0) {
458 lxc_error("%s\n", "lxc.mount.auto");
459 goto non_test_error;
460 }
461
462 /* lxc.mount.entry
463 * Note that we cannot compare the values since the getter for
464 * lxc.mount.entry appends newlines.
465 */
466 if (set_get_compare_clear_save_load(c, "lxc.mount.entry", "/dev/dri dev/dri none bind,optional,create=dir", tmpf, false) < 0) {
467 lxc_error("%s\n", "lxc.mount.entry");
468 goto non_test_error;
469 }
470
471 if (set_get_compare_clear_save_load(c, "lxc.rootfs.path", "/some/path", tmpf, true) < 0) {
472 lxc_error("%s\n", "lxc.rootfs.path");
473 goto non_test_error;
474 }
475
476 if (set_get_compare_clear_save_load(c, "lxc.rootfs.mount", "/some/path", tmpf, true) < 0) {
477 lxc_error("%s\n", "lxc.rootfs.mount");
478 goto non_test_error;
479 }
480
481 if (set_get_compare_clear_save_load(c, "lxc.rootfs.options", "ext4,discard", tmpf, true) < 0) {
482 lxc_error("%s\n", "lxc.rootfs.options");
483 goto non_test_error;
484 }
485
486 if (set_get_compare_clear_save_load(c, "lxc.uts.name", "the-shire", tmpf, true) < 0) {
487 lxc_error("%s\n", "lxc.uts.name");
488 goto non_test_error;
489 }
490
491 if (set_get_compare_clear_save_load(
492 c, "lxc.hook.pre-start", "/some/pre-start", tmpf, false) < 0) {
493 lxc_error("%s\n", "lxc.hook.pre-start");
494 goto non_test_error;
495 }
496
497 if (set_get_compare_clear_save_load(
498 c, "lxc.hook.pre-mount", "/some/pre-mount", tmpf, false) < 0) {
499 lxc_error("%s\n", "lxc.hook.pre-mount");
500 goto non_test_error;
501 }
502
503 if (set_get_compare_clear_save_load(c, "lxc.hook.mount", "/some/mount", tmpf, false) < 0) {
504 lxc_error("%s\n", "lxc.hook.mount");
505 goto non_test_error;
506 }
507
508 if (set_get_compare_clear_save_load(c, "lxc.hook.autodev", "/some/autodev", tmpf, false) < 0) {
509 lxc_error("%s\n", "lxc.hook.autodev");
510 goto non_test_error;
511 }
512
513 if (set_get_compare_clear_save_load(c, "lxc.hook.start", "/some/start", tmpf, false) < 0) {
514 lxc_error("%s\n", "lxc.hook.start");
515 goto non_test_error;
516 }
517
518 if (set_get_compare_clear_save_load(c, "lxc.hook.stop", "/some/stop", tmpf, false) < 0) {
519 lxc_error("%s\n", "lxc.hook.stop");
520 goto non_test_error;
521 }
522
523 if (set_get_compare_clear_save_load(c, "lxc.hook.post-stop", "/some/post-stop", tmpf, false) < 0) {
524 lxc_error("%s\n", "lxc.hook.post-stop");
525 goto non_test_error;
526 }
527
528 if (set_get_compare_clear_save_load(c, "lxc.hook.clone", "/some/clone", tmpf, false) < 0) {
529 lxc_error("%s\n", "lxc.hook.clone");
530 goto non_test_error;
531 }
532
533 if (set_get_compare_clear_save_load(c, "lxc.hook.destroy", "/some/destroy", tmpf, false) < 0) {
534 lxc_error("%s\n", "lxc.hook.destroy");
535 goto non_test_error;
536 }
537
538 if (set_get_compare_clear_save_load(c, "lxc.cap.drop", "sys_module mknod setuid net_raw", tmpf, false) < 0) {
539 lxc_error("%s\n", "lxc.cap.drop");
540 goto non_test_error;
541 }
542
543 if (set_get_compare_clear_save_load(c, "lxc.cap.keep", "sys_module mknod setuid net_raw", tmpf, false) < 0) {
544 lxc_error("%s\n", "lxc.cap.keep");
545 goto non_test_error;
546 }
547
548 if (set_get_compare_clear_save_load(c, "lxc.console.path", "none", tmpf, true) < 0) {
549 lxc_error("%s\n", "lxc.console.path");
550 goto non_test_error;
551 }
552
553 if (set_get_compare_clear_save_load(c, "lxc.console.logfile", "/some/logfile", tmpf, true) < 0) {
554 lxc_error("%s\n", "lxc.console.logfile");
555 goto non_test_error;
556 }
557
558 if (set_get_compare_clear_save_load(c, "lxc.seccomp.profile", "/some/seccomp/file", tmpf, true) < 0) {
559 lxc_error("%s\n", "lxc.seccomp.profile");
560 goto non_test_error;
561 }
562
563 if (set_get_compare_clear_save_load(c, "lxc.autodev.tmpfs.size", "1", tmpf, true) < 0) {
564 lxc_error("%s\n", "lxc.autodev.tmpfs.size");
565 goto non_test_error;
566 }
567
568 if (set_get_compare_clear_save_load(c, "lxc.autodev", "1", tmpf, true) <
569 0) {
570 lxc_error("%s\n", "lxc.autodev");
571 goto non_test_error;
572 }
573
574 if (set_get_compare_clear_save_load(c, "lxc.signal.halt", "1", tmpf, true) < 0) {
575 lxc_error("%s\n", "lxc.signal.halt");
576 goto non_test_error;
577 }
578
579 if (set_get_compare_clear_save_load(c, "lxc.signal.reboot", "1", tmpf, true) < 0) {
580 lxc_error("%s\n", "lxc.signal.reboot");
581 goto non_test_error;
582 }
583
584 if (set_get_compare_clear_save_load(c, "lxc.signal.stop", "1", tmpf, true) < 0) {
585 lxc_error("%s\n", "lxc.signal.stop");
586 goto non_test_error;
587 }
588
589 if (set_get_compare_clear_save_load(c, "lxc.start.auto", "1", tmpf, true) < 0) {
590 lxc_error("%s\n", "lxc.start.auto");
591 goto non_test_error;
592 }
593
594 if (set_get_compare_clear_save_load(c, "lxc.start.delay", "5", tmpf, true) < 0) {
595 lxc_error("%s\n", "lxc.start.delay");
596 goto non_test_error;
597 }
598
599 if (set_get_compare_clear_save_load(c, "lxc.start.order", "1", tmpf, true) < 0) {
600 lxc_error("%s\n", "lxc.start.order");
601 goto non_test_error;
602 }
603
604 if (set_get_compare_clear_save_load(c, "lxc.log.syslog", "local0", tmpf, true) < 0) {
605 lxc_error("%s\n", "lxc.log.syslog");
606 goto non_test_error;
607 }
608
609 if (set_get_compare_clear_save_load(c, "lxc.monitor.unshare", "1", tmpf, true) < 0) {
610 lxc_error("%s\n", "lxc.monitor.unshare");
611 goto non_test_error;
612 }
613
614 if (set_get_compare_clear_save_load(c, "lxc.group", "some,container,groups", tmpf, false) < 0) {
615 lxc_error("%s\n", "lxc.group");
616 goto non_test_error;
617 }
618
619 if (set_get_compare_clear_save_load(c, "lxc.environment", "FOO=BAR", tmpf, false) < 0) {
620 lxc_error("%s\n", "lxc.environment");
621 goto non_test_error;
622 }
623
624 if (set_get_compare_clear_save_load(c, "lxc.init.cmd", "/bin/bash", tmpf, true) < 0) {
625 lxc_error("%s\n", "lxc.init.cmd");
626 goto non_test_error;
627 }
628
629 if (set_get_compare_clear_save_load(c, "lxc.init.uid", "1000", tmpf, true) < 0) {
630 lxc_error("%s\n", "lxc.init.uid");
631 goto non_test_error;
632 }
633
634 if (set_get_compare_clear_save_load(c, "lxc.init.gid", "1000", tmpf, true) < 0) {
635 lxc_error("%s\n", "lxc.init.gid");
636 goto non_test_error;
637 }
638
639 if (set_get_compare_clear_save_load(c, "lxc.ephemeral", "1", tmpf, true) < 0) {
640 lxc_error("%s\n", "lxc.ephemeral");
641 goto non_test_error;
642 }
643
644 if (set_get_compare_clear_save_load(c, "lxc.no_new_privs", "1", tmpf, true) < 0) {
645 lxc_error("%s\n", "lxc.no_new_privs");
646 goto non_test_error;
647 }
648
649 if (set_get_compare_clear_save_load(c, "lxc.sysctl.net.core.somaxconn", "256", tmpf, true) < 0) {
650 lxc_error("%s\n", "lxc.sysctl.net.core.somaxconn");
651 goto non_test_error;
652 }
653
654 if (set_get_compare_clear_save_load(c, "lxc.proc.oom_score_adj", "10", tmpf, true) < 0) {
655 lxc_error("%s\n", "lxc.proc.oom_score_adj");
656 goto non_test_error;
657 }
658
659 if (set_get_compare_clear_save_load(c, "lxc.prlimit.nofile", "65536", tmpf, true) < 0) {
660 lxc_error("%s\n", "lxc.prlimit.nofile");
661 goto non_test_error;
662 }
663
664 if (test_idmap_parser() < 0) {
665 lxc_error("%s\n", "failed to test parser for \"lxc.id_map\"");
666 goto non_test_error;
667 }
668
669 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "veth", tmpf, true)) {
670 lxc_error("%s\n", "lxc.net.0.type");
671 goto non_test_error;
672 }
673
674 if (set_get_compare_clear_save_load(c, "lxc.net.2.type", "none", tmpf, true)) {
675 lxc_error("%s\n", "lxc.net.2.type");
676 goto non_test_error;
677 }
678
679 if (set_get_compare_clear_save_load(c, "lxc.net.3.type", "empty", tmpf, true)) {
680 lxc_error("%s\n", "lxc.net.3.type");
681 goto non_test_error;
682 }
683
684 if (set_get_compare_clear_save_load(c, "lxc.net.4.type", "vlan", tmpf, true)) {
685 lxc_error("%s\n", "lxc.net.4.type");
686 goto non_test_error;
687 }
688
689 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "macvlan", tmpf, true)) {
690 lxc_error("%s\n", "lxc.net.0.type");
691 goto non_test_error;
692 }
693
694 if (set_get_compare_clear_save_load(c, "lxc.net.0.type", "ipvlan", tmpf, true)) {
695 lxc_error("%s\n", "lxc.net.0.type");
696 goto non_test_error;
697 }
698
699 if (set_get_compare_clear_save_load(c, "lxc.net.1000.type", "phys", tmpf, true)) {
700 lxc_error("%s\n", "lxc.net.1000.type");
701 goto non_test_error;
702 }
703
704 if (set_get_compare_clear_save_load(c, "lxc.net.0.flags", "up", tmpf, true)) {
705 lxc_error("%s\n", "lxc.net.0.flags");
706 goto non_test_error;
707 }
708
709 if (set_get_compare_clear_save_load(c, "lxc.net.0.name", "eth0", tmpf, true)) {
710 lxc_error("%s\n", "lxc.net.0.name");
711 goto non_test_error;
712 }
713
714 if (set_get_compare_clear_save_load(c, "lxc.net.0.link", "bla", tmpf, true)) {
715 lxc_error("%s\n", "lxc.net.0.link");
716 goto non_test_error;
717 }
718
719 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.macvlan.mode", "private", tmpf, true, "macvlan")) {
720 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
721 goto non_test_error;
722 }
723
724 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.macvlan.mode", "vepa", tmpf, true, "macvlan")) {
725 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
726 goto non_test_error;
727 }
728
729 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.macvlan.mode", "bridge", tmpf, true, "macvlan")) {
730 lxc_error("%s\n", "lxc.net.0.macvlan.mode");
731 goto non_test_error;
732 }
733
734 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.mode", "l3", tmpf, true, "ipvlan")) {
735 lxc_error("%s\n", "lxc.net.0.ipvlan.mode");
736 goto non_test_error;
737 }
738
739 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.mode", "l3s", tmpf, true, "ipvlan")) {
740 lxc_error("%s\n", "lxc.net.0.ipvlan.mode");
741 goto non_test_error;
742 }
743
744 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.mode", "l2", tmpf, true, "ipvlan")) {
745 lxc_error("%s\n", "lxc.net.0.ipvlan.mode");
746 goto non_test_error;
747 }
748
749 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.isolation", "bridge", tmpf, true, "ipvlan")) {
750 lxc_error("%s\n", "lxc.net.0.ipvlan.isolation");
751 goto non_test_error;
752 }
753
754 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.isolation", "private", tmpf, true, "ipvlan")) {
755 lxc_error("%s\n", "lxc.net.0.ipvlan.isolation");
756 goto non_test_error;
757 }
758
759 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.ipvlan.isolation", "vepa", tmpf, true, "ipvlan")) {
760 lxc_error("%s\n", "lxc.net.0.ipvlan.isolation");
761 goto non_test_error;
762 }
763
764 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.pair", "clusterfuck", tmpf, true, "veth")) {
765 lxc_error("%s\n", "lxc.net.0.veth.pair");
766 goto non_test_error;
767 }
768
769 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.ipv4.route", "192.0.2.1/32", tmpf, true, "veth")) {
770 lxc_error("%s\n", "lxc.net.0.veth.ipv4.route");
771 return -1;
772 }
773
774 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.veth.ipv6.route", "2001:db8::1/128", tmpf, true, "veth")) {
775 lxc_error("%s\n", "lxc.net.0.veth.ipv6.route");
776 return -1;
777 }
778
779 if (set_get_compare_clear_save_load(c, "lxc.net.0.script.up", "/some/up/path", tmpf, true)) {
780 lxc_error("%s\n", "lxc.net.0.script.up");
781 goto non_test_error;
782 }
783
784 if (set_get_compare_clear_save_load(c, "lxc.net.0.script.down", "/some/down/path", tmpf, true)) {
785 lxc_error("%s\n", "lxc.net.0.script.down");
786 goto non_test_error;
787 }
788
789 if (set_get_compare_clear_save_load(c, "lxc.net.0.hwaddr", "52:54:00:80:7a:5d", tmpf, true)) {
790 lxc_error("%s\n", "lxc.net.0.hwaddr");
791 goto non_test_error;
792 }
793
794 if (set_get_compare_clear_save_load(c, "lxc.net.0.mtu", "2000", tmpf, true)) {
795 lxc_error("%s\n", "lxc.net.0.mtu");
796 goto non_test_error;
797 }
798
799 if (set_get_compare_clear_save_load_network(c, "lxc.net.0.vlan.id", "2", tmpf, true, "vlan")) {
800 lxc_error("%s\n", "lxc.net.0.vlan.id");
801 goto non_test_error;
802 }
803
804 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.gateway", "10.0.2.2", tmpf, true)) {
805 lxc_error("%s\n", "lxc.net.0.ipv4.gateway");
806 goto non_test_error;
807 }
808
809 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.gateway", "auto", tmpf, true)) {
810 lxc_error("%s\n", "lxc.net.0.ipv4.gateway");
811 goto non_test_error;
812 }
813
814 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.gateway", "dev", tmpf, true)) {
815 lxc_error("%s\n", "lxc.net.0.ipv4.gateway");
816 goto non_test_error;
817 }
818
819 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.gateway", "2003:db8:1::1", tmpf, true)) {
820 lxc_error("%s\n", "lxc.net.0.ipv6.gateway");
821 goto non_test_error;
822 }
823
824 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.gateway", "auto", tmpf, true)) {
825 lxc_error("%s\n", "lxc.net.0.ipv6.gateway");
826 goto non_test_error;
827 }
828
829 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.gateway", "dev", tmpf, true)) {
830 lxc_error("%s\n", "lxc.net.0.ipv6.gateway");
831 goto non_test_error;
832 }
833
834 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv4.address", "10.0.2.3/24", tmpf, true)) {
835 lxc_error("%s\n", "lxc.net.0.ipv4.address");
836 goto non_test_error;
837 }
838
839 if (set_get_compare_clear_save_load(c, "lxc.net.0.ipv6.address", "2003:db8:1:0:214:1234:fe0b:3596/64", tmpf, true)) {
840 lxc_error("%s\n", "lxc.net.0.ipv6.address");
841 goto non_test_error;
842 }
843
844 if (set_get_compare_clear_save_load(c, "lxc.cgroup.dir", "lxd", tmpf, true)) {
845 lxc_error("%s\n", "lxc.cgroup.dir");
846 goto non_test_error;
847 }
848
849 if (set_and_clear_complete_netdev(c) < 0) {
850 lxc_error("%s\n", "failed to clear whole network");
851 goto non_test_error;
852 }
853
854 if (set_invalid_netdev(c) < 0) {
855 lxc_error("%s\n", "failed to reject invalid configuration");
856 goto non_test_error;
857 }
858
859 ret = set_get_compare_clear_save_load(c, "lxc.hook.version", "1", tmpf, true);
860 if (ret < 0) {
861 lxc_error("%s\n", "lxc.hook.version");
862 goto non_test_error;
863 }
864
865 ret = set_get_compare_clear_save_load(c, "lxc.hook.version", "2", tmpf, true);
866 if (ret == 0) {
867 lxc_error("%s\n", "lxc.hook.version");
868 goto non_test_error;
869 }
870
871 ret = set_get_compare_clear_save_load(c, "lxc.monitor.signal.pdeath", "SIGKILL", tmpf, true);
872 if (ret == 0) {
873 lxc_error("%s\n", "lxc.hook.version");
874 goto non_test_error;
875 }
876
877 if (set_get_compare_clear_save_load(c, "lxc.rootfs.managed", "1", tmpf, true) < 0) {
878 lxc_error("%s\n", "lxc.rootfs.managed");
879 goto non_test_error;
880 }
881
882 if (c->set_config_item(c, "lxc.notaconfigkey", "invalid")) {
883 lxc_error("%s\n", "Managed to set to set invalid config item \"lxc.notaconfigkey\" to \"invalid\"");
884 return -1;
885 }
886
887 fret = EXIT_SUCCESS;
888
889 non_test_error:
890 (void)unlink(tmpf);
891 (void)rmdir(dirname(c->configfile));
892 lxc_container_put(c);
893 exit(fret);
894 }