haproxy/include/haproxy/protocol.h
Willy Tarreau e91bff2134 MAJOR: init: start all listeners via protocols and not via proxies anymore
Ever since the protocols were added in 1.3.13, listeners used to be
started twice:
  - once by start_proxies(), which iteratees over all proxies then all
    listeners ;
  - once by protocol_bind_all() which iterates over all protocols then
    all listeners ;

It's a real mess because error reporting is not even consistent, and
more importantly now that some protocols do not appear in regular
proxies (peers, logs), there is no way to retry their binding should
it fail on the last step.

What this patch does is to make sure that listeners are exclusively
started by protocols. The failure to start a listener now causes the
emission of an error indicating the proxy's name (as it used to be
the case per proxy), and retryable failures are silently ignored
during all but last attempts.

The start_proxies() function was kept solely for setting the proxy's
state to READY and emitting the "Proxy started" message and log that
some have likely got used to seeking in their logs.
2020-09-02 11:11:43 +02:00

73 lines
2.3 KiB
C

/*
* include/haproxy/protocol.h
* This file declares generic protocol management primitives.
*
* Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, version 2.1
* exclusively.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _HAPROXY_PROTOCOL_H
#define _HAPROXY_PROTOCOL_H
#include <sys/socket.h>
#include <haproxy/protocol-t.h>
#include <haproxy/thread.h>
extern struct protocol *__protocol_by_family[AF_CUST_MAX];
__decl_thread(extern HA_SPINLOCK_T proto_lock);
/* Registers the protocol <proto> */
void protocol_register(struct protocol *proto);
/* Unregisters the protocol <proto>. Note that all listeners must have
* previously been unbound.
*/
void protocol_unregister(struct protocol *proto);
/* binds all listeners of all registered protocols. Returns a composition
* of ERR_NONE, ERR_RETRYABLE, ERR_FATAL, ERR_ABORT.
*/
int protocol_bind_all(int verbose);
/* 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.
*/
int protocol_unbind_all(void);
/* enables all listeners of all registered protocols. This is intended to be
* used after a fork() to enable reading on all file descriptors. Returns a
* composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
*/
int protocol_enable_all(void);
/* returns the protocol associated to family <family> or NULL if not found */
static inline struct protocol *protocol_by_family(int family)
{
if (family >= 0 && family < AF_CUST_MAX)
return __protocol_by_family[family];
return NULL;
}
#endif /* _HAPROXY_PROTOCOL_H */
/*
* Local variables:
* c-indent-level: 8
* c-basic-offset: 8
* End:
*/