From cc30a905568640bb0b07f75d701b285ba00a41b3 Mon Sep 17 00:00:00 2001 From: bol-van Date: Tue, 19 Nov 2024 14:01:24 +0300 Subject: [PATCH] tpws: check for kernel version in fixseg --- tpws/params.h | 1 + tpws/tpws.c | 4 +++- tpws/tpws_conn.c | 27 +++++++++++++++------------ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/tpws/params.h b/tpws/params.h index fca406f..7ffef07 100644 --- a/tpws/params.h +++ b/tpws/params.h @@ -105,6 +105,7 @@ struct params_s uint8_t proxy_type; unsigned int fix_seg; + bool fix_seg_avail; bool no_resolve; bool skip_nodelay; bool droproot; diff --git a/tpws/tpws.c b/tpws/tpws.c index e675877..3cf557c 100644 --- a/tpws/tpws.c +++ b/tpws/tpws.c @@ -538,6 +538,8 @@ void parse_params(int argc, char *argv[]) params.pf_enable = true; // OpenBSD and MacOS have no other choice #endif + params.fix_seg_avail = socket_supports_notsent(); + LIST_INIT(¶ms.hostlists); LIST_INIT(¶ms.ipsets); @@ -1236,7 +1238,7 @@ void parse_params(int argc, char *argv[]) } break; case 65: /* fix-seg */ - if (!socket_supports_notsent()) + if (!params.fix_seg_avail) { DLOG_ERR("--fix-seg is supported since kernel 4.6\n"); exit_clean(1); diff --git a/tpws/tpws_conn.c b/tpws/tpws_conn.c index 696da8a..9fc393e 100644 --- a/tpws/tpws_conn.c +++ b/tpws/tpws_conn.c @@ -1248,19 +1248,22 @@ static bool handle_epoll(tproxy_conn_t *conn, struct tailhead *conn_list, uint32 bApplyOOB = i==0 && (split_flags & SPLIT_FLAG_OOB); len = to-from; #ifdef __linux__ - if (params.fix_seg) + if (params.fix_seg_avail) { - unsigned int wasted; - bool bWaitOK = socket_wait_notsent(conn->partner->fd, params.fix_seg, &wasted); - if (wasted) - VPRINT("WARNING ! wasted %u ms to fix segmenation\n", wasted); - if (!bWaitOK) - report_segfail(); - } - else - { - if (socket_has_notsent(conn->partner->fd)) - report_segfail(); + if (params.fix_seg) + { + unsigned int wasted; + bool bWaitOK = socket_wait_notsent(conn->partner->fd, params.fix_seg, &wasted); + if (wasted) + VPRINT("WARNING ! wasted %u ms to fix segmenation\n", wasted); + if (!bWaitOK) + report_segfail(); + } + else + { + if (socket_has_notsent(conn->partner->fd)) + report_segfail(); + } } #endif VPRINT("Sending multisplit part %d %zd-%zd (len %zd)%s%s : ", i+1, from, to, len, bApplyDisorder ? " with disorder" : "", bApplyOOB ? " with OOB" : "");