Home | History | Annotate | Line # | Download | only in netipsec
key.h revision 1.7
      1  1.7  degroote /*	$NetBSD: key.h,v 1.7 2007/06/27 20:38:33 degroote Exp $	*/
      2  1.1  jonathan /*	$FreeBSD: src/sys/netipsec/key.h,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $	*/
      3  1.1  jonathan /*	$KAME: key.h,v 1.21 2001/07/27 03:51:30 itojun 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_KEY_H_
     35  1.1  jonathan #define _NETIPSEC_KEY_H_
     36  1.1  jonathan 
     37  1.1  jonathan #ifdef _KERNEL
     38  1.1  jonathan 
     39  1.7  degroote #include "opt_ipsec.h"
     40  1.7  degroote 
     41  1.1  jonathan struct secpolicy;
     42  1.1  jonathan struct secpolicyindex;
     43  1.1  jonathan struct ipsecrequest;
     44  1.1  jonathan struct secasvar;
     45  1.1  jonathan struct sockaddr;
     46  1.1  jonathan struct socket;
     47  1.1  jonathan struct sadb_msg;
     48  1.1  jonathan struct sadb_x_policy;
     49  1.1  jonathan struct secasindex;
     50  1.1  jonathan union sockaddr_union;
     51  1.1  jonathan 
     52  1.1  jonathan extern	int key_havesp(u_int dir);
     53  1.1  jonathan extern struct secpolicy *key_allocsp(struct secpolicyindex *, u_int,
     54  1.1  jonathan 	const char*, int);
     55  1.1  jonathan extern struct secpolicy *key_allocsp2(u_int32_t spi, union sockaddr_union *dst,
     56  1.1  jonathan 	u_int8_t proto, u_int dir, const char*, int);
     57  1.1  jonathan extern struct secpolicy *key_newsp(const char*, int);
     58  1.1  jonathan extern struct secpolicy *key_gettunnel(const struct sockaddr *,
     59  1.1  jonathan 	const struct sockaddr *, const struct sockaddr *,
     60  1.1  jonathan 	const struct sockaddr *, const char*, int);
     61  1.1  jonathan /* NB: prepend with _ for KAME IPv6 compatbility */
     62  1.1  jonathan extern void _key_freesp(struct secpolicy **, const char*, int);
     63  1.1  jonathan 
     64  1.1  jonathan /*
     65  1.1  jonathan  * Access to the SADB are interlocked with splsoftnet.  In particular,
     66  1.1  jonathan  * holders of SA's use this to block accesses by protocol processing
     67  1.1  jonathan  * that can happen either by network swi's or by continuations that
     68  1.1  jonathan  * occur on crypto callbacks.  Much of this could go away if
     69  1.1  jonathan  * key_checkrequest were redone.
     70  1.3     perry  */
     71  1.1  jonathan #define	KEY_ALLOCSP(spidx, dir)					\
     72  1.1  jonathan 	key_allocsp(spidx, dir, __FILE__, __LINE__)
     73  1.1  jonathan #define	KEY_ALLOCSP2(spi, dst, proto, dir)			\
     74  1.1  jonathan 	key_allocsp2(spi, dst, proto, dir, __FILE__, __LINE__)
     75  1.1  jonathan #define	KEY_NEWSP()						\
     76  1.1  jonathan 	key_newsp(__FILE__, __LINE__)
     77  1.1  jonathan #define	KEY_GETTUNNEL(osrc, odst, isrc, idst)			\
     78  1.1  jonathan 	key_gettunnel(osrc, odst, isrc, idst, __FILE__, __LINE__)
     79  1.1  jonathan #define	KEY_FREESP(spp)						\
     80  1.1  jonathan 	_key_freesp(spp, __FILE__, __LINE__)
     81  1.1  jonathan 
     82  1.5  degroote extern struct secasvar *key_allocsa(const union sockaddr_union *,
     83  1.7  degroote 		u_int, u_int32_t, u_int16_t, u_int16_t, const char*, int);
     84  1.1  jonathan extern void key_freesav(struct secasvar **, const char*, int);
     85  1.1  jonathan 
     86  1.7  degroote #define	KEY_ALLOCSA(dst, proto, spi, sport, dport)				\
     87  1.7  degroote 	key_allocsa(dst, proto, spi, sport, dport,  __FILE__, __LINE__)
     88  1.1  jonathan #define	KEY_FREESAV(psav)					\
     89  1.1  jonathan 	key_freesav(psav, __FILE__, __LINE__)
     90  1.1  jonathan 
     91  1.1  jonathan extern void key_freeso __P((struct socket *));
     92  1.1  jonathan extern int key_checktunnelsanity __P((struct secasvar *, u_int,
     93  1.6  christos 					void *, void *));
     94  1.1  jonathan extern int key_checkrequest
     95  1.1  jonathan 	__P((struct ipsecrequest *isr, const struct secasindex *));
     96  1.1  jonathan 
     97  1.1  jonathan extern struct secpolicy *key_msg2sp __P((struct sadb_x_policy *,
     98  1.1  jonathan 	size_t, int *));
     99  1.1  jonathan extern struct mbuf *key_sp2msg __P((struct secpolicy *));
    100  1.1  jonathan extern int key_ismyaddr __P((struct sockaddr *));
    101  1.2   thorpej extern int key_cmpspidx_exactly
    102  1.2   thorpej 	__P((struct secpolicyindex *, struct secpolicyindex *));
    103  1.2   thorpej extern int key_cmpspidx_withmask
    104  1.2   thorpej 	__P((struct secpolicyindex *, struct secpolicyindex *));
    105  1.1  jonathan extern int key_spdacquire __P((struct secpolicy *));
    106  1.1  jonathan extern void key_timehandler __P((void*));
    107  1.1  jonathan extern u_long key_random __P((void));
    108  1.1  jonathan extern void key_randomfill __P((void *, size_t));
    109  1.1  jonathan extern void key_freereg __P((struct socket *));
    110  1.1  jonathan extern int key_parse __P((struct mbuf *, struct socket *));
    111  1.1  jonathan extern void key_init __P((void));
    112  1.1  jonathan extern void key_sa_recordxfer __P((struct secasvar *, struct mbuf *));
    113  1.1  jonathan extern void key_sa_routechange __P((struct sockaddr *));
    114  1.1  jonathan extern void key_sa_stir_iv __P((struct secasvar *));
    115  1.1  jonathan 
    116  1.7  degroote #ifdef IPSEC_NAT_T
    117  1.7  degroote u_int16_t key_portfromsaddr __P((const union sockaddr_union *));
    118  1.7  degroote #endif
    119  1.7  degroote 
    120  1.7  degroote 
    121  1.7  degroote 
    122  1.1  jonathan #ifdef MALLOC_DECLARE
    123  1.1  jonathan MALLOC_DECLARE(M_SECA);
    124  1.1  jonathan #endif /* MALLOC_DECLARE */
    125  1.1  jonathan 
    126  1.1  jonathan #endif /* defined(_KERNEL) */
    127  1.4      elad #endif /* !_NETIPSEC_KEY_H_ */
    128