Пример #1
0
/*
  close all open network connections
*/
void close_network_connections(meshlink_handle_t *mesh) {
	if(mesh->connections) {
		for(list_node_t *node = mesh->connections->head, *next; node; node = next) {
			next = node->next;
			connection_t *c = node->data;
			c->outgoing = NULL;
			terminate_connection(mesh, c, false);
		}
	}

	if(mesh->outgoings)
		list_delete_list(mesh->outgoings);

	if(mesh->self && mesh->self->connection) {
		terminate_connection(mesh, mesh->self->connection, false);
		free_connection(mesh->self->connection);
	}

	for(int i = 0; i < mesh->listen_sockets; i++) {
		io_del(&mesh->loop, &mesh->listen_socket[i].tcp);
		io_del(&mesh->loop, &mesh->listen_socket[i].udp);
		close(mesh->listen_socket[i].tcp.fd);
		close(mesh->listen_socket[i].udp.fd);
	}

	exit_requests(mesh);
	exit_edges(mesh);
	exit_nodes(mesh);
	exit_connections(mesh);

	if(mesh->myport) free(mesh->myport);

	return;
}
Пример #2
0
/*
  close all open network connections
*/
void close_network_connections(void) {
    avl_node_t *node, *next;
    connection_t *c;
    char *envp[5];
    int i;

    for(node = connection_tree->head; node; node = next) {
        next = node->next;
        c = node->data;
        c->outgoing = NULL;
        terminate_connection(c, false);
    }

    for(list_node_t *node = outgoing_list->head; node; node = node->next) {
        outgoing_t *outgoing = node->data;

        if(outgoing->event)
            event_del(outgoing->event);
    }

    list_delete_list(outgoing_list);

    if(myself && myself->connection) {
        subnet_update(myself, NULL, false);
        terminate_connection(myself->connection, false);
        free_connection(myself->connection);
    }

    for(i = 0; i < listen_sockets; i++) {
        close(listen_socket[i].tcp);
        close(listen_socket[i].udp);
    }

    xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
    xasprintf(&envp[1], "DEVICE=%s", device ? : "");
    xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
    xasprintf(&envp[3], "NAME=%s", myself->name);
    envp[4] = NULL;

    exit_requests();
    exit_edges();
    exit_subnets();
    exit_nodes();
    exit_connections();
    exit_events();

    execute_script("tinc-down", envp);

    if(myport) free(myport);

    for(i = 0; i < 4; i++)
        free(envp[i]);

    close_device();

    return;
}