Ejemplo n.º 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;
}
Ejemplo n.º 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;

    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;
}
Ejemplo n.º 3
0
bool assert_equals_ipv4(struct in_addr *expected, struct in_addr *actual, char *test_name)
{
	if (!ipv4_addr_equals(expected, actual)) {
		UNIT_WARNING(test_name, expected, actual, "%pI4");
		return false;
	}
	return true;
}
Ejemplo n.º 4
0
/** Check that first and last pool addresses belongs to the same network.
 *
 * @param[in] 	af			Address Family: AF_INET[6].
 * @param[in] 	network		Pool's network address.
 * @param[in] 	maskbits		Net mask in CIDR format ('/N').
 * @param[in] 	addr_first		First IP address.
 * @param[in] 	addr_last		Last IP address.
 * @return		true if all they belong to the same net, otherwise return false.
 */
int ip_addr_in_same_net(int af,
			const void *network, unsigned char maskbits,
	       	const void *addr_first, const void *addr_last)
{
	struct in_addr ipv4_net;
	struct in_addr ipv4_netmask;
	struct in_addr ipv4_first;
	struct in_addr ipv4_last;

	switch (af)
	{
		case AF_INET:
			convert_bits_to_netmask(af, maskbits, &ipv4_netmask);

			get_net_addr(af, (struct in_addr *)network, &ipv4_netmask, &ipv4_net);
			if ( !ipv4_addr_equals((struct in_addr *)network, &ipv4_net)  )
				return false;

			get_net_addr(af, (struct in_addr *)addr_first, &ipv4_netmask, &ipv4_first);
			if ( !ipv4_addr_equals(&ipv4_net, &ipv4_first)  )
				return false;

			get_net_addr(af, (struct in_addr *)addr_last, &ipv4_netmask, &ipv4_last);
			if ( !ipv4_addr_equals(&ipv4_net, &ipv4_last)  )
				return false;

			break;
		case AF_INET6:
			/* Is this necesary? */
			/* convert_bits_to_netmask(af, ipv6_bits, &ipv6_netmask); */
			break;
		default:
			/* log_warning("%s. Error, bad address family.", "ip_addr_in_same_net"); */
			return false;
	}

	return true;
}