1 .\" $KAME: ipsec_set_policy.3,v 1.14 2001/04/06 07:00:46 itojun Exp $
2 .\" $FreeBSD: src/lib/libipsec/ipsec_set_policy.3,v 1.3.2.7 2001/08/17 15:42:59 ru Exp $
4 .\" Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
5 .\" All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. Neither the name of the project nor the names of its contributors
16 .\" may be used to endorse or promote products derived from this software
17 .\" without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .Dt IPSEC_SET_POLICY 3
35 .Nm ipsec_set_policy ,
36 .Nm ipsec_get_policylen ,
38 .Nd manipulate IPsec policy specification structure from readable string
43 .Fd #include <netinet6/ipsec.h>
45 .Fn ipsec_set_policy "char *policy" "int len"
47 .Fn ipsec_get_policylen "char *buf"
49 .Fn ipsec_dump_policy "char *buf" "char *delim"
52 generates IPsec policy specification structure, namely
53 .Li struct sadb_x_policy
55 .Li struct sadb_x_ipsecrequest
56 from human-readable policy specification.
57 Policy specification must be given as C string
64 will return the buffer of IPsec policy specification structure.
66 You may want the length of the generated buffer such when calling
68 .Fn ipsec_get_policylen
69 will return the length.
72 converts IPsec policy structure into readable form.
75 can be regarded as inverse conversion of
76 .Fn ipsec_set_policy .
78 points to a IPsec policy structure,
79 .Li struct sadb_x_policy .
81 is a delimiter string, which is usually a blank character.
86 single whitespace is assumed.
88 returns pointer to dynamically allocated string.
89 It is caller's responsibility to reclaim the region, by using
93 is formatted as either of the following:
94 .Bl -tag -width "discard"
95 .It Ar direction Li discard
102 specifies which direction the policy needs to be applied.
105 policy, packets will be dropped if they match the policy.
106 .It Ar direction Li entrust
108 means to consult to SPD defined by
110 .It Ar direction Li bypass
112 means to be bypassed the IPsec processing.
113 (packet will be transmitted in clear).
114 This is for privileged socket.
121 means that the matching packets are subject to IPsec processing.
123 can be followed by one or more
125 string, which is formatted as below:
126 .Bl -tag -width "discard"
153 specifies IPsec endpoint.
182 must be set to one of the following:
183 .Li default , use , require
187 means that the kernel should consult the system default policy
191 .Li net.inet.ipsec.esp_trans_deflev .
194 regarding the system default.
196 means that a relevant SA can be used when available,
197 since the kernel may perform IPsec operation against packets when possible.
198 In this case, packets can be transmitted in clear
199 (when SA is not available),
201 (when SA is available).
203 means that a relevant SA is required,
204 since the kernel must perform IPsec operation against packets.
208 but adds the restriction that the SA for outbound traffic is used
209 only for this policy.
210 You may need the identifier in order to relate the policy and the SA
211 when you define the SA by manual keying.
212 You can put the decimal number as the identifier after
215 .Li unique : number .
217 must be between 1 and 32767 .
220 string is kept unambiguous,
225 However, it is encouraged to specify them explicitly
226 to avoid unintended behaviors.
229 is omitted, it will be interpreted as
234 Note that there is a bit difference of specification from
238 both entrust and bypass are not used.
243 Here are several examples
244 (long lines are wrapped for readability):
245 .Bd -literal -offset indent
247 out ipsec esp/transport//require
248 in ipsec ah/transport//require
249 out ipsec esp/tunnel/10.1.1.2-10.1.1.1/use
250 in ipsec ipcomp/transport//use
255 returns a pointer to the allocated buffer of policy specification if successful; otherwise a NULL pointer is returned.
256 .Fn ipsec_get_policylen
257 returns with positive value
258 (meaning the buffer size)
259 on success, and negative value on errors.
260 .Fn ipsec_dump_policy
261 returns a pointer to dynamically allocated region on success,
266 .Xr ipsec_strerror 3 ,
270 The functions first appeared in WIDE/KAME IPv6 protocol stack kit.
272 IPv6 and IPsec support based on the KAME Project (http://www.kame.net/) stack
273 was initially integrated into