haproxy/reg-tests/server/abnsz.vtc
Tristan 18582ede05 MEDIUM: socket: add zero-terminated ABNS alternative
When an abstract unix socket is bound by HAProxy (using "abns@" prefix),
NUL bytes are appended at the end of its path until sun_path is filled
(for a total of 108 characters).

Here we add an alternative to pass only the non-NUL length of that path
to connect/bind calls, such that the effective path of the socket's name
is as humanly written. This may be useful to interconnect with existing
softwares that implement abstract sockets with this logic instead of the
default haproxy one.

This is achieved by implementing the "abnsz" socket prefix (instead of
"abns"), which stands for "zero-terminated ABNS". "abnsz" prefix may be
used anywhere "abns" is. Internally, haproxy uses the custom socket
family (AF_CUST_ABNS vs AF_CUST_ABNSZ) to differentiate default abns
sockets from zero-terminated ones.

Documentation was updated and regtest was added.

Fixes GH issues #977 and #2479

Co-authored-by: Aurelien DARRAGON <adarragon@haproxy.com>
2024-10-29 12:15:24 +01:00

37 lines
871 B
Text

varnishtest "Abstract unix socket - zero terminated"
feature ignore_unknown_macro
feature cmd "command -v curl"
# abns@ sockets are not available on freebsd
#EXCLUDE_TARGETS=freebsd,osx,generic
#REGTEST_TYPE=devel
haproxy h1 -W -S -conf {
global
stats socket "${tmpdir}/h1/stats" level admin expose-fd listeners
defaults
mode http
log global
option httplog
timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
listen testme
bind "fd@${testme}"
server f2 abnsz@hap-f2
frontend f2
bind abnsz@hap-f2
http-request return status 200 content-type text/plain string "ok"
} -start
client c1 -connect ${h1_testme_sock} {
txreq -url "/"
rxresp
} -run
shell {
curl -sfS --abstract-unix-socket hap-f2 "http://host/" | grep "ok"
}