Skip to content

Commit

Permalink
daemon: fix DoH truncation and tasklist addition
Browse files Browse the repository at this point in the history
  • Loading branch information
Oto Šťáva committed Jan 26, 2023
1 parent d26843c commit 55515df
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 47 deletions.
6 changes: 3 additions & 3 deletions daemon/session2.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ static enum protolayer_protocol protolayer_grp_doudp[] = {

static enum protolayer_protocol protolayer_grp_dotcp[] = {
PROTOLAYER_TCP,
PROTOLAYER_DNS_MSTREAM,
PROTOLAYER_DNS_MULTI_STREAM,
PROTOLAYER_NULL
};

static enum protolayer_protocol protolayer_grp_dot[] = {
PROTOLAYER_TCP,
PROTOLAYER_TLS,
PROTOLAYER_DNS_MSTREAM,
PROTOLAYER_DNS_MULTI_STREAM,
PROTOLAYER_NULL
};

static enum protolayer_protocol protolayer_grp_doh[] = {
PROTOLAYER_TCP,
PROTOLAYER_TLS,
PROTOLAYER_HTTP,
PROTOLAYER_DNS_DGRAM,
PROTOLAYER_DNS_UNSIZED_STREAM,
PROTOLAYER_NULL
};

Expand Down
24 changes: 13 additions & 11 deletions daemon/session2.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,21 @@ struct comm_info {
* processed. See `PROTOLAYER_GRP_MAP` below for more details. */
#define PROTOLAYER_PROTOCOL_MAP(XX) \
/* General transport protocols */\
XX(UDP) \
XX(TCP) \
XX(TLS) \
XX(HTTP) \
\
/* QUIC (not yet implemented) */\
XX(UDP_TO_QCONN)\
XX(QCONN_TO_QSTREAM)\
XX(UDP)\
XX(TCP)\
XX(TLS)\
XX(HTTP)\
\
/* DNS (`worker`) */\
XX(DNS_DGRAM)\
XX(DNS_MSTREAM)\
XX(DNS_SSTREAM)
XX(DNS_DGRAM) /**< Packets WITHOUT prepended size, one per (un)wrap,
* limited to UDP sizes, multiple sources (single
* session for multiple clients). */\
XX(DNS_UNSIZED_STREAM) /**< Singular packet WITHOUT prepended size, one
* per (un)wrap, no UDP limits, single source. */\
XX(DNS_MULTI_STREAM) /**< Multiple packets WITH prepended sizes in a
* stream (may span multiple (un)wraps). */\
XX(DNS_SINGLE_STREAM) /**< Singular packet WITH prepended size in a
* stream (may span multiple (un)wraps). */

/** The identifiers of protocol layer types. */
enum protolayer_protocol {
Expand Down
51 changes: 18 additions & 33 deletions daemon/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -1938,40 +1938,21 @@ struct pl_dns_stream_iter_data {
} sent;
};

static void pl_dns_stream_sess_init_common(struct session2 *session,
struct pl_dns_stream_sess_data *stream,
bool single)
static int pl_dns_stream_sess_init(struct protolayer_manager *manager,
void *sess_data, void *param)
{
session->stream = true;
*stream = (struct pl_dns_stream_sess_data){
.single = single
};
}

static int pl_dns_mstream_sess_init(struct protolayer_manager *manager,
void *sess_data,
void *param)
{
struct pl_dns_stream_sess_data *stream = sess_data;
pl_dns_stream_sess_init_common(manager->session, stream, false);
/* _UNSIZED_STREAM and _MULTI_STREAM - don't forget to split if needed
* at some point */
manager->session->stream = true;
return kr_ok();
}

static int pl_dns_sstream_sess_init(struct protolayer_manager *manager,
void *sess_data,
void *param)
static int pl_dns_single_stream_sess_init(struct protolayer_manager *manager,
void *sess_data, void *param)
{
manager->session->stream = true;
struct pl_dns_stream_sess_data *stream = sess_data;
pl_dns_stream_sess_init_common(manager->session, stream, true);
return kr_ok();
}

static int pl_dns_stream_iter_init(struct protolayer_manager *manager,
struct protolayer_iter_ctx *ctx,
void *iter_data)
{
struct pl_dns_stream_iter_data *stream = iter_data;
*stream = (struct pl_dns_stream_iter_data){0};
stream->single = true;
return kr_ok();
}

Expand Down Expand Up @@ -2320,20 +2301,24 @@ int worker_init(void)
.unwrap = pl_dns_dgram_unwrap,
.event_unwrap = pl_dns_dgram_event_unwrap
};
protolayer_globals[PROTOLAYER_DNS_UNSIZED_STREAM] = (struct protolayer_globals){
.sess_init = pl_dns_stream_sess_init,
.unwrap = pl_dns_dgram_unwrap,
.event_unwrap = pl_dns_stream_event_unwrap
};
const struct protolayer_globals stream_common = {
.sess_size = sizeof(struct pl_dns_stream_sess_data),
.sess_init = NULL, /* replaced in specific layers below */
.iter_size = sizeof(struct pl_dns_stream_iter_data),
.iter_init = pl_dns_stream_iter_init,
.iter_deinit = pl_dns_stream_iter_deinit,
.unwrap = pl_dns_stream_unwrap,
.wrap = pl_dns_stream_wrap,
.event_unwrap = pl_dns_stream_event_unwrap
};
protolayer_globals[PROTOLAYER_DNS_MSTREAM] = stream_common;
protolayer_globals[PROTOLAYER_DNS_MSTREAM].sess_init = pl_dns_mstream_sess_init;
protolayer_globals[PROTOLAYER_DNS_SSTREAM] = stream_common;
protolayer_globals[PROTOLAYER_DNS_SSTREAM].sess_init = pl_dns_sstream_sess_init;
protolayer_globals[PROTOLAYER_DNS_MULTI_STREAM] = stream_common;
protolayer_globals[PROTOLAYER_DNS_MULTI_STREAM].sess_init = pl_dns_stream_sess_init;
protolayer_globals[PROTOLAYER_DNS_SINGLE_STREAM] = stream_common;
protolayer_globals[PROTOLAYER_DNS_SINGLE_STREAM].sess_init = pl_dns_single_stream_sess_init;

/* Create main worker. */
the_worker = &the_worker_value;
Expand Down

0 comments on commit 55515df

Please sign in to comment.