Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Protocol registration functions. |
| 3 | * |
| 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
Willy Tarreau | a6e3be7 | 2016-08-10 18:24:48 +0200 | [diff] [blame] | 13 | #include <sys/types.h> |
Willy Tarreau | b550d00 | 2015-02-20 16:53:25 +0100 | [diff] [blame] | 14 | #include <sys/socket.h> |
| 15 | |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 16 | #include <haproxy/api.h> |
Willy Tarreau | 8d36697 | 2020-05-27 16:10:29 +0200 | [diff] [blame] | 17 | #include <haproxy/errors.h> |
Frédéric Lécaille | 12a0317 | 2023-01-12 15:23:54 +0100 | [diff] [blame] | 18 | #include <haproxy/global.h> |
Willy Tarreau | 853b297 | 2020-05-27 18:01:47 +0200 | [diff] [blame] | 19 | #include <haproxy/list.h> |
Willy Tarreau | 9432085 | 2020-09-01 18:48:35 +0200 | [diff] [blame] | 20 | #include <haproxy/listener.h> |
Frédéric Lécaille | 12a0317 | 2023-01-12 15:23:54 +0100 | [diff] [blame] | 21 | #include <haproxy/proto_quic.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 22 | #include <haproxy/protocol.h> |
Willy Tarreau | e91bff2 | 2020-09-02 11:11:43 +0200 | [diff] [blame] | 23 | #include <haproxy/proxy.h> |
Willy Tarreau | f1003ea | 2023-04-22 18:26:56 +0200 | [diff] [blame] | 24 | #include <haproxy/sock.h> |
Willy Tarreau | 48fbcae | 2020-06-03 18:09:46 +0200 | [diff] [blame] | 25 | #include <haproxy/tools.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 26 | |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 27 | |
| 28 | /* List head of all registered protocols */ |
| 29 | static struct list protocols = LIST_HEAD_INIT(protocols); |
Willy Tarreau | e3b4518 | 2021-10-27 17:28:55 +0200 | [diff] [blame] | 30 | struct protocol *__protocol_by_family[AF_CUST_MAX][PROTO_NUM_TYPES][2] __read_mostly = { }; |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 31 | |
Willy Tarreau | daacf36 | 2019-07-24 16:45:02 +0200 | [diff] [blame] | 32 | /* This is the global spinlock we may need to register/unregister listeners or |
| 33 | * protocols. Its main purpose is in fact to serialize the rare stop/deinit() |
| 34 | * phases. |
| 35 | */ |
| 36 | __decl_spinlock(proto_lock); |
| 37 | |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 38 | /* Registers the protocol <proto> */ |
| 39 | void protocol_register(struct protocol *proto) |
| 40 | { |
Willy Tarreau | bdcee7f | 2021-10-27 15:06:35 +0200 | [diff] [blame] | 41 | int sock_domain = proto->fam->sock_domain; |
| 42 | |
| 43 | BUG_ON(sock_domain < 0 || sock_domain >= AF_CUST_MAX); |
Willy Tarreau | e3b4518 | 2021-10-27 17:28:55 +0200 | [diff] [blame] | 44 | BUG_ON(proto->proto_type >= PROTO_NUM_TYPES); |
Willy Tarreau | bdcee7f | 2021-10-27 15:06:35 +0200 | [diff] [blame] | 45 | |
Willy Tarreau | daacf36 | 2019-07-24 16:45:02 +0200 | [diff] [blame] | 46 | HA_SPIN_LOCK(PROTO_LOCK, &proto_lock); |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 47 | LIST_APPEND(&protocols, &proto->list); |
Willy Tarreau | bdcee7f | 2021-10-27 15:06:35 +0200 | [diff] [blame] | 48 | __protocol_by_family[sock_domain] |
Willy Tarreau | e3b4518 | 2021-10-27 17:28:55 +0200 | [diff] [blame] | 49 | [proto->proto_type] |
Willy Tarreau | 91b4726 | 2022-05-20 16:36:46 +0200 | [diff] [blame] | 50 | [proto->xprt_type == PROTO_TYPE_DGRAM] = proto; |
Willy Tarreau | daacf36 | 2019-07-24 16:45:02 +0200 | [diff] [blame] | 51 | HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock); |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /* Unregisters the protocol <proto>. Note that all listeners must have |
| 55 | * previously been unbound. |
| 56 | */ |
| 57 | void protocol_unregister(struct protocol *proto) |
| 58 | { |
Willy Tarreau | daacf36 | 2019-07-24 16:45:02 +0200 | [diff] [blame] | 59 | HA_SPIN_LOCK(PROTO_LOCK, &proto_lock); |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 60 | LIST_DELETE(&proto->list); |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 61 | LIST_INIT(&proto->list); |
Willy Tarreau | daacf36 | 2019-07-24 16:45:02 +0200 | [diff] [blame] | 62 | HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock); |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 63 | } |
| 64 | |
Willy Tarreau | 65df7e0 | 2023-04-22 15:02:35 +0200 | [diff] [blame] | 65 | /* clears flag <flag> on all protocols. */ |
| 66 | void protocol_clrf_all(uint flag) |
| 67 | { |
| 68 | struct protocol *proto; |
| 69 | |
| 70 | HA_SPIN_LOCK(PROTO_LOCK, &proto_lock); |
| 71 | list_for_each_entry(proto, &protocols, list) |
| 72 | proto->flags &= ~flag; |
| 73 | HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock); |
| 74 | } |
| 75 | |
| 76 | /* sets flag <flag> on all protocols. */ |
| 77 | void protocol_setf_all(uint flag) |
| 78 | { |
| 79 | struct protocol *proto; |
| 80 | |
| 81 | HA_SPIN_LOCK(PROTO_LOCK, &proto_lock); |
| 82 | list_for_each_entry(proto, &protocols, list) |
| 83 | proto->flags |= flag; |
| 84 | HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock); |
| 85 | } |
| 86 | |
Willy Tarreau | 8a5e6f4 | 2023-04-22 17:39:30 +0200 | [diff] [blame] | 87 | /* Checks if protocol <proto> supports PROTO_F flag <flag>. Returns zero if not, |
| 88 | * non-zero if supported. It may return a cached value from a previous test, |
| 89 | * and may run live tests then update the proto's flags to cache a result. It's |
| 90 | * better to call it only if needed so that it doesn't result in modules being |
| 91 | * loaded in case of a live test. It is only supposed to be used during boot. |
| 92 | */ |
| 93 | int protocol_supports_flag(struct protocol *proto, uint flag) |
| 94 | { |
| 95 | if (flag == PROTO_F_REUSEPORT_SUPPORTED) { |
Willy Tarreau | f1003ea | 2023-04-22 18:26:56 +0200 | [diff] [blame] | 96 | int ret = 0; |
| 97 | |
Willy Tarreau | 8a5e6f4 | 2023-04-22 17:39:30 +0200 | [diff] [blame] | 98 | /* check if the protocol supports SO_REUSEPORT */ |
| 99 | if (!(_HA_ATOMIC_LOAD(&proto->flags) & PROTO_F_REUSEPORT_SUPPORTED)) |
| 100 | return 0; |
| 101 | |
Willy Tarreau | f1003ea | 2023-04-22 18:26:56 +0200 | [diff] [blame] | 102 | /* at least nobody said it was not supported */ |
| 103 | if (_HA_ATOMIC_LOAD(&proto->flags) & PROTO_F_REUSEPORT_TESTED) |
| 104 | return 1; |
| 105 | |
| 106 | /* run a live check */ |
| 107 | ret = _sock_supports_reuseport(proto->fam, proto->sock_type, proto->sock_prot); |
| 108 | if (!ret) |
| 109 | _HA_ATOMIC_AND(&proto->flags, ~PROTO_F_REUSEPORT_SUPPORTED); |
| 110 | |
| 111 | _HA_ATOMIC_OR(&proto->flags, PROTO_F_REUSEPORT_TESTED); |
| 112 | return ret; |
Willy Tarreau | 8a5e6f4 | 2023-04-22 17:39:30 +0200 | [diff] [blame] | 113 | } |
| 114 | return 0; |
| 115 | } |
| 116 | |
Frédéric Lécaille | df3f457 | 2023-07-21 18:22:38 +0200 | [diff] [blame] | 117 | #ifdef USE_QUIC |
| 118 | /* Return 1 if QUIC protocol may be bound, 0 if no, depending on the tuning |
| 119 | * parameters. |
| 120 | */ |
Frédéric Lécaille | ee7b2bb | 2023-08-08 11:41:13 +0200 | [diff] [blame] | 121 | static inline int protocol_may_bind_quic(struct listener *l) |
Frédéric Lécaille | df3f457 | 2023-07-21 18:22:38 +0200 | [diff] [blame] | 122 | { |
| 123 | if (global.tune.options & GTUNE_NO_QUIC) |
| 124 | return 0; |
Frédéric Lécaille | df3f457 | 2023-07-21 18:22:38 +0200 | [diff] [blame] | 125 | return 1; |
| 126 | } |
| 127 | #endif |
| 128 | |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 129 | /* binds all listeners of all registered protocols. Returns a composition |
| 130 | * of ERR_NONE, ERR_RETRYABLE, ERR_FATAL. |
| 131 | */ |
Willy Tarreau | e91bff2 | 2020-09-02 11:11:43 +0200 | [diff] [blame] | 132 | int protocol_bind_all(int verbose) |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 133 | { |
| 134 | struct protocol *proto; |
Willy Tarreau | 9432085 | 2020-09-01 18:48:35 +0200 | [diff] [blame] | 135 | struct listener *listener; |
Willy Tarreau | fc97488 | 2020-09-02 18:22:11 +0200 | [diff] [blame] | 136 | struct receiver *receiver; |
Bjoern Jacke | ed17485 | 2021-01-12 19:24:43 +0100 | [diff] [blame] | 137 | char msg[1000]; |
Willy Tarreau | fc97488 | 2020-09-02 18:22:11 +0200 | [diff] [blame] | 138 | char *errmsg; |
Willy Tarreau | e91bff2 | 2020-09-02 11:11:43 +0200 | [diff] [blame] | 139 | int err, lerr; |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 140 | |
| 141 | err = 0; |
Willy Tarreau | daacf36 | 2019-07-24 16:45:02 +0200 | [diff] [blame] | 142 | HA_SPIN_LOCK(PROTO_LOCK, &proto_lock); |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 143 | list_for_each_entry(proto, &protocols, list) { |
Willy Tarreau | d7f331c | 2020-09-25 17:01:43 +0200 | [diff] [blame] | 144 | list_for_each_entry(receiver, &proto->receivers, proto_list) { |
Frédéric Lécaille | ee7b2bb | 2023-08-08 11:41:13 +0200 | [diff] [blame] | 145 | listener = LIST_ELEM(receiver, struct listener *, rx); |
Frédéric Lécaille | 12a0317 | 2023-01-12 15:23:54 +0100 | [diff] [blame] | 146 | #ifdef USE_QUIC |
Frédéric Lécaille | df3f457 | 2023-07-21 18:22:38 +0200 | [diff] [blame] | 147 | if ((proto == &proto_quic4 || proto == &proto_quic6) && |
Frédéric Lécaille | ee7b2bb | 2023-08-08 11:41:13 +0200 | [diff] [blame] | 148 | !protocol_may_bind_quic(listener)) |
Frédéric Lécaille | 12a0317 | 2023-01-12 15:23:54 +0100 | [diff] [blame] | 149 | continue; |
| 150 | #endif |
Willy Tarreau | fc97488 | 2020-09-02 18:22:11 +0200 | [diff] [blame] | 151 | |
Willy Tarreau | 233ad28 | 2020-10-15 21:45:15 +0200 | [diff] [blame] | 152 | lerr = proto->fam->bind(receiver, &errmsg); |
Willy Tarreau | fc97488 | 2020-09-02 18:22:11 +0200 | [diff] [blame] | 153 | err |= lerr; |
Willy Tarreau | e91bff2 | 2020-09-02 11:11:43 +0200 | [diff] [blame] | 154 | |
| 155 | /* errors are reported if <verbose> is set or if they are fatal */ |
| 156 | if (verbose || (lerr & (ERR_FATAL | ERR_ABORT))) { |
| 157 | struct proxy *px = listener->bind_conf->frontend; |
| 158 | |
| 159 | if (lerr & ERR_ALERT) |
Willy Tarreau | 37de553 | 2021-10-14 11:55:48 +0200 | [diff] [blame] | 160 | ha_alert("Binding [%s:%d] for %s %s: %s\n", |
| 161 | listener->bind_conf->file, listener->bind_conf->line, |
Willy Tarreau | fc97488 | 2020-09-02 18:22:11 +0200 | [diff] [blame] | 162 | proxy_type_str(px), px->id, errmsg); |
Willy Tarreau | e91bff2 | 2020-09-02 11:11:43 +0200 | [diff] [blame] | 163 | else if (lerr & ERR_WARN) |
Willy Tarreau | 37de553 | 2021-10-14 11:55:48 +0200 | [diff] [blame] | 164 | ha_warning("Binding [%s:%d] for %s %s: %s\n", |
| 165 | listener->bind_conf->file, listener->bind_conf->line, |
Willy Tarreau | fc97488 | 2020-09-02 18:22:11 +0200 | [diff] [blame] | 166 | proxy_type_str(px), px->id, errmsg); |
Willy Tarreau | e91bff2 | 2020-09-02 11:11:43 +0200 | [diff] [blame] | 167 | } |
Aurelien DARRAGON | 8429627 | 2023-02-07 15:51:58 +0100 | [diff] [blame] | 168 | if (lerr != ERR_NONE) |
| 169 | ha_free(&errmsg); |
| 170 | |
Willy Tarreau | fc97488 | 2020-09-02 18:22:11 +0200 | [diff] [blame] | 171 | if (lerr & ERR_ABORT) |
| 172 | break; |
Willy Tarreau | e91bff2 | 2020-09-02 11:11:43 +0200 | [diff] [blame] | 173 | |
Willy Tarreau | fc97488 | 2020-09-02 18:22:11 +0200 | [diff] [blame] | 174 | if (lerr & ~ERR_WARN) |
| 175 | continue; |
| 176 | |
| 177 | /* for now there's still always a listening function */ |
| 178 | BUG_ON(!proto->listen); |
| 179 | lerr = proto->listen(listener, msg, sizeof(msg)); |
Willy Tarreau | e91bff2 | 2020-09-02 11:11:43 +0200 | [diff] [blame] | 180 | err |= lerr; |
Willy Tarreau | fc97488 | 2020-09-02 18:22:11 +0200 | [diff] [blame] | 181 | |
| 182 | if (verbose || (lerr & (ERR_FATAL | ERR_ABORT))) { |
| 183 | struct proxy *px = listener->bind_conf->frontend; |
| 184 | |
| 185 | if (lerr & ERR_ALERT) |
Willy Tarreau | 37de553 | 2021-10-14 11:55:48 +0200 | [diff] [blame] | 186 | ha_alert("Starting [%s:%d] for %s %s: %s\n", |
| 187 | listener->bind_conf->file, listener->bind_conf->line, |
Willy Tarreau | fc97488 | 2020-09-02 18:22:11 +0200 | [diff] [blame] | 188 | proxy_type_str(px), px->id, msg); |
| 189 | else if (lerr & ERR_WARN) |
Willy Tarreau | 37de553 | 2021-10-14 11:55:48 +0200 | [diff] [blame] | 190 | ha_warning("Starting [%s:%d] for %s %s: %s\n", |
| 191 | listener->bind_conf->file, listener->bind_conf->line, |
Willy Tarreau | fc97488 | 2020-09-02 18:22:11 +0200 | [diff] [blame] | 192 | proxy_type_str(px), px->id, msg); |
| 193 | } |
Willy Tarreau | e91bff2 | 2020-09-02 11:11:43 +0200 | [diff] [blame] | 194 | if (lerr & ERR_ABORT) |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 195 | break; |
| 196 | } |
Willy Tarreau | e91bff2 | 2020-09-02 11:11:43 +0200 | [diff] [blame] | 197 | if (err & ERR_ABORT) |
| 198 | break; |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 199 | } |
Willy Tarreau | daacf36 | 2019-07-24 16:45:02 +0200 | [diff] [blame] | 200 | HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock); |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 201 | return err; |
| 202 | } |
| 203 | |
| 204 | /* unbinds all listeners of all registered protocols. They are also closed. |
| 205 | * This must be performed before calling exit() in order to get a chance to |
| 206 | * remove file-system based sockets and pipes. |
| 207 | * Returns a composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL, ERR_ABORT. |
| 208 | */ |
| 209 | int protocol_unbind_all(void) |
| 210 | { |
| 211 | struct protocol *proto; |
Willy Tarreau | ca21262 | 2020-09-02 10:31:31 +0200 | [diff] [blame] | 212 | struct listener *listener; |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 213 | int err; |
| 214 | |
| 215 | err = 0; |
Willy Tarreau | daacf36 | 2019-07-24 16:45:02 +0200 | [diff] [blame] | 216 | HA_SPIN_LOCK(PROTO_LOCK, &proto_lock); |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 217 | list_for_each_entry(proto, &protocols, list) { |
Willy Tarreau | d7f331c | 2020-09-25 17:01:43 +0200 | [diff] [blame] | 218 | list_for_each_entry(listener, &proto->receivers, rx.proto_list) |
Willy Tarreau | ca21262 | 2020-09-02 10:31:31 +0200 | [diff] [blame] | 219 | unbind_listener(listener); |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 220 | } |
Willy Tarreau | daacf36 | 2019-07-24 16:45:02 +0200 | [diff] [blame] | 221 | HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock); |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 222 | return err; |
| 223 | } |
| 224 | |
Willy Tarreau | eb77824 | 2021-06-11 16:27:10 +0200 | [diff] [blame] | 225 | /* stops all listeners of all registered protocols. This will normally catch |
| 226 | * every single listener, all protocols included. This is to be used during |
| 227 | * soft_stop() only. It does not return any error. |
Willy Tarreau | 02e8557 | 2020-10-07 16:50:49 +0200 | [diff] [blame] | 228 | */ |
| 229 | void protocol_stop_now(void) |
| 230 | { |
| 231 | struct protocol *proto; |
| 232 | struct listener *listener, *lback; |
| 233 | |
| 234 | HA_SPIN_LOCK(PROTO_LOCK, &proto_lock); |
| 235 | list_for_each_entry(proto, &protocols, list) { |
| 236 | list_for_each_entry_safe(listener, lback, &proto->receivers, rx.proto_list) |
Aurelien DARRAGON | 4059e09 | 2023-02-06 17:06:03 +0100 | [diff] [blame] | 237 | stop_listener(listener, 0, 1, 0); |
Willy Tarreau | 02e8557 | 2020-10-07 16:50:49 +0200 | [diff] [blame] | 238 | } |
| 239 | HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock); |
| 240 | } |
| 241 | |
Aurelien DARRAGON | d3ffba4 | 2023-02-13 17:45:08 +0100 | [diff] [blame] | 242 | /* suspends all listeners of all registered protocols. This is typically |
Willy Tarreau | 09819d1 | 2020-09-24 16:26:50 +0200 | [diff] [blame] | 243 | * used on SIG_TTOU to release all listening sockets for the time needed to |
Aurelien DARRAGON | d3ffba4 | 2023-02-13 17:45:08 +0100 | [diff] [blame] | 244 | * try to bind a new process. The listeners enter LI_PAUSED or LI_ASSIGNED. |
| 245 | * It returns ERR_NONE, with ERR_FATAL on failure. |
Willy Tarreau | 09819d1 | 2020-09-24 16:26:50 +0200 | [diff] [blame] | 246 | */ |
| 247 | int protocol_pause_all(void) |
| 248 | { |
| 249 | struct protocol *proto; |
| 250 | struct listener *listener; |
| 251 | int err; |
| 252 | |
| 253 | err = 0; |
| 254 | HA_SPIN_LOCK(PROTO_LOCK, &proto_lock); |
| 255 | list_for_each_entry(proto, &protocols, list) { |
Willy Tarreau | d7f331c | 2020-09-25 17:01:43 +0200 | [diff] [blame] | 256 | list_for_each_entry(listener, &proto->receivers, rx.proto_list) |
Aurelien DARRAGON | d3ffba4 | 2023-02-13 17:45:08 +0100 | [diff] [blame] | 257 | if (!suspend_listener(listener, 0, 0)) |
Willy Tarreau | 09819d1 | 2020-09-24 16:26:50 +0200 | [diff] [blame] | 258 | err |= ERR_FATAL; |
| 259 | } |
| 260 | HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock); |
| 261 | return err; |
| 262 | } |
| 263 | |
| 264 | /* resumes all listeners of all registered protocols. This is typically used on |
| 265 | * SIG_TTIN to re-enable listening sockets after a new process failed to bind. |
| 266 | * The listeners switch to LI_READY/LI_FULL. It returns ERR_NONE, with ERR_FATAL |
| 267 | * on failure. |
| 268 | */ |
| 269 | int protocol_resume_all(void) |
| 270 | { |
| 271 | struct protocol *proto; |
| 272 | struct listener *listener; |
| 273 | int err; |
| 274 | |
| 275 | err = 0; |
| 276 | HA_SPIN_LOCK(PROTO_LOCK, &proto_lock); |
| 277 | list_for_each_entry(proto, &protocols, list) { |
Willy Tarreau | d7f331c | 2020-09-25 17:01:43 +0200 | [diff] [blame] | 278 | list_for_each_entry(listener, &proto->receivers, rx.proto_list) |
Aurelien DARRAGON | 4059e09 | 2023-02-06 17:06:03 +0100 | [diff] [blame] | 279 | if (!resume_listener(listener, 0, 0)) |
Willy Tarreau | 09819d1 | 2020-09-24 16:26:50 +0200 | [diff] [blame] | 280 | err |= ERR_FATAL; |
| 281 | } |
| 282 | HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock); |
| 283 | return err; |
| 284 | } |
| 285 | |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 286 | /* enables all listeners of all registered protocols. This is intended to be |
Willy Tarreau | 5b95ae6 | 2020-09-25 16:41:05 +0200 | [diff] [blame] | 287 | * used after a fork() to enable reading on all file descriptors. Returns |
| 288 | * composition of ERR_NONE. |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 289 | */ |
| 290 | int protocol_enable_all(void) |
| 291 | { |
| 292 | struct protocol *proto; |
Willy Tarreau | 5b95ae6 | 2020-09-25 16:41:05 +0200 | [diff] [blame] | 293 | struct listener *listener; |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 294 | |
Willy Tarreau | daacf36 | 2019-07-24 16:45:02 +0200 | [diff] [blame] | 295 | HA_SPIN_LOCK(PROTO_LOCK, &proto_lock); |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 296 | list_for_each_entry(proto, &protocols, list) { |
Willy Tarreau | d7f331c | 2020-09-25 17:01:43 +0200 | [diff] [blame] | 297 | list_for_each_entry(listener, &proto->receivers, rx.proto_list) |
Willy Tarreau | 5b95ae6 | 2020-09-25 16:41:05 +0200 | [diff] [blame] | 298 | enable_listener(listener); |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 299 | } |
Willy Tarreau | daacf36 | 2019-07-24 16:45:02 +0200 | [diff] [blame] | 300 | HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock); |
Willy Tarreau | 5b95ae6 | 2020-09-25 16:41:05 +0200 | [diff] [blame] | 301 | return ERR_NONE; |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 302 | } |
| 303 | |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 304 | /* |
| 305 | * Local variables: |
| 306 | * c-indent-level: 8 |
| 307 | * c-basic-offset: 8 |
| 308 | * End: |
| 309 | */ |