186ab142dSRuslan Ermilov.\" $KAME: ipsec_set_policy.3,v 1.15 2001/08/17 07:21:36 itojun Exp $ 23c62e87aSJun-ichiro itojun Hagino.\" 333841545SHajimu UMEMOTO.\" Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 49a4365d0SYoshinobu Inoue.\" All rights reserved. 59a4365d0SYoshinobu Inoue.\" 69a4365d0SYoshinobu Inoue.\" Redistribution and use in source and binary forms, with or without 79a4365d0SYoshinobu Inoue.\" modification, are permitted provided that the following conditions 89a4365d0SYoshinobu Inoue.\" are met: 99a4365d0SYoshinobu Inoue.\" 1. Redistributions of source code must retain the above copyright 109a4365d0SYoshinobu Inoue.\" notice, this list of conditions and the following disclaimer. 119a4365d0SYoshinobu Inoue.\" 2. Redistributions in binary form must reproduce the above copyright 129a4365d0SYoshinobu Inoue.\" notice, this list of conditions and the following disclaimer in the 139a4365d0SYoshinobu Inoue.\" documentation and/or other materials provided with the distribution. 149a4365d0SYoshinobu Inoue.\" 3. Neither the name of the project nor the names of its contributors 159a4365d0SYoshinobu Inoue.\" may be used to endorse or promote products derived from this software 169a4365d0SYoshinobu Inoue.\" without specific prior written permission. 179a4365d0SYoshinobu Inoue.\" 189a4365d0SYoshinobu Inoue.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 199a4365d0SYoshinobu Inoue.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 209a4365d0SYoshinobu Inoue.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 219a4365d0SYoshinobu Inoue.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 229a4365d0SYoshinobu Inoue.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 239a4365d0SYoshinobu Inoue.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 249a4365d0SYoshinobu Inoue.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 259a4365d0SYoshinobu Inoue.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 269a4365d0SYoshinobu Inoue.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 279a4365d0SYoshinobu Inoue.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 289a4365d0SYoshinobu Inoue.\" SUCH DAMAGE. 299a4365d0SYoshinobu Inoue.\" 30108b9d83SGeorge V. Neville-Neil.Dd February 14, 2006 319a4365d0SYoshinobu Inoue.Dt IPSEC_SET_POLICY 3 326be6c650SAlexey Zelkin.Os 339a4365d0SYoshinobu Inoue.Sh NAME 349a4365d0SYoshinobu Inoue.Nm ipsec_set_policy , 359a4365d0SYoshinobu Inoue.Nm ipsec_get_policylen , 369a4365d0SYoshinobu Inoue.Nm ipsec_dump_policy 37108b9d83SGeorge V. Neville-Neil.Nd create an IPsec policy structure from a human readable string 383c62e87aSJun-ichiro itojun Hagino.\" 396be6c650SAlexey Zelkin.Sh LIBRARY 406be6c650SAlexey Zelkin.Lb libipsec 419a4365d0SYoshinobu Inoue.Sh SYNOPSIS 428409aedfSGeorge V. Neville-Neil.In netipsec/ipsec.h 439a4365d0SYoshinobu Inoue.Ft "char *" 44*50ecbc51SLexi Winter.Fn ipsec_set_policy "const char *policy" "int len" 459a4365d0SYoshinobu Inoue.Ft int 46*50ecbc51SLexi Winter.Fn ipsec_get_policylen "const char *buf" 479a4365d0SYoshinobu Inoue.Ft "char *" 48*50ecbc51SLexi Winter.Fn ipsec_dump_policy "c_caddr_t *buf" "const char *delim" 499a4365d0SYoshinobu Inoue.Sh DESCRIPTION 50bd99773bSPhilippe CharnierThe 519a4365d0SYoshinobu Inoue.Fn ipsec_set_policy 52108b9d83SGeorge V. Neville-Neilfunction generates an IPsec policy specification structure, 539a4365d0SYoshinobu Inoue.Li struct sadb_x_policy 549a4365d0SYoshinobu Inoueand/or 559a4365d0SYoshinobu Inoue.Li struct sadb_x_ipsecrequest 56108b9d83SGeorge V. Neville-Neilfrom a human-readable policy specification. 57108b9d83SGeorge V. Neville-NeilThe policy specification must be given as a C string, 58108b9d83SGeorge V. Neville-Neilpassed in the 599a4365d0SYoshinobu Inoue.Fa policy 60108b9d83SGeorge V. Neville-Neilargument and the length of the string, given as 61108b9d83SGeorge V. Neville-Neil.Fa len . 62bd99773bSPhilippe CharnierThe 639a4365d0SYoshinobu Inoue.Fn ipsec_set_policy 64108b9d83SGeorge V. Neville-Neilfunction returns pointer to a buffer which contains a properly formed 65108b9d83SGeorge V. Neville-NeilIPsec policy specification structure. 66108b9d83SGeorge V. Neville-NeilThe buffer is dynamically allocated, and must be freed by using the 67108b9d83SGeorge V. Neville-Neil.Xr free 3 68108b9d83SGeorge V. Neville-Neillibrary function. 699a4365d0SYoshinobu Inoue.Pp 70bd99773bSPhilippe CharnierThe 719a4365d0SYoshinobu Inoue.Fn ipsec_get_policylen 72ba3896e1SKonstantin Belousovfunction returns the length of the buffer which is needed when passing 73108b9d83SGeorge V. Neville-Neilthe specification structure to the 74108b9d83SGeorge V. Neville-Neil.Xr setsockopt 2 75108b9d83SGeorge V. Neville-Neilsystem call. 769a4365d0SYoshinobu Inoue.Pp 77bd99773bSPhilippe CharnierThe 789a4365d0SYoshinobu Inoue.Fn ipsec_dump_policy 79108b9d83SGeorge V. Neville-Neilfunction converts an IPsec policy structure into a human readable form. 80108b9d83SGeorge V. Neville-NeilThe 819a4365d0SYoshinobu Inoue.Fa buf 82108b9d83SGeorge V. Neville-Neilargument points to an IPsec policy structure, 839a4365d0SYoshinobu Inoue.Li struct sadb_x_policy . 849a4365d0SYoshinobu Inoue.Fa delim 859a4365d0SYoshinobu Inoueis a delimiter string, which is usually a blank character. 869a4365d0SYoshinobu InoueIf you set 879a4365d0SYoshinobu Inoue.Fa delim 889a4365d0SYoshinobu Inoueto 899a4365d0SYoshinobu Inoue.Dv NULL , 90108b9d83SGeorge V. Neville-Neila single white space is assumed. 91bd99773bSPhilippe CharnierThe 929a4365d0SYoshinobu Inoue.Fn ipsec_dump_policy 93bd99773bSPhilippe Charnierfunction returns a pointer to dynamically allocated string. 94108b9d83SGeorge V. Neville-NeilIt is the caller's responsibility to free the returned pointer using the 95108b9d83SGeorge V. Neville-Neil.Xr free 3 96108b9d83SGeorge V. Neville-Neillibrary call. 979a4365d0SYoshinobu Inoue.Pp 98108b9d83SGeorge V. Neville-NeilA 999a4365d0SYoshinobu Inoue.Fa policy 100108b9d83SGeorge V. Neville-Neilis given in the following way: 1019a4365d0SYoshinobu Inoue.Bl -tag -width "discard" 10233841545SHajimu UMEMOTO.It Ar direction Li discard 103108b9d83SGeorge V. Neville-NeilThe 1049a4365d0SYoshinobu Inoue.Ar direction 1059a4365d0SYoshinobu Inouemust be 1069a4365d0SYoshinobu Inoue.Li in 1079a4365d0SYoshinobu Inoueor 108108b9d83SGeorge V. Neville-Neil.Li out 109108b9d83SGeorge V. Neville-Neiland 110108b9d83SGeorge V. Neville-Neilspecifies which direction the policy needs to be applied, either on 111108b9d83SGeorge V. Neville-Neilinbound or outbound packets. 112108b9d83SGeorge V. Neville-NeilWhen the 11333841545SHajimu UMEMOTO.Li discard 114108b9d83SGeorge V. Neville-Neilpolicy is selected, packets will be dropped if they match the policy. 11533841545SHajimu UMEMOTO.It Ar direction Li entrust 1169a4365d0SYoshinobu Inoue.Li entrust 117108b9d83SGeorge V. Neville-Neilmeans to consult the security policy database 118108b9d83SGeorge V. Neville-Neil(SPD) 119108b9d83SGeorge V. Neville-Neilin the kernel, as controlled by 1209a4365d0SYoshinobu Inoue.Xr setkey 8 . 1219a4365d0SYoshinobu Inoue.It Ar direction Li bypass 122108b9d83SGeorge V. Neville-NeilA direction of 1239a4365d0SYoshinobu Inoue.Li bypass 124108b9d83SGeorge V. Neville-Neilindicates that IPsec processing should not occur and that the 125a73a3ab5SRuslan Ermilovpacket will be transmitted in clear. 126a73a3ab5SRuslan ErmilovThe bypass option is only 127108b9d83SGeorge V. Neville-Neilavailable to privileged sockets. 1289a4365d0SYoshinobu Inoue.It Xo 1299a4365d0SYoshinobu Inoue.Ar direction 1309a4365d0SYoshinobu Inoue.Li ipsec 1319a4365d0SYoshinobu Inoue.Ar request ... 1329a4365d0SYoshinobu Inoue.Xc 133108b9d83SGeorge V. Neville-NeilA direction of 1349a4365d0SYoshinobu Inoue.Li ipsec 135108b9d83SGeorge V. Neville-Neilmeans that matching packets are processed by IPsec. 1369a4365d0SYoshinobu Inoue.Li ipsec 1379a4365d0SYoshinobu Inouecan be followed by one or more 1389a4365d0SYoshinobu Inoue.Ar request 139108b9d83SGeorge V. Neville-Neilstring, which is formatted as: 1409a4365d0SYoshinobu Inoue.Bl -tag -width "discard" 1419a4365d0SYoshinobu Inoue.It Xo 1429a4365d0SYoshinobu Inoue.Ar protocol 1439a4365d0SYoshinobu Inoue.Li / 1449a4365d0SYoshinobu Inoue.Ar mode 1459a4365d0SYoshinobu Inoue.Li / 1469a4365d0SYoshinobu Inoue.Ar src 1479a4365d0SYoshinobu Inoue.Li - 1489a4365d0SYoshinobu Inoue.Ar dst 1499a4365d0SYoshinobu Inoue.Op Ar /level 1509a4365d0SYoshinobu Inoue.Xc 151108b9d83SGeorge V. Neville-NeilThe 1529a4365d0SYoshinobu Inoue.Ar protocol 153108b9d83SGeorge V. Neville-Neilis one of: 1549a4365d0SYoshinobu Inoue.Li ah , 1559a4365d0SYoshinobu Inoue.Li esp 1569a4365d0SYoshinobu Inoueor 157108b9d83SGeorge V. Neville-Neil.Li ipcomp 158108b9d83SGeorge V. Neville-Neilindicating Authentication Header, Encapsulating Security Protocol or 159108b9d83SGeorge V. Neville-NeilIP Compression protocol is used. 1609a4365d0SYoshinobu Inoue.Pp 161108b9d83SGeorge V. Neville-NeilThe 1629a4365d0SYoshinobu Inoue.Ar mode 1639a4365d0SYoshinobu Inoueis either 1649a4365d0SYoshinobu Inoue.Li transport 1659a4365d0SYoshinobu Inoueor 166108b9d83SGeorge V. Neville-Neil.Li tunnel 167108b9d83SGeorge V. Neville-Neilthe meanings of both modes are described in 168108b9d83SGeorge V. Neville-Neil.Xr ipsec 4 . 1699a4365d0SYoshinobu Inoue.Pp 170108b9d83SGeorge V. Neville-NeilThe 1719a4365d0SYoshinobu Inoue.Ar src 1729a4365d0SYoshinobu Inoueand 1739a4365d0SYoshinobu Inoue.Ar dst 174108b9d83SGeorge V. Neville-Neilspecify the IP address, either v4 or v6, of the source and destination systems. 175108b9d83SGeorge V. Neville-NeilThe 1769a4365d0SYoshinobu Inoue.Ar src 177108b9d83SGeorge V. Neville-Neilalways stands for the 1789a4365d0SYoshinobu Inoue.Dq sending node 1799a4365d0SYoshinobu Inoueand 1809a4365d0SYoshinobu Inoue.Ar dst 181108b9d83SGeorge V. Neville-Neilalways stands for the 1829a4365d0SYoshinobu Inoue.Dq receiving node . 183108b9d83SGeorge V. Neville-NeilWhen 1849a4365d0SYoshinobu Inoue.Ar direction 1859a4365d0SYoshinobu Inoueis 1869a4365d0SYoshinobu Inoue.Li in , 1879a4365d0SYoshinobu Inoue.Ar dst 188108b9d83SGeorge V. Neville-Neilis this local node 1899a4365d0SYoshinobu Inoueand 1909a4365d0SYoshinobu Inoue.Ar src 191108b9d83SGeorge V. Neville-Neilis the remote node or peer. 19233841545SHajimu UMEMOTOIf 19333841545SHajimu UMEMOTO.Ar mode 19433841545SHajimu UMEMOTOis 19533841545SHajimu UMEMOTO.Li transport , 196108b9d83SGeorge V. Neville-Neilboth 19733841545SHajimu UMEMOTO.Ar src 19833841545SHajimu UMEMOTOand 19933841545SHajimu UMEMOTO.Ar dst 20057bd0fc6SJens Schweikhardtcan be omitted. 2019a4365d0SYoshinobu Inoue.Pp 202108b9d83SGeorge V. Neville-NeilThe 2039a4365d0SYoshinobu Inoue.Ar level 2049a4365d0SYoshinobu Inouemust be set to one of the following: 2053c62e87aSJun-ichiro itojun Hagino.Li default , use , require 2069a4365d0SYoshinobu Inoueor 2073c62e87aSJun-ichiro itojun Hagino.Li unique . 2089a4365d0SYoshinobu Inoue.Li default 209108b9d83SGeorge V. Neville-Neilmeans that the kernel should consult the default security policies as 210108b9d83SGeorge V. Neville-Neildefined by a set of 2119a4365d0SYoshinobu Inoue.Xr sysctl 8 , 212a73a3ab5SRuslan Ermilovvariables. 213a73a3ab5SRuslan ErmilovThe relevant 214108b9d83SGeorge V. Neville-Neil.Xr sysctl 8 215108b9d83SGeorge V. Neville-Neilvariables are described in 216108b9d83SGeorge V. Neville-Neil.Xr ipsec 4 . 217108b9d83SGeorge V. Neville-Neil.Pp 218108b9d83SGeorge V. Neville-NeilWhen 2199a4365d0SYoshinobu Inoue.Li use 220108b9d83SGeorge V. Neville-Neilis selected a relevant security association 221108b9d83SGeorge V. Neville-Neil(SA) 222108b9d83SGeorge V. Neville-Neilcan be used when available but is not necessary. 223108b9d83SGeorge V. Neville-NeilIf the SA is available then packets will be handled by IPsec, 224a73a3ab5SRuslan Ermilovi.e., encrypted and/or authenticated but if an SA is not available then 225a73a3ab5SRuslan Ermilovpackets will be transmitted in the clear. 226a73a3ab5SRuslan ErmilovThe 227108b9d83SGeorge V. Neville-Neil.Li use 228108b9d83SGeorge V. Neville-Neiloption is not recommended because it allows for accidental 229108b9d83SGeorge V. Neville-Neilmis-configurations where encrypted or authenticated link becomes 230108b9d83SGeorge V. Neville-Neilunencrypted or unauthenticated, the 2319a4365d0SYoshinobu Inoue.Li require 232108b9d83SGeorge V. Neville-Neilkeyword is recommended instead of 233108b9d83SGeorge V. Neville-Neil.Li use 234108b9d83SGeorge V. Neville-Neilwhere possible. 235108b9d83SGeorge V. Neville-NeilUsing the 236108b9d83SGeorge V. Neville-Neil.Li require 237108b9d83SGeorge V. Neville-Neilkeyword means that a relevant SA is required, 238108b9d83SGeorge V. Neville-Neiland that the kernel must perform IPsec processing on all matching 239108b9d83SGeorge V. Neville-Neilpackets. 240108b9d83SGeorge V. Neville-Neil.Pp 241108b9d83SGeorge V. Neville-NeilThe 2423c62e87aSJun-ichiro itojun Hagino.Li unique 243108b9d83SGeorge V. Neville-Neilkeyword has the same effect as 2443c62e87aSJun-ichiro itojun Hagino.Li require , 2453c62e87aSJun-ichiro itojun Haginobut adds the restriction that the SA for outbound traffic is used 2463c62e87aSJun-ichiro itojun Haginoonly for this policy. 2473c62e87aSJun-ichiro itojun HaginoYou may need the identifier in order to relate the policy and the SA 248108b9d83SGeorge V. Neville-Neilwhen you define the SA by manual keying using 249108b9d83SGeorge V. Neville-Neil.Xr setkey 8 . 250108b9d83SGeorge V. Neville-NeilPut the decimal number as the identifier after the 2513c62e87aSJun-ichiro itojun Hagino.Li unique 252108b9d83SGeorge V. Neville-Neilkeyword in this way: 253108b9d83SGeorge V. Neville-Neil.Li unique : number , 254108b9d83SGeorge V. Neville-Neilwhere 2553c62e87aSJun-ichiro itojun Hagino.Li number 2563c62e87aSJun-ichiro itojun Haginomust be between 1 and 32767. 257108b9d83SGeorge V. Neville-Neil.Pp 2589a4365d0SYoshinobu InoueIf the 2599a4365d0SYoshinobu Inoue.Ar request 2609a4365d0SYoshinobu Inouestring is kept unambiguous, 2619a4365d0SYoshinobu Inoue.Ar level 262108b9d83SGeorge V. Neville-Neiland the slash prior to 2639a4365d0SYoshinobu Inoue.Ar level 264108b9d83SGeorge V. Neville-Neilcan be omitted but you are encouraged to specify them explicitly 2659a4365d0SYoshinobu Inoueto avoid unintended behaviors. 2669a4365d0SYoshinobu InoueIf 2679a4365d0SYoshinobu Inoue.Ar level 2689a4365d0SYoshinobu Inoueis omitted, it will be interpreted as 2699a4365d0SYoshinobu Inoue.Li default . 2709a4365d0SYoshinobu Inoue.El 2719a4365d0SYoshinobu Inoue.El 2729a4365d0SYoshinobu Inoue.Pp 273108b9d83SGeorge V. Neville-NeilNote that there is a difference between the specification allowed here 274108b9d83SGeorge V. Neville-Neiland in 2759a4365d0SYoshinobu Inoue.Xr setkey 8 . 276108b9d83SGeorge V. Neville-NeilWhen specifying security policies with 2779a4365d0SYoshinobu Inoue.Xr setkey 8 , 278108b9d83SGeorge V. Neville-Neilneither entrust nor bypass are used. 27933841545SHajimu UMEMOTORefer to 2809a4365d0SYoshinobu Inoue.Xr setkey 8 281108b9d83SGeorge V. Neville-Neilfor details. 2829a4365d0SYoshinobu Inoue.Sh RETURN VALUES 283bd99773bSPhilippe CharnierThe 2849a4365d0SYoshinobu Inoue.Fn ipsec_set_policy 285108b9d83SGeorge V. Neville-Neilfunction returns a pointer to the allocated buffer containing a the 286108b9d83SGeorge V. Neville-Neilpolicy specification if successful; otherwise a NULL pointer is 287108b9d83SGeorge V. Neville-Neilreturned. 288108b9d83SGeorge V. Neville-Neil.Pp 2890552350eSPhilippe CharnierThe 2909a4365d0SYoshinobu Inoue.Fn ipsec_get_policylen 291108b9d83SGeorge V. Neville-Neilfunction returns a positive value, 292108b9d83SGeorge V. Neville-Neilindicating the buffer size, 293108b9d83SGeorge V. Neville-Neilon success, and a negative value on error. 294108b9d83SGeorge V. Neville-Neil.Pp 2950552350eSPhilippe CharnierThe 2969a4365d0SYoshinobu Inoue.Fn ipsec_dump_policy 297108b9d83SGeorge V. Neville-Neilfunction returns a pointer to a dynamically allocated region 298108b9d83SGeorge V. Neville-Neilcontaining a human readable security policy on success, and 2999a4365d0SYoshinobu Inoue.Dv NULL 300108b9d83SGeorge V. Neville-Neilon error. 301a73a3ab5SRuslan Ermilov.Sh EXAMPLES 302a73a3ab5SRuslan ErmilovSet a policy that all inbound packets are discarded. 303a73a3ab5SRuslan Ermilov.Pp 304a73a3ab5SRuslan Ermilov.Dl "in discard" 305a73a3ab5SRuslan Ermilov.Pp 306a73a3ab5SRuslan Ermilov.\" 307a73a3ab5SRuslan ErmilovAll outbound packets are required to be processed by IPsec and 308a73a3ab5SRuslan Ermilovtransported using ESP. 309a73a3ab5SRuslan Ermilov.Pp 310a73a3ab5SRuslan Ermilov.Dl "out ipsec esp/transport//require" 311a73a3ab5SRuslan Ermilov.Pp 312a73a3ab5SRuslan Ermilov.\" 313a73a3ab5SRuslan ErmilovAll inbound packets are required to be authenticated using the AH protocol. 314a73a3ab5SRuslan Ermilov.Pp 315a73a3ab5SRuslan Ermilov.Dl "in ipsec ah/transport//require" 316a73a3ab5SRuslan Ermilov.Pp 317a73a3ab5SRuslan Ermilov.\" 318a73a3ab5SRuslan ErmilovTunnel packets outbound through the endpoints at 10.1.1.2 and 10.1.1.1. 319a73a3ab5SRuslan Ermilov.Pp 320a73a3ab5SRuslan Ermilov.Dl "out ipsec esp/tunnel/10.1.1.2-10.1.1.1/require" 3219a4365d0SYoshinobu Inoue.Sh SEE ALSO 3229a4365d0SYoshinobu Inoue.Xr ipsec_strerror 3 , 323b9d41215SBen Smithurst.Xr ipsec 4 , 3249a4365d0SYoshinobu Inoue.Xr setkey 8 3259a4365d0SYoshinobu Inoue.Sh HISTORY 326108b9d83SGeorge V. Neville-NeilThese functions first appeared in WIDE/KAME IPv6 protocol stack kit. 32733841545SHajimu UMEMOTO.Pp 32833841545SHajimu UMEMOTOIPv6 and IPsec support based on the KAME Project (http://www.kame.net/) stack 32933841545SHajimu UMEMOTOwas initially integrated into 330a73a3ab5SRuslan Ermilov.Fx 4.0 . 331