1 .\" $KAME: ipsec_set_policy.3,v 1.15 2001/08/17 07:21:36 itojun Exp $
2 .\" $FreeBSD: src/lib/libipsec/ipsec_set_policy.3,v 1.3.2.10 2002/12/29 16:35:36 schweikh 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
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.
65 The buffer is dynamically allocated, and must be freed by the caller by calling
68 You may want the length of the generated buffer such when calling
70 .Fn ipsec_get_policylen
71 will return the length.
74 converts IPsec policy structure into readable form.
77 can be regarded as inverse conversion of
78 .Fn ipsec_set_policy .
80 points to an IPsec policy structure,
81 .Li struct sadb_x_policy .
83 is a delimiter string, which is usually a blank character.
88 single whitespace is assumed.
90 returns pointer to dynamically allocated string.
91 It is caller's responsibility to reclaim the region, by using
95 is formatted as either of the following:
96 .Bl -tag -width "discard"
97 .It Ar direction Li discard
104 specifies which direction the policy needs to be applied.
107 policy, packets will be dropped if they match the policy.
108 .It Ar direction Li entrust
110 means to consult to SPD defined by
112 .It Ar direction Li bypass
114 means to be bypassed the IPsec processing.
115 (packet will be transmitted in clear).
116 This is for privileged socket.
123 means that the matching packets are subject to IPsec processing.
125 can be followed by one or more
127 string, which is formatted as below:
128 .Bl -tag -width "discard"
155 specifies IPsec endpoint.
184 must be set to one of the following:
185 .Li default , use , require
189 means that the kernel should consult the system default policy
193 .Va net.inet.ipsec.esp_trans_deflev .
196 regarding the system default.
198 means that a relevant SA can be used when available,
199 since the kernel may perform IPsec operation against packets when possible.
200 In this case, packets can be transmitted in clear
201 (when SA is not available),
203 (when SA is available).
205 means that a relevant SA is required,
206 since the kernel must perform IPsec operation against packets.
210 but adds the restriction that the SA for outbound traffic is used
211 only for this policy.
212 You may need the identifier in order to relate the policy and the SA
213 when you define the SA by manual keying.
214 You can put the decimal number as the identifier after
217 .Li unique : number .
219 must be between 1 and 32767 .
222 string is kept unambiguous,
227 However, it is encouraged to specify them explicitly
228 to avoid unintended behaviors.
231 is omitted, it will be interpreted as
236 Note that there is a bit difference of specification from
240 both entrust and bypass are not used.
245 Here are several examples
246 (long lines are wrapped for readability):
247 .Bd -literal -offset indent
249 out ipsec esp/transport//require
250 in ipsec ah/transport//require
251 out ipsec esp/tunnel/10.1.1.2-10.1.1.1/use
252 in ipsec ipcomp/transport//use
257 returns a pointer to the allocated buffer of policy specification if successful; otherwise a NULL pointer is returned.
258 .Fn ipsec_get_policylen
259 returns with positive value
260 (meaning the buffer size)
261 on success, and negative value on errors.
262 .Fn ipsec_dump_policy
263 returns a pointer to dynamically allocated region on success,
268 .Xr ipsec_strerror 3 ,
272 The functions first appeared in WIDE/KAME IPv6 protocol stack kit.
274 IPv6 and IPsec support based on the KAME Project
275 .Pa ( http://www.kame.net/ )
276 stack was initially integrated into