blob: f38baeb976c37ed5295c90abddff0898d4a91443 [file] [log] [blame]
Willy Tarreaud1d54542012-09-12 22:58:11 +02001/*
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 */
33struct listener;
34struct connection;
35
William Lallemand2d3f8a42018-09-11 16:51:28 +020036/*
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 Tarreaud1d54542012-09-12 22:58:11 +020053/* 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 */
62struct 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 Tarreau7a798e52016-04-14 11:13:20 +020070 void (*accept)(int fd); /* generic accept function */
Willy Tarreaud1d54542012-09-12 22:58:11 +020071 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 Houchardfdcb0072019-05-06 18:32:29 +020076 int (*connect)(struct connection *, int flags); /* connect function if any, see below for flags values */
Willy Tarreaud1d54542012-09-12 22:58:11 +020077 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 Tarreau2b57cb82013-06-10 19:56:38 +020079 int (*drain)(int fd); /* indicates whether we can safely close the fd */
Willy Tarreau092d8652014-07-07 20:22:12 +020080 int (*pause)(struct listener *l); /* temporarily pause this listener for a soft restart */
Willy Tarreau9d5be5c2017-09-15 07:55:51 +020081 void (*add)(struct listener *l, int port); /* add a listener for this protocol and port */
Willy Tarreaud1d54542012-09-12 22:58:11 +020082
Willy Tarreaudaacf362019-07-24 16:45:02 +020083 struct list listeners; /* list of listeners using this protocol (under proto_lock) */
84 int nb_listeners; /* number of listeners (under proto_lock) */
85 struct list list; /* list of registered protocols (under proto_lock) */
Willy Tarreaud1d54542012-09-12 22:58:11 +020086};
87
Olivier Houchardfdcb0072019-05-06 18:32:29 +020088#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 Tarreau034c88c2017-01-23 23:36:45 +010091#define CONNECT_CAN_USE_TFO 0x00000008 /* We can use TFO for this connection */
Willy Tarreaud1d54542012-09-12 22:58:11 +020092#endif /* _TYPES_PROTOCOL_H */
93
94/*
95 * Local variables:
96 * c-indent-level: 8
97 * c-basic-offset: 8
98 * End:
99 */