コード例 #1
0
bool test_allocate_ipv4_transport_address_digger( void )
{
    struct in_addr expected_addr;
    struct tuple tuple;
    struct ipv4_tuple_address new_ipv4_transport_address;
    bool success = true;

    bib_init();
    pool4_init(true);

    success &= inject_bib_entry( IPPROTO_ICMP );
    success &= inject_bib_entry( IPPROTO_TCP );
    success &= init_tuple_for_test_ipv6(&tuple, IPPROTO_UDP);
    success &= str_to_addr4_verbose(IPV4_ALLOCATED_ADDR, &expected_addr);
    if (!success)
    	return false;
    
    success &= assert_true( allocate_ipv4_transport_address_digger(&tuple, IPPROTO_UDP, &new_ipv4_transport_address),
        "Check that we can allocate a brand new IPv4 transport address for UDP.");
    success &= assert_true( ipv4_addr_equals(&new_ipv4_transport_address.address, &expected_addr) ,
        "Check that the allocated IPv4 address is correct for UDP.");
    success &= assert_equals_u16( IPV4_ALLOCATED_PORT_DIGGER, new_ipv4_transport_address.l4_id,
        "Check that the allocated IPv4 port is correct for UDP.");

    pool4_destroy();
    bib_destroy();

    return success;
}
コード例 #2
0
bool init_full(void)
{
	int error;

	error = pool6_init(NULL, 0);
	if (error)
		goto fail;
	error = pool4_init(NULL, 0);
	if (error)
		goto fail;
	error = bib_init();
	if (error)
		goto fail;
	error = session_init(session_expired_callback);
	if (error)
		goto fail;
	error = filtering_init();
	if (error)
		goto fail;

	return true;

fail:
	return false;
}
コード例 #3
0
ファイル: bib_session_test.c プロジェクト: kuldeepin/NAT64
bool init(void)
{
	int error;
	int i;

	for (i = 0; i < ARRAY_SIZE(IPV4_ADDRS); i++) {
		error = str_to_addr4(IPV4_ADDRS[i], &addr4[i].address);
		if (error)
			return false;
		addr4[i].l4_id = IPV4_PORTS[i];
	}

	for (i = 0; i < ARRAY_SIZE(IPV4_ADDRS); i++) {
		error = str_to_addr6(IPV6_ADDRS[i], &addr6[i].address);
		if (error)
			return false;
		addr6[i].l4_id = IPV6_PORTS[i];
	}

	error = bib_init();
	if (error)
		return false;

	error = session_init(session_always_dies);
	if (error) {
		bib_destroy();
		return false;
	}

	return true;
}
コード例 #4
0
static bool init(void)
{
	if (bib_init())
		return false;
	db = bib_create();
	if (!db)
		bib_destroy();
	return db;
}
コード例 #5
0
bool init_full(void)
{
	bool success = true;

	success &= pool6_init();
	success &= pool4_init(true);
	success &= bib_init();
	success &= session_init();
	success &= filtering_init();

	return success;
}
コード例 #6
0
/**
 * Prepares the environment for the tests.
 *
 * @return whether the initialization was successful or not. An error message has been printed to
 *		the kernel ring buffer.
 */
static bool init(void)
{
	u_int8_t protocols[] = { IPPROTO_UDP, IPPROTO_TCP, IPPROTO_ICMP };
	int i;
	struct ipv6_prefix prefix;

	// Init test addresses
	if (str_to_addr6(remote_ipv6_str, &remote_ipv6) != 0) {
		log_warning("Can't parse address '%s'. Failing test...", remote_ipv6_str);
		return false;
	}
	if (str_to_addr6(local_ipv6_str, &local_ipv6) != 0) {
		log_warning("Can't parse address '%s'. Failing test...", local_ipv6_str);
		return false;
	}
	if (str_to_addr4(local_ipv4_str, &local_ipv4) != 0) {
		log_warning("Can't parse address '%s'. Failing test...", local_ipv4_str);
		return false;
	}
	if (str_to_addr4(remote_ipv4_str, &remote_ipv4) != 0) {
		log_warning("Can't parse address '%s'. Failing test...", remote_ipv4_str);
		return false;
	}

	// Init the IPv6 pool module
	if (!pool6_init())
		return false;
	if (str_to_addr6("64:ff9b::", &prefix.address) != 0) {
		log_warning("Cannot parse the IPv6 prefix. Failing...");
		return false;
	}
	prefix.len = 96;
	if (pool6_register(&prefix) != 0) {
		log_warning("Could not add the IPv6 prefix. Failing...");
		return false;
	}

	// Init the BIB module
	if (!bib_init())
		return false;

	for (i = 0; i < ARRAY_SIZE(protocols); i++)
		if (!add_bib(&local_ipv4, 80, &remote_ipv6, 1500, protocols[i]))
			return false;

	return true;
}
コード例 #7
0
/**
 * Prepares the environment for the tests.
 *
 * @return whether the initialization was successful or not. An error message has been printed to
 *		the kernel ring buffer.
 */
