blob: c8cb7d9630c133d863bb111bea5b056d48b212c5 [file] [log] [blame]
Frédéric Lécaille1d96d6e2022-05-23 16:38:14 +02001#include <string.h>
2
Amaury Denoyellec8b4ce42022-01-11 11:54:59 +01003#include <haproxy/api.h>
Amaury Denoyelle97e84c62022-04-19 18:26:55 +02004#include <haproxy/cfgparse.h>
Frédéric Lécaille43910a92022-07-11 10:24:21 +02005#include <haproxy/errors.h>
Willy Tarreau07a3d532022-11-24 08:28:43 +01006#include <haproxy/global.h>
Amaury Denoyellec8b4ce42022-01-11 11:54:59 +01007#include <haproxy/listener.h>
8#include <haproxy/proxy-t.h>
Frédéric Lécaille43910a92022-07-11 10:24:21 +02009#include <haproxy/quic_cc-t.h>
Amaury Denoyelle97e84c62022-04-19 18:26:55 +020010#include <haproxy/tools.h>
Amaury Denoyellec8b4ce42022-01-11 11:54:59 +010011
Amaury Denoyelleb76ae692022-01-11 14:16:37 +010012static int bind_parse_quic_force_retry(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
13{
Willy Tarreau787e92a2022-05-20 16:06:01 +020014 conf->options |= BC_O_QUIC_FORCE_RETRY;
Amaury Denoyelleb76ae692022-01-11 14:16:37 +010015 return 0;
16}
17
Frédéric Lécaille43910a92022-07-11 10:24:21 +020018/* parse "quic-cc-algo" bind keyword */
19static int bind_parse_quic_cc_algo(char **args, int cur_arg, struct proxy *px,
20 struct bind_conf *conf, char **err)
21{
22 struct quic_cc_algo *cc_algo;
Frédéric Lécailledb4bc6b2023-03-31 15:21:55 +020023 char *arg;
Frédéric Lécaille43910a92022-07-11 10:24:21 +020024
25 if (!*args[cur_arg + 1]) {
Ilya Shipitsin4a689da2022-10-29 09:34:32 +050026 memprintf(err, "'%s' : missing control congestion algorithm", args[cur_arg]);
Frédéric Lécaille43910a92022-07-11 10:24:21 +020027 return ERR_ALERT | ERR_FATAL;
28 }
29
Frédéric Lécailledb4bc6b2023-03-31 15:21:55 +020030 arg = args[cur_arg + 1];
31 if (strcmp(arg, "newreno") == 0)
Frédéric Lécaille43910a92022-07-11 10:24:21 +020032 cc_algo = &quic_cc_algo_nr;
Frédéric Lécailledb4bc6b2023-03-31 15:21:55 +020033 else if (strcmp(arg, "cubic") == 0)
Frédéric Lécaille43910a92022-07-11 10:24:21 +020034 cc_algo = &quic_cc_algo_cubic;
Frédéric Lécailledb4bc6b2023-03-31 15:21:55 +020035 else if (strlen(arg) >= 6 && strncmp(arg, "nocc-", 5) == 0) {
36 if (!experimental_directives_allowed) {
37 ha_alert("'%s' algo is experimental, must be allowed via a global 'expose-experimental-directives'\n", arg);
38 return ERR_ALERT | ERR_FATAL;
39 }
40
41 cc_algo = &quic_cc_algo_nocc;
42 quic_cc_nocc_fixed_cwnd = atoi(arg + 5);
43 }
Frédéric Lécaille43910a92022-07-11 10:24:21 +020044 else {
45 memprintf(err, "'%s' : unknown control congestion algorithm", args[cur_arg]);
46 return ERR_ALERT | ERR_FATAL;
47 }
48
49 conf->quic_cc_algo = cc_algo;
50 return 0;
51}
52
Amaury Denoyellec8b4ce42022-01-11 11:54:59 +010053static struct bind_kw_list bind_kws = { "QUIC", { }, {
Amaury Denoyelleb76ae692022-01-11 14:16:37 +010054 { "quic-force-retry", bind_parse_quic_force_retry, 0 },
Frédéric Lécaille43910a92022-07-11 10:24:21 +020055 { "quic-cc-algo", bind_parse_quic_cc_algo, 1 },
Amaury Denoyellec8b4ce42022-01-11 11:54:59 +010056 { NULL, NULL, 0 },
57}};
58
59INITCALL1(STG_REGISTER, bind_register_keywords, &bind_kws);
Amaury Denoyelle97e84c62022-04-19 18:26:55 +020060
Amaury Denoyelle511ddd52022-11-18 17:42:16 +010061/* parse "tune.quic.socket-owner", accepts "listener" or "connection" */
62static int cfg_parse_quic_tune_socket_owner(char **args, int section_type,
63 struct proxy *curpx,
64 const struct proxy *defpx,
65 const char *file, int line, char **err)
66{
67 if (too_many_args(1, args, err, NULL))
68 return -1;
69
70 if (strcmp(args[1], "connection") == 0) {
71 global.tune.options |= GTUNE_QUIC_SOCK_PER_CONN;
72 }
73 else if (strcmp(args[1], "listener") == 0) {
74 global.tune.options &= ~GTUNE_QUIC_SOCK_PER_CONN;
75 }
76 else {
77 memprintf(err, "'%s' expects either 'listener' or 'connection' but got '%s'.", args[0], args[1]);
78 return -1;
79 }
80
81 return 0;
82}
83
Frédéric Lécaille1d96d6e2022-05-23 16:38:14 +020084/* Must be used to parse tune.quic.* setting which requires a time
85 * as value.
86 * Return -1 on alert, or 0 if succeeded.
87 */
88static int cfg_parse_quic_time(char **args, int section_type,
89 struct proxy *curpx,
90 const struct proxy *defpx,
91 const char *file, int line, char **err)
92{
93 unsigned int time;
94 const char *res, *name, *value;
95 int prefix_len = strlen("tune.quic.");
96
97 if (too_many_args(1, args, err, NULL))
98 return -1;
99
100 name = args[0];
101 value = args[1];
102 res = parse_time_err(value, &time, TIME_UNIT_MS);
103 if (res == PARSE_TIME_OVER) {
104 memprintf(err, "timer overflow in argument '%s' to '%s' "
105 "(maximum value is 2147483647 ms or ~24.8 days)", value, name);
106 return -1;
107 }
108 else if (res == PARSE_TIME_UNDER) {
109 memprintf(err, "timer underflow in argument '%s' to '%s' "
110 "(minimum non-null value is 1 ms)", value, name);
111 return -1;
112 }
113 else if (res) {
114 memprintf(err, "unexpected character '%c' in '%s'", *res, name);
115 return -1;
116 }
117
118 if (strcmp(name + prefix_len, "frontend.max-idle-timeout") == 0)
119 global.tune.quic_frontend_max_idle_timeout = time;
120 else if (strcmp(name + prefix_len, "backend.max-idle-timeout") == 0)
121 global.tune.quic_backend_max_idle_timeout = time;
122 else {
123 memprintf(err, "'%s' keyword not unhandled (please report this bug).", args[0]);
124 return -1;
125 }
126
127 return 0;
128}
129
Frédéric Lécaille92862102022-05-20 16:29:10 +0200130/* Parse any tune.quic.* setting with strictly positive integer values.
131 * Return -1 on alert, or 0 if succeeded.
132 */
133static int cfg_parse_quic_tune_setting(char **args, int section_type,
134 struct proxy *curpx,
135 const struct proxy *defpx,
136 const char *file, int line, char **err)
Amaury Denoyelle97e84c62022-04-19 18:26:55 +0200137{
138 unsigned int arg = 0;
Frédéric Lécaille92862102022-05-20 16:29:10 +0200139 int prefix_len = strlen("tune.quic.");
Frédéric Lécaille26740982022-05-23 17:28:01 +0200140 const char *suffix;
Amaury Denoyelle97e84c62022-04-19 18:26:55 +0200141
142 if (too_many_args(1, args, err, NULL))
143 return -1;
144
145 if (*(args[1]) != 0)
146 arg = atoi(args[1]);
147
148 if (arg < 1) {
149 memprintf(err, "'%s' expects a positive integer.", args[0]);
150 return -1;
151 }
152
Frédéric Lécaille26740982022-05-23 17:28:01 +0200153 suffix = args[0] + prefix_len;
Frédéric Lécaille38dea052022-05-25 17:14:28 +0200154 if (strcmp(suffix, "frontend.conn-tx-buffers.limit") == 0)
Frédéric Lécaille92862102022-05-20 16:29:10 +0200155 global.tune.quic_streams_buf = arg;
Frédéric Lécaille26740982022-05-23 17:28:01 +0200156 else if (strcmp(suffix, "frontend.max-streams-bidi") == 0)
157 global.tune.quic_frontend_max_streams_bidi = arg;
Amaury Denoyelle24d5b722023-01-31 11:44:50 +0100158 else if (strcmp(suffix, "max-frame-loss") == 0)
159 global.tune.quic_max_frame_loss = arg;
Frédéric Lécaille26740982022-05-23 17:28:01 +0200160 else if (strcmp(suffix, "retry-threshold") == 0)
Frédéric Lécaille92862102022-05-20 16:29:10 +0200161 global.tune.quic_retry_threshold = arg;
162 else {
163 memprintf(err, "'%s' keyword not unhandled (please report this bug).", args[0]);
164 return -1;
165 }
Amaury Denoyelle97e84c62022-04-19 18:26:55 +0200166
167 return 0;
168}
169
170static struct cfg_kw_list cfg_kws = {ILH, {
Amaury Denoyelle511ddd52022-11-18 17:42:16 +0100171 { CFG_GLOBAL, "tune.quic.socket-owner", cfg_parse_quic_tune_socket_owner },
Frédéric Lécaille1d96d6e2022-05-23 16:38:14 +0200172 { CFG_GLOBAL, "tune.quic.backend.max-idle-timeou", cfg_parse_quic_time },
Frédéric Lécaille38dea052022-05-25 17:14:28 +0200173 { CFG_GLOBAL, "tune.quic.frontend.conn-tx-buffers.limit", cfg_parse_quic_tune_setting },
Frédéric Lécaille26740982022-05-23 17:28:01 +0200174 { CFG_GLOBAL, "tune.quic.frontend.max-streams-bidi", cfg_parse_quic_tune_setting },
Frédéric Lécaille1d96d6e2022-05-23 16:38:14 +0200175 { CFG_GLOBAL, "tune.quic.frontend.max-idle-timeout", cfg_parse_quic_time },
Amaury Denoyelle24d5b722023-01-31 11:44:50 +0100176 { CFG_GLOBAL, "tune.quic.max-frame-loss", cfg_parse_quic_tune_setting },
Frédéric Lécaille92862102022-05-20 16:29:10 +0200177 { CFG_GLOBAL, "tune.quic.retry-threshold", cfg_parse_quic_tune_setting },
Amaury Denoyelle97e84c62022-04-19 18:26:55 +0200178 { 0, NULL, NULL }
179}};
180
181INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);