summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzuul <zuul@gerrit.asterisk.org>2017-03-20 11:50:50 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2017-03-20 11:50:50 -0500
commit74f59af52acef316b7a02646e64207ef0674dcb1 (patch)
tree0add9f07c3492e91f4b0245889760efc374834bd
parenta38a44880a4ce9d5d3ce4915635d1f40c47b1e84 (diff)
parent75c4b1c97d4fde7fac285e7d3b6a57fd34ceae0a (diff)
Merge "thread safety: Don't use getprotobyname()" into 14
-rw-r--r--channels/chan_skinny.c9
-rw-r--r--include/asterisk/network.h5
-rw-r--r--main/http.c16
-rw-r--r--main/manager.c13
4 files changed, 14 insertions, 29 deletions
diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c
index 56e659690..96a206c37 100644
--- a/channels/chan_skinny.c
+++ b/channels/chan_skinny.c
@@ -7641,7 +7641,6 @@ static void *accept_thread(void *ignore)
struct sockaddr_in sin;
socklen_t sinlen;
struct skinnysession *s;
- struct protoent *p;
int arg = 1;
for (;;) {
@@ -7658,12 +7657,10 @@ static void *accept_thread(void *ignore)
continue;
}
- p = getprotobyname("tcp");
- if(p) {
- if( setsockopt(as, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) {
- ast_log(LOG_WARNING, "Failed to set Skinny tcp connection to TCP_NODELAY mode: %s\n", strerror(errno));
- }
+ if (setsockopt(as, IPPROTO_TCP, TCP_NODELAY, (char *) &arg, sizeof(arg)) < 0) {
+ ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on Skinny TCP connection: %s\n", strerror(errno));
}
+
if (!(s = ast_calloc(1, sizeof(struct skinnysession)))) {
close(as);
ast_atomic_fetchadd_int(&unauth_sessions, -1);
diff --git a/include/asterisk/network.h b/include/asterisk/network.h
index 3371e5895..5216f4c61 100644
--- a/include/asterisk/network.h
+++ b/include/asterisk/network.h
@@ -86,6 +86,11 @@ const char *ast_inet_ntoa(struct in_addr ia);
#endif
#define inet_ntoa __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__
+#ifdef getprotobyname
+#undef getprotobyname
+#endif
+#define getprotobyname __getprotobyname_is_not_threadsafe__do_not_use__
+
/*! \brief Compares the source address and port of two sockaddr_in */
static force_inline int inaddrcmp(const struct sockaddr_in *sin1, const struct sockaddr_in *sin2)
{
diff --git a/main/http.c b/main/http.c
index 5f308c358..7565523de 100644
--- a/main/http.c
+++ b/main/http.c
@@ -1915,8 +1915,7 @@ static int httpd_process_request(struct ast_tcptls_session_instance *ser)
static void *httpd_helper_thread(void *data)
{
struct ast_tcptls_session_instance *ser = data;
- struct protoent *p;
- int flags;
+ int flags = 1;
int timeout;
if (!ser || !ser->f) {
@@ -1936,17 +1935,8 @@ static void *httpd_helper_thread(void *data)
* This is necessary to prevent delays (caused by buffering) as we
* write to the socket in bits and pieces.
*/
- p = getprotobyname("tcp");
- if (p) {
- int arg = 1;
-
- if (setsockopt(ser->fd, p->p_proto, TCP_NODELAY, (char *) &arg, sizeof(arg) ) < 0) {
- ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection: %s\n", strerror(errno));
- ast_log(LOG_WARNING, "Some HTTP requests may be slow to respond.\n");
- }
- } else {
- ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection, getprotobyname(\"tcp\") failed\n");
- ast_log(LOG_WARNING, "Some HTTP requests may be slow to respond.\n");
+ if (setsockopt(ser->fd, IPPROTO_TCP, TCP_NODELAY, (char *) &flags, sizeof(flags)) < 0) {
+ ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection: %s\n", strerror(errno));
}
/* make sure socket is non-blocking */
diff --git a/main/manager.c b/main/manager.c
index 91b401c74..c7f4092ac 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -6633,10 +6633,9 @@ static void *session_do(void *data)
struct mansession s = {
.tcptls_session = data,
};
- int flags;
+ int flags = 1;
int res;
struct ast_sockaddr ser_remote_address_tmp;
- struct protoent *p;
if (ast_atomic_fetchadd_int(&unauth_sessions, +1) >= authlimit) {
fclose(ser->f);
@@ -6656,14 +6655,8 @@ static void *session_do(void *data)
/* here we set TCP_NODELAY on the socket to disable Nagle's algorithm.
* This is necessary to prevent delays (caused by buffering) as we
* write to the socket in bits and pieces. */
- p = getprotobyname("tcp");
- if (p) {
- int arg = 1;
- if( setsockopt(ser->fd, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) {
- ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY mode: %s\nSome manager actions may be slow to respond.\n", strerror(errno));
- }
- } else {
- ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY, getprotobyname(\"tcp\") failed\nSome manager actions may be slow to respond.\n");
+ if (setsockopt(ser->fd, IPPROTO_TCP, TCP_NODELAY, (char *) &flags, sizeof(flags)) < 0) {
+ ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on manager connection: %s\n", strerror(errno));
}
/* make sure socket is non-blocking */