Beispiel #1
0
static bool init(void)
{
	char *pool4_addrs[] = { "1.1.1.1", "2.2.2.2" };
	int i;

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

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

	if (is_error(config_init(false)))
		return false;

	if (is_error(pool4_init(pool4_addrs, ARRAY_SIZE(pool4_addrs)))) {
		config_destroy();
		return false;
	}

	if (is_error(bibdb_init())) {
		pool4_destroy();
		config_destroy();
		return false;
	}

	return true;
}
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;
}
void end_full(void)
{
	filtering_destroy();
	session_destroy();
	bib_destroy();
	pool4_destroy();
	pool6_destroy();
}
Beispiel #4
0
static void end(void)
{
	sessiondb_destroy();
	bibdb_destroy();
	pool6_destroy();
	pool4_destroy();
	pktqueue_destroy();
	config_destroy();
}
Beispiel #5
0
static bool init(void)
{
	int i;

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

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

	if (is_error(config_init(false)))
		goto config_fail;
	if (is_error(pktqueue_init()))
		goto pktqueue_fail;
	if (is_error(pool4_init(NULL, 0)))
		goto pool4_fail;
	if (is_error(pool6_init(NULL, 0)))
		goto pool6_fail;
	if (is_error(bibdb_init()))
		goto bib_fail;
	if (is_error(sessiondb_init()))
		goto session_fail;

	return true;

session_fail:
	bibdb_destroy();
bib_fail:
	pool6_destroy();
pool6_fail:
	pool4_destroy();
pool4_fail:
	pktqueue_destroy();
pktqueue_fail:
	config_destroy();
config_fail:
	return false;
}
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;
}
Beispiel #7
0
static void __exit nat64_exit(void)
{
	/* Release the hook. */
	nf_unregister_hooks(nfho, ARRAY_SIZE(nfho));

	/* Deinitialize the submodules. */
#ifdef BENCHMARK
	logtime_destroy();
#endif
	sendpkt_destroy();
	translate_packet_destroy();
	filtering_destroy();
	fragdb_destroy();
	sessiondb_destroy();
	bibdb_destroy();
	pktqueue_destroy();
	pool4_destroy();
	pool6_destroy();
	config_destroy();

	log_info(MODULE_NAME " module removed.");
}
Beispiel #8
0
bool init_full(void)
{
	char *prefixes[] = { "3::/96" };
	int error;

	error = config_init(false);
	if (error)
		goto config_fail;
	error = pool6_init(prefixes, ARRAY_SIZE(prefixes));
	if (error)
		goto pool6_fail;
	error = pool4_init(NULL, 0);
	if (error)
		goto pool4_fail;
	error = pktqueue_init();
	if (error)
		goto pktqueue_fail;
	error = bibdb_init();
	if (error)
		goto bibdb_fail;
	error = sessiondb_init();
	if (error)
		goto sessiondb_fail;

	return true;

sessiondb_fail:
	bibdb_destroy();
bibdb_fail:
	pktqueue_destroy();
pktqueue_fail:
	pool4_destroy();
pool4_fail:
	pool6_destroy();
pool6_fail:
	config_destroy();
config_fail:
	return false;
}
Beispiel #9
0
static void destroy(void)
{
    pool4_destroy();
}
Beispiel #10
0
static int __init nat64_init(void)
{
	int error;

	log_debug("%s", banner);
	log_debug("Inserting the module...");

	/* Init Jool's submodules. */
	error = config_init();
	if (error)
		goto config_failure;
	error = pool6_init(pool6, pool6_size);
	if (error)
		goto pool6_failure;
	error = pool4_init(pool4, pool4_size);
	if (error)
		goto pool4_failure;
	error = pktqueue_init();
	if (error)
		goto pktqueue_failure;
	error = bibdb_init();
	if (error)
		goto bib_failure;
	error = sessiondb_init();
	if (error)
		goto session_failure;
	error = fragdb_init();
	if (error)
		goto fragdb_failure;
	error = filtering_init();
	if (error)
		goto filtering_failure;
	error = translate_packet_init();
	if (error)
		goto translate_packet_failure;
	error = sendpkt_init();
	if (error)
		goto sendpkt_failure;
#ifdef BENCHMARK
	error = logtime_init();
	if (error)
		goto log_time_failure;
#endif

	/* Hook Jool to Netfilter. */
	error = nf_register_hooks(nfho, ARRAY_SIZE(nfho));
	if (error)
		goto nf_register_hooks_failure;

	/* Yay */
	log_info(MODULE_NAME " module inserted.");
	return error;

nf_register_hooks_failure:
#ifdef BENCHMARK
	logtime_destroy();

log_time_failure:
#endif
	sendpkt_destroy();

sendpkt_failure:
	translate_packet_destroy();

translate_packet_failure:
	filtering_destroy();

filtering_failure:
	fragdb_destroy();

fragdb_failure:
	sessiondb_destroy();

session_failure:
	bibdb_destroy();

bib_failure:
	pktqueue_destroy();

pktqueue_failure:
	pool4_destroy();

pool4_failure:
	pool6_destroy();

pool6_failure:
	config_destroy();

config_failure:
	return error;
}
Beispiel #11
0
static void end(void)
{
	bibdb_destroy();
	pool4_destroy();
	config_destroy();
}