2 * Copyright (C) 2012-2013 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
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>.
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
17 * @defgroup ipsec_types ipsec_types
21 #ifndef IPSEC_TYPES_H_
22 #define IPSEC_TYPES_H_
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 enum hw_offload_t hw_offload_t
;
30 typedef struct ipsec_sa_cfg_t ipsec_sa_cfg_t
;
31 typedef struct lifetime_cfg_t lifetime_cfg_t
;
32 typedef struct mark_t mark_t
;
37 * Mode of an IPsec SA.
40 /** not using any encapsulation */
42 /** transport mode, no inner address */
44 /** tunnel mode, inner and outer addresses */
46 /** BEET mode, tunnel mode but fixed, bound inner addresses */
48 /** passthrough policy for traffic without an IPsec SA */
50 /** drop policy discarding traffic */
55 * enum names for ipsec_mode_t.
57 extern enum_name_t
*ipsec_mode_names
;
60 * Direction of a policy. These are equal to those
61 * defined in xfrm.h, but we want to stay implementation
65 /** Policy for inbound traffic */
67 /** Policy for outbound traffic */
69 /** Policy for forwarded traffic */
74 * enum names for policy_dir_t.
76 extern enum_name_t
*policy_dir_names
;
82 /** Normal IPsec policy */
84 /** Passthrough policy (traffic is ignored by IPsec) */
86 /** Drop policy (traffic is discarded) */
91 * High-level priority of a policy.
93 enum policy_priority_t
{
94 /** Priority for passthrough policies */
96 /** Priority for regular IPsec policies */
97 POLICY_PRIORITY_DEFAULT
,
98 /** Priority for trap policies */
99 POLICY_PRIORITY_ROUTED
,
100 /** Priority for fallback drop policies */
101 POLICY_PRIORITY_FALLBACK
,
105 * IPComp transform IDs, as in RFC 4306
107 enum ipcomp_transform_t
{
116 * enum strings for ipcomp_transform_t.
118 extern enum_name_t
*ipcomp_transform_names
;
121 * HW offload mode options
130 * enum names for hw_offload_t.
132 extern enum_name_t
*hw_offload_names
;
135 * This struct contains details about IPsec SA(s) tied to a policy.
137 struct ipsec_sa_cfg_t
{
138 /** mode of SA (tunnel, transport) */
142 /** number of policies of the same kind (in/out/fwd) attached to SA */
143 uint32_t policy_count
;
144 /** details about ESP/AH */
146 /** TRUE if this protocol is used */
148 /** SPI for ESP/AH */
151 /** details about IPComp */
153 /** the IPComp transform used */
155 /** CPI for IPComp */
161 * Compare two ipsec_sa_cfg_t objects for equality.
163 * @param a first object
164 * @param b second object
165 * @return TRUE if both objects are equal
167 bool ipsec_sa_cfg_equals(ipsec_sa_cfg_t
*a
, ipsec_sa_cfg_t
*b
);
170 * A lifetime_cfg_t defines the lifetime limits of an SA.
172 * Set any of these values to 0 to ignore.
174 struct lifetime_cfg_t
{
176 /** Limit before the SA gets invalid. */
178 /** Limit before the SA gets rekeyed. */
180 /** The range of a random value subtracted from rekey. */
182 } time
, bytes
, packets
;
186 * A mark_t defines an optional mark in an IPsec SA.
196 * Special mark value that uses a unique mark for each CHILD_SA (and direction)
198 #define MARK_UNIQUE (0xFFFFFFFF)
199 #define MARK_UNIQUE_DIR (0xFFFFFFFE)
200 #define MARK_IS_UNIQUE(m) ((m) == MARK_UNIQUE || (m) == MARK_UNIQUE_DIR)
203 * Try to parse a mark_t from the given string of the form mark[/mask].
205 * @param value string to parse
206 * @param mark mark to fill
207 * @return TRUE if parsing was successful
209 bool mark_from_string(const char *value
, mark_t
*mark
);
211 #endif /** IPSEC_TYPES_H_ @}*/