blob: 7bbebb8e8c243fc0ee8483efd8076f44948cdc00 [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 Tarreaud1d54542012-09-12 22:58:11 +020026#include <types/protocol.h>
27
William Lallemand2d3f8a42018-09-11 16:51:28 +020028extern struct protocol *__protocol_by_family[AF_CUST_MAX];
Willy Tarreaub550d002015-02-20 16:53:25 +010029
Willy Tarreaud1d54542012-09-12 22:58:11 +020030/* Registers the protocol <proto> */
31void protocol_register(struct protocol *proto);
32
33/* Unregisters the protocol <proto>. Note that all listeners must have
34 * previously been unbound.
35 */
36void protocol_unregister(struct protocol *proto);
37
Joseph Herlanteeac3c72018-11-25 13:26:40 -080038/* binds all listeners of all registered protocols. Returns a composition
Willy Tarreaud1d54542012-09-12 22:58:11 +020039 * of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
40 */
41int protocol_bind_all(char *errmsg, int errlen);
42
43/* unbinds all listeners of all registered protocols. They are also closed.
44 * This must be performed before calling exit() in order to get a chance to
45 * remove file-system based sockets and pipes.
46 * Returns a composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
47 */
48int protocol_unbind_all(void);
49
50/* enables all listeners of all registered protocols. This is intended to be
51 * used after a fork() to enable reading on all file descriptors. Returns a
52 * composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
53 */
54int protocol_enable_all(void);
55
56/* returns the protocol associated to family <family> or NULL if not found */
Willy Tarreaub550d002015-02-20 16:53:25 +010057static inline struct protocol *protocol_by_family(int family)
58{
William Lallemand2d3f8a42018-09-11 16:51:28 +020059 if (family >= 0 && family < AF_CUST_MAX)
Willy Tarreaub550d002015-02-20 16:53:25 +010060 return __protocol_by_family[family];
61 return NULL;
62}
Willy Tarreaud1d54542012-09-12 22:58:11 +020063
64#endif /* _PROTO_PROTOCOL_H */
65
66/*
67 * Local variables:
68 * c-indent-level: 8
69 * c-basic-offset: 8
70 * End:
71 */