2
include/types/protocols.h
3
This file defines the structures used by generic network protocols.
5
Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
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
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.
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
22
#ifndef _TYPES_PROTOCOLS_H
23
#define _TYPES_PROTOCOLS_H
25
#include <sys/types.h>
26
#include <sys/socket.h>
30
#include <common/config.h>
31
#include <common/mini-clist.h>
33
/* max length of a protcol name, including trailing zero */
34
#define PROTO_NAME_LEN 16
37
#define LI_NEW 0 /* not initialized yet */
38
#define LI_INIT 1 /* all parameters filled in, but not assigned yet */
39
#define LI_ASSIGNED 2 /* assigned to the protocol, but not listening yet */
40
#define LI_LISTEN 3 /* started, listening but not enabled */
41
#define LI_READY 4 /* started, listening and enabled */
42
#define LI_FULL 5 /* reached its connection limit */
44
/* Listener transitions
45
* calloc() set() add_listener() bind()
46
* -------> NEW ----> INIT ----------> ASSIGNED -----> LISTEN
47
* <------- <---- <---------- <-----
48
* free() bzero() del_listener() unbind()
50
* The file descriptor is valid only during these three states :
53
* LISTEN <------------ READY
55
* || !max & enable() ||
58
* || max & enable() V| !max
59
* |+---------------> FULL
65
/* listener socket options */
66
#define LI_O_NONE 0x0000
67
#define LI_O_NOLINGER 0x0001 /* disable linger on this socket */
69
/* The listener will be directly referenced by the fdtab[] which holds its
70
* socket. The listener provides the protocol-specific accept() function to
74
int fd; /* the listen socket */
75
int state; /* state: NEW, INIT, ASSIGNED, LISTEN, READY, FULL */
76
int options; /* socket options : LI_O_* */
77
struct sockaddr_storage addr; /* the address we listen to */
78
struct protocol *proto; /* protocol this listener belongs to */
79
int nbconn; /* current number of connections on this listener */
80
int maxconn; /* maximum connections allowed on this listener */
81
unsigned int backlog; /* if set, listen backlog */
82
struct listener *next; /* next address for the same proxy, or NULL */
83
struct list proto_list; /* list in the protocol header */
84
int (*accept)(int fd); /* accept() function passed to fdtab[] */
85
void (*handler)(struct task *t, struct timeval *next); /* protocol handler */
86
struct timeval *timeout; /* pointer to client-side timeout */
87
void *private; /* any private data which may be used by accept() */
88
union { /* protocol-dependant access restrictions */
89
struct { /* UNIX socket permissions */
90
uid_t uid; /* -1 to leave unchanged */
91
gid_t gid; /* -1 to leave unchanged */
92
mode_t mode; /* 0 to leave unchanged */
97
/* This structure contains all information needed to easily handle a protocol.
98
* Its primary goal is to ease listeners maintenance. Specifically, the
99
* bind_all() primitive must be used before any fork(), and the enable_all()
100
* primitive must be called after the fork() to enable all fds. Last, the
101
* unbind_all() primitive closes all listeners.
104
char name[PROTO_NAME_LEN]; /* protocol name, zero-terminated */
105
int sock_domain; /* socket domain, as passed to socket() */
106
int sock_type; /* socket type, as passed to socket() */
107
int sock_prot; /* socket protocol, as passed to socket() */
108
sa_family_t sock_family; /* socket family, for sockaddr */
109
socklen_t sock_addrlen; /* socket address length, used by bind() */
110
int l3_addrlen; /* layer3 address length, used by hashes */
111
int (*read)(int fd); /* generic read function */
112
int (*write)(int fd); /* generic write function */
113
int (*bind_all)(struct protocol *proto); /* bind all unbound listeners */
114
int (*unbind_all)(struct protocol *proto); /* unbind all bound listeners */
115
int (*enable_all)(struct protocol *proto); /* enable all bound listeners */
116
int (*disable_all)(struct protocol *proto); /* disable all bound listeners */
117
struct list listeners; /* list of listeners using this protocol */
118
int nb_listeners; /* number of listeners */
119
struct list list; /* list of registered protocols */
122
#endif /* _TYPES_PROTOCOLS_H */