Esempio n. 1
0
int main(int argc, char **argv)
{
  mesh_t meshA = mesh_new(3);
  fail_unless(meshA);
  lob_t secretsA = mesh_generate(meshA);
  fail_unless(secretsA);
  fail_unless(ext_link_auto(meshA));

  mesh_t meshB = mesh_new(3);
  fail_unless(meshB);
  lob_t secretsB = mesh_generate(meshB);
  fail_unless(secretsB);
  fail_unless(ext_link_auto(meshB));

  net_loopback_t pair = net_loopback_new(meshA,meshB);
  fail_unless(pair);
  
  link_t linkAB = link_get(meshA, meshB->id->hashname);
  link_t linkBA = link_get(meshB, meshA->id->hashname);
  fail_unless(linkAB);
  fail_unless(linkBA);

  fail_unless(link_sync(linkAB));

  // lob_t block = lob_new();
  // lob_append(block,NULL,1500);
//  fail_unless(ext_block_send(linkAB,block));
//  fail_unless(ext_block_receive(meshB));

  return 0;
}
Esempio n. 2
0
int main(int argc, char **argv)
{
  mesh_t meshA = mesh_new();
  fail_unless(meshA);
  mesh_on_link(meshA, "test", link_check); // testing the event being triggered
  lob_t secretsA = mesh_generate(meshA);
  fail_unless(secretsA);

  mesh_t meshB = mesh_new();
  fail_unless(meshB);
  lob_t secretsB = mesh_generate(meshB);
  fail_unless(secretsB);
  
  net_loopback_t pair = net_loopback_new(meshA,meshB);
  fail_unless(pair);
  
  link_t linkAB = link_get(meshA, meshB->id);
  link_t linkBA = link_get(meshB, meshA->id);
  fail_unless(linkAB);
  fail_unless(linkBA);

  fail_unless(link_resync(linkAB));
  fail_unless(link_up(linkAB));
  fail_unless(link_up(linkBA));
  fail_unless(status);
  
  fail_unless(mesh_process(meshA,1));
  fail_unless(mesh_linked(meshA, hashname_char(meshB->id),0));
  fail_unless(mesh_unlink(linkAB));
  fail_unless(mesh_process(meshA,1));
  fail_unless(!mesh_linked(meshA, hashname_char(meshB->id),0));
  fail_unless(!status);

  return 0;
}
Esempio n. 3
0
int main(int argc, char **argv)
{
  mesh_t meshA = mesh_new(3);
  fail_unless(meshA);
  lob_t secretsA = mesh_generate(meshA);
  fail_unless(secretsA);
  fail_unless(ext_stream(meshA));

  mesh_t meshB = mesh_new(3);
  fail_unless(meshB);
  lob_t secretsB = mesh_generate(meshB);
  fail_unless(secretsB);
  fail_unless(ext_stream(meshB));

  net_loopback_t pair = net_loopback_new(meshA,meshB);
  fail_unless(pair);
  
  link_t linkAB = link_get(meshA, meshB->id->hashname);
  link_t linkBA = link_get(meshB, meshA->id->hashname);
  fail_unless(linkAB);
  fail_unless(linkBA);

  fail_unless(link_resync(linkAB));

//  fail_unless(ext_link_status(linkAB,NULL));
//  fail_unless(ext_link_status(linkBA,NULL));

  return 0;
}
static gboolean
link_set_address (NMPlatform *platform, int ifindex, gconstpointer addr, size_t len)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	if (device->address)
		g_bytes_unref (device->address);

	device->address = g_bytes_new (addr, len);

	link_changed (platform, link_get (platform, ifindex));

	return TRUE;
}
Esempio n. 5
0
link_t mesh_add(mesh_t mesh, lob_t json, pipe_t pipe)
{
  link_t link;
  lob_t keys, paths;
  uint8_t csid;

  if(!mesh || !json) return LOG("bad args");
  LOG("mesh add %s",lob_json(json));
  link = link_get(mesh, hashname_vchar(lob_get(json,"hashname")));
  keys = lob_get_json(json,"keys");
  paths = lob_get_array(json,"paths");
  if(!link) link = link_keys(mesh, keys);
  if(!link) LOG("no hashname");
  
  LOG("loading keys/paths");
  if(keys && (csid = hashname_id(mesh->keys,keys))) link_load(link, csid, keys);

  // handle any pipe/paths
  if(pipe) link_pipe(link, pipe);
  lob_t path;
  for(path=paths;path;path = lob_next(path)) link_path(link,path);
  
  lob_free(keys);
  lob_freeall(paths);

  return link;
}
Esempio n. 6
0
File: link.c Progetto: fd/telehash-c
link_t link_key(mesh_t mesh, lob_t key)
{
  uint8_t csid;
  hashname_t hn;
  link_t link;

  if(!mesh || !key) return LOG("invalid args");
  csid = hashname_id(mesh->keys,key);
  if(!csid) return LOG("no supported key");

  hn = hashname_key(key);
  if(!hn) return LOG("invalid key");

  link = link_get(mesh, hn->hashname);
  if(link)
  {
    hashname_free(hn);
  }else{
    link = link_new(mesh,hn);
  }

  // load key if it's not yet
  if(!link->key) return link_load(link, csid, key);

  return link;
}
static gboolean
link_uses_arp (NMPlatform *platform, int ifindex)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	return device ? device->link.arp : FALSE;
}
Esempio n. 8
0
static int manager_process_link(Manager *m, struct udev_device *device) {
        Link *link = NULL;
        int r;

        assert(m);
        assert(device);

        link_get(m, udev_device_get_ifindex(device), &link);

        if (streq_ptr(udev_device_get_action(device), "remove")) {
                log_debug("%s: link removed", udev_device_get_sysname(device));

                if (link)
                        link_free(link);
        } else {
                if (link) {
                        log_debug("%s: link already exists, ignoring",
                                  link->ifname);
                        return 0;
                }

                r = link_add(m, device, &link);
                if (r < 0) {
                        log_error("%s: could not handle link: %s",
                                  udev_device_get_sysname(device),
                                  strerror(-r));
                } else
                        log_debug("%s: link (with ifindex %" PRIu64") added",
                                  link->ifname, link->ifindex);
        }

        return 0;
}
static gboolean
link_set_up (NMPlatform *platform, int ifindex)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	if (!device)
		return FALSE;

	device->link.up = TRUE;
	switch (device->link.type) {
	case NM_LINK_TYPE_DUMMY:
	case NM_LINK_TYPE_VLAN:
		device->link.connected = TRUE;
		break;
	case NM_LINK_TYPE_BRIDGE:
	case NM_LINK_TYPE_BOND:
	case NM_LINK_TYPE_TEAM:
		device->link.connected = FALSE;
		break;
	default:
		device->link.connected = FALSE;
		g_error ("Unexpected device type: %d", device->link.type);
	}

	link_changed (platform, device);

	return TRUE;
}
Esempio n. 10
0
static gboolean
link_is_connected (NMPlatform *platform, int ifindex)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	return device ? device->link.connected : FALSE;
}
Esempio n. 11
0
static NMLinkType
link_get_type (NMPlatform *platform, int ifindex)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	return device ? device->link.type : NM_LINK_TYPE_NONE;
}
Esempio n. 12
0
static const char *
link_get_name (NMPlatform *platform, int ifindex)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	return device ? device->link.name : NULL;
}
Esempio n. 13
0
static guint32
link_get_mtu (NMPlatform *platform, int ifindex)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	return device ? device->link.mtu : 0;
}
Esempio n. 14
0
static gboolean
link_get_wake_on_lan (NMPlatform *platform, int ifindex)
{
	/* We call link_get just to cause an error to be set if @ifindex is bad. */
	link_get (platform, ifindex);

	return FALSE;
}
Esempio n. 15
0
static char *
link_get_physical_port_id (NMPlatform *platform, int ifindex)
{
	/* We call link_get just to cause an error to be set if @ifindex is bad. */
	link_get (platform, ifindex);

	return NULL;
}
Esempio n. 16
0
static gboolean
_nm_platform_link_get (NMPlatform *platform, int ifindex, NMPlatformLink *l)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	if (device)
		*l = device->link;
	return !!device;
}
Esempio n. 17
0
static int
link_get_master (NMPlatform *platform, int slave)
{
	NMFakePlatformLink *device = link_get (platform, slave);

	g_return_val_if_fail (device, FALSE);

	return device->link.master;
}
Esempio n. 18
0
static gboolean
link_release (NMPlatform *platform, int master_idx, int slave_idx)
{
	NMFakePlatformLink *master = link_get (platform, master_idx);
	NMFakePlatformLink *slave = link_get (platform, slave_idx);

	g_return_val_if_fail (master, FALSE);
	g_return_val_if_fail (slave, FALSE);

	if (slave->link.master != master->link.ifindex) {
		platform->error = NM_PLATFORM_ERROR_NOT_SLAVE;
		return FALSE;
	}

	slave->link.master = 0;

	link_changed (platform, slave);
	link_changed (platform, master);

	return TRUE;
}
Esempio n. 19
0
static gboolean
link_set_mtu (NMPlatform *platform, int ifindex, guint32 mtu)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	if (device) {
		device->link.mtu = mtu;
		link_changed (platform, device);
	}

	return !!device;
}
Esempio n. 20
0
static gboolean
link_enslave (NMPlatform *platform, int master, int slave)
{
	NMFakePlatformLink *device = link_get (platform, slave);

	g_return_val_if_fail (device, FALSE);

	device->link.master = master;

	link_changed (platform, device);

	return TRUE;
}
Esempio n. 21
0
static gconstpointer
link_get_address (NMPlatform *platform, int ifindex, size_t *length)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	if (!device || !device->address) {
		if (length)
			*length = 0;
		return NULL;
	}

	return g_bytes_get_data (device->address, length);
}
Esempio n. 22
0
static gboolean
vlan_get_info (NMPlatform *platform, int ifindex, int *parent, int *vlan_id)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	g_return_val_if_fail (device, FALSE);

	if (parent)
		*parent = device->link.parent;
	if (vlan_id)
		*vlan_id = device->vlan_id;

	return TRUE;
}
Esempio n. 23
0
static gboolean
link_set_noarp (NMPlatform *platform, int ifindex)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	if (!device)
		return FALSE;

	device->link.arp = FALSE;

	link_changed (platform, device);

	return TRUE;
}
Esempio n. 24
0
static gboolean
link_added_emit (gpointer user_data)
{
	LinkAddedInfo *info = user_data;
	NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (info->platform);
	NMFakePlatformLink *device;

	priv->link_added_ids = g_slist_remove (priv->link_added_ids, GUINT_TO_POINTER (info->id));

	device = link_get (info->platform, info->ifindex);
	g_assert (device);
	g_signal_emit_by_name (info->platform, NM_PLATFORM_LINK_ADDED, info->ifindex, &device->link, NM_PLATFORM_REASON_INTERNAL);
	return FALSE;
}
Esempio n. 25
0
static gboolean
link_supports_vlans (NMPlatform *platform, int ifindex)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	if (!device)
		return FALSE;

	switch (device->link.type) {
	case NM_LINK_TYPE_LOOPBACK:
		return FALSE;
	default:
		return TRUE;
	}
}
Esempio n. 26
0
static gboolean
link_supports_carrier_detect (NMPlatform *platform, int ifindex)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	if (!device)
		return FALSE;

	switch (device->link.type) {
	case NM_LINK_TYPE_DUMMY:
		return FALSE;
	default:
		return TRUE;
	}
}
Esempio n. 27
0
link_t link_get_key(mesh_t mesh, lob_t key, uint8_t csid)
{
  link_t link;

  if(!mesh || !key) return LOG("invalid args");
  if(hashname_id(mesh->keys,key) > csid) return LOG("invalid csid");

  link = link_get(mesh, hashname_vkey(key, csid));
  if(!link) return LOG("invalid key");

  // load key if it's not yet
  if(!link->key) return link_load(link, csid, key);

  return link;
}
Esempio n. 28
0
static gboolean
infiniband_partition_add (NMPlatform *platform, int parent, int p_key)
{
	NMFakePlatformLink *parent_device;
	char *name;
	gboolean success;

	parent_device = link_get (platform, parent);
	g_return_val_if_fail (parent_device != NULL, FALSE);

	name = g_strdup_printf ("%s.%04x", parent_device->link.name, p_key);
	success = link_add (platform, name, NM_LINK_TYPE_INFINIBAND, NULL, 0);
	g_free (name);

	return success;
}
Esempio n. 29
0
static gboolean
vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint32 vlan_flags)
{
	NMFakePlatformLink *device;

	if (!link_add (platform, name, NM_LINK_TYPE_VLAN, NULL, 0))
		return FALSE;

	device = link_get (platform, link_get_ifindex (platform, name));

	g_return_val_if_fail (device, FALSE);

	device->vlan_id = vlan_id;
	device->link.parent = parent;

	return TRUE;
}
Esempio n. 30
0
static gboolean
link_delete (NMPlatform *platform, int ifindex)
{
	NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
	NMFakePlatformLink *device = link_get (platform, ifindex);
	NMPlatformLink deleted_device;
	int i;

	if (!device || !device->link.ifindex)
		return FALSE;

	memcpy (&deleted_device, &device->link, sizeof (deleted_device));
	memset (&device->link, 0, sizeof (device->link));

	/* Remove addresses and routes which belong to the deleted interface */
	for (i = 0; i < priv->ip4_addresses->len; i++) {
		NMPlatformIP4Address *address = &g_array_index (priv->ip4_addresses, NMPlatformIP4Address, i);

		if (address->ifindex == ifindex)
			memset (address, 0, sizeof (*address));
	}
	for (i = 0; i < priv->ip6_addresses->len; i++) {
		NMPlatformIP6Address *address = &g_array_index (priv->ip6_addresses, NMPlatformIP6Address, i);

		if (address->ifindex == ifindex)
			memset (address, 0, sizeof (*address));
	}
	for (i = 0; i < priv->ip4_routes->len; i++) {
		NMPlatformIP4Route *route = &g_array_index (priv->ip4_routes, NMPlatformIP4Route, i);

		if (route->ifindex == ifindex)
			memset (route, 0, sizeof (*route));
	}
	for (i = 0; i < priv->ip6_routes->len; i++) {
		NMPlatformIP6Route *route = &g_array_index (priv->ip6_routes, NMPlatformIP6Route, i);

		if (route->ifindex == ifindex)
			memset (route, 0, sizeof (*route));
	}

	g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, ifindex, &deleted_device, NM_PLATFORM_SIGNAL_REMOVED, NM_PLATFORM_REASON_INTERNAL);

	return TRUE;
}