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