/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/* All of the structures in this file may not change size as they are
* passed into the kernel from userspace via netlink sockets.
/* Structure to encapsulate addresses. I do not want to use
* "standard" structure. My apologies.
/* Ident of a specific xfrm_state. It is used on input to lookup
* the state by (spi,daddr,ah/esp) or to store information about
* spi, protocol and tunnel address on output.
/* Security Context Domains of Interpretation */
#define XFRM_SC_DOI_RESERVED 0
#define XFRM_SC_DOI_LSM 1
/* Security Context Algorithms */
#define XFRM_SC_ALG_RESERVED 0
#define XFRM_SC_ALG_SELINUX 1
/* Selector, used as selector both on policy rules (SPD) and SAs. */
#define XFRM_INF (~(__u64)0)
struct xfrm_lifetime_cfg {
__u64 soft_add_expires_seconds;
__u64 hard_add_expires_seconds;
__u64 soft_use_expires_seconds;
__u64 hard_use_expires_seconds;
struct xfrm_lifetime_cur {
struct xfrm_replay_state {
#define XFRMA_REPLAY_ESN_MAX 4096
struct xfrm_replay_state_esn {
unsigned int alg_key_len; /* in bits */
unsigned int alg_key_len; /* in bits */
unsigned int alg_trunc_len; /* in bits */
unsigned int alg_key_len; /* in bits */
unsigned int alg_icv_len; /* in bits */
XFRM_POLICY_TYPE_MAIN = 0,
XFRM_POLICY_TYPE_SUB = 1,
XFRM_POLICY_TYPE_MAX = 2,
XFRM_POLICY_TYPE_ANY = 255
XFRM_SHARE_ANY, /* No limitations */
XFRM_SHARE_SESSION, /* For this session only */
XFRM_SHARE_USER, /* For this user only */
XFRM_SHARE_UNIQUE /* Use once */
#define XFRM_MODE_TRANSPORT 0
#define XFRM_MODE_TUNNEL 1
#define XFRM_MODE_ROUTEOPTIMIZATION 2
#define XFRM_MODE_IN_TRIGGER 3
/* Netlink configuration messages. */
#define XFRM_MSG_NEWSA XFRM_MSG_NEWSA
#define XFRM_MSG_DELSA XFRM_MSG_DELSA
#define XFRM_MSG_GETSA XFRM_MSG_GETSA
#define XFRM_MSG_NEWPOLICY XFRM_MSG_NEWPOLICY
#define XFRM_MSG_DELPOLICY XFRM_MSG_DELPOLICY
#define XFRM_MSG_GETPOLICY XFRM_MSG_GETPOLICY
#define XFRM_MSG_ALLOCSPI XFRM_MSG_ALLOCSPI
#define XFRM_MSG_ACQUIRE XFRM_MSG_ACQUIRE
#define XFRM_MSG_EXPIRE XFRM_MSG_EXPIRE
#define XFRM_MSG_UPDPOLICY XFRM_MSG_UPDPOLICY
#define XFRM_MSG_UPDSA XFRM_MSG_UPDSA
#define XFRM_MSG_POLEXPIRE XFRM_MSG_POLEXPIRE
#define XFRM_MSG_FLUSHSA XFRM_MSG_FLUSHSA
#define XFRM_MSG_FLUSHPOLICY XFRM_MSG_FLUSHPOLICY
#define XFRM_MSG_NEWAE XFRM_MSG_NEWAE
#define XFRM_MSG_GETAE XFRM_MSG_GETAE
#define XFRM_MSG_REPORT XFRM_MSG_REPORT
#define XFRM_MSG_MIGRATE XFRM_MSG_MIGRATE
#define XFRM_MSG_NEWSADINFO XFRM_MSG_NEWSADINFO
#define XFRM_MSG_GETSADINFO XFRM_MSG_GETSADINFO
#define XFRM_MSG_NEWSPDINFO XFRM_MSG_NEWSPDINFO
#define XFRM_MSG_GETSPDINFO XFRM_MSG_GETSPDINFO
#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING
#define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)
#define XFRM_NR_MSGTYPES (XFRM_MSG_MAX + 1 - XFRM_MSG_BASE)
* Generic LSM security context for comunicating to user space
* NOTE: Same format as sadb_x_sec_ctx
struct xfrm_user_sec_ctx {
__u8 ctx_alg; /* LSMs: e.g., selinux == 1 */
XFRM_AE_RTHR=1, /* replay threshold*/
XFRM_AE_RVAL=2, /* replay value */
XFRM_AE_LVAL=4, /* lifetime value */
XFRM_AE_ETHR=8, /* expiry timer threshold */
XFRM_AE_CR=16, /* Event cause is replay update */
XFRM_AE_CE=32, /* Event cause is timer expiry */
XFRM_AE_CU=64, /* Event cause is policy update */
#define XFRM_AE_MAX (__XFRM_AE_MAX - 1)
struct xfrm_userpolicy_type {
/* Netlink message attributes. */
XFRMA_ALG_AUTH, /* struct xfrm_algo */
XFRMA_ALG_CRYPT, /* struct xfrm_algo */
XFRMA_ALG_COMP, /* struct xfrm_algo */
XFRMA_ENCAP, /* struct xfrm_algo + struct xfrm_encap_tmpl */
XFRMA_TMPL, /* 1 or more struct xfrm_user_tmpl */
XFRMA_SA, /* struct xfrm_usersa_info */
XFRMA_POLICY, /*struct xfrm_userpolicy_info */
XFRMA_SEC_CTX, /* struct xfrm_sec_ctx */
XFRMA_SRCADDR, /* xfrm_address_t */
XFRMA_COADDR, /* xfrm_address_t */
XFRMA_LASTUSED, /* unsigned long */
XFRMA_POLICY_TYPE, /* struct xfrm_userpolicy_type */
XFRMA_ALG_AEAD, /* struct xfrm_algo_aead */
XFRMA_KMADDRESS, /* struct xfrm_user_kmaddress */
XFRMA_ALG_AUTH_TRUNC, /* struct xfrm_algo_auth */
XFRMA_MARK, /* struct xfrm_mark */
XFRMA_TFCPAD, /* __u32 */
XFRMA_REPLAY_ESN_VAL, /* struct xfrm_replay_state_esn */
XFRMA_SA_EXTRA_FLAGS, /* __u32 */
XFRMA_ADDRESS_FILTER, /* struct xfrm_address_filter */
XFRMA_OFFLOAD_DEV, /* struct xfrm_user_offload */
XFRMA_SET_MARK, /* __u32 */
XFRMA_SET_MARK_MASK, /* __u32 */
#define XFRMA_OUTPUT_MARK XFRMA_SET_MARK /* Compatibility */
#define XFRMA_MAX (__XFRMA_MAX - 1)
enum xfrm_sadattr_type_t {
#define XFRMA_SAD_MAX (__XFRMA_SAD_MAX - 1)
__u32 sadhcnt; /* current hash bkts */
__u32 sadhmcnt; /* max allowed hash bkts */
enum xfrm_spdattr_type_t {
#define XFRMA_SPD_MAX (__XFRMA_SPD_MAX - 1)
struct xfrmu_spdhthresh {
struct xfrm_usersa_info {
struct xfrm_selector sel;
struct xfrm_lifetime_cfg lft;
struct xfrm_lifetime_cur curlft;
__u8 mode; /* XFRM_MODE_xxx */
#define XFRM_STATE_NOECN 1
#define XFRM_STATE_DECAP_DSCP 2
#define XFRM_STATE_NOPMTUDISC 4
#define XFRM_STATE_WILDRECV 8
#define XFRM_STATE_ICMP 16
#define XFRM_STATE_AF_UNSPEC 32
#define XFRM_STATE_ALIGN4 64
#define XFRM_STATE_ESN 128
#define XFRM_SA_XFLAG_DONT_ENCAP_DSCP 1
struct xfrm_usersa_id sa_id;
struct xfrm_userspi_info {
struct xfrm_usersa_info info;
struct xfrm_userpolicy_info {
struct xfrm_selector sel;
struct xfrm_lifetime_cfg lft;
struct xfrm_lifetime_cur curlft;
#define XFRM_POLICY_ALLOW 0
#define XFRM_POLICY_BLOCK 1
#define XFRM_POLICY_LOCALOK 1 /* Allow user to override global policy */
/* Automatically expand selector to include matching ICMP payloads. */
#define XFRM_POLICY_ICMP 2
struct xfrm_userpolicy_id {
struct xfrm_selector sel;
struct xfrm_user_acquire {
struct xfrm_selector sel;
struct xfrm_userpolicy_info policy;
struct xfrm_user_expire {
struct xfrm_usersa_info state;
struct xfrm_user_polexpire {
struct xfrm_userpolicy_info pol;
struct xfrm_usersa_flush {
struct xfrm_user_report {
struct xfrm_selector sel;
/* Used by MIGRATE to pass addresses IKE should use to perform
* SA negotiation with the peer */
struct xfrm_user_kmaddress {
struct xfrm_user_migrate {
xfrm_address_t old_daddr;
xfrm_address_t old_saddr;
xfrm_address_t new_daddr;
xfrm_address_t new_saddr;
struct xfrm_user_mapping {
struct xfrm_usersa_id id;
xfrm_address_t old_saddr;
xfrm_address_t new_saddr;
struct xfrm_address_filter {