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 | |
| 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 | */ |
| 45 | struct 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 */ |
| 53 | int (*accept)(int fd); /* generic accept function */ |
| 54 | 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 Tarreau | f0837b2 | 2012-11-24 10:24:27 +0100 | [diff] [blame] | 59 | int (*connect)(struct connection *, int data, int delack); /* connect function if any */ |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 60 | 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 Tarreau | 2b57cb8 | 2013-06-10 19:56:38 +0200 | [diff] [blame] | 62 | int (*drain)(int fd); /* indicates whether we can safely close the fd */ |
Willy Tarreau | d903bb3 | 2014-07-07 20:22:12 +0200 | [diff] [blame] | 63 | int (*pause)(struct listener *l); /* temporarily pause this listener for a soft restart */ |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 64 | |
| 65 | struct list listeners; /* list of listeners using this protocol */ |
| 66 | int nb_listeners; /* number of listeners */ |
| 67 | struct list list; /* list of registered protocols */ |
| 68 | }; |
| 69 | |
| 70 | #endif /* _TYPES_PROTOCOL_H */ |
| 71 | |
| 72 | /* |
| 73 | * Local variables: |
| 74 | * c-indent-level: 8 |
| 75 | * c-basic-offset: 8 |
| 76 | * End: |
| 77 | */ |