@cryptotaxi247 / netdata-1 / commits / dd3b914ed

Misc SSL improvements 3 (#14602)

* go to normal only if its in stream mode * use ssl specific flags for wait receive and send * remove brackets

Emmanuel Vasilakis committed Feb 28, 2023 at 17:34 UTC dd3b914ed5dfb12fa816c7ae086c57b7702f2821
3 files changed +20 -12
web/server/static/static-threaded.c
+2 -5
@@ -293,9 +293,6 @@ static int web_server_rcv_callback(POLLINFO *pi, short int *events) {
293 struct web_client *w = (struct web_client *)pi->data;
294 int fd = pi->fd;
295
296 - web_client_disable_wait_receive(w);
297 - web_client_disable_wait_send(w);
298 -
296 ssize_t bytes;
297 bytes = web_client_receive(w);
298
@@ -354,10 +351,10 @@ static int web_server_rcv_callback(POLLINFO *pi, short int *events) {
351 ret = -1;
352 goto cleanup;
353 } else if (unlikely(bytes == 0)) {
357 - if(unlikely(w->ifd == fd && web_client_has_wait_receive(w)))
354 + if(unlikely(w->ifd == fd && web_client_has_ssl_wait_receive(w)))
355 *events |= POLLIN;
356
360 - if(unlikely(w->ofd == fd && web_client_has_wait_send(w)))
357 + if(unlikely(w->ofd == fd && web_client_has_ssl_wait_send(w)))
358 *events |= POLLOUT;
359 }
360
web/server/web_client.c
+7 -7
@@ -41,12 +41,12 @@ static inline int web_client_crock_socket(struct web_client *w) {
41 static inline void web_client_enable_wait_from_ssl(struct web_client *w, int bytes) {
42 int ssl_err = SSL_get_error(w->ssl.conn, bytes);
43 if (ssl_err == SSL_ERROR_WANT_READ)
44 - web_client_enable_wait_receive(w);
44 + web_client_enable_ssl_wait_receive(w);
45 else if (ssl_err == SSL_ERROR_WANT_WRITE)
46 - web_client_enable_wait_send(w);
47 - else if (ssl_err) {
48 - web_client_disable_wait_receive(w);
49 - web_client_disable_wait_send(w);
46 + web_client_enable_ssl_wait_send(w);
47 + else {
48 + web_client_disable_ssl_wait_receive(w);
49 + web_client_disable_ssl_wait_send(w);
50 }
51 }
52
@@ -955,7 +955,6 @@ static inline HTTP_VALIDATION http_request_validate(struct web_client *w) {
955 return HTTP_VALIDATION_NOT_SUPPORTED;
956 }
957 }
958 -
958 web_client_enable_wait_receive(w);
959 return HTTP_VALIDATION_INCOMPLETE;
960 }
@@ -1528,7 +1527,8 @@ void web_client_process_request(struct web_client *w) {
1527 // wait for more data
1528 // set to normal to prevent web_server_rcv_callback
1529 // from going into stream mode
1531 - w->mode = WEB_CLIENT_MODE_NORMAL;
1530 + if (w->mode == WEB_CLIENT_MODE_STREAM)
1531 + w->mode = WEB_CLIENT_MODE_NORMAL;
1532 return;
1533 }
1534 break;
web/server/web_client.h
+11
@@ -71,6 +71,9 @@ typedef enum web_client_flags {
71 WEB_CLIENT_FLAG_DONT_CLOSE_SOCKET = 1 << 9, // don't close the socket when cleaning up (static-threaded web server)
72
73 WEB_CLIENT_CHUNKED_TRANSFER = 1 << 10, // chunked transfer (used with zlib compression)
74 +
75 + WEB_CLIENT_FLAG_SSL_WAIT_RECEIVE = 1 << 11, // if set, we are waiting more input data from an ssl conn
76 + WEB_CLIENT_FLAG_SSL_WAIT_SEND = 1 << 12, // if set, we have data to send to the client from an ssl conn
77 } WEB_CLIENT_FLAGS;
78
79 #define web_client_flag_check(w, flag) ((w)->flags & (flag))
@@ -100,6 +103,14 @@ typedef enum web_client_flags {
103 #define web_client_enable_wait_send(w) web_client_flag_set(w, WEB_CLIENT_FLAG_WAIT_SEND)
104 #define web_client_disable_wait_send(w) web_client_flag_clear(w, WEB_CLIENT_FLAG_WAIT_SEND)
105
106 +#define web_client_has_ssl_wait_receive(w) web_client_flag_check(w, WEB_CLIENT_FLAG_SSL_WAIT_RECEIVE)
107 +#define web_client_enable_ssl_wait_receive(w) web_client_flag_set(w, WEB_CLIENT_FLAG_SSL_WAIT_RECEIVE)
108 +#define web_client_disable_ssl_wait_receive(w) web_client_flag_clear(w, WEB_CLIENT_FLAG_SSL_WAIT_RECEIVE)
109 +
110 +#define web_client_has_ssl_wait_send(w) web_client_flag_check(w, WEB_CLIENT_FLAG_SSL_WAIT_SEND)
111 +#define web_client_enable_ssl_wait_send(w) web_client_flag_set(w, WEB_CLIENT_FLAG_SSL_WAIT_SEND)
112 +#define web_client_disable_ssl_wait_send(w) web_client_flag_clear(w, WEB_CLIENT_FLAG_SSL_WAIT_SEND)
113 +
114 #define web_client_set_tcp(w) web_client_flag_set(w, WEB_CLIENT_FLAG_TCP_CLIENT)
115 #define web_client_set_unix(w) web_client_flag_set(w, WEB_CLIENT_FLAG_UNIX_CLIENT)
116 #define web_client_check_unix(w) web_client_flag_check(w, WEB_CLIENT_FLAG_UNIX_CLIENT)