1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 #ifndef _IP_FW_H
51 #define _IP_FW_H
52
53 struct ip_fw
54 {
55 struct ip_fw *fw_next;
56 struct in_addr fw_src, fw_dst;
57 struct in_addr fw_smsk, fw_dmsk;
58 struct in_addr fw_via;
59 struct device *fw_viadev;
60 unsigned short fw_flg;
61 unsigned short fw_nsp, fw_ndp;
62
63
64
65 #define IP_FW_MAX_PORTS 10
66 unsigned short fw_pts[IP_FW_MAX_PORTS];
67 unsigned long fw_pcnt,fw_bcnt;
68 unsigned char fw_tosand, fw_tosxor;
69 char fw_vianame[IFNAMSIZ];
70 };
71
72
73
74
75
76 #define IP_FW_F_ALL 0x000
77 #define IP_FW_F_TCP 0x001
78 #define IP_FW_F_UDP 0x002
79 #define IP_FW_F_ICMP 0x003
80 #define IP_FW_F_KIND 0x003
81 #define IP_FW_F_ACCEPT 0x004
82
83
84 #define IP_FW_F_SRNG 0x008
85
86
87
88 #define IP_FW_F_DRNG 0x010
89
90
91
92
93 #define IP_FW_F_PRN 0x020
94 #define IP_FW_F_BIDIR 0x040
95 #define IP_FW_F_TCPSYN 0x080
96 #define IP_FW_F_ICMPRPL 0x100
97 #define IP_FW_F_MASQ 0x200
98 #define IP_FW_F_TCPACK 0x400
99
100 #define IP_FW_F_MASK 0x7FF
101
102
103
104
105
106
107
108 #define IP_FW_BASE_CTL 64
109
110 #define IP_FW_COMMAND 0x00FF
111 #define IP_FW_TYPE 0x0300
112 #define IP_FW_SHIFT 8
113
114 #define IP_FW_FWD 0
115 #define IP_FW_IN 1
116 #define IP_FW_OUT 2
117 #define IP_FW_ACCT 3
118 #define IP_FW_CHAINS 4
119
120 #define IP_FW_INSERT (IP_FW_BASE_CTL)
121 #define IP_FW_APPEND (IP_FW_BASE_CTL+1)
122 #define IP_FW_DELETE (IP_FW_BASE_CTL+2)
123 #define IP_FW_FLUSH (IP_FW_BASE_CTL+3)
124 #define IP_FW_ZERO (IP_FW_BASE_CTL+4)
125 #define IP_FW_POLICY (IP_FW_BASE_CTL+5)
126 #define IP_FW_CHECK (IP_FW_BASE_CTL+6)
127
128 #define IP_FW_INSERT_FWD (IP_FW_INSERT | (IP_FW_FWD << IP_FW_SHIFT))
129 #define IP_FW_APPEND_FWD (IP_FW_APPEND | (IP_FW_FWD << IP_FW_SHIFT))
130 #define IP_FW_DELETE_FWD (IP_FW_DELETE | (IP_FW_FWD << IP_FW_SHIFT))
131 #define IP_FW_FLUSH_FWD (IP_FW_FLUSH | (IP_FW_FWD << IP_FW_SHIFT))
132 #define IP_FW_ZERO_FWD (IP_FW_ZERO | (IP_FW_FWD << IP_FW_SHIFT))
133 #define IP_FW_POLICY_FWD (IP_FW_POLICY | (IP_FW_FWD << IP_FW_SHIFT))
134 #define IP_FW_CHECK_FWD (IP_FW_CHECK | (IP_FW_FWD << IP_FW_SHIFT))
135
136 #define IP_FW_INSERT_IN (IP_FW_INSERT | (IP_FW_IN << IP_FW_SHIFT))
137 #define IP_FW_APPEND_IN (IP_FW_APPEND | (IP_FW_IN << IP_FW_SHIFT))
138 #define IP_FW_DELETE_IN (IP_FW_DELETE | (IP_FW_IN << IP_FW_SHIFT))
139 #define IP_FW_FLUSH_IN (IP_FW_FLUSH | (IP_FW_IN << IP_FW_SHIFT))
140 #define IP_FW_ZERO_IN (IP_FW_ZERO | (IP_FW_IN << IP_FW_SHIFT))
141 #define IP_FW_POLICY_IN (IP_FW_POLICY | (IP_FW_IN << IP_FW_SHIFT))
142 #define IP_FW_CHECK_IN (IP_FW_CHECK | (IP_FW_IN << IP_FW_SHIFT))
143
144 #define IP_FW_INSERT_OUT (IP_FW_INSERT | (IP_FW_OUT << IP_FW_SHIFT))
145 #define IP_FW_APPEND_OUT (IP_FW_APPEND | (IP_FW_OUT << IP_FW_SHIFT))
146 #define IP_FW_DELETE_OUT (IP_FW_DELETE | (IP_FW_OUT << IP_FW_SHIFT))
147 #define IP_FW_FLUSH_OUT (IP_FW_FLUSH | (IP_FW_OUT << IP_FW_SHIFT))
148 #define IP_FW_ZERO_OUT (IP_FW_ZERO | (IP_FW_OUT << IP_FW_SHIFT))
149 #define IP_FW_POLICY_OUT (IP_FW_POLICY | (IP_FW_OUT << IP_FW_SHIFT))
150 #define IP_FW_CHECK_OUT (IP_FW_CHECK | (IP_FW_OUT << IP_FW_SHIFT))
151
152 #define IP_ACCT_INSERT (IP_FW_INSERT | (IP_FW_ACCT << IP_FW_SHIFT))
153 #define IP_ACCT_APPEND (IP_FW_APPEND | (IP_FW_ACCT << IP_FW_SHIFT))
154 #define IP_ACCT_DELETE (IP_FW_DELETE | (IP_FW_ACCT << IP_FW_SHIFT))
155 #define IP_ACCT_FLUSH (IP_FW_FLUSH | (IP_FW_ACCT << IP_FW_SHIFT))
156 #define IP_ACCT_ZERO (IP_FW_ZERO | (IP_FW_ACCT << IP_FW_SHIFT))
157
158 struct ip_fwpkt
159 {
160 struct iphdr fwp_iph;
161 union {
162 struct tcphdr fwp_tcph;
163 struct udphdr fwp_udph;
164 struct icmphdr fwp_icmph;
165 } fwp_protoh;
166 struct in_addr fwp_via;
167 char fwp_vianame[IFNAMSIZ];
168 };
169
170
171
172
173
174 #ifdef __KERNEL__
175
176 #include <linux/config.h>
177
178 #ifdef CONFIG_IP_MASQUERADE
179 struct ip_masq {
180 struct ip_masq *next;
181 struct timer_list timer;
182 __u16 protocol;
183 __u32 src, dst;
184 __u16 sport,dport;
185 __u16 mport;
186 __u32 init_seq;
187 short delta;
188 short previous_delta;
189 char sawfin;
190 };
191 extern struct ip_masq *ip_msq_hosts;
192 extern void ip_fw_masquerade(struct sk_buff **, struct device *);
193 extern int ip_fw_demasquerade(struct sk_buff *);
194 #endif
195 #ifdef CONFIG_IP_FIREWALL
196 extern struct ip_fw *ip_fw_in_chain;
197 extern struct ip_fw *ip_fw_out_chain;
198 extern struct ip_fw *ip_fw_fwd_chain;
199 extern int ip_fw_in_policy;
200 extern int ip_fw_out_policy;
201 extern int ip_fw_fwd_policy;
202 extern int ip_fw_ctl(int, void *, int);
203 #endif
204 #ifdef CONFIG_IP_ACCT
205 extern struct ip_fw *ip_acct_chain;
206 extern void ip_acct_cnt(struct iphdr *, struct device *, struct ip_fw *);
207 extern int ip_acct_ctl(int, void *, int);
208 #endif
209
210
211 extern int ip_fw_chk(struct iphdr *, struct device *rif,struct ip_fw *, int, int);
212 extern void ip_fw_init(void);
213 #endif
214
215 #ifdef CONFIG_IP_MASQUERADE
216
217 #undef DEBUG_MASQ
218
219 #define MASQUERADE_EXPIRE_TCP 15*60*HZ
220 #define MASQUERADE_EXPIRE_TCP_FIN 2*60*HZ
221 #define MASQUERADE_EXPIRE_UDP 5*60*HZ
222
223
224
225
226
227 #define PORT_MASQ_BEGIN 60000
228 #define PORT_MASQ_END (PORT_MASQ_BEGIN+4096)
229 #define FTP_DPORT_TBD (PORT_MASQ_END+1)
230 #endif
231
232 #endif