]> git.meshlink.io Git - meshlink/commitdiff
Set meshlink_errno when trying to create a channel to a blacklisted node.
authorGuus Sliepen <guus@meshlink.io>
Mon, 28 Oct 2019 20:12:14 +0000 (21:12 +0100)
committerGuus Sliepen <guus@meshlink.io>
Mon, 28 Oct 2019 20:12:14 +0000 (21:12 +0100)
Create a new errno value MESHLINK_EBLACKLISTED, which is used when trying
to send something or create a channel to a blacklisted node. Also improve
some log messages.

src/meshlink.c
src/meshlink.h

index 0318a497ba98bc4a30549898c72ccbd19b12ef81..98e02f7db623d8c8b4e837eb96e77f23580fddd8 100644 (file)
@@ -796,6 +796,7 @@ static const char *errstr[] = {
        [MESHLINK_EPEER] = "Error communicating with peer",
        [MESHLINK_ENOTSUP] = "Operation not supported",
        [MESHLINK_EBUSY] = "MeshLink instance already in use",
        [MESHLINK_EPEER] = "Error communicating with peer",
        [MESHLINK_ENOTSUP] = "Operation not supported",
        [MESHLINK_EBUSY] = "MeshLink instance already in use",
+       [MESHLINK_EBLACKLISTED] = "Node is blacklisted",
 };
 
 const char *meshlink_strerror(meshlink_errno_t err) {
 };
 
 const char *meshlink_strerror(meshlink_errno_t err) {
@@ -1757,6 +1758,7 @@ bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const
 
        if(n->status.blacklisted) {
                logger(mesh, MESHLINK_ERROR, "Node %s blacklisted, dropping packet\n", n->name);
 
        if(n->status.blacklisted) {
                logger(mesh, MESHLINK_ERROR, "Node %s blacklisted, dropping packet\n", n->name);
+               meshlink_errno = MESHLINK_EBLACKLISTED;
                return false;
        }
 
                return false;
        }
 
@@ -2861,9 +2863,15 @@ void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) {
 
        node_t *n = (node_t *)node;
 
 
        node_t *n = (node_t *)node;
 
+       if(n == mesh->self) {
+               logger(mesh, MESHLINK_ERROR, "%s whitelisting itself?\n", node->name);
+               meshlink_errno = MESHLINK_EINVAL;
+               pthread_mutex_unlock(&mesh->mutex);
+               return;
+       }
+
        if(!n->status.blacklisted) {
                logger(mesh, MESHLINK_DEBUG, "Node %s was already whitelisted\n", node->name);
        if(!n->status.blacklisted) {
                logger(mesh, MESHLINK_DEBUG, "Node %s was already whitelisted\n", node->name);
-               meshlink_errno = MESHLINK_EINVAL;
                pthread_mutex_unlock(&mesh->mutex);
                return;
        }
                pthread_mutex_unlock(&mesh->mutex);
                return;
        }
@@ -2876,6 +2884,8 @@ void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) {
                update_node_status(mesh, n);
        }
 
                update_node_status(mesh, n);
        }
 
+       logger(mesh, MESHLINK_DEBUG, "Whitelisted %s.\n", node->name);
+
        pthread_mutex_unlock(&mesh->mutex);
        return;
 }
        pthread_mutex_unlock(&mesh->mutex);
        return;
 }
@@ -3183,6 +3193,7 @@ 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");
 
        if(n->status.blacklisted) {
                logger(mesh, MESHLINK_ERROR, "Cannot open a channel with blacklisted node\n");
+               meshlink_errno = MESHLINK_EBLACKLISTED;
                pthread_mutex_unlock(&mesh->mutex);
                return NULL;
        }
                pthread_mutex_unlock(&mesh->mutex);
                return NULL;
        }
index e043d8d28f3a402dc52e7ed4f9ffc554a8ee1c60..3d12af6b87b40e4679b426a2015ab1fc1567622f 100644 (file)
@@ -59,18 +59,19 @@ typedef struct meshlink_submesh meshlink_submesh_t;
 
 /// Code of most recent error encountered.
 typedef enum {
 
 /// Code of most recent error encountered.
 typedef enum {
-       MESHLINK_OK,        ///< Everything is fine
-       MESHLINK_EINVAL,    ///< Invalid parameter(s) to function call
-       MESHLINK_ENOMEM,    ///< Out of memory
-       MESHLINK_ENOENT,    ///< Node is not known
-       MESHLINK_EEXIST,    ///< Node already exists
-       MESHLINK_EINTERNAL, ///< MeshLink internal error
-       MESHLINK_ERESOLV,   ///< MeshLink could not resolve a hostname
-       MESHLINK_ESTORAGE,  ///< MeshLink could not load or write data from/to disk
-       MESHLINK_ENETWORK,  ///< MeshLink encountered a network error
-       MESHLINK_EPEER,     ///< A peer caused an error
-       MESHLINK_ENOTSUP,   ///< The operation is not supported in the current configuration of MeshLink
-       MESHLINK_EBUSY      ///< The MeshLink instance is already in use by another process
+       MESHLINK_OK,           ///< Everything is fine
+       MESHLINK_EINVAL,       ///< Invalid parameter(s) to function call
+       MESHLINK_ENOMEM,       ///< Out of memory
+       MESHLINK_ENOENT,       ///< Node is not known
+       MESHLINK_EEXIST,       ///< Node already exists
+       MESHLINK_EINTERNAL,    ///< MeshLink internal error
+       MESHLINK_ERESOLV,      ///< MeshLink could not resolve a hostname
+       MESHLINK_ESTORAGE,     ///< MeshLink could not load or write data from/to disk
+       MESHLINK_ENETWORK,     ///< MeshLink encountered a network error
+       MESHLINK_EPEER,        ///< A peer caused an error
+       MESHLINK_ENOTSUP,      ///< The operation is not supported in the current configuration of MeshLink
+       MESHLINK_EBUSY,        ///< The MeshLink instance is already in use by another process
+       MESHLINK_EBLACKLISTED, ///< The operation is not allowed because the node is blacklisted
 } meshlink_errno_t;
 
 /// Device class
 } meshlink_errno_t;
 
 /// Device class