ebtables support
[openwrt/svn-archive/archive.git] / obsolete-buildroot / sources / ebtables-brnf-5.patch
1 diff -Nurb src/linux/linux.stock/include/linux/if_bridge.h src/linux/linux/include/linux/if_bridge.h
2 --- src/linux/linux.stock/include/linux/if_bridge.h 2003-10-14 04:09:25.000000000 -0400
3 +++ src/linux/linux/include/linux/if_bridge.h 2004-07-10 23:46:39.000000000 -0400
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 -Nurb src/linux/linux.stock/include/linux/netfilter.h src/linux/linux/include/linux/netfilter.h
15 --- src/linux/linux.stock/include/linux/netfilter.h 2004-07-10 23:30:09.000000000 -0400
16 +++ src/linux/linux/include/linux/netfilter.h 2004-07-10 23:46:39.000000000 -0400
17 @@ -119,17 +119,23 @@
18 /* This is gross, but inline doesn't cut it for avoiding the function
19 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
20 #ifdef CONFIG_NETFILTER_DEBUG
21 -#define NF_HOOK nf_hook_slow
22 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
23 +nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN)
24 +#define NF_HOOK_THRESH nf_hook_slow
25 #else
26 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
27 (list_empty(&nf_hooks[(pf)][(hook)]) \
28 ? (okfn)(skb) \
29 - : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn)))
30 + : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
31 +#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
32 +(list_empty(&nf_hooks[(pf)][(hook)]) \
33 + ? (okfn)(skb) \
34 + : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), (thresh)))
35 #endif
36
37 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
38 struct net_device *indev, struct net_device *outdev,
39 - int (*okfn)(struct sk_buff *));
40 + int (*okfn)(struct sk_buff *), int thresh);
41
42 /* Call setsockopt() */
43 int nf_setsockopt(struct sock *sk, int pf, int optval, char *opt,
44 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_802_3.h src/linux/linux/include/linux/netfilter_bridge/ebt_802_3.h
45 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_802_3.h 1969-12-31 19:00:00.000000000 -0500
46 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_802_3.h 2004-07-10 23:46:39.000000000 -0400
47 @@ -0,0 +1,60 @@
48 +#ifndef __LINUX_BRIDGE_EBT_802_3_H
49 +#define __LINUX_BRIDGE_EBT_802_3_H
50 +
51 +#define EBT_802_3_SAP 0x01
52 +#define EBT_802_3_TYPE 0x02
53 +
54 +#define EBT_802_3_MATCH "802_3"
55 +
56 +/*
57 + * If frame has DSAP/SSAP value 0xaa you must check the SNAP type
58 + * to discover what kind of packet we're carrying.
59 + */
60 +#define CHECK_TYPE 0xaa
61 +
62 +/*
63 + * Control field may be one or two bytes. If the first byte has
64 + * the value 0x03 then the entire length is one byte, otherwise it is two.
65 + * One byte controls are used in Unnumbered Information frames.
66 + * Two byte controls are used in Numbered Information frames.
67 + */
68 +#define IS_UI 0x03
69 +
70 +#define EBT_802_3_MASK (EBT_802_3_SAP | EBT_802_3_TYPE | EBT_802_3)
71 +
72 +/* ui has one byte ctrl, ni has two */
73 +struct hdr_ui {
74 + uint8_t dsap;
75 + uint8_t ssap;
76 + uint8_t ctrl;
77 + uint8_t orig[3];
78 + uint16_t type;
79 +};
80 +
81 +struct hdr_ni {
82 + uint8_t dsap;
83 + uint8_t ssap;
84 + uint16_t ctrl;
85 + uint8_t orig[3];
86 + uint16_t type;
87 +};
88 +
89 +struct ebt_802_3_hdr {
90 + uint8_t daddr[6];
91 + uint8_t saddr[6];
92 + uint16_t len;
93 + union {
94 + struct hdr_ui ui;
95 + struct hdr_ni ni;
96 + } llc;
97 +};
98 +
99 +struct ebt_802_3_info
100 +{
101 + uint8_t sap;
102 + uint16_t type;
103 + uint8_t bitmask;
104 + uint8_t invflags;
105 +};
106 +
107 +#endif
108 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_among.h src/linux/linux/include/linux/netfilter_bridge/ebt_among.h
109 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_among.h 1969-12-31 19:00:00.000000000 -0500
110 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_among.h 2004-07-10 23:46:39.000000000 -0400
111 @@ -0,0 +1,65 @@
112 +#ifndef __LINUX_BRIDGE_EBT_AMONG_H
113 +#define __LINUX_BRIDGE_EBT_AMONG_H
114 +
115 +#define EBT_AMONG_DST 0x01
116 +#define EBT_AMONG_SRC 0x02
117 +
118 +/* Grzegorz Borowiak <grzes@gnu.univ.gda.pl> 2003
119 + *
120 + * Write-once-read-many hash table, used for checking if a given
121 + * MAC address belongs to a set or not and possibly for checking
122 + * if it is related with a given IPv4 address.
123 + *
124 + * The hash value of an address is its last byte.
125 + *
126 + * In real-world ethernet addresses, values of the last byte are
127 + * evenly distributed and there is no need to consider other bytes.
128 + * It would only slow the routines down.
129 + *
130 + * For MAC address comparison speedup reasons, we introduce a trick.
131 + * MAC address is mapped onto an array of two 32-bit integers.
132 + * This pair of integers is compared with MAC addresses in the
133 + * hash table, which are stored also in form of pairs of integers
134 + * (in `cmp' array). This is quick as it requires only two elementary
135 + * number comparisons in worst case. Further, we take advantage of
136 + * fact that entropy of 3 last bytes of address is larger than entropy
137 + * of 3 first bytes. So first we compare 4 last bytes of addresses and
138 + * if they are the same we compare 2 first.
139 + *
140 + * Yes, it is a memory overhead, but in 2003 AD, who cares?
141 + */
142 +
143 +struct ebt_mac_wormhash_tuple
144 +{
145 + uint32_t cmp[2];
146 + uint32_t ip;
147 +};
148 +
149 +struct ebt_mac_wormhash
150 +{
151 + int table[257];
152 + int poolsize;
153 + struct ebt_mac_wormhash_tuple pool[0];
154 +};
155 +
156 +#define ebt_mac_wormhash_size(x) ((x) ? sizeof(struct ebt_mac_wormhash) \
157 + + (x)->poolsize * sizeof(struct ebt_mac_wormhash_tuple) : 0)
158 +
159 +struct ebt_among_info
160 +{
161 + int wh_dst_ofs;
162 + int wh_src_ofs;
163 + int bitmask;
164 +};
165 +
166 +#define EBT_AMONG_DST_NEG 0x1
167 +#define EBT_AMONG_SRC_NEG 0x2
168 +
169 +#define ebt_among_wh_dst(x) ((x)->wh_dst_ofs ? \
170 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_dst_ofs) : NULL)
171 +#define ebt_among_wh_src(x) ((x)->wh_src_ofs ? \
172 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_src_ofs) : NULL)
173 +
174 +#define EBT_AMONG_MATCH "among"
175 +
176 +#endif
177 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_arp.h src/linux/linux/include/linux/netfilter_bridge/ebt_arp.h
178 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_arp.h 1969-12-31 19:00:00.000000000 -0500
179 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_arp.h 2004-07-10 23:46:39.000000000 -0400
180 @@ -0,0 +1,32 @@
181 +#ifndef __LINUX_BRIDGE_EBT_ARP_H
182 +#define __LINUX_BRIDGE_EBT_ARP_H
183 +
184 +#define EBT_ARP_OPCODE 0x01
185 +#define EBT_ARP_HTYPE 0x02
186 +#define EBT_ARP_PTYPE 0x04
187 +#define EBT_ARP_SRC_IP 0x08
188 +#define EBT_ARP_DST_IP 0x10
189 +#define EBT_ARP_SRC_MAC 0x20
190 +#define EBT_ARP_DST_MAC 0x40
191 +#define EBT_ARP_MASK (EBT_ARP_OPCODE | EBT_ARP_HTYPE | EBT_ARP_PTYPE | \
192 + EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)
193 +#define EBT_ARP_MATCH "arp"
194 +
195 +struct ebt_arp_info
196 +{
197 + uint16_t htype;
198 + uint16_t ptype;
199 + uint16_t opcode;
200 + uint32_t saddr;
201 + uint32_t smsk;
202 + uint32_t daddr;
203 + uint32_t dmsk;
204 + unsigned char smaddr[ETH_ALEN];
205 + unsigned char smmsk[ETH_ALEN];
206 + unsigned char dmaddr[ETH_ALEN];
207 + unsigned char dmmsk[ETH_ALEN];
208 + uint8_t bitmask;
209 + uint8_t invflags;
210 +};
211 +
212 +#endif
213 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_arpreply.h src/linux/linux/include/linux/netfilter_bridge/ebt_arpreply.h
214 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_arpreply.h 1969-12-31 19:00:00.000000000 -0500
215 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_arpreply.h 2004-07-10 23:46:39.000000000 -0400
216 @@ -0,0 +1,11 @@
217 +#ifndef __LINUX_BRIDGE_EBT_ARPREPLY_H
218 +#define __LINUX_BRIDGE_EBT_ARPREPLY_H
219 +
220 +struct ebt_arpreply_info
221 +{
222 + unsigned char mac[ETH_ALEN];
223 + int target;
224 +};
225 +#define EBT_ARPREPLY_TARGET "arpreply"
226 +
227 +#endif
228 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_ip.h src/linux/linux/include/linux/netfilter_bridge/ebt_ip.h
229 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_ip.h 1969-12-31 19:00:00.000000000 -0500
230 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_ip.h 2004-07-10 23:46:39.000000000 -0400
231 @@ -0,0 +1,43 @@
232 +/*
233 + * ebt_ip
234 + *
235 + * Authors:
236 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
237 + *
238 + * April, 2002
239 + *
240 + * Changes:
241 + * added ip-sport and ip-dport
242 + * Innominate Security Technologies AG <mhopf@innominate.com>
243 + * September, 2002
244 + */
245 +
246 +#ifndef __LINUX_BRIDGE_EBT_IP_H
247 +#define __LINUX_BRIDGE_EBT_IP_H
248 +
249 +#define EBT_IP_SOURCE 0x01
250 +#define EBT_IP_DEST 0x02
251 +#define EBT_IP_TOS 0x04
252 +#define EBT_IP_PROTO 0x08
253 +#define EBT_IP_SPORT 0x10
254 +#define EBT_IP_DPORT 0x20
255 +#define EBT_IP_MASK (EBT_IP_SOURCE | EBT_IP_DEST | EBT_IP_TOS | EBT_IP_PROTO |\
256 + EBT_IP_SPORT | EBT_IP_DPORT )
257 +#define EBT_IP_MATCH "ip"
258 +
259 +// the same values are used for the invflags
260 +struct ebt_ip_info
261 +{
262 + uint32_t saddr;
263 + uint32_t daddr;
264 + uint32_t smsk;
265 + uint32_t dmsk;
266 + uint8_t tos;
267 + uint8_t protocol;
268 + uint8_t bitmask;
269 + uint8_t invflags;
270 + uint16_t sport[2];
271 + uint16_t dport[2];
272 +};
273 +
274 +#endif
275 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_limit.h src/linux/linux/include/linux/netfilter_bridge/ebt_limit.h
276 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_limit.h 1969-12-31 19:00:00.000000000 -0500
277 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_limit.h 2004-07-10 23:46:39.000000000 -0400
278 @@ -0,0 +1,23 @@
279 +#ifndef __LINUX_BRIDGE_EBT_LIMIT_H
280 +#define __LINUX_BRIDGE_EBT_LIMIT_H
281 +
282 +#define EBT_LIMIT_MATCH "limit"
283 +
284 +/* timings are in milliseconds. */
285 +#define EBT_LIMIT_SCALE 10000
286 +
287 +/* 1/10,000 sec period => max of 10,000/sec. Min rate is then 429490
288 + seconds, or one every 59 hours. */
289 +
290 +struct ebt_limit_info
291 +{
292 + u_int32_t avg; /* Average secs between packets * scale */
293 + u_int32_t burst; /* Period multiplier for upper limit. */
294 +
295 + /* Used internally by the kernel */
296 + unsigned long prev;
297 + u_int32_t credit;
298 + u_int32_t credit_cap, cost;
299 +};
300 +
301 +#endif
302 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_log.h src/linux/linux/include/linux/netfilter_bridge/ebt_log.h
303 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_log.h 1969-12-31 19:00:00.000000000 -0500
304 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_log.h 2004-07-10 23:46:39.000000000 -0400
305 @@ -0,0 +1,17 @@
306 +#ifndef __LINUX_BRIDGE_EBT_LOG_H
307 +#define __LINUX_BRIDGE_EBT_LOG_H
308 +
309 +#define EBT_LOG_IP 0x01 // if the frame is made by ip, log the ip information
310 +#define EBT_LOG_ARP 0x02
311 +#define EBT_LOG_MASK (EBT_LOG_IP | EBT_LOG_ARP)
312 +#define EBT_LOG_PREFIX_SIZE 30
313 +#define EBT_LOG_WATCHER "log"
314 +
315 +struct ebt_log_info
316 +{
317 + uint8_t loglevel;
318 + uint8_t prefix[EBT_LOG_PREFIX_SIZE];
319 + uint32_t bitmask;
320 +};
321 +
322 +#endif
323 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_mark_m.h src/linux/linux/include/linux/netfilter_bridge/ebt_mark_m.h
324 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_mark_m.h 1969-12-31 19:00:00.000000000 -0500
325 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_mark_m.h 2004-07-10 23:46:39.000000000 -0400
326 @@ -0,0 +1,15 @@
327 +#ifndef __LINUX_BRIDGE_EBT_MARK_M_H
328 +#define __LINUX_BRIDGE_EBT_MARK_M_H
329 +
330 +#define EBT_MARK_AND 0x01
331 +#define EBT_MARK_OR 0x02
332 +#define EBT_MARK_MASK (EBT_MARK_AND | EBT_MARK_OR)
333 +struct ebt_mark_m_info
334 +{
335 + unsigned long mark, mask;
336 + uint8_t invert;
337 + uint8_t bitmask;
338 +};
339 +#define EBT_MARK_MATCH "mark_m"
340 +
341 +#endif
342 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_mark_t.h src/linux/linux/include/linux/netfilter_bridge/ebt_mark_t.h
343 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_mark_t.h 1969-12-31 19:00:00.000000000 -0500
344 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_mark_t.h 2004-07-10 23:46:39.000000000 -0400
345 @@ -0,0 +1,12 @@
346 +#ifndef __LINUX_BRIDGE_EBT_MARK_T_H
347 +#define __LINUX_BRIDGE_EBT_MARK_T_H
348 +
349 +struct ebt_mark_t_info
350 +{
351 + unsigned long mark;
352 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
353 + int target;
354 +};
355 +#define EBT_MARK_TARGET "mark"
356 +
357 +#endif
358 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_nat.h src/linux/linux/include/linux/netfilter_bridge/ebt_nat.h
359 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_nat.h 1969-12-31 19:00:00.000000000 -0500
360 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_nat.h 2004-07-10 23:46:39.000000000 -0400
361 @@ -0,0 +1,13 @@
362 +#ifndef __LINUX_BRIDGE_EBT_NAT_H
363 +#define __LINUX_BRIDGE_EBT_NAT_H
364 +
365 +struct ebt_nat_info
366 +{
367 + unsigned char mac[ETH_ALEN];
368 + // EBT_ACCEPT, EBT_DROP, EBT_CONTINUE or EBT_RETURN
369 + int target;
370 +};
371 +#define EBT_SNAT_TARGET "snat"
372 +#define EBT_DNAT_TARGET "dnat"
373 +
374 +#endif
375 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_pkttype.h src/linux/linux/include/linux/netfilter_bridge/ebt_pkttype.h
376 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_pkttype.h 1969-12-31 19:00:00.000000000 -0500
377 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_pkttype.h 2004-07-10 23:46:39.000000000 -0400
378 @@ -0,0 +1,11 @@
379 +#ifndef __LINUX_BRIDGE_EBT_PKTTYPE_H
380 +#define __LINUX_BRIDGE_EBT_PKTTYPE_H
381 +
382 +struct ebt_pkttype_info
383 +{
384 + uint8_t pkt_type;
385 + uint8_t invert;
386 +};
387 +#define EBT_PKTTYPE_MATCH "pkttype"
388 +
389 +#endif
390 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_redirect.h src/linux/linux/include/linux/netfilter_bridge/ebt_redirect.h
391 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_redirect.h 1969-12-31 19:00:00.000000000 -0500
392 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_redirect.h 2004-07-10 23:46:39.000000000 -0400
393 @@ -0,0 +1,11 @@
394 +#ifndef __LINUX_BRIDGE_EBT_REDIRECT_H
395 +#define __LINUX_BRIDGE_EBT_REDIRECT_H
396 +
397 +struct ebt_redirect_info
398 +{
399 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
400 + int target;
401 +};
402 +#define EBT_REDIRECT_TARGET "redirect"
403 +
404 +#endif
405 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_stp.h src/linux/linux/include/linux/netfilter_bridge/ebt_stp.h
406 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_stp.h 1969-12-31 19:00:00.000000000 -0500
407 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_stp.h 2004-07-10 23:46:39.000000000 -0400
408 @@ -0,0 +1,46 @@
409 +#ifndef __LINUX_BRIDGE_EBT_STP_H
410 +#define __LINUX_BRIDGE_EBT_STP_H
411 +
412 +#define EBT_STP_TYPE 0x0001
413 +
414 +#define EBT_STP_FLAGS 0x0002
415 +#define EBT_STP_ROOTPRIO 0x0004
416 +#define EBT_STP_ROOTADDR 0x0008
417 +#define EBT_STP_ROOTCOST 0x0010
418 +#define EBT_STP_SENDERPRIO 0x0020
419 +#define EBT_STP_SENDERADDR 0x0040
420 +#define EBT_STP_PORT 0x0080
421 +#define EBT_STP_MSGAGE 0x0100
422 +#define EBT_STP_MAXAGE 0x0200
423 +#define EBT_STP_HELLOTIME 0x0400
424 +#define EBT_STP_FWDD 0x0800
425 +
426 +#define EBT_STP_MASK 0x0fff
427 +#define EBT_STP_CONFIG_MASK 0x0ffe
428 +
429 +#define EBT_STP_MATCH "stp"
430 +
431 +struct ebt_stp_config_info
432 +{
433 + uint8_t flags;
434 + uint16_t root_priol, root_priou;
435 + char root_addr[6], root_addrmsk[6];
436 + uint32_t root_costl, root_costu;
437 + uint16_t sender_priol, sender_priou;
438 + char sender_addr[6], sender_addrmsk[6];
439 + uint16_t portl, portu;
440 + uint16_t msg_agel, msg_ageu;
441 + uint16_t max_agel, max_ageu;
442 + uint16_t hello_timel, hello_timeu;
443 + uint16_t forward_delayl, forward_delayu;
444 +};
445 +
446 +struct ebt_stp_info
447 +{
448 + uint8_t type;
449 + struct ebt_stp_config_info config;
450 + uint16_t bitmask;
451 + uint16_t invflags;
452 +};
453 +
454 +#endif
455 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_vlan.h src/linux/linux/include/linux/netfilter_bridge/ebt_vlan.h
456 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_vlan.h 1969-12-31 19:00:00.000000000 -0500
457 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_vlan.h 2004-07-10 23:46:39.000000000 -0400
458 @@ -0,0 +1,20 @@
459 +#ifndef __LINUX_BRIDGE_EBT_VLAN_H
460 +#define __LINUX_BRIDGE_EBT_VLAN_H
461 +
462 +#define EBT_VLAN_ID 0x01
463 +#define EBT_VLAN_PRIO 0x02
464 +#define EBT_VLAN_ENCAP 0x04
465 +#define EBT_VLAN_MASK (EBT_VLAN_ID | EBT_VLAN_PRIO | EBT_VLAN_ENCAP)
466 +#define EBT_VLAN_MATCH "vlan"
467 +
468 +struct ebt_vlan_info {
469 + uint16_t id; /* VLAN ID {1-4095} */
470 + uint8_t prio; /* VLAN User Priority {0-7} */
471 + uint16_t encap; /* VLAN Encapsulated frame code {0-65535} */
472 + uint8_t bitmask; /* Args bitmask bit 1=1 - ID arg,
473 + bit 2=1 User-Priority arg, bit 3=1 encap*/
474 + uint8_t invflags; /* Inverse bitmask bit 1=1 - inversed ID arg,
475 + bit 2=1 - inversed Pirority arg */
476 +};
477 +
478 +#endif
479 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebtables.h src/linux/linux/include/linux/netfilter_bridge/ebtables.h
480 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebtables.h 1969-12-31 19:00:00.000000000 -0500
481 +++ src/linux/linux/include/linux/netfilter_bridge/ebtables.h 2004-07-10 23:46:39.000000000 -0400
482 @@ -0,0 +1,361 @@
483 +/*
484 + * ebtables
485 + *
486 + * Authors:
487 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
488 + *
489 + * ebtables.c,v 2.0, September, 2002
490 + *
491 + * This code is stongly inspired on the iptables code which is
492 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
493 + */
494 +
495 +#ifndef __LINUX_BRIDGE_EFF_H
496 +#define __LINUX_BRIDGE_EFF_H
497 +#include <linux/if.h>
498 +#include <linux/netfilter_bridge.h>
499 +#include <linux/if_ether.h>
500 +
501 +#define EBT_TABLE_MAXNAMELEN 32
502 +#define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN
503 +#define EBT_FUNCTION_MAXNAMELEN EBT_TABLE_MAXNAMELEN
504 +
505 +// verdicts >0 are "branches"
506 +#define EBT_ACCEPT -1
507 +#define EBT_DROP -2
508 +#define EBT_CONTINUE -3
509 +#define EBT_RETURN -4
510 +#define NUM_STANDARD_TARGETS 4
511 +
512 +struct ebt_counter
513 +{
514 + uint64_t pcnt;
515 + uint64_t bcnt;
516 +};
517 +
518 +struct ebt_entries {
519 + // this field is always set to zero
520 + // See EBT_ENTRY_OR_ENTRIES.
521 + // Must be same size as ebt_entry.bitmask
522 + unsigned int distinguisher;
523 + // the chain name
524 + char name[EBT_CHAIN_MAXNAMELEN];
525 + // counter offset for this chain
526 + unsigned int counter_offset;
527 + // one standard (accept, drop, return) per hook
528 + int policy;
529 + // nr. of entries
530 + unsigned int nentries;
531 + // entry list
532 + char data[0];
533 +};
534 +
535 +// used for the bitmask of struct ebt_entry
536 +
537 +// This is a hack to make a difference between an ebt_entry struct and an
538 +// ebt_entries struct when traversing the entries from start to end.
539 +// Using this simplifies the code alot, while still being able to use
540 +// ebt_entries.
541 +// Contrary, iptables doesn't use something like ebt_entries and therefore uses
542 +// different techniques for naming the policy and such. So, iptables doesn't
543 +// need a hack like this.
544 +#define EBT_ENTRY_OR_ENTRIES 0x01
545 +// these are the normal masks
546 +#define EBT_NOPROTO 0x02
547 +#define EBT_802_3 0x04
548 +#define EBT_SOURCEMAC 0x08
549 +#define EBT_DESTMAC 0x10
550 +#define EBT_F_MASK (EBT_NOPROTO | EBT_802_3 | EBT_SOURCEMAC | EBT_DESTMAC \
551 + | EBT_ENTRY_OR_ENTRIES)
552 +
553 +#define EBT_IPROTO 0x01
554 +#define EBT_IIN 0x02
555 +#define EBT_IOUT 0x04
556 +#define EBT_ISOURCE 0x8
557 +#define EBT_IDEST 0x10
558 +#define EBT_ILOGICALIN 0x20
559 +#define EBT_ILOGICALOUT 0x40
560 +#define EBT_INV_MASK (EBT_IPROTO | EBT_IIN | EBT_IOUT | EBT_ILOGICALIN \
561 + | EBT_ILOGICALOUT | EBT_ISOURCE | EBT_IDEST)
562 +
563 +struct ebt_entry_match
564 +{
565 + union {
566 + char name[EBT_FUNCTION_MAXNAMELEN];
567 + struct ebt_match *match;
568 + } u;
569 + // size of data
570 + unsigned int match_size;
571 + unsigned char data[0];
572 +};
573 +
574 +struct ebt_entry_watcher
575 +{
576 + union {
577 + char name[EBT_FUNCTION_MAXNAMELEN];
578 + struct ebt_watcher *watcher;
579 + } u;
580 + // size of data
581 + unsigned int watcher_size;
582 + unsigned char data[0];
583 +};
584 +
585 +struct ebt_entry_target
586 +{
587 + union {
588 + char name[EBT_FUNCTION_MAXNAMELEN];
589 + struct ebt_target *target;
590 + } u;
591 + // size of data
592 + unsigned int target_size;
593 + unsigned char data[0];
594 +};
595 +
596 +#define EBT_STANDARD_TARGET "standard"
597 +struct ebt_standard_target
598 +{
599 + struct ebt_entry_target target;
600 + int verdict;
601 +};
602 +
603 +// one entry
604 +struct ebt_entry {
605 + // this needs to be the first field
606 + unsigned int bitmask;
607 + unsigned int invflags;
608 + uint16_t ethproto;
609 + // the physical in-dev
610 + char in[IFNAMSIZ];
611 + // the logical in-dev
612 + char logical_in[IFNAMSIZ];
613 + // the physical out-dev
614 + char out[IFNAMSIZ];
615 + // the logical out-dev
616 + char logical_out[IFNAMSIZ];
617 + unsigned char sourcemac[ETH_ALEN];
618 + unsigned char sourcemsk[ETH_ALEN];
619 + unsigned char destmac[ETH_ALEN];
620 + unsigned char destmsk[ETH_ALEN];
621 + // sizeof ebt_entry + matches
622 + unsigned int watchers_offset;
623 + // sizeof ebt_entry + matches + watchers
624 + unsigned int target_offset;
625 + // sizeof ebt_entry + matches + watchers + target
626 + unsigned int next_offset;
627 + unsigned char elems[0];
628 +};
629 +
630 +struct ebt_replace
631 +{
632 + char name[EBT_TABLE_MAXNAMELEN];
633 + unsigned int valid_hooks;
634 + // nr of rules in the table
635 + unsigned int nentries;
636 + // total size of the entries
637 + unsigned int entries_size;
638 + // start of the chains
639 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
640 + // nr of counters userspace expects back
641 + unsigned int num_counters;
642 + // where the kernel will put the old counters
643 + struct ebt_counter *counters;
644 + char *entries;
645 +};
646 +
647 +// [gs]etsockopt numbers
648 +#define EBT_BASE_CTL 128
649 +
650 +#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
651 +#define EBT_SO_SET_COUNTERS (EBT_SO_SET_ENTRIES+1)
652 +#define EBT_SO_SET_MAX (EBT_SO_SET_COUNTERS+1)
653 +
654 +#define EBT_SO_GET_INFO (EBT_BASE_CTL)
655 +#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO+1)
656 +#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES+1)
657 +#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO+1)
658 +#define EBT_SO_GET_MAX (EBT_SO_GET_INIT_ENTRIES+1)
659 +
660 +#ifdef __KERNEL__
661 +
662 +// return values for match() functions
663 +#define EBT_MATCH 0
664 +#define EBT_NOMATCH 1
665 +
666 +struct ebt_match
667 +{
668 + struct list_head list;
669 + const char name[EBT_FUNCTION_MAXNAMELEN];
670 + // 0 == it matches
671 + int (*match)(const struct sk_buff *skb, const struct net_device *in,
672 + const struct net_device *out, const void *matchdata,
673 + unsigned int datalen);
674 + // 0 == let it in
675 + int (*check)(const char *tablename, unsigned int hookmask,
676 + const struct ebt_entry *e, void *matchdata, unsigned int datalen);
677 + void (*destroy)(void *matchdata, unsigned int datalen);
678 + struct module *me;
679 +};
680 +
681 +struct ebt_watcher
682 +{
683 + struct list_head list;
684 + const char name[EBT_FUNCTION_MAXNAMELEN];
685 + void (*watcher)(const struct sk_buff *skb, const struct net_device *in,
686 + const struct net_device *out, const void *watcherdata,
687 + unsigned int datalen);
688 + // 0 == let it in
689 + int (*check)(const char *tablename, unsigned int hookmask,
690 + const struct ebt_entry *e, void *watcherdata, unsigned int datalen);
691 + void (*destroy)(void *watcherdata, unsigned int datalen);
692 + struct module *me;
693 +};
694 +
695 +struct ebt_target
696 +{
697 + struct list_head list;
698 + const char name[EBT_FUNCTION_MAXNAMELEN];
699 + // returns one of the standard verdicts
700 + int (*target)(struct sk_buff **pskb, unsigned int hooknr,
701 + const struct net_device *in, const struct net_device *out,
702 + const void *targetdata, unsigned int datalen);
703 + // 0 == let it in
704 + int (*check)(const char *tablename, unsigned int hookmask,
705 + const struct ebt_entry *e, void *targetdata, unsigned int datalen);
706 + void (*destroy)(void *targetdata, unsigned int datalen);
707 + struct module *me;
708 +};
709 +
710 +// used for jumping from and into user defined chains (udc)
711 +struct ebt_chainstack
712 +{
713 + struct ebt_entries *chaininfo; // pointer to chain data
714 + struct ebt_entry *e; // pointer to entry data
715 + unsigned int n; // n'th entry
716 +};
717 +
718 +struct ebt_table_info
719 +{
720 + // total size of the entries
721 + unsigned int entries_size;
722 + unsigned int nentries;
723 + // pointers to the start of the chains
724 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
725 + // room to maintain the stack used for jumping from and into udc
726 + struct ebt_chainstack **chainstack;
727 + char *entries;
728 + struct ebt_counter counters[0] ____cacheline_aligned;
729 +};
730 +
731 +struct ebt_table
732 +{
733 + struct list_head list;
734 + char name[EBT_TABLE_MAXNAMELEN];
735 + struct ebt_replace *table;
736 + unsigned int valid_hooks;
737 + rwlock_t lock;
738 + // e.g. could be the table explicitly only allows certain
739 + // matches, targets, ... 0 == let it in
740 + int (*check)(const struct ebt_table_info *info,
741 + unsigned int valid_hooks);
742 + // the data used by the kernel
743 + struct ebt_table_info *private;
744 +};
745 +
746 +#define EBT_ALIGN(s) (((s) + (__alignof__(struct ebt_entry_target)-1)) & \
747 + ~(__alignof__(struct ebt_entry_target)-1))
748 +extern int ebt_register_table(struct ebt_table *table);
749 +extern void ebt_unregister_table(struct ebt_table *table);
750 +extern int ebt_register_match(struct ebt_match *match);
751 +extern void ebt_unregister_match(struct ebt_match *match);
752 +extern int ebt_register_watcher(struct ebt_watcher *watcher);
753 +extern void ebt_unregister_watcher(struct ebt_watcher *watcher);
754 +extern int ebt_register_target(struct ebt_target *target);
755 +extern void ebt_unregister_target(struct ebt_target *target);
756 +extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff **pskb,
757 + const struct net_device *in, const struct net_device *out,
758 + struct ebt_table *table);
759 +
760 + // Used in the kernel match() functions
761 +#define FWINV(bool,invflg) ((bool) ^ !!(info->invflags & invflg))
762 +// True if the hook mask denotes that the rule is in a base chain,
763 +// used in the check() functions
764 +#define BASE_CHAIN (hookmask & (1 << NF_BR_NUMHOOKS))
765 +// Clear the bit in the hook mask that tells if the rule is on a base chain
766 +#define CLEAR_BASE_CHAIN_BIT (hookmask &= ~(1 << NF_BR_NUMHOOKS))
767 +// True if the target is not a standard target
768 +#define INVALID_TARGET (info->target < -NUM_STANDARD_TARGETS || info->target >= 0)
769 +
770 +#endif /* __KERNEL__ */
771 +
772 +// blatently stolen from ip_tables.h
773 +// fn returns 0 to continue iteration
774 +#define EBT_MATCH_ITERATE(e, fn, args...) \
775 +({ \
776 + unsigned int __i; \
777 + int __ret = 0; \
778 + struct ebt_entry_match *__match; \
779 + \
780 + for (__i = sizeof(struct ebt_entry); \
781 + __i < (e)->watchers_offset; \
782 + __i += __match->match_size + \
783 + sizeof(struct ebt_entry_match)) { \
784 + __match = (void *)(e) + __i; \
785 + \
786 + __ret = fn(__match , ## args); \
787 + if (__ret != 0) \
788 + break; \
789 + } \
790 + if (__ret == 0) { \
791 + if (__i != (e)->watchers_offset) \
792 + __ret = -EINVAL; \
793 + } \
794 + __ret; \
795 +})
796 +
797 +#define EBT_WATCHER_ITERATE(e, fn, args...) \
798 +({ \
799 + unsigned int __i; \
800 + int __ret = 0; \
801 + struct ebt_entry_watcher *__watcher; \
802 + \
803 + for (__i = e->watchers_offset; \
804 + __i < (e)->target_offset; \
805 + __i += __watcher->watcher_size + \
806 + sizeof(struct ebt_entry_watcher)) { \
807 + __watcher = (void *)(e) + __i; \
808 + \
809 + __ret = fn(__watcher , ## args); \
810 + if (__ret != 0) \
811 + break; \
812 + } \
813 + if (__ret == 0) { \
814 + if (__i != (e)->target_offset) \
815 + __ret = -EINVAL; \
816 + } \
817 + __ret; \
818 +})
819 +
820 +#define EBT_ENTRY_ITERATE(entries, size, fn, args...) \
821 +({ \
822 + unsigned int __i; \
823 + int __ret = 0; \
824 + struct ebt_entry *__entry; \
825 + \
826 + for (__i = 0; __i < (size);) { \
827 + __entry = (void *)(entries) + __i; \
828 + __ret = fn(__entry , ## args); \
829 + if (__ret != 0) \
830 + break; \
831 + if (__entry->bitmask != 0) \
832 + __i += __entry->next_offset; \
833 + else \
834 + __i += sizeof(struct ebt_entries); \
835 + } \
836 + if (__ret == 0) { \
837 + if (__i != (size)) \
838 + __ret = -EINVAL; \
839 + } \
840 + __ret; \
841 +})
842 +
843 +#endif
844 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge.h src/linux/linux/include/linux/netfilter_bridge.h
845 --- src/linux/linux.stock/include/linux/netfilter_bridge.h 2003-07-04 04:12:26.000000000 -0400
846 +++ src/linux/linux/include/linux/netfilter_bridge.h 2004-07-10 23:46:39.000000000 -0400
847 @@ -6,6 +6,10 @@
848
849 #include <linux/config.h>
850 #include <linux/netfilter.h>
851 +#if defined(__KERNEL__) && defined(CONFIG_NETFILTER)
852 +#include <asm/atomic.h>
853 +#include <linux/if_ether.h>
854 +#endif
855
856 /* Bridge Hooks */
857 /* After promisc drops, checksum checks. */
858 @@ -18,7 +22,76 @@
859 #define NF_BR_LOCAL_OUT 3
860 /* Packets about to hit the wire. */
861 #define NF_BR_POST_ROUTING 4
862 -#define NF_BR_NUMHOOKS 5
863 +/* Not really a hook, but used for the ebtables broute table */
864 +#define NF_BR_BROUTING 5
865 +#define NF_BR_NUMHOOKS 6
866 +
867 +#ifdef __KERNEL__
868 +
869 +#define BRNF_PKT_TYPE 0x01
870 +#define BRNF_BRIDGED_DNAT 0x02
871 +#define BRNF_DONT_TAKE_PARENT 0x04
872 +#define BRNF_BRIDGED 0x08
873 +#define BRNF_NF_BRIDGE_PREROUTING 0x10
874 +
875 +enum nf_br_hook_priorities {
876 + NF_BR_PRI_FIRST = INT_MIN,
877 + NF_BR_PRI_NAT_DST_BRIDGED = -300,
878 + NF_BR_PRI_FILTER_BRIDGED = -200,
879 + NF_BR_PRI_BRNF = 0,
880 + NF_BR_PRI_NAT_DST_OTHER = 100,
881 + NF_BR_PRI_FILTER_OTHER = 200,
882 + NF_BR_PRI_NAT_SRC = 300,
883 + NF_BR_PRI_LAST = INT_MAX,
884 +};
885 +
886 +#ifdef CONFIG_NETFILTER
887 +static inline
888 +struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
889 +{
890 + struct nf_bridge_info **nf_bridge = &(skb->nf_bridge);
891 +
892 + if ((*nf_bridge = kmalloc(sizeof(**nf_bridge), GFP_ATOMIC)) != NULL) {
893 + atomic_set(&(*nf_bridge)->use, 1);
894 + (*nf_bridge)->mask = 0;
895 + (*nf_bridge)->physindev = (*nf_bridge)->physoutdev = NULL;
896 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
897 + (*nf_bridge)->netoutdev = NULL;
898 +#endif
899 + }
900 +
901 + return *nf_bridge;
902 +}
903 +
904 +/* Only used in br_forward.c */
905 +static inline
906 +void nf_bridge_maybe_copy_header(struct sk_buff *skb)
907 +{
908 + if (skb->nf_bridge) {
909 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
910 + memcpy(skb->data - 18, skb->nf_bridge->data, 18);
911 + skb_push(skb, 4);
912 + } else
913 + memcpy(skb->data - 16, skb->nf_bridge->data, 16);
914 + }
915 +}
916 +
917 +static inline
918 +void nf_bridge_save_header(struct sk_buff *skb)
919 +{
920 + int header_size = 16;
921 +
922 + if (skb->protocol == __constant_htons(ETH_P_8021Q))
923 + header_size = 18;
924 + memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
925 +}
926
927 +struct bridge_skb_cb {
928 + union {
929 + __u32 ipv4;
930 + } daddr;
931 +};
932 +#endif /* CONFIG_NETFILTER */
933
934 +#endif /* __KERNEL__ */
935 #endif
936 diff -Nurb src/linux/linux.stock/include/linux/netfilter_ipv4/ipt_physdev.h src/linux/linux/include/linux/netfilter_ipv4/ipt_physdev.h
937 --- src/linux/linux.stock/include/linux/netfilter_ipv4/ipt_physdev.h 1969-12-31 19:00:00.000000000 -0500
938 +++ src/linux/linux/include/linux/netfilter_ipv4/ipt_physdev.h 2004-07-10 23:46:39.000000000 -0400
939 @@ -0,0 +1,24 @@
940 +#ifndef _IPT_PHYSDEV_H
941 +#define _IPT_PHYSDEV_H
942 +
943 +#ifdef __KERNEL__
944 +#include <linux/if.h>
945 +#endif
946 +
947 +#define IPT_PHYSDEV_OP_IN 0x01
948 +#define IPT_PHYSDEV_OP_OUT 0x02
949 +#define IPT_PHYSDEV_OP_BRIDGED 0x04
950 +#define IPT_PHYSDEV_OP_ISIN 0x08
951 +#define IPT_PHYSDEV_OP_ISOUT 0x10
952 +#define IPT_PHYSDEV_OP_MASK (0x20 - 1)
953 +
954 +struct ipt_physdev_info {
955 + char physindev[IFNAMSIZ];
956 + char in_mask[IFNAMSIZ];
957 + char physoutdev[IFNAMSIZ];
958 + char out_mask[IFNAMSIZ];
959 + u_int8_t invert;
960 + u_int8_t bitmask;
961 +};
962 +
963 +#endif /*_IPT_PHYSDEV_H*/
964 diff -Nurb src/linux/linux.stock/include/linux/netfilter_ipv4.h src/linux/linux/include/linux/netfilter_ipv4.h
965 --- src/linux/linux.stock/include/linux/netfilter_ipv4.h 2004-07-10 23:30:09.000000000 -0400
966 +++ src/linux/linux/include/linux/netfilter_ipv4.h 2004-07-10 23:46:39.000000000 -0400
967 @@ -54,8 +54,10 @@
968 NF_IP_PRI_CONNTRACK_DEFRAG = -400,
969 NF_IP_PRI_RAW = -300,
970 NF_IP_PRI_CONNTRACK = -200,
971 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD = -175,
972 NF_IP_PRI_MANGLE = -150,
973 NF_IP_PRI_NAT_DST = -100,
974 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT = -50,
975 NF_IP_PRI_FILTER = 0,
976 NF_IP_PRI_NAT_SRC = 100,
977 NF_IP_PRI_LAST = INT_MAX,
978 diff -Nurb src/linux/linux.stock/include/linux/skbuff.h src/linux/linux/include/linux/skbuff.h
979 --- src/linux/linux.stock/include/linux/skbuff.h 2003-07-04 04:12:26.000000000 -0400
980 +++ src/linux/linux/include/linux/skbuff.h 2004-07-10 23:46:39.000000000 -0400
981 @@ -92,6 +92,20 @@
982 struct nf_ct_info {
983 struct nf_conntrack *master;
984 };
985 +
986 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
987 +struct nf_bridge_info {
988 + atomic_t use;
989 + struct net_device *physindev;
990 + struct net_device *physoutdev;
991 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
992 + struct net_device *netoutdev;
993 +#endif
994 + unsigned int mask;
995 + unsigned long data[32 / sizeof(unsigned long)];
996 +};
997 +#endif
998 +
999 #endif
1000
1001 struct sk_buff_head {
1002 @@ -204,6 +218,9 @@
1003 #ifdef CONFIG_NETFILTER_DEBUG
1004 unsigned int nf_debug;
1005 #endif
1006 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1007 + struct nf_bridge_info *nf_bridge; /* Saved data about a bridged frame - see br_netfilter.c */
1008 +#endif
1009 #endif /*CONFIG_NETFILTER*/
1010
1011 #if defined(CONFIG_HIPPI)
1012 @@ -1143,6 +1160,20 @@
1013 if (nfct)
1014 atomic_inc(&nfct->master->use);
1015 }
1016 +
1017 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1018 +static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
1019 +{
1020 + if (nf_bridge && atomic_dec_and_test(&nf_bridge->use))
1021 + kfree(nf_bridge);
1022 +}
1023 +static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)
1024 +{
1025 + if (nf_bridge)
1026 + atomic_inc(&nf_bridge->use);
1027 +}
1028 +#endif
1029 +
1030 #endif
1031
1032 #endif /* __KERNEL__ */
1033 diff -Nurb src/linux/linux.stock/include/linux/sysctl.h src/linux/linux/include/linux/sysctl.h
1034 --- src/linux/linux.stock/include/linux/sysctl.h 2004-07-10 23:29:55.000000000 -0400
1035 +++ src/linux/linux/include/linux/sysctl.h 2004-07-10 23:46:39.000000000 -0400
1036 @@ -547,6 +547,15 @@
1037 NET_DECNET_CONF_DEV_STATE = 7
1038 };
1039
1040 +/* /proc/sys/net/bridge */
1041 +enum {
1042 + NET_BRIDGE_NF_CALL_ARPTABLES = 1,
1043 + NET_BRIDGE_NF_CALL_IPTABLES = 2,
1044 + NET_BRIDGE_NF_CALL_IP6TABLES = 3,
1045 + NET_BRIDGE_NF_FILTER_VLAN_TAGGED = 4,
1046 +};
1047 +
1048 +
1049 /* CTL_PROC names: */
1050
1051 /* CTL_FS names: */
1052 diff -Nurb src/linux/linux.stock/net/8021q/vlan_dev.c src/linux/linux/net/8021q/vlan_dev.c
1053 --- src/linux/linux.stock/net/8021q/vlan_dev.c 2003-07-04 04:12:29.000000000 -0400
1054 +++ src/linux/linux/net/8021q/vlan_dev.c 2004-07-10 23:46:39.000000000 -0400
1055 @@ -503,6 +503,10 @@
1056 stats->tx_packets++; /* for statics only */
1057 stats->tx_bytes += skb->len;
1058
1059 + skb->protocol = __constant_htons(ETH_P_8021Q);
1060 + skb->mac.raw -= VLAN_HLEN;
1061 + skb->nh.raw -= VLAN_HLEN;
1062 +
1063 dev_queue_xmit(skb);
1064
1065 return 0;
1066 diff -Nurb src/linux/linux.stock/net/Config.in src/linux/linux/net/Config.in
1067 --- src/linux/linux.stock/net/Config.in 2004-07-10 23:29:49.000000000 -0400
1068 +++ src/linux/linux/net/Config.in 2004-07-10 23:46:39.000000000 -0400
1069 @@ -68,6 +68,9 @@
1070 source net/decnet/Config.in
1071 fi
1072 dep_tristate '802.1d Ethernet Bridging' CONFIG_BRIDGE $CONFIG_INET
1073 +if [ "$CONFIG_BRIDGE" != "n" -a "$CONFIG_NETFILTER" != "n" ]; then
1074 + source net/bridge/netfilter/Config.in
1075 +fi
1076 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
1077 tristate 'CCITT X.25 Packet Layer (EXPERIMENTAL)' CONFIG_X25
1078 tristate 'LAPB Data Link Driver (EXPERIMENTAL)' CONFIG_LAPB
1079 diff -Nurb src/linux/linux.stock/net/Makefile src/linux/linux/net/Makefile
1080 --- src/linux/linux.stock/net/Makefile 2004-07-10 23:29:49.000000000 -0400
1081 +++ src/linux/linux/net/Makefile 2004-07-10 23:49:10.000000000 -0400
1082 @@ -26,6 +26,12 @@
1083 endif
1084 endif
1085
1086 +ifneq ($(CONFIG_BRIDGE),n)
1087 +ifneq ($(CONFIG_BRIDGE),)
1088 +subdir-$(CONFIG_BRIDGE) += bridge/netfilter
1089 +endif
1090 +endif
1091 +
1092 subdir-$(CONFIG_KHTTPD) += khttpd
1093 subdir-$(CONFIG_PACKET) += packet
1094 subdir-$(CONFIG_NET_SCHED) += sched
1095 diff -Nurb src/linux/linux.stock/net/bridge/Makefile src/linux/linux/net/bridge/Makefile
1096 --- src/linux/linux.stock/net/bridge/Makefile 2003-07-04 04:12:30.000000000 -0400
1097 +++ src/linux/linux/net/bridge/Makefile 2004-07-10 23:46:39.000000000 -0400
1098 @@ -7,10 +7,17 @@
1099 #
1100 # Note 2! The CFLAGS definition is now in the main makefile...
1101
1102 +export-objs := br.o
1103 +
1104 O_TARGET := bridge.o
1105 obj-y := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \
1106 br_ioctl.o br_notify.o br_stp.o br_stp_bpdu.o \
1107 br_stp_if.o br_stp_timer.o
1108 +
1109 +ifeq ($(CONFIG_NETFILTER),y)
1110 +obj-y += br_netfilter.o
1111 +endif
1112 +
1113 obj-m := $(O_TARGET)
1114
1115 include $(TOPDIR)/Rules.make
1116 diff -Nurb src/linux/linux.stock/net/bridge/br.c src/linux/linux/net/bridge/br.c
1117 --- src/linux/linux.stock/net/bridge/br.c 2003-10-14 04:09:32.000000000 -0400
1118 +++ src/linux/linux/net/bridge/br.c 2004-07-10 23:46:39.000000000 -0400
1119 @@ -29,6 +29,8 @@
1120 #include "../atm/lec.h"
1121 #endif
1122
1123 +int (*br_should_route_hook) (struct sk_buff **pskb) = NULL;
1124 +
1125 void br_dec_use_count()
1126 {
1127 MOD_DEC_USE_COUNT;
1128 @@ -43,6 +45,10 @@
1129 {
1130 printk(KERN_INFO "NET4: Ethernet Bridge 008 for NET4.0\n");
1131
1132 +#ifdef CONFIG_NETFILTER
1133 + if (br_netfilter_init())
1134 + return 1;
1135 +#endif
1136 br_handle_frame_hook = br_handle_frame;
1137 br_ioctl_hook = br_ioctl_deviceless_stub;
1138 #if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
1139 @@ -61,6 +67,9 @@
1140
1141 static void __exit br_deinit(void)
1142 {
1143 +#ifdef CONFIG_NETFILTER
1144 + br_netfilter_fini();
1145 +#endif
1146 unregister_netdevice_notifier(&br_device_notifier);
1147 br_call_ioctl_atomic(__br_clear_ioctl_hook);
1148
1149 @@ -74,7 +83,7 @@
1150 #endif
1151 }
1152
1153 -EXPORT_NO_SYMBOLS;
1154 +EXPORT_SYMBOL(br_should_route_hook);
1155
1156 module_init(br_init)
1157 module_exit(br_deinit)
1158 diff -Nurb src/linux/linux.stock/net/bridge/br_forward.c src/linux/linux/net/bridge/br_forward.c
1159 --- src/linux/linux.stock/net/bridge/br_forward.c 2003-10-14 04:09:32.000000000 -0400
1160 +++ src/linux/linux/net/bridge/br_forward.c 2004-07-10 23:46:39.000000000 -0400
1161 @@ -30,18 +30,21 @@
1162 return 1;
1163 }
1164
1165 -static int __dev_queue_push_xmit(struct sk_buff *skb)
1166 +int br_dev_queue_push_xmit(struct sk_buff *skb)
1167 {
1168 +#ifdef CONFIG_NETFILTER
1169 + nf_bridge_maybe_copy_header(skb);
1170 +#endif
1171 skb_push(skb, ETH_HLEN);
1172 dev_queue_xmit(skb);
1173
1174 return 0;
1175 }
1176
1177 -static int __br_forward_finish(struct sk_buff *skb)
1178 +int br_forward_finish(struct sk_buff *skb)
1179 {
1180 NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
1181 - __dev_queue_push_xmit);
1182 + br_dev_queue_push_xmit);
1183
1184 return 0;
1185 }
1186 @@ -49,8 +52,11 @@
1187 static void __br_deliver(struct net_bridge_port *to, struct sk_buff *skb)
1188 {
1189 skb->dev = to->dev;
1190 +#ifdef CONFIG_NETFILTER_DEBUG
1191 + skb->nf_debug = 0;
1192 +#endif
1193 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
1194 - __br_forward_finish);
1195 + br_forward_finish);
1196 }
1197
1198 static void __br_forward(struct net_bridge_port *to, struct sk_buff *skb)
1199 @@ -61,7 +67,7 @@
1200 skb->dev = to->dev;
1201
1202 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
1203 - __br_forward_finish);
1204 + br_forward_finish);
1205 }
1206
1207 /* called under bridge lock */
1208 diff -Nurb src/linux/linux.stock/net/bridge/br_input.c src/linux/linux/net/bridge/br_input.c
1209 --- src/linux/linux.stock/net/bridge/br_input.c 2003-10-14 04:09:32.000000000 -0400
1210 +++ src/linux/linux/net/bridge/br_input.c 2004-07-10 23:48:36.000000000 -0400
1211 @@ -24,6 +24,9 @@
1212
1213 static int br_pass_frame_up_finish(struct sk_buff *skb)
1214 {
1215 +#ifdef CONFIG_NETFILTER_DEBUG
1216 + skb->nf_debug = 0;
1217 +#endif
1218 netif_rx(skb);
1219
1220 return 0;
1221 @@ -46,7 +49,7 @@
1222 br_pass_frame_up_finish);
1223 }
1224
1225 -static int br_handle_frame_finish(struct sk_buff *skb)
1226 +int br_handle_frame_finish(struct sk_buff *skb)
1227 {
1228 struct net_bridge *br;
1229 unsigned char *dest;
1230 @@ -112,7 +115,7 @@
1231 return 0;
1232 }
1233
1234 -void br_handle_frame(struct sk_buff *skb)
1235 +int br_handle_frame(struct sk_buff *skb)
1236 {
1237 struct net_bridge *br;
1238 unsigned char *dest;
1239 @@ -146,25 +149,34 @@
1240 goto handle_special_frame;
1241
1242 if (p->state == BR_STATE_FORWARDING) {
1243 + if (br_should_route_hook && br_should_route_hook(&skb)) {
1244 + read_unlock(&br->lock);
1245 + return -1;
1246 + }
1247 +
1248 + if (!memcmp(p->br->dev.dev_addr, dest, ETH_ALEN))
1249 + skb->pkt_type = PACKET_HOST;
1250 +
1251 NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
1252 br_handle_frame_finish);
1253 read_unlock(&br->lock);
1254 - return;
1255 + return 0;
1256 }
1257
1258 err:
1259 read_unlock(&br->lock);
1260 err_nolock:
1261 kfree_skb(skb);
1262 - return;
1263 + return 0;
1264
1265 handle_special_frame:
1266 if (!dest[5]) {
1267 br_stp_handle_bpdu(skb);
1268 read_unlock(&br->lock);
1269 - return;
1270 + return 0;
1271 }
1272
1273 read_unlock(&br->lock);
1274 kfree_skb(skb);
1275 + return 0;
1276 }
1277 diff -Nurb src/linux/linux.stock/net/bridge/br_netfilter.c src/linux/linux/net/bridge/br_netfilter.c
1278 --- src/linux/linux.stock/net/bridge/br_netfilter.c 1969-12-31 19:00:00.000000000 -0500
1279 +++ src/linux/linux/net/bridge/br_netfilter.c 2004-07-10 23:46:39.000000000 -0400
1280 @@ -0,0 +1,896 @@
1281 +/*
1282 + * Handle firewalling
1283 + * Linux ethernet bridge
1284 + *
1285 + * Authors:
1286 + * Lennert Buytenhek <buytenh@gnu.org>
1287 + * Bart De Schuymer (maintainer) <bdschuym@pandora.be>
1288 + *
1289 + * Changes:
1290 + * Apr 29 2003: physdev module support (bdschuym)
1291 + * Jun 19 2003: let arptables see bridged ARP traffic (bdschuym)
1292 + * Oct 06 2003: filter encapsulated IP/ARP VLAN traffic on untagged bridge
1293 + * (bdschuym)
1294 + *
1295 + * This program is free software; you can redistribute it and/or
1296 + * modify it under the terms of the GNU General Public License
1297 + * as published by the Free Software Foundation; either version
1298 + * 2 of the License, or (at your option) any later version.
1299 + *
1300 + * Lennert dedicates this file to Kerstin Wurdinger.
1301 + */
1302 +
1303 +#include <linux/module.h>
1304 +#include <linux/kernel.h>
1305 +#include <linux/ip.h>
1306 +#include <linux/netdevice.h>
1307 +#include <linux/skbuff.h>
1308 +#include <linux/if_ether.h>
1309 +#include <linux/if_vlan.h>
1310 +#include <linux/netfilter_bridge.h>
1311 +#include <linux/netfilter_ipv4.h>
1312 +#include <linux/in_route.h>
1313 +#include <net/ip.h>
1314 +#include <asm/uaccess.h>
1315 +#include <asm/checksum.h>
1316 +#include "br_private.h"
1317 +#ifdef CONFIG_SYSCTL
1318 +#include <linux/sysctl.h>
1319 +#endif
1320 +
1321 +
1322 +#define skb_origaddr(skb) (((struct bridge_skb_cb *) \
1323 + (skb->nf_bridge->data))->daddr.ipv4)
1324 +#define store_orig_dstaddr(skb) (skb_origaddr(skb) = (skb)->nh.iph->daddr)
1325 +#define dnat_took_place(skb) (skb_origaddr(skb) != (skb)->nh.iph->daddr)
1326 +
1327 +#define has_bridge_parent(device) ((device)->br_port != NULL)
1328 +#define bridge_parent(device) (&((device)->br_port->br->dev))
1329 +
1330 +#ifdef CONFIG_SYSCTL
1331 +static struct ctl_table_header *brnf_sysctl_header;
1332 +static int brnf_call_iptables = 1;
1333 +static int brnf_call_arptables = 1;
1334 +static int brnf_filter_vlan_tagged = 1;
1335 +#else
1336 +#define brnf_filter_vlan_tagged 1
1337 +#endif
1338 +
1339 +#define IS_VLAN_IP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
1340 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IP) && \
1341 + brnf_filter_vlan_tagged)
1342 +/*
1343 +#define IS_VLAN_ARP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
1344 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_ARP) && \
1345 + brnf_filter_vlan_tagged)
1346 +*/
1347 +
1348 +/* We need these fake structures to make netfilter happy --
1349 + * lots of places assume that skb->dst != NULL, which isn't
1350 + * all that unreasonable.
1351 + *
1352 + * Currently, we fill in the PMTU entry because netfilter
1353 + * refragmentation needs it, and the rt_flags entry because
1354 + * ipt_REJECT needs it. Future netfilter modules might
1355 + * require us to fill additional fields.
1356 + */
1357 +static struct net_device __fake_net_device = {
1358 + .hard_header_len = ETH_HLEN
1359 +};
1360 +
1361 +static struct rtable __fake_rtable = {
1362 + u: {
1363 + dst: {
1364 + __refcnt: ATOMIC_INIT(1),
1365 + dev: &__fake_net_device,
1366 + pmtu: 1500
1367 + }
1368 + },
1369 +
1370 + rt_flags: 0
1371 +};
1372 +
1373 +
1374 +/* PF_BRIDGE/PRE_ROUTING *********************************************/
1375 +static void __br_dnat_complain(void)
1376 +{
1377 + static unsigned long last_complaint;
1378 +
1379 + if (jiffies - last_complaint >= 5 * HZ) {
1380 + printk(KERN_WARNING "Performing cross-bridge DNAT requires IP "
1381 + "forwarding to be enabled\n");
1382 + last_complaint = jiffies;
1383 + }
1384 +}
1385 +
1386 +
1387 +/* This requires some explaining. If DNAT has taken place,
1388 + * we will need to fix up the destination Ethernet address,
1389 + * and this is a tricky process.
1390 + *
1391 + * There are two cases to consider:
1392 + * 1. The packet was DNAT'ed to a device in the same bridge
1393 + * port group as it was received on. We can still bridge
1394 + * the packet.
1395 + * 2. The packet was DNAT'ed to a different device, either
1396 + * a non-bridged device or another bridge port group.
1397 + * The packet will need to be routed.
1398 + *
1399 + * The correct way of distinguishing between these two cases is to
1400 + * call ip_route_input() and to look at skb->dst->dev, which is
1401 + * changed to the destination device if ip_route_input() succeeds.
1402 + *
1403 + * Let us first consider the case that ip_route_input() succeeds:
1404 + *
1405 + * If skb->dst->dev equals the logical bridge device the packet
1406 + * came in on, we can consider this bridging. We then call
1407 + * skb->dst->output() which will make the packet enter br_nf_local_out()
1408 + * not much later. In that function it is assured that the iptables
1409 + * FORWARD chain is traversed for the packet.
1410 + *
1411 + * Otherwise, the packet is considered to be routed and we just
1412 + * change the destination MAC address so that the packet will
1413 + * later be passed up to the IP stack to be routed.
1414 + *
1415 + * Let us now consider the case that ip_route_input() fails:
1416 + *
1417 + * After a "echo '0' > /proc/sys/net/ipv4/ip_forward" ip_route_input()
1418 + * will fail, while __ip_route_output_key() will return success. The source
1419 + * address for __ip_route_output_key() is set to zero, so __ip_route_output_key
1420 + * thinks we're handling a locally generated packet and won't care
1421 + * if IP forwarding is allowed. We send a warning message to the users's
1422 + * log telling her to put IP forwarding on.
1423 + *
1424 + * ip_route_input() will also fail if there is no route available.
1425 + * In that case we just drop the packet.
1426 + *
1427 + * --Lennert, 20020411
1428 + * --Bart, 20020416 (updated)
1429 + * --Bart, 20021007 (updated)
1430 + */
1431 +
1432 +static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
1433 +{
1434 +#ifdef CONFIG_NETFILTER_DEBUG
1435 + skb->nf_debug |= (1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_FORWARD);
1436 +#endif
1437 +
1438 + if (skb->pkt_type == PACKET_OTHERHOST) {
1439 + skb->pkt_type = PACKET_HOST;
1440 + skb->nf_bridge->mask |= BRNF_PKT_TYPE;
1441 + }
1442 + skb->nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
1443 +
1444 + skb->dev = bridge_parent(skb->dev);
1445 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1446 + skb_pull(skb, VLAN_HLEN);
1447 + skb->nh.raw += VLAN_HLEN;
1448 + }
1449 + skb->dst->output(skb);
1450 + return 0;
1451 +}
1452 +
1453 +static int br_nf_pre_routing_finish(struct sk_buff *skb)
1454 +{
1455 + struct net_device *dev = skb->dev;
1456 + struct iphdr *iph = skb->nh.iph;
1457 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
1458 +
1459 +#ifdef CONFIG_NETFILTER_DEBUG
1460 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
1461 +#endif
1462 +
1463 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
1464 + skb->pkt_type = PACKET_OTHERHOST;
1465 + nf_bridge->mask ^= BRNF_PKT_TYPE;
1466 + }
1467 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
1468 +
1469 + if (dnat_took_place(skb)) {
1470 + if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos,
1471 + dev)) {
1472 + struct rtable *rt;
1473 +
1474 + if (!ip_route_output(&rt, iph->daddr, 0, iph->tos, 0)) {
1475 + /* Bridged-and-DNAT'ed traffic doesn't
1476 + * require ip_forwarding.
1477 + */
1478 + if (((struct dst_entry *)rt)->dev == dev) {
1479 + skb->dst = (struct dst_entry *)rt;
1480 + goto bridged_dnat;
1481 + }
1482 + __br_dnat_complain();
1483 + dst_release((struct dst_entry *)rt);
1484 + }
1485 + kfree_skb(skb);
1486 + return 0;
1487 + } else {
1488 + if (skb->dst->dev == dev) {
1489 +bridged_dnat:
1490 + /* Tell br_nf_local_out this is a
1491 + * bridged frame
1492 + */
1493 + nf_bridge->mask |= BRNF_BRIDGED_DNAT;
1494 + skb->dev = nf_bridge->physindev;
1495 + if (skb->protocol ==
1496 + __constant_htons(ETH_P_8021Q)) {
1497 + skb_push(skb, VLAN_HLEN);
1498 + skb->nh.raw -= VLAN_HLEN;
1499 + }
1500 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING,
1501 + skb, skb->dev, NULL,
1502 + br_nf_pre_routing_finish_bridge,
1503 + 1);
1504 + return 0;
1505 + }
1506 + memcpy(skb->mac.ethernet->h_dest, dev->dev_addr,
1507 + ETH_ALEN);
1508 + skb->pkt_type = PACKET_HOST;
1509 + }
1510 + } else {
1511 + skb->dst = (struct dst_entry *)&__fake_rtable;
1512 + dst_hold(skb->dst);
1513 + }
1514 +
1515 + skb->dev = nf_bridge->physindev;
1516 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1517 + skb_push(skb, VLAN_HLEN);
1518 + skb->nh.raw -= VLAN_HLEN;
1519 + }
1520 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
1521 + br_handle_frame_finish, 1);
1522 +
1523 + return 0;
1524 +}
1525 +
1526 +/* Replicate the checks that IPv4 does on packet reception.
1527 + * Set skb->dev to the bridge device (i.e. parent of the
1528 + * receiving device) to make netfilter happy, the REDIRECT
1529 + * target in particular. Save the original destination IP
1530 + * address to be able to detect DNAT afterwards.
1531 + */
1532 +static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
1533 + const struct net_device *in, const struct net_device *out,
1534 + int (*okfn)(struct sk_buff *))
1535 +{
1536 + struct iphdr *iph;
1537 + __u32 len;
1538 + struct sk_buff *skb = *pskb;
1539 + struct nf_bridge_info *nf_bridge;
1540 +
1541 +#ifdef CONFIG_SYSCTL
1542 + if (!brnf_call_iptables)
1543 + return NF_ACCEPT;
1544 +#endif
1545 +
1546 + if (skb->protocol != __constant_htons(ETH_P_IP)) {
1547 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)
1548 + ((*pskb)->mac.ethernet);
1549 +
1550 + if (!IS_VLAN_IP)
1551 + return NF_ACCEPT;
1552 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
1553 + goto out;
1554 + skb_pull(*pskb, VLAN_HLEN);
1555 + (*pskb)->nh.raw += VLAN_HLEN;
1556 + } else if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
1557 + goto out;
1558 +
1559 + if (!pskb_may_pull(skb, sizeof(struct iphdr)))
1560 + goto inhdr_error;
1561 +
1562 + iph = skb->nh.iph;
1563 + if (iph->ihl < 5 || iph->version != 4)
1564 + goto inhdr_error;
1565 +
1566 + if (!pskb_may_pull(skb, 4*iph->ihl))
1567 + goto inhdr_error;
1568 +
1569 + iph = skb->nh.iph;
1570 + if (ip_fast_csum((__u8 *)iph, iph->ihl) != 0)
1571 + goto inhdr_error;
1572 +
1573 + len = ntohs(iph->tot_len);
1574 + if (skb->len < len || len < 4*iph->ihl)
1575 + goto inhdr_error;
1576 +
1577 + if (skb->len > len) {
1578 + __pskb_trim(skb, len);
1579 + if (skb->ip_summed == CHECKSUM_HW)
1580 + skb->ip_summed = CHECKSUM_NONE;
1581 + }
1582 +
1583 +#ifdef CONFIG_NETFILTER_DEBUG
1584 + skb->nf_debug ^= (1 << NF_IP_PRE_ROUTING);
1585 +#endif
1586 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
1587 + return NF_DROP;
1588 +
1589 + if (skb->pkt_type == PACKET_OTHERHOST) {
1590 + skb->pkt_type = PACKET_HOST;
1591 + nf_bridge->mask |= BRNF_PKT_TYPE;
1592 + }
1593 +
1594 + nf_bridge->mask |= BRNF_NF_BRIDGE_PREROUTING;
1595 + nf_bridge->physindev = skb->dev;
1596 + skb->dev = bridge_parent(skb->dev);
1597 + store_orig_dstaddr(skb);
1598 +
1599 + NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL,
1600 + br_nf_pre_routing_finish);
1601 +
1602 + return NF_STOLEN;
1603 +
1604 +inhdr_error:
1605 +// IP_INC_STATS_BH(IpInHdrErrors);
1606 +out:
1607 + return NF_DROP;
1608 +}
1609 +
1610 +
1611 +/* PF_BRIDGE/LOCAL_IN ************************************************/
1612 +/* The packet is locally destined, which requires a real
1613 + * dst_entry, so detach the fake one. On the way up, the
1614 + * packet would pass through PRE_ROUTING again (which already
1615 + * took place when the packet entered the bridge), but we
1616 + * register an IPv4 PRE_ROUTING 'sabotage' hook that will
1617 + * prevent this from happening.
1618 + */
1619 +static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff **pskb,
1620 + const struct net_device *in, const struct net_device *out,
1621 + int (*okfn)(struct sk_buff *))
1622 +{
1623 + struct sk_buff *skb = *pskb;
1624 +
1625 + if (skb->dst == (struct dst_entry *)&__fake_rtable) {
1626 + dst_release(skb->dst);
1627 + skb->dst = NULL;
1628 + }
1629 +
1630 + return NF_ACCEPT;
1631 +}
1632 +
1633 +/* PF_BRIDGE/FORWARD *************************************************/
1634 +static int br_nf_forward_finish(struct sk_buff *skb)
1635 +{
1636 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
1637 + struct net_device *in;
1638 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1639 +
1640 +#ifdef CONFIG_NETFILTER_DEBUG
1641 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
1642 +#endif
1643 +
1644 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP) {
1645 + in = nf_bridge->physindev;
1646 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
1647 + skb->pkt_type = PACKET_OTHERHOST;
1648 + nf_bridge->mask ^= BRNF_PKT_TYPE;
1649 + }
1650 + } else {
1651 + in = *((struct net_device **)(skb->cb));
1652 + }
1653 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1654 + skb_push(skb, VLAN_HLEN);
1655 + skb->nh.raw -= VLAN_HLEN;
1656 + }
1657 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_FORWARD, skb, in,
1658 + skb->dev, br_forward_finish, 1);
1659 + return 0;
1660 +}
1661 +
1662 +/* This is the 'purely bridged' case. For IP, we pass the packet to
1663 + * netfilter with indev and outdev set to the bridge device,
1664 + * but we are still able to filter on the 'real' indev/outdev
1665 + * because of the ipt_physdev.c module. For ARP, indev and outdev are the
1666 + * bridge ports.
1667 + */
1668 +static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb,
1669 + const struct net_device *in, const struct net_device *out,
1670 + int (*okfn)(struct sk_buff *))
1671 +{
1672 + struct sk_buff *skb = *pskb;
1673 + struct nf_bridge_info *nf_bridge;
1674 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1675 +
1676 +#ifdef CONFIG_SYSCTL
1677 + if (!skb->nf_bridge)
1678 + return NF_ACCEPT;
1679 +#endif
1680 +
1681 + if (skb->protocol != __constant_htons(ETH_P_IP)) {
1682 + if (!IS_VLAN_IP)
1683 + return NF_ACCEPT;
1684 + skb_pull(*pskb, VLAN_HLEN);
1685 + (*pskb)->nh.raw += VLAN_HLEN;
1686 + }
1687 +
1688 +#ifdef CONFIG_NETFILTER_DEBUG
1689 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
1690 +#endif
1691 + nf_bridge = skb->nf_bridge;
1692 + if (skb->pkt_type == PACKET_OTHERHOST) {
1693 + skb->pkt_type = PACKET_HOST;
1694 + nf_bridge->mask |= BRNF_PKT_TYPE;
1695 + }
1696 +
1697 + /* The physdev module checks on this */
1698 + nf_bridge->mask |= BRNF_BRIDGED;
1699 + nf_bridge->physoutdev = skb->dev;
1700 +
1701 + NF_HOOK(PF_INET, NF_IP_FORWARD, skb, bridge_parent(in),
1702 + bridge_parent(out), br_nf_forward_finish);
1703 +
1704 + return NF_STOLEN;
1705 +}
1706 +
1707 +/*
1708 +static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb,
1709 + const struct net_device *in, const struct net_device *out,
1710 + int (*okfn)(struct sk_buff *))
1711 +{
1712 + struct sk_buff *skb = *pskb;
1713 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1714 + struct net_device **d = (struct net_device **)(skb->cb);
1715 +
1716 + if (!brnf_call_arptables)
1717 + return NF_ACCEPT;
1718 +
1719 + if (skb->protocol != __constant_htons(ETH_P_ARP)) {
1720 + if (!IS_VLAN_ARP)
1721 + return NF_ACCEPT;
1722 + skb_pull(*pskb, VLAN_HLEN);
1723 + (*pskb)->nh.raw += VLAN_HLEN;
1724 + }
1725 +
1726 +#ifdef CONFIG_NETFILTER_DEBUG
1727 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
1728 +#endif
1729 +
1730 + if (skb->nh.arph->ar_pln != 4) {
1731 + if (IS_VLAN_ARP) {
1732 + skb_push(*pskb, VLAN_HLEN);
1733 + (*pskb)->nh.raw -= VLAN_HLEN;
1734 + }
1735 + return NF_ACCEPT;
1736 + }
1737 + *d = (struct net_device *)in;
1738 + NF_HOOK(NF_ARP, NF_ARP_FORWARD, skb, (struct net_device *)in,
1739 + (struct net_device *)out, br_nf_forward_finish);
1740 +
1741 + return NF_STOLEN;
1742 +}
1743 +*/
1744 +
1745 +/* PF_BRIDGE/LOCAL_OUT ***********************************************/
1746 +static int br_nf_local_out_finish(struct sk_buff *skb)
1747 +{
1748 +#ifdef CONFIG_NETFILTER_DEBUG
1749 + skb->nf_debug &= ~(1 << NF_BR_LOCAL_OUT);
1750 +#endif
1751 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1752 + skb_push(skb, VLAN_HLEN);
1753 + skb->nh.raw -= VLAN_HLEN;
1754 + }
1755 +
1756 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
1757 + br_forward_finish, NF_BR_PRI_FIRST + 1);
1758 +
1759 + return 0;
1760 +}
1761 +
1762 +
1763 +/* This function sees both locally originated IP packets and forwarded
1764 + * IP packets (in both cases the destination device is a bridge
1765 + * device). It also sees bridged-and-DNAT'ed packets.
1766 + * To be able to filter on the physical bridge devices (with the ipt_physdev.c
1767 + * module), we steal packets destined to a bridge device away from the
1768 + * PF_INET/FORWARD and PF_INET/OUTPUT hook functions, and give them back later,
1769 + * when we have determined the real output device. This is done in here.
1770 + *
1771 + * If (nf_bridge->mask & BRNF_BRIDGED_DNAT) then the packet is bridged
1772 + * and we fake the PF_BRIDGE/FORWARD hook. The function br_nf_forward()
1773 + * will then fake the PF_INET/FORWARD hook. br_nf_local_out() has priority
1774 + * NF_BR_PRI_FIRST, so no relevant PF_BRIDGE/INPUT functions have been nor
1775 + * will be executed.
1776 + * Otherwise, if nf_bridge->physindev is NULL, the bridge-nf code never touched
1777 + * this packet before, and so the packet was locally originated. We fake
1778 + * the PF_INET/LOCAL_OUT hook.
1779 + * Finally, if nf_bridge->physindev isn't NULL, then the packet was IP routed,
1780 + * so we fake the PF_INET/FORWARD hook. ipv4_sabotage_out() makes sure
1781 + * even routed packets that didn't arrive on a bridge interface have their
1782 + * nf_bridge->physindev set.
1783 + */
1784 +
1785 +static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb,
1786 + const struct net_device *in, const struct net_device *out,
1787 + int (*_okfn)(struct sk_buff *))
1788 +{
1789 + int (*okfn)(struct sk_buff *skb);
1790 + struct net_device *realindev;
1791 + struct sk_buff *skb = *pskb;
1792 + struct nf_bridge_info *nf_bridge;
1793 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1794 +
1795 +#ifdef CONFIG_SYSCTL
1796 + if (!skb->nf_bridge)
1797 + return NF_ACCEPT;
1798 +#endif
1799 +
1800 + if (skb->protocol != __constant_htons(ETH_P_IP) && !IS_VLAN_IP)
1801 + return NF_ACCEPT;
1802 +
1803 + /* Sometimes we get packets with NULL ->dst here (for example,
1804 + * running a dhcp client daemon triggers this).
1805 + */
1806 + if (skb->dst == NULL)
1807 + return NF_ACCEPT;
1808 +
1809 + nf_bridge = skb->nf_bridge;
1810 + nf_bridge->physoutdev = skb->dev;
1811 + realindev = nf_bridge->physindev;
1812 +
1813 + /* Bridged, take PF_BRIDGE/FORWARD.
1814 + * (see big note in front of br_nf_pre_routing_finish)
1815 + */
1816 + if (nf_bridge->mask & BRNF_BRIDGED_DNAT) {
1817 + okfn = br_forward_finish;
1818 +
1819 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
1820 + skb->pkt_type = PACKET_OTHERHOST;
1821 + nf_bridge->mask ^= BRNF_PKT_TYPE;
1822 + }
1823 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1824 + skb_push(skb, VLAN_HLEN);
1825 + skb->nh.raw -= VLAN_HLEN;
1826 + }
1827 +
1828 + NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, realindev,
1829 + skb->dev, okfn);
1830 + } else {
1831 + struct net_device *realoutdev = bridge_parent(skb->dev);
1832 +
1833 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1834 + /* iptables should match -o br0.x */
1835 + if (nf_bridge->netoutdev)
1836 + realoutdev = nf_bridge->netoutdev;
1837 +#endif
1838 + okfn = br_nf_local_out_finish;
1839 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1840 + skb_pull(skb, VLAN_HLEN);
1841 + (*pskb)->nh.raw += VLAN_HLEN;
1842 + }
1843 + /* IP forwarded traffic has a physindev, locally
1844 + * generated traffic hasn't.
1845 + */
1846 + if (realindev != NULL) {
1847 + if (((nf_bridge->mask & BRNF_DONT_TAKE_PARENT) == 0) &&
1848 + has_bridge_parent(realindev))
1849 + realindev = bridge_parent(realindev);
1850 + NF_HOOK_THRESH(PF_INET, NF_IP_FORWARD, skb, realindev,
1851 + realoutdev, okfn,
1852 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD + 1);
1853 + } else {
1854 +#ifdef CONFIG_NETFILTER_DEBUG
1855 + skb->nf_debug ^= (1 << NF_IP_LOCAL_OUT);
1856 +#endif
1857 +
1858 + NF_HOOK_THRESH(PF_INET, NF_IP_LOCAL_OUT, skb, realindev,
1859 + realoutdev, okfn,
1860 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT + 1);
1861 + }
1862 + }
1863 +
1864 + return NF_STOLEN;
1865 +}
1866 +
1867 +
1868 +/* PF_BRIDGE/POST_ROUTING ********************************************/
1869 +static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
1870 + const struct net_device *in, const struct net_device *out,
1871 + int (*okfn)(struct sk_buff *))
1872 +{
1873 + struct sk_buff *skb = *pskb;
1874 + struct nf_bridge_info *nf_bridge = (*pskb)->nf_bridge;
1875 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1876 + struct net_device *realoutdev = bridge_parent(skb->dev);
1877 +
1878 +#ifdef CONFIG_NETFILTER_DEBUG
1879 + /* Be very paranoid. This probably won't happen anymore, but let's
1880 + * keep the check just to be sure... */
1881 + if (skb->mac.raw < skb->head || skb->mac.raw + ETH_HLEN > skb->data) {
1882 + printk(KERN_CRIT "br_netfilter: Argh!! br_nf_post_routing: "
1883 + "bad mac.raw pointer.");
1884 + goto print_error;
1885 + }
1886 +#endif
1887 +
1888 +#ifdef CONFIG_SYSCTL
1889 + if (!nf_bridge)
1890 + return NF_ACCEPT;
1891 +#endif
1892 +
1893 + if (skb->protocol != __constant_htons(ETH_P_IP) && !IS_VLAN_IP)
1894 + return NF_ACCEPT;
1895 +
1896 + /* Sometimes we get packets with NULL ->dst here (for example,
1897 + * running a dhcp client daemon triggers this).
1898 + */
1899 + if (skb->dst == NULL)
1900 + return NF_ACCEPT;
1901 +
1902 +#ifdef CONFIG_NETFILTER_DEBUG
1903 + /* Sometimes we get packets with NULL ->dst here (for example,
1904 + * running a dhcp client daemon triggers this). This should now
1905 + * be fixed, but let's keep the check around.
1906 + */
1907 + if (skb->dst == NULL) {
1908 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
1909 + goto print_error;
1910 + }
1911 +
1912 + skb->nf_debug ^= (1 << NF_IP_POST_ROUTING);
1913 +#endif
1914 +
1915 + /* We assume any code from br_dev_queue_push_xmit onwards doesn't care
1916 + * about the value of skb->pkt_type.
1917 + */
1918 + if (skb->pkt_type == PACKET_OTHERHOST) {
1919 + skb->pkt_type = PACKET_HOST;
1920 + nf_bridge->mask |= BRNF_PKT_TYPE;
1921 + }
1922 +
1923 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1924 + skb_pull(skb, VLAN_HLEN);
1925 + skb->nh.raw += VLAN_HLEN;
1926 + }
1927 +
1928 + nf_bridge_save_header(skb);
1929 +
1930 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1931 + if (nf_bridge->netoutdev)
1932 + realoutdev = nf_bridge->netoutdev;
1933 +#endif
1934 + NF_HOOK(PF_INET, NF_IP_POST_ROUTING, skb, NULL,
1935 + realoutdev, br_dev_queue_push_xmit);
1936 +
1937 + return NF_STOLEN;
1938 +
1939 +#ifdef CONFIG_NETFILTER_DEBUG
1940 +print_error:
1941 + if (skb->dev != NULL) {
1942 + printk("[%s]", skb->dev->name);
1943 + if (has_bridge_parent(skb->dev))
1944 + printk("[%s]", bridge_parent(skb->dev)->name);
1945 + }
1946 + printk(" head:%p, raw:%p, data:%p\n", skb->head, skb->mac.raw,
1947 + skb->data);
1948 + return NF_ACCEPT;
1949 +#endif
1950 +}
1951 +
1952 +
1953 +/* IPv4/SABOTAGE *****************************************************/
1954 +
1955 +/* Don't hand locally destined packets to PF_INET/PRE_ROUTING
1956 + * for the second time.
1957 + */
1958 +static unsigned int ipv4_sabotage_in(unsigned int hook, struct sk_buff **pskb,
1959 + const struct net_device *in, const struct net_device *out,
1960 + int (*okfn)(struct sk_buff *))
1961 +{
1962 + if ((*pskb)->nf_bridge &&
1963 + !((*pskb)->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
1964 + okfn(*pskb);
1965 + return NF_STOLEN;
1966 + }
1967 +
1968 + return NF_ACCEPT;
1969 +}
1970 +
1971 +/* Postpone execution of PF_INET/FORWARD, PF_INET/LOCAL_OUT
1972 + * and PF_INET/POST_ROUTING until we have done the forwarding
1973 + * decision in the bridge code and have determined skb->physoutdev.
1974 + */
1975 +static unsigned int ipv4_sabotage_out(unsigned int hook, struct sk_buff **pskb,
1976 + const struct net_device *in, const struct net_device *out,
1977 + int (*okfn)(struct sk_buff *))
1978 +{
1979 + struct sk_buff *skb = *pskb;
1980 +
1981 +#ifdef CONFIG_SYSCTL
1982 + if (!brnf_call_iptables && !skb->nf_bridge)
1983 + return NF_ACCEPT;
1984 +#endif
1985 +
1986 + if ((out->hard_start_xmit == br_dev_xmit &&
1987 + okfn != br_nf_forward_finish &&
1988 + okfn != br_nf_local_out_finish &&
1989 + okfn != br_dev_queue_push_xmit)
1990 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1991 + || ((out->priv_flags & IFF_802_1Q_VLAN) &&
1992 + VLAN_DEV_INFO(out)->real_dev->hard_start_xmit == br_dev_xmit)
1993 +#endif
1994 + ) {
1995 + struct nf_bridge_info *nf_bridge;
1996 +
1997 + if (!skb->nf_bridge && !nf_bridge_alloc(skb))
1998 + return NF_DROP;
1999 +
2000 + nf_bridge = skb->nf_bridge;
2001 +
2002 + /* This frame will arrive on PF_BRIDGE/LOCAL_OUT and we
2003 + * will need the indev then. For a brouter, the real indev
2004 + * can be a bridge port, so we make sure br_nf_local_out()
2005 + * doesn't use the bridge parent of the indev by using
2006 + * the BRNF_DONT_TAKE_PARENT mask.
2007 + */
2008 + if (hook == NF_IP_FORWARD && nf_bridge->physindev == NULL) {
2009 + nf_bridge->mask &= BRNF_DONT_TAKE_PARENT;
2010 + nf_bridge->physindev = (struct net_device *)in;
2011 + }
2012 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
2013 + /* the iptables outdev is br0.x, not br0 */
2014 + if (out->priv_flags & IFF_802_1Q_VLAN)
2015 + nf_bridge->netoutdev = (struct net_device *)out;
2016 +#endif
2017 + okfn(skb);
2018 + return NF_STOLEN;
2019 + }
2020 +
2021 + return NF_ACCEPT;
2022 +}
2023 +
2024 +/* For br_nf_local_out we need (prio = NF_BR_PRI_FIRST), to insure that innocent
2025 + * PF_BRIDGE/NF_BR_LOCAL_OUT functions don't get bridged traffic as input.
2026 + * For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because
2027 + * ip_refrag() can return NF_STOLEN.
2028 + */
2029 +static struct nf_hook_ops br_nf_ops[] = {
2030 + { .hook = br_nf_pre_routing,
2031 + .pf = PF_BRIDGE,
2032 + .hooknum = NF_BR_PRE_ROUTING,
2033 + .priority = NF_BR_PRI_BRNF, },
2034 + { .hook = br_nf_local_in,
2035 + .pf = PF_BRIDGE,
2036 + .hooknum = NF_BR_LOCAL_IN,
2037 + .priority = NF_BR_PRI_BRNF, },
2038 + { .hook = br_nf_forward_ip,
2039 + .pf = PF_BRIDGE,
2040 + .hooknum = NF_BR_FORWARD,
2041 + .priority = NF_BR_PRI_BRNF /*- 1*/, },
2042 +/* { .hook = br_nf_forward_arp,
2043 + .pf = PF_BRIDGE,
2044 + .hooknum = NF_BR_FORWARD,
2045 + .priority = NF_BR_PRI_BRNF, },*/
2046 + { .hook = br_nf_local_out,
2047 + .pf = PF_BRIDGE,
2048 + .hooknum = NF_BR_LOCAL_OUT,
2049 + .priority = NF_BR_PRI_FIRST, },
2050 + { .hook = br_nf_post_routing,
2051 + .pf = PF_BRIDGE,
2052 + .hooknum = NF_BR_POST_ROUTING,
2053 + .priority = NF_BR_PRI_LAST, },
2054 + { .hook = ipv4_sabotage_in,
2055 + .pf = PF_INET,
2056 + .hooknum = NF_IP_PRE_ROUTING,
2057 + .priority = NF_IP_PRI_FIRST, },
2058 + { .hook = ipv4_sabotage_out,
2059 + .pf = PF_INET,
2060 + .hooknum = NF_IP_FORWARD,
2061 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD, },
2062 + { .hook = ipv4_sabotage_out,
2063 + .pf = PF_INET,
2064 + .hooknum = NF_IP_LOCAL_OUT,
2065 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
2066 + { .hook = ipv4_sabotage_out,
2067 + .pf = PF_INET,
2068 + .hooknum = NF_IP_POST_ROUTING,
2069 + .priority = NF_IP_PRI_FIRST, },
2070 +};
2071 +
2072 +#ifdef CONFIG_SYSCTL
2073 +static
2074 +int brnf_sysctl_call_tables(ctl_table *ctl, int write, struct file * filp,
2075 + void *buffer, size_t *lenp)
2076 +{
2077 + int ret;
2078 +
2079 + ret = proc_dointvec(ctl, write, filp, buffer, lenp);
2080 +
2081 + if (write && *(int *)(ctl->data))
2082 + *(int *)(ctl->data) = 1;
2083 + return ret;
2084 +}
2085 +
2086 +static ctl_table brnf_table[] = {
2087 + {
2088 + .ctl_name = NET_BRIDGE_NF_CALL_ARPTABLES,
2089 + .procname = "bridge-nf-call-arptables",
2090 + .data = &brnf_call_arptables,
2091 + .maxlen = sizeof(int),
2092 + .mode = 0644,
2093 + .proc_handler = &brnf_sysctl_call_tables,
2094 + },
2095 + {
2096 + .ctl_name = NET_BRIDGE_NF_CALL_IPTABLES,
2097 + .procname = "bridge-nf-call-iptables",
2098 + .data = &brnf_call_iptables,
2099 + .maxlen = sizeof(int),
2100 + .mode = 0644,
2101 + .proc_handler = &brnf_sysctl_call_tables,
2102 + },
2103 + {
2104 + .ctl_name = NET_BRIDGE_NF_FILTER_VLAN_TAGGED,
2105 + .procname = "bridge-nf-filter-vlan-tagged",
2106 + .data = &brnf_filter_vlan_tagged,
2107 + .maxlen = sizeof(int),
2108 + .mode = 0644,
2109 + .proc_handler = &brnf_sysctl_call_tables,
2110 + },
2111 + { .ctl_name = 0 }
2112 +};
2113 +
2114 +static ctl_table brnf_bridge_table[] = {
2115 + {
2116 + .ctl_name = NET_BRIDGE,
2117 + .procname = "bridge",
2118 + .mode = 0555,
2119 + .child = brnf_table,
2120 + },
2121 + { .ctl_name = 0 }
2122 +};
2123 +
2124 +static ctl_table brnf_net_table[] = {
2125 + {
2126 + .ctl_name = CTL_NET,
2127 + .procname = "net",
2128 + .mode = 0555,
2129 + .child = brnf_bridge_table,
2130 + },
2131 + { .ctl_name = 0 }
2132 +};
2133 +#endif
2134 +
2135 +int br_netfilter_init(void)
2136 +{
2137 + int i;
2138 +
2139 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++) {
2140 + int ret;
2141 +
2142 + if ((ret = nf_register_hook(&br_nf_ops[i])) >= 0)
2143 + continue;
2144 +
2145 + while (i--)
2146 + nf_unregister_hook(&br_nf_ops[i]);
2147 +
2148 + return ret;
2149 + }
2150 +
2151 +#ifdef CONFIG_SYSCTL
2152 + brnf_sysctl_header = register_sysctl_table(brnf_net_table, 0);
2153 + if (brnf_sysctl_header == NULL) {
2154 + printk(KERN_WARNING "br_netfilter: can't register to sysctl.\n");
2155 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++)
2156 + nf_unregister_hook(&br_nf_ops[i]);
2157 + return -EFAULT;
2158 + }
2159 +#endif
2160 +
2161 + printk(KERN_NOTICE "Bridge firewalling registered\n");
2162 +
2163 + return 0;
2164 +}
2165 +
2166 +void br_netfilter_fini(void)
2167 +{
2168 + int i;
2169 +
2170 + for (i = ARRAY_SIZE(br_nf_ops) - 1; i >= 0; i--)
2171 + nf_unregister_hook(&br_nf_ops[i]);
2172 +#ifdef CONFIG_SYSCTL
2173 + unregister_sysctl_table(brnf_sysctl_header);
2174 +#endif
2175 +
2176 +}
2177 diff -Nurb src/linux/linux.stock/net/bridge/br_private.h src/linux/linux/net/bridge/br_private.h
2178 --- src/linux/linux.stock/net/bridge/br_private.h 2003-10-14 04:09:32.000000000 -0400
2179 +++ src/linux/linux/net/bridge/br_private.h 2004-07-10 23:46:39.000000000 -0400
2180 @@ -145,8 +145,10 @@
2181 /* br_forward.c */
2182 extern void br_deliver(struct net_bridge_port *to,
2183 struct sk_buff *skb);
2184 +extern int br_dev_queue_push_xmit(struct sk_buff *skb);
2185 extern void br_forward(struct net_bridge_port *to,
2186 struct sk_buff *skb);
2187 +extern int br_forward_finish(struct sk_buff *skb);
2188 extern void br_flood_deliver(struct net_bridge *br,
2189 struct sk_buff *skb,
2190 int clone);
2191 @@ -167,7 +169,8 @@
2192 int *ifindices);
2193
2194 /* br_input.c */
2195 -extern void br_handle_frame(struct sk_buff *skb);
2196 +extern int br_handle_frame_finish(struct sk_buff *skb);
2197 +extern int br_handle_frame(struct sk_buff *skb);
2198
2199 /* br_ioctl.c */
2200 extern void br_call_ioctl_atomic(void (*fn)(void));
2201 @@ -178,6 +181,10 @@
2202 unsigned long arg2);
2203 extern int br_ioctl_deviceless_stub(unsigned long arg);
2204
2205 +/* br_netfilter.c */
2206 +extern int br_netfilter_init(void);
2207 +extern void br_netfilter_fini(void);
2208 +
2209 /* br_stp.c */
2210 extern int br_is_root_bridge(struct net_bridge *br);
2211 extern struct net_bridge_port *br_get_port(struct net_bridge *br,
2212 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/Config.in src/linux/linux/net/bridge/netfilter/Config.in
2213 --- src/linux/linux.stock/net/bridge/netfilter/Config.in 1969-12-31 19:00:00.000000000 -0500
2214 +++ src/linux/linux/net/bridge/netfilter/Config.in 2004-07-10 23:46:39.000000000 -0400
2215 @@ -0,0 +1,22 @@
2216 +#
2217 +# Bridge netfilter configuration
2218 +#
2219 +dep_tristate ' Bridge: ebtables' CONFIG_BRIDGE_NF_EBTABLES $CONFIG_BRIDGE
2220 +dep_tristate ' ebt: filter table support' CONFIG_BRIDGE_EBT_T_FILTER $CONFIG_BRIDGE_NF_EBTABLES
2221 +dep_tristate ' ebt: nat table support' CONFIG_BRIDGE_EBT_T_NAT $CONFIG_BRIDGE_NF_EBTABLES
2222 +dep_tristate ' ebt: broute table support' CONFIG_BRIDGE_EBT_BROUTE $CONFIG_BRIDGE_NF_EBTABLES
2223 +dep_tristate ' ebt: log support' CONFIG_BRIDGE_EBT_LOG $CONFIG_BRIDGE_NF_EBTABLES
2224 +dep_tristate ' ebt: IP filter support' CONFIG_BRIDGE_EBT_IPF $CONFIG_BRIDGE_NF_EBTABLES
2225 +dep_tristate ' ebt: ARP filter support' CONFIG_BRIDGE_EBT_ARPF $CONFIG_BRIDGE_NF_EBTABLES
2226 +dep_tristate ' ebt: among filter support' CONFIG_BRIDGE_EBT_AMONG $CONFIG_BRIDGE_NF_EBTABLES
2227 +dep_tristate ' ebt: limit filter support' CONFIG_BRIDGE_EBT_LIMIT $CONFIG_BRIDGE_NF_EBTABLES
2228 +dep_tristate ' ebt: 802.1Q VLAN filter support' CONFIG_BRIDGE_EBT_VLANF $CONFIG_BRIDGE_NF_EBTABLES
2229 +dep_tristate ' ebt: 802.3 filter support' CONFIG_BRIDGE_EBT_802_3 $CONFIG_BRIDGE_NF_EBTABLES
2230 +dep_tristate ' ebt: packet type filter support' CONFIG_BRIDGE_EBT_PKTTYPE $CONFIG_BRIDGE_NF_EBTABLES
2231 +dep_tristate ' ebt: STP filter support' CONFIG_BRIDGE_EBT_STP $CONFIG_BRIDGE_NF_EBTABLES
2232 +dep_tristate ' ebt: mark filter support' CONFIG_BRIDGE_EBT_MARKF $CONFIG_BRIDGE_NF_EBTABLES
2233 +dep_tristate ' ebt: arp reply target support' CONFIG_BRIDGE_EBT_ARPREPLY $CONFIG_BRIDGE_NF_EBTABLES
2234 +dep_tristate ' ebt: snat target support' CONFIG_BRIDGE_EBT_SNAT $CONFIG_BRIDGE_NF_EBTABLES
2235 +dep_tristate ' ebt: dnat target support' CONFIG_BRIDGE_EBT_DNAT $CONFIG_BRIDGE_NF_EBTABLES
2236 +dep_tristate ' ebt: redirect target support' CONFIG_BRIDGE_EBT_REDIRECT $CONFIG_BRIDGE_NF_EBTABLES
2237 +dep_tristate ' ebt: mark target support' CONFIG_BRIDGE_EBT_MARK_T $CONFIG_BRIDGE_NF_EBTABLES
2238 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/Makefile src/linux/linux/net/bridge/netfilter/Makefile
2239 --- src/linux/linux.stock/net/bridge/netfilter/Makefile 1969-12-31 19:00:00.000000000 -0500
2240 +++ src/linux/linux/net/bridge/netfilter/Makefile 2004-07-10 23:46:39.000000000 -0400
2241 @@ -0,0 +1,33 @@
2242 +#
2243 +# Makefile for the netfilter modules on top of bridging.
2244 +#
2245 +# Note! Dependencies are done automagically by 'make dep', which also
2246 +# removes any old dependencies. DON'T put your own dependencies here
2247 +# unless it's something special (ie not a .c file).
2248 +#
2249 +# Note 2! The CFLAGS definition is now in the main makefile...
2250 +
2251 +O_TARGET := netfilter.o
2252 +
2253 +export-objs := ebtables.o
2254 +
2255 +obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o
2256 +obj-$(CONFIG_BRIDGE_EBT_T_FILTER) += ebtable_filter.o
2257 +obj-$(CONFIG_BRIDGE_EBT_T_NAT) += ebtable_nat.o
2258 +obj-$(CONFIG_BRIDGE_EBT_BROUTE) += ebtable_broute.o
2259 +obj-$(CONFIG_BRIDGE_EBT_802_3) += ebt_802_3.o
2260 +obj-$(CONFIG_BRIDGE_EBT_ARPF) += ebt_arp.o
2261 +obj-$(CONFIG_BRIDGE_EBT_AMONG) += ebt_among.o
2262 +obj-$(CONFIG_BRIDGE_EBT_IPF) += ebt_ip.o
2263 +obj-$(CONFIG_BRIDGE_EBT_LIMIT) += ebt_limit.o
2264 +obj-$(CONFIG_BRIDGE_EBT_MARKF) += ebt_mark_m.o
2265 +obj-$(CONFIG_BRIDGE_EBT_PKTTYPE) += ebt_pkttype.o
2266 +obj-$(CONFIG_BRIDGE_EBT_STP) += ebt_stp.o
2267 +obj-$(CONFIG_BRIDGE_EBT_VLANF) += ebt_vlan.o
2268 +obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_log.o
2269 +obj-$(CONFIG_BRIDGE_EBT_ARPREPLY) += ebt_arpreply.o
2270 +obj-$(CONFIG_BRIDGE_EBT_DNAT) += ebt_dnat.o
2271 +obj-$(CONFIG_BRIDGE_EBT_MARK_T) += ebt_mark.o
2272 +obj-$(CONFIG_BRIDGE_EBT_REDIRECT) += ebt_redirect.o
2273 +obj-$(CONFIG_BRIDGE_EBT_SNAT) += ebt_snat.o
2274 +include $(TOPDIR)/Rules.make
2275 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_802_3.c src/linux/linux/net/bridge/netfilter/ebt_802_3.c
2276 --- src/linux/linux.stock/net/bridge/netfilter/ebt_802_3.c 1969-12-31 19:00:00.000000000 -0500
2277 +++ src/linux/linux/net/bridge/netfilter/ebt_802_3.c 2004-07-10 23:46:39.000000000 -0400
2278 @@ -0,0 +1,74 @@
2279 +/*
2280 + * 802_3
2281 + *
2282 + * Author:
2283 + * Chris Vitale csv@bluetail.com
2284 + *
2285 + * May 2003
2286 + *
2287 + */
2288 +
2289 +#include <linux/netfilter_bridge/ebtables.h>
2290 +#include <linux/netfilter_bridge/ebt_802_3.h>
2291 +#include <linux/module.h>
2292 +
2293 +static int ebt_filter_802_3(const struct sk_buff *skb, const struct net_device *in,
2294 + const struct net_device *out, const void *data, unsigned int datalen)
2295 +{
2296 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
2297 + struct ebt_802_3_hdr *hdr = (struct ebt_802_3_hdr *)skb->mac.ethernet;
2298 + uint16_t type = hdr->llc.ui.ctrl & IS_UI ? hdr->llc.ui.type : hdr->llc.ni.type;
2299 +
2300 + if (info->bitmask & EBT_802_3_SAP) {
2301 + if (FWINV(info->sap != hdr->llc.ui.ssap, EBT_802_3_SAP))
2302 + return EBT_NOMATCH;
2303 + if (FWINV(info->sap != hdr->llc.ui.dsap, EBT_802_3_SAP))
2304 + return EBT_NOMATCH;
2305 + }
2306 +
2307 + if (info->bitmask & EBT_802_3_TYPE) {
2308 + if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
2309 + return EBT_NOMATCH;
2310 + if (FWINV(info->type != type, EBT_802_3_TYPE))
2311 + return EBT_NOMATCH;
2312 + }
2313 +
2314 + return EBT_MATCH;
2315 +}
2316 +
2317 +static struct ebt_match filter_802_3;
2318 +static int ebt_802_3_check(const char *tablename, unsigned int hookmask,
2319 + const struct ebt_entry *e, void *data, unsigned int datalen)
2320 +{
2321 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
2322 +
2323 + if (datalen != EBT_ALIGN(sizeof(struct ebt_802_3_info)))
2324 + return -EINVAL;
2325 + if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
2326 + return -EINVAL;
2327 +
2328 + return 0;
2329 +}
2330 +
2331 +static struct ebt_match filter_802_3 =
2332 +{
2333 + .name = EBT_802_3_MATCH,
2334 + .match = ebt_filter_802_3,
2335 + .check = ebt_802_3_check,
2336 + .me = THIS_MODULE,
2337 +};
2338 +
2339 +static int __init init(void)
2340 +{
2341 + return ebt_register_match(&filter_802_3);
2342 +}
2343 +
2344 +static void __exit fini(void)
2345 +{
2346 + ebt_unregister_match(&filter_802_3);
2347 +}
2348 +
2349 +module_init(init);
2350 +module_exit(fini);
2351 +EXPORT_NO_SYMBOLS;
2352 +MODULE_LICENSE("GPL");
2353 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_among.c src/linux/linux/net/bridge/netfilter/ebt_among.c
2354 --- src/linux/linux.stock/net/bridge/netfilter/ebt_among.c 1969-12-31 19:00:00.000000000 -0500
2355 +++ src/linux/linux/net/bridge/netfilter/ebt_among.c 2004-07-10 23:46:39.000000000 -0400
2356 @@ -0,0 +1,223 @@
2357 +/*
2358 + * ebt_among
2359 + *
2360 + * Authors:
2361 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
2362 + *
2363 + * August, 2003
2364 + *
2365 + */
2366 +
2367 +#include <linux/netfilter_bridge/ebtables.h>
2368 +#include <linux/netfilter_bridge/ebt_among.h>
2369 +#include <linux/ip.h>
2370 +#include <linux/if_arp.h>
2371 +#include <linux/module.h>
2372 +
2373 +static int ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh,
2374 + const char *mac, uint32_t ip)
2375 +{
2376 + /* You may be puzzled as to how this code works.
2377 + * Some tricks were used, refer to
2378 + * include/linux/netfilter_bridge/ebt_among.h
2379 + * as there you can find a solution of this mystery.
2380 + */
2381 + const struct ebt_mac_wormhash_tuple *p;
2382 + int start, limit, i;
2383 + uint32_t cmp[2] = { 0, 0 };
2384 + int key = (const unsigned char) mac[5];
2385 +
2386 + memcpy(((char *) cmp) + 2, mac, 6);
2387 + start = wh->table[key];
2388 + limit = wh->table[key + 1];
2389 + if (ip) {
2390 + for (i = start; i < limit; i++) {
2391 + p = &wh->pool[i];
2392 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
2393 + if (p->ip == 0 || p->ip == ip) {
2394 + return 1;
2395 + }
2396 + }
2397 + }
2398 + } else {
2399 + for (i = start; i < limit; i++) {
2400 + p = &wh->pool[i];
2401 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
2402 + if (p->ip == 0) {
2403 + return 1;
2404 + }
2405 + }
2406 + }
2407 + }
2408 + return 0;
2409 +}
2410 +
2411 +static int ebt_mac_wormhash_check_integrity(const struct ebt_mac_wormhash
2412 + *wh)
2413 +{
2414 + int i;
2415 +
2416 + for (i = 0; i < 256; i++) {
2417 + if (wh->table[i] > wh->table[i + 1])
2418 + return -0x100 - i;
2419 + if (wh->table[i] < 0)
2420 + return -0x200 - i;
2421 + if (wh->table[i] > wh->poolsize)
2422 + return -0x300 - i;
2423 + }
2424 + if (wh->table[256] > wh->poolsize)
2425 + return -0xc00;
2426 + return 0;
2427 +}
2428 +
2429 +static int get_ip_dst(const struct sk_buff *skb, uint32_t * addr)
2430 +{
2431 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
2432 + *addr = skb->nh.iph->daddr;
2433 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
2434 + uint32_t arp_len = sizeof(struct arphdr) +
2435 + (2 * (((*skb).nh.arph)->ar_hln)) +
2436 + (2 * (((*skb).nh.arph)->ar_pln));
2437 +
2438 + /* Make sure the packet is long enough. */
2439 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2440 + return -1;
2441 + /* IPv4 addresses are always 4 bytes. */
2442 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
2443 + return -1;
2444 +
2445 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
2446 + (2 * (((*skb).nh.arph)->ar_hln)) +
2447 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
2448 +
2449 + }
2450 + return 0;
2451 +}
2452 +
2453 +static int get_ip_src(const struct sk_buff *skb, uint32_t * addr)
2454 +{
2455 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
2456 + *addr = skb->nh.iph->saddr;
2457 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
2458 + uint32_t arp_len = sizeof(struct arphdr) +
2459 + (2 * (((*skb).nh.arph)->ar_hln)) +
2460 + (2 * (((*skb).nh.arph)->ar_pln));
2461 +
2462 + /* Make sure the packet is long enough. */
2463 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2464 + return -1;
2465 + /* IPv4 addresses are always 4 bytes. */
2466 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
2467 + return -1;
2468 +
2469 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
2470 + ((((*skb).nh.arph)->ar_hln)), sizeof(uint32_t));
2471 +
2472 + }
2473 + return 0;
2474 +}
2475 +
2476 +static int ebt_filter_among(const struct sk_buff *skb,
2477 + const struct net_device *in,
2478 + const struct net_device *out, const void *data,
2479 + unsigned int datalen)
2480 +{
2481 + struct ebt_among_info *info = (struct ebt_among_info *) data;
2482 + const char *dmac, *smac;
2483 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
2484 + uint32_t dip = 0, sip = 0;
2485 +
2486 + wh_dst = ebt_among_wh_dst(info);
2487 + wh_src = ebt_among_wh_src(info);
2488 +
2489 + if (wh_src) {
2490 + smac = skb->mac.ethernet->h_source;
2491 + if (get_ip_src(skb, &sip))
2492 + return EBT_NOMATCH;
2493 + if (!(info->bitmask & EBT_AMONG_SRC_NEG)) {
2494 + /* we match only if it contains */
2495 + if (!ebt_mac_wormhash_contains(wh_src, smac, sip))
2496 + return EBT_NOMATCH;
2497 + } else {
2498 + /* we match only if it DOES NOT contain */
2499 + if (ebt_mac_wormhash_contains(wh_src, smac, sip))
2500 + return EBT_NOMATCH;
2501 + }
2502 + }
2503 +
2504 + if (wh_dst) {
2505 + dmac = skb->mac.ethernet->h_dest;
2506 + if (get_ip_dst(skb, &dip))
2507 + return EBT_NOMATCH;
2508 + if (!(info->bitmask & EBT_AMONG_DST_NEG)) {
2509 + /* we match only if it contains */
2510 + if (!ebt_mac_wormhash_contains(wh_dst, dmac, dip))
2511 + return EBT_NOMATCH;
2512 + } else {
2513 + /* we match only if it DOES NOT contain */
2514 + if (ebt_mac_wormhash_contains(wh_dst, dmac, dip))
2515 + return EBT_NOMATCH;
2516 + }
2517 + }
2518 +
2519 + return EBT_MATCH;
2520 +}
2521 +
2522 +static int ebt_among_check(const char *tablename, unsigned int hookmask,
2523 + const struct ebt_entry *e, void *data,
2524 + unsigned int datalen)
2525 +{
2526 + struct ebt_among_info *info = (struct ebt_among_info *) data;
2527 + int expected_length = sizeof(struct ebt_among_info);
2528 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
2529 + int err;
2530 +
2531 + wh_dst = ebt_among_wh_dst(info);
2532 + wh_src = ebt_among_wh_src(info);
2533 + expected_length += ebt_mac_wormhash_size(wh_dst);
2534 + expected_length += ebt_mac_wormhash_size(wh_src);
2535 +
2536 + if (datalen != EBT_ALIGN(expected_length)) {
2537 + printk(KERN_WARNING
2538 + "ebtables: among: wrong size: %d"
2539 + "against expected %d, rounded to %d\n",
2540 + datalen, expected_length,
2541 + EBT_ALIGN(expected_length));
2542 + return -EINVAL;
2543 + }
2544 + if (wh_dst && (err = ebt_mac_wormhash_check_integrity(wh_dst))) {
2545 + printk(KERN_WARNING
2546 + "ebtables: among: dst integrity fail: %x\n", -err);
2547 + return -EINVAL;
2548 + }
2549 + if (wh_src && (err = ebt_mac_wormhash_check_integrity(wh_src))) {
2550 + printk(KERN_WARNING
2551 + "ebtables: among: src integrity fail: %x\n", -err);
2552 + return -EINVAL;
2553 + }
2554 + return 0;
2555 +}
2556 +
2557 +static struct ebt_match filter_among = {
2558 + {NULL, NULL},
2559 + EBT_AMONG_MATCH,
2560 + ebt_filter_among,
2561 + ebt_among_check,
2562 + NULL,
2563 + THIS_MODULE
2564 +};
2565 +
2566 +static int __init init(void)
2567 +{
2568 + return ebt_register_match(&filter_among);
2569 +}
2570 +
2571 +static void __exit fini(void)
2572 +{
2573 + ebt_unregister_match(&filter_among);
2574 +}
2575 +
2576 +module_init(init);
2577 +module_exit(fini);
2578 +EXPORT_NO_SYMBOLS;
2579 +MODULE_LICENSE("GPL");
2580 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_arp.c src/linux/linux/net/bridge/netfilter/ebt_arp.c
2581 --- src/linux/linux.stock/net/bridge/netfilter/ebt_arp.c 1969-12-31 19:00:00.000000000 -0500
2582 +++ src/linux/linux/net/bridge/netfilter/ebt_arp.c 2004-07-10 23:46:39.000000000 -0400
2583 @@ -0,0 +1,149 @@
2584 +/*
2585 + * ebt_arp
2586 + *
2587 + * Authors:
2588 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2589 + * Tim Gardner <timg@tpi.com>
2590 + *
2591 + * April, 2002
2592 + *
2593 + */
2594 +
2595 +#include <linux/netfilter_bridge/ebtables.h>
2596 +#include <linux/netfilter_bridge/ebt_arp.h>
2597 +#include <linux/if_arp.h>
2598 +#include <linux/if_ether.h>
2599 +#include <linux/module.h>
2600 +
2601 +static int ebt_filter_arp(const struct sk_buff *skb, const struct net_device *in,
2602 + const struct net_device *out, const void *data, unsigned int datalen)
2603 +{
2604 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
2605 +
2606 + if (info->bitmask & EBT_ARP_OPCODE && FWINV(info->opcode !=
2607 + ((*skb).nh.arph)->ar_op, EBT_ARP_OPCODE))
2608 + return EBT_NOMATCH;
2609 + if (info->bitmask & EBT_ARP_HTYPE && FWINV(info->htype !=
2610 + ((*skb).nh.arph)->ar_hrd, EBT_ARP_HTYPE))
2611 + return EBT_NOMATCH;
2612 + if (info->bitmask & EBT_ARP_PTYPE && FWINV(info->ptype !=
2613 + ((*skb).nh.arph)->ar_pro, EBT_ARP_PTYPE))
2614 + return EBT_NOMATCH;
2615 +
2616 + if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP))
2617 + {
2618 + uint32_t arp_len = sizeof(struct arphdr) +
2619 + (2 * (((*skb).nh.arph)->ar_hln)) +
2620 + (2 * (((*skb).nh.arph)->ar_pln));
2621 + uint32_t dst;
2622 + uint32_t src;
2623 +
2624 + // Make sure the packet is long enough.
2625 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2626 + return EBT_NOMATCH;
2627 + // IPv4 addresses are always 4 bytes.
2628 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
2629 + return EBT_NOMATCH;
2630 +
2631 + if (info->bitmask & EBT_ARP_SRC_IP) {
2632 + memcpy(&src, ((*skb).nh.raw) + sizeof(struct arphdr) +
2633 + ((*skb).nh.arph)->ar_hln, sizeof(uint32_t));
2634 + if (FWINV(info->saddr != (src & info->smsk),
2635 + EBT_ARP_SRC_IP))
2636 + return EBT_NOMATCH;
2637 + }
2638 +
2639 + if (info->bitmask & EBT_ARP_DST_IP) {
2640 + memcpy(&dst, ((*skb).nh.raw)+sizeof(struct arphdr) +
2641 + (2*(((*skb).nh.arph)->ar_hln)) +
2642 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
2643 + if (FWINV(info->daddr != (dst & info->dmsk),
2644 + EBT_ARP_DST_IP))
2645 + return EBT_NOMATCH;
2646 + }
2647 + }
2648 +
2649 + if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC))
2650 + {
2651 + uint32_t arp_len = sizeof(struct arphdr) +
2652 + (2 * (((*skb).nh.arph)->ar_hln)) +
2653 + (2 * (((*skb).nh.arph)->ar_pln));
2654 + unsigned char dst[ETH_ALEN];
2655 + unsigned char src[ETH_ALEN];
2656 +
2657 + // Make sure the packet is long enough.
2658 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2659 + return EBT_NOMATCH;
2660 + // MAC addresses are 6 bytes.
2661 + if (((*skb).nh.arph)->ar_hln != ETH_ALEN)
2662 + return EBT_NOMATCH;
2663 + if (info->bitmask & EBT_ARP_SRC_MAC) {
2664 + uint8_t verdict, i;
2665 +
2666 + memcpy(&src, ((*skb).nh.raw) +
2667 + sizeof(struct arphdr),
2668 + ETH_ALEN);
2669 + verdict = 0;
2670 + for (i = 0; i < 6; i++)
2671 + verdict |= (src[i] ^ info->smaddr[i]) &
2672 + info->smmsk[i];
2673 + if (FWINV(verdict != 0, EBT_ARP_SRC_MAC))
2674 + return EBT_NOMATCH;
2675 + }
2676 +
2677 + if (info->bitmask & EBT_ARP_DST_MAC) {
2678 + uint8_t verdict, i;
2679 +
2680 + memcpy(&dst, ((*skb).nh.raw) +
2681 + sizeof(struct arphdr) +
2682 + (((*skb).nh.arph)->ar_hln) +
2683 + (((*skb).nh.arph)->ar_pln),
2684 + ETH_ALEN);
2685 + verdict = 0;
2686 + for (i = 0; i < 6; i++)
2687 + verdict |= (dst[i] ^ info->dmaddr[i]) &
2688 + info->dmmsk[i];
2689 + if (FWINV(verdict != 0, EBT_ARP_DST_MAC))
2690 + return EBT_NOMATCH;
2691 + }
2692 + }
2693 +
2694 + return EBT_MATCH;
2695 +}
2696 +
2697 +static int ebt_arp_check(const char *tablename, unsigned int hookmask,
2698 + const struct ebt_entry *e, void *data, unsigned int datalen)
2699 +{
2700 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
2701 +
2702 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arp_info)))
2703 + return -EINVAL;
2704 + if ((e->ethproto != __constant_htons(ETH_P_ARP) &&
2705 + e->ethproto != __constant_htons(ETH_P_RARP)) ||
2706 + e->invflags & EBT_IPROTO)
2707 + return -EINVAL;
2708 + if (info->bitmask & ~EBT_ARP_MASK || info->invflags & ~EBT_ARP_MASK)
2709 + return -EINVAL;
2710 + return 0;
2711 +}
2712 +
2713 +static struct ebt_match filter_arp =
2714 +{
2715 + {NULL, NULL}, EBT_ARP_MATCH, ebt_filter_arp, ebt_arp_check, NULL,
2716 + THIS_MODULE
2717 +};
2718 +
2719 +static int __init init(void)
2720 +{
2721 + return ebt_register_match(&filter_arp);
2722 +}
2723 +
2724 +static void __exit fini(void)
2725 +{
2726 + ebt_unregister_match(&filter_arp);
2727 +}
2728 +
2729 +module_init(init);
2730 +module_exit(fini);
2731 +EXPORT_NO_SYMBOLS;
2732 +MODULE_LICENSE("GPL");
2733 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_arpreply.c src/linux/linux/net/bridge/netfilter/ebt_arpreply.c
2734 --- src/linux/linux.stock/net/bridge/netfilter/ebt_arpreply.c 1969-12-31 19:00:00.000000000 -0500
2735 +++ src/linux/linux/net/bridge/netfilter/ebt_arpreply.c 2004-07-10 23:46:39.000000000 -0400
2736 @@ -0,0 +1,86 @@
2737 +/*
2738 + * ebt_arpreply
2739 + *
2740 + * Authors:
2741 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
2742 + * Bart De Schuymer <bdschuym@pandora.be>
2743 + *
2744 + * August, 2003
2745 + *
2746 + */
2747 +
2748 +#include <linux/netfilter_bridge/ebtables.h>
2749 +#include <linux/netfilter_bridge/ebt_arpreply.h>
2750 +#include <linux/if_arp.h>
2751 +#include <net/arp.h>
2752 +#include <linux/module.h>
2753 +
2754 +static int ebt_target_reply(struct sk_buff **pskb, unsigned int hooknr,
2755 + const struct net_device *in, const struct net_device *out,
2756 + const void *data, unsigned int datalen)
2757 +{
2758 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
2759 + struct arphdr *ah;
2760 + unsigned char *sha, *arp_ptr;
2761 + u32 sip, tip;
2762 +
2763 + ah = (**pskb).nh.arph;
2764 + if (ah->ar_op != __constant_htons(ARPOP_REQUEST) ||
2765 + ah->ar_hln != ETH_ALEN || ah->ar_pro != htons(ETH_P_IP) ||
2766 + ah->ar_pln != 4)
2767 + return EBT_CONTINUE;
2768 +
2769 + arp_ptr = (unsigned char *)(ah + 1);
2770 +
2771 + /* get source and target IP */
2772 + sha = arp_ptr;
2773 + arp_ptr += ETH_ALEN;
2774 + memcpy(&sip, arp_ptr, 4);
2775 + arp_ptr += 4 + ETH_ALEN;
2776 + memcpy(&tip, arp_ptr, 4);
2777 +
2778 + arp_send(ARPOP_REPLY, ETH_P_ARP, sip, in, tip, sha, info->mac, sha);
2779 +
2780 + return info->target;
2781 +}
2782 +
2783 +static int ebt_target_reply_check(const char *tablename, unsigned int hookmask,
2784 + const struct ebt_entry *e, void *data, unsigned int datalen)
2785 +{
2786 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
2787 +
2788 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arpreply_info)))
2789 + return -EINVAL;
2790 + if (BASE_CHAIN && info->target == EBT_RETURN)
2791 + return -EINVAL;
2792 + if (e->ethproto != __constant_htons(ETH_P_ARP) ||
2793 + e->invflags & EBT_IPROTO)
2794 + return -EINVAL;
2795 + CLEAR_BASE_CHAIN_BIT;
2796 + if (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING))
2797 + return -EINVAL;
2798 + return 0;
2799 +}
2800 +
2801 +static struct ebt_target reply_target =
2802 +{
2803 + .name = EBT_ARPREPLY_TARGET,
2804 + .target = ebt_target_reply,
2805 + .check = ebt_target_reply_check,
2806 + .me = THIS_MODULE,
2807 +};
2808 +
2809 +static int __init init(void)
2810 +{
2811 + return ebt_register_target(&reply_target);
2812 +}
2813 +
2814 +static void __exit fini(void)
2815 +{
2816 + ebt_unregister_target(&reply_target);
2817 +}
2818 +
2819 +module_init(init);
2820 +module_exit(fini);
2821 +EXPORT_NO_SYMBOLS;
2822 +MODULE_LICENSE("GPL");
2823 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_dnat.c src/linux/linux/net/bridge/netfilter/ebt_dnat.c
2824 --- src/linux/linux.stock/net/bridge/netfilter/ebt_dnat.c 1969-12-31 19:00:00.000000000 -0500
2825 +++ src/linux/linux/net/bridge/netfilter/ebt_dnat.c 2004-07-10 23:46:39.000000000 -0400
2826 @@ -0,0 +1,65 @@
2827 +/*
2828 + * ebt_dnat
2829 + *
2830 + * Authors:
2831 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2832 + *
2833 + * June, 2002
2834 + *
2835 + */
2836 +
2837 +#include <linux/netfilter_bridge/ebtables.h>
2838 +#include <linux/netfilter_bridge/ebt_nat.h>
2839 +#include <linux/module.h>
2840 +#include <net/sock.h>
2841 +
2842 +static int ebt_target_dnat(struct sk_buff **pskb, unsigned int hooknr,
2843 + const struct net_device *in, const struct net_device *out,
2844 + const void *data, unsigned int datalen)
2845 +{
2846 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
2847 +
2848 + memcpy(((**pskb).mac.ethernet)->h_dest, info->mac,
2849 + ETH_ALEN * sizeof(unsigned char));
2850 + return info->target;
2851 +}
2852 +
2853 +static int ebt_target_dnat_check(const char *tablename, unsigned int hookmask,
2854 + const struct ebt_entry *e, void *data, unsigned int datalen)
2855 +{
2856 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
2857 +
2858 + if (BASE_CHAIN && info->target == EBT_RETURN)
2859 + return -EINVAL;
2860 + CLEAR_BASE_CHAIN_BIT;
2861 + if ( (strcmp(tablename, "nat") ||
2862 + (hookmask & ~((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT)))) &&
2863 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
2864 + return -EINVAL;
2865 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
2866 + return -EINVAL;
2867 + if (INVALID_TARGET)
2868 + return -EINVAL;
2869 + return 0;
2870 +}
2871 +
2872 +static struct ebt_target dnat =
2873 +{
2874 + {NULL, NULL}, EBT_DNAT_TARGET, ebt_target_dnat, ebt_target_dnat_check,
2875 + NULL, THIS_MODULE
2876 +};
2877 +
2878 +static int __init init(void)
2879 +{
2880 + return ebt_register_target(&dnat);
2881 +}
2882 +
2883 +static void __exit fini(void)
2884 +{
2885 + ebt_unregister_target(&dnat);
2886 +}
2887 +
2888 +module_init(init);
2889 +module_exit(fini);
2890 +EXPORT_NO_SYMBOLS;
2891 +MODULE_LICENSE("GPL");
2892 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_ip.c src/linux/linux/net/bridge/netfilter/ebt_ip.c
2893 --- src/linux/linux.stock/net/bridge/netfilter/ebt_ip.c 1969-12-31 19:00:00.000000000 -0500
2894 +++ src/linux/linux/net/bridge/netfilter/ebt_ip.c 2004-07-10 23:46:39.000000000 -0400
2895 @@ -0,0 +1,121 @@
2896 +/*
2897 + * ebt_ip
2898 + *
2899 + * Authors:
2900 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2901 + *
2902 + * April, 2002
2903 + *
2904 + * Changes:
2905 + * added ip-sport and ip-dport
2906 + * Innominate Security Technologies AG <mhopf@innominate.com>
2907 + * September, 2002
2908 + */
2909 +
2910 +#include <linux/netfilter_bridge/ebtables.h>
2911 +#include <linux/netfilter_bridge/ebt_ip.h>
2912 +#include <linux/ip.h>
2913 +#include <linux/in.h>
2914 +#include <linux/module.h>
2915 +
2916 +struct tcpudphdr {
2917 + uint16_t src;
2918 + uint16_t dst;
2919 +};
2920 +
2921 +union h_u {
2922 + unsigned char *raw;
2923 + struct tcpudphdr *tuh;
2924 +};
2925 +
2926 +static int ebt_filter_ip(const struct sk_buff *skb, const struct net_device *in,
2927 + const struct net_device *out, const void *data,
2928 + unsigned int datalen)
2929 +{
2930 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
2931 +
2932 + if (info->bitmask & EBT_IP_TOS &&
2933 + FWINV(info->tos != ((*skb).nh.iph)->tos, EBT_IP_TOS))
2934 + return EBT_NOMATCH;
2935 + if (info->bitmask & EBT_IP_PROTO) {
2936 + if (FWINV(info->protocol != ((*skb).nh.iph)->protocol,
2937 + EBT_IP_PROTO))
2938 + return EBT_NOMATCH;
2939 + if ( info->protocol == IPPROTO_TCP ||
2940 + info->protocol == IPPROTO_UDP )
2941 + {
2942 + union h_u h;
2943 + h.raw = skb->data + skb->nh.iph->ihl*4;
2944 + if (info->bitmask & EBT_IP_DPORT) {
2945 + uint16_t port = ntohs(h.tuh->dst);
2946 + if (FWINV(port < info->dport[0] ||
2947 + port > info->dport[1],
2948 + EBT_IP_DPORT))
2949 + return EBT_NOMATCH;
2950 + }
2951 + if (info->bitmask & EBT_IP_SPORT) {
2952 + uint16_t port = ntohs(h.tuh->src);
2953 + if (FWINV(port < info->sport[0] ||
2954 + port > info->sport[1],
2955 + EBT_IP_SPORT))
2956 + return EBT_NOMATCH;
2957 + }
2958 + }
2959 + }
2960 + if (info->bitmask & EBT_IP_SOURCE &&
2961 + FWINV((((*skb).nh.iph)->saddr & info->smsk) !=
2962 + info->saddr, EBT_IP_SOURCE))
2963 + return EBT_NOMATCH;
2964 + if ((info->bitmask & EBT_IP_DEST) &&
2965 + FWINV((((*skb).nh.iph)->daddr & info->dmsk) !=
2966 + info->daddr, EBT_IP_DEST))
2967 + return EBT_NOMATCH;
2968 + return EBT_MATCH;
2969 +}
2970 +
2971 +static int ebt_ip_check(const char *tablename, unsigned int hookmask,
2972 + const struct ebt_entry *e, void *data, unsigned int datalen)
2973 +{
2974 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
2975 +
2976 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ip_info)))
2977 + return -EINVAL;
2978 + if (e->ethproto != __constant_htons(ETH_P_IP) ||
2979 + e->invflags & EBT_IPROTO)
2980 + return -EINVAL;
2981 + if (info->bitmask & ~EBT_IP_MASK || info->invflags & ~EBT_IP_MASK)
2982 + return -EINVAL;
2983 + if (info->bitmask & (EBT_IP_DPORT | EBT_IP_SPORT)) {
2984 + if (!info->bitmask & EBT_IPROTO)
2985 + return -EINVAL;
2986 + if (info->protocol != IPPROTO_TCP &&
2987 + info->protocol != IPPROTO_UDP)
2988 + return -EINVAL;
2989 + }
2990 + if (info->bitmask & EBT_IP_DPORT && info->dport[0] > info->dport[1])
2991 + return -EINVAL;
2992 + if (info->bitmask & EBT_IP_SPORT && info->sport[0] > info->sport[1])
2993 + return -EINVAL;
2994 + return 0;
2995 +}
2996 +
2997 +static struct ebt_match filter_ip =
2998 +{
2999 + {NULL, NULL}, EBT_IP_MATCH, ebt_filter_ip, ebt_ip_check, NULL,
3000 + THIS_MODULE
3001 +};
3002 +
3003 +static int __init init(void)
3004 +{
3005 + return ebt_register_match(&filter_ip);
3006 +}
3007 +
3008 +static void __exit fini(void)
3009 +{
3010 + ebt_unregister_match(&filter_ip);
3011 +}
3012 +
3013 +module_init(init);
3014 +module_exit(fini);
3015 +EXPORT_NO_SYMBOLS;
3016 +MODULE_LICENSE("GPL");
3017 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_limit.c src/linux/linux/net/bridge/netfilter/ebt_limit.c
3018 --- src/linux/linux.stock/net/bridge/netfilter/ebt_limit.c 1969-12-31 19:00:00.000000000 -0500
3019 +++ src/linux/linux/net/bridge/netfilter/ebt_limit.c 2004-07-10 23:46:39.000000000 -0400
3020 @@ -0,0 +1,101 @@
3021 +/*
3022 + * ebt_limit
3023 + *
3024 + * Authors:
3025 + * Tom Marshall <tommy@home.tig-grr.com>
3026 + *
3027 + * Mostly copied from netfilter's ipt_limit.c, see that file for explanation
3028 + *
3029 + * September, 2003
3030 + *
3031 + */
3032 +
3033 +#include <linux/netfilter_bridge/ebtables.h>
3034 +#include <linux/netfilter_bridge/ebt_limit.h>
3035 +#include <linux/module.h>
3036 +
3037 +#include <linux/netdevice.h>
3038 +#include <linux/spinlock.h>
3039 +
3040 +static spinlock_t limit_lock = SPIN_LOCK_UNLOCKED;
3041 +
3042 +#define CREDITS_PER_JIFFY 128
3043 +
3044 +static int ebt_limit_match(const struct sk_buff *skb, const struct net_device *in,
3045 + const struct net_device *out, const void *data, unsigned int datalen)
3046 +{
3047 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
3048 + unsigned long now = jiffies;
3049 +
3050 + spin_lock_bh(&limit_lock);
3051 + info->credit += (now - xchg(&info->prev, now)) * CREDITS_PER_JIFFY;
3052 + if (info->credit > info->credit_cap)
3053 + info->credit = info->credit_cap;
3054 +
3055 + if (info->credit >= info->cost) {
3056 + /* We're not limited. */
3057 + info->credit -= info->cost;
3058 + spin_unlock_bh(&limit_lock);
3059 + return EBT_MATCH;
3060 + }
3061 +
3062 + spin_unlock_bh(&limit_lock);
3063 + return EBT_NOMATCH;
3064 +}
3065 +
3066 +/* Precision saver. */
3067 +static u_int32_t
3068 +user2credits(u_int32_t user)
3069 +{
3070 + /* If multiplying would overflow... */
3071 + if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
3072 + /* Divide first. */
3073 + return (user / EBT_LIMIT_SCALE) * HZ * CREDITS_PER_JIFFY;
3074 +
3075 + return (user * HZ * CREDITS_PER_JIFFY) / EBT_LIMIT_SCALE;
3076 +}
3077 +
3078 +static int ebt_limit_check(const char *tablename, unsigned int hookmask,
3079 + const struct ebt_entry *e, void *data, unsigned int datalen)
3080 +{
3081 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
3082 +
3083 + if (datalen != EBT_ALIGN(sizeof(struct ebt_limit_info)))
3084 + return -EINVAL;
3085 +
3086 + /* Check for overflow. */
3087 + if (info->burst == 0
3088 + || user2credits(info->avg * info->burst) < user2credits(info->avg)) {
3089 + printk("Overflow in ebt_limit: %u/%u\n",
3090 + info->avg, info->burst);
3091 + return -EINVAL;
3092 + }
3093 +
3094 + /* User avg in seconds * EBT_LIMIT_SCALE: convert to jiffies * 128. */
3095 + info->prev = jiffies;
3096 + info->credit = user2credits(info->avg * info->burst);
3097 + info->credit_cap = user2credits(info->avg * info->burst);
3098 + info->cost = user2credits(info->avg);
3099 + return 0;
3100 +}
3101 +
3102 +static struct ebt_match ebt_limit_reg =
3103 +{
3104 + {NULL, NULL}, EBT_LIMIT_MATCH, ebt_limit_match, ebt_limit_check, NULL,
3105 + THIS_MODULE
3106 +};
3107 +
3108 +static int __init init(void)
3109 +{
3110 + return ebt_register_match(&ebt_limit_reg);
3111 +}
3112 +
3113 +static void __exit fini(void)
3114 +{
3115 + ebt_unregister_match(&ebt_limit_reg);
3116 +}
3117 +
3118 +module_init(init);
3119 +module_exit(fini);
3120 +EXPORT_NO_SYMBOLS;
3121 +MODULE_LICENSE("GPL");
3122 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_log.c src/linux/linux/net/bridge/netfilter/ebt_log.c
3123 --- src/linux/linux.stock/net/bridge/netfilter/ebt_log.c 1969-12-31 19:00:00.000000000 -0500
3124 +++ src/linux/linux/net/bridge/netfilter/ebt_log.c 2004-07-10 23:46:39.000000000 -0400
3125 @@ -0,0 +1,152 @@
3126 +/*
3127 + * ebt_log
3128 + *
3129 + * Authors:
3130 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3131 + *
3132 + * April, 2002
3133 + *
3134 + */
3135 +
3136 +#include <linux/netfilter_bridge/ebtables.h>
3137 +#include <linux/netfilter_bridge/ebt_log.h>
3138 +#include <linux/module.h>
3139 +#include <linux/ip.h>
3140 +#include <linux/in.h>
3141 +#include <linux/if_arp.h>
3142 +#include <linux/spinlock.h>
3143 +
3144 +static spinlock_t ebt_log_lock = SPIN_LOCK_UNLOCKED;
3145 +
3146 +static int ebt_log_check(const char *tablename, unsigned int hookmask,
3147 + const struct ebt_entry *e, void *data, unsigned int datalen)
3148 +{
3149 + struct ebt_log_info *info = (struct ebt_log_info *)data;
3150 +
3151 + if (datalen != EBT_ALIGN(sizeof(struct ebt_log_info)))
3152 + return -EINVAL;
3153 + if (info->bitmask & ~EBT_LOG_MASK)
3154 + return -EINVAL;
3155 + if (info->loglevel >= 8)
3156 + return -EINVAL;
3157 + info->prefix[EBT_LOG_PREFIX_SIZE - 1] = '\0';
3158 + return 0;
3159 +}
3160 +
3161 +struct tcpudphdr
3162 +{
3163 + uint16_t src;
3164 + uint16_t dst;
3165 +};
3166 +
3167 +struct arppayload
3168 +{
3169 + unsigned char mac_src[ETH_ALEN];
3170 + unsigned char ip_src[4];
3171 + unsigned char mac_dst[ETH_ALEN];
3172 + unsigned char ip_dst[4];
3173 +};
3174 +
3175 +static void print_MAC(unsigned char *p)
3176 +{
3177 + int i;
3178 +
3179 + for (i = 0; i < ETH_ALEN; i++, p++)
3180 + printk("%02x%c", *p, i == ETH_ALEN - 1 ? ' ':':');
3181 +}
3182 +
3183 +#define myNIPQUAD(a) a[0], a[1], a[2], a[3]
3184 +static void ebt_log(const struct sk_buff *skb, const struct net_device *in,
3185 + const struct net_device *out, const void *data, unsigned int datalen)
3186 +{
3187 + struct ebt_log_info *info = (struct ebt_log_info *)data;
3188 + char level_string[4] = "< >";
3189 + level_string[1] = '0' + info->loglevel;
3190 +
3191 + spin_lock_bh(&ebt_log_lock);
3192 + printk(level_string);
3193 + printk("%s IN=%s OUT=%s ", info->prefix, in ? in->name : "",
3194 + out ? out->name : "");
3195 +
3196 + printk("MAC source = ");
3197 + print_MAC((skb->mac.ethernet)->h_source);
3198 + printk("MAC dest = ");
3199 + print_MAC((skb->mac.ethernet)->h_dest);
3200 +
3201 + printk("proto = 0x%04x", ntohs(((*skb).mac.ethernet)->h_proto));
3202 +
3203 + if ((info->bitmask & EBT_LOG_IP) && skb->mac.ethernet->h_proto ==
3204 + htons(ETH_P_IP)){
3205 + struct iphdr *iph = skb->nh.iph;
3206 + printk(" IP SRC=%u.%u.%u.%u IP DST=%u.%u.%u.%u,",
3207 + NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
3208 + printk(" IP tos=0x%02X, IP proto=%d", iph->tos, iph->protocol);
3209 + if (iph->protocol == IPPROTO_TCP ||
3210 + iph->protocol == IPPROTO_UDP) {
3211 + struct tcpudphdr *ports = (struct tcpudphdr *)(skb->data + iph->ihl*4);
3212 +
3213 + if (skb->data + iph->ihl*4 > skb->tail) {
3214 + printk(" INCOMPLETE TCP/UDP header");
3215 + goto out;
3216 + }
3217 + printk(" SPT=%u DPT=%u", ntohs(ports->src),
3218 + ntohs(ports->dst));
3219 + }
3220 + goto out;
3221 + }
3222 +
3223 + if ((info->bitmask & EBT_LOG_ARP) &&
3224 + ((skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) ||
3225 + (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_RARP)))) {
3226 + struct arphdr * arph = skb->nh.arph;
3227 + printk(" ARP HTYPE=%d, PTYPE=0x%04x, OPCODE=%d",
3228 + ntohs(arph->ar_hrd), ntohs(arph->ar_pro),
3229 + ntohs(arph->ar_op));
3230 + /* If it's for Ethernet and the lengths are OK,
3231 + * then log the ARP payload */
3232 + if (arph->ar_hrd == __constant_htons(1) &&
3233 + arph->ar_hln == ETH_ALEN &&
3234 + arph->ar_pln == sizeof(uint32_t)) {
3235 + struct arppayload *arpp = (struct arppayload *)(skb->data + sizeof(*arph));
3236 +
3237 + if (skb->data + sizeof(*arph) > skb->tail) {
3238 + printk(" INCOMPLETE ARP header");
3239 + goto out;
3240 + }
3241 +
3242 + printk(" ARP MAC SRC=");
3243 + print_MAC(arpp->mac_src);
3244 + printk(" ARP IP SRC=%u.%u.%u.%u",
3245 + myNIPQUAD(arpp->ip_src));
3246 + printk(" ARP MAC DST=");
3247 + print_MAC(arpp->mac_dst);
3248 + printk(" ARP IP DST=%u.%u.%u.%u",
3249 + myNIPQUAD(arpp->ip_dst));
3250 + }
3251 +
3252 + }
3253 +out:
3254 + printk("\n");
3255 + spin_unlock_bh(&ebt_log_lock);
3256 +}
3257 +
3258 +static struct ebt_watcher log =
3259 +{
3260 + {NULL, NULL}, EBT_LOG_WATCHER, ebt_log, ebt_log_check, NULL,
3261 + THIS_MODULE
3262 +};
3263 +
3264 +static int __init init(void)
3265 +{
3266 + return ebt_register_watcher(&log);
3267 +}
3268 +
3269 +static void __exit fini(void)
3270 +{
3271 + ebt_unregister_watcher(&log);
3272 +}
3273 +
3274 +module_init(init);
3275 +module_exit(fini);
3276 +EXPORT_NO_SYMBOLS;
3277 +MODULE_LICENSE("GPL");
3278 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_mark.c src/linux/linux/net/bridge/netfilter/ebt_mark.c
3279 --- src/linux/linux.stock/net/bridge/netfilter/ebt_mark.c 1969-12-31 19:00:00.000000000 -0500
3280 +++ src/linux/linux/net/bridge/netfilter/ebt_mark.c 2004-07-10 23:46:39.000000000 -0400
3281 @@ -0,0 +1,66 @@
3282 +/*
3283 + * ebt_mark
3284 + *
3285 + * Authors:
3286 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3287 + *
3288 + * July, 2002
3289 + *
3290 + */
3291 +
3292 +// The mark target can be used in any chain
3293 +// I believe adding a mangle table just for marking is total overkill
3294 +// Marking a frame doesn't really change anything in the frame anyway
3295 +
3296 +#include <linux/netfilter_bridge/ebtables.h>
3297 +#include <linux/netfilter_bridge/ebt_mark_t.h>
3298 +#include <linux/module.h>
3299 +
3300 +static int ebt_target_mark(struct sk_buff **pskb, unsigned int hooknr,
3301 + const struct net_device *in, const struct net_device *out,
3302 + const void *data, unsigned int datalen)
3303 +{
3304 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
3305 +
3306 + if ((*pskb)->nfmark != info->mark) {
3307 + (*pskb)->nfmark = info->mark;
3308 + (*pskb)->nfcache |= NFC_ALTERED;
3309 + }
3310 + return info->target;
3311 +}
3312 +
3313 +static int ebt_target_mark_check(const char *tablename, unsigned int hookmask,
3314 + const struct ebt_entry *e, void *data, unsigned int datalen)
3315 +{
3316 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
3317 +
3318 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_t_info)))
3319 + return -EINVAL;
3320 + if (BASE_CHAIN && info->target == EBT_RETURN)
3321 + return -EINVAL;
3322 + CLEAR_BASE_CHAIN_BIT;
3323 + if (INVALID_TARGET)
3324 + return -EINVAL;
3325 + return 0;
3326 +}
3327 +
3328 +static struct ebt_target mark_target =
3329 +{
3330 + {NULL, NULL}, EBT_MARK_TARGET, ebt_target_mark,
3331 + ebt_target_mark_check, NULL, THIS_MODULE
3332 +};
3333 +
3334 +static int __init init(void)
3335 +{
3336 + return ebt_register_target(&mark_target);
3337 +}
3338 +
3339 +static void __exit fini(void)
3340 +{
3341 + ebt_unregister_target(&mark_target);
3342 +}
3343 +
3344 +module_init(init);
3345 +module_exit(fini);
3346 +EXPORT_NO_SYMBOLS;
3347 +MODULE_LICENSE("GPL");
3348 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_mark_m.c src/linux/linux/net/bridge/netfilter/ebt_mark_m.c
3349 --- src/linux/linux.stock/net/bridge/netfilter/ebt_mark_m.c 1969-12-31 19:00:00.000000000 -0500
3350 +++ src/linux/linux/net/bridge/netfilter/ebt_mark_m.c 2004-07-10 23:46:39.000000000 -0400
3351 @@ -0,0 +1,61 @@
3352 +/*
3353 + * ebt_mark_m
3354 + *
3355 + * Authors:
3356 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3357 + *
3358 + * July, 2002
3359 + *
3360 + */
3361 +
3362 +#include <linux/netfilter_bridge/ebtables.h>
3363 +#include <linux/netfilter_bridge/ebt_mark_m.h>
3364 +#include <linux/module.h>
3365 +
3366 +static int ebt_filter_mark(const struct sk_buff *skb,
3367 + const struct net_device *in, const struct net_device *out, const void *data,
3368 + unsigned int datalen)
3369 +{
3370 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
3371 +
3372 + if (info->bitmask & EBT_MARK_OR)
3373 + return !(!!(skb->nfmark & info->mask) ^ info->invert);
3374 + return !(((skb->nfmark & info->mask) == info->mark) ^ info->invert);
3375 +}
3376 +
3377 +static int ebt_mark_check(const char *tablename, unsigned int hookmask,
3378 + const struct ebt_entry *e, void *data, unsigned int datalen)
3379 +{
3380 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
3381 +
3382 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_m_info)))
3383 + return -EINVAL;
3384 + if (info->bitmask & ~EBT_MARK_MASK)
3385 + return -EINVAL;
3386 + if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
3387 + return -EINVAL;
3388 + if (!info->bitmask)
3389 + return -EINVAL;
3390 + return 0;
3391 +}
3392 +
3393 +static struct ebt_match filter_mark =
3394 +{
3395 + {NULL, NULL}, EBT_MARK_MATCH, ebt_filter_mark, ebt_mark_check, NULL,
3396 + THIS_MODULE
3397 +};
3398 +
3399 +static int __init init(void)
3400 +{
3401 + return ebt_register_match(&filter_mark);
3402 +}
3403 +
3404 +static void __exit fini(void)
3405 +{
3406 + ebt_unregister_match(&filter_mark);
3407 +}
3408 +
3409 +module_init(init);
3410 +module_exit(fini);
3411 +EXPORT_NO_SYMBOLS;
3412 +MODULE_LICENSE("GPL");
3413 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_pkttype.c src/linux/linux/net/bridge/netfilter/ebt_pkttype.c
3414 --- src/linux/linux.stock/net/bridge/netfilter/ebt_pkttype.c 1969-12-31 19:00:00.000000000 -0500
3415 +++ src/linux/linux/net/bridge/netfilter/ebt_pkttype.c 2004-07-10 23:46:39.000000000 -0400
3416 @@ -0,0 +1,60 @@
3417 +/*
3418 + * ebt_pkttype
3419 + *
3420 + * Authors:
3421 + * Bart De Schuymer <bdschuym@pandora.be>
3422 + *
3423 + * April, 2003
3424 + *
3425 + */
3426 +
3427 +#include <linux/netfilter_bridge/ebtables.h>
3428 +#include <linux/netfilter_bridge/ebt_pkttype.h>
3429 +#include <linux/module.h>
3430 +
3431 +static int ebt_filter_pkttype(const struct sk_buff *skb,
3432 + const struct net_device *in,
3433 + const struct net_device *out,
3434 + const void *data,
3435 + unsigned int datalen)
3436 +{
3437 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
3438 +
3439 + return (skb->pkt_type != info->pkt_type) ^ info->invert;
3440 +}
3441 +
3442 +static int ebt_pkttype_check(const char *tablename, unsigned int hookmask,
3443 + const struct ebt_entry *e, void *data, unsigned int datalen)
3444 +{
3445 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
3446 +
3447 + if (datalen != EBT_ALIGN(sizeof(struct ebt_pkttype_info)))
3448 + return -EINVAL;
3449 + if (info->invert != 0 && info->invert != 1)
3450 + return -EINVAL;
3451 + /* Allow any pkt_type value */
3452 + return 0;
3453 +}
3454 +
3455 +static struct ebt_match filter_pkttype =
3456 +{
3457 + .name = EBT_PKTTYPE_MATCH,
3458 + .match = ebt_filter_pkttype,
3459 + .check = ebt_pkttype_check,
3460 + .me = THIS_MODULE,
3461 +};
3462 +
3463 +static int __init init(void)
3464 +{
3465 + return ebt_register_match(&filter_pkttype);
3466 +}
3467 +
3468 +static void __exit fini(void)
3469 +{
3470 + ebt_unregister_match(&filter_pkttype);
3471 +}
3472 +
3473 +module_init(init);
3474 +module_exit(fini);
3475 +EXPORT_NO_SYMBOLS;
3476 +MODULE_LICENSE("GPL");
3477 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_redirect.c src/linux/linux/net/bridge/netfilter/ebt_redirect.c
3478 --- src/linux/linux.stock/net/bridge/netfilter/ebt_redirect.c 1969-12-31 19:00:00.000000000 -0500
3479 +++ src/linux/linux/net/bridge/netfilter/ebt_redirect.c 2004-07-10 23:46:39.000000000 -0400
3480 @@ -0,0 +1,71 @@
3481 +/*
3482 + * ebt_redirect
3483 + *
3484 + * Authors:
3485 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3486 + *
3487 + * April, 2002
3488 + *
3489 + */
3490 +
3491 +#include <linux/netfilter_bridge/ebtables.h>
3492 +#include <linux/netfilter_bridge/ebt_redirect.h>
3493 +#include <linux/module.h>
3494 +#include <net/sock.h>
3495 +#include "../br_private.h"
3496 +
3497 +static int ebt_target_redirect(struct sk_buff **pskb, unsigned int hooknr,
3498 + const struct net_device *in, const struct net_device *out,
3499 + const void *data, unsigned int datalen)
3500 +{
3501 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
3502 +
3503 + if (hooknr != NF_BR_BROUTING)
3504 + memcpy((**pskb).mac.ethernet->h_dest,
3505 + in->br_port->br->dev.dev_addr, ETH_ALEN);
3506 + else {
3507 + memcpy((**pskb).mac.ethernet->h_dest,
3508 + in->dev_addr, ETH_ALEN);
3509 + (*pskb)->pkt_type = PACKET_HOST;
3510 + }
3511 + return info->target;
3512 +}
3513 +
3514 +static int ebt_target_redirect_check(const char *tablename, unsigned int hookmask,
3515 + const struct ebt_entry *e, void *data, unsigned int datalen)
3516 +{
3517 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
3518 +
3519 + if (datalen != EBT_ALIGN(sizeof(struct ebt_redirect_info)))
3520 + return -EINVAL;
3521 + if (BASE_CHAIN && info->target == EBT_RETURN)
3522 + return -EINVAL;
3523 + CLEAR_BASE_CHAIN_BIT;
3524 + if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) &&
3525 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
3526 + return -EINVAL;
3527 + if (INVALID_TARGET)
3528 + return -EINVAL;
3529 + return 0;
3530 +}
3531 +
3532 +static struct ebt_target redirect_target =
3533 +{
3534 + {NULL, NULL}, EBT_REDIRECT_TARGET, ebt_target_redirect,
3535 + ebt_target_redirect_check, NULL, THIS_MODULE
3536 +};
3537 +
3538 +static int __init init(void)
3539 +{
3540 + return ebt_register_target(&redirect_target);
3541 +}
3542 +
3543 +static void __exit fini(void)
3544 +{
3545 + ebt_unregister_target(&redirect_target);
3546 +}
3547 +
3548 +module_init(init);
3549 +module_exit(fini);
3550 +EXPORT_NO_SYMBOLS;
3551 +MODULE_LICENSE("GPL");
3552 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_snat.c src/linux/linux/net/bridge/netfilter/ebt_snat.c
3553 --- src/linux/linux.stock/net/bridge/netfilter/ebt_snat.c 1969-12-31 19:00:00.000000000 -0500
3554 +++ src/linux/linux/net/bridge/netfilter/ebt_snat.c 2004-07-10 23:46:39.000000000 -0400
3555 @@ -0,0 +1,64 @@
3556 +/*
3557 + * ebt_snat
3558 + *
3559 + * Authors:
3560 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3561 + *
3562 + * June, 2002
3563 + *
3564 + */
3565 +
3566 +#include <linux/netfilter_bridge/ebtables.h>
3567 +#include <linux/netfilter_bridge/ebt_nat.h>
3568 +#include <linux/module.h>
3569 +
3570 +static int ebt_target_snat(struct sk_buff **pskb, unsigned int hooknr,
3571 + const struct net_device *in, const struct net_device *out,
3572 + const void *data, unsigned int datalen)
3573 +{
3574 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
3575 +
3576 + memcpy(((**pskb).mac.ethernet)->h_source, info->mac,
3577 + ETH_ALEN * sizeof(unsigned char));
3578 + return info->target;
3579 +}
3580 +
3581 +static int ebt_target_snat_check(const char *tablename, unsigned int hookmask,
3582 + const struct ebt_entry *e, void *data, unsigned int datalen)
3583 +{
3584 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
3585 +
3586 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
3587 + return -EINVAL;
3588 + if (BASE_CHAIN && info->target == EBT_RETURN)
3589 + return -EINVAL;
3590 + CLEAR_BASE_CHAIN_BIT;
3591 + if (strcmp(tablename, "nat"))
3592 + return -EINVAL;
3593 + if (hookmask & ~(1 << NF_BR_POST_ROUTING))