#ifndef _NETINET6_IPSEC_H_
#define _NETINET6_IPSEC_H_
#include <sys/cdefs.h>
#include <sys/appleapiopts.h>
#include <net/pfkeyv2.h>
#ifdef BSD_KERNEL_PRIVATE
#include <netkey/keydb.h>
#include <netinet/ip_var.h>
extern lck_grp_t *sadb_stat_mutex_grp;
extern lck_grp_attr_t *sadb_stat_mutex_grp_attr;
extern lck_attr_t *sadb_stat_mutex_attr;
extern lck_mtx_t *sadb_stat_mutex;
#define IPSEC_STAT_INCREMENT(x) \
{lck_mtx_lock(sadb_stat_mutex); (x)++; lck_mtx_unlock(sadb_stat_mutex);}
struct secpolicyaddrrange {
struct sockaddr_storage start;
struct sockaddr_storage end;
};
struct secpolicyindex {
u_int8_t dir;
struct sockaddr_storage src;
struct sockaddr_storage dst;
u_int8_t prefs;
u_int8_t prefd;
u_int16_t ul_proto;
ifnet_t internal_if;
struct secpolicyaddrrange src_range;
struct secpolicyaddrrange dst_range;
#ifdef notyet
uid_t uids;
uid_t uidd;
gid_t gids;
gid_t gidd;
#endif
};
struct secpolicy {
LIST_ENTRY(secpolicy) chain;
int refcnt;
struct secpolicyindex spidx;
u_int32_t id;
u_int state;
#define IPSEC_SPSTATE_DEAD 0
#define IPSEC_SPSTATE_ALIVE 1
u_int policy;
struct ipsecrequest *req;
ifnet_t ipsec_if;
ifnet_t outgoing_if;
char disabled;
long created;
long lastused;
long lifetime;
long validtime;
};
struct ipsecrequest {
struct ipsecrequest *next;
struct secasindex saidx;
u_int level;
struct secpolicy *sp;
};
struct inpcbpolicy {
struct secpolicy *sp_in;
struct secpolicy *sp_out;
int priv;
};
struct secspacq {
LIST_ENTRY(secspacq) chain;
struct secpolicyindex spidx;
long created;
int count;
};
#endif
#define IPSEC_PORT_ANY 0
#define IPSEC_ULPROTO_ANY 255
#define IPSEC_PROTO_ANY 255
#define IPSEC_MODE_ANY 0
#define IPSEC_MODE_TRANSPORT 1
#define IPSEC_MODE_TUNNEL 2
#define IPSEC_DIR_ANY 0
#define IPSEC_DIR_INBOUND 1
#define IPSEC_DIR_OUTBOUND 2
#define IPSEC_DIR_MAX 3
#define IPSEC_DIR_INVALID 4
#define IPSEC_POLICY_DISCARD 0
#define IPSEC_POLICY_NONE 1
#define IPSEC_POLICY_IPSEC 2
#define IPSEC_POLICY_ENTRUST 3
#define IPSEC_POLICY_BYPASS 4
#define IPSEC_POLICY_GENERATE 5
#define IPSEC_LEVEL_DEFAULT 0
#define IPSEC_LEVEL_USE 1
#define IPSEC_LEVEL_REQUIRE 2
#define IPSEC_LEVEL_UNIQUE 3
#define IPSEC_MANUAL_REQID_MAX 0x3fff
#define IPSEC_REPLAYWSIZE 32
struct ipsecstat {
u_quad_t in_success;
u_quad_t in_polvio;
u_quad_t in_nosa;
u_quad_t in_inval;
u_quad_t in_nomem;
u_quad_t in_badspi;
u_quad_t in_ahreplay;
u_quad_t in_espreplay;
u_quad_t in_ahauthsucc;
u_quad_t in_ahauthfail;
u_quad_t in_espauthsucc;
u_quad_t in_espauthfail;
u_quad_t in_esphist[256];
u_quad_t in_ahhist[256];
u_quad_t in_comphist[256];
u_quad_t out_success;
u_quad_t out_polvio;
u_quad_t out_nosa;
u_quad_t out_inval;
u_quad_t out_nomem;
u_quad_t out_noroute;
u_quad_t out_esphist[256];
u_quad_t out_ahhist[256];
u_quad_t out_comphist[256];
};
#ifdef BSD_KERNEL_PRIVATE
#define IPSECCTL_STATS 1
#define IPSECCTL_DEF_POLICY 2
#define IPSECCTL_DEF_ESP_TRANSLEV 3
#define IPSECCTL_DEF_ESP_NETLEV 4
#define IPSECCTL_DEF_AH_TRANSLEV 5
#define IPSECCTL_DEF_AH_NETLEV 6
#if 0
#define IPSECCTL_INBOUND_CALL_IKE 7
#endif
#define IPSECCTL_AH_CLEARTOS 8
#define IPSECCTL_AH_OFFSETMASK 9
#define IPSECCTL_DFBIT 10
#define IPSECCTL_ECN 11
#define IPSECCTL_DEBUG 12
#define IPSECCTL_ESP_RANDPAD 13
#define IPSECCTL_MAXID 14
#define IPSECCTL_NAMES { \
{ 0, 0 }, \
{ 0, 0 }, \
{ "def_policy", CTLTYPE_INT }, \
{ "esp_trans_deflev", CTLTYPE_INT }, \
{ "esp_net_deflev", CTLTYPE_INT }, \
{ "ah_trans_deflev", CTLTYPE_INT }, \
{ "ah_net_deflev", CTLTYPE_INT }, \
{ 0, 0 }, \
{ "ah_cleartos", CTLTYPE_INT }, \
{ "ah_offsetmask", CTLTYPE_INT }, \
{ "dfbit", CTLTYPE_INT }, \
{ "ecn", CTLTYPE_INT }, \
{ "debug", CTLTYPE_INT }, \
{ "esp_randpad", CTLTYPE_INT }, \
}
#define IPSEC6CTL_NAMES { \
{ 0, 0 }, \
{ 0, 0 }, \
{ "def_policy", CTLTYPE_INT }, \
{ "esp_trans_deflev", CTLTYPE_INT }, \
{ "esp_net_deflev", CTLTYPE_INT }, \
{ "ah_trans_deflev", CTLTYPE_INT }, \
{ "ah_net_deflev", CTLTYPE_INT }, \
{ 0, 0 }, \
{ 0, 0 }, \
{ 0, 0 }, \
{ 0, 0 }, \
{ "ecn", CTLTYPE_INT }, \
{ "debug", CTLTYPE_INT }, \
{ "esp_randpad", CTLTYPE_INT }, \
}
#define IPSEC_IS_P2ALIGNED(p) 1
#define IPSEC_GET_P2UNALIGNED_OFS(p) 0
struct ipsec_output_state {
int tunneled;
struct mbuf *m;
struct route ro;
struct sockaddr *dst;
u_int outgoing_if;
};
struct ipsec_history {
int ih_proto;
u_int32_t ih_spi;
};
extern int ipsec_debug;
extern struct ipsecstat ipsecstat;
extern struct secpolicy ip4_def_policy;
extern int ip4_esp_trans_deflev;
extern int ip4_esp_net_deflev;
extern int ip4_ah_trans_deflev;
extern int ip4_ah_net_deflev;
extern int ip4_ah_cleartos;
extern int ip4_ah_offsetmask;
extern int ip4_ipsec_dfbit;
extern int ip4_ipsec_ecn;
extern int ip4_esp_randpad;
#define ipseclog(x) do { if (ipsec_debug) log x; } while (0)
extern struct secpolicy *ipsec4_getpolicybysock(struct mbuf *, u_int,
struct socket *, int *);
extern struct secpolicy *ipsec4_getpolicybyaddr(struct mbuf *, u_int, int,
int *);
extern int ipsec4_getpolicybyinterface(struct mbuf *, u_int, int *,
struct ip_out_args *, struct secpolicy **);
extern u_int ipsec_get_reqlevel(struct ipsecrequest *);
struct inpcb;
extern int ipsec_init_policy(struct socket *so, struct inpcbpolicy **);
extern int ipsec_copy_policy(struct inpcbpolicy *, struct inpcbpolicy *);
extern u_int ipsec_get_reqlevel(struct ipsecrequest *);
extern int ipsec4_set_policy(struct inpcb *inp, int optname,
caddr_t request, size_t len, int priv);
extern int ipsec4_delete_pcbpolicy(struct inpcb *);
extern int ipsec4_in_reject_so(struct mbuf *, struct socket *);
extern int ipsec4_in_reject(struct mbuf *, struct inpcb *);
struct secas;
struct tcpcb;
extern int ipsec_chkreplay(u_int32_t, struct secasvar *);
extern int ipsec_updatereplay(u_int32_t, struct secasvar *);
extern size_t ipsec4_hdrsiz(struct mbuf *, u_int, struct inpcb *);
extern size_t ipsec_hdrsiz_tcp(struct tcpcb *);
extern size_t ipsec_hdrsiz(struct secpolicy *);
struct ip;
extern const char *ipsec4_logpacketstr(struct ip *, u_int32_t);
extern const char *ipsec_logsastr(struct secasvar *);
extern void ipsec_dumpmbuf(struct mbuf *);
extern int ipsec4_interface_output(struct ipsec_output_state *state, ifnet_t interface);
extern int ipsec4_output(struct ipsec_output_state *, struct secpolicy *, int);
#if INET
extern struct mbuf * ipsec4_splithdr(struct mbuf *);
extern int ipsec4_encapsulate(struct mbuf *, struct secasvar *);
extern int ipsec4_encapsulate_utun_esp_keepalive(struct mbuf **, struct secasvar *);
#endif
#if INET6
extern struct mbuf * ipsec6_splithdr(struct mbuf *);
extern int ipsec6_encapsulate(struct mbuf *, struct secasvar *);
extern int ipsec6_encapsulate_utun_esp_keepalive(struct mbuf **, struct secasvar *);
#endif
extern int ipsec4_tunnel_validate(struct mbuf *, int, u_int, struct secasvar *, sa_family_t *);
extern struct mbuf *ipsec_copypkt(struct mbuf *);
extern void ipsec_delaux(struct mbuf *);
extern int ipsec_setsocket(struct mbuf *, struct socket *);
extern struct socket *ipsec_getsocket(struct mbuf *);
extern int ipsec_addhist(struct mbuf *, int, u_int32_t);
extern struct ipsec_history *ipsec_gethist(struct mbuf *, int *);
extern void ipsec_clearhist(struct mbuf *);
#endif
#ifndef KERNEL
__BEGIN_DECLS
extern caddr_t ipsec_set_policy(char *, int);
extern int ipsec_get_policylen(caddr_t);
extern char *ipsec_dump_policy(caddr_t, char *);
extern const char *ipsec_strerror(void);
__END_DECLS
#endif
#endif