From 92581043fb30315f5f28ceda2c3b3a3ac5a75263 Mon Sep 17 00:00:00 2001 From: Frederic Lecaille Date: Fri, 20 Feb 2026 12:00:34 +0100 Subject: [PATCH] MINOR: haterm: add long options for QUIC and TCP "bind" settings Add the --quic-bind-opts and --tcp-bind-opts long options to append settings to all QUIC and TCP bind lines. This requires modifying the argv parser to first process these new options, ensuring they are available during the second argv pass to be added to each relevant "bind" line. --- doc/haterm.txt | 3 ++ src/haterm_init.c | 79 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/doc/haterm.txt b/doc/haterm.txt index c84b23682..c0a42ef79 100644 --- a/doc/haterm.txt +++ b/doc/haterm.txt @@ -62,6 +62,9 @@ versions. It displays its usage when run without argument or wrong arguments: -c : ECSDA curves (ex: "P-256", "P-384"...) -v : shows version -d : enable the traces for all http protocols + --quic-bind-opts : append options to QUIC "bind" lines + --tcp-bind-opts : append options to TCP "bind" lines + Arguments -G, -F, -T permit to append one or multiple lines at the end of their respective sections. A tab character ('\t') is prepended at the beginning of diff --git a/src/haterm_init.c b/src/haterm_init.c index 61679e7fa..1eacd900e 100644 --- a/src/haterm_init.c +++ b/src/haterm_init.c @@ -7,6 +7,8 @@ static int haterm_debug; +#define QUIC_BIND_LONG_OPT "quic-bind-opts" +#define TCP_BIND_LONG_OPT "tcp-bind-opts" /* * This function prints the command line usage for haterm and exits */ @@ -23,7 +25,10 @@ static void haterm_usage(char *name) " -b : RSA key size in bits (ex: \"2048\", \"4096\"...)\n" " -c : ECSDA curves (ex: \"P-256\", \"P-384\"...)\n" " -v : shows version\n" - " -d : enable the traces for all http protocols\n", name); + " -d : enable the traces for all http protocols\n" + " --" QUIC_BIND_LONG_OPT " : append options to QUIC \"bind\" lines\n" + " --" TCP_BIND_LONG_OPT " : append options to TCP \"bind\" lines\n" + , name); exit(1); } @@ -162,6 +167,9 @@ void haproxy_init_args(int argc, char **argv) struct hbuf fbuf = HBUF_NULL; // "frontend" section struct hbuf tbuf = HBUF_NULL; // "traces" section char *bits = NULL, *curves = NULL; + char *quic_bind_opt = NULL, *tcp_bind_opt = NULL; + int sargc; /* saved argc */ + char **sargv; /* saved argv */ fileless_mode = 1; if (argc <= 1) @@ -174,12 +182,67 @@ void haproxy_init_args(int argc, char **argv) /* skip program name and start */ argc--; argv++; + /* save the arguments */ + sargc = argc; sargv = argv; + + /* THIS PART MUST NOT MODIFY THE ARGUMENTS */ + /* Parse the arguments which must be reused to build the conf. */ while (argc > 0) { char *opt; if (**argv == '-') { opt = *argv + 1; - if (*opt == 'd') { + if (*opt == '-') { + /* long options */ + opt++; + if (strcmp(opt, QUIC_BIND_LONG_OPT) == 0) { + argv++; argc--; + if (argc <= 0 || **argv == '-') + haterm_usage(progname); + + quic_bind_opt = *argv; + } + else if (strcmp(opt, TCP_BIND_LONG_OPT) == 0) { + argv++; argc--; + if (argc <= 0 || **argv == '-') + haterm_usage(progname); + + tcp_bind_opt = *argv; + } + } + } + + argc--; argv++; + } + + /* Restore the argumenst */ + argc = sargc; argv = sargv; + while (argc > 0) { + char *opt; + + if (**argv == '-') { + opt = *argv + 1; + if (*opt == '-') { + /* long options */ + opt++; + if (strcmp(opt, QUIC_BIND_LONG_OPT) == 0) { + argv++; argc--; + if (argc <= 0 || **argv == '-') + haterm_usage(progname); + + quic_bind_opt = *argv; + } + else if (strcmp(opt, TCP_BIND_LONG_OPT) == 0) { + argv++; argc--; + if (argc <= 0 || **argv == '-') + haterm_usage(progname); + + tcp_bind_opt = *argv; + } + else + haterm_usage(progname); + } + else if (*opt == 'd') { /* empty option */ if (*(opt + 1)) haterm_usage(progname); @@ -324,14 +387,18 @@ void haproxy_init_args(int argc, char **argv) hbuf_appendf(&fbuf, "\tbind %s:%s shards by-thread ssl " "alpn h2,http1.1,http1.0" " crt " HATERM_RSA_CERT_NAME - " crt " HATERM_ECDSA_CERT_NAME "\n", - ip, port2); + " crt " HATERM_ECDSA_CERT_NAME "%s%s\n", + ip, port2, + tcp_bind_opt ? " " : "", + tcp_bind_opt ? tcp_bind_opt : ""); /* QUIC binding */ hbuf_appendf(&fbuf, "\tbind %s@%s:%s shards by-thread ssl" " crt " HATERM_RSA_CERT_NAME - " crt " HATERM_ECDSA_CERT_NAME "\n", - ipv6 ? "quic6" : "quic4", ip, port2); + " crt " HATERM_ECDSA_CERT_NAME "%s%s\n", + ipv6 ? "quic6" : "quic4", ip, port2, + quic_bind_opt ? " " : "", + quic_bind_opt ? quic_bind_opt : ""); } } else -- 2.47.3