]> git.meshlink.io Git - meshlink/commitdiff
Implemented meshlink_blacklist feature
authorSaverio Proto <zioproto@gmail.com>
Tue, 20 May 2014 21:15:45 +0000 (23:15 +0200)
committerSaverio Proto <zioproto@gmail.com>
Fri, 23 May 2014 08:59:30 +0000 (10:59 +0200)
using the meshlink_blacklist function the application is able to blacklist a node

data from with node will be discarded. No more data will be sent to this node.

the blacklisting is persistent in the host configuration file

src/meshlink.c
src/net.c
src/net_packet.c
src/net_socket.c
src/node.h

index bfadf61b320596304e925ee4e41a7c2d8319332e..816f77abe630540d7f3f2724be887d505c0cd4e0 100644 (file)
@@ -1248,6 +1248,15 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) {
 }
 
 void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) {
+    node_t *n;
+    n = (node_t*)node;
+    n->status.blacklisted=true;
+       fprintf(stderr, "Blacklisted %s.\n",node->name);
+
+       //Make blacklisting persistent in the config file
+       append_config_file(mesh, n->name, "blacklisted", "yes");
+    return;
+
 }
 
 static void __attribute__((constructor)) meshlink_init(void) {
index 866bacb10c7eb46d5cdaaf93086f8d72ad1129d0..deac6eee42a612a57ef3e621a0eb657f0b924913 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -178,6 +178,8 @@ static void periodic_handler(event_loop_t *loop, void *data) {
                                }
 
                                if(!found) {
+                                       //TODO: if the node is blacklisted the connection will not happen, but
+                                       //the user will read this debug message "Autoconnecting to %s" that is misleading
                                        logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name);
                                        outgoing_t *outgoing = xzalloc(sizeof *outgoing);
                                        outgoing->name = xstrdup(n->name);
index f3809e87f191e0866ec93e6d2b2afb177c9ee0a1..8367a9c5157d78c978d65ce9e1267daa1e6fc862 100644 (file)
@@ -276,10 +276,14 @@ static void receive_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *pac
        logger(DEBUG_TRAFFIC, LOG_DEBUG, "Received packet of %d bytes from %s (%s)",
                           packet->len, n->name, n->hostname);
 
+    if (n->status.blacklisted) {
+        logger(DEBUG_PROTOCOL, LOG_WARNING, "Dropping packet from blacklisted node %s", n->name);
+    } else {
        n->in_packets++;
        n->in_bytes += packet->len;
 
        route(mesh, n, packet);
+    }
 }
 
 static bool try_mac(meshlink_handle_t *mesh, node_t *n, const vpn_packet_t *inpkt) {
@@ -654,6 +658,10 @@ void handle_incoming_vpn_data(event_loop_t *loop, void *data, int flags) {
                        return;
        }
 
+    if (n->status.blacklisted) {
+                       logger(DEBUG_PROTOCOL, LOG_WARNING, "Dropping packet from blacklisted node %s", n->name);
+            return;
+    }
        n->sock = ls - mesh->listen_socket;
 
        receive_udppacket(mesh, n, &pkt);
index 3cbc5dd634fa2d60d302daab5a0959b9c16d9b17..2ddf837b0a357589df87b280ccb9c512dfa6880b 100644 (file)
@@ -503,6 +503,7 @@ static struct addrinfo *get_known_addresses(node_t *n) {
 }
 
 void setup_outgoing_connection(meshlink_handle_t *mesh, outgoing_t *outgoing) {
+       bool blacklisted = false;
        timeout_del(&mesh->loop, &outgoing->ev);
 
        node_t *n = lookup_node(mesh, outgoing->name);
@@ -518,6 +519,9 @@ void setup_outgoing_connection(meshlink_handle_t *mesh, outgoing_t *outgoing) {
        read_host_config(mesh, outgoing->config_tree, outgoing->name);
        outgoing->cfg = lookup_config(outgoing->config_tree, "Address");
 
+       get_config_bool(lookup_config(outgoing->config_tree, "blacklisted"), &blacklisted);
+       if (blacklisted) return;
+
        if(!outgoing->cfg) {
                if(n)
                        outgoing->aip = outgoing->ai = get_known_addresses(n);
index 3a779af97055b163917a0c2aacc2860db8c80c68..f393089527c310303fb491ea463141ad499790ef 100644 (file)
@@ -33,8 +33,9 @@ typedef struct node_status_t {
        unsigned int indirect:1;                /* 1 if this node is not directly reachable by us */
        unsigned int unused_sptps:1;            /* 1 if this node supports SPTPS */
        unsigned int udp_confirmed:1;           /* 1 if the address is one that we received UDP traffic on */
-       unsigned int broadcast:1;               /* 1 if the next UDP packet should be broadcast to the local network */
-       unsigned int unused:23;
+       unsigned int broadcast:1;               /* 1 if the next UDP packet should be broadcast to the local network */
+       unsigned int blacklisted:1;             /* 1 if the node is blacklist so we never want to speak with him anymore*/
+       unsigned int unused:22;
 } node_status_t;
 
 typedef struct node_t {