1 .\" $NetBSD: ipsec_set_policy.3,v 1.13 2006/09/09 16:22:09 manu Exp $
3 .\" $KAME: ipsec_set_policy.3,v 1.16 2003/01/06 21:59:03 sumikawa Exp $
5 .\" Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
6 .\" All rights reserved.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. Neither the name of the project nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" 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 human-readable policy 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"
53 generates an IPsec policy specification structure, namely
54 .Li struct sadb_x_policy
56 .Li struct sadb_x_ipsecrequest
57 from a human-readable policy specification.
58 The policy specification must be given as a C string
63 will return a buffer with the corresponding IPsec policy specification structure.
64 The buffer is dynamically allocated, and must be
68 You can get the length of the generated buffer with
69 .Fn ipsec_get_policylen
74 converts an IPsec policy structure into human-readable form.
77 can be regarded as the inverse function to
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 a single whitespace is assumed.
90 returns a pointer to a dynamically allocated string.
91 It is the caller's responsibility to
96 is formatted as either of the following:
97 .Bl -tag -width "discard"
98 .It Ar direction [priority specification] Li discard
106 specifies in which direction the policy needs to be applied.
107 The non-standard direction
111 on platforms which do not support forward policies.
113 .Ar priority specification
114 is used to control the placement of the policy within the SPD.
115 The policy position is determined by
116 a signed integer where higher priorities indicate the policy is placed
117 closer to the beginning of the list and lower priorities indicate the
118 policy is placed closer to the end of the list.
120 priorities are added at the end of the group of such policies.
123 be specified when libipsec has been compiled against kernel headers that
124 support policy priorities (Linux \*[Gt]= 2.6.6).
125 It takes one of the following formats:
126 .Bl -tag -width "discard"
127 .It Ar {priority,prio} offset
129 is an integer in the range -2147483647..214783648.
130 .It Ar {priority,prio} base {+,-} offset
133 .Li low (-1073741824) ,
136 .Li high (1073741824) .
139 is an unsigned integer.
140 It can be up to 1073741824 for
141 positive offsets, and up to 1073741823 for negative offsets.
144 The interpretation of policy priority in these functions and the
146 The relationship between the two can be described as
147 p(kernel) = 0x80000000 - p(func)
151 policy, packets will be dropped if they match the policy.
152 .It Ar direction [priority specification] Li entrust
154 means to consult the SPD defined by
156 .It Ar direction [priority specification] Li bypass
158 means to bypass the IPsec processing.
159 .Pq the packet will be transmitted in clear .
160 This is for privileged sockets.
161 .It Ar direction Bo Ar priority specification Bc Li ipsec Ar request ...
163 means that the matching packets are subject to IPsec processing.
165 can be followed by one or more
167 strings, which are formatted as below:
168 .Bl -tag -width "discard"
169 .It Ar protocol Li / Ar mode Li / Ar src Li - Ar dst Op Ar /level
186 specifies the IPsec endpoint.
215 must be set to one of the following:
216 .Li default , use , require ,
220 means that the kernel should consult the system default policy
224 .Li net.inet.ipsec.esp_trans_deflev .
227 regarding the system default.
229 means that a relevant SA can be used when available,
230 since the kernel may perform IPsec operation against packets when possible.
231 In this case, packets can be transmitted in clear
232 .Pq when SA is not available ,
234 .Pq when SA is available .
236 means that a relevant SA is required,
237 since the kernel must perform IPsec operation against packets.
241 but adds the restriction that the SA for outbound traffic is used
242 only for this policy.
243 You may need the identifier in order to relate the policy and the SA
244 when you define the SA by manual keying.
245 You can put the decimal number as the identifier after
248 .Li unique : number .
250 must be between 1 and 32767 .
253 string is kept unambiguous,
258 However, it is encouraged to specify them explicitly
259 to avoid unintended behavior.
262 is omitted, it will be interpreted as
266 Note that there are slight differences to the specification of
268 In the specification of
279 Here are several examples
280 .Pq long lines are wrapped for readability :
281 .Bd -literal -offset indent
283 out ipsec esp/transport//require
284 in ipsec ah/transport//require
285 out ipsec esp/tunnel/10.1.1.2-10.1.1.1/use
286 in ipsec ipcomp/transport//use
292 returns a pointer to the allocated buffer with the policy specification
293 if successful; otherwise a
296 .Fn ipsec_get_policylen
297 returns a positive value
298 .Pq meaning the buffer size
299 on success, and a negative value on errors.
300 .Fn ipsec_dump_policy
301 returns a pointer to a dynamically allocated region on success,
306 .Xr ipsec_strerror 3 ,
310 The functions first appeared in the WIDE/KAME IPv6 protocol stack kit.