Skip to content

Commit

Permalink
proto_wss: write all TLS chunks under a single lock
Browse files Browse the repository at this point in the history
Reported by Eric Tamme from OnSIP

(cherry picked from commit e113e14)
  • Loading branch information
razvancrainea committed Sep 13, 2017
1 parent f77ae30 commit cf9c0f1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 8 additions & 1 deletion modules/proto_tls/proto_tls.c
Expand Up @@ -116,7 +116,12 @@ static struct mi_root* tls_trace_mi(struct mi_root* cmd, void* param );
static int w_tls_blocking_write(struct tcp_connection *c, int fd, const char *buf,
size_t len)
{
return tls_blocking_write(c, fd, buf, len, &tls_mgm_api);
int ret;

lock_get(&c->write_lock);
ret = tls_blocking_write(c, fd, buf, len, &tls_mgm_api);
lock_release(&c->write_lock);
return ret;
}

/* buffer to be used for reading all TCP SIP messages
Expand Down Expand Up @@ -482,7 +487,9 @@ static int proto_tls_send(struct socket_info* send_sock,

LM_DBG("sending via fd %d...\n",fd);

lock_get(&c->write_lock);
n = tls_blocking_write(c, fd, buf, len, &tls_mgm_api);
lock_release(&c->write_lock);
tcp_conn_set_lifetime( c, tcp_con_lifetime);

LM_DBG("after write: c= %p n=%d fd=%d\n",c, n, fd);
Expand Down
4 changes: 4 additions & 0 deletions modules/proto_wss/proto_wss.c
Expand Up @@ -608,6 +608,7 @@ static int wss_raw_writev(struct tcp_connection *c, int fd,
#endif

#ifndef TLS_DONT_WRITE_FRAGMENTS
lock_get(&c->write_lock);
for (i = 0; i < iovcnt; i++) {
n = tls_blocking_write(c, fd, iov[i].iov_base, iov[i].iov_len, &tls_mgm_api);
if (n < 0) {
Expand All @@ -616,6 +617,7 @@ static int wss_raw_writev(struct tcp_connection *c, int fd,
}
ret += n;
}
lock_release(&c->write_lock);
#else
n = 0;
for (i = 0; i < iovcnt; i++)
Expand All @@ -630,7 +632,9 @@ static int wss_raw_writev(struct tcp_connection *c, int fd,
memcpy(buf + n, iov[i].iov_base, iov[i].iov_len);
n += iov[i].iov_len;
}
lock_get(&c->write_lock);
n = tls_blocking_write(c, fd, buf, n, &tls_mgm_api);
lock_release(&c->write_lock);

#endif /* TLS_DONT_WRITE_FRAGMENTS */

Expand Down
4 changes: 0 additions & 4 deletions modules/tls_mgm/tls_conn_server.h
Expand Up @@ -558,8 +558,6 @@ static int tls_blocking_write(struct tcp_connection *c, int fd, const char *buf,
goto error;
}

lock_get(&c->write_lock);

if (tls_update_fd(c, fd) < 0)
goto error;

Expand Down Expand Up @@ -610,7 +608,6 @@ static int tls_blocking_write(struct tcp_connection *c, int fd, const char *buf,
/*
* successful full write
*/
lock_release(&c->write_lock);
return written;
}

Expand Down Expand Up @@ -652,7 +649,6 @@ static int tls_blocking_write(struct tcp_connection *c, int fd, const char *buf,
}

error:
lock_release(&c->write_lock);
return -1;
}

Expand Down

0 comments on commit cf9c0f1

Please sign in to comment.