Frédéric Lécaille | 1d96d6e | 2022-05-23 16:38:14 +0200 | [diff] [blame] | 1 | #include <string.h> |
| 2 | |
Amaury Denoyelle | c8b4ce4 | 2022-01-11 11:54:59 +0100 | [diff] [blame] | 3 | #include <haproxy/api.h> |
Amaury Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 4 | #include <haproxy/cfgparse.h> |
Frédéric Lécaille | 43910a9 | 2022-07-11 10:24:21 +0200 | [diff] [blame] | 5 | #include <haproxy/errors.h> |
Willy Tarreau | 07a3d53 | 2022-11-24 08:28:43 +0100 | [diff] [blame] | 6 | #include <haproxy/global.h> |
Amaury Denoyelle | c8b4ce4 | 2022-01-11 11:54:59 +0100 | [diff] [blame] | 7 | #include <haproxy/listener.h> |
| 8 | #include <haproxy/proxy-t.h> |
Frédéric Lécaille | 43910a9 | 2022-07-11 10:24:21 +0200 | [diff] [blame] | 9 | #include <haproxy/quic_cc-t.h> |
Amaury Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 10 | #include <haproxy/tools.h> |
Amaury Denoyelle | c8b4ce4 | 2022-01-11 11:54:59 +0100 | [diff] [blame] | 11 | |
Amaury Denoyelle | b76ae69 | 2022-01-11 14:16:37 +0100 | [diff] [blame] | 12 | static int bind_parse_quic_force_retry(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 13 | { |
Willy Tarreau | 787e92a | 2022-05-20 16:06:01 +0200 | [diff] [blame] | 14 | conf->options |= BC_O_QUIC_FORCE_RETRY; |
Amaury Denoyelle | b76ae69 | 2022-01-11 14:16:37 +0100 | [diff] [blame] | 15 | return 0; |
| 16 | } |
| 17 | |
Frédéric Lécaille | 43910a9 | 2022-07-11 10:24:21 +0200 | [diff] [blame] | 18 | /* parse "quic-cc-algo" bind keyword */ |
| 19 | static 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écaille | db4bc6b | 2023-03-31 15:21:55 +0200 | [diff] [blame] | 23 | char *arg; |
Frédéric Lécaille | 43910a9 | 2022-07-11 10:24:21 +0200 | [diff] [blame] | 24 | |
| 25 | if (!*args[cur_arg + 1]) { |
Ilya Shipitsin | 4a689da | 2022-10-29 09:34:32 +0500 | [diff] [blame] | 26 | memprintf(err, "'%s' : missing control congestion algorithm", args[cur_arg]); |
Frédéric Lécaille | 43910a9 | 2022-07-11 10:24:21 +0200 | [diff] [blame] | 27 | return ERR_ALERT | ERR_FATAL; |
| 28 | } |
| 29 | |
Frédéric Lécaille | db4bc6b | 2023-03-31 15:21:55 +0200 | [diff] [blame] | 30 | arg = args[cur_arg + 1]; |
| 31 | if (strcmp(arg, "newreno") == 0) |
Frédéric Lécaille | 43910a9 | 2022-07-11 10:24:21 +0200 | [diff] [blame] | 32 | cc_algo = &quic_cc_algo_nr; |
Frédéric Lécaille | db4bc6b | 2023-03-31 15:21:55 +0200 | [diff] [blame] | 33 | else if (strcmp(arg, "cubic") == 0) |
Frédéric Lécaille | 43910a9 | 2022-07-11 10:24:21 +0200 | [diff] [blame] | 34 | cc_algo = &quic_cc_algo_cubic; |
Frédéric Lécaille | db4bc6b | 2023-03-31 15:21:55 +0200 | [diff] [blame] | 35 | 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écaille | 43910a9 | 2022-07-11 10:24:21 +0200 | [diff] [blame] | 44 | 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 Denoyelle | c8b4ce4 | 2022-01-11 11:54:59 +0100 | [diff] [blame] | 53 | static struct bind_kw_list bind_kws = { "QUIC", { }, { |
Amaury Denoyelle | b76ae69 | 2022-01-11 14:16:37 +0100 | [diff] [blame] | 54 | { "quic-force-retry", bind_parse_quic_force_retry, 0 }, |
Frédéric Lécaille | 43910a9 | 2022-07-11 10:24:21 +0200 | [diff] [blame] | 55 | { "quic-cc-algo", bind_parse_quic_cc_algo, 1 }, |
Amaury Denoyelle | c8b4ce4 | 2022-01-11 11:54:59 +0100 | [diff] [blame] | 56 | { NULL, NULL, 0 }, |
| 57 | }}; |
| 58 | |
| 59 | INITCALL1(STG_REGISTER, bind_register_keywords, &bind_kws); |
Amaury Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 60 | |
Amaury Denoyelle | 511ddd5 | 2022-11-18 17:42:16 +0100 | [diff] [blame] | 61 | /* parse "tune.quic.socket-owner", accepts "listener" or "connection" */ |
| 62 | static 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écaille | 1d96d6e | 2022-05-23 16:38:14 +0200 | [diff] [blame] | 84 | /* 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 | */ |
| 88 | static 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écaille | 9286210 | 2022-05-20 16:29:10 +0200 | [diff] [blame] | 130 | /* Parse any tune.quic.* setting with strictly positive integer values. |
| 131 | * Return -1 on alert, or 0 if succeeded. |
| 132 | */ |
| 133 | static 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 Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 137 | { |
| 138 | unsigned int arg = 0; |
Frédéric Lécaille | 9286210 | 2022-05-20 16:29:10 +0200 | [diff] [blame] | 139 | int prefix_len = strlen("tune.quic."); |
Frédéric Lécaille | 2674098 | 2022-05-23 17:28:01 +0200 | [diff] [blame] | 140 | const char *suffix; |
Amaury Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 141 | |
| 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écaille | 2674098 | 2022-05-23 17:28:01 +0200 | [diff] [blame] | 153 | suffix = args[0] + prefix_len; |
Frédéric Lécaille | 38dea05 | 2022-05-25 17:14:28 +0200 | [diff] [blame] | 154 | if (strcmp(suffix, "frontend.conn-tx-buffers.limit") == 0) |
Frédéric Lécaille | 9286210 | 2022-05-20 16:29:10 +0200 | [diff] [blame] | 155 | global.tune.quic_streams_buf = arg; |
Frédéric Lécaille | 2674098 | 2022-05-23 17:28:01 +0200 | [diff] [blame] | 156 | else if (strcmp(suffix, "frontend.max-streams-bidi") == 0) |
| 157 | global.tune.quic_frontend_max_streams_bidi = arg; |
Amaury Denoyelle | 24d5b72 | 2023-01-31 11:44:50 +0100 | [diff] [blame] | 158 | else if (strcmp(suffix, "max-frame-loss") == 0) |
| 159 | global.tune.quic_max_frame_loss = arg; |
Frédéric Lécaille | 2674098 | 2022-05-23 17:28:01 +0200 | [diff] [blame] | 160 | else if (strcmp(suffix, "retry-threshold") == 0) |
Frédéric Lécaille | 9286210 | 2022-05-20 16:29:10 +0200 | [diff] [blame] | 161 | 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 Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | static struct cfg_kw_list cfg_kws = {ILH, { |
Amaury Denoyelle | 511ddd5 | 2022-11-18 17:42:16 +0100 | [diff] [blame] | 171 | { CFG_GLOBAL, "tune.quic.socket-owner", cfg_parse_quic_tune_socket_owner }, |
Frédéric Lécaille | 1d96d6e | 2022-05-23 16:38:14 +0200 | [diff] [blame] | 172 | { CFG_GLOBAL, "tune.quic.backend.max-idle-timeou", cfg_parse_quic_time }, |
Frédéric Lécaille | 38dea05 | 2022-05-25 17:14:28 +0200 | [diff] [blame] | 173 | { CFG_GLOBAL, "tune.quic.frontend.conn-tx-buffers.limit", cfg_parse_quic_tune_setting }, |
Frédéric Lécaille | 2674098 | 2022-05-23 17:28:01 +0200 | [diff] [blame] | 174 | { CFG_GLOBAL, "tune.quic.frontend.max-streams-bidi", cfg_parse_quic_tune_setting }, |
Frédéric Lécaille | 1d96d6e | 2022-05-23 16:38:14 +0200 | [diff] [blame] | 175 | { CFG_GLOBAL, "tune.quic.frontend.max-idle-timeout", cfg_parse_quic_time }, |
Amaury Denoyelle | 24d5b72 | 2023-01-31 11:44:50 +0100 | [diff] [blame] | 176 | { CFG_GLOBAL, "tune.quic.max-frame-loss", cfg_parse_quic_tune_setting }, |
Frédéric Lécaille | 9286210 | 2022-05-20 16:29:10 +0200 | [diff] [blame] | 177 | { CFG_GLOBAL, "tune.quic.retry-threshold", cfg_parse_quic_tune_setting }, |
Amaury Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 178 | { 0, NULL, NULL } |
| 179 | }}; |
| 180 | |
| 181 | INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws); |