/* Encode <frm> QUIC frame into <buf> buffer.
* Returns 1 if succeeded (enough room in <buf> to encode the frame), 0 if not.
+ * The buffer is updated to point to one byte past the end of the built frame
+ * only if succeeded.
*/
int qc_build_frm(unsigned char **buf, const unsigned char *end,
struct quic_frame *frm, struct quic_tx_packet *pkt,
{
int ret = 0;
const struct quic_frame_builder *builder;
+ unsigned char *pos = *buf;
TRACE_ENTER(QUIC_EV_CONN_BFRM, qc);
builder = &quic_frame_builders[frm->type];
BUG_ON(!(builder->mask & (1U << pkt->type)));
}
- if (end <= *buf) {
+ if (end <= pos) {
TRACE_DEVEL("not enough room", QUIC_EV_CONN_BFRM, qc, frm);
goto leave;
}
TRACE_PROTO("frame", QUIC_EV_CONN_BFRM, qc, frm);
- *(*buf)++ = frm->type;
- if (!quic_frame_builders[frm->type].func(buf, end, frm, qc)) {
+ *pos++ = frm->type;
+ if (!quic_frame_builders[frm->type].func(&pos, end, frm, qc)) {
TRACE_DEVEL("frame building error", QUIC_EV_CONN_BFRM, qc, frm);
goto leave;
}
pkt->flags |= builder->flags;
+ *buf = pos;
ret = 1;
leave:
if (!LIST_ISEMPTY(&frm_list)) {
struct quic_frame *tmp_cf;
list_for_each_entry_safe(cf, tmp_cf, &frm_list, list) {
- unsigned char *spos = pos;
-
- if (!qc_build_frm(&spos, end, cf, pkt, qc)) {
+ if (!qc_build_frm(&pos, end, cf, pkt, qc)) {
ssize_t room = end - pos;
TRACE_DEVEL("Not enough room", QUIC_EV_CONN_TXPKT,
qc, NULL, NULL, &room);
break;
}
- pos = spos;
quic_tx_packet_refinc(pkt);
cf->pkt = pkt;
}