[BIGMOVE] exploded the monolithic haproxy.c file into multiple files.
The files are now stored under :
- include/haproxy for the generic includes
- include/types.h for the structures needed within prototypes
- include/proto.h for function prototypes and inline functions
- src/*.c for the C files
Most include files are now covered by LGPL. A last move still needs
to be done to put inline functions under GPL and not LGPL.
Version has been set to 1.3.0 in the code but some control still
needs to be done before releasing.
diff --git a/include/types/backend.h b/include/types/backend.h
new file mode 100644
index 0000000..7a6a640
--- /dev/null
+++ b/include/types/backend.h
@@ -0,0 +1,60 @@
+/*
+ include/types/backend.h
+ This file rassembles definitions for backends
+
+ Copyright (C) 2000-2006 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_BACKEND_H
+#define _TYPES_BACKEND_H
+
+/* bits for proxy->options */
+#define PR_O_REDISP 0x00000001 /* allow reconnection to dispatch in case of errors */
+#define PR_O_TRANSP 0x00000002 /* transparent mode : use original DEST as dispatch */
+#define PR_O_COOK_RW 0x00000004 /* rewrite all direct cookies with the right serverid */
+#define PR_O_COOK_IND 0x00000008 /* keep only indirect cookies */
+#define PR_O_COOK_INS 0x00000010 /* insert cookies when not accessing a server directly */
+#define PR_O_COOK_PFX 0x00000020 /* rewrite all cookies by prefixing the right serverid */
+#define PR_O_COOK_ANY (PR_O_COOK_RW | PR_O_COOK_IND | PR_O_COOK_INS | PR_O_COOK_PFX)
+#define PR_O_BALANCE_RR 0x00000040 /* balance in round-robin mode */
+#define PR_O_KEEPALIVE 0x00000080 /* follow keep-alive sessions */
+#define PR_O_FWDFOR 0x00000100 /* insert x-forwarded-for with client address */
+#define PR_O_BIND_SRC 0x00000200 /* bind to a specific source address when connect()ing */
+#define PR_O_NULLNOLOG 0x00000400 /* a connect without request will not be logged */
+#define PR_O_COOK_NOC 0x00000800 /* add a 'Cache-control' header with the cookie */
+#define PR_O_COOK_POST 0x00001000 /* don't insert cookies for requests other than a POST */
+#define PR_O_HTTP_CHK 0x00002000 /* use HTTP 'OPTIONS' method to check server health */
+#define PR_O_PERSIST 0x00004000 /* server persistence stays effective even when server is down */
+#define PR_O_LOGASAP 0x00008000 /* log as soon as possible, without waiting for the session to complete */
+#define PR_O_HTTP_CLOSE 0x00010000 /* force 'connection: close' in both directions */
+#define PR_O_CHK_CACHE 0x00020000 /* require examination of cacheability of the 'set-cookie' field */
+#define PR_O_TCP_CLI_KA 0x00040000 /* enable TCP keep-alive on client-side sessions */
+#define PR_O_TCP_SRV_KA 0x00080000 /* enable TCP keep-alive on server-side sessions */
+#define PR_O_USE_ALL_BK 0x00100000 /* load-balance between backup servers */
+#define PR_O_FORCE_CLO 0x00200000 /* enforce the connection close immediately after server response */
+#define PR_O_BALANCE_SH 0x00400000 /* balance on source IP hash */
+#define PR_O_BALANCE (PR_O_BALANCE_RR | PR_O_BALANCE_SH)
+#define PR_O_ABRT_CLOSE 0x00800000 /* immediately abort request when client closes */
+
+#endif /* _TYPES_BACKEND_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/buffers.h b/include/types/buffers.h
new file mode 100644
index 0000000..2fcf59f
--- /dev/null
+++ b/include/types/buffers.h
@@ -0,0 +1,53 @@
+/*
+ include/types/buffers.h
+ Buffer management definitions, macros and inline functions.
+
+ Copyright (C) 2000-2006 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_BUFFERS_H
+#define _TYPES_BUFFERS_H
+
+#include <haproxy/defaults.h>
+#include <haproxy/memory.h>
+
+/* describes a chunk of string */
+struct chunk {
+ char *str; /* beginning of the string itself. Might not be 0-terminated */
+ int len; /* size of the string from first to last char. <0 = uninit. */
+};
+
+struct buffer {
+ unsigned int l; /* data length */
+ char *r, *w, *h, *lr; /* read ptr, write ptr, last header ptr, last read */
+ char *rlim; /* read limit, used for header rewriting */
+ unsigned long long total; /* total data read */
+ char data[BUFSIZE];
+};
+
+#define sizeof_buffer sizeof(struct buffer)
+extern void **pool_buffer;
+
+
+#endif /* _TYPES_BUFFERS_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/capture.h b/include/types/capture.h
new file mode 100644
index 0000000..e531b54
--- /dev/null
+++ b/include/types/capture.h
@@ -0,0 +1,43 @@
+/*
+ include/types/capture.h
+ This file defines everything related to captures.
+
+ Copyright (C) 2000-2006 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_CAPTURE_H
+#define _TYPES_CAPTURE_H
+
+struct cap_hdr {
+ struct cap_hdr *next;
+ char *name; /* header name, case insensitive */
+ int namelen; /* length of the header name, to speed-up lookups */
+ int len; /* capture length, not including terminal zero */
+ int index; /* index in the output array */
+ void *pool; /* pool of pre-allocated memory area of (len+1) bytes */
+};
+
+extern void **pool_capture;
+
+#endif /* _TYPES_CAPTURE_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/client.h b/include/types/client.h
new file mode 100644
index 0000000..d19e100
--- /dev/null
+++ b/include/types/client.h
@@ -0,0 +1,45 @@
+/*
+ include/types/client.h
+ This file contains client-side definitions.
+
+ Copyright (C) 2000-2006 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_CLIENT_H
+#define _TYPES_CLIENT_H
+
+/*
+ * FIXME: break this into HTTP state and TCP socket state.
+ * See server.h for the other end.
+ */
+
+/* different possible states for the client side */
+#define CL_STHEADERS 0
+#define CL_STDATA 1
+#define CL_STSHUTR 2
+#define CL_STSHUTW 3
+#define CL_STCLOSE 4
+
+
+#endif /* _TYPES_CLIENT_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/fd.h b/include/types/fd.h
new file mode 100644
index 0000000..6e350e5
--- /dev/null
+++ b/include/types/fd.h
@@ -0,0 +1,60 @@
+/*
+ include/fd.h
+ File descriptors states.
+
+ Copyright (C) 2000-2006 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_FD_H
+#define _TYPES_FD_H
+
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <haproxy/config.h>
+#include <types/task.h>
+
+/* different possible states for the fd */
+#define FD_STCLOSE 0
+#define FD_STLISTEN 1
+#define FD_STCONN 2
+#define FD_STREADY 3
+#define FD_STERROR 4
+
+
+/* info about one given fd */
+struct fdtab {
+ int (*read)(int fd); /* read function */
+ int (*write)(int fd); /* write function */
+ struct task *owner; /* the session (or proxy) associated with this fd */
+ int state; /* the state of this fd */
+};
+
+extern struct fdtab *fdtab; /* array of all the file descriptors */
+extern int maxfd; /* # of the highest fd + 1 */
+extern int totalconn; /* total # of terminated sessions */
+extern int actconn; /* # of active sessions */
+
+#endif /* _TYPES_FD_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/global.h b/include/types/global.h
new file mode 100644
index 0000000..4a2e895
--- /dev/null
+++ b/include/types/global.h
@@ -0,0 +1,75 @@
+/*
+ include/types/global.h
+ Global variables.
+
+ Copyright (C) 2000-2006 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_GLOBAL_H
+#define _TYPES_GLOBAL_H
+
+#include <netinet/in.h>
+
+#include <types/task.h>
+
+/* modes of operation (global.mode) */
+#define MODE_DEBUG 1
+#define MODE_STATS 2
+#define MODE_LOG 4
+#define MODE_DAEMON 8
+#define MODE_QUIET 16
+#define MODE_CHECK 32
+#define MODE_VERBOSE 64
+#define MODE_STARTING 128
+#define MODE_FOREGROUND 256
+
+
+/* FIXME : this will have to be redefined correctly */
+struct global {
+ int uid;
+ int gid;
+ int nbproc;
+ int maxconn;
+ int maxsock; /* max # of sockets */
+ int rlimit_nofile; /* default ulimit-n value : 0=unset */
+ int rlimit_memmax; /* default ulimit-d in megs value : 0=unset */
+ int mode;
+ char *chroot;
+ char *pidfile;
+ int logfac1, logfac2;
+ int loglev1, loglev2;
+ struct sockaddr_in logsrv1, logsrv2;
+};
+
+extern struct global global;
+extern char *progname; /* program name */
+extern int pid; /* current process id */
+extern int actconn; /* # of active sessions */
+extern int listeners;
+extern char trash[BUFSIZE];
+extern const int zero;
+extern const int one;
+extern int stopping; /* non zero means stopping in progress */
+
+#endif /* _TYPES_GLOBAL_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/httperr.h b/include/types/httperr.h
new file mode 100644
index 0000000..3a40a23
--- /dev/null
+++ b/include/types/httperr.h
@@ -0,0 +1,42 @@
+/*
+ include/types/httperr.h
+ This file defines everything related to HTTP responses and errors.
+
+ Copyright (C) 2000-2006 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_HTTPERR_H
+#define _TYPES_HTTPERR_H
+
+/* various data sources for the responses */
+#define DATA_SRC_NONE 0
+#define DATA_SRC_STATS 1
+
+/* data transmission states for the responses */
+#define DATA_ST_INIT 0
+#define DATA_ST_DATA 1
+
+
+
+#endif /* _TYPES_HTTPERR_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/log.h b/include/types/log.h
new file mode 100644
index 0000000..9aeb11e
--- /dev/null
+++ b/include/types/log.h
@@ -0,0 +1,56 @@
+/*
+ include/types/log.h
+ This file contains definitions of log-related structures and macros.
+
+ Copyright (C) 2000-2006 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_LOG_H
+#define _TYPES_LOG_H
+
+
+#define MAX_SYSLOG_LEN 1024
+#define NB_LOG_FACILITIES 24
+#define NB_LOG_LEVELS 8
+#define SYSLOG_PORT 514
+
+
+/* fields that need to be logged. They appear as flags in session->logs.logwait */
+#define LW_DATE 1 /* date */
+#define LW_CLIP 2 /* CLient IP */
+#define LW_SVIP 4 /* SerVer IP */
+#define LW_SVID 8 /* server ID */
+#define LW_REQ 16 /* http REQuest */
+#define LW_RESP 32 /* http RESPonse */
+#define LW_PXIP 64 /* proxy IP */
+#define LW_PXID 128 /* proxy ID */
+#define LW_BYTES 256 /* bytes read from server */
+#define LW_COOKIE 512 /* captured cookie */
+#define LW_REQHDR 1024 /* request header(s) */
+#define LW_RSPHDR 2048 /* response header(s) */
+
+extern void **pool_requri;
+
+
+#endif /* _TYPES_LOG_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/polling.h b/include/types/polling.h
new file mode 100644
index 0000000..3c2a231
--- /dev/null
+++ b/include/types/polling.h
@@ -0,0 +1,74 @@
+/*
+ include/types/polling.h
+ File descriptors and polling definitions.
+
+ Copyright (C) 2000-2006 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_POLLING_H
+#define _TYPES_POLLING_H
+
+/* for fd_set */
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <haproxy/config.h>
+
+/* for POLL_* */
+#if defined(ENABLE_POLL)
+#include <sys/poll.h>
+#endif
+
+/* for EPOLL_* */
+#if defined(ENABLE_EPOLL)
+#if !defined(USE_MY_EPOLL)
+#include <sys/epoll.h>
+#else
+#include <haproxy/epoll.h>
+#endif
+#endif
+
+/* possible actions for the *poll() loops */
+#define POLL_LOOP_ACTION_INIT 0
+#define POLL_LOOP_ACTION_RUN 1
+#define POLL_LOOP_ACTION_CLEAN 2
+
+/* poll mechanisms available */
+#define POLL_USE_SELECT (1<<0)
+#define POLL_USE_POLL (1<<1)
+#define POLL_USE_EPOLL (1<<2)
+
+/* result of an I/O event */
+#define RES_SILENT 0 /* didn't happen */
+#define RES_DATA 1 /* data were sent or received */
+#define RES_NULL 2 /* result is 0 (read == 0), or connect without need for writing */
+#define RES_ERROR 3 /* result -1 or error on the socket (eg: connect()) */
+
+/* fd states */
+extern fd_set *StaticReadEvent, *StaticWriteEvent;
+extern int cfg_polling_mechanism; /* POLL_USE_{SELECT|POLL|EPOLL} */
+
+
+#endif /* _TYPES_POLLING_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/proto_http.h b/include/types/proto_http.h
new file mode 100644
index 0000000..2ccee06
--- /dev/null
+++ b/include/types/proto_http.h
@@ -0,0 +1,60 @@
+/*
+ include/types/proto_http.h
+ This file contains HTTP protocol definitions.
+
+ Copyright (C) 2000-2006 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_PROTO_HTTP_H
+#define _TYPES_PROTO_HTTP_H
+
+
+/*
+ * FIXME: break this into HTTP state and TCP socket state.
+ * See server.h for the other end.
+ */
+
+/* different possible states for the client side */
+#define CL_STHEADERS 0
+#define CL_STDATA 1
+#define CL_STSHUTR 2
+#define CL_STSHUTW 3
+#define CL_STCLOSE 4
+
+/*
+ * FIXME: break this into HTTP state and TCP socket state.
+ * See client.h for the other end.
+ */
+
+/* different possible states for the server side */
+#define SV_STIDLE 0
+#define SV_STCONN 1
+#define SV_STHEADERS 2
+#define SV_STDATA 3
+#define SV_STSHUTR 4
+#define SV_STSHUTW 5
+#define SV_STCLOSE 6
+
+
+#endif /* _TYPES_PROTO_HTTP_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/proxy.h b/include/types/proxy.h
new file mode 100644
index 0000000..9685828
--- /dev/null
+++ b/include/types/proxy.h
@@ -0,0 +1,145 @@
+/*
+ include/types/proxy.h
+ This file defines everything related to proxies.
+
+ Copyright (C) 2000-2006 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_PROXY_H
+#define _TYPES_PROXY_H
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/socket.h>
+
+#include <haproxy/appsession.h>
+#include <haproxy/chtbl.h>
+#include <haproxy/mini-clist.h>
+#include <haproxy/regex.h>
+
+#include <types/buffers.h>
+#include <types/session.h>
+#include <types/server.h>
+
+/* values for proxy->state */
+#define PR_STNEW 0
+#define PR_STIDLE 1
+#define PR_STRUN 2
+#define PR_STSTOPPED 3
+#define PR_STPAUSED 4
+#define PR_STERROR 5
+
+/* values for proxy->mode */
+#define PR_MODE_TCP 0
+#define PR_MODE_HTTP 1
+#define PR_MODE_HEALTH 2
+
+/* return codes for start_proxies */
+#define ERR_NONE 0 /* no error */
+#define ERR_RETRYABLE 1 /* retryable error, may be cumulated */
+#define ERR_FATAL 2 /* fatal error, may be cumulated */
+
+
+struct listener {
+ int fd; /* the listen socket */
+ struct sockaddr_storage addr; /* the address we listen to */
+ struct listener *next; /* next address or NULL */
+};
+
+struct proxy {
+ struct listener *listen; /* the listen addresses and sockets */
+ struct in_addr mon_net, mon_mask; /* don't forward connections from this net (network order) FIXME: should support IPv6 */
+ int state; /* proxy state */
+ struct sockaddr_in dispatch_addr; /* the default address to connect to */
+ struct server *srv; /* known servers */
+ int srv_act, srv_bck; /* # of running servers */
+ int tot_wact, tot_wbck; /* total weights of active and backup servers */
+ struct server **srv_map; /* the server map used to apply weights */
+ int srv_map_sz; /* the size of the effective server map */
+ int srv_rr_idx; /* next server to be elected in round robin mode */
+ char *cookie_name; /* name of the cookie to look for */
+ int cookie_len; /* strlen(cookie_name), computed only once */
+ char *appsession_name; /* name of the cookie to look for */
+ int appsession_name_len; /* strlen(appsession_name), computed only once */
+ int appsession_len; /* length of the appsession cookie value to be used */
+ int appsession_timeout;
+ CHTbl htbl_proxy; /* Per Proxy hashtable */
+ char *capture_name; /* beginning of the name of the cookie to capture */
+ int capture_namelen; /* length of the cookie name to match */
+ int capture_len; /* length of the string to be captured */
+ struct uri_auth *uri_auth; /* if non-NULL, the (list of) per-URI authentications */
+ int clitimeout; /* client I/O timeout (in milliseconds) */
+ int srvtimeout; /* server I/O timeout (in milliseconds) */
+ int contimeout; /* connect timeout (in milliseconds) */
+ char *id; /* proxy id */
+ struct list pendconns; /* pending connections with no server assigned yet */
+ int nbpend, nbpend_max; /* number of pending connections with no server assigned yet */
+ int totpend; /* total number of pending connections on this instance (for stats) */
+ unsigned int nbconn, nbconn_max; /* # of active sessions */
+ unsigned int cum_conn; /* cumulated number of processed sessions */
+ unsigned int maxconn; /* max # of active sessions */
+ unsigned failed_conns, failed_resp; /* failed connect() and responses */
+ unsigned failed_secu; /* blocked responses because of security concerns */
+ int conn_retries; /* maximum number of connect retries */
+ int options; /* PR_O_REDISP, PR_O_TRANSP, ... */
+ int mode; /* mode = PR_MODE_TCP, PR_MODE_HTTP or PR_MODE_HEALTH */
+ struct sockaddr_in source_addr; /* the address to which we want to bind for connect() */
+ struct proxy *next;
+ struct sockaddr_in logsrv1, logsrv2; /* 2 syslog servers */
+ signed char logfac1, logfac2; /* log facility for both servers. -1 = disabled */
+ int loglev1, loglev2; /* log level for each server, 7 by default */
+ int to_log; /* things to be logged (LW_*) */
+ struct timeval stop_time; /* date to stop listening, when stopping != 0 */
+ int nb_reqadd, nb_rspadd;
+ struct hdr_exp *req_exp; /* regular expressions for request headers */
+ struct hdr_exp *rsp_exp; /* regular expressions for response headers */
+ int nb_req_cap, nb_rsp_cap; /* # of headers to be captured */
+ struct cap_hdr *req_cap; /* chained list of request headers to be captured */
+ struct cap_hdr *rsp_cap; /* chained list of response headers to be captured */
+ void *req_cap_pool, *rsp_cap_pool; /* pools of pre-allocated char ** used to build the sessions */
+ char *req_add[MAX_NEWHDR], *rsp_add[MAX_NEWHDR]; /* headers to be added */
+ int grace; /* grace time after stop request */
+ char *check_req; /* HTTP request to use if PR_O_HTTP_CHK is set, else NULL */
+ int check_len; /* Length of the HTTP request */
+ struct {
+ char *msg400; /* message for error 400 */
+ int len400; /* message length for error 400 */
+ char *msg403; /* message for error 403 */
+ int len403; /* message length for error 403 */
+ char *msg408; /* message for error 408 */
+ int len408; /* message length for error 408 */
+ char *msg500; /* message for error 500 */
+ int len500; /* message length for error 500 */
+ char *msg502; /* message for error 502 */
+ int len502; /* message length for error 502 */
+ char *msg503; /* message for error 503 */
+ int len503; /* message length for error 503 */
+ char *msg504; /* message for error 504 */
+ int len504; /* message length for error 504 */
+ } errmsg;
+};
+
+extern struct proxy *proxy;
+
+#endif /* _TYPES_PROXY_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/queue.h b/include/types/queue.h
new file mode 100644
index 0000000..d35fae9
--- /dev/null
+++ b/include/types/queue.h
@@ -0,0 +1,47 @@
+/*
+ include/types/queue.h
+ This file defines variables and structures needed for queues.
+
+ Copyright (C) 2000-2006 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_QUEUE_H
+#define _TYPES_QUEUE_H
+
+#include <haproxy/mini-clist.h>
+
+#include <types/server.h>
+#include <types/session.h>
+
+struct pendconn {
+ struct list list; /* chaining ... */
+ struct session *sess; /* the session waiting for a connection */
+ struct server *srv; /* the server we are waiting for */
+};
+
+#define sizeof_pendconn sizeof(struct pendconn)
+extern void **pool_pendconn;
+
+
+#endif /* _TYPES_QUEUE_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/server.h b/include/types/server.h
new file mode 100644
index 0000000..56a6b63
--- /dev/null
+++ b/include/types/server.h
@@ -0,0 +1,87 @@
+/*
+ include/types/server.h
+ This file defines everything related to servers.
+
+ Copyright (C) 2000-2006 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_SERVER_H
+#define _TYPES_SERVER_H
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <haproxy/mini-clist.h>
+
+#include <types/buffers.h>
+#include <types/proxy.h>
+#include <types/queue.h>
+#include <types/task.h>
+
+
+/* server flags */
+#define SRV_RUNNING 1 /* the server is UP */
+#define SRV_BACKUP 2 /* this server is a backup server */
+#define SRV_MAPPORTS 4 /* this server uses mapped ports */
+#define SRV_BIND_SRC 8 /* this server uses a specific source address */
+#define SRV_CHECKED 16 /* this server needs to be checked */
+
+/* function which act on servers need to return various errors */
+#define SRV_STATUS_OK 0 /* everything is OK. */
+#define SRV_STATUS_INTERNAL 1 /* other unrecoverable errors. */
+#define SRV_STATUS_NOSRV 2 /* no server is available */
+#define SRV_STATUS_FULL 3 /* the/all server(s) are saturated */
+#define SRV_STATUS_QUEUED 4 /* the/all server(s) are saturated but the connection was queued */
+
+
+struct server {
+ struct server *next;
+ int state; /* server state (SRV_*) */
+ int cklen; /* the len of the cookie, to speed up checks */
+ char *cookie; /* the id set in the cookie */
+ char *id; /* just for identification */
+ struct list pendconns; /* pending connections */
+ int nbpend, nbpend_max; /* number of pending connections */
+ struct task *queue_mgt; /* the task associated to the queue processing */
+ struct sockaddr_in addr; /* the address to connect to */
+ struct sockaddr_in source_addr; /* the address to which we want to bind for connect() */
+ short check_port; /* the port to use for the health checks */
+ int health; /* 0->rise-1 = bad; rise->rise+fall-1 = good */
+ int rise, fall; /* time in iterations */
+ int inter; /* time in milliseconds */
+ int result; /* 0 = connect OK, -1 = connect KO */
+ int curfd; /* file desc used for current test, or -1 if not in test */
+ unsigned char uweight, eweight; /* user-specified weight-1, and effective weight-1 */
+ unsigned int wscore; /* weight score, used during srv map computation */
+ int cur_sess, cur_sess_max; /* number of currently active sessions (including syn_sent) */
+ unsigned int cum_sess; /* cumulated number of sessions really sent to this server */
+ unsigned int maxconn, minconn; /* max # of active sessions (0 = unlimited), min# for dynamic limit. */
+ unsigned failed_checks, down_trans; /* failed checks and up-down transitions */
+ unsigned failed_conns, failed_resp; /* failed connect() and responses */
+ unsigned failed_secu; /* blocked responses because of security concerns */
+ struct proxy *proxy; /* the proxy this server belongs to */
+};
+
+
+#endif /* _TYPES_SERVER_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/session.h b/include/types/session.h
new file mode 100644
index 0000000..e2ae54d
--- /dev/null
+++ b/include/types/session.h
@@ -0,0 +1,166 @@
+/*
+ include/types/session.h
+ This file defines everything related to sessions.
+
+ Copyright (C) 2000-2006 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_SESSION_H
+#define _TYPES_SESSION_H
+
+
+#include <sys/time.h>
+#include <unistd.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <haproxy/mini-clist.h>
+
+#include <types/buffers.h>
+#include <types/proxy.h>
+#include <types/queue.h>
+#include <types/server.h>
+#include <types/task.h>
+
+
+/* various session flags, bits values 0x01 to 0x20 (shift 0) */
+#define SN_DIRECT 0x00000001 /* connection made on the server matching the client cookie */
+#define SN_CLDENY 0x00000002 /* a client header matches a deny regex */
+#define SN_CLALLOW 0x00000004 /* a client header matches an allow regex */
+#define SN_SVDENY 0x00000008 /* a server header matches a deny regex */
+#define SN_SVALLOW 0x00000010 /* a server header matches an allow regex */
+#define SN_POST 0x00000020 /* the request was an HTTP POST */
+
+/* session flags dedicated to cookies : bits values 0x40, 0x80 (0-3 shift 6) */
+#define SN_CK_NONE 0x00000000 /* this session had no cookie */
+#define SN_CK_INVALID 0x00000040 /* this session had a cookie which matches no server */
+#define SN_CK_DOWN 0x00000080 /* this session had cookie matching a down server */
+#define SN_CK_VALID 0x000000C0 /* this session had cookie matching a valid server */
+#define SN_CK_MASK 0x000000C0 /* mask to get this session's cookie flags */
+#define SN_CK_SHIFT 6 /* bit shift */
+
+/* session termination conditions, bits values 0x100 to 0x700 (0-7 shift 8) */
+#define SN_ERR_NONE 0x00000000
+#define SN_ERR_CLITO 0x00000100 /* client time-out */
+#define SN_ERR_CLICL 0x00000200 /* client closed (read/write error) */
+#define SN_ERR_SRVTO 0x00000300 /* server time-out, connect time-out */
+#define SN_ERR_SRVCL 0x00000400 /* server closed (connect/read/write error) */
+#define SN_ERR_PRXCOND 0x00000500 /* the proxy decided to close (deny...) */
+#define SN_ERR_RESOURCE 0x00000600 /* the proxy encountered a lack of a local resources (fd, mem, ...) */
+#define SN_ERR_INTERNAL 0x00000700 /* the proxy encountered an internal error */
+#define SN_ERR_MASK 0x00000700 /* mask to get only session error flags */
+#define SN_ERR_SHIFT 8 /* bit shift */
+
+/* session state at termination, bits values 0x1000 to 0x7000 (0-7 shift 12) */
+#define SN_FINST_R 0x00001000 /* session ended during client request */
+#define SN_FINST_C 0x00002000 /* session ended during server connect */
+#define SN_FINST_H 0x00003000 /* session ended during server headers */
+#define SN_FINST_D 0x00004000 /* session ended during data phase */
+#define SN_FINST_L 0x00005000 /* session ended while pushing last data to client */
+#define SN_FINST_Q 0x00006000 /* session ended while waiting in queue for a server slot */
+#define SN_FINST_MASK 0x00007000 /* mask to get only final session state flags */
+#define SN_FINST_SHIFT 12 /* bit shift */
+
+/* cookie information, bits values 0x10000 to 0x80000 (0-8 shift 16) */
+#define SN_SCK_NONE 0x00000000 /* no set-cookie seen for the server cookie */
+#define SN_SCK_DELETED 0x00010000 /* existing set-cookie deleted or changed */
+#define SN_SCK_INSERTED 0x00020000 /* new set-cookie inserted or changed existing one */
+#define SN_SCK_SEEN 0x00040000 /* set-cookie seen for the server cookie */
+#define SN_SCK_MASK 0x00070000 /* mask to get the set-cookie field */
+#define SN_SCK_ANY 0x00080000 /* at least one set-cookie seen (not to be counted) */
+#define SN_SCK_SHIFT 16 /* bit shift */
+
+/* cacheability management, bits values 0x100000 to 0x300000 (0-3 shift 20) */
+#define SN_CACHEABLE 0x00100000 /* at least part of the response is cacheable */
+#define SN_CACHE_COOK 0x00200000 /* a cookie in the response is cacheable */
+#define SN_CACHE_SHIFT 20 /* bit shift */
+
+/* various other session flags, bits values 0x400000 and above */
+#define SN_MONITOR 0x00400000 /* this session comes from a monitoring system */
+#define SN_ASSIGNED 0x00800000 /* no need to assign a server to this session */
+#define SN_ADDR_SET 0x01000000 /* this session's server address has been set */
+#define SN_SELF_GEN 0x02000000 /* the proxy generates data for the client (eg: stats) */
+
+
+/* WARNING: if new fields are added, they must be initialized in event_accept() */
+struct session {
+ struct task *task; /* the task associated with this session */
+ /* application specific below */
+ struct timeval crexpire; /* expiration date for a client read */
+ struct timeval cwexpire; /* expiration date for a client write */
+ struct timeval srexpire; /* expiration date for a server read */
+ struct timeval swexpire; /* expiration date for a server write */
+ struct timeval cnexpire; /* expiration date for a connect */
+ char res_cr, res_cw, res_sr, res_sw; /* results of some events */
+ struct proxy *proxy; /* the proxy this socket belongs to */
+ int cli_fd; /* the client side fd */
+ int srv_fd; /* the server side fd */
+ int cli_state; /* state of the client side */
+ int srv_state; /* state of the server side */
+ int conn_retries; /* number of connect retries left */
+ int flags; /* some flags describing the session */
+ struct buffer *req; /* request buffer */
+ struct buffer *rep; /* response buffer */
+ struct sockaddr_storage cli_addr; /* the client address */
+ struct sockaddr_in srv_addr; /* the address to connect to */
+ struct server *srv; /* the server being used */
+ struct pendconn *pend_pos; /* if not NULL, points to the position in the pending queue */
+ char **req_cap; /* array of captured request headers (may be NULL) */
+ char **rsp_cap; /* array of captured response headers (may be NULL) */
+ struct chunk req_line; /* points to first line */
+ struct chunk auth_hdr; /* points to 'Authorization:' header */
+ struct {
+ int logwait; /* log fields waiting to be collected : LW_* */
+ struct timeval tv_accept; /* date of the accept() (beginning of the session) */
+ long t_request; /* delay before the end of the request arrives, -1 if never occurs */
+ long t_queue; /* delay before the session gets out of the connect queue, -1 if never occurs */
+ long t_connect; /* delay before the connect() to the server succeeds, -1 if never occurs */
+ long t_data; /* delay before the first data byte from the server ... */
+ unsigned long t_close; /* total session duration */
+ unsigned long srv_queue_size; /* number of sessions waiting for a connect slot on this server at accept() time (in direct assignment) */
+ unsigned long prx_queue_size; /* overall number of sessions waiting for a connect slot on this instance at accept() time */
+ char *uri; /* first line if log needed, NULL otherwise */
+ char *cli_cookie; /* cookie presented by the client, in capture mode */
+ char *srv_cookie; /* cookie presented by the server, in capture mode */
+ int status; /* HTTP status from the server, negative if from proxy */
+ long long bytes; /* number of bytes transferred from the server */
+ } logs;
+ short int data_source; /* where to get the data we generate ourselves */
+ short int data_state; /* where to get the data we generate ourselves */
+ union {
+ struct {
+ struct proxy *px;
+ struct server *sv;
+ short px_st, sv_st; /* DATA_ST_INIT or DATA_ST_DATA */
+ } stats;
+ } data_ctx;
+ unsigned int uniq_id; /* unique ID used for the traces */
+};
+
+
+#define sizeof_session sizeof(struct session)
+extern void **pool_session;
+
+
+#endif /* _TYPES_SESSION_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/task.h b/include/types/task.h
new file mode 100644
index 0000000..560a2fc
--- /dev/null
+++ b/include/types/task.h
@@ -0,0 +1,58 @@
+/*
+ include/types/task.h
+ Macros, variables and structures for task management.
+
+ Copyright (C) 2000-2006 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_TASK_H
+#define _TYPES_TASK_H
+
+
+#include <sys/time.h>
+
+
+/* values for task->state */
+#define TASK_IDLE 0
+#define TASK_RUNNING 1
+
+/* The base for all tasks */
+struct task {
+ struct task *next, *prev; /* chaining ... */
+ struct task *rqnext; /* chaining in run queue ... */
+ struct task *wq; /* the wait queue this task is in */
+ int state; /* task state : IDLE or RUNNING */
+ struct timeval expire; /* next expiration time for this task, use only for fast sorting */
+ int (*process)(struct task *t); /* the function which processes the task */
+ void *context; /* the task's context */
+};
+
+#define sizeof_task sizeof(struct task)
+extern void **pool_task;
+
+extern struct task wait_queue[2];
+extern struct task *rq;
+
+
+#endif /* _TYPES_TASK_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/template.h b/include/types/template.h
new file mode 100644
index 0000000..8fa1ce5
--- /dev/null
+++ b/include/types/template.h
@@ -0,0 +1,33 @@
+/*
+ include/types/template.h
+ This file serves as a template for future include files.
+
+ Copyright (C) 2000-2006 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_TEMPLATE_H
+#define _TYPES_TEMPLATE_H
+
+
+#endif /* _TYPES_TEMPLATE_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */