GSO-Friendly Packet Memory (#175)

This commit is contained in:
Victor Stewart 2020-10-03 06:48:01 +01:00 committed by GitHub
parent 2f4629f27d
commit fecdd10417
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 19 additions and 60 deletions

View File

@ -2043,7 +2043,7 @@ pba_init (struct packout_buf_allocator *pba, unsigned max)
void *
pba_allocate (void *packout_buf_allocator, void *peer_ctx, unsigned short size,
pba_allocate (void *packout_buf_allocator, void *peer_ctx, void *conn_ctx, unsigned short size,
char is_ipv6)
{
struct packout_buf_allocator *const pba = packout_buf_allocator;

View File

@ -115,7 +115,7 @@ void
pba_init (struct packout_buf_allocator *, unsigned max);
void *
pba_allocate (void *packout_buf_allocator, void*, unsigned short, char);
pba_allocate (void *packout_buf_allocator, void*, void *conn_ctx, unsigned short, char);
void
pba_release (void *packout_buf_allocator, void *, void *obj, char);

View File

@ -2016,7 +2016,7 @@ Miscellaneous Types
If not specified, malloc() and free() are used.
.. member:: void * (*pmi_allocate) (void *pmi_ctx, void *peer_ctx, unsigned short sz, char is_ipv6)
.. member:: void * (*pmi_allocate) (void *pmi_ctx, void *peer_ctx, lsquic_conn_get_ctx *conn_ctx, unsigned short sz, char is_ipv6)
Allocate buffer for sending.

View File

@ -974,7 +974,8 @@ struct lsquic_out_spec
const struct sockaddr *local_sa;
const struct sockaddr *dest_sa;
void *peer_ctx;
int ecn; /* Valid values are 0 - 3. See RFC 3168 */
lsquic_conn_ctx_t *conn_ctx; /* will be NULL when sending out the first batch of handshake packets */
int ecn; /* Valid values are 0 - 3. See RFC 3168 */
};
/**
@ -1043,7 +1044,7 @@ struct lsquic_packout_mem_if
/**
* Allocate buffer for sending.
*/
void * (*pmi_allocate) (void *pmi_ctx, void *peer_ctx, unsigned short sz,
void * (*pmi_allocate) (void *pmi_ctx, void *peer_ctx, lsquic_conn_ctx_t *, unsigned short sz,
char is_ipv6);
/**
* This function is used to release the allocated buffer after it is

View File

@ -205,14 +205,14 @@ lsquic_conn_push_stream (struct lsquic_conn *lconn, void *hset,
lsquic_conn_ctx_t *
lsquic_conn_get_ctx (const struct lsquic_conn *lconn)
{
return lconn->cn_if->ci_get_ctx(lconn);
return lconn->conn_ctx;
}
void
lsquic_conn_set_ctx (struct lsquic_conn *lconn, lsquic_conn_ctx_t *ctx)
{
lconn->cn_if->ci_set_ctx(lconn, ctx);
lconn->conn_ctx = ctx;
}

View File

@ -178,12 +178,6 @@ struct conn_iface
struct lsquic_engine *
(*ci_get_engine) (struct lsquic_conn *);
struct lsquic_conn_ctx *
(*ci_get_ctx) (const struct lsquic_conn *);
void
(*ci_set_ctx) (struct lsquic_conn *, struct lsquic_conn_ctx *);
void
(*ci_make_stream) (struct lsquic_conn *);
@ -318,6 +312,7 @@ struct conn_cid_elem
struct lsquic_conn
{
void *cn_enc_session;
lsquic_conn_ctx_t *conn_ctx;
const struct enc_session_funcs_common
*cn_esf_c;
union {

View File

@ -1976,7 +1976,7 @@ iquic_esf_encrypt_packet (enc_session_t *enc_session_p,
dst_sz = lconn->cn_pf->pf_packout_size(lconn, packet_out);
ipv6 = NP_IS_IPv6(packet_out->po_path);
dst = enpub->enp_pmi->pmi_allocate(enpub->enp_pmi_ctx,
packet_out->po_path->np_peer_ctx, dst_sz, ipv6);
packet_out->po_path->np_peer_ctx, lconn->conn_ctx, dst_sz, ipv6);
if (!dst)
{
LSQ_DEBUG("could not allocate memory for outgoing packet of size %zd",

View File

@ -467,7 +467,7 @@ free_packet (void *ctx, void *conn_ctx, void *packet_data, char is_ipv6)
static void *
malloc_buf (void *ctx, void *conn_ctx, unsigned short size, char is_ipv6)
malloc_buf (void *ctx, void *peer_ctx, lsquic_conn_ctx_t *conn_ctx, unsigned short size, char is_ipv6)
{
return malloc(size);
}
@ -1969,7 +1969,7 @@ copy_packet (struct lsquic_engine *engine, struct lsquic_conn *conn,
}
packet_out->po_enc_data = engine->pub.enp_pmi->pmi_allocate(
engine->pub.enp_pmi_ctx, packet_out->po_path->np_peer_ctx,
engine->pub.enp_pmi_ctx, packet_out->po_path->np_peer_ctx, conn->conn_ctx,
packet_out->po_data_sz, ipv6);
if (!packet_out->po_enc_data)
{
@ -2477,6 +2477,7 @@ send_packets_out (struct lsquic_engine *engine,
batch->outs [n].peer_ctx = packet_out->po_path->np_peer_ctx;
batch->outs [n].local_sa = NP_LOCAL_SA(packet_out->po_path);
batch->outs [n].dest_sa = NP_PEER_SA(packet_out->po_path);
batch->outs [n].conn_ctx = conn->conn_ctx;
batch->conns [n] = conn;
}
*packet = packet_out;

View File

@ -172,7 +172,6 @@ struct full_conn
const struct lsquic_stream_if *stream_if;
void *stream_if_ctx;
} fc_stream_ifs[N_STREAM_IFS];
lsquic_conn_ctx_t *fc_conn_ctx;
struct lsquic_send_ctl fc_send_ctl;
struct lsquic_conn_public fc_pub;
lsquic_alarmset_t fc_alset;
@ -798,7 +797,7 @@ full_conn_ci_client_call_on_new (struct lsquic_conn *lconn)
{
struct full_conn *const conn = (struct full_conn *) lconn;
assert(conn->fc_flags & FC_CREATED_OK);
conn->fc_conn_ctx = conn->fc_stream_ifs[STREAM_IF_STD].stream_if
lconn->conn_ctx = conn->fc_stream_ifs[STREAM_IF_STD].stream_if
->on_new_conn(conn->fc_stream_ifs[STREAM_IF_STD].stream_if_ctx, lconn);
}
@ -972,7 +971,7 @@ lsquic_gquic_full_conn_server_new (struct lsquic_engine_public *enpub,
lsquic_send_ctl_turn_nstp_on(&conn->fc_send_ctl);
}
LSQ_DEBUG("Calling on_new_conn callback");
conn->fc_conn_ctx = enpub->enp_stream_if->on_new_conn(
lconn_full->conn_ctx = enpub->enp_stream_if->on_new_conn(
enpub->enp_stream_if_ctx, &conn->fc_conn);
/* Now that user code knows about this connection, process incoming
* packets, if any.
@ -4176,22 +4175,6 @@ full_conn_ci_tls_alert (struct lsquic_conn *lconn, uint8_t alert)
}
static struct lsquic_conn_ctx *
full_conn_ci_get_ctx (const struct lsquic_conn *lconn)
{
struct full_conn *const conn = (struct full_conn *) lconn;
return conn->fc_conn_ctx;
}
static void
full_conn_ci_set_ctx (struct lsquic_conn *lconn, lsquic_conn_ctx_t *ctx)
{
struct full_conn *const conn = (struct full_conn *) lconn;
conn->fc_conn_ctx = ctx;
}
static enum LSQUIC_CONN_STATUS
full_conn_ci_status (struct lsquic_conn *lconn, char *errbuf, size_t bufsz)
{
@ -4477,7 +4460,6 @@ static const struct conn_iface full_conn_iface = {
.ci_client_call_on_new = full_conn_ci_client_call_on_new,
.ci_close = full_conn_ci_close,
.ci_destroy = full_conn_ci_destroy,
.ci_get_ctx = full_conn_ci_get_ctx,
.ci_get_stream_by_id = full_conn_ci_get_stream_by_id,
.ci_get_engine = full_conn_ci_get_engine,
.ci_get_path = full_conn_ci_get_path,
@ -4503,7 +4485,6 @@ static const struct conn_iface full_conn_iface = {
* caller when packets come in.
*/
.ci_report_live = NULL,
.ci_set_ctx = full_conn_ci_set_ctx,
.ci_status = full_conn_ci_status,
.ci_tick = full_conn_ci_tick,
.ci_write_ack = full_conn_ci_write_ack,

View File

@ -376,7 +376,6 @@ struct ietf_full_conn
*ifc_enpub;
const struct lsquic_engine_settings
*ifc_settings;
lsquic_conn_ctx_t *ifc_conn_ctx;
STAILQ_HEAD(, stream_id_to_ss)
ifc_stream_ids_to_ss;
lsquic_time_t ifc_created;
@ -1552,7 +1551,7 @@ lsquic_ietf_full_conn_server_new (struct lsquic_engine_public *enpub,
conn->ifc_last_live_update = now;
LSQ_DEBUG("Calling on_new_conn callback");
conn->ifc_conn_ctx = conn->ifc_enpub->enp_stream_if->on_new_conn(
conn->ifc_conn.conn_ctx = conn->ifc_enpub->enp_stream_if->on_new_conn(
conn->ifc_enpub->enp_stream_if_ctx, &conn->ifc_conn);
if (0 != handshake_ok(&conn->ifc_conn))
@ -2761,7 +2760,7 @@ ietf_full_conn_ci_client_call_on_new (struct lsquic_conn *lconn)
{
struct ietf_full_conn *conn = (struct ietf_full_conn *) lconn;
assert(conn->ifc_flags & IFC_CREATED_OK);
conn->ifc_conn_ctx = conn->ifc_enpub->enp_stream_if->on_new_conn(
lconn->conn_ctx = conn->ifc_enpub->enp_stream_if->on_new_conn(
conn->ifc_enpub->enp_stream_if_ctx, lconn);
}
@ -7908,14 +7907,6 @@ ietf_full_conn_ci_stateless_reset (struct lsquic_conn *lconn)
}
static struct lsquic_conn_ctx *
ietf_full_conn_ci_get_ctx (const struct lsquic_conn *lconn)
{
struct ietf_full_conn *const conn = (struct ietf_full_conn *) lconn;
return conn->ifc_conn_ctx;
}
static struct lsquic_engine *
ietf_full_conn_ci_get_engine (struct lsquic_conn *lconn)
{
@ -7924,14 +7915,6 @@ ietf_full_conn_ci_get_engine (struct lsquic_conn *lconn)
}
static void
ietf_full_conn_ci_set_ctx (struct lsquic_conn *lconn, lsquic_conn_ctx_t *ctx)
{
struct ietf_full_conn *const conn = (struct ietf_full_conn *) lconn;
conn->ifc_conn_ctx = ctx;
}
static unsigned
ietf_full_conn_ci_n_pending_streams (const struct lsquic_conn *lconn)
{
@ -8194,7 +8177,6 @@ ietf_full_conn_ci_count_garbage (struct lsquic_conn *lconn, size_t garbage_sz)
.ci_destroy = ietf_full_conn_ci_destroy, \
.ci_drain_time = ietf_full_conn_ci_drain_time, \
.ci_drop_crypto_streams = ietf_full_conn_ci_drop_crypto_streams, \
.ci_get_ctx = ietf_full_conn_ci_get_ctx, \
.ci_get_engine = ietf_full_conn_ci_get_engine, \
.ci_get_log_cid = ietf_full_conn_ci_get_log_cid, \
.ci_get_min_datagram_size= ietf_full_conn_ci_get_min_datagram_size, \
@ -8214,7 +8196,6 @@ ietf_full_conn_ci_count_garbage (struct lsquic_conn *lconn, size_t garbage_sz)
.ci_record_addrs = ietf_full_conn_ci_record_addrs, \
.ci_report_live = ietf_full_conn_ci_report_live, \
.ci_retx_timeout = ietf_full_conn_ci_retx_timeout, \
.ci_set_ctx = ietf_full_conn_ci_set_ctx, \
.ci_set_min_datagram_size= ietf_full_conn_ci_set_min_datagram_size, \
.ci_status = ietf_full_conn_ci_status, \
.ci_stateless_reset = ietf_full_conn_ci_stateless_reset, \

View File

@ -3738,7 +3738,7 @@ gquic_encrypt_packet (enc_session_t *enc_session_p,
return ENCPA_BADCRYPT; /* To cause connection to close */
ipv6 = NP_IS_IPv6(packet_out->po_path);
buf = enpub->enp_pmi->pmi_allocate(enpub->enp_pmi_ctx,
packet_out->po_path->np_peer_ctx, bufsz, ipv6);
packet_out->po_path->np_peer_ctx, lconn->conn_ctx, bufsz, ipv6);
if (!buf)
{
LSQ_DEBUG("could not allocate memory for outgoing packet of size %zd",
@ -3936,7 +3936,7 @@ gquic2_esf_encrypt_packet (enc_session_t *enc_session_p,
dst_sz = lconn->cn_pf->pf_packout_size(lconn, packet_out);
ipv6 = NP_IS_IPv6(packet_out->po_path);
dst = enpub->enp_pmi->pmi_allocate(enpub->enp_pmi_ctx,
packet_out->po_path->np_peer_ctx, dst_sz, ipv6);
packet_out->po_path->np_peer_ctx, lconn->conn_ctx, dst_sz, ipv6);
if (!dst)
{
LSQ_DEBUG("could not allocate memory for outgoing packet of size %zd",