blob: ee23dc8e1c3b39e09ee18d8b15e2cce5350fb9bd [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>
Amaury Denoyelle97e84c62022-04-19 18:26:55 +02006#include <haproxy/global-t.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
Frédéric Lécaille1d96d6e2022-05-23 16:38:14 +020050/* Must be used to parse tune.quic.* setting which requires a time
51 * as value.
52 * Return -1 on alert, or 0 if succeeded.
53 */
54static int cfg_parse_quic_time(char **args, int section_type,
55 struct proxy *curpx,
56 const struct proxy *defpx,
57 const char *file, int line, char **err)
58{
59 unsigned int time;
60 const char *res, *name, *value;
61 int prefix_len = strlen("tune.quic.");
62
63 if (too_many_args(1, args, err, NULL))
64 return -1;
65
66 name = args[0];
67 value = args[1];
68 res = parse_time_err(value, &time, TIME_UNIT_MS);
69 if (res == PARSE_TIME_OVER) {
70 memprintf(err, "timer overflow in argument '%s' to '%s' "
71 "(maximum value is 2147483647 ms or ~24.8 days)", value, name);
72 return -1;
73 }
74 else if (res == PARSE_TIME_UNDER) {
75 memprintf(err, "timer underflow in argument '%s' to '%s' "
76 "(minimum non-null value is 1 ms)", value, name);
77 return -1;
78 }
79 else if (res) {
80 memprintf(err, "unexpected character '%c' in '%s'", *res, name);
81 return -1;
82 }
83
84 if (strcmp(name + prefix_len, "frontend.max-idle-timeout") == 0)
85 global.tune.quic_frontend_max_idle_timeout = time;
86 else if (strcmp(name + prefix_len, "backend.max-idle-timeout") == 0)
87 global.tune.quic_backend_max_idle_timeout = time;
88 else {
89 memprintf(err, "'%s' keyword not unhandled (please report this bug).", args[0]);
90 return -1;
91 }
92
93 return 0;
94}
95
Frédéric Lécaille92862102022-05-20 16:29:10 +020096/* Parse any tune.quic.* setting with strictly positive integer values.
97 * Return -1 on alert, or 0 if succeeded.
98 */
99static int cfg_parse_quic_tune_setting(char **args, int section_type,
100 struct proxy *curpx,
101 const struct proxy *defpx,
102 const char *file, int line, char **err)
Amaury Denoyelle97e84c62022-04-19 18:26:55 +0200103{
104 unsigned int arg = 0;
Frédéric Lécaille92862102022-05-20 16:29:10 +0200105 int prefix_len = strlen("tune.quic.");
Frédéric Lécaille26740982022-05-23 17:28:01 +0200106 const char *suffix;
Amaury Denoyelle97e84c62022-04-19 18:26:55 +0200107
108 if (too_many_args(1, args, err, NULL))
109 return -1;
110
111 if (*(args[1]) != 0)
112 arg = atoi(args[1]);
113
114 if (arg < 1) {
115 memprintf(err, "'%s' expects a positive integer.", args[0]);
116 return -1;
117 }
118
Frédéric Lécaille26740982022-05-23 17:28:01 +0200119 suffix = args[0] + prefix_len;
Frédéric Lécaille38dea052022-05-25 17:14:28 +0200120 if (strcmp(suffix, "frontend.conn-tx-buffers.limit") == 0)
Frédéric Lécaille92862102022-05-20 16:29:10 +0200121 global.tune.quic_streams_buf = arg;
Frédéric Lécaille26740982022-05-23 17:28:01 +0200122 else if (strcmp(suffix, "frontend.max-streams-bidi") == 0)
123 global.tune.quic_frontend_max_streams_bidi = arg;
124 else if (strcmp(suffix, "retry-threshold") == 0)
Frédéric Lécaille92862102022-05-20 16:29:10 +0200125 global.tune.quic_retry_threshold = arg;
126 else {
127 memprintf(err, "'%s' keyword not unhandled (please report this bug).", args[0]);
128 return -1;
129 }
Amaury Denoyelle97e84c62022-04-19 18:26:55 +0200130
131 return 0;
132}
133
134static struct cfg_kw_list cfg_kws = {ILH, {
Frédéric Lécaille1d96d6e2022-05-23 16:38:14 +0200135 { CFG_GLOBAL, "tune.quic.backend.max-idle-timeou", cfg_parse_quic_time },
Frédéric Lécaille38dea052022-05-25 17:14:28 +0200136 { CFG_GLOBAL, "tune.quic.frontend.conn-tx-buffers.limit", cfg_parse_quic_tune_setting },
Frédéric Lécaille26740982022-05-23 17:28:01 +0200137 { CFG_GLOBAL, "tune.quic.frontend.max-streams-bidi", cfg_parse_quic_tune_setting },
Frédéric Lécaille1d96d6e2022-05-23 16:38:14 +0200138 { CFG_GLOBAL, "tune.quic.frontend.max-idle-timeout", cfg_parse_quic_time },
Frédéric Lécaille92862102022-05-20 16:29:10 +0200139 { CFG_GLOBAL, "tune.quic.retry-threshold", cfg_parse_quic_tune_setting },
Amaury Denoyelle97e84c62022-04-19 18:26:55 +0200140 { 0, NULL, NULL }
141}};
142
143INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);