Skip to content

Commit

Permalink
1.11.0: [FEATURE] Add support for Q044
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitri Tikhonov committed Aug 15, 2018
1 parent c6457e4 commit 9626cfc
Show file tree
Hide file tree
Showing 34 changed files with 1,157 additions and 279 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2018-08-15

- 1.11.0
- [FEATURE] Add support for Q044.

2018-08-09

- 1.10.2
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ our own products: LiteSpeed Web Server and ADC. We think it is free of
major problems. Nevertheless, do not hesitate to report bugs back to us.
Even better, send us fixes and improvements!

Currently supported QUIC versions are Q035, Q039, and Q043. Support for
newer versions will be added soon after they are released. The version(s)
specified by IETF QUIC WG will be added once the IETF version of the
protocol settles down a little.
Currently supported QUIC versions are Q035, Q039, Q043, and Q044. Support
for newer versions will be added soon after they are released. The
version(s) specified by IETF QUIC WG will be added once the IETF version
of the protocol settles down a little.

Documentation
-------------
Expand Down
37 changes: 31 additions & 6 deletions include/lsquic.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ extern "C" {
#endif

#define LSQUIC_MAJOR_VERSION 1
#define LSQUIC_MINOR_VERSION 10
#define LSQUIC_PATCH_VERSION 2
#define LSQUIC_MINOR_VERSION 11
#define LSQUIC_PATCH_VERSION 0

/**
* Engine flags:
Expand Down Expand Up @@ -97,23 +97,45 @@ enum lsquic_version
*/
LSQVER_043,

/**
* Q044. IETF-like packet headers are used. Frames are the same as
* in Q043. Server never includes CIDs in short packets.
*/
LSQVER_044,

#if LSQUIC_USE_Q098
/**
* Q098. This is a made-up, experimental version used to test version
* negotiation. The choice of 98 is similar to Google's choice of 99
* as the "IETF" version.
*/
LSQVER_098,
#define LSQUIC_EXPERIMENTAL_Q098 (1 << LSQVER_098)
#else
#define LSQUIC_EXPERIMENTAL_Q098 0
#endif

N_LSQVER
};

/**
* We currently support versions 35, 39, and 43.
* We currently support versions 35, 39, 43, and 44.
* @see lsquic_version
*/
#define LSQUIC_SUPPORTED_VERSIONS ((1 << N_LSQVER) - 1)

#define LSQUIC_EXPERIMENTAL_VERSIONS 0
#define LSQUIC_EXPERIMENTAL_VERSIONS (0 \
| LSQUIC_EXPERIMENTAL_Q098)

#define LSQUIC_DEPRECATED_VERSIONS 0

#define LSQUIC_GQUIC_HEADER_VERSIONS ( \
(1 << LSQVER_035) | (1 << LSQVER_039) | (1 << LSQVER_043))

/**
* List of version in which the server does not include CID in short packets.
* List of versions in which the server never includes CID in short packets.
*/
#define LSQUIC_FORCED_TCID0_VERSIONS 0
#define LSQUIC_FORCED_TCID0_VERSIONS (1 << LSQVER_044)

/**
* @struct lsquic_stream_if
Expand Down Expand Up @@ -330,6 +352,9 @@ struct lsquic_engine_settings {
* (source-addr, dest-addr) tuple, thereby making it necessary to create
* a socket for each connection.
*
* This option has no effect in Q044, as the server never includes CIDs
* in the short packets.
*
* The default is @ref LSQUIC_DF_SUPPORT_TCID0.
*/
int es_support_tcid0;
Expand Down
3 changes: 3 additions & 0 deletions src/liblsquic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ SET(lsquic_STAT_SRCS
lsquic_chsk_stream.c
lsquic_engine.c
lsquic_parse_gquic_common.c
lsquic_parse_iquic_common.c
lsquic_parse_common.c
lsquic_parse_gquic_le.c
lsquic_parse_gquic_be.c
lsquic_packet_in.c
Expand Down Expand Up @@ -50,6 +52,7 @@ SET(lsquic_STAT_SRCS
lsquic_buf.c
lsquic_min_heap.c
lshpack.c
lsquic_parse_Q044.c
)


Expand Down
23 changes: 23 additions & 0 deletions src/liblsquic/lsquic_byteswap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright (c) 2017 - 2018 LiteSpeed Technologies Inc. See LICENSE. */
#ifndef LSQUIC_BYTESWAP_H
#define LSQUIC_BYTESWAP_H 1

#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__)
#include <sys/endian.h>
#define bswap_16 bswap16
#define bswap_32 bswap32
#define bswap_64 bswap64
#elif defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#define bswap_16 OSSwapInt16
#define bswap_32 OSSwapInt32
#define bswap_64 OSSwapInt64
#elif defined(WIN32)
#define bswap_16 _byteswap_ushort
#define bswap_32 _byteswap_ulong
#define bswap_64 _byteswap_uint64
#else
#include <byteswap.h>
#endif

#endif
4 changes: 2 additions & 2 deletions src/liblsquic/lsquic_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ lsquic_conn_decrypt_packet (lsquic_conn_t *lconn,
| (enc_level << PIBIT_ENC_LEV_SHIFT);
packet_in->pi_header_sz = header_len;
packet_in->pi_data_sz = out_len + header_len;
EV_LOG_CONN_EVENT(lconn->cn_cid, "decrypted packet %"PRIu64,
packet_in->pi_packno);
EV_LOG_CONN_EVENT(lconn->cn_cid, "decrypted packet %"PRIu64" crypto: %s",
packet_in->pi_packno, lsquic_enclev2str[ enc_level ]);
return 0;
}

Expand Down
68 changes: 43 additions & 25 deletions src/liblsquic/lsquic_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "lsquic.h"
#include "lsquic_types.h"
#include "lsquic_alarmset.h"
#include "lsquic_parse_common.h"
#include "lsquic_parse.h"
#include "lsquic_packet_in.h"
#include "lsquic_packet_out.h"
Expand Down Expand Up @@ -261,6 +262,18 @@ static const struct lsquic_packout_mem_if stock_pmi =
};


static int
hash_conns_by_addr (const struct lsquic_engine *engine)
{
if (engine->pub.enp_settings.es_versions & LSQUIC_FORCED_TCID0_VERSIONS)
return 1;
if ((engine->pub.enp_settings.es_versions & LSQUIC_GQUIC_HEADER_VERSIONS)
&& engine->pub.enp_settings.es_support_tcid0)
return 1;
return 0;
}


lsquic_engine_t *
lsquic_engine_new (unsigned flags,
const struct lsquic_engine_api *api)
Expand Down Expand Up @@ -295,7 +308,7 @@ lsquic_engine_new (unsigned flags,
engine->pub.enp_settings = *api->ea_settings;
else
lsquic_engine_init_settings(&engine->pub.enp_settings, flags);
tag_buf_len = gen_ver_tags(engine->pub.enp_ver_tags_buf,
tag_buf_len = lsquic_gen_ver_tags(engine->pub.enp_ver_tags_buf,
sizeof(engine->pub.enp_ver_tags_buf),
engine->pub.enp_settings.es_versions);
if (tag_buf_len <= 0)
Expand Down Expand Up @@ -324,8 +337,7 @@ lsquic_engine_new (unsigned flags,
}
engine->pub.enp_engine = engine;
conn_hash_init(&engine->conns_hash,
!(flags & ENG_SERVER) && engine->pub.enp_settings.es_support_tcid0 ?
CHF_USE_ADDR : 0);
hash_conns_by_addr(engine) ? CHF_USE_ADDR : 0);
engine->attq = attq_create();
eng_hist_init(&engine->history);
engine->batch_size = INITIAL_OUT_BATCH_SIZE;
Expand Down Expand Up @@ -498,7 +510,7 @@ process_packet_in (lsquic_engine_t *engine, lsquic_packet_in_t *packet_in,
{
lsquic_conn_t *conn;

if (lsquic_packet_in_is_prst(packet_in)
if (lsquic_packet_in_is_gquic_prst(packet_in)
&& !engine->pub.enp_settings.es_honor_prst)
{
lsquic_mm_put_packet_in(&engine->pub.enp_mm, packet_in);
Expand Down Expand Up @@ -758,44 +770,34 @@ lsquic_engine_process_conns (lsquic_engine_t *engine)
}


static int
generate_header (const lsquic_packet_out_t *packet_out,
const struct parse_funcs *pf, lsquic_cid_t cid,
unsigned char *buf, size_t bufsz)
{
return pf->pf_gen_reg_pkt_header(buf, bufsz,
packet_out->po_flags & PO_CONN_ID ? &cid : NULL,
packet_out->po_flags & PO_VERSION ? &packet_out->po_ver_tag : NULL,
packet_out->po_flags & PO_NONCE ? packet_out->po_nonce : NULL,
packet_out->po_packno, lsquic_packet_out_packno_bits(packet_out));
}


static ssize_t
really_encrypt_packet (const lsquic_conn_t *conn,
const lsquic_packet_out_t *packet_out,
struct lsquic_packet_out *packet_out,
unsigned char *buf, size_t bufsz)
{
int enc, header_sz, is_hello_packet;
int header_sz, is_hello_packet;
enum enc_level enc_level;
size_t packet_sz;
unsigned char header_buf[QUIC_MAX_PUBHDR_SZ];

header_sz = generate_header(packet_out, conn->cn_pf, conn->cn_cid,
header_sz = conn->cn_pf->pf_gen_reg_pkt_header(conn, packet_out,
header_buf, sizeof(header_buf));
if (header_sz < 0)
return -1;

is_hello_packet = !!(packet_out->po_flags & PO_HELLO);
enc = conn->cn_esf->esf_encrypt(conn->cn_enc_session, conn->cn_version, 0,
enc_level = conn->cn_esf->esf_encrypt(conn->cn_enc_session,
conn->cn_version, 0,
packet_out->po_packno, header_buf, header_sz,
packet_out->po_data, packet_out->po_data_sz,
buf, bufsz, &packet_sz, is_hello_packet);
if (0 == enc)
if ((int) enc_level >= 0)
{
LSQ_DEBUG("encrypted packet %"PRIu64"; plaintext is %u bytes, "
lsquic_packet_out_set_enc_level(packet_out, enc_level);
LSQ_DEBUG("encrypted packet %"PRIu64"; plaintext is %zu bytes, "
"ciphertext is %zd bytes",
packet_out->po_packno,
lsquic_po_header_length(packet_out->po_flags) +
conn->cn_pf->pf_packout_header_size(conn, packet_out->po_flags) +
packet_out->po_data_sz,
packet_sz);
return packet_sz;
Expand All @@ -814,7 +816,7 @@ encrypt_packet (lsquic_engine_t *engine, const lsquic_conn_t *conn,
unsigned sent_sz;
unsigned char *buf;

bufsz = lsquic_po_header_length(packet_out->po_flags) +
bufsz = conn->cn_pf->pf_packout_header_size(conn, packet_out->po_flags) +
packet_out->po_data_sz + QUIC_PACKET_HASH_SZ;
buf = engine->pub.enp_pmi->pmi_allocate(engine->pub.enp_pmi_ctx, bufsz);
if (!buf)
Expand Down Expand Up @@ -1281,6 +1283,8 @@ lsquic_engine_packet_in (lsquic_engine_t *engine,
{
struct packin_parse_state ppstate;
lsquic_packet_in_t *packet_in;
int (*parse_packet_in_begin) (struct lsquic_packet_in *, size_t length,
int is_server, struct packin_parse_state *);

if (packet_in_size > QUIC_MAX_PACKET_SZ)
{
Expand All @@ -1290,6 +1294,20 @@ lsquic_engine_packet_in (lsquic_engine_t *engine,
return -1;
}

if (conn_hash_using_addr(&engine->conns_hash))
{
const struct lsquic_conn *conn;
conn = conn_hash_find_by_addr(&engine->conns_hash, sa_local);
if (!conn)
return -1;
if ((1 << conn->cn_version) & LSQUIC_GQUIC_HEADER_VERSIONS)
parse_packet_in_begin = lsquic_gquic_parse_packet_in_begin;
else
parse_packet_in_begin = lsquic_iquic_parse_packet_in_begin;
}
else
parse_packet_in_begin = lsquic_parse_packet_in_begin;

packet_in = lsquic_mm_get_packet_in(&engine->pub.enp_mm);
if (!packet_in)
return -1;
Expand Down
28 changes: 26 additions & 2 deletions src/liblsquic/lsquic_ev_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "lsquic_parse.h"
#include "lsquic_frame_common.h"
#include "lsquic_frame_reader.h"
#include "lsquic_str.h"
#include "lsquic_handshake.h"
#include "lsquic_ev_log.h"

#define LSQUIC_LOGGER_MODULE LSQLM_EVENT
Expand All @@ -39,7 +41,17 @@
void
lsquic_ev_log_packet_in (lsquic_cid_t cid, const lsquic_packet_in_t *packet_in)
{
LCID("packet in: %"PRIu64, packet_in->pi_packno);
switch (packet_in->pi_flags & (
PI_GQUIC))
{
case PI_GQUIC:
LCID("packet in: %"PRIu64, packet_in->pi_packno);
break;
default:
LCID("packet in: %"PRIu64", type: %s",
packet_in->pi_packno, lsquic_hety2str[packet_in->pi_header_type]);
break;
}
}


Expand Down Expand Up @@ -153,7 +165,7 @@ lsquic_ev_log_packet_sent (lsquic_cid_t cid,
packet_out->po_data_sz);
else if (lsquic_packet_out_pubres(packet_out))
LCID("sent public reset packet, size %hu", packet_out->po_data_sz);
else
else if (packet_out->po_flags & PO_GQUIC)
LCID("sent packet %"PRIu64", size %hu, frame types: %s",
packet_out->po_packno, packet_out->po_enc_data_sz,
/* Frame types is a list of different frames types contained
Expand All @@ -162,6 +174,18 @@ lsquic_ev_log_packet_sent (lsquic_cid_t cid,
*/
lsquic_frame_types_to_str(frames, sizeof(frames),
packet_out->po_frame_types));
else
LCID("sent packet %"PRIu64", type %s, crypto: %s, size %hu, frame "
"types: %s",
packet_out->po_packno, lsquic_hety2str[packet_out->po_header_type],
lsquic_enclev2str[ lsquic_packet_out_enc_level(packet_out) ],
packet_out->po_enc_data_sz,
/* Frame types is a list of different frames types contained
* in the packet, no more. Count and order of frames is not
* printed.
*/
lsquic_frame_types_to_str(frames, sizeof(frames),
packet_out->po_frame_types));
}


Expand Down
Loading

0 comments on commit 9626cfc

Please sign in to comment.