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