From: sairoop-elear Date: Mon, 13 May 2019 00:52:15 +0000 (+0530) Subject: Update android build X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=ad87362afd13c4f14ce9a4b2cf0586a753b5a422;p=meshlink Update android build Fix compiling warnings --- diff --git a/configure.ac b/configure.ac index c1baec17..bc3d27fd 100644 --- a/configure.ac +++ b/configure.ac @@ -96,9 +96,15 @@ PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1.0], [cmocka=true], [cmocka=false]) 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], @@ -112,7 +118,7 @@ AM_CONDITIONAL(INSTALL_TESTS, test "$install_tests" = true) 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__) @@ -128,7 +134,7 @@ AC_CHECK_TYPES([struct sockaddr_storage], ,AC_MSG_ERROR([System must support str 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"] ) diff --git a/examples/.gitignore b/examples/.gitignore index 681b8897..3c0d4109 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -5,3 +5,4 @@ chatpp manynodes meshlinkapp monitor +groupchat diff --git a/examples/Makefile.am b/examples/Makefile.am index fbd71382..150c0c7a 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,27 +1,29 @@ -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 diff --git a/examples/chatpp.cc b/examples/chatpp.cc index d3690404..294ca866 100644 --- a/examples/chatpp.cc +++ b/examples/chatpp.cc @@ -99,7 +99,7 @@ static void parse_command(meshlink::mesh *mesh, char *buf) { 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); diff --git a/examples/groupchat.c b/examples/groupchat.c index f84b3e99..38bbd85b 100644 --- a/examples/groupchat.c +++ b/examples/groupchat.c @@ -239,10 +239,10 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { 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); diff --git a/examples/manynodes.c b/examples/manynodes.c index f9150ef7..3d82bd31 100644 --- a/examples/manynodes.c +++ b/examples/manynodes.c @@ -272,7 +272,7 @@ static void parse_command(char *buf) { 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")) { diff --git a/examples/monitor.c b/examples/monitor.c index ef010af6..218cb67c 100644 --- a/examples/monitor.c +++ b/examples/monitor.c @@ -64,7 +64,7 @@ static void do_redraw_nodes() { 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) { @@ -140,7 +140,6 @@ static void node_status(meshlink_handle_t *mesh, meshlink_node_t *node, bool rea int main(int argc, char *argv[]) { const char *confbase = ".monitor"; const char *id = NULL; - char buf[1024]; if(argc > 1) { confbase = argv[1]; diff --git a/src/Makefile.am b/src/Makefile.am index f793e912..88a84e60 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -33,7 +33,7 @@ lib_LTLIBRARIES = libmeshlink.la 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 \ @@ -54,7 +54,7 @@ libmeshlink_la_SOURCES = \ 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 \ diff --git a/src/ed25519/precomp_data.h b/src/ed25519/precomp_data.h index 776b84f4..ce59788c 100644 --- a/src/ed25519/precomp_data.h +++ b/src/ed25519/precomp_data.h @@ -1388,4 +1388,4 @@ static ge_precomp base[32][8] = { { -20430234, 14955537, -24126347, 8124619, -5369288, -5990470, 30468147, -13900640, 18423289, 4177476 }, }, }, -}; \ No newline at end of file +}; diff --git a/src/meshlink.c b/src/meshlink.c index 1dbefd0e..9641173a 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -49,7 +49,6 @@ typedef struct { #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; @@ -215,23 +214,27 @@ struct socket_in_netns_params { 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; @@ -241,6 +244,10 @@ static int socket_in_netns(int domain, int type, int protocol, int netns) { } 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. @@ -1172,6 +1179,7 @@ static bool meshlink_setup(meshlink_handle_t *mesh) { return true; } +#ifdef HAVE_SETNS static void *setup_network_in_netns_thread(void *arg) { meshlink_handle_t *mesh = arg; @@ -1183,6 +1191,7 @@ static void *setup_network_in_netns_thread(void *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) { @@ -1246,7 +1255,8 @@ void meshlink_open_params_free(meshlink_open_params_t *params) { 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; @@ -1396,12 +1406,19 @@ meshlink_handle_t *meshlink_open_ex(const meshlink_open_params_t *params) { 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); @@ -1448,9 +1465,15 @@ static void *meshlink_main_loop(void *arg) { 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)); @@ -2112,7 +2135,7 @@ static bool refresh_invitation_key(meshlink_handle_t *mesh) { } 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); diff --git a/src/meshlink.sym b/src/meshlink.sym new file mode 100644 index 00000000..71846a7e --- /dev/null +++ b/src/meshlink.sym @@ -0,0 +1,64 @@ +__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 diff --git a/src/net.c b/src/net.c index 2a27350b..26982d2c 100644 --- a/src/net.c +++ b/src/net.c @@ -387,8 +387,6 @@ static void periodic_handler(event_loop_t *loop, void *data) { // 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; diff --git a/src/net.h b/src/net.h index 04bd55a5..cc84ce96 100644 --- a/src/net.h +++ b/src/net.h @@ -36,10 +36,8 @@ #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; diff --git a/src/net_packet.c b/src/net_packet.c index d20ea018..f0c4e980 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -551,11 +551,13 @@ void handle_incoming_vpn_data(event_loop_t *loop, void *data, int flags) { 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) { diff --git a/src/net_socket.c b/src/net_socket.c index 3047ccbd..143f1548 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -670,10 +670,12 @@ void handle_new_meta_connection(event_loop_t *loop, void *data, int flags) { 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) { diff --git a/src/netutl.c b/src/netutl.c index 2a62c18a..9f2319ec 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -52,9 +52,11 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock 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, diff --git a/src/node.c b/src/node.c index 4f4f5999..3a43b8f1 100644 --- a/src/node.c +++ b/src/node.c @@ -136,7 +136,7 @@ void update_node_udp(meshlink_handle_t *mesh, node_t *n, const sockaddr_t *sa) { 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); diff --git a/src/protocol_auth.c b/src/protocol_auth.c index f88aaf4b..b7f6acdd 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -258,7 +258,7 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat 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); @@ -428,7 +428,7 @@ bool id_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { 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; } diff --git a/src/route.c b/src/route.c index 91bd2f82..77e018e9 100644 --- a/src/route.c +++ b/src/route.c @@ -63,7 +63,7 @@ void route(meshlink_handle_t *mesh, node_t *source, vpn_packet_t *packet) { 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 } diff --git a/src/splay_tree.c b/src/splay_tree.c index e2b93a05..51439259 100644 --- a/src/splay_tree.c +++ b/src/splay_tree.c @@ -25,11 +25,14 @@ /* 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; diff --git a/src/submesh.c b/src/submesh.c index 7d4a326e..661ec280 100644 --- a/src/submesh.c +++ b/src/submesh.c @@ -155,4 +155,4 @@ bool submesh_allows_node(const submesh_t *submesh, const node_t *node) { } else { return false; } -} \ No newline at end of file +}