Home | History | Annotate | Line # | Download | only in netipsec
keydb.h revision 1.2
      1  1.2      elad /*	$NetBSD: keydb.h,v 1.2 2005/12/10 23:44:08 elad Exp $	*/
      2  1.1  jonathan /*	$FreeBSD: src/sys/netipsec/keydb.h,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $	*/
      3  1.1  jonathan /*	$KAME: keydb.h,v 1.14 2000/08/02 17:58:26 sakane Exp $	*/
      4  1.1  jonathan 
      5  1.1  jonathan /*
      6  1.1  jonathan  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      7  1.1  jonathan  * All rights reserved.
      8  1.1  jonathan  *
      9  1.1  jonathan  * Redistribution and use in source and binary forms, with or without
     10  1.1  jonathan  * modification, are permitted provided that the following conditions
     11  1.1  jonathan  * are met:
     12  1.1  jonathan  * 1. Redistributions of source code must retain the above copyright
     13  1.1  jonathan  *    notice, this list of conditions and the following disclaimer.
     14  1.1  jonathan  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  jonathan  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  jonathan  *    documentation and/or other materials provided with the distribution.
     17  1.1  jonathan  * 3. Neither the name of the project nor the names of its contributors
     18  1.1  jonathan  *    may be used to endorse or promote products derived from this software
     19  1.1  jonathan  *    without specific prior written permission.
     20  1.1  jonathan  *
     21  1.1  jonathan  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     22  1.1  jonathan  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.1  jonathan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1  jonathan  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     25  1.1  jonathan  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1  jonathan  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1  jonathan  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1  jonathan  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1  jonathan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1  jonathan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1  jonathan  * SUCH DAMAGE.
     32  1.1  jonathan  */
     33  1.1  jonathan 
     34  1.1  jonathan #ifndef _NETIPSEC_KEYDB_H_
     35  1.1  jonathan #define _NETIPSEC_KEYDB_H_
     36  1.1  jonathan 
     37  1.1  jonathan #ifdef _KERNEL
     38  1.1  jonathan 
     39  1.1  jonathan #include <netipsec/key_var.h>
     40  1.1  jonathan #include <net/route.h>
     41  1.1  jonathan #include <netinet/in.h>
     42  1.1  jonathan 
     43  1.1  jonathan /*
     44  1.1  jonathan  * The union of all possible address formats we handle.
     45  1.1  jonathan  */
     46  1.1  jonathan union sockaddr_union {
     47  1.1  jonathan 	struct sockaddr		sa;
     48  1.1  jonathan 	struct sockaddr_in	sin;
     49  1.1  jonathan 	struct sockaddr_in6	sin6;
     50  1.1  jonathan };
     51  1.1  jonathan 
     52  1.1  jonathan /* Security Assocciation Index */
     53  1.1  jonathan /* NOTE: Ensure to be same address family */
     54  1.1  jonathan struct secasindex {
     55  1.1  jonathan 	union sockaddr_union src;	/* srouce address for SA */
     56  1.1  jonathan 	union sockaddr_union dst;	/* destination address for SA */
     57  1.1  jonathan 	u_int16_t proto;		/* IPPROTO_ESP or IPPROTO_AH */
     58  1.1  jonathan 	u_int8_t mode;			/* mode of protocol, see ipsec.h */
     59  1.1  jonathan 	u_int32_t reqid;		/* reqid id who owned this SA */
     60  1.1  jonathan 					/* see IPSEC_MANUAL_REQID_MAX. */
     61  1.1  jonathan };
     62  1.1  jonathan 
     63  1.1  jonathan /* Security Association Data Base */
     64  1.1  jonathan struct secashead {
     65  1.1  jonathan 	LIST_ENTRY(secashead) chain;
     66  1.1  jonathan 
     67  1.1  jonathan 	struct secasindex saidx;
     68  1.1  jonathan 
     69  1.1  jonathan 	struct sadb_ident *idents;	/* source identity */
     70  1.1  jonathan 	struct sadb_ident *identd;	/* destination identity */
     71  1.1  jonathan 					/* XXX I don't know how to use them. */
     72  1.1  jonathan 
     73  1.1  jonathan 	u_int8_t state;			/* MATURE or DEAD. */
     74  1.1  jonathan 	LIST_HEAD(_satree, secasvar) savtree[SADB_SASTATE_MAX+1];
     75  1.1  jonathan 					/* SA chain */
     76  1.1  jonathan 					/* The first of this list is newer SA */
     77  1.1  jonathan 
     78  1.1  jonathan 	struct route sa_route;		/* route cache */
     79  1.1  jonathan };
     80  1.1  jonathan 
     81  1.1  jonathan struct xformsw;
     82  1.1  jonathan struct enc_xform;
     83  1.1  jonathan struct auth_hash;
     84  1.1  jonathan struct comp_algo;
     85  1.1  jonathan 
     86  1.1  jonathan /* Security Association */
     87  1.1  jonathan struct secasvar {
     88  1.1  jonathan 	LIST_ENTRY(secasvar) chain;
     89  1.1  jonathan 
     90  1.1  jonathan 	u_int refcnt;			/* reference count */
     91  1.1  jonathan 	u_int8_t state;			/* Status of this Association */
     92  1.1  jonathan 
     93  1.1  jonathan 	u_int8_t alg_auth;		/* Authentication Algorithm Identifier*/
     94  1.1  jonathan 	u_int8_t alg_enc;		/* Cipher Algorithm Identifier */
     95  1.1  jonathan 	u_int8_t alg_comp;		/* Compression Algorithm Identifier */
     96  1.1  jonathan 	u_int32_t spi;			/* SPI Value, network byte order */
     97  1.1  jonathan 	u_int32_t flags;		/* holder for SADB_KEY_FLAGS */
     98  1.1  jonathan 
     99  1.1  jonathan 	struct sadb_key *key_auth;	/* Key for Authentication */
    100  1.1  jonathan 	struct sadb_key *key_enc;	/* Key for Encryption */
    101  1.1  jonathan 	caddr_t iv;			/* Initilization Vector */
    102  1.1  jonathan 	u_int ivlen;			/* length of IV */
    103  1.1  jonathan 	void *sched;			/* intermediate encryption key */
    104  1.1  jonathan 	size_t schedlen;
    105  1.1  jonathan 
    106  1.1  jonathan 	struct secreplay *replay;	/* replay prevention */
    107  1.1  jonathan 	long created;			/* for lifetime */
    108  1.1  jonathan 
    109  1.1  jonathan 	struct sadb_lifetime *lft_c;	/* CURRENT lifetime, it's constant. */
    110  1.1  jonathan 	struct sadb_lifetime *lft_h;	/* HARD lifetime */
    111  1.1  jonathan 	struct sadb_lifetime *lft_s;	/* SOFT lifetime */
    112  1.1  jonathan 
    113  1.1  jonathan 	u_int32_t seq;			/* sequence number */
    114  1.1  jonathan 	pid_t pid;			/* message's pid */
    115  1.1  jonathan 
    116  1.1  jonathan 	struct secashead *sah;		/* back pointer to the secashead */
    117  1.1  jonathan 
    118  1.1  jonathan 	/*
    119  1.1  jonathan 	 * NB: Fields with a tdb_ prefix are part of the "glue" used
    120  1.1  jonathan 	 *     to interface to the OpenBSD crypto support.  This was done
    121  1.1  jonathan 	 *     to distinguish this code from the mainline KAME code.
    122  1.1  jonathan 	 */
    123  1.1  jonathan 	struct xformsw *tdb_xform;	/* transform */
    124  1.1  jonathan 	struct enc_xform *tdb_encalgxform;	/* encoding algorithm */
    125  1.1  jonathan 	struct auth_hash *tdb_authalgxform;	/* authentication algorithm */
    126  1.1  jonathan 	struct comp_algo *tdb_compalgxform;	/* compression algorithm */
    127  1.1  jonathan 	u_int64_t tdb_cryptoid;		/* crypto session id */
    128  1.1  jonathan };
    129  1.1  jonathan 
    130  1.1  jonathan /* replay prevention */
    131  1.1  jonathan struct secreplay {
    132  1.1  jonathan 	u_int32_t count;
    133  1.1  jonathan 	u_int wsize;		/* window size, i.g. 4 bytes */
    134  1.1  jonathan 	u_int32_t seq;		/* used by sender */
    135  1.1  jonathan 	u_int32_t lastseq;	/* used by receiver */
    136  1.1  jonathan 	caddr_t bitmap;		/* used by receiver */
    137  1.1  jonathan 	int overflow;		/* overflow flag */
    138  1.1  jonathan };
    139  1.1  jonathan 
    140  1.1  jonathan /* socket table due to send PF_KEY messages. */
    141  1.1  jonathan struct secreg {
    142  1.1  jonathan 	LIST_ENTRY(secreg) chain;
    143  1.1  jonathan 
    144  1.1  jonathan 	struct socket *so;
    145  1.1  jonathan };
    146  1.1  jonathan 
    147  1.1  jonathan #ifndef IPSEC_NONBLOCK_ACQUIRE
    148  1.1  jonathan /* acquiring list table. */
    149  1.1  jonathan struct secacq {
    150  1.1  jonathan 	LIST_ENTRY(secacq) chain;
    151  1.1  jonathan 
    152  1.1  jonathan 	struct secasindex saidx;
    153  1.1  jonathan 
    154  1.1  jonathan 	u_int32_t seq;		/* sequence number */
    155  1.1  jonathan 	long created;		/* for lifetime */
    156  1.1  jonathan 	int count;		/* for lifetime */
    157  1.1  jonathan };
    158  1.1  jonathan #endif
    159  1.1  jonathan 
    160  1.1  jonathan /* Sensitivity Level Specification */
    161  1.1  jonathan /* nothing */
    162  1.1  jonathan 
    163  1.1  jonathan #define SADB_KILL_INTERVAL	600	/* six seconds */
    164  1.1  jonathan 
    165  1.1  jonathan /* secpolicy */
    166  1.1  jonathan extern struct secpolicy *keydb_newsecpolicy __P((void));
    167  1.1  jonathan extern void keydb_delsecpolicy __P((struct secpolicy *));
    168  1.1  jonathan /* secashead */
    169  1.1  jonathan extern struct secashead *keydb_newsecashead __P((void));
    170  1.1  jonathan extern void keydb_delsecashead __P((struct secashead *));
    171  1.1  jonathan /* secasvar */
    172  1.1  jonathan extern struct secasvar *keydb_newsecasvar __P((void));
    173  1.1  jonathan extern void keydb_refsecasvar __P((struct secasvar *));
    174  1.1  jonathan extern void keydb_freesecasvar __P((struct secasvar *));
    175  1.1  jonathan /* secreplay */
    176  1.1  jonathan extern struct secreplay *keydb_newsecreplay __P((size_t));
    177  1.1  jonathan extern void keydb_delsecreplay __P((struct secreplay *));
    178  1.1  jonathan /* secreg */
    179  1.1  jonathan extern struct secreg *keydb_newsecreg __P((void));
    180  1.1  jonathan extern void keydb_delsecreg __P((struct secreg *));
    181  1.1  jonathan 
    182  1.1  jonathan #endif /* _KERNEL */
    183  1.1  jonathan 
    184  1.2      elad #endif /* !_NETIPSEC_KEYDB_H_ */
    185