blob: f25f77f0a06455c8582aa3f6a50eb1c1643cd8fd [file] [log] [blame]
Willy Tarreaud1d54542012-09-12 22:58:11 +02001/*
2 * include/proto/protocol.h
3 * This file declares generic protocol management primitives.
4 *
5 * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, version 2.1
10 * exclusively.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#ifndef _PROTO_PROTOCOL_H
23#define _PROTO_PROTOCOL_H
24
Willy Tarreaub550d002015-02-20 16:53:25 +010025#include <sys/socket.h>
Willy Tarreaudaacf362019-07-24 16:45:02 +020026#include <common/hathreads.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020027#include <types/protocol.h>
28
William Lallemand2d3f8a42018-09-11 16:51:28 +020029extern struct protocol *__protocol_by_family[AF_CUST_MAX];
Willy Tarreaudaacf362019-07-24 16:45:02 +020030__decl_hathreads(extern HA_SPINLOCK_T proto_lock);
Willy Tarreaub550d002015-02-20 16:53:25 +010031
Willy Tarreaud1d54542012-09-12 22:58:11 +020032/* Registers the protocol <proto> */
33void protocol_register(struct protocol *proto);
34
35/* Unregisters the protocol <proto>. Note that all listeners must have
36 * previously been unbound.
37 */
38void protocol_unregister(struct protocol *proto);
39
Joseph Herlanteeac3c72018-11-25 13:26:40 -080040/* binds all listeners of all registered protocols. Returns a composition
Willy Tarreaud1d54542012-09-12 22:58:11 +020041 * of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
42 */
43int protocol_bind_all(char *errmsg, int errlen);
44
45/* unbinds all listeners of all registered protocols. They are also closed.
46 * This must be performed before calling exit() in order to get a chance to
47 * remove file-system based sockets and pipes.
48 * Returns a composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
49 */
50int protocol_unbind_all(void);
51
52/* enables all listeners of all registered protocols. This is intended to be
53 * used after a fork() to enable reading on all file descriptors. Returns a
54 * composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
55 */
56int protocol_enable_all(void);
57
58/* returns the protocol associated to family <family> or NULL if not found */
Willy Tarreaub550d002015-02-20 16:53:25 +010059static inline struct protocol *protocol_by_family(int family)
60{
William Lallemand2d3f8a42018-09-11 16:51:28 +020061 if (family >= 0 && family < AF_CUST_MAX)
Willy Tarreaub550d002015-02-20 16:53:25 +010062 return __protocol_by_family[family];
63 return NULL;
64}
Willy Tarreaud1d54542012-09-12 22:58:11 +020065
66#endif /* _PROTO_PROTOCOL_H */
67
68/*
69 * Local variables:
70 * c-indent-level: 8
71 * c-basic-offset: 8
72 * End:
73 */