Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/types/protocol.h |
| 3 | * This file defines the structures used by generic network protocols. |
| 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 _TYPES_PROTOCOL_H |
| 23 | #define _TYPES_PROTOCOL_H |
| 24 | |
| 25 | #include <sys/types.h> |
| 26 | #include <sys/socket.h> |
| 27 | |
| 28 | #include <common/config.h> |
| 29 | #include <common/mini-clist.h> |
| 30 | #include <eb32tree.h> |
| 31 | |
| 32 | /* some pointer types referenced below */ |
| 33 | struct listener; |
| 34 | struct connection; |
| 35 | |
William Lallemand | 2d3f8a4 | 2018-09-11 16:51:28 +0200 | [diff] [blame] | 36 | /* |
| 37 | * Custom network family for str2sa parsing. Should be ok to do this since |
| 38 | * sa_family_t is standardized as an unsigned integer |
| 39 | */ |
| 40 | |
| 41 | #define AF_CUST_SOCKPAIR (AF_MAX + 1) |
| 42 | #define AF_CUST_MAX (AF_MAX + 2) |
| 43 | |
| 44 | /* |
| 45 | * Test in case AF_CUST_MAX overflows the sa_family_t (unsigned int) |
| 46 | */ |
| 47 | #if (AF_CUST_MAX < AF_MAX) |
| 48 | # error "Can't build on the target system, AF_CUST_MAX overflow" |
| 49 | #endif |
| 50 | |
| 51 | |
| 52 | |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 53 | /* max length of a protcol name, including trailing zero */ |
| 54 | #define PROTO_NAME_LEN 16 |
| 55 | |
| 56 | /* This structure contains all information needed to easily handle a protocol. |
| 57 | * Its primary goal is to ease listeners maintenance. Specifically, the |
| 58 | * bind_all() primitive must be used before any fork(), and the enable_all() |
| 59 | * primitive must be called after the fork() to enable all fds. Last, the |
| 60 | * unbind_all() primitive closes all listeners. |
| 61 | */ |
| 62 | struct protocol { |
| 63 | char name[PROTO_NAME_LEN]; /* protocol name, zero-terminated */ |
| 64 | int sock_domain; /* socket domain, as passed to socket() */ |
| 65 | int sock_type; /* socket type, as passed to socket() */ |
| 66 | int sock_prot; /* socket protocol, as passed to socket() */ |
| 67 | sa_family_t sock_family; /* socket family, for sockaddr */ |
| 68 | socklen_t sock_addrlen; /* socket address length, used by bind() */ |
| 69 | int l3_addrlen; /* layer3 address length, used by hashes */ |
Willy Tarreau | 7a798e5 | 2016-04-14 11:13:20 +0200 | [diff] [blame] | 70 | void (*accept)(int fd); /* generic accept function */ |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 71 | int (*bind)(struct listener *l, char *errmsg, int errlen); /* bind a listener */ |
| 72 | int (*bind_all)(struct protocol *proto, char *errmsg, int errlen); /* bind all unbound listeners */ |
| 73 | int (*unbind_all)(struct protocol *proto); /* unbind all bound listeners */ |
| 74 | int (*enable_all)(struct protocol *proto); /* enable all bound listeners */ |
| 75 | int (*disable_all)(struct protocol *proto); /* disable all bound listeners */ |
Olivier Houchard | fdcb007 | 2019-05-06 18:32:29 +0200 | [diff] [blame] | 76 | int (*connect)(struct connection *, int flags); /* connect function if any, see below for flags values */ |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 77 | int (*get_src)(int fd, struct sockaddr *, socklen_t, int dir); /* syscall used to retrieve src addr */ |
| 78 | int (*get_dst)(int fd, struct sockaddr *, socklen_t, int dir); /* syscall used to retrieve dst addr */ |
Willy Tarreau | 2b57cb8 | 2013-06-10 19:56:38 +0200 | [diff] [blame] | 79 | int (*drain)(int fd); /* indicates whether we can safely close the fd */ |
Willy Tarreau | 092d865 | 2014-07-07 20:22:12 +0200 | [diff] [blame] | 80 | int (*pause)(struct listener *l); /* temporarily pause this listener for a soft restart */ |
Willy Tarreau | 9d5be5c | 2017-09-15 07:55:51 +0200 | [diff] [blame] | 81 | void (*add)(struct listener *l, int port); /* add a listener for this protocol and port */ |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 82 | |
| 83 | struct list listeners; /* list of listeners using this protocol */ |
| 84 | int nb_listeners; /* number of listeners */ |
| 85 | struct list list; /* list of registered protocols */ |
| 86 | }; |
| 87 | |
Olivier Houchard | fdcb007 | 2019-05-06 18:32:29 +0200 | [diff] [blame] | 88 | #define CONNECT_HAS_DATA 0x00000001 /* There's data available to be sent */ |
| 89 | #define CONNECT_DELACK_SMART_CONNECT 0x00000002 /* Use a delayed ACK if the backend has tcp-smart-connect */ |
| 90 | #define CONNECT_DELACK_ALWAYS 0x00000004 /* Use a delayed ACK */ |
Willy Tarreau | 034c88c | 2017-01-23 23:36:45 +0100 | [diff] [blame] | 91 | #define CONNECT_CAN_USE_TFO 0x00000008 /* We can use TFO for this connection */ |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 92 | #endif /* _TYPES_PROTOCOL_H */ |
| 93 | |
| 94 | /* |
| 95 | * Local variables: |
| 96 | * c-indent-level: 8 |
| 97 | * c-basic-offset: 8 |
| 98 | * End: |
| 99 | */ |