comparison src/event/ngx_event_quic_transport.c @ 8315:fdda518d10ba quic

Proper handling of packet number in header. - fixed setting of largest received packet number. - sending properly truncated packet number - added support for multi-byte packet number
author Vladimir Homutov <vl@nginx.com>
date Fri, 03 Apr 2020 14:02:16 +0300
parents e10b4c61420f
children 853908b5a216
comparison
equal deleted inserted replaced
8314:de8981bf2dd5 8315:fdda518d10ba
35 (p)[3] = (u_char) (s), \ 35 (p)[3] = (u_char) (s), \
36 (p) + sizeof(uint32_t)) 36 (p) + sizeof(uint32_t))
37 37
38 #endif 38 #endif
39 39
40 #define ngx_quic_write_uint24(p, s) \
41 ((p)[0] = (u_char) ((s) >> 16), \
42 (p)[1] = (u_char) ((s) >> 8), \
43 (p)[2] = (u_char) (s), \
44 (p) + 3)
40 45
41 #define ngx_quic_write_uint16_aligned(p, s) \ 46 #define ngx_quic_write_uint16_aligned(p, s) \
42 (*(uint16_t *) (p) = htons((uint16_t) (s)), (p) + sizeof(uint16_t)) 47 (*(uint16_t *) (p) = htons((uint16_t) (s)), (p) + sizeof(uint16_t))
43 48
44 #define ngx_quic_write_uint32_aligned(p, s) \ 49 #define ngx_quic_write_uint32_aligned(p, s) \
360 365
361 if (pkt->level == ssl_encryption_initial) { 366 if (pkt->level == ssl_encryption_initial) {
362 ngx_quic_build_int(&p, pkt->token.len); 367 ngx_quic_build_int(&p, pkt->token.len);
363 } 368 }
364 369
365 ngx_quic_build_int(&p, pkt_len + 1); // length (inc. pnl) 370 ngx_quic_build_int(&p, pkt_len + pkt->num_len);
366 371
367 *pnp = p; 372 *pnp = p;
368 373
369 *p++ = pkt->number; // XXX: uint64 374 switch (pkt->num_len) {
375 case 1:
376 *p++ = pkt->trunc;
377 break;
378 case 2:
379 p = ngx_quic_write_uint16(p, pkt->trunc);
380 break;
381 case 3:
382 p = ngx_quic_write_uint24(p, pkt->trunc);
383 break;
384 case 4:
385 p = ngx_quic_write_uint32(p, pkt->trunc);
386 break;
387 }
370 388
371 return p - start; 389 return p - start;
372 } 390 }
373 391
374 392
378 { 396 {
379 u_char *p, *start; 397 u_char *p, *start;
380 398
381 p = start = out; 399 p = start = out;
382 400
383 *p++ = 0x40; 401 *p++ = pkt->flags;
384 402
385 p = ngx_cpymem(p, pkt->scid.data, pkt->scid.len); 403 p = ngx_cpymem(p, pkt->scid.data, pkt->scid.len);
386 404
387 *pnp = p; 405 *pnp = p;
388 406
389 *p++ = pkt->number; // XXX: uint64 407 switch (pkt->num_len) {
408 case 1:
409 *p++ = pkt->trunc;
410 break;
411 case 2:
412 p = ngx_quic_write_uint16(p, pkt->trunc);
413 break;
414 case 3:
415 p = ngx_quic_write_uint24(p, pkt->trunc);
416 break;
417 case 4:
418 p = ngx_quic_write_uint32(p, pkt->trunc);
419 break;
420 }
390 421
391 return p - start; 422 return p - start;
392 } 423 }
393 424
394 425