mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-03-14 14:58:06 +08:00
Allow compression to fail, and in that case send uncompressed packets
That allows to cancel compression early, if it seems to expand the packet. Suggested by David Woodhouse.
This commit is contained in:
@@ -299,9 +299,9 @@ int lz4_decompress(void *dst, int dstlen, const void *src, int srclen)
|
|||||||
static
|
static
|
||||||
int lz4_compress(void *dst, int dstlen, const void *src, int srclen)
|
int lz4_compress(void *dst, int dstlen, const void *src, int srclen)
|
||||||
{
|
{
|
||||||
if (dstlen < LZ4_compressBound(srclen))
|
/* we intentionally restrict output to srclen so that
|
||||||
return -1;
|
* compression fails early for packets that expand. */
|
||||||
return LZ4_compress(src, dst, srclen);
|
return LZ4_compress_limitedOutput(src, dst, srclen, srclen);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1235,12 +1235,7 @@ static int tun_mainloop(struct worker_st *ws, struct timespec *tnow)
|
|||||||
if (ws->udp_state == UP_ACTIVE && ws->dtls_selected_comp != NULL && l > MIN_COMPRESSED_SIZE) {
|
if (ws->udp_state == UP_ACTIVE && ws->dtls_selected_comp != NULL && l > MIN_COMPRESSED_SIZE) {
|
||||||
/* otherwise don't compress */
|
/* otherwise don't compress */
|
||||||
ret = ws->dtls_selected_comp->compress(ws->decomp+8, sizeof(ws->decomp)-8, ws->buffer, l);
|
ret = ws->dtls_selected_comp->compress(ws->decomp+8, sizeof(ws->decomp)-8, ws->buffer, l);
|
||||||
if (ret <= 0) {
|
if (ret > 0 && ret < l) {
|
||||||
oclog(ws, LOG_ERR, "error in %s compression %d\n", ws->dtls_selected_comp->name, ret);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret < l) {
|
|
||||||
dtls_to_send.data = ws->decomp;
|
dtls_to_send.data = ws->decomp;
|
||||||
dtls_to_send.size = ret;
|
dtls_to_send.size = ret;
|
||||||
dtls_type = AC_PKT_COMPRESSED;
|
dtls_type = AC_PKT_COMPRESSED;
|
||||||
@@ -1256,12 +1251,7 @@ static int tun_mainloop(struct worker_st *ws, struct timespec *tnow)
|
|||||||
} else if (ws->cstp_selected_comp != NULL && l > MIN_COMPRESSED_SIZE) {
|
} else if (ws->cstp_selected_comp != NULL && l > MIN_COMPRESSED_SIZE) {
|
||||||
/* otherwise don't compress */
|
/* otherwise don't compress */
|
||||||
ret = ws->cstp_selected_comp->compress(ws->decomp+8, sizeof(ws->decomp)-8, ws->buffer, l);
|
ret = ws->cstp_selected_comp->compress(ws->decomp+8, sizeof(ws->decomp)-8, ws->buffer, l);
|
||||||
if (ret <= 0) {
|
if (ret > 0 && ret < l) {
|
||||||
oclog(ws, LOG_ERR, "error in %s compression %d\n", ws->dtls_selected_comp->name, ret);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret < l) {
|
|
||||||
cstp_to_send.data = ws->decomp;
|
cstp_to_send.data = ws->decomp;
|
||||||
cstp_to_send.size = ret;
|
cstp_to_send.size = ret;
|
||||||
cstp_type = AC_PKT_COMPRESSED;
|
cstp_type = AC_PKT_COMPRESSED;
|
||||||
|
|||||||
Reference in New Issue
Block a user