]>
git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libstrongswan/ipsec/ipsec_types.c
2 * Copyright (C) 2012-2013 Tobias Brunner
4 * Copyright (C) secunet Security Networks AG
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>.
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
17 #include "ipsec_types.h"
19 ENUM(ipsec_mode_names
, MODE_TRANSPORT
, MODE_DROP
,
27 ENUM(policy_dir_names
, POLICY_IN
, POLICY_FWD
,
33 ENUM(ipcomp_transform_names
, IPCOMP_NONE
, IPCOMP_LZJH
,
41 ENUM(hw_offload_names
, HW_OFFLOAD_NO
, HW_OFFLOAD_AUTO
,
47 ENUM(dscp_copy_names
, DSCP_COPY_OUT_ONLY
, DSCP_COPY_NO
,
57 bool ipsec_sa_cfg_equals(ipsec_sa_cfg_t
*a
, ipsec_sa_cfg_t
*b
)
59 return a
->mode
== b
->mode
&&
60 a
->reqid
== b
->reqid
&&
61 a
->policy_count
== b
->policy_count
&&
62 a
->esp
.use
== b
->esp
.use
&&
63 a
->esp
.spi
== b
->esp
.spi
&&
64 a
->ah
.use
== b
->ah
.use
&&
65 a
->ah
.spi
== b
->ah
.spi
&&
66 a
->ipcomp
.transform
== b
->ipcomp
.transform
&&
67 a
->ipcomp
.cpi
== b
->ipcomp
.cpi
;
73 bool mark_from_string(const char *value
, mark_op_t ops
, mark_t
*mark
)
81 if (strcasepfx(value
, "%unique"))
83 if (!(ops
& MARK_OP_UNIQUE
))
85 DBG1(DBG_APP
, "unexpected use of %%unique mark", value
);
88 endptr
= (char*)value
+ strlen("%unique");
89 if (strcasepfx(endptr
, "-dir"))
91 mark
->value
= MARK_UNIQUE_DIR
;
92 endptr
+= strlen("-dir");
94 else if (!*endptr
|| *endptr
== '/')
96 mark
->value
= MARK_UNIQUE
;
100 DBG1(DBG_APP
, "invalid mark value: %s", value
);
104 else if (strcasepfx(value
, "%same"))
106 if (!(ops
& MARK_OP_SAME
))
108 DBG1(DBG_APP
, "unexpected use of %%same mark", value
);
111 endptr
= (char*)value
+ strlen("%same");
112 if (!*endptr
|| *endptr
== '/')
114 mark
->value
= MARK_SAME
;
118 DBG1(DBG_APP
, "invalid mark value: %s", value
);
124 mark
->value
= strtoul(value
, &endptr
, 0);
130 DBG1(DBG_APP
, "invalid mark value: %s", value
);
133 mark
->mask
= strtoul(endptr
+1, &endptr
, 0);
136 DBG1(DBG_LIB
, "invalid mark mask: %s", endptr
);
142 mark
->mask
= 0xffffffff;
144 if (!MARK_IS_UNIQUE(mark
->value
))
146 /* apply the mask to ensure the value is in range */
147 mark
->value
&= mark
->mask
;
153 * Described in header
155 bool if_id_from_string(const char *value
, uint32_t *if_id
)
163 if (strcasepfx(value
, "%unique"))
165 endptr
= (char*)value
+ strlen("%unique");
166 if (strcasepfx(endptr
, "-dir"))
168 *if_id
= IF_ID_UNIQUE_DIR
;
169 endptr
+= strlen("-dir");
173 *if_id
= IF_ID_UNIQUE
;
177 DBG1(DBG_APP
, "invalid interface ID: %s", value
);
183 *if_id
= strtoul(value
, &endptr
, 0);
187 DBG1(DBG_APP
, "invalid interface ID: %s", value
);
194 * Described in header
196 void allocate_unique_if_ids(uint32_t *in
, uint32_t *out
)
198 static refcount_t unique_if_id
= 0;
200 if (IF_ID_IS_UNIQUE(*in
) || IF_ID_IS_UNIQUE(*out
))
202 refcount_t if_id
= 0;
203 bool unique_dir
= *in
== IF_ID_UNIQUE_DIR
||
204 *out
== IF_ID_UNIQUE_DIR
;
208 if_id
= ref_get(&unique_if_id
);
210 if (IF_ID_IS_UNIQUE(*in
))
212 *in
= unique_dir
? ref_get(&unique_if_id
) : if_id
;
214 if (IF_ID_IS_UNIQUE(*out
))
216 *out
= unique_dir
? ref_get(&unique_if_id
) : if_id
;