]> git.meshlink.io Git - meshlink/blobdiff - src/devtools.c
Modify meshlink configuration base file structre
[meshlink] / src / devtools.c
index a1921d8b234ed04901349aa81a536e864a50db32..5991d70cbbe5a1fb7af0c0998b17e18a2ab82bc1 100644 (file)
 #include "logger.h"
 #include "meshlink_internal.h"
 #include "node.h"
+#include "submesh.h"
 #include "splay_tree.h"
 #include "netutl.h"
 #include "xalloc.h"
 
 #include "devtools.h"
 
+static void trybind_nop_probe(void) {
+       return;
+}
+
+static void keyrotate_nop_probe(int stage) {
+       (void)stage;
+       return;
+}
+
+void (*devtool_trybind_probe)(void) = trybind_nop_probe;
+void (*devtool_keyrotate_probe)(int stage) = keyrotate_nop_probe;
+
 /* Return an array of edges in the current network graph.
  * Data captures the current state and will not be updated.
  * Caller must deallocate data when done.
@@ -185,7 +198,7 @@ bool devtool_export_json_all_edges_state(meshlink_handle_t *mesh, FILE *stream)
                }
 
                char *host = NULL, *port = NULL, *address = NULL;
-               sockaddr2str((const sockaddr_t *) & (edges[i].address), &host, &port);
+               sockaddr2str((const sockaddr_t *)&edges[i].address, &host, &port);
 
                if(host && port) {
                        xasprintf(&address, "{ \"host\": \"%s\", \"port\": %s }", host, port);
@@ -250,7 +263,7 @@ void devtool_get_node_status(meshlink_handle_t *mesh, meshlink_node_t *node, dev
 
        status->options = internal->options;
        memcpy(&status->status, &internal->status, sizeof status->status);
-       status->address = internal->address;
+       memcpy(&status->address, &internal->address, sizeof status->address);
        status->mtu = internal->mtu;
        status->minmtu = internal->minmtu;
        status->maxmtu = internal->maxmtu;
@@ -279,3 +292,50 @@ void devtool_get_node_status(meshlink_handle_t *mesh, meshlink_node_t *node, dev
 
        pthread_mutex_unlock(&mesh->mesh_mutex);
 }
+
+meshlink_submesh_t **devtool_get_all_submeshes(meshlink_handle_t *mesh, meshlink_submesh_t **submeshes, size_t *nmemb) {
+       if(!mesh || !nmemb || (*nmemb && !submeshes)) {
+               meshlink_errno = MESHLINK_EINVAL;
+               return NULL;
+       }
+
+       meshlink_submesh_t **result;
+
+       //lock mesh->nodes
+       pthread_mutex_lock(&(mesh->mesh_mutex));
+
+       *nmemb = mesh->submeshes->count;
+       result = realloc(submeshes, *nmemb * sizeof(*submeshes));
+
+       if(result) {
+               meshlink_submesh_t **p = result;
+
+               for list_each(submesh_t, s, mesh->submeshes) {
+                       *p++ = (meshlink_submesh_t *)s;
+               }
+       } else {
+               *nmemb = 0;
+               free(submeshes);
+               meshlink_errno = MESHLINK_ENOMEM;
+       }
+
+       pthread_mutex_unlock(&(mesh->mesh_mutex));
+
+       return result;
+}
+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);
+       meshlink_handle_t *handle;
+
+       if(params->netns == -1) {
+               handle = NULL;
+               meshlink_errno = MESHLINK_EINVAL;
+       } else {
+               handle = meshlink_open_ex(params);
+       }
+
+       meshlink_open_params_free(params);
+
+       return handle;
+}