]> git.meshlink.io Git - meshlink/commitdiff
Add channel disconnection fix when node blacklisted
authorSS Roop <sairoop@elear.solutions>
Tue, 12 Feb 2019 17:32:59 +0000 (23:02 +0530)
committerGuus Sliepen <guus@meshlink.io>
Mon, 25 Feb 2019 10:25:13 +0000 (11:25 +0100)
src/graph.c
src/meshlink.c
src/net_setup.c
src/utcp

index 9b0184b091a0cdf15602871afcb7f5e277614720..19a33e2e9de1485cd1d7a462168ff288bbf2e49b 100644 (file)
@@ -229,7 +229,9 @@ static void check_reachability(meshlink_handle_t *mesh) {
 
                        timeout_del(&mesh->loop, &n->mtutimeout);
 
-                       update_node_status(mesh, n);
+                       if(!n->status.blacklisted) {
+                               update_node_status(mesh, n);
+                       }
 
                        if(!n->status.reachable) {
                                update_node_udp(mesh, n, NULL);
index d094452733712c2e1b02b3bbfaa09efce7e96cca..8f0f82d1a8ae1c3afe5f94f0db22c134c2783ecd 100644 (file)
@@ -1732,6 +1732,13 @@ bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const
                return false;
        }
 
+       node_t *n = (node_t *)destination;
+
+       if(n->status.blacklisted) {
+               logger(mesh, MESHLINK_ERROR, "Node %s blacklisted, dropping packet\n", n->name);
+               return false;
+       }
+
        // Prepare the packet
        vpn_packet_t *packet = malloc(sizeof(*packet));
 
@@ -2773,6 +2780,20 @@ void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) {
 
        node_t *n;
        n = (node_t *)node;
+
+       if(n == mesh->self) {
+               logger(mesh, MESHLINK_ERROR, "%s blacklisting itself?\n", node->name);
+               meshlink_errno = MESHLINK_EINVAL;
+               pthread_mutex_unlock(&(mesh->mesh_mutex));
+               return;
+       }
+
+       if(n->status.blacklisted) {
+               logger(mesh, MESHLINK_DEBUG, "Node %s already blacklisted\n", node->name);
+               pthread_mutex_unlock(&(mesh->mesh_mutex));
+               return;
+       }
+
        n->status.blacklisted = true;
        logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", node->name);
 
@@ -2786,6 +2807,18 @@ void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) {
                }
        }
 
+       utcp_abort_all_connections(n->utcp);
+
+       n->mtu = 0;
+       n->minmtu = 0;
+       n->maxmtu = MTU;
+       n->mtuprobes = 0;
+       n->status.udp_confirmed = false;
+
+       if(n->status.reachable) {
+               update_node_status(mesh, n);
+       }
+
        pthread_mutex_unlock(&(mesh->mesh_mutex));
 }
 
@@ -2798,9 +2831,22 @@ void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) {
        pthread_mutex_lock(&(mesh->mesh_mutex));
 
        node_t *n = (node_t *)node;
+
+       if(!n->status.blacklisted) {
+               logger(mesh, MESHLINK_DEBUG, "Node %s was already whitelisted\n", node->name);
+               meshlink_errno = MESHLINK_EINVAL;
+               pthread_mutex_unlock(&(mesh->mesh_mutex));
+               return;
+       }
+
        n->status.blacklisted = false;
 
-       //TODO: remove blacklisted = yes from the config file
+       if(n->status.reachable) {
+               update_node_status(mesh, n);
+       }
+
+       //Remove blacklisting from the config file
+       append_config_file(mesh, n->name, "blacklisted", NULL);
 
        pthread_mutex_unlock(&(mesh->mesh_mutex));
        return;
@@ -2989,6 +3035,11 @@ meshlink_channel_t *meshlink_channel_open_ex(meshlink_handle_t *mesh, meshlink_n
                }
        }
 
+       if(n->status.blacklisted) {
+               logger(mesh, MESHLINK_ERROR, "Cannot open a channel with blacklisted node\n");
+               return NULL;
+       }
+
        meshlink_channel_t *channel = xzalloc(sizeof(*channel));
        channel->node = n;
        channel->receive_cb = cb;
@@ -3072,7 +3123,7 @@ void update_node_status(meshlink_handle_t *mesh, node_t *n) {
        }
 
        if(mesh->node_status_cb) {
-               mesh->node_status_cb(mesh, (meshlink_node_t *)n, n->status.reachable);
+               mesh->node_status_cb(mesh, (meshlink_node_t *)n, n->status.reachable && !n->status.blacklisted);
        }
 }
 
index 47ed32e0ec9e202b22cb1bf1e73433587b5f5eaf..70ed294e2862cc23bc8bdfa3184319a3f8cb303d 100644 (file)
@@ -190,6 +190,26 @@ exit:
        return n->submesh != NULL;
 }
 
+bool node_read_blacklist_status(meshlink_handle_t *mesh, node_t *n) {
+
+       splay_tree_t *config_tree;
+       bool blacklist_status;
+
+       init_configuration(&config_tree);
+
+       if(!read_host_config(mesh, config_tree, n->name)) {
+               goto exit;
+       }
+
+       if(get_config_bool(lookup_config(config_tree, "blacklisted"), &blacklist_status)) {
+               n->status.blacklisted = blacklist_status;
+       }
+
+exit:
+       exit_configuration(&config_tree);
+       return n->status.blacklisted;
+}
+
 bool node_write_devclass(meshlink_handle_t *mesh, node_t *n) {
 
        if((int)n->devclass < 0 || n->devclass > _DEV_CLASS_MAX) {
@@ -292,6 +312,7 @@ void load_all_nodes(meshlink_handle_t *mesh) {
                n->name = xstrdup(ent->d_name);
                node_read_devclass(mesh, n);
                node_read_submesh(mesh, n);
+               node_read_blacklist_status(mesh, n);
                node_add(mesh, n);
        }
 
index fad2787f2394bad3cf105ca5b4cf411db6d34aa6..f1035e971bb894203bdfba6cafbaf0bb30f197eb 160000 (submodule)
--- a/src/utcp
+++ b/src/utcp
@@ -1 +1 @@
-Subproject commit fad2787f2394bad3cf105ca5b4cf411db6d34aa6
+Subproject commit f1035e971bb894203bdfba6cafbaf0bb30f197eb