blob: 21aaac2e2d5d016d366a1e94b8351e407e061300 [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;
23
24 if (!*args[cur_arg + 1]) {
Ilya Shipitsin4a689da2022-10-29 09:34:32 +050025 memprintf(err, "'%s' : missing control congestion algorithm", args[cur_arg]);
Frédéric Lécaille43910a92022-07-11 10:24:21 +020026 return ERR_ALERT | ERR_FATAL;
27 }
28
Tim Duesterhusa6fc6162022-10-08 12:33:19 +020029 if (strcmp(args[cur_arg + 1], "newreno") == 0)
Frédéric Lécaille43910a92022-07-11 10:24:21 +020030 cc_algo = &quic_cc_algo_nr;
Tim Duesterhusa6fc6162022-10-08 12:33:19 +020031 else if (strcmp(args[cur_arg + 1], "cubic") == 0)
Frédéric Lécaille43910a92022-07-11 10:24:21 +020032 cc_algo = &quic_cc_algo_cubic;
33 else {
34 memprintf(err, "'%s' : unknown control congestion algorithm", args[cur_arg]);
35 return ERR_ALERT | ERR_FATAL;
36 }
37
38 conf->quic_cc_algo = cc_algo;
39 return 0;
40}
41
Amaury Denoyellec8b4ce42022-01-11 11:54:59 +010042static struct bind_kw_list bind_kws = { "QUIC", { }, {
Amaury Denoyelleb76ae692022-01-11 14:16:37 +010043 { "quic-force-retry", bind_parse_quic_force_retry, 0 },
Frédéric Lécaille43910a92022-07-11 10:24:21 +020044 { "quic-cc-algo", bind_parse_quic_cc_algo, 1 },
Amaury Denoyellec8b4ce42022-01-11 11:54:59 +010045 { NULL, NULL, 0 },
46}};
47
48INITCALL1(STG_REGISTER, bind_register_keywords, &bind_kws);
Amaury Denoyelle97e84c62022-04-19 18:26:55 +020049
Amaury Denoyelle511ddd52022-11-18 17:42:16 +010050/* parse "tune.quic.socket-owner", accepts "listener" or "connection" */
51static int cfg_parse_quic_tune_socket_owner(char **args, int section_type,
52 struct proxy *curpx,
53 const struct proxy *defpx,
54 const char *file, int line, char **err)
55{
56 if (too_many_args(1, args, err, NULL))
57 return -1;
58
59 if (strcmp(args[1], "connection") == 0) {
60 global.tune.options |= GTUNE_QUIC_SOCK_PER_CONN;
61 }
62 else if (strcmp(args[1], "listener") == 0) {
63 global.tune.options &= ~GTUNE_QUIC_SOCK_PER_CONN;
64 }
65 else {
66 memprintf(err, "'%s' expects either 'listener' or 'connection' but got '%s'.", args[0], args[1]);
67 return -1;
68 }
69
70 return 0;
71}
72
Frédéric Lécaille1d96d6e2022-05-23 16:38:14 +020073/* Must be used to parse tune.quic.* setting which requires a time
74 * as value.
75 * Return -1 on alert, or 0 if succeeded.
76 */
77static int cfg_parse_quic_time(char **args, int section_type,
78 struct proxy *curpx,
79 const struct proxy *defpx,
80 const char *file, int line, char **err)
81{
82 unsigned int time;
83 const char *res, *name, *value;
84 int prefix_len = strlen("tune.quic.");
85
86 if (too_many_args(1, args, err, NULL))
87 return -1;
88
89 name = args[0];
90 value = args[1];
91 res = parse_time_err(value, &time, TIME_UNIT_MS);
92 if (res == PARSE_TIME_OVER) {
93 memprintf(err, "timer overflow in argument '%s' to '%s' "
94 "(maximum value is 2147483647 ms or ~24.8 days)", value, name);
95 return -1;
96 }
97 else if (res == PARSE_TIME_UNDER) {
98 memprintf(err, "timer underflow in argument '%s' to '%s' "
99 "(minimum non-null value is 1 ms)", value, name);
100 return -1;
101 }
102 else if (res) {
103 memprintf(err, "unexpected character '%c' in '%s'", *res, name);
104 return -1;
105 }
106
107 if (strcmp(name + prefix_len, "frontend.max-idle-timeout") == 0)
108 global.tune.quic_frontend_max_idle_timeout = time;
109 else if (strcmp(name + prefix_len, "backend.max-idle-timeout") == 0)
110 global.tune.quic_backend_max_idle_timeout = time;
111 else {
112 memprintf(err, "'%s' keyword not unhandled (please report this bug).", args[0]);
113 return -1;
114 }
115
116 return 0;
117}
118
Frédéric Lécaille92862102022-05-20 16:29:10 +0200119/* Parse any tune.quic.* setting with strictly positive integer values.
120 * Return -1 on alert, or 0 if succeeded.
121 */
122static int cfg_parse_quic_tune_setting(char **args, int section_type,
123 struct proxy *curpx,
124 const struct proxy *defpx,
125 const char *file, int line, char **err)
Amaury Denoyelle97e84c62022-04-19 18:26:55 +0200126{
127 unsigned int arg = 0;
Frédéric Lécaille92862102022-05-20 16:29:10 +0200128 int prefix_len = strlen("tune.quic.");
Frédéric Lécaille26740982022-05-23 17:28:01 +0200129 const char *suffix;
Amaury Denoyelle97e84c62022-04-19 18:26:55 +0200130
131 if (too_many_args(1, args, err, NULL))
132 return -1;
133
134 if (*(args[1]) != 0)
135 arg = atoi(args[1]);
136
137 if (arg < 1) {
138 memprintf(err, "'%s' expects a positive integer.", args[0]);
139 return -1;
140 }
141
Frédéric Lécaille26740982022-05-23 17:28:01 +0200142 suffix = args[0] + prefix_len;
Frédéric Lécaille38dea052022-05-25 17:14:28 +0200143 if (strcmp(suffix, "frontend.conn-tx-buffers.limit") == 0)
Frédéric Lécaille92862102022-05-20 16:29:10 +0200144 global.tune.quic_streams_buf = arg;
Frédéric Lécaille26740982022-05-23 17:28:01 +0200145 else if (strcmp(suffix, "frontend.max-streams-bidi") == 0)
146 global.tune.quic_frontend_max_streams_bidi = arg;
147 else if (strcmp(suffix, "retry-threshold") == 0)
Frédéric Lécaille92862102022-05-20 16:29:10 +0200148 global.tune.quic_retry_threshold = arg;
149 else {
150 memprintf(err, "'%s' keyword not unhandled (please report this bug).", args[0]);
151 return -1;
152 }
Amaury Denoyelle97e84c62022-04-19 18:26:55 +0200153
154 return 0;
155}
156
157static struct cfg_kw_list cfg_kws = {ILH, {
Amaury Denoyelle511ddd52022-11-18 17:42:16 +0100158 { CFG_GLOBAL, "tune.quic.socket-owner", cfg_parse_quic_tune_socket_owner },
Frédéric Lécaille1d96d6e2022-05-23 16:38:14 +0200159 { CFG_GLOBAL, "tune.quic.backend.max-idle-timeou", cfg_parse_quic_time },
Frédéric Lécaille38dea052022-05-25 17:14:28 +0200160 { CFG_GLOBAL, "tune.quic.frontend.conn-tx-buffers.limit", cfg_parse_quic_tune_setting },
Frédéric Lécaille26740982022-05-23 17:28:01 +0200161 { CFG_GLOBAL, "tune.quic.frontend.max-streams-bidi", cfg_parse_quic_tune_setting },
Frédéric Lécaille1d96d6e2022-05-23 16:38:14 +0200162 { CFG_GLOBAL, "tune.quic.frontend.max-idle-timeout", cfg_parse_quic_time },
Frédéric Lécaille92862102022-05-20 16:29:10 +0200163 { CFG_GLOBAL, "tune.quic.retry-threshold", cfg_parse_quic_tune_setting },
Amaury Denoyelle97e84c62022-04-19 18:26:55 +0200164 { 0, NULL, NULL }
165}};
166
167INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);