Exemplo n.º 1
0
static bool test_address_filtering(void)
{
	struct session_entry *session;
	bool success = true;

	/* Init. */
	session = create_and_insert_session(0, 0, 0, 0);
	if (!session)
		return false;

	/* Test the packet is allowed when the tuple and session match perfectly. */
	success &= assert_true(test_address_filtering_aux(0, 0, 0, 0), "lol1");
	/* Test a tuple that completely mismatches the session. */
	success &= assert_false(test_address_filtering_aux(1, 1, 1, 1), "lol2");
	/* Now test tuples that nearly match the session. */
	success &= assert_false(test_address_filtering_aux(0, 0, 0, 1), "lol3");
	success &= assert_false(test_address_filtering_aux(0, 0, 1, 0), "lol4");
	/* The remote port is the only one that doesn't matter. */
	success &= assert_true(test_address_filtering_aux(0, 1, 0, 0), "lol5");
	success &= assert_false(test_address_filtering_aux(1, 0, 0, 0), "lol6");

	/* Now we erase the session entry */
	remove(session, &session_table_udp);
	session_return(session);
	session = NULL;

	/* Repeat the "lol5" test but now the assert must be false */
	success &= assert_false(test_address_filtering_aux(0, 1, 0, 0), "lol7");


	return success;
}
Exemplo n.º 2
0
bool test_address_filtering(void)
{
	struct bib_entry *bib;
	struct session_entry *session;
	bool success = true;

	/* Init. */
	bib = create_and_insert_bib(0, 0, IPPROTO_UDP);
	if (!bib)
		return false;
	session = create_and_insert_session(0, 0, 0, 0, bib, IPPROTO_UDP, 12345);
	if (!session)
		return false;

	/* Test the packet is allowed when the tuple and session match perfectly. */
	success &= assert_true(test_address_filtering_aux(0, 0, 0, 0), "");
	/* Test a tuple that completely mismatches the session. */
	success &= assert_false(test_address_filtering_aux(1, 1, 1, 1), "");
	/* Now test tuples that nearly match the session. */
	success &= assert_false(test_address_filtering_aux(0, 0, 0, 1), "");
	success &= assert_false(test_address_filtering_aux(0, 0, 1, 0), "");
	/* The remote port is the only one that doesn't matter. */
	success &= assert_true(test_address_filtering_aux(0, 1, 0, 0), "");
	success &= assert_false(test_address_filtering_aux(1, 0, 0, 0), "");

	return true;
}
Exemplo n.º 3
0
bool test_address_filtering(void)
{
	struct bib_entry *bib;
	struct session_entry *session;

	// Init.
	bib = create_bib_entry(0, 0);
	if (!bib) {
		log_warning("Could not allocate a BIB entry.");
		return false;
	}
	session = create_session_entry(0, 0, 0, 0, bib, IPPROTO_UDP, 12345);
	if (!session) {
		log_warning("Could not allocate a Session entry.");
		return false;
	}

	if (!bib_add(bib, IPPROTO_UDP)) {
		log_warning("Could not add the BIB entry.");
		return false;
	}
	if (!session_add(session)) {
		log_warning("Could not add the session entry.");
		return false;
	}

	// Test the packet is allowed when the tuple and session match perfectly.
	if (!test_address_filtering_aux(0, 0, 0, 0, true))
		return false;

	// Test a tuple that completely mismatches the session.
	if (!test_address_filtering_aux(1, 1, 1, 1, false))
		return false;

	// Now test tuples that nearly match the session.
	if (!test_address_filtering_aux(0, 0, 0, 1, false))
		return false;
	if (!test_address_filtering_aux(0, 0, 1, 0, false))
		return false;
	if (!test_address_filtering_aux(0, 1, 0, 0, true))
		return false; // The remote port is the only one that doesn't matter.
	if (!test_address_filtering_aux(1, 0, 0, 0, false))
		return false;

	return true;
}