static bool init(void)
{
	l4_protocol l4_protos[] = { L4PROTO_UDP, L4PROTO_TCP, L4PROTO_ICMP };
	int i;
	struct ipv6_prefix prefix;

	/* Init test addresses */
	if (str_to_addr6(remote_ipv6_str, &remote_ipv6) != 0) {
		log_warning("Can't parse address '%s'. Failing test...", remote_ipv6_str);
		return false;
	}
	if (str_to_addr6(local_ipv6_str, &local_ipv6) != 0) {
		log_warning("Can't parse address '%s'. Failing test...", local_ipv6_str);
		return false;
	}
	if (str_to_addr4(local_ipv4_str, &local_ipv4) != 0) {
		log_warning("Can't parse address '%s'. Failing test...", local_ipv4_str);
		return false;
	}
	if (str_to_addr4(remote_ipv4_str, &remote_ipv4) != 0) {
		log_warning("Can't parse address '%s'. Failing test...", remote_ipv4_str);
		return false;
	}

	/* Init the IPv6 pool module */
	if (is_error(pool6_init(NULL, 0))) /* we'll use the defaults. */
		return false;
	if (str_to_addr6("64:ff9b::", &prefix.address) != 0) {
		log_warning("Cannot parse the IPv6 prefix. Failing...");
		return false;
	}
	prefix.len = 96;

	/* Init the BIB module */
	if (is_error(bib_init()))
		return false;

	for (i = 0; i < ARRAY_SIZE(l4_protos); i++)
		if (!add_bib(&local_ipv4, 80, &remote_ipv6, 1500, l4_protos[i]))
			return false;

	return true;
}
コード例 #8
0
bool test_allocate_ipv4_transport_address( void )
{
	u_int8_t protocols[] = { IPPROTO_ICMP, IPPROTO_TCP, IPPROTO_UDP };
	__u16 expected_ports[] = { IPV6_ALLOCATE_PORT, IPV6_ALLOCATE_PORT, IPV6_ALLOCATE_PORT };

    struct in_addr expected_addr;
    
    struct tuple tuple;
    struct ipv4_tuple_address new_ipv4_transport_address;

    bool success = true;
    int i;

    success &= pool6_init();
    success &= pool4_init(true);
    success &= bib_init();
    success &= str_to_addr4_verbose(IPV4_ALLOCATED_ADDR, &expected_addr);
    success &= inject_bib_entry( IPPROTO_ICMP );
    success &= inject_bib_entry( IPPROTO_TCP );
    success &= inject_bib_entry( IPPROTO_UDP );
    if (!success)
    	return false;

    for (i = 0; i < ARRAY_SIZE(protocols); i++)
    {
		init_tuple_for_test_ipv6(&tuple, protocols[i]);

		success &= assert_true(allocate_ipv4_transport_address(&tuple, protocols[i], &new_ipv4_transport_address),
			"Check that we can allocate a brand new IPv4 transport address.");
		success &= assert_equals_ipv4(&expected_addr , &new_ipv4_transport_address.address,
			"Check that the allocated IPv4 address is correct.");
		success &= assert_equals_u16( expected_ports[i], new_ipv4_transport_address.l4_id,
			"Check that the allocated IPv4 port is correct.");
    }

    bib_destroy();
    pool4_destroy();
    pool6_destroy();

    return success;
}
コード例 #9
0
bool init(void)
{
	return bib_init() && session_init();
}