Various stylistic fixes
[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 <daemon.h>
18
19 #include <tkm/client.h>
20 #include <tkm/constants.h>
21
22 #include "tkm.h"
23
24 #define IKE_SOCKET "/tmp/tkm.rpc.ike"
25 #define EES_SOCKET "/tmp/tkm.rpc.ees"
26
27 typedef struct private_tkm_t private_tkm_t;
28
29 extern result_type ees_server_init(const char * const address);
30 extern void ees_server_finalize(void);
31 extern void ehandler_init(void);
32
33 /*
34 * Private additions to tkm_t.
35 */
36 struct private_tkm_t {
37
38 /**
39 * Public members of tkm_t.
40 */
41 tkm_t public;
42 };
43
44 /**
45 * Single instance of tkm_t.
46 */
47 tkm_t *tkm = NULL;
48
49 /**
50 * Described in header.
51 */
52 bool tkm_init()
53 {
54 private_tkm_t *this;
55 active_requests_type max_requests;
56 char *ikesock, *eessock;
57 tkm_limits_t limits;
58
59 /* initialize TKM client library */
60 tkmlib_init();
61 ehandler_init();
62
63 ikesock = lib->settings->get_str(lib->settings, "%s.ike_socket", IKE_SOCKET,
64 charon->name);
65 if (ike_init(ikesock) != TKM_OK)
66 {
67 tkmlib_final();
68 return FALSE;
69 }
70 DBG1(DBG_DMN, "connected to TKM via socket '%s'", ikesock);
71
72 eessock = lib->settings->get_str(lib->settings, "%s.ees_socket", EES_SOCKET,
73 charon->name);
74 ees_server_init(eessock);
75 DBG1(DBG_DMN, "serving EES requests on socket '%s'", eessock);
76
77 if (ike_tkm_reset() != TKM_OK)
78 {
79 ees_server_finalize();
80 tkmlib_final();
81 return FALSE;
82 }
83
84 /* get limits from tkm */
85 if (ike_tkm_limits(&max_requests, &limits[TKM_CTX_NONCE], &limits[TKM_CTX_DH],
86 &limits[TKM_CTX_CC], &limits[TKM_CTX_AE],
87 &limits[TKM_CTX_ISA], &limits[TKM_CTX_ESA]) != TKM_OK)
88 {
89 ees_server_finalize();
90 tkmlib_final();
91 return FALSE;
92 }
93
94 INIT(this,
95 .public = {
96 .idmgr = tkm_id_manager_create(limits),
97 .chunk_map = tkm_chunk_map_create(),
98 },
99 );
100 tkm = &this->public;
101
102 return TRUE;
103 }
104
105 /**
106 * Described in header.
107 */
108 void tkm_deinit()
109 {
110 if (!tkm)
111 {
112 return;
113 }
114 private_tkm_t *this = (private_tkm_t*)tkm;
115 this->public.idmgr->destroy(this->public.idmgr);
116 this->public.chunk_map->destroy(this->public.chunk_map);
117
118 ees_server_finalize();
119
120 tkmlib_final();
121 free(this);
122 tkm = NULL;
123 }