Request limits from TKM on init
[strongswan.git] / src / charon-tkm / src / tkm / tkm.c
1 /*
2 * Copyright (C) 2012 Reto Buerki
3 * Copyright (C) 2012 Adrian-Ken Rueegsegger
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include <tkm/client.h>
18 #include <tkm/constants.h>
19
20 #include "tkm.h"
21
22 #define IKE_SOCKET "/tmp/tkm.rpc.ike"
23
24 typedef struct private_tkm_t private_tkm_t;
25
26 /**
27 * Private additions to tkm_t.
28 */
29 struct private_tkm_t {
30
31 /**
32 * Public members of tkm_t.
33 */
34 tkm_t public;
35 };
36
37 /**
38 * Single instance of tkm_t.
39 */
40 tkm_t *tkm = NULL;
41
42 /**
43 * Described in header.
44 */
45 bool tkm_init()
46 {
47 private_tkm_t *this;
48
49 active_requests_type max_requests;
50 nc_id_type nc;
51 dh_id_type dh;
52 cc_id_type cc;
53 ae_id_type ae;
54 isa_id_type isa;
55 esa_id_type esa;
56
57 /* initialize TKM client library */
58 tkmlib_init();
59 if (ike_init(IKE_SOCKET) != TKM_OK)
60 {
61 tkmlib_final();
62 return FALSE;
63 }
64
65 if (ike_tkm_reset() != TKM_OK)
66 {
67 tkmlib_final();
68 return FALSE;
69 }
70
71 /* get limits from tkm */
72 if (ike_tkm_limits(&max_requests, &nc, &dh, &cc, &ae, &isa, &esa) != TKM_OK)
73 {
74 tkmlib_final();
75 return FALSE;
76 }
77
78 INIT(this,
79 .public = {
80 .idmgr = tkm_id_manager_create(),
81 },
82 );
83 tkm = &this->public;
84
85 return TRUE;
86 }
87
88 /**
89 * Described in header.
90 */
91 void tkm_deinit()
92 {
93 if (!tkm)
94 {
95 return;
96 }
97 private_tkm_t *this = (private_tkm_t*)tkm;
98 this->public.idmgr->destroy(this->public.idmgr);
99
100 tkmlib_final();
101 free(this);
102 tkm = NULL;
103 }