blob: 9480c186907fe1114b8df736209f5dbd537f8f1e [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
36/* max length of a protcol name, including trailing zero */
37#define PROTO_NAME_LEN 16
38
39/* This structure contains all information needed to easily handle a protocol.
40 * Its primary goal is to ease listeners maintenance. Specifically, the
41 * bind_all() primitive must be used before any fork(), and the enable_all()
42 * primitive must be called after the fork() to enable all fds. Last, the
43 * unbind_all() primitive closes all listeners.
44 */
45struct protocol {
46 char name[PROTO_NAME_LEN]; /* protocol name, zero-terminated */
47 int sock_domain; /* socket domain, as passed to socket() */
48 int sock_type; /* socket type, as passed to socket() */
49 int sock_prot; /* socket protocol, as passed to socket() */
50 sa_family_t sock_family; /* socket family, for sockaddr */
51 socklen_t sock_addrlen; /* socket address length, used by bind() */
52 int l3_addrlen; /* layer3 address length, used by hashes */
Willy Tarreau7a798e52016-04-14 11:13:20 +020053 void (*accept)(int fd); /* generic accept function */
Willy Tarreaud1d54542012-09-12 22:58:11 +020054 int (*bind)(struct listener *l, char *errmsg, int errlen); /* bind a listener */
55 int (*bind_all)(struct protocol *proto, char *errmsg, int errlen); /* bind all unbound listeners */
56 int (*unbind_all)(struct protocol *proto); /* unbind all bound listeners */
57 int (*enable_all)(struct protocol *proto); /* enable all bound listeners */
58 int (*disable_all)(struct protocol *proto); /* disable all bound listeners */
Willy Tarreauf0837b22012-11-24 10:24:27 +010059 int (*connect)(struct connection *, int data, int delack); /* connect function if any */
Willy Tarreaud1d54542012-09-12 22:58:11 +020060 int (*get_src)(int fd, struct sockaddr *, socklen_t, int dir); /* syscall used to retrieve src addr */
61 int (*get_dst)(int fd, struct sockaddr *, socklen_t, int dir); /* syscall used to retrieve dst addr */
Willy Tarreau2b57cb82013-06-10 19:56:38 +020062 int (*drain)(int fd); /* indicates whether we can safely close the fd */
Willy Tarreau092d8652014-07-07 20:22:12 +020063 int (*pause)(struct listener *l); /* temporarily pause this listener for a soft restart */
Willy Tarreau9d5be5c2017-09-15 07:55:51 +020064 void (*add)(struct listener *l, int port); /* add a listener for this protocol and port */
Willy Tarreaud1d54542012-09-12 22:58:11 +020065
66 struct list listeners; /* list of listeners using this protocol */
67 int nb_listeners; /* number of listeners */
68 struct list list; /* list of registered protocols */
69};
70
71#endif /* _TYPES_PROTOCOL_H */
72
73/*
74 * Local variables:
75 * c-indent-level: 8
76 * c-basic-offset: 8
77 * End:
78 */