Home | History | Annotate | Line # | Download | only in npf
npf_conn.h revision 1.5.2.2
      1  1.5.2.2  tls /*	$NetBSD: npf_conn.h,v 1.5.2.2 2014/08/10 06:56:16 tls Exp $	*/
      2  1.5.2.2  tls 
      3  1.5.2.2  tls /*-
      4  1.5.2.2  tls  * Copyright (c) 2009-2014 The NetBSD Foundation, Inc.
      5  1.5.2.2  tls  * All rights reserved.
      6  1.5.2.2  tls  *
      7  1.5.2.2  tls  * This material is based upon work partially supported by The
      8  1.5.2.2  tls  * NetBSD Foundation under a contract with Mindaugas Rasiukevicius.
      9  1.5.2.2  tls  *
     10  1.5.2.2  tls  * Redistribution and use in source and binary forms, with or without
     11  1.5.2.2  tls  * modification, are permitted provided that the following conditions
     12  1.5.2.2  tls  * are met:
     13  1.5.2.2  tls  * 1. Redistributions of source code must retain the above copyright
     14  1.5.2.2  tls  *    notice, this list of conditions and the following disclaimer.
     15  1.5.2.2  tls  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.5.2.2  tls  *    notice, this list of conditions and the following disclaimer in the
     17  1.5.2.2  tls  *    documentation and/or other materials provided with the distribution.
     18  1.5.2.2  tls  *
     19  1.5.2.2  tls  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.5.2.2  tls  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.5.2.2  tls  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.5.2.2  tls  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.5.2.2  tls  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.5.2.2  tls  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.5.2.2  tls  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.5.2.2  tls  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.5.2.2  tls  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.5.2.2  tls  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.5.2.2  tls  * POSSIBILITY OF SUCH DAMAGE.
     30  1.5.2.2  tls  */
     31  1.5.2.2  tls 
     32  1.5.2.2  tls #ifndef _NPF_CONN_H_
     33  1.5.2.2  tls #define _NPF_CONN_H_
     34  1.5.2.2  tls 
     35  1.5.2.2  tls #if !defined(_KERNEL)
     36  1.5.2.2  tls #error "kernel-level header only"
     37  1.5.2.2  tls #endif
     38  1.5.2.2  tls 
     39  1.5.2.2  tls #include <sys/types.h>
     40  1.5.2.2  tls 
     41  1.5.2.2  tls #include "npf_impl.h"
     42  1.5.2.2  tls 
     43  1.5.2.2  tls typedef struct npf_connkey npf_connkey_t;
     44  1.5.2.2  tls 
     45  1.5.2.2  tls #if defined(__NPF_CONN_PRIVATE)
     46  1.5.2.2  tls 
     47  1.5.2.2  tls #include <sys/rbtree.h>
     48  1.5.2.2  tls 
     49  1.5.2.2  tls /*
     50  1.5.2.2  tls  * See npf_conn_key() function for the description key layout.
     51  1.5.2.2  tls  */
     52  1.5.2.2  tls #define	NPF_CONN_NKEYWORDS	(2 + ((sizeof(npf_addr_t) * 2) >> 2))
     53  1.5.2.2  tls #define	NPF_CONN_MAXKEYLEN	(NPF_CONN_NKEYWORDS * sizeof(uint32_t))
     54  1.5.2.2  tls #define	NPF_CONN_GETALEN(key)	((key)->ck_key[0] & 0xffff)
     55  1.5.2.2  tls #define	NPF_CONN_KEYLEN(key)	(8 + (2 * NPF_CONN_GETALEN(key)))
     56  1.5.2.2  tls 
     57  1.5.2.2  tls struct npf_connkey {
     58  1.5.2.2  tls 	/* Entry node and back-pointer to the actual connection. */
     59  1.5.2.2  tls 	rb_node_t		ck_rbnode;
     60  1.5.2.2  tls 	uint32_t		ck_key[NPF_CONN_NKEYWORDS];
     61  1.5.2.2  tls 	npf_conn_t *		ck_backptr;
     62  1.5.2.2  tls };
     63  1.5.2.2  tls 
     64  1.5.2.2  tls /*
     65  1.5.2.2  tls  * The main connection tracking structure.
     66  1.5.2.2  tls  */
     67  1.5.2.2  tls 
     68  1.5.2.2  tls struct npf_conn {
     69  1.5.2.2  tls 	/*
     70  1.5.2.2  tls 	 * Connection "forwards" and "backwards" entries, plus the
     71  1.5.2.2  tls 	 * interface ID (if zero, then the state is global).
     72  1.5.2.2  tls 	 */
     73  1.5.2.2  tls 	npf_connkey_t		c_forw_entry;
     74  1.5.2.2  tls 	npf_connkey_t		c_back_entry;
     75  1.5.2.2  tls 	u_int			c_proto;
     76  1.5.2.2  tls 	u_int			c_ifid;
     77  1.5.2.2  tls 
     78  1.5.2.2  tls 	/* Flags and entry in the connection database or G/C list. */
     79  1.5.2.2  tls 	u_int			c_flags;
     80  1.5.2.2  tls 	npf_conn_t *		c_next;
     81  1.5.2.2  tls 
     82  1.5.2.2  tls 	/* Associated rule procedure or NAT (if any). */
     83  1.5.2.2  tls 	npf_rproc_t *		c_rproc;
     84  1.5.2.2  tls 	npf_nat_t *		c_nat;
     85  1.5.2.2  tls 
     86  1.5.2.2  tls 	/*
     87  1.5.2.2  tls 	 * The protocol state, reference count and the last activity
     88  1.5.2.2  tls 	 * time (used to calculate expiration time).
     89  1.5.2.2  tls 	 */
     90  1.5.2.2  tls 	kmutex_t		c_lock;
     91  1.5.2.2  tls 	npf_state_t		c_state;
     92  1.5.2.2  tls 	u_int			c_refcnt;
     93  1.5.2.2  tls 	struct timespec		c_atime;
     94  1.5.2.2  tls };
     95  1.5.2.2  tls 
     96  1.5.2.2  tls #endif
     97  1.5.2.2  tls 
     98  1.5.2.2  tls /*
     99  1.5.2.2  tls  * Connection tracking interface.
    100  1.5.2.2  tls  */
    101  1.5.2.2  tls void		npf_conn_sysinit(void);
    102  1.5.2.2  tls void		npf_conn_sysfini(void);
    103  1.5.2.2  tls void		npf_conn_tracking(bool);
    104  1.5.2.2  tls void		npf_conn_load(npf_conndb_t *, bool);
    105  1.5.2.2  tls 
    106  1.5.2.2  tls unsigned	npf_conn_conkey(const npf_cache_t *, npf_connkey_t *, bool);
    107  1.5.2.2  tls npf_conn_t *	npf_conn_lookup(const npf_cache_t *, const int, bool *);
    108  1.5.2.2  tls npf_conn_t *	npf_conn_inspect(npf_cache_t *, const int, int *);
    109  1.5.2.2  tls npf_conn_t *	npf_conn_establish(npf_cache_t *, int, bool);
    110  1.5.2.2  tls void		npf_conn_release(npf_conn_t *);
    111  1.5.2.2  tls void		npf_conn_expire(npf_conn_t *);
    112  1.5.2.2  tls bool		npf_conn_pass(const npf_conn_t *, npf_rproc_t **);
    113  1.5.2.2  tls void		npf_conn_setpass(npf_conn_t *, npf_rproc_t *);
    114  1.5.2.2  tls int		npf_conn_setnat(const npf_cache_t *, npf_conn_t *,
    115  1.5.2.2  tls 		    npf_nat_t *, u_int);
    116  1.5.2.2  tls npf_nat_t *	npf_conn_retnat(npf_conn_t *, const int, bool *);
    117  1.5.2.2  tls void		npf_conn_gc(npf_conndb_t *, bool, bool);
    118  1.5.2.2  tls int		npf_conn_export(prop_array_t);
    119  1.5.2.2  tls int		npf_conn_import(npf_conndb_t *, prop_dictionary_t,
    120  1.5.2.2  tls 		    npf_ruleset_t *);
    121  1.5.2.2  tls void		npf_conn_print(const npf_conn_t *);
    122  1.5.2.2  tls 
    123  1.5.2.2  tls /*
    124  1.5.2.2  tls  * Connection database (aka state table) interface.
    125  1.5.2.2  tls  */
    126  1.5.2.2  tls npf_conndb_t *	npf_conndb_create(void);
    127  1.5.2.2  tls void		npf_conndb_destroy(npf_conndb_t *);
    128  1.5.2.2  tls 
    129  1.5.2.2  tls npf_conn_t *	npf_conndb_lookup(npf_conndb_t *, const npf_connkey_t *,
    130  1.5.2.2  tls 		    bool *);
    131  1.5.2.2  tls bool		npf_conndb_insert(npf_conndb_t *, npf_connkey_t *,
    132  1.5.2.2  tls 		    npf_conn_t *);
    133  1.5.2.2  tls npf_conn_t *	npf_conndb_remove(npf_conndb_t *, const npf_connkey_t *);
    134  1.5.2.2  tls 
    135  1.5.2.2  tls void		npf_conndb_enqueue(npf_conndb_t *, npf_conn_t *);
    136  1.5.2.2  tls void		npf_conndb_dequeue(npf_conndb_t *, npf_conn_t *,
    137  1.5.2.2  tls 		    npf_conn_t *);
    138  1.5.2.2  tls npf_conn_t *	npf_conndb_getlist(npf_conndb_t *);
    139  1.5.2.2  tls void		npf_conndb_settail(npf_conndb_t *, npf_conn_t *);
    140  1.5.2.2  tls 
    141  1.5.2.2  tls #endif	/* _NPF_CONN_H_ */
    142