2012-09-12 16:58:11 -04:00
|
|
|
/*
|
|
|
|
|
* Protocol registration functions.
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2016-08-10 12:24:48 -04:00
|
|
|
#include <sys/types.h>
|
2015-02-20 10:53:25 -05:00
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
2020-05-27 06:58:42 -04:00
|
|
|
#include <haproxy/api.h>
|
2020-05-27 10:10:29 -04:00
|
|
|
#include <haproxy/errors.h>
|
2023-01-12 09:23:54 -05:00
|
|
|
#include <haproxy/global.h>
|
2020-05-27 12:01:47 -04:00
|
|
|
#include <haproxy/list.h>
|
2020-09-01 12:48:35 -04:00
|
|
|
#include <haproxy/listener.h>
|
2023-01-12 09:23:54 -05:00
|
|
|
#include <haproxy/proto_quic.h>
|
2020-06-09 03:07:15 -04:00
|
|
|
#include <haproxy/protocol.h>
|
2020-09-02 05:11:43 -04:00
|
|
|
#include <haproxy/proxy.h>
|
2023-04-22 12:26:56 -04:00
|
|
|
#include <haproxy/sock.h>
|
2020-06-03 12:09:46 -04:00
|
|
|
#include <haproxy/tools.h>
|
2012-09-12 16:58:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/* List head of all registered protocols */
|
|
|
|
|
static struct list protocols = LIST_HEAD_INIT(protocols);
|
2021-10-27 11:28:55 -04:00
|
|
|
struct protocol *__protocol_by_family[AF_CUST_MAX][PROTO_NUM_TYPES][2] __read_mostly = { };
|
2012-09-12 16:58:11 -04:00
|
|
|
|
2019-07-24 10:45:02 -04:00
|
|
|
/* This is the global spinlock we may need to register/unregister listeners or
|
|
|
|
|
* protocols. Its main purpose is in fact to serialize the rare stop/deinit()
|
|
|
|
|
* phases.
|
|
|
|
|
*/
|
|
|
|
|
__decl_spinlock(proto_lock);
|
|
|
|
|
|
2012-09-12 16:58:11 -04:00
|
|
|
/* Registers the protocol <proto> */
|
|
|
|
|
void protocol_register(struct protocol *proto)
|
|
|
|
|
{
|
2021-10-27 09:06:35 -04:00
|
|
|
int sock_domain = proto->fam->sock_domain;
|
|
|
|
|
|
|
|
|
|
BUG_ON(sock_domain < 0 || sock_domain >= AF_CUST_MAX);
|
2021-10-27 11:28:55 -04:00
|
|
|
BUG_ON(proto->proto_type >= PROTO_NUM_TYPES);
|
2021-10-27 09:06:35 -04:00
|
|
|
|
2019-07-24 10:45:02 -04:00
|
|
|
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
|
2021-04-21 01:32:39 -04:00
|
|
|
LIST_APPEND(&protocols, &proto->list);
|
2021-10-27 09:06:35 -04:00
|
|
|
__protocol_by_family[sock_domain]
|
2021-10-27 11:28:55 -04:00
|
|
|
[proto->proto_type]
|
2022-05-20 10:36:46 -04:00
|
|
|
[proto->xprt_type == PROTO_TYPE_DGRAM] = proto;
|
2019-07-24 10:45:02 -04:00
|
|
|
HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
|
2012-09-12 16:58:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Unregisters the protocol <proto>. Note that all listeners must have
|
|
|
|
|
* previously been unbound.
|
|
|
|
|
*/
|
|
|
|
|
void protocol_unregister(struct protocol *proto)
|
|
|
|
|
{
|
2019-07-24 10:45:02 -04:00
|
|
|
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
|
2021-04-21 01:32:39 -04:00
|
|
|
LIST_DELETE(&proto->list);
|
2012-09-12 16:58:11 -04:00
|
|
|
LIST_INIT(&proto->list);
|
2019-07-24 10:45:02 -04:00
|
|
|
HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
|
2012-09-12 16:58:11 -04:00
|
|
|
}
|
|
|
|
|
|
2023-04-22 09:02:35 -04:00
|
|
|
/* clears flag <flag> on all protocols. */
|
|
|
|
|
void protocol_clrf_all(uint flag)
|
|
|
|
|
{
|
|
|
|
|
struct protocol *proto;
|
|
|
|
|
|
|
|
|
|
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
|
|
|
|
|
list_for_each_entry(proto, &protocols, list)
|
|
|
|
|
proto->flags &= ~flag;
|
|
|
|
|
HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* sets flag <flag> on all protocols. */
|
|
|
|
|
void protocol_setf_all(uint flag)
|
|
|
|
|
{
|
|
|
|
|
struct protocol *proto;
|
|
|
|
|
|
|
|
|
|
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
|
|
|
|
|
list_for_each_entry(proto, &protocols, list)
|
|
|
|
|
proto->flags |= flag;
|
|
|
|
|
HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-22 11:39:30 -04:00
|
|
|
/* Checks if protocol <proto> supports PROTO_F flag <flag>. Returns zero if not,
|
|
|
|
|
* non-zero if supported. It may return a cached value from a previous test,
|
|
|
|
|
* and may run live tests then update the proto's flags to cache a result. It's
|
|
|
|
|
* better to call it only if needed so that it doesn't result in modules being
|
|
|
|
|
* loaded in case of a live test. It is only supposed to be used during boot.
|
|
|
|
|
*/
|
|
|
|
|
int protocol_supports_flag(struct protocol *proto, uint flag)
|
|
|
|
|
{
|
|
|
|
|
if (flag == PROTO_F_REUSEPORT_SUPPORTED) {
|
2023-04-22 12:26:56 -04:00
|
|
|
int ret = 0;
|
|
|
|
|
|
2023-04-22 11:39:30 -04:00
|
|
|
/* check if the protocol supports SO_REUSEPORT */
|
|
|
|
|
if (!(_HA_ATOMIC_LOAD(&proto->flags) & PROTO_F_REUSEPORT_SUPPORTED))
|
|
|
|
|
return 0;
|
|
|
|
|
|
2023-04-22 12:26:56 -04:00
|
|
|
/* at least nobody said it was not supported */
|
|
|
|
|
if (_HA_ATOMIC_LOAD(&proto->flags) & PROTO_F_REUSEPORT_TESTED)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
/* run a live check */
|
|
|
|
|
ret = _sock_supports_reuseport(proto->fam, proto->sock_type, proto->sock_prot);
|
|
|
|
|
if (!ret)
|
|
|
|
|
_HA_ATOMIC_AND(&proto->flags, ~PROTO_F_REUSEPORT_SUPPORTED);
|
|
|
|
|
|
|
|
|
|
_HA_ATOMIC_OR(&proto->flags, PROTO_F_REUSEPORT_TESTED);
|
|
|
|
|
return ret;
|
2023-04-22 11:39:30 -04:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-21 12:22:38 -04:00
|
|
|
#ifdef USE_QUIC
|
|
|
|
|
/* Return 1 if QUIC protocol may be bound, 0 if no, depending on the tuning
|
|
|
|
|
* parameters.
|
|
|
|
|
*/
|
2023-08-08 05:41:13 -04:00
|
|
|
static inline int protocol_may_bind_quic(struct listener *l)
|
2023-07-21 12:22:38 -04:00
|
|
|
{
|
|
|
|
|
if (global.tune.options & GTUNE_NO_QUIC)
|
|
|
|
|
return 0;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-09-12 16:58:11 -04:00
|
|
|
/* binds all listeners of all registered protocols. Returns a composition
|
|
|
|
|
* of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
|
|
|
|
|
*/
|
2020-09-02 05:11:43 -04:00
|
|
|
int protocol_bind_all(int verbose)
|
2012-09-12 16:58:11 -04:00
|
|
|
{
|
|
|
|
|
struct protocol *proto;
|
2020-09-01 12:48:35 -04:00
|
|
|
struct listener *listener;
|
2020-09-02 12:22:11 -04:00
|
|
|
struct receiver *receiver;
|
2021-01-12 13:24:43 -05:00
|
|
|
char msg[1000];
|
2020-09-02 12:22:11 -04:00
|
|
|
char *errmsg;
|
2020-09-02 05:11:43 -04:00
|
|
|
int err, lerr;
|
2012-09-12 16:58:11 -04:00
|
|
|
|
|
|
|
|
err = 0;
|
2019-07-24 10:45:02 -04:00
|
|
|
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
|
2012-09-12 16:58:11 -04:00
|
|
|
list_for_each_entry(proto, &protocols, list) {
|
2020-09-25 11:01:43 -04:00
|
|
|
list_for_each_entry(receiver, &proto->receivers, proto_list) {
|
2023-08-08 05:41:13 -04:00
|
|
|
listener = LIST_ELEM(receiver, struct listener *, rx);
|
2023-01-12 09:23:54 -05:00
|
|
|
#ifdef USE_QUIC
|
2023-07-21 12:22:38 -04:00
|
|
|
if ((proto == &proto_quic4 || proto == &proto_quic6) &&
|
2023-08-08 05:41:13 -04:00
|
|
|
!protocol_may_bind_quic(listener))
|
2023-01-12 09:23:54 -05:00
|
|
|
continue;
|
|
|
|
|
#endif
|
2020-09-02 12:22:11 -04:00
|
|
|
|
2020-10-15 15:45:15 -04:00
|
|
|
lerr = proto->fam->bind(receiver, &errmsg);
|
2020-09-02 12:22:11 -04:00
|
|
|
err |= lerr;
|
2020-09-02 05:11:43 -04:00
|
|
|
|
|
|
|
|
/* errors are reported if <verbose> is set or if they are fatal */
|
|
|
|
|
if (verbose || (lerr & (ERR_FATAL | ERR_ABORT))) {
|
|
|
|
|
struct proxy *px = listener->bind_conf->frontend;
|
|
|
|
|
|
|
|
|
|
if (lerr & ERR_ALERT)
|
2021-10-14 05:55:48 -04:00
|
|
|
ha_alert("Binding [%s:%d] for %s %s: %s\n",
|
|
|
|
|
listener->bind_conf->file, listener->bind_conf->line,
|
2020-09-02 12:22:11 -04:00
|
|
|
proxy_type_str(px), px->id, errmsg);
|
2020-09-02 05:11:43 -04:00
|
|
|
else if (lerr & ERR_WARN)
|
2021-10-14 05:55:48 -04:00
|
|
|
ha_warning("Binding [%s:%d] for %s %s: %s\n",
|
|
|
|
|
listener->bind_conf->file, listener->bind_conf->line,
|
2020-09-02 12:22:11 -04:00
|
|
|
proxy_type_str(px), px->id, errmsg);
|
2020-09-02 05:11:43 -04:00
|
|
|
}
|
BUG/MINOR: protocol: fix minor memory leak in protocol_bind_all()
In protocol_bind_all() (involved in startup sequence):
We only free errmsg (set by fam->bind() attempt) when we make use of it.
But this could lead to some memory leaks because there are some cases
where we ignore the error message (e.g: verbose=0 with ERR_WARN messages).
As long as errmsg is set, we should always free it.
As mentioned earlier, this really is a minor leak because it can only occur on
specific conditions (error paths) during the startup phase.
This may be backported up to 2.4.
--
Backport notes:
-> 2.4 only:
Replace this:
| ha_warning("Binding [%s:%d] for %s %s: %s\n",
| listener->bind_conf->file, listener->bind_conf->line,
| proxy_type_str(px), px->id, errmsg);
By this:
| else if (lerr & ERR_WARN)
| ha_warning("Starting %s %s: %s\n",
| proxy_type_str(px), px->id, errmsg);
2023-02-07 09:51:58 -05:00
|
|
|
if (lerr != ERR_NONE)
|
|
|
|
|
ha_free(&errmsg);
|
|
|
|
|
|
2020-09-02 12:22:11 -04:00
|
|
|
if (lerr & ERR_ABORT)
|
|
|
|
|
break;
|
2020-09-02 05:11:43 -04:00
|
|
|
|
2020-09-02 12:22:11 -04:00
|
|
|
if (lerr & ~ERR_WARN)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* for now there's still always a listening function */
|
|
|
|
|
BUG_ON(!proto->listen);
|
|
|
|
|
lerr = proto->listen(listener, msg, sizeof(msg));
|
2020-09-02 05:11:43 -04:00
|
|
|
err |= lerr;
|
2020-09-02 12:22:11 -04:00
|
|
|
|
|
|
|
|
if (verbose || (lerr & (ERR_FATAL | ERR_ABORT))) {
|
|
|
|
|
struct proxy *px = listener->bind_conf->frontend;
|
|
|
|
|
|
|
|
|
|
if (lerr & ERR_ALERT)
|
2021-10-14 05:55:48 -04:00
|
|
|
ha_alert("Starting [%s:%d] for %s %s: %s\n",
|
|
|
|
|
listener->bind_conf->file, listener->bind_conf->line,
|
2020-09-02 12:22:11 -04:00
|
|
|
proxy_type_str(px), px->id, msg);
|
|
|
|
|
else if (lerr & ERR_WARN)
|
2021-10-14 05:55:48 -04:00
|
|
|
ha_warning("Starting [%s:%d] for %s %s: %s\n",
|
|
|
|
|
listener->bind_conf->file, listener->bind_conf->line,
|
2020-09-02 12:22:11 -04:00
|
|
|
proxy_type_str(px), px->id, msg);
|
|
|
|
|
}
|
2020-09-02 05:11:43 -04:00
|
|
|
if (lerr & ERR_ABORT)
|
2012-09-12 16:58:11 -04:00
|
|
|
break;
|
|
|
|
|
}
|
2020-09-02 05:11:43 -04:00
|
|
|
if (err & ERR_ABORT)
|
|
|
|
|
break;
|
2012-09-12 16:58:11 -04:00
|
|
|
}
|
2019-07-24 10:45:02 -04:00
|
|
|
HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
|
2012-09-12 16:58:11 -04:00
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* unbinds all listeners of all registered protocols. They are also closed.
|
|
|
|
|
* This must be performed before calling exit() in order to get a chance to
|
|
|
|
|
* remove file-system based sockets and pipes.
|
|
|
|
|
* Returns a composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL, ERR_ABORT.
|
|
|
|
|
*/
|
|
|
|
|
int protocol_unbind_all(void)
|
|
|
|
|
{
|
|
|
|
|
struct protocol *proto;
|
2020-09-02 04:31:31 -04:00
|
|
|
struct listener *listener;
|
2012-09-12 16:58:11 -04:00
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
err = 0;
|
2019-07-24 10:45:02 -04:00
|
|
|
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
|
2012-09-12 16:58:11 -04:00
|
|
|
list_for_each_entry(proto, &protocols, list) {
|
2020-09-25 11:01:43 -04:00
|
|
|
list_for_each_entry(listener, &proto->receivers, rx.proto_list)
|
2020-09-02 04:31:31 -04:00
|
|
|
unbind_listener(listener);
|
2012-09-12 16:58:11 -04:00
|
|
|
}
|
2019-07-24 10:45:02 -04:00
|
|
|
HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
|
2012-09-12 16:58:11 -04:00
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-11 10:27:10 -04:00
|
|
|
/* stops all listeners of all registered protocols. This will normally catch
|
|
|
|
|
* every single listener, all protocols included. This is to be used during
|
|
|
|
|
* soft_stop() only. It does not return any error.
|
2020-10-07 10:50:49 -04:00
|
|
|
*/
|
|
|
|
|
void protocol_stop_now(void)
|
|
|
|
|
{
|
|
|
|
|
struct protocol *proto;
|
|
|
|
|
struct listener *listener, *lback;
|
|
|
|
|
|
|
|
|
|
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
|
|
|
|
|
list_for_each_entry(proto, &protocols, list) {
|
|
|
|
|
list_for_each_entry_safe(listener, lback, &proto->receivers, rx.proto_list)
|
MINOR: listener/api: add lli hint to listener functions
Add listener lock hint (AKA lli) to (stop/resume/pause)_listener() functions.
All these functions implicitely take the listener lock when they are called:
It could be useful to be able to call them while already holding the lock, so
we're adding lli hint to make them take the lock only when it is missing.
This should only be backported if explicitly required by another commit
--
-> 2.4 and 2.5 common backport notes:
These 2 commits need to be backported first:
- 187396e34 "CLEANUP: listener: function comment typo in stop_listener()"
- a57786e87 "BUG/MINOR: listener: null pointer dereference suspected by
coverity"
-> 2.4 special backport notes:
In addition to the previously mentionned dependencies, the patch needs to be
slightly adapted to match the corresponding contextual lines:
Replace this:
|@@ -471,7 +474,8 @@ int pause_listener(struct listener *l, int lpx)
| if (!lpx && px)
| HA_RWLOCK_WRLOCK(PROXY_LOCK, &px->lock);
|
|- HA_RWLOCK_WRLOCK(LISTENER_LOCK, &l->lock);
|+ if (!lli)
|+ HA_RWLOCK_WRLOCK(LISTENER_LOCK, &l->lock);
|
| if (l->state <= LI_PAUSED)
| goto end;
By this:
|@@ -471,7 +474,8 @@ int pause_listener(struct listener *l, int lpx)
| if (!lpx && px)
| HA_RWLOCK_WRLOCK(PROXY_LOCK, &px->lock);
|
|- HA_RWLOCK_WRLOCK(LISTENER_LOCK, &l->lock);
|+ if (!lli)
|+ HA_RWLOCK_WRLOCK(LISTENER_LOCK, &l->lock);
|
| if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
| !(proc_mask(l->rx.settings->bind_proc) & pid_bit))
Replace this:
|@@ -169,7 +169,7 @@ void protocol_stop_now(void)
| HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
| list_for_each_entry(proto, &protocols, list) {
| list_for_each_entry_safe(listener, lback, &proto->receivers, rx.proto_list)
|- stop_listener(listener, 0, 1);
|+ stop_listener(listener, 0, 1, 0);
| }
| HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
| }
By this:
|@@ -169,7 +169,7 @@ void protocol_stop_now(void)
| HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
| list_for_each_entry(proto, &protocols, list) {
| list_for_each_entry_safe(listener, lback, &proto->receivers, rx.proto_list)
| if (!listener->bind_conf->frontend->grace)
|- stop_listener(listener, 0, 1);
|+ stop_listener(listener, 0, 1, 0);
| }
| HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
Replace this:
|@@ -2315,7 +2315,7 @@ void stop_proxy(struct proxy *p)
| HA_RWLOCK_WRLOCK(PROXY_LOCK, &p->lock);
|
| list_for_each_entry(l, &p->conf.listeners, by_fe)
|- stop_listener(l, 1, 0);
|+ stop_listener(l, 1, 0, 0);
|
| if (!(p->flags & (PR_FL_DISABLED|PR_FL_STOPPED)) && !p->li_ready) {
| /* might be just a backend */
By this:
|@@ -2315,7 +2315,7 @@ void stop_proxy(struct proxy *p)
| HA_RWLOCK_WRLOCK(PROXY_LOCK, &p->lock);
|
| list_for_each_entry(l, &p->conf.listeners, by_fe)
|- stop_listener(l, 1, 0);
|+ stop_listener(l, 1, 0, 0);
|
| if (!p->disabled && !p->li_ready) {
| /* might be just a backend */
2023-02-06 11:06:03 -05:00
|
|
|
stop_listener(listener, 0, 1, 0);
|
2020-10-07 10:50:49 -04:00
|
|
|
}
|
|
|
|
|
HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
|
|
|
|
|
}
|
|
|
|
|
|
MINOR: listener: pause_listener() becomes suspend_listener()
We are simply renaming pause_listener() to suspend_listener() to prevent
confusion around listener pausing.
A suspended listener can be in two differents valid states:
- LI_PAUSED: the listener is effectively paused, it will unpause on
resume_listener()
- LI_ASSIGNED (not bound): the listener does not support the LI_PAUSED
state, so it was unbound to satisfy the suspend request, it will
correcly re-bind on resume_listener()
Besides that, we add the LI_F_SUSPENDED flag to mark suspended listeners in
suspend_listener() and unmark them in resume_listener().
We're also adding li_suspend proxy variable to track the number of currently
suspended listeners:
That is, the number of listeners that were suspended through suspend_listener()
and that are either in LI_PAUSED or LI_ASSIGNED state.
Counter is increased on successful suspend in suspend_listener() and it is
decreased on successful resume in resume_listener()
--
Backport notes:
-> 2.4 only, as "MINOR: proxy/listener: support for additional PAUSED state"
was not backported:
Replace this:
| /* PROXY_LOCK is require
| proxy_cond_resume(px);
By this:
| ha_warning("Resumed %s %s.\n", proxy_cap_str(px->cap), px->id);
| send_log(px, LOG_WARNING, "Resumed %s %s.\n", proxy_cap_str(px->cap), px->id);
-> 2.6 and 2.7 only, as "MINOR: listener: make sure we don't pause/resume" was
custom patched:
Replace this:
|@@ -253,6 +253,7 @@ struct listener {
|
| /* listener flags (16 bits) */
| #define LI_F_FINALIZED 0x0001 /* listener made it to the READY||LIMITED||FULL state at least once, may be suspended/resumed safely */
|+#define LI_F_SUSPENDED 0x0002 /* listener has been suspended using suspend_listener(), it is either is LI_PAUSED or LI_ASSIGNED state */
|
| /* Descriptor for a "bind" keyword. The ->parse() function returns 0 in case of
| * success, or a combination of ERR_* flags if an error is encountered. The
By this:
|@@ -222,6 +222,7 @@ struct li_per_thread {
|
| #define LI_F_QUIC_LISTENER 0x00000001 /* listener uses proto quic */
| #define LI_F_FINALIZED 0x00000002 /* listener made it to the READY||LIMITED||FULL state at least once, may be suspended/resumed safely */
|+#define LI_F_SUSPENDED 0x00000004 /* listener has been suspended using suspend_listener(), it is either is LI_PAUSED or LI_ASSIGNED state */
|
| /* The listener will be directly referenced by the fdtab[] which holds its
| * socket. The listener provides the protocol-specific accept() function to
2023-02-13 11:45:08 -05:00
|
|
|
/* suspends all listeners of all registered protocols. This is typically
|
2020-09-24 10:26:50 -04:00
|
|
|
* used on SIG_TTOU to release all listening sockets for the time needed to
|
MINOR: listener: pause_listener() becomes suspend_listener()
We are simply renaming pause_listener() to suspend_listener() to prevent
confusion around listener pausing.
A suspended listener can be in two differents valid states:
- LI_PAUSED: the listener is effectively paused, it will unpause on
resume_listener()
- LI_ASSIGNED (not bound): the listener does not support the LI_PAUSED
state, so it was unbound to satisfy the suspend request, it will
correcly re-bind on resume_listener()
Besides that, we add the LI_F_SUSPENDED flag to mark suspended listeners in
suspend_listener() and unmark them in resume_listener().
We're also adding li_suspend proxy variable to track the number of currently
suspended listeners:
That is, the number of listeners that were suspended through suspend_listener()
and that are either in LI_PAUSED or LI_ASSIGNED state.
Counter is increased on successful suspend in suspend_listener() and it is
decreased on successful resume in resume_listener()
--
Backport notes:
-> 2.4 only, as "MINOR: proxy/listener: support for additional PAUSED state"
was not backported:
Replace this:
| /* PROXY_LOCK is require
| proxy_cond_resume(px);
By this:
| ha_warning("Resumed %s %s.\n", proxy_cap_str(px->cap), px->id);
| send_log(px, LOG_WARNING, "Resumed %s %s.\n", proxy_cap_str(px->cap), px->id);
-> 2.6 and 2.7 only, as "MINOR: listener: make sure we don't pause/resume" was
custom patched:
Replace this:
|@@ -253,6 +253,7 @@ struct listener {
|
| /* listener flags (16 bits) */
| #define LI_F_FINALIZED 0x0001 /* listener made it to the READY||LIMITED||FULL state at least once, may be suspended/resumed safely */
|+#define LI_F_SUSPENDED 0x0002 /* listener has been suspended using suspend_listener(), it is either is LI_PAUSED or LI_ASSIGNED state */
|
| /* Descriptor for a "bind" keyword. The ->parse() function returns 0 in case of
| * success, or a combination of ERR_* flags if an error is encountered. The
By this:
|@@ -222,6 +222,7 @@ struct li_per_thread {
|
| #define LI_F_QUIC_LISTENER 0x00000001 /* listener uses proto quic */
| #define LI_F_FINALIZED 0x00000002 /* listener made it to the READY||LIMITED||FULL state at least once, may be suspended/resumed safely */
|+#define LI_F_SUSPENDED 0x00000004 /* listener has been suspended using suspend_listener(), it is either is LI_PAUSED or LI_ASSIGNED state */
|
| /* The listener will be directly referenced by the fdtab[] which holds its
| * socket. The listener provides the protocol-specific accept() function to
2023-02-13 11:45:08 -05:00
|
|
|
* try to bind a new process. The listeners enter LI_PAUSED or LI_ASSIGNED.
|
|
|
|
|
* It returns ERR_NONE, with ERR_FATAL on failure.
|
2020-09-24 10:26:50 -04:00
|
|
|
*/
|
|
|
|
|
int protocol_pause_all(void)
|
|
|
|
|
{
|
|
|
|
|
struct protocol *proto;
|
|
|
|
|
struct listener *listener;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
|
|
|
|
|
list_for_each_entry(proto, &protocols, list) {
|
2020-09-25 11:01:43 -04:00
|
|
|
list_for_each_entry(listener, &proto->receivers, rx.proto_list)
|
MINOR: listener: pause_listener() becomes suspend_listener()
We are simply renaming pause_listener() to suspend_listener() to prevent
confusion around listener pausing.
A suspended listener can be in two differents valid states:
- LI_PAUSED: the listener is effectively paused, it will unpause on
resume_listener()
- LI_ASSIGNED (not bound): the listener does not support the LI_PAUSED
state, so it was unbound to satisfy the suspend request, it will
correcly re-bind on resume_listener()
Besides that, we add the LI_F_SUSPENDED flag to mark suspended listeners in
suspend_listener() and unmark them in resume_listener().
We're also adding li_suspend proxy variable to track the number of currently
suspended listeners:
That is, the number of listeners that were suspended through suspend_listener()
and that are either in LI_PAUSED or LI_ASSIGNED state.
Counter is increased on successful suspend in suspend_listener() and it is
decreased on successful resume in resume_listener()
--
Backport notes:
-> 2.4 only, as "MINOR: proxy/listener: support for additional PAUSED state"
was not backported:
Replace this:
| /* PROXY_LOCK is require
| proxy_cond_resume(px);
By this:
| ha_warning("Resumed %s %s.\n", proxy_cap_str(px->cap), px->id);
| send_log(px, LOG_WARNING, "Resumed %s %s.\n", proxy_cap_str(px->cap), px->id);
-> 2.6 and 2.7 only, as "MINOR: listener: make sure we don't pause/resume" was
custom patched:
Replace this:
|@@ -253,6 +253,7 @@ struct listener {
|
| /* listener flags (16 bits) */
| #define LI_F_FINALIZED 0x0001 /* listener made it to the READY||LIMITED||FULL state at least once, may be suspended/resumed safely */
|+#define LI_F_SUSPENDED 0x0002 /* listener has been suspended using suspend_listener(), it is either is LI_PAUSED or LI_ASSIGNED state */
|
| /* Descriptor for a "bind" keyword. The ->parse() function returns 0 in case of
| * success, or a combination of ERR_* flags if an error is encountered. The
By this:
|@@ -222,6 +222,7 @@ struct li_per_thread {
|
| #define LI_F_QUIC_LISTENER 0x00000001 /* listener uses proto quic */
| #define LI_F_FINALIZED 0x00000002 /* listener made it to the READY||LIMITED||FULL state at least once, may be suspended/resumed safely */
|+#define LI_F_SUSPENDED 0x00000004 /* listener has been suspended using suspend_listener(), it is either is LI_PAUSED or LI_ASSIGNED state */
|
| /* The listener will be directly referenced by the fdtab[] which holds its
| * socket. The listener provides the protocol-specific accept() function to
2023-02-13 11:45:08 -05:00
|
|
|
if (!suspend_listener(listener, 0, 0))
|
2020-09-24 10:26:50 -04:00
|
|
|
err |= ERR_FATAL;
|
|
|
|
|
}
|
|
|
|
|
HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* resumes all listeners of all registered protocols. This is typically used on
|
|
|
|
|
* SIG_TTIN to re-enable listening sockets after a new process failed to bind.
|
|
|
|
|
* The listeners switch to LI_READY/LI_FULL. It returns ERR_NONE, with ERR_FATAL
|
|
|
|
|
* on failure.
|
|
|
|
|
*/
|
|
|
|
|
int protocol_resume_all(void)
|
|
|
|
|
{
|
|
|
|
|
struct protocol *proto;
|
|
|
|
|
struct listener *listener;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
|
|
|
|
|
list_for_each_entry(proto, &protocols, list) {
|
2020-09-25 11:01:43 -04:00
|
|
|
list_for_each_entry(listener, &proto->receivers, rx.proto_list)
|
MINOR: listener/api: add lli hint to listener functions
Add listener lock hint (AKA lli) to (stop/resume/pause)_listener() functions.
All these functions implicitely take the listener lock when they are called:
It could be useful to be able to call them while already holding the lock, so
we're adding lli hint to make them take the lock only when it is missing.
This should only be backported if explicitly required by another commit
--
-> 2.4 and 2.5 common backport notes:
These 2 commits need to be backported first:
- 187396e34 "CLEANUP: listener: function comment typo in stop_listener()"
- a57786e87 "BUG/MINOR: listener: null pointer dereference suspected by
coverity"
-> 2.4 special backport notes:
In addition to the previously mentionned dependencies, the patch needs to be
slightly adapted to match the corresponding contextual lines:
Replace this:
|@@ -471,7 +474,8 @@ int pause_listener(struct listener *l, int lpx)
| if (!lpx && px)
| HA_RWLOCK_WRLOCK(PROXY_LOCK, &px->lock);
|
|- HA_RWLOCK_WRLOCK(LISTENER_LOCK, &l->lock);
|+ if (!lli)
|+ HA_RWLOCK_WRLOCK(LISTENER_LOCK, &l->lock);
|
| if (l->state <= LI_PAUSED)
| goto end;
By this:
|@@ -471,7 +474,8 @@ int pause_listener(struct listener *l, int lpx)
| if (!lpx && px)
| HA_RWLOCK_WRLOCK(PROXY_LOCK, &px->lock);
|
|- HA_RWLOCK_WRLOCK(LISTENER_LOCK, &l->lock);
|+ if (!lli)
|+ HA_RWLOCK_WRLOCK(LISTENER_LOCK, &l->lock);
|
| if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
| !(proc_mask(l->rx.settings->bind_proc) & pid_bit))
Replace this:
|@@ -169,7 +169,7 @@ void protocol_stop_now(void)
| HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
| list_for_each_entry(proto, &protocols, list) {
| list_for_each_entry_safe(listener, lback, &proto->receivers, rx.proto_list)
|- stop_listener(listener, 0, 1);
|+ stop_listener(listener, 0, 1, 0);
| }
| HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
| }
By this:
|@@ -169,7 +169,7 @@ void protocol_stop_now(void)
| HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
| list_for_each_entry(proto, &protocols, list) {
| list_for_each_entry_safe(listener, lback, &proto->receivers, rx.proto_list)
| if (!listener->bind_conf->frontend->grace)
|- stop_listener(listener, 0, 1);
|+ stop_listener(listener, 0, 1, 0);
| }
| HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
Replace this:
|@@ -2315,7 +2315,7 @@ void stop_proxy(struct proxy *p)
| HA_RWLOCK_WRLOCK(PROXY_LOCK, &p->lock);
|
| list_for_each_entry(l, &p->conf.listeners, by_fe)
|- stop_listener(l, 1, 0);
|+ stop_listener(l, 1, 0, 0);
|
| if (!(p->flags & (PR_FL_DISABLED|PR_FL_STOPPED)) && !p->li_ready) {
| /* might be just a backend */
By this:
|@@ -2315,7 +2315,7 @@ void stop_proxy(struct proxy *p)
| HA_RWLOCK_WRLOCK(PROXY_LOCK, &p->lock);
|
| list_for_each_entry(l, &p->conf.listeners, by_fe)
|- stop_listener(l, 1, 0);
|+ stop_listener(l, 1, 0, 0);
|
| if (!p->disabled && !p->li_ready) {
| /* might be just a backend */
2023-02-06 11:06:03 -05:00
|
|
|
if (!resume_listener(listener, 0, 0))
|
2020-09-24 10:26:50 -04:00
|
|
|
err |= ERR_FATAL;
|
|
|
|
|
}
|
|
|
|
|
HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-12 16:58:11 -04:00
|
|
|
/* enables all listeners of all registered protocols. This is intended to be
|
2020-09-25 10:41:05 -04:00
|
|
|
* used after a fork() to enable reading on all file descriptors. Returns
|
|
|
|
|
* composition of ERR_NONE.
|
2012-09-12 16:58:11 -04:00
|
|
|
*/
|
|
|
|
|
int protocol_enable_all(void)
|
|
|
|
|
{
|
|
|
|
|
struct protocol *proto;
|
2020-09-25 10:41:05 -04:00
|
|
|
struct listener *listener;
|
2012-09-12 16:58:11 -04:00
|
|
|
|
2019-07-24 10:45:02 -04:00
|
|
|
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
|
2012-09-12 16:58:11 -04:00
|
|
|
list_for_each_entry(proto, &protocols, list) {
|
2020-09-25 11:01:43 -04:00
|
|
|
list_for_each_entry(listener, &proto->receivers, rx.proto_list)
|
2020-09-25 10:41:05 -04:00
|
|
|
enable_listener(listener);
|
2012-09-12 16:58:11 -04:00
|
|
|
}
|
2019-07-24 10:45:02 -04:00
|
|
|
HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
|
2020-09-25 10:41:05 -04:00
|
|
|
return ERR_NONE;
|
2012-09-12 16:58:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Local variables:
|
|
|
|
|
* c-indent-level: 8
|
|
|
|
|
* c-basic-offset: 8
|
|
|
|
|
* End:
|
|
|
|
|
*/
|