]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libstrongswan/ipsec/ipsec_types.h
Merge branch 'fwmarks'
[thirdparty/strongswan.git] / src / libstrongswan / ipsec / ipsec_types.h
1 /*
2 * Copyright (C) 2012-2013 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup ipsec_types ipsec_types
18 * @{ @ingroup ipsec
19 */
20
21 #ifndef IPSEC_TYPES_H_
22 #define IPSEC_TYPES_H_
23
24 typedef enum ipsec_mode_t ipsec_mode_t;
25 typedef enum policy_dir_t policy_dir_t;
26 typedef enum policy_type_t policy_type_t;
27 typedef enum policy_priority_t policy_priority_t;
28 typedef enum ipcomp_transform_t ipcomp_transform_t;
29 typedef struct ipsec_sa_cfg_t ipsec_sa_cfg_t;
30 typedef struct lifetime_cfg_t lifetime_cfg_t;
31 typedef struct mark_t mark_t;
32
33 #include <library.h>
34
35 /**
36 * Mode of an IPsec SA.
37 */
38 enum ipsec_mode_t {
39 /** not using any encapsulation */
40 MODE_NONE = 0,
41 /** transport mode, no inner address */
42 MODE_TRANSPORT = 1,
43 /** tunnel mode, inner and outer addresses */
44 MODE_TUNNEL,
45 /** BEET mode, tunnel mode but fixed, bound inner addresses */
46 MODE_BEET,
47 /** passthrough policy for traffic without an IPsec SA */
48 MODE_PASS,
49 /** drop policy discarding traffic */
50 MODE_DROP
51 };
52
53 /**
54 * enum names for ipsec_mode_t.
55 */
56 extern enum_name_t *ipsec_mode_names;
57
58 /**
59 * Direction of a policy. These are equal to those
60 * defined in xfrm.h, but we want to stay implementation
61 * neutral here.
62 */
63 enum policy_dir_t {
64 /** Policy for inbound traffic */
65 POLICY_IN = 0,
66 /** Policy for outbound traffic */
67 POLICY_OUT = 1,
68 /** Policy for forwarded traffic */
69 POLICY_FWD = 2,
70 };
71
72 /**
73 * enum names for policy_dir_t.
74 */
75 extern enum_name_t *policy_dir_names;
76
77 /**
78 * Type of a policy.
79 */
80 enum policy_type_t {
81 /** Normal IPsec policy */
82 POLICY_IPSEC = 1,
83 /** Passthrough policy (traffic is ignored by IPsec) */
84 POLICY_PASS,
85 /** Drop policy (traffic is discarded) */
86 POLICY_DROP,
87 };
88
89 /**
90 * High-level priority of a policy.
91 */
92 enum policy_priority_t {
93 /** Default priority */
94 POLICY_PRIORITY_DEFAULT,
95 /** Priority for trap policies */
96 POLICY_PRIORITY_ROUTED,
97 /** Priority for fallback drop policies */
98 POLICY_PRIORITY_FALLBACK,
99 };
100
101 /**
102 * IPComp transform IDs, as in RFC 4306
103 */
104 enum ipcomp_transform_t {
105 IPCOMP_NONE = 0,
106 IPCOMP_OUI = 1,
107 IPCOMP_DEFLATE = 2,
108 IPCOMP_LZS = 3,
109 IPCOMP_LZJH = 4,
110 };
111
112 /**
113 * enum strings for ipcomp_transform_t.
114 */
115 extern enum_name_t *ipcomp_transform_names;
116
117 /**
118 * This struct contains details about IPsec SA(s) tied to a policy.
119 */
120 struct ipsec_sa_cfg_t {
121 /** mode of SA (tunnel, transport) */
122 ipsec_mode_t mode;
123 /** unique ID */
124 u_int32_t reqid;
125 /** details about ESP/AH */
126 struct {
127 /** TRUE if this protocol is used */
128 bool use;
129 /** SPI for ESP/AH */
130 u_int32_t spi;
131 } esp, ah;
132 /** details about IPComp */
133 struct {
134 /** the IPComp transform used */
135 u_int16_t transform;
136 /** CPI for IPComp */
137 u_int16_t cpi;
138 } ipcomp;
139 };
140
141 /**
142 * A lifetime_cfg_t defines the lifetime limits of an SA.
143 *
144 * Set any of these values to 0 to ignore.
145 */
146 struct lifetime_cfg_t {
147 struct {
148 /** Limit before the SA gets invalid. */
149 u_int64_t life;
150 /** Limit before the SA gets rekeyed. */
151 u_int64_t rekey;
152 /** The range of a random value subtracted from rekey. */
153 u_int64_t jitter;
154 } time, bytes, packets;
155 };
156
157 /**
158 * A mark_t defines an optional mark in an IPsec SA.
159 */
160 struct mark_t {
161 /** Mark value */
162 u_int32_t value;
163 /** Mark mask */
164 u_int32_t mask;
165 };
166
167 /**
168 * Special mark value that uses the reqid of the CHILD_SA as mark
169 */
170 #define MARK_REQID (0xFFFFFFFF)
171
172 /**
173 * Try to parse a mark_t from the given string of the form <mark>[/<mask>].
174 *
175 * @param value string to parse
176 * @param mark mark to fill
177 * @return TRUE if parsing was successful
178 */
179 bool mark_from_string(const char *value, mark_t *mark);
180
181 #endif /** IPSEC_TYPES_H_ @}*/