src/event/quic/ngx_event_quic.h - nginx

Data types defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Nginx, Inc.
  3. */


  4. #ifndef _NGX_EVENT_QUIC_H_INCLUDED_
  5. #define _NGX_EVENT_QUIC_H_INCLUDED_


  6. #include <ngx_config.h>
  7. #include <ngx_core.h>


  8. #if (OPENSSL_VERSION_NUMBER >= 0x30500010L)
  9. #define NGX_QUIC_OPENSSL_API                 1

  10. #elif (defined SSL_R_MISSING_QUIC_TRANSPORT_PARAMETERS_EXTENSION)
  11. #define NGX_QUIC_QUICTLS_API                 1

  12. #elif (defined OPENSSL_IS_BORINGSSL || defined OPENSSL_IS_AWSLC               \
  13.        || defined LIBRESSL_VERSION_NUMBER)
  14. #define NGX_QUIC_BORINGSSL_API               1

  15. #else
  16. #define NGX_QUIC_BORINGSSL_API               1
  17. #define NGX_QUIC_OPENSSL_COMPAT              1
  18. #endif


  19. #define NGX_QUIC_MAX_UDP_PAYLOAD_SIZE        65527

  20. #define NGX_QUIC_DEFAULT_ACK_DELAY_EXPONENT  3
  21. #define NGX_QUIC_DEFAULT_MAX_ACK_DELAY       25
  22. #define NGX_QUIC_DEFAULT_HOST_KEY_LEN        32
  23. #define NGX_QUIC_SR_KEY_LEN                  32
  24. #define NGX_QUIC_AV_KEY_LEN                  32

  25. #define NGX_QUIC_SR_TOKEN_LEN                16

  26. #define NGX_QUIC_MIN_INITIAL_SIZE            1200

  27. #define NGX_QUIC_STREAM_SERVER_INITIATED     0x01
  28. #define NGX_QUIC_STREAM_UNIDIRECTIONAL       0x02


  29. typedef ngx_int_t (*ngx_quic_init_pt)(ngx_connection_t *c);
  30. typedef void (*ngx_quic_shutdown_pt)(ngx_connection_t *c);


  31. typedef enum {
  32.     NGX_QUIC_STREAM_SEND_READY = 0,
  33.     NGX_QUIC_STREAM_SEND_SEND,
  34.     NGX_QUIC_STREAM_SEND_DATA_SENT,
  35.     NGX_QUIC_STREAM_SEND_DATA_RECVD,
  36.     NGX_QUIC_STREAM_SEND_RESET_SENT,
  37.     NGX_QUIC_STREAM_SEND_RESET_RECVD
  38. } ngx_quic_stream_send_state_e;


  39. typedef enum {
  40.     NGX_QUIC_STREAM_RECV_RECV = 0,
  41.     NGX_QUIC_STREAM_RECV_SIZE_KNOWN,
  42.     NGX_QUIC_STREAM_RECV_DATA_RECVD,
  43.     NGX_QUIC_STREAM_RECV_DATA_READ,
  44.     NGX_QUIC_STREAM_RECV_RESET_RECVD,
  45.     NGX_QUIC_STREAM_RECV_RESET_READ
  46. } ngx_quic_stream_recv_state_e;


  47. typedef struct {
  48.     uint64_t                       size;
  49.     uint64_t                       offset;
  50.     uint64_t                       last_offset;
  51.     ngx_chain_t                   *chain;
  52.     ngx_chain_t                   *last_chain;
  53. } ngx_quic_buffer_t;


  54. typedef struct {
  55.     ngx_ssl_t                     *ssl;

  56.     ngx_flag_t                     retry;
  57.     ngx_flag_t                     gso_enabled;
  58.     ngx_flag_t                     disable_active_migration;
  59.     ngx_msec_t                     handshake_timeout;
  60.     ngx_msec_t                     idle_timeout;
  61.     ngx_str_t                      host_key;
  62.     size_t                         stream_buffer_size;
  63.     ngx_uint_t                     max_concurrent_streams_bidi;
  64.     ngx_uint_t                     max_concurrent_streams_uni;
  65.     ngx_uint_t                     active_connection_id_limit;
  66.     ngx_int_t                      stream_close_code;
  67.     ngx_int_t                      stream_reject_code_uni;
  68.     ngx_int_t                      stream_reject_code_bidi;

  69.     ngx_quic_init_pt               init;
  70.     ngx_quic_shutdown_pt           shutdown;

  71.     u_char                         av_token_key[NGX_QUIC_AV_KEY_LEN];
  72.     u_char                         sr_token_key[NGX_QUIC_SR_KEY_LEN];
  73. } ngx_quic_conf_t;


  74. struct ngx_quic_stream_s {
  75.     ngx_rbtree_node_t              node;
  76.     ngx_queue_t                    queue;
  77.     ngx_connection_t              *parent;
  78.     ngx_connection_t              *connection;
  79.     uint64_t                       id;
  80.     uint64_t                       sent;
  81.     uint64_t                       acked;
  82.     uint64_t                       send_max_data;
  83.     uint64_t                       send_offset;
  84.     uint64_t                       send_final_size;
  85.     uint64_t                       recv_max_data;
  86.     uint64_t                       recv_offset;
  87.     uint64_t                       recv_window;
  88.     uint64_t                       recv_last;
  89.     uint64_t                       recv_final_size;
  90.     ngx_quic_buffer_t              send;
  91.     ngx_quic_buffer_t              recv;
  92.     ngx_quic_stream_send_state_e   send_state;
  93.     ngx_quic_stream_recv_state_e   recv_state;
  94.     unsigned                       cancelable:1;
  95.     unsigned                       fin_acked:1;
  96. };


  97. void ngx_quic_recvmsg(ngx_event_t *ev);
  98. void ngx_quic_run(ngx_connection_t *c, ngx_quic_conf_t *conf);
  99. ngx_connection_t *ngx_quic_open_stream(ngx_connection_t *c, ngx_uint_t bidi);
  100. void ngx_quic_finalize_connection(ngx_connection_t *c, ngx_uint_t err,
  101.     const char *reason);
  102. void ngx_quic_shutdown_connection(ngx_connection_t *c, ngx_uint_t err,
  103.     const char *reason);
  104. ngx_int_t ngx_quic_reset_stream(ngx_connection_t *c, ngx_uint_t err);
  105. ngx_int_t ngx_quic_shutdown_stream(ngx_connection_t *c, int how);
  106. void ngx_quic_cancelable_stream(ngx_connection_t *c);
  107. ngx_int_t ngx_quic_get_packet_dcid(ngx_log_t *log, u_char *data, size_t len,
  108.     ngx_str_t *dcid);
  109. ngx_int_t ngx_quic_derive_key(ngx_log_t *log, const char *label,
  110.     ngx_str_t *secret, ngx_str_t *salt, u_char *out, size_t len);

  111. #endif /* _NGX_EVENT_QUIC_H_INCLUDED_ */