Seth Woolley's Man Viewer

ipsec_set_policy(3) - ipsec_dump_policy, ipsec_get_policylen, ipsec_set_policy, ipsec_dump_policy, ipsec_get_policylen, ipsec_set_policy - manipulate IPsec policy specification structure from readable string - man 3 ipsec_set_policy

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

IPSEC_SET_POLICY(3)      BSD Library Functions Manual      IPSEC_SET_POLICY(3)

     ipsec_set_policy, ipsec_get_policylen, ipsec_dump_policy -- manipulate
     IPsec policy specification structure from readable string(3,n)

     IPsec Policy Control Library (libipsec, -lipsec)

     #include <netinet6/ipsec.h>

     char *
     ipsec_set_policy(char *policy, int len);

     ipsec_get_policylen(char *buf);

     char *
     ipsec_dump_policy(char *buf, char *delim);

     ipsec_set_policy() generates IPsec policy specification structure, namely
     struct sadb_x_policy and/or struct sadb_x_ipsecrequest from human-read-
     able policy specification.  policy specification must be given as C
     string(3,n) policy and length len of policy.  ipsec_set_policy() will return
     the buffer of IPsec policy specification structure.  The buffer is dynam-
     ically allocated, and must be freed by the caller by calling free(3).

     You may want the length of the generated buffer such when calling
     setsockopt(2).  ipsec_get_policylen() will return the length.

     ipsec_dump_policy() converts IPsec policy structure into readable form.
     Therefore, ipsec_dump_policy() can be regarded as inverse conversion of
     ipsec_set_policy().  buf points to an IPsec policy structure, struct
     sadb_x_policy.  delim is a delimiter string(3,n), which is usually a blank
     character.  If you set(7,n,1 builtins) delim to NULL, single whitespace is assumed.
     ipsec_dump_policy() returns pointer to dynamically allocated string.  It
     is caller's responsibility to reclaim the region, by using free(3).

     policy is formatted as either of the following:

     direction [priority specification] discard
              direction must be in(1,8) , out or fwd.  direction specifies which
              direction the policy needs to be applied. Nonstandard direction
              fwd is substituted with in(1,8) on platforms which do not support
              forward policies.

              priority specification is used to control the placement of the
              policy within the SPD. Policy position is determined by a signed
              integer where higher priorities indicate the policy is placed
              closer to the beginning of the list and lower priorities indi-
              cate the policy is placed closer to the end of the list. Poli-
              cies with equal priorities are added at the end of the group of
              such policies.

              Priority can only be specified when libipsec has been compiled
              against kernel headers that support policy priorities (>=
              2.6.6). It takes one of the following formats:

              {priority,prio} offset
                       offset is an integer in(1,8) ranges -2147483647 ..

              {priority,prio} base {+,-} offset
                       base is either low (-1073741824), def (0), or high

                       offset is an unsigned integer. It can be up to
                       1073741824 for positive offsets, and up to 1073741823
                       for negative offsets.

              The interpretation of policy priority in(1,8) these functions and the
              kernel DOES differ. The relationship between the two can be
              described as p(kernel) = 0x80000000 - p(func)

              With discard policy, packets will be dropped if(3,n) they match the

     direction [priority specification] entrust
              entrust means to consult to SPD defined by setkey(8).

     direction [priority specification] bypass
              bypass means to be bypassed the IPsec processing.  (packet will
              be transmitted in(1,8) clear(1,3x,3x clrtobot)).  This is for privileged socket.

     direction [priority specification] ipsec(5,8) request ...
              ipsec(5,8) means that the matching packets are subject to IPsec pro-
              cessing.  ipsec(5,8) can be followed by one or more request string(3,n),
              which is formatted as below:

              protocol / mode / src - dst [/level]
                       protocol is either ah, esp or ipcomp.

                       mode is either transport or tunnel.

                       src and dst specifies IPsec endpoint.  src always means
                       ``sending node'' and dst always means ``receiving
                       node''.  Therefore, when direction is in(1,8), dst is this
                       node and src is the other node (peer).  If mode is
                       transport, Both src and dst can be omited.

                       level must be set(7,n,1 builtins) to one of the following: default,
                       use, require or unique.  default means that the kernel
                       should consult the system default policy defined by
                       sysctl(2,5,8)(8), such as net.inet.ipsec.esp_trans_deflev.
                       See ipsec(5,8)(4) regarding the system default.  use means
                       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 transmit-
                       ted in(1,8) clear(1,3x,3x clrtobot) (when SA is not available), or encrypted
                       (when SA is available).  require means that a relevant
                       SA is required, since the kernel must perform IPsec
                       operation against packets.  unique is the same as
                       require, but adds the restriction that the SA for out-
                       bound traffic is used only for this policy.  You may
                       need the identifier in(1,8) order to relate the policy and
                       the SA when you define the SA by manual keying.  You
                       can put the decimal number as the identifier after
                       unique like unique: number.  number must be between 1
                       and 32767 .  If the request string(3,n) is kept unambiguous,
                       level and slash prior to level can be omitted.  How-
                       ever, it is encouraged to specify them explicitly to
                       avoid unintended behaviors.  If level is omitted, it
                       will be interpreted as default.

              Note that there is a bit difference of specification from
              setkey(8).  In specification by setkey(8), both entrust and
              bypass are not used.  Refer to setkey(8) for detail.

              Here are several examples (long lines are wrapped for

                    in(1,8) discard
                    out ipsec(5,8) esp/transport//require
                    in(1,8) ipsec(5,8) ah/transport//require
                    out ipsec(5,8) esp/tunnel/
                    in(1,8) ipsec(5,8) ipcomp/transport//use

     ipsec_set_policy() returns a pointer to the allocated buffer of policy
     specification if(3,n) successful; otherwise a NULL pointer is returned.
     ipsec_get_policylen() returns with positive value (meaning the buffer
     size) on success, and negative value on errors.  ipsec_dump_policy()
     returns a pointer to dynamically allocated region on success, and NULL on

     ipsec_strerror(3), ipsec(5,8)(4), setkey(8)

     The functions first appeared in(1,8) WIDE/KAME IPv6 protocol stack kit.

KAME                              May 5, 1998                             KAME

References for this manual (incoming links)