diff --git a/haproxy-lua/activate.sh b/haproxy-lua/activate.sh index 03076b0..82ea9f9 100755 --- a/haproxy-lua/activate.sh +++ b/haproxy-lua/activate.sh @@ -1,8 +1,16 @@ #!/usr/bin/bash set -e - -WEIR_HAPROXY_BASE_COMMIT=v3.3.0 +WEIR_HAPROXY_BASE_COMMIT=v3.2.15 +# Use the major.minor series (for example, 3.3) for the upstream repo name. +# Accept commit tags in form v.. or ... +if [[ "$WEIR_HAPROXY_BASE_COMMIT" =~ ^v?([0-9]+\.[0-9]+)\.[0-9]+$ ]]; then + WEIR_HAPROXY_SERIES=${BASH_REMATCH[1]} +else + echo "Invalid WEIR_HAPROXY_BASE_COMMIT: $WEIR_HAPROXY_BASE_COMMIT" + echo "Expected format: [v].. (for example, v3.3.6 or 3.3.6)" + exit 1 +fi SCRIPT_DIR=$(dirname "$0") HAPROXY_SOURCE_DIR=$SCRIPT_DIR/haproxy-source @@ -10,7 +18,7 @@ HAPROXY_SOURCE_DIR=$SCRIPT_DIR/haproxy-source if [[ -d "$HAPROXY_SOURCE_DIR" ]]; then echo "HAProxy directory already exists @ $HAPROXY_SOURCE_DIR, skipping clone step..." else - git clone "${WEIR_HAPROXY_REPO_URL:-https://github.com/haproxy/haproxy.git}" "$HAPROXY_SOURCE_DIR" + git clone "${WEIR_HAPROXY_REPO_URL:-https://git.haproxy.org/git/haproxy-$WEIR_HAPROXY_SERIES.git}" "$HAPROXY_SOURCE_DIR" fi if (! git -C "$HAPROXY_SOURCE_DIR" diff --quiet) || (! git -C "$HAPROXY_SOURCE_DIR" diff --staged --quiet); then @@ -20,8 +28,26 @@ fi # Store the commit on which our local changes are based, so that we know which commits need to be # turned into patches when we later run the `deactivate` script. -git -C "$HAPROXY_SOURCE_DIR" checkout $WEIR_HAPROXY_BASE_COMMIT -git -C "$HAPROXY_SOURCE_DIR" show-ref -s $WEIR_HAPROXY_BASE_COMMIT > "$SCRIPT_DIR"/.haproxy-activated-commit +HAPROXY_BASE_REF="$WEIR_HAPROXY_BASE_COMMIT" + +# Ensure the requested base ref exists locally before checkout. +# If missing, fetch tags from the upstream series repo and retry once. +if ! git -C "$HAPROXY_SOURCE_DIR" rev-parse --verify --quiet "$HAPROXY_BASE_REF^{commit}" >/dev/null; then + SERIES_REPO_URL="https://git.haproxy.org/git/haproxy-$WEIR_HAPROXY_SERIES.git" + ORIGIN_URL=$(git -C "$HAPROXY_SOURCE_DIR" config --get remote.origin.url || true) + echo "HAProxy base ref '$HAPROXY_BASE_REF' not found in '$ORIGIN_URL'. Fetching tags from '$SERIES_REPO_URL'..." + git -C "$HAPROXY_SOURCE_DIR" fetch --tags "$SERIES_REPO_URL" + + # Fail fast if the ref still does not resolve after tag refresh. + if ! git -C "$HAPROXY_SOURCE_DIR" rev-parse --verify --quiet "$HAPROXY_BASE_REF^{commit}" >/dev/null; then + echo "Unable to resolve HAProxy base ref '$HAPROXY_BASE_REF'." + echo "If this is a new release, update WEIR_HAPROXY_BASE_COMMIT to a ref that exists in upstream." + exit 1 + fi +fi + +git -C "$HAPROXY_SOURCE_DIR" checkout "$HAPROXY_BASE_REF" +git -C "$HAPROXY_SOURCE_DIR" rev-parse "$HAPROXY_BASE_REF^{commit}" > "$SCRIPT_DIR"/.haproxy-activated-commit # Enable ** for directory expansion in globs, and allow zero matches to result in an empty list shopt -s globstar nullglob diff --git a/haproxy-lua/patches/0001-Initial-commit-of-Weir-QoS.patch b/haproxy-lua/patches/0001-Initial-commit-of-Weir-QoS.patch index bd6868b..fcf1756 100644 --- a/haproxy-lua/patches/0001-Initial-commit-of-Weir-QoS.patch +++ b/haproxy-lua/patches/0001-Initial-commit-of-Weir-QoS.patch @@ -5,26 +5,26 @@ Subject: [PATCH] Initial commit of Weir QoS --- Makefile | 1 + - src/hlua.c | 30 ++++++++++++++++++++++++++++++ - 2 files changed, 31 insertions(+) + src/hlua.c | 31 +++++++++++++++++++++++++++++++ + 2 files changed, 32 insertions(+) diff --git a/Makefile b/Makefile -index 90e791f39..e6be08e58 100644 +index 1959ac479..3a099edbc 100644 --- a/Makefile +++ b/Makefile -@@ -1003,6 +1003,7 @@ OBJS += src/mux_h2.o src/mux_h1.o src/mux_fcgi.o src/log.o \ +@@ -993,6 +993,7 @@ OBJS += src/mux_h2.o src/mux_h1.o src/mux_fcgi.o src/log.o \ src/http_acl.o src/dict.o src/dgram.o src/pipe.o \ src/hpack-huff.o src/hpack-enc.o src/ebtree.o src/hash.o \ - src/httpclient_cli.o src/version.o src/ncbmbuf.o src/ech.o + src/version.o src/ncbmbuf.o +OBJS += src/flt_weir.o ifneq ($(TRACE),) OBJS += src/calltrace.o diff --git a/src/hlua.c b/src/hlua.c -index ec2a8ee7b..2332e29c3 100644 +index 9699936e8..875f6113d 100644 --- a/src/hlua.c +++ b/src/hlua.c -@@ -14010,6 +14010,35 @@ static void *hlua_alloc(void *ud, void *ptr, size_t osize, size_t nsize) +@@ -14038,6 +14038,35 @@ static void *hlua_alloc(void *ud, void *ptr, size_t osize, size_t nsize) return ptr; } @@ -60,10 +60,10 @@ index ec2a8ee7b..2332e29c3 100644 /* This function can fail with an abort() due to a Lua critical error. * We are in the initialisation process of HAProxy, this abort() is * tolerated. -@@ -14132,6 +14161,7 @@ lua_State *hlua_init_state(int thread_num) +@@ -14160,6 +14189,7 @@ lua_State *hlua_init_state(int thread_num) hlua_class_function(L, "Alert", hlua_log_alert); hlua_class_function(L, "done", hlua_done); - hlua_class_function(L, "use_native_mailers_config", hlua_use_native_mailers_config); + hlua_class_function(L, "disable_legacy_mailers", hlua_disable_legacy_mailers); + hlua_class_function(L, "ingest_weir_limit_share_update", hlua_ingest_weir_limit_share_update); hlua_fcn_reg_core_fcn(L); diff --git a/haproxy-lua/patches/0002-Add-old-rate-limit-system-specific-hlua-and-Makefile.patch b/haproxy-lua/patches/0002-Add-old-rate-limit-system-specific-hlua-and-Makefile.patch index 01aac9a..3778158 100644 --- a/haproxy-lua/patches/0002-Add-old-rate-limit-system-specific-hlua-and-Makefile.patch +++ b/haproxy-lua/patches/0002-Add-old-rate-limit-system-specific-hlua-and-Makefile.patch @@ -5,24 +5,24 @@ Subject: [PATCH] Add old-rate-limit-system-specific hlua and Makefile changes --- Makefile | 2 +- - src/hlua.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ - 2 files changed, 101 insertions(+), 1 deletion(-) + src/hlua.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++- + 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile -index e6be08e58..1e86ba270 100644 +index 3a099edbc..413534fa1 100644 --- a/Makefile +++ b/Makefile -@@ -1003,7 +1003,7 @@ OBJS += src/mux_h2.o src/mux_h1.o src/mux_fcgi.o src/log.o \ +@@ -993,7 +993,7 @@ OBJS += src/mux_h2.o src/mux_h1.o src/mux_fcgi.o src/log.o \ src/http_acl.o src/dict.o src/dgram.o src/pipe.o \ src/hpack-huff.o src/hpack-enc.o src/ebtree.o src/hash.o \ - src/httpclient_cli.o src/version.o src/ncbmbuf.o src/ech.o + src/version.o src/ncbmbuf.o -OBJS += src/flt_weir.o +OBJS += src/flt_weir.o src/rate_limit.o ifneq ($(TRACE),) OBJS += src/calltrace.o diff --git a/src/hlua.c b/src/hlua.c -index 2332e29c3..f47693239 100644 +index 875f6113d..a9263daed 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -69,6 +69,7 @@ @@ -33,7 +33,7 @@ index 2332e29c3..f47693239 100644 /* Global LUA flags */ -@@ -14039,6 +14040,100 @@ __LJMP static int hlua_ingest_weir_limit_share_update(lua_State *L) +@@ -14067,5 +14068,99 @@ __LJMP static int hlua_ingest_weir_limit_share_update(lua_State *L) return 1; } @@ -62,8 +62,8 @@ index 2332e29c3..f47693239 100644 + lua_pushboolean(L, 1); + return 1; + } -+ lua_pushboolean(L, 0); + ++ lua_pushboolean(L, 0); + return 1; +} + @@ -133,10 +133,9 @@ index 2332e29c3..f47693239 100644 + /* This function can fail with an abort() due to a Lua critical error. * We are in the initialisation process of HAProxy, this abort() is - * tolerated. -@@ -14162,6 +14257,9 @@ lua_State *hlua_init_state(int thread_num) +@@ -14191,6 +14286,9 @@ lua_State *hlua_init_state(int thread_num) hlua_class_function(L, "done", hlua_done); - hlua_class_function(L, "use_native_mailers_config", hlua_use_native_mailers_config); + hlua_class_function(L, "disable_legacy_mailers", hlua_disable_legacy_mailers); hlua_class_function(L, "ingest_weir_limit_share_update", hlua_ingest_weir_limit_share_update); + hlua_class_function(L, "throttle_key_speed", hlua_throttle_key_speed); + hlua_class_function(L, "printout_speed_table", hlua_printout_speed_table); @@ -144,7 +143,7 @@ index 2332e29c3..f47693239 100644 hlua_fcn_reg_core_fcn(L); lua_setglobal(L, "core"); -@@ -14410,6 +14508,7 @@ lua_State *hlua_init_state(int thread_num) +@@ -14439,6 +14537,7 @@ lua_State *hlua_init_state(int thread_num) hlua_class_function(L, "req_set_path", hlua_http_req_set_path); hlua_class_function(L, "req_set_query", hlua_http_req_set_query); hlua_class_function(L, "req_set_uri", hlua_http_req_set_uri); @@ -152,10 +151,11 @@ index 2332e29c3..f47693239 100644 hlua_class_function(L, "res_get_headers",hlua_http_res_get_headers); hlua_class_function(L, "res_del_header", hlua_http_res_del_hdr); -@@ -14419,6 +14518,7 @@ lua_State *hlua_init_state(int thread_num) +@@ -14447,7 +14546,7 @@ lua_State *hlua_init_state(int thread_num) + hlua_class_function(L, "res_add_header", hlua_http_res_add_hdr); hlua_class_function(L, "res_set_header", hlua_http_res_set_hdr); hlua_class_function(L, "res_set_status", hlua_http_res_set_status); - +- + hlua_class_function(L, "res_get_status", hlua_http_res_get_status); lua_rawset(L, -3);