Skip to content

Commit c618679

Browse files
committed
Move the pipelining code into the record layer
Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from openssl#19198)
1 parent c6d5f34 commit c618679

2 files changed

Lines changed: 57 additions & 43 deletions

File tree

ssl/record/methods/tls_common.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,9 @@ static int tls_is_multiblock_capable(OSSL_RECORD_LAYER *rl, int type,
14501450
size_t tls_get_max_records(OSSL_RECORD_LAYER *rl, int type, size_t len,
14511451
size_t maxfrag, size_t *preffrag)
14521452
{
1453+
/* TODO(RECLAYER): Remove me */
1454+
SSL_CONNECTION *s = rl->cbarg;
1455+
14531456
if (tls_is_multiblock_capable(rl, type, len, *preffrag)) {
14541457
/* minimize address aliasing conflicts */
14551458
if ((*preffrag & 0xfff) == 0)
@@ -1460,6 +1463,29 @@ size_t tls_get_max_records(OSSL_RECORD_LAYER *rl, int type, size_t len,
14601463

14611464
return 4;
14621465
}
1466+
1467+
/*
1468+
* TODO(RECLYAER): There is no test for the pipelining code. We should add
1469+
* one.
1470+
*/
1471+
/*
1472+
* If we have a pipeline capable cipher, and we have been configured to use
1473+
* it, then return the preferred number of pipelines.
1474+
*/
1475+
if (rl->max_pipelines > 0
1476+
&& s->enc_write_ctx != NULL
1477+
&& (EVP_CIPHER_get_flags(EVP_CIPHER_CTX_get0_cipher(s->enc_write_ctx))
1478+
& EVP_CIPH_FLAG_PIPELINE) != 0
1479+
&& RLAYER_USE_EXPLICIT_IV(rl)) {
1480+
size_t pipes;
1481+
1482+
if (len == 0)
1483+
return 1;
1484+
pipes = ((len - 1) / *preffrag) + 1;
1485+
1486+
return (pipes < rl->max_pipelines) ? pipes : rl->max_pipelines;
1487+
}
1488+
14631489
return 1;
14641490
}
14651491

ssl/record/rec_layer_s3.c

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -292,35 +292,6 @@ int ssl3_write_bytes(SSL *ssl, int type, const void *buf_, size_t len,
292292
max_send_fragment = ssl_get_max_send_fragment(s);
293293
split_send_fragment = ssl_get_split_send_fragment(s);
294294

295-
/*
296-
* Ask the record layer how it would like to split the amount of data that
297-
* we have, and how many of those records it would like in one go.
298-
*/
299-
maxpipes = s->rlayer.wrlmethod->get_max_records(s->rlayer.wrl, type, n,
300-
max_send_fragment,
301-
&split_send_fragment);
302-
/*
303-
* If max_pipelines is 0 then this means "undefined" and we default to
304-
* whatever the record layer wants to do. Otherwise we use the smallest
305-
* value from the number requested by the record layer, and max number
306-
* configured by the user.
307-
*/
308-
if (s->max_pipelines > 0 && maxpipes > s->max_pipelines)
309-
maxpipes = s->max_pipelines;
310-
311-
if (maxpipes > SSL_MAX_PIPELINES)
312-
maxpipes = SSL_MAX_PIPELINES;
313-
314-
315-
#if 0
316-
/* TODO(RECLAYER): FIX ME */
317-
if (maxpipes == 0
318-
|| s->enc_write_ctx == NULL
319-
|| (EVP_CIPHER_get_flags(EVP_CIPHER_CTX_get0_cipher(s->enc_write_ctx))
320-
& EVP_CIPH_FLAG_PIPELINE) == 0
321-
|| !SSL_USE_EXPLICIT_IV(s))
322-
maxpipes = 1;
323-
#endif
324295
if (max_send_fragment == 0
325296
|| split_send_fragment == 0
326297
|| split_send_fragment > max_send_fragment) {
@@ -346,39 +317,56 @@ int ssl3_write_bytes(SSL *ssl, int type, const void *buf_, size_t len,
346317

347318
for (;;) {
348319
size_t tmppipelen, remain;
349-
size_t numpipes, j, lensofar = 0;
320+
size_t j, lensofar = 0;
350321

351-
if (n == 0)
352-
numpipes = 1;
353-
else
354-
numpipes = ((n - 1) / split_send_fragment) + 1;
355-
if (numpipes > maxpipes)
356-
numpipes = maxpipes;
322+
/*
323+
* Ask the record layer how it would like to split the amount of data
324+
* that we have, and how many of those records it would like in one go.
325+
*/
326+
maxpipes = s->rlayer.wrlmethod->get_max_records(s->rlayer.wrl, type, n,
327+
max_send_fragment,
328+
&split_send_fragment);
329+
/*
330+
* If max_pipelines is 0 then this means "undefined" and we default to
331+
* whatever the record layer wants to do. Otherwise we use the smallest
332+
* value from the number requested by the record layer, and max number
333+
* configured by the user.
334+
*/
335+
if (s->max_pipelines > 0 && maxpipes > s->max_pipelines)
336+
maxpipes = s->max_pipelines;
337+
338+
if (maxpipes > SSL_MAX_PIPELINES)
339+
maxpipes = SSL_MAX_PIPELINES;
340+
341+
if (split_send_fragment > max_send_fragment) {
342+
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
343+
return -1;
344+
}
357345

358-
if (n / numpipes >= split_send_fragment) {
346+
if (n / maxpipes >= split_send_fragment) {
359347
/*
360348
* We have enough data to completely fill all available
361349
* pipelines
362350
*/
363-
for (j = 0; j < numpipes; j++) {
351+
for (j = 0; j < maxpipes; j++) {
364352
tmpls[j].type = type;
365353
tmpls[j].version = recversion;
366354
tmpls[j].buf = &(buf[tot]) + (j * split_send_fragment);
367355
tmpls[j].buflen = split_send_fragment;
368356
}
369357
/* Remember how much data we are going to be sending */
370-
s->rlayer.wpend_tot = numpipes * split_send_fragment;
358+
s->rlayer.wpend_tot = maxpipes * split_send_fragment;
371359
} else {
372360
/* We can partially fill all available pipelines */
373-
tmppipelen = n / numpipes;
374-
remain = n % numpipes;
361+
tmppipelen = n / maxpipes;
362+
remain = n % maxpipes;
375363
/*
376364
* If there is a remainder we add an extra byte to the first few
377365
* pipelines
378366
*/
379367
if (remain > 0)
380368
tmppipelen++;
381-
for (j = 0; j < numpipes; j++) {
369+
for (j = 0; j < maxpipes; j++) {
382370
tmpls[j].type = type;
383371
tmpls[j].version = recversion;
384372
tmpls[j].buf = &(buf[tot]) + lensofar;
@@ -392,7 +380,7 @@ int ssl3_write_bytes(SSL *ssl, int type, const void *buf_, size_t len,
392380
}
393381

394382
i = HANDLE_RLAYER_WRITE_RETURN(s,
395-
s->rlayer.wrlmethod->write_records(s->rlayer.wrl, tmpls, numpipes));
383+
s->rlayer.wrlmethod->write_records(s->rlayer.wrl, tmpls, maxpipes));
396384
if (i <= 0) {
397385
/* SSLfatal() already called if appropriate */
398386
s->rlayer.wnum = tot;

0 commit comments

Comments
 (0)