mirror of
https://github.com/EndPositive/slipstream.git
synced 2025-10-08 12:25:04 +00:00
double free, cubic, domain name, disable gso
This commit is contained in:
parent
b1cb046417
commit
fcd1145439
4 changed files with 45 additions and 32 deletions
|
|
@ -16,14 +16,14 @@ extern "C" {
|
|||
|
||||
#define SLIPSTREAM_CLIENT_TICKET_STORE "sample_ticket_store.bin";
|
||||
#define SLIPSTREAM_CLIENT_TOKEN_STORE "sample_token_store.bin";
|
||||
#define SLIPSTREAM_QLOG_DIR "./qlog/";
|
||||
#define SLIPSTREAM_QLOG_DIR "./qlog";
|
||||
|
||||
|
||||
|
||||
int picoquic_slipstream_client(int listen_port, char const* server_name, int server_port);
|
||||
int picoquic_slipstream_client(int listen_port, char const* server_name, int server_port, const char* domain_name);
|
||||
|
||||
int picoquic_slipstream_server(int server_port, const char* pem_cert, const char* pem_key, char const* upstream_name,
|
||||
int upstream_port);
|
||||
int upstream_port, const char* domain_name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
static void usage(char const * sample_name)
|
||||
{
|
||||
fprintf(stderr, "Usage:\n");
|
||||
fprintf(stderr, " %s client listen_port slipstream_server_name slipstream_server_port\n", sample_name);
|
||||
fprintf(stderr, " %s server listen_port cert key target_server_name target_server_port\n", sample_name);
|
||||
fprintf(stderr, " %s client listen_port slipstream_server_name slipstream_server_port domain_name\n", sample_name);
|
||||
fprintf(stderr, " %s server listen_port cert key target_server_name target_server_port domain_name\n", sample_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
@ -34,24 +34,26 @@ int main(int argc, char** argv)
|
|||
usage(argv[0]);
|
||||
}
|
||||
else if (strcmp(argv[1], "client") == 0) {
|
||||
if (argc != 5) {
|
||||
if (argc != 6) {
|
||||
usage(argv[0]);
|
||||
}
|
||||
else {
|
||||
int local_port = atoi(argv[2]);
|
||||
char const* remote_ip = argv[3];
|
||||
int remote_port = atoi(argv[4]);
|
||||
exit_code = picoquic_slipstream_client(local_port, remote_ip, remote_port);
|
||||
const char* domain_name = argv[5];
|
||||
exit_code = picoquic_slipstream_client(local_port, remote_ip, remote_port, domain_name);
|
||||
}
|
||||
}
|
||||
else if (strcmp(argv[1], "server") == 0) {
|
||||
if (argc != 7) {
|
||||
if (argc != 8) {
|
||||
usage(argv[0]);
|
||||
}
|
||||
else {
|
||||
int server_port = get_port(argv[0], argv[2]);
|
||||
int remote_port = get_port(argv[0], argv[6]);
|
||||
exit_code = picoquic_slipstream_server(server_port, argv[3], argv[4], argv[5], remote_port);
|
||||
const char* domain_name = argv[7];
|
||||
exit_code = picoquic_slipstream_server(server_port, argv[3], argv[4], argv[5], remote_port, domain_name);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@
|
|||
#include "SPCDNS/src/dns.h"
|
||||
#include "SPCDNS/src/mappings.h"
|
||||
|
||||
char* client_domain_name = NULL;
|
||||
size_t client_domain_name_len = 0;
|
||||
|
||||
ssize_t client_encode_segment(dns_packet_t* packet, size_t* packet_len, const unsigned char* src_buf, size_t src_buf_len) {
|
||||
edns0_opt_t opt;
|
||||
dns_answer_t edns;
|
||||
|
|
@ -31,10 +34,9 @@ ssize_t client_encode_segment(dns_packet_t* packet, size_t* packet_len, const un
|
|||
const size_t encoded_len = slipstream_inline_dotify(name, 255, len);
|
||||
name[encoded_len] = '.';
|
||||
|
||||
const char* tld = "test.com.";
|
||||
const size_t tld_len = strlen(tld);
|
||||
memcpy(&name[encoded_len + 1], tld, tld_len);
|
||||
name[encoded_len + 1 + tld_len] = '\0';
|
||||
memcpy(&name[encoded_len + 1], client_domain_name, client_domain_name_len);
|
||||
name[encoded_len + 1 + client_domain_name_len] = '.';
|
||||
name[encoded_len + 1 + client_domain_name_len + 1] = '\0';
|
||||
|
||||
dns_question_t domain;
|
||||
domain.name = name;
|
||||
|
|
@ -567,32 +569,35 @@ static int slipstream_connect(char const* server_name, int server_port,
|
|||
return ret;
|
||||
}
|
||||
|
||||
int picoquic_slipstream_client(int listen_port, char const* server_name, int server_port) {
|
||||
int picoquic_slipstream_client(int listen_port, char const* server_name, int server_port, const char* domain_name) {
|
||||
/* Start: start the QUIC process */
|
||||
int ret = 0;
|
||||
picoquic_quic_t* quic = NULL;
|
||||
uint64_t current_time = 0;
|
||||
picoquic_cnx_t* cnx = NULL;
|
||||
slipstream_client_ctx_t client_ctx = {0};
|
||||
char const* ticket_store_filename = SLIPSTREAM_CLIENT_TICKET_STORE;
|
||||
char const* token_store_filename = SLIPSTREAM_CLIENT_TOKEN_STORE;
|
||||
|
||||
int mtu = 146;
|
||||
client_domain_name = strdup(domain_name);
|
||||
client_domain_name_len = strlen(domain_name);
|
||||
|
||||
// int mtu = 1200;
|
||||
// int mtu = 129;
|
||||
int mtu = 145;
|
||||
|
||||
/* Create config */
|
||||
picoquic_quic_config_t config;
|
||||
picoquic_config_init(&config);
|
||||
config.nb_connections = 8;
|
||||
// config.log_file = "-";
|
||||
#ifndef BUILD_LOGLIB
|
||||
#ifdef BUILD_LOGLIB
|
||||
config.qlog_dir = SLIPSTREAM_QLOG_DIR;
|
||||
#endif
|
||||
config.server_port = server_port;
|
||||
config.mtu_max = mtu;
|
||||
config.initial_send_mtu_ipv4 = mtu;
|
||||
config.initial_send_mtu_ipv6 = mtu;
|
||||
config.cc_algo_id = "bbr1";
|
||||
config.cc_algo_id = "cubic";
|
||||
config.multipath_option = 0;
|
||||
config.use_long_log = 1;
|
||||
config.do_preemptive_repeat = 1;
|
||||
|
|
@ -603,8 +608,11 @@ int picoquic_slipstream_client(int listen_port, char const* server_name, int ser
|
|||
|
||||
/* Create the QUIC context for the server */
|
||||
current_time = picoquic_current_time();
|
||||
// one connection only, freed in slipstream_client_free_context on picoquic close callback
|
||||
slipstream_client_ctx_t *client_ctx = malloc(sizeof(slipstream_client_ctx_t));
|
||||
memset(client_ctx, 0, sizeof(slipstream_client_ctx_t));
|
||||
/* Create QUIC context */
|
||||
quic = picoquic_create_and_configure(&config, slipstream_client_callback, &client_ctx, current_time, NULL);
|
||||
quic = picoquic_create_and_configure(&config, slipstream_client_callback, client_ctx, current_time, NULL);
|
||||
if (quic == NULL) {
|
||||
fprintf(stderr, "Could not create server context\n");
|
||||
return -1;
|
||||
|
|
@ -617,7 +625,7 @@ int picoquic_slipstream_client(int listen_port, char const* server_name, int ser
|
|||
#endif
|
||||
picoquic_set_key_log_file_from_env(quic);
|
||||
|
||||
ret = slipstream_connect(server_name, server_port, quic, &cnx, &client_ctx);
|
||||
ret = slipstream_connect(server_name, server_port, quic, &cnx, client_ctx);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "Could not connect to server\n");
|
||||
return -1;
|
||||
|
|
@ -660,7 +668,7 @@ int picoquic_slipstream_client(int listen_port, char const* server_name, int ser
|
|||
// And ensure that gso is on
|
||||
// $ ethtool -k lo | grep generic-segmentation-offload
|
||||
// generic-segmentation-offload: on
|
||||
param.do_not_use_gso = 0;
|
||||
param.do_not_use_gso = 1;
|
||||
|
||||
param.is_client = 1;
|
||||
param.decode = client_decode;
|
||||
|
|
@ -670,17 +678,17 @@ int picoquic_slipstream_client(int listen_port, char const* server_name, int ser
|
|||
thread_ctx.quic = quic;
|
||||
thread_ctx.param = ¶m;
|
||||
thread_ctx.loop_callback = slipstream_client_sockloop_callback;
|
||||
thread_ctx.loop_callback_ctx = &client_ctx;
|
||||
thread_ctx.loop_callback_ctx = client_ctx;
|
||||
|
||||
/* Open the wake up pipe or event */
|
||||
picoquic_open_network_wake_up(&thread_ctx, &ret);
|
||||
|
||||
client_ctx.thread_ctx = &thread_ctx;
|
||||
client_ctx->thread_ctx = &thread_ctx;
|
||||
|
||||
slipstream_client_accepter_args* args = malloc(sizeof(slipstream_client_accepter_args));
|
||||
args->fd = listen_sock;
|
||||
args->cnx = cnx;
|
||||
args->client_ctx = &client_ctx;
|
||||
args->client_ctx = client_ctx;
|
||||
args->thread_ctx = &thread_ctx;
|
||||
|
||||
pthread_t thread;
|
||||
|
|
@ -705,8 +713,5 @@ int picoquic_slipstream_client(int listen_port, char const* server_name, int ser
|
|||
}
|
||||
picoquic_free(quic);
|
||||
|
||||
/* Free the Client context */
|
||||
slipstream_client_free_context(&client_ctx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@
|
|||
#include "SPCDNS/src/mappings.h"
|
||||
|
||||
circular_query_buffer_t server_cqb = {0};
|
||||
char* server_domain_name = NULL;
|
||||
size_t server_domain_name_len = 0;
|
||||
|
||||
ssize_t server_encode(unsigned char** dest_buf, const unsigned char* src_buf, size_t src_buf_len, size_t* segment_size) {
|
||||
const dns_query_t *query = (dns_query_t *) circular_query_buffer_get_read_slot(&server_cqb);
|
||||
|
|
@ -99,12 +101,12 @@ ssize_t server_decode(const unsigned char** dest_buf, const unsigned char* src_b
|
|||
return -1;
|
||||
}
|
||||
|
||||
const char* tld = "test.com.";
|
||||
const size_t data_len = strlen(question->name) - strlen(tld) - 1;
|
||||
const size_t data_len = strlen(question->name) - server_domain_name_len - 1 - 1;
|
||||
|
||||
// copy the subdomain from name to a new buffer
|
||||
char data_buf[data_len];
|
||||
memcpy(data_buf, question->name, data_len);
|
||||
data_buf[data_len] = '\0';
|
||||
const size_t encoded_len = slipstream_inline_undotify(data_buf, data_len);
|
||||
|
||||
char* decoded_buf = malloc(encoded_len);
|
||||
|
|
@ -484,7 +486,7 @@ void server_sighandler(int signum) {
|
|||
}
|
||||
|
||||
int picoquic_slipstream_server(int server_port, const char* server_cert, const char* server_key,
|
||||
char const* upstream_name, int upstream_port) {
|
||||
char const* upstream_name, int upstream_port, const char* domain_name) {
|
||||
/* Start: start the QUIC process with cert and key files */
|
||||
int ret = 0;
|
||||
picoquic_quic_t* quic = NULL;
|
||||
|
|
@ -495,6 +497,9 @@ int picoquic_slipstream_server(int server_port, const char* server_cert, const c
|
|||
int is_name = 0;
|
||||
picoquic_get_server_address(upstream_name, upstream_port, &default_context.upstream_addr, &is_name);
|
||||
|
||||
server_domain_name = strdup(domain_name);
|
||||
server_domain_name_len = strlen(domain_name);
|
||||
|
||||
// int mtu = 250;
|
||||
int mtu = 900;
|
||||
|
||||
|
|
@ -505,14 +510,14 @@ int picoquic_slipstream_server(int server_port, const char* server_cert, const c
|
|||
config.server_cert_file = server_cert;
|
||||
config.server_key_file = server_key;
|
||||
// config.log_file = "-";
|
||||
#ifndef BUILD_LOGLIB
|
||||
#ifdef BUILD_LOGLIB
|
||||
config.qlog_dir = SLIPSTREAM_QLOG_DIR;
|
||||
#endif
|
||||
config.server_port = server_port;
|
||||
config.mtu_max = mtu;
|
||||
config.initial_send_mtu_ipv4 = mtu;
|
||||
config.initial_send_mtu_ipv6 = mtu;
|
||||
config.cc_algo_id = "bbr1";
|
||||
config.cc_algo_id = "cubic";
|
||||
config.multipath_option = 0;
|
||||
config.use_long_log = 1;
|
||||
config.do_preemptive_repeat = 1;
|
||||
|
|
@ -544,6 +549,7 @@ int picoquic_slipstream_server(int server_port, const char* server_cert, const c
|
|||
param.is_client = 0;
|
||||
param.decode = server_decode;
|
||||
param.encode = server_encode;
|
||||
// param.delay_max = 1;
|
||||
|
||||
picoquic_network_thread_ctx_t thread_ctx = {0};
|
||||
thread_ctx.quic = quic;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue