From: Martin Mirchev Date: Wed, 18 Nov 2026 03:25:34 +0000 (+0800) Subject: BUG/MINOR: net_helper: accept an Ethernet header ending with the protocol X-Git-Url: https://git.kaiwu.me/http/ngx_http_auth_basic_module.html?a=commitdiff_plain;h=d9807b77dd8b5ee6eb092bf4a33e09c2ab4c4752;p=haproxy.git BUG/MINOR: net_helper: accept an Ethernet header ending with the protocol The eth.data, eth.hdr, eth.proto and eth.vlan converters walk the Ethernet header with "idx + 2 < data", which requires at least one byte after the 2-byte protocol field. An input that ends exactly with the header is thus reported as incomplete, so eth.proto and eth.vlan return nothing on the output of eth.hdr: "eth.hdr,eth.proto" never works, and neither does any frame truncated right after the protocol field. The protocol field is complete when idx + 2 <= data, so let's use this condition in the 4 loops. Frames that carry data after the header are not affected. The net_helper reg-test now checks eth.hdr followed by eth.proto and eth.vlan. This should be backported to 3.4. --- diff --git a/reg-tests/converter/net_helper.vtc b/reg-tests/converter/net_helper.vtc index 85d6450cb..7fc8bb824 100644 --- a/reg-tests/converter/net_helper.vtc +++ b/reg-tests/converter/net_helper.vtc @@ -26,6 +26,14 @@ haproxy h1 -conf { http-after-response set-header ws-ok "%[bin(00010050000000000000000060020000ffff000001030307),tcp.options.wscale]" http-after-response set-header ws-len2 "%[bin(00010050000000000000000060020000ffff000001010302aa),tcp.options.wscale]" http-after-response set-header tsval-len2 "%[bin(00010050000000000000000060020000ffff00000101080212345678),tcp.options.tsval]" + + # Ethernet header with one VLAN tag (ID 100) and IPv4, followed by + # some data, and the same header alone as returned by eth.hdr. + http-after-response set-header eth-proto "%[bin(000000000000000000000000810000640800450000),eth.proto]" + http-after-response set-header eth-hdr-proto "%[bin(000000000000000000000000810000640800450000),eth.hdr,eth.proto]" + http-after-response set-header eth-hdr-vlan "%[bin(000000000000000000000000810000640800450000),eth.hdr,eth.vlan]" + http-after-response set-header eth-data "%[bin(000000000000000000000000810000640800450000),eth.data,hex]" + http-after-response set-header eth-noproto "%[bin(00000000000000000000000081000064),eth.proto]" } -start client c1 -connect ${h1_fe_sock} { @@ -37,4 +45,9 @@ client c1 -connect ${h1_fe_sock} { expect resp.http.ws-ok == "7" expect resp.http.ws-len2 == "0" expect resp.http.tsval-len2 == "0" + expect resp.http.eth-proto == "2048" + expect resp.http.eth-hdr-proto == "2048" + expect resp.http.eth-hdr-vlan == "100" + expect resp.http.eth-data == "450000" + expect resp.http.eth-noproto == "" } -run diff --git a/src/net_helper.c b/src/net_helper.c index 6a0c7d7d3..e9a062b67 100644 --- a/src/net_helper.c +++ b/src/net_helper.c @@ -23,7 +23,7 @@ static int sample_conv_eth_data(const struct arg *arg_p, struct sample *smp, voi { size_t idx; - for (idx = 12; idx + 2 < smp->data.u.str.data; idx += 4) { + for (idx = 12; idx + 2 <= smp->data.u.str.data; idx += 4) { if (read_n16(smp->data.u.str.area + idx) != 0x8100) { if (smp->data.u.str.size) smp->data.u.str.size -= idx + 2; @@ -54,7 +54,7 @@ static int sample_conv_eth_hdr(const struct arg *arg_p, struct sample *smp, void { size_t idx; - for (idx = 12; idx + 2 < smp->data.u.str.data; idx += 4) { + for (idx = 12; idx + 2 <= smp->data.u.str.data; idx += 4) { if (read_n16(smp->data.u.str.area + idx) != 0x8100) { smp->data.u.str.data = idx + 2; return 1; @@ -72,7 +72,7 @@ static int sample_conv_eth_proto(const struct arg *arg_p, struct sample *smp, vo ushort proto; size_t idx; - for (idx = 12; idx + 2 < smp->data.u.str.data; idx += 4) { + for (idx = 12; idx + 2 <= smp->data.u.str.data; idx += 4) { proto = read_n16(smp->data.u.str.area + idx); if (proto != 0x8100) { smp->data.u.sint = proto; @@ -107,7 +107,7 @@ static int sample_conv_eth_vlan(const struct arg *arg_p, struct sample *smp, voi ushort vlan = 0; size_t idx; - for (idx = 12; idx + 2 < smp->data.u.str.data; idx += 4) { + for (idx = 12; idx + 2 <= smp->data.u.str.data; idx += 4) { if (read_n16(smp->data.u.str.area + idx) != 0x8100) { smp->data.u.sint = vlan; smp->data.type = SMP_T_SINT;