63bf17fbfc82fa041dbe15d17e7ca9910056ed92
[strongswan.git] / src / libcharon / sa / trap_manager.h
1 /*
2 * Copyright (C) 2013-2017 Tobias Brunner
3 * Copyright (C) 2009 Martin Willi
4 * HSR 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 /**
18 * @defgroup trap_manager trap_manager
19 * @{ @ingroup sa
20 */
21
22 #ifndef TRAP_MANAGER_H_
23 #define TRAP_MANAGER_H_
24
25 #include <library.h>
26 #include <collections/enumerator.h>
27 #include <config/peer_cfg.h>
28
29 typedef struct trap_manager_t trap_manager_t;
30
31 /**
32 * Manage policies to create SAs from traffic.
33 */
34 struct trap_manager_t {
35
36 /**
37 * Install a policy as a trap.
38 *
39 * @param peer peer configuration to initiate on trap
40 * @param child child configuration to install as a trap
41 * @return TRUE if successfully installed
42 */
43 bool (*install)(trap_manager_t *this, peer_cfg_t *peer, child_cfg_t *child);
44
45 /**
46 * Uninstall a trap policy.
47 *
48 * If no peer configuration name is given the first matching child
49 * configuration is uninstalled.
50 *
51 * @param peer peer configuration name or NULL
52 * @param child child configuration name
53 * @return TRUE if uninstalled successfully
54 */
55 bool (*uninstall)(trap_manager_t *this, char *peer, char *child);
56
57 /**
58 * Create an enumerator over all installed traps.
59 *
60 * @return enumerator over (peer_cfg_t, child_sa_t)
61 */
62 enumerator_t* (*create_enumerator)(trap_manager_t *this);
63
64 /**
65 * Find the reqid of a child config installed as a trap.
66 *
67 * @param child CHILD_SA config to get the reqid for
68 * @return reqid of trap, 0 if not found
69 */
70 uint32_t (*find_reqid)(trap_manager_t *this, child_cfg_t *child);
71
72 /**
73 * Acquire an SA triggered by an installed trap.
74 *
75 * @param reqid requid of the triggering CHILD_SA
76 * @param src source of the triggering packet
77 * @param dst destination of the triggering packet
78 */
79 void (*acquire)(trap_manager_t *this, uint32_t reqid,
80 traffic_selector_t *src, traffic_selector_t *dst);
81
82 /**
83 * Clear any installed trap.
84 */
85 void (*flush)(trap_manager_t *this);
86
87 /**
88 * Destroy a trap_manager_t.
89 */
90 void (*destroy)(trap_manager_t *this);
91 };
92
93 /**
94 * Create a trap_manager instance.
95 */
96 trap_manager_t *trap_manager_create();
97
98 #endif /** TRAP_MANAGER_H_ @}*/