1 |
786 |
skrzyp |
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
libipsec Reference
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
ipsec_set_policy
|
13 |
|
|
|
14 |
|
|
IPSEC_SET_POLICY(3) System Library Functions Manual IPSEC_SET_POLICY(3)
|
15 |
|
|
|
16 |
|
|
NAME
|
17 |
|
|
ipsec_set_policy, ipsec_get_policylen, ipsec_dump_policy - manipulate
|
18 |
|
|
IPsec policy specification structure from readable string
|
19 |
|
|
|
20 |
|
|
LIBRARY
|
21 |
|
|
IPsec Policy Control Library (libipsec, -lipsec)
|
22 |
|
|
|
23 |
|
|
SYNOPSIS
|
24 |
|
|
#include <netinet6/ipsec.h>
|
25 |
|
|
|
26 |
|
|
char *
|
27 |
|
|
ipsec_set_policy(char *policy, int len);
|
28 |
|
|
|
29 |
|
|
int
|
30 |
|
|
ipsec_get_policylen(char *buf);
|
31 |
|
|
|
32 |
|
|
char *
|
33 |
|
|
ipsec_dump_policy(char *buf, char *delim);
|
34 |
|
|
|
35 |
|
|
DESCRIPTION
|
36 |
|
|
ipsec_set_policy() generates IPsec policy specification structure, namely
|
37 |
|
|
struct sadb_x_policy and/or struct sadb_x_ipsecrequest from human-read-
|
38 |
|
|
able policy specification. policy specification must be given as C
|
39 |
|
|
string policy and length len of policy. ipsec_set_policy() will return
|
40 |
|
|
the buffer of IPsec policy specification structure. The buffer is dynam-
|
41 |
|
|
ically allocated, and must be freed by the caller by calling free(3).
|
42 |
|
|
|
43 |
|
|
You may want the length of the generated buffer such when calling
|
44 |
|
|
setsockopt(2). ipsec_get_policylen() will return the length.
|
45 |
|
|
|
46 |
|
|
ipsec_dump_policy() converts IPsec policy structure into readable form.
|
47 |
|
|
Therefore, ipsec_dump_policy() can be regarded as inverse conversion of
|
48 |
|
|
ipsec_set_policy(). buf points to a IPsec policy structure, struct
|
49 |
|
|
sadb_x_policy. delim is a delimiter string, which is usually a blank
|
50 |
|
|
character. If you set delim to NULL, single whitespace is assumed.
|
51 |
|
|
ipsec_dump_policy() returns pointer to dynamically allocated string. It
|
52 |
|
|
is caller's responsibility to reclaim the region, by using free(3).
|
53 |
|
|
|
54 |
|
|
policy is formatted as either of the following:
|
55 |
|
|
|
56 |
|
|
direction discard
|
57 |
|
|
direction must be in or out. direction specifies which direc-
|
58 |
|
|
tion the policy needs to be applied. With discard policy, pack-
|
59 |
|
|
ets will be dropped if they match the policy.
|
60 |
|
|
|
61 |
|
|
direction entrust
|
62 |
|
|
entrust means to consult to SPD defined by setkey(8).
|
63 |
|
|
|
64 |
|
|
direction bypass
|
65 |
|
|
bypass means to be bypassed the IPsec processing. (packet will
|
66 |
|
|
be transmitted in clear). This is for privileged socket.
|
67 |
|
|
|
68 |
|
|
direction ipsec request ...
|
69 |
|
|
ipsec means that the matching packets are subject to IPsec pro-
|
70 |
|
|
cessing. ipsec can be followed by one or more request string,
|
71 |
|
|
which is formatted as below:
|
72 |
|
|
|
73 |
|
|
protocol / mode / src - dst [/level]
|
74 |
|
|
protocol is either ah, esp or ipcomp.
|
75 |
|
|
|
76 |
|
|
mode is either transport or tunnel.
|
77 |
|
|
|
78 |
|
|
src and dst specifies IPsec endpoint. src always means
|
79 |
|
|
``sending node'' and dst always means ``receiving
|
80 |
|
|
node''. Therefore, when direction is in, dst is this
|
81 |
|
|
node and src is the other node (peer). If mode is
|
82 |
|
|
transport, Both src and dst can be omited.
|
83 |
|
|
|
84 |
|
|
level must be set to one of the following: default,
|
85 |
|
|
use, require or unique. default means that the kernel
|
86 |
|
|
should consult the system default policy defined by
|
87 |
|
|
sysctl(8), such as net.inet.ipsec.esp_trans_deflev.
|
88 |
|
|
See ipsec(4) regarding the system default. use means
|
89 |
|
|
that a relevant SA can be used when available, since
|
90 |
|
|
the kernel may perform IPsec operation against packets
|
91 |
|
|
when possible. In this case, packets can be transmit-
|
92 |
|
|
ted in clear (when SA is not available), or encrypted
|
93 |
|
|
(when SA is available). require means that a relevant
|
94 |
|
|
SA is required, since the kernel must perform IPsec
|
95 |
|
|
operation against packets. unique is the same as
|
96 |
|
|
require, but adds the restriction that the SA for out-
|
97 |
|
|
bound traffic is used only for this policy. You may
|
98 |
|
|
need the identifier in order to relate the policy and
|
99 |
|
|
the SA when you define the SA by manual keying. You
|
100 |
|
|
can put the decimal number as the identifier after
|
101 |
|
|
unique like unique: number. number must be between 1
|
102 |
|
|
and 32767 . If the request string is kept unambiguous,
|
103 |
|
|
level and slash prior to level can be omitted. How-
|
104 |
|
|
ever, it is encouraged to specify them explicitly to
|
105 |
|
|
avoid unintended behaviors. If level is omitted, it
|
106 |
|
|
will be interpreted as default.
|
107 |
|
|
|
108 |
|
|
Note that there is a bit difference of specification from setkey(8). In
|
109 |
|
|
specification by setkey(8), both entrust and bypass are not used. Refer
|
110 |
|
|
to setkey(8) for detail.
|
111 |
|
|
|
112 |
|
|
Here are several examples (long lines are wrapped for readability):
|
113 |
|
|
|
114 |
|
|
in discard
|
115 |
|
|
out ipsec esp/transport//require
|
116 |
|
|
in ipsec ah/transport//require
|
117 |
|
|
out ipsec esp/tunnel/10.1.1.2-10.1.1.1/use
|
118 |
|
|
in ipsec ipcomp/transport//use
|
119 |
|
|
esp/transport//use
|
120 |
|
|
|
121 |
|
|
RETURN VALUES
|
122 |
|
|
ipsec_set_policy() returns a pointer to the allocated buffer of policy
|
123 |
|
|
specification if successful; otherwise a NULL pointer is returned.
|
124 |
|
|
ipsec_get_policylen() returns with positive value (meaning the buffer
|
125 |
|
|
size) on success, and negative value on errors. ipsec_dump_policy()
|
126 |
|
|
returns a pointer to dynamically allocated region on success, and NULL on
|
127 |
|
|
errors.
|
128 |
|
|
|
129 |
|
|
SEE ALSO
|
130 |
|
|
ipsec_strerror(3), ipsec(4), setkey(8)
|
131 |
|
|
|
132 |
|
|
HISTORY
|
133 |
|
|
The functions first appeared in WIDE/KAME IPv6 protocol stack kit.
|
134 |
|
|
|
135 |
|
|
KAME May 5, 1998 KAME
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
ipsec_strerror
|
141 |
|
|
|
142 |
|
|
IPSEC_STRERROR(3) System Library Functions Manual IPSEC_STRERROR(3)
|
143 |
|
|
|
144 |
|
|
NAME
|
145 |
|
|
ipsec_strerror - error message for IPsec policy manipulation library
|
146 |
|
|
|
147 |
|
|
SYNOPSIS
|
148 |
|
|
#include <netinet6/ipsec.h>
|
149 |
|
|
|
150 |
|
|
const char *
|
151 |
|
|
ipsec_strerror();
|
152 |
|
|
|
153 |
|
|
DESCRIPTION
|
154 |
|
|
netinet6/ipsec.h declares
|
155 |
|
|
|
156 |
|
|
extern int ipsec_errcode;
|
157 |
|
|
|
158 |
|
|
which is used to pass an error code from IPsec policy manipulation
|
159 |
|
|
library to an user program. ipsec_strerror() can be used to obtain the
|
160 |
|
|
error message string for the error code.
|
161 |
|
|
|
162 |
|
|
The array pointed to is not to be modified by the program. Since
|
163 |
|
|
ipsec_strerror() uses strerror(3) as underlying function, calling
|
164 |
|
|
strerror(3) after ipsec_strerror() would make the return value from
|
165 |
|
|
ipsec_strerror() invalid, or overwritten.
|
166 |
|
|
|
167 |
|
|
RETURN VALUES
|
168 |
|
|
ipsec_strerror() always return a pointer to C string. The C string must
|
169 |
|
|
not be overwritten by user programs.
|
170 |
|
|
|
171 |
|
|
SEE ALSO
|
172 |
|
|
ipsec_set_policy(3)
|
173 |
|
|
|
174 |
|
|
HISTORY
|
175 |
|
|
ipsec_strerror() first appeared in WIDE/KAME IPv6 protocol stack kit.
|
176 |
|
|
|
177 |
|
|
BUGS
|
178 |
|
|
ipsec_strerror() will return its result which may be overwritten by sub-
|
179 |
|
|
sequent calls.
|
180 |
|
|
|
181 |
|
|
ipsec_errcode is not thread safe.
|
182 |
|
|
|
183 |
|
|
KAME May 6, 1998 KAME
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
208 |
|
|
|