PKG_CHECK_MODULES([LXC], [lxc >= 2.0.0], [lxc=true], [lxc=false])
AM_CONDITIONAL(BLACKBOX_TESTS, test "$cmocka" = true -a "$lxc" = true)
+
dnl Additional example code
PKG_CHECK_MODULES([NCURSES], [ncurses >= 5], [curses=true], [curses=false])
-AM_CONDITIONAL(CURSES, test "$curses" = true)
+AC_ARG_ENABLE([monitor_code],
+ [AS_HELP_STRING([--enable-monitor-code], [Add monitor example code to the build])],
+ [AS_IF([test "x$enable_monitor_code" = "xyes"], [monitor_code=true], [monitor_code=false])],
+ [monitor_code=false]
+)
+AM_CONDITIONAL(MONITOR, test "$monitor_code" = true)
dnl Install test binaries
AC_ARG_ENABLE([install_tests],
dnl Checks for header files.
dnl We do this in multiple stages, because unlike Linux all the other operating systems really suck and don't include their own dependencies.
-AC_CHECK_HEADERS([syslog.h sys/file.h sys/param.h sys/resource.h sys/socket.h sys/time.h sys/un.h sys/wait.h netdb.h arpa/inet.h dirent.h])
+AC_CHECK_HEADERS([syslog.h sys/file.h sys/param.h sys/resource.h sys/socket.h sys/time.h sys/un.h sys/wait.h netdb.h arpa/inet.h dirent.h curses.h])
dnl Checks for typedefs, structures, and compiler characteristics.
MeshLink_ATTRIBUTE(__malloc__)
dnl Checks for library functions.
AC_TYPE_SIGNAL
-AC_CHECK_FUNCS([asprintf fchmod fork gettimeofday random select strdup usleep],
+AC_CHECK_FUNCS([asprintf fchmod fork gettimeofday random select setns strdup usleep],
[], [], [#include "$srcdir/src/have.h"]
)
manynodes
meshlinkapp
monitor
+groupchat
-noinst_PROGRAMS = meshlinkapp chat chatpp manynodes channels monitor groupchat
+noinst_PROGRAMS = meshlinkapp chat manynodes channels groupchat
AM_CPPFLAGS = $(PTHREAD_CFLAGS) -I${top_srcdir}/src -iquote. -Wall
AM_LDFLAGS = $(PTHREAD_LIBS)
meshlinkapp_SOURCES = meshlinkapp.c
-meshlinkapp_LDADD = ${top_builddir}/src/libmeshlink.la
+meshlinkapp_LDADD = ${top_builddir}/src/libmeshlink.la ${top_builddir}/catta/src/libcatta.la
chat_SOURCES = chat.c
-chat_LDADD = ${top_builddir}/src/libmeshlink.la
+chat_LDADD = ${top_builddir}/src/libmeshlink.la ${top_builddir}/catta/src/libcatta.la
-chatpp_SOURCES = chatpp.cc
-chatpp_LDADD = ${top_builddir}/src/libmeshlink.la
+#noinst_PROGRAMS += chatpp
+#chatpp_SOURCES = chatpp.cc
+#chatpp_LDADD = ${top_builddir}/src/libmeshlink.la
manynodes_SOURCES = manynodes.c
-manynodes_LDADD = ${top_builddir}/src/libmeshlink.la
+manynodes_LDADD = ${top_builddir}/src/libmeshlink.la ${top_builddir}/catta/src/libcatta.la
channels_SOURCES = channels.c
-channels_LDADD = ${top_builddir}/src/libmeshlink.la
+channels_LDADD = ${top_builddir}/src/libmeshlink.la ${top_builddir}/catta/src/libcatta.la
-if CURSES
+if MONITOR
+noinst_PROGRAMS += monitor
monitor_SOURCES = monitor.c
monitor_LDADD = ${top_builddir}/src/libmeshlink.la $(NCURSES_LIBS) -lm
endif
groupchat_SOURCES = groupchat.c
-groupchat_LDADD = ${top_builddir}/src/libmeshlink.la
+groupchat_LDADD = ${top_builddir}/src/libmeshlink.la ${top_builddir}/catta/src/libcatta.la
if(!nodes) {
fprintf(stderr, "Could not get list of nodes: %s\n", meshlink::strerror());
} else {
- printf("%zu known nodes:", nnodes);
+ printf("%lu known nodes:", (unsigned long)nnodes);
for(size_t i = 0; i < nnodes; i++) {
printf(" %s", nodes[i]->name);
if(!nnodes) {
fprintf(stderr, "Could not get list of nodes: %s\n", meshlink_strerror(meshlink_errno));
} else {
- fprintf(stderr, "%zu known nodes:\n", nnodes);
+ fprintf(stderr, "%lu known nodes:\n", (unsigned long)nnodes);
for(size_t i = 0; i < nnodes; i++) {
- fprintf(stderr, " %lu. %s", i, nodes[i]->name);
+ fprintf(stderr, " %lu. %s", (unsigned long)i, nodes[i]->name);
if((node_group = meshlink_get_node_submesh(mesh, nodes[i]))) {
fprintf(stderr, "\t%s", node_group->name);
if(!node) {
fprintf(stderr, "Unknown node '%s'\n", arg);
} else {
- printf("Node %s found, pmtu %zd\n", arg, meshlink_get_pmtu(mesh[nodeindex], node));
+ printf("Node %s found, pmtu %ld\n", arg, (long int)meshlink_get_pmtu(mesh[nodeindex], node));
}
}
} else if(!strcasecmp(buf, "link")) {
devtool_get_node_status(mesh, nodes[i], &status);
char host[NI_MAXHOST] = "";
char serv[NI_MAXSERV] = "";
- getnameinfo(&status.address, sizeof status.address, host, sizeof host, serv, sizeof serv, NI_NUMERICHOST | NI_NUMERICSERV);
+ getnameinfo((struct sockaddr *)&status.address, sizeof status.address, host, sizeof host, serv, sizeof serv, NI_NUMERICHOST | NI_NUMERICSERV);
const char *desc;
switch(status.udp_status) {
int main(int argc, char *argv[]) {
const char *confbase = ".monitor";
const char *id = NULL;
- char buf[1024];
if(argc > 1) {
confbase = argv[1];
pkginclude_HEADERS = meshlink++.h meshlink.h
-libmeshlink_la_LDFLAGS = -export-symbols-regex '^(meshlink_|devtool_)'
+libmeshlink_la_LDFLAGS = -export-symbols $(srcdir)/meshlink.sym
libmeshlink_la_SOURCES = \
buffer.c buffer.h \
have.h \
list.c list.h \
logger.c logger.h \
- meshlink.c meshlink.h \
+ meshlink.c meshlink.h meshlink.sym \
meshlink_internal.h \
meshlink_queue.h \
meta.c meta.h \
{ -20430234, 14955537, -24126347, 8124619, -5369288, -5990470, 30468147, -13900640, 18423289, 4177476 },
},
},
-};
\ No newline at end of file
+};
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
-
__thread meshlink_errno_t meshlink_errno;
meshlink_log_cb_t global_log_cb;
meshlink_log_level_t global_log_level;
int fd;
};
+#ifdef HAVE_SETNS
static void *socket_in_netns_thread(void *arg) {
struct socket_in_netns_params *params = arg;
if(setns(params->netns, CLONE_NEWNET) == -1) {
meshlink_errno = MESHLINK_EINVAL;
- } else {
- params->fd = socket(params->domain, params->type, params->protocol);
+ return NULL;
}
+ params->fd = socket(params->domain, params->type, params->protocol);
+
return NULL;
}
+#endif // HAVE_SETNS
static int socket_in_netns(int domain, int type, int protocol, int netns) {
if(netns == -1) {
return socket(domain, type, protocol);
}
+#ifdef HAVE_SETNS
struct socket_in_netns_params params = {domain, type, protocol, netns, -1};
pthread_t thr;
}
return params.fd;
+#else
+ return -1;
+#endif // HAVE_SETNS
+
}
// Find out what local address a socket would use if we connect to the given address.
return true;
}
+#ifdef HAVE_SETNS
static void *setup_network_in_netns_thread(void *arg) {
meshlink_handle_t *mesh = arg;
add_local_addresses(mesh);
return success ? arg : NULL;
}
+#endif // HAVE_SETNS
meshlink_open_params_t *meshlink_open_params_init(const char *confbase, const char *name, const char *appname, dev_class_t devclass) {
if(!confbase || !*confbase) {
meshlink_handle_t *meshlink_open(const char *confbase, const char *name, const char *appname, dev_class_t devclass) {
/* Create a temporary struct on the stack, to avoid allocating and freeing one. */
- meshlink_open_params_t params = {NULL};
+ meshlink_open_params_t params;
+ memset(¶ms, 0, sizeof(params));
params.confbase = (char *)confbase;
params.name = (char *)name;
bool success = false;
if(mesh->netns != -1) {
+#ifdef HAVE_SETNS
pthread_t thr;
if(pthread_create(&thr, NULL, setup_network_in_netns_thread, mesh) == 0) {
void *retval = NULL;
success = pthread_join(thr, &retval) == 0 && retval;
}
+
+#else
+ meshlink_errno = MESHLINK_EINTERNAL;
+ return NULL;
+
+#endif // HAVE_SETNS
} else {
success = setup_network(mesh);
add_local_addresses(mesh);
meshlink_handle_t *mesh = arg;
if(mesh->netns != -1) {
+#ifdef HAVE_SETNS
+
if(setns(mesh->netns, CLONE_NEWNET) != 0) {
return NULL;
}
+
+#else
+ return NULL;
+#endif // HAVE_SETNS
}
pthread_mutex_lock(&(mesh->mesh_mutex));
}
if(!stat(invname, &st)) {
- if(mesh->invitation_key && deadline < st.st_mtime) {
+ if(mesh->invitation_key && deadline < (time_t)st.st_mtime) {
count++;
} else {
unlink(invname);
--- /dev/null
+__emutls_v.meshlink_errno
+devtool_export_json_all_edges_state
+devtool_get_all_edges
+devtool_get_all_submeshes
+devtool_get_node_status
+devtool_open_in_netns
+meshlink_add_address
+meshlink_add_external_address
+meshlink_blacklist
+meshlink_channel_close
+meshlink_channel_get_flags
+meshlink_channel_get_recvq
+meshlink_channel_get_sendq
+meshlink_channel_open
+meshlink_channel_open_ex
+meshlink_channel_send
+meshlink_channel_shutdown
+meshlink_close
+meshlink_destroy
+meshlink_enable_discovery
+meshlink_errno
+meshlink_export
+meshlink_get_all_nodes
+meshlink_get_all_nodes_by_dev_class
+meshlink_get_all_nodes_by_submesh
+meshlink_get_external_address
+meshlink_get_external_address_for_family
+meshlink_get_fingerprint
+meshlink_get_local_address_for_family
+meshlink_get_node
+meshlink_get_node_dev_class
+meshlink_get_node_submesh
+meshlink_get_pmtu
+meshlink_get_port
+meshlink_get_self
+meshlink_hint_address
+meshlink_import
+meshlink_invite
+meshlink_invite_ex
+meshlink_join
+meshlink_main_loop
+meshlink_open
+meshlink_open_ex
+meshlink_open_params_free
+meshlink_open_params_init
+meshlink_send
+meshlink_set_canonical_address
+meshlink_set_channel_accept_cb
+meshlink_set_channel_poll_cb
+meshlink_set_channel_receive_cb
+meshlink_set_default_blacklist
+meshlink_set_invitation_timeout
+meshlink_set_log_cb
+meshlink_set_node_duplicate_cb
+meshlink_set_node_status_cb
+meshlink_set_port
+meshlink_set_receive_cb
+meshlink_sign
+meshlink_start
+meshlink_stop
+meshlink_strerror
+meshlink_submesh_open
+meshlink_verify
+meshlink_whitelist
// get min_connects and max_connects
- assert(mesh->devclass >= 0 && mesh->devclass <= _DEV_CLASS_MAX);
-
unsigned int min_connects = dev_class_traits[mesh->devclass].min_connects;
unsigned int max_connects = dev_class_traits[mesh->devclass].max_connects;
#define MAXBUFSIZE ((MAXSIZE > 2048 ? MAXSIZE : 2048) + 128)
typedef struct vpn_packet_t {
- struct {
- unsigned int probe: 1;
- unsigned int tcp: 1;
- };
+ unsigned int probe: 1;
+ unsigned int tcp: 1;
uint16_t len; /* the actual number of bytes in the `data' field */
uint8_t data[MAXSIZE];
} vpn_packet_t;
listen_socket_t *ls = data;
vpn_packet_t pkt;
char *hostname;
- sockaddr_t from = {0};
+ sockaddr_t from;
socklen_t fromlen = sizeof(from);
node_t *n;
int len;
+ memset(&from, 0, sizeof(from));
+
len = recvfrom(ls->udp.fd, pkt.data, MAXSIZE, 0, &from.sa, &fromlen);
if(len <= 0 || len > MAXSIZE) {
meshlink_handle_t *mesh = loop->data;
listen_socket_t *l = data;
connection_t *c;
- sockaddr_t sa = {0};
+ sockaddr_t sa;
int fd;
socklen_t len = sizeof(sa);
+ memset(&sa, 0, sizeof(sa));
+
fd = accept(l->tcp.fd, &sa.sa, &len);
if(fd < 0) {
sockaddr_t str2sockaddr(const char *address, const char *port) {
struct addrinfo *ai;
- sockaddr_t result = {0};
+ sockaddr_t result;
int err;
+ memset(&result, 0, sizeof(result));
+
struct addrinfo hint = {
.ai_family = AF_UNSPEC,
.ai_flags = AI_NUMERICHOST,
meshlink_hint_address(mesh, (meshlink_node_t *)n, &sa->sa);
- if(mesh->log_level >= MESHLINK_DEBUG) {
+ if(mesh->log_level <= MESHLINK_DEBUG) {
char *hostname = sockaddr2hostname(&n->address);
logger(mesh, MESHLINK_DEBUG, "UDP address of %s set to %s", n->name, hostname);
free(hostname);
return false;
}
- if(time(NULL) > st.st_mtime + mesh->invitation_timeout) {
+ if(time(NULL) > (time_t)(st.st_mtime + mesh->invitation_timeout)) {
logger(mesh, MESHLINK_ERROR, "Peer %s tried to use an outdated invitation file %s\n", c->name, usedname);
fclose(f);
unlink(usedname);
get_config_bool(lookup_config(c->config_tree, "blacklisted"), &blacklisted);
if(blacklisted) {
- logger(mesh, MESHLINK_EPEER, "Peer %s is blacklisted", c->name);
+ logger(mesh, MESHLINK_INFO, "Peer %s is blacklisted", c->name);
return false;
}
char hex[len * 2 + 1];
- if(mesh->log_level >= MESHLINK_DEBUG) {
+ if(mesh->log_level <= MESHLINK_DEBUG) {
bin2hex(payload, hex, len); // don't do this unless it's going to be logged
}
/* Splay operation */
static splay_node_t *splay_top_down(splay_tree_t *tree, const void *data, int *result) {
- splay_node_t left = {NULL}, right = {NULL};
+ splay_node_t left, right;
splay_node_t *leftbottom = &left, *rightbottom = &right, *child, *grandchild;
splay_node_t *root = tree->root;
int c;
+ memset(&left, 0, sizeof(left));
+ memset(&right, 0, sizeof(right));
+
if(!root) {
if(result) {
*result = 0;
} else {
return false;
}
-}
\ No newline at end of file
+}