darwin-xnu/bsd/netinet6/ipsec.h
<<
>>
Prefs
   1/*      $FreeBSD: src/sys/netinet6/ipsec.h,v 1.4.2.2 2001/07/03 11:01:54 ume Exp $      */
   2/*      $KAME: ipsec.h,v 1.44 2001/03/23 08:08:47 itojun Exp $  */
   3
   4/*
   5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
   6 * All rights reserved.
   7 *
   8 * Redistribution and use in source and binary forms, with or without
   9 * modification, are permitted provided that the following conditions
  10 * are met:
  11 * 1. Redistributions of source code must retain the above copyright
  12 *    notice, this list of conditions and the following disclaimer.
  13 * 2. Redistributions in binary form must reproduce the above copyright
  14 *    notice, this list of conditions and the following disclaimer in the
  15 *    documentation and/or other materials provided with the distribution.
  16 * 3. Neither the name of the project nor the names of its contributors
  17 *    may be used to endorse or promote products derived from this software
  18 *    without specific prior written permission.
  19 *
  20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30 * SUCH DAMAGE.
  31 */
  32
  33/*
  34 * IPsec controller part.
  35 */
  36
  37#ifndef _NETINET6_IPSEC_H_
  38#define _NETINET6_IPSEC_H_
  39#include <sys/appleapiopts.h>
  40
  41#include <net/pfkeyv2.h>
  42#ifdef KERNEL_PRIVATE
  43#include <netkey/keydb.h>
  44
  45/*
  46 * Security Policy Index
  47 * Ensure that both address families in the "src" and "dst" are same.
  48 * When the value of the ul_proto is ICMPv6, the port field in "src"
  49 * specifies ICMPv6 type, and the port field in "dst" specifies ICMPv6 code.
  50 */
  51struct secpolicyindex {
  52        u_int8_t dir;                   /* direction of packet flow, see blow */
  53        struct sockaddr_storage src;    /* IP src address for SP */
  54        struct sockaddr_storage dst;    /* IP dst address for SP */
  55        u_int8_t prefs;                 /* prefix length in bits for src */
  56        u_int8_t prefd;                 /* prefix length in bits for dst */
  57        u_int16_t ul_proto;             /* upper layer Protocol */
  58#ifdef notyet
  59        uid_t uids;
  60        uid_t uidd;
  61        gid_t gids;
  62        gid_t gidd;
  63#endif
  64};
  65
  66/* Security Policy Data Base */
  67struct secpolicy {
  68        LIST_ENTRY(secpolicy) chain;
  69
  70        int refcnt;                     /* reference count */
  71        struct secpolicyindex spidx;    /* selector */
  72        u_int32_t id;                   /* It's unique number on the system. */
  73        u_int state;                    /* 0: dead, others: alive */
  74#define IPSEC_SPSTATE_DEAD      0
  75#define IPSEC_SPSTATE_ALIVE     1
  76
  77        u_int policy;           /* DISCARD, NONE or IPSEC, see keyv2.h */
  78        struct ipsecrequest *req;
  79                                /* pointer to the ipsec request tree, */
  80                                /* if policy == IPSEC else this value == NULL.*/
  81
  82        /*
  83         * lifetime handler.
  84         * the policy can be used without limitiation if both lifetime and
  85         * validtime are zero.
  86         * "lifetime" is passed by sadb_lifetime.sadb_lifetime_addtime.
  87         * "validtime" is passed by sadb_lifetime.sadb_lifetime_usetime.
  88         */
  89        long created;           /* time created the policy */
  90        long lastused;          /* updated every when kernel sends a packet */
  91        long lifetime;          /* duration of the lifetime of this policy */
  92        long validtime;         /* duration this policy is valid without use */
  93};
  94
  95/* Request for IPsec */
  96struct ipsecrequest {
  97        struct ipsecrequest *next;
  98                                /* pointer to next structure */
  99                                /* If NULL, it means the end of chain. */
 100        struct secasindex saidx;/* hint for search proper SA */
 101                                /* if __ss_len == 0 then no address specified.*/
 102        u_int level;            /* IPsec level defined below. */
 103
 104        struct secasvar *sav;   /* place holder of SA for use */
 105        struct secpolicy *sp;   /* back pointer to SP */
 106};
 107
 108/* security policy in PCB */
 109struct inpcbpolicy {
 110        struct secpolicy *sp_in;
 111        struct secpolicy *sp_out;
 112        int priv;                       /* privileged socket ? */
 113};
 114
 115/* SP acquiring list table. */
 116struct secspacq {
 117        LIST_ENTRY(secspacq) chain;
 118
 119        struct secpolicyindex spidx;
 120
 121        long created;           /* for lifetime */
 122        int count;              /* for lifetime */
 123        /* XXX: here is mbuf place holder to be sent ? */
 124};
 125#endif /* KERNEL_PRIVATE */
 126
 127/* according to IANA assignment, port 0x0000 and proto 0xff are reserved. */
 128#define IPSEC_PORT_ANY          0
 129#define IPSEC_ULPROTO_ANY       255
 130#define IPSEC_PROTO_ANY         255
 131
 132/* mode of security protocol */
 133/* NOTE: DON'T use IPSEC_MODE_ANY at SPD.  It's only use in SAD */
 134#define IPSEC_MODE_ANY          0       /* i.e. wildcard. */
 135#define IPSEC_MODE_TRANSPORT    1
 136#define IPSEC_MODE_TUNNEL       2
 137
 138/*
 139 * Direction of security policy.
 140 * NOTE: Since INVALID is used just as flag.
 141 * The other are used for loop counter too.
 142 */
 143#define IPSEC_DIR_ANY           0
 144#define IPSEC_DIR_INBOUND       1
 145#define IPSEC_DIR_OUTBOUND      2
 146#define IPSEC_DIR_MAX           3
 147#define IPSEC_DIR_INVALID       4
 148
 149/* Policy level */
 150/*
 151 * IPSEC, ENTRUST and BYPASS are allowed for setsockopt() in PCB,
 152 * DISCARD, IPSEC and NONE are allowed for setkey() in SPD.
 153 * DISCARD and NONE are allowed for system default.
 154 */
 155#define IPSEC_POLICY_DISCARD    0       /* discarding packet */
 156#define IPSEC_POLICY_NONE       1       /* through IPsec engine */
 157#define IPSEC_POLICY_IPSEC      2       /* do IPsec */
 158#define IPSEC_POLICY_ENTRUST    3       /* consulting SPD if present. */
 159#define IPSEC_POLICY_BYPASS     4       /* only for privileged socket. */
 160
 161/* Security protocol level */
 162#define IPSEC_LEVEL_DEFAULT     0       /* reference to system default */
 163#define IPSEC_LEVEL_USE         1       /* use SA if present. */
 164#define IPSEC_LEVEL_REQUIRE     2       /* require SA. */
 165#define IPSEC_LEVEL_UNIQUE      3       /* unique SA. */
 166
 167#define IPSEC_MANUAL_REQID_MAX  0x3fff
 168                                /*
 169                                 * if security policy level == unique, this id
 170                                 * indicate to a relative SA for use, else is
 171                                 * zero.
 172                                 * 1 - 0x3fff are reserved for manual keying.
 173                                 * 0 are reserved for above reason.  Others is
 174                                 * for kernel use.
 175                                 * Note that this id doesn't identify SA
 176                                 * by only itself.
 177                                 */
 178#define IPSEC_REPLAYWSIZE  32
 179
 180/* statistics for ipsec processing */
 181struct ipsecstat {
 182        u_quad_t in_success;  /* succeeded inbound process */
 183        u_quad_t in_polvio;
 184                        /* security policy violation for inbound process */
 185        u_quad_t in_nosa;     /* inbound SA is unavailable */
 186        u_quad_t in_inval;    /* inbound processing failed due to EINVAL */
 187        u_quad_t in_nomem;    /* inbound processing failed due to ENOBUFS */
 188        u_quad_t in_badspi;   /* failed getting a SPI */
 189        u_quad_t in_ahreplay; /* AH replay check failed */
 190        u_quad_t in_espreplay; /* ESP replay check failed */
 191        u_quad_t in_ahauthsucc; /* AH authentication success */
 192        u_quad_t in_ahauthfail; /* AH authentication failure */
 193        u_quad_t in_espauthsucc; /* ESP authentication success */
 194        u_quad_t in_espauthfail; /* ESP authentication failure */
 195        u_quad_t in_esphist[256];
 196        u_quad_t in_ahhist[256];
 197        u_quad_t in_comphist[256];
 198        u_quad_t out_success; /* succeeded outbound process */
 199        u_quad_t out_polvio;
 200                        /* security policy violation for outbound process */
 201        u_quad_t out_nosa;    /* outbound SA is unavailable */
 202        u_quad_t out_inval;   /* outbound process failed due to EINVAL */
 203        u_quad_t out_nomem;    /* inbound processing failed due to ENOBUFS */
 204        u_quad_t out_noroute; /* there is no route */
 205        u_quad_t out_esphist[256];
 206        u_quad_t out_ahhist[256];
 207        u_quad_t out_comphist[256];
 208};
 209
 210#ifdef KERNEL_PRIVATE
 211/*
 212 * Definitions for IPsec & Key sysctl operations.
 213 */
 214/*
 215 * Names for IPsec & Key sysctl objects
 216 */
 217#define IPSECCTL_STATS                  1       /* stats */
 218#define IPSECCTL_DEF_POLICY             2
 219#define IPSECCTL_DEF_ESP_TRANSLEV       3       /* int; ESP transport mode */
 220#define IPSECCTL_DEF_ESP_NETLEV         4       /* int; ESP tunnel mode */
 221#define IPSECCTL_DEF_AH_TRANSLEV        5       /* int; AH transport mode */
 222#define IPSECCTL_DEF_AH_NETLEV          6       /* int; AH tunnel mode */
 223#if 0   /* obsolete, do not reuse */
 224#define IPSECCTL_INBOUND_CALL_IKE       7
 225#endif
 226#define IPSECCTL_AH_CLEARTOS            8
 227#define IPSECCTL_AH_OFFSETMASK          9
 228#define IPSECCTL_DFBIT                  10
 229#define IPSECCTL_ECN                    11
 230#define IPSECCTL_DEBUG                  12
 231#define IPSECCTL_ESP_RANDPAD            13
 232#define IPSECCTL_MAXID                  14
 233
 234#define IPSECCTL_NAMES { \
 235        { 0, 0 }, \
 236        { 0, 0 }, \
 237        { "def_policy", CTLTYPE_INT }, \
 238        { "esp_trans_deflev", CTLTYPE_INT }, \
 239        { "esp_net_deflev", CTLTYPE_INT }, \
 240        { "ah_trans_deflev", CTLTYPE_INT }, \
 241        { "ah_net_deflev", CTLTYPE_INT }, \
 242        { 0, 0 }, \
 243        { "ah_cleartos", CTLTYPE_INT }, \
 244        { "ah_offsetmask", CTLTYPE_INT }, \
 245        { "dfbit", CTLTYPE_INT }, \
 246        { "ecn", CTLTYPE_INT }, \
 247        { "debug", CTLTYPE_INT }, \
 248        { "esp_randpad", CTLTYPE_INT }, \
 249}
 250
 251#define IPSEC6CTL_NAMES { \
 252        { 0, 0 }, \
 253        { 0, 0 }, \
 254        { "def_policy", CTLTYPE_INT }, \
 255        { "esp_trans_deflev", CTLTYPE_INT }, \
 256        { "esp_net_deflev", CTLTYPE_INT }, \
 257        { "ah_trans_deflev", CTLTYPE_INT }, \
 258        { "ah_net_deflev", CTLTYPE_INT }, \
 259        { 0, 0 }, \
 260        { 0, 0 }, \
 261        { 0, 0 }, \
 262        { 0, 0 }, \
 263        { "ecn", CTLTYPE_INT }, \
 264        { "debug", CTLTYPE_INT }, \
 265        { "esp_randpad", CTLTYPE_INT }, \
 266}
 267
 268#ifdef KERNEL
 269struct ipsec_output_state {
 270        struct mbuf *m;
 271        struct route *ro;
 272        struct sockaddr *dst;
 273};
 274
 275struct ipsec_history {
 276        int ih_proto;
 277        u_int32_t ih_spi;
 278};
 279
 280extern int ipsec_debug;
 281
 282extern struct ipsecstat ipsecstat;
 283extern struct secpolicy ip4_def_policy;
 284extern int ip4_esp_trans_deflev;
 285extern int ip4_esp_net_deflev;
 286extern int ip4_ah_trans_deflev;
 287extern int ip4_ah_net_deflev;
 288extern int ip4_ah_cleartos;
 289extern int ip4_ah_offsetmask;
 290extern int ip4_ipsec_dfbit;
 291extern int ip4_ipsec_ecn;
 292extern int ip4_esp_randpad;
 293
 294#define ipseclog(x)     do { if (ipsec_debug) log x; } while (0)
 295
 296extern struct secpolicy *ipsec4_getpolicybysock(struct mbuf *, u_int,
 297                                                struct socket *, int *);
 298extern struct secpolicy *ipsec4_getpolicybyaddr(struct mbuf *, u_int, int,
 299                                                int *);
 300
 301struct inpcb;
 302extern int ipsec_init_policy(struct socket *so, struct inpcbpolicy **);
 303extern int ipsec_copy_policy(struct inpcbpolicy *, struct inpcbpolicy *);
 304extern u_int ipsec_get_reqlevel(struct ipsecrequest *);
 305
 306extern int ipsec4_set_policy(struct inpcb *inp, int optname,
 307        caddr_t request, size_t len, int priv);
 308extern int ipsec4_get_policy(struct inpcb *inpcb, caddr_t request,
 309        size_t len, struct mbuf **mp);
 310extern int ipsec4_delete_pcbpolicy(struct inpcb *);
 311extern int ipsec4_in_reject_so(struct mbuf *, struct socket *);
 312extern int ipsec4_in_reject(struct mbuf *, struct inpcb *);
 313
 314struct secas;
 315struct tcpcb;
 316extern int ipsec_chkreplay(u_int32_t, struct secasvar *);
 317extern int ipsec_updatereplay(u_int32_t, struct secasvar *);
 318
 319extern size_t ipsec4_hdrsiz(struct mbuf *, u_int, struct inpcb *);
 320extern size_t ipsec_hdrsiz_tcp(struct tcpcb *);
 321
 322struct ip;
 323extern const char *ipsec4_logpacketstr(struct ip *, u_int32_t);
 324extern const char *ipsec_logsastr(struct secasvar *);
 325
 326extern void ipsec_dumpmbuf(struct mbuf *);
 327
 328extern int ipsec4_output(struct ipsec_output_state *, struct secpolicy *, int);
 329extern int ipsec4_tunnel_validate(struct mbuf *, int, u_int, struct secasvar *);
 330extern struct mbuf *ipsec_copypkt(struct mbuf *);
 331extern void ipsec_delaux(struct mbuf *);
 332extern int ipsec_setsocket(struct mbuf *, struct socket *);
 333extern struct socket *ipsec_getsocket(struct mbuf *);
 334extern int ipsec_addhist(struct mbuf *, int, u_int32_t); 
 335extern struct ipsec_history *ipsec_gethist(struct mbuf *, int *);
 336extern void ipsec_clearhist(struct mbuf *);
 337#endif KERNEL
 338#endif KERNEL_PRIVATE
 339
 340#ifndef KERNEL
 341extern caddr_t ipsec_set_policy(char *, int);
 342extern int ipsec_get_policylen(caddr_t);
 343extern char *ipsec_dump_policy(caddr_t, char *);
 344
 345extern const char *ipsec_strerror(void);
 346#endif KERNEL
 347
 348#endif _NETINET6_IPSEC_H_
 349
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.