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> |
Amaury Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 6 | #include <haproxy/global-t.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 | |
Frédéric Lécaille | 1d96d6e | 2022-05-23 16:38:14 +0200 | [diff] [blame] | 50 | /* 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 | */ |
| 54 | static 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écaille | 9286210 | 2022-05-20 16:29:10 +0200 | [diff] [blame] | 96 | /* Parse any tune.quic.* setting with strictly positive integer values. |
| 97 | * Return -1 on alert, or 0 if succeeded. |
| 98 | */ |
| 99 | static 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 Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 103 | { |
| 104 | unsigned int arg = 0; |
Frédéric Lécaille | 9286210 | 2022-05-20 16:29:10 +0200 | [diff] [blame] | 105 | int prefix_len = strlen("tune.quic."); |
Frédéric Lécaille | 2674098 | 2022-05-23 17:28:01 +0200 | [diff] [blame] | 106 | const char *suffix; |
Amaury Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 107 | |
| 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écaille | 2674098 | 2022-05-23 17:28:01 +0200 | [diff] [blame] | 119 | suffix = args[0] + prefix_len; |
Frédéric Lécaille | 38dea05 | 2022-05-25 17:14:28 +0200 | [diff] [blame] | 120 | if (strcmp(suffix, "frontend.conn-tx-buffers.limit") == 0) |
Frédéric Lécaille | 9286210 | 2022-05-20 16:29:10 +0200 | [diff] [blame] | 121 | global.tune.quic_streams_buf = arg; |
Frédéric Lécaille | 2674098 | 2022-05-23 17:28:01 +0200 | [diff] [blame] | 122 | 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écaille | 9286210 | 2022-05-20 16:29:10 +0200 | [diff] [blame] | 125 | 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 Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static struct cfg_kw_list cfg_kws = {ILH, { |
Frédéric Lécaille | 1d96d6e | 2022-05-23 16:38:14 +0200 | [diff] [blame] | 135 | { 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] | 136 | { 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] | 137 | { 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] | 138 | { 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] | 139 | { CFG_GLOBAL, "tune.quic.retry-threshold", cfg_parse_quic_tune_setting }, |
Amaury Denoyelle | 97e84c6 | 2022-04-19 18:26:55 +0200 | [diff] [blame] | 140 | { 0, NULL, NULL } |
| 141 | }}; |
| 142 | |
| 143 | INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws); |