NetBSD/sys/netinet/ip_state.h

259 lines
7.2 KiB
C
Raw Normal View History

2004-07-23 09:39:03 +04:00
/* $NetBSD: ip_state.h,v 1.25 2004/07/23 05:39:04 martti Exp $ */
/*
2002-01-24 11:21:30 +03:00
* Copyright (C) 1995-2001 by Darren Reed.
*
2002-01-24 11:21:30 +03:00
* See the IPFILTER.LICENCE file for details on licencing.
*
* @(#)ip_state.h 1.3 1/12/96 (C) 1995 Darren Reed
2004-07-23 09:39:03 +04:00
* Id: ip_state.h,v 2.68.2.1 2004/06/30 11:26:12 darrenr Exp
*/
#ifndef _NETINET_IP_STATE_H_
#define _NETINET_IP_STATE_H_
2000-05-03 15:12:03 +04:00
#if defined(__STDC__) || defined(__GNUC__)
2004-03-28 13:00:53 +04:00
# define SIOCDELST _IOW('r', 61, struct ipfobj)
2000-05-03 15:12:03 +04:00
#else
2004-03-28 13:00:53 +04:00
# define SIOCDELST _IOW(r, 61, struct ipfobj)
2000-05-03 15:12:03 +04:00
#endif
2004-03-28 13:00:53 +04:00
struct ipscan;
2002-01-24 11:21:30 +03:00
#ifndef IPSTATE_SIZE
# define IPSTATE_SIZE 5737
#endif
#ifndef IPSTATE_MAX
# define IPSTATE_MAX 4013 /* Maximum number of states held */
#endif
1997-05-25 16:40:11 +04:00
#define PAIRS(s1,d1,s2,d2) ((((s1) == (s2)) && ((d1) == (d2))) ||\
(((s1) == (d2)) && ((d1) == (s2))))
#define IPPAIR(s1,d1,s2,d2) PAIRS((s1).s_addr, (d1).s_addr, \
(s2).s_addr, (d2).s_addr)
typedef struct ipstate {
2004-03-28 13:00:53 +04:00
ipfmutex_t is_lock;
struct ipstate *is_next;
2000-05-03 15:12:03 +04:00
struct ipstate **is_pnext;
struct ipstate *is_hnext;
struct ipstate **is_phnext;
2002-01-24 11:21:30 +03:00
struct ipstate **is_me;
2004-03-28 13:00:53 +04:00
void *is_ifp[4];
void *is_sync;
struct nat *is_nat[2];
2002-05-02 21:11:37 +04:00
frentry_t *is_rule;
2004-03-28 13:00:53 +04:00
struct ipftq *is_tqehead[2];
struct ipscan *is_isc;
U_QUAD_T is_pkts[4];
U_QUAD_T is_bytes[4];
U_QUAD_T is_icmppkts[4];
struct ipftqent is_sti;
u_int is_frage[2];
int is_ref; /* reference count */
int is_isninc[2];
u_short is_sumd[2];
i6addr_t is_src;
i6addr_t is_dst;
2002-05-02 21:11:37 +04:00
u_int is_pass;
1999-12-12 14:11:15 +03:00
u_char is_p; /* Protocol */
2004-03-28 13:00:53 +04:00
u_char is_v;
u_32_t is_hv;
u_32_t is_tag;
1999-12-12 14:11:15 +03:00
u_32_t is_opt; /* packet options set */
u_32_t is_optmsk; /* " " mask */
u_short is_sec; /* security options set */
u_short is_secmsk; /* " " mask */
u_short is_auth; /* authentication options set */
u_short is_authmsk; /* " " mask */
union {
2004-03-28 13:00:53 +04:00
icmpinfo_t is_ics;
tcpinfo_t is_ts;
udpinfo_t is_us;
greinfo_t is_ug;
} is_ps;
2004-03-28 13:00:53 +04:00
u_32_t is_flags;
int is_flx[2][2];
u_32_t is_rulen; /* rule number when created */
u_32_t is_s0[2];
u_short is_smsk[2];
char is_group[FR_GROUPLEN];
char is_sbuf[2][16];
char is_ifname[4][LIFNAMSIZ];
} ipstate_t;
2004-03-28 13:00:53 +04:00
#define is_die is_sti.tqe_die
#define is_state is_sti.tqe_state
#define is_touched is_sti.tqe_touched
2000-05-03 15:12:03 +04:00
#define is_saddr is_src.in4.s_addr
#define is_daddr is_dst.in4.s_addr
#define is_icmp is_ps.is_ics
2004-03-28 13:00:53 +04:00
#define is_type is_icmp.ici_type
#define is_code is_icmp.ici_code
2000-05-03 15:12:03 +04:00
#define is_tcp is_ps.is_ts
#define is_udp is_ps.is_us
#define is_send is_tcp.ts_data[0].td_end
#define is_dend is_tcp.ts_data[1].td_end
1999-12-12 14:11:15 +03:00
#define is_maxswin is_tcp.ts_data[0].td_maxwin
#define is_maxdwin is_tcp.ts_data[1].td_maxwin
#define is_maxsend is_tcp.ts_data[0].td_maxend
#define is_maxdend is_tcp.ts_data[1].td_maxend
2004-03-28 13:00:53 +04:00
#define is_swinscale is_tcp.ts_data[0].td_winscale
#define is_dwinscale is_tcp.ts_data[1].td_winscale
#define is_swinflags is_tcp.ts_data[0].td_winflags
#define is_dwinflags is_tcp.ts_data[1].td_winflags
#define is_sport is_tcp.ts_sport
#define is_dport is_tcp.ts_dport
2000-05-03 15:12:03 +04:00
#define is_ifpin is_ifp[0]
2002-01-24 11:21:30 +03:00
#define is_ifpout is_ifp[2]
2004-03-28 13:00:53 +04:00
#define is_gre is_ps.is_ug
#define IS_WSPORT SI_W_SPORT /* 0x00100 */
#define IS_WDPORT SI_W_DPORT /* 0x00200 */
#define IS_WSADDR SI_W_SADDR /* 0x00400 */
#define IS_WDADDR SI_W_DADDR /* 0x00800 */
#define IS_NEWFR SI_NEWFR /* 0x01000 */
#define IS_CLONE SI_CLONE /* 0x02000 */
#define IS_CLONED SI_CLONED /* 0x04000 */
#define IS_TCPFSM 0x10000
#define IS_STRICT 0x20000
#define IS_ISNSYN 0x40000
#define IS_ISNACK 0x80000
/*
* IS_SC flags are for scan-operations that need to be recognised in state.
*/
#define IS_SC_CLIENT 0x10000000
#define IS_SC_SERVER 0x20000000
#define IS_SC_MATCHC 0x40000000
#define IS_SC_MATCHS 0x80000000
#define IS_SC_MATCHALL (IS_SC_MATCHC|IS_SC_MATCHC)
#define IS_SC_ALL (IS_SC_MATCHC|IS_SC_MATCHC|IS_SC_CLIENT|IS_SC_SERVER)
/*
* Flags that can be passed into fr_addstate
*/
#define IS_INHERITED 0x0fffff00
#define TH_OPENING (TH_SYN|TH_ACK)
1999-12-12 14:11:15 +03:00
/*
* is_flags:
* Bits 0 - 3 are use as a mask with the current packet's bits to check for
* whether it is short, tcp/udp, a fragment or the presence of IP options.
* Bits 4 - 7 are set from the initial packet and contain what the packet
* anded with bits 0-3 must match.
* Bits 8,9 are used to indicate wildcard source/destination port matching.
2004-03-28 13:00:53 +04:00
* Bits 10,11 are reserved for other wildcard flag compatibility.
* Bits 12,13 are for scaning.
1999-12-12 14:11:15 +03:00
*/
2000-05-03 15:12:03 +04:00
typedef struct ipstate_save {
void *ips_next;
struct ipstate ips_is;
struct frentry ips_fr;
} ipstate_save_t;
#define ips_rule ips_is.is_rule
1997-05-25 16:40:11 +04:00
typedef struct ipslog {
2004-03-28 13:00:53 +04:00
U_QUAD_T isl_pkts[4];
U_QUAD_T isl_bytes[4];
i6addr_t isl_src;
i6addr_t isl_dst;
u_32_t isl_tag;
1997-05-25 16:40:11 +04:00
u_short isl_type;
union {
u_short isl_filler[2];
u_short isl_ports[2];
u_short isl_icmp;
} isl_ps;
2000-05-03 15:12:03 +04:00
u_char isl_v;
u_char isl_p;
u_char isl_flags;
u_char isl_state[2];
2002-09-19 12:08:14 +04:00
u_32_t isl_rulen;
2004-03-28 13:00:53 +04:00
char isl_group[FR_GROUPLEN];
1997-05-25 16:40:11 +04:00
} ipslog_t;
#define isl_sport isl_ps.isl_ports[0]
#define isl_dport isl_ps.isl_ports[1]
#define isl_itype isl_ps.isl_icmp
2004-03-28 13:00:53 +04:00
#define ISL_NEW 0
#define ISL_CLONE 1
#define ISL_EXPIRE 0xffff
#define ISL_FLUSH 0xfffe
#define ISL_REMOVE 0xfffd
#define ISL_INTERMEDIATE 0xfffc
#define ISL_KILLED 0xfffb
#define ISL_ORPHAN 0xfffa
1997-05-25 16:40:11 +04:00
typedef struct ips_stat {
u_long iss_hits;
u_long iss_miss;
u_long iss_max;
2004-03-28 13:00:53 +04:00
u_long iss_maxref;
u_long iss_tcp;
u_long iss_udp;
u_long iss_icmp;
u_long iss_nomem;
u_long iss_expire;
u_long iss_fin;
u_long iss_active;
1997-05-25 16:40:11 +04:00
u_long iss_logged;
u_long iss_logfail;
1999-12-12 14:11:15 +03:00
u_long iss_inuse;
2004-03-28 13:00:53 +04:00
u_long iss_wild;
u_long iss_killed;
u_long iss_ticks;
u_long iss_bucketfull;
int iss_statesize;
int iss_statemax;
ipstate_t **iss_table;
2000-05-03 15:12:03 +04:00
ipstate_t *iss_list;
2004-03-28 13:00:53 +04:00
u_long *iss_bucketlen;
} ips_stat_t;
1997-05-25 16:40:11 +04:00
1997-07-05 09:38:14 +04:00
extern u_long fr_tcpidletimeout;
extern u_long fr_tcpclosewait;
extern u_long fr_tcplastack;
extern u_long fr_tcptimeout;
extern u_long fr_tcpclosed;
2001-03-26 10:11:46 +04:00
extern u_long fr_tcphalfclosed;
1997-07-05 09:38:14 +04:00
extern u_long fr_udptimeout;
2002-01-24 11:21:30 +03:00
extern u_long fr_udpacktimeout;
1997-07-05 09:38:14 +04:00
extern u_long fr_icmptimeout;
2002-01-24 11:21:30 +03:00
extern u_long fr_icmpacktimeout;
2004-03-28 13:00:53 +04:00
extern int fr_statemax;
extern int fr_statesize;
2000-05-03 15:12:03 +04:00
extern int fr_state_lock;
2004-03-28 13:00:53 +04:00
extern int fr_state_maxbucket;
extern int fr_state_maxbucket_reset;
extern ipstate_t *ips_list;
extern ipftq_t *ips_utqe;
extern ipftq_t ips_tqtqb[IPF_TCP_NSTATES];
1999-12-12 14:11:15 +03:00
extern int fr_stateinit __P((void));
2004-03-28 13:00:53 +04:00
extern ipstate_t *fr_addstate __P((fr_info_t *, ipstate_t **, u_int));
extern frentry_t *fr_checkstate __P((struct fr_info *, u_32_t *));
extern ipstate_t *fr_stlookup __P((fr_info_t *, tcphdr_t *, ipftq_t **));
extern void fr_statesync __P((void *));
1997-07-05 09:38:14 +04:00
extern void fr_timeoutstate __P((void));
2004-03-28 13:00:53 +04:00
extern int fr_tcp_age __P((struct ipftqent *, struct fr_info *,
struct ipftq *, int));
extern int fr_tcpinwindow __P((struct fr_info *, struct tcpdata *,
2004-07-23 09:39:03 +04:00
struct tcpdata *, tcphdr_t *, int));
1997-07-05 09:38:14 +04:00
extern void fr_stateunload __P((void));
1999-12-12 14:11:15 +03:00
extern void ipstate_log __P((struct ipstate *, u_int));
2004-03-28 13:00:53 +04:00
extern int fr_state_ioctl __P((caddr_t, ioctlcmd_t, int));
extern void fr_stinsert __P((struct ipstate *, int));
extern void fr_sttab_init __P((struct ipftq *));
extern void fr_sttab_destroy __P((struct ipftq *));
extern void fr_updatestate __P((fr_info_t *, ipstate_t *, ipftq_t *));
extern void fr_statederef __P((fr_info_t *, ipstate_t **));
extern void fr_setstatequeue __P((ipstate_t *, int));
#endif /* _NETINET_IP_STATE_H_ */