This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Generate an IPsec policy specification structure from a readable string
#include <netinet6/ipsec.h> char* ipsec_set_policy(char *policy, int len);
libipsec
Use the -l ipsec option to qcc to link against this library.
The function ipsec_set_policy() generates an IPsec policy specification structure, namely a struct sadb_x_policy and potentially a struct sadb_x_ipsecrequest from a human-readable policy specification. This function returns a pointer to the IPsec policy specification structure.
You should release the buffer returned by ipsec_set_policy() by calling free(). See the example below. |
The policy is formatted as one of the following:
protocol / mode / src - dst [/level]
unique: number
where number must be between 1 and 32767. If the request string is kept unambiguous, you can omit the level and the slash ("/") prior to level. However, you should specify them explicitly to avoid unintended behavior. If level is omitted, it will be interpreted as default.
Here's an example of policy information:
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 ipcom/transport//use esp/transport//use
It differs from the specification of setkey, where both entrust and bypass are not used. Please refer to setkey for detail. |
A pointer to the allocated policy specification, or NULL if an error occurs.
#include <netinet6/ipsec.h> #include <sys/socket.h> #include <stdio.h> #include <malloc.h> #include <string.h> int main(void) { char *sadb; char *policy = "in discard"; int len; sadb = ipsec_set_policy(policy, strlen(policy)); if (sadb == NULL) { fprintf(stderr, "ipsec_set_policy: %s\n", ipsec_strerror()); return 1; } len = ipsec_get_policylen(sadb); printf("len: %d\n", len); policy = NULL; policy = ipsec_dump_policy(sadb, NULL); if (policy == NULL) { fprintf(stderr, "ipsec_dump_policy: %s\n", ipsec_strerror()); return 1; } printf("policy: %s\n", policy); free(policy); free(sadb); return 0; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
IPsec, ipsec_dump_policy(), ipsec_get_policylen(), ipsec_strerror()
setkey in the Utilities Reference