Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSO-Friendly Packet Memory #175

Merged
merged 7 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/test_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bin/test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion docs/apiref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,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.

Expand Down
5 changes: 3 additions & 2 deletions include/lsquic.h
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,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 */
};

/**
Expand Down Expand Up @@ -1035,7 +1036,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
Expand Down
4 changes: 2 additions & 2 deletions src/liblsquic/lsquic_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
7 changes: 1 addition & 6 deletions src/liblsquic/lsquic_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/liblsquic/lsquic_enc_sess_ietf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,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",
Expand Down
5 changes: 3 additions & 2 deletions src/liblsquic/lsquic_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,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);
}
Expand Down Expand Up @@ -1955,7 +1955,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)
{
Expand Down Expand Up @@ -2463,6 +2463,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;
Expand Down
23 changes: 2 additions & 21 deletions src/liblsquic/lsquic_full_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
23 changes: 2 additions & 21 deletions src/liblsquic/lsquic_full_conn_ietf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1550,7 +1549,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))
Expand Down Expand Up @@ -2759,7 +2758,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);
}

Expand Down Expand Up @@ -7904,14 +7903,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)
{
Expand All @@ -7920,14 +7911,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)
{
Expand Down Expand Up @@ -8190,7 +8173,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, \
Expand All @@ -8210,7 +8192,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, \
Expand Down
4 changes: 2 additions & 2 deletions src/liblsquic/lsquic_handshake.c
Original file line number Diff line number Diff line change
Expand Up @@ -3746,7 +3746,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",
Expand Down Expand Up @@ -3944,7 +3944,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",
Expand Down