From 368780334cb1b4c46bcd666af353c177619f4774 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 22 Dec 2016 19:46:17 +0100 Subject: [PATCH] MEDIUM: compression: move the zlib-specific stuff from global.h to compression.c This finishes to clean up the zlib-specific parts. It also unbreaks recent commit b97c6fb ("CLEANUP: compression: use the build options list to report the algos") which broke USE_ZLIB due to MAXWBITS not being defined anymore in haproxy.c. --- include/types/global.h | 4 --- src/cfgparse.c | 48 ------------------------------ src/compression.c | 67 ++++++++++++++++++++++++++++++++++++++++-- src/haproxy.c | 8 ----- 4 files changed, 64 insertions(+), 63 deletions(-) diff --git a/include/types/global.h b/include/types/global.h index 9d71eca28a..0b6d4392a9 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -155,10 +155,6 @@ struct global { unsigned int ssl_max_record; /* SSL max record size */ unsigned int ssl_default_dh_param; /* SSL maximum DH parameter size */ int ssl_ctx_cache; /* max number of entries in the ssl_ctx cache. */ -#endif -#ifdef USE_ZLIB - int zlibmemlevel; /* zlib memlevel */ - int zlibwindowsize; /* zlib window size */ #endif int comp_maxlevel; /* max HTTP compression level */ unsigned short idle_timer; /* how long before an empty buffer is considered idle (ms) */ diff --git a/src/cfgparse.c b/src/cfgparse.c index 3ed2c2221d..e9876f8592 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -901,54 +901,6 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) } global.tune.max_http_hdr = atol(args[1]); } - else if (!strcmp(args[0], "tune.zlib.memlevel")) { -#ifdef USE_ZLIB - if (alertif_too_many_args(1, file, linenum, args, &err_code)) - goto out; - if (*args[1]) { - global.tune.zlibmemlevel = atoi(args[1]); - if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { - Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", - file, linenum, args[0]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - } else { - Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", - file, linenum, args[0]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } -#else - Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; -#endif - } - else if (!strcmp(args[0], "tune.zlib.windowsize")) { -#ifdef USE_ZLIB - if (alertif_too_many_args(1, file, linenum, args, &err_code)) - goto out; - if (*args[1]) { - global.tune.zlibwindowsize = atoi(args[1]); - if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { - Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", - file, linenum, args[0]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - } else { - Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", - file, linenum, args[0]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } -#else - Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; -#endif - } else if (!strcmp(args[0], "tune.comp.maxlevel")) { if (alertif_too_many_args(1, file, linenum, args, &err_code)) goto out; diff --git a/src/compression.c b/src/compression.c index 4ce26ec8b8..27ab7f785a 100644 --- a/src/compression.c +++ b/src/compression.c @@ -26,6 +26,7 @@ #undef free_func #endif /* USE_ZLIB */ +#include #include #include @@ -53,6 +54,9 @@ static struct pool_head *zlib_pool_pending_buf = NULL; long zlib_used_memory = 0; +static int global_tune_zlibmemlevel = 8; /* zlib memlevel */ +static int global_tune_zlibwindowsize = MAX_WBITS; /* zlib window size */ + #endif unsigned int compress_min_idle = 0; @@ -479,7 +483,7 @@ static int gzip_init(struct comp_ctx **comp_ctx, int level) strm = &(*comp_ctx)->strm; - if (deflateInit2(strm, level, Z_DEFLATED, global.tune.zlibwindowsize + 16, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) { + if (deflateInit2(strm, level, Z_DEFLATED, global_tune_zlibwindowsize + 16, global_tune_zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) { deinit_comp_ctx(comp_ctx); return -1; } @@ -499,7 +503,7 @@ static int raw_def_init(struct comp_ctx **comp_ctx, int level) strm = &(*comp_ctx)->strm; - if (deflateInit2(strm, level, Z_DEFLATED, -global.tune.zlibwindowsize, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) { + if (deflateInit2(strm, level, Z_DEFLATED, -global_tune_zlibwindowsize, global_tune_zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) { deinit_comp_ctx(comp_ctx); return -1; } @@ -521,7 +525,7 @@ static int deflate_init(struct comp_ctx **comp_ctx, int level) strm = &(*comp_ctx)->strm; - if (deflateInit2(strm, level, Z_DEFLATED, global.tune.zlibwindowsize, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) { + if (deflateInit2(strm, level, Z_DEFLATED, global_tune_zlibwindowsize, global_tune_zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) { deinit_comp_ctx(comp_ctx); return -1; } @@ -619,8 +623,61 @@ static int deflate_end(struct comp_ctx **comp_ctx) return ret; } +/* config parser for global "tune.zlibmemlevel" */ +static int zlib_parse_global_memlevel(char **args, int section_type, struct proxy *curpx, + struct proxy *defpx, const char *file, int line, + char **err) +{ + if (too_many_args(1, args, err, NULL)) + return -1; + + if (*(args[1]) == 0) { + memprintf(err, "'%s' expects a numeric value between 1 and 9.", args[0]); + return -1; + } + + global_tune_zlibmemlevel = atoi(args[1]); + if (global_tune_zlibmemlevel < 1 || global_tune_zlibmemlevel > 9) { + memprintf(err, "'%s' expects a numeric value between 1 and 9.", args[0]); + return -1; + } + return 0; +} + + +/* config parser for global "tune.zlibwindowsize" */ +static int zlib_parse_global_windowsize(char **args, int section_type, struct proxy *curpx, + struct proxy *defpx, const char *file, int line, + char **err) +{ + if (too_many_args(1, args, err, NULL)) + return -1; + + if (*(args[1]) == 0) { + memprintf(err, "'%s' expects a numeric value between 8 and 15.", args[0]); + return -1; + } + + global_tune_zlibwindowsize = atoi(args[1]); + if (global_tune_zlibwindowsize < 8 || global_tune_zlibwindowsize > 15) { + memprintf(err, "'%s' expects a numeric value between 8 and 15.", args[0]); + return -1; + } + return 0; +} + #endif /* USE_ZLIB */ + +/* config keyword parsers */ +static struct cfg_kw_list cfg_kws = {ILH, { +#ifdef USE_ZLIB + { CFG_GLOBAL, "tune.zlib.memlevel", zlib_parse_global_memlevel }, + { CFG_GLOBAL, "tune.zlib.windowsize", zlib_parse_global_windowsize }, +#endif + { 0, NULL, NULL } +}}; + __attribute__((constructor)) static void __comp_fetch_init(void) { @@ -631,6 +688,9 @@ static void __comp_fetch_init(void) slz_make_crc_table(); slz_prepare_dist_table(); #endif +#if defined(USE_ZLIB) && defined(DEFAULT_MAXZLIBMEM) + global.tune.maxzlibmem = DEFAULT_MAXZLIBMEM * 1024U * 1024U, +#endif #ifdef USE_ZLIB memprintf(&ptr, "Built with zlib version : " ZLIB_VERSION); memprintf(&ptr, "%s\nRunning on zlib version : %s", ptr, zlibVersion()); @@ -646,4 +706,5 @@ static void __comp_fetch_init(void) memprintf(&ptr, "%s none", ptr); hap_register_build_opts(ptr, 1); + cfg_register_keywords(&cfg_kws); } diff --git a/src/haproxy.c b/src/haproxy.c index 239db80855..ef846fe4e2 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -123,11 +123,7 @@ struct global global = { .nbproc = 1, .req_count = 0, .logsrvs = LIST_HEAD_INIT(global.logsrvs), -#if defined(USE_ZLIB) && defined(DEFAULT_MAXZLIBMEM) - .maxzlibmem = DEFAULT_MAXZLIBMEM * 1024U * 1024U, -#else .maxzlibmem = 0, -#endif .comp_rate_lim = 0, .ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED, .unix_bind = { @@ -150,10 +146,6 @@ struct global global = { .ssl_max_record = DEFAULT_SSL_MAX_RECORD, #endif .ssl_ctx_cache = DEFAULT_SSL_CTX_CACHE, -#endif -#ifdef USE_ZLIB - .zlibmemlevel = 8, - .zlibwindowsize = MAX_WBITS, #endif .comp_maxlevel = 1, #ifdef DEFAULT_IDLE_TIMER -- 2.39.5