Skip to content

Commit 9626cfc

Browse files
author
Dmitri Tikhonov
committed
1.11.0: [FEATURE] Add support for Q044
1 parent c6457e4 commit 9626cfc

34 files changed

+1157
-279
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-08-15
2+
3+
- 1.11.0
4+
- [FEATURE] Add support for Q044.
5+
16
2018-08-09
27

38
- 1.10.2

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ our own products: LiteSpeed Web Server and ADC. We think it is free of
1313
major problems. Nevertheless, do not hesitate to report bugs back to us.
1414
Even better, send us fixes and improvements!
1515

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

2121
Documentation
2222
-------------

include/lsquic.h

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ extern "C" {
2424
#endif
2525

2626
#define LSQUIC_MAJOR_VERSION 1
27-
#define LSQUIC_MINOR_VERSION 10
28-
#define LSQUIC_PATCH_VERSION 2
27+
#define LSQUIC_MINOR_VERSION 11
28+
#define LSQUIC_PATCH_VERSION 0
2929

3030
/**
3131
* Engine flags:
@@ -97,23 +97,45 @@ enum lsquic_version
9797
*/
9898
LSQVER_043,
9999

100+
/**
101+
* Q044. IETF-like packet headers are used. Frames are the same as
102+
* in Q043. Server never includes CIDs in short packets.
103+
*/
104+
LSQVER_044,
105+
106+
#if LSQUIC_USE_Q098
107+
/**
108+
* Q098. This is a made-up, experimental version used to test version
109+
* negotiation. The choice of 98 is similar to Google's choice of 99
110+
* as the "IETF" version.
111+
*/
112+
LSQVER_098,
113+
#define LSQUIC_EXPERIMENTAL_Q098 (1 << LSQVER_098)
114+
#else
115+
#define LSQUIC_EXPERIMENTAL_Q098 0
116+
#endif
117+
100118
N_LSQVER
101119
};
102120

103121
/**
104-
* We currently support versions 35, 39, and 43.
122+
* We currently support versions 35, 39, 43, and 44.
105123
* @see lsquic_version
106124
*/
107125
#define LSQUIC_SUPPORTED_VERSIONS ((1 << N_LSQVER) - 1)
108126

109-
#define LSQUIC_EXPERIMENTAL_VERSIONS 0
127+
#define LSQUIC_EXPERIMENTAL_VERSIONS (0 \
128+
| LSQUIC_EXPERIMENTAL_Q098)
110129

111130
#define LSQUIC_DEPRECATED_VERSIONS 0
112131

132+
#define LSQUIC_GQUIC_HEADER_VERSIONS ( \
133+
(1 << LSQVER_035) | (1 << LSQVER_039) | (1 << LSQVER_043))
134+
113135
/**
114-
* List of version in which the server does not include CID in short packets.
136+
* List of versions in which the server never includes CID in short packets.
115137
*/
116-
#define LSQUIC_FORCED_TCID0_VERSIONS 0
138+
#define LSQUIC_FORCED_TCID0_VERSIONS (1 << LSQVER_044)
117139

118140
/**
119141
* @struct lsquic_stream_if
@@ -330,6 +352,9 @@ struct lsquic_engine_settings {
330352
* (source-addr, dest-addr) tuple, thereby making it necessary to create
331353
* a socket for each connection.
332354
*
355+
* This option has no effect in Q044, as the server never includes CIDs
356+
* in the short packets.
357+
*
333358
* The default is @ref LSQUIC_DF_SUPPORT_TCID0.
334359
*/
335360
int es_support_tcid0;

