Commit f29457e9 authored by Dmitry Frank's avatar Dmitry Frank Committed by Cesanta Bot

Remove tunneling from mongoose

CL: Mongoose Web Server: Remove tunneling functionality which was used by nobody

PUBLISHED_FROM=38b9e8ae7b0a5a1dbba5cff4074843dc681267d3
parent 8742fac5
...@@ -53,7 +53,6 @@ signature: | ...@@ -53,7 +53,6 @@ signature: |
#define MG_F_WEBSOCKET_NO_DEFRAG (1 << 12) /* Websocket specific */ #define MG_F_WEBSOCKET_NO_DEFRAG (1 << 12) /* Websocket specific */
#define MG_F_DELETE_CHUNK (1 << 13) /* HTTP specific */ #define MG_F_DELETE_CHUNK (1 << 13) /* HTTP specific */
#define MG_F_ENABLE_BROADCAST (1 << 14) /* Allow broadcast address usage */ #define MG_F_ENABLE_BROADCAST (1 << 14) /* Allow broadcast address usage */
#define MG_F_TUN_DO_NOT_RECONNECT (1 << 15) /* Don't reconnect tunnel */
#define MG_F_USER_1 (1 << 20) /* Flags left for application */ #define MG_F_USER_1 (1 << 20) /* Flags left for application */
#define MG_F_USER_2 (1 << 21) #define MG_F_USER_2 (1 << 21)
......
This diff is collapsed.
...@@ -3157,10 +3157,6 @@ struct { \ ...@@ -3157,10 +3157,6 @@ struct { \
(CS_PLATFORM == CS_P_WINDOWS || CS_PLATFORM == CS_P_UNIX) (CS_PLATFORM == CS_P_WINDOWS || CS_PLATFORM == CS_P_UNIX)
#endif #endif
#ifndef MG_ENABLE_TUN
#define MG_ENABLE_TUN MG_ENABLE_HTTP_WEBSOCKET
#endif
#ifndef MG_ENABLE_SNTP #ifndef MG_ENABLE_SNTP
#define MG_ENABLE_SNTP 0 #define MG_ENABLE_SNTP 0
#endif #endif
...@@ -3524,7 +3520,6 @@ struct mg_connection { ...@@ -3524,7 +3520,6 @@ struct mg_connection {
#define MG_F_WEBSOCKET_NO_DEFRAG (1 << 12) /* Websocket specific */ #define MG_F_WEBSOCKET_NO_DEFRAG (1 << 12) /* Websocket specific */
#define MG_F_DELETE_CHUNK (1 << 13) /* HTTP specific */ #define MG_F_DELETE_CHUNK (1 << 13) /* HTTP specific */
#define MG_F_ENABLE_BROADCAST (1 << 14) /* Allow broadcast address usage */ #define MG_F_ENABLE_BROADCAST (1 << 14) /* Allow broadcast address usage */
#define MG_F_TUN_DO_NOT_RECONNECT (1 << 15) /* Don't reconnect tunnel */
#define MG_F_USER_1 (1 << 20) /* Flags left for application */ #define MG_F_USER_1 (1 << 20) /* Flags left for application */
#define MG_F_USER_2 (1 << 21) #define MG_F_USER_2 (1 << 21)
......
...@@ -153,10 +153,6 @@ ...@@ -153,10 +153,6 @@
(CS_PLATFORM == CS_P_WINDOWS || CS_PLATFORM == CS_P_UNIX) (CS_PLATFORM == CS_P_WINDOWS || CS_PLATFORM == CS_P_UNIX)
#endif #endif
#ifndef MG_ENABLE_TUN
#define MG_ENABLE_TUN MG_ENABLE_HTTP_WEBSOCKET
#endif
#ifndef MG_ENABLE_SNTP #ifndef MG_ENABLE_SNTP
#define MG_ENABLE_SNTP 0 #define MG_ENABLE_SNTP 0
#endif #endif
......
...@@ -59,15 +59,12 @@ SOURCES = $(COMMON)/mg_mem.h \ ...@@ -59,15 +59,12 @@ SOURCES = $(COMMON)/mg_mem.h \
$(COMMON)/mbuf.c \ $(COMMON)/mbuf.c \
$(COMMON)/mg_str.c \ $(COMMON)/mg_str.c \
$(COMMON)/str_util.c \ $(COMMON)/str_util.c \
tun.h \
net.c \ net.c \
net_if_socket.h \ net_if_socket.h \
net_if_tun.h \
net_if_socks.h \ net_if_socks.h \
net_if.c \ net_if.c \
net_if_socket.c \ net_if_socket.c \
net_if_socks.c \ net_if_socks.c \
net_if_tun.c \
ssl_if_openssl.c \ ssl_if_openssl.c \
ssl_if_mbedtls.c \ ssl_if_mbedtls.c \
uri.c \ uri.c \
...@@ -83,7 +80,6 @@ SOURCES = $(COMMON)/mg_mem.h \ ...@@ -83,7 +80,6 @@ SOURCES = $(COMMON)/mg_mem.h \
dns_server.c \ dns_server.c \
resolv.c \ resolv.c \
coap.c \ coap.c \
tun.c \
sntp.c \ sntp.c \
socks.c \ socks.c \
$(COMMON)/platforms/cc3200/cc3200_libc.c \ $(COMMON)/platforms/cc3200/cc3200_libc.c \
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "mongoose/src/dns.h" #include "mongoose/src/dns.h"
#include "mongoose/src/internal.h" #include "mongoose/src/internal.h"
#include "mongoose/src/resolv.h" #include "mongoose/src/resolv.h"
#include "mongoose/src/tun.h"
#include "mongoose/src/util.h" #include "mongoose/src/util.h"
#define MG_MAX_HOST_LEN 200 #define MG_MAX_HOST_LEN 200
...@@ -816,13 +815,6 @@ struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address, ...@@ -816,13 +815,6 @@ struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address,
MG_COPY_COMMON_CONNECTION_OPTIONS(&add_sock_opts, &opts); MG_COPY_COMMON_CONNECTION_OPTIONS(&add_sock_opts, &opts);
#if MG_ENABLE_TUN
if (mg_strncmp(mg_mk_str(address), mg_mk_str("ws://"), 5) == 0 ||
mg_strncmp(mg_mk_str(address), mg_mk_str("wss://"), 6) == 0) {
return mg_tun_bind_opt(mgr, address, MG_CB(callback, user_data), opts);
}
#endif
if (mg_parse_address(address, &sa, &proto, host, sizeof(host)) <= 0) { if (mg_parse_address(address, &sa, &proto, host, sizeof(host)) <= 0) {
MG_SET_PTRPTR(opts.error_string, "cannot parse address"); MG_SET_PTRPTR(opts.error_string, "cannot parse address");
return NULL; return NULL;
......
...@@ -146,7 +146,6 @@ struct mg_connection { ...@@ -146,7 +146,6 @@ struct mg_connection {
#define MG_F_WEBSOCKET_NO_DEFRAG (1 << 12) /* Websocket specific */ #define MG_F_WEBSOCKET_NO_DEFRAG (1 << 12) /* Websocket specific */
#define MG_F_DELETE_CHUNK (1 << 13) /* HTTP specific */ #define MG_F_DELETE_CHUNK (1 << 13) /* HTTP specific */
#define MG_F_ENABLE_BROADCAST (1 << 14) /* Allow broadcast address usage */ #define MG_F_ENABLE_BROADCAST (1 << 14) /* Allow broadcast address usage */
#define MG_F_TUN_DO_NOT_RECONNECT (1 << 15) /* Don't reconnect tunnel */
#define MG_F_USER_1 (1 << 20) /* Flags left for application */ #define MG_F_USER_1 (1 << 20) /* Flags left for application */
#define MG_F_USER_2 (1 << 21) #define MG_F_USER_2 (1 << 21)
......
#include "mongoose/src/net_if.h" #include "mongoose/src/net_if.h"
#include "mongoose/src/internal.h" #include "mongoose/src/internal.h"
#include "mongoose/src/net_if_socket.h" #include "mongoose/src/net_if_socket.h"
#include "mongoose/src/net_if_tun.h"
extern const struct mg_iface_vtable mg_default_iface_vtable; extern const struct mg_iface_vtable mg_default_iface_vtable;
const struct mg_iface_vtable *mg_ifaces[] = { const struct mg_iface_vtable *mg_ifaces[] = {
&mg_default_iface_vtable, &mg_default_iface_vtable,
#if MG_ENABLE_TUN
&mg_tun_iface_vtable,
#endif
}; };
int mg_num_ifaces = (int) (sizeof(mg_ifaces) / sizeof(mg_ifaces[0])); int mg_num_ifaces = (int) (sizeof(mg_ifaces) / sizeof(mg_ifaces[0]));
......
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#if MG_ENABLE_TUN
#include "common/cs_dbg.h"
#include "common/cs_time.h"
#include "mongoose/src/internal.h"
#include "mongoose/src/net_if_tun.h"
#include "mongoose/src/tun.h"
#include "mongoose/src/util.h"
#define MG_TCP_RECV_BUFFER_SIZE 1024
#define MG_UDP_RECV_BUFFER_SIZE 1500
void mg_tun_if_connect_tcp(struct mg_connection *nc,
const union socket_address *sa) {
(void) nc;
(void) sa;
}
void mg_tun_if_connect_udp(struct mg_connection *nc) {
(void) nc;
}
int mg_tun_if_listen_tcp(struct mg_connection *nc, union socket_address *sa) {
(void) nc;
(void) sa;
return 0;
}
int mg_tun_if_listen_udp(struct mg_connection *nc, union socket_address *sa) {
(void) nc;
(void) sa;
return -1;
}
void mg_tun_if_tcp_send(struct mg_connection *nc, const void *buf, size_t len) {
struct mg_tun_client *client = (struct mg_tun_client *) nc->iface->data;
uint32_t stream_id = (uint32_t)(uintptr_t) nc->mgr_data;
struct mg_str msg = {(char *) buf, len};
#if MG_ENABLE_HEXDUMP
char hex[512];
mg_hexdump(buf, len, hex, sizeof(hex));
LOG(LL_DEBUG, ("sending to stream 0x%x:\n%s", (unsigned int) stream_id, hex));
#endif
mg_tun_send_frame(client->disp, stream_id, MG_TUN_DATA_FRAME, 0, msg);
}
void mg_tun_if_udp_send(struct mg_connection *nc, const void *buf, size_t len) {
(void) nc;
(void) buf;
(void) len;
}
void mg_tun_if_recved(struct mg_connection *nc, size_t len) {
(void) nc;
(void) len;
}
int mg_tun_if_create_conn(struct mg_connection *nc) {
(void) nc;
return 1;
}
void mg_tun_if_destroy_conn(struct mg_connection *nc) {
struct mg_tun_client *client = (struct mg_tun_client *) nc->iface->data;
if (nc->flags & MG_F_LISTENING) {
mg_tun_destroy_client(client);
} else if (client->disp) {
uint32_t stream_id = (uint32_t)(uintptr_t) nc->mgr_data;
struct mg_str msg = {NULL, 0};
LOG(LL_DEBUG, ("closing 0x%x:", (unsigned int) stream_id));
mg_tun_send_frame(client->disp, stream_id, MG_TUN_DATA_FRAME,
MG_TUN_F_END_STREAM, msg);
}
}
/* Associate a socket to a connection. */
void mg_tun_if_sock_set(struct mg_connection *nc, sock_t sock) {
(void) nc;
(void) sock;
}
void mg_tun_if_init(struct mg_iface *iface) {
(void) iface;
}
void mg_tun_if_free(struct mg_iface *iface) {
(void) iface;
}
void mg_tun_if_add_conn(struct mg_connection *nc) {
nc->sock = INVALID_SOCKET;
}
void mg_tun_if_remove_conn(struct mg_connection *nc) {
(void) nc;
}
time_t mg_tun_if_poll(struct mg_iface *iface, int timeout_ms) {
(void) iface;
(void) timeout_ms;
return (time_t) cs_time();
}
void mg_tun_if_get_conn_addr(struct mg_connection *nc, int remote,
union socket_address *sa) {
(void) nc;
(void) remote;
(void) sa;
}
struct mg_connection *mg_tun_if_find_conn(struct mg_tun_client *client,
uint32_t stream_id) {
struct mg_connection *nc = NULL;
for (nc = client->mgr->active_connections; nc != NULL; nc = nc->next) {
if (nc->iface != client->iface || (nc->flags & MG_F_LISTENING)) {
continue;
}
if (stream_id == (uint32_t)(uintptr_t) nc->mgr_data) {
return nc;
}
}
if (stream_id > client->last_stream_id) {
/* create a new connection */
LOG(LL_DEBUG, ("new stream 0x%x, accepting", (unsigned int) stream_id));
nc = mg_if_accept_new_conn(client->listener);
nc->mgr_data = (void *) (uintptr_t) stream_id;
client->last_stream_id = stream_id;
} else {
LOG(LL_DEBUG,
("Ignoring stream 0x%x (last_stream_id 0x%x)", (unsigned int) stream_id,
(unsigned int) client->last_stream_id));
}
return nc;
}
/* clang-format off */
#define MG_TUN_IFACE_VTABLE \
{ \
mg_tun_if_init, \
mg_tun_if_free, \
mg_tun_if_add_conn, \
mg_tun_if_remove_conn, \
mg_tun_if_poll, \
mg_tun_if_listen_tcp, \
mg_tun_if_listen_udp, \
mg_tun_if_connect_tcp, \
mg_tun_if_connect_udp, \
mg_tun_if_tcp_send, \
mg_tun_if_udp_send, \
mg_tun_if_recved, \
mg_tun_if_create_conn, \
mg_tun_if_destroy_conn, \
mg_tun_if_sock_set, \
mg_tun_if_get_conn_addr, \
}
/* clang-format on */
const struct mg_iface_vtable mg_tun_iface_vtable = MG_TUN_IFACE_VTABLE;
#endif /* MG_ENABLE_TUN */
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_MONGOOSE_SRC_NET_IF_TUN_H_
#define CS_MONGOOSE_SRC_NET_IF_TUN_H_
#if MG_ENABLE_TUN
#include "mongoose/src/net_if.h"
struct mg_tun_client;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
extern const struct mg_iface_vtable mg_tun_iface_vtable;
struct mg_connection *mg_tun_if_find_conn(struct mg_tun_client *client,
uint32_t stream_id);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* MG_ENABLE_TUN */
#endif /* CS_MONGOOSE_SRC_NET_IF_TUN_H_ */
This diff is collapsed.
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_MONGOOSE_SRC_TUN_H_
#define CS_MONGOOSE_SRC_TUN_H_
#if MG_ENABLE_TUN
#include "mongoose/src/net.h"
#include "common/mg_str.h"
#ifndef MG_TUN_RECONNECT_INTERVAL
#define MG_TUN_RECONNECT_INTERVAL 1
#endif
#define MG_TUN_PROTO_NAME "mg_tun"
#define MG_TUN_DATA_FRAME 0x0
#define MG_TUN_F_END_STREAM 0x1
/*
* MG TUN frame format is loosely based on HTTP/2.
* However since the communication happens via WebSocket
* there is no need to encode the frame length, since that's
* solved by WebSocket framing.
*
* TODO(mkm): Detailed description of the protocol.
*/
struct mg_tun_frame {
uint8_t type;
uint8_t flags;
uint32_t stream_id; /* opaque stream identifier */
struct mg_str body;
};
struct mg_tun_ssl_opts {
#if MG_ENABLE_SSL
const char *ssl_cert;
const char *ssl_key;
const char *ssl_ca_cert;
#else
int dummy; /* some compilers don't like empty structs */
#endif
};
struct mg_tun_client {
struct mg_mgr *mgr;
struct mg_iface *iface;
const char *disp_url;
struct mg_tun_ssl_opts ssl;
uint32_t last_stream_id; /* stream id of most recently accepted connection */
struct mg_connection *disp;
struct mg_connection *listener;
struct mg_connection *reconnect;
};
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct mg_connection *mg_tun_bind_opt(struct mg_mgr *mgr,
const char *dispatcher,
MG_CB(mg_event_handler_t handler,
void *user_data),
struct mg_bind_opts opts);
int mg_tun_parse_frame(void *data, size_t len, struct mg_tun_frame *frame);
void mg_tun_send_frame(struct mg_connection *ws, uint32_t stream_id,
uint8_t type, uint8_t flags, struct mg_str msg);
void mg_tun_destroy_client(struct mg_tun_client *client);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* MG_ENABLE_TUN */
#endif /* CS_MONGOOSE_SRC_TUN_H_ */
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
PROG = unit_test PROG = unit_test
REPO_ROOT ?= ../../ REPO_ROOT ?= ../../
SRC_DIR = ../src SRC_DIR = ../src
TEST_SOURCES = unit_test.c $(REPO_ROOT)/common/test_util.c $(REPO_ROOT)/tuna/dispatcher.c TEST_SOURCES = unit_test.c $(REPO_ROOT)/common/test_util.c
AMALGAMATED_SOURCES = ../mongoose.c AMALGAMATED_SOURCES = ../mongoose.c
KRYPTON_PATH = $(REPO_ROOT)/krypton KRYPTON_PATH = $(REPO_ROOT)/krypton
# or Krypton, or mbedTLS # or Krypton, or mbedTLS
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "unit_test.h" #include "unit_test.h"
#include "common/test_util.h" #include "common/test_util.h"
#include "common/cs_md5.h" #include "common/cs_md5.h"
#include "tuna/dispatcher.h"
#if defined(_MSC_VER) && _MSC_VER >= 1900 #if defined(_MSC_VER) && _MSC_VER >= 1900
#include <crtdbg.h> #include <crtdbg.h>
...@@ -3816,44 +3815,6 @@ void tunnel_client_test_handler(struct mg_connection *nc, int ev, ...@@ -3816,44 +3815,6 @@ void tunnel_client_test_handler(struct mg_connection *nc, int ev,
} }
} }
/*
* NOTE(mkm): this test requires compiling the unit_test.c file with
* //tuna/dispatcher.c .
* Windows test runner doesn't use a makefile that's checked in
* and I can't shave this yak now.
* This doesn't mean the tunnel is not supposed to work on windows; there
* is no fundamental reason it shouldn't, but obviously we should shave
* the yak and make it testable there as well.
*/
#ifndef _WIN32
static const char *test_tunnel(void) {
struct mg_connection *client, *server;
struct mg_mgr mgr;
int sentinel = 0;
mg_mgr_init(&mgr, NULL);
mg_tund_bind(&mgr, "localhost:4321");
server = mg_bind(&mgr, "ws://localhost:4321", tunnel_server_test_handler);
mg_set_protocol_http_websocket(server);
/*
* Connection happens only at the next poll (because we need to give the app
* a chance to set MG_F_TUN_DO_NOT_RECONNECT), so let's poll once
*/
mg_mgr_poll(&mgr, 1);
mg_mgr_poll(&mgr, 1);
client = mg_connect_http(&mgr, tunnel_client_test_handler,
"http://localhost:4321/foo", NULL, NULL);
client->user_data = (void *) &sentinel;
poll_until(&mgr, 1, c_int_eq, &sentinel, (void *) 1);
ASSERT_EQ(sentinel, 1);
mg_mgr_free(&mgr);
return NULL;
}
#endif
static const char *test_http_chunk(void) { static const char *test_http_chunk(void) {
struct mg_connection nc; struct mg_connection nc;
init_test_connection(&nc); init_test_connection(&nc);
...@@ -5544,9 +5505,6 @@ static const char *run_tests(const char *filter, double *total_elapsed) { ...@@ -5544,9 +5505,6 @@ static const char *run_tests(const char *filter, double *total_elapsed) {
RUN_TEST(test_hexdump_file); RUN_TEST(test_hexdump_file);
RUN_TEST(test_basic_auth_helpers); RUN_TEST(test_basic_auth_helpers);
RUN_TEST(test_http_auth); RUN_TEST(test_http_auth);
#ifndef _WIN32
RUN_TEST(test_tunnel);
#endif
#if MG_ENABLE_SSL #if MG_ENABLE_SSL
RUN_TEST(test_ssl); RUN_TEST(test_ssl);
#ifdef OPENSSL_VERSION_NUMBER #ifdef OPENSSL_VERSION_NUMBER
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment