Пример #1
0
static int handle_eamt_flush(struct eam_table *eamt)
{
	if (verify_superpriv())
		return -EPERM;

	eamt_flush(eamt);
	return 0;
}
Пример #2
0
static int handle_eamt_config(struct nlmsghdr *nl_hdr, struct request_hdr *jool_hdr,
		union request_eamt *request)
{
	__u64 count;
	int error;

	if (xlat_is_nat64()) {
		log_err("Stateful NAT64 doesn't have an EAMT.");
		return -EINVAL;
	}

	switch (jool_hdr->operation) {
	case OP_DISPLAY:
		return handle_eamt_display(nl_hdr, request);

	case OP_COUNT:
		log_debug("Returning EAMT count.");
		error = eamt_count(&count);
		if (error)
			return respond_error(nl_hdr, error);
		return respond_setcfg(nl_hdr, &count, sizeof(count));

	case OP_TEST:
		return handle_eamt_test(nl_hdr, request);

	case OP_ADD:
		if (verify_superpriv())
			return respond_error(nl_hdr, -EPERM);

		log_debug("Adding EAMT entry.");
		return respond_error(nl_hdr, eamt_add(&request->add.prefix6,
				&request->add.prefix4, request->add.force));

	case OP_REMOVE:
		if (verify_superpriv())
			return respond_error(nl_hdr, -EPERM);

		log_debug("Removing EAMT entry.");
		return respond_error(nl_hdr, eamt_rm(
				request->rm.prefix6_set ? &request->rm.prefix6 : NULL,
				request->rm.prefix4_set ? &request->rm.prefix4 : NULL));

	case OP_FLUSH:
		if (verify_superpriv())
			return respond_error(nl_hdr, -EPERM);

		eamt_flush();
		return respond_error(nl_hdr, 0);

	default:
		log_err("Unknown operation: %d", jool_hdr->operation);
		return respond_error(nl_hdr, -EINVAL);
	}
}
Пример #3
0
static bool remove_test(void)
{
	bool success = true;

	/* trie is empty */
	success &= remove_entry("10.0.0.0", 24, "1::", 120, -ESRCH);

	/* trie is one node high */
	success &= add_entry("20.0.0.0", 25, "2::", 121);
	success &= remove_entry("30.0.0.1", 25, NULL, 0, -ESRCH);
	success &= remove_entry("20.0.0.130", 25, NULL, 0, -ESRCH);
	success &= remove_entry("20.0.0.120", 25, NULL, 0, 0);

	success &= add_entry("30.0.0.0", 24, "3::", 120);
	success &= test("30.0.0.0", "3::");
	success &= remove_entry(NULL, 0, "3::1:0", 120, -ESRCH);
	success &= test("30.0.0.0", "3::");
	success &= remove_entry(NULL, 0, "3::0", 120, 0);
	success &= test_6to4("3::", NULL);
	success &= test_4to6("30.0.0.0", NULL);

	success &= ASSERT_U64(0ULL, eamt.count, "Table count");
	if (!success)
		return false;

	/* trie is two nodes high */
	success &= create_two_story_trie();
	success &= remove_entry(NULL, 0, "1::10", 124, 0);
	success &= test("1.0.0.0", "1::00");
	success &= test_6to4("1::10", "1.0.0.0");
	success &= test_4to6("2.0.0.0", NULL);
	success &= test("3.0.0.0", "1::20");
	eamt_flush();

	success &= create_two_story_trie();
	success &= remove_entry(NULL, 0, "1::20", 124, 0);
	success &= test("1.0.0.0", "1::00");
	success &= test("2.0.0.0", "1::10");
	success &= test_6to4("1::20", "1.0.0.0");
	success &= test_4to6("3.0.0.0", NULL);
	eamt_flush();

	success &= create_two_story_trie();
	success &= remove_entry(NULL, 0, "1::00", 120, 0);
	success &= test_6to4("1::00", NULL);
	success &= test_4to6("1.0.0.0", NULL);
	success &= test("2.0.0.0", "1::10");
	success &= test("3.0.0.0", "1::20");
	eamt_flush();

	/* trie is three or more nodes high */
	success &= create_four_story_trie();
	success &= remove_entry(NULL, 0, "1::", 16, 0);
	success &= test_6to4("1::", NULL);
	success &= test_4to6("1.0.0.0", NULL);
	success &= test("2.0.0.0", "1:1::");
	success &= test("3.0.0.0", "1:2::");
	success &= test("4.0.0.0", "1:1:1::");
	success &= test("5.0.0.0", "1:1:2::");
	success &= test("6.0.0.0", "1:2:1::");
	success &= test("7.0.0.0", "1:2:1:1::");
	eamt_flush();

	success &= create_four_story_trie();
	success &= remove_entry(NULL, 0, "1:1::", 32, 0);
	success &= test("1.0.0.0", "1::");
	success &= test_6to4("1:1::", "1.0.0.0");
	success &= test("3.0.0.0", "1:2::");
	success &= test("4.0.0.0", "1:1:1::");
	success &= test("5.0.0.0", "1:1:2::");
	success &= test("6.0.0.0", "1:2:1::");
	success &= test("7.0.0.0", "1:2:1:1::");
	eamt_flush();

	success &= create_four_story_trie();
	success &= remove_entry(NULL, 0, "1:2::", 32, 0);
	success &= test("1.0.0.0", "1::");
	success &= test("2.0.0.0", "1:1::");
	success &= test_6to4("1:2::", "1.0.0.0");
	success &= test("4.0.0.0", "1:1:1::");
	success &= test("5.0.0.0", "1:1:2::");
	success &= test("6.0.0.0", "1:2:1::");
	success &= test("7.0.0.0", "1:2:1:1::");
	eamt_flush();

	success &= create_four_story_trie();
	success &= remove_entry(NULL, 0, "1:1:1::", 48, 0);
	success &= test("1.0.0.0", "1::");
	success &= test("2.0.0.0", "1:1::");
	success &= test("3.0.0.0", "1:2::");
	success &= test_6to4("1:1:1::", "2.0.0.0");
	success &= test("5.0.0.0", "1:1:2::");
	success &= test("6.0.0.0", "1:2:1::");
	success &= test("7.0.0.0", "1:2:1:1::");
	eamt_flush();

	success &= create_four_story_trie();
	success &= remove_entry(NULL, 0, "1:1:2::", 48, 0);
	success &= test("1.0.0.0", "1::");
	success &= test("2.0.0.0", "1:1::");
	success &= test("3.0.0.0", "1:2::");
	success &= test("4.0.0.0", "1:1:1::");
	success &= test_6to4("1:1:2::", "2.0.0.0");
	success &= test("6.0.0.0", "1:2:1::");
	success &= test("7.0.0.0", "1:2:1:1::");
	eamt_flush();

	success &= create_four_story_trie();
	success &= remove_entry(NULL, 0, "1:2:1::", 48, 0);
	success &= test("1.0.0.0", "1::");
	success &= test("2.0.0.0", "1:1::");
	success &= test("3.0.0.0", "1:2::");
	success &= test("4.0.0.0", "1:1:1::");
	success &= test("5.0.0.0", "1:1:2::");
	success &= test_6to4("1:2:1::", "3.0.0.0");
	success &= test("7.0.0.0", "1:2:1:1::");
	eamt_flush();

	success &= create_four_story_trie();
	success &= remove_entry(NULL, 0, "1:2:1:1::", 64, 0);
	success &= test("1.0.0.0", "1::");
	success &= test("2.0.0.0", "1:1::");
	success &= test("3.0.0.0", "1:2::");
	success &= test("4.0.0.0", "1:1:1::");
	success &= test("5.0.0.0", "1:1:2::");
	success &= test("6.0.0.0", "1:2:1::");
	success &= test_6to4("1:2:1:1::", "6.0.0.0");
	eamt_flush();

	return success;
}
Пример #4
0
Файл: eam.c Проект: NICMx/Jool
static int handle_eamt_flush(struct eam_table *eamt)
{
	eamt_flush(eamt);
	return 0;
}