src/liblsquic/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ SET(lsquic_STAT_SRCS
66
lsquic_chsk_stream.c
77
lsquic_engine.c
88
lsquic_parse_gquic_common.c
9+
lsquic_parse_iquic_common.c
10+
lsquic_parse_common.c
911
lsquic_parse_gquic_le.c
1012
lsquic_parse_gquic_be.c
1113
lsquic_packet_in.c
@@ -50,6 +52,7 @@ SET(lsquic_STAT_SRCS
5052
lsquic_buf.c
5153
lsquic_min_heap.c
5254
lshpack.c
55+
lsquic_parse_Q044.c
5356
)
5457

5558

src/liblsquic/lsquic_byteswap.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* Copyright (c) 2017 - 2018 LiteSpeed Technologies Inc. See LICENSE. */
2+
#ifndef LSQUIC_BYTESWAP_H
3+
#define LSQUIC_BYTESWAP_H 1
4+
5+
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__)
6+
#include <sys/endian.h>
7+
#define bswap_16 bswap16
8+
#define bswap_32 bswap32
9+
#define bswap_64 bswap64
10+
#elif defined(__APPLE__)
11+
#include <libkern/OSByteOrder.h>
12+
#define bswap_16 OSSwapInt16
13+
#define bswap_32 OSSwapInt32
14+
#define bswap_64 OSSwapInt64
15+
#elif defined(WIN32)
16+
#define bswap_16 _byteswap_ushort
17+
#define bswap_32 _byteswap_ulong
18+
#define bswap_64 _byteswap_uint64
19+
#else
20+
#include <byteswap.h>
21+
#endif
22+
23+
#endif

src/liblsquic/lsquic_conn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ lsquic_conn_decrypt_packet (lsquic_conn_t *lconn,
126126
| (enc_level << PIBIT_ENC_LEV_SHIFT);
127127
packet_in->pi_header_sz = header_len;
128128
packet_in->pi_data_sz = out_len + header_len;
129-
EV_LOG_CONN_EVENT(lconn->cn_cid, "decrypted packet %"PRIu64,
130-
packet_in->pi_packno);
129+
EV_LOG_CONN_EVENT(lconn->cn_cid, "decrypted packet %"PRIu64" crypto: %s",
130+
packet_in->pi_packno, lsquic_enclev2str[ enc_level ]);
131131
return 0;
132132
}
133133

src/liblsquic/lsquic_engine.c

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "lsquic.h"
2828
#include "lsquic_types.h"
2929
#include "lsquic_alarmset.h"
30+
#include "lsquic_parse_common.h"
3031
#include "lsquic_parse.h"
3132
#include "lsquic_packet_in.h"
3233
#include "lsquic_packet_out.h"
@@ -261,6 +262,18 @@ static const struct lsquic_packout_mem_if stock_pmi =
261262
};
262263

263264

