From b1ec8c4a593e73c254b2709f338cf610ef9d3003 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 3 Apr 2015 13:53:24 +0200 Subject: [PATCH] MINOR: session: start to reintroduce struct session There is now a pointer to the session in the stream, which is NULL for now. The session pool is created as well. Some parts will move from the stream to the session now. --- Makefile | 2 +- include/proto/session.h | 43 ++++++++++++++++++++++++++++++++++++ include/proto/stream.h | 6 ++++++ include/types/session.h | 48 +++++++++++++++++++++++++++++++++++++++++ include/types/stream.h | 3 +++ src/haproxy.c | 2 ++ src/hlua.c | 1 + src/peers.c | 1 + src/session.c | 35 ++++++++++++++++++++++++++++++ src/stream.c | 1 + 10 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 include/proto/session.h create mode 100644 include/types/session.h create mode 100644 src/session.c diff --git a/Makefile b/Makefile index 2f8c2eb06..917f023f6 100644 --- a/Makefile +++ b/Makefile @@ -704,7 +704,7 @@ OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocol.o \ src/proto_http.o src/raw_sock.o src/appsession.o src/backend.o \ src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o src/lb_fas.o \ src/stream_interface.o src/dumpstats.o src/proto_tcp.o \ - src/stream.o src/hdr_idx.o src/ev_select.o src/signal.o \ + src/session.o src/stream.o src/hdr_idx.o src/ev_select.o src/signal.o \ src/acl.o src/sample.o src/memory.o src/freq_ctr.o src/auth.o \ src/compression.o src/payload.o src/hash.o src/pattern.o src/map.o \ src/namespace.o src/mailers.o diff --git a/include/proto/session.h b/include/proto/session.h new file mode 100644 index 000000000..79589d391 --- /dev/null +++ b/include/proto/session.h @@ -0,0 +1,43 @@ +/* + * include/proto/session.h + * This file defines everything related to sessions. + * + * Copyright (C) 2000-2015 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_SESSION_H +#define _PROTO_SESSION_H + +#include +#include +#include +#include + +#include +#include + +extern struct pool_head *pool2_session; +int init_session(); + +#endif /* _PROTO_SESSION_H */ + +/* + * Local variables: + * c-indent-level: 8 + * c-basic-offset: 8 + * End: + */ diff --git a/include/proto/stream.h b/include/proto/stream.h index ba2c94367..4d234703a 100644 --- a/include/proto/stream.h +++ b/include/proto/stream.h @@ -62,6 +62,12 @@ int stream_alloc_work_buffer(struct stream *s); void stream_release_buffers(struct stream *s); int stream_alloc_recv_buffer(struct channel *chn); +/* returns the session this stream belongs to */ +static inline struct session *strm_sess(const struct stream *strm) +{ + return strm->sess; +} + /* sets the stick counter's entry pointer */ static inline void stkctr_set_entry(struct stkctr *stkctr, struct stksess *entry) { diff --git a/include/types/session.h b/include/types/session.h new file mode 100644 index 000000000..c07b46ac7 --- /dev/null +++ b/include/types/session.h @@ -0,0 +1,48 @@ +/* + * include/types/session.h + * This file defines everything related to sessions. + * + * Copyright (C) 2000-2015 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 +#include +#include +#include + +#include +#include + +#include +#include +#include + +struct session { +}; + +#endif /* _TYPES_SESSION_H */ + +/* + * Local variables: + * c-indent-level: 8 + * c-basic-offset: 8 + * End: + */ diff --git a/include/types/stream.h b/include/types/stream.h index c8c244547..469edc7e0 100644 --- a/include/types/stream.h +++ b/include/types/stream.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -119,6 +120,8 @@ struct stream { struct proxy *fe; /* the proxy this stream depends on for the client side */ struct proxy *be; /* the proxy this stream depends on for the server side */ + struct session *sess; /* the session this stream is attached to */ + struct listener *listener; /* the listener by which the request arrived */ struct server *srv_conn; /* stream already has a slot on a server and is not in queue */ struct pendconn *pend_pos; /* if not NULL, points to the position in the pending queue */ diff --git a/src/haproxy.c b/src/haproxy.c index 11b781038..591bb96e6 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -97,6 +97,7 @@ #include #include #include +#include #include #include #include @@ -560,6 +561,7 @@ void init(int argc, char **argv) exit(1); init_task(); init_stream(); + init_session(); init_connection(); /* warning, we init buffers later */ init_pendconn(); diff --git a/src/hlua.c b/src/hlua.c index a13b8ce1d..cdbce0043 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -2127,6 +2127,7 @@ __LJMP static int hlua_socket_new(lua_State *L) /* The stream dont have listener. The listener is used with real * proxies. */ + socket->s->sess = NULL; socket->s->listener = NULL; /* The flags are initialized to 0. Values are setted later. */ diff --git a/src/peers.c b/src/peers.c index 6df3ce7a6..0a66010dc 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1144,6 +1144,7 @@ static struct stream *peer_session_create(struct peer *peer, struct peer_session s->task = t; s->listener = l; + s->sess = NULL; /* Note: initially, the stream's backend points to the frontend. * This changes later when switching rules are executed or diff --git a/src/session.c b/src/session.c new file mode 100644 index 000000000..116816fbd --- /dev/null +++ b/src/session.c @@ -0,0 +1,35 @@ +/* + * Stream management functions. + * + * Copyright 2000-2012 Willy Tarreau + * + * 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 +#include +#include +#include + +#include +#include + +struct pool_head *pool2_session; + +/* perform minimal intializations, report 0 in case of error, 1 if OK. */ +int init_session() +{ + pool2_session = create_pool("session", sizeof(struct session), MEM_F_SHARED); + return pool2_session != NULL; +} + +/* + * Local variables: + * c-indent-level: 8 + * c-basic-offset: 8 + * End: + */ diff --git a/src/stream.c b/src/stream.c index 3bc337ea4..aaea9c08c 100644 --- a/src/stream.c +++ b/src/stream.c @@ -116,6 +116,7 @@ int stream_accept(struct listener *l, int cfd, struct sockaddr_storage *addr) memset(s->stkctr, 0, sizeof(s->stkctr)); + s->sess = NULL; s->listener = l; s->fe = p;