blob: 8ccb83bab61d8689d328ac507bff83c2dd165534 [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>
5#include <haproxy/global-t.h>
Amaury Denoyellec8b4ce42022-01-11 11:54:59 +01006#include <haproxy/listener.h>
7#include <haproxy/proxy-t.h>
Amaury Denoyelle97e84c62022-04-19 18:26:55 +02008#include <haproxy/tools.h>
Amaury Denoyellec8b4ce42022-01-11 11:54:59 +01009
Amaury Denoyelleb76ae692022-01-11 14:16:37 +010010static int bind_parse_quic_force_retry(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
11{
Willy Tarreau787e92a2022-05-20 16:06:01 +020012 conf->options |= BC_O_QUIC_FORCE_RETRY;
Amaury Denoyelleb76ae692022-01-11 14:16:37 +010013 return 0;
14}
15
Amaury Denoyellec8b4ce42022-01-11 11:54:59 +010016static struct bind_kw_list bind_kws = { "QUIC", { }, {
Amaury Denoyelleb76ae692022-01-11 14:16:37 +010017 { "quic-force-retry", bind_parse_quic_force_retry, 0 },
Amaury Denoyellec8b4ce42022-01-11 11:54:59 +010018 { NULL, NULL, 0 },
19}};
20
21INITCALL1(STG_REGISTER, bind_register_keywords, &bind_kws);
Amaury Denoyelle97e84c62022-04-19 18:26:55 +020022
Frédéric Lécaille1d96d6e2022-05-23 16:38:14 +020023/* Must be used to parse tune.quic.* setting which requires a time
24 * as value.
25 * Return -1 on alert, or 0 if succeeded.
26 */
27static int cfg_parse_quic_time(char **args, int section_type,
28 struct proxy *curpx,
29 const struct proxy *defpx,
30 const char *file, int line, char **err)
31{
32 unsigned int time;
33 const char *res, *name, *value;
34 int prefix_len = strlen("tune.quic.");
35
36 if (too_many_args(1, args, err, NULL))
37 return -1;
38
39 name = args[0];
40 value = args[1];
41 res = parse_time_err(value, &time, TIME_UNIT_MS);
42 if (res == PARSE_TIME_OVER) {
43 memprintf(err, "timer overflow in argument '%s' to '%s' "
44 "(maximum value is 2147483647 ms or ~24.8 days)", value, name);
45 return -1;
46 }
47 else if (res == PARSE_TIME_UNDER) {
48 memprintf(err, "timer underflow in argument '%s' to '%s' "
49 "(minimum non-null value is 1 ms)", value, name);
50 return -1;
51 }
52 else if (res) {
53 memprintf(err, "unexpected character '%c' in '%s'", *res, name);
54 return -1;
55 }
56
57 if (strcmp(name + prefix_len, "frontend.max-idle-timeout") == 0)
58 global.tune.quic_frontend_max_idle_timeout = time;
59 else if (strcmp(name + prefix_len, "backend.max-idle-timeout") == 0)
60 global.tune.quic_backend_max_idle_timeout = time;
61 else {
62 memprintf(err, "'%s' keyword not unhandled (please report this bug).", args[0]);
63 return -1;
64 }
65
66 return 0;
67}
68
Frédéric Lécaille92862102022-05-20 16:29:10 +020069/* Parse any tune.quic.* setting with strictly positive integer values.
70 * Return -1 on alert, or 0 if succeeded.
71 */
72static int cfg_parse_quic_tune_setting(char **args, int section_type,
73 struct proxy *curpx,
74 const struct proxy *defpx,
75 const char *file, int line, char **err)
Amaury Denoyelle97e84c62022-04-19 18:26:55 +020076{
77 unsigned int arg = 0;
Frédéric Lécaille92862102022-05-20 16:29:10 +020078 int prefix_len = strlen("tune.quic.");
Frédéric Lécaille26740982022-05-23 17:28:01 +020079 const char *suffix;
Amaury Denoyelle97e84c62022-04-19 18:26:55 +020080
81 if (too_many_args(1, args, err, NULL))
82 return -1;
83
84 if (*(args[1]) != 0)
85 arg = atoi(args[1]);
86
87 if (arg < 1) {
88 memprintf(err, "'%s' expects a positive integer.", args[0]);
89 return -1;
90 }
91
Frédéric Lécaille26740982022-05-23 17:28:01 +020092 suffix = args[0] + prefix_len;
Frédéric Lécaille38dea052022-05-25 17:14:28 +020093 if (strcmp(suffix, "frontend.conn-tx-buffers.limit") == 0)
Frédéric Lécaille92862102022-05-20 16:29:10 +020094 global.tune.quic_streams_buf = arg;
Frédéric Lécaille26740982022-05-23 17:28:01 +020095 else if (strcmp(suffix, "frontend.max-streams-bidi") == 0)
96 global.tune.quic_frontend_max_streams_bidi = arg;
97 else if (strcmp(suffix, "retry-threshold") == 0)
Frédéric Lécaille92862102022-05-20 16:29:10 +020098 global.tune.quic_retry_threshold = arg;
99 else {
100 memprintf(err, "'%s' keyword not unhandled (please report this bug).", args[0]);
101 return -1;
102 }
Amaury Denoyelle97e84c62022-04-19 18:26:55 +0200103
104 return 0;
105}
106
107static struct cfg_kw_list cfg_kws = {ILH, {
Frédéric Lécaille1d96d6e2022-05-23 16:38:14 +0200108 { CFG_GLOBAL, "tune.quic.backend.max-idle-timeou", cfg_parse_quic_time },
Frédéric Lécaille38dea052022-05-25 17:14:28 +0200109 { CFG_GLOBAL, "tune.quic.frontend.conn-tx-buffers.limit", cfg_parse_quic_tune_setting },
Frédéric Lécaille26740982022-05-23 17:28:01 +0200110 { CFG_GLOBAL, "tune.quic.frontend.max-streams-bidi", cfg_parse_quic_tune_setting },
Frédéric Lécaille1d96d6e2022-05-23 16:38:14 +0200111 { CFG_GLOBAL, "tune.quic.frontend.max-idle-timeout", cfg_parse_quic_time },
Frédéric Lécaille92862102022-05-20 16:29:10 +0200112 { CFG_GLOBAL, "tune.quic.retry-threshold", cfg_parse_quic_tune_setting },
Amaury Denoyelle97e84c62022-04-19 18:26:55 +0200113 { 0, NULL, NULL }
114}};
115
116INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);