Skip to content

Commit

Permalink
Enable loss bits when compiled with -DLSQUIC_LOSS_BITS=1
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitri Tikhonov committed Nov 19, 2019
1 parent be8bc27 commit 0b83dfa
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 5 deletions.
15 changes: 15 additions & 0 deletions src/liblsquic/lsquic_enc_sess_ietf.c
Expand Up @@ -333,7 +333,11 @@ apply_hp (struct enc_sess_iquic *enc_sess,
hp->hp_gen_mask(enc_sess, hp, cliser, dst + packno_off + 4, mask);
LSQ_DEBUG("apply header protection using mask %s",
HEXSTR(mask, 5, mask_str));
#if LSQUIC_LOSS_BITS
dst[0] ^= (0x7 | ((dst[0] >> 7) << 3)) & mask[0];
#else
dst[0] ^= (0xF | (((dst[0] & 0x80) == 0) << 4)) & mask[0];
#endif
switch (packno_len)
{
case 4:
Expand Down Expand Up @@ -391,7 +395,11 @@ strip_hp (struct enc_sess_iquic *enc_sess,
hp->hp_gen_mask(enc_sess, hp, cliser, iv, mask);
LSQ_DEBUG("strip header protection using mask %s",
HEXSTR(mask, 5, mask_str));
#if LSQUIC_LOSS_BITS
dst[0] ^= (0x7 | ((dst[0] >> 7) << 3)) & mask[0];
#else
dst[0] ^= (0xF | (((dst[0] & 0x80) == 0) << 4)) & mask[0];
#endif
packno = 0;
shift = 0;
*packno_len = 1 + (dst[0] & 3);
Expand Down Expand Up @@ -1978,12 +1986,19 @@ iquic_esf_decrypt_packet (enc_session_t *enc_session_p,
goto err;
}

#if LSQUIC_LOSS_BITS
if (dst[0] & 0x10)
packet_in->pi_flags |= PI_SQUARE_BIT;
if (dst[0] & 0x08)
packet_in->pi_flags |= PI_LOSS_BIT;
#else
if (dst[0] & (0x0C << (packet_in->pi_header_type == HETY_NOT_SET)))
{
LSQ_DEBUG("reserved bits are not set to zero");
dec_packin = DECPI_VIOLATION;
goto err;
}
#endif

if (crypto_ctx == &crypto_ctx_buf)
{
Expand Down
26 changes: 22 additions & 4 deletions src/liblsquic/lsquic_ev_log.c
Expand Up @@ -67,12 +67,21 @@ lsquic_ev_log_packet_in (const lsquic_cid_t *cid,
break;
default:
LCID("packet in: %"PRIu64", type: %s, size: %u; ecn: %u, spin: %d; "
"path: %hhu",
"path: %hhu"
#if LSQUIC_LOSS_BITS
"; Q: %d; L: %d"
#endif
,
packet_in->pi_packno, lsquic_hety2str[packet_in->pi_header_type],
(unsigned) (packet_in->pi_data_sz + IQUIC_TAG_LEN),
lsquic_packet_in_ecn(packet_in),
/* spin bit value is only valid for short packet headers */
lsquic_packet_in_spin_bit(packet_in), packet_in->pi_path_id);
lsquic_packet_in_spin_bit(packet_in), packet_in->pi_path_id
#if LSQUIC_LOSS_BITS
, ((packet_in->pi_flags & PI_SQUARE_BIT) > 0)
, ((packet_in->pi_flags & PI_LOSS_BIT) > 0)
#endif
);
break;
}
}
Expand Down Expand Up @@ -222,7 +231,11 @@ lsquic_ev_log_packet_sent (const lsquic_cid_t *cid,
packet_out->po_frame_types));
else
LCID("sent packet %"PRIu64", type %s, crypto: %s, size %hu, frame "
"types: %s, ecn: %u, spin: %d; kp: %u, path: %hhu, flags: %u",
"types: %s, ecn: %u, spin: %d; kp: %u, path: %hhu, flags: %u"
#if LSQUIC_LOSS_BITS
"; Q: %u; L: %u"
#endif
,
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,
Expand All @@ -237,7 +250,12 @@ lsquic_ev_log_packet_sent (const lsquic_cid_t *cid,
lsquic_packet_out_spin_bit(packet_out),
lsquic_packet_out_kp(packet_out),
packet_out->po_path->np_path_id,
(unsigned) packet_out->po_flags);
(unsigned) packet_out->po_flags
#if LSQUIC_LOSS_BITS
, lsquic_packet_out_square_bit(packet_out)
, lsquic_packet_out_loss_bit(packet_out)
#endif
);
}