265+
static int
266+
hash_conns_by_addr (const struct lsquic_engine *engine)
267+
{
268+
if (engine->pub.enp_settings.es_versions & LSQUIC_FORCED_TCID0_VERSIONS)
269+
return 1;
270+
if ((engine->pub.enp_settings.es_versions & LSQUIC_GQUIC_HEADER_VERSIONS)
271+
&& engine->pub.enp_settings.es_support_tcid0)
272+
return 1;
273+
return 0;
274+
}
275+
276+
264277
lsquic_engine_t *
265278
lsquic_engine_new (unsigned flags,
266279
const struct lsquic_engine_api *api)
@@ -295,7 +308,7 @@ lsquic_engine_new (unsigned flags,
295308
engine->pub.enp_settings = *api->ea_settings;
296309
else
297310
lsquic_engine_init_settings(&engine->pub.enp_settings, flags);
298-
tag_buf_len = gen_ver_tags(engine->pub.enp_ver_tags_buf,
311+
tag_buf_len = lsquic_gen_ver_tags(engine->pub.enp_ver_tags_buf,
299312
sizeof(engine->pub.enp_ver_tags_buf),
300313
engine->pub.enp_settings.es_versions);
301314
if (tag_buf_len <= 0)
@@ -324,8 +337,7 @@ lsquic_engine_new (unsigned flags,
324337
}
325338
engine->pub.enp_engine = engine;
326339
conn_hash_init(&engine->conns_hash,
327-
!(flags & ENG_SERVER) && engine->pub.enp_settings.es_support_tcid0 ?
328-
CHF_USE_ADDR : 0);
340+
hash_conns_by_addr(engine) ? CHF_USE_ADDR : 0);
329341
engine->attq = attq_create();
330342
eng_hist_init(&engine->history);
331343
engine->batch_size = INITIAL_OUT_BATCH_SIZE;
@@ -498,7 +510,7 @@ process_packet_in (lsquic_engine_t *engine, lsquic_packet_in_t *packet_in,
498510
{
499511
lsquic_conn_t *conn;
500512

501-
if (lsquic_packet_in_is_prst(packet_in)
513+
if (lsquic_packet_in_is_gquic_prst(packet_in)
502514
&& !engine->pub.enp_settings.es_honor_prst)
503515
{
504516
lsquic_mm_put_packet_in(&engine->pub.enp_mm, packet_in);
@@ -758,44 +770,34 @@ lsquic_engine_process_conns (lsquic_engine_t *engine)
758770
}
759771

760772

761-
static int
762-
generate_header (const lsquic_packet_out_t *packet_out,
763-
const struct parse_funcs *pf, lsquic_cid_t cid,
764-
unsigned char *buf, size_t bufsz)
765-
{
766-
return pf->pf_gen_reg_pkt_header(buf, bufsz,
767-
packet_out->po_flags & PO_CONN_ID ? &cid : NULL,
768-
packet_out->po_flags & PO_VERSION ? &packet_out->po_ver_tag : NULL,
769-
packet_out->po_flags & PO_NONCE ? packet_out->po_nonce : NULL,
770-
packet_out->po_packno, lsquic_packet_out_packno_bits(packet_out));
771-
}
772-
773-
774773
static ssize_t
775774
really_encrypt_packet (const lsquic_conn_t *conn,
776-
const lsquic_packet_out_t *packet_out,
775+
struct lsquic_packet_out *packet_out,
777776
unsigned char *buf, size_t bufsz)
778777
{
779-
int enc, header_sz, is_hello_packet;
778+
int header_sz, is_hello_packet;
779+
enum enc_level enc_level;
780780
size_t packet_sz;
781781
unsigned char header_buf[QUIC_MAX_PUBHDR_SZ];
782782

783-
header_sz = generate_header(packet_out, conn->cn_pf, conn->cn_cid,
783+
header_sz = conn->cn_pf->pf_gen_reg_pkt_header(conn, packet_out,
784784
header_buf, sizeof(header_buf));
785785
if (header_sz < 0)
786786
return -1;
787787

788788
is_hello_packet = !!(packet_out->po_flags & PO_HELLO);
789-
enc = conn->cn_esf->esf_encrypt(conn->cn_enc_session, conn->cn_version, 0,
789+
enc_level = conn->cn_esf->esf_encrypt(conn->cn_enc_session,
790+
conn->cn_version, 0,
790791
packet_out->po_packno, header_buf, header_sz,
791792
packet_out->po_data, packet_out->po_data_sz,
792793
buf, bufsz, &packet_sz, is_hello_packet);
793-
if (0 == enc)
794+
if ((int) enc_level >= 0)
794795
{
795-
LSQ_DEBUG("encrypted packet %"PRIu64"; plaintext is %u bytes, "
796+
lsquic_packet_out_set_enc_level(packet_out, enc_level);
797+
LSQ_DEBUG("encrypted packet %"PRIu64"; plaintext is %zu bytes, "
796798
"ciphertext is %zd bytes",
797799
packet_out->po_packno,
798-
lsquic_po_header_length(packet_out->po_flags) +
800+
conn->cn_pf->pf_packout_header_size(conn, packet_out->po_flags) +
799801
packet_out->po_data_sz,
800802
packet_sz);
801803
return packet_sz;
@@ -814,7 +816,7 @@ encrypt_packet (lsquic_engine_t *engine, const lsquic_conn_t *conn,
814816
unsigned sent_sz;
815817
unsigned char *buf;
816818

817-
bufsz = lsquic_po_header_length(packet_out->po_flags) +
819+
bufsz = conn->cn_pf->pf_packout_header_size(conn, packet_out->po_flags) +
818820
packet_out->po_data_sz + QUIC_PACKET_HASH_SZ;
819821
buf = engine->pub.enp_pmi->pmi_allocate(engine->pub.enp_pmi_ctx, bufsz);
820822
if (!buf)
@@ -1281,6 +1283,8 @@ lsquic_engine_packet_in (lsquic_engine_t *engine,
12811283
{
12821284
struct packin_parse_state ppstate;
12831285
lsquic_packet_in_t *packet_in;
1286+
int (*parse_packet_in_begin) (struct lsquic_packet_in *, size_t length,
1287+
int is_server, struct packin_parse_state *);
12841288

12851289
if (packet_in_size > QUIC_MAX_PACKET_SZ)
12861290
{
@@ -1290,6 +1294,20 @@ lsquic_engine_packet_in (lsquic_engine_t *engine,
12901294
return -1;
12911295
}
12921296

1297+
if (conn_hash_using_addr(&engine->conns_hash))
1298+
{
1299+
const struct lsquic_conn *conn;
1300+
conn = conn_hash_find_by_addr(&engine->conns_hash, sa_local);
1301+
if (!conn)
1302+
return -1;
1303+
if ((1 << conn->cn_version) & LSQUIC_GQUIC_HEADER_VERSIONS)
1304+
parse_packet_in_begin = lsquic_gquic_parse_packet_in_begin;
1305+
else
1306+
parse_packet_in_begin = lsquic_iquic_parse_packet_in_begin;
1307+
}
1308+
else
1309+
parse_packet_in_begin = lsquic_parse_packet_in_begin;
1310+
12931311
packet_in = lsquic_mm_get_packet_in(&engine->pub.enp_mm);
12941312
if (!packet_in)
12951313
return -1;

src/liblsquic/lsquic_ev_log.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "lsquic_parse.h"
2020
#include "lsquic_frame_common.h"
2121
#include "lsquic_frame_reader.h"
22+
#include "lsquic_str.h"
23+
#include "lsquic_handshake.h"
2224
#include "lsquic_ev_log.h"
2325

2426
#define LSQUIC_LOGGER_MODULE LSQLM_EVENT
@@ -39,7 +41,17 @@
3941
void
4042
lsquic_ev_log_packet_in (lsquic_cid_t cid, const lsquic_packet_in_t *packet_in)
4143
{
42-
LCID("packet in: %"PRIu64, packet_in->pi_packno);
44+
switch (packet_in->pi_flags & (
45+
PI_GQUIC))
46+
{
47+
case PI_GQUIC:
48+
LCID("packet in: %"PRIu64, packet_in->pi_packno);
49+
break;
50+
default:
51+
LCID("packet in: %"PRIu64", type: %s",
52+
packet_in->pi_packno, lsquic_hety2str[packet_in->pi_header_type]);
53+
break;
54+
}
4355
}
4456

4557

@@ -153,7 +165,7 @@ lsquic_ev_log_packet_sent (lsquic_cid_t cid,
153165
packet_out->po_data_sz);
154166
else if (lsquic_packet_out_pubres(packet_out))
155167
LCID("sent public reset packet, size %hu", packet_out->po_data_sz);
156-
else
168+
else if (packet_out->po_flags & PO_GQUIC)
157169
LCID("sent packet %"PRIu64", size %hu, frame types: %s",
158170
packet_out->po_packno, packet_out->po_enc_data_sz,
159171
/* Frame types is a list of different frames types contained
@@ -162,6 +174,18 @@ lsquic_ev_log_packet_sent (lsquic_cid_t cid,
162174
*/
163175
lsquic_frame_types_to_str(frames, sizeof(frames),
164176
packet_out->po_frame_types));
177+
else
178+
LCID("sent packet %"PRIu64", type %s, crypto: %s, size %hu, frame "
179+
"types: %s",
180+
packet_out->po_packno, lsquic_hety2str[packet_out->po_header_type],
181+
lsquic_enclev2str[ lsquic_packet_out_enc_level(packet_out) ],
182+
packet_out->po_enc_data_sz,
183+
/* Frame types is a list of different frames types contained
184+
* in the packet, no more. Count and order of frames is not
185+
* printed.
186+
*/
187+
lsquic_frame_types_to_str(frames, sizeof(frames),
188+
packet_out->po_frame_types));
165189
}
166190

167191

0 commit comments

Comments
 (0)