Emeric Brun | 3e541d1 | 2012-09-03 11:14:36 +0200 | [diff] [blame] | 1 | /* |
| 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 Brun | af9619d | 2012-11-28 18:47:52 +0100 | [diff] [blame] | 19 | #ifndef SHSESS_BLOCK_MIN_SIZE |
| 20 | #define SHSESS_BLOCK_MIN_SIZE 128 |
Emeric Brun | 3e541d1 | 2012-09-03 11:14:36 +0200 | [diff] [blame] | 21 | #endif |
| 22 | |
| 23 | #ifndef SHSESS_MAX_DATA_LEN |
Emeric Brun | af9619d | 2012-11-28 18:47:52 +0100 | [diff] [blame] | 24 | #define SHSESS_MAX_DATA_LEN 4096 |
Emeric Brun | 3e541d1 | 2012-09-03 11:14:36 +0200 | [diff] [blame] | 25 | #endif |
| 26 | |
Emeric Brun | 786991e | 2012-11-26 18:37:12 +0100 | [diff] [blame] | 27 | #ifndef SHCTX_APPNAME |
| 28 | #define SHCTX_APPNAME "haproxy" |
| 29 | #endif |
| 30 | |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 31 | #define SHCTX_E_ALLOC_CACHE -1 |
| 32 | #define SHCTX_E_INIT_LOCK -2 |
| 33 | |
Emeric Brun | 3e541d1 | 2012-09-03 11:14:36 +0200 | [diff] [blame] | 34 | /* Allocate shared memory context. |
Emeric Brun | af9619d | 2012-11-28 18:47:52 +0100 | [diff] [blame] | 35 | * <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 Brun | 22890a1 | 2012-12-28 14:41:32 +0100 | [diff] [blame] | 37 | * If <size> is set less or equal to 0, ssl cache is disabled. |
Emeric Brun | af9619d | 2012-11-28 18:47:52 +0100 | [diff] [blame] | 38 | * 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 Brun | 4b3091e | 2012-09-24 15:48:52 +0200 | [diff] [blame] | 43 | int shared_context_init(int size, int use_shared_memory); |
Emeric Brun | 3e541d1 | 2012-09-03 11:14:36 +0200 | [diff] [blame] | 44 | |
| 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 */ |
| 48 | void shared_context_set_cache(SSL_CTX *ctx); |
| 49 | |
| 50 | #endif /* SHCTX_H */ |
| 51 | |