QUIC Frame Encoding and Decoding Functions#18795
QUIC Frame Encoding and Decoding Functions#18795hlandau wants to merge 9 commits intoopenssl:masterfrom
Conversation
1739ace to
30f4fe9
Compare
| * |*data| | ||
| */ | ||
| __owur static ossl_inline int PACKET_peek_net_8(const PACKET *pkt, | ||
| uint64_t *data) |
There was a problem hiding this comment.
Our existing use of unsigned long for the net_4/net_3 versions of these functions seems dubious. We probably should use fixed width types instead. But that is for another PR.
include/internal/quic_wire.h
Outdated
| * e.g. multiple packets). | ||
| * | ||
| * Note also that this means f->len is always valid after this function returns | ||
| * successfully, regardless of the value of f->has_len. |
There was a problem hiding this comment.
Given that f->len is always set anyway - I'm wondering why f->has_len is useful when decoding.
There was a problem hiding this comment.
has_len specifies whether the length field is or was included in the encoding. If it isn't, the frame runs to the end of the packet. Maybe could be named less confusingly (has_explicit_len?)
There was a problem hiding this comment.
I understand what it does. My question really was why we care how it was encoded. Surely the presence or otherwise of the length field is only useful during the decoding itself? i.e. not something we need to pass around and remember after we've decoded it.
There was a problem hiding this comment.
We also need a way to tell the encoder whether to include the length field. Keeping it symmetrical on the decode side seems the least surprising thing to do, as I see it.
| 0x01 | ||
| }; | ||
|
|
||
| /* 3. ACK */ |
There was a problem hiding this comment.
I feel like there are perhaps more test cases required here:
E.g. ack frame with no gaps, maximal/minimal ack delay values, no ecn data, etc
There was a problem hiding this comment.
The ACK frames are definitely the hairiest frames to encode and decode. There are more tests specifically for ACK below, but more would probably be good.
ACKs with and without ECN are tested, but we can probably test ACK delays more. I'll take this as an action item.
| BUF_MEM_free(buf); | ||
| return testresult; | ||
| } | ||
|
|
There was a problem hiding this comment.
We don't seem to have any test cases for decoding illegal frame encodings?
There was a problem hiding this comment.
Good point. I'll add some.
include/internal/quic_wire.h
Outdated
| uint64_t len; /* Length of data in bytes */ | ||
| const uint8_t *data; | ||
|
|
||
| char has_len; /* 1 if len field is valid */ |
There was a problem hiding this comment.
Is the comment right? Below we say that len is always valid on decoding and has_len indicates it was in the frame.
There was a problem hiding this comment.
Added comment, and renamed to has_explicit_len since the current naming is confusing.
include/internal/quic_wire.h
Outdated
| * frame consumes one byte; num_bytes specifies the number of bytes of padding | ||
| * to write. | ||
| */ | ||
| int ossl_quic_wire_encode_frame_padding(WPACKET *pkt, size_t num_bytes); |
There was a problem hiding this comment.
Should it be named ossl_quic_wire_encode_frames_padding when it creates potentially multiple frames.
There was a problem hiding this comment.
Maybe just ossl_wire_encode_padding? I'll change it.
This adds functions for encoding and decoding QUIC frames.
|
Updated. Rebased, and no longer based on top of ACKM. Some small definitions in ACKM this relied on are now incorporated in this PR. ACKM will be rebased on top of this soon. I've added testing for malformed frame decoding. Testing of ACK frames with no gaps is already tested. |
30f4fe9 to
f6949e9
Compare
|
Updated. |
paulidale
left a comment
There was a problem hiding this comment.
Looks good. Mostly nits but a couple of more meaningful comments.
I've not gone through comparing the produced output to the formal frame definitions.
include/internal/quic_wire.h
Outdated
| typedef struct ossl_quic_frame_new_conn_id_st { | ||
| uint64_t seq_num; | ||
| uint64_t retire_prior_to; | ||
| const unsigned char *conn_id; |
There was a problem hiding this comment.
Is a fixed array appropriate here?
There was a problem hiding this comment.
It would be equally valid. Any preference?
There was a problem hiding this comment.
The ID cache proposal now uses fixed arrays. We might as well be consistent and use them everywhere (and pray the standard doesn't increase the size soon). Not that I'm against length + pointer. The reduction in mallocs is probably a good thing.
BTW: I'm currently proposing an array 21 long, with the size in the first byte and the up to 20 octets in the remaining (zero filled). That way one memcmp is enough to compare two. It's a bit kludgy but workable.
There was a problem hiding this comment.
That's a bit obtuse. Since we will be representing connection IDs all over the place, I'll introduce a structure:
#define OSSL_QUIC_MAX_CONN_ID_LEN 20
typedef struct ossl_quic_conn_id_st {
unsigned char id_len;
unsigned char id[OSSL_QUIC_MAX_CONN_ID_LEN];
} OSSL_QUIC_CONN_ID;
| || !PACKET_get_quic_vlint(pkt, &len_)) | ||
| return NULL; | ||
|
|
||
| if (len_ > SIZE_MAX |
There was a problem hiding this comment.
Prediction: some compilers will complain about a guaranteed true condition and we'll need to change this in the future...
There was a problem hiding this comment.
Sadly, nothing comes to mind except preprocessor lines :(
Reversing the condition and excluding equality len_ < SIZE_MAX sort of circumvents this but is really ugly.
There was a problem hiding this comment.
I guess we shouldn't reduce the correctness of the code to satisfy compiler warnings since this is putting the cart before the horse. I'll leave this as it is for now...
If compilers start complaining about this it will definitely happen elsewhere in the codebase too, and it will probably be more productive to figure out a general strategy for it at this time.
There was a problem hiding this comment.
I'm fine with this. I wasn't expecting a resolution -- I couldn't think of one.
Once we get warnings, we can address them.
We've had some previously BTW which we've managed to avoid.
|
This pull request is ready to merge |
|
Merged. |
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from #18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl/openssl#18795)
This adds functions for encoding and decoding QUIC frames. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl#18795)
From OpenSSL commit dffafaf48174497a724d546c3483d2493fc9b64c, openssl/openssl#18795 This adds functions for encoding and decoding QUIC frames. Modify the existing include/internal/packet.h with additional PACKET_peek_quic_vlint and PACKET_skip_quic_vlint functions.
Note that this is built on top of the ACKM PR.
I'm holding off on including packet header functions for now until I can ask @mattcaswell if he wants them, since he owns the record layer.
This is done/ready for review so I'm not marking it as a draft, but it shouldn't be merged until ACKM is merged.