Beispiel #1
0
void iface_test_new_unmanaged(void)
{
	iface_register_user(&user_mock);

	struct iface *iface = iface_create("test0", NULL, 0);
	sput_fail_unless(!!iface, "alloc unmanaged");

	struct iface *iface2 = iface_get("test0");
	sput_fail_unless(iface == iface2, "get after create");

	struct iface *iface3 = iface_create("test0", NULL, 0);
	sput_fail_unless(iface == iface3, "create after create");

	iface_remove(iface);
	sput_fail_unless(!iface_get("test0"), "delete");

	smock_is_empty();
	iface_unregister_user(&user_mock);
}
Beispiel #2
0
iface_t *iface_bind(int family, int port)
{
	iface_t *iface;

	iface = iface_create(family);
	if(iface != NULL)
	{
		if(family == AF_INET)
		{
			((struct sockaddr_in *) iface->addr)->sin_port = htons(port);
		}
		else if(family == AF_INET6)
		{
			((struct sockaddr_in6 *) iface->addr)->sin6_port = htons(port);
		}

		iface->socket_fd = socket(family, SOCK_STREAM, 0);
		if(iface->socket_fd == -1)
		{
			iface_destroy(iface);
			iface = NULL;
		}
		else
		{
			if(family == AF_INET)
			{
				if(inet_pton(family, "localhost", &(((struct sockaddr_in *) iface->addr)->sin_addr)) == -1)
				{
					iface_destroy(iface);
					iface = NULL;
				}
			}
			else if(family == AF_INET6)
			{
				if(inet_pton(family, "localhost", &(((struct sockaddr_in6 *) iface->addr)->sin6_addr)) == -1)
				{
					iface_destroy(iface);
					iface = NULL;
				}
			}

			if(iface != NULL)
			{
				bind(iface->socket_fd, iface->addr, iface->addrlen);
				listen(iface->socket_fd, 5);
			}
		}
	}

	return iface;
}
Beispiel #3
0
void iface_test_new_managed(void)
{
	struct in_addr v4source = {INADDR_LOOPBACK};
	iface_register_user(&user_mock);
	struct prefix p = {IN6ADDR_LOOPBACK_INIT, 0};
	char test[] = "test";

	struct iface *iface00 = iface_create("test00", "test00", 0);
	iface_update_ipv4_uplink(iface00);
	iface_set_ipv4_uplink(iface00, &v4source, 24);
	iface_commit_ipv4_uplink(iface00);
	/* smock_pull_bool_is("test00", false); */
        /* this was removed in the commit
           a5293745c235a057b6a477ffbd817937eaa9bc12 at 5/2015(!);
        */

	struct iface *iface = iface_create("test0", "test0", 0);
	iface->carrier = true;
	iface_discover_border(iface);

	sput_fail_unless(!!iface, "alloc managed");

	struct iface *iface2 = iface_get("test0");
	sput_fail_unless(iface == iface2, "get after create");

	struct iface *iface3 = iface_create("test0", "test0", 0);
	sput_fail_unless(iface == iface3, "create after create");

	/* smock_pull_bool_is("test0", false); */
        /* this was removed in the commit
           a5293745c235a057b6a477ffbd817937eaa9bc12 at 5/2015(!);
        */

	uloop_cancelled = false;
	uloop_run();
	smock_pull_bool_is("test0", true);

	iface_update_ipv4_uplink(iface);
	iface_set_ipv4_uplink(iface, &v4source, 24);
	iface_commit_ipv4_uplink(iface);
	smock_pull_bool_is("test0", false);

	iface_update_ipv4_uplink(iface);
	iface_commit_ipv4_uplink(iface);
	uloop_cancelled = false;
	uloop_run();
	smock_pull_bool_is("test0", true);

	iface_update_ipv6_uplink(iface);
	iface_add_delegated(iface, &p, NULL, HNETD_TIME_MAX, 0, test, sizeof(test));
	iface_commit_ipv6_uplink(iface);

	smock_pull_bool_is("test0", false);
	sput_fail_unless(!prefix_cmp(&p, (struct prefix *)smock_pull("prefix_prefix")), "prefix address");
	smock_pull_int64_is("prefix_valid", HNETD_TIME_MAX);
	smock_pull_int64_is("prefix_preferred", 0);
	sput_fail_unless(!strcmp(smock_pull("dhcpv6_data"), "test"), "dhcpv6_data");
	smock_pull_int_is("dhcpv6_len", sizeof(test));

	iface_update_ipv4_uplink(iface);
	iface_set_ipv4_uplink(iface, &v4source, 24);
	iface_commit_ipv4_uplink(iface);

	iface_update_ipv6_uplink(iface);
	iface_commit_ipv6_uplink(iface);
	smock_pull_bool_is("prefix_remove", true);

	iface_update_ipv4_uplink(iface);
	iface_commit_ipv4_uplink(iface);

	uloop_cancelled = false;
	uloop_run();
	smock_pull_bool_is("test0", true);

	iface_remove(iface);
	sput_fail_unless(!iface_get("test0"), "delete");
	smock_pull_bool_is("test0", false);
	smock_is_empty();
	iface_unregister_user(&user_mock);
}