Expand Down
13 changes: 12 additions & 1 deletion src/liblsquic/lsquic_packet_in.h
Expand Up @@ -83,7 +83,18 @@ typedef struct lsquic_packet_in
#define PIBIT_BITS_SHIFT 12
PI_BITS_BIT_0 = (1 <<12),
PI_BITS_BIT_1 = (1 <<13),
} pi_flags:16;
#if LSQUIC_LOSS_BITS
/* Square bit and loss bit flags are used for logging */
PI_SQUARE_BIT = (1 <<14),
PI_LOSS_BIT = (1 <<15),
#endif
} pi_flags:
#if LSQUIC_LOSS_BITS
32
#else
16
#endif
;
/* pi_token and pi_token_size are set in Initial and Retry packets */
unsigned short pi_token_size; /* Size of the token */
unsigned char pi_token; /* Offset to token */
Expand Down
8 changes: 8 additions & 0 deletions src/liblsquic/lsquic_packet_out.h
Expand Up @@ -143,6 +143,10 @@ typedef struct lsquic_packet_out
#define POECN_SHIFT 4
POL_ECNBIT_0 = 1 << 4,
POL_ECNBIT_1 = 1 << 5,
#if LSQUIC_LOSS_BITS
POL_SQUARE_BIT = 1 << 6,
POL_LOSS_BIT = 1 << 7,
#endif
} po_lflags:8;
unsigned char *po_data;

Expand Down Expand Up @@ -199,6 +203,10 @@ typedef struct lsquic_packet_out
} while (0)

#define lsquic_packet_out_spin_bit(p) (((p)->po_flags & PO_SPIN_BIT) > 0)
#if LSQUIC_LOSS_BITS
#define lsquic_packet_out_square_bit(p) (((p)->po_lflags & POL_SQUARE_BIT) > 0)
#define lsquic_packet_out_loss_bit(p) (((p)->po_lflags & POL_LOSS_BIT) > 0)
#endif

#define lsquic_packet_out_set_spin_bit(p, b) do { \
(p)->po_flags &= ~PO_SPIN_BIT; \
Expand Down
4 changes: 4 additions & 0 deletions src/liblsquic/lsquic_parse_ietf_v1.c
Expand Up @@ -260,6 +260,10 @@ gen_short_pkt_header (const struct lsquic_conn *lconn,

buf[0] = 0x40
| (lsquic_packet_out_spin_bit(packet_out) << 5)
#if LSQUIC_LOSS_BITS
| (lsquic_packet_out_square_bit(packet_out) << 4)
| (lsquic_packet_out_loss_bit(packet_out) << 3)
#endif
| (lsquic_packet_out_key_phase(packet_out) << 2)
| packno_bits
;
Expand Down
18 changes: 18 additions & 0 deletions src/liblsquic/lsquic_send_ctl.c
Expand Up @@ -765,6 +765,10 @@ send_ctl_handle_lost_packet (lsquic_send_ctl_t *ctl,
assert(ctl->sc_n_in_flight_all);
packet_sz = packet_out_sent_sz(packet_out);

#if LSQUIC_LOSS_BITS
++ctl->sc_loss_count;
#endif

if (packet_out->po_frame_types & (1 << QUIC_FRAME_ACK))
{
ctl->sc_flags |= SC_LOST_ACK_INIT << lsquic_packet_out_pns(packet_out);
Expand Down Expand Up @@ -1610,6 +1614,20 @@ lsquic_send_ctl_next_packet_to_send (struct lsquic_send_ctl *ctl, size_t size)
send_ctl_maybe_zero_pad(ctl, packet_out, size ? size : 1200);
}

#if LSQUIC_LOSS_BITS
if (ctl->sc_loss_count)
{
--ctl->sc_loss_count;
packet_out->po_lflags |= POL_LOSS_BIT;
}
else
packet_out->po_lflags &= ~POL_LOSS_BIT;
if (ctl->sc_square_count++ & 128)
packet_out->po_lflags |= POL_SQUARE_BIT;
else
packet_out->po_lflags &= ~POL_SQUARE_BIT;
#endif

return packet_out;
}

Expand Down
4 changes: 4 additions & 0 deletions src/liblsquic/lsquic_send_ctl.h
Expand Up @@ -124,6 +124,10 @@ typedef struct lsquic_send_ctl {
unsigned sc_retry_count;
unsigned sc_rt_count; /* Count round trips */
lsquic_packno_t sc_cur_rt_end;
#if LSQUIC_LOSS_BITS
unsigned sc_loss_count; /* Used to set loss bit */
unsigned sc_square_count;/* Used to set square bit */
#endif
} lsquic_send_ctl_t;

void
Expand Down

0 comments on commit 0b83dfa

Please sign in to comment.