Skip to content

Set server name implementation#11

Open
alexanderstephan wants to merge 7 commits intomasterfrom
set-server-name-option
Open

Set server name implementation#11
alexanderstephan wants to merge 7 commits intomasterfrom
set-server-name-option

Conversation

@alexanderstephan
Copy link
Copy Markdown

@alexanderstephan alexanderstephan commented Feb 18, 2026

Fixes haproxy#952.

Copy link
Copy Markdown

@Garfield96 Garfield96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a test case similar to https://github.com/haproxy/haproxy/blob/master/reg-tests/server/cli_add_server.vtc for this functionality.

Comment thread src/server.c Outdated
Comment on lines +59 to +60
#include <haproxy/stick_table-t.h>
#include <haproxy/peers-t.h>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The imports are sorted

Comment thread src/server.c
if (rule->table.t && rule->table.t->peers.p)
return "Cannot rename: backend has store-response rules using a peer-synced table.\n";
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Length of new server name is not checked.

Comment thread src/server.c
Comment on lines +5435 to +5439
/* reject control characters, spaces, and '/' which break CLI parsing */
for (p = new_name; *p; p++) {
if ((unsigned char)*p <= ' ' || *p == '/')
return "Server name must not contain spaces, control characters, or '/'.\n";
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no utility function for this task?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I searched again, but I couldn't find any helper like that sadly.

…enaming

Add a global-level 'server-rename' keyword as an alternative to the
per-backend 'option server-rename'. When set in the global section,
it allows runtime server renaming via 'set server <b>/<s> name' on
all backends without requiring the per-backend option individually.

The per-backend 'option server-rename' still works independently —
either one is sufficient to enable renaming for a given backend.

This uses bit 24 of global.tune.options (GTUNE_SRV_RENAME) and
follows the same pattern as other global boolean toggles like
'insecure-fork-wanted'. The 'no' prefix is supported to disable it.
Add a VTC test covering:
  - error cases: missing name, backend without opt-in, server not in
    maintenance, invalid characters in name, duplicate name
  - success: rename, verify via 'show servers state', old name no
    longer resolves, rename back, traffic still works
  - global 'server-rename' keyword: rename succeeds on a backend
    without 'option server-rename' when global toggle is set
Add a VTC test covering:
  - error cases: missing name, backend without opt-in, server not in
    maintenance, invalid characters in name, duplicate name
  - success: rename, verify via 'show servers state', old name no
    longer resolves, rename back, traffic still works
  - global 'server-rename' keyword: rename succeeds on a backend
    without 'option server-rename' when global toggle is set
alexanderstephan pushed a commit that referenced this pull request May 8, 2026
New type sockaddr_in46 has been recently introduced. It serves as a
union which can store either an IPv4 or IPv6 address. The objective is
to reduce the storage size for QUIC datagrams which previously uses a
sockaddr_storage field.

On qc_new_conn(), source and destination addresses from the datagram are
passed to the function as sockaddr_storage so that they are copied into
the newly built quic_conn instance. However, the involved memcpy() is
producing a buffer overflow as sockaddr_in46 is smaller than
sockaddr_storage type.

This patch fixes this by defining a new helper function
in46un_to_addr(). This allows to convert safely sockaddr_in46 to a plain
sockaddr type. The function is now used before invoking qc_new_conn().

Note that there is still other several places where union sockaddr_in46
is casted as sockaddr_storage type. However, these should be safe as in
these cases sockaddr fields are accessed individually after checking
ss_family. The memory issue only exists when plain memcpy is used.

This bug was detected using ASAN. It generates the following traces when
a QUIC connection is instantiated.

==37474==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7c3bb9a61100 at pc 0x5631f52c3946 bp 0x7ffc83e45b50 sp 0x7ffc83e45310
READ of size 128 at 0x7c3bb9a61100 thread T0
    #0 0x5631f52c3945 in __asan_memcpy (/home/amaury/work/haproxy-quic-dev/haproxy+0x3ae945) (BuildId: a7ccfd74b7a71a869b8ff8d13f6dcde8c82c1487)
    #1 0x5631f55f9e34 in qc_new_conn /home/amaury/work/haproxy-quic-dev/src/quic_conn.c:1311:2
    #2 0x5631f558d5c3 in quic_rx_pkt_retrieve_conn /home/amaury/work/haproxy-quic-dev/src/quic_rx.c:1875:10
    #3 0x5631f558330b in quic_dgram_parse /home/amaury/work/haproxy-quic-dev/src/quic_rx.c:2463:29
    #4 0x5631f5625da6 in quic_lstnr_dghdlr /home/amaury/work/haproxy-quic-dev/src/quic_sock.c:206:3
    #5 0x5631f6a64173 in run_tasks_from_lists /home/amaury/work/haproxy-quic-dev/src/task.c:660:26
    #6 0x5631f6a6ba1e in process_runnable_tasks /home/amaury/work/haproxy-quic-dev/src/task.c:913:9
    #7 0x5631f5e984c3 in run_poll_loop /home/amaury/work/haproxy-quic-dev/src/haproxy.c:2982:3
    #8 0x5631f5e9a715 in run_thread_poll_loop /home/amaury/work/haproxy-quic-dev/src/haproxy.c:3212:2
    #9 0x5631f5e9f732 in main /home/amaury/work/haproxy-quic-dev/src/haproxy.c:3853:2
    #10 0x7f2bba8276c0  (/usr/lib/libc.so.6+0x276c0) (BuildId: ca0db5ab57a36507d61bbcf4988d344974331f19)
    #11 0x7f2bba8277f8 in __libc_start_main (/usr/lib/libc.so.6+0x277f8) (BuildId: ca0db5ab57a36507d61bbcf4988d344974331f19)
    #12 0x5631f51be594 in _start (/home/amaury/work/haproxy-quic-dev/haproxy+0x2a9594) (BuildId: a7ccfd74b7a71a869b8ff8d13f6dcde8c82c1487)

No need to backport.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to rename a server at runtime.

2 participants