From 635ab1b77b06a8891479a46a0e1ba88315ff3958 Mon Sep 17 00:00:00 2001 From: Dmitry Pokrovsky Date: Wed, 12 Jun 2024 21:39:31 +0300 Subject: 1. Fixes the issue #124 "HTTP replay for non SSTP query" 2. Fixes log_debug2 in Triton lib --- accel-pppd/ctrl/sstp/sstp.c | 77 +++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 38 deletions(-) (limited to 'accel-pppd/ctrl') diff --git a/accel-pppd/ctrl/sstp/sstp.c b/accel-pppd/ctrl/sstp/sstp.c index 2e2c4d3b..e21a7769 100644 --- a/accel-pppd/ctrl/sstp/sstp.c +++ b/accel-pppd/ctrl/sstp/sstp.c @@ -1925,6 +1925,44 @@ static int sstp_handler(struct sstp_conn_t *conn, struct buffer_t *buf) return 0; } +static int sstp_write(struct triton_md_handler_t *h) +{ + struct sstp_conn_t *conn = container_of(h, typeof(*conn), hnd); + struct buffer_t *buf; + int n; + + while (!list_empty(&conn->out_queue)) { + buf = list_first_entry(&conn->out_queue, typeof(*buf), entry); + while (buf->len) { + n = conn->stream->write(conn->stream, buf->head, buf->len); + if (n < 0) { + if (errno == EINTR) + continue; + if (errno == EAGAIN) + goto defer; + if (conf_verbose && errno != EPIPE) + log_ppp_info2("sstp: write: %s\n", strerror(errno)); + goto drop; + } else if (n == 0) + goto defer; + buf_pull(buf, n); + } + list_del(&buf->entry); + free_buf(buf); + } + + triton_md_disable_handler(h, MD_MODE_WRITE); + return 0; + +defer: + triton_md_enable_handler(h, MD_MODE_WRITE); + return 0; + +drop: + triton_context_call(&conn->ctx, (triton_event_func)sstp_disconnect, conn); + return 1; +} + static int sstp_read(struct triton_md_handler_t *h) { struct sstp_conn_t *conn = container_of(h, typeof(*conn), hnd); @@ -1956,6 +1994,7 @@ static int sstp_read(struct triton_md_handler_t *h) return 0; drop: + n = sstp_write(h); sstp_disconnect(conn); return 1; } @@ -2049,44 +2088,6 @@ drop: return 1; } -static int sstp_write(struct triton_md_handler_t *h) -{ - struct sstp_conn_t *conn = container_of(h, typeof(*conn), hnd); - struct buffer_t *buf; - int n; - - while (!list_empty(&conn->out_queue)) { - buf = list_first_entry(&conn->out_queue, typeof(*buf), entry); - while (buf->len) { - n = conn->stream->write(conn->stream, buf->head, buf->len); - if (n < 0) { - if (errno == EINTR) - continue; - if (errno == EAGAIN) - goto defer; - if (conf_verbose && errno != EPIPE) - log_ppp_info2("sstp: write: %s\n", strerror(errno)); - goto drop; - } else if (n == 0) - goto defer; - buf_pull(buf, n); - } - list_del(&buf->entry); - free_buf(buf); - } - - triton_md_disable_handler(h, MD_MODE_WRITE); - return 0; - -defer: - triton_md_enable_handler(h, MD_MODE_WRITE); - return 0; - -drop: - triton_context_call(&conn->ctx, (triton_event_func)sstp_disconnect, conn); - return 1; -} - static inline void sstp_queue(struct sstp_conn_t *conn, struct buffer_t *buf) { list_add_tail(&buf->entry, &conn->out_queue); -- cgit v1.2.3 From e7a0368462368d2b356eccdd738f776b85b1d4c3 Mon Sep 17 00:00:00 2001 From: Dmitry Pokrovsky Date: Fri, 14 Jun 2024 13:48:12 +0300 Subject: Revert "1. Fixes the issue #124 "HTTP replay for non SSTP query"" This reverts commit 635ab1b77b06a8891479a46a0e1ba88315ff3958. --- accel-pppd/ctrl/sstp/sstp.c | 77 ++++++++++++++++++++++----------------------- accel-pppd/triton/triton.c | 2 +- 2 files changed, 39 insertions(+), 40 deletions(-) (limited to 'accel-pppd/ctrl') diff --git a/accel-pppd/ctrl/sstp/sstp.c b/accel-pppd/ctrl/sstp/sstp.c index e21a7769..2e2c4d3b 100644 --- a/accel-pppd/ctrl/sstp/sstp.c +++ b/accel-pppd/ctrl/sstp/sstp.c @@ -1925,44 +1925,6 @@ static int sstp_handler(struct sstp_conn_t *conn, struct buffer_t *buf) return 0; } -static int sstp_write(struct triton_md_handler_t *h) -{ - struct sstp_conn_t *conn = container_of(h, typeof(*conn), hnd); - struct buffer_t *buf; - int n; - - while (!list_empty(&conn->out_queue)) { - buf = list_first_entry(&conn->out_queue, typeof(*buf), entry); - while (buf->len) { - n = conn->stream->write(conn->stream, buf->head, buf->len); - if (n < 0) { - if (errno == EINTR) - continue; - if (errno == EAGAIN) - goto defer; - if (conf_verbose && errno != EPIPE) - log_ppp_info2("sstp: write: %s\n", strerror(errno)); - goto drop; - } else if (n == 0) - goto defer; - buf_pull(buf, n); - } - list_del(&buf->entry); - free_buf(buf); - } - - triton_md_disable_handler(h, MD_MODE_WRITE); - return 0; - -defer: - triton_md_enable_handler(h, MD_MODE_WRITE); - return 0; - -drop: - triton_context_call(&conn->ctx, (triton_event_func)sstp_disconnect, conn); - return 1; -} - static int sstp_read(struct triton_md_handler_t *h) { struct sstp_conn_t *conn = container_of(h, typeof(*conn), hnd); @@ -1994,7 +1956,6 @@ static int sstp_read(struct triton_md_handler_t *h) return 0; drop: - n = sstp_write(h); sstp_disconnect(conn); return 1; } @@ -2088,6 +2049,44 @@ drop: return 1; } +static int sstp_write(struct triton_md_handler_t *h) +{ + struct sstp_conn_t *conn = container_of(h, typeof(*conn), hnd); + struct buffer_t *buf; + int n; + + while (!list_empty(&conn->out_queue)) { + buf = list_first_entry(&conn->out_queue, typeof(*buf), entry); + while (buf->len) { + n = conn->stream->write(conn->stream, buf->head, buf->len); + if (n < 0) { + if (errno == EINTR) + continue; + if (errno == EAGAIN) + goto defer; + if (conf_verbose && errno != EPIPE) + log_ppp_info2("sstp: write: %s\n", strerror(errno)); + goto drop; + } else if (n == 0) + goto defer; + buf_pull(buf, n); + } + list_del(&buf->entry); + free_buf(buf); + } + + triton_md_disable_handler(h, MD_MODE_WRITE); + return 0; + +defer: + triton_md_enable_handler(h, MD_MODE_WRITE); + return 0; + +drop: + triton_context_call(&conn->ctx, (triton_event_func)sstp_disconnect, conn); + return 1; +} + static inline void sstp_queue(struct sstp_conn_t *conn, struct buffer_t *buf) { list_add_tail(&buf->entry, &conn->out_queue); diff --git a/accel-pppd/triton/triton.c b/accel-pppd/triton/triton.c index 841bd008..395a42df 100644 --- a/accel-pppd/triton/triton.c +++ b/accel-pppd/triton/triton.c @@ -55,7 +55,7 @@ static __thread struct triton_context_t *this_ctx; static __thread jmp_buf jmp_env; static __thread void *thread_frame; -//#define log_debug2(fmt, ...) +#define log_debug2(fmt, ...) void triton_thread_wakeup(struct _triton_thread_t *thread) { -- cgit v1.2.3 From 382b02b6a123fd4d74099e163e54ea0663e9f956 Mon Sep 17 00:00:00 2001 From: Dmitry Pokrovsky Date: Fri, 14 Jun 2024 15:00:11 +0300 Subject: Fixes the issue #124 "HTTP replay for non SSTP query" --- accel-pppd/ctrl/sstp/sstp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'accel-pppd/ctrl') diff --git a/accel-pppd/ctrl/sstp/sstp.c b/accel-pppd/ctrl/sstp/sstp.c index 2e2c4d3b..63bde053 100644 --- a/accel-pppd/ctrl/sstp/sstp.c +++ b/accel-pppd/ctrl/sstp/sstp.c @@ -187,6 +187,7 @@ static unsigned int stat_active; static inline void sstp_queue(struct sstp_conn_t *conn, struct buffer_t *buf); static int sstp_send(struct sstp_conn_t *conn, struct buffer_t *buf); static inline void sstp_queue_deferred(struct sstp_conn_t *conn, struct buffer_t *buf); +static int sstp_write(struct triton_md_handler_t *h); static int sstp_read_deferred(struct sstp_conn_t *conn); static int sstp_abort(struct sstp_conn_t *conn, int disconnect); static void sstp_disconnect(struct sstp_conn_t *conn); @@ -858,7 +859,7 @@ static int http_send_response(struct sstp_conn_t *conn, char *proto, char *statu } } - return sstp_send(conn, buf); + return sstp_send(conn, buf) && sstp_write(&conn->hnd); } static int http_recv_request(struct sstp_conn_t *conn, uint8_t *data, int len) -- cgit v1.2.3 From 4fbba4715bd82a104713cf95b0ae2ac622968879 Mon Sep 17 00:00:00 2001 From: Dmitry Pokrovsky Date: Fri, 14 Jun 2024 16:17:56 +0300 Subject: Fixes the issue #124 "HTTP replay for non SSTP query" --- accel-pppd/ctrl/sstp/sstp.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'accel-pppd/ctrl') diff --git a/accel-pppd/ctrl/sstp/sstp.c b/accel-pppd/ctrl/sstp/sstp.c index 63bde053..2a9ddae3 100644 --- a/accel-pppd/ctrl/sstp/sstp.c +++ b/accel-pppd/ctrl/sstp/sstp.c @@ -859,7 +859,7 @@ static int http_send_response(struct sstp_conn_t *conn, char *proto, char *statu } } - return sstp_send(conn, buf) && sstp_write(&conn->hnd); + return sstp_send(conn, buf) || sstp_write(&conn->hnd); } static int http_recv_request(struct sstp_conn_t *conn, uint8_t *data, int len) @@ -938,7 +938,7 @@ static int http_handler(struct sstp_conn_t *conn, struct buffer_t *buf) static const char *table[] = { "\n\r\n", "\r\r\n", NULL }; const char **pptr; uint8_t *ptr, *end = NULL; - int n; + int n, r; if (conn->sstp_state != STATE_SERVER_CALL_DISCONNECTED) return -1; @@ -964,8 +964,11 @@ static int http_handler(struct sstp_conn_t *conn, struct buffer_t *buf) } else n = end - buf->head; - if (http_recv_request(conn, buf->head, n) < 0) + r = http_recv_request(conn, buf->head, n); + if (r < 0) return -1; + else if (r > 0) + return 1; buf_pull(buf, n); conn->sstp_state = STATE_SERVER_CONNECT_REQUEST_PENDING; @@ -1951,6 +1954,8 @@ static int sstp_read(struct triton_md_handler_t *h) n = conn->handler(conn, buf); if (n < 0) goto drop; + else if (n > 0) + return 1; buf_expand_tail(buf, SSTP_MAX_PACKET_SIZE); } -- cgit v1.2.3