|
|
ipsec_set_policy will return the buffer of IPsec policy specification structure. The buffer is dynamically allocated, and must be freed by the caller by calling free(S). You may want the length of the generated buffer such when calling setsockopt(S). 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 a IPsec policy structure, struct sadb_x_policy delim is a delimiter string, which is usually a blank character. If you set delim to NULL, single whitespace is assumed. ipsec_dump_policy returns a pointer to a dynamically allocated string. It is the caller's responsibility to reclaim the region, by using free(S).
policy is formatted as either of the following:
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 dst is this node and src is the other node (peer) If mode is transport Both src and dst can be omitted.
level must be set to one of the following: default , use , require or unique default means that the kernel should consult the system default policy 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 transmitted in clear (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 outbound traffic is used only for this policy. You may need the identifier in 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 is kept unambiguous, level and slash prior to level can be omitted. However, 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(ADM). In specification by setkey(ADM), both entrust and bypass are not used. Refer to setkey(ADM) for detail.
Here are several examples (long lines are wrapped for readability)
in discard out ipsec esp/transport//require in ipsec ah/transport//require out ipsec esp/tunnel/10.1.1.2-10.1.1.1/use in ipsec ipcomp/transport//use esp/transport//use