blob: e0c695d1b3bbb33690ba451f6dd871bc8ed0f703 [file] [log] [blame]
Emeric Brun3e541d12012-09-03 11:14:36 +02001/*
2 * shctx.h - shared context management functions for SSL
3 *
4 * Copyright (C) 2011-2012 EXCELIANCE
5 *
6 * Author: Emeric Brun - emeric@exceliance.fr
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 */
13
14#ifndef SHCTX_H
15#define SHCTX_H
16#include <openssl/ssl.h>
17#include <stdint.h>
18
Emeric Brunaf9619d2012-11-28 18:47:52 +010019#ifndef SHSESS_BLOCK_MIN_SIZE
20#define SHSESS_BLOCK_MIN_SIZE 128
Emeric Brun3e541d12012-09-03 11:14:36 +020021#endif
22
23#ifndef SHSESS_MAX_DATA_LEN
Emeric Brunaf9619d2012-11-28 18:47:52 +010024#define SHSESS_MAX_DATA_LEN 4096
Emeric Brun3e541d12012-09-03 11:14:36 +020025#endif
26
Emeric Brun786991e2012-11-26 18:37:12 +010027#ifndef SHCTX_APPNAME
28#define SHCTX_APPNAME "haproxy"
29#endif
30
Emeric Bruncaa19cc2014-05-07 16:10:18 +020031#define SHCTX_E_ALLOC_CACHE -1
32#define SHCTX_E_INIT_LOCK -2
33
Emeric Brun3e541d12012-09-03 11:14:36 +020034/* Allocate shared memory context.
Emeric Brunaf9619d2012-11-28 18:47:52 +010035 * <size> is the number of allocated blocks into cache (default 128 bytes)
36 * A block is large enough to contain a classic session (without client cert)
Emeric Brun22890a12012-12-28 14:41:32 +010037 * If <size> is set less or equal to 0, ssl cache is disabled.
Emeric Brunaf9619d2012-11-28 18:47:52 +010038 * Set <use_shared_memory> to 1 to use a mapped shared memory instead
39 * of private. (ignored if compiled with USE_PRIVATE_CACHE=1).
40 * Returns: -1 on alloc failure, <size> if it performs context alloc,
41 * and 0 if cache is already allocated.
42 */
Emeric Brun4b3091e2012-09-24 15:48:52 +020043int shared_context_init(int size, int use_shared_memory);
Emeric Brun3e541d12012-09-03 11:14:36 +020044
45/* Set shared cache callbacks on an ssl context.
46 * Set session cache mode to server and disable openssl internal cache.
47 * Shared context MUST be firstly initialized */
48void shared_context_set_cache(SSL_CTX *ctx);
49
50#endif /* SHCTX_H */
51