1 /* 2 * Copyright 2022 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 10 #ifndef OSSL_QUIC_LOCAL_H 11 # define OSSL_QUIC_LOCAL_H 12 13 # include <openssl/ssl.h> 14 # include "../ssl_local.h" 15 16 typedef struct quic_conn_st { 17 /* type identifier and common data */ 18 struct ssl_st ssl; 19 /* the associated tls-1.3 connection data */ 20 SSL *tls; 21 /* just an example member */ 22 uint64_t conn_id; 23 } QUIC_CONNECTION; 24 25 # define QUIC_CONNECTION_FROM_SSL_int(ssl, c) \ 26 ((ssl) == NULL ? NULL \ 27 : ((ssl)->type == SSL_TYPE_QUIC_CONNECTION \ 28 ? (c QUIC_CONNECTION *)(ssl) \ 29 : NULL)) 30 31 # define SSL_CONNECTION_FROM_QUIC_SSL_int(ssl, c) \ 32 ((ssl) == NULL ? NULL \ 33 : ((ssl)->type == SSL_TYPE_QUIC_CONNECTION \ 34 ? (c SSL_CONNECTION *)((c QUIC_CONNECTION *)(ssl))->tls \ 35 : NULL)) 36 37 # define QUIC_CONNECTION_FROM_SSL(ssl) \ 38 QUIC_CONNECTION_FROM_SSL_int(ssl, SSL_CONNECTION_NO_CONST) 39 # define QUIC_CONNECTION_FROM_CONST_SSL(ssl) \ 40 QUIC_CONNECTION_FROM_SSL_int(ssl, const) 41 # define SSL_CONNECTION_FROM_QUIC_SSL(ssl) \ 42 SSL_CONNECTION_FROM_QUIC_SSL_int(ssl, SSL_CONNECTION_NO_CONST) 43 # define SSL_CONNECTION_FROM_CONST_QUIC_SSL(ssl) \ 44 SSL_CONNECTION_FROM_CONST_QUIC_SSL_int(ssl, const) 45 46 # define OSSL_QUIC_ANY_VERSION 0xFFFFF 47 48 # define IMPLEMENT_quic_meth_func(version, func_name, q_accept, \ 49 q_connect, enc_data) \ 50 const SSL_METHOD *func_name(void) \ 51 { \ 52 static const SSL_METHOD func_name##_data= { \ 53 version, \ 54 0, \ 55 0, \ 56 ossl_quic_new, \ 57 ossl_quic_free, \ 58 ossl_quic_reset, \ 59 ossl_quic_init, \ 60 ossl_quic_clear, \ 61 ossl_quic_deinit, \ 62 q_accept, \ 63 q_connect, \ 64 ossl_quic_read, \ 65 ossl_quic_peek, \ 66 ossl_quic_write, \ 67 ossl_quic_shutdown, \ 68 NULL /* renegotiate */, \ 69 ossl_quic_renegotiate_check, \ 70 NULL /* read_bytes */, \ 71 NULL /* write_bytes */, \ 72 NULL /* dispatch_alert */, \ 73 ossl_quic_ctrl, \ 74 ossl_quic_ctx_ctrl, \ 75 NULL /* get_cipher_by_char */, \ 76 NULL /* put_cipher_by_char */, \ 77 ossl_quic_pending, \ 78 ossl_quic_num_ciphers, \ 79 ossl_quic_get_cipher, \ 80 ossl_quic_default_timeout, \ 81 &enc_data, \ 82 ssl_undefined_void_function, \ 83 ossl_quic_callback_ctrl, \ 84 ossl_quic_ctx_callback_ctrl, \ 85 }; \ 86 return &func_name##_data; \ 87 } 88 89 __owur SSL *ossl_quic_new(SSL_CTX *ctx); 90 __owur int ossl_quic_init(SSL *s); 91 void ossl_quic_deinit(SSL *s); 92 void ossl_quic_free(SSL *s); 93 int ossl_quic_reset(SSL *s); 94 int ossl_quic_clear(SSL *s); 95 __owur int ossl_quic_accept(SSL *s); 96 __owur int ossl_quic_connect(SSL *s); 97 __owur int ossl_quic_read(SSL *s, void *buf, size_t len, size_t *readbytes); 98 __owur int ossl_quic_peek(SSL *s, void *buf, size_t len, size_t *readbytes); 99 __owur int ossl_quic_write(SSL *s, const void *buf, size_t len, size_t *written); 100 __owur int ossl_quic_shutdown(SSL *s); 101 __owur long ossl_quic_ctrl(SSL *s, int cmd, long larg, void *parg); 102 __owur long ossl_quic_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg); 103 __owur long ossl_quic_callback_ctrl(SSL *s, int cmd, void (*fp) (void)); 104 __owur long ossl_quic_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp) (void)); 105 __owur size_t ossl_quic_pending(const SSL *s); 106 __owur long ossl_quic_default_timeout(void); 107 __owur int ossl_quic_num_ciphers(void); 108 __owur const SSL_CIPHER *ossl_quic_get_cipher(unsigned int u); 109 int ossl_quic_renegotiate_check(SSL *ssl, int initok); 110 111 __owur int ossl_quic_depacketize(QUIC_CONNECTION *connection); 112 113 #endif 114