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; |
| 23 | |
| 24 | if (!*args[cur_arg + 1]) { |
Ilya Shipitsin | 4a689da | 2022-10-29 09:34:32 +0500 | [diff] [blame] | 25 | 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] | 26 | return ERR_ALERT | ERR_FATAL; |
| 27 | } |
| 28 | |
Tim Duesterhus | a6fc616 | 2022-10-08 12:33:19 +0200 | [diff] [blame] | 29 | if (strcmp(args[cur_arg + 1], "newreno") == 0) |
Frédéric Lécaille | 43910a9 | 2022-07-11 10:24:21 +0200 | [diff] [blame] | 30 | cc_algo = &quic_cc_algo_nr; |
Tim Duesterhus | a6fc616 | 2022-10-08 12:33:19 +0200 | [diff] [blame] | 31 | else if (strcmp(args[cur_arg + 1], "cubic") == 0) |
Frédéric Lécaille | 43910a9 | 2022-07-11 10:24:21 +0200 | [diff] [blame] | 32 | 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 Denoyelle | c8b4ce4 | 2022-01-11 11:54:59 +0100 | [diff] [blame] | 42 | static struct bind_kw_list bind_kws = { "QUIC", { }, { |
Amaury Denoyelle | b76ae69 | 2022-01-11 14:16:37 +0100 | [diff] [blame] | 43 | { "quic-force-retry", bind_parse_quic_force_retry, 0 }, |
Frédéric Lécaille | 43910a9 | 2022-07-11 10:24:21 +0200 | [diff] [blame] | 44 | { "quic-cc-algo", bind_parse_quic_cc_algo, 1 }, |
Amaury Denoyelle | c8b4ce4 | 2022-01-11 11:54:59 +0100 | [diff] [blame] | 45 | { NULL, NULL, 0 }, |
| 46 | }}; |
| 47 | |
| 48 | INITCALL1(STG_REGISTER, bind_register_keywords, &bind_kws); |
Amaury Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 49 | |
Amaury Denoyelle | 511ddd5 | 2022-11-18 17:42:16 +0100 | [diff] [blame] | 50 | /* parse "tune.quic.socket-owner", accepts "listener" or "connection" */ |
| 51 | static 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écaille | 1d96d6e | 2022-05-23 16:38:14 +0200 | [diff] [blame] | 73 | /* 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 | */ |
| 77 | static 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écaille | 9286210 | 2022-05-20 16:29:10 +0200 | [diff] [blame] | 119 | /* Parse any tune.quic.* setting with strictly positive integer values. |
| 120 | * Return -1 on alert, or 0 if succeeded. |
| 121 | */ |
| 122 | static 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 Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 126 | { |
| 127 | unsigned int arg = 0; |
Frédéric Lécaille | 9286210 | 2022-05-20 16:29:10 +0200 | [diff] [blame] | 128 | int prefix_len = strlen("tune.quic."); |
Frédéric Lécaille | 2674098 | 2022-05-23 17:28:01 +0200 | [diff] [blame] | 129 | const char *suffix; |
Amaury Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 130 | |
| 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écaille | 2674098 | 2022-05-23 17:28:01 +0200 | [diff] [blame] | 142 | suffix = args[0] + prefix_len; |
Frédéric Lécaille | 38dea05 | 2022-05-25 17:14:28 +0200 | [diff] [blame] | 143 | if (strcmp(suffix, "frontend.conn-tx-buffers.limit") == 0) |
Frédéric Lécaille | 9286210 | 2022-05-20 16:29:10 +0200 | [diff] [blame] | 144 | global.tune.quic_streams_buf = arg; |
Frédéric Lécaille | 2674098 | 2022-05-23 17:28:01 +0200 | [diff] [blame] | 145 | 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écaille | 9286210 | 2022-05-20 16:29:10 +0200 | [diff] [blame] | 148 | 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 Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | static struct cfg_kw_list cfg_kws = {ILH, { |
Amaury Denoyelle | 511ddd5 | 2022-11-18 17:42:16 +0100 | [diff] [blame] | 158 | { 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] | 159 | { 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] | 160 | { 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] | 161 | { 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] | 162 | { CFG_GLOBAL, "tune.quic.frontend.max-idle-timeout", cfg_parse_quic_time }, |
Frédéric Lécaille | 9286210 | 2022-05-20 16:29:10 +0200 | [diff] [blame] | 163 | { CFG_GLOBAL, "tune.quic.retry-threshold", cfg_parse_quic_tune_setting }, |
Amaury Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 164 | { 0, NULL, NULL } |
| 165 | }}; |
| 166 | |
| 167 | INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws); |