Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 1 | /* |
| 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 Tarreau | b550d00 | 2015-02-20 16:53:25 +0100 | [diff] [blame] | 25 | #include <sys/socket.h> |
Willy Tarreau | daacf36 | 2019-07-24 16:45:02 +0200 | [diff] [blame] | 26 | #include <common/hathreads.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 27 | #include <types/protocol.h> |
| 28 | |
William Lallemand | 2d3f8a4 | 2018-09-11 16:51:28 +0200 | [diff] [blame] | 29 | extern struct protocol *__protocol_by_family[AF_CUST_MAX]; |
Willy Tarreau | daacf36 | 2019-07-24 16:45:02 +0200 | [diff] [blame] | 30 | __decl_hathreads(extern HA_SPINLOCK_T proto_lock); |
Willy Tarreau | b550d00 | 2015-02-20 16:53:25 +0100 | [diff] [blame] | 31 | |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 32 | /* Registers the protocol <proto> */ |
| 33 | void protocol_register(struct protocol *proto); |
| 34 | |
| 35 | /* Unregisters the protocol <proto>. Note that all listeners must have |
| 36 | * previously been unbound. |
| 37 | */ |
| 38 | void protocol_unregister(struct protocol *proto); |
| 39 | |
Joseph Herlant | eeac3c7 | 2018-11-25 13:26:40 -0800 | [diff] [blame] | 40 | /* binds all listeners of all registered protocols. Returns a composition |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 41 | * of ERR_NONE, ERR_RETRYABLE, ERR_FATAL. |
| 42 | */ |
| 43 | int 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 | */ |
| 50 | int 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 | */ |
| 56 | int protocol_enable_all(void); |
| 57 | |
| 58 | /* returns the protocol associated to family <family> or NULL if not found */ |
Willy Tarreau | b550d00 | 2015-02-20 16:53:25 +0100 | [diff] [blame] | 59 | static inline struct protocol *protocol_by_family(int family) |
| 60 | { |
William Lallemand | 2d3f8a4 | 2018-09-11 16:51:28 +0200 | [diff] [blame] | 61 | if (family >= 0 && family < AF_CUST_MAX) |
Willy Tarreau | b550d00 | 2015-02-20 16:53:25 +0100 | [diff] [blame] | 62 | return __protocol_by_family[family]; |
| 63 | return NULL; |
| 64 | } |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 65 | |
| 66 | #endif /* _PROTO_PROTOCOL_H */ |
| 67 | |
| 68 | /* |
| 69 | * Local variables: |
| 70 | * c-indent-level: 8 |
| 71 | * c-basic-offset: 8 |
| 72 | * End: |
| 73 | */ |