1999-12-12 14:11:15 +03:00
|
|
|
/* $NetBSD: ip_nat.h,v 1.16 1999/12/12 11:11:17 veego Exp $ */
|
1997-01-06 00:32:18 +03:00
|
|
|
|
1997-01-05 16:47:59 +03:00
|
|
|
/*
|
1998-11-22 18:17:18 +03:00
|
|
|
* Copyright (C) 1995-1998 by Darren Reed.
|
1997-01-05 16:47:59 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that this notice is preserved and due credit is given
|
|
|
|
* to the original author and the contributors.
|
|
|
|
*
|
|
|
|
* @(#)ip_nat.h 1.5 2/4/96
|
1999-12-12 14:11:15 +03:00
|
|
|
* Id: ip_nat.h,v 2.1.2.2 1999/11/28 11:01:51 darrenr Exp
|
1997-01-05 16:47:59 +03:00
|
|
|
*/
|
|
|
|
|
1998-02-10 04:26:19 +03:00
|
|
|
#ifndef _NETINET_IP_NAT_H_
|
|
|
|
#define _NETINET_IP_NAT_H_
|
1997-01-05 16:47:59 +03:00
|
|
|
|
|
|
|
#ifndef SOLARIS
|
|
|
|
#define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__STDC__) || defined(__GNUC__)
|
|
|
|
#define SIOCADNAT _IOW('r', 80, struct ipnat)
|
|
|
|
#define SIOCRMNAT _IOW('r', 81, struct ipnat)
|
|
|
|
#define SIOCGNATS _IOR('r', 82, struct natstat)
|
|
|
|
#define SIOCGNATL _IOWR('r', 83, struct natlookup)
|
|
|
|
#define SIOCGFRST _IOR('r', 84, struct ipfrstat)
|
|
|
|
#define SIOCGIPST _IOR('r', 85, struct ips_stat)
|
1997-03-29 03:54:55 +03:00
|
|
|
#define SIOCFLNAT _IOWR('r', 86, int)
|
|
|
|
#define SIOCCNATL _IOWR('r', 87, int)
|
1997-01-05 16:47:59 +03:00
|
|
|
#else
|
|
|
|
#define SIOCADNAT _IOW(r, 80, struct ipnat)
|
|
|
|
#define SIOCRMNAT _IOW(r, 81, struct ipnat)
|
|
|
|
#define SIOCGNATS _IOR(r, 82, struct natstat)
|
|
|
|
#define SIOCGNATL _IOWR(r, 83, struct natlookup)
|
|
|
|
#define SIOCGFRST _IOR(r, 84, struct ipfrstat)
|
|
|
|
#define SIOCGIPST _IOR(r, 85, struct ips_stat)
|
1997-03-29 03:54:55 +03:00
|
|
|
#define SIOCFLNAT _IOWR(r, 86, int)
|
|
|
|
#define SIOCCNATL _IOWR(r, 87, int)
|
1997-01-05 16:47:59 +03:00
|
|
|
#endif
|
|
|
|
|
1999-12-12 14:11:15 +03:00
|
|
|
#undef LARGE_NAT /* define this if you're setting up a system to NAT
|
|
|
|
* LARGE numbers of networks/hosts - i.e. in the
|
|
|
|
* hundreds or thousands. In such a case, you should
|
|
|
|
* also change the RDR_SIZE and NAT_SIZE below to more
|
|
|
|
* appropriate sizes. The figures below were used for
|
|
|
|
* a setup with 1000-2000 networks to NAT.
|
|
|
|
*/
|
|
|
|
#define NAT_SIZE 127
|
|
|
|
#define RDR_SIZE 127
|
|
|
|
#define NAT_TABLE_SZ 127
|
|
|
|
#ifdef LARGE_NAT
|
|
|
|
#undef NAT_SIZE
|
|
|
|
#undef RDR_SIZE
|
|
|
|
#undef NAT_TABLE_SZ
|
|
|
|
#define NAT_SIZE 2047
|
|
|
|
#define RDR_SIZE 2047
|
|
|
|
#define NAT_TABLE_SZ 16383
|
|
|
|
#endif
|
1997-07-05 09:38:14 +04:00
|
|
|
#ifndef APR_LABELLEN
|
|
|
|
#define APR_LABELLEN 16
|
|
|
|
#endif
|
1999-12-12 14:11:15 +03:00
|
|
|
#define NAT_HW_CKSUM 0x80000000
|
|
|
|
|
|
|
|
#define DEF_NAT_AGE 1200 /* 10 minutes (600 seconds) */
|
1997-01-05 16:47:59 +03:00
|
|
|
|
|
|
|
typedef struct nat {
|
1997-03-29 03:54:55 +03:00
|
|
|
u_long nat_age;
|
|
|
|
int nat_flags;
|
1999-12-12 14:11:15 +03:00
|
|
|
u_32_t nat_sumd[2];
|
1998-05-30 00:24:36 +04:00
|
|
|
u_32_t nat_ipsumd;
|
1997-10-30 19:08:54 +03:00
|
|
|
void *nat_data;
|
1998-11-22 18:17:18 +03:00
|
|
|
void *nat_aps; /* proxy session */
|
1999-12-12 14:11:15 +03:00
|
|
|
frentry_t *nat_fr; /* filter rule ptr if appropriate */
|
1997-01-05 16:47:59 +03:00
|
|
|
struct in_addr nat_inip;
|
|
|
|
struct in_addr nat_outip;
|
|
|
|
struct in_addr nat_oip; /* other ip */
|
1997-05-25 16:40:11 +04:00
|
|
|
U_QUAD_T nat_pkts;
|
|
|
|
U_QUAD_T nat_bytes;
|
1998-11-22 18:17:18 +03:00
|
|
|
u_short nat_oport; /* other port */
|
1997-01-05 16:47:59 +03:00
|
|
|
u_short nat_inport;
|
|
|
|
u_short nat_outport;
|
|
|
|
u_short nat_use;
|
1999-12-12 14:11:15 +03:00
|
|
|
u_char nat_tcpstate[2];
|
|
|
|
u_char nat_p; /* protocol for NAT */
|
1998-11-22 18:17:18 +03:00
|
|
|
struct ipnat *nat_ptr; /* pointer back to the rule */
|
1997-03-29 03:54:55 +03:00
|
|
|
struct nat *nat_next;
|
|
|
|
struct nat *nat_hnext[2];
|
|
|
|
struct nat **nat_hstart[2];
|
1997-05-25 16:40:11 +04:00
|
|
|
void *nat_ifp;
|
|
|
|
int nat_dir;
|
1997-01-05 16:47:59 +03:00
|
|
|
} nat_t;
|
|
|
|
|
|
|
|
typedef struct ipnat {
|
|
|
|
struct ipnat *in_next;
|
1999-12-12 14:11:15 +03:00
|
|
|
struct ipnat *in_rnext;
|
|
|
|
struct ipnat *in_mnext;
|
|
|
|
void *in_ifp;
|
|
|
|
void *in_apr;
|
|
|
|
u_long in_space;
|
1997-03-29 03:54:55 +03:00
|
|
|
u_int in_use;
|
1999-12-12 14:11:15 +03:00
|
|
|
u_int in_hits;
|
1997-01-05 16:47:59 +03:00
|
|
|
struct in_addr in_nextip;
|
|
|
|
u_short in_pnext;
|
1999-12-12 14:11:15 +03:00
|
|
|
u_short in_ppip; /* ports per IP */
|
|
|
|
u_short in_ippip; /* IP #'s per IP# */
|
|
|
|
u_short in_flags; /* From here to in_dport must be reflected */
|
|
|
|
u_short in_port[2]; /* correctly in IPN_CMPSIZ */
|
1997-01-05 16:47:59 +03:00
|
|
|
struct in_addr in_in[2];
|
|
|
|
struct in_addr in_out[2];
|
1999-12-12 14:11:15 +03:00
|
|
|
struct in_addr in_src[2];
|
1997-01-05 16:47:59 +03:00
|
|
|
int in_redir; /* 0 if it's a mapping, 1 if it's a hard redir */
|
|
|
|
char in_ifname[IFNAMSIZ];
|
1997-05-25 16:40:11 +04:00
|
|
|
char in_plabel[APR_LABELLEN]; /* proxy label */
|
|
|
|
char in_p; /* protocol */
|
|
|
|
u_short in_dport;
|
1997-01-05 16:47:59 +03:00
|
|
|
} ipnat_t;
|
|
|
|
|
|
|
|
#define in_pmin in_port[0] /* Also holds static redir port */
|
|
|
|
#define in_pmax in_port[1]
|
|
|
|
#define in_nip in_nextip.s_addr
|
|
|
|
#define in_inip in_in[0].s_addr
|
|
|
|
#define in_inmsk in_in[1].s_addr
|
|
|
|
#define in_outip in_out[0].s_addr
|
|
|
|
#define in_outmsk in_out[1].s_addr
|
1999-12-12 14:11:15 +03:00
|
|
|
#define in_srcip in_src[0].s_addr
|
|
|
|
#define in_srcmsk in_src[1].s_addr
|
1997-01-05 16:47:59 +03:00
|
|
|
|
1997-05-25 16:40:11 +04:00
|
|
|
#define NAT_OUTBOUND 0
|
|
|
|
#define NAT_INBOUND 1
|
1997-01-05 16:47:59 +03:00
|
|
|
|
1997-05-25 16:40:11 +04:00
|
|
|
#define NAT_MAP 0x01
|
|
|
|
#define NAT_REDIRECT 0x02
|
|
|
|
#define NAT_BIMAP (NAT_MAP|NAT_REDIRECT)
|
1999-12-12 14:11:15 +03:00
|
|
|
#define NAT_MAPBLK 0x04
|
|
|
|
|
|
|
|
#define MAPBLK_MINPORT 1024 /* don't use reserved ports for src port */
|
|
|
|
#define USABLE_PORTS (65536 - MAPBLK_MINPORT)
|
1997-01-05 16:47:59 +03:00
|
|
|
|
1998-11-22 18:17:18 +03:00
|
|
|
#define IPN_CMPSIZ (sizeof(ipnat_t) - offsetof(ipnat_t, in_flags))
|
1997-01-05 16:47:59 +03:00
|
|
|
|
|
|
|
typedef struct natlookup {
|
|
|
|
struct in_addr nl_inip;
|
|
|
|
struct in_addr nl_outip;
|
1997-07-05 09:38:14 +04:00
|
|
|
struct in_addr nl_realip;
|
|
|
|
int nl_flags;
|
1997-01-05 16:47:59 +03:00
|
|
|
u_short nl_inport;
|
|
|
|
u_short nl_outport;
|
1997-07-05 09:38:14 +04:00
|
|
|
u_short nl_realport;
|
1997-01-05 16:47:59 +03:00
|
|
|
} natlookup_t;
|
|
|
|
|
|
|
|
typedef struct natstat {
|
|
|
|
u_long ns_mapped[2];
|
1997-05-25 16:40:11 +04:00
|
|
|
u_long ns_rules;
|
1997-01-05 16:47:59 +03:00
|
|
|
u_long ns_added;
|
|
|
|
u_long ns_expire;
|
|
|
|
u_long ns_inuse;
|
1997-05-25 16:40:11 +04:00
|
|
|
u_long ns_logged;
|
|
|
|
u_long ns_logfail;
|
1997-03-29 03:54:55 +03:00
|
|
|
nat_t **ns_table[2];
|
1997-01-05 16:47:59 +03:00
|
|
|
ipnat_t *ns_list;
|
1998-11-22 18:17:18 +03:00
|
|
|
void *ns_apslist;
|
1999-12-12 14:11:15 +03:00
|
|
|
u_int ns_nattab_sz;
|
|
|
|
u_int ns_rultab_sz;
|
|
|
|
u_int ns_rdrtab_sz;
|
|
|
|
nat_t *ns_instances;
|
1997-01-05 16:47:59 +03:00
|
|
|
} natstat_t;
|
|
|
|
|
1997-05-25 16:40:11 +04:00
|
|
|
#define IPN_ANY 0x00
|
|
|
|
#define IPN_TCP 0x01
|
|
|
|
#define IPN_UDP 0x02
|
1999-12-12 14:11:15 +03:00
|
|
|
#define IPN_TCPUDP (IPN_TCP|IPN_UDP)
|
1997-05-25 16:40:11 +04:00
|
|
|
#define IPN_DELETE 0x04
|
1997-10-30 19:08:54 +03:00
|
|
|
#define IPN_ICMPERR 0x08
|
1999-12-12 14:11:15 +03:00
|
|
|
#define IPN_RF (IPN_TCPUDP|IPN_DELETE|IPN_ICMPERR)
|
|
|
|
#define IPN_AUTOPORTMAP 0x10
|
|
|
|
#define IPN_RANGE 0x20
|
|
|
|
#define IPN_USERFLAGS (IPN_TCPUDP|IPN_AUTOPORTMAP|IPN_RANGE)
|
1997-05-25 16:40:11 +04:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct natlog {
|
|
|
|
struct in_addr nl_origip;
|
|
|
|
struct in_addr nl_outip;
|
|
|
|
struct in_addr nl_inip;
|
|
|
|
u_short nl_origport;
|
|
|
|
u_short nl_outport;
|
|
|
|
u_short nl_inport;
|
|
|
|
u_short nl_type;
|
|
|
|
int nl_rule;
|
|
|
|
U_QUAD_T nl_pkts;
|
|
|
|
U_QUAD_T nl_bytes;
|
|
|
|
} natlog_t;
|
|
|
|
|
|
|
|
|
|
|
|
#define NL_NEWMAP NAT_MAP
|
|
|
|
#define NL_NEWRDR NAT_REDIRECT
|
|
|
|
#define NL_EXPIRE 0xffff
|
|
|
|
|
1999-12-12 14:11:15 +03:00
|
|
|
#define NAT_HASH_FN(k,m) (((k) + ((k) >> 12)) % (m))
|
|
|
|
|
|
|
|
#define LONG_SUM(in) (((in) & 0xffff) + ((in) >> 16))
|
|
|
|
|
|
|
|
#define CALC_SUMD(s1, s2, sd) { \
|
|
|
|
(s1) = ((s1) & 0xffff) + ((s1) >> 16); \
|
|
|
|
(s2) = ((s2) & 0xffff) + ((s2) >> 16); \
|
|
|
|
/* Do it twice */ \
|
|
|
|
(s1) = ((s1) & 0xffff) + ((s1) >> 16); \
|
|
|
|
(s2) = ((s2) & 0xffff) + ((s2) >> 16); \
|
|
|
|
/* Because ~1 == -2, We really need ~1 == -1 */ \
|
|
|
|
if ((s1) > (s2)) (s2)--; \
|
|
|
|
(sd) = (s2) - (s1); \
|
|
|
|
(sd) = ((sd) & 0xffff) + ((sd) >> 16); }
|
|
|
|
|
1997-01-05 16:47:59 +03:00
|
|
|
|
1999-12-12 14:11:15 +03:00
|
|
|
extern u_int ipf_nattable_sz;
|
|
|
|
extern u_int ipf_natrules_sz;
|
|
|
|
extern u_int ipf_rdrrules_sz;
|
1997-09-21 22:00:54 +04:00
|
|
|
extern void ip_natsync __P((void *));
|
1997-07-05 09:38:14 +04:00
|
|
|
extern u_long fr_defnatage;
|
1997-10-30 19:08:54 +03:00
|
|
|
extern u_long fr_defnaticmpage;
|
1999-12-12 14:11:15 +03:00
|
|
|
extern nat_t **nat_table[2];
|
|
|
|
extern nat_t *nat_instances;
|
|
|
|
extern ipnat_t **nat_rules;
|
|
|
|
extern ipnat_t **rdr_rules;
|
|
|
|
extern natstat_t nat_stats;
|
1997-10-30 19:08:54 +03:00
|
|
|
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
1997-07-05 09:38:14 +04:00
|
|
|
extern int nat_ioctl __P((caddr_t, u_long, int));
|
1997-05-27 05:21:33 +04:00
|
|
|
#else
|
1997-07-05 09:38:14 +04:00
|
|
|
extern int nat_ioctl __P((caddr_t, int, int));
|
1997-05-27 05:21:33 +04:00
|
|
|
#endif
|
1999-12-12 14:11:15 +03:00
|
|
|
extern int nat_init __P((void));
|
|
|
|
extern nat_t *nat_new __P((ipnat_t *, ip_t *, fr_info_t *, u_int, int));
|
|
|
|
extern nat_t *nat_outlookup __P((void *, u_int, u_int, struct in_addr,
|
|
|
|
struct in_addr, u_32_t));
|
|
|
|
extern nat_t *nat_inlookup __P((void *, u_int, u_int, struct in_addr,
|
|
|
|
struct in_addr, u_32_t));
|
|
|
|
extern nat_t *nat_maplookup __P((void *, u_int, struct in_addr,
|
|
|
|
struct in_addr));
|
1997-07-05 09:38:14 +04:00
|
|
|
extern nat_t *nat_lookupredir __P((natlookup_t *));
|
1997-10-30 19:08:54 +03:00
|
|
|
extern nat_t *nat_icmpinlookup __P((ip_t *, fr_info_t *));
|
1999-12-12 14:11:15 +03:00
|
|
|
extern nat_t *nat_icmpin __P((ip_t *, fr_info_t *, u_int *));
|
1997-03-29 03:54:55 +03:00
|
|
|
|
1999-12-12 14:11:15 +03:00
|
|
|
extern int ip_natout __P((ip_t *, fr_info_t *));
|
|
|
|
extern int ip_natin __P((ip_t *, fr_info_t *));
|
1997-07-05 09:38:14 +04:00
|
|
|
extern void ip_natunload __P((void)), ip_natexpire __P((void));
|
1999-12-12 14:11:15 +03:00
|
|
|
extern void nat_log __P((struct nat *, u_int));
|
|
|
|
extern void fix_incksum __P((u_short *, u_32_t, int));
|
|
|
|
extern void fix_outcksum __P((u_short *, u_32_t, int));
|
1998-02-10 04:26:19 +03:00
|
|
|
|
|
|
|
#endif /* _NETINET_IP_NAT_H_ */
|