1 .\" $KAME: ipsec_set_policy.3,v 1.15 2001/08/17 07:21:36 itojun Exp $
3 .\" Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the project nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .Dt IPSEC_SET_POLICY 3
36 .Nm ipsec_set_policy ,
37 .Nm ipsec_get_policylen ,
39 .Nd manipulate IPsec policy specification structure from readable string
46 .Fn ipsec_set_policy "char *policy" "int len"
48 .Fn ipsec_get_policylen "char *buf"
50 .Fn ipsec_dump_policy "char *buf" "char *delim"
54 function generates IPsec policy specification structure, namely
55 .Li struct sadb_x_policy
57 .Li struct sadb_x_ipsecrequest
58 from human-readable policy specification.
59 Policy specification must be given as C string
67 function will return the buffer of IPsec policy specification structure.
68 The buffer is dynamically allocated, and must be freed by the caller by calling
71 You may want the length of the generated buffer such when calling
74 .Fn ipsec_get_policylen
75 function will return the length.
79 function converts IPsec policy structure into readable form.
82 can be regarded as inverse conversion of
83 .Fn ipsec_set_policy .
85 points to an IPsec policy structure,
86 .Li struct sadb_x_policy .
88 is a delimiter string, which is usually a blank character.
93 single whitespace is assumed.
96 function returns a pointer to dynamically allocated string.
97 It is caller's responsibility to reclaim the region, by using
101 is formatted as either of the following:
102 .Bl -tag -width "discard"
103 .It Ar direction Li discard
110 specifies which direction the policy needs to be applied.
113 policy, packets will be dropped if they match the policy.
114 .It Ar direction Li entrust
116 means to consult to SPD defined by
118 .It Ar direction Li bypass
120 means to be bypassed the IPsec processing.
121 (packet will be transmitted in clear).
122 This is for privileged socket.
129 means that the matching packets are subject to IPsec processing.
131 can be followed by one or more
133 string, which is formatted as below:
134 .Bl -tag -width "discard"
161 specifies IPsec endpoint.
190 must be set to one of the following:
191 .Li default , use , require
195 means that the kernel should consult the system default policy
199 .Li net.inet.ipsec.esp_trans_deflev .
202 regarding the system default.
204 means that a relevant SA can be used when available,
205 since the kernel may perform IPsec operation against packets when possible.
206 In this case, packets can be transmitted in clear
207 (when SA is not available),
209 (when SA is available).
211 means that a relevant SA is required,
212 since the kernel must perform IPsec operation against packets.
216 but adds the restriction that the SA for outbound traffic is used
217 only for this policy.
218 You may need the identifier in order to relate the policy and the SA
219 when you define the SA by manual keying.
220 You can put the decimal number as the identifier after
223 .Li unique : number .
225 must be between 1 and 32767 .
228 string is kept unambiguous,
233 However, it is encouraged to specify them explicitly
234 to avoid unintended behaviors.
237 is omitted, it will be interpreted as
242 Note that there is a bit difference of specification from
246 both entrust and bypass are not used.
251 Here are several examples
252 (long lines are wrapped for readability):
253 .Bd -literal -offset indent
255 out ipsec esp/transport//require
256 in ipsec ah/transport//require
257 out ipsec esp/tunnel/10.1.1.2-10.1.1.1/use
258 in ipsec ipcomp/transport//use
264 function returns a pointer to the allocated buffer of policy specification if
265 successful; otherwise a NULL pointer is returned.
267 .Fn ipsec_get_policylen
268 function returns with positive value
269 (meaning the buffer size)
270 on success, and negative value on errors.
272 .Fn ipsec_dump_policy
273 function returns a pointer to dynamically allocated region on success,
278 .Xr ipsec_strerror 3 ,
282 The functions first appeared in WIDE/KAME IPv6 protocol stack kit.
284 IPv6 and IPsec support based on the KAME Project (http://www.kame.net/) stack
285 was initially integrated into