ipsec_set_policy.3
来自「eCos操作系统源码」· 3 代码 · 共 272 行
3
272 行
.\" $KAME: ipsec_set_policy.3,v 1.15 2001/08/17 07:21:36 itojun Exp $.\".\" Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project..\" 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..\".Dd May 5, 1998.Dt IPSEC_SET_POLICY 3.Os KAME.Sh NAME.Nm ipsec_set_policy ,.Nm ipsec_get_policylen ,.Nm ipsec_dump_policy.Nd manipulate IPsec policy specification structure from readable string.\".Sh LIBRARY.Lb libipsec.Sh SYNOPSIS.Fd #include <netinet6/ipsec.h>.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.Fn ipsec_set_policygenerates IPsec policy specification structure, namely.Li struct sadb_x_policyand/or.Li struct sadb_x_ipsecrequestfrom human-readable policy specification.policy specification must be given as C string.Fa policyand length.Fa lenof.Fa policy ..Fn ipsec_set_policywill return the buffer of IPsec policy specification structure.The buffer is dynamically allocated, and must be freed by the caller by calling.Xr free 3 ..PpYou may want the length of the generated buffer such when calling.Xr setsockopt 2 ..Fn ipsec_get_policylenwill return the length..Pp.Fn ipsec_dump_policyconverts IPsec policy structure into readable form.Therefore,.Fn ipsec_dump_policycan be regarded as inverse conversion of.Fn ipsec_set_policy ..Fa bufpoints to a IPsec policy structure,.Li struct sadb_x_policy ..Fa delimis a delimiter string, which is usually a blank character.If you set.Fa delimto.Dv NULL ,single whitespace is assumed..Fn ipsec_dump_policyreturns pointer to dynamically allocated string.It is caller's responsibility to reclaim the region, by using.Xr free 3 ..Pp.Fa policyis formatted as either of the following:.Bl -tag -width "discard".It Ar direction Li discard.Ar directionmust be.Li inor.Li out ..Ar directionspecifies which direction the policy needs to be applied.With.Li discardpolicy, packets will be dropped if they match the policy..It Ar direction Li entrust.Li entrustmeans to consult to SPD defined by.Xr setkey 8 ..It Ar direction Li bypass.Li bypassmeans to be bypassed the IPsec processing..Pq packet will be transmitted in clear .This is for privileged socket..It Xo.Ar direction.Li ipsec.Ar request ....Xc.Li ipsecmeans that the matching packets are subject to IPsec processing..Li ipseccan be followed by one or more.Ar requeststring, which is formatted as below:.Bl -tag -width "discard".It Xo.Ar protocol.Li /.Ar mode.Li /.Ar src.Li -.Ar dst.Op Ar /level.Xc.Ar protocolis either.Li ah ,.Li espor.Li ipcomp ..Pp.Ar modeis either.Li transportor.Li tunnel ..Pp.Ar srcand.Ar dstspecifies IPsec endpoint..Ar srcalways means.Dq sending nodeand.Ar dstalways means.Dq receiving node .Therefore, when.Ar directionis.Li in ,.Ar dstis this nodeand.Ar srcis the other node.Pq peer .If.Ar modeis.Li transport ,Both.Ar srcand.Ar dstcan be omited. .Pp.Ar levelmust be set to one of the following:.Li default , use , requireor.Li unique ..Li defaultmeans that the kernel should consult the system default policydefined by.Xr sysctl 8 ,such as.Li net.inet.ipsec.esp_trans_deflev .See.Xr ipsec 4regarding the system default..Li usemeans that a relevant SA can be used when available,since the kernel may perform IPsec operation against packets when possible.In this case, packets can be transmitted in clear.Pq when SA is not available ,or encrypted.Pq when SA is available ..Li requiremeans that a relevant SA is required,since the kernel must perform IPsec operation against packets..Li uniqueis the same as.Li require ,but adds the restriction that the SA for outbound traffic is usedonly for this policy.You may need the identifier in order to relate the policy and the SAwhen you define the SA by manual keying.You can put the decimal number as the identifier after.Li uniquelike.Li unique : number ..Li numbermust be between 1 and 32767 .If the.Ar requeststring is kept unambiguous,.Ar leveland slash prior to.Ar levelcan be omitted.However, it is encouraged to specify them explicitlyto avoid unintended behaviors.If.Ar levelis omitted, it will be interpreted as.Li default ..El.El.PpNote that there is a bit difference of specification from.Xr setkey 8 .In specification by.Xr setkey 8 ,both entrust and bypass are not used.Refer to.Xr setkey 8for detail..PpHere are several examples.Pq long lines are wrapped for readability :.Bd -literal -offset indentin discardout ipsec esp/transport//requirein ipsec ah/transport//requireout ipsec esp/tunnel/10.1.1.2-10.1.1.1/usein ipsec ipcomp/transport//use esp/transport//use.Ed.Sh RETURN VALUES.Fn ipsec_set_policyreturns a pointer to the allocated buffer of policy specification if successful; otherwise a NULL pointer is returned..Fn ipsec_get_policylenreturns with positive value.Pq meaning the buffer sizeon success, and negative value on errors..Fn ipsec_dump_policyreturns a pointer to dynamically allocated region on success,and.Dv NULLon errors..Sh SEE ALSO.Xr ipsec_strerror 3 ,.Xr ipsec 4 ,.Xr setkey 8.Sh HISTORYThe functions first appeared in WIDE/KAME IPv6 protocol stack kit.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?