mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 13:51:26 +02:00
REORG: split "protocols" files into protocol and listener
It was becoming confusing to have protocols and listeners in the same files, split them.
This commit is contained in:
parent
21c705b0f8
commit
d1d5454180
4
Makefile
4
Makefile
@ -560,9 +560,9 @@ else
|
|||||||
all: haproxy
|
all: haproxy
|
||||||
endif
|
endif
|
||||||
|
|
||||||
OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \
|
OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocol.o \
|
||||||
src/uri_auth.o src/standard.o src/buffer.o src/log.o src/task.o \
|
src/uri_auth.o src/standard.o src/buffer.o src/log.o src/task.o \
|
||||||
src/chunk.o src/channel.o \
|
src/chunk.o src/channel.o src/listener.o \
|
||||||
src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \
|
src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \
|
||||||
src/checks.o src/queue.o src/frontend.o src/proxy.o src/peers.o \
|
src/checks.o src/queue.o src/frontend.o src/proxy.o src/peers.o \
|
||||||
src/arg.o src/stick_table.o src/proto_uxst.o src/connection.o \
|
src/arg.o src/stick_table.o src/proto_uxst.o src/connection.o \
|
||||||
|
@ -105,9 +105,9 @@ LIBS = $(LIBS.$(TARGET)) $(LIBS.$(REGEX)) $(ADDLIB)
|
|||||||
CFLAGS = -Wall $(COPTS) $(DEBUG)
|
CFLAGS = -Wall $(COPTS) $(DEBUG)
|
||||||
LDFLAGS = -g
|
LDFLAGS = -g
|
||||||
|
|
||||||
OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \
|
OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocol.o \
|
||||||
src/uri_auth.o src/standard.o src/buffer.o src/log.o src/task.o \
|
src/uri_auth.o src/standard.o src/buffer.o src/log.o src/task.o \
|
||||||
src/chunk.o src/channel.o \
|
src/chunk.o src/channel.o src/listener.o \
|
||||||
src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \
|
src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \
|
||||||
src/checks.o src/queue.o src/frontend.o src/proxy.o src/proto_uxst.o \
|
src/checks.o src/queue.o src/frontend.o src/proxy.o src/proto_uxst.o \
|
||||||
src/proto_http.o src/raw_sock.o src/appsession.o src/backend.o \
|
src/proto_http.o src/raw_sock.o src/appsession.o src/backend.o \
|
||||||
|
@ -102,9 +102,9 @@ LIBS = $(LIBS.$(TARGET)) $(LIBS.$(REGEX)) $(ADDLIB)
|
|||||||
CFLAGS = -Wall $(COPTS) $(DEBUG) -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -mmacosx-version-min=10.4
|
CFLAGS = -Wall $(COPTS) $(DEBUG) -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -mmacosx-version-min=10.4
|
||||||
LDFLAGS = -g -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -mmacosx-version-min=10.4
|
LDFLAGS = -g -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -mmacosx-version-min=10.4
|
||||||
|
|
||||||
OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \
|
OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocol.o \
|
||||||
src/uri_auth.o src/standard.o src/buffer.o src/log.o src/task.o \
|
src/uri_auth.o src/standard.o src/buffer.o src/log.o src/task.o \
|
||||||
src/chunk.o src/channel.o \
|
src/chunk.o src/channel.o src/listener.o \
|
||||||
src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \
|
src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \
|
||||||
src/checks.o src/queue.o src/frontend.o src/proxy.o src/proto_uxst.o \
|
src/checks.o src/queue.o src/frontend.o src/proxy.o src/proto_uxst.o \
|
||||||
src/proto_http.o src/raw_sock.o src/appsession.o src/backend.o \
|
src/proto_http.o src/raw_sock.o src/appsession.o src/backend.o \
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
#include <types/connection.h>
|
#include <types/connection.h>
|
||||||
#include <types/protocols.h>
|
#include <types/listener.h>
|
||||||
|
|
||||||
/* I/O callback for fd-based connections. It calls the read/write handlers
|
/* I/O callback for fd-based connections. It calls the read/write handlers
|
||||||
* provided by the connection's sock_ops. Returns 0.
|
* provided by the connection's sock_ops. Returns 0.
|
||||||
|
@ -1,28 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
include/proto/protocols.h
|
* include/proto/listener.h
|
||||||
This file declares generic protocol primitives.
|
* This file declares listener management primitives.
|
||||||
|
*
|
||||||
Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
|
* Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
|
||||||
|
*
|
||||||
This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation, version 2.1
|
* License as published by the Free Software Foundation, version 2.1
|
||||||
exclusively.
|
* exclusively.
|
||||||
|
*
|
||||||
This library is distributed in the hope that it will be useful,
|
* This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _PROTO_PROTOCOLS_H
|
#ifndef _PROTO_LISTENER_H
|
||||||
#define _PROTO_PROTOCOLS_H
|
#define _PROTO_LISTENER_H
|
||||||
|
|
||||||
#include <types/protocols.h>
|
#include <types/listener.h>
|
||||||
|
|
||||||
/* This function adds the specified listener's file descriptor to the polling
|
/* This function adds the specified listener's file descriptor to the polling
|
||||||
* lists if it is in the LI_LISTEN state. The listener enters LI_READY or
|
* lists if it is in the LI_LISTEN state. The listener enters LI_READY or
|
||||||
@ -105,35 +105,6 @@ void delete_listener(struct listener *listener);
|
|||||||
*/
|
*/
|
||||||
int listener_accept(int fd);
|
int listener_accept(int fd);
|
||||||
|
|
||||||
/* Registers the protocol <proto> */
|
|
||||||
void protocol_register(struct protocol *proto);
|
|
||||||
|
|
||||||
/* Unregisters the protocol <proto>. Note that all listeners must have
|
|
||||||
* previously been unbound.
|
|
||||||
*/
|
|
||||||
void protocol_unregister(struct protocol *proto);
|
|
||||||
|
|
||||||
/* binds all listeneres of all registered protocols. Returns a composition
|
|
||||||
* of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
|
|
||||||
*/
|
|
||||||
int protocol_bind_all(char *errmsg, int errlen);
|
|
||||||
|
|
||||||
/* unbinds all listeners of all registered protocols. They are also closed.
|
|
||||||
* This must be performed before calling exit() in order to get a chance to
|
|
||||||
* remove file-system based sockets and pipes.
|
|
||||||
* Returns a composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
|
|
||||||
*/
|
|
||||||
int protocol_unbind_all(void);
|
|
||||||
|
|
||||||
/* enables all listeners of all registered protocols. This is intended to be
|
|
||||||
* used after a fork() to enable reading on all file descriptors. Returns a
|
|
||||||
* composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
|
|
||||||
*/
|
|
||||||
int protocol_enable_all(void);
|
|
||||||
|
|
||||||
/* returns the protocol associated to family <family> or NULL if not found */
|
|
||||||
struct protocol *protocol_by_family(int family);
|
|
||||||
|
|
||||||
/* allocate an ssl_conf struct for a bind line, and chain it to list head <lh>.
|
/* allocate an ssl_conf struct for a bind line, and chain it to list head <lh>.
|
||||||
* If <arg> is not NULL, it is duplicated into ->arg to store useful config
|
* If <arg> is not NULL, it is duplicated into ->arg to store useful config
|
||||||
* information for error reporting.
|
* information for error reporting.
|
||||||
@ -151,7 +122,7 @@ static inline struct ssl_conf *ssl_conf_alloc(struct list *lh, const char *file,
|
|||||||
return ssl_conf;
|
return ssl_conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _PROTO_PROTOCOLS_H */
|
#endif /* _PROTO_LISTENER_H */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Local variables:
|
* Local variables:
|
63
include/proto/protocol.h
Normal file
63
include/proto/protocol.h
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* include/proto/protocol.h
|
||||||
|
* This file declares generic protocol management primitives.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, version 2.1
|
||||||
|
* exclusively.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _PROTO_PROTOCOL_H
|
||||||
|
#define _PROTO_PROTOCOL_H
|
||||||
|
|
||||||
|
#include <types/protocol.h>
|
||||||
|
|
||||||
|
/* Registers the protocol <proto> */
|
||||||
|
void protocol_register(struct protocol *proto);
|
||||||
|
|
||||||
|
/* Unregisters the protocol <proto>. Note that all listeners must have
|
||||||
|
* previously been unbound.
|
||||||
|
*/
|
||||||
|
void protocol_unregister(struct protocol *proto);
|
||||||
|
|
||||||
|
/* binds all listeneres of all registered protocols. Returns a composition
|
||||||
|
* of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
|
||||||
|
*/
|
||||||
|
int protocol_bind_all(char *errmsg, int errlen);
|
||||||
|
|
||||||
|
/* unbinds all listeners of all registered protocols. They are also closed.
|
||||||
|
* This must be performed before calling exit() in order to get a chance to
|
||||||
|
* remove file-system based sockets and pipes.
|
||||||
|
* Returns a composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
|
||||||
|
*/
|
||||||
|
int protocol_unbind_all(void);
|
||||||
|
|
||||||
|
/* enables all listeners of all registered protocols. This is intended to be
|
||||||
|
* used after a fork() to enable reading on all file descriptors. Returns a
|
||||||
|
* composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
|
||||||
|
*/
|
||||||
|
int protocol_enable_all(void);
|
||||||
|
|
||||||
|
/* returns the protocol associated to family <family> or NULL if not found */
|
||||||
|
struct protocol *protocol_by_family(int family);
|
||||||
|
|
||||||
|
#endif /* _PROTO_PROTOCOL_H */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local variables:
|
||||||
|
* c-indent-level: 8
|
||||||
|
* c-basic-offset: 8
|
||||||
|
* End:
|
||||||
|
*/
|
@ -27,6 +27,7 @@
|
|||||||
#include <common/time.h>
|
#include <common/time.h>
|
||||||
#include <types/global.h>
|
#include <types/global.h>
|
||||||
#include <types/proxy.h>
|
#include <types/proxy.h>
|
||||||
|
#include <types/listener.h>
|
||||||
#include <proto/freq_ctr.h>
|
#include <proto/freq_ctr.h>
|
||||||
|
|
||||||
int start_proxies(int verbose);
|
int start_proxies(int verbose);
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
#define _PROTO_SSL_SOCK_H
|
#define _PROTO_SSL_SOCK_H
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
#include <types/protocols.h>
|
#include <types/connection.h>
|
||||||
|
#include <types/listener.h>
|
||||||
|
#include <types/proxy.h>
|
||||||
#include <types/stream_interface.h>
|
#include <types/stream_interface.h>
|
||||||
|
|
||||||
extern struct data_ops ssl_sock;
|
extern struct data_ops ssl_sock;
|
||||||
|
@ -27,8 +27,10 @@
|
|||||||
|
|
||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
|
|
||||||
|
#include <types/listener.h>
|
||||||
|
#include <types/protocol.h>
|
||||||
|
|
||||||
/* referenced below */
|
/* referenced below */
|
||||||
struct protocol;
|
|
||||||
struct connection;
|
struct connection;
|
||||||
struct buffer;
|
struct buffer;
|
||||||
struct pipe;
|
struct pipe;
|
||||||
@ -36,7 +38,6 @@ struct server;
|
|||||||
struct proxy;
|
struct proxy;
|
||||||
struct si_applet;
|
struct si_applet;
|
||||||
struct task;
|
struct task;
|
||||||
struct listener;
|
|
||||||
|
|
||||||
/* Polling flags that are manipulated by I/O callbacks and handshake callbacks
|
/* Polling flags that are manipulated by I/O callbacks and handshake callbacks
|
||||||
* indicate what they expect from a file descriptor at each layer. For each
|
* indicate what they expect from a file descriptor at each layer. For each
|
||||||
|
@ -26,8 +26,7 @@
|
|||||||
|
|
||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
#include <types/freq_ctr.h>
|
#include <types/freq_ctr.h>
|
||||||
#include <types/log.h>
|
#include <types/listener.h>
|
||||||
#include <types/protocols.h>
|
|
||||||
#include <types/proxy.h>
|
#include <types/proxy.h>
|
||||||
#include <types/task.h>
|
#include <types/task.h>
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* include/types/protocols.h
|
* include/types/listener.h
|
||||||
* This file defines the structures used by generic network protocols.
|
* This file defines the structures needed to manage listeners.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000-2011 Willy Tarreau - w@1wt.eu
|
* Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -19,13 +19,11 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TYPES_PROTOCOLS_H
|
#ifndef _TYPES_LISTENER_H
|
||||||
#define _TYPES_PROTOCOLS_H
|
#define _TYPES_LISTENER_H
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/un.h>
|
|
||||||
|
|
||||||
#ifdef USE_OPENSSL
|
#ifdef USE_OPENSSL
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
@ -35,11 +33,12 @@
|
|||||||
#include <common/mini-clist.h>
|
#include <common/mini-clist.h>
|
||||||
#include <eb32tree.h>
|
#include <eb32tree.h>
|
||||||
|
|
||||||
#include <types/counters.h>
|
/* Some pointer types reference below */
|
||||||
#include <types/task.h>
|
struct task;
|
||||||
|
struct protocol;
|
||||||
/* max length of a protcol name, including trailing zero */
|
struct data_ops;
|
||||||
#define PROTO_NAME_LEN 16
|
struct proxy;
|
||||||
|
struct licounters;
|
||||||
|
|
||||||
/* listener state */
|
/* listener state */
|
||||||
enum {
|
enum {
|
||||||
@ -159,38 +158,7 @@ struct listener {
|
|||||||
} conf; /* config information */
|
} conf; /* config information */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct connection;
|
#endif /* _TYPES_LISTENER_H */
|
||||||
|
|
||||||
/* This structure contains all information needed to easily handle a protocol.
|
|
||||||
* Its primary goal is to ease listeners maintenance. Specifically, the
|
|
||||||
* bind_all() primitive must be used before any fork(), and the enable_all()
|
|
||||||
* primitive must be called after the fork() to enable all fds. Last, the
|
|
||||||
* unbind_all() primitive closes all listeners.
|
|
||||||
*/
|
|
||||||
struct protocol {
|
|
||||||
char name[PROTO_NAME_LEN]; /* protocol name, zero-terminated */
|
|
||||||
int sock_domain; /* socket domain, as passed to socket() */
|
|
||||||
int sock_type; /* socket type, as passed to socket() */
|
|
||||||
int sock_prot; /* socket protocol, as passed to socket() */
|
|
||||||
sa_family_t sock_family; /* socket family, for sockaddr */
|
|
||||||
socklen_t sock_addrlen; /* socket address length, used by bind() */
|
|
||||||
int l3_addrlen; /* layer3 address length, used by hashes */
|
|
||||||
int (*accept)(int fd); /* generic accept function */
|
|
||||||
int (*bind)(struct listener *l, char *errmsg, int errlen); /* bind a listener */
|
|
||||||
int (*bind_all)(struct protocol *proto, char *errmsg, int errlen); /* bind all unbound listeners */
|
|
||||||
int (*unbind_all)(struct protocol *proto); /* unbind all bound listeners */
|
|
||||||
int (*enable_all)(struct protocol *proto); /* enable all bound listeners */
|
|
||||||
int (*disable_all)(struct protocol *proto); /* disable all bound listeners */
|
|
||||||
int (*connect)(struct connection *, int data); /* connect function if any */
|
|
||||||
int (*get_src)(int fd, struct sockaddr *, socklen_t, int dir); /* syscall used to retrieve src addr */
|
|
||||||
int (*get_dst)(int fd, struct sockaddr *, socklen_t, int dir); /* syscall used to retrieve dst addr */
|
|
||||||
|
|
||||||
struct list listeners; /* list of listeners using this protocol */
|
|
||||||
int nb_listeners; /* number of listeners */
|
|
||||||
struct list list; /* list of registered protocols */
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* _TYPES_PROTOCOLS_H */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Local variables:
|
* Local variables:
|
75
include/types/protocol.h
Normal file
75
include/types/protocol.h
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* include/types/protocol.h
|
||||||
|
* This file defines the structures used by generic network protocols.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, version 2.1
|
||||||
|
* exclusively.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TYPES_PROTOCOL_H
|
||||||
|
#define _TYPES_PROTOCOL_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <common/config.h>
|
||||||
|
#include <common/mini-clist.h>
|
||||||
|
#include <eb32tree.h>
|
||||||
|
|
||||||
|
/* some pointer types referenced below */
|
||||||
|
struct listener;
|
||||||
|
struct connection;
|
||||||
|
|
||||||
|
/* max length of a protcol name, including trailing zero */
|
||||||
|
#define PROTO_NAME_LEN 16
|
||||||
|
|
||||||
|
/* This structure contains all information needed to easily handle a protocol.
|
||||||
|
* Its primary goal is to ease listeners maintenance. Specifically, the
|
||||||
|
* bind_all() primitive must be used before any fork(), and the enable_all()
|
||||||
|
* primitive must be called after the fork() to enable all fds. Last, the
|
||||||
|
* unbind_all() primitive closes all listeners.
|
||||||
|
*/
|
||||||
|
struct protocol {
|
||||||
|
char name[PROTO_NAME_LEN]; /* protocol name, zero-terminated */
|
||||||
|
int sock_domain; /* socket domain, as passed to socket() */
|
||||||
|
int sock_type; /* socket type, as passed to socket() */
|
||||||
|
int sock_prot; /* socket protocol, as passed to socket() */
|
||||||
|
sa_family_t sock_family; /* socket family, for sockaddr */
|
||||||
|
socklen_t sock_addrlen; /* socket address length, used by bind() */
|
||||||
|
int l3_addrlen; /* layer3 address length, used by hashes */
|
||||||
|
int (*accept)(int fd); /* generic accept function */
|
||||||
|
int (*bind)(struct listener *l, char *errmsg, int errlen); /* bind a listener */
|
||||||
|
int (*bind_all)(struct protocol *proto, char *errmsg, int errlen); /* bind all unbound listeners */
|
||||||
|
int (*unbind_all)(struct protocol *proto); /* unbind all bound listeners */
|
||||||
|
int (*enable_all)(struct protocol *proto); /* enable all bound listeners */
|
||||||
|
int (*disable_all)(struct protocol *proto); /* disable all bound listeners */
|
||||||
|
int (*connect)(struct connection *, int data); /* connect function if any */
|
||||||
|
int (*get_src)(int fd, struct sockaddr *, socklen_t, int dir); /* syscall used to retrieve src addr */
|
||||||
|
int (*get_dst)(int fd, struct sockaddr *, socklen_t, int dir); /* syscall used to retrieve dst addr */
|
||||||
|
|
||||||
|
struct list listeners; /* list of listeners using this protocol */
|
||||||
|
int nb_listeners; /* number of listeners */
|
||||||
|
struct list list; /* list of registered protocols */
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _TYPES_PROTOCOL_H */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local variables:
|
||||||
|
* c-indent-level: 8
|
||||||
|
* c-basic-offset: 8
|
||||||
|
* End:
|
||||||
|
*/
|
@ -40,8 +40,8 @@
|
|||||||
#include <types/backend.h>
|
#include <types/backend.h>
|
||||||
#include <types/counters.h>
|
#include <types/counters.h>
|
||||||
#include <types/freq_ctr.h>
|
#include <types/freq_ctr.h>
|
||||||
|
#include <types/listener.h>
|
||||||
#include <types/log.h>
|
#include <types/log.h>
|
||||||
#include <types/protocols.h>
|
|
||||||
#include <types/proto_http.h>
|
#include <types/proto_http.h>
|
||||||
#include <types/sample.h>
|
#include <types/sample.h>
|
||||||
#include <types/session.h>
|
#include <types/session.h>
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
#include <proto/lb_fwlc.h>
|
#include <proto/lb_fwlc.h>
|
||||||
#include <proto/lb_fwrr.h>
|
#include <proto/lb_fwrr.h>
|
||||||
#include <proto/lb_map.h>
|
#include <proto/lb_map.h>
|
||||||
#include <proto/protocols.h>
|
#include <proto/protocol.h>
|
||||||
#include <proto/proto_http.h>
|
#include <proto/proto_http.h>
|
||||||
#include <proto/proto_tcp.h>
|
#include <proto/proto_tcp.h>
|
||||||
#include <proto/queue.h>
|
#include <proto/queue.h>
|
||||||
|
@ -51,9 +51,10 @@
|
|||||||
#include <proto/lb_fwlc.h>
|
#include <proto/lb_fwlc.h>
|
||||||
#include <proto/lb_fwrr.h>
|
#include <proto/lb_fwrr.h>
|
||||||
#include <proto/lb_map.h>
|
#include <proto/lb_map.h>
|
||||||
|
#include <proto/listener.h>
|
||||||
#include <proto/log.h>
|
#include <proto/log.h>
|
||||||
#include <proto/port_range.h>
|
#include <proto/port_range.h>
|
||||||
#include <proto/protocols.h>
|
#include <proto/protocol.h>
|
||||||
#include <proto/proto_tcp.h>
|
#include <proto/proto_tcp.h>
|
||||||
#include <proto/proto_uxst.h>
|
#include <proto/proto_uxst.h>
|
||||||
#include <proto/proto_http.h>
|
#include <proto/proto_http.h>
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
#include <proto/freq_ctr.h>
|
#include <proto/freq_ctr.h>
|
||||||
#include <proto/log.h>
|
#include <proto/log.h>
|
||||||
#include <proto/pipe.h>
|
#include <proto/pipe.h>
|
||||||
#include <proto/protocols.h>
|
#include <proto/listener.h>
|
||||||
#include <proto/proto_uxst.h>
|
#include <proto/proto_uxst.h>
|
||||||
#include <proto/proxy.h>
|
#include <proto/proxy.h>
|
||||||
#include <proto/session.h>
|
#include <proto/session.h>
|
||||||
|
@ -78,8 +78,9 @@
|
|||||||
#include <proto/checks.h>
|
#include <proto/checks.h>
|
||||||
#include <proto/fd.h>
|
#include <proto/fd.h>
|
||||||
#include <proto/hdr_idx.h>
|
#include <proto/hdr_idx.h>
|
||||||
|
#include <proto/listener.h>
|
||||||
#include <proto/log.h>
|
#include <proto/log.h>
|
||||||
#include <proto/protocols.h>
|
#include <proto/protocol.h>
|
||||||
#include <proto/proto_http.h>
|
#include <proto/proto_http.h>
|
||||||
#include <proto/proxy.h>
|
#include <proto/proxy.h>
|
||||||
#include <proto/queue.h>
|
#include <proto/queue.h>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Protocol registration and listener management functions.
|
* Listener management functions.
|
||||||
*
|
*
|
||||||
* Copyright 2000-2010 Willy Tarreau <w@1wt.eu>
|
* Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
@ -21,6 +21,7 @@
|
|||||||
#include <common/time.h>
|
#include <common/time.h>
|
||||||
|
|
||||||
#include <types/global.h>
|
#include <types/global.h>
|
||||||
|
#include <types/protocol.h>
|
||||||
|
|
||||||
#include <proto/acl.h>
|
#include <proto/acl.h>
|
||||||
#include <proto/fd.h>
|
#include <proto/fd.h>
|
||||||
@ -28,9 +29,6 @@
|
|||||||
#include <proto/log.h>
|
#include <proto/log.h>
|
||||||
#include <proto/task.h>
|
#include <proto/task.h>
|
||||||
|
|
||||||
/* List head of all registered protocols */
|
|
||||||
static struct list protocols = LIST_HEAD_INIT(protocols);
|
|
||||||
|
|
||||||
/* This function adds the specified listener's file descriptor to the polling
|
/* This function adds the specified listener's file descriptor to the polling
|
||||||
* lists if it is in the LI_LISTEN state. The listener enters LI_READY or
|
* lists if it is in the LI_LISTEN state. The listener enters LI_READY or
|
||||||
* LI_FULL state depending on its number of connections.
|
* LI_FULL state depending on its number of connections.
|
||||||
@ -411,107 +409,6 @@ void listener_accept(int fd)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Registers the protocol <proto> */
|
|
||||||
void protocol_register(struct protocol *proto)
|
|
||||||
{
|
|
||||||
LIST_ADDQ(&protocols, &proto->list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Unregisters the protocol <proto>. Note that all listeners must have
|
|
||||||
* previously been unbound.
|
|
||||||
*/
|
|
||||||
void protocol_unregister(struct protocol *proto)
|
|
||||||
{
|
|
||||||
LIST_DEL(&proto->list);
|
|
||||||
LIST_INIT(&proto->list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* binds all listeners of all registered protocols. Returns a composition
|
|
||||||
* of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
|
|
||||||
*/
|
|
||||||
int protocol_bind_all(char *errmsg, int errlen)
|
|
||||||
{
|
|
||||||
struct protocol *proto;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = 0;
|
|
||||||
list_for_each_entry(proto, &protocols, list) {
|
|
||||||
if (proto->bind_all) {
|
|
||||||
err |= proto->bind_all(proto, errmsg, errlen);
|
|
||||||
if ( err & ERR_ABORT )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* unbinds all listeners of all registered protocols. They are also closed.
|
|
||||||
* This must be performed before calling exit() in order to get a chance to
|
|
||||||
* remove file-system based sockets and pipes.
|
|
||||||
* Returns a composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL, ERR_ABORT.
|
|
||||||
*/
|
|
||||||
int protocol_unbind_all(void)
|
|
||||||
{
|
|
||||||
struct protocol *proto;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = 0;
|
|
||||||
list_for_each_entry(proto, &protocols, list) {
|
|
||||||
if (proto->unbind_all) {
|
|
||||||
err |= proto->unbind_all(proto);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* enables all listeners of all registered protocols. This is intended to be
|
|
||||||
* used after a fork() to enable reading on all file descriptors. Returns a
|
|
||||||
* composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
|
|
||||||
*/
|
|
||||||
int protocol_enable_all(void)
|
|
||||||
{
|
|
||||||
struct protocol *proto;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = 0;
|
|
||||||
list_for_each_entry(proto, &protocols, list) {
|
|
||||||
if (proto->enable_all) {
|
|
||||||
err |= proto->enable_all(proto);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* disables all listeners of all registered protocols. This may be used before
|
|
||||||
* a fork() to avoid duplicating poll lists. Returns a composition of ERR_NONE,
|
|
||||||
* ERR_RETRYABLE, ERR_FATAL.
|
|
||||||
*/
|
|
||||||
int protocol_disable_all(void)
|
|
||||||
{
|
|
||||||
struct protocol *proto;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = 0;
|
|
||||||
list_for_each_entry(proto, &protocols, list) {
|
|
||||||
if (proto->disable_all) {
|
|
||||||
err |= proto->disable_all(proto);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns the protocol handler for socket family <family> or NULL if not found */
|
|
||||||
struct protocol *protocol_by_family(int family)
|
|
||||||
{
|
|
||||||
struct protocol *proto;
|
|
||||||
|
|
||||||
list_for_each_entry(proto, &protocols, list) {
|
|
||||||
if (proto->sock_domain == family)
|
|
||||||
return proto;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* All supported ACL keywords must be declared here. */
|
/* All supported ACL keywords must be declared here. */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
@ -546,7 +443,7 @@ static struct acl_kw_list acl_kws = {{ },{
|
|||||||
}};
|
}};
|
||||||
|
|
||||||
__attribute__((constructor))
|
__attribute__((constructor))
|
||||||
static void __protocols_init(void)
|
static void __listener_init(void)
|
||||||
{
|
{
|
||||||
acl_register_keywords(&acl_kws);
|
acl_register_keywords(&acl_kws);
|
||||||
}
|
}
|
@ -25,6 +25,7 @@
|
|||||||
#include <common/time.h>
|
#include <common/time.h>
|
||||||
|
|
||||||
#include <types/global.h>
|
#include <types/global.h>
|
||||||
|
#include <proto/listener.h>
|
||||||
#include <types/peers.h>
|
#include <types/peers.h>
|
||||||
|
|
||||||
#include <proto/acl.h>
|
#include <proto/acl.h>
|
||||||
@ -32,7 +33,6 @@
|
|||||||
#include <proto/fd.h>
|
#include <proto/fd.h>
|
||||||
#include <proto/log.h>
|
#include <proto/log.h>
|
||||||
#include <proto/hdr_idx.h>
|
#include <proto/hdr_idx.h>
|
||||||
#include <proto/protocols.h>
|
|
||||||
#include <proto/proto_tcp.h>
|
#include <proto/proto_tcp.h>
|
||||||
#include <proto/proto_http.h>
|
#include <proto/proto_http.h>
|
||||||
#include <proto/proxy.h>
|
#include <proto/proxy.h>
|
||||||
|
@ -42,9 +42,10 @@
|
|||||||
#include <proto/channel.h>
|
#include <proto/channel.h>
|
||||||
#include <proto/connection.h>
|
#include <proto/connection.h>
|
||||||
#include <proto/fd.h>
|
#include <proto/fd.h>
|
||||||
|
#include <proto/listener.h>
|
||||||
#include <proto/log.h>
|
#include <proto/log.h>
|
||||||
#include <proto/port_range.h>
|
#include <proto/port_range.h>
|
||||||
#include <proto/protocols.h>
|
#include <proto/protocol.h>
|
||||||
#include <proto/proto_tcp.h>
|
#include <proto/proto_tcp.h>
|
||||||
#include <proto/proxy.h>
|
#include <proto/proxy.h>
|
||||||
#include <proto/sample.h>
|
#include <proto/sample.h>
|
||||||
|
@ -36,8 +36,9 @@
|
|||||||
#include <types/global.h>
|
#include <types/global.h>
|
||||||
|
|
||||||
#include <proto/fd.h>
|
#include <proto/fd.h>
|
||||||
|
#include <proto/listener.h>
|
||||||
#include <proto/log.h>
|
#include <proto/log.h>
|
||||||
#include <proto/protocols.h>
|
#include <proto/protocol.h>
|
||||||
#include <proto/proto_uxst.h>
|
#include <proto/proto_uxst.h>
|
||||||
#include <proto/task.h>
|
#include <proto/task.h>
|
||||||
|
|
||||||
|
129
src/protocol.c
Normal file
129
src/protocol.c
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* Protocol registration functions.
|
||||||
|
*
|
||||||
|
* Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version
|
||||||
|
* 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <common/config.h>
|
||||||
|
#include <common/errors.h>
|
||||||
|
#include <common/mini-clist.h>
|
||||||
|
#include <common/standard.h>
|
||||||
|
|
||||||
|
#include <types/protocol.h>
|
||||||
|
|
||||||
|
/* List head of all registered protocols */
|
||||||
|
static struct list protocols = LIST_HEAD_INIT(protocols);
|
||||||
|
|
||||||
|
/* Registers the protocol <proto> */
|
||||||
|
void protocol_register(struct protocol *proto)
|
||||||
|
{
|
||||||
|
LIST_ADDQ(&protocols, &proto->list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Unregisters the protocol <proto>. Note that all listeners must have
|
||||||
|
* previously been unbound.
|
||||||
|
*/
|
||||||
|
void protocol_unregister(struct protocol *proto)
|
||||||
|
{
|
||||||
|
LIST_DEL(&proto->list);
|
||||||
|
LIST_INIT(&proto->list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* binds all listeners of all registered protocols. Returns a composition
|
||||||
|
* of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
|
||||||
|
*/
|
||||||
|
int protocol_bind_all(char *errmsg, int errlen)
|
||||||
|
{
|
||||||
|
struct protocol *proto;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
list_for_each_entry(proto, &protocols, list) {
|
||||||
|
if (proto->bind_all) {
|
||||||
|
err |= proto->bind_all(proto, errmsg, errlen);
|
||||||
|
if ( err & ERR_ABORT )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* unbinds all listeners of all registered protocols. They are also closed.
|
||||||
|
* This must be performed before calling exit() in order to get a chance to
|
||||||
|
* remove file-system based sockets and pipes.
|
||||||
|
* Returns a composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL, ERR_ABORT.
|
||||||
|
*/
|
||||||
|
int protocol_unbind_all(void)
|
||||||
|
{
|
||||||
|
struct protocol *proto;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
list_for_each_entry(proto, &protocols, list) {
|
||||||
|
if (proto->unbind_all) {
|
||||||
|
err |= proto->unbind_all(proto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* enables all listeners of all registered protocols. This is intended to be
|
||||||
|
* used after a fork() to enable reading on all file descriptors. Returns a
|
||||||
|
* composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
|
||||||
|
*/
|
||||||
|
int protocol_enable_all(void)
|
||||||
|
{
|
||||||
|
struct protocol *proto;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
list_for_each_entry(proto, &protocols, list) {
|
||||||
|
if (proto->enable_all) {
|
||||||
|
err |= proto->enable_all(proto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* disables all listeners of all registered protocols. This may be used before
|
||||||
|
* a fork() to avoid duplicating poll lists. Returns a composition of ERR_NONE,
|
||||||
|
* ERR_RETRYABLE, ERR_FATAL.
|
||||||
|
*/
|
||||||
|
int protocol_disable_all(void)
|
||||||
|
{
|
||||||
|
struct protocol *proto;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
list_for_each_entry(proto, &protocols, list) {
|
||||||
|
if (proto->disable_all) {
|
||||||
|
err |= proto->disable_all(proto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns the protocol handler for socket family <family> or NULL if not found */
|
||||||
|
struct protocol *protocol_by_family(int family)
|
||||||
|
{
|
||||||
|
struct protocol *proto;
|
||||||
|
|
||||||
|
list_for_each_entry(proto, &protocols, list) {
|
||||||
|
if (proto->sock_domain == family)
|
||||||
|
return proto;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local variables:
|
||||||
|
* c-indent-level: 8
|
||||||
|
* c-basic-offset: 8
|
||||||
|
* End:
|
||||||
|
*/
|
@ -31,8 +31,8 @@
|
|||||||
#include <proto/backend.h>
|
#include <proto/backend.h>
|
||||||
#include <proto/fd.h>
|
#include <proto/fd.h>
|
||||||
#include <proto/hdr_idx.h>
|
#include <proto/hdr_idx.h>
|
||||||
|
#include <proto/listener.h>
|
||||||
#include <proto/log.h>
|
#include <proto/log.h>
|
||||||
#include <proto/protocols.h>
|
|
||||||
#include <proto/proto_tcp.h>
|
#include <proto/proto_tcp.h>
|
||||||
#include <proto/proto_http.h>
|
#include <proto/proto_http.h>
|
||||||
#include <proto/proxy.h>
|
#include <proto/proxy.h>
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
#include <proto/freq_ctr.h>
|
#include <proto/freq_ctr.h>
|
||||||
#include <proto/log.h>
|
#include <proto/log.h>
|
||||||
#include <proto/pipe.h>
|
#include <proto/pipe.h>
|
||||||
#include <proto/protocols.h>
|
|
||||||
#include <proto/raw_sock.h>
|
#include <proto/raw_sock.h>
|
||||||
#include <proto/stream_interface.h>
|
#include <proto/stream_interface.h>
|
||||||
#include <proto/task.h>
|
#include <proto/task.h>
|
||||||
|
@ -32,11 +32,11 @@
|
|||||||
#include <proto/freq_ctr.h>
|
#include <proto/freq_ctr.h>
|
||||||
#include <proto/frontend.h>
|
#include <proto/frontend.h>
|
||||||
#include <proto/hdr_idx.h>
|
#include <proto/hdr_idx.h>
|
||||||
|
#include <proto/listener.h>
|
||||||
#include <proto/log.h>
|
#include <proto/log.h>
|
||||||
#include <proto/raw_sock.h>
|
#include <proto/raw_sock.h>
|
||||||
#include <proto/session.h>
|
#include <proto/session.h>
|
||||||
#include <proto/pipe.h>
|
#include <proto/pipe.h>
|
||||||
#include <proto/protocols.h>
|
|
||||||
#include <proto/proto_http.h>
|
#include <proto/proto_http.h>
|
||||||
#include <proto/proto_tcp.h>
|
#include <proto/proto_tcp.h>
|
||||||
#include <proto/proxy.h>
|
#include <proto/proxy.h>
|
||||||
|
@ -64,7 +64,6 @@
|
|||||||
#include <proto/freq_ctr.h>
|
#include <proto/freq_ctr.h>
|
||||||
#include <proto/frontend.h>
|
#include <proto/frontend.h>
|
||||||
#include <proto/log.h>
|
#include <proto/log.h>
|
||||||
#include <proto/protocols.h>
|
|
||||||
#include <proto/shctx.h>
|
#include <proto/shctx.h>
|
||||||
#include <proto/ssl_sock.h>
|
#include <proto/ssl_sock.h>
|
||||||
#include <proto/task.h>
|
#include <proto/task.h>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user