Home | History | Annotate | Line # | Download | only in netipsec
ipsec.h revision 1.1
      1  1.1  jonathan /*	$NetBSD: ipsec.h,v 1.1 2003/08/13 20:06:50 jonathan Exp $	*/
      2  1.1  jonathan /*	$FreeBSD: src/sys/netipsec/ipsec.h,v 1.2.4.1 2003/01/24 05:11:35 sam Exp $	*/
      3  1.1  jonathan /*	$KAME: ipsec.h,v 1.53 2001/11/20 08:32:38 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 /*
     35  1.1  jonathan  * IPsec controller part.
     36  1.1  jonathan  */
     37  1.1  jonathan 
     38  1.1  jonathan #ifndef _NETIPSEC_IPSEC_H_
     39  1.1  jonathan #define _NETIPSEC_IPSEC_H_
     40  1.1  jonathan 
     41  1.1  jonathan #if defined(_KERNEL) && !defined(_LKM) && !defined(KLD_MODULE)
     42  1.1  jonathan #include "opt_inet.h"
     43  1.1  jonathan #include "opt_ipsec.h"
     44  1.1  jonathan #endif
     45  1.1  jonathan 
     46  1.1  jonathan #include <net/pfkeyv2.h>
     47  1.1  jonathan #include <netipsec/keydb.h>
     48  1.1  jonathan 
     49  1.1  jonathan #ifdef _KERNEL
     50  1.1  jonathan 
     51  1.1  jonathan /*
     52  1.1  jonathan  * Security Policy Index
     53  1.1  jonathan  * Ensure that both address families in the "src" and "dst" are same.
     54  1.1  jonathan  * When the value of the ul_proto is ICMPv6, the port field in "src"
     55  1.1  jonathan  * specifies ICMPv6 type, and the port field in "dst" specifies ICMPv6 code.
     56  1.1  jonathan  */
     57  1.1  jonathan struct secpolicyindex {
     58  1.1  jonathan 	u_int8_t dir;			/* direction of packet flow, see blow */
     59  1.1  jonathan 	union sockaddr_union src;	/* IP src address for SP */
     60  1.1  jonathan 	union sockaddr_union dst;	/* IP dst address for SP */
     61  1.1  jonathan 	u_int8_t prefs;			/* prefix length in bits for src */
     62  1.1  jonathan 	u_int8_t prefd;			/* prefix length in bits for dst */
     63  1.1  jonathan 	u_int16_t ul_proto;		/* upper layer Protocol */
     64  1.1  jonathan #ifdef notyet
     65  1.1  jonathan 	uid_t uids;
     66  1.1  jonathan 	uid_t uidd;
     67  1.1  jonathan 	gid_t gids;
     68  1.1  jonathan 	gid_t gidd;
     69  1.1  jonathan #endif
     70  1.1  jonathan };
     71  1.1  jonathan 
     72  1.1  jonathan /* Security Policy Data Base */
     73  1.1  jonathan struct secpolicy {
     74  1.1  jonathan 	LIST_ENTRY(secpolicy) chain;
     75  1.1  jonathan 
     76  1.1  jonathan 	u_int refcnt;			/* reference count */
     77  1.1  jonathan 	struct secpolicyindex spidx;	/* selector */
     78  1.1  jonathan 	u_int32_t id;			/* It's unique number on the system. */
     79  1.1  jonathan 	u_int state;			/* 0: dead, others: alive */
     80  1.1  jonathan #define IPSEC_SPSTATE_DEAD	0
     81  1.1  jonathan #define IPSEC_SPSTATE_ALIVE	1
     82  1.1  jonathan 
     83  1.1  jonathan 	u_int policy;		/* DISCARD, NONE or IPSEC, see keyv2.h */
     84  1.1  jonathan 	struct ipsecrequest *req;
     85  1.1  jonathan 				/* pointer to the ipsec request tree, */
     86  1.1  jonathan 				/* if policy == IPSEC else this value == NULL.*/
     87  1.1  jonathan 
     88  1.1  jonathan 	/*
     89  1.1  jonathan 	 * lifetime handler.
     90  1.1  jonathan 	 * the policy can be used without limitiation if both lifetime and
     91  1.1  jonathan 	 * validtime are zero.
     92  1.1  jonathan 	 * "lifetime" is passed by sadb_lifetime.sadb_lifetime_addtime.
     93  1.1  jonathan 	 * "validtime" is passed by sadb_lifetime.sadb_lifetime_usetime.
     94  1.1  jonathan 	 */
     95  1.1  jonathan 	long created;		/* time created the policy */
     96  1.1  jonathan 	long lastused;		/* updated every when kernel sends a packet */
     97  1.1  jonathan 	long lifetime;		/* duration of the lifetime of this policy */
     98  1.1  jonathan 	long validtime;		/* duration this policy is valid without use */
     99  1.1  jonathan };
    100  1.1  jonathan 
    101  1.1  jonathan /* Request for IPsec */
    102  1.1  jonathan struct ipsecrequest {
    103  1.1  jonathan 	struct ipsecrequest *next;
    104  1.1  jonathan 				/* pointer to next structure */
    105  1.1  jonathan 				/* If NULL, it means the end of chain. */
    106  1.1  jonathan 	struct secasindex saidx;/* hint for search proper SA */
    107  1.1  jonathan 				/* if __ss_len == 0 then no address specified.*/
    108  1.1  jonathan 	u_int level;		/* IPsec level defined below. */
    109  1.1  jonathan 
    110  1.1  jonathan 	struct secasvar *sav;	/* place holder of SA for use */
    111  1.1  jonathan 	struct secpolicy *sp;	/* back pointer to SP */
    112  1.1  jonathan };
    113  1.1  jonathan 
    114  1.1  jonathan /* security policy in PCB */
    115  1.1  jonathan struct inpcbpolicy {
    116  1.1  jonathan 	struct secpolicy *sp_in;
    117  1.1  jonathan 	struct secpolicy *sp_out;
    118  1.1  jonathan 	int priv;			/* privileged socket ? */
    119  1.1  jonathan };
    120  1.1  jonathan 
    121  1.1  jonathan /* SP acquiring list table. */
    122  1.1  jonathan struct secspacq {
    123  1.1  jonathan 	LIST_ENTRY(secspacq) chain;
    124  1.1  jonathan 
    125  1.1  jonathan 	struct secpolicyindex spidx;
    126  1.1  jonathan 
    127  1.1  jonathan 	long created;		/* for lifetime */
    128  1.1  jonathan 	int count;		/* for lifetime */
    129  1.1  jonathan 	/* XXX: here is mbuf place holder to be sent ? */
    130  1.1  jonathan };
    131  1.1  jonathan #endif /* _KERNEL */
    132  1.1  jonathan 
    133  1.1  jonathan /* according to IANA assignment, port 0x0000 and proto 0xff are reserved. */
    134  1.1  jonathan #define IPSEC_PORT_ANY		0
    135  1.1  jonathan #define IPSEC_ULPROTO_ANY	255
    136  1.1  jonathan #define IPSEC_PROTO_ANY		255
    137  1.1  jonathan 
    138  1.1  jonathan /* mode of security protocol */
    139  1.1  jonathan /* NOTE: DON'T use IPSEC_MODE_ANY at SPD.  It's only use in SAD */
    140  1.1  jonathan #define	IPSEC_MODE_ANY		0	/* i.e. wildcard. */
    141  1.1  jonathan #define	IPSEC_MODE_TRANSPORT	1
    142  1.1  jonathan #define	IPSEC_MODE_TUNNEL	2
    143  1.1  jonathan 
    144  1.1  jonathan /*
    145  1.1  jonathan  * Direction of security policy.
    146  1.1  jonathan  * NOTE: Since INVALID is used just as flag.
    147  1.1  jonathan  * The other are used for loop counter too.
    148  1.1  jonathan  */
    149  1.1  jonathan #define IPSEC_DIR_ANY		0
    150  1.1  jonathan #define IPSEC_DIR_INBOUND	1
    151  1.1  jonathan #define IPSEC_DIR_OUTBOUND	2
    152  1.1  jonathan #define IPSEC_DIR_MAX		3
    153  1.1  jonathan #define IPSEC_DIR_INVALID	4
    154  1.1  jonathan 
    155  1.1  jonathan /* Policy level */
    156  1.1  jonathan /*
    157  1.1  jonathan  * IPSEC, ENTRUST and BYPASS are allowed for setsockopt() in PCB,
    158  1.1  jonathan  * DISCARD, IPSEC and NONE are allowed for setkey() in SPD.
    159  1.1  jonathan  * DISCARD and NONE are allowed for system default.
    160  1.1  jonathan  */
    161  1.1  jonathan #define IPSEC_POLICY_DISCARD	0	/* discarding packet */
    162  1.1  jonathan #define IPSEC_POLICY_NONE	1	/* through IPsec engine */
    163  1.1  jonathan #define IPSEC_POLICY_IPSEC	2	/* do IPsec */
    164  1.1  jonathan #define IPSEC_POLICY_ENTRUST	3	/* consulting SPD if present. */
    165  1.1  jonathan #define IPSEC_POLICY_BYPASS	4	/* only for privileged socket. */
    166  1.1  jonathan 
    167  1.1  jonathan /* Security protocol level */
    168  1.1  jonathan #define	IPSEC_LEVEL_DEFAULT	0	/* reference to system default */
    169  1.1  jonathan #define	IPSEC_LEVEL_USE		1	/* use SA if present. */
    170  1.1  jonathan #define	IPSEC_LEVEL_REQUIRE	2	/* require SA. */
    171  1.1  jonathan #define	IPSEC_LEVEL_UNIQUE	3	/* unique SA. */
    172  1.1  jonathan 
    173  1.1  jonathan #define IPSEC_MANUAL_REQID_MAX	0x3fff
    174  1.1  jonathan 				/*
    175  1.1  jonathan 				 * if security policy level == unique, this id
    176  1.1  jonathan 				 * indicate to a relative SA for use, else is
    177  1.1  jonathan 				 * zero.
    178  1.1  jonathan 				 * 1 - 0x3fff are reserved for manual keying.
    179  1.1  jonathan 				 * 0 are reserved for above reason.  Others is
    180  1.1  jonathan 				 * for kernel use.
    181  1.1  jonathan 				 * Note that this id doesn't identify SA
    182  1.1  jonathan 				 * by only itself.
    183  1.1  jonathan 				 */
    184  1.1  jonathan #define IPSEC_REPLAYWSIZE  32
    185  1.1  jonathan 
    186  1.1  jonathan /* old statistics for ipsec processing */
    187  1.1  jonathan struct ipsecstat {
    188  1.1  jonathan 	u_quad_t in_success;  /* succeeded inbound process */
    189  1.1  jonathan 	u_quad_t in_polvio;
    190  1.1  jonathan 			/* security policy violation for inbound process */
    191  1.1  jonathan 	u_quad_t in_nosa;     /* inbound SA is unavailable */
    192  1.1  jonathan 	u_quad_t in_inval;    /* inbound processing failed due to EINVAL */
    193  1.1  jonathan 	u_quad_t in_nomem;    /* inbound processing failed due to ENOBUFS */
    194  1.1  jonathan 	u_quad_t in_badspi;   /* failed getting a SPI */
    195  1.1  jonathan 	u_quad_t in_ahreplay; /* AH replay check failed */
    196  1.1  jonathan 	u_quad_t in_espreplay; /* ESP replay check failed */
    197  1.1  jonathan 	u_quad_t in_ahauthsucc; /* AH authentication success */
    198  1.1  jonathan 	u_quad_t in_ahauthfail; /* AH authentication failure */
    199  1.1  jonathan 	u_quad_t in_espauthsucc; /* ESP authentication success */
    200  1.1  jonathan 	u_quad_t in_espauthfail; /* ESP authentication failure */
    201  1.1  jonathan 	u_quad_t in_esphist[256];
    202  1.1  jonathan 	u_quad_t in_ahhist[256];
    203  1.1  jonathan 	u_quad_t in_comphist[256];
    204  1.1  jonathan 	u_quad_t out_success; /* succeeded outbound process */
    205  1.1  jonathan 	u_quad_t out_polvio;
    206  1.1  jonathan 			/* security policy violation for outbound process */
    207  1.1  jonathan 	u_quad_t out_nosa;    /* outbound SA is unavailable */
    208  1.1  jonathan 	u_quad_t out_inval;   /* outbound process failed due to EINVAL */
    209  1.1  jonathan 	u_quad_t out_nomem;    /* inbound processing failed due to ENOBUFS */
    210  1.1  jonathan 	u_quad_t out_noroute; /* there is no route */
    211  1.1  jonathan 	u_quad_t out_esphist[256];
    212  1.1  jonathan 	u_quad_t out_ahhist[256];
    213  1.1  jonathan 	u_quad_t out_comphist[256];
    214  1.1  jonathan };
    215  1.1  jonathan 
    216  1.1  jonathan /* statistics for ipsec processing */
    217  1.1  jonathan struct newipsecstat {
    218  1.1  jonathan 	u_int32_t ips_in_polvio;	/* input: sec policy violation */
    219  1.1  jonathan 	u_int32_t ips_out_polvio;	/* output: sec policy violation */
    220  1.1  jonathan 	u_int32_t ips_out_nosa;		/* output: SA unavailable  */
    221  1.1  jonathan 	u_int32_t ips_out_nomem;	/* output: no memory available */
    222  1.1  jonathan 	u_int32_t ips_out_noroute;	/* output: no route available */
    223  1.1  jonathan 	u_int32_t ips_out_inval;	/* output: generic error */
    224  1.1  jonathan 	u_int32_t ips_out_bundlesa;	/* output: bundled SA processed */
    225  1.1  jonathan 	u_int32_t ips_mbcoalesced;	/* mbufs coalesced during clone */
    226  1.1  jonathan 	u_int32_t ips_clcoalesced;	/* clusters coalesced during clone */
    227  1.1  jonathan 	u_int32_t ips_clcopied;		/* clusters copied during clone */
    228  1.1  jonathan 	u_int32_t ips_mbinserted;	/* mbufs inserted during makespace */
    229  1.1  jonathan 	/*
    230  1.1  jonathan 	 * Temporary statistics for performance analysis.
    231  1.1  jonathan 	 */
    232  1.1  jonathan 	/* See where ESP/AH/IPCOMP header land in mbuf on input */
    233  1.1  jonathan 	u_int32_t ips_input_front;
    234  1.1  jonathan 	u_int32_t ips_input_middle;
    235  1.1  jonathan 	u_int32_t ips_input_end;
    236  1.1  jonathan };
    237  1.1  jonathan 
    238  1.1  jonathan /*
    239  1.1  jonathan  * XXX JRS FIXME: later replace NetBSD sourcecode with an IPSECSTAT_POLVIO() macro.
    240  1.1  jonathan  * for now, map the old fields to the new fields.  */
    241  1.1  jonathan #define ipsecstat newipsecstat
    242  1.1  jonathan 
    243  1.1  jonathan #define in_polvio ips_in_polvio
    244  1.1  jonathan #define out_polvio ips_out_polvio
    245  1.1  jonathan #define out_inval ips_out_inval
    246  1.1  jonathan 
    247  1.1  jonathan /*
    248  1.1  jonathan  * Definitions for IPsec & Key sysctl operations.
    249  1.1  jonathan  */
    250  1.1  jonathan /*
    251  1.1  jonathan  * Names for IPsec & Key sysctl objects
    252  1.1  jonathan  */
    253  1.1  jonathan #define IPSECCTL_STATS			1	/* stats */
    254  1.1  jonathan #define IPSECCTL_DEF_POLICY		2
    255  1.1  jonathan #define IPSECCTL_DEF_ESP_TRANSLEV	3	/* int; ESP transport mode */
    256  1.1  jonathan #define IPSECCTL_DEF_ESP_NETLEV		4	/* int; ESP tunnel mode */
    257  1.1  jonathan #define IPSECCTL_DEF_AH_TRANSLEV	5	/* int; AH transport mode */
    258  1.1  jonathan #define IPSECCTL_DEF_AH_NETLEV		6	/* int; AH tunnel mode */
    259  1.1  jonathan #if 0	/* obsolete, do not reuse */
    260  1.1  jonathan #define IPSECCTL_INBOUND_CALL_IKE	7
    261  1.1  jonathan #endif
    262  1.1  jonathan #define	IPSECCTL_AH_CLEARTOS		8
    263  1.1  jonathan #define	IPSECCTL_AH_OFFSETMASK		9
    264  1.1  jonathan #define	IPSECCTL_DFBIT			10
    265  1.1  jonathan #define	IPSECCTL_ECN			11
    266  1.1  jonathan #define	IPSECCTL_DEBUG			12
    267  1.1  jonathan #define	IPSECCTL_ESP_RANDPAD		13
    268  1.1  jonathan #define IPSECCTL_MAXID			14
    269  1.1  jonathan 
    270  1.1  jonathan #define IPSECCTL_NAMES { \
    271  1.1  jonathan 	{ 0, 0 }, \
    272  1.1  jonathan 	{ 0, 0 }, \
    273  1.1  jonathan 	{ "def_policy", CTLTYPE_INT }, \
    274  1.1  jonathan 	{ "esp_trans_deflev", CTLTYPE_INT }, \
    275  1.1  jonathan 	{ "esp_net_deflev", CTLTYPE_INT }, \
    276  1.1  jonathan 	{ "ah_trans_deflev", CTLTYPE_INT }, \
    277  1.1  jonathan 	{ "ah_net_deflev", CTLTYPE_INT }, \
    278  1.1  jonathan 	{ 0, 0 }, \
    279  1.1  jonathan 	{ "ah_cleartos", CTLTYPE_INT }, \
    280  1.1  jonathan 	{ "ah_offsetmask", CTLTYPE_INT }, \
    281  1.1  jonathan 	{ "dfbit", CTLTYPE_INT }, \
    282  1.1  jonathan 	{ "ecn", CTLTYPE_INT }, \
    283  1.1  jonathan 	{ "debug", CTLTYPE_INT }, \
    284  1.1  jonathan 	{ "esp_randpad", CTLTYPE_INT }, \
    285  1.1  jonathan }
    286  1.1  jonathan 
    287  1.1  jonathan #define IPSEC6CTL_NAMES { \
    288  1.1  jonathan 	{ 0, 0 }, \
    289  1.1  jonathan 	{ 0, 0 }, \
    290  1.1  jonathan 	{ "def_policy", CTLTYPE_INT }, \
    291  1.1  jonathan 	{ "esp_trans_deflev", CTLTYPE_INT }, \
    292  1.1  jonathan 	{ "esp_net_deflev", CTLTYPE_INT }, \
    293  1.1  jonathan 	{ "ah_trans_deflev", CTLTYPE_INT }, \
    294  1.1  jonathan 	{ "ah_net_deflev", CTLTYPE_INT }, \
    295  1.1  jonathan 	{ 0, 0 }, \
    296  1.1  jonathan 	{ 0, 0 }, \
    297  1.1  jonathan 	{ 0, 0 }, \
    298  1.1  jonathan 	{ 0, 0 }, \
    299  1.1  jonathan 	{ "ecn", CTLTYPE_INT }, \
    300  1.1  jonathan 	{ "debug", CTLTYPE_INT }, \
    301  1.1  jonathan 	{ "esp_randpad", CTLTYPE_INT }, \
    302  1.1  jonathan }
    303  1.1  jonathan 
    304  1.1  jonathan #ifdef _KERNEL
    305  1.1  jonathan struct ipsec_output_state {
    306  1.1  jonathan 	struct mbuf *m;
    307  1.1  jonathan 	struct route *ro;
    308  1.1  jonathan 	struct sockaddr *dst;
    309  1.1  jonathan };
    310  1.1  jonathan 
    311  1.1  jonathan struct ipsec_history {
    312  1.1  jonathan 	int ih_proto;
    313  1.1  jonathan 	u_int32_t ih_spi;
    314  1.1  jonathan };
    315  1.1  jonathan 
    316  1.1  jonathan extern int ipsec_debug;
    317  1.1  jonathan 
    318  1.1  jonathan extern struct newipsecstat newipsecstat;
    319  1.1  jonathan extern struct secpolicy ip4_def_policy;
    320  1.1  jonathan extern int ip4_esp_trans_deflev;
    321  1.1  jonathan extern int ip4_esp_net_deflev;
    322  1.1  jonathan extern int ip4_ah_trans_deflev;
    323  1.1  jonathan extern int ip4_ah_net_deflev;
    324  1.1  jonathan extern int ip4_ah_cleartos;
    325  1.1  jonathan extern int ip4_ah_offsetmask;
    326  1.1  jonathan extern int ip4_ipsec_dfbit;
    327  1.1  jonathan extern int ip4_ipsec_ecn;
    328  1.1  jonathan extern int ip4_esp_randpad;
    329  1.1  jonathan extern int crypto_support;
    330  1.1  jonathan 
    331  1.1  jonathan #define ipseclog(x)	do { if (ipsec_debug) log x; } while (0)
    332  1.1  jonathan /* for openbsd compatibility */
    333  1.1  jonathan #define	DPRINTF(x)	do { if (ipsec_debug) printf x; } while (0)
    334  1.1  jonathan 
    335  1.1  jonathan struct tdb_ident;
    336  1.1  jonathan extern struct secpolicy *ipsec_getpolicy __P((struct tdb_ident*, u_int));
    337  1.1  jonathan struct inpcb;
    338  1.1  jonathan extern struct secpolicy *ipsec4_checkpolicy __P((struct mbuf *, u_int, u_int,
    339  1.1  jonathan 	int *, struct inpcb *));
    340  1.1  jonathan extern struct secpolicy *ipsec_getpolicybysock(struct mbuf *, u_int,
    341  1.1  jonathan 	struct inpcb *, int *);
    342  1.1  jonathan extern struct secpolicy * ipsec_getpolicybyaddr(struct mbuf *, u_int,
    343  1.1  jonathan 	int, int *);
    344  1.1  jonathan 
    345  1.1  jonathan 
    346  1.1  jonathan static __inline struct secpolicy*
    347  1.1  jonathan ipsec4_getpolicybysock(struct mbuf *m, u_int dir, const struct socket *so, int *err)
    348  1.1  jonathan {
    349  1.1  jonathan   panic("ipsec4_getpolicybysock");
    350  1.1  jonathan }
    351  1.1  jonathan 
    352  1.1  jonathan static __inline int
    353  1.1  jonathan ipsec_copy_pcbpolicy(struct inpcbpolicy *old, struct inpcbpolicy *new)
    354  1.1  jonathan {
    355  1.1  jonathan   /*XXX do nothing */
    356  1.1  jonathan   return (0);
    357  1.1  jonathan }
    358  1.1  jonathan 
    359  1.1  jonathan 
    360  1.1  jonathan 
    361  1.1  jonathan struct inpcb;
    362  1.1  jonathan #define	ipsec_init_pcbpolicy ipsec_init_policy
    363  1.1  jonathan extern int ipsec_init_policy __P((struct socket *so, struct inpcbpolicy **));
    364  1.1  jonathan extern int ipsec_copy_policy
    365  1.1  jonathan 	__P((struct inpcbpolicy *, struct inpcbpolicy *));
    366  1.1  jonathan extern u_int ipsec_get_reqlevel __P((struct ipsecrequest *));
    367  1.1  jonathan extern int ipsec_in_reject __P((struct secpolicy *, struct mbuf *));
    368  1.1  jonathan 
    369  1.1  jonathan extern int ipsec4_set_policy __P((struct inpcb *inp, int optname,
    370  1.1  jonathan 	caddr_t request, size_t len, int priv));
    371  1.1  jonathan extern int ipsec4_get_policy __P((struct inpcb *inpcb, caddr_t request,
    372  1.1  jonathan 	size_t len, struct mbuf **mp));
    373  1.1  jonathan extern int ipsec4_delete_pcbpolicy __P((struct inpcb *));
    374  1.1  jonathan extern int ipsec4_in_reject __P((struct mbuf *, struct inpcb *));
    375  1.1  jonathan /*
    376  1.1  jonathan  * KAME ipsec4_in_reject_so(struct mbuf*, struct so)  compatibility shim
    377  1.1  jonathan  */
    378  1.1  jonathan #define ipsec4_in_reject_so(m, _so) \
    379  1.1  jonathan   ipsec4_in_reject(m, ((_so) == NULL? NULL : sotoinpcb(_so)))
    380  1.1  jonathan 
    381  1.1  jonathan 
    382  1.1  jonathan struct secas;
    383  1.1  jonathan struct tcpcb;
    384  1.1  jonathan extern int ipsec_chkreplay __P((u_int32_t, struct secasvar *));
    385  1.1  jonathan extern int ipsec_updatereplay __P((u_int32_t, struct secasvar *));
    386  1.1  jonathan 
    387  1.1  jonathan extern size_t ipsec4_hdrsiz __P((struct mbuf *, u_int, struct inpcb *));
    388  1.1  jonathan #ifdef __FreeBSD__
    389  1.1  jonathan extern size_t ipsec_hdrsiz_tcp __P((struct tcpcb *));
    390  1.1  jonathan #else
    391  1.1  jonathan extern size_t ipsec4_hdrsiz_tcp __P((struct tcpcb *));
    392  1.1  jonathan #define ipsec4_getpolicybyaddr ipsec_getpolicybyaddr
    393  1.1  jonathan #endif
    394  1.1  jonathan 
    395  1.1  jonathan union sockaddr_union;
    396  1.1  jonathan extern char * ipsec_address(union sockaddr_union* sa);
    397  1.1  jonathan extern const char *ipsec_logsastr __P((struct secasvar *));
    398  1.1  jonathan 
    399  1.1  jonathan extern void ipsec_dumpmbuf __P((struct mbuf *));
    400  1.1  jonathan 
    401  1.1  jonathan /* NetBSD protosw ctlin entrypoint */
    402  1.1  jonathan extern void *esp4_ctlinput __P((int, struct sockaddr *, void *));
    403  1.1  jonathan extern void *ah4_ctlinput __P((int, struct sockaddr *, void *));
    404  1.1  jonathan extern int ipsec_sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
    405  1.1  jonathan 
    406  1.1  jonathan struct m_tag;
    407  1.1  jonathan extern int ipsec4_common_input(struct mbuf *m, ...);
    408  1.1  jonathan extern int ipsec4_common_input_cb(struct mbuf *m, struct secasvar *sav,
    409  1.1  jonathan 			int skip, int protoff, struct m_tag *mt);
    410  1.1  jonathan extern int ipsec4_process_packet __P((struct mbuf *, struct ipsecrequest *,
    411  1.1  jonathan 			int, int));
    412  1.1  jonathan extern int ipsec_process_done __P((struct mbuf *, struct ipsecrequest *));
    413  1.1  jonathan 
    414  1.1  jonathan extern struct mbuf *ipsec_copypkt __P((struct mbuf *));
    415  1.1  jonathan 
    416  1.1  jonathan extern	void m_checkalignment(const char* where, struct mbuf *m0,
    417  1.1  jonathan 		int off, int len);
    418  1.1  jonathan extern	struct mbuf *m_clone(struct mbuf *m0);
    419  1.1  jonathan extern	struct mbuf *m_makespace(struct mbuf *m0, int skip, int hlen, int *off);
    420  1.1  jonathan extern	caddr_t m_pad(struct mbuf *m, int n);
    421  1.1  jonathan extern	int m_striphdr(struct mbuf *m, int skip, int hlen);
    422  1.1  jonathan 
    423  1.1  jonathan /* Per-socket caching of IPsec output policy */
    424  1.1  jonathan static __inline int ipsec_clear_socket_cache(struct mbuf *m)
    425  1.1  jonathan {
    426  1.1  jonathan   return 0;
    427  1.1  jonathan }
    428  1.1  jonathan 
    429  1.1  jonathan 
    430  1.1  jonathan #endif /* _KERNEL */
    431  1.1  jonathan 
    432  1.1  jonathan #ifndef _KERNEL
    433  1.1  jonathan extern caddr_t ipsec_set_policy __P((char *, int));
    434  1.1  jonathan extern int ipsec_get_policylen __P((caddr_t));
    435  1.1  jonathan extern char *ipsec_dump_policy __P((caddr_t, char *));
    436  1.1  jonathan 
    437  1.1  jonathan extern const char *ipsec_strerror __P((void));
    438  1.1  jonathan #endif /* !_KERNEL */
    439  1.1  jonathan 
    440  1.1  jonathan /*
    441  1.1  jonathan  * Porting glue for impedance mismatches between {free,net,open}bsd
    442  1.1  jonathan  */
    443  1.1  jonathan #ifdef __FreeBSD__
    444  1.1  jonathan   #define IPSEC_ASSERT(x, y) KASSERT(x, y)
    445  1.1  jonathan   #define INITFN static
    446  1.1  jonathan #endif
    447  1.1  jonathan #ifdef __NetBSD__
    448  1.1  jonathan   #define IPSEC_ASSERT(x, y) KASSERT(x)
    449  1.1  jonathan #define INITFN extern
    450  1.1  jonathan 
    451  1.1  jonathan /* External declarations of per-file init functions */
    452  1.1  jonathan INITFN void ah_attach(void);
    453  1.1  jonathan INITFN void esp_attach(void);
    454  1.1  jonathan INITFN void ipcomp_attach(void);
    455  1.1  jonathan INITFN void ipe4_attach(void);
    456  1.1  jonathan 
    457  1.1  jonathan INITFN void ipsec_attach(void);
    458  1.1  jonathan #endif /* __NetBSD __ */
    459  1.1  jonathan 
    460  1.1  jonathan #endif /* _NETIPSEC_IPSEC_H_ */
    461