quic_port.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OSSL_QUIC_PORT_H
  10. # define OSSL_QUIC_PORT_H
  11. # include <openssl/ssl.h>
  12. # include "internal/quic_types.h"
  13. # include "internal/quic_reactor.h"
  14. # include "internal/quic_demux.h"
  15. # include "internal/quic_predef.h"
  16. # include "internal/thread_arch.h"
  17. # ifndef OPENSSL_NO_QUIC
  18. /*
  19. * QUIC Port
  20. * =========
  21. *
  22. * A QUIC Port (QUIC_PORT) represents a single UDP network socket and contains
  23. * zero or more subsidiary QUIC_CHANNEL instances, each of which represents a
  24. * single QUIC connection. All QUIC_CHANNEL instances must belong to a
  25. * QUIC_PORT.
  26. *
  27. * A QUIC port is responsible for managing a set of channels which all use the
  28. * same UDP socket, and (in future) for automatically creating new channels when
  29. * incoming connections are received.
  30. *
  31. * In order to retain compatibility with QUIC_TSERVER, it also supports a point
  32. * of legacy compatibility where a caller can create an incoming (server role)
  33. * channel and that channel will be automatically be bound to the next incoming
  34. * connection. In the future this will go away once QUIC_TSERVER is removed.
  35. *
  36. * All QUIC_PORT instances are created by a QUIC_ENGINE.
  37. */
  38. typedef struct quic_port_args_st {
  39. /* The engine which the QUIC port is to be a child of. */
  40. QUIC_ENGINE *engine;
  41. /*
  42. * This SSL_CTX will be used when constructing the handshake layer object
  43. * inside newly created channels.
  44. */
  45. SSL_CTX *channel_ctx;
  46. /*
  47. * If 1, this port is to be used for multiple connections, so
  48. * non-zero-length CIDs should be used. If 0, this port will only be used
  49. * for a single connection, so a zero-length local CID can be used.
  50. */
  51. int is_multi_conn;
  52. } QUIC_PORT_ARGS;
  53. /* Only QUIC_ENGINE should use this function. */
  54. QUIC_PORT *ossl_quic_port_new(const QUIC_PORT_ARGS *args);
  55. void ossl_quic_port_free(QUIC_PORT *port);
  56. /*
  57. * Operations
  58. * ==========
  59. */
  60. /* Create an outgoing channel using this port. */
  61. QUIC_CHANNEL *ossl_quic_port_create_outgoing(QUIC_PORT *port, SSL *tls);
  62. /*
  63. * Create an incoming channel using this port.
  64. *
  65. * TODO(QUIC SERVER): temporary TSERVER use only - will be removed.
  66. */
  67. QUIC_CHANNEL *ossl_quic_port_create_incoming(QUIC_PORT *port, SSL *tls);
  68. /*
  69. * Queries and Accessors
  70. * =====================
  71. */
  72. /* Gets/sets the underlying network read and write BIO. */
  73. BIO *ossl_quic_port_get_net_rbio(QUIC_PORT *port);
  74. BIO *ossl_quic_port_get_net_wbio(QUIC_PORT *port);
  75. int ossl_quic_port_set_net_rbio(QUIC_PORT *port, BIO *net_rbio);
  76. int ossl_quic_port_set_net_wbio(QUIC_PORT *port, BIO *net_wbio);
  77. /*
  78. * Re-poll the network BIOs already set to determine if their support
  79. * for polling has changed.
  80. */
  81. int ossl_quic_port_update_poll_descriptors(QUIC_PORT *port);
  82. /* Gets the engine which this port is a child of. */
  83. QUIC_ENGINE *ossl_quic_port_get0_engine(QUIC_PORT *port);
  84. /* Gets the reactor which can be used to tick/poll on the port. */
  85. QUIC_REACTOR *ossl_quic_port_get0_reactor(QUIC_PORT *port);
  86. /* Gets the demuxer belonging to the port. */
  87. QUIC_DEMUX *ossl_quic_port_get0_demux(QUIC_PORT *port);
  88. /* Gets the mutex used by the port. */
  89. CRYPTO_MUTEX *ossl_quic_port_get0_mutex(QUIC_PORT *port);
  90. /* Gets the current time. */
  91. OSSL_TIME ossl_quic_port_get_time(QUIC_PORT *port);
  92. int ossl_quic_port_get_rx_short_dcid_len(const QUIC_PORT *port);
  93. int ossl_quic_port_get_tx_init_dcid_len(const QUIC_PORT *port);
  94. /* Returns 1 if the port is running/healthy, 0 if it has failed. */
  95. int ossl_quic_port_is_running(const QUIC_PORT *port);
  96. /*
  97. * Restores port-level error to the error stack. To be called only if
  98. * the port is no longer running.
  99. */
  100. void ossl_quic_port_restore_err_state(const QUIC_PORT *port);
  101. /* For use by QUIC_ENGINE. You should not need to call this directly. */
  102. void ossl_quic_port_subtick(QUIC_PORT *port, QUIC_TICK_RESULT *r,
  103. uint32_t flags);
  104. /*
  105. * Events
  106. * ======
  107. */
  108. /*
  109. * Called if a permanent network error occurs. Terminates all channels
  110. * immediately. triggering_ch is an optional argument designating
  111. * a channel which encountered the network error.
  112. */
  113. void ossl_quic_port_raise_net_error(QUIC_PORT *port,
  114. QUIC_CHANNEL *triggering_ch);
  115. # endif
  116. #endif