From 5618834958c3ffd0250d3712174bd20aaac36e95 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 7 Apr 2020 23:17:38 +0200 Subject: [PATCH] Remove unused support for proxies. --- src/meshlink_internal.h | 15 ------ src/net.c | 7 --- src/net_socket.c | 49 +++++++------------ src/protocol.c | 16 ------ src/protocol_auth.c | 106 ---------------------------------------- 5 files changed, 18 insertions(+), 175 deletions(-) diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index 8a632e26..8ba4e980 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -57,14 +57,6 @@ typedef struct listen_socket_t { sockaddr_t broadcast_sa; } listen_socket_t; -typedef enum proxytype_t { - PROXY_NONE = 0, - PROXY_SOCKS4, - PROXY_SOCKS4A, - PROXY_SOCKS5, - PROXY_HTTP, -} proxytype_t; - struct meshlink_open_params { char *confbase; char *appname; @@ -199,13 +191,6 @@ struct meshlink_handle { meshlink_queue_t adns_queue; meshlink_queue_t adns_done_queue; signal_t adns_signal; - - // Proxy configuration, currently not exposed. - char *proxyhost; - char *proxyport; - char *proxyuser; - char *proxypass; - proxytype_t proxytype; }; /// A handle for a MeshLink node. diff --git a/src/net.c b/src/net.c index 05049cff..d80df2fd 100644 --- a/src/net.c +++ b/src/net.c @@ -92,13 +92,6 @@ void terminate_connection(meshlink_handle_t *mesh, connection_t *c, bool report) if(outgoing) { do_outgoing_connection(mesh, outgoing); } - -#ifndef HAVE_MINGW - /* Clean up dead proxy processes */ - - while(waitpid(-1, NULL, WNOHANG) > 0); - -#endif } /* diff --git a/src/net_socket.c b/src/net_socket.c index 63bf49ea..30ff0169 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -333,9 +333,6 @@ static bool get_next_outgoing_address(meshlink_handle_t *mesh, outgoing_t *outgo } void do_outgoing_connection(meshlink_handle_t *mesh, outgoing_t *outgoing) { - struct addrinfo *proxyai = NULL; - int result; - begin: if(!get_next_outgoing_address(mesh, outgoing)) { @@ -354,35 +351,26 @@ begin: memcpy(&c->address, outgoing->aip->ai_addr, outgoing->aip->ai_addrlen); - char *hostname = sockaddr2hostname(&c->address); - - logger(mesh, MESHLINK_INFO, "Trying to connect to %s at %s", outgoing->node->name, hostname); + if(mesh->log_level <= MESHLINK_INFO) { + char *hostname = sockaddr2hostname(&c->address); + logger(mesh, MESHLINK_INFO, "Trying to connect to %s at %s", outgoing->node->name, hostname); + free(hostname); + } - if(!mesh->proxytype) { - c->socket = socket(c->address.sa.sa_family, SOCK_STREAM, IPPROTO_TCP); - configure_tcp(c); - } else { - proxyai = str2addrinfo(mesh->proxyhost, mesh->proxyport, SOCK_STREAM); + c->socket = socket(c->address.sa.sa_family, SOCK_STREAM, IPPROTO_TCP); - if(!proxyai) { - free_connection(c); + if(c->socket == -1) { + if(mesh->log_level <= MESHLINK_ERROR) { + char *hostname = sockaddr2hostname(&c->address); + logger(mesh, MESHLINK_ERROR, "Creating socket for %s at %s failed: %s", c->name, hostname, sockstrerror(sockerrno)); free(hostname); - goto begin; } - logger(mesh, MESHLINK_INFO, "Using proxy at %s port %s", mesh->proxyhost, mesh->proxyport); - c->socket = socket(proxyai->ai_family, SOCK_STREAM, IPPROTO_TCP); - configure_tcp(c); - } - - if(c->socket == -1) { - logger(mesh, MESHLINK_ERROR, "Creating socket for %s at %s failed: %s", c->name, hostname, sockstrerror(sockerrno)); free_connection(c); - free(hostname); goto begin; } - free(hostname); + configure_tcp(c); #ifdef FD_CLOEXEC fcntl(c->socket, F_SETFD, FD_CLOEXEC); @@ -399,17 +387,16 @@ begin: /* Connect */ - if(!mesh->proxytype) { - result = connect(c->socket, &c->address.sa, SALEN(c->address.sa)); - } else { - result = connect(c->socket, proxyai->ai_addr, proxyai->ai_addrlen); - freeaddrinfo(proxyai); - } + int result = connect(c->socket, &c->address.sa, SALEN(c->address.sa)); if(result == -1 && !sockinprogress(sockerrno)) { - logger(mesh, MESHLINK_ERROR, "Could not connect to %s: %s", outgoing->node->name, sockstrerror(sockerrno)); - free_connection(c); + if(mesh->log_level <= MESHLINK_ERROR) { + char *hostname = sockaddr2hostname(&c->address); + logger(mesh, MESHLINK_ERROR, "Could not connect to %s: %s", outgoing->node->name, sockstrerror(sockerrno)); + free(hostname); + } + free_connection(c); goto begin; } diff --git a/src/protocol.c b/src/protocol.c index 482808a7..c8c75cfc 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -130,22 +130,6 @@ void forward_request(meshlink_handle_t *mesh, connection_t *from, submesh_t *s, bool receive_request(meshlink_handle_t *mesh, connection_t *c, const char *request) { assert(request); - if(c->outgoing && mesh->proxytype == PROXY_HTTP && c->allow_request == ID) { - if(!request[0] || request[0] == '\r') { - return true; - } - - if(!strncasecmp(request, "HTTP/1.1 ", 9)) { - if(!strncmp(request + 9, "200", 3)) { - logger(mesh, MESHLINK_DEBUG, "Proxy request granted"); - return true; - } else { - logger(mesh, MESHLINK_DEBUG, "Proxy request rejected: %s", request + 9); - return false; - } - } - } - int reqno = atoi(request); if(reqno || *request == '0') { diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 416066ff..5632c5a2 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -43,113 +43,7 @@ extern bool node_write_devclass(meshlink_handle_t *mesh, node_t *n); -static bool send_proxyrequest(meshlink_handle_t *mesh, connection_t *c) { - switch(mesh->proxytype) { - case PROXY_HTTP: { - char *host; - char *port; - - sockaddr2str(&c->address, &host, &port); - send_request(mesh, c, NULL, "CONNECT %s:%s HTTP/1.1\r\n\r", host, port); - free(host); - free(port); - return true; - } - - case PROXY_SOCKS4: { - if(c->address.sa.sa_family != AF_INET) { - logger(mesh, MESHLINK_ERROR, "Cannot connect to an IPv6 host through a SOCKS 4 proxy!"); - return false; - } - - char s4req[9 + (mesh->proxyuser ? strlen(mesh->proxyuser) : 0)]; - s4req[0] = 4; - s4req[1] = 1; - memcpy(s4req + 2, &c->address.in.sin_port, 2); - memcpy(s4req + 4, &c->address.in.sin_addr, 4); - - if(mesh->proxyuser) { - memcpy(s4req + 8, mesh->proxyuser, strlen(mesh->proxyuser)); - } - - s4req[sizeof(s4req) - 1] = 0; - c->tcplen = 8; - return send_meta(mesh, c, s4req, sizeof(s4req)); - } - - case PROXY_SOCKS5: { - int len = 3 + 6 + (c->address.sa.sa_family == AF_INET ? 4 : 16); - c->tcplen = 2; - - if(mesh->proxypass) { - len += 3 + strlen(mesh->proxyuser) + strlen(mesh->proxypass); - } - - char s5req[len]; - int i = 0; - s5req[i++] = 5; - s5req[i++] = 1; - - if(mesh->proxypass) { - s5req[i++] = 2; - s5req[i++] = 1; - s5req[i++] = strlen(mesh->proxyuser); - memcpy(s5req + i, mesh->proxyuser, strlen(mesh->proxyuser)); - i += strlen(mesh->proxyuser); - s5req[i++] = strlen(mesh->proxypass); - memcpy(s5req + i, mesh->proxypass, strlen(mesh->proxypass)); - i += strlen(mesh->proxypass); - c->tcplen += 2; - } else { - s5req[i++] = 0; - } - - s5req[i++] = 5; - s5req[i++] = 1; - s5req[i++] = 0; - - if(c->address.sa.sa_family == AF_INET) { - s5req[i++] = 1; - memcpy(s5req + i, &c->address.in.sin_addr, 4); - i += 4; - memcpy(s5req + i, &c->address.in.sin_port, 2); - i += 2; - c->tcplen += 10; - } else if(c->address.sa.sa_family == AF_INET6) { - s5req[i++] = 3; - memcpy(s5req + i, &c->address.in6.sin6_addr, 16); - i += 16; - memcpy(s5req + i, &c->address.in6.sin6_port, 2); - i += 2; - c->tcplen += 22; - } else { - logger(mesh, MESHLINK_ERROR, "Address family %hx not supported for SOCKS 5 proxies!", c->address.sa.sa_family); - return false; - } - - if(i > len) { - abort(); - } - - return send_meta(mesh, c, s5req, sizeof(s5req)); - } - - case PROXY_SOCKS4A: - logger(mesh, MESHLINK_ERROR, "Proxy type not implemented yet"); - return false; - - default: - logger(mesh, MESHLINK_ERROR, "Unknown proxy type"); - return false; - } -} - bool send_id(meshlink_handle_t *mesh, connection_t *c) { - if(mesh->proxytype && c->outgoing) - if(!send_proxyrequest(mesh, c)) { - return false; - } - return send_request(mesh, c, NULL, "%d %s %d.%d %s", ID, mesh->self->name, PROT_MAJOR, PROT_MINOR, mesh->appname); } -- 2.39.5