uncompress patches, requested by Kaloz
[openwrt/svn-archive/archive.git] / openwrt / package / linux / kernel-patches / 302-ebtables
1 diff -Nur linux-mips-cvs/include/linux/if_bridge.h linux-ebtables/include/linux/if_bridge.h
2 --- linux-mips-cvs/include/linux/if_bridge.h 2000-02-24 01:13:20.000000000 +0100
3 +++ linux-ebtables/include/linux/if_bridge.h 2005-02-07 05:52:50.000000000 +0100
4 @@ -102,7 +102,8 @@
5 struct net_bridge_port;
6
7 extern int (*br_ioctl_hook)(unsigned long arg);
8 -extern void (*br_handle_frame_hook)(struct sk_buff *skb);
9 +extern int (*br_handle_frame_hook)(struct sk_buff *skb);
10 +extern int (*br_should_route_hook)(struct sk_buff **pskb);
11
12 #endif
13
14 diff -Nur linux-mips-cvs/include/linux/netfilter.h linux-ebtables/include/linux/netfilter.h
15 --- linux-mips-cvs/include/linux/netfilter.h 2005-01-20 03:19:24.000000000 +0100
16 +++ linux-ebtables/include/linux/netfilter.h 2005-02-07 05:52:50.000000000 +0100
17 @@ -118,17 +118,23 @@
18 /* This is gross, but inline doesn't cut it for avoiding the function
19 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
20 #ifdef CONFIG_NETFILTER_DEBUG
21 -#define NF_HOOK nf_hook_slow
22 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
23 +nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN)
24 +#define NF_HOOK_THRESH nf_hook_slow
25 #else
26 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
27 (list_empty(&nf_hooks[(pf)][(hook)]) \
28 ? (okfn)(skb) \
29 - : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn)))
30 + : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
31 +#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
32 +(list_empty(&nf_hooks[(pf)][(hook)]) \
33 + ? (okfn)(skb) \
34 + : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), (thresh)))
35 #endif
36
37 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
38 struct net_device *indev, struct net_device *outdev,
39 - int (*okfn)(struct sk_buff *));
40 + int (*okfn)(struct sk_buff *), int thresh);
41
42 /* Call setsockopt() */
43 int nf_setsockopt(struct sock *sk, int pf, int optval, char *opt,
44 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_802_3.h linux-ebtables/include/linux/netfilter_bridge/ebt_802_3.h
45 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_802_3.h 1970-01-01 01:00:00.000000000 +0100
46 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_802_3.h 2005-02-07 05:52:50.000000000 +0100
47 @@ -0,0 +1,60 @@
48 +#ifndef __LINUX_BRIDGE_EBT_802_3_H
49 +#define __LINUX_BRIDGE_EBT_802_3_H
50 +
51 +#define EBT_802_3_SAP 0x01
52 +#define EBT_802_3_TYPE 0x02
53 +
54 +#define EBT_802_3_MATCH "802_3"
55 +
56 +/*
57 + * If frame has DSAP/SSAP value 0xaa you must check the SNAP type
58 + * to discover what kind of packet we're carrying.
59 + */
60 +#define CHECK_TYPE 0xaa
61 +
62 +/*
63 + * Control field may be one or two bytes. If the first byte has
64 + * the value 0x03 then the entire length is one byte, otherwise it is two.
65 + * One byte controls are used in Unnumbered Information frames.
66 + * Two byte controls are used in Numbered Information frames.
67 + */
68 +#define IS_UI 0x03
69 +
70 +#define EBT_802_3_MASK (EBT_802_3_SAP | EBT_802_3_TYPE | EBT_802_3)
71 +
72 +/* ui has one byte ctrl, ni has two */
73 +struct hdr_ui {
74 + uint8_t dsap;
75 + uint8_t ssap;
76 + uint8_t ctrl;
77 + uint8_t orig[3];
78 + uint16_t type;
79 +};
80 +
81 +struct hdr_ni {
82 + uint8_t dsap;
83 + uint8_t ssap;
84 + uint16_t ctrl;
85 + uint8_t orig[3];
86 + uint16_t type;
87 +};
88 +
89 +struct ebt_802_3_hdr {
90 + uint8_t daddr[6];
91 + uint8_t saddr[6];
92 + uint16_t len;
93 + union {
94 + struct hdr_ui ui;
95 + struct hdr_ni ni;
96 + } llc;
97 +};
98 +
99 +struct ebt_802_3_info
100 +{
101 + uint8_t sap;
102 + uint16_t type;
103 + uint8_t bitmask;
104 + uint8_t invflags;
105 +};
106 +
107 +#endif
108 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_among.h linux-ebtables/include/linux/netfilter_bridge/ebt_among.h
109 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_among.h 1970-01-01 01:00:00.000000000 +0100
110 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_among.h 2005-02-07 05:52:50.000000000 +0100
111 @@ -0,0 +1,65 @@
112 +#ifndef __LINUX_BRIDGE_EBT_AMONG_H
113 +#define __LINUX_BRIDGE_EBT_AMONG_H
114 +
115 +#define EBT_AMONG_DST 0x01
116 +#define EBT_AMONG_SRC 0x02
117 +
118 +/* Grzegorz Borowiak <grzes@gnu.univ.gda.pl> 2003
119 + *
120 + * Write-once-read-many hash table, used for checking if a given
121 + * MAC address belongs to a set or not and possibly for checking
122 + * if it is related with a given IPv4 address.
123 + *
124 + * The hash value of an address is its last byte.
125 + *
126 + * In real-world ethernet addresses, values of the last byte are
127 + * evenly distributed and there is no need to consider other bytes.
128 + * It would only slow the routines down.
129 + *
130 + * For MAC address comparison speedup reasons, we introduce a trick.
131 + * MAC address is mapped onto an array of two 32-bit integers.
132 + * This pair of integers is compared with MAC addresses in the
133 + * hash table, which are stored also in form of pairs of integers
134 + * (in `cmp' array). This is quick as it requires only two elementary
135 + * number comparisons in worst case. Further, we take advantage of
136 + * fact that entropy of 3 last bytes of address is larger than entropy
137 + * of 3 first bytes. So first we compare 4 last bytes of addresses and
138 + * if they are the same we compare 2 first.
139 + *
140 + * Yes, it is a memory overhead, but in 2003 AD, who cares?
141 + */
142 +
143 +struct ebt_mac_wormhash_tuple
144 +{
145 + uint32_t cmp[2];
146 + uint32_t ip;
147 +};
148 +
149 +struct ebt_mac_wormhash
150 +{
151 + int table[257];
152 + int poolsize;
153 + struct ebt_mac_wormhash_tuple pool[0];
154 +};
155 +
156 +#define ebt_mac_wormhash_size(x) ((x) ? sizeof(struct ebt_mac_wormhash) \
157 + + (x)->poolsize * sizeof(struct ebt_mac_wormhash_tuple) : 0)
158 +
159 +struct ebt_among_info
160 +{
161 + int wh_dst_ofs;
162 + int wh_src_ofs;
163 + int bitmask;
164 +};
165 +
166 +#define EBT_AMONG_DST_NEG 0x1
167 +#define EBT_AMONG_SRC_NEG 0x2
168 +
169 +#define ebt_among_wh_dst(x) ((x)->wh_dst_ofs ? \
170 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_dst_ofs) : NULL)
171 +#define ebt_among_wh_src(x) ((x)->wh_src_ofs ? \
172 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_src_ofs) : NULL)
173 +
174 +#define EBT_AMONG_MATCH "among"
175 +
176 +#endif
177 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_arp.h linux-ebtables/include/linux/netfilter_bridge/ebt_arp.h
178 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_arp.h 1970-01-01 01:00:00.000000000 +0100
179 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_arp.h 2005-02-07 05:52:50.000000000 +0100
180 @@ -0,0 +1,32 @@
181 +#ifndef __LINUX_BRIDGE_EBT_ARP_H
182 +#define __LINUX_BRIDGE_EBT_ARP_H
183 +
184 +#define EBT_ARP_OPCODE 0x01
185 +#define EBT_ARP_HTYPE 0x02
186 +#define EBT_ARP_PTYPE 0x04
187 +#define EBT_ARP_SRC_IP 0x08
188 +#define EBT_ARP_DST_IP 0x10
189 +#define EBT_ARP_SRC_MAC 0x20
190 +#define EBT_ARP_DST_MAC 0x40
191 +#define EBT_ARP_MASK (EBT_ARP_OPCODE | EBT_ARP_HTYPE | EBT_ARP_PTYPE | \
192 + EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)
193 +#define EBT_ARP_MATCH "arp"
194 +
195 +struct ebt_arp_info
196 +{
197 + uint16_t htype;
198 + uint16_t ptype;
199 + uint16_t opcode;
200 + uint32_t saddr;
201 + uint32_t smsk;
202 + uint32_t daddr;
203 + uint32_t dmsk;
204 + unsigned char smaddr[ETH_ALEN];
205 + unsigned char smmsk[ETH_ALEN];
206 + unsigned char dmaddr[ETH_ALEN];
207 + unsigned char dmmsk[ETH_ALEN];
208 + uint8_t bitmask;
209 + uint8_t invflags;
210 +};
211 +
212 +#endif
213 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_arpreply.h linux-ebtables/include/linux/netfilter_bridge/ebt_arpreply.h
214 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_arpreply.h 1970-01-01 01:00:00.000000000 +0100
215 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_arpreply.h 2005-02-07 05:52:50.000000000 +0100
216 @@ -0,0 +1,11 @@
217 +#ifndef __LINUX_BRIDGE_EBT_ARPREPLY_H
218 +#define __LINUX_BRIDGE_EBT_ARPREPLY_H
219 +
220 +struct ebt_arpreply_info
221 +{
222 + unsigned char mac[ETH_ALEN];
223 + int target;
224 +};
225 +#define EBT_ARPREPLY_TARGET "arpreply"
226 +
227 +#endif
228 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_ip.h linux-ebtables/include/linux/netfilter_bridge/ebt_ip.h
229 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_ip.h 1970-01-01 01:00:00.000000000 +0100
230 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_ip.h 2005-02-07 05:52:50.000000000 +0100
231 @@ -0,0 +1,43 @@
232 +/*
233 + * ebt_ip
234 + *
235 + * Authors:
236 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
237 + *
238 + * April, 2002
239 + *
240 + * Changes:
241 + * added ip-sport and ip-dport
242 + * Innominate Security Technologies AG <mhopf@innominate.com>
243 + * September, 2002
244 + */
245 +
246 +#ifndef __LINUX_BRIDGE_EBT_IP_H
247 +#define __LINUX_BRIDGE_EBT_IP_H
248 +
249 +#define EBT_IP_SOURCE 0x01
250 +#define EBT_IP_DEST 0x02
251 +#define EBT_IP_TOS 0x04
252 +#define EBT_IP_PROTO 0x08
253 +#define EBT_IP_SPORT 0x10
254 +#define EBT_IP_DPORT 0x20
255 +#define EBT_IP_MASK (EBT_IP_SOURCE | EBT_IP_DEST | EBT_IP_TOS | EBT_IP_PROTO |\
256 + EBT_IP_SPORT | EBT_IP_DPORT )
257 +#define EBT_IP_MATCH "ip"
258 +
259 +// the same values are used for the invflags
260 +struct ebt_ip_info
261 +{
262 + uint32_t saddr;
263 + uint32_t daddr;
264 + uint32_t smsk;
265 + uint32_t dmsk;
266 + uint8_t tos;
267 + uint8_t protocol;
268 + uint8_t bitmask;
269 + uint8_t invflags;
270 + uint16_t sport[2];
271 + uint16_t dport[2];
272 +};
273 +
274 +#endif
275 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_limit.h linux-ebtables/include/linux/netfilter_bridge/ebt_limit.h
276 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_limit.h 1970-01-01 01:00:00.000000000 +0100
277 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_limit.h 2005-02-07 05:52:50.000000000 +0100
278 @@ -0,0 +1,23 @@
279 +#ifndef __LINUX_BRIDGE_EBT_LIMIT_H
280 +#define __LINUX_BRIDGE_EBT_LIMIT_H
281 +
282 +#define EBT_LIMIT_MATCH "limit"
283 +
284 +/* timings are in milliseconds. */
285 +#define EBT_LIMIT_SCALE 10000
286 +
287 +/* 1/10,000 sec period => max of 10,000/sec. Min rate is then 429490
288 + seconds, or one every 59 hours. */
289 +
290 +struct ebt_limit_info
291 +{
292 + u_int32_t avg; /* Average secs between packets * scale */
293 + u_int32_t burst; /* Period multiplier for upper limit. */
294 +
295 + /* Used internally by the kernel */
296 + unsigned long prev;
297 + u_int32_t credit;
298 + u_int32_t credit_cap, cost;
299 +};
300 +
301 +#endif
302 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_log.h linux-ebtables/include/linux/netfilter_bridge/ebt_log.h
303 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_log.h 1970-01-01 01:00:00.000000000 +0100
304 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_log.h 2005-02-07 05:52:50.000000000 +0100
305 @@ -0,0 +1,17 @@
306 +#ifndef __LINUX_BRIDGE_EBT_LOG_H
307 +#define __LINUX_BRIDGE_EBT_LOG_H
308 +
309 +#define EBT_LOG_IP 0x01 // if the frame is made by ip, log the ip information
310 +#define EBT_LOG_ARP 0x02
311 +#define EBT_LOG_MASK (EBT_LOG_IP | EBT_LOG_ARP)
312 +#define EBT_LOG_PREFIX_SIZE 30
313 +#define EBT_LOG_WATCHER "log"
314 +
315 +struct ebt_log_info
316 +{
317 + uint8_t loglevel;
318 + uint8_t prefix[EBT_LOG_PREFIX_SIZE];
319 + uint32_t bitmask;
320 +};
321 +
322 +#endif
323 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_mark_m.h linux-ebtables/include/linux/netfilter_bridge/ebt_mark_m.h
324 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_mark_m.h 1970-01-01 01:00:00.000000000 +0100
325 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_mark_m.h 2005-02-07 05:52:50.000000000 +0100
326 @@ -0,0 +1,15 @@
327 +#ifndef __LINUX_BRIDGE_EBT_MARK_M_H
328 +#define __LINUX_BRIDGE_EBT_MARK_M_H
329 +
330 +#define EBT_MARK_AND 0x01
331 +#define EBT_MARK_OR 0x02
332 +#define EBT_MARK_MASK (EBT_MARK_AND | EBT_MARK_OR)
333 +struct ebt_mark_m_info
334 +{
335 + unsigned long mark, mask;
336 + uint8_t invert;
337 + uint8_t bitmask;
338 +};
339 +#define EBT_MARK_MATCH "mark_m"
340 +
341 +#endif
342 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_mark_t.h linux-ebtables/include/linux/netfilter_bridge/ebt_mark_t.h
343 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_mark_t.h 1970-01-01 01:00:00.000000000 +0100
344 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_mark_t.h 2005-02-07 05:52:50.000000000 +0100
345 @@ -0,0 +1,12 @@
346 +#ifndef __LINUX_BRIDGE_EBT_MARK_T_H
347 +#define __LINUX_BRIDGE_EBT_MARK_T_H
348 +
349 +struct ebt_mark_t_info
350 +{
351 + unsigned long mark;
352 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
353 + int target;
354 +};
355 +#define EBT_MARK_TARGET "mark"
356 +
357 +#endif
358 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_nat.h linux-ebtables/include/linux/netfilter_bridge/ebt_nat.h
359 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_nat.h 1970-01-01 01:00:00.000000000 +0100
360 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_nat.h 2005-02-07 05:52:50.000000000 +0100
361 @@ -0,0 +1,13 @@
362 +#ifndef __LINUX_BRIDGE_EBT_NAT_H
363 +#define __LINUX_BRIDGE_EBT_NAT_H
364 +
365 +struct ebt_nat_info
366 +{
367 + unsigned char mac[ETH_ALEN];
368 + // EBT_ACCEPT, EBT_DROP, EBT_CONTINUE or EBT_RETURN
369 + int target;
370 +};
371 +#define EBT_SNAT_TARGET "snat"
372 +#define EBT_DNAT_TARGET "dnat"
373 +
374 +#endif
375 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_pkttype.h linux-ebtables/include/linux/netfilter_bridge/ebt_pkttype.h
376 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_pkttype.h 1970-01-01 01:00:00.000000000 +0100
377 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_pkttype.h 2005-02-07 05:52:50.000000000 +0100
378 @@ -0,0 +1,11 @@
379 +#ifndef __LINUX_BRIDGE_EBT_PKTTYPE_H
380 +#define __LINUX_BRIDGE_EBT_PKTTYPE_H
381 +
382 +struct ebt_pkttype_info
383 +{
384 + uint8_t pkt_type;
385 + uint8_t invert;
386 +};
387 +#define EBT_PKTTYPE_MATCH "pkttype"
388 +
389 +#endif
390 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_redirect.h linux-ebtables/include/linux/netfilter_bridge/ebt_redirect.h
391 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_redirect.h 1970-01-01 01:00:00.000000000 +0100
392 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_redirect.h 2005-02-07 05:52:50.000000000 +0100
393 @@ -0,0 +1,11 @@
394 +#ifndef __LINUX_BRIDGE_EBT_REDIRECT_H
395 +#define __LINUX_BRIDGE_EBT_REDIRECT_H
396 +
397 +struct ebt_redirect_info
398 +{
399 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
400 + int target;
401 +};
402 +#define EBT_REDIRECT_TARGET "redirect"
403 +
404 +#endif
405 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_stp.h linux-ebtables/include/linux/netfilter_bridge/ebt_stp.h
406 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_stp.h 1970-01-01 01:00:00.000000000 +0100
407 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_stp.h 2005-02-07 05:52:50.000000000 +0100
408 @@ -0,0 +1,46 @@
409 +#ifndef __LINUX_BRIDGE_EBT_STP_H
410 +#define __LINUX_BRIDGE_EBT_STP_H
411 +
412 +#define EBT_STP_TYPE 0x0001
413 +
414 +#define EBT_STP_FLAGS 0x0002
415 +#define EBT_STP_ROOTPRIO 0x0004
416 +#define EBT_STP_ROOTADDR 0x0008
417 +#define EBT_STP_ROOTCOST 0x0010
418 +#define EBT_STP_SENDERPRIO 0x0020
419 +#define EBT_STP_SENDERADDR 0x0040
420 +#define EBT_STP_PORT 0x0080
421 +#define EBT_STP_MSGAGE 0x0100
422 +#define EBT_STP_MAXAGE 0x0200
423 +#define EBT_STP_HELLOTIME 0x0400
424 +#define EBT_STP_FWDD 0x0800
425 +
426 +#define EBT_STP_MASK 0x0fff
427 +#define EBT_STP_CONFIG_MASK 0x0ffe
428 +
429 +#define EBT_STP_MATCH "stp"
430 +
431 +struct ebt_stp_config_info
432 +{
433 + uint8_t flags;
434 + uint16_t root_priol, root_priou;
435 + char root_addr[6], root_addrmsk[6];
436 + uint32_t root_costl, root_costu;
437 + uint16_t sender_priol, sender_priou;
438 + char sender_addr[6], sender_addrmsk[6];
439 + uint16_t portl, portu;
440 + uint16_t msg_agel, msg_ageu;
441 + uint16_t max_agel, max_ageu;
442 + uint16_t hello_timel, hello_timeu;
443 + uint16_t forward_delayl, forward_delayu;
444 +};
445 +
446 +struct ebt_stp_info
447 +{
448 + uint8_t type;
449 + struct ebt_stp_config_info config;
450 + uint16_t bitmask;
451 + uint16_t invflags;
452 +};
453 +
454 +#endif
455 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_ulog.h linux-ebtables/include/linux/netfilter_bridge/ebt_ulog.h
456 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_ulog.h 1970-01-01 01:00:00.000000000 +0100
457 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_ulog.h 2005-02-07 05:52:50.000000000 +0100
458 @@ -0,0 +1,33 @@
459 +#ifndef _EBT_ULOG_H
460 +#define _EBT_ULOG_H
461 +
462 +#define EBT_ULOG_DEFAULT_NLGROUP 0
463 +#define EBT_ULOG_DEFAULT_QTHRESHOLD 1
464 +#define EBT_ULOG_MAXNLGROUPS 32 /* hardcoded netlink max */
465 +#define EBT_ULOG_PREFIX_LEN 32
466 +#define EBT_ULOG_MAX_QLEN 50
467 +#define EBT_ULOG_WATCHER "ulog"
468 +
469 +struct ebt_ulog_info {
470 + uint32_t nlgroup;
471 + unsigned int cprange;
472 + unsigned int qthreshold;
473 + char prefix[EBT_ULOG_PREFIX_LEN];
474 +};
475 +
476 +typedef struct ebt_ulog_packet_msg {
477 + char indev[IFNAMSIZ];
478 + char outdev[IFNAMSIZ];
479 + char physindev[IFNAMSIZ];
480 + char physoutdev[IFNAMSIZ];
481 + char prefix[EBT_ULOG_PREFIX_LEN];
482 + struct timeval stamp;
483 + unsigned long mark;
484 + unsigned int hook;
485 + size_t data_len;
486 + /* The complete packet, including Ethernet header and perhaps
487 + * the VLAN header is appended */
488 + unsigned char data[0] __attribute__ ((aligned (__alignof__(int))));
489 +} ebt_ulog_packet_msg_t;
490 +
491 +#endif /* _EBT_ULOG_H */
492 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_vlan.h linux-ebtables/include/linux/netfilter_bridge/ebt_vlan.h
493 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_vlan.h 1970-01-01 01:00:00.000000000 +0100
494 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_vlan.h 2005-02-07 05:52:50.000000000 +0100
495 @@ -0,0 +1,20 @@
496 +#ifndef __LINUX_BRIDGE_EBT_VLAN_H
497 +#define __LINUX_BRIDGE_EBT_VLAN_H
498 +
499 +#define EBT_VLAN_ID 0x01
500 +#define EBT_VLAN_PRIO 0x02
501 +#define EBT_VLAN_ENCAP 0x04
502 +#define EBT_VLAN_MASK (EBT_VLAN_ID | EBT_VLAN_PRIO | EBT_VLAN_ENCAP)
503 +#define EBT_VLAN_MATCH "vlan"
504 +
505 +struct ebt_vlan_info {
506 + uint16_t id; /* VLAN ID {1-4095} */
507 + uint8_t prio; /* VLAN User Priority {0-7} */
508 + uint16_t encap; /* VLAN Encapsulated frame code {0-65535} */
509 + uint8_t bitmask; /* Args bitmask bit 1=1 - ID arg,
510 + bit 2=1 User-Priority arg, bit 3=1 encap*/
511 + uint8_t invflags; /* Inverse bitmask bit 1=1 - inversed ID arg,
512 + bit 2=1 - inversed Pirority arg */
513 +};
514 +
515 +#endif
516 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebtables.h linux-ebtables/include/linux/netfilter_bridge/ebtables.h
517 --- linux-mips-cvs/include/linux/netfilter_bridge/ebtables.h 1970-01-01 01:00:00.000000000 +0100
518 +++ linux-ebtables/include/linux/netfilter_bridge/ebtables.h 2005-02-07 05:52:50.000000000 +0100
519 @@ -0,0 +1,361 @@
520 +/*
521 + * ebtables
522 + *
523 + * Authors:
524 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
525 + *
526 + * ebtables.c,v 2.0, September, 2002
527 + *
528 + * This code is stongly inspired on the iptables code which is
529 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
530 + */
531 +
532 +#ifndef __LINUX_BRIDGE_EFF_H
533 +#define __LINUX_BRIDGE_EFF_H
534 +#include <linux/if.h>
535 +#include <linux/netfilter_bridge.h>
536 +#include <linux/if_ether.h>
537 +
538 +#define EBT_TABLE_MAXNAMELEN 32
539 +#define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN
540 +#define EBT_FUNCTION_MAXNAMELEN EBT_TABLE_MAXNAMELEN
541 +
542 +// verdicts >0 are "branches"
543 +#define EBT_ACCEPT -1
544 +#define EBT_DROP -2
545 +#define EBT_CONTINUE -3
546 +#define EBT_RETURN -4
547 +#define NUM_STANDARD_TARGETS 4
548 +
549 +struct ebt_counter
550 +{
551 + uint64_t pcnt;
552 + uint64_t bcnt;
553 +};
554 +
555 +struct ebt_entries {
556 + // this field is always set to zero
557 + // See EBT_ENTRY_OR_ENTRIES.
558 + // Must be same size as ebt_entry.bitmask
559 + unsigned int distinguisher;
560 + // the chain name
561 + char name[EBT_CHAIN_MAXNAMELEN];
562 + // counter offset for this chain
563 + unsigned int counter_offset;
564 + // one standard (accept, drop, return) per hook
565 + int policy;
566 + // nr. of entries
567 + unsigned int nentries;
568 + // entry list
569 + char data[0];
570 +};
571 +
572 +// used for the bitmask of struct ebt_entry
573 +
574 +// This is a hack to make a difference between an ebt_entry struct and an
575 +// ebt_entries struct when traversing the entries from start to end.
576 +// Using this simplifies the code alot, while still being able to use
577 +// ebt_entries.
578 +// Contrary, iptables doesn't use something like ebt_entries and therefore uses
579 +// different techniques for naming the policy and such. So, iptables doesn't
580 +// need a hack like this.
581 +#define EBT_ENTRY_OR_ENTRIES 0x01
582 +// these are the normal masks
583 +#define EBT_NOPROTO 0x02
584 +#define EBT_802_3 0x04
585 +#define EBT_SOURCEMAC 0x08
586 +#define EBT_DESTMAC 0x10
587 +#define EBT_F_MASK (EBT_NOPROTO | EBT_802_3 | EBT_SOURCEMAC | EBT_DESTMAC \
588 + | EBT_ENTRY_OR_ENTRIES)
589 +
590 +#define EBT_IPROTO 0x01
591 +#define EBT_IIN 0x02
592 +#define EBT_IOUT 0x04
593 +#define EBT_ISOURCE 0x8
594 +#define EBT_IDEST 0x10
595 +#define EBT_ILOGICALIN 0x20
596 +#define EBT_ILOGICALOUT 0x40
597 +#define EBT_INV_MASK (EBT_IPROTO | EBT_IIN | EBT_IOUT | EBT_ILOGICALIN \
598 + | EBT_ILOGICALOUT | EBT_ISOURCE | EBT_IDEST)
599 +
600 +struct ebt_entry_match
601 +{
602 + union {
603 + char name[EBT_FUNCTION_MAXNAMELEN];
604 + struct ebt_match *match;
605 + } u;
606 + // size of data
607 + unsigned int match_size;
608 + unsigned char data[0];
609 +};
610 +
611 +struct ebt_entry_watcher
612 +{
613 + union {
614 + char name[EBT_FUNCTION_MAXNAMELEN];
615 + struct ebt_watcher *watcher;
616 + } u;
617 + // size of data
618 + unsigned int watcher_size;
619 + unsigned char data[0];
620 +};
621 +
622 +struct ebt_entry_target
623 +{
624 + union {
625 + char name[EBT_FUNCTION_MAXNAMELEN];
626 + struct ebt_target *target;
627 + } u;
628 + // size of data
629 + unsigned int target_size;
630 + unsigned char data[0];
631 +};
632 +
633 +#define EBT_STANDARD_TARGET "standard"
634 +struct ebt_standard_target
635 +{
636 + struct ebt_entry_target target;
637 + int verdict;
638 +};
639 +
640 +// one entry
641 +struct ebt_entry {
642 + // this needs to be the first field
643 + unsigned int bitmask;
644 + unsigned int invflags;
645 + uint16_t ethproto;
646 + // the physical in-dev
647 + char in[IFNAMSIZ];
648 + // the logical in-dev
649 + char logical_in[IFNAMSIZ];
650 + // the physical out-dev
651 + char out[IFNAMSIZ];
652 + // the logical out-dev
653 + char logical_out[IFNAMSIZ];
654 + unsigned char sourcemac[ETH_ALEN];
655 + unsigned char sourcemsk[ETH_ALEN];
656 + unsigned char destmac[ETH_ALEN];
657 + unsigned char destmsk[ETH_ALEN];
658 + // sizeof ebt_entry + matches
659 + unsigned int watchers_offset;
660 + // sizeof ebt_entry + matches + watchers
661 + unsigned int target_offset;
662 + // sizeof ebt_entry + matches + watchers + target
663 + unsigned int next_offset;
664 + unsigned char elems[0];
665 +};
666 +
667 +struct ebt_replace
668 +{
669 + char name[EBT_TABLE_MAXNAMELEN];
670 + unsigned int valid_hooks;
671 + // nr of rules in the table
672 + unsigned int nentries;
673 + // total size of the entries
674 + unsigned int entries_size;
675 + // start of the chains
676 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
677 + // nr of counters userspace expects back
678 + unsigned int num_counters;
679 + // where the kernel will put the old counters
680 + struct ebt_counter *counters;
681 + char *entries;
682 +};
683 +
684 +// [gs]etsockopt numbers
685 +#define EBT_BASE_CTL 128
686 +
687 +#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
688 +#define EBT_SO_SET_COUNTERS (EBT_SO_SET_ENTRIES+1)
689 +#define EBT_SO_SET_MAX (EBT_SO_SET_COUNTERS+1)
690 +
691 +#define EBT_SO_GET_INFO (EBT_BASE_CTL)
692 +#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO+1)
693 +#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES+1)
694 +#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO+1)
695 +#define EBT_SO_GET_MAX (EBT_SO_GET_INIT_ENTRIES+1)
696 +
697 +#ifdef __KERNEL__
698 +
699 +// return values for match() functions
700 +#define EBT_MATCH 0
701 +#define EBT_NOMATCH 1
702 +
703 +struct ebt_match
704 +{
705 + struct list_head list;
706 + const char name[EBT_FUNCTION_MAXNAMELEN];
707 + // 0 == it matches
708 + int (*match)(const struct sk_buff *skb, const struct net_device *in,
709 + const struct net_device *out, const void *matchdata,
710 + unsigned int datalen);
711 + // 0 == let it in
712 + int (*check)(const char *tablename, unsigned int hookmask,
713 + const struct ebt_entry *e, void *matchdata, unsigned int datalen);
714 + void (*destroy)(void *matchdata, unsigned int datalen);
715 + struct module *me;
716 +};
717 +
718 +struct ebt_watcher
719 +{
720 + struct list_head list;
721 + const char name[EBT_FUNCTION_MAXNAMELEN];
722 + void (*watcher)(const struct sk_buff *skb, unsigned int hooknr,
723 + const struct net_device *in, const struct net_device *out,
724 + const void *watcherdata, unsigned int datalen);
725 + // 0 == let it in
726 + int (*check)(const char *tablename, unsigned int hookmask,
727 + const struct ebt_entry *e, void *watcherdata, unsigned int datalen);
728 + void (*destroy)(void *watcherdata, unsigned int datalen);
729 + struct module *me;
730 +};
731 +
732 +struct ebt_target
733 +{
734 + struct list_head list;
735 + const char name[EBT_FUNCTION_MAXNAMELEN];
736 + // returns one of the standard verdicts
737 + int (*target)(struct sk_buff **pskb, unsigned int hooknr,
738 + const struct net_device *in, const struct net_device *out,
739 + const void *targetdata, unsigned int datalen);
740 + // 0 == let it in
741 + int (*check)(const char *tablename, unsigned int hookmask,
742 + const struct ebt_entry *e, void *targetdata, unsigned int datalen);
743 + void (*destroy)(void *targetdata, unsigned int datalen);
744 + struct module *me;
745 +};
746 +
747 +// used for jumping from and into user defined chains (udc)
748 +struct ebt_chainstack
749 +{
750 + struct ebt_entries *chaininfo; // pointer to chain data
751 + struct ebt_entry *e; // pointer to entry data
752 + unsigned int n; // n'th entry
753 +};
754 +
755 +struct ebt_table_info
756 +{
757 + // total size of the entries
758 + unsigned int entries_size;
759 + unsigned int nentries;
760 + // pointers to the start of the chains
761 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
762 + // room to maintain the stack used for jumping from and into udc
763 + struct ebt_chainstack **chainstack;
764 + char *entries;
765 + struct ebt_counter counters[0] ____cacheline_aligned;
766 +};
767 +
768 +struct ebt_table
769 +{
770 + struct list_head list;
771 + char name[EBT_TABLE_MAXNAMELEN];
772 + struct ebt_replace *table;
773 + unsigned int valid_hooks;
774 + rwlock_t lock;
775 + // e.g. could be the table explicitly only allows certain
776 + // matches, targets, ... 0 == let it in
777 + int (*check)(const struct ebt_table_info *info,
778 + unsigned int valid_hooks);
779 + // the data used by the kernel
780 + struct ebt_table_info *private;
781 +};
782 +
783 +#define EBT_ALIGN(s) (((s) + (__alignof__(struct ebt_entry_target)-1)) & \
784 + ~(__alignof__(struct ebt_entry_target)-1))
785 +extern int ebt_register_table(struct ebt_table *table);
786 +extern void ebt_unregister_table(struct ebt_table *table);
787 +extern int ebt_register_match(struct ebt_match *match);
788 +extern void ebt_unregister_match(struct ebt_match *match);
789 +extern int ebt_register_watcher(struct ebt_watcher *watcher);
790 +extern void ebt_unregister_watcher(struct ebt_watcher *watcher);
791 +extern int ebt_register_target(struct ebt_target *target);
792 +extern void ebt_unregister_target(struct ebt_target *target);
793 +extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff **pskb,
794 + const struct net_device *in, const struct net_device *out,
795 + struct ebt_table *table);
796 +
797 + // Used in the kernel match() functions
798 +#define FWINV(bool,invflg) ((bool) ^ !!(info->invflags & invflg))
799 +// True if the hook mask denotes that the rule is in a base chain,
800 +// used in the check() functions
801 +#define BASE_CHAIN (hookmask & (1 << NF_BR_NUMHOOKS))
802 +// Clear the bit in the hook mask that tells if the rule is on a base chain
803 +#define CLEAR_BASE_CHAIN_BIT (hookmask &= ~(1 << NF_BR_NUMHOOKS))
804 +// True if the target is not a standard target
805 +#define INVALID_TARGET (info->target < -NUM_STANDARD_TARGETS || info->target >= 0)
806 +
807 +#endif /* __KERNEL__ */
808 +
809 +// blatently stolen from ip_tables.h
810 +// fn returns 0 to continue iteration
811 +#define EBT_MATCH_ITERATE(e, fn, args...) \
812 +({ \
813 + unsigned int __i; \
814 + int __ret = 0; \
815 + struct ebt_entry_match *__match; \
816 + \
817 + for (__i = sizeof(struct ebt_entry); \
818 + __i < (e)->watchers_offset; \
819 + __i += __match->match_size + \
820 + sizeof(struct ebt_entry_match)) { \
821 + __match = (void *)(e) + __i; \
822 + \
823 + __ret = fn(__match , ## args); \
824 + if (__ret != 0) \
825 + break; \
826 + } \
827 + if (__ret == 0) { \
828 + if (__i != (e)->watchers_offset) \
829 + __ret = -EINVAL; \
830 + } \
831 + __ret; \
832 +})
833 +
834 +#define EBT_WATCHER_ITERATE(e, fn, args...) \
835 +({ \
836 + unsigned int __i; \
837 + int __ret = 0; \
838 + struct ebt_entry_watcher *__watcher; \
839 + \
840 + for (__i = e->watchers_offset; \
841 + __i < (e)->target_offset; \
842 + __i += __watcher->watcher_size + \
843 + sizeof(struct ebt_entry_watcher)) { \
844 + __watcher = (void *)(e) + __i; \
845 + \
846 + __ret = fn(__watcher , ## args); \
847 + if (__ret != 0) \
848 + break; \
849 + } \
850 + if (__ret == 0) { \
851 + if (__i != (e)->target_offset) \
852 + __ret = -EINVAL; \
853 + } \
854 + __ret; \
855 +})
856 +
857 +#define EBT_ENTRY_ITERATE(entries, size, fn, args...) \
858 +({ \
859 + unsigned int __i; \
860 + int __ret = 0; \
861 + struct ebt_entry *__entry; \
862 + \
863 + for (__i = 0; __i < (size);) { \
864 + __entry = (void *)(entries) + __i; \
865 + __ret = fn(__entry , ## args); \
866 + if (__ret != 0) \
867 + break; \
868 + if (__entry->bitmask != 0) \
869 + __i += __entry->next_offset; \
870 + else \
871 + __i += sizeof(struct ebt_entries); \
872 + } \
873 + if (__ret == 0) { \
874 + if (__i != (size)) \
875 + __ret = -EINVAL; \
876 + } \
877 + __ret; \
878 +})
879 +
880 +#endif
881 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge.h linux-ebtables/include/linux/netfilter_bridge.h
882 --- linux-mips-cvs/include/linux/netfilter_bridge.h 2001-08-22 05:25:11.000000000 +0200
883 +++ linux-ebtables/include/linux/netfilter_bridge.h 2005-02-07 05:52:50.000000000 +0100
884 @@ -6,6 +6,10 @@
885
886 #include <linux/config.h>
887 #include <linux/netfilter.h>
888 +#if defined(__KERNEL__) && defined(CONFIG_NETFILTER)
889 +#include <asm/atomic.h>
890 +#include <linux/if_ether.h>
891 +#endif
892
893 /* Bridge Hooks */
894 /* After promisc drops, checksum checks. */
895 @@ -18,7 +22,76 @@
896 #define NF_BR_LOCAL_OUT 3
897 /* Packets about to hit the wire. */
898 #define NF_BR_POST_ROUTING 4
899 -#define NF_BR_NUMHOOKS 5
900 +/* Not really a hook, but used for the ebtables broute table */
901 +#define NF_BR_BROUTING 5
902 +#define NF_BR_NUMHOOKS 6
903 +
904 +#ifdef __KERNEL__
905 +
906 +#define BRNF_PKT_TYPE 0x01
907 +#define BRNF_BRIDGED_DNAT 0x02
908 +#define BRNF_DONT_TAKE_PARENT 0x04
909 +#define BRNF_BRIDGED 0x08
910 +#define BRNF_NF_BRIDGE_PREROUTING 0x10
911 +
912 +enum nf_br_hook_priorities {
913 + NF_BR_PRI_FIRST = INT_MIN,
914 + NF_BR_PRI_NAT_DST_BRIDGED = -300,
915 + NF_BR_PRI_FILTER_BRIDGED = -200,
916 + NF_BR_PRI_BRNF = 0,
917 + NF_BR_PRI_NAT_DST_OTHER = 100,
918 + NF_BR_PRI_FILTER_OTHER = 200,
919 + NF_BR_PRI_NAT_SRC = 300,
920 + NF_BR_PRI_LAST = INT_MAX,
921 +};
922 +
923 +#ifdef CONFIG_NETFILTER
924 +static inline
925 +struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
926 +{
927 + struct nf_bridge_info **nf_bridge = &(skb->nf_bridge);
928 +
929 + if ((*nf_bridge = kmalloc(sizeof(**nf_bridge), GFP_ATOMIC)) != NULL) {
930 + atomic_set(&(*nf_bridge)->use, 1);
931 + (*nf_bridge)->mask = 0;
932 + (*nf_bridge)->physindev = (*nf_bridge)->physoutdev = NULL;
933 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
934 + (*nf_bridge)->netoutdev = NULL;
935 +#endif
936 + }
937 +
938 + return *nf_bridge;
939 +}
940 +
941 +/* Only used in br_forward.c */
942 +static inline
943 +void nf_bridge_maybe_copy_header(struct sk_buff *skb)
944 +{
945 + if (skb->nf_bridge) {
946 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
947 + memcpy(skb->data - 18, skb->nf_bridge->data, 18);
948 + skb_push(skb, 4);
949 + } else
950 + memcpy(skb->data - 16, skb->nf_bridge->data, 16);
951 + }
952 +}
953 +
954 +static inline
955 +void nf_bridge_save_header(struct sk_buff *skb)
956 +{
957 + int header_size = 16;
958 +
959 + if (skb->protocol == __constant_htons(ETH_P_8021Q))
960 + header_size = 18;
961 + memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
962 +}
963
964 +struct bridge_skb_cb {
965 + union {
966 + __u32 ipv4;
967 + } daddr;
968 +};
969 +#endif /* CONFIG_NETFILTER */
970
971 +#endif /* __KERNEL__ */
972 #endif
973 diff -Nur linux-mips-cvs/include/linux/netfilter_ipv4/ipt_physdev.h linux-ebtables/include/linux/netfilter_ipv4/ipt_physdev.h
974 --- linux-mips-cvs/include/linux/netfilter_ipv4/ipt_physdev.h 1970-01-01 01:00:00.000000000 +0100
975 +++ linux-ebtables/include/linux/netfilter_ipv4/ipt_physdev.h 2005-02-07 05:52:50.000000000 +0100
976 @@ -0,0 +1,24 @@
977 +#ifndef _IPT_PHYSDEV_H
978 +#define _IPT_PHYSDEV_H
979 +
980 +#ifdef __KERNEL__
981 +#include <linux/if.h>
982 +#endif
983 +
984 +#define IPT_PHYSDEV_OP_IN 0x01
985 +#define IPT_PHYSDEV_OP_OUT 0x02
986 +#define IPT_PHYSDEV_OP_BRIDGED 0x04
987 +#define IPT_PHYSDEV_OP_ISIN 0x08
988 +#define IPT_PHYSDEV_OP_ISOUT 0x10
989 +#define IPT_PHYSDEV_OP_MASK (0x20 - 1)
990 +
991 +struct ipt_physdev_info {
992 + char physindev[IFNAMSIZ];
993 + char in_mask[IFNAMSIZ];
994 + char physoutdev[IFNAMSIZ];
995 + char out_mask[IFNAMSIZ];
996 + u_int8_t invert;
997 + u_int8_t bitmask;
998 +};
999 +
1000 +#endif /*_IPT_PHYSDEV_H*/
1001 diff -Nur linux-mips-cvs/include/linux/netfilter_ipv4.h linux-ebtables/include/linux/netfilter_ipv4.h
1002 --- linux-mips-cvs/include/linux/netfilter_ipv4.h 2002-02-26 07:00:31.000000000 +0100
1003 +++ linux-ebtables/include/linux/netfilter_ipv4.h 2005-02-07 05:52:50.000000000 +0100
1004 @@ -52,8 +52,10 @@
1005 enum nf_ip_hook_priorities {
1006 NF_IP_PRI_FIRST = INT_MIN,
1007 NF_IP_PRI_CONNTRACK = -200,
1008 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD = -175,
1009 NF_IP_PRI_MANGLE = -150,
1010 NF_IP_PRI_NAT_DST = -100,
1011 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT = -50,
1012 NF_IP_PRI_FILTER = 0,
1013 NF_IP_PRI_NAT_SRC = 100,
1014 NF_IP_PRI_LAST = INT_MAX,
1015 diff -Nur linux-mips-cvs/include/linux/netfilter_ipv6.h linux-ebtables/include/linux/netfilter_ipv6.h
1016 --- linux-mips-cvs/include/linux/netfilter_ipv6.h 2001-01-11 05:02:45.000000000 +0100
1017 +++ linux-ebtables/include/linux/netfilter_ipv6.h 2005-02-07 05:52:50.000000000 +0100
1018 @@ -57,8 +57,10 @@
1019 enum nf_ip6_hook_priorities {
1020 NF_IP6_PRI_FIRST = INT_MIN,
1021 NF_IP6_PRI_CONNTRACK = -200,
1022 + NF_IP6_PRI_BRIDGE_SABOTAGE_FORWARD = -175,
1023 NF_IP6_PRI_MANGLE = -150,
1024 NF_IP6_PRI_NAT_DST = -100,
1025 + NF_IP6_PRI_BRIDGE_SABOTAGE_LOCAL_OUT = -50,
1026 NF_IP6_PRI_FILTER = 0,
1027 NF_IP6_PRI_NAT_SRC = 100,
1028 NF_IP6_PRI_LAST = INT_MAX,
1029 diff -Nur linux-mips-cvs/include/linux/skbuff.h linux-ebtables/include/linux/skbuff.h
1030 --- linux-mips-cvs/include/linux/skbuff.h 2005-01-31 12:56:47.000000000 +0100
1031 +++ linux-ebtables/include/linux/skbuff.h 2005-02-07 05:52:50.000000000 +0100
1032 @@ -92,6 +92,20 @@
1033 struct nf_ct_info {
1034 struct nf_conntrack *master;
1035 };
1036 +
1037 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1038 +struct nf_bridge_info {
1039 + atomic_t use;
1040 + struct net_device *physindev;
1041 + struct net_device *physoutdev;
1042 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1043 + struct net_device *netoutdev;
1044 +#endif
1045 + unsigned int mask;
1046 + unsigned long data[32 / sizeof(unsigned long)];
1047 +};
1048 +#endif
1049 +
1050 #endif
1051
1052 struct sk_buff_head {
1053 @@ -208,6 +222,9 @@
1054 #ifdef CONFIG_NETFILTER_DEBUG
1055 unsigned int nf_debug;
1056 #endif
1057 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1058 + struct nf_bridge_info *nf_bridge; /* Saved data about a bridged frame - see br_netfilter.c */
1059 +#endif
1060 #endif /*CONFIG_NETFILTER*/
1061
1062 #if defined(CONFIG_HIPPI)
1063 @@ -1175,6 +1192,20 @@
1064 skb->nf_debug = 0;
1065 #endif
1066 }
1067 +
1068 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1069 +static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
1070 +{
1071 + if (nf_bridge && atomic_dec_and_test(&nf_bridge->use))
1072 + kfree(nf_bridge);
1073 +}
1074 +static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)
1075 +{
1076 + if (nf_bridge)
1077 + atomic_inc(&nf_bridge->use);
1078 +}
1079 +#endif
1080 +
1081 #else /* CONFIG_NETFILTER */
1082 static inline void nf_reset(struct sk_buff *skb) {}
1083 #endif /* CONFIG_NETFILTER */
1084 diff -Nur linux-mips-cvs/include/linux/sysctl.h linux-ebtables/include/linux/sysctl.h
1085 --- linux-mips-cvs/include/linux/sysctl.h 2004-11-29 18:47:18.000000000 +0100
1086 +++ linux-ebtables/include/linux/sysctl.h 2005-02-07 05:52:50.000000000 +0100
1087 @@ -608,6 +608,15 @@
1088 NET_DECNET_CONF_DEV_STATE = 7
1089 };
1090
1091 +/* /proc/sys/net/bridge */
1092 +enum {
1093 + NET_BRIDGE_NF_CALL_ARPTABLES = 1,
1094 + NET_BRIDGE_NF_CALL_IPTABLES = 2,
1095 + NET_BRIDGE_NF_CALL_IP6TABLES = 3,
1096 + NET_BRIDGE_NF_FILTER_VLAN_TAGGED = 4,
1097 +};
1098 +
1099 +
1100 /* CTL_PROC names: */
1101
1102 /* CTL_FS names: */
1103 diff -Nur linux-mips-cvs/include/linux/sysctl.h.orig linux-ebtables/include/linux/sysctl.h.orig
1104 --- linux-mips-cvs/include/linux/sysctl.h.orig 1970-01-01 01:00:00.000000000 +0100
1105 +++ linux-ebtables/include/linux/sysctl.h.orig 2004-11-29 18:47:18.000000000 +0100
1106 @@ -0,0 +1,841 @@
1107 +/*
1108 + * sysctl.h: General linux system control interface
1109 + *
1110 + * Begun 24 March 1995, Stephen Tweedie
1111 + *
1112 + ****************************************************************
1113 + ****************************************************************
1114 + **
1115 + ** WARNING:
1116 + ** The values in this file are exported to user space via
1117 + ** the sysctl() binary interface. Do *NOT* change the
1118 + ** numbering of any existing values here, and do not change
1119 + ** any numbers within any one set of values. If you have
1120 + ** to redefine an existing interface, use a new number for it.
1121 + ** The kernel will then return ENOTDIR to any application using
1122 + ** the old binary interface.
1123 + **
1124 + ** --sct
1125 + **
1126 + ****************************************************************
1127 + ****************************************************************
1128 + */
1129 +
1130 +#ifndef _LINUX_SYSCTL_H
1131 +#define _LINUX_SYSCTL_H
1132 +
1133 +#include <linux/kernel.h>
1134 +#include <linux/types.h>
1135 +#include <linux/list.h>
1136 +
1137 +struct file;
1138 +
1139 +#define CTL_MAXNAME 10
1140 +
1141 +struct __sysctl_args {
1142 + int *name;
1143 + int nlen;
1144 + void *oldval;
1145 + size_t *oldlenp;
1146 + void *newval;
1147 + size_t newlen;
1148 + unsigned long __unused[4];
1149 +};
1150 +
1151 +/* Define sysctl names first */
1152 +
1153 +/* Top-level names: */
1154 +
1155 +/* For internal pattern-matching use only: */
1156 +#ifdef __KERNEL__
1157 +#define CTL_ANY -1 /* Matches any name */
1158 +#define CTL_NONE 0
1159 +#endif
1160 +
1161 +enum
1162 +{
1163 + CTL_KERN=1, /* General kernel info and control */
1164 + CTL_VM=2, /* VM management */
1165 + CTL_NET=3, /* Networking */
1166 + CTL_PROC=4, /* Process info */
1167 + CTL_FS=5, /* Filesystems */
1168 + CTL_DEBUG=6, /* Debugging */
1169 + CTL_DEV=7, /* Devices */
1170 + CTL_BUS=8, /* Busses */
1171 + CTL_ABI=9, /* Binary emulation */
1172 + CTL_CPU=10 /* CPU stuff (speed scaling, etc) */
1173 +};
1174 +
1175 +/* CTL_BUS names: */
1176 +enum
1177 +{
1178 + CTL_BUS_ISA=1 /* ISA */
1179 +};
1180 +
1181 +/* CTL_KERN names: */
1182 +enum
1183 +{
1184 + KERN_OSTYPE=1, /* string: system version */
1185 + KERN_OSRELEASE=2, /* string: system release */
1186 + KERN_OSREV=3, /* int: system revision */
1187 + KERN_VERSION=4, /* string: compile time info */
1188 + KERN_SECUREMASK=5, /* struct: maximum rights mask */
1189 + KERN_PROF=6, /* table: profiling information */
1190 + KERN_NODENAME=7,
1191 + KERN_DOMAINNAME=8,
1192 +
1193 + KERN_CAP_BSET=14, /* int: capability bounding set */
1194 + KERN_PANIC=15, /* int: panic timeout */
1195 + KERN_REALROOTDEV=16, /* real root device to mount after initrd */
1196 +
1197 + KERN_SPARC_REBOOT=21, /* reboot command on Sparc */
1198 + KERN_CTLALTDEL=22, /* int: allow ctl-alt-del to reboot */
1199 + KERN_PRINTK=23, /* struct: control printk logging parameters */
1200 + KERN_NAMETRANS=24, /* Name translation */
1201 + KERN_PPC_HTABRECLAIM=25, /* turn htab reclaimation on/off on PPC */
1202 + KERN_PPC_ZEROPAGED=26, /* turn idle page zeroing on/off on PPC */
1203 + KERN_PPC_POWERSAVE_NAP=27, /* use nap mode for power saving */
1204 + KERN_MODPROBE=28,
1205 + KERN_SG_BIG_BUFF=29,
1206 + KERN_ACCT=30, /* BSD process accounting parameters */
1207 + KERN_PPC_L2CR=31, /* l2cr register on PPC */
1208 +
1209 + KERN_RTSIGNR=32, /* Number of rt sigs queued */
1210 + KERN_RTSIGMAX=33, /* Max queuable */
1211 +
1212 + KERN_SHMMAX=34, /* long: Maximum shared memory segment */
1213 + KERN_MSGMAX=35, /* int: Maximum size of a messege */
1214 + KERN_MSGMNB=36, /* int: Maximum message queue size */
1215 + KERN_MSGPOOL=37, /* int: Maximum system message pool size */
1216 + KERN_SYSRQ=38, /* int: Sysreq enable */
1217 + KERN_MAX_THREADS=39, /* int: Maximum nr of threads in the system */
1218 + KERN_RANDOM=40, /* Random driver */
1219 + KERN_SHMALL=41, /* int: Maximum size of shared memory */
1220 + KERN_MSGMNI=42, /* int: msg queue identifiers */
1221 + KERN_SEM=43, /* struct: sysv semaphore limits */
1222 + KERN_SPARC_STOP_A=44, /* int: Sparc Stop-A enable */
1223 + KERN_SHMMNI=45, /* int: shm array identifiers */
1224 + KERN_OVERFLOWUID=46, /* int: overflow UID */
1225 + KERN_OVERFLOWGID=47, /* int: overflow GID */
1226 + KERN_SHMPATH=48, /* string: path to shm fs */
1227 + KERN_HOTPLUG=49, /* string: path to hotplug policy agent */
1228 + KERN_IEEE_EMULATION_WARNINGS=50, /* int: unimplemented ieee instructions */
1229 + KERN_S390_USER_DEBUG_LOGGING=51, /* int: dumps of user faults */
1230 + KERN_CORE_USES_PID=52, /* int: use core or core.%pid */
1231 + KERN_TAINTED=53, /* int: various kernel tainted flags */
1232 + KERN_CADPID=54, /* int: PID of the process to notify on CAD */
1233 + KERN_CORE_PATTERN=56, /* string: pattern for core-files */
1234 + KERN_PPC_L3CR=57, /* l3cr register on PPC */
1235 + KERN_EXCEPTION_TRACE=58, /* boolean: exception trace */
1236 + KERN_CORE_SETUID=59, /* int: set to allow core dumps of setuid apps */
1237 + KERN_SPARC_SCONS_PWROFF=64, /* int: serial console power-off halt */
1238 +};
1239 +
1240 +
1241 +/* CTL_VM names: */
1242 +enum
1243 +{
1244 + VM_SWAPCTL=1, /* struct: Set vm swapping control */
1245 + VM_SWAPOUT=2, /* int: Linear or sqrt() swapout for hogs */
1246 + VM_FREEPG=3, /* struct: Set free page thresholds */
1247 + VM_BDFLUSH=4, /* struct: Control buffer cache flushing */
1248 + VM_OVERCOMMIT_MEMORY=5, /* Turn off the virtual memory safety limit */
1249 + VM_BUFFERMEM=6, /* struct: Set buffer memory thresholds */
1250 + VM_PAGECACHE=7, /* struct: Set cache memory thresholds */
1251 + VM_PAGERDAEMON=8, /* struct: Control kswapd behaviour */
1252 + VM_PGT_CACHE=9, /* struct: Set page table cache parameters */
1253 + VM_PAGE_CLUSTER=10, /* int: set number of pages to swap together */
1254 + VM_MAX_MAP_COUNT=11, /* int: Maximum number of active map areas */
1255 + VM_MIN_READAHEAD=12, /* Min file readahead */
1256 + VM_MAX_READAHEAD=13, /* Max file readahead */
1257 + VM_VFS_SCAN_RATIO=14, /* part of the inactive vfs lists to scan */
1258 + VM_LRU_BALANCE_RATIO=15,/* balance active and inactive caches */
1259 + VM_PASSES=16, /* number of vm passes before failing */
1260 + VM_PAGEBUF=17, /* struct: Control pagebuf parameters */
1261 + VM_GFP_DEBUG=18, /* debug GFP failures */
1262 + VM_CACHE_SCAN_RATIO=19, /* part of the inactive cache list to scan */
1263 + VM_MAPPED_RATIO=20, /* amount of unfreeable pages that triggers swapout */
1264 + VM_LAPTOP_MODE=21, /* kernel in laptop flush mode */
1265 + VM_BLOCK_DUMP=22, /* dump fs activity to log */
1266 + VM_ANON_LRU=23, /* immediatly insert anon pages in the vm page lru */
1267 +};
1268 +
1269 +
1270 +/* CTL_NET names: */
1271 +enum
1272 +{
1273 + NET_CORE=1,
1274 + NET_ETHER=2,
1275 + NET_802=3,
1276 + NET_UNIX=4,
1277 + NET_IPV4=5,
1278 + NET_IPX=6,
1279 + NET_ATALK=7,
1280 + NET_NETROM=8,
1281 + NET_AX25=9,
1282 + NET_BRIDGE=10,
1283 + NET_ROSE=11,
1284 + NET_IPV6=12,
1285 + NET_X25=13,
1286 + NET_TR=14,
1287 + NET_DECNET=15,
1288 + NET_ECONET=16,
1289 + NET_KHTTPD=17,
1290 + NET_SCTP=18
1291 +};
1292 +
1293 +/* /proc/sys/kernel/random */
1294 +enum
1295 +{
1296 + RANDOM_POOLSIZE=1,
1297 + RANDOM_ENTROPY_COUNT=2,
1298 + RANDOM_READ_THRESH=3,
1299 + RANDOM_WRITE_THRESH=4,
1300 + RANDOM_BOOT_ID=5,
1301 + RANDOM_UUID=6
1302 +};
1303 +
1304 +/* /proc/sys/bus/isa */
1305 +enum
1306 +{
1307 + BUS_ISA_MEM_BASE=1,
1308 + BUS_ISA_PORT_BASE=2,
1309 + BUS_ISA_PORT_SHIFT=3
1310 +};
1311 +
1312 +/* /proc/sys/net/core */
1313 +enum
1314 +{
1315 + NET_CORE_WMEM_MAX=1,
1316 + NET_CORE_RMEM_MAX=2,
1317 + NET_CORE_WMEM_DEFAULT=3,
1318 + NET_CORE_RMEM_DEFAULT=4,
1319 +/* was NET_CORE_DESTROY_DELAY */
1320 + NET_CORE_MAX_BACKLOG=6,
1321 + NET_CORE_FASTROUTE=7,
1322 + NET_CORE_MSG_COST=8,
1323 + NET_CORE_MSG_BURST=9,
1324 + NET_CORE_OPTMEM_MAX=10,
1325 + NET_CORE_HOT_LIST_LENGTH=11,
1326 + NET_CORE_DIVERT_VERSION=12,
1327 + NET_CORE_NO_CONG_THRESH=13,
1328 + NET_CORE_NO_CONG=14,
1329 + NET_CORE_LO_CONG=15,
1330 + NET_CORE_MOD_CONG=16,
1331 + NET_CORE_DEV_WEIGHT=17,
1332 + NET_CORE_SOMAXCONN=18,
1333 +};
1334 +
1335 +/* /proc/sys/net/ethernet */
1336 +
1337 +/* /proc/sys/net/802 */
1338 +
1339 +/* /proc/sys/net/unix */
1340 +
1341 +enum
1342 +{
1343 + NET_UNIX_DESTROY_DELAY=1,
1344 + NET_UNIX_DELETE_DELAY=2,
1345 + NET_UNIX_MAX_DGRAM_QLEN=3,
1346 +};
1347 +
1348 +/* /proc/sys/net/ipv4 */
1349 +enum
1350 +{
1351 + /* v2.0 compatibile variables */
1352 + NET_IPV4_FORWARD=8,
1353 + NET_IPV4_DYNADDR=9,
1354 +
1355 + NET_IPV4_CONF=16,
1356 + NET_IPV4_NEIGH=17,
1357 + NET_IPV4_ROUTE=18,
1358 + NET_IPV4_FIB_HASH=19,
1359 + NET_IPV4_NETFILTER=20,
1360 +
1361 + NET_IPV4_TCP_TIMESTAMPS=33,
1362 + NET_IPV4_TCP_WINDOW_SCALING=34,
1363 + NET_IPV4_TCP_SACK=35,
1364 + NET_IPV4_TCP_RETRANS_COLLAPSE=36,
1365 + NET_IPV4_DEFAULT_TTL=37,
1366 + NET_IPV4_AUTOCONFIG=38,
1367 + NET_IPV4_NO_PMTU_DISC=39,
1368 + NET_IPV4_TCP_SYN_RETRIES=40,
1369 + NET_IPV4_IPFRAG_HIGH_THRESH=41,
1370 + NET_IPV4_IPFRAG_LOW_THRESH=42,
1371 + NET_IPV4_IPFRAG_TIME=43,
1372 + NET_IPV4_TCP_MAX_KA_PROBES=44,
1373 + NET_IPV4_TCP_KEEPALIVE_TIME=45,
1374 + NET_IPV4_TCP_KEEPALIVE_PROBES=46,
1375 + NET_IPV4_TCP_RETRIES1=47,
1376 + NET_IPV4_TCP_RETRIES2=48,
1377 + NET_IPV4_TCP_FIN_TIMEOUT=49,
1378 + NET_IPV4_IP_MASQ_DEBUG=50,
1379 + NET_TCP_SYNCOOKIES=51,
1380 + NET_TCP_STDURG=52,
1381 + NET_TCP_RFC1337=53,
1382 + NET_TCP_SYN_TAILDROP=54,
1383 + NET_TCP_MAX_SYN_BACKLOG=55,
1384 + NET_IPV4_LOCAL_PORT_RANGE=56,
1385 + NET_IPV4_ICMP_ECHO_IGNORE_ALL=57,
1386 + NET_IPV4_ICMP_ECHO_IGNORE_BROADCASTS=58,
1387 + NET_IPV4_ICMP_SOURCEQUENCH_RATE=59,
1388 + NET_IPV4_ICMP_DESTUNREACH_RATE=60,
1389 + NET_IPV4_ICMP_TIMEEXCEED_RATE=61,
1390 + NET_IPV4_ICMP_PARAMPROB_RATE=62,
1391 + NET_IPV4_ICMP_ECHOREPLY_RATE=63,
1392 + NET_IPV4_ICMP_IGNORE_BOGUS_ERROR_RESPONSES=64,
1393 + NET_IPV4_IGMP_MAX_MEMBERSHIPS=65,
1394 + NET_TCP_TW_RECYCLE=66,
1395 + NET_IPV4_ALWAYS_DEFRAG=67,
1396 + NET_IPV4_TCP_KEEPALIVE_INTVL=68,
1397 + NET_IPV4_INET_PEER_THRESHOLD=69,
1398 + NET_IPV4_INET_PEER_MINTTL=70,
1399 + NET_IPV4_INET_PEER_MAXTTL=71,
1400 + NET_IPV4_INET_PEER_GC_MINTIME=72,
1401 + NET_IPV4_INET_PEER_GC_MAXTIME=73,
1402 + NET_TCP_ORPHAN_RETRIES=74,
1403 + NET_TCP_ABORT_ON_OVERFLOW=75,
1404 + NET_TCP_SYNACK_RETRIES=76,
1405 + NET_TCP_MAX_ORPHANS=77,
1406 + NET_TCP_MAX_TW_BUCKETS=78,
1407 + NET_TCP_FACK=79,
1408 + NET_TCP_REORDERING=80,
1409 + NET_TCP_ECN=81,
1410 + NET_TCP_DSACK=82,
1411 + NET_TCP_MEM=83,
1412 + NET_TCP_WMEM=84,
1413 + NET_TCP_RMEM=85,
1414 + NET_TCP_APP_WIN=86,
1415 + NET_TCP_ADV_WIN_SCALE=87,
1416 + NET_IPV4_NONLOCAL_BIND=88,
1417 + NET_IPV4_ICMP_RATELIMIT=89,
1418 + NET_IPV4_ICMP_RATEMASK=90,
1419 + NET_TCP_TW_REUSE=91,
1420 + NET_TCP_FRTO=92,
1421 + NET_TCP_LOW_LATENCY=93,
1422 + NET_IPV4_IPFRAG_SECRET_INTERVAL=94,
1423 + NET_TCP_WESTWOOD=95,
1424 + NET_IPV4_IGMP_MAX_MSF=96,
1425 + NET_TCP_NO_METRICS_SAVE=97,
1426 + NET_TCP_VEGAS=98,
1427 + NET_TCP_VEGAS_ALPHA=99,
1428 + NET_TCP_VEGAS_BETA=100,
1429 + NET_TCP_VEGAS_GAMMA=101,
1430 + NET_TCP_BIC=102,
1431 + NET_TCP_BIC_FAST_CONVERGENCE=103,
1432 + NET_TCP_BIC_LOW_WINDOW=104,
1433 + NET_TCP_DEFAULT_WIN_SCALE=105,
1434 + NET_TCP_MODERATE_RCVBUF=106,
1435 +};
1436 +
1437 +enum {
1438 + NET_IPV4_ROUTE_FLUSH=1,
1439 + NET_IPV4_ROUTE_MIN_DELAY=2,
1440 + NET_IPV4_ROUTE_MAX_DELAY=3,
1441 + NET_IPV4_ROUTE_GC_THRESH=4,
1442 + NET_IPV4_ROUTE_MAX_SIZE=5,
1443 + NET_IPV4_ROUTE_GC_MIN_INTERVAL=6,
1444 + NET_IPV4_ROUTE_GC_TIMEOUT=7,
1445 + NET_IPV4_ROUTE_GC_INTERVAL=8,
1446 + NET_IPV4_ROUTE_REDIRECT_LOAD=9,
1447 + NET_IPV4_ROUTE_REDIRECT_NUMBER=10,
1448 + NET_IPV4_ROUTE_REDIRECT_SILENCE=11,
1449 + NET_IPV4_ROUTE_ERROR_COST=12,
1450 + NET_IPV4_ROUTE_ERROR_BURST=13,
1451 + NET_IPV4_ROUTE_GC_ELASTICITY=14,
1452 + NET_IPV4_ROUTE_MTU_EXPIRES=15,
1453 + NET_IPV4_ROUTE_MIN_PMTU=16,
1454 + NET_IPV4_ROUTE_MIN_ADVMSS=17,
1455 + NET_IPV4_ROUTE_SECRET_INTERVAL=18,
1456 +};
1457 +
1458 +enum
1459 +{
1460 + NET_PROTO_CONF_ALL=-2,
1461 + NET_PROTO_CONF_DEFAULT=-3
1462 +
1463 + /* And device ifindices ... */
1464 +};
1465 +
1466 +enum
1467 +{
1468 + NET_IPV4_CONF_FORWARDING=1,
1469 + NET_IPV4_CONF_MC_FORWARDING=2,
1470 + NET_IPV4_CONF_PROXY_ARP=3,
1471 + NET_IPV4_CONF_ACCEPT_REDIRECTS=4,
1472 + NET_IPV4_CONF_SECURE_REDIRECTS=5,
1473 + NET_IPV4_CONF_SEND_REDIRECTS=6,
1474 + NET_IPV4_CONF_SHARED_MEDIA=7,
1475 + NET_IPV4_CONF_RP_FILTER=8,
1476 + NET_IPV4_CONF_ACCEPT_SOURCE_ROUTE=9,
1477 + NET_IPV4_CONF_BOOTP_RELAY=10,
1478 + NET_IPV4_CONF_LOG_MARTIANS=11,
1479 + NET_IPV4_CONF_TAG=12,
1480 + NET_IPV4_CONF_ARPFILTER=13,
1481 + NET_IPV4_CONF_MEDIUM_ID=14,
1482 + NET_IPV4_CONF_FORCE_IGMP_VERSION=17,
1483 + NET_IPV4_CONF_ARP_ANNOUNCE=18,
1484 + NET_IPV4_CONF_ARP_IGNORE=19,
1485 +};
1486 +
1487 +/* /proc/sys/net/ipv4/netfilter */
1488 +enum
1489 +{
1490 + NET_IPV4_NF_CONNTRACK_MAX=1,
1491 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT=2,
1492 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV=3,
1493 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED=4,
1494 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT=5,
1495 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT=6,
1496 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK=7,
1497 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT=8,
1498 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE=9,
1499 + NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT=10,
1500 + NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT_STREAM=11,
1501 + NET_IPV4_NF_CONNTRACK_ICMP_TIMEOUT=12,
1502 + NET_IPV4_NF_CONNTRACK_GENERIC_TIMEOUT=13,
1503 + NET_IPV4_NF_CONNTRACK_BUCKETS=14,
1504 +};
1505 +
1506 +/* /proc/sys/net/ipv6 */
1507 +enum {
1508 + NET_IPV6_CONF=16,
1509 + NET_IPV6_NEIGH=17,
1510 + NET_IPV6_ROUTE=18,
1511 + NET_IPV6_ICMP=19,
1512 + NET_IPV6_BINDV6ONLY=20,
1513 + NET_IPV6_MLD_MAX_MSF=25,
1514 +};
1515 +
1516 +enum {
1517 + NET_IPV6_ROUTE_FLUSH=1,
1518 + NET_IPV6_ROUTE_GC_THRESH=2,
1519 + NET_IPV6_ROUTE_MAX_SIZE=3,
1520 + NET_IPV6_ROUTE_GC_MIN_INTERVAL=4,
1521 + NET_IPV6_ROUTE_GC_TIMEOUT=5,
1522 + NET_IPV6_ROUTE_GC_INTERVAL=6,
1523 + NET_IPV6_ROUTE_GC_ELASTICITY=7,
1524 + NET_IPV6_ROUTE_MTU_EXPIRES=8,
1525 + NET_IPV6_ROUTE_MIN_ADVMSS=9
1526 +};
1527 +
1528 +enum {
1529 + NET_IPV6_FORWARDING=1,
1530 + NET_IPV6_HOP_LIMIT=2,
1531 + NET_IPV6_MTU=3,
1532 + NET_IPV6_ACCEPT_RA=4,
1533 + NET_IPV6_ACCEPT_REDIRECTS=5,
1534 + NET_IPV6_AUTOCONF=6,
1535 + NET_IPV6_DAD_TRANSMITS=7,
1536 + NET_IPV6_RTR_SOLICITS=8,
1537 + NET_IPV6_RTR_SOLICIT_INTERVAL=9,
1538 + NET_IPV6_RTR_SOLICIT_DELAY=10
1539 +};
1540 +
1541 +/* /proc/sys/net/ipv6/icmp */
1542 +enum {
1543 + NET_IPV6_ICMP_RATELIMIT=1
1544 +};
1545 +
1546 +/* /proc/sys/net/<protocol>/neigh/<dev> */
1547 +enum {
1548 + NET_NEIGH_MCAST_SOLICIT=1,
1549 + NET_NEIGH_UCAST_SOLICIT=2,
1550 + NET_NEIGH_APP_SOLICIT=3,
1551 + NET_NEIGH_RETRANS_TIME=4,
1552 + NET_NEIGH_REACHABLE_TIME=5,
1553 + NET_NEIGH_DELAY_PROBE_TIME=6,
1554 + NET_NEIGH_GC_STALE_TIME=7,
1555 + NET_NEIGH_UNRES_QLEN=8,
1556 + NET_NEIGH_PROXY_QLEN=9,
1557 + NET_NEIGH_ANYCAST_DELAY=10,
1558 + NET_NEIGH_PROXY_DELAY=11,
1559 + NET_NEIGH_LOCKTIME=12,
1560 + NET_NEIGH_GC_INTERVAL=13,
1561 + NET_NEIGH_GC_THRESH1=14,
1562 + NET_NEIGH_GC_THRESH2=15,
1563 + NET_NEIGH_GC_THRESH3=16
1564 +};
1565 +
1566 +/* /proc/sys/net/ipx */
1567 +enum {
1568 + NET_IPX_PPROP_BROADCASTING=1,
1569 + NET_IPX_FORWARDING=2
1570 +};
1571 +
1572 +
1573 +/* /proc/sys/net/appletalk */
1574 +enum {
1575 + NET_ATALK_AARP_EXPIRY_TIME=1,
1576 + NET_ATALK_AARP_TICK_TIME=2,
1577 + NET_ATALK_AARP_RETRANSMIT_LIMIT=3,
1578 + NET_ATALK_AARP_RESOLVE_TIME=4
1579 +};
1580 +
1581 +
1582 +/* /proc/sys/net/netrom */
1583 +enum {
1584 + NET_NETROM_DEFAULT_PATH_QUALITY=1,
1585 + NET_NETROM_OBSOLESCENCE_COUNT_INITIALISER=2,
1586 + NET_NETROM_NETWORK_TTL_INITIALISER=3,
1587 + NET_NETROM_TRANSPORT_TIMEOUT=4,
1588 + NET_NETROM_TRANSPORT_MAXIMUM_TRIES=5,
1589 + NET_NETROM_TRANSPORT_ACKNOWLEDGE_DELAY=6,
1590 + NET_NETROM_TRANSPORT_BUSY_DELAY=7,
1591 + NET_NETROM_TRANSPORT_REQUESTED_WINDOW_SIZE=8,
1592 + NET_NETROM_TRANSPORT_NO_ACTIVITY_TIMEOUT=9,
1593 + NET_NETROM_ROUTING_CONTROL=10,
1594 + NET_NETROM_LINK_FAILS_COUNT=11
1595 +};
1596 +
1597 +/* /proc/sys/net/ax25 */
1598 +enum {
1599 + NET_AX25_IP_DEFAULT_MODE=1,
1600 + NET_AX25_DEFAULT_MODE=2,
1601 + NET_AX25_BACKOFF_TYPE=3,
1602 + NET_AX25_CONNECT_MODE=4,
1603 + NET_AX25_STANDARD_WINDOW=5,
1604 + NET_AX25_EXTENDED_WINDOW=6,
1605 + NET_AX25_T1_TIMEOUT=7,
1606 + NET_AX25_T2_TIMEOUT=8,
1607 + NET_AX25_T3_TIMEOUT=9,
1608 + NET_AX25_IDLE_TIMEOUT=10,
1609 + NET_AX25_N2=11,
1610 + NET_AX25_PACLEN=12,
1611 + NET_AX25_PROTOCOL=13,
1612 + NET_AX25_DAMA_SLAVE_TIMEOUT=14
1613 +};
1614 +
1615 +/* /proc/sys/net/rose */
1616 +enum {
1617 + NET_ROSE_RESTART_REQUEST_TIMEOUT=1,
1618 + NET_ROSE_CALL_REQUEST_TIMEOUT=2,
1619 + NET_ROSE_RESET_REQUEST_TIMEOUT=3,
1620 + NET_ROSE_CLEAR_REQUEST_TIMEOUT=4,
1621 + NET_ROSE_ACK_HOLD_BACK_TIMEOUT=5,
1622 + NET_ROSE_ROUTING_CONTROL=6,
1623 + NET_ROSE_LINK_FAIL_TIMEOUT=7,
1624 + NET_ROSE_MAX_VCS=8,
1625 + NET_ROSE_WINDOW_SIZE=9,
1626 + NET_ROSE_NO_ACTIVITY_TIMEOUT=10
1627 +};
1628 +
1629 +/* /proc/sys/net/x25 */
1630 +enum {
1631 + NET_X25_RESTART_REQUEST_TIMEOUT=1,
1632 + NET_X25_CALL_REQUEST_TIMEOUT=2,
1633 + NET_X25_RESET_REQUEST_TIMEOUT=3,
1634 + NET_X25_CLEAR_REQUEST_TIMEOUT=4,
1635 + NET_X25_ACK_HOLD_BACK_TIMEOUT=5
1636 +};
1637 +
1638 +/* /proc/sys/net/token-ring */
1639 +enum
1640 +{
1641 + NET_TR_RIF_TIMEOUT=1
1642 +};
1643 +
1644 +/* /proc/sys/net/decnet/ */
1645 +enum {
1646 + NET_DECNET_NODE_TYPE = 1,
1647 + NET_DECNET_NODE_ADDRESS = 2,
1648 + NET_DECNET_NODE_NAME = 3,
1649 + NET_DECNET_DEFAULT_DEVICE = 4,
1650 + NET_DECNET_TIME_WAIT = 5,
1651 + NET_DECNET_DN_COUNT = 6,
1652 + NET_DECNET_DI_COUNT = 7,
1653 + NET_DECNET_DR_COUNT = 8,
1654 + NET_DECNET_DST_GC_INTERVAL = 9,
1655 + NET_DECNET_CONF = 10,
1656 + NET_DECNET_NO_FC_MAX_CWND = 11,
1657 + NET_DECNET_DEBUG_LEVEL = 255
1658 +};
1659 +
1660 +/* /proc/sys/net/sctp */
1661 +enum {
1662 + NET_SCTP_RTO_INITIAL = 1,
1663 + NET_SCTP_RTO_MIN = 2,
1664 + NET_SCTP_RTO_MAX = 3,
1665 + NET_SCTP_RTO_ALPHA = 4,
1666 + NET_SCTP_RTO_BETA = 5,
1667 + NET_SCTP_VALID_COOKIE_LIFE = 6,
1668 + NET_SCTP_ASSOCIATION_MAX_RETRANS = 7,
1669 + NET_SCTP_PATH_MAX_RETRANS = 8,
1670 + NET_SCTP_MAX_INIT_RETRANSMITS = 9,
1671 + NET_SCTP_HB_INTERVAL = 10,
1672 + NET_SCTP_PRESERVE_ENABLE = 11,
1673 + NET_SCTP_MAX_BURST = 12,
1674 + NET_SCTP_ADDIP_ENABLE = 13,
1675 + NET_SCTP_PRSCTP_ENABLE = 14,
1676 +};
1677 +/* /proc/sys/net/khttpd/ */
1678 +enum {
1679 + NET_KHTTPD_DOCROOT = 1,
1680 + NET_KHTTPD_START = 2,
1681 + NET_KHTTPD_STOP = 3,
1682 + NET_KHTTPD_UNLOAD = 4,
1683 + NET_KHTTPD_CLIENTPORT = 5,
1684 + NET_KHTTPD_PERMREQ = 6,
1685 + NET_KHTTPD_PERMFORBID = 7,
1686 + NET_KHTTPD_LOGGING = 8,
1687 + NET_KHTTPD_SERVERPORT = 9,
1688 + NET_KHTTPD_DYNAMICSTRING= 10,
1689 + NET_KHTTPD_SLOPPYMIME = 11,
1690 + NET_KHTTPD_THREADS = 12,
1691 + NET_KHTTPD_MAXCONNECT = 13
1692 +};
1693 +
1694 +/* /proc/sys/net/decnet/conf/<dev> */
1695 +enum {
1696 + NET_DECNET_CONF_LOOPBACK = -2,
1697 + NET_DECNET_CONF_DDCMP = -3,
1698 + NET_DECNET_CONF_PPP = -4,
1699 + NET_DECNET_CONF_X25 = -5,
1700 + NET_DECNET_CONF_GRE = -6,
1701 + NET_DECNET_CONF_ETHER = -7
1702 +
1703 + /* ... and ifindex of devices */
1704 +};
1705 +
1706 +/* /proc/sys/net/decnet/conf/<dev>/ */
1707 +enum {
1708 + NET_DECNET_CONF_DEV_PRIORITY = 1,
1709 + NET_DECNET_CONF_DEV_T1 = 2,
1710 + NET_DECNET_CONF_DEV_T2 = 3,
1711 + NET_DECNET_CONF_DEV_T3 = 4,
1712 + NET_DECNET_CONF_DEV_FORWARDING = 5,
1713 + NET_DECNET_CONF_DEV_BLKSIZE = 6,
1714 + NET_DECNET_CONF_DEV_STATE = 7
1715 +};
1716 +
1717 +/* CTL_PROC names: */
1718 +
1719 +/* CTL_FS names: */
1720 +enum
1721 +{
1722 + FS_NRINODE=1, /* int:current number of allocated inodes */
1723 + FS_STATINODE=2,
1724 + FS_MAXINODE=3, /* int:maximum number of inodes that can be allocated */
1725 + FS_NRDQUOT=4, /* int:current number of allocated dquots */
1726 + /* was FS_MAXDQUOT */
1727 + FS_NRFILE=6, /* int:current number of allocated filedescriptors */
1728 + FS_MAXFILE=7, /* int:maximum number of filedescriptors that can be allocated */
1729 + FS_DENTRY=8,
1730 + FS_NRSUPER=9, /* int:current number of allocated super_blocks */
1731 + FS_MAXSUPER=10, /* int:maximum number of super_blocks that can be allocated */
1732 + FS_OVERFLOWUID=11, /* int: overflow UID */
1733 + FS_OVERFLOWGID=12, /* int: overflow GID */
1734 + FS_LEASES=13, /* int: leases enabled */
1735 + FS_DIR_NOTIFY=14, /* int: directory notification enabled */
1736 + FS_LEASE_TIME=15, /* int: maximum time to wait for a lease break */
1737 + FS_DQSTATS=16, /* dir: disc quota usage statistics and settings */
1738 + FS_XFS=17, /* struct: control xfs parameters */
1739 +};
1740 +
1741 +/* /proc/sys/fs/quota/ */
1742 +enum {
1743 + FS_DQ_LOOKUPS = 1,
1744 + FS_DQ_DROPS = 2,
1745 + FS_DQ_READS = 3,
1746 + FS_DQ_WRITES = 4,
1747 + FS_DQ_CACHE_HITS = 5,
1748 + FS_DQ_ALLOCATED = 6,
1749 + FS_DQ_FREE = 7,
1750 + FS_DQ_SYNCS = 8,
1751 + FS_DQ_WARNINGS = 9,
1752 +};
1753 +
1754 +/* CTL_DEBUG names: */
1755 +
1756 +/* CTL_DEV names: */
1757 +enum {
1758 + DEV_CDROM=1,
1759 + DEV_HWMON=2,
1760 + DEV_PARPORT=3,
1761 + DEV_RAID=4,
1762 + DEV_MAC_HID=5
1763 +};
1764 +
1765 +/* /proc/sys/dev/cdrom */
1766 +enum {
1767 + DEV_CDROM_INFO=1,
1768 + DEV_CDROM_AUTOCLOSE=2,
1769 + DEV_CDROM_AUTOEJECT=3,
1770 + DEV_CDROM_DEBUG=4,
1771 + DEV_CDROM_LOCK=5,
1772 + DEV_CDROM_CHECK_MEDIA=6
1773 +};
1774 +
1775 +/* /proc/sys/dev/parport */
1776 +enum {
1777 + DEV_PARPORT_DEFAULT=-3
1778 +};
1779 +
1780 +/* /proc/sys/dev/raid */
1781 +enum {
1782 + DEV_RAID_SPEED_LIMIT_MIN=1,
1783 + DEV_RAID_SPEED_LIMIT_MAX=2
1784 +};
1785 +
1786 +/* /proc/sys/dev/parport/default */
1787 +enum {
1788 + DEV_PARPORT_DEFAULT_TIMESLICE=1,
1789 + DEV_PARPORT_DEFAULT_SPINTIME=2
1790 +};
1791 +
1792 +/* /proc/sys/dev/parport/parport n */
1793 +enum {
1794 + DEV_PARPORT_SPINTIME=1,
1795 + DEV_PARPORT_BASE_ADDR=2,
1796 + DEV_PARPORT_IRQ=3,
1797 + DEV_PARPORT_DMA=4,
1798 + DEV_PARPORT_MODES=5,
1799 + DEV_PARPORT_DEVICES=6,
1800 + DEV_PARPORT_AUTOPROBE=16
1801 +};
1802 +
1803 +/* /proc/sys/dev/parport/parport n/devices/ */
1804 +enum {
1805 + DEV_PARPORT_DEVICES_ACTIVE=-3,
1806 +};
1807 +
1808 +/* /proc/sys/dev/parport/parport n/devices/device n */
1809 +enum {
1810 + DEV_PARPORT_DEVICE_TIMESLICE=1,
1811 +};
1812 +
1813 +/* /proc/sys/dev/mac_hid */
1814 +enum {
1815 + DEV_MAC_HID_KEYBOARD_SENDS_LINUX_KEYCODES=1,
1816 + DEV_MAC_HID_KEYBOARD_LOCK_KEYCODES=2,
1817 + DEV_MAC_HID_MOUSE_BUTTON_EMULATION=3,
1818 + DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE=4,
1819 + DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE=5,
1820 + DEV_MAC_HID_ADB_MOUSE_SENDS_KEYCODES=6
1821 +};
1822 +
1823 +/* /proc/sys/abi */
1824 +enum
1825 +{
1826 + ABI_DEFHANDLER_COFF=1, /* default handler for coff binaries */
1827 + ABI_DEFHANDLER_ELF=2, /* default handler for ELF binaries */
1828 + ABI_DEFHANDLER_LCALL7=3,/* default handler for procs using lcall7 */
1829 + ABI_DEFHANDLER_LIBCSO=4,/* default handler for an libc.so ELF interp */
1830 + ABI_TRACE=5, /* tracing flags */
1831 + ABI_FAKE_UTSNAME=6, /* fake target utsname information */
1832 +};
1833 +
1834 +#ifdef __KERNEL__
1835 +
1836 +extern asmlinkage long sys_sysctl(struct __sysctl_args *);
1837 +extern void sysctl_init(void);
1838 +
1839 +typedef struct ctl_table ctl_table;
1840 +
1841 +typedef int ctl_handler (ctl_table *table, int *name, int nlen,
1842 + void *oldval, size_t *oldlenp,
1843 + void *newval, size_t newlen,
1844 + void **context);
1845 +
1846 +typedef int proc_handler (ctl_table *ctl, int write, struct file * filp,
1847 + void *buffer, size_t *lenp);
1848 +
1849 +extern int proc_dostring(ctl_table *, int, struct file *,
1850 + void *, size_t *);
1851 +extern int proc_dointvec(ctl_table *, int, struct file *,
1852 + void *, size_t *);
1853 +extern int proc_dointvec_bset(ctl_table *, int, struct file *,
1854 + void *, size_t *);
1855 +extern int proc_dointvec_minmax(ctl_table *, int, struct file *,
1856 + void *, size_t *);
1857 +extern int proc_dointvec_jiffies(ctl_table *, int, struct file *,
1858 + void *, size_t *);
1859 +extern int proc_doulongvec_minmax(ctl_table *, int, struct file *,
1860 + void *, size_t *);
1861 +extern int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int,
1862 + struct file *, void *, size_t *);
1863 +
1864 +extern int do_sysctl (int *name, int nlen,
1865 + void *oldval, size_t *oldlenp,
1866 + void *newval, size_t newlen);
1867 +
1868 +extern int do_sysctl_strategy (ctl_table *table,
1869 + int *name, int nlen,
1870 + void *oldval, size_t *oldlenp,
1871 + void *newval, size_t newlen, void ** context);
1872 +
1873 +extern ctl_handler sysctl_string;
1874 +extern ctl_handler sysctl_intvec;
1875 +extern ctl_handler sysctl_jiffies;
1876 +
1877 +
1878 +/*
1879 + * Register a set of sysctl names by calling register_sysctl_table
1880 + * with an initialised array of ctl_table's. An entry with zero
1881 + * ctl_name terminates the table. table->de will be set up by the
1882 + * registration and need not be initialised in advance.
1883 + *
1884 + * sysctl names can be mirrored automatically under /proc/sys. The
1885 + * procname supplied controls /proc naming.
1886 + *
1887 + * The table's mode will be honoured both for sys_sysctl(2) and
1888 + * proc-fs access.
1889 + *
1890 + * Leaf nodes in the sysctl tree will be represented by a single file
1891 + * under /proc; non-leaf nodes will be represented by directories. A
1892 + * null procname disables /proc mirroring at this node.
1893 + *
1894 + * sysctl(2) can automatically manage read and write requests through
1895 + * the sysctl table. The data and maxlen fields of the ctl_table
1896 + * struct enable minimal validation of the values being written to be
1897 + * performed, and the mode field allows minimal authentication.
1898 + *
1899 + * More sophisticated management can be enabled by the provision of a
1900 + * strategy routine with the table entry. This will be called before
1901 + * any automatic read or write of the data is performed.
1902 + *
1903 + * The strategy routine may return:
1904 + * <0: Error occurred (error is passed to user process)
1905 + * 0: OK - proceed with automatic read or write.
1906 + * >0: OK - read or write has been done by the strategy routine, so
1907 + * return immediately.
1908 + *
1909 + * There must be a proc_handler routine for any terminal nodes
1910 + * mirrored under /proc/sys (non-terminals are handled by a built-in
1911 + * directory handler). Several default handlers are available to
1912 + * cover common cases.
1913 + */
1914 +
1915 +/* A sysctl table is an array of struct ctl_table: */
1916 +struct ctl_table
1917 +{
1918 + int ctl_name; /* Binary ID */
1919 + const char *procname; /* Text ID for /proc/sys, or zero */
1920 + void *data;
1921 + int maxlen;
1922 + mode_t mode;
1923 + ctl_table *child;
1924 + proc_handler *proc_handler; /* Callback for text formatting */
1925 + ctl_handler *strategy; /* Callback function for all r/w */
1926 + struct proc_dir_entry *de; /* /proc control block */
1927 + void *extra1;
1928 + void *extra2;
1929 +};
1930 +
1931 +/* struct ctl_table_header is used to maintain dynamic lists of
1932 + ctl_table trees. */
1933 +struct ctl_table_header
1934 +{
1935 + ctl_table *ctl_table;
1936 + struct list_head ctl_entry;
1937 +};
1938 +
1939 +struct ctl_table_header * register_sysctl_table(ctl_table * table,
1940 + int insert_at_head);
1941 +void unregister_sysctl_table(struct ctl_table_header * table);
1942 +
1943 +#else /* __KERNEL__ */
1944 +
1945 +#endif /* __KERNEL__ */
1946 +
1947 +#endif /* _LINUX_SYSCTL_H */
1948 diff -Nur linux-mips-cvs/net/8021q/vlan_dev.c linux-ebtables/net/8021q/vlan_dev.c
1949 --- linux-mips-cvs/net/8021q/vlan_dev.c 2004-11-29 18:47:19.000000000 +0100
1950 +++ linux-ebtables/net/8021q/vlan_dev.c 2005-02-07 05:52:50.000000000 +0100
1951 @@ -488,6 +488,10 @@
1952 stats->tx_packets++; /* for statics only */
1953 stats->tx_bytes += skb->len;
1954
1955 + skb->protocol = __constant_htons(ETH_P_8021Q);
1956 + skb->mac.raw -= VLAN_HLEN;
1957 + skb->nh.raw -= VLAN_HLEN;
1958 +
1959 skb->dev = VLAN_DEV_INFO(dev)->real_dev;
1960 dev_queue_xmit(skb);
1961
1962 diff -Nur linux-mips-cvs/net/Config.in linux-ebtables/net/Config.in
1963 --- linux-mips-cvs/net/Config.in 2005-01-09 20:34:04.000000000 +0100
1964 +++ linux-ebtables/net/Config.in 2005-02-07 05:52:50.000000000 +0100
1965 @@ -70,6 +70,9 @@
1966 source net/decnet/Config.in
1967 fi
1968 dep_tristate '802.1d Ethernet Bridging' CONFIG_BRIDGE $CONFIG_INET
1969 +if [ "$CONFIG_BRIDGE" != "n" -a "$CONFIG_NETFILTER" != "n" ]; then
1970 + source net/bridge/netfilter/Config.in
1971 +fi
1972 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
1973 tristate 'CCITT X.25 Packet Layer (EXPERIMENTAL)' CONFIG_X25
1974 tristate 'LAPB Data Link Driver (EXPERIMENTAL)' CONFIG_LAPB
1975 diff -Nur linux-mips-cvs/net/Config.in.orig linux-ebtables/net/Config.in.orig
1976 --- linux-mips-cvs/net/Config.in.orig 1970-01-01 01:00:00.000000000 +0100
1977 +++ linux-ebtables/net/Config.in.orig 2005-01-09 20:34:04.000000000 +0100
1978 @@ -0,0 +1,107 @@
1979 +#
1980 +# Network configuration
1981 +#
1982 +mainmenu_option next_comment
1983 +comment 'Networking options'
1984 +tristate 'Packet socket' CONFIG_PACKET
1985 +if [ "$CONFIG_PACKET" != "n" ]; then
1986 + bool ' Packet socket: mmapped IO' CONFIG_PACKET_MMAP
1987 +fi
1988 +
1989 +tristate 'Netlink device emulation' CONFIG_NETLINK_DEV
1990 +
1991 +bool 'Network packet filtering (replaces ipchains)' CONFIG_NETFILTER
1992 +if [ "$CONFIG_NETFILTER" = "y" ]; then
1993 + bool ' Network packet filtering debugging' CONFIG_NETFILTER_DEBUG
1994 +fi
1995 +bool 'Socket Filtering' CONFIG_FILTER
1996 +tristate 'Unix domain sockets' CONFIG_UNIX
1997 +bool 'TCP/IP networking' CONFIG_INET
1998 +if [ "$CONFIG_INET" = "y" ]; then
1999 + source net/ipv4/Config.in
2000 + if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
2001 +# IPv6 as module will cause a CRASH if you try to unload it
2002 + tristate ' The IPv6 protocol (EXPERIMENTAL)' CONFIG_IPV6
2003 + if [ "$CONFIG_IPV6" != "n" ]; then
2004 + source net/ipv6/Config.in
2005 + fi
2006 + fi
2007 + if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
2008 + source net/khttpd/Config.in
2009 + fi
2010 + if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
2011 + source net/sctp/Config.in
2012 + fi
2013 +fi
2014 +if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
2015 + tristate 'Asynchronous Transfer Mode (ATM) (EXPERIMENTAL)' CONFIG_ATM
2016 + if [ "$CONFIG_ATM" = "y" -o "$CONFIG_ATM" = "m" ]; then
2017 + if [ "$CONFIG_INET" = "y" ]; then
2018 + dep_tristate ' Classical IP over ATM' CONFIG_ATM_CLIP $CONFIG_ATM
2019 + if [ "$CONFIG_ATM_CLIP" != "n" ]; then
2020 + bool ' Do NOT send ICMP if no neighbour' CONFIG_ATM_CLIP_NO_ICMP
2021 + fi
2022 + fi
2023 + dep_tristate ' LAN Emulation (LANE) support' CONFIG_ATM_LANE $CONFIG_ATM
2024 + if [ "$CONFIG_INET" = "y" -a "$CONFIG_ATM_LANE" != "n" ]; then
2025 + tristate ' Multi-Protocol Over ATM (MPOA) support' CONFIG_ATM_MPOA
2026 + fi
2027 + dep_tristate ' RFC1483/2684 Bridged protocols' CONFIG_ATM_BR2684 $CONFIG_ATM
2028 + if [ "$CONFIG_ATM_BR2684" != "n" ]; then
2029 + bool ' Per-VC IP filter kludge' CONFIG_ATM_BR2684_IPFILTER
2030 + fi
2031 + fi
2032 +fi
2033 +tristate '802.1Q VLAN Support' CONFIG_VLAN_8021Q
2034 +
2035 +comment ' '
2036 +tristate 'The IPX protocol' CONFIG_IPX
2037 +if [ "$CONFIG_IPX" != "n" ]; then
2038 + source net/ipx/Config.in
2039 +fi
2040 +
2041 +tristate 'Appletalk protocol support' CONFIG_ATALK
2042 +if [ "$CONFIG_ATALK" != "n" ]; then
2043 + source drivers/net/appletalk/Config.in
2044 +fi
2045 +
2046 +tristate 'DECnet Support' CONFIG_DECNET
2047 +if [ "$CONFIG_DECNET" != "n" ]; then
2048 + source net/decnet/Config.in
2049 +fi
2050 +dep_tristate '802.1d Ethernet Bridging' CONFIG_BRIDGE $CONFIG_INET
2051 +if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
2052 + tristate 'CCITT X.25 Packet Layer (EXPERIMENTAL)' CONFIG_X25
2053 + tristate 'LAPB Data Link Driver (EXPERIMENTAL)' CONFIG_LAPB
2054 + bool '802.2 LLC (EXPERIMENTAL)' CONFIG_LLC
2055 + bool 'Frame Diverter (EXPERIMENTAL)' CONFIG_NET_DIVERT
2056 +# if [ "$CONFIG_LLC" = "y" ]; then
2057 +# bool ' Netbeui (EXPERIMENTAL)' CONFIG_NETBEUI
2058 +# fi
2059 + if [ "$CONFIG_INET" = "y" ]; then
2060 + tristate 'Acorn Econet/AUN protocols (EXPERIMENTAL)' CONFIG_ECONET
2061 + if [ "$CONFIG_ECONET" != "n" ]; then
2062 + bool ' AUN over UDP' CONFIG_ECONET_AUNUDP
2063 + bool ' Native Econet' CONFIG_ECONET_NATIVE
2064 + fi
2065 + fi
2066 + tristate 'WAN router' CONFIG_WAN_ROUTER
2067 + bool 'Fast switching (read help!)' CONFIG_NET_FASTROUTE
2068 + bool 'Forwarding between high speed interfaces' CONFIG_NET_HW_FLOWCONTROL
2069 +fi
2070 +
2071 +mainmenu_option next_comment
2072 +comment 'QoS and/or fair queueing'
2073 +bool 'QoS and/or fair queueing' CONFIG_NET_SCHED
2074 +if [ "$CONFIG_NET_SCHED" = "y" ]; then
2075 + source net/sched/Config.in
2076 +fi
2077 +#bool 'Network code profiler' CONFIG_NET_PROFILE
2078 +endmenu
2079 +
2080 +mainmenu_option next_comment
2081 +comment 'Network testing'
2082 +dep_tristate 'Packet Generator (USE WITH CAUTION)' CONFIG_NET_PKTGEN $CONFIG_PROC_FS
2083 +endmenu
2084 +
2085 +endmenu
2086 diff -Nur linux-mips-cvs/net/Makefile linux-ebtables/net/Makefile
2087 --- linux-mips-cvs/net/Makefile 2004-08-14 20:39:04.000000000 +0200
2088 +++ linux-ebtables/net/Makefile 2005-02-07 05:52:50.000000000 +0100
2089 @@ -7,7 +7,8 @@
2090
2091 O_TARGET := network.o
2092
2093 -mod-subdirs := ipv4/netfilter ipv6/netfilter ipx irda bluetooth atm netlink sched core sctp 802
2094 +mod-subdirs := ipv4/netfilter ipv6/netfilter bridge/netfilter ipx irda \
2095 + bluetooth atm netlink sched core sctp 802
2096 export-objs := netsyms.o
2097
2098 subdir-y := core ethernet
2099 @@ -27,6 +28,12 @@
2100 endif
2101 endif
2102
2103 +ifneq ($(CONFIG_BRIDGE),n)
2104 +ifneq ($(CONFIG_BRIDGE),)
2105 +subdir-$(CONFIG_BRIDGE) += bridge/netfilter
2106 +endif
2107 +endif
2108 +
2109 subdir-$(CONFIG_KHTTPD) += khttpd
2110 subdir-$(CONFIG_PACKET) += packet
2111 subdir-$(CONFIG_NET_SCHED) += sched
2112 diff -Nur linux-mips-cvs/net/bridge/Makefile linux-ebtables/net/bridge/Makefile
2113 --- linux-mips-cvs/net/bridge/Makefile 2001-01-10 18:18:10.000000000 +0100
2114 +++ linux-ebtables/net/bridge/Makefile 2005-02-07 05:52:50.000000000 +0100
2115 @@ -7,10 +7,17 @@
2116 #
2117 # Note 2! The CFLAGS definition is now in the main makefile...
2118
2119 +export-objs := br.o
2120 +
2121 O_TARGET := bridge.o
2122 obj-y := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \
2123 br_ioctl.o br_notify.o br_stp.o br_stp_bpdu.o \
2124 br_stp_if.o br_stp_timer.o
2125 +
2126 +ifeq ($(CONFIG_NETFILTER),y)
2127 +obj-y += br_netfilter.o
2128 +endif
2129 +
2130 obj-m := $(O_TARGET)
2131
2132 include $(TOPDIR)/Rules.make
2133 diff -Nur linux-mips-cvs/net/bridge/br.c linux-ebtables/net/bridge/br.c
2134 --- linux-mips-cvs/net/bridge/br.c 2004-08-14 20:39:04.000000000 +0200
2135 +++ linux-ebtables/net/bridge/br.c 2005-02-07 05:52:50.000000000 +0100
2136 @@ -30,6 +30,8 @@
2137 #include "../atm/lec.h"
2138 #endif
2139
2140 +int (*br_should_route_hook) (struct sk_buff **pskb) = NULL;
2141 +
2142 void br_dec_use_count()
2143 {
2144 MOD_DEC_USE_COUNT;
2145 @@ -44,6 +46,10 @@
2146 {
2147 printk(KERN_INFO "NET4: Ethernet Bridge 008 for NET4.0\n");
2148
2149 +#ifdef CONFIG_NETFILTER
2150 + if (br_netfilter_init())
2151 + return 1;
2152 +#endif
2153 br_handle_frame_hook = br_handle_frame;
2154 br_ioctl_hook = br_ioctl_deviceless_stub;
2155 #if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
2156 @@ -57,6 +63,9 @@
2157
2158 static void __exit br_deinit(void)
2159 {
2160 +#ifdef CONFIG_NETFILTER
2161 + br_netfilter_fini();
2162 +#endif
2163 unregister_netdevice_notifier(&br_device_notifier);
2164
2165 rtnl_lock();
2166 @@ -73,7 +82,7 @@
2167 #endif
2168 }
2169
2170 -EXPORT_NO_SYMBOLS;
2171 +EXPORT_SYMBOL(br_should_route_hook);
2172
2173 module_init(br_init)
2174 module_exit(br_deinit)
2175 diff -Nur linux-mips-cvs/net/bridge/br_forward.c linux-ebtables/net/bridge/br_forward.c
2176 --- linux-mips-cvs/net/bridge/br_forward.c 2003-11-17 02:07:47.000000000 +0100
2177 +++ linux-ebtables/net/bridge/br_forward.c 2005-02-07 05:52:50.000000000 +0100
2178 @@ -30,18 +30,21 @@
2179 return 1;
2180 }
2181
2182 -static int __dev_queue_push_xmit(struct sk_buff *skb)
2183 +int br_dev_queue_push_xmit(struct sk_buff *skb)
2184 {
2185 +#ifdef CONFIG_NETFILTER
2186 + nf_bridge_maybe_copy_header(skb);
2187 +#endif
2188 skb_push(skb, ETH_HLEN);
2189 dev_queue_xmit(skb);
2190
2191 return 0;
2192 }
2193
2194 -static int __br_forward_finish(struct sk_buff *skb)
2195 +int br_forward_finish(struct sk_buff *skb)
2196 {
2197 NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
2198 - __dev_queue_push_xmit);
2199 + br_dev_queue_push_xmit);
2200
2201 return 0;
2202 }
2203 @@ -49,8 +52,11 @@
2204 static void __br_deliver(struct net_bridge_port *to, struct sk_buff *skb)
2205 {
2206 skb->dev = to->dev;
2207 +#ifdef CONFIG_NETFILTER_DEBUG
2208 + skb->nf_debug = 0;
2209 +#endif
2210 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
2211 - __br_forward_finish);
2212 + br_forward_finish);
2213 }
2214
2215 static void __br_forward(struct net_bridge_port *to, struct sk_buff *skb)
2216 @@ -62,7 +68,7 @@
2217 skb->ip_summed = CHECKSUM_NONE;
2218
2219 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
2220 - __br_forward_finish);
2221 + br_forward_finish);
2222 }
2223
2224 /* called under bridge lock */
2225 diff -Nur linux-mips-cvs/net/bridge/br_input.c linux-ebtables/net/bridge/br_input.c
2226 --- linux-mips-cvs/net/bridge/br_input.c 2003-08-13 19:19:30.000000000 +0200
2227 +++ linux-ebtables/net/bridge/br_input.c 2005-02-07 05:52:50.000000000 +0100
2228 @@ -24,6 +24,9 @@
2229
2230 static int br_pass_frame_up_finish(struct sk_buff *skb)
2231 {
2232 +#ifdef CONFIG_NETFILTER_DEBUG
2233 + skb->nf_debug = 0;
2234 +#endif
2235 netif_rx(skb);
2236
2237 return 0;
2238 @@ -46,7 +49,7 @@
2239 br_pass_frame_up_finish);
2240 }
2241
2242 -static int br_handle_frame_finish(struct sk_buff *skb)
2243 +int br_handle_frame_finish(struct sk_buff *skb)
2244 {
2245 struct net_bridge *br;
2246 unsigned char *dest;
2247 @@ -112,7 +115,7 @@
2248 return 0;
2249 }
2250
2251 -void br_handle_frame(struct sk_buff *skb)
2252 +int br_handle_frame(struct sk_buff *skb)
2253 {
2254 struct net_bridge *br;
2255 unsigned char *dest;
2256 @@ -146,26 +149,35 @@
2257 goto handle_special_frame;
2258
2259 if (p->state == BR_STATE_FORWARDING) {
2260 + if (br_should_route_hook && br_should_route_hook(&skb)) {
2261 + read_unlock(&br->lock);
2262 + return -1;
2263 + }
2264 +
2265 + if (!memcmp(p->br->dev.dev_addr, dest, ETH_ALEN))
2266 + skb->pkt_type = PACKET_HOST;
2267 +
2268 NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
2269 br_handle_frame_finish);
2270 read_unlock(&br->lock);
2271 - return;
2272 + return 0;
2273 }
2274
2275 err:
2276 read_unlock(&br->lock);
2277 err_nolock:
2278 kfree_skb(skb);
2279 - return;
2280 + return 0;
2281
2282 handle_special_frame:
2283 if (!dest[5]) {
2284 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,NULL,
2285 br_stp_handle_bpdu);
2286 read_unlock(&br->lock);
2287 - return;
2288 + return 0;
2289 }
2290
2291 read_unlock(&br->lock);
2292 kfree_skb(skb);
2293 + return 0;
2294 }
2295 diff -Nur linux-mips-cvs/net/bridge/br_netfilter.c linux-ebtables/net/bridge/br_netfilter.c
2296 --- linux-mips-cvs/net/bridge/br_netfilter.c 1970-01-01 01:00:00.000000000 +0100
2297 +++ linux-ebtables/net/bridge/br_netfilter.c 2005-02-07 05:52:50.000000000 +0100
2298 @@ -0,0 +1,1103 @@
2299 +/*
2300 + * Handle firewalling
2301 + * Linux ethernet bridge
2302 + *
2303 + * Authors:
2304 + * Lennert Buytenhek <buytenh@gnu.org>
2305 + * Bart De Schuymer (maintainer) <bdschuym@pandora.be>
2306 + *
2307 + * Changes:
2308 + * Apr 29 2003: physdev module support (bdschuym)
2309 + * Jun 19 2003: let arptables see bridged ARP traffic (bdschuym)
2310 + * Oct 06 2003: filter encapsulated IP/ARP VLAN traffic on untagged bridge
2311 + * (bdschuym)
2312 + * Aug 28 2004: add IPv6 filtering (bdschuym)
2313 + *
2314 + * This program is free software; you can redistribute it and/or
2315 + * modify it under the terms of the GNU General Public License
2316 + * as published by the Free Software Foundation; either version
2317 + * 2 of the License, or (at your option) any later version.
2318 + *
2319 + * Lennert dedicates this file to Kerstin Wurdinger.
2320 + */
2321 +
2322 +#include <linux/module.h>
2323 +#include <linux/kernel.h>
2324 +#include <linux/ip.h>
2325 +#include <linux/netdevice.h>
2326 +#include <linux/skbuff.h>
2327 +#include <linux/if_ether.h>
2328 +#include <linux/if_vlan.h>
2329 +#include <linux/netfilter_bridge.h>
2330 +#include <linux/netfilter_ipv4.h>
2331 +#include <linux/netfilter_ipv6.h>
2332 +#include <linux/in_route.h>
2333 +#include <net/ip.h>
2334 +#include <net/ipv6.h>
2335 +#include <asm/uaccess.h>
2336 +#include <asm/checksum.h>
2337 +#include "br_private.h"
2338 +#ifdef CONFIG_SYSCTL
2339 +#include <linux/sysctl.h>
2340 +#endif
2341 +
2342 +#define skb_origaddr(skb) (((struct bridge_skb_cb *) \
2343 + (skb->nf_bridge->data))->daddr.ipv4)
2344 +#define store_orig_dstaddr(skb) (skb_origaddr(skb) = (skb)->nh.iph->daddr)
2345 +#define dnat_took_place(skb) (skb_origaddr(skb) != (skb)->nh.iph->daddr)
2346 +
2347 +#define has_bridge_parent(device) ((device)->br_port != NULL)
2348 +#define bridge_parent(device) (&((device)->br_port->br->dev))
2349 +
2350 +#ifdef CONFIG_SYSCTL
2351 +static struct ctl_table_header *brnf_sysctl_header;
2352 +static int brnf_call_iptables = 1;
2353 +static int brnf_call_ip6tables = 1;
2354 +static int brnf_call_arptables = 1;
2355 +static int brnf_filter_vlan_tagged = 1;
2356 +#else
2357 +#define brnf_filter_vlan_tagged 1
2358 +#endif
2359 +
2360 +#define IS_VLAN_IP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
2361 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IP) && \
2362 + brnf_filter_vlan_tagged)
2363 +#define IS_VLAN_IPV6 (skb->protocol == __constant_htons(ETH_P_8021Q) && \
2364 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IPV6) && \
2365 + brnf_filter_vlan_tagged)
2366 +/*
2367 +#define IS_VLAN_ARP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
2368 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_ARP) && \
2369 + brnf_filter_vlan_tagged)
2370 +*/
2371 +
2372 +/* We need these fake structures to make netfilter happy --
2373 + * lots of places assume that skb->dst != NULL, which isn't
2374 + * all that unreasonable.
2375 + *
2376 + * Currently, we fill in the PMTU entry because netfilter
2377 + * refragmentation needs it, and the rt_flags entry because
2378 + * ipt_REJECT needs it. Future netfilter modules might
2379 + * require us to fill additional fields.
2380 + */
2381 +static struct net_device __fake_net_device = {
2382 + .hard_header_len = ETH_HLEN
2383 +};
2384 +
2385 +static struct rtable __fake_rtable = {
2386 + u: {
2387 + dst: {
2388 + __refcnt: ATOMIC_INIT(1),
2389 + dev: &__fake_net_device,
2390 + pmtu: 1500
2391 + }
2392 + },
2393 +
2394 + rt_flags: 0
2395 +};
2396 +
2397 +
2398 +/* PF_BRIDGE/PRE_ROUTING *********************************************/
2399 +/* Undo the changes made for ip6tables PREROUTING and continue the
2400 + * bridge PRE_ROUTING hook. */
2401 +static int br_nf_pre_routing_finish_ipv6(struct sk_buff *skb)
2402 +{
2403 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
2404 +
2405 +#ifdef CONFIG_NETFILTER_DEBUG
2406 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
2407 +#endif
2408 +
2409 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
2410 + skb->pkt_type = PACKET_OTHERHOST;
2411 + nf_bridge->mask ^= BRNF_PKT_TYPE;
2412 + }
2413 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
2414 +
2415 + skb->dst = (struct dst_entry *)&__fake_rtable;
2416 + dst_hold(skb->dst);
2417 +
2418 + skb->dev = nf_bridge->physindev;
2419 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2420 + skb_push(skb, VLAN_HLEN);
2421 + skb->nh.raw -= VLAN_HLEN;
2422 + }
2423 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
2424 + br_handle_frame_finish, 1);
2425 +
2426 + return 0;
2427 +}
2428 +
2429 +static void __br_dnat_complain(void)
2430 +{
2431 + static unsigned long last_complaint;
2432 +
2433 + if (jiffies - last_complaint >= 5 * HZ) {
2434 + printk(KERN_WARNING "Performing cross-bridge DNAT requires IP "
2435 + "forwarding to be enabled\n");
2436 + last_complaint = jiffies;
2437 + }
2438 +}
2439 +
2440 +
2441 +/* This requires some explaining. If DNAT has taken place,
2442 + * we will need to fix up the destination Ethernet address,
2443 + * and this is a tricky process.
2444 + *
2445 + * There are two cases to consider:
2446 + * 1. The packet was DNAT'ed to a device in the same bridge
2447 + * port group as it was received on. We can still bridge
2448 + * the packet.
2449 + * 2. The packet was DNAT'ed to a different device, either
2450 + * a non-bridged device or another bridge port group.
2451 + * The packet will need to be routed.
2452 + *
2453 + * The correct way of distinguishing between these two cases is to
2454 + * call ip_route_input() and to look at skb->dst->dev, which is
2455 + * changed to the destination device if ip_route_input() succeeds.
2456 + *
2457 + * Let us first consider the case that ip_route_input() succeeds:
2458 + *
2459 + * If skb->dst->dev equals the logical bridge device the packet
2460 + * came in on, we can consider this bridging. We then call
2461 + * skb->dst->output() which will make the packet enter br_nf_local_out()
2462 + * not much later. In that function it is assured that the iptables
2463 + * FORWARD chain is traversed for the packet.
2464 + *
2465 + * Otherwise, the packet is considered to be routed and we just
2466 + * change the destination MAC address so that the packet will
2467 + * later be passed up to the IP stack to be routed.
2468 + *
2469 + * Let us now consider the case that ip_route_input() fails:
2470 + *
2471 + * After a "echo '0' > /proc/sys/net/ipv4/ip_forward" ip_route_input()
2472 + * will fail, while __ip_route_output_key() will return success. The source
2473 + * address for __ip_route_output_key() is set to zero, so __ip_route_output_key
2474 + * thinks we're handling a locally generated packet and won't care
2475 + * if IP forwarding is allowed. We send a warning message to the users's
2476 + * log telling her to put IP forwarding on.
2477 + *
2478 + * ip_route_input() will also fail if there is no route available.
2479 + * In that case we just drop the packet.
2480 + *
2481 + * --Lennert, 20020411
2482 + * --Bart, 20020416 (updated)
2483 + * --Bart, 20021007 (updated)
2484 + */
2485 +
2486 +static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
2487 +{
2488 +#ifdef CONFIG_NETFILTER_DEBUG
2489 + skb->nf_debug |= (1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_FORWARD);
2490 +#endif
2491 +
2492 + if (skb->pkt_type == PACKET_OTHERHOST) {
2493 + skb->pkt_type = PACKET_HOST;
2494 + skb->nf_bridge->mask |= BRNF_PKT_TYPE;
2495 + }
2496 + skb->nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
2497 +
2498 + skb->dev = bridge_parent(skb->dev);
2499 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2500 + skb_pull(skb, VLAN_HLEN);
2501 + skb->nh.raw += VLAN_HLEN;
2502 + }
2503 + skb->dst->output(skb);
2504 + return 0;
2505 +}
2506 +
2507 +static int br_nf_pre_routing_finish(struct sk_buff *skb)
2508 +{
2509 + struct net_device *dev = skb->dev;
2510 + struct iphdr *iph = skb->nh.iph;
2511 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
2512 +
2513 +#ifdef CONFIG_NETFILTER_DEBUG
2514 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
2515 +#endif
2516 +
2517 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
2518 + skb->pkt_type = PACKET_OTHERHOST;
2519 + nf_bridge->mask ^= BRNF_PKT_TYPE;
2520 + }
2521 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
2522 +
2523 + if (dnat_took_place(skb)) {
2524 + if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos,
2525 + dev)) {
2526 + struct rtable *rt;
2527 +
2528 + if (!ip_route_output(&rt, iph->daddr, 0, iph->tos, 0)) {
2529 + /* Bridged-and-DNAT'ed traffic doesn't
2530 + * require ip_forwarding.
2531 + */
2532 + if (((struct dst_entry *)rt)->dev == dev) {
2533 + skb->dst = (struct dst_entry *)rt;
2534 + goto bridged_dnat;
2535 + }
2536 + __br_dnat_complain();
2537 + dst_release((struct dst_entry *)rt);
2538 + }
2539 + kfree_skb(skb);
2540 + return 0;
2541 + } else {
2542 + if (skb->dst->dev == dev) {
2543 +bridged_dnat:
2544 + /* Tell br_nf_local_out this is a
2545 + * bridged frame
2546 + */
2547 + nf_bridge->mask |= BRNF_BRIDGED_DNAT;
2548 + skb->dev = nf_bridge->physindev;
2549 + if (skb->protocol ==
2550 + __constant_htons(ETH_P_8021Q)) {
2551 + skb_push(skb, VLAN_HLEN);
2552 + skb->nh.raw -= VLAN_HLEN;
2553 + }
2554 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING,
2555 + skb, skb->dev, NULL,
2556 + br_nf_pre_routing_finish_bridge,
2557 + 1);
2558 + return 0;
2559 + }
2560 + memcpy(skb->mac.ethernet->h_dest, dev->dev_addr,
2561 + ETH_ALEN);
2562 + skb->pkt_type = PACKET_HOST;
2563 + }
2564 + } else {
2565 + skb->dst = (struct dst_entry *)&__fake_rtable;
2566 + dst_hold(skb->dst);
2567 + }
2568 +
2569 + skb->dev = nf_bridge->physindev;
2570 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2571 + skb_push(skb, VLAN_HLEN);
2572 + skb->nh.raw -= VLAN_HLEN;
2573 + }
2574 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
2575 + br_handle_frame_finish, 1);
2576 +
2577 + return 0;
2578 +}
2579 +
2580 +/* Some common code for IPv4/IPv6 */
2581 +static void setup_pre_routing(struct sk_buff *skb)
2582 +{
2583 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
2584 +
2585 + if (skb->pkt_type == PACKET_OTHERHOST) {
2586 + skb->pkt_type = PACKET_HOST;
2587 + nf_bridge->mask |= BRNF_PKT_TYPE;
2588 + }
2589 +
2590 + nf_bridge->mask |= BRNF_NF_BRIDGE_PREROUTING;
2591 + nf_bridge->physindev = skb->dev;
2592 + skb->dev = bridge_parent(skb->dev);
2593 +}
2594 +
2595 +/* We only check the length. A bridge shouldn't do any hop-by-hop stuff anyway */
2596 +static int check_hbh_len(struct sk_buff *skb)
2597 +{
2598 + unsigned char *raw = (u8*)(skb->nh.ipv6h+1);
2599 + u32 pkt_len;
2600 + int off = raw - skb->nh.raw;
2601 + int len = (raw[1]+1)<<3;
2602 +
2603 + if ((raw + len) - skb->data > skb_headlen(skb))
2604 + goto bad;
2605 +
2606 + off += 2;
2607 + len -= 2;
2608 +
2609 + while (len > 0) {
2610 + int optlen = raw[off+1]+2;
2611 +
2612 + switch (skb->nh.raw[off]) {
2613 + case IPV6_TLV_PAD0:
2614 + optlen = 1;
2615 + break;
2616 +
2617 + case IPV6_TLV_PADN:
2618 + break;
2619 +
2620 + case IPV6_TLV_JUMBO:
2621 + if (skb->nh.raw[off+1] != 4 || (off&3) != 2)
2622 + goto bad;
2623 +
2624 + pkt_len = ntohl(*(u32*)(skb->nh.raw+off+2));
2625 +
2626 + if (pkt_len > skb->len - sizeof(struct ipv6hdr))
2627 + goto bad;
2628 + if (pkt_len + sizeof(struct ipv6hdr) < skb->len) {
2629 + if (__pskb_trim(skb,
2630 + pkt_len + sizeof(struct ipv6hdr)))
2631 + goto bad;
2632 + if (skb->ip_summed == CHECKSUM_HW)
2633 + skb->ip_summed = CHECKSUM_NONE;
2634 + }
2635 + break;
2636 + default:
2637 + if (optlen > len)
2638 + goto bad;
2639 + break;
2640 + }
2641 + off += optlen;
2642 + len -= optlen;
2643 + }
2644 + if (len == 0)
2645 + return 0;
2646 +bad:
2647 + return -1;
2648 +
2649 +}
2650 +
2651 +/* Replicate the checks that IPv6 does on packet reception and pass the packet
2652 + * to ip6tables, which doesn't support NAT, so things are fairly simple. */
2653 +static unsigned int br_nf_pre_routing_ipv6(unsigned int hook,
2654 + struct sk_buff *skb, const struct net_device *in,
2655 + const struct net_device *out, int (*okfn)(struct sk_buff *))
2656 +{
2657 + struct ipv6hdr *hdr;
2658 + u32 pkt_len;
2659 + struct nf_bridge_info *nf_bridge;
2660 +
2661 + if (skb->len < sizeof(struct ipv6hdr))
2662 + goto inhdr_error;
2663 +
2664 + if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
2665 + goto inhdr_error;
2666 +
2667 + hdr = skb->nh.ipv6h;
2668 +
2669 + if (hdr->version != 6)
2670 + goto inhdr_error;
2671 +
2672 + pkt_len = ntohs(hdr->payload_len);
2673 +
2674 + if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) {
2675 + if (pkt_len + sizeof(struct ipv6hdr) > skb->len)
2676 + goto inhdr_error;
2677 + if (pkt_len + sizeof(struct ipv6hdr) < skb->len) {
2678 + if (__pskb_trim(skb, pkt_len + sizeof(struct ipv6hdr)))
2679 + goto inhdr_error;
2680 + if (skb->ip_summed == CHECKSUM_HW)
2681 + skb->ip_summed = CHECKSUM_NONE;
2682 + }
2683 + }
2684 + if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb))
2685 + goto inhdr_error;
2686 +
2687 +#ifdef CONFIG_NETFILTER_DEBUG
2688 + skb->nf_debug ^= (1 << NF_IP6_PRE_ROUTING);
2689 +#endif
2690 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
2691 + return NF_DROP;
2692 + setup_pre_routing(skb);
2693 +
2694 + NF_HOOK(PF_INET6, NF_IP6_PRE_ROUTING, skb, skb->dev, NULL,
2695 + br_nf_pre_routing_finish_ipv6);
2696 +
2697 + return NF_STOLEN;
2698 +
2699 +inhdr_error:
2700 + return NF_DROP;
2701 +}
2702 +
2703 +/* Direct IPv6 traffic to br_nf_pre_routing_ipv6.
2704 + * Replicate the checks that IPv4 does on packet reception.
2705 + * Set skb->dev to the bridge device (i.e. parent of the
2706 + * receiving device) to make netfilter happy, the REDIRECT
2707 + * target in particular. Save the original destination IP
2708 + * address to be able to detect DNAT afterwards.
2709 + */
2710 +static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
2711 + const struct net_device *in, const struct net_device *out,
2712 + int (*okfn)(struct sk_buff *))
2713 +{
2714 + struct iphdr *iph;
2715 + __u32 len;
2716 + struct sk_buff *skb = *pskb;
2717 + struct nf_bridge_info *nf_bridge;
2718 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)
2719 + ((*pskb)->mac.ethernet);
2720 +
2721 + if (skb->protocol == __constant_htons(ETH_P_IPV6) || IS_VLAN_IPV6) {
2722 +#ifdef CONFIG_SYSCTL
2723 + if (!brnf_call_ip6tables)
2724 + return NF_ACCEPT;
2725 +#endif
2726 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
2727 + goto out;
2728 +
2729 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2730 + skb_pull(skb, VLAN_HLEN);
2731 + (skb)->nh.raw += VLAN_HLEN;
2732 + }
2733 + return br_nf_pre_routing_ipv6(hook, skb, in, out, okfn);
2734 + }
2735 +
2736 +#ifdef CONFIG_SYSCTL
2737 + if (!brnf_call_iptables)
2738 + return NF_ACCEPT;
2739 +#endif
2740 +
2741 + if (skb->protocol != __constant_htons(ETH_P_IP) && !IS_VLAN_IP)
2742 + return NF_ACCEPT;
2743 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
2744 + goto out;
2745 +
2746 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2747 + skb_pull(skb, VLAN_HLEN);
2748 + (skb)->nh.raw += VLAN_HLEN;
2749 + }
2750 +
2751 + if (!pskb_may_pull(skb, sizeof(struct iphdr)))
2752 + goto inhdr_error;
2753 +
2754 + iph = skb->nh.iph;
2755 + if (iph->ihl < 5 || iph->version != 4)
2756 + goto inhdr_error;
2757 +
2758 + if (!pskb_may_pull(skb, 4*iph->ihl))
2759 + goto inhdr_error;
2760 +
2761 + iph = skb->nh.iph;
2762 + if (ip_fast_csum((__u8 *)iph, iph->ihl) != 0)
2763 + goto inhdr_error;
2764 +
2765 + len = ntohs(iph->tot_len);
2766 + if (skb->len < len || len < 4*iph->ihl)
2767 + goto inhdr_error;
2768 +
2769 + if (skb->len > len) {
2770 + __pskb_trim(skb, len);
2771 + if (skb->ip_summed == CHECKSUM_HW)
2772 + skb->ip_summed = CHECKSUM_NONE;
2773 + }
2774 +
2775 +#ifdef CONFIG_NETFILTER_DEBUG
2776 + skb->nf_debug ^= (1 << NF_IP_PRE_ROUTING);
2777 +#endif
2778 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
2779 + return NF_DROP;
2780 +
2781 + setup_pre_routing(skb);
2782 + store_orig_dstaddr(skb);
2783 +
2784 + NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL,
2785 + br_nf_pre_routing_finish);
2786 +
2787 + return NF_STOLEN;
2788 +
2789 +inhdr_error:
2790 +// IP_INC_STATS_BH(IpInHdrErrors);
2791 +out:
2792 + return NF_DROP;
2793 +}
2794 +
2795 +
2796 +/* PF_BRIDGE/LOCAL_IN ************************************************/
2797 +/* The packet is locally destined, which requires a real
2798 + * dst_entry, so detach the fake one. On the way up, the
2799 + * packet would pass through PRE_ROUTING again (which already
2800 + * took place when the packet entered the bridge), but we
2801 + * register an IPv4 PRE_ROUTING 'sabotage' hook that will
2802 + * prevent this from happening.
2803 + */
2804 +static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff **pskb,
2805 + const struct net_device *in, const struct net_device *out,
2806 + int (*okfn)(struct sk_buff *))
2807 +{
2808 + struct sk_buff *skb = *pskb;
2809 +
2810 + if (skb->dst == (struct dst_entry *)&__fake_rtable) {
2811 + dst_release(skb->dst);
2812 + skb->dst = NULL;
2813 + }
2814 +
2815 + return NF_ACCEPT;
2816 +}
2817 +
2818 +/* PF_BRIDGE/FORWARD *************************************************/
2819 +static int br_nf_forward_finish(struct sk_buff *skb)
2820 +{
2821 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
2822 + struct net_device *in;
2823 +/* struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);*/
2824 +
2825 +#ifdef CONFIG_NETFILTER_DEBUG
2826 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
2827 +#endif
2828 +
2829 +/* if (skb->protocol != __constant_htons(ETH_P_ARP) && !IS_VLAN_ARP) {*/
2830 + in = nf_bridge->physindev;
2831 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
2832 + skb->pkt_type = PACKET_OTHERHOST;
2833 + nf_bridge->mask ^= BRNF_PKT_TYPE;
2834 + }
2835 +/* } else {
2836 + in = *((struct net_device **)(skb->cb));
2837 + }*/
2838 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2839 + skb_push(skb, VLAN_HLEN);
2840 + skb->nh.raw -= VLAN_HLEN;
2841 + }
2842 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_FORWARD, skb, in,
2843 + skb->dev, br_forward_finish, 1);
2844 + return 0;
2845 +}
2846 +
2847 +/* This is the 'purely bridged' case. For IP, we pass the packet to
2848 + * netfilter with indev and outdev set to the bridge device,
2849 + * but we are still able to filter on the 'real' indev/outdev
2850 + * because of the ipt_physdev.c module. For ARP, indev and outdev are the
2851 + * bridge ports.
2852 + */
2853 +static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb,
2854 + const struct net_device *in, const struct net_device *out,
2855 + int (*okfn)(struct sk_buff *))
2856 +{
2857 + struct sk_buff *skb = *pskb;
2858 + struct nf_bridge_info *nf_bridge;
2859 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
2860 + int pf;
2861 +
2862 + if (!skb->nf_bridge)
2863 + return NF_ACCEPT;
2864 +
2865 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
2866 + pf = PF_INET;
2867 + else
2868 + pf = PF_INET6;
2869 +
2870 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2871 + skb_pull(*pskb, VLAN_HLEN);
2872 + (*pskb)->nh.raw += VLAN_HLEN;
2873 + }
2874 +
2875 +#ifdef CONFIG_NETFILTER_DEBUG
2876 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
2877 +#endif
2878 + nf_bridge = skb->nf_bridge;
2879 + if (skb->pkt_type == PACKET_OTHERHOST) {
2880 + skb->pkt_type = PACKET_HOST;
2881 + nf_bridge->mask |= BRNF_PKT_TYPE;
2882 + }
2883 +
2884 + /* The physdev module checks on this */
2885 + nf_bridge->mask |= BRNF_BRIDGED;
2886 + nf_bridge->physoutdev = skb->dev;
2887 +
2888 + NF_HOOK(pf, NF_IP_FORWARD, skb, bridge_parent(in),
2889 + bridge_parent(out), br_nf_forward_finish);
2890 +
2891 + return NF_STOLEN;
2892 +}
2893 +
2894 +/*
2895 +static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb,
2896 + const struct net_device *in, const struct net_device *out,
2897 + int (*okfn)(struct sk_buff *))
2898 +{
2899 + struct sk_buff *skb = *pskb;
2900 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
2901 + struct net_device **d = (struct net_device **)(skb->cb);
2902 +
2903 + if (!brnf_call_arptables)
2904 + return NF_ACCEPT;
2905 +
2906 + if (skb->protocol != __constant_htons(ETH_P_ARP)) {
2907 + if (!IS_VLAN_ARP)
2908 + return NF_ACCEPT;
2909 + skb_pull(*pskb, VLAN_HLEN);
2910 + (*pskb)->nh.raw += VLAN_HLEN;
2911 + }
2912 +
2913 +#ifdef CONFIG_NETFILTER_DEBUG
2914 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
2915 +#endif
2916 +
2917 + if (skb->nh.arph->ar_pln != 4) {
2918 + if (IS_VLAN_ARP) {
2919 + skb_push(*pskb, VLAN_HLEN);
2920 + (*pskb)->nh.raw -= VLAN_HLEN;
2921 + }
2922 + return NF_ACCEPT;
2923 + }
2924 + *d = (struct net_device *)in;
2925 + NF_HOOK(NF_ARP, NF_ARP_FORWARD, skb, (struct net_device *)in,
2926 + (struct net_device *)out, br_nf_forward_finish);
2927 +
2928 + return NF_STOLEN;
2929 +}
2930 +*/
2931 +
2932 +/* PF_BRIDGE/LOCAL_OUT ***********************************************/
2933 +static int br_nf_local_out_finish(struct sk_buff *skb)
2934 +{
2935 +#ifdef CONFIG_NETFILTER_DEBUG
2936 + skb->nf_debug &= ~(1 << NF_BR_LOCAL_OUT);
2937 +#endif
2938 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2939 + skb_push(skb, VLAN_HLEN);
2940 + skb->nh.raw -= VLAN_HLEN;
2941 + }
2942 +
2943 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
2944 + br_forward_finish, NF_BR_PRI_FIRST + 1);
2945 +
2946 + return 0;
2947 +}
2948 +
2949 +
2950 +/* This function sees both locally originated IP packets and forwarded
2951 + * IP packets (in both cases the destination device is a bridge
2952 + * device). It also sees bridged-and-DNAT'ed packets.
2953 + * To be able to filter on the physical bridge devices (with the ipt_physdev.c
2954 + * module), we steal packets destined to a bridge device away from the
2955 + * PF_INET/FORWARD and PF_INET/OUTPUT hook functions, and give them back later,
2956 + * when we have determined the real output device. This is done in here.
2957 + *
2958 + * If (nf_bridge->mask & BRNF_BRIDGED_DNAT) then the packet is bridged
2959 + * and we fake the PF_BRIDGE/FORWARD hook. The function br_nf_forward()
2960 + * will then fake the PF_INET/FORWARD hook. br_nf_local_out() has priority
2961 + * NF_BR_PRI_FIRST, so no relevant PF_BRIDGE/INPUT functions have been nor
2962 + * will be executed.
2963 + * Otherwise, if nf_bridge->physindev is NULL, the bridge-nf code never touched
2964 + * this packet before, and so the packet was locally originated. We fake
2965 + * the PF_INET/LOCAL_OUT hook.
2966 + * Finally, if nf_bridge->physindev isn't NULL, then the packet was IP routed,
2967 + * so we fake the PF_INET/FORWARD hook. ipv4_sabotage_out() makes sure
2968 + * even routed packets that didn't arrive on a bridge interface have their
2969 + * nf_bridge->physindev set.
2970 + */
2971 +
2972 +static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb,
2973 + const struct net_device *in, const struct net_device *out,
2974 + int (*okfn)(struct sk_buff *))
2975 +{
2976 + struct net_device *realindev, *realoutdev;
2977 + struct sk_buff *skb = *pskb;
2978 + struct nf_bridge_info *nf_bridge;
2979 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
2980 + int pf;
2981 +
2982 + if (!skb->nf_bridge)
2983 + return NF_ACCEPT;
2984 +
2985 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
2986 + pf = PF_INET;
2987 + else
2988 + pf = PF_INET6;
2989 +
2990 +#ifdef CONFIG_NETFILTER_DEBUG
2991 + /* Sometimes we get packets with NULL ->dst here (for example,
2992 + * running a dhcp client daemon triggers this). This should now
2993 + * be fixed, but let's keep the check around. */
2994 + if (skb->dst == NULL) {
2995 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
2996 + return NF_ACCEPT;
2997 + }
2998 +#endif
2999 +
3000 + nf_bridge = skb->nf_bridge;
3001 + nf_bridge->physoutdev = skb->dev;
3002 + realindev = nf_bridge->physindev;
3003 +
3004 + /* Bridged, take PF_BRIDGE/FORWARD.
3005 + * (see big note in front of br_nf_pre_routing_finish)
3006 + */
3007 + if (nf_bridge->mask & BRNF_BRIDGED_DNAT) {
3008 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
3009 + skb->pkt_type = PACKET_OTHERHOST;
3010 + nf_bridge->mask ^= BRNF_PKT_TYPE;
3011 + }
3012 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
3013 + skb_push(skb, VLAN_HLEN);
3014 + skb->nh.raw -= VLAN_HLEN;
3015 + }
3016 +
3017 + NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, realindev,
3018 + skb->dev, br_forward_finish);
3019 + goto out;
3020 + }
3021 + realoutdev = bridge_parent(skb->dev);
3022 +
3023 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
3024 + /* iptables should match -o br0.x */
3025 + if (nf_bridge->netoutdev)
3026 + realoutdev = nf_bridge->netoutdev;
3027 +#endif
3028 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
3029 + skb_pull(skb, VLAN_HLEN);
3030 + (*pskb)->nh.raw += VLAN_HLEN;
3031 + }
3032 + /* IP forwarded traffic has a physindev, locally
3033 + * generated traffic hasn't.
3034 + */
3035 + if (realindev != NULL) {
3036 + if (((nf_bridge->mask & BRNF_DONT_TAKE_PARENT) == 0) &&
3037 + has_bridge_parent(realindev))
3038 + realindev = bridge_parent(realindev);
3039 + NF_HOOK_THRESH(pf, NF_IP_FORWARD, skb, realindev,
3040 + realoutdev, okfn,
3041 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD + 1);
3042 + } else {
3043 +#ifdef CONFIG_NETFILTER_DEBUG
3044 + skb->nf_debug ^= (1 << NF_IP_LOCAL_OUT);
3045 +#endif
3046 +
3047 + NF_HOOK_THRESH(pf, NF_IP_LOCAL_OUT, skb, realindev,
3048 + realoutdev, okfn,
3049 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT + 1);
3050 + }
3051 +
3052 +out:
3053 + return NF_STOLEN;
3054 +}
3055 +
3056 +
3057 +/* PF_BRIDGE/POST_ROUTING ********************************************/
3058 +static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
3059 + const struct net_device *in, const struct net_device *out,
3060 + int (*okfn)(struct sk_buff *))
3061 +{
3062 + struct sk_buff *skb = *pskb;
3063 + struct nf_bridge_info *nf_bridge = (*pskb)->nf_bridge;
3064 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
3065 + struct net_device *realoutdev = bridge_parent(skb->dev);
3066 + int pf;
3067 +
3068 +#ifdef CONFIG_NETFILTER_DEBUG
3069 + /* Be very paranoid. This probably won't happen anymore, but let's
3070 + * keep the check just to be sure... */
3071 + if (skb->mac.raw < skb->head || skb->mac.raw + ETH_HLEN > skb->data) {
3072 + printk(KERN_CRIT "br_netfilter: Argh!! br_nf_post_routing: "
3073 + "bad mac.raw pointer.");
3074 + goto print_error;
3075 + }
3076 +#endif
3077 +
3078 + if (!nf_bridge)
3079 + return NF_ACCEPT;
3080 +
3081 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
3082 + pf = PF_INET;
3083 + else
3084 + pf = PF_INET6;
3085 +
3086 + /* Sometimes we get packets with NULL ->dst here (for example,
3087 + * running a dhcp client daemon triggers this).
3088 + */
3089 + if (skb->dst == NULL)
3090 + return NF_ACCEPT;
3091 +
3092 +#ifdef CONFIG_NETFILTER_DEBUG
3093 + /* Sometimes we get packets with NULL ->dst here (for example,
3094 + * running a dhcp client daemon triggers this). This should now
3095 + * be fixed, but let's keep the check around.
3096 + */
3097 + if (skb->dst == NULL) {
3098 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
3099 + goto print_error;
3100 + }
3101 +
3102 + skb->nf_debug ^= (1 << NF_IP_POST_ROUTING);
3103 +#endif
3104 +
3105 + /* We assume any code from br_dev_queue_push_xmit onwards doesn't care
3106 + * about the value of skb->pkt_type.
3107 + */
3108 + if (skb->pkt_type == PACKET_OTHERHOST) {
3109 + skb->pkt_type = PACKET_HOST;
3110 + nf_bridge->mask |= BRNF_PKT_TYPE;
3111 + }
3112 +
3113 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
3114 + skb_pull(skb, VLAN_HLEN);
3115 + skb->nh.raw += VLAN_HLEN;
3116 + }
3117 +
3118 + nf_bridge_save_header(skb);
3119 +
3120 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
3121 + if (nf_bridge->netoutdev)
3122 + realoutdev = nf_bridge->netoutdev;
3123 +#endif
3124 + NF_HOOK(pf, NF_IP_POST_ROUTING, skb, NULL,
3125 + realoutdev, br_dev_queue_push_xmit);
3126 +
3127 + return NF_STOLEN;
3128 +
3129 +#ifdef CONFIG_NETFILTER_DEBUG
3130 +print_error:
3131 + if (skb->dev != NULL) {
3132 + printk("[%s]", skb->dev->name);
3133 + if (has_bridge_parent(skb->dev))
3134 + printk("[%s]", bridge_parent(skb->dev)->name);
3135 + }
3136 + printk(" head:%p, raw:%p, data:%p\n", skb->head, skb->mac.raw,
3137 + skb->data);
3138 + return NF_ACCEPT;
3139 +#endif
3140 +}
3141 +
3142 +
3143 +/* IPv4/SABOTAGE *****************************************************/
3144 +
3145 +/* Don't hand locally destined packets to PF_INET/PRE_ROUTING
3146 + * for the second time.
3147 + */
3148 +static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff **pskb,
3149 + const struct net_device *in, const struct net_device *out,
3150 + int (*okfn)(struct sk_buff *))
3151 +{
3152 + if ((*pskb)->nf_bridge &&
3153 + !((*pskb)->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
3154 + okfn(*pskb);
3155 + return NF_STOLEN;
3156 + }
3157 +
3158 + return NF_ACCEPT;
3159 +}
3160 +
3161 +/* Postpone execution of PF_INET/FORWARD, PF_INET/LOCAL_OUT
3162 + * and PF_INET/POST_ROUTING until we have done the forwarding
3163 + * decision in the bridge code and have determined skb->physoutdev.
3164 + */
3165 +static unsigned int ip_sabotage_out(unsigned int hook, struct sk_buff **pskb,
3166 + const struct net_device *in, const struct net_device *out,
3167 + int (*okfn)(struct sk_buff *))
3168 +{
3169 + struct sk_buff *skb = *pskb;
3170 +
3171 + if ((out->hard_start_xmit == br_dev_xmit &&
3172 + okfn != br_nf_forward_finish &&
3173 + okfn != br_nf_local_out_finish &&
3174 + okfn != br_dev_queue_push_xmit)
3175 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
3176 + || ((out->priv_flags & IFF_802_1Q_VLAN) &&
3177 + VLAN_DEV_INFO(out)->real_dev->hard_start_xmit == br_dev_xmit)
3178 +#endif
3179 + ) {
3180 + struct nf_bridge_info *nf_bridge;
3181 +
3182 + if (!skb->nf_bridge) {
3183 +#ifdef CONFIG_SYSCTL
3184 + /* This code is executed while in the IP(v6) stack,
3185 + the version should be 4 or 6. We can't use
3186 + skb->protocol because that isn't set on
3187 + PF_INET(6)/LOCAL_OUT. */
3188 + struct iphdr *ip = skb->nh.iph;
3189 +
3190 + if (ip->version == 4 && !brnf_call_iptables)
3191 + return NF_ACCEPT;
3192 + else if (ip->version == 6 && !brnf_call_ip6tables)
3193 + return NF_ACCEPT;
3194 +#endif
3195 + if (hook == NF_IP_POST_ROUTING)
3196 + return NF_ACCEPT;
3197 + if (!nf_bridge_alloc(skb))
3198 + return NF_DROP;
3199 + }
3200 +
3201 + nf_bridge = skb->nf_bridge;
3202 +
3203 + /* This frame will arrive on PF_BRIDGE/LOCAL_OUT and we
3204 + * will need the indev then. For a brouter, the real indev
3205 + * can be a bridge port, so we make sure br_nf_local_out()
3206 + * doesn't use the bridge parent of the indev by using
3207 + * the BRNF_DONT_TAKE_PARENT mask.
3208 + */
3209 + if (hook == NF_IP_FORWARD && nf_bridge->physindev == NULL) {
3210 + nf_bridge->mask &= BRNF_DONT_TAKE_PARENT;
3211 + nf_bridge->physindev = (struct net_device *)in;
3212 + }
3213 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
3214 + /* the iptables outdev is br0.x, not br0 */
3215 + if (out->priv_flags & IFF_802_1Q_VLAN)
3216 + nf_bridge->netoutdev = (struct net_device *)out;
3217 +#endif
3218 + okfn(skb);
3219 + return NF_STOLEN;
3220 + }
3221 +
3222 + return NF_ACCEPT;
3223 +}
3224 +
3225 +/* For br_nf_local_out we need (prio = NF_BR_PRI_FIRST), to insure that innocent
3226 + * PF_BRIDGE/NF_BR_LOCAL_OUT functions don't get bridged traffic as input.
3227 + * For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because
3228 + * ip_refrag() can return NF_STOLEN.
3229 + */
3230 +static struct nf_hook_ops br_nf_ops[] = {
3231 + { .hook = br_nf_pre_routing,
3232 + .pf = PF_BRIDGE,
3233 + .hooknum = NF_BR_PRE_ROUTING,
3234 + .priority = NF_BR_PRI_BRNF, },
3235 + { .hook = br_nf_local_in,
3236 + .pf = PF_BRIDGE,
3237 + .hooknum = NF_BR_LOCAL_IN,
3238 + .priority = NF_BR_PRI_BRNF, },
3239 + { .hook = br_nf_forward_ip,
3240 + .pf = PF_BRIDGE,
3241 + .hooknum = NF_BR_FORWARD,
3242 + .priority = NF_BR_PRI_BRNF /*- 1*/, },
3243 +/* { .hook = br_nf_forward_arp,
3244 + .pf = PF_BRIDGE,
3245 + .hooknum = NF_BR_FORWARD,
3246 + .priority = NF_BR_PRI_BRNF, },*/
3247 + { .hook = br_nf_local_out,
3248 + .pf = PF_BRIDGE,
3249 + .hooknum = NF_BR_LOCAL_OUT,
3250 + .priority = NF_BR_PRI_FIRST, },
3251 + { .hook = br_nf_post_routing,
3252 + .pf = PF_BRIDGE,
3253 + .hooknum = NF_BR_POST_ROUTING,
3254 + .priority = NF_BR_PRI_LAST, },
3255 + { .hook = ip_sabotage_in,
3256 + .pf = PF_INET,
3257 + .hooknum = NF_IP_PRE_ROUTING,
3258 + .priority = NF_IP_PRI_FIRST, },
3259 + { .hook = ip_sabotage_in,
3260 + .pf = PF_INET6,
3261 + .hooknum = NF_IP6_PRE_ROUTING,
3262 + .priority = NF_IP6_PRI_FIRST, },
3263 + { .hook = ip_sabotage_out,
3264 + .pf = PF_INET,
3265 + .hooknum = NF_IP_FORWARD,
3266 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD, },
3267 + { .hook = ip_sabotage_out,
3268 + .pf = PF_INET6,
3269 + .hooknum = NF_IP6_FORWARD,
3270 + .priority = NF_IP6_PRI_BRIDGE_SABOTAGE_FORWARD, },
3271 + { .hook = ip_sabotage_out,
3272 + .pf = PF_INET,
3273 + .hooknum = NF_IP_LOCAL_OUT,
3274 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
3275 + { .hook = ip_sabotage_out,
3276 + .pf = PF_INET6,
3277 + .hooknum = NF_IP6_LOCAL_OUT,
3278 + .priority = NF_IP6_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
3279 + { .hook = ip_sabotage_out,
3280 + .pf = PF_INET,
3281 + .hooknum = NF_IP_POST_ROUTING,
3282 + .priority = NF_IP_PRI_FIRST, },
3283 + { .hook = ip_sabotage_out,
3284 + .pf = PF_INET6,
3285 + .hooknum = NF_IP6_POST_ROUTING,
3286 + .priority = NF_IP6_PRI_FIRST, },
3287 +};
3288 +
3289 +#ifdef CONFIG_SYSCTL
3290 +static
3291 +int brnf_sysctl_call_tables(ctl_table *ctl, int write, struct file * filp,
3292 + void *buffer, size_t *lenp)
3293 +{
3294 + int ret;
3295 +
3296 + ret = proc_dointvec(ctl, write, filp, buffer, lenp);
3297 +
3298 + if (write && *(int *)(ctl->data))
3299 + *(int *)(ctl->data) = 1;
3300 + return ret;
3301 +}
3302 +
3303 +static ctl_table brnf_table[] = {
3304 + {
3305 + .ctl_name = NET_BRIDGE_NF_CALL_ARPTABLES,
3306 + .procname = "bridge-nf-call-arptables",
3307 + .data = &brnf_call_arptables,
3308 + .maxlen = sizeof(int),
3309 + .mode = 0644,
3310 + .proc_handler = &brnf_sysctl_call_tables,
3311 + },
3312 + {
3313 + .ctl_name = NET_BRIDGE_NF_CALL_IPTABLES,
3314 + .procname = "bridge-nf-call-iptables",
3315 + .data = &brnf_call_iptables,
3316 + .maxlen = sizeof(int),
3317 + .mode = 0644,
3318 + .proc_handler = &brnf_sysctl_call_tables,
3319 + },
3320 + {
3321 + .ctl_name = NET_BRIDGE_NF_CALL_IP6TABLES,
3322 + .procname = "bridge-nf-call-ip6tables",
3323 + .data = &brnf_call_ip6tables,
3324 + .maxlen = sizeof(int),
3325 + .mode = 0644,
3326 + .proc_handler = &brnf_sysctl_call_tables,
3327 + },
3328 + {
3329 + .ctl_name = NET_BRIDGE_NF_FILTER_VLAN_TAGGED,
3330 + .procname = "bridge-nf-filter-vlan-tagged",
3331 + .data = &brnf_filter_vlan_tagged,
3332 + .maxlen = sizeof(int),
3333 + .mode = 0644,
3334 + .proc_handler = &brnf_sysctl_call_tables,
3335 + },
3336 + { .ctl_name = 0 }
3337 +};
3338 +
3339 +static ctl_table brnf_bridge_table[] = {
3340 + {
3341 + .ctl_name = NET_BRIDGE,
3342 + .procname = "bridge",
3343 + .mode = 0555,
3344 + .child = brnf_table,
3345 + },
3346 + { .ctl_name = 0 }
3347 +};
3348 +
3349 +static ctl_table brnf_net_table[] = {
3350 + {
3351 + .ctl_name = CTL_NET,
3352 + .procname = "net",
3353 + .mode = 0555,
3354 + .child = brnf_bridge_table,
3355 + },
3356 + { .ctl_name = 0 }
3357 +};
3358 +#endif
3359 +
3360 +int br_netfilter_init(void)
3361 +{
3362 + int i;
3363 +
3364 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++) {
3365 + int ret;
3366 +
3367 + if ((ret = nf_register_hook(&br_nf_ops[i])) >= 0)
3368 + continue;
3369 +
3370 + while (i--)
3371 + nf_unregister_hook(&br_nf_ops[i]);
3372 +
3373 + return ret;
3374 + }
3375 +
3376 +#ifdef CONFIG_SYSCTL
3377 + brnf_sysctl_header = register_sysctl_table(brnf_net_table, 0);
3378 + if (brnf_sysctl_header == NULL) {
3379 + printk(KERN_WARNING "br_netfilter: can't register to sysctl.\n");
3380 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++)
3381 + nf_unregister_hook(&br_nf_ops[i]);
3382 + return -EFAULT;
3383 + }
3384 +#endif
3385 +
3386 + printk(KERN_NOTICE "Bridge firewalling registered\n");
3387 +
3388 + return 0;
3389 +}
3390 +
3391 +void br_netfilter_fini(void)
3392 +{
3393 + int i;
3394 +
3395 + for (i = ARRAY_SIZE(br_nf_ops) - 1; i >= 0; i--)
3396 + nf_unregister_hook(&br_nf_ops[i]);
3397 +#ifdef CONFIG_SYSCTL
3398 + unregister_sysctl_table(brnf_sysctl_header);
3399 +#endif
3400 +
3401 +}
3402 diff -Nur linux-mips-cvs/net/bridge/br_private.h linux-ebtables/net/bridge/br_private.h
3403 --- linux-mips-cvs/net/bridge/br_private.h 2004-08-14 20:39:04.000000000 +0200
3404 +++ linux-ebtables/net/bridge/br_private.h 2005-02-07 05:52:50.000000000 +0100
3405 @@ -143,8 +143,10 @@
3406 /* br_forward.c */
3407 extern void br_deliver(struct net_bridge_port *to,
3408 struct sk_buff *skb);
3409 +extern int br_dev_queue_push_xmit(struct sk_buff *skb);
3410 extern void br_forward(struct net_bridge_port *to,
3411 struct sk_buff *skb);
3412 +extern int br_forward_finish(struct sk_buff *skb);
3413 extern void br_flood_deliver(struct net_bridge *br,
3414 struct sk_buff *skb,
3415 int clone);
3416 @@ -165,7 +167,8 @@
3417 int *ifindices);
3418
3419 /* br_input.c */
3420 -extern void br_handle_frame(struct sk_buff *skb);
3421 +extern int br_handle_frame_finish(struct sk_buff *skb);
3422 +extern int br_handle_frame(struct sk_buff *skb);
3423
3424 /* br_ioctl.c */
3425 extern int br_ioctl(struct net_bridge *br,
3426 @@ -175,6 +178,10 @@
3427 unsigned long arg2);
3428 extern int br_ioctl_deviceless_stub(unsigned long arg);
3429
3430 +/* br_netfilter.c */
3431 +extern int br_netfilter_init(void);
3432 +extern void br_netfilter_fini(void);
3433 +
3434 /* br_stp.c */
3435 extern int br_is_root_bridge(struct net_bridge *br);
3436 extern struct net_bridge_port *br_get_port(struct net_bridge *br,
3437 diff -Nur linux-mips-cvs/net/bridge/netfilter/Config.in linux-ebtables/net/bridge/netfilter/Config.in
3438 --- linux-mips-cvs/net/bridge/netfilter/Config.in 1970-01-01 01:00:00.000000000 +0100
3439 +++ linux-ebtables/net/bridge/netfilter/Config.in 2005-02-07 05:52:50.000000000 +0100
3440 @@ -0,0 +1,23 @@
3441 +#
3442 +# Bridge netfilter configuration
3443 +#
3444 +dep_tristate ' Bridge: ebtables' CONFIG_BRIDGE_NF_EBTABLES $CONFIG_BRIDGE
3445 +dep_tristate ' ebt: filter table support' CONFIG_BRIDGE_EBT_T_FILTER $CONFIG_BRIDGE_NF_EBTABLES
3446 +dep_tristate ' ebt: nat table support' CONFIG_BRIDGE_EBT_T_NAT $CONFIG_BRIDGE_NF_EBTABLES
3447 +dep_tristate ' ebt: broute table support' CONFIG_BRIDGE_EBT_BROUTE $CONFIG_BRIDGE_NF_EBTABLES
3448 +dep_tristate ' ebt: log support' CONFIG_BRIDGE_EBT_LOG $CONFIG_BRIDGE_NF_EBTABLES
3449 +dep_tristate ' ebt: ulog support' CONFIG_BRIDGE_EBT_LOG $CONFIG_BRIDGE_NF_EBTABLES
3450 +dep_tristate ' ebt: IP filter support' CONFIG_BRIDGE_EBT_IPF $CONFIG_BRIDGE_NF_EBTABLES
3451 +dep_tristate ' ebt: ARP filter support' CONFIG_BRIDGE_EBT_ARPF $CONFIG_BRIDGE_NF_EBTABLES
3452 +dep_tristate ' ebt: among filter support' CONFIG_BRIDGE_EBT_AMONG $CONFIG_BRIDGE_NF_EBTABLES
3453 +dep_tristate ' ebt: limit filter support' CONFIG_BRIDGE_EBT_LIMIT $CONFIG_BRIDGE_NF_EBTABLES
3454 +dep_tristate ' ebt: 802.1Q VLAN filter support' CONFIG_BRIDGE_EBT_VLANF $CONFIG_BRIDGE_NF_EBTABLES
3455 +dep_tristate ' ebt: 802.3 filter support' CONFIG_BRIDGE_EBT_802_3 $CONFIG_BRIDGE_NF_EBTABLES
3456 +dep_tristate ' ebt: packet type filter support' CONFIG_BRIDGE_EBT_PKTTYPE $CONFIG_BRIDGE_NF_EBTABLES
3457 +dep_tristate ' ebt: STP filter support' CONFIG_BRIDGE_EBT_STP $CONFIG_BRIDGE_NF_EBTABLES
3458 +dep_tristate ' ebt: mark filter support' CONFIG_BRIDGE_EBT_MARKF $CONFIG_BRIDGE_NF_EBTABLES
3459 +dep_tristate ' ebt: arp reply target support' CONFIG_BRIDGE_EBT_ARPREPLY $CONFIG_BRIDGE_NF_EBTABLES
3460 +dep_tristate ' ebt: snat target support' CONFIG_BRIDGE_EBT_SNAT $CONFIG_BRIDGE_NF_EBTABLES
3461 +dep_tristate ' ebt: dnat target support' CONFIG_BRIDGE_EBT_DNAT $CONFIG_BRIDGE_NF_EBTABLES
3462 +dep_tristate ' ebt: redirect target support' CONFIG_BRIDGE_EBT_REDIRECT $CONFIG_BRIDGE_NF_EBTABLES
3463 +dep_tristate ' ebt: mark target support' CONFIG_BRIDGE_EBT_MARK_T $CONFIG_BRIDGE_NF_EBTABLES
3464 diff -Nur linux-mips-cvs/net/bridge/netfilter/Makefile linux-ebtables/net/bridge/netfilter/Makefile
3465 --- linux-mips-cvs/net/bridge/netfilter/Makefile 1970-01-01 01:00:00.000000000 +0100
3466 +++ linux-ebtables/net/bridge/netfilter/Makefile 2005-02-07 05:52:50.000000000 +0100
3467 @@ -0,0 +1,34 @@
3468 +#
3469 +# Makefile for the netfilter modules on top of bridging.
3470 +#
3471 +# Note! Dependencies are done automagically by 'make dep', which also
3472 +# removes any old dependencies. DON'T put your own dependencies here
3473 +# unless it's something special (ie not a .c file).
3474 +#
3475 +# Note 2! The CFLAGS definition is now in the main makefile...
3476 +
3477 +O_TARGET := netfilter.o
3478 +
3479 +export-objs := ebtables.o
3480 +
3481 +obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o
3482 +obj-$(CONFIG_BRIDGE_EBT_T_FILTER) += ebtable_filter.o
3483 +obj-$(CONFIG_BRIDGE_EBT_T_NAT) += ebtable_nat.o
3484 +obj-$(CONFIG_BRIDGE_EBT_BROUTE) += ebtable_broute.o
3485 +obj-$(CONFIG_BRIDGE_EBT_802_3) += ebt_802_3.o
3486 +obj-$(CONFIG_BRIDGE_EBT_ARPF) += ebt_arp.o
3487 +obj-$(CONFIG_BRIDGE_EBT_AMONG) += ebt_among.o
3488 +obj-$(CONFIG_BRIDGE_EBT_IPF) += ebt_ip.o
3489 +obj-$(CONFIG_BRIDGE_EBT_LIMIT) += ebt_limit.o
3490 +obj-$(CONFIG_BRIDGE_EBT_MARKF) += ebt_mark_m.o
3491 +obj-$(CONFIG_BRIDGE_EBT_PKTTYPE) += ebt_pkttype.o
3492 +obj-$(CONFIG_BRIDGE_EBT_STP) += ebt_stp.o
3493 +obj-$(CONFIG_BRIDGE_EBT_VLANF) += ebt_vlan.o
3494 +obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_log.o
3495 +obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_ulog.o
3496 +obj-$(CONFIG_BRIDGE_EBT_ARPREPLY) += ebt_arpreply.o
3497 +obj-$(CONFIG_BRIDGE_EBT_DNAT) += ebt_dnat.o
3498 +obj-$(CONFIG_BRIDGE_EBT_MARK_T) += ebt_mark.o
3499 +obj-$(CONFIG_BRIDGE_EBT_REDIRECT) += ebt_redirect.o
3500 +obj-$(CONFIG_BRIDGE_EBT_SNAT) += ebt_snat.o
3501 +include $(TOPDIR)/Rules.make
3502 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_802_3.c linux-ebtables/net/bridge/netfilter/ebt_802_3.c
3503 --- linux-mips-cvs/net/bridge/netfilter/ebt_802_3.c 1970-01-01 01:00:00.000000000 +0100
3504 +++ linux-ebtables/net/bridge/netfilter/ebt_802_3.c 2005-02-07 05:52:50.000000000 +0100
3505 @@ -0,0 +1,74 @@
3506 +/*
3507 + * 802_3
3508 + *
3509 + * Author:
3510 + * Chris Vitale csv@bluetail.com
3511 + *
3512 + * May 2003
3513 + *
3514 + */
3515 +
3516 +#include <linux/netfilter_bridge/ebtables.h>
3517 +#include <linux/netfilter_bridge/ebt_802_3.h>
3518 +#include <linux/module.h>
3519 +
3520 +static int ebt_filter_802_3(const struct sk_buff *skb, const struct net_device *in,
3521 + const struct net_device *out, const void *data, unsigned int datalen)
3522 +{
3523 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
3524 + struct ebt_802_3_hdr *hdr = (struct ebt_802_3_hdr *)skb->mac.ethernet;
3525 + uint16_t type = hdr->llc.ui.ctrl & IS_UI ? hdr->llc.ui.type : hdr->llc.ni.type;
3526 +
3527 + if (info->bitmask & EBT_802_3_SAP) {
3528 + if (FWINV(info->sap != hdr->llc.ui.ssap, EBT_802_3_SAP))
3529 + return EBT_NOMATCH;
3530 + if (FWINV(info->sap != hdr->llc.ui.dsap, EBT_802_3_SAP))
3531 + return EBT_NOMATCH;
3532 + }
3533 +
3534 + if (info->bitmask & EBT_802_3_TYPE) {
3535 + if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
3536 + return EBT_NOMATCH;
3537 + if (FWINV(info->type != type, EBT_802_3_TYPE))
3538 + return EBT_NOMATCH;
3539 + }
3540 +
3541 + return EBT_MATCH;
3542 +}
3543 +
3544 +static struct ebt_match filter_802_3;
3545 +static int ebt_802_3_check(const char *tablename, unsigned int hookmask,
3546 + const struct ebt_entry *e, void *data, unsigned int datalen)
3547 +{
3548 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
3549 +
3550 + if (datalen != EBT_ALIGN(sizeof(struct ebt_802_3_info)))
3551 + return -EINVAL;
3552 + if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
3553 + return -EINVAL;
3554 +
3555 + return 0;
3556 +}
3557 +
3558 +static struct ebt_match filter_802_3 =
3559 +{
3560 + .name = EBT_802_3_MATCH,
3561 + .match = ebt_filter_802_3,
3562 + .check = ebt_802_3_check,
3563 + .me = THIS_MODULE,
3564 +};
3565 +
3566 +static int __init init(void)
3567 +{
3568 + return ebt_register_match(&filter_802_3);
3569 +}
3570 +
3571 +static void __exit fini(void)
3572 +{
3573 + ebt_unregister_match(&filter_802_3);
3574 +}
3575 +
3576 +module_init(init);
3577 +module_exit(fini);
3578 +EXPORT_NO_SYMBOLS;
3579 +MODULE_LICENSE("GPL");
3580 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_among.c linux-ebtables/net/bridge/netfilter/ebt_among.c
3581 --- linux-mips-cvs/net/bridge/netfilter/ebt_among.c 1970-01-01 01:00:00.000000000 +0100
3582 +++ linux-ebtables/net/bridge/netfilter/ebt_among.c 2005-02-07 05:52:50.000000000 +0100
3583 @@ -0,0 +1,223 @@
3584 +/*
3585 + * ebt_among
3586 + *
3587 + * Authors:
3588 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
3589 + *
3590 + * August, 2003
3591 + *
3592 + */
3593 +
3594 +#include <linux/netfilter_bridge/ebtables.h>
3595 +#include <linux/netfilter_bridge/ebt_among.h>
3596 +#include <linux/ip.h>
3597 +#include <linux/if_arp.h>
3598 +#include <linux/module.h>
3599 +
3600 +static int ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh,
3601 + const char *mac, uint32_t ip)
3602 +{
3603 + /* You may be puzzled as to how this code works.
3604 + * Some tricks were used, refer to
3605 + * include/linux/netfilter_bridge/ebt_among.h
3606 + * as there you can find a solution of this mystery.
3607 + */
3608 + const struct ebt_mac_wormhash_tuple *p;
3609 + int start, limit, i;
3610 + uint32_t cmp[2] = { 0, 0 };
3611 + int key = (const unsigned char) mac[5];
3612 +
3613 + memcpy(((char *) cmp) + 2, mac, 6);
3614 + start = wh->table[key];
3615 + limit = wh->table[key + 1];
3616 + if (ip) {
3617 + for (i = start; i < limit; i++) {
3618 + p = &wh->pool[i];
3619 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
3620 + if (p->ip == 0 || p->ip == ip) {
3621 + return 1;
3622 + }
3623 + }
3624 + }
3625 + } else {
3626 + for (i = start; i < limit; i++) {
3627 + p = &wh->pool[i];
3628 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
3629 + if (p->ip == 0) {
3630 + return 1;
3631 + }
3632 + }
3633 + }
3634 + }
3635 + return 0;
3636 +}
3637 +
3638 +static int ebt_mac_wormhash_check_integrity(const struct ebt_mac_wormhash
3639 + *wh)
3640 +{
3641 + int i;
3642 +
3643 + for (i = 0; i < 256; i++) {
3644 + if (wh->table[i] > wh->table[i + 1])
3645 + return -0x100 - i;
3646 + if (wh->table[i] < 0)
3647 + return -0x200 - i;
3648 + if (wh->table[i] > wh->poolsize)
3649 + return -0x300 - i;
3650 + }
3651 + if (wh->table[256] > wh->poolsize)
3652 + return -0xc00;
3653 + return 0;
3654 +}
3655 +
3656 +static int get_ip_dst(const struct sk_buff *skb, uint32_t * addr)
3657 +{
3658 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
3659 + *addr = skb->nh.iph->daddr;
3660 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
3661 + uint32_t arp_len = sizeof(struct arphdr) +
3662 + (2 * (((*skb).nh.arph)->ar_hln)) +
3663 + (2 * (((*skb).nh.arph)->ar_pln));
3664 +
3665 + /* Make sure the packet is long enough. */
3666 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
3667 + return -1;
3668 + /* IPv4 addresses are always 4 bytes. */
3669 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
3670 + return -1;
3671 +
3672 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
3673 + (2 * (((*skb).nh.arph)->ar_hln)) +
3674 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
3675 +
3676 + }
3677 + return 0;
3678 +}
3679 +
3680 +static int get_ip_src(const struct sk_buff *skb, uint32_t * addr)
3681 +{
3682 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
3683 + *addr = skb->nh.iph->saddr;
3684 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
3685 + uint32_t arp_len = sizeof(struct arphdr) +
3686 + (2 * (((*skb).nh.arph)->ar_hln)) +
3687 + (2 * (((*skb).nh.arph)->ar_pln));
3688 +
3689 + /* Make sure the packet is long enough. */
3690 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
3691 + return -1;
3692 + /* IPv4 addresses are always 4 bytes. */
3693 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
3694 + return -1;
3695 +
3696 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
3697 + ((((*skb).nh.arph)->ar_hln)), sizeof(uint32_t));
3698 +
3699 + }
3700 + return 0;
3701 +}
3702 +
3703 +static int ebt_filter_among(const struct sk_buff *skb,
3704 + const struct net_device *in,
3705 + const struct net_device *out, const void *data,
3706 + unsigned int datalen)
3707 +{
3708 + struct ebt_among_info *info = (struct ebt_among_info *) data;
3709 + const char *dmac, *smac;
3710 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
3711 + uint32_t dip = 0, sip = 0;
3712 +
3713 + wh_dst = ebt_among_wh_dst(info);
3714 + wh_src = ebt_among_wh_src(info);
3715 +
3716 + if (wh_src) {
3717 + smac = skb->mac.ethernet->h_source;
3718 + if (get_ip_src(skb, &sip))
3719 + return EBT_NOMATCH;
3720 + if (!(info->bitmask & EBT_AMONG_SRC_NEG)) {
3721 + /* we match only if it contains */
3722 + if (!ebt_mac_wormhash_contains(wh_src, smac, sip))
3723 + return EBT_NOMATCH;
3724 + } else {
3725 + /* we match only if it DOES NOT contain */
3726 + if (ebt_mac_wormhash_contains(wh_src, smac, sip))
3727 + return EBT_NOMATCH;
3728 + }
3729 + }
3730 +
3731 + if (wh_dst) {
3732 + dmac = skb->mac.ethernet->h_dest;
3733 + if (get_ip_dst(skb, &dip))
3734 + return EBT_NOMATCH;
3735 + if (!(info->bitmask & EBT_AMONG_DST_NEG)) {
3736 + /* we match only if it contains */
3737 + if (!ebt_mac_wormhash_contains(wh_dst, dmac, dip))
3738 + return EBT_NOMATCH;
3739 + } else {
3740 + /* we match only if it DOES NOT contain */
3741 + if (ebt_mac_wormhash_contains(wh_dst, dmac, dip))
3742 + return EBT_NOMATCH;
3743 + }
3744 + }
3745 +
3746 + return EBT_MATCH;
3747 +}
3748 +
3749 +static int ebt_among_check(const char *tablename, unsigned int hookmask,
3750 + const struct ebt_entry *e, void *data,
3751 + unsigned int datalen)
3752 +{
3753 + struct ebt_among_info *info = (struct ebt_among_info *) data;
3754 + int expected_length = sizeof(struct ebt_among_info);
3755 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
3756 + int err;
3757 +
3758 + wh_dst = ebt_among_wh_dst(info);
3759 + wh_src = ebt_among_wh_src(info);
3760 + expected_length += ebt_mac_wormhash_size(wh_dst);
3761 + expected_length += ebt_mac_wormhash_size(wh_src);
3762 +
3763 + if (datalen != EBT_ALIGN(expected_length)) {
3764 + printk(KERN_WARNING
3765 + "ebtables: among: wrong size: %d"
3766 + "against expected %d, rounded to %d\n",
3767 + datalen, expected_length,
3768 + EBT_ALIGN(expected_length));
3769 + return -EINVAL;
3770 + }
3771 + if (wh_dst && (err = ebt_mac_wormhash_check_integrity(wh_dst))) {
3772 + printk(KERN_WARNING
3773 + "ebtables: among: dst integrity fail: %x\n", -err);
3774 + return -EINVAL;
3775 + }
3776 + if (wh_src && (err = ebt_mac_wormhash_check_integrity(wh_src))) {
3777 + printk(KERN_WARNING
3778 + "ebtables: among: src integrity fail: %x\n", -err);
3779 + return -EINVAL;
3780 + }
3781 + return 0;
3782 +}
3783 +
3784 +static struct ebt_match filter_among = {
3785 + {NULL, NULL},
3786 + EBT_AMONG_MATCH,
3787 + ebt_filter_among,
3788 + ebt_among_check,
3789 + NULL,
3790 + THIS_MODULE
3791 +};
3792 +
3793 +static int __init init(void)
3794 +{
3795 + return ebt_register_match(&filter_among);
3796 +}
3797 +
3798 +static void __exit fini(void)
3799 +{
3800 + ebt_unregister_match(&filter_among);
3801 +}
3802 +
3803 +module_init(init);
3804 +module_exit(fini);
3805 +EXPORT_NO_SYMBOLS;
3806 +MODULE_LICENSE("GPL");
3807 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_arp.c linux-ebtables/net/bridge/netfilter/ebt_arp.c
3808 --- linux-mips-cvs/net/bridge/netfilter/ebt_arp.c 1970-01-01 01:00:00.000000000 +0100
3809 +++ linux-ebtables/net/bridge/netfilter/ebt_arp.c 2005-02-07 05:52:50.000000000 +0100
3810 @@ -0,0 +1,149 @@
3811 +/*
3812 + * ebt_arp
3813 + *
3814 + * Authors:
3815 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3816 + * Tim Gardner <timg@tpi.com>
3817 + *
3818 + * April, 2002
3819 + *
3820 + */
3821 +
3822 +#include <linux/netfilter_bridge/ebtables.h>
3823 +#include <linux/netfilter_bridge/ebt_arp.h>
3824 +#include <linux/if_arp.h>
3825 +#include <linux/if_ether.h>
3826 +#include <linux/module.h>
3827 +
3828 +static int ebt_filter_arp(const struct sk_buff *skb, const struct net_device *in,
3829 + const struct net_device *out, const void *data, unsigned int datalen)
3830 +{
3831 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
3832 +
3833 + if (info->bitmask & EBT_ARP_OPCODE && FWINV(info->opcode !=
3834 + ((*skb).nh.arph)->ar_op, EBT_ARP_OPCODE))
3835 + return EBT_NOMATCH;
3836 + if (info->bitmask & EBT_ARP_HTYPE && FWINV(info->htype !=
3837 + ((*skb).nh.arph)->ar_hrd, EBT_ARP_HTYPE))
3838 + return EBT_NOMATCH;
3839 + if (info->bitmask & EBT_ARP_PTYPE && FWINV(info->ptype !=
3840 + ((*skb).nh.arph)->ar_pro, EBT_ARP_PTYPE))
3841 + return EBT_NOMATCH;
3842 +
3843 + if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP))
3844 + {
3845 + uint32_t arp_len = sizeof(struct arphdr) +
3846 + (2 * (((*skb).nh.arph)->ar_hln)) +
3847 + (2 * (((*skb).nh.arph)->ar_pln));
3848 + uint32_t dst;
3849 + uint32_t src;
3850 +
3851 + // Make sure the packet is long enough.
3852 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
3853 + return EBT_NOMATCH;
3854 + // IPv4 addresses are always 4 bytes.
3855 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
3856 + return EBT_NOMATCH;
3857 +
3858 + if (info->bitmask & EBT_ARP_SRC_IP) {
3859 + memcpy(&src, ((*skb).nh.raw) + sizeof(struct arphdr) +
3860 + ((*skb).nh.arph)->ar_hln, sizeof(uint32_t));
3861 + if (FWINV(info->saddr != (src & info->smsk),
3862 + EBT_ARP_SRC_IP))
3863 + return EBT_NOMATCH;
3864 + }
3865 +
3866 + if (info->bitmask & EBT_ARP_DST_IP) {
3867 + memcpy(&dst, ((*skb).nh.raw)+sizeof(struct arphdr) +
3868 + (2*(((*skb).nh.arph)->ar_hln)) +
3869 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
3870 + if (FWINV(info->daddr != (dst & info->dmsk),
3871 + EBT_ARP_DST_IP))
3872 + return EBT_NOMATCH;
3873 + }
3874 + }
3875 +
3876 + if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC))
3877 + {
3878 + uint32_t arp_len = sizeof(struct arphdr) +
3879 + (2 * (((*skb).nh.arph)->ar_hln)) +
3880 + (2 * (((*skb).nh.arph)->ar_pln));
3881 + unsigned char dst[ETH_ALEN];
3882 + unsigned char src[ETH_ALEN];
3883 +
3884 + // Make sure the packet is long enough.
3885 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
3886 + return EBT_NOMATCH;
3887 + // MAC addresses are 6 bytes.
3888 + if (((*skb).nh.arph)->ar_hln != ETH_ALEN)
3889 + return EBT_NOMATCH;
3890 + if (info->bitmask & EBT_ARP_SRC_MAC) {
3891 + uint8_t verdict, i;
3892 +
3893 + memcpy(&src, ((*skb).nh.raw) +
3894 + sizeof(struct arphdr),
3895 + ETH_ALEN);
3896 + verdict = 0;
3897 + for (i = 0; i < 6; i++)
3898 + verdict |= (src[i] ^ info->smaddr[i]) &
3899 + info->smmsk[i];
3900 + if (FWINV(verdict != 0, EBT_ARP_SRC_MAC))
3901 + return EBT_NOMATCH;
3902 + }
3903 +
3904 + if (info->bitmask & EBT_ARP_DST_MAC) {
3905 + uint8_t verdict, i;
3906 +
3907 + memcpy(&dst, ((*skb).nh.raw) +
3908 + sizeof(struct arphdr) +
3909 + (((*skb).nh.arph)->ar_hln) +
3910 + (((*skb).nh.arph)->ar_pln),
3911 + ETH_ALEN);
3912 + verdict = 0;
3913 + for (i = 0; i < 6; i++)
3914 + verdict |= (dst[i] ^ info->dmaddr[i]) &
3915 + info->dmmsk[i];
3916 + if (FWINV(verdict != 0, EBT_ARP_DST_MAC))
3917 + return EBT_NOMATCH;
3918 + }
3919 + }
3920 +
3921 + return EBT_MATCH;
3922 +}
3923 +
3924 +static int ebt_arp_check(const char *tablename, unsigned int hookmask,
3925 + const struct ebt_entry *e, void *data, unsigned int datalen)
3926 +{
3927 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
3928 +
3929 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arp_info)))
3930 + return -EINVAL;
3931 + if ((e->ethproto != __constant_htons(ETH_P_ARP) &&
3932 + e->ethproto != __constant_htons(ETH_P_RARP)) ||
3933 + e->invflags & EBT_IPROTO)
3934 + return -EINVAL;
3935 + if (info->bitmask & ~EBT_ARP_MASK || info->invflags & ~EBT_ARP_MASK)
3936 + return -EINVAL;
3937 + return 0;
3938 +}
3939 +
3940 +static struct ebt_match filter_arp =
3941 +{
3942 + {NULL, NULL}, EBT_ARP_MATCH, ebt_filter_arp, ebt_arp_check, NULL,
3943 + THIS_MODULE
3944 +};
3945 +
3946 +static int __init init(void)
3947 +{
3948 + return ebt_register_match(&filter_arp);
3949 +}
3950 +
3951 +static void __exit fini(void)
3952 +{
3953 + ebt_unregister_match(&filter_arp);
3954 +}
3955 +
3956 +module_init(init);
3957 +module_exit(fini);
3958 +EXPORT_NO_SYMBOLS;
3959 +MODULE_LICENSE("GPL");
3960 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_arpreply.c linux-ebtables/net/bridge/netfilter/ebt_arpreply.c
3961 --- linux-mips-cvs/net/bridge/netfilter/ebt_arpreply.c 1970-01-01 01:00:00.000000000 +0100
3962 +++ linux-ebtables/net/bridge/netfilter/ebt_arpreply.c 2005-02-07 05:52:50.000000000 +0100
3963 @@ -0,0 +1,86 @@
3964 +/*
3965 + * ebt_arpreply
3966 + *
3967 + * Authors:
3968 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
3969 + * Bart De Schuymer <bdschuym@pandora.be>
3970 + *
3971 + * August, 2003
3972 + *
3973 + */
3974 +
3975 +#include <linux/netfilter_bridge/ebtables.h>
3976 +#include <linux/netfilter_bridge/ebt_arpreply.h>
3977 +#include <linux/if_arp.h>
3978 +#include <net/arp.h>
3979 +#include <linux/module.h>
3980 +
3981 +static int ebt_target_reply(struct sk_buff **pskb, unsigned int hooknr,
3982 + const struct net_device *in, const struct net_device *out,
3983 + const void *data, unsigned int datalen)
3984 +{
3985 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
3986 + struct arphdr *ah;
3987 + unsigned char *sha, *arp_ptr;
3988 + u32 sip, tip;
3989 +
3990 + ah = (**pskb).nh.arph;
3991 + if (ah->ar_op != __constant_htons(ARPOP_REQUEST) ||
3992 + ah->ar_hln != ETH_ALEN || ah->ar_pro != htons(ETH_P_IP) ||
3993 + ah->ar_pln != 4)
3994 + return EBT_CONTINUE;
3995 +
3996 + arp_ptr = (unsigned char *)(ah + 1);
3997 +
3998 + /* get source and target IP */
3999 + sha = arp_ptr;
4000 + arp_ptr += ETH_ALEN;
4001 + memcpy(&sip, arp_ptr, 4);
4002 + arp_ptr += 4 + ETH_ALEN;
4003 + memcpy(&tip, arp_ptr, 4);
4004 +
4005 + arp_send(ARPOP_REPLY, ETH_P_ARP, sip, in, tip, sha, info->mac, sha);
4006 +
4007 + return info->target;
4008 +}
4009 +
4010 +static int ebt_target_reply_check(const char *tablename, unsigned int hookmask,
4011 + const struct ebt_entry *e, void *data, unsigned int datalen)
4012 +{
4013 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
4014 +
4015 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arpreply_info)))
4016 + return -EINVAL;
4017 + if (BASE_CHAIN && info->target == EBT_RETURN)
4018 + return -EINVAL;
4019 + if (e->ethproto != __constant_htons(ETH_P_ARP) ||
4020 + e->invflags & EBT_IPROTO)
4021 + return -EINVAL;
4022 + CLEAR_BASE_CHAIN_BIT;
4023 + if (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING))
4024 + return -EINVAL;
4025 + return 0;
4026 +}
4027 +
4028 +static struct ebt_target reply_target =
4029 +{
4030 + .name = EBT_ARPREPLY_TARGET,
4031 + .target = ebt_target_reply,
4032 + .check = ebt_target_reply_check,
4033 + .me = THIS_MODULE,
4034 +};
4035 +
4036 +static int __init init(void)
4037 +{
4038 + return ebt_register_target(&reply_target);
4039 +}
4040 +
4041 +static void __exit fini(void)
4042 +{
4043 + ebt_unregister_target(&reply_target);
4044 +}
4045 +
4046 +module_init(init);
4047 +module_exit(fini);
4048 +EXPORT_NO_SYMBOLS;
4049 +MODULE_LICENSE("GPL");
4050 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_dnat.c linux-ebtables/net/bridge/netfilter/ebt_dnat.c
4051 --- linux-mips-cvs/net/bridge/netfilter/ebt_dnat.c 1970-01-01 01:00:00.000000000 +0100
4052 +++ linux-ebtables/net/bridge/netfilter/ebt_dnat.c 2005-02-07 05:52:50.000000000 +0100
4053 @@ -0,0 +1,65 @@
4054 +/*
4055 + * ebt_dnat
4056 + *
4057 + * Authors:
4058 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4059 + *
4060 + * June, 2002
4061 + *
4062 + */
4063 +
4064 +#include <linux/netfilter_bridge/ebtables.h>
4065 +#include <linux/netfilter_bridge/ebt_nat.h>
4066 +#include <linux/module.h>
4067 +#include <net/sock.h>
4068 +
4069 +static int ebt_target_dnat(struct sk_buff **pskb, unsigned int hooknr,
4070 + const struct net_device *in, const struct net_device *out,
4071 + const void *data, unsigned int datalen)
4072 +{
4073 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
4074 +
4075 + memcpy(((**pskb).mac.ethernet)->h_dest, info->mac,
4076 + ETH_ALEN * sizeof(unsigned char));
4077 + return info->target;
4078 +}
4079 +
4080 +static int ebt_target_dnat_check(const char *tablename, unsigned int hookmask,
4081 + const struct ebt_entry *e, void *data, unsigned int datalen)
4082 +{
4083 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
4084 +
4085 + if (BASE_CHAIN && info->target == EBT_RETURN)
4086 + return -EINVAL;
4087 + CLEAR_BASE_CHAIN_BIT;
4088 + if ( (strcmp(tablename, "nat") ||
4089 + (hookmask & ~((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT)))) &&
4090 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
4091 + return -EINVAL;
4092 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
4093 + return -EINVAL;
4094 + if (INVALID_TARGET)
4095 + return -EINVAL;
4096 + return 0;
4097 +}
4098 +
4099 +static struct ebt_target dnat =
4100 +{
4101 + {NULL, NULL}, EBT_DNAT_TARGET, ebt_target_dnat, ebt_target_dnat_check,
4102 + NULL, THIS_MODULE
4103 +};
4104 +
4105 +static int __init init(void)
4106 +{
4107 + return ebt_register_target(&dnat);
4108 +}
4109 +
4110 +static void __exit fini(void)
4111 +{
4112 + ebt_unregister_target(&dnat);
4113 +}
4114 +
4115 +module_init(init);
4116 +module_exit(fini);
4117 +EXPORT_NO_SYMBOLS;
4118 +MODULE_LICENSE("GPL");
4119 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_ip.c linux-ebtables/net/bridge/netfilter/ebt_ip.c
4120 --- linux-mips-cvs/net/bridge/netfilter/ebt_ip.c 1970-01-01 01:00:00.000000000 +0100
4121 +++ linux-ebtables/net/bridge/netfilter/ebt_ip.c 2005-02-07 05:52:50.000000000 +0100
4122 @@ -0,0 +1,121 @@
4123 +/*
4124 + * ebt_ip
4125 + *
4126 + * Authors:
4127 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4128 + *
4129 + * April, 2002
4130 + *
4131 + * Changes:
4132 + * added ip-sport and ip-dport
4133 + * Innominate Security Technologies AG <mhopf@innominate.com>
4134 + * September, 2002
4135 + */
4136 +
4137 +#include <linux/netfilter_bridge/ebtables.h>
4138 +#include <linux/netfilter_bridge/ebt_ip.h>
4139 +#include <linux/ip.h>
4140 +#include <linux/in.h>
4141 +#include <linux/module.h>
4142 +
4143 +struct tcpudphdr {
4144 + uint16_t src;
4145 + uint16_t dst;
4146 +};
4147 +
4148 +union h_u {
4149 + unsigned char *raw;
4150 + struct tcpudphdr *tuh;
4151 +};
4152 +
4153 +static int ebt_filter_ip(const struct sk_buff *skb, const struct net_device *in,
4154 + const struct net_device *out, const void *data,
4155 + unsigned int datalen)
4156 +{
4157 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
4158 +
4159 + if (info->bitmask & EBT_IP_TOS &&
4160 + FWINV(info->tos != ((*skb).nh.iph)->tos, EBT_IP_TOS))
4161 + return EBT_NOMATCH;
4162 + if (info->bitmask & EBT_IP_PROTO) {
4163 + if (FWINV(info->protocol != ((*skb).nh.iph)->protocol,
4164 + EBT_IP_PROTO))
4165 + return EBT_NOMATCH;
4166 + if ( info->protocol == IPPROTO_TCP ||
4167 + info->protocol == IPPROTO_UDP )
4168 + {
4169 + union h_u h;
4170 + h.raw = skb->data + skb->nh.iph->ihl*4;
4171 + if (info->bitmask & EBT_IP_DPORT) {
4172 + uint16_t port = ntohs(h.tuh->dst);
4173 + if (FWINV(port < info->dport[0] ||
4174 + port > info->dport[1],
4175 + EBT_IP_DPORT))
4176 + return EBT_NOMATCH;
4177 + }
4178 + if (info->bitmask & EBT_IP_SPORT) {
4179 + uint16_t port = ntohs(h.tuh->src);
4180 + if (FWINV(port < info->sport[0] ||
4181 + port > info->sport[1],
4182 + EBT_IP_SPORT))
4183 + return EBT_NOMATCH;
4184 + }
4185 + }
4186 + }
4187 + if (info->bitmask & EBT_IP_SOURCE &&
4188 + FWINV((((*skb).nh.iph)->saddr & info->smsk) !=
4189 + info->saddr, EBT_IP_SOURCE))
4190 + return EBT_NOMATCH;
4191 + if ((info->bitmask & EBT_IP_DEST) &&
4192 + FWINV((((*skb).nh.iph)->daddr & info->dmsk) !=
4193 + info->daddr, EBT_IP_DEST))
4194 + return EBT_NOMATCH;
4195 + return EBT_MATCH;
4196 +}
4197 +
4198 +static int ebt_ip_check(const char *tablename, unsigned int hookmask,
4199 + const struct ebt_entry *e, void *data, unsigned int datalen)
4200 +{
4201 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
4202 +
4203 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ip_info)))
4204 + return -EINVAL;
4205 + if (e->ethproto != __constant_htons(ETH_P_IP) ||
4206 + e->invflags & EBT_IPROTO)
4207 + return -EINVAL;
4208 + if (info->bitmask & ~EBT_IP_MASK || info->invflags & ~EBT_IP_MASK)
4209 + return -EINVAL;
4210 + if (info->bitmask & (EBT_IP_DPORT | EBT_IP_SPORT)) {
4211 + if (!info->bitmask & EBT_IPROTO)
4212 + return -EINVAL;
4213 + if (info->protocol != IPPROTO_TCP &&
4214 + info->protocol != IPPROTO_UDP)
4215 + return -EINVAL;
4216 + }
4217 + if (info->bitmask & EBT_IP_DPORT && info->dport[0] > info->dport[1])
4218 + return -EINVAL;
4219 + if (info->bitmask & EBT_IP_SPORT && info->sport[0] > info->sport[1])
4220 + return -EINVAL;
4221 + return 0;
4222 +}
4223 +
4224 +static struct ebt_match filter_ip =
4225 +{
4226 + {NULL, NULL}, EBT_IP_MATCH, ebt_filter_ip, ebt_ip_check, NULL,
4227 + THIS_MODULE
4228 +};
4229 +
4230 +static int __init init(void)
4231 +{
4232 + return ebt_register_match(&filter_ip);
4233 +}
4234 +
4235 +static void __exit fini(void)
4236 +{
4237 + ebt_unregister_match(&filter_ip);
4238 +}
4239 +
4240 +module_init(init);
4241 +module_exit(fini);
4242 +EXPORT_NO_SYMBOLS;
4243 +MODULE_LICENSE("GPL");
4244 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_limit.c linux-ebtables/net/bridge/netfilter/ebt_limit.c
4245 --- linux-mips-cvs/net/bridge/netfilter/ebt_limit.c 1970-01-01 01:00:00.000000000 +0100
4246 +++ linux-ebtables/net/bridge/netfilter/ebt_limit.c 2005-02-07 05:52:50.000000000 +0100
4247 @@ -0,0 +1,101 @@
4248 +/*
4249 + * ebt_limit
4250 + *
4251 + * Authors:
4252 + * Tom Marshall <tommy@home.tig-grr.com>
4253 + *
4254 + * Mostly copied from netfilter's ipt_limit.c, see that file for explanation
4255 + *
4256 + * September, 2003
4257 + *
4258 + */
4259 +
4260 +#include <linux/netfilter_bridge/ebtables.h>
4261 +#include <linux/netfilter_bridge/ebt_limit.h>
4262 +#include <linux/module.h>
4263 +
4264 +#include <linux/netdevice.h>
4265 +#include <linux/spinlock.h>
4266 +
4267 +static spinlock_t limit_lock = SPIN_LOCK_UNLOCKED;
4268 +
4269 +#define CREDITS_PER_JIFFY 128
4270 +
4271 +static int ebt_limit_match(const struct sk_buff *skb, const struct net_device *in,
4272 + const struct net_device *out, const void *data, unsigned int datalen)
4273 +{
4274 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
4275 + unsigned long now = jiffies;
4276 +
4277 + spin_lock_bh(&limit_lock);
4278 + info->credit += (now - xchg(&info->prev, now)) * CREDITS_PER_JIFFY;
4279 + if (info->credit > info->credit_cap)
4280 + info->credit = info->credit_cap;
4281 +
4282 + if (info->credit >= info->cost) {
4283 + /* We're not limited. */
4284 + info->credit -= info->cost;
4285 + spin_unlock_bh(&limit_lock);
4286 + return EBT_MATCH;
4287 + }
4288 +
4289 + spin_unlock_bh(&limit_lock);
4290 + return EBT_NOMATCH;
4291 +}
4292 +
4293 +/* Precision saver. */
4294 +static u_int32_t
4295 +user2credits(u_int32_t user)
4296 +{
4297 + /* If multiplying would overflow... */
4298 + if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
4299 + /* Divide first. */
4300 + return (user / EBT_LIMIT_SCALE) * HZ * CREDITS_PER_JIFFY;
4301 +
4302 + return (user * HZ * CREDITS_PER_JIFFY) / EBT_LIMIT_SCALE;
4303 +}
4304 +
4305 +static int ebt_limit_check(const char *tablename, unsigned int hookmask,
4306 + const struct ebt_entry *e, void *data, unsigned int datalen)
4307 +{
4308 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
4309 +
4310 + if (datalen != EBT_ALIGN(sizeof(struct ebt_limit_info)))
4311 + return -EINVAL;
4312 +
4313 + /* Check for overflow. */
4314 + if (info->burst == 0
4315 + || user2credits(info->avg * info->burst) < user2credits(info->avg)) {
4316 + printk("Overflow in ebt_limit: %u/%u\n",
4317 + info->avg, info->burst);
4318 + return -EINVAL;
4319 + }
4320 +
4321 + /* User avg in seconds * EBT_LIMIT_SCALE: convert to jiffies * 128. */
4322 + info->prev = jiffies;
4323 + info->credit = user2credits(info->avg * info->burst);
4324 + info->credit_cap = user2credits(info->avg * info->burst);
4325 + info->cost = user2credits(info->avg);
4326 + return 0;
4327 +}
4328 +
4329 +static struct ebt_match ebt_limit_reg =
4330 +{
4331 + {NULL, NULL}, EBT_LIMIT_MATCH, ebt_limit_match, ebt_limit_check, NULL,
4332 + THIS_MODULE
4333 +};
4334 +
4335 +static int __init init(void)
4336 +{
4337 + return ebt_register_match(&ebt_limit_reg);
4338 +}
4339 +
4340 +static void __exit fini(void)
4341 +{
4342 + ebt_unregister_match(&ebt_limit_reg);
4343 +}
4344 +
4345 +module_init(init);
4346 +module_exit(fini);
4347 +EXPORT_NO_SYMBOLS;
4348 +MODULE_LICENSE("GPL");
4349 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_log.c linux-ebtables/net/bridge/netfilter/ebt_log.c
4350 --- linux-mips-cvs/net/bridge/netfilter/ebt_log.c 1970-01-01 01:00:00.000000000 +0100
4351 +++ linux-ebtables/net/bridge/netfilter/ebt_log.c 2005-02-07 05:52:50.000000000 +0100
4352 @@ -0,0 +1,153 @@
4353 +/*
4354 + * ebt_log
4355 + *
4356 + * Authors:
4357 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4358 + *
4359 + * April, 2002
4360 + *
4361 + */
4362 +
4363 +#include <linux/netfilter_bridge/ebtables.h>
4364 +#include <linux/netfilter_bridge/ebt_log.h>
4365 +#include <linux/module.h>
4366 +#include <linux/ip.h>
4367 +#include <linux/in.h>
4368 +#include <linux/if_arp.h>
4369 +#include <linux/spinlock.h>
4370 +
4371 +static spinlock_t ebt_log_lock = SPIN_LOCK_UNLOCKED;
4372 +
4373 +static int ebt_log_check(const char *tablename, unsigned int hookmask,
4374 + const struct ebt_entry *e, void *data, unsigned int datalen)
4375 +{
4376 + struct ebt_log_info *info = (struct ebt_log_info *)data;
4377 +
4378 + if (datalen != EBT_ALIGN(sizeof(struct ebt_log_info)))
4379 + return -EINVAL;
4380 + if (info->bitmask & ~EBT_LOG_MASK)
4381 + return -EINVAL;
4382 + if (info->loglevel >= 8)
4383 + return -EINVAL;
4384 + info->prefix[EBT_LOG_PREFIX_SIZE - 1] = '\0';
4385 + return 0;
4386 +}
4387 +
4388 +struct tcpudphdr
4389 +{
4390 + uint16_t src;
4391 + uint16_t dst;
4392 +};
4393 +
4394 +struct arppayload
4395 +{
4396 + unsigned char mac_src[ETH_ALEN];
4397 + unsigned char ip_src[4];
4398 + unsigned char mac_dst[ETH_ALEN];
4399 + unsigned char ip_dst[4];
4400 +};
4401 +
4402 +static void print_MAC(unsigned char *p)
4403 +{
4404 + int i;
4405 +
4406 + for (i = 0; i < ETH_ALEN; i++, p++)
4407 + printk("%02x%c", *p, i == ETH_ALEN - 1 ? ' ':':');
4408 +}
4409 +
4410 +#define myNIPQUAD(a) a[0], a[1], a[2], a[3]
4411 +static void ebt_log(const struct sk_buff *skb, unsigned int hooknr,
4412 + const struct net_device *in, const struct net_device *out,
4413 + const void *data, unsigned int datalen)
4414 +{
4415 + struct ebt_log_info *info = (struct ebt_log_info *)data;
4416 + char level_string[4] = "< >";
4417 + level_string[1] = '0' + info->loglevel;
4418 +
4419 + spin_lock_bh(&ebt_log_lock);
4420 + printk(level_string);
4421 + printk("%s IN=%s OUT=%s ", info->prefix, in ? in->name : "",
4422 + out ? out->name : "");
4423 +
4424 + printk("MAC source = ");
4425 + print_MAC((skb->mac.ethernet)->h_source);
4426 + printk("MAC dest = ");
4427 + print_MAC((skb->mac.ethernet)->h_dest);
4428 +
4429 + printk("proto = 0x%04x", ntohs(((*skb).mac.ethernet)->h_proto));
4430 +
4431 + if ((info->bitmask & EBT_LOG_IP) && skb->mac.ethernet->h_proto ==
4432 + htons(ETH_P_IP)){
4433 + struct iphdr *iph = skb->nh.iph;
4434 + printk(" IP SRC=%u.%u.%u.%u IP DST=%u.%u.%u.%u,",
4435 + NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
4436 + printk(" IP tos=0x%02X, IP proto=%d", iph->tos, iph->protocol);
4437 + if (iph->protocol == IPPROTO_TCP ||
4438 + iph->protocol == IPPROTO_UDP) {
4439 + struct tcpudphdr *ports = (struct tcpudphdr *)(skb->data + iph->ihl*4);
4440 +
4441 + if (skb->data + iph->ihl*4 > skb->tail) {
4442 + printk(" INCOMPLETE TCP/UDP header");
4443 + goto out;
4444 + }
4445 + printk(" SPT=%u DPT=%u", ntohs(ports->src),
4446 + ntohs(ports->dst));
4447 + }
4448 + goto out;
4449 + }
4450 +
4451 + if ((info->bitmask & EBT_LOG_ARP) &&
4452 + ((skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) ||
4453 + (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_RARP)))) {
4454 + struct arphdr * arph = skb->nh.arph;
4455 + printk(" ARP HTYPE=%d, PTYPE=0x%04x, OPCODE=%d",
4456 + ntohs(arph->ar_hrd), ntohs(arph->ar_pro),
4457 + ntohs(arph->ar_op));
4458 + /* If it's for Ethernet and the lengths are OK,
4459 + * then log the ARP payload */
4460 + if (arph->ar_hrd == __constant_htons(1) &&
4461 + arph->ar_hln == ETH_ALEN &&
4462 + arph->ar_pln == sizeof(uint32_t)) {
4463 + struct arppayload *arpp = (struct arppayload *)(skb->data + sizeof(*arph));
4464 +
4465 + if (skb->data + sizeof(*arph) > skb->tail) {
4466 + printk(" INCOMPLETE ARP header");
4467 + goto out;
4468 + }
4469 +
4470 + printk(" ARP MAC SRC=");
4471 + print_MAC(arpp->mac_src);
4472 + printk(" ARP IP SRC=%u.%u.%u.%u",
4473 + myNIPQUAD(arpp->ip_src));
4474 + printk(" ARP MAC DST=");
4475 + print_MAC(arpp->mac_dst);
4476 + printk(" ARP IP DST=%u.%u.%u.%u",
4477 + myNIPQUAD(arpp->ip_dst));
4478 + }
4479 +
4480 + }
4481 +out:
4482 + printk("\n");
4483 + spin_unlock_bh(&ebt_log_lock);
4484 +}
4485 +
4486 +static struct ebt_watcher log =
4487 +{
4488 + {NULL, NULL}, EBT_LOG_WATCHER, ebt_log, ebt_log_check, NULL,
4489 + THIS_MODULE
4490 +};
4491 +
4492 +static int __init init(void)
4493 +{
4494 + return ebt_register_watcher(&log);
4495 +}
4496 +
4497 +static void __exit fini(void)
4498 +{
4499 + ebt_unregister_watcher(&log);
4500 +}
4501 +
4502 +module_init(init);
4503 +module_exit(fini);
4504 +EXPORT_NO_SYMBOLS;
4505 +MODULE_LICENSE("GPL");
4506 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_mark.c linux-ebtables/net/bridge/netfilter/ebt_mark.c
4507 --- linux-mips-cvs/net/bridge/netfilter/ebt_mark.c 1970-01-01 01:00:00.000000000 +0100
4508 +++ linux-ebtables/net/bridge/netfilter/ebt_mark.c 2005-02-07 05:52:50.000000000 +0100
4509 @@ -0,0 +1,66 @@
4510 +/*
4511 + * ebt_mark
4512 + *
4513 + * Authors:
4514 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4515 + *
4516 + * July, 2002
4517 + *
4518 + */
4519 +
4520 +// The mark target can be used in any chain
4521 +// I believe adding a mangle table just for marking is total overkill
4522 +// Marking a frame doesn't really change anything in the frame anyway
4523 +
4524 +#include <linux/netfilter_bridge/ebtables.h>
4525 +#include <linux/netfilter_bridge/ebt_mark_t.h>
4526 +#include <linux/module.h>
4527 +
4528 +static int ebt_target_mark(struct sk_buff **pskb, unsigned int hooknr,
4529 + const struct net_device *in, const struct net_device *out,
4530 + const void *data, unsigned int datalen)
4531 +{
4532 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
4533 +
4534 + if ((*pskb)->nfmark != info->mark) {
4535 + (*pskb)->nfmark = info->mark;
4536 + (*pskb)->nfcache |= NFC_ALTERED;
4537 + }
4538 + return info->target;
4539 +}
4540 +
4541 +static int ebt_target_mark_check(const char *tablename, unsigned int hookmask,
4542 + const struct ebt_entry *e, void *data, unsigned int datalen)
4543 +{
4544 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
4545 +
4546 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_t_info)))
4547 + return -EINVAL;
4548 + if (BASE_CHAIN && info->target == EBT_RETURN)
4549 + return -EINVAL;
4550 + CLEAR_BASE_CHAIN_BIT;
4551 + if (INVALID_TARGET)
4552 + return -EINVAL;
4553 + return 0;
4554 +}
4555 +
4556 +static struct ebt_target mark_target =
4557 +{
4558 + {NULL, NULL}, EBT_MARK_TARGET, ebt_target_mark,
4559 + ebt_target_mark_check, NULL, THIS_MODULE
4560 +};
4561 +
4562 +static int __init init(void)
4563 +{
4564 + return ebt_register_target(&mark_target);
4565 +}
4566 +
4567 +static void __exit fini(void)
4568 +{
4569 + ebt_unregister_target(&mark_target);
4570 +}
4571 +
4572 +module_init(init);
4573 +module_exit(fini);
4574 +EXPORT_NO_SYMBOLS;
4575 +MODULE_LICENSE("GPL");
4576 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_mark_m.c linux-ebtables/net/bridge/netfilter/ebt_mark_m.c
4577 --- linux-mips-cvs/net/bridge/netfilter/ebt_mark_m.c 1970-01-01 01:00:00.000000000 +0100
4578 +++ linux-ebtables/net/bridge/netfilter/ebt_mark_m.c 2005-02-07 05:52:50.000000000 +0100
4579 @@ -0,0 +1,61 @@
4580 +/*
4581 + * ebt_mark_m
4582 + *
4583 + * Authors:
4584 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4585 + *
4586 + * July, 2002
4587 + *
4588 + */
4589 +
4590 +#include <linux/netfilter_bridge/ebtables.h>
4591 +#include <linux/netfilter_bridge/ebt_mark_m.h>
4592 +#include <linux/module.h>
4593 +
4594 +static int ebt_filter_mark(const struct sk_buff *skb,
4595 + const struct net_device *in, const struct net_device *out, const void *data,
4596 + unsigned int datalen)
4597 +{
4598 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
4599 +
4600 + if (info->bitmask & EBT_MARK_OR)
4601 + return !(!!(skb->nfmark & info->mask) ^ info->invert);
4602 + return !(((skb->nfmark & info->mask) == info->mark) ^ info->invert);
4603 +}
4604 +
4605 +static int ebt_mark_check(const char *tablename, unsigned int hookmask,
4606 + const struct ebt_entry *e, void *data, unsigned int datalen)
4607 +{
4608 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
4609 +
4610 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_m_info)))
4611 + return -EINVAL;
4612 + if (info->bitmask & ~EBT_MARK_MASK)
4613 + return -EINVAL;
4614 + if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
4615 + return -EINVAL;
4616 + if (!info->bitmask)
4617 + return -EINVAL;
4618 + return 0;
4619 +}
4620 +
4621 +static struct ebt_match filter_mark =
4622 +{
4623 + {NULL, NULL}, EBT_MARK_MATCH, ebt_filter_mark, ebt_mark_check, NULL,
4624 + THIS_MODULE
4625 +};
4626 +
4627 +static int __init init(void)
4628 +{
4629 + return ebt_register_match(&filter_mark);
4630 +}
4631 +
4632 +static void __exit fini(void)
4633 +{
4634 + ebt_unregister_match(&filter_mark);
4635 +}
4636 +
4637 +module_init(init);
4638 +module_exit(fini);
4639 +EXPORT_NO_SYMBOLS;
4640 +MODULE_LICENSE("GPL");
4641 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_pkttype.c linux-ebtables/net/bridge/netfilter/ebt_pkttype.c
4642 --- linux-mips-cvs/net/bridge/netfilter/ebt_pkttype.c 1970-01-01 01:00:00.000000000 +0100
4643 +++ linux-ebtables/net/bridge/netfilter/ebt_pkttype.c 2005-02-07 05:52:50.000000000 +0100
4644 @@ -0,0 +1,60 @@
4645 +/*
4646 + * ebt_pkttype
4647 + *
4648 + * Authors:
4649 + * Bart De Schuymer <bdschuym@pandora.be>
4650 + *
4651 + * April, 2003
4652 + *
4653 + */
4654 +
4655 +#include <linux/netfilter_bridge/ebtables.h>
4656 +#include <linux/netfilter_bridge/ebt_pkttype.h>
4657 +#include <linux/module.h>
4658 +
4659 +static int ebt_filter_pkttype(const struct sk_buff *skb,
4660 + const struct net_device *in,
4661 + const struct net_device *out,
4662 + const void *data,
4663 + unsigned int datalen)
4664 +{
4665 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
4666 +
4667 + return (skb->pkt_type != info->pkt_type) ^ info->invert;
4668 +}
4669 +
4670 +static int ebt_pkttype_check(const char *tablename, unsigned int hookmask,
4671 + const struct ebt_entry *e, void *data, unsigned int datalen)
4672 +{
4673 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
4674 +
4675 + if (datalen != EBT_ALIGN(sizeof(struct ebt_pkttype_info)))
4676 + return -EINVAL;
4677 + if (info->invert != 0 && info->invert != 1)
4678 + return -EINVAL;
4679 + /* Allow any pkt_type value */
4680 + return 0;
4681 +}
4682 +
4683 +static struct ebt_match filter_pkttype =
4684 +{
4685 + .name = EBT_PKTTYPE_MATCH,
4686 + .match = ebt_filter_pkttype,
4687 + .check = ebt_pkttype_check,
4688 + .me = THIS_MODULE,
4689 +};
4690 +
4691 +static int __init init(void)
4692 +{
4693 + return ebt_register_match(&filter_pkttype);
4694 +}
4695 +
4696 +static void __exit fini(void)
4697 +{
4698 + ebt_unregister_match(&filter_pkttype);
4699 +}
4700 +
4701 +module_init(init);
4702 +module_exit(fini);
4703 +EXPORT_NO_SYMBOLS;
4704 +MODULE_LICENSE("GPL");
4705 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_redirect.c linux-ebtables/net/bridge/netfilter/ebt_redirect.c
4706 --- linux-mips-cvs/net/bridge/netfilter/ebt_redirect.c 1970-01-01 01:00:00.000000000 +0100
4707 +++ linux-ebtables/net/bridge/netfilter/ebt_redirect.c 2005-02-07 05:52:50.000000000 +0100
4708 @@ -0,0 +1,71 @@
4709 +/*
4710 + * ebt_redirect
4711 + *
4712 + * Authors:
4713 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4714 + *
4715 + * April, 2002
4716 + *
4717 + */
4718 +
4719 +#include <linux/netfilter_bridge/ebtables.h>
4720 +#include <linux/netfilter_bridge/ebt_redirect.h>
4721 +#include <linux/module.h>
4722 +#include <net/sock.h>
4723 +#include "../br_private.h"
4724 +
4725 +static int ebt_target_redirect(struct sk_buff **pskb, unsigned int hooknr,
4726 + const struct net_device *in, const struct net_device *out,
4727 + const void *data, unsigned int datalen)
4728 +{
4729 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
4730 +
4731 + if (hooknr != NF_BR_BROUTING)
4732 + memcpy((**pskb).mac.ethernet->h_dest,
4733 + in->br_port->br->dev.dev_addr, ETH_ALEN);
4734 + else {
4735 + memcpy((**pskb).mac.ethernet->h_dest,
4736 + in->dev_addr, ETH_ALEN);
4737 + (*pskb)->pkt_type = PACKET_HOST;
4738 + }
4739 + return info->target;
4740 +}
4741 +
4742 +static int ebt_target_redirect_check(const char *tablename, unsigned int hookmask,
4743 + const struct ebt_entry *e, void *data, unsigned int datalen)
4744 +{
4745 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
4746 +
4747 + if (datalen != EBT_ALIGN(sizeof(struct ebt_redirect_info)))
4748 + return -EINVAL;
4749 + if (BASE_CHAIN && info->target == EBT_RETURN)
4750 + return -EINVAL;
4751 + CLEAR_BASE_CHAIN_BIT;
4752 + if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) &&
4753 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
4754 + return -EINVAL;
4755 + if (INVALID_TARGET)
4756 + return -EINVAL;
4757 + return 0;
4758 +}
4759 +
4760 +static struct ebt_target redirect_target =
4761 +{
4762 + {NULL, NULL}, EBT_REDIRECT_TARGET, ebt_target_redirect,
4763 + ebt_target_redirect_check, NULL, THIS_MODULE
4764 +};
4765 +
4766 +static int __init init(void)
4767 +{
4768 + return ebt_register_target(&redirect_target);
4769 +}
4770 +
4771 +static void __exit fini(void)
4772 +{
4773 + ebt_unregister_target(&redirect_target);
4774 +}
4775 +
4776 +module_init(init);
4777 +module_exit(fini);
4778 +EXPORT_NO_SYMBOLS;
4779 +MODULE_LICENSE("GPL");
4780 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_snat.c linux-ebtables/net/bridge/netfilter/ebt_snat.c
4781 --- linux-mips-cvs/net/bridge/netfilter/ebt_snat.c 1970-01-01 01:00:00.000000000 +0100
4782 +++ linux-ebtables/net/bridge/netfilter/ebt_snat.c 2005-02-07 05:52:50.000000000 +0100
4783 @@ -0,0 +1,64 @@
4784 +/*
4785 + * ebt_snat
4786 + *
4787 + * Authors:
4788 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4789 + *
4790 + * June, 2002
4791 + *
4792 + */
4793 +
4794 +#include <linux/netfilter_bridge/ebtables.h>
4795 +#include <linux/netfilter_bridge/ebt_nat.h>
4796 +#include <linux/module.h>
4797 +
4798 +static int ebt_target_snat(struct sk_buff **pskb, unsigned int hooknr,
4799 + const struct net_device *in, const struct net_device *out,
4800 + const void *data, unsigned int datalen)
4801 +{
4802 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
4803 +
4804 + memcpy(((**pskb).mac.ethernet)->h_source, info->mac,
4805 + ETH_ALEN * sizeof(unsigned char));
4806 + return info->target;
4807 +}
4808 +
4809 +static int ebt_target_snat_check(const char *tablename, unsigned int hookmask,
4810 + const struct ebt_entry *e, void *data, unsigned int datalen)
4811 +{
4812 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
4813 +
4814 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
4815 + return -EINVAL;
4816 + if (BASE_CHAIN && info->target == EBT_RETURN)
4817 + return -EINVAL;
4818 + CLEAR_BASE_CHAIN_BIT;
4819 + if (strcmp(tablename, "nat"))
4820 + return -EINVAL;
4821 + if (hookmask & ~(1 << NF_BR_POST_ROUTING))
4822 + return -EINVAL;
4823 + if (INVALID_TARGET)
4824 + return -EINVAL;
4825 + return 0;
4826 +}
4827 +
4828 +static struct ebt_target snat =
4829 +{
4830 + {NULL, NULL}, EBT_SNAT_TARGET, ebt_target_snat, ebt_target_snat_check,
4831 + NULL, THIS_MODULE
4832 +};
4833 +
4834 +static int __init init(void)
4835 +{
4836 + return ebt_register_target(&snat);
4837 +}
4838 +
4839 +static void __exit fini(void)
4840 +{
4841 + ebt_unregister_target(&snat);
4842 +}
4843 +
4844 +module_init(init);
4845 +module_exit(fini);
4846 +EXPORT_NO_SYMBOLS;
4847 +MODULE_LICENSE("GPL");
4848 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_stp.c linux-ebtables/net/bridge/netfilter/ebt_stp.c
4849 --- linux-mips-cvs/net/bridge/netfilter/ebt_stp.c 1970-01-01 01:00:00.000000000 +0100
4850 +++ linux-ebtables/net/bridge/netfilter/ebt_stp.c 2005-02-07 05:52:50.000000000 +0100
4851 @@ -0,0 +1,191 @@
4852 +/*
4853 + * ebt_stp
4854 + *
4855 + * Authors:
4856 + * Bart De Schuymer <bdschuym@pandora.be>
4857 + * Stephen Hemminger <shemminger@osdl.org>
4858 + *
4859 + * June, 2003
4860 + */
4861 +
4862 +#include <linux/netfilter_bridge/ebtables.h>
4863 +#include <linux/netfilter_bridge/ebt_stp.h>
4864 +#include <linux/module.h>
4865 +
4866 +#define BPDU_TYPE_CONFIG 0
4867 +#define BPDU_TYPE_TCN 0x80
4868 +
4869 +struct stp_header {
4870 + uint8_t dsap;
4871 + uint8_t ssap;
4872 + uint8_t ctrl;
4873 + uint8_t pid;
4874 + uint8_t vers;
4875 + uint8_t type;
4876 +};
4877 +
4878 +struct stp_config_pdu {
4879 + uint8_t flags;
4880 + uint8_t root[8];
4881 + uint8_t root_cost[4];
4882 + uint8_t sender[8];
4883 + uint8_t port[2];
4884 + uint8_t msg_age[2];
4885 + uint8_t max_age[2];
4886 + uint8_t hello_time[2];
4887 + uint8_t forward_delay[2];
4888 +};
4889 +
4890 +#define NR16(p) (p[0] << 8 | p[1])
4891 +#define NR32(p) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3])
4892 +
4893 +static int ebt_filter_config(struct ebt_stp_info *info,
4894 + struct stp_config_pdu *stpc)
4895 +{
4896 + struct ebt_stp_config_info *c;
4897 + uint16_t v16;
4898 + uint32_t v32;
4899 + int verdict, i;
4900 +
4901 + c = &info->config;
4902 + if ((info->bitmask & EBT_STP_FLAGS) &&
4903 + FWINV(c->flags != stpc->flags, EBT_STP_FLAGS))
4904 + return EBT_NOMATCH;
4905 + if (info->bitmask & EBT_STP_ROOTPRIO) {
4906 + v16 = NR16(stpc->root);
4907 + if (FWINV(v16 < c->root_priol ||
4908 + v16 > c->root_priou, EBT_STP_ROOTPRIO))
4909 + return EBT_NOMATCH;
4910 + }
4911 + if (info->bitmask & EBT_STP_ROOTADDR) {
4912 + verdict = 0;
4913 + for (i = 0; i < 6; i++)
4914 + verdict |= (stpc->root[2+i] ^ c->root_addr[i]) &
4915 + c->root_addrmsk[i];
4916 + if (FWINV(verdict != 0, EBT_STP_ROOTADDR))
4917 + return EBT_NOMATCH;
4918 + }
4919 + if (info->bitmask & EBT_STP_ROOTCOST) {
4920 + v32 = NR32(stpc->root_cost);
4921 + if (FWINV(v32 < c->root_costl ||
4922 + v32 > c->root_costu, EBT_STP_ROOTCOST))
4923 + return EBT_NOMATCH;
4924 + }
4925 + if (info->bitmask & EBT_STP_SENDERPRIO) {
4926 + v16 = NR16(stpc->sender);
4927 + if (FWINV(v16 < c->sender_priol ||
4928 + v16 > c->sender_priou, EBT_STP_SENDERPRIO))
4929 + return EBT_NOMATCH;
4930 + }
4931 + if (info->bitmask & EBT_STP_SENDERADDR) {
4932 + verdict = 0;
4933 + for (i = 0; i < 6; i++)
4934 + verdict |= (stpc->sender[2+i] ^ c->sender_addr[i]) &
4935 + c->sender_addrmsk[i];
4936 + if (FWINV(verdict != 0, EBT_STP_SENDERADDR))
4937 + return EBT_NOMATCH;
4938 + }
4939 + if (info->bitmask & EBT_STP_PORT) {
4940 + v16 = NR16(stpc->port);
4941 + if (FWINV(v16 < c->portl ||
4942 + v16 > c->portu, EBT_STP_PORT))
4943 + return EBT_NOMATCH;
4944 + }
4945 + if (info->bitmask & EBT_STP_MSGAGE) {
4946 + v16 = NR16(stpc->msg_age);
4947 + if (FWINV(v16 < c->msg_agel ||
4948 + v16 > c->msg_ageu, EBT_STP_MSGAGE))
4949 + return EBT_NOMATCH;
4950 + }
4951 + if (info->bitmask & EBT_STP_MAXAGE) {
4952 + v16 = NR16(stpc->max_age);
4953 + if (FWINV(v16 < c->max_agel ||
4954 + v16 > c->max_ageu, EBT_STP_MAXAGE))
4955 + return EBT_NOMATCH;
4956 + }
4957 + if (info->bitmask & EBT_STP_HELLOTIME) {
4958 + v16 = NR16(stpc->hello_time);
4959 + if (FWINV(v16 < c->hello_timel ||
4960 + v16 > c->hello_timeu, EBT_STP_HELLOTIME))
4961 + return EBT_NOMATCH;
4962 + }
4963 + if (info->bitmask & EBT_STP_FWDD) {
4964 + v16 = NR16(stpc->forward_delay);
4965 + if (FWINV(v16 < c->forward_delayl ||
4966 + v16 > c->forward_delayu, EBT_STP_FWDD))
4967 + return EBT_NOMATCH;
4968 + }
4969 + return EBT_MATCH;
4970 +}
4971 +
4972 +static int ebt_filter_stp(const struct sk_buff *skb, const struct net_device *in,
4973 + const struct net_device *out, const void *data, unsigned int datalen)
4974 +{
4975 + struct ebt_stp_info *info = (struct ebt_stp_info *)data;
4976 + struct stp_header stph;
4977 + uint8_t header[6] = {0x42, 0x42, 0x03, 0x00, 0x00, 0x00};
4978 + if (skb_copy_bits(skb, 0, &stph, sizeof(stph)))
4979 + return EBT_NOMATCH;
4980 +
4981 + /* The stp code only considers these */
4982 + if (memcmp(&stph, header, sizeof(header)))
4983 + return EBT_NOMATCH;
4984 +
4985 + if (info->bitmask & EBT_STP_TYPE
4986 + && FWINV(info->type != stph.type, EBT_STP_TYPE))
4987 + return EBT_NOMATCH;
4988 +
4989 + if (stph.type == BPDU_TYPE_CONFIG &&
4990 + info->bitmask & EBT_STP_CONFIG_MASK) {
4991 + struct stp_config_pdu stpc;
4992 +
4993 + if (skb_copy_bits(skb, sizeof(stph), &stpc, sizeof(stpc)))
4994 + return EBT_NOMATCH;
4995 + return ebt_filter_config(info, &stpc);
4996 + }
4997 + return EBT_MATCH;
4998 +}
4999 +
5000 +static int ebt_stp_check(const char *tablename, unsigned int hookmask,
5001 + const struct ebt_entry *e, void *data, unsigned int datalen)
5002 +{
5003 + struct ebt_stp_info *info = (struct ebt_stp_info *)data;
5004 + int len = EBT_ALIGN(sizeof(struct ebt_stp_info));
5005 + uint8_t bridge_ula[6] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
5006 + uint8_t msk[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
5007 +
5008 + if (info->bitmask & ~EBT_STP_MASK || info->invflags & ~EBT_STP_MASK ||
5009 + !(info->bitmask & EBT_STP_MASK))
5010 + return -EINVAL;
5011 + if (datalen != len)
5012 + return -EINVAL;
5013 + /* Make sure the match only receives stp frames */
5014 + if (memcmp(e->destmac, bridge_ula, ETH_ALEN) ||
5015 + memcmp(e->destmsk, msk, ETH_ALEN) || !(e->bitmask & EBT_DESTMAC))
5016 + return -EINVAL;
5017 +
5018 + return 0;
5019 +}
5020 +
5021 +static struct ebt_match filter_stp =
5022 +{
5023 + .name = EBT_STP_MATCH,
5024 + .match = ebt_filter_stp,
5025 + .check = ebt_stp_check,
5026 + .me = THIS_MODULE,
5027 +};
5028 +
5029 +static int __init init(void)
5030 +{
5031 + return ebt_register_match(&filter_stp);
5032 +}
5033 +
5034 +static void __exit fini(void)
5035 +{
5036 + ebt_unregister_match(&filter_stp);
5037 +}
5038 +
5039 +module_init(init);
5040 +module_exit(fini);
5041 +EXPORT_NO_SYMBOLS;
5042 +MODULE_LICENSE("GPL");
5043 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_ulog.c linux-ebtables/net/bridge/netfilter/ebt_ulog.c
5044 --- linux-mips-cvs/net/bridge/netfilter/ebt_ulog.c 1970-01-01 01:00:00.000000000 +0100
5045 +++ linux-ebtables/net/bridge/netfilter/ebt_ulog.c 2005-02-07 05:52:50.000000000 +0100
5046 @@ -0,0 +1,281 @@
5047 +/*
5048 + * netfilter module for userspace bridged Ethernet frames logging daemons
5049 + *
5050 + * Authors:
5051 + * Bart De Schuymer <bdschuym@pandora.be>
5052 + *
5053 + * November, 2004
5054 + *
5055 + * Based on ipt_ULOG.c, which is
5056 + * (C) 2000-2002 by Harald Welte <laforge@netfilter.org>
5057 + *
5058 + * This module accepts two parameters:
5059 + *
5060 + * nlbufsiz:
5061 + * The parameter specifies how big the buffer for each netlink multicast
5062 + * group is. e.g. If you say nlbufsiz=8192, up to eight kb of packets will
5063 + * get accumulated in the kernel until they are sent to userspace. It is
5064 + * NOT possible to allocate more than 128kB, and it is strongly discouraged,
5065 + * because atomically allocating 128kB inside the network rx softirq is not
5066 + * reliable. Please also keep in mind that this buffer size is allocated for
5067 + * each nlgroup you are using, so the total kernel memory usage increases
5068 + * by that factor.
5069 + *
5070 + * flushtimeout:
5071 + * Specify, after how many hundredths of a second the queue should be
5072 + * flushed even if it is not full yet.
5073 + *
5074 + */
5075 +
5076 +#include <linux/module.h>
5077 +#include <linux/config.h>
5078 +#include <linux/spinlock.h>
5079 +#include <linux/socket.h>
5080 +#include <linux/skbuff.h>
5081 +#include <linux/kernel.h>
5082 +#include <linux/timer.h>
5083 +#include <linux/netlink.h>
5084 +#include <linux/netdevice.h>
5085 +#include <linux/module.h>
5086 +#include <linux/netfilter_bridge/ebtables.h>
5087 +#include <linux/netfilter_bridge/ebt_ulog.h>
5088 +#include <net/sock.h>
5089 +#include "../br_private.h"
5090 +
5091 +#define PRINTR(format, args...) do { if (net_ratelimit()) \
5092 + printk(format , ## args); } while (0)
5093 +
5094 +static unsigned int nlbufsiz = 4096;
5095 +MODULE_PARM(nlbufsiz, "i");
5096 +MODULE_PARM_DESC(nlbufsiz, "netlink buffer size (number of bytes) "
5097 + "(defaults to 4096)");
5098 +
5099 +static unsigned int flushtimeout = 10;
5100 +MODULE_PARM(flushtimeout, "i");
5101 +MODULE_PARM_DESC(flushtimeout, "buffer flush timeout (hundredths of a second) "
5102 + "(defaults to 10)");
5103 +
5104 +typedef struct {
5105 + unsigned int qlen; /* number of nlmsgs' in the skb */
5106 + struct nlmsghdr *lastnlh; /* netlink header of last msg in skb */
5107 + struct sk_buff *skb; /* the pre-allocated skb */
5108 + struct timer_list timer; /* the timer function */
5109 + spinlock_t lock; /* the per-queue lock */
5110 +} ebt_ulog_buff_t;
5111 +
5112 +static ebt_ulog_buff_t ulog_buffers[EBT_ULOG_MAXNLGROUPS];
5113 +static struct sock *ebtlognl;
5114 +
5115 +/* send one ulog_buff_t to userspace */
5116 +static void ulog_send(unsigned int nlgroup)
5117 +{
5118 + ebt_ulog_buff_t *ub = &ulog_buffers[nlgroup];
5119 +
5120 + if (timer_pending(&ub->timer))
5121 + del_timer(&ub->timer);
5122 +
5123 + /* last nlmsg needs NLMSG_DONE */
5124 + if (ub->qlen > 1)
5125 + ub->lastnlh->nlmsg_type = NLMSG_DONE;
5126 +
5127 + NETLINK_CB(ub->skb).dst_groups = 1 << nlgroup;
5128 + netlink_broadcast(ebtlognl, ub->skb, 0, 1 << nlgroup, GFP_ATOMIC);
5129 +
5130 + ub->qlen = 0;
5131 + ub->skb = NULL;
5132 +}
5133 +
5134 +/* timer function to flush queue in flushtimeout time */
5135 +static void ulog_timer(unsigned long data)
5136 +{
5137 + spin_lock_bh(&ulog_buffers[data].lock);
5138 + if (ulog_buffers[data].skb)
5139 + ulog_send(data);
5140 + spin_unlock_bh(&ulog_buffers[data].lock);
5141 +}
5142 +
5143 +static struct sk_buff *ulog_alloc_skb(unsigned int size)
5144 +{
5145 + struct sk_buff *skb;
5146 +
5147 + skb = alloc_skb(nlbufsiz, GFP_ATOMIC);
5148 + if (!skb) {
5149 + PRINTR(KERN_ERR "ebt_ulog: can't alloc whole buffer "
5150 + "of size %ub!\n", nlbufsiz);
5151 + if (size < nlbufsiz) {
5152 + /* try to allocate only as much as we need for
5153 + * current packet */
5154 + skb = alloc_skb(size, GFP_ATOMIC);
5155 + if (!skb)
5156 + PRINTR(KERN_ERR "ebt_ulog: can't even allocate "
5157 + "buffer of size %ub\n", size);
5158 + }
5159 + }
5160 +
5161 + return skb;
5162 +}
5163 +
5164 +static void ebt_ulog(const struct sk_buff *skb, unsigned int hooknr,
5165 + const struct net_device *in, const struct net_device *out,
5166 + const void *data, unsigned int datalen)
5167 +{
5168 + ebt_ulog_packet_msg_t *pm;
5169 + size_t size, copy_len;
5170 + struct nlmsghdr *nlh;
5171 + struct ebt_ulog_info *loginfo = (struct ebt_ulog_info *)data;
5172 + unsigned int group = loginfo->nlgroup;
5173 + ebt_ulog_buff_t *ub = &ulog_buffers[group];
5174 + spinlock_t *lock = &ub->lock;
5175 +
5176 + if ((loginfo->cprange == 0) ||
5177 + (loginfo->cprange > skb->len + ETH_HLEN))
5178 + copy_len = skb->len + ETH_HLEN;
5179 + else
5180 + copy_len = loginfo->cprange;
5181 +
5182 + size = NLMSG_SPACE(sizeof(*pm) + copy_len);
5183 +
5184 + spin_lock_bh(lock);
5185 +
5186 + if (!ub->skb) {
5187 + if (!(ub->skb = ulog_alloc_skb(size)))
5188 + goto alloc_failure;
5189 + } else if (size > skb_tailroom(ub->skb)) {
5190 + ulog_send(group);
5191 +
5192 + if (!(ub->skb = ulog_alloc_skb(size)))
5193 + goto alloc_failure;
5194 + }
5195 +
5196 + nlh = NLMSG_PUT(ub->skb, 0, ub->qlen, 0,
5197 + size - NLMSG_ALIGN(sizeof(*nlh)));
5198 + ub->qlen++;
5199 +
5200 + pm = NLMSG_DATA(nlh);
5201 +
5202 + /* Fill in the ulog data */
5203 + do_gettimeofday(&pm->stamp);
5204 + if (ub->qlen == 1)
5205 + ub->skb->stamp = pm->stamp;
5206 + pm->data_len = copy_len;
5207 + pm->mark = skb->nfmark;
5208 + pm->hook = hooknr;
5209 + if (loginfo->prefix != NULL)
5210 + strcpy(pm->prefix, loginfo->prefix);
5211 + else
5212 + *(pm->prefix) = '\0';
5213 +
5214 + if (in) {
5215 + strcpy(pm->physindev, in->name);
5216 + strcpy(pm->indev, in->br_port->br->dev.name);
5217 + } else
5218 + pm->indev[0] = pm->physindev[0] = '\0';
5219 +
5220 + if (out) {
5221 + strcpy(pm->physoutdev, out->name);
5222 + strcpy(pm->outdev, out->br_port->br->dev.name);
5223 + } else
5224 + pm->outdev[0] = pm->physoutdev[0] = '\0';
5225 +
5226 + if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
5227 + BUG();
5228 +
5229 + if (ub->qlen > 1)
5230 + ub->lastnlh->nlmsg_flags |= NLM_F_MULTI;
5231 +
5232 + ub->lastnlh = nlh;
5233 +
5234 + if (ub->qlen >= loginfo->qthreshold)
5235 + ulog_send(group);
5236 + else if (!timer_pending(&ub->timer)) {
5237 + ub->timer.expires = jiffies + flushtimeout * HZ / 100;
5238 + add_timer(&ub->timer);
5239 + }
5240 +
5241 +unlock:
5242 + spin_unlock_bh(lock);
5243 +
5244 + return;
5245 +
5246 +nlmsg_failure:
5247 + PRINTR(KERN_ERR "ebt_ULOG: error during NLMSG_PUT.\n");
5248 + goto unlock;
5249 +alloc_failure:
5250 + goto unlock;
5251 +}
5252 +
5253 +static int ebt_ulog_check(const char *tablename, unsigned int hookmask,
5254 + const struct ebt_entry *e, void *data, unsigned int datalen)
5255 +{
5256 + struct ebt_ulog_info *loginfo = (struct ebt_ulog_info *)data;
5257 +
5258 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ulog_info)) ||
5259 + loginfo->nlgroup > 31)
5260 + return -EINVAL;
5261 +
5262 + loginfo->prefix[EBT_ULOG_PREFIX_LEN - 1] = '\0';
5263 +
5264 + if (loginfo->qthreshold > EBT_ULOG_MAX_QLEN)
5265 + loginfo->qthreshold = EBT_ULOG_MAX_QLEN;
5266 +
5267 + return 0;
5268 +}
5269 +
5270 +static struct ebt_watcher ulog = {
5271 + {NULL, NULL}, EBT_ULOG_WATCHER, ebt_ulog, ebt_ulog_check, NULL,
5272 + THIS_MODULE
5273 +};
5274 +
5275 +static int __init init(void)
5276 +{
5277 + int i, ret = 0;
5278 +
5279 + if (nlbufsiz >= 128*1024) {
5280 + printk(KERN_NOTICE "ebt_ulog: Netlink buffer has to be <= 128kB,"
5281 + " please try a smaller nlbufsiz parameter.\n");
5282 + return -EINVAL;
5283 + }
5284 +
5285 + /* initialize ulog_buffers */
5286 + for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
5287 + init_timer(&ulog_buffers[i].timer);
5288 + ulog_buffers[i].timer.function = ulog_timer;
5289 + ulog_buffers[i].timer.data = i;
5290 + ulog_buffers[i].lock = SPIN_LOCK_UNLOCKED;
5291 + }
5292 +
5293 + ebtlognl = netlink_kernel_create(NETLINK_NFLOG, NULL);
5294 + if (!ebtlognl)
5295 + ret = -ENOMEM;
5296 + else if ((ret = ebt_register_watcher(&ulog)))
5297 + sock_release(ebtlognl->socket);
5298 +
5299 + return ret;
5300 +}
5301 +
5302 +static void __exit fini(void)
5303 +{
5304 + ebt_ulog_buff_t *ub;
5305 + int i;
5306 +
5307 + ebt_unregister_watcher(&ulog);
5308 + for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
5309 + ub = &ulog_buffers[i];
5310 + if (timer_pending(&ub->timer))
5311 + del_timer(&ub->timer);
5312 + spin_lock_bh(&ub->lock);
5313 + if (ub->skb) {
5314 + kfree_skb(ub->skb);
5315 + ub->skb = NULL;
5316 + }
5317 + spin_unlock_bh(&ub->lock);
5318 + }
5319 + sock_release(ebtlognl->socket);
5320 +}
5321 +
5322 +module_init(init);
5323 +module_exit(fini);
5324 +MODULE_LICENSE("GPL");
5325 +MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
5326 +MODULE_DESCRIPTION("ebtables userspace logging module for bridged Ethernet"
5327 + " frames");
5328 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_vlan.c linux-ebtables/net/bridge/netfilter/ebt_vlan.c
5329 --- linux-mips-cvs/net/bridge/netfilter/ebt_vlan.c 1970-01-01 01:00:00.000000000 +0100
5330 +++ linux-ebtables/net/bridge/netfilter/ebt_vlan.c 2005-02-07 05:52:50.000000000 +0100
5331 @@ -0,0 +1,259 @@
5332 +/*
5333 + * Description: EBTables 802.1Q match extension kernelspace module.
5334 + * Authors: Nick Fedchik <nick@fedchik.org.ua>
5335 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
5336 + *
5337 + * This program is free software; you can redistribute it and/or modify
5338 + * it under the terms of the GNU General Public License as published by
5339 + * the Free Software Foundation; either version 2 of the License, or
5340 + * (at your option) any later version.
5341 + *
5342 + * This program is distributed in the hope that it will be useful,
5343 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5344 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5345 + * GNU General Public License for more details.
5346 + *
5347 + * You should have received a copy of the GNU General Public License
5348 + * along with this program; if not, write to the Free Software
5349 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
5350 + */
5351 +
5352 +#include <linux/if_ether.h>
5353 +#include <linux/if_vlan.h>
5354 +#include <linux/module.h>
5355 +#include <linux/netfilter_bridge/ebtables.h>
5356 +#include <linux/netfilter_bridge/ebt_vlan.h>
5357 +
5358 +static unsigned char debug;
5359 +#define MODULE_VERSION "0.6"
5360 +
5361 +MODULE_PARM(debug, "0-1b");
5362 +MODULE_PARM_DESC(debug, "debug=1 is turn on debug messages");
5363 +MODULE_AUTHOR("Nick Fedchik <nick@fedchik.org.ua>");
5364 +MODULE_DESCRIPTION("802.1Q match module (ebtables extension), v"
5365 + MODULE_VERSION);
5366 +MODULE_LICENSE("GPL");
5367 +
5368 +
5369 +#define DEBUG_MSG(args...) if (debug) printk (KERN_DEBUG "ebt_vlan: " args)
5370 +#define INV_FLAG(_inv_flag_) (info->invflags & _inv_flag_) ? "!" : ""
5371 +#define GET_BITMASK(_BIT_MASK_) info->bitmask & _BIT_MASK_
5372 +#define SET_BITMASK(_BIT_MASK_) info->bitmask |= _BIT_MASK_
5373 +#define EXIT_ON_MISMATCH(_MATCH_,_MASK_) if (!((info->_MATCH_ == _MATCH_)^!!(info->invflags & _MASK_))) return 1;
5374 +
5375 +/*
5376 + * Function description: ebt_filter_vlan() is main engine for
5377 + * checking passed 802.1Q frame according to
5378 + * the passed extension parameters (in the *data buffer)
5379 + * ebt_filter_vlan() is called after successfull check the rule params
5380 + * by ebt_check_vlan() function.
5381 + * Parameters:
5382 + * const struct sk_buff *skb - pointer to passed ethernet frame buffer
5383 + * const void *data - pointer to passed extension parameters
5384 + * unsigned int datalen - length of passed *data buffer
5385 + * const struct net_device *in -
5386 + * const struct net_device *out -
5387 + * const struct ebt_counter *c -
5388 + * Returned values:
5389 + * 0 - ok (all rule params matched)
5390 + * 1 - miss (rule params not acceptable to the parsed frame)
5391 + */
5392 +static int
5393 +ebt_filter_vlan(const struct sk_buff *skb,
5394 + const struct net_device *in,
5395 + const struct net_device *out,
5396 + const void *data, unsigned int datalen)
5397 +{
5398 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data; /* userspace data */
5399 + struct vlan_ethhdr *frame = (struct vlan_ethhdr *) skb->mac.raw; /* Passed tagged frame */
5400 +
5401 + unsigned short TCI; /* Whole TCI, given from parsed frame */
5402 + unsigned short id; /* VLAN ID, given from frame TCI */
5403 + unsigned char prio; /* user_priority, given from frame TCI */
5404 + unsigned short encap; /* VLAN encapsulated Type/Length field, given from orig frame */
5405 +
5406 + /*
5407 + * Tag Control Information (TCI) consists of the following elements:
5408 + * - User_priority. The user_priority field is three bits in length,
5409 + * interpreted as a binary number.
5410 + * - Canonical Format Indicator (CFI). The Canonical Format Indicator
5411 + * (CFI) is a single bit flag value. Currently ignored.
5412 + * - VLAN Identifier (VID). The VID is encoded as
5413 + * an unsigned binary number.
5414 + */
5415 + TCI = ntohs(frame->h_vlan_TCI);
5416 + id = TCI & VLAN_VID_MASK;
5417 + prio = (TCI >> 13) & 0x7;
5418 + encap = frame->h_vlan_encapsulated_proto;
5419 +
5420 + /*
5421 + * Checking VLAN Identifier (VID)
5422 + */
5423 + if (GET_BITMASK(EBT_VLAN_ID)) { /* Is VLAN ID parsed? */
5424 + EXIT_ON_MISMATCH(id, EBT_VLAN_ID);
5425 + }
5426 + /*
5427 + * Checking user_priority
5428 + */
5429 + if (GET_BITMASK(EBT_VLAN_PRIO)) { /* Is VLAN user_priority parsed? */
5430 + EXIT_ON_MISMATCH(prio, EBT_VLAN_PRIO);
5431 + }
5432 + /*
5433 + * Checking Encapsulated Proto (Length/Type) field
5434 + */
5435 + if (GET_BITMASK(EBT_VLAN_ENCAP)) { /* Is VLAN Encap parsed? */
5436 + EXIT_ON_MISMATCH(encap, EBT_VLAN_ENCAP);
5437 + }
5438 + /*
5439 + * All possible extension parameters was parsed.
5440 + * If rule never returned by missmatch, then all ok.
5441 + */
5442 + return 0;
5443 +}
5444 +
5445 +/*
5446 + * Function description: ebt_vlan_check() is called when userspace
5447 + * delivers the table entry to the kernel,
5448 + * and to check that userspace doesn't give a bad table.
5449 + * Parameters:
5450 + * const char *tablename - table name string
5451 + * unsigned int hooknr - hook number
5452 + * const struct ebt_entry *e - ebtables entry basic set
5453 + * const void *data - pointer to passed extension parameters
5454 + * unsigned int datalen - length of passed *data buffer
5455 + * Returned values:
5456 + * 0 - ok (all delivered rule params are correct)
5457 + * 1 - miss (rule params is out of range, invalid, incompatible, etc.)
5458 + */
5459 +static int
5460 +ebt_check_vlan(const char *tablename,
5461 + unsigned int hooknr,
5462 + const struct ebt_entry *e, void *data, unsigned int datalen)
5463 +{
5464 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data;
5465 +
5466 + /*
5467 + * Parameters buffer overflow check
5468 + */
5469 + if (datalen != EBT_ALIGN(sizeof(struct ebt_vlan_info))) {
5470 + DEBUG_MSG
5471 + ("passed size %d is not eq to ebt_vlan_info (%d)\n",
5472 + datalen, sizeof(struct ebt_vlan_info));
5473 + return -EINVAL;
5474 + }
5475 +
5476 + /*
5477 + * Is it 802.1Q frame checked?
5478 + */
5479 + if (e->ethproto != __constant_htons(ETH_P_8021Q)) {
5480 + DEBUG_MSG
5481 + ("passed entry proto %2.4X is not 802.1Q (8100)\n",
5482 + (unsigned short) ntohs(e->ethproto));
5483 + return -EINVAL;
5484 + }
5485 +
5486 + /*
5487 + * Check for bitmask range
5488 + * True if even one bit is out of mask
5489 + */
5490 + if (info->bitmask & ~EBT_VLAN_MASK) {
5491 + DEBUG_MSG("bitmask %2X is out of mask (%2X)\n",
5492 + info->bitmask, EBT_VLAN_MASK);
5493 + return -EINVAL;
5494 + }
5495 +
5496 + /*
5497 + * Check for inversion flags range
5498 + */
5499 + if (info->invflags & ~EBT_VLAN_MASK) {
5500 + DEBUG_MSG("inversion flags %2X is out of mask (%2X)\n",
5501 + info->invflags, EBT_VLAN_MASK);
5502 + return -EINVAL;
5503 + }
5504 +
5505 + /*
5506 + * Reserved VLAN ID (VID) values
5507 + * -----------------------------
5508 + * 0 - The null VLAN ID.
5509 + * 1 - The default Port VID (PVID)
5510 + * 0x0FFF - Reserved for implementation use.
5511 + * if_vlan.h: VLAN_GROUP_ARRAY_LEN 4096.
5512 + */
5513 + if (GET_BITMASK(EBT_VLAN_ID)) { /* when vlan-id param was spec-ed */
5514 + if (!!info->id) { /* if id!=0 => check vid range */
5515 + if (info->id > VLAN_GROUP_ARRAY_LEN) {
5516 + DEBUG_MSG
5517 + ("id %d is out of range (1-4096)\n",
5518 + info->id);
5519 + return -EINVAL;
5520 + }
5521 + /*
5522 + * Note: This is valid VLAN-tagged frame point.
5523 + * Any value of user_priority are acceptable,
5524 + * but should be ignored according to 802.1Q Std.
5525 + * So we just drop the prio flag.
5526 + */
5527 + info->bitmask &= ~EBT_VLAN_PRIO;
5528 + }
5529 + /*
5530 + * Else, id=0 (null VLAN ID) => user_priority range (any?)
5531 + */
5532 + }
5533 +
5534 + if (GET_BITMASK(EBT_VLAN_PRIO)) {
5535 + if ((unsigned char) info->prio > 7) {
5536 + DEBUG_MSG
5537 + ("prio %d is out of range (0-7)\n",
5538 + info->prio);
5539 + return -EINVAL;
5540 + }
5541 + }
5542 + /*
5543 + * Check for encapsulated proto range - it is possible to be
5544 + * any value for u_short range.
5545 + * if_ether.h: ETH_ZLEN 60 - Min. octets in frame sans FCS
5546 + */
5547 + if (GET_BITMASK(EBT_VLAN_ENCAP)) {
5548 + if ((unsigned short) ntohs(info->encap) < ETH_ZLEN) {
5549 + DEBUG_MSG
5550 + ("encap frame length %d is less than minimal\n",
5551 + ntohs(info->encap));
5552 + return -EINVAL;
5553 + }
5554 + }
5555 +
5556 + return 0;
5557 +}
5558 +
5559 +static struct ebt_match filter_vlan = {
5560 + {NULL, NULL},
5561 + EBT_VLAN_MATCH,
5562 + ebt_filter_vlan,
5563 + ebt_check_vlan,
5564 + NULL,
5565 + THIS_MODULE
5566 +};
5567 +
5568 +/*
5569 + * Module initialization function.
5570 + */
5571 +static int __init init(void)
5572 +{
5573 + DEBUG_MSG("ebtables 802.1Q extension module v"
5574 + MODULE_VERSION "\n");
5575 + DEBUG_MSG("module debug=%d\n", !!debug);
5576 + return ebt_register_match(&filter_vlan);
5577 +}
5578 +
5579 +/*
5580 + * Module "finalization" function
5581 + */
5582 +static void __exit fini(void)
5583 +{
5584 + ebt_unregister_match(&filter_vlan);
5585 +}
5586 +
5587 +module_init(init);
5588 +module_exit(fini);
5589 +
5590 +EXPORT_NO_SYMBOLS;
5591 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebtable_broute.c linux-ebtables/net/bridge/netfilter/ebtable_broute.c
5592 --- linux-mips-cvs/net/bridge/netfilter/ebtable_broute.c 1970-01-01 01:00:00.000000000 +0100
5593 +++ linux-ebtables/net/bridge/netfilter/ebtable_broute.c 2005-02-07 05:52:50.000000000 +0100
5594 @@ -0,0 +1,79 @@
5595 +/*
5596 + * ebtable_broute
5597 + *
5598 + * Authors:
5599 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
5600 + *
5601 + * April, 2002
5602 + *
5603 + * This table lets you choose between routing and bridging for frames
5604 + * entering on a bridge enslaved nic. This table is traversed before any
5605 + * other ebtables table. See net/bridge/br_input.c.
5606 + */
5607 +
5608 +#include <linux/netfilter_bridge/ebtables.h>
5609 +#include <linux/module.h>
5610 +#include <linux/if_bridge.h>
5611 +#include <linux/brlock.h>
5612 +
5613 +// EBT_ACCEPT means the frame will be bridged
5614 +// EBT_DROP means the frame will be routed
5615 +static struct ebt_entries initial_chain =
5616 + {0, "BROUTING", 0, EBT_ACCEPT, 0};
5617 +
5618 +static struct ebt_replace initial_table =
5619 +{
5620 + "broute", 1 << NF_BR_BROUTING, 0, sizeof(struct ebt_entries),
5621 + { [NF_BR_BROUTING]&initial_chain}, 0, NULL, (char *)&initial_chain
5622 +};
5623 +
5624 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
5625 +{
5626 + if (valid_hooks & ~(1 << NF_BR_BROUTING))
5627 + return -EINVAL;
5628 + return 0;
5629 +}
5630 +
5631 +static struct ebt_table broute_table =
5632 +{
5633 + {NULL, NULL}, "broute", &initial_table, 1 << NF_BR_BROUTING,
5634 + RW_LOCK_UNLOCKED, check, NULL
5635 +};
5636 +
5637 +static int ebt_broute(struct sk_buff **pskb)
5638 +{
5639 + int ret;
5640 +
5641 + ret = ebt_do_table(NF_BR_BROUTING, pskb, (*pskb)->dev, NULL,
5642 + &broute_table);
5643 + if (ret == NF_DROP)
5644 + return 1; // route it
5645 + return 0; // bridge it
5646 +}
5647 +
5648 +static int __init init(void)
5649 +{
5650 + int ret;
5651 +
5652 + ret = ebt_register_table(&broute_table);
5653 + if (ret < 0)
5654 + return ret;
5655 + br_write_lock_bh(BR_NETPROTO_LOCK);
5656 + // see br_input.c
5657 + br_should_route_hook = ebt_broute;
5658 + br_write_unlock_bh(BR_NETPROTO_LOCK);
5659 + return ret;
5660 +}
5661 +
5662 +static void __exit fini(void)
5663 +{
5664 + br_write_lock_bh(BR_NETPROTO_LOCK);
5665 + br_should_route_hook = NULL;
5666 + br_write_unlock_bh(BR_NETPROTO_LOCK);
5667 + ebt_unregister_table(&broute_table);
5668 +}
5669 +
5670 +module_init(init);
5671 +module_exit(fini);
5672 +EXPORT_NO_SYMBOLS;
5673 +MODULE_LICENSE("GPL");
5674 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebtable_filter.c linux-ebtables/net/bridge/netfilter/ebtable_filter.c
5675 --- linux-mips-cvs/net/bridge/netfilter/ebtable_filter.c 1970-01-01 01:00:00.000000000 +0100
5676 +++ linux-ebtables/net/bridge/netfilter/ebtable_filter.c 2005-02-07 05:52:50.000000000 +0100
5677 @@ -0,0 +1,90 @@
5678 +/*
5679 + * ebtable_filter
5680 + *
5681 + * Authors:
5682 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
5683 + *
5684 + * April, 2002
5685 + *
5686 + */
5687 +
5688 +#include <linux/netfilter_bridge/ebtables.h>
5689 +#include <linux/module.h>
5690 +
5691 +#define FILTER_VALID_HOOKS ((1 << NF_BR_LOCAL_IN) | (1 << NF_BR_FORWARD) | \
5692 + (1 << NF_BR_LOCAL_OUT))
5693 +
5694 +static struct ebt_entries initial_chains[] =
5695 +{
5696 + {0, "INPUT", 0, EBT_ACCEPT, 0},
5697 + {0, "FORWARD", 0, EBT_ACCEPT, 0},
5698 + {0, "OUTPUT", 0, EBT_ACCEPT, 0}
5699 +};
5700 +
5701 +static struct ebt_replace initial_table =
5702 +{
5703 + "filter", FILTER_VALID_HOOKS, 0, 3 * sizeof(struct ebt_entries),
5704 + { [NF_BR_LOCAL_IN]&initial_chains[0], [NF_BR_FORWARD]&initial_chains[1],
5705 + [NF_BR_LOCAL_OUT]&initial_chains[2] }, 0, NULL, (char *)initial_chains
5706 +};
5707 +
5708 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
5709 +{
5710 + if (valid_hooks & ~FILTER_VALID_HOOKS)
5711 + return -EINVAL;
5712 + return 0;
5713 +}
5714 +
5715 +static struct ebt_table frame_filter =
5716 +{
5717 + {NULL, NULL}, "filter", &initial_table, FILTER_VALID_HOOKS,
5718 + RW_LOCK_UNLOCKED, check, NULL
5719 +};
5720 +
5721 +static unsigned int
5722 +ebt_hook (unsigned int hook, struct sk_buff **pskb, const struct net_device *in,
5723 + const struct net_device *out, int (*okfn)(struct sk_buff *))
5724 +{
5725 + return ebt_do_table(hook, pskb, in, out, &frame_filter);
5726 +}
5727 +
5728 +static struct nf_hook_ops ebt_ops_filter[] = {
5729 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_LOCAL_IN,
5730 + NF_BR_PRI_FILTER_BRIDGED},
5731 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_FORWARD,
5732 + NF_BR_PRI_FILTER_BRIDGED},
5733 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_LOCAL_OUT,
5734 + NF_BR_PRI_FILTER_OTHER}
5735 +};
5736 +
5737 +static int __init init(void)
5738 +{
5739 + int i, j, ret;
5740 +
5741 + ret = ebt_register_table(&frame_filter);
5742 + if (ret < 0)
5743 + return ret;
5744 + for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
5745 + if ((ret = nf_register_hook(&ebt_ops_filter[i])) < 0)
5746 + goto cleanup;
5747 + return ret;
5748 +cleanup:
5749 + for (j = 0; j < i; j++)
5750 + nf_unregister_hook(&ebt_ops_filter[j]);
5751 + ebt_unregister_table(&frame_filter);
5752 + return ret;
5753 +}
5754 +
5755 +static void __exit fini(void)
5756 +{
5757 + int i;
5758 +
5759 + for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
5760 + nf_unregister_hook(&ebt_ops_filter[i]);
5761 + ebt_unregister_table(&frame_filter);
5762 +}
5763 +
5764 +module_init(init);
5765 +module_exit(fini);
5766 +EXPORT_NO_SYMBOLS;
5767 +MODULE_LICENSE("GPL");
5768 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebtable_nat.c linux-ebtables/net/bridge/netfilter/ebtable_nat.c
5769 --- linux-mips-cvs/net/bridge/netfilter/ebtable_nat.c 1970-01-01 01:00:00.000000000 +0100
5770 +++ linux-ebtables/net/bridge/netfilter/ebtable_nat.c 2005-02-07 05:52:50.000000000 +0100
5771 @@ -0,0 +1,96 @@
5772 +/*
5773 + * ebtable_nat
5774 + *
5775 + * Authors:
5776 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
5777 + *
5778 + * April, 2002
5779 + *
5780 + */
5781 +
5782 +#include <linux/netfilter_bridge/ebtables.h>
5783 +#include <linux/module.h>
5784 +#define NAT_VALID_HOOKS ((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT) | \
5785 + (1 << NF_BR_POST_ROUTING))
5786 +
5787 +static struct ebt_entries initial_chains[] =
5788 +{
5789 + {0, "PREROUTING", 0, EBT_ACCEPT, 0},
5790 + {0, "OUTPUT", 0, EBT_ACCEPT, 0},
5791 + {0, "POSTROUTING", 0, EBT_ACCEPT, 0}
5792 +};
5793 +
5794 +static struct ebt_replace initial_table =
5795 +{
5796 + "nat", NAT_VALID_HOOKS, 0, 3 * sizeof(struct ebt_entries),
5797 + { [NF_BR_PRE_ROUTING]&initial_chains[0], [NF_BR_LOCAL_OUT]&initial_chains[1],
5798 + [NF_BR_POST_ROUTING]&initial_chains[2] }, 0, NULL, (char *)initial_chains
5799 +};
5800 +
5801 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
5802 +{
5803 + if (valid_hooks & ~NAT_VALID_HOOKS)
5804 + return -EINVAL;
5805 + return 0;
5806 +}
5807 +
5808 +static struct ebt_table frame_nat =
5809 +{
5810 + {NULL, NULL}, "nat", &initial_table, NAT_VALID_HOOKS,
5811 + RW_LOCK_UNLOCKED, check, NULL
5812 +};
5813 +
5814 +static unsigned int
5815 +ebt_nat_dst(unsigned int hook, struct sk_buff **pskb, const struct net_device *in
5816 + , const struct net_device *out, int (*okfn)(struct sk_buff *))
5817 +{
5818 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
5819 +}
5820 +
5821 +static unsigned int
5822 +ebt_nat_src(unsigned int hook, struct sk_buff **pskb, const struct net_device *in
5823 + , const struct net_device *out, int (*okfn)(struct sk_buff *))
5824 +{
5825 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
5826 +}
5827 +
5828 +static struct nf_hook_ops ebt_ops_nat[] = {
5829 + { { NULL, NULL }, ebt_nat_dst, PF_BRIDGE, NF_BR_LOCAL_OUT,
5830 + NF_BR_PRI_NAT_DST_OTHER},
5831 + { { NULL, NULL }, ebt_nat_src, PF_BRIDGE, NF_BR_POST_ROUTING,
5832 + NF_BR_PRI_NAT_SRC},
5833 + { { NULL, NULL }, ebt_nat_dst, PF_BRIDGE, NF_BR_PRE_ROUTING,
5834 + NF_BR_PRI_NAT_DST_BRIDGED},
5835 +};
5836 +
5837 +static int __init init(void)
5838 +{
5839 + int i, ret, j;
5840 +
5841 + ret = ebt_register_table(&frame_nat);
5842 + if (ret < 0)
5843 + return ret;
5844 + for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
5845 + if ((ret = nf_register_hook(&ebt_ops_nat[i])) < 0)
5846 + goto cleanup;
5847 + return ret;
5848 +cleanup:
5849 + for (j = 0; j < i; j++)
5850 + nf_unregister_hook(&ebt_ops_nat[j]);
5851 + ebt_unregister_table(&frame_nat);
5852 + return ret;
5853 +}
5854 +
5855 +static void __exit fini(void)
5856 +{
5857 + int i;
5858 +
5859 + for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
5860 + nf_unregister_hook(&ebt_ops_nat[i]);
5861 + ebt_unregister_table(&frame_nat);
5862 +}
5863 +
5864 +module_init(init);
5865 +module_exit(fini);
5866 +EXPORT_NO_SYMBOLS;
5867 +MODULE_LICENSE("GPL");
5868 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebtables.c linux-ebtables/net/bridge/netfilter/ebtables.c
5869 --- linux-mips-cvs/net/bridge/netfilter/ebtables.c 1970-01-01 01:00:00.000000000 +0100
5870 +++ linux-ebtables/net/bridge/netfilter/ebtables.c 2005-02-07 05:52:50.000000000 +0100
5871 @@ -0,0 +1,1496 @@
5872 +/*
5873 + * ebtables
5874 + *
5875 + * Author:
5876 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
5877 + *
5878 + * ebtables.c,v 2.0, July, 2002
5879 + *
5880 + * This code is stongly inspired on the iptables code which is
5881 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
5882 + *
5883 + * This program is free software; you can redistribute it and/or
5884 + * modify it under the terms of the GNU General Public License
5885 + * as published by the Free Software Foundation; either version
5886 + * 2 of the License, or (at your option) any later version.
5887 + */
5888 +
5889 +// used for print_string
5890 +#include <linux/sched.h>
5891 +#include <linux/tty.h>
5892 +
5893 +#include <linux/kmod.h>
5894 +#include <linux/module.h>
5895 +#include <linux/vmalloc.h>
5896 +#include <linux/netfilter_bridge/ebtables.h>
5897 +#include <linux/spinlock.h>
5898 +#include <asm/uaccess.h>
5899 +#include <linux/smp.h>
5900 +#include <net/sock.h>
5901 +// needed for logical [in,out]-dev filtering
5902 +#include "../br_private.h"
5903 +
5904 +// list_named_find
5905 +#define ASSERT_READ_LOCK(x)
5906 +#define ASSERT_WRITE_LOCK(x)
5907 +#include <linux/netfilter_ipv4/listhelp.h>
5908 +
5909 +#if 0 // use this for remote debugging
5910 +// Copyright (C) 1998 by Ori Pomerantz
5911 +// Print the string to the appropriate tty, the one
5912 +// the current task uses
5913 +static void print_string(char *str)
5914 +{
5915 + struct tty_struct *my_tty;
5916 +
5917 + /* The tty for the current task */
5918 + my_tty = current->tty;
5919 + if (my_tty != NULL) {
5920 + (*(my_tty->driver).write)(my_tty, 0, str, strlen(str));
5921 + (*(my_tty->driver).write)(my_tty, 0, "\015\012", 2);
5922 + }
5923 +}
5924 +
5925 +#define BUGPRINT(args) print_string(args);
5926 +#else
5927 +#define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\
5928 + "report to author: "format, ## args)
5929 +// #define BUGPRINT(format, args...)
5930 +#endif
5931 +#define MEMPRINT(format, args...) printk("kernel msg: ebtables "\
5932 + ": out of memory: "format, ## args)
5933 +// #define MEMPRINT(format, args...)
5934 +
5935 +
5936 +
5937 +// Each cpu has its own set of counters, so there is no need for write_lock in
5938 +// the softirq
5939 +// For reading or updating the counters, the user context needs to
5940 +// get a write_lock
5941 +
5942 +// The size of each set of counters is altered to get cache alignment
5943 +#define SMP_ALIGN(x) (((x) + SMP_CACHE_BYTES-1) & ~(SMP_CACHE_BYTES-1))
5944 +#define COUNTER_OFFSET(n) (SMP_ALIGN(n * sizeof(struct ebt_counter)))
5945 +#define COUNTER_BASE(c, n, cpu) ((struct ebt_counter *)(((char *)c) + \
5946 + COUNTER_OFFSET(n) * cpu))
5947 +
5948 +
5949 +
5950 +static DECLARE_MUTEX(ebt_mutex);
5951 +static LIST_HEAD(ebt_tables);
5952 +static LIST_HEAD(ebt_targets);
5953 +static LIST_HEAD(ebt_matches);
5954 +static LIST_HEAD(ebt_watchers);
5955 +
5956 +static struct ebt_target ebt_standard_target =
5957 +{ {NULL, NULL}, EBT_STANDARD_TARGET, NULL, NULL, NULL, NULL};
5958 +
5959 +static inline int ebt_do_watcher (struct ebt_entry_watcher *w,
5960 + const struct sk_buff *skb, unsigned int hooknr, const struct net_device *in,
5961 + const struct net_device *out)
5962 +{
5963 + w->u.watcher->watcher(skb, hooknr, in, out, w->data,
5964 + w->watcher_size);
5965 + // watchers don't give a verdict
5966 + return 0;
5967 +}
5968 +
5969 +static inline int ebt_do_match (struct ebt_entry_match *m,
5970 + const struct sk_buff *skb, const struct net_device *in,
5971 + const struct net_device *out)
5972 +{
5973 + return m->u.match->match(skb, in, out, m->data,
5974 + m->match_size);
5975 +}
5976 +
5977 +static inline int ebt_dev_check(char *entry, const struct net_device *device)
5978 +{
5979 + int i = 0;
5980 + char *devname = device->name;
5981 +
5982 + if (*entry == '\0')
5983 + return 0;
5984 + if (!device)
5985 + return 1;
5986 + /* 1 is the wildcard token */
5987 + while (entry[i] != '\0' && entry[i] != 1 && entry[i] == devname[i])
5988 + i++;
5989 + return (devname[i] != entry[i] && entry[i] != 1);
5990 +}
5991 +
5992 +#define FWINV2(bool,invflg) ((bool) ^ !!(e->invflags & invflg))
5993 +// process standard matches
5994 +static inline int ebt_basic_match(struct ebt_entry *e, struct ethhdr *h,
5995 + const struct net_device *in, const struct net_device *out)
5996 +{
5997 + int verdict, i;
5998 +
5999 + if (e->bitmask & EBT_802_3) {
6000 + if (FWINV2(ntohs(h->h_proto) >= 1536, EBT_IPROTO))
6001 + return 1;
6002 + } else if (!(e->bitmask & EBT_NOPROTO) &&
6003 + FWINV2(e->ethproto != h->h_proto, EBT_IPROTO))
6004 + return 1;
6005 +
6006 + if (FWINV2(ebt_dev_check(e->in, in), EBT_IIN))
6007 + return 1;
6008 + if (FWINV2(ebt_dev_check(e->out, out), EBT_IOUT))
6009 + return 1;
6010 + if ((!in || !in->br_port) ? 0 : FWINV2(ebt_dev_check(
6011 + e->logical_in, &in->br_port->br->dev), EBT_ILOGICALIN))
6012 + return 1;
6013 + if ((!out || !out->br_port) ? 0 : FWINV2(ebt_dev_check(
6014 + e->logical_out, &out->br_port->br->dev), EBT_ILOGICALOUT))
6015 + return 1;
6016 +
6017 + if (e->bitmask & EBT_SOURCEMAC) {
6018 + verdict = 0;
6019 + for (i = 0; i < 6; i++)
6020 + verdict |= (h->h_source[i] ^ e->sourcemac[i]) &
6021 + e->sourcemsk[i];
6022 + if (FWINV2(verdict != 0, EBT_ISOURCE) )
6023 + return 1;
6024 + }
6025 + if (e->bitmask & EBT_DESTMAC) {
6026 + verdict = 0;
6027 + for (i = 0; i < 6; i++)
6028 + verdict |= (h->h_dest[i] ^ e->destmac[i]) &
6029 + e->destmsk[i];
6030 + if (FWINV2(verdict != 0, EBT_IDEST) )
6031 + return 1;
6032 + }
6033 + return 0;
6034 +}
6035 +
6036 +// Do some firewalling
6037 +unsigned int ebt_do_table (unsigned int hook, struct sk_buff **pskb,
6038 + const struct net_device *in, const struct net_device *out,
6039 + struct ebt_table *table)
6040 +{
6041 + int i, nentries;
6042 + struct ebt_entry *point;
6043 + struct ebt_counter *counter_base, *cb_base;
6044 + struct ebt_entry_target *t;
6045 + int verdict, sp = 0;
6046 + struct ebt_chainstack *cs;
6047 + struct ebt_entries *chaininfo;
6048 + char *base;
6049 + struct ebt_table_info *private = table->private;
6050 +
6051 + read_lock_bh(&table->lock);
6052 + cb_base = COUNTER_BASE(private->counters, private->nentries,
6053 + cpu_number_map(smp_processor_id()));
6054 + if (private->chainstack)
6055 + cs = private->chainstack[cpu_number_map(smp_processor_id())];
6056 + else
6057 + cs = NULL;
6058 + chaininfo = private->hook_entry[hook];
6059 + nentries = private->hook_entry[hook]->nentries;
6060 + point = (struct ebt_entry *)(private->hook_entry[hook]->data);
6061 + counter_base = cb_base + private->hook_entry[hook]->counter_offset;
6062 + // base for chain jumps
6063 + base = private->entries;
6064 + i = 0;
6065 + while (i < nentries) {
6066 + if (ebt_basic_match(point, (**pskb).mac.ethernet, in, out))
6067 + goto letscontinue;
6068 +
6069 + if (EBT_MATCH_ITERATE(point, ebt_do_match, *pskb, in, out) != 0)
6070 + goto letscontinue;
6071 +
6072 + // increase counter
6073 + (*(counter_base + i)).pcnt++;
6074 + (*(counter_base + i)).bcnt+=(**pskb).len;
6075 +
6076 + // these should only watch: not modify, nor tell us
6077 + // what to do with the packet
6078 + EBT_WATCHER_ITERATE(point, ebt_do_watcher, *pskb, hook, in,
6079 + out);
6080 +
6081 + t = (struct ebt_entry_target *)
6082 + (((char *)point) + point->target_offset);
6083 + // standard target
6084 + if (!t->u.target->target)
6085 + verdict = ((struct ebt_standard_target *)t)->verdict;
6086 + else
6087 + verdict = t->u.target->target(pskb, hook,
6088 + in, out, t->data, t->target_size);
6089 + if (verdict == EBT_ACCEPT) {
6090 + read_unlock_bh(&table->lock);
6091 + return NF_ACCEPT;
6092 + }
6093 + if (verdict == EBT_DROP) {
6094 + read_unlock_bh(&table->lock);
6095 + return NF_DROP;
6096 + }
6097 + if (verdict == EBT_RETURN) {
6098 +letsreturn:
6099 +#ifdef CONFIG_NETFILTER_DEBUG
6100 + if (sp == 0) {
6101 + BUGPRINT("RETURN on base chain");
6102 + // act like this is EBT_CONTINUE
6103 + goto letscontinue;
6104 + }
6105 +#endif
6106 + sp--;
6107 + // put all the local variables right
6108 + i = cs[sp].n;
6109 + chaininfo = cs[sp].chaininfo;
6110 + nentries = chaininfo->nentries;
6111 + point = cs[sp].e;
6112 + counter_base = cb_base +
6113 + chaininfo->counter_offset;
6114 + continue;
6115 + }
6116 + if (verdict == EBT_CONTINUE)
6117 + goto letscontinue;
6118 +#ifdef CONFIG_NETFILTER_DEBUG
6119 + if (verdict < 0) {
6120 + BUGPRINT("bogus standard verdict\n");
6121 + read_unlock_bh(&table->lock);
6122 + return NF_DROP;
6123 + }
6124 +#endif
6125 + // jump to a udc
6126 + cs[sp].n = i + 1;
6127 + cs[sp].chaininfo = chaininfo;
6128 + cs[sp].e = (struct ebt_entry *)
6129 + (((char *)point) + point->next_offset);
6130 + i = 0;
6131 + chaininfo = (struct ebt_entries *) (base + verdict);
6132 +#ifdef CONFIG_NETFILTER_DEBUG
6133 + if (chaininfo->distinguisher) {
6134 + BUGPRINT("jump to non-chain\n");
6135 + read_unlock_bh(&table->lock);
6136 + return NF_DROP;
6137 + }
6138 +#endif
6139 + nentries = chaininfo->nentries;
6140 + point = (struct ebt_entry *)chaininfo->data;
6141 + counter_base = cb_base + chaininfo->counter_offset;
6142 + sp++;
6143 + continue;
6144 +letscontinue:
6145 + point = (struct ebt_entry *)
6146 + (((char *)point) + point->next_offset);
6147 + i++;
6148 + }
6149 +
6150 + // I actually like this :)
6151 + if (chaininfo->policy == EBT_RETURN)
6152 + goto letsreturn;
6153 + if (chaininfo->policy == EBT_ACCEPT) {
6154 + read_unlock_bh(&table->lock);
6155 + return NF_ACCEPT;
6156 + }
6157 + read_unlock_bh(&table->lock);
6158 + return NF_DROP;
6159 +}
6160 +
6161 +// If it succeeds, returns element and locks mutex
6162 +static inline void *
6163 +find_inlist_lock_noload(struct list_head *head, const char *name, int *error,
6164 + struct semaphore *mutex)
6165 +{
6166 + void *ret;
6167 +
6168 + *error = down_interruptible(mutex);
6169 + if (*error != 0)
6170 + return NULL;
6171 +
6172 + ret = list_named_find(head, name);
6173 + if (!ret) {
6174 + *error = -ENOENT;
6175 + up(mutex);
6176 + }
6177 + return ret;
6178 +}
6179 +
6180 +#ifndef CONFIG_KMOD
6181 +#define find_inlist_lock(h,n,p,e,m) find_inlist_lock_noload((h),(n),(e),(m))
6182 +#else
6183 +static void *
6184 +find_inlist_lock(struct list_head *head, const char *name, const char *prefix,
6185 + int *error, struct semaphore *mutex)
6186 +{
6187 + void *ret;
6188 +
6189 + ret = find_inlist_lock_noload(head, name, error, mutex);
6190 + if (!ret) {
6191 + char modulename[EBT_FUNCTION_MAXNAMELEN + strlen(prefix) + 1];
6192 + strcpy(modulename, prefix);
6193 + strcat(modulename, name);
6194 + request_module(modulename);
6195 + ret = find_inlist_lock_noload(head, name, error, mutex);
6196 + }
6197 + return ret;
6198 +}
6199 +#endif
6200 +
6201 +static inline struct ebt_table *
6202 +find_table_lock(const char *name, int *error, struct semaphore *mutex)
6203 +{
6204 + return find_inlist_lock(&ebt_tables, name, "ebtable_", error, mutex);
6205 +}
6206 +
6207 +static inline struct ebt_match *
6208 +find_match_lock(const char *name, int *error, struct semaphore *mutex)
6209 +{
6210 + return find_inlist_lock(&ebt_matches, name, "ebt_", error, mutex);
6211 +}
6212 +
6213 +static inline struct ebt_watcher *
6214 +find_watcher_lock(const char *name, int *error, struct semaphore *mutex)
6215 +{
6216 + return find_inlist_lock(&ebt_watchers, name, "ebt_", error, mutex);
6217 +}
6218 +
6219 +static inline struct ebt_target *
6220 +find_target_lock(const char *name, int *error, struct semaphore *mutex)
6221 +{
6222 + return find_inlist_lock(&ebt_targets, name, "ebt_", error, mutex);
6223 +}
6224 +
6225 +static inline int
6226 +ebt_check_match(struct ebt_entry_match *m, struct ebt_entry *e,
6227 + const char *name, unsigned int hookmask, unsigned int *cnt)
6228 +{
6229 + struct ebt_match *match;
6230 + int ret;
6231 +
6232 + if (((char *)m) + m->match_size + sizeof(struct ebt_entry_match) >
6233 + ((char *)e) + e->watchers_offset)
6234 + return -EINVAL;
6235 + match = find_match_lock(m->u.name, &ret, &ebt_mutex);
6236 + if (!match)
6237 + return ret;
6238 + m->u.match = match;
6239 + if (match->me)
6240 + __MOD_INC_USE_COUNT(match->me);
6241 + up(&ebt_mutex);
6242 + if (match->check &&
6243 + match->check(name, hookmask, e, m->data, m->match_size) != 0) {
6244 + BUGPRINT("match->check failed\n");
6245 + if (match->me)
6246 + __MOD_DEC_USE_COUNT(match->me);
6247 + return -EINVAL;
6248 + }
6249 + (*cnt)++;
6250 + return 0;
6251 +}
6252 +
6253 +static inline int
6254 +ebt_check_watcher(struct ebt_entry_watcher *w, struct ebt_entry *e,
6255 + const char *name, unsigned int hookmask, unsigned int *cnt)
6256 +{
6257 + struct ebt_watcher *watcher;
6258 + int ret;
6259 +
6260 + if (((char *)w) + w->watcher_size + sizeof(struct ebt_entry_watcher) >
6261 + ((char *)e) + e->target_offset)
6262 + return -EINVAL;
6263 + watcher = find_watcher_lock(w->u.name, &ret, &ebt_mutex);
6264 + if (!watcher)
6265 + return ret;
6266 + w->u.watcher = watcher;
6267 + if (watcher->me)
6268 + __MOD_INC_USE_COUNT(watcher->me);
6269 + up(&ebt_mutex);
6270 + if (watcher->check &&
6271 + watcher->check(name, hookmask, e, w->data, w->watcher_size) != 0) {
6272 + BUGPRINT("watcher->check failed\n");
6273 + if (watcher->me)
6274 + __MOD_DEC_USE_COUNT(watcher->me);
6275 + return -EINVAL;
6276 + }
6277 + (*cnt)++;
6278 + return 0;
6279 +}
6280 +
6281 +// this one is very careful, as it is the first function
6282 +// to parse the userspace data
6283 +static inline int
6284 +ebt_check_entry_size_and_hooks(struct ebt_entry *e,
6285 + struct ebt_table_info *newinfo, char *base, char *limit,
6286 + struct ebt_entries **hook_entries, unsigned int *n, unsigned int *cnt,
6287 + unsigned int *totalcnt, unsigned int *udc_cnt, unsigned int valid_hooks)
6288 +{
6289 + int i;
6290 +
6291 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
6292 + if ((valid_hooks & (1 << i)) == 0)
6293 + continue;
6294 + if ( (char *)hook_entries[i] - base ==
6295 + (char *)e - newinfo->entries)
6296 + break;
6297 + }
6298 + // beginning of a new chain
6299 + // if i == NF_BR_NUMHOOKS it must be a user defined chain
6300 + if (i != NF_BR_NUMHOOKS || !(e->bitmask & EBT_ENTRY_OR_ENTRIES)) {
6301 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) != 0) {
6302 + // we make userspace set this right,
6303 + // so there is no misunderstanding
6304 + BUGPRINT("EBT_ENTRY_OR_ENTRIES shouldn't be set "
6305 + "in distinguisher\n");
6306 + return -EINVAL;
6307 + }
6308 + // this checks if the previous chain has as many entries
6309 + // as it said it has
6310 + if (*n != *cnt) {
6311 + BUGPRINT("nentries does not equal the nr of entries "
6312 + "in the chain\n");
6313 + return -EINVAL;
6314 + }
6315 + // before we look at the struct, be sure it is not too big
6316 + if ((char *)hook_entries[i] + sizeof(struct ebt_entries)
6317 + > limit) {
6318 + BUGPRINT("entries_size too small\n");
6319 + return -EINVAL;
6320 + }
6321 + if (((struct ebt_entries *)e)->policy != EBT_DROP &&
6322 + ((struct ebt_entries *)e)->policy != EBT_ACCEPT) {
6323 + // only RETURN from udc
6324 + if (i != NF_BR_NUMHOOKS ||
6325 + ((struct ebt_entries *)e)->policy != EBT_RETURN) {
6326 + BUGPRINT("bad policy\n");
6327 + return -EINVAL;
6328 + }
6329 + }
6330 + if (i == NF_BR_NUMHOOKS) // it's a user defined chain
6331 + (*udc_cnt)++;
6332 + else
6333 + newinfo->hook_entry[i] = (struct ebt_entries *)e;
6334 + if (((struct ebt_entries *)e)->counter_offset != *totalcnt) {
6335 + BUGPRINT("counter_offset != totalcnt");
6336 + return -EINVAL;
6337 + }
6338 + *n = ((struct ebt_entries *)e)->nentries;
6339 + *cnt = 0;
6340 + return 0;
6341 + }
6342 + // a plain old entry, heh
6343 + if (sizeof(struct ebt_entry) > e->watchers_offset ||
6344 + e->watchers_offset > e->target_offset ||
6345 + e->target_offset >= e->next_offset) {
6346 + BUGPRINT("entry offsets not in right order\n");
6347 + return -EINVAL;
6348 + }
6349 + // this is not checked anywhere else
6350 + if (e->next_offset - e->target_offset < sizeof(struct ebt_entry_target)) {
6351 + BUGPRINT("target size too small\n");
6352 + return -EINVAL;
6353 + }
6354 +
6355 + (*cnt)++;
6356 + (*totalcnt)++;
6357 + return 0;
6358 +}
6359 +
6360 +struct ebt_cl_stack
6361 +{
6362 + struct ebt_chainstack cs;
6363 + int from;
6364 + unsigned int hookmask;
6365 +};
6366 +
6367 +// we need these positions to check that the jumps to a different part of the
6368 +// entries is a jump to the beginning of a new chain.
6369 +static inline int
6370 +ebt_get_udc_positions(struct ebt_entry *e, struct ebt_table_info *newinfo,
6371 + struct ebt_entries **hook_entries, unsigned int *n, unsigned int valid_hooks,
6372 + struct ebt_cl_stack *udc)
6373 +{
6374 + int i;
6375 +
6376 + // we're only interested in chain starts
6377 + if (e->bitmask & EBT_ENTRY_OR_ENTRIES)
6378 + return 0;
6379 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
6380 + if ((valid_hooks & (1 << i)) == 0)
6381 + continue;
6382 + if (newinfo->hook_entry[i] == (struct ebt_entries *)e)
6383 + break;
6384 + }
6385 + // only care about udc
6386 + if (i != NF_BR_NUMHOOKS)
6387 + return 0;
6388 +
6389 + udc[*n].cs.chaininfo = (struct ebt_entries *)e;
6390 + // these initialisations are depended on later in check_chainloops()
6391 + udc[*n].cs.n = 0;
6392 + udc[*n].hookmask = 0;
6393 +
6394 + (*n)++;
6395 + return 0;
6396 +}
6397 +
6398 +static inline int
6399 +ebt_cleanup_match(struct ebt_entry_match *m, unsigned int *i)
6400 +{
6401 + if (i && (*i)-- == 0)
6402 + return 1;
6403 + if (m->u.match->destroy)
6404 + m->u.match->destroy(m->data, m->match_size);
6405 + if (m->u.match->me)
6406 + __MOD_DEC_USE_COUNT(m->u.match->me);
6407 +
6408 + return 0;
6409 +}
6410 +
6411 +static inline int
6412 +ebt_cleanup_watcher(struct ebt_entry_watcher *w, unsigned int *i)
6413 +{
6414 + if (i && (*i)-- == 0)
6415 + return 1;
6416 + if (w->u.watcher->destroy)
6417 + w->u.watcher->destroy(w->data, w->watcher_size);
6418 + if (w->u.watcher->me)
6419 + __MOD_DEC_USE_COUNT(w->u.watcher->me);
6420 +
6421 + return 0;
6422 +}
6423 +
6424 +static inline int
6425 +ebt_cleanup_entry(struct ebt_entry *e, unsigned int *cnt)
6426 +{
6427 + struct ebt_entry_target *t;
6428 +
6429 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
6430 + return 0;
6431 + // we're done
6432 + if (cnt && (*cnt)-- == 0)
6433 + return 1;
6434 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, NULL);
6435 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, NULL);
6436 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
6437 + if (t->u.target->destroy)
6438 + t->u.target->destroy(t->data, t->target_size);
6439 + if (t->u.target->me)
6440 + __MOD_DEC_USE_COUNT(t->u.target->me);
6441 +
6442 + return 0;
6443 +}
6444 +
6445 +static inline int
6446 +ebt_check_entry(struct ebt_entry *e, struct ebt_table_info *newinfo,
6447 + const char *name, unsigned int *cnt, unsigned int valid_hooks,
6448 + struct ebt_cl_stack *cl_s, unsigned int udc_cnt)
6449 +{
6450 + struct ebt_entry_target *t;
6451 + struct ebt_target *target;
6452 + unsigned int i, j, hook = 0, hookmask = 0;
6453 + int ret;
6454 +
6455 + // Don't mess with the struct ebt_entries
6456 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
6457 + return 0;
6458 +
6459 + if (e->bitmask & ~EBT_F_MASK) {
6460 + BUGPRINT("Unknown flag for bitmask\n");
6461 + return -EINVAL;
6462 + }
6463 + if (e->invflags & ~EBT_INV_MASK) {
6464 + BUGPRINT("Unknown flag for inv bitmask\n");
6465 + return -EINVAL;
6466 + }
6467 + if ( (e->bitmask & EBT_NOPROTO) && (e->bitmask & EBT_802_3) ) {
6468 + BUGPRINT("NOPROTO & 802_3 not allowed\n");
6469 + return -EINVAL;
6470 + }
6471 + // what hook do we belong to?
6472 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
6473 + if ((valid_hooks & (1 << i)) == 0)
6474 + continue;
6475 + if ((char *)newinfo->hook_entry[i] < (char *)e)
6476 + hook = i;
6477 + else
6478 + break;
6479 + }
6480 + // (1 << NF_BR_NUMHOOKS) tells the check functions the rule is on
6481 + // a base chain
6482 + if (i < NF_BR_NUMHOOKS)
6483 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
6484 + else {
6485 + for (i = 0; i < udc_cnt; i++)
6486 + if ((char *)(cl_s[i].cs.chaininfo) > (char *)e)
6487 + break;
6488 + if (i == 0)
6489 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
6490 + else
6491 + hookmask = cl_s[i - 1].hookmask;
6492 + }
6493 + i = 0;
6494 + ret = EBT_MATCH_ITERATE(e, ebt_check_match, e, name, hookmask, &i);
6495 + if (ret != 0)
6496 + goto cleanup_matches;
6497 + j = 0;
6498 + ret = EBT_WATCHER_ITERATE(e, ebt_check_watcher, e, name, hookmask, &j);
6499 + if (ret != 0)
6500 + goto cleanup_watchers;
6501 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
6502 + target = find_target_lock(t->u.name, &ret, &ebt_mutex);
6503 + if (!target)
6504 + goto cleanup_watchers;
6505 + if (target->me)
6506 + __MOD_INC_USE_COUNT(target->me);
6507 + up(&ebt_mutex);
6508 +
6509 + t->u.target = target;
6510 + if (t->u.target == &ebt_standard_target) {
6511 + if (e->target_offset + sizeof(struct ebt_standard_target) >
6512 + e->next_offset) {
6513 + BUGPRINT("Standard target size too big\n");
6514 + ret = -EFAULT;
6515 + goto cleanup_watchers;
6516 + }
6517 + if (((struct ebt_standard_target *)t)->verdict <
6518 + -NUM_STANDARD_TARGETS) {
6519 + BUGPRINT("Invalid standard target\n");
6520 + ret = -EFAULT;
6521 + goto cleanup_watchers;
6522 + }
6523 + } else if ((e->target_offset + t->target_size +
6524 + sizeof(struct ebt_entry_target) > e->next_offset) ||
6525 + (t->u.target->check &&
6526 + t->u.target->check(name, hookmask, e, t->data, t->target_size) != 0)){
6527 + if (t->u.target->me)
6528 + __MOD_DEC_USE_COUNT(t->u.target->me);
6529 + ret = -EFAULT;
6530 + goto cleanup_watchers;
6531 + }
6532 + (*cnt)++;
6533 + return 0;
6534 +cleanup_watchers:
6535 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, &j);
6536 +cleanup_matches:
6537 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, &i);
6538 + return ret;
6539 +}
6540 +
6541 +// checks for loops and sets the hook mask for udc
6542 +// the hook mask for udc tells us from which base chains the udc can be
6543 +// accessed. This mask is a parameter to the check() functions of the extensions
6544 +static int check_chainloops(struct ebt_entries *chain,
6545 + struct ebt_cl_stack *cl_s, unsigned int udc_cnt,
6546 + unsigned int hooknr, char *base)
6547 +{
6548 + int i, chain_nr = -1, pos = 0, nentries = chain->nentries, verdict;
6549 + struct ebt_entry *e = (struct ebt_entry *)chain->data;
6550 + struct ebt_entry_target *t;
6551 +
6552 + while (pos < nentries || chain_nr != -1) {
6553 + // end of udc, go back one 'recursion' step
6554 + if (pos == nentries) {
6555 + // put back values of the time when this chain was called
6556 + e = cl_s[chain_nr].cs.e;
6557 + if (cl_s[chain_nr].from != -1)
6558 + nentries =
6559 + cl_s[cl_s[chain_nr].from].cs.chaininfo->nentries;
6560 + else
6561 + nentries = chain->nentries;
6562 + pos = cl_s[chain_nr].cs.n;
6563 + // make sure we won't see a loop that isn't one
6564 + cl_s[chain_nr].cs.n = 0;
6565 + chain_nr = cl_s[chain_nr].from;
6566 + if (pos == nentries)
6567 + continue;
6568 + }
6569 + t = (struct ebt_entry_target *)
6570 + (((char *)e) + e->target_offset);
6571 + if (strcmp(t->u.name, EBT_STANDARD_TARGET))
6572 + goto letscontinue;
6573 + if (e->target_offset + sizeof(struct ebt_standard_target) >
6574 + e->next_offset) {
6575 + BUGPRINT("Standard target size too big\n");
6576 + return -1;
6577 + }
6578 + verdict = ((struct ebt_standard_target *)t)->verdict;
6579 + if (verdict >= 0) { // jump to another chain
6580 + struct ebt_entries *hlp2 =
6581 + (struct ebt_entries *)(base + verdict);
6582 + for (i = 0; i < udc_cnt; i++)
6583 + if (hlp2 == cl_s[i].cs.chaininfo)
6584 + break;
6585 + // bad destination or loop
6586 + if (i == udc_cnt) {
6587 + BUGPRINT("bad destination\n");
6588 + return -1;
6589 + }
6590 + if (cl_s[i].cs.n) {
6591 + BUGPRINT("loop\n");
6592 + return -1;
6593 + }
6594 + // this can't be 0, so the above test is correct
6595 + cl_s[i].cs.n = pos + 1;
6596 + pos = 0;
6597 + cl_s[i].cs.e = ((void *)e + e->next_offset);
6598 + e = (struct ebt_entry *)(hlp2->data);
6599 + nentries = hlp2->nentries;
6600 + cl_s[i].from = chain_nr;
6601 + chain_nr = i;
6602 + // this udc is accessible from the base chain for hooknr
6603 + cl_s[i].hookmask |= (1 << hooknr);
6604 + continue;
6605 + }
6606 +letscontinue:
6607 + e = (void *)e + e->next_offset;
6608 + pos++;
6609 + }
6610 + return 0;
6611 +}
6612 +
6613 +// do the parsing of the table/chains/entries/matches/watchers/targets, heh
6614 +static int translate_table(struct ebt_replace *repl,
6615 + struct ebt_table_info *newinfo)
6616 +{
6617 + unsigned int i, j, k, udc_cnt;
6618 + int ret;
6619 + struct ebt_cl_stack *cl_s = NULL; // used in the checking for chain loops
6620 +
6621 + i = 0;
6622 + while (i < NF_BR_NUMHOOKS && !(repl->valid_hooks & (1 << i)))
6623 + i++;
6624 + if (i == NF_BR_NUMHOOKS) {
6625 + BUGPRINT("No valid hooks specified\n");
6626 + return -EINVAL;
6627 + }
6628 + if (repl->hook_entry[i] != (struct ebt_entries *)repl->entries) {
6629 + BUGPRINT("Chains don't start at beginning\n");
6630 + return -EINVAL;
6631 + }
6632 + // make sure chains are ordered after each other in same order
6633 + // as their corresponding hooks
6634 + for (j = i + 1; j < NF_BR_NUMHOOKS; j++) {
6635 + if (!(repl->valid_hooks & (1 << j)))
6636 + continue;
6637 + if ( repl->hook_entry[j] <= repl->hook_entry[i] ) {
6638 + BUGPRINT("Hook order must be followed\n");
6639 + return -EINVAL;
6640 + }
6641 + i = j;
6642 + }
6643 +
6644 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
6645 + newinfo->hook_entry[i] = NULL;
6646 +
6647 + newinfo->entries_size = repl->entries_size;
6648 + newinfo->nentries = repl->nentries;
6649 +
6650 + // do some early checkings and initialize some things
6651 + i = 0; // holds the expected nr. of entries for the chain
6652 + j = 0; // holds the up to now counted entries for the chain
6653 + k = 0; // holds the total nr. of entries, should equal
6654 + // newinfo->nentries afterwards
6655 + udc_cnt = 0; // will hold the nr. of user defined chains (udc)
6656 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
6657 + ebt_check_entry_size_and_hooks, newinfo, repl->entries,
6658 + repl->entries + repl->entries_size, repl->hook_entry, &i, &j, &k,
6659 + &udc_cnt, repl->valid_hooks);
6660 +
6661 + if (ret != 0)
6662 + return ret;
6663 +
6664 + if (i != j) {
6665 + BUGPRINT("nentries does not equal the nr of entries in the "
6666 + "(last) chain\n");
6667 + return -EINVAL;
6668 + }
6669 + if (k != newinfo->nentries) {
6670 + BUGPRINT("Total nentries is wrong\n");
6671 + return -EINVAL;
6672 + }
6673 +
6674 + // check if all valid hooks have a chain
6675 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
6676 + if (newinfo->hook_entry[i] == NULL &&
6677 + (repl->valid_hooks & (1 << i))) {
6678 + BUGPRINT("Valid hook without chain\n");
6679 + return -EINVAL;
6680 + }
6681 + }
6682 +
6683 + // Get the location of the udc, put them in an array
6684 + // While we're at it, allocate the chainstack
6685 + if (udc_cnt) {
6686 + // this will get free'd in do_replace()/ebt_register_table()
6687 + // if an error occurs
6688 + newinfo->chainstack = (struct ebt_chainstack **)
6689 + vmalloc(smp_num_cpus * sizeof(struct ebt_chainstack));
6690 + if (!newinfo->chainstack)
6691 + return -ENOMEM;
6692 + for (i = 0; i < smp_num_cpus; i++) {
6693 + newinfo->chainstack[i] =
6694 + vmalloc(udc_cnt * sizeof(struct ebt_chainstack));
6695 + if (!newinfo->chainstack[i]) {
6696 + while (i)
6697 + vfree(newinfo->chainstack[--i]);
6698 + vfree(newinfo->chainstack);
6699 + newinfo->chainstack = NULL;
6700 + return -ENOMEM;
6701 + }
6702 + }
6703 +
6704 + cl_s = (struct ebt_cl_stack *)
6705 + vmalloc(udc_cnt * sizeof(struct ebt_cl_stack));
6706 + if (!cl_s)
6707 + return -ENOMEM;
6708 + i = 0; // the i'th udc
6709 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
6710 + ebt_get_udc_positions, newinfo, repl->hook_entry, &i,
6711 + repl->valid_hooks, cl_s);
6712 + // sanity check
6713 + if (i != udc_cnt) {
6714 + BUGPRINT("i != udc_cnt\n");
6715 + vfree(cl_s);
6716 + return -EFAULT;
6717 + }
6718 + }
6719 +
6720 + // Check for loops
6721 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
6722 + if (repl->valid_hooks & (1 << i))
6723 + if (check_chainloops(newinfo->hook_entry[i],
6724 + cl_s, udc_cnt, i, newinfo->entries)) {
6725 + if (cl_s)
6726 + vfree(cl_s);
6727 + return -EINVAL;
6728 + }
6729 +
6730 + // we now know the following (along with E=mc²):
6731 + // - the nr of entries in each chain is right
6732 + // - the size of the allocated space is right
6733 + // - all valid hooks have a corresponding chain
6734 + // - there are no loops
6735 + // - wrong data can still be on the level of a single entry
6736 + // - could be there are jumps to places that are not the
6737 + // beginning of a chain. This can only occur in chains that
6738 + // are not accessible from any base chains, so we don't care.
6739 +
6740 + // used to know what we need to clean up if something goes wrong
6741 + i = 0;
6742 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
6743 + ebt_check_entry, newinfo, repl->name, &i, repl->valid_hooks,
6744 + cl_s, udc_cnt);
6745 + if (ret != 0) {
6746 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
6747 + ebt_cleanup_entry, &i);
6748 + }
6749 + if (cl_s)
6750 + vfree(cl_s);
6751 + return ret;
6752 +}
6753 +
6754 +// called under write_lock
6755 +static void get_counters(struct ebt_counter *oldcounters,
6756 + struct ebt_counter *counters, unsigned int nentries)
6757 +{
6758 + int i, cpu;
6759 + struct ebt_counter *counter_base;
6760 +
6761 + // counters of cpu 0
6762 + memcpy(counters, oldcounters,
6763 + sizeof(struct ebt_counter) * nentries);
6764 + // add other counters to those of cpu 0
6765 + for (cpu = 1; cpu < smp_num_cpus; cpu++) {
6766 + counter_base = COUNTER_BASE(oldcounters, nentries, cpu);
6767 + for (i = 0; i < nentries; i++) {
6768 + counters[i].pcnt += counter_base[i].pcnt;
6769 + counters[i].bcnt += counter_base[i].bcnt;
6770 + }
6771 + }
6772 +}
6773 +
6774 +// replace the table
6775 +static int do_replace(void *user, unsigned int len)
6776 +{
6777 + int ret, i, countersize;
6778 + struct ebt_table_info *newinfo;
6779 + struct ebt_replace tmp;
6780 + struct ebt_table *t;
6781 + struct ebt_counter *counterstmp = NULL;
6782 + // used to be able to unlock earlier
6783 + struct ebt_table_info *table;
6784 +
6785 + if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
6786 + return -EFAULT;
6787 +
6788 + if (len != sizeof(tmp) + tmp.entries_size) {
6789 + BUGPRINT("Wrong len argument\n");
6790 + return -EINVAL;
6791 + }
6792 +
6793 + if (tmp.entries_size == 0) {
6794 + BUGPRINT("Entries_size never zero\n");
6795 + return -EINVAL;
6796 + }
6797 + countersize = COUNTER_OFFSET(tmp.nentries) * smp_num_cpus;
6798 + newinfo = (struct ebt_table_info *)
6799 + vmalloc(sizeof(struct ebt_table_info) + countersize);
6800 + if (!newinfo)
6801 + return -ENOMEM;
6802 +
6803 + if (countersize)
6804 + memset(newinfo->counters, 0, countersize);
6805 +
6806 + newinfo->entries = (char *)vmalloc(tmp.entries_size);
6807 + if (!newinfo->entries) {
6808 + ret = -ENOMEM;
6809 + goto free_newinfo;
6810 + }
6811 + if (copy_from_user(
6812 + newinfo->entries, tmp.entries, tmp.entries_size) != 0) {
6813 + BUGPRINT("Couldn't copy entries from userspace\n");
6814 + ret = -EFAULT;
6815 + goto free_entries;
6816 + }
6817 +
6818 + // the user wants counters back
6819 + // the check on the size is done later, when we have the lock
6820 + if (tmp.num_counters) {
6821 + counterstmp = (struct ebt_counter *)
6822 + vmalloc(tmp.num_counters * sizeof(struct ebt_counter));
6823 + if (!counterstmp) {
6824 + ret = -ENOMEM;
6825 + goto free_entries;
6826 + }
6827 + }
6828 + else
6829 + counterstmp = NULL;
6830 +
6831 + // this can get initialized by translate_table()
6832 + newinfo->chainstack = NULL;
6833 + ret = translate_table(&tmp, newinfo);
6834 +
6835 + if (ret != 0)
6836 + goto free_counterstmp;
6837 +
6838 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
6839 + if (!t)
6840 + goto free_iterate;
6841 +
6842 + // the table doesn't like it
6843 + if (t->check && (ret = t->check(newinfo, tmp.valid_hooks)))
6844 + goto free_unlock;
6845 +
6846 + if (tmp.num_counters && tmp.num_counters != t->private->nentries) {
6847 + BUGPRINT("Wrong nr. of counters requested\n");
6848 + ret = -EINVAL;
6849 + goto free_unlock;
6850 + }
6851 +
6852 + // we have the mutex lock, so no danger in reading this pointer
6853 + table = t->private;
6854 + // we need an atomic snapshot of the counters
6855 + write_lock_bh(&t->lock);
6856 + if (tmp.num_counters)
6857 + get_counters(t->private->counters, counterstmp,
6858 + t->private->nentries);
6859 +
6860 + t->private = newinfo;
6861 + write_unlock_bh(&t->lock);
6862 + up(&ebt_mutex);
6863 + // So, a user can change the chains while having messed up her counter
6864 + // allocation. Only reason why this is done is because this way the lock
6865 + // is held only once, while this doesn't bring the kernel into a
6866 + // dangerous state.
6867 + if (tmp.num_counters &&
6868 + copy_to_user(tmp.counters, counterstmp,
6869 + tmp.num_counters * sizeof(struct ebt_counter))) {
6870 + BUGPRINT("Couldn't copy counters to userspace\n");
6871 + ret = -EFAULT;
6872 + }
6873 + else
6874 + ret = 0;
6875 +
6876 + // decrease module count and free resources
6877 + EBT_ENTRY_ITERATE(table->entries, table->entries_size,
6878 + ebt_cleanup_entry, NULL);
6879 +
6880 + vfree(table->entries);
6881 + if (table->chainstack) {
6882 + for (i = 0; i < smp_num_cpus; i++)
6883 + vfree(table->chainstack[i]);
6884 + vfree(table->chainstack);
6885 + }
6886 + vfree(table);
6887 +
6888 + if (counterstmp)
6889 + vfree(counterstmp);
6890 + return ret;
6891 +
6892 +free_unlock:
6893 + up(&ebt_mutex);
6894 +free_iterate:
6895 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
6896 + ebt_cleanup_entry, NULL);
6897 +free_counterstmp:
6898 + if (counterstmp)
6899 + vfree(counterstmp);
6900 + // can be initialized in translate_table()
6901 + if (newinfo->chainstack) {
6902 + for (i = 0; i < smp_num_cpus; i++)
6903 + vfree(newinfo->chainstack[i]);
6904 + vfree(newinfo->chainstack);
6905 + }
6906 +free_entries:
6907 + if (newinfo->entries)
6908 + vfree(newinfo->entries);
6909 +free_newinfo:
6910 + if (newinfo)
6911 + vfree(newinfo);
6912 + return ret;
6913 +}
6914 +
6915 +int ebt_register_target(struct ebt_target *target)
6916 +{
6917 + int ret;
6918 +
6919 + ret = down_interruptible(&ebt_mutex);
6920 + if (ret != 0)
6921 + return ret;
6922 + if (!list_named_insert(&ebt_targets, target)) {
6923 + up(&ebt_mutex);
6924 + return -EEXIST;
6925 + }
6926 + up(&ebt_mutex);
6927 + MOD_INC_USE_COUNT;
6928 +
6929 + return 0;
6930 +}
6931 +
6932 +void ebt_unregister_target(struct ebt_target *target)
6933 +{
6934 + down(&ebt_mutex);
6935 + LIST_DELETE(&ebt_targets, target);
6936 + up(&ebt_mutex);
6937 + MOD_DEC_USE_COUNT;
6938 +}
6939 +
6940 +int ebt_register_match(struct ebt_match *match)
6941 +{
6942 + int ret;
6943 +
6944 + ret = down_interruptible(&ebt_mutex);
6945 + if (ret != 0)
6946 + return ret;
6947 + if (!list_named_insert(&ebt_matches, match)) {
6948 + up(&ebt_mutex);
6949 + return -EEXIST;
6950 + }
6951 + up(&ebt_mutex);
6952 + MOD_INC_USE_COUNT;
6953 +
6954 + return 0;
6955 +}
6956 +
6957 +void ebt_unregister_match(struct ebt_match *match)
6958 +{
6959 + down(&ebt_mutex);
6960 + LIST_DELETE(&ebt_matches, match);
6961 + up(&ebt_mutex);
6962 + MOD_DEC_USE_COUNT;
6963 +}
6964 +
6965 +int ebt_register_watcher(struct ebt_watcher *watcher)
6966 +{
6967 + int ret;
6968 +
6969 + ret = down_interruptible(&ebt_mutex);
6970 + if (ret != 0)
6971 + return ret;
6972 + if (!list_named_insert(&ebt_watchers, watcher)) {
6973 + up(&ebt_mutex);
6974 + return -EEXIST;
6975 + }
6976 + up(&ebt_mutex);
6977 + MOD_INC_USE_COUNT;
6978 +
6979 + return 0;
6980 +}
6981 +
6982 +void ebt_unregister_watcher(struct ebt_watcher *watcher)
6983 +{
6984 + down(&ebt_mutex);
6985 + LIST_DELETE(&ebt_watchers, watcher);
6986 + up(&ebt_mutex);
6987 + MOD_DEC_USE_COUNT;
6988 +}
6989 +
6990 +int ebt_register_table(struct ebt_table *table)
6991 +{
6992 + struct ebt_table_info *newinfo;
6993 + int ret, i, countersize;
6994 +
6995 + if (!table || !table->table ||!table->table->entries ||
6996 + table->table->entries_size == 0 ||
6997 + table->table->counters || table->private) {
6998 + BUGPRINT("Bad table data for ebt_register_table!!!\n");
6999 + return -EINVAL;
7000 + }
7001 +
7002 + countersize = COUNTER_OFFSET(table->table->nentries) * smp_num_cpus;
7003 + newinfo = (struct ebt_table_info *)
7004 + vmalloc(sizeof(struct ebt_table_info) + countersize);
7005 + ret = -ENOMEM;
7006 + if (!newinfo)
7007 + return -ENOMEM;
7008 +
7009 + newinfo->entries = (char *)vmalloc(table->table->entries_size);
7010 + if (!(newinfo->entries))
7011 + goto free_newinfo;
7012 +
7013 + memcpy(newinfo->entries, table->table->entries,
7014 + table->table->entries_size);
7015 +
7016 + if (countersize)
7017 + memset(newinfo->counters, 0, countersize);
7018 +
7019 + // fill in newinfo and parse the entries
7020 + newinfo->chainstack = NULL;
7021 + ret = translate_table(table->table, newinfo);
7022 + if (ret != 0) {
7023 + BUGPRINT("Translate_table failed\n");
7024 + goto free_chainstack;
7025 + }
7026 +
7027 + if (table->check && table->check(newinfo, table->valid_hooks)) {
7028 + BUGPRINT("The table doesn't like its own initial data, lol\n");
7029 + return -EINVAL;
7030 + }
7031 +
7032 + table->private = newinfo;
7033 + table->lock = RW_LOCK_UNLOCKED;
7034 + ret = down_interruptible(&ebt_mutex);
7035 + if (ret != 0)
7036 + goto free_chainstack;
7037 +
7038 + if (list_named_find(&ebt_tables, table->name)) {
7039 + ret = -EEXIST;
7040 + BUGPRINT("Table name already exists\n");
7041 + goto free_unlock;
7042 + }
7043 +
7044 + list_prepend(&ebt_tables, table);
7045 + up(&ebt_mutex);
7046 + MOD_INC_USE_COUNT;
7047 + return 0;
7048 +free_unlock:
7049 + up(&ebt_mutex);
7050 +free_chainstack:
7051 + if (newinfo->chainstack) {
7052 + for (i = 0; i < smp_num_cpus; i++)
7053 + vfree(newinfo->chainstack[i]);
7054 + vfree(newinfo->chainstack);
7055 + }
7056 + vfree(newinfo->entries);
7057 +free_newinfo:
7058 + vfree(newinfo);
7059 + return ret;
7060 +}
7061 +
7062 +void ebt_unregister_table(struct ebt_table *table)
7063 +{
7064 + int i;
7065 +
7066 + if (!table) {
7067 + BUGPRINT("Request to unregister NULL table!!!\n");
7068 + return;
7069 + }
7070 + down(&ebt_mutex);
7071 + LIST_DELETE(&ebt_tables, table);
7072 + up(&ebt_mutex);
7073 + EBT_ENTRY_ITERATE(table->private->entries,
7074 + table->private->entries_size, ebt_cleanup_entry, NULL);
7075 + if (table->private->entries)
7076 + vfree(table->private->entries);
7077 + if (table->private->chainstack) {
7078 + for (i = 0; i < smp_num_cpus; i++)
7079 + vfree(table->private->chainstack[i]);
7080 + vfree(table->private->chainstack);
7081 + }
7082 + vfree(table->private);
7083 + MOD_DEC_USE_COUNT;
7084 +}
7085 +
7086 +// userspace just supplied us with counters
7087 +static int update_counters(void *user, unsigned int len)
7088 +{
7089 + int i, ret;
7090 + struct ebt_counter *tmp;
7091 + struct ebt_replace hlp;
7092 + struct ebt_table *t;
7093 +
7094 + if (copy_from_user(&hlp, user, sizeof(hlp)))
7095 + return -EFAULT;
7096 +
7097 + if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
7098 + return -EINVAL;
7099 + if (hlp.num_counters == 0)
7100 + return -EINVAL;
7101 +
7102 + if ( !(tmp = (struct ebt_counter *)
7103 + vmalloc(hlp.num_counters * sizeof(struct ebt_counter))) ){
7104 + MEMPRINT("Update_counters && nomemory\n");
7105 + return -ENOMEM;
7106 + }
7107 +
7108 + t = find_table_lock(hlp.name, &ret, &ebt_mutex);
7109 + if (!t)
7110 + goto free_tmp;
7111 +
7112 + if (hlp.num_counters != t->private->nentries) {
7113 + BUGPRINT("Wrong nr of counters\n");
7114 + ret = -EINVAL;
7115 + goto unlock_mutex;
7116 + }
7117 +
7118 + if ( copy_from_user(tmp, hlp.counters,
7119 + hlp.num_counters * sizeof(struct ebt_counter)) ) {
7120 + BUGPRINT("Updata_counters && !cfu\n");
7121 + ret = -EFAULT;
7122 + goto unlock_mutex;
7123 + }
7124 +
7125 + // we want an atomic add of the counters
7126 + write_lock_bh(&t->lock);
7127 +
7128 + // we add to the counters of the first cpu
7129 + for (i = 0; i < hlp.num_counters; i++) {
7130 + t->private->counters[i].pcnt += tmp[i].pcnt;
7131 + t->private->counters[i].bcnt += tmp[i].bcnt;
7132 + }
7133 +
7134 + write_unlock_bh(&t->lock);
7135 + ret = 0;
7136 +unlock_mutex:
7137 + up(&ebt_mutex);
7138 +free_tmp:
7139 + vfree(tmp);
7140 + return ret;
7141 +}
7142 +
7143 +static inline int ebt_make_matchname(struct ebt_entry_match *m,
7144 + char *base, char *ubase)
7145 +{
7146 + char *hlp = ubase - base + (char *)m;
7147 + if (copy_to_user(hlp, m->u.match->name, EBT_FUNCTION_MAXNAMELEN))
7148 + return -EFAULT;
7149 + return 0;
7150 +}
7151 +
7152 +static inline int ebt_make_watchername(struct ebt_entry_watcher *w,
7153 + char *base, char *ubase)
7154 +{
7155 + char *hlp = ubase - base + (char *)w;
7156 + if (copy_to_user(hlp , w->u.watcher->name, EBT_FUNCTION_MAXNAMELEN))
7157 + return -EFAULT;
7158 + return 0;
7159 +}
7160 +
7161 +static inline int ebt_make_names(struct ebt_entry *e, char *base, char *ubase)
7162 +{
7163 + int ret;
7164 + char *hlp;
7165 + struct ebt_entry_target *t;
7166 +
7167 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
7168 + return 0;
7169 +
7170 + hlp = ubase - base + (char *)e + e->target_offset;
7171 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
7172 +
7173 + ret = EBT_MATCH_ITERATE(e, ebt_make_matchname, base, ubase);
7174 + if (ret != 0)
7175 + return ret;
7176 + ret = EBT_WATCHER_ITERATE(e, ebt_make_watchername, base, ubase);
7177 + if (ret != 0)
7178 + return ret;
7179 + if (copy_to_user(hlp, t->u.target->name, EBT_FUNCTION_MAXNAMELEN))
7180 + return -EFAULT;
7181 + return 0;
7182 +}
7183 +
7184 +// called with ebt_mutex down
7185 +static int copy_everything_to_user(struct ebt_table *t, void *user,
7186 + int *len, int cmd)
7187 +{
7188 + struct ebt_replace tmp;
7189 + struct ebt_counter *counterstmp, *oldcounters;
7190 + unsigned int entries_size, nentries;
7191 + char *entries;
7192 +
7193 + if (cmd == EBT_SO_GET_ENTRIES) {
7194 + entries_size = t->private->entries_size;
7195 + nentries = t->private->nentries;
7196 + entries = t->private->entries;
7197 + oldcounters = t->private->counters;
7198 + } else {
7199 + entries_size = t->table->entries_size;
7200 + nentries = t->table->nentries;
7201 + entries = t->table->entries;
7202 + oldcounters = t->table->counters;
7203 + }
7204 +
7205 + if (copy_from_user(&tmp, user, sizeof(tmp))) {
7206 + BUGPRINT("Cfu didn't work\n");
7207 + return -EFAULT;
7208 + }
7209 +
7210 + if (*len != sizeof(struct ebt_replace) + entries_size +
7211 + (tmp.num_counters? nentries * sizeof(struct ebt_counter): 0)) {
7212 + BUGPRINT("Wrong size\n");
7213 + return -EINVAL;
7214 + }
7215 +
7216 + if (tmp.nentries != nentries) {
7217 + BUGPRINT("Nentries wrong\n");
7218 + return -EINVAL;
7219 + }
7220 +
7221 + if (tmp.entries_size != entries_size) {
7222 + BUGPRINT("Wrong size\n");
7223 + return -EINVAL;
7224 + }
7225 +
7226 + // userspace might not need the counters
7227 + if (tmp.num_counters) {
7228 + if (tmp.num_counters != nentries) {
7229 + BUGPRINT("Num_counters wrong\n");
7230 + return -EINVAL;
7231 + }
7232 + counterstmp = (struct ebt_counter *)
7233 + vmalloc(nentries * sizeof(struct ebt_counter));
7234 + if (!counterstmp) {
7235 + MEMPRINT("Couldn't copy counters, out of memory\n");
7236 + return -ENOMEM;
7237 + }
7238 + write_lock_bh(&t->lock);
7239 + get_counters(oldcounters, counterstmp, nentries);
7240 + write_unlock_bh(&t->lock);
7241 +
7242 + if (copy_to_user(tmp.counters, counterstmp,
7243 + nentries * sizeof(struct ebt_counter))) {
7244 + BUGPRINT("Couldn't copy counters to userspace\n");
7245 + vfree(counterstmp);
7246 + return -EFAULT;
7247 + }
7248 + vfree(counterstmp);
7249 + }
7250 +
7251 + if (copy_to_user(tmp.entries, entries, entries_size)) {
7252 + BUGPRINT("Couldn't copy entries to userspace\n");
7253 + return -EFAULT;
7254 + }
7255 + // set the match/watcher/target names right
7256 + return EBT_ENTRY_ITERATE(entries, entries_size,
7257 + ebt_make_names, entries, tmp.entries);
7258 +}
7259 +
7260 +static int do_ebt_set_ctl(struct sock *sk,
7261 + int cmd, void *user, unsigned int len)
7262 +{
7263 + int ret;
7264 +
7265 + switch(cmd) {
7266 + case EBT_SO_SET_ENTRIES:
7267 + ret = do_replace(user, len);
7268 + break;
7269 + case EBT_SO_SET_COUNTERS:
7270 + ret = update_counters(user, len);
7271 + break;
7272 + default:
7273 + ret = -EINVAL;
7274 + }
7275 + return ret;
7276 +}
7277 +
7278 +static int do_ebt_get_ctl(struct sock *sk, int cmd, void *user, int *len)
7279 +{
7280 + int ret;
7281 + struct ebt_replace tmp;
7282 + struct ebt_table *t;
7283 +
7284 + if (copy_from_user(&tmp, user, sizeof(tmp)))
7285 + return -EFAULT;
7286 +
7287 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
7288 + if (!t)
7289 + return ret;
7290 +
7291 + switch(cmd) {
7292 + case EBT_SO_GET_INFO:
7293 + case EBT_SO_GET_INIT_INFO:
7294 + if (*len != sizeof(struct ebt_replace)){
7295 + ret = -EINVAL;
7296 + up(&ebt_mutex);
7297 + break;
7298 + }
7299 + if (cmd == EBT_SO_GET_INFO) {
7300 + tmp.nentries = t->private->nentries;
7301 + tmp.entries_size = t->private->entries_size;
7302 + tmp.valid_hooks = t->valid_hooks;
7303 + } else {
7304 + tmp.nentries = t->table->nentries;
7305 + tmp.entries_size = t->table->entries_size;
7306 + tmp.valid_hooks = t->table->valid_hooks;
7307 + }
7308 + up(&ebt_mutex);
7309 + if (copy_to_user(user, &tmp, *len) != 0){
7310 + BUGPRINT("c2u Didn't work\n");
7311 + ret = -EFAULT;
7312 + break;
7313 + }
7314 + ret = 0;
7315 + break;
7316 +
7317 + case EBT_SO_GET_ENTRIES:
7318 + case EBT_SO_GET_INIT_ENTRIES:
7319 + ret = copy_everything_to_user(t, user, len, cmd);
7320 + up(&ebt_mutex);
7321 + break;
7322 +
7323 + default:
7324 + up(&ebt_mutex);
7325 + ret = -EINVAL;
7326 + }
7327 +
7328 + return ret;
7329 +}
7330 +
7331 +static struct nf_sockopt_ops ebt_sockopts =
7332 +{ { NULL, NULL }, PF_INET, EBT_BASE_CTL, EBT_SO_SET_MAX + 1, do_ebt_set_ctl,
7333 + EBT_BASE_CTL, EBT_SO_GET_MAX + 1, do_ebt_get_ctl, 0, NULL
7334 +};
7335 +
7336 +static int __init init(void)
7337 +{
7338 + int ret;
7339 +
7340 + down(&ebt_mutex);
7341 + list_named_insert(&ebt_targets, &ebt_standard_target);
7342 + up(&ebt_mutex);
7343 + if ((ret = nf_register_sockopt(&ebt_sockopts)) < 0)
7344 + return ret;
7345 +
7346 + printk(KERN_NOTICE "Ebtables v2.0 registered\n");
7347 + return 0;
7348 +}
7349 +
7350 +static void __exit fini(void)
7351 +{
7352 + nf_unregister_sockopt(&ebt_sockopts);
7353 + printk(KERN_NOTICE "Ebtables v2.0 unregistered\n");
7354 +}
7355 +
7356 +EXPORT_SYMBOL(ebt_register_table);
7357 +EXPORT_SYMBOL(ebt_unregister_table);
7358 +EXPORT_SYMBOL(ebt_register_match);
7359 +EXPORT_SYMBOL(ebt_unregister_match);
7360 +EXPORT_SYMBOL(ebt_register_watcher);
7361 +EXPORT_SYMBOL(ebt_unregister_watcher);
7362 +EXPORT_SYMBOL(ebt_register_target);
7363 +EXPORT_SYMBOL(ebt_unregister_target);
7364 +EXPORT_SYMBOL(ebt_do_table);
7365 +module_init(init);
7366 +module_exit(fini);
7367 +MODULE_LICENSE("GPL");
7368 diff -Nur linux-mips-cvs/net/core/dev.c linux-ebtables/net/core/dev.c
7369 --- linux-mips-cvs/net/core/dev.c 2004-04-16 05:14:21.000000000 +0200
7370 +++ linux-ebtables/net/core/dev.c 2005-02-07 05:52:50.000000000 +0100
7371 @@ -1426,7 +1426,7 @@
7372
7373
7374 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7375 -void (*br_handle_frame_hook)(struct sk_buff *skb) = NULL;
7376 +int (*br_handle_frame_hook)(struct sk_buff *skb) = NULL;
7377 #endif
7378
7379 static __inline__ int handle_bridge(struct sk_buff *skb,
7380 @@ -1443,7 +1443,6 @@
7381 }
7382 }
7383
7384 - br_handle_frame_hook(skb);
7385 return ret;
7386 }
7387
7388 @@ -1503,7 +1502,12 @@
7389 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7390 if (skb->dev->br_port != NULL && br_handle_frame_hook != NULL &&
7391 skb->pkt_type != PACKET_LOOPBACK) {
7392 - return handle_bridge(skb, pt_prev);
7393 + int ret;
7394 +
7395 + ret = handle_bridge(skb, pt_prev);
7396 + if (br_handle_frame_hook(skb) == 0)
7397 + return ret;
7398 + pt_prev = NULL;
7399 }
7400 #endif
7401
7402 diff -Nur linux-mips-cvs/net/core/netfilter.c linux-ebtables/net/core/netfilter.c
7403 --- linux-mips-cvs/net/core/netfilter.c 2005-01-20 03:19:25.000000000 +0100
7404 +++ linux-ebtables/net/core/netfilter.c 2005-02-07 05:52:50.000000000 +0100
7405 @@ -342,10 +342,15 @@
7406 const struct net_device *indev,
7407 const struct net_device *outdev,
7408 struct list_head **i,
7409 - int (*okfn)(struct sk_buff *))
7410 + int (*okfn)(struct sk_buff *),
7411 + int hook_thresh)
7412 {
7413 for (*i = (*i)->next; *i != head; *i = (*i)->next) {
7414 struct nf_hook_ops *elem = (struct nf_hook_ops *)*i;
7415 +
7416 + if (hook_thresh > elem->priority)
7417 + continue;
7418 +
7419 switch (elem->hook(hook, skb, indev, outdev, okfn)) {
7420 case NF_QUEUE:
7421 return NF_QUEUE;
7422 @@ -413,6 +418,10 @@
7423 {
7424 int status;
7425 struct nf_info *info;
7426 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7427 + struct net_device *physindev = NULL;
7428 + struct net_device *physoutdev = NULL;
7429 +#endif
7430
7431 if (!queue_handler[pf].outfn) {
7432 kfree_skb(skb);
7433 @@ -435,11 +444,24 @@
7434 if (indev) dev_hold(indev);
7435 if (outdev) dev_hold(outdev);
7436
7437 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7438 + if (skb->nf_bridge) {
7439 + physindev = skb->nf_bridge->physindev;
7440 + if (physindev) dev_hold(physindev);
7441 + physoutdev = skb->nf_bridge->physoutdev;
7442 + if (physoutdev) dev_hold(physoutdev);
7443 + }
7444 +#endif
7445 +
7446 status = queue_handler[pf].outfn(skb, info, queue_handler[pf].data);
7447 if (status < 0) {
7448 /* James M doesn't say fuck enough. */
7449 if (indev) dev_put(indev);
7450 if (outdev) dev_put(outdev);
7451 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7452 + if (physindev) dev_put(physindev);
7453 + if (physoutdev) dev_put(physoutdev);
7454 +#endif
7455 kfree(info);
7456 kfree_skb(skb);
7457 return;
7458 @@ -449,7 +471,8 @@
7459 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
7460 struct net_device *indev,
7461 struct net_device *outdev,
7462 - int (*okfn)(struct sk_buff *))
7463 + int (*okfn)(struct sk_buff *),
7464 + int hook_thresh)
7465 {
7466 struct list_head *elem;
7467 unsigned int verdict;
7468 @@ -481,7 +504,7 @@
7469
7470 elem = &nf_hooks[pf][hook];
7471 verdict = nf_iterate(&nf_hooks[pf][hook], &skb, hook, indev,
7472 - outdev, &elem, okfn);
7473 + outdev, &elem, okfn, hook_thresh);
7474 if (verdict == NF_QUEUE) {
7475 NFDEBUG("nf_hook: Verdict = QUEUE.\n");
7476 nf_queue(skb, elem, pf, hook, indev, outdev, okfn);
7477 @@ -510,6 +533,14 @@
7478
7479 /* We don't have BR_NETPROTO_LOCK here */
7480 br_read_lock_bh(BR_NETPROTO_LOCK);
7481 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7482 + if (skb->nf_bridge) {
7483 + if (skb->nf_bridge->physindev)
7484 + dev_put(skb->nf_bridge->physindev);
7485 + if (skb->nf_bridge->physoutdev)
7486 + dev_put(skb->nf_bridge->physoutdev);
7487 + }
7488 +#endif
7489 for (i = nf_hooks[info->pf][info->hook].next; i != elem; i = i->next) {
7490 if (i == &nf_hooks[info->pf][info->hook]) {
7491 /* The module which sent it to userspace is gone. */
7492 @@ -530,7 +561,7 @@
7493 verdict = nf_iterate(&nf_hooks[info->pf][info->hook],
7494 &skb, info->hook,
7495 info->indev, info->outdev, &elem,
7496 - info->okfn);
7497 + info->okfn, INT_MIN);
7498 }
7499
7500 switch (verdict) {
7501 diff -Nur linux-mips-cvs/net/core/skbuff.c linux-ebtables/net/core/skbuff.c
7502 --- linux-mips-cvs/net/core/skbuff.c 2003-08-13 19:19:30.000000000 +0200
7503 +++ linux-ebtables/net/core/skbuff.c 2005-02-07 05:52:50.000000000 +0100
7504 @@ -246,6 +246,9 @@
7505 #ifdef CONFIG_NETFILTER_DEBUG
7506 skb->nf_debug = 0;
7507 #endif
7508 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7509 + skb->nf_bridge = NULL;
7510 +#endif
7511 #endif
7512 #ifdef CONFIG_NET_SCHED
7513 skb->tc_index = 0;
7514 @@ -326,6 +329,9 @@
7515 }
7516 #ifdef CONFIG_NETFILTER
7517 nf_conntrack_put(skb->nfct);
7518 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7519 + nf_bridge_put(skb->nf_bridge);
7520 +#endif
7521 #endif
7522 skb_headerinit(skb, NULL, 0); /* clean state */
7523 kfree_skbmem(skb);
7524 @@ -393,6 +399,9 @@
7525 #ifdef CONFIG_NETFILTER_DEBUG
7526 C(nf_debug);
7527 #endif
7528 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7529 + C(nf_bridge);
7530 +#endif
7531 #endif /*CONFIG_NETFILTER*/
7532 #if defined(CONFIG_HIPPI)
7533 C(private);
7534 @@ -405,6 +414,9 @@
7535 skb->cloned = 1;
7536 #ifdef CONFIG_NETFILTER
7537 nf_conntrack_get(skb->nfct);
7538 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7539 + nf_bridge_get(skb->nf_bridge);
7540 +#endif
7541 #endif
7542 return n;
7543 }
7544 @@ -440,6 +452,10 @@
7545 #ifdef CONFIG_NETFILTER_DEBUG
7546 new->nf_debug=old->nf_debug;
7547 #endif
7548 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7549 + new->nf_bridge=old->nf_bridge;
7550 + nf_bridge_get(new->nf_bridge);
7551 +#endif
7552 #endif
7553 #ifdef CONFIG_NET_SCHED
7554 new->tc_index = old->tc_index;
7555 @@ -726,9 +742,9 @@
7556 /* Set the tail pointer and length */
7557 skb_put(n,skb->len);
7558
7559 - /* Copy the data only. */
7560 - if (skb_copy_bits(skb, 0, n->data, skb->len))
7561 - BUG();
7562 + /* Copy the linear data and header. */
7563 + if (skb_copy_bits(skb, -newheadroom, n->head, newheadroom + skb->len))
7564 + BUG();
7565
7566 copy_skb_header(n, skb);
7567 return n;
7568 diff -Nur linux-mips-cvs/net/ipv4/ip_output.c linux-ebtables/net/ipv4/ip_output.c
7569 --- linux-mips-cvs/net/ipv4/ip_output.c 2005-01-20 03:19:25.000000000 +0100
7570 +++ linux-ebtables/net/ipv4/ip_output.c 2005-02-07 05:52:50.000000000 +0100
7571 @@ -890,6 +890,10 @@
7572 /* Connection association is same as pre-frag packet */
7573 skb2->nfct = skb->nfct;
7574 nf_conntrack_get(skb2->nfct);
7575 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7576 + skb2->nf_bridge = skb->nf_bridge;
7577 + nf_bridge_get(skb2->nf_bridge);
7578 +#endif
7579 #ifdef CONFIG_NETFILTER_DEBUG
7580 skb2->nf_debug = skb->nf_debug;
7581 #endif
7582 diff -Nur linux-mips-cvs/net/ipv4/ip_output.c.orig linux-ebtables/net/ipv4/ip_output.c.orig
7583 --- linux-mips-cvs/net/ipv4/ip_output.c.orig 1970-01-01 01:00:00.000000000 +0100
7584 +++ linux-ebtables/net/ipv4/ip_output.c.orig 2005-01-20 03:19:25.000000000 +0100
7585 @@ -0,0 +1,1036 @@
7586 +/*
7587 + * INET An implementation of the TCP/IP protocol suite for the LINUX
7588 + * operating system. INET is implemented using the BSD Socket
7589 + * interface as the means of communication with the user level.
7590 + *
7591 + * The Internet Protocol (IP) output module.
7592 + *
7593 + * Version: $Id$
7594 + *
7595 + * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
7596 + * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
7597 + * Donald Becker, <becker@super.org>
7598 + * Alan Cox, <Alan.Cox@linux.org>
7599 + * Richard Underwood
7600 + * Stefan Becker, <stefanb@yello.ping.de>
7601 + * Jorge Cwik, <jorge@laser.satlink.net>
7602 + * Arnt Gulbrandsen, <agulbra@nvg.unit.no>
7603 + *
7604 + * See ip_input.c for original log
7605 + *
7606 + * Fixes:
7607 + * Alan Cox : Missing nonblock feature in ip_build_xmit.
7608 + * Mike Kilburn : htons() missing in ip_build_xmit.
7609 + * Bradford Johnson: Fix faulty handling of some frames when
7610 + * no route is found.
7611 + * Alexander Demenshin: Missing sk/skb free in ip_queue_xmit
7612 + * (in case if packet not accepted by
7613 + * output firewall rules)
7614 + * Mike McLagan : Routing by source
7615 + * Alexey Kuznetsov: use new route cache
7616 + * Andi Kleen: Fix broken PMTU recovery and remove
7617 + * some redundant tests.
7618 + * Vitaly E. Lavrov : Transparent proxy revived after year coma.
7619 + * Andi Kleen : Replace ip_reply with ip_send_reply.
7620 + * Andi Kleen : Split fast and slow ip_build_xmit path
7621 + * for decreased register pressure on x86
7622 + * and more readibility.
7623 + * Marc Boucher : When call_out_firewall returns FW_QUEUE,
7624 + * silently drop skb instead of failing with -EPERM.
7625 + * Detlev Wengorz : Copy protocol for fragments.
7626 + */
7627 +
7628 +#include <asm/uaccess.h>
7629 +#include <asm/system.h>
7630 +#include <linux/types.h>
7631 +#include <linux/kernel.h>
7632 +#include <linux/sched.h>
7633 +#include <linux/mm.h>
7634 +#include <linux/string.h>
7635 +#include <linux/errno.h>
7636 +#include <linux/config.h>
7637 +
7638 +#include <linux/socket.h>
7639 +#include <linux/sockios.h>
7640 +#include <linux/in.h>
7641 +#include <linux/inet.h>
7642 +#include <linux/netdevice.h>
7643 +#include <linux/etherdevice.h>
7644 +#include <linux/proc_fs.h>
7645 +#include <linux/stat.h>
7646 +#include <linux/init.h>
7647 +
7648 +#include <net/snmp.h>
7649 +#include <net/ip.h>
7650 +#include <net/protocol.h>
7651 +#include <net/route.h>
7652 +#include <net/tcp.h>
7653 +#include <net/udp.h>
7654 +#include <linux/skbuff.h>
7655 +#include <net/sock.h>
7656 +#include <net/arp.h>
7657 +#include <net/icmp.h>
7658 +#include <net/raw.h>
7659 +#include <net/checksum.h>
7660 +#include <net/inetpeer.h>
7661 +#include <linux/igmp.h>
7662 +#include <linux/netfilter_ipv4.h>
7663 +#include <linux/mroute.h>
7664 +#include <linux/netlink.h>
7665 +
7666 +/*
7667 + * Shall we try to damage output packets if routing dev changes?
7668 + */
7669 +
7670 +int sysctl_ip_dynaddr = 0;
7671 +int sysctl_ip_default_ttl = IPDEFTTL;
7672 +
7673 +/* Generate a checksum for an outgoing IP datagram. */
7674 +__inline__ void ip_send_check(struct iphdr *iph)
7675 +{
7676 + iph->check = 0;
7677 + iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
7678 +}
7679 +
7680 +/* dev_loopback_xmit for use with netfilter. */
7681 +static int ip_dev_loopback_xmit(struct sk_buff *newskb)
7682 +{
7683 + newskb->mac.raw = newskb->data;
7684 + __skb_pull(newskb, newskb->nh.raw - newskb->data);
7685 + newskb->pkt_type = PACKET_LOOPBACK;
7686 + newskb->ip_summed = CHECKSUM_UNNECESSARY;
7687 + BUG_TRAP(newskb->dst);
7688 +
7689 +#ifdef CONFIG_NETFILTER_DEBUG
7690 + nf_debug_ip_loopback_xmit(newskb);
7691 +#endif
7692 + netif_rx(newskb);
7693 + return 0;
7694 +}
7695 +
7696 +/* Don't just hand NF_HOOK skb->dst->output, in case netfilter hook
7697 + changes route */
7698 +static inline int
7699 +output_maybe_reroute(struct sk_buff *skb)
7700 +{
7701 + return skb->dst->output(skb);
7702 +}
7703 +
7704 +/*
7705 + * Add an ip header to a skbuff and send it out.
7706 + */
7707 +int ip_build_and_send_pkt(struct sk_buff *skb, struct sock *sk,
7708 + u32 saddr, u32 daddr, struct ip_options *opt)
7709 +{
7710 + struct rtable *rt = (struct rtable *)skb->dst;
7711 + struct iphdr *iph;
7712 +
7713 + /* Build the IP header. */
7714 + if (opt)
7715 + iph=(struct iphdr *)skb_push(skb,sizeof(struct iphdr) + opt->optlen);
7716 + else
7717 + iph=(struct iphdr *)skb_push(skb,sizeof(struct iphdr));
7718 +
7719 + iph->version = 4;
7720 + iph->ihl = 5;
7721 + iph->tos = sk->protinfo.af_inet.tos;
7722 + if (ip_dont_fragment(sk, &rt->u.dst))
7723 + iph->frag_off = htons(IP_DF);
7724 + else
7725 + iph->frag_off = 0;
7726 + iph->ttl = sk->protinfo.af_inet.ttl;
7727 + iph->daddr = rt->rt_dst;
7728 + iph->saddr = rt->rt_src;
7729 + iph->protocol = sk->protocol;
7730 + iph->tot_len = htons(skb->len);
7731 + ip_select_ident(iph, &rt->u.dst, sk);
7732 + skb->nh.iph = iph;
7733 +
7734 + if (opt && opt->optlen) {
7735 + iph->ihl += opt->optlen>>2;
7736 + ip_options_build(skb, opt, daddr, rt, 0);
7737 + }
7738 + ip_send_check(iph);
7739 +
7740 + /* Send it out. */
7741 + return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
7742 + output_maybe_reroute);
7743 +}
7744 +
7745 +static inline int ip_finish_output2(struct sk_buff *skb)
7746 +{
7747 + struct dst_entry *dst = skb->dst;
7748 + struct hh_cache *hh = dst->hh;
7749 +
7750 +#ifdef CONFIG_NETFILTER_DEBUG
7751 + nf_debug_ip_finish_output2(skb);
7752 +#endif /*CONFIG_NETFILTER_DEBUG*/
7753 +
7754 + if (hh) {
7755 + int hh_alen;
7756 +
7757 + read_lock_bh(&hh->hh_lock);
7758 + hh_alen = HH_DATA_ALIGN(hh->hh_len);
7759 + memcpy(skb->data - hh_alen, hh->hh_data, hh_alen);
7760 + read_unlock_bh(&hh->hh_lock);
7761 + skb_push(skb, hh->hh_len);
7762 + return hh->hh_output(skb);
7763 + } else if (dst->neighbour)
7764 + return dst->neighbour->output(skb);
7765 +
7766 + if (net_ratelimit())
7767 + printk(KERN_DEBUG "ip_finish_output2: No header cache and no neighbour!\n");
7768 + kfree_skb(skb);
7769 + return -EINVAL;
7770 +}
7771 +
7772 +static __inline__ int __ip_finish_output(struct sk_buff *skb)
7773 +{
7774 + struct net_device *dev = skb->dst->dev;
7775 +
7776 + skb->dev = dev;
7777 + skb->protocol = htons(ETH_P_IP);
7778 +
7779 + return NF_HOOK(PF_INET, NF_IP_POST_ROUTING, skb, NULL, dev,
7780 + ip_finish_output2);
7781 +}
7782 +
7783 +int ip_finish_output(struct sk_buff *skb)
7784 +{
7785 + return __ip_finish_output(skb);
7786 +}
7787 +
7788 +int ip_mc_output(struct sk_buff *skb)
7789 +{
7790 + struct sock *sk = skb->sk;
7791 + struct rtable *rt = (struct rtable*)skb->dst;
7792 + struct net_device *dev = rt->u.dst.dev;
7793 +
7794 + /*
7795 + * If the indicated interface is up and running, send the packet.
7796 + */
7797 + IP_INC_STATS(IpOutRequests);
7798 +#ifdef CONFIG_IP_ROUTE_NAT
7799 + if (rt->rt_flags & RTCF_NAT)
7800 + ip_do_nat(skb);
7801 +#endif
7802 +
7803 + skb->dev = dev;
7804 + skb->protocol = htons(ETH_P_IP);
7805 +
7806 + /*
7807 + * Multicasts are looped back for other local users
7808 + */
7809 +
7810 + if (rt->rt_flags&RTCF_MULTICAST) {
7811 + if ((!sk || sk->protinfo.af_inet.mc_loop)
7812 +#ifdef CONFIG_IP_MROUTE
7813 + /* Small optimization: do not loopback not local frames,
7814 + which returned after forwarding; they will be dropped
7815 + by ip_mr_input in any case.
7816 + Note, that local frames are looped back to be delivered
7817 + to local recipients.
7818 +
7819 + This check is duplicated in ip_mr_input at the moment.
7820 + */
7821 + && ((rt->rt_flags&RTCF_LOCAL) || !(IPCB(skb)->flags&IPSKB_FORWARDED))
7822 +#endif
7823 + ) {
7824 + struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
7825 + if (newskb)
7826 + NF_HOOK(PF_INET, NF_IP_POST_ROUTING, newskb, NULL,
7827 + newskb->dev,
7828 + ip_dev_loopback_xmit);
7829 + }
7830 +
7831 + /* Multicasts with ttl 0 must not go beyond the host */
7832 +
7833 + if (skb->nh.iph->ttl == 0) {
7834 + kfree_skb(skb);
7835 + return 0;
7836 + }
7837 + }
7838 +
7839 + if (rt->rt_flags&RTCF_BROADCAST) {
7840 + struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
7841 + if (newskb)
7842 + NF_HOOK(PF_INET, NF_IP_POST_ROUTING, newskb, NULL,
7843 + newskb->dev, ip_dev_loopback_xmit);
7844 + }
7845 +
7846 + return __ip_finish_output(skb);
7847 +}
7848 +
7849 +int ip_output(struct sk_buff *skb)
7850 +{
7851 +#ifdef CONFIG_IP_ROUTE_NAT
7852 + struct rtable *rt = (struct rtable*)skb->dst;
7853 +#endif
7854 +
7855 + IP_INC_STATS(IpOutRequests);
7856 +
7857 +#ifdef CONFIG_IP_ROUTE_NAT
7858 + if (rt->rt_flags&RTCF_NAT)
7859 + ip_do_nat(skb);
7860 +#endif
7861 +
7862 + return __ip_finish_output(skb);
7863 +}
7864 +
7865 +/* Queues a packet to be sent, and starts the transmitter if necessary.
7866 + * This routine also needs to put in the total length and compute the
7867 + * checksum. We use to do this in two stages, ip_build_header() then
7868 + * this, but that scheme created a mess when routes disappeared etc.
7869 + * So we do it all here, and the TCP send engine has been changed to
7870 + * match. (No more unroutable FIN disasters, etc. wheee...) This will
7871 + * most likely make other reliable transport layers above IP easier
7872 + * to implement under Linux.
7873 + */
7874 +static inline int ip_queue_xmit2(struct sk_buff *skb)
7875 +{
7876 + struct sock *sk = skb->sk;
7877 + struct rtable *rt = (struct rtable *)skb->dst;
7878 + struct net_device *dev;
7879 + struct iphdr *iph = skb->nh.iph;
7880 +
7881 + dev = rt->u.dst.dev;
7882 +
7883 + /* This can happen when the transport layer has segments queued
7884 + * with a cached route, and by the time we get here things are
7885 + * re-routed to a device with a different MTU than the original
7886 + * device. Sick, but we must cover it.
7887 + */
7888 + if (skb_headroom(skb) < dev->hard_header_len && dev->hard_header) {
7889 + struct sk_buff *skb2;
7890 +
7891 + skb2 = skb_realloc_headroom(skb, (dev->hard_header_len + 15) & ~15);
7892 + kfree_skb(skb);
7893 + if (skb2 == NULL)
7894 + return -ENOMEM;
7895 + if (sk)
7896 + skb_set_owner_w(skb2, sk);
7897 + skb = skb2;
7898 + iph = skb->nh.iph;
7899 + }
7900 +
7901 + if (skb->len > rt->u.dst.pmtu)
7902 + goto fragment;
7903 +
7904 + ip_select_ident(iph, &rt->u.dst, sk);
7905 +
7906 + /* Add an IP checksum. */
7907 + ip_send_check(iph);
7908 +
7909 + skb->priority = sk->priority;
7910 + return skb->dst->output(skb);
7911 +
7912 +fragment:
7913 + if (ip_dont_fragment(sk, &rt->u.dst)) {
7914 + /* Reject packet ONLY if TCP might fragment
7915 + * it itself, if were careful enough.
7916 + */
7917 + NETDEBUG(printk(KERN_DEBUG "sending pkt_too_big (len[%u] pmtu[%u]) to self\n",
7918 + skb->len, rt->u.dst.pmtu));
7919 +
7920 + icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
7921 + htonl(rt->u.dst.pmtu));
7922 + kfree_skb(skb);
7923 + return -EMSGSIZE;
7924 + }
7925 + ip_select_ident(iph, &rt->u.dst, sk);
7926 + if (skb->ip_summed == CHECKSUM_HW &&
7927 + (skb = skb_checksum_help(skb)) == NULL)
7928 + return -ENOMEM;
7929 + return ip_fragment(skb, skb->dst->output);
7930 +}
7931 +
7932 +int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
7933 +{
7934 + struct sock *sk = skb->sk;
7935 + struct ip_options *opt = sk->protinfo.af_inet.opt;
7936 + struct rtable *rt;
7937 + struct iphdr *iph;
7938 +
7939 + /* Skip all of this if the packet is already routed,
7940 + * f.e. by something like SCTP.
7941 + */
7942 + rt = (struct rtable *) skb->dst;
7943 + if (rt != NULL)
7944 + goto packet_routed;
7945 +
7946 + /* Make sure we can route this packet. */
7947 + rt = (struct rtable *)__sk_dst_check(sk, 0);
7948 + if (rt == NULL) {
7949 + u32 daddr;
7950 +
7951 + /* Use correct destination address if we have options. */
7952 + daddr = sk->daddr;
7953 + if(opt && opt->srr)
7954 + daddr = opt->faddr;
7955 +
7956 + /* If this fails, retransmit mechanism of transport layer will
7957 + * keep trying until route appears or the connection times itself
7958 + * out.
7959 + */
7960 + if (ip_route_output(&rt, daddr, sk->saddr,
7961 + RT_CONN_FLAGS(sk),
7962 + sk->bound_dev_if))
7963 + goto no_route;
7964 + __sk_dst_set(sk, &rt->u.dst);
7965 + sk->route_caps = rt->u.dst.dev->features;
7966 + }
7967 + skb->dst = dst_clone(&rt->u.dst);
7968 +
7969 +packet_routed:
7970 + if (opt && opt->is_strictroute && rt->rt_dst != rt->rt_gateway)
7971 + goto no_route;
7972 +
7973 + /* OK, we know where to send it, allocate and build IP header. */
7974 + iph = (struct iphdr *) skb_push(skb, sizeof(struct iphdr) + (opt ? opt->optlen : 0));
7975 + *((__u16 *)iph) = htons((4 << 12) | (5 << 8) | (sk->protinfo.af_inet.tos & 0xff));
7976 + iph->tot_len = htons(skb->len);
7977 + if (ip_dont_fragment(sk, &rt->u.dst) && !ipfragok)
7978 + iph->frag_off = htons(IP_DF);
7979 + else
7980 + iph->frag_off = 0;
7981 + iph->ttl = sk->protinfo.af_inet.ttl;
7982 + iph->protocol = sk->protocol;
7983 + iph->saddr = rt->rt_src;
7984 + iph->daddr = rt->rt_dst;
7985 + skb->nh.iph = iph;
7986 + /* Transport layer set skb->h.foo itself. */
7987 +
7988 + if(opt && opt->optlen) {
7989 + iph->ihl += opt->optlen >> 2;
7990 + ip_options_build(skb, opt, sk->daddr, rt, 0);
7991 + }
7992 +
7993 + return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
7994 + ip_queue_xmit2);
7995 +
7996 +no_route:
7997 + IP_INC_STATS(IpOutNoRoutes);
7998 + kfree_skb(skb);
7999 + return -EHOSTUNREACH;
8000 +}
8001 +
8002 +/*
8003 + * Build and send a packet, with as little as one copy
8004 + *
8005 + * Doesn't care much about ip options... option length can be
8006 + * different for fragment at 0 and other fragments.
8007 + *
8008 + * Note that the fragment at the highest offset is sent first,
8009 + * so the getfrag routine can fill in the TCP/UDP checksum header
8010 + * field in the last fragment it sends... actually it also helps
8011 + * the reassemblers, they can put most packets in at the head of
8012 + * the fragment queue, and they know the total size in advance. This
8013 + * last feature will measurably improve the Linux fragment handler one
8014 + * day.
8015 + *
8016 + * The callback has five args, an arbitrary pointer (copy of frag),
8017 + * the source IP address (may depend on the routing table), the
8018 + * destination address (char *), the offset to copy from, and the
8019 + * length to be copied.
8020 + */
8021 +
8022 +static int ip_build_xmit_slow(struct sock *sk,
8023 + int getfrag (const void *,
8024 + char *,
8025 + unsigned int,
8026 + unsigned int,
8027 + struct sk_buff *),
8028 + const void *frag,
8029 + unsigned length,
8030 + struct ipcm_cookie *ipc,
8031 + struct rtable *rt,
8032 + int flags)
8033 +{
8034 + unsigned int fraglen, maxfraglen, fragheaderlen;
8035 + int err;
8036 + int offset, mf;
8037 + int mtu;
8038 + u16 id;
8039 +
8040 + int hh_len = (rt->u.dst.dev->hard_header_len + 15)&~15;
8041 + int nfrags=0;
8042 + struct ip_options *opt = ipc->opt;
8043 + int df = 0;
8044 +
8045 + mtu = rt->u.dst.pmtu;
8046 + if (ip_dont_fragment(sk, &rt->u.dst))
8047 + df = htons(IP_DF);
8048 +
8049 + length -= sizeof(struct iphdr);
8050 +
8051 + if (opt) {
8052 + fragheaderlen = sizeof(struct iphdr) + opt->optlen;
8053 + maxfraglen = ((mtu-sizeof(struct iphdr)-opt->optlen) & ~7) + fragheaderlen;
8054 + } else {
8055 + fragheaderlen = sizeof(struct iphdr);
8056 +
8057 + /*
8058 + * Fragheaderlen is the size of 'overhead' on each buffer. Now work
8059 + * out the size of the frames to send.
8060 + */
8061 +
8062 + maxfraglen = ((mtu-sizeof(struct iphdr)) & ~7) + fragheaderlen;
8063 + }
8064 +
8065 + if (length + fragheaderlen > 0xFFFF) {
8066 + ip_local_error(sk, EMSGSIZE, rt->rt_dst, sk->dport, mtu);
8067 + return -EMSGSIZE;
8068 + }
8069 +
8070 + /*
8071 + * Start at the end of the frame by handling the remainder.
8072 + */
8073 +
8074 + offset = length - (length % (maxfraglen - fragheaderlen));
8075 +
8076 + /*
8077 + * Amount of memory to allocate for final fragment.
8078 + */
8079 +
8080 + fraglen = length - offset + fragheaderlen;
8081 +
8082 + if (length-offset==0) {
8083 + fraglen = maxfraglen;
8084 + offset -= maxfraglen-fragheaderlen;
8085 + }
8086 +
8087 + /*
8088 + * The last fragment will not have MF (more fragments) set.
8089 + */
8090 +
8091 + mf = 0;
8092 +
8093 + /*
8094 + * Don't fragment packets for path mtu discovery.
8095 + */
8096 +
8097 + if (offset > 0 && sk->protinfo.af_inet.pmtudisc==IP_PMTUDISC_DO) {
8098 + ip_local_error(sk, EMSGSIZE, rt->rt_dst, sk->dport, mtu);
8099 + return -EMSGSIZE;
8100 + }
8101 + if (flags&MSG_PROBE)
8102 + goto out;
8103 +
8104 + /*
8105 + * Begin outputting the bytes.
8106 + */
8107 +
8108 + id = sk->protinfo.af_inet.id++;
8109 +
8110 + do {
8111 + char *data;
8112 + struct sk_buff * skb;
8113 +
8114 + /*
8115 + * Get the memory we require with some space left for alignment.
8116 + */
8117 + if (!(flags & MSG_DONTWAIT) || nfrags == 0) {
8118 + skb = sock_alloc_send_skb(sk, fraglen + hh_len + 15,
8119 + (flags & MSG_DONTWAIT), &err);
8120 + } else {
8121 + /* On a non-blocking write, we check for send buffer
8122 + * usage on the first fragment only.
8123 + */
8124 + skb = sock_wmalloc(sk, fraglen + hh_len + 15, 1,
8125 + sk->allocation);
8126 + if (!skb)
8127 + err = -ENOBUFS;
8128 + }
8129 + if (skb == NULL)
8130 + goto error;
8131 +
8132 + /*
8133 + * Fill in the control structures
8134 + */
8135 +
8136 + skb->priority = sk->priority;
8137 + skb->dst = dst_clone(&rt->u.dst);
8138 + skb_reserve(skb, hh_len);
8139 +
8140 + /*
8141 + * Find where to start putting bytes.
8142 + */
8143 +
8144 + data = skb_put(skb, fraglen);
8145 + skb->nh.iph = (struct iphdr *)data;
8146 +
8147 + /*
8148 + * Only write IP header onto non-raw packets
8149 + */
8150 +
8151 + {
8152 + struct iphdr *iph = (struct iphdr *)data;
8153 +
8154 + iph->version = 4;
8155 + iph->ihl = 5;
8156 + if (opt) {
8157 + iph->ihl += opt->optlen>>2;
8158 + ip_options_build(skb, opt,
8159 + ipc->addr, rt, offset);
8160 + }
8161 + iph->tos = sk->protinfo.af_inet.tos;
8162 + iph->tot_len = htons(fraglen - fragheaderlen + iph->ihl*4);
8163 + iph->frag_off = htons(offset>>3)|mf|df;
8164 + iph->id = id;
8165 + if (!mf) {
8166 + if (offset || !df) {
8167 + /* Select an unpredictable ident only
8168 + * for packets without DF or having
8169 + * been fragmented.
8170 + */
8171 + __ip_select_ident(iph, &rt->u.dst);
8172 + id = iph->id;
8173 + }
8174 +
8175 + /*
8176 + * Any further fragments will have MF set.
8177 + */
8178 + mf = htons(IP_MF);
8179 + }
8180 + if (rt->rt_type == RTN_MULTICAST)
8181 + iph->ttl = sk->protinfo.af_inet.mc_ttl;
8182 + else
8183 + iph->ttl = sk->protinfo.af_inet.ttl;
8184 + iph->protocol = sk->protocol;
8185 + iph->check = 0;
8186 + iph->saddr = rt->rt_src;
8187 + iph->daddr = rt->rt_dst;
8188 + iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
8189 + data += iph->ihl*4;
8190 + }
8191 +
8192 + /*
8193 + * User data callback
8194 + */
8195 +
8196 + if (getfrag(frag, data, offset, fraglen-fragheaderlen, skb)) {
8197 + err = -EFAULT;
8198 + kfree_skb(skb);
8199 + goto error;
8200 + }
8201 +
8202 + offset -= (maxfraglen-fragheaderlen);
8203 + fraglen = maxfraglen;
8204 +
8205 + nfrags++;
8206 +
8207 + err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL,
8208 + skb->dst->dev, output_maybe_reroute);
8209 + if (err) {
8210 + if (err > 0)
8211 + err = sk->protinfo.af_inet.recverr ? net_xmit_errno(err) : 0;
8212 + if (err)
8213 + goto error;
8214 + }
8215 + } while (offset >= 0);
8216 +
8217 + if (nfrags>1)
8218 + ip_statistics[smp_processor_id()*2 + !in_softirq()].IpFragCreates += nfrags;
8219 +out:
8220 + return 0;
8221 +
8222 +error:
8223 + IP_INC_STATS(IpOutDiscards);
8224 + if (nfrags>1)
8225 + ip_statistics[smp_processor_id()*2 + !in_softirq()].IpFragCreates += nfrags;
8226 + return err;
8227 +}
8228 +
8229 +/*
8230 + * Fast path for unfragmented packets.
8231 + */
8232 +int ip_build_xmit(struct sock *sk,
8233 + int getfrag (const void *,
8234 + char *,
8235 + unsigned int,
8236 + unsigned int,
8237 + struct sk_buff *),
8238 + const void *frag,
8239 + unsigned length,
8240 + struct ipcm_cookie *ipc,
8241 + struct rtable *rt,
8242 + int flags)
8243 +{
8244 + int err;
8245 + struct sk_buff *skb;
8246 + int df;
8247 + struct iphdr *iph;
8248 +
8249 + /*
8250 + * Try the simple case first. This leaves fragmented frames, and by
8251 + * choice RAW frames within 20 bytes of maximum size(rare) to the long path
8252 + */
8253 +
8254 + if (!sk->protinfo.af_inet.hdrincl) {
8255 + length += sizeof(struct iphdr);
8256 +
8257 + /*
8258 + * Check for slow path.
8259 + */
8260 + if (length > rt->u.dst.pmtu || ipc->opt != NULL)
8261 + return ip_build_xmit_slow(sk,getfrag,frag,length,ipc,rt,flags);
8262 + } else {
8263 + if (length > rt->u.dst.dev->mtu) {
8264 + ip_local_error(sk, EMSGSIZE, rt->rt_dst, sk->dport, rt->u.dst.dev->mtu);
8265 + return -EMSGSIZE;
8266 + }
8267 + }
8268 + if (flags&MSG_PROBE)
8269 + goto out;
8270 +
8271 + /*
8272 + * Do path mtu discovery if needed.
8273 + */
8274 + df = 0;
8275 + if (ip_dont_fragment(sk, &rt->u.dst))
8276 + df = htons(IP_DF);
8277 +
8278 + /*
8279 + * Fast path for unfragmented frames without options.
8280 + */
8281 + {
8282 + int hh_len = (rt->u.dst.dev->hard_header_len + 15)&~15;
8283 +
8284 + skb = sock_alloc_send_skb(sk, length+hh_len+15,
8285 + flags&MSG_DONTWAIT, &err);
8286 + if(skb==NULL)
8287 + goto error;
8288 + skb_reserve(skb, hh_len);
8289 + }
8290 +
8291 + skb->priority = sk->priority;
8292 + skb->dst = dst_clone(&rt->u.dst);
8293 +
8294 + skb->nh.iph = iph = (struct iphdr *)skb_put(skb, length);
8295 +
8296 + if(!sk->protinfo.af_inet.hdrincl) {
8297 + iph->version=4;
8298 + iph->ihl=5;
8299 + iph->tos=sk->protinfo.af_inet.tos;
8300 + iph->tot_len = htons(length);
8301 + iph->frag_off = df;
8302 + iph->ttl=sk->protinfo.af_inet.mc_ttl;
8303 + ip_select_ident(iph, &rt->u.dst, sk);
8304 + if (rt->rt_type != RTN_MULTICAST)
8305 + iph->ttl=sk->protinfo.af_inet.ttl;
8306 + iph->protocol=sk->protocol;
8307 + iph->saddr=rt->rt_src;
8308 + iph->daddr=rt->rt_dst;
8309 + iph->check=0;
8310 + iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
8311 + err = getfrag(frag, ((char *)iph)+iph->ihl*4,0, length-iph->ihl*4, skb);
8312 + }
8313 + else
8314 + err = getfrag(frag, (void *)iph, 0, length, skb);
8315 +
8316 + if (err)
8317 + goto error_fault;
8318 +
8319 + err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
8320 + output_maybe_reroute);
8321 + if (err > 0)
8322 + err = sk->protinfo.af_inet.recverr ? net_xmit_errno(err) : 0;
8323 + if (err)
8324 + goto error;
8325 +out:
8326 + return 0;
8327 +
8328 +error_fault:
8329 + err = -EFAULT;
8330 + kfree_skb(skb);
8331 +error:
8332 + IP_INC_STATS(IpOutDiscards);
8333 + return err;
8334 +}
8335 +
8336 +/*
8337 + * This IP datagram is too large to be sent in one piece. Break it up into
8338 + * smaller pieces (each of size equal to IP header plus
8339 + * a block of the data of the original IP data part) that will yet fit in a
8340 + * single device frame, and queue such a frame for sending.
8341 + *
8342 + * Yes this is inefficient, feel free to submit a quicker one.
8343 + */
8344 +
8345 +int ip_fragment(struct sk_buff *skb, int (*output)(struct sk_buff*))
8346 +{
8347 + struct iphdr *iph;
8348 + int raw = 0;
8349 + int ptr;
8350 + struct net_device *dev;
8351 + struct sk_buff *skb2;
8352 + unsigned int mtu, hlen, left, len;
8353 + int offset;
8354 + int not_last_frag;
8355 + struct rtable *rt = (struct rtable*)skb->dst;
8356 + int err = 0;
8357 +
8358 + dev = rt->u.dst.dev;
8359 +
8360 + /*
8361 + * Point into the IP datagram header.
8362 + */
8363 +
8364 + iph = skb->nh.iph;
8365 +
8366 + /*
8367 + * Setup starting values.
8368 + */
8369 +
8370 + hlen = iph->ihl * 4;
8371 + left = skb->len - hlen; /* Space per frame */
8372 + mtu = rt->u.dst.pmtu - hlen; /* Size of data space */
8373 + ptr = raw + hlen; /* Where to start from */
8374 +
8375 + /*
8376 + * Fragment the datagram.
8377 + */
8378 +
8379 + offset = (ntohs(iph->frag_off) & IP_OFFSET) << 3;
8380 + not_last_frag = iph->frag_off & htons(IP_MF);
8381 +
8382 + /*
8383 + * Keep copying data until we run out.
8384 + */
8385 +
8386 + while(left > 0) {
8387 + len = left;
8388 + /* IF: it doesn't fit, use 'mtu' - the data space left */
8389 + if (len > mtu)
8390 + len = mtu;
8391 + /* IF: we are not sending upto and including the packet end
8392 + then align the next start on an eight byte boundary */
8393 + if (len < left) {
8394 + len &= ~7;
8395 + }
8396 + /*
8397 + * Allocate buffer.
8398 + */
8399 +
8400 + if ((skb2 = alloc_skb(len+hlen+dev->hard_header_len+15,GFP_ATOMIC)) == NULL) {
8401 + NETDEBUG(printk(KERN_INFO "IP: frag: no memory for new fragment!\n"));
8402 + err = -ENOMEM;
8403 + goto fail;
8404 + }
8405 +
8406 + /*
8407 + * Set up data on packet
8408 + */
8409 +
8410 + skb2->pkt_type = skb->pkt_type;
8411 + skb2->priority = skb->priority;
8412 + skb_reserve(skb2, (dev->hard_header_len+15)&~15);
8413 + skb_put(skb2, len + hlen);
8414 + skb2->nh.raw = skb2->data;
8415 + skb2->h.raw = skb2->data + hlen;
8416 + skb2->protocol = skb->protocol;
8417 + skb2->security = skb->security;
8418 +
8419 + /*
8420 + * Charge the memory for the fragment to any owner
8421 + * it might possess
8422 + */
8423 +
8424 + if (skb->sk)
8425 + skb_set_owner_w(skb2, skb->sk);
8426 + skb2->dst = dst_clone(skb->dst);
8427 + skb2->dev = skb->dev;
8428 +
8429 + /*
8430 + * Copy the packet header into the new buffer.
8431 + */
8432 +
8433 + memcpy(skb2->nh.raw, skb->data, hlen);
8434 +
8435 + /*
8436 + * Copy a block of the IP datagram.
8437 + */
8438 + if (skb_copy_bits(skb, ptr, skb2->h.raw, len))
8439 + BUG();
8440 + left -= len;
8441 +
8442 + /*
8443 + * Fill in the new header fields.
8444 + */
8445 + iph = skb2->nh.iph;
8446 + iph->frag_off = htons((offset >> 3));
8447 +
8448 + /* ANK: dirty, but effective trick. Upgrade options only if
8449 + * the segment to be fragmented was THE FIRST (otherwise,
8450 + * options are already fixed) and make it ONCE
8451 + * on the initial skb, so that all the following fragments
8452 + * will inherit fixed options.
8453 + */
8454 + if (offset == 0)
8455 + ip_options_fragment(skb);
8456 +
8457 + /* Copy the flags to each fragment. */
8458 + IPCB(skb2)->flags = IPCB(skb)->flags;
8459 +
8460 + /*
8461 + * Added AC : If we are fragmenting a fragment that's not the
8462 + * last fragment then keep MF on each bit
8463 + */
8464 + if (left > 0 || not_last_frag)
8465 + iph->frag_off |= htons(IP_MF);
8466 + ptr += len;
8467 + offset += len;
8468 +
8469 +#ifdef CONFIG_NET_SCHED
8470 + skb2->tc_index = skb->tc_index;
8471 +#endif
8472 +#ifdef CONFIG_NETFILTER
8473 + skb2->nfmark = skb->nfmark;
8474 + skb2->nfcache = skb->nfcache;
8475 + /* Connection association is same as pre-frag packet */
8476 + skb2->nfct = skb->nfct;
8477 + nf_conntrack_get(skb2->nfct);
8478 +#ifdef CONFIG_NETFILTER_DEBUG
8479 + skb2->nf_debug = skb->nf_debug;
8480 +#endif
8481 +#endif
8482 +
8483 + /*
8484 + * Put this fragment into the sending queue.
8485 + */
8486 +
8487 + IP_INC_STATS(IpFragCreates);
8488 +
8489 + iph->tot_len = htons(len + hlen);
8490 +
8491 + ip_send_check(iph);
8492 +
8493 + err = output(skb2);
8494 + if (err)
8495 + goto fail;
8496 + }
8497 + kfree_skb(skb);
8498 + IP_INC_STATS(IpFragOKs);
8499 + return err;
8500 +
8501 +fail:
8502 + kfree_skb(skb);
8503 + IP_INC_STATS(IpFragFails);
8504 + return err;
8505 +}
8506 +
8507 +/*
8508 + * Fetch data from kernel space and fill in checksum if needed.
8509 + */
8510 +static int ip_reply_glue_bits(const void *dptr, char *to, unsigned int offset,
8511 + unsigned int fraglen, struct sk_buff *skb)
8512 +{
8513 + struct ip_reply_arg *dp = (struct ip_reply_arg*)dptr;
8514 + u16 *pktp = (u16 *)to;
8515 + struct iovec *iov;
8516 + int len;
8517 + int hdrflag = 1;
8518 +
8519 + iov = &dp->iov[0];
8520 + if (offset >= iov->iov_len) {
8521 + offset -= iov->iov_len;
8522 + iov++;
8523 + hdrflag = 0;
8524 + }
8525 + len = iov->iov_len - offset;
8526 + if (fraglen > len) { /* overlapping. */
8527 + dp->csum = csum_partial_copy_nocheck(iov->iov_base+offset, to, len,
8528 + dp->csum);
8529 + offset = 0;
8530 + fraglen -= len;
8531 + to += len;
8532 + iov++;
8533 + }
8534 +
8535 + dp->csum = csum_partial_copy_nocheck(iov->iov_base+offset, to, fraglen,
8536 + dp->csum);
8537 +
8538 + if (hdrflag && dp->csumoffset)
8539 + *(pktp + dp->csumoffset) = csum_fold(dp->csum); /* fill in checksum */
8540 + return 0;
8541 +}
8542 +
8543 +/*
8544 + * Generic function to send a packet as reply to another packet.
8545 + * Used to send TCP resets so far. ICMP should use this function too.
8546 + *
8547 + * Should run single threaded per socket because it uses the sock
8548 + * structure to pass arguments.
8549 + */
8550 +void ip_send_reply(struct sock *sk, struct sk_buff *skb, struct ip_reply_arg *arg,
8551 + unsigned int len)
8552 +{
8553 + struct {
8554 + struct ip_options opt;
8555 + char data[40];
8556 + } replyopts;
8557 + struct ipcm_cookie ipc;
8558 + u32 daddr;
8559 + struct rtable *rt = (struct rtable*)skb->dst;
8560 +
8561 + if (ip_options_echo(&replyopts.opt, skb))
8562 + return;
8563 +
8564 + daddr = ipc.addr = rt->rt_src;
8565 + ipc.opt = NULL;
8566 +
8567 + if (replyopts.opt.optlen) {
8568 + ipc.opt = &replyopts.opt;
8569 +
8570 + if (ipc.opt->srr)
8571 + daddr = replyopts.opt.faddr;
8572 + }
8573 +
8574 + if (ip_route_output(&rt, daddr, rt->rt_spec_dst, RT_TOS(skb->nh.iph->tos), 0))
8575 + return;
8576 +
8577 + /* And let IP do all the hard work.
8578 +
8579 + This chunk is not reenterable, hence spinlock.
8580 + Note that it uses the fact, that this function is called
8581 + with locally disabled BH and that sk cannot be already spinlocked.
8582 + */
8583 + bh_lock_sock(sk);
8584 + sk->protinfo.af_inet.tos = skb->nh.iph->tos;
8585 + sk->priority = skb->priority;
8586 + sk->protocol = skb->nh.iph->protocol;
8587 + ip_build_xmit(sk, ip_reply_glue_bits, arg, len, &ipc, rt, MSG_DONTWAIT);
8588 + bh_unlock_sock(sk);
8589 +
8590 + ip_rt_put(rt);
8591 +}
8592 +
8593 +/*
8594 + * IP protocol layer initialiser
8595 + */
8596 +
8597 +static struct packet_type ip_packet_type =
8598 +{
8599 + __constant_htons(ETH_P_IP),
8600 + NULL, /* All devices */
8601 + ip_rcv,
8602 + (void*)1,
8603 + NULL,
8604 +};
8605 +
8606 +/*
8607 + * IP registers the packet type and then calls the subprotocol initialisers
8608 + */
8609 +
8610 +void __init ip_init(void)
8611 +{
8612 + dev_add_pack(&ip_packet_type);
8613 +
8614 + ip_rt_init();
8615 + inet_initpeers();
8616 +
8617 +#ifdef CONFIG_IP_MULTICAST
8618 + proc_net_create("igmp", 0, ip_mc_procinfo);
8619 +#endif
8620 + proc_net_create("mcfilter", 0, ip_mcf_procinfo);
8621 +}
8622 diff -Nur linux-mips-cvs/net/ipv4/netfilter/Config.in linux-ebtables/net/ipv4/netfilter/Config.in
8623 --- linux-mips-cvs/net/ipv4/netfilter/Config.in 2005-01-20 03:19:25.000000000 +0100
8624 +++ linux-ebtables/net/ipv4/netfilter/Config.in 2005-02-07 05:52:50.000000000 +0100
8625 @@ -44,6 +44,9 @@
8626 dep_tristate ' Unclean match support (EXPERIMENTAL)' CONFIG_IP_NF_MATCH_UNCLEAN $CONFIG_IP_NF_IPTABLES
8627 dep_tristate ' Owner match support (EXPERIMENTAL)' CONFIG_IP_NF_MATCH_OWNER $CONFIG_IP_NF_IPTABLES
8628 fi
8629 + if [ "$CONFIG_BRIDGE" != "n" ]; then
8630 + dep_tristate ' Physdev match support' CONFIG_IP_NF_MATCH_PHYSDEV $CONFIG_IP_NF_IPTABLES
8631 + fi
8632 # The targets
8633 dep_tristate ' Packet filtering' CONFIG_IP_NF_FILTER $CONFIG_IP_NF_IPTABLES
8634 if [ "$CONFIG_IP_NF_FILTER" != "n" ]; then
8635 diff -Nur linux-mips-cvs/net/ipv4/netfilter/Makefile linux-ebtables/net/ipv4/netfilter/Makefile
8636 --- linux-mips-cvs/net/ipv4/netfilter/Makefile 2003-08-13 19:19:30.000000000 +0200
8637 +++ linux-ebtables/net/ipv4/netfilter/Makefile 2005-02-07 05:52:50.000000000 +0100
8638 @@ -87,6 +87,8 @@
8639 obj-$(CONFIG_IP_NF_MATCH_UNCLEAN) += ipt_unclean.o
8640 obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o
8641
8642 +obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
8643 +
8644 # targets
8645 obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
8646 obj-$(CONFIG_IP_NF_TARGET_MIRROR) += ipt_MIRROR.o
8647 diff -Nur linux-mips-cvs/net/ipv4/netfilter/ip_tables.c linux-ebtables/net/ipv4/netfilter/ip_tables.c
8648 --- linux-mips-cvs/net/ipv4/netfilter/ip_tables.c 2005-01-20 03:19:25.000000000 +0100
8649 +++ linux-ebtables/net/ipv4/netfilter/ip_tables.c 2005-02-07 05:52:50.000000000 +0100
8650 @@ -118,12 +118,19 @@
8651 static inline int
8652 ip_packet_match(const struct iphdr *ip,
8653 const char *indev,
8654 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8655 + const char *physindev,
8656 +#endif
8657 const char *outdev,
8658 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8659 + const char *physoutdev,
8660 +#endif
8661 const struct ipt_ip *ipinfo,
8662 int isfrag)
8663 {
8664 size_t i;
8665 unsigned long ret;
8666 + unsigned long ret2 = 1;
8667
8668 #define FWINV(bool,invflg) ((bool) ^ !!(ipinfo->invflags & invflg))
8669
8670 @@ -153,7 +160,15 @@
8671 & ((const unsigned long *)ipinfo->iniface_mask)[i];
8672 }
8673
8674 - if (FWINV(ret != 0, IPT_INV_VIA_IN)) {
8675 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8676 + for (i = 0, ret2 = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
8677 + ret2 |= (((const unsigned long *)physindev)[i]
8678 + ^ ((const unsigned long *)ipinfo->iniface)[i])
8679 + & ((const unsigned long *)ipinfo->iniface_mask)[i];
8680 + }
8681 +#endif
8682 +
8683 + if (FWINV(ret != 0 && ret2 != 0, IPT_INV_VIA_IN)) {
8684 dprintf("VIA in mismatch (%s vs %s).%s\n",
8685 indev, ipinfo->iniface,
8686 ipinfo->invflags&IPT_INV_VIA_IN ?" (INV)":"");
8687 @@ -166,7 +181,15 @@
8688 & ((const unsigned long *)ipinfo->outiface_mask)[i];
8689 }
8690
8691 - if (FWINV(ret != 0, IPT_INV_VIA_OUT)) {
8692 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8693 + for (i = 0, ret2 = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
8694 + ret2 |= (((const unsigned long *)physoutdev)[i]
8695 + ^ ((const unsigned long *)ipinfo->outiface)[i])
8696 + & ((const unsigned long *)ipinfo->outiface_mask)[i];
8697 + }
8698 +#endif
8699 +
8700 + if (FWINV(ret != 0 && ret2 != 0, IPT_INV_VIA_OUT)) {
8701 dprintf("VIA out mismatch (%s vs %s).%s\n",
8702 outdev, ipinfo->outiface,
8703 ipinfo->invflags&IPT_INV_VIA_OUT ?" (INV)":"");
8704 @@ -265,6 +288,9 @@
8705 /* Initializing verdict to NF_DROP keeps gcc happy. */
8706 unsigned int verdict = NF_DROP;
8707 const char *indev, *outdev;
8708 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8709 + const char *physindev, *physoutdev;
8710 +#endif
8711 void *table_base;
8712 struct ipt_entry *e, *back;
8713
8714 @@ -274,6 +300,13 @@
8715 datalen = (*pskb)->len - ip->ihl * 4;
8716 indev = in ? in->name : nulldevname;
8717 outdev = out ? out->name : nulldevname;
8718 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8719 + physindev = ((*pskb)->nf_bridge && (*pskb)->nf_bridge->physindev) ?
8720 + (*pskb)->nf_bridge->physindev->name : nulldevname;
8721 + physoutdev = ((*pskb)->nf_bridge && (*pskb)->nf_bridge->physoutdev) ?
8722 + (*pskb)->nf_bridge->physoutdev->name : nulldevname;
8723 +#endif
8724 +
8725 /* We handle fragments by dealing with the first fragment as
8726 * if it was a normal packet. All other fragments are treated
8727 * normally, except that they will NEVER match rules that ask
8728 @@ -309,7 +342,15 @@
8729 IP_NF_ASSERT(e);
8730 IP_NF_ASSERT(back);
8731 (*pskb)->nfcache |= e->nfcache;
8732 - if (ip_packet_match(ip, indev, outdev, &e->ip, offset)) {
8733 + if (ip_packet_match(ip, indev,
8734 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8735 + physindev,
8736 +#endif
8737 + outdev,
8738 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8739 + physoutdev,
8740 +#endif
8741 + &e->ip, offset)) {
8742 struct ipt_entry_target *t;
8743
8744 if (IPT_MATCH_ITERATE(e, do_match,
8745 diff -Nur linux-mips-cvs/net/ipv4/netfilter/ipt_LOG.c linux-ebtables/net/ipv4/netfilter/ipt_LOG.c
8746 --- linux-mips-cvs/net/ipv4/netfilter/ipt_LOG.c 2003-11-17 02:07:48.000000000 +0100
8747 +++ linux-ebtables/net/ipv4/netfilter/ipt_LOG.c 2005-02-07 05:52:50.000000000 +0100
8748 @@ -316,6 +316,18 @@
8749 loginfo->prefix,
8750 in ? in->name : "",
8751 out ? out->name : "");
8752 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8753 + if ((*pskb)->nf_bridge) {
8754 + struct net_device *physindev = (*pskb)->nf_bridge->physindev;
8755 + struct net_device *physoutdev = (*pskb)->nf_bridge->physoutdev;
8756 +
8757 + if (physindev && in != physindev)
8758 + printk("PHYSIN=%s ", physindev->name);
8759 + if (physoutdev && out != physoutdev)
8760 + printk("PHYSOUT=%s ", physoutdev->name);
8761 + }
8762 +#endif
8763 +
8764 if (in && !out) {
8765 /* MAC logging for input chain only. */
8766 printk("MAC=");
8767 diff -Nur linux-mips-cvs/net/ipv4/netfilter/ipt_REJECT.c linux-ebtables/net/ipv4/netfilter/ipt_REJECT.c
8768 --- linux-mips-cvs/net/ipv4/netfilter/ipt_REJECT.c 2005-01-20 03:19:25.000000000 +0100
8769 +++ linux-ebtables/net/ipv4/netfilter/ipt_REJECT.c 2005-02-07 05:52:50.000000000 +0100
8770 @@ -15,6 +15,9 @@
8771 #include <net/route.h>
8772 #include <linux/netfilter_ipv4/ip_tables.h>
8773 #include <linux/netfilter_ipv4/ipt_REJECT.h>
8774 +#ifdef CONFIG_BRIDGE_NETFILTER
8775 +#include <linux/netfilter_bridge.h>
8776 +#endif
8777
8778 #if 0
8779 #define DEBUGP printk
8780 @@ -29,7 +32,13 @@
8781 struct rt_key key = {};
8782 struct rtable *rt;
8783
8784 - if (hook != NF_IP_FORWARD) {
8785 + /* We don't require ip forwarding to be enabled to be able to
8786 + * send a RST reply for bridged traffic. */
8787 + if (hook != NF_IP_FORWARD
8788 +#ifdef CONFIG_BRIDGE_NETFILTER
8789 + || (skb->nf_bridge && skb->nf_bridge->mask & BRNF_BRIDGED)
8790 +#endif
8791 + ) {
8792 key.dst = iph->saddr;
8793 if (hook == NF_IP_LOCAL_IN)
8794 key.src = iph->daddr;
8795 diff -Nur linux-mips-cvs/net/ipv4/netfilter/ipt_REJECT.c.orig linux-ebtables/net/ipv4/netfilter/ipt_REJECT.c.orig
8796 --- linux-mips-cvs/net/ipv4/netfilter/ipt_REJECT.c.orig 1970-01-01 01:00:00.000000000 +0100
8797 +++ linux-ebtables/net/ipv4/netfilter/ipt_REJECT.c.orig 2005-01-20 03:19:25.000000000 +0100
8798 @@ -0,0 +1,426 @@
8799 +/*
8800 + * This is a module which is used for rejecting packets.
8801 + * Added support for customized reject packets (Jozsef Kadlecsik).
8802 + * Added support for ICMP type-3-code-13 (Maciej Soltysiak). [RFC 1812]
8803 + */
8804 +#include <linux/config.h>
8805 +#include <linux/module.h>
8806 +#include <linux/skbuff.h>
8807 +#include <linux/ip.h>
8808 +#include <linux/udp.h>
8809 +#include <linux/icmp.h>
8810 +#include <net/icmp.h>
8811 +#include <net/ip.h>
8812 +#include <net/tcp.h>
8813 +#include <net/route.h>
8814 +#include <linux/netfilter_ipv4/ip_tables.h>
8815 +#include <linux/netfilter_ipv4/ipt_REJECT.h>
8816 +
8817 +#if 0
8818 +#define DEBUGP printk
8819 +#else
8820 +#define DEBUGP(format, args...)
8821 +#endif
8822 +
8823 +static inline struct rtable *route_reverse(struct sk_buff *skb, int hook)
8824 +{
8825 + struct iphdr *iph = skb->nh.iph;
8826 + struct dst_entry *odst;
8827 + struct rt_key key = {};
8828 + struct rtable *rt;
8829 +
8830 + if (hook != NF_IP_FORWARD) {
8831 + key.dst = iph->saddr;
8832 + if (hook == NF_IP_LOCAL_IN)
8833 + key.src = iph->daddr;
8834 + key.tos = RT_TOS(iph->tos);
8835 +
8836 + if (ip_route_output_key(&rt, &key) != 0)
8837 + return NULL;
8838 + } else {
8839 + /* non-local src, find valid iif to satisfy
8840 + * rp-filter when calling ip_route_input. */
8841 + key.dst = iph->daddr;
8842 + if (ip_route_output_key(&rt, &key) != 0)
8843 + return NULL;
8844 +
8845 + odst = skb->dst;
8846 + if (ip_route_input(skb, iph->saddr, iph->daddr,
8847 + RT_TOS(iph->tos), rt->u.dst.dev) != 0) {
8848 + dst_release(&rt->u.dst);
8849 + return NULL;
8850 + }
8851 + dst_release(&rt->u.dst);
8852 + rt = (struct rtable *)skb->dst;
8853 + skb->dst = odst;
8854 + }
8855 +
8856 + if (rt->u.dst.error) {
8857 + dst_release(&rt->u.dst);
8858 + rt = NULL;
8859 + }
8860 +
8861 + return rt;
8862 +}
8863 +
8864 +/* Send RST reply */
8865 +static void send_reset(struct sk_buff *oldskb, int hook)
8866 +{
8867 + struct sk_buff *nskb;
8868 + struct tcphdr *otcph, *tcph;
8869 + struct rtable *rt;
8870 + unsigned int otcplen;
8871 + u_int16_t tmp_port;
8872 + u_int32_t tmp_addr;
8873 + int needs_ack;
8874 + int hh_len;
8875 +
8876 + /* IP header checks: fragment, too short. */
8877 + if (oldskb->nh.iph->frag_off & htons(IP_OFFSET)
8878 + || oldskb->len < (oldskb->nh.iph->ihl<<2) + sizeof(struct tcphdr))
8879 + return;
8880 +
8881 + otcph = (struct tcphdr *)((u_int32_t*)oldskb->nh.iph + oldskb->nh.iph->ihl);
8882 + otcplen = oldskb->len - oldskb->nh.iph->ihl*4;
8883 +
8884 + /* No RST for RST. */
8885 + if (otcph->rst)
8886 + return;
8887 +
8888 + /* Check checksum. */
8889 + if (tcp_v4_check(otcph, otcplen, oldskb->nh.iph->saddr,
8890 + oldskb->nh.iph->daddr,
8891 + csum_partial((char *)otcph, otcplen, 0)) != 0)
8892 + return;
8893 +
8894 + if ((rt = route_reverse(oldskb, hook)) == NULL)
8895 + return;
8896 +
8897 + hh_len = (rt->u.dst.dev->hard_header_len + 15)&~15;
8898 +
8899 +
8900 + /* Copy skb (even if skb is about to be dropped, we can't just
8901 + clone it because there may be other things, such as tcpdump,
8902 + interested in it). We also need to expand headroom in case
8903 + hh_len of incoming interface < hh_len of outgoing interface */
8904 + nskb = skb_copy_expand(oldskb, hh_len, skb_tailroom(oldskb),
8905 + GFP_ATOMIC);
8906 + if (!nskb) {
8907 + dst_release(&rt->u.dst);
8908 + return;
8909 + }
8910 +
8911 + dst_release(nskb->dst);
8912 + nskb->dst = &rt->u.dst;
8913 +
8914 + /* This packet will not be the same as the other: clear nf fields */
8915 + nf_reset(nskb);
8916 + nskb->nfcache = 0;
8917 + nskb->nfmark = 0;
8918 +
8919 + tcph = (struct tcphdr *)((u_int32_t*)nskb->nh.iph + nskb->nh.iph->ihl);
8920 +
8921 + /* Swap source and dest */
8922 + tmp_addr = nskb->nh.iph->saddr;
8923 + nskb->nh.iph->saddr = nskb->nh.iph->daddr;
8924 + nskb->nh.iph->daddr = tmp_addr;
8925 + tmp_port = tcph->source;
8926 + tcph->source = tcph->dest;
8927 + tcph->dest = tmp_port;
8928 +
8929 + /* Truncate to length (no data) */
8930 + tcph->doff = sizeof(struct tcphdr)/4;
8931 + skb_trim(nskb, nskb->nh.iph->ihl*4 + sizeof(struct tcphdr));
8932 + nskb->nh.iph->tot_len = htons(nskb->len);
8933 +
8934 + if (tcph->ack) {
8935 + needs_ack = 0;
8936 + tcph->seq = otcph->ack_seq;
8937 + tcph->ack_seq = 0;
8938 + } else {
8939 + needs_ack = 1;
8940 + tcph->ack_seq = htonl(ntohl(otcph->seq) + otcph->syn + otcph->fin
8941 + + otcplen - (otcph->doff<<2));
8942 + tcph->seq = 0;
8943 + }
8944 +
8945 + /* Reset flags */
8946 + ((u_int8_t *)tcph)[13] = 0;
8947 + tcph->rst = 1;
8948 + tcph->ack = needs_ack;
8949 +
8950 + tcph->window = 0;
8951 + tcph->urg_ptr = 0;
8952 +
8953 + /* Adjust TCP checksum */
8954 + tcph->check = 0;
8955 + tcph->check = tcp_v4_check(tcph, sizeof(struct tcphdr),
8956 + nskb->nh.iph->saddr,
8957 + nskb->nh.iph->daddr,
8958 + csum_partial((char *)tcph,
8959 + sizeof(struct tcphdr), 0));
8960 +
8961 + /* Adjust IP TTL, DF */
8962 + nskb->nh.iph->ttl = MAXTTL;
8963 + /* Set DF, id = 0 */
8964 + nskb->nh.iph->frag_off = htons(IP_DF);
8965 + nskb->nh.iph->id = 0;
8966 +
8967 + /* Adjust IP checksum */
8968 + nskb->nh.iph->check = 0;
8969 + nskb->nh.iph->check = ip_fast_csum((unsigned char *)nskb->nh.iph,
8970 + nskb->nh.iph->ihl);
8971 +
8972 + /* "Never happens" */
8973 + if (nskb->len > nskb->dst->pmtu)
8974 + goto free_nskb;
8975 +
8976 + nf_ct_attach(nskb, oldskb);
8977 +
8978 + NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, nskb, NULL, nskb->dst->dev,
8979 + ip_finish_output);
8980 + return;
8981 +
8982 + free_nskb:
8983 + kfree_skb(nskb);
8984 +}
8985 +
8986 +static void send_unreach(struct sk_buff *skb_in, int code)
8987 +{
8988 + struct iphdr *iph;
8989 + struct udphdr *udph;
8990 + struct icmphdr *icmph;
8991 + struct sk_buff *nskb;
8992 + u32 saddr;
8993 + u8 tos;
8994 + int hh_len, length;
8995 + struct rtable *rt = (struct rtable*)skb_in->dst;
8996 + unsigned char *data;
8997 +
8998 + if (!rt)
8999 + return;
9000 +
9001 + /* FIXME: Use sysctl number. --RR */
9002 + if (!xrlim_allow(&rt->u.dst, 1*HZ))
9003 + return;
9004 +
9005 + iph = skb_in->nh.iph;
9006 +
9007 + /* No replies to physical multicast/broadcast */
9008 + if (skb_in->pkt_type!=PACKET_HOST)
9009 + return;
9010 +
9011 + /* Now check at the protocol level */
9012 + if (rt->rt_flags&(RTCF_BROADCAST|RTCF_MULTICAST))
9013 + return;
9014 +
9015 + /* Only reply to fragment 0. */
9016 + if (iph->frag_off&htons(IP_OFFSET))
9017 + return;
9018 +
9019 + /* if UDP checksum is set, verify it's correct */
9020 + if (iph->protocol == IPPROTO_UDP
9021 + && skb_in->tail-(u8*)iph >= sizeof(struct udphdr)) {
9022 + int datalen = skb_in->len - (iph->ihl<<2);
9023 + udph = (struct udphdr *)((char *)iph + (iph->ihl<<2));
9024 + if (udph->check
9025 + && csum_tcpudp_magic(iph->saddr, iph->daddr,
9026 + datalen, IPPROTO_UDP,
9027 + csum_partial((char *)udph, datalen,
9028 + 0)) != 0)
9029 + return;
9030 + }
9031 +
9032 + /* If we send an ICMP error to an ICMP error a mess would result.. */
9033 + if (iph->protocol == IPPROTO_ICMP
9034 + && skb_in->tail-(u8*)iph >= sizeof(struct icmphdr)) {
9035 + icmph = (struct icmphdr *)((char *)iph + (iph->ihl<<2));
9036 + /* Between echo-reply (0) and timestamp (13),
9037 + everything except echo-request (8) is an error.
9038 + Also, anything greater than NR_ICMP_TYPES is
9039 + unknown, and hence should be treated as an error... */
9040 + if ((icmph->type < ICMP_TIMESTAMP
9041 + && icmph->type != ICMP_ECHOREPLY
9042 + && icmph->type != ICMP_ECHO)
9043 + || icmph->type > NR_ICMP_TYPES)
9044 + return;
9045 + }
9046 +
9047 + saddr = iph->daddr;
9048 + if (!(rt->rt_flags & RTCF_LOCAL))
9049 + saddr = 0;
9050 +
9051 + tos = (iph->tos & IPTOS_TOS_MASK) | IPTOS_PREC_INTERNETCONTROL;
9052 +
9053 + if (ip_route_output(&rt, iph->saddr, saddr, RT_TOS(tos), 0))
9054 + return;
9055 +
9056 + /* RFC says return as much as we can without exceeding 576 bytes. */
9057 + length = skb_in->len + sizeof(struct iphdr) + sizeof(struct icmphdr);
9058 +
9059 + if (length > rt->u.dst.pmtu)
9060 + length = rt->u.dst.pmtu;
9061 + if (length > 576)
9062 + length = 576;
9063 +
9064 + hh_len = (rt->u.dst.dev->hard_header_len + 15)&~15;
9065 +
9066 + nskb = alloc_skb(hh_len+15+length, GFP_ATOMIC);
9067 + if (!nskb) {
9068 + ip_rt_put(rt);
9069 + return;
9070 + }
9071 +
9072 + nskb->priority = 0;
9073 + nskb->dst = &rt->u.dst;
9074 + skb_reserve(nskb, hh_len);
9075 +
9076 + /* Set up IP header */
9077 + iph = nskb->nh.iph
9078 + = (struct iphdr *)skb_put(nskb, sizeof(struct iphdr));
9079 + iph->version=4;
9080 + iph->ihl=5;
9081 + iph->tos=tos;
9082 + iph->tot_len = htons(length);
9083 +
9084 + /* PMTU discovery never applies to ICMP packets. */
9085 + iph->frag_off = 0;
9086 +
9087 + iph->ttl = MAXTTL;
9088 + ip_select_ident(iph, &rt->u.dst, NULL);
9089 + iph->protocol=IPPROTO_ICMP;
9090 + iph->saddr=rt->rt_src;
9091 + iph->daddr=rt->rt_dst;
9092 + iph->check=0;
9093 + iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
9094 +
9095 + /* Set up ICMP header. */
9096 + icmph = nskb->h.icmph
9097 + = (struct icmphdr *)skb_put(nskb, sizeof(struct icmphdr));
9098 + icmph->type = ICMP_DEST_UNREACH;
9099 + icmph->code = code;
9100 + icmph->un.gateway = 0;
9101 + icmph->checksum = 0;
9102 +
9103 + /* Copy as much of original packet as will fit */
9104 + data = skb_put(nskb,
9105 + length - sizeof(struct iphdr) - sizeof(struct icmphdr));
9106 + /* FIXME: won't work with nonlinear skbs --RR */
9107 + memcpy(data, skb_in->nh.iph,
9108 + length - sizeof(struct iphdr) - sizeof(struct icmphdr));
9109 + icmph->checksum = ip_compute_csum((unsigned char *)icmph,
9110 + length - sizeof(struct iphdr));
9111 +
9112 + nf_ct_attach(nskb, skb_in);
9113 +
9114 + NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, nskb, NULL, nskb->dst->dev,
9115 + ip_finish_output);
9116 +}
9117 +
9118 +static unsigned int reject(struct sk_buff **pskb,
9119 + unsigned int hooknum,
9120 + const struct net_device *in,
9121 + const struct net_device *out,
9122 + const void *targinfo,
9123 + void *userinfo)
9124 +{
9125 + const struct ipt_reject_info *reject = targinfo;
9126 +
9127 + /* Our naive response construction doesn't deal with IP
9128 + options, and probably shouldn't try. */
9129 + if ((*pskb)->nh.iph->ihl<<2 != sizeof(struct iphdr))
9130 + return NF_DROP;
9131 +
9132 + /* WARNING: This code causes reentry within iptables.
9133 + This means that the iptables jump stack is now crap. We
9134 + must return an absolute verdict. --RR */
9135 + switch (reject->with) {
9136 + case IPT_ICMP_NET_UNREACHABLE:
9137 + send_unreach(*pskb, ICMP_NET_UNREACH);
9138 + break;
9139 + case IPT_ICMP_HOST_UNREACHABLE:
9140 + send_unreach(*pskb, ICMP_HOST_UNREACH);
9141 + break;
9142 + case IPT_ICMP_PROT_UNREACHABLE:
9143 + send_unreach(*pskb, ICMP_PROT_UNREACH);
9144 + break;
9145 + case IPT_ICMP_PORT_UNREACHABLE:
9146 + send_unreach(*pskb, ICMP_PORT_UNREACH);
9147 + break;
9148 + case IPT_ICMP_NET_PROHIBITED:
9149 + send_unreach(*pskb, ICMP_NET_ANO);
9150 + break;
9151 + case IPT_ICMP_HOST_PROHIBITED:
9152 + send_unreach(*pskb, ICMP_HOST_ANO);
9153 + break;
9154 + case IPT_ICMP_ADMIN_PROHIBITED:
9155 + send_unreach(*pskb, ICMP_PKT_FILTERED);
9156 + break;
9157 + case IPT_TCP_RESET:
9158 + send_reset(*pskb, hooknum);
9159 + case IPT_ICMP_ECHOREPLY:
9160 + /* Doesn't happen. */
9161 + break;
9162 + }
9163 +
9164 + return NF_DROP;
9165 +}
9166 +
9167 +static int check(const char *tablename,
9168 + const struct ipt_entry *e,
9169 + void *targinfo,
9170 + unsigned int targinfosize,
9171 + unsigned int hook_mask)
9172 +{
9173 + const struct ipt_reject_info *rejinfo = targinfo;
9174 +
9175 + if (targinfosize != IPT_ALIGN(sizeof(struct ipt_reject_info))) {
9176 + DEBUGP("REJECT: targinfosize %u != 0\n", targinfosize);
9177 + return 0;
9178 + }
9179 +
9180 + /* Only allow these for packet filtering. */
9181 + if (strcmp(tablename, "filter") != 0) {
9182 + DEBUGP("REJECT: bad table `%s'.\n", tablename);
9183 + return 0;
9184 + }
9185 + if ((hook_mask & ~((1 << NF_IP_LOCAL_IN)
9186 + | (1 << NF_IP_FORWARD)
9187 + | (1 << NF_IP_LOCAL_OUT))) != 0) {
9188 + DEBUGP("REJECT: bad hook mask %X\n", hook_mask);
9189 + return 0;
9190 + }
9191 +
9192 + if (rejinfo->with == IPT_ICMP_ECHOREPLY) {
9193 + printk("REJECT: ECHOREPLY no longer supported.\n");
9194 + return 0;
9195 + } else if (rejinfo->with == IPT_TCP_RESET) {
9196 + /* Must specify that it's a TCP packet */
9197 + if (e->ip.proto != IPPROTO_TCP
9198 + || (e->ip.invflags & IPT_INV_PROTO)) {
9199 + DEBUGP("REJECT: TCP_RESET illegal for non-tcp\n");
9200 + return 0;
9201 + }
9202 + }
9203 +
9204 + return 1;
9205 +}
9206 +
9207 +static struct ipt_target ipt_reject_reg
9208 += { { NULL, NULL }, "REJECT", reject, check, NULL, THIS_MODULE };
9209 +
9210 +static int __init init(void)
9211 +{
9212 + if (ipt_register_target(&ipt_reject_reg))
9213 + return -EINVAL;
9214 + return 0;
9215 +}
9216 +
9217 +static void __exit fini(void)
9218 +{
9219 + ipt_unregister_target(&ipt_reject_reg);
9220 +}
9221 +
9222 +module_init(init);
9223 +module_exit(fini);
9224 +MODULE_LICENSE("GPL");
9225 diff -Nur linux-mips-cvs/net/ipv4/netfilter/ipt_physdev.c linux-ebtables/net/ipv4/netfilter/ipt_physdev.c
9226 --- linux-mips-cvs/net/ipv4/netfilter/ipt_physdev.c 1970-01-01 01:00:00.000000000 +0100
9227 +++ linux-ebtables/net/ipv4/netfilter/ipt_physdev.c 2005-02-07 05:52:50.000000000 +0100
9228 @@ -0,0 +1,127 @@
9229 +/* Kernel module to match the bridge port in and
9230 + * out device for IP packets coming into contact with a bridge. */
9231 +#include <linux/module.h>
9232 +#include <linux/skbuff.h>
9233 +#include <linux/netfilter_ipv4/ipt_physdev.h>
9234 +#include <linux/netfilter_ipv4/ip_tables.h>
9235 +#include <linux/netfilter_bridge.h>
9236 +#include <linux/netdevice.h>
9237 +#define MATCH 1
9238 +#define NOMATCH 0
9239 +
9240 +static int
9241 +match(const struct sk_buff *skb,
9242 + const struct net_device *in,
9243 + const struct net_device *out,
9244 + const void *matchinfo,
9245 + int offset,
9246 + const void *hdr,
9247 + u_int16_t datalen,
9248 + int *hotdrop)
9249 +{
9250 + int i;
9251 + static const char nulldevname[IFNAMSIZ] = { 0 };
9252 + const struct ipt_physdev_info *info = matchinfo;
9253 + unsigned long ret;
9254 + const char *indev, *outdev;
9255 + struct nf_bridge_info *nf_bridge;
9256 +
9257 + /* Not a bridged IP packet or no info available yet:
9258 + * LOCAL_OUT/mangle and LOCAL_OUT/nat don't know if
9259 + * the destination device will be a bridge. */
9260 + if (!(nf_bridge = skb->nf_bridge)) {
9261 + /* Return MATCH if the invert flags of the used options are on */
9262 + if ((info->bitmask & IPT_PHYSDEV_OP_BRIDGED) &&
9263 + !(info->invert & IPT_PHYSDEV_OP_BRIDGED))
9264 + return NOMATCH;
9265 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN) &&
9266 + !(info->invert & IPT_PHYSDEV_OP_ISIN))
9267 + return NOMATCH;
9268 + if ((info->bitmask & IPT_PHYSDEV_OP_ISOUT) &&
9269 + !(info->invert & IPT_PHYSDEV_OP_ISOUT))
9270 + return NOMATCH;
9271 + if ((info->bitmask & IPT_PHYSDEV_OP_IN) &&
9272 + !(info->invert & IPT_PHYSDEV_OP_IN))
9273 + return NOMATCH;
9274 + if ((info->bitmask & IPT_PHYSDEV_OP_OUT) &&
9275 + !(info->invert & IPT_PHYSDEV_OP_OUT))
9276 + return NOMATCH;
9277 + return MATCH;
9278 + }
9279 +
9280 + /* This only makes sense in the FORWARD and POSTROUTING chains */
9281 + if ((info->bitmask & IPT_PHYSDEV_OP_BRIDGED) &&
9282 + (!!(nf_bridge->mask & BRNF_BRIDGED) ^
9283 + !(info->invert & IPT_PHYSDEV_OP_BRIDGED)))
9284 + return NOMATCH;
9285 +
9286 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN &&
9287 + (!nf_bridge->physindev ^ !!(info->invert & IPT_PHYSDEV_OP_ISIN))) ||
9288 + (info->bitmask & IPT_PHYSDEV_OP_ISOUT &&
9289 + (!nf_bridge->physoutdev ^ !!(info->invert & IPT_PHYSDEV_OP_ISOUT))))
9290 + return NOMATCH;
9291 +
9292 + if (!(info->bitmask & IPT_PHYSDEV_OP_IN))
9293 + goto match_outdev;
9294 + indev = nf_bridge->physindev ? nf_bridge->physindev->name : nulldevname;
9295 + for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
9296 + ret |= (((const unsigned long *)indev)[i]
9297 + ^ ((const unsigned long *)info->physindev)[i])
9298 + & ((const unsigned long *)info->in_mask)[i];
9299 + }
9300 +
9301 + if ((ret == 0) ^ !(info->invert & IPT_PHYSDEV_OP_IN))
9302 + return NOMATCH;
9303 +
9304 +match_outdev:
9305 + if (!(info->bitmask & IPT_PHYSDEV_OP_OUT))
9306 + return MATCH;
9307 + outdev = nf_bridge->physoutdev ?
9308 + nf_bridge->physoutdev->name : nulldevname;
9309 + for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
9310 + ret |= (((const unsigned long *)outdev)[i]
9311 + ^ ((const unsigned long *)info->physoutdev)[i])
9312 + & ((const unsigned long *)info->out_mask)[i];
9313 + }
9314 +
9315 + return (ret != 0) ^ !(info->invert & IPT_PHYSDEV_OP_OUT);
9316 +}
9317 +
9318 +static int
9319 +checkentry(const char *tablename,
9320 + const struct ipt_ip *ip,
9321 + void *matchinfo,
9322 + unsigned int matchsize,
9323 + unsigned int hook_mask)
9324 +{
9325 + const struct ipt_physdev_info *info = matchinfo;
9326 +
9327 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_physdev_info)))
9328 + return 0;
9329 + if (!(info->bitmask & IPT_PHYSDEV_OP_MASK) ||
9330 + info->bitmask & ~IPT_PHYSDEV_OP_MASK)
9331 + return 0;
9332 + return 1;
9333 +}
9334 +
9335 +static struct ipt_match physdev_match = {
9336 + .name = "physdev",
9337 + .match = &match,
9338 + .checkentry = &checkentry,
9339 + .me = THIS_MODULE,
9340 +};
9341 +
9342 +static int __init init(void)
9343 +{
9344 + return ipt_register_match(&physdev_match);
9345 +}
9346 +
9347 +static void __exit fini(void)
9348 +{
9349 + ipt_unregister_match(&physdev_match);
9350 +}
9351 +
9352 +module_init(init);
9353 +module_exit(fini);
9354 +MODULE_LICENSE("GPL");
9355 +EXPORT_NO_SYMBOLS;