2004-07-01 17:13:15 +00:00
|
|
|
.\" $KAME: ipsec_set_policy.3,v 1.15 2001/08/17 07:21:36 itojun Exp $
|
2000-07-04 16:22:05 +00:00
|
|
|
.\"
|
2001-06-11 12:39:29 +00:00
|
|
|
.\" Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
|
2000-01-06 12:40:54 +00:00
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. Neither the name of the project nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
2005-02-09 18:07:17 +00:00
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
2006-02-14 13:02:00 +00:00
|
|
|
.Dd February 14, 2006
|
2000-01-06 12:40:54 +00:00
|
|
|
.Dt IPSEC_SET_POLICY 3
|
2000-05-01 14:40:06 +00:00
|
|
|
.Os
|
2000-01-06 12:40:54 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm ipsec_set_policy ,
|
|
|
|
.Nm ipsec_get_policylen ,
|
|
|
|
.Nm ipsec_dump_policy
|
2006-02-14 13:02:00 +00:00
|
|
|
.Nd create an IPsec policy structure from a human readable string
|
2000-07-04 16:22:05 +00:00
|
|
|
.\"
|
2000-05-01 14:40:06 +00:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libipsec
|
2000-01-06 12:40:54 +00:00
|
|
|
.Sh SYNOPSIS
|
2007-07-01 12:08:08 +00:00
|
|
|
.In netipsec/ipsec.h
|
2000-01-06 12:40:54 +00:00
|
|
|
.Ft "char *"
|
|
|
|
.Fn ipsec_set_policy "char *policy" "int len"
|
|
|
|
.Ft int
|
|
|
|
.Fn ipsec_get_policylen "char *buf"
|
|
|
|
.Ft "char *"
|
|
|
|
.Fn ipsec_dump_policy "char *buf" "char *delim"
|
|
|
|
.Sh DESCRIPTION
|
2003-02-06 11:29:40 +00:00
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Fn ipsec_set_policy
|
2006-09-17 21:27:35 +00:00
|
|
|
function generates an IPsec policy specification structure,
|
2000-01-06 12:40:54 +00:00
|
|
|
.Li struct sadb_x_policy
|
|
|
|
and/or
|
|
|
|
.Li struct sadb_x_ipsecrequest
|
2006-02-14 13:02:00 +00:00
|
|
|
from a human-readable policy specification.
|
2006-09-17 21:27:35 +00:00
|
|
|
The policy specification must be given as a C string,
|
|
|
|
passed in the
|
2000-01-06 12:40:54 +00:00
|
|
|
.Fa policy
|
2006-02-14 13:02:00 +00:00
|
|
|
argument and the length of the string, given as
|
|
|
|
.Fa len .
|
2003-02-06 11:29:40 +00:00
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Fn ipsec_set_policy
|
2006-02-14 13:02:00 +00:00
|
|
|
function returns pointer to a buffer which contains a properly formed
|
|
|
|
IPsec policy specification structure.
|
|
|
|
The buffer is dynamically allocated, and must be freed by using the
|
2006-09-17 21:27:35 +00:00
|
|
|
.Xr free 3
|
2006-02-14 13:02:00 +00:00
|
|
|
library function.
|
2000-01-06 12:40:54 +00:00
|
|
|
.Pp
|
2003-02-06 11:29:40 +00:00
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Fn ipsec_get_policylen
|
2021-08-09 10:37:41 +00:00
|
|
|
function returns the length of the buffer which is needed when passing
|
2006-02-14 13:02:00 +00:00
|
|
|
the specification structure to the
|
|
|
|
.Xr setsockopt 2
|
|
|
|
system call.
|
2000-01-06 12:40:54 +00:00
|
|
|
.Pp
|
2003-02-06 11:29:40 +00:00
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Fn ipsec_dump_policy
|
2006-02-14 13:02:00 +00:00
|
|
|
function converts an IPsec policy structure into a human readable form.
|
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Fa buf
|
2006-02-14 13:02:00 +00:00
|
|
|
argument points to an IPsec policy structure,
|
2000-01-06 12:40:54 +00:00
|
|
|
.Li struct sadb_x_policy .
|
|
|
|
.Fa delim
|
|
|
|
is a delimiter string, which is usually a blank character.
|
|
|
|
If you set
|
|
|
|
.Fa delim
|
|
|
|
to
|
|
|
|
.Dv NULL ,
|
2006-02-14 13:02:00 +00:00
|
|
|
a single white space is assumed.
|
2003-02-06 11:29:40 +00:00
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Fn ipsec_dump_policy
|
2003-02-06 11:29:40 +00:00
|
|
|
function returns a pointer to dynamically allocated string.
|
2006-02-14 13:02:00 +00:00
|
|
|
It is the caller's responsibility to free the returned pointer using the
|
2006-09-17 21:27:35 +00:00
|
|
|
.Xr free 3
|
2006-02-14 13:02:00 +00:00
|
|
|
library call.
|
2000-01-06 12:40:54 +00:00
|
|
|
.Pp
|
2006-09-17 21:27:35 +00:00
|
|
|
A
|
2000-01-06 12:40:54 +00:00
|
|
|
.Fa policy
|
2006-02-14 13:02:00 +00:00
|
|
|
is given in the following way:
|
2006-09-17 21:27:35 +00:00
|
|
|
.Bl -tag -width "discard"
|
2001-06-11 12:39:29 +00:00
|
|
|
.It Ar direction Li discard
|
2006-02-14 13:02:00 +00:00
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Ar direction
|
|
|
|
must be
|
|
|
|
.Li in
|
|
|
|
or
|
2006-02-14 13:02:00 +00:00
|
|
|
.Li out
|
2006-09-17 21:27:35 +00:00
|
|
|
and
|
2006-02-14 13:02:00 +00:00
|
|
|
specifies which direction the policy needs to be applied, either on
|
|
|
|
inbound or outbound packets.
|
|
|
|
When the
|
2001-06-11 12:39:29 +00:00
|
|
|
.Li discard
|
2006-02-14 13:02:00 +00:00
|
|
|
policy is selected, packets will be dropped if they match the policy.
|
2001-06-11 12:39:29 +00:00
|
|
|
.It Ar direction Li entrust
|
2000-01-06 12:40:54 +00:00
|
|
|
.Li entrust
|
2006-02-14 13:02:00 +00:00
|
|
|
means to consult the security policy database
|
|
|
|
(SPD)
|
|
|
|
in the kernel, as controlled by
|
2000-01-06 12:40:54 +00:00
|
|
|
.Xr setkey 8 .
|
|
|
|
.It Ar direction Li bypass
|
2006-09-17 21:27:35 +00:00
|
|
|
A direction of
|
2000-01-06 12:40:54 +00:00
|
|
|
.Li bypass
|
2006-02-14 13:02:00 +00:00
|
|
|
indicates that IPsec processing should not occur and that the
|
2006-09-17 21:27:35 +00:00
|
|
|
packet will be transmitted in clear.
|
|
|
|
The bypass option is only
|
2006-02-14 13:02:00 +00:00
|
|
|
available to privileged sockets.
|
2000-01-06 12:40:54 +00:00
|
|
|
.It Xo
|
|
|
|
.Ar direction
|
|
|
|
.Li ipsec
|
|
|
|
.Ar request ...
|
|
|
|
.Xc
|
2006-02-14 13:02:00 +00:00
|
|
|
A direction of
|
2000-01-06 12:40:54 +00:00
|
|
|
.Li ipsec
|
2006-02-14 13:02:00 +00:00
|
|
|
means that matching packets are processed by IPsec.
|
2000-01-06 12:40:54 +00:00
|
|
|
.Li ipsec
|
|
|
|
can be followed by one or more
|
|
|
|
.Ar request
|
2006-02-14 13:02:00 +00:00
|
|
|
string, which is formatted as:
|
2006-09-17 21:27:35 +00:00
|
|
|
.Bl -tag -width "discard"
|
2000-01-06 12:40:54 +00:00
|
|
|
.It Xo
|
|
|
|
.Ar protocol
|
|
|
|
.Li /
|
|
|
|
.Ar mode
|
|
|
|
.Li /
|
|
|
|
.Ar src
|
|
|
|
.Li -
|
|
|
|
.Ar dst
|
|
|
|
.Op Ar /level
|
|
|
|
.Xc
|
2006-02-14 13:02:00 +00:00
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Ar protocol
|
2006-02-14 13:02:00 +00:00
|
|
|
is one of:
|
2000-01-06 12:40:54 +00:00
|
|
|
.Li ah ,
|
|
|
|
.Li esp
|
|
|
|
or
|
2006-02-14 13:02:00 +00:00
|
|
|
.Li ipcomp
|
|
|
|
indicating Authentication Header, Encapsulating Security Protocol or
|
|
|
|
IP Compression protocol is used.
|
2000-01-06 12:40:54 +00:00
|
|
|
.Pp
|
2006-02-14 13:02:00 +00:00
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Ar mode
|
|
|
|
is either
|
|
|
|
.Li transport
|
|
|
|
or
|
2006-09-17 21:27:35 +00:00
|
|
|
.Li tunnel
|
|
|
|
the meanings of both modes are described in
|
2006-02-14 13:02:00 +00:00
|
|
|
.Xr ipsec 4 .
|
2000-01-06 12:40:54 +00:00
|
|
|
.Pp
|
2006-02-14 13:02:00 +00:00
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Ar src
|
|
|
|
and
|
|
|
|
.Ar dst
|
2006-02-14 13:02:00 +00:00
|
|
|
specify the IP address, either v4 or v6, of the source and destination systems.
|
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Ar src
|
2006-02-14 13:02:00 +00:00
|
|
|
always stands for the
|
2000-01-06 12:40:54 +00:00
|
|
|
.Dq sending node
|
|
|
|
and
|
|
|
|
.Ar dst
|
2006-02-14 13:02:00 +00:00
|
|
|
always stands for the
|
2000-01-06 12:40:54 +00:00
|
|
|
.Dq receiving node .
|
2006-02-14 13:02:00 +00:00
|
|
|
When
|
2000-01-06 12:40:54 +00:00
|
|
|
.Ar direction
|
|
|
|
is
|
|
|
|
.Li in ,
|
|
|
|
.Ar dst
|
2006-02-14 13:02:00 +00:00
|
|
|
is this local node
|
2000-01-06 12:40:54 +00:00
|
|
|
and
|
|
|
|
.Ar src
|
2006-02-14 13:02:00 +00:00
|
|
|
is the remote node or peer.
|
2001-06-11 12:39:29 +00:00
|
|
|
If
|
|
|
|
.Ar mode
|
|
|
|
is
|
|
|
|
.Li transport ,
|
2006-02-14 13:02:00 +00:00
|
|
|
both
|
2001-06-11 12:39:29 +00:00
|
|
|
.Ar src
|
|
|
|
and
|
|
|
|
.Ar dst
|
2002-12-27 12:15:40 +00:00
|
|
|
can be omitted.
|
2000-01-06 12:40:54 +00:00
|
|
|
.Pp
|
2006-02-14 13:02:00 +00:00
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Ar level
|
|
|
|
must be set to one of the following:
|
2000-07-04 16:22:05 +00:00
|
|
|
.Li default , use , require
|
2000-01-06 12:40:54 +00:00
|
|
|
or
|
2000-07-04 16:22:05 +00:00
|
|
|
.Li unique .
|
2000-01-06 12:40:54 +00:00
|
|
|
.Li default
|
2006-02-14 13:02:00 +00:00
|
|
|
means that the kernel should consult the default security policies as
|
|
|
|
defined by a set of
|
2000-01-06 12:40:54 +00:00
|
|
|
.Xr sysctl 8 ,
|
2006-09-17 21:27:35 +00:00
|
|
|
variables.
|
|
|
|
The relevant
|
|
|
|
.Xr sysctl 8
|
|
|
|
variables are described in
|
2006-02-14 13:02:00 +00:00
|
|
|
.Xr ipsec 4 .
|
|
|
|
.Pp
|
|
|
|
When
|
|
|
|
.Li use
|
|
|
|
is selected a relevant security association
|
|
|
|
(SA)
|
|
|
|
can be used when available but is not necessary.
|
|
|
|
If the SA is available then packets will be handled by IPsec,
|
2006-09-17 21:27:35 +00:00
|
|
|
i.e., encrypted and/or authenticated but if an SA is not available then
|
|
|
|
packets will be transmitted in the clear.
|
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Li use
|
2006-02-14 13:02:00 +00:00
|
|
|
option is not recommended because it allows for accidental
|
|
|
|
mis-configurations where encrypted or authenticated link becomes
|
|
|
|
unencrypted or unauthenticated, the
|
2000-01-06 12:40:54 +00:00
|
|
|
.Li require
|
2006-02-14 13:02:00 +00:00
|
|
|
keyword is recommended instead of
|
2006-09-17 21:27:35 +00:00
|
|
|
.Li use
|
2006-02-14 13:02:00 +00:00
|
|
|
where possible.
|
|
|
|
Using the
|
|
|
|
.Li require
|
|
|
|
keyword means that a relevant SA is required,
|
|
|
|
and that the kernel must perform IPsec processing on all matching
|
|
|
|
packets.
|
|
|
|
.Pp
|
|
|
|
The
|
2000-07-04 16:22:05 +00:00
|
|
|
.Li unique
|
2006-02-14 13:02:00 +00:00
|
|
|
keyword has the same effect as
|
2000-07-04 16:22:05 +00:00
|
|
|
.Li require ,
|
|
|
|
but adds the restriction that the SA for outbound traffic is used
|
|
|
|
only for this policy.
|
|
|
|
You may need the identifier in order to relate the policy and the SA
|
2006-02-14 13:02:00 +00:00
|
|
|
when you define the SA by manual keying using
|
|
|
|
.Xr setkey 8 .
|
|
|
|
Put the decimal number as the identifier after the
|
2000-07-04 16:22:05 +00:00
|
|
|
.Li unique
|
2006-02-14 13:02:00 +00:00
|
|
|
keyword in this way:
|
|
|
|
.Li unique : number ,
|
2006-09-17 21:27:35 +00:00
|
|
|
where
|
2000-07-04 16:22:05 +00:00
|
|
|
.Li number
|
2006-02-14 13:02:00 +00:00
|
|
|
must be between 1 and 32767.
|
|
|
|
.Pp
|
2000-01-06 12:40:54 +00:00
|
|
|
If the
|
|
|
|
.Ar request
|
|
|
|
string is kept unambiguous,
|
|
|
|
.Ar level
|
2006-02-14 13:02:00 +00:00
|
|
|
and the slash prior to
|
2000-01-06 12:40:54 +00:00
|
|
|
.Ar level
|
2006-02-14 13:02:00 +00:00
|
|
|
can be omitted but you are encouraged to specify them explicitly
|
2000-01-06 12:40:54 +00:00
|
|
|
to avoid unintended behaviors.
|
|
|
|
If
|
|
|
|
.Ar level
|
|
|
|
is omitted, it will be interpreted as
|
|
|
|
.Li default .
|
|
|
|
.El
|
|
|
|
.El
|
|
|
|
.Pp
|
2006-02-14 13:02:00 +00:00
|
|
|
Note that there is a difference between the specification allowed here
|
2006-09-17 21:27:35 +00:00
|
|
|
and in
|
2000-01-06 12:40:54 +00:00
|
|
|
.Xr setkey 8 .
|
2006-02-14 13:02:00 +00:00
|
|
|
When specifying security policies with
|
2000-01-06 12:40:54 +00:00
|
|
|
.Xr setkey 8 ,
|
2006-02-14 13:02:00 +00:00
|
|
|
neither entrust nor bypass are used.
|
2001-06-11 12:39:29 +00:00
|
|
|
Refer to
|
2000-01-06 12:40:54 +00:00
|
|
|
.Xr setkey 8
|
2006-02-14 13:02:00 +00:00
|
|
|
for details.
|
2000-01-06 12:40:54 +00:00
|
|
|
.Sh RETURN VALUES
|
2003-02-06 11:29:40 +00:00
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Fn ipsec_set_policy
|
2006-02-14 13:02:00 +00:00
|
|
|
function returns a pointer to the allocated buffer containing a the
|
|
|
|
policy specification if successful; otherwise a NULL pointer is
|
2006-09-17 21:27:35 +00:00
|
|
|
returned.
|
2006-02-14 13:02:00 +00:00
|
|
|
.Pp
|
2003-03-24 16:02:05 +00:00
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Fn ipsec_get_policylen
|
2006-09-17 21:27:35 +00:00
|
|
|
function returns a positive value,
|
2006-02-14 13:02:00 +00:00
|
|
|
indicating the buffer size,
|
|
|
|
on success, and a negative value on error.
|
|
|
|
.Pp
|
2003-03-24 16:02:05 +00:00
|
|
|
The
|
2000-01-06 12:40:54 +00:00
|
|
|
.Fn ipsec_dump_policy
|
2006-02-14 13:02:00 +00:00
|
|
|
function returns a pointer to a dynamically allocated region
|
|
|
|
containing a human readable security policy on success, and
|
2000-01-06 12:40:54 +00:00
|
|
|
.Dv NULL
|
2006-02-14 13:02:00 +00:00
|
|
|
on error.
|
2006-09-17 21:27:35 +00:00
|
|
|
.Sh EXAMPLES
|
|
|
|
Set a policy that all inbound packets are discarded.
|
|
|
|
.Pp
|
|
|
|
.Dl "in discard"
|
|
|
|
.Pp
|
|
|
|
.\"
|
|
|
|
All outbound packets are required to be processed by IPsec and
|
|
|
|
transported using ESP.
|
|
|
|
.Pp
|
|
|
|
.Dl "out ipsec esp/transport//require"
|
|
|
|
.Pp
|
|
|
|
.\"
|
|
|
|
All inbound packets are required to be authenticated using the AH protocol.
|
|
|
|
.Pp
|
|
|
|
.Dl "in ipsec ah/transport//require"
|
|
|
|
.Pp
|
|
|
|
.\"
|
|
|
|
Tunnel packets outbound through the endpoints at 10.1.1.2 and 10.1.1.1.
|
|
|
|
.Pp
|
|
|
|
.Dl "out ipsec esp/tunnel/10.1.1.2-10.1.1.1/require"
|
2000-01-06 12:40:54 +00:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr ipsec_strerror 3 ,
|
2001-01-01 23:26:16 +00:00
|
|
|
.Xr ipsec 4 ,
|
2000-01-06 12:40:54 +00:00
|
|
|
.Xr setkey 8
|
|
|
|
.Sh HISTORY
|
2006-02-14 13:02:00 +00:00
|
|
|
These functions first appeared in WIDE/KAME IPv6 protocol stack kit.
|
2001-06-11 12:39:29 +00:00
|
|
|
.Pp
|
|
|
|
IPv6 and IPsec support based on the KAME Project (http://www.kame.net/) stack
|
|
|
|
was initially integrated into
|
2006-09-17 21:27:35 +00:00
|
|
|
.Fx 4.0 .
|