예제 #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;

    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_true( new_ipv4_transport_address.l4_id % 2 == 0,
        "Check that the allocated IPv4 port is even.");
    success &= assert_true( new_ipv4_transport_address.l4_id > 1023,
		"Check that the allocated IPv4 port is in the upper range.");

    return success;
}
예제 #2
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;
}
예제 #3
0
bool test_allocate_ipv4_transport_address( void )
{
    struct tuple tuple;
    struct ipv4_tuple_address tuple_addr;
    struct in_addr expected_addr;
    bool success = true;

    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;

    init_tuple_for_test_ipv6(&tuple, IPPROTO_ICMP);
	success &= assert_true(allocate_ipv4_transport_address(&tuple, IPPROTO_ICMP, &tuple_addr),
		"Function result for ICMP");
	success &= assert_equals_ipv4(&expected_addr , &tuple_addr.address, "IPv4 address for ICMP");

	init_tuple_for_test_ipv6(&tuple, IPPROTO_TCP);
	success &= assert_true(allocate_ipv4_transport_address(&tuple, IPPROTO_TCP, &tuple_addr),
		"Function result for TCP");
	success &= assert_equals_ipv4(&expected_addr , &tuple_addr.address, "IPv4 address for TCP");
	success &= assert_true(tuple_addr.l4_id > 1023, "Port range for TCP");

	init_tuple_for_test_ipv6(&tuple, IPPROTO_UDP);
	success &= assert_true(allocate_ipv4_transport_address(&tuple, IPPROTO_UDP, &tuple_addr),
		"Function result for UDP");
	success &= assert_equals_ipv4(&expected_addr , &tuple_addr.address, "IPv4 address for UDP");
	success &= assert_true(tuple_addr.l4_id % 2 == 0, "Port parity for UDP");
	success &= assert_true( tuple_addr.l4_id > 1023, "Port range for UDP");

    return success;
}
예제 #4
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;
}