Skip to content

Commit

Permalink
Merge branch '4527-improve-tls-framing-for-dot' into 'main'
Browse files Browse the repository at this point in the history
TLS: improve framing by assembling DNS message in one buffer

Closes #4527

See merge request isc-projects/bind9!8646
  • Loading branch information
arbv committed Jan 17, 2024
2 parents 5670d8e + 20d5a80 commit 2ff9080
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions lib/isc/netmgr/tlsstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

#define TLS_MAX_SEND_BUF_SIZE (UINT16_MAX + UINT16_MAX / 2)

#define MAX_DNS_MESSAGE_SIZE (UINT16_MAX)

#ifdef ISC_NETMGR_TRACE
ISC_ATTR_UNUSED static const char *
tls_status2str(int tls_status) {
Expand Down Expand Up @@ -608,27 +610,34 @@ tls_do_bio(isc_nmsocket_t *sock, isc_region_t *received_data,
SSL_SENT_SHUTDOWN) != 0);
bool write_failed = false;
if (*(uint16_t *)send_data->tcplen != 0) {
size_t sendlen = 0;
uint8_t sendbuf[MAX_DNS_MESSAGE_SIZE +
sizeof(uint16_t)];
/*
* There is a DNS message length to write - do
* it.
*/
rv = SSL_write_ex(
sock->tlsstream.tls, send_data->tcplen,
sizeof(send_data->tcplen), &len);
if (rv != 1 || len != sizeof(send_data->tcplen))
{

/*
* There's no SSL_writev(), so we need to use a
* local buffer to assemble the whole message
*/
INSIST(send_data->uvbuf.len <=
MAX_DNS_MESSAGE_SIZE);

sendlen = send_data->uvbuf.len +
sizeof(uint16_t);
memmove(sendbuf, send_data->tcplen,
sizeof(uint16_t));
memmove(sendbuf + sizeof(uint16_t),
send_data->uvbuf.base,
send_data->uvbuf.len);

/* Write data */
rv = SSL_write_ex(sock->tlsstream.tls, sendbuf,
sendlen, &len);
if (rv != 1 || len != sendlen) {
write_failed = true;
} else {
/* Write data */
rv = SSL_write_ex(sock->tlsstream.tls,
send_data->uvbuf.base,
send_data->uvbuf.len,
&len);
if (rv != 1 ||
len != send_data->uvbuf.len)
{
write_failed = true;
}
}
} else {
/* Write data only */
Expand Down

0 comments on commit 2ff9080

Please sign in to comment.