1275970Scy/*	$NetBSD: ip_sync.h,v 1.2 2012/03/23 20:39:50 christos Exp $	*/
2275970Scy
3275970Scy/*
4275970Scy * Copyright (C) 2012 by Darren Reed.
5275970Scy *
6275970Scy * See the IPFILTER.LICENCE file for details on licencing.
7275970Scy *
8275970Scy * @(#)ip_fil.h	1.35 6/5/96
9275970Scy * Id: ip_sync.h,v 2.19.2.1 2012/01/26 05:29:13 darrenr Exp
10275970Scy */
11275970Scy
12275970Scy#ifndef __IP_SYNC_H__
13275970Scy#define __IP_SYNC_H__
14275970Scy
15275970Scytypedef	struct	synchdr	{
16275970Scy	u_32_t		sm_magic;	/* magic */
17275970Scy	u_char		sm_v;		/* version: 4,6 */
18275970Scy	u_char		sm_p;		/* protocol */
19275970Scy	u_char		sm_cmd;		/* command */
20275970Scy	u_char		sm_table;	/* NAT, STATE, etc */
21275970Scy	u_int		sm_num;		/* table entry number */
22275970Scy	int		sm_rev;		/* forward/reverse */
23275970Scy	int		sm_len;		/* length of the data section */
24275970Scy	struct	synclist	*sm_sl;		/* back pointer to parent */
25275970Scy} synchdr_t;
26275970Scy
27275970Scy
28275970Scy#define SYNHDRMAGIC 0x0FF51DE5
29275970Scy
30275970Scy/*
31275970Scy * Commands
32275970Scy * No delete required as expirey will take care of that!
33275970Scy */
34275970Scy#define	SMC_CREATE	0	/* pass ipstate_t after synchdr_t */
35275970Scy#define	SMC_UPDATE	1
36275970Scy#define	SMC_MAXCMD	1
37275970Scy
38275970Scy/*
39275970Scy * Tables
40275970Scy */
41275970Scy#define	SMC_RLOG	-2	/* Only used with SIOCIPFFL */
42275970Scy#define	SMC_NAT		0
43275970Scy#define	SMC_STATE	1
44275970Scy#define	SMC_MAXTBL	1
45275970Scy
46275970Scy
47275970Scy/*
48275970Scy * Only TCP requires "more" information than just a reference to the entry
49275970Scy * for which an update is being made.
50275970Scy */
51275970Scytypedef	struct	synctcp_update	{
52275970Scy	u_long		stu_age;
53275970Scy	tcpdata_t	stu_data[2];
54275970Scy	int		stu_state[2];
55275970Scy} synctcp_update_t;
56275970Scy
57275970Scy
58275970Scytypedef	struct	synclist	{
59275970Scy	struct	synclist	*sl_next;
60275970Scy	struct	synclist	**sl_pnext;
61275970Scy	int			sl_idx;		/* update index */
62275970Scy	struct	synchdr		sl_hdr;
63275970Scy	union	{
64275970Scy		struct	ipstate	*slu_ips;
65275970Scy		struct	nat	*slu_ipn;
66275970Scy		void		*slu_ptr;
67275970Scy	} sl_un;
68275970Scy} synclist_t;
69275970Scy
70275970Scy#define	sl_ptr	sl_un.slu_ptr
71275970Scy#define	sl_ips	sl_un.slu_ips
72275970Scy#define	sl_ipn	sl_un.slu_ipn
73275970Scy#define	sl_magic sl_hdr.sm_magic
74275970Scy#define	sl_v	sl_hdr.sm_v
75275970Scy#define	sl_p	sl_hdr.sm_p
76275970Scy#define	sl_cmd	sl_hdr.sm_cmd
77275970Scy#define	sl_rev	sl_hdr.sm_rev
78275970Scy#define	sl_table	sl_hdr.sm_table
79275970Scy#define	sl_num	sl_hdr.sm_num
80275970Scy#define	sl_len	sl_hdr.sm_len
81275970Scy
82275970Scy/*
83275970Scy * NOTE: SYNCLOG_SZ is defined *low*.  It should be the next power of two
84275970Scy * up for whatever number of packets per second you expect to see.  Be
85275970Scy * warned: this index's a table of large elements (upto 272 bytes in size
86275970Scy * each), and thus a size of 8192, for example, results in a 2MB table.
87275970Scy * The lesson here is not to use small machines for running fast firewalls
88275970Scy * (100BaseT) in sync, where you might have upwards of 10k pps.
89275970Scy */
90275970Scy#define	SYNCLOG_SZ	256
91275970Scy
92275970Scytypedef	struct	synclogent	{
93275970Scy	struct	synchdr	sle_hdr;
94275970Scy	union	{
95275970Scy		struct	ipstate	sleu_ips;
96275970Scy		struct	nat	sleu_ipn;
97275970Scy	} sle_un;
98275970Scy} synclogent_t;
99275970Scy
100275970Scytypedef	struct	syncupdent	{		/* 28 or 32 bytes */
101275970Scy	struct	synchdr	sup_hdr;
102275970Scy	struct	synctcp_update	sup_tcp;
103275970Scy} syncupdent_t;
104275970Scy
105275970Scyextern	void *ipf_sync_create(ipf_main_softc_t *);
106275970Scyextern	int ipf_sync_soft_init(ipf_main_softc_t *, void *);
107275970Scyextern	int ipf_sync_soft_fini(ipf_main_softc_t *, void *);
108275970Scyextern	int ipf_sync_canread(void *);
109275970Scyextern	int ipf_sync_canwrite(void *);
110275970Scyextern	void ipf_sync_del_nat(void *, synclist_t *);
111275970Scyextern	void ipf_sync_del_state(void *, synclist_t *);
112275970Scyextern	int ipf_sync_init(void);
113275970Scyextern	int ipf_sync_ioctl(ipf_main_softc_t *, void *, ioctlcmd_t, int, int, void *);
114275970Scyextern	synclist_t *ipf_sync_new(ipf_main_softc_t *, int, fr_info_t *, void *);
115275970Scyextern	int ipf_sync_read(ipf_main_softc_t *, struct uio *uio);
116275970Scyextern	int ipf_sync_write(ipf_main_softc_t *, struct uio *uio);
117275970Scyextern	int ipf_sync_main_unload(void);
118extern	void ipf_sync_update(ipf_main_softc_t *, int, fr_info_t *, synclist_t *);
119extern	void ipf_sync_expire(ipf_main_softc_t *);
120extern	void	ipf_sync_soft_destroy(ipf_main_softc_t *, void *);
121extern	void	*ipf_sync_soft_create(ipf_main_softc_t *);
122
123#endif /* __IP_SYNC_H__ */
124