fix typos in CONFIG_SITE files
[openwrt/svn-archive/openwrt.git] / openwrt / target / linux / linux-2.4 / patches / generic / 114-ebtables-brnf-10.patch
1 diff -Nur linux.old/include/linux/if_bridge.h linux.dev/include/linux/if_bridge.h
2 --- linux.old/include/linux/if_bridge.h 2001-11-22 20:47:12.000000000 +0100
3 +++ linux.dev/include/linux/if_bridge.h 2005-10-10 10:36:45.953860750 +0200
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.old/include/linux/netfilter.h linux.dev/include/linux/netfilter.h
15 --- linux.old/include/linux/netfilter.h 2005-01-19 15:10:12.000000000 +0100
16 +++ linux.dev/include/linux/netfilter.h 2005-10-10 10:36:46.145872750 +0200
17 @@ -17,7 +17,8 @@
18 #define NF_STOLEN 2
19 #define NF_QUEUE 3
20 #define NF_REPEAT 4
21 -#define NF_MAX_VERDICT NF_REPEAT
22 +#define NF_STOP 5
23 +#define NF_MAX_VERDICT NF_STOP
24
25 /* Generic cache responses from hook functions.
26 <= 0x2000 is used for protocol-flags. */
27 @@ -118,17 +119,34 @@
28 /* This is gross, but inline doesn't cut it for avoiding the function
29 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
30 #ifdef CONFIG_NETFILTER_DEBUG
31 -#define NF_HOOK nf_hook_slow
32 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
33 +({int __ret; \
34 +if ((__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, INT_MIN)) == 1) \
35 + __ret = (okfn)(skb); \
36 +__ret;})
37 +#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
38 +({int __ret; \
39 +if ((__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1) \
40 + __ret = (okfn)(skb); \
41 +__ret;})
42 #else
43 -#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
44 -(list_empty(&nf_hooks[(pf)][(hook)]) \
45 - ? (okfn)(skb) \
46 - : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn)))
47 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
48 +({int __ret; \
49 +if (list_empty(&nf_hooks[pf][hook]) || \
50 + (__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, INT_MIN)) == 1) \
51 + __ret = (okfn)(skb); \
52 +__ret;})
53 +#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
54 +({int __ret; \
55 +if (list_empty(&nf_hooks[pf][hook]) || \
56 + (__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1) \
57 + __ret = (okfn)(skb); \
58 +__ret;})
59 #endif
60
61 -int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
62 +int nf_hook_slow(int pf, unsigned int hook, struct sk_buff **pskb,
63 struct net_device *indev, struct net_device *outdev,
64 - int (*okfn)(struct sk_buff *));
65 + int (*okfn)(struct sk_buff *), int thresh);
66
67 /* Call setsockopt() */
68 int nf_setsockopt(struct sock *sk, int pf, int optval, char *opt,
69 diff -Nur linux.old/include/linux/netfilter_arp/arp_tables.h linux.dev/include/linux/netfilter_arp/arp_tables.h
70 --- linux.old/include/linux/netfilter_arp/arp_tables.h 2003-08-25 13:44:44.000000000 +0200
71 +++ linux.dev/include/linux/netfilter_arp/arp_tables.h 2005-10-10 10:36:46.065867750 +0200
72 @@ -154,7 +154,7 @@
73 #define ARPT_CONTINUE 0xFFFFFFFF
74
75 /* For standard target */
76 -#define ARPT_RETURN (-NF_MAX_VERDICT - 1)
77 +#define ARPT_RETURN (-NF_REPEAT - 1)
78
79 /* The argument to ARPT_SO_GET_INFO */
80 struct arpt_getinfo
81 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_802_3.h linux.dev/include/linux/netfilter_bridge/ebt_802_3.h
82 --- linux.old/include/linux/netfilter_bridge/ebt_802_3.h 1970-01-01 01:00:00.000000000 +0100
83 +++ linux.dev/include/linux/netfilter_bridge/ebt_802_3.h 2005-10-10 10:36:46.125871500 +0200
84 @@ -0,0 +1,60 @@
85 +#ifndef __LINUX_BRIDGE_EBT_802_3_H
86 +#define __LINUX_BRIDGE_EBT_802_3_H
87 +
88 +#define EBT_802_3_SAP 0x01
89 +#define EBT_802_3_TYPE 0x02
90 +
91 +#define EBT_802_3_MATCH "802_3"
92 +
93 +/*
94 + * If frame has DSAP/SSAP value 0xaa you must check the SNAP type
95 + * to discover what kind of packet we're carrying.
96 + */
97 +#define CHECK_TYPE 0xaa
98 +
99 +/*
100 + * Control field may be one or two bytes. If the first byte has
101 + * the value 0x03 then the entire length is one byte, otherwise it is two.
102 + * One byte controls are used in Unnumbered Information frames.
103 + * Two byte controls are used in Numbered Information frames.
104 + */
105 +#define IS_UI 0x03
106 +
107 +#define EBT_802_3_MASK (EBT_802_3_SAP | EBT_802_3_TYPE | EBT_802_3)
108 +
109 +/* ui has one byte ctrl, ni has two */
110 +struct hdr_ui {
111 + uint8_t dsap;
112 + uint8_t ssap;
113 + uint8_t ctrl;
114 + uint8_t orig[3];
115 + uint16_t type;
116 +};
117 +
118 +struct hdr_ni {
119 + uint8_t dsap;
120 + uint8_t ssap;
121 + uint16_t ctrl;
122 + uint8_t orig[3];
123 + uint16_t type;
124 +};
125 +
126 +struct ebt_802_3_hdr {
127 + uint8_t daddr[6];
128 + uint8_t saddr[6];
129 + uint16_t len;
130 + union {
131 + struct hdr_ui ui;
132 + struct hdr_ni ni;
133 + } llc;
134 +};
135 +
136 +struct ebt_802_3_info
137 +{
138 + uint8_t sap;
139 + uint16_t type;
140 + uint8_t bitmask;
141 + uint8_t invflags;
142 +};
143 +
144 +#endif
145 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_among.h linux.dev/include/linux/netfilter_bridge/ebt_among.h
146 --- linux.old/include/linux/netfilter_bridge/ebt_among.h 1970-01-01 01:00:00.000000000 +0100
147 +++ linux.dev/include/linux/netfilter_bridge/ebt_among.h 2005-10-10 10:36:46.125871500 +0200
148 @@ -0,0 +1,65 @@
149 +#ifndef __LINUX_BRIDGE_EBT_AMONG_H
150 +#define __LINUX_BRIDGE_EBT_AMONG_H
151 +
152 +#define EBT_AMONG_DST 0x01
153 +#define EBT_AMONG_SRC 0x02
154 +
155 +/* Grzegorz Borowiak <grzes@gnu.univ.gda.pl> 2003
156 + *
157 + * Write-once-read-many hash table, used for checking if a given
158 + * MAC address belongs to a set or not and possibly for checking
159 + * if it is related with a given IPv4 address.
160 + *
161 + * The hash value of an address is its last byte.
162 + *
163 + * In real-world ethernet addresses, values of the last byte are
164 + * evenly distributed and there is no need to consider other bytes.
165 + * It would only slow the routines down.
166 + *
167 + * For MAC address comparison speedup reasons, we introduce a trick.
168 + * MAC address is mapped onto an array of two 32-bit integers.
169 + * This pair of integers is compared with MAC addresses in the
170 + * hash table, which are stored also in form of pairs of integers
171 + * (in `cmp' array). This is quick as it requires only two elementary
172 + * number comparisons in worst case. Further, we take advantage of
173 + * fact that entropy of 3 last bytes of address is larger than entropy
174 + * of 3 first bytes. So first we compare 4 last bytes of addresses and
175 + * if they are the same we compare 2 first.
176 + *
177 + * Yes, it is a memory overhead, but in 2003 AD, who cares?
178 + */
179 +
180 +struct ebt_mac_wormhash_tuple
181 +{
182 + uint32_t cmp[2];
183 + uint32_t ip;
184 +};
185 +
186 +struct ebt_mac_wormhash
187 +{
188 + int table[257];
189 + int poolsize;
190 + struct ebt_mac_wormhash_tuple pool[0];
191 +};
192 +
193 +#define ebt_mac_wormhash_size(x) ((x) ? sizeof(struct ebt_mac_wormhash) \
194 + + (x)->poolsize * sizeof(struct ebt_mac_wormhash_tuple) : 0)
195 +
196 +struct ebt_among_info
197 +{
198 + int wh_dst_ofs;
199 + int wh_src_ofs;
200 + int bitmask;
201 +};
202 +
203 +#define EBT_AMONG_DST_NEG 0x1
204 +#define EBT_AMONG_SRC_NEG 0x2
205 +
206 +#define ebt_among_wh_dst(x) ((x)->wh_dst_ofs ? \
207 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_dst_ofs) : NULL)
208 +#define ebt_among_wh_src(x) ((x)->wh_src_ofs ? \
209 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_src_ofs) : NULL)
210 +
211 +#define EBT_AMONG_MATCH "among"
212 +
213 +#endif
214 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_arp.h linux.dev/include/linux/netfilter_bridge/ebt_arp.h
215 --- linux.old/include/linux/netfilter_bridge/ebt_arp.h 1970-01-01 01:00:00.000000000 +0100
216 +++ linux.dev/include/linux/netfilter_bridge/ebt_arp.h 2005-10-10 10:36:46.125871500 +0200
217 @@ -0,0 +1,32 @@
218 +#ifndef __LINUX_BRIDGE_EBT_ARP_H
219 +#define __LINUX_BRIDGE_EBT_ARP_H
220 +
221 +#define EBT_ARP_OPCODE 0x01
222 +#define EBT_ARP_HTYPE 0x02
223 +#define EBT_ARP_PTYPE 0x04
224 +#define EBT_ARP_SRC_IP 0x08
225 +#define EBT_ARP_DST_IP 0x10
226 +#define EBT_ARP_SRC_MAC 0x20
227 +#define EBT_ARP_DST_MAC 0x40
228 +#define EBT_ARP_MASK (EBT_ARP_OPCODE | EBT_ARP_HTYPE | EBT_ARP_PTYPE | \
229 + EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)
230 +#define EBT_ARP_MATCH "arp"
231 +
232 +struct ebt_arp_info
233 +{
234 + uint16_t htype;
235 + uint16_t ptype;
236 + uint16_t opcode;
237 + uint32_t saddr;
238 + uint32_t smsk;
239 + uint32_t daddr;
240 + uint32_t dmsk;
241 + unsigned char smaddr[ETH_ALEN];
242 + unsigned char smmsk[ETH_ALEN];
243 + unsigned char dmaddr[ETH_ALEN];
244 + unsigned char dmmsk[ETH_ALEN];
245 + uint8_t bitmask;
246 + uint8_t invflags;
247 +};
248 +
249 +#endif
250 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_arpreply.h linux.dev/include/linux/netfilter_bridge/ebt_arpreply.h
251 --- linux.old/include/linux/netfilter_bridge/ebt_arpreply.h 1970-01-01 01:00:00.000000000 +0100
252 +++ linux.dev/include/linux/netfilter_bridge/ebt_arpreply.h 2005-10-10 10:36:46.125871500 +0200
253 @@ -0,0 +1,11 @@
254 +#ifndef __LINUX_BRIDGE_EBT_ARPREPLY_H
255 +#define __LINUX_BRIDGE_EBT_ARPREPLY_H
256 +
257 +struct ebt_arpreply_info
258 +{
259 + unsigned char mac[ETH_ALEN];
260 + int target;
261 +};
262 +#define EBT_ARPREPLY_TARGET "arpreply"
263 +
264 +#endif
265 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_ip.h linux.dev/include/linux/netfilter_bridge/ebt_ip.h
266 --- linux.old/include/linux/netfilter_bridge/ebt_ip.h 1970-01-01 01:00:00.000000000 +0100
267 +++ linux.dev/include/linux/netfilter_bridge/ebt_ip.h 2005-10-10 10:36:46.125871500 +0200
268 @@ -0,0 +1,43 @@
269 +/*
270 + * ebt_ip
271 + *
272 + * Authors:
273 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
274 + *
275 + * April, 2002
276 + *
277 + * Changes:
278 + * added ip-sport and ip-dport
279 + * Innominate Security Technologies AG <mhopf@innominate.com>
280 + * September, 2002
281 + */
282 +
283 +#ifndef __LINUX_BRIDGE_EBT_IP_H
284 +#define __LINUX_BRIDGE_EBT_IP_H
285 +
286 +#define EBT_IP_SOURCE 0x01
287 +#define EBT_IP_DEST 0x02
288 +#define EBT_IP_TOS 0x04
289 +#define EBT_IP_PROTO 0x08
290 +#define EBT_IP_SPORT 0x10
291 +#define EBT_IP_DPORT 0x20
292 +#define EBT_IP_MASK (EBT_IP_SOURCE | EBT_IP_DEST | EBT_IP_TOS | EBT_IP_PROTO |\
293 + EBT_IP_SPORT | EBT_IP_DPORT )
294 +#define EBT_IP_MATCH "ip"
295 +
296 +// the same values are used for the invflags
297 +struct ebt_ip_info
298 +{
299 + uint32_t saddr;
300 + uint32_t daddr;
301 + uint32_t smsk;
302 + uint32_t dmsk;
303 + uint8_t tos;
304 + uint8_t protocol;
305 + uint8_t bitmask;
306 + uint8_t invflags;
307 + uint16_t sport[2];
308 + uint16_t dport[2];
309 +};
310 +
311 +#endif
312 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_limit.h linux.dev/include/linux/netfilter_bridge/ebt_limit.h
313 --- linux.old/include/linux/netfilter_bridge/ebt_limit.h 1970-01-01 01:00:00.000000000 +0100
314 +++ linux.dev/include/linux/netfilter_bridge/ebt_limit.h 2005-10-10 10:36:46.125871500 +0200
315 @@ -0,0 +1,23 @@
316 +#ifndef __LINUX_BRIDGE_EBT_LIMIT_H
317 +#define __LINUX_BRIDGE_EBT_LIMIT_H
318 +
319 +#define EBT_LIMIT_MATCH "limit"
320 +
321 +/* timings are in milliseconds. */
322 +#define EBT_LIMIT_SCALE 10000
323 +
324 +/* 1/10,000 sec period => max of 10,000/sec. Min rate is then 429490
325 + seconds, or one every 59 hours. */
326 +
327 +struct ebt_limit_info
328 +{
329 + u_int32_t avg; /* Average secs between packets * scale */
330 + u_int32_t burst; /* Period multiplier for upper limit. */
331 +
332 + /* Used internally by the kernel */
333 + unsigned long prev;
334 + u_int32_t credit;
335 + u_int32_t credit_cap, cost;
336 +};
337 +
338 +#endif
339 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_log.h linux.dev/include/linux/netfilter_bridge/ebt_log.h
340 --- linux.old/include/linux/netfilter_bridge/ebt_log.h 1970-01-01 01:00:00.000000000 +0100
341 +++ linux.dev/include/linux/netfilter_bridge/ebt_log.h 2005-10-10 10:36:46.125871500 +0200
342 @@ -0,0 +1,17 @@
343 +#ifndef __LINUX_BRIDGE_EBT_LOG_H
344 +#define __LINUX_BRIDGE_EBT_LOG_H
345 +
346 +#define EBT_LOG_IP 0x01 // if the frame is made by ip, log the ip information
347 +#define EBT_LOG_ARP 0x02
348 +#define EBT_LOG_MASK (EBT_LOG_IP | EBT_LOG_ARP)
349 +#define EBT_LOG_PREFIX_SIZE 30
350 +#define EBT_LOG_WATCHER "log"
351 +
352 +struct ebt_log_info
353 +{
354 + uint8_t loglevel;
355 + uint8_t prefix[EBT_LOG_PREFIX_SIZE];
356 + uint32_t bitmask;
357 +};
358 +
359 +#endif
360 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_mark_m.h linux.dev/include/linux/netfilter_bridge/ebt_mark_m.h
361 --- linux.old/include/linux/netfilter_bridge/ebt_mark_m.h 1970-01-01 01:00:00.000000000 +0100
362 +++ linux.dev/include/linux/netfilter_bridge/ebt_mark_m.h 2005-10-10 10:36:46.129871750 +0200
363 @@ -0,0 +1,15 @@
364 +#ifndef __LINUX_BRIDGE_EBT_MARK_M_H
365 +#define __LINUX_BRIDGE_EBT_MARK_M_H
366 +
367 +#define EBT_MARK_AND 0x01
368 +#define EBT_MARK_OR 0x02
369 +#define EBT_MARK_MASK (EBT_MARK_AND | EBT_MARK_OR)
370 +struct ebt_mark_m_info
371 +{
372 + unsigned long mark, mask;
373 + uint8_t invert;
374 + uint8_t bitmask;
375 +};
376 +#define EBT_MARK_MATCH "mark_m"
377 +
378 +#endif
379 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_mark_t.h linux.dev/include/linux/netfilter_bridge/ebt_mark_t.h
380 --- linux.old/include/linux/netfilter_bridge/ebt_mark_t.h 1970-01-01 01:00:00.000000000 +0100
381 +++ linux.dev/include/linux/netfilter_bridge/ebt_mark_t.h 2005-10-10 10:36:46.129871750 +0200
382 @@ -0,0 +1,12 @@
383 +#ifndef __LINUX_BRIDGE_EBT_MARK_T_H
384 +#define __LINUX_BRIDGE_EBT_MARK_T_H
385 +
386 +struct ebt_mark_t_info
387 +{
388 + unsigned long mark;
389 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
390 + int target;
391 +};
392 +#define EBT_MARK_TARGET "mark"
393 +
394 +#endif
395 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_nat.h linux.dev/include/linux/netfilter_bridge/ebt_nat.h
396 --- linux.old/include/linux/netfilter_bridge/ebt_nat.h 1970-01-01 01:00:00.000000000 +0100
397 +++ linux.dev/include/linux/netfilter_bridge/ebt_nat.h 2005-10-10 10:36:46.129871750 +0200
398 @@ -0,0 +1,13 @@
399 +#ifndef __LINUX_BRIDGE_EBT_NAT_H
400 +#define __LINUX_BRIDGE_EBT_NAT_H
401 +
402 +struct ebt_nat_info
403 +{
404 + unsigned char mac[ETH_ALEN];
405 + // EBT_ACCEPT, EBT_DROP, EBT_CONTINUE or EBT_RETURN
406 + int target;
407 +};
408 +#define EBT_SNAT_TARGET "snat"
409 +#define EBT_DNAT_TARGET "dnat"
410 +
411 +#endif
412 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_pkttype.h linux.dev/include/linux/netfilter_bridge/ebt_pkttype.h
413 --- linux.old/include/linux/netfilter_bridge/ebt_pkttype.h 1970-01-01 01:00:00.000000000 +0100
414 +++ linux.dev/include/linux/netfilter_bridge/ebt_pkttype.h 2005-10-10 10:36:46.125871500 +0200
415 @@ -0,0 +1,11 @@
416 +#ifndef __LINUX_BRIDGE_EBT_PKTTYPE_H
417 +#define __LINUX_BRIDGE_EBT_PKTTYPE_H
418 +
419 +struct ebt_pkttype_info
420 +{
421 + uint8_t pkt_type;
422 + uint8_t invert;
423 +};
424 +#define EBT_PKTTYPE_MATCH "pkttype"
425 +
426 +#endif
427 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_redirect.h linux.dev/include/linux/netfilter_bridge/ebt_redirect.h
428 --- linux.old/include/linux/netfilter_bridge/ebt_redirect.h 1970-01-01 01:00:00.000000000 +0100
429 +++ linux.dev/include/linux/netfilter_bridge/ebt_redirect.h 2005-10-10 10:36:46.129871750 +0200
430 @@ -0,0 +1,11 @@
431 +#ifndef __LINUX_BRIDGE_EBT_REDIRECT_H
432 +#define __LINUX_BRIDGE_EBT_REDIRECT_H
433 +
434 +struct ebt_redirect_info
435 +{
436 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
437 + int target;
438 +};
439 +#define EBT_REDIRECT_TARGET "redirect"
440 +
441 +#endif
442 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_stp.h linux.dev/include/linux/netfilter_bridge/ebt_stp.h
443 --- linux.old/include/linux/netfilter_bridge/ebt_stp.h 1970-01-01 01:00:00.000000000 +0100
444 +++ linux.dev/include/linux/netfilter_bridge/ebt_stp.h 2005-10-10 10:36:46.125871500 +0200
445 @@ -0,0 +1,46 @@
446 +#ifndef __LINUX_BRIDGE_EBT_STP_H
447 +#define __LINUX_BRIDGE_EBT_STP_H
448 +
449 +#define EBT_STP_TYPE 0x0001
450 +
451 +#define EBT_STP_FLAGS 0x0002
452 +#define EBT_STP_ROOTPRIO 0x0004
453 +#define EBT_STP_ROOTADDR 0x0008
454 +#define EBT_STP_ROOTCOST 0x0010
455 +#define EBT_STP_SENDERPRIO 0x0020
456 +#define EBT_STP_SENDERADDR 0x0040
457 +#define EBT_STP_PORT 0x0080
458 +#define EBT_STP_MSGAGE 0x0100
459 +#define EBT_STP_MAXAGE 0x0200
460 +#define EBT_STP_HELLOTIME 0x0400
461 +#define EBT_STP_FWDD 0x0800
462 +
463 +#define EBT_STP_MASK 0x0fff
464 +#define EBT_STP_CONFIG_MASK 0x0ffe
465 +
466 +#define EBT_STP_MATCH "stp"
467 +
468 +struct ebt_stp_config_info
469 +{
470 + uint8_t flags;
471 + uint16_t root_priol, root_priou;
472 + char root_addr[6], root_addrmsk[6];
473 + uint32_t root_costl, root_costu;
474 + uint16_t sender_priol, sender_priou;
475 + char sender_addr[6], sender_addrmsk[6];
476 + uint16_t portl, portu;
477 + uint16_t msg_agel, msg_ageu;
478 + uint16_t max_agel, max_ageu;
479 + uint16_t hello_timel, hello_timeu;
480 + uint16_t forward_delayl, forward_delayu;
481 +};
482 +
483 +struct ebt_stp_info
484 +{
485 + uint8_t type;
486 + struct ebt_stp_config_info config;
487 + uint16_t bitmask;
488 + uint16_t invflags;
489 +};
490 +
491 +#endif
492 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_ulog.h linux.dev/include/linux/netfilter_bridge/ebt_ulog.h
493 --- linux.old/include/linux/netfilter_bridge/ebt_ulog.h 1970-01-01 01:00:00.000000000 +0100
494 +++ linux.dev/include/linux/netfilter_bridge/ebt_ulog.h 2005-10-10 10:36:46.129871750 +0200
495 @@ -0,0 +1,33 @@
496 +#ifndef _EBT_ULOG_H
497 +#define _EBT_ULOG_H
498 +
499 +#define EBT_ULOG_DEFAULT_NLGROUP 0
500 +#define EBT_ULOG_DEFAULT_QTHRESHOLD 1
501 +#define EBT_ULOG_MAXNLGROUPS 32 /* hardcoded netlink max */
502 +#define EBT_ULOG_PREFIX_LEN 32
503 +#define EBT_ULOG_MAX_QLEN 50
504 +#define EBT_ULOG_WATCHER "ulog"
505 +
506 +struct ebt_ulog_info {
507 + uint32_t nlgroup;
508 + unsigned int cprange;
509 + unsigned int qthreshold;
510 + char prefix[EBT_ULOG_PREFIX_LEN];
511 +};
512 +
513 +typedef struct ebt_ulog_packet_msg {
514 + char indev[IFNAMSIZ];
515 + char outdev[IFNAMSIZ];
516 + char physindev[IFNAMSIZ];
517 + char physoutdev[IFNAMSIZ];
518 + char prefix[EBT_ULOG_PREFIX_LEN];
519 + struct timeval stamp;
520 + unsigned long mark;
521 + unsigned int hook;
522 + size_t data_len;
523 + /* The complete packet, including Ethernet header and perhaps
524 + * the VLAN header is appended */
525 + unsigned char data[0] __attribute__ ((aligned (__alignof__(int))));
526 +} ebt_ulog_packet_msg_t;
527 +
528 +#endif /* _EBT_ULOG_H */
529 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_vlan.h linux.dev/include/linux/netfilter_bridge/ebt_vlan.h
530 --- linux.old/include/linux/netfilter_bridge/ebt_vlan.h 1970-01-01 01:00:00.000000000 +0100
531 +++ linux.dev/include/linux/netfilter_bridge/ebt_vlan.h 2005-10-10 10:36:46.125871500 +0200
532 @@ -0,0 +1,20 @@
533 +#ifndef __LINUX_BRIDGE_EBT_VLAN_H
534 +#define __LINUX_BRIDGE_EBT_VLAN_H
535 +
536 +#define EBT_VLAN_ID 0x01
537 +#define EBT_VLAN_PRIO 0x02
538 +#define EBT_VLAN_ENCAP 0x04
539 +#define EBT_VLAN_MASK (EBT_VLAN_ID | EBT_VLAN_PRIO | EBT_VLAN_ENCAP)
540 +#define EBT_VLAN_MATCH "vlan"
541 +
542 +struct ebt_vlan_info {
543 + uint16_t id; /* VLAN ID {1-4095} */
544 + uint8_t prio; /* VLAN User Priority {0-7} */
545 + uint16_t encap; /* VLAN Encapsulated frame code {0-65535} */
546 + uint8_t bitmask; /* Args bitmask bit 1=1 - ID arg,
547 + bit 2=1 User-Priority arg, bit 3=1 encap*/
548 + uint8_t invflags; /* Inverse bitmask bit 1=1 - inversed ID arg,
549 + bit 2=1 - inversed Pirority arg */
550 +};
551 +
552 +#endif
553 diff -Nur linux.old/include/linux/netfilter_bridge/ebtables.h linux.dev/include/linux/netfilter_bridge/ebtables.h
554 --- linux.old/include/linux/netfilter_bridge/ebtables.h 1970-01-01 01:00:00.000000000 +0100
555 +++ linux.dev/include/linux/netfilter_bridge/ebtables.h 2005-10-10 10:36:46.125871500 +0200
556 @@ -0,0 +1,361 @@
557 +/*
558 + * ebtables
559 + *
560 + * Authors:
561 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
562 + *
563 + * ebtables.c,v 2.0, September, 2002
564 + *
565 + * This code is stongly inspired on the iptables code which is
566 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
567 + */
568 +
569 +#ifndef __LINUX_BRIDGE_EFF_H
570 +#define __LINUX_BRIDGE_EFF_H
571 +#include <linux/if.h>
572 +#include <linux/netfilter_bridge.h>
573 +#include <linux/if_ether.h>
574 +
575 +#define EBT_TABLE_MAXNAMELEN 32
576 +#define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN
577 +#define EBT_FUNCTION_MAXNAMELEN EBT_TABLE_MAXNAMELEN
578 +
579 +// verdicts >0 are "branches"
580 +#define EBT_ACCEPT -1
581 +#define EBT_DROP -2
582 +#define EBT_CONTINUE -3
583 +#define EBT_RETURN -4
584 +#define NUM_STANDARD_TARGETS 4
585 +
586 +struct ebt_counter
587 +{
588 + uint64_t pcnt;
589 + uint64_t bcnt;
590 +};
591 +
592 +struct ebt_entries {
593 + // this field is always set to zero
594 + // See EBT_ENTRY_OR_ENTRIES.
595 + // Must be same size as ebt_entry.bitmask
596 + unsigned int distinguisher;
597 + // the chain name
598 + char name[EBT_CHAIN_MAXNAMELEN];
599 + // counter offset for this chain
600 + unsigned int counter_offset;
601 + // one standard (accept, drop, return) per hook
602 + int policy;
603 + // nr. of entries
604 + unsigned int nentries;
605 + // entry list
606 + char data[0];
607 +};
608 +
609 +// used for the bitmask of struct ebt_entry
610 +
611 +// This is a hack to make a difference between an ebt_entry struct and an
612 +// ebt_entries struct when traversing the entries from start to end.
613 +// Using this simplifies the code alot, while still being able to use
614 +// ebt_entries.
615 +// Contrary, iptables doesn't use something like ebt_entries and therefore uses
616 +// different techniques for naming the policy and such. So, iptables doesn't
617 +// need a hack like this.
618 +#define EBT_ENTRY_OR_ENTRIES 0x01
619 +// these are the normal masks
620 +#define EBT_NOPROTO 0x02
621 +#define EBT_802_3 0x04
622 +#define EBT_SOURCEMAC 0x08
623 +#define EBT_DESTMAC 0x10
624 +#define EBT_F_MASK (EBT_NOPROTO | EBT_802_3 | EBT_SOURCEMAC | EBT_DESTMAC \
625 + | EBT_ENTRY_OR_ENTRIES)
626 +
627 +#define EBT_IPROTO 0x01
628 +#define EBT_IIN 0x02
629 +#define EBT_IOUT 0x04
630 +#define EBT_ISOURCE 0x8
631 +#define EBT_IDEST 0x10
632 +#define EBT_ILOGICALIN 0x20
633 +#define EBT_ILOGICALOUT 0x40
634 +#define EBT_INV_MASK (EBT_IPROTO | EBT_IIN | EBT_IOUT | EBT_ILOGICALIN \
635 + | EBT_ILOGICALOUT | EBT_ISOURCE | EBT_IDEST)
636 +
637 +struct ebt_entry_match
638 +{
639 + union {
640 + char name[EBT_FUNCTION_MAXNAMELEN];
641 + struct ebt_match *match;
642 + } u;
643 + // size of data
644 + unsigned int match_size;
645 + unsigned char data[0];
646 +};
647 +
648 +struct ebt_entry_watcher
649 +{
650 + union {
651 + char name[EBT_FUNCTION_MAXNAMELEN];
652 + struct ebt_watcher *watcher;
653 + } u;
654 + // size of data
655 + unsigned int watcher_size;
656 + unsigned char data[0];
657 +};
658 +
659 +struct ebt_entry_target
660 +{
661 + union {
662 + char name[EBT_FUNCTION_MAXNAMELEN];
663 + struct ebt_target *target;
664 + } u;
665 + // size of data
666 + unsigned int target_size;
667 + unsigned char data[0];
668 +};
669 +
670 +#define EBT_STANDARD_TARGET "standard"
671 +struct ebt_standard_target
672 +{
673 + struct ebt_entry_target target;
674 + int verdict;
675 +};
676 +
677 +// one entry
678 +struct ebt_entry {
679 + // this needs to be the first field
680 + unsigned int bitmask;
681 + unsigned int invflags;
682 + uint16_t ethproto;
683 + // the physical in-dev
684 + char in[IFNAMSIZ];
685 + // the logical in-dev
686 + char logical_in[IFNAMSIZ];
687 + // the physical out-dev
688 + char out[IFNAMSIZ];
689 + // the logical out-dev
690 + char logical_out[IFNAMSIZ];
691 + unsigned char sourcemac[ETH_ALEN];
692 + unsigned char sourcemsk[ETH_ALEN];
693 + unsigned char destmac[ETH_ALEN];
694 + unsigned char destmsk[ETH_ALEN];
695 + // sizeof ebt_entry + matches
696 + unsigned int watchers_offset;
697 + // sizeof ebt_entry + matches + watchers
698 + unsigned int target_offset;
699 + // sizeof ebt_entry + matches + watchers + target
700 + unsigned int next_offset;
701 + unsigned char elems[0];
702 +};
703 +
704 +struct ebt_replace
705 +{
706 + char name[EBT_TABLE_MAXNAMELEN];
707 + unsigned int valid_hooks;
708 + // nr of rules in the table
709 + unsigned int nentries;
710 + // total size of the entries
711 + unsigned int entries_size;
712 + // start of the chains
713 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
714 + // nr of counters userspace expects back
715 + unsigned int num_counters;
716 + // where the kernel will put the old counters
717 + struct ebt_counter *counters;
718 + char *entries;
719 +};
720 +
721 +// [gs]etsockopt numbers
722 +#define EBT_BASE_CTL 128
723 +
724 +#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
725 +#define EBT_SO_SET_COUNTERS (EBT_SO_SET_ENTRIES+1)
726 +#define EBT_SO_SET_MAX (EBT_SO_SET_COUNTERS+1)
727 +
728 +#define EBT_SO_GET_INFO (EBT_BASE_CTL)
729 +#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO+1)
730 +#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES+1)
731 +#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO+1)
732 +#define EBT_SO_GET_MAX (EBT_SO_GET_INIT_ENTRIES+1)
733 +
734 +#ifdef __KERNEL__
735 +
736 +// return values for match() functions
737 +#define EBT_MATCH 0
738 +#define EBT_NOMATCH 1
739 +
740 +struct ebt_match
741 +{
742 + struct list_head list;
743 + const char name[EBT_FUNCTION_MAXNAMELEN];
744 + // 0 == it matches
745 + int (*match)(const struct sk_buff *skb, const struct net_device *in,
746 + const struct net_device *out, const void *matchdata,
747 + unsigned int datalen);
748 + // 0 == let it in
749 + int (*check)(const char *tablename, unsigned int hookmask,
750 + const struct ebt_entry *e, void *matchdata, unsigned int datalen);
751 + void (*destroy)(void *matchdata, unsigned int datalen);
752 + struct module *me;
753 +};
754 +
755 +struct ebt_watcher
756 +{
757 + struct list_head list;
758 + const char name[EBT_FUNCTION_MAXNAMELEN];
759 + void (*watcher)(const struct sk_buff *skb, unsigned int hooknr,
760 + const struct net_device *in, const struct net_device *out,
761 + const void *watcherdata, unsigned int datalen);
762 + // 0 == let it in
763 + int (*check)(const char *tablename, unsigned int hookmask,
764 + const struct ebt_entry *e, void *watcherdata, unsigned int datalen);
765 + void (*destroy)(void *watcherdata, unsigned int datalen);
766 + struct module *me;
767 +};
768 +
769 +struct ebt_target
770 +{
771 + struct list_head list;
772 + const char name[EBT_FUNCTION_MAXNAMELEN];
773 + // returns one of the standard verdicts
774 + int (*target)(struct sk_buff **pskb, unsigned int hooknr,
775 + const struct net_device *in, const struct net_device *out,
776 + const void *targetdata, unsigned int datalen);
777 + // 0 == let it in
778 + int (*check)(const char *tablename, unsigned int hookmask,
779 + const struct ebt_entry *e, void *targetdata, unsigned int datalen);
780 + void (*destroy)(void *targetdata, unsigned int datalen);
781 + struct module *me;
782 +};
783 +
784 +// used for jumping from and into user defined chains (udc)
785 +struct ebt_chainstack
786 +{
787 + struct ebt_entries *chaininfo; // pointer to chain data
788 + struct ebt_entry *e; // pointer to entry data
789 + unsigned int n; // n'th entry
790 +};
791 +
792 +struct ebt_table_info
793 +{
794 + // total size of the entries
795 + unsigned int entries_size;
796 + unsigned int nentries;
797 + // pointers to the start of the chains
798 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
799 + // room to maintain the stack used for jumping from and into udc
800 + struct ebt_chainstack **chainstack;
801 + char *entries;
802 + struct ebt_counter counters[0] ____cacheline_aligned;
803 +};
804 +
805 +struct ebt_table
806 +{
807 + struct list_head list;
808 + char name[EBT_TABLE_MAXNAMELEN];
809 + struct ebt_replace *table;
810 + unsigned int valid_hooks;
811 + rwlock_t lock;
812 + // e.g. could be the table explicitly only allows certain
813 + // matches, targets, ... 0 == let it in
814 + int (*check)(const struct ebt_table_info *info,
815 + unsigned int valid_hooks);
816 + // the data used by the kernel
817 + struct ebt_table_info *private;
818 +};
819 +
820 +#define EBT_ALIGN(s) (((s) + (__alignof__(struct ebt_entry_target)-1)) & \
821 + ~(__alignof__(struct ebt_entry_target)-1))
822 +extern int ebt_register_table(struct ebt_table *table);
823 +extern void ebt_unregister_table(struct ebt_table *table);
824 +extern int ebt_register_match(struct ebt_match *match);
825 +extern void ebt_unregister_match(struct ebt_match *match);
826 +extern int ebt_register_watcher(struct ebt_watcher *watcher);
827 +extern void ebt_unregister_watcher(struct ebt_watcher *watcher);
828 +extern int ebt_register_target(struct ebt_target *target);
829 +extern void ebt_unregister_target(struct ebt_target *target);
830 +extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff **pskb,
831 + const struct net_device *in, const struct net_device *out,
832 + struct ebt_table *table);
833 +
834 + // Used in the kernel match() functions
835 +#define FWINV(bool,invflg) ((bool) ^ !!(info->invflags & invflg))
836 +// True if the hook mask denotes that the rule is in a base chain,
837 +// used in the check() functions
838 +#define BASE_CHAIN (hookmask & (1 << NF_BR_NUMHOOKS))
839 +// Clear the bit in the hook mask that tells if the rule is on a base chain
840 +#define CLEAR_BASE_CHAIN_BIT (hookmask &= ~(1 << NF_BR_NUMHOOKS))
841 +// True if the target is not a standard target
842 +#define INVALID_TARGET (info->target < -NUM_STANDARD_TARGETS || info->target >= 0)
843 +
844 +#endif /* __KERNEL__ */
845 +
846 +// blatently stolen from ip_tables.h
847 +// fn returns 0 to continue iteration
848 +#define EBT_MATCH_ITERATE(e, fn, args...) \
849 +({ \
850 + unsigned int __i; \
851 + int __ret = 0; \
852 + struct ebt_entry_match *__match; \
853 + \
854 + for (__i = sizeof(struct ebt_entry); \
855 + __i < (e)->watchers_offset; \
856 + __i += __match->match_size + \
857 + sizeof(struct ebt_entry_match)) { \
858 + __match = (void *)(e) + __i; \
859 + \
860 + __ret = fn(__match , ## args); \
861 + if (__ret != 0) \
862 + break; \
863 + } \
864 + if (__ret == 0) { \
865 + if (__i != (e)->watchers_offset) \
866 + __ret = -EINVAL; \
867 + } \
868 + __ret; \
869 +})
870 +
871 +#define EBT_WATCHER_ITERATE(e, fn, args...) \
872 +({ \
873 + unsigned int __i; \
874 + int __ret = 0; \
875 + struct ebt_entry_watcher *__watcher; \
876 + \
877 + for (__i = e->watchers_offset; \
878 + __i < (e)->target_offset; \
879 + __i += __watcher->watcher_size + \
880 + sizeof(struct ebt_entry_watcher)) { \
881 + __watcher = (void *)(e) + __i; \
882 + \
883 + __ret = fn(__watcher , ## args); \
884 + if (__ret != 0) \
885 + break; \
886 + } \
887 + if (__ret == 0) { \
888 + if (__i != (e)->target_offset) \
889 + __ret = -EINVAL; \
890 + } \
891 + __ret; \
892 +})
893 +
894 +#define EBT_ENTRY_ITERATE(entries, size, fn, args...) \
895 +({ \
896 + unsigned int __i; \
897 + int __ret = 0; \
898 + struct ebt_entry *__entry; \
899 + \
900 + for (__i = 0; __i < (size);) { \
901 + __entry = (void *)(entries) + __i; \
902 + __ret = fn(__entry , ## args); \
903 + if (__ret != 0) \
904 + break; \
905 + if (__entry->bitmask != 0) \
906 + __i += __entry->next_offset; \
907 + else \
908 + __i += sizeof(struct ebt_entries); \
909 + } \
910 + if (__ret == 0) { \
911 + if (__i != (size)) \
912 + __ret = -EINVAL; \
913 + } \
914 + __ret; \
915 +})
916 +
917 +#endif
918 diff -Nur linux.old/include/linux/netfilter_bridge.h linux.dev/include/linux/netfilter_bridge.h
919 --- linux.old/include/linux/netfilter_bridge.h 2001-06-12 04:15:27.000000000 +0200
920 +++ linux.dev/include/linux/netfilter_bridge.h 2005-10-10 10:36:45.989863000 +0200
921 @@ -6,6 +6,10 @@
922
923 #include <linux/config.h>
924 #include <linux/netfilter.h>
925 +#if defined(__KERNEL__) && defined(CONFIG_NETFILTER)
926 +#include <asm/atomic.h>
927 +#include <linux/if_ether.h>
928 +#endif
929
930 /* Bridge Hooks */
931 /* After promisc drops, checksum checks. */
932 @@ -18,7 +22,89 @@
933 #define NF_BR_LOCAL_OUT 3
934 /* Packets about to hit the wire. */
935 #define NF_BR_POST_ROUTING 4
936 -#define NF_BR_NUMHOOKS 5
937 +/* Not really a hook, but used for the ebtables broute table */
938 +#define NF_BR_BROUTING 5
939 +#define NF_BR_NUMHOOKS 6
940 +
941 +#ifdef __KERNEL__
942 +
943 +#define BRNF_PKT_TYPE 0x01
944 +#define BRNF_BRIDGED_DNAT 0x02
945 +#define BRNF_DONT_TAKE_PARENT 0x04
946 +#define BRNF_BRIDGED 0x08
947 +#define BRNF_NF_BRIDGE_PREROUTING 0x10
948 +
949 +enum nf_br_hook_priorities {
950 + NF_BR_PRI_FIRST = INT_MIN,
951 + NF_BR_PRI_NAT_DST_BRIDGED = -300,
952 + NF_BR_PRI_FILTER_BRIDGED = -200,
953 + NF_BR_PRI_BRNF = 0,
954 + NF_BR_PRI_NAT_DST_OTHER = 100,
955 + NF_BR_PRI_FILTER_OTHER = 200,
956 + NF_BR_PRI_NAT_SRC = 300,
957 + NF_BR_PRI_LAST = INT_MAX,
958 +};
959 +
960 +#ifdef CONFIG_NETFILTER
961 +static inline
962 +struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
963 +{
964 + struct nf_bridge_info **nf_bridge = &(skb->nf_bridge);
965 +
966 + if ((*nf_bridge = kmalloc(sizeof(**nf_bridge), GFP_ATOMIC)) != NULL) {
967 + atomic_set(&(*nf_bridge)->use, 1);
968 + (*nf_bridge)->mask = 0;
969 + (*nf_bridge)->physindev = (*nf_bridge)->physoutdev = NULL;
970 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
971 + (*nf_bridge)->netoutdev = NULL;
972 +#endif
973 + }
974 +
975 + return *nf_bridge;
976 +}
977 +
978 +/* Only used in br_forward.c */
979 +static inline
980 +void nf_bridge_maybe_copy_header(struct sk_buff *skb)
981 +{
982 + if (skb->nf_bridge) {
983 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
984 + memcpy(skb->data - 18, skb->nf_bridge->data, 18);
985 + skb_push(skb, 4);
986 + } else
987 + memcpy(skb->data - 16, skb->nf_bridge->data, 16);
988 + }
989 +}
990 +
991 +static inline
992 +void nf_bridge_save_header(struct sk_buff *skb)
993 +{
994 + int header_size = 16;
995 +
996 + if (skb->protocol == __constant_htons(ETH_P_8021Q))
997 + header_size = 18;
998 + memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
999 +}
1000 +
1001 +struct bridge_skb_cb {
1002 + union {
1003 + __u32 ipv4;
1004 + } daddr;
1005 +};
1006 +
1007
1008 +/* This is called by the IP fragmenting code and it ensures there is
1009 + * enough room for the encapsulating header (if there is one). */
1010 +static inline
1011 +int nf_bridge_pad(struct sk_buff *skb)
1012 +{
1013 + if (skb->nf_bridge) {
1014 + if (skb->protocol == __constant_htons(ETH_P_8021Q))
1015 + return 4;
1016 + }
1017 + return 0;
1018 +}
1019 +#endif /* CONFIG_NETFILTER */
1020
1021 +#endif /* __KERNEL__ */
1022 #endif
1023 diff -Nur linux.old/include/linux/netfilter_ipv4/ip_tables.h linux.dev/include/linux/netfilter_ipv4/ip_tables.h
1024 --- linux.old/include/linux/netfilter_ipv4/ip_tables.h 2005-10-10 10:33:04.011990250 +0200
1025 +++ linux.dev/include/linux/netfilter_ipv4/ip_tables.h 2005-10-10 10:36:46.021865000 +0200
1026 @@ -159,7 +159,7 @@
1027 #define IPT_CONTINUE 0xFFFFFFFF
1028
1029 /* For standard target */
1030 -#define IPT_RETURN (-NF_MAX_VERDICT - 1)
1031 +#define IPT_RETURN (-NF_REPEAT - 1)
1032
1033 /* TCP matching stuff */
1034 struct ipt_tcp
1035 diff -Nur linux.old/include/linux/netfilter_ipv4/ipt_physdev.h linux.dev/include/linux/netfilter_ipv4/ipt_physdev.h
1036 --- linux.old/include/linux/netfilter_ipv4/ipt_physdev.h 1970-01-01 01:00:00.000000000 +0100
1037 +++ linux.dev/include/linux/netfilter_ipv4/ipt_physdev.h 2005-10-10 10:36:46.293882000 +0200
1038 @@ -0,0 +1,24 @@
1039 +#ifndef _IPT_PHYSDEV_H
1040 +#define _IPT_PHYSDEV_H
1041 +
1042 +#ifdef __KERNEL__
1043 +#include <linux/if.h>
1044 +#endif
1045 +
1046 +#define IPT_PHYSDEV_OP_IN 0x01
1047 +#define IPT_PHYSDEV_OP_OUT 0x02
1048 +#define IPT_PHYSDEV_OP_BRIDGED 0x04
1049 +#define IPT_PHYSDEV_OP_ISIN 0x08
1050 +#define IPT_PHYSDEV_OP_ISOUT 0x10
1051 +#define IPT_PHYSDEV_OP_MASK (0x20 - 1)
1052 +
1053 +struct ipt_physdev_info {
1054 + char physindev[IFNAMSIZ];
1055 + char in_mask[IFNAMSIZ];
1056 + char physoutdev[IFNAMSIZ];
1057 + char out_mask[IFNAMSIZ];
1058 + u_int8_t invert;
1059 + u_int8_t bitmask;
1060 +};
1061 +
1062 +#endif /*_IPT_PHYSDEV_H*/
1063 diff -Nur linux.old/include/linux/netfilter_ipv4.h linux.dev/include/linux/netfilter_ipv4.h
1064 --- linux.old/include/linux/netfilter_ipv4.h 2002-02-25 20:38:13.000000000 +0100
1065 +++ linux.dev/include/linux/netfilter_ipv4.h 2005-10-10 10:36:46.161873750 +0200
1066 @@ -52,8 +52,10 @@
1067 enum nf_ip_hook_priorities {
1068 NF_IP_PRI_FIRST = INT_MIN,
1069 NF_IP_PRI_CONNTRACK = -200,
1070 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD = -175,
1071 NF_IP_PRI_MANGLE = -150,
1072 NF_IP_PRI_NAT_DST = -100,
1073 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT = -50,
1074 NF_IP_PRI_FILTER = 0,
1075 NF_IP_PRI_NAT_SRC = 100,
1076 NF_IP_PRI_LAST = INT_MAX,
1077 diff -Nur linux.old/include/linux/netfilter_ipv6/ip6_tables.h linux.dev/include/linux/netfilter_ipv6/ip6_tables.h
1078 --- linux.old/include/linux/netfilter_ipv6/ip6_tables.h 2005-04-04 03:42:20.000000000 +0200
1079 +++ linux.dev/include/linux/netfilter_ipv6/ip6_tables.h 2005-10-10 10:36:46.037866000 +0200
1080 @@ -165,7 +165,7 @@
1081 #define IP6T_CONTINUE 0xFFFFFFFF
1082
1083 /* For standard target */
1084 -#define IP6T_RETURN (-NF_MAX_VERDICT - 1)
1085 +#define IP6T_RETURN (-NF_REPEAT - 1)
1086
1087 /* TCP matching stuff */
1088 struct ip6t_tcp
1089 diff -Nur linux.old/include/linux/netfilter_ipv6.h linux.dev/include/linux/netfilter_ipv6.h
1090 --- linux.old/include/linux/netfilter_ipv6.h 2001-01-02 01:17:54.000000000 +0100
1091 +++ linux.dev/include/linux/netfilter_ipv6.h 2005-10-10 10:36:46.169874250 +0200
1092 @@ -57,8 +57,10 @@
1093 enum nf_ip6_hook_priorities {
1094 NF_IP6_PRI_FIRST = INT_MIN,
1095 NF_IP6_PRI_CONNTRACK = -200,
1096 + NF_IP6_PRI_BRIDGE_SABOTAGE_FORWARD = -175,
1097 NF_IP6_PRI_MANGLE = -150,
1098 NF_IP6_PRI_NAT_DST = -100,
1099 + NF_IP6_PRI_BRIDGE_SABOTAGE_LOCAL_OUT = -50,
1100 NF_IP6_PRI_FILTER = 0,
1101 NF_IP6_PRI_NAT_SRC = 100,
1102 NF_IP6_PRI_LAST = INT_MAX,
1103 diff -Nur linux.old/include/linux/skbuff.h linux.dev/include/linux/skbuff.h
1104 --- linux.old/include/linux/skbuff.h 2005-10-10 10:33:06.840167000 +0200
1105 +++ linux.dev/include/linux/skbuff.h 2005-10-10 10:36:46.185875250 +0200
1106 @@ -92,6 +92,20 @@
1107 struct nf_ct_info {
1108 struct nf_conntrack *master;
1109 };
1110 +
1111 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1112 +struct nf_bridge_info {
1113 + atomic_t use;
1114 + struct net_device *physindev;
1115 + struct net_device *physoutdev;
1116 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1117 + struct net_device *netoutdev;
1118 +#endif
1119 + unsigned int mask;
1120 + unsigned long data[32 / sizeof(unsigned long)];
1121 +};
1122 +#endif
1123 +
1124 #endif
1125 #if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1126 struct nf_info;
1127 @@ -207,6 +221,9 @@
1128 #ifdef CONFIG_NETFILTER_DEBUG
1129 unsigned int nf_debug;
1130 #endif
1131 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1132 + struct nf_bridge_info *nf_bridge; /* Saved data about a bridged frame - see br_netfilter.c */
1133 +#endif
1134 #endif /*CONFIG_NETFILTER*/
1135
1136 #if defined(CONFIG_HIPPI)
1137 @@ -1177,6 +1194,20 @@
1138 skb->nf_debug = 0;
1139 #endif
1140 }
1141 +
1142 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1143 +static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
1144 +{
1145 + if (nf_bridge && atomic_dec_and_test(&nf_bridge->use))
1146 + kfree(nf_bridge);
1147 +}
1148 +static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)
1149 +{
1150 + if (nf_bridge)
1151 + atomic_inc(&nf_bridge->use);
1152 +}
1153 +#endif
1154 +
1155 #else /* CONFIG_NETFILTER */
1156 static inline void nf_reset(struct sk_buff *skb) {}
1157 #endif /* CONFIG_NETFILTER */
1158 diff -Nur linux.old/include/linux/sysctl.h linux.dev/include/linux/sysctl.h
1159 --- linux.old/include/linux/sysctl.h 2005-04-04 03:42:20.000000000 +0200
1160 +++ linux.dev/include/linux/sysctl.h 2005-10-10 10:36:46.333884500 +0200
1161 @@ -609,6 +609,15 @@
1162 NET_DECNET_CONF_DEV_STATE = 7
1163 };
1164
1165 +/* /proc/sys/net/bridge */
1166 +enum {
1167 + NET_BRIDGE_NF_CALL_ARPTABLES = 1,
1168 + NET_BRIDGE_NF_CALL_IPTABLES = 2,
1169 + NET_BRIDGE_NF_CALL_IP6TABLES = 3,
1170 + NET_BRIDGE_NF_FILTER_VLAN_TAGGED = 4,
1171 +};
1172 +
1173 +
1174 /* CTL_PROC names: */
1175
1176 /* CTL_FS names: */
1177 diff -Nur linux.old/net/8021q/vlan_dev.c linux.dev/net/8021q/vlan_dev.c
1178 --- linux.old/net/8021q/vlan_dev.c 2005-01-19 15:10:13.000000000 +0100
1179 +++ linux.dev/net/8021q/vlan_dev.c 2005-10-10 10:36:46.317883500 +0200
1180 @@ -488,6 +488,10 @@
1181 stats->tx_packets++; /* for statics only */
1182 stats->tx_bytes += skb->len;
1183
1184 + skb->protocol = __constant_htons(ETH_P_8021Q);
1185 + skb->mac.raw -= VLAN_HLEN;
1186 + skb->nh.raw -= VLAN_HLEN;
1187 +
1188 skb->dev = VLAN_DEV_INFO(dev)->real_dev;
1189 dev_queue_xmit(skb);
1190
1191 diff -Nur linux.old/net/Config.in linux.dev/net/Config.in
1192 --- linux.old/net/Config.in 2005-10-10 10:33:00.299758250 +0200
1193 +++ linux.dev/net/Config.in 2005-10-10 10:36:46.085869000 +0200
1194 @@ -70,6 +70,9 @@
1195 source net/decnet/Config.in
1196 fi
1197 dep_tristate '802.1d Ethernet Bridging' CONFIG_BRIDGE $CONFIG_INET
1198 +if [ "$CONFIG_BRIDGE" != "n" -a "$CONFIG_NETFILTER" != "n" ]; then
1199 + source net/bridge/netfilter/Config.in
1200 +fi
1201 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
1202 tristate 'CCITT X.25 Packet Layer (EXPERIMENTAL)' CONFIG_X25
1203 tristate 'LAPB Data Link Driver (EXPERIMENTAL)' CONFIG_LAPB
1204 diff -Nur linux.old/net/Makefile linux.dev/net/Makefile
1205 --- linux.old/net/Makefile 2004-08-08 01:26:06.000000000 +0200
1206 +++ linux.dev/net/Makefile 2005-10-10 10:36:46.077868500 +0200
1207 @@ -7,7 +7,8 @@
1208
1209 O_TARGET := network.o
1210
1211 -mod-subdirs := ipv4/netfilter ipv6/netfilter ipx irda bluetooth atm netlink sched core sctp 802
1212 +mod-subdirs := ipv4/netfilter ipv6/netfilter bridge/netfilter ipx irda \
1213 + bluetooth atm netlink sched core sctp 802
1214 export-objs := netsyms.o
1215
1216 subdir-y := core ethernet
1217 @@ -27,6 +28,12 @@
1218 endif
1219 endif
1220
1221 +ifneq ($(CONFIG_BRIDGE),n)
1222 +ifneq ($(CONFIG_BRIDGE),)
1223 +subdir-$(CONFIG_BRIDGE) += bridge/netfilter
1224 +endif
1225 +endif
1226 +
1227 subdir-$(CONFIG_KHTTPD) += khttpd
1228 subdir-$(CONFIG_PACKET) += packet
1229 subdir-$(CONFIG_NET_SCHED) += sched
1230 diff -Nur linux.old/net/bridge/Makefile linux.dev/net/bridge/Makefile
1231 --- linux.old/net/bridge/Makefile 2000-12-29 23:07:24.000000000 +0100
1232 +++ linux.dev/net/bridge/Makefile 2005-10-10 11:32:01.347058000 +0200
1233 @@ -7,10 +7,18 @@
1234 #
1235 # Note 2! The CFLAGS definition is now in the main makefile...
1236
1237 +export-objs := br.o
1238 +
1239 O_TARGET := bridge.o
1240 obj-y := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \
1241 br_ioctl.o br_notify.o br_stp.o br_stp_bpdu.o \
1242 br_stp_if.o br_stp_timer.o
1243 +
1244 +ifeq ($(CONFIG_NETFILTER),y)
1245 +export-objs += br_netfilter.o
1246 +obj-y += br_netfilter.o
1247 +endif
1248 +
1249 obj-m := $(O_TARGET)
1250
1251 include $(TOPDIR)/Rules.make
1252 diff -Nur linux.old/net/bridge/br.c linux.dev/net/bridge/br.c
1253 --- linux.old/net/bridge/br.c 2004-08-08 01:26:06.000000000 +0200
1254 +++ linux.dev/net/bridge/br.c 2005-10-10 10:40:13.694843750 +0200
1255 @@ -30,6 +30,8 @@
1256 #include "../atm/lec.h"
1257 #endif
1258
1259 +int (*br_should_route_hook) (struct sk_buff **pskb) = NULL;
1260 +
1261 void br_dec_use_count()
1262 {
1263 MOD_DEC_USE_COUNT;
1264 @@ -73,7 +75,7 @@
1265 #endif
1266 }
1267
1268 -EXPORT_NO_SYMBOLS;
1269 +EXPORT_SYMBOL(br_should_route_hook);
1270
1271 module_init(br_init)
1272 module_exit(br_deinit)
1273 diff -Nur linux.old/net/bridge/br_forward.c linux.dev/net/bridge/br_forward.c
1274 --- linux.old/net/bridge/br_forward.c 2003-11-28 19:26:21.000000000 +0100
1275 +++ linux.dev/net/bridge/br_forward.c 2005-10-10 10:36:45.981862500 +0200
1276 @@ -30,18 +30,21 @@
1277 return 1;
1278 }
1279
1280 -static int __dev_queue_push_xmit(struct sk_buff *skb)
1281 +int br_dev_queue_push_xmit(struct sk_buff *skb)
1282 {
1283 +#ifdef CONFIG_NETFILTER
1284 + nf_bridge_maybe_copy_header(skb);
1285 +#endif
1286 skb_push(skb, ETH_HLEN);
1287 dev_queue_xmit(skb);
1288
1289 return 0;
1290 }
1291
1292 -static int __br_forward_finish(struct sk_buff *skb)
1293 +int br_forward_finish(struct sk_buff *skb)
1294 {
1295 NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
1296 - __dev_queue_push_xmit);
1297 + br_dev_queue_push_xmit);
1298
1299 return 0;
1300 }
1301 @@ -49,8 +52,11 @@
1302 static void __br_deliver(struct net_bridge_port *to, struct sk_buff *skb)
1303 {
1304 skb->dev = to->dev;
1305 +#ifdef CONFIG_NETFILTER_DEBUG
1306 + skb->nf_debug = 0;
1307 +#endif
1308 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
1309 - __br_forward_finish);
1310 + br_forward_finish);
1311 }
1312
1313 static void __br_forward(struct net_bridge_port *to, struct sk_buff *skb)
1314 @@ -62,7 +68,7 @@
1315 skb->ip_summed = CHECKSUM_NONE;
1316
1317 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
1318 - __br_forward_finish);
1319 + br_forward_finish);
1320 }
1321
1322 /* called under bridge lock */
1323 diff -Nur linux.old/net/bridge/br_input.c linux.dev/net/bridge/br_input.c
1324 --- linux.old/net/bridge/br_input.c 2003-08-25 13:44:44.000000000 +0200
1325 +++ linux.dev/net/bridge/br_input.c 2005-10-10 10:36:45.981862500 +0200
1326 @@ -24,6 +24,9 @@
1327
1328 static int br_pass_frame_up_finish(struct sk_buff *skb)
1329 {
1330 +#ifdef CONFIG_NETFILTER_DEBUG
1331 + skb->nf_debug = 0;
1332 +#endif
1333 netif_rx(skb);
1334
1335 return 0;
1336 @@ -46,7 +49,7 @@
1337 br_pass_frame_up_finish);
1338 }
1339
1340 -static int br_handle_frame_finish(struct sk_buff *skb)
1341 +int br_handle_frame_finish(struct sk_buff *skb)
1342 {
1343 struct net_bridge *br;
1344 unsigned char *dest;
1345 @@ -112,7 +115,7 @@
1346 return 0;
1347 }
1348
1349 -void br_handle_frame(struct sk_buff *skb)
1350 +int br_handle_frame(struct sk_buff *skb)
1351 {
1352 struct net_bridge *br;
1353 unsigned char *dest;
1354 @@ -146,26 +149,35 @@
1355 goto handle_special_frame;
1356
1357 if (p->state == BR_STATE_FORWARDING) {
1358 + if (br_should_route_hook && br_should_route_hook(&skb)) {
1359 + read_unlock(&br->lock);
1360 + return -1;
1361 + }
1362 +
1363 + if (!memcmp(p->br->dev.dev_addr, dest, ETH_ALEN))
1364 + skb->pkt_type = PACKET_HOST;
1365 +
1366 NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
1367 br_handle_frame_finish);
1368 read_unlock(&br->lock);
1369 - return;
1370 + return 0;
1371 }
1372
1373 err:
1374 read_unlock(&br->lock);
1375 err_nolock:
1376 kfree_skb(skb);
1377 - return;
1378 + return 0;
1379
1380 handle_special_frame:
1381 if (!dest[5]) {
1382 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,NULL,
1383 br_stp_handle_bpdu);
1384 read_unlock(&br->lock);
1385 - return;
1386 + return 0;
1387 }
1388
1389 read_unlock(&br->lock);
1390 kfree_skb(skb);
1391 + return 0;
1392 }
1393 diff -Nur linux.old/net/bridge/br_netfilter.c linux.dev/net/bridge/br_netfilter.c
1394 --- linux.old/net/bridge/br_netfilter.c 1970-01-01 01:00:00.000000000 +0100
1395 +++ linux.dev/net/bridge/br_netfilter.c 2005-10-10 11:43:47.019159750 +0200
1396 @@ -0,0 +1,1105 @@
1397 +/*
1398 + * Handle firewalling
1399 + * Linux ethernet bridge
1400 + *
1401 + * Authors:
1402 + * Lennert Buytenhek <buytenh@gnu.org>
1403 + * Bart De Schuymer (maintainer) <bdschuym@pandora.be>
1404 + *
1405 + * Changes:
1406 + * Apr 29 2003: physdev module support (bdschuym)
1407 + * Jun 19 2003: let arptables see bridged ARP traffic (bdschuym)
1408 + * Oct 06 2003: filter encapsulated IP/ARP VLAN traffic on untagged bridge
1409 + * (bdschuym)
1410 + * Aug 28 2004: add IPv6 filtering (bdschuym)
1411 + *
1412 + * This program is free software; you can redistribute it and/or
1413 + * modify it under the terms of the GNU General Public License
1414 + * as published by the Free Software Foundation; either version
1415 + * 2 of the License, or (at your option) any later version.
1416 + *
1417 + * Lennert dedicates this file to Kerstin Wurdinger.
1418 + */
1419 +
1420 +#include <linux/module.h>
1421 +#include <linux/kernel.h>
1422 +#include <linux/ip.h>
1423 +#include <linux/netdevice.h>
1424 +#include <linux/skbuff.h>
1425 +#include <linux/if_ether.h>
1426 +#include <linux/if_vlan.h>
1427 +#include <linux/netfilter_bridge.h>
1428 +#include <linux/netfilter_ipv4.h>
1429 +#include <linux/netfilter_ipv6.h>
1430 +#include <linux/in_route.h>
1431 +#include <net/ip.h>
1432 +#include <net/ipv6.h>
1433 +#include <asm/uaccess.h>
1434 +#include <asm/checksum.h>
1435 +#include "br_private.h"
1436 +#ifdef CONFIG_SYSCTL
1437 +#include <linux/sysctl.h>
1438 +#endif
1439 +
1440 +#define skb_origaddr(skb) (((struct bridge_skb_cb *) \
1441 + (skb->nf_bridge->data))->daddr.ipv4)
1442 +#define store_orig_dstaddr(skb) (skb_origaddr(skb) = (skb)->nh.iph->daddr)
1443 +#define dnat_took_place(skb) (skb_origaddr(skb) != (skb)->nh.iph->daddr)
1444 +
1445 +#define has_bridge_parent(device) ((device)->br_port != NULL)
1446 +#define bridge_parent(device) (&((device)->br_port->br->dev))
1447 +
1448 +#ifdef CONFIG_SYSCTL
1449 +static struct ctl_table_header *brnf_sysctl_header;
1450 +static int brnf_call_iptables = 1;
1451 +static int brnf_call_ip6tables = 1;
1452 +static int brnf_call_arptables = 1;
1453 +static int brnf_filter_vlan_tagged = 1;
1454 +#else
1455 +#define brnf_filter_vlan_tagged 1
1456 +#endif
1457 +
1458 +#define IS_VLAN_IP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
1459 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IP) && \
1460 + brnf_filter_vlan_tagged)
1461 +#define IS_VLAN_IPV6 (skb->protocol == __constant_htons(ETH_P_8021Q) && \
1462 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IPV6) && \
1463 + brnf_filter_vlan_tagged)
1464 +/*
1465 +#define IS_VLAN_ARP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
1466 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_ARP) && \
1467 + brnf_filter_vlan_tagged)
1468 +*/
1469 +
1470 +/* We need these fake structures to make netfilter happy --
1471 + * lots of places assume that skb->dst != NULL, which isn't
1472 + * all that unreasonable.
1473 + *
1474 + * Currently, we fill in the PMTU entry because netfilter
1475 + * refragmentation needs it, and the rt_flags entry because
1476 + * ipt_REJECT needs it. Future netfilter modules might
1477 + * require us to fill additional fields.
1478 + */
1479 +static struct net_device __fake_net_device = {
1480 + .hard_header_len = ETH_HLEN
1481 +};
1482 +
1483 +static struct rtable __fake_rtable = {
1484 + u: {
1485 + dst: {
1486 + __refcnt: ATOMIC_INIT(1),
1487 + dev: &__fake_net_device,
1488 + pmtu: 1500
1489 + }
1490 + },
1491 +
1492 + rt_flags: 0
1493 +};
1494 +
1495 +
1496 +/* PF_BRIDGE/PRE_ROUTING *********************************************/
1497 +/* Undo the changes made for ip6tables PREROUTING and continue the
1498 + * bridge PRE_ROUTING hook. */
1499 +static int br_nf_pre_routing_finish_ipv6(struct sk_buff *skb)
1500 +{
1501 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
1502 +
1503 +#ifdef CONFIG_NETFILTER_DEBUG
1504 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
1505 +#endif
1506 +
1507 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
1508 + skb->pkt_type = PACKET_OTHERHOST;
1509 + nf_bridge->mask ^= BRNF_PKT_TYPE;
1510 + }
1511 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
1512 +
1513 + skb->dst = (struct dst_entry *)&__fake_rtable;
1514 + dst_hold(skb->dst);
1515 +
1516 + skb->dev = nf_bridge->physindev;
1517 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1518 + skb_push(skb, VLAN_HLEN);
1519 + skb->nh.raw -= VLAN_HLEN;
1520 + }
1521 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
1522 + br_handle_frame_finish, 1);
1523 +
1524 + return 0;
1525 +}
1526 +
1527 +static void __br_dnat_complain(void)
1528 +{
1529 + static unsigned long last_complaint;
1530 +
1531 + if (jiffies - last_complaint >= 5 * HZ) {
1532 + printk(KERN_WARNING "Performing cross-bridge DNAT requires IP "
1533 + "forwarding to be enabled\n");
1534 + last_complaint = jiffies;
1535 + }
1536 +}
1537 +
1538 +
1539 +/* This requires some explaining. If DNAT has taken place,
1540 + * we will need to fix up the destination Ethernet address,
1541 + * and this is a tricky process.
1542 + *
1543 + * There are two cases to consider:
1544 + * 1. The packet was DNAT'ed to a device in the same bridge
1545 + * port group as it was received on. We can still bridge
1546 + * the packet.
1547 + * 2. The packet was DNAT'ed to a different device, either
1548 + * a non-bridged device or another bridge port group.
1549 + * The packet will need to be routed.
1550 + *
1551 + * The correct way of distinguishing between these two cases is to
1552 + * call ip_route_input() and to look at skb->dst->dev, which is
1553 + * changed to the destination device if ip_route_input() succeeds.
1554 + *
1555 + * Let us first consider the case that ip_route_input() succeeds:
1556 + *
1557 + * If skb->dst->dev equals the logical bridge device the packet
1558 + * came in on, we can consider this bridging. We then call
1559 + * skb->dst->output() which will make the packet enter br_nf_local_out()
1560 + * not much later. In that function it is assured that the iptables
1561 + * FORWARD chain is traversed for the packet.
1562 + *
1563 + * Otherwise, the packet is considered to be routed and we just
1564 + * change the destination MAC address so that the packet will
1565 + * later be passed up to the IP stack to be routed.
1566 + *
1567 + * Let us now consider the case that ip_route_input() fails:
1568 + *
1569 + * After a "echo '0' > /proc/sys/net/ipv4/ip_forward" ip_route_input()
1570 + * will fail, while __ip_route_output_key() will return success. The source
1571 + * address for __ip_route_output_key() is set to zero, so __ip_route_output_key
1572 + * thinks we're handling a locally generated packet and won't care
1573 + * if IP forwarding is allowed. We send a warning message to the users's
1574 + * log telling her to put IP forwarding on.
1575 + *
1576 + * ip_route_input() will also fail if there is no route available.
1577 + * In that case we just drop the packet.
1578 + *
1579 + * --Lennert, 20020411
1580 + * --Bart, 20020416 (updated)
1581 + * --Bart, 20021007 (updated)
1582 + */
1583 +
1584 +static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
1585 +{
1586 +#ifdef CONFIG_NETFILTER_DEBUG
1587 + skb->nf_debug |= (1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_FORWARD);
1588 +#endif
1589 +
1590 + if (skb->pkt_type == PACKET_OTHERHOST) {
1591 + skb->pkt_type = PACKET_HOST;
1592 + skb->nf_bridge->mask |= BRNF_PKT_TYPE;
1593 + }
1594 + skb->nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
1595 +
1596 + skb->dev = bridge_parent(skb->dev);
1597 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1598 + skb_pull(skb, VLAN_HLEN);
1599 + skb->nh.raw += VLAN_HLEN;
1600 + }
1601 + skb->dst->output(skb);
1602 + return 0;
1603 +}
1604 +
1605 +static int br_nf_pre_routing_finish(struct sk_buff *skb)
1606 +{
1607 + struct net_device *dev = skb->dev;
1608 + struct iphdr *iph = skb->nh.iph;
1609 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
1610 +
1611 +#ifdef CONFIG_NETFILTER_DEBUG
1612 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
1613 +#endif
1614 +
1615 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
1616 + skb->pkt_type = PACKET_OTHERHOST;
1617 + nf_bridge->mask ^= BRNF_PKT_TYPE;
1618 + }
1619 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
1620 +
1621 + if (dnat_took_place(skb)) {
1622 + if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos,
1623 + dev)) {
1624 + struct rtable *rt;
1625 +
1626 + if (!ip_route_output(&rt, iph->daddr, 0, iph->tos, 0)) {
1627 + /* Bridged-and-DNAT'ed traffic doesn't
1628 + * require ip_forwarding.
1629 + */
1630 + if (((struct dst_entry *)rt)->dev == dev) {
1631 + skb->dst = (struct dst_entry *)rt;
1632 + goto bridged_dnat;
1633 + }
1634 + __br_dnat_complain();
1635 + dst_release((struct dst_entry *)rt);
1636 + }
1637 + kfree_skb(skb);
1638 + return 0;
1639 + } else {
1640 + if (skb->dst->dev == dev) {
1641 +bridged_dnat:
1642 + /* Tell br_nf_local_out this is a
1643 + * bridged frame
1644 + */
1645 + nf_bridge->mask |= BRNF_BRIDGED_DNAT;
1646 + skb->dev = nf_bridge->physindev;
1647 + if (skb->protocol ==
1648 + __constant_htons(ETH_P_8021Q)) {
1649 + skb_push(skb, VLAN_HLEN);
1650 + skb->nh.raw -= VLAN_HLEN;
1651 + }
1652 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING,
1653 + skb, skb->dev, NULL,
1654 + br_nf_pre_routing_finish_bridge,
1655 + 1);
1656 + return 0;
1657 + }
1658 + memcpy(skb->mac.ethernet->h_dest, dev->dev_addr,
1659 + ETH_ALEN);
1660 + skb->pkt_type = PACKET_HOST;
1661 + }
1662 + } else {
1663 + skb->dst = (struct dst_entry *)&__fake_rtable;
1664 + dst_hold(skb->dst);
1665 + }
1666 +
1667 + skb->dev = nf_bridge->physindev;
1668 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1669 + skb_push(skb, VLAN_HLEN);
1670 + skb->nh.raw -= VLAN_HLEN;
1671 + }
1672 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
1673 + br_handle_frame_finish, 1);
1674 +
1675 + return 0;
1676 +}
1677 +
1678 +/* Some common code for IPv4/IPv6 */
1679 +static void setup_pre_routing(struct sk_buff *skb)
1680 +{
1681 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
1682 +
1683 + if (skb->pkt_type == PACKET_OTHERHOST) {
1684 + skb->pkt_type = PACKET_HOST;
1685 + nf_bridge->mask |= BRNF_PKT_TYPE;
1686 + }
1687 +
1688 + nf_bridge->mask |= BRNF_NF_BRIDGE_PREROUTING;
1689 + nf_bridge->physindev = skb->dev;
1690 + skb->dev = bridge_parent(skb->dev);
1691 +}
1692 +
1693 +/* We only check the length. A bridge shouldn't do any hop-by-hop stuff anyway */
1694 +static int check_hbh_len(struct sk_buff *skb)
1695 +{
1696 + unsigned char *raw = (u8*)(skb->nh.ipv6h+1);
1697 + u32 pkt_len;
1698 + int off = raw - skb->nh.raw;
1699 + int len = (raw[1]+1)<<3;
1700 +
1701 + if ((raw + len) - skb->data > skb_headlen(skb))
1702 + goto bad;
1703 +
1704 + off += 2;
1705 + len -= 2;
1706 +
1707 + while (len > 0) {
1708 + int optlen = raw[off+1]+2;
1709 +
1710 + switch (skb->nh.raw[off]) {
1711 + case IPV6_TLV_PAD0:
1712 + optlen = 1;
1713 + break;
1714 +
1715 + case IPV6_TLV_PADN:
1716 + break;
1717 +
1718 + case IPV6_TLV_JUMBO:
1719 + if (skb->nh.raw[off+1] != 4 || (off&3) != 2)
1720 + goto bad;
1721 +
1722 + pkt_len = ntohl(*(u32*)(skb->nh.raw+off+2));
1723 +
1724 + if (pkt_len > skb->len - sizeof(struct ipv6hdr))
1725 + goto bad;
1726 + if (pkt_len + sizeof(struct ipv6hdr) < skb->len) {
1727 + if (__pskb_trim(skb,
1728 + pkt_len + sizeof(struct ipv6hdr)))
1729 + goto bad;
1730 + if (skb->ip_summed == CHECKSUM_HW)
1731 + skb->ip_summed = CHECKSUM_NONE;
1732 + }
1733 + break;
1734 + default:
1735 + if (optlen > len)
1736 + goto bad;
1737 + break;
1738 + }
1739 + off += optlen;
1740 + len -= optlen;
1741 + }
1742 + if (len == 0)
1743 + return 0;
1744 +bad:
1745 + return -1;
1746 +
1747 +}
1748 +
1749 +/* Replicate the checks that IPv6 does on packet reception and pass the packet
1750 + * to ip6tables, which doesn't support NAT, so things are fairly simple. */
1751 +static unsigned int br_nf_pre_routing_ipv6(unsigned int hook,
1752 + struct sk_buff *skb, const struct net_device *in,
1753 + const struct net_device *out, int (*okfn)(struct sk_buff *))
1754 +{
1755 + struct ipv6hdr *hdr;
1756 + u32 pkt_len;
1757 + struct nf_bridge_info *nf_bridge;
1758 +
1759 + if (skb->len < sizeof(struct ipv6hdr))
1760 + goto inhdr_error;
1761 +
1762 + if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
1763 + goto inhdr_error;
1764 +
1765 + hdr = skb->nh.ipv6h;
1766 +
1767 + if (hdr->version != 6)
1768 + goto inhdr_error;
1769 +
1770 + pkt_len = ntohs(hdr->payload_len);
1771 +
1772 + if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) {
1773 + if (pkt_len + sizeof(struct ipv6hdr) > skb->len)
1774 + goto inhdr_error;
1775 + if (pkt_len + sizeof(struct ipv6hdr) < skb->len) {
1776 + if (__pskb_trim(skb, pkt_len + sizeof(struct ipv6hdr)))
1777 + goto inhdr_error;
1778 + if (skb->ip_summed == CHECKSUM_HW)
1779 + skb->ip_summed = CHECKSUM_NONE;
1780 + }
1781 + }
1782 + if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb))
1783 + goto inhdr_error;
1784 +
1785 +#ifdef CONFIG_NETFILTER_DEBUG
1786 + skb->nf_debug ^= (1 << NF_IP6_PRE_ROUTING);
1787 +#endif
1788 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
1789 + return NF_DROP;
1790 + setup_pre_routing(skb);
1791 +
1792 + NF_HOOK(PF_INET6, NF_IP6_PRE_ROUTING, skb, skb->dev, NULL,
1793 + br_nf_pre_routing_finish_ipv6);
1794 +
1795 + return NF_STOLEN;
1796 +
1797 +inhdr_error:
1798 + return NF_DROP;
1799 +}
1800 +
1801 +/* Direct IPv6 traffic to br_nf_pre_routing_ipv6.
1802 + * Replicate the checks that IPv4 does on packet reception.
1803 + * Set skb->dev to the bridge device (i.e. parent of the
1804 + * receiving device) to make netfilter happy, the REDIRECT
1805 + * target in particular. Save the original destination IP
1806 + * address to be able to detect DNAT afterwards.
1807 + */
1808 +static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
1809 + const struct net_device *in, const struct net_device *out,
1810 + int (*okfn)(struct sk_buff *))
1811 +{
1812 + struct iphdr *iph;
1813 + __u32 len;
1814 + struct sk_buff *skb = *pskb;
1815 + struct nf_bridge_info *nf_bridge;
1816 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)
1817 + ((*pskb)->mac.ethernet);
1818 +
1819 + if (skb->protocol == __constant_htons(ETH_P_IPV6) || IS_VLAN_IPV6) {
1820 +#ifdef CONFIG_SYSCTL
1821 + if (!brnf_call_ip6tables)
1822 + return NF_ACCEPT;
1823 +#endif
1824 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
1825 + goto out;
1826 +
1827 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1828 + skb_pull(skb, VLAN_HLEN);
1829 + (skb)->nh.raw += VLAN_HLEN;
1830 + }
1831 + return br_nf_pre_routing_ipv6(hook, skb, in, out, okfn);
1832 + }
1833 +
1834 +#ifdef CONFIG_SYSCTL
1835 + if (!brnf_call_iptables)
1836 + return NF_ACCEPT;
1837 +#endif
1838 +
1839 + if (skb->protocol != __constant_htons(ETH_P_IP) && !IS_VLAN_IP)
1840 + return NF_ACCEPT;
1841 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
1842 + goto out;
1843 +
1844 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1845 + skb_pull(skb, VLAN_HLEN);
1846 + (skb)->nh.raw += VLAN_HLEN;
1847 + }
1848 +
1849 + if (!pskb_may_pull(skb, sizeof(struct iphdr)))
1850 + goto inhdr_error;
1851 +
1852 + iph = skb->nh.iph;
1853 + if (iph->ihl < 5 || iph->version != 4)
1854 + goto inhdr_error;
1855 +
1856 + if (!pskb_may_pull(skb, 4*iph->ihl))
1857 + goto inhdr_error;
1858 +
1859 + iph = skb->nh.iph;
1860 + if (ip_fast_csum((__u8 *)iph, iph->ihl) != 0)
1861 + goto inhdr_error;
1862 +
1863 + len = ntohs(iph->tot_len);
1864 + if (skb->len < len || len < 4*iph->ihl)
1865 + goto inhdr_error;
1866 +
1867 + if (skb->len > len) {
1868 + __pskb_trim(skb, len);
1869 + if (skb->ip_summed == CHECKSUM_HW)
1870 + skb->ip_summed = CHECKSUM_NONE;
1871 + }
1872 +
1873 +#ifdef CONFIG_NETFILTER_DEBUG
1874 + skb->nf_debug ^= (1 << NF_IP_PRE_ROUTING);
1875 +#endif
1876 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
1877 + return NF_DROP;
1878 +
1879 + setup_pre_routing(skb);
1880 + store_orig_dstaddr(skb);
1881 +
1882 + NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL,
1883 + br_nf_pre_routing_finish);
1884 +
1885 + return NF_STOLEN;
1886 +
1887 +inhdr_error:
1888 +// IP_INC_STATS_BH(IpInHdrErrors);
1889 +out:
1890 + return NF_DROP;
1891 +}
1892 +
1893 +
1894 +/* PF_BRIDGE/LOCAL_IN ************************************************/
1895 +/* The packet is locally destined, which requires a real
1896 + * dst_entry, so detach the fake one. On the way up, the
1897 + * packet would pass through PRE_ROUTING again (which already
1898 + * took place when the packet entered the bridge), but we
1899 + * register an IPv4 PRE_ROUTING 'sabotage' hook that will
1900 + * prevent this from happening.
1901 + */
1902 +static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff **pskb,
1903 + const struct net_device *in, const struct net_device *out,
1904 + int (*okfn)(struct sk_buff *))
1905 +{
1906 + struct sk_buff *skb = *pskb;
1907 +
1908 + if (skb->dst == (struct dst_entry *)&__fake_rtable) {
1909 + dst_release(skb->dst);
1910 + skb->dst = NULL;
1911 + }
1912 +
1913 + return NF_ACCEPT;
1914 +}
1915 +
1916 +/* PF_BRIDGE/FORWARD *************************************************/
1917 +static int br_nf_forward_finish(struct sk_buff *skb)
1918 +{
1919 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
1920 + struct net_device *in;
1921 +/* struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);*/
1922 +
1923 +#ifdef CONFIG_NETFILTER_DEBUG
1924 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
1925 +#endif
1926 +
1927 +/* if (skb->protocol != __constant_htons(ETH_P_ARP) && !IS_VLAN_ARP) {*/
1928 + in = nf_bridge->physindev;
1929 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
1930 + skb->pkt_type = PACKET_OTHERHOST;
1931 + nf_bridge->mask ^= BRNF_PKT_TYPE;
1932 + }
1933 +/* } else {
1934 + in = *((struct net_device **)(skb->cb));
1935 + }*/
1936 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1937 + skb_push(skb, VLAN_HLEN);
1938 + skb->nh.raw -= VLAN_HLEN;
1939 + }
1940 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_FORWARD, skb, in,
1941 + skb->dev, br_forward_finish, 1);
1942 + return 0;
1943 +}
1944 +
1945 +/* This is the 'purely bridged' case. For IP, we pass the packet to
1946 + * netfilter with indev and outdev set to the bridge device,
1947 + * but we are still able to filter on the 'real' indev/outdev
1948 + * because of the ipt_physdev.c module. For ARP, indev and outdev are the
1949 + * bridge ports.
1950 + */
1951 +static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb,
1952 + const struct net_device *in, const struct net_device *out,
1953 + int (*okfn)(struct sk_buff *))
1954 +{
1955 + struct sk_buff *skb = *pskb;
1956 + struct nf_bridge_info *nf_bridge;
1957 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1958 + int pf;
1959 +
1960 + if (!skb->nf_bridge)
1961 + return NF_ACCEPT;
1962 +
1963 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
1964 + pf = PF_INET;
1965 + else
1966 + pf = PF_INET6;
1967 +
1968 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1969 + skb_pull(*pskb, VLAN_HLEN);
1970 + (*pskb)->nh.raw += VLAN_HLEN;
1971 + }
1972 +
1973 +#ifdef CONFIG_NETFILTER_DEBUG
1974 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
1975 +#endif
1976 + nf_bridge = skb->nf_bridge;
1977 + if (skb->pkt_type == PACKET_OTHERHOST) {
1978 + skb->pkt_type = PACKET_HOST;
1979 + nf_bridge->mask |= BRNF_PKT_TYPE;
1980 + }
1981 +
1982 + /* The physdev module checks on this */
1983 + nf_bridge->mask |= BRNF_BRIDGED;
1984 + nf_bridge->physoutdev = skb->dev;
1985 +
1986 + NF_HOOK(pf, NF_IP_FORWARD, skb, bridge_parent(in),
1987 + bridge_parent(out), br_nf_forward_finish);
1988 +
1989 + return NF_STOLEN;
1990 +}
1991 +
1992 +/*
1993 +static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb,
1994 + const struct net_device *in, const struct net_device *out,
1995 + int (*okfn)(struct sk_buff *))
1996 +{
1997 + struct sk_buff *skb = *pskb;
1998 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1999 + struct net_device **d = (struct net_device **)(skb->cb);
2000 +
2001 + if (!brnf_call_arptables)
2002 + return NF_ACCEPT;
2003 +
2004 + if (skb->protocol != __constant_htons(ETH_P_ARP)) {
2005 + if (!IS_VLAN_ARP)
2006 + return NF_ACCEPT;
2007 + skb_pull(*pskb, VLAN_HLEN);
2008 + (*pskb)->nh.raw += VLAN_HLEN;
2009 + }
2010 +
2011 +#ifdef CONFIG_NETFILTER_DEBUG
2012 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
2013 +#endif
2014 +
2015 + if (skb->nh.arph->ar_pln != 4) {
2016 + if (IS_VLAN_ARP) {
2017 + skb_push(*pskb, VLAN_HLEN);
2018 + (*pskb)->nh.raw -= VLAN_HLEN;
2019 + }
2020 + return NF_ACCEPT;
2021 + }
2022 + *d = (struct net_device *)in;
2023 + NF_HOOK(NF_ARP, NF_ARP_FORWARD, skb, (struct net_device *)in,
2024 + (struct net_device *)out, br_nf_forward_finish);
2025 +
2026 + return NF_STOLEN;
2027 +}
2028 +*/
2029 +
2030 +/* PF_BRIDGE/LOCAL_OUT ***********************************************/
2031 +static int br_nf_local_out_finish(struct sk_buff *skb)
2032 +{
2033 +#ifdef CONFIG_NETFILTER_DEBUG
2034 + skb->nf_debug &= ~(1 << NF_BR_LOCAL_OUT);
2035 +#endif
2036 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2037 + skb_push(skb, VLAN_HLEN);
2038 + skb->nh.raw -= VLAN_HLEN;
2039 + }
2040 +
2041 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
2042 + br_forward_finish, NF_BR_PRI_FIRST + 1);
2043 +
2044 + return 0;
2045 +}
2046 +
2047 +
2048 +/* This function sees both locally originated IP packets and forwarded
2049 + * IP packets (in both cases the destination device is a bridge
2050 + * device). It also sees bridged-and-DNAT'ed packets.
2051 + * To be able to filter on the physical bridge devices (with the ipt_physdev.c
2052 + * module), we steal packets destined to a bridge device away from the
2053 + * PF_INET/FORWARD and PF_INET/OUTPUT hook functions, and give them back later,
2054 + * when we have determined the real output device. This is done in here.
2055 + *
2056 + * If (nf_bridge->mask & BRNF_BRIDGED_DNAT) then the packet is bridged
2057 + * and we fake the PF_BRIDGE/FORWARD hook. The function br_nf_forward()
2058 + * will then fake the PF_INET/FORWARD hook. br_nf_local_out() has priority
2059 + * NF_BR_PRI_FIRST, so no relevant PF_BRIDGE/INPUT functions have been nor
2060 + * will be executed.
2061 + * Otherwise, if nf_bridge->physindev is NULL, the bridge-nf code never touched
2062 + * this packet before, and so the packet was locally originated. We fake
2063 + * the PF_INET/LOCAL_OUT hook.
2064 + * Finally, if nf_bridge->physindev isn't NULL, then the packet was IP routed,
2065 + * so we fake the PF_INET/FORWARD hook. ipv4_sabotage_out() makes sure
2066 + * even routed packets that didn't arrive on a bridge interface have their
2067 + * nf_bridge->physindev set.
2068 + */
2069 +
2070 +static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb,
2071 + const struct net_device *in, const struct net_device *out,
2072 + int (*okfn)(struct sk_buff *))
2073 +{
2074 + struct net_device *realindev, *realoutdev;
2075 + struct sk_buff *skb = *pskb;
2076 + struct nf_bridge_info *nf_bridge;
2077 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
2078 + int pf;
2079 +
2080 + if (!skb->nf_bridge)
2081 + return NF_ACCEPT;
2082 +
2083 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
2084 + pf = PF_INET;
2085 + else
2086 + pf = PF_INET6;
2087 +
2088 +#ifdef CONFIG_NETFILTER_DEBUG
2089 + /* Sometimes we get packets with NULL ->dst here (for example,
2090 + * running a dhcp client daemon triggers this). This should now
2091 + * be fixed, but let's keep the check around. */
2092 + if (skb->dst == NULL) {
2093 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
2094 + return NF_ACCEPT;
2095 + }
2096 +#endif
2097 +
2098 + nf_bridge = skb->nf_bridge;
2099 + nf_bridge->physoutdev = skb->dev;
2100 + realindev = nf_bridge->physindev;
2101 +
2102 + /* Bridged, take PF_BRIDGE/FORWARD.
2103 + * (see big note in front of br_nf_pre_routing_finish)
2104 + */
2105 + if (nf_bridge->mask & BRNF_BRIDGED_DNAT) {
2106 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
2107 + skb->pkt_type = PACKET_OTHERHOST;
2108 + nf_bridge->mask ^= BRNF_PKT_TYPE;
2109 + }
2110 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2111 + skb_push(skb, VLAN_HLEN);
2112 + skb->nh.raw -= VLAN_HLEN;
2113 + }
2114 +
2115 + NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, realindev,
2116 + skb->dev, br_forward_finish);
2117 + goto out;
2118 + }
2119 + realoutdev = bridge_parent(skb->dev);
2120 +
2121 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
2122 + /* iptables should match -o br0.x */
2123 + if (nf_bridge->netoutdev)
2124 + realoutdev = nf_bridge->netoutdev;
2125 +#endif
2126 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2127 + skb_pull(skb, VLAN_HLEN);
2128 + (*pskb)->nh.raw += VLAN_HLEN;
2129 + }
2130 + /* IP forwarded traffic has a physindev, locally
2131 + * generated traffic hasn't.
2132 + */
2133 + if (realindev != NULL) {
2134 + if (((nf_bridge->mask & BRNF_DONT_TAKE_PARENT) == 0) &&
2135 + has_bridge_parent(realindev))
2136 + realindev = bridge_parent(realindev);
2137 + NF_HOOK_THRESH(pf, NF_IP_FORWARD, skb, realindev,
2138 + realoutdev, okfn,
2139 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD + 1);
2140 + } else {
2141 +#ifdef CONFIG_NETFILTER_DEBUG
2142 + skb->nf_debug ^= (1 << NF_IP_LOCAL_OUT);
2143 +#endif
2144 +
2145 + NF_HOOK_THRESH(pf, NF_IP_LOCAL_OUT, skb, realindev,
2146 + realoutdev, okfn,
2147 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT + 1);
2148 + }
2149 +
2150 +out:
2151 + return NF_STOLEN;
2152 +}
2153 +
2154 +
2155 +/* PF_BRIDGE/POST_ROUTING ********************************************/
2156 +static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
2157 + const struct net_device *in, const struct net_device *out,
2158 + int (*okfn)(struct sk_buff *))
2159 +{
2160 + struct sk_buff *skb = *pskb;
2161 + struct nf_bridge_info *nf_bridge = (*pskb)->nf_bridge;
2162 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
2163 + struct net_device *realoutdev = bridge_parent(skb->dev);
2164 + int pf;
2165 +
2166 +#ifdef CONFIG_NETFILTER_DEBUG
2167 + /* Be very paranoid. This probably won't happen anymore, but let's
2168 + * keep the check just to be sure... */
2169 + if (skb->mac.raw < skb->head || skb->mac.raw + ETH_HLEN > skb->data) {
2170 + printk(KERN_CRIT "br_netfilter: Argh!! br_nf_post_routing: "
2171 + "bad mac.raw pointer.");
2172 + goto print_error;
2173 + }
2174 +#endif
2175 +
2176 + if (!nf_bridge)
2177 + return NF_ACCEPT;
2178 +
2179 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
2180 + pf = PF_INET;
2181 + else
2182 + pf = PF_INET6;
2183 +
2184 + /* Sometimes we get packets with NULL ->dst here (for example,
2185 + * running a dhcp client daemon triggers this).
2186 + */
2187 + if (skb->dst == NULL)
2188 + return NF_ACCEPT;
2189 +
2190 +#ifdef CONFIG_NETFILTER_DEBUG
2191 + /* Sometimes we get packets with NULL ->dst here (for example,
2192 + * running a dhcp client daemon triggers this). This should now
2193 + * be fixed, but let's keep the check around.
2194 + */
2195 + if (skb->dst == NULL) {
2196 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
2197 + goto print_error;
2198 + }
2199 +
2200 + skb->nf_debug ^= (1 << NF_IP_POST_ROUTING);
2201 +#endif
2202 +
2203 + /* We assume any code from br_dev_queue_push_xmit onwards doesn't care
2204 + * about the value of skb->pkt_type.
2205 + */
2206 + if (skb->pkt_type == PACKET_OTHERHOST) {
2207 + skb->pkt_type = PACKET_HOST;
2208 + nf_bridge->mask |= BRNF_PKT_TYPE;
2209 + }
2210 +
2211 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2212 + skb_pull(skb, VLAN_HLEN);
2213 + skb->nh.raw += VLAN_HLEN;
2214 + }
2215 +
2216 + nf_bridge_save_header(skb);
2217 +
2218 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
2219 + if (nf_bridge->netoutdev)
2220 + realoutdev = nf_bridge->netoutdev;
2221 +#endif
2222 + NF_HOOK(pf, NF_IP_POST_ROUTING, skb, NULL,
2223 + realoutdev, br_dev_queue_push_xmit);
2224 +
2225 + return NF_STOLEN;
2226 +
2227 +#ifdef CONFIG_NETFILTER_DEBUG
2228 +print_error:
2229 + if (skb->dev != NULL) {
2230 + printk("[%s]", skb->dev->name);
2231 + if (has_bridge_parent(skb->dev))
2232 + printk("[%s]", bridge_parent(skb->dev)->name);
2233 + }
2234 + printk(" head:%p, raw:%p, data:%p\n", skb->head, skb->mac.raw,
2235 + skb->data);
2236 + return NF_ACCEPT;
2237 +#endif
2238 +}
2239 +
2240 +
2241 +/* IPv4/SABOTAGE *****************************************************/
2242 +
2243 +/* Don't hand locally destined packets to PF_INET/PRE_ROUTING
2244 + * for the second time.
2245 + */
2246 +static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff **pskb,
2247 + const struct net_device *in, const struct net_device *out,
2248 + int (*okfn)(struct sk_buff *))
2249 +{
2250 + if ((*pskb)->nf_bridge &&
2251 + !((*pskb)->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
2252 + return NF_STOP;
2253 + }
2254 +
2255 + return NF_ACCEPT;
2256 +}
2257 +
2258 +/* Postpone execution of PF_INET/FORWARD, PF_INET/LOCAL_OUT
2259 + * and PF_INET/POST_ROUTING until we have done the forwarding
2260 + * decision in the bridge code and have determined skb->physoutdev.
2261 + */
2262 +static unsigned int ip_sabotage_out(unsigned int hook, struct sk_buff **pskb,
2263 + const struct net_device *in, const struct net_device *out,
2264 + int (*okfn)(struct sk_buff *))
2265 +{
2266 + struct sk_buff *skb = *pskb;
2267 +
2268 + if ((out->hard_start_xmit == br_dev_xmit &&
2269 + okfn != br_nf_forward_finish &&
2270 + okfn != br_nf_local_out_finish &&
2271 + okfn != br_dev_queue_push_xmit)
2272 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
2273 + || ((out->priv_flags & IFF_802_1Q_VLAN) &&
2274 + VLAN_DEV_INFO(out)->real_dev->hard_start_xmit == br_dev_xmit)
2275 +#endif
2276 + ) {
2277 + struct nf_bridge_info *nf_bridge;
2278 +
2279 + if (!skb->nf_bridge) {
2280 +#ifdef CONFIG_SYSCTL
2281 + /* This code is executed while in the IP(v6) stack,
2282 + the version should be 4 or 6. We can't use
2283 + skb->protocol because that isn't set on
2284 + PF_INET(6)/LOCAL_OUT. */
2285 + struct iphdr *ip = skb->nh.iph;
2286 +
2287 + if (ip->version == 4 && !brnf_call_iptables)
2288 + return NF_ACCEPT;
2289 + else if (ip->version == 6 && !brnf_call_ip6tables)
2290 + return NF_ACCEPT;
2291 +#endif
2292 + if (hook == NF_IP_POST_ROUTING)
2293 + return NF_ACCEPT;
2294 + if (!nf_bridge_alloc(skb))
2295 + return NF_DROP;
2296 + }
2297 +
2298 + nf_bridge = skb->nf_bridge;
2299 +
2300 + /* This frame will arrive on PF_BRIDGE/LOCAL_OUT and we
2301 + * will need the indev then. For a brouter, the real indev
2302 + * can be a bridge port, so we make sure br_nf_local_out()
2303 + * doesn't use the bridge parent of the indev by using
2304 + * the BRNF_DONT_TAKE_PARENT mask.
2305 + */
2306 + if (hook == NF_IP_FORWARD && nf_bridge->physindev == NULL) {
2307 + nf_bridge->mask &= BRNF_DONT_TAKE_PARENT;
2308 + nf_bridge->physindev = (struct net_device *)in;
2309 + }
2310 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
2311 + /* the iptables outdev is br0.x, not br0 */
2312 + if (out->priv_flags & IFF_802_1Q_VLAN)
2313 + nf_bridge->netoutdev = (struct net_device *)out;
2314 +#endif
2315 + return NF_STOP;
2316 + }
2317 +
2318 + return NF_ACCEPT;
2319 +}
2320 +
2321 +/* For br_nf_local_out we need (prio = NF_BR_PRI_FIRST), to insure that innocent
2322 + * PF_BRIDGE/NF_BR_LOCAL_OUT functions don't get bridged traffic as input.
2323 + * For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because
2324 + * ip_refrag() can return NF_STOLEN.
2325 + */
2326 +static struct nf_hook_ops br_nf_ops[] = {
2327 + { .hook = br_nf_pre_routing,
2328 + .pf = PF_BRIDGE,
2329 + .hooknum = NF_BR_PRE_ROUTING,
2330 + .priority = NF_BR_PRI_BRNF, },
2331 + { .hook = br_nf_local_in,
2332 + .pf = PF_BRIDGE,
2333 + .hooknum = NF_BR_LOCAL_IN,
2334 + .priority = NF_BR_PRI_BRNF, },
2335 + { .hook = br_nf_forward_ip,
2336 + .pf = PF_BRIDGE,
2337 + .hooknum = NF_BR_FORWARD,
2338 + .priority = NF_BR_PRI_BRNF /*- 1*/, },
2339 +/* { .hook = br_nf_forward_arp,
2340 + .pf = PF_BRIDGE,
2341 + .hooknum = NF_BR_FORWARD,
2342 + .priority = NF_BR_PRI_BRNF, },*/
2343 + { .hook = br_nf_local_out,
2344 + .pf = PF_BRIDGE,
2345 + .hooknum = NF_BR_LOCAL_OUT,
2346 + .priority = NF_BR_PRI_FIRST, },
2347 + { .hook = br_nf_post_routing,
2348 + .pf = PF_BRIDGE,
2349 + .hooknum = NF_BR_POST_ROUTING,
2350 + .priority = NF_BR_PRI_LAST, },
2351 + { .hook = ip_sabotage_in,
2352 + .pf = PF_INET,
2353 + .hooknum = NF_IP_PRE_ROUTING,
2354 + .priority = NF_IP_PRI_FIRST, },
2355 + { .hook = ip_sabotage_in,
2356 + .pf = PF_INET6,
2357 + .hooknum = NF_IP6_PRE_ROUTING,
2358 + .priority = NF_IP6_PRI_FIRST, },
2359 + { .hook = ip_sabotage_out,
2360 + .pf = PF_INET,
2361 + .hooknum = NF_IP_FORWARD,
2362 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD, },
2363 + { .hook = ip_sabotage_out,
2364 + .pf = PF_INET6,
2365 + .hooknum = NF_IP6_FORWARD,
2366 + .priority = NF_IP6_PRI_BRIDGE_SABOTAGE_FORWARD, },
2367 + { .hook = ip_sabotage_out,
2368 + .pf = PF_INET,
2369 + .hooknum = NF_IP_LOCAL_OUT,
2370 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
2371 + { .hook = ip_sabotage_out,
2372 + .pf = PF_INET6,
2373 + .hooknum = NF_IP6_LOCAL_OUT,
2374 + .priority = NF_IP6_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
2375 + { .hook = ip_sabotage_out,
2376 + .pf = PF_INET,
2377 + .hooknum = NF_IP_POST_ROUTING,
2378 + .priority = NF_IP_PRI_FIRST, },
2379 + { .hook = ip_sabotage_out,
2380 + .pf = PF_INET6,
2381 + .hooknum = NF_IP6_POST_ROUTING,
2382 + .priority = NF_IP6_PRI_FIRST, },
2383 +};
2384 +
2385 +#ifdef CONFIG_SYSCTL
2386 +static
2387 +int brnf_sysctl_call_tables(ctl_table *ctl, int write, struct file * filp,
2388 + void *buffer, size_t *lenp)
2389 +{
2390 + int ret;
2391 +
2392 + ret = proc_dointvec(ctl, write, filp, buffer, lenp);
2393 +
2394 + if (write && *(int *)(ctl->data))
2395 + *(int *)(ctl->data) = 1;
2396 + return ret;
2397 +}
2398 +
2399 +static ctl_table brnf_table[] = {
2400 + {
2401 + .ctl_name = NET_BRIDGE_NF_CALL_ARPTABLES,
2402 + .procname = "bridge-nf-call-arptables",
2403 + .data = &brnf_call_arptables,
2404 + .maxlen = sizeof(int),
2405 + .mode = 0644,
2406 + .proc_handler = &brnf_sysctl_call_tables,
2407 + },
2408 + {
2409 + .ctl_name = NET_BRIDGE_NF_CALL_IPTABLES,
2410 + .procname = "bridge-nf-call-iptables",
2411 + .data = &brnf_call_iptables,
2412 + .maxlen = sizeof(int),
2413 + .mode = 0644,
2414 + .proc_handler = &brnf_sysctl_call_tables,
2415 + },
2416 + {
2417 + .ctl_name = NET_BRIDGE_NF_CALL_IP6TABLES,
2418 + .procname = "bridge-nf-call-ip6tables",
2419 + .data = &brnf_call_ip6tables,
2420 + .maxlen = sizeof(int),
2421 + .mode = 0644,
2422 + .proc_handler = &brnf_sysctl_call_tables,
2423 + },
2424 + {
2425 + .ctl_name = NET_BRIDGE_NF_FILTER_VLAN_TAGGED,
2426 + .procname = "bridge-nf-filter-vlan-tagged",
2427 + .data = &brnf_filter_vlan_tagged,
2428 + .maxlen = sizeof(int),
2429 + .mode = 0644,
2430 + .proc_handler = &brnf_sysctl_call_tables,
2431 + },
2432 + { .ctl_name = 0 }
2433 +};
2434 +
2435 +static ctl_table brnf_bridge_table[] = {
2436 + {
2437 + .ctl_name = NET_BRIDGE,
2438 + .procname = "bridge",
2439 + .mode = 0555,
2440 + .child = brnf_table,
2441 + },
2442 + { .ctl_name = 0 }
2443 +};
2444 +
2445 +static ctl_table brnf_net_table[] = {
2446 + {
2447 + .ctl_name = CTL_NET,
2448 + .procname = "net",
2449 + .mode = 0555,
2450 + .child = brnf_bridge_table,
2451 + },
2452 + { .ctl_name = 0 }
2453 +};
2454 +#endif
2455 +
2456 +int br_netfilter_init(void)
2457 +{
2458 + int i;
2459 +
2460 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++) {
2461 + int ret;
2462 +
2463 + if ((ret = nf_register_hook(&br_nf_ops[i])) >= 0)
2464 + continue;
2465 +
2466 + while (i--)
2467 + nf_unregister_hook(&br_nf_ops[i]);
2468 +
2469 + return ret;
2470 + }
2471 +
2472 +#ifdef CONFIG_SYSCTL
2473 + brnf_sysctl_header = register_sysctl_table(brnf_net_table, 0);
2474 + if (brnf_sysctl_header == NULL) {
2475 + printk(KERN_WARNING "br_netfilter: can't register to sysctl.\n");
2476 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++)
2477 + nf_unregister_hook(&br_nf_ops[i]);
2478 + return -EFAULT;
2479 + }
2480 +#endif
2481 +
2482 + printk(KERN_NOTICE "Bridge firewalling registered\n");
2483 +
2484 + return 0;
2485 +}
2486 +
2487 +void br_netfilter_fini(void)
2488 +{
2489 + int i;
2490 +
2491 + for (i = ARRAY_SIZE(br_nf_ops) - 1; i >= 0; i--)
2492 + nf_unregister_hook(&br_nf_ops[i]);
2493 +#ifdef CONFIG_SYSCTL
2494 + unregister_sysctl_table(brnf_sysctl_header);
2495 +#endif
2496 +
2497 +}
2498 +
2499 +EXPORT_NO_SYMBOLS;
2500 +EXPORT_SYMBOL(br_netfilter_init);
2501 +EXPORT_SYMBOL(br_netfilter_fini);
2502 diff -Nur linux.old/net/bridge/br_private.h linux.dev/net/bridge/br_private.h
2503 --- linux.old/net/bridge/br_private.h 2004-08-08 01:26:06.000000000 +0200
2504 +++ linux.dev/net/bridge/br_private.h 2005-10-10 10:36:45.913858250 +0200
2505 @@ -143,8 +143,10 @@
2506 /* br_forward.c */
2507 extern void br_deliver(struct net_bridge_port *to,
2508 struct sk_buff *skb);
2509 +extern int br_dev_queue_push_xmit(struct sk_buff *skb);
2510 extern void br_forward(struct net_bridge_port *to,
2511 struct sk_buff *skb);
2512 +extern int br_forward_finish(struct sk_buff *skb);
2513 extern void br_flood_deliver(struct net_bridge *br,
2514 struct sk_buff *skb,
2515 int clone);
2516 @@ -165,7 +167,8 @@
2517 int *ifindices);
2518
2519 /* br_input.c */
2520 -extern void br_handle_frame(struct sk_buff *skb);
2521 +extern int br_handle_frame_finish(struct sk_buff *skb);
2522 +extern int br_handle_frame(struct sk_buff *skb);
2523
2524 /* br_ioctl.c */
2525 extern int br_ioctl(struct net_bridge *br,
2526 @@ -175,6 +178,10 @@
2527 unsigned long arg2);
2528 extern int br_ioctl_deviceless_stub(unsigned long arg);
2529
2530 +/* br_netfilter.c */
2531 +extern int br_netfilter_init(void);
2532 +extern void br_netfilter_fini(void);
2533 +
2534 /* br_stp.c */
2535 extern int br_is_root_bridge(struct net_bridge *br);
2536 extern struct net_bridge_port *br_get_port(struct net_bridge *br,
2537 diff -Nur linux.old/net/bridge/netfilter/Config.in linux.dev/net/bridge/netfilter/Config.in
2538 --- linux.old/net/bridge/netfilter/Config.in 1970-01-01 01:00:00.000000000 +0100
2539 +++ linux.dev/net/bridge/netfilter/Config.in 2005-10-10 10:36:46.089869250 +0200
2540 @@ -0,0 +1,23 @@
2541 +#
2542 +# Bridge netfilter configuration
2543 +#
2544 +dep_tristate ' Bridge: ebtables' CONFIG_BRIDGE_NF_EBTABLES $CONFIG_BRIDGE
2545 +dep_tristate ' ebt: filter table support' CONFIG_BRIDGE_EBT_T_FILTER $CONFIG_BRIDGE_NF_EBTABLES
2546 +dep_tristate ' ebt: nat table support' CONFIG_BRIDGE_EBT_T_NAT $CONFIG_BRIDGE_NF_EBTABLES
2547 +dep_tristate ' ebt: broute table support' CONFIG_BRIDGE_EBT_BROUTE $CONFIG_BRIDGE_NF_EBTABLES
2548 +dep_tristate ' ebt: log support' CONFIG_BRIDGE_EBT_LOG $CONFIG_BRIDGE_NF_EBTABLES
2549 +dep_tristate ' ebt: ulog support' CONFIG_BRIDGE_EBT_LOG $CONFIG_BRIDGE_NF_EBTABLES
2550 +dep_tristate ' ebt: IP filter support' CONFIG_BRIDGE_EBT_IPF $CONFIG_BRIDGE_NF_EBTABLES
2551 +dep_tristate ' ebt: ARP filter support' CONFIG_BRIDGE_EBT_ARPF $CONFIG_BRIDGE_NF_EBTABLES
2552 +dep_tristate ' ebt: among filter support' CONFIG_BRIDGE_EBT_AMONG $CONFIG_BRIDGE_NF_EBTABLES
2553 +dep_tristate ' ebt: limit filter support' CONFIG_BRIDGE_EBT_LIMIT $CONFIG_BRIDGE_NF_EBTABLES
2554 +dep_tristate ' ebt: 802.1Q VLAN filter support' CONFIG_BRIDGE_EBT_VLANF $CONFIG_BRIDGE_NF_EBTABLES
2555 +dep_tristate ' ebt: 802.3 filter support' CONFIG_BRIDGE_EBT_802_3 $CONFIG_BRIDGE_NF_EBTABLES
2556 +dep_tristate ' ebt: packet type filter support' CONFIG_BRIDGE_EBT_PKTTYPE $CONFIG_BRIDGE_NF_EBTABLES
2557 +dep_tristate ' ebt: STP filter support' CONFIG_BRIDGE_EBT_STP $CONFIG_BRIDGE_NF_EBTABLES
2558 +dep_tristate ' ebt: mark filter support' CONFIG_BRIDGE_EBT_MARKF $CONFIG_BRIDGE_NF_EBTABLES
2559 +dep_tristate ' ebt: arp reply target support' CONFIG_BRIDGE_EBT_ARPREPLY $CONFIG_BRIDGE_NF_EBTABLES
2560 +dep_tristate ' ebt: snat target support' CONFIG_BRIDGE_EBT_SNAT $CONFIG_BRIDGE_NF_EBTABLES
2561 +dep_tristate ' ebt: dnat target support' CONFIG_BRIDGE_EBT_DNAT $CONFIG_BRIDGE_NF_EBTABLES
2562 +dep_tristate ' ebt: redirect target support' CONFIG_BRIDGE_EBT_REDIRECT $CONFIG_BRIDGE_NF_EBTABLES
2563 +dep_tristate ' ebt: mark target support' CONFIG_BRIDGE_EBT_MARK_T $CONFIG_BRIDGE_NF_EBTABLES
2564 diff -Nur linux.old/net/bridge/netfilter/Makefile linux.dev/net/bridge/netfilter/Makefile
2565 --- linux.old/net/bridge/netfilter/Makefile 1970-01-01 01:00:00.000000000 +0100
2566 +++ linux.dev/net/bridge/netfilter/Makefile 2005-10-10 10:36:46.089869250 +0200
2567 @@ -0,0 +1,34 @@
2568 +#
2569 +# Makefile for the netfilter modules on top of bridging.
2570 +#
2571 +# Note! Dependencies are done automagically by 'make dep', which also
2572 +# removes any old dependencies. DON'T put your own dependencies here
2573 +# unless it's something special (ie not a .c file).
2574 +#
2575 +# Note 2! The CFLAGS definition is now in the main makefile...
2576 +
2577 +O_TARGET := netfilter.o
2578 +
2579 +export-objs := ebtables.o
2580 +
2581 +obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o
2582 +obj-$(CONFIG_BRIDGE_EBT_T_FILTER) += ebtable_filter.o
2583 +obj-$(CONFIG_BRIDGE_EBT_T_NAT) += ebtable_nat.o
2584 +obj-$(CONFIG_BRIDGE_EBT_BROUTE) += ebtable_broute.o
2585 +obj-$(CONFIG_BRIDGE_EBT_802_3) += ebt_802_3.o
2586 +obj-$(CONFIG_BRIDGE_EBT_ARPF) += ebt_arp.o
2587 +obj-$(CONFIG_BRIDGE_EBT_AMONG) += ebt_among.o
2588 +obj-$(CONFIG_BRIDGE_EBT_IPF) += ebt_ip.o
2589 +obj-$(CONFIG_BRIDGE_EBT_LIMIT) += ebt_limit.o
2590 +obj-$(CONFIG_BRIDGE_EBT_MARKF) += ebt_mark_m.o
2591 +obj-$(CONFIG_BRIDGE_EBT_PKTTYPE) += ebt_pkttype.o
2592 +obj-$(CONFIG_BRIDGE_EBT_STP) += ebt_stp.o
2593 +obj-$(CONFIG_BRIDGE_EBT_VLANF) += ebt_vlan.o
2594 +obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_log.o
2595 +obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_ulog.o
2596 +obj-$(CONFIG_BRIDGE_EBT_ARPREPLY) += ebt_arpreply.o
2597 +obj-$(CONFIG_BRIDGE_EBT_DNAT) += ebt_dnat.o
2598 +obj-$(CONFIG_BRIDGE_EBT_MARK_T) += ebt_mark.o
2599 +obj-$(CONFIG_BRIDGE_EBT_REDIRECT) += ebt_redirect.o
2600 +obj-$(CONFIG_BRIDGE_EBT_SNAT) += ebt_snat.o
2601 +include $(TOPDIR)/Rules.make
2602 diff -Nur linux.old/net/bridge/netfilter/ebt_802_3.c linux.dev/net/bridge/netfilter/ebt_802_3.c
2603 --- linux.old/net/bridge/netfilter/ebt_802_3.c 1970-01-01 01:00:00.000000000 +0100
2604 +++ linux.dev/net/bridge/netfilter/ebt_802_3.c 2005-10-10 10:36:46.089869250 +0200
2605 @@ -0,0 +1,74 @@
2606 +/*
2607 + * 802_3
2608 + *
2609 + * Author:
2610 + * Chris Vitale csv@bluetail.com
2611 + *
2612 + * May 2003
2613 + *
2614 + */
2615 +
2616 +#include <linux/netfilter_bridge/ebtables.h>
2617 +#include <linux/netfilter_bridge/ebt_802_3.h>
2618 +#include <linux/module.h>
2619 +
2620 +static int ebt_filter_802_3(const struct sk_buff *skb, const struct net_device *in,
2621 + const struct net_device *out, const void *data, unsigned int datalen)
2622 +{
2623 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
2624 + struct ebt_802_3_hdr *hdr = (struct ebt_802_3_hdr *)skb->mac.ethernet;
2625 + uint16_t type = hdr->llc.ui.ctrl & IS_UI ? hdr->llc.ui.type : hdr->llc.ni.type;
2626 +
2627 + if (info->bitmask & EBT_802_3_SAP) {
2628 + if (FWINV(info->sap != hdr->llc.ui.ssap, EBT_802_3_SAP))
2629 + return EBT_NOMATCH;
2630 + if (FWINV(info->sap != hdr->llc.ui.dsap, EBT_802_3_SAP))
2631 + return EBT_NOMATCH;
2632 + }
2633 +
2634 + if (info->bitmask & EBT_802_3_TYPE) {
2635 + if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
2636 + return EBT_NOMATCH;
2637 + if (FWINV(info->type != type, EBT_802_3_TYPE))
2638 + return EBT_NOMATCH;
2639 + }
2640 +
2641 + return EBT_MATCH;
2642 +}
2643 +
2644 +static struct ebt_match filter_802_3;
2645 +static int ebt_802_3_check(const char *tablename, unsigned int hookmask,
2646 + const struct ebt_entry *e, void *data, unsigned int datalen)
2647 +{
2648 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
2649 +
2650 + if (datalen != EBT_ALIGN(sizeof(struct ebt_802_3_info)))
2651 + return -EINVAL;
2652 + if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
2653 + return -EINVAL;
2654 +
2655 + return 0;
2656 +}
2657 +
2658 +static struct ebt_match filter_802_3 =
2659 +{
2660 + .name = EBT_802_3_MATCH,
2661 + .match = ebt_filter_802_3,
2662 + .check = ebt_802_3_check,
2663 + .me = THIS_MODULE,
2664 +};
2665 +
2666 +static int __init init(void)
2667 +{
2668 + return ebt_register_match(&filter_802_3);
2669 +}
2670 +
2671 +static void __exit fini(void)
2672 +{
2673 + ebt_unregister_match(&filter_802_3);
2674 +}
2675 +
2676 +module_init(init);
2677 +module_exit(fini);
2678 +EXPORT_NO_SYMBOLS;
2679 +MODULE_LICENSE("GPL");
2680 diff -Nur linux.old/net/bridge/netfilter/ebt_among.c linux.dev/net/bridge/netfilter/ebt_among.c
2681 --- linux.old/net/bridge/netfilter/ebt_among.c 1970-01-01 01:00:00.000000000 +0100
2682 +++ linux.dev/net/bridge/netfilter/ebt_among.c 2005-10-10 10:36:46.089869250 +0200
2683 @@ -0,0 +1,223 @@
2684 +/*
2685 + * ebt_among
2686 + *
2687 + * Authors:
2688 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
2689 + *
2690 + * August, 2003
2691 + *
2692 + */
2693 +
2694 +#include <linux/netfilter_bridge/ebtables.h>
2695 +#include <linux/netfilter_bridge/ebt_among.h>
2696 +#include <linux/ip.h>
2697 +#include <linux/if_arp.h>
2698 +#include <linux/module.h>
2699 +
2700 +static int ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh,
2701 + const char *mac, uint32_t ip)
2702 +{
2703 + /* You may be puzzled as to how this code works.
2704 + * Some tricks were used, refer to
2705 + * include/linux/netfilter_bridge/ebt_among.h
2706 + * as there you can find a solution of this mystery.
2707 + */
2708 + const struct ebt_mac_wormhash_tuple *p;
2709 + int start, limit, i;
2710 + uint32_t cmp[2] = { 0, 0 };
2711 + int key = (const unsigned char) mac[5];
2712 +
2713 + memcpy(((char *) cmp) + 2, mac, 6);
2714 + start = wh->table[key];
2715 + limit = wh->table[key + 1];
2716 + if (ip) {
2717 + for (i = start; i < limit; i++) {
2718 + p = &wh->pool[i];
2719 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
2720 + if (p->ip == 0 || p->ip == ip) {
2721 + return 1;
2722 + }
2723 + }
2724 + }
2725 + } else {
2726 + for (i = start; i < limit; i++) {
2727 + p = &wh->pool[i];
2728 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
2729 + if (p->ip == 0) {
2730 + return 1;
2731 + }
2732 + }
2733 + }
2734 + }
2735 + return 0;
2736 +}
2737 +
2738 +static int ebt_mac_wormhash_check_integrity(const struct ebt_mac_wormhash
2739 + *wh)
2740 +{
2741 + int i;
2742 +
2743 + for (i = 0; i < 256; i++) {
2744 + if (wh->table[i] > wh->table[i + 1])
2745 + return -0x100 - i;
2746 + if (wh->table[i] < 0)
2747 + return -0x200 - i;
2748 + if (wh->table[i] > wh->poolsize)
2749 + return -0x300 - i;
2750 + }
2751 + if (wh->table[256] > wh->poolsize)
2752 + return -0xc00;
2753 + return 0;
2754 +}
2755 +
2756 +static int get_ip_dst(const struct sk_buff *skb, uint32_t * addr)
2757 +{
2758 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
2759 + *addr = skb->nh.iph->daddr;
2760 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
2761 + uint32_t arp_len = sizeof(struct arphdr) +
2762 + (2 * (((*skb).nh.arph)->ar_hln)) +
2763 + (2 * (((*skb).nh.arph)->ar_pln));
2764 +
2765 + /* Make sure the packet is long enough. */
2766 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2767 + return -1;
2768 + /* IPv4 addresses are always 4 bytes. */
2769 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
2770 + return -1;
2771 +
2772 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
2773 + (2 * (((*skb).nh.arph)->ar_hln)) +
2774 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
2775 +
2776 + }
2777 + return 0;
2778 +}
2779 +
2780 +static int get_ip_src(const struct sk_buff *skb, uint32_t * addr)
2781 +{
2782 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
2783 + *addr = skb->nh.iph->saddr;
2784 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
2785 + uint32_t arp_len = sizeof(struct arphdr) +
2786 + (2 * (((*skb).nh.arph)->ar_hln)) +
2787 + (2 * (((*skb).nh.arph)->ar_pln));
2788 +
2789 + /* Make sure the packet is long enough. */
2790 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2791 + return -1;
2792 + /* IPv4 addresses are always 4 bytes. */
2793 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
2794 + return -1;
2795 +
2796 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
2797 + ((((*skb).nh.arph)->ar_hln)), sizeof(uint32_t));
2798 +
2799 + }
2800 + return 0;
2801 +}
2802 +
2803 +static int ebt_filter_among(const struct sk_buff *skb,
2804 + const struct net_device *in,
2805 + const struct net_device *out, const void *data,
2806 + unsigned int datalen)
2807 +{
2808 + struct ebt_among_info *info = (struct ebt_among_info *) data;
2809 + const char *dmac, *smac;
2810 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
2811 + uint32_t dip = 0, sip = 0;
2812 +
2813 + wh_dst = ebt_among_wh_dst(info);
2814 + wh_src = ebt_among_wh_src(info);
2815 +
2816 + if (wh_src) {
2817 + smac = skb->mac.ethernet->h_source;
2818 + if (get_ip_src(skb, &sip))
2819 + return EBT_NOMATCH;
2820 + if (!(info->bitmask & EBT_AMONG_SRC_NEG)) {
2821 + /* we match only if it contains */
2822 + if (!ebt_mac_wormhash_contains(wh_src, smac, sip))
2823 + return EBT_NOMATCH;
2824 + } else {
2825 + /* we match only if it DOES NOT contain */
2826 + if (ebt_mac_wormhash_contains(wh_src, smac, sip))
2827 + return EBT_NOMATCH;
2828 + }
2829 + }
2830 +
2831 + if (wh_dst) {
2832 + dmac = skb->mac.ethernet->h_dest;
2833 + if (get_ip_dst(skb, &dip))
2834 + return EBT_NOMATCH;
2835 + if (!(info->bitmask & EBT_AMONG_DST_NEG)) {
2836 + /* we match only if it contains */
2837 + if (!ebt_mac_wormhash_contains(wh_dst, dmac, dip))
2838 + return EBT_NOMATCH;
2839 + } else {
2840 + /* we match only if it DOES NOT contain */
2841 + if (ebt_mac_wormhash_contains(wh_dst, dmac, dip))
2842 + return EBT_NOMATCH;
2843 + }
2844 + }
2845 +
2846 + return EBT_MATCH;
2847 +}
2848 +
2849 +static int ebt_among_check(const char *tablename, unsigned int hookmask,
2850 + const struct ebt_entry *e, void *data,
2851 + unsigned int datalen)
2852 +{
2853 + struct ebt_among_info *info = (struct ebt_among_info *) data;
2854 + int expected_length = sizeof(struct ebt_among_info);
2855 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
2856 + int err;
2857 +
2858 + wh_dst = ebt_among_wh_dst(info);
2859 + wh_src = ebt_among_wh_src(info);
2860 + expected_length += ebt_mac_wormhash_size(wh_dst);
2861 + expected_length += ebt_mac_wormhash_size(wh_src);
2862 +
2863 + if (datalen != EBT_ALIGN(expected_length)) {
2864 + printk(KERN_WARNING
2865 + "ebtables: among: wrong size: %d"
2866 + "against expected %d, rounded to %d\n",
2867 + datalen, expected_length,
2868 + EBT_ALIGN(expected_length));
2869 + return -EINVAL;
2870 + }
2871 + if (wh_dst && (err = ebt_mac_wormhash_check_integrity(wh_dst))) {
2872 + printk(KERN_WARNING
2873 + "ebtables: among: dst integrity fail: %x\n", -err);
2874 + return -EINVAL;
2875 + }
2876 + if (wh_src && (err = ebt_mac_wormhash_check_integrity(wh_src))) {
2877 + printk(KERN_WARNING
2878 + "ebtables: among: src integrity fail: %x\n", -err);
2879 + return -EINVAL;
2880 + }
2881 + return 0;
2882 +}
2883 +
2884 +static struct ebt_match filter_among = {
2885 + {NULL, NULL},
2886 + EBT_AMONG_MATCH,
2887 + ebt_filter_among,
2888 + ebt_among_check,
2889 + NULL,
2890 + THIS_MODULE
2891 +};
2892 +
2893 +static int __init init(void)
2894 +{
2895 + return ebt_register_match(&filter_among);
2896 +}
2897 +
2898 +static void __exit fini(void)
2899 +{
2900 + ebt_unregister_match(&filter_among);
2901 +}
2902 +
2903 +module_init(init);
2904 +module_exit(fini);
2905 +EXPORT_NO_SYMBOLS;
2906 +MODULE_LICENSE("GPL");
2907 diff -Nur linux.old/net/bridge/netfilter/ebt_arp.c linux.dev/net/bridge/netfilter/ebt_arp.c
2908 --- linux.old/net/bridge/netfilter/ebt_arp.c 1970-01-01 01:00:00.000000000 +0100
2909 +++ linux.dev/net/bridge/netfilter/ebt_arp.c 2005-10-10 10:36:46.093869500 +0200
2910 @@ -0,0 +1,149 @@
2911 +/*
2912 + * ebt_arp
2913 + *
2914 + * Authors:
2915 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2916 + * Tim Gardner <timg@tpi.com>
2917 + *
2918 + * April, 2002
2919 + *
2920 + */
2921 +
2922 +#include <linux/netfilter_bridge/ebtables.h>
2923 +#include <linux/netfilter_bridge/ebt_arp.h>
2924 +#include <linux/if_arp.h>
2925 +#include <linux/if_ether.h>
2926 +#include <linux/module.h>
2927 +
2928 +static int ebt_filter_arp(const struct sk_buff *skb, const struct net_device *in,
2929 + const struct net_device *out, const void *data, unsigned int datalen)
2930 +{
2931 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
2932 +
2933 + if (info->bitmask & EBT_ARP_OPCODE && FWINV(info->opcode !=
2934 + ((*skb).nh.arph)->ar_op, EBT_ARP_OPCODE))
2935 + return EBT_NOMATCH;
2936 + if (info->bitmask & EBT_ARP_HTYPE && FWINV(info->htype !=
2937 + ((*skb).nh.arph)->ar_hrd, EBT_ARP_HTYPE))
2938 + return EBT_NOMATCH;
2939 + if (info->bitmask & EBT_ARP_PTYPE && FWINV(info->ptype !=
2940 + ((*skb).nh.arph)->ar_pro, EBT_ARP_PTYPE))
2941 + return EBT_NOMATCH;
2942 +
2943 + if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP))
2944 + {
2945 + uint32_t arp_len = sizeof(struct arphdr) +
2946 + (2 * (((*skb).nh.arph)->ar_hln)) +
2947 + (2 * (((*skb).nh.arph)->ar_pln));
2948 + uint32_t dst;
2949 + uint32_t src;
2950 +
2951 + // Make sure the packet is long enough.
2952 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2953 + return EBT_NOMATCH;
2954 + // IPv4 addresses are always 4 bytes.
2955 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
2956 + return EBT_NOMATCH;
2957 +
2958 + if (info->bitmask & EBT_ARP_SRC_IP) {
2959 + memcpy(&src, ((*skb).nh.raw) + sizeof(struct arphdr) +
2960 + ((*skb).nh.arph)->ar_hln, sizeof(uint32_t));
2961 + if (FWINV(info->saddr != (src & info->smsk),
2962 + EBT_ARP_SRC_IP))
2963 + return EBT_NOMATCH;
2964 + }
2965 +
2966 + if (info->bitmask & EBT_ARP_DST_IP) {
2967 + memcpy(&dst, ((*skb).nh.raw)+sizeof(struct arphdr) +
2968 + (2*(((*skb).nh.arph)->ar_hln)) +
2969 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
2970 + if (FWINV(info->daddr != (dst & info->dmsk),
2971 + EBT_ARP_DST_IP))
2972 + return EBT_NOMATCH;
2973 + }
2974 + }
2975 +
2976 + if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC))
2977 + {
2978 + uint32_t arp_len = sizeof(struct arphdr) +
2979 + (2 * (((*skb).nh.arph)->ar_hln)) +
2980 + (2 * (((*skb).nh.arph)->ar_pln));
2981 + unsigned char dst[ETH_ALEN];
2982 + unsigned char src[ETH_ALEN];
2983 +
2984 + // Make sure the packet is long enough.
2985 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2986 + return EBT_NOMATCH;
2987 + // MAC addresses are 6 bytes.
2988 + if (((*skb).nh.arph)->ar_hln != ETH_ALEN)
2989 + return EBT_NOMATCH;
2990 + if (info->bitmask & EBT_ARP_SRC_MAC) {
2991 + uint8_t verdict, i;
2992 +
2993 + memcpy(&src, ((*skb).nh.raw) +
2994 + sizeof(struct arphdr),
2995 + ETH_ALEN);
2996 + verdict = 0;
2997 + for (i = 0; i < 6; i++)
2998 + verdict |= (src[i] ^ info->smaddr[i]) &
2999 + info->smmsk[i];
3000 + if (FWINV(verdict != 0, EBT_ARP_SRC_MAC))
3001 + return EBT_NOMATCH;
3002 + }
3003 +
3004 + if (info->bitmask & EBT_ARP_DST_MAC) {
3005 + uint8_t verdict, i;
3006 +
3007 + memcpy(&dst, ((*skb).nh.raw) +
3008 + sizeof(struct arphdr) +
3009 + (((*skb).nh.arph)->ar_hln) +
3010 + (((*skb).nh.arph)->ar_pln),
3011 + ETH_ALEN);
3012 + verdict = 0;
3013 + for (i = 0; i < 6; i++)
3014 + verdict |= (dst[i] ^ info->dmaddr[i]) &
3015 + info->dmmsk[i];
3016 + if (FWINV(verdict != 0, EBT_ARP_DST_MAC))
3017 + return EBT_NOMATCH;
3018 + }
3019 + }
3020 +
3021 + return EBT_MATCH;
3022 +}
3023 +
3024 +static int ebt_arp_check(const char *tablename, unsigned int hookmask,
3025 + const struct ebt_entry *e, void *data, unsigned int datalen)
3026 +{
3027 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
3028 +
3029 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arp_info)))
3030 + return -EINVAL;
3031 + if ((e->ethproto != __constant_htons(ETH_P_ARP) &&
3032 + e->ethproto != __constant_htons(ETH_P_RARP)) ||
3033 + e->invflags & EBT_IPROTO)
3034 + return -EINVAL;
3035 + if (info->bitmask & ~EBT_ARP_MASK || info->invflags & ~EBT_ARP_MASK)
3036 + return -EINVAL;
3037 + return 0;
3038 +}
3039 +
3040 +static struct ebt_match filter_arp =
3041 +{
3042 + {NULL, NULL}, EBT_ARP_MATCH, ebt_filter_arp, ebt_arp_check, NULL,
3043 + THIS_MODULE
3044 +};
3045 +
3046 +static int __init init(void)
3047 +{
3048 + return ebt_register_match(&filter_arp);
3049 +}
3050 +
3051 +static void __exit fini(void)
3052 +{
3053 + ebt_unregister_match(&filter_arp);
3054 +}
3055 +
3056 +module_init(init);
3057 +module_exit(fini);
3058 +EXPORT_NO_SYMBOLS;
3059 +MODULE_LICENSE("GPL");
3060 diff -Nur linux.old/net/bridge/netfilter/ebt_arpreply.c linux.dev/net/bridge/netfilter/ebt_arpreply.c
3061 --- linux.old/net/bridge/netfilter/ebt_arpreply.c 1970-01-01 01:00:00.000000000 +0100
3062 +++ linux.dev/net/bridge/netfilter/ebt_arpreply.c 2005-10-10 10:36:46.089869250 +0200
3063 @@ -0,0 +1,86 @@
3064 +/*
3065 + * ebt_arpreply
3066 + *
3067 + * Authors:
3068 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
3069 + * Bart De Schuymer <bdschuym@pandora.be>
3070 + *
3071 + * August, 2003
3072 + *
3073 + */
3074 +
3075 +#include <linux/netfilter_bridge/ebtables.h>
3076 +#include <linux/netfilter_bridge/ebt_arpreply.h>
3077 +#include <linux/if_arp.h>
3078 +#include <net/arp.h>
3079 +#include <linux/module.h>
3080 +
3081 +static int ebt_target_reply(struct sk_buff **pskb, unsigned int hooknr,
3082 + const struct net_device *in, const struct net_device *out,
3083 + const void *data, unsigned int datalen)
3084 +{
3085 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
3086 + struct arphdr *ah;
3087 + unsigned char *sha, *arp_ptr;
3088 + u32 sip, tip;
3089 +
3090 + ah = (**pskb).nh.arph;
3091 + if (ah->ar_op != __constant_htons(ARPOP_REQUEST) ||
3092 + ah->ar_hln != ETH_ALEN || ah->ar_pro != htons(ETH_P_IP) ||
3093 + ah->ar_pln != 4)
3094 + return EBT_CONTINUE;
3095 +
3096 + arp_ptr = (unsigned char *)(ah + 1);
3097 +
3098 + /* get source and target IP */
3099 + sha = arp_ptr;
3100 + arp_ptr += ETH_ALEN;
3101 + memcpy(&sip, arp_ptr, 4);
3102 + arp_ptr += 4 + ETH_ALEN;
3103 + memcpy(&tip, arp_ptr, 4);
3104 +
3105 + arp_send(ARPOP_REPLY, ETH_P_ARP, sip, in, tip, sha, info->mac, sha);
3106 +
3107 + return info->target;
3108 +}
3109 +
3110 +static int ebt_target_reply_check(const char *tablename, unsigned int hookmask,
3111 + const struct ebt_entry *e, void *data, unsigned int datalen)
3112 +{
3113 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
3114 +
3115 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arpreply_info)))
3116 + return -EINVAL;
3117 + if (BASE_CHAIN && info->target == EBT_RETURN)
3118 + return -EINVAL;
3119 + if (e->ethproto != __constant_htons(ETH_P_ARP) ||
3120 + e->invflags & EBT_IPROTO)
3121 + return -EINVAL;
3122 + CLEAR_BASE_CHAIN_BIT;
3123 + if (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING))
3124 + return -EINVAL;
3125 + return 0;
3126 +}
3127 +
3128 +static struct ebt_target reply_target =
3129 +{
3130 + .name = EBT_ARPREPLY_TARGET,
3131 + .target = ebt_target_reply,
3132 + .check = ebt_target_reply_check,
3133 + .me = THIS_MODULE,
3134 +};
3135 +
3136 +static int __init init(void)
3137 +{
3138 + return ebt_register_target(&reply_target);
3139 +}
3140 +
3141 +static void __exit fini(void)
3142 +{
3143 + ebt_unregister_target(&reply_target);
3144 +}
3145 +
3146 +module_init(init);
3147 +module_exit(fini);
3148 +EXPORT_NO_SYMBOLS;
3149 +MODULE_LICENSE("GPL");
3150 diff -Nur linux.old/net/bridge/netfilter/ebt_dnat.c linux.dev/net/bridge/netfilter/ebt_dnat.c
3151 --- linux.old/net/bridge/netfilter/ebt_dnat.c 1970-01-01 01:00:00.000000000 +0100
3152 +++ linux.dev/net/bridge/netfilter/ebt_dnat.c 2005-10-10 10:36:46.109870500 +0200
3153 @@ -0,0 +1,65 @@
3154 +/*
3155 + * ebt_dnat
3156 + *
3157 + * Authors:
3158 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3159 + *
3160 + * June, 2002
3161 + *
3162 + */
3163 +
3164 +#include <linux/netfilter_bridge/ebtables.h>
3165 +#include <linux/netfilter_bridge/ebt_nat.h>
3166 +#include <linux/module.h>
3167 +#include <net/sock.h>
3168 +
3169 +static int ebt_target_dnat(struct sk_buff **pskb, unsigned int hooknr,
3170 + const struct net_device *in, const struct net_device *out,
3171 + const void *data, unsigned int datalen)
3172 +{
3173 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
3174 +
3175 + memcpy(((**pskb).mac.ethernet)->h_dest, info->mac,
3176 + ETH_ALEN * sizeof(unsigned char));
3177 + return info->target;
3178 +}
3179 +
3180 +static int ebt_target_dnat_check(const char *tablename, unsigned int hookmask,
3181 + const struct ebt_entry *e, void *data, unsigned int datalen)
3182 +{
3183 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
3184 +
3185 + if (BASE_CHAIN && info->target == EBT_RETURN)
3186 + return -EINVAL;
3187 + CLEAR_BASE_CHAIN_BIT;
3188 + if ( (strcmp(tablename, "nat") ||
3189 + (hookmask & ~((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT)))) &&
3190 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
3191 + return -EINVAL;
3192 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
3193 + return -EINVAL;
3194 + if (INVALID_TARGET)
3195 + return -EINVAL;
3196 + return 0;
3197 +}
3198 +
3199 +static struct ebt_target dnat =
3200 +{
3201 + {NULL, NULL}, EBT_DNAT_TARGET, ebt_target_dnat, ebt_target_dnat_check,
3202 + NULL, THIS_MODULE
3203 +};
3204 +
3205 +static int __init init(void)
3206 +{
3207 + return ebt_register_target(&dnat);
3208 +}
3209 +
3210 +static void __exit fini(void)
3211 +{
3212 + ebt_unregister_target(&dnat);
3213 +}
3214 +
3215 +module_init(init);
3216 +module_exit(fini);
3217 +EXPORT_NO_SYMBOLS;
3218 +MODULE_LICENSE("GPL");
3219 diff -Nur linux.old/net/bridge/netfilter/ebt_ip.c linux.dev/net/bridge/netfilter/ebt_ip.c
3220 --- linux.old/net/bridge/netfilter/ebt_ip.c 1970-01-01 01:00:00.000000000 +0100
3221 +++ linux.dev/net/bridge/netfilter/ebt_ip.c 2005-10-10 10:36:46.093869500 +0200
3222 @@ -0,0 +1,121 @@
3223 +/*
3224 + * ebt_ip
3225 + *
3226 + * Authors:
3227 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3228 + *
3229 + * April, 2002
3230 + *
3231 + * Changes:
3232 + * added ip-sport and ip-dport
3233 + * Innominate Security Technologies AG <mhopf@innominate.com>
3234 + * September, 2002
3235 + */
3236 +
3237 +#include <linux/netfilter_bridge/ebtables.h>
3238 +#include <linux/netfilter_bridge/ebt_ip.h>
3239 +#include <linux/ip.h>
3240 +#include <linux/in.h>
3241 +#include <linux/module.h>
3242 +
3243 +struct tcpudphdr {
3244 + uint16_t src;
3245 + uint16_t dst;
3246 +};
3247 +
3248 +union h_u {
3249 + unsigned char *raw;
3250 + struct tcpudphdr *tuh;
3251 +};
3252 +
3253 +static int ebt_filter_ip(const struct sk_buff *skb, const struct net_device *in,
3254 + const struct net_device *out, const void *data,
3255 + unsigned int datalen)
3256 +{
3257 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
3258 +
3259 + if (info->bitmask & EBT_IP_TOS &&
3260 + FWINV(info->tos != ((*skb).nh.iph)->tos, EBT_IP_TOS))
3261 + return EBT_NOMATCH;
3262 + if (info->bitmask & EBT_IP_PROTO) {
3263 + if (FWINV(info->protocol != ((*skb).nh.iph)->protocol,
3264 + EBT_IP_PROTO))
3265 + return EBT_NOMATCH;
3266 + if ( info->protocol == IPPROTO_TCP ||
3267 + info->protocol == IPPROTO_UDP )
3268 + {
3269 + union h_u h;
3270 + h.raw = skb->data + skb->nh.iph->ihl*4;
3271 + if (info->bitmask & EBT_IP_DPORT) {
3272 + uint16_t port = ntohs(h.tuh->dst);
3273 + if (FWINV(port < info->dport[0] ||
3274 + port > info->dport[1],
3275 + EBT_IP_DPORT))
3276 + return EBT_NOMATCH;
3277 + }
3278 + if (info->bitmask & EBT_IP_SPORT) {
3279 + uint16_t port = ntohs(h.tuh->src);
3280 + if (FWINV(port < info->sport[0] ||
3281 + port > info->sport[1],
3282 + EBT_IP_SPORT))
3283 + return EBT_NOMATCH;
3284 + }
3285 + }
3286 + }
3287 + if (info->bitmask & EBT_IP_SOURCE &&
3288 + FWINV((((*skb).nh.iph)->saddr & info->smsk) !=
3289 + info->saddr, EBT_IP_SOURCE))
3290 + return EBT_NOMATCH;
3291 + if ((info->bitmask & EBT_IP_DEST) &&
3292 + FWINV((((*skb).nh.iph)->daddr & info->dmsk) !=
3293 + info->daddr, EBT_IP_DEST))
3294 + return EBT_NOMATCH;
3295 + return EBT_MATCH;
3296 +}
3297 +
3298 +static int ebt_ip_check(const char *tablename, unsigned int hookmask,
3299 + const struct ebt_entry *e, void *data, unsigned int datalen)
3300 +{
3301 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
3302 +
3303 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ip_info)))
3304 + return -EINVAL;
3305 + if (e->ethproto != __constant_htons(ETH_P_IP) ||
3306 + e->invflags & EBT_IPROTO)
3307 + return -EINVAL;
3308 + if (info->bitmask & ~EBT_IP_MASK || info->invflags & ~EBT_IP_MASK)
3309 + return -EINVAL;
3310 + if (info->bitmask & (EBT_IP_DPORT | EBT_IP_SPORT)) {
3311 + if (!info->bitmask & EBT_IPROTO)
3312 + return -EINVAL;
3313 + if (info->protocol != IPPROTO_TCP &&
3314 + info->protocol != IPPROTO_UDP)
3315 + return -EINVAL;
3316 + }
3317 + if (info->bitmask & EBT_IP_DPORT && info->dport[0] > info->dport[1])
3318 + return -EINVAL;
3319 + if (info->bitmask & EBT_IP_SPORT && info->sport[0] > info->sport[1])
3320 + return -EINVAL;
3321 + return 0;
3322 +}
3323 +
3324 +static struct ebt_match filter_ip =
3325 +{
3326 + {NULL, NULL}, EBT_IP_MATCH, ebt_filter_ip, ebt_ip_check, NULL,
3327 + THIS_MODULE
3328 +};
3329 +
3330 +static int __init init(void)
3331 +{
3332 + return ebt_register_match(&filter_ip);
3333 +}
3334 +
3335 +static void __exit fini(void)
3336 +{
3337 + ebt_unregister_match(&filter_ip);
3338 +}
3339 +
3340 +module_init(init);
3341 +module_exit(fini);
3342 +EXPORT_NO_SYMBOLS;
3343 +MODULE_LICENSE("GPL");
3344 diff -Nur linux.old/net/bridge/netfilter/ebt_limit.c linux.dev/net/bridge/netfilter/ebt_limit.c
3345 --- linux.old/net/bridge/netfilter/ebt_limit.c 1970-01-01 01:00:00.000000000 +0100
3346 +++ linux.dev/net/bridge/netfilter/ebt_limit.c 2005-10-10 10:36:46.089869250 +0200
3347 @@ -0,0 +1,101 @@
3348 +/*
3349 + * ebt_limit
3350 + *
3351 + * Authors:
3352 + * Tom Marshall <tommy@home.tig-grr.com>
3353 + *
3354 + * Mostly copied from netfilter's ipt_limit.c, see that file for explanation
3355 + *
3356 + * September, 2003
3357 + *
3358 + */
3359 +
3360 +#include <linux/netfilter_bridge/ebtables.h>
3361 +#include <linux/netfilter_bridge/ebt_limit.h>
3362 +#include <linux/module.h>
3363 +
3364 +#include <linux/netdevice.h>
3365 +#include <linux/spinlock.h>
3366 +
3367 +static spinlock_t limit_lock = SPIN_LOCK_UNLOCKED;
3368 +
3369 +#define CREDITS_PER_JIFFY 128
3370 +
3371 +static int ebt_limit_match(const struct sk_buff *skb, const struct net_device *in,
3372 + const struct net_device *out, const void *data, unsigned int datalen)
3373 +{
3374 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
3375 + unsigned long now = jiffies;
3376 +
3377 + spin_lock_bh(&limit_lock);
3378 + info->credit += (now - xchg(&info->prev, now)) * CREDITS_PER_JIFFY;
3379 + if (info->credit > info->credit_cap)
3380 + info->credit = info->credit_cap;
3381 +
3382 + if (info->credit >= info->cost) {
3383 + /* We're not limited. */
3384 + info->credit -= info->cost;
3385 + spin_unlock_bh(&limit_lock);
3386 + return EBT_MATCH;
3387 + }
3388 +
3389 + spin_unlock_bh(&limit_lock);
3390 + return EBT_NOMATCH;
3391 +}
3392 +
3393 +/* Precision saver. */
3394 +static u_int32_t
3395 +user2credits(u_int32_t user)
3396 +{
3397 + /* If multiplying would overflow... */
3398 + if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
3399 + /* Divide first. */
3400 + return (user / EBT_LIMIT_SCALE) * HZ * CREDITS_PER_JIFFY;
3401 +
3402 + return (user * HZ * CREDITS_PER_JIFFY) / EBT_LIMIT_SCALE;
3403 +}
3404 +
3405 +static int ebt_limit_check(const char *tablename, unsigned int hookmask,
3406 + const struct ebt_entry *e, void *data, unsigned int datalen)
3407 +{
3408 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
3409 +
3410 + if (datalen != EBT_ALIGN(sizeof(struct ebt_limit_info)))
3411 + return -EINVAL;
3412 +
3413 + /* Check for overflow. */
3414 + if (info->burst == 0
3415 + || user2credits(info->avg * info->burst) < user2credits(info->avg)) {
3416 + printk("Overflow in ebt_limit: %u/%u\n",
3417 + info->avg, info->burst);
3418 + return -EINVAL;
3419 + }
3420 +
3421 + /* User avg in seconds * EBT_LIMIT_SCALE: convert to jiffies * 128. */
3422 + info->prev = jiffies;
3423 + info->credit = user2credits(info->avg * info->burst);
3424 + info->credit_cap = user2credits(info->avg * info->burst);
3425 + info->cost = user2credits(info->avg);
3426 + return 0;
3427 +}
3428 +
3429 +static struct ebt_match ebt_limit_reg =
3430 +{
3431 + {NULL, NULL}, EBT_LIMIT_MATCH, ebt_limit_match, ebt_limit_check, NULL,
3432 + THIS_MODULE
3433 +};
3434 +
3435 +static int __init init(void)
3436 +{
3437 + return ebt_register_match(&ebt_limit_reg);
3438 +}
3439 +
3440 +static void __exit fini(void)
3441 +{
3442 + ebt_unregister_match(&ebt_limit_reg);
3443 +}
3444 +
3445 +module_init(init);
3446 +module_exit(fini);
3447 +EXPORT_NO_SYMBOLS;
3448 +MODULE_LICENSE("GPL");
3449 diff -Nur linux.old/net/bridge/netfilter/ebt_log.c linux.dev/net/bridge/netfilter/ebt_log.c
3450 --- linux.old/net/bridge/netfilter/ebt_log.c 1970-01-01 01:00:00.000000000 +0100
3451 +++ linux.dev/net/bridge/netfilter/ebt_log.c 2005-10-10 10:36:46.105870250 +0200
3452 @@ -0,0 +1,153 @@
3453 +/*
3454 + * ebt_log
3455 + *
3456 + * Authors:
3457 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3458 + *
3459 + * April, 2002
3460 + *
3461 + */
3462 +
3463 +#include <linux/netfilter_bridge/ebtables.h>
3464 +#include <linux/netfilter_bridge/ebt_log.h>
3465 +#include <linux/module.h>
3466 +#include <linux/ip.h>
3467 +#include <linux/in.h>
3468 +#include <linux/if_arp.h>
3469 +#include <linux/spinlock.h>
3470 +
3471 +static spinlock_t ebt_log_lock = SPIN_LOCK_UNLOCKED;
3472 +
3473 +static int ebt_log_check(const char *tablename, unsigned int hookmask,
3474 + const struct ebt_entry *e, void *data, unsigned int datalen)
3475 +{
3476 + struct ebt_log_info *info = (struct ebt_log_info *)data;
3477 +
3478 + if (datalen != EBT_ALIGN(sizeof(struct ebt_log_info)))
3479 + return -EINVAL;
3480 + if (info->bitmask & ~EBT_LOG_MASK)
3481 + return -EINVAL;
3482 + if (info->loglevel >= 8)
3483 + return -EINVAL;
3484 + info->prefix[EBT_LOG_PREFIX_SIZE - 1] = '\0';
3485 + return 0;
3486 +}
3487 +
3488 +struct tcpudphdr
3489 +{
3490 + uint16_t src;
3491 + uint16_t dst;
3492 +};
3493 +
3494 +struct arppayload
3495 +{
3496 + unsigned char mac_src[ETH_ALEN];
3497 + unsigned char ip_src[4];
3498 + unsigned char mac_dst[ETH_ALEN];
3499 + unsigned char ip_dst[4];
3500 +};
3501 +
3502 +static void print_MAC(unsigned char *p)
3503 +{
3504 + int i;
3505 +
3506 + for (i = 0; i < ETH_ALEN; i++, p++)
3507 + printk("%02x%c", *p, i == ETH_ALEN - 1 ? ' ':':');
3508 +}
3509 +
3510 +#define myNIPQUAD(a) a[0], a[1], a[2], a[3]
3511 +static void ebt_log(const struct sk_buff *skb, unsigned int hooknr,
3512 + const struct net_device *in, const struct net_device *out,
3513 + const void *data, unsigned int datalen)
3514 +{
3515 + struct ebt_log_info *info = (struct ebt_log_info *)data;
3516 + char level_string[4] = "< >";
3517 + level_string[1] = '0' + info->loglevel;
3518 +
3519 + spin_lock_bh(&ebt_log_lock);
3520 + printk(level_string);
3521 + printk("%s IN=%s OUT=%s ", info->prefix, in ? in->name : "",
3522 + out ? out->name : "");
3523 +
3524 + printk("MAC source = ");
3525 + print_MAC((skb->mac.ethernet)->h_source);
3526 + printk("MAC dest = ");
3527 + print_MAC((skb->mac.ethernet)->h_dest);
3528 +
3529 + printk("proto = 0x%04x", ntohs(((*skb).mac.ethernet)->h_proto));
3530 +
3531 + if ((info->bitmask & EBT_LOG_IP) && skb->mac.ethernet->h_proto ==
3532 + htons(ETH_P_IP)){
3533 + struct iphdr *iph = skb->nh.iph;
3534 + printk(" IP SRC=%u.%u.%u.%u IP DST=%u.%u.%u.%u,",
3535 + NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
3536 + printk(" IP tos=0x%02X, IP proto=%d", iph->tos, iph->protocol);
3537 + if (iph->protocol == IPPROTO_TCP ||
3538 + iph->protocol == IPPROTO_UDP) {
3539 + struct tcpudphdr *ports = (struct tcpudphdr *)(skb->data + iph->ihl*4);
3540 +
3541 + if (skb->data + iph->ihl*4 > skb->tail) {
3542 + printk(" INCOMPLETE TCP/UDP header");
3543 + goto out;
3544 + }
3545 + printk(" SPT=%u DPT=%u", ntohs(ports->src),
3546 + ntohs(ports->dst));
3547 + }
3548 + goto out;
3549 + }
3550 +
3551 + if ((info->bitmask & EBT_LOG_ARP) &&
3552 + ((skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) ||
3553 + (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_RARP)))) {
3554 + struct arphdr * arph = skb->nh.arph;
3555 + printk(" ARP HTYPE=%d, PTYPE=0x%04x, OPCODE=%d",
3556 + ntohs(arph->ar_hrd), ntohs(arph->ar_pro),
3557 + ntohs(arph->ar_op));
3558 + /* If it's for Ethernet and the lengths are OK,
3559 + * then log the ARP payload */
3560 + if (arph->ar_hrd == __constant_htons(1) &&
3561 + arph->ar_hln == ETH_ALEN &&
3562 + arph->ar_pln == sizeof(uint32_t)) {
3563 + struct arppayload *arpp = (struct arppayload *)(skb->data + sizeof(*arph));
3564 +
3565 + if (skb->data + sizeof(*arph) > skb->tail) {
3566 + printk(" INCOMPLETE ARP header");
3567 + goto out;
3568 + }
3569 +
3570 + printk(" ARP MAC SRC=");
3571 + print_MAC(arpp->mac_src);
3572 + printk(" ARP IP SRC=%u.%u.%u.%u",
3573 + myNIPQUAD(arpp->ip_src));
3574 + printk(" ARP MAC DST=");
3575 + print_MAC(arpp->mac_dst);
3576 + printk(" ARP IP DST=%u.%u.%u.%u",
3577 + myNIPQUAD(arpp->ip_dst));
3578 + }
3579 +
3580 + }
3581 +out:
3582 + printk("\n");
3583 + spin_unlock_bh(&ebt_log_lock);
3584 +}
3585 +
3586 +static struct ebt_watcher log =
3587 +{
3588 + {NULL, NULL}, EBT_LOG_WATCHER, ebt_log, ebt_log_check, NULL,
3589 + THIS_MODULE
3590 +};
3591 +
3592 +static int __init init(void)
3593 +{
3594 + return ebt_register_watcher(&log);
3595 +}
3596 +
3597 +static void __exit fini(void)
3598 +{
3599 + ebt_unregister_watcher(&log);
3600 +}
3601 +
3602 +module_init(init);
3603 +module_exit(fini);
3604 +EXPORT_NO_SYMBOLS;
3605 +MODULE_LICENSE("GPL");
3606 diff -Nur linux.old/net/bridge/netfilter/ebt_mark.c linux.dev/net/bridge/netfilter/ebt_mark.c
3607 --- linux.old/net/bridge/netfilter/ebt_mark.c 1970-01-01 01:00:00.000000000 +0100
3608 +++ linux.dev/net/bridge/netfilter/ebt_mark.c 2005-10-10 10:36:46.089869250 +0200
3609 @@ -0,0 +1,66 @@
3610 +/*
3611 + * ebt_mark
3612 + *
3613 + * Authors:
3614 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3615 + *
3616 + * July, 2002
3617 + *
3618 + */
3619 +
3620 +// The mark target can be used in any chain
3621 +// I believe adding a mangle table just for marking is total overkill
3622 +// Marking a frame doesn't really change anything in the frame anyway
3623 +
3624 +#include <linux/netfilter_bridge/ebtables.h>
3625 +#include <linux/netfilter_bridge/ebt_mark_t.h>
3626 +#include <linux/module.h>
3627 +
3628 +static int ebt_target_mark(struct sk_buff **pskb, unsigned int hooknr,
3629 + const struct net_device *in, const struct net_device *out,
3630 + const void *data, unsigned int datalen)
3631 +{
3632 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
3633 +
3634 + if ((*pskb)->nfmark != info->mark) {
3635 + (*pskb)->nfmark = info->mark;
3636 + (*pskb)->nfcache |= NFC_ALTERED;
3637 + }
3638 + return info->target;
3639 +}
3640 +
3641 +static int ebt_target_mark_check(const char *tablename, unsigned int hookmask,
3642 + const struct ebt_entry *e, void *data, unsigned int datalen)
3643 +{
3644 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
3645 +
3646 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_t_info)))
3647 + return -EINVAL;
3648 + if (BASE_CHAIN && info->target == EBT_RETURN)
3649 + return -EINVAL;
3650 + CLEAR_BASE_CHAIN_BIT;
3651 + if (INVALID_TARGET)
3652 + return -EINVAL;
3653 + return 0;
3654 +}
3655 +
3656 +static struct ebt_target mark_target =
3657 +{
3658 + {NULL, NULL}, EBT_MARK_TARGET, ebt_target_mark,
3659 + ebt_target_mark_check, NULL, THIS_MODULE
3660 +};
3661 +
3662 +static int __init init(void)
3663 +{
3664 + return ebt_register_target(&mark_target);
3665 +}
3666 +
3667 +static void __exit fini(void)
3668 +{
3669 + ebt_unregister_target(&mark_target);
3670 +}
3671 +
3672 +module_init(init);
3673 +module_exit(fini);
3674 +EXPORT_NO_SYMBOLS;
3675 +MODULE_LICENSE("GPL");
3676 diff -Nur linux.old/net/bridge/netfilter/ebt_mark_m.c linux.dev/net/bridge/netfilter/ebt_mark_m.c
3677 --- linux.old/net/bridge/netfilter/ebt_mark_m.c 1970-01-01 01:00:00.000000000 +0100
3678 +++ linux.dev/net/bridge/netfilter/ebt_mark_m.c 2005-10-10 10:36:46.093869500 +0200
3679 @@ -0,0 +1,61 @@
3680 +/*
3681 + * ebt_mark_m
3682 + *
3683 + * Authors:
3684 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3685 + *
3686 + * July, 2002
3687 + *
3688 + */
3689 +
3690 +#include <linux/netfilter_bridge/ebtables.h>
3691 +#include <linux/netfilter_bridge/ebt_mark_m.h>
3692 +#include <linux/module.h>
3693 +
3694 +static int ebt_filter_mark(const struct sk_buff *skb,
3695 + const struct net_device *in, const struct net_device *out, const void *data,
3696 + unsigned int datalen)
3697 +{
3698 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
3699 +
3700 + if (info->bitmask & EBT_MARK_OR)
3701 + return !(!!(skb->nfmark & info->mask) ^ info->invert);
3702 + return !(((skb->nfmark & info->mask) == info->mark) ^ info->invert);
3703 +}
3704 +
3705 +static int ebt_mark_check(const char *tablename, unsigned int hookmask,
3706 + const struct ebt_entry *e, void *data, unsigned int datalen)
3707 +{
3708 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
3709 +
3710 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_m_info)))
3711 + return -EINVAL;
3712 + if (info->bitmask & ~EBT_MARK_MASK)
3713 + return -EINVAL;
3714 + if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
3715 + return -EINVAL;
3716 + if (!info->bitmask)
3717 + return -EINVAL;
3718 + return 0;
3719 +}
3720 +
3721 +static struct ebt_match filter_mark =
3722 +{
3723 + {NULL, NULL}, EBT_MARK_MATCH, ebt_filter_mark, ebt_mark_check, NULL,
3724 + THIS_MODULE
3725 +};
3726 +
3727 +static int __init init(void)
3728 +{
3729 + return ebt_register_match(&filter_mark);
3730 +}
3731 +
3732 +static void __exit fini(void)
3733 +{
3734 + ebt_unregister_match(&filter_mark);
3735 +}
3736 +
3737 +module_init(init);
3738 +module_exit(fini);
3739 +EXPORT_NO_SYMBOLS;
3740 +MODULE_LICENSE("GPL");
3741 diff -Nur linux.old/net/bridge/netfilter/ebt_pkttype.c linux.dev/net/bridge/netfilter/ebt_pkttype.c
3742 --- linux.old/net/bridge/netfilter/ebt_pkttype.c 1970-01-01 01:00:00.000000000 +0100
3743 +++ linux.dev/net/bridge/netfilter/ebt_pkttype.c 2005-10-10 10:36:46.093869500 +0200
3744 @@ -0,0 +1,60 @@
3745 +/*
3746 + * ebt_pkttype
3747 + *
3748 + * Authors:
3749 + * Bart De Schuymer <bdschuym@pandora.be>
3750 + *
3751 + * April, 2003
3752 + *
3753 + */
3754 +
3755 +#include <linux/netfilter_bridge/ebtables.h>
3756 +#include <linux/netfilter_bridge/ebt_pkttype.h>
3757 +#include <linux/module.h>
3758 +
3759 +static int ebt_filter_pkttype(const struct sk_buff *skb,
3760 + const struct net_device *in,
3761 + const struct net_device *out,
3762 + const void *data,
3763 + unsigned int datalen)
3764 +{
3765 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
3766 +
3767 + return (skb->pkt_type != info->pkt_type) ^ info->invert;
3768 +}
3769 +
3770 +static int ebt_pkttype_check(const char *tablename, unsigned int hookmask,
3771 + const struct ebt_entry *e, void *data, unsigned int datalen)
3772 +{
3773 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
3774 +
3775 + if (datalen != EBT_ALIGN(sizeof(struct ebt_pkttype_info)))
3776 + return -EINVAL;
3777 + if (info->invert != 0 && info->invert != 1)
3778 + return -EINVAL;
3779 + /* Allow any pkt_type value */
3780 + return 0;
3781 +}
3782 +
3783 +static struct ebt_match filter_pkttype =
3784 +{
3785 + .name = EBT_PKTTYPE_MATCH,
3786 + .match = ebt_filter_pkttype,
3787 + .check = ebt_pkttype_check,
3788 + .me = THIS_MODULE,
3789 +};
3790 +
3791 +static int __init init(void)
3792 +{
3793 + return ebt_register_match(&filter_pkttype);
3794 +}
3795 +
3796 +static void __exit fini(void)
3797 +{
3798 + ebt_unregister_match(&filter_pkttype);
3799 +}
3800 +
3801 +module_init(init);
3802 +module_exit(fini);
3803 +EXPORT_NO_SYMBOLS;
3804 +MODULE_LICENSE("GPL");
3805 diff -Nur linux.old/net/bridge/netfilter/ebt_redirect.c linux.dev/net/bridge/netfilter/ebt_redirect.c
3806 --- linux.old/net/bridge/netfilter/ebt_redirect.c 1970-01-01 01:00:00.000000000 +0100
3807 +++ linux.dev/net/bridge/netfilter/ebt_redirect.c 2005-10-10 10:36:46.093869500 +0200
3808 @@ -0,0 +1,71 @@
3809 +/*
3810 + * ebt_redirect
3811 + *
3812 + * Authors:
3813 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3814 + *
3815 + * April, 2002
3816 + *
3817 + */
3818 +
3819 +#include <linux/netfilter_bridge/ebtables.h>
3820 +#include <linux/netfilter_bridge/ebt_redirect.h>
3821 +#include <linux/module.h>
3822 +#include <net/sock.h>
3823 +#include "../br_private.h"
3824 +
3825 +static int ebt_target_redirect(struct sk_buff **pskb, unsigned int hooknr,
3826 + const struct net_device *in, const struct net_device *out,
3827 + const void *data, unsigned int datalen)
3828 +{
3829 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
3830 +
3831 + if (hooknr != NF_BR_BROUTING)
3832 + memcpy((**pskb).mac.ethernet->h_dest,
3833 + in->br_port->br->dev.dev_addr, ETH_ALEN);
3834 + else {
3835 + memcpy((**pskb).mac.ethernet->h_dest,
3836 + in->dev_addr, ETH_ALEN);
3837 + (*pskb)->pkt_type = PACKET_HOST;
3838 + }
3839 + return info->target;
3840 +}
3841 +
3842 +static int ebt_target_redirect_check(const char *tablename, unsigned int hookmask,
3843 + const struct ebt_entry *e, void *data, unsigned int datalen)
3844 +{
3845 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
3846 +
3847 + if (datalen != EBT_ALIGN(sizeof(struct ebt_redirect_info)))
3848 + return -EINVAL;
3849 + if (BASE_CHAIN && info->target == EBT_RETURN)
3850 + return -EINVAL;
3851 + CLEAR_BASE_CHAIN_BIT;
3852 + if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) &&
3853 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
3854 + return -EINVAL;
3855 + if (INVALID_TARGET)
3856 + return -EINVAL;
3857 + return 0;
3858 +}
3859 +
3860 +static struct ebt_target redirect_target =
3861 +{
3862 + {NULL, NULL}, EBT_REDIRECT_TARGET, ebt_target_redirect,
3863 + ebt_target_redirect_check, NULL, THIS_MODULE
3864 +};
3865 +
3866 +static int __init init(void)
3867 +{
3868 + return ebt_register_target(&redirect_target);
3869 +}
3870 +
3871 +static void __exit fini(void)
3872 +{
3873 + ebt_unregister_target(&redirect_target);
3874 +}
3875 +
3876 +module_init(init);
3877 +module_exit(fini);
3878 +EXPORT_NO_SYMBOLS;
3879 +MODULE_LICENSE("GPL");
3880 diff -Nur linux.old/net/bridge/netfilter/ebt_snat.c linux.dev/net/bridge/netfilter/ebt_snat.c
3881 --- linux.old/net/bridge/netfilter/ebt_snat.c 1970-01-01 01:00:00.000000000 +0100
3882 +++ linux.dev/net/bridge/netfilter/ebt_snat.c 2005-10-10 10:36:46.109870500 +0200
3883 @@ -0,0 +1,64 @@
3884 +/*
3885 + * ebt_snat
3886 + *
3887 + * Authors:
3888 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3889 + *
3890 + * June, 2002
3891 + *
3892 + */
3893 +
3894 +#include <linux/netfilter_bridge/ebtables.h>
3895 +#include <linux/netfilter_bridge/ebt_nat.h>
3896 +#include <linux/module.h>
3897 +
3898 +static int ebt_target_snat(struct sk_buff **pskb, unsigned int hooknr,
3899 + const struct net_device *in, const struct net_device *out,
3900 + const void *data, unsigned int datalen)
3901 +{
3902 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
3903 +
3904 + memcpy(((**pskb).mac.ethernet)->h_source, info->mac,
3905 + ETH_ALEN * sizeof(unsigned char));
3906 + return info->target;
3907 +}
3908 +
3909 +static int ebt_target_snat_check(const char *tablename, unsigned int hookmask,
3910 + const struct ebt_entry *e, void *data, unsigned int datalen)
3911 +{
3912 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
3913 +
3914 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
3915 + return -EINVAL;
3916 + if (BASE_CHAIN && info->target == EBT_RETURN)
3917 + return -EINVAL;
3918 + CLEAR_BASE_CHAIN_BIT;
3919 + if (strcmp(tablename, "nat"))
3920 + return -EINVAL;
3921 + if (hookmask & ~(1 << NF_BR_POST_ROUTING))
3922 + return -EINVAL;
3923 + if (INVALID_TARGET)
3924 + return -EINVAL;
3925 + return 0;
3926 +}
3927 +
3928 +static struct ebt_target snat =
3929 +{
3930 + {NULL, NULL}, EBT_SNAT_TARGET, ebt_target_snat, ebt_target_snat_check,
3931 + NULL, THIS_MODULE
3932 +};
3933 +
3934 +static int __init init(void)
3935 +{
3936 + return ebt_register_target(&snat);
3937 +}
3938 +
3939 +static void __exit fini(void)
3940 +{
3941 + ebt_unregister_target(&snat);
3942 +}
3943 +
3944 +module_init(init);
3945 +module_exit(fini);
3946 +EXPORT_NO_SYMBOLS;
3947 +MODULE_LICENSE("GPL");
3948 diff -Nur linux.old/net/bridge/netfilter/ebt_stp.c linux.dev/net/bridge/netfilter/ebt_stp.c
3949 --- linux.old/net/bridge/netfilter/ebt_stp.c 1970-01-01 01:00:00.000000000 +0100
3950 +++ linux.dev/net/bridge/netfilter/ebt_stp.c 2005-10-10 10:36:46.093869500 +0200
3951 @@ -0,0 +1,191 @@
3952 +/*
3953 + * ebt_stp
3954 + *
3955 + * Authors:
3956 + * Bart De Schuymer <bdschuym@pandora.be>
3957 + * Stephen Hemminger <shemminger@osdl.org>
3958 + *
3959 + * June, 2003
3960 + */
3961 +
3962 +#include <linux/netfilter_bridge/ebtables.h>
3963 +#include <linux/netfilter_bridge/ebt_stp.h>
3964 +#include <linux/module.h>
3965 +
3966 +#define BPDU_TYPE_CONFIG 0
3967 +#define BPDU_TYPE_TCN 0x80
3968 +
3969 +struct stp_header {
3970 + uint8_t dsap;
3971 + uint8_t ssap;
3972 + uint8_t ctrl;
3973 + uint8_t pid;
3974 + uint8_t vers;
3975 + uint8_t type;
3976 +};
3977 +
3978 +struct stp_config_pdu {
3979 + uint8_t flags;
3980 + uint8_t root[8];
3981 + uint8_t root_cost[4];
3982 + uint8_t sender[8];
3983 + uint8_t port[2];
3984 + uint8_t msg_age[2];
3985 + uint8_t max_age[2];
3986 + uint8_t hello_time[2];
3987 + uint8_t forward_delay[2];
3988 +};
3989 +
3990 +#define NR16(p) (p[0] << 8 | p[1])
3991 +#define NR32(p) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3])
3992 +
3993 +static int ebt_filter_config(struct ebt_stp_info *info,
3994 + struct stp_config_pdu *stpc)
3995 +{
3996 + struct ebt_stp_config_info *c;
3997 + uint16_t v16;
3998 + uint32_t v32;
3999 + int verdict, i;
4000 +
4001 + c = &info->config;
4002 + if ((info->bitmask & EBT_STP_FLAGS) &&
4003 + FWINV(c->flags != stpc->flags, EBT_STP_FLAGS))
4004 + return EBT_NOMATCH;
4005 + if (info->bitmask & EBT_STP_ROOTPRIO) {
4006 + v16 = NR16(stpc->root);
4007 + if (FWINV(v16 < c->root_priol ||
4008 + v16 > c->root_priou, EBT_STP_ROOTPRIO))
4009 + return EBT_NOMATCH;
4010 + }
4011 + if (info->bitmask & EBT_STP_ROOTADDR) {
4012 + verdict = 0;
4013 + for (i = 0; i < 6; i++)
4014 + verdict |= (stpc->root[2+i] ^ c->root_addr[i]) &
4015 + c->root_addrmsk[i];
4016 + if (FWINV(verdict != 0, EBT_STP_ROOTADDR))
4017 + return EBT_NOMATCH;
4018 + }
4019 + if (info->bitmask & EBT_STP_ROOTCOST) {
4020 + v32 = NR32(stpc->root_cost);
4021 + if (FWINV(v32 < c->root_costl ||
4022 + v32 > c->root_costu, EBT_STP_ROOTCOST))
4023 + return EBT_NOMATCH;
4024 + }
4025 + if (info->bitmask & EBT_STP_SENDERPRIO) {
4026 + v16 = NR16(stpc->sender);
4027 + if (FWINV(v16 < c->sender_priol ||
4028 + v16 > c->sender_priou, EBT_STP_SENDERPRIO))
4029 + return EBT_NOMATCH;
4030 + }
4031 + if (info->bitmask & EBT_STP_SENDERADDR) {
4032 + verdict = 0;
4033 + for (i = 0; i < 6; i++)
4034 + verdict |= (stpc->sender[2+i] ^ c->sender_addr[i]) &
4035 + c->sender_addrmsk[i];
4036 + if (FWINV(verdict != 0, EBT_STP_SENDERADDR))
4037 + return EBT_NOMATCH;
4038 + }
4039 + if (info->bitmask & EBT_STP_PORT) {
4040 + v16 = NR16(stpc->port);
4041 + if (FWINV(v16 < c->portl ||
4042 + v16 > c->portu, EBT_STP_PORT))
4043 + return EBT_NOMATCH;
4044 + }
4045 + if (info->bitmask & EBT_STP_MSGAGE) {
4046 + v16 = NR16(stpc->msg_age);
4047 + if (FWINV(v16 < c->msg_agel ||
4048 + v16 > c->msg_ageu, EBT_STP_MSGAGE))
4049 + return EBT_NOMATCH;
4050 + }
4051 + if (info->bitmask & EBT_STP_MAXAGE) {
4052 + v16 = NR16(stpc->max_age);
4053 + if (FWINV(v16 < c->max_agel ||
4054 + v16 > c->max_ageu, EBT_STP_MAXAGE))
4055 + return EBT_NOMATCH;
4056 + }
4057 + if (info->bitmask & EBT_STP_HELLOTIME) {
4058 + v16 = NR16(stpc->hello_time);
4059 + if (FWINV(v16 < c->hello_timel ||
4060 + v16 > c->hello_timeu, EBT_STP_HELLOTIME))
4061 + return EBT_NOMATCH;
4062 + }
4063 + if (info->bitmask & EBT_STP_FWDD) {
4064 + v16 = NR16(stpc->forward_delay);
4065 + if (FWINV(v16 < c->forward_delayl ||
4066 + v16 > c->forward_delayu, EBT_STP_FWDD))
4067 + return EBT_NOMATCH;
4068 + }
4069 + return EBT_MATCH;
4070 +}
4071 +
4072 +static int ebt_filter_stp(const struct sk_buff *skb, const struct net_device *in,
4073 + const struct net_device *out, const void *data, unsigned int datalen)
4074 +{
4075 + struct ebt_stp_info *info = (struct ebt_stp_info *)data;
4076 + struct stp_header stph;
4077 + uint8_t header[6] = {0x42, 0x42, 0x03, 0x00, 0x00, 0x00};
4078 + if (skb_copy_bits(skb, 0, &stph, sizeof(stph)))
4079 + return EBT_NOMATCH;
4080 +
4081 + /* The stp code only considers these */
4082 + if (memcmp(&stph, header, sizeof(header)))
4083 + return EBT_NOMATCH;
4084 +
4085 + if (info->bitmask & EBT_STP_TYPE
4086 + && FWINV(info->type != stph.type, EBT_STP_TYPE))
4087 + return EBT_NOMATCH;
4088 +
4089 + if (stph.type == BPDU_TYPE_CONFIG &&
4090 + info->bitmask & EBT_STP_CONFIG_MASK) {
4091 + struct stp_config_pdu stpc;
4092 +
4093 + if (skb_copy_bits(skb, sizeof(stph), &stpc, sizeof(stpc)))
4094 + return EBT_NOMATCH;
4095 + return ebt_filter_config(info, &stpc);
4096 + }
4097 + return EBT_MATCH;
4098 +}
4099 +
4100 +static int ebt_stp_check(const char *tablename, unsigned int hookmask,
4101 + const struct ebt_entry *e, void *data, unsigned int datalen)
4102 +{
4103 + struct ebt_stp_info *info = (struct ebt_stp_info *)data;
4104 + int len = EBT_ALIGN(sizeof(struct ebt_stp_info));
4105 + uint8_t bridge_ula[6] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
4106 + uint8_t msk[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
4107 +
4108 + if (info->bitmask & ~EBT_STP_MASK || info->invflags & ~EBT_STP_MASK ||
4109 + !(info->bitmask & EBT_STP_MASK))
4110 + return -EINVAL;
4111 + if (datalen != len)
4112 + return -EINVAL;
4113 + /* Make sure the match only receives stp frames */
4114 + if (memcmp(e->destmac, bridge_ula, ETH_ALEN) ||
4115 + memcmp(e->destmsk, msk, ETH_ALEN) || !(e->bitmask & EBT_DESTMAC))
4116 + return -EINVAL;
4117 +
4118 + return 0;
4119 +}
4120 +
4121 +static struct ebt_match filter_stp =
4122 +{
4123 + .name = EBT_STP_MATCH,
4124 + .match = ebt_filter_stp,
4125 + .check = ebt_stp_check,
4126 + .me = THIS_MODULE,
4127 +};
4128 +
4129 +static int __init init(void)
4130 +{
4131 + return ebt_register_match(&filter_stp);
4132 +}
4133 +
4134 +static void __exit fini(void)
4135 +{
4136 + ebt_unregister_match(&filter_stp);
4137 +}
4138 +
4139 +module_init(init);
4140 +module_exit(fini);
4141 +EXPORT_NO_SYMBOLS;
4142 +MODULE_LICENSE("GPL");
4143 diff -Nur linux.old/net/bridge/netfilter/ebt_ulog.c linux.dev/net/bridge/netfilter/ebt_ulog.c
4144 --- linux.old/net/bridge/netfilter/ebt_ulog.c 1970-01-01 01:00:00.000000000 +0100
4145 +++ linux.dev/net/bridge/netfilter/ebt_ulog.c 2005-10-10 10:36:46.105870250 +0200
4146 @@ -0,0 +1,281 @@
4147 +/*
4148 + * netfilter module for userspace bridged Ethernet frames logging daemons
4149 + *
4150 + * Authors:
4151 + * Bart De Schuymer <bdschuym@pandora.be>
4152 + *
4153 + * November, 2004
4154 + *
4155 + * Based on ipt_ULOG.c, which is
4156 + * (C) 2000-2002 by Harald Welte <laforge@netfilter.org>
4157 + *
4158 + * This module accepts two parameters:
4159 + *
4160 + * nlbufsiz:
4161 + * The parameter specifies how big the buffer for each netlink multicast
4162 + * group is. e.g. If you say nlbufsiz=8192, up to eight kb of packets will
4163 + * get accumulated in the kernel until they are sent to userspace. It is
4164 + * NOT possible to allocate more than 128kB, and it is strongly discouraged,
4165 + * because atomically allocating 128kB inside the network rx softirq is not
4166 + * reliable. Please also keep in mind that this buffer size is allocated for
4167 + * each nlgroup you are using, so the total kernel memory usage increases
4168 + * by that factor.
4169 + *
4170 + * flushtimeout:
4171 + * Specify, after how many hundredths of a second the queue should be
4172 + * flushed even if it is not full yet.
4173 + *
4174 + */
4175 +
4176 +#include <linux/module.h>
4177 +#include <linux/config.h>
4178 +#include <linux/spinlock.h>
4179 +#include <linux/socket.h>
4180 +#include <linux/skbuff.h>
4181 +#include <linux/kernel.h>
4182 +#include <linux/timer.h>
4183 +#include <linux/netlink.h>
4184 +#include <linux/netdevice.h>
4185 +#include <linux/module.h>
4186 +#include <linux/netfilter_bridge/ebtables.h>
4187 +#include <linux/netfilter_bridge/ebt_ulog.h>
4188 +#include <net/sock.h>
4189 +#include "../br_private.h"
4190 +
4191 +#define PRINTR(format, args...) do { if (net_ratelimit()) \
4192 + printk(format , ## args); } while (0)
4193 +
4194 +static unsigned int nlbufsiz = 4096;
4195 +MODULE_PARM(nlbufsiz, "i");
4196 +MODULE_PARM_DESC(nlbufsiz, "netlink buffer size (number of bytes) "
4197 + "(defaults to 4096)");
4198 +
4199 +static unsigned int flushtimeout = 10;
4200 +MODULE_PARM(flushtimeout, "i");
4201 +MODULE_PARM_DESC(flushtimeout, "buffer flush timeout (hundredths of a second) "
4202 + "(defaults to 10)");
4203 +
4204 +typedef struct {
4205 + unsigned int qlen; /* number of nlmsgs' in the skb */
4206 + struct nlmsghdr *lastnlh; /* netlink header of last msg in skb */
4207 + struct sk_buff *skb; /* the pre-allocated skb */
4208 + struct timer_list timer; /* the timer function */
4209 + spinlock_t lock; /* the per-queue lock */
4210 +} ebt_ulog_buff_t;
4211 +
4212 +static ebt_ulog_buff_t ulog_buffers[EBT_ULOG_MAXNLGROUPS];
4213 +static struct sock *ebtlognl;
4214 +
4215 +/* send one ulog_buff_t to userspace */
4216 +static void ulog_send(unsigned int nlgroup)
4217 +{
4218 + ebt_ulog_buff_t *ub = &ulog_buffers[nlgroup];
4219 +
4220 + if (timer_pending(&ub->timer))
4221 + del_timer(&ub->timer);
4222 +
4223 + /* last nlmsg needs NLMSG_DONE */
4224 + if (ub->qlen > 1)
4225 + ub->lastnlh->nlmsg_type = NLMSG_DONE;
4226 +
4227 + NETLINK_CB(ub->skb).dst_groups = 1 << nlgroup;
4228 + netlink_broadcast(ebtlognl, ub->skb, 0, 1 << nlgroup, GFP_ATOMIC);
4229 +
4230 + ub->qlen = 0;
4231 + ub->skb = NULL;
4232 +}
4233 +
4234 +/* timer function to flush queue in flushtimeout time */
4235 +static void ulog_timer(unsigned long data)
4236 +{
4237 + spin_lock_bh(&ulog_buffers[data].lock);
4238 + if (ulog_buffers[data].skb)
4239 + ulog_send(data);
4240 + spin_unlock_bh(&ulog_buffers[data].lock);
4241 +}
4242 +
4243 +static struct sk_buff *ulog_alloc_skb(unsigned int size)
4244 +{
4245 + struct sk_buff *skb;
4246 +
4247 + skb = alloc_skb(nlbufsiz, GFP_ATOMIC);
4248 + if (!skb) {
4249 + PRINTR(KERN_ERR "ebt_ulog: can't alloc whole buffer "
4250 + "of size %ub!\n", nlbufsiz);
4251 + if (size < nlbufsiz) {
4252 + /* try to allocate only as much as we need for
4253 + * current packet */
4254 + skb = alloc_skb(size, GFP_ATOMIC);
4255 + if (!skb)
4256 + PRINTR(KERN_ERR "ebt_ulog: can't even allocate "
4257 + "buffer of size %ub\n", size);
4258 + }
4259 + }
4260 +
4261 + return skb;
4262 +}
4263 +
4264 +static void ebt_ulog(const struct sk_buff *skb, unsigned int hooknr,
4265 + const struct net_device *in, const struct net_device *out,
4266 + const void *data, unsigned int datalen)
4267 +{
4268 + ebt_ulog_packet_msg_t *pm;
4269 + size_t size, copy_len;
4270 + struct nlmsghdr *nlh;
4271 + struct ebt_ulog_info *loginfo = (struct ebt_ulog_info *)data;
4272 + unsigned int group = loginfo->nlgroup;
4273 + ebt_ulog_buff_t *ub = &ulog_buffers[group];
4274 + spinlock_t *lock = &ub->lock;
4275 +
4276 + if ((loginfo->cprange == 0) ||
4277 + (loginfo->cprange > skb->len + ETH_HLEN))
4278 + copy_len = skb->len + ETH_HLEN;
4279 + else
4280 + copy_len = loginfo->cprange;
4281 +
4282 + size = NLMSG_SPACE(sizeof(*pm) + copy_len);
4283 +
4284 + spin_lock_bh(lock);
4285 +
4286 + if (!ub->skb) {
4287 + if (!(ub->skb = ulog_alloc_skb(size)))
4288 + goto alloc_failure;
4289 + } else if (size > skb_tailroom(ub->skb)) {
4290 + ulog_send(group);
4291 +
4292 + if (!(ub->skb = ulog_alloc_skb(size)))
4293 + goto alloc_failure;
4294 + }
4295 +
4296 + nlh = NLMSG_PUT(ub->skb, 0, ub->qlen, 0,
4297 + size - NLMSG_ALIGN(sizeof(*nlh)));
4298 + ub->qlen++;
4299 +
4300 + pm = NLMSG_DATA(nlh);
4301 +
4302 + /* Fill in the ulog data */
4303 + do_gettimeofday(&pm->stamp);
4304 + if (ub->qlen == 1)
4305 + ub->skb->stamp = pm->stamp;
4306 + pm->data_len = copy_len;
4307 + pm->mark = skb->nfmark;
4308 + pm->hook = hooknr;
4309 + if (loginfo->prefix != NULL)
4310 + strcpy(pm->prefix, loginfo->prefix);
4311 + else
4312 + *(pm->prefix) = '\0';
4313 +
4314 + if (in) {
4315 + strcpy(pm->physindev, in->name);
4316 + strcpy(pm->indev, in->br_port->br->dev.name);
4317 + } else
4318 + pm->indev[0] = pm->physindev[0] = '\0';
4319 +
4320 + if (out) {
4321 + strcpy(pm->physoutdev, out->name);
4322 + strcpy(pm->outdev, out->br_port->br->dev.name);
4323 + } else
4324 + pm->outdev[0] = pm->physoutdev[0] = '\0';
4325 +
4326 + if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
4327 + BUG();
4328 +
4329 + if (ub->qlen > 1)
4330 + ub->lastnlh->nlmsg_flags |= NLM_F_MULTI;
4331 +
4332 + ub->lastnlh = nlh;
4333 +
4334 + if (ub->qlen >= loginfo->qthreshold)
4335 + ulog_send(group);
4336 + else if (!timer_pending(&ub->timer)) {
4337 + ub->timer.expires = jiffies + flushtimeout * HZ / 100;
4338 + add_timer(&ub->timer);
4339 + }
4340 +
4341 +unlock:
4342 + spin_unlock_bh(lock);
4343 +
4344 + return;
4345 +
4346 +nlmsg_failure:
4347 + PRINTR(KERN_ERR "ebt_ULOG: error during NLMSG_PUT.\n");
4348 + goto unlock;
4349 +alloc_failure:
4350 + goto unlock;
4351 +}
4352 +
4353 +static int ebt_ulog_check(const char *tablename, unsigned int hookmask,
4354 + const struct ebt_entry *e, void *data, unsigned int datalen)
4355 +{
4356 + struct ebt_ulog_info *loginfo = (struct ebt_ulog_info *)data;
4357 +
4358 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ulog_info)) ||
4359 + loginfo->nlgroup > 31)
4360 + return -EINVAL;
4361 +
4362 + loginfo->prefix[EBT_ULOG_PREFIX_LEN - 1] = '\0';
4363 +
4364 + if (loginfo->qthreshold > EBT_ULOG_MAX_QLEN)
4365 + loginfo->qthreshold = EBT_ULOG_MAX_QLEN;
4366 +
4367 + return 0;
4368 +}
4369 +
4370 +static struct ebt_watcher ulog = {
4371 + {NULL, NULL}, EBT_ULOG_WATCHER, ebt_ulog, ebt_ulog_check, NULL,
4372 + THIS_MODULE
4373 +};
4374 +
4375 +static int __init init(void)
4376 +{
4377 + int i, ret = 0;
4378 +
4379 + if (nlbufsiz >= 128*1024) {
4380 + printk(KERN_NOTICE "ebt_ulog: Netlink buffer has to be <= 128kB,"
4381 + " please try a smaller nlbufsiz parameter.\n");
4382 + return -EINVAL;
4383 + }
4384 +
4385 + /* initialize ulog_buffers */
4386 + for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
4387 + init_timer(&ulog_buffers[i].timer);
4388 + ulog_buffers[i].timer.function = ulog_timer;
4389 + ulog_buffers[i].timer.data = i;
4390 + ulog_buffers[i].lock = SPIN_LOCK_UNLOCKED;
4391 + }
4392 +
4393 + ebtlognl = netlink_kernel_create(NETLINK_NFLOG, NULL);
4394 + if (!ebtlognl)
4395 + ret = -ENOMEM;
4396 + else if ((ret = ebt_register_watcher(&ulog)))
4397 + sock_release(ebtlognl->socket);
4398 +
4399 + return ret;
4400 +}
4401 +
4402 +static void __exit fini(void)
4403 +{
4404 + ebt_ulog_buff_t *ub;
4405 + int i;
4406 +
4407 + ebt_unregister_watcher(&ulog);
4408 + for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
4409 + ub = &ulog_buffers[i];
4410 + if (timer_pending(&ub->timer))
4411 + del_timer(&ub->timer);
4412 + spin_lock_bh(&ub->lock);
4413 + if (ub->skb) {
4414 + kfree_skb(ub->skb);
4415 + ub->skb = NULL;
4416 + }
4417 + spin_unlock_bh(&ub->lock);
4418 + }
4419 + sock_release(ebtlognl->socket);
4420 +}
4421 +
4422 +module_init(init);
4423 +module_exit(fini);
4424 +MODULE_LICENSE("GPL");
4425 +MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
4426 +MODULE_DESCRIPTION("ebtables userspace logging module for bridged Ethernet"
4427 + " frames");
4428 diff -Nur linux.old/net/bridge/netfilter/ebt_vlan.c linux.dev/net/bridge/netfilter/ebt_vlan.c
4429 --- linux.old/net/bridge/netfilter/ebt_vlan.c 1970-01-01 01:00:00.000000000 +0100
4430 +++ linux.dev/net/bridge/netfilter/ebt_vlan.c 2005-10-10 10:36:46.093869500 +0200
4431 @@ -0,0 +1,259 @@
4432 +/*
4433 + * Description: EBTables 802.1Q match extension kernelspace module.
4434 + * Authors: Nick Fedchik <nick@fedchik.org.ua>
4435 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4436 + *
4437 + * This program is free software; you can redistribute it and/or modify
4438 + * it under the terms of the GNU General Public License as published by
4439 + * the Free Software Foundation; either version 2 of the License, or
4440 + * (at your option) any later version.
4441 + *
4442 + * This program is distributed in the hope that it will be useful,
4443 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4444 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4445 + * GNU General Public License for more details.
4446 + *
4447 + * You should have received a copy of the GNU General Public License
4448 + * along with this program; if not, write to the Free Software
4449 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4450 + */
4451 +
4452 +#include <linux/if_ether.h>
4453 +#include <linux/if_vlan.h>
4454 +#include <linux/module.h>
4455 +#include <linux/netfilter_bridge/ebtables.h>
4456 +#include <linux/netfilter_bridge/ebt_vlan.h>
4457 +
4458 +static unsigned char debug;
4459 +#define MODULE_VERSION "0.6"
4460 +
4461 +MODULE_PARM(debug, "0-1b");
4462 +MODULE_PARM_DESC(debug, "debug=1 is turn on debug messages");
4463 +MODULE_AUTHOR("Nick Fedchik <nick@fedchik.org.ua>");
4464 +MODULE_DESCRIPTION("802.1Q match module (ebtables extension), v"
4465 + MODULE_VERSION);
4466 +MODULE_LICENSE("GPL");
4467 +
4468 +
4469 +#define DEBUG_MSG(args...) if (debug) printk (KERN_DEBUG "ebt_vlan: " args)
4470 +#define INV_FLAG(_inv_flag_) (info->invflags & _inv_flag_) ? "!" : ""
4471 +#define GET_BITMASK(_BIT_MASK_) info->bitmask & _BIT_MASK_
4472 +#define SET_BITMASK(_BIT_MASK_) info->bitmask |= _BIT_MASK_
4473 +#define EXIT_ON_MISMATCH(_MATCH_,_MASK_) if (!((info->_MATCH_ == _MATCH_)^!!(info->invflags & _MASK_))) return 1;
4474 +
4475 +/*
4476 + * Function description: ebt_filter_vlan() is main engine for
4477 + * checking passed 802.1Q frame according to
4478 + * the passed extension parameters (in the *data buffer)
4479 + * ebt_filter_vlan() is called after successfull check the rule params
4480 + * by ebt_check_vlan() function.
4481 + * Parameters:
4482 + * const struct sk_buff *skb - pointer to passed ethernet frame buffer
4483 + * const void *data - pointer to passed extension parameters
4484 + * unsigned int datalen - length of passed *data buffer
4485 + * const struct net_device *in -
4486 + * const struct net_device *out -
4487 + * const struct ebt_counter *c -
4488 + * Returned values:
4489 + * 0 - ok (all rule params matched)
4490 + * 1 - miss (rule params not acceptable to the parsed frame)
4491 + */
4492 +static int
4493 +ebt_filter_vlan(const struct sk_buff *skb,
4494 + const struct net_device *in,
4495 + const struct net_device *out,
4496 + const void *data, unsigned int datalen)
4497 +{
4498 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data; /* userspace data */
4499 + struct vlan_ethhdr *frame = (struct vlan_ethhdr *) skb->mac.raw; /* Passed tagged frame */
4500 +
4501 + unsigned short TCI; /* Whole TCI, given from parsed frame */
4502 + unsigned short id; /* VLAN ID, given from frame TCI */
4503 + unsigned char prio; /* user_priority, given from frame TCI */
4504 + unsigned short encap; /* VLAN encapsulated Type/Length field, given from orig frame */
4505 +
4506 + /*
4507 + * Tag Control Information (TCI) consists of the following elements:
4508 + * - User_priority. The user_priority field is three bits in length,
4509 + * interpreted as a binary number.
4510 + * - Canonical Format Indicator (CFI). The Canonical Format Indicator
4511 + * (CFI) is a single bit flag value. Currently ignored.
4512 + * - VLAN Identifier (VID). The VID is encoded as
4513 + * an unsigned binary number.
4514 + */
4515 + TCI = ntohs(frame->h_vlan_TCI);
4516 + id = TCI & VLAN_VID_MASK;
4517 + prio = (TCI >> 13) & 0x7;
4518 + encap = frame->h_vlan_encapsulated_proto;
4519 +
4520 + /*
4521 + * Checking VLAN Identifier (VID)
4522 + */
4523 + if (GET_BITMASK(EBT_VLAN_ID)) { /* Is VLAN ID parsed? */
4524 + EXIT_ON_MISMATCH(id, EBT_VLAN_ID);
4525 + }
4526 + /*
4527 + * Checking user_priority
4528 + */
4529 + if (GET_BITMASK(EBT_VLAN_PRIO)) { /* Is VLAN user_priority parsed? */
4530 + EXIT_ON_MISMATCH(prio, EBT_VLAN_PRIO);
4531 + }
4532 + /*
4533 + * Checking Encapsulated Proto (Length/Type) field
4534 + */
4535 + if (GET_BITMASK(EBT_VLAN_ENCAP)) { /* Is VLAN Encap parsed? */
4536 + EXIT_ON_MISMATCH(encap, EBT_VLAN_ENCAP);
4537 + }
4538 + /*
4539 + * All possible extension parameters was parsed.
4540 + * If rule never returned by missmatch, then all ok.
4541 + */
4542 + return 0;
4543 +}
4544 +
4545 +/*
4546 + * Function description: ebt_vlan_check() is called when userspace
4547 + * delivers the table entry to the kernel,
4548 + * and to check that userspace doesn't give a bad table.
4549 + * Parameters:
4550 + * const char *tablename - table name string
4551 + * unsigned int hooknr - hook number
4552 + * const struct ebt_entry *e - ebtables entry basic set
4553 + * const void *data - pointer to passed extension parameters
4554 + * unsigned int datalen - length of passed *data buffer
4555 + * Returned values:
4556 + * 0 - ok (all delivered rule params are correct)
4557 + * 1 - miss (rule params is out of range, invalid, incompatible, etc.)
4558 + */
4559 +static int
4560 +ebt_check_vlan(const char *tablename,
4561 + unsigned int hooknr,
4562 + const struct ebt_entry *e, void *data, unsigned int datalen)
4563 +{
4564 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data;
4565 +
4566 + /*
4567 + * Parameters buffer overflow check
4568 + */
4569 + if (datalen != EBT_ALIGN(sizeof(struct ebt_vlan_info))) {
4570 + DEBUG_MSG
4571 + ("passed size %d is not eq to ebt_vlan_info (%d)\n",
4572 + datalen, sizeof(struct ebt_vlan_info));
4573 + return -EINVAL;
4574 + }
4575 +
4576 + /*
4577 + * Is it 802.1Q frame checked?
4578 + */
4579 + if (e->ethproto != __constant_htons(ETH_P_8021Q)) {
4580 + DEBUG_MSG
4581 + ("passed entry proto %2.4X is not 802.1Q (8100)\n",
4582 + (unsigned short) ntohs(e->ethproto));
4583 + return -EINVAL;
4584 + }
4585 +
4586 + /*
4587 + * Check for bitmask range
4588 + * True if even one bit is out of mask
4589 + */
4590 + if (info->bitmask & ~EBT_VLAN_MASK) {
4591 + DEBUG_MSG("bitmask %2X is out of mask (%2X)\n",
4592 + info->bitmask, EBT_VLAN_MASK);
4593 + return -EINVAL;
4594 + }
4595 +
4596 + /*
4597 + * Check for inversion flags range
4598 + */
4599 + if (info->invflags & ~EBT_VLAN_MASK) {
4600 + DEBUG_MSG("inversion flags %2X is out of mask (%2X)\n",
4601 + info->invflags, EBT_VLAN_MASK);
4602 + return -EINVAL;
4603 + }
4604 +
4605 + /*
4606 + * Reserved VLAN ID (VID) values
4607 + * -----------------------------
4608 + * 0 - The null VLAN ID.
4609 + * 1 - The default Port VID (PVID)
4610 + * 0x0FFF - Reserved for implementation use.
4611 + * if_vlan.h: VLAN_GROUP_ARRAY_LEN 4096.
4612 + */
4613 + if (GET_BITMASK(EBT_VLAN_ID)) { /* when vlan-id param was spec-ed */
4614 + if (!!info->id) { /* if id!=0 => check vid range */
4615 + if (info->id > VLAN_GROUP_ARRAY_LEN) {
4616 + DEBUG_MSG
4617 + ("id %d is out of range (1-4096)\n",
4618 + info->id);
4619 + return -EINVAL;
4620 + }
4621 + /*
4622 + * Note: This is valid VLAN-tagged frame point.
4623 + * Any value of user_priority are acceptable,
4624 + * but should be ignored according to 802.1Q Std.
4625 + * So we just drop the prio flag.
4626 + */
4627 + info->bitmask &= ~EBT_VLAN_PRIO;
4628 + }
4629 + /*
4630 + * Else, id=0 (null VLAN ID) => user_priority range (any?)
4631 + */
4632 + }
4633 +
4634 + if (GET_BITMASK(EBT_VLAN_PRIO)) {
4635 + if ((unsigned char) info->prio > 7) {
4636 + DEBUG_MSG
4637 + ("prio %d is out of range (0-7)\n",
4638 + info->prio);
4639 + return -EINVAL;
4640 + }
4641 + }
4642 + /*
4643 + * Check for encapsulated proto range - it is possible to be
4644 + * any value for u_short range.
4645 + * if_ether.h: ETH_ZLEN 60 - Min. octets in frame sans FCS
4646 + */
4647 + if (GET_BITMASK(EBT_VLAN_ENCAP)) {
4648 + if ((unsigned short) ntohs(info->encap) < ETH_ZLEN) {
4649 + DEBUG_MSG
4650 + ("encap frame length %d is less than minimal\n",
4651 + ntohs(info->encap));
4652 + return -EINVAL;
4653 + }
4654 + }
4655 +
4656 + return 0;
4657 +}
4658 +
4659 +static struct ebt_match filter_vlan = {
4660 + {NULL, NULL},
4661 + EBT_VLAN_MATCH,
4662 + ebt_filter_vlan,
4663 + ebt_check_vlan,
4664 + NULL,
4665 + THIS_MODULE
4666 +};
4667 +
4668 +/*
4669 + * Module initialization function.
4670 + */
4671 +static int __init init(void)
4672 +{
4673 + DEBUG_MSG("ebtables 802.1Q extension module v"
4674 + MODULE_VERSION "\n");
4675 + DEBUG_MSG("module debug=%d\n", !!debug);
4676 + return ebt_register_match(&filter_vlan);
4677 +}
4678 +
4679 +/*
4680 + * Module "finalization" function
4681 + */
4682 +static void __exit fini(void)
4683 +{
4684 + ebt_unregister_match(&filter_vlan);
4685 +}
4686 +
4687 +module_init(init);
4688 +module_exit(fini);
4689 +
4690 +EXPORT_NO_SYMBOLS;
4691 diff -Nur linux.old/net/bridge/netfilter/ebtable_broute.c linux.dev/net/bridge/netfilter/ebtable_broute.c
4692 --- linux.old/net/bridge/netfilter/ebtable_broute.c 1970-01-01 01:00:00.000000000 +0100
4693 +++ linux.dev/net/bridge/netfilter/ebtable_broute.c 2005-10-10 10:36:46.089869250 +0200
4694 @@ -0,0 +1,79 @@
4695 +/*
4696 + * ebtable_broute
4697 + *
4698 + * Authors:
4699 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4700 + *
4701 + * April, 2002
4702 + *
4703 + * This table lets you choose between routing and bridging for frames
4704 + * entering on a bridge enslaved nic. This table is traversed before any
4705 + * other ebtables table. See net/bridge/br_input.c.
4706 + */
4707 +
4708 +#include <linux/netfilter_bridge/ebtables.h>
4709 +#include <linux/module.h>
4710 +#include <linux/if_bridge.h>
4711 +#include <linux/brlock.h>
4712 +
4713 +// EBT_ACCEPT means the frame will be bridged
4714 +// EBT_DROP means the frame will be routed
4715 +static struct ebt_entries initial_chain =
4716 + {0, "BROUTING", 0, EBT_ACCEPT, 0};
4717 +
4718 +static struct ebt_replace initial_table =
4719 +{
4720 + "broute", 1 << NF_BR_BROUTING, 0, sizeof(struct ebt_entries),
4721 + { [NF_BR_BROUTING]&initial_chain}, 0, NULL, (char *)&initial_chain
4722 +};
4723 +
4724 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
4725 +{
4726 + if (valid_hooks & ~(1 << NF_BR_BROUTING))
4727 + return -EINVAL;
4728 + return 0;
4729 +}
4730 +
4731 +static struct ebt_table broute_table =
4732 +{
4733 + {NULL, NULL}, "broute", &initial_table, 1 << NF_BR_BROUTING,
4734 + RW_LOCK_UNLOCKED, check, NULL
4735 +};
4736 +
4737 +static int ebt_broute(struct sk_buff **pskb)
4738 +{
4739 + int ret;
4740 +
4741 + ret = ebt_do_table(NF_BR_BROUTING, pskb, (*pskb)->dev, NULL,
4742 + &broute_table);
4743 + if (ret == NF_DROP)
4744 + return 1; // route it
4745 + return 0; // bridge it
4746 +}
4747 +
4748 +static int __init init(void)
4749 +{
4750 + int ret;
4751 +
4752 + ret = ebt_register_table(&broute_table);
4753 + if (ret < 0)
4754 + return ret;
4755 + br_write_lock_bh(BR_NETPROTO_LOCK);
4756 + // see br_input.c
4757 + br_should_route_hook = ebt_broute;
4758 + br_write_unlock_bh(BR_NETPROTO_LOCK);
4759 + return ret;
4760 +}
4761 +
4762 +static void __exit fini(void)
4763 +{
4764 + br_write_lock_bh(BR_NETPROTO_LOCK);
4765 + br_should_route_hook = NULL;
4766 + br_write_unlock_bh(BR_NETPROTO_LOCK);
4767 + ebt_unregister_table(&broute_table);
4768 +}
4769 +
4770 +module_init(init);
4771 +module_exit(fini);
4772 +EXPORT_NO_SYMBOLS;
4773 +MODULE_LICENSE("GPL");
4774 diff -Nur linux.old/net/bridge/netfilter/ebtable_filter.c linux.dev/net/bridge/netfilter/ebtable_filter.c
4775 --- linux.old/net/bridge/netfilter/ebtable_filter.c 1970-01-01 01:00:00.000000000 +0100
4776 +++ linux.dev/net/bridge/netfilter/ebtable_filter.c 2005-10-10 10:36:46.089869250 +0200
4777 @@ -0,0 +1,90 @@
4778 +/*
4779 + * ebtable_filter
4780 + *
4781 + * Authors:
4782 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4783 + *
4784 + * April, 2002
4785 + *
4786 + */
4787 +
4788 +#include <linux/netfilter_bridge/ebtables.h>
4789 +#include <linux/module.h>
4790 +
4791 +#define FILTER_VALID_HOOKS ((1 << NF_BR_LOCAL_IN) | (1 << NF_BR_FORWARD) | \
4792 + (1 << NF_BR_LOCAL_OUT))
4793 +
4794 +static struct ebt_entries initial_chains[] =
4795 +{
4796 + {0, "INPUT", 0, EBT_ACCEPT, 0},
4797 + {0, "FORWARD", 0, EBT_ACCEPT, 0},
4798 + {0, "OUTPUT", 0, EBT_ACCEPT, 0}
4799 +};
4800 +
4801 +static struct ebt_replace initial_table =
4802 +{
4803 + "filter", FILTER_VALID_HOOKS, 0, 3 * sizeof(struct ebt_entries),
4804 + { [NF_BR_LOCAL_IN]&initial_chains[0], [NF_BR_FORWARD]&initial_chains[1],
4805 + [NF_BR_LOCAL_OUT]&initial_chains[2] }, 0, NULL, (char *)initial_chains
4806 +};
4807 +
4808 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
4809 +{
4810 + if (valid_hooks & ~FILTER_VALID_HOOKS)
4811 + return -EINVAL;
4812 + return 0;
4813 +}
4814 +
4815 +static struct ebt_table frame_filter =
4816 +{
4817 + {NULL, NULL}, "filter", &initial_table, FILTER_VALID_HOOKS,
4818 + RW_LOCK_UNLOCKED, check, NULL
4819 +};
4820 +
4821 +static unsigned int
4822 +ebt_hook (unsigned int hook, struct sk_buff **pskb, const struct net_device *in,
4823 + const struct net_device *out, int (*okfn)(struct sk_buff *))
4824 +{
4825 + return ebt_do_table(hook, pskb, in, out, &frame_filter);
4826 +}
4827 +
4828 +static struct nf_hook_ops ebt_ops_filter[] = {
4829 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_LOCAL_IN,
4830 + NF_BR_PRI_FILTER_BRIDGED},
4831 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_FORWARD,
4832 + NF_BR_PRI_FILTER_BRIDGED},
4833 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_LOCAL_OUT,
4834 + NF_BR_PRI_FILTER_OTHER}
4835 +};
4836 +
4837 +static int __init init(void)
4838 +{
4839 + int i, j, ret;
4840 +
4841 + ret = ebt_register_table(&frame_filter);
4842 + if (ret < 0)
4843 + return ret;
4844 + for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
4845 + if ((ret = nf_register_hook(&ebt_ops_filter[i])) < 0)
4846 + goto cleanup;
4847 + return ret;
4848 +cleanup:
4849 + for (j = 0; j < i; j++)
4850 + nf_unregister_hook(&ebt_ops_filter[j]);
4851 + ebt_unregister_table(&frame_filter);
4852 + return ret;
4853 +}
4854 +
4855 +static void __exit fini(void)
4856 +{
4857 + int i;
4858 +
4859 + for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
4860 + nf_unregister_hook(&ebt_ops_filter[i]);
4861 + ebt_unregister_table(&frame_filter);
4862 +}
4863 +
4864 +module_init(init);
4865 +module_exit(fini);
4866 +EXPORT_NO_SYMBOLS;
4867 +MODULE_LICENSE("GPL");
4868 diff -Nur linux.old/net/bridge/netfilter/ebtable_nat.c linux.dev/net/bridge/netfilter/ebtable_nat.c
4869 --- linux.old/net/bridge/netfilter/ebtable_nat.c 1970-01-01 01:00:00.000000000 +0100
4870 +++ linux.dev/net/bridge/netfilter/ebtable_nat.c 2005-10-10 10:36:46.089869250 +0200
4871 @@ -0,0 +1,96 @@
4872 +/*
4873 + * ebtable_nat
4874 + *
4875 + * Authors:
4876 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4877 + *
4878 + * April, 2002
4879 + *
4880 + */
4881 +
4882 +#include <linux/netfilter_bridge/ebtables.h>
4883 +#include <linux/module.h>
4884 +#define NAT_VALID_HOOKS ((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT) | \
4885 + (1 << NF_BR_POST_ROUTING))
4886 +
4887 +static struct ebt_entries initial_chains[] =
4888 +{
4889 + {0, "PREROUTING", 0, EBT_ACCEPT, 0},
4890 + {0, "OUTPUT", 0, EBT_ACCEPT, 0},
4891 + {0, "POSTROUTING", 0, EBT_ACCEPT, 0}
4892 +};
4893 +
4894 +static struct ebt_replace initial_table =
4895 +{
4896 + "nat", NAT_VALID_HOOKS, 0, 3 * sizeof(struct ebt_entries),
4897 + { [NF_BR_PRE_ROUTING]&initial_chains[0], [NF_BR_LOCAL_OUT]&initial_chains[1],
4898 + [NF_BR_POST_ROUTING]&initial_chains[2] }, 0, NULL, (char *)initial_chains
4899 +};
4900 +
4901 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
4902 +{
4903 + if (valid_hooks & ~NAT_VALID_HOOKS)
4904 + return -EINVAL;
4905 + return 0;
4906 +}
4907 +
4908 +static struct ebt_table frame_nat =
4909 +{
4910 + {NULL, NULL}, "nat", &initial_table, NAT_VALID_HOOKS,
4911 + RW_LOCK_UNLOCKED, check, NULL
4912 +};
4913 +
4914 +static unsigned int
4915 +ebt_nat_dst(unsigned int hook, struct sk_buff **pskb, const struct net_device *in
4916 + , const struct net_device *out, int (*okfn)(struct sk_buff *))
4917 +{
4918 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
4919 +}
4920 +
4921 +static unsigned int
4922 +ebt_nat_src(unsigned int hook, struct sk_buff **pskb, const struct net_device *in
4923 + , const struct net_device *out, int (*okfn)(struct sk_buff *))
4924 +{
4925 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
4926 +}
4927 +
4928 +static struct nf_hook_ops ebt_ops_nat[] = {
4929 + { { NULL, NULL }, ebt_nat_dst, PF_BRIDGE, NF_BR_LOCAL_OUT,
4930 + NF_BR_PRI_NAT_DST_OTHER},
4931 + { { NULL, NULL }, ebt_nat_src, PF_BRIDGE, NF_BR_POST_ROUTING,
4932 + NF_BR_PRI_NAT_SRC},
4933 + { { NULL, NULL }, ebt_nat_dst, PF_BRIDGE, NF_BR_PRE_ROUTING,
4934 + NF_BR_PRI_NAT_DST_BRIDGED},
4935 +};
4936 +
4937 +static int __init init(void)
4938 +{
4939 + int i, ret, j;
4940 +
4941 + ret = ebt_register_table(&frame_nat);
4942 + if (ret < 0)
4943 + return ret;
4944 + for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
4945 + if ((ret = nf_register_hook(&ebt_ops_nat[i])) < 0)
4946 + goto cleanup;
4947 + return ret;
4948 +cleanup:
4949 + for (j = 0; j < i; j++)
4950 + nf_unregister_hook(&ebt_ops_nat[j]);
4951 + ebt_unregister_table(&frame_nat);
4952 + return ret;
4953 +}
4954 +
4955 +static void __exit fini(void)
4956 +{
4957 + int i;
4958 +
4959 + for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
4960 + nf_unregister_hook(&ebt_ops_nat[i]);
4961 + ebt_unregister_table(&frame_nat);
4962 +}
4963 +
4964 +module_init(init);
4965 +module_exit(fini);
4966 +EXPORT_NO_SYMBOLS;
4967 +MODULE_LICENSE("GPL");
4968 diff -Nur linux.old/net/bridge/netfilter/ebtables.c linux.dev/net/bridge/netfilter/ebtables.c
4969 --- linux.old/net/bridge/netfilter/ebtables.c 1970-01-01 01:00:00.000000000 +0100
4970 +++ linux.dev/net/bridge/netfilter/ebtables.c 2005-10-10 10:40:05.146309500 +0200
4971 @@ -0,0 +1,1502 @@
4972 +/*
4973 + * ebtables
4974 + *
4975 + * Author:
4976 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4977 + *
4978 + * ebtables.c,v 2.0, July, 2002
4979 + *
4980 + * This code is stongly inspired on the iptables code which is
4981 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
4982 + *
4983 + * This program is free software; you can redistribute it and/or
4984 + * modify it under the terms of the GNU General Public License
4985 + * as published by the Free Software Foundation; either version
4986 + * 2 of the License, or (at your option) any later version.
4987 + */
4988 +
4989 +// used for print_string
4990 +#include <linux/sched.h>
4991 +#include <linux/tty.h>
4992 +
4993 +#include <linux/kmod.h>
4994 +#include <linux/module.h>
4995 +#include <linux/vmalloc.h>
4996 +#include <linux/netfilter_bridge/ebtables.h>
4997 +#include <linux/spinlock.h>
4998 +#include <asm/uaccess.h>
4999 +#include <linux/smp.h>
5000 +#include <net/sock.h>
5001 +// needed for logical [in,out]-dev filtering
5002 +#include "../br_private.h"
5003 +
5004 +// list_named_find
5005 +#define ASSERT_READ_LOCK(x)
5006 +#define ASSERT_WRITE_LOCK(x)
5007 +#include <linux/netfilter_ipv4/listhelp.h>
5008 +
5009 +#if 0 // use this for remote debugging
5010 +// Copyright (C) 1998 by Ori Pomerantz
5011 +// Print the string to the appropriate tty, the one
5012 +// the current task uses
5013 +static void print_string(char *str)
5014 +{
5015 + struct tty_struct *my_tty;
5016 +
5017 + /* The tty for the current task */
5018 + my_tty = current->tty;
5019 + if (my_tty != NULL) {
5020 + (*(my_tty->driver).write)(my_tty, 0, str, strlen(str));
5021 + (*(my_tty->driver).write)(my_tty, 0, "\015\012", 2);
5022 + }
5023 +}
5024 +
5025 +#define BUGPRINT(args) print_string(args);
5026 +#else
5027 +#define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\
5028 + "report to author: "format, ## args)
5029 +// #define BUGPRINT(format, args...)
5030 +#endif
5031 +#define MEMPRINT(format, args...) printk("kernel msg: ebtables "\
5032 + ": out of memory: "format, ## args)
5033 +// #define MEMPRINT(format, args...)
5034 +
5035 +
5036 +
5037 +// Each cpu has its own set of counters, so there is no need for write_lock in
5038 +// the softirq
5039 +// For reading or updating the counters, the user context needs to
5040 +// get a write_lock
5041 +
5042 +// The size of each set of counters is altered to get cache alignment
5043 +#define SMP_ALIGN(x) (((x) + SMP_CACHE_BYTES-1) & ~(SMP_CACHE_BYTES-1))
5044 +#define COUNTER_OFFSET(n) (SMP_ALIGN(n * sizeof(struct ebt_counter)))
5045 +#define COUNTER_BASE(c, n, cpu) ((struct ebt_counter *)(((char *)c) + \
5046 + COUNTER_OFFSET(n) * cpu))
5047 +
5048 +
5049 +
5050 +static DECLARE_MUTEX(ebt_mutex);
5051 +static LIST_HEAD(ebt_tables);
5052 +static LIST_HEAD(ebt_targets);
5053 +static LIST_HEAD(ebt_matches);
5054 +static LIST_HEAD(ebt_watchers);
5055 +
5056 +static struct ebt_target ebt_standard_target =
5057 +{ {NULL, NULL}, EBT_STANDARD_TARGET, NULL, NULL, NULL, NULL};
5058 +
5059 +static inline int ebt_do_watcher (struct ebt_entry_watcher *w,
5060 + const struct sk_buff *skb, unsigned int hooknr, const struct net_device *in,
5061 + const struct net_device *out)
5062 +{
5063 + w->u.watcher->watcher(skb, hooknr, in, out, w->data,
5064 + w->watcher_size);
5065 + // watchers don't give a verdict
5066 + return 0;
5067 +}
5068 +
5069 +static inline int ebt_do_match (struct ebt_entry_match *m,
5070 + const struct sk_buff *skb, const struct net_device *in,
5071 + const struct net_device *out)
5072 +{
5073 + return m->u.match->match(skb, in, out, m->data,
5074 + m->match_size);
5075 +}
5076 +
5077 +static inline int ebt_dev_check(char *entry, const struct net_device *device)
5078 +{
5079 + int i = 0;
5080 + char *devname = device->name;
5081 +
5082 + if (*entry == '\0')
5083 + return 0;
5084 + if (!device)
5085 + return 1;
5086 + /* 1 is the wildcard token */
5087 + while (entry[i] != '\0' && entry[i] != 1 && entry[i] == devname[i])
5088 + i++;
5089 + return (devname[i] != entry[i] && entry[i] != 1);
5090 +}
5091 +
5092 +#define FWINV2(bool,invflg) ((bool) ^ !!(e->invflags & invflg))
5093 +// process standard matches
5094 +static inline int ebt_basic_match(struct ebt_entry *e, struct ethhdr *h,
5095 + const struct net_device *in, const struct net_device *out)
5096 +{
5097 + int verdict, i;
5098 +
5099 + if (e->bitmask & EBT_802_3) {
5100 + if (FWINV2(ntohs(h->h_proto) >= 1536, EBT_IPROTO))
5101 + return 1;
5102 + } else if (!(e->bitmask & EBT_NOPROTO) &&
5103 + FWINV2(e->ethproto != h->h_proto, EBT_IPROTO))
5104 + return 1;
5105 +
5106 + if (FWINV2(ebt_dev_check(e->in, in), EBT_IIN))
5107 + return 1;
5108 + if (FWINV2(ebt_dev_check(e->out, out), EBT_IOUT))
5109 + return 1;
5110 + if ((!in || !in->br_port) ? 0 : FWINV2(ebt_dev_check(
5111 + e->logical_in, &in->br_port->br->dev), EBT_ILOGICALIN))
5112 + return 1;
5113 + if ((!out || !out->br_port) ? 0 : FWINV2(ebt_dev_check(
5114 + e->logical_out, &out->br_port->br->dev), EBT_ILOGICALOUT))
5115 + return 1;
5116 +
5117 + if (e->bitmask & EBT_SOURCEMAC) {
5118 + verdict = 0;
5119 + for (i = 0; i < 6; i++)
5120 + verdict |= (h->h_source[i] ^ e->sourcemac[i]) &
5121 + e->sourcemsk[i];
5122 + if (FWINV2(verdict != 0, EBT_ISOURCE) )
5123 + return 1;
5124 + }
5125 + if (e->bitmask & EBT_DESTMAC) {
5126 + verdict = 0;
5127 + for (i = 0; i < 6; i++)
5128 + verdict |= (h->h_dest[i] ^ e->destmac[i]) &
5129 + e->destmsk[i];
5130 + if (FWINV2(verdict != 0, EBT_IDEST) )
5131 + return 1;
5132 + }
5133 + return 0;
5134 +}
5135 +
5136 +// Do some firewalling
5137 +unsigned int ebt_do_table (unsigned int hook, struct sk_buff **pskb,
5138 + const struct net_device *in, const struct net_device *out,
5139 + struct ebt_table *table)
5140 +{
5141 + int i, nentries;
5142 + struct ebt_entry *point;
5143 + struct ebt_counter *counter_base, *cb_base;
5144 + struct ebt_entry_target *t;
5145 + int verdict, sp = 0;
5146 + struct ebt_chainstack *cs;
5147 + struct ebt_entries *chaininfo;
5148 + char *base;
5149 + struct ebt_table_info *private;
5150 +
5151 + read_lock_bh(&table->lock);
5152 + private = table->private;
5153 + cb_base = COUNTER_BASE(private->counters, private->nentries,
5154 + cpu_number_map(smp_processor_id()));
5155 + if (private->chainstack)
5156 + cs = private->chainstack[cpu_number_map(smp_processor_id())];
5157 + else
5158 + cs = NULL;
5159 + chaininfo = private->hook_entry[hook];
5160 + nentries = private->hook_entry[hook]->nentries;
5161 + point = (struct ebt_entry *)(private->hook_entry[hook]->data);
5162 + counter_base = cb_base + private->hook_entry[hook]->counter_offset;
5163 + // base for chain jumps
5164 + base = private->entries;
5165 + i = 0;
5166 + while (i < nentries) {
5167 + if (ebt_basic_match(point, (**pskb).mac.ethernet, in, out))
5168 + goto letscontinue;
5169 +
5170 + if (EBT_MATCH_ITERATE(point, ebt_do_match, *pskb, in, out) != 0)
5171 + goto letscontinue;
5172 +
5173 + // increase counter
5174 + (*(counter_base + i)).pcnt++;
5175 + (*(counter_base + i)).bcnt+=(**pskb).len;
5176 +
5177 + // these should only watch: not modify, nor tell us
5178 + // what to do with the packet
5179 + EBT_WATCHER_ITERATE(point, ebt_do_watcher, *pskb, hook, in,
5180 + out);
5181 +
5182 + t = (struct ebt_entry_target *)
5183 + (((char *)point) + point->target_offset);
5184 + // standard target
5185 + if (!t->u.target->target)
5186 + verdict = ((struct ebt_standard_target *)t)->verdict;
5187 + else
5188 + verdict = t->u.target->target(pskb, hook,
5189 + in, out, t->data, t->target_size);
5190 + if (verdict == EBT_ACCEPT) {
5191 + read_unlock_bh(&table->lock);
5192 + return NF_ACCEPT;
5193 + }
5194 + if (verdict == EBT_DROP) {
5195 + read_unlock_bh(&table->lock);
5196 + return NF_DROP;
5197 + }
5198 + if (verdict == EBT_RETURN) {
5199 +letsreturn:
5200 +#ifdef CONFIG_NETFILTER_DEBUG
5201 + if (sp == 0) {
5202 + BUGPRINT("RETURN on base chain");
5203 + // act like this is EBT_CONTINUE
5204 + goto letscontinue;
5205 + }
5206 +#endif
5207 + sp--;
5208 + // put all the local variables right
5209 + i = cs[sp].n;
5210 + chaininfo = cs[sp].chaininfo;
5211 + nentries = chaininfo->nentries;
5212 + point = cs[sp].e;
5213 + counter_base = cb_base +
5214 + chaininfo->counter_offset;
5215 + continue;
5216 + }
5217 + if (verdict == EBT_CONTINUE)
5218 + goto letscontinue;
5219 +#ifdef CONFIG_NETFILTER_DEBUG
5220 + if (verdict < 0) {
5221 + BUGPRINT("bogus standard verdict\n");
5222 + read_unlock_bh(&table->lock);
5223 + return NF_DROP;
5224 + }
5225 +#endif
5226 + // jump to a udc
5227 + cs[sp].n = i + 1;
5228 + cs[sp].chaininfo = chaininfo;
5229 + cs[sp].e = (struct ebt_entry *)
5230 + (((char *)point) + point->next_offset);
5231 + i = 0;
5232 + chaininfo = (struct ebt_entries *) (base + verdict);
5233 +#ifdef CONFIG_NETFILTER_DEBUG
5234 + if (chaininfo->distinguisher) {
5235 + BUGPRINT("jump to non-chain\n");
5236 + read_unlock_bh(&table->lock);
5237 + return NF_DROP;
5238 + }
5239 +#endif
5240 + nentries = chaininfo->nentries;
5241 + point = (struct ebt_entry *)chaininfo->data;
5242 + counter_base = cb_base + chaininfo->counter_offset;
5243 + sp++;
5244 + continue;
5245 +letscontinue:
5246 + point = (struct ebt_entry *)
5247 + (((char *)point) + point->next_offset);
5248 + i++;
5249 + }
5250 +
5251 + // I actually like this :)
5252 + if (chaininfo->policy == EBT_RETURN)
5253 + goto letsreturn;
5254 + if (chaininfo->policy == EBT_ACCEPT) {
5255 + read_unlock_bh(&table->lock);
5256 + return NF_ACCEPT;
5257 + }
5258 + read_unlock_bh(&table->lock);
5259 + return NF_DROP;
5260 +}
5261 +
5262 +// If it succeeds, returns element and locks mutex
5263 +static inline void *
5264 +find_inlist_lock_noload(struct list_head *head, const char *name, int *error,
5265 + struct semaphore *mutex)
5266 +{
5267 + void *ret;
5268 +
5269 + *error = down_interruptible(mutex);
5270 + if (*error != 0)
5271 + return NULL;
5272 +
5273 + ret = list_named_find(head, name);
5274 + if (!ret) {
5275 + *error = -ENOENT;
5276 + up(mutex);
5277 + }
5278 + return ret;
5279 +}
5280 +
5281 +#ifndef CONFIG_KMOD
5282 +#define find_inlist_lock(h,n,p,e,m) find_inlist_lock_noload((h),(n),(e),(m))
5283 +#else
5284 +static void *
5285 +find_inlist_lock(struct list_head *head, const char *name, const char *prefix,
5286 + int *error, struct semaphore *mutex)
5287 +{
5288 + void *ret;
5289 +
5290 + ret = find_inlist_lock_noload(head, name, error, mutex);
5291 + if (!ret) {
5292 + char modulename[EBT_FUNCTION_MAXNAMELEN + strlen(prefix) + 1];
5293 + strcpy(modulename, prefix);
5294 + strcat(modulename, name);
5295 + request_module(modulename);
5296 + ret = find_inlist_lock_noload(head, name, error, mutex);
5297 + }
5298 + return ret;
5299 +}
5300 +#endif
5301 +
5302 +static inline struct ebt_table *
5303 +find_table_lock(const char *name, int *error, struct semaphore *mutex)
5304 +{
5305 + return find_inlist_lock(&ebt_tables, name, "ebtable_", error, mutex);
5306 +}
5307 +
5308 +static inline struct ebt_match *
5309 +find_match_lock(const char *name, int *error, struct semaphore *mutex)
5310 +{
5311 + return find_inlist_lock(&ebt_matches, name, "ebt_", error, mutex);
5312 +}
5313 +
5314 +static inline struct ebt_watcher *
5315 +find_watcher_lock(const char *name, int *error, struct semaphore *mutex)
5316 +{
5317 + return find_inlist_lock(&ebt_watchers, name, "ebt_", error, mutex);
5318 +}
5319 +
5320 +static inline struct ebt_target *
5321 +find_target_lock(const char *name, int *error, struct semaphore *mutex)
5322 +{
5323 + return find_inlist_lock(&ebt_targets, name, "ebt_", error, mutex);
5324 +}
5325 +
5326 +static inline int
5327 +ebt_check_match(struct ebt_entry_match *m, struct ebt_entry *e,
5328 + const char *name, unsigned int hookmask, unsigned int *cnt)
5329 +{
5330 + struct ebt_match *match;
5331 + int ret;
5332 +
5333 + if (((char *)m) + m->match_size + sizeof(struct ebt_entry_match) >
5334 + ((char *)e) + e->watchers_offset)
5335 + return -EINVAL;
5336 + match = find_match_lock(m->u.name, &ret, &ebt_mutex);
5337 + if (!match)
5338 + return ret;
5339 + m->u.match = match;
5340 + if (match->me)
5341 + __MOD_INC_USE_COUNT(match->me);
5342 + up(&ebt_mutex);
5343 + if (match->check &&
5344 + match->check(name, hookmask, e, m->data, m->match_size) != 0) {
5345 + BUGPRINT("match->check failed\n");
5346 + if (match->me)
5347 + __MOD_DEC_USE_COUNT(match->me);
5348 + return -EINVAL;
5349 + }
5350 + (*cnt)++;
5351 + return 0;
5352 +}
5353 +
5354 +static inline int
5355 +ebt_check_watcher(struct ebt_entry_watcher *w, struct ebt_entry *e,
5356 + const char *name, unsigned int hookmask, unsigned int *cnt)
5357 +{
5358 + struct ebt_watcher *watcher;
5359 + int ret;
5360 +
5361 + if (((char *)w) + w->watcher_size + sizeof(struct ebt_entry_watcher) >
5362 + ((char *)e) + e->target_offset)
5363 + return -EINVAL;
5364 + watcher = find_watcher_lock(w->u.name, &ret, &ebt_mutex);
5365 + if (!watcher)
5366 + return ret;
5367 + w->u.watcher = watcher;
5368 + if (watcher->me)
5369 + __MOD_INC_USE_COUNT(watcher->me);
5370 + up(&ebt_mutex);
5371 + if (watcher->check &&
5372 + watcher->check(name, hookmask, e, w->data, w->watcher_size) != 0) {
5373 + BUGPRINT("watcher->check failed\n");
5374 + if (watcher->me)
5375 + __MOD_DEC_USE_COUNT(watcher->me);
5376 + return -EINVAL;
5377 + }
5378 + (*cnt)++;
5379 + return 0;
5380 +}
5381 +
5382 +// this one is very careful, as it is the first function
5383 +// to parse the userspace data
5384 +static inline int
5385 +ebt_check_entry_size_and_hooks(struct ebt_entry *e,
5386 + struct ebt_table_info *newinfo, char *base, char *limit,
5387 + struct ebt_entries **hook_entries, unsigned int *n, unsigned int *cnt,
5388 + unsigned int *totalcnt, unsigned int *udc_cnt, unsigned int valid_hooks)
5389 +{
5390 + int i;
5391 +
5392 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
5393 + if ((valid_hooks & (1 << i)) == 0)
5394 + continue;
5395 + if ( (char *)hook_entries[i] - base ==
5396 + (char *)e - newinfo->entries)
5397 + break;
5398 + }
5399 + // beginning of a new chain
5400 + // if i == NF_BR_NUMHOOKS it must be a user defined chain
5401 + if (i != NF_BR_NUMHOOKS || !(e->bitmask & EBT_ENTRY_OR_ENTRIES)) {
5402 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) != 0) {
5403 + // we make userspace set this right,
5404 + // so there is no misunderstanding
5405 + BUGPRINT("EBT_ENTRY_OR_ENTRIES shouldn't be set "
5406 + "in distinguisher\n");
5407 + return -EINVAL;
5408 + }
5409 + // this checks if the previous chain has as many entries
5410 + // as it said it has
5411 + if (*n != *cnt) {
5412 + BUGPRINT("nentries does not equal the nr of entries "
5413 + "in the chain\n");
5414 + return -EINVAL;
5415 + }
5416 + // before we look at the struct, be sure it is not too big
5417 + if ((char *)hook_entries[i] + sizeof(struct ebt_entries)
5418 + > limit) {
5419 + BUGPRINT("entries_size too small\n");
5420 + return -EINVAL;
5421 + }
5422 + if (((struct ebt_entries *)e)->policy != EBT_DROP &&
5423 + ((struct ebt_entries *)e)->policy != EBT_ACCEPT) {
5424 + // only RETURN from udc
5425 + if (i != NF_BR_NUMHOOKS ||
5426 + ((struct ebt_entries *)e)->policy != EBT_RETURN) {
5427 + BUGPRINT("bad policy\n");
5428 + return -EINVAL;
5429 + }
5430 + }
5431 + if (i == NF_BR_NUMHOOKS) // it's a user defined chain
5432 + (*udc_cnt)++;
5433 + else
5434 + newinfo->hook_entry[i] = (struct ebt_entries *)e;
5435 + if (((struct ebt_entries *)e)->counter_offset != *totalcnt) {
5436 + BUGPRINT("counter_offset != totalcnt");
5437 + return -EINVAL;
5438 + }
5439 + *n = ((struct ebt_entries *)e)->nentries;
5440 + *cnt = 0;
5441 + return 0;
5442 + }
5443 + // a plain old entry, heh
5444 + if (sizeof(struct ebt_entry) > e->watchers_offset ||
5445 + e->watchers_offset > e->target_offset ||
5446 + e->target_offset >= e->next_offset) {
5447 + BUGPRINT("entry offsets not in right order\n");
5448 + return -EINVAL;
5449 + }
5450 + // this is not checked anywhere else
5451 + if (e->next_offset - e->target_offset < sizeof(struct ebt_entry_target)) {
5452 + BUGPRINT("target size too small\n");
5453 + return -EINVAL;
5454 + }
5455 +
5456 + (*cnt)++;
5457 + (*totalcnt)++;
5458 + return 0;
5459 +}
5460 +
5461 +struct ebt_cl_stack
5462 +{
5463 + struct ebt_chainstack cs;
5464 + int from;
5465 + unsigned int hookmask;
5466 +};
5467 +
5468 +// we need these positions to check that the jumps to a different part of the
5469 +// entries is a jump to the beginning of a new chain.
5470 +static inline int
5471 +ebt_get_udc_positions(struct ebt_entry *e, struct ebt_table_info *newinfo,
5472 + struct ebt_entries **hook_entries, unsigned int *n, unsigned int valid_hooks,
5473 + struct ebt_cl_stack *udc)
5474 +{
5475 + int i;
5476 +
5477 + // we're only interested in chain starts
5478 + if (e->bitmask & EBT_ENTRY_OR_ENTRIES)
5479 + return 0;
5480 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
5481 + if ((valid_hooks & (1 << i)) == 0)
5482 + continue;
5483 + if (newinfo->hook_entry[i] == (struct ebt_entries *)e)
5484 + break;
5485 + }
5486 + // only care about udc
5487 + if (i != NF_BR_NUMHOOKS)
5488 + return 0;
5489 +
5490 + udc[*n].cs.chaininfo = (struct ebt_entries *)e;
5491 + // these initialisations are depended on later in check_chainloops()
5492 + udc[*n].cs.n = 0;
5493 + udc[*n].hookmask = 0;
5494 +
5495 + (*n)++;
5496 + return 0;
5497 +}
5498 +
5499 +static inline int
5500 +ebt_cleanup_match(struct ebt_entry_match *m, unsigned int *i)
5501 +{
5502 + if (i && (*i)-- == 0)
5503 + return 1;
5504 + if (m->u.match->destroy)
5505 + m->u.match->destroy(m->data, m->match_size);
5506 + if (m->u.match->me)
5507 + __MOD_DEC_USE_COUNT(m->u.match->me);
5508 +
5509 + return 0;
5510 +}
5511 +
5512 +static inline int
5513 +ebt_cleanup_watcher(struct ebt_entry_watcher *w, unsigned int *i)
5514 +{
5515 + if (i && (*i)-- == 0)
5516 + return 1;
5517 + if (w->u.watcher->destroy)
5518 + w->u.watcher->destroy(w->data, w->watcher_size);
5519 + if (w->u.watcher->me)
5520 + __MOD_DEC_USE_COUNT(w->u.watcher->me);
5521 +
5522 + return 0;
5523 +}
5524 +
5525 +static inline int
5526 +ebt_cleanup_entry(struct ebt_entry *e, unsigned int *cnt)
5527 +{
5528 + struct ebt_entry_target *t;
5529 +
5530 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
5531 + return 0;
5532 + // we're done
5533 + if (cnt && (*cnt)-- == 0)
5534 + return 1;
5535 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, NULL);
5536 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, NULL);
5537 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
5538 + if (t->u.target->destroy)
5539 + t->u.target->destroy(t->data, t->target_size);
5540 + if (t->u.target->me)
5541 + __MOD_DEC_USE_COUNT(t->u.target->me);
5542 +
5543 + return 0;
5544 +}
5545 +
5546 +static inline int
5547 +ebt_check_entry(struct ebt_entry *e, struct ebt_table_info *newinfo,
5548 + const char *name, unsigned int *cnt, unsigned int valid_hooks,
5549 + struct ebt_cl_stack *cl_s, unsigned int udc_cnt)
5550 +{
5551 + struct ebt_entry_target *t;
5552 + struct ebt_target *target;
5553 + unsigned int i, j, hook = 0, hookmask = 0;
5554 + int ret;
5555 +
5556 + // Don't mess with the struct ebt_entries
5557 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
5558 + return 0;
5559 +
5560 + if (e->bitmask & ~EBT_F_MASK) {
5561 + BUGPRINT("Unknown flag for bitmask\n");
5562 + return -EINVAL;
5563 + }
5564 + if (e->invflags & ~EBT_INV_MASK) {
5565 + BUGPRINT("Unknown flag for inv bitmask\n");
5566 + return -EINVAL;
5567 + }
5568 + if ( (e->bitmask & EBT_NOPROTO) && (e->bitmask & EBT_802_3) ) {
5569 + BUGPRINT("NOPROTO & 802_3 not allowed\n");
5570 + return -EINVAL;
5571 + }
5572 + // what hook do we belong to?
5573 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
5574 + if ((valid_hooks & (1 << i)) == 0)
5575 + continue;
5576 + if ((char *)newinfo->hook_entry[i] < (char *)e)
5577 + hook = i;
5578 + else
5579 + break;
5580 + }
5581 + // (1 << NF_BR_NUMHOOKS) tells the check functions the rule is on
5582 + // a base chain
5583 + if (i < NF_BR_NUMHOOKS)
5584 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
5585 + else {
5586 + for (i = 0; i < udc_cnt; i++)
5587 + if ((char *)(cl_s[i].cs.chaininfo) > (char *)e)
5588 + break;
5589 + if (i == 0)
5590 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
5591 + else
5592 + hookmask = cl_s[i - 1].hookmask;
5593 + }
5594 + i = 0;
5595 + ret = EBT_MATCH_ITERATE(e, ebt_check_match, e, name, hookmask, &i);
5596 + if (ret != 0)
5597 + goto cleanup_matches;
5598 + j = 0;
5599 + ret = EBT_WATCHER_ITERATE(e, ebt_check_watcher, e, name, hookmask, &j);
5600 + if (ret != 0)
5601 + goto cleanup_watchers;
5602 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
5603 + target = find_target_lock(t->u.name, &ret, &ebt_mutex);
5604 + if (!target)
5605 + goto cleanup_watchers;
5606 + if (target->me)
5607 + __MOD_INC_USE_COUNT(target->me);
5608 + up(&ebt_mutex);
5609 +
5610 + t->u.target = target;
5611 + if (t->u.target == &ebt_standard_target) {
5612 + if (e->target_offset + sizeof(struct ebt_standard_target) >
5613 + e->next_offset) {
5614 + BUGPRINT("Standard target size too big\n");
5615 + ret = -EFAULT;
5616 + goto cleanup_watchers;
5617 + }
5618 + if (((struct ebt_standard_target *)t)->verdict <
5619 + -NUM_STANDARD_TARGETS) {
5620 + BUGPRINT("Invalid standard target\n");
5621 + ret = -EFAULT;
5622 + goto cleanup_watchers;
5623 + }
5624 + } else if ((e->target_offset + t->target_size +
5625 + sizeof(struct ebt_entry_target) > e->next_offset) ||
5626 + (t->u.target->check &&
5627 + t->u.target->check(name, hookmask, e, t->data, t->target_size) != 0)){
5628 + if (t->u.target->me)
5629 + __MOD_DEC_USE_COUNT(t->u.target->me);
5630 + ret = -EFAULT;
5631 + goto cleanup_watchers;
5632 + }
5633 + (*cnt)++;
5634 + return 0;
5635 +cleanup_watchers:
5636 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, &j);
5637 +cleanup_matches:
5638 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, &i);
5639 + return ret;
5640 +}
5641 +
5642 +// checks for loops and sets the hook mask for udc
5643 +// the hook mask for udc tells us from which base chains the udc can be
5644 +// accessed. This mask is a parameter to the check() functions of the extensions
5645 +static int check_chainloops(struct ebt_entries *chain,
5646 + struct ebt_cl_stack *cl_s, unsigned int udc_cnt,
5647 + unsigned int hooknr, char *base)
5648 +{
5649 + int i, chain_nr = -1, pos = 0, nentries = chain->nentries, verdict;
5650 + struct ebt_entry *e = (struct ebt_entry *)chain->data;
5651 + struct ebt_entry_target *t;
5652 +
5653 + while (pos < nentries || chain_nr != -1) {
5654 + // end of udc, go back one 'recursion' step
5655 + if (pos == nentries) {
5656 + // put back values of the time when this chain was called
5657 + e = cl_s[chain_nr].cs.e;
5658 + if (cl_s[chain_nr].from != -1)
5659 + nentries =
5660 + cl_s[cl_s[chain_nr].from].cs.chaininfo->nentries;
5661 + else
5662 + nentries = chain->nentries;
5663 + pos = cl_s[chain_nr].cs.n;
5664 + // make sure we won't see a loop that isn't one
5665 + cl_s[chain_nr].cs.n = 0;
5666 + chain_nr = cl_s[chain_nr].from;
5667 + if (pos == nentries)
5668 + continue;
5669 + }
5670 + t = (struct ebt_entry_target *)
5671 + (((char *)e) + e->target_offset);
5672 + if (strcmp(t->u.name, EBT_STANDARD_TARGET))
5673 + goto letscontinue;
5674 + if (e->target_offset + sizeof(struct ebt_standard_target) >
5675 + e->next_offset) {
5676 + BUGPRINT("Standard target size too big\n");
5677 + return -1;
5678 + }
5679 + verdict = ((struct ebt_standard_target *)t)->verdict;
5680 + if (verdict >= 0) { // jump to another chain
5681 + struct ebt_entries *hlp2 =
5682 + (struct ebt_entries *)(base + verdict);
5683 + for (i = 0; i < udc_cnt; i++)
5684 + if (hlp2 == cl_s[i].cs.chaininfo)
5685 + break;
5686 + // bad destination or loop
5687 + if (i == udc_cnt) {
5688 + BUGPRINT("bad destination\n");
5689 + return -1;
5690 + }
5691 + if (cl_s[i].cs.n) {
5692 + BUGPRINT("loop\n");
5693 + return -1;
5694 + }
5695 + // this can't be 0, so the above test is correct
5696 + cl_s[i].cs.n = pos + 1;
5697 + pos = 0;
5698 + cl_s[i].cs.e = ((void *)e + e->next_offset);
5699 + e = (struct ebt_entry *)(hlp2->data);
5700 + nentries = hlp2->nentries;
5701 + cl_s[i].from = chain_nr;
5702 + chain_nr = i;
5703 + // this udc is accessible from the base chain for hooknr
5704 + cl_s[i].hookmask |= (1 << hooknr);
5705 + continue;
5706 + }
5707 +letscontinue:
5708 + e = (void *)e + e->next_offset;
5709 + pos++;
5710 + }
5711 + return 0;
5712 +}
5713 +
5714 +// do the parsing of the table/chains/entries/matches/watchers/targets, heh
5715 +static int translate_table(struct ebt_replace *repl,
5716 + struct ebt_table_info *newinfo)
5717 +{
5718 + unsigned int i, j, k, udc_cnt;
5719 + int ret;
5720 + struct ebt_cl_stack *cl_s = NULL; // used in the checking for chain loops
5721 +
5722 + i = 0;
5723 + while (i < NF_BR_NUMHOOKS && !(repl->valid_hooks & (1 << i)))
5724 + i++;
5725 + if (i == NF_BR_NUMHOOKS) {
5726 + BUGPRINT("No valid hooks specified\n");
5727 + return -EINVAL;
5728 + }
5729 + if (repl->hook_entry[i] != (struct ebt_entries *)repl->entries) {
5730 + BUGPRINT("Chains don't start at beginning\n");
5731 + return -EINVAL;
5732 + }
5733 + // make sure chains are ordered after each other in same order
5734 + // as their corresponding hooks
5735 + for (j = i + 1; j < NF_BR_NUMHOOKS; j++) {
5736 + if (!(repl->valid_hooks & (1 << j)))
5737 + continue;
5738 + if ( repl->hook_entry[j] <= repl->hook_entry[i] ) {
5739 + BUGPRINT("Hook order must be followed\n");
5740 + return -EINVAL;
5741 + }
5742 + i = j;
5743 + }
5744 +
5745 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
5746 + newinfo->hook_entry[i] = NULL;
5747 +
5748 + newinfo->entries_size = repl->entries_size;
5749 + newinfo->nentries = repl->nentries;
5750 +
5751 + // do some early checkings and initialize some things
5752 + i = 0; // holds the expected nr. of entries for the chain
5753 + j = 0; // holds the up to now counted entries for the chain
5754 + k = 0; // holds the total nr. of entries, should equal
5755 + // newinfo->nentries afterwards
5756 + udc_cnt = 0; // will hold the nr. of user defined chains (udc)
5757 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5758 + ebt_check_entry_size_and_hooks, newinfo, repl->entries,
5759 + repl->entries + repl->entries_size, repl->hook_entry, &i, &j, &k,
5760 + &udc_cnt, repl->valid_hooks);
5761 +
5762 + if (ret != 0)
5763 + return ret;
5764 +
5765 + if (i != j) {
5766 + BUGPRINT("nentries does not equal the nr of entries in the "
5767 + "(last) chain\n");
5768 + return -EINVAL;
5769 + }
5770 + if (k != newinfo->nentries) {
5771 + BUGPRINT("Total nentries is wrong\n");
5772 + return -EINVAL;
5773 + }
5774 +
5775 + // check if all valid hooks have a chain
5776 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
5777 + if (newinfo->hook_entry[i] == NULL &&
5778 + (repl->valid_hooks & (1 << i))) {
5779 + BUGPRINT("Valid hook without chain\n");
5780 + return -EINVAL;
5781 + }
5782 + }
5783 +
5784 + // Get the location of the udc, put them in an array
5785 + // While we're at it, allocate the chainstack
5786 + if (udc_cnt) {
5787 + // this will get free'd in do_replace()/ebt_register_table()
5788 + // if an error occurs
5789 + newinfo->chainstack = (struct ebt_chainstack **)
5790 + vmalloc(smp_num_cpus * sizeof(struct ebt_chainstack));
5791 + if (!newinfo->chainstack)
5792 + return -ENOMEM;
5793 + for (i = 0; i < smp_num_cpus; i++) {
5794 + newinfo->chainstack[i] =
5795 + vmalloc(udc_cnt * sizeof(struct ebt_chainstack));
5796 + if (!newinfo->chainstack[i]) {
5797 + while (i)
5798 + vfree(newinfo->chainstack[--i]);
5799 + vfree(newinfo->chainstack);
5800 + newinfo->chainstack = NULL;
5801 + return -ENOMEM;
5802 + }
5803 + }
5804 +
5805 + cl_s = (struct ebt_cl_stack *)
5806 + vmalloc(udc_cnt * sizeof(struct ebt_cl_stack));
5807 + if (!cl_s)
5808 + return -ENOMEM;
5809 + i = 0; // the i'th udc
5810 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5811 + ebt_get_udc_positions, newinfo, repl->hook_entry, &i,
5812 + repl->valid_hooks, cl_s);
5813 + // sanity check
5814 + if (i != udc_cnt) {
5815 + BUGPRINT("i != udc_cnt\n");
5816 + vfree(cl_s);
5817 + return -EFAULT;
5818 + }
5819 + }
5820 +
5821 + // Check for loops
5822 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
5823 + if (repl->valid_hooks & (1 << i))
5824 + if (check_chainloops(newinfo->hook_entry[i],
5825 + cl_s, udc_cnt, i, newinfo->entries)) {
5826 + if (cl_s)
5827 + vfree(cl_s);
5828 + return -EINVAL;
5829 + }
5830 +
5831 + // we now know the following (along with E=mc):
5832 + // - the nr of entries in each chain is right
5833 + // - the size of the allocated space is right
5834 + // - all valid hooks have a corresponding chain
5835 + // - there are no loops
5836 + // - wrong data can still be on the level of a single entry
5837 + // - could be there are jumps to places that are not the
5838 + // beginning of a chain. This can only occur in chains that
5839 + // are not accessible from any base chains, so we don't care.
5840 +
5841 + // used to know what we need to clean up if something goes wrong
5842 + i = 0;
5843 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5844 + ebt_check_entry, newinfo, repl->name, &i, repl->valid_hooks,
5845 + cl_s, udc_cnt);
5846 + if (ret != 0) {
5847 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5848 + ebt_cleanup_entry, &i);
5849 + }
5850 + if (cl_s)
5851 + vfree(cl_s);
5852 + return ret;
5853 +}
5854 +
5855 +// called under write_lock
5856 +static void get_counters(struct ebt_counter *oldcounters,
5857 + struct ebt_counter *counters, unsigned int nentries)
5858 +{
5859 + int i, cpu;
5860 + struct ebt_counter *counter_base;
5861 +
5862 + // counters of cpu 0
5863 + memcpy(counters, oldcounters,
5864 + sizeof(struct ebt_counter) * nentries);
5865 + // add other counters to those of cpu 0
5866 + for (cpu = 1; cpu < smp_num_cpus; cpu++) {
5867 + counter_base = COUNTER_BASE(oldcounters, nentries, cpu);
5868 + for (i = 0; i < nentries; i++) {
5869 + counters[i].pcnt += counter_base[i].pcnt;
5870 + counters[i].bcnt += counter_base[i].bcnt;
5871 + }
5872 + }
5873 +}
5874 +
5875 +// replace the table
5876 +static int do_replace(void *user, unsigned int len)
5877 +{
5878 + int ret, i, countersize;
5879 + struct ebt_table_info *newinfo;
5880 + struct ebt_replace tmp;
5881 + struct ebt_table *t;
5882 + struct ebt_counter *counterstmp = NULL;
5883 + // used to be able to unlock earlier
5884 + struct ebt_table_info *table;
5885 +
5886 + if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
5887 + return -EFAULT;
5888 +
5889 + if (len != sizeof(tmp) + tmp.entries_size) {
5890 + BUGPRINT("Wrong len argument\n");
5891 + return -EINVAL;
5892 + }
5893 +
5894 + if (tmp.entries_size == 0) {
5895 + BUGPRINT("Entries_size never zero\n");
5896 + return -EINVAL;
5897 + }
5898 + countersize = COUNTER_OFFSET(tmp.nentries) * smp_num_cpus;
5899 + newinfo = (struct ebt_table_info *)
5900 + vmalloc(sizeof(struct ebt_table_info) + countersize);
5901 + if (!newinfo)
5902 + return -ENOMEM;
5903 +
5904 + if (countersize)
5905 + memset(newinfo->counters, 0, countersize);
5906 +
5907 + newinfo->entries = (char *)vmalloc(tmp.entries_size);
5908 + if (!newinfo->entries) {
5909 + ret = -ENOMEM;
5910 + goto free_newinfo;
5911 + }
5912 + if (copy_from_user(
5913 + newinfo->entries, tmp.entries, tmp.entries_size) != 0) {
5914 + BUGPRINT("Couldn't copy entries from userspace\n");
5915 + ret = -EFAULT;
5916 + goto free_entries;
5917 + }
5918 +
5919 + // the user wants counters back
5920 + // the check on the size is done later, when we have the lock
5921 + if (tmp.num_counters) {
5922 + counterstmp = (struct ebt_counter *)
5923 + vmalloc(tmp.num_counters * sizeof(struct ebt_counter));
5924 + if (!counterstmp) {
5925 + ret = -ENOMEM;
5926 + goto free_entries;
5927 + }
5928 + }
5929 + else
5930 + counterstmp = NULL;
5931 +
5932 + // this can get initialized by translate_table()
5933 + newinfo->chainstack = NULL;
5934 + ret = translate_table(&tmp, newinfo);
5935 +
5936 + if (ret != 0)
5937 + goto free_counterstmp;
5938 +
5939 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
5940 + if (!t)
5941 + goto free_iterate;
5942 +
5943 + // the table doesn't like it
5944 + if (t->check && (ret = t->check(newinfo, tmp.valid_hooks)))
5945 + goto free_unlock;
5946 +
5947 + if (tmp.num_counters && tmp.num_counters != t->private->nentries) {
5948 + BUGPRINT("Wrong nr. of counters requested\n");
5949 + ret = -EINVAL;
5950 + goto free_unlock;
5951 + }
5952 +
5953 + // we have the mutex lock, so no danger in reading this pointer
5954 + table = t->private;
5955 + // we need an atomic snapshot of the counters
5956 + write_lock_bh(&t->lock);
5957 + if (tmp.num_counters)
5958 + get_counters(t->private->counters, counterstmp,
5959 + t->private->nentries);
5960 +
5961 + t->private = newinfo;
5962 + write_unlock_bh(&t->lock);
5963 + up(&ebt_mutex);
5964 + // So, a user can change the chains while having messed up her counter
5965 + // allocation. Only reason why this is done is because this way the lock
5966 + // is held only once, while this doesn't bring the kernel into a
5967 + // dangerous state.
5968 + if (tmp.num_counters &&
5969 + copy_to_user(tmp.counters, counterstmp,
5970 + tmp.num_counters * sizeof(struct ebt_counter))) {
5971 + BUGPRINT("Couldn't copy counters to userspace\n");
5972 + ret = -EFAULT;
5973 + }
5974 + else
5975 + ret = 0;
5976 +
5977 + // decrease module count and free resources
5978 + EBT_ENTRY_ITERATE(table->entries, table->entries_size,
5979 + ebt_cleanup_entry, NULL);
5980 +
5981 + vfree(table->entries);
5982 + if (table->chainstack) {
5983 + for (i = 0; i < smp_num_cpus; i++)
5984 + vfree(table->chainstack[i]);
5985 + vfree(table->chainstack);
5986 + }
5987 + vfree(table);
5988 +
5989 + if (counterstmp)
5990 + vfree(counterstmp);
5991 + return ret;
5992 +
5993 +free_unlock:
5994 + up(&ebt_mutex);
5995 +free_iterate:
5996 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5997 + ebt_cleanup_entry, NULL);
5998 +free_counterstmp:
5999 + if (counterstmp)
6000 + vfree(counterstmp);
6001 + // can be initialized in translate_table()
6002 + if (newinfo->chainstack) {
6003 + for (i = 0; i < smp_num_cpus; i++)
6004 + vfree(newinfo->chainstack[i]);
6005 + vfree(newinfo->chainstack);
6006 + }
6007 +free_entries:
6008 + if (newinfo->entries)
6009 + vfree(newinfo->entries);
6010 +free_newinfo:
6011 + if (newinfo)
6012 + vfree(newinfo);
6013 + return ret;
6014 +}
6015 +
6016 +int ebt_register_target(struct ebt_target *target)
6017 +{
6018 + int ret;
6019 +
6020 + ret = down_interruptible(&ebt_mutex);
6021 + if (ret != 0)
6022 + return ret;
6023 + if (!list_named_insert(&ebt_targets, target)) {
6024 + up(&ebt_mutex);
6025 + return -EEXIST;
6026 + }
6027 + up(&ebt_mutex);
6028 + MOD_INC_USE_COUNT;
6029 +
6030 + return 0;
6031 +}
6032 +
6033 +void ebt_unregister_target(struct ebt_target *target)
6034 +{
6035 + down(&ebt_mutex);
6036 + LIST_DELETE(&ebt_targets, target);
6037 + up(&ebt_mutex);
6038 + MOD_DEC_USE_COUNT;
6039 +}
6040 +
6041 +int ebt_register_match(struct ebt_match *match)
6042 +{
6043 + int ret;
6044 +
6045 + ret = down_interruptible(&ebt_mutex);
6046 + if (ret != 0)
6047 + return ret;
6048 + if (!list_named_insert(&ebt_matches, match)) {
6049 + up(&ebt_mutex);
6050 + return -EEXIST;
6051 + }
6052 + up(&ebt_mutex);
6053 + MOD_INC_USE_COUNT;
6054 +
6055 + return 0;
6056 +}
6057 +
6058 +void ebt_unregister_match(struct ebt_match *match)
6059 +{
6060 + down(&ebt_mutex);
6061 + LIST_DELETE(&ebt_matches, match);
6062 + up(&ebt_mutex);
6063 + MOD_DEC_USE_COUNT;
6064 +}
6065 +
6066 +int ebt_register_watcher(struct ebt_watcher *watcher)
6067 +{
6068 + int ret;
6069 +
6070 + ret = down_interruptible(&ebt_mutex);
6071 + if (ret != 0)
6072 + return ret;
6073 + if (!list_named_insert(&ebt_watchers, watcher)) {
6074 + up(&ebt_mutex);
6075 + return -EEXIST;
6076 + }
6077 + up(&ebt_mutex);
6078 + MOD_INC_USE_COUNT;
6079 +
6080 + return 0;
6081 +}
6082 +
6083 +void ebt_unregister_watcher(struct ebt_watcher *watcher)
6084 +{
6085 + down(&ebt_mutex);
6086 + LIST_DELETE(&ebt_watchers, watcher);
6087 + up(&ebt_mutex);
6088 + MOD_DEC_USE_COUNT;
6089 +}
6090 +
6091 +int ebt_register_table(struct ebt_table *table)
6092 +{
6093 + struct ebt_table_info *newinfo;
6094 + int ret, i, countersize;
6095 +
6096 + if (!table || !table->table ||!table->table->entries ||
6097 + table->table->entries_size == 0 ||
6098 + table->table->counters || table->private) {
6099 + BUGPRINT("Bad table data for ebt_register_table!!!\n");
6100 + return -EINVAL;
6101 + }
6102 +
6103 + countersize = COUNTER_OFFSET(table->table->nentries) * smp_num_cpus;
6104 + newinfo = (struct ebt_table_info *)
6105 + vmalloc(sizeof(struct ebt_table_info) + countersize);
6106 + ret = -ENOMEM;
6107 + if (!newinfo)
6108 + return -ENOMEM;
6109 +
6110 + newinfo->entries = (char *)vmalloc(table->table->entries_size);
6111 + if (!(newinfo->entries))
6112 + goto free_newinfo;
6113 +
6114 + memcpy(newinfo->entries, table->table->entries,
6115 + table->table->entries_size);
6116 +
6117 + if (countersize)
6118 + memset(newinfo->counters, 0, countersize);
6119 +
6120 + // fill in newinfo and parse the entries
6121 + newinfo->chainstack = NULL;
6122 + ret = translate_table(table->table, newinfo);
6123 + if (ret != 0) {
6124 + BUGPRINT("Translate_table failed\n");
6125 + goto free_chainstack;
6126 + }
6127 +
6128 + if (table->check && table->check(newinfo, table->valid_hooks)) {
6129 + BUGPRINT("The table doesn't like its own initial data, lol\n");
6130 + return -EINVAL;
6131 + }
6132 +
6133 + table->private = newinfo;
6134 + table->lock = RW_LOCK_UNLOCKED;
6135 + ret = down_interruptible(&ebt_mutex);
6136 + if (ret != 0)
6137 + goto free_chainstack;
6138 +
6139 + if (list_named_find(&ebt_tables, table->name)) {
6140 + ret = -EEXIST;
6141 + BUGPRINT("Table name already exists\n");
6142 + goto free_unlock;
6143 + }
6144 +
6145 + list_prepend(&ebt_tables, table);
6146 + up(&ebt_mutex);
6147 + MOD_INC_USE_COUNT;
6148 + return 0;
6149 +free_unlock:
6150 + up(&ebt_mutex);
6151 +free_chainstack:
6152 + if (newinfo->chainstack) {
6153 + for (i = 0; i < smp_num_cpus; i++)
6154 + vfree(newinfo->chainstack[i]);
6155 + vfree(newinfo->chainstack);
6156 + }
6157 + vfree(newinfo->entries);
6158 +free_newinfo:
6159 + vfree(newinfo);
6160 + return ret;
6161 +}
6162 +
6163 +void ebt_unregister_table(struct ebt_table *table)
6164 +{
6165 + int i;
6166 +
6167 + if (!table) {
6168 + BUGPRINT("Request to unregister NULL table!!!\n");
6169 + return;
6170 + }
6171 + down(&ebt_mutex);
6172 + LIST_DELETE(&ebt_tables, table);
6173 + up(&ebt_mutex);
6174 + EBT_ENTRY_ITERATE(table->private->entries,
6175 + table->private->entries_size, ebt_cleanup_entry, NULL);
6176 + if (table->private->entries)
6177 + vfree(table->private->entries);
6178 + if (table->private->chainstack) {
6179 + for (i = 0; i < smp_num_cpus; i++)
6180 + vfree(table->private->chainstack[i]);
6181 + vfree(table->private->chainstack);
6182 + }
6183 + vfree(table->private);
6184 + MOD_DEC_USE_COUNT;
6185 +}
6186 +
6187 +// userspace just supplied us with counters
6188 +static int update_counters(void *user, unsigned int len)
6189 +{
6190 + int i, ret;
6191 + struct ebt_counter *tmp;
6192 + struct ebt_replace hlp;
6193 + struct ebt_table *t;
6194 +
6195 + if (copy_from_user(&hlp, user, sizeof(hlp)))
6196 + return -EFAULT;
6197 +
6198 + if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
6199 + return -EINVAL;
6200 + if (hlp.num_counters == 0)
6201 + return -EINVAL;
6202 +
6203 + if ( !(tmp = (struct ebt_counter *)
6204 + vmalloc(hlp.num_counters * sizeof(struct ebt_counter))) ){
6205 + MEMPRINT("Update_counters && nomemory\n");
6206 + return -ENOMEM;
6207 + }
6208 +
6209 + t = find_table_lock(hlp.name, &ret, &ebt_mutex);
6210 + if (!t)
6211 + goto free_tmp;
6212 +
6213 + if (hlp.num_counters != t->private->nentries) {
6214 + BUGPRINT("Wrong nr of counters\n");
6215 + ret = -EINVAL;
6216 + goto unlock_mutex;
6217 + }
6218 +
6219 + if ( copy_from_user(tmp, hlp.counters,
6220 + hlp.num_counters * sizeof(struct ebt_counter)) ) {
6221 + BUGPRINT("Updata_counters && !cfu\n");
6222 + ret = -EFAULT;
6223 + goto unlock_mutex;
6224 + }
6225 +
6226 + // we want an atomic add of the counters
6227 + write_lock_bh(&t->lock);
6228 +
6229 + // we add to the counters of the first cpu
6230 + for (i = 0; i < hlp.num_counters; i++) {
6231 + t->private->counters[i].pcnt += tmp[i].pcnt;
6232 + t->private->counters[i].bcnt += tmp[i].bcnt;
6233 + }
6234 +
6235 + write_unlock_bh(&t->lock);
6236 + ret = 0;
6237 +unlock_mutex:
6238 + up(&ebt_mutex);
6239 +free_tmp:
6240 + vfree(tmp);
6241 + return ret;
6242 +}
6243 +
6244 +static inline int ebt_make_matchname(struct ebt_entry_match *m,
6245 + char *base, char *ubase)
6246 +{
6247 + char *hlp = ubase - base + (char *)m;
6248 + if (copy_to_user(hlp, m->u.match->name, EBT_FUNCTION_MAXNAMELEN))
6249 + return -EFAULT;
6250 + return 0;
6251 +}
6252 +
6253 +static inline int ebt_make_watchername(struct ebt_entry_watcher *w,
6254 + char *base, char *ubase)
6255 +{
6256 + char *hlp = ubase - base + (char *)w;
6257 + if (copy_to_user(hlp , w->u.watcher->name, EBT_FUNCTION_MAXNAMELEN))
6258 + return -EFAULT;
6259 + return 0;
6260 +}
6261 +
6262 +static inline int ebt_make_names(struct ebt_entry *e, char *base, char *ubase)
6263 +{
6264 + int ret;
6265 + char *hlp;
6266 + struct ebt_entry_target *t;
6267 +
6268 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
6269 + return 0;
6270 +
6271 + hlp = ubase - base + (char *)e + e->target_offset;
6272 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
6273 +
6274 + ret = EBT_MATCH_ITERATE(e, ebt_make_matchname, base, ubase);
6275 + if (ret != 0)
6276 + return ret;
6277 + ret = EBT_WATCHER_ITERATE(e, ebt_make_watchername, base, ubase);
6278 + if (ret != 0)
6279 + return ret;
6280 + if (copy_to_user(hlp, t->u.target->name, EBT_FUNCTION_MAXNAMELEN))
6281 + return -EFAULT;
6282 + return 0;
6283 +}
6284 +
6285 +// called with ebt_mutex down
6286 +static int copy_everything_to_user(struct ebt_table *t, void *user,
6287 + int *len, int cmd)
6288 +{
6289 + struct ebt_replace tmp;
6290 + struct ebt_counter *counterstmp, *oldcounters;
6291 + unsigned int entries_size, nentries;
6292 + char *entries;
6293 +
6294 + if (cmd == EBT_SO_GET_ENTRIES) {
6295 + entries_size = t->private->entries_size;
6296 + nentries = t->private->nentries;
6297 + entries = t->private->entries;
6298 + oldcounters = t->private->counters;
6299 + } else {
6300 + entries_size = t->table->entries_size;
6301 + nentries = t->table->nentries;
6302 + entries = t->table->entries;
6303 + oldcounters = t->table->counters;
6304 + }
6305 +
6306 + if (copy_from_user(&tmp, user, sizeof(tmp))) {
6307 + BUGPRINT("Cfu didn't work\n");
6308 + return -EFAULT;
6309 + }
6310 +
6311 + if (*len != sizeof(struct ebt_replace) + entries_size +
6312 + (tmp.num_counters? nentries * sizeof(struct ebt_counter): 0)) {
6313 + BUGPRINT("Wrong size\n");
6314 + return -EINVAL;
6315 + }
6316 +
6317 + if (tmp.nentries != nentries) {
6318 + BUGPRINT("Nentries wrong\n");
6319 + return -EINVAL;
6320 + }
6321 +
6322 + if (tmp.entries_size != entries_size) {
6323 + BUGPRINT("Wrong size\n");
6324 + return -EINVAL;
6325 + }
6326 +
6327 + // userspace might not need the counters
6328 + if (tmp.num_counters) {
6329 + if (tmp.num_counters != nentries) {
6330 + BUGPRINT("Num_counters wrong\n");
6331 + return -EINVAL;
6332 + }
6333 + counterstmp = (struct ebt_counter *)
6334 + vmalloc(nentries * sizeof(struct ebt_counter));
6335 + if (!counterstmp) {
6336 + MEMPRINT("Couldn't copy counters, out of memory\n");
6337 + return -ENOMEM;
6338 + }
6339 + write_lock_bh(&t->lock);
6340 + get_counters(oldcounters, counterstmp, nentries);
6341 + write_unlock_bh(&t->lock);
6342 +
6343 + if (copy_to_user(tmp.counters, counterstmp,
6344 + nentries * sizeof(struct ebt_counter))) {
6345 + BUGPRINT("Couldn't copy counters to userspace\n");
6346 + vfree(counterstmp);
6347 + return -EFAULT;
6348 + }
6349 + vfree(counterstmp);
6350 + }
6351 +
6352 + if (copy_to_user(tmp.entries, entries, entries_size)) {
6353 + BUGPRINT("Couldn't copy entries to userspace\n");
6354 + return -EFAULT;
6355 + }
6356 + // set the match/watcher/target names right
6357 + return EBT_ENTRY_ITERATE(entries, entries_size,
6358 + ebt_make_names, entries, tmp.entries);
6359 +}
6360 +
6361 +static int do_ebt_set_ctl(struct sock *sk,
6362 + int cmd, void *user, unsigned int len)
6363 +{
6364 + int ret;
6365 +
6366 + switch(cmd) {
6367 + case EBT_SO_SET_ENTRIES:
6368 + ret = do_replace(user, len);
6369 + break;
6370 + case EBT_SO_SET_COUNTERS:
6371 + ret = update_counters(user, len);
6372 + break;
6373 + default:
6374 + ret = -EINVAL;
6375 + }
6376 + return ret;
6377 +}
6378 +
6379 +static int do_ebt_get_ctl(struct sock *sk, int cmd, void *user, int *len)
6380 +{
6381 + int ret;
6382 + struct ebt_replace tmp;
6383 + struct ebt_table *t;
6384 +
6385 + if (copy_from_user(&tmp, user, sizeof(tmp)))
6386 + return -EFAULT;
6387 +
6388 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
6389 + if (!t)
6390 + return ret;
6391 +
6392 + switch(cmd) {
6393 + case EBT_SO_GET_INFO:
6394 + case EBT_SO_GET_INIT_INFO:
6395 + if (*len != sizeof(struct ebt_replace)){
6396 + ret = -EINVAL;
6397 + up(&ebt_mutex);
6398 + break;
6399 + }
6400 + if (cmd == EBT_SO_GET_INFO) {
6401 + tmp.nentries = t->private->nentries;
6402 + tmp.entries_size = t->private->entries_size;
6403 + tmp.valid_hooks = t->valid_hooks;
6404 + } else {
6405 + tmp.nentries = t->table->nentries;
6406 + tmp.entries_size = t->table->entries_size;
6407 + tmp.valid_hooks = t->table->valid_hooks;
6408 + }
6409 + up(&ebt_mutex);
6410 + if (copy_to_user(user, &tmp, *len) != 0){
6411 + BUGPRINT("c2u Didn't work\n");
6412 + ret = -EFAULT;
6413 + break;
6414 + }
6415 + ret = 0;
6416 + break;
6417 +
6418 + case EBT_SO_GET_ENTRIES:
6419 + case EBT_SO_GET_INIT_ENTRIES:
6420 + ret = copy_everything_to_user(t, user, len, cmd);
6421 + up(&ebt_mutex);
6422 + break;
6423 +
6424 + default:
6425 + up(&ebt_mutex);
6426 + ret = -EINVAL;
6427 + }
6428 +
6429 + return ret;
6430 +}
6431 +
6432 +static struct nf_sockopt_ops ebt_sockopts =
6433 +{ { NULL, NULL }, PF_INET, EBT_BASE_CTL, EBT_SO_SET_MAX + 1, do_ebt_set_ctl,
6434 + EBT_BASE_CTL, EBT_SO_GET_MAX + 1, do_ebt_get_ctl, 0, NULL
6435 +};
6436 +
6437 +static int __init init(void)
6438 +{
6439 + int ret;
6440 +
6441 + if (br_netfilter_init())
6442 + return 1;
6443 +
6444 + down(&ebt_mutex);
6445 + list_named_insert(&ebt_targets, &ebt_standard_target);
6446 + up(&ebt_mutex);
6447 + if ((ret = nf_register_sockopt(&ebt_sockopts)) < 0)
6448 + return ret;
6449 +
6450 + printk(KERN_NOTICE "Ebtables v2.0 registered\n");
6451 + return 0;
6452 +}
6453 +
6454 +static void __exit fini(void)
6455 +{
6456 + nf_unregister_sockopt(&ebt_sockopts);
6457 + printk(KERN_NOTICE "Ebtables v2.0 unregistered\n");
6458 +
6459 + br_netfilter_fini();
6460 +}
6461 +
6462 +EXPORT_SYMBOL(ebt_register_table);
6463 +EXPORT_SYMBOL(ebt_unregister_table);
6464 +EXPORT_SYMBOL(ebt_register_match);
6465 +EXPORT_SYMBOL(ebt_unregister_match);
6466 +EXPORT_SYMBOL(ebt_register_watcher);
6467 +EXPORT_SYMBOL(ebt_unregister_watcher);
6468 +EXPORT_SYMBOL(ebt_register_target);
6469 +EXPORT_SYMBOL(ebt_unregister_target);
6470 +EXPORT_SYMBOL(ebt_do_table);
6471 +module_init(init);
6472 +module_exit(fini);
6473 +MODULE_LICENSE("GPL");
6474 diff -Nur linux.old/net/core/dev.c linux.dev/net/core/dev.c
6475 --- linux.old/net/core/dev.c 2005-10-10 10:33:06.872169000 +0200
6476 +++ linux.dev/net/core/dev.c 2005-10-10 10:36:45.969861750 +0200
6477 @@ -1439,7 +1439,7 @@
6478
6479
6480 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6481 -void (*br_handle_frame_hook)(struct sk_buff *skb) = NULL;
6482 +int (*br_handle_frame_hook)(struct sk_buff *skb) = NULL;
6483 #endif
6484
6485 static __inline__ int handle_bridge(struct sk_buff *skb,
6486 @@ -1456,7 +1456,6 @@
6487 }
6488 }
6489
6490 - br_handle_frame_hook(skb);
6491 return ret;
6492 }
6493
6494 @@ -1516,7 +1515,12 @@
6495 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6496 if (skb->dev->br_port != NULL && br_handle_frame_hook != NULL &&
6497 skb->pkt_type != PACKET_LOOPBACK) {
6498 - return handle_bridge(skb, pt_prev);
6499 + int ret;
6500 +
6501 + ret = handle_bridge(skb, pt_prev);
6502 + if (br_handle_frame_hook(skb) == 0)
6503 + return ret;
6504 + pt_prev = NULL;
6505 }
6506 #endif
6507
6508 diff -Nur linux.old/net/core/netfilter.c linux.dev/net/core/netfilter.c
6509 --- linux.old/net/core/netfilter.c 2005-01-19 15:10:13.000000000 +0100
6510 +++ linux.dev/net/core/netfilter.c 2005-10-10 10:36:46.197876000 +0200
6511 @@ -342,32 +342,29 @@
6512 const struct net_device *indev,
6513 const struct net_device *outdev,
6514 struct list_head **i,
6515 - int (*okfn)(struct sk_buff *))
6516 + int (*okfn)(struct sk_buff *),
6517 + int hook_thresh)
6518 {
6519 + unsigned int verdict;
6520 +
6521 for (*i = (*i)->next; *i != head; *i = (*i)->next) {
6522 struct nf_hook_ops *elem = (struct nf_hook_ops *)*i;
6523 - switch (elem->hook(hook, skb, indev, outdev, okfn)) {
6524 - case NF_QUEUE:
6525 - return NF_QUEUE;
6526 -
6527 - case NF_STOLEN:
6528 - return NF_STOLEN;
6529 -
6530 - case NF_DROP:
6531 - return NF_DROP;
6532
6533 - case NF_REPEAT:
6534 - *i = (*i)->prev;
6535 - break;
6536 + if (hook_thresh > elem->priority)
6537 + continue;
6538
6539 + verdict = elem->hook(hook, skb, indev, outdev, okfn);
6540 + if (verdict != NF_ACCEPT) {
6541 #ifdef CONFIG_NETFILTER_DEBUG
6542 - case NF_ACCEPT:
6543 - break;
6544 -
6545 - default:
6546 - NFDEBUG("Evil return from %p(%u).\n",
6547 - elem->hook, hook);
6548 + if (unlikely(verdict > NF_MAX_VERDICT)) {
6549 + NFDEBUG("Evil return from %p(%u).\n",
6550 + elem->hook, hook);
6551 + continue;
6552 + }
6553 #endif
6554 + if (verdict != NF_REPEAT)
6555 + return verdict;
6556 + *i = (*i)->prev;
6557 }
6558 }
6559 return NF_ACCEPT;
6560 @@ -413,6 +410,10 @@
6561 {
6562 int status;
6563 struct nf_info *info;
6564 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6565 + struct net_device *physindev = NULL;
6566 + struct net_device *physoutdev = NULL;
6567 +#endif
6568
6569 if (!queue_handler[pf].outfn) {
6570 kfree_skb(skb);
6571 @@ -435,36 +436,52 @@
6572 if (indev) dev_hold(indev);
6573 if (outdev) dev_hold(outdev);
6574
6575 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6576 + if (skb->nf_bridge) {
6577 + physindev = skb->nf_bridge->physindev;
6578 + if (physindev) dev_hold(physindev);
6579 + physoutdev = skb->nf_bridge->physoutdev;
6580 + if (physoutdev) dev_hold(physoutdev);
6581 + }
6582 +#endif
6583 +
6584 status = queue_handler[pf].outfn(skb, info, queue_handler[pf].data);
6585 if (status < 0) {
6586 /* James M doesn't say fuck enough. */
6587 if (indev) dev_put(indev);
6588 if (outdev) dev_put(outdev);
6589 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6590 + if (physindev) dev_put(physindev);
6591 + if (physoutdev) dev_put(physoutdev);
6592 +#endif
6593 kfree(info);
6594 kfree_skb(skb);
6595 return;
6596 }
6597 }
6598
6599 -int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
6600 +/* Returns 1 if okfn() needs to be executed by the caller,
6601 + * -EPERM for NF_DROP, 0 otherwise. */
6602 +int nf_hook_slow(int pf, unsigned int hook, struct sk_buff **pskb,
6603 struct net_device *indev,
6604 struct net_device *outdev,
6605 - int (*okfn)(struct sk_buff *))
6606 + int (*okfn)(struct sk_buff *),
6607 + int hook_thresh)
6608 {
6609 struct list_head *elem;
6610 unsigned int verdict;
6611 int ret = 0;
6612
6613 /* This stopgap cannot be removed until all the hooks are audited. */
6614 - if (skb_is_nonlinear(skb) && skb_linearize(skb, GFP_ATOMIC) != 0) {
6615 - kfree_skb(skb);
6616 + if (skb_is_nonlinear(*pskb) && skb_linearize(*pskb, GFP_ATOMIC) != 0) {
6617 + kfree_skb(*pskb);
6618 return -ENOMEM;
6619 }
6620 - if (skb->ip_summed == CHECKSUM_HW) {
6621 + if ((*pskb)->ip_summed == CHECKSUM_HW) {
6622 if (outdev == NULL) {
6623 - skb->ip_summed = CHECKSUM_NONE;
6624 + (*pskb)->ip_summed = CHECKSUM_NONE;
6625 } else {
6626 - skb_checksum_help(skb);
6627 + skb_checksum_help(*pskb);
6628 }
6629 }
6630
6631 @@ -472,30 +489,24 @@
6632 br_read_lock_bh(BR_NETPROTO_LOCK);
6633
6634 #ifdef CONFIG_NETFILTER_DEBUG
6635 - if (skb->nf_debug & (1 << hook)) {
6636 + if (unlikely((*pskb)->nf_debug & (1 << hook))) {
6637 printk("nf_hook: hook %i already set.\n", hook);
6638 - nf_dump_skb(pf, skb);
6639 + nf_dump_skb(pf, *pskb);
6640 }
6641 - skb->nf_debug |= (1 << hook);
6642 + (*pskb)->nf_debug |= (1 << hook);
6643 #endif
6644
6645 elem = &nf_hooks[pf][hook];
6646 - verdict = nf_iterate(&nf_hooks[pf][hook], &skb, hook, indev,
6647 - outdev, &elem, okfn);
6648 - if (verdict == NF_QUEUE) {
6649 - NFDEBUG("nf_hook: Verdict = QUEUE.\n");
6650 - nf_queue(skb, elem, pf, hook, indev, outdev, okfn);
6651 - }
6652 -
6653 - switch (verdict) {
6654 - case NF_ACCEPT:
6655 - ret = okfn(skb);
6656 - break;
6657 -
6658 - case NF_DROP:
6659 - kfree_skb(skb);
6660 + verdict = nf_iterate(&nf_hooks[pf][hook], pskb, hook, indev,
6661 + outdev, &elem, okfn, hook_thresh);
6662 + if (verdict == NF_ACCEPT || verdict == NF_STOP)
6663 + ret = 1;
6664 + else if (verdict == NF_DROP) {
6665 + kfree_skb(*pskb);
6666 ret = -EPERM;
6667 - break;
6668 + } else if (verdict == NF_QUEUE) {
6669 + NFDEBUG("nf_hook: Verdict = QUEUE.\n");
6670 + nf_queue(*pskb, elem, pf, hook, indev, outdev, okfn);
6671 }
6672
6673 br_read_unlock_bh(BR_NETPROTO_LOCK);
6674 @@ -510,6 +521,14 @@
6675
6676 /* We don't have BR_NETPROTO_LOCK here */
6677 br_read_lock_bh(BR_NETPROTO_LOCK);
6678 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6679 + if (skb->nf_bridge) {
6680 + if (skb->nf_bridge->physindev)
6681 + dev_put(skb->nf_bridge->physindev);
6682 + if (skb->nf_bridge->physoutdev)
6683 + dev_put(skb->nf_bridge->physoutdev);
6684 + }
6685 +#endif
6686 for (i = nf_hooks[info->pf][info->hook].next; i != elem; i = i->next) {
6687 if (i == &nf_hooks[info->pf][info->hook]) {
6688 /* The module which sent it to userspace is gone. */
6689 @@ -530,7 +549,7 @@
6690 verdict = nf_iterate(&nf_hooks[info->pf][info->hook],
6691 &skb, info->hook,
6692 info->indev, info->outdev, &elem,
6693 - info->okfn);
6694 + info->okfn, INT_MIN);
6695 }
6696
6697 switch (verdict) {
6698 diff -Nur linux.old/net/core/skbuff.c linux.dev/net/core/skbuff.c
6699 --- linux.old/net/core/skbuff.c 2005-10-10 10:33:00.891795250 +0200
6700 +++ linux.dev/net/core/skbuff.c 2005-10-10 10:36:46.205876500 +0200
6701 @@ -250,6 +250,9 @@
6702 #ifdef CONFIG_NETFILTER_DEBUG
6703 skb->nf_debug = 0;
6704 #endif
6705 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6706 + skb->nf_bridge = NULL;
6707 +#endif
6708 #endif
6709 #ifdef CONFIG_NET_SCHED
6710 skb->tc_index = 0;
6711 @@ -334,6 +337,9 @@
6712 }
6713 #ifdef CONFIG_NETFILTER
6714 nf_conntrack_put(skb->nfct);
6715 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6716 + nf_bridge_put(skb->nf_bridge);
6717 +#endif
6718 #endif
6719 skb_headerinit(skb, NULL, 0); /* clean state */
6720 kfree_skbmem(skb);
6721 @@ -401,6 +407,9 @@
6722 #ifdef CONFIG_NETFILTER_DEBUG
6723 C(nf_debug);
6724 #endif
6725 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6726 + C(nf_bridge);
6727 +#endif
6728 #endif /*CONFIG_NETFILTER*/
6729 #if defined(CONFIG_HIPPI)
6730 C(private);
6731 @@ -417,6 +426,9 @@
6732 skb->cloned = 1;
6733 #ifdef CONFIG_NETFILTER
6734 nf_conntrack_get(skb->nfct);
6735 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6736 + nf_bridge_get(skb->nf_bridge);
6737 +#endif
6738 #endif
6739 return n;
6740 }
6741 @@ -452,6 +464,10 @@
6742 #ifdef CONFIG_NETFILTER_DEBUG
6743 new->nf_debug=old->nf_debug;
6744 #endif
6745 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6746 + new->nf_bridge=old->nf_bridge;
6747 + nf_bridge_get(new->nf_bridge);
6748 +#endif
6749 #endif
6750 #ifdef CONFIG_NET_SCHED
6751 new->tc_index = old->tc_index;
6752 @@ -742,9 +758,9 @@
6753 /* Set the tail pointer and length */
6754 skb_put(n,skb->len);
6755
6756 - /* Copy the data only. */
6757 - if (skb_copy_bits(skb, 0, n->data, skb->len))
6758 - BUG();
6759 + /* Copy the linear data and header. */
6760 + if (skb_copy_bits(skb, -newheadroom, n->head, newheadroom + skb->len))
6761 + BUG();
6762
6763 copy_skb_header(n, skb);
6764 return n;
6765 diff -Nur linux.old/net/ipv4/ip_output.c linux.dev/net/ipv4/ip_output.c
6766 --- linux.old/net/ipv4/ip_output.c 2005-01-19 15:10:13.000000000 +0100
6767 +++ linux.dev/net/ipv4/ip_output.c 2005-10-10 10:36:46.265880250 +0200
6768 @@ -77,6 +77,7 @@
6769 #include <linux/netfilter_ipv4.h>
6770 #include <linux/mroute.h>
6771 #include <linux/netlink.h>
6772 +#include <linux/netfilter_bridge.h>
6773
6774 /*
6775 * Shall we try to damage output packets if routing dev changes?
6776 @@ -769,7 +770,8 @@
6777 int not_last_frag;
6778 struct rtable *rt = (struct rtable*)skb->dst;
6779 int err = 0;
6780 -
6781 + unsigned int ll_rs = 0;
6782 +
6783 dev = rt->u.dst.dev;
6784
6785 /*
6786 @@ -785,6 +787,10 @@
6787 hlen = iph->ihl * 4;
6788 left = skb->len - hlen; /* Space per frame */
6789 mtu = rt->u.dst.pmtu - hlen; /* Size of data space */
6790 +#ifdef CONFIG_NETFILTER
6791 + ll_rs = nf_bridge_pad(skb);
6792 + mtu -= ll_rs;
6793 +#endif
6794 ptr = raw + hlen; /* Where to start from */
6795
6796 /*
6797 @@ -812,7 +818,7 @@
6798 * Allocate buffer.
6799 */
6800
6801 - if ((skb2 = alloc_skb(len+hlen+dev->hard_header_len+15,GFP_ATOMIC)) == NULL) {
6802 + if ((skb2 = alloc_skb(len+hlen+dev->hard_header_len+15+ll_rs,GFP_ATOMIC)) == NULL) {
6803 NETDEBUG(printk(KERN_INFO "IP: frag: no memory for new fragment!\n"));
6804 err = -ENOMEM;
6805 goto fail;
6806 @@ -824,7 +830,7 @@
6807
6808 skb2->pkt_type = skb->pkt_type;
6809 skb2->priority = skb->priority;
6810 - skb_reserve(skb2, (dev->hard_header_len+15)&~15);
6811 + skb_reserve(skb2, (dev->hard_header_len+15+ll_rs)&~15);
6812 skb_put(skb2, len + hlen);
6813 skb2->nh.raw = skb2->data;
6814 skb2->h.raw = skb2->data + hlen;
6815 @@ -890,6 +896,10 @@
6816 /* Connection association is same as pre-frag packet */
6817 skb2->nfct = skb->nfct;
6818 nf_conntrack_get(skb2->nfct);
6819 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6820 + skb2->nf_bridge = skb->nf_bridge;
6821 + nf_bridge_get(skb2->nf_bridge);
6822 +#endif
6823 #ifdef CONFIG_NETFILTER_DEBUG
6824 skb2->nf_debug = skb->nf_debug;
6825 #endif
6826 diff -Nur linux.old/net/ipv4/netfilter/Config.in linux.dev/net/ipv4/netfilter/Config.in
6827 --- linux.old/net/ipv4/netfilter/Config.in 2005-10-10 10:33:00.891795250 +0200
6828 +++ linux.dev/net/ipv4/netfilter/Config.in 2005-10-10 10:36:46.293882000 +0200
6829 @@ -55,6 +55,9 @@
6830 int ' Buffer size for application layer data (256-65536)' CONFIG_IP_NF_MATCH_LAYER7_MAXDATALEN 2048
6831
6832 fi
6833 + if [ "$CONFIG_BRIDGE" != "n" ]; then
6834 + dep_tristate ' Physdev match support' CONFIG_IP_NF_MATCH_PHYSDEV $CONFIG_IP_NF_IPTABLES
6835 + fi
6836 # The targets
6837 dep_tristate ' Packet filtering' CONFIG_IP_NF_FILTER $CONFIG_IP_NF_IPTABLES
6838 if [ "$CONFIG_IP_NF_FILTER" != "n" ]; then
6839 diff -Nur linux.old/net/ipv4/netfilter/Makefile linux.dev/net/ipv4/netfilter/Makefile
6840 --- linux.old/net/ipv4/netfilter/Makefile 2005-10-10 10:33:00.895795500 +0200
6841 +++ linux.dev/net/ipv4/netfilter/Makefile 2005-10-10 10:36:46.289881750 +0200
6842 @@ -100,6 +100,8 @@
6843
6844 obj-$(CONFIG_IP_NF_MATCH_LAYER7) += ipt_layer7.o
6845
6846 +obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
6847 +
6848 # targets
6849 obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
6850 obj-$(CONFIG_IP_NF_TARGET_MIRROR) += ipt_MIRROR.o
6851 diff -Nur linux.old/net/ipv4/netfilter/ip_tables.c linux.dev/net/ipv4/netfilter/ip_tables.c
6852 --- linux.old/net/ipv4/netfilter/ip_tables.c 2005-04-04 03:42:20.000000000 +0200
6853 +++ linux.dev/net/ipv4/netfilter/ip_tables.c 2005-10-10 10:36:46.233878250 +0200
6854 @@ -120,12 +120,19 @@
6855 static inline int
6856 ip_packet_match(const struct iphdr *ip,
6857 const char *indev,
6858 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6859 + const char *physindev,
6860 +#endif
6861 const char *outdev,
6862 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6863 + const char *physoutdev,
6864 +#endif
6865 const struct ipt_ip *ipinfo,
6866 int isfrag)
6867 {
6868 size_t i;
6869 unsigned long ret;
6870 + unsigned long ret2 = 1;
6871
6872 #define FWINV(bool,invflg) ((bool) ^ !!(ipinfo->invflags & invflg))
6873
6874 @@ -155,7 +162,15 @@
6875 & ((const unsigned long *)ipinfo->iniface_mask)[i];
6876 }
6877
6878 - if (FWINV(ret != 0, IPT_INV_VIA_IN)) {
6879 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6880 + for (i = 0, ret2 = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
6881 + ret2 |= (((const unsigned long *)physindev)[i]
6882 + ^ ((const unsigned long *)ipinfo->iniface)[i])
6883 + & ((const unsigned long *)ipinfo->iniface_mask)[i];
6884 + }
6885 +#endif
6886 +
6887 + if (FWINV(ret != 0 && ret2 != 0, IPT_INV_VIA_IN)) {
6888 dprintf("VIA in mismatch (%s vs %s).%s\n",
6889 indev, ipinfo->iniface,
6890 ipinfo->invflags&IPT_INV_VIA_IN ?" (INV)":"");
6891 @@ -168,7 +183,15 @@
6892 & ((const unsigned long *)ipinfo->outiface_mask)[i];
6893 }
6894
6895 - if (FWINV(ret != 0, IPT_INV_VIA_OUT)) {
6896 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6897 + for (i = 0, ret2 = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
6898 + ret2 |= (((const unsigned long *)physoutdev)[i]
6899 + ^ ((const unsigned long *)ipinfo->outiface)[i])
6900 + & ((const unsigned long *)ipinfo->outiface_mask)[i];
6901 + }
6902 +#endif
6903 +
6904 + if (FWINV(ret != 0 && ret2 != 0, IPT_INV_VIA_OUT)) {
6905 dprintf("VIA out mismatch (%s vs %s).%s\n",
6906 outdev, ipinfo->outiface,
6907 ipinfo->invflags&IPT_INV_VIA_OUT ?" (INV)":"");
6908 @@ -267,6 +290,9 @@
6909 /* Initializing verdict to NF_DROP keeps gcc happy. */
6910 unsigned int verdict = NF_DROP;
6911 const char *indev, *outdev;
6912 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6913 + const char *physindev, *physoutdev;
6914 +#endif
6915 void *table_base;
6916 struct ipt_entry *e, *back;
6917
6918 @@ -276,6 +302,13 @@
6919 datalen = (*pskb)->len - ip->ihl * 4;
6920 indev = in ? in->name : nulldevname;
6921 outdev = out ? out->name : nulldevname;
6922 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6923 + physindev = ((*pskb)->nf_bridge && (*pskb)->nf_bridge->physindev) ?
6924 + (*pskb)->nf_bridge->physindev->name : nulldevname;
6925 + physoutdev = ((*pskb)->nf_bridge && (*pskb)->nf_bridge->physoutdev) ?
6926 + (*pskb)->nf_bridge->physoutdev->name : nulldevname;
6927 +#endif
6928 +
6929 /* We handle fragments by dealing with the first fragment as
6930 * if it was a normal packet. All other fragments are treated
6931 * normally, except that they will NEVER match rules that ask
6932 @@ -311,7 +344,15 @@
6933 IP_NF_ASSERT(e);
6934 IP_NF_ASSERT(back);
6935 (*pskb)->nfcache |= e->nfcache;
6936 - if (ip_packet_match(ip, indev, outdev, &e->ip, offset)) {
6937 + if (ip_packet_match(ip, indev,
6938 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6939 + physindev,
6940 +#endif
6941 + outdev,
6942 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6943 + physoutdev,
6944 +#endif
6945 + &e->ip, offset)) {
6946 struct ipt_entry_target *t;
6947
6948 if (IPT_MATCH_ITERATE(e, do_match,
6949 diff -Nur linux.old/net/ipv4/netfilter/ipt_LOG.c linux.dev/net/ipv4/netfilter/ipt_LOG.c
6950 --- linux.old/net/ipv4/netfilter/ipt_LOG.c 2005-04-04 03:42:20.000000000 +0200
6951 +++ linux.dev/net/ipv4/netfilter/ipt_LOG.c 2005-10-10 10:36:46.265880250 +0200
6952 @@ -317,6 +317,18 @@
6953 loginfo->prefix,
6954 in ? in->name : "",
6955 out ? out->name : "");
6956 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6957 + if ((*pskb)->nf_bridge) {
6958 + struct net_device *physindev = (*pskb)->nf_bridge->physindev;
6959 + struct net_device *physoutdev = (*pskb)->nf_bridge->physoutdev;
6960 +
6961 + if (physindev && in != physindev)
6962 + printk("PHYSIN=%s ", physindev->name);
6963 + if (physoutdev && out != physoutdev)
6964 + printk("PHYSOUT=%s ", physoutdev->name);
6965 + }
6966 +#endif
6967 +
6968 if (in && !out) {
6969 /* MAC logging for input chain only. */
6970 printk("MAC=");
6971 diff -Nur linux.old/net/ipv4/netfilter/ipt_REJECT.c linux.dev/net/ipv4/netfilter/ipt_REJECT.c
6972 --- linux.old/net/ipv4/netfilter/ipt_REJECT.c 2005-01-19 15:10:13.000000000 +0100
6973 +++ linux.dev/net/ipv4/netfilter/ipt_REJECT.c 2005-10-10 10:36:46.353885750 +0200
6974 @@ -15,6 +15,9 @@
6975 #include <net/route.h>
6976 #include <linux/netfilter_ipv4/ip_tables.h>
6977 #include <linux/netfilter_ipv4/ipt_REJECT.h>
6978 +#ifdef CONFIG_BRIDGE_NETFILTER
6979 +#include <linux/netfilter_bridge.h>
6980 +#endif
6981
6982 #if 0
6983 #define DEBUGP printk
6984 @@ -29,7 +32,13 @@
6985 struct rt_key key = {};
6986 struct rtable *rt;
6987
6988 - if (hook != NF_IP_FORWARD) {
6989 + /* We don't require ip forwarding to be enabled to be able to
6990 + * send a RST reply for bridged traffic. */
6991 + if (hook != NF_IP_FORWARD
6992 +#ifdef CONFIG_BRIDGE_NETFILTER
6993 + || (skb->nf_bridge && skb->nf_bridge->mask & BRNF_BRIDGED)
6994 +#endif
6995 + ) {
6996 key.dst = iph->saddr;
6997 if (hook == NF_IP_LOCAL_IN)
6998 key.src = iph->daddr;
6999 diff -Nur linux.old/net/ipv4/netfilter/ipt_physdev.c linux.dev/net/ipv4/netfilter/ipt_physdev.c
7000 --- linux.old/net/ipv4/netfilter/ipt_physdev.c 1970-01-01 01:00:00.000000000 +0100
7001 +++ linux.dev/net/ipv4/netfilter/ipt_physdev.c 2005-10-10 10:36:46.293882000 +0200
7002 @@ -0,0 +1,127 @@
7003 +/* Kernel module to match the bridge port in and
7004 + * out device for IP packets coming into contact with a bridge. */
7005 +#include <linux/module.h>
7006 +#include <linux/skbuff.h>
7007 +#include <linux/netfilter_ipv4/ipt_physdev.h>
7008 +#include <linux/netfilter_ipv4/ip_tables.h>
7009 +#include <linux/netfilter_bridge.h>
7010 +#include <linux/netdevice.h>
7011 +#define MATCH 1
7012 +#define NOMATCH 0
7013 +
7014 +static int
7015 +match(const struct sk_buff *skb,
7016 + const struct net_device *in,
7017 + const struct net_device *out,
7018 + const void *matchinfo,
7019 + int offset,
7020 + const void *hdr,
7021 + u_int16_t datalen,
7022 + int *hotdrop)
7023 +{
7024 + int i;
7025 + static const char nulldevname[IFNAMSIZ] = { 0 };
7026 + const struct ipt_physdev_info *info = matchinfo;
7027 + unsigned long ret;
7028 + const char *indev, *outdev;
7029 + struct nf_bridge_info *nf_bridge;
7030 +
7031 + /* Not a bridged IP packet or no info available yet:
7032 + * LOCAL_OUT/mangle and LOCAL_OUT/nat don't know if
7033 + * the destination device will be a bridge. */
7034 + if (!(nf_bridge = skb->nf_bridge)) {
7035 + /* Return MATCH if the invert flags of the used options are on */
7036 + if ((info->bitmask & IPT_PHYSDEV_OP_BRIDGED) &&
7037 + !(info->invert & IPT_PHYSDEV_OP_BRIDGED))
7038 + return NOMATCH;
7039 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN) &&
7040 + !(info->invert & IPT_PHYSDEV_OP_ISIN))
7041 + return NOMATCH;
7042 + if ((info->bitmask & IPT_PHYSDEV_OP_ISOUT) &&
7043 + !(info->invert & IPT_PHYSDEV_OP_ISOUT))
7044 + return NOMATCH;
7045 + if ((info->bitmask & IPT_PHYSDEV_OP_IN) &&
7046 + !(info->invert & IPT_PHYSDEV_OP_IN))
7047 + return NOMATCH;
7048 + if ((info->bitmask & IPT_PHYSDEV_OP_OUT) &&
7049 + !(info->invert & IPT_PHYSDEV_OP_OUT))
7050 + return NOMATCH;
7051 + return MATCH;
7052 + }
7053 +
7054 + /* This only makes sense in the FORWARD and POSTROUTING chains */
7055 + if ((info->bitmask & IPT_PHYSDEV_OP_BRIDGED) &&
7056 + (!!(nf_bridge->mask & BRNF_BRIDGED) ^
7057 + !(info->invert & IPT_PHYSDEV_OP_BRIDGED)))
7058 + return NOMATCH;
7059 +
7060 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN &&
7061 + (!nf_bridge->physindev ^ !!(info->invert & IPT_PHYSDEV_OP_ISIN))) ||
7062 + (info->bitmask & IPT_PHYSDEV_OP_ISOUT &&
7063 + (!nf_bridge->physoutdev ^ !!(info->invert & IPT_PHYSDEV_OP_ISOUT))))
7064 + return NOMATCH;
7065 +
7066 + if (!(info->bitmask & IPT_PHYSDEV_OP_IN))
7067 + goto match_outdev;
7068 + indev = nf_bridge->physindev ? nf_bridge->physindev->name : nulldevname;
7069 + for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
7070 + ret |= (((const unsigned long *)indev)[i]
7071 + ^ ((const unsigned long *)info->physindev)[i])
7072 + & ((const unsigned long *)info->in_mask)[i];
7073 + }
7074 +
7075 + if ((ret == 0) ^ !(info->invert & IPT_PHYSDEV_OP_IN))
7076 + return NOMATCH;
7077 +
7078 +match_outdev:
7079 + if (!(info->bitmask & IPT_PHYSDEV_OP_OUT))
7080 + return MATCH;
7081 + outdev = nf_bridge->physoutdev ?
7082 + nf_bridge->physoutdev->name : nulldevname;
7083 + for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
7084 + ret |= (((const unsigned long *)outdev)[i]
7085 + ^ ((const unsigned long *)info->physoutdev)[i])
7086 + & ((const unsigned long *)info->out_mask)[i];
7087 + }
7088 +
7089 + return (ret != 0) ^ !(info->invert & IPT_PHYSDEV_OP_OUT);
7090 +}
7091 +
7092 +static int
7093 +checkentry(const char *tablename,
7094 + const struct ipt_ip *ip,
7095 + void *matchinfo,
7096 + unsigned int matchsize,
7097 + unsigned int hook_mask)
7098 +{
7099 + const struct ipt_physdev_info *info = matchinfo;
7100 +
7101 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_physdev_info)))
7102 + return 0;
7103 + if (!(info->bitmask & IPT_PHYSDEV_OP_MASK) ||
7104 + info->bitmask & ~IPT_PHYSDEV_OP_MASK)
7105 + return 0;
7106 + return 1;
7107 +}
7108 +
7109 +static struct ipt_match physdev_match = {
7110 + .name = "physdev",
7111 + .match = &match,
7112 + .checkentry = &checkentry,
7113 + .me = THIS_MODULE,
7114 +};
7115 +
7116 +static int __init init(void)
7117 +{
7118 + return ipt_register_match(&physdev_match);
7119 +}
7120 +
7121 +static void __exit fini(void)
7122 +{
7123 + ipt_unregister_match(&physdev_match);
7124 +}
7125 +
7126 +module_init(init);
7127 +module_exit(fini);
7128 +MODULE_LICENSE("GPL");
7129 +EXPORT_NO_SYMBOLS;