From: Guus Sliepen Date: Sat, 19 Jun 2021 21:31:16 +0000 (+0200) Subject: Remove MTU and traffic statistics. X-Git-Url: http://git.meshlink.io/?p=meshlink-tiny;a=commitdiff_plain;h=1e3d251b5c65e49a1d4ed89d4154a1837ddd4f08 Remove MTU and traffic statistics. --- diff --git a/src/devtools.c b/src/devtools.c index 2c135ea..1b08d42 100644 --- a/src/devtools.c +++ b/src/devtools.c @@ -53,48 +53,6 @@ void (*devtool_keyrotate_probe)(int stage) = keyrotate_nop_probe; void (*devtool_set_inviter_commits_first)(bool inviter_commited_first) = inviter_commits_first_nop_probe; void (*devtool_sptps_renewal_probe)(meshlink_node_t *node) = sptps_renewal_nop_probe; -void devtool_get_node_status(meshlink_handle_t *mesh, meshlink_node_t *node, devtool_node_status_t *status) { - if(!mesh || !node || !status) { - meshlink_errno = MESHLINK_EINVAL; - return; - } - - node_t *internal = (node_t *)node; - - if(pthread_mutex_lock(&mesh->mutex) != 0) { - abort(); - } - - memcpy(&status->status, &internal->status, sizeof status->status); - status->mtu = internal->mtu; - status->minmtu = internal->minmtu; - status->maxmtu = internal->maxmtu; - status->mtuprobes = internal->mtuprobes; - status->in_packets = internal->in_packets; - status->in_bytes = internal->in_bytes; - status->out_packets = internal->out_packets; - status->out_bytes = internal->out_bytes; - - // Derive UDP connection status - if(internal == mesh->self) { - status->udp_status = DEVTOOL_UDP_WORKING; - } else if(!internal->status.reachable) { - status->udp_status = DEVTOOL_UDP_IMPOSSIBLE; - } else if(!internal->status.validkey) { - status->udp_status = DEVTOOL_UDP_UNKNOWN; - } else if(internal->status.udp_confirmed) { - status->udp_status = DEVTOOL_UDP_WORKING; - } else if(internal->mtuprobes > 30) { - status->udp_status = DEVTOOL_UDP_FAILED; - } else if(internal->mtuprobes > 0) { - status->udp_status = DEVTOOL_UDP_TRYING; - } else { - status->udp_status = DEVTOOL_UDP_UNKNOWN; - } - - pthread_mutex_unlock(&mesh->mutex); -} - meshlink_handle_t *devtool_open_in_netns(const char *confbase, const char *name, const char *appname, dev_class_t devclass, int netns) { meshlink_open_params_t *params = meshlink_open_params_init(confbase, name, appname, devclass); params->netns = dup(netns); diff --git a/src/devtools.h b/src/devtools.h index 16b8959..32b58ff 100644 --- a/src/devtools.h +++ b/src/devtools.h @@ -26,42 +26,6 @@ * Applications should not depend on any of these functions for their normal operation. */ -/// The status of a node. -typedef struct devtool_node_status devtool_node_status_t; - -/// The status of a node. -struct devtool_node_status { - uint32_t status; - uint16_t mtu; - uint16_t minmtu; - uint16_t maxmtu; - int mtuprobes; - enum { - DEVTOOL_UDP_FAILED = -2, /// UDP tried but failed - DEVTOOL_UDP_IMPOSSIBLE = -1, /// UDP not possible (node unreachable) - DEVTOOL_UDP_UNKNOWN = 0, /// UDP status not known (never tried to communicate with the node) - DEVTOOL_UDP_TRYING, /// UDP detection in progress - DEVTOOL_UDP_WORKING, /// UDP communication established - } udp_status; - uint64_t in_packets; - uint64_t in_bytes; - uint64_t out_packets; - uint64_t out_bytes; -}; - -/// Get the status of a node. -/** This function returns a struct containing extra information about a node. - * The information is a snapshot taken at call time. - * - * @param mesh A handle which represents an instance of MeshLink. - * @param node A pointer to a meshlink_node_t. - * @param status A pointer to a devtools_node_status_t variable that has - * to be provided by the caller. - * The contents of this variable will be changed to reflect - * the current status of the node. - */ -void devtool_get_node_status(meshlink_handle_t *mesh, meshlink_node_t *node, devtool_node_status_t *status); - /// Open a MeshLink instance in a given network namespace. /** This function opens MeshLink in the given network namespace. * diff --git a/src/meshlink-tiny++.h b/src/meshlink-tiny++.h index b789395..238931e 100644 --- a/src/meshlink-tiny++.h +++ b/src/meshlink-tiny++.h @@ -56,14 +56,6 @@ typedef void (*connection_try_cb_t)(mesh *mesh, node *node); */ typedef void (*node_status_cb_t)(mesh *mesh, node *node, bool reachable); -/// A callback reporting node path MTU changes. -/** @param mesh A handle which represents an instance of MeshLink. - * @param node A pointer to a meshlink_node_t describing the node whose status changed. - * This pointer is valid until meshlink_close() is called. - * @param pmtu The current path MTU to the node, or 0 if UDP communication is not (yet) possible. - */ -typedef void (*node_pmtu_cb_t)(mesh *mesh, node *node, uint16_t pmtu); - /// A callback reporting duplicate node detection. /** @param mesh A handle which represents an instance of MeshLink. * @param node A pointer to a meshlink_node_t describing the node which is duplicate. @@ -243,13 +235,6 @@ public: (void)reachable; } - /// This functions is called whenever another node's path MTU changes. - virtual void node_pmtu(node *peer, uint16_t pmtu) { - /* do nothing */ - (void)peer; - (void)pmtu; - } - /// This functions is called whenever a duplicate node is detected. virtual void node_duplicate(node *peer) { /* do nothing */ @@ -365,7 +350,6 @@ public: bool start() { meshlink_set_receive_cb(handle, &receive_trampoline); meshlink_set_node_status_cb(handle, &node_status_trampoline); - meshlink_set_node_pmtu_cb(handle, &node_pmtu_trampoline); meshlink_set_node_duplicate_cb(handle, &node_duplicate_trampoline); meshlink_set_log_cb(handle, MESHLINK_DEBUG, &log_trampoline); meshlink_set_error_cb(handle, &error_trampoline); @@ -976,15 +960,6 @@ private: that->node_status(static_cast(peer), reachable); } - static void node_pmtu_trampoline(meshlink_handle_t *handle, meshlink_node_t *peer, uint16_t pmtu) { - if(!(handle->priv)) { - return; - } - - meshlink::mesh *that = static_cast(handle->priv); - that->node_pmtu(static_cast(peer), pmtu); - } - static void node_duplicate_trampoline(meshlink_handle_t *handle, meshlink_node_t *peer) { if(!(handle->priv)) { return; diff --git a/src/meshlink-tiny.h b/src/meshlink-tiny.h index a0ca5fe..10fec47 100644 --- a/src/meshlink-tiny.h +++ b/src/meshlink-tiny.h @@ -448,28 +448,6 @@ typedef void (*meshlink_node_status_cb_t)(struct meshlink_handle *mesh, struct m */ void meshlink_set_node_status_cb(struct meshlink_handle *mesh, meshlink_node_status_cb_t cb); -/// A callback reporting node path MTU changes. -/** @param mesh A handle which represents an instance of MeshLink. - * @param node A pointer to a struct meshlink_node describing the node whose status changed. - * This pointer is valid until meshlink_close() is called. - * @param pmtu The current path MTU to the node, or 0 if UDP communication is not (yet) possible. - */ -typedef void (*meshlink_node_pmtu_cb_t)(struct meshlink_handle *mesh, struct meshlink_node *node, uint16_t pmtu); - -/// Set the node extended status callback. -/** This functions sets the callback that is called whenever certain connectivity parameters for a node change. - * The callback is run in MeshLink's own thread. - * It is therefore important that the callback uses apprioriate methods (queues, pipes, locking, etc.) - * to hand the data over to the application's thread. - * The callback should also not block itself and return as quickly as possible. - * - * \memberof meshlink_handle - * @param mesh A handle which represents an instance of MeshLink. - * @param cb A pointer to the function which will be called when another node's extended status changes. - * If a NULL pointer is given, the callback will be disabled. - */ -void meshlink_set_node_pmtu_cb(struct meshlink_handle *mesh, meshlink_node_pmtu_cb_t cb); - /// A callback reporting duplicate node detection. /** @param mesh A handle which represents an instance of MeshLink. * @param node A pointer to a struct meshlink_node describing the node which is duplicate. @@ -572,7 +550,6 @@ void meshlink_set_error_cb(struct meshlink_handle *mesh, meshlink_error_cb_t cb) * the packet is sent as one unit and is received as one unit, * and that there is no guarantee that the packet will arrive at the destination. * Packets that are too big to be sent over the network as one unit might be dropped, and this function may return an error if this situation can be detected beforehand. - * The application should not send packets that are larger than the path MTU, which can be queried with meshlink_get_pmtu(). * The application should take care of getting an acknowledgement and retransmission if necessary. * * \memberof meshlink_node @@ -587,22 +564,6 @@ void meshlink_set_error_cb(struct meshlink_handle *mesh, meshlink_error_cb_t cb) */ bool meshlink_send(struct meshlink_handle *mesh, struct meshlink_node *destination, const void *data, size_t len) __attribute__((__warn_unused_result__)); -/// Query the maximum packet size that can be sent to a node. -/** This functions returns the maximum size of packets (path MTU) that can be sent to a specific node with meshlink_send(). - * The path MTU is a property of the path packets will take to the destination node over the Internet. - * It can be different for different destination nodes. - * and the path MTU can change at any point in time due to changes in the Internet. - * Therefore, although this should only occur rarely, it can still happen that packets that do not exceed this size get dropped. - * - * \memberof meshlink_node - * @param mesh A handle which represents an instance of MeshLink. - * @param destination A pointer to a struct meshlink_node describing the destination for the data. - * - * @return The recommended maximum size of packets that are to be sent to the destination node, 0 if the node is unreachable, - * or a negative value in case of an error. - */ -ssize_t meshlink_get_pmtu(struct meshlink_handle *mesh, struct meshlink_node *destination) __attribute__((__warn_unused_result__)); - /// Get a handle for our own node. /** This function returns a handle for the local node. * diff --git a/src/meshlink.c b/src/meshlink.c index 19d9fdc..89a146e 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1419,22 +1419,6 @@ void meshlink_set_node_status_cb(meshlink_handle_t *mesh, meshlink_node_status_c pthread_mutex_unlock(&mesh->mutex); } -void meshlink_set_node_pmtu_cb(meshlink_handle_t *mesh, meshlink_node_pmtu_cb_t cb) { - logger(mesh, MESHLINK_DEBUG, "meshlink_set_node_pmtu_cb(%p)", (void *)(intptr_t)cb); - - if(!mesh) { - meshlink_errno = MESHLINK_EINVAL; - return; - } - - if(pthread_mutex_lock(&mesh->mutex) != 0) { - abort(); - } - - mesh->node_pmtu_cb = cb; - pthread_mutex_unlock(&mesh->mutex); -} - void meshlink_set_node_duplicate_cb(meshlink_handle_t *mesh, meshlink_node_duplicate_cb_t cb) { logger(mesh, MESHLINK_DEBUG, "meshlink_set_node_duplicate_cb(%p)", (void *)(intptr_t)cb); @@ -1588,38 +1572,11 @@ void meshlink_send_from_queue(event_loop_t *loop, void *data) { for(vpn_packet_t *packet; (packet = meshlink_queue_pop(&mesh->outpacketqueue));) { logger(mesh, MESHLINK_DEBUG, "Removing packet of %d bytes from packet queue", packet->len); - mesh->self->in_packets++; - mesh->self->in_bytes += packet->len; route(mesh, mesh->self, packet); free(packet); } } -ssize_t meshlink_get_pmtu(meshlink_handle_t *mesh, meshlink_node_t *destination) { - if(!mesh || !destination) { - meshlink_errno = MESHLINK_EINVAL; - return -1; - } - - if(pthread_mutex_lock(&mesh->mutex) != 0) { - abort(); - } - - node_t *n = (node_t *)destination; - - if(!n->status.reachable) { - pthread_mutex_unlock(&mesh->mutex); - return 0; - - } else if(n->mtuprobes > 30 && n->minmtu) { - pthread_mutex_unlock(&mesh->mutex); - return n->minmtu; - } else { - pthread_mutex_unlock(&mesh->mutex); - return MTU; - } -} - char *meshlink_get_fingerprint(meshlink_handle_t *mesh, meshlink_node_t *node) { if(!mesh || !node) { meshlink_errno = MESHLINK_EINVAL; @@ -2447,17 +2404,6 @@ static void channel_accept(struct utcp_connection *utcp_connection, uint16_t por } } -static void channel_retransmit(struct utcp_connection *utcp_connection) { - node_t *n = utcp_connection->utcp->priv; - meshlink_handle_t *mesh = n->mesh; - - if(n->mtuprobes == 31 && n->mtutimeout.cb) { - timeout_set(&mesh->loop, &n->mtutimeout, &(struct timespec) { - 0, 0 - }); - } -} - static ssize_t channel_send(struct utcp *utcp, const void *data, size_t len) { node_t *n = utcp->priv; @@ -2638,8 +2584,6 @@ void meshlink_set_channel_accept_cb(meshlink_handle_t *mesh, meshlink_channel_ac if(mesh->peer) { mesh->peer->utcp = utcp_init(channel_accept, channel_pre_accept, channel_send, mesh->peer); - utcp_set_mtu(mesh->peer->utcp, mesh->peer->mtu - sizeof(meshlink_packethdr_t)); - utcp_set_retransmit_cb(mesh->peer->utcp, channel_retransmit); } pthread_mutex_unlock(&mesh->mutex); @@ -2725,8 +2669,6 @@ meshlink_channel_t *meshlink_channel_open_ex(meshlink_handle_t *mesh, meshlink_n if(!n->utcp) { n->utcp = utcp_init(channel_accept, channel_pre_accept, channel_send, n); - utcp_set_mtu(n->utcp, n->mtu - sizeof(meshlink_packethdr_t)); - utcp_set_retransmit_cb(n->utcp, channel_retransmit); mesh->receive_cb = channel_receive; if(!n->utcp) { @@ -3102,8 +3044,6 @@ void meshlink_set_node_channel_timeout(meshlink_handle_t *mesh, meshlink_node_t if(!n->utcp) { n->utcp = utcp_init(channel_accept, channel_pre_accept, channel_send, n); - utcp_set_mtu(n->utcp, n->mtu - sizeof(meshlink_packethdr_t)); - utcp_set_retransmit_cb(n->utcp, channel_retransmit); } utcp_set_user_timeout(n->utcp, timeout); @@ -3114,25 +3054,11 @@ void meshlink_set_node_channel_timeout(meshlink_handle_t *mesh, meshlink_node_t void update_node_status(meshlink_handle_t *mesh, node_t *n) { if(n->status.reachable && mesh->channel_accept_cb && !n->utcp) { n->utcp = utcp_init(channel_accept, channel_pre_accept, channel_send, n); - utcp_set_mtu(n->utcp, n->mtu - sizeof(meshlink_packethdr_t)); - utcp_set_retransmit_cb(n->utcp, channel_retransmit); } if(mesh->node_status_cb) { mesh->node_status_cb(mesh, (meshlink_node_t *)n, n->status.reachable && !n->status.blacklisted); } - - if(mesh->node_pmtu_cb) { - mesh->node_pmtu_cb(mesh, (meshlink_node_t *)n, n->minmtu); - } -} - -void update_node_pmtu(meshlink_handle_t *mesh, node_t *n) { - utcp_set_mtu(n->utcp, (n->minmtu > MINMTU ? n->minmtu : MINMTU) - sizeof(meshlink_packethdr_t)); - - if(mesh->node_pmtu_cb && !n->status.blacklisted) { - mesh->node_pmtu_cb(mesh, (meshlink_node_t *)n, n->minmtu); - } } void handle_duplicate_node(meshlink_handle_t *mesh, node_t *n) { diff --git a/src/meshlink.sym b/src/meshlink.sym index 3df9d7b..1389360 100644 --- a/src/meshlink.sym +++ b/src/meshlink.sym @@ -34,7 +34,6 @@ meshlink_get_fingerprint meshlink_get_node meshlink_get_node_dev_class meshlink_get_node_reachability -meshlink_get_pmtu meshlink_get_self meshlink_hint_address meshlink_hint_network_change @@ -72,7 +71,6 @@ meshlink_set_inviter_commits_first meshlink_set_log_cb meshlink_set_node_channel_timeout meshlink_set_node_duplicate_cb -meshlink_set_node_pmtu_cb meshlink_set_node_status_cb meshlink_set_receive_cb meshlink_set_scheduling_granularity diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index 3074863..c92af1b 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -111,7 +111,6 @@ struct meshlink_handle { // Infrequently used callbacks meshlink_node_status_cb_t node_status_cb; meshlink_node_status_cb_t meta_status_cb; - meshlink_node_pmtu_cb_t node_pmtu_cb; meshlink_channel_listen_cb_t channel_listen_cb; meshlink_channel_accept_cb_t channel_accept_cb; meshlink_node_duplicate_cb_t node_duplicate_cb; @@ -186,7 +185,6 @@ typedef struct meshlink_packethdr { void meshlink_send_from_queue(event_loop_t *loop, void *mesh); void update_node_status(meshlink_handle_t *mesh, struct node_t *n); -void update_node_pmtu(meshlink_handle_t *mesh, struct node_t *n); extern meshlink_log_level_t global_log_level; extern meshlink_log_cb_t global_log_cb; void handle_duplicate_node(meshlink_handle_t *mesh, struct node_t *n); diff --git a/src/net.h b/src/net.h index 023591b..91b9ad2 100644 --- a/src/net.h +++ b/src/net.h @@ -105,7 +105,6 @@ bool node_read_from_config(struct meshlink_handle *mesh, struct node_t *, const bool read_ecdsa_public_key(struct meshlink_handle *mesh, struct connection_t *) __attribute__((__warn_unused_result__)); bool read_ecdsa_private_key(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); bool node_write_config(struct meshlink_handle *mesh, struct node_t *, bool new_key) __attribute__((__warn_unused_result__)); -void send_mtu_probe(struct meshlink_handle *mesh, struct node_t *); void handle_meta_connection_data(struct meshlink_handle *mesh, struct connection_t *); void retry(struct meshlink_handle *mesh); void flush_meta(struct meshlink_handle *mesh, struct connection_t *); diff --git a/src/net_packet.c b/src/net_packet.c index d4eb0c4..21e164a 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -41,9 +41,6 @@ static void receive_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *pac if(n->status.blacklisted) { logger(mesh, MESHLINK_WARNING, "Dropping packet from blacklisted node %s", n->name); } else { - n->in_packets++; - n->in_bytes += packet->len; - route(mesh, n, packet); } } @@ -176,8 +173,6 @@ bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t */ void send_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *packet) { if(n == mesh->self) { - n->out_packets++; - n->out_bytes += packet->len; // TODO: send to application return; } @@ -189,10 +184,6 @@ void send_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *packet) { return; } - n->out_packets++; - n->out_bytes += packet->len; - n->status.want_udp = true; - send_sptps_packet(mesh, n, packet); return; } diff --git a/src/node.c b/src/node.c index ce5a5a2..01173f8 100644 --- a/src/node.c +++ b/src/node.c @@ -43,8 +43,6 @@ void exit_nodes(meshlink_handle_t *mesh) { node_t *new_node(void) { node_t *n = xzalloc(sizeof(*n)); - n->mtu = MTU; - n->maxmtu = MTU; n->devclass = DEV_CLASS_UNKNOWN; return n; @@ -58,10 +56,6 @@ void free_node(node_t *n) { ecdsa_free(n->ecdsa); sptps_stop(&n->sptps); - if(n->mtutimeout.cb) { - abort(); - } - free(n->name); free(n->canonical_address); @@ -84,7 +78,6 @@ void node_del(meshlink_handle_t *mesh, node_t *n) { } assert(mesh->peer && mesh->peer == n); - timeout_del(&mesh->loop, &n->mtutimeout); free_node(n); mesh->peer = NULL; } diff --git a/src/node.h b/src/node.h index 29d3725..7384f17 100644 --- a/src/node.h +++ b/src/node.h @@ -49,7 +49,6 @@ typedef struct node_t { // Private member variables node_status_t status; - uint16_t minmtu; /* Probed minimum MTU */ dev_class_t devclass; // Used for packet I/O @@ -58,18 +57,6 @@ typedef struct node_t { struct utcp *utcp; - // Traffic counters - uint64_t in_packets; - uint64_t in_bytes; - uint64_t out_packets; - uint64_t out_bytes; - - // MTU probes - timeout_t mtutimeout; /* Probe event */ - int mtuprobes; /* Number of probes */ - uint16_t mtu; /* Maximum size of packets to send to this node */ - uint16_t maxmtu; /* Probed maximum MTU */ - // Used for meta-connection I/O, timeouts struct meshlink_handle *mesh; /* The mesh this node belongs to */