Home | History | Annotate | Line # | Download | only in netinet
ip_nat.h revision 1.3
      1  1.3   darrenr /*	$NetBSD: ip_nat.h,v 1.3 2012/07/22 14:27:51 darrenr Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.3   darrenr  * Copyright (C) 2012 by Darren Reed.
      5  1.1  christos  *
      6  1.1  christos  * See the IPFILTER.LICENCE file for details on licencing.
      7  1.1  christos  *
      8  1.1  christos  * @(#)ip_nat.h	1.5 2/4/96
      9  1.3   darrenr  * Id: ip_nat.h,v 1.1.1.2 2012/07/22 13:45:29 darrenr Exp
     10  1.1  christos  */
     11  1.1  christos 
     12  1.1  christos #ifndef	__IP_NAT_H__
     13  1.1  christos #define	__IP_NAT_H__
     14  1.1  christos 
     15  1.1  christos #ifndef SOLARIS
     16  1.1  christos #define	SOLARIS	(defined(sun) && (defined(__svr4__) || defined(__SVR4)))
     17  1.1  christos #endif
     18  1.1  christos 
     19  1.1  christos #if defined(__STDC__) || defined(__GNUC__) || defined(_AIX51)
     20  1.1  christos #define	SIOCADNAT	_IOW('r', 60, struct ipfobj)
     21  1.1  christos #define	SIOCRMNAT	_IOW('r', 61, struct ipfobj)
     22  1.1  christos #define	SIOCGNATS	_IOWR('r', 62, struct ipfobj)
     23  1.1  christos #define	SIOCGNATL	_IOWR('r', 63, struct ipfobj)
     24  1.3   darrenr #define	SIOCPURGENAT	_IOWR('r', 100, struct ipfobj)
     25  1.1  christos #else
     26  1.1  christos #define	SIOCADNAT	_IOW(r, 60, struct ipfobj)
     27  1.1  christos #define	SIOCRMNAT	_IOW(r, 61, struct ipfobj)
     28  1.1  christos #define	SIOCGNATS	_IOWR(r, 62, struct ipfobj)
     29  1.1  christos #define	SIOCGNATL	_IOWR(r, 63, struct ipfobj)
     30  1.3   darrenr #define	SIOCPURGENAT	_IOWR(r, 100, struct ipfobj)
     31  1.1  christos #endif
     32  1.1  christos 
     33  1.1  christos #undef	LARGE_NAT	/* define	this if you're setting up a system to NAT
     34  1.1  christos 			 * LARGE numbers of networks/hosts - i.e. in the
     35  1.1  christos 			 * hundreds or thousands.  In such a case, you should
     36  1.1  christos 			 * also change the RDR_SIZE and NAT_SIZE below to more
     37  1.1  christos 			 * appropriate sizes.  The figures below were used for
     38  1.1  christos 			 * a setup with 1000-2000 networks to NAT.
     39  1.1  christos 			 */
     40  1.1  christos #ifndef NAT_SIZE
     41  1.1  christos # ifdef LARGE_NAT
     42  1.1  christos #  define	NAT_SIZE	2047
     43  1.1  christos # else
     44  1.1  christos #  define	NAT_SIZE	127
     45  1.1  christos # endif
     46  1.1  christos #endif
     47  1.1  christos #ifndef RDR_SIZE
     48  1.1  christos # ifdef LARGE_NAT
     49  1.1  christos #  define	RDR_SIZE	2047
     50  1.1  christos # else
     51  1.1  christos #  define	RDR_SIZE	127
     52  1.1  christos # endif
     53  1.1  christos #endif
     54  1.1  christos #ifndef HOSTMAP_SIZE
     55  1.1  christos # ifdef LARGE_NAT
     56  1.1  christos #  define	HOSTMAP_SIZE	8191
     57  1.1  christos # else
     58  1.1  christos #  define	HOSTMAP_SIZE	2047
     59  1.1  christos # endif
     60  1.1  christos #endif
     61  1.1  christos #ifndef NAT_TABLE_MAX
     62  1.1  christos /*
     63  1.1  christos  * This is newly introduced and for the sake of "least surprise", the numbers
     64  1.1  christos  * present aren't what we'd normally use for creating a proper hash table.
     65  1.1  christos  */
     66  1.1  christos # ifdef	LARGE_NAT
     67  1.1  christos #  define	NAT_TABLE_MAX	180000
     68  1.1  christos # else
     69  1.1  christos #  define	NAT_TABLE_MAX	30000
     70  1.1  christos # endif
     71  1.1  christos #endif
     72  1.1  christos #ifndef NAT_TABLE_SZ
     73  1.1  christos # ifdef LARGE_NAT
     74  1.1  christos #  define	NAT_TABLE_SZ	16383
     75  1.1  christos # else
     76  1.1  christos #  define	NAT_TABLE_SZ	2047
     77  1.1  christos # endif
     78  1.1  christos #endif
     79  1.1  christos #ifndef	APR_LABELLEN
     80  1.1  christos #define	APR_LABELLEN	16
     81  1.1  christos #endif
     82  1.3   darrenr #define	NAT_HW_CKSUM		0x80000000
     83  1.3   darrenr #define	NAT_HW_CKSUM_PART	0x40000000
     84  1.1  christos 
     85  1.1  christos #define	DEF_NAT_AGE	1200     /* 10 minutes (600 seconds) */
     86  1.1  christos 
     87  1.1  christos struct ipstate;
     88  1.1  christos struct ap_session;
     89  1.1  christos 
     90  1.1  christos /*
     91  1.1  christos  * This structure is used in the active NAT table and represents an
     92  1.1  christos  * active NAT session.
     93  1.1  christos  */
     94  1.1  christos typedef	struct	nat	{
     95  1.1  christos 	ipfmutex_t	nat_lock;
     96  1.1  christos 	struct	nat	*nat_next;
     97  1.1  christos 	struct	nat	**nat_pnext;
     98  1.1  christos 	struct	nat	*nat_hnext[2];
     99  1.1  christos 	struct	nat	**nat_phnext[2];
    100  1.1  christos 	struct	hostmap	*nat_hm;
    101  1.1  christos 	void		*nat_data;
    102  1.1  christos 	struct	nat	**nat_me;
    103  1.1  christos 	struct	ipstate	*nat_state;
    104  1.1  christos 	struct	ap_session	*nat_aps;		/* proxy session */
    105  1.1  christos 	frentry_t	*nat_fr;	/* filter rule ptr if appropriate */
    106  1.1  christos 	struct	ipnat	*nat_ptr;	/* pointer back to the rule */
    107  1.1  christos 	void		*nat_ifps[2];
    108  1.1  christos 	void		*nat_sync;
    109  1.1  christos 	ipftqent_t	nat_tqe;
    110  1.1  christos 	int		nat_mtu[2];
    111  1.1  christos 	u_32_t		nat_flags;
    112  1.1  christos 	u_32_t		nat_sumd[2];	/* ip checksum delta for data segment*/
    113  1.1  christos 	u_32_t		nat_ipsumd;	/* ip checksum delta for ip header */
    114  1.1  christos 	u_32_t		nat_mssclamp;	/* if != zero clamp MSS to this */
    115  1.1  christos 	i6addr_t	nat_odst6;
    116  1.1  christos 	i6addr_t	nat_osrc6;
    117  1.1  christos 	i6addr_t	nat_ndst6;
    118  1.1  christos 	i6addr_t	nat_nsrc6;
    119  1.1  christos 	U_QUAD_T	nat_pkts[2];
    120  1.1  christos 	U_QUAD_T	nat_bytes[2];
    121  1.1  christos 	union	{
    122  1.1  christos 		udpinfo_t	nat_unu;
    123  1.1  christos 		tcpinfo_t	nat_unt;
    124  1.1  christos 		icmpinfo_t	nat_uni;
    125  1.1  christos 		greinfo_t	nat_ugre;
    126  1.1  christos 	} nat_unold, nat_unnew;
    127  1.1  christos 	int		nat_use;
    128  1.1  christos 	int		nat_pr[2];		/* protocol for NAT */
    129  1.1  christos 	int		nat_dir;
    130  1.1  christos 	int		nat_ref;		/* reference count */
    131  1.1  christos 	u_int		nat_hv[2];
    132  1.1  christos 	char		nat_ifnames[2][LIFNAMSIZ];
    133  1.1  christos 	int		nat_rev;		/* 0 = forward, 1 = reverse */
    134  1.1  christos 	int		nat_dlocal;
    135  1.1  christos 	int		nat_v[2];		/* 0 = old, 1 = new */
    136  1.1  christos 	u_int		nat_redir;		/* copy of in_redir */
    137  1.1  christos } nat_t;
    138  1.1  christos 
    139  1.1  christos #define	nat_osrcip	nat_osrc6.in4
    140  1.1  christos #define	nat_odstip	nat_odst6.in4
    141  1.1  christos #define	nat_nsrcip	nat_nsrc6.in4
    142  1.1  christos #define	nat_ndstip	nat_ndst6.in4
    143  1.1  christos #define	nat_osrcaddr	nat_osrc6.in4.s_addr
    144  1.1  christos #define	nat_odstaddr	nat_odst6.in4.s_addr
    145  1.1  christos #define	nat_nsrcaddr	nat_nsrc6.in4.s_addr
    146  1.1  christos #define	nat_ndstaddr	nat_ndst6.in4.s_addr
    147  1.1  christos #define	nat_age		nat_tqe.tqe_die
    148  1.1  christos #define	nat_osport	nat_unold.nat_unt.ts_sport
    149  1.1  christos #define	nat_odport	nat_unold.nat_unt.ts_dport
    150  1.1  christos #define	nat_nsport	nat_unnew.nat_unt.ts_sport
    151  1.1  christos #define	nat_ndport	nat_unnew.nat_unt.ts_dport
    152  1.1  christos #define	nat_oicmpid	nat_unold.nat_uni.ici_id
    153  1.1  christos #define	nat_nicmpid	nat_unnew.nat_uni.ici_id
    154  1.1  christos #define	nat_type	nat_unold.nat_uni.ici_type
    155  1.1  christos #define	nat_oseq	nat_unold.nat_uni.ici_seq
    156  1.1  christos #define	nat_nseq	nat_unnew.nat_uni.ici_seq
    157  1.1  christos #define	nat_tcpstate	nat_tqe.tqe_state
    158  1.1  christos #define	nat_die		nat_tqe.tqe_die
    159  1.1  christos #define	nat_touched	nat_tqe.tqe_touched
    160  1.1  christos 
    161  1.1  christos /*
    162  1.1  christos  * Values for nat_dir
    163  1.1  christos  */
    164  1.1  christos #define	NAT_INBOUND	0
    165  1.1  christos #define	NAT_OUTBOUND	1
    166  1.1  christos #define	NAT_ENCAPIN	2
    167  1.1  christos #define	NAT_ENCAPOUT	3
    168  1.1  christos #define	NAT_DIVERTIN	4
    169  1.1  christos #define	NAT_DIVERTOUT	5
    170  1.1  christos 
    171  1.1  christos /*
    172  1.1  christos  * Definitions for nat_flags
    173  1.1  christos  */
    174  1.1  christos #define	NAT_TCP		0x0001	/* IPN_TCP */
    175  1.1  christos #define	NAT_UDP		0x0002	/* IPN_UDP */
    176  1.1  christos #define	NAT_ICMPERR	0x0004	/* IPN_ICMPERR */
    177  1.1  christos #define	NAT_ICMPQUERY	0x0008	/* IPN_ICMPQUERY */
    178  1.1  christos #define	NAT_SEARCH	0x0010
    179  1.1  christos #define	NAT_SLAVE	0x0020	/* Slave connection for a proxy */
    180  1.1  christos #define	NAT_NOTRULEPORT	0x0040	/* Don't use the port # in the NAT rule */
    181  1.1  christos 
    182  1.1  christos #define	NAT_TCPUDP	(NAT_TCP|NAT_UDP)
    183  1.1  christos #define	NAT_TCPUDPICMP	(NAT_TCP|NAT_UDP|NAT_ICMPERR)
    184  1.1  christos #define	NAT_TCPUDPICMPQ	(NAT_TCP|NAT_UDP|NAT_ICMPQUERY)
    185  1.1  christos #define	NAT_FROMRULE	(NAT_TCP|NAT_UDP)
    186  1.1  christos 
    187  1.1  christos /* 0x0100 reserved for FI_W_SPORT */
    188  1.1  christos /* 0x0200 reserved for FI_W_DPORT */
    189  1.1  christos /* 0x0400 reserved for FI_W_SADDR */
    190  1.1  christos /* 0x0800 reserved for FI_W_DADDR */
    191  1.1  christos /* 0x1000 reserved for FI_W_NEWFR */
    192  1.1  christos /* 0x2000 reserved for SI_CLONE */
    193  1.1  christos /* 0x4000 reserved for SI_CLONED */
    194  1.1  christos /* 0x8000 reserved for SI_IGNOREPKT */
    195  1.1  christos 
    196  1.1  christos #define	NAT_DEBUG	0x800000
    197  1.1  christos 
    198  1.1  christos typedef	struct nat_addr_s {
    199  1.1  christos 	i6addr_t	na_addr[2];
    200  1.1  christos 	i6addr_t	na_nextaddr;
    201  1.1  christos 	int		na_atype;
    202  1.1  christos 	int		na_function;
    203  1.1  christos } nat_addr_t;
    204  1.1  christos 
    205  1.1  christos #define	na_nextip	na_nextaddr.in4.s_addr
    206  1.1  christos #define	na_nextip6	na_nextaddr.in6
    207  1.1  christos #define	na_num		na_addr[0].iplookupnum
    208  1.1  christos #define	na_type		na_addr[0].iplookuptype
    209  1.1  christos #define	na_subtype	na_addr[0].iplookupsubtype
    210  1.1  christos #define	na_ptr		na_addr[1].iplookupptr
    211  1.1  christos #define	na_func		na_addr[1].iplookupfunc
    212  1.1  christos 
    213  1.1  christos 
    214  1.1  christos /*
    215  1.1  christos  * This structure represents an actual NAT rule, loaded by ipnat.
    216  1.1  christos  */
    217  1.1  christos typedef	struct	ipnat	{
    218  1.1  christos 	ipfmutex_t	in_lock;
    219  1.1  christos 	struct	ipnat	*in_next;		/* NAT rule list next */
    220  1.1  christos 	struct	ipnat	**in_pnext;		/* prior rdr next ptr */
    221  1.1  christos 	struct	ipnat	*in_rnext;		/* rdr rule hash next */
    222  1.1  christos 	struct	ipnat	**in_prnext;		/* prior rdr next ptr */
    223  1.1  christos 	struct	ipnat	*in_mnext;		/* map rule hash next */
    224  1.1  christos 	struct	ipnat	**in_pmnext;		/* prior map next ptr */
    225  1.1  christos 	struct	ipftq	*in_tqehead[2];
    226  1.1  christos 	void		*in_ifps[2];
    227  1.1  christos 	void		*in_apr;
    228  1.1  christos 	char		*in_comment;
    229  1.1  christos 	mb_t		*in_divmp;
    230  1.1  christos 	void		*in_pconf;
    231  1.3   darrenr 	U_QUAD_T	in_pkts[2];
    232  1.3   darrenr 	U_QUAD_T	in_bytes[2];
    233  1.1  christos 	u_long		in_space;
    234  1.1  christos 	u_long		in_hits;
    235  1.1  christos 	int		in_size;
    236  1.3   darrenr 	int		in_use;
    237  1.1  christos 	u_int		in_hv[2];
    238  1.1  christos 	int		in_flineno;		/* conf. file line number */
    239  1.1  christos 	int		in_stepnext;
    240  1.1  christos 	int		in_dlocal;
    241  1.1  christos 	u_short		in_dpnext;
    242  1.1  christos 	u_short		in_spnext;
    243  1.1  christos 	/* From here to the end is covered by IPN_CMPSIZ */
    244  1.1  christos 	u_char		in_v[2];		/* 0 = old, 1 = new */
    245  1.1  christos 	u_32_t		in_flags;
    246  1.1  christos 	u_32_t		in_mssclamp;		/* if != 0 clamp MSS to this */
    247  1.1  christos 	u_int		in_age[2];
    248  1.1  christos 	int		in_redir;		/* see below for values */
    249  1.1  christos 	int		in_pr[2];		/* protocol. */
    250  1.1  christos 	nat_addr_t	in_ndst;
    251  1.1  christos 	nat_addr_t	in_nsrc;
    252  1.1  christos 	nat_addr_t	in_osrc;
    253  1.1  christos 	nat_addr_t	in_odst;
    254  1.1  christos 	frtuc_t		in_tuc;
    255  1.1  christos 	u_short		in_ppip;		/* ports per IP. */
    256  1.1  christos 	u_short		in_ippip;		/* IP #'s per IP# */
    257  1.1  christos 	u_short		in_ndports[2];
    258  1.1  christos 	u_short		in_nsports[2];
    259  1.1  christos 	int		in_ifnames[2];
    260  1.1  christos 	int		in_plabel;	/* proxy label. */
    261  1.1  christos 	int		in_pconfig;	/* proxy label. */
    262  1.1  christos 	ipftag_t	in_tag;
    263  1.1  christos 	int		in_namelen;
    264  1.1  christos 	char		in_names[1];
    265  1.1  christos } ipnat_t;
    266  1.1  christos 
    267  1.1  christos /*
    268  1.1  christos  *      MAP-IN MAP-OUT RDR-IN RDR-OUT
    269  1.1  christos  * osrc    X   == src  == src    X
    270  1.1  christos  * odst    X   == dst  == dst    X
    271  1.1  christos  * nsrc == dst   X       X    == dst
    272  1.1  christos  * ndst == src   X       X    == src
    273  1.1  christos  */
    274  1.1  christos #define	in_dpmin	in_ndports[0]	/* Also holds static redir port */
    275  1.1  christos #define	in_dpmax	in_ndports[1]
    276  1.1  christos #define	in_spmin	in_nsports[0]	/* Also holds static redir port */
    277  1.1  christos #define	in_spmax	in_nsports[1]
    278  1.1  christos #define	in_ndport	in_ndports[0]
    279  1.1  christos #define	in_nsport	in_nsports[0]
    280  1.1  christos #define	in_dipnext	in_ndst.na_nextaddr.in4
    281  1.1  christos #define	in_dipnext6	in_ndst.na_nextaddr
    282  1.1  christos #define	in_dnip		in_ndst.na_nextaddr.in4.s_addr
    283  1.1  christos #define	in_dnip6	in_ndst.na_nextaddr
    284  1.1  christos #define	in_sipnext	in_nsrc.na_nextaddr.in4
    285  1.1  christos #define	in_snip		in_nsrc.na_nextaddr.in4.s_addr
    286  1.1  christos #define	in_snip6	in_nsrc.na_nextaddr
    287  1.1  christos #define	in_odstip	in_odst.na_addr[0].in4
    288  1.1  christos #define	in_odstip6	in_odst.na_addr[0]
    289  1.1  christos #define	in_odstaddr	in_odst.na_addr[0].in4.s_addr
    290  1.1  christos #define	in_odstmsk	in_odst.na_addr[1].in4.s_addr
    291  1.1  christos #define	in_odstmsk6	in_odst.na_addr[1]
    292  1.1  christos #define	in_odstatype	in_odst.na_atype
    293  1.1  christos #define	in_osrcip	in_osrc.na_addr[0].in4
    294  1.1  christos #define	in_osrcip6	in_osrc.na_addr[0]
    295  1.1  christos #define	in_osrcaddr	in_osrc.na_addr[0].in4.s_addr
    296  1.1  christos #define	in_osrcmsk	in_osrc.na_addr[1].in4.s_addr
    297  1.1  christos #define	in_osrcmsk6	in_osrc.na_addr[1]
    298  1.1  christos #define	in_osrcatype	in_osrc.na_atype
    299  1.1  christos #define	in_ndstip	in_ndst.na_addr[0].in4
    300  1.1  christos #define	in_ndstip6	in_ndst.na_addr[0]
    301  1.1  christos #define	in_ndstaddr	in_ndst.na_addr[0].in4.s_addr
    302  1.1  christos #define	in_ndstmsk	in_ndst.na_addr[1].in4.s_addr
    303  1.1  christos #define	in_ndstmsk6	in_ndst.na_addr[1]
    304  1.1  christos #define	in_ndstatype	in_ndst.na_atype
    305  1.1  christos #define	in_ndstafunc	in_ndst.na_function
    306  1.1  christos #define	in_nsrcip	in_nsrc.na_addr[0].in4
    307  1.1  christos #define	in_nsrcip6	in_nsrc.na_addr[0]
    308  1.1  christos #define	in_nsrcaddr	in_nsrc.na_addr[0].in4.s_addr
    309  1.1  christos #define	in_nsrcmsk	in_nsrc.na_addr[1].in4.s_addr
    310  1.1  christos #define	in_nsrcmsk6	in_nsrc.na_addr[1]
    311  1.1  christos #define	in_nsrcatype	in_nsrc.na_atype
    312  1.1  christos #define	in_nsrcafunc	in_nsrc.na_function
    313  1.1  christos #define	in_scmp		in_tuc.ftu_scmp
    314  1.1  christos #define	in_dcmp		in_tuc.ftu_dcmp
    315  1.1  christos #define	in_stop		in_tuc.ftu_stop
    316  1.1  christos #define	in_dtop		in_tuc.ftu_dtop
    317  1.1  christos #define	in_osport	in_tuc.ftu_sport
    318  1.1  christos #define	in_odport	in_tuc.ftu_dport
    319  1.1  christos #define	in_ndstnum	in_ndst.na_addr[0].iplookupnum
    320  1.1  christos #define	in_ndsttype	in_ndst.na_addr[0].iplookuptype
    321  1.1  christos #define	in_ndstptr	in_ndst.na_addr[1].iplookupptr
    322  1.1  christos #define	in_ndstfunc	in_ndst.na_addr[1].iplookupfunc
    323  1.1  christos #define	in_nsrcnum	in_nsrc.na_addr[0].iplookupnum
    324  1.1  christos #define	in_nsrctype	in_nsrc.na_addr[0].iplookuptype
    325  1.1  christos #define	in_nsrcptr	in_nsrc.na_addr[1].iplookupptr
    326  1.1  christos #define	in_nsrcfunc	in_nsrc.na_addr[1].iplookupfunc
    327  1.1  christos #define	in_odstnum	in_odst.na_addr[0].iplookupnum
    328  1.1  christos #define	in_odsttype	in_odst.na_addr[0].iplookuptype
    329  1.1  christos #define	in_odstptr	in_odst.na_addr[1].iplookupptr
    330  1.1  christos #define	in_odstfunc	in_odst.na_addr[1].iplookupfunc
    331  1.1  christos #define	in_osrcnum	in_osrc.na_addr[0].iplookupnum
    332  1.1  christos #define	in_osrctype	in_osrc.na_addr[0].iplookuptype
    333  1.1  christos #define	in_osrcptr	in_osrc.na_addr[1].iplookupptr
    334  1.1  christos #define	in_osrcfunc	in_osrc.na_addr[1].iplookupfunc
    335  1.1  christos #define	in_icmpidmin	in_nsports[0]
    336  1.1  christos #define	in_icmpidmax	in_nsports[1]
    337  1.1  christos 
    338  1.1  christos /*
    339  1.1  christos  * Bit definitions for in_flags
    340  1.1  christos  */
    341  1.1  christos #define	IPN_ANY		0x00000
    342  1.1  christos #define	IPN_TCP		0x00001
    343  1.1  christos #define	IPN_UDP		0x00002
    344  1.1  christos #define	IPN_TCPUDP	(IPN_TCP|IPN_UDP)
    345  1.1  christos #define	IPN_ICMPERR	0x00004
    346  1.1  christos #define	IPN_TCPUDPICMP	(IPN_TCP|IPN_UDP|IPN_ICMPERR)
    347  1.1  christos #define	IPN_ICMPQUERY	0x00008
    348  1.1  christos #define	IPN_TCPUDPICMPQ	(IPN_TCP|IPN_UDP|IPN_ICMPQUERY)
    349  1.1  christos #define	IPN_RF		(IPN_TCPUDP|IPN_DELETE|IPN_ICMPERR)
    350  1.1  christos #define	IPN_AUTOPORTMAP	0x00010
    351  1.1  christos #define	IPN_FILTER	0x00020
    352  1.1  christos #define	IPN_SPLIT	0x00040
    353  1.1  christos #define	IPN_ROUNDR	0x00080
    354  1.1  christos #define	IPN_SIPRANGE	0x00100
    355  1.1  christos #define	IPN_DIPRANGE	0x00200
    356  1.1  christos #define	IPN_NOTSRC	0x00400
    357  1.1  christos #define	IPN_NOTDST	0x00800
    358  1.1  christos #define	IPN_NO		0x01000
    359  1.1  christos #define	IPN_DYNSRCIP	0x02000	/* dynamic src IP# */
    360  1.1  christos #define	IPN_DYNDSTIP	0x04000	/* dynamic dst IP# */
    361  1.1  christos #define	IPN_DELETE	0x08000
    362  1.1  christos #define	IPN_STICKY	0x10000
    363  1.1  christos #define	IPN_FRAG	0x20000
    364  1.1  christos #define	IPN_FIXEDSPORT	0x40000
    365  1.1  christos #define	IPN_FIXEDDPORT	0x80000
    366  1.1  christos #define	IPN_FINDFORWARD	0x100000
    367  1.1  christos #define	IPN_IN		0x200000
    368  1.1  christos #define	IPN_SEQUENTIAL	0x400000
    369  1.3   darrenr #define	IPN_PURGE	0x800000
    370  1.3   darrenr #define	IPN_PROXYRULE	0x1000000
    371  1.1  christos #define	IPN_USERFLAGS	(IPN_TCPUDP|IPN_AUTOPORTMAP|IPN_SIPRANGE|IPN_SPLIT|\
    372  1.1  christos 			 IPN_ROUNDR|IPN_FILTER|IPN_NOTSRC|IPN_NOTDST|IPN_NO|\
    373  1.1  christos 			 IPN_FRAG|IPN_STICKY|IPN_FIXEDDPORT|IPN_ICMPQUERY|\
    374  1.3   darrenr 			 IPN_DIPRANGE|IPN_SEQUENTIAL|IPN_PURGE)
    375  1.1  christos 
    376  1.1  christos /*
    377  1.1  christos  * Values for in_redir
    378  1.1  christos  */
    379  1.1  christos #define	NAT_MAP		0x01
    380  1.1  christos #define	NAT_REDIRECT	0x02
    381  1.1  christos #define	NAT_BIMAP	(NAT_MAP|NAT_REDIRECT)
    382  1.1  christos #define	NAT_MAPBLK	0x04
    383  1.1  christos #define	NAT_REWRITE	0x08
    384  1.1  christos #define	NAT_ENCAP	0x10
    385  1.1  christos #define	NAT_DIVERTUDP	0x20
    386  1.1  christos 
    387  1.1  christos #define	MAPBLK_MINPORT	1024	/* don't use reserved ports for src port */
    388  1.1  christos #define	USABLE_PORTS	(65536 - MAPBLK_MINPORT)
    389  1.1  christos 
    390  1.1  christos #define	IPN_CMPSIZ	(sizeof(ipnat_t) - offsetof(ipnat_t, in_v))
    391  1.1  christos 
    392  1.1  christos typedef	struct	natlookup {
    393  1.1  christos 	i6addr_t	nl_inipaddr;
    394  1.1  christos 	i6addr_t	nl_outipaddr;
    395  1.1  christos 	i6addr_t	nl_realipaddr;
    396  1.1  christos 	int		nl_v;
    397  1.1  christos 	int		nl_flags;
    398  1.1  christos 	u_short		nl_inport;
    399  1.1  christos 	u_short		nl_outport;
    400  1.1  christos 	u_short		nl_realport;
    401  1.1  christos } natlookup_t;
    402  1.1  christos 
    403  1.1  christos #define	nl_inip		nl_inipaddr.in4
    404  1.1  christos #define	nl_outip	nl_outipaddr.in4
    405  1.1  christos #define	nl_realip	nl_realipaddr.in4
    406  1.1  christos #define	nl_inip6	nl_inipaddr.in6
    407  1.1  christos #define	nl_outip6	nl_outipaddr.in6
    408  1.1  christos #define	nl_realip6	nl_realipaddr.in6
    409  1.1  christos 
    410  1.1  christos 
    411  1.1  christos typedef struct  nat_save    {
    412  1.1  christos 	void	*ipn_next;
    413  1.1  christos 	struct	nat	ipn_nat;
    414  1.1  christos 	struct	ipnat	ipn_ipnat;
    415  1.1  christos 	struct	frentry ipn_fr;
    416  1.1  christos 	int	ipn_dsize;
    417  1.1  christos 	char	ipn_data[4];
    418  1.1  christos } nat_save_t;
    419  1.1  christos 
    420  1.1  christos #define	ipn_rule	ipn_nat.nat_fr
    421  1.1  christos 
    422  1.1  christos typedef	struct	natget	{
    423  1.1  christos 	void	*ng_ptr;
    424  1.1  christos 	int	ng_sz;
    425  1.1  christos } natget_t;
    426  1.1  christos 
    427  1.1  christos 
    428  1.1  christos /*
    429  1.1  christos  * This structure gets used to help NAT sessions keep the same NAT rule (and
    430  1.1  christos  * thus translation for IP address) when:
    431  1.1  christos  * (a) round-robin redirects are in use
    432  1.1  christos  * (b) different IP add
    433  1.1  christos  */
    434  1.1  christos typedef	struct	hostmap	{
    435  1.1  christos 	struct	hostmap	*hm_hnext;
    436  1.1  christos 	struct	hostmap	**hm_phnext;
    437  1.1  christos 	struct	hostmap	*hm_next;
    438  1.1  christos 	struct	hostmap	**hm_pnext;
    439  1.1  christos 	struct	ipnat	*hm_ipnat;
    440  1.1  christos 	i6addr_t	hm_osrcip6;
    441  1.1  christos 	i6addr_t	hm_odstip6;
    442  1.1  christos 	i6addr_t	hm_nsrcip6;
    443  1.1  christos 	i6addr_t	hm_ndstip6;
    444  1.1  christos 	u_32_t		hm_port;
    445  1.1  christos 	int		hm_ref;
    446  1.1  christos 	int		hm_hv;
    447  1.1  christos 	int		hm_v;
    448  1.1  christos } hostmap_t;
    449  1.1  christos 
    450  1.1  christos #define	hm_osrcip	hm_osrcip6.in4
    451  1.1  christos #define	hm_odstip	hm_odstip6.in4
    452  1.1  christos #define	hm_nsrcip	hm_nsrcip6.in4
    453  1.1  christos #define	hm_ndstip	hm_ndstip6.in4
    454  1.1  christos #define	hm_osrc6	hm_osrcip6.in6
    455  1.1  christos #define	hm_odst6	hm_odstip6.in6
    456  1.1  christos #define	hm_nsrc6	hm_nsrcip6.in6
    457  1.1  christos #define	hm_ndst6	hm_ndstip6.in6
    458  1.1  christos 
    459  1.1  christos 
    460  1.1  christos /*
    461  1.1  christos  * Structure used to pass information in to nat_newmap and nat_newrdr.
    462  1.1  christos  */
    463  1.1  christos typedef struct	natinfo	{
    464  1.1  christos 	ipnat_t		*nai_np;
    465  1.1  christos 	u_32_t		nai_sum1;
    466  1.1  christos 	u_32_t		nai_sum2;
    467  1.1  christos 	struct	in_addr	nai_ip;		/* In host byte order */
    468  1.1  christos 	u_short		nai_port;
    469  1.1  christos 	u_short		nai_nport;
    470  1.1  christos 	u_short		nai_sport;
    471  1.1  christos 	u_short		nai_dport;
    472  1.1  christos } natinfo_t;
    473  1.1  christos 
    474  1.1  christos 
    475  1.1  christos typedef	struct nat_stat_side {
    476  1.1  christos 	u_int	*ns_bucketlen;
    477  1.1  christos 	nat_t	**ns_table;
    478  1.1  christos 	u_long	ns_added;
    479  1.1  christos 	u_long	ns_appr_fail;
    480  1.1  christos 	u_long	ns_badnat;
    481  1.1  christos 	u_long	ns_badnatnew;
    482  1.1  christos 	u_long	ns_badnextaddr;
    483  1.1  christos 	u_long	ns_bucket_max;
    484  1.1  christos 	u_long	ns_clone_nomem;
    485  1.1  christos 	u_long	ns_decap_bad;
    486  1.1  christos 	u_long	ns_decap_fail;
    487  1.1  christos 	u_long	ns_decap_pullup;
    488  1.1  christos 	u_long	ns_divert_dup;
    489  1.1  christos 	u_long	ns_divert_exist;
    490  1.1  christos 	u_long	ns_drop;
    491  1.1  christos 	u_long	ns_encap_dup;
    492  1.1  christos 	u_long	ns_encap_pullup;
    493  1.1  christos 	u_long	ns_exhausted;
    494  1.1  christos 	u_long	ns_icmp_address;
    495  1.1  christos 	u_long	ns_icmp_basic;
    496  1.1  christos 	u_long	ns_icmp_mbuf;
    497  1.1  christos 	u_long	ns_icmp_notfound;
    498  1.1  christos 	u_long	ns_icmp_rebuild;
    499  1.1  christos 	u_long	ns_icmp_short;
    500  1.1  christos 	u_long	ns_icmp_size;
    501  1.1  christos 	u_long	ns_ifpaddrfail;
    502  1.1  christos 	u_long	ns_ignored;
    503  1.1  christos 	u_long	ns_insert_fail;
    504  1.1  christos 	u_long	ns_inuse;
    505  1.1  christos 	u_long	ns_log;
    506  1.1  christos 	u_long	ns_lookup_miss;
    507  1.1  christos 	u_long	ns_lookup_nowild;
    508  1.1  christos 	u_long	ns_new_ifpaddr;
    509  1.1  christos 	u_long	ns_memfail;
    510  1.1  christos 	u_long	ns_table_max;
    511  1.1  christos 	u_long	ns_translated;
    512  1.1  christos 	u_long	ns_unfinalised;
    513  1.1  christos 	u_long	ns_wrap;
    514  1.1  christos 	u_long	ns_xlate_null;
    515  1.1  christos 	u_long	ns_xlate_exists;
    516  1.1  christos 	u_long	ns_ipf_proxy_fail;
    517  1.1  christos 	u_long	ns_uncreate[2];
    518  1.1  christos } nat_stat_side_t;
    519  1.1  christos 
    520  1.1  christos 
    521  1.1  christos typedef	struct	natstat	{
    522  1.1  christos 	nat_t		*ns_instances;
    523  1.1  christos 	ipnat_t		*ns_list;
    524  1.1  christos 	hostmap_t	*ns_maplist;
    525  1.1  christos 	hostmap_t	**ns_maptable;
    526  1.1  christos 	u_int		ns_active;
    527  1.1  christos 	u_long		ns_addtrpnt;
    528  1.1  christos 	u_long		ns_divert_build;
    529  1.1  christos 	u_long		ns_expire;
    530  1.1  christos 	u_long		ns_flush_all;
    531  1.1  christos 	u_long		ns_flush_closing;
    532  1.1  christos 	u_long		ns_flush_queue;
    533  1.1  christos 	u_long		ns_flush_state;
    534  1.1  christos 	u_long		ns_flush_timeout;
    535  1.1  christos 	u_long		ns_hm_new;
    536  1.1  christos 	u_long		ns_hm_newfail;
    537  1.1  christos 	u_long		ns_hm_addref;
    538  1.1  christos 	u_long		ns_hm_nullnp;
    539  1.1  christos 	u_long		ns_log_ok;
    540  1.1  christos 	u_long		ns_log_fail;
    541  1.1  christos 	u_int		ns_hostmap_sz;
    542  1.1  christos 	u_int		ns_nattab_sz;
    543  1.1  christos 	u_int		ns_nattab_max;
    544  1.1  christos 	u_int		ns_orphans;
    545  1.1  christos 	u_int		ns_rules;
    546  1.1  christos 	u_int		ns_rules_map;
    547  1.1  christos 	u_int		ns_rules_rdr;
    548  1.1  christos 	u_int		ns_rultab_sz;
    549  1.1  christos 	u_int		ns_rdrtab_sz;
    550  1.1  christos 	u_32_t		ns_ticks;
    551  1.1  christos 	u_int		ns_trpntab_sz;
    552  1.1  christos 	u_int		ns_wilds;
    553  1.1  christos 	u_long		ns_proto[256];
    554  1.1  christos 	nat_stat_side_t	ns_side[2];
    555  1.1  christos #ifdef USE_INET6
    556  1.1  christos 	nat_stat_side_t	ns_side6[2];
    557  1.1  christos #endif
    558  1.1  christos } natstat_t;
    559  1.1  christos 
    560  1.1  christos typedef	struct	natlog {
    561  1.1  christos 	i6addr_t	nl_osrcip;
    562  1.1  christos 	i6addr_t	nl_odstip;
    563  1.1  christos 	i6addr_t	nl_nsrcip;
    564  1.1  christos 	i6addr_t	nl_ndstip;
    565  1.1  christos 	u_short		nl_osrcport;
    566  1.1  christos 	u_short		nl_odstport;
    567  1.1  christos 	u_short		nl_nsrcport;
    568  1.1  christos 	u_short		nl_ndstport;
    569  1.1  christos 	int		nl_action;
    570  1.1  christos 	int		nl_type;
    571  1.1  christos 	int		nl_rule;
    572  1.1  christos 	U_QUAD_T	nl_pkts[2];
    573  1.1  christos 	U_QUAD_T	nl_bytes[2];
    574  1.1  christos 	u_char		nl_p[2];
    575  1.1  christos 	u_char		nl_v[2];
    576  1.1  christos 	u_char		nl_ifnames[2][LIFNAMSIZ];
    577  1.1  christos } natlog_t;
    578  1.1  christos 
    579  1.1  christos 
    580  1.1  christos #define	NL_NEW		0
    581  1.1  christos #define	NL_CLONE	1
    582  1.3   darrenr #define	NL_PURGE	0xfffc
    583  1.1  christos #define	NL_DESTROY	0xfffd
    584  1.1  christos #define	NL_FLUSH	0xfffe
    585  1.1  christos #define	NL_EXPIRE	0xffff
    586  1.1  christos 
    587  1.1  christos #define	NAT_HASH_FN(_k,_l,_m)	(((_k) + ((_k) >> 12) + _l) % (_m))
    588  1.1  christos #define	NAT_HASH_FN6(_k,_l,_m)	((((u_32_t *)(_k))[3] \
    589  1.1  christos 				 + (((u_32_t *)(_k))[3] >> 12) \
    590  1.1  christos 				 + (((u_32_t *)(_k))[2]) \
    591  1.1  christos 				 + (((u_32_t *)(_k))[2] >> 12) \
    592  1.1  christos 				 + (((u_32_t *)(_k))[1]) \
    593  1.1  christos 				 + (((u_32_t *)(_k))[1] >> 12) \
    594  1.1  christos 				 + (((u_32_t *)(_k))[0]) \
    595  1.1  christos 				 + (((u_32_t *)(_k))[0] >> 12) \
    596  1.1  christos 				 + _l) % (_m))
    597  1.1  christos 
    598  1.1  christos #define	LONG_SUM(_i)	(((_i) & 0xffff) + ((_i) >> 16))
    599  1.1  christos #define	LONG_SUM6(_i)	(LONG_SUM(ntohl(((u_32_t *)(_i))[0])) + \
    600  1.1  christos 			 LONG_SUM(ntohl(((u_32_t *)(_i))[1])) + \
    601  1.1  christos 			 LONG_SUM(ntohl(((u_32_t *)(_i))[2])) + \
    602  1.1  christos 			 LONG_SUM(ntohl(((u_32_t *)(_i))[3])))
    603  1.1  christos 
    604  1.1  christos #define	CALC_SUMD(s1, s2, sd) { \
    605  1.1  christos 			    (s1) = ((s1) & 0xffff) + ((s1) >> 16); \
    606  1.1  christos 			    (s2) = ((s2) & 0xffff) + ((s2) >> 16); \
    607  1.1  christos 			    /* Do it twice */ \
    608  1.1  christos 			    (s1) = ((s1) & 0xffff) + ((s1) >> 16); \
    609  1.1  christos 			    (s2) = ((s2) & 0xffff) + ((s2) >> 16); \
    610  1.1  christos 			    /* Because ~1 == -2, We really need ~1 == -1 */ \
    611  1.1  christos 			    if ((s1) > (s2)) (s2)--; \
    612  1.1  christos 			    (sd) = (s2) - (s1); \
    613  1.1  christos 			    (sd) = ((sd) & 0xffff) + ((sd) >> 16); }
    614  1.1  christos 
    615  1.1  christos #define	NAT_SYSSPACE		0x80000000
    616  1.1  christos #define	NAT_LOCKHELD		0x40000000
    617  1.1  christos 
    618  1.1  christos /*
    619  1.1  christos  * This is present in ip_nat.h because it needs to be shared between
    620  1.1  christos  * ip_nat.c and ip_nat6.c
    621  1.1  christos  */
    622  1.1  christos typedef struct ipf_nat_softc_s {
    623  1.1  christos 	ipfmutex_t	ipf_nat_new;
    624  1.1  christos 	ipfmutex_t	ipf_nat_io;
    625  1.1  christos 	int		ipf_nat_doflush;
    626  1.1  christos 	int		ipf_nat_logging;
    627  1.1  christos 	int		ipf_nat_lock;
    628  1.1  christos 	int		ipf_nat_inited;
    629  1.1  christos 	int		ipf_nat_table_wm_high;
    630  1.1  christos 	int		ipf_nat_table_wm_low;
    631  1.1  christos 	u_int		ipf_nat_table_max;
    632  1.1  christos 	u_int		ipf_nat_table_sz;
    633  1.1  christos 	u_int		ipf_nat_maprules_sz;
    634  1.1  christos 	u_int		ipf_nat_rdrrules_sz;
    635  1.1  christos 	u_int		ipf_nat_hostmap_sz;
    636  1.1  christos 	u_int		ipf_nat_maxbucket;
    637  1.1  christos 	u_int		ipf_nat_last_force_flush;
    638  1.1  christos 	u_int		ipf_nat_defage;
    639  1.1  christos 	u_int		ipf_nat_defipage;
    640  1.1  christos 	u_int		ipf_nat_deficmpage;
    641  1.3   darrenr 	ipf_v4_masktab_t	ipf_nat_map_mask;
    642  1.3   darrenr 	ipf_v6_masktab_t	ipf_nat6_map_mask;
    643  1.3   darrenr 	ipf_v4_masktab_t	ipf_nat_rdr_mask;
    644  1.3   darrenr 	ipf_v6_masktab_t	ipf_nat6_rdr_mask;
    645  1.1  christos 	nat_t		**ipf_nat_table[2];
    646  1.1  christos 	nat_t		*ipf_nat_instances;
    647  1.1  christos 	ipnat_t		*ipf_nat_list;
    648  1.3   darrenr 	ipnat_t		**ipf_nat_list_tail;
    649  1.1  christos 	ipnat_t		**ipf_nat_map_rules;
    650  1.1  christos 	ipnat_t		**ipf_nat_rdr_rules;
    651  1.1  christos 	ipftq_t		*ipf_nat_utqe;
    652  1.1  christos 	hostmap_t	**ipf_hm_maptable ;
    653  1.1  christos 	hostmap_t	*ipf_hm_maplist ;
    654  1.1  christos 	ipftuneable_t	*ipf_nat_tune;
    655  1.1  christos 	ipftq_t		ipf_nat_udptq;
    656  1.1  christos 	ipftq_t		ipf_nat_udpacktq;
    657  1.1  christos 	ipftq_t		ipf_nat_icmptq;
    658  1.1  christos 	ipftq_t		ipf_nat_icmpacktq;
    659  1.1  christos 	ipftq_t		ipf_nat_iptq;
    660  1.1  christos 	ipftq_t		ipf_nat_pending;
    661  1.1  christos 	ipftq_t		ipf_nat_tcptq[IPF_TCP_NSTATES];
    662  1.1  christos 	natstat_t	ipf_nat_stats;
    663  1.1  christos } ipf_nat_softc_t ;
    664  1.1  christos 
    665  1.3   darrenr #define	ipf_nat_map_max			ipf_nat_map_mask.imt4_max
    666  1.3   darrenr #define	ipf_nat_rdr_max			ipf_nat_rdr_mask.imt4_max
    667  1.3   darrenr #define	ipf_nat6_map_max		ipf_nat6_map_mask.imt6_max
    668  1.3   darrenr #define	ipf_nat6_rdr_max		ipf_nat6_rdr_mask.imt6_max
    669  1.3   darrenr #define	ipf_nat_map_active_masks	ipf_nat_map_mask.imt4_active
    670  1.3   darrenr #define	ipf_nat_rdr_active_masks	ipf_nat_rdr_mask.imt4_active
    671  1.3   darrenr #define	ipf_nat6_map_active_masks	ipf_nat6_map_mask.imt6_active
    672  1.3   darrenr #define	ipf_nat6_rdr_active_masks	ipf_nat6_rdr_mask.imt6_active
    673  1.3   darrenr 
    674  1.1  christos extern	frentry_t 	ipfnatblock;
    675  1.1  christos 
    676  1.2  christos extern	void	ipf_fix_datacksum(u_short *, u_32_t);
    677  1.3   darrenr extern	void	ipf_fix_incksum(int, u_short *, u_32_t, u_32_t);
    678  1.3   darrenr extern	void	ipf_fix_outcksum(int, u_short *, u_32_t, u_32_t);
    679  1.2  christos 
    680  1.2  christos extern	int	ipf_nat_checkin(fr_info_t *, u_32_t *);
    681  1.2  christos extern	int	ipf_nat_checkout(fr_info_t *, u_32_t *);
    682  1.2  christos extern	void	ipf_nat_delete(ipf_main_softc_t *, struct nat *, int);
    683  1.2  christos extern	void	ipf_nat_deref(ipf_main_softc_t *, nat_t **);
    684  1.2  christos extern	void	ipf_nat_expire(ipf_main_softc_t *);
    685  1.3   darrenr extern	int	ipf_nat_hashtab_add(ipf_main_softc_t *,
    686  1.3   darrenr 					 ipf_nat_softc_t *, nat_t *);
    687  1.3   darrenr extern	void	ipf_nat_hostmapdel(ipf_main_softc_t *, hostmap_t **);
    688  1.2  christos extern	int	ipf_nat_hostmap_rehash(ipf_main_softc_t *,
    689  1.2  christos 					    ipftuneable_t *, ipftuneval_t *);
    690  1.2  christos extern	nat_t	*ipf_nat_icmperrorlookup(fr_info_t *, int);
    691  1.2  christos extern	nat_t	*ipf_nat_icmperror(fr_info_t *, u_int *, int);
    692  1.1  christos #if defined(__OpenBSD__)
    693  1.2  christos extern	void	ipf_nat_ifdetach(void *);
    694  1.1  christos #endif
    695  1.2  christos extern	int	ipf_nat_init(void);
    696  1.2  christos extern	nat_t	*ipf_nat_inlookup(fr_info_t *, u_int, u_int,
    697  1.2  christos 				      struct in_addr, struct in_addr);
    698  1.2  christos extern	int	ipf_nat_in(fr_info_t *, nat_t *, int, u_32_t);
    699  1.2  christos extern	int	ipf_nat_insert(ipf_main_softc_t *, ipf_nat_softc_t *,
    700  1.2  christos 				    nat_t *);
    701  1.2  christos extern	int	ipf_nat_ioctl(ipf_main_softc_t *, void *, ioctlcmd_t,
    702  1.2  christos 				   int, int, void *);
    703  1.2  christos extern	void	ipf_nat_log(ipf_main_softc_t *, ipf_nat_softc_t *,
    704  1.2  christos 				 struct nat *, u_int);
    705  1.2  christos extern	nat_t	*ipf_nat_lookupredir(natlookup_t *);
    706  1.2  christos extern	nat_t	*ipf_nat_maplookup(void *, u_int, struct in_addr,
    707  1.2  christos 				struct in_addr);
    708  1.2  christos extern	nat_t	*ipf_nat_add(fr_info_t *, ipnat_t *, nat_t **,
    709  1.2  christos 				 u_int, int);
    710  1.2  christos extern	int	ipf_nat_out(fr_info_t *, nat_t *, int, u_32_t);
    711  1.2  christos extern	nat_t	*ipf_nat_outlookup(fr_info_t *, u_int, u_int,
    712  1.2  christos 				       struct in_addr, struct in_addr);
    713  1.2  christos extern	u_short	*ipf_nat_proto(fr_info_t *, nat_t *, u_int);
    714  1.3   darrenr extern	void	ipf_nat_rule_deref(ipf_main_softc_t *, ipnat_t **);
    715  1.2  christos extern	void	ipf_nat_setqueue(ipf_main_softc_t *, ipf_nat_softc_t *,
    716  1.2  christos 				      nat_t *);
    717  1.2  christos extern	void	ipf_nat_setpending(ipf_main_softc_t *, nat_t *);
    718  1.2  christos extern	nat_t	*ipf_nat_tnlookup(fr_info_t *, int);
    719  1.2  christos extern	void	ipf_nat_update(fr_info_t *, nat_t *);
    720  1.2  christos extern	frentry_t *ipf_nat_ipfin(fr_info_t *, u_32_t *);
    721  1.2  christos extern	frentry_t *ipf_nat_ipfout(fr_info_t *, u_32_t *);
    722  1.2  christos extern	int	ipf_nat_in(fr_info_t *, nat_t *, int, u_32_t);
    723  1.2  christos extern	int	ipf_nat_out(fr_info_t *, nat_t *, int, u_32_t);
    724  1.2  christos extern	int	ipf_nat_rehash(ipf_main_softc_t *, ipftuneable_t *,
    725  1.2  christos 				    ipftuneval_t *);
    726  1.2  christos extern	int	ipf_nat_rehash_rules(ipf_main_softc_t *, ipftuneable_t *,
    727  1.2  christos 					  ipftuneval_t *);
    728  1.2  christos extern	int	ipf_nat_settimeout(struct ipf_main_softc_s *,
    729  1.2  christos 					ipftuneable_t *, ipftuneval_t *);
    730  1.2  christos extern	void	ipf_nat_sync(ipf_main_softc_t *, void *);
    731  1.2  christos 
    732  1.2  christos extern	nat_t	*ipf_nat_clone(fr_info_t *, nat_t *);
    733  1.2  christos extern	void	ipf_nat_delmap(ipf_nat_softc_t *, ipnat_t *);
    734  1.2  christos extern	void	ipf_nat_delrdr(ipf_nat_softc_t *, ipnat_t *);
    735  1.2  christos extern	int	ipf_nat_wildok(nat_t *, int, int, int, int);
    736  1.2  christos extern	void	ipf_nat_setlock(void *, int);
    737  1.2  christos extern	void	ipf_nat_load(void);
    738  1.2  christos extern	void	*ipf_nat_soft_create(ipf_main_softc_t *);
    739  1.2  christos extern	int	ipf_nat_soft_init(ipf_main_softc_t *, void *);
    740  1.2  christos extern	void	ipf_nat_soft_destroy(ipf_main_softc_t *, void *);
    741  1.2  christos extern	int	ipf_nat_soft_fini(ipf_main_softc_t *, void *);
    742  1.2  christos extern	int	ipf_nat_main_load(void);
    743  1.2  christos extern	int	ipf_nat_main_unload(void);
    744  1.2  christos extern	ipftq_t	*ipf_nat_add_tq(ipf_main_softc_t *, int);
    745  1.2  christos extern	void	ipf_nat_uncreate(fr_info_t *);
    746  1.1  christos 
    747  1.1  christos #ifdef USE_INET6
    748  1.2  christos extern	nat_t	*ipf_nat6_add(fr_info_t *, ipnat_t *, nat_t **,
    749  1.2  christos 				   u_int, int);
    750  1.2  christos extern	void	ipf_nat6_addrdr(ipf_nat_softc_t *, ipnat_t *);
    751  1.2  christos extern	void	ipf_nat6_addmap(ipf_nat_softc_t *, ipnat_t *);
    752  1.2  christos extern	int	ipf_nat6_checkout(fr_info_t *, u_32_t *);
    753  1.2  christos extern	int	ipf_nat6_checkin(fr_info_t *, u_32_t *);
    754  1.3   darrenr extern	void	ipf_nat6_delmap(ipf_nat_softc_t *, ipnat_t *);
    755  1.3   darrenr extern	void	ipf_nat6_delrdr(ipf_nat_softc_t *, ipnat_t *);
    756  1.2  christos extern	int	ipf_nat6_finalise(fr_info_t *, nat_t *);
    757  1.2  christos extern	nat_t	*ipf_nat6_icmperror(fr_info_t *, u_int *, int);
    758  1.2  christos extern	nat_t	*ipf_nat6_icmperrorlookup(fr_info_t *, int);
    759  1.2  christos extern	nat_t	*ipf_nat6_inlookup(fr_info_t *, u_int, u_int,
    760  1.2  christos 					struct in6_addr *, struct in6_addr *);
    761  1.2  christos extern	u_32_t	ipf_nat6_ip6subtract(i6addr_t *, i6addr_t *);
    762  1.2  christos extern	frentry_t *ipf_nat6_ipfin(fr_info_t *, u_32_t *);
    763  1.2  christos extern	frentry_t *ipf_nat6_ipfout(fr_info_t *, u_32_t *);
    764  1.2  christos extern	nat_t	*ipf_nat6_lookupredir(natlookup_t *);
    765  1.2  christos extern	int	ipf_nat6_newmap(fr_info_t *, nat_t *, natinfo_t *);
    766  1.2  christos extern	int	ipf_nat6_newrdr(fr_info_t *, nat_t *, natinfo_t *);
    767  1.2  christos extern	nat_t	*ipf_nat6_outlookup(fr_info_t *, u_int, u_int,
    768  1.2  christos 					 struct in6_addr *, struct in6_addr *);
    769  1.2  christos extern	int	ipf_nat6_newrewrite(fr_info_t *, nat_t *, natinfo_t *);
    770  1.2  christos extern	int	ipf_nat6_newdivert(fr_info_t *, nat_t *, natinfo_t *);
    771  1.2  christos extern	int	ipf_nat6_ruleaddrinit(ipf_main_softc_t *, ipf_nat_softc_t *, ipnat_t *);
    772  1.1  christos 
    773  1.1  christos #endif
    774  1.1  christos 
    775  1.1  christos 
    776  1.1  christos #endif /* __IP_NAT_H__ */
    777