2 * Copyright (C) 2012-2013 Tobias Brunner
3 * HSR 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
16 #include "ipsec_types.h"
18 ENUM(ipsec_mode_names
, MODE_TRANSPORT
, MODE_DROP
,
26 ENUM(policy_dir_names
, POLICY_IN
, POLICY_FWD
,
32 ENUM(ipcomp_transform_names
, IPCOMP_NONE
, IPCOMP_LZJH
,
40 ENUM(hw_offload_names
, HW_OFFLOAD_NO
, HW_OFFLOAD_AUTO
,
46 ENUM(dscp_copy_names
, DSCP_COPY_OUT_ONLY
, DSCP_COPY_NO
,
56 bool ipsec_sa_cfg_equals(ipsec_sa_cfg_t
*a
, ipsec_sa_cfg_t
*b
)
58 return a
->mode
== b
->mode
&&
59 a
->reqid
== b
->reqid
&&
60 a
->policy_count
== b
->policy_count
&&
61 a
->esp
.use
== b
->esp
.use
&&
62 a
->esp
.spi
== b
->esp
.spi
&&
63 a
->ah
.use
== b
->ah
.use
&&
64 a
->ah
.spi
== b
->ah
.spi
&&
65 a
->ipcomp
.transform
== b
->ipcomp
.transform
&&
66 a
->ipcomp
.cpi
== b
->ipcomp
.cpi
;
72 bool mark_from_string(const char *value
, mark_t
*mark
)
80 if (strcasepfx(value
, "%unique"))
82 endptr
= (char*)value
+ strlen("%unique");
83 if (strcasepfx(endptr
, "-dir"))
85 mark
->value
= MARK_UNIQUE_DIR
;
86 endptr
+= strlen("-dir");
88 else if (!*endptr
|| *endptr
== '/')
90 mark
->value
= MARK_UNIQUE
;
94 DBG1(DBG_APP
, "invalid mark value: %s", value
);
100 mark
->value
= strtoul(value
, &endptr
, 0);
106 DBG1(DBG_APP
, "invalid mark value: %s", value
);
109 mark
->mask
= strtoul(endptr
+1, &endptr
, 0);
112 DBG1(DBG_LIB
, "invalid mark mask: %s", endptr
);
118 mark
->mask
= 0xffffffff;
120 if (!MARK_IS_UNIQUE(mark
->value
))
122 /* apply the mask to ensure the value is in range */
123 mark
->value
&= mark
->mask
;