#include <string.h>
#include <unistd.h>
#include <stdlib.h>

#include "zdtmtst.h"

const char *test_doc	= "Check that network environment (links, addresses and routes) are preserved";
const char *test_author	= "Pavel Emelianov <xemul@parallels.com>";

static int test_fn(int argc, char **argv)
{
	if (system("ip link set lo up")) {
		fail("Can't set lo up");
		return -1;
	}

	if (system("ip addr add 1.2.3.4 dev lo")) {
		fail("Can't add addr on lo");
		return -1;
	}

	if (system("ip route add 1.2.3.5 dev lo")) {
		fail("Can't add route via lo");
		return -1;
	}

	if (system("ip route add 1.2.3.6 via 1.2.3.5")) {
		fail("Can't add route via lo (2)");
		return -1;
	}

	if (system("ip link > ip.dump && ip addr >> ip.dump && ip route >> ip.dump")) {
		fail("Can't save net config");
		return -1;
	}

	test_daemon();
	test_waitsig();

	if (system("ip link > ip.rst && ip addr >> ip.rst && ip route >> ip.rst")) {
		fail("Can't get net config");
		return -1;
	}

	if (system("diff ip.rst ip.dump")) {
		fail("Net config differs after restore");
		return -1;
	}

	pass();
	return 0;
}

#define CLONE_NEWNET     0x40000000

int main(int argc, char **argv)
{
	test_init_ns(argc, argv, CLONE_NEWNET, test_fn);
	return 0;
}

