1 /* 2 * Copyright 2022-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 10 #include "internal/quic_cc.h" 11 #include "internal/quic_types.h" 12 13 typedef struct ossl_cc_dummy_st { 14 size_t max_dgram_len; 15 size_t *p_diag_max_dgram_len; 16 } OSSL_CC_DUMMY; 17 18 static void dummy_update_diag(OSSL_CC_DUMMY *d); 19 20 static OSSL_CC_DATA *dummy_new(OSSL_TIME (*now_cb)(void *arg), 21 void *now_cb_arg) 22 { 23 OSSL_CC_DUMMY *d = OPENSSL_zalloc(sizeof(*d)); 24 25 if (d == NULL) 26 return NULL; 27 28 d->max_dgram_len = QUIC_MIN_INITIAL_DGRAM_LEN; 29 return (OSSL_CC_DATA *)d; 30 } 31 32 static void dummy_free(OSSL_CC_DATA *cc) 33 { 34 OPENSSL_free(cc); 35 } 36 37 static void dummy_reset(OSSL_CC_DATA *cc) 38 { 39 } 40 41 static int dummy_set_input_params(OSSL_CC_DATA *cc, const OSSL_PARAM *params) 42 { 43 OSSL_CC_DUMMY *d = (OSSL_CC_DUMMY *)cc; 44 const OSSL_PARAM *p; 45 size_t value; 46 47 p = OSSL_PARAM_locate_const(params, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN); 48 if (p != NULL) { 49 if (!OSSL_PARAM_get_size_t(p, &value)) 50 return 0; 51 if (value < QUIC_MIN_INITIAL_DGRAM_LEN) 52 return 0; 53 54 d->max_dgram_len = value; 55 dummy_update_diag(d); 56 } 57 58 return 1; 59 } 60 61 static int dummy_bind_diagnostic(OSSL_CC_DATA *cc, OSSL_PARAM *params) 62 { 63 OSSL_CC_DUMMY *d = (OSSL_CC_DUMMY *)cc; 64 const OSSL_PARAM *p; 65 66 p = OSSL_PARAM_locate_const(params, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN); 67 if (p != NULL) { 68 if (p->data_type != OSSL_PARAM_UNSIGNED_INTEGER 69 || p->data_size != sizeof(size_t)) 70 return 0; 71 72 d->p_diag_max_dgram_len = p->data; 73 } 74 75 dummy_update_diag(d); 76 return 1; 77 } 78 79 static int dummy_unbind_diagnostic(OSSL_CC_DATA *cc, OSSL_PARAM *params) 80 { 81 OSSL_CC_DUMMY *d = (OSSL_CC_DUMMY *)cc; 82 83 if (OSSL_PARAM_locate_const(params, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN) 84 != NULL) 85 d->p_diag_max_dgram_len = NULL; 86 87 return 1; 88 } 89 90 static void dummy_update_diag(OSSL_CC_DUMMY *d) 91 { 92 if (d->p_diag_max_dgram_len != NULL) 93 *d->p_diag_max_dgram_len = d->max_dgram_len; 94 } 95 96 static uint64_t dummy_get_tx_allowance(OSSL_CC_DATA *cc) 97 { 98 return SIZE_MAX; 99 } 100 101 static OSSL_TIME dummy_get_wakeup_deadline(OSSL_CC_DATA *cc) 102 { 103 return ossl_time_infinite(); 104 } 105 106 static int dummy_on_data_sent(OSSL_CC_DATA *cc, 107 uint64_t num_bytes) 108 { 109 return 1; 110 } 111 112 static int dummy_on_data_acked(OSSL_CC_DATA *cc, 113 const OSSL_CC_ACK_INFO *info) 114 { 115 return 1; 116 } 117 118 static int dummy_on_data_lost(OSSL_CC_DATA *cc, 119 const OSSL_CC_LOSS_INFO *info) 120 { 121 return 1; 122 } 123 124 static int dummy_on_data_lost_finished(OSSL_CC_DATA *cc, 125 uint32_t flags) 126 { 127 return 1; 128 } 129 130 static int dummy_on_data_invalidated(OSSL_CC_DATA *cc, 131 uint64_t num_bytes) 132 { 133 return 1; 134 } 135 136 const OSSL_CC_METHOD ossl_cc_dummy_method = { 137 dummy_new, 138 dummy_free, 139 dummy_reset, 140 dummy_set_input_params, 141 dummy_bind_diagnostic, 142 dummy_unbind_diagnostic, 143 dummy_get_tx_allowance, 144 dummy_get_wakeup_deadline, 145 dummy_on_data_sent, 146 dummy_on_data_acked, 147 dummy_on_data_lost, 148 dummy_on_data_lost_finished, 149 dummy_on_data_invalidated, 150 }; 151