1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*
* Copyright (C) 2012-2013 Tobias Brunner
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "ipsec_types.h"
ENUM(ipsec_mode_names, MODE_TRANSPORT, MODE_DROP,
"TRANSPORT",
"TUNNEL",
"BEET",
"PASS",
"DROP"
);
ENUM(policy_dir_names, POLICY_IN, POLICY_FWD,
"in",
"out",
"fwd"
);
ENUM(ipcomp_transform_names, IPCOMP_NONE, IPCOMP_LZJH,
"IPCOMP_NONE",
"IPCOMP_OUI",
"IPCOMP_DEFLATE",
"IPCOMP_LZS",
"IPCOMP_LZJH"
);
ENUM(hw_offload_names, HW_OFFLOAD_NO, HW_OFFLOAD_AUTO,
"no",
"yes",
"auto",
);
ENUM(dscp_copy_names, DSCP_COPY_OUT_ONLY, DSCP_COPY_NO,
"out",
"in",
"yes",
"no",
);
/*
* See header
*/
bool ipsec_sa_cfg_equals(ipsec_sa_cfg_t *a, ipsec_sa_cfg_t *b)
{
return a->mode == b->mode &&
a->reqid == b->reqid &&
a->policy_count == b->policy_count &&
a->esp.use == b->esp.use &&
a->esp.spi == b->esp.spi &&
a->ah.use == b->ah.use &&
a->ah.spi == b->ah.spi &&
a->ipcomp.transform == b->ipcomp.transform &&
a->ipcomp.cpi == b->ipcomp.cpi;
}
/*
* See header
*/
bool mark_from_string(const char *value, mark_op_t ops, mark_t *mark)
{
char *endptr;
if (!value)
{
return FALSE;
}
if (strcasepfx(value, "%unique"))
{
if (!(ops & MARK_OP_UNIQUE))
{
DBG1(DBG_APP, "unexpected use of %%unique mark", value);
return FALSE;
}
endptr = (char*)value + strlen("%unique");
if (strcasepfx(endptr, "-dir"))
{
mark->value = MARK_UNIQUE_DIR;
endptr += strlen("-dir");
}
else if (!*endptr || *endptr == '/')
{
mark->value = MARK_UNIQUE;
}
else
{
DBG1(DBG_APP, "invalid mark value: %s", value);
return FALSE;
}
}
else if (strcasepfx(value, "%same"))
{
if (!(ops & MARK_OP_SAME))
{
DBG1(DBG_APP, "unexpected use of %%same mark", value);
return FALSE;
}
endptr = (char*)value + strlen("%same");
if (!*endptr || *endptr == '/')
{
mark->value = MARK_SAME;
}
else
{
DBG1(DBG_APP, "invalid mark value: %s", value);
return FALSE;
}
}
else
{
mark->value = strtoul(value, &endptr, 0);
}
if (*endptr)
{
if (*endptr != '/')
{
DBG1(DBG_APP, "invalid mark value: %s", value);
return FALSE;
}
mark->mask = strtoul(endptr+1, &endptr, 0);
if (*endptr)
{
DBG1(DBG_LIB, "invalid mark mask: %s", endptr);
return FALSE;
}
}
else
{
mark->mask = 0xffffffff;
}
if (!MARK_IS_UNIQUE(mark->value))
{
/* apply the mask to ensure the value is in range */
mark->value &= mark->mask;
}
return TRUE;
